博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
wordpress 菜单_如何通过删除不必要的菜单选项使WordPress更容易为客户端
阅读量:2506 次
发布时间:2019-05-11

本文共 3940 字,大约阅读时间需要 13 分钟。

wordpress 菜单

WordPress menu

In my previous WordPress posts we discovered how to , , and .

在我以前的WordPress文章中,我们发现了如何 , 以及 。

In this post, we’ll make some fundamental changes to the main administration menu. If you haven’t created an initial plugin, . Welcome back — let’s begin…

在本文中,我们将对主管理菜单进行一些基本更改。 如果您尚未创建初始插件, 。 欢迎回来-让我们开始吧...

The standard WordPress menu can be a little daunting — and third-party plugins often add further items. You can restrict user roles so clients do not see all menu items but, unless you’re using every WordPress feature, they’ll still see options which don’t apply to their site.

标准的WordPress菜单可能有些令人生畏-第三方插件通常会添加更多项目。 您可以限制用户角色,以使客户端不会看到所有菜单项,但是除非您使用每个WordPress功能,否则他们仍然会看到不适用于其网站的选项。

We’ll create a function which removes redundant links and simplifies the experience for your clients. Here’s the full code which you can copy into easy-admin.php:

我们将创建一个函数,该函数将删除冗余链接并简化您的客户的体验。 这是完整的代码,您可以将其复制到easy-admin.php中:

// remove unnecessary menusfunction remove_admin_menus() {	global $menu, $submenu;	// main menus removed for all users	$restrict = explode(',', 'Links,Comments');	// sub-menus removed for all users	$restrictsub = explode(',', 'Categories,Post Tags');	// main menus removed for everyone except administrators	$restrict_user = explode(',', 'Media,Profile,Appearance,Plugins,Users,Tools,Settings');	// sub-menus removed for everyone except administrators	$restrictsub_user = explode(',', 'Updates,My Sites');	// WP localization	$f = create_function('$v,$i', 'return __($v);');	array_walk($restrict, $f);	if (!current_user_can('activate_plugins')) {		array_walk($restrict_user, $f);		$restrict = array_merge($restrict, $restrict_user);		array_walk($restrictsub_user, $f);		$restrictsub = array_merge($restrictsub, $restrictsub_user);	}	// remove menus	end($menu);	while (prev($menu)) {		$k = key($menu);		$v = explode(' ', $menu[$k][0]);		if(in_array(is_null($v[0]) ? '' : $v[0] , $restrict)) unset($menu[$k]);	}	// remove sub-menus	foreach ($submenu as $k => $p) {		foreach($submenu[$k] as $j => $s) {			if (in_array(is_null($s[0]) ? '' : $s[0] , $restrictsub)) unset($submenu[$k][$j]);		}	}}add_action('admin_menu', 'remove_admin_menus');

The lines at the top of this function determine which menu items are removed:

此功能顶部的行确定要删除的菜单项:

  • $restrict (line 5) contains a comma-delimited list of main menu items which will not be shown to any users — including administrators. In the example above, we’re hiding Links and Comments since they’re not used in our site.

    $ restrict (第5行)包含用逗号分隔的主菜单项列表,该列表不会显示给任何用户(包括管理员)。 在上面的示例中,我们隐藏了链接和评论,因为它们未在我们的网站中使用。

  • $restrictsub (line 7) contains a comma-delimited list of sub-menu items which will not be shown to any user. We’ve disabled Categories and Post Tags which normally appear in the main Posts menu.

    $ restrictsub (第7行)包含用逗号分隔的子菜单项列表,该列表不会显示给任何用户。 我们已禁用通常显示在“主帖子”菜单中的“类别”和“帖子标签”。

  • $restrict_user (line 9) contains a comma-delimited list of main menu items which are hidden to everyone except administrators. The example above disables everything other than the Dashboard, Pages and Posts. (Non-administrators would not normally see Appearance and Plugins, but other plugins could change that functionality).

    $ restrict_user (第9行)包含用逗号分隔的主菜单项列表,这些菜单项对管理员外的所有人均隐藏。 上面的示例禁用了“仪表板”,“页面”和“帖子”以外的所有内容。 (非管理员通常不会看到外观和插件,但是其他插件可以更改该功能)。

  • $restrictsub_user (line 11) contains a comma-delimited list of sub-menu items which are hidden to everyone except administrators. We’ve disabled Updates and My Sites which normally appear within the main Dashboard menu.

    $ restrictsub_user (第11行)包含用逗号分隔的子菜单项列表,该子菜单项对管理员外的所有人均隐藏。 我们已禁用通常显示在主仪表板菜单中的“更新”和“我的网站”。

simplified WordPress menu

If you don’t want any items removed for a specific value, set it to an empty array, e.g. $restrict = array();

如果您不希望为特定的值删除任何项目,请将其设置为空数组,例如$restrict = array();

The result is a far simpler administration menu which is free of dangerous options which could confuse your clients.

结果是一个简单得多的管理菜单,其中没有可能使您的客户感到困惑的危险选项。

翻译自:

wordpress 菜单

转载地址:http://sdrgb.baihongyu.com/

你可能感兴趣的文章
WINFORM中加入WPF控件并绑定数据源实现跨线程自动更新
查看>>
C#类对象的事件定义
查看>>
各类程序员学习路线图
查看>>
HDU 5510 Bazinga KMP
查看>>
关于select @@IDENTITY的初识
查看>>
ASP.NET MVC ajax提交 防止CSRF攻击
查看>>
关于CSS伪类选择器
查看>>
适用于带文字 和图片的垂直居中方法
查看>>
Part 2 - Fundamentals(4-10)
查看>>
使用Postmark测试后端存储性能
查看>>
NSTextView 文字链接的定制化
查看>>
第五天站立会议内容
查看>>
CentOs7安装rabbitmq
查看>>
(转))iOS App上架AppStore 会遇到的坑
查看>>
解决vmware与主机无法连通的问题
查看>>
做好产品
查看>>
项目管理经验
查看>>
笔记:Hadoop权威指南 第8章 MapReduce 的特性
查看>>
JMeter响应数据出现乱码的处理-三种解决方式
查看>>
获取设备实际宽度
查看>>