Version Description
Download this release
Release Info
Developer | machothemes |
Plugin | Simple Custom Post Order |
Version | 2.4.0 |
Comparing to | |
See all releases |
Code changes from version 2.3.9 to 2.4.0
- assets/scporder.css +10 -10
- assets/scporder.js +31 -31
- assets/taxonomy_order.js +53 -53
- readme.md +84 -81
- simple-custom-post-order.php +562 -561
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.md
CHANGED
@@ -1,81 +1,84 @@
|
|
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: 5.0.0
|
6 |
-
Stable tag: 2.
|
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 |
-
|
26 |
-
= A question that someone might have =
|
27 |
-
|
28 |
-
An answer to that question.
|
29 |
-
|
30 |
-
== Screenshots ==
|
31 |
-
|
32 |
-
1. Order Custom Posts
|
33 |
-
2. Order Posts
|
34 |
-
3. Settings
|
35 |
-
|
36 |
-
== Changelog ==
|
37 |
-
|
38 |
-
= Version 2.
|
39 |
-
*
|
40 |
-
|
41 |
-
= Version 2.3.
|
42 |
-
*
|
43 |
-
|
44 |
-
= Version 2.3.
|
45 |
-
* Fixed white screen ( https://wordpress.org/support/topic/white-screen-after-upgrade-to-2-3-6/ )
|
46 |
-
|
47 |
-
= Version 2.3.
|
48 |
-
* Fixed https://
|
49 |
-
|
50 |
-
= Version 2.3.
|
51 |
-
* Fixed https://github.com/ColorlibHQ/simple-custom-post-order/issues/
|
52 |
-
|
53 |
-
= Version 2.3.
|
54 |
-
*
|
55 |
-
|
56 |
-
= Version 2.3.
|
57 |
-
*
|
58 |
-
|
59 |
-
= Version 2.3 (
|
60 |
-
*
|
61 |
-
|
62 |
-
= Version 2.
|
63 |
-
* Fixed bug
|
64 |
-
|
65 |
-
|
66 |
-
*
|
67 |
-
|
68 |
-
|
69 |
-
*
|
70 |
-
|
71 |
-
= Version 2.
|
72 |
-
*
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
*
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
*
|
|
|
|
|
|
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: 5.0.0
|
6 |
+
Stable tag: 2.4.0
|
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 |
+
|
26 |
+
= A question that someone might have =
|
27 |
+
|
28 |
+
An answer to that question.
|
29 |
+
|
30 |
+
== Screenshots ==
|
31 |
+
|
32 |
+
1. Order Custom Posts
|
33 |
+
2. Order Posts
|
34 |
+
3. Settings
|
35 |
+
|
36 |
+
== Changelog ==
|
37 |
+
|
38 |
+
= Version 2.4.0 =
|
39 |
+
* Optimized our db queries ( https://wordpress.org/support/topic/update-optimization/ )
|
40 |
+
|
41 |
+
= Version 2.3.9 =
|
42 |
+
* Added button to dismiss the admin notice
|
43 |
+
|
44 |
+
= Version 2.3.8 =
|
45 |
+
* Fixed white screen ( https://wordpress.org/support/topic/white-screen-after-upgrade-to-2-3-6/ )
|
46 |
+
|
47 |
+
= Version 2.3.7 =
|
48 |
+
* Fixed white screen ( https://wordpress.org/support/topic/white-screen-after-upgrade-to-2-3-6/ )
|
49 |
+
|
50 |
+
= Version 2.3.6 =
|
51 |
+
* Fixed https://github.com/ColorlibHQ/simple-custom-post-order/issues/3
|
52 |
+
|
53 |
+
= Version 2.3.5 =
|
54 |
+
* Fixed https://github.com/ColorlibHQ/simple-custom-post-order/issues/12
|
55 |
+
|
56 |
+
= Version 2.3.4 =
|
57 |
+
* Removed deprecated function "screen_icon"
|
58 |
+
|
59 |
+
= Version 2.3.2 (17-03-2017) =
|
60 |
+
* Minor documentation and readme tweaks
|
61 |
+
|
62 |
+
= Version 2.3 (24-03-2014) =
|
63 |
+
* Fixed major bug on taxonomy and post order
|
64 |
+
|
65 |
+
= Version 2.2 (02-07-2014) =
|
66 |
+
* Fixed bug: Custom Query which uses 'order' or 'orderby' parameters is preferred
|
67 |
+
* It does not depend on the designation manner of arguments( Parameters ). ( $args = 'orderby=&order=' or $args = array( 'orderby' => '', 'order' => '' ) )
|
68 |
+
* Previous Versions Issues were Improved.
|
69 |
+
* Removed Taxonomy Sort( Will add in next Version :) )
|
70 |
+
|
71 |
+
= Version 2.1 (31-12-2013) =
|
72 |
+
* Prevent Breaking autocomplete
|
73 |
+
|
74 |
+
= Version 2.0 (22-11-2013) =
|
75 |
+
* Fixed Undefined Notice Error in wp version 3.7.1
|
76 |
+
* Taxonomy Activate Checkbox removed.
|
77 |
+
|
78 |
+
= Version 1.5 (25-07-2013) =
|
79 |
+
* Fix : fix errors
|
80 |
+
* Added Taxonomy Sort
|
81 |
+
* Added Taxonomy Sort option In setting Page
|
82 |
+
|
83 |
+
= Version 1.0 (20-07-2013) =
|
84 |
+
* Initial release.
|
simple-custom-post-order.php
CHANGED
@@ -1,562 +1,563 @@
|
|
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.
|
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 |
-
add_action( 'admin_notices', array( $this, 'scporder_notice_not_checked' ) );
|
46 |
-
add_action( 'wp_ajax_scporder_dismiss_notices', array( $this, 'dismiss_notices' ) );
|
47 |
-
|
48 |
-
}
|
49 |
-
|
50 |
-
public function dismiss_notices() {
|
51 |
-
|
52 |
-
if ( ! check_admin_referer( 'scporder_dismiss_notice', 'scporder_nonce' ) ) {
|
53 |
-
wp_die( 'nok' );
|
54 |
-
}
|
55 |
-
|
56 |
-
update_option( 'scporder_notice', '1' );
|
57 |
-
|
58 |
-
wp_die( 'ok' );
|
59 |
-
|
60 |
-
}
|
61 |
-
|
62 |
-
public function scporder_notice_not_checked() {
|
63 |
-
|
64 |
-
$settings = $this->get_scporder_options_objects();
|
65 |
-
if ( ! empty( $settings ) ){
|
66 |
-
return;
|
67 |
-
}
|
68 |
-
|
69 |
-
$screen = get_current_screen();
|
70 |
-
|
71 |
-
if ( 'settings_page_scporder-settings' == $screen->id ) {
|
72 |
-
return;
|
73 |
-
}
|
74 |
-
|
75 |
-
$dismessed = get_option( 'scporder_notice', false );
|
76 |
-
|
77 |
-
if ( $dismessed ) {
|
78 |
-
return;
|
79 |
-
}
|
80 |
-
|
81 |
-
?>
|
82 |
-
<div class="notice scpo-notice" id="scpo-notice">
|
83 |
-
<img src="<?php echo esc_url( plugins_url( 'assets/logo.jpg', __FILE__ ) ); ?>" width="80">
|
84 |
-
|
85 |
-
<h1><?php esc_html_e( 'Simple Custom Post Order', 'scporder' ); ?></h1>
|
86 |
-
|
87 |
-
<p><?php esc_html_e( 'Thank you for installing our awesome plugin, in order to enable it you need to go to the settings page and select which custom post or taxonomy you want to order.', 'scporder' ); ?></p>
|
88 |
-
|
89 |
-
<p><a href="<?php echo admin_url( 'options-general.php?page=scporder-settings' ) ?>" class="button button-primary button-hero"><?php esc_html_e( 'Get started !', 'scporder' ); ?></a></p>
|
90 |
-
<button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'scporder' ); ?></span></button>
|
91 |
-
</div>
|
92 |
-
|
93 |
-
<style>
|
94 |
-
.scpo-notice {
|
95 |
-
background: #e9eff3;
|
96 |
-
border: 10px solid #fff;
|
97 |
-
color: #608299;
|
98 |
-
padding: 30px;
|
99 |
-
text-align: center;
|
100 |
-
position: relative;
|
101 |
-
}
|
102 |
-
</style>
|
103 |
-
<script>
|
104 |
-
jQuery(document).ready(function(){
|
105 |
-
jQuery( '#scpo-notice .notice-dismiss' ).click(function( evt ){
|
106 |
-
evt.preventDefault();
|
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 |
-
wp_enqueue_script('jquery');
|
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 |
-
$input_options
|
313 |
-
$input_options['
|
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 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
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 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
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 |
-
$wp_query->set('
|
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 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
$
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
$
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
$
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
}
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
$
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
|
|
562 |
?>
|
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.4.0
|
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 |
+
add_action( 'admin_notices', array( $this, 'scporder_notice_not_checked' ) );
|
46 |
+
add_action( 'wp_ajax_scporder_dismiss_notices', array( $this, 'dismiss_notices' ) );
|
47 |
+
|
48 |
+
}
|
49 |
+
|
50 |
+
public function dismiss_notices() {
|
51 |
+
|
52 |
+
if ( ! check_admin_referer( 'scporder_dismiss_notice', 'scporder_nonce' ) ) {
|
53 |
+
wp_die( 'nok' );
|
54 |
+
}
|
55 |
+
|
56 |
+
update_option( 'scporder_notice', '1' );
|
57 |
+
|
58 |
+
wp_die( 'ok' );
|
59 |
+
|
60 |
+
}
|
61 |
+
|
62 |
+
public function scporder_notice_not_checked() {
|
63 |
+
|
64 |
+
$settings = $this->get_scporder_options_objects();
|
65 |
+
if ( ! empty( $settings ) ){
|
66 |
+
return;
|
67 |
+
}
|
68 |
+
|
69 |
+
$screen = get_current_screen();
|
70 |
+
|
71 |
+
if ( 'settings_page_scporder-settings' == $screen->id ) {
|
72 |
+
return;
|
73 |
+
}
|
74 |
+
|
75 |
+
$dismessed = get_option( 'scporder_notice', false );
|
76 |
+
|
77 |
+
if ( $dismessed ) {
|
78 |
+
return;
|
79 |
+
}
|
80 |
+
|
81 |
+
?>
|
82 |
+
<div class="notice scpo-notice" id="scpo-notice">
|
83 |
+
<img src="<?php echo esc_url( plugins_url( 'assets/logo.jpg', __FILE__ ) ); ?>" width="80">
|
84 |
+
|
85 |
+
<h1><?php esc_html_e( 'Simple Custom Post Order', 'scporder' ); ?></h1>
|
86 |
+
|
87 |
+
<p><?php esc_html_e( 'Thank you for installing our awesome plugin, in order to enable it you need to go to the settings page and select which custom post or taxonomy you want to order.', 'scporder' ); ?></p>
|
88 |
+
|
89 |
+
<p><a href="<?php echo admin_url( 'options-general.php?page=scporder-settings' ) ?>" class="button button-primary button-hero"><?php esc_html_e( 'Get started !', 'scporder' ); ?></a></p>
|
90 |
+
<button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.', 'scporder' ); ?></span></button>
|
91 |
+
</div>
|
92 |
+
|
93 |
+
<style>
|
94 |
+
.scpo-notice {
|
95 |
+
background: #e9eff3;
|
96 |
+
border: 10px solid #fff;
|
97 |
+
color: #608299;
|
98 |
+
padding: 30px;
|
99 |
+
text-align: center;
|
100 |
+
position: relative;
|
101 |
+
}
|
102 |
+
</style>
|
103 |
+
<script>
|
104 |
+
jQuery(document).ready(function(){
|
105 |
+
jQuery( '#scpo-notice .notice-dismiss' ).click(function( evt ){
|
106 |
+
evt.preventDefault();
|
107 |
+
|
108 |
+
var ajaxData = {
|
109 |
+
'action' : 'scporder_dismiss_notices',
|
110 |
+
'scporder_nonce' : '<?php echo wp_create_nonce( 'scporder_dismiss_notice' ) ?>'
|
111 |
+
}
|
112 |
+
|
113 |
+
jQuery.ajax({
|
114 |
+
url: "<?php echo admin_url('admin-ajax.php'); ?>",
|
115 |
+
method: "POST",
|
116 |
+
data: ajaxData,
|
117 |
+
dataType: "html"
|
118 |
+
}).done(function(){
|
119 |
+
jQuery("#scpo-notice").hide();
|
120 |
+
});
|
121 |
+
|
122 |
+
});
|
123 |
+
})
|
124 |
+
</script>
|
125 |
+
<?php
|
126 |
+
}
|
127 |
+
|
128 |
+
public function scporder_install() {
|
129 |
+
global $wpdb;
|
130 |
+
$result = $wpdb->query("DESCRIBE $wpdb->terms `term_order`");
|
131 |
+
if (!$result) {
|
132 |
+
$query = "ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'";
|
133 |
+
$result = $wpdb->query($query);
|
134 |
+
}
|
135 |
+
update_option('scporder_install', 1);
|
136 |
+
}
|
137 |
+
|
138 |
+
public function admin_menu() {
|
139 |
+
add_options_page(__('SCPOrder', 'scporder'), __('SCPOrder', 'scporder'), 'manage_options', 'scporder-settings', array($this, 'admin_page'));
|
140 |
+
}
|
141 |
+
|
142 |
+
public function admin_page() {
|
143 |
+
require SCPORDER_DIR . 'settings.php';
|
144 |
+
}
|
145 |
+
|
146 |
+
public function _check_load_script_css() {
|
147 |
+
$active = false;
|
148 |
+
|
149 |
+
$objects = $this->get_scporder_options_objects();
|
150 |
+
$tags = $this->get_scporder_options_tags();
|
151 |
+
|
152 |
+
if (empty($objects) && empty($tags))
|
153 |
+
return false;
|
154 |
+
|
155 |
+
if (isset($_GET['orderby']) || strstr($_SERVER['REQUEST_URI'], 'action=edit') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php'))
|
156 |
+
return false;
|
157 |
+
|
158 |
+
if (!empty($objects)) {
|
159 |
+
if (isset($_GET['post_type']) && !isset($_GET['taxonomy']) && in_array($_GET['post_type'], $objects)) { // if page or custom post types
|
160 |
+
$active = true;
|
161 |
+
}
|
162 |
+
if (!isset($_GET['post_type']) && strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') && in_array('post', $objects)) { // if post
|
163 |
+
$active = true;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
if (!empty($tags)) {
|
168 |
+
if (isset($_GET['taxonomy']) && in_array($_GET['taxonomy'], $tags)) {
|
169 |
+
$active = true;
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
return $active;
|
174 |
+
}
|
175 |
+
|
176 |
+
public function load_script_css() {
|
177 |
+
if ($this->_check_load_script_css()) {
|
178 |
+
wp_enqueue_script('jquery');
|
179 |
+
wp_enqueue_script('jquery-ui-sortable');
|
180 |
+
wp_enqueue_script('scporderjs', SCPORDER_URL . '/assets/scporder.js', array('jquery'), null, true);
|
181 |
+
|
182 |
+
wp_enqueue_style('scporder', SCPORDER_URL . '/assets/scporder.css', array(), null);
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
public function refresh() {
|
187 |
+
global $wpdb;
|
188 |
+
$objects = $this->get_scporder_options_objects();
|
189 |
+
$tags = $this->get_scporder_options_tags();
|
190 |
+
|
191 |
+
if (!empty($objects)) {
|
192 |
+
foreach ($objects as $object) {
|
193 |
+
$result = $wpdb->get_results("
|
194 |
+
SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
|
195 |
+
FROM $wpdb->posts
|
196 |
+
WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
197 |
+
");
|
198 |
+
|
199 |
+
if ($result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max)
|
200 |
+
continue;
|
201 |
+
|
202 |
+
// Here's the optimization
|
203 |
+
$wpdb->query("SET @row_number = 0;");
|
204 |
+
$wpdb->query("UPDATE $wpdb->posts as pt JOIN (
|
205 |
+
SELECT ID, (@row_number:=@row_number + 1) AS rank
|
206 |
+
FROM $wpdb->posts
|
207 |
+
WHERE post_type = '$object' AND post_status IN ( 'publish', 'pending', 'draft', 'private', 'future' )
|
208 |
+
ORDER BY menu_order ASC
|
209 |
+
) as pt2
|
210 |
+
ON pt.id = pt2.id
|
211 |
+
SET pt.menu_order = pt2.rank;");
|
212 |
+
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
if (!empty($tags)) {
|
217 |
+
foreach ($tags as $taxonomy) {
|
218 |
+
$result = $wpdb->get_results("
|
219 |
+
SELECT count(*) as cnt, max(term_order) as max, min(term_order) as min
|
220 |
+
FROM $wpdb->terms AS terms
|
221 |
+
INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
|
222 |
+
WHERE term_taxonomy.taxonomy = '" . $taxonomy . "'
|
223 |
+
");
|
224 |
+
if ($result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max)
|
225 |
+
continue;
|
226 |
+
|
227 |
+
$results = $wpdb->get_results("
|
228 |
+
SELECT terms.term_id
|
229 |
+
FROM $wpdb->terms AS terms
|
230 |
+
INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
|
231 |
+
WHERE term_taxonomy.taxonomy = '" . $taxonomy . "'
|
232 |
+
ORDER BY term_order ASC
|
233 |
+
");
|
234 |
+
foreach ($results as $key => $result) {
|
235 |
+
$wpdb->update($wpdb->terms, array('term_order' => $key + 1), array('term_id' => $result->term_id));
|
236 |
+
}
|
237 |
+
}
|
238 |
+
}
|
239 |
+
}
|
240 |
+
|
241 |
+
public function update_menu_order() {
|
242 |
+
global $wpdb;
|
243 |
+
|
244 |
+
parse_str($_POST['order'], $data);
|
245 |
+
|
246 |
+
if (!is_array($data))
|
247 |
+
return false;
|
248 |
+
|
249 |
+
$id_arr = array();
|
250 |
+
foreach ($data as $key => $values) {
|
251 |
+
foreach ($values as $position => $id) {
|
252 |
+
$id_arr[] = $id;
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
$menu_order_arr = array();
|
257 |
+
foreach ($id_arr as $key => $id) {
|
258 |
+
$results = $wpdb->get_results("SELECT menu_order FROM $wpdb->posts WHERE ID = " . intval($id));
|
259 |
+
foreach ($results as $result) {
|
260 |
+
$menu_order_arr[] = $result->menu_order;
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
sort($menu_order_arr);
|
265 |
+
|
266 |
+
foreach ($data as $key => $values) {
|
267 |
+
foreach ($values as $position => $id) {
|
268 |
+
$wpdb->update($wpdb->posts, array('menu_order' => $menu_order_arr[$position]), array('ID' => intval($id)));
|
269 |
+
}
|
270 |
+
}
|
271 |
+
}
|
272 |
+
|
273 |
+
public function update_menu_order_tags() {
|
274 |
+
global $wpdb;
|
275 |
+
|
276 |
+
parse_str($_POST['order'], $data);
|
277 |
+
|
278 |
+
if (!is_array($data))
|
279 |
+
return false;
|
280 |
+
|
281 |
+
$id_arr = array();
|
282 |
+
foreach ($data as $key => $values) {
|
283 |
+
foreach ($values as $position => $id) {
|
284 |
+
$id_arr[] = $id;
|
285 |
+
}
|
286 |
+
}
|
287 |
+
|
288 |
+
$menu_order_arr = array();
|
289 |
+
foreach ($id_arr as $key => $id) {
|
290 |
+
$results = $wpdb->get_results("SELECT term_order FROM $wpdb->terms WHERE term_id = " . intval($id));
|
291 |
+
foreach ($results as $result) {
|
292 |
+
$menu_order_arr[] = $result->term_order;
|
293 |
+
}
|
294 |
+
}
|
295 |
+
sort($menu_order_arr);
|
296 |
+
|
297 |
+
foreach ($data as $key => $values) {
|
298 |
+
foreach ($values as $position => $id) {
|
299 |
+
$wpdb->update($wpdb->terms, array('term_order' => $menu_order_arr[$position]), array('term_id' => intval($id)));
|
300 |
+
}
|
301 |
+
}
|
302 |
+
}
|
303 |
+
|
304 |
+
public function update_options() {
|
305 |
+
global $wpdb;
|
306 |
+
|
307 |
+
if (!isset($_POST['scporder_submit']))
|
308 |
+
return false;
|
309 |
+
|
310 |
+
check_admin_referer('nonce_scporder');
|
311 |
+
|
312 |
+
$input_options = array();
|
313 |
+
$input_options['objects'] = isset($_POST['objects']) ? $_POST['objects'] : '';
|
314 |
+
$input_options['tags'] = isset($_POST['tags']) ? $_POST['tags'] : '';
|
315 |
+
|
316 |
+
update_option('scporder_options', $input_options);
|
317 |
+
|
318 |
+
$objects = $this->get_scporder_options_objects();
|
319 |
+
$tags = $this->get_scporder_options_tags();
|
320 |
+
|
321 |
+
if (!empty($objects)) {
|
322 |
+
foreach ($objects as $object) {
|
323 |
+
$result = $wpdb->get_results("
|
324 |
+
SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
|
325 |
+
FROM $wpdb->posts
|
326 |
+
WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
327 |
+
");
|
328 |
+
if ($result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max)
|
329 |
+
continue;
|
330 |
+
|
331 |
+
if ($object == 'page') {
|
332 |
+
$results = $wpdb->get_results("
|
333 |
+
SELECT ID
|
334 |
+
FROM $wpdb->posts
|
335 |
+
WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
336 |
+
ORDER BY post_title ASC
|
337 |
+
");
|
338 |
+
} else {
|
339 |
+
$results = $wpdb->get_results("
|
340 |
+
SELECT ID
|
341 |
+
FROM $wpdb->posts
|
342 |
+
WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
|
343 |
+
ORDER BY post_date DESC
|
344 |
+
");
|
345 |
+
}
|
346 |
+
foreach ($results as $key => $result) {
|
347 |
+
$wpdb->update($wpdb->posts, array('menu_order' => $key + 1), array('ID' => $result->ID));
|
348 |
+
}
|
349 |
+
}
|
350 |
+
}
|
351 |
+
|
352 |
+
if (!empty($tags)) {
|
353 |
+
foreach ($tags as $taxonomy) {
|
354 |
+
$result = $wpdb->get_results("
|
355 |
+
SELECT count(*) as cnt, max(term_order) as max, min(term_order) as min
|
356 |
+
FROM $wpdb->terms AS terms
|
357 |
+
INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
|
358 |
+
WHERE term_taxonomy.taxonomy = '" . $taxonomy . "'
|
359 |
+
");
|
360 |
+
if ($result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max)
|
361 |
+
continue;
|
362 |
+
|
363 |
+
$results = $wpdb->get_results("
|
364 |
+
SELECT terms.term_id
|
365 |
+
FROM $wpdb->terms AS terms
|
366 |
+
INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
|
367 |
+
WHERE term_taxonomy.taxonomy = '" . $taxonomy . "'
|
368 |
+
ORDER BY name ASC
|
369 |
+
");
|
370 |
+
foreach ($results as $key => $result) {
|
371 |
+
$wpdb->update($wpdb->terms, array('term_order' => $key + 1), array('term_id' => $result->term_id));
|
372 |
+
}
|
373 |
+
}
|
374 |
+
}
|
375 |
+
|
376 |
+
wp_redirect('admin.php?page=scporder-settings&msg=update');
|
377 |
+
}
|
378 |
+
|
379 |
+
public function scporder_previous_post_where($where) {
|
380 |
+
global $post;
|
381 |
+
|
382 |
+
$objects = $this->get_scporder_options_objects();
|
383 |
+
if (empty($objects))
|
384 |
+
return $where;
|
385 |
+
|
386 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
387 |
+
$where = preg_replace("/p.post_date < \'[0-9\-\s\:]+\'/i", "p.menu_order > '" . $post->menu_order . "'", $where);
|
388 |
+
}
|
389 |
+
return $where;
|
390 |
+
}
|
391 |
+
|
392 |
+
public function scporder_previous_post_sort($orderby) {
|
393 |
+
global $post;
|
394 |
+
|
395 |
+
$objects = $this->get_scporder_options_objects();
|
396 |
+
if (empty($objects))
|
397 |
+
return $orderby;
|
398 |
+
|
399 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
400 |
+
$orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
|
401 |
+
}
|
402 |
+
return $orderby;
|
403 |
+
}
|
404 |
+
|
405 |
+
public function scporder_next_post_where($where) {
|
406 |
+
global $post;
|
407 |
+
|
408 |
+
$objects = $this->get_scporder_options_objects();
|
409 |
+
if (empty($objects))
|
410 |
+
return $where;
|
411 |
+
|
412 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
413 |
+
$where = preg_replace("/p.post_date > \'[0-9\-\s\:]+\'/i", "p.menu_order < '" . $post->menu_order . "'", $where);
|
414 |
+
}
|
415 |
+
return $where;
|
416 |
+
}
|
417 |
+
|
418 |
+
public function scporder_next_post_sort($orderby) {
|
419 |
+
global $post;
|
420 |
+
|
421 |
+
$objects = $this->get_scporder_options_objects();
|
422 |
+
if (empty($objects))
|
423 |
+
return $orderby;
|
424 |
+
|
425 |
+
if (isset($post->post_type) && in_array($post->post_type, $objects)) {
|
426 |
+
$orderby = 'ORDER BY p.menu_order DESC LIMIT 1';
|
427 |
+
}
|
428 |
+
return $orderby;
|
429 |
+
}
|
430 |
+
|
431 |
+
public function scporder_pre_get_posts($wp_query) {
|
432 |
+
$objects = $this->get_scporder_options_objects();
|
433 |
+
if (empty($objects))
|
434 |
+
return false;
|
435 |
+
if (is_admin()) {
|
436 |
+
|
437 |
+
if (isset($wp_query->query['post_type']) && !isset($_GET['orderby'])) {
|
438 |
+
if (in_array($wp_query->query['post_type'], $objects)) {
|
439 |
+
$wp_query->set('orderby', 'menu_order');
|
440 |
+
$wp_query->set('order', 'ASC');
|
441 |
+
}
|
442 |
+
}
|
443 |
+
} else {
|
444 |
+
|
445 |
+
$active = false;
|
446 |
+
|
447 |
+
if (isset($wp_query->query['post_type'])) {
|
448 |
+
if (!is_array($wp_query->query['post_type'])) {
|
449 |
+
if (in_array($wp_query->query['post_type'], $objects)) {
|
450 |
+
$active = true;
|
451 |
+
}
|
452 |
+
}
|
453 |
+
} else {
|
454 |
+
if (in_array('post', $objects)) {
|
455 |
+
$active = true;
|
456 |
+
}
|
457 |
+
}
|
458 |
+
|
459 |
+
if (!$active)
|
460 |
+
return false;
|
461 |
+
|
462 |
+
if (isset($wp_query->query['suppress_filters'])) {
|
463 |
+
if ($wp_query->get('orderby') == 'date')
|
464 |
+
$wp_query->set('orderby', 'menu_order');
|
465 |
+
if ($wp_query->get('order') == 'DESC')
|
466 |
+
$wp_query->set('order', 'ASC');
|
467 |
+
} else {
|
468 |
+
if (!$wp_query->get('orderby'))
|
469 |
+
$wp_query->set('orderby', 'menu_order');
|
470 |
+
if (!$wp_query->get('order'))
|
471 |
+
$wp_query->set('order', 'ASC');
|
472 |
+
}
|
473 |
+
}
|
474 |
+
}
|
475 |
+
|
476 |
+
public function scporder_get_terms_orderby($orderby, $args) {
|
477 |
+
if (is_admin())
|
478 |
+
return $orderby;
|
479 |
+
|
480 |
+
$tags = $this->get_scporder_options_tags();
|
481 |
+
|
482 |
+
if (!isset($args['taxonomy']))
|
483 |
+
return $orderby;
|
484 |
+
|
485 |
+
$taxonomy = $args['taxonomy'];
|
486 |
+
if (!in_array($taxonomy, $tags))
|
487 |
+
return $orderby;
|
488 |
+
|
489 |
+
$orderby = 't.term_order';
|
490 |
+
return $orderby;
|
491 |
+
}
|
492 |
+
|
493 |
+
public function scporder_get_object_terms($terms) {
|
494 |
+
$tags = $this->get_scporder_options_tags();
|
495 |
+
|
496 |
+
if (is_admin() && isset($_GET['orderby']))
|
497 |
+
return $terms;
|
498 |
+
|
499 |
+
foreach ($terms as $key => $term) {
|
500 |
+
if (is_object($term) && isset($term->taxonomy)) {
|
501 |
+
$taxonomy = $term->taxonomy;
|
502 |
+
if (!in_array($taxonomy, $tags))
|
503 |
+
return $terms;
|
504 |
+
} else {
|
505 |
+
return $terms;
|
506 |
+
}
|
507 |
+
}
|
508 |
+
|
509 |
+
usort($terms, array($this, 'taxcmp'));
|
510 |
+
return $terms;
|
511 |
+
}
|
512 |
+
|
513 |
+
public function taxcmp($a, $b) {
|
514 |
+
if ($a->term_order == $b->term_order)
|
515 |
+
return 0;
|
516 |
+
return ( $a->term_order < $b->term_order ) ? -1 : 1;
|
517 |
+
}
|
518 |
+
|
519 |
+
public function get_scporder_options_objects() {
|
520 |
+
$scporder_options = get_option('scporder_options') ? get_option('scporder_options') : array();
|
521 |
+
$objects = isset($scporder_options['objects']) && is_array($scporder_options['objects']) ? $scporder_options['objects'] : array();
|
522 |
+
return $objects;
|
523 |
+
}
|
524 |
+
|
525 |
+
public function get_scporder_options_tags() {
|
526 |
+
$scporder_options = get_option('scporder_options') ? get_option('scporder_options') : array();
|
527 |
+
$tags = isset($scporder_options['tags']) && is_array($scporder_options['tags']) ? $scporder_options['tags'] : array();
|
528 |
+
return $tags;
|
529 |
+
}
|
530 |
+
|
531 |
+
}
|
532 |
+
|
533 |
+
/**
|
534 |
+
* SCP Order Uninstall hook
|
535 |
+
*/
|
536 |
+
register_uninstall_hook(__FILE__, 'scporder_uninstall');
|
537 |
+
|
538 |
+
function scporder_uninstall() {
|
539 |
+
global $wpdb;
|
540 |
+
if (function_exists('is_multisite') && is_multisite()) {
|
541 |
+
$curr_blog = $wpdb->blogid;
|
542 |
+
$blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
|
543 |
+
foreach ($blogids as $blog_id) {
|
544 |
+
switch_to_blog($blog_id);
|
545 |
+
scporder_uninstall_db();
|
546 |
+
}
|
547 |
+
switch_to_blog($curr_blog);
|
548 |
+
} else {
|
549 |
+
scporder_uninstall_db();
|
550 |
+
}
|
551 |
+
}
|
552 |
+
|
553 |
+
function scporder_uninstall_db() {
|
554 |
+
global $wpdb;
|
555 |
+
$result = $wpdb->query("DESCRIBE $wpdb->terms `term_order`");
|
556 |
+
if ($result) {
|
557 |
+
$query = "ALTER TABLE $wpdb->terms DROP `term_order`";
|
558 |
+
$result = $wpdb->query($query);
|
559 |
+
}
|
560 |
+
delete_option('scporder_install');
|
561 |
+
}
|
562 |
+
|
563 |
?>
|