Beispiel #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;
 }
Beispiel #2
0
function kopa_get_like_permission($pid)
{
    $permission = 'disable';
    $key = 'kopa_' . kopa_get_domain() . '_like_by_' . kopa_get_client_IP();
    $is_voted = kopa_get_post_meta($pid, $key, true, 'Int');
    if (!$is_voted) {
        $permission = 'enable';
    }
    return $permission;
}