公认的答案在2021对我来说并不适用。我怀疑动作挂钩名称已更改。
以下是对我有效的更新解决方案:
function newpost_notify( $auto ) {
$mailadmin = \'[email protected]\';
$subject = \'Subject\';
$headers = \'MIME-Version: 1.0\' . "\\r\\n";
$headers .= \'Content-type: text/html; charset=UTF-8\' . "\\r\\n";
$headers .= \'From: xxx <[email protected]>\' . "\\r\\n";
$message = \'There\\\'s a new post.\';
wp_mail( $mailadmin, $subject, $message, $headers );
}
add_action( \'pending_auto\', \'newpost_notify\', 10, 2 );
Note that the action name is dynamic, so you will need to adjust the first argument of add_action
to match your custom post_type. 格式为{status}{postType}。
还要注意,传递给回调函数的参数是新post的post ID(不是WP\\U post的实例)。