7

ログイン後にユーザーを posts-new.php にリダイレクトする機能を functions.php に追加しました。ただし、ログインしているユーザーが寄稿者である場合にのみ、これを実現したいと考えています。だから私は以下を追加しました:

/** Redirect after login */
    function mysite_login_redirect(){
        if ( current_user_can( 'manage_options' ) ) {
           return 'http://mysite.com/wp-admin/index.php';}
        else {
           return 'http://mysite.com/wp-admin/post-new.php';}
    }
add_action( 'login_redirect', 'mysite_login_redirect');

この状態では、投稿者と管理者の両方が post-new.php にリダイレクトされます。それをテストするために、機能のないユーザーがリダイレクトされるように関数を変更しました。

if ( !current_user_can( 'ma ...

関数を変更すると、貢献者と管理者の両方が index.php にリダイレクトされます。

したがって、機能は機能しているように見えますが、これは、管理者の「manage_options」機能が表示されていないことを意味します。管理者専用の機能をいくつか試しましたが、結果は同じでした。変でしょ?

私は user role-editor-plugin を使用していると言わざるを得ませんが、それを無効にして同じ結果で機能をテストしました。

また、Active Directory Integration と Admin Menu Editor も使用しています。

4

2 に答える 2

21

これを試して:

if( current_user_can( 'administrator' ) ){} // only if administrator
if( current_user_can( 'editor' ) ){} // only if editor
if( current_user_can( 'author' ) ){} // only if author
if( current_user_can( 'contributor' ) ){} // only if contributor
if( current_user_can( 'subscriber' ) ){} // only if subscriber

または:

if( current_user_can( 'level_10' ) ){}
if( current_user_can( 'level_9' ) ){}
if( current_user_can( 'level_8' ) ){}
if( current_user_can( 'level_7' ) ){}
if( current_user_can( 'level_6' ) ){}
if( current_user_can( 'level_5' ) ){}
if( current_user_can( 'level_4' ) ){}
if( current_user_can( 'level_3' ) ){}
if( current_user_can( 'level_2' ) ){}
if( current_user_can( 'level_1' ) ){}
if( current_user_can( 'level_0' ) ){}
于 2012-11-15T19:09:40.547 に答える