Example #1
0
 function kopa_change_like_status()
 {
     check_ajax_referer('kopa_change_like_status', 'wpnonce');
     if (!empty($_POST['pid'])) {
         $pid = (int) $_POST['pid'];
         $status = $_POST['status'];
         $public_key = 'kopa_' . kopa_get_domain() . '_total_like';
         $single_key = 'kopa_' . kopa_get_domain() . '_like_by_' . kopa_get_client_IP();
         $total = kopa_get_post_meta($pid, $public_key, true, 'Int');
         $is_voted = kopa_get_post_meta($pid, $single_key, true, 'Int');
         $result = array();
         if ('enable' == $status && 0 == $is_voted) {
             $total++;
             update_post_meta($pid, $single_key, 1);
             update_post_meta($pid, $public_key, abs($total));
             $result['status'] = 'disable';
         } else {
             $total--;
             delete_post_meta($pid, $single_key);
             update_post_meta($pid, $public_key, abs($total));
             $result['status'] = 'enable';
         }
         $result['total'] = sprintf(__('%1$s Likes', kopa_get_domain()), $total);
         echo json_encode($result);
     }
     die;
 }
Example #2
0
function kopa_get_view_count($post_id)
{
    $key = 'kopa_' . kopa_get_domain() . '_total_view';
    return kopa_get_post_meta($post_id, $key, true, 'Int');
}
Example #3
0
function kopa_get_like_count($pid)
{
    $key = 'kopa_' . kopa_get_domain() . '_total_like';
    return kopa_get_post_meta($pid, $key, true, 'Int');
}