Skip Navigation

[Resolved] Front-end user management

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 1 voice.

Last updated by Marcel 1 week, 2 days ago.

Assisted by: Minesh.

Author
Posts
#2801249

My client wants a front-end user management system. For that, I need to query some data I can't select from the UI.

- The user role: I tried [wpv-user field="roles"] but that doesn't seem to work
- The activity of the user: the client would like the number of times the user logged in, but I think the last login date is fine too
- User data: a link to a page with all the data for a specific user, and a form to edit those date front-end for any user (instead of just the logged-in one)

I've created a classic view and used the table format, but the fields "first name" and "last name" aren't sortable.

#2801250

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

- The user role: I tried [wpv-user field="roles"] but that doesn't seem to work
==>
Do you mean the current loggedin user role? if yes:
You can use the [wpv-current-user info='role'] shortcode
-- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-153354

- The activity of the user: the client would like the number of times the user logged in, but I think the last login date is fine too
===>
There is no such feature available to record the activity of user. You may check for plugins available on wordpress.org

- User data: a link to a page with all the data for a specific user, and a form to edit those date front-end for any user (instead of just the logged-in one)
===>
You can create custom user profiles
-- https://toolset.com/2022/12/how-to-let-wordpress-users-create-their-own-profiles-in-your-people-directory/#create-public-profiles-with-toolset
-- https://toolset.com/documentation/customizing-sites-using-php/creating-custom-user-profiles/

You can even create edit user form:
-- https://toolset.com/course-lesson/using-forms-to-create-an-edit-your-profile-page/

I've created a classic view and used the table format, but the fields "first name" and "last name" aren't sortable.
===>
You can build the custom search with sorting for post type views not the user type views.

#2801278

The user role: I tried [wpv-user field="roles"] but that doesn't seem to work
==>
Do you mean the current loggedin user role? if yes:
You can use the [wpv-current-user info='role'] shortcode
-- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-153354

-------------------------------------------------------------------------------------------------------------------------------------
No. I'm listing all users, and I need to show their user role in that list. I can query it with Greenshifts repeater builder, so it can be queried.
--------------------------------------------------------------------------------------------------------------------------------------

- The activity of the user: the client would like the number of times the user logged in, but I think the last login date is fine too
===>
There is no such feature available to record the activity of user. You may check for plugins available on wordpress.org

--------------------------------------------------------------------------------------------------------------------------------------
Again, I can query the last login date with Greenshifts repeater builder so it should be possible
--------------------------------------------------------------------------------------------------------------------------------------

#2801366

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

So, you found the solution or where exactly you require the help?

#2801367

No I didn't find a solution. Greenshift lacks some other things I need so I need to do this in Toolset. What I meant is that if I can query certain data with Greenshift, I should be able to query that data with Toolset too.

And I'm still not clear on how to build a front-end user edit form that can be used by admins for all users. I can only seem to edit my own data, so only for the currently logged-in user.

#2801465

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I can not say anything whats possible for now.

If you can share your whole requirement and access details and tell me what exactly you want to dislay where I can guide you in the right direction.

I can easily guide you to create view for users and edit user form but then you will have to check how you can query certain data with Greenshift.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2801546

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry but I'm still confuse where you get stuck.

I see the view you created is working. We can not offer support to customize the things as per client requiirement as it may need customization and custom code that is beyond the scope of our support policy.

I can help you to get user role displayed.

To display the user role I've added the following custom shortcode to "Custom Code" section offered by Toolset with the code snippet namely "toolset-custom-code":
=> hidden link

add_shortcode('get_user_role', 'func_get_user_role');
function func_get_user_role($atts, $content){
    $atts = shortcode_atts( array(
          'user_id' => 0,
    ), $atts );
    $user = new WP_User( $atts['user_id'] );
    $arr = array();
    if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
        foreach ( $user->roles as $role )
            $arr[] = $role;
    }
    $res = implode(', ', $arr);
    return $res;
}

And I've called the above shortcode within your following view where I've added new column "User Role":
=> hidden link

<td>[get_user_role user_id="[wpv-user field='ID']"]</td>

This way you can display the user role.

#2801552

Thank you for this. The most important thing however is that my client wants to be able to edit the user info from the front-end.

So for example on hidden link, you see a link "gegevens aanpassen". This links to a post form to edit the ships info.

Below that, you see a heading "Gegevens eigenaar". That's the owner of the ship. In this case, his name is Nelson A. He is the post author. I added a link "gegevens aanpassen" for that too, which leads to a front-end user edit form. But when I click on it, I can only edit my own user data. I want to edit the user data for Nelson A.

#2801635

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

With the single post content template where you added the link to edit the user profile:
- hidden link

I've chagned the link code as given under:

<a href="<em><u>hidden link</u></em> format='meta' meta='ID']">Gegevens aanpassen</a>

As you can see I've passed the URL param "user_id" and the value is coming from the shortcode:

[wpv-post-author format='meta' meta='ID']

Now, on the following post under section "Gegevens eigenaar" when I click on the link "Gegevens aanpassen"
=> hidden link

It redirect me on the following URL and I can see the correct information on the user edit form.
=> hidden link

#2801638

That's great, thank you! Do also have a way to display the last login date?

#2801645

Oh, and under the "sinds" column, the date is displayed with the time. How can I only display the date in this format, without the time?

#2801674

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added the following shortcode to "Custom Code" section with the code snippet "toolset-custom-code" display the last login date:
=> hidden link

add_shortcode('show_last_login_date', 'func_show_last_login_date_wordfence_security');
function func_show_last_login_date_wordfence_security($atts, $content){
    $atts = shortcode_atts( array(
          'last_login_timestamp' => 0,
          
    ), $atts );
    
 
    if(isset($atts['last_login_timestamp']) and $atts['last_login_timestamp']!=''){
        setlocale(LC_TIME, 'nl_NL');
		return strftime('%A, %B %d, %Y', $atts['last_login_timestamp']);
       
    }else{
      return 0;
    }
    
    
}

And within your view I've added the column "Last Login" and display it as given under:
=> hidden link

<td>[show_last_login_date last_login_timestamp="[wpv-user field='wfls-last-login']"]</td>

I would like to mention here all this is custom code and which is beyond the scope of our support policy. If you need further help with any of such query you are welcome to contact any of our certified partners:
- https://toolset.com/contractors/

#2801706

Hi Minesh,

Thank you for your trouble. I didn't expect to need custom code for this to be honest, I expected there would just be a standard shortcode for this that I didn't find in the documentation.

Best regards,

Marcel