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.
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”
Attempting to set up an example of the portal below
Is it possible to do this with this plugin with the certificate holders only viewed when information is searched?
You can use the “suppress” attribute of the list shortcode…for example:
Nothing will be shown until a search is performed.
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?
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.
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 :)
This normally hidden field can be displayed if you use the “fields” attribute in the shortcode to determine which fields are shown. For example:
It’s also possible to display the value by setting up a custom template.
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.
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
Can you limit what the user can edit when they log in?
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
Which WP User plugin do you recommend?
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.
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?
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.
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.
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.
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
This is my code i put into the fields loop in my custom template, which is just a copy of the default template.
To check the name of the current field, you need to use $this->field->name
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.
What if i want to just use the standard WP user registration? How would i get the two databases to play nice?
I’ve got an article that discusses this:
Using Participants Database with WordPress Users
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)
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:
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.
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() ?>
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.
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?
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:
Very helpful. Thank you very much
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”.
Beg pardon, this is what appears as an element:
Woops, no idea why it doesn’t copy-paste! I’ll type it out this time:
input name=”user_login” type=”hidden” value=””
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.
I have tested version 1.7.5, 126.96.36.199 and 188.8.131.52 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.
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!!
It was the PHP plugin all along? Well that’s certainly good news! Thanks for keeping us in the loop.
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.
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.