Posted on by

Using Participants Database with WordPress Users

This post was updated November 6, 2019 to be compatible with current versions of WordPress.

A very common support request is along the lines of “how can I give my users access to a set of Participants Database records?”

There are basically two ways to do this, depending on what privileges you want to give your users. If you just want them to be able to use a couple of pieces of information (email and password, perhaps) to gain access to their one Participants Database record for editing (and nothing more than that), you can use the Participant Login add-on to provide a login form for that purpose.

If you need to provide your users with other privileges, such as access to protected areas or the ability to know who they are on other pages, then you have to register your users as WordPress users. That will give them a way to log in and that will be persistent throughout your site.

Participants Database can work very well with WP users, but it can be a little tricky figuring out how the two functionalities will work together. In this post, I lay out a simple scheme that can serve as a starting point for your own integration. What I describe here won’t require much coding, but you’ll probably need to get deeper into the code if you want to take things beyond this.

Relating Records to Users

The easiest part is relating a record to a user. When a user is logged in, several pieces of information about them is available. All we need to do is capture a bit of information that will identify the user and store that with the record. I’ll provide an example of how to do that.

Create a hidden field named “username” to hold the user login. After creating the field, I changed the title to “User Name” for readability, you should choose whatever title makes sense to you. Set the default to current_user->user_login That will grab the “user_login” property of the current_user object when a new record is created.

If your application allows users to create multiple records, they will all be associated with the user through this value. Be sure to set the field to appear in the signup form by checking the “signup” checkbox.

example configuration of the field that captures the user login value

Of course, for this to work, your signup form has to be accessible only to logged-in users.

Showing a List of the User’s Records

It’s not difficult to filter a list display so that it only shows records that relate to a particular user. What we need to do is set up a custom shortcode that filters the list according to the currently logged-in user. What it does is how a list that is filtered by the user_login field using the current user’s login name value. That means that the list will only show records that that user created.

The code included in this tutorial will install a plugin that gives you a shortcode for this purpose: [pdb_user_list].

The tutorial code can be modified for your specific needs, for instance, you may want to combine this with: Adding an Edit Record Link to the Frontend List which you can do by adding a template attribute to the list shortcode string that is used in the user_list_shortcode method in the tutorial code.

The tutorial code provides alternate content if the user is not logged in, you can of course change that to show whatever you want such a user to see. This is also in the user_list_shortcode method.

Showing the User an Editable Record

If each user only has one record associated with them, you’ll probably want a way to let them edit it. Showing a single, editable record is a bit trickier because we need to find the record id of the user’s record, but the plugin has methods to help us do that.

The plugin provided with this tutorial creates a shortcode for this purpose [pdb_user_record] This shortcode will show the record that matches the user’s ID and allow them to edit it.

The core of this is the call to Participants_Db::get_record_id_by_term() to which we supply the name of the field (or term) to look at and the value to match. The method returns a single id number, if there are multiple matches, the first in the series is returned.

Showing the User their Record

If you just want to show the user their record (not editable) there is a shortcode provided for that purpose in the tutorial code. Use [pdb_user_single] to show the user’s record.

The Tutorial Plugin

This plugin will install the three shortcodes described in the article. With a little php knowledge, you can modify the plugin to suit your specific needs.

Be sure to check the private $user_id_field = 'username'; line: that is the name of the field you are using to capture the user’s ID value. It must match the field name you use in your setup.

Installing this plugin: How to Install a WordPress Plugin from a Gist

