wordpress 从管理面板中删除“配置文件”管理菜单

qmelpv7a  于 2022-12-11  发布在  WordPress
关注(0)|答案(3)|浏览(117)

我正在使用WordPress,我想完全删除“配置文件”菜单选项
有没有人知道我怎么才能做到这一点?
谢谢

aor9mmx1

aor9mmx11#

为了完整起见,下面介绍如何通过编程方式完成此操作...

// Run the function on admin_init
add_action('admin_init', 'remove_profile_menu');

// Removal function
function remove_profile_menu() {
  global $wp_roles;

  // Remove the menu. Syntax is `remove_submenu_page($menu_slug, $submenu_slug)`
  remove_submenu_page('users.php', 'profile.php');

  /* Remove the capability altogether. Syntax is `remove_cap($role, $capability)`
   * 'Read' is the only capability subscriber has by default, and allows access
   * to the Dashboard and Profile page. You can also remove from a specific user
   * like this:
   * $user = new WP_User(null, $username);
   * $user->remove_cap($capability); 
   */
  $wp_roles->remove_cap('subscriber', 'read');
}
webghufk

webghufk2#

我知道这是晚了,但我只是偶然发现这个,并认为我会添加到它。这确实删除了子菜单配置文件菜单项,但没有删除菜单配置文件项。对于像我这样创建了一个完全自定义的配置文件页面的人,我不希望我的用户访问profile.php页面。所以下面的代码将工作:

function remove_profile_menu() {

    remove_submenu_page('users.php', 'profile.php');
    remove_menu_page('profile.php');
}

add_action('admin_menu', 'remove_profile_menu');

如果您只想对某些功能执行此操作....请使用以下代码:

function remove_profile_menu() {

    // Only the Admin can see the profile menu
    if(!current_user_can('update_core')) {

    remove_submenu_page('users.php', 'profile.php');
    remove_menu_page('profile.php');

    }
}

add_action('admin_menu', 'remove_profile_menu');

您可以使用current_user_can()函数来确定您希望哪些人查看菜单项。

yh2wf1be

yh2wf1be3#

Profiless插件可以在用户级别上实现这个功能。如果你想在其他组中实现这个功能,你应该将它与Capability manager插件结合使用。

相关问题