Login a WP user via REST API
-
Hello,
I have two websites:
– site.com (WordPress site)
– subdomain.site.com (another site)I want to login a WP user in site.com (WP) through subdomain.site.com using WP REST API.
So, I do the following in functions.php in site.com (WP):
add_action('rest_api_init', function () { register_rest_route('xxx/v1', '/login', [ 'methods' => WP_REST_Server::READABLE, 'callback' => function (WP_REST_Request $request) { // I try this: wp_set_current_user(1); wp_set_auth_cookie(1); // and this: $user = wp_signon([ 'user_login' => 'xxx', 'user_password' => 'xxx', 'remember' => true, ], false); } ]); });
And in subdomain.site.com, I use CURL to make the request.
Unfortunately, it doen’t work. The code is well executed but user login does not work, cookies are not defined.
Can you help?
Thanks!
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Login a WP user via REST API’ is closed to new replies.