Email Post Changes
Post-Status change detection for Email Post Changes 1.7 (2 posts)

  1. Ov3rfly
    Posted 1 year ago #

    Had to enhance Email Post Changes 1.7 for a project to also send email for changes of $post->post_status, like "Draft" to "Published" or similar without other changes in post.

    Maybe somebody else wants to use this functionality, so I am sharing it here. To the plugin author(s), feel free to use (parts of) the code in future releases.

    Pastebin: Post-Status change detection for Email Post Changes 1.7

    In file class.email-post-changes.php replace the current function post_updated(..) with the new code-block from Pastebin.

    All changes are marked with Ov3rfly.

    Note: The new code-block also contains a new function nice_post_status(..) which goes right after function post_updated(..)

    Thanks for the great plugin.


  2. Ov3rfly
    Posted 1 year ago #

    Here a cleaner version which uses the existing $html_diffs and $text_diffs arrays, so Status changes are shown exactly like Title or Content changes in HTML and Plaintext of the Email.

    Requires only a single code-block within function post_updated(..) and adding the function nice_post_status(..) to file class.email-post-changes.php:

    1. Add this within function post_updated(..) before the if ( $identical ) { line:

    // Ov3rfly: Detect draft to publish or similar
    if ( $this->left_post->post_status != $this->right_post->post_status ) {
    	$left = $this->nice_post_status( $this->left_post->post_status );
    	$right = $this->nice_post_status( $this->right_post->post_status );
    	$field_title = __( 'Status' );
    	if ( $diff = $this->wp_text_diff( $left, $right ) )
    		$html_diffs[$field_title] = $diff;
    	require_once( dirname( __FILE__ ) . '/unified.php' );
    	$text_diff = new Text_Diff( array( $left ), array( $right ) );
    	$renderer  = new Text_Diff_Renderer_unified();
    	$text_diffs[$field_title] = $renderer->render($text_diff);
    	$identical = false;

    2. Add this before the function phpmailer_init( &$phpmailer ) { line:

    // Ov3rfly:
    function nice_post_status( $post_status ) {
    	$nice = 'Unknown';
    	switch( $post_status ) {
    	case 'publish':
    		$nice = _x( 'Published', 'post' ); break;
    	case 'future':
    		$nice = _x( 'Scheduled', 'post' ); break;
    	case 'draft':
    		$nice = _x( 'Draft', 'post' ); break;
    	case 'pending':
    		$nice = _x( 'Pending', 'post' ); break;
    	case 'private':
    		$nice = _x( 'Private', 'post' ); break;
    	case 'trash':
    		$nice = _x( 'Trash', 'post' ); break;
    	case 'auto-draft':
    	case 'inherit':
    		$nice = $post_status; break;
    	return $nice;

    Would recommend to add this to the plugin, maybe with an $options['status'] switch in backend.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Email Post Changes
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic