Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Version 1.21   Updated Sunday, April 27th, 2008 at 6:18pm

Draft Notification Plugin for WordPress

This WordPress plugin automatically emails the admin when a new draft is saved. The email contains the post’s title, the author, and a link. There is no options page currently, because there is really nothing to configure. The plugin now supports the new ‘pending’ status.

Download

Instructions

  • Download the above file, rename it from .txt to .php, and upload it to your plugins directory.
  • Enable the plugin.

Change Log

  • 04-27-08 Version 1.21 - Updated to work with WordPress 2.5 and the ‘pending’ status.
  • 05-16-07 Version 1.2 - Updated to work with WordPress 2.2.
  • 10-20-06 Version 1.1 - The emails now contain the author’s name, instead of ID.
  • 04-22-06 Version 1.0 - First release.

Notes

Because of the way this plugin works, it also sends out an email when an existing draft has been saved again. There does not seem to be an efficient way to check to see if it is the first time the draft has been saved, since dates are not stored for drafts.

By default, the author’s display_name is shown in the email. If you would prefer to see the login_name, or nice_name field, just look for the line in the script that says “Choose one of the following options to show the author’s name” and uncomment the option you would like to use.

Modifications

If you would rather have the email notification sent to the author of the post, instead of the admin, replace this line:

$recipient = get_bloginfo('admin_email');

With this:

