WordPress pluggin not working with multiple instances of shortcode on the page (Social Discount Pres

4 replies
The problem can be seen this page: Pre-Launch 1 | Igniting The Sixth Sense

The issue is with the pluggin called Social Discount Press. The purpose of this pluggin is that it prompts the user to share your webpage via social media, and if they do so a link will then appear giving them access to restricted content.

There are actually 2 problems, but I am not sure if they stem from the same issue or not.

1) The first issue is that I have placed the social share buttons on the page twice using this shortcode:

[social_sharing_discount index="2"]
And the second instance of the share buttons (towards the bottom of the page) do not work properly. The Facebook and Twitter button activate the share box when clicked, but after sharing, the "instant access" button does not appear beneath the share button as it should. And the Google button does nothing at all when clicked. I have found that if I remove the 1st instance of the share buttons (at the top of the page), then the second instance of them starts working, so in other words it only seems to work properly if there is one instance on the page at a time.

2) The second and much much smaller issue, is that when the Google share button is clicked, the access button appears before the person actually shares.

And assistance with this would be greatly appreciated.
#discount #instances #multiple #page #pluggin #pres #shortcode #social #wordpress #working
  • Profile picture of the author MikeOranguu
    Howdy,

    After having a look at your page and getting to grips witht hat plugin. I can 100% confirm it is never going to work in more than one instance. That is for the simple fact the plugin's JS works on ids instead of classess. Since ids have to be unique across a page, you are going to get some interesting errors when you start to have duplicate ids, such as you are now.

    To fix this problem both the plugins php and js would need to be altered to move out from being a single instance plugin to a multi instance plugin. Thus there is no easy fix here, you would either have to try and alter the plugin yourself or hire a developer to help.

    Also just as a note, because of the above problem your site's markup won't validate dude to the duplicate ids.

    The second issue is because when you click the share with google button, the click event is being duplicated and thus it opens up two new windows. This second window causes the main google share window to lose focus and because it's able to errorneously pass the logic test in the script, it shows the access button early.

    So there we go; sorry this isn't a simple fix. If nothing else it's good to know it's flaws with the plugin and not flaws with how you're using it.

    I'm here if you have any other questions,

    Until then.
    {{ DiscussionBoard.errors[8322182].message }}
    • Profile picture of the author jleavitt13
      Wow, thank you so much for the detailed answer MikeOranguu. I greatly appreciate it. I did manage to modify the pluggin to work with the second instance of the shortcode by switching some of the id's to classes as you suggested.

      The only problem I am having is with the Google button which is still showing the instant access button before the user actually shared it. I understand what you are saying about the multiple windows causing it to loose focus, however if I remove the second instance of the code on the page, the issue is still there. Any other suggestions as to what might be causing it?

      I think this is the code for the specific action, copied straight from the pluggin:

      Code:
      <script type="text/javascript">
      			var googleWindow;
      			jQuery(".gshare_link").click(function() {
      				googleWindow = window.open(this.href, '','menubar=no,toolbar=no,height=600,width=600');
      jQuery('.modgsp').addClass('active');
      				googleWindow.onunload =onun; 
      				
      				function onun() {
      					
      					if(googleWindow.location != "about:blank") // This is so that the function 
      										// doesn't do anything when the 
      										 // window is first opened.
      					{
      						jQuery('.modgsp').addClass('active');
      					}
      				}
      				return false;
      			});
      	   </script>
      Thanks so much
      {{ DiscussionBoard.errors[8323678].message }}
      • Profile picture of the author MikeOranguu
        First of all i'm glad that you managed to fix the first issue. Sadly I have dissapointing news regarding the second issue.

        tl:dr - Not possible for us to observer the share event for google and as such uses a mediocre solution to guess if it has been shared. But that has it's downfalls and causes our issue.

        Now the detailed version:

        The reason why the google one is so inaccurate is because the author simply opens up a popup to the google share page in a popup, this doesn't allow us to see the JS events such as when we share.

        On the other hand because the twitter and facebook jssdk are loaded into the page, we know the exact moment when there has been either of those have been shared and thus accurately display the instant access button.

        Due to this the author is just doing a best guess as to when the user is likely to have shared. It this case the author is guessing that when the javascript onunload event fires, that logically the user has shared on google. Now the onunload event can be fired in multiple ways, one is when the user closes the popup, i.e the best guess scenario as to if the user has shared. However the onunload event also fires when the form loses focus, a user naviagtes a way or a link is clicked.

        You can find a complete list of the things that may cause the event to be fired in this msdn doc:

        unload | onunload event (Windows)

        Furthermore the onunload event is only properly supported in IE, FF and Safari, not Chrome and Opera. Which in the end gives it differeing behaviour in different browsers.

        All of this can lead to unpredicatable behaviour, such as what you are noticing.

        A better solution would be for google to have a jssdk for the the google plus share that let's us create a share box on the fly, however it's lacking that functionality as of now.

        Thus all in all what you have is the lesser of two evils, and probably the best that you can hope for in this situation. The only other option would be to set up an interval and constantly check if the popup window is still open and when it isn't, then show the instant access button. However that still relies of the closing of the popup and not the actual sharing, which is what we want.

        Have fun!
        {{ DiscussionBoard.errors[8327314].message }}
        • Profile picture of the author jleavitt13
          You are awesome, thanks so much for the detailed answer.
          {{ DiscussionBoard.errors[8327699].message }}

Trending Topics