Options for authenticated feeds

Assuming you only want to switch it from excerpts to full content, then you could filter the rss_use_excerpt option based on whatever settings you prefer. Something like this would work: add_filter(‘option_rss_use_excerpt’,’random_function_name_here’); function random_function_name_here($value) { if ( whatever_check_you_want_here() ) { return false; // false = show full content } else { return true; // true = … 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

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 REST API GET Requests require authentication

I’ve been working on a similar issue today. Here’s what I’ve done: add_filter(‘rest_dispatch_request’, function($dispatch_result, $request, $route, $handler) { if (!is_user_logged_in()) { $dispatch_result = new WP_Error( ‘rest_not_logged_in’, __( ‘You are not currently logged in.’ ), array( ‘status’ => 401 ) ); } return $dispatch_result; }, 10, 4); You may want to use the $handler to determine … Read more