• Hello. Great plugin!

    I have a small issue and I didn’t find any actual info on how to solve it. I have 2 websites, that are already in sync, which works great. On one of the websites, I had to add a script that for some users changed their role. the script is outside of WP, but it uses this to change the role:

    $userData = new WP_User( $user_id );

        $userData->remove_role( ‘subscriber’ );

        $userData->add_role( ‘non_subscriber’ );

    The issue is that it doesn’t change on the other website. Note that I need to do this for a couple of hundred users. Question: is there any way to trigger a sync users ? Without deleting the users and importing them again.

    Thanks in advance.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Alexandre Froger

    (@frogerme)

    Hello!

    WPRUS synchronises the roles when the following WordPress actions are triggered (registered in Wprus_Api_Update and calling Wprus_Api_Role::handle_notify_remote_data( $data, $site, $user )):

    add_action( 'profile_update', array( $this, 'track_updates' ), PHP_INT_MAX - 100, 1 );
    add_action( 'add_user_role', array( $this, 'track_updates' ), PHP_INT_MAX - 100, 1 );
    add_action( 'remove_user_role', array( $this, 'track_updates' ), PHP_INT_MAX - 100, 1 );
    add_action( 'set_user_role', array( $this, 'track_updates' ), PHP_INT_MAX - 100, 1 );
    add_action( 'wp_update_user', array( $this, 'track_updates' ), PHP_INT_MAX - 100, 1 );

    So, for the synchronization to happen, one of these actions must be called via do_action somewhere in your code, either directly or by the code you are using. Which one is the most appropriate depends on your script’s logic and is out the scope of this support forum.

    However, it seems the task performed by your update script is either a one-time task, or a recurring batch operation.
    While triggering one of the WordPress actions above would work in theory, running the sync for 200+ users would fire an equal number of requests, all at once. WPRUS is designed to process sync per user and in real time; this is not designed to scale for batch user operations, so it may not be ideal, and your experience may vary.

    If this is a one-time operation, I would recommend to run part of your update script on the other site instead of relying on sync. I know this is a bit out of scope, and won’t go into implementation details, but you could collect the $username of the users you updated on siteA during the process, save it somewhere, and then feed it to a similar user role update logic on siteB after retrieving the corresponding $user_id .

    Thread Starter MirceaR

    (@mircear)

    Hello and sorry for the late feedback. So here is my issue: I have the code bellow. I need that meta info to go to a website that is in sync with the one I’m executing the code in.

    function mepr_capture_stopped_sub($event) {

        $subscription = $event->get_data();

        $user = $subscription->user();

        //doing some custom stuff here

        update_user_meta($user->ID, 'custom_cr5_status', 'inactive');

        $updated_userdata = array(

            'custom_cr5_status' => 'inactive',

        );

        do_action('wp_update_user', $user->ID, $updated_userdata, $updated_userdata);  //triggered for wp remote user sync

    }

    add_action('mepr-event-subscription-stopped', 'mepr_capture_stopped_sub');
    Thread Starter MirceaR

    (@mircear)

    Btw, and sorry for the double post. we managed to single out the calls to only one…so right now we just need to make sure that user meta field is set to both websites. That code is triggered from a custom plugin.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.