Can we assume that /wp-json/ will always be /wp-json/ under any circumstances when creating custom REST routes?

Sure they can! Actually the structure you used is assuming that url rewrites are on. Which may be or may be not. To assure the right endpoint, you must use get_rest_url function: https://developer.wordpress.org/reference/functions/get_rest_url/ So in your case, this would be: ‘get_rest_url’ => get_rest_url(null, ‘/block_help/v1/block_identi…’)

WordPress REST API – Modify JSON before importing

Using the rest_pre_dispatch hook is probably the most straightforward way to go, but you need to be careful about putting your new request data back into the WP_REST_Request object properly. You were reassigning the WP_REST_Request object to an array of request data. Those changes are not persisted because the parameter is not passed by reference. … Read more

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.

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

Check Password Strength using WordPress API

WordPress uses the zxcvbn javascript library by Dropbox, to estimate the password strength. We can see the implementation in: /wp-admin/js/password-strength-meter.js /wp-admin/js/user-profile.js with: strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 ); As far as I know there’s no explicit PHP WordPress API for estimating the password strength, but zxcvbn has been ported to a PHP library here, … Read more

Gutenberg Custom Block Getting All Posts

In addition to loading the wp-api script as mentioned here: wp_enqueue_script( ‘wp-api’ ); // or use below when enqueueing as dependency //wp_enqueue_script( ‘my_script’, ‘path/to/my/script’, array( ‘wp-api’ ) ); You should also know that each collection is a function (equivalent to a class in PHP), so you need to use the new keyword to instantiate a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)