Notify admin when page is edited?

You can register TheDeadMedic’s function to fire on the save_post action, which runs every time a post is saved, regardless of whether or not the status changed.

add_action( 'save_post', '__notify_admin_on_publish', 10, 3 );

Then, comment out these lines in his function:

//if ( $new_status != 'publish' || $old_status == 'publish' )
        //return;

To prevent getting an e-mail for autosaves, add this code to the top of the function:

global $post;
if( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || $post->post_status == 'auto-draft' )
    return;

Here’s the fully merged code:

<?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 );

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)