Rest API code to get ID of current user not working: get_current_user_id() gives 0
Rest API code to get ID of current user not working: get_current_user_id() gives 0
Rest API code to get ID of current user not working: get_current_user_id() gives 0
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
You could check for a log-in cookie in your .htaccess, but that can be spoofed: RewriteCond %{HTTP_COOKIE} ! wordpress_logged_in_.+= [NC] RewriteRule \.pdf$ – [F,L]
The true reason of not using nonces for non logged in users, is that it adds a pointless burden on their usage as they need to refresh the page when the nonce expire, and the only way they will know that they need to do it is when something do not work. There is probably … Read more
Problem solved! I had a filter hooked onto random_password filter to generate passwords with custom rules and get_password_reset_key uses the function wp_generate_password to generate the key, and that is why I was getting the behavior I was getting. Allz I had to do was to remove my filter from it, and bada bing bada boom, … Read more
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
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
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.
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
You can use the wp_create_user function to create users without a defined email To log in without a password you can see this question