Getting 401 from ajax using an application password

You should use cookie based authentication instead of basic auth. Delete the basic auth/application password authentication code. Follow the cookie authentication example that creates a post via the REST API from the REST API handbook: https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/#cookie-authentication Create a valid nonce for use in your AJAX requests in PHP wp_create_nonce( ‘wp_rest’ ) as the docs tell … Read more

How to call wp plugin REST functions without curl?

You can internally route REST API requests using rest_do_request and a WP_REST_Request object. $request = new WP_REST_Request( ‘GET’, ‘/fb_connect’ ); $request->set_param( ‘x’, true ); // You can also use it this way: $request[‘y’] = true; $request[‘z’] = true; $response = rest_do_request( $request );

Update user meta via REST API?

I had to do this yesterday, here’s how I did it. Like you have already done register_meta to appear in the api. register_meta(‘user’, ‘meta_key’, array( “type” => “string”, “show_in_rest” => true, “single” => true, )); Then you will need to make a POST or PUT request to the users endpoint with the meta values in … Read more

rest api endpoint – accept diacritic characters

Looks to me like WordPress doesn’t enable UTF-8 mode when it runs the regex. https://github.com/WordPress/WordPress/blob/5.2.1/wp-includes/rest-api/class-wp-rest-server.php#L837 In PHP, matching multibyte characters requires the u flag. (The code above just adds the case-insensitive flag). So although some strings will still match (like “Département”), they’re not matching as whole Unicode characters. For example the following pattern matches when … Read more

Get a remote post ID via API given URL

The Posts endpoint accepts a slug parameter when querying for posts, so if you can get the slug from the URL, then you can make request to /wp-json/wp/v2/posts?slug=<slug>. So if the URL is http://example.com/hello-world/ and you know the slug is hello-world, then for example in JavaScript, you can do something like: fetch( ‘http://example.com/wp-json/wp/v2/posts?slug=hello-world’ ) .then( … Read more

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