Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Last active April 10, 2019 16:27
Show Gist options
  • Save Asikur22/cfe7f3b00640c261c204e32e01ba2fc0 to your computer and use it in GitHub Desktop.
Save Asikur22/cfe7f3b00640c261c204e32e01ba2fc0 to your computer and use it in GitHub Desktop.
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment