Intuitive Custom Post Order - Version 3.0.3

Version Description

  • Performance improvement for Activation.
  • Add Initialize of Custom Taxonomy Order.
  • Fixed bug of refresh method.
  • Overwirting orderby, order improved.(Thanks @newash and @anriettec)
Download this release

Release Info

Developer hijiri
Plugin Icon 128x128 Intuitive Custom Post Order
Version 3.0.3
Comparing to
See all releases

Code changes from version 2.1.0 to 3.0.3

admin/settings.php CHANGED
@@ -1,7 +1,8 @@
1
  <?php
2
 
3
- $hicpo_options = get_option('hicpo_options');
4
- $objects = $hicpo_options['objects'];
 
5
 
6
  ?>
7
 
@@ -9,12 +10,12 @@ $objects = $hicpo_options['objects'];
9
 
10
  <?php screen_icon( 'plugins' ); ?>
11
 
12
- <h2><?php _e('Intuitive Custom Post Order Settings', 'hicpo'); ?></h2>
13
 
14
  <?php if ( isset($_GET['msg'] )) : ?>
15
  <div id="message" class="updated below-h2">
16
- <?php if ( $_GET['msg'] == 'update') : ?>
17
- <p><?php _e('Settings saved.', 'hicpo'); ?></p>
18
  <?php endif; ?>
19
  </div>
20
  <?php endif; ?>
@@ -28,19 +29,19 @@ $objects = $hicpo_options['objects'];
28
  <table class="form-table">
29
  <tbody>
30
  <tr valign="top">
31
- <th scope="row"><?php _e('Sortable Objects', 'hicpo') ?></th>
32
  <td>
33
  <?php
34
  $post_types = get_post_types( array (
35
- 'public' => true
 
36
  ), 'objects' );
37
 
38
- foreach ($post_types as $post_type ) {
39
- if ( $post_type->name != 'attachment' ) {
40
  ?>
41
- <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 />
42
  <?php
43
- }
44
  }
45
  ?>
46
  </td>
@@ -50,29 +51,58 @@ $objects = $hicpo_options['objects'];
50
 
51
  </div>
52
 
53
- <label><input type="checkbox" id="hicpo_allcheck"> <?php _e('All Check', 'hicpo') ?></label>
54
 
55
- <script>
56
- (function($){
57
 
58
- $("#hicpo_allcheck").on('click', function(){
59
-
60
- var items = $("#hicpo_select_objects input");
61
-
62
- if ( $(this).is(':checked') ) {
63
- $(items).prop('checked', true);
64
- } else {
65
- $(items).prop('checked', false);
66
- }
67
- });
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- })(jQuery)
70
- </script>
 
71
 
72
  <p class="submit">
73
- <input type="submit" class="button-primary" name="hicpo_submit" value="<?php _e('Update', 'cptg'); ?>" />
74
  </p>
75
 
76
  </form>
77
 
78
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ $hicpo_options = get_option( 'hicpo_options' );
4
+ $hicpo_objects = isset( $hicpo_options['objects'] ) ? $hicpo_options['objects'] : array();
5
+ $hicpo_tags = isset( $hicpo_options['tags'] ) ? $hicpo_options['tags'] : array();
6
 
7
  ?>
8
 
10
 
11
  <?php screen_icon( 'plugins' ); ?>
12
 
13
+ <h2><?php _e( 'Intuitive Custom Post Order Settings', 'hicpo' ); ?></h2>
14
 
15
  <?php if ( isset($_GET['msg'] )) : ?>
16
  <div id="message" class="updated below-h2">
17
+ <?php if ( $_GET['msg'] == 'update' ) : ?>
18
+ <p><?php _e( 'Settings saved.' ); ?></p>
19
  <?php endif; ?>
20
  </div>
21
  <?php endif; ?>
29
  <table class="form-table">
30
  <tbody>
31
  <tr valign="top">
32
+ <th scope="row"><?php _e( 'Sortable Post Types', 'hicpo' ) ?></th>
33
  <td>
34
  <?php
35
  $post_types = get_post_types( array (
36
+ 'show_ui' => true,
37
+ 'show_in_menu' => true,
38
  ), 'objects' );
39
 
40
+ foreach ( $post_types as $post_type ) {
41
+ if ( $post_type->name == 'attachment' ) continue;
42
  ?>
43
+ <label><input type="checkbox" name="objects[]" value="<?php echo $post_type->name; ?>" <?php if ( isset( $hicpo_objects ) && is_array( $hicpo_objects ) ) { if ( in_array( $post_type->name, $hicpo_objects ) ) { echo 'checked="checked"'; } } ?>>&nbsp;<?php echo $post_type->label; ?></label><br>
44
  <?php
 
45
  }
46
  ?>
47
  </td>
51
 
52
  </div>
53
 
54
+ <label><input type="checkbox" id="hicpo_allcheck_objects"> <?php _e( 'All Check', 'hicpo' ) ?></label>
55
 
56
+ <div id="hicpo_select_tags">
 
57
 
58
+ <table class="form-table">
59
+ <tbody>
60
+ <tr valign="top">
61
+ <th scope="row"><?php _e( 'Sortable Taxonomies', 'hicpo' ) ?></th>
62
+ <td>
63
+ <?php
64
+ $taxonomies = get_taxonomies( array(
65
+ 'show_ui' => true,
66
+ ), 'objects' );
67
+
68
+ foreach( $taxonomies as $taxonomy ) {
69
+ if ( $taxonomy->name == 'post_format' ) continue;
70
+ ?>
71
+ <label><input type="checkbox" name="tags[]" value="<?php echo $taxonomy->name; ?>" <?php if ( isset( $hicpo_tags ) && is_array( $hicpo_tags ) ) { if ( in_array( $taxonomy->name, $hicpo_tags ) ) { echo 'checked="checked"'; } } ?>>&nbsp;<?php echo $taxonomy->label ?></label><br>
72
+ <?php
73
+ }
74
+ ?>
75
+ </td>
76
+ </tr>
77
+ </tbody>
78
+ </table>
79
 
80
+ </div>
81
+
82
+ <label><input type="checkbox" id="hicpo_allcheck_tags"> <?php _e( 'All Check', 'hicpo' ) ?></label>
83
 
84
  <p class="submit">
85
+ <input type="submit" class="button-primary" name="hicpo_submit" value="<?php _e( 'Update', 'cptg' ); ?>">
86
  </p>
87
 
88
  </form>
89
 
