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've created a custom post type that makes use of custom fields over the default editor. I want to receive an email notification when an update to the post is made. The email does not have to show the diff (though it would be nice).

I've tried Email Post Changes and it requires you to have "Revisions" enabled. I've tried enabling it and I am guessing, because I am not using the default editor, that it won't work without it.

Any thoughts on either getting the plugin working or figuring out how to have an email sent when a custom post type is updated?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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 = 'test@example.com'
                // 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;
        }
share|improve this answer
    
Thank you for this! I will take a closer look and update the question accordingly. –  Jonathan Wold Jun 7 '11 at 17:29

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.