Simple Page Ordering - Version 2.1

Version Description

  • UI refinements: Better "spinner" positioning (and HiDPI), translucent row when moving, improved appearance of "drop" placeholder, wait till row dragged by at least 5px to start sorting
  • Major JavaScript refactoring and simplification (combined with new stylesheet) for better performance
  • Awareness of custom user capabilities for post types, in addition to a filter (simple_page_ordering_edit_rights) for overriding reordering rights (previously used edit_others_pages globally)
  • Awareness of custom post statuses (so they are not skipped during backend ordering operation)
Download this release

Release Info

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

Code changes from version 2.0 to 2.1

readme.txt CHANGED
@@ -2,15 +2,15 @@
2
  Contributors: jakemgold, 10up, thinkoomph
3
  Donate link: http://10up.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.2
6
- Tested up to: 3.5
7
- Stable tag: 2.0
8
 
9
  Order your pages and other hierarchical post types with simple drag and drop right from the standard page list.
10
 
11
  == Description ==
12
 
13
- Order your pages, hierarchical custom post types, or custom post types with "page-attributes" with simple drag and drop right from the built in page list.
14
 
15
  Simply drag and drop the page into the desired position. It's that simple. No new admin menus pages, no clunky, bolted on user interfaces. Just drag and drop on the page or post-type screen.
16
 
@@ -18,55 +18,55 @@ The plug-in is "capabilities aware" - only users with the ability to edit others
18
 
19
  Integrated help is included: just click the "help" tab at the top right of the screen.
20
 
21
- Please note that the plug-in is currently only minimally compatible with Internet Explorer 7 and earlier, due to limitations within those browsers.
22
 
23
 
24
  == Installation ==
25
 
26
  1. Install either via the WordPress.org plugin directory, or by uploading the files to your server.
27
  1. Activate the plugin through the 'Plugins' menu in WordPress.
28
- 1. Get to work reordering your content!
29
-
30
-
31
- == Frequently Asked Questions ==
32
-
33
- = Why can't I reorder my posts? =
34
-
35
- Generic posts are not displayed by menu order - they're displayed by chronology. You can theoretically add menu ordering to posts in your code (theme functions.php, plug-in) by using:
36
-
37
- `add_post_type_support( 'post', 'page-attributes' );`
38
-
39
- = Can I make my custom post type take advantage of this plug-in? =
40
-
41
- Yep. There are two ways to turn on support for Simple Page Ordering.
42
-
43
- Ideally, when you register the post type, set `hierarchical` to `true` - hierarchical post types natively order by menu order.
44
-
45
- Alternatively, when you define the features the post type supports, include `page-attributes`. This will add a `Sort by Order` option to the filter links above the drop downs. Once you sort by order, you can drag and drop the content.
46
-
47
- Finally, you can take advantage of the `simple_page_ordering_is_sortable` filter, which passes the result of the default check and the post type name, to override default behavior.
48
-
49
- = I want my non-hierarchical post type to be sortable. Help! =
50
-
51
- See the previous two answers - just add `page-attributes` to the list of supported post type features.
52
-
53
- = I reordered my posts, but the order didn't change on the front end of my site! =
54
-
55
- This plug-in doesn't change any *behavior* on the front end, it simply changes the menu order stored in WordPress.
56
-
57
- If you want a list of pages or custom post types to display in that defined order, you must change the post query's `orderby` parameter to `menu_order` (if it's not already).
58
-
59
- = I reordered my content, it seemed to work, but when I refreshed, it went back to the old order! =
60
-
61
- This most likely means the AJAX request - the server side code - failed after you dropped the content into the new position. Some shared hosts aggressively time out and limit AJAX requests. Version 2.0 batches these requests so you can try reducing the number of items it updates on each request using a filter in your theme's functions.php or a custom plug-in:
62
-
63
- `add_filter( 'simple_page_ordering_limit', function($number) { return 5; } );`
64
-
65
- Where 5 is the number of items to batch on each request (the default is 50). Note that this example uses PHP 5.3+ callback functions, so if you're still on PHP 5.2, you'll need to add a traditional callback.
66
-
67
- = What happened to the drop down box that let me change the number of items on each page in the admin?? =
68
-
69
- This feature is already built into WordPress natively, but a bit tucked away. If you pull down the "Screen Options" tab up top (on the list of post objects) there's a field where you can specify the number of items to show per page. I decided it was not a very good practice to duplicate this.
70
 
71
 
72
  == Screenshots ==
@@ -76,15 +76,21 @@ This feature is already built into WordPress natively, but a bit tucked away. If
76
 
77
 
78
  == Changelog ==
