/** * Flag a post as inappropriate * @return void * @since 2.0.0-alpha2 */ public function flag_post() { $post_id = (int) $_POST['post_id']; if (!wp_verify_nonce($_POST['__nonce'], 'flag_' . $post_id) && is_user_logged_in()) { ap_send_json(ap_ajax_responce('something_wrong')); return; } $userid = get_current_user_id(); $is_flagged = ap_is_user_flagged($post_id); if ($is_flagged) { ap_send_json(ap_ajax_responce(array('message' => 'already_flagged'))); echo json_encode(array('action' => false, 'message' => __('You already flagged this post', 'ap'))); } else { ap_add_flag($userid, $post_id); $count = ap_post_flag_count($post_id); //update post meta update_post_meta($post_id, ANSPRESS_FLAG_META, $count); ap_send_json(ap_ajax_responce(array('message' => 'flagged', 'action' => 'flagged', 'view' => array($post_id . '_flag_count' => $count), 'count' => $count))); } die; }
/** * Ajax callback to process post flag button * @since 2.0.0 */ public function flag_post() { $post_id = (int) $_POST['args'][0]; if (!ap_verify_nonce('flag_' . $post_id) || !is_user_logged_in()) { $this->something_wrong(); } $userid = get_current_user_id(); $is_flagged = ap_is_user_flagged($post_id); if ($is_flagged) { $this->send(array('message' => 'already_flagged')); } else { ap_add_flag($userid, $post_id); $count = ap_post_flag_count($post_id); // Update post meta. update_post_meta($post_id, ANSPRESS_FLAG_META, $count); $this->send(array('message' => 'flagged', 'action' => 'flagged', 'view' => array($post_id . '_flag_count' => $count), 'count' => $count)); } $this->something_wrong(); }
public function ap_submit_flag_note() { $args = explode('-', sanitize_text_field($_POST['args'])); $note_id = sanitize_text_field($_POST['note_id']); $other_note = sanitize_text_field($_POST['other_note']); if (wp_verify_nonce($args[1], 'flag_submit_' . $args[0])) { global $wpdb; $userid = get_current_user_id(); $is_flagged = ap_is_user_flagged($args[0]); if ($is_flagged) { // if already then return echo json_encode(array('action' => false, 'message' => __('You already flagged this post', 'ap'))); } else { if ($note_id != 'other') { $row = ap_add_flag($userid, $args[0], $note_id); } else { $row = ap_add_flag($userid, $args[0], NULL, $other_note); } $counts = ap_post_flag_count($args[0]); //update post meta update_post_meta($args[0], ANSPRESS_FLAG_META, $counts); echo json_encode(array('row' => $row, 'action' => 'flagged', 'text' => __('Flag', 'ap') . ' (' . $counts . ')', 'title' => __('You have flagged this post', 'ap'), 'message' => __('This post is notified to moderator. Thank you for helping us', 'ap'))); } } else { echo '0' . __('Please try again', 'ap'); } die; }