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: « 7 6 5 [4] 3 2 1 » Show All

  1. 60
    Jason

    hey thanks for this code, how do I get it just to send to the main wp email thats set in the settings page of wp

  2. Thanks for your great plugin. It was useful for my team.

  3. Thankyou very much. great plugin! This was very helpful.

  4. We supply all kinds of moncler boots,moncler bags,moncler coats,moncler jackets,moncler T-shirt,moncler vest and so on.We have got a good reputation pf our products with top quality and good price.We sincerely look forward to futher cooperation with you for mutual benefits.We are sure that you will find working with us is a pleasant, time-saving and profitable experience. Please feel free to contact us if you have any questions.Our website is http://www.newlyapparel.com.

  5. 56
    Sascha

    Hey Dagon is it possible to edit the plugin that only the post authors of the draft are getting a notification?

    Hope you can help me !

    Thanks

    Sascha

  6. Hey, great plugins. I modded this one to force it to go only to admin. I changed line 45 from this:
    $editors = $wpdb->get_results("SELECT user_id FROM {$tp}usermeta WHERE {$tp}usermeta.meta_value >= " . $email_user_level);
    to this:
    $editors = $wpdb->get_results("SELECT user_id FROM {$tp}usermeta WHERE {$tp}usermeta.meta_value = 10");

  7. 54
    Serge

    HI,

    I have to admit that I don’t know anything about scripts, In our blog, there is five administrators (same level). How can ths script be modified to make sure the alert is sent to only one recipient (myself) ?
    Thanks in advance for your reply.

    P.-S. Sorry for the bad English.

  8. Tested but the email is not sent out. no problem with new user registration email.

  9. Jerod: This plugin does not currently have a settings page.

    I just tested again on one of my WP 2.8 installs and it worked fine for me. Me sure you have your admin email address set properly in your WP user profile. Also, you might make sure it is not getting blocked by a spam filter, etc..

  10. I have uploaded the plugin and really want to use it. I am hoping that it will integrate nicely with P2 and alert me when a new post is written. However, after activating the plugin and I cannot find any place in the dashboard where I can change the settings. And I have not gotten it to work yet, as no emails have come my way. Using WordPress 2.8. Any helpful hints on what my problem could be?

  11. ron: That is just where the variable is defined. In the actual SQL statement, the proper code is used.

  12. Hey Admin, I didn’t check your actual code but in your posting, I believe you need “$email_user_level = 7;” to be “>= 7″ to include all level 7 users and ABOVE. Currently it would only email level 7 users.

  13. Version 1.22 has been released

    You can now choose to send the email notifications by user level. See above for the option. This release has been tested, and works, in the latest release of WordPress – 2.8

    ron G: Thanks!

  14. Sorry I forgot a small but major piece of code. Where it says:

    
    foreach ($editors as $editor) {			
       $user_info = get_userdata($editor);
       $recipient .= $user_info->user_email . ',';
    }
    

    it should be:

    
    foreach ($editors as $editor) {			
       $user_info = get_userdata($editor->user_id);
       $recipient .= $user_info->user_email . ',';
    }
    

  15. I added some additional code to email all editors (in my case all users with a user-level 7 and above) when there is a post pending. Hope this helps.

    
    
    <?php
    /*
    Plugin Name: Draft Notification
    Plugin URI: http://www.dagondesign.com/articles/draft-notification-plugin-for-wordpress/
    Description: Sends an email to the site admin when a draft is saved.
    Author: Dagon Design
    Version: 1.21
    Author URI: http://www.dagondesign.com
    */
    
    
    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 == "pending") {
    
    		$message = "";
    		$message .= "A draft was 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') . "'";
    
    		$editors = $wpdb->get_results("SELECT user_id FROM {$tp}usermeta WHERE {$tp}usermeta.meta_value >= 7");
    		
    		$recipient = "";
    	
    			foreach ($editors as $editor) {			
    
    				$user_info = get_userdata($editor);
    				$recipient .= $user_info->user_email . ',';
    			}
    
    		mail($recipient, $subject, $message);
    
    	}
    
    }
    
    
    add_action('save_post', 'dddn_process');
    
    ?>
    
    

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