Show Custom Message After Posting Comment

/*
 * Show Custom Message After post Comment.
 */

function ar_set_comment_cookies( $comment, $user ) {
	setcookie( 'ta_comment_wait_approval', '1', 0, '/' );
}
add_action( 'set_comment_cookies', 'ar_set_comment_cookies', 10, 2 );

function ar_comment_sent_message() {
	if ( isset( $_COOKIE['ta_comment_wait_approval'] ) && $_COOKIE['ta_comment_wait_approval'] === '1' ) {
		setcookie( 'ta_comment_wait_approval', '0', 0, '/' );

		function ar_show_comment_mesg() {
			echo "<p id='wait_approval'><strong>Your comment has been sent successfully & Waiting for Approval.</strong></p>";
		}
		add_action( 'comment_form_before', 'ar_show_comment_mesg' );
	}
}
add_action( 'init', 'ar_comment_sent_message' );

function ar_comment_post_redirect( $location, $comment ) {
	$location = get_permalink( $comment->comment_post_ID ) . '#wait_approval';

	return $location;
}
add_filter( 'comment_post_redirect', 'ar_comment_post_redirect', 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *