function rcl_delete_rating($args) { global $wpdb; if (isset($args['ID'])) { $data = rcl_get_rating_by_id($args['ID']); $query = $wpdb->prepare("DELETE FROM " . RCL_PREF . "rating_values WHERE ID = '%d'", $args['ID']); $args = array('object_id' => $data->object_id, 'object_author' => $data->object_author, 'rating_type' => $data->rating_type, 'rating_value' => $data->rating_value); } else { $rating = rcl_get_vote_value($args); if (!isset($rating)) { return false; } $args['rating_value'] = isset($args['rating_value']) ? $args['rating_value'] : $rating; $query = $wpdb->prepare("DELETE FROM " . RCL_PREF . "rating_values WHERE object_id = '%d' AND rating_type='%s' AND user_id='%s'", $args['object_id'], $args['rating_type'], $args['user_id']); } $res = $wpdb->query($query); $args['rating_value'] = -1 * $args['rating_value']; do_action('rcl_delete_rating', $args); return $args['rating_value']; }
function rcl_edit_rating_post() { global $rcl_options, $rcl_rating_types; $args = rcl_decode_data_rating(sanitize_text_field($_POST['rating'])); if ($rcl_options['rating_' . $args['rating_status'] . '_limit_' . $args['rating_type']]) { $timelimit = $rcl_options['rating_' . $args['rating_status'] . '_time_' . $args['rating_type']] ? $rcl_options['rating_' . $args['rating_status'] . '_time_' . $args['rating_type']] : 3600; $votes = rcl_count_votes_time($args, $timelimit); if ($votes >= $rcl_options['rating_' . $args['rating_status'] . '_limit_' . $args['rating_type']]) { $log['error'] = sprintf(__('exceeded the limit of votes for the period - %d seconds', 'wp-recall'), $timelimit); echo json_encode($log); exit; } } $value = rcl_get_vote_value($args); if ($value) { if ($args['rating_status'] == 'cancel') { $rating = rcl_delete_rating($args); } else { $log['result'] = 110; echo json_encode($log); exit; } } else { $args['rating_value'] = rcl_get_rating_value($args['rating_type']); $rating = rcl_insert_rating($args); } $total = rcl_get_total_rating($args['object_id'], $args['rating_type']); $log['result'] = 100; $log['object_id'] = $args['object_id']; $log['rating_type'] = $args['rating_type']; $log['rating'] = $total; echo json_encode($log); exit; }