PluginProbe
RSS Includes Pages / 1.1
RSS Includes Pages v1.1
trunk 1.0 1.0.1 1.0.2 1.1 1.2 1.3 1.4 1.4.1 1.4.2
rss-includes-pages / rss-includes-pages.php

rss-includes-pages.php in RSS Includes Pages 1.1, at rss-includes-pages.php

62 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: RSS Includes Pages
4 Version: 1.1
5 Plugin URI: http://www.mariosalexandrou.com/rss-includes-pages.asp
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://www.mariosalexandrou.com/
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 '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