Search Exclude - Version 1.2.0

Version Description

  • Added quick and bulk edit support
  • Tested up to WP 4.1
Download this release

Release Info

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

Code changes from version 1.1.0 to 1.2.0

css/style.css ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ .fixed .column-search_exclude {
2
+ width: 12%;
3
+ }
4
+ .fixed .column-search_exclude div {
5
+ text-align: center;
6
+ }
7
+ .inline-edit-row fieldset label span.title.search-exclude-label {
8
+ width: 11em;
9
+ }
js/search_exclude.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($) {
2
+
3
+ // we create a copy of the WP inline edit post function
4
+ var $wp_inline_edit = inlineEditPost.edit;
5
+
6
+ // and then we overwrite the function with our own code
7
+ inlineEditPost.edit = function( id ) {
8
+
9
+ // "call" the original WP edit function
10
+ // we don't want to leave WordPress hanging
11
+ $wp_inline_edit.apply( this, arguments );
12
+
13
+ var $post_id = 0;
14
+ if ( typeof( id ) == 'object' ) {
15
+ $post_id = parseInt(this.getId(id));
16
+ }
17
+
18
+ if ( $post_id > 0 ) {
19
+ var $edit_row = $( '#edit-' + $post_id );
20
+ var $exclude = $( '#search-exclude-' + $post_id).data("search_exclude");
21
+ $edit_row.find( 'input[name="sep[exclude]"]' ).prop('checked', $exclude);
22
+ }
23
+ };
24
+
25
+ $('#bulk_edit').live( 'click', function() {
26
+ // define the bulk edit row
27
+ var $bulk_row = $( '#bulk-edit' );
28
+
29
+ // get the selected post ids that are being edited
30
+ var $post_ids = new Array();
31
+ $bulk_row.find('#bulk-titles').children().each( function() {
32
+ $post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) );
33
+ });
34
+
35
+ // get the search exclude value
36
+ var $exclude = $bulk_row.find('select[name="sep[exclude]"]').val();
37
+
38
+ // save the data
39
+ $.ajax({
40
+ url: ajaxurl,
41
+ type: 'POST',
42
+ cache: false,
43
+ data: {
44
+ action: 'search_exclude_save_bulk_edit',
45
+ post_ids: $post_ids,
46
+ sep_exclude: $exclude
47
+ }
48
+ });
49
+ });
50
+
51
+ })(jQuery);
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.0
6
- Stable tag: 1.1.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -11,9 +11,10 @@ Hide any post or page from the search results.
11
 
12
  == Description ==
13
 
14
- With this plugin you can exclude any page, post or whatever from the search results by checking off the corresponding checkbox on post/page edit page.
 
15
 
16
- You can also view the list of all the items that are excluded from search on the plugin settings page.
17
 
18
  == Installation ==
19
 
@@ -28,6 +29,10 @@ You can also view the list of all the items that are excluded from search on the
28
 
29
  == Changelog ==
30
 
 
 
 
 
31
  = 1.1.0 =
32
  * Tested up to WP 4.0
33
  * Do not show Plugin on some service pages in Admin
2
  Contributors: pronskiy, williamdodson, stevelock
3
  Tags: admin, plugin, search
4
  Requires at least: 3.3
5
+ Tested up to: 4.1
6
+ Stable tag: 1.2.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
11
 
12
  == Description ==
13
 
14
+ With this plugin you can exclude any page, post or whatever from the WordPress search results by checking off the corresponding checkbox on post/page edit page.
15
+ Supports quick and bulk edit.
16
 
17
+ On the plugin settings page you can also see the list of all the items that are hidden from search.
18
 
19
  == Installation ==
20
 
29
 
30
  == Changelog ==
31
 
32
+ = 1.2.0 =
33
+ * Added quick and bulk edit support
34
+ * Tested up to WP 4.1
35
+
36
  = 1.1.0 =
37
  * Tested up to WP 4.0
38
  * Do not show Plugin on some service pages in Admin
search-exclude.php CHANGED
@@ -1,15 +1,15 @@
1
  <?php
2
  /*
3
  Plugin Name: Search Exclude
4
- Description: Exclude any page or post from the WordPress search results by checking off the checkbox.
5
- Version: 1.1.0
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 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
@@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27
 
28
  class SearchExclude
29
  {
 
 
30
  public function __construct()
31
  {
32
  $this->registerHooks();
@@ -40,29 +42,39 @@ class SearchExclude
40
  add_action('post_updated', array($this, 'postSave'));
41
  add_action('edit_attachment', array($this, 'postSave'));
42
  add_action('add_meta_boxes', array($this, 'addMetabox') );
43
- add_filter('pre_get_posts',array($this, 'searchFilter'));
44
 
45
  add_filter('bbp_has_replies_query', array($this, 'flagBbPress'));
 
 
 
 
 
 
 
 
 
 
46
  }
47
 
48
  /**
49
  * @param $postId int the ID of the post
50
- * @param $value bool indicates whether post should be excluded from the search results or not
51
  */
