Skip Navigation

[Resolved] ACCESS Form

This support ticket is created 3 years, 9 months 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 7 replies, has 2 voices.

Last updated by acts-1224C 3 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1995449

I have a membership site. I have few site managers each providing me with single tasks. I want to avoid allowing these managers access to the backend.

This is my need

I have many users under the role "subscriber", and from time to time there is a large group to move from subscriber to author.
is it possible to promote the user from "subscriber" role to "author" role in the frontend using access form, without the need for my managers to login into the my dashboard backend ?

Thanks

#1995775

Hi,

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

As there is no built-in option available in the user forms to change the user's role from the front-end, this is possible using some custom code.

You can create a user edit form, which only has a submit button without any actual fields. When the form is submitted, you can attach a custom function through the "cred_save_data" hook, which removes the "subscriber" role and assigns the "author" role to the user who is being edited with the form.
( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data )

You'll find a good usage example for a similar requirement in this reply:
https://toolset.com/forums/topic/is-it-possible-to-change-user-role-using-front-end-form/#post-1503479

regards,
Waqar

#2001809

Hello Waqar, thanks for your reply. In following your suggested documentation https://toolset.com/forums/topic/is-it-possible-to-change-user-role-using-front-end-form/#post-1503479 where other toolset developers had similar request

I took these steps:

I created a form to edit user with the intent to promote from "subscriber" to "author" when edit form is submitted.
Saved edited form into an unassigned content template
I adjusted the access settings in the forms tab and allowing my manager with credentials to edit/promote users.
I created the following snippet code in toolset>settings>custom code area and activated it.
I copied the form ID and added it to the snippet code.

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'] == 870) {
// modify the user role to match the selected option
$u = new WP_User( $user_id );
$u->remove_role( 'subscriber' ); /// adjust role name here if needed
$u->add_role( 'author' );
}
}

When testing the form as manger with proper credentials to edit, I got an error message "The user was not saved because of the following problem:
This form can not edit users with a role of subscriber "

Also, when I tried to use the form as administrator, it copied the current user login ID and displayed in the form without the option to change it. If I submitted it my credentials as admin would have switched to author as well. Somehow the code needed to have a function not allowing to self promote for that matter.

I don't know what else I should be doing, or if I missed a step using the hook function code.

Thanks

Miller

#2004269

Thank you for sharing these details, but I couldn't reproduce this on my test website.

Can you share temporary admin login details, so that I can see how this form is set up in the admin area?

Please also share the link to an example page where this user edit form can be seen.

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

#2006985

Thank you for sharing the admin access details.

Just wanted to update you that I'm currently running some tests on my website with a similar form.

I'll update you with my findings, as soon as this testing completes.

Thank you for your patience.

#2007495

Thanks Waqar for looking into this. Take your time. But I really needed that functionality to work. I appreciate your time.

Thanks

#2016051

Hi,

Thank you for waiting as this investigation took longer than I initially expected.

During testing on my website with similar settings and custom code, the form worked.

After further debugging on your website, I was able to make the edit form work, by making these 2 changes:

1. In the "Promote User to Author - User Form" settings, I selected the "Subscriber" role, instead of "Author", since, before the form's submission, the user's role is "Subscriber".
( screenshot: hidden link )

This fixed the message about the incorrect user role being edited by the form.

2. The next challenge was that the custom function to change the user role was not executing with the form submission. I noticed that in the custom code snippet's settings, the "Run mode" was set to "On demand" and not "Run Always".
( screenshot: hidden link )

Changing the run mode to always fixed the code's execution and I apologize, I should've caught this sooner.

regards,
Waqar

#2016569

My issue is resolved now. Thank you!

Thanks Waqar,

For me it did not take much time as I waited. It is paid off with the results. I am sure this will also help others since this feature adds value to the toolset functionalities as a whole. The idea of being able to perform in the front end is what differentiates TOOLSET from all other plugins.

Thanks Toolset team!