Last active
June 27, 2019 22:38
-
-
Save SeanChDavis/7066363ede1e3e092d5103dcb60ca1f3 to your computer and use it in GitHub Desktop.
EDD Edit New User Notification Login URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // DO NOT COPY THIS LINE. COPY THE 3 SECTIONS BELOW ... THEY ALL WORK TOGETHER. | |
/** | |
* EDD core uses a custom function called edd_new_user_notification() to build the | |
* email template used for new user notification emails. So first, we need to tell | |
* EDD core to STOP using that function. | |
*/ | |
function custom_remove_new_user_notification() { | |
remove_action( 'edd_insert_user', 'edd_new_user_notification', 10, 2 ); | |
} | |
add_action( 'init', 'custom_remove_new_user_notification' ); | |
/** | |
* With the above in place, EDD core no longer has an email template to use when | |
* sending the email notification. So, we're building a replacement function. We | |
* have to slightly change the name to avoid a PHP error. With this function in | |
* place, and accessible, we are free to customize it using PHP. | |
*/ | |
function custom_edd_new_user_notification( $user_id = 0, $user_data = array() ) { | |
if( empty( $user_id ) || empty( $user_data ) ) { | |
return; | |
} | |
$emails = EDD()->emails; | |
$from_name = edd_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); | |
$from_email = edd_get_option( 'from_email', get_bloginfo( 'admin_email' ) ); | |
// Setup and send the new user email for Admins. | |
$emails->__set( 'from_name', $from_name ); | |
$emails->__set( 'from_email', $from_email ); | |
$admin_subject = apply_filters( 'edd_user_registration_admin_email_subject', sprintf( __('[%s] New User Registration', 'easy-digital-downloads' ), $from_name ), $user_data ); | |
$admin_heading = apply_filters( 'edd_user_registration_admin_email_heading', __( 'New user registration', 'easy-digital-downloads' ), $user_data ); | |
$admin_message = sprintf( __( 'Username: %s', 'easy-digital-downloads'), $user_data['user_login'] ) . "\r\n\r\n"; | |
$admin_message .= sprintf( __( 'E-mail: %s', 'easy-digital-downloads'), $user_data['user_email'] ) . "\r\n"; | |
$admin_message = apply_filters( 'edd_user_registration_admin_email_message', $admin_message, $user_data ); | |
$emails->__set( 'heading', $admin_heading ); | |
$emails->send( get_option( 'admin_email' ), $admin_subject, $admin_message ); | |
// Setup and send the new user email for the end user. | |
$user_subject = apply_filters( 'edd_user_registration_email_subject', sprintf( __( '[%s] Your username and password', 'easy-digital-downloads' ), $from_name ), $user_data ); | |
$user_heading = apply_filters( 'edd_user_registration_email_heading', __( 'Your account info', 'easy-digital-downloads' ), $user_data ); | |
$user_message = apply_filters( 'edd_user_registration_email_username', sprintf( __( 'Username: %s', 'easy-digital-downloads' ), $user_data['user_login'] ) . "\r\n", $user_data ); | |
if ( did_action( 'edd_pre_process_purchase' ) ) { | |
$password_message = __( 'Password entered at checkout', 'easy-digital-downloads' ); | |
} else { | |
$password_message = __( 'Password entered at registration', 'easy-digital-downloads' ); | |
} | |
$user_message .= apply_filters( 'edd_user_registration_email_password', sprintf( __( 'Password: %s', 'easy-digital-downloads' ), '[' . $password_message . ']' ) . "\r\n" ); | |
$login_url = apply_filters( 'edd_user_registration_email_login_url', wp_login_url() ); | |
if( $emails->html ) { | |
$user_message .= '<a href="' . $login_url . '"> ' . esc_attr__( 'Click here to log in', 'easy-digital-downloads' ) . ' »</a>' . "\r\n"; | |
} else { | |
$user_message .= sprintf( __( 'To log in, visit: %s', 'easy-digital-downloads' ), $login_url ) . "\r\n"; | |
} | |
$user_message = apply_filters( 'edd_user_registration_email_message', $user_message, $user_data ); | |
$emails->__set( 'heading', $user_heading ); | |
$emails->send( $user_data['user_email'], $user_subject, $user_message ); | |
} | |
/** | |
* Now that we have the custom function just the way we like it, let's tell EDD | |
* core to use the new, custom function. Now when a new user is inserted, and this | |
* email is sent, it will use the template from the custom function above. | |
*/ | |
add_action( 'edd_insert_user', 'custom_edd_new_user_notification', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment