* @link http://wp-dreams.com, http://codecanyon.net/user/anago/portfolio * @copyright Copyright (c) 2016, Ernest Marcinko */ class wd_UserSelect extends wpdreamsType { private $args = array( "show_type" => 0, "show_checkboxes" => 0, "show_all_users_option" => 1 ); private $e_data; public function getType() { parent::getType(); $this->processData(); ?>
args["show_type"] == 1) ? '' : ' class="hiddend"'; ?>>
label; ?>

    args['show_all_users_option'] == 1): ?>

e_data['op_type']; ?>!

    printSelectedUsers(); ?>
e_data['users'] as $u) { switch ($u) { case -1: echo '
  • ' . __('All users', 'ajax-search-pro') . '
  • '; break; case 0: echo '
  • ' . __('Anonymous user (no user)', 'ajax-search-pro') . '
  • '; break; case -2: echo '
  • ' . __('Current logged in user', 'ajax-search-pro') . '
  • '; break; default: $user = get_user_by("ID", $u); if (empty($user) || is_wp_error($user)) break; $checkbox = ""; if ($this->args['show_checkboxes'] == 1) $checkbox = 'ID, $this->e_data['un_checked']) ? ' checked="checked"' : '') . '/>'; echo '
  • ' . $user->user_login . ' ('.$user->display_name.') ' . $checkbox . '
  • '; break; } } } public static function searchUsers() { if ( isset($_POST['wd_phrase'], $_POST['wd_user_select_nonce']) && ( current_user_can( 'manage_options' ) || apply_filters('wpdrms/backend/options/ajax/user_role_override', false) ) && wp_verify_nonce( $_POST["wd_user_select_nonce"], 'wd_user_select_nonce' ) ) { $phrase = trim($_POST['wd_phrase']); $data = json_decode(base64_decode($_POST['wd_args']), true); $user_query = new WP_User_Query( array( 'search' => "*" . $phrase . "*", "number" => 100 ) ); Ajax::prepareHeaders(); if ( $data['show_all_users_option'] == 1 ) echo '
  • ' . __('All users', 'ajax-search-pro') . '
  • '; echo '
  • ' . __('Anonymous user (no user)', 'ajax-search-pro') . '
  • ' . __('Current logged in user', 'ajax-search-pro') . '
  • '; // User Loop $user_results = $user_query->get_results(); if ( ! empty( $user_results ) ) { echo "Or select users:"; foreach ( $user_results as $user ) { $checkbox = ""; if ($data['show_checkboxes'] == 1) $checkbox = ''; echo '
  • ' . $user->user_login . ' ('.$user->display_name.') '.$checkbox.'
  • '; } } else { echo __('No users found for term:', 'ajax-search-pro') . ' ' . esc_html($phrase) .''; } } die(); } public function processData() { // Get the args first if exists if ( is_array($this->data) && isset($this->data['args']) ) $this->args = array_merge($this->args, $this->data['args']); if ( is_array($this->data) && isset($this->data['value']) ) { // If called from back-end non-post context $this->e_data = $this->decode_param($this->data['value']); $this->data = $this->encode_param($this->data['value']); } else { // POST method or something else $this->e_data = $this->decode_param($this->data); $this->data = $this->encode_param($this->data); } /** * At this point the this->data variable surely contains the encoded data, no matter what. */ } public final function getData() { return $this->data; } public final function getSelected() { return $this->e_data; } } } if ( !has_action('wp_ajax_wd_search_users') ) add_action('wp_ajax_wd_search_users', 'wd_UserSelect::searchUsers');