Take a closer look at the function rest_cookie_check_errors()
.
When you get the nonce via /wp-json/nonce/v1/get
, you’re not sending a nonce in the first place. So this function nullifies your authentication, with this code:
if ( null === $nonce ) {
// No nonce at all, so act as if it's an unauthenticated request.
wp_set_current_user( 0 );
return true;
}
That’s why you’re getting a different nonce from your REST call vs getting it from the theme. The REST call is intentionally not recognizing your login credentials (in this case via cookie auth) because you didn’t send a valid nonce in the get request.
Now, the reason your wp_loaded code worked was because you got the nonce and saved it to a global before this rest code nullified your login. The verify fails because the rest code nullifies your login before the verify takes place.
Related Posts:
- Headless WordPress: How to authenticate front end requests?
- Rest API invalid nonce with Backbone Client
- REST API: Backbone and custom endpoint
- Gutenberg custom block plugin with custom image sizes
- Get loading state of wp data selector
- WP REST – video and audio players
- Post to WordPress using REST API from external site
- How to handle malformed response from WP REST API?
- Rest API authentication issue when called from fetch request in bundle.js
- Get HTTP response code on non-2xx apiFetch request
- WP REST API Post Status Using JavaScript
- How to transform a legacy widget into a block
- Authentication with the Rest API when using an External Application
- Get Block Attributes in JSON REST API
- Setting/unsetting terms using the Backbone JavaScript client
- Checks when fetching data from multiple REST API endpoints in Gutenberg
- Search for a keyword across post types in a Gutenberg component
- Using apiFetch for retrieving post data in Gutenberg
- Get terms of a taxonomy using useSelect
- Return ‘X-WP-Total’ from headers in response
- How to render WP Rest-API Endpoints in a React.js Theme with Woocommerce
- Retrieving data about comments and likes
- how to use nimble-API and Display data?
- Check if user can in javascript
- wp-api Backbone JS Client fetch options
- Why does my array sort order changes when I pass it to JS using WP_REST_Response?
- Rest API and how to deal with it in server side
- Access checks with custom REST endpoints and backbone
- [Vue warn]: Error in render: “TypeError: Cannot read property ‘wp:featuredmedia’ of undefined – REST API
- Update block once an API request returns with a value
- Get user in rest API endpoint
- How to improve WP-Rest atrocious response time?
- I would like to retrive JSON value and display it in wordpress page or widget
- Connecting a wordpress site to an AngularJS APP
- WordPress REST API response is empty in browser and script, but not in Postman
- WP REST API – “rest_user_cannot_view” ONLY on specific users
- Get Comment Text via REST API
- Embedded data and the _fields parameter in getEntityRecords
- REST API not returning all tags – is there a way to return all tags even ones that are not part of published posts?
- Script loaders vs wp_enqueue_script
- PHP or JS for header image rotator?
- convertEntities() used before it is defined
- Block pattern conflict with custom block
- Use one javascript variable into another javascript file
- JavaScript: TypeError: xyz is not a function after upgrading WordPress
- How do I find stylesheet & javascript handles? [duplicate]
- JavaScript errors
- JavaScript file successfully registered but does not render correctly
- Don’t understand how to link Javascript files in WordPress
- How could I add load more posts to my theme? [closed]
- Disable PAGESPEED SCRIPT INJECTION to IMAGE in theme files [closed]
- How to Create a Repeatable Meta Box
- How to keep close a sub-menu under homepage? [closed]
- Custom JS doesn’t work after 4.9.9 update [closed]
- How to implement custom URL handler to access JS modal content? [closed]
- Contact form 7 hide and show fields depending up on the condition [closed]
- Loading 2 Different Version of JS files [closed]
- List unused javascript for easy removal
- Embed Kajabi into WP
- Include Facebook Javascript SDK In WordPress
- Mobile menu will only toggle on
- Making the HTML list to a checkbox tree with the plugin jstree [closed]
- How can I stop loading wordpress jquery on header?
- Why the images on mi javascript are not found?
- Live Time on WP showing weirdly [closed]
- Add Javascript/Html into a WordPress
- Javascript button to call custom fields data
- Javascript 2 elements dependent onclick .toggle [closed]
- wp_enqueue has a resource but doesn’t generate a script tag [duplicate]
- Javascript not working on index.php but it is working on single post’s page
- Replacing & in JS code on pages
- Adding react app to an existing wordpress website
- Unable to change the location of a file
- Orbit Slider and Events Manager Plug-in JavaScript
- Securing Contact Form 7 [closed]
- Javascript file not included only on home page
- Broken links help with site
- Get current day using javascript [closed]
- Google AdSense Ad not showing up in WordPress Blog [closed]
- Change color of a specific word generated by script [closed]
- dropdown does not work [closed]
- Google Map JavaScript error after migrating
- Browser is showing Javascript code instead of processing it [closed]
- WordPress Gutenberg: Attribute overwritten by block duplicate
- Anyway to disable the auto excerpt creation?
- Table block variation with header section activated
- Filtering Gutenberg Components, not Blocks
- How to remove js using theme, which was added by plugin in WordPress site?
- WP Rest API feature image breaking react component
- How do I cycle a JS function in WordPress? [closed]
- Where to include JS library in gutenberg blocks
- How to load JavaScript modules with script_loader_tag hook?
- How to delete child block for associated parent block
- Passing object to FormTokenField suggestions
- Registration fields prefilled with URL parameters
- Theme path of WordPress inside javascript file
- Uncaught ReferenceError: tippy is not defined
- Divi Carousel/ Slider – How to slide two sliders with a single button
- Uncaught SyntaxError: missing ) after argument list [duplicate]
- Masonry grid with bootstrap 4