public function widget($args, $instance) { global $questions; $title = apply_filters('widget_title', $instance['title']); $sort = $instance['sort']; $limit = $instance['limit']; $category_ids = $instance['category_ids']; if (!empty($category_ids)) { $category_ids = explode(',', str_replace(' ', '', $category_ids)); } echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } $question_args = array('showposts' => $limit, 'sortby' => $sort); if (is_array($category_ids) && count($category_ids) > 0) { $question_args['tax_query'][] = array('taxonomy' => 'question_category', 'field' => 'term_id', 'terms' => $category_ids); } $questions = ap_get_questions($question_args); echo '<div class="ap-widget-inner">'; ap_get_template_part('widget-questions'); echo '</div>'; echo $args['after_widget']; wp_reset_postdata(); }
/** * Layout of base page */ public function base_page() { global $questions, $wp; $query = $wp->query_vars; $tax_relation = @$wp->query_vars['ap_sc_atts_tax_relation']; $tax_relation = !empty($tax_relation) ? $tax_relation : 'OR'; $tags_operator = @$wp->query_vars['ap_sc_atts_tags_operator']; $tags_operator = !empty($tags_operator) ? $tags_operator : 'IN'; $categories_operator = @$wp->query_vars['ap_sc_atts_categories_operator']; $categories_operator = !empty($categories_operator) ? $categories_operator : 'IN'; $args = array(); $args['tax_query'] = array('relation' => $tax_relation); if (isset($query['ap_sc_atts_tags']) && is_array($query['ap_sc_atts_tags'])) { $args['tax_query'][] = array('taxonomy' => 'question_tag', 'field' => 'slug', 'terms' => $query['ap_sc_atts_tags'], 'operator' => $tags_operator); } elseif (isset($_GET['ap_tag_sort']) && 0 != $_GET['ap_tag_sort']) { $cat = (int) $_GET['ap_tag_sort']; $args['tax_query'][] = array('taxonomy' => 'question_tag', 'field' => 'term_id', 'terms' => array($cat)); } if (isset($query['ap_sc_atts_categories']) && is_array($query['ap_sc_atts_categories'])) { $args['tax_query'][] = array('taxonomy' => 'question_category', 'field' => 'slug', 'terms' => $query['ap_sc_atts_categories'], 'operator' => $categories_operator); } elseif (isset($_GET['ap_cat_sort']) && 0 != $_GET['ap_cat_sort']) { $cat = (int) $_GET['ap_cat_sort']; $args['tax_query'][] = array('taxonomy' => 'question_category', 'field' => 'term_id', 'terms' => array($cat)); } /** * FILTER: ap_main_questions_args * Filter main question list args * @var array */ $args = apply_filters('ap_main_questions_args', $args); $questions = ap_get_questions($args); ap_get_template_part('base'); }
/** * Output widget * @param array $args Widget arguments. * @param array $instance Widget instance. */ public function widget($args, $instance) { global $ap_activities; $ap_activities = ap_get_activities(array('per_page' => 20, 'notification' => true, 'user_id' => ap_get_displayed_user_id())); echo $args['before_widget']; ap_get_template_part('widgets/notifications'); echo $args['after_widget']; }
public function questions_screen_content() { global $questions; $questions = new Question_Query(array('author' => bp_displayed_user_id())); echo '<div id="anspress">'; ap_get_template_part('buddypress/user-questions'); echo '</div>'; wp_reset_postdata(); }
public function reputation_screen_content() { global $wpdb; $user_id = bp_displayed_user_id(); $reputation = ap_get_all_reputation($user_id); echo '<div id="anspress">'; include ap_get_template_part('user/reputation'); echo '</div>'; }
public function widget($args, $instance) { $title = apply_filters('widget_title', $instance['title']); $order = $instance['order']; $limit = $instance['limit']; echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } $question_args = array('showposts' => $limit, 'orderby' => $order); $questions = ap_get_questions($question_args); ap_get_template_part('widget-questions'); echo $args['after_widget']; wp_reset_postdata(); }
public function widget($args, $instance) { $title = apply_filters('widget_title', $instance['title']); echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } global $ap_user_query; if (is_user_logged_in()) { $ap_user_query = ap_has_users(array('ID' => ap_get_displayed_user_id())); if ($ap_user_query->has_users()) { while (ap_users()) { ap_the_user(); ap_get_template_part('widgets/user'); } } } else { _e('Login to see your profile links', 'ap'); } echo $args['after_widget']; }
?> <div class="ap-questions"> <?php /* Start the Loop */ while (ap_questions()) { ap_the_question(); ap_get_template_part('content-list'); } ?> </div> <?php ap_questions_the_pagination(); ?> <?php } else { ap_get_template_part('content-none'); } ?> </div> <?php if (is_active_sidebar('ap-sidebar') && is_anspress()) { ?> <div class="ap-question-right col-md-3"> <?php dynamic_sidebar('ap-sidebar'); ?> </div> <?php } ?>
<span class="ap-about-rep-label"><?php _e('Total', 'ap'); ?> </span> <span class="ap-about-rep-count"><?php ap_user_the_reputation(); ?> </span> </div> <div class="ap-about-rep-chart"> <span data-action="ap_chart" data-type="bar" data-peity='{"fill" : ["#8fc77e"], "height": 45, "width": "100%"}'><?php echo ap_user_get_28_days_reputation(); ?> </span> </div> <div class="ap-user-rep"> <?php if (ap_has_reputations()) { while (ap_reputations()) { ap_the_reputation(); ap_get_template_part('user/reputation-content'); } ap_pagination(false, anspress()->reputations->total_pages); } else { _e('No reputation earned yet.', 'ap'); } ?> </div> </div> </div>
public function reputation_page() { ap_get_template_part('user/reputation'); }
/** * Add user dropdown and notification menu * @param string $o Menu html. * @param object $item Menu item object. * @param integer $depth Menu depth. * @param object $args Menu args. * @return string */ public function walker_nav_menu_start_el($o, $item, $depth, $args) { if (!is_user_logged_in() && (in_array('anspress-page-profile', $item->classes) || in_array('anspress-page-notification', $item->classes))) { $o = ''; } if (in_array('anspress-page-profile', $item->classes) && is_user_logged_in()) { $menus = ap_get_user_menu(get_current_user_id()); $active_user_page = get_query_var('user_page') ? esc_attr(get_query_var('user_page')) : 'about'; $o = '<a id="ap-user-menu-anchor" class="ap-dropdown-toggle" href="#">'; $o .= get_avatar(get_current_user_id(), 80); $o .= '<span class="name">' . ap_user_display_name(get_current_user_id()) . '</span>'; $o .= ap_icon('chevron-down', true); $o .= '</a>'; $o .= '<ul id="ap-user-menu-link" class="ap-dropdown-menu ap-user-dropdown-menu">'; foreach ($menus as $m) { $class = !empty($m['class']) ? ' ' . $m['class'] : ''; $o .= '<li' . ($active_user_page == $m['slug'] ? ' class="active"' : '') . '>'; $o .= '<a href="' . $m['link'] . '" class="ap-user-link-' . $m['slug'] . $class . '">'; $o .= esc_attr($m['title']) . '</a>'; $o .= '</li>'; } $o .= '</ul>'; } elseif (in_array('anspress-page-notification', $item->classes) && is_user_logged_in()) { $o = '<a id="ap-user-notification-anchor" class="ap-dropdown-toggle ' . ap_icon('globe') . '" href="#">' . ap_get_the_total_unread_notification(false, false) . '</a>'; global $ap_notifications; ob_start(); $ap_notifications = ap_get_user_notifications(array('per_page' => 10)); ap_get_template_part('user/notification-dropdown'); $o .= ob_get_clean(); } return $o; }
/** * Handle Ajax callback for user hover card */ public function ap_user_card() { if (ap_opt('disable_hover_card')) { $this->something_wrong(); } $user_id = (int) $_POST['user_id']; if (!ap_verify_default_nonce()) { $this->something_wrong(); } global $ap_user_query; $ap_user_query = ap_has_users(array('ID' => $user_id)); if ($ap_user_query->has_users()) { while (ap_users()) { ap_the_user(); ap_get_template_part('user/user-card'); } } wp_die(); }
/** * Process answer form */ public function process_answer_form() { global $ap_errors, $validate; if (ap_show_captcha_to_user() && !$this->check_recaptcha()) { $this->result = array('form' => $_POST['ap_form_action'], 'message' => 'captcha_error', 'errors' => array('captcha' => __('Bot verification failed.', 'ap'))); return; } $question = get_post((int) $_POST['form_question_id']); $args = array('description' => array('sanitize' => array('remove_more', 'encode_pre_code', 'wp_kses'), 'validate' => array('required' => true, 'length_check' => ap_opt('minimum_question_length'))), 'is_private' => array('sanitize' => array('only_boolean')), 'name' => array('sanitize' => array('strip_tags', 'sanitize_text_field')), 'form_question_id' => array('sanitize' => array('only_int')), 'edit_post_id' => array('sanitize' => array('only_int'))); /** * FILTER: ap_answer_fields_validation * Filter can be used to modify answer form fields. * @var void * @since 2.0.1 */ $args = apply_filters('ap_answer_fields_validation', $args); $validate = new AnsPress_Validation($args); $ap_errors = $validate->get_errors(); // if error in form then return if ($validate->have_error()) { $this->result = array('form' => $_POST['ap_form_action'], 'message_type' => 'error', 'message' => __('Check missing fields and then re-submit.', 'ap'), 'errors' => $ap_errors); return; } $fields = $validate->get_sanitized_fields(); $this->fields = $fields; if (!empty($fields['edit_post_id'])) { $this->edit_answer($question); return; } // Do security check, if fails then return if (!ap_user_can_answer($question->ID) || !isset($_POST['__nonce']) || !wp_verify_nonce($_POST['__nonce'], 'nonce_answer_' . $question->ID)) { $this->result = ap_ajax_responce('no_permission'); return; } $user_id = get_current_user_id(); $status = 'publish'; if (ap_opt('new_answer_status') == 'moderate' || ap_opt('new_answer_status') == 'point' && ap_get_points($user_id) < ap_opt('new_answer_status')) { $status = 'moderate'; } if (isset($this->fields['is_private']) && $this->fields['is_private']) { $status = 'private_post'; } $answer_array = array('post_title' => $question->post_title, 'post_author' => $user_id, 'post_content' => apply_filters('ap_form_contents_filter', $fields['description']), 'post_parent' => $question->ID, 'post_type' => 'answer', 'post_status' => $status, 'comment_status' => 'open'); /** * FILTER: ap_pre_insert_answer * Can be used to modify args before inserting answer * @var array * @since 2.0.1 */ $answer_array = apply_filters('ap_pre_insert_answer', $answer_array); $post_id = wp_insert_post($answer_array); if ($post_id) { // get existing answer count $current_ans = ap_count_published_answers($question->ID); if (!is_user_logged_in() && ap_opt('allow_anonymous') && isset($fields['name'])) { update_post_meta($post_id, 'anonymous_name', $fields['name']); } if ($this->is_ajax) { if ($current_ans == 1) { global $post; $post = $question; setup_postdata($post); } else { global $post; $post = get_post($post_id); setup_postdata($post); } ob_start(); global $answers; if ($current_ans == 1) { $answers = ap_get_answers(array('question_id' => $question->ID)); ap_get_template_part('answers'); } else { $answers = ap_get_answers(array('p' => $post_id)); while (ap_have_answers()) { ap_the_answer(); ap_get_template_part('answer'); } } $html = ob_get_clean(); $count_label = sprintf(_n('1 Answer', '%d Answers', $current_ans, 'ap'), $current_ans); $result = array('postid' => $post_id, 'action' => 'new_answer', 'div_id' => '#answer_' . get_the_ID(), 'can_answer' => ap_user_can_answer($post->ID), 'html' => $html, 'message' => 'answer_submitted', 'do' => 'clearForm', 'view' => array('answer_count' => $current_ans, 'answer_count_label' => $count_label)); $this->result = $result; } } $this->process_image_uploads($post_id, $user_id); }
/** * Add user dropdown and notification menu * @param string $o Menu html. * @param object $item Menu item object. * @param integer $depth Menu depth. * @param object $args Menu args. * @return string */ public function walker_nav_menu_start_el($o, $item, $depth, $args) { if (!is_user_logged_in() && (ap_is_notification_menu($item) || ap_is_profile_menu($item))) { $o = ''; } if (!ap_is_profile_active() && (ap_is_notification_menu($item) || ap_is_profile_menu($item))) { return ''; } if (in_array('anspress-page-profile', $item->classes) && is_user_logged_in()) { $menus = ap_get_user_menu(get_current_user_id()); $active_user_page = get_query_var('user_page') ? esc_attr(get_query_var('user_page')) : 'about'; $o = '<a id="ap-user-menu-anchor" class="ap-dropdown-toggle" href="#">'; $o .= get_avatar(get_current_user_id(), 80); $o .= '<span class="name">' . ap_user_display_name(get_current_user_id()) . '</span>'; $o .= ap_icon('chevron-down', true); $o .= '</a>'; $o .= '<ul id="ap-user-menu-link" class="ap-dropdown-menu ap-user-dropdown-menu">'; foreach ($menus as $m) { $class = !empty($m['class']) ? ' ' . $m['class'] : ''; $o .= '<li' . ($active_user_page == $m['slug'] ? ' class="active"' : '') . '>'; $o .= '<a href="' . $m['link'] . '" class="ap-user-link-' . $m['slug'] . $class . '">'; $o .= $m['title'] . '</a>'; $o .= '</li>'; } $o .= '</ul>'; } elseif (in_array('anspress-page-notification', $item->classes) && is_user_logged_in()) { $o = '<a id="ap-user-notification-anchor" class="ap-dropdown-toggle ap-sidetoggle ' . ap_icon('globe') . '" href="#">' . ap_get_the_total_unread_notification(false, false) . '</a>'; global $ap_activities; /** * Dropdown notification arguments. * Allow filtering of dropdown notification arguments. * @since 2.4.5 * @var array */ $notification_args = apply_filters('ap_dropdown_notification_args', array('per_page' => 20, 'notification' => true, 'user_id' => ap_get_displayed_user_id())); $ap_activities = ap_get_activities($notification_args); ob_start(); ap_get_template_part('user/notification-dropdown'); $o .= ob_get_clean(); } return $o; }
<div id="ap-lists"> <h3 class="ap-user-page-title clearfix"> <?php echo ap_page_title(); ?> <?php ap_get_template_part('list-head'); ?> </h3> <?php if (ap_have_questions()) { ?> <div class="ap-questions"> <?php /* Start the Loop */ while (ap_questions()) { ap_the_question(); ap_get_template_part('user/list-question'); } ?> </div> <?php ap_questions_the_pagination(); ?> <?php } else { include ap_get_theme_location('content-none.php'); } ?> </div>
public function ap_user_cover() { if (ap_opt('disable_hover_card')) { ap_send_json(ap_ajax_responce('something_wrong')); } $user_id = (int) $_POST['user_id']; if (!wp_verify_nonce($_POST['ap_ajax_nonce'], 'ap_ajax_nonce')) { ap_send_json(ap_ajax_responce('something_wrong')); return; } global $ap_user_query; $ap_user_query = ap_has_users(array('ID' => $user_id)); if ($ap_user_query->has_users()) { while (ap_users()) { ap_the_user(); ap_get_template_part('user/user-card'); } } else { ap_send_json(ap_ajax_responce('something_wrong')); } die; }
/** * Register user subscription page * @since 2.3 */ public function subscription_page() { global $questions; if (!ap_is_user_page_public('profile') && !ap_is_my_profile()) { ap_get_template_part('not-found'); return; } $questions = ap_get_questions(array('ap_query' => 'ap_subscription_query', 'user_id' => get_current_user_id(), 'sortby' => 'newest')); ap_get_template_part('user/subscription'); }
ap_question_subscribers($question_category->term_id, 'category'); ?> <?php $sub_cat_count = count(get_term_children($question_category->term_id, 'question_category')); if ($sub_cat_count > 0) { echo '<div class="ap-term-sub">'; echo '<div class="sub-taxo-label">' . $sub_cat_count . ' ' . __('Sub Categories', 'categories-for-anspress') . '</div>'; ap_sub_category_list($question_category->term_id); echo '</div>'; } ?> </div><!-- close .ap-taxo-detail --> <?php ap_get_template_part('list-head'); ?> <?php if (ap_have_questions()) { ?> <div class="ap-questions"> <?php /* Start the Loop */ while (ap_questions()) { ap_the_question(); include ap_get_theme_location('content-list.php'); } ?> </div><!-- close .ap-questions -->
ap_how_to_ask(); ?> <?php } ?> </div> </div> </div> </div> <?php } elseif (is_user_logged_in()) { ?> <div class="ap-no-permission"> <?php _e('You dont have permission to ask question.', 'ap'); ?> </div> <?php } ?> <?php ap_get_template_part('login-signup'); ?> </div>
<div id="ap-lists"> <h3 class="ap-user-page-title clearfix"> <?php echo ap_page_title(); ?> </h3> <?php if (ap_have_answers()) { ?> <div class="ap-answers"> <?php while (ap_have_answers()) { ap_the_answer(); ap_get_template_part('user/list-answer'); } ?> </div> <?php ap_answers_the_pagination(); ?> <?php } else { include ap_get_theme_location('content-none.php'); } ?> </div>
/** * Output for user questions page * @since 2.1 */ public function questions_page() { global $questions; $questions = ap_get_questions(array('author' => ap_get_displayed_user_id())); ap_get_template_part('user/user-questions'); wp_reset_postdata(); }
/** * Register user subscription page * @since 2.3 */ public function subscription_page() { if (!ap_is_user_page_public('profile') && !ap_is_my_profile()) { ap_get_template_part('not-found'); return; } ap_get_questions(array('ap_query' => 'ap_subscription_query', 'user_id' => get_current_user_id(), 'sortby' => 'newest')); include ap_get_theme_location('user/subscription.php'); }