Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Meitar on "WP-API not recognizing WordPress login cookie?"

$
0
0

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() returns 0 for all Ajax-initiated calls, despite a PHP-side var_dump(get_current_user_id()) returning the correct logged-in user ID number on the output of the page itself.

Checking document.cookie seems to confirm the absence of a login cookie on the JS side, but a var_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.


Viewing all articles
Browse latest Browse all 8245

Trending Articles