Simply Exclude - Version 2.0.3

Version Description

2012-03-18 Fixes to core filtering logic.

Download this release

Release Info

Developer pmenard
Plugin Icon wp plugin Simply Exclude
Version 2.0.3
Comparing to
See all releases

Code changes from version 2.0.2 to 2.0.3

Files changed (2) hide show
  1. readme.txt +13 -2
  2. simplyexclude.php +115 -61
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.codehooligans.com
4
  Tags: admin, posts, pages, categories, tags, Post Type, Taxonomy, exclude, include, is_front, is_archive, is_search, is_feed, is_author
5
  Requires at least: 3.2
6
  Tested up to: 3.3.1
7
- Stable tag: 2.0.2
8
 
9
  == Description ==
10
 
@@ -36,7 +36,10 @@ Well you need to be careful when excluding both categories and tags. Since a pos
36
 
37
  Only the parent Page itself is excluded from searches. By default WordPress does not yet include Pages in search. Make sure you have other search plugins correctly configured to not search attachments.
38
 
39
- See more FAQ information when you install the plugin. Look for the Help section.
 
 
 
40
 
41
  == Screenshots ==
42
 
@@ -46,6 +49,14 @@ See more FAQ information when you install the plugin. Look for the Help section.
46
 
47
  == Changelog ==
48
 
 
 
 
 
 
 
 
 
49
  = 2.0.1 =
50
  2012-03-04
51
  Small bug. On the new Simply Exclude Help panel I user the jQuery UI Accordion package. Seems I failed to check this when setting the minimum WordPress version I was supporting (3.2). Seems jQuery UI Accordion is not available in core WordPress until version 3.3. So have added my own libraries to cover the older versions of WordPress. Sorry about that. And thanks to @biswajeet for bringing this up in the WordPress forums.
4
  Tags: admin, posts, pages, categories, tags, Post Type, Taxonomy, exclude, include, is_front, is_archive, is_search, is_feed, is_author
5
  Requires at least: 3.2
6
  Tested up to: 3.3.1
7
+ Stable tag: 2.0.3
8
 
9
  == Description ==
10
 
36
 
37
  Only the parent Page itself is excluded from searches. By default WordPress does not yet include Pages in search. Make sure you have other search plugins correctly configured to not search attachments.
38
 
39
+ = I've excluded a Page via the plugin but it still shows up in my sidebar when wp_list_pages is called. Why? =
40
+
41
+ At the time (version 1.6.1) the plugin only effects Pages included in the traditional Search feature on a site. It does not trap all selections of Pages via other internal WordPress functions...yet!
42
+
43
 
44
  == Screenshots ==
45
 
49
 
50
  == Changelog ==
51
 
52
+ = 2.0.3 =
53
+ 2012-03-18
54
+ Fixes to core filtering logic.
55
+
56
+ = 2.0.2 =
57
+ 2012-03-05
58
+ Fixed some issues when converting from the previous version of the Simply Exclude configurations.
59
+
60
  = 2.0.1 =
61
  2012-03-04
62
  Small bug. On the new Simply Exclude Help panel I user the jQuery UI Accordion package. Seems I failed to check this when setting the minimum WordPress version I was supporting (3.2). Seems jQuery UI Accordion is not available in core WordPress until version 3.3. So have added my own libraries to cover the older versions of WordPress. Sorry about that. And thanks to @biswajeet for bringing this up in the WordPress forums.
simplyexclude.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Simply Exclude
4
  Plugin URI: http://www.codehooligans.com/projects/wordpress/simply-exclude/
5
  Description: Provides an interface to selectively exclude/include categories, tags and page from the 4 actions used by WordPress. is_front, is_archive, is_search, is_feed.
6
  Author: Paul Menard
7
- Version: 2.0.2
8
  Author URI: http://www.codehooligans.com
9
 
10
  Revision history
@@ -21,6 +21,7 @@ Revision history
21
  2.0 - 2012-03-03 Full rewrite of the plugin to support custom Taxonomies and Custom Post Types. Added support for managing items within the Taxonomy/Post Type panels. Added support for exclude/include on Post instead of just Categories and Tags. Dropped support for third-party plugins like Google XML Sitemaps and Seach Unleashed (Sorry!). Now correctly supporting Pages seach excludes. Yah!.
