2012-03-20 18 views
2

私はWPMUマルチサイトのインストールに取り組んでいますが、問題はありません。Wordpress WPMUマルチサイトネットワーク間のログイン一貫性

プライマリドメインの登録プロセス中にユーザーを作成します。次のようなもので。

$username = 'myname-'.time(); 
$user_id = wpmu_create_user($username,'anypassword','[email protected]'); 

add_user_to_blog(1, 5, 'subscriber'); 

$user = wp_signon(array(
"user_login" => $username, 
"user_password" => 'anypassword', 
"remember" => true 
)); 

私は何をすると、ユーザーを作成し、唯一のプライマリドメインに割り当て、そしてwp_signonでユーザーをログインです。しかし、サブドメイン上のネットワークのサブサイトにアクセスすると、アクセスが非常に制限されます。私はまだログインしていて、トップのダッシュボードメニューはまだ表示されています。

私はis_user_blog()を使用して、ユーザーがこれを見ることができるかどうかを判断し、それらをサブドメインのログインページに誘導できるかどうかを判断しました。しかしこれは、プライマリドメイン上の既存のログインセッションを終了させることを意味します。理想的には、プライマリドメインにログインしてサブドメインにログインすることもできますが、両方とも別々に処理すると理想的です。

誰でもこの問題に直面していますか?

+1

エラーがありますあなたのサンプルコードで。 'add_user_to_blog(1、$ user_id、 'subscriber');'でなければなりません。 – brasofilo

答えて

1

はい、この問題がありました。また、特別なユーザー管理が必要な場合は、新しい自律(単一サイト)WordPressインストールを設定する必要があります。

これは、マルチサイトが動作する方法です。すべてのユーザーは、自動的にネットワーク内のすべてのサイトのsubscribersに含まれます。記事Don't Use WordPress Multisiteから

あなたはしかし、彼らはマルチサイトを使用していない、ネットワークにしていることを認識していない、ユーザーが別のサイト上に存在する必要がある場合は!さて、はい、これを回避する方法はありますが、それは大企業にとっては監査の悪夢であり、セキュリティリスクは開始する前に知っておくべきです。

このプラグインは役立つかもしれませんが、わかりません:Multisite User Management。私はいくつかの小さなハックが役立つかもしれない、ワードプレスStackExchangeに与えたthis recent answerから


(私は私の開発環境で、小さなテストをしましたが、してください、テスト広範囲)

/* 
* Redirect users that are not members of the current blog to the home page, 
* if they try to access the profile page or dashboard 
* (which they could, as they have subscriber privileges) 
* http://not-my-blog.example.com/wp-admin/profile.php 
*/ 
add_action('admin_init', 'wpse_57206_admin_init'); 

function wpse_57206_admin_init() 
{ 
    if(!is_user_member_of_blog()) 
    { 
     wp_redirect(home_url()); 
     exit(); 
    } 
} 


/* 
* Redirect users that are not members of the current blog to the home page, 
* if they try to access the admin 
* http://not-my-blog.example.com/wp-admin/ 
*/ 
add_action('admin_page_access_denied', 'wpse_57206_access_denied'); 

function wpse_57206_access_denied() 
{ 
    wp_redirect(home_url()); 
    exit(); 
} 


/* 
* Redirect users that are not members of the current blog to the home page, 
* if they try to login 
* http://not-my-blog.example.com/wp-login.php 
*/ 
add_filter('login_redirect', 'wpse_57206_login_redirect'); 

function wpse_57206_login_redirect($url) 
{ 
    global $user; 
    if (!is_user_member_of_blog()) 
    { 
     $url = home_url(); 
    } 
    return $url; 
} 


/* 
* Hide the admin bar for users which are not members of the blog 
*/ 
add_filter('show_admin_bar', 'wpse51831_hide_admin_bar'); 

function wpse51831_hide_admin_bar($bool) 
{ 
    if(!is_user_member_of_blog()) 
    { 
     $bool = false; 
    } 
    return $bool; 
} 
関連する問題