Posted on by

Allowing Participants Database Editors to Delete Records

Normally, users with the Participants Database “Editor” role cannot delete records, but it is possible to provide this access if your situation needs it.

I’m going to explain this in a little detail because how it works is not very intuitive at all. If you just want to put in the code, you can jump ahead.

Participants Database Privileges

Privileged actions in Participants Database are passed through a filter that makes it possible to change who has access to a particular function. The way this works is each privilege is identified with a “context” string. To change the access for a particular privilege, you need to know the context string. Check this page for a list of most of them: User Access Controls. This tutorial demonstrates how to change the access level for a particular privilege, deleting Participants Database records.

The filter we need to use is ‘pdb-access_capability’ and the way it works is it gives you the current access capability and the context or name of the privilege being requested. The filter can then change the access capability for that privilege.

I know that this is difficult to understand until you have a good grasp of how WordPress roles and capabilities work. Simply put, a “role” is something like Administrator or Editor. Each role has a set of capabilities, which is a list of the things that that role can do. This gives us a lot of control over what each user can and cannot do.

Plugin Administrators and Editors

In Participants Database, there are “administrator” and “editor” roles as well. By default, these correspond to the WordPress roles by the same name. In Participants Database, each plugin role is typified by a WordPress capability. A plugin administrator is identified by the “manage_options” capability and a plugin editor is identified by the “edit_others_posts” capability. I know this can be confusing, but if you think of the capability as just another way to identify a role it makes more sense.

So, when we want to allow a plugin role access to a specific privilege, we do that by setting the WP capability that corresponds to the role when the access privileges are requested. Our filter gives us access to those requests so we can change what role is allowed.

The Filter Code

Here is a simple filter that will make it possible for plugin editors to delete records. It does this by first checking which privilege is being asked for, and if it is the “delete participants” privilege, we give it the WP capability that corresponds to the plugin “editor” role.

To use this filter, as usual, you can place it in your theme functions file. It’s also possible to install it as a plugin, you just need to copy it to a file, add the WP plugin header and upload it to your plugin directory.

Leave a Reply
You have to agree to the comment policy.

Leave a Reply
You have to agree to the comment policy.