ajaxt returning object object [closed]
The issue is with this line: wp_localize_script( ‘ajaxHandle’, ‘myAjax’, array( ‘ajaxurl’ => admin_url( ‘admin_ajax.php’ ) ) ); It should be admin-ajax.php instead of admin_ajax.php.
The issue is with this line: wp_localize_script( ‘ajaxHandle’, ‘myAjax’, array( ‘ajaxurl’ => admin_url( ‘admin_ajax.php’ ) ) ); It should be admin-ajax.php instead of admin_ajax.php.
There isn’t much point to distinguishing admin-ajax.php since it’s essentially same file with same logic running for many many purposes. You are passing action data and hooking into respective action. So action is your identifier. If you are reusing same action and need to further differentiate — just pass more data with your GET/POST request … Read more
Maybe you have an image that was smaller or equal to the thumbnail size, if so, then no thumbnail will be created, and this.data[i].sizes.thumbnail will be undefined.
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
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.
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
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
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
You need to also check it’s not an AJAX request inside your hook: if ( ! current_user_can( ‘administrator’ ) && ( ! defined( ‘DOING_AJAX’ ) || ! DOING_AJAX ) ) { wp_redirect( home_url() ); }
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