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">

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

相关文章

我们有时候在定制WORDPRESS主题的时候,由于菜单样式的要求我...
很多朋友在做wordpree主题制作的时候会经常遇到一个问题,那...
wordpress后台的模块很多,但并不是每个都经常用到。介绍几段...
从WordPress4.2版本开始,如果我们在MYSQL5.1版本数据中导出...
很多网友会遇到这样一个问题,就是WordPress网站上传图片、附...
对于经常要在文章中出现代码的IT相关博客,安装一个代码高亮...