2

正如标题所暗示的,我正在寻找一种方法来删除帖子/页面编辑器屏幕中的屏幕选项选项卡。我发现了以下...

function remove_screen_options(){ __return_false;}
add_filter('screen_options_show_screen', 'remove_screen_options');

...但它会删除所有用户的选项卡。我想为管理员保留它。

问候,

约翰

经过大家的共同努力,找到了答案。谢谢你。

get_currentuserinfo() ;
global $user_level;

function remove_screen_options(){ __return_false;}
if( $user_level <= 8 ) add_filter('screen_options_show_screen', 'remove_screen_options');
4

7 回答 7

3

如果您将以下代码片段放入您的functions.php 文件,屏幕选项选项卡将在整个后端消失,除了管理员之外的所有用户。话虽如此,修改子主题的 php 文件是一个好习惯。

函数.php代码:

function remove_screen_options_tab() 
{
    return current_user_can('manage_options' );
}   
add_filter('screen_options_show_screen', 'remove_screen_options_tab');
于 2015-09-11T15:37:29.607 回答
1

您只需要有条件地检查当前用户是否是管理员。如果不是,则删除屏幕选项,如下所示:

if ( !is_admin() ) {
  function remove_screen_options(){ __return_false;}
  add_filter('screen_options_show_screen', 'remove_screen_options');
}

以下是详细说明此功能的官方 Wordpress 文档:http: //codex.wordpress.org/Function_Reference/is_admin

于 2013-05-22T01:00:33.123 回答
1

Using capabilities the way Spencer suggests is usually the best method.

I'm thinking most people find roles & capabilities to be overly confusing. Using the actual user role with 'current_user_can' is more often than not your best bet for this or any other similar 'permission' based situation.

More often than not you will eventually end up adding/removing capabilities for a specific role, so if you ever give someone else the 'manage_options' capability, like perhaps the owner of the business, you all of a sudden gave them back the screen options as well (On a side note 'activate_plugins' is usually safe since it is only for someone that has level 10 access). You can check out all permissons on the User Level Capability Table at the bottom of the page to get a better grasp on it all.

Insert this in functions php:

if( !current_user_can('administrator') ) {
  // hide screen options for everyone but the admin
add_filter('screen_options_show_screen', 'remove_screen_options_tab');
}

if( current_user_can('administrator') ) {
  // code here is shown to the admin
}

Following this format you can do the same thing with other roles. Also you dont have is change administrator to editor, author, contributor and subscriber, or any other roles you create.

于 2014-01-24T11:37:59.553 回答
0

这是所有宁愿远离 php 的设计师的 CSS 方法。它连接到 admin_body_class 并将 user-{role} 添加为 body 类。

函数.php代码:

function hide_using_css_user_role( $classes ) {
global $current_user;
foreach( $current_user->roles as $role )
    $classes .= ' user-' . $role;

return trim( $classes );
 }
add_filter( 'admin_body_class', 'hide_using_css_user_role' );

使用它,您可以在每个用户角色的管理员端隐藏/显示任何内容。在这种情况下,只需使用 :not css 选择器来确保它只对非管理员隐藏。

function add_my_custom_user_css() {
ob_start(); ?>


<style type="text/css">
:not(.user-administrator) #screen-options-link-wrap, 
    :not(.user-administrator) #contextual-help-link-wrap  {
      display:none !important;
    }   
</style>


<?php
echo ob_get_clean();
}
add_action ( 'admin_head', 'add_my_custom_user_css', 999);

这是一种非常老套的做事方式,但有时当您不知道正确的过滤器/操作来隐藏或更改 wordpress 中的内容时,这对于临时快速修复很有用。添加 999 将确保它被加载到 head 标签的末尾。请注意,它只是使用 css 隐藏,所以不要将它用于任何非常重要的事情,因为代码在源文件中仍然可见。

要从源中删除它,请改用 jquery。只需将上面的样式替换为以下内容:

<script type="text/javascript">
jQuery(document).ready(function($)) {
$( ":not(.user-administrator) #screen-options-link-wrap" ).remove();
}
</script>

'admin_body_class' 已经为我们提供了将页面添加到 body 类的好处,因此也针对特定页面,只需检查源代码,在 body 标记中您可以看到当前页面。例如,仪表板使用 .index-php。只需将其附加到 .user-administrator 或您要定位的任何用户,您就可以使用 css 和 javascript 为任何用户自定义管理员。

于 2014-01-24T13:06:23.257 回答
0

尝试这个

if(!current_user_can('manage_options')) add_filter('screen_options_show_screen', 'remove_screen_options');
于 2013-05-22T00:59:30.723 回答
0

您正在寻找功能current_user_can

if( current_user_can( 'manage_options' ) ) {
    // executes when user is an Administrator
}
于 2013-05-22T01:17:46.807 回答
0

使用 Adminimize,一个 WordPress 插件,可让您从 WordPress 后端隐藏“不必要的”项目。

http://wordpress.org/plugins/adminimize/

于 2013-05-22T01:19:33.623 回答