90
+ </div>
91
+
92
+ <script>
93
+ (function($){
94
+
95
+ $("#hicpo_allcheck_objects").on('click', function(){
96
+ var items = $("#hicpo_select_objects input");
97
+ if ( $(this).is(':checked') ) $(items).prop('checked', true);
98
+ else $(items).prop('checked', false);
99
+ });
100
+
101
+ $("#hicpo_allcheck_tags").on('click', function(){
102
+ var items = $("#hicpo_select_tags input");
103
+ if ( $(this).is(':checked') ) $(items).prop('checked', true);
104
+ else $(items).prop('checked', false);
105
+ });
106
+
107
+ })(jQuery)
108
+ </script>
intuitive-custom-post-order.php CHANGED
@@ -2,45 +2,56 @@
2
  /*
3
  Plugin Name: Intuitive Custom Post Order
4
  Plugin URI: http://hijiriworld.com/web/plugins/intuitive-custom-post-order/
5
- Description: Intuitively, Order Items (Posts, Pages, and Custom Post Types) using a Drag and Drop Sortable JavaScript.
6
- Version: 2.1.0
7
  Author: hijiri
8
  Author URI: http://hijiriworld.com/web/
 
 
9
  */
10
 
11
- /* Copyright 2014 hijiri
12
-
13
- This program is free software; you can redistribute it and/or modify
14
- it under the terms of the GNU General Public License, version 2, as
15
- published by the Free Software Foundation.
16
-
17
- This program is distributed in the hope that it will be useful,
18
- but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- GNU General Public License for more details.
21
-
22
- You should have received a copy of the GNU General Public License
23
- along with this program; if not, write to the Free Software
24
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
- /***********************************************************************************
28
-
29
- Define
30
-
31
- ***********************************************************************************/
32
-
33
- define( 'HICPO_URL', plugins_url('', __FILE__) );
34
 
35
- define( 'HICPO_DIR', plugin_dir_path(__FILE__) );
36
-
37
- load_plugin_textdomain( 'hicpo', false, basename(dirname(__FILE__)).'/lang' );
38
-
39
- /***********************************************************************************
40
 
41
- Class & Method
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
- ***********************************************************************************/
 
 
44
 
45
  $hicpo = new Hicpo();
46
 
@@ -48,70 +59,48 @@ class Hicpo
48
  {
49
  function __construct()
50
  {
51
-
52
- if ( !get_option('hicpo_options') ) $this->hicpo_install();
 
53
 
54
- add_action( 'admin_menu', array( &$this, 'admin_menu') );
55
 
56
- add_action( 'admin_init', array( &$this, 'refresh' ) );
57
- add_action( 'admin_init', array( &$this, 'update_options') );
58
- add_action( 'admin_init', array( &$this, 'load_script_css' ) );
59
 
60
- add_action( 'wp_ajax_update-menu-order', array( &$this, 'update_menu_order' ) );
 
 
61
 
62
- // pre_get_posts
63
- add_filter( 'pre_get_posts', array( &$this, 'hicpo_filter_active' ) );
64
- add_filter( 'pre_get_posts', array( &$this, 'hicpo_pre_get_posts' ) );
65
 
66
- // previous_post(s)_link, next_post(s)_link
67
- add_filter( 'get_previous_post_where', array( &$this, 'hicpo_previous_post_where' ) );
68
- add_filter( 'get_previous_post_sort', array( &$this, 'hicpo_previous_post_sort' ) );
69
- add_filter( 'get_next_post_where', array( &$this, 'hocpo_next_post_where' ) );
70
- add_filter( 'get_next_post_sort', array( &$this, 'hicpo_next_post_sort' ) );
71
 
72
- // for dev
73
- //add_action( 'pre_get_posts', array( &$this, 'hicpo_dev' ) );
 
 
74
  }
75
 
76
- function hicpo_install()
77
  {
78
  global $wpdb;
79
-
80
- // Initialize : hicpo_options
81
-
82
- $post_types = get_post_types( array (
83
- 'public' => true
84
- ), 'objects' );
85
-
86
- $init_objects = array();
87
-
88
- foreach ($post_types as $post_type ) {
89
- if ( $post_type->name != 'attachment' ) {
90
- $init_objects[] = $post_type->name;
91
- }
92
- }
93
- $input_options = array( 'objects' => $init_objects );
94
-
95
- update_option( 'hicpo_options', $input_options );
96
-
97
- // Initialize : menu_order
98
-
99
- $hicpo_options = get_option( 'hicpo_options' );
100
- $objects = $hicpo_options['objects'];
101
-
102
- if ( !empty( $objects ) ) {
103
- foreach( $objects as $object) {
104
- $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" );
105
- foreach( $results as $key => $result ) {
106
- $wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
107
- }
108
- }
109
  }
 
110
  }
111
-
112
  function admin_menu()
113
  {
114
- add_options_page( __('Intuitive CPO', 'hicpo'), __('Intuitive CPO', 'hicpo'), 'manage_options', 'hicpo-settings', array( &$this,'admin_page' ));
115
  }
116
 
117
  function admin_page()
@@ -119,74 +108,108 @@ class Hicpo
119
  require HICPO_DIR.'admin/settings.php';
120
  }
121
 
122
- function _check_load_script_css() {
123
-
124
  $active = false;
125
 
126
- $hicpo_options = get_option( 'hicpo_options' );
127
- $objects = $hicpo_options['objects'];
128
 
129
- if ( is_array( $objects ) ) {
130
- // exlude addnew Page and edit Page
131
- if ( !strstr( $_SERVER["REQUEST_URI"], 'action=edit' ) && !strstr( $_SERVER["REQUEST_URI"], 'wp-admin/post-new.php' ) ) {
132
-
133
- // if Custom Post Types( include 'Page')
134
- if ( isset( $_GET['post_type'] ) ) {
135
- if ( in_array( $_GET['post_type'], $objects ) ) {
136
- $active = true;
137
- }
138
- // if Post
139
- } else if ( strstr( $_SERVER["REQUEST_URI"], 'wp-admin/edit.php' ) ) {
140
- if ( in_array( 'post', $objects ) ) {
141
- $active = true;
142
- }
143
- }
144
  }
145
  }
 
 
 
 
 
 
 
 
146
  return $active;
147
  }
148
 
149
- function load_script_css() {
150
-
151
  if ( $this->_check_load_script_css() ) {
152
 
153
  // load JavaScript
154
-
155
  wp_enqueue_script( 'jquery' );
156
  wp_enqueue_script( 'jquery-ui-sortable' );
157
  wp_enqueue_script( 'hicpojs', HICPO_URL.'/js/hicpo.js', array( 'jquery' ), null, true );
158
-
159
  // load CSS
160
-
161
  wp_enqueue_style( 'hicpo', HICPO_URL.'/css/hicpo.css', array(), null );
162
  }
163
  }
164
 
165
  function refresh()
