Simple Page Ordering - Version 0.9.5

Version Description

  • Smarter awareness of "sorted" modes in WordPress 3.1 (can only use when sorted by menu order)
  • Smarter awareness of "quick edit" mode (can't drag)
  • Generally simplified / better organized code
Download this release

Release Info

Developer jakemgold
Plugin Icon 128x128 Simple Page Ordering
Version 0.9.5
Comparing to
See all releases

Code changes from version 0.9.1 to 0.9.5

readme.txt CHANGED
@@ -1,10 +1,10 @@
1
=== Simple Page Ordering ===
2
- Contributors: jakemgold
3
- Donate link: http://www.thinkoomph.com/plugins-modules/wordpress-page-order-plugin/
4
Tags: order, re-order, ordering, pages, page, manage, menu_order, hierarchical, ajax, drag-and-drop, admin
5
Requires at least: 3.0.1
6
Tested up to: 3.1
7
- Stable tag: 0.9.1
8
9
Order your pages and other hierarchical post types with simple drag and drop. Also adds a drop down to change items per page.
10
@@ -48,6 +48,11 @@ folder to the `/wp-content/plugins/` directory
48
49
== Changelog ==
50
51
= 0.9 =
52
* Fix page count display always showing "0" on non-hierarchical post types (Showing 1-X of X)
53
* Fix hidden menu order not updating after sort (causing Quick Edit to reset order when used right after sorting)
1
=== Simple Page Ordering ===
2
+ Contributors: jakemgold, thinkoomph
3
+ Donate link: http://www.get10up.com/plugins/simple-page-ordering-wordpress/
4
Tags: order, re-order, ordering, pages, page, manage, menu_order, hierarchical, ajax, drag-and-drop, admin
5
Requires at least: 3.0.1
6
Tested up to: 3.1
7
+ Stable tag: 0.9.5
8
9
Order your pages and other hierarchical post types with simple drag and drop. Also adds a drop down to change items per page.
10
48
49
== Changelog ==
50
51
+ = 0.9.5 =
52
+ * Smarter awareness of "sorted" modes in WordPress 3.1 (can only use when sorted by menu order)
53
+ * Smarter awareness of "quick edit" mode (can't drag)
54
+ * Generally simplified / better organized code
55
+
56
= 0.9 =
57
* Fix page count display always showing "0" on non-hierarchical post types (Showing 1-X of X)
58
* Fix hidden menu order not updating after sort (causing Quick Edit to reset order when used right after sorting)
spo-ordering.js → simple-page-ordering.js RENAMED
@@ -1,6 +1,9 @@
1
- jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move');
2
3
- jQuery("table.widefat tbody").sortable({
4
cursor: 'move',
5
axis: 'y',
6
containment: 'table.widefat',
@@ -19,17 +22,6 @@ jQuery("table.widefat tbody").sortable({
19
ui.item.children('td,th').css('border-bottom-width','1px');
20
},
21
update: function(event, ui) {
22
- if ( ui.item.hasClass('inline-editor') ) {
23
- jQuery("table.widefat tbody").sortable('cancel');
24
- alert( 'Please close the quick editor before reordering this item.' );
25
- return;
26
- }
27
- if ( jQuery('table.widefat th.sorted').length > 0 ) {
28
- jQuery("table.widefat tbody").sortable('cancel');
29
- alert( 'Please return the list to the default, menu order sorting before ordering items.' );
30
- return;
31
- }
32
-
33
var postid = ui.item.find('.check-column input').val(); // this post id
34
var postparent = ui.item.find('.post_parent').html(); // post parent
35
@@ -77,4 +69,6 @@ jQuery("table.widefat tbody").sortable({
77
else jQuery(this).removeClass('alternate');
78
});
79
}
80
- }).disableSelection();
1
+ if ( jQuery('table.widefat th.sorted').length < 1 ) {
2
3
+ jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move');
4
+
5
+ jQuery("table.widefat tbody").sortable({
6
+ items: 'tr:not(.inline-edit-row)',
7
cursor: 'move',
8
axis: 'y',
9
containment: 'table.widefat',
22
ui.item.children('td,th').css('border-bottom-width','1px');
23
},
24
update: function(event, ui) {
25
var postid = ui.item.find('.check-column input').val(); // this post id
26
var postparent = ui.item.find('.post_parent').html(); // post parent
27
69
else jQuery(this).removeClass('alternate');
70
});
71
}
72
+ }).disableSelection();
73
+
74
+ }
simple-page-ordering.php CHANGED
@@ -1,13 +1,13 @@
1
<?php
2
/**
3
Plugin Name: Simple Page Ordering
4
- Plugin URI: http://www.thinkoomph.com/plugins-modules/wordpress-page-order-plugin/
5
Description: Order your pages and hierarchical post types using drag and drop on the built in page list. Also adds a filter for items to show per page. For further instructions, open the "Help" tab on the Pages screen.
6
- Version: 0.9.1
7
- Author: Jake Goldman (Oomph, Inc)
8
- Author URI: http://www.thinkoomph.com
9
10
- Plugin: Copyright 2009 C. Murray Consulting (email : jake@cmurrayconsulting.com)
11
12
This program is free software; you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
@@ -24,162 +24,149 @@
24
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
*/
26
27
- /**
28
- * code to add posts per page filter
29
- */
30
-
31
- add_filter( 'edit_posts_per_page', 'spo_edit_posts_per_page', 10, 2 );
32
-
33
- function spo_edit_posts_per_page( $per_page, $post_type )
34
- {
35
- if ( !current_user_can('edit_others_pages') ) // check permission
36
- return $per_page;
37
-
38
- $post_type_object = get_post_type_object( $post_type );
39
- if ( !$post_type_object->hierarchical ) // only hierarchical post types apply
40
- return $per_page;
41
-
42
- add_action( 'restrict_manage_posts', 'spo_posts_per_page_filter' ); // posts per page drop down UI
43
- add_action( 'admin_print_styles', 'spo_admin_styles' ); // special styles (move cursor)
44
- wp_enqueue_script( 'spo-ordering', plugin_dir_url( __FILE__ ) . '/spo-ordering.js', array('jquery-ui-sortable'), '0.9', true );
45
- add_filter( 'contextual_help', 'spo_contextual_help' );
46
-
47
- if ( isset( $_GET['spo'] ) && is_numeric( $_GET['spo'] ) && ( $_GET['spo'] == -1 || ($_GET['spo']%10) == 0 ) ) :
48
-
49
- global $edit_per_page, $user_ID;
50
-
51
- $per_page = $_GET['spo'];
52
-
53
- if ( $per_page == -1 )
54
- $per_page = 99999;
55
-
56
- update_user_option( $user_ID, $edit_per_page, $per_page );
57
-
58
- endif;
59
-
60
- return $per_page;
61
- }
62
-
63
- function spo_posts_per_page_filter()
64
{
65
- global $per_page;
66
67
- $spo = isset($_GET['spo']) ? (int)$_GET['spo'] : $per_page;
68
- ?>
69
- <select name="spo" style="width: 110px;">
70
- <option<?php selected( $spo, -1 ); ?> value="-1"><?php _e('Show all'); ?></option>
71
- <?php for( $i=10;$i<=100;$i+=10 ) : ?>
72
- <option<?php selected( $spo, $i ); ?> value="<?php echo $i; ?>"><?php echo $i; ?> <?php _e('per page'); ?></option>
73
- <?php endfor; ?>
74
- </select>
75
- <?php
76
- }
77
-
78
- /**
79
- * styling and help
80
- */
81
-
82
- function spo_admin_styles() {
83
- echo '<style type="text/css">.js table.widefat tbody th, .js table.widefat tbody td { cursor: move; }</style>';
84
- }
85
-
86
- function spo_contextual_help( $help )
87
- {
88
- return $help . '
89
- <p><strong>'. __( 'Simple Page Ordering' ) . '</strong></p>
90
91
- <p><a href="http://www.thinkoomph.com/plugins-modules/wordpress-page-order-plugin/" target="_blank">Simple Page Ordering</a> is a plug-in by <a href="http://www.jakegoldman.net" target="_blank">Jake Goldman</a> (<a href="http://www.thinkoomph.com" target="_blank">Oomph, Inc</a>) that allows you to order pages and other hierarchical post types with drag and drop.</p>
92
93
- <p>To reposition an item, simply drag and drop the row by "clicking and holding" it anywhere (outside of the links and form controls) and moving it to its new position.</p>
94
95
- <p>If you have a large number of pages, it may be helpful to adjust the new "items per page" filter located above the table and before the filter button.</p>
96
97
- <p>To keep things relatively simple, the current version only allows you to reposition items within their current tree / hierarchy (next to pages with the same parent). If you want to move an item into or out of a different part of the page tree, use the "quick edit" feature to change the parent.</p>
98
- ';
99
- }
100
-
101
- /**
102
- * actual ajax request for sorting pages
103
- */
104
-
105
- add_action( 'wp_ajax_simple_page_ordering', 'spo_do_page_ordering' );
106
-
107
- function spo_do_page_ordering()
108
- {
109
- // check permissions again and make sure we have what we need
110
- if ( !current_user_can('edit_others_pages') || !isset($_POST['id']) || empty($_POST['id']) || ( !isset($_POST['previd']) && !isset($_POST['nextid']) ) )
111
- die(-1);
112
-
113
- // real post?
114
- if ( !$post = get_post( $_POST['id'] ) )
115
- die(-1);
116
117
- $previd = isset($_POST['previd']) ? $_POST['previd'] : false;
118
- $nextid = isset($_POST['nextid']) ? $_POST['nextid'] : false;
119
- $new_pos = array(); // store new positions for ajax
120
121
- if ( $previd ) {
122
-
123
- $siblings = get_posts(array( 'depth' => 1, 'numberposts' => -1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->post_parent, 'orderby' => 'menu_order', 'order' => 'ASC', 'exclude' => $post->ID )); // fetch all the siblings (relative ordering)
124
-
125
- foreach( $siblings as $sibling ) :
126
-
127
- // start updating menu orders
128
- if ( $sibling->ID == $previd ) {
129
- $menu_order = $sibling->menu_order + 1;
130
- wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
131
- $new_pos[$post->ID] = $menu_order;
132
- continue;
133
- }
134
-
135
- // nothing left to do - numbers already sufficiently padded!
136
- if ( isset($menu_order) && $menu_order < $sibling->menu_order )
137
- break;
138
-
139
- // need to update this sibling's menu order too
140
- if ( isset($menu_order) ) {
141
- $menu_order++;
142
- wp_update_post(array( 'ID' => $sibling->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
143
- $new_pos[$sibling->ID] = $menu_order;
144
- }
145
-
146
- endforeach;
147
-
148
}
149
150
- if ( !isset($menu_order) && $nextid ) {
151
-
152
- $siblings = get_posts(array( 'depth' => 1, 'numberposts' => -1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->post_parent, 'orderby' => 'menu_order', 'order' => 'DESC', 'exclude' => $post->ID )); // fetch all the siblings (relative ordering)
153
154
- foreach( $siblings as $sibling ) :
155
156
- // start updating menu orders
157
- if ( $sibling->ID == $nextid ) {
158
- $menu_order = $sibling->menu_order - 1;
159
- wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
160
- $new_pos[$post->ID] = $menu_order;
161
- continue;
162
- }
163
164
- // nothing left to do - numbers already sufficiently padded!
165
- if ( isset($menu_order) && $menu_order > $sibling->menu_order )
166
- break;
167
168
- // need to update this sibling's menu order too
169
- if ( isset($menu_order) ) {
170
- $menu_order--;
171
- wp_update_post(array( 'ID' => $sibling->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
172
- $new_pos[$sibling->ID] = $menu_order;
173
- }
174
175
- endforeach;
176
177
}
178
-
179
- // if the moved post has children, we need to refresh the page
180
- $children = get_posts(array( 'depth' => 1, 'numberposts' => 1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->ID )); // fetch all the siblings (relative ordering)
181
- if ( !empty($children) )
182
- die('children');
183
-
184
- die( json_encode($new_pos) );
185
- }
1
<?php
2
/**
3
Plugin Name: Simple Page Ordering
4
+ Plugin URI: http://www.get10up.com/plugins/simple-page-ordering-wordpress/
5
Description: Order your pages and hierarchical post types using drag and drop on the built in page list. Also adds a filter for items to show per page. For further instructions, open the "Help" tab on the Pages screen.
6
+ Version: 0.9.5
7
+ Author: Jake Goldman (10up)
8
+ Author URI: http://www.get10up.com
9
10
+ Plugin: Copyright 2011 10up (email : jake@get10up.com)
11
12
This program is free software; you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
24
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
*/
26
27
+ class simple_page_ordering
28
{
29
+ function simple_page_ordering()
30
+ {
31
+ add_filter( 'edit_posts_per_page', array( $this, 'edit_posts_per_page' ), 10, 2 );
32
+ add_action( 'wp_ajax_simple_page_ordering', array( $this, 'ajax_simple_page_ordering' ) );
33
+ }
34
+
35
+ function edit_posts_per_page( $per_page, $post_type )
36
+ {
37
+ if ( !current_user_can('edit_others_pages') ) // check permission
38
+ return $per_page;
39
+
40
+ $post_type_object = get_post_type_object( $post_type );
41
+ if ( !$post_type_object->hierarchical ) // only hierarchical post types apply
42
+ return $per_page;
43
44
+ add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) ); // posts per page drop down UI
45
+ wp_enqueue_script( 'simple-page-ordering', plugin_dir_url( __FILE__ ) . '/simple-page-ordering.js', array('jquery-ui-sortable'), '0.9.5', true );
46
+ add_filter( 'contextual_help', array( $this, 'contextual_help' ) );
47
48
+ if ( isset( $_GET['spo'] ) && is_numeric( $_GET['spo'] ) && ( $_GET['spo'] == -1 || ($_GET['spo']%10) == 0 ) ) :
49
50
+ global $edit_per_page, $user_ID;
51
+
52
+ $per_page = $_GET['spo'];
53
+
54
+ if ( $per_page == -1 )
55
+ $per_page = 99999;
56
+
57
+ update_user_option( $user_ID, $edit_per_page, $per_page );
58
59
+ endif;
60
61
+ return $per_page;
62
+ }
63
64
+ function restrict_manage_posts()
65
+ {
66
+ global $per_page;
67
+
68
+ $spo = isset($_GET['spo']) ? (int)$_GET['spo'] : $per_page;
69
+ ?>
70
+ <select name="spo" style="width: 110px;">
71
+ <option<?php selected( $spo, -1 ); ?> value="-1"><?php _e('Show all'); ?></option>
72
+ <?php for( $i=10;$i<=100;$i+=10 ) : ?>
73
+ <option<?php selected( $spo, $i ); ?> value="<?php echo $i; ?>"><?php echo $i; ?> <?php _e('per page'); ?></option>
74
+ <?php endfor; ?>
75
+ </select>
76
+ <?php
77
+ }
78
79
+ function contextual_help( $help )
80
+ {
81
+ return $help . '
82
+ <p><strong>'. __( 'Simple Page Ordering' ) . '</strong></p>
83
+ <p><a href="http://www.get10up.com/plugins/simple-page-ordering-wordpress/" target="_blank">Simple Page Ordering</a> is a plug-in by <a href="http://www.get10up.com" target="_blank">Jake Goldman (10up)</a>) that allows you to order pages and other hierarchical post types with drag and drop.</p>
84
+ <p>To reposition an item, simply drag and drop the row by "clicking and holding" it anywhere (outside of the links and form controls) and moving it to its new position.</p>
85
+ <p>If you have a large number of pages, it may be helpful to adjust the new "items per page" filter located above the table and before the filter button.</p>
86
+ <p>To keep things relatively simple, the current version only allows you to reposition items within their current tree / hierarchy (next to pages with the same parent). If you want to move an item into or out of a different part of the page tree, use the "quick edit" feature to change the parent.</p>
87
+ ';
88
}
89
90
+ function ajax_simple_page_ordering()
91
+ {
92
+ // check permissions again and make sure we have what we need
93
+ if ( !current_user_can('edit_others_pages') || empty($_POST['id']) || ( !isset($_POST['previd']) && !isset($_POST['nextid']) ) )
94
+ die(-1);
95
+
96
+ // real post?
97
+ if ( !$post = get_post( $_POST['id'] ) )
98
+ die(-1);
99
+
100
+ $previd = isset($_POST['previd']) ? $_POST['previd'] : false;
101
+ $nextid = isset($_POST['nextid']) ? $_POST['nextid'] : false;
102
+ $new_pos = array(); // store new positions for ajax
103
+
104
+ if ( $previd )
105
+ {
106
+ $siblings = get_posts(array( 'depth' => 1, 'numberposts' => -1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->post_parent, 'orderby' => 'menu_order', 'order' => 'ASC', 'exclude' => $post->ID )); // fetch all the siblings (relative ordering)
107
+
108
+ foreach( $siblings as $sibling ) :
109
+
110
+ // start updating menu orders
111
+ if ( $sibling->ID == $previd ) {
112
+ $menu_order = $sibling->menu_order + 1;
113
+ wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
114
+ $new_pos[$post->ID] = $menu_order;
115
+ continue;
116
+ }
117
+
118
+ // nothing left to do - numbers already sufficiently padded!
119
+ if ( isset($menu_order) && $menu_order < $sibling->menu_order )
120
+ break;
121
+
122
+ // need to update this sibling's menu order too
123
+ if ( isset($menu_order) ) {
124
+ $menu_order++;
125
+ wp_update_post(array( 'ID' => $sibling->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
126
+ $new_pos[$sibling->ID] = $menu_order;
127
+ }
128
+
129
+ endforeach;
130
+
131
+ }
132
133
+ if ( !isset($menu_order) && $nextid ) {
134
+
135
+ $siblings = get_posts(array( 'depth' => 1, 'numberposts' => -1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->post_parent, 'orderby' => 'menu_order', 'order' => 'DESC', 'exclude' => $post->ID )); // fetch all the siblings (relative ordering)
136
137
+ foreach( $siblings as $sibling ) :
138
+
139
+ // start updating menu orders
140
+ if ( $sibling->ID == $nextid ) {
141
+ $menu_order = $sibling->menu_order - 1;
142
+ wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
143
+ $new_pos[$post->ID] = $menu_order;
144
+ continue;
145
+ }
146
+
147
+ // nothing left to do - numbers already sufficiently padded!
148
+ if ( isset($menu_order) && $menu_order > $sibling->menu_order )
149
+ break;
150
+
151
+ // need to update this sibling's menu order too
152
+ if ( isset($menu_order) ) {
153
+ $menu_order--;
154
+ wp_update_post(array( 'ID' => $sibling->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
155
+ $new_pos[$sibling->ID] = $menu_order;
156
+ }
157
158
+ endforeach;
159
160
+ }
161
162
+ // if the moved post has children, we need to refresh the page
163
+ $children = get_posts(array( 'depth' => 1, 'numberposts' => 1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->ID )); // fetch all the siblings (relative ordering)
164
+ if ( !empty($children) )
165
+ die('children');
166
167
+ die( json_encode($new_pos) );
168
}
169
+ }
170
+
171
+ if ( is_admin() )
172
+ $simple_page_ordering = new simple_page_ordering;