Ajax with OOP doesn’t work
You need to create a new instance of the class so that your constructor is called and your actions are registered. e.g. you need to add something like $test = new PR_Test; below the definition of PR_Test.
You need to create a new instance of the class so that your constructor is called and your actions are registered. e.g. you need to add something like $test = new PR_Test; below the definition of PR_Test.
When you add a new field for customisation, WordPress handles how the values are saved, retrieved, previewed. Then you don’t have to save the value with a AJAX call. You just have to add the new field that store orders of sections. Then with JavaScript, you modify the value of this field and use field.trigger(“change”) … Read more
I resolved this issue by using the wp-ajax environment. Essentially, I created the callback function for the comment_row_actions filter which created the link pointing to admin-ajax.php in the admin directory with a query string. Then I created the add_action to run in the wp_ajax environment with a redirect back to the referring page. I couldn’t … Read more
Rarst said it worked for him both logged in and logged out, i can also confirm the same, here’s my ugly test code that works, very much just a hacked together version of your code(for testing). function say_coucou(){ check_ajax_referer( ‘hello’, ‘nonce’ ); echo “Hello”; die; } add_action(‘wp_ajax_hello_hello’, ‘say_coucou’); add_action(‘wp_ajax_nopriv_hello_hello’, ‘say_coucou’); add_action(‘admin_print_footer_scripts’,’blabla’,20000); add_action(‘wp_head’,’enj’,20000); add_action(‘wp_footer’,’blabla’,20000); function enj() … Read more
If you’re building something for public consumption (a plugin, a theme, etc) use admin-ajax.php like you should because that is the appropriate and accepted way to do things and gives your end users the power they need to change and modify things if they so choose. Beyond that, the best you MAY be able to … Read more
You can’t add AJAX calls from public templates. They have to get added much earlier The file that passes the call is admin-ajax.php for a reason: Ajax calls must not be hidden outside admin. For e.g. wrapping your call inside ! is_admin() will let it fail. Template files are not meant to hold actual function … Read more
Drag and drop multiple file upload using Ajax WordPress
If you follow the second approach in the linked Q\A, you do not need ajax, but just to pass the array of terms to the script. First of all in your functions.php (or equivalent) enqueue the script and pass the array of trades via wp_localize_script: add_action( ‘wp_enqueue_scripts’, function() { /* you should check if the … Read more
I found it First, I want to note that the approach I mentionned in my question is bad according to almost tutorials talking about AJAX in wordpress. So I decided to change the approach and use the built-in AJAX of WordPress. In other words, the best way for my situation is to use the wp-admin/admin-ajax.php. … Read more
Your code actually works for me and it is changing the theme according to the current width. But I think you should need some tweaking something like below: For your JavaScript: var $ = jQuery; $(document).ready(function() { var windowWidth = $(window).width(); var windowHeight = $(window).height(); $.ajax( { type: “POST”, url: “http://example.com/wp-admin/admin-ajax.php”, // Must use absolute … Read more