Intuitive Custom Post Order - Version 2.0.4

Version Description

  • Bug fixed
Download this release

Release Info

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

Version 2.0.4

admin/settings.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $hicpo_options = get_option('hicpo_options');
4
+ $objects = $hicpo_options['objects'];
5
+
6
+ ?>
7
+
8
+ <div class="wrap">
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; ?>
21
+
22
+ <form method="post">
23
+
24
+ <?php if ( function_exists( 'wp_nonce_field' ) ) wp_nonce_field( 'nonce_hicpo' ); ?>
25
+
26
+ <table class="form-table">
27
+ <tbody>
28
+ <tr valign="top">
29
+ <th scope="row"><label for="blogname"><?php _e('Sortable Objects', 'hicpo') ?></label></th>
30
+ <td>
31
+ <?php
32
+ $post_types = get_post_types( array (
33
+ 'public' => true
34
+ ), 'objects' );
35
+
36
+ foreach ($post_types as $post_type ) {
37
+ if ( $post_type->name != 'attachment' ) {
38
+ ?>
39
+ <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 />
40
+ <?php
41
+ }
42
+ }
43
+ ?>
44
+ </td>
45
+ </tr>
46
+ </tbody>
47
+ </table>
48
+
49
+ <p class="submit">
50
+ <input type="submit" class="button-primary" name="hicpo_submit" value="<?php _e('Update', 'cptg'); ?>" />
51
+ </p>
52
+
53
+ </form>
54
+
55
+ </div>
css/hicpo.css ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ .ui-sortable tr:hover {
2
+ cursor: move;
3
+ }
4
+ .ui-sortable tr.alternate {
5
+ background-color: #F9F9F9;
6
+ }
7
+ .ui-sortable tr.ui-sortable-helper {
8
+ background-color: #F9F9F9;
9
+ border-top: 1px solid #DFDFDF;
10
+ }
intuitive-custom-post-order.php ADDED
@@ -0,0 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
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.0.4
7
+ Author: hijiri
8
+ Author URI: http://hijiriworld.com/web/
9
+ */
10
+
11
+ /* Copyright 2013 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
+
47
+ class Hicpo
48
+ {
49
+ function __construct()
50
+ {
51
+ if ( !get_option('hicpo_options') ) $this->hicpo_install();
52
+
53
+ add_action( 'admin_menu', array( &$this, 'admin_menu') );
54
+
55
+ add_action( 'admin_init', array( &$this, 'refresh' ) );
56
+ add_action( 'admin_init', array( &$this, 'update_options') );
57
+ add_action( 'init', array( &$this, 'enable_objects' ) );
58
+
59
+ add_action( 'wp_ajax_update-menu-order', array( &$this, 'update_menu_order' ) );
60
+ }
61
+
62
+ function hicpo_install()
63
+ {
64
+ global $wpdb;
65
+
66
+ // Initialize : hicpo_options
67
+
68
+ $post_types = get_post_types( array (
69
+ 'public' => true
70
+ ), 'objects' );
71
+
72
+ foreach ($post_types as $post_type ) {
73
+ $init_objects[] = $post_type->name;
74
+ }
75
+ $input_options = array( 'objects' => $init_objects );
76
+
77
+ update_option( 'hicpo_options', $input_options );
78
+
79
+
80
+ // Initialize : menu_order from date_post
81
+
82
+ $hicpo_options = get_option( 'hicpo_options' );
83
+ $objects = $hicpo_options['objects'];
84
+
85
+ foreach( $objects as $object) {
86
+ $sql = "SELECT
87
+ ID
88
+ FROM
89
+ $wpdb->posts
90
+ WHERE
91
+ post_type = '".$object."'
92
+ AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
93
+ ORDER BY
94
+ post_date DESC
95
+ ";
96
+
97
+ $results = $wpdb->get_results($sql);
98
+
99
+ foreach( $results as $key => $result ) {
100
+ $wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
101
+ }
102
+ }
103
+ }
104
+
105
+ function admin_menu()
106
+ {
107
+ add_options_page( __('Intuitive CPO', 'hicpo'), __('Intuitive CPO', 'hicpo'), 'manage_options', 'hicpo-settings', array( &$this,'admin_page' ));
108
+ }
109
+
110
+ function admin_page()
111
+ {
112
+ require HICPO_DIR.'admin/settings.php';
113
+ }
114
+
115
+ function enable_objects()
116
+ {
117
+ $hicpo_options = get_option( 'hicpo_options' );
118
+ $objects = $hicpo_options['objects'];
119
+
120
+ if ( is_array( $objects ) ) {
121
+ $active = false;
122
+
123
+ // for Pages or Custom Post Types
124
+ if ( isset($_GET['post_type']) ) {
125
+ if ( in_array( $_GET['post_type'], $objects ) ) {
126
+ $active = true;
127
+ }
128
+ // for Posts
129
+ } else {
130
+ $post_list = strstr( $_SERVER["REQUEST_URI"], 'wp-admin/edit.php' );
131
+ if ( $post_list && in_array( 'post', $objects ) ) {
132
+ $active = true;
133
+ }
134
+ }
135
+
136
+ if ( $active ) {
137
+ $this->load_script_css();
138
+ }
139
+ }
140
+ }
141
+
142
+ function load_script_css() {
143
+ // load JavaScript
144
+ wp_enqueue_script( 'jQuery' );
145
+ wp_enqueue_script( 'jquery-ui-sortable' );
146
+ wp_enqueue_script( 'hicpojs', HICPO_URL.'/js/hicpo.js', array( 'jquery' ), null, true );
147
+ // load CSS
148
+ wp_enqueue_style( 'hicpo', HICPO_URL.'/css/hicpo.css', array(), null );
149
+ }
150
+
151
+ function refresh()
152
+ {
153
+ // menu_orderを再構築する
154
+ global $wpdb;
155
+
156
+ $hicpo_options = get_option( 'hicpo_options' );
157
+ $objects = $hicpo_options['objects'];
158
+
159
+ if ( is_array( $objects ) ) {
160
+ foreach( $objects as $object) {
161
+ $sql = "SELECT
162
+ ID
163
+ FROM
164
+ $wpdb->posts
165
+ WHERE
166
+ post_type = '".$object."'
167
+ AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
168
+ ORDER BY
169
+ menu_order ASC
170
+ ";
171
+
172
+ $results = $wpdb->get_results($sql);
173
+
174
+ foreach( $results as $key => $result ) {
175
+ // 新規追加した場合「menu_order=0」で登録されるため、常に1からはじまるように振っておく
176
+ $wpdb->update( $wpdb->posts, array( 'menu_order' => $key+1 ), array( 'ID' => $result->ID ) );
177
+ }
178
+ }
179
+ }
180
+ }
181
+
182
+ function update_menu_order()
183
+ {
184
+ global $wpdb;
185
+
186
+ parse_str($_POST['order'], $data);
187
+
188
+ if ( is_array($data) ) {
189
+
190
+ // ページに含まれる記事のIDをすべて取得
191
+ $id_arr = array();
192
+ foreach( $data as $key => $values ) {
193
+ foreach( $values as $position => $id ) {
194
+ $id_arr[] = $id;
195
+ }
196
+ }
197
+
198
+ // ページに含まれる記事のmenu_orderをすべて取得
199
+ $menu_order_arr = array();
200
+ foreach( $id_arr as $key => $id ) {
201
+ $results = $wpdb->get_results("SELECT menu_order FROM $wpdb->posts WHERE ID = ".$id);
202
+ foreach( $results as $result ) {
203
+ $menu_order_arr[] = $result->menu_order;
204
+ }
205
+ }
206
+ // menu_order配列をソート(キーと値の相関関係は維持しない)
207
+ sort($menu_order_arr);
208
+
209
+ foreach( $data as $key => $values ) {
210
+ foreach( $values as $position => $id ) {
211
+ $wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => $id ) );
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+
218
+
219
+ function update_options()
220
+ {
221
+ if ( isset( $_POST['hicpo_submit'] ) ) {
222
+
223
+ check_admin_referer( 'nonce_hicpo' );
224
+
225
+ if ( isset( $_POST['objects'] ) ) {
226
+ $input_options = array( 'objects' => $_POST['objects'] );
227
+ } else {
228
+ $input_options = array( 'objects' => '' );
229
+ }
230
+
231
+ update_option( 'hicpo_options', $input_options );
232
+ wp_redirect( 'admin.php?page=hicpo-settings&msg=update' );
233
+ }
234
+ }
235
+ }
236
+
237
+ /***************************************************************
238
+
239
+ output filter hook
240
+
241
+ ***************************************************************/
242
+
243
+ add_filter( 'pre_get_posts', 'hicpo_filter_active' );
244
+
245
+ function hicpo_filter_active( $wp_query )
246
+ {
247
+ // get_postsの場合 suppress_filters=true となる為、フィルタリングを有効にする
248
+ if ( isset($wp_query->query['suppress_filters']) ) $wp_query->query['suppress_filters'] = false;
249
+ if ( isset($wp_query->query_vars['suppress_filters']) ) $wp_query->query_vars['suppress_filters'] = false;
250
+ return $wp_query;
251
+ }
252
+
253
+ add_filter( 'pre_get_posts', 'hicpo_pre_get_posts' );
254
+
255
+ function hicpo_pre_get_posts( $wp_query )
256
+ {
257
+ $hicpo_options = get_option('hicpo_options');
258
+ $objects = $hicpo_options['objects'];
259
+
260
+ if ( is_array( $objects ) ) {
261
+
262
+ // for Admin ---------------------------------------------------------------
263
+
264
+ if ( is_admin() && !defined( 'DOING_AJAX' ) ) {
265
+
266
+ // post_type=post or page or custom post type
267
+ // adminの場合、post_tyope=postも渡される
268
+ if ( isset( $wp_query->query['post_type'] ) ) {
269
+ if ( in_array( $wp_query->query['post_type'], $objects ) ) {
270
+ $wp_query->set( 'orderby', 'menu_order' );
271
+ $wp_query->set( 'order', 'ASC' );
272
+ }
273
+ }
274
+
275
+ // for Template ------------------------------------------------------------
276
+
277
+ } else {
278
+
279
+ $active = false;
280
+
281
+ // postsのWordpressループ ----------------
282
+
283
+ // $wp_query->queryが空配列の場合
284
+ // WordPressループでもposts以外はpost_typeが渡される
285
+
286
+ if ( empty( $wp_query->query ) ) {
287
+ if ( in_array( 'post', $objects ) ) {
288
+ $active = true;
289
+ }
290
+ } else {
291
+
292
+ // get_posts() ----------------------
293
+
294
+ // 完全な判別ではないが、suppress_filtersパラメータの有無で判別
295
+ // get_posts()の場合、post_type, orderby, orderパラメータは必ず渡される
296
+
297
+ if ( isset($wp_query->query['suppress_filters']) ) {
298
+
299
+ // post_type判定
300
+ if ( is_array( $wp_query->query['post_type'] ) ) {
301
+ $post_types = $wp_query->query['post_type'];
302
+ foreach( $post_types as $post_type ) {
303
+ if ( in_array( $post_type, $objects ) ) {
304
+ $active = true;
305
+ }
306
+ }
307
+ } else {
308
+ if ( in_array( $wp_query->query['post_type'], $objects ) ) {
309
+ $active = true;
310
+ }
311
+ }
312
+
313
+ // query_posts() or WP_Query()
314
+ } else {
315
+
316
+ // post_typeが指定されている場合
317
+ if ( isset( $wp_query->query['post_type'] ) ) {
318
+
319
+ // post_type判定
320
+ if ( is_array( $wp_query->query['post_type'] ) ) {
321
+ $post_types = $wp_query->query['post_type'];
322
+ foreach( $post_types as $post_type ) {
323
+ if ( in_array( $post_type, $objects ) ) {
324
+ $active = true;
325
+ }
326
+ }
327
+ } else {
328
+ if ( in_array( $wp_query->query['post_type'], $objects ) ) {
329
+ $active = true;
330
+ }
331
+ }
332
+ // post_typeが指定されてい場合はpost_type=post
333
+ } else {
334
+ if ( in_array( 'post', $objects ) ) {
335
+ $active = true;
336
+ }
337
+ }
338
+ }
339
+ }
340
+
341
+ if ( $active ) {
342
+ if ( !isset( $wp_query->query['orderby'] ) || $wp_query->query['orderby'] == 'post_date' ) $wp_query->set( 'orderby', 'menu_order' );
343
+ if ( !isset( $wp_query->query['order'] ) || $wp_query->query['order'] == 'DESC' ) $wp_query->set( 'order', 'ASC' );
344
+ }
345
+ }
346
+ }
347
+ }
348
+ ?>
js/hicpo.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function() {
2
+ jQuery("#the-list").sortable({
3
+ 'items': 'tr',
4
+ 'axis': 'y',
5
+ 'helper': fixHelper,
6
+ 'update' : function(e, ui) {
7
+ jQuery.post( ajaxurl, {
8
+ action: 'update-menu-order',
9
+ order: jQuery("#the-list").sortable("serialize"),
10
+ });
11
+ }
12
+ });
13
+ //jQuery("#the-list").disableSelection();
14
+ });
15
+
16
+ var fixHelper = function(e, ui) {
17
+ ui.children().children().each(function() {
18
+ jQuery(this).width(jQuery(this).width());
19
+ });
20
+ return ui;
21
+ };
lang/default.pot ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
16
+ #: intuitive-custom-post-order/admin/settings.php:12
17
+ msgid "Intuitive Custom Post Order Settings"
18
+ msgstr ""
19
+
20
+ #: intuitive-custom-post-order/admin/settings.php:17
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 ""
readme.txt ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.0.0
5
+ Tested up to: 3.5.1
6
+ Stable tag: 2.0.4
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
+ Excluding Custom Query which uses 'order' or 'orderby' parameters, in query_posts()', 'WP_Query()', and 'get_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.0.4 =
33
+
34
+ * Bug fixed
35
+
36
+ = 2.0.3 =
37
+
38
+ * Intuitive CPO Settings Page was moved to Settings menu.
39
+
40
+ = 2.0.2 =
41
+
42
+ * Bug fixed
43
+
44
+ = 2.0.0 =
45
+
46
+ * Select Sortable Objects. (Posts, Pages, and Custom Post Types)
47
+ * Support Pages and hierarchical Custom Post Types.
48
+ * Sortable Item's status is not only 'publish' but also other all status('pending', 'draft', 'private', 'future').
49
+ * In Paging, it's all activated normaly. So, 'screen-per-page' is User like.
50
+ * In Lists which sorted any category(Category, Tag, Taxonomy), it's all activated normaly.
51
+ * Support Child posts and Child pages. When you sort any item, Relation of parent item between it's child items is maintained.
52
+
53
+ = 1.2.1 =
54
+
55
+ * Bug fixed
56
+
57
+ = 1.2.0 =
58
+
59
+ * Sortable UI that Visually cleared. (Change cursor, and so on.)
60
+ * Sortable items can be dragged only vertically.
61
+ * Quick Edit Menu was enabled.
62
+ * It is not collapse of the cell widths any more whenever dragging any items.
63
+
64
+ = 1.1.1 =
65
+
66
+ * Bug fixed
67
+
68
+ = 1.1.0 =
69
+
70
+ * screen-per-page is configurated to '999' automatically to prevent the trouble due to not setting it.
71
+ * Excluding custom query which uses 'order' or 'orderby' parameters, in 'get_posts' or 'query_posts' and so on.
72
+
73
+ = 1.0.0 =
74
+
75
+ Initial Release
screenshot-1.png ADDED
Binary file