• Hello. I want to print a message after submitting a new comment. Any idea how to do that? (I’ve tried using comment_post, but it doesn’t let me print anything.)

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Devtard

    (@devtard)

    Bump.

    Moderator bcworkz

    (@bcworkz)

    Depending on how you want to present the message, this is not as easy as you would think. After a comment is submitted, normally the entire page is simply reloaded. The page in general does not know a comment was submitted. If you’ve enabled comment moderation, the loop that displays comments includes comments queued for moderation authored by the current user. A message about being comment moderation is appended to such comments, but I see no easy way to alter this.

    You could redirect to a completely different page with the ‘comment_post_redirect’ filter. That page could then redirect back to the initial page after acknowledgement.

    If the message must be on the same page, the page would probably need to query for a recent comment by the current user to decide whether to display a message or not.

    Thread Starter Devtard

    (@devtard)

    I know about the redirection thingy, but I am not sure how it would help if I redirected the user to another page and then to the original one.

    I could pass variables in the URL that would indicate that a comment has been submitted, but what if I don’t want to alter the URL (e.g. show no parameters)? How would you solve this with redirection?

    Moderator bcworkz

    (@bcworkz)

    You could redirect to a page (post type) with a custom template that simply displays your message. Then after acknowledgement and/or a certain time, redirect back to the single post and comments page. The template needs to know what that post was in order to go back to it. An URL parameter is an easy way to do this, but there’s other possibilities.

    A javascript solution using either browser history or cookie to get back to the post.

    The HTTP referer field might have the information. (or it may be the comments-post page, which is useless– verify)

    Store a value somewhere. A transient is probably best, though something in usermeta would work.

    I don’t really like the redirect solution, it’s lame IMO to have two full page loads just to display a message. I would look into trying to let the single template try to determine if a very recent comment was submitted and display a message accordingly.

    Thread Starter Devtard

    (@devtard)

    These possibilities haven’t even occured to me. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to print a message after submitting a comment?’ is closed to new replies.