AnsPress_Flag::action_flag()
Description #
Ajax callback to process post flag button
Source #
File: includes/flag.php
public static function action_flag() { $post_id = (int) ap_sanitize_unslash( 'post_id', 'r' ); if ( ! ap_verify_nonce( 'flag_' . $post_id ) || ! is_user_logged_in() ) { ap_ajax_json( 'something_wrong' ); } $userid = get_current_user_id(); $is_flagged = ap_is_user_flagged( $post_id ); // Die if already flagged. if ( $is_flagged ) { ap_ajax_json( array( 'success' => false, 'snackbar' => array( 'message' => __( 'You have already reported this post.', 'anspress-question-answer' ) ), ) ); } ap_add_flag( $post_id ); $count = ap_update_flags_count( $post_id ); ap_ajax_json( array( 'success' => true, 'action' => array( 'count' => $count, 'active' => true, ), 'snackbar' => array( 'message' => __( 'Thank you for reporting this post.', 'anspress-question-answer' ) ), ) ); }
Expand full source code Collapse full source code View on GitHub: includes/flag.php:24
Add your comment