/** * Prepare user row actions * * @param WP_User $user * * @return array * * @access protected */ protected function prepareRowActions(WP_User $user) { $max = AAM_Core_API::maxLevel(wp_get_current_user()->allcaps); if ($max < AAM_Core_API::maxLevel($user->allcaps)) { $actions = array('no-manage', 'no-lock', 'no-edit'); } else { $actions = array('manage'); $prefix = $user->ID == get_current_user_id() ? 'no-' : ''; $actions[] = $prefix . ($user->user_status ? 'unlock' : 'lock'); $actions[] = 'edit'; } if (class_exists('user_switching')) { $url = user_switching::maybe_switch_url($user); if (!in_array('edit', $actions) || empty($url)) { $actions[] = 'no-switch'; } else { $actions[] = 'switch|' . $url; } } return $actions; }
/** * Gets the URL to switch to the user * if the User Switching plugin is active * * @access public * @since 2.1 */ public function get_switch_to_url() { if (!class_exists('user_switching')) { return false; } $link = user_switching::maybe_switch_url($this); if ($link) { $link = add_query_arg('redirect_to', urlencode(home_url()), $link); return $link; } else { return false; } }
/** * function abus_user_search() * searches for the required user depending what was entered into the search box * in the admin bar */ function abus_user_search() { global $user_switching; /* get the posted query search, current url and nonce */ $q = $_POST['query']; $url = $_POST['currenturl']; $nonce = $_POST['nonce']; /* check nonce passes for intent */ if (!wp_verify_nonce($nonce, 'abus_nonce')) { exit; } $args = array('search' => $q, 'search_columns' => array('user_login')); /* query the users */ $user_query = new WP_User_Query($args); echo '<div class="abus_user_results">'; /* check we have results returned */ if (!empty($user_query->results)) { /* loop through each returned user */ foreach ($user_query->results as $user) { /* if this user is the current user - skip to next user */ if ($user->ID == get_current_user_id()) { continue; } $link = user_switching::maybe_switch_url($user); if ($link) { $link = add_query_arg('redirect_to', apply_filters('abus_switch_to_url', $url), $link); echo '<p class="result"><a href="' . esc_url($link, $user) . '">' . $user->display_name . '</a></p>'; } } /* no users match search */ } else { echo '<p class="result">No users found.</p>'; } echo '</div>'; die; }