$recipient = get_the_author_email();
  1. thank! it works now. i tried to inform the author /and/ the admin this wat:

    $admin = get_bloginfo(’admin_email’);
    $poster = get_the_author_email();

    mail($admin, $subject, $message);
    mail($poster, $subject, $message);

    but i end up with both emails going to the admin - do you see the problem?

    PAT

  2. Pat: I am still planning to check all the plugins for compatibility :) I know most of them work with no problems (Sitemap generator, Contact form), but there are a couple others I am going to fix when I get a chance.

  3. hi, could you make it compatible with vesion wordpress 2.5? it seems the db structure canged and the query is not working anymore..

  4. Hello,

    I want use your plugin for my blog but I don’t get the recipient bis the function

    $recipient = get_the_author_email();

    I checked it to input the recipient into the message, but this part is empty. I don’t get the author email.

    I hope, you can help me.

    Thanks a lot
    Uwe from germany

  5. 36
    josh

    Great plugin!! Thanks for making it available.

    In case anyone else wants to be notified upon “Pending Review” instead of Draft (with the introduction of Pending Review in 2.3), it’s easy to do. Just change the line that says:

    if ($result->post_status == “draft”)

    to

    if ($result->post_status == “pending”)

    and it seems to work great.

    -Josh

  6. 35
    mifouane

    Works now. The USERS table prefix was different in my DB.

  7. 34
    mifouane

    Oops! I just saw the change log that says this now works with Wordpress 2.2. However, has anyone tried this with Wordpress MU?

  8. 33
    mifouane

    hi,
    Thanks, this is exactly what I’m looking for. Unfortunately, I haven’t been able to make it work so far. I am using Wordpress MU 1.0 (which uses the core Wordpress version 2.2). Any idea if this plugin should work with Wordpress MU or at least with Wordpress 2.2?

  9. 32
    Rumman

    hi,
    I’ve slightly modified your handy plugin. I’ve add an administration menu, where admins can choose, which users will get notifications. Here’s the code:

    
    
    <?php
    
    function dddn_menu () {
      add_options_page('Notifikation', 'Notifikation', 8, basename(__FILE__), 'dddn_options_page');
    }
    function dddn_options_page() {
      global $wpdb;
    
      // get all users
      $tp = $wpdb->prefix;
    	$users = $wpdb->get_results("
    		SELECT ID, user_login
        FROM {$tp}users    
    	");
      if ($_POST['hidden_field']==='Y') { // form processing
        $notify= $_POST['notify'];  
        for ($j=0; $j < count($users); $j++) {
          if ($notify[$j] != get_usermeta($users[$j]->ID,'notify') ) {
            update_usermeta($users[$j]->ID,'notify',$notify[$j]);
            $output.=$users[$j]->user_login."<br />\n";
          }
        }
        if ($output) {
          ?>
          <div class="updated"><h3>Updated users:</h3><p><strong><?php echo $output; ?></strong></p></div>
          <?php
        }
      }
      // form	
      ?>  
      <div class="wrap">
        <h2>Notifikation</h2>
        <p>Sends an email to selected users when a draft is saved.
        </p>
        <form name="form1" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
          <input type="hidden" name="hidden_field" value="Y">
          <p><?php 
            $i=0;
            foreach ($users as $user) {  
              if (get_usermeta($user->ID,"notify")) $checked.=" checked=\"checked\" ";
              echo "<input type=\"checkbox\" name=\"notify[$i]\" value=\"1\" id=\"notify[$i]\" $checked>&nbsp;";
              echo "<label for=\"notify[$i]\" >{$user->user_login}</label><br />\n";
              unset($checked);
              $i++;
            }    
          
            ?> 
          </p><hr />
          <p class="submit">
            <input type="submit" name="Submit" value="<?php _e('Update Options') ?>" />
          </p>
        </form>
      </div>
      <?php
    } // dddn_options_page
    
    function dddn_process($id) {
    
    	global $wpdb;
    	
    	$tp = $wpdb->prefix;
    
    	$result = $wpdb->get_row("
    		SELECT post_status, post_title, user_login, user_nicename, display_name 
    		FROM {$tp}posts, {$tp}users 
    		WHERE {$tp}posts.post_author = {$tp}users.ID 
    		AND {$tp}posts.ID = '$id'
    	");
    
    	if ($result->post_status == "draft") {
    
    		$message = "";
    		$message .= "Draft updated on '" . get_bloginfo('name') . "'\n\n";
    		$message .= "Title: " . $result->post_title . "\n\n";
    
    	
    		// *** Choose one of the following options to show the author's name
    	
    		$message .= "Author: " . $result->display_name . "\n\n";
    		// $message .= "Author: " . $result->user_nicename . "\n\n";
    		// $message .= "Author: " . $result->user_login . "\n\n";
    
    
    
    		$message .= "Link: " . get_permalink($id);
    
    		$subject = "Draft updated on '" . get_bloginfo('name') . "'";
    
    		// get recipients from db
        $recipients = $wpdb->get_results("
    		  SELECT {$tp}users.user_email 
          FROM {$tp}users, {$tp}usermeta
          WHERE {$tp}users.ID={$tp}usermeta.user_id
          AND {$tp}usermeta.meta_key= 'notify' AND {$tp}usermeta.meta_value= '1' 
    	  ");
    	  // send mails
    	  foreach ($recipients as $recipient) {
    		  mail($recipient, $subject, $message);
        }
    	}
    
    }
    
    if (function_exists('add_action')) {
      add_action('save_post', 'dddn_process');
      add_action('admin_menu', 'dddn_menu');
    }
    ?>
    
    
    

  10. Graham: In the WordPress admin panel, go to ‘Manage -> Plugins’

  11. I have installed the above plug in; how do I enable it?
    Thansk

  12. tyson: That should work fine, except you do not want that ‘echo’ there.

  13. 28
    tyson

    How could the $recipient line be changed so that one (or more ) static e-mail addresses could be entered? Something like this?

    $recipient = echo "jon@mail.com, mary@mail.com";

  14. Manne: I just added some alternate code you can try.

  15. 26
    Manne

    Unfortunately the author mod didn’t work for me…

  16. 25
    Manne

    Many thanks, I will try it out right away

  17. Manne: I just added instructions in the ‘Other Modifications’ section above. Let me know if it works for you.

  18. 23
    Manne

    Hello, and many thanks for a great plugin.

    I’m trying to figure out how to change it to email the author instead of the admin, any ideas?

  19. Josh: Very nice method :)

  20. I have added just a little bit of code to this to make it just a little better. With this code you can have the draft set to a time instead of every save. For example it will email you when the first draft is saved then the next time that the draft is saved it will only email you it is past your time set, I have at 10 minutes.

    Here is the code:

    
    //Original code
    $recipient = get_bloginfo('admin_email');
    
    // New code
    if ( isset($_COOKIE['draft_page_id_'.$id])  )
    {
    	//there is a cookie for this draft under the set time 
    	$minDelay = 10;// this is how many minutes to delay before a resend
    	if( ($_COOKIE['draft_page_id_'.$id]+(60*$minDelay) ) < time() )
    	{
    		//set the cookie for the current Draft
    		setcookie('draft_page_id_'.$id, time(), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    		mail($recipient, "Saved Draft".$subject, $message);
    	}
    }
    else
    {
    	//set the cookie for the first Draft
    	setcookie('draft_page_id_'.$id, time(), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    	//now send email
    	mail($recipient, "Starting Draft".$subject, $message);
    }
    
    

  21. Next time I have a chance, I will see if there is anyway to do it :)

  22. I agree with Scot’s comment (#19), especially with the auto-save feature in WordPress 2.1. If the contributor were able to select to send a draft notification, that would be great (plus, I can be sure that I’m reviewing their final best efforts!). Otherwise, I love the plugin!

  23. Rather than sending automatically upon save (or auto-save), would love to see a checkbox option in the editor to send notification. Also, I agree that it should be possible to customize the destination email (in my case I’d want it to be sent to a mailing list address for editors). And I agree that the link in the email should go to the back-end, not to a public page.

  24. Teeth: I know that WordPress 2.1 has implemented several new hooks. I will have to look through them to see if there is a way to detect the difference.

  25. Great plugin, but with the Wordpress 2.1 it gets a little annoying as a message is sent everytime the system does an autosave. I hope there is a way around to having the message delivered ONLY when the save draft is pressed, I wonder how but just an idea

  26. Thank you for this great plug-in! This saves a lot of time when you have multiple Blogs you administer.

  27. Thank you very much for the plugin.
    It is exactly what I needed at http://www.newrss.net

    Please feel free to stop by and make a post about it. I’m sure there are others who could benefit from this plugin.

    Again, thanks! This is a great plugin.

  28. 13
    Cisco

    This is EXACTLY the plugin that I’ve been looking for. Thank you so much!

  29. Shane: I just uploaded a new version - 1.1

    It shows the display_name for the author now, and includes an option in the code to use login_name or nice_name if you prefer :)

    I had actually intended it to show the name, not ID, so thanks for pointing that out :)

  30. This is great… Just what I needed… Though is there a way to have it show the author’s name in the post rather than their number?

  31. What a cool idea! This was exactly what I was looking for. :)

  32. Opps, I forgot to mention that I have “just” copy&paste the From:-line from Scott Merrill’s (Skippy) commentauth-plugin. So it was not fully my work. ;)

  33. Quix0r: Nice work. One reason I skipped extra headers in this script was because so many people have problems with extra headers in my mail scripts - since a lot of servers disable the use of the extra parameters when PHP is in safe mode. Eventually I will add checks in to determine whether or not the extra info can be used. I like your code though :)

  34. Hello,

    I have patched your plugin slightly. I have added a nicer “From:”-line than the ugly “www-data” one or what ever your webserver is mailing with.

    http://blog.mxchange.org/dd-draft-notification.phps

    It not (yet) tested but it may work. So please feel free to grab and test it.

    Quix0r

  35. Brian: Good to hear :)

  36. 5
    Brian Barnes

    Nevermind, I got it figured out! I edited the recipient list! Thanks for a great plugin!

  37. 4
    Brian Barnes

    Is there a way to edit the list of recipients? I don’t want the admins to get the emails, but rather a list of editors who will proof and publish the post.

  38. Glad it is working for you :)

    As far as the link, it does appear to work on my site, as long as I am logged in as the admin. I will test it out some more though. Either way, pointing it straight to the admin panel would be a good idea :)

  39. Ok. Forget about this. There was a problem on my server side.
    It’s all fixed and it works great now!
    Just one little remark: the link we receive in the email can not be valid until the draft hasn’t been published. The page doesn’t exist.
    It would make more sense to link to the admin. Something like: /wp-admin/post.php?action=edit&post=$post_id.

  40. Hello,
    Thank you for this plugin. It’s a very good idea. I was just looking for something like that.
    Unfortunately I just tried to install it and it’s not working. I activated it but nothing happens!
    I just came across this : http://wordpress.org/support/topic/51296?replies=4
    Nothing to do with it?

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.