79
-
80
- = 2.0 =
81
- * Drag pages into any part of the page hierarchy! No longer limited to same branch of tree!
82
- * Big performance improvements under the hood: leaner queries, batched requests, less processing
83
- * Scales much more reliably in situations with very high page counts due to batching of requests
84
- * Order of the first page is now set to "1" instead of "0", so pages added after ordering are added at the top (instead of second)
85
- * Removed "number of pages" drop down, which is repetitive of a field accessible under Screen Options
86
- * New filters and hooks to extend / override default functionality
87
- * Improved compatibility with newer versions of WordPress
 
 
 
 
 
 
88
 
89
  = 1.0 =
90
  * Fix unexpected page ordering results when pages have not been explictly ordered yet (sorts by menu_order, then title, not just menu_order)
2
  Contributors: jakemgold, 10up, thinkoomph
3
  Donate link: http://10up.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.4
6
+ Tested up to: 3.6
7
+ Stable tag: 2.1
8
 
9
  Order your pages and other hierarchical post types with simple drag and drop right from the standard page list.
10
 
11
  == Description ==
12
 
13
+ Order your pages, hierarchical custom post types, or custom post types with "page-attributes" with simple drag and drop right from the built in page list.
14
 
15
  Simply drag and drop the page into the desired position. It's that simple. No new admin menus pages, no clunky, bolted on user interfaces. Just drag and drop on the page or post-type screen.
16
 
18
 
19
  Integrated help is included: just click the "help" tab at the top right of the screen.
20
 
21
+ Please note that the plug-in is not compatible with Internet Explorer 7 and earlier, due to limitations within those browsers.
22
 
23
 
24
  == Installation ==
25
 
26
  1. Install either via the WordPress.org plugin directory, or by uploading the files to your server.
27
  1. Activate the plugin through the 'Plugins' menu in WordPress.
28
+ 1. Get to work reordering your content!
29
+
30
+
31
+ == Frequently Asked Questions ==
32
+
33
+ = Why can't I reorder my posts? =
34
+
35
+ Generic posts are not displayed by menu order - they're displayed by chronology. You can theoretically add menu ordering to posts in your code (theme functions.php, plug-in) by using:
36
+
37
+ `add_post_type_support( 'post', 'page-attributes' );`
38
+
39
+ = Can I make my custom post type take advantage of this plug-in? =
40
+
41
+ Yep. There are two ways to turn on support for Simple Page Ordering.
42
+
43
+ Ideally, when you register the post type, set `hierarchical` to `true` - hierarchical post types natively order by menu order.
44
+
45
+ Alternatively, when you define the features the post type supports, include `page-attributes`. This will add a `Sort by Order` option to the filter links above the drop downs. Once you sort by order, you can drag and drop the content.
46
+
47
+ Finally, you can take advantage of the `simple_page_ordering_is_sortable` filter, which passes the result of the default check and the post type name, to override default behavior.
48
+
49
+ = I want my non-hierarchical post type to be sortable. Help! =
50
+
51
+ See the previous two answers - just add `page-attributes` to the list of supported post type features.
52
+
53
+ = I reordered my posts, but the order didn't change on the front end of my site! =
54
+
55
+ This plug-in doesn't change any *behavior* on the front end, it simply changes the menu order stored in WordPress.
56
+
57
+ If you want a list of pages or custom post types to display in that defined order, you must change the post query's `orderby` parameter to `menu_order` (if it's not already).
58
+
59
+ = I reordered my content, it seemed to work, but when I refreshed, it went back to the old order! =
60
+
61
+ This most likely means the AJAX request - the server side code - failed after you dropped the content into the new position. Some shared hosts aggressively time out and limit AJAX requests. Version 2.0 batches these requests so you can try reducing the number of items it updates on each request using a filter in your theme's functions.php or a custom plug-in:
62
+
63
+ `add_filter( 'simple_page_ordering_limit', function($number) { return 5; } );`
64
+
65
+ Where 5 is the number of items to batch on each request (the default is 50). Note that this example uses PHP 5.3+ callback functions, so if you're still on PHP 5.2, you'll need to add a traditional callback.
66
+
67
+ = What happened to the drop down box that let me change the number of items on each page in the admin?? =
68
+
69
+ This feature is already built into WordPress natively, but a bit tucked away. If you pull down the "Screen Options" tab up top (on the list of post objects) there's a field where you can specify the number of items to show per page. I decided it was not a very good practice to duplicate this.
70
 
71
 
72
  == Screenshots ==
76
 
77
 
78
  == Changelog ==
