comments – Easily invalidate form in comment_post hook


$GLOBALS['test'] = 'a';

function comment_post_check($comment_ID, $comment_approved, $commentdata) 
    $GLOBALS['test'] = 'b';        

add_action('comment_post', 'comment_post_check', 10, 3);

But my in my single.php, echo $GLOBALS['test']; always returns a even after comment post.

I guess that this because of a POST redirect and probably need to store in sessions only ?
Is there no easier way to set a new WP_Error and get that shown as an error by the default WordPress like it does in Duplicate comment detected; it looks as though you’ve already said that! ?

I thought I could set some pre-defined WP error variables and it’ll viola show the error UI magically.

anjanesh 1 year 2023-01-20T05:11:37-05:00 0 Answers 0 views 0

Leave an answer