| | 1 | <?php |
| | 2 | require_once('admin.php'); |
| | 3 | |
| | 4 | global $wp_roles, $wp_users_object, $bbdb; |
| | 5 | |
| | 6 | if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && $_POST['action'] == 'create' ) { |
| | 7 | |
| | 8 | bb_check_admin_referer( 'user-new-create' ); |
| | 9 | |
| | 10 | // Create the new user |
| | 11 | $create_user_errors = new WP_Error; |
| | 12 | $_POST = stripslashes_deep( $_POST ); |
| | 13 | $user_login = $_POST['user_login']; |
| | 14 | $user_email = $_POST['user_email']; |
| | 15 | $user_url = $_POST['user_url']; |
| | 16 | $user_meta['from'] = $_POST['from']; |
| | 17 | $user_meta['occ'] = $_POST['occ']; |
| | 18 | $user_meta['interest'] = $_POST['interest']; |
| | 19 | $user_role = $_POST['userrole']; |
| | 20 | $user_pass1 = $_POST['pass1']; |
| | 21 | $user_pass2 = $_POST['pass2']; |
| | 22 | $user_status = 0; |
| | 23 | $user_pass = false; |
| | 24 | |
| | 25 | $user_url = $user_url ? bb_fix_link( $user_url ) : ''; |
| | 26 | |
| | 27 | if ( ( !empty($user_pass1) || !empty($user_pass2) ) && $user_pass1 !== $user_pass2 ) |
| | 28 | $create_user_errors->add( 'pass', __( 'You must enter the same password twice.' ) ); |
| | 29 | else |
| | 30 | $user_pass = $user_pass1; |
| | 31 | |
| | 32 | if( is_wp_error( $create_user_errors ) ) { |
| | 33 | $user = $wp_users_object->new_user( compact( 'user_login', 'user_email', 'user_url', 'user_nicename', 'user_status', 'user_pass' ) ); |
| | 34 | if ( is_wp_error($user) ) { |
| | 35 | bb_admin_notice( $user ); |
| | 36 | } else { |
| | 37 | bb_update_usermeta( $user['ID'], $bbdb->prefix . 'capabilities', array($user_role => true) ); |
| | 38 | foreach($user_meta as $key => $mta) |
| | 39 | bb_update_usermeta($user['ID'], $key, $mta ); |
| | 40 | bb_send_pass( $user['ID'], $user['plain_pass'] ); |
| | 41 | do_action('bb_new_user', $user['ID'], $user['plain_pass']); |
| | 42 | } |
| | 43 | $goback = add_query_arg( 'created', 'true', wp_get_referer() ); |
| | 44 | bb_safe_redirect( $goback ); |
| | 45 | } else { |
| | 46 | bb_admin_notice( $create_user_errors ); |
| | 47 | } |
| | 48 | } |
| | 49 | |
| | 50 | // Get all errors and print as notice |
| | 51 | if ( !empty( $_GET['created'] ) ) |
| | 52 | bb_admin_notice( __( '<strong>User Created.</strong>' ) ); |
| | 53 | |
| | 54 | // Load password strength checker |
| | 55 | wp_enqueue_script( 'password-strength-meter' ); |
| | 56 | wp_enqueue_script( 'profile-edit' ); |
| | 57 | |
| | 58 | $bb_admin_body_class = ' bb-admin-user-new'; |
| | 59 | |
| | 60 | bb_get_admin_header(); |
| | 61 | |
| | 62 | $user_roles = apply_filters( 'bb_user_search_form_roles', $wp_roles->get_names() ); |
| | 63 | $some_pass_hints = ''; |
| | 64 | for($l = 3; $l != 0; $l--) $some_pass_hints .= '<p>'.bb_generate_password().'</p>'; |
| | 65 | |
| | 66 | $user_fields = array( |
| | 67 | 'user_login' => array( |
| | 68 | 'title' => __( 'Username' ), |
| | 69 | 'note' => __( 'Required! Unique identifier for new user.' ), |
| | 70 | 'value' => $user_login |
| | 71 | ), |
| | 72 | 'user_email' => array( |
| | 73 | 'title' => __( 'Email' ), |
| | 74 | 'note' => __( 'Required! Will be used for notifications and profile settings changes.' ), |
| | 75 | 'value' => $user_email |
| | 76 | ), |
| | 77 | 'user_url' => array( |
| | 78 | 'title' => __( 'Website' ), |
| | 79 | 'class' => array('long', 'code'), |
| | 80 | 'note' => __( 'The full URL of user\'s homepage or blog.' ), |
| | 81 | 'value' => $user_url |
| | 82 | ), |
| | 83 | 'from' => array( |
| | 84 | 'title' => __( 'Location' ), |
| | 85 | 'class' => array('long'), |
| | 86 | 'value' => $user_meta['from'] |
| | 87 | ), |
| | 88 | 'occ'=> array( |
| | 89 | 'title' => __( 'Occupation' ), |
| | 90 | 'class' => array('long'), |
| | 91 | 'value' => $user_meta['occ'] |
| | 92 | ), |
| | 93 | 'interest' => array( |
| | 94 | 'title' => __( 'Interests' ), |
| | 95 | 'class' => array('long'), |
| | 96 | 'value' => $user_meta['interest'] |
| | 97 | ), |
| | 98 | 'userrole' => array( |
| | 99 | 'title' => __( 'User Role' ), |
| | 100 | 'type' => 'select', |
| | 101 | 'options'=> $user_roles, |
| | 102 | 'note' => __( 'Allow user the above privileges.' ), |
| | 103 | ), |
| | 104 | 'pass1' => array( |
| | 105 | 'title' => __( 'New Password' ), |
| | 106 | 'type' => 'password', |
| | 107 | 'class' => array('short', 'text', 'code'), |
| | 108 | 'note' => __('Hints: ').$some_pass_hints, |
| | 109 | ), |
| | 110 | 'pass2' => array( |
| | 111 | 'title' => __( 'Repeat New Password' ), |
| | 112 | 'type' => 'password', |
| | 113 | 'class' => array('short', 'text', 'code'), |
| | 114 | 'note' => __('If you ignore hints, remember: |
| | 115 | the password should be at least seven characters long. |
| | 116 | To make it stronger, use upper and lower case letters, |
| | 117 | numbers and symbols like ! " ? $ % ^ & ).'), |
| | 118 | ), |
| | 119 | 'email_pass'=> array( |
| | 120 | 'title' => __( '' ), |
| | 121 | 'type' => 'checkbox', |
| | 122 | 'options'=> array( |
| | 123 | '1' => array( |
| | 124 | 'label' => __( 'Email the new password.' ), |
| | 125 | 'attributes' => array('checked' => true) |
| | 126 | ) |
| | 127 | ), |
| | 128 | ), |
| | 129 | 'pass-strenght-fake-input' => array( |
| | 130 | 'title' => __( 'Password Strength' ), |
| | 131 | 'type' => 'hidden', |
| | 132 | ), |
| | 133 | ); |
| | 134 | ?> |
| | 135 | |
| | 136 | <div class="wrap"> |
| | 137 | <h2><?php _e('Add a new user'); ?></h2> |
| | 138 | <?php do_action( 'bb_admin_notices' ); ?> |
| | 139 | <!-- TODO: Rename the CSS class settings as something more general. --> |
| | 140 | <form class="settings" method="post" action="<?php bb_uri( 'bb-admin/user-new.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN ); ?>"> |
| | 141 | <fieldset> |
| | 142 | <?php |
| | 143 | foreach ( $user_fields as $field => $args ) { |
| | 144 | bb_option_form_element( $field, $args ); |
| | 145 | } |
| | 146 | ?> |
| | 147 | <noscript> |
| | 148 | <?php _e('Disabled (requires JavaScript)'); ?> |
| | 149 | </noscript> |
| | 150 | <script type="text/javascript" charset="utf-8"> |
| | 151 | if (typeof jQuery != 'undefined') { |
| | 152 | document.writeln('<div id="pass-strength-result">' + pwsL10n.short + '</div>'); |
| | 153 | } else { |
| | 154 | document.writeln('<?php echo str_replace("'", "\'", __('Disabled (requires jQuery)')); ?>') |
| | 155 | } |
| | 156 | </script> |
| | 157 | </fieldset> |
| | 158 | <fieldset class="submit"> |
| | 159 | <?php bb_nonce_field( 'user-new-create' ); ?> |
| | 160 | <input type="hidden" name="action" value="create" /> |
| | 161 | <input class="submit" type="submit" name="submit" value="<?php _e('Create User') ?>" /> |
| | 162 | </fieldset> |
| | 163 | </form> |
| | 164 | </div> |
| | 165 | |
| | 166 | <?php |
| | 167 | bb_get_admin_footer(); |
| | 168 | ?> |
| | 169 | No newline at end of file |