Ticket #462: blog-user.diff

File blog-user.diff, 6.4 kB (added by ktlee, 1 year ago)
  • wp-admin/wpmu-blogs.php

    old new  
    631631                                        <tr><th style="text-align:center;" scope='row'><?php _e('Blog Title') ?></th><td><input name="blog[title]" type="text" size="20" title="<?php _e('Title') ?>"/></td></tr> 
    632632                                        <tr><th style="text-align:center;" scope='row'><?php _e('Admin Email') ?></th><td><input name="blog[email]" type="text" size="20" title="<?php _e('Email') ?>"/></td></tr> 
    633633                                        <tr><td colspan='2'><?php _e('A new user will be created if the above email address is not in the database.') ?></td></tr> 
     634                                        <tr><td colspan='2'><?php _e('His username and password will be mailed to this email address.') ?></td></tr> 
    634635                                </table> 
    635636                                <input class="button" type="submit" name="go" value="<?php _e('Add Blog') ?>" /> 
    636637                        </form> 
  • wp-admin/wpmu-users.php

    old new  
    278278                                <th style="text-align:center;" scope='row'><?php _e('Email') ?></th> 
    279279                                <td><input type="text" name="user[email]" /></td> 
    280280                        </tr> 
     281                        <tr><td colspan='2'><?php _e('Username and password will be mailed to the above email address.') ?></td></tr> 
    281282                </table> 
    282283                <p> 
    283284                        <?php wp_nonce_field('add-user') ?> 
  • wp-admin/wpmu-edit.php

    old new  
    8585        case "addblog": 
    8686                check_admin_referer('add-blog'); 
    8787 
    88                 if( is_array( $_POST['blog'] ) == true ) { 
    89                         $blog = $_POST['blog']; 
    90                         $domain = strtolower( wp_specialchars( $blog['domain'] ) ); 
    91                         $email = wp_specialchars( $blog['email'] ); 
    92                         if( !is_email( $email ) )  
    93                 wp_die( __("<p>Invalid email address</p>") );  
    94                          
    95                         if( constant( "VHOST" ) == 'yes' ) { 
    96                                 $newdomain = $domain.".".$current_site->domain; 
    97                                 $path = $base; 
    98                         } else { 
    99                                 $newdomain = $current_site->domain; 
    100                                 $path = $base.$domain.'/'; 
    101                         } 
     88                $blog = $_POST['blog']; 
     89                $domain = strtolower( wp_specialchars( $blog['domain'] ) ); 
     90                $email = wp_specialchars( $blog['email'] ); 
     91                 
     92                if ( empty($domain) || empty($email)) 
     93                        wp_die( __("<p>Missing blog address or email address.</p>") ); 
     94                if( !is_email( $email ) )  
     95                        wp_die( __("<p>Invalid email address</p>") );  
     96                 
     97                if( constant( "VHOST" ) == 'yes' ) { 
     98                        $newdomain = $domain.".".$current_site->domain; 
     99                        $path = $base; 
     100                } else { 
     101                        $newdomain = $current_site->domain; 
     102                        $path = $base.$domain.'/'; 
     103                } 
    102104 
    103                         $user_id = email_exists($email); 
    104                         if( !$user_id ) { // I'm not sure what this check should be. 
    105                                 $password = generate_random_password(); 
    106                                 $user_id = wpmu_create_user( $domain, $password, $email ); 
    107                                 if(false == $user_id) { 
    108                                         wp_die( __("<p>There was an error creating the user</p>") ); 
    109                                 } else { 
    110                                         wp_new_user_notification($user_id, $password); 
    111                                 } 
    112                         } 
    113  
    114                         $wpdb->hide_errors(); 
    115                         $blog_id = wpmu_create_blog($newdomain, $path, wp_specialchars( $blog['title'] ), $user_id ,'', $current_site->id); 
    116                         $wpdb->show_errors(); 
    117                         if( !is_wp_error($blog_id) ) { 
    118                                 if( get_user_option( $user_id, 'primary_blog' ) == 1 ) 
    119                                         update_user_option( $user_id, 'primary_blog', $blog_id, true ); 
    120                                 $content_mail = sprintf(__("New blog created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain.$path, wp_specialchars($blog['title']) ); 
    121                                 wp_mail( get_site_option('admin_email'),  sprintf(__('[%s] New Blog Created'), $current_site->site_name), $content_mail, 'From: "Site Admin" <' . get_site_option( 'admin_email' ) . '>' ); 
    122                                 wp_redirect( add_query_arg( array('updated' => 'true', 'action' => 'add-blog'), $_SERVER['HTTP_REFERER'] ) ); 
    123                                 exit(); 
     105                $user_id = email_exists($email); 
     106                if( !$user_id ) { // I'm not sure what this check should be. 
     107                        $password = generate_random_password(); 
     108                        $user_id = wpmu_create_user( $domain, $password, $email ); 
     109                        if(false == $user_id) { 
     110                                wp_die( __("<p>There was an error creating the user</p>") ); 
    124111                        } else { 
    125                                 die( $blog_id->get_error_message() ); 
     112                                wp_new_user_notification($user_id, $password); 
    126113                        } 
    127114                } 
     115 
     116                $wpdb->hide_errors(); 
     117                $blog_id = wpmu_create_blog($newdomain, $path, wp_specialchars( $blog['title'] ), $user_id ,'', $current_site->id); 
     118                $wpdb->show_errors(); 
     119                if( !is_wp_error($blog_id) ) { 
     120                        if( get_user_option( $user_id, 'primary_blog' ) == 1 ) 
     121                                update_user_option( $user_id, 'primary_blog', $blog_id, true ); 
     122                        $content_mail = sprintf(__("New blog created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain.$path, wp_specialchars($blog['title']) ); 
     123                        wp_mail( get_site_option('admin_email'),  sprintf(__('[%s] New Blog Created'), $current_site->site_name), $content_mail, 'From: "Site Admin" <' . get_site_option( 'admin_email' ) . '>' ); 
     124                        wp_redirect( add_query_arg( array('updated' => 'true', 'action' => 'add-blog'), $_SERVER['HTTP_REFERER'] ) ); 
     125                        exit(); 
     126                } else { 
     127                        die( $blog_id->get_error_message() ); 
     128                } 
    128129        break; 
    129130         
    130131        case "updateblog": 
     
    400401        case "adduser": 
    401402                check_admin_referer('add-user'); 
    402403 
    403                 if( is_array( $_POST['user'] ) == true ) { 
    404                         $user = $_POST['user']; 
    405                         if ( empty($user['username']) || empty($user['email']) ) { 
    406                                 wp_die( __("<p>Missing username and email.</p>") ); 
    407                         }                        
    408                         $password = generate_random_password(); 
    409                         $user_id = wpmu_create_user(wp_specialchars( strtolower( $user['username'] ) ), $password, wp_specialchars( $user['email'] ) ); 
    410                         if( false == $user_id ) { 
    411                                 wp_die( __("<p>There was an error creating the user</p>") ); 
    412                         } else { 
    413                                 wp_new_user_notification($user_id, $password); 
    414                         } 
    415                 } 
     404                $user = $_POST['user']; 
     405                if ( empty($user['username']) || empty($user['email']) ) 
     406                        wp_die( __("<p>Missing username or email.</p>") ); 
     407                if ( !is_email($user['email']) ) 
     408                        wp_die( __("<p>Invalid email address.</p>") ); 
     409 
     410                $password = generate_random_password(); 
     411                $user_id = wpmu_create_user(wp_specialchars( strtolower( $user['username'] ) ), $password, wp_specialchars( $user['email'] ) ); 
     412                 
     413                if( false == $user_id ) 
     414                        wp_die( __("<p>Duplicated username or email address.</p>") ); 
     415                else 
     416                        wp_new_user_notification($user_id, $password); 
     417 
    416418                wp_redirect( add_query_arg( array('updated' => 'true', 'action' => 'add'), $_SERVER['HTTP_REFERER'] ) ); 
    417419                exit(); 
    418420        break;