Make WordPress Core

Ticket #12868: 12868-6.diff

File 12868-6.diff, 2.7 KB (added by technosailor, 15 years ago)

-1 on admin_email. I think the scope of this ticket is basically about the site breaking if siteurl is blank. However, attaching patch to handle admin email as well and making it consistent with the rest of the code.

  • wp-includes/formatting.php

     
    23592359        switch ($option) {
    23602360                case 'admin_email':
    23612361                        $value = sanitize_email($value);
    2362                         if ( !$value && function_exists('add_settings_error') )
    2363                                 add_settings_error('admin_email', 'invalid_admin_email', __('The email address submitted was not in the right format. Please enter a valid email address.'));
     2362                        if ( !is_email( $value ) ){
     2363                                $value = get_option( $option ); // Resets option to stored val in case of invalid email
     2364                                if( function_exists('add_settings_error') )
     2365                                        add_settings_error('admin_email', 'invalid_admin_email', __('The email address submitted was not in the right format. Please enter a valid email address.'));
     2366                        }
    23642367                        break;
    23652368
    23662369                case 'thumbnail_size_w':
     
    24342437                        $value = preg_replace('/[^0-9:.-]/', '', $value); // strips slashes
    24352438                        break;
    24362439
    2437                 case 'siteurl':
    2438                 case 'home':
    2439                         $value = esc_url_raw($value);
    2440                         break;
     2440                case 'siteurl':
     2441                        $value = esc_url_raw($value);
     2442                        if ( !is_url( $value ) )
     2443                        {
     2444                                $value = get_option( $option ); // Resets option to stored val in case of empty
     2445                                if( function_exists('add_settings_error') )
     2446                                        add_settings_error('siteurl', 'invalid_siteurl', __('The WordPress address you submitted was not in the right format. Please enter a valid URL.'));
     2447                        }
     2448                        break;
     2449                case 'home':
     2450                        $value = esc_url_raw($value);
     2451                        if ( !is_url( $value ) )
     2452                        {
     2453                                $value = get_option( $option ); // Resets option to stored val in case of empty
     2454                                if( function_exists('add_settings_error') )
     2455                                        add_settings_error('home', 'invalid_home', __('The Site address you submitted was not in the right format. Please enter a valid URL.'));
     2456                        }
     2457                        break;
    24412458                default :
    24422459                        $value = apply_filters("sanitize_option_{$option}", $value, $option);
    24432460                        break;
  • wp-includes/pluggable.php

     
    17491749        return $r;
    17501750}
    17511751endif;
     1752
     1753if( !function_exists('is_url') )
     1754{
     1755        /**
     1756         * Provides minimal validation that a string looks like a URL verifying only that it begins with http or https
     1757         * Note that strings without dots (i.e. localhost) are considered valid RFC domain names so validation does
     1758         * not look for .com, .net, etc
     1759         *
     1760         * @since 3.0
     1761         * @param string $url A URL to be validated.
     1762         * @return boolean
     1763        */
     1764        function is_url( $url )
     1765        {
     1766                preg_match( '#http(s?)://(.+)#i', $url, $matches );
     1767                if( empty( $matches ) )
     1768                        return false;
     1769                       
     1770                return true;
     1771        }
     1772}
     1773 No newline at end of file