Version Description
Download this release
Release Info
Developer | simonwheatley |
Plugin | Exclude Pages |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 1.2
- exclude_pages.php +105 -23
- readme.txt +19 -3
- screenshot-2.png +0 -0
exclude_pages.php
CHANGED
@@ -3,7 +3,7 @@
|
|
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.
|
7 |
Author: Simon Wheatley
|
8 |
|
9 |
Copyright 2007 Simon Wheatley
|
@@ -32,23 +32,73 @@ define('EP_OPTION_NAME', 'ep_exclude_pages');
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
// returns true if NOT excluded (i.e. included)
|
53 |
// returns false is it IS excluded.
|
54 |
// (Tricky this upside down flag business.)
|
@@ -63,7 +113,24 @@ function ep_include_this_page()
|
|
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 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
}
|
68 |
|
69 |
function ep_get_excluded_ids()
|
@@ -122,24 +189,36 @@ function ep_set_option( $name, $value, $description )
|
|
122 |
// Add some HTML for the DBX sidebar control into the edit page page
|
123 |
function ep_admin_sidebar()
|
124 |
{
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
<
|
130 |
-
<
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
/>
|
138 |
-
Include this page in menus</label>
|
139 |
-
<input type="hidden" name="ep_ctrl_present" value="1" />
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
144 |
|
145 |
// Add our ctrl to the list of controls which AREN'T hidden
|
@@ -163,6 +242,9 @@ add_action('save_post', 'ep_update_exclusions');
|
|
163 |
// remove these pages every time.)
|
164 |
add_filter('get_pages','ep_exclude_pages');
|
165 |
|
|
|
|
|
|
|
166 |
// Call this function on our very own hec_show_dbx filter
|
167 |
// This filter is harmless to add, even if we don't have the
|
168 |
// Hide Editor Clutter plugin installed as it's using a custom filter
|
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.2
|
7 |
Author: Simon Wheatley
|
8 |
|
9 |
Copyright 2007 Simon Wheatley
|
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 |
+
// Ensure we catch all descendant pages, so that if a parent
|
40 |
+
// is hidden, it's children are too.
|
41 |
for ( $i=0; $i<$length; $i++ ) {
|
42 |
$page = & $pages[$i];
|
43 |
+
// If one of the ancestor pages is excluded, add it to our exclude array
|
44 |
+
if ( ep_ancestor_excluded( $page, $excluded_ids, $pages ) ) {
|
45 |
+
// Can't actually delete the pages at the moment,
|
46 |
+
// it'll screw with our recursive search.
|
47 |
+
// For the moment, just tag the ID onto our excluded IDs
|
48 |
+
$excluded_ids[] = $page->ID;
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
// Ensure the array only has unique values
|
53 |
+
$delete_ids = array_unique( $excluded_ids );
|
54 |
+
|
55 |
+
// Loop though the $pages array and actually unset/delete stuff
|
56 |
+
for ( $i=0; $i<$length; $i++ ) {
|
57 |
+
$page = & $pages[$i];
|
58 |
+
// If one of the ancestor pages is excluded, add it to our exclude array
|
59 |
+
if ( in_array( $page->ID, $delete_ids ) ) {
|
60 |
+
// Finally, delete something(s)
|
61 |
unset( $pages[$i] );
|
62 |
}
|
63 |
}
|
64 |
+
|
65 |
// Reindex the array, for neatness
|
66 |
// SWFIXME: Is reindexing the array going to create a memory optimisation problem for large arrays of WP post/page objects?
|
67 |
$pages = array_values( $pages );
|
68 |
+
|
69 |
return $pages;
|
70 |
}
|
71 |
|
72 |
+
// Recurse down an ancestor chain, checking if one is excluded
|
73 |
+
// Returns the ID of the "nearest" excluded ancestor
|
74 |
+
function ep_ancestor_excluded( & $page, & $excluded_ids, & $pages )
|
75 |
+
{
|
76 |
+
$parent = & ep_get_page( $page->post_parent, $pages );
|
77 |
+
// Is it excluded?
|
78 |
+
if ( in_array( $parent->ID, $excluded_ids ) ) {
|
79 |
+
return $parent->ID;
|
80 |
+
}
|
81 |
+
// Is it the homepage?
|
82 |
+
if ( $parent->ID == 0 ) return false;
|
83 |
+
// Otherwise we have another ancestor to check
|
84 |
+
return ep_ancestor_excluded( $parent->ID, $excluded_ids, $pages );
|
85 |
+
}
|
86 |
+
|
87 |
+
// Return the portion of the $pages array which refers to the ID passed as $page_id
|
88 |
+
function ep_get_page( $page_id, & $pages )
|
89 |
+
{
|
90 |
+
// PHP 5 would be much nicer here, we could use foreach by reference, ah well.
|
91 |
+
$length = count($pages);
|
92 |
+
for ( $i=0; $i<$length; $i++ ) {
|
93 |
+
$page = & $pages[$i];
|
94 |
+
if ( $page->ID == $page_id ) return $page;
|
95 |
+
}
|
96 |
+
// Unusual.
|
97 |
+
return false;
|
98 |
+
}
|
99 |
+
|
100 |
+
// Is this page we're editing (defined by global $post_ID var)
|
101 |
+
// currently NOT excluded (i.e. included),
|
102 |
// returns true if NOT excluded (i.e. included)
|
103 |
// returns false is it IS excluded.
|
104 |
// (Tricky this upside down flag business.)
|
113 |
// Check if our page is in the exclusion array
|
114 |
// The bang (!) reverses the polarity [1] of the boolean
|
115 |
return ! in_array( $post_ID, $excluded_ids );
|
116 |
+
// fn1. (of the neutron flow, ahem)
|
117 |
+
}
|
118 |
+
|
119 |
+
// Check the ancestors for the page we're editing (defined by
|
120 |
+
// global $post_ID var), return the ID if the nearest one which
|
121 |
+
// is excluded (if any);
|
122 |
+
function ep_nearest_excluded_ancestor()
|
123 |
+
{
|
124 |
+
global $post_ID, $wpdb;
|
125 |
+
// New post? No problem.
|
126 |
+
if ( ! $post_ID ) return false;
|
127 |
+
$excluded_ids = ep_get_excluded_ids();
|
128 |
+
// Manually get all the pages, to avoid our own filter.
|
129 |
+
$sql = "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'";
|
130 |
+
$pages = $wpdb->get_results( $sql );
|
131 |
+
// Start recursively checking the ancestors
|
132 |
+
$parent = ep_get_page( $post_ID, $pages );
|
133 |
+
return ep_ancestor_excluded( $parent, $excluded_ids, $pages );
|
134 |
}
|
135 |
|
136 |
function ep_get_excluded_ids()
|
189 |
// Add some HTML for the DBX sidebar control into the edit page page
|
190 |
function ep_admin_sidebar()
|
191 |
{
|
192 |
+
$nearest_excluded_ancestor = ep_nearest_excluded_ancestor();
|
193 |
+
error_log( "Nearest: " . $nearest_excluded_ancestor );
|
194 |
+
if ( $nearest_excluded_ancestor === false ) error_log("FALSE");
|
195 |
+
echo ' <fieldset id="excludepagediv" class="dbx-box">';
|
196 |
+
echo ' <h3 class="dbx-handle">'.__('Navigation').'</h3>';
|
197 |
+
echo ' <div class="dbx-content">';
|
198 |
+
echo ' <label for="ep_include_this_page" class="selectit">';
|
199 |
+
echo ' <input ';
|
200 |
+
echo ' type="checkbox" ';
|
201 |
+
echo ' name="ep_include_this_page" ';
|
202 |
+
echo ' id="ep_include_this_page" ';
|
203 |
+
if ( ep_include_this_page() ) echo 'checked="checked"';
|
204 |
+
echo ' />';
|
205 |
+
echo ' '.__('Include this page in menus').'</label>';
|
206 |
+
echo ' <input type="hidden" name="ep_ctrl_present" value="1" />';
|
207 |
+
if ( $nearest_excluded_ancestor !== false ) {
|
208 |
+
echo '<div class="exclude_alert">';
|
209 |
+
echo __('An ancestor of this page is excluded, so this page is too. ');
|
210 |
+
echo '<a href="http://wordpress.test.site/wp-admin/page.php?action=edit&post='.$nearest_excluded_ancestor.'"';
|
211 |
+
echo ' title="'.__('edit the excluded ancestor').'">'.__('Edit ancestor').'</a>.</div>';
|
212 |
+
}
|
213 |
+
echo ' </div></fieldset>';
|
214 |
+
}
|
215 |
+
|
216 |
+
// Add some CSS into the HEAD element of the admin area
|
217 |
+
function ep_admin_css()
|
218 |
+
{
|
219 |
+
echo ' <style type="text/css" media="screen">';
|
220 |
+
echo ' div.exclude_alert { font-size: 11px; }';
|
221 |
+
echo ' </style>';
|
222 |
}
|
223 |
|
224 |
// Add our ctrl to the list of controls which AREN'T hidden
|
242 |
// remove these pages every time.)
|
243 |
add_filter('get_pages','ep_exclude_pages');
|
244 |
|
245 |
+
// Add some CSS to the admin header
|
246 |
+
add_action('admin_head', 'ep_admin_css');
|
247 |
+
|
248 |
// Call this function on our very own hec_show_dbx filter
|
249 |
// This filter is harmless to add, even if we don't have the
|
250 |
// Hide Editor Clutter plugin installed as it's using a custom filter
|
readme.txt
CHANGED
@@ -3,14 +3,25 @@ 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.
|
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 |
== Change Log ==
|
13 |
|
|
|
|
|
|
|
|
|
14 |
= v1.1 2007/11/10 =
|
15 |
|
16 |
* Fix: Pages not created manually using "Write Page" were always excluded from the navigation, meaning the admin has to edit the page to manually include them. Pages created by other plugins are not always included in the navigation, if you want to exclude them (a less common scenario) you have to edit them and uncheck the box. ([Reported by Nudnik](http://wordpress.org/support/topic/140017 "Wordpress forum topic"))
|
@@ -21,12 +32,17 @@ This plugin adds a checkbox, “include this page in menus”, which is checked
|
|
21 |
it, the page will not appear in any listings of pages (which includes, and is *usually* limited to, your
|
22 |
page navigation menus).
|
23 |
|
|
|
|
|
|
|
|
|
24 |
== Installation ==
|
25 |
|
26 |
1. Upload `exclude_pages.php` to the `/wp-content/plugins/` directory
|
27 |
1. Activate the plugin through the 'Plugins' menu in WordPress
|
28 |
-
1.
|
29 |
|
30 |
== Screenshots ==
|
31 |
|
32 |
1. Showing the control on the editing screen to exclude a page from the navigation
|
|
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.1
|
7 |
+
Stable tag: 1.2
|
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”, uncheck this to exclude pages from the
|
15 |
+
page navigation that users see on your site.
|
16 |
+
|
17 |
+
Any issues: [contact me](http://www.simonwheatley.co.uk/contact-me/).
|
18 |
+
|
19 |
== Change Log ==
|
20 |
|
21 |
+
= v1.2 2007/11/21 =
|
22 |
+
|
23 |
+
* Enhancement: Child pages of an excluded page are now also hidden. There is also a warning message in the edit screen for any child page with a hidden ancestor, informing the person editing that the page is effectively hidden; a link is provided to edit the ancestor affecting the child page.
|
24 |
+
|
25 |
= v1.1 2007/11/10 =
|
26 |
|
27 |
* Fix: Pages not created manually using "Write Page" were always excluded from the navigation, meaning the admin has to edit the page to manually include them. Pages created by other plugins are not always included in the navigation, if you want to exclude them (a less common scenario) you have to edit them and uncheck the box. ([Reported by Nudnik](http://wordpress.org/support/topic/140017 "Wordpress forum topic"))
|
32 |
it, the page will not appear in any listings of pages (which includes, and is *usually* limited to, your
|
33 |
page navigation menus).
|
34 |
|
35 |
+
Pages which are children of excluded pages also do not show up in menu listings. (An alert in the editing screen,
|
36 |
+
underneath the "include" checkbox allows you to track down which ancestor page is affecting child pages
|
37 |
+
in this way.)
|
38 |
+
|
39 |
== Installation ==
|
40 |
|
41 |
1. Upload `exclude_pages.php` to the `/wp-content/plugins/` directory
|
42 |
1. Activate the plugin through the 'Plugins' menu in WordPress
|
43 |
+
1. Create or edit a page, and enjoy the frisson of excitement as you exclude it from the navigation
|
44 |
|
45 |
== Screenshots ==
|
46 |
|
47 |
1. Showing the control on the editing screen to exclude a page from the navigation
|
48 |
+
2. Showing the control and warning for a page which is the child of an excluded page
|
screenshot-2.png
ADDED
Binary file
|