The WordPress user role is useful when two or more people need back-end access to the site. In most cases, there can be at least multiple participants. However, everyone who has access to the site does not have to have the same permissions. This is where WordPress custom user roles work. Here is how to add custom user roles in word press using plug-in based and code based solutions. But first, we will discuss the reasons for the default user roles and permission restrictions provided with WordPress. The
WordPress default user roles WordPress comes with a set of default user roles that you can select when you first install and set up WordPress. These user roles are defined as follows: Administrator – this user has access to all administrative features in the WordPress web site. You can add themes and plug-ins and customize your site (including editing PHP files). Editor – this user role has access to, edit, and publish blog posts from other users. Creator – you can use this user role to create and post your own blog posts. Contributor – at this user role level, blog posts can be created and edited, but not published. Subscribers – this applies only to sites that actually own member or user profiles. At this level, users can access and manage site profiles, but that’s all. If there is a multi site network, there is another user role to understand, that is, the top administrator. Provide access to all management functions on all websites in the network, including the network settings themselves. The
The correct way to use permission levels is often to use such roles to meet the needs of most word press users. But the big mistake many people make is not using them correctly. For example, sometimes you have no reason to assign administrator level permissions to people who contribute to your site. People who create one-time blog posts do not need to access all the back-end files on the site. You also have no reason to edit the site theme, add or remove plug-ins, or change the entire site. In addition, if all users are granted full permissions, the risk of hacker attacks and user errors will increase. It is best to allow users only the level of access required to complete the task. One time participants only need participant level access. The person who creates a recurring post may need to be designated as the creator. However, if the user does not need access to the function to complete the assigned task, there is no reason to provide the function. The
Since the user role needs to be customized, if WordPress already includes this function, what is the customized user role? Unclear, sometimes the default role does not meet the specific requirements of all site owners. For example, suppose your site has regular contributors. Do not edit and publish other people’s posts, so you do not need edit access. However, for testing purposes, I want to be able to access the administrator level functionality of the installed plug-ins. If you do not want to provide full administrator access, you can create custom user roles that meet specific requirements. The
If WordPress does not want to handle plug-in code editing to add custom user roles, it is recommended to use the custom user role plug-in. We have collected three options that greatly simplify this process. 1. user role editor the most used plug-in is the user role editor
Yes- If this sounds like you, maybe you should bypass the plug-in. This allows you to hard code user role changes without worrying about keeping unrelated plug-ins up to date. If you only want to add user roles or change functions for a single user – if not, why interrupt the site with an additional plug-in? Now, you can take this into account and go to the details. We will discuss two ways to modify user roles using code only. The
In theory, the following code example is the function of the theme. You can throw it into a PHP file to run. However, changing the WordPress user role is usually a one-time event, so it makes no sense to do so. Each time the page in the function file is refreshed, the page will be loaded and the site database will be continuously updated, but the efficiency is not high. Therefore, it is recommended that you create a custom plug-in that can contain the corresponding code to run only once when the plug-in is activated. To do this, the first step is customized user roles. Create a file named PHP (or other file to be named), open it with a code editor, and include the following fragments: Here, you can reopen the file through the FTP client, enter the required code, and then activate and disable the plug-in once. Add and remove the WordPress user role add\u role(). First, let’s discuss the add_role() function. According to the official WordPress code reference, this function adds a new user role to WordPress, unless a user role with the same name still exists. The default structure is as follows: Let’s analyze what add\u role ($role, $display\u name, $capability=array()) means to all other parts$ Role – this is the name of the role that will be stored in the word press database$ Display_name – the name of the role that the user will see on the back end$ Capability – this array describes the capabilities of the new user role. You can find the list here. Yes, to be more specific, let’s look at a specific case. Suppose you want to add a new role called mainternance guy to the web site. The only thing he can do is update word press and all the themes and plug-ins. The code snippet is as follows: Function add_custom_user_role() {add_role (‘maintenance_guy’,’maintenance guy’, array (‘read’= > true,’update\u core’ = > true,’update\u plugins’= > true,’update\u themes’ = > true));} Register_activation_hook (\u file\u,’add\u custom\u user\u role’); As you can see, the name of the role is maintenance \u guy, and the display name is defined. The function of the array is very important. Read (must be added to view the backend) update\u themes update\u core, update\u plugins, and update\u themes. The register_activation_hook at the time of the function call will run when the plug-in is activated. Activate the custom plug-in, use this role to create a new user on the site, and then log in as this user. You can only see the word press dashboard, the profile menu, and the update page. Now, whether it makes sense to create such a user or simply automate the update process is another story, but the above content is a
As long as you assign the least functional user role, the site will be more secure and everyone can continue to access the required projects. Now is the time to perform custom user roles. What is the custom user role used by the WordPress website? Please tell the following comments!