Example #1
0
/**
 * Flag button html.
 *
 * @return string
 *
 * @since 0.9
 */
function ap_flag_btn_html($echo = false)
{
    if (!is_user_logged_in()) {
        return;
    }
    global $post;
    $flagged = ap_is_user_flagged();
    $total_flag = ap_flagged_post_meta($post->ID);
    $nonce = wp_create_nonce('flag_' . $post->ID);
    $title = !$flagged ? __('Flag this post', 'ap') : __('You have flagged this post', 'ap');
    $output = '<a id="flag_' . $post->ID . '" data-action="ajax_btn" data-query="flag_post::' . $nonce . '::' . $post->ID . '" class="flag-btn' . (!$flagged ? ' can-flagged' : '') . '" href="#" title="' . $title . '">' . __('Flag ', 'ap') . '<span class="ap-data-view ap-view-count-' . $total_flag . '" data-view="' . $post->ID . '_flag_count">' . $total_flag . '</span></a>';
    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
}
Example #2
0
    public function flag_meta_box($post)
    {
        ?>
			<i class="apicon-flag"></i>
			<strong><?php 
        echo ap_flagged_post_meta($post->ID);
        ?>
</strong> <?php 
        _e('Flag', 'anspress-question-answer');
        ?>
			<a id="ap-clear-flag" href="#" data-query="ap_clear_flag::<?php 
        echo wp_create_nonce('clear_flag_' . $post->ID) . '::' . $post->ID;
        ?>
" class="ap-ajax-btn flag-clear" data-cb="afterFlagClear"><?php 
        _e('Clear flag', 'anspress-question-answer');
        ?>
</a>
		<?php 
    }
 /**
  * Add clear flag action button in question list.
  * @param array  $actions Actions array.
  * @param object $post    Post object.
  */
 public function add_question_flag_link($actions, $post)
 {
     if (ap_flagged_post_meta($post->ID)) {
         $actions['flag'] = '<a href="#" data-query="ap_clear_flag::' . wp_create_nonce('clear_flag_' . $post->ID) . '::' . $post->ID . '" class="ap-ajax-btn flag-clear" data-cb="afterFlagClear">' . __('Clear flag', 'anspress-question-answer') . '</a>';
     }
     return $actions;
 }