【问题标题】:How to hide user dashboard details in WordPress?如何在 WordPress 中隐藏用户仪表板详细信息?
【发布时间】:2019-06-18 19:46:30
【问题描述】:

我正在尝试向后端用户(不是管理员)隐藏详细信息,例如 Recently Published From our Blog WordPress Events and News Admin Colour Scheme Help Activity Screen Options WordPress 仪表板

我无法找到其中任何一个的 html(php/javascript?),但为配色方案选择器找到了一些 html,如下所示:

<h2>Personal Options</h2>
<table class="form-table">
<tr class="user-admin-color-wrap">
<th scope="row">Admin Color Scheme</th>
<td>
<fieldset id="color-picker" class="scheme-list">
<legend class="screen-reader-text"><span>Admin Color Scheme</span>. 
</legend>
<input type="hidden" id="color-nonce" name="color-nonce" 
value="98ec68455d" /><div class="color-option selected">
<input name="admin_color" id="admin_color_fresh" type="radio" 
value="fresh" class="tog"  checked='checked' />
<input type="hidden" class="css_url" value="" />
<input type="hidden" class="icon_colors" value="{&quot;icons&quot;:  
{&quot;base&quot;:&quot;#a0a5aa&quot;, 
&quot;focus&quot;:&quot;#00a0d2&quot;,&quot;
current&quot;:&quot;#fff&quot;}}" />
<label for="admin_color_fresh">Default</label>
<table class="color-palette">
<tr>
<td style="background-color: #222">&nbsp;</td>
<td style="background-color: #333">&nbsp;</td>
<td style="background-color: #0073aa">&nbsp;</td>
<td style="background-color: #00a0d2">&nbsp;</td>
</tr>
</table>
</div>
<div class="color-option ">
<input name="admin_color" id="admin_color_light" type="radio" 
value="light" class="tog"  />
<input type="hidden" class="css_url" value="https://adsler.co.uk/wp- 
admin/css/colors/light/colors.min.css" />
<input type="hidden" class="icon_colors" value="{&quot;icons&quot;:  
{&quot;base&quot;:&quot;#999&quot;,&quot;focus&quot;
:&quot;#ccc&quot;,&quot;current&quot;:&quot;#ccc&quot;}}" />
<label for="admin_color_light">Light</label>
<table class="color-palette">
<tr>
<td style="background-color: #e5e5e5">&nbsp;</td>

尝试过的css:

 #tab-panel-overview {visibility: hidden;} 

.help-tab-content active {visibility: hidden;} 

.form-table {visibility:hidden; display:none;} 


.user-admin-color-wrap {visibility: hidden; display: none;}

也试过了:

.scheme-list {visibility:hidden;} 

什么都没有。

【问题讨论】:

  • 你能附上你要取出的截图吗?当您谈到仪表板小部件然后说不是管理员时,这个问题有点令人困惑。谢谢。我会做出相应的回应。
  • 嗨。谢谢你的评论。如您所知,WordPress 使用不同的用户角色 subscriber Editor 等。Admin 用户角色专门用于网站的所有者/管理员。这为您提供了所有内容的完整概述,并允许您自定义/批准等其他用户正在做的事情。我不介意这是什么样子,只要它里面有所有东西......
  • 但是,对于其他用户角色,仪表板会有所减少。他们只能看到某些东西,主要是您需要看到的东西,并且只能编辑您自己的帖子/个人资料以及特定类别的帖子,即工作,约会,事件。当用户the role in this case is subscriber(但我想为除管理员之外的所有用户隐藏上述详细信息)登录该站点时,他们的菜单减少了,但在主屏幕上他们看到了上面提到的所有内容我不想要 - colour picker to define admin screen color WordPress Blog` 等。他们不需要它
  • 如果他们唯一的选择是将这些东西也隐藏为管理员角色,我仍然很想看看它是什么......谢谢
  • 如何附上截图?

标签: html css wordpress


【解决方案1】:

请通过插件添加或将代码添加到您的functions.php。 这是经过测试的,并且可以工作。请参阅随附的屏幕截图

function stackinnerflow_remove_dashboard_widgets() {
    global $wp_meta_boxes;

    // Remove At a glance
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    // Remove Activity
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);
    // Remove News and Events
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
}

add_action('wp_dashboard_setup', 'stackinnerflow_remove_dashboard_widgets' );

// removes the `profile.php` admin color scheme options
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );

// Remove thanks WP
add_action('admin_head', 'stackinnerflow_footer_remove');

function stackinnerflow_footer_remove() {
  echo '<style>
              #footer-thankyou,
              #footer-upgrade {
                  display:none;
              } 
        </style>';
}

// remove the Help Tab use

add_action('admin_head', 'stackinnerflow_remove_help_tabs');
function stackinnerflow_remove_help_tabs() {
    $screen = get_current_screen();
    $screen->remove_help_tabs();
}

//remove the Screen Options Tab
add_filter('screen_options_show_screen', '__return_false');

如果您为低于管理员权限级别的用户包装所有代码,则除了管理员之外,任何作为编辑者或更低级别的用户都不会看到这一点。

if (current_user_can('editor')) {}

如果您想循环使用许多其他功能,请查看以下问题:https://wordpress.stackexchange.com/questions/131814/if-the-current-user-is-an-administrator-or-editor

【讨论】:

  • 你能删除 if 条件并检查这是否是你想要的吗?
  • 是的,最后一个 } 在底部
  • 因为你离开了 { if 条件所在的位置。
  • 请告诉我您使用的 WP 版本。
  • 版本通常在右下角,但现在不会显示您应用的代码。如果它的解决方案是有帮助的。如果这是另一个人从答案中受益的解决方案,请不要忘记投票。
【解决方案2】:

您的意思是管理仪表板小部件? 您可以使用以下 wordpress 操作隐藏它们。

function remove_dashboard_widgets() {
    global $wp_meta_boxes;

    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);

}

add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );

【讨论】:

  • 请参见上面的 cmets。这就是你的答案吗?谢谢。
  • 另外,只是想隐藏上面列出的东西,最好只为用户,而不是管理员...
  • 你能添加一些你想隐藏的仪表板页面细节的截图吗?
  • 您可以通过使用 wp_get_current_user 函数获取用户角色来做到这一点。
  • 我该怎么做?-截图?
猜你喜欢
  • 1970-01-01
  • 2020-09-01
  • 2019-11-24
  • 2013-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-25
  • 2023-01-22
相关资源
最近更新 更多