Why does AWStats show /wp-json* as Viewed URLs

I’m not entirely sure what will be better explanation, or why this one (the real one) is not enough. In your stats you see URLs of requests and not paths to files. URL has nothing to do with files on server. Yes – if the requests targets physical file, then that file exists, but… There … Read more

REST API GET users

Read the docs: you need to add a Header named X-WP-Nonce to your requests to the API that require authentication, as you can see in the jQuery example. However the catch is getting that nonce in the first place. WordPress inject that token itself in the post editing screens. Type wpApiSettings in the developer console … Read more

How to add WP API and JS featured image attachment

I manage to solved it by adding this code (at the bottom) to the YOUR BLOG THEMES my path : wp-content/themes/twentysixteen/function.php: function ws_register_images_field() { register_rest_field( ‘post’, ‘images’, array( ‘get_callback’ => ‘ws_get_images_urls’, ‘update_callback’ => null, ‘schema’ => null, ) ); } add_action( ‘rest_api_init’, ‘ws_register_images_field’ ); function ws_get_images_urls( $object, $field_name, $request ) { $medium = wp_get_attachment_image_src( get_post_thumbnail_id( … Read more

WP REST API – Limit the taxonomy search to the first letter

You can use the rest_names_query filter to handle the custom starts_with REST API parameter, and use the terms_clauses filter to add a custom SQL clause for searching terms having their name starting with the specified letter (e.g. A or a for /wp/v2/names/?starts_with=A): add_filter( ‘rest_names_query’, function( $args, $request ){ if ( ‘/wp/v2/names’ === $request->get_route() && // … Read more

Passing a borrowed nonce through Postman fails

For remote apps (cURL, Postman, etc.), or when not using the browser, you should use an authentication plugin like Application Passwords instead of sending the cookies. But if you’d rather send the cookies, then copy and send the WordPress logged-in cookie named wordpress_logged_in_<hash>. Example in cURL: curl -H “X-WP-Nonce: <nonce>” -X POST https://example.com/wp-json/wp/v2/posts -d “Data … Read more

WP 5.5 Fatal Error – get_rest_controller() in rest-api.php

Since 5.5 WP_Taxonomy objects now have a new method, get_rest_controller(), to allow for per-taxonomy controller overrides. The problem is that your plugin overwrites the taxonomy saved in the global $wp_taxonomies cache with a version that isn’t a real WP_Taxonomy object, just a stdObject property bag, and so does not have get_rest_controller() to call. This is … Read more