REST : how do you handle the rest_no_route error?

I dug in the codex and found some interesting functions. This is how I finally did it : function api_request($api_url = null, $params=null,$method = ‘GET’){ if (!$api_url){ return new WP_Error(‘no_api_url’,”Missing API URL”); } //Create request $request = WP_REST_Request::from_url( $api_url ); //Method $request->set_method( $method ); //params switch($method){ case ‘GET’: $request->set_query_params($params); break; case ‘POST’: $request->set_body_params($params); break; } … Read more

Make authorization mandatory on custom routes

Late, but maybe helpful for other readers as I added solution specifically to above code of this question. Solution: Permission Callback function WordPress: version 5.7.2 PHP: version 7.4 host: hostmonster.com client: Windows 10 browsers: tested on Chrome, Firefox, even Edge 😜 worked Code (PHP code in function.php of your installed theme): add_action(‘rest_api_init’, function() { /** … Read more

Authenticating with REST API

You don’t need plugins for authentication unless you’re making a cross domain request, and to get the nonce, you just create it as you would any other nonce. As the handbook states: For developers making manual Ajax requests, the nonce will need to be passed with each request. The API uses nonces with the action … Read more

Updating link on page via REST api

The problem is with your POST request, where the content property should be a plain string and not an object. You should also send just the data that you want to change. When updating a Page (i.e. a post of the type page), you should provide a JSON-encoded or URL-encoded string containing one or more … Read more

current_user_can(‘administrator’) returns false when I’m logged in

Normally for checking for administration privileges you have to check the ā€œmanage_optionsā€ capability, such as: current_user_can(‘manage_options’) Alternatively, you want to list the roles with wp_get_current_user()->roles and ensure the ā€œAdministratorā€ role is in that array. The capabilities you are checking for do not exist in a vanilla install of wp.

WP_Query To call data from diffrent tables

How can i join my request and get data from multiple tables You don’t, instead, you break it into multiple steps, and retrieve by individually For example, lets say I want to list the top 5 posts, and display a piece of user meta about their authors, e.g. a score. That can’t be done in … Read more

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