79
+
80
+ = 2.1 =
81
+ * UI refinements: Better "spinner" positioning (and HiDPI), translucent row when moving, improved appearance of "drop" placeholder, wait till row dragged by at least 5px to start sorting
82
+ * Major JavaScript refactoring and simplification (combined with new stylesheet) for better performance
83
+ * Awareness of custom user capabilities for post types, in addition to a filter (`simple_page_ordering_edit_rights`) for overriding reordering rights (previously used `edit_others_pages` globally)
84
+ * Awareness of custom post statuses (so they are not skipped during backend ordering operation)
85
+
86
+ = 2.0 =
87
+ * Drag pages into any part of the page hierarchy! No longer limited to same branch of tree!
88
+ * Big performance improvements under the hood: leaner queries, batched requests, less processing
89
+ * Scales much more reliably in situations with very high page counts due to batching of requests
90
+ * Order of the first page is now set to "1" instead of "0", so pages added after ordering are added at the top (instead of second)
91
+ * Removed "number of pages" drop down, which is repetitive of a field accessible under Screen Options
92
+ * New filters and hooks to extend / override default functionality
93
+ * Improved compatibility with newer versions of WordPress
94
 
95
  = 1.0 =
96
  * Fix unexpected page ordering results when pages have not been explictly ordered yet (sorts by menu_order, then title, not just menu_order)
