Exemplo n.º 1
0
function userpro_memberlist_loop($args)
{
    global $userpro;
    $per_page = isset($args['per_page']) ? $args['per_page'] : 0;
    $relation = isset($args['relation']) ? $args['relation'] : 'AND';
    $role = isset($args['role']) ? $args['role'] : '';
    $memberlist_verified = isset($args['memberlist_verified']) ? $args['memberlist_verified'] : 0;
    $sortby = isset($args['sortby']) ? $args['sortby'] : '';
    $order = isset($args['order']) ? $args['order'] : '';
    $arr = array();
    if (get_option('userpro_trial') == 1) {
        $per_page = 3;
        do_action('userpro_pre_form_message');
    }
    global $wpdb;
    $blog_id = get_current_blog_id();
    $page = !empty($_GET['userp']) ? $_GET['userp'] : 1;
    $offset = ($page - 1) * $per_page;
    /** QUERY ARGS BEGIN **/
    /* exclude specific users? */
    if (isset($args['exclude'])) {
        $exclude = explode(',', $args['exclude']);
        $query['exclude'] = $exclude;
    }
    /* Start Added by Ranjith to hide/show unapproved users */
    if (isset($args['userpro_show_unapproved_members']) && $args['userpro_show_unapproved_members'] === '0') {
        $user_ids = get_users(array('meta_key' => '_account_status', 'meta_value' => array('pending_admin', 'pending'), 'fields' => "ID"));
        if (isset($args['exclude'])) {
            $exclude = explode(',', $args['exclude']);
            if (is_array($user_ids) && is_array($exclude)) {
                $query['exclude'] = array_merge($user_ids, $exclude);
            } else {
                if (is_array($user_ids)) {
                    $query['exclude'] = $user_ids;
                } else {
                    if (is_array($exclude)) {
                        $query['exclude'] = $exclude;
                    }
                }
            }
        }
    }
    /* End */
    $query['meta_query'] = array('relation' => strtoupper($relation));
    if (isset($role) && $role != '') {
        $roles = explode(',', $role);
        $query['meta_query']['relation'] = 'AND';
        if (count($roles) >= 2) {
            $role_query['relation'] = 'or';
        }
        foreach ($roles as $subrole) {
            $role_query[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => $subrole, 'compare' => 'like');
        }
        $query['meta_query'][] = $role_query;
    }
    /* limited to userpro fields */
    if (userpro_retrieve_metakeys()) {
        foreach (userpro_retrieve_metakeys() as $key) {
            if ($userpro->field_type($key) == 'multiselect' || $userpro->field_type($key) == 'checkbox' || $userpro->field_type($key) == 'checkbox-full') {
                $like = 'like';
            } else {
                $like = '=';
            }
            if (isset($args[$key]) && $key != 'role') {
                if (substr(trim(htmlspecialchars_decode($args[$key])), 0, 1) === '>') {
                    $choices = explode('>', trim(htmlspecialchars_decode($args[$key])));
                    $target = $choices[1];
                    $query['meta_query'][] = array('key' => $key, 'value' => $target, 'compare' => '>');
                } elseif (substr(trim(htmlspecialchars_decode($args[$key])), 0, 1) === '<') {
                    $choices = explode('<', trim(htmlspecialchars_decode($args[$key])));
                    $target = $choices[1];
                    $query['meta_query'][] = array('key' => $key, 'value' => $target, 'compare' => '<');
                } elseif (strstr(esc_attr(trim($args[$key])), ':')) {
                    $choices = explode(':', esc_attr(trim($args[$key])));
                    $min = $choices[0];
                    $max = $choices[1];
                    $query['meta_query'][] = array('key' => $key, 'value' => array($min, $max), 'compare' => 'between');
                } elseif (strstr(esc_attr(trim($args[$key])), ',')) {
                    $choices = explode(',', esc_attr(trim($args[$key])));
                    foreach ($choices as $choice) {
                        $query['meta_query'][] = array('key' => $key, 'value' => $choice, 'compare' => $like);
                    }
                } else {
                    $query['meta_query'][] = array('key' => $key, 'value' => esc_attr(trim($args[$key])), 'compare' => $like);
                }
            }
        }
    }
    if ($memberlist_verified) {
        $query['meta_query'][] = array('key' => 'userpro_verified', 'value' => 1, 'compare' => '=');
    }
    if (isset($args['memberlist_verified']) && $args['memberlist_verified'] === '0') {
        $query['meta_query'][] = array('key' => 'userpro_verified', 'compare' => 'NOT EXISTS');
    }
    $memberlist_withavatar = $args['memberlist_withavatar'];
    if (isset($memberlist_withavatar) && $memberlist_withavatar == 1) {
        $query['meta_query'][] = array('key' => 'profilepicture', 'value' => '', 'compare' => '!=');
    }
    /**
    			CUSTOM SEARCH FILTERS UPDATE
    		**
    		**
    		**/
    if (isset($_GET['searchuser'])) {
        global $userpro_emd;
        $role = isset($args['role']) ? $args['role'] : '';
        if ($role != '') {
            $role = str_replace(',', '|', $role);
        }
        $role_query['relation'] = 'and';
        $role_query[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => $role, 'compare' => 'REGEXP');
        /* Searchuser query param */
        $search_string = esc_attr(trim(get_query_var('searchuser')));
        if ($search_string != '') {
            if (isset($args['memberlist_filters']) && !empty($args['memberlist_filters'])) {
                $customfilters = explode(',', $args['memberlist_filters']);
                if ($customfilters) {
                    if (count($customfilters) > 1) {
                        $customfiltersquery['relation'] = 'or';
                    }
                    foreach ($customfilters as $customfilter) {
                        $customfiltersquery[] = array('key' => $customfilter, 'value' => $search_string, 'compare' => 'like');
                    }
                    $query['meta_query'][] = $customfiltersquery;
                    $testkeys = new WP_User_Query($query);
                } elseif ($role != '') {
                    if (count($customfilters) > 1) {
                        $customfilter_query['relation'] = 'or';
                    }
                    foreach ($customfilters as $customfilter) {
                        $customfilter_query[] = array('key' => $customfilter, 'value' => $search_string, 'compare' => 'like');
                    }
                    // 						$query['meta_query'][] = array(
                    // 								'relation'	=> 'and' ,
                    // 								array(
                    // 										'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
                    // 										'value' =>$role,
                    // 										'compare' => 'REGEXP'
                    // 								) ,
                    // 								$customfilter_query
                    // 						);
                }
            }
            if (empty($testkeys->results) && $role != '') {
                $query['meta_query'][] = array('relation' => 'and', array('key' => 'display_name', 'value' => $search_string, 'compare' => 'like'), array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => $role, 'compare' => 'REGEXP'));
            } else {
                if (empty($testkeys->results)) {
                    $query['meta_query'][] = array('key' => 'display_name', 'value' => $search_string, 'compare' => 'like');
                }
            }
        }
        /* Searchuser query param */
        parse_str($_SERVER['QUERY_STRING'], $params);
        foreach ($params as $k => $v) {
            $v = trim(strip_tags(esc_attr($v)));
            $cleankey = str_replace('emd-', '', $k);
            if (strstr($cleankey, 'from_')) {
                $rangekey = str_replace('from_', '', $cleankey);
                if (is_numeric($v)) {
                    $rangefilter[$rangekey]['compare']['min'] = $v;
                }
            } elseif (strstr($cleankey, 'to_')) {
                $rangekey = str_replace('to_', '', $cleankey);
                if (is_numeric($v)) {
                    $rangefilter[$rangekey]['compare']['max'] = $v;
                }
            } else {
                if (in_array('emd_' . $cleankey, $userpro_emd->must_be_custom_fields)) {
                    $cleanparams[$cleankey] = $v;
                } elseif ($userpro->field_label($cleankey) != '') {
                    $cleanparams[$cleankey] = $v;
                }
            }
        }
        if (isset($rangefilter)) {
            foreach ($rangefilter as $range_k => $arr) {
                if (isset($arr['compare']['min']) && isset($arr['compare']['max']) || isset($arr['compare']['min']) || isset($arr['compare']['max'])) {
                    if (!isset($arr['compare']['min'])) {
                        $split = explode(',', $args[$range_k . '_range']);
                        $arr['compare']['min'] = $split[0];
                    }
                    if (!isset($arr['compare']['max'])) {
                        $split = explode(',', $args[$range_k . '_range']);
                        $arr['compare']['max'] = $split[1];
                    }
                    $query['meta_query'][] = array('key' => $range_k, 'value' => array($arr['compare']['min'], $arr['compare']['max']), 'compare' => 'between');
                }
            }
        }
        if (isset($cleanparams)) {
            foreach ($cleanparams as $k => $v) {
                if ($k == 'photopreference') {
                    if ($v === '1') {
                        $query['meta_query'][] = array('key' => 'profilepicture', 'value' => '', 'compare' => '!=');
                    }
                    if ($v === '2') {
                        $query['meta_query'][] = array('key' => 'profilepicture', 'value' => '', 'compare' => '==');
                    }
                } elseif ($k == 'accountstatus') {
                    if ($v > 0) {
                        $query['meta_query'][] = array('key' => 'userpro_verified', 'value' => 1, 'compare' => '==');
                    }
                } elseif ($v != 'all') {
                    if ($v != '') {
                        if ($userpro->field_type($k) == 'multiselect' || $userpro->field_type($k) == 'checkbox' || $userpro->field_type($k) == 'checkbox-full') {
                            $like = 'like';
                        } else {
                            $like = '=';
                        }
                        $query['meta_query'][] = array('key' => $k, 'value' => $v, 'compare' => $like);
                    }
                }
            }
        }
    }
    /** DO **/
    if ($sortby) {
        $query['orderby'] = $sortby;
    }
    if ($order) {
        $query['order'] = strtoupper($order);
    }
    // asc to ASC
    /** QUERY ARGS END **/
    $defaultorder = array('ID', 'display_name', 'name', 'user_name', 'login', 'user_login', 'nicename', 'user_nicename', 'email', 'user_email', 'url', 'user_url', 'registered', 'user_registered', 'post_count');
    /* Start Added By Yogesh for sorting the users*/
    if (in_array($sortby, $defaultorder)) {
        $query['number'] = $per_page;
        $query['offset'] = $offset;
    }
    /* End Added By Yogesh for sorting the users*/
    /* Search mode */
    if (isset($_GET['searchuser']) && !empty($_GET['searchuser']) || count($query['meta_query']) > 1) {
        $count_args = array_merge($query, array('number' => 10000));
        unset($count_args['offset']);
        $user_count_query = $userpro->get_cached_query($count_args);
    }
    $wp_user_query = $userpro->get_cached_query($query);
    if ($per_page) {
        /* Get Total Users */
        if (isset($_GET['searchuser']) && !empty($_GET['searchuser']) || count($query['meta_query']) > 1) {
            $user_count = $user_count_query->get_results();
            $total_users = $user_count ? count($user_count) : 1;
        } else {
            /* Commented by Ranjith to show proper count */
            //$result = count_users();
            //$total_users = $result['total_users'];
            $total_users = $wp_user_query->total_users;
        }
        $total_pages = ceil($total_users / $per_page);
    }
    remove_action('pre_user_query', 'userpro_query_search_displayname');
    $url = parse_url(wp_guess_url());
    if (isset($url['query'])) {
        $string_query = $url['query'];
    } else {
        $string_query = null;
    }
    if (!in_array($sortby, $defaultorder)) {
        /* Start Added By Yogesh for sorting the users*/
        $userstable = $wpdb->base_prefix . "users";
        $usermetatable = $wpdb->base_prefix . "usermeta";
        $query = "SELECT a.ID\n\t\t\tFROM {$userstable} AS a\n\t\t\tJOIN {$usermetatable} ON a.ID= {$usermetatable}.user_id WHERE {$usermetatable}.meta_key = '{$sortby}' AND {$usermetatable}.user_id = a.ID ORDER BY   {$usermetatable}.meta_value {$order}";
        $orderArray = $wpdb->get_results($query);
        $allusers = sortArrayByArray($wp_user_query->results, $orderArray);
        $paged_users = array();
        $keyedUsers = array();
        foreach ($allusers as $key => $user) {
            $keyedUsers[] = $user;
        }
        for ($i = $offset; $i < $offset + $per_page; $i++) {
            if (isset($keyedUsers[$i])) {
                array_push($paged_users, $keyedUsers[$i]);
            }
        }
        $wp_user_query->results = $paged_users;
    }
    /* End Added By Yogesh for sorting the users*/
    if (!empty($wp_user_query->results)) {
        $arr['total'] = $total_users;
        $arr['paginate'] = paginate_links(array('base' => @add_query_arg('userp', '%#%'), 'total' => $total_pages, 'current' => $page, 'show_all' => false, 'end_size' => 1, 'mid_size' => 2, 'prev_next' => true, 'prev_text' => __('« Previous', 'userpro'), 'next_text' => __('Next »', 'userpro'), 'type' => 'plain', 'add_args' => false));
        $arr['users'] = $wp_user_query->results;
    }
    return $arr;
}
Exemplo n.º 2
0
Arquivo: api.php Projeto: Darciro/PPM
 function setup_query($args)
 {
     global $wpdb, $userpro;
     $blog_id = get_current_blog_id();
     $query['meta_query'] = array('relation' => 'AND');
     $query['orderby'] = 'registered';
     $query['order'] = 'desc';
     /* Query Parameters */
     /* Role */
     if (isset($args['role'])) {
         $role = str_replace(',', '|', $args['role']);
         $query['meta_query'][] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => $role, 'compare' => 'REGEXP');
     }
     /* meta keys */
     if (userpro_retrieve_metakeys()) {
         foreach (userpro_retrieve_metakeys() as $key) {
             if ($userpro->field_type($key) == 'multiselect' || $userpro->field_type($key) == 'checkbox' || $userpro->field_type($key) == 'checkbox-full') {
                 $like = 'like';
             } else {
                 $like = '=';
             }
             if (isset($args[$key]) && $key != 'role') {
                 if (substr(trim(htmlspecialchars_decode($args[$key])), 0, 1) === '>') {
                     $choices = explode('>', trim(htmlspecialchars_decode($args[$key])));
                     $target = $choices[1];
                     $query['meta_query'][] = array('key' => $key, 'value' => $target, 'compare' => '>');
                 } elseif (substr(trim(htmlspecialchars_decode($args[$key])), 0, 1) === '<') {
                     $choices = explode('<', trim(htmlspecialchars_decode($args[$key])));
                     $target = $choices[1];
                     $query['meta_query'][] = array('key' => $key, 'value' => $target, 'compare' => '<');
                 } elseif (strstr(esc_attr(trim($args[$key])), ':')) {
                     $choices = explode(':', esc_attr(trim($args[$key])));
                     $min = $choices[0];
                     $max = $choices[1];
                     $query['meta_query'][] = array('key' => $key, 'value' => array($min, $max), 'compare' => 'between');
                 } elseif (strstr(esc_attr(trim($args[$key])), ',')) {
                     $choices = explode(',', esc_attr(trim($args[$key])));
                     foreach ($choices as $choice) {
                         $query['meta_query'][] = array('key' => $key, 'value' => $choice, 'compare' => $like);
                     }
                 } else {
                     $query['meta_query'][] = array('key' => $key, 'value' => esc_attr(trim($args[$key])), 'compare' => $like);
                 }
             }
         }
     }
     /* Search Parameters */
     if (isset($_GET['emd-search'])) {
         parse_str($_SERVER['QUERY_STRING'], $params);
         foreach ($params as $k => $v) {
             $v = trim(strip_tags(esc_attr($v)));
             $cleankey = str_replace('emd-', '', $k);
             if (in_array('emd_' . $cleankey, $this->must_be_custom_fields)) {
                 $cleanparams[$cleankey] = $v;
             } elseif ($userpro->field_label($cleankey) != '') {
                 $cleanparams[$cleankey] = $v;
             }
         }
         foreach ($cleanparams as $k => $v) {
             if ($k == 'photopreference') {
                 if ($v === '1') {
                     $query['meta_query'][] = array('key' => 'profilepicture', 'value' => '', 'compare' => '!=');
                 }
                 if ($v === '2') {
                     $query['meta_query'][] = array('key' => 'profilepicture', 'value' => '', 'compare' => '==');
                 }
             } elseif ($k == 'accountstatus') {
                 if ($v > 0) {
                     $query['meta_query'][] = array('key' => 'userpro_verified', 'value' => 1, 'compare' => '==');
                 }
             } elseif ($v != 'all') {
                 if ($v != '') {
                     if ($userpro->field_type($k) == 'multiselect' || $userpro->field_type($k) == 'checkbox' || $userpro->field_type($k) == 'checkbox-full') {
                         $like = 'like';
                     } else {
                         $like = '=';
                     }
                     $query['meta_query'][] = array('key' => $k, 'value' => $v, 'compare' => $like);
                 }
             }
         }
     }
     return $query;
 }
