微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WordPress开发教程:修改后台用户角色的名称

在使用wordpress建站的过程中,当我们开放了用户注册功能,想要给不同的注册用户赋予不同的权限的时候,我们需要先了解一下wordpress认的用户角色以及权限。

wordpress内置的角色和权限系统,首先将用户分为各个角色(Role),然后给各个角色分配一定的权限。wordpress通过这个内置的系统来验证特定的用户是否有足够的权限来进行某种动作。

wordpress认的用户角色以及权限如下:

这篇wordpress教程里我们向大家介绍一下如何修改认角色的名称。比如将认的投稿者修改为贡献者,可以使用下面的代码来实现:

Crayon-5c891d18be2dd972696395" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-mixed-highlight" title="Contains Mixed Languages">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHP
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d18be2dd972696395-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d18be2dd972696395-2">2
Crayon-num" data-line="Crayon-5c891d18be2dd972696395-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d18be2dd972696395-4">4
Crayon-num" data-line="Crayon-5c891d18be2dd972696395-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d18be2dd972696395-6">6
Crayon-num" data-line="Crayon-5c891d18be2dd972696395-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d18be2dd972696395-8">8
Crayon-num" data-line="Crayon-5c891d18be2dd972696395-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d18be2dd972696395-10">10
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d18be2dd972696395-1">Crayon-ta">PHP
Crayon-line Crayon-striped-line" id="Crayon-5c891d18be2dd972696395-2">Crayon-h"> Crayon-t">functionCrayon-h"> Crayon-e">wps_change_role_nameCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d18be2dd972696395-3">Crayon-h"> Crayon-m">globalCrayon-h"> Crayon-v">$wp_rolesCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d18be2dd972696395-4">Crayon-h"> Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-o">!Crayon-h"> Crayon-k ">issetCrayon-sy">(Crayon-h"> Crayon-v">$wp_rolesCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">)
Crayon-line" id="Crayon-5c891d18be2dd972696395-5">Crayon-h"> Crayon-v">$wp_rolesCrayon-h"> Crayon-o">=Crayon-h"> Crayon-r">newCrayon-h"> Crayon-e">WP_RolesCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d18be2dd972696395-6">Crayon-h"> Crayon-v">$wp_rolesCrayon-i">rolesCrayon-sy">[Crayon-s">'contributor'Crayon-sy">]Crayon-sy">[Crayon-s">'name'Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'贡献者'Crayon-sy">;
Crayon-line" id="Crayon-5c891d18be2dd972696395-7">Crayon-h"> Crayon-v">$wp_rolesCrayon-i">role_namesCrayon-sy">[Crayon-s">'contributor'Crayon-sy">]Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'贡献者'Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d18be2dd972696395-8">Crayon-h"> Crayon-sy">}
Crayon-line" id="Crayon-5c891d18be2dd972696395-9">Crayon-h"> Crayon-e">add_actionCrayon-sy">(Crayon-s">'init'Crayon-sy">,Crayon-h"> Crayon-s">'wps_change_role_name'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d18be2dd972696395-10">

赶紧使用上面的代码来测试一下吧。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