Custom post type without editor or revisions – Notify on update?

If you publish a post, also custom post type, the hook get form status and post_type – {$new_status}_{$post->post_type} – is active and you can use this hook for send an mail. As an examaple for publish music: add_action('publish_music', 'fb_my_function');
You can also send the revision inside the mail, the revision is only a other post type and can get from the database and add to the message of the mail.
Maybe you can see the possibilities on my last plugin, send mails for comments and posts.

An simple example for custom post type “Archive”

public $post_type_1 = 'archiv';

add_action( 'publish_' . $this -> post_type_1, array( $this, 'fb_my_function') );

        public function fb_my_function( $post_id = FALSE ) {

            if ( $post_id ) {
                // get data from current post
                $post_data = get_post( $post_id );
                //var_dump($post_data);exit; <-- see this for all content or use the id for get the revisons

                // get mail from author
                $user_mail = get_userdata( $post_data -> post_author );

                // email addresses
                $to = '[email protected]'
                // email subject
                $subject = get_option( 'blogname' ) . ': ' . $post_data -> post_title;
                // message content
                $message = $post_data -> post_content . ' ' . PHP_EOL .  
                    get_author_name( $post_data -> post_author ) . ' ' . PHP_EOL . . 
                    get_permalink( $post_id );
                // create header data
                $headers="From: " . 
                    get_author_name( $post_data -> post_author ) . 
                    ' (' . get_option( 'blogname' ) . ')' . 
                    ' <' . $user_mail -> user_email . '>' . 
                    PHP_EOL;
                // send mail
                wp_mail( 
                    $to,
                    $subject, 
                    $message,
                    $headers
                );
            }

            return $post_id;
        }

Leave a Comment