ID;
return apply_filters('ap_post_flag_count', ap_meta_total_count('flag', $postid));
}
/**
* Return flag count of question and answer from meta.
* @param integer $post_id Question/Answer Id.
* @return integer
*/
function ap_flagged_post_meta( $post_id ){
return (int)get_post_meta( $post_id, ANSPRESS_FLAG_META, true );
}
/**
* check if user flagged on post.
*
* @param bool $postid
*
* @return bool
*/
function ap_is_user_flagged($postid = false)
{
if (is_user_logged_in()) {
global $post;
$postid = $postid ? $postid : $post->ID;
$userid = get_current_user_id();
$done = ap_meta_user_done('flag', $userid, $postid);
return $done > 0 ? true : false;
}
return false;
}
/**
* 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', 'anspress-question-answer')) : (__('You have flagged this post', 'anspress-question-answer'));
$output = ''.__('Flag ', 'anspress-question-answer').''.$total_flag.'';
if ($echo) {
echo $output;
} else {
return $output;
}
}
/**
* Insert flag vote for comment.
*
* @param int $user_id
* @param int $action_id
* @param mixed $value
* @param mixed $param
*
* @return integer
*/
function ap_insert_comment_flag($user_id, $action_id, $value = null, $param = null)
{
return ap_add_meta($user_id, 'comment_flag', $action_id, $value, $param);
}
/**
* Output flag button for the comment.
*
* @param bool|int $comment_id
*
* @since 2.4
*
* @return string
*/
function ap_comment_flag_btn($comment_id = false, $label = false)
{
echo ap_get_comment_flag_btn($comment_id, $label);
}
/**
* 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', 'anspress-question-answer');
}
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 = '';
return $output;
}
/**
* Count comment flag votes.
*
*
* @return int
*/
function ap_comment_flag_count($comment_id = false)
{
if (false === $comment_id) {
$comment_id = get_comment_ID();
}
return apply_filters('ap_comment_flag_count', ap_meta_total_count('comment_flag', $comment_id));
}
/**
* Check if user flagged comment.
*
* @param bool|int $comment_id
* @param bool|int $user_id
*
* @since 2.4
*
* @return bool
*/
function ap_is_user_flagged_comment($comment_id = false, $user_id = false)
{
if (!is_user_logged_in()) {
return false;
}
if (false === $comment_id) {
$comment_id = get_comment_ID();
}
if (false === $user_id) {
$user_id = get_current_user_id();
}
$done = ap_meta_user_done('comment_flag', $user_id, $comment_id);
return $done > 0 ? true : false;
}