我发现这段代码非常适合在帖子更新时通知管理员,但这让管理员很恼火,因为她收到了所有更新的电子邮件,而她只需要等待的帖子的通知。我不知道怎么做。
以下是我目前的代码:
add_action( \'save_post\', \'my_project_updated_send_email\' );
function my_project_updated_send_email( $post_id ) {
//verify post is not a revision
if ( !wp_is_post_revision( $post_id ) ) {
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = \'A post has been updated\';
$message = "A post has been updated on your website:\\n\\n";
$message .= "<a href=\'". $post_url. "\'>" .$post_title. "</a>\\n\\n";
//send email to admin
wp_mail( \'[email protected]\', $subject, $message );
}
}
我试过换衣服
add_action(\'save_post\'
到add_action(\'on_publish_pending_post\'
但那没用。我试着“等待”,但没有成功。我有点卡住了。
SO网友:MrFox
我做了更多的研究,这就是我现在的工作。
管理员只有在添加或更新挂起的帖子时才会得到更新。
add_action( \'transition_post_status\', \'pending_post_status\', 10, 3 );
function pending_post_status( $new_status, $old_status, $post ) {
if ( $new_status === "pending" ) {
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = \'A post has been updated\';
$message = "A post has been updated on your website:\\n\\n";
$message .= "<a href=\'". $post_url. "\'>" .$post_title. "</a>\\n\\n";
//send email to admin
wp_mail( \'[email protected]\' , $subject, $message );
}
}