Do you know how to log in to the WordPress site as an author and delete other people’s posts, or do you not manage core site projects, such as themes and plug-ins? Roles and functions are a very useful system for managing all this. In this weekend’s WordPress project, we will learn more about some code based modifications, including custom roles and functions to meet your needs. earth What are roles and functions? The word press subsystem is responsible for determining the actions that specific users on the website can take. This reduces dashboard clutter (many menu items are not visible to the creator \/ writer) and enhances security by not simply allowing certain users to perform certain actions. The
The system is more than a simple way to hide items. The \
There are more than 50 functions in management, including plug-ins, posts, options and multi site networks. Let’s see how to use it later in this document. Roles roles are simply functions grouped together as packages. When I say \
The benefits of roles and functions are really many. The system is the hub of WordPress user management and plays a great role in separating user groups. The advantage of this is that you can work efficiently with users. The WordPress user management interface enables you to better manage website content. It is the basis of an oiling safety system to provide as few access rights as possible, but only necessary access rights. The theme and plug-in options cannot be viewed because no editing is required. Other people’s posts cannot be deleted because the author is not required. Administrators can immediately understand what problem users can and cannot do, making team collaboration (and problem solving) much easier. The
The subscriber view of WordPress administrator finally, the functional system, especially when combined with the nonce system to confirm permissions and intentions, has great security advantages. Each time a task is executed, WordPress checks whether the corresponding functions are available. This will use nonce to confirm the intention, if everything is OK, the operation will be performed, otherwise the following error message will be displayed: Although this doesn’t allow you to do anything, it’s what happens when you try anyway. Let’s think about why nonce also needs it. Delete the post link as follows: http:\/\/wordpress.local\/wp-admin\/post.php?post=1&action=delete When you access the link as a logged in administrator, the post is deleted. If WordPress is not sure where the user comes from, problems may arise. Can delete links to your site content
Can be published anywhere. A problem occurs when you click. As a result, functionality helps determine whether you have permission to perform tasks, but temporary items are also required to determine intent. For more information, check out the non story. The
When creating plug-ins and themes using roles and features, you can limit specific actions to roles. For example, if you create an SEO plug-in, you can restrict it to creators, editors, and administrators only. In addition, you may want to limit the default options to administrators. To do this, use the current_user_can() function or specific parameters of an existing word press function. Take a look at both. The example on the load summary d0f8b 862996088491820 shows how to add top-level menu items to the administration menu. The add\menu\u page() function contains parameters that define the functions required to view menu items. In our case, manage_options. By default, this means that only administrators can see it. The
You can use the current_user_can() (or user_can()) function to test the function directly. Use this method to hide delete links in the view. Please note that loading the summary d0f8b 862996088491820 obviously, all I have to do is grant administrator access, but the function is used in both cases. There are two reasons to always use features: One is to check how functions are built. In some cases, if a role is specified, only true is returned for the role, and the role \
The second reason relates to the role and limitation (functional) architecture. A role is a completely arbitrary name assigned to any feature list. In fact, we cannot guarantee that the administrator actually has the manage_options function. By default, WordPress assigns these functions, but you can use code or plug-ins to add \/ remove functions for roles or specific users. This makes role-based code unstable, so always use the feature. Creating custom roles when building large applications, you may need custom roles to group users individually. If your site runs its own ads, you can create a company role. Users in this role may have a special function to view the statistics page showing advertising performance. The
The basic code for this operation is as follows: Use the add_role() function to create the role and add the functions required by the role to the third parameter. The first parameter is the name of the role, and the second parameter is the title of the display. The load summary d0f8b 862996088491820 add\u role() function returns null when a role is created or exists, so it can be safely used anywhere in the code. In other words, there is no reason to always run this function. My favorite method is to put it into the activation hook. View the advanced example below. The
The load summary d0f8b 862996088491820 has two differences. First, we wrap the code with activation functions. This runs only once when the plug-in is activated. If it does not exist, the role will be generated. We also decided to copy the list of features for the author role instead of recording all the features I wanted, and then add a unique feature to view advertising statistics. To do this, we use the get_role() function to search for the author role and copy the list of functions into the correct parameters of the add_role() function. In the profile section, the user level system was used before word press version 2.0 (a long time ago)