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.

15 thoughts on “Allowing Participants Database Editors to Delete Records

  1. Hi Roland:
    Thanks for the info.
    I was going through my code from one of my developers.
    I am unable to add records to database.
    I copied code from another site he did for me which works.
    I added the php to the template.
    It looks right/
    I get all the fields, but when I submit it does not populated db.
    Here is a portion of the code.
    What does the wp_0k8…. mean.
    If its the id for the db, where do I find that ID on my site to add to code.
    $wpdb->insert(‘wp_0k8kmyk1bc_participants_database’, array(‘section’=>$_POST[‘section’] ,

    1. If you can’t add records, it’s important to find out why and fix that instead of trying to find a way around the problem because if that isn’t working, other problems will probably exist as well.

      Are you asking about adding a record from the backend (admin section) or frontend using the signup form? What exactly happens when you try to add the record? Have you looked in the php error log after trying to add a record?

      To answer your technical question, the database table prefix is provided by the $wpdb->prefix property. Take a look at the WordPress wpdb class for the details.

  2. Hi Roland:
    I was actually setting this up on the backend for administrators only.
    I know if I go in the records and following notes you wrote in the past, I see the area where I can delete a record, but, I have to be in the record and can only do one at a time.
    I want to be able to delete multiple records from a list.
    Can that be done from the backend?

    1. On the backend list, you select the ones you want to delete, then at the top of the list is a dropdown for the “with selected” actions…choose “delete”

  3. Hi Roland:
    First thanks for all you help in the past.
    Can you help me with the ability to allow multiple deletes just by putting a check mark in the box and then pressing a delete button. I would like to know what short code to use and and filters. Currently, I can do a search and provide and output. From that output, I want to select if needed more then one line entry, check it and then click “Delete” and they all get deleted.
    Here is the link: http://r89.134.myftpupload.com/edit%20record%20link/
    From the search select “section”
    Then use the letter “M” and click search
    Currently you can view. I want to change the view to a check box and then somewhere have a delete button. Maybe a warning message to come up.

    1. Well, of course this can easily be done on the admin side. Setting this up on the frontend means you’d be building the functionality from scratch there’s no code support for it at all. If you can write the code (php and javascript will be required), I can give you some pointers, but i can’t do this for you, I’m sorry.

  4. 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.

  5. 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

Your email address will not be published. Required fields are marked *

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.

15 thoughts on “Allowing Participants Database Editors to Delete Records

  1. Hi Roland:
    Thanks for the info.
    I was going through my code from one of my developers.
    I am unable to add records to database.
    I copied code from another site he did for me which works.
    I added the php to the template.
    It looks right/
    I get all the fields, but when I submit it does not populated db.
    Here is a portion of the code.
    What does the wp_0k8…. mean.
    If its the id for the db, where do I find that ID on my site to add to code.
    $wpdb->insert(‘wp_0k8kmyk1bc_participants_database’, array(‘section’=>$_POST[‘section’] ,

    1. If you can’t add records, it’s important to find out why and fix that instead of trying to find a way around the problem because if that isn’t working, other problems will probably exist as well.

      Are you asking about adding a record from the backend (admin section) or frontend using the signup form? What exactly happens when you try to add the record? Have you looked in the php error log after trying to add a record?

      To answer your technical question, the database table prefix is provided by the $wpdb->prefix property. Take a look at the WordPress wpdb class for the details.

  2. Hi Roland:
    I was actually setting this up on the backend for administrators only.
    I know if I go in the records and following notes you wrote in the past, I see the area where I can delete a record, but, I have to be in the record and can only do one at a time.
    I want to be able to delete multiple records from a list.
    Can that be done from the backend?

    1. On the backend list, you select the ones you want to delete, then at the top of the list is a dropdown for the “with selected” actions…choose “delete”

  3. Hi Roland:
    First thanks for all you help in the past.
    Can you help me with the ability to allow multiple deletes just by putting a check mark in the box and then pressing a delete button. I would like to know what short code to use and and filters. Currently, I can do a search and provide and output. From that output, I want to select if needed more then one line entry, check it and then click “Delete” and they all get deleted.
    Here is the link: http://r89.134.myftpupload.com/edit%20record%20link/
    From the search select “section”
    Then use the letter “M” and click search
    Currently you can view. I want to change the view to a check box and then somewhere have a delete button. Maybe a warning message to come up.

    1. Well, of course this can easily be done on the admin side. Setting this up on the frontend means you’d be building the functionality from scratch there’s no code support for it at all. If you can write the code (php and javascript will be required), I can give you some pointers, but i can’t do this for you, I’m sorry.

  4. 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.

  5. 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

Your email address will not be published. Required fields are marked *

Would you like to be notified of followup comments via e-mail? You can also subscribe without commenting.