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

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 bloginfo_rss( 'name' ); wp_title_rss(); ?>
	} else {
		foreach ($items as $item) {
			<?php echo stripslashes( apply_filters( 'comment_author', $item->post_title ) ); ?>
			ID) ) ); ?>
			post_date ); ?>
			post_author) ); ?>

			guid) ); ?>
			post_excerpt != '' ) { ?>
			post_excerpt) ) ); ?>]]>
			post_content) ) ) ); ?>]]>
			post_content ) ) ); ?>]]>



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





5 responses to “Feed for Drafts (Plugin)”

  1. […] Feed for Drafts (Plugin) – We are already working with four WPEngineer – … […]

  2. […] gestionas un sitio WordPress con varios autores seguro que te va a encantar este plugin, Feed for Drafts. Lo que ofrece es la creación de un feed RSS especial que muestra los posts en estado de […]

  3. Kevin Avatar

    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

  4. Frank Avatar

    @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