gpt4 book ai didi

Wordpress - 在配置文件页面上删除 "Roles"

转载 作者:行者123 更新时间:2023-12-05 05:28:10 25 4
gpt4 key购买 nike

我是 Wordpress 插件创建方面的新手,仍在尝试了解操作 Hook 或过滤器 Hook 的概念。

我为“版主”创建了一个自定义角色。我对这个角色的要求:
- 负责具有特定角色的用户,例如订户。
- 能够更改用户密码。
- 无法更改其他用户角色。

问题是这样的:为了能够更改其他用户的密码,版主需要能够访问用户个人资料页面。但是,在用户个人资料页面上,版主可以更改其他用户角色。我可以通过更改 wp-admin/user-edit.php 来隐藏它,但我认为最好通过插件来完成。那么,如何使用插件隐藏/修改“角色”选择?

感谢您的帮助。

为了更清楚,我附上了一张图片。 enter image description here

最佳答案

no hooks 删除它。它必须用 CSS 和/或 jQuery 来解决。

这里,CSS和jQuery做的几乎一样,你可以二选一,也可以同时使用。

current_user_can必须根据您的角色/能力设置进行调整。

注意钩子(Hook)admin_head可以有一个后缀,所以它只会在那个特定的 /wp-admin/WP-PAGE.php 地址中运行。

add_action( 'admin_head-user-edit.php', 'so_13598192_remove_roles_dropbox' );

function so_13598192_remove_roles_dropbox()
{
// Admins can edit that, exit without printing scripts
if ( current_user_can( 'administrator' ) )
return;
?>
<style>
label[for=role], #role
{
display:none;
}
</style>
<script>
jQuery(document).ready(function($)
{
$('label[for=role]').parent().parent().remove();
});
</script>
<?php
}

关于Wordpress - 在配置文件页面上删除 "Roles",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13598192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com