• Resolved oturia

    (@oturia)


    I have a hack that closes the WordPress popup comment window after the comment is submitted. However, it also attempts to close the window when a comment is made on a single post page because I am tying into the same filter that is used by both.

    if( stripos($_SERVER['REQUEST_URI'], 'comments_popup') !== FALSE ) {
         add_filter('comment_post_redirect', 'reload_blog_index');
    
    function reload_blog_index(){
    echo  "<script type='text/javascript'>";
    echo "window.close()";
    echo "</script>";
    }
    }

    As you can see above, I’m attempting to tell if the URL that referred the wp-comment-post file is coming from the popup comment window, but that seems to have no effect.

    Any suggestions on a function that checks to see if comments_popup is in the referring URL string and only run this function in that instance?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    REQUEST_URI is the currently requested page, so your conditional will always resolve to TRUE. The referring URL is in HTTP_REFERER, but I don’t think that will help you. There is no good way to tell from the referer URL if it is a single page or not.

    The only scheme I can come up with is to set a transient equal to the value of is_single() from the base page. Then your conditional can check this value to decide if the filter should be added or not. The transient name should be created based on the request URL which will then be the referer URL to prevent collisions with other server traffic in the same time frame. Of course the add filter script would clear the transient once it has retrieved the contained value.

    Thread Starter oturia

    (@oturia)

    Thanks! So when I use the comment popup script, comments_popup appears in the URL, and it doesn’t when you’re using the standard contact form on a single post page. So if I use a comments popup on the homepage, I should be able to target that string in the URL, right?

    Moderator bcworkz

    (@bcworkz)

    Something is not adding up. Where is this code placed? Maybe you need to always add the filter unconditionally, then place the conditional in the filter callback.

    Thread Starter oturia

    (@oturia)

    That’s the route I went. Thanks for your help on this, here is what worked.

    if( stripos($_SERVER['HTTP_REFERER'], 'comments_popup') !== FALSE ) {
         add_filter('comment_post_redirect', 'reload_blog_index');
    }
    function reload_blog_index(){
    echo  "<script type='text/javascript'>";
    echo "window.close()";
    echo "</script>";
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Close Popup Comment Window after Comment’ is closed to new replies.