Skip Navigation

[Resolved] Display list of users on front-end

This support ticket is created 3 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 3 years ago.

Assisted by: Waqar.

Author
Posts
#2345475

Hi,

I'd like to display a list of user with a certain role on the front-end to allow to some users to view their profile clicking on the name, giving them the capability to change user role.

I try to apply some solutions without success (es. https://toolset.com/forums/topic/displaying-lists-of-members-on-the-front-end/ or this one https://toolset.com/forums/topic/display-a-filtrable-list-of-users/).

Thank you!

Moreno

#2345819

Hi Moreno,

Thank you for contacting us and I'd be happy to assist.

Can you please share temporary admin login details, along with the link to the page where you've tried to show this user list?

I'll be in a better position to guide you around any missing steps, accordingly.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2347165

Hi Waqar,

my previous issue is resolved. Here's the page where I've displayed the list of registered users with some custom fields: hidden link

I've another linked question. I'd like to put near each listed user a link opening the profile page of the selected user.

How could I display a profile page for each user with all custom user field starting from a link in the user list?

Also, I would like to allow admin users to change the user's role on the user profile page. Is it possible?

Thank you!

Moreno

#2348695

Thanks for the update and glad that you were able to create the list of users.

To show the user profile page, you can follow these steps:

1. Create a new page and name it something like "User Profile".

2. In your view to show the list of users, you can include a link to each user's profile page, using the HTML and shortcodes like this:


<a href="[wpv-post-url item='123']?id=[wpv-user field='ID']">Vedi il profilo</a>

Please replace 123 with the ID of the page "User Profile" created in step 1.

When this individual link will be clicked, the visitor will be taken to the user profile page, with the selected user's ID passed in the URL parameter 'id', for example:

{yourwebsite.com}/user-profile/?id=123
{yourwebsite.com}/user-profile/?id=456

3. In this "User Profile" page's content you can include the shortcodes for the user information and user fields as needed:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-user
https://toolset.com/documentation/customizing-sites-using-php/functions/

Note: To get the target user's ID from the URL parameter 'id', you can use the shortcode [wpv-search-term param='id'].

For example:


User First Name: [wpv-user field="user_firstname" id="[wpv-search-term param='id']"]<br>
User Last Name: [wpv-user field="user_lastname" id="[wpv-search-term param='id']"]<br>
User Email: [wpv-user field="user_email" id="[wpv-search-term param='id']"]<br>
User Custom Field: [types usermeta="user-custom field" user_id="[wpv-search-term param='id']"][/types]

And to allow the admin or specific role users to edit other user's role, you can create a new user edit form. In the form, you don't have to include any field, the "cred_save_data" hook can be used to programmatically change the user's role, when form is submitted.
( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data )


add_action('cred_save_data', 'func_update_user_role_action',10,2);
function func_update_user_role_action($user_id, $form_data) {
	if ($form_data['id'] == 12345) {
	// modify the user role to match the selected option
		$u = new WP_User( $user_id );
		$u->remove_role( 'contributor' ); // role name to remove
		$u->add_role( 'subscriber' ); // role name to add
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

In the code, you'll remove "12345" with the actual user form ID and replace 'contributor' and 'subscriber' with the actual role name to remove and add, respectively.

And in the user profile page, you can include this edit user form, using the shortcode so that the form edits the user whose ID is available in the URL parameter 'id':


[cred_user_form form='test-user-edit-form' user='[wpv-search-term param='id']']

Note: You'll replace "test-user-edit-form" with the actual name of your user form.

Important: If you're not already using the Toolset Access plugin, you'll need to activate it, to control which user roles can use this user edit form, to change the role.
( ref: https://toolset.com/lesson-placement/lesson-placements-1621521-1612073/ )