admin-ajax.php responding with 0
the action has to be an HTTP argument, try that : jQuery.ajax({ url: mbp_Ajax.ajaxurl, type:”POST”, data:{ deleteFrame: id action: ‘mbp-deleteFrame’, }, success: function(resp){ console.log(resp); } });
the action has to be an HTTP argument, try that : jQuery.ajax({ url: mbp_Ajax.ajaxurl, type:”POST”, data:{ deleteFrame: id action: ‘mbp-deleteFrame’, }, success: function(resp){ console.log(resp); } });
After some fiddling and sparring with @t-todua I found the issue: With the Fetch API fetch call you must manually set to send cookies with a request. After setting the credentials option properly the cookies were sent and the AJAX endpoint recognized the current user. So the JS becomes: var msg = ”; // I’m … Read more
add_action(‘wp_ajax_get_post_info’, ‘get_post_info’); add_action(‘wp_ajax_nopriv_get_post_info’, ‘get_post_info’); wp_ajax_nopriv_(action) only on front-end and only for non logged users. Use wp_ajax_(action) for logged in users.
You can use get_current_user_id() to get the ID of the current user, and in your case, you can do so to print the user ID in the JavaScript Li.re() call: <script type=”text/javascript”> Li.re( ‘ab12′,'<?php echo get_current_user_id(); ?>’ ); </script> And yes, you can include the user ID as part of a shortcode: (note that I … Read more
✨ Intro to the Gutenberg Data Module ✨ Gutenberg’s core data model shares a lot of the API and ideology of the state-management library Redux, with a number of differences. Reading up on Redux can provide a lot of insight into how Gutenberg’s data management functions. This lecture will be on the final exam. Application … Read more
wp_localize_script takes an array of data (in PHP) spits out a javascript. It’s a way for you to add dynamic data for a specific script to the front end without having to hook into wp_head or wp_footer and echo it out yourself. More over, wp_localize_script outputs your data right above the script you enqueued. Hooking … Read more
WordPress already ships with jQuery. There is no need to include it in your theme. Javascript Let’s say your jquery.tabify.js file is located in /js/jquery.tabify.js in your theme. Include the following code in your functions.php file: function jquery_tabify() { wp_enqueue_script( ‘jquery-tabify’, get_template_directory_uri() . ‘/js/jquery.tabify.js’, array( ‘jquery’ ) ); } add_action( ‘wp_enqueue_scripts’, ‘jquery_tabify’ ); This will … Read more
When you register/enqueue your other scripts, simply pass jQuery as the third parameter and it will be loaded first and only once, from the local WordPress files: wp_register_script( ‘theme-js’, get_template_directory_uri() . ‘/js/theme.js’, array( ‘jquery’) ); If you only need the jQuery, simply use: wp_enqueue_script(‘jquery’); You can find a list here about the javascript libraries that … Read more
Note that if any script in the header at all needs jQuery then it will bump it to header, regardless if it’s changed to be enqueued for footer. So while changing it to be queued for footer makes sense it rarely works out when a lot of script stuff is going on.
I had exactly the same need, because of the ajax checkout validation. Woocommerce has some custom javascript events we can hook to. In reCaptcha specific case we need to hook to checkout_error that is triggered when the ajax call fails. So, I solved with the following code in my own javascript file, besides the PHP … Read more