function ap_get_breadcrumbs() { $current_page = get_query_var('ap_page'); $title = ap_page_title(); $a = array(); $a['base'] = array('title' => ap_opt('base_page_title'), 'link' => ap_base_page_link(), 'order' => 0); if (is_question_tag()) { $a['tag'] = array('title' => __('Tags', 'ap'), 'link' => '', 'order' => 10); } elseif (is_question()) { $a['page'] = array('title' => substr($title, 0, 30) . (strlen($title) > 30 ? __('..', 'ap') : ''), 'link' => get_permalink(get_question_id()), 'order' => 10); } elseif ($current_page != 'base' && $current_page != '') { if ($current_page == 'user') { $a['page'] = array('title' => __('User', 'ap'), 'link' => ap_user_link(ap_get_displayed_user_id()), 'order' => 10); $a['user_page'] = array('title' => substr($title, 0, 30) . (strlen($title) > 30 ? __('..', 'ap') : ''), 'link' => ap_user_link(ap_get_displayed_user_id(), get_query_var('user_page')), 'order' => 10); } else { $a['page'] = array('title' => substr($title, 0, 30) . (strlen($title) > 30 ? __('..', 'ap') : ''), 'link' => ap_get_link_to($current_page), 'order' => 10); } } $a = apply_filters('ap_breadcrumbs', $a); return ap_sort_array_by_order($a); }
/** * Output subscribe btn HTML * @param boolean|integer $action_id Question ID or Term ID * @return string * @since 2.0.1 */ function ap_subscribe_btn_html($action_id = false, $type = false) { global $question_category, $question_tag; if ($action_id === false) { if (is_question()) { $action_id = get_question_id(); } elseif (is_question_category()) { $action_id = $question_category->term_id; } elseif (is_question_tag()) { $action_id = $question_tag->term_id; } } if ($type == false) { if (is_question_category()) { $subscribe_type = 'category'; } elseif (is_question_tag()) { $subscribe_type = 'tag'; } else { $subscribe_type = false; } } else { if ($type === 'category') { $subscribe_type = 'category'; } elseif ($type === 'tag') { $subscribe_type = 'tag'; } else { $subscribe_type = false; } } $subscribed = ap_is_user_subscribed($action_id, false, $subscribe_type); $nonce = wp_create_nonce('subscribe_' . $action_id . '_' . $subscribe_type); $title = !$subscribed ? __('Follow question', 'ap') : __('Unfollow question', 'ap'); ?> <div class="ap-subscribe" id="<?php echo 'subscribe_' . $action_id; ?> "> <a href="#" class="ap-btn-toggle<?php echo $subscribed ? ' active' : ''; ?> " data-query="ap_ajax_action=subscribe&action_id=<?php echo $action_id; ?> &__nonce=<?php echo $nonce; ?> &type=<?php echo $subscribe_type; ?> " data-action="ap_subscribe" data-args="<?php echo $action_id . '-' . $nonce; ?> "> <span class="apicon-toggle-on"></span> <span class="apicon-toggle-off"></span> </a> <b><?php echo $title; ?> </b> </div> <?php }
public function ap_breadcrumbs($navs) { if (is_question_tag()) { $tag_id = sanitize_text_field(get_query_var('q_tag')); $tag = get_term_by(is_numeric($tag_id) ? 'id' : 'slug', $tag_id, 'question_tag'); $navs['page'] = array(); $navs['tag'] = array('title' => $tag->name, 'link' => get_term_link($tag, 'question_tag'), 'order' => 8); } elseif (is_question_categories()) { $navs['page'] = array('title' => __('Categories', 'ap'), 'link' => ap_get_link_to('categories'), 'order' => 8); } return $navs; }
public function ap_base_page_sc($atts, $content = "") { if (!is_question()) { $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('ap_query' => 'main_questions', 'post_type' => 'question', 'post_status' => 'publish', 'showposts' => ap_opt('question_per_page'), 'paged' => $paged); if ($order == 'active') { $question_args['ap_query'] = 'main_questions_active'; $question_args['orderby'] = 'meta_value'; $question_args['meta_key'] = ANSPRESS_UPDATED_META; $question_args['meta_query'] = array('relation' => 'OR', array('key' => ANSPRESS_UPDATED_META, 'compare' => 'NOT EXISTS')); } 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_main_query_args', $question_args); } if (is_question()) { $args = array('p' => get_question_id(), 'post_type' => 'question', 'post_status' => array('moderate', 'publish')); $question = new WP_Query($args); } elseif (is_question_tag()) { $question_args['tax_query'] = array(array('taxonomy' => 'question_tags', 'field' => 'id', 'terms' => array(get_question_tag_id()))); $question = new WP_Query($question_args); $tag = $question->get_queried_object(); } elseif (is_question_cat()) { $question_args['tax_query'] = array(array('taxonomy' => 'question_category', 'field' => 'id', 'terms' => array(get_question_cat_id()))); $question = new WP_Query($question_args); $category = $question->get_queried_object(); } elseif (is_question_tags()) { $paged = get_query_var('paged') ? get_query_var('paged') : 1; $per_page = ap_opt('tags_per_page'); $total_terms = wp_count_terms('question_tags'); $offset = $per_page * ($paged - 1); $args = array('number' => $per_page, 'offset' => $offset, 'hide_empty' => false, 'orderby' => 'count', 'order' => 'DESC'); $tags = get_terms('question_tags', $args); } elseif (is_question_categories()) { $paged = get_query_var('paged') ? get_query_var('paged') : 1; $per_page = ap_opt('categories_per_page'); $total_terms = wp_count_terms('question_category'); $offset = $per_page * ($paged - 1); $cat_args = array('parent' => 0, 'number' => $per_page, 'offset' => $offset, 'hide_empty' => false, 'orderby' => 'count', 'order' => 'DESC'); $categories = get_terms('question_category', $cat_args); } elseif (is_ap_users()) { global $current_user_meta; $count_args = array('fields' => 'all_with_meta', 'number' => 999999); $user_count_query = new WP_User_Query($count_args); $user_count = $user_count_query->get_results(); // count the number of users found in the query $total_users = $user_count ? count($user_count) : 1; // how many users to show per page $per_page = ap_opt('users_per_page'); // 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 = $per_page * ($paged - 1); $total_pages = ceil($total_users / $per_page); $order = get_query_var('sort'); if (empty($order)) { $order = 'points'; } $args = array('number' => $per_page, 'offset' => $offset); if ($order == 'points') { $args['ap_query'] = 'sort_points'; $args['meta_key'] = 'ap_points'; $args['orderby'] = 'meta_value'; $args['order'] = 'DESC'; } elseif ($order == 'newest') { $args['orderby'] = 'date'; $args['order'] = 'DESC'; } // The Query $users = new WP_User_Query($args); } elseif (is_ap_user()) { global $current_user_meta; global $user; $user = get_userdata(ap_get_user_page_user()); if ($user === FALSE) { echo '<div class="user-not-found">' . __('User not found', 'ap') . '</div>'; return; } $userid = $user->data->ID; $display_name = $user->data->display_name; $username = $user->data->user_login; $current_user_meta = array_map('ap_meta_array_map', get_user_meta($userid)); } elseif (is_ap_search()) { $question_args['s'] = sanitize_text_field(get_query_var('ap_s')); $question = new WP_Query($question_args); } else { $question = new WP_Query($question_args); } echo '<div class="ap-container">'; do_action('ap_page_top'); echo '<div class="ap-dtable">'; echo '<div class="ap-cl">'; include ap_get_theme_location(ap_get_current_page_template()); if (is_ap_users()) { $base = ap_get_link_to('users') . '/%_%'; ap_pagi($base, ceil($total_users / $per_page), $paged); } if (is_question_tags()) { ap_pagi(ap_get_link_to('tags') . '/%_%', ceil($total_terms / $per_page), $paged); } if (is_question_categories()) { ap_pagi(ap_get_link_to('categories') . '/%_%', ceil($total_terms / $per_page), $paged); } echo '</div>'; if (!is_question() && is_active_sidebar('ap-sidebar')) { echo '<div class="ap-sidebar">'; dynamic_sidebar('ap-sidebar'); echo '</div>'; } echo '</div>'; if (!ap_opt('author_credits')) { ?> <div class="ap-footer"> <p class="ap-author-credit">AnsPress Version <?php echo AP_VERSION; ?> </p> </div> <?php } wp_reset_postdata(); echo '</div>'; }
public function subscribe_type($type) { if (is_question_tag()) { $subscribe_type = 'tag'; } else { return $type; } }
function ap_current_page_is() { if (is_anspress()) { if (is_question()) { $template = 'question'; } elseif (is_ask()) { $template = 'ask'; } elseif (is_question_categories()) { $template = 'categories'; } elseif (is_question_tags()) { $template = 'tags'; } elseif (is_question_tag()) { $template = 'tag'; } elseif (is_question_cat()) { $template = 'category'; } elseif (is_question_edit()) { $template = 'edit-question'; } elseif (is_answer_edit()) { $template = 'edit-answer'; } elseif (is_ap_users()) { $template = 'users'; } elseif (is_ap_user()) { $template = 'user'; } elseif (is_ap_search()) { $template = 'search'; } elseif (is_ap_revision()) { $template = 'revision'; } elseif (get_query_var('ap_page') == '') { $template = 'base'; } else { $template = 'not-found'; } return apply_filters('ap_current_page_is', $template); } return false; }
function ap_question_subscribers($action_id = false, $type = '', $avatar_size = 30) { global $question_category, $question_tag; if (false === $action_id) { if (is_question()) { $action_id = get_question_id(); } elseif (is_question_category()) { $action_id = $question_category->term_id; } elseif (is_question_tag()) { $action_id = $question_tag->term_id; } } if ($type == '') { $type = is_question() ? 'q_all' : 'tax_new_q'; } $subscribers = ap_get_subscribers($action_id, $type); if ($subscribers) { echo '<div class="ap-question-subscribers clearfix">'; echo '<div class="ap-question-subscribers-inner">'; foreach ($subscribers as $subscriber) { echo '<a href="' . ap_user_link($subscriber->subs_user_id) . '"'; ap_hover_card_attributes($subscriber->subs_user_id); echo '>' . get_avatar($subscriber->subs_user_id, $avatar_size) . '</a>'; } echo '</div>'; echo '</div>'; } }
public function subscribe_btn_action_type($args) { if (is_question_tag()) { global $question_tag; $args['action_id'] = $question_tag->term_id; $args['type'] = 'tag'; } return $args; }