Version Description
Download this release
Release Info
Developer | colorlibplugins |
Plugin | Simple Custom Post Order |
Version | 2.3.3 |
Comparing to | |
See all releases |
Code changes from version 2.2 to 2.3.3
- assets/scporder.css +0 -1
- assets/scporder.js +14 -4
- readme.txt +20 -7
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- settings.php +116 -57
- simple-custom-post-order.php +468 -331
assets/scporder.css
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
.wp-list-table.tags td:hover{ cursor: move; }
|
2 |
.ui-sortable tr:hover {
|
3 |
cursor: move;
|
4 |
}
|
|
|
1 |
.ui-sortable tr:hover {
|
2 |
cursor: move;
|
3 |
}
|
assets/scporder.js
CHANGED
@@ -1,16 +1,26 @@
|
|
1 |
(function($){
|
2 |
-
$(
|
3 |
'items': 'tr',
|
4 |
'axis': 'y',
|
5 |
'helper': fixHelper,
|
6 |
'update' : function(e, ui) {
|
7 |
$.post( ajaxurl, {
|
8 |
action: 'update-menu-order',
|
9 |
-
order: $(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
});
|
11 |
}
|
12 |
});
|
13 |
-
|
14 |
var fixHelper = function(e, ui) {
|
15 |
ui.children().children().each(function() {
|
16 |
$(this).width($(this).width());
|
@@ -18,4 +28,4 @@
|
|
18 |
return ui;
|
19 |
};
|
20 |
|
21 |
-
})(jQuery)
|
1 |
(function($){
|
2 |
+
$('table.posts #the-list, table.pages #the-list').sortable({
|
3 |
'items': 'tr',
|
4 |
'axis': 'y',
|
5 |
'helper': fixHelper,
|
6 |
'update' : function(e, ui) {
|
7 |
$.post( ajaxurl, {
|
8 |
action: 'update-menu-order',
|
9 |
+
order: $('#the-list').sortable('serialize'),
|
10 |
+
});
|
11 |
+
}
|
12 |
+
});
|
13 |
+
$('table.tags #the-list').sortable({
|
14 |
+
'items': 'tr',
|
15 |
+
'axis': 'y',
|
16 |
+
'helper': fixHelper,
|
17 |
+
'update' : function(e, ui) {
|
18 |
+
$.post( ajaxurl, {
|
19 |
+
action: 'update-menu-order-tags',
|
20 |
+
order: $('#the-list').sortable('serialize'),
|
21 |
});
|
22 |
}
|
23 |
});
|
|
|
24 |
var fixHelper = function(e, ui) {
|
25 |
ui.children().children().each(function() {
|
26 |
$(this).width($(this).width());
|
28 |
return ui;
|
29 |
};
|
30 |
|
31 |
+
})(jQuery)
|
readme.txt
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
=== Simple Custom Post Order ===
|
2 |
-
Contributors:
|
3 |
Tags: custom post order, post order, js post order, page order, posts order, category order, sort posts, sort pages, sort custom posts
|
4 |
-
Requires at least: 3.
|
5 |
-
Tested up to:
|
6 |
-
|
7 |
-
|
8 |
-
License
|
|
|
9 |
|
10 |
Order posts(posts, any custom post types) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary.
|
11 |
|
@@ -14,6 +15,8 @@ Order posts(posts, any custom post types) using a Drag and Drop Sortable JavaScr
|
|
14 |
Order posts(posts, any custom post types) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary. You can do directly on default WordPress administration.
|
15 |
Excluding custom query which uses order or orderby parameters, in get_posts or query_posts and so on.
|
16 |
|
|
|
|
|
17 |
== Installation ==
|
18 |
|
19 |
1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
|
@@ -31,6 +34,7 @@ An answer to that question.
|
|
31 |
2. screenshot-2
|
32 |
|
33 |
== Changelog ==
|
|
|
34 |
= Version 1.0 (20-07-2013) =
|
35 |
* Initial release.
|
36 |
|
@@ -50,4 +54,13 @@ An answer to that question.
|
|
50 |
* Fixed bug: Custom Query which uses 'order' or 'orderby' parameters is preferred
|
51 |
* It does not depend on the designation manner of arguments( Parameters ). ( $args = 'orderby=&order=' or $args = array( 'orderby' => '', 'order' => '' ) )
|
52 |
* Previous Versions Issues were Improved.
|
53 |
-
* Removed Taxonomy Sort( Will add in next Version :) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
=== Simple Custom Post Order ===
|
2 |
+
Contributors: colorlibplugins, silkalns
|
3 |
Tags: custom post order, post order, js post order, page order, posts order, category order, sort posts, sort pages, sort custom posts
|
4 |
+
Requires at least: 3.5.1
|
5 |
+
Tested up to: 4.9
|
6 |
+
Requires PHP: 5.6
|
7 |
+
Stable tag: trunk
|
8 |
+
License: GPLv3 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
11 |
Order posts(posts, any custom post types) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary.
|
12 |
|
15 |
Order posts(posts, any custom post types) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary. You can do directly on default WordPress administration.
|
16 |
Excluding custom query which uses order or orderby parameters, in get_posts or query_posts and so on.
|
17 |
|
18 |
+
This plugins is now supported and maintained by <a href=“https://colorlib.com/wp/“ target=“_blank” rel=“friend” >Colorlib</a>.
|
19 |
+
|
20 |
== Installation ==
|
21 |
|
22 |
1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
|
34 |
2. screenshot-2
|
35 |
|
36 |
== Changelog ==
|
37 |
+
|
38 |
= Version 1.0 (20-07-2013) =
|
39 |
* Initial release.
|
40 |
|
54 |
* Fixed bug: Custom Query which uses 'order' or 'orderby' parameters is preferred
|
55 |
* It does not depend on the designation manner of arguments( Parameters ). ( $args = 'orderby=&order=' or $args = array( 'orderby' => '', 'order' => '' ) )
|
56 |
* Previous Versions Issues were Improved.
|
57 |
+
* Removed Taxonomy Sort( Will add in next Version :) )
|
58 |
+
|
59 |
+
= Version 2.3 (24-03-2014) =
|
60 |
+
* Fixed major bug on taxonomy and post order
|
61 |
+
|
62 |
+
= Version 2.3.2 (17-03-2017) =
|
63 |
+
* Minor documentation and readme tweaks
|
64 |
+
|
65 |
+
= Version 2.3.3 (22-10-2018) =
|
66 |
+
* Minor tweaks & fixes
|
screenshot-1.png
CHANGED
Binary file
|
screenshot-2.png
CHANGED
Binary file
|
screenshot-3.png
ADDED
Binary file
|
settings.php
CHANGED
@@ -1,62 +1,121 @@
|
|
1 |
<?php
|
2 |
-
$scporder_options = get_option(
|
3 |
-
$
|
|
|
4 |
?>
|
5 |
|
6 |
-
<div class="
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
<script>
|
52 |
-
(function($){
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
</script>
|
1 |
<?php
|
2 |
+
$scporder_options = get_option('scporder_options');
|
3 |
+
$scporder_objects = isset($scporder_options['objects']) ? $scporder_options['objects'] : array();
|
4 |
+
$scporder_tags = isset($scporder_options['tags']) ? $scporder_options['tags'] : array();
|
5 |
?>
|
6 |
|
7 |
+
<div class="wrap">
|
8 |
+
<?php screen_icon('plugins'); ?>
|
9 |
+
<h2><?php _e('Simple Custom Post Order Settings', 'scporder'); ?></h2>
|
10 |
+
<?php if (isset($_GET['msg'])) : ?>
|
11 |
+
<div id="message" class="updated below-h2">
|
12 |
+
<?php if ($_GET['msg'] == 'update') : ?>
|
13 |
+
<p><?php _e('Settings Updated.','scporder'); ?></p>
|
14 |
+
<?php endif; ?>
|
15 |
+
</div>
|
16 |
+
<?php endif; ?>
|
17 |
+
|
18 |
+
<form method="post">
|
19 |
+
|
20 |
+
<?php if (function_exists('wp_nonce_field')) wp_nonce_field('nonce_scporder'); ?>
|
21 |
+
|
22 |
+
<div id="scporder_select_objects">
|
23 |
+
|
24 |
+
<table class="form-table">
|
25 |
+
<tbody>
|
26 |
+
<tr valign="top">
|
27 |
+
<th scope="row"><?php _e('Check to Sort Post Types', 'scporder') ?></th>
|
28 |
+
<td>
|
29 |
+
<label><input type="checkbox" id="scporder_allcheck_objects"> <?php _e('Check All', 'scporder') ?></label><br>
|
30 |
+
<?php
|
31 |
+
$post_types = get_post_types(array(
|
32 |
+
'show_ui' => true,
|
33 |
+
'show_in_menu' => true,
|
34 |
+
), 'objects');
|
35 |
+
|
36 |
+
foreach ($post_types as $post_type) {
|
37 |
+
if ($post_type->name == 'attachment')
|
38 |
+
continue;
|
39 |
+
?>
|
40 |
+
<label><input type="checkbox" name="objects[]" value="<?php echo $post_type->name; ?>" <?php
|
41 |
+
if (isset($scporder_objects) && is_array($scporder_objects)) {
|
42 |
+
if (in_array($post_type->name, $scporder_objects)) {
|
43 |
+
echo 'checked="checked"';
|
44 |
+
}
|
45 |
+
}
|
46 |
+
?>> <?php echo $post_type->label; ?></label><br>
|
47 |
+
<?php
|
48 |
+
}
|
49 |
+
?>
|
50 |
+
</td>
|
51 |
+
</tr>
|
52 |
+
</tbody>
|
53 |
+
</table>
|
54 |
+
|
55 |
+
</div>
|
56 |
+
|
57 |
+
|
58 |
+
<div id="scporder_select_tags">
|
59 |
+
<table class="form-table">
|
60 |
+
<tbody>
|
61 |
+
<tr valign="top">
|
62 |
+
<th scope="row"><?php _e('Check to Sort Taxonomies', 'scporder') ?></th>
|
63 |
+
<td>
|
64 |
+
<label><input type="checkbox" id="scporder_allcheck_tags"> <?php _e('Check All', 'scporder') ?></label><br>
|
65 |
+
<?php
|
66 |
+
$taxonomies = get_taxonomies(array(
|
67 |
+
'show_ui' => true,
|
68 |
+
), 'objects');
|
69 |
+
|
70 |
+
foreach ($taxonomies as $taxonomy) {
|
71 |
+
if ($taxonomy->name == 'post_format')
|
72 |
+
continue;
|
73 |
+
?>
|
74 |
+
<label><input type="checkbox" name="tags[]" value="<?php echo $taxonomy->name; ?>" <?php
|
75 |
+
if (isset($scporder_tags) && is_array($scporder_tags)) {
|
76 |
+
if (in_array($taxonomy->name, $scporder_tags)) {
|
77 |
+
echo 'checked="checked"';
|
78 |
+
}
|
79 |
+
}
|
80 |
+
?>> <?php echo $taxonomy->label ?></label><br>
|
81 |
+
<?php
|
82 |
+
}
|
83 |
+
?>
|
84 |
+
</td>
|
85 |
+
</tr>
|
86 |
+
</tbody>
|
87 |
+
</table>
|
88 |
+
|
89 |
+
</div>
|
90 |
+
<p class="submit">
|
91 |
+
<input type="submit" class="button-primary" name="scporder_submit" value="<?php _e('Update', 'scporder'); ?>">
|
92 |
+
</p>
|
93 |
+
|
94 |
+
</form>
|
95 |
+
<h3>Like this simple plugin?</h3>
|
96 |
+
<p>Make sure to <a href="https://wordpress.org/support/plugin/simple-custom-post-order/reviews/?filter=5"><strong>rate it</strong></a> and visit us at <a href="https://colorlib.com/wp/"><strong>Colorlib.com</strong></a></p>
|
97 |
+
|
98 |
+
|
99 |
+
</div>
|
100 |
+
|
101 |
<script>
|
102 |
+
(function ($) {
|
103 |
+
|
104 |
+
$("#scporder_allcheck_objects").on('click', function () {
|
105 |
+
var items = $("#scporder_select_objects input");
|
106 |
+
if ($(this).is(':checked'))
|
107 |
+
$(items).prop('checked', true);
|
108 |
+
else
|
109 |
+
$(items).prop('checked', false);
|
110 |
+
});
|
111 |
+
|
112 |
+
$("#scporder_allcheck_tags").on('click', function () {
|
113 |
+
var items = $("#scporder_select_tags input");
|
114 |
+
if ($(this).is(':checked'))
|
115 |
+
$(items).prop('checked', true);
|
116 |
+
else
|
117 |
+
$(items).prop('checked', false);
|
118 |
+
});
|
119 |
+
|
120 |
+
})(jQuery)
|
121 |
</script>
|
simple-custom-post-order.php
CHANGED
@@ -2,342 +2,479 @@
|
|
2 |
|
3 |
/*
|
4 |
Plugin Name: Simple Custom Post Order
|
5 |
-
Plugin URI:
|
6 |
Description: Order Items (Posts, Pages, and Custom Post Types) using a Drag and Drop Sortable JavaScript.
|
7 |
-
Version: 2.
|
8 |
-
Author:
|
9 |
-
Author URI:
|
10 |
*/
|
11 |
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
define( 'SCPO_URL', plugins_url( '', __FILE__ ) );
|
18 |
-
define( 'SCPO_DIR', plugin_dir_path( __FILE__ ) );
|
19 |
-
|
20 |
-
/* ====================================================================
|
21 |
-
Class & Method
|
22 |
-
==================================================================== */
|
23 |
-
|
24 |
$scporder = new SCPO_Engine();
|
25 |
|
26 |
class SCPO_Engine {
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/*
|
4 |
Plugin Name: Simple Custom Post Order
|
5 |
+
Plugin URI: https://wordpress.org/plugins-wp/simple-custom-post-order/
|
6 |
Description: Order Items (Posts, Pages, and Custom Post Types) using a Drag and Drop Sortable JavaScript.
|
7 |
+
Version: 2.3.3
|
8 |
+
Author: Colorlib
|
9 |
+
Author URI: https://colorlib.com/wp/
|
10 |
*/
|
11 |
|
12 |
|
13 |
+
define('SCPORDER_URL', plugins_url('', __FILE__));
|
14 |
+
define('SCPORDER_DIR', plugin_dir_path(__FILE__));
|
15 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
$scporder = new SCPO_Engine();
|
17 |
|
18 |
class SCPO_Engine {
|
19 |
|
20 |
+
function __construct() {
|
21 |
+
if (!get_option('scporder_install'))
|
22 |
+
$this->scporder_install();
|
23 |
+
|
24 |
+
add_action('admin_menu', array($this, 'admin_menu'));
|
25 |
+
|
26 |
+
add_action('admin_init', array($this, 'refresh'));
|
27 |
+
|
28 |
+
add_action('admin_init', array($this, 'update_options'));
|
29 |
+
add_action('admin_init', array($this, 'load_script_css'));
|
30 |
+
|
31 |
+
add_action('wp_ajax_update-menu-order', array($this, 'update_menu_order'));
|
32 |
+
add_action('wp_ajax_update-menu-order-tags', array($this, 'update_menu_order_tags'));
|
33 |
+
|
34 |
+
add_action('pre_get_posts', array($this, 'scporder_pre_get_posts'));
|
35 |
+
|
36 |
+
add_filter('get_previous_post_where', array($this, 'scporder_previous_post_where'));
|
37 |
+
add_filter('get_previous_post_sort', array($this, 'scporder_previous_post_sort'));
|
38 |
+
add_filter('get_next_post_where', array($this, 'scporder_next_post_where'));
|
39 |
+
add_filter('get_next_post_sort', array($this, 'scporder_next_post_sort'));
|
40 |
+
|
41 |
+
add_filter('get_terms_orderby', array($this, 'scporder_get_terms_orderby'), 10, 3);
|
42 |
+
add_filter('wp_get_object_terms', array($this, 'scporder_get_object_terms'), 10, 3);
|
43 |
+
add_filter('get_terms', array($this, 'scporder_get_object_terms'), 10, 3);
|
44 |
+
}
|
45 |
+
|
46 |
+
function scporder_install() {
|
47 |
+
global $wpdb;
|
48 |
+
$result = $wpdb->query("DESCRIBE $wpdb->terms `term_order`");
|
49 |
+
if (!$result) {
|
50 |
+
$query = "ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'";
|
51 |
+
$result = $wpdb->query($query);
|
52 |
+
}
|
53 |
+
update_option('scporder_install', 1);
|
54 |
+
}
|
55 |
+
|
56 |
+
function admin_menu() {
|
57 |
+
add_options_page(__('SCPOrder', 'scporder'), __('SCPOrder', 'scporder'), 'manage_options', 'scporder-settings', array($this, 'admin_page'));
|
58 |
+
}
|
59 |
+
|
60 |
+
function admin_page() {
|
61 |
+
require SCPORDER_DIR . 'settings.php';
|
62 |
+
}
|
63 |
+
|
64 |
+
function _check_load_script_css() {
|
65 |
+
$active = false;
|
66 |
+
|
67 |
+
$objects = $this->get_scporder_options_objects();
|
68 |
+
$tags = $this->get_scporder_options_tags();
|
69 |
+
|
70 |
+
if (empty($objects) && empty($tags))
|
71 |
+
return false;
|
72 |
+
|
73 |
+
if (isset($_GET['orderby']) || strstr($_SERVER['REQUEST_URI'], 'action=edit') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php'))
|
74 |
+
return false;
|
75 |
+
|
76 |
+
if (!empty($objects)) {
|
77 |
+
if (isset($_GET['post_type']) && !isset($_GET['taxonomy']) && in_array($_GET['post_type'], $objects)) { // if page or custom post types
|
78 |
+
$active = true;
|
79 |
+
}
|
80 |
+
if (!isset($_GET['post_type']) && strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') && in_array('post', $objects)) { // if post
|
81 |
+
$active = true;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
if (!empty($tags)) {
|
86 |
+
if (isset($_GET['taxonomy']) && in_array($_GET['taxonomy'], $tags)) {
|
87 |
+
$active = true;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
return $active;
|
92 |
+
}
|
93 |
+
|
94 |
+
function load_script_css() {
|
95 |
+
if ($this->_check_load_script_css()) {
|
96 |
+
wp_enqueue_script('jquery');
|
97 |
+
wp_enqueue_script('jquery-ui-sortable');
|
98 |
+
wp_enqueue_script('scporderjs', SCPORDER_URL . '/assets/scporder.js', array('jquery'), null, true);
|
99 |
+
|
100 |
+
wp_enqueue_style('scporder', SCPORDER_URL . '/assets/scporder.css', array(), null);
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
function refresh() {
|
105 |
+
global $wpdb;
|
106 |
+
$objects = $this->get_scporder_options_objects();
|
107 |
+
$tags = $this->get_scporder_options_tags();
|
108 |
+
|
109 |
+
if (!empty($objects)) {
|
110 |
+
foreach ($objects as $object) {
|
111 |
+
$result = $wpdb->get_results("
|
112 |
+
SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
|
113 |
+
FROM $wpdb->posts
|
114 |
+
WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
115 |
+
");
|
116 |
+
if ($result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max)
|
117 |
+
continue;
|
118 |
+
|
119 |
+
$results = $wpdb->get_results("
|
120 |
+
SELECT ID
|
121 |
+
FROM $wpdb->posts
|
122 |
+
WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
123 |
+
ORDER BY menu_order ASC
|
124 |
+
");
|
125 |
+
foreach ($results as $key => $result) {
|
126 |
+
$wpdb->update($wpdb->posts, array('menu_order' => $key + 1), array('ID' => $result->ID));
|
127 |
+
}
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
if (!empty($tags)) {
|
132 |
+
foreach ($tags as $taxonomy) {
|
133 |
+
$result = $wpdb->get_results("
|
134 |
+
SELECT count(*) as cnt, max(term_order) as max, min(term_order) as min
|
135 |
+
FROM $wpdb->terms AS terms
|
136 |
+
INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
|
137 |
+
WHERE term_taxonomy.taxonomy = '" . $taxonomy . "'
|
138 |
+
");
|
139 |
+
if ($result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max)
|
140 |
+
continue;
|
141 |
+
|
142 |
+
$results = $wpdb->get_results("
|
143 |
+
SELECT terms.term_id
|
144 |
+
FROM $wpdb->terms AS terms
|
145 |
+
INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
|
146 |
+
WHERE term_taxonomy.taxonomy = '" . $taxonomy . "'
|
147 |
+
ORDER BY term_order ASC
|
148 |
+
");
|
149 |
+
foreach ($results as $key => $result) {
|
150 |
+
$wpdb->update($wpdb->terms, array('term_order' => $key + 1), array('term_id' => $result->term_id));
|
151 |
+
}
|
152 |
+
}
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
function update_menu_order() {
|
157 |
+
global $wpdb;
|
158 |
+
|
159 |
+
parse_str($_POST['order'], $data);
|
160 |
+
|
161 |
+
if (!is_array($data))
|
162 |
+
return false;
|
163 |
+
|
164 |
+
$id_arr = array();
|
165 |
+
foreach ($data as $key => $values) {
|
166 |
+
foreach ($values as $position => $id) {
|
167 |
+
$id_arr[] = $id;
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
$menu_order_arr = array();
|
172 |
+
foreach ($id_arr as $key => $id) {
|
173 |
+
$results = $wpdb->get_results("SELECT menu_order FROM $wpdb->posts WHERE ID = " . intval($id));
|
174 |
+
foreach ($results as $result) {
|
175 |
+
$menu_order_arr[] = $result->menu_order;
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
sort($menu_order_arr);
|
180 |
+
|
181 |
+
foreach ($data as $key => $values) {
|
182 |
+
foreach ($values as $position => $id) {
|
183 |
+
$wpdb->update($wpdb->posts, array('menu_order' => $menu_order_arr[$position]), array('ID' => intval($id)));
|
184 |
+
}
|
185 |
+
}
|
186 |
+
}
|
187 |
+
|
188 |
+
function update_menu_order_tags() {
|
189 |
+
global $wpdb;
|
190 |
+
|
191 |
+
parse_str($_POST['order'], $data);
|
192 |
+
|
193 |
+
if (!is_array($data))
|
194 |
+
return false;
|
195 |
+
|
196 |
+
$id_arr = array();
|
197 |
+
foreach ($data as $key => $values) {
|
198 |
+
foreach ($values as $position => $id) {
|
199 |
+
$id_arr[] = $id;
|
200 |
+
}
|
201 |
+
}
|
202 |
+
|
203 |
+
$menu_order_arr = array();
|
204 |
+
foreach ($id_arr as $key => $id) {
|
205 |
+
$results = $wpdb->get_results("SELECT term_order FROM $wpdb->terms WHERE term_id = " . intval($id));
|
206 |
+
foreach ($results as $result) {
|
207 |
+
$menu_order_arr[] = $result->term_order;
|
208 |
+
}
|
209 |
+
}
|
210 |
+
sort($menu_order_arr);
|
211 |
+
|
212 |
+
foreach ($data as $key => $values) {
|
213 |
+
foreach ($values as $position => $id) {
|
214 |
+
$wpdb->update($wpdb->terms, array('term_order' => $menu_order_arr[$position]), array('term_id' => intval($id)));
|
215 |
+
}
|
216 |
+
}
|
217 |
+
}
|
218 |
+
|
219 |
+
function update_options() {
|
220 |
+
global $wpdb;
|
221 |
+
|
222 |
+
if (!isset($_POST['scporder_submit']))
|
223 |
+
return false;
|
224 |
+
|
225 |
+
check_admin_referer('nonce_scporder');
|
226 |
+
|
227 |
+
$input_options = array();
|
228 |
+
$input_options['objects'] = isset($_POST['objects']) ? $_POST['objects'] : '';
|
229 |
+
$input_options['tags'] = isset($_POST['tags']) ? $_POST['tags'] : '';
|
230 |
+
|
231 |
+
update_option('scporder_options', $input_options);
|
232 |
+
|
233 |
+
$objects = $this->get_scporder_options_objects();
|
234 |
+
$tags = $this->get_scporder_options_tags();
|
235 |
+
|
236 |
+
if (!empty($objects)) {
|
237 |
+
foreach ($objects as $object) {
|
238 |
+
$result = $wpdb->get_results("
|
239 |
+
SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
|
240 |
+
FROM $wpdb->posts
|
241 |
+
WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
242 |
+
");
|
243 |
+
if ($result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max)
|
244 |
+
continue;
|
245 |
+
|
246 |
+
if ($object == 'page') {
|
247 |
+
$results = $wpdb->get_results("
|
248 |
+
SELECT ID
|
249 |
+
FROM $wpdb->posts
|
250 |
+
WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
251 |
+
ORDER BY post_title ASC
|
252 |
+
");
|
253 |
+
} else {
|
254 |
+
$results = $wpdb->get_results("
|
255 |
+
SELECT ID
|
256 |
+
FROM $wpdb->posts
|
257 |
+
WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
258 |
+
ORDER BY post_date DESC
|
259 |
+
");
|
260 |
+
}
|
261 |
+
foreach ($results as $key => $result) {
|
262 |
+
$wpdb->update($wpdb->posts, array('menu_order' => $key + 1), array('ID' => $result->ID));
|
263 |
+
}
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
if (!empty($tags)) {
|
268 |
+
foreach ($tags as $taxonomy) {
|
269 |
+
$result = $wpdb->get_results("
|
270 |
+
SELECT count(*) as cnt, max(term_order) as max, min(term_order) as min
|
271 |
+
FROM $wpdb->terms AS terms
|
272 |
+
INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
|
273 |
+
WHERE term_taxonomy.taxonomy = '" . $taxonomy . "'
|
274 |
+
");
|
275 |
+
if ($result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max)
|
276 |
+
continue;
|
277 |
+
|
278 |
+
$results = $wpdb->get_results("
|
279 |
+
SELECT terms.term_id
|
280 |
+
FROM $wpdb->terms AS terms
|
281 |
+
INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
|
282 |
+
WHERE term_taxonomy.taxonomy = '" . $taxonomy . "'
|
283 |
+
ORDER BY name ASC
|
284 |
+
");
|
285 |
+
foreach ($results as $key => $result) {
|
286 |
+
$wpdb->update($wpdb->terms, array('term_order' => $key + 1), array('term_id' => $result->term_id));
|
287 |
+
}
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
wp_redirect('admin.php?page=scporder-settings&msg=update');
|
292 |
+
}
|
293 |
+
|
294 |
+
function scporder_previous_post_where($where) {
|
295 |
+
global $post;
|
296 |
+
|
297 |
+
$objects = $this->get_scporder_options_objects();
|
298 |
+
if (empty($objects))
|
299 |
+
return $where;
|
300 |
+
|
301 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
302 |
+
$current_menu_order = $post->menu_order;
|
303 |
+
$where = "WHERE p.menu_order > '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
|
304 |
+
}
|
305 |
+
return $where;
|
306 |
+
}
|
307 |
+
|
308 |
+
function scporder_previous_post_sort($orderby) {
|
309 |
+
global $post;
|
310 |
+
|
311 |
+
$objects = $this->get_scporder_options_objects();
|
312 |
+
if (empty($objects))
|
313 |
+
return $orderby;
|
314 |
+
|
315 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
316 |
+
$orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
|
317 |
+
}
|
318 |
+
return $orderby;
|
319 |
+
}
|
320 |
+
|
321 |
+
function scporder_next_post_where($where) {
|
322 |
+
global $post;
|
323 |
+
|
324 |
+
$objects = $this->get_scporder_options_objects();
|
325 |
+
if (empty($objects))
|
326 |
+
return $where;
|
327 |
+
|
328 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
329 |
+
$current_menu_order = $post->menu_order;
|
330 |
+
$where = "WHERE p.menu_order < '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
|
331 |
+
}
|
332 |
+
return $where;
|
333 |
+
}
|
334 |
+
|
335 |
+
function scporder_next_post_sort($orderby) {
|
336 |
+
global $post;
|
337 |
+
|
338 |
+
$objects = $this->get_scporder_options_objects();
|
339 |
+
if (empty($objects))
|
340 |
+
return $orderby;
|
341 |
+
|
342 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
343 |
+
$orderby = 'ORDER BY p.menu_order DESC LIMIT 1';
|
344 |
+
}
|
345 |
+
return $orderby;
|
346 |
+
}
|
347 |
+
|
348 |
+
function scporder_pre_get_posts($wp_query) {
|
349 |
+
$objects = $this->get_scporder_options_objects();
|
350 |
+
if (empty($objects))
|
351 |
+
return false;
|
352 |
+
if (is_admin()) {
|
353 |
+
|
354 |
+
if (isset($wp_query->query['post_type']) && !isset($_GET['orderby'])) {
|
355 |
+
if (in_array($wp_query->query['post_type'], $objects)) {
|
356 |
+
$wp_query->set('orderby', 'menu_order');
|
357 |
+
$wp_query->set('order', 'ASC');
|
358 |
+
}
|
359 |
+
}
|
360 |
+
} else {
|
361 |
+
|
362 |
+
$active = false;
|
363 |
+
|
364 |
+
if (isset($wp_query->query['post_type'])) {
|
365 |
+
if (!is_array($wp_query->query['post_type'])) {
|
366 |
+
if (in_array($wp_query->query['post_type'], $objects)) {
|
367 |
+
$active = true;
|
368 |
+
}
|
369 |
+
}
|
370 |
+
} else {
|
371 |
+
if (in_array('post', $objects)) {
|
372 |
+
$active = true;
|
373 |
+
}
|
374 |
+
}
|
375 |
+
|
376 |
+
if (!$active)
|
377 |
+
return false;
|
378 |
+
|
379 |
+
if (isset($wp_query->query['suppress_filters'])) {
|
380 |
+
if ($wp_query->get('orderby') == 'date')
|
381 |
+
$wp_query->set('orderby', 'menu_order');
|
382 |
+
if ($wp_query->get('order') == 'DESC')
|
383 |
+
$wp_query->set('order', 'ASC');
|
384 |
+
} else {
|
385 |
+
if (!$wp_query->get('orderby'))
|
386 |
+
$wp_query->set('orderby', 'menu_order');
|
387 |
+
if (!$wp_query->get('order'))
|
388 |
+
$wp_query->set('order', 'ASC');
|
389 |
+
}
|
390 |
+
}
|
391 |
+
}
|
392 |
+
|
393 |
+
function scporder_get_terms_orderby($orderby, $args) {
|
394 |
+
if (is_admin())
|
395 |
+
return $orderby;
|
396 |
+
|
397 |
+
$tags = $this->get_scporder_options_tags();
|
398 |
+
|
399 |
+
if (!isset($args['taxonomy']))
|
400 |
+
return $orderby;
|
401 |
+
|
402 |
+
$taxonomy = $args['taxonomy'];
|
403 |
+
if (!in_array($taxonomy, $tags))
|
404 |
+
return $orderby;
|
405 |
+
|
406 |
+
$orderby = 't.term_order';
|
407 |
+
return $orderby;
|
408 |
+
}
|
409 |
+
|
410 |
+
function scporder_get_object_terms($terms) {
|
411 |
+
$tags = $this->get_scporder_options_tags();
|
412 |
+
|
413 |
+
if (is_admin() && isset($_GET['orderby']))
|
414 |
+
return $terms;
|
415 |
+
|
416 |
+
foreach ($terms as $key => $term) {
|
417 |
+
if (is_object($term) && isset($term->taxonomy)) {
|
418 |
+
$taxonomy = $term->taxonomy;
|
419 |
+
if (!in_array($taxonomy, $tags))
|
420 |
+
return $terms;
|
421 |
+
} else {
|
422 |
+
return $terms;
|
423 |
+
}
|
424 |
+
}
|
425 |
+
|
426 |
+
usort($terms, array($this, 'taxcmp'));
|
427 |
+
return $terms;
|
428 |
+
}
|
429 |
+
|
430 |
+
function taxcmp($a, $b) {
|
431 |
+
if ($a->term_order == $b->term_order)
|
432 |
+
return 0;
|
433 |
+
return ( $a->term_order < $b->term_order ) ? -1 : 1;
|
434 |
+
}
|
435 |
+
|
436 |
+
function get_scporder_options_objects() {
|
437 |
+
$scporder_options = get_option('scporder_options') ? get_option('scporder_options') : array();
|
438 |
+
$objects = isset($scporder_options['objects']) && is_array($scporder_options['objects']) ? $scporder_options['objects'] : array();
|
439 |
+
return $objects;
|
440 |
+
}
|
441 |
+
|
442 |
+
function get_scporder_options_tags() {
|
443 |
+
$scporder_options = get_option('scporder_options') ? get_option('scporder_options') : array();
|
444 |
+
$tags = isset($scporder_options['tags']) && is_array($scporder_options['tags']) ? $scporder_options['tags'] : array();
|
445 |
+
return $tags;
|
446 |
+
}
|
447 |
+
|
448 |
+
}
|
449 |
+
|
450 |
+
/**
|
451 |
+
* SCP Order Uninstall hook
|
452 |
+
*/
|
453 |
+
register_uninstall_hook(__FILE__, 'scporder_uninstall');
|
454 |
+
|
455 |
+
function scporder_uninstall() {
|
456 |
+
global $wpdb;
|
457 |
+
if (function_exists('is_multisite') && is_multisite()) {
|
458 |
+
$curr_blog = $wpdb->blogid;
|
459 |
+
$blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
|
460 |
+
foreach ($blogids as $blog_id) {
|
461 |
+
switch_to_blog($blog_id);
|
462 |
+
scporder_uninstall_db();
|
463 |
+
}
|
464 |
+
switch_to_blog($curr_blog);
|
465 |
+
} else {
|
466 |
+
scporder_uninstall_db();
|
467 |
+
}
|
468 |
+
}
|
469 |
+
|
470 |
+
function scporder_uninstall_db() {
|
471 |
+
global $wpdb;
|
472 |
+
$result = $wpdb->query("DESCRIBE $wpdb->terms `term_order`");
|
473 |
+
if ($result) {
|
474 |
+
$query = "ALTER TABLE $wpdb->terms DROP `term_order`";
|
475 |
+
$result = $wpdb->query($query);
|
476 |
+
}
|
477 |
+
delete_option('scporder_install');
|
478 |
+
}
|
479 |
+
|
480 |
+
?>
|