Search Exclude - Version 1.3.0

Version Description

  • Fix and rework bulk edit: The Bulk actions dropdown now offers hide/show actions.
Download this release

Release Info

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

Code changes from version 1.2.7 to 1.3.0

Files changed (4) hide show
  1. js/search_exclude.js +0 -32
  2. readme.txt +6 -3
  3. search-exclude.php +65 -24
  4. views/bulk_edit.php +0 -15
js/search_exclude.js CHANGED
@@ -22,36 +22,4 @@
22
  }
23
  };
24
 
25
- $('body').on( 'click', '#bulk_edit', 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
- var nonce = $bulk_row.find('input[name="_wpnonce_search_exclude_bulk_edit"]').val();
39
- var referer = $bulk_row.find('input[name="_wp_http_referer"]').val();
40
-
41
- // save the data
42
- $.ajax({
43
- url: ajaxurl,
44
- type: 'POST',
45
- cache: false,
46
- async: false, // Fixes bulk editing in FF, see https://wordpress.org/support/topic/bulk-search-exclude-doesnt-work
47
- data: {
48
- action: 'search_exclude_save_bulk_edit',
49
- post_ids: $post_ids,
50
- sep_exclude: $exclude,
51
- _wpnonce_search_exclude_bulk_edit: nonce,
52
- _wp_http_referer: referer
53
- }
54
- });
55
- });
56
-
57
  })(jQuery);
22
  }
23
  };
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  })(jQuery);
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Search Exclude ===
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.7
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -92,6 +92,9 @@ function filterForProducts($exclude, $query)
92
 
93
  == Changelog ==
94
 
 
 
 
95
  = 1.2.7 =
96
  * This is a security release. All users are encouraged to upgrade.
97
  * Fix possible XSS vulnerability.
1
  === Search Exclude ===
2
  Contributors: pronskiy, williamdodson, stevelock
3
  Tags: admin, plugin, search
4
+ Requires at least: 4.7
5
+ Tested up to: 6.1
6
+ Stable tag: 1.3.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
92
 
93
  == Changelog ==
94
 
95
+ = 1.3.0 =
96
+ * Fix and rework bulk edit: The `Bulk actions` dropdown now offers hide/show actions.
97
+
98
  = 1.2.7 =
99
  * This is a security release. All users are encouraged to upgrade.
100
  * Fix possible XSS vulnerability.
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.7
6
  Author: Roman Pronskiy
7
  Author URI: http://pronskiy.com
8
  Plugin URI: http://wordpress.org/plugins/search-exclude/
@@ -50,14 +50,24 @@ class SearchExclude
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.
@@ -84,6 +94,57 @@ class SearchExclude
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
@@ -138,19 +199,6 @@ class SearchExclude
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));
@@ -180,13 +228,6 @@ class SearchExclude
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';
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.3.0
6
  Author: Roman Pronskiy
7
  Author URI: http://pronskiy.com
8
  Plugin URI: http://wordpress.org/plugins/search-exclude/
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
+
54
  add_action('quick_edit_custom_box', array($this, 'addQuickEditCustomBox'));
55
  add_action('admin_print_scripts-edit.php', array($this, 'enqueueEditScripts'));
 
56
  add_action('admin_enqueue_scripts', array($this, 'addStyle'));
57
 
58
+ /** Bulk edit */
59
+ foreach ( get_post_types() as $post_type ) {
60
+ add_filter( "bulk_actions-edit-$post_type", array($this, 'bulk_edit') ); // Add dropdown
61
+ add_filter( "handle_bulk_actions-edit-$post_type", array($this, 'bulk_action_handler'), 10, 3 ); // process the action
62
+ }
63
+ add_action( 'admin_notices', array($this, 'bulk_action_notices') ); // display messages
64
+ add_filter( 'removable_query_args', function($args) {
65
+ $args[] = 'se_saved';
66
+ return $args;
67
+ });
68
+
69
  /**
70
+ * Hook can be used outside the plugin.
71
  *
72
  * You can pass any post/page/custom_post ids in the array with first parameter.
73
  * The second parameter specifies states of visibility in search to be set.
94
  add_action('searchexclude_hide_from_search', array($this, 'savePostIdsToSearchExclude'), 10, 2);
95
  }
96
 
97
+ public function bulk_action_notices() {
98
+ if ( empty( $_GET[ 'se_saved' ] ) ) {
99
+ return;
100
+ }
101
+
102
+ $count = (int) $_GET[ 'se_saved' ];
103
+ $message = sprintf(
104
+ _n(
105
+ '%d item updated.',
106
+ '%d items updated.',
107
+ $count
108
+ ),
109
+ $count
110
+ );
111
+
112
+ echo "<div class=\"notice notice-success is-dismissible\"><p>{$message}</p></div>";
113
+ }
114
+
115
+ public function bulk_action_handler( $redirect, $doaction, $object_ids ) {
116
+
117
+ // let's remove query args first
118
+ $redirect = remove_query_arg(
119
+ array( 'se_saved' ),
120
+ $redirect
121
+ );
122
+
123
+ if ($doaction !== 'se_show' && $doaction !== 'se_hide') {
124
+ return $redirect;
125
+ }
126
+
127
+ // do something for "Make Draft" bulk action
128
+ $exclude = ('se_hide' === $doaction);
129
+ $this->savePostIdsToSearchExclude($object_ids, $exclude);
130
+
131
+ $redirect = add_query_arg(
132
+ 'se_saved', // just a parameter for URL
133
+ count( $object_ids ), // how many posts have been selected
134
+ $redirect
135
+ );
136
+
137
+ return $redirect;
138
+ }
139
+
140
+ public function bulk_edit( $bulk_array ) {
141
+
142
+ $bulk_array[ 'se_hide' ] = 'Hide from Search';
143
+ $bulk_array[ 'se_show' ] = 'Show in Search';
144
+
145
+ return $bulk_array;
146
+ }
147
+
148
  /**
149
  * @param $postId int the ID of the post
150
  * @param $exclude bool indicates whether post should be excluded from the search results or not
199
  include(dirname(__FILE__) . '/views/' . $view . '.php');
200
  }
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  private function filterPostIds($postIds)
203
  {
204
  return array_filter(filter_var($postIds, FILTER_VALIDATE_INT, FILTER_FORCE_ARRAY));
228
  }
229
  }
230
 
 
 
 
 
 
 
 
231
  public function addColumn($columns)
232
  {
233
  $columns['search_exclude'] = 'Search Exclude';
views/bulk_edit.php DELETED
@@ -1,15 +0,0 @@
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
- <?php wp_nonce_field( 'search_exclude_bulk_edit', '_wpnonce_search_exclude_bulk_edit'); ?>
13
- </div>
14
- </div>
15
- </fieldset>