函数文档

wp_send_new_user_notifications()

💡 云策文档标注

概述

wp_send_new_user_notifications() 函数用于触发新用户创建相关的电子邮件通知。它通过调用 wp_new_user_notification() 实现,支持向管理员和/或新用户发送通知。

关键要点

  • 函数触发新用户创建时的电子邮件通知,包括向站点管理员和新用户发送。
  • 接受两个参数:$user_id(必需,新用户的ID)和 $notify(可选,通知类型,默认为 'both')。
  • $notify 参数可接受 'admin'、'user' 或 'both',控制通知发送对象。
  • 自 WordPress 4.6.0 起,$notify 参数支持 'user' 值,允许仅向新用户发送通知。
  • 函数定义简单,直接调用 wp_new_user_notification() 处理核心逻辑。

代码示例

function wp_send_new_user_notifications( $user_id, $notify = 'both' ) {
	wp_new_user_notification( $user_id, null, $notify );
}

📄 原文内容

Initiates email notifications related to the creation of new users.

Description

Notifications are sent both to the site admin and to the newly created user.

Parameters

$user_idintrequired
ID of the newly created user.
$notifystringoptional
Type of notification that should happen. Accepts 'admin' or an empty string (admin only), 'user', or 'both' (admin and user).
Default 'both'.

Source

function wp_send_new_user_notifications( $user_id, $notify = 'both' ) {
	wp_new_user_notification( $user_id, null, $notify );
}

Changelog

Version Description
4.6.0 Converted the $notify parameter to accept 'user' for sending notifications only to the user created.
4.4.0 Introduced.