function userpro_memberlist_loop($args)
{
    global $userpro;
    extract($args);
    if (get_option('userpro_trial') == 1) {
        $per_page = 3;
        do_action('userpro_pre_form_message');
    }
    global $wpdb;
    $blog_id = get_current_blog_id();
    $page = !empty($_GET['userp']) ? $_GET['userp'] : 1;
    $offset = ($page - 1) * $per_page;
    /** QUERY ARGS BEGIN **/
    $query['meta_query'] = array('relation' => strtoupper($relation));
    if (isset($role)) {
        $roles = explode(',', $role);
        if (count($roles) >= 2) {
            $query['meta_query']['relation'] = 'or';
        }
        foreach ($roles as $subrole) {
            $query['meta_query'][] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => $subrole, 'compare' => 'like');
        }
    }
    /* limited to userpro fields */
    if (userpro_retrieve_metakeys()) {
        foreach (userpro_retrieve_metakeys() as $key) {
            if ($userpro->field_type($key) == 'multiselect') {
                $like = 'like';
            } else {
                $like = '=';
            }
            if (isset($args[$key]) && $key != 'role') {
                if (substr(trim(htmlspecialchars_decode($args[$key])), 0, 1) === '>') {
                    $choices = explode('>', trim(htmlspecialchars_decode($args[$key])));
                    $target = $choices[1];
                    $query['meta_query'][] = array('key' => $key, 'value' => $target, 'compare' => '>');
                } elseif (substr(trim(htmlspecialchars_decode($args[$key])), 0, 1) === '<') {
                    $choices = explode('<', trim(htmlspecialchars_decode($args[$key])));
                    $target = $choices[1];
                    $query['meta_query'][] = array('key' => $key, 'value' => $target, 'compare' => '<');
                } elseif (strstr(esc_attr(trim($args[$key])), ':')) {
                    $choices = explode(':', esc_attr(trim($args[$key])));
                    $min = $choices[0];
                    $max = $choices[1];
                    $query['meta_query'][] = array('key' => $key, 'value' => array($min, $max), 'compare' => 'between');
                } elseif (strstr(esc_attr(trim($args[$key])), ',')) {
                    $choices = explode(',', esc_attr(trim($args[$key])));
                    foreach ($choices as $choice) {
                        $query['meta_query'][] = array('key' => $key, 'value' => $choice, 'compare' => $like);
                    }
                } else {
                    $query['meta_query'][] = array('key' => $key, 'value' => esc_attr(trim($args[$key])), 'compare' => $like);
                }
            }
        }
    }
    if ($memberlist_verified) {
        $query['meta_query'][] = array('key' => 'userpro_verified', 'value' => 1, 'compare' => '=');
    }
    if (isset($memberlist_withavatar) && $memberlist_withavatar == 1) {
        $query['meta_query'][] = array('key' => 'profilepicture', 'value' => '', 'compare' => '!=');
    }
    /**
    			CUSTOM SEARCH FILTERS UPDATE
    		**
    		**
    		**/
    if (isset($_GET['searchuser'])) {
        global $userpro_emd;
        /* Searchuser query param */
        $search_string = esc_attr(trim(get_query_var('searchuser')));
        if ($search_string != '') {
            if (isset($args['memberlist_filters']) && !empty($args['memberlist_filters'])) {
                $customfilters = explode(',', $args['memberlist_filters']);
                if ($customfilters) {
                    foreach ($customfilters as $customfilter) {
                        $query['meta_query'][] = array('key' => $customfilter, 'value' => $search_string, 'compare' => '=');
                    }
                    $testkeys = new WP_User_Query($query);
                }
            }
            if (empty($testkeys->results)) {
                $query['meta_query'][] = array('key' => 'display_name', 'value' => $search_string, 'compare' => 'like');
            }
        }
        /* Searchuser query param */
        parse_str($_SERVER['QUERY_STRING'], $params);
        foreach ($params as $k => $v) {
            $v = trim(strip_tags(esc_attr($v)));
            $cleankey = str_replace('emd-', '', $k);
            if (strstr($cleankey, 'from_')) {
                $rangekey = str_replace('from_', '', $cleankey);
                if (is_numeric($v)) {
                    $rangefilter[$rangekey]['compare']['min'] = $v;
                }
            } elseif (strstr($cleankey, 'to_')) {
                $rangekey = str_replace('to_', '', $cleankey);
                if (is_numeric($v)) {
                    $rangefilter[$rangekey]['compare']['max'] = $v;
                }
            } else {
                if (in_array('emd_' . $cleankey, $userpro_emd->must_be_custom_fields)) {
                    $cleanparams[$cleankey] = $v;
                } elseif ($userpro->field_label($cleankey) != '') {
                    $cleanparams[$cleankey] = $v;
                }
            }
        }
        if (isset($rangefilter)) {
            foreach ($rangefilter as $range_k => $arr) {
                if (isset($arr['compare']['min']) && isset($arr['compare']['max']) || isset($arr['compare']['min']) || isset($arr['compare']['max'])) {
                    if (!isset($arr['compare']['min'])) {
                        $split = explode(',', $args[$range_k . '_range']);
                        $arr['compare']['min'] = $split[0];
                    }
                    if (!isset($arr['compare']['max'])) {
                        $split = explode(',', $args[$range_k . '_range']);
                        $arr['compare']['max'] = $split[1];
                    }
                    $query['meta_query'][] = array('key' => $range_k, 'value' => array($arr['compare']['min'], $arr['compare']['max']), 'compare' => 'between');
                }
            }
        }
        if (isset($cleanparams)) {
            foreach ($cleanparams as $k => $v) {
                if ($k == 'photopreference') {
                    if ($v === '1') {
                        $query['meta_query'][] = array('key' => 'profilepicture', 'value' => '', 'compare' => '!=');
                    }
                    if ($v === '2') {
                        $query['meta_query'][] = array('key' => 'profilepicture', 'value' => '', 'compare' => '==');
                    }
                } elseif ($k == 'accountstatus') {
                    if ($v > 0) {
                        $query['meta_query'][] = array('key' => 'userpro_verified', 'value' => 1, 'compare' => '==');
                    }
                } elseif ($v != 'all') {
                    if ($v != '') {
                        $query['meta_query'][] = array('key' => $k, 'value' => $v, 'compare' => '=');
                    }
                }
            }
        }
    }
    /** DO **/
    if ($sortby) {
        $query['orderby'] = $sortby;
    }
    if ($order) {
        $query['order'] = strtoupper($order);
    }
    // asc to ASC
    /** QUERY ARGS END **/
    $query['number'] = $per_page;
    $query['offset'] = $offset;
    $count_args = array_merge($query, array('number' => 99999999999));
    unset($count_args['offset']);
    $user_count_query = $userpro->get_cached_query($count_args);
    //$user_count_query = new WP_User_Query($count_args);
    if ($per_page) {
        $user_count = $user_count_query->get_results();
        $total_users = $user_count ? count($user_count) : 1;
        $total_pages = ceil($total_users / $per_page);
    }
    $wp_user_query = $userpro->get_cached_query($query);
    //$wp_user_query = new WP_User_Query($query);
    remove_action('pre_user_query', 'userpro_query_search_displayname');
    $url = parse_url(wp_guess_url());
    if (isset($url['query'])) {
        $string_query = $url['query'];
    } else {
        $string_query = null;
    }
    if (!empty($wp_user_query->results)) {
        $arr['total'] = $total_users;
    }
    $arr['paginate'] = paginate_links(array('base' => @add_query_arg('userp', '%#%'), 'total' => $total_pages, 'current' => $page, 'show_all' => false, 'end_size' => 1, 'mid_size' => 2, 'prev_next' => true, 'prev_text' => __('« Previous', 'userpro'), 'next_text' => __('Next »', 'userpro'), 'type' => 'plain'));
    $arr['users'] = $wp_user_query->results;
    return $arr;
}
Exemplo n.º 4
0
    function show_filters($args)
    {
        $big_array = array_merge(userpro_retrieve_metakeys(), $this->must_be_custom_fields);
        foreach ($args as $key => $v) {
            if (in_array($key, $big_array) || in_array(str_replace('emd_', '', $key), $big_array)) {
                $options = explode(',', $args[$key]);
                if (!isset($options[1])) {
                    $type = 'input';
                } else {
                    $type = $options[1];
                }
                if (in_array($key, $this->must_be_custom_fields)) {
                    $type = 'custom';
                }
                $label = $options[0];
                if ($label) {
                    $array[$key] = array('label' => $label, 'type' => $type);
                }
            }
        }
        if (is_array($array)) {
            foreach ($array as $custom_field => $data) {
                $custom_field = str_replace('emd_', '', $custom_field);
                ?>
		
		<div class="emd-filter">
			
			<div class="emd-filter-head"><?php 
                echo $data['label'];
                ?>
</div>
			
			<?php 
                if ($data['type'] == 'dropdown') {
                    ?>
			<select name="emd-<?php 
                    echo $custom_field;
                    ?>
" id="emd-<?php 
                    echo $custom_field;
                    ?>
" class="chosen-select" data-placeholder="<?php 
                    echo $this->placeholder($custom_field);
                    ?>
">
				<?php 
                    $this->loop_options($custom_field);
                    ?>
			</select>
			<?php 
                }
                ?>
			
			<?php 
                if ($data['type'] == 'radio') {
                    ?>
			<?php 
                    $this->loop_options_radio($custom_field);
                    ?>
			<?php 
                }
                ?>
			
			<?php 
                if ($data['type'] == 'input') {
                    ?>
			<div class="userpro-input">
				<input type="text" name="emd-<?php 
                    echo $custom_field;
                    ?>
" id="emd-<?php 
                    echo $custom_field;
                    ?>
" placeholder="<?php 
                    echo $this->placeholder($custom_field);
                    ?>
" value="<?php 
                    echo $this->try_text_value($custom_field);
                    ?>
" />
			</div><div class="userpro-clear"></div>
			<?php 
                }
                ?>
			
			<?php 
                if ($data['type'] == 'custom') {
                    ?>
			<?php 
                    $this->loop_custom_options($custom_field);
                    ?>
			<?php 
                }
                ?>
			
		</div>
		
		<?php 
            }
        }
    }
