Version Description
- Initial release
Download this release
Release Info
Developer | pronskiy |
Plugin | Search Exclude |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- metabox.php +7 -0
- options.php +30 -0
- readme.txt +31 -0
- search-exclude.php +160 -0
metabox.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="misc-pub-section">
|
2 |
+
<label for="sep_exclude">
|
3 |
+
<input type="hidden" name="sep[hidden]" id="sep_hidden" value="1" />
|
4 |
+
<input type="checkbox" name="sep[exclude]" id="sep_exclude" value="1" <?php echo ($exclude) ? 'checked' : ''; ?> />
|
5 |
+
Exclude from Search Results
|
6 |
+
</label>
|
7 |
+
</div>
|
options.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="wrap">
|
2 |
+
<?php screen_icon(); ?>
|
3 |
+
<h2>Search Exclude</h2>
|
4 |
+
<?php if (empty($excluded)):?>
|
5 |
+
<p>No items excluded from the search results yet.</p>
|
6 |
+
<?php else: ?>
|
7 |
+
<h3>The following items are excluded from the search results</h3>
|
8 |
+
<form method="post" action="options-general.php?page=search_exclude" enctype="multipart/form-data">
|
9 |
+
<table cellspacing="0" class="wp-list-table widefat fixed pages">
|
10 |
+
<thead>
|
11 |
+
<tr>
|
12 |
+
<th style="" class="check-column" id="cb" scope="col"></th><th style="" class="column-title manage-column" id="title" scope="col"><span>Title</span></th><th style="" class="manage-column column-type" id="type" scope="col"><span>Type</span>
|
13 |
+
</tr>
|
14 |
+
</thead>
|
15 |
+
|
16 |
+
<tbody id="the-list">
|
17 |
+
<?php while ( $query->have_posts() ) : $query->the_post();?>
|
18 |
+
<tr valign="top" class="post-<?php the_ID()?> page type-page status-draft author-self" >
|
19 |
+
<th class="check-column" scope="row"><input type="checkbox" value="<?php the_ID()?>" name="sep_exclude[]" checked="checked"></th>
|
20 |
+
<td class="post-title page-title column-title"><strong><a title="Edit “<?php the_title()?>”" href="/wp-admin/post.php?post=<?php the_ID()?>&action=edit" class="row-title"><?php the_title()?></a></strong>
|
21 |
+
<td class="author column-author"><?php echo get_post_type();?></td>
|
22 |
+
</tr>
|
23 |
+
<?php endwhile; ?>
|
24 |
+
</tbody>
|
25 |
+
</table>
|
26 |
+
|
27 |
+
<p class="submit"><input type="submit" name="search_exclude_submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></p>
|
28 |
+
</form>
|
29 |
+
<?php endif; ?>
|
30 |
+
</div>
|
readme.txt
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Search Exclude ===
|
2 |
+
Contributors: pronskiy
|
3 |
+
Tags: admin, plugin, search
|
4 |
+
Requires at least: 3.3
|
5 |
+
Tested up to: 3.4
|
6 |
+
Stable tag: 1.0
|
7 |
+
License: GPLv2 or later
|
8 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
|
10 |
+
Exclude 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 |
+
|
20 |
+
1. Upload `search-exclude` directory to the `/wp-content/plugins/` directory
|
21 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
22 |
+
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
|
23 |
+
|
24 |
+
== Screenshots ==
|
25 |
+
|
26 |
+
1. screenshot-1.png
|
27 |
+
|
28 |
+
== Changelog ==
|
29 |
+
|
30 |
+
= 1.0 =
|
31 |
+
* Initial release
|
search-exclude.php
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.0
|
6 |
+
Author: Roman Pronskiy
|
7 |
+
Author URI: http://pronskiy.com
|
8 |
+
*/
|
9 |
+
|
10 |
+
/*
|
11 |
+
Copyright (c) 2012 Roman Pronskiy
|
12 |
+
|
13 |
+
This program is free software; you can redistribute it and/or modify
|
14 |
+
it under the terms of the GNU General Public License as published by
|
15 |
+
the Free Software Foundation; either version 3 of the License, or
|
16 |
+
(at your option) any later version.
|
17 |
+
|
18 |
+
This program is distributed in the hope that it will be useful,
|
19 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
GNU General Public License for more details.
|
22 |
+
|
23 |
+
You should have received a copy of the GNU General Public License
|
24 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class SearchExclude
|
28 |
+
{
|
29 |
+
public function __construct()
|
30 |
+
{
|
31 |
+
$this->registerHooks();
|
32 |
+
}
|
33 |
+
|
34 |
+
public function registerHooks()
|
35 |
+
{
|
36 |
+
register_activation_hook( __FILE__, array($this, 'activate') );
|
37 |
+
add_action('admin_init', array($this, 'saveOptions') );
|
38 |
+
add_action('admin_menu', array($this, 'adminMenu'));
|
39 |
+
add_action('post_updated', array($this, 'postSave'));
|
40 |
+
add_action('add_meta_boxes', array($this, 'addMetabox') );
|
41 |
+
add_filter('pre_get_posts',array($this, 'searchFilter'));
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* @param $postId int the ID of the post
|
46 |
+
* @param $value bool indicates whether post should be excluded from the search results or not
|
47 |
+
*/
|
48 |
+
protected function savePostIdToSearchExclude($postId, $value)
|
49 |
+
{
|
50 |
+
$excluded = $this->getExcluded();
|
51 |
+
|
52 |
+
$indSep = array_search($postId, $excluded);
|
53 |
+
if ($value) {
|
54 |
+
if (false === $indSep) {
|
55 |
+
$excluded[] = $postId;
|
56 |
+
}
|
57 |
+
}
|
58 |
+
else {
|
59 |
+
if (false !== $indSep) {
|
60 |
+
unset($excluded[$indSep]);
|
61 |
+
}
|
62 |
+
}
|
63 |
+
$this->saveExcluded($excluded);
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* @param $excluded array IDs of posts to be saved for excluding from the search results
|
68 |
+
*/
|
69 |
+
protected function saveExcluded($excluded)
|
70 |
+
{
|
71 |
+
update_option('sep_exclude', $excluded);
|
72 |
+
}
|
73 |
+
|
74 |
+
protected function getExcluded()
|
75 |
+
{
|
76 |
+
$excluded = get_option('sep_exclude');
|
77 |
+
|
78 |
+
if (!is_array($excluded)) {
|
79 |
+
$excluded = array();
|
80 |
+
}
|
81 |
+
return $excluded;
|
82 |
+
}
|
83 |
+
|
84 |
+
function activate()
|
85 |
+
{
|
86 |
+
$excluded = $this->getExcluded();
|
87 |
+
|
88 |
+
if (empty($excluded)) {
|
89 |
+
$this->saveExcluded(array());
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
public function addMetabox()
|
94 |
+
{
|
95 |
+
add_meta_box( 'sep_metabox_id', 'Search Exclude', array($this, 'metabox'), null);
|
96 |
+
}
|
97 |
+
|
98 |
+
public function metabox( $post )
|
99 |
+
{
|
100 |
+
$excluded = $this->getExcluded();
|
101 |
+
$exclude = !(false === array_search($post->ID, $excluded));
|
102 |
+
|
103 |
+
wp_nonce_field( 'sep_metabox_nonce', 'metabox_nonce' );
|
104 |
+
include(__DIR__ . '/metabox.php');
|
105 |
+
}
|
106 |
+
|
107 |
+
public function adminMenu()
|
108 |
+
{
|
109 |
+
add_options_page(
|
110 |
+
'Search Exclude',
|
111 |
+
'Search Exclude',
|
112 |
+
10,
|
113 |
+
'search_exclude',
|
114 |
+
array($this, 'options')
|
115 |
+
);
|
116 |
+
}
|
117 |
+
|
118 |
+
public function searchFilter($query)
|
119 |
+
{
|
120 |
+
if ($query->is_search) {
|
121 |
+
$query->set('post__not_in', array_merge($query->get('post__not_in'), $this->getExcluded()));
|
122 |
+
}
|
123 |
+
return $query;
|
124 |
+
}
|
125 |
+
|
126 |
+
public function postSave( $post_id )
|
127 |
+
{
|
128 |
+
if (!isset($_POST['sep'])) return $post_id;
|
129 |
+
|
130 |
+
$sep = $_POST['sep'];
|
131 |
+
$exclude = (isset($sep['exclude'])) ? $sep['exclude'] : 0 ;
|
132 |
+
|
133 |
+
$this->savePostIdToSearchExclude($post_id, $exclude);
|
134 |
+
|
135 |
+
return $post_id;
|
136 |
+
}
|
137 |
+
|
138 |
+
public function options()
|
139 |
+
{
|
140 |
+
$excluded = $this->getExcluded();
|
141 |
+
|
142 |
+
$query = new WP_Query( array(
|
143 |
+
'post_type' => 'any',
|
144 |
+
'post__in' => $excluded,
|
145 |
+
'order'=>'ASC',
|
146 |
+
'nopaging' => true,
|
147 |
+
));
|
148 |
+
include(__DIR__ . '/options.php');
|
149 |
+
}
|
150 |
+
|
151 |
+
public function saveOptions()
|
152 |
+
{
|
153 |
+
if (isset($_POST['search_exclude_submit'])) {
|
154 |
+
|
155 |
+
$excluded = $_POST['sep_exclude'];
|
156 |
+
$this->saveExcluded($excluded);
|
157 |
+
}
|
158 |
+
}
|
159 |
+
}
|
160 |
+
$sep = new SearchExclude();
|