Make WordPress Core

Ticket #32350: 32350.diff

File 32350.diff, 7.2 KB (added by wonderboymusic, 10 years ago)
  • src/wp-includes/formatting.php

     
    33653365        global $wpdb;
    33663366
    33673367        $original_value = $value;
     3368        $error = '';
    33683369
    33693370        switch ( $option ) {
    33703371                case 'admin_email' :
    33713372                case 'new_admin_email' :
    33723373                        $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    3373                         $value = sanitize_email( $value );
    3374                         if ( ! is_email( $value ) ) {
    3375                                 $value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
    3376                                 if ( function_exists( 'add_settings_error' ) )
    3377                                         add_settings_error( $option, 'invalid_admin_email', __( 'The email address entered did not appear to be a valid email address. Please enter a valid email address.' ) );
     3374                        if ( is_wp_error( $value ) ) {
     3375                                $error = $value->get_error_message();
     3376                        } else {
     3377                                $value = sanitize_email( $value );
     3378                                if ( ! is_email( $value ) ) {
     3379                                        $error = __( 'The email address entered did not appear to be a valid email address. Please enter a valid email address.' );
     3380                                }
    33783381                        }
    33793382                        break;
    33803383
     
    34193422                case 'blogdescription':
    34203423                case 'blogname':
    34213424                        $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    3422                         $value = wp_kses_post( $value );
    3423                         $value = esc_html( $value );
     3425                        if ( is_wp_error( $value ) ) {
     3426                                $error = $value->get_error_message();
     3427                        } else {
     3428                                $value = wp_kses_post( $value );
     3429                                $value = esc_html( $value );
     3430                        }
    34243431                        break;
    34253432
    34263433                case 'blog_charset':
     
    34423449                case 'mailserver_pass':
    34433450                case 'upload_path':
    34443451                        $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    3445                         $value = strip_tags( $value );
    3446                         $value = wp_kses_data( $value );
     3452                        if ( is_wp_error( $value ) ) {
     3453                                $error = $value->get_error_message();
     3454                        } else {
     3455                                $value = strip_tags( $value );
     3456                                $value = wp_kses_data( $value );
     3457                        }
    34473458                        break;
    34483459
    34493460                case 'ping_sites':
     
    34593470
    34603471                case 'siteurl':
    34613472                        $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    3462                         if ( (bool)preg_match( '#http(s?)://(.+)#i', $value) ) {
    3463                                 $value = esc_url_raw($value);
     3473                        if ( is_wp_error( $value ) ) {
     3474                                $error = $value->get_error_message();
    34643475                        } else {
    3465                                 $value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
    3466                                 if ( function_exists('add_settings_error') )
    3467                                         add_settings_error('siteurl', 'invalid_siteurl', __('The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.'));
     3476                                if ( preg_match( '#http(s?)://(.+)#i', $value ) ) {
     3477                                        $value = esc_url_raw( $value );
     3478                                } else {
     3479                                        $error = __( 'The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.' );
     3480                                }
    34683481                        }
    34693482                        break;
    34703483
    34713484                case 'home':
    34723485                        $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    3473                         if ( (bool)preg_match( '#http(s?)://(.+)#i', $value) ) {
    3474                                 $value = esc_url_raw($value);
     3486                        if ( is_wp_error( $value ) ) {
     3487                                $error = $value->get_error_message();
    34753488                        } else {
    3476                                 $value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
    3477                                 if ( function_exists('add_settings_error') )
    3478                                         add_settings_error('home', 'invalid_home', __('The Site address you entered did not appear to be a valid URL. Please enter a valid URL.'));
     3489                                if ( preg_match( '#http(s?)://(.+)#i', $value ) ) {
     3490                                        $value = esc_url_raw( $value );
     3491                                } else {
     3492                                        $error = __( 'The Site address you entered did not appear to be a valid URL. Please enter a valid URL.' );
     3493                                }
    34793494                        }
    34803495                        break;
    34813496
     
    34913506
    34923507                case 'illegal_names':
    34933508                        $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    3494                         if ( ! is_array( $value ) )
    3495                                 $value = explode( ' ', $value );
     3509                        if ( is_wp_error( $value ) ) {
     3510                                $error = $value->get_error_message();
     3511                        } else {
     3512                                if ( ! is_array( $value ) )
     3513                                        $value = explode( ' ', $value );
    34963514
    3497                         $value = array_values( array_filter( array_map( 'trim', $value ) ) );
     3515                                $value = array_values( array_filter( array_map( 'trim', $value ) ) );
    34983516
    3499                         if ( ! $value )
    3500                                 $value = '';
     3517                                if ( ! $value )
     3518                                        $value = '';
     3519                        }
    35013520                        break;
    35023521
    35033522                case 'limited_email_domains':
    35043523                case 'banned_email_domains':
    35053524                        $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    3506                         if ( ! is_array( $value ) )
    3507                                 $value = explode( "\n", $value );
     3525                        if ( is_wp_error( $value ) ) {
     3526                                $error = $value->get_error_message();
     3527                        } else {
     3528                                if ( ! is_array( $value ) )
     3529                                        $value = explode( "\n", $value );
    35083530
    3509                         $domains = array_values( array_filter( array_map( 'trim', $value ) ) );
    3510                         $value = array();
     3531                                $domains = array_values( array_filter( array_map( 'trim', $value ) ) );
     3532                                $value = array();
    35113533
    3512                         foreach ( $domains as $domain ) {
    3513                                 if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
    3514                                         $value[] = $domain;
     3534                                foreach ( $domains as $domain ) {
     3535                                        if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) ) {
     3536                                                $value[] = $domain;
     3537                                        }
     3538                                }
     3539                                if ( ! $value )
     3540                                        $value = '';
    35153541                        }
    3516                         if ( ! $value )
    3517                                 $value = '';
    35183542                        break;
    35193543
    35203544                case 'timezone_string':
    35213545                        $allowed_zones = timezone_identifiers_list();
    35223546                        if ( ! in_array( $value, $allowed_zones ) && ! empty( $value ) ) {
    3523                                 $value = get_option( $option ); // Resets option to stored value in the case of failed sanitization
    3524                                 if ( function_exists('add_settings_error') )
    3525                                         add_settings_error('timezone_string', 'invalid_timezone_string', __('The timezone you have entered is not valid. Please select a valid timezone.') );
     3547                                $error = __( 'The timezone you have entered is not valid. Please select a valid timezone.' );
    35263548                        }
    35273549                        break;
    35283550
     
    35303552                case 'category_base':
    35313553                case 'tag_base':
    35323554                        $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    3533                         $value = esc_url_raw( $value );
    3534                         $value = str_replace( 'http://', '', $value );
     3555                        if ( is_wp_error( $value ) ) {
     3556                                $error = $value->get_error_message();
     3557                        } else {
     3558                                $value = esc_url_raw( $value );
     3559                                $value = str_replace( 'http://', '', $value );
     3560                        }
    35353561                        break;
    35363562
    35373563                case 'default_role' :
     
    35423568                case 'moderation_keys':
    35433569                case 'blacklist_keys':
    35443570                        $value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
    3545                         $value = explode( "\n", $value );
    3546                         $value = array_filter( array_map( 'trim', $value ) );
    3547                         $value = array_unique( $value );
    3548                         $value = implode( "\n", $value );
     3571                        if ( is_wp_error( $value ) ) {
     3572                                $error = $value->get_error_message();
     3573                        } else {
     3574                                $value = explode( "\n", $value );
     3575                                $value = array_filter( array_map( 'trim', $value ) );
     3576                                $value = array_unique( $value );
     3577                                $value = implode( "\n", $value );
     3578                        }
    35493579                        break;
    35503580        }
    35513581
     3582        if ( ! empty( $error ) ) {
     3583                $value = get_option( $option );
     3584                if ( function_exists( 'add_settings_error' ) ) {
     3585                        add_settings_error( $option, "invalid_{$option}", $error );
     3586                }
     3587        }
     3588
    35523589        /**
    35533590         * Filter an option value following sanitization.
    35543591         *