-
Notifications
You must be signed in to change notification settings - Fork 0
/
include-pages-in-rss-feed.php
77 lines (69 loc) · 2.24 KB
/
include-pages-in-rss-feed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Plugin Name: Include Pages in RSS Feed
* Description: Adds page post types to the standard WordPress RSS feed.
* Author: Infinitnet
* Author URI: https://infinitnet.io/
* Plugin URI: https://github.com/infinitnet/include-pages-in-rss-feed
* Update URI: https://github.com/infinitnet/include-pages-in-rss-feed
* Version: 1.0
* License: GPLv3
* Text Domain: include-pages-in-rss-feed
*/
function add_pages_to_rss_feed($query) {
if ($query->is_feed()) {
$query->set('post_type', array('post', 'page'));
$exclude_ids = get_option('exclude_page_ids_in_rss', '');
if (!empty($exclude_ids)) {
$query->set('post__not_in', array_map('intval', explode(',', $exclude_ids)));
}
}
return $query;
}
add_filter('pre_get_posts', 'add_pages_to_rss_feed');
function add_rss_feed_settings_page() {
add_options_page(
'Include Pages in RSS Feed',
'Include Pages in RSS Feed',
'manage_options',
'include-pages-in-rss-feed',
'render_rss_feed_settings_page'
);
}
add_action('admin_menu', 'add_rss_feed_settings_page');
function render_rss_feed_settings_page() {
?>
<div class="wrap">
<h1>Include Pages in RSS Feed</h1>
<form method="post" action="options.php">
<?php
settings_fields('include-pages-in-rss-feed');
do_settings_sections('include-pages-in-rss-feed');
submit_button();
?>
</form>
</div>
<?php
}
function register_rss_feed_settings() {
register_setting(
'include-pages-in-rss-feed',
'exclude_page_ids_in_rss',
array(
'sanitize_callback' => 'sanitize_text_field'
)
);
add_settings_section('rss_feed_settings_section', '', null, 'include-pages-in-rss-feed');
add_settings_field(
'exclude_page_ids',
'Exclude Page IDs',
'render_exclude_page_ids_field',
'include-pages-in-rss-feed',
'rss_feed_settings_section'
);
}
add_action('admin_init', 'register_rss_feed_settings');
function render_exclude_page_ids_field() {
$value = get_option('exclude_page_ids_in_rss', '');
echo '<input type="text" name="exclude_page_ids_in_rss" value="' . esc_attr($value) . '" />';
}