Closed dvhirst closed 7 years ago
Hi @dvhirst thanks for your report.
I have thought about the issue you raise and I am not persuaded that notifications are part of this plugin's core remit. There are hooks throughout the plugin which are designed to allow customisation, including the implementation of your particular use case. To be specific, you can use civi_wp_member_sync_after_insert_user
to trigger any action you require when a user is created.
If you want to use Better Notifications for WordPress, for example, then your code would look something like:
add_action( 'civi_wp_member_sync_after_insert_user', 'my_trigger_notification', 10, 2 );
function my_trigger_notification( $civi_contact, $user_id ) {
if ( ! isset( 'BNFW' ) OR ! is_object( 'BNFW' ) ) return;
$bnfw = BNFW::factory();
$bnfw->welcome_email( $user_id );
}
Note that this is untested code, but it should point you in the right direction.
Cheers, Christian
Hello, this kind of approach could be very useful to me as well, cause I need to trigger the sending of the "new user email" after the sync.
I read your note stating that civi_wp_member_sync_post_insert_user should now be used instead of civi_wp_member_sync_after_insert_user Could you please explain how the add_action code should be written for this purpose?
Thank you for your very useful plugin. Gimmy
Nevermind, it was a quite trivial question. I realized that just changing the hook name is needed.
Looking also at this good source https://wordpress.org/support/topic/wp-email-notification-email-password/ I wrote the following code, that works fine:
add_action( 'civi_wp_member_sync_post_insert_user', 'nkt_trigger_user_notification', 10, 2 );
function nkt_trigger_user_notification( $civi_contact, $user_id ) {
wp_new_user_notification( $user_id, null, 'both' );
}
@kenshir Happy to hear you solved your issue.
Christian, this is a very useful plugin and I'm mostly pleased with how it functions in my environment. I have one concern: I am creating new users / members in CiviCRM (current release) and depending on CWMS to create / sync the new user in WordPress (also current release). It does do that; what it does not do is trigger the "new user" email in WordPress. I have tested this by creating a new user in WordPress, the email from WordPress goes out as expected. When I create a new user in CiviCRM, the new user is created also in WordPress and the roles are synced (I am using role-based sync), but the new user email does not get sent. Can you suggest a way that the new user email could be triggered in WordPress or via the CWMS plugin? Note; I've tested this both with no notification plugins, and also with the Better Notifications for WordPress plugin (my preference). Behaviour is identical in both cases -- add user in WordPress, email is sent; add user / member in CiviCRM, user is synced in WordPress, but no email is sent.
Thanks for your consideration.