Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].
I own a plug in that uses a basic POST form. It uses a shortcode and works correctly with WordPress’s standard text editor using either the “text” or “visual” tab. However if I use Siteorigin Pagebuilder the form does not post correctly. It seems to wipe the POST form data, or something similar. I haven’t quite figured it out yet but it manipulates something in the form that prevents it from being submitted properly. Has this been noted anywhere else?
Hi Ojt,
That’s odd. We don’t touch the POST (on the frontend) so we’re not too sure what could be causing this issue. To clarify, what widget are you using to add the shortcode?
Have you tried extracting the data early and then passing the data to the shortcode later on? I know it’s not ideal, but that could be a workaround.
Hi, I’m using a custom plug-in. I double-checked my code and everything is fine, it works no problem using the normal editor or by pasting it as a php do_shortcode command anywhere else in a page.
From further inspection it seems that the pagebuilder processes the shortcode twice. This is only obvious when you are dealing with POST form data.
For example:
If no POST data detected the shortcode will create a form. Once posted (to the same page), the plugin detects POST data and stores the form data in a db table.
My plugin only allows one entry per user (email is the unique identifier). If that email address has already been used it tells the user and the dat isn’t stored. However in this case, with the form builder activated, it posts the data successfully but ALSO gives the user the response “email already added”. I can only assume that it has processed twice on the same page.
Very strange, and I can’t see any other way the error could be happening.
Any help greatly appreciated. I’ll keep testing, and I’ll perform your suggestion too.
I’ll also try some kind of javascript count to see if it process the shortcode more than once.
Hi, I’ve done some more tests and the results are odd…
I used console.log to see how many times the shortcode ran, and on-screen it “appears” to run just once.
However I also had the code email me when the function called by the shortcode is executed, and I received 3 emails at exactly the same time (to the second anyway, I’m guessing there are a few milliseconds in between). Assuming one of those is the actual on-screen shortcode process this would mean that the code ran two times before it actually printed out to screen.
I performed the same test by placing the shortcode using the standard editor and I correctly received just one email and one console log.
Hi Ojt,
Hm. Can you please add a is_main_query() check prior to running your code to check if that helps?
Yes it returns with 1 all three times.
Hi Ojt,
That’s odd. To confirm, you have no other plugins running on this website, correct?
Would it be possible for you to provide us with a copy of the code of your plugin so we can run some tests?
Good question. I have new results and they are even more confusing.
I disabled all plugins apart from sitebuilder and mine and it works. I started re-enabling the plugins one by one. Eventually I have found the plugins that cause the issue.
Page Builder and SiteOrigin Widgets Bundle + my plugin = No error
Jetpack + Page Builder and SiteOrigin Widgets Bundle + my plugin = No error
Yoast SEO + Page Builder and SiteOrigin Widgets Bundle + my plugin = No error
Jetpack + Yoast SEO + Page Builder and SiteOrigin Widgets Bundle + my plugin = Error
I have emailed my client who is experiencing the same issue on their set up to ask if this pattern is the same with them.
Hi Ojt,
This is going to sound weird but, if you disable both the Twitter Card and (Facebook) Open Graph features does it work without issue? I ask because we had a similar issue with Yoast a while ago it sounds very much related. Although, I’m not too sure why Jetpack needs to be enabled but I know it does something similar with one of its modules so it may be doing the same thing.
I think Jetpack was a red herring, I was either mistaken or my page was cached.
My client also has Yoast and confirmed that with yoast desabled the form works correctly. But he also said that it still worked when he re-enabled Yoast but I suspect that is a caching thing too.
So the problem seems to be just with Yoast. I have the plugin email every time it tries to post the form. With your suggestions here are the results:
Yoast enabled + Facebook Open Graph disabled + Twitter card disabled = form posts successfully (ie. just once)
Yoast enabled + Facebook Open Graph disabled + Twitter card enabled = form posts twice (error)
Yoast enabled + Facebook Open Graph enabled + Twitter card disabled = form posts twice (error)
Yoast enabled + Facebook Open Graph enabled + Twitter card enabled = form posts three times (error)
So both social components seem to execute the shortcode. If the shortcode was just posting data to the screen then this wouldn’t be an issue but if the shortcode is something like mine, which looks for posted data and if found will process that data, then it could cause issues.
Is there anything I can add to my code to prevent it? Or is this a problem for Yoast?
Thanks for your help
Sorry, quick update.
There is a temporary solution for me, which is to enter some data in the twitter and the facebook components of the Yoast plugin on that page.
I’m guessing by default the twitter and facebook social data comes from the main text content of the page from Pagebuilder, but if I add my own description data then this overides it?
Hi Ojt,
Yes, that’ll avoid the issue as get_the_excerpt() won’t need to generate the excerpt manually.
Hi Ojt,
I would personally use is_main_query() to avoid it but for whatever reason that hasn’t worked for you. Hm. To clarify, where are you adding the shortcode? In the main content area or elsewhere on the page?
Your best bet may be to allow for the code to run and set up something to check if it’s already been run or not (and output as intended) – that’s what we did for the SiteOrigin contact form. That may not however be possible.
Regardless of the above, it’s not an issue specific to Yoast (it’s caused by get_the_excerpt()). The following PHP should trigger the same error (regardless of Yoast):
The shortcode is being added directly to the main content area. But the user could also paste the shortcode anywhere else on the page such as within an html widget or via php echo do_shortcode anywhere within a page template. But the issue only happens when used in the main content area with PageBuilder.
I added the is_main_query() check but it didn’t make a difference. But I’m happy with the overide solution for now.
Thanks again