Simple Page Ordering - Version 0.8.4

Version Description

  • Loosened constraints on drag and drop to ease dropping into top and bottom position
  • Fixed row background staying "white" after dropping into a new position
  • Fixed double border on the bottom of the row while dragging
  • Improved some terminology (with custom post types in mind)
Download this release

Release Info

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

Version 0.8.4

readme.txt ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Simple Page Ordering ===
2
+ Contributors: Jacob M Goldman (C. Murray Consulting)
3
+ Donate link: http://www.cmurrayconsulting.com/software/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.0.1
7
+ Stable tag: 0.8.4
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
+
11
+ == Description ==
12
+
13
+ Order your pages (and any hierarchical custom post types) with simple drag and drop on the page (or custom type) management / list screen.
14
+
15
+ The following video is from an earlier build (0.7) that has been refined.
16
+
17
+ [youtube http://www.youtube.com/watch?v=wWEVW78VF30]
18
+
19
+ Simply drag and drop the page into your desired position! It's that simple. No new admin menus pages, no dedicated clunky user interfaces. Just drag and drop on the page list screen.
20
+
21
+ To facilitate the menu order management on sites with many pages, the plug-in also adds a new drop down filter allowing you to customize the paging (pages per page) on the page admin screen. Your last choice will even be saved whenever you return (on a user to user basis and post type by post type basis)!
22
+
23
+ The plug-in is "capabilities smart" - only users with the ability to edit others' pages (i.e. editors and administrators) will be able to reorder pages.
24
+
25
+ Integrated help is included! Just click the "help" tab toward the top right of the screen; the help is below the standard help for the screen.
26
+
27
+ Note that this plug-in only allows drag and drop resort within the same branch in the page tree / hierarchy for a given page. You can instantly change the hierarchy by using the Quick Edit feature built into WordPress and changing the "Parent" option. This may be addressed in the future, but the intention is to avoid confusion about "where" you're trying to put the page. For example, if you move a page after another page's last child, are you trying to make it a child of the other page, or position it after the other page? Ideas are welcome.
28
+
29
+ This plug-in is being released as a "beta" in the Google sense. There are no known issues, but it requires much more comprehensive testing with custom post types and environments with large number of pages before we can label it "1.0". You must have JavaScript enabled for this plug-in to work.
30
+
31
+ Please note that the plug-in is currently only minimally compatible with Internet Explorer 7 and earlier, due to limitations within those browsers.
32
+
33
+
34
+ == Installation ==
35
+
36
+ 1. Install easily with the WordPress plugin control panel or manually download the plugin and upload the extracted
37
+ folder to the `/wp-content/plugins/` directory
38
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
39
+ 1. Start dragging and dropping by going to the "Page" admin menu (or custom post type equivalent)!
40
+
41
+
42
+ == Screenshots ==
43
+
44
+ 1. Changing the paging (items per page)
45
+ 1. Dragging the page to its new position
46
+ 1. Processing indicator
47
+
48
+
49
+ == Changelog ==
50
+
51
+ = 0.8.4 =
52
+ * Loosened constraints on drag and drop to ease dropping into top and bottom position
53
+ * Fixed row background staying "white" after dropping into a new position
54
+ * Fixed double border on the bottom of the row while dragging
55
+ * Improved some terminology (with custom post types in mind)
56
+
57
+ = 0.8.2 =
58
+ * Simplified code - consolidated hooks
59
+ * Updated version requirements
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
simple-page-ordering.php ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ Plugin Name: Simple Page Ordering
4
+ Plugin URI: http://www.cmurrayconsulting.com/software/wordpress-page-order-plugin/
5
+ Description: Order your pages and other hierarchical post types with drag and drop. Also adds a filter for items to show per page.
6
+ Version: 0.8.4
7
+ Author: Jacob M Goldman (C. Murray Consulting)
8
+ Author URI: http://www.cmurrayconsulting.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
14
+ the Free Software Foundation; either version 2 of the License, or
15
+ (at your option) any later version.
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
+ * 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;
37
+
38
+ $post_type_object = get_post_type_object( $post_type );
39
+ if ( !$post_type_object->hierarchical ) // only hierarchical post types apply
40
+ return;
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), spinner positioning
44
+ wp_enqueue_script( 'spo-ordering', plugin_dir_url( __FILE__ ) . '/spo-ordering.js', array('jquery-ui-sortable'), '0.8.4', 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: 100px;">
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">table.widefat tbody th, 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.cmurrayconsulting.com/software/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.cmurrayconsulting.com/software/wordpress-page-order-plugin/" target="_blank">C. Murray Consulting</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
+
120
+ if ( $previd ) {
121
+
122
+ $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)
123
+
124
+ foreach( $siblings as $sibling ) :
125
+
126
+ // start updating menu orders
127
+ if ( $sibling->ID == $previd ) {
128
+ $menu_order = $sibling->menu_order + 1;
129
+ wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
130
+ continue;
131
+ }
132
+
133
+ // nothing left to do - numbers already sufficiently padded!
134
+ if ( isset($menu_order) && $menu_order < $sibling->menu_order )
135
+ break;
136
+
137
+ // need to update this sibling's menu order too
138
+ if ( isset($menu_order) ) {
139
+ $menu_order++;
140
+ wp_update_post(array( 'ID' => $sibling->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
141
+ }
142
+
143
+ endforeach;
144
+
145
+ }
146
+
147
+ if ( !isset($menu_order) && $nextid ) {
148
+
149
+ $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)
150
+
151
+ foreach( $siblings as $sibling ) :
152
+
153
+ // start updating menu orders
154
+ if ( $sibling->ID == $nextid ) {
155
+ $menu_order = $sibling->menu_order - 1;
156
+ wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
157
+ continue;
158
+ }
159
+
160
+ // nothing left to do - numbers already sufficiently padded!
161
+ if ( isset($menu_order) && $menu_order > $sibling->menu_order )
162
+ break;
163
+
164
+ // need to update this sibling's menu order too
165
+ if ( isset($menu_order) ) {
166
+ $menu_order--;
167
+ wp_update_post(array( 'ID' => $sibling->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
168
+ }
169
+
170
+ endforeach;
171
+
172
+ }
173
+
174
+ // if the moved post has children, we need to refresh the page
175
+ $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)
176
+ if ( !empty($children) )
177
+ die('children');
178
+
179
+ die();
180
+ }
spo-ordering.js ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery("table.widefat tbody").sortable({
2
+ cursor: 'move',
3
+ axis: 'y',
4
+ containment: 'table.widefat',
5
+ scrollSensitivity: 40,
6
+ helper: function(e, ui) {
7
+ ui.children().each(function() { jQuery(this).width(jQuery(this).width()); });
8
+ return ui;
9
+ },
10
+ start: function(event, ui) {
11
+ if ( ! ui.item.hasClass('alternate') ) ui.item.css( 'background-color', '#ffffff' );
12
+ ui.item.children('td, th').css('border','none');
13
+ ui.item.css( 'outline', '1px solid #dfdfdf' );
14
+ },
15
+ stop: function(event, ui) {
16
+ ui.item.removeAttr('style');
17
+ ui.item.children('td, th').removeAttr('style');
18
+ },
19
+ update: function(event, ui) {
20
+ if ( ui.item.hasClass('inline-editor') ) {
21
+ jQuery("table.widefat tbody").sortable('cancel');
22
+ alert( 'Please close the quick editor before reordering this item.' );
23
+ return;
24
+ }
25
+
26
+ var postid = ui.item.find('.check-column input').val(); // this post id
27
+ var postparent = ui.item.find('.post_parent').html(); // post parent
28
+
29
+ var prevpostid = ui.item.prev().find('.check-column input').val();
30
+ var nextpostid = ui.item.next().find('.check-column input').val();
31
+
32
+ // can only sort in same tree
33
+
34
+ var prevpostparent = undefined;
35
+ if ( prevpostid != undefined ) {
36
+ var prevpostparent = ui.item.prev().find('.post_parent').html()
37
+ if ( prevpostparent != postparent) prevpostid = undefined;
38
+ }
39
+
40
+ var nextpostparent = undefined;
41
+ if ( nextpostid != undefined ) {
42
+ nextpostparent = ui.item.next().find('.post_parent').html();
43
+ if ( nextpostparent != postparent) nextpostid = undefined;
44
+ }
45
+
46
+ // if previous and next not at same tree level, or next not at same tree level and the previous is the parent of the next, or just moved item beneath its own children
47
+ if ( ( prevpostid == undefined && nextpostid == undefined ) || ( nextpostid == undefined && nextpostparent == prevpostid ) || ( nextpostid != undefined && prevpostparent == postid ) ) {
48
+ jQuery("table.widefat tbody").sortable('cancel');
49
+ alert( "Items can only be repositioned within their current branch in the page tree / hierarchy (next to pages with the same parent).\n\nIf you want to move this item into a different part of the page tree, use the Quick Edit feature to change the parent before continuing." );
50
+ return;
51
+ }
52
+
53
+ // show spinner
54
+ ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />');
55
+
56
+ // go do the sorting stuff via ajax
57
+ jQuery.post( ajaxurl, { action: 'simple_page_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, function(response){
58
+ if ( response == 'children' ) window.location.reload();
59
+ else ui.item.find('.check-column input').show().siblings('img').remove();
60
+ });
61
+
62
+ // fix cell colors
63
+ jQuery( 'table.widefat tbody tr' ).each(function(){
64
+ var i = jQuery('table.widefat tbody tr').index(this);
65
+ if ( i%2 == 0 ) jQuery(this).addClass('alternate');
66
+ else jQuery(this).removeClass('alternate');
67
+ });
68
+ }
69
+ }).disableSelection();