2012-11-15 2 views
3

functions.php에 로그인하여 사용자를 posts-new.php로 리디렉션하는 기능이 추가되어 작동합니다. 그러나 로그인하는 사용자가 컨트 리뷰 터인 경우에만이 작업이 필요합니다. 참여자 및 관리자 모두가 포스트 new.php로 리디렉션됩니다,이 상태에서functions.php의 Wordpress 기능 및 current_user_can()

/** 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'); 

: 그래서 나는 다음과 같은 추가. 능력이없는 사용자가 리디렉션 될 수 있도록를 테스트하기 위해 나는 기능을 수정 :

if (!current_user_can('ma ... 

내가 기능을 수정하는 경우, 참여자와 관리자 모두의 index.php로 리디렉션됩니다.

기능이 작동하는 것 같지만 관리자에게 'manage_options'기능이 표시되지 않는다는 것을 의미합니다. 동일한 결과를 가진 몇 가지 관리자 전용 기능을 시도했습니다. 이상한가?

필자는 사용자 역할 편집기 플러그인을 사용하고 있지만이 기능을 비활성화하고 동일한 결과로 기능을 테스트했습니다.

저는 Active Directory 통합 및 관리자 메뉴 편집기도 사용하고 있습니다.

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 

또는 :

+0

자세한 내용은 대신 내가 '관리자'를 사용하여 시도 여기 https://codex.wordpress.org/Function_Reference/current_user_can –

답변

10

이 시도

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')){} 
+0

을 찾을 수 있습니다 'manage_options'하지만 같은 결과가 나옵니다. 올바르게 이해하면 current_user_can() 태그는 기능에만 적용되며 사용자 역할에는 적용되지 않습니다. – ItsGeorge

+1

이 인수는 기능 또는 역할 이름이므로 작동해야합니다 (http://codex.wordpress.org/Function_Reference/current_user_can). –

+0

그래서 어떤 방법 으로든 함수가 작동하지 않으며 역할이나 기능이 함수에 의해 올바르게 인식되지 않는 것이 문제입니다. 관리자 특정 역할 또는 '관리자'로 설정하면 관리자로 로그인하면 'if'URL을 사용해야하고 기여자로 로그인하면 'else'url을 사용해야합니다. 어느 쪽이든, 기능을 'current_user_can'또는 '! current_user_can'으로 설정했는지 여부에 관계없이 관리자 로그인과 참여자 로그인은 기능이 다른 경우와 동일하게 작동합니다. – ItsGeorge

관련 문제