Detect if REST API is running

I would use : if ( defined( ‘REST_REQUEST’ ) && REST_REQUEST ) {…} Source: https://github.com/WP-API/WP-API/issues/926#issuecomment-162920686 If you take a look to this source code on you will notice the constant is defined before processing anything, I would check for it instead of calling the mentioned function wp_is_json_request() Why? if headers were not set when you … Read more

Send request to WordPress REST API

Since your specific scenario is a remote application making a request to WordPress you’ll need to explore additional authentication methods available via plugins for the REST API. I won’t make any specific recommendations since I don’t know your use case in detail but I’m sure you will find one that works well.

WP Rest API not working

First you’ve to Check if the WordPress REST API is enabled or not The best way to check is to visit this URL: https://yoursite.com/wp-json. If you see some JSON response, REST API is enabled. If it’s showing some error page or returns to home page, REST API is not enabled. Then we’ve to enable it … Read more

Using WordPress RESTapi to call a php file instead of post or page

Make custom API endpoint and move the logic from your PHP file into there instead For example, the code below will create an endpoint in /wp-json/my/v1/video/<id> add_action( ‘rest_api_init’, function() { register_rest_route( ‘my/v1’, ‘/video/(?P<id>\d+)’, [ ‘methods’ => ‘GET’, ‘callback’ => ‘get_video_data’, ‘permission_callback’ => ‘__return_true’, ] ); } ); function get_video_data( $params ) { $video_id = $params[‘id’]; … Read more

WordPress doesn’t send a notification email when submitting a comment using REST API

Here’s an untested suggestion for the REST API case: add_action( ‘rest_after_insert_comment’, ‘wp_new_comment_notify_moderator’ ); emulating the existing: add_action( ‘comment_post’, ‘wp_new_comment_notify_moderator’ ); Note the different callback inputs between actions and that we use that get_comment() should handle both comment ID or comment object as an input.

Cannot get ‘sanitize_callback’ to work for rest parameters

You’re not getting the TESTING because your playlist argument should actually be in the args array like so: (reindented for brevity) register_rest_route( SoundSystem::$rest_namespace, ‘/playlist/new’, array( ‘methods’ => WP_REST_Server::CREATABLE, ‘callback’ => array( __class__, ‘rest_add_playlist’ ), ‘permission_callback’ => function () { return is_user_logged_in(); }, ‘args’ => array( ‘playlist’ => array( ‘description’ => __( ‘JSPF playlist data’, ‘soundsystem’ … Read more

Get all tags not just first 10 with wp api 2.0

If we look at the WP_REST_Controller::get_collection_params() method, we can see the minimum is 1 and the maximum is 100: ‘per_page’ => array( ‘description’ => __( ‘Maximum number of items to be returned in result set.’ ), ‘type’ => ‘integer’, ‘default’ => 10, ‘minimum’ => 1, ‘maximum’ => 100, ‘sanitize_callback’ => ‘absint’, ‘validate_callback’ => ‘rest_validate_request_arg’, ), … Read more