Exclude Pages - Version 1.8.2

Version Description

Download this release

Release Info

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

Code changes from version 1.8.1 to 1.8.2

Files changed (3) hide show
  1. exclude_pages.php +63 -82
  2. locale/exclude-pages.pot +42 -0
  3. readme.txt +18 -2
exclude_pages.php CHANGED
@@ -3,7 +3,7 @@
3
Plugin Name: Exclude Pages from Navigation
4
Plugin URI: http://wordpress.org/extend/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.8.1
7
Author: Simon Wheatley
8
Author URI: http://simonwheatley.co.uk/wordpress/
9
@@ -31,11 +31,12 @@ define('EP_PLUGIN_DIR', dirname(__FILE__));
31
define('EP_OPTION_NAME', 'ep_exclude_pages');
32
// Separator for the string of IDs stored in the option value
33
define('EP_OPTION_SEP', ',');
34
35
// Take the pages array, and return the pages array without the excluded pages
36
// Doesn't do this when in the admin area
37
- function ep_exclude_pages( $pages )
38
- {
39
// If the URL includes "wp-admin", just return the unaltered list
40
// This constant, WP_ADMIN, only came into WP on 2007-12-19 17:56:16 rev 6412, i.e. not something we can rely upon unfortunately.
41
// May as well check it though.
@@ -80,28 +81,37 @@ function ep_exclude_pages( $pages )
80
return $pages;
81
}
82
83
- // Recurse down an ancestor chain, checking if one is excluded
84
- // Returns the ID of the "nearest" excluded ancestor
85
- function ep_ancestor_excluded( $page, $excluded_ids, $pages )
86
- {
87
$parent = & ep_get_page( $page->post_parent, $pages );
88
// Is there a parent?
89
- if ( ! $parent ) {
90
- return;
91
- }
92
// Is it excluded?
93
- if ( in_array( $parent->ID, $excluded_ids ) ) {
94
- return $parent->ID;
95
- }
96
// Is it the homepage?
97
- if ( $parent->ID == 0 ) return false;
98
// Otherwise we have another ancestor to check
99
return ep_ancestor_excluded( $parent, $excluded_ids, $pages );
100
}
101
102
- // Return the portion of the $pages array which refers to the ID passed as $page_id
103
- function ep_get_page( $page_id, $pages )
104
- {
105
// PHP 5 would be much nicer here, we could use foreach by reference, ah well.
106
$length = count($pages);
107
for ( $i=0; $i<$length; $i++ ) {
@@ -117,8 +127,7 @@ function ep_get_page( $page_id, $pages )
117
// returns true if NOT excluded (i.e. included)
118
// returns false is it IS excluded.
119
// (Tricky this upside down flag business.)
120
- function ep_this_page_included()
121
- {
122
global $post_ID;
123
// New post? Must be included then.
124
if ( ! $post_ID ) return true;
@@ -134,8 +143,7 @@ function ep_this_page_included()
134
// Check the ancestors for the page we're editing (defined by
135
// global $post_ID var), return the ID if the nearest one which
136
// is excluded (if any);
137
- function ep_nearest_excluded_ancestor()
138
- {
139
global $post_ID, $wpdb;
140
// New post? No problem.
141
if ( ! $post_ID ) return false;
@@ -148,8 +156,7 @@ function ep_nearest_excluded_ancestor()
148
return ep_ancestor_excluded( $parent, $excluded_ids, $pages );
149
}
150
151
- function ep_get_excluded_ids()
152
- {
153
$exclude_ids_str = get_option( EP_OPTION_NAME );
154
// No excluded IDs? Return an empty array
155
if ( empty($exclude_ids_str) ) return array();
@@ -163,8 +170,7 @@ function ep_get_excluded_ids()
163
// don't want to have to retrieve meta for every page in order to
164
// determine if it's to be excluded. Storing all the exclusions in
165
// one row seems more sensible.
166
- function ep_update_exclusions( $post_ID )
167
- {
168
// Bang (!) to reverse the polarity of the boolean, turning include into exclude
169
$exclude_this_page = ! (bool) $_POST['ep_this_page_included'];
170
// SWTODO: Also check for a hidden var, which confirms that this checkbox was present
@@ -189,48 +195,24 @@ function ep_update_exclusions( $post_ID )
189
if ( $index !== false ) unset( $excluded_ids[$index] );
190
}
191
$excluded_ids_str = implode( EP_OPTION_SEP, $excluded_ids );
192
- 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." );
193
}
194
195
// Take an option, delete it if it exists, then add it.
196
- function ep_set_option( $name, $value, $description )
197
- {
198
// Delete option
199
delete_option($name);
200
// Insert option
201
add_option($name, $value, $description);
202
}
203
204
- // Pre WP2.5
205
- // Add some HTML for the DBX sidebar control into the edit page page
206
- function ep_admin_sidebar()
207
- {
208
- $nearest_excluded_ancestor = ep_nearest_excluded_ancestor();
209
- echo ' <fieldset id="excludepagediv" class="dbx-box">';
210
- echo ' <h3 class="dbx-handle">'.__('Navigation').'</h3>';
211
- echo ' <div class="dbx-content">';
212
- echo ' <label for="ep_this_page_included" class="selectit">';
213
- echo ' <input ';
214
- echo ' type="checkbox" ';
215
- echo ' name="ep_this_page_included" ';
216
- echo ' id="ep_this_page_included" ';
217
- if ( ep_this_page_included() ) echo 'checked="checked"';
218
- echo ' />';
219
- echo ' '.__('Include this page in menus').'</label>';
220
- echo ' <input type="hidden" name="ep_ctrl_present" value="1" />';
221
- if ( $nearest_excluded_ancestor !== false ) {
222
- echo '<div class="exclude_alert">';
223
- echo __('An ancestor of this page is excluded, so this page is too. ');
224
- echo '<a href="page.php?action=edit&amp;post='.$nearest_excluded_ancestor.'"';
225
- echo ' title="'.__('edit the excluded ancestor').'">'.__('Edit ancestor').'</a>.</div>';
226
- }
227
- echo ' </div></fieldset>';
228
- }
229
-
230
- // Post WP 2.5
231
- // Add some HTML below the submit box
232
- function ep_admin_sidebar_wp25()
233
- {
234
$nearest_excluded_ancestor = ep_nearest_excluded_ancestor();
235
echo ' <div id="excludepagediv" class="new-admin-wp25">';
236
echo ' <div class="outer"><div class="inner">';
@@ -239,23 +221,27 @@ function ep_admin_sidebar_wp25()
239
echo ' type="checkbox" ';
240
echo ' name="ep_this_page_included" ';
241
echo ' id="ep_this_page_included" ';
242
- if ( ep_this_page_included() ) echo 'checked="checked"';
243
echo ' />';
244
- echo ' '.__('Include this page in user menus').'</label>';
245
echo ' <input type="hidden" name="ep_ctrl_present" value="1" />';
246
if ( $nearest_excluded_ancestor !== false ) {
247
echo '<div class="exclude_alert"><em>';
248
- echo __('N.B. An ancestor of this page is excluded, so this page is too. ');
249
- echo '<a href="page.php?action=edit&amp;post='.$nearest_excluded_ancestor.'"';
250
- echo ' title="'.__('edit the excluded ancestor').'">'.__('Edit ancestor').'</a>.</em></div>';
251
}
252
echo ' </div><!-- .inner --></div><!-- .outer -->';
253
echo ' </div><!-- #excludepagediv -->';
254
}
255
256
- // Add some CSS into the HEAD element of the admin area
257
- function ep_admin_css()
258
- {
259
echo ' <style type="text/css" media="screen">';
260
echo ' div.exclude_alert { font-size: 11px; }';
261
echo ' .new-admin-wp25 { font-size: 11px; background-color: #fff; }';
@@ -268,45 +254,40 @@ function ep_admin_css()
268
}
269
270
// Add our ctrl to the list of controls which AREN'T hidden
271
- function ep_hec_show_dbx( $to_show )
272
- {
273
array_push( $to_show, 'excludepagediv' );
274
return $to_show;
275
}
276
277
// PAUSE & RESUME FUNCTIONS
278
279
- function pause_exclude_pages()
280
- {
281
remove_filter('get_pages','ep_exclude_pages');
282
}
283
284
- function resume_exclude_pages()
285
- {
286
add_filter('get_pages','ep_exclude_pages');
287
}
288
289
// INIT FUNCTIONS
290
291
- function ep_init()
292
- {
293
// Call this function on the get_pages filter
294
// (get_pages filter appears to only be called on the "consumer" side of WP,
295
// the admin side must use another function to get the pages. So we're safe to
296
// remove these pages every time.)
297
add_filter('get_pages','ep_exclude_pages');
298
}
299
300
- function ep_admin_init()
301
- {
302
// Add panels into the editing sidebar(s)
303
global $wp_version;
304
- if ( version_compare( $wp_version, '2.7-beta', '>=' ) ) {
305
- add_meta_box('ep_admin_meta_box', __('Exclude Pages'), 'ep_admin_sidebar_wp25', 'page', 'side', 'low');
306
- } else {
307
- add_action('dbx_page_sidebar', 'ep_admin_sidebar'); // Pre WP2.5
308
- add_action('submitpage_box', 'ep_admin_sidebar_wp25'); // Post WP 2.5, pre WP 2.7
309
- }
310
311
// Set the exclusion when the post is saved
312
add_action('save_post', 'ep_update_exclusions');
3
Plugin Name: Exclude Pages from Navigation
4
Plugin URI: http://wordpress.org/extend/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.8.2
7
Author: Simon Wheatley
8
Author URI: http://simonwheatley.co.uk/wordpress/
9
31
define('EP_OPTION_NAME', 'ep_exclude_pages');
32
// Separator for the string of IDs stored in the option value
33
define('EP_OPTION_SEP', ',');
34
+ // The textdomain for the WP i18n gear
35
+ define( 'EP_TD', 'exclude-pages' );
36
37
// Take the pages array, and return the pages array without the excluded pages
38
// Doesn't do this when in the admin area
39
+ function ep_exclude_pages( $pages ) {
40
// If the URL includes "wp-admin", just return the unaltered list
41
// This constant, WP_ADMIN, only came into WP on 2007-12-19 17:56:16 rev 6412, i.e. not something we can rely upon unfortunately.
42
// May as well check it though.
81
return $pages;
82
}
83
84
+ /**
85
+ * Recurse down an ancestor chain, checking if one is excluded
86
+ *
87
+ * @param
88
+ * @return boolean|int The ID of the "nearest" excluded ancestor, otherwise false
89
+ * @author Simon Wheatley
90
+ **/
91
+ function ep_ancestor_excluded( $page, $excluded_ids, $pages ) {
92
$parent = & ep_get_page( $page->post_parent, $pages );
93
// Is there a parent?
94
+ if ( ! $parent )
95
+ return false;
96
// Is it excluded?
97
+ if ( in_array( $parent->ID, $excluded_ids ) )
98
+ return (int) $parent->ID;
99
// Is it the homepage?
100
+ if ( $parent->ID == 0 )
101
+ return false;
102
// Otherwise we have another ancestor to check
103
return ep_ancestor_excluded( $parent, $excluded_ids, $pages );
104
}
105
106
+ /**
107
+ * {no description}
108
+ *
109
+ * @param int $page_id The ID of the WP page to search for
110
+ * @param array $pages An array of WP page objects
111
+ * @return boolean|object the page from the $pages array which corresponds to the $page_id
112
+ * @author Simon Wheatley
113
+ **/
114
+ function ep_get_page( $page_id, $pages ) {
115
// PHP 5 would be much nicer here, we could use foreach by reference, ah well.
116
$length = count($pages);
117
for ( $i=0; $i<$length; $i++ ) {
127
// returns true if NOT excluded (i.e. included)
128
// returns false is it IS excluded.
129
// (Tricky this upside down flag business.)
130
+ function ep_this_page_included() {
131
global $post_ID;
132
// New post? Must be included then.
133
if ( ! $post_ID ) return true;
143
// Check the ancestors for the page we're editing (defined by
144
// global $post_ID var), return the ID if the nearest one which
145
// is excluded (if any);
146
+ function ep_nearest_excluded_ancestor() {
147
global $post_ID, $wpdb;
148
// New post? No problem.
149
if ( ! $post_ID ) return false;
156
return ep_ancestor_excluded( $parent, $excluded_ids, $pages );
157
}
158
159
+ function ep_get_excluded_ids() {
160
$exclude_ids_str = get_option( EP_OPTION_NAME );
161
// No excluded IDs? Return an empty array
162
if ( empty($exclude_ids_str) ) return array();
170
// don't want to have to retrieve meta for every page in order to
171
// determine if it's to be excluded. Storing all the exclusions in
172
// one row seems more sensible.
173
+ function ep_update_exclusions( $post_ID ) {
174
// Bang (!) to reverse the polarity of the boolean, turning include into exclude
175
$exclude_this_page = ! (bool) $_POST['ep_this_page_included'];
176
// SWTODO: Also check for a hidden var, which confirms that this checkbox was present
195
if ( $index !== false ) unset( $excluded_ids[$index] );
196
}
197
$excluded_ids_str = implode( EP_OPTION_SEP, $excluded_ids );
198
+ 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.", "exclude-pages" ) );
199
}
200
201
// Take an option, delete it if it exists, then add it.
202
+ function ep_set_option( $name, $value, $description ) {
203
// Delete option
204
delete_option($name);
205
// Insert option
206
add_option($name, $value, $description);
207
}
208
209
+ /**
210
+ * Callback function for the metabox on the page edit screen.
211
+ *
212
+ * @return void
213
+ * @author Simon Wheatley
214
+ **/
215
+ function ep_admin_sidebar_wp25() {
216
$nearest_excluded_ancestor = ep_nearest_excluded_ancestor();
217
echo ' <div id="excludepagediv" class="new-admin-wp25">';
218
echo ' <div class="outer"><div class="inner">';
221
echo ' type="checkbox" ';
222
echo ' name="ep_this_page_included" ';
223
echo ' id="ep_this_page_included" ';
224
+ if ( ep_this_page_included() )
225
+ echo 'checked="checked"';
226
echo ' />';
227
+ echo ' '.__( 'Include this page in user menus', EP_TD ).'</label>';
228
echo ' <input type="hidden" name="ep_ctrl_present" value="1" />';
229
if ( $nearest_excluded_ancestor !== false ) {
230
echo '<div class="exclude_alert"><em>';
231
+ echo sprintf( __( 'N.B. An ancestor of this page is excluded, so this page is too (<a href="%1$s" title="%2$s">edit ancestor</a>).', EP_TD), "post.php?action=edit&amp;post=$nearest_excluded_ancestor", __( 'edit the excluded ancestor', EP_TD ) );
232
+ echo '</em></div>';
233
}
234
echo ' </div><!-- .inner --></div><!-- .outer -->';
235
echo ' </div><!-- #excludepagediv -->';
236
}
237
238
+ /**
239
+ * Hooks the WordPress admin_head action to inject some CSS.
240
+ *
241
+ * @return void
242
+ * @author Simon Wheatley
243
+ **/
244
+ function ep_admin_css() {
245
echo ' <style type="text/css" media="screen">';
246
echo ' div.exclude_alert { font-size: 11px; }';
247
echo ' .new-admin-wp25 { font-size: 11px; background-color: #fff; }';
254
}
255
256
// Add our ctrl to the list of controls which AREN'T hidden
257
+ function ep_hec_show_dbx( $to_show ) {
258
array_push( $to_show, 'excludepagediv' );
259
return $to_show;
260
}
261
262
// PAUSE & RESUME FUNCTIONS
263
264
+ function pause_exclude_pages() {
265
remove_filter('get_pages','ep_exclude_pages');
266
}
267
268
+ function resume_exclude_pages() {
269
add_filter('get_pages','ep_exclude_pages');
270
}
271
272
// INIT FUNCTIONS
273
274
+ function ep_init() {
275
// Call this function on the get_pages filter
276
// (get_pages filter appears to only be called on the "consumer" side of WP,
277
// the admin side must use another function to get the pages. So we're safe to
278
// remove these pages every time.)
279
add_filter('get_pages','ep_exclude_pages');
280
+ // Load up the translation gear
281
+ $locale = get_locale();
282
+ $folder = rtrim( basename( dirname( __FILE__ ) ), '/' );
283
+ $mo_file = trailingslashit( WP_PLUGIN_DIR ) . "$folder/locale/" . EP_TD . "-$locale.mo";
284
+ load_textdomain( EP_TD, $mo_file );
285
}
286
287
+ function ep_admin_init() {
288
// Add panels into the editing sidebar(s)
289
global $wp_version;
290
+ add_meta_box('ep_admin_meta_box', __( 'Exclude Pages', EP_TD ), 'ep_admin_sidebar_wp25', 'page', 'side', 'low');
291
292
// Set the exclusion when the post is saved
293
add_action('save_post', 'ep_update_exclusions');
locale/exclude-pages.pot ADDED
@@ -0,0 +1,42 @@
1
+ # Translation of the WordPress plugin by .
2
+ # Copyright (C) 2010
3
+ # This file is distributed under the same license as the package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: \n"
10
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/exclude-pages\n"
11
+ "POT-Creation-Date: 2010-05-14 08:36+0000\n"
12
+ "PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: Simon Wheatley <simon@simonwheatley.co.uk>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=utf-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+
19
+ #: exclude_pages.php:196
20
+ msgid ""
21
+ "Comma separated list of post and page IDs to exclude when returning pages "
22
+ "from the get_pages function."
23
+ msgstr ""
24
+
25
+ #: exclude_pages.php:226
26
+ msgid "Include this page in user menus"
27
+ msgstr ""
28
+
29
+ #: exclude_pages.php:230
30
+ #, php-format
31
+ msgid ""
32
+ "N.B. An ancestor of this page is excluded, so this page is too (<a href=\"%1"
33
+ "$s\" title=\"%2$s\">edit ancestor</a>)."
34
+ msgstr ""
35
+
36
+ #: exclude_pages.php:230
37
+ msgid "edit the excluded ancestor"
38
+ msgstr ""
39
+
40
+ #: exclude_pages.php:284
41
+ msgid "Exclude Pages"
42
+ msgstr ""
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.9.2
7
- Stable tag: 1.8.1
8
9
This plugin adds a checkbox, “include this page in menus”, uncheck this to exclude pages from the page navigation that users see on your site.
10
@@ -41,6 +41,22 @@ Exclude pages is incompatible with:
41
42
== Change Log ==
43
44
= v1.8.1 2010/4/19 =
45
46
* BUGFIX: Check for existence of parent object before attempting to use it. (Thanks to Robert Kosara for the bug report.)
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: 3.0 beta
7
+ Stable tag: 1.8.2
8
9
This plugin adds a checkbox, “include this page in menus”, uncheck this to exclude pages from the page navigation that users see on your site.
10
41
42
== Change Log ==
43
44
+ = v1.8.2 2010/5/14 =
45
+
46
+ Dear Non-English Exclude Pages Users,
47
+
48
+ This release includes the facility for Exclude Pages to be translated into languages other than English. Please [contact me](http://www.simonwheatley.co.uk/contact-me/) if you want to translate Exclude Pages into your language.
49
+
50
+ Sorry it took so long.
51
+
52
+ Best regards,
53
+
54
+ Simon
55
+
56
+ * DROPPED SUPPORT FOR WORDPRESS VERSIONS PRIOR TO VERSION 2.7
57
+ * BUGFIX: Everything was reporting that it was excluded by an ancestor for some reason. Crazy. Fixed now.
58
+ * LOCALISATION: Added POT file! Woo hoo!
59
+
60
= v1.8.1 2010/4/19 =
61
62
* BUGFIX: Check for existence of parent object before attempting to use it. (Thanks to Robert Kosara for the bug report.)