Wordpress - 从其他管理员隐藏主题选项

时间:2012-08-20 09:20:06

标签: wordpress wordpress-theming

我正在制作一个模板,我目前正在尝试找到一个解决方案或方法来有效地隐藏位于另外管理员用户的APPEARANCE中的主题选项?

我不想剥夺我的共同管理员的“管理员权限”,并将他改为较低的班级但是我正在寻找隐藏这个元素的可能性,以便他无法改变主题选项/设置。

非常感谢一些帮助。

非常感谢, 帕特里克

1 个答案:

答案 0 :(得分:8)

您可以在检查特定用户ID的函数中使用内置的Wordpress函数remove_submenu_page。你可以把它挂钩到admin_head。

<?php

function hide_menu() {
 global $current_user;
 $user_id = get_current_user_id();
 // echo "user:".$user_id;   // Use this to find your user id quickly

    if($user_id != '1') {

        // To remove the whole Appearance admin menu you would use;
        remove_menu_page( 'themes.php' );

        // To remove the theme editor and theme options submenus from
        // the Appearance admin menu, as well as the main 'Themes'
        // submenu you would use 

        remove_submenu_page( 'themes.php', 'themes.php' );
        remove_submenu_page( 'themes.php', 'theme-editor.php' );
        remove_submenu_page( 'themes.php', 'theme_options' );

    }
}

add_action('admin_head', 'hide_menu');
?>

但是,应该注意(根据评论),使用它只隐藏菜单项,它不会完全禁用它,它可以直接从浏览器访问。如果你真的必须让这个人作为管理员而不是具有较低权限的用户,并且你必须确保他们根本无法访问主题选项,那么你应该考虑使用插件创建一个新的用户访问级别自定义功能(我说使用插件,因为我不相信自己编码有任何意义,你只是重新发明轮子)。

相关问题