What’s the latest I can hook into wp_ajax_%?

There seems to be a big misunderstanding here about how hooks work, and how AJAX works. The reason that you can’t hook into AJAX in footer.php is because footer.php is not loaded during an AJAX request. No templates are. When you run add_action() you are scheduling a given function to fire when that action is … Read more

I can’t get a return value from Ajax

Returning the result array will only return to the PHP function calling it, instead you actually need to output it by echoing it, and in this case because it is an array, encoding it with JSON before outputting. So return $result becomes: echo json_encode($result); exit; and then add dataType to the javascript call so it … Read more

Get response for check_ajax_referer

It’s totally fine to manually call wp_die() which works fine both with AJAX and non-AJAX requests. Just make sure you return a valid response body; e.g. if your JS expects a JSON response, then return a JSON-encoded string. However, wp_send_json_error() is a wrapper for wp_send_json() which uses wp_die(), so you don’t need to call wp_die() … Read more

400 Bad Request, in wordpress theme development, wp_ajax

The problem is that, you have added extra white space before wp_ajax action. remove space from actions ‘ wp_ajax_my_action’ and ‘ wp_ajax_nopriv_my_action’. because of extra space before ajax request, showing the 400 bad request error. You should use : add_action(‘wp_ajax_my_action’, ‘my_action’); add_action(‘wp_ajax_nopriv_my_action’, ‘my_action’);

Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working

Currently you can not unset key because you can not find proper key from array. The issue is that you did $stamp = array($_POST[‘stamp’]); as array which is wrong. you have to remove array() from $stamp, so which look like $stamp = $_POST[‘stamp’];. then you can search value in column from array and unset it. … Read more

Save value from Javascript object to WP user

First off your setup is quite hard to understand. It seems that the only reason that you are exchanging data from client to server/ JS to PHP is that you have some global info JS object and some gonative_onesignal_info() method. Maybe it’s possible to find some PHP SDK or just retrieve that information either synchronously … Read more

Bad Request in AJAX

The problem is that it’s sending JSON request headers, the old legacy Admin AJAX API doesn’t understand this. As a result these are the cause of the bad request: dataType: “json”, contentType: “application/json” Your endpoint might be able to handle that input, but WP’s admin AJAX handler can’t, so it never knows which action to … Read more

how update data through ajax and jquery

First of all, in your jquery event handler the action parameter’s value should be the string after wp_ajax_ and wp_ajax_nopriv_. So in your example the action should be update_records. So display_func is wrong. Then in line 3 of your php code here the echo keyword should be removed. So your php code should be like … Read more

Render Modula Plugin Shortcode On Ajax Request

I can only comment on this on a general level as I’m not familiar with the plugin you’re using. (This might also not be the best place to ask this kind of plugin related questions as 3rd party plugins are currently considered off-topic here on WPSE.) Majority of this kind of plugins I’ve encountered have … Read more