Fix for Disqus Comment Plugin with SSO popup window

Standard

If you are using WordPress Disqus Comment plugin and enabled SSO (Single Sign-On) with site’s login, you will face a general issue with the popup that will stay open after the login is completed and when you close the popup window, parent window will refresh. To fix this, here is a quick solution till Disqus team implements the fix in the plugin:

1. Open theme’s (or child theme) header.php
2. Add the following JavaScript (preferably at top before anything else gets loaded):

<script type="text/javascript">
// <![CDATA[
if ( window.opener != null && !window.opener.closed ) {
    window.close();
}
// ]]>
</script>

This is the quick fix that I was able to come up with. I’ve also tried to figure out whether Disqus opens the window with any specific window name or not, but, found none. If a window name for the child was found, it would be more specific fix as I could check whether Disqus has opened the window or not. But, unfortunately I had no luck.

If you have any better solution, please share through your comment.

Also, for SSO to work seamlessly with Better WP Security plugin, you need to open the disqus.php file in the plugin folder’s root and change the dsq_sso_login() as follows:

function dsq_sso_login() {
    global $current_site;
    $sitename = get_bloginfo('name');
    $siteurl = site_url();
    $button = get_option('disqus_sso_button');
    $icon = get_option('disqus_sso_icon');
    $sso_login_str = 'this.sso = {
         name: "'.$sitename.'",
         button: "'.$button.'",
         icon: "'.$icon.'",
         url: "'.wp_login_url(get_permalink()).'",
         logout: "'.str_replace('&amp;', '&', wp_logout_url(get_permalink())).'",
         width: "800",
         height: "700"
    }';
    return $sso_login_str;
}

Original function:

function dsq_sso_login() {
    global $current_site;
    $sitename = get_bloginfo('name');
    $siteurl = site_url();
    $button = get_option('disqus_sso_button');
    $icon = get_option('disqus_sso_icon');
    $sso_login_str = 'this.sso = {
          name: "'.$sitename.'",
          button: "'.$button.'",
          icon: "'.$icon.'",
          url: "'.$siteurl.'/wp-login.php",
          logout: "'.$siteurl.'/wp-login.php?action=logout",
          width: "800",
          height: "700"
    }';
    return $sso_login_str;
}

Happy blogging!

Advertisements

18 thoughts on “Fix for Disqus Comment Plugin with SSO popup window

  1. I am using disqus sso for wordpress. I am trying it on my local host. I am able to get the wordpress login window in a new screen. This is the one thing(wordpress’ login window) i want to get rid off but before that, i tried that the window should get closed after the user logs in. I am using wordpress 3.6 version and the gadgetry parent theme.

    I tried coding below javascript in the header.php of the parent theme but it did not work.

    //

    Please let me know if i am doing something wrong here.

  2. @akil I guess your code was not rendered through the comment area. However, could you put the JavaScript shown my post in the child theme’s (if any) header.php instead of the parent theme? Let me kow.

  3. Was looking for a solution to this for hours and after implementing this it suddenly worked like a charm. THANK YOU!!! :D

    Cannot honestly express my gratitude enough.

  4. What’s up to every body, it’s my first visit to this blog; this weblog carries amazing
    and genuinely fine stuff in support of visitors.

  5. @Nicolas – This is a known issue with this intermediate solution. I have contacted the plugin development team for this popup issue. They don’t have any plan to resolve this. If you can see their JavaScript and create a window name while opening the popup, that will help us to check whether the plugin popup is opened or not. If wee found the window name exists, we can close the popup and not for any other call to the site pages.

  6. @Anupam, to be honest I did not understand: I’m french and I’m not a programmer. To be precise, this problem occurs when the link opens in a new tab automatically. If the link is set to be opened in the same window there is no problem. How could I see their JavaScript and create a window name while opening the popup ? Thanks for your answer.

I will be happy to answer your queries

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s