Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command for "create user record"? #188

Open
kenahoo opened this issue Feb 20, 2024 · 1 comment
Open

Command for "create user record"? #188

kenahoo opened this issue Feb 20, 2024 · 1 comment

Comments

@kenahoo
Copy link

kenahoo commented Feb 20, 2024

Is there a cv command for "Create User Record", to create a WordPress/Drupal user for a given CiviCRM contact? It would be very convenient if so!

@MegaphoneJon
Copy link
Contributor

MegaphoneJon commented Feb 20, 2024

There's not one built in, but you could probably write a one-liner. Something like this for contact 333:

cv ev '$contact = civicrm_api3("Contact", "getsingle", ["id" => 333]); $contact["cms_name"] = $contact["display_name"]; CRM_Core_BAO_CMSUser::create($contact, "email")'

That's 3 PHP statements. The first makes an API call based on the ID 333 to get that contact's info. Second, we set the CMS username to the contact's display name (could also be, e.g., $contact["email"] and not $contact["display_name"]). The third command creates the CMS user.

Note that this doesn't actually connect the user to the Civi record, but that will happen when they first log in. If you need that ahead of time, you'll have to figure that part out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants