0
votes

I have a website, to say, example.com. Now example.com uses a in-house custom login system. I also have a WordPress blog, blog.example.com

When logging into google, google redirects us to a lot of domains including youtube.com for a sign-in everywhere.

Now I want my users to get logged into the blog.example.com when they sign in to example.com

Provided, all the users of example.com are already registered as subscribers to WordPress (blog.example.com) using REST API when they register with example.com

In simple words, how to build a custom "Login with Google" kind of "Login with example.com" and integrate it into WordPress? Basically used for comments, likes and shares.

1

1 Answers

1
votes

Assuming that you know the user_login or user_email (because you created them via REST API, right?), maybe you can set the auth cookie for blog.example.com right after the user logs in example.com.

With user_login or user_email you can get the $user->ID (using the function get_user_by) from blog.example.com and then try using this function to set the auth cookie:

wp_set_auth_cookie( $user_id, $remember = false, $secure = '', $token = '' );

In fact, I didn't test it, but I can work a little bit on that, eventually, if you still need it.