Stop admin-ajax?

The first thing admin-ajax.php does is define DOING_AJAX. Then, it loads wp-load.php. It does some other stuff, and the first thing it comes across that you have control over is wp-config.php. So if you want to stop all ajax, you can add to following to your wp-config.php file. if( defined( ‘DOING_AJAX’ ) && DOING_AJAX ) … Read more

admin-ajax.php vs Custom Page Template for Ajax Requests

First, the obvious drawback to the first method is that it depends on your specific page, template, and permalink structure to all work correctly. Using admin-ajax.php will work correctly in any context, theme or plugin, where proper WordPress best practices are followed. The less obvious drawback to the first method is that it uses more … Read more

Updating custom post meta with ajax

If you load a file directly none of the WordPress functions will work. That is why you should nearly always use the AJAX API. The AJAX API solves this problem. Everything loads in WordPress context. You would wrap your processing PHP is a function: function my_ajax_cb_wpse_108143() { $cote = get_post_meta($_POST[‘id’], ‘cote’, true); if($_POST[‘cote’] == ‘like’) … Read more

How to HTML5 FormData Ajax

The action should be part of the data object: var formdata = new FormData(); formdata.append(‘name’, ‘This is Name’); formdata.append(‘action’, ‘plugin_save’); $.ajax({ url: ‘admin-ajax.php’, type: ‘POST’, data: formdata, contentType:false, processData:false, success: success, error: error });

Are ‘wp_ajax’ and ‘wp_ajax_nopriv’ exclusive to authenticated and non-authenticated users?

Looking at the WordPress source code, I’d say that wp_ajax_nopriv_* fires only if you’re not logged in, and wp_ajax_* fires otherwise. Here’s the relevant bit, in admin-ajax.php, lines 85-115 in version 5.0.3: if ( is_user_logged_in() ) { // If no action is registered, return a Bad Request response. if ( ! has_action( ‘wp_ajax_’ . $_REQUEST[‘action’] … Read more

AJAX nonce with check_ajax_referer()

Difficult to say for sure where the mistake is as you have not mentioned about your add_action(‘wp_ajax_my_function’,’whatever_callback’);which I think you missed out on that. But your question is missing info in this respect. This is how I would get on about this: In your functions.php file or similar: add_action(wp_ajax_handle_login, ‘handle_login_ajax’); add_action(wp_ajax_nopriv_handle_login, ‘handle_login_ajax’); Make sure your … Read more