Search Exclude - Version 1.2.2

Version Description

  • Added action searchexclude_hide_from_search
  • Added filter searchexclude_filter_search
  • Fixed Bulk actions for Firefox
Download this release

Release Info

Developer pronskiy
Plugin Icon 128x128 Search Exclude
Version 1.2.2
Comparing to
See all releases

Code changes from version 1.2.1 to 1.2.2

Files changed (3) hide show
  1. js/search_exclude.js +1 -0
  2. readme.txt +57 -2
  3. search-exclude.php +38 -3
js/search_exclude.js CHANGED
@@ -40,6 +40,7 @@
40
  url: ajaxurl,
41
  type: 'POST',
42
  cache: false,
 
43
  data: {
44
  action: 'search_exclude_save_bulk_edit',
45
  post_ids: $post_ids,
40
  url: ajaxurl,
41
  type: 'POST',
42
  cache: false,
43
+ async: false, // Fixes bulk editing in FF, see https://wordpress.org/support/topic/bulk-search-exclude-doesnt-work
44
  data: {
45
  action: 'search_exclude_save_bulk_edit',
46
  post_ids: $post_ids,
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: pronskiy, williamdodson, stevelock
3
  Tags: admin, plugin, search
4
  Requires at least: 3.3
5
- Tested up to: 4.3
6
- Stable tag: 1.2.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -22,6 +22,55 @@ On the plugin settings page you can also see the list of all the items that are
22
  2. Activate the plugin through the 'Plugins' menu in WordPress
23
  3. Go to any post/page edit page and check off the checkbox `Exclude from Search Results` if you don't want the post/page to be shown in the search results
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  == Screenshots ==
26
 
27
  1. screenshot-1.png
@@ -29,9 +78,15 @@ On the plugin settings page you can also see the list of all the items that are
29
 
30
  == Changelog ==
31
 
 
 
 
 
 
32
  = 1.2.1 =
33
  * Fixed bug when unable to save post on PHP <5.5 because of boolval() usage
34
 
 
35
  = 1.2.0 =
36
  * Added quick and bulk edit support
37
  * Tested up to WP 4.1
2
  Contributors: pronskiy, williamdodson, stevelock
3
  Tags: admin, plugin, search
4
  Requires at least: 3.3
5
+ Tested up to: 4.9
6
+ Stable tag: 1.2.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
22
  2. Activate the plugin through the 'Plugins' menu in WordPress
23
  3. Go to any post/page edit page and check off the checkbox `Exclude from Search Results` if you don't want the post/page to be shown in the search results
24
 
25
+ == Frequently Asked Questions ==
26
+
27
+ = Does this plugin affect SEO? =
28
+
29
+ No, it does not affect crawling and indexing by search engines.
30
+ The only thing it does is hiding selected post/pages from your site search page. Not altering SEO indexing.
31
+
32
+ = Are there any hooks or actions available to customize plugin behaviour? =
33
+
34
+ Yes.
35
+ There is an action `searchexclude_hide_from_search`.
36
+ You can pass any post/page/custom_post ids as an array in the first parameter.
37
+ The second parameter specifies state of visibility in search. Pass true if you want to hide posts/pages,
38
+ or false - if you want show them in the search results.
39
+
40
+ Example:
41
+ Let's say you want "Exclude from Search Results" checkbox to be checked off by default
42
+ for newly created posts, but not pages. In this case you can add following code
43
+ to your theme's function.php:
44
+
45
+ `
46
+ add_filter('default_content', 'excludeNewPostByDefault', 10, 2);
47
+ function excludeNewPostByDefault($content, $post)
48
+ {
49
+ if ('post' === $post->post_type) {
50
+ do_action('searchexclude_hide_from_search', array($post->ID), true);
51
+ }
52
+ }
53
+ `
54
+
55
+ Also there is a filter `searchexclude_filter_search`.
56
+ With this filter you can turn on/off search filtering dynamically.
57
+ Parameters:
58
+ $exclude - current search filtering state (specifies whether to filter search or not)
59
+ $query - current WP_Query object
60
+
61
+ By returning true or false you can turn search filtering respectively.
62
+
63
+ Example:
64
+ Let's say you need to disable search filtering if searching by specific post_type.
65
+ In this case you could add following code to you functions.php:
66
+ `
67
+ add_filter('searchexclude_filter_search', 'filterForProducts', 10, 2);
68
+ function filterForProducts($exclude, $query)
69
+ {
70
+ return $exclude && 'product' !== $query->get('post_type');
71
+ }
72
+ `
73
+
74
  == Screenshots ==
75
 
76
  1. screenshot-1.png
78
 
79
  == Changelog ==
80
 
81
+ = 1.2.2 =
82
+ * Added action searchexclude_hide_from_search
83
+ * Added filter searchexclude_filter_search
84
+ * Fixed Bulk actions for Firefox
85
+
86
  = 1.2.1 =
87
  * Fixed bug when unable to save post on PHP <5.5 because of boolval() usage
88
 
89
+
90
  = 1.2.0 =
91
  * Added quick and bulk edit support
92
  * Tested up to WP 4.1
search-exclude.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Search Exclude
4
  Description: Hide any page or post from the WordPress search results by checking off the checkbox.
5
- Version: 1.2.1
6
  Author: Roman Pronskiy
7
  Author URI: http://pronskiy.com
8
  Plugin URI: http://wordpress.org/plugins/search-exclude/
@@ -55,6 +55,33 @@ class SearchExclude
55
  add_action('admin_print_scripts-edit.php', array($this, 'enqueueEditScripts'));
56
  add_action('wp_ajax_search_exclude_save_bulk_edit', array($this, 'saveBulkEdit'));
57
  add_action('admin_enqueue_scripts', array($this, 'addStyle'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  }
59
 
60
  /**
@@ -66,7 +93,7 @@ class SearchExclude
66
  $this->savePostIdsToSearchExclude(array(intval($postId)), $exclude);
67
  }
68
 
69
- protected function savePostIdsToSearchExclude($postIds, $exclude)
70
  {
71
  $exclude = (bool) $exclude;
72
  $excluded = $this->getExcluded();
@@ -202,9 +229,17 @@ class SearchExclude
202
 
203
  public function searchFilter($query)
204
  {
205
- if ((!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) && $query->is_search && !$this->isBbPress($query)) {
 
 
 
 
 
 
 
206
  $query->set('post__not_in', array_merge(array(), $this->getExcluded()));
207
  }
 
208
  return $query;
209
  }
210
 
2
  /*
3
  Plugin Name: Search Exclude
4
  Description: Hide any page or post from the WordPress search results by checking off the checkbox.
5
+ Version: 1.2.2
6
  Author: Roman Pronskiy
7
  Author URI: http://pronskiy.com
8
  Plugin URI: http://wordpress.org/plugins/search-exclude/
55
  add_action('admin_print_scripts-edit.php', array($this, 'enqueueEditScripts'));
56
  add_action('wp_ajax_search_exclude_save_bulk_edit', array($this, 'saveBulkEdit'));
57
  add_action('admin_enqueue_scripts', array($this, 'addStyle'));
58
+
59
+ /**
60
+ * Hook can be used outside of the plugin.
61
+ *
62
+ * You can pass any post/page/custom_post ids in the array with first parameter.
63
+ * The second parameter specifies states of visibility in search to be set.
64
+ * Pass true if you want to hide posts/pages, or false - if you want show them in the search results.
65
+ *
66
+ * Example:
67
+ * Let's say you want "Exclude from Search Results" checkbox to be checked off by default
68
+ * for newly created posts, but not pages. In this case you can add following code
69
+ * to your theme's function.php:
70
+ *
71
+ * <code>
72
+ * add_filter('default_content', 'excludeNewPostByDefault', 10, 2);
73
+ * function excludeNewPostByDefault($content, $post)
74
+ * {
75
+ * if ('post' === $post->post_type) {
76
+ * do_action('searchexclude_hide_from_search', array($post->ID), true);
77
+ * }
78
+ * }
79
+ * </code>
80
+ *
81
+ * @param array $postIds array of post IDs
82
+ * @param bool $hide
83
+ */
84
+ add_action('searchexclude_hide_from_search', array($this, 'savePostIdsToSearchExclude'), 10, 2);
85
  }
86
 
87
  /**
93
  $this->savePostIdsToSearchExclude(array(intval($postId)), $exclude);
94
  }
95
 
96
+ public function savePostIdsToSearchExclude($postIds, $exclude)
97
  {
98
  $exclude = (bool) $exclude;
99
  $excluded = $this->getExcluded();
229
 
230
  public function searchFilter($query)
231
  {
232
+ $exclude =
233
+ (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX))
234
+ && $query->is_search
235
+ && !$this->isBbPress($query);
236
+
237
+ $exclude = apply_filters('searchexclude_filter_search', $exclude, $query);
238
+
239
+ if ($exclude) {
240
  $query->set('post__not_in', array_merge(array(), $this->getExcluded()));
241
  }
242
+
243
  return $query;
244
  }
245