function userpro_modify_search_filters($args)
{
    global $userpro_emd;
    $big_array = userpro_retrieve_metakeys();
    foreach ($args as $key => $v) {
        if (in_array($key, $big_array) || in_array(str_replace('search_', '', $key), $big_array)) {
            $options = explode(',', $args[$key]);
            if (!isset($options[1])) {
                $type = 'input';
            } else {
                $type = $options[1];
            }
            if (in_array($key, $userpro_emd->must_be_custom_fields)) {
                $type = 'custom';
            }
            $label = $options[0];
            if ($label) {
                $array[$key] = array('label' => $label, 'type' => $type);
            }
        }
        if (in_array($key, $big_array) || in_array(str_replace('search_from_', '', $key), $big_array) || in_array(str_replace('search_to_', '', $key), $big_array)) {
            $options = explode(',', $args[$key]);
            if (!isset($options[1])) {
                $type = 'input';
            } else {
                $type = $options[1];
            }
            if (in_array($key, $userpro_emd->must_be_custom_fields)) {
                $type = 'custom';
            }
            $label = $options[0];
            if ($label) {
                $array[$key] = array('label' => $label, 'type' => $type);
            }
        }
    }
    if (isset($array) && userpro_retrieve_metakeys()) {
        foreach (userpro_retrieve_metakeys() as $key) {
            unset($array[$key]);
            // remove native keys
        }
    }
    if (isset($array) && isset($array['role'])) {
        unset($array['role']);
        // remove role
    }
    if (isset($array) && is_array($array)) {
        foreach ($array as $custom_field => $data) {
            $custom_field = str_replace('search_', '', $custom_field);
            $purekey = str_replace('from_', '', $custom_field);
            $purekey = str_replace('to_', '', $purekey);
            ?>
		
		<div class="emd-filter">
			
			<div class="emd-filter-head"><?php 
            echo $data['label'];
            ?>
</div>
			
			<?php 
            if ($data['type'] == 'dropdown') {
                ?>
			
			<?php 
                if (strstr($custom_field, 'from_') || strstr($custom_field, 'to_')) {
                    ?>
			
			<?php 
                    if (isset($args[$purekey . '_range'])) {
                        $range = $args[$purekey . '_range'];
                    } else {
                        $range = '1,100';
                    }
                    ?>
			
			<select name="emd-<?php 
                    echo $custom_field;
                    ?>
" id="emd-<?php 
                    echo $custom_field;
                    ?>
" class="chosen-select-compact" data-placeholder="<?php 
                    echo $data['label'];
                    ?>
">
				<?php 
                    $userpro_emd->loop_options($custom_field, $num_range = $range);
                    ?>
			</select>
			
			<?php 
                } else {
                    ?>
			
			<select name="emd-<?php 
                    echo $custom_field;
                    ?>
" id="emd-<?php 
                    echo $custom_field;
                    ?>
" class="chosen-select" data-placeholder="<?php 
                    echo $data['label'];
                    ?>
">
				<?php 
                    $userpro_emd->loop_options($custom_field);
                    ?>
			</select>
			
			<?php 
                }
                ?>
			
			<?php 
            }
            ?>
			
			<?php 
            if ($data['type'] == 'radio') {
                ?>
			<?php 
                $userpro_emd->loop_options_radio($custom_field);
                ?>
			<?php 
            }
            ?>
			
			<?php 
            if ($data['type'] == 'input') {
                ?>
			<div class="userpro-input">
				<input type="text" name="emd-<?php 
                echo $custom_field;
                ?>
" id="emd-<?php 
                echo $custom_field;
                ?>
" placeholder="<?php 
                echo $data['label'];
                ?>
" value="<?php 
                echo $userpro_emd->try_text_value($custom_field);
                ?>
" />
			</div><div class="userpro-clear"></div>
			<?php 
            }
            ?>
			
			<?php 
            if ($data['type'] == 'custom') {
                ?>
			<?php 
                $userpro_emd->loop_custom_options($custom_field);
                ?>
			<?php 
            }
            ?>
			
		</div>
		
		<?php 
        }
    }
}