我试图在用户更新页面/帖子时发送通知电子邮件,无论是在后端还是通过使用Front-End Editor.
它在后端更新时工作正常,但在使用前端编辑器更新时不会通过电子邮件发送数据。有人对此有什么想法吗?
function __test_on_publish( $post )
{
global $post;
if( ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE ) || $post->post_status == \'auto-draft\' )
return;
if ( !wp_is_post_revision( $post ) ) {
$post_title = get_the_title( $post );
$post_url = get_permalink( $post );
$aid = $post->post_author;
$user_email = get_the_author_meta(\'user_nicename\', $aid);
$subject = \'A page has been updated\';
$message = "A page has been updated on " . get_bloginfo( \'name\' ). " by ".$user_email."\\n\\n";
$message .= $post_title. "\\n\\nView it: " . get_permalink( $post ) . "\\n\\nEdit it: " . get_edit_post_link( $post ). "\\n\\n";
//send email to admin
wp_mail( get_option( \'admin_email\' ), $subject, $message );
}
}
add_action( \'pre_post_update\', \'__test_on_publish\', 10, 3 );
Edit: 我最终在帖子中直接添加了一些wp\\u邮件功能。前端编辑器的php文件,似乎运行良好(见下文)。
function save( $data, $content ) {
/--- some original code omitted ---/
wp_update_post( (object) $postdata );
//// added ////
$post_title = get_the_title( $post_id );
$post_tmp = get_post( $post_id );
$aid = $post_tmp->post_author;
$user_email = get_the_author_meta(\'user_nicename\', $aid);
$subject = \'A page has been updated by \'.$user_email;
$message = "A page has been updated on " . get_bloginfo( \'name\' ). " by ".$user_email."\\n\\n";
$message .= $post_title. "\\n\\nView it: " . get_permalink( $post_id ) . "\\n\\nEdit it: " . get_edit_post_link( $post_id ). "\\n\\n";
wp_mail( get_option( \'admin_email\' ), $subject, $message );
}