Simple Custom Post Order - Version 2.3.4

Version Description

Download this release

Release Info

Developer colorlibplugins
Plugin Icon wp plugin Simple Custom Post Order
Version 2.3.4
Comparing to
See all releases

Code changes from version 2.2 to 2.3.4

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