| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: RSS Includes Pages |
| 4 |
Version: 1.4 |
| 5 |
Plugin URI: http://infolific.com/technology/software-worth-using/include-pages-in-wordpress-rss-feeds/ |
| 6 |
Description: Include pages (not just posts) in RSS feeds. Particularly useful to those that use WordPress as a CMS. |
| 7 |
Author: Marios Alexandrou |
| 8 |
Author URI: http://infolific.com/technology/ |
| 9 |
*/ |
| 10 |
add_filter('posts_where', 'ma_posts_where'); |
| 11 |
|
| 12 |
function ma_posts_where($var){ |
| 13 |
if (!is_feed()){ // check if this is a feed |
| 14 |
return $var; // if not, return an unmodified variable |
| 15 |
} else { |
| 16 |
global $table_prefix; // get the table prefix |
| 17 |
$find = $table_prefix . 'posts.post_type = \'post\''; // find where the query filters by post_type |
| 18 |
$replace = '(' . $find . ' OR ' . $table_prefix . 'posts.post_type = \'page\')'; // add OR post_type 'page' to the query |
| 19 |
$var = str_replace($find, $replace, $var); // change the query |
| 20 |
} |
| 21 |
return $var; // return the variable |
| 22 |
} |
| 23 |
|
| 24 |
/* |
| 25 |
* Deal with Last Post Modified so feeds will validate. WP default just checks for posts, not pages. |
| 26 |
*/ |
| 27 |
|
| 28 |
add_filter('get_lastpostmodified', 'ma_get_lastpostmodified',10,2); |
| 29 |
|
| 30 |
// We do this because is_feed is not set when calling get_lastpostmodified. |
| 31 |
add_action('rss2_ns', 'ma_feed_true'); |
| 32 |
add_action('atom_ns', 'ma_feed_true'); |
| 33 |
add_action('rdf_ns', 'ma_feed_true'); |
| 34 |
// We won't mess with comment feeds. |
| 35 |
add_action ('rss2_comments_ns', 'ma_feed_false'); |
| 36 |
add_action ('atom_comments_ns', 'ma_feed_false'); |
| 37 |
|
| 38 |
function ma_get_lastpostmodified($lastpostmodified, $timezone){ |
| 39 |
global $ma_feed, $wpdb;; |
| 40 |
if (!($ma_feed)){ |
| 41 |
return $lastpostmodified; |
| 42 |
} |
| 43 |
|
| 44 |
//queires taken from wp-includes/post.php modified to include pages |
| 45 |
$lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND (post_type = 'post' OR post_type = 'page') ORDER BY post_modified_gmt DESC LIMIT 1"); |
| 46 |
$lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND (post_type = 'post' OR post_type = 'page') ORDER BY post_date_gmt DESC LIMIT 1"); |
| 47 |
if ( $lastpostdate > $lastpostmodified ) { |
| 48 |
$lastpostmodified = $lastpostdate; |
| 49 |
} |
| 50 |
return $lastpostmodified; |
| 51 |
} |
| 52 |
|
| 53 |
function ma_feed_true(){ |
| 54 |
global $ma_feed; |
| 55 |
$ma_feed = true; |
| 56 |
} |
| 57 |
function ma_feed_false(){ |
| 58 |
global $ma_feed; |
| 59 |
$ma_feed = false; |
| 60 |
} |
| 61 |
?> |
| 62 |
|