Changeset 1122

Show
Ignore:
Timestamp:
10/22/07 17:46:24 (11 months ago)
Author:
donncha
Message:

Cleanup user and blog add code. props ktlee, fixes #462

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/wpmu-blogs.php

    r1092 r1122  
    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('The 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') ?>" /> 
  • trunk/wp-admin/wpmu-edit.php

    r1120 r1122  
    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; 
     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                } 
     104 
     105                $user_id = email_exists($email); 
     106                if( !$user_id ) { 
     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>") ); 
    98111                        } else { 
    99                                 $newdomain = $current_site->domain; 
    100                                 $path = $base.$domain.'/'; 
    101                         } 
    102  
    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(); 
    124                         } else { 
    125                                 die( $blog_id->get_error_message() ); 
    126                         } 
     112                                wp_new_user_notification($user_id, $password); 
     113                        } 
     114                } 
     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() ); 
    127128                } 
    128129        break; 
     
    403404                check_admin_referer('add-user'); 
    404405 
    405                 if( is_array( $_POST['user'] ) == true ) { 
    406                        $user = $_POST['user']; 
    407                         if ( empty($user['username']) && empty($user['email']) ) { 
    408                                wp_die( __("<p>Missing username and email.</p>") ); 
    409                         } elseif ( empty($user['username']) ) { 
    410                                wp_die( __("<p>Missing username.</p>") ); 
    411                         } elseif ( empty($user['email']) ) { 
    412                                wp_die( __("<p>Missing email.</p>") ); 
    413                         } 
    414                         
    415                        $password = generate_random_password(); 
    416                         $user_id = wpmu_create_user(wp_specialchars( strtolower( $user['username'] ) ), $password, wp_specialchars( $user['email'] ) ); 
    417                        if( false == $user_id ) { 
    418                                wp_die( __("<p>There was an error creating the user</p>") ); 
    419                        } else { 
    420                                wp_new_user_notification($user_id, $password); 
    421                        
    422                 } 
     406                $user = $_POST['user']; 
     407                if ( empty($user['username']) && empty($user['email']) ) { 
     408                        wp_die( __("<p>Missing username and email.</p>") ); 
     409                } elseif ( empty($user['username']) ) { 
     410                        wp_die( __("<p>Missing username.</p>") ); 
     411                } elseif ( empty($user['email']) ) { 
     412                        wp_die( __("<p>Missing email.</p>") ); 
     413                } 
     414 
     415                $password = generate_random_password(); 
     416                $user_id = wpmu_create_user(wp_specialchars( strtolower( $user['username'] ) ), $password, wp_specialchars( $user['email'] ) ); 
     417 
     418                if( false == $user_id ) { 
     419                       wp_die( __("<p>Duplicated username or email address.</p>") ); 
     420                } else { 
     421                        wp_new_user_notification($user_id, $password); 
     422               
     423 
    423424                wp_redirect( add_query_arg( array('updated' => 'true', 'action' => 'add'), $_SERVER['HTTP_REFERER'] ) ); 
    424425                exit(); 
  • trunk/wp-admin/wpmu-users.php

    r1096 r1122  
    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>