Simple Custom Post Order - Version 2.3.6

Version Description

Download this release

Release Info

Developer machothemes
Plugin Icon wp plugin Simple Custom Post Order
Version 2.3.6
Comparing to
See all releases

Code changes from version 2.3.5 to 2.3.6

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