Make WordPress Core

Ticket #12868: 12868-3.diff

File 12868-3.diff, 1.9 KB (added by technosailor, 15 years ago)

New patch makes sure the value _looks_ like a valid URL using a new function is_url() which provides minimal validation. Much more could be done with it but domains like 'localhost' fail traditional URL regex's

  • wp-includes/formatting.php

     
    24352435                        break;
    24362436
    24372437                case 'siteurl':
     2438                        $value = esc_url_raw($value);
     2439                        if ( !is_url( $value ) && function_exists('add_settings_error') )
     2440                        {
     2441                                $value = get_option( $option ); // Resets option to stored val in case of empty
     2442                                add_settings_error('siteurl', 'invalid_siteurl', __('The WordPress address you submitted was not in the right format. Please enter a valid URL.'));
     2443                        }
     2444                        break;
    24382445                case 'home':
    24392446                        $value = esc_url_raw($value);
     2447                        if ( !is_url( $value ) && function_exists('add_settings_error') )
     2448                        {
     2449                                $value = get_option( $option ); // Resets option to stored val in case of empty
     2450                                add_settings_error('home', 'invalid_home', __('The Site address you submitted was not in the right format. Please enter a valid URL.'));
     2451                        }
    24402452                        break;
    24412453                default :
    24422454                        $value = apply_filters("sanitize_option_{$option}", $value, $option);
  • 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