I'm trying to send a notification email when a user updates a page/post, either in the backend or by using the Front-End Editor.
It works fine when updating in the backend but no data is emailed through when updating with the Front-End Editor. Anybody have any ideas on this please?
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: I ended up adding some wp_mail functionality directly into the post.php file of Front-end Editor which seems to work well, (see below).
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 );
}