I'm developing a plugin that is starting to make use of 4.4's WP-API in a few very simple JavaScript functions. The trouble is that none of the Ajax calls execute in the context of a logged-in user, despite being loaded from a logged-in account on the traditional WP Admin dashboard.
I posted details and code excerpts on the WP StackExchange here, and I'm hoping to draw people's attention to it by posting here.
The TL;DR:
The output of my Ajax calls always runs in the context of a logged-out user. Specifically,
get_current_user_id()returns0for all Ajax-initiated calls, despite a PHP-sidevar_dump(get_current_user_id())returning the correct logged-in user ID number on the output of the page itself.Checking
document.cookieseems to confirm the absence of a login cookie on the JS side, but avar_dump($_COOKIE)shows the correct login cookie's presence.To add to the weirdness, Firefox's Network Pane shows the full cookie, along with the login value, being sent to WordPress from the Ajax call.
What gives?
Any help you can offer either in this thread or that one would be much appreciated.
Thanks.