Simple Custom Post Order - Version 2.3.3

Version Description

Download this release

Release Info

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

Code changes from version 2.2 to 2.3.3

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