Unable to parse JSON response from wp_send_json_success [closed]

In short, you should use response.data.messages. And that’s because wp_send_json_success() will send a JSON response (an object) with the property data set to whatever that you passed to the function. wp_send_json_success( 123 ); // In JS, response.data would be an integer. I.e. response.data = 123 wp_send_json_success( array( ‘foo’ => ‘bar’ ) ); // In JS, … Read more

Identical wp_rest nonce returned from rest_api

Despite you already figured it out or found a solution, since this is a follow-up to the other question, I thought it’d be benefecial to post this answer, so hopefully it helps you. =) WordPress uses the native setcookie() function in PHP for setting the authentication cookies, and $_COOKIE for reading the cookies values. But … Read more

how to send Ajax request in wordpress backend

When you enqueue or localize a script you’re doing it specifically for the front end or the admin. If you want to enqueue or localize a script in both, you have to specifically do it for both. This is used to enqueue/localize for the front end add_action( ‘wp_enqueue_scripts’, ‘your_function_front’ ); your_function_front() { wp_localize_script(‘scripts’, ‘myAjax’, array( … Read more

Filter Custom Post Type by Category with Ajax

Nevermind, I’ve managed to solve it. For anyone interested, the problem was ‘category__in’ isn’t support by custom post types so instead needed to edit the $args array to include ‘tax_query’. $args = array( ‘post_type’ => ‘libraries’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘library_types’, ‘terms’ => $category ), ), );

How to test nonce with AJAX – Plugin development

I see some issues: You ajax action can be only used by logged users. If this is correct, I recommend you add a nopriv action that returns a error message. // Inside Constructor add_action( ‘wp_ajax_nopriv_pp_html_process’, array( $this, ‘pp_html_process_not_logged’ ) ); And create this function : public function pp_html_process_not_logged () { // Status can be used … Read more