2014-09-03 2 views
0

WordPress에서 Yoast SEO 플러그인을 사용하고 있으며 db 또는 functions.php 파일의 특정 사용자에게만 표시되도록하는 방법이 있는지 알고 싶습니까? 실제 사용자가 아닌 역할.특정 사용자에게만 표시되는 WordPress SEO 플러그인

+0

, 당신처럼, 현재 사용자의 ID를 확인하는 기능을 가진 기능은 일정한를 확인하는 기능을 대체 할 수 그냥 if와 if 그리고 ID. –

답변

1

"플러그인 이름"을 추가하고 사용하지 않도록 설정했지만 범용 솔루션을 시도했지만 실패했습니다.

add_action('plugins_loaded', 'seo_so_25654837'); 

function seo_so_25654837() 
{ 
    if ('2' == get_current_user_id()) 
     return; 

    remove_action('plugins_loaded', 'wpseo_admin_init', 15); 
} 

functions.php에 코드를 추가 normal plugin로 사용하지 마십시오

그러나 만 특정 사용자 ( ID2와 동일), 다음 작품에 WPSEO를 표시합니다.

또한 관리자 표시 줄에서 검색 엔진 최적화 메뉴 제거하는 데 필요한 다음이 코드는 잘 작동

add_action('wp_before_admin_bar_render', 'bar_so_25654837'); 

function bar_so_25654837() 
{ 
    if ('2' == get_current_user_id()) 
     return; 

    global $wp_admin_bar; 
    $nodes = $wp_admin_bar->get_nodes(); 

    foreach($nodes as $node) 
    { 
     if(!$node->parent) 
     { 
      if('wpseo-menu' === $node->id) 
       $wp_admin_bar->remove_menu($node->id); 
     }   
    } 
} 
+0

굉장! 나는 PHP 코드로 플러그인을 만들었고 완벽하게 작동합니다. 당신의 도움을 주셔서 감사합니다. – Brendan

0

테이블에 표시되기 전에 요소를 제거하려면 pre_current_active_plugins에 연결할 수 있습니다. 함수 내에서 get_current_user_id()을 사용하면 선택적으로 플러그인을 숨길 수 있습니다.

function hide_plugins_by_user($all_plugins=false) { 
    global $wp_list_table; 

    // if the current user ID is not 1, hide it. 
    if (1 != get_current_user_id()){ 
     // the active plugins from the table 
     $plugins = $wp_list_table->items; 
     // loop through them 
     foreach ($plugins as $key => $val) { 
      // use the dir + filename of the plugin to hide 
      if ($key == 'plugindir/plugin.php') { 
       unset($wp_list_table->items[$key]); 
      } 
     } 
    } 
} 
add_action('pre_current_active_plugins', 'hide_plugins_by_user'); 
0

(크레딧 Hislop로 이동) :

// Returns true if user has specific role 
function check_user_role($role, $user_id = null) { 
    if (is_numeric($user_id)) 
     $user = get_userdata($user_id); 
    else 
     $user = wp_get_current_user(); 
    if (empty($user)) 
     return false; 
    return in_array($role, (array) $user->roles); 
} 

// Disable WordPress SEO meta box for all roles other than administrator and seo 
function wpse_init(){ 
    if(!(check_user_role('seo') || check_user_role('administrator'))){ 
     // Remove page analysis columns from post lists, also SEO status on post editor 
     add_filter('wpseo_use_page_analysis', '__return_false'); 
     // Remove Yoast meta boxes 
     add_action('add_meta_boxes', 'disable_seo_metabox', 100000); 
    } 
} 
add_action('init', 'wpse_init'); 

function disable_seo_metabox(){ 
    remove_meta_box('wpseo_meta', 'post', 'normal'); 
    remove_meta_box('wpseo_meta', 'page', 'normal'); 
} 

을 단지에 배치 functions.php 파일.

0

모든 사용자의 Yoast를 비활성화하고 몇 가지 또는 특정 용도로만 사용하려면 function.php 파일에 다음 코드를 추가하십시오.

  function remove_wpseo(){ 

       /* if you want to keep it enabled for user with id 2 */ 
       if ('2' == get_current_user_id()) { 
        return; 
       } 

       global $wpseo_front; 
       if(defined($wpseo_front)){ 
        remove_action('wp_head',array($wpseo_front,'head'),1); 
       } 
       else { 
        $wp_thing = WPSEO_Frontend::get_instance(); 
        remove_action('wp_head',array($wp_thing,'head'),1); 
       } 

      } 

      add_action('template_redirect','remove_wpseo'); 

참조 :`get_current_user_id`의 그것 : https://makersbyte.com/disable-yoast-seo-plugin-specific-page/ 내 머리의 상단에서

관련 문제