A
A
Alexander Vitkalov2014-11-17 12:05:51
PHP
Alexander Vitkalov, 2014-11-17 12:05:51

How can Wordpress MU know if a user is logged in to another subsite?

Greetings.
There is a Wordpress MU with several subsites, for example mywp.ru
The user is authorized on the subsite u1.mywp.ru
Being authorized on u1.mywp.ru he enters mywp.ru or u2.mywp.ru
How do I for mywp.ru or u2 .mywp.ru to know that the user is authorized on u1.mywp.ru ?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Sydorenko, 2014-11-17
@San40

I think if you can do it, then something like this

if (is_user_logged_in()) {
  $blog_u1_ID = ??? // your u1.mywp.ru blog id
  global $current_user;
  get_currentuserinfo();
  if (is_user_member_of_blog( $current_user->ID,  $blog_u1_ID)) {
    echo "Current user is a member of blog u1"
  };
}

I
Igor Vorotnev, 2014-11-20
@HeadOnFire

In general, if you set the cookie domain constant in wp-config.php to empty, then the default authorization will work as it should, as long as the subsites are subdomains of the main domain (without using mapping of other domain names). Having authorized on any of the sites of the network, the user remains authorized on any other site of the network, including the main site. By default, the cookie is set to the domain/subdomain on which the user is authorized, so the authorization fails on another network site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question