Exclude Pages - Version 1.0

Version Description

Download this release

Release Info

Developer simonwheatley
Plugin Icon wp plugin Exclude Pages
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (3) hide show
  1. exclude_pages.php +166 -0
  2. readme.txt +26 -0
  3. screenshot-1.png +0 -0
exclude_pages.php ADDED
@@ -0,0 +1,166 @@
1
+ <?php
2
+ /*
3
+ Plugin Name: Exclude Pages from Navigation
4
+ Plugin URI: http://www.simonwheatley.co.uk/wordpress-plugins/exclude-pages/
5
+ Description: Provides a checkbox on the editing page which you can check to exclude pages from the primary navigation. IMPORTANT NOTE: This will remove the pages from any "consumer" side page listings, which may not be limited to your page navigation listings.
6
+ Version: 1.0
7
+ Author: Simon Wheatley
8
+
9
+ Copyright 2007 Simon Wheatley
10
+
11
+ This script is free software; you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation; either version 3 of the License, or
14
+ (at your option) any later version.
15
+
16
+ This script is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+
24
+ */
25
+
26
+ // Full filesystem path to this dir
27
+ define('EP_PLUGIN_DIR', dirname(__FILE__));
28
+
29
+ // Option name for exclusion data
30
+ define('EP_OPTION_NAME', 'ep_exclude_pages');
31
+ // Separator for the string of IDs stored in the option value
32
+ define('EP_OPTION_SEP', ',');
33
+
34
+ // Take the pages array, and return the pages array without the excluded pages
35
+ function ep_exclude_pages( $pages )
36
+ {
37
+ $excluded_ids = ep_get_excluded_ids();
38
+ $length = count($pages);
39
+ for ( $i=0; $i<$length; $i++ ) {
40
+ $page = & $pages[$i];
41
+ if ( in_array($page->ID, $excluded_ids ) ) {
42
+ unset( $pages[$i] );
43
+ }
44
+ }
45
+ // Reindex the array, for neatness
46
+ // SWFIXME: Is reindexing the array going to create a memory optimisation problem for large arrays of WP post/page objects?
47
+ $pages = array_values( $pages );
48
+ return $pages;
49
+ }
50
+
51
+ // Is this page currently NOT excluded,
52
+ // returns true if NOT excluded (i.e. included)
53
+ // returns false is it IS excluded.
54
+ // (Tricky this upside down flag business.)
55
+ function ep_include_this_page()
56
+ {
57
+ global $post_ID;
58
+ // New post? Must be included then.
59
+ if ( ! $post_ID ) return true;
60
+ $excluded_ids = ep_get_excluded_ids();
61
+ // If there's no exclusion array, we can return true
62
+ if ( empty($excluded_ids) ) return true;
63
+ // Check if our page is in the exclusion array
64
+ // The bang (!) reverses the polarity [1] of the boolean
65
+ return ! in_array( $post_ID, $excluded_ids );
66
+ // [1] (of the neutron flow)
67
+ }
68
+
69
+ function ep_get_excluded_ids()
70
+ {
71
+ $exclude_ids_str = get_option( EP_OPTION_NAME );
72
+ // No excluded IDs? Return an empty array
73
+ if ( empty($exclude_ids_str) ) return array();
74
+ // Otherwise, explode the separated string into an array, and return that
75
+ return explode( EP_OPTION_SEP, $exclude_ids_str );
76
+ }
77
+
78
+ // This function gets all the exclusions out of the options
79
+ // table, updates them, and resaves them in the options table.
80
+ // We're avoiding making this a postmeta (custom field) because we
81
+ // don't want to have to retrieve meta for every page in order to
82
+ // determine if it's to be excluded. Storing all the exclusions in
83
+ // one row seems more sensible.
84
+ function ep_update_exclusions( $post_ID )
85
+ {
86
+ // Bang (!) to reverse the polarity of the boolean, turning include into exclude
87
+ $exclude_this_page = ! (bool) $_POST['ep_include_this_page'];
88
+ $excluded_ids = ep_get_excluded_ids();
89
+ // If we need to EXCLUDE the page from the navigation...
90
+ if ( $exclude_this_page ) {
91
+ // Add the post ID to the array of excluded IDs
92
+ array_push( $excluded_ids, $post_ID );
93
+ // De-dupe the array, in case it was there already
94
+ $excluded_ids = array_unique( $excluded_ids );
95
+ }
96
+ // If we need to INCLUDE the page in the navigation...
97
+ if ( ! $exclude_this_page ) {
98
+ // Find the post ID in the array of excluded IDs
99
+ $index = array_search( $post_ID, $excluded_ids );
100
+ // Delete any index found
101
+ if ( $index !== false ) unset( $excluded_ids[$index] );
102
+ }
103
+ $excluded_ids_str = implode( EP_OPTION_SEP, $excluded_ids );
104
+ ep_set_option( EP_OPTION_NAME, $excluded_ids_str, "Comma separated list of post and page IDs to exclude when returning pages from the get_pages function." );
105
+ }
106
+
107
+ // Take an option, delete it if it exists, then add it.
108
+ function ep_set_option( $name, $value, $description )
109
+ {
110
+ // Delete option
111
+ delete_option($name);
112
+ // Insert option
113
+ add_option($name, $value, $description);
114
+ }
115
+
116
+ // Add some HTML for the DBX sidebar control into the edit page page
117
+ function ep_admin_sidebar()
118
+ {
119
+ echo <<<END
120
+ <fieldset id="excludepagediv" class="dbx-box">
121
+ <h3 class="dbx-handle">Navigation</h3>
122
+ <div class="dbx-content">
123
+ <label for="ep_include_this_page" class="selectit">
124
+ <input
125
+ type="checkbox"
126
+ name="ep_include_this_page"
127
+ id="ep_include_this_page"
128
+ END;
129
+ if ( ep_include_this_page() ) echo 'checked="checked"';
130
+ echo <<<END
131
+ />
132
+ Include this page in menus</label>
133
+ </div>
134
+ </fieldset>
135
+ END;
136
+ }
137
+
138
+ // Add our ctrl to the list of controls which AREN'T hidden
139
+ function ep_hec_show_dbx( $to_show )
140
+ {
141
+ array_push( $to_show, 'excludepagediv' );
142
+ return $to_show;
143
+ }
144
+
145
+ // HOOK IT UP TO WORDPRESS
146
+
147
+ // Add panels into the editing sidebar(s)
148
+ add_action('dbx_page_sidebar', 'ep_admin_sidebar');
149
+
150
+ // Set the exclusion when the post is saved
151
+ add_action('save_post', 'ep_update_exclusions');
152
+
153
+ // Call this function on the get_pages filter
154
+ // (get_pages filter appears to only be called on the "consumer" side of WP,
155
+ // the admin side must use another function to get the pages. So we're safe to
156
+ // remove these pages every time.)
157
+ add_filter('get_pages','ep_exclude_pages');
158
+
159
+ // Call this function on our very own hec_show_dbx filter
160
+ // This filter is harmless to add, even if we don't have the
161
+ // Hide Editor Clutter plugin installed as it's using a custom filter
162
+ // which won't be called except by the HEC plugin.
163
+ // Uncomment to show the control by default
164
+ // add_filter('hec_show_dbx','ep_hec_show_dbx');
165
+
166
+ ?>
readme.txt ADDED
@@ -0,0 +1,26 @@
1
+ === Exclude Pages ===
2
+ Contributors: simonwheatley
3
+ Donate link: http://www.simonwheatley.co.uk/wordpress-plugins/
4
+ Tags: get_pages, navigation, menu, exclude pages, hide pages
5
+ Requires at least: 2.2.3
6
+ Tested up to: 2.3
7
+ Stable tag: 1.0
8
+
9
+ This plugin adds a checkbox, “include this page in menus”, uncheck this to exclude pages from the
10
+ page navigation that users see on your site.
11
+
12
+ == Description ==
13
+
14
+ This plugin adds a checkbox, “include this page in menus”, which is checked by default. If you uncheck
15
+ it, the page will not appear in any listings of pages (which includes, and is *usually* limited to, your
16
+ page navigation menus).
17
+
18
+ == Installation ==
19
+
20
+ 1. Upload `exclude_pages.php` to the `/wp-content/plugins/` directory
21
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
22
+ 1. Edit a post and enjoy the new rich styles in your excerpts
23
+
24
+ == Screenshots ==
25
+
26
+ 1. Showing the control on the editing screen to exclude a page from the navigation
screenshot-1.png ADDED
Binary file