如何删除自定义字段菜单?
How to remove the Custom Fields menu?
我使用 Advanced Custom Fields
插件,但我想删除菜单 Custom Fields
。
代码如下:
add_filter('admin_menu', function() {
remove_menu_page('edit.php?post_type=acf');
});
但是没用。有什么问题吗,或者有人知道解决我问题的方法吗?
这是我隐藏自定义字段菜单的功能。它允许您指定仍应能够看到菜单的用户 ID。
// hide ACF menus for all users except those specified
function show_hide_acf_menu( $show ) {
// array of user IDs that are allowed to see ACF menu
$allowedUsers = array(1);
// get the current user's ID
$userID = get_current_user_id();
if (in_array($userID, $allowedUsers)) {
return true;
} else {
return false;
}
}
add_filter('acf/settings/show_admin', 'show_hide_acf_menu');
你能不能在你的主题functions.php文件中添加这个功能
function remove_menus(){
remove_menu_page( 'edit.php?post_type=acf' ); //Remove Post Type ACF
}
add_action( 'admin_init', 'remove_menus' );
这是我用来通过用户名限制菜单的逻辑。
/**
* Hide ACF admin menu from non-approved users.
*/
function wpgood_restrict_acf_menu( $show ) {
// array of user names that are allowed to see ACF menu
$allowedUsers = array(
'YOUR USER NAME HERE',
'ANOTHER APPROVED USER NAME HERE'
);
// get the current user
$current_user = wp_get_current_user();
$current_user_name = $current_user->user_login;
if (in_array($current_user_name, $allowedUsers)) {
return true;
} else {
return false;
}
}
add_filter('acf/settings/show_admin', 'wpgood_restrict_acf_menu');
Mukesh Panchal 他的回答不再有效。
他们改名为:
remove_menu_page( 'edit.php?post_type=acf-field-group' )
这样就可以了。
有一种简单的方法可以做到这一点。您可以隐藏特定环境的 ACF 菜单,在 wp-config.php.
中设置一个 CONST
将此放入您的 function.php:
/*
* Hide acf from the wp=admin area.
*/
function awesome_acf_hide_acf_admin() {
if (SHOW_ACF == 1) return true;
return false;
}
add_filter('acf/settings/show_admin', 'awesome_acf_hide_acf_admin');
并在你的 wp-config.php 中定义这个 CONST:
define( 'SHOW_ACF', true );
因此,如果您想在活动站点中隐藏 acf 菜单,例如,您可以更改此 CONST 的值:
define( 'SHOW_ACF', false );
希望对您有所帮助!
ACF 对此有一个过滤器,您可以使用 WP '__return_false' 函数而不需要定义额外的函数。
add_filter('acf/settings/show_admin', '__return_false');
参考文献:
我使用 Advanced Custom Fields
插件,但我想删除菜单 Custom Fields
。
代码如下:
add_filter('admin_menu', function() {
remove_menu_page('edit.php?post_type=acf');
});
但是没用。有什么问题吗,或者有人知道解决我问题的方法吗?
这是我隐藏自定义字段菜单的功能。它允许您指定仍应能够看到菜单的用户 ID。
// hide ACF menus for all users except those specified
function show_hide_acf_menu( $show ) {
// array of user IDs that are allowed to see ACF menu
$allowedUsers = array(1);
// get the current user's ID
$userID = get_current_user_id();
if (in_array($userID, $allowedUsers)) {
return true;
} else {
return false;
}
}
add_filter('acf/settings/show_admin', 'show_hide_acf_menu');
你能不能在你的主题functions.php文件中添加这个功能
function remove_menus(){
remove_menu_page( 'edit.php?post_type=acf' ); //Remove Post Type ACF
}
add_action( 'admin_init', 'remove_menus' );
这是我用来通过用户名限制菜单的逻辑。
/**
* Hide ACF admin menu from non-approved users.
*/
function wpgood_restrict_acf_menu( $show ) {
// array of user names that are allowed to see ACF menu
$allowedUsers = array(
'YOUR USER NAME HERE',
'ANOTHER APPROVED USER NAME HERE'
);
// get the current user
$current_user = wp_get_current_user();
$current_user_name = $current_user->user_login;
if (in_array($current_user_name, $allowedUsers)) {
return true;
} else {
return false;
}
}
add_filter('acf/settings/show_admin', 'wpgood_restrict_acf_menu');
Mukesh Panchal 他的回答不再有效。 他们改名为:
remove_menu_page( 'edit.php?post_type=acf-field-group' )
这样就可以了。
有一种简单的方法可以做到这一点。您可以隐藏特定环境的 ACF 菜单,在 wp-config.php.
中设置一个 CONST将此放入您的 function.php:
/*
* Hide acf from the wp=admin area.
*/
function awesome_acf_hide_acf_admin() {
if (SHOW_ACF == 1) return true;
return false;
}
add_filter('acf/settings/show_admin', 'awesome_acf_hide_acf_admin');
并在你的 wp-config.php 中定义这个 CONST:
define( 'SHOW_ACF', true );
因此,如果您想在活动站点中隐藏 acf 菜单,例如,您可以更改此 CONST 的值:
define( 'SHOW_ACF', false );
希望对您有所帮助!
ACF 对此有一个过滤器,您可以使用 WP '__return_false' 函数而不需要定义额外的函数。
add_filter('acf/settings/show_admin', '__return_false');
参考文献: