function rcl_delete_rating_with_post($args) { global $wpdb; $args['rating_value'] = rcl_get_total_rating($args['object_id'], $args['rating_type']); $wpdb->query($wpdb->prepare("DELETE FROM " . RCL_PREF . "rating_values " . "WHERE object_id = '%d' AND rating_type='%s'", $args['object_id'], $args['rating_type'])); $wpdb->query($wpdb->prepare("DELETE FROM " . RCL_PREF . "rating_totals " . "WHERE object_id = '%d' AND rating_type='%s'", $args['object_id'], $args['rating_type'])); $args['rating_value'] = -1 * $args['rating_value']; do_action('rcl_delete_rating_with_post', $args); }
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; }