Search Exclude - Version 1.2.6

Version Description

  • Fix compatibility with WordPress 5.5
Download this release

Release Info

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

Code changes from version 1.2.5 to 1.2.6

Files changed (3) hide show
  1. js/search_exclude.js +1 -1
  2. readme.txt +20 -3
  3. search-exclude.php +329 -329
js/search_exclude.js CHANGED
@@ -22,7 +22,7 @@
22
  }
23
  };
24
 
25
- $('#bulk_edit').live( 'click', function() {
26
  // define the bulk edit row
27
  var $bulk_row = $( '#bulk-edit' );
28
 
22
  }
23
  };
24
 
25
+ $('body').on( 'click', '#bulk_edit', function() {
26
  // define the bulk edit row
27
  var $bulk_row = $( '#bulk-edit' );
28
 
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: 5.3
6
- Stable tag: 1.2.5
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -27,7 +27,21 @@ On the plugin settings page you can also see the list of all the items that are
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
 
@@ -78,6 +92,9 @@ function filterForProducts($exclude, $query)
78
 
79
  == Changelog ==
80
 
 
 
 
81
  = 1.2.5 =
82
  * Security release. More protection added.
83
 
2
  Contributors: pronskiy, williamdodson, stevelock
3
  Tags: admin, plugin, search
4
  Requires at least: 3.3
5
+ Tested up to: 6.0
6
+ Stable tag: 1.2.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
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
+ If you want posts/pages to be hidden from search engines you may add the following snippet to your `functions.php`:
33
+ `
34
+ function add_meta_for_search_excluded()
35
+ {
36
+ global $post;
37
+ if (false !== array_search($post->ID, get_option('sep_exclude', array()))) {
38
+ echo '<meta name="robots" content="noindex,nofollow" />', "\n";
39
+ }
40
+ }
41
+ add_action('wp_head', 'add_meta_for_search_excluded');
42
+ `
43
+
44
+ Note: already indexed pages will remain indexed for quite a while. In order to remove them from Google index, you may use Google Search Console (or similar tool for other engines).
45
 
46
  = Are there any hooks or actions available to customize plugin behaviour? =
47
 
92
 
93
  == Changelog ==
94
 
95
+ = 1.2.6 =
96
+ * Fix compatibility with WordPress 5.5
97
+
98
  = 1.2.5 =
99
  * Security release. More protection added.
100
 
search-exclude.php CHANGED
@@ -1,329 +1,329 @@
1
- <?php
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.5
6
- Author: Roman Pronskiy
7
- Author URI: http://pronskiy.com
8
- Plugin URI: http://wordpress.org/plugins/search-exclude/
9
- */
10
-
11
- /*
12
- Copyright (c) 2012-2019 Roman Pronskiy
13
-
14
- This program is free software; you can redistribute it and/or modify
15
- it under the terms of the GNU General Public License as published by
16
- the Free Software Foundation; either version 3 of the License, or
17
- (at your option) any later version.
18
-
19
- This program is distributed in the hope that it will be useful,
20
- but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
- GNU General Public License for more details.
23
-
24
- You should have received a copy of the GNU General Public License
25
- along with this program. If not, see <http://www.gnu.org/licenses/>.
26
- */
27
-
28
- class SearchExclude
29
- {
30
- protected $excluded;
31
-
32
- public function __construct()
33
- {
34
- $this->registerHooks();
35
- }
36
-
37
- public function registerHooks()
38
- {
39
- register_activation_hook( __FILE__, array($this, 'activate') );
40
- add_action('admin_init', array($this, 'saveOptions') );
41
- add_action('admin_menu', array($this, 'adminMenu'));
42
- add_action('post_updated', array($this, 'postSave'));
43
- add_action('edit_attachment', array($this, 'postSave'));
44
- add_action('add_meta_boxes', array($this, 'addMetabox') );
45
- add_filter('pre_get_posts', array($this, 'searchFilter'));
46
-
47
- add_filter('bbp_has_replies_query', array($this, 'flagBbPress'));
48
-
49
- add_filter('manage_posts_columns', array($this, 'addColumn'));
50
- add_filter('manage_pages_columns', array($this, 'addColumn'));
51
- add_action('manage_posts_custom_column', array($this, 'populateColumnValue'), 10, 2);
52
- add_action('manage_pages_custom_column', array($this, 'populateColumnValue'), 10, 2);
53
- add_action('bulk_edit_custom_box', array($this, 'addBulkEditCustomBox'));
54
- add_action('quick_edit_custom_box', array($this, 'addQuickEditCustomBox'));
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
- /**
88
- * @param $postId int the ID of the post
89
- * @param $exclude bool indicates whether post should be excluded from the search results or not
90
- */
91
- protected function savePostIdToSearchExclude($postId, $exclude)
92
- {
93
- $this->savePostIdsToSearchExclude(array(intval($postId)), $exclude);
94
- }
95
-
96
- public function savePostIdsToSearchExclude($postIds, $exclude)
97
- {
98
- $exclude = (bool) $exclude;
99
- $excluded = $this->getExcluded();
100
-
101
- if ($exclude) {
102
- $excluded = array_unique(array_merge($excluded, $postIds));
103
- } else {
104
- $excluded = array_diff($excluded, $postIds);
105
- }
106
- $this->saveExcluded($excluded);
107
- }
108
-
109
- /**
110
- * @param $excluded array IDs of posts to be saved for excluding from the search results
111
- */
112
- protected function saveExcluded($excluded)
113
- {
114
- update_option('sep_exclude', $excluded);
115
- $this->excluded = $excluded;
116
- }
117
-
118
- protected function getExcluded()
119
- {
120
- if (null === $this->excluded) {
121
- $this->excluded = get_option('sep_exclude');
122
- if (!is_array($this->excluded)) {
123
- $this->excluded = array();
124
- }
125
- }
126
-
127
- return $this->excluded;
128
- }
129
-
130
- protected function isExcluded($postId)
131
- {
132
- return false !== array_search($postId, $this->getExcluded());
133
- }
134
-
135
- protected function view($view, $params = array())
136
- {
137
- extract($params);
138
- include(dirname(__FILE__) . '/views/' . $view . '.php');
139
- }
140
-
141
- public function saveBulkEdit()
142
- {
143
- check_ajax_referer( 'search_exclude_bulk_edit', '_wpnonce_search_exclude_bulk_edit' );
144
- $this->checkPermissions();
145
- $postIds = !empty($_POST['post_ids']) ? $this->filterPostIds($_POST[ 'post_ids' ]) : false;
146
- $exclude = isset($_POST['sep_exclude']) && '' !== $_POST['sep_exclude']
147
- ? filter_var($_POST['sep_exclude'], FILTER_VALIDATE_BOOLEAN)
148
- : null;
149
- if (is_array($postIds) && null !== $exclude) {
150
- $this->savePostIdsToSearchExclude($postIds, $exclude);
151
- }
152
- }
153
-
154
- private function filterPostIds($postIds)
155
- {
156
- return array_filter(filter_var($postIds, FILTER_VALIDATE_INT, FILTER_FORCE_ARRAY));
157
- }
158
-
159
- public function enqueueEditScripts()
160
- {
161
- wp_enqueue_script(
162
- 'search-exclude-admin-edit',
163
- plugin_dir_url( __FILE__ ) . 'js/search_exclude.js',
164
- array( 'jquery', 'inline-edit-post' ),
165
- '',
166
- true
167
- );
168
- }
169
-
170
- public function addStyle()
171
- {
172
- wp_register_style('search-exclude-stylesheet', plugins_url('/css/style.css', __FILE__ ));
173
- wp_enqueue_style('search-exclude-stylesheet');
174
- }
175
-
176
- public function addQuickEditCustomBox($columnName)
177
- {
178
- if ('search_exclude' == $columnName) {
179
- $this->view('quick_edit');
180
- }
181
- }
182
-
183
- public function addBulkEditCustomBox($columnName)
184
- {
185
- if ('search_exclude' == $columnName) {
186
- $this->view('bulk_edit');
187
- }
188
- }
189
-
190
- public function addColumn($columns)
191
- {
192
- $columns['search_exclude'] = 'Search Exclude';
193
- return $columns;
194
- }
195
-
196
- public function populateColumnValue($columnName, $postId)
197
- {
198
- if ('search_exclude' == $columnName) {
199
- $this->view('column_cell', array('exclude' => $this->isExcluded($postId), 'postId' => $postId));
200
- }
201
- }
202
-
203
- public function activate()
204
- {
205
- $excluded = $this->getExcluded();
206
-
207
- if (empty($excluded)) {
208
- $this->saveExcluded(array());
209
- }
210
- }
211
-
212
- public function addMetabox()
213
- {
214
- $currentScreen = get_current_screen();
215
- /* Do not show meta box on service pages */
216
- if (empty($currentScreen->post_type)) {
217
- return;
218
- }
219
- add_meta_box('sep_metabox_id', 'Search Exclude', array($this, 'metabox'), null, 'side');
220
- }
221
-
222
- public function metabox($post)
223
- {
224
- wp_nonce_field( 'sep_metabox_nonce', 'metabox_nonce' );
225
- $this->view('metabox', array('exclude' => $this->isExcluded($post->ID)));
226
- }
227
-
228
- public function adminMenu()
229
- {
230
- add_options_page(
231
- 'Search Exclude',
232
- 'Search Exclude',
233
- 'manage_options',
234
- 'search_exclude',
235
- array($this, 'options')
236
- );
237
- }
238
-
239
- public function searchFilter($query)
240
- {
241
- $exclude =
242
- (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX))
243
- && $query->is_search
244
- && !$this->isBbPress($query);
245
-
246
- $exclude = apply_filters('searchexclude_filter_search', $exclude, $query);
247
-
248
- if ($exclude) {
249
- $query->set('post__not_in', array_merge(array(), $this->getExcluded()));
250
- }
251
-
252
- return $query;
253
- }
254
-
255
- public function isBbPress($query)
256
- {
257
- return $query->get('___s2_is_bbp_has_replies');
258
- }
259
-
260
- /**
261
- * Flags a WP Query has being a `bbp_has_replies()` query.
262
- * @attaches-to ``add_filter('bbp_has_replies_query');``
263
- *
264
- * @param array $args Query arguments passed by the filter.
265
- *
266
- * @return array The array of ``$args``.
267
- *
268
- * @see Workaround for bbPress and the `s` key. See: <http://bit.ly/1obLpv4>
269
- */
270
- public function flagBbPress($args)
271
- {
272
- return array_merge($args, array('___s2_is_bbp_has_replies' => true));
273
- }
274
-
275
- public function postSave($postId)
276
- {
277
- if (!isset($_POST['sep'])) return $postId;
278
-
279
- $sep = $_POST['sep'];
280
- $exclude = (isset($sep['exclude'])) ? filter_var($sep['exclude'], FILTER_VALIDATE_BOOLEAN) : false;
281
-
282
- $this->savePostIdToSearchExclude($postId, $exclude);
283
-
284
- return $postId;
285
- }
286
-
287
- public function options()
288
- {
289
- $excluded = $this->getExcluded();
290
- $query = new WP_Query( array(
291
- 'post_type' => 'any',
292
- 'post_status' => 'any',
293
- 'post__in' => $excluded,
294
- 'order'=>'ASC',
295
- 'nopaging' => true,
296
- ));
297
- $this->view(
298
- 'options',
299
- array(
300
- 'excluded' => $excluded,
301
- 'query' => $query,
302
- )
303
- );
304
- }
305
-
306
- public function saveOptions()
307
- {
308
- if (!isset($_POST['search_exclude_submit'])) {
309
- return;
310
- }
311
-
312
- check_admin_referer( 'search_exclude_submit' );
313
-
314
- $this->checkPermissions();
315
-
316
- $excluded = $this->filterPostIds($_POST['sep_exclude']);
317
- $this->saveExcluded($excluded);
318
- }
319
-
320
- private function checkPermissions()
321
- {
322
- $capability = apply_filters('searchexclude_filter_permissions', 'edit_others_pages');
323
-
324
- if ( !current_user_can($capability) ) {
325
- wp_die( 'Not enough permissions', '', ['response' => 401, 'exit' => true] );
326
- }
327
- }
328
- }
329
- $pluginSearchExclude = new SearchExclude();
1
+ <?php
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.6
6
+ Author: Roman Pronskiy
7
+ Author URI: http://pronskiy.com
8
+ Plugin URI: http://wordpress.org/plugins/search-exclude/
9
+ */
10
+
11
+ /*
12
+ Copyright (c) 2012-2022 Roman Pronskiy
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 3 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
26
+ */
27
+
28
+ class SearchExclude
29
+ {
30
+ protected $excluded;
31
+
32
+ public function __construct()
33
+ {
34
+ $this->registerHooks();
35
+ }
36
+
37
+ public function registerHooks()
38
+ {
39
+ register_activation_hook( __FILE__, array($this, 'activate') );
40
+ add_action('admin_init', array($this, 'saveOptions') );
41
+ add_action('admin_menu', array($this, 'adminMenu'));
42
+ add_action('post_updated', array($this, 'postSave'));
43
+ add_action('edit_attachment', array($this, 'postSave'));
44
+ add_action('add_meta_boxes', array($this, 'addMetabox') );
45
+ add_filter('pre_get_posts', array($this, 'searchFilter'));
46
+
47
+ add_filter('bbp_has_replies_query', array($this, 'flagBbPress'));
48
+
49
+ add_filter('manage_posts_columns', array($this, 'addColumn'));
50
+ add_filter('manage_pages_columns', array($this, 'addColumn'));
51
+ add_action('manage_posts_custom_column', array($this, 'populateColumnValue'), 10, 2);
52
+ add_action('manage_pages_custom_column', array($this, 'populateColumnValue'), 10, 2);
53
+ add_action('bulk_edit_custom_box', array($this, 'addBulkEditCustomBox'));
54
+ add_action('quick_edit_custom_box', array($this, 'addQuickEditCustomBox'));
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
+ /**
88
+ * @param $postId int the ID of the post
89
+ * @param $exclude bool indicates whether post should be excluded from the search results or not
90
+ */
91
+ protected function savePostIdToSearchExclude($postId, $exclude)
92
+ {
93
+ $this->savePostIdsToSearchExclude(array(intval($postId)), $exclude);
94
+ }
95
+
96
+ public function savePostIdsToSearchExclude($postIds, $exclude)
97
+ {
98
+ $exclude = (bool) $exclude;
99
+ $excluded = $this->getExcluded();
100
+
101
+ if ($exclude) {
102
+ $excluded = array_unique(array_merge($excluded, $postIds));
103
+ } else {
104
+ $excluded = array_diff($excluded, $postIds);
105
+ }
106
+ $this->saveExcluded($excluded);
107
+ }
108
+
109
+ /**
110
+ * @param $excluded array IDs of posts to be saved for excluding from the search results
111
+ */
112
+ protected function saveExcluded($excluded)
113
+ {
114
+ update_option('sep_exclude', $excluded);
115
+ $this->excluded = $excluded;
116
+ }
117
+
118
+ protected function getExcluded()
119
+ {
120
+ if (null === $this->excluded) {
121
+ $this->excluded = get_option('sep_exclude');
122
+ if (!is_array($this->excluded)) {
123
+ $this->excluded = array();
124
+ }
125
+ }
126
+
127
+ return $this->excluded;
128
+ }
129
+
130
+ protected function isExcluded($postId)
131
+ {
132
+ return false !== array_search($postId, $this->getExcluded());
133
+ }
134
+
135
+ protected function view($view, $params = array())
136
+ {
137
+ extract($params);
138
+ include(dirname(__FILE__) . '/views/' . $view . '.php');
139
+ }
140
+
141
+ public function saveBulkEdit()
142
+ {
143
+ check_ajax_referer( 'search_exclude_bulk_edit', '_wpnonce_search_exclude_bulk_edit' );
144
+ $this->checkPermissions();
145
+ $postIds = !empty($_POST['post_ids']) ? $this->filterPostIds($_POST[ 'post_ids' ]) : false;
146
+ $exclude = isset($_POST['sep_exclude']) && '' !== $_POST['sep_exclude']
147
+ ? filter_var($_POST['sep_exclude'], FILTER_VALIDATE_BOOLEAN)
148
+ : null;
149
+ if (is_array($postIds) && null !== $exclude) {
150
+ $this->savePostIdsToSearchExclude($postIds, $exclude);
151
+ }
152
+ }
153
+
154
+ private function filterPostIds($postIds)
155
+ {
156
+ return array_filter(filter_var($postIds, FILTER_VALIDATE_INT, FILTER_FORCE_ARRAY));
157
+ }
158
+
159
+ public function enqueueEditScripts()
160
+ {
161
+ wp_enqueue_script(
162
+ 'search-exclude-admin-edit',
163
+ plugin_dir_url( __FILE__ ) . 'js/search_exclude.js',
164
+ array( 'jquery', 'inline-edit-post' ),
165
+ '',
166
+ true
167
+ );
168
+ }
169
+
170
+ public function addStyle()
171
+ {
172
+ wp_register_style('search-exclude-stylesheet', plugins_url('/css/style.css', __FILE__ ));
173
+ wp_enqueue_style('search-exclude-stylesheet');
174
+ }
175
+
176
+ public function addQuickEditCustomBox($columnName)
177
+ {
178
+ if ('search_exclude' == $columnName) {
179
+ $this->view('quick_edit');
180
+ }
181
+ }
182
+
183
+ public function addBulkEditCustomBox($columnName)
184
+ {
185
+ if ('search_exclude' == $columnName) {
186
+ $this->view('bulk_edit');
187
+ }
188
+ }
189
+
190
+ public function addColumn($columns)
191
+ {
192
+ $columns['search_exclude'] = 'Search Exclude';
193
+ return $columns;
194
+ }
195
+
196
+ public function populateColumnValue($columnName, $postId)
197
+ {
198
+ if ('search_exclude' == $columnName) {
199
+ $this->view('column_cell', array('exclude' => $this->isExcluded($postId), 'postId' => $postId));
200
+ }
201
+ }
202
+
203
+ public function activate()
204
+ {
205
+ $excluded = $this->getExcluded();
206
+
207
+ if (empty($excluded)) {
208
+ $this->saveExcluded(array());
209
+ }
210
+ }
211
+
212
+ public function addMetabox()
213
+ {
214
+ $currentScreen = get_current_screen();
215
+ /* Do not show meta box on service pages */
216
+ if (empty($currentScreen->post_type)) {
217
+ return;
218
+ }
219
+ add_meta_box('sep_metabox_id', 'Search Exclude', array($this, 'metabox'), null, 'side');
220
+ }
221
+
222
+ public function metabox($post)
223
+ {
224
+ wp_nonce_field( 'sep_metabox_nonce', 'metabox_nonce' );
225
+ $this->view('metabox', array('exclude' => $this->isExcluded($post->ID)));
226
+ }
227
+
228
+ public function adminMenu()
229
+ {
230
+ add_options_page(
231
+ 'Search Exclude',
232
+ 'Search Exclude',
233
+ 'manage_options',
234
+ 'search_exclude',
235
+ array($this, 'options')
236
+ );
237
+ }
238
+
239
+ public function searchFilter($query)
240
+ {
241
+ $exclude =
242
+ (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX))
243
+ && $query->is_search
244
+ && !$this->isBbPress($query);
245
+
246
+ $exclude = apply_filters('searchexclude_filter_search', $exclude, $query);
247
+
248
+ if ($exclude) {
249
+ $query->set('post__not_in', array_merge(array(), $this->getExcluded()));
250
+ }
251
+
252
+ return $query;
253
+ }
254
+
255
+ public function isBbPress($query)
256
+ {
257
+ return $query->get('___s2_is_bbp_has_replies');
258
+ }
259
+
260
+ /**
261
+ * Flags a WP Query has being a `bbp_has_replies()` query.
262
+ * @attaches-to ``add_filter('bbp_has_replies_query');``
263
+ *
264
+ * @param array $args Query arguments passed by the filter.
265
+ *
266
+ * @return array The array of ``$args``.
267
+ *
268
+ * @see Workaround for bbPress and the `s` key. See: <http://bit.ly/1obLpv4>
269
+ */
270
+ public function flagBbPress($args)
271
+ {
272
+ return array_merge($args, array('___s2_is_bbp_has_replies' => true));
273
+ }
274
+
275
+ public function postSave($postId)
276
+ {
277
+ if (!isset($_POST['sep'])) return $postId;
278
+
279
+ $sep = $_POST['sep'];
280
+ $exclude = (isset($sep['exclude'])) ? filter_var($sep['exclude'], FILTER_VALIDATE_BOOLEAN) : false;
281
+
282
+ $this->savePostIdToSearchExclude($postId, $exclude);
283
+
284
+ return $postId;
285
+ }
286
+
287
+ public function options()
288
+ {
289
+ $excluded = $this->getExcluded();
290
+ $query = new WP_Query( array(
291
+ 'post_type' => 'any',
292
+ 'post_status' => 'any',
293
+ 'post__in' => $excluded,
294
+ 'order'=>'ASC',
295
+ 'nopaging' => true,
296
+ ));
297
+ $this->view(
298
+ 'options',
299
+ array(
300
+ 'excluded' => $excluded,
301
+ 'query' => $query,
302
+ )
303
+ );
304
+ }
305
+
306
+ public function saveOptions()
307
+ {
308
+ if (!isset($_POST['search_exclude_submit'])) {
309
+ return;
310
+ }
311
+
312
+ check_admin_referer( 'search_exclude_submit' );
313
+
314
+ $this->checkPermissions();
315
+
316
+ $excluded = $this->filterPostIds($_POST['sep_exclude']);
317
+ $this->saveExcluded($excluded);
318
+ }
319
+
320
+ private function checkPermissions()
321
+ {
322
+ $capability = apply_filters('searchexclude_filter_permissions', 'edit_others_pages');
323
+
324
+ if ( !current_user_can($capability) ) {
325
+ wp_die( 'Not enough permissions', '', ['response' => 401, 'exit' => true] );
326
+ }
327
+ }
328
+ }
329
+ $pluginSearchExclude = new SearchExclude();