• Resolved theinnographer

    (@theinnographer)


    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter theinnographer

    (@theinnographer)

    Hi again,

    Wanted to update that updating your class-wprus-api-update.php as follows does the trick for us. Everything syncs up beautifully:

    class Wprus_Api_Update extends Wprus_Api_Abstract {
    
    	/*******************************************************************
    	 * Public methods
    	 *******************************************************************/
    
    	public function init_notification_hooks() {
    		add_action( 'profile_update', array( $this, 'notify_remote' ), PHP_INT_MAX, 2 );
    		add_action( 'add_user_role',  array( $this, 'notify_remote' ), PHP_INT_MAX, 2 ); // Added this line
    		add_action( 'remove_user_role',  array( $this, 'notify_remote' ), PHP_INT_MAX, 2 ); // Added this line
    	}
    ...

    Which is just to say that I believe it was correct to summarize our case as needing to fire on WP_User::add_role and WP_User::remove_role.

    To avoid changing the plugin files themselves, we tried to extend Wprus_Api_Abstract as you have outlined here:

    https://github.com/froger-me/wp-remote-users-sync#user-content-adding-user-actions

    Looks good and runs fine but there are no entries at all in the log. And indeed the sync doesn’t happen.

    Would be grateful for any guidance. Looking for the best / simplest way to fire on these.

    Thanks again!

    Alex.

    Plugin Author Alexandre Froger

    (@frogerme)

    Hi @theinnographer !
    Please feel free to keep the plugin files modified directly on your install for now: this is a feature I will actually include directly in the code base at next update.
    I also have to say thank you for the research you made and feedback you gave here, it make my work easier ; it is refreshing to see that there is participation in the development of this free solution.

    Thread Starter theinnographer

    (@theinnographer)

    Right on! Thank you.

    And thank you again for your plugin. We evaluated a number of paid solutions and this was significantly better suited to our needs.

    With appreciation for your work and best wishes!

    Alex.

    Plugin Author Alexandre Froger

    (@frogerme)

    Hi @theinnographer !
    Thank you for your patience ; v1.2 is out now, with the fix included. I added a subscription to set_user_role hook as well, and some condition to avoid the hooks firing multiple times.
    I’m now closing this topic ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Fire sync on WP_User::add_role’ is closed to new replies.