$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>publish - Check if comment was successfully submited|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

publish - Check if comment was successfully submited

matteradmin10PV0评论


Is there a way to check that comment was successfully submitted? I want to display some text or hide a comment form for example if comment was succesfully submitted.


Is there a way to check that comment was successfully submitted? I want to display some text or hide a comment form for example if comment was succesfully submitted.

Share Improve this question asked Jul 14, 2016 at 11:58 antonanton 1,0811 gold badge10 silver badges14 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 0

You got this action comment_post which fires just after comment is inserted in database

The following example uses the comment_post hook to run a function immediately after a comment is posted. The function checks whether the comment is approved and, if so, executes the code specified.

function show_message_function( $comment_ID, $comment_approved ) {
if( 1 === $comment_approved ){
    //function logic goes here
}}add_action( 'comment_post', 'show_message_function', 10, 2 );

Note that the add_action line includes the priority and the number of parameters (, 10, 2). If we leave the number of parameters out, we will only be able to access to the first parameter ($comment_ID) in our function. We will not be able to access the second parameter ($comment_approved).

For More reference please check the comment_post hook link.

Wordpress adds hashtag to URL if comment was successfully submitted. The easiest way to hide comment form or display some info is to check if hash exists with Javascript.

hash = window.location.hash;
if(hash){
    $('#commentform').hide();
}

I have tried this in the following way, you can try this ....

put the following code in functions.php

function hide_comment_form_function( $comment_ID, $comment_approved ){  
$commentData = get_comment( $comment_ID );
$postTitle = get_the_title($commentData->comment_post_ID);
$url = get_site_url() ."/" .$postTitle . "/?status=cmt_post";
header("Location: $url");
exit();}add_action( 'comment_post', 'hide_comment_form_function', 10, 2 );

And the following code in header.php

if(isset($_GET['status']) &&  ($_GET['status'] == "cmt_post")){
?>
<style>
#commentform, #reply-title
{
    display: none;
}
</style>
<?php}

This will hide the comment form after submit the comment.

Post a comment

comment list (0)

  1. No comments so far