I have a simple text-box popup on my page, and it calls on a php function script which resides in the header.
I am adding code (in text view) to create this very simple popup. It is triggered on the front end via a link click. (I cannot find a plugin that isn’t all about big flashy popups and ads so I found simple html code in W3schools.)
The popup looks like this when you click the link…
see –
https://www.fireflywebs.ca/wp-content/uploads/2024/05/popupView.jpg
(It creates a simple white box with text which hides when you click the box again)
This is an example of the code blow. The bolded popFunction is what gets stripped out. I have several on the page, and the popFunction is stripped from all of them whenever I come back to the page and do an edit anywhere on the page and then re-save. Then function part of the code is stripped, so the popup no longer works of course.
The code example:
<span class=”popup” onclick=”popFunction1()”>1534
(The popFunction calls to the php script ID in the header)
It’s similar to this
https://www.w3schools.com/howto/howto_js_popup.asp
The question is how to prevent the code from being stripped out.
Thanks. I hope you can help.
Hi Glen
Alex at SiteOrigin has prepared the following for you to whitelist your function:
The above function can be added to a child theme functions.php or, for an easier solution, via the Code Snippets plugin (Snippets > Add New).
Thank you so much. I do have a child theme so can add this to the function.php. I don’t know php so need to ask, do I add a separate declaration for each function. ‘popfunction1’ is only one of several on the page.
Or is there a way of writing this filter to include function1 through 10 for example.
G
Hi, thanks for your kind reply and feedback. Alex sent me the following:
I believe the whitelist might not work if you use an uppercase “F”. That’ll be addressed if possible in a future update. Please let us know how you get on. For the above, our test widget has the following in the OnClick field:
popFunction1();
Very helpful, thank you.
I will give this a try and also take out the capital F
G
Tried the function code provided, and it worked. Awesome!!! This saves me big time.
Thank you so much.
G
Hi, thanks for the update. I’m glad to hear you’re making progress and can add your onclick function. All the best with your site.
Kind regards
Andrew
Well I need to reopen this. The code still gets stripped, but not every time. I get away with an edit or two, then suddenly after a save the function part of the code is gone.
Any ideas how to make this more stable?
I have.
add_filter( 'siteorigin_widgets_onclick_allowlist_functions', function(
$allowlist ) {
$allowlist[] = 'popfunction1'; // First function
$allowlist[] = 'popfunction2'; // Second function
$allowlist[] = 'popfunction3'; // Third function
$allowlist[] = 'popfunction4'; // Fourth function
$allowlist[] = 'popfunction5'; // Fifth function
$allowlist[] = 'popfunction6'; // Sixth function
$allowlist[] = 'popfunction7'; // Seventh function
$allowlist[] = 'popfunction8'; // Eighth function
$allowlist[] = 'popfunction9'; // Nineth function
$allowlist[] = 'popfunction10'; // Tenth function return $allowlist;
} );
Hi Glen,
Regardless, based on the provided snippet the return is present in the Tenth Function comment. This will prevent the allowlist from returning correctly. Please add the following PHP to the line after the tenth function:
I recommend adjusting your popup function to accept a parameter with the id of the popup you wish to use rather than allow listing all of those functions (call central function and then conditionally trigger other code based on the id present). This will allow you to allowlist one function and then not have to worry about the PHP side of things again.
Kind regards,
Alex
That line is there. Sorry I likely missed it when I did the copy and paste.
add_filter( 'siteorigin_widgets_onclick_allowlist_functions', function(
$allowlist ) {
$allowlist[] = 'popfunction1'; // First function
$allowlist[] = 'popfunction2'; // Second function
$allowlist[] = 'popfunction3'; // Third function
$allowlist[] = 'popfunction4'; // Fourth function
$allowlist[] = 'popfunction5'; // Fifth function
$allowlist[] = 'popfunction6'; // Sixth function
$allowlist[] = 'popfunction7'; // Seventh function
$allowlist[] = 'popfunction8'; // Eighth function
$allowlist[] = 'popfunction9'; // Nineth function
$allowlist[] = 'popfunction10'; // Tenth function return $allowlist;
} );
I was working on this page this morning, and the codes were not stripped,
so maybe it was just a particular thing I did the other day.
Sorry: I don't follow what you mean by this
" I recommend adjusting your popup function to accept a parameter with the id of the popup you wish to use rather than allow listing all of those functions (call central function and then conditionally trigger other code based on the id present). This will allow you to allowlist one function and then not have to worry about the PHP side of things again. "
Thank you for your prompt reply.
Hi Glen,
Odd stuff. I’m glad to hear it’s working without issue now. It previously might not have worked as expected due to caching.
Kind regards,
Alex
Well I've had the chance to test it out a few more times, and the function part of the code is still most definitely being stripped when edits are applied to the content of the page in question.
It's annoying to say the least.
G
Hi Glen,
I’m sorry to hear that. Unfortunately, I’m not able to replicate this result.
I recommend moving forward with my previous suggestion. I’m suggesting making one function rather than 10. That can be done by using the following:
Add your popup code between the case and the break. To trigger this code, simply add popFunction( 2 ); where you would previously add popFunction2();
For more information on switch statements, please refer to this page.
Kind regards,
Alex
Not clear on what popup code is needed in the code. Do I have the example correct below?
ie
function popFunction( $popup ) {
switch( $popup ) {
case 1:
// <span class="popup" onclick="popfunction1()">
break;
case 2:
// <span class="popup" onclick="popfunction2()">
break;
case 3:
// <span class="popup" onclick="popfunction3()">
break;
I don't see the difference, but I don't know php. I'm still having to list each and every one, correct?
BUT on the actual document then I just need one default? Is that correct?
What would that be exactly?
default:
<span class="popup" onclick="popfunction">
break;
}
}
Or does each still need the number only as (1) instead of 1()
I need the exact code, cause my interpretation is going to get it wrong.
Hi Glen
Thanks for your reply. Unfortunately, we don’t have the resources within our free support scope to assist with an implementation like the one found here https://www.w3schools.com/howto/howto_js_popup.asp.
It would be best to use a plugin like Popup Maker.
Two forward slashes will comment a line out.
We can assist with the Button Widget outputting a function name. The following will work:
With the above in place, you can use the following in the OnClick field of the Button Widget:
popFunction(1);
.You can also use the Custom HTML Widget to circumvent the Button Widget.
A plugin like Popup Maker would be ideal for this task. Popup Builder is another option.
Wishing you all the best with your page; I hope you can make progress. We can help with outputting a function name into the OnClick field; we can also help with ideas or suggestions. For more in-depth customized assistance, please consider our SiteOrigin Premium support scope where we have the budget to dive deeper into code level customizations.