Ticket #35379: 35379.3.diff
File 35379.3.diff, 4.2 KB (added by , 9 years ago) |
---|
-
src/wp-includes/formatting.php
3635 3635 * of functions depending on the $option. 3636 3636 * 3637 3637 * @since 2.0.5 3638 * @since 4.6.0 Added a $context and $context_id parameter to distinguish between site and network options. 3638 3639 * 3639 3640 * @global wpdb $wpdb WordPress database abstraction object. 3640 3641 * 3641 * @param string $option The name of the option. 3642 * @param string $value The unsanitised value. 3642 * @param string $option The name of the option. 3643 * @param string $value The unsanitised value. 3644 * @param string $context The context of the option (either 'site' or 'network') 3645 * @param int $context_id Unique identifier of the $context, e.g. for 'network' , its network_id 3643 3646 * @return string Sanitized value. 3644 3647 */ 3645 function sanitize_option( $option, $value ) {3648 function sanitize_option( $option, $value, $context = 'site', $context_id = '' ) { 3646 3649 global $wpdb; 3647 3650 3648 3651 $original_value = $value; 3649 $error = ''; 3650 3652 $error = ''; 3653 3654 if ( 'network' === $context ) { 3655 //Network mode 3656 global $current_site; 3657 if ( ( isset( $current_site->id ) ) && ( empty( $context_id ) ) ) { 3658 //If $context_id is not set, use the current network ID 3659 $network_id = $current_site->id; 3660 } else { 3661 //If context_id is set, make sure its a network ID 3662 $context_id = (int) $context_id; 3663 if ( $context_id > 0 ) { 3664 //Use the validated context as network ID 3665 $network_id = $context_id; 3666 } 3667 } 3668 } 3669 3651 3670 switch ( $option ) { 3652 3671 case 'admin_email' : 3653 3672 case 'new_admin_email' : … … 3783 3802 $allowed[] = WPLANG; 3784 3803 } 3785 3804 if ( ! in_array( $value, $allowed ) && ! empty( $value ) ) { 3786 $value = get_option( $option ); 3805 if ( 'network' === $context ) { 3806 $value = get_network_option( $network_id, $option, false ); 3807 } else { 3808 $value = get_option( $option ); 3809 } 3787 3810 } 3788 3811 break; 3789 3812 … … 3863 3886 } 3864 3887 3865 3888 if ( ! empty( $error ) ) { 3866 $value = get_option( $option ); 3889 if ( 'network' === $context ) { 3890 $value = get_network_option( $network_id, $option, false ); 3891 } else { 3892 $value = get_option( $option ); 3893 } 3867 3894 if ( function_exists( 'add_settings_error' ) ) { 3868 3895 add_settings_error( $option, "invalid_{$option}", $error ); 3869 3896 } … … 3870 3897 } 3871 3898 3872 3899 /** 3900 * Filter an option value following sanitization based on its context. 3901 * 3902 * The dynamic part $context of the filter determines what kind of option is being sanitized. 3903 * It can be set to either 'site' or 'network'. 3904 * 3905 * The $option part of the filter is the option name being sanitized. 3906 * 3907 * @since 4.6.0 3908 * 3909 * @param string $value The sanitized option value. 3910 * @param string $option The option name. 3911 * @param string $original_value The original value passed to the function. 3912 */ 3913 $value = apply_filters( "sanitize_{$context}_context_option_{$option}", $value, $option, $original_value ); 3914 3915 /** 3873 3916 * Filter an option value following sanitization. 3874 3917 * 3918 * This filter is here for backwards compatibility. You should use the 3919 * `sanitize_{$context}_context_option_{$option}` filter instead. 3920 * 3875 3921 * @since 2.3.0 3876 3922 * @since 4.3.0 Added the `$original_value` parameter. 3877 3923 * -
src/wp-includes/option.php
1235 1235 } 1236 1236 } 1237 1237 1238 $value = sanitize_option( $option, $value );1238 $value = sanitize_option( $option, $value, 'network', $network_id ); 1239 1239 1240 1240 $serialized_value = maybe_serialize( $value ); 1241 1241 $result = $wpdb->insert( $wpdb->sitemeta, array( 'site_id' => $network_id, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); … … 1433 1433 if ( ! is_multisite() ) { 1434 1434 $result = update_option( $option, $value ); 1435 1435 } else { 1436 $value = sanitize_option( $option, $value );1436 $value = sanitize_option( $option, $value, 'network', $network_id ); 1437 1437 1438 1438 $serialized_value = maybe_serialize( $value ); 1439 1439 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) );