AnsPress_Flag()

Description #

All flag methods.

Source #

File: includes/flag.php

class AnsPress_Flag {
	/**
	 * Ajax callback to process post flag button
	 *
	 * @since 2.0.0
	 */
	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' ) ),
			)
		);
	}

}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment