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();

Pages: [3] 2 1 » Show All

  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’

Pages: [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.