Plugin Directory

Changeset 704528

Timestamp:
04/27/2013 03:01:56 AM (11 years ago)
Author:
dllh
Message:

3.6 broke this plugin because of changes to the revisions api. Here we hook onto post_updated instead of wp_insert_post so that we have actual before and after values for the post.

Location:
email-post-changes/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • email-post-changes/trunk/class.email-post-changes.php

    r557038 r704528  
    3636
    3737        if ( $options['enable'] )
    38             add_action( 'wp_insert_post', array( $this, 'wp_insert_post' ), 10, 2 );
     38            add_action( ' );
    3939        if ( current_user_can( 'manage_options' ) )
    4040            add_action( 'admin_menu', array( $this, 'admin_menu' ), 115 );
     
    6363
    6464    // The meat of the plugin
    65     function wp_insert_post( $post_id, $post ) {
    66         $options = $this->get_options();
    67 
    68         if ( ! $options['drafts'] && 'draft' == $post->post_status )
    69             return;
    70 
    71         if ( 'revision' == $post->post_type ) { // Revision is saved first
    72             if ( wp_is_post_autosave( $post ) )
    73                 return;
    74             $this->left_post = $post;
    75         } elseif ( !empty( $this->left_post ) && $this->left_post->post_parent == $post->ID ) { // Then new post
    76             if ( !in_array( $post->post_type, $options['post_types'] ) )
    77                 return;
    78             $this->right_post = $post;
     65    function post_updated( $post_id, $post_after, $post_before ) {
     66        $options = $this->get_options();
     67        // If we're purely saving a draft, and don't have the draft option enabled, skip. If we're transitioning one way or the other, send a notification.
     68        if ( 0 == $options['drafts'] && 'draft' == $post_before->post_status && 'draft' == $post_after->post_status )
     69            return;
     70                   
     71        if ( wp_is_post_autosave( $post_after ) )
     72            return;
     73
     74        // Our inputs are just the raw post data from before and after, so the wp_is_post_autosave() check,
     75        // which looks for {$post->post_parent}-autosave in the post_name, may not work. Check this too just to be safe.
     76        if ( 'auto-draft' == $post_before->post_status || 'auto-draft' == $post_after->post_status )
     77            return;
     78
     79        if ( !in_array( $post_before->post_type, $options['post_types'] ) )
     80            return;
     81
     82        $this->left_post = $post_before;
     83        $this->right_post = $post_after;
     84
     85        // If this is a new post, set an empty title for $this->left_post so that it appears in the diff.
     86                $child_posts = wp_get_post_revisions( $post_id, array( 'numberposts' => 1 ) );
     87                if ( count( $child_posts ) == 0 ) {
     88            $this->left_post->post_title = '';
    7989        }
    8090
  • email-post-changes/trunk/readme.txt

    r557034 r704528  
    33Tags: email, diff, post, page, change
    44Requires at least: 3.2
    5 Tested up to: 3.4
    6 Stable tag: 1.2
     5Tested up to: 3.
     6Stable tag: 1.
    77
    88Emails you whenever a change to a post or page is made.
     
    2828
    2929== Changelog ==
     30
     31
     32
    3033
    3134= 1.2 =
Note: See TracChangeset for help on using the changeset viewer.