Changeset 1364

Show
Ignore:
Timestamp:
07/10/08 12:02:26 (1 year ago)
Author:
donncha
Message:

Use $blogname instead of $blog_id to avoid conflicts with the global variable $blog_id.
This affects the following filters: signup_another_blog_init, signup_blog_init, wpmu_validate_blog_signup.
The "newblog_id" filter becomes "newblogname".
Fixed stack problem with switching and restoring blogs. Fixes #674

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-includes/wpmu-functions.php

    r1354 r1364  
    328328                return; 
    329329 
     330        if ( empty($switched_stack) ) 
     331                $switched_stack = array(); 
     332 
     333        $switched_stack[] = $blog_id; 
     334 
    330335        if ( $blog_id == $new_blog ) 
    331336                return; 
    332  
    333         if ( empty($switched_stack) ) 
    334                 $switched_stack = array(); 
    335  
    336         $switched_stack[] = $blog_id; 
    337337 
    338338        $wpdb->set_blog_id($new_blog); 
     
    894894} 
    895895 
    896 function wpmu_validate_blog_signup($blog_id, $blog_title, $user = '') { 
     896function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { 
    897897        global $wpdb, $domain, $base; 
    898898 
    899         $blog_id = sanitize_user( $blog_id ); 
     899        $blogname = sanitize_user( $blogname ); 
    900900        $blog_title = strip_tags( $blog_title ); 
    901901        $blog_title = substr( $blog_title, 0, 50 ); 
     
    908908        } 
    909909 
    910         if ( empty( $blog_id ) ) 
    911             $errors->add('blog_id', __("Please enter a blog name")); 
     910        if ( empty( $blogname ) ) 
     911            $errors->add('blogname', __("Please enter a blog name")); 
    912912 
    913913        $maybe = array(); 
    914         preg_match( "/[a-z0-9]+/", $blog_id, $maybe ); 
    915         if( $blog_id != $maybe[0] ) { 
    916             $errors->add('blog_id', __("Only lowercase letters and numbers allowed")); 
    917         } 
    918         if( in_array( $blog_id, $illegal_names ) == true ) { 
    919             $errors->add('blog_id',  __("That name is not allowed")); 
    920         } 
    921         if( strlen( $blog_id ) < 4 && !is_site_admin() ) { 
    922             $errors->add('blog_id',  __("Blog name must be at least 4 characters")); 
    923         } 
    924  
    925         if ( strpos( " " . $blog_id, "_" ) != false ) 
    926                 $errors->add('blog_id', __("Sorry, blog names may not contain the character '_'!")); 
     914        preg_match( "/[a-z0-9]+/", $blogname, $maybe ); 
     915        if( $blogname != $maybe[0] ) { 
     916            $errors->add('blogname', __("Only lowercase letters and numbers allowed")); 
     917        } 
     918        if( in_array( $blogname, $illegal_names ) == true ) { 
     919            $errors->add('blogname',  __("That name is not allowed")); 
     920        } 
     921        if( strlen( $blogname ) < 4 && !is_site_admin() ) { 
     922            $errors->add('blogname',  __("Blog name must be at least 4 characters")); 
     923        } 
     924 
     925        if ( strpos( " " . $blogname, "_" ) != false ) 
     926                $errors->add('blogname', __("Sorry, blog names may not contain the character '_'!")); 
    927927 
    928928        // all numeric? 
    929929        $match = array(); 
    930         preg_match( '/[0-9]*/', $blog_id, $match ); 
    931         if ( $match[0] == $blog_id
    932                 $errors->add('blog_id', __("Sorry, blog names must have letters too!")); 
    933  
    934         $blog_id = apply_filters( "newblog_id", $blog_id ); 
     930        preg_match( '/[0-9]*/', $blogname, $match ); 
     931        if ( $match[0] == $blogname
     932                $errors->add('blogname', __("Sorry, blog names must have letters too!")); 
     933 
     934        $blogname = apply_filters( "newblogname", $blogname ); 
    935935 
    936936        $blog_title = stripslashes(  $blog_title ); 
     
    941941        // Check if the domain/path has been used already. 
    942942        if( constant( "VHOST" ) == 'yes' ) { 
    943                 $mydomain = "$blog_id.$domain"; 
     943                $mydomain = "$blogname.$domain"; 
    944944                $path = $base; 
    945945        } else { 
    946946                $mydomain = "$domain"; 
    947                 $path = $base.$blog_id.'/'; 
     947                $path = $base.$blogname.'/'; 
    948948        } 
    949949        if ( domain_exists($mydomain, $path) ) 
    950                 $errors->add('blog_id', __("Sorry, that blog already exists!")); 
    951  
    952         if ( username_exists($blog_id) ) { 
    953                 if  ( !is_object($user) && ( $user->user_login != $blog_id ) ) 
    954                         $errors->add('blog_id', __("Sorry, that blog is reserved!")); 
     950                $errors->add('blogname', __("Sorry, that blog already exists!")); 
     951 
     952        if ( username_exists($blogname) ) { 
     953                if  ( !is_object($user) && ( $user->user_login != $blogname ) ) 
     954                        $errors->add('blogname', __("Sorry, that blog is reserved!")); 
    955955        } 
    956956 
     
    966966                        $wpdb->query("DELETE FROM $wpdb->signups WHERE domain = '$mydomain' AND path = '$path'"); 
    967967                } else { 
    968                         $errors->add('blog_id', __("That blog is currently reserved but may be available in a couple days.")); 
    969                 } 
    970         } 
    971  
    972         $result = array('domain' => $mydomain, 'path' => $path, 'blog_id' => $blog_id, 'blog_title' => $blog_title, 
     968                        $errors->add('blogname', __("That blog is currently reserved but may be available in a couple days.")); 
     969                } 
     970        } 
     971 
     972        $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 
    973973                                'errors' => $errors); 
    974974 
     
    11661166 
    11671167        if ( is_array($meta) ) foreach ($meta as $key => $value) { 
    1168                 update_blog_status( $blog_id, $key, $value ); 
    1169                 update_option( $blog_id, $key, $value ); 
    1170         } 
    1171  
    1172         add_option( $blog_id, 'WPLANG', get_site_option( 'WPLANG' ) ); 
    1173  
    1174         update_option( $blog_id, 'blog_public', $meta['public'] ); 
    1175         delete_blog_option( $blog_id, 'public' ); 
     1168                if( $key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id' ) { 
     1169                        update_blog_status( $blog_id, $key, $value ); 
     1170                } else { 
     1171                        update_option( $blog_id, $key, $value ); 
     1172                } 
     1173        } 
     1174 
     1175        add_option( 'WPLANG', get_site_option( 'WPLANG' ) ); 
     1176 
     1177        update_option( 'blog_public', $meta['public'] ); 
    11761178 
    11771179        if(get_usermeta( $user_id, 'primary_blog' ) == 1 ) 
  • trunk/wp-signup.php

    r1330 r1364  
    3535                        .mu_register #blog_title, 
    3636                        .mu_register #user_email,  
    37                         .mu_register #blog_id
     37                        .mu_register #blogname
    3838                        .mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; }   
    3939                .mu_register .prefix_address, 
     
    5252<div class="mu_register"> 
    5353<?php 
    54 function show_blog_form($blog_id = '', $blog_title = '', $errors = '') { 
     54function show_blog_form($blogname = '', $blog_title = '', $errors = '') { 
    5555        global $current_site; 
    5656        // Blog name 
    5757        if( constant( "VHOST" ) == 'no' ) 
    58                 echo '<label for="blog_id">' . __('Blog Name:') . '</label>'; 
     58                echo '<label for="blogname">' . __('Blog Name:') . '</label>'; 
    5959        else 
    60                 echo '<label for="blog_id">' . __('Blog Domain:') . '</label>'; 
    61  
    62         if ( $errmsg = $errors->get_error_message('blog_id') ) { ?> 
     60                echo '<label for="blogname">' . __('Blog Domain:') . '</label>'; 
     61 
     62        if ( $errmsg = $errors->get_error_message('blogname') ) { ?> 
    6363                <p class="error"><?php echo $errmsg ?></p> 
    6464        <?php } 
    6565 
    6666        if( constant( "VHOST" ) == 'no' ) { 
    67                 echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blog_id" type="text" id="blog_id" value="'.$blog_id.'" maxlength="50" /><br />'; 
     67                echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />'; 
    6868        } else { 
    69                 echo '<input name="blog_id" type="text" id="blog_id" value="'.$blog_id.'" maxlength="50" /><span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />'; 
     69                echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />'; 
    7070        } 
    7171        if ( !is_user_logged_in() ) { 
     
    111111                $user = wp_get_current_user(); 
    112112 
    113         return wpmu_validate_blog_signup($_POST['blog_id'], $_POST['blog_title'], $user); 
     113        return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user); 
    114114} 
    115115 
     
    140140} 
    141141 
    142 function signup_another_blog($blog_id = '', $blog_title = '', $errors = '') { 
     142function signup_another_blog($blogname = '', $blog_title = '', $errors = '') { 
    143143        global $current_user, $current_site; 
    144144         
     
    148148 
    149149        // allow definition of default variables 
    150         $filtered_results = apply_filters('signup_another_blog_init', array('blog_id' => $blog_id, 'blog_title' => $blog_title, 'errors' => $errors )); 
    151         $blog_id = $filtered_results['blog_id']; 
     150        $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors )); 
     151        $blogname = $filtered_results['blogname']; 
    152152        $blog_title = $filtered_results['blog_title']; 
    153153        $errors = $filtered_results['errors']; 
     
    178178                <input type="hidden" name="stage" value="gimmeanotherblog" /> 
    179179                <?php do_action( "signup_hidden_fields" ); ?> 
    180                 <?php show_blog_form($blog_id, $blog_title, $errors); ?> 
     180                <?php show_blog_form($blogname, $blog_title, $errors); ?> 
    181181                <p> 
    182182                        <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog &raquo;') ?>" /></p> 
     
    186186 
    187187function validate_another_blog_signup() { 
    188         global $wpdb, $current_user, $blog_id, $blog_title, $errors, $domain, $path; 
     188        global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path; 
    189189        $current_user = wp_get_current_user(); 
    190190        if( !is_user_logged_in() ) 
     
    195195 
    196196        if ( $errors->get_error_code() ) { 
    197                 signup_another_blog($blog_id, $blog_title, $errors); 
     197                signup_another_blog($blogname, $blog_title, $errors); 
    198198                return false; 
    199199        } 
     
    291291} 
    292292 
    293 function signup_blog($user_name = '', $user_email = '', $blog_id = '', $blog_title = '', $errors = '') { 
     293function signup_blog($user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '') { 
    294294        if ( !is_wp_error($errors) ) 
    295295                $errors = new WP_Error(); 
    296296 
    297297        // allow definition of default variables 
    298         $filtered_results = apply_filters('signup_blog_init', array('user_name' => $user_name, 'user_email' => $user_email, 'blog_id' => $blog_id, 'blog_title' => $blog_title, 'errors' => $errors )); 
     298        $filtered_results = apply_filters('signup_blog_init', array('user_name' => $user_name, 'user_email' => $user_email, 'blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors )); 
    299299        $user_name = $filtered_results['user_name']; 
    300300        $user_email = $filtered_results['user_email']; 
    301         $blog_id = $filtered_results['blog_id']; 
     301        $blogname = $filtered_results['blogname']; 
    302302        $blog_title = $filtered_results['blog_title']; 
    303303        $errors = $filtered_results['errors']; 
    304304 
    305         if ( empty($blog_id) ) 
    306                 $blog_id = $user_name; 
     305        if ( empty($blogname) ) 
     306                $blogname = $user_name; 
    307307        ?> 
    308308        <form id="setupform" method="post" action="wp-signup.php"> 
     
    311311                <input type="hidden" name="user_email" value="<?php echo $user_email ?>" /> 
    312312                <?php do_action( "signup_hidden_fields" ); ?> 
    313                 <?php show_blog_form($blog_id, $blog_title, $errors); ?> 
     313                <?php show_blog_form($blogname, $blog_title, $errors); ?> 
    314314                <p> 
    315315                        <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Signup &raquo;') ?>" /></p> 
     
    328328        } 
    329329 
    330         $result = wpmu_validate_blog_signup($_POST['blog_id'], $_POST['blog_title']); 
     330        $result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title']); 
    331331        extract($result); 
    332332 
    333333        if ( $errors->get_error_code() ) { 
    334                 signup_blog($user_name, $user_email, $blog_id, $blog_title, $errors); 
     334                signup_blog($user_name, $user_email, $blogname, $blog_title, $errors); 
    335335                return false; 
    336336        } 
     
    352352        <p><?php printf(__('Check your inbox at <strong>%s</strong> and click the link given. It should arrive within 30 minutes.'),  $user_email) ?></p> 
    353353        <p><?php _e('If you do not activate your blog within two days, you will have to sign up again.'); ?></p> 
    354         <h2><?php _e('Still waiting for your email?') ?></h2> 
     354        <h2><?php _e('Still waiting for your email?'); ?></h2> 
    355355        <p> 
    356356                <?php _e("If you haven't received your email yet, there are a number of things you can do:") ?>