What exactly does ‘authenticated’ mean for wp_ajax_nopriv?

Authenticated here means according to the is_user_logged_in() function, i.e. if the user is logged in or not, no matter the user role. This part from the admin-ajax.php file, explains it all: if ( is_user_logged_in() ) { /** * Fires authenticated AJAX actions for logged-in users. * * The dynamic portion of the hook name, `$_REQUEST[‘action’]`, … Read more

200 return code on ‘POST /wp-admin/admin-ajax.php’ while NOT logged in

wp-admin/admin-ajax.php is the script used by any plugin or theme using WP Ajax API and Ajax actions can be registered for non-logged in users. For example: //For logged in users add_action( ‘wp_ajax_my_action’, ‘my_action_callback’ ); //For non-logged in users add_action( ‘wp_ajax_nopriv_my_action’, ‘my_action_callback’ ); There is no problem on that. See WP Ajax documentation for more information.

update_option in WordPress AJAX

Your first chunk of code is PHP, the second is javascript. Here is how a full example might look: In PHP (your theme’s functions.php file or a plugin file): //First enqueue your javascript in WordPress function your_prefix_enqueue_scripts(){ //Enqueue your Javascript (this assumes your javascript file is located in your plugin in an “includes/js” directory) wp_enqueue_script( … Read more

PHP session when called wp_ajax_nopriv

WordPress does not use or affect PHP Sessions in any way. Therefore, the session functions will work exactly the same whether you’re using WordPress or plain PHP or AJAX requests or anything else. However, PHP Sessions depend very heavily on your specific PHP configuration. If you don’t have the PHP Session settings configured correctly in … Read more

Run javascript upon successfully set featured image

You could use .ajaxComplete, as mentioned by @onetrickpony in https://wordpress.stackexchange.com/a/36597/57034, except do it globally on document, as mentioned in http://api.jquery.com/ajaxcomplete/, then filter based on action: add_action( ‘admin_print_footer_scripts’, function () { ?> <script type=”text/javascript”> jQuery(function ($) { $(document).ajaxComplete(function (event, xhr, settings) { var match; if (typeof settings.data === ‘string’ && /action=set-post-thumbnail/.test(settings.data) && xhr.responseJSON && typeof xhr.responseJSON.data … Read more

Ajax not working for certain user roles

OK I found the issue. When directly entering myurl/wp-admin/admin-ajax.php?action= mdjm_update_addon_options into my browser window whilst logged in as an Administrator, I was getting the expected response of 0. However, when not logged in, or logged in as a non-admin, I noticed I was receiving “You do not have sufficient permissions to access this page”. Looking … Read more

wp_ajax is not calling the action

if the request is from an unauthenticated user, you should use wp_ajax_nopriv_(action) to call the function, which in your case is: add_action(‘wp_ajax_nopriv_cpm_add_update’, array($this,’edit_added_people’));