public function widget($args, $instance) { global $questions; $title = apply_filters('widget_title', $instance['title']); echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } echo '<div class="ap-widget-inner">'; if (!class_exists('Tags_For_AnsPress')) { echo 'Tags plugin must be installed for related question. Get <a href="https://wordpress.org/plugins/tags-for-anspress">Tags for AnsPress</a>'; return; } $tags = get_the_terms(get_question_id(), 'question_tag'); $tags_in = array(); if ($tags) { foreach ($tags as $t) { $tags_in[] = $t->term_id; } } $question_args = array('tax_query' => array(array('taxonomy' => 'question_tag', 'field' => 'term_id', 'terms' => $tags_in)), 'showposts' => 5, 'post__not_in' => array(get_question_id())); $questions = ap_get_questions($question_args); include ap_get_theme_location('widget-related_questions.php'); wp_reset_postdata(); echo '</div>'; echo $args['after_widget']; }
public function comment_template($comment_template) { global $post; if ($post->post_type == 'question' || $post->post_type == 'answer') { return ap_get_theme_location('comments.php'); } }
public function widget($args, $instance) { $title = apply_filters('widget_title', $instance['title']); $number = $instance['number']; echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } $user_a = array('number' => $number, 'ap_query' => 'sort_points', 'meta_key' => 'ap_points', 'orderby' => 'meta_value'); // The Query $users = new WP_User_Query($user_a); include ap_get_theme_location('users-widget.php'); echo $args['after_widget']; }
public function widget($args, $instance) { $title = apply_filters('widget_title', $instance['title']); $avatar = $instance['avatar']; $order = $instance['order']; $show_selected = $instance['show_selected']; $show_activity = $instance['show_activity']; $show_answers = $instance['show_answers']; $show_vote = $instance['show_vote']; $show_views = $instance['show_views']; $show_category = $instance['show_category']; $show_tags = $instance['show_tags']; $label = $instance['label']; $limit = $instance['limit']; echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } if (empty($label)) { $label = ''; } $question_args = array('ap_query' => 'main_questions', 'post_type' => 'question', 'post_status' => 'publish', 'showposts' => $limit); 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 = new WP_Query($question_args); include ap_get_theme_location('questions-widget.php'); echo $args['after_widget']; wp_reset_postdata(); }
/** * Find bad words in a string. * @param string $str String need to be checked. * @return array|boolean * @since 2.4.5 */ function ap_find_bad_words($str) { $bad_word_file = ap_get_theme_location('badwords.txt'); // Return if badwords.txt file does not exists. if (!file_exists($bad_word_file)) { return false; } $words = file($bad_word_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $found = array(); foreach ($words as $w) { $count = preg_match_all('/\\b' . preg_quote($w, '/') . '\\b/i', $str); if ($count > 0) { $found[$w] = $count; } } if (!empty($found)) { return $found; } return false; }
public function widget($args, $instance) { $title = apply_filters('widget_title', $instance['title']); $number = $instance['number']; $avatar_size = $instance['avatar_size']; echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } if (is_ap_user()) { $followers = ap_has_users(array('user_id' => ap_get_displayed_user_id(), 'sortby' => 'followers')); if ($followers->has_users()) { include ap_get_theme_location('widgets/followers.php'); } else { _e('No followers yet', 'ap'); } } else { _e('This widget can only be used in user page.', 'ap'); } echo $args['after_widget']; }
public function widget($args, $instance) { global $ap_user_query; $title = apply_filters('widget_title', $instance['title']); $number = $instance['number']; $sortby = $instance['sortby']; echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } $user_a = array('number' => $number, 'sortby' => $sortby); // The Query. $ap_user_query = ap_has_users($user_a); echo '<div class="ap-widget-inner">'; while (ap_users()) { ap_the_user(); include ap_get_theme_location('users/loop-item.php'); } echo '</div>'; echo $args['after_widget']; }
public function widget($args, $instance) { $title = apply_filters('widget_title', $instance['title']); $avatar = $instance['avatar']; $show_selected = $instance['show_selected']; $show_activity = $instance['show_activity']; $show_answers = $instance['show_answers']; $show_vote = $instance['show_vote']; $show_views = $instance['show_views']; $show_category = $instance['show_category']; $show_tags = $instance['show_tags']; echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } $question_args = array('ap_query' => 'related', 'ap_title' => get_the_title(get_question_id()), 'post_type' => 'question', 'post__not_in' => array(get_question_id()), 'post_status' => 'publish', 'showposts' => ap_opt('question_per_page')); $question = new WP_Query($question_args); include ap_get_theme_location('questions-widget.php'); echo $args['after_widget']; wp_reset_postdata(); }
/** * Control the output of [question] shortcode * @param string $content * @return string * @since 2.0.0-beta */ public function anspress_question_sc($atts, $content = '') { ob_start(); echo '<div id="anspress" class="ap-eq">'; /** * ACTION: ap_before_question_shortcode * Action is fired before loading AnsPress body. */ do_action('ap_before_question_shortcode'); $questions = ap_get_question($atts['id']); if ($questions->have_posts()) { /** * Set current question as global post * @since 2.3.3 */ while ($questions->have_posts()) { $questions->the_post(); include ap_get_theme_location('shortcode/question.php'); } } echo '</div>'; wp_reset_postdata(); return ob_get_clean(); }
function ap_comment($comment) { $GLOBALS['comment'] = $comment; $class = '0' == $comment->comment_approved ? ' pending' : ''; include ap_get_theme_location('comment.php'); }
public function subscription_page($active) { $active = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'question'; if ($active != 'category') { return; } global $question_categories, $ap_max_num_pages, $ap_per_page; $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); $ap_max_num_pages = $total_terms / $per_page; $cat_args = array('user_id' => get_current_user_id(), 'ap_query' => 'subscription', 'parent' => 0, 'number' => $per_page, 'offset' => $offset, 'hide_empty' => false, 'orderby' => 'count', 'order' => 'DESC'); $question_categories = get_terms('question_category', $cat_args); include ap_get_theme_location('categories.php', CATEGORIES_FOR_ANSPRESS_DIR); }
/** * Output answer of active question. * @return void * @since 2.1 */ function ap_question_the_answers() { global $answers; $answers = ap_get_best_answer(); include ap_get_theme_location('best_answer.php'); $answers = ap_get_answers(); include ap_get_theme_location('answers.php'); wp_reset_postdata(); }
/** * Register followers page in AnsPress */ public function following_page() { $following = ap_has_users(array('user_id' => ap_get_displayed_user_id(), 'sortby' => 'following')); if ($following->has_users()) { include ap_get_theme_location('user/following.php'); } else { esc_attr_e('You are not following anyone.', 'anspress-question-answer'); } }
<div id="ap-following" class="ap-users-lists clearfix"> <?php if (!empty($following)) { foreach ($following as $f) { $data = $f->data; $current_user_meta = array_map(function ($a) { return $a[0]; }, get_user_meta($f->ID)); include ap_get_theme_location('content-user.php'); } } else { _e('No users found.', 'ap'); } ?> </div> <?php if (!empty($following)) { ap_pagi($base, $total_pages, $paged); }
public function subscription_page($active) { $active = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'question'; if ($active != 'tag') { return; } global $question_tags, $ap_max_num_pages, $ap_per_page, $tags_rows_found; $paged = get_query_var('paged') ? get_query_var('paged') : 1; $per_page = ap_opt('tags_per_page'); $total_terms = $tags_rows_found; $offset = $per_page * ($paged - 1); $ap_max_num_pages = ceil($total_terms / $per_page); $tag_args = array('ap_tags_query' => 'num_rows', 'ap_query' => 'tags_subscription', 'parent' => 0, 'number' => $per_page, 'offset' => $offset, 'hide_empty' => false, 'order' => 'DESC', 'user_id' => get_current_user_id()); if (@$_GET['ap_sort'] == 'new') { $tag_args['orderby'] = 'id'; $tag_args['order'] = 'ASC'; } elseif (@$_GET['ap_sort'] == 'name') { $tag_args['orderby'] = 'name'; $tag_args['order'] = 'ASC'; } else { $tag_args['orderby'] = 'count'; } if (isset($_GET['ap_s'])) { $tag_args['search'] = sanitize_text_field($_GET['ap_s']); } $question_tags = get_terms('question_tag', $tag_args); include ap_get_theme_location('tags.php', TAGS_FOR_ANSPRESS_DIR); }
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(); } }
" value="<?php echo sanitize_text_field(get_query_var('ap_s')); ?> " /> <input name="type" type="hidden" value="user" /> </form> <?php ap_users_tab(); ?> </div> <div class="ap-users-loop clearfix"> <?php while (ap_users()) { ap_the_user(); include ap_get_theme_location('users/loop-item.php'); } ?> </div> <?php ap_users_the_pagination(); ?> </div> <?php if (is_active_sidebar('ap-sidebar') && is_anspress()) { ?> <div class="ap-question-right col-md-3"> <div class="ap-question-info"> <?php dynamic_sidebar('ap-sidebar'); ?>
public function question_feed() { include ap_get_theme_location('feed-question.php'); }
/** * Output answer of active question. * @return void * @since 2.1 */ function ap_question_the_answers() { include ap_get_theme_location('best_answer.php'); ap_get_answers(); include ap_get_theme_location('answers.php'); wp_reset_postdata(); }
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>'; }
/** * If page is not found then set header as 404 */ public function set_404() { global $wp_query; $wp_query->set_404(); status_header(404); include ap_get_theme_location('not-found.php'); }
public function answers_screen_content() { global $answers; $answers = new Answers_Query(array('author' => bp_displayed_user_id())); echo '<div id="anspress">'; include ap_get_theme_location('buddypress/user-answers.php'); echo '</div>'; wp_reset_postdata(); }
?> <div id="ap-lists" class="clearfix"> <?php ap_questions_tab(); ?> <?php if ($question->have_posts()) { ?> <div class="question-list"> <?php /* Start the Loop */ while ($question->have_posts()) { $question->the_post(); global $post; include ap_get_theme_location('content-list.php'); } ?> </div> <?php ap_pagination('', 2, $paged, $question); ?> <?php } else { include ap_get_theme_location('content-none.php'); } ?> </div>
<?php /** * Best answer content * * @author Rahul Aryan <*****@*****.**> * @link http://anspress.io/anspress * @since 0.1 * * @package AnsPress */ /** * Show best answer */ if (ap_have_answers()) { echo '<div id="ap-best-answer">'; echo '<h3 class="ap-answers-label"><span>' . __('Best answer', 'anspress-question-answer') . '</span></h3>'; while (ap_have_answers()) { ap_the_answer(); include ap_get_theme_location('answer.php'); } echo '</div>'; }
/** * Include template php files * @param string $file File name without extension * @since 2.1 */ function ap_get_template_part($file) { include ap_get_theme_location($file . '.php'); }
<?php /** * Answer content * * @author Rahul Aryan <*****@*****.**> * @link http://anspress.io/anspress * @since 0.1 * * @package AnsPress */ if (!ap_answer_user_can_view()) { include ap_get_theme_location('no-permission-post.php'); return; } ?> <div id="answer_<?php the_ID(); ?> " <?php post_class(); ?> data-id="<?php the_ID(); ?> " data-index="<?php echo @$i; ?> " itemprop="suggestedAnswer<?php echo ap_answer_is_best() ? ' acceptedAnswer' : ''; ?>
<div id="ap-user-favorites"> <?php if ($question->have_posts()) { ?> <div class="question-list"> <?php /* Start the Loop */ while ($question->have_posts()) { $question->the_post(); include ap_get_theme_location('content-list.php'); } ?> </div> <?php ap_pagination('', 2, $paged, $question); ?> <?php } else { _e('No favourite questions', 'ap'); } ?> </div>
/** * Return comment form. * * @since 2.0.1 */ public function load_comment_form() { $result = array('ap_responce' => true, 'action' => 'load_comment_form'); $comment_id = (int) @$_POST['comment_ID']; if (ap_verify_nonce('comment_form_nonce') || ap_verify_nonce('edit_comment_' . $comment_id)) { $comment_args = array(); $content = ''; $commentid = ''; if (isset($_REQUEST['comment_ID'])) { $comment = get_comment($comment_id); $comment_post_ID = $comment->comment_post_ID; $nonce = wp_create_nonce('comment_' . $comment->comment_ID); $comment_args['label_submit'] = __('Update comment', 'anspress-question-answer'); $content = $comment->comment_content; $commentid = '<input type="hidden" name="comment_ID" value="' . $comment->comment_ID . '"/>'; } else { $comment_post_ID = (int) $_REQUEST['post']; $nonce = wp_create_nonce('comment_' . (int) $_REQUEST['post']); } ob_start(); include ap_get_theme_location('comment-form.php'); $html = ob_get_clean(); $comment_args = array('id_form' => 'ap-commentform', 'title_reply' => '', 'logged_in_as' => '', 'comment_field' => $html . '<input type="hidden" name="ap_form_action" value="comment_form"/><input type="hidden" name="ap_ajax_action" value="comment_form"/><input type="hidden" name="__nonce" value="' . $nonce . '"/>' . $commentid, 'comment_notes_after' => ''); if (isset($_REQUEST['comment_ID'])) { $comment_args['label_submit'] = __('Update comment', 'anspress-question-answer'); } // $current_user = get_userdata( get_current_user_id() ); global $withcomments; $withcomments = true; $post = new WP_Query(array('p' => $comment_post_ID, 'post_type' => array('question', 'answer'))); $count = get_comment_count($comment_post_ID); ob_start(); if (!ap_opt('show_comments_by_default')) { echo '<div class="ap-comment-block clearfix">'; } echo '<div class="ap-comment-form clearfix">'; echo '<div class="ap-comment-inner">'; comment_form($comment_args, $comment_post_ID); echo '</div>'; echo '</div>'; if (!ap_opt('show_comments_by_default')) { while ($post->have_posts()) { $post->the_post(); comments_template(); } wp_reset_postdata(); } if (!ap_opt('show_comments_by_default')) { echo '</div>'; } $result['html'] = ob_get_clean(); $result['container'] = '#comments-' . $comment_post_ID; // $result['message'] = 'success'; $result['view_default'] = ap_opt('show_comments_by_default'); $result['view'] = array('comments_count_' . $comment_post_ID => '(' . $count['approved'] . ')', 'comment_count_label_' . $comment_post_ID => sprintf(_n('One comment', '%d comments', $count['approved'], 'anspress-question-answer'), $count['approved'])); } else { $result['message'] = 'no_permission'; } $this->send($result); }
public function process_answer_form() { if (!is_user_logged_in()) { return false; } if (isset($_POST['is_answer']) && isset($_POST['submitted']) && isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'post_nonce_' . $_POST['form_question_id'])) { $fields = $this->get_answer_fields_to_process(); $validate = $this->validate_ans_form(); if ($validate['has_error']) { if ($_POST['action'] == 'ap_submit_answer') { $result = array('action' => 'validation_falied', 'message' => __('Answer not submitted, please check the form fields.', 'ap'), 'error' => $validate); return json_encode($result); } return; } if (!isset($fields['question_id']) && !is_int($fields['question_id']) && 'question' !== get_post_type($fields['question_id'])) { return; } $question = get_post($fields['question_id']); if (!ap_user_can_answer($question->ID)) { return; } do_action('process_answer_form'); $logged_in = false; $user_id = get_current_user_id(); $ans_array = array('post_author' => $user_id, 'post_content' => wp_kses($fields['post_content'], ap_form_allowed_tags()), 'post_type' => 'answer', 'post_status' => 'publish', 'post_parent' => $question->ID); $post_id = wp_insert_post($ans_array); if ($post_id) { // set default value for meta update_post_meta($post_id, ANSPRESS_VOTE_META, '0'); // set updated meta for sorting purpose update_post_meta($question->ID, ANSPRESS_UPDATED_META, current_time('mysql')); ap_add_parti($question->ID, $user_id, 'answer'); // get existing answer count $current_ans = ap_count_ans($question->ID); //update answer count update_post_meta($question->ID, ANSPRESS_ANS_META, $current_ans); update_post_meta($post_id, ANSPRESS_BEST_META, 0); // redirect if just logged in if ($logged_in && $_POST['action'] != 'ap_submit_answer') { wp_redirect(get_permalink($question->ID)); exit; } $result = array(); if ($_POST['action'] == 'ap_submit_answer') { if ($current_ans == 1) { global $post; $post = $question; setup_postdata($post); } else { global $post; $post = get_post($post_id); setup_postdata($post); } ob_start(); if ($current_ans == 1) { ap_answers_list($post->ID, 'voted'); } else { include ap_get_theme_location('answer.php'); } $html = ob_get_clean(); $count_label = sprintf(_n('1 Answer', '%d Answers', $current_ans, 'ap'), $current_ans); $result = apply_filters('ap_ajax_answer_submit_result', array('postid' => $post_id, 'action' => 'new_answer', 'div_id' => '#answer_' . get_the_ID(), 'count' => $current_ans, 'count_label' => $count_label, 'can_answer' => ap_user_can_answer($post->ID), 'html' => $html, 'message' => __('Answer submitted successfully!', 'ap'))); if ($logged_in) { $result['redirect_to'] = get_permalink($post->ID); } } do_action('ap_after_inserting_answer', $post_id); ap_do_event('new_answer', $post_id, $user_id, $question->ID, $result); if ($_POST['action'] == 'ap_submit_answer') { return json_encode($result); } } } elseif ($_POST['action'] == 'ap_submit_answer') { $result = array('postid' => $post_id, 'action' => false, 'message' => __('Please try again, answer submission failed!', 'ap')); return json_encode($result); } }
/** * 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'); }