wpmu_welcome_user_notification

函式
wpmu_welcome_user_notification ( $user_id, $password, $meta = array() )
引數
  • (int) $user_id User ID.
    Required:
  • (string) $password User password.
    Required:
  • (array) $meta Optional. Signup meta data. Default empty array.
    Required:
    Default: array()
返回值
  • (bool)
定義位置
相關方法
wpmu_welcome_notificationwp_new_user_notificationwpmu_signup_user_notificationwp_send_new_user_notificationswpmu_new_site_admin_notification
引入
-
棄用
-

wpmu_welcome_user_notification: 這個函式用於WPMU安裝中,當新使用者註冊時向他們傳送歡迎郵件。它將使用者的ID和密碼作為引數,並向使用者傳送一封包含其登入資訊的郵件。

通知使用者他們的賬戶啟用已經成功。

過濾{@see ‘wpmu_welcome_user_notification’}以禁用或繞過。

過濾{@see ‘update_welcome_user_email’}和{@see ‘update_welcome_user_subject’}來修改通知郵件的內容和主題行。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) {
$current_network = get_network();
/**
* Filters whether to bypass the welcome email after user activation.
*
* Returning false disables the welcome email.
*
* @since MU (3.0.0)
*
* @param int $user_id User ID.
* @param string $password User password.
* @param array $meta Signup meta data. Default empty array.
*/
if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) {
return false;
}
$welcome_email = get_site_option( 'welcome_user_email' );
$user = get_userdata( $user_id );
$switched_locale = switch_to_locale( get_user_locale( $user ) );
/**
* Filters the content of the welcome email after user activation.
*
* Content should be formatted for transmission via wp_mail().
*
* @since MU (3.0.0)
*
* @param string $welcome_email The message body of the account activation success email.
* @param int $user_id User ID.
* @param string $password User password.
* @param array $meta Signup meta data. Default empty array.
*/
$welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta );
$welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email );
$welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
$welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
$welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email );
$admin_email = get_site_option( 'admin_email' );
if ( '' === $admin_email ) {
$admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST );
}
$from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress';
$message_headers = "From: "{$from_name}" <{$admin_email}>n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . ""n";
$message = $welcome_email;
if ( empty( $current_network->site_name ) ) {
$current_network->site_name = 'WordPress';
}
/* translators: New user notification email subject. 1: Network title, 2: New user login. */
$subject = __( 'New %1$s User: %2$s' );
/**
* Filters the subject of the welcome email after user activation.
*
* @since MU (3.0.0)
*
* @param string $subject Subject of the email.
*/
$subject = apply_filters( 'update_welcome_user_subject', sprintf( $subject, $current_network->site_name, $user->user_login ) );
wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
if ( $switched_locale ) {
restore_previous_locale();
}
return true;
}
function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) { $current_network = get_network(); /** * Filters whether to bypass the welcome email after user activation. * * Returning false disables the welcome email. * * @since MU (3.0.0) * * @param int $user_id User ID. * @param string $password User password. * @param array $meta Signup meta data. Default empty array. */ if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) { return false; } $welcome_email = get_site_option( 'welcome_user_email' ); $user = get_userdata( $user_id ); $switched_locale = switch_to_locale( get_user_locale( $user ) ); /** * Filters the content of the welcome email after user activation. * * Content should be formatted for transmission via wp_mail(). * * @since MU (3.0.0) * * @param string $welcome_email The message body of the account activation success email. * @param int $user_id User ID. * @param string $password User password. * @param array $meta Signup meta data. Default empty array. */ $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta ); $welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email ); $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); $welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email ); $admin_email = get_site_option( 'admin_email' ); if ( '' === $admin_email ) { $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); } $from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; $message_headers = "From: "{$from_name}" <{$admin_email}>n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . ""n"; $message = $welcome_email; if ( empty( $current_network->site_name ) ) { $current_network->site_name = 'WordPress'; } /* translators: New user notification email subject. 1: Network title, 2: New user login. */ $subject = __( 'New %1$s User: %2$s' ); /** * Filters the subject of the welcome email after user activation. * * @since MU (3.0.0) * * @param string $subject Subject of the email. */ $subject = apply_filters( 'update_welcome_user_subject', sprintf( $subject, $current_network->site_name, $user->user_login ) ); wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); if ( $switched_locale ) { restore_previous_locale(); } return true; }
function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) {
	$current_network = get_network();

	/**
	 * Filters whether to bypass the welcome email after user activation.
	 *
	 * Returning false disables the welcome email.
	 *
	 * @since MU (3.0.0)
	 *
	 * @param int    $user_id  User ID.
	 * @param string $password User password.
	 * @param array  $meta     Signup meta data. Default empty array.
	 */
	if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) {
		return false;
	}

	$welcome_email = get_site_option( 'welcome_user_email' );

	$user = get_userdata( $user_id );

	$switched_locale = switch_to_locale( get_user_locale( $user ) );

	/**
	 * Filters the content of the welcome email after user activation.
	 *
	 * Content should be formatted for transmission via wp_mail().
	 *
	 * @since MU (3.0.0)
	 *
	 * @param string $welcome_email The message body of the account activation success email.
	 * @param int    $user_id       User ID.
	 * @param string $password      User password.
	 * @param array  $meta          Signup meta data. Default empty array.
	 */
	$welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta );
	$welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email );
	$welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
	$welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
	$welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email );

	$admin_email = get_site_option( 'admin_email' );

	if ( '' === $admin_email ) {
		$admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST );
	}

	$from_name       = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress';
	$message_headers = "From: "{$from_name}" <{$admin_email}>n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . ""n";
	$message         = $welcome_email;

	if ( empty( $current_network->site_name ) ) {
		$current_network->site_name = 'WordPress';
	}

	/* translators: New user notification email subject. 1: Network title, 2: New user login. */
	$subject = __( 'New %1$s User: %2$s' );

	/**
	 * Filters the subject of the welcome email after user activation.
	 *
	 * @since MU (3.0.0)
	 *
	 * @param string $subject Subject of the email.
	 */
	$subject = apply_filters( 'update_welcome_user_subject', sprintf( $subject, $current_network->site_name, $user->user_login ) );

	wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );

	if ( $switched_locale ) {
		restore_previous_locale();
	}

	return true;
}

常見問題

FAQs
檢視更多 >