christianwach / civicrm-wp-profile-sync

Keeps a WordPress User profile in sync with a CiviCRM Contact and integrates WordPress and CiviCRM Entities with data synced via Advanced Custom Fields.
https://wordpress.org/plugins/civicrm-wp-profile-sync/
GNU General Public License v2.0
13 stars 17 forks source link

CiviCRM Profile Sync will remove CiviCRM Contact First Name and Last Name if WordPress User fields are not set #32

Open agileware-justin opened 2 years ago

agileware-justin commented 2 years ago

CiviCRM Profile Sync will remove CiviCRM Contact First Name and Last Name if WordPress User fields are not set.

Agileware Ref: CIVIWPSYNC-1

christianwach commented 2 years ago

Thanks for this @agileware-justin - could you make the PR conform to WordPress coding standards as per the phpcs.xml file? It's currently CiviCRM formatted. Cheers!

christianwach commented 2 years ago

@agileware-justin Hmm, so it doesn't seem to be true that both "First Name" and "Last Name" are required by CiviCRM. I can see that you don't want to lose data in CiviCRM, but I don't think this is the way to go about that. You can use the cwps/contact/name/should_be_synced filter to inspect the proposed update and reject those with less data than your install requires.

A full solution might involve an option on the Settings screen that allows a policy to be chosen, but I suspect these could get complicated. I think documentation with some example code might help.

agileware-justin commented 2 years ago

@christianwach thanks for reviewing. This PR arose from a support request whereby a customer had added ~2,000 new WordPress user accounts to their site. Those user accounts only had the email address set.

When the profile sync process ran, the existing CiviCRM contacts matching those WordPress user accounts lost their first and last names.

Consequently, there was no longer any record of this information either in WordPress or CiviCRM. CiviCRM logging was not enabled.

CiviCRM database needed to be restored from backup, contacts exported and re-imported.

If anything, this PR was to highlight that this problem can occur.

christianwach commented 2 years ago

@agileware-justin Yes, I fully understand the problem - I just can't see a way to accommodate the range of needs in this plugin. There may be cases where overwriting with empty values in either direction is the desired behaviour. There may be cases where it's not. That's why I suggested using the filter - sync policies are much easier to implement on a site-by-site basis than though a UI or "one size fits all" solution.

I'm open to suggestions on how to implement such policies via the UI, of course. And also happy to accept updates to the readme files to illustrate how to write policies in code. Sorry I can't be more helpful at this point.

tresero commented 1 year ago

I am having this exact problem. We have 25k+ civi contacts and are allowing them to update their own data. The only way to do this as far as I'm aware is for them to register. Even if I add the First Name and Last Name fields to the registration form, this plugin overwrites the name with email.

I know the cases can get crazy, but I think that first and last names are very important and an easy solution is have a flag that says don't overwrite first/last names?

christianwach commented 11 months ago

@tresero It's not as simple as having a flag though. Consider this scenario:

I would love to find a general solution to this, but I really think that it's a per-site task using the filters I mentioned above.

christianwach commented 11 months ago

Even if I add the First Name and Last Name fields to the registration form, this plugin overwrites the name with email.

@tresero Can you post steps to reproduce? I'd be interested to see this in action.