Support » Plugin: CiviCRM WordPress Member Sync » Does the 24 hourly sync created WP user

  • Resolved Fullworks

    (@fullworks)


    Just looking for clarification.

    The manual sync has an option, ( unticked by default ) to create non existing WP users.

    When you have the ‘Synchronize using a recurring schedule. This action is performed on all users and contacts.’ set – e.g. daily – how does that operate – will it create ‘missing’ WP users – e.g. sames as manual with the option ticked?

    • This topic was modified 1 year ago by Fullworks.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Fullworks

    (@fullworks)

    Just reading the code and the scheduled sync calls sync_all_wp_user_memberships() which explicity skips if ( ! $user->exists() ) { continue; }

    I’ll create a pull request in github to add a do action to that function.

    • This reply was modified 1 year ago by Fullworks.
    Thread Starter Fullworks

    (@fullworks)

    Actually having read the code in more detail, as ync_all_wp_user_memberships() drives off the wp users not civicrm members – I can’t see a way of doing this with simple filters / actions.

    • This reply was modified 1 year ago by Fullworks.
    Plugin Author Christian Wach

    (@needle)

    @fullworks Yes, your reading is correct. The creation of WordPress users is a “one time only” operation that happens when a CiviCRM Membership is created – or when syncing manually with the option checked. The cron/pseudo-cron sync processes only update the WordPress users roles or capabilities.

    Thread Starter Fullworks

    (@fullworks)

    OK any ideas for an easy background solution using your existing product that will add missed memberships?

    If you recall – I’m grabbing the email from a relationship – so depending on sequence that email ( or relationship) may not exist when the membership is created and so no WP user created.

    Of course, I could effectively replicate your ajax manual load code ( not sure I can use the function as is ) and then use a batch scheduler like action scheduler to background action the batches.

    Plugin Author Christian Wach

    (@needle)

    If you recall – I’m grabbing the email from a relationship – so depending on sequence that email (or relationship) may not exist when the membership is created and so no WP user created.

    @fullworks Ah yes, I had forgotten that. Can you clarify the exact requirements for a valid sync to take place? I may be able to construct something that hooks into the relevant events and triggers the process if the conditions are met.

    Thread Starter Fullworks

    (@fullworks)

    So the events would be – relationship ( id =7 ) added trigger an attempt at adding user.

    Or email added to the related record ( that didn’t have an email ) trigger an attempt at adding a user.

    I did create an action that fires on ‘civicrm_post’ to handle email changes ( based on some of your code in profile sync

    https://github.com/alanef/civi-member-sync-custom/blob/master/civi-member-sync-custom.php

    I guess the bit of the puzzle I have not got is the trigger to check / attempt to create the WP user.

    Thread Starter Fullworks

    (@fullworks)

    I think I have a solution that doesn’t require rebuilding the world.

    The issue is if the relationship or email doesn’t exist, it doesn’t create a WP user. The only bit I’m using is the email. So a solution would be to generate a random email string if the relationship/email is not there.

    OK so I’m going to get a load of extra WP users, but I already have the code that will sync the emails when / if they are eventually set up.

    Plugin Author Christian Wach

    (@needle)

    @fullworks That could work… you could use a “base” email that you own and append the random string e.g. blah+4536563@yourdomain.com so that you can capture any emails sent to that user. Please post your results here for others to find.

    Cheers, Christian

    Thread Starter Fullworks

    (@fullworks)

    Hi Christian,

    I think now I have covered all the bases

    Yes all this custom code posted on github https://github.com/alanef/civi-member-sync-custom

    I generate the random email with md5 like

    do {
        $contact_data['email'] = md5( time() ) . '@fullworks.net';
    } while ( false !== email_exists( $contact_data['email'] ) );

    Also I had also to identify Relationship changes, as if the relationship is added or changed later it needs to have look for emails – to ensure they get changed.

    Alan

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Does the 24 hourly sync created WP user’ is closed to new replies.