136 thoughts on “Using Participants Database with WordPress Users

  1. Attempting to set up an example of the portal below
    https://nctrc.org/ctrs-verification/

    Is it possible to do this with this plugin with the certificate holders only viewed when information is searched?

    1. You can use the “suppress” attribute of the list shortcode…for example:

      [pdb_list search=true suppress=true]

      Nothing will be shown until a search is performed.

  2. Good Evening;
    I am attempting to create a database of “certified” individuals in our profession. This would be used for employers verification of their employees current active status. I was able to add additional filters….that would assist others to view this information. When I added the code [pdb_list] to a page, I’m able to view the individuals I’ve added with the necessary fields……However when I added the code [pdb_single] and click on preview; I’m told no record available……What am I doing incorrect…..How do I link these two together where an employer can click on the person name and be able to view the information they are seeking. Also is it possible to create an alphabetical list to separate?
    Thanks

    1. The steps to set this up are found in the “Setup Guide” item in the admin Participants Database menu. The [pdb_single] shortcode need to be accessed using a special link so that it know which record to show. These links are configured in the list by designating a page to show the record on and a field to use as the link to the single record page. This is configured under the “List Display” settings tab in Participants Database.

  3. When listing a record (single or multiple) I need to show the date the record was added (date_recorded). I don’t need to be able to edit the date recorded, just display it. I’ve been trying all day and I can’t figure out how to get it to display. Any help/direction would be greatly appreciated :)

    1. This normally hidden field can be displayed if you use the “fields” attribute in the shortcode to determine which fields are shown. For example:

      [pdb_list fields="first_name,last_name,city,state,date_recorded"]

      It’s also possible to display the value by setting up a custom template.

      1. please, im a website developer. how can i create a form for my client whos going to use the website and the database without having access to my wordpress dashbord but he/she can can fill his/her client detail and even generate login form.

        1. This is possible, although I don’t know what you mean by “generate login form” Participants Database does not normally have a login form. You can use the “signup” form to create new records, and use the “list” display to show the records. You can give them access to edit records by using a special template, this is discussed in this article, Adding an Edit Record Link to the Frontend List

  4. Can you limit what the user can edit when they log in?

    1. Ian, It’s important to understand that Participants Database does not offer a persistent login that gives users privileges. You need to give them a WordPress login to get that. Here is an article that discusses the use of the plugin with WordPress users:

      Using Participants Database with WordPress Users

      1. Which WP User plugin do you recommend?

        1. That depends in the purpose…what do you want your users to be able to do? You may not need a plugin for that at all.

        2. Users will register through a registration application such as a WP Users plugin as you have mentioned in earlier posts. Once logged in they will be redirected their profile page which will have buttons. One to “Add Event” and the other to “Edit Event.” The Add Event button will go to the pdb sign-up page and add the event to the database. The other button “to use a dynamic value to set the “filter” attribute of the list shortcode. We get the current user’s login and use that value to show only those records that were created by that user,” so that user may change their entries. I had hoped to do this through pdb login, but that will only call one entry. So, I am curious if you have a WP User plugin (for dummies or beginners) that you recommend?

        3. There isn’t a “WP Users plugin” what I am talking about is the user registration functionality built into your WordPress site.

          What you are looking for is usually called a “membership” plugin that provides your registered users with a profile page on the frontend. It would be on that profile page that you would put those links to Participants Database. Exactly how that would be done depends on the membership plugin. I have done something like this before using the Member Mouse plugin, so I know it’s possible with that one. There are many more, some are free, most are premium plugins.

  5. Hi, first of all thank you for the great PDB plugin. Unfortunately I do not understand many things since I am not a developer. So let me explain in a brief way what I would like to do with the PDB plugin. Sorry for my perhaps bad English, I’m no native speaker. What’s my plan? I would like to offer a service in Germany, where employers – which are in my special case private households – can enter several data and receive a payroll by the end of every month. In the first version I just would like to collect the data which are a lot, so that there will be up to 50 fields with only one employee and 20 extra fields for every additional employee. But the amount is not decisive isuppose. What I need is a way to register first with a minimum of basic data and the possibility for the customer to enter all the other data after login. This version should allow to export the data as csv file. So it’s a kind of Minimal Viable Product.

    In further versions i am thinking of the following features: Providing the monthly invoice (PDF) within the individual account, providing the monthly payroll (PDF) as well, interface for the data processing system (lexware).

    Would you recommend to start with PDB? At the moment I have problems to understand the Usage of Participants Database with WordPress Users. I would really like to work with PDB, but don’t know weather I (may be with a developer support) can realize my ideas with the plugin. Can you give me an advice? Thank you in advance.

    1. Thanks for your interest in Participants Database, I think it could be the basis for your project. You will need to hire a developer to set this up, it is far too complex for someone without technical knowledge. Because what you are creating is so specialized, you will need to have a lot of custom code developed–you won’t be able to find a plugin that will do this.

  6. Hi, i have been trying to integrate WP-Members plugin so that when someone registers it prefills forms for PDB but I don’t know how to do that, maybe you can help? My main question is that i have followed your instructions to make a custom template to make the above work where user login is pre-filled but i’ve tried everything i can think of and it isn’t working, can you help me? Thanks, Levi

    1. This is my code i put into the fields loop in my custom template, which is just a copy of the default template.

      $current_user = wp_get_current_user();
      if ( $field->name == ‘user_login’ ) { 
         $this->field->value = $current_user->user_login; 
      }
      1. To check the name of the current field, you need to use $this->field->name

    2. Hi Levi,

      I’m sorry, I can’t help you…integrating two plugins is really going to leave you on your own, and it is a generally challenging assignment. I’ve done it several times, and I try to avoid it.

      1. What if i want to just use the standard WP user registration? How would i get the two databases to play nice?

        1. I’ve got an article that discusses this:

          Using Participants Database with WordPress Users

  7. Hello Roland,
    I have successful used the tutorials on this page to create a “dashboard” for my users and redirected them after login. It works well for existing users with a record in PDB. My issue is with new users and my questions are as follows:

    1. is it possible to auto create & populate the field ‘user_login’ with the new user id on a new wordpress user registration?

    2. Instead of no ” record was found ” in a custom pdb_single template, how can I show eg. “you have no profile yet, click here to create one (with a link to a custom pdb_signup form)

    Kind regards.

    1. Glad to hear you’remaking good progress.

      If you’re familiar with working with the custom templates, doing these things is easy. For your first question, you can place code in the custom template that pre-fills the value of the field…with something like this in the fields loop before it’s displayed:

      name === 'user_login' ) { $this->field->value = $current_user->user_login; } ?>

      for the second question, you need to use a custom template there, too. If you look at the template for the single record display pdb-single-default.php, toward the bottom, you’ll see the part of the template that is displayed when the record ID can’t be found. That is where you place your alternate content.

      1. Hello, Thank you for the message and apologies for the double post on this issue in the WP support forum.

        I am unable to find the section of the pdb-single-default.php template that displays if no record ID can be found.
        Below is the content of the pdb-single-default.php towards the end. Unfortunately i cant paste it all here (comment too long :-) )
        ……..
        <dl class="field->name.’ ‘.$this->field->form_element.’ ‘.$empty_class?>”>

        <dt class="field->name.’ ‘.$empty_class?>”>field->print_label() ?>

        <dd class="field->name.’ ‘.$empty_class?>”>field->print_value() ?>

        1. Hi Peter, sorry about the confusion, I was looking at the record template. There isn’t a specific way to show alternate “not found” content for the single shortcode. There should be, but it looks like I didn’t put that in. I’ve got it on the list for the nest release.

          All you can do for now (unless you want use a snippet) is use the “Record Not Found Error Message” (under the record form tab) for your “not found” content.

  8. Hi, Pls is there a way to show the edit link to only a user with “editor” capabilities? irrespective of who the record belongs to?

    1. If you are talking about the modified list template that will show a record edit link, then yes, all you need to do is add a condition to the modification that checks the current user’s role. Something like this:

      if ($this->field->name == 'edit_link' && current_user_can( 'editor' ) ) {
        $this->field->link = $record->get_edit_link();
      }
      1. Very helpful. Thank you very much

  9. Thanks Ronald for the quick reply.

    Btw I’m not a developer but I’m trying to learn a few basics! This appears as an element in the page, is this what you mean?

    The field is set as user_login, hidden, with current_user->user_login in the Values box. Admin column set at 1, and “sortable” and “signup” are ticked. When “required” is selected the user gets a 404 page on hitting “submit”; otherwise it works but without recording the WordPress user.

    I don’t suppose it matters which group it’s assigned to? Currently in “Main”.

    Thanks again.

    1. Beg pardon, this is what appears as an element:

      1. Woops, no idea why it doesn’t copy-paste! I’ll type it out this time:

        1. input name=”user_login” type=”hidden” value=””

        2. Looks like you got it set up right, just make sure that you are logged in when you load the signup form. The group doesn’t matter, a field like that will usually be in an administrative group.

  10. I have tested version 1.7.5, 1.7.5.7 and 1.7.5.8 and both gives the same result.
    Starting from the top…
    Manage Database fields> Create a user_login field as instructed (tick the signup box, hidden field and set the default to current_user->user_login). When I go Add Participant, enter a few values and Submit.
    Then go to List Participants, the user_login field remains blank.
    Up until two weeks ago it used to fill in the value there of the user that is logged in.
    Somehow the ‘hook’ to the user_login no longer works.

    1. Found the problem…eventually!!
      Using WordPress 4.8.1 – the Insert PHP Plugin does not work correctly – has not been tested on WP4.8.1. I installed Insert PHP Code Snippet plugin ….and tada!!

      1. It was the PHP plugin all along? Well that’s certainly good news! Thanks for keeping us in the loop.

        1. I’m having the same problem but I’m not using any Insert PHP plugin yet. I’m stuck on step 1 – user_login field remains blank after submitting an entry while logged in as admin.

        2. Neil,
          All I can say is make sure that the hidden field is correctly configured and that it is included in the signup form. You may need to look at the HTML to verify this.