166
  {
167
- // menu_orderを再構築する
168
  global $wpdb;
169
 
170
- $hicpo_options = get_option( 'hicpo_options' );
171
- $objects = $hicpo_options['objects'];
172
 
173
- if ( is_array( $objects ) ) {
174
  foreach( $objects as $object) {
 
 
 
 
 
175
 
176
- /*
177
- menu_order max とレコード数が一致して、かつ min 0 じゃない時は再構築処理をスキップする
178
  */
 
 
179
 
180
- $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')" );
181
- if ( count( $result ) > 0 && $result[0]->cnt == $result[0]->max && $result[0]->min != 0 ) {
182
- continue;
 
 
 
 
 
 
183
  }
 
 
 
 
 
 
 
 
 
 
 
184
 
185
- $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" );
 
186
 
 
 
 
 
 
 
 
187
  foreach( $results as $key => $result ) {
188
- // 新規追加した場合 menu_order=0 で登録されるため、常に1からはじまるように振っておく
189
- $wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
190
  }
191
  }
192
  }
@@ -195,35 +218,65 @@ class Hicpo
195
  function update_menu_order()
196
  {
197
  global $wpdb;
 
 
198
 
199
- parse_str($_POST['order'], $data);
200
-
201
- if ( is_array($data) ) {
202
 
203
- // ページに含まれる記事のIDをすべて取得
204
- $id_arr = array();
205
-
206
- foreach( $data as $key => $values ) {
207
- foreach( $values as $position => $id ) {
208
- $id_arr[] = $id;
209
- }
210
  }
211
-
212
- // ページに含まれる記事の menu_order をすべて取得
213
- $menu_order_arr = array();
214
- foreach( $id_arr as $key => $id ) {
215
- $results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = ".$id );
216
- foreach( $results as $result ) {
217
- $menu_order_arr[] = $result->menu_order;
218
- }
219
  }
220
- // menu_order 配列をソート(キーと値の相関関係は維持しない)
221
- sort($menu_order_arr);
222
-
223
- foreach( $data as $key => $values ) {
224
- foreach( $values as $position => $id ) {
225
- $wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => $id ) );
226
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  }
228
  }
229
  }
@@ -236,27 +289,39 @@ class Hicpo
236
 
237
  check_admin_referer( 'nonce_hicpo' );
238
 
239
- if ( isset( $_POST['objects'] ) ) {
240
- $input_options = array( 'objects' => $_POST['objects'] );
241
- } else {
242
- $input_options = array( 'objects' => '' );
243
- }
244
 
245
  update_option( 'hicpo_options', $input_options );
246
 
247
- /*
248
- はじめて有効化されたオブジェクトの場合、ディフォルト状態 order=post_date に従って menu_order を振っておく
 
 
 
249
  */
250
 
251
- $hicpo_options = get_option( 'hicpo_options' );
252
- $objects = $hicpo_options['objects'];
253
 
254
  if ( !empty( $objects ) ) {
255
- foreach( $objects as $object) {
256
- // 記事が1つ以上存在し、menu_oredr の最大値が 0 のオブジェクトが該当
257
- $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')" );
 
 
 
 
 
 
258
  if ( count( $result ) > 0 && $result[0]->max == 0 ) {
259
- $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" );
 
 
 
 
 
260
  foreach( $results as $key => $result ) {
261
  $wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
262
  }
@@ -264,6 +329,29 @@ class Hicpo
264
  }
265
  }
266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  wp_redirect( 'admin.php?page=hicpo-settings&msg=update' );
268
  }
269
  }
