Created
July 30, 2015 16:42
-
-
Save rveitch/92f1396d27b8755b7dd6 to your computer and use it in GitHub Desktop.
Plugin Name: Draft Feed | https://github.com/bueltge/Drafts-Feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| 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" | |
| xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
| xmlns:wfw="http://wellformedweb.org/CommentAPI/" | |
| xmlns:dc="http://purl.org/dc/elements/1.1/" | |
| xmlns:atom="http://www.w3.org/2005/Atom" | |
| xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" | |
| <?php do_action('rss2_ns'); ?> | |
| > | |
| <channel> | |
| <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> | |
| <generator>http://bueltge.de/</generator> | |
| <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'); ?> | |
| <?php | |
| if ( empty($items) ) { | |
| echo '<!-- No submissions found yet. //-->'; | |
| } else { | |
| foreach ($items as $item) { | |
| ?> | |
| <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'); ?> | |
| </item> | |
| <?php | |
| } | |
| } | |
| ?> | |
| </channel> | |
| </rss> | |
| <?php | |
| } | |
| } // 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') ); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment