Custom BuddyPress email not always sending
-
I currently have an issue with trying to get a custom email to send once a user activates.
When a user does a traditional signup/activation, the email gets sent without any issues.
But when I use plugin to do sign ups via social media, this email does not get sent, and I get the following error when I capture the results of the failed email message.object(WP_Error)#6355 (2) { ["errors"]=> array(1) { ["missing_email"]=> array(1) { [0]=> string(12) "bp_get_email" } } ["error_data"]=> array(1) { ["missing_email"]=> array(2) { [0]=> string(24) "member_activated_account" [1]=> array(6) { ["no_found_rows"]=> bool(true) ["numberposts"]=> int(1) ["post_status"]=> string(7) "publish" ["post_type"]=> string(8) "bp-email" ["suppress_filters"]=> bool(false) ["tax_query"]=> array(1) { [0]=> array(3) { ["field"]=> string(4) "slug" ["taxonomy"]=> string(13) "bp-email-type" ["terms"]=> string(24) "member_activated_account" } } } } } }
My code for the custom email creation, and the code to call it is as follows:
function welcome_email_message() { // Do not create if it already exists and is not in the trash $post_exists = post_exists( '[{{{site.name}}}] Welcome to {{{site.name}}}' ); if ( $post_exists != 0 && get_post_status( $post_exists ) == 'publish' ) return; // Create post object $my_post = array( 'post_title' => __( '[{{{site.name}}}] Welcome to {{{site.name}}}', 'buddypress' ), 'post_content' => __( 'Hi {{recipient.name}}, welcome to {{site.name}}! Thankyou for signing up and helping us grow our community. {{site.name}} is a community run service which connects families with the right babysitter or nanny for them. Your new account is all set up and ready to go, you can login with the following information: Username: <strong>{{recipient.username}}</strong> This link will take you to our log in page: <a href="https://bbs4you.com/login/?login=newuser">Login</a> We need you to log in and fill in the details of your profile in order to make the most of our site. Please let us know if you have any issues using the site via the contact us page: <a href="https://bbs4you.com/contact-us/">Contact Us</a> The {{site.name}} Team', 'buddypress' ), // HTML email content. 'post_excerpt' => __( 'Hi {{recipient.firstname}}, welcome to {{site.name}}! Thankyou for signing up and helping us grow our community. {{site.name}} is a community run service which connects families with the right babysitter or nanny for them. Your new account is all set up and ready to go, you can login with the following information: Username: {{recipient.username}} This link will take you to our log in page:
Login
We need you to log in and fill in the details of your profile in order to make the most of our site. Please let us know if you have any issues using the site via the contact us page:Contact Us
The {{site.name}} Team.', 'buddypress' ), // Plain text email content. 'post_status' => 'publish', 'post_type' => bp_get_email_post_type() // this is the post type for emails ); // Insert the email post into the database $post_id = wp_insert_post( $my_post ); if ( $post_id ) { // add our email to the taxonomy term 'post_received_comment' // Email is a custom post type, therefore use wp_set_object_terms $tt_ids = wp_set_object_terms( $post_id, 'member_activated_account', bp_get_email_tax_type() ); foreach ( $tt_ids as $tt_id ) { $term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() ); wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array( 'description' => 'A member activates their account', ) ); } } } add_action( 'bp_core_install_emails', 'welcome_email_message' ); function new_member_welcome_email( $user_id, $key = false, $user = false ) { if ( $user_id) { // get the user data $user = get_userdata( $user_id ); // add tokens to parse in email $args = array( 'tokens' => array( 'site.name' => get_bloginfo( 'name' ), 'recipient.firstname' => ucfirst($user->first_name), 'recipient.username' => $user->user_login, ), ); // send args and user ID to receive email bp_send_email( 'member_activated_account', $user_id, $args ); } } add_action( 'bp_core_activated_user','new_member_welcome_email', 99, 2 );Why it works for a normal activation, and not with a OneAll social login account creation seems to confuse me, as the user_id is set and coming through from this point.
- You must be logged in to reply to this topic.