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 a login and password to access their profile?”

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

103 thoughts on “Using Participants Database with WordPress Users

  1. Dear Ronald,
    Thank you so much for your plugin. PDB is simply and powerful. I am setting PDB up to a kinder garten website so the parents can find information about their children. I am using this Word Press users so the parents login and find the informatio on their kids. I am using the [pdb_user_record] record to show the children info and some activities.
    I need to set a “Link field” field so the parents can dowload a .pdf file with the activities for the children. However this Link field is not clikable in the front end [pdb_user_record] template. The [pdb_record] allows to link the pdf file but the [pdb_user_record] does not.
    Is there any way to make a Link field or text-line clickable in the [pdb_user_record] template?

    Best regards from Colombia,

    1. Hi Roland,
      I got it! I’ve changed the [pdb_user_record] for the [pdb_user_single] short code and it does make clickable the text-line fields.
      This plugin is so versatile. Thanks again.

      1. glad you go that figured out!

  2. Hi there in the tutorial it says:

    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.

    However this is not actually provided for by the code so the shortcode is not created, how would I create this shortcode as it is something I need.

    To clarify I just want to show the user the details on their record but not make it editable.

    1. The tutorial does not include that, but it is not difficult to add. The tutorial is really only meant as a starting point for your own custom code.

  3. What would be the best approach to create custom signup shortcode that will allow a WP user to signup/add multiple records with one submit.
    CSV approach is not an option due to being too complex for the user. Ideally be html multi rows form (landscape) each row being a new signup record.

    Thank you for any guidance,
    Andrew.

    1. Easiest way to create several records with a single submission would be to let javascript handle the submission, then on the server side, you’d parse out the submitted data for each record then save the records in succession. If you try to do a synchronous submission, you’ll have to avoid the plugin trying to process the submission. Doing it asynchronously gives you better control over how the submission and user feedback is handled.

      With a complex interaction like that, I think it’s a must to design the UI first, then figure out how to make the code work.

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

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

103 thoughts on “Using Participants Database with WordPress Users

  1. Dear Ronald,
    Thank you so much for your plugin. PDB is simply and powerful. I am setting PDB up to a kinder garten website so the parents can find information about their children. I am using this Word Press users so the parents login and find the informatio on their kids. I am using the [pdb_user_record] record to show the children info and some activities.
    I need to set a “Link field” field so the parents can dowload a .pdf file with the activities for the children. However this Link field is not clikable in the front end [pdb_user_record] template. The [pdb_record] allows to link the pdf file but the [pdb_user_record] does not.
    Is there any way to make a Link field or text-line clickable in the [pdb_user_record] template?

    Best regards from Colombia,

    1. Hi Roland,
      I got it! I’ve changed the [pdb_user_record] for the [pdb_user_single] short code and it does make clickable the text-line fields.
      This plugin is so versatile. Thanks again.

      1. glad you go that figured out!

  2. Hi there in the tutorial it says:

    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.

    However this is not actually provided for by the code so the shortcode is not created, how would I create this shortcode as it is something I need.

    To clarify I just want to show the user the details on their record but not make it editable.

    1. The tutorial does not include that, but it is not difficult to add. The tutorial is really only meant as a starting point for your own custom code.

  3. What would be the best approach to create custom signup shortcode that will allow a WP user to signup/add multiple records with one submit.
    CSV approach is not an option due to being too complex for the user. Ideally be html multi rows form (landscape) each row being a new signup record.

    Thank you for any guidance,
    Andrew.

    1. Easiest way to create several records with a single submission would be to let javascript handle the submission, then on the server side, you’d parse out the submitted data for each record then save the records in succession. If you try to do a synchronous submission, you’ll have to avoid the plugin trying to process the submission. Doing it asynchronously gives you better control over how the submission and user feedback is handled.

      With a complex interaction like that, I think it’s a must to design the UI first, then figure out how to make the code work.

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

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