function testUserStatusList() { $valids = pw_new_user_approve()->get_valid_statuses(); $statuses = pw_new_user_approve()->_get_user_statuses(); $this->assertTrue(is_array($statuses)); $this->assertEquals(count($statuses), count($valids)); }
/** * Email template tag: password * Generates the password for the user to add to the email * * @param array $attributes * * @return string password label and password */ function nua_email_tag_password($attributes) { $user = $attributes['user']; if (pw_new_user_approve()->do_password_reset($user->ID)) { // reset password to know what to send the user $new_pass = wp_generate_password(12, false); // store the password global $wpdb; $data = array('user_pass' => md5($new_pass), 'user_activation_key' => ''); $where = array('ID' => $user->ID); $wpdb->update($wpdb->users, $data, $where, array('%s', '%s'), array('%d')); // Set up the Password change nag. update_user_option($user->ID, 'default_password_nag', true, true); // Set this meta field to track that the password has been reset by // the plugin. Don't reset it again unless doing a password reset. update_user_meta($user->ID, 'pw_user_approve_password_reset', time()); return sprintf(__('Password: %s', 'new-user-approve'), $new_pass); } else { return ''; } }
/** * Add bubble for number of users pending to the user menu * * @uses admin_menu */ public function pending_users_bubble() { global $menu; $users = pw_new_user_approve()->get_user_statuses(); // Count Number of Pending Members $pending_users = count($users['pending']); // Make sure there are pending members if ($pending_users > 0) { // Locate the key of $key = $this->recursive_array_search('users.php', $menu); // Not found, just in case if (!$key) { return; } // Modify menu item $menu[$key][0] .= sprintf('<span class="update-plugins count-%1$s" style="background-color:white;color:black;margin-left:5px;"><span class="plugin-count">%1$s</span></span>', $pending_users); } }
/** * Only validate the update if the status has been updated to prevent unnecessary update * and especially emails. * * @param bool $do_update * @param int $user_id * @param string $status either 'approve' or 'deny' */ public function validate_status_update($do_update, $user_id, $status) { $current_status = pw_new_user_approve()->get_user_status($user_id); if ($status == 'approve') { $new_status = 'approved'; } else { $new_status = 'denied'; } if ($current_status == $new_status) { $do_update = false; } return $do_update; }
/** * Accept input from admin to modify a user * * @uses init */ public function process_input() { if (isset($_GET['page']) && $_GET['page'] == $this->_admin_page && isset($_GET['status'])) { $valid_request = check_admin_referer('pw_new_user_approve_action_' . get_class($this)); if ($valid_request) { $status = sanitize_key($_GET['status']); $user_id = absint($_GET['user']); pw_new_user_approve()->update_user_status($user_id, $status); } } }