您不知道传递给$user 参数,让我们测试一下。
您将希望详细介绍这些条件和响应。这只是您可能想要进行的测试的一个示例。
function user_registered( $user ) {
// Check to make sure it\'s not an error.
if ( is_wp_error( $user ) ) {
return;
}
// This is how WordPress checks to make sure the user exists.
// This could also apply to many other objects, though.
if ( ! isset( $user->ID ) ) {
return;
}
// This checks to make sure you\'re getting the expected user object fields.
if ( ! isset( $user->user_email ) ) {
// If you have a correct ID, you can still retrieve the user\'s fields.
$user = get_user_by( \'ID\', $user->ID );
// If the user doesn\'t exist, stop where you are.
if ( ! $user ) {
return false;
}
}
$headers = array(
\'Content-Type: text/html; charset=UTF-8\',
\'From: WordPress Website <admin@example.com>\',
);
wp_mail( $user->user_email, \'Subject of email\', \'Email body\', $headers );
}