/** * Add answer-seleted class in post_class * @param array $classes Post class attribute. * @return array * @since 2.0.1 */ public function question_answer_post_class($classes) { global $post; if ('question' == $post->post_type) { if (ap_question_best_answer_selected($post->ID)) { $classes[] = 'answer-selected'; } if (ap_is_featured_question($post->ID)) { $classes[] = 'featured-question'; } $classes[] = 'answer-count-' . ap_count_answer_meta(); } elseif ('answer' == $post->post_type) { if (ap_answer_is_best($post->ID)) { $classes[] = 'best-answer'; } } return $classes; }
/** * Question meta to display * @param false|integer $question_id * @return string * @since 2.0.1 */ function ap_display_question_metas($question_id = false) { if (false === $question_id) { $question_id = get_the_ID(); } $metas = array(); if (!is_question()) { if (ap_question_best_answer_selected()) { $metas['solved'] = '<span class="ap-best-answer-label ap-tip" title="' . __('answer accepted', 'ap') . '">' . __('Solved', 'ap') . '</span>'; } $view_count = ap_get_qa_views(); $metas['views'] = sprintf(__('<i>%d views</i>', 'ap'), $view_count); $metas['history'] = ap_get_latest_history_html($question_id, true); } /** * FILTER: ap_display_question_meta * Used to filter question display meta */ $metas = apply_filters('ap_display_question_metas', $metas, $question_id); $output = ''; if (!empty($metas) && is_array($metas)) { foreach ($metas as $meta => $display) { $output .= "<span class='ap-display-meta-item {$meta}'>{$display}</span>"; } } return $output; }
/** * Ajax action for selecting a best answer. * * @since 2.0.0 */ public function select_best_answer() { $answer_id = (int) $_POST['answer_id']; if (!is_user_logged_in()) { ap_send_json(ap_ajax_responce('no_permission')); return; } if (!wp_verify_nonce($_POST['__nonce'], 'answer-' . $answer_id)) { $this->something_wrong(); } $post = get_post($answer_id); if (ap_question_best_answer_selected($post->post_parent)) { do_action('ap_unselect_answer', $post->post_author, $post->post_parent, $post->ID); update_post_meta($post->ID, ANSPRESS_BEST_META, 0); update_post_meta($post->post_parent, ANSPRESS_SELECTED_META, false); update_post_meta($post->post_parent, ANSPRESS_UPDATED_META, current_time('mysql')); if (ap_opt('close_after_selecting')) { wp_update_post(array('ID' => $post->post_parent, 'post_status' => 'publish')); } ap_update_user_best_answers_count_meta($post->post_author); ap_update_user_solved_answers_count_meta($post->post_author); $this->send(array('message' => 'unselected_the_answer', 'action' => 'unselected_answer', 'do' => 'reload')); } else { do_action('ap_select_answer', $post->post_author, $post->post_parent, $post->ID); update_post_meta($post->ID, ANSPRESS_BEST_META, 1); update_post_meta($post->post_parent, ANSPRESS_SELECTED_META, $post->ID); update_post_meta($post->post_parent, ANSPRESS_UPDATED_META, current_time('mysql')); if (ap_opt('close_after_selecting')) { wp_update_post(array('ID' => $post->post_parent, 'post_status' => 'closed')); } ap_update_user_best_answers_count_meta($post->post_author); ap_update_user_solved_answers_count_meta($post->post_author); $html = ap_select_answer_btn_html($answer_id); $this->send(array('message' => 'selected_the_answer', 'action' => 'selected_answer', 'do' => 'reload', 'html' => $html)); } }
?> </h3> <?php $questions = ap_get_questions(array('sortby' => 'newest')); if (ap_have_questions()) { ?> <div class="ap-user-posts"> <?php while (ap_questions()) { ap_the_question(); ?> <div class="ap-user-posts-item clearfix"> <a class="ap-user-posts-vcount ap-tip<?php echo ap_question_best_answer_selected() ? ' answer-selected' : ''; ?> " href="<?php ap_question_the_permalink(); ?> " title="<?php _e('Answers'); ?> "><?php echo ap_icon('answer', true); echo ap_question_get_the_answer_count(); ?> </a> <span class="ap-user-posts-active"><?php ap_question_the_active_ago(); ?>
/** * Return question id with solved prefix if answer is accepted. * * @param bool|int $question_id * * @return string * * @since 2.3 [@see ap_page_title] */ function ap_question_title_with_solved_prefix($question_id = false) { if ($question_id === false) { $question_id = get_question_id(); } $solved = ap_question_best_answer_selected($question_id); if (ap_opt('show_solved_prefix')) { return ($solved ? __('[Solved] ', 'ap') : '') . get_the_title($question_id); } return get_the_title($question_id); }