wordpress 菜单_如何通过删除不必要的菜单选项使WordPress更容易为客户端

本文介绍如何通过编写一个函数来修改WordPress的主要管理菜单,删除不适用的菜单项,为客户提供更简洁的体验。这个函数可以隐藏链接、评论等主菜单项,并针对不同用户角色限制特定的子菜单项,如更新和我的站点,从而避免混淆。
摘要由CSDN通过智能技术生成

wordpress 菜单

WordPress menu

In my previous WordPress posts we discovered how to create a plugin, change the administration panel branding, and remove unnecessary dashboard widgets and meta boxes.

在我以前的WordPress文章中,我们发现了如何创建插件更改管理面板品牌以及删除不必要的仪表板小部件和元框

In this post, we’ll make some fundamental changes to the main administration menu. If you haven’t created an initial plugin, please read the first part. 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 menus
function 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.

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

翻译自: https://www.sitepoint.com/wordpress-easy-administration-plugin-3/

wordpress 菜单

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值