52
- protected function savePostIdToSearchExclude($postId, $value)
 
 
 
 
 
53
  {
 
54
  $excluded = $this->getExcluded();
55
 
56
- $indSep = array_search($postId, $excluded);
57
- if ($value) {
58
- if (false === $indSep) {
59
- $excluded[] = $postId;
60
- }
61
- }
62
- else {
63
- if (false !== $indSep) {
64
- unset($excluded[$indSep]);
65
- }
66
  }
67
  $this->saveExcluded($excluded);
68
  }
@@ -73,19 +85,86 @@ class SearchExclude
73
  protected function saveExcluded($excluded)
74
  {
75
  update_option('sep_exclude', $excluded);
 
76
  }
77
 
78
  protected function getExcluded()
79
  {
80
- $excluded = get_option('sep_exclude');
 
 
 
 
 
 
 
 
81
 
82
- if (!is_array($excluded)) {
83
- $excluded = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
- return $excluded;
86
  }
87
 
88
- function activate()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  {
90
  $excluded = $this->getExcluded();
91
 
@@ -101,16 +180,13 @@ class SearchExclude
101
  if (empty($currentScreen->post_type)) {
102
  return;
103
  }
104
- add_meta_box( 'sep_metabox_id', 'Search Exclude', array($this, 'metabox'), null, 'side');
105
  }
106
 
107
  public function metabox($post)
108
  {
109
- $excluded = $this->getExcluded();
110
- $exclude = !(false === array_search($post->ID, $excluded));
111
-
112
  wp_nonce_field( 'sep_metabox_nonce', 'metabox_nonce' );
113
- include(dirname(__FILE__) . '/metabox.php');
114
  }
115
 
116
  public function adminMenu()
@@ -152,22 +228,21 @@ class SearchExclude
152
  return array_merge($args, array('___s2_is_bbp_has_replies' => true));
153
  }
154
 
155
- public function postSave( $post_id )
156
  {
157
- if (!isset($_POST['sep'])) return $post_id;
158
 
159
  $sep = $_POST['sep'];
160
  $exclude = (isset($sep['exclude'])) ? $sep['exclude'] : 0 ;
161
 
162
- $this->savePostIdToSearchExclude($post_id, $exclude);
163
 
164
- return $post_id;
165
  }
166
 
167
  public function options()
168
  {
169
  $excluded = $this->getExcluded();
170
-
171
  $query = new WP_Query( array(
172
  'post_type' => 'any',
173
  'post_status' => 'any',
@@ -175,7 +250,13 @@ class SearchExclude
175
  'order'=>'ASC',
176
  'nopaging' => true,
177
  ));
178
- include(dirname(__FILE__) . '/options.php');
 
 
 
 
 
 
179
  }
180
 
181
  public function saveOptions()
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.0
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-2015 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
27
 
28
  class SearchExclude
