如何删除自定义字段菜单?

时间:2016-04-05 07:43:42

标签: wordpress advanced-custom-fields

我使用Advanced Custom Fields插件,但我想删除菜单Custom Fields

enter image description here

代码如下:

add_filter('admin_menu', function() {
    remove_menu_page('edit.php?post_type=acf');
});

但它不起作用。有什么不对劲,或者有人知道解决我问题的方法吗?

5 个答案:

答案 0 :(得分:2)

这是隐藏自定义字段菜单的功能。它允许您指定仍应能够看到菜单的用户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');

答案 1 :(得分:1)

你能在主题functions.php文件中添加这个功能吗?

function remove_menus(){
   remove_menu_page( 'edit.php?post_type=acf' ); //Remove Post Type ACF
}
add_action( 'admin_init', 'remove_menus' );

答案 2 :(得分:0)

Mukesh Panchal,他的答案不再起作用。 他们改名为:

remove_menu_page( 'edit.php?post_type=acf-field-group' )

这可以解决问题。

答案 3 :(得分:0)

有一个简单的方法可以做到这一点。您可以隐藏特定环境的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 );

希望对您有帮助!

答案 4 :(得分:0)

ACF 对此有一个过滤器,您可以使用 WP '__return_false' 函数而无需定义其他函数。

add_filter('acf/settings/show_admin', '__return_false');

参考文献:

ACF Documentation: acf/settings

WP Documentation: __return_false

相关问题