Fire sync on WP_User::add_role
-
Hi there,
Thoroughly impressed with and grateful for your plugin. Thank you.
We have a situation where we want to sync between sites when we add a role, e.g. using:
$user->add_role( 'my_role' );
Our initial testing indicates that this is not supported with your plugin out of the box, i.e. the user is getting the new secondary user role on the site where we do this just fine, but our second site doesn’t sync added user role. (Whereas it seems to just fine for changes made through code to the primary user role and for all changes made on the backend through https://educatorspro.com/wp-admin/user-edit.php)
Is that right?
And, if so, could you guide us on how to go about it?
Would something like this work to force a profile_update and your Wprus_Api_Update syncing along with it?
add_action( 'add_user_role', 'force_profile_update_upon_user_add_role', 20, 2 ); function force_profile_update_upon_user_add_role( $user_id, $role ) { if( $role == 'my_role' ) do_action('profile_update', $user_id, get_userdata( $user_id ) ); }
Or, would it be better to try and extend (one of) your class(es) in order to have it fire on WP_User::add_role? e.g.:
public function init_notification_hooks() { add_action( 'add_user_role', array( $this, 'notify_remote' ), PHP_INT_MAX, 2 ); }
The former seemed less attractive because of the possibly increased load each time a role is added, but the latter seemed less attractive because of wanting to avoid having to maintain any code that’s different from your core code.
All that said, we are running a custom plugin and can easily make changes there.
Thank you very much for your guidance.
Also, I noticed your comment about offering support only for general enquiries and bug fixes. Don’t hesitate to advise if this doesn’t fall into that. Want to respect your terms and time. And happy to engage as you wish.
Alex.
- The topic ‘Fire sync on WP_User::add_role’ is closed to new replies.