您可以注册TheDeadMedic\'s function 向…开火save_post
操作,无论状态是否更改,都会在每次保存帖子时运行。
add_action( \'save_post\', \'__notify_admin_on_publish\', 10, 3 );
然后,在他的函数中注释掉以下几行:
//if ( $new_status != \'publish\' || $old_status == \'publish\' )
//return;
要防止收到自动保存的电子邮件,请在函数顶部添加以下代码:
global $post;
if( ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE ) || $post->post_status == \'auto-draft\' )
return;
以下是完全合并的代码:
<?php
function __notify_admin_on_publish( $new_status, $old_status, $post )
{
global $post;
if( ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE ) || $post->post_status == \'auto-draft\' )
return;
$message = \'View it: \' . get_permalink( $post->ID ) . "\\nEdit it: " . get_edit_post_link( $post->ID );
if ( $post_type = get_post_type_object( $post->post_type ) )
wp_mail( get_option( \'admin_email\' ), \'New \' . $post_type->labels->singular_name, $message );
}
add_action( \'save_post\', \'__notify_admin_on_publish\', 10, 3 );