Is there a hook to keep scripts that are included with widgets, persistent during the admin-ajax.php
process?
I use jQuery show()
to open an element within a widget and the element should remain closed until clicked, and that works as expected. However when the widget is saved and WP is doing ajax at admin-ajax.php, the the function fails and opens without any interaction. If the page is reloaded, the function returns to normal.
The function is running from a file myscript.js
and loaded in admin_enqueue_scripts
action.
$(".handle").click(function(){
$(".element").show("slow");
});
<span class="button handle">View Details</span>
<div class="element">this is detail</div>
I suspect the widget is then at admin-ajax.php and the JS is not detected.
Is there a hook to keep scripts that are included with widgets, persistent during the admin-ajax.php
process?
I use jQuery show()
to open an element within a widget and the element should remain closed until clicked, and that works as expected. However when the widget is saved and WP is doing ajax at admin-ajax.php, the the function fails and opens without any interaction. If the page is reloaded, the function returns to normal.
The function is running from a file myscript.js
and loaded in admin_enqueue_scripts
action.
$(".handle").click(function(){
$(".element").show("slow");
});
<span class="button handle">View Details</span>
<div class="element">this is detail</div>
I suspect the widget is then at admin-ajax.php and the JS is not detected.
Share Improve this question edited Feb 13, 2021 at 5:26 Nadal asked Feb 12, 2021 at 22:44 NadalNadal 896 bronze badges1 Answer
Reset to default 0After deep meditation and a meeting with dally the llama (maybe it was an alpaca, I was quite high), I've defined a solution.
Use the widget-updated
var to reload the JS function on widget save.
$(document).on('widget-updated', function(event, widget) {
doAccordion();
});