Example #1
0
/**
 * Post actions buttons
 * @return 	string
 * @param  array $disable
 * @return void
 * @since 	2.0
 */
function ap_post_actions_buttons($disable = array())
{
    global $post;
    if (!$post->post_type == 'question' || !$post->post_type == 'answer') {
        return;
    }
    $actions = array();
    /**
     * Select answer button
     * @var string
     */
    if ($post->post_type == 'answer') {
        $actions['select_answer'] = ap_select_answer_btn_html($post->ID);
    }
    /**
     * Comment button
     */
    if (ap_user_can_comment()) {
        $actions['comment'] = ap_comment_btn_html();
    }
    $actions['status'] = ap_post_change_status_btn_html($post->ID);
    /**
     * edit question link
     */
    if (ap_user_can_edit_question($post->ID) && $post->post_type == 'question') {
        $actions['dropdown']['edit_question'] = ap_edit_post_link_html();
    }
    if (ap_user_can_edit_ans($post->ID) && $post->post_type == 'answer') {
        $actions['dropdown']['edit_answer'] = ap_edit_post_link_html();
    }
    if (is_user_logged_in()) {
        $actions['dropdown']['flag'] = ap_flag_btn_html();
    }
    if (is_super_admin() && $post->post_type == 'question') {
        $actions['dropdown']['featured'] = ap_featured_post_btn();
    }
    if (ap_user_can_delete($post->ID) && $post->post_status != 'trash') {
        $actions['dropdown']['delete'] = ap_post_delete_btn_html();
    }
    if (ap_user_can_delete($post->ID)) {
        $actions['dropdown']['permanent_delete'] = ap_post_permanent_delete_btn_html();
    }
    /**
     * FILTER: ap_post_actions_buttons
     * For filtering post actions buttons
     * @var 	string
     * @since 	2.0
     */
    $actions = apply_filters('ap_post_actions_buttons', $actions);
    if (!empty($actions) && count($actions) > 0) {
        echo '<ul id="ap_post_actions_' . $post->ID . '" class="ap-q-actions ap-ul-inline clearfix">';
        foreach ($actions as $k => $action) {
            if (!empty($action) && $k != 'dropdown' && !in_array($k, $disable)) {
                echo '<li class="ap-post-action ap-action-' . $k . '">' . $action . '</li>';
            }
        }
        if (!empty($actions['dropdown'])) {
            echo '<li class="ap-post-action dropdown">';
            echo '<div id="ap_post_action_' . $post->ID . '" class="ap-dropdown">';
            echo '<a class="apicon-ellipsis more-actions ap-tip ap-dropdown-toggle" title="' . __('More action', 'ap') . '" href="#"></a>';
            echo '<ul class="ap-dropdown-menu">';
            foreach ($actions['dropdown'] as $sk => $sub) {
                echo '<li class="ap-post-action ap-action-' . $sk . '">' . $sub . '</li>';
            }
            echo '</ul>';
            echo '</div>';
            echo '</li>';
        }
        echo '</ul>';
    }
}
Example #2
0
" itemprop="suggestedAnswer<?php 
echo ap_is_best_answer(get_the_ID()) ? ' acceptedAnswer' : '';
?>
" itemtype="http://schema.org/Answer" itemscope="">
	<div class="ap-content clearfix">		
		<div class="ap-avatar">
			<a href="<?php 
echo ap_user_link(get_the_author_meta('ID'));
?>
">
				<?php 
echo get_avatar(get_the_author_meta('user_email'), ap_opt('avatar_size_qanswer'));
?>
			</a>
			<?php 
echo ap_select_answer_btn_html(get_the_ID());
?>
		</div>
		<div class="ap-content-inner no-overflow">
			<div class="ap-amainc">
				<div class="ap-user-meta">
					<div class="ap-single-vote">
							<?php 
ap_vote_html();
?>
					</div>
					<div class="ap-meta">
						<?php 
printf(__('<a href="' . ap_user_link(get_the_author_meta('ID')) . '" class="author"><span>%s</span></a> <span class="when">answered about %s ago</span>', 'ap'), ap_user_display_name(false, true), ap_human_time(get_the_time('U')));
?>
							
Example #3
0
 /**
  * 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));
     }
 }
Example #4
0
 public function ap_set_best_answer()
 {
     $args = explode('-', sanitize_text_field($_POST['args']));
     if (wp_verify_nonce($args[1], 'answer-' . $args[0])) {
         $post = get_post($args[0]);
         $user_id = get_current_user_id();
         if (ap_is_answer_selected($post->post_parent)) {
             ap_do_event('unselect_answer', $user_id, $post->post_parent, $post->ID);
             update_post_meta($post->ID, ANSPRESS_BEST_META, 0);
             update_post_meta($post->post_parent, ANSPRESS_SELECTED_META, false);
             $html = ap_select_answer_btn_html($args[0]);
             $result = array('action' => 'unselected', 'message' => __('Uselected the answer', 'ap'), 'html' => $html);
         } else {
             ap_do_event('select_answer', $user_id, $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);
             $html = ap_select_answer_btn_html($args[0]);
             $result = array('action' => 'selected', 'message' => __('Thank you for awarding best answer', 'ap'), 'html' => $html);
         }
     } else {
         $result = array('action' => false, 'message' => __('Please try again', 'ap'));
     }
     die(json_encode($result));
 }