Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ); 
    }
share|improve this question

1 Answer 1

I believe Front End Editor calls wp_update_post, which in turn calls wp_insert_post. You should be able to hook either save_post or wp_insert_post for new/updated posts, and edit_post or post_updated for updated posts.

share|improve this answer
    
Thanks @Milo! They all work ok when updating using FEE, sending the email, but no data is being passed through : ( –  sta777 Dec 4 '12 at 17:33
    
have a look at the actions in source, the format of the arguments may differ between actions –  Milo Dec 4 '12 at 17:38
    
Thanks @Milo. Ended up adding code directly to the plugin - see above. –  sta777 Dec 5 '12 at 11:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.