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.

9 thoughts on “Allowing Participants Database Editors to Delete Records

  1. Hi Roland,
    I’m testing this plugin to make future registrations for my wedding ( two dates, differents forms.. i still didn’t find how exactly doing it, but this is not my question yet ).
    I made some test and now I would like to delete the list, but it doesn’t work. I’m admin. Why ??
    Thanks a lot for your help.

    1. What did you try? You can delete multiple records in the admin list by selecting them (or use the “select all” at the top of the sector column) and then choosing “delete” in the “with selected” menu.

      1. Hi Roland
        I’m a fan of your plugin. Unfortunately I experience the same problem as Melanie above. I did exactly what you described but nothing happens. I need to delete a few test entries and my admin doesn’t give me database access, which would be my fallback solution.
        I’m looking forward to your reply and thanks for all the good work.
        Katrin

        1. Well, she never got back to me, so I figured she solved it.

          So, in your case, I assume that you have the “with selected” control visible and can check the records you want deleted. In the “with selected” dropdown, you select “delete” then click on “apply” Then what happens? Probably in your case there is some kind of javascript conflict with another plugin.

  2. I’m setting up a custom user role for database contributors. This tutorial was very helpful, but could you also list the other permissions required for a user to be able to access the Participants Database in the WordPress Dashboard?

    1. To be more specific, I have assigned the custom user role as database editor, but the participants database is not showing in the dashboard menu.

    2. The way this works is Participants Database has 2 assigned roles for interacting with the plugin in the admin. Under the “Admin Settings” tab, you’ll see the two access roles. Your custom role will show up in the dropdown. The role doesn’t need any particular capability for this, but of course they will need access to the admin side.

      1. I thought that as well. However, the behavior that I observed when I set the editor role in the plugin to the custom role I created was different. It actually removed the add and list participants from the admin role, and didn’t show the Participants Database menu item at all for the editor role.

        1. Aaron, my apologies, it’s been too long since I looked at this, and I steered you wrong. We do use specific capabilities to determine the plugin access roles.

          I decided to publish a tutorial on the subject so my explanation of how to do this can be (hopefully) found by others.

          Setting Up Custom Access Roles in Participants Database

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

9 thoughts on “Allowing Participants Database Editors to Delete Records

  1. Hi Roland,
    I’m testing this plugin to make future registrations for my wedding ( two dates, differents forms.. i still didn’t find how exactly doing it, but this is not my question yet ).
    I made some test and now I would like to delete the list, but it doesn’t work. I’m admin. Why ??
    Thanks a lot for your help.

    1. What did you try? You can delete multiple records in the admin list by selecting them (or use the “select all” at the top of the sector column) and then choosing “delete” in the “with selected” menu.

      1. Hi Roland
        I’m a fan of your plugin. Unfortunately I experience the same problem as Melanie above. I did exactly what you described but nothing happens. I need to delete a few test entries and my admin doesn’t give me database access, which would be my fallback solution.
        I’m looking forward to your reply and thanks for all the good work.
        Katrin

        1. Well, she never got back to me, so I figured she solved it.

          So, in your case, I assume that you have the “with selected” control visible and can check the records you want deleted. In the “with selected” dropdown, you select “delete” then click on “apply” Then what happens? Probably in your case there is some kind of javascript conflict with another plugin.

  2. I’m setting up a custom user role for database contributors. This tutorial was very helpful, but could you also list the other permissions required for a user to be able to access the Participants Database in the WordPress Dashboard?

    1. To be more specific, I have assigned the custom user role as database editor, but the participants database is not showing in the dashboard menu.

    2. The way this works is Participants Database has 2 assigned roles for interacting with the plugin in the admin. Under the “Admin Settings” tab, you’ll see the two access roles. Your custom role will show up in the dropdown. The role doesn’t need any particular capability for this, but of course they will need access to the admin side.

      1. I thought that as well. However, the behavior that I observed when I set the editor role in the plugin to the custom role I created was different. It actually removed the add and list participants from the admin role, and didn’t show the Participants Database menu item at all for the editor role.

        1. Aaron, my apologies, it’s been too long since I looked at this, and I steered you wrong. We do use specific capabilities to determine the plugin access roles.

          I decided to publish a tutorial on the subject so my explanation of how to do this can be (hopefully) found by others.

          Setting Up Custom Access Roles in Participants Database

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