Leave a Reply to neil Cancel 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.

136 thoughts on “Using Participants Database with WordPress Users

  1. Attempting to set up an example of the portal below
    https://nctrc.org/ctrs-verification/

    Is it possible to do this with this plugin with the certificate holders only viewed when information is searched?

    1. You can use the “suppress” attribute of the list shortcode…for example:

      [pdb_list search=true suppress=true]

      Nothing will be shown until a search is performed.

  2. Good Evening;
    I am attempting to create a database of “certified” individuals in our profession. This would be used for employers verification of their employees current active status. I was able to add additional filters….that would assist others to view this information. When I added the code [pdb_list] to a page, I’m able to view the individuals I’ve added with the necessary fields……However when I added the code [pdb_single] and click on preview; I’m told no record available……What am I doing incorrect…..How do I link these two together where an employer can click on the person name and be able to view the information they are seeking. Also is it possible to create an alphabetical list to separate?
    Thanks

    1. The steps to set this up are found in the “Setup Guide” item in the admin Participants Database menu. The [pdb_single] shortcode need to be accessed using a special link so that it know which record to show. These links are configured in the list by designating a page to show the record on and a field to use as the link to the single record page. This is configured under the “List Display” settings tab in Participants Database.

  3. When listing a record (single or multiple) I need to show the date the record was added (date_recorded). I don’t need to be able to edit the date recorded, just display it. I’ve been trying all day and I can’t figure out how to get it to display. Any help/direction would be greatly appreciated :)

    1. This normally hidden field can be displayed if you use the “fields” attribute in the shortcode to determine which fields are shown. For example:

      [pdb_list fields="first_name,last_name,city,state,date_recorded"]

      It’s also possible to display the value by setting up a custom template.

      1. please, im a website developer. how can i create a form for my client whos going to use the website and the database without having access to my wordpress dashbord but he/she can can fill his/her client detail and even generate login form.

        1. This is possible, although I don’t know what you mean by “generate login form” Participants Database does not normally have a login form. You can use the “signup” form to create new records, and use the “list” display to show the records. You can give them access to edit records by using a special template, this is discussed in this article, Adding an Edit Record Link to the Frontend List

  4. Can you limit what the user can edit when they log in?

    1. Ian, It’s important to understand that Participants Database does not offer a persistent login that gives users privileges. You need to give them a WordPress login to get that. Here is an article that discusses the use of the plugin with WordPress users:

      Using Participants Database with WordPress Users

      1. Which WP User plugin do you recommend?

        1. That depends in the purpose…what do you want your users to be able to do? You may not need a plugin for that at all.

        2. Users will register through a registration application such as a WP Users plugin as you have mentioned in earlier posts. Once logged in they will be redirected their profile page which will have buttons. One to “Add Event” and the other to “Edit Event.” The Add Event button will go to the pdb sign-up page and add the event to the database. The other button “to use a dynamic value to set the “filter” attribute of the list shortcode. We get the current user’s login and use that value to show only those records that were created by that user,” so that user may change their entries. I had hoped to do this through pdb login, but that will only call one entry. So, I am curious if you have a WP User plugin (for dummies or beginners) that you recommend?

        3. There isn’t a “WP Users plugin” what I am talking about is the user registration functionality built into your WordPress site.

          What you are looking for is usually called a “membership” plugin that provides your registered users with a profile page on the frontend. It would be on that profile page that you would put those links to Participants Database. Exactly how that would be done depends on the membership plugin. I have done something like this before using the Member Mouse plugin, so I know it’s possible with that one. There are many more, some are free, most are premium plugins.

  5. Hi, first of all thank you for the great PDB plugin. Unfortunately I do not understand many things since I am not a developer. So let me explain in a brief way what I would like to do with the PDB plugin. Sorry for my perhaps bad English, I’m no native speaker. What’s my plan? I would like to offer a service in Germany, where employers – which are in my special case private households – can enter several data and receive a payroll by the end of every month. In the first version I just would like to collect the data which are a lot, so that there will be up to 50 fields with only one employee and 20 extra fields for every additional employee. But the amount is not decisive isuppose. What I need is a way to register first with a minimum of basic data and the possibility for the customer to enter all the other data after login. This version should allow to export the data as csv file. So it’s a kind of Minimal Viable Product.

    In further versions i am thinking of the following features: Providing the monthly invoice (PDF) within the individual account, providing the monthly payroll (PDF) as well, interface for the data processing system (lexware).

    Would you recommend to start with PDB? At the moment I have problems to understand the Usage of Participants Database with WordPress Users. I would really like to work with PDB, but don’t know weather I (may be with a developer support) can realize my ideas with the plugin. Can you give me an advice? Thank you in advance.

    1. Thanks for your interest in Participants Database, I think it could be the basis for your project. You will need to hire a developer to set this up, it is far too complex for someone without technical knowledge. Because what you are creating is so specialized, you will need to have a lot of custom code developed–you won’t be able to find a plugin that will do this.

  6. Hi, i have been trying to integrate WP-Members plugin so that when someone registers it prefills forms for PDB but I don’t know how to do that, maybe you can help? My main question is that i have followed your instructions to make a custom template to make the above work where user login is pre-filled but i’ve tried everything i can think of and it isn’t working, can you help me? Thanks, Levi

    1. This is my code i put into the fields loop in my custom template, which is just a copy of the default template.

      $current_user = wp_get_current_user();
      if ( $field->name == ‘user_login’ ) { 
         $this->field->value = $current_user->user_login; 
      }
      1. To check the name of the current field, you need to use $this->field->name

    2. Hi Levi,

      I’m sorry, I can’t help you…integrating two plugins is really going to leave you on your own, and it is a generally challenging assignment. I’ve done it several times, and I try to avoid it.

      1. What if i want to just use the standard WP user registration? How would i get the two databases to play nice?

        1. I’ve got an article that discusses this:

          Using Participants Database with WordPress Users

  7. Hello Roland,
    I have successful used the tutorials on this page to create a “dashboard” for my users and redirected them after login. It works well for existing users with a record in PDB. My issue is with new users and my questions are as follows:

    1. is it possible to auto create & populate the field ‘user_login’ with the new user id on a new wordpress user registration?

    2. Instead of no ” record was found ” in a custom pdb_single template, how can I show eg. “you have no profile yet, click here to create one (with a link to a custom pdb_signup form)

    Kind regards.

    1. Glad to hear you’remaking good progress.

      If you’re familiar with working with the custom templates, doing these things is easy. For your first question, you can place code in the custom template that pre-fills the value of the field…with something like this in the fields loop before it’s displayed:

      name === 'user_login' ) { $this->field->value = $current_user->user_login; } ?>

      for the second question, you need to use a custom template there, too. If you look at the template for the single record display pdb-single-default.php, toward the bottom, you’ll see the part of the template that is displayed when the record ID can’t be found. That is where you place your alternate content.

      1. Hello, Thank you for the message and apologies for the double post on this issue in the WP support forum.

        I am unable to find the section of the pdb-single-default.php template that displays if no record ID can be found.
        Below is the content of the pdb-single-default.php towards the end. Unfortunately i cant paste it all here (comment too long :-) )
        ……..
        <dl class="field->name.’ ‘.$this->field->form_element.’ ‘.$empty_class?>”>

        <dt class="field->name.’ ‘.$empty_class?>”>field->print_label() ?>

        <dd class="field->name.’ ‘.$empty_class?>”>field->print_value() ?>

        1. Hi Peter, sorry about the confusion, I was looking at the record template. There isn’t a specific way to show alternate “not found” content for the single shortcode. There should be, but it looks like I didn’t put that in. I’ve got it on the list for the nest release.

          All you can do for now (unless you want use a snippet) is use the “Record Not Found Error Message” (under the record form tab) for your “not found” content.

  8. Hi, Pls is there a way to show the edit link to only a user with “editor” capabilities? irrespective of who the record belongs to?

    1. If you are talking about the modified list template that will show a record edit link, then yes, all you need to do is add a condition to the modification that checks the current user’s role. Something like this:

      if ($this->field->name == 'edit_link' && current_user_can( 'editor' ) ) {
        $this->field->link = $record->get_edit_link();
      }
      1. Very helpful. Thank you very much

  9. Thanks Ronald for the quick reply.

    Btw I’m not a developer but I’m trying to learn a few basics! This appears as an element in the page, is this what you mean?

    The field is set as user_login, hidden, with current_user->user_login in the Values box. Admin column set at 1, and “sortable” and “signup” are ticked. When “required” is selected the user gets a 404 page on hitting “submit”; otherwise it works but without recording the WordPress user.

    I don’t suppose it matters which group it’s assigned to? Currently in “Main”.

    Thanks again.

    1. Beg pardon, this is what appears as an element:

      1. Woops, no idea why it doesn’t copy-paste! I’ll type it out this time:

        1. input name=”user_login” type=”hidden” value=””

        2. Looks like you got it set up right, just make sure that you are logged in when you load the signup form. The group doesn’t matter, a field like that will usually be in an administrative group.

  10. I have tested version 1.7.5, 1.7.5.7 and 1.7.5.8 and both gives the same result.
    Starting from the top…
    Manage Database fields> Create a user_login field as instructed (tick the signup box, hidden field and set the default to current_user->user_login). When I go Add Participant, enter a few values and Submit.
    Then go to List Participants, the user_login field remains blank.
    Up until two weeks ago it used to fill in the value there of the user that is logged in.
    Somehow the ‘hook’ to the user_login no longer works.

    1. Found the problem…eventually!!
      Using WordPress 4.8.1 – the Insert PHP Plugin does not work correctly – has not been tested on WP4.8.1. I installed Insert PHP Code Snippet plugin ….and tada!!

      1. It was the PHP plugin all along? Well that’s certainly good news! Thanks for keeping us in the loop.

        1. I’m having the same problem but I’m not using any Insert PHP plugin yet. I’m stuck on step 1 – user_login field remains blank after submitting an entry while logged in as admin.

        2. Neil,
          All I can say is make sure that the hidden field is correctly configured and that it is included in the signup form. You may need to look at the HTML to verify this.

Leave a Reply to neil Cancel 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.