Hi,
What do you mean by custom code?
I will try to explain …
I have registered the following route, which calls the function “ajax_Interface”:
register_rest_route( 'blabla/v1', '/ajax-interface', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this,'ajax_interface' ),
'permission_callback' => function () {
return current_user_can( 'administrator' );
}
));
The function “ajax_interface” does some work. For example I do a SQL-update …
function ajax_interface() {
$db_update_result = $wpdb->update( ... SQL update ...
if ( $db_update_result > 0) {
error! - Give error status code back to JS
} else {
success!
}
return ( $ajax_callback_array );
}
If the SQL-update is not OK it should give a status code back. I want to react on error with JS:
error: function(data) {
// if error occured
}
As mentioned the function “status_header()” seems not to be working with REST API like above. I used it with admin-ajax before. Are you sure it is working? Have you done it already?
Thank you