29
  {
30
+ protected $excluded;
31
+
32
  public function __construct()
33
  {
34
  $this->registerHooks();
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
  /**
61
  * @param $postId int the ID of the post
62
+ * @param $exclude bool indicates whether post should be excluded from the search results or not
63
  */
64
+ protected function savePostIdToSearchExclude($postId, $exclude)
65
+ {
66
+ $this->savePostIdsToSearchExclude(array(intval($postId)), $exclude);
67
+ }
68
+
69
+ protected function savePostIdsToSearchExclude($postIds, $exclude)
70
  {
71
+ $exclude = boolval($exclude);
72
  $excluded = $this->getExcluded();
73
 
74
+ if ($exclude) {
75
+ $excluded = array_unique(array_merge($excluded, $postIds));
76
+ } else {
77
+ $excluded = array_diff($excluded, $postIds);
 
 
 
 
 
 
78
  }
79
  $this->saveExcluded($excluded);
80
  }
85
  protected function saveExcluded($excluded)
86
  {
87
  update_option('sep_exclude', $excluded);
88
+ $this->excluded = $excluded;
89
  }
90
 
91
  protected function getExcluded()
92
  {
93
+ if (null === $this->excluded) {
94
+ $this->excluded = get_option('sep_exclude');
95
+ if (!is_array($this->excluded)) {
96
+ $this->excluded = array();
97
+ }
98
+ }
99
+
100
+ return $this->excluded;
101
+ }
102
 
103
+ protected function isExcluded($postId)
104
+ {
105
+ return false !== array_search($postId, $this->getExcluded());
106
+ }
107
+
108
+ protected function view($view, $params = array())
109
+ {
110
+ extract($params);
111
+ include(dirname(__FILE__) . '/views/' . $view . '.php');
112
+ }
113
+
114
+ public function saveBulkEdit()
115
+ {
116
+ $postIds = !empty($_POST['post_ids']) ? $_POST[ 'post_ids' ] : false;
117
+ $exclude = isset($_POST['sep_exclude']) && '' !== $_POST['sep_exclude'] ? $_POST[ 'sep_exclude' ] : null;
118
+ if (is_array($postIds) && null !== $exclude) {
119
+ $this->savePostIdsToSearchExclude($postIds, $exclude);
120
  }
 
121
  }
122
 
123
+ public function enqueueEditScripts()
124
+ {
125
+ wp_enqueue_script(
126
+ 'search-exclude-admin-edit',
127
+ plugin_dir_url( __FILE__ ) . 'js/search_exclude.js',
128
+ array( 'jquery', 'inline-edit-post' ),
129
+ '',
130
+ true
131
+ );
132
+ }
133
+
134
+ public function addStyle()
135
+ {
136
+ wp_register_style('search-exclude-stylesheet', plugins_url('/css/style.css', __FILE__ ));
137
+ wp_enqueue_style('search-exclude-stylesheet');
138
+ }
139
+
140
+ public function addQuickEditCustomBox($columnName)
141
+ {
142
+ if ('search_exclude' == $columnName) {
143
+ $this->view('quick_edit');
144
+ }
145
+ }
146
+
147
+ public function addBulkEditCustomBox($columnName)
148
+ {
149
+ if ('search_exclude' == $columnName) {
150
+ $this->view('bulk_edit');
151
+ }
152
+ }
153
+
154
+ public function addColumn($columns)
155
+ {
156
+ $columns['search_exclude'] = 'Search Exclude';
157
+ return $columns;
158
+ }
159
+
160
+ public function populateColumnValue($columnName, $postId)
161
+ {
162
+ if ('search_exclude' == $columnName) {
163
+ $this->view('column_cell', array('exclude' => $this->isExcluded($postId), 'postId' => $postId));
164
+ }
165
+ }
166
+
167
+ public function activate()
168
  {
169
  $excluded = $this->getExcluded();
170
 
180
  if (empty($currentScreen->post_type)) {
181
  return;
182
  }
183
+ add_meta_box('sep_metabox_id', 'Search Exclude', array($this, 'metabox'), null, 'side');
184
  }
185
 
186
  public function metabox($post)
187
  {
 
 
 
188
  wp_nonce_field( 'sep_metabox_nonce', 'metabox_nonce' );
189
+ $this->view('metabox', array('exclude' => $this->isExcluded($post->ID)));
190
  }
191
 
192
  public function adminMenu()
228
  return array_merge($args, array('___s2_is_bbp_has_replies' => true));
229
  }
230
 
231
+ public function postSave($postId)
232
  {
233
+ if (!isset($_POST['sep'])) return $postId;
234
 
235
  $sep = $_POST['sep'];
236
  $exclude = (isset($sep['exclude'])) ? $sep['exclude'] : 0 ;
237
 
238
+ $this->savePostIdToSearchExclude($postId, $exclude);
239
 
240
+ return $postId;
241
  }
242
 
243
  public function options()
244
  {
245
  $excluded = $this->getExcluded();
 
246
  $query = new WP_Query( array(
247
  'post_type' => 'any',
248
  'post_status' => 'any',
250
  'order'=>'ASC',
251
  'nopaging' => true,
252
  ));
253
+ $this->view(
254
+ 'options',
255
+ array(
256
+ 'excluded' => $excluded,
257
+ 'query' => $query,
258
+ )
259
+ );
260
  }
261
 
262
  public function saveOptions()
views/bulk_edit.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <fieldset class="inline-edit-col-right">
2
+ <div class="inline-edit-col">
3
+ <div class="inline-edit-group">
4
+ <label class="alignleft">
5
+ <span class="title search-exclude-label">Show in Search Results</span>
6
+ <select name="sep[exclude]">
7
+ <option value="">— No Change —</option>
8
+ <option value="1">Hide</option>
9
+ <option value="0">Show</option>
10
+ </select>
11
+ </label>
12
+ </div>
13
+ </div>
14
+ </fieldset>
views/column_cell.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <div id="search-exclude-<?php echo $postId ?>" data-search_exclude="<?php echo (int)$exclude ?>"
2
+ <?php if ($exclude): ?>
3
+ title="Hidden from search results">Hidden
4
+ <?php else: ?>
5
+ title="Visible in search results">Visible
6
+ <?php endif; ?>
7
+ </div>
metabox.php → views/metabox.php RENAMED
File without changes
options.php → views/options.php RENAMED
File without changes
views/quick_edit.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <fieldset class="inline-edit-col-right">
2
+ <div class="inline-edit-col">
3
+ <div class="inline-edit-group">
4
+ <label for="sep_exclude">
5
+ <input type="hidden" name="sep[hidden]" id="sep_hidden" value="1" />
6
+ <input type="checkbox" name="sep[exclude]" id="sep_exclude" value="1" />
7
+ <span class="checkbox-title">Exclude from Search Results</span>
8
+ </label>
9
+ </div>
10
+ </div>
11
+ </fieldset>