Feed for Drafts (Plugin)

We are already working with four authors at WPEngineer – so it's quite useful to have a feed for drafts and everybody can look at it. If someone is writing a new post and saves as draft everybody get immediately notified via feed.

There is also the possibility to get notified via email, but I thought it's more convenient to let everybody know about new drafts through our feed reader. That's why I checked out how to create your own feed. With the help of the loop you can do quite a lot, as you can see in our previous post „Customize Your WordPress-Feeds“.

You are welcome to use the following small Plugin (download link at the end of this post) or use the displayed code below to create your own feed.

Feed doesn't have an access protection – that makes reading with several online tools easy and simple.

The Plugin creates a feed, which is available at http://example.com/?feed=draft. The name of the feed can be defined in line 27 add_feed( 'draft', array(&$this, 'get_draft_feed') ); .

Plugin Name: Draft Feed
Plugin URI: 
Description: Add a new Feed for drafts: <code>/?feed=drafts</code>
Version: 0.1
Author: Frank Bültge
Author URI: http://bueltge.de/

if ( !class_exists('DraftFeed') ) {
	class DraftFeed {
		// constructor
		function DraftFeed() {
			add_action( 'init', array(&$this, 'add_draft_feed') );
		// add feed via hook
		function add_draft_feed() {
			// set name for the feed
			// http://example.com/?feed=draft
			add_feed( 'draft', array(&$this, 'get_draft_feed') );
		// get feed
		function get_draft_feed() {
			global $wpdb;
			// draft or future
			$sql = "
							SELECT ID, post_title, post_date, post_author, post_author, guid, post_excerpt, post_content
							FROM $wpdb->posts
							WHERE post_status = 'draft'
							ORDER BY post_date_gmt DESC
			$items = $wpdb->get_results($sql);
			if ( !headers_sent() )
				header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
			$more = 1;
		<?php echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>'; ?>
<rss version="2.0"
	<?php do_action('rss2_ns'); ?>

	<title><?php bloginfo_rss( 'name' ); wp_title_rss(); ?></title>
	<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
	<link><?php bloginfo_rss( 'url' ) ?></link>
	<description><?php bloginfo_rss( 'description' ) ?></description>
	<pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false ); ?></pubDate>
	<language><?php echo get_option( 'rss_language' ); ?></language>
	<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
	<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
	<?php do_action('rss2_head'); ?>
	if ( empty($items) ) {
		echo '<!-- No submissions found yet. //-->';
	} else {
		foreach ($items as $item) {
			<title><?php echo stripslashes( apply_filters( 'comment_author', $item->post_title ) ); ?></title>
			<link><?php echo stripslashes( apply_filters( 'comment_author_url', get_permalink($item->ID) ) ); ?></link>
			<pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', $item->post_date ); ?></pubDate>
			<dc:creator><?php echo stripslashes( apply_filters('comment_author', $item->post_author) ); ?></dc:creator>

			<guid isPermaLink="false"><?php echo stripslashes( apply_filters('comment_author_url', $item->guid) ); ?></guid>
			<?php if ( $item->post_excerpt != '' ) { ?>
			<description><![CDATA[<?php echo trim(stripslashes( apply_filters('comment_text', $item->post_excerpt) ) ); ?>]]></description>
			<?php } else { ?>
			<description><![CDATA[<?php echo strip_tags( trim( stripslashes( apply_filters('comment_text', $item->post_content) ) ) ); ?>]]></description>
			<?php } ?>
			<content:encoded><![CDATA[<?php echo trim( stripslashes( apply_filters( 'comment_text', $item->post_content ) ) ); ?>]]></content:encoded>
			<?php do_action('rss2_item'); ?>

	} // end class
} // end if class exists

if ( class_exists('DraftFeed') && function_exists('is_admin') ) {
	$df_wp_injector = new DraftFeed();

// WP init and add new function for feed
if ( isset($df_wp_injector) && function_exists( 'add_action' ) ) {
	add_action( 'DraftFeed',  array(&$df_wp_injector, 'init') );


You are welcome to download the above code as Plugin at the Github Repo.

Comments are closed.


  1. Kevin

    I get the following error when i install & activate:

    This page contains the following errors:

    error on line 1 at column 6: XML declaration allowed only at the start of the document
    Below is a rendering of the page up to the first error.

    I'm running WP 2.9.2

  2. Frank

    @Kevin: i think you has an empty line after the end of php; this is also possible when you have a empty line in a template in the theme

3 pingbacks

  1. WordPress links - Week 49 - 2008 | WPStart.org - WordPress themes, plugins and news
  2. Weekend Links - Dec 5, 2008 | OMNINOGGIN
  3. Feed de los borradores | Ayuda WordPress