Version Description
Download this release
Release Info
Developer | colorlibplugins |
Plugin | Simple Custom Post Order |
Version | 2.3.5 |
Comparing to | |
See all releases |
Code changes from version 2.3.3 to 2.3.5
- assets/scporder.css +10 -10
- assets/scporder.js +31 -31
- assets/taxonomy_order.js +53 -53
- readme.txt → readme.md +30 -27
- settings.php +119 -120
- simple-custom-post-order.php +477 -479
assets/scporder.css
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
.ui-sortable tr:hover {
|
2 |
-
cursor: move;
|
3 |
-
}
|
4 |
-
.ui-sortable tr.alternate {
|
5 |
-
background-color: #F9F9F9;
|
6 |
-
}
|
7 |
-
.ui-sortable tr.ui-sortable-helper {
|
8 |
-
background-color: #F9F9F9;
|
9 |
-
border-top: 1px solid #DFDFDF;
|
10 |
-
}
|
1 |
+
.ui-sortable tr:hover {
|
2 |
+
cursor: move;
|
3 |
+
}
|
4 |
+
.ui-sortable tr.alternate {
|
5 |
+
background-color: #F9F9F9;
|
6 |
+
}
|
7 |
+
.ui-sortable tr.ui-sortable-helper {
|
8 |
+
background-color: #F9F9F9;
|
9 |
+
border-top: 1px solid #DFDFDF;
|
10 |
+
}
|
assets/scporder.js
CHANGED
@@ -1,31 +1,31 @@
|
|
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());
|
27 |
-
});
|
28 |
-
return ui;
|
29 |
-
};
|
30 |
-
|
31 |
-
})(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());
|
27 |
+
});
|
28 |
+
return ui;
|
29 |
+
};
|
30 |
+
|
31 |
+
})(jQuery)
|
assets/taxonomy_order.js
CHANGED
@@ -1,54 +1,54 @@
|
|
1 |
-
jQuery( document ).ready( function( $ )
|
2 |
-
{
|
3 |
-
// if it is taxonomy page
|
4 |
-
if( adminpage == 'edit-tags-php' )
|
5 |
-
{
|
6 |
-
// make table rows sortable
|
7 |
-
$( '.wp-list-table.tags tbody' ).sortable({
|
8 |
-
items: 'tr:not(.inline-edit-row)',
|
9 |
-
cursor: 'move',
|
10 |
-
axis: 'y',
|
11 |
-
containment: 'table.widefat',
|
12 |
-
scrollSensitivity: 40,
|
13 |
-
stop: function( event, ui ) {
|
14 |
-
// array for the ids and positions
|
15 |
-
var rows = new Array([]);
|
16 |
-
|
17 |
-
// show "activity" with spinner
|
18 |
-
hsam_taxonomy_sort_activity_spinner( true );
|
19 |
-
|
20 |
-
$( '.wp-list-table.tags tbody tr:not(.inline-edit-row)' ).each( function( i, e ) {
|
21 |
-
var rowID = parseInt( $( e ).attr( 'id' ).substr( 4 ) );
|
22 |
-
rows[i] = rowID;
|
23 |
-
} );
|
24 |
-
|
25 |
-
// post rows for sorting
|
26 |
-
$.post( ajaxurl, { 'rows' : rows, 'action' : 'get_inline_boxes' }, function(response) {
|
27 |
-
// stop activity spinner
|
28 |
-
hsam_taxonomy_sort_activity_spinner( false );
|
29 |
-
});
|
30 |
-
}
|
31 |
-
});
|
32 |
-
}
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Adds, shows or hides the activity status spinner
|
36 |
-
|
37 |
-
*/
|
38 |
-
function hsam_taxonomy_sort_activity_spinner( status ) {
|
39 |
-
var actions_table = $( '.tablenav .actions' );
|
40 |
-
|
41 |
-
if( actions_table.find( '.spinner' ).length === 0 && status === true ) {
|
42 |
-
// add spinner
|
43 |
-
actions_table.prepend( '<div class="spinner" style="display: inline;" />' );
|
44 |
-
}
|
45 |
-
else if ( status === true ) {
|
46 |
-
// show spinner
|
47 |
-
actions_table.find( '.spinner' ).show();
|
48 |
-
}
|
49 |
-
else {
|
50 |
-
// hide spinner
|
51 |
-
actions_table.find( '.spinner' ).hide();
|
52 |
-
}
|
53 |
-
}
|
54 |
} );
|
1 |
+
jQuery( document ).ready( function( $ )
|
2 |
+
{
|
3 |
+
// if it is taxonomy page
|
4 |
+
if( adminpage == 'edit-tags-php' )
|
5 |
+
{
|
6 |
+
// make table rows sortable
|
7 |
+
$( '.wp-list-table.tags tbody' ).sortable({
|
8 |
+
items: 'tr:not(.inline-edit-row)',
|
9 |
+
cursor: 'move',
|
10 |
+
axis: 'y',
|
11 |
+
containment: 'table.widefat',
|
12 |
+
scrollSensitivity: 40,
|
13 |
+
stop: function( event, ui ) {
|
14 |
+
// array for the ids and positions
|
15 |
+
var rows = new Array([]);
|
16 |
+
|
17 |
+
// show "activity" with spinner
|
18 |
+
hsam_taxonomy_sort_activity_spinner( true );
|
19 |
+
|
20 |
+
$( '.wp-list-table.tags tbody tr:not(.inline-edit-row)' ).each( function( i, e ) {
|
21 |
+
var rowID = parseInt( $( e ).attr( 'id' ).substr( 4 ) );
|
22 |
+
rows[i] = rowID;
|
23 |
+
} );
|
24 |
+
|
25 |
+
// post rows for sorting
|
26 |
+
$.post( ajaxurl, { 'rows' : rows, 'action' : 'get_inline_boxes' }, function(response) {
|
27 |
+
// stop activity spinner
|
28 |
+
hsam_taxonomy_sort_activity_spinner( false );
|
29 |
+
});
|
30 |
+
}
|
31 |
+
});
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Adds, shows or hides the activity status spinner
|
36 |
+
|
37 |
+
*/
|
38 |
+
function hsam_taxonomy_sort_activity_spinner( status ) {
|
39 |
+
var actions_table = $( '.tablenav .actions' );
|
40 |
+
|
41 |
+
if( actions_table.find( '.spinner' ).length === 0 && status === true ) {
|
42 |
+
// add spinner
|
43 |
+
actions_table.prepend( '<div class="spinner" style="display: inline;" />' );
|
44 |
+
}
|
45 |
+
else if ( status === true ) {
|
46 |
+
// show spinner
|
47 |
+
actions_table.find( '.spinner' ).show();
|
48 |
+
}
|
49 |
+
else {
|
50 |
+
// hide spinner
|
51 |
+
actions_table.find( '.spinner' ).hide();
|
52 |
+
}
|
53 |
+
}
|
54 |
} );
|
readme.txt → readme.md
RENAMED
@@ -2,25 +2,24 @@
|
|
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:
|
6 |
-
|
7 |
-
|
8 |
-
License:
|
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 |
|
13 |
== Description ==
|
14 |
|
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
|
19 |
|
20 |
== Installation ==
|
21 |
|
22 |
1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
|
23 |
-
1. Activate the plugin through the 'Plugins' menu in WordPress
|
24 |
|
25 |
== Frequently asked questions ==
|
26 |
|
@@ -30,25 +29,23 @@ An answer to that question.
|
|
30 |
|
31 |
== Screenshots ==
|
32 |
|
33 |
-
1.
|
34 |
-
2.
|
|
|
35 |
|
36 |
== Changelog ==
|
37 |
|
38 |
-
= Version
|
39 |
-
*
|
40 |
|
41 |
-
= Version
|
42 |
-
*
|
43 |
-
* Added Taxonomy Sort
|
44 |
-
* Added Taxonomy Sort option In setting Page
|
45 |
|
46 |
-
= Version 2.
|
47 |
-
*
|
48 |
-
* Taxonomy Activate Checkbox removed.
|
49 |
|
50 |
-
= Version 2.
|
51 |
-
*
|
52 |
|
53 |
= Version 2.2 (02-07-2014) =
|
54 |
* Fixed bug: Custom Query which uses 'order' or 'orderby' parameters is preferred
|
@@ -56,11 +53,17 @@ An answer to that question.
|
|
56 |
* Previous Versions Issues were Improved.
|
57 |
* Removed Taxonomy Sort( Will add in next Version :) )
|
58 |
|
59 |
-
= Version 2.
|
60 |
-
*
|
61 |
|
62 |
-
= Version 2.
|
63 |
-
*
|
|
|
64 |
|
65 |
-
= Version
|
66 |
-
*
|
|
|
|
|
|
|
|
|
|
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: 5.0.0
|
6 |
+
Stable tag: 2.3.5
|
7 |
+
License: GPLv2 or later
|
8 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
9 |
|
10 |
+
Order posts(posts, any custom post types) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary.
|
11 |
|
12 |
== Description ==
|
13 |
|
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 |
+
This plugins is now supported and maintained by <a href="https://colorlib.com/wp/" target="_blank">Colorlib</a>.
|
18 |
|
19 |
== Installation ==
|
20 |
|
21 |
1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
|
22 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
23 |
|
24 |
== Frequently asked questions ==
|
25 |
|
29 |
|
30 |
== Screenshots ==
|
31 |
|
32 |
+
1. Order Custom Posts
|
33 |
+
2. Order Posts
|
34 |
+
3. Settings
|
35 |
|
36 |
== Changelog ==
|
37 |
|
38 |
+
= Version 2.3.5 =
|
39 |
+
* Fixed https://github.com/ColorlibHQ/simple-custom-post-order/issues/12
|
40 |
|
41 |
+
= Version 2.3.4 =
|
42 |
+
* Removed deprecated function "screen_icon"
|
|
|
|
|
43 |
|
44 |
+
= Version 2.3.2 (17-03-2017) =
|
45 |
+
* Minor documentation and readme tweaks
|
|
|
46 |
|
47 |
+
= Version 2.3 (24-03-2014) =
|
48 |
+
* Fixed major bug on taxonomy and post order
|
49 |
|
50 |
= Version 2.2 (02-07-2014) =
|
51 |
* Fixed bug: Custom Query which uses 'order' or 'orderby' parameters is preferred
|
53 |
* Previous Versions Issues were Improved.
|
54 |
* Removed Taxonomy Sort( Will add in next Version :) )
|
55 |
|
56 |
+
= Version 2.1 (31-12-2013) =
|
57 |
+
* Prevent Breaking autocomplete
|
58 |
|
59 |
+
= Version 2.0 (22-11-2013) =
|
60 |
+
* Fixed Undefined Notice Error in wp version 3.7.1
|
61 |
+
* Taxonomy Activate Checkbox removed.
|
62 |
|
63 |
+
= Version 1.5 (25-07-2013) =
|
64 |
+
* Fix : fix errors
|
65 |
+
* Added Taxonomy Sort
|
66 |
+
* Added Taxonomy Sort option In setting Page
|
67 |
+
|
68 |
+
= Version 1.0 (20-07-2013) =
|
69 |
+
* Initial release.
|
settings.php
CHANGED
@@ -1,121 +1,120 @@
|
|
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 |
-
|
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 |
-
|
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 |
-
})(jQuery)
|
121 |
</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 |
+
<h2><?php _e('Simple Custom Post Order Settings', 'scporder'); ?></h2>
|
9 |
+
<?php if (isset($_GET['msg'])) : ?>
|
10 |
+
<div id="message" class="updated below-h2">
|
11 |
+
<?php if ($_GET['msg'] == 'update') : ?>
|
12 |
+
<p><?php _e('Settings Updated.','scporder'); ?></p>
|
13 |
+
<?php endif; ?>
|
14 |
+
</div>
|
15 |
+
<?php endif; ?>
|
16 |
+
|
17 |
+
<form method="post">
|
18 |
+
|
19 |
+
<?php if (function_exists('wp_nonce_field')) wp_nonce_field('nonce_scporder'); ?>
|
20 |
+
|
21 |
+
<div id="scporder_select_objects">
|
22 |
+
|
23 |
+
<table class="form-table">
|
24 |
+
<tbody>
|
25 |
+
<tr valign="top">
|
26 |
+
<th scope="row"><?php _e('Check to Sort Post Types', 'scporder') ?></th>
|
27 |
+
<td>
|
28 |
+
<label><input type="checkbox" id="scporder_allcheck_objects"> <?php _e('Check All', 'scporder') ?></label><br>
|
29 |
+
<?php
|
30 |
+
$post_types = get_post_types(array(
|
31 |
+
'show_ui' => true,
|
32 |
+
'show_in_menu' => true,
|
33 |
+
), 'objects');
|
34 |
+
|
35 |
+
foreach ($post_types as $post_type) {
|
36 |
+
if ($post_type->name == 'attachment')
|
37 |
+
continue;
|
38 |
+
?>
|
39 |
+
<label><input type="checkbox" name="objects[]" value="<?php echo $post_type->name; ?>" <?php
|
40 |
+
if (isset($scporder_objects) && is_array($scporder_objects)) {
|
41 |
+
if (in_array($post_type->name, $scporder_objects)) {
|
42 |
+
echo 'checked="checked"';
|
43 |
+
}
|
44 |
+
}
|
45 |
+
?>> <?php echo $post_type->label; ?></label><br>
|
46 |
+
<?php
|
47 |
+
}
|
48 |
+
?>
|
49 |
+
</td>
|
50 |
+
</tr>
|
51 |
+
</tbody>
|
52 |
+
</table>
|
53 |
+
|
54 |
+
</div>
|
55 |
+
|
56 |
+
|
57 |
+
<div id="scporder_select_tags">
|
58 |
+
<table class="form-table">
|
59 |
+
<tbody>
|
60 |
+
<tr valign="top">
|
61 |
+
<th scope="row"><?php _e('Check to Sort Taxonomies', 'scporder') ?></th>
|
62 |
+
<td>
|
63 |
+
<label><input type="checkbox" id="scporder_allcheck_tags"> <?php _e('Check All', 'scporder') ?></label><br>
|
64 |
+
<?php
|
65 |
+
$taxonomies = get_taxonomies(array(
|
66 |
+
'show_ui' => true,
|
67 |
+
), 'objects');
|
68 |
+
|
69 |
+
foreach ($taxonomies as $taxonomy) {
|
70 |
+
if ($taxonomy->name == 'post_format')
|
71 |
+
continue;
|
72 |
+
?>
|
73 |
+
<label><input type="checkbox" name="tags[]" value="<?php echo $taxonomy->name; ?>" <?php
|
74 |
+
if (isset($scporder_tags) && is_array($scporder_tags)) {
|
75 |
+
if (in_array($taxonomy->name, $scporder_tags)) {
|
76 |
+
echo 'checked="checked"';
|
77 |
+
}
|
78 |
+
}
|
79 |
+
?>> <?php echo $taxonomy->label ?></label><br>
|
80 |
+
<?php
|
81 |
+
}
|
82 |
+
?>
|
83 |
+
</td>
|
84 |
+
</tr>
|
85 |
+
</tbody>
|
86 |
+
</table>
|
87 |
+
|
88 |
+
</div>
|
89 |
+
<p class="submit">
|
90 |
+
<input type="submit" class="button-primary" name="scporder_submit" value="<?php _e('Update', 'scporder'); ?>">
|
91 |
+
</p>
|
92 |
+
|
93 |
+
</form>
|
94 |
+
<h3>Like this simple plugin?</h3>
|
95 |
+
<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>
|
96 |
+
|
97 |
+
|
98 |
+
</div>
|
99 |
+
|
100 |
+
<script>
|
101 |
+
(function ($) {
|
102 |
+
|
103 |
+
$("#scporder_allcheck_objects").on('click', function () {
|
104 |
+
var items = $("#scporder_select_objects input");
|
105 |
+
if ($(this).is(':checked'))
|
106 |
+
$(items).prop('checked', true);
|
107 |
+
else
|
108 |
+
$(items).prop('checked', false);
|
109 |
+
});
|
110 |
+
|
111 |
+
$("#scporder_allcheck_tags").on('click', function () {
|
112 |
+
var items = $("#scporder_select_tags input");
|
113 |
+
if ($(this).is(':checked'))
|
114 |
+
$(items).prop('checked', true);
|
115 |
+
else
|
116 |
+
$(items).prop('checked', false);
|
117 |
+
});
|
118 |
+
|
119 |
+
})(jQuery)
|
|
|
120 |
</script>
|
simple-custom-post-order.php
CHANGED
@@ -1,480 +1,478 @@
|
|
1 |
-
<?php
|
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.
|
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 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
$objects
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
$objects
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
if (
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
$
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
if ($wp_query->get('
|
381 |
-
$wp_query->set('
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
if (!$wp_query->get('
|
386 |
-
$wp_query->set('
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
}
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
$
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
$
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
$
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
}
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
}
|
479 |
-
|
480 |
?>
|
1 |
+
<?php
|
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.5
|
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 |
+
$where = preg_replace("/p.post_date < \'[0-9\-\s\:]+\'/i", "p.menu_order > '" . $post->menu_order . "'", $where);
|
303 |
+
}
|
304 |
+
return $where;
|
305 |
+
}
|
306 |
+
|
307 |
+
function scporder_previous_post_sort($orderby) {
|
308 |
+
global $post;
|
309 |
+
|
310 |
+
$objects = $this->get_scporder_options_objects();
|
311 |
+
if (empty($objects))
|
312 |
+
return $orderby;
|
313 |
+
|
314 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
315 |
+
$orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
|
316 |
+
}
|
317 |
+
return $orderby;
|
318 |
+
}
|
319 |
+
|
320 |
+
function scporder_next_post_where($where) {
|
321 |
+
global $post;
|
322 |
+
|
323 |
+
$objects = $this->get_scporder_options_objects();
|
324 |
+
if (empty($objects))
|
325 |
+
return $where;
|
326 |
+
|
327 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
328 |
+
$where = preg_replace("/p.post_date > \'[0-9\-\s\:]+\'/i", "p.menu_order < '" . $post->menu_order . "'", $where);
|
329 |
+
}
|
330 |
+
return $where;
|
331 |
+
}
|
332 |
+
|
333 |
+
function scporder_next_post_sort($orderby) {
|
334 |
+
global $post;
|
335 |
+
|
336 |
+
$objects = $this->get_scporder_options_objects();
|
337 |
+
if (empty($objects))
|
338 |
+
return $orderby;
|
339 |
+
|
340 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
341 |
+
$orderby = 'ORDER BY p.menu_order DESC LIMIT 1';
|
342 |
+
}
|
343 |
+
return $orderby;
|
344 |
+
}
|
345 |
+
|
346 |
+
function scporder_pre_get_posts($wp_query) {
|
347 |
+
$objects = $this->get_scporder_options_objects();
|
348 |
+
if (empty($objects))
|
349 |
+
return false;
|
350 |
+
if (is_admin()) {
|
351 |
+
|
352 |
+
if (isset($wp_query->query['post_type']) && !isset($_GET['orderby'])) {
|
353 |
+
if (in_array($wp_query->query['post_type'], $objects)) {
|
354 |
+
$wp_query->set('orderby', 'menu_order');
|
355 |
+
$wp_query->set('order', 'ASC');
|
356 |
+
}
|
357 |
+
}
|
358 |
+
} else {
|
359 |
+
|
360 |
+
$active = false;
|
361 |
+
|
362 |
+
if (isset($wp_query->query['post_type'])) {
|
363 |
+
if (!is_array($wp_query->query['post_type'])) {
|
364 |
+
if (in_array($wp_query->query['post_type'], $objects)) {
|
365 |
+
$active = true;
|
366 |
+
}
|
367 |
+
}
|
368 |
+
} else {
|
369 |
+
if (in_array('post', $objects)) {
|
370 |
+
$active = true;
|
371 |
+
}
|
372 |
+
}
|
373 |
+
|
374 |
+
if (!$active)
|
375 |
+
return false;
|
376 |
+
|
377 |
+
if (isset($wp_query->query['suppress_filters'])) {
|
378 |
+
if ($wp_query->get('orderby') == 'date')
|
379 |
+
$wp_query->set('orderby', 'menu_order');
|
380 |
+
if ($wp_query->get('order') == 'DESC')
|
381 |
+
$wp_query->set('order', 'ASC');
|
382 |
+
} else {
|
383 |
+
if (!$wp_query->get('orderby'))
|
384 |
+
$wp_query->set('orderby', 'menu_order');
|
385 |
+
if (!$wp_query->get('order'))
|
386 |
+
$wp_query->set('order', 'ASC');
|
387 |
+
}
|
388 |
+
}
|
389 |
+
}
|
390 |
+
|
391 |
+
function scporder_get_terms_orderby($orderby, $args) {
|
392 |
+
if (is_admin())
|
393 |
+
return $orderby;
|
394 |
+
|
395 |
+
$tags = $this->get_scporder_options_tags();
|
396 |
+
|
397 |
+
if (!isset($args['taxonomy']))
|
398 |
+
return $orderby;
|
399 |
+
|
400 |
+
$taxonomy = $args['taxonomy'];
|
401 |
+
if (!in_array($taxonomy, $tags))
|
402 |
+
return $orderby;
|
403 |
+
|
404 |
+
$orderby = 't.term_order';
|
405 |
+
return $orderby;
|
406 |
+
}
|
407 |
+
|
408 |
+
function scporder_get_object_terms($terms) {
|
409 |
+
$tags = $this->get_scporder_options_tags();
|
410 |
+
|
411 |
+
if (is_admin() && isset($_GET['orderby']))
|
412 |
+
return $terms;
|
413 |
+
|
414 |
+
foreach ($terms as $key => $term) {
|
415 |
+
if (is_object($term) && isset($term->taxonomy)) {
|
416 |
+
$taxonomy = $term->taxonomy;
|
417 |
+
if (!in_array($taxonomy, $tags))
|
418 |
+
return $terms;
|
419 |
+
} else {
|
420 |
+
return $terms;
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
usort($terms, array($this, 'taxcmp'));
|
425 |
+
return $terms;
|
426 |
+
}
|
427 |
+
|
428 |
+
function taxcmp($a, $b) {
|
429 |
+
if ($a->term_order == $b->term_order)
|
430 |
+
return 0;
|
431 |
+
return ( $a->term_order < $b->term_order ) ? -1 : 1;
|
432 |
+
}
|
433 |
+
|
434 |
+
function get_scporder_options_objects() {
|
435 |
+
$scporder_options = get_option('scporder_options') ? get_option('scporder_options') : array();
|
436 |
+
$objects = isset($scporder_options['objects']) && is_array($scporder_options['objects']) ? $scporder_options['objects'] : array();
|
437 |
+
return $objects;
|
438 |
+
}
|
439 |
+
|
440 |
+
function get_scporder_options_tags() {
|
441 |
+
$scporder_options = get_option('scporder_options') ? get_option('scporder_options') : array();
|
442 |
+
$tags = isset($scporder_options['tags']) && is_array($scporder_options['tags']) ? $scporder_options['tags'] : array();
|
443 |
+
return $tags;
|
444 |
+
}
|
445 |
+
|
446 |
+
}
|
447 |
+
|
448 |
+
/**
|
449 |
+
* SCP Order Uninstall hook
|
450 |
+
*/
|
451 |
+
register_uninstall_hook(__FILE__, 'scporder_uninstall');
|
452 |
+
|
453 |
+
function scporder_uninstall() {
|
454 |
+
global $wpdb;
|
455 |
+
if (function_exists('is_multisite') && is_multisite()) {
|
456 |
+
$curr_blog = $wpdb->blogid;
|
457 |
+
$blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
|
458 |
+
foreach ($blogids as $blog_id) {
|
459 |
+
switch_to_blog($blog_id);
|
460 |
+
scporder_uninstall_db();
|
461 |
+
}
|
462 |
+
switch_to_blog($curr_blog);
|
463 |
+
} else {
|
464 |
+
scporder_uninstall_db();
|
465 |
+
}
|
466 |
+
}
|
467 |
+
|
468 |
+
function scporder_uninstall_db() {
|
469 |
+
global $wpdb;
|
470 |
+
$result = $wpdb->query("DESCRIBE $wpdb->terms `term_order`");
|
471 |
+
if ($result) {
|
472 |
+
$query = "ALTER TABLE $wpdb->terms DROP `term_order`";
|
473 |
+
$result = $wpdb->query($query);
|
474 |
+
}
|
475 |
+
delete_option('scporder_install');
|
476 |
+
}
|
477 |
+
|
|
|
|
|
478 |
?>
|