Ticket #35379: 35379.4.diff
File 35379.4.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'). If it passes 'network' as context in a single-site mode, 'site' context is used. 3645 * @param int $context_id Unique identifier of the $context, example for 'network' , it is the 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' context passed 3656 if ( ! is_multisite() ) { 3657 //Not in multisite, fallback to 'site' context 3658 $context = 'site'; 3659 } elseif ( ! $context_id ) { 3660 //context_id not set, use the current network ID 3661 global $current_site; 3662 $context_id = $current_site->id; 3663 } 3664 } 3665 3651 3666 switch ( $option ) { 3652 3667 case 'admin_email' : 3653 3668 case 'new_admin_email' : … … 3783 3798 $allowed[] = WPLANG; 3784 3799 } 3785 3800 if ( ! in_array( $value, $allowed ) && ! empty( $value ) ) { 3786 $value = get_option( $option ); 3801 if ( 'network' === $context ) { 3802 $value = get_network_option( $context_id, $option, false ); 3803 } else { 3804 $value = get_option( $option ); 3805 } 3787 3806 } 3788 3807 break; 3789 3808 … … 3863 3882 } 3864 3883 3865 3884 if ( ! empty( $error ) ) { 3866 $value = get_option( $option ); 3885 if ( 'network' === $context ) { 3886 $value = get_network_option( $context_id, $option, false ); 3887 } else { 3888 $value = get_option( $option ); 3889 } 3867 3890 if ( function_exists( 'add_settings_error' ) ) { 3868 3891 add_settings_error( $option, "invalid_{$option}", $error ); 3869 3892 } … … 3870 3893 } 3871 3894 3872 3895 /** 3896 * Filter an option value following sanitization based on its context. 3897 * 3898 * The dynamic part $context of the filter determines what kind of option is being sanitized. 3899 * It can be set to either 'site' or 'network'. 3900 * 3901 * The $option part of the filter is the option name being sanitized. 3902 * 3903 * @since 4.6.0 3904 * 3905 * @param string $value The sanitized option value. 3906 * @param string $option The option name. 3907 * @param string $original_value The original value passed to the function. 3908 */ 3909 $value = apply_filters( "sanitize_{$context}_context_option_{$option}", $value, $option, $original_value ); 3910 3911 /** 3873 3912 * Filter an option value following sanitization. 3874 3913 * 3914 * This filter is here for backwards compatibility. You should use the 3915 * `sanitize_{$context}_context_option_{$option}` filter instead. 3916 * 3875 3917 * @since 2.3.0 3876 3918 * @since 4.3.0 Added the `$original_value` parameter. 3877 3919 * -
src/wp-includes/option.php
1239 1239 } 1240 1240 } 1241 1241 1242 $value = sanitize_option( $option, $value );1242 $value = sanitize_option( $option, $value, 'network', $network_id ); 1243 1243 1244 1244 $serialized_value = maybe_serialize( $value ); 1245 1245 $result = $wpdb->insert( $wpdb->sitemeta, array( 'site_id' => $network_id, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); … … 1437 1437 if ( ! is_multisite() ) { 1438 1438 $result = update_option( $option, $value, 'no' ); 1439 1439 } else { 1440 $value = sanitize_option( $option, $value );1440 $value = sanitize_option( $option, $value, 'network', $network_id ); 1441 1441 1442 1442 $serialized_value = maybe_serialize( $value ); 1443 1443 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) );