@@ -272,10 +360,10 @@ class Hicpo
272
  {
273
  global $post;
274
 
275
- $hicpo_options = get_option('hicpo_options');
276
- $objects = $hicpo_options['objects'];
277
 
278
- if ( in_array( $post->post_type, $objects ) ) {
279
  $current_menu_order = $post->menu_order;
280
  $where = "WHERE p.menu_order > '".$current_menu_order."' AND p.post_type = '". $post->post_type ."' AND p.post_status = 'publish'";
281
  }
@@ -285,11 +373,11 @@ class Hicpo
285
  function hicpo_previous_post_sort( $orderby )
286
  {
287
  global $post;
288
-
289
- $hicpo_options = get_option('hicpo_options');
290
- $objects = $hicpo_options['objects'];
291
 
292
- if ( in_array( $post->post_type, $objects ) ) {
 
 
 
293
  $orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
294
  }
295
  return $orderby;
@@ -299,10 +387,10 @@ class Hicpo
299
  {
300
  global $post;
301
 
302
- $hicpo_options = get_option('hicpo_options');
303
- $objects = $hicpo_options['objects'];
304
 
305
- if ( in_array( $post->post_type, $objects ) ) {
306
  $current_menu_order = $post->menu_order;
307
  $where = "WHERE p.menu_order < '".$current_menu_order."' AND p.post_type = '". $post->post_type ."' AND p.post_status = 'publish'";
308
  }
@@ -313,10 +401,10 @@ class Hicpo
313
  {
314
  global $post;
315
 
316
- $hicpo_options = get_option('hicpo_options');
317
- $objects = $hicpo_options['objects'];
318
-
319
- if ( in_array( $post->post_type, $objects ) ) {
320
  $orderby = 'ORDER BY p.menu_order DESC LIMIT 1';
321
  }
322
  return $orderby;
@@ -334,124 +422,141 @@ class Hicpo
334
  {
335
  global $args;
336
 
337
- $hicpo_options = get_option('hicpo_options');
338
- $objects = $hicpo_options['objects'];
339
 
340
- if ( is_array( $objects ) ) {
341
 
342
- // for Admin >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
 
 
 
343
 
344
- if ( is_admin() && !defined( 'DOING_AJAX' ) ) {
345
-
346
- /*
347
- post_type=post or page or custom post type
348
- adminの場合、post_type=postも渡される
349
- */
350
-
351
- if ( isset( $wp_query->query['post_type'] ) ) {
352
- if ( in_array( $wp_query->query['post_type'], $objects ) ) {
353
- $wp_query->set( 'orderby', 'menu_order' );
354
- $wp_query->set( 'order', 'ASC' );
355
- }
356
  }
 
 
 
 
 
 
 
357
 
358
- // for Template >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
 
 
359
 
360
- } else {
361
-
362
- /*
363
-
364
- post_type が有効オブジェクトかどうかを判別
365
-
366
- $wp_query->query['post_type'] で判別
367
- ディフォルトのクエリの場合、$args指定がないため
368
 
369
- */
370
-
371
- $active = false;
372
-
373
- // post_typeが指定されている場合
374
-
375
- if ( isset( $wp_query->query['post_type'] ) ) {
376
- // 複数指定の場合は、いずれかひとつでも該当すれば有効
377
- if ( is_array( $wp_query->query['post_type'] ) ) {
378
- $post_types = $wp_query->query['post_type'];
379
- foreach( $post_types as $post_type ) {
380
- if ( in_array( $post_type, $objects ) ) {
381
- $active = true;
382
- }
383
- }
384
- } else {
385
- if ( in_array( $wp_query->query['post_type'], $objects ) ) {
386
  $active = true;
387
  }
388
  }
389
- // post_typeが指定されていなければpost
390
  } else {
391
- if ( in_array( 'post', $objects ) ) {
392
  $active = true;
393
  }
394
  }
395
-
396
- /*
397
-
398
- $args が存在した場合はそちらを優先する
399
-
400
- */
401
-
402
- if ( $active ) {
403
-
404
- if ( isset( $args ) ) {
405
- // args = array( 'orderby' => 'date', 'order' => 'DESC' );
406
- if ( is_array( $args ) ) {
407
- if ( !isset( $args['orderby'] ) ) {
408
- $wp_query->set( 'orderby', 'menu_order' );
409
- }
410
- if ( !isset( $args['order'] ) ) {
411
- $wp_query->set( 'order', 'ASC' );
412
- }
413
- // args = 'orderby=date&order=DESC';
414
- } else {
415
- if ( !strstr( $args, 'orderby=' ) ) {
416
- $wp_query->set( 'orderby', 'menu_order' );
417
- }
418
- if ( !strstr( $args, 'order=' ) ) {
419
- $wp_query->set( 'order', 'ASC' );
420
-
421
- }
422
- }
423
- } else {
424
- $wp_query->set( 'orderby', 'menu_order' );
425
- $wp_query->set( 'order', 'ASC' );
426
- }
427
  }
428
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  }
430
  }
431
 
432
- // for dev
433
- /*
434
- function hicpo_dev( $query ) {
435
 
436
- global $args;
 
 
437
 
438
- echo '[$args]';
439
- echo isset( $args ) ? ' isset ' : ' non-object ';
440
- echo '/';
441
- echo is_array( $args ) ? ' array ' : ' no-array ';
442
- echo '<br>';
443
- print_r($args);
444
- echo '<br>';
445
-
446
- echo '[$query->query]';
447
- echo isset( $query->query ) ? ' isset ' : ' non-object ';
448
- echo '/';
449
- echo is_array( $query->query ) ? ' array ' : ' no-array ';
450
- echo '<br>';
451
- print_r($query->query);
452
- echo '<br>';
453
 
 
 
454
  }
455
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456
  }
 
457
  ?>
2
  /*
3
  Plugin Name: Intuitive Custom Post Order
4
  Plugin URI: http://hijiriworld.com/web/plugins/intuitive-custom-post-order/
5
+ Description: Intuitively, Order Items (Posts, Pages, and Custom Post Types and Custom Taxonomies) using a Drag and Drop Sortable JavaScript.
6
+ Version: 3.0.3
7
  Author: hijiri
8
  Author URI: http://hijiriworld.com/web/
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  */
12
 
13
+ /**
14
+ * Define
 
 
 
 
 
 
 
 
 
 
 
 
15
  */
16
 
17
+ define( 'HICPO_URL', plugins_url( '', __FILE__ ) );
18
+ define( 'HICPO_DIR', plugin_dir_path( __FILE__ ) );
19
+ load_plugin_textdomain( 'hicpo', false, basename( dirname( __FILE__ ) ).'/lang' );
 
 
 
 
20
 
21
+ /**
22
+ * Uninstall hook
23
+ */
 
 
24
 
25
+ register_uninstall_hook( __FILE__, 'hicpo_uninstall' );
26
+ function hicpo_uninstall()
27
+ {
28
+ global $wpdb;
29
+ if ( function_exists( 'is_multisite' ) && is_multisite() ) {
30
+ $curr_blog = $wpdb->blogid;
31
+ $blogids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
32
+ foreach( $blogids as $blog_id ) {
33
+ switch_to_blog( $blog_id );
34
+ hicpo_uninstall_db();
35
+ }
36
+ switch_to_blog( $curr_blog );
37
+ } else {
38
+ hicpo_uninstall_db();
39
+ }
40
+ }
41
+ function hicpo_uninstall_db()
42
+ {
43
+ global $wpdb;
44
+ $result = $wpdb->query( "DESCRIBE $wpdb->terms `term_order`" );
45
+ if ( $result ){
46
+ $query = "ALTER TABLE $wpdb->terms DROP `term_order`";
47
+ $result = $wpdb->query( $query );
48
+ }
49
+ delete_option( 'hicpo_activation' );
50
+ }
51
 
52
+ /**
53
+ * Class & Method
54
+ */
55
 
56
  $hicpo = new Hicpo();
57
 
59
  {
60
  function __construct()
61
  {
62
+ if ( !get_option( 'hicpo_activation' ) ) $this->hicpo_activation();
63
+
64
+ add_action( 'admin_menu', array( $this, 'admin_menu') );
65
 
66
+ add_action( 'admin_init', array( $this, 'refresh' ) );
67
 
68
+ add_action( 'admin_init', array( $this, 'update_options') );
69
+ add_action( 'admin_init', array( $this, 'load_script_css' ) );
 
70
 
71
+ // sortable ajax action
72
+ add_action( 'wp_ajax_update-menu-order', array( $this, 'update_menu_order' ) );
73
+ add_action( 'wp_ajax_update-menu-order-tags', array( $this, 'update_menu_order_tags' ) );
74
 
75
+ // reorder post types
76
+ add_filter( 'pre_get_posts', array( $this, 'hicpo_filter_active' ) );
77
+ add_filter( 'pre_get_posts', array( $this, 'hicpo_pre_get_posts' ) );
78
 
79
+ add_filter( 'get_previous_post_where', array( $this, 'hicpo_previous_post_where' ) );
80
+ add_filter( 'get_previous_post_sort', array( $this, 'hicpo_previous_post_sort' ) );
81
+ add_filter( 'get_next_post_where', array( $this, 'hocpo_next_post_where' ) );
82
+ add_filter( 'get_next_post_sort', array( $this, 'hicpo_next_post_sort' ) );
 
83
 
84
+ // reorder taxonomies
85
+ add_filter( 'get_terms_orderby', array( $this, 'hicpo_get_terms_orderby' ), 10, 3 );
86
+ add_filter( 'wp_get_object_terms', array( $this, 'hicpo_get_object_terms' ), 10, 3 );
87
+ add_filter( 'get_terms', array( $this, 'hicpo_get_object_terms' ), 10, 3 );
88
  }
89
 
90
+ function hicpo_activation()
91
  {
92
  global $wpdb;
93
+ $result = $wpdb->query( "DESCRIBE $wpdb->terms `term_order`" );
94
+ if ( !$result ) {
95
+ $query = "ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'";
96
+ $result = $wpdb->query( $query );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
+ update_option( 'hicpo_activation', 1 );
99
  }
100
+
101
  function admin_menu()
102
  {
103
+ add_options_page( __( 'Intuitive CPO', 'hicpo' ), __( 'Intuitive CPO', 'hicpo' ), 'manage_options', 'hicpo-settings', array( $this,'admin_page' ));
104
  }
105
 
106
  function admin_page()
108
  require HICPO_DIR.'admin/settings.php';
109
  }
110
 
111
+ function _check_load_script_css()
112
+ {
113
  $active = false;
114
 
115
+ $objects = $this->get_hicpo_options_objects();
116
+ $tags = $this->get_hicpo_options_tags();
117
 
118
+ if ( empty( $objects ) && empty( $tags ) ) return false;
119
+
120
+ // exclude (sorting, addnew page, edit page)
121
+ if ( isset( $_GET['orderby'] ) || strstr( $_SERVER["REQUEST_URI"], 'action=edit' ) || strstr( $_SERVER["REQUEST_URI"], 'wp-admin/post-new.php' ) ) return false;
122
+
123
+ // check post_type
124
+ if ( !empty( $objects ) ) {
125
+ // if page or custom post types
126
+ if ( isset( $_GET['post_type'] ) && in_array( $_GET['post_type'], $objects ) ) {
127
+ $active = true;
128
+ // if post
129
+ } else if ( strstr( $_SERVER["REQUEST_URI"], 'wp-admin/edit.php' ) && in_array( 'post', $objects ) ) {
130
+ $active = true;
 
 
131
  }
132
  }
133
+
134
+ // check taxonomy
135
+ if ( !empty( $tags ) ) {
136
+ if ( isset( $_GET['taxonomy'] ) && in_array( $_GET['taxonomy'], $tags ) ) {
137
+ $active = true;
138
+ }
139
+ }
140
+
141
  return $active;
142
  }
143
 
144
+ function load_script_css()
145
+ {
146
  if ( $this->_check_load_script_css() ) {
147
 
148
  // load JavaScript
 
149
  wp_enqueue_script( 'jquery' );
150
  wp_enqueue_script( 'jquery-ui-sortable' );
151
  wp_enqueue_script( 'hicpojs', HICPO_URL.'/js/hicpo.js', array( 'jquery' ), null, true );
152
+
153
  // load CSS
 
154
  wp_enqueue_style( 'hicpo', HICPO_URL.'/css/hicpo.css', array(), null );
155
  }
156
  }
157
 
158
  function refresh()
159
  {
 
160
  global $wpdb;
161
 
162
+ $objects = $this->get_hicpo_options_objects();
163
+ $tags = $this->get_hicpo_options_tags();
164
 
165
+ if ( !empty( $objects ) ) {
166
  foreach( $objects as $object) {
167
+ $result = $wpdb->get_results( "
168
+ SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
169
+ FROM $wpdb->posts
170
+ WHERE post_type = '".$object."' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
171
+ " );
172
 
173
+ /**
174
+ * アイテム数が 0、もしくはアイテム数とmaxが同じでminが0以外の場合は、再構築処理をスキップ
175
  */
176
+ if ( $result[0]->cnt == 0 ) continue;
177
+ if ( count( $result ) > 0 && $result[0]->cnt == $result[0]->max && $result[0]->min != 0 ) continue;
178
 
179
+ $results = $wpdb->get_results( "
180
+ SELECT ID
181
+ FROM $wpdb->posts
182
+ WHERE post_type = '".$object."' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
183
+ ORDER BY menu_order ASC
184
+ " );
185
+ // 新規追加した場合 menu_order=0 で登録されるため、常に1からはじまるように振っておく
186
+ foreach( $results as $key => $result ) {
187
+ $wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
188
  }
189
+ }
190
+ }
191
+
192
+ if ( !empty( $tags ) ) {
193
+ foreach( $tags as $taxonomy ) {
194
+ $result = $wpdb->get_results( "
195
+ SELECT count(*) as cnt, max(term_order) as max, min(term_order) as min
196
+ FROM $wpdb->terms AS terms
197
+ INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
198
+ WHERE term_taxonomy.taxonomy = '".$taxonomy."'
199
+ " );
200
 
201
+ if ( $result[0]->cnt == 0 ) continue;
202
+ if ( count( $result ) > 0 && $result[0]->max == $result[0]->cnt && $result[0]->min != 0 ) continue;
203
 
204
+ $results = $wpdb->get_results( "
205
+ SELECT terms.term_id
206
+ FROM $wpdb->terms AS terms
207
+ INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
208
+ WHERE term_taxonomy.taxonomy = '".$taxonomy."'
209
+ ORDER BY name ASC
210
+ " );
211
  foreach( $results as $key => $result ) {
212
+ $wpdb->update( $wpdb->terms, array( 'term_order' => $key+1 ), array( 'term_id' => $result->term_id ) );
 
213
  }
214
  }
215
  }
218
  function update_menu_order()
219
  {
220
  global $wpdb;
221
+
222
+ parse_str( $_POST['order'], $data );
223
 
224
+ if ( !is_array( $data ) ) return false;
 
 
225
 
226
+ // get objects per now page
227
+ $id_arr = array();
228
+ foreach( $data as $key => $values ) {
229
+ foreach( $values as $position => $id ) {
230
+ $id_arr[] = $id;
 
 
231
  }
232
+ }
233
+
234
+ // get menu_order of objects per now page
235
+ $menu_order_arr = array();
236
+ foreach( $id_arr as $key => $id ) {
237
+ $results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = ".intval( $id ) );
238
+ foreach( $results as $result ) {
239
+ $menu_order_arr[] = $result->menu_order;
240
  }
241
+ }
242
+
243
+ // maintains key association = no
244
+ sort( $menu_order_arr );
245
+
246
+ foreach( $data as $key => $values ) {
247
+ foreach( $values as $position => $id ) {
248
+ $wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => intval( $id ) ) );
249
+ }
250
+ }
251
+ }
252
+
253
+ function update_menu_order_tags()
254
+ {
255
+ global $wpdb;
256
+
257
+ parse_str( $_POST['order'], $data );
258
+
259
+ if ( !is_array( $data ) ) return false;
260
+
261
+ $id_arr = array();
262
+ foreach( $data as $key => $values ) {
263
+ foreach( $values as $position => $id ) {
264
+ $id_arr[] = $id;
265
+ }
266
+ }
267
+
268
+ $menu_order_arr = array();
269
+ foreach( $id_arr as $key => $id ) {
270
+ $results = $wpdb->get_results( "SELECT term_order FROM $wpdb->terms WHERE term_id = ".intval( $id ) );
271
+ foreach( $results as $result ) {
272
+ $menu_order_arr[] = $result->term_order;
273
+ }
274
+ }
275
+ sort( $menu_order_arr );
276
+
277
+ foreach( $data as $key => $values ) {
278
+ foreach( $values as $position => $id ) {
279
+ $wpdb->update( $wpdb->terms, array( 'term_order' => $menu_order_arr[$position] ), array( 'term_id' => intval( $id ) ) );
280
  }
281
  }
282
  }
289
 
290
  check_admin_referer( 'nonce_hicpo' );
291
 
292
+ $input_options = array();
293
+ $input_options['objects'] = isset( $_POST['objects'] ) ? $_POST['objects'] : '';
294
+ $input_options['tags'] = isset( $_POST['tags'] ) ? $_POST['tags'] : '';
 
 
295
 
296
  update_option( 'hicpo_options', $input_options );
297
 
298
+ /**
299
+ * はじめて有効化されたオブジェクトの場合、ディフォルトの order に従って order 値をセットしておく。
300
+ *
301
+ * post type: orderby=date, order=desc
302
+ * taxonomy: orderby=name, order=asc
303
  */
304
 
305
+ $objects = $this->get_hicpo_options_objects();
306
+ $tags = $this->get_hicpo_options_tags();
307
 
308
  if ( !empty( $objects ) ) {
309
+ foreach( $objects as $object ) {
310
+ /**
311
+ * アイテム数が 0 以上で order 値がセットされていないオブジェクトが対象
312
+ */
313
+ $result = $wpdb->get_results( "
314
+ SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
315
+ FROM $wpdb->posts
316
+ WHERE post_type = '".$object."' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
317
+ " );
318
  if ( count( $result ) > 0 && $result[0]->max == 0 ) {
319
+ $results = $wpdb->get_results( "
320
+ SELECT ID
321
+ FROM $wpdb->posts
322
+ WHERE post_type = '".$object."' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
323
+ ORDER BY post_date DESC
324
+ " );
325
  foreach( $results as $key => $result ) {
326
  $wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
327
  }
329
  }
330
  }
331
 
332
+ if ( !empty( $tags ) ) {
333
+ foreach( $tags as $taxonomy ) {
334
+ $result = $wpdb->get_results( "
335
+ SELECT count(*) as cnt, max(term_order) as max, min(term_order) as min
336
+ FROM $wpdb->terms AS terms
337
+ INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
338
+ WHERE term_taxonomy.taxonomy = '".$taxonomy."'
339
+ " );
340
+ if ( count( $result ) > 0 && $result[0]->max == 0 ) {
341
+ $results = $wpdb->get_results( "
342
+ SELECT terms.term_id
343
+ FROM $wpdb->terms AS terms
344
+ INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
345
+ WHERE term_taxonomy.taxonomy = '".$taxonomy."'
346
+ ORDER BY name ASC
347
+ " );
348
+ foreach( $results as $key => $result ) {
349
+ $wpdb->update( $wpdb->terms, array( 'term_order' => $key+1 ), array( 'term_id' => $result->term_id ) );
350
+ }
351
+ }
352
+ }
353
+ }
354
+
355
  wp_redirect( 'admin.php?page=hicpo-settings&msg=update' );
356
  }
357
  }
360
  {
361
  global $post;
362
 
363
+ $objects = $this->get_hicpo_options_objects();
364
+ if ( empty( $objects ) ) return $where;
365
 
366
+ if ( isset( $post->post_type ) && in_array( $post->post_type, $objects ) ) {
367
  $current_menu_order = $post->menu_order;
368
  $where = "WHERE p.menu_order > '".$current_menu_order."' AND p.post_type = '". $post->post_type ."' AND p.post_status = 'publish'";
369
  }
373
  function hicpo_previous_post_sort( $orderby )
374
  {
375
  global $post;
 
 
 
376
 
377
+ $objects = $this->get_hicpo_options_objects();
378
+ if ( empty( $objects ) ) return $orderby;
379
+
380
+ if ( isset( $post->post_type ) && in_array( $post->post_type, $objects ) ) {
381
  $orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
382
  }
383
  return $orderby;
387
  {
388
  global $post;
389
 
390
+ $objects = $this->get_hicpo_options_objects();
391
+ if ( empty( $objects ) ) return $where;
392
 
393
+ if ( isset( $post->post_type ) && in_array( $post->post_type, $objects ) ) {
394
  $current_menu_order = $post->menu_order;
395
  $where = "WHERE p.menu_order < '".$current_menu_order."' AND p.post_type = '". $post->post_type ."' AND p.post_status = 'publish'";
396
  }
401
  {
402
  global $post;
403
 
404
+ $objects = $this->get_hicpo_options_objects();
405
+ if ( empty( $objects ) ) return $orderby;
406
+
407
+ if ( isset( $post->post_type ) && in_array( $post->post_type, $objects ) ) {
408
  $orderby = 'ORDER BY p.menu_order DESC LIMIT 1';
409
  }
410
  return $orderby;
422
  {
423
  global $args;
424
 
425
+ $objects = $this->get_hicpo_options_objects();
 
426
 
427
+ if ( !is_array( $objects ) ) return false;
428
 
429
+ /**
430
+ * for Admin
431
+ */
432
+
433
+ if ( is_admin() && !defined( 'DOING_AJAX' ) ) {
434
 
435
+ /**
436
+ * adminの場合 post_type=post も渡される
437
+ * ゆえに $_GET['post_type] での判定はダメ
438
+ */
439
+
440
+ if ( isset( $wp_query->query['post_type'] ) && !isset( $_GET['orderby'] ) ) {
441
+ if ( in_array( $wp_query->query['post_type'], $objects ) ) {
442
+ $wp_query->set( 'orderby', 'menu_order' );
443
+ $wp_query->set( 'order', 'ASC' );
 
 
 
444
  }
445
+ }
446
+
447
+ /**
448
+ * for Front
449
+ */
450
+
451
+ } else {
452
 
453
+ /**
454
+ * $wp_query->query['post_type'] でオブジェクト判別
455
+ * ディフォルトのクエリの場合 $args が渡ってこないので可能
456
+ */
457
 
458
+ $active = false;
 
 
 
 
 
 
 
459
 
460
+ // post_typeが指定されている場合
461
+
462
+ if ( isset( $wp_query->query['post_type'] ) ) {
463
+ // 複数指定の場合は、いずれかひとつでも該当すれば有効とする
464
+ if ( is_array( $wp_query->query['post_type'] ) ) {
465
+ $post_types = $wp_query->query['post_type'];
466
+ foreach( $post_types as $post_type ) {
467
+ if ( in_array( $post_type, $objects ) ) {
 
 
 
 
 
 
 
 
 
468
  $active = true;
469
  }
470
  }
 
471
  } else {
472
+ if ( in_array( $wp_query->query['post_type'], $objects ) ) {
473
  $active = true;
474
  }
475
  }
476
+ // post_typeが指定されていなければ post_type=post
477
+
478
+ } else {
479
+ if ( in_array( 'post', $objects ) ) {
480
+ $active = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  }
482
  }
483
+
484
+ /**
485
+ * $args が存在した場合はそちらを優先する
486
+ */
487
+
488
+ if ( !$active ) return false;
489
+
490
+ if ( isset( $args ) ) {
491
+ // args = Array
492
+ if ( is_array( $args ) ) {
493
+ if ( !isset( $args['orderby'] ) ) $wp_query->set( 'orderby', 'menu_order' );
494
+ if ( !isset( $args['order'] ) ) $wp_query->set( 'order', 'ASC' );
495
+ // args = String
496
+ } else {
497
+ if ( !strstr( $args, 'orderby=' ) ) $wp_query->set( 'orderby', 'menu_order' );
498
+ if ( !strstr( $args, 'order=' ) ) $wp_query->set( 'order', 'ASC' );
499
+ }
500
+ } else {
501
+ if ( !$wp_query->get( 'orderby' ) ) $wp_query->set( 'orderby', 'menu_order' );
502
+ if ( !$wp_query->get( 'order' ) && $wp_query->get( 'orderby' ) == 'menu_order') $wp_query->set( 'order', 'ASC' );;
503
+ }
504
  }
505
  }
506
 
507
+ function hicpo_get_terms_orderby( $orderby, $args )
508
+ {
509
+ if ( is_admin() ) return $orderby;
510
 
511
+ $tags = $this->get_hicpo_options_tags();
512
+
513
+ if( !isset( $args['taxonomy'] ) ) return $orderby;
514
 
515
+ $taxonomy = $args['taxonomy'];
516
+ if ( !in_array( $taxonomy, $tags ) ) return $orderby;
 
 
 
 
 
 
 
 
 
 
 
 
 
517
 
518
+ $orderby = 't.term_order';
519
+ return $orderby;
520
  }
521
+
522
+ function hicpo_get_object_terms( $terms )
523
+ {
524
+ $tags = $this->get_hicpo_options_tags();
525
+
526
+ if ( is_admin() && isset( $_GET['orderby'] ) ) return $terms;
527
+
528
+ foreach( $terms as $key => $term ) {
529
+ if ( is_object( $term ) && isset( $term->taxonomy ) ) {
530
+ $taxonomy = $term->taxonomy;
531
+ if ( !in_array( $taxonomy, $tags ) ) return $terms;
532
+ } else {
533
+ return $terms;
534
+ }
535
+ }
536
+
537
+ usort( $terms, array( $this, 'taxcmp' ) );
538
+ return $terms;
539
+ }
540
+
541
+ function taxcmp( $a, $b )
542
+ {
543
+ if ( $a->term_order == $b->term_order ) return 0;
544
+ return ( $a->term_order < $b->term_order ) ? -1 : 1;
545
+ }
546
+
547
+ function get_hicpo_options_objects()
548
+ {
549
+ $hicpo_options = get_option( 'hicpo_options' ) ? get_option( 'hicpo_options' ) : array();
550
+ $objects = isset( $hicpo_options['objects'] ) && is_array( $hicpo_options['objects'] ) ? $hicpo_options['objects'] : array();
551
+ return $objects;
552
+ }
553
+ function get_hicpo_options_tags()
554
+ {
555
+ $hicpo_options = get_option( 'hicpo_options' ) ? get_option( 'hicpo_options' ) : array();
556
+ $tags = isset( $hicpo_options['tags'] ) && is_array( $hicpo_options['tags'] ) ? $hicpo_options['tags'] : array();
557
+ return $tags;
558
+ }
559
+
560
  }
561
+
562
  ?>
js/hicpo.js CHANGED
@@ -1,17 +1,35 @@
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
  //$("#the-list").disableSelection();
14
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  var fixHelper = function(e, ui) {
16
  ui.children().children().each(function() {
17
  $(this).width($(this).width());
1
  (function($){
2
+
3
+ // posts
4
+
5
+ $('table.posts #the-list, table.pages #the-list').sortable({
6
  'items': 'tr',
7
  'axis': 'y',
8
  'helper': fixHelper,
9
  'update' : function(e, ui) {
10
  $.post( ajaxurl, {
11
  action: 'update-menu-order',
12
+ order: $('#the-list').sortable('serialize'),
13
  });
14
  }
15
  });
16
  //$("#the-list").disableSelection();
17
+
18
+ // tags
19
+
20
+ $('table.tags #the-list').sortable({
21
+ 'items': 'tr',
22
+ 'axis': 'y',
23
+ 'helper': fixHelper,
24
+ 'update' : function(e, ui) {
25
+ $.post( ajaxurl, {
26
+ action: 'update-menu-order-tags',
27
+ order: $('#the-list').sortable('serialize'),
28
+ });
29
+ }
30
+ });
31
+ //$("#the-list").disableSelection();
32
+
33
  var fixHelper = function(e, ui) {
34
  ui.children().children().each(function() {
35
  $(this).width($(this).width());
lang/default.pot CHANGED
@@ -1,15 +1,17 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: \n"
4
- "POT-Creation-Date: 2013-03-05 01:46+0900\n"
5
- "PO-Revision-Date: 2013-03-05 01:47+0900\n"
6
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
7
- "Language-Team: LANGUAGE <LL@li.org>\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
 
 
11
 
12
- #: intuitive-custom-post-order/intuitive-custom-post-order.php:107
13
  msgid "Intuitive CPO"
14
  msgstr ""
15
 
@@ -21,10 +23,22 @@ msgstr ""
21
  msgid "Settings saved."
22
  msgstr ""
23
 
24
- #: intuitive-custom-post-order/admin/settings.php:29
25
- msgid "Sortable Objects"
26
  msgstr ""
27
 
28
- #: intuitive-custom-post-order/admin/settings.php:50
 
 
 
 
 
 
 
 
 
 
 
 
29
  msgid "Update"
30
  msgstr ""
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: \n"
4
+ "POT-Creation-Date: 2015-01-26 21:02+0900\n"
5
+ "PO-Revision-Date: 2015-01-26 21:02+0900\n"
6
+ "Last-Translator: hijiri <hijiriworld@gmail.com>\n"
7
+ "Language-Team: \n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
+ "X-Generator: Poedit 1.5.7\n"
12
+ "X-Poedit-KeywordsList: __;_e\n"
13
 
14
+ #: intuitive-custom-post-order/intuitive-custom-post-order.php:140
15
  msgid "Intuitive CPO"
16
  msgstr ""
17
 
23
  msgid "Settings saved."
24
  msgstr ""
25
 
26
+ #: intuitive-custom-post-order/admin/settings.php:31
27
+ msgid "Sortable Post Types"
28
  msgstr ""
29
 
30
+ #: intuitive-custom-post-order/admin/settings.php:53
31
+ msgid "All Check"
32
+ msgstr ""
33
+
34
+ #: intuitive-custom-post-order/admin/settings.php:60
35
+ msgid "Sortable Taxonomies"
36
+ msgstr ""
37
+
38
+ #: intuitive-custom-post-order/admin/settings.php:62
39
+ msgid "Custom Taxonomies Order becomes always effective."
40
+ msgstr ""
41
+
42
+ #: intuitive-custom-post-order/admin/settings.php:71
43
  msgid "Update"
44
  msgstr ""
lang/hicpo-ja.mo ADDED
Binary file
lang/hicpo-ja.po ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "POT-Creation-Date: 2015-01-26 21:02+0900\n"
5
+ "PO-Revision-Date: 2015-01-26 21:05+0900\n"
6
+ "Last-Translator: hijiri <hijiriworld@gmail.com>\n"
7
+ "Language-Team: \n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "X-Generator: Poedit 1.5.7\n"
12
+ "X-Poedit-KeywordsList: __;_e\n"
13
+
14
+ #: intuitive-custom-post-order/intuitive-custom-post-order.php:140
15
+ msgid "Intuitive CPO"
16
+ msgstr "並び替え設定"
17
+
18
+ #: intuitive-custom-post-order/admin/settings.php:12
19
+ msgid "Intuitive Custom Post Order Settings"
20
+ msgstr "並び替え設定"
21
+
22
+ #: intuitive-custom-post-order/admin/settings.php:17
23
+ msgid "Settings saved."
24
+ msgstr ""
25
+
26
+ #: intuitive-custom-post-order/admin/settings.php:31
27
+ msgid "Sortable Post Types"
28
+ msgstr "並び替える投稿タイプ"
29
+
30
+ #: intuitive-custom-post-order/admin/settings.php:53
31
+ msgid "All Check"
32
+ msgstr "すべて選択"
33
+
34
+ #: intuitive-custom-post-order/admin/settings.php:60
35
+ msgid "Sortable Taxonomies"
36
+ msgstr "並び替えるカスタム分類"
37
+
38
+ #: intuitive-custom-post-order/admin/settings.php:62
39
+ msgid "Custom Taxonomies Order becomes always effective."
40
+ msgstr "カスタム分類は常に並び替えが有効になります。"
41
+
42
+ #: intuitive-custom-post-order/admin/settings.php:71
43
+ msgid "Update"
44
+ msgstr ""
readme.txt CHANGED
@@ -1,34 +1,56 @@
1
  === Intuitive Custom Post Order ===
2
  Contributors: hijiri
3
- Tags: post order, posts order, order post, order posts, custom post type order
4
  Requires at least: 3.5.0
5
- Tested up to: 3.8.1
6
- Stable tag: 2.1.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
- Intuitively, Order Items (Posts, Pages, and Custom Post Types) using a Drag and Drop Sortable JavaScript.
11
 
12
  == Description ==
13
 
14
- Intuitively, Order Items (Posts, Pages, and Custom Post Types) using a Drag and Drop Sortable JavaScript.
15
  Configuration is unnecessary.
16
  You can do directly on default WordPress administration.
17
 
18
- Custom Query which uses 'order' or 'orderby' parameters is preferred. ( 'WP_Query()', 'get_posts()', 'query_posts()' )
19
 
20
  == Installation ==
21
 
22
- 1. Upload 'intuitive-custom-post-order' folder to the `/wp-content/plugins/` directory
23
- 2. Activate the plugin through the 'Plugins' menu in WordPress
24
- 3. (Optional) Select Sortable Objects from Intuitive CPT Menu
25
 
26
  == Screenshots ==
27
 
28
- 1. Order items
 
 
29
 
30
  == Changelog ==
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  = 2.1.0 =
33
 
34
  * Fixed bug: Custom Query which uses 'order' or 'orderby' parameters is preferred.
@@ -107,4 +129,10 @@ Custom Query which uses 'order' or 'orderby' parameters is preferred. ( 'WP_Quer
107
 
108
  = 1.0.0 =
109
 
110
- Initial Release
 
 
 
 
 
 
1
  === Intuitive Custom Post Order ===
2
  Contributors: hijiri
3
+ Tags: post order, posts order, order post, order posts, custom post type order, custom taxonomy order
4
  Requires at least: 3.5.0
5
+ Tested up to: 4.1.0
6
+ Stable tag: 3.0.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
+ Intuitively, Order Items (Posts, Pages, and Custom Post Types, and Custom Taxonomies) using a Drag and Drop Sortable JavaScript.
11
 
12
  == Description ==
13
 
14
+ Intuitively, Order Items (Posts, Pages, and Custom Post Types, and Custom Taxonomies) using a Drag and Drop Sortable JavaScript.
15
  Configuration is unnecessary.
16
  You can do directly on default WordPress administration.
17
 
18
+ Your Query which uses 'order' or 'orderby' parameters is preferred. ( 'WP_Query()', 'get_posts()', 'query_posts()' )
19
 
20
  == Installation ==
21
 
22
+ 1. Upload 'intuitive-custom-post-order' folder to the `/wp-content/plugins/` directory.
23
+ 2. Activate the plugin through the 'Plugins' menu in WordPress.
24
+ 3. Select Sortable Objects from Intuitive CPT Menu.
25
 
26
  == Screenshots ==
27
 
28
+ 1. Reorder post
29
+ 2. Reorder taxonomy
30
+ 3. Settings
31
 
32
  == Changelog ==
33
 
34
+ = 3.0.3 =
35
+
36
+ * Performance improvement for Activation.
37
+ * Add Initialize of Custom Taxonomy Order.
38
+ * Fixed bug of refresh method.
39
+ * Overwirting orderby, order improved.(Thanks @newash and @anriettec)
40
+
41
+ = 3.0.1 & 3.0.2 =
42
+
43
+ * Fixed bug
44
+
45
+ = 3.0.0 =
46
+
47
+ * Support the Custom Taxonomy Order!!
48
+ ( wp_list_categories, get_categories, the_terms, the_tags, get_terms, get_the_terms, get_the_term_list, the_category, wp_dropdown_categories, the_taxonomies )
49
+ * Suuport the sorting in admin UI.
50
+ While having sorted, Drag and Drop Sortable Javascript don't run.
51
+ * Support non public objects( show_ui=true, show_in_menu=true )
52
+ * Add Japanese Translations.
53
+
54
  = 2.1.0 =
55
 
56
  * Fixed bug: Custom Query which uses 'order' or 'orderby' parameters is preferred.
129
 
130
  = 1.0.0 =
131
 
132
+ Initial Release
133
+
134
+ == Upgrade Notice ==
135
+
136
+ = 3.0.3 =
137
+
138
+ Expand Database Table: wp_terms.
screenshot-1.png DELETED
Binary file