Isn’t rest_do_request() filtered by pre_get_posts() filter?

Removing the conditionals for the set() calls will solve the problem. I suspect that the REST request is populating those parameters, and as such the set() calls do not occur. Untested: add_action( ‘pre_get_posts’, ‘test_pre_get_post_filter’ ); function test_pre_get_post_filter( $query ) { if ( is_admin() ) { return; } $query->set( ‘post_status’, array( ‘publish’ ) ); $query->set( ‘posts_per_page’, … Read more

How can I get the number of items stored under a cache group

Here is an untested one-liner, counting the cache data array returned from the magic __get method, with a fallback to an empty array if the group key is not set: ‘numberOfEntries’ => count( $wp_object_cache->cache[$group] ?? [] ); Another approach is to consider bindTo to access the private cache array of the $wp_object_cache instance via closure.

Creating Application Password using REST API results in 401 regardless of JWT token

Because what you’re trying to do boils down to the fundamental question: How do I log in to WordPress using only the REST API? The answer: You can’t in stock/vanilla WordPress. /wp-json/wp/v2/users/me/application-passwords/ “message”: “You are not currently logged in.”, and /wp-json/wp/v2/users/1/application-passwords/ “message”: “Sorry, you are not allowed to create application passwords for this user.”, Are … Read more

custom REST endpoints and application passwords

If you want to use application passwords to authenticate requests to your RESTful endpoints, you can modify your permission_callback function to check for the presence and validity of an application password instead of a user’s credentials. To do this, you can use the wp_check_application_passwords function, which was introduced in WordPress 5.6. This function takes an … Read more