WordPress.org

Make WordPress Core

Ticket #10970: 10970.2.diff

File 10970.2.diff, 2.7 KB (added by scribu, 4 years ago)

Make www preference consistent

  • wp-admin/options-general.php

     
    7171<span class="description"><?php _e('In a few words, explain what this blog is about.') ?></span></td> 
    7272</tr> 
    7373<tr valign="top"> 
    74 <th scope="row"><label for="siteurl"><?php _e('WordPress address (URL)') ?></label></th> 
    75 <td><input name="siteurl" type="text" id="siteurl" value="<?php form_option('siteurl'); ?>" class="regular-text code<?php if ( defined( 'WP_SITEURL' ) ) : ?> disabled" disabled="disabled"<?php else: ?>"<?php endif; ?> /></td> 
    76 </tr> 
    77 <tr valign="top"> 
    7874<th scope="row"><label for="home"><?php _e('Blog address (URL)') ?></label></th> 
    7975<td><input name="home" type="text" id="home" value="<?php form_option('home'); ?>" class="regular-text code<?php if ( defined( 'WP_HOME' ) ) : ?> disabled" disabled="disabled"<?php else: ?>"<?php endif; ?> /> 
    8076<span class="description"><?php _e('Enter the address here if you want your blog homepage <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">to be different from the directory</a> you installed WordPress.'); ?></span></td> 
  • wp-admin/options.php

     
    3030        'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'show_on_front', 'page_on_front', 'page_for_posts' ), 
    3131        'writing' => array( 'default_post_edit_rows', 'use_smilies', 'ping_sites', 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'enable_app', 'enable_xmlrpc' ), 
    3232        'options' => array( '' ) ); 
    33 if ( !defined( 'WP_SITEURL' ) ) $whitelist_options['general'][] = 'siteurl'; 
    3433if ( !defined( 'WP_HOME' ) ) $whitelist_options['general'][] = 'home'; 
    3534 
    3635$whitelist_options = apply_filters( 'whitelist_options', $whitelist_options ); 
     
    7170                        $_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']); 
    7271                        $_POST['timezone_string'] = ''; 
    7372                } 
     73 
     74                // Make 'www' preference consistent 
     75                $home = $_POST['home']; 
     76                $siteurl = get_option('siteurl'); 
     77 
     78                $siteurl_www = ( FALSE !== strpos($siteurl, '://www.') ); 
     79                $home_www = ( FALSE !== strpos($home, '://www.') ); 
     80 
     81                if ( $home_www && !$siteurl_www ) 
     82                        update_option('siteurl', str_replace('://', '://www.', $siteurl)); 
     83                elseif ( !$home_www && $siteurl_www ) 
     84                        update_option('siteurl', str_replace('://www.', '://', $siteurl)); 
    7485        } 
    7586 
    7687        if ( $options ) {