Ejemplo n.º 1
0
function ap_user_template()
{
    $userid = ap_get_user_page_user();
    $user_meta = (object) array_map('ap_meta_array_map', get_user_meta($userid));
    if (is_ap_followers()) {
        $total_followers = ap_get_current_user_meta('followers');
        // how many users to show per page
        $users_per_page = ap_opt('followers_limit');
        // grab the current page number and set to 1 if no page number is set
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        // calculate the total number of pages.
        $total_pages = 1;
        $offset = $users_per_page * ($paged - 1);
        $total_pages = ceil($total_followers / $users_per_page);
        $args = array('ap_followers_query' => true, 'number' => $users_per_page, 'userid' => ap_get_user_page_user(), 'offset' => $offset);
        // The Query
        $followers_query = new WP_User_Query($args);
        $followers = $followers_query->results;
        $base = ap_user_link(ap_get_user_page_user(), 'followers') . '/%_%';
    } elseif (ap_current_user_page_is('following')) {
        $total_following = ap_get_current_user_meta('following');
        // how many users to show per page
        $users_per_page = ap_opt('following_limit');
        // grab the current page number and set to 1 if no page number is set
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        // calculate the total number of pages.
        $total_pages = 1;
        $offset = $users_per_page * ($paged - 1);
        $total_pages = ceil($total_following / $users_per_page);
        $args = array('ap_following_query' => true, 'number' => $users_per_page, 'userid' => ap_get_user_page_user(), 'offset' => $offset);
        // The Query
        $following_query = new WP_User_Query($args);
        $following = $following_query->results;
        $base = ap_user_link(ap_get_user_page_user(), 'following') . '/%_%';
    } elseif (ap_current_user_page_is('questions')) {
        $order = get_query_var('sort');
        $label = sanitize_text_field(get_query_var('label'));
        if (empty($order)) {
            $order = 'active';
        }
        //ap_opt('answers_sort');
        if (empty($label)) {
            $label = '';
        }
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $question_args = array('author' => ap_get_user_page_user(), 'post_type' => 'question', 'post_status' => 'publish', 'showposts' => ap_opt('question_per_page'), 'paged' => $paged);
        if ($order == 'active') {
            $question_args['orderby'] = 'meta_value';
            $question_args['meta_key'] = ANSPRESS_UPDATED_META;
        } elseif ($order == 'voted') {
            $question_args['orderby'] = 'meta_value_num';
            $question_args['meta_key'] = ANSPRESS_VOTE_META;
        } elseif ($order == 'answers') {
            $question_args['orderby'] = 'meta_value_num';
            $question_args['meta_key'] = ANSPRESS_ANS_META;
        } elseif ($order == 'unanswered') {
            $question_args['orderby'] = 'meta_value';
            $question_args['meta_key'] = ANSPRESS_ANS_META;
            $question_args['meta_value'] = '0';
        } elseif ($order == 'oldest') {
            $question_args['orderby'] = 'date';
            $question_args['order'] = 'ASC';
        }
        if ($label != '') {
            $question_args['tax_query'] = array(array('taxonomy' => 'question_label', 'field' => 'slug', 'terms' => $label));
        }
        $question_args = apply_filters('ap_user_question_args', $question_args);
        $question = new WP_Query($question_args);
    } elseif (ap_current_user_page_is('answers')) {
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $order = get_query_var('sort');
        if (empty($order)) {
            $order = ap_opt('answers_sort');
        }
        if ($order == 'voted') {
            $ans_args = array('author' => ap_get_user_page_user(), 'ap_query' => 'answer_sort_voted', 'post_type' => 'answer', 'post_status' => 'publish', 'showposts' => ap_opt('answers_per_page'), 'paged' => $paged, 'orderby' => 'meta_value_num', 'meta_key' => ANSPRESS_VOTE_META, 'meta_query' => array('relation' => 'OR', array('key' => ANSPRESS_BEST_META, 'compare' => '=', 'value' => '1'), array('key' => ANSPRESS_BEST_META, 'compare' => 'NOT EXISTS')));
        } elseif ($order == 'oldest') {
            $ans_args = array('author' => ap_get_user_page_user(), 'ap_query' => 'answer_sort_newest', 'post_type' => 'answer', 'post_status' => 'publish', 'showposts' => ap_opt('answers_per_page'), 'paged' => $paged, 'orderby' => 'meta_value date', 'meta_key' => ANSPRESS_BEST_META, 'order' => 'ASC', 'meta_query' => array('relation' => 'OR', array('key' => ANSPRESS_BEST_META, 'compare' => 'NOT EXISTS')));
        } else {
            $ans_args = array('author' => ap_get_user_page_user(), 'ap_query' => 'answer_sort_newest', 'post_type' => 'answer', 'post_status' => 'publish', 'showposts' => ap_opt('answers_per_page'), 'paged' => $paged, 'orderby' => 'meta_value date', 'meta_key' => ANSPRESS_BEST_META, 'order' => 'DESC', 'meta_query' => array('relation' => 'OR', array('key' => ANSPRESS_BEST_META, 'compare' => 'NOT EXISTS')));
        }
        $ans_args = apply_filters('ap_user_answers_args', $ans_args);
        $answer = new WP_Query($ans_args);
    } elseif (ap_current_user_page_is('favorites')) {
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $args = array('author' => ap_get_user_page_user(), 'ap_query' => 'user_favorites', 'post_type' => 'question', 'post_status' => 'publish', 'showposts' => ap_opt('answers_per_page'), 'paged' => $paged, 'orderby' => 'date', 'order' => 'DESC');
        $args = apply_filters('ap_user_favorites_args', $args);
        $question = new WP_Query($args);
    } elseif (ap_current_user_page_is('messages')) {
        if (ap_get_user_page_user() != get_current_user_id()) {
            _e('You do not have access here', 'ap');
            return;
        }
    } elseif (ap_current_user_page_is('message')) {
        if (ap_get_user_page_user() != get_current_user_id()) {
            _e('You do not have access here', 'ap');
            return;
        }
        $message_id = get_query_var('message_id');
    } elseif (ap_current_user_page_is('badges')) {
        $user_badges = ap_get_users_all_badges(ap_get_user_page_user());
        $count_badges = ap_user_badge_count_by_badge(ap_get_user_page_user());
    }
    global $user;
    global $current_user_meta;
    include ap_get_theme_location(ap_get_current_user_page_template());
    // Restore original Post Data
    if (ap_current_user_page_is('questions') || ap_current_user_page_is('answers') || ap_current_user_page_is('favorites')) {
        wp_reset_postdata();
    }
}
Ejemplo n.º 2
0
function ap_user_have_badge_type($user_id, $type)
{
    $badges = ap_get_users_all_badges($user_id, $type);
}