Skip Navigation

[Resuelto] Disabling Multiple Roles

This support ticket is created hace 2 años, 7 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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/Hong_Kong (GMT+08:00)

Este tema contiene 5 respuestas, tiene 3 mensajes.

Última actualización por Luo Yang hace 2 años, 7 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#2323963

I am running into an issue with one of my integrations because Toolset is allowing multiple user roles to be set. Is there a way to disable this feature so that WordPress reverts to its default condition of only allowing users to have one role? Thanks.

-- Aaron

#2324067

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi Aaron

When this feature was added, it didn't include any way to disable it I'm afraid.

The problem is specifically that users can edit their profile in the back end and Access adds the option to assign additional roles?

If that is where the problem arises then it is possible to unhook the code responsible for adding the link to add additional roles, like so:

add_action( 'wp_loaded', function(){

	$backend_filters = \OTGS\Toolset\Access\Controllers\Filters\BackendFilters::get_instance();
	remove_action( 'personal_options', array( $backend_filters, 'show_user_roles' ) );

});
#2324071

The issue is that I am using the wpFusion plugin in conjunction with Active Campaign (our CRM) to synchronize user data. There are certain automations that run in our CRM that may trigger role changes in the website. Active Campaign uses a webhook to send an API call to wpFusion, which then updates the user role. However, it seems to be adding the role instead of replacing the role. Their support has told me it's because Toolset is allowing multiple roles. I wonder if there is a code snippet we can use to remove any existing roles immediately before a new role is applied? Let me know any ideas you may have. Thanks.

-- Aaron

#2324533

You can try WordPress "set_role" method of WP class "WP_User", for example:

// NOTE: Of course change 3 to the appropriate user ID
$wpUser = new WP_User( 3 );

// set role
$wpUser->set_role('my_own_role')

More help:
https://developer.wordpress.org/reference/classes/wp_user/set_role/

#2325019

Unfortunately I don't have control over what wpFusion does with their code. I just had another idea, though. Can you tell me if there is a Toolset hook that fires when a custom field's value is updated? I could create a custom field called 'wpcf-active-role' that gets updated by wpFusion, and then when that field gets updated I could run a code snippet that sets the actual WordPress role to that same value.

-- Aaron

#2325515

There is a misunderstanding, according to your description above, it seems that the "wpFusion" plugin is using add_role() to setup the user role value, it will conducts the problem, see WP document:
https://developer.wordpress.org/reference/classes/wp_user/add_role/
Add role to user.

You need to fix the problem in wpFusion plugin side, it should be able to use set_role() to update user's role, this method will delete user's role value, and update with new user role value

For the new question:
Can you tell me if there is a Toolset hook that fires when a custom field's value is updated?

You can try the WP built-in action hook:
update_(meta_type)_meta
See WP document:
https://codex.wordpress.org/Plugin_API/Action_Reference
update_(meta_type)_meta
Runs when a metadata gets saved.