Ejemplo n.º 1
0
 /**
  * Ajax callback for processing comment flag button.
  * @since 2.4
  */
 public function flag_comment()
 {
     $comment_id = (int) $_POST['comment_id'];
     if (!ap_verify_nonce('flag_' . $comment_id) || !is_user_logged_in()) {
         $this->something_wrong();
     }
     $userid = get_current_user_id();
     $is_flagged = ap_is_user_flagged_comment($comment_id);
     if ($is_flagged) {
         ap_send_json(ap_ajax_responce(array('message' => 'already_flagged_comment')));
     } else {
         ap_insert_comment_flag($userid, $comment_id);
         $count = ap_comment_flag_count($comment_id);
         update_comment_meta($comment_id, ANSPRESS_FLAG_META, $count);
         $this->send(array('message' => 'flagged_comment', 'action' => 'flagged', 'view' => array($comment_id . '_comment_flag' => $count), 'count' => $count));
     }
     $this->something_wrong();
 }
Ejemplo n.º 2
0
/**
 * Return flag button for the comment.
 *
 * @param bool|int $comment_id
 *
 * @since  2.4
 *
 * @return string
 */
function ap_get_comment_flag_btn($comment_id = false, $label = false)
{
    if (!is_user_logged_in()) {
        return;
    }
    if (false === $label) {
        $label = __('Flag', 'ap');
    }
    if (false === $comment_id) {
        $comment_id = get_comment_ID();
    }
    $flagged = ap_is_user_flagged_comment($comment_id);
    $total_flag = ap_comment_flag_count($comment_id);
    $nonce = wp_create_nonce('flag_' . $comment_id);
    $output = '<a id="flag_' . $comment_id . '" data-query="ap_ajax_action=flag_comment&comment_id=' . $comment_id . '&__nonce=' . $nonce . '"
    	data-action="ap_subscribe" class="flag-btn' . (!$flagged ? ' can-flag' : '') . '" href="#" title="' . __('Report this comment to moderaor', 'ap') . '">
    	' . $label . '<span class="ap-data-view ap-view-count-' . $total_flag . '" data-view="' . $comment_id . '_comment_flag">' . $total_flag . '</span>
    </a>';
    return $output;
}