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

前端之家收集整理的这篇文章主要介绍了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">

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

原文链接:https://www.f2er.com/wordpress/238456.html

猜你在找的wordpress相关文章