Post Types Order - Version 0.9

Version Description

Make sure you get the latest version

Download this release

Release Info

Developer nsp-code
Plugin Icon 128x128 Post Types Order
Version 0.9
Comparing to
See all releases

Version 0.9

Files changed (4) hide show
  1. css/cpt.css +5 -0
  2. post-types-order.php +297 -0
  3. readme.txt +44 -0
  4. screenshot-1.png +0 -0
css/cpt.css ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ #sortable { list-style-type: none; margin: 10px 0 0; padding: 0; width: 100%; }
2
+ #sortable ul { margin-left:20px; list-style: none; }
3
+ #sortable li { margin: 4px 0; padding: 4px 0x; border: 1px solid #DDDDDD; -moz-border-radius:6px; cursor: move}
4
+ #sortable li span { display: block; background: #f7f7f7; padding: 5px; color:#808080; font-size: font-size:14px; font-weight:bold;}
5
+ #sortable li.placeholder{border: dashed 2px #ccc;background-color:#FFF;height:20px;}
post-types-order.php ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Post Types Order
4
+ Plugin URI: http://www.nsp-code.com
5
+ Description: Order Post Types Objects using a Drag and Drop Sortable javascript capability
6
+ Author: NSP CODE
7
+ Author URI: http://www.nsp-code.com
8
+ Version: 0.9
9
+ */
10
+
11
+ define('CPTPATH', ABSPATH.'wp-content/plugins/post-types-order');
12
+ define('CPTURL', get_option('siteurl').'/wp-content/plugins/post-types-order');
13
+
14
+
15
+ add_filter('posts_orderby', 'CPTOrderPosts');
16
+ function CPTOrderPosts($orderBy)
17
+ {
18
+ global $wpdb;
19
+ $orderBy = "{$wpdb->posts}.menu_order ASC";
20
+ return($orderBy);
21
+ }
22
+
23
+ if (is_admin())
24
+ add_action( 'plugins_loaded', 'initCPT' );
25
+
26
+ function initCPT()
27
+ {
28
+ global $custom_post_type_order;
29
+ $custom_post_type_order = new CPT();
30
+ }
31
+
32
+
33
+ class Custom_Type_Order_Walker extends Walker
34
+ {
35
+ /**
36
+ * @see Walker::$tree_type
37
+ * @since 2.1.0
38
+ * @var string
39
+ */
40
+ var $tree_type = 'page';
41
+
42
+ /**
43
+ * @see Walker::$db_fields
44
+ * @since 2.1.0
45
+ * @todo Decouple this.
46
+ * @var array
47
+ */
48
+ var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
49
+
50
+ /**
51
+ * @see Walker::start_lvl()
52
+ * @since 2.1.0
53
+ *
54
+ * @param string $output Passed by reference. Used to append additional content.
55
+ * @param int $depth Depth of page. Used for padding.
56
+ */
57
+ function start_lvl(&$output, $depth) {
58
+ $indent = str_repeat("\t", $depth);
59
+ $output .= "\n$indent<ul class='children'>\n";
60
+ }
61
+
62
+ /**
63
+ * @see Walker::end_lvl()
64
+ * @since 2.1.0
65
+ *
66
+ * @param string $output Passed by reference. Used to append additional content.
67
+ * @param int $depth Depth of page. Used for padding.
68
+ */
69
+ function end_lvl(&$output, $depth) {
70
+ $indent = str_repeat("\t", $depth);
71
+ $output .= "$indent</ul>\n";
72
+ }
73
+
74
+ /**
75
+ * @see Walker::start_el()
76
+ * @since 2.1.0
77
+ *
78
+ * @param string $output Passed by reference. Used to append additional content.
79
+ * @param object $page Page data object.
80
+ * @param int $depth Depth of page. Used for padding.
81
+ * @param int $current_page Page ID.
82
+ * @param array $args
83
+ */
84
+ function start_el(&$output, $page, $depth, $args) {
85
+ if ( $depth )
86
+ $indent = str_repeat("\t", $depth);
87
+ else
88
+ $indent = '';
89
+
90
+ extract($args, EXTR_SKIP);
91
+
92
+ $output .= $indent . '<li id="item_'.$page->ID.'"><span>'.apply_filters( 'the_title', $page->post_title, $page->ID ).'</span>';
93
+ }
94
+
95
+ /**
96
+ * @see Walker::end_el()
97
+ * @since 2.1.0
98
+ *
99
+ * @param string $output Passed by reference. Used to append additional content.
100
+ * @param object $page Page data object. Not used.
101
+ * @param int $depth Depth of page. Not Used.
102
+ */
103
+ function end_el(&$output, $page, $depth) {
104
+ $output .= "</li>\n";
105
+ }
106
+
107
+ }
108
+
109
+
110
+ class CPT
111
+ {
112
+ var $current_post_type = null;
113
+
114
+ function CPT()
115
+ {
116
+ add_action( 'admin_init', array(&$this, 'registerJavaScript'), 11 );
117
+ add_action( 'admin_init', array(&$this, 'checkPost'), 10 );
118
+ add_action( 'admin_menu', array(&$this, 'addMenu') );
119
+
120
+
121
+
122
+ add_action( 'wp_ajax_update-custom-type-order', array(&$this, 'saveAjaxOrder') );
123
+ }
124
+
125
+ function registerJavaScript()
126
+ {
127
+ if ( $this->current_post_type != null )
128
+ {
129
+ wp_enqueue_script('jQuery');
130
+ wp_enqueue_script('jquery-ui-sortable');
131
+
132
+ wp_register_style('CPTStyleSheets', CPTURL . '/css/cpt.css');
133
+ wp_enqueue_style( 'CPTStyleSheets');
134
+
135
+ }
136
+ }
137
+
138
+ function checkPost()
139
+ {
140
+ if ( isset($_GET['page']) && substr($_GET['page'], 0, 16) == 'order-post-type-' )
141
+ {
142
+ $this->current_post_type = get_post_type_object(str_replace( 'order-post-type-', '', $_GET['page'] ));
143
+ if ( $this->current_post_type == null)
144
+ {
145
+ wp_die('Invalid post type');
146
+ }
147
+ }
148
+ }
149
+
150
+ function saveAjaxOrder()
151
+ {
152
+ global $wpdb;
153
+
154
+ parse_str($_POST['order'], $output);
155
+
156
+ if (is_array($output))
157
+ foreach($output as $key => $values )
158
+ {
159
+ if ( $key == 'item' )
160
+ {
161
+ foreach( $values as $position => $id )
162
+ {
163
+ $wpdb->update( $wpdb->posts, array('menu_order' => $position, 'post_parent' => 0), array('ID' => $id) );
164
+ }
165
+ }
166
+ else
167
+ {
168
+ foreach( $values as $position => $id )
169
+ {
170
+ $wpdb->update( $wpdb->posts, array('menu_order' => $position, 'post_parent' => str_replace('item_', '', $key)), array('ID' => $id) );
171
+ }
172
+ }
173
+ }
174
+ }
175
+
176
+
177
+ function addMenu()
178
+ {
179
+ //put a menu for all custom_type
180
+ $post_types = get_post_types();
181
+ foreach( $post_types as $post_type_name )
182
+ {
183
+ add_submenu_page('edit.php?post_type='.$post_type_name, 'Re-Order', 'Re-Order', 'manage_options', 'order-post-type-'.$post_type_name, array(&$this, 'pageManage') );
184
+ }
185
+ }
186
+
187
+
188
+ function pageManage() {
189
+ ?>
190
+ <div class="wrap">
191
+ <h2><?php echo $this->current_post_type->labels->singular_name . ' - Re-order '?></h2>
192
+
193
+ <div id="ajax-response"></div>
194
+
195
+ <noscript>
196
+ <div class="error message">
197
+ <p>This plugin can't work without javascript, because it's use drag and drop and AJAX.</p>
198
+ </div>
199
+ </noscript>
200
+
201
+ <div id="order-post-type">
202
+ <ul id="sortable">
203
+ <?php $this->listPages('hide_empty=0&title_li=&post_type='.$this->current_post_type->name); ?>
204
+ </ul>
205
+
206
+ <div class="clear"></div>
207
+ </div>
208
+
209
+ <p class="submit">
210
+ <a href="#" id="save-order" class="button-primary">Update</a>
211
+ </p>
212
+
213
+ <script type="text/javascript">
214
+ jQuery(document).ready(function() {
215
+ jQuery("#sortable").sortable({
216
+ 'tolerance':'intersect',
217
+ 'cursor':'pointer',
218
+ 'grid': [50, 10],
219
+ 'items':'li',
220
+ 'placeholder':'placeholder',
221
+ 'nested': 'ul'
222
+ });
223
+
224
+ jQuery("#sortable").disableSelection();
225
+ jQuery("#save-order").bind( "click", function() {
226
+ jQuery.post( ajaxurl, { action:'update-custom-type-order', order:jQuery("#sortable").sortable("serialize") }, function() {
227
+ jQuery("#ajax-response").html('<div class="message updated fade"><p>Items Order Updates</p></div>');
228
+ jQuery("#ajax-response div").delay(3000).hide("slow");
229
+ });
230
+ });
231
+ });
232
+ </script>
233
+ </div>
234
+ <?php
235
+ }
236
+
237
+ function listPages($args = '')
238
+ {
239
+ $defaults = array(
240
+ 'depth' => 0, 'show_date' => '',
241
+ 'date_format' => get_option('date_format'),
242
+ 'child_of' => 0, 'exclude' => '',
243
+ 'title_li' => __('Pages'), 'echo' => 1,
244
+ 'authors' => '', 'sort_column' => 'menu_order',
245
+ 'link_before' => '', 'link_after' => '', 'walker' => '',
246
+ );
247
+
248
+ $r = wp_parse_args( $args, $defaults );
249
+ extract( $r, EXTR_SKIP );
250
+
251
+ $output = '';
252
+
253
+ $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
254
+ $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();
255
+ $r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );
256
+
257
+ // Query pages.
258
+ $r['hierarchical'] = 0;
259
+ $args = array(
260
+ 'sort_column' => 'menu_order',
261
+ 'post_type' => $post_type
262
+ );
263
+
264
+ $the_query = new WP_Query($args);
265
+ $pages = $the_query->posts;
266
+
267
+ if ( !empty($pages) ) {
268
+ if ( $r['title_li'] )
269
+ $output .= '<li class="pagenav intersect">' . $r['title_li'] . '<ul>';
270
+
271
+ $output .= $this->walkTree($pages, $r['depth'], $r);
272
+
273
+ if ( $r['title_li'] )
274
+ $output .= '</ul></li>';
275
+ }
276
+
277
+ $output = apply_filters('wp_list_pages', $output, $r);
278
+
279
+ if ( $r['echo'] )
280
+ echo $output;
281
+ else
282
+ return $output;
283
+ }
284
+
285
+ function walkTree($pages, $depth, $r)
286
+ {
287
+ if ( empty($r['walker']) )
288
+ $walker = new Custom_Type_Order_Walker;
289
+ else
290
+ $walker = $r['walker'];
291
+
292
+ $args = array($pages, $depth, $r);
293
+ return call_user_func_array(array(&$walker, 'walk'), $args);
294
+ }
295
+ }
296
+
297
+ ?>
readme.txt ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Post Types Order ===
2
+ Contributors: NSP CODE
3
+ Donate link: http://www.nsp-code.com/donate.php
4
+ Tags: post type order, custom post type order, post types order, page order, post order, custom order, ajax, re-order, drag-and-drop, admin, manage, custom, post, custom type, post type, order, ordering, sort
5
+ Requires at least: 3.0
6
+ Tested up to: 3.0.1
7
+ Stable tag: 0.9
8
+
9
+ Order Post Types Objects using a Drag and Drop Sortable javascript capability
10
+
11
+ == Description ==
12
+
13
+ Order Post Types Objects using a Drag and Drop Sortable javascript capability
14
+ It allow to reorder posts for any custom post types you defined
15
+
16
+ == Installation ==
17
+
18
+ 1. Upload `post-types-order` folder to your `/wp-content/plugins/` directory.
19
+ 2. Activate the plugin from Admin > Plugins menu.
20
+ 3. Use Re-Oder link to make your sort.
21
+
22
+
23
+ == Screenshots ==
24
+
25
+ 1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif).
26
+
27
+ == Frequently Asked Questions ==
28
+
29
+ Feel free to contact me at electronice_delphi@yahoo.com
30
+
31
+ == Change Log ==
32
+
33
+ = 0.9. =
34
+ - Initial Release
35
+
36
+
37
+ == Upgrade Notice ==
38
+
39
+ Make sure you get the latest version
40
+
41
+
42
+ == Localization ==
43
+
44
+ Currently only available in english.
screenshot-1.png ADDED
Binary file