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.22   Updated Wednesday, July 1st, 2009 at 8:20pm

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

  If you have found this page useful, please consider donating. Thanks!

Instructions

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

Change Log

  • 07-01-09 Version 1.22 – You can now choose to send the emails to all users on or above a certain level (eg: editors).
  • 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 – This includes auto-saves. A solution to this is being researched.

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.

Changing the user level for notifications

In the script, look for this line:

$email_user_level = 7;

This tells the script to send notification emails to anyone on, or above, that user level. Just change this for your particular needs.

Pages: « 4 [3] 2 1 » Show All

  1. If anyone is having problems with not receiving emails from Wordpress, there is a solution here: http://www.roblayton.net/archive/wordpress-not-sending-emails-anymore-solved/

    Good luck!

  2. This plugin has been tested, and works in the latest WordPress release (2.7.1).

    The only current issue is that an email is sent every time the draft is auto-saved. While the auto-save feature of WordPress can be turned off, I plan to come up with a solution to this.

  3. 43
    Brian

    Will you be updating this plugin for use with Wordpress 2.7?

  4. There is currently an issue with this plugin when the auto-save feature of new versions of WP is enabled. Everytime WP automatically safes the drafts, an email is sent. It will be looked into soon.

  5. 41
    Simon

    The method for sending to authors didn’t work for me, so I changed the code to the following using get_userdata, which worked:

    
    
    function dddn_process($id) {
    
    	global $wpdb;
    	
    	$tp = $wpdb->prefix;
    
    	$result = $wpdb->get_row("
    		SELECT post_status, post_author, 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 == "pending") {
    
    		$message = "";
    		$message .= "Thanks for your post. \n\n";
    		$message .= "Title: " . $result->post_title . "\n\n";
    
    		$message .= "Message body .";
    
    		$message .= "Many thanks";
    
    		$subject = "Subject";
    
                    $user_info = get_userdata($result->post_author);
    
    		$recipient = $user_info->user_email;
    
    		mail($recipient, $subject, $message);
    
    	}
    
    }
    
    
    add_action('save_post', 'dddn_process');
    
    ?>
    
    

  6. 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

  7. 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.

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

  9. 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

  10. 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

  11. 35
    mifouane

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

  12. 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?

  13. 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?

  14. 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');
    }
    ?>
    
    
    

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

Pages: « 4 [3] 2 1 » Show All

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.