simple-page-ordering.css ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wp-list-table .ui-sortable tr {
2
+ cursor: move;
3
+ }
4
+ .wp-list-table .spo-updating tr {
5
+ cursor: default;
6
+ }
7
+ .wp-list-table .ui-sortable-placeholder {
8
+ border: 0;
9
+ height: 51px;
10
+ background: #808080;
11
+ background-image: -webkit-gradient(linear, left bottom, left top, from(#6d6d6d), to(#808080));
12
+ background-image: -webkit-linear-gradient(bottom, #6d6d6d, #808080);
13
+ background-image: -moz-linear-gradient(bottom, #6d6d6d, #808080);
14
+ background-image: -o-linear-gradient(bottom, #6d6d6d, #808080);
15
+ background-image: linear-gradient(to top, #6d6d6d, #808080);
16
+ visibility: visible !important;
17
+ }
18
+ .wp-list-table .ui-sortable-helper {
19
+ background-color: #fff;
20
+ margin-left: -1px;
21
+ border: 1px solid #dfdfdf;
22
+ }
23
+ .wp-list-table .ui-sortable-helper th,
24
+ .wp-list-table .ui-sortable-helper td {
25
+ border-bottom-width: 0 !important;
26
+ }
27
+
28
+ .spo-updating-row .check-column {
29
+ background: url('../../../wp-admin/images/wpspin_light.gif') center no-repeat;
30
+ }
31
+ @media print,
32
+ (-o-min-device-pixel-ratio: 5/4),
33
+ (-webkit-min-device-pixel-ratio: 1.25),
34
+ (min-resolution: 120dpi) {
35
+ .spo-updating-row .check-column {
36
+ background-image: url('../../../wp-admin/images/wpspin_light-2x.gif');
37
+ background-size: 16px 16px;
38
+ }
39
+ }
40
+ .spo-updating-row .check-column input {
41
+ visibility: hidden;
42
+ }
simple-page-ordering.dev.js CHANGED
@@ -1,5 +1,5 @@
1
  function update_simple_ordering_callback(response) {
2
- if ( response == 'children' ) {
3
  window.location.reload();
4
  return;
5
  }
@@ -7,23 +7,25 @@ function update_simple_ordering_callback(response) {
7
  var changes = jQuery.parseJSON( response );
8
 
9
  var new_pos = changes.new_pos;
10
- for ( key in new_pos ) {
11
- if ( key == 'next' )
12
  continue;
13
 
14
- if ( jQuery('#inline_'+key).length > 0 ) {
15
- if ( new_pos[key]['menu_order'] != null ) {
16
- jQuery('#inline_'+key+' .menu_order').html( new_pos[key]['menu_order'] );
17
- jQuery('#inline_'+key+' .post_parent').html( new_pos[key]['post_parent'] );
18
- var post_title = jQuery('#inline_'+key+' .post_title').html();
 
 
19
  var dashes = 0;
20
- while ( dashes < new_pos[key]['depth'] ) {
21
  post_title = '&mdash; ' + post_title;
22
  dashes++;
23
  }
24
- jQuery('tr#post-'+key+' a.row-title').html( post_title );
25
  } else {
26
- jQuery('#inline_'+key+' .menu_order').html(new_pos[key]);
27
  }
28
  }
29
  }
@@ -38,59 +40,52 @@ function update_simple_ordering_callback(response) {
38
  excluded: changes.next['excluded']
39
  }, update_simple_ordering_callback );
40
  } else {
41
- jQuery('.check-column .waiting').siblings('input').show().siblings('img').remove();
42
- jQuery('tr.iedit').css('cursor','move');
43
- jQuery(".wp-list-table tbody").sortable('enable');
44
  }
45
  }
46
 
47
- jQuery('tr.iedit').css('cursor','move');
48
-
49
- jQuery(".wp-list-table tbody").sortable({
50
- items: 'tr:not(.inline-edit-row)',
51
  cursor: 'move',
52
  axis: 'y',
53
  containment: 'table.widefat',
54
  scrollSensitivity: 40,
55
- helper: function(e, ui) {
56
- ui.children().each(function() { jQuery(this).width(jQuery(this).width()); });
57
- return ui;
58
- },
59
- start: function(event, ui) {
60
- if ( ! ui.item.hasClass('alternate') ) ui.item.css( 'background-color', '#ffffff' );
61
- ui.item.children('td,th').css('border-bottom-width','0');
62
- ui.item.css( 'outline', '1px solid #dfdfdf' );
63
- },
64
- stop: function(event, ui) {
65
- ui.item.removeAttr('style');
66
- ui.item.children('td,th').css('border-bottom-width','1px');
67
- },
68
  update: function(event, ui) {
69
- jQuery('tr.iedit').css('cursor','default');
70
- jQuery(".wp-list-table tbody").sortable('disable');
71
 
72
- var postid = ui.item.attr('id').substr(5); // post id
73
 
74
  var prevpostid = false;
75
  var prevpost = ui.item.prev();
76
- if ( prevpost.length > 0 )
77
  prevpostid = prevpost.attr('id').substr(5);
 
78
 
79
  var nextpostid = false;
80
  var nextpost = ui.item.next();
81
- if ( nextpost.length > 0 )
82
  nextpostid = nextpost.attr('id').substr(5);
83
-
84
- // show spinner
85
- ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />');
86
 
87
  // go do the sorting stuff via ajax
88
  jQuery.post( ajaxurl, { action: 'simple_page_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, update_simple_ordering_callback );
89
 
90
  // fix cell colors
91
- jQuery( 'tr.iedit' ).each(function(i){
92
- if ( i%2 == 0 ) jQuery(this).addClass('alternate');
93
- else jQuery(this).removeClass('alternate');
94
- });
 
 
 
 
 
95
  }
96
  });
1
  function update_simple_ordering_callback(response) {
2
+ if ( 'children' === response ) {
3
  window.location.reload();
4
  return;
5
  }
7
  var changes = jQuery.parseJSON( response );
8
 
9
  var new_pos = changes.new_pos;
10
+ for ( var key in new_pos ) {
11
+ if ( 'next' === key )
12
  continue;
13
 
14
+ var inline_key = document.getElementById('inline_' + key);
15
+ if ( null !== inline_key && new_pos.hasOwnProperty(key) ) {
16
+ if ( undefined !== new_pos[key]['menu_order'] ) {
17
+ inline_key.querySelector('.menu_order').innerHTML = new_pos[key]['menu_order'];
18
+ inline_key.querySelector('.post_parent').innerHTML = new_pos[key]['post_parent'];
19
+ var post_title = inline_key.querySelector('.post_title').innerHTML;
20
+
21
  var dashes = 0;
22
+ while (dashes < new_pos[key]['depth']) {
23
  post_title = '&mdash; ' + post_title;
24
  dashes++;
25
  }
26
+ inline_key.parentNode.querySelector('.row-title').innerHTML = post_title;
27
  } else {
28
+ inline_key.querySelector('.menu_order').innerHTML = new_pos[key];
29
  }
30
  }
31
  }
40
  excluded: changes.next['excluded']
41
  }, update_simple_ordering_callback );
42
  } else {
43
+ jQuery(document.querySelector('.spo-updating-row')).removeClass('spo-updating-row');
44
+ sortable_post_table.removeClass('spo-updating').sortable('enable');
 
45
  }
46
  }
47
 
48
+ var sortable_post_table = jQuery( document.querySelector(".wp-list-table tbody") );
49
+ sortable_post_table.sortable({
50
+ items: '> tr',
 
51
  cursor: 'move',
52
  axis: 'y',
53
  containment: 'table.widefat',
54
  scrollSensitivity: 40,
55
+ cancel: '.inline-edit-row',
56
+ distance: 5,
57
+ opacity: .85,
58
+ forceHelperSize: true,
 
 
 
 
 
 
 
 
 
59
  update: function(event, ui) {
60
+ sortable_post_table.sortable('disable').addClass('spo-updating');
61
+ ui.item.addClass('spo-updating-row');
62
 
63
+ var postid = ui.item[0].id.substr(5); // post id
64
 
65
  var prevpostid = false;
66
  var prevpost = ui.item.prev();
67
+ if ( prevpost.length > 0 ) {
68
  prevpostid = prevpost.attr('id').substr(5);
69
+ }
70
 
71
  var nextpostid = false;
72
  var nextpost = ui.item.next();
73
+ if ( nextpost.length > 0 ) {
74
  nextpostid = nextpost.attr('id').substr(5);
75
+ }
 
 
76
 
77
  // go do the sorting stuff via ajax
78
  jQuery.post( ajaxurl, { action: 'simple_page_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, update_simple_ordering_callback );
79
 
80
  // fix cell colors
81
+ var table_rows = document.querySelectorAll('tr.iedit'),
82
+ table_row_count = table_rows.length;
83
+ while( table_row_count-- ) {
84
+ if ( table_row_count%2 == 0 ) {
85
+ jQuery( table_rows[table_row_count]).addClass('alternate');
86
+ } else {
87
+ jQuery( table_rows[table_row_count]).removeClass('alternate');
88
+ }
89
+ }
90
  }
91
  });
simple-page-ordering.js CHANGED
@@ -1 +1 @@
1
- function update_simple_ordering_callback(response){if(response=='children'){window.location.reload();return}var changes=jQuery.parseJSON(response);var new_pos=changes.new_pos;for(key in new_pos){if(key=='next')continue;if(jQuery('#inline_'+key).length>0){if(new_pos[key]['menu_order']!=null){jQuery('#inline_'+key+' .menu_order').html(new_pos[key]['menu_order']);jQuery('#inline_'+key+' .post_parent').html(new_pos[key]['post_parent']);var post_title=jQuery('#inline_'+key+' .post_title').html();var dashes=0;while(dashes<new_pos[key]['depth']){post_title='&mdash; '+post_title;dashes++}jQuery('tr#post-'+key+' a.row-title').html(post_title)}else{jQuery('#inline_'+key+' .menu_order').html(new_pos[key])}}}if(changes.next){jQuery.post(ajaxurl,{action:'simple_page_ordering',id:changes.next['id'],previd:changes.next['previd'],nextid:changes.next['nextid'],start:changes.next['start'],excluded:changes.next['excluded']},update_simple_ordering_callback)}else{jQuery('.check-column .waiting').siblings('input').show().siblings('img').remove();jQuery('tr.iedit').css('cursor','move');jQuery(".wp-list-table tbody").sortable('enable')}}jQuery('tr.iedit').css('cursor','move');jQuery(".wp-list-table tbody").sortable({items:'tr:not(.inline-edit-row)',cursor:'move',axis:'y',containment:'table.widefat',scrollSensitivity:40,helper:function(e,ui){ui.children().each(function(){jQuery(this).width(jQuery(this).width())});return ui},start:function(event,ui){if(!ui.item.hasClass('alternate'))ui.item.css('background-color','#ffffff');ui.item.children('td,th').css('border-bottom-width','0');ui.item.css('outline','1px solid #dfdfdf')},stop:function(event,ui){ui.item.removeAttr('style');ui.item.children('td,th').css('border-bottom-width','1px')},update:function(event,ui){jQuery('tr.iedit').css('cursor','default');jQuery(".wp-list-table tbody").sortable('disable');var postid=ui.item.attr('id').substr(5);var prevpostid=false;var prevpost=ui.item.prev();if(prevpost.length>0)prevpostid=prevpost.attr('id').substr(5);var nextpostid=false;var nextpost=ui.item.next();if(nextpost.length>0)nextpostid=nextpost.attr('id').substr(5);ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />');jQuery.post(ajaxurl,{action:'simple_page_ordering',id:postid,previd:prevpostid,nextid:nextpostid},update_simple_ordering_callback);jQuery('tr.iedit').each(function(i){if(i%2==0)jQuery(this).addClass('alternate');else jQuery(this).removeClass('alternate')})}});
1
+ function update_simple_ordering_callback(e){if("children"===e){window.location.reload();return}var t=jQuery.parseJSON(e);var n=t.new_pos;for(var r in n){if("next"===r)continue;var i=document.getElementById("inline_"+r);if(null!==i&&n.hasOwnProperty(r)){if(undefined!==n[r]["menu_order"]){i.querySelector(".menu_order").innerHTML=n[r]["menu_order"];i.querySelector(".post_parent").innerHTML=n[r]["post_parent"];var s=i.querySelector(".post_title").innerHTML;var o=0;while(o<n[r]["depth"]){s="— "+s;o++}i.parentNode.querySelector(".row-title").innerHTML=s}else{i.querySelector(".menu_order").innerHTML=n[r]}}}if(t.next){jQuery.post(ajaxurl,{action:"simple_page_ordering",id:t.next["id"],previd:t.next["previd"],nextid:t.next["nextid"],start:t.next["start"],excluded:t.next["excluded"]},update_simple_ordering_callback)}else{jQuery(document.querySelector(".spo-updating-row")).removeClass("spo-updating-row");sortable_post_table.removeClass("spo-updating").sortable("enable")}}var sortable_post_table=jQuery(document.querySelector(".wp-list-table tbody"));sortable_post_table.sortable({items:"> tr",cursor:"move",axis:"y",containment:"table.widefat",scrollSensitivity:40,cancel:".inline-edit-row",distance:5,opacity:.85,forceHelperSize:true,update:function(e,t){sortable_post_table.sortable("disable").addClass("spo-updating");t.item.addClass("spo-updating-row");var n=t.item[0].id.substr(5);var r=false;var i=t.item.prev();if(i.length>0){r=i.attr("id").substr(5)}var s=false;var o=t.item.next();if(o.length>0){s=o.attr("id").substr(5)}jQuery.post(ajaxurl,{action:"simple_page_ordering",id:n,previd:r,nextid:s},update_simple_ordering_callback);var u=document.querySelectorAll("tr.iedit"),a=u.length;while(a--){if(a%2==0){jQuery(u[a]).addClass("alternate")}else{jQuery(u[a]).removeClass("alternate")}}}})
simple-page-ordering.php CHANGED
@@ -3,30 +3,10 @@
3
  Plugin Name: Simple Page Ordering
4
  Plugin URI: http://10up.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. For further instructions, open the "Help" tab on the Pages screen.
6
- Version: 2.0
7
- Author: Jake Goldman, 10up, Oomph
8
  Author URI: http://10up.com
9
  License: GPLv2 or later
10
-
11
- This plug-in is was created by Jake Goldman with original copyright
12
- attributions for purposes of GPL enforcement assigned to Oomph Inc
13
- (pre-1.0). All modifications, updates, and support since February 2011
14
- have been provided by 10up LLC and Jake Goldman from that date forward,
15
- including the near rewrite, version 2.0.
16
-
17
- This program is free software; you can redistribute it and/or modify
18
- it under the terms of the GNU General Public License as published by
19
- the Free Software Foundation; either version 2 of the License, or
20
- (at your option) any later version.
21
-
22
- This program is distributed in the hope that it will be useful,
23
- but WITHOUT ANY WARRANTY; without even the implied warranty of
24
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
- GNU General Public License for more details.
26
-
27
- You should have received a copy of the GNU General Public License
28
- along with this program; if not, write to the Free Software
29
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
  */
31
 
32
  class Simple_Page_Ordering {
@@ -37,13 +17,16 @@ class Simple_Page_Ordering {
37
  }
38
 
39
  public function load_edit_screen() {
40
- if ( ! current_user_can('edit_others_pages') )
 
 
 
 
 
41
  return;
42
 
43
- $screen = get_current_screen();
44
- $sortable = ( post_type_supports( $screen->post_type, 'page-attributes' ) || is_post_type_hierarchical( $screen->post_type ) ); // check permission
45
- $sortable = apply_filters( 'simple_page_ordering_is_sortable', $sortable, $screen->post_type );
46
- if ( ! $sortable )
47
  return;
48
 
49
  add_filter( 'views_' . $screen->id, array( $this, 'sort_by_order_link' ) ); // add view by menu order to views
@@ -52,9 +35,10 @@ class Simple_Page_Ordering {
52
  }
53
 
54
  public function wp() {
55
- if ( strpos( get_query_var('orderby'), 'menu_order' ) === 0 ) { // we can only sort if we're organized by menu order
56
  $script_name = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'simple-page-ordering.dev.js' : 'simple-page-ordering.js';
57
- wp_enqueue_script( 'simple-page-ordering', plugins_url( $script_name, __FILE__ ), array('jquery-ui-sortable'), '2.0', true );
 
58
  }
59
  }
60
 
@@ -68,16 +52,21 @@ class Simple_Page_Ordering {
68
  }
69
 
70
  public function ajax_simple_page_ordering() {
71
- // check permissions again and make sure we have what we need
72
- if ( !current_user_can( 'edit_others_pages' ) || empty( $_POST['id'] ) || ( !isset( $_POST['previd'] ) && !isset( $_POST['nextid'] ) ) )
73
  die(-1);
74
 
75
  // real post?
76
  if ( ! $post = get_post( $_POST['id'] ) )
77
  die(-1);
78
 
 
 
 
 
79
  // badly written plug-in hooks for save post can break things
80
- error_reporting( 0 );
 
81
 
82
  $previd = empty( $_POST['previd'] ) ? false : (int) $_POST['previd'];
83
  $nextid = empty( $_POST['nextid'] ) ? false : (int) $_POST['nextid'];
@@ -91,32 +80,37 @@ class Simple_Page_Ordering {
91
 
92
  // attempt to get the intended parent... if either sibling has a matching parent ID, use that
93
  $parent_id = $post->post_parent;
94
- //$prev_post_parent = $previd ? wp_get_post_parent_id( $previd ) : false;
95
  $next_post_parent = $nextid ? wp_get_post_parent_id( $nextid ) : false;
96
- if ( $previd == $next_post_parent ) { // if the preceding post is the parent of the next most, move it inside
97
  $parent_id = $next_post_parent;
98
  } elseif ( $next_post_parent !== $parent_id ) { // otherwise, if the next post's parent isn't the same as our parent, we need to study
99
  $prev_post_parent = $previd ? wp_get_post_parent_id( $previd ) : false;
100
- if ( $prev_post_parent !== $parent_id ) // if the previous post is not our parent now, make it so!
101
  $parent_id = ( $prev_post_parent !== false ) ? $prev_post_parent : $next_post_parent;
 
102
  }
103
  // if the next post's parent isn't our parent, it might as well be false (irrelevant to our query)
104
  if ( $next_post_parent !== $parent_id )
105
  $nextid = false;
106
 
107
  $max_sortable_posts = (int) apply_filters( 'simple_page_ordering_limit', 50 ); // should reliably be able to do about 50 at a time
108
- if ( $max_sortable_posts < 5 )
109
  $max_sortable_posts = 50;
110
 
 
 
 
 
 
111
  $siblings = new WP_Query(array(
112
  'depth' => 1,
113
  'posts_per_page' => $max_sortable_posts,
114
  'post_type' => $post->post_type,
115
- 'post_status' => array( 'publish' , 'pending', 'draft', 'future', 'private' ),
116
  'post_parent' => $parent_id,
117
  'orderby' => 'menu_order title',
118
  'order' => 'ASC',
119
- 'post__not_in' => array_merge( $excluded ),
120
  'update_post_term_cache' => false,
121
  'update_post_meta_cache' => false,
122
  'suppress_filters' => true,
@@ -129,11 +123,11 @@ class Simple_Page_Ordering {
129
  foreach( $siblings->posts as $sibling ) :
130
 
131
  // don't handle the actual post
132
- if ( $sibling->ID == $post->ID )
133
  continue;
134
 
135
  // if this is the post that comes after our repositioned post, set our repositioned post position and increment menu order
136
- if ( $nextid == $sibling->ID ) {
137
  wp_update_post(array(
138
  'ID' => $post->ID,
139
  'menu_order' => $start,
@@ -200,8 +194,9 @@ class Simple_Page_Ordering {
200
  $children = get_posts(array(
201
  'numberposts' => 1,
202
  'post_type' => $post->post_type,
203
- 'post_status' => array('publish','pending','draft','future','private'),
204
  'post_parent' => $post->ID,
 
205
  'update_post_term_cache' => false,
206
  'update_post_meta_cache' => false,
207
  ));
@@ -222,6 +217,18 @@ class Simple_Page_Ordering {
222
  $views['byorder'] = '<a href="'. $query_string . '" class="' . $class . '">Sort by Order</a>';
223
  return $views;
224
  }
 
 
 
 
 
 
 
 
 
 
 
 
225
  }
226
 
227
  $simple_page_ordering = new Simple_Page_Ordering;
3
  Plugin Name: Simple Page Ordering
4
  Plugin URI: http://10up.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. For further instructions, open the "Help" tab on the Pages screen.
6
+ Version: 2.1
7
+ Author: Jake Goldman, 10up
8
  Author URI: http://10up.com
9
  License: GPLv2 or later
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  */
11
 
12
  class Simple_Page_Ordering {
17
  }
18
 
19
  public function load_edit_screen() {
20
+ $screen = get_current_screen();
21
+ $post_type = $screen->post_type;
22
+
23
+ // is post type sortable?
24
+ $sortable = ( post_type_supports( $post_type, 'page-attributes' ) || is_post_type_hierarchical( $post_type ) ); // check permission
25
+ if ( ! $sortable = apply_filters( 'simple_page_ordering_is_sortable', $sortable, $post_type ) )
26
  return;
27
 
28
+ // does user have the right to manage these post objects?
29
+ if ( ! $this->check_edit_others_caps( $post_type ) )
 
 
30
  return;
31
 
32
  add_filter( 'views_' . $screen->id, array( $this, 'sort_by_order_link' ) ); // add view by menu order to views
35
  }
36
 
37
  public function wp() {
38
+ if ( 0 === strpos( get_query_var('orderby'), 'menu_order' ) ) { // we can only sort if we're organized by menu order
39
  $script_name = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'simple-page-ordering.dev.js' : 'simple-page-ordering.js';
40
+ wp_enqueue_script( 'simple-page-ordering', plugins_url( $script_name, __FILE__ ), array('jquery-ui-sortable'), '2.1', true );
41
+ wp_enqueue_style( 'simple-page-ordering', plugins_url( 'simple-page-ordering.css', __FILE__ ) );
42
  }
43
  }
44
 
52
  }
53
 
54
  public function ajax_simple_page_ordering() {
55
+ // check and make sure we have what we need
56
+ if ( empty( $_POST['id'] ) || ( !isset( $_POST['previd'] ) && !isset( $_POST['nextid'] ) ) )
57
  die(-1);
58
 
59
  // real post?
60
  if ( ! $post = get_post( $_POST['id'] ) )
61
  die(-1);
62
 
63
+ // does user have the right to manage these post objects?
64
+ if ( ! $this->check_edit_others_caps( $post->post_type ) )
65
+ die(-1);
66
+
67
  // badly written plug-in hooks for save post can break things
68
+ if ( !defined( 'WP_DEBUG' ) || !WP_DEBUG )
69
+ error_reporting( 0 );
70
 
71
  $previd = empty( $_POST['previd'] ) ? false : (int) $_POST['previd'];
72
  $nextid = empty( $_POST['nextid'] ) ? false : (int) $_POST['nextid'];
80
 
81
  // attempt to get the intended parent... if either sibling has a matching parent ID, use that
82
  $parent_id = $post->post_parent;
 
83
  $next_post_parent = $nextid ? wp_get_post_parent_id( $nextid ) : false;
84
+ if ( $previd == $next_post_parent ) { // if the preceding post is the parent of the next post, move it inside
85
  $parent_id = $next_post_parent;
86
  } elseif ( $next_post_parent !== $parent_id ) { // otherwise, if the next post's parent isn't the same as our parent, we need to study
87
  $prev_post_parent = $previd ? wp_get_post_parent_id( $previd ) : false;
88
+ if ( $prev_post_parent !== $parent_id ) { // if the previous post is not our parent now, make it so!
89
  $parent_id = ( $prev_post_parent !== false ) ? $prev_post_parent : $next_post_parent;
90
+ }
91
  }
92
  // if the next post's parent isn't our parent, it might as well be false (irrelevant to our query)
93
  if ( $next_post_parent !== $parent_id )
94
  $nextid = false;
95
 
96
  $max_sortable_posts = (int) apply_filters( 'simple_page_ordering_limit', 50 ); // should reliably be able to do about 50 at a time
97
+ if ( $max_sortable_posts < 5 ) // don't be ridiculous!
98
  $max_sortable_posts = 50;
99
 
100
+ // we need to handle all post stati, except trash (in case of custom stati)
101
+ $post_stati = get_post_stati(array(
102
+ 'show_in_admin_all_list' => true,
103
+ ));
104
+
105
  $siblings = new WP_Query(array(
106
  'depth' => 1,
107
  'posts_per_page' => $max_sortable_posts,
108
  'post_type' => $post->post_type,
109
+ 'post_status' => $post_stati,
110
  'post_parent' => $parent_id,
111
  'orderby' => 'menu_order title',
112
  'order' => 'ASC',
113
+ 'post__not_in' => $excluded,
114
  'update_post_term_cache' => false,
115
  'update_post_meta_cache' => false,
116
  'suppress_filters' => true,
123
  foreach( $siblings->posts as $sibling ) :
124
 
125
  // don't handle the actual post
126
+ if ( $sibling->ID === $post->ID )
127
  continue;
128
 
129
  // if this is the post that comes after our repositioned post, set our repositioned post position and increment menu order
130
+ if ( $nextid === $sibling->ID ) {
131
  wp_update_post(array(
132
  'ID' => $post->ID,
133
  'menu_order' => $start,
194
  $children = get_posts(array(
195
  'numberposts' => 1,
196
  'post_type' => $post->post_type,
197
+ 'post_status' => $post_stati,
198
  'post_parent' => $post->ID,
199
+ 'fields' => 'ids',
200
  'update_post_term_cache' => false,
201
  'update_post_meta_cache' => false,
202
  ));
217
  $views['byorder'] = '<a href="'. $query_string . '" class="' . $class . '">Sort by Order</a>';
218
  return $views;
219
  }
220
+
221
+ /**
222
+ * Checks to see if the current user has the capability to "edit others" for a post type
223
+ *
224
+ * @param (string) $post_type Post type name
225
+ * @return (bool) True or false
226
+ */
227
+ public function check_edit_others_caps( $post_type ) {
228
+ $post_type_object = get_post_type_object( $post_type );
229
+ $edit_others_cap = empty( $post_type_object ) ? 'edit_others_' . $post_type . 's' : $post_type_object->cap->edit_others_posts;
230
+ return apply_filters( 'simple_page_ordering_edit_rights', current_user_can( $edit_others_cap ), $post_type );
231
+ }
232
  }
233
 
234
  $simple_page_ordering = new Simple_Page_Ordering;