22
  2.0.1 - 2012-03-04 Small bug. On the new Simply Exclude Help panel I user the jQuery UI Accordion package. Seems I failed to check this when setting the minimum WordPress version I was supporting (3.2). Seems jQuery UI Accordion is not available in core WordPress until version 3.3. So have added my own libraries to cover the older versions of WordPress. Sorry about that. And thanks to @biswajeet for bringing this up in the WordPress forums.
23
  2.0.2 - 2012-03-05 Fixed some issues when converting from the previous version of the Simply Exclude configurations.
 
24
  */
25
 
26
  define('SIMPLY_EXCLUDE_I18N_DOMAIN', 'simplyexclude');
@@ -44,7 +45,7 @@ class SimplyExclude
44
 
45
  public function __construct() {
46
 
47
- $this->se_version = "2.0.2";
48
 
49
  $this->admin_menu_label = __("Simply Exclude", SIMPLY_EXCLUDE_I18N_DOMAIN);
50
  $this->options_key = "simplyexclude_v2";
@@ -66,7 +67,7 @@ class SimplyExclude
66
  add_action( 'wp_ajax_se_update', array(&$this, 'se_ajax_update') );
67
 
68
  // Used to limit the categories displayed on the home page. Simple
69
- add_filter('pre_get_posts', array(&$this,'se_filters'));
70
  }
71
 
72
  function admin_init_proc()
@@ -1896,10 +1897,23 @@ class SimplyExclude
1896
 
1897
  function se_filters($query)
1898
  {
1899
- global $wp_query;
1900
 
1901
- if ($wp_query != $query)
 
1902
  return $query;
 
 
 
 
 
 
 
 
 
 
 
 
1903
 
1904
  // Ignore all queries from within wp-admin.
1905
  if ($query->is_admin)
@@ -1907,12 +1921,15 @@ class SimplyExclude
1907
 
1908
  $this->se_load_config();
1909
 
1910
- // echo "se_cfg<pre>"; print_r($this->se_cfg); echo "</pre>";
1911
- // echo "query<pre>"; print_r($query); echo "</pre>";
1912
- // echo "wp_query<pre>"; print_r($wp_query); echo "</pre>";
1913
- // exit;
1914
-
 
 
1915
  $action_data = array();
 
1916
  // Only filter on our actions.
1917
  if (($query->is_home) || ($query->is_posts_page))
1918
  {
@@ -1922,32 +1939,30 @@ class SimplyExclude
1922
  {
1923
  $action_data = $this->se_get_action_data('is_search');
1924
  }
1925
- else if ($query->is_archive)
1926
- {
1927
- $action_data = $this->se_get_action_data('is_archive');
1928
- }
1929
  else if ($query->is_feed)
1930
  {
1931
  $action_data = $this->se_get_action_data('is_feed');
1932
  }
 
 
 
 
1933
 
1934
- //echo "action_data<pre>"; print_r($action_data); echo "</pre>";
 
 
 
1935
  if ($action_data)
1936
  {
1937
  $tax_query = array();
1938
  $tax_query_relation = array();
1939
- // echo "action_data<pre>"; print_r($action_data); echo "</pre>";
1940
  foreach($action_data as $key => $key_data)
1941
  {
1942
- // echo "key=[". $key ."]<br />";
1943
- // echo "key_data<pre>"; print_r($key_data); echo "</pre>";
1944
  if ($key == "taxonomies")
1945
  {
1946
  foreach($key_data as $key_key => $key_key_data)
1947
  {
1948
- //echo "key_key=[". $key_key ."]<br />";
1949
- //echo "key_key_data<pre>"; print_r($key_key_data); echo "</pre>";
1950
-
1951
  $tax_args = array(
1952
  'taxonomy' => $key_key,
1953
  'field' => 'id',
@@ -1973,63 +1988,93 @@ class SimplyExclude
1973
  $post_types_array = array();
1974
  $post__in = array();
1975
  $post__not_in = array();
 
1976
  foreach($key_data as $key_key => $key_key_data)
1977
- {
1978
- //echo "key_key=[". $key_key ."]<br />";
1979
- //echo "key_key_data<pre>"; print_r($key_key_data); echo "</pre>";
1980
-
1981
- $post_types_array[] = $key_key;
1982
- if ($key_key_data['actions'] == 'e')
1983
  $post__not_in = array_merge($post__not_in, $key_key_data['terms']);
1984
- else if ($key_key_data['actions'] == 'i')
1985
- $post__in = array_merge($post__in, $key_key_data['terms']);
 
 
 
 
 
 
1986
  }
1987
- //echo "post_types_array<pre>"; print_r($post_types_array); echo "</pre>";
1988
- //echo "post__not_in<pre>"; print_r($post__not_in); echo "</pre>";
1989
- //echo "post__in<pre>"; print_r($post__in); echo "</pre>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1990
 
1991
  if (count($post__not_in))
1992
  {
1993
- //echo "PROCESSING: POST__NOT_IN<br />";
1994
- //echo "post__not_in<pre>"; print_r($post__not_in); echo "</pre>";
1995
  $query->set('post__not_in', $post__not_in);
 
 
 
 
 
 
1996
  }
1997
  else if (count($post__in))
1998
  {
1999
- //echo "PROCESSING: POST__IN<br />";
2000
- //echo "post__in<pre>"; print_r($post__in); echo "</pre>";
2001
  $query->set('post__in', $post__in);
2002
- }
2003
-
2004
- $query_post_type = $query->get('post_type');
2005
- //echo "query_post_type<pre>"; print_r($query_post_type); echo "</pre>";
2006
- if (!$query_post_type) $query_post_type = array();
2007
- else if (!is_array($query_post_type))
 
 
 
 
 
 
 
2008
  {
2009
- $query_post_type = array($query_post_type);
2010
- }
2011
- //echo "query_post_type<pre>"; print_r($query_post_type); echo "</pre>";
2012
 
2013
- if ($post_types_array)
2014
- {
2015
- $query_post_type = array_unique(array_merge($post_types_array, $query_post_type));
2016
- $query->set('post_type', $query_post_type);
2017
- }
 
2018
  }
2019
  else if ($key == "se_types")
2020
  {
2021
  foreach($key_data as $key_key => $key_key_data)
2022
  {
2023
- // echo "key_key=[". $key_key ."]<br />";
2024
- // echo "key_key_data<pre>"; print_r($key_key_data); echo "</pre>";
2025
-
2026
  if ($key_key == "users")
2027
  {
2028
  $user_ids = $this->se_listify_ids($key_key_data['terms'], $key_key_data['actions']);
2029
- //echo "user_ids=[". $user_ids ."]<br />";
2030
  if ($user_ids)
2031
  {
2032
  $query->set('author', $user_ids);
 
 
 
 
2033
  }
2034
  }
2035
  }
@@ -2042,9 +2087,14 @@ class SimplyExclude
2042
  else
2043
  $tax_query['relation'] = "AND";
2044
 
 
 
 
2045
  $query->set('tax_query', $tax_query);
2046
  }
2047
- //echo "query<pre>"; print_r($query); echo "</pre>";
 
 
2048
  }
2049
 
2050
  return $query;
@@ -2853,7 +2903,7 @@ class SimplyExclude
2853
 
2854
  <h3><a href="#">Can I use the Simply Exclude plugin to include other Post Types on my front page?</a></h3>
2855
  <div>
2856
- <p>Short answer, YES! Longer answer. This can be done but you need to be careful with the setup.</p>
2857
 
2858
  <p>First, some assumptions about your WordPress setup. You MUST be able to answer <strong>YES</strong> to the following</p>
2859
  <ol>
@@ -2864,13 +2914,17 @@ class SimplyExclude
2864
  <p>Here is the setup</p>
2865
  <ol>
2866
  <li>Go to the Simply Exclude <a href="admin.php?page=se_manage_settings">Settings panel</a>. Location the Post Type you want to manage</li>
2867
- <li>On the sub-panel ensure the Post Type is <strong>Active</strong>.</li>
2868
- <li>Next, find the row for <strong>Front/Home</strong>. Ensure the selection is set to <strong>Include All</strong></li>
2869
- <li>Finally, ensure the <strong>Show/Hide</strong> option is set to <strong>Show</strong>.</li>
2870
- <li>Now navigate to the Post Type listing. This is important. You must ensure no items are set to <strong>Include Only</strong> or <strong>Exclude</strong>.</li>
2871
  </ol>
 
 
 
 
 
 
2872
 
2873
- <p>Note you can also use the <strong>Include all</strong> on the Feeds actions for Post Types</p>
2874
  </div>
2875
 
2876
  <h3><a href="#">I've configured the plugin to Include/Exclude a combination of Taxonomies and Post Types. Now my site is all messed up. How do I reset things to the default?</a></h3>
4
  Plugin URI: http://www.codehooligans.com/projects/wordpress/simply-exclude/
5
  Description: Provides an interface to selectively exclude/include categories, tags and page from the 4 actions used by WordPress. is_front, is_archive, is_search, is_feed.
6
  Author: Paul Menard
7
+ Version: 2.0.3
8
  Author URI: http://www.codehooligans.com
9
 
10
  Revision history
21
  2.0 - 2012-03-03 Full rewrite of the plugin to support custom Taxonomies and Custom Post Types. Added support for managing items within the Taxonomy/Post Type panels. Added support for exclude/include on Post instead of just Categories and Tags. Dropped support for third-party plugins like Google XML Sitemaps and Seach Unleashed (Sorry!). Now correctly supporting Pages seach excludes. Yah!.
22
  2.0.1 - 2012-03-04 Small bug. On the new Simply Exclude Help panel I user the jQuery UI Accordion package. Seems I failed to check this when setting the minimum WordPress version I was supporting (3.2). Seems jQuery UI Accordion is not available in core WordPress until version 3.3. So have added my own libraries to cover the older versions of WordPress. Sorry about that. And thanks to @biswajeet for bringing this up in the WordPress forums.
23
  2.0.2 - 2012-03-05 Fixed some issues when converting from the previous version of the Simply Exclude configurations.
24
+ 2.0.3 - 2012-03-18 Fixes to core filtering logic.
25
  */
26
 
27
  define('SIMPLY_EXCLUDE_I18N_DOMAIN', 'simplyexclude');
45
 
46
  public function __construct() {
47
 
48
+ $this->se_version = "2.0.3";
49
 
50
  $this->admin_menu_label = __("Simply Exclude", SIMPLY_EXCLUDE_I18N_DOMAIN);
51
  $this->options_key = "simplyexclude_v2";
67
  add_action( 'wp_ajax_se_update', array(&$this, 'se_ajax_update') );
68
 
69
  // Used to limit the categories displayed on the home page. Simple
70
+ add_filter('pre_get_posts', array(&$this,'se_filters'), 999);
71
  }
72
 
73
  function admin_init_proc()
1897
 
1898
  function se_filters($query)
1899
  {
1900
+ global $wp_version;
1901
 
1902
+ // We don't process filtering for admin. ever!
1903
+ if (is_admin())
1904
  return $query;
1905
+
1906
+ if ( version_compare( $wp_version, '3.3.0', '<' ) ) {
1907
+
1908
+ global $wp_the_query;
1909
+ return $wp_the_query === $query;
1910
+ return $query;
1911
+
1912
+ } else {
1913
+ if (!is_main_query())
1914
+ return $query;
1915
+ }
1916
+
1917
 
1918
  // Ignore all queries from within wp-admin.
1919
  if ($query->is_admin)
1921
 
1922
  $this->se_load_config();
1923
 
1924
+ // Check our debug
1925
+ if (isset($_GET['SE_DEBUG']))
1926
+ $se_debug = true;
1927
+ else
1928
+ $se_debug = false;
1929
+
1930
+
1931
  $action_data = array();
1932
+
1933
  // Only filter on our actions.
1934
  if (($query->is_home) || ($query->is_posts_page))
1935
  {
1939
  {
1940
  $action_data = $this->se_get_action_data('is_search');
1941
  }
 
 
 
 
1942
  else if ($query->is_feed)
1943
  {
1944
  $action_data = $this->se_get_action_data('is_feed');
1945
  }
1946
+ else if ($query->is_archive)
1947
+ {
1948
+ $action_data = $this->se_get_action_data('is_archive');
1949
+ }
1950
 
1951
+ if (( current_user_can('manage_options') ) && ( $se_debug == true ) ){
1952
+ echo "action_data<pre>"; print_r($action_data); echo "</pre>";
1953
+ }
1954
+
1955
  if ($action_data)
1956
  {
1957
  $tax_query = array();
1958
  $tax_query_relation = array();
1959
+
1960
  foreach($action_data as $key => $key_data)
1961
  {
 
 
1962
  if ($key == "taxonomies")
1963
  {
1964
  foreach($key_data as $key_key => $key_key_data)
1965
  {
 
 
 
1966
  $tax_args = array(
1967
  'taxonomy' => $key_key,
1968
  'field' => 'id',
1988
  $post_types_array = array();
1989
  $post__in = array();
1990
  $post__not_in = array();
1991
+ $post__all = array();
1992
  foreach($key_data as $key_key => $key_key_data)
1993
+ {
1994
+ if ($key_key_data['actions'] == 'e') {
 
 
 
 
1995
  $post__not_in = array_merge($post__not_in, $key_key_data['terms']);
1996
+ $post_types_array['__not_in'][] = $key_key;
1997
+
1998
+ } else if ($key_key_data['actions'] == 'i') {
1999
+ $post__in = array_merge($post__in, $key_key_data['terms']);
2000
+ $post_types_array['__in'][] = $key_key;
2001
+ } else if ($key_key_data['actions'] == 'a') {
2002
+ $post_types_array['all'][] = $key_key;
2003
+ }
2004
  }
2005
+
2006
+ $query_post_types = $query->get('post_type');
2007
+ if (!$query_post_types) {
2008
+ if (isset($_GET['post_type'])) {
2009
+ $query_post_types = explode(',', $_GET['post_type']);
2010
+ if ($query_post_types) {
2011
+ foreach($query_post_types as $idx => $post_type) {
2012
+ $query_post_types[$idx] = trim($post_type);
2013
+ }
2014
+ }
2015
+ }
2016
+ }
2017
+ if (!$query_post_types) $query_post_types = array();
2018
+ else if (!is_array($query_post_types))
2019
+ {
2020
+ $query_post_types = array($query_post_types);
2021
+ }
2022
+ if (( current_user_can('manage_options') ) && ( $se_debug == true ) ){
2023
+ echo "query_post_types<pre>"; print_r($query_post_types); echo "</pre>";
2024
+ echo "post_types_array<pre>"; print_r($post_types_array); echo "</pre>";
2025
+ }
2026
+
2027
 
2028
  if (count($post__not_in))
2029
  {
 
 
2030
  $query->set('post__not_in', $post__not_in);
2031
+
2032
+ if (( current_user_can('manage_options') ) && ( $se_debug == true ) ){
2033
+
2034
+ echo "PROCESSING: POST__NOT_IN<br />";
2035
+ echo "post__not_in<pre>"; print_r($post__not_in); echo "</pre>";
2036
+ }
2037
  }
2038
  else if (count($post__in))
2039
  {
 
 
2040
  $query->set('post__in', $post__in);
2041
+
2042
+ if (isset($post_types_array['__in']))
2043
+ {
2044
+ $merged_query_post_types = array_unique(array_merge($post_types_array['__in'], $query_post_types));
2045
+ $query->set('post_type', $merged_query_post_types);
2046
+ }
2047
+ if (( current_user_can('manage_options') ) && ( $se_debug == true ) ){
2048
+ echo "PROCESSING: POST__IN<br />";
2049
+ echo "post__in<pre>"; print_r($post__in); echo "</pre>";
2050
+ echo "merged_query_post_types<pre>"; print_r($merged_query_post_types); echo "</pre>";
2051
+ }
2052
+ }
2053
+ else if ((isset($post_types_array['all'])) && (count($post_types_array['all'])))
2054
  {
2055
+ $merged_query_post_types = array_unique(array_merge($post_types_array['all'], $query_post_types));
 
 
2056
 
2057
+ if (( current_user_can('manage_options') ) && ( $se_debug == true ) ){
2058
+ echo "post_types_array[all]<pre>"; print_r($post_types_array['all']); echo "</pre>";
2059
+ echo "merged_query_post_types<pre>"; print_r($merged_query_post_types); echo "</pre>";
2060
+ }
2061
+ $query->set('post_type', $merged_query_post_types);
2062
+ }
2063
  }
2064
  else if ($key == "se_types")
2065
  {
2066
  foreach($key_data as $key_key => $key_key_data)
2067
  {
 
 
 
2068
  if ($key_key == "users")
2069
  {
2070
  $user_ids = $this->se_listify_ids($key_key_data['terms'], $key_key_data['actions']);
 
2071
  if ($user_ids)
2072
  {
2073
  $query->set('author', $user_ids);
2074
+
2075
+ if (( current_user_can('manage_options') ) && ( $se_debug == true ) ){
2076
+ echo "user_ids=[". $user_ids ."]<br />";
2077
+ }
2078
  }
2079
  }
2080
  }
2087
  else
2088
  $tax_query['relation'] = "AND";
2089
 
2090
+ if (( current_user_can('manage_options') ) && ( $se_debug == true ) ){
2091
+ echo "tax_query<pre>"; print_r($tax_query); echo "</pre>";
2092
+ }
2093
  $query->set('tax_query', $tax_query);
2094
  }
2095
+ if (( current_user_can('manage_options') ) && ( $se_debug == true ) ){
2096
+ echo "query<pre>"; print_r($query); echo "</pre>";
2097
+ }
2098
  }
2099
 
2100
  return $query;
2903
 
2904
  <h3><a href="#">Can I use the Simply Exclude plugin to include other Post Types on my front page?</a></h3>
2905
  <div>
2906
+ <p>Short answer, YES! Longer answer. This can be done but you need to be careful with the setup. This <em>could</em> effect how other post_types are displayed.</p>
2907
 
2908
  <p>First, some assumptions about your WordPress setup. You MUST be able to answer <strong>YES</strong> to the following</p>
2909
  <ol>
2914
  <p>Here is the setup</p>
2915
  <ol>
2916
  <li>Go to the Simply Exclude <a href="admin.php?page=se_manage_settings">Settings panel</a>. Location the Post Type you want to manage</li>
2917
+ <li>On the sub-panel ensure the Post Type is <strong>Active</strong>. Next, find the row for <strong>Front/Home</strong>. Ensure the selection is set to <strong>Include All</strong>. Finally, ensure the <strong>Show/Hide</strong> option is set to <strong>Show</strong>.</li>
2918
+ <li>Now navigate to the Post Type listing. This is important. You must ensure no items are set to <strong>Include Only</strong> or <strong>Exclude</strong> for this Post Type.</li>
 
 
2919
  </ol>
2920
+
2921
+ <p><strong>Notes:</strong></p>
2922
+ <p>You can mix Post Types to include on the Home/Front page. For example you have a custom Post Type Books and you want to show Books and Posts on the Home/Front page. You should set both Post Types to <strong>Include All</strong>. You would also set one or both Post Types to <strong>Include only</strong>. The result is only those checked items will be includes. Similar results setting the Post Types to <strong>Exclude</strong> will exclude only those Post Type item.</li>
2923
+ But the process is trial and errors. You need to make sure you review this in your own setup.</p>
2924
+
2925
+ <p>Also beware of setting one Post Type to <strong>Include all</strong> or <strong>Include only</strong> then setting a second Post Type as <strong>Exclude</strong>. The <strong>Exclude</strong> Post Type items will be processed while the <strong>Include all/only</strong> items will be ignored</p>
2926
 
2927
+ <p>You can also use the <strong>Include all</strong> on the Feeds actions for Post Types</p>
2928
  </div>
2929
 
2930
  <h3><a href="#">I've configured the plugin to Include/Exclude a combination of Taxonomies and Post Types. Now my site is all messed up. How do I reset things to the default?</a></h3>