Displaying PHP Errors from admin-ajax.php

WordPress by default hide errors for ajax request call. This can be confirmed from the source file wp-includes/load.php#L352, here: if ( defined( ‘XMLRPC_REQUEST’ ) || defined( ‘REST_REQUEST’ ) || ( defined( ‘WP_INSTALLING’ ) && WP_INSTALLING ) || wp_doing_ajax() ) { @ini_set( ‘display_errors’, 0 ); } See the function wp_doing_ajax() is being used in the conditional … Read more

WordPress Ajax Data Security

There are a few things you can do to make more secure: First the Ajax call it self should be made with a WordPress nonce like you said: <script type=”text/javascript” > jQuery(document).ready(function($) { var data = { action: ‘ACTION_NAME’, Whatever_data: 1234, _ajax_nonce: <?php echo wp_create_nonce( ‘my_ajax_nonce’ ); ?> }; $.post(ajaxurl, data, function(response) { alert(‘Got this … Read more

Ajax in a settings page (update_option is undefined)

Don’t send AJAX to your PHP file directly. Instead, use WordPress’ built-in AJAX functions 1). You can register an AJAX callback from your plugin, and WordPress will route requests to your plugin file for you. For example, this code will register a callback called “wpa_49691”: add_action( ‘wp_ajax_wpa_49691’, ‘wpa_49691_callback’ ); add_action( ‘wp_ajax_nopriv_wpa_49691’, ‘wpa_49691_callback’ ); function wpa_49691_callback() … Read more

Using Ajax with a Class file

The errors I’ve spotted in your code: One was pointed by @helgatheviking in a comment: the Ajax callback has to be a public method, not private. Not sure how are you initializing this class, but wp_enqueue_script&_style (in singular) has to be encapsulated inside a wp_enqueue_scripts hook (WP_DEBUG dumps a notice). You can drop the & … Read more

failed to load wp-admin/admin-ajax.php

Yes finally the problem was that the hosting provider had blocked the admin-ajax.php file saying that this file was receiving too many request, and requests to this file bypasses cache , hence it was causing problems on server 🙂 So now i’ll have to ‘convince’ them to turn it back on. Thank you all for … Read more

Is there a JavaScript API? How to access public and private data in JS?

TL;DR There is no JavaScript API in the WordPress core and no one is planned, but actually, there is no need of it. Backend First of all let’s say that, regarding the backend, some useful information can be fetched from already present JavaScript global variables (WordPress loves all global flavors). E.g. ajaxurl for the admin-ajax.php … Read more

Making my AJAX powered WordPress Crawlable

Specifically AVOID using “hashbang” (“!#”) in order to make AJAX powered WordPress sites crawlable. You really don’t want to use the “hashbang” method on a WordPress site. The “!#” is more like a hacky patch for sites that cannot provide a static analog to it’s AJAX version. Its use in general is not recommended by … Read more