/** * Updates the role level when a new role is added or an existing role is updated. Note * that in order to properly update the `user_level` field of users, we need to run * `WP_User::update_user_level_from_caps()`, which can be a heavy function if the role * as a lot of users because each user of the role needs to be updated. * * @since 1.0.0 * @access public * @param string $role * @return void */ public function update_role_level($role) { // Verify the nonce before proceeding. if (isset($_POST['mrl_role_level_nonce']) && wp_verify_nonce($_POST['mrl_role_level_nonce'], 'role_level')) { // Get the current role object to edit. $role = get_role(members_sanitize_role($role)); // If the role doesn't exist, bail. if (is_null($role)) { return; } // Get the posted level. $new_level = isset($_POST['mrl-role-level']) ? $_POST['mrl-role-level'] : ''; // Make sure the posted level is in the whitelisted array of levels. if (!mrl_is_valid_level($new_level)) { return; } // Get the role's current level. $role_level = mrl_get_role_level($role); // If the posted level doesn't match the role level, update it. if ($new_level !== $role_level) { mrl_set_role_level($role, $new_level); } } }
/** * Returns the content for the level column. * * @since 1.0.0 * @access public * @return void */ public function column_level($out, $role) { $level = mrl_get_role_level(get_role($role)); return $level ? mrl_remove_level_prefix($level) : '–'; }