Changeset 967

Show
Ignore:
Timestamp:
04/10/08 14:28:56 (8 months ago)
Author:
thomasklaiber
Message:

tag 1.3

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • admin-add-user/trunk/admin-add-user.php

    r700 r967  
    22/** 
    33 * Plugin Name: Admin add user 
    4  * Plugin Description: Allows Keymasters to add user through the administration panel. 
     4 * Plugin Description: Allows keymasters to add user through the administration panel. 
    55 * Author: Thomas Klaiber 
    66 * Author URI: http://thomasklaiber.com/ 
    77 * Plugin URI: http://thomasklaiber.com/bbpress/admin-add-user/ 
    8  * Version: 1.2 
     8 * Version: 1.3 
    99 */ 
    1010  
    1111function admin_add_user_adminpage() { 
    12         global $bbdb, $bb, $bb_table_prefix; 
     12        global $bbdb, $bb; 
     13         
     14        // get the default registration functions 
     15        require_once( BB_PATH . BB_INC . 'registration-functions.php'); 
    1316?> 
    1417<h2><?php _e('Add New User') ?></h2> 
     
    2023        if (empty($_POST['user_login'])) : 
    2124                $admin_add_user_error['user_login'] = "<li><strong>ERROR</strong>: Please enter a username.</li>"; 
    22         elseif (bb_user_exists(user_sanitize($_POST['user_login'], true))) : 
     25        elseif (bb_user_exists(sanitize_user($_POST['user_login'], true))) : 
    2326                $admin_add_user_error['user_login'] = "<li><strong>ERROR</strong>: This username is already taken.</li>";        
    2427        endif; 
     
    3639        if (!$admin_add_user_error) : 
    3740         
    38                 $now = bb_current_time('mysql'); 
    39                 $user_login = user_sanitize( $_POST['user_login'], true ); 
     41                $user_login =  $_POST['user_login']; 
    4042                $user_email = $_POST['user_email']; 
    4143                $user_url   = bb_fix_link( $_POST['user_url'] ); 
    4244                $password   = $_POST['pass1']; 
    43                 $passcrypt  = md5( $password ); 
    4445                 
    45                 $bbdb->query("INSERT INTO $bbdb->users 
    46                 (user_login,     user_pass,    user_email,    user_url, user_registered) 
    47                 VALUES 
    48                 ('$user_login', '$passcrypt', '$user_email', '$user_url',   '$now')"); 
     46                if ( $user_id = bb_new_user( $user_login, $user_email, $user_url ) ) { 
     47                        bb_update_user_password( $user_id, $password ); 
     48                         
     49                        bb_update_usermeta( $user_id, $bbdb->prefix . 'capabilities', array('member' => true) ); 
     50                         
     51                        if ($_POST['user_send_email']) : 
     52                                /** 
     53                                 * Sending a mail again is bad, but if we don't do this, 
     54                                 * the user gets a wrong password sent. 
     55                                 * The bb_new_user() function can't be prevented from sending the first mail. 
     56                                 */ 
     57                                $message = __("PLEASE IGNORE THE FIRST MAIL!\n\nYour username is: %1\$s \nYour new password is: %2\$s \nYou can now log in: %3\$s \n\nEnjoy!"); 
     58 
     59                                bb_mail( 
     60                                        $user_email, 
     61                                        bb_get_option('name') . ': ' . __('Password'), 
     62                                        sprintf( $message, $user_login, $password, bb_get_option('uri') ) 
     63                                ); 
     64                        endif;           
    4965         
    50                 $user_id = $bbdb->insert_id; 
    51                 bb_update_usermeta( $user_id, $bb_table_prefix . 'capabilities', array('member' => true) ); 
    52                  
    53                 if ($_POST['user_send_email']) : 
    54                         // why doesn't this work? 
    55                         // bb_send_pass( $user_id, $password ); 
    56                          
    57                         $message = __("Your username is: %1\$s \nYour password is: %2\$s \nYou can now log in: %3\$s \n\nEnjoy!"); 
    58  
    59                         bb_mail( 
    60                                 bb_get_user_email( $user_id ), 
    61                                 bb_get_option('name') . ': ' . __('Password'), 
    62                                 sprintf( $message, "$user_login", "$password", bb_get_option('uri') ) 
    63                         ); 
    64                 endif; 
    65          
    66                 do_action('bb_admin_new_user', $user_id, $password); 
     66                        do_action('bb_admin_new_user', $user_id, $password); 
     67                } 
    6768         
    6869                $admin_add_user_success['user_login'] = "<li>User <strong>".$user_login."</strong> has been added. <a href=\"".get_profile_tab_link($user_id, 'edit')."\">Edit user's profile &raquo;</a></li>"; 
     
    141142function admin_add_user_adminnav() { 
    142143        global $bb_submenu; 
    143         $bb_submenu['users.php'][] = array(__('Add User'), 'use_keys', 'admin_add_user_adminpage'); 
     144        $bb_submenu['users.php'][] = array(__('Add User'), 'administrate', 'admin_add_user_adminpage'); 
    144145} 
    145146add_action( 'bb_admin_menu_generator', 'admin_add_user_adminnav' );