Simple Page Ordering - Version 2.3.3

Version Description

  • Added: Nonce verify for AJAX requests (props @williampatton, @dtbaker)
  • Changed: Disable Post Revisions now using the correct action of post_updated (props @blue-liquid-designs)
  • Changed: Bump WordPress version "tested up to" 5.3 (props @adamsilverstein, @dinhtungdu)
  • Changed: Documentation updates (props @jeffpaul)
  • Fixed: Mismatched localized data variable name (props @dinhtungdu)
  • Fixed: VIP Go coding standards (props @mrasharirfan, @dinhtungdu, @pereirinha, @brentvr)
Download this release

Release Info

Developer 10upbot
Plugin Icon 128x128 Simple Page Ordering
Version 2.3.3
Comparing to
See all releases

Code changes from version 2.3.2 to 2.3.3

assets/js/simple-page-ordering.min.js CHANGED
@@ -1 +1 @@
1
- function update_simple_ordering_callback(e){if("children"!==e){var t=jQuery.parseJSON(e),r=t.new_pos;for(var n in r)if("next"!==n){var a=document.getElementById("inline_"+n);if(null!==a&&r.hasOwnProperty(n)){var o=a.querySelector(".menu_order");if(void 0!==r[n].menu_order){null!==o&&(o.innerHTML=r[n].menu_order);var l=a.querySelector(".post_parent");null!==l&&(l.innerHTML=r[n].post_parent);var i=null,s=a.querySelector(".post_title");null!==s&&(i=s.innerHTML);for(var d=0;d<r[n].depth;)i="&mdash; "+i,d++;var p=a.parentNode.querySelector(".row-title");null!==p&&null!==i&&(p.innerHTML=i)}else null!==o&&(o.innerHTML=r[n])}}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:JSON.stringify(t.next.excluded)},update_simple_ordering_callback):(jQuery(".spo-updating-row").removeClass("spo-updating-row").find(".check-column").removeClass("spinner is-active"),sortable_post_table.removeClass("spo-updating").sortable("enable"))}else window.location.reload()}var sortable_post_table=jQuery(".wp-list-table tbody");sortable_post_table.sortable({items:"> tr",cursor:"move",axis:"y",containment:"table.widefat",cancel:"input, textarea, button, select, option, .inline-edit-row",distance:2,opacity:.8,tolerance:"pointer",create:function(){jQuery(document).keydown(function(e){var t=e.key||e.keyCode;"Escape"!==t&&"Esc"!==t&&27!==t||(sortable_post_table.sortable("option","preventUpdate",!0),sortable_post_table.sortable("cancel"))})},start:function(e,t){"undefined"!=typeof inlineEditPost&&inlineEditPost.revert(),t.placeholder.height(t.item.height()),t.placeholder.empty()},helper:function(e,t){for(var r=t.children(),n=0;n<r.length;n++){var a=jQuery(r[n]);a.width(a.width())}return t},stop:function(e,t){sortable_post_table.sortable("option","preventUpdate")&&sortable_post_table.sortable("option","preventUpdate",!1),t.item.children().css("width","")},update:function(e,t){if(sortable_post_table.sortable("option","preventUpdate"))sortable_post_table.sortable("option","preventUpdate",!1);else{sortable_post_table.sortable("disable").addClass("spo-updating"),t.item.addClass("spo-updating-row"),t.item.find(".check-column").addClass("spinner is-active");var r=t.item[0].id.substr(5),n=!1,a=t.item.prev();a.length>0&&(n=a.attr("id").substr(5));var o=!1,l=t.item.next();l.length>0&&(o=l.attr("id").substr(5)),jQuery.post(ajaxurl,{action:"simple_page_ordering",id:r,previd:n,nextid:o},update_simple_ordering_callback);for(var i=document.querySelectorAll("tr.iedit"),s=i.length;s--;)0==s%2?jQuery(i[s]).addClass("alternate"):jQuery(i[s]).removeClass("alternate")}}});
1
+ function update_simple_ordering_callback(e){if("children"!==e){var t=jQuery.parseJSON(e),r=t.new_pos;for(var n in r)if("next"!==n){var a=document.getElementById("inline_"+n);if(null!==a&&r.hasOwnProperty(n)){var o=a.querySelector(".menu_order");if(void 0!==r[n].menu_order){null!==o&&(o.textContent=r[n].menu_order);var l=a.querySelector(".post_parent");null!==l&&(l.textContent=r[n].post_parent);var i=null,s=a.querySelector(".post_title");null!==s&&(i=s.innerHTML);for(var d=0;d<r[n].depth;)i="&mdash; "+i,d++;var p=a.parentNode.querySelector(".row-title");null!==p&&null!==i&&(p.textContent=i)}else null!==o&&(o.textContent=r[n])}}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,_wpnonce:simple_page_ordering_localized_data._wpnonce,screen_id:simple_page_ordering_localized_data.screen_id,excluded:JSON.stringify(t.next.excluded)},update_simple_ordering_callback):(jQuery(".spo-updating-row").removeClass("spo-updating-row").find(".check-column").removeClass("spinner is-active"),sortable_post_table.removeClass("spo-updating").sortable("enable"))}else window.location.reload()}var sortable_post_table=jQuery(".wp-list-table tbody");sortable_post_table.sortable({items:"> tr",cursor:"move",axis:"y",containment:"table.widefat",cancel:"input, textarea, button, select, option, .inline-edit-row",distance:2,opacity:.8,tolerance:"pointer",create:function(){jQuery(document).keydown(function(e){var t=e.key||e.keyCode;"Escape"!==t&&"Esc"!==t&&27!==t||(sortable_post_table.sortable("option","preventUpdate",!0),sortable_post_table.sortable("cancel"))})},start:function(e,t){"undefined"!=typeof inlineEditPost&&inlineEditPost.revert(),t.placeholder.height(t.item.height()),t.placeholder.empty()},helper:function(e,t){for(var r=t.children(),n=0;n<r.length;n++){var a=jQuery(r[n]);a.width(a.width())}return t},stop:function(e,t){sortable_post_table.sortable("option","preventUpdate")&&sortable_post_table.sortable("option","preventUpdate",!1),t.item.children().css("width","")},update:function(e,t){if(sortable_post_table.sortable("option","preventUpdate"))sortable_post_table.sortable("option","preventUpdate",!1);else{sortable_post_table.sortable("disable").addClass("spo-updating"),t.item.addClass("spo-updating-row"),t.item.find(".check-column").addClass("spinner is-active");var r=t.item[0].id.substr(5),n=!1,a=t.item.prev();0<a.length&&(n=a.attr("id").substr(5));var o=!1,l=t.item.next();0<l.length&&(o=l.attr("id").substr(5)),jQuery.post(ajaxurl,{action:"simple_page_ordering",id:r,previd:n,nextid:o,_wpnonce:simple_page_ordering_localized_data._wpnonce,screen_id:simple_page_ordering_localized_data.screen_id},update_simple_ordering_callback);for(var i=document.querySelectorAll("tr.iedit"),s=i.length;s--;)0==s%2?jQuery(i[s]).addClass("alternate"):jQuery(i[s]).removeClass("alternate")}}});
assets/js/src/simple-page-ordering.js CHANGED
@@ -18,12 +18,12 @@ function update_simple_ordering_callback(response) {
18
 
19
  if ( undefined !== new_pos[key]['menu_order'] ) {
20
  if ( null !== dom_menu_order ) {
21
- dom_menu_order.innerHTML = new_pos[key]['menu_order'];
22
  }
23
 
24
  var dom_post_parent = inline_key.querySelector('.post_parent');
25
  if ( null !== dom_post_parent ) {
26
- dom_post_parent.innerHTML = new_pos[key]['post_parent'];
27
  }
28
 
29
  var post_title = null;
@@ -39,10 +39,10 @@ function update_simple_ordering_callback(response) {
39
  }
40
  var dom_row_title = inline_key.parentNode.querySelector('.row-title');
41
  if ( null !== dom_row_title && null !== post_title ) {
42
- dom_row_title.innerHTML = post_title;
43
  }
44
  } else if ( null !== dom_menu_order ) {
45
- dom_menu_order.innerHTML = new_pos[key];
46
  }
47
  }
48
  }
@@ -54,6 +54,8 @@ function update_simple_ordering_callback(response) {
54
  previd: changes.next['previd'],
55
  nextid: changes.next['nextid'],
56
  start: changes.next['start'],
 
 
57
  excluded: JSON.stringify( changes.next['excluded'] )
58
  }, update_simple_ordering_callback );
59
  } else {
@@ -129,7 +131,7 @@ sortable_post_table.sortable({
129
  }
130
 
131
  // go do the sorting stuff via ajax
132
- jQuery.post( ajaxurl, { action: 'simple_page_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, update_simple_ordering_callback );
133
 
134
  // fix cell colors
135
  var table_rows = document.querySelectorAll('tr.iedit'),
18
 
19
  if ( undefined !== new_pos[key]['menu_order'] ) {
20
  if ( null !== dom_menu_order ) {
21
+ dom_menu_order.textContent = new_pos[key]['menu_order'];
22
  }
23
 
24
  var dom_post_parent = inline_key.querySelector('.post_parent');
25
  if ( null !== dom_post_parent ) {
26
+ dom_post_parent.textContent = new_pos[key]['post_parent'];
27
  }
28
 
29
  var post_title = null;
39
  }
40
  var dom_row_title = inline_key.parentNode.querySelector('.row-title');
41
  if ( null !== dom_row_title && null !== post_title ) {
42
+ dom_row_title.textContent = post_title;
43
  }
44
  } else if ( null !== dom_menu_order ) {
45
+ dom_menu_order.textContent = new_pos[key];
46
  }
47
  }
48
  }
54
  previd: changes.next['previd'],
55
  nextid: changes.next['nextid'],
56
  start: changes.next['start'],
57
+ _wpnonce: simple_page_ordering_localized_data._wpnonce,
58
+ screen_id: simple_page_ordering_localized_data.screen_id,
59
  excluded: JSON.stringify( changes.next['excluded'] )
60
  }, update_simple_ordering_callback );
61
  } else {
131
  }
132
 
133
  // go do the sorting stuff via ajax
134
+ jQuery.post( ajaxurl, { action: 'simple_page_ordering', id: postid, previd: prevpostid, nextid: nextpostid, _wpnonce: simple_page_ordering_localized_data._wpnonce, screen_id: simple_page_ordering_localized_data.screen_id, }, update_simple_ordering_callback );
135
 
136
  // fix cell colors
137
  var table_rows = document.querySelectorAll('tr.iedit'),
readme.txt CHANGED
@@ -3,14 +3,16 @@ Contributors: 10up, jakemgold, welcher, helen, 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.8
6
- Tested up to: 5.0.3
7
- Stable tag: 2.3.2
 
 
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
 
@@ -60,13 +62,13 @@ This plug-in doesn't change any *behavior* on the front end, it simply changes t
60
 
61
  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).
62
 
63
- = I reordered my content, it seemed to work, but when I refreshed, it went back to the old order! =
64
 
65
  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:
66
 
67
  `add_filter( 'simple_page_ordering_limit', function($number) { return 5; } );`
68
 
69
- 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.
70
 
71
  = What happened to the drop down box that let me change the number of items on each page in the admin?? =
72
 
@@ -81,97 +83,104 @@ This feature is already built into WordPress natively, but a bit tucked away. If
81
 
82
  == Changelog ==
83
 
 
 
 
 
 
 
 
 
84
  = 2.3.2 =
85
- * Enhancement: Allow cancellation of drag operation by pressing escape key
86
- * Bug fix: Allow form input elements added to a row by plugins to be interacted with
87
 
88
  = 2.3.1 =
89
- * Bug fix: Prevent rows with hidden columns from jumping around while dragging
90
 
91
- = 2.3 =
92
- * Avoid exceeding PHP's max input variables, which could cause incorrectly assigned page order
93
- * Fix a malformed URL that would take you to posts instead of pages
94
- * Use `WP_Query` instead of `get_posts()` for better performance
95
- * Use WordPress core's spinner class
96
- * Add Grunt-based build process with Sass
97
- * Remove bundled translations in favor of WordPress.org language packs
98
- * Fix some PHPDoc and coding standards to align with 10up's Engineering Best Practices
99
 
100
  = 2.2.4 =
101
- * Fixed redundant URL encoding when sorting in admin page list
102
 
103
  = 2.2.3 =
104
- * Fixed ordering in WordPress 4.0 following core changes to ORDER BY in WP_Query
105
 
106
  = 2.2.2 =
107
- * Column widths no longer change when dragging a row (partial props griffinjt)
108
- * Closed obscure XSS vulnerability related to Sort by Order link (props simon-waters)
109
- * Add German localization (props glueckpress).
110
 
111
  = 2.2.1 =
112
- * Bring back translations / text domain (yikes!)
113
- * Add Brazilian translation
114
- * Props to "felds"
115
 
116
- = 2.2 =
117
- * Updated look and feel to better match WordPress 3.8 admin redesign
118
- * Improved awareness of and compatibility with Quick Edit (inline editor)
119
- * Prevent collisions with themes and plugins bundling Simple Page Ordering
120
 
121
  = 2.1.2 =
122
- * Bug fix: hierarchical custom post types without page-attributes was still broken - doh!
123
- * Bug fix: extreme edge case where post columns did not include the post title now supported
124
 
125
  = 2.1.1 =
126
- * Bug fix: custom post types with page-attributes or hierarchical properties, but not both, breaking ordering
127
-
128
- = 2.1 =
129
- * 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
130
- * Major JavaScript refactoring and simplification (combined with new stylesheet) for better performance
131
- * 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)
132
- * Awareness of custom post statuses (so they are not skipped during backend ordering operation)
133
-
134
- = 2.0 =
135
- * Drag pages into any part of the page hierarchy! No longer limited to same branch of tree!
136
- * Big performance improvements under the hood: leaner queries, batched requests, less processing
137
- * Scales much more reliably in situations with very high page counts due to batching of requests
138
- * 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)
139
- * Removed "number of pages" drop down, which is repetitive of a field accessible under Screen Options
140
- * New filters and hooks to extend / override default functionality
141
- * Improved compatibility with newer versions of WordPress
142
-
143
- = 1.0 =
144
- * Fix unexpected page ordering results when pages have not been explictly ordered yet (sorts by menu_order, then title, not just menu_order)
145
- * Support for ordering non-hierarchical post types that have "page-attributes" support
146
- * New filter link for "Sort by Order" to restore (hierarchical) or set (non-hierarchical, page attributes support) post list sort to menu order
147
- * Fix "per page" drop down filter selection not saving between page loads (was broken in 3.1)
148
- * Users are now forced to wait for current sort operation to finish before they can sort another item
149
- * Smarter about "not sortable" view states
150
- * Localization ready! Rough Spanish translation included.
151
- * Items are always ordered with positive integers (potential negative sort orders had some performance benefits in last version, but sometimes caused issues)
152
- * Assorted other performance and code improvements
153
 
154
  = 0.9.6 =
155
- * Fix for broken inline editing (quick edit) fields in Firefox
156
 
157
  = 0.9.5 =
158
- * Smarter awareness of "sorted" modes in WordPress 3.1 (can only use when sorted by menu order)
159
- * Smarter awareness of "quick edit" mode (can't drag)
160
- * Generally simplified / better organized code
161
 
162
- = 0.9 =
163
- * Fix page count display always showing "0" on non-hierarchical post types (Showing 1-X of X)
164
- * Fix hidden menu order not updating after sort (causing Quick Edit to reset order when used right after sorting)
165
- * "Move" cursor only set if JavaScript enabled
166
- * Added further directions in the plug-in description (some users were confused about how to use it)
167
- * Basic compatibility with 3.1 RC (prevent clashes with post list sorting)
168
 
169
  = 0.8.4 =
170
- * Loosened constraints on drag and drop to ease dropping into top and bottom position
171
- * Fixed row background staying "white" after dropping into a new position
172
- * Fixed double border on the bottom of the row while dragging
173
- * Improved some terminology (with custom post types in mind)
174
 
175
  = 0.8.2 =
176
- * Simplified code - consolidated hooks
177
- * Updated version requirements
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.8
6
+ Tested up to: 5.3
7
+ Stable tag: 2.3.3
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Order your pages and other hierarchical post types with simple drag and drop right from the standard page list.
12
 
13
  == Description ==
14
 
15
+ 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.
16
 
17
  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.
18
 
62
 
63
  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).
64
 
65
+ = I reordered my content, it seemed to work, but when I refreshed, it went back to the old order! =
66
 
67
  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:
68
 
69
  `add_filter( 'simple_page_ordering_limit', function($number) { return 5; } );`
70
 
71
+ 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.
72
 
73
  = What happened to the drop down box that let me change the number of items on each page in the admin?? =
74
 
83
 
84
  == Changelog ==
85
 
86
+ = 2.3.3 =
87
+ * **Added:** Nonce verify for AJAX requests (props [@williampatton](https://profiles.wordpress.org/williampatton/), [@dtbaker](https://profiles.wordpress.org/dtbaker/))
88
+ * **Changed:** Disable Post Revisions now using the correct action of `post_updated` (props [@blue-liquid-designs](https://profiles.wordpress.org/blue-liquid-designs/))
89
+ * **Changed:** Bump WordPress version "tested up to" 5.3 (props [@adamsilverstein](https://profiles.wordpress.org/adamsilverstein/), [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/))
90
+ * **Changed:** Documentation updates (props [@jeffpaul](https://profiles.wordpress.org/jeffpaul/))
91
+ * **Fixed:** Mismatched localized data variable name (props [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/))
92
+ * **Fixed:** VIP Go coding standards (props [@mrasharirfan](https://profiles.wordpress.org/mrasharirfan/), [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/), [@pereirinha](https://profiles.wordpress.org/pereirinha/), [@brentvr](https://profiles.wordpress.org/brentvr/))
93
+
94
  = 2.3.2 =
95
+ * **Added:** Allow cancellation of drag operation by pressing escape key
96
+ * **Fixed:** Allow form input elements added to a row by plugins to be interacted with
97
 
98
  = 2.3.1 =
99
+ * **Fixed:** Prevent rows with hidden columns from jumping around while dragging
100
 
101
+ = 2.3.0 =
102
+ * **Added:** Use WordPress core's spinner class
103
+ * **Added:** Grunt-based build process with Sass
104
+ * **Changed:** Use `WP_Query` instead of `get_posts()` for better performance
105
+ * **Changed:** Remove bundled translations in favor of WordPress.org language packs
106
+ * **Fixed:** Avoid exceeding PHP's max input variables, which could cause incorrectly assigned page order
107
+ * **Fixed:** Malformed URL that would take you to posts instead of pages
108
+ * **Fixed:** PHPDoc and coding standards to align with 10up's Engineering Best Practices
109
 
110
  = 2.2.4 =
111
+ * **Fixed:** Redundant URL encoding when sorting in admin page list
112
 
113
  = 2.2.3 =
114
+ * **Fixed:** Ordering in WordPress 4.0 following core changes to `ORDER BY` in `WP_Query`
115
 
116
  = 2.2.2 =
117
+ * **Added:** German localization (props [@glueckpress](https://profiles.wordpress.org/glueckpress/))
118
+ * **Fixed:** Column widths no longer change when dragging a row (partial props [@griffinjt](https://profiles.wordpress.org/griffinjt/))
119
+ * **Security:** Closed obscure XSS vulnerability related to Sort by Order link (props [@simon-waters](https://profiles.wordpress.org/simon-waters/))
120
 
121
  = 2.2.1 =
122
+ * **Added:** Brazilian translation (props [@felds](https://profiles.wordpress.org/felds/))
123
+ * **Fixed:** Bring back translations / text domain (yikes!)
 
124
 
125
+ = 2.2.0 =
126
+ * **Changed:** Look and feel to better match WordPress 3.8 admin redesign
127
+ * **Changed:** Improved awareness of and compatibility with Quick Edit (inline editor)
128
+ * **Fixed:** Prevent collisions with themes and plugins bundling Simple Page Ordering
129
 
130
  = 2.1.2 =
131
+ * **Fixed:** Hierarchical custom post types without page-attributes was still broken - doh!
132
+ * **Fixed:** Extreme edge case where post columns did not include the post title now supported
133
 
134
  = 2.1.1 =
135
+ * **Fixed:** custom post types with page-attributes or hierarchical properties, but not both, breaking ordering
136
+
137
+ = 2.1.0 =
138
+ * **Added:** 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)
139
+ * **Added:** Awareness of custom post statuses (so they are not skipped during backend ordering operation)
140
+ * **Changed:** 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
141
+ * **Changed:** Major JavaScript refactoring and simplification (combined with new stylesheet) for better performance
142
+
143
+ = 2.0.0 =
144
+ * **Added:** Drag pages into any part of the page hierarchy! No longer limited to same branch of tree!
145
+ * **Added:** Big performance improvements under the hood: leaner queries, batched requests, less processing
146
+ * **Added:** New filters and hooks to extend / override default functionality
147
+ * **Changed:** Scales much more reliably in situations with very high page counts due to batching of requests
148
+ * **Changed:** 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)
149
+ * **Changed:** Removed "number of pages" drop down, which is repetitive of a field accessible under Screen Options
150
+ * **Changed:** Improved compatibility with newer versions of WordPress
151
+
152
+ = 1.0.0 =
153
+ * **Added:** Support for ordering non-hierarchical post types that have "page-attributes" support
154
+ * **Added:** New filter link for "Sort by Order" to restore (hierarchical) or set (non-hierarchical, page attributes support) post list sort to menu order
155
+ * **Changed:** Users are now forced to wait for current sort operation to finish before they can sort another item
156
+ * **Changed:** Smarter about "not sortable" view states
157
+ * **Changed:** Localization ready! Rough Spanish translation included.
158
+ * **Changed:** Assorted other performance and code improvements
159
+ * **Fixed:** Unexpected page ordering results when pages have not been explictly ordered yet (sorts by menu_order, then title, not just menu_order)
160
+ * **Fixed:** "Per page" drop down filter selection not saving between page loads (was broken in 3.1)
161
+ * **Fixed:** Items are always ordered with positive integers (potential negative sort orders had some performance benefits in last version, but sometimes caused issues)
162
 
163
  = 0.9.6 =
164
+ * **Fixed:** for broken inline editing (quick edit) fields in Firefox
165
 
166
  = 0.9.5 =
167
+ * **Changed:** Smarter awareness of "sorted" modes in WordPress 3.1 (can only use when sorted by menu order)
168
+ * **Changed:** Smarter awareness of "quick edit" mode (can't drag)
169
+ * **Changed:** Generally simplified / better organized code
170
 
171
+ = 0.9.0 =
172
+ * **Added:** Further directions in the plug-in description (some users were confused about how to use it)
173
+ * **Added:** Basic compatibility with 3.1 RC (prevent clashes with post list sorting)
174
+ * **Changed:** "Move" cursor only set if JavaScript enabled
175
+ * **Fixed:** Page count display always showing "0" on non-hierarchical post types (Showing 1-X of X)
176
+ * **Fixed:** Hidden menu order not updating after sort (causing Quick Edit to reset order when used right after sorting)
177
 
178
  = 0.8.4 =
179
+ * **Changed:** Loosened constraints on drag and drop to ease dropping into top and bottom position
180
+ * **Changed:** Improved some terminology (with custom post types in mind)
181
+ * **Fixed:** Row background staying "white" after dropping into a new position
182
+ * **Fixed:** Double border on the bottom of the row while dragging
183
 
184
  = 0.8.2 =
185
+ * **Changed:** Simplified code - consolidated hooks
186
+ * **Changed:** Updated version requirements
simple-page-ordering.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
2
- /*
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.3.2
7
- Author: Jake Goldman, 10up
8
- Author URI: http://10up.com
9
- License: GPLv2 or later
10
- Text Domain: simple-page-ordering
11
- */
 
 
12
 
13
  if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
14
 
@@ -63,7 +65,8 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
63
 
64
  // is post type sortable?
65
  $sortable = ( post_type_supports( $post_type, 'page-attributes' ) || is_post_type_hierarchical( $post_type ) ); // check permission
66
- if ( ! $sortable = apply_filters( 'simple_page_ordering_is_sortable', $sortable, $post_type ) ) {
 
67
  return;
68
  }
69
 
@@ -85,9 +88,18 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
85
  */
86
  public static function wp() {
87
  $orderby = get_query_var( 'orderby' );
 
88
  if ( ( is_string( $orderby ) && 0 === strpos( $orderby, 'menu_order' ) ) || ( isset( $orderby['menu_order'] ) && 'ASC' === $orderby['menu_order'] ) ) {
89
  $script_name = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '/assets/js/src/simple-page-ordering.js' : '/assets/js/simple-page-ordering.min.js';
90
  wp_enqueue_script( 'simple-page-ordering', plugins_url( $script_name, __FILE__ ), array( 'jquery-ui-sortable' ), '2.1', true );
 
 
 
 
 
 
 
 
91
  wp_enqueue_style( 'simple-page-ordering', plugins_url( '/assets/css/simple-page-ordering.css', __FILE__ ) );
92
  }
93
  }
@@ -110,8 +122,17 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
110
  die( - 1 );
111
  }
112
 
 
 
 
 
 
 
 
 
113
  // real post?
114
- if ( ! $post = get_post( $_POST['id'] ) ) {
 
115
  die( - 1 );
116
  }
117
 
@@ -120,9 +141,9 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
120
  die( - 1 );
121
  }
122
 
123
- // badly written plug-in hooks for save post can break things
124
  if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
125
- error_reporting( 0 );
126
  }
127
 
128
  global $wp_version;
@@ -130,7 +151,7 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
130
  $previd = empty( $_POST['previd'] ) ? false : (int) $_POST['previd'];
131
  $nextid = empty( $_POST['nextid'] ) ? false : (int) $_POST['nextid'];
132
  $start = empty( $_POST['start'] ) ? 1 : (int) $_POST['start'];
133
- $excluded = empty( $_POST['excluded'] ) ? array( $post->ID ) : array_filter( (array) json_decode( $_POST['excluded'] ), 'intval' );
134
 
135
  $new_pos = array(); // store new positions for ajax
136
  $return_data = new stdClass;
@@ -140,7 +161,7 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
140
  // attempt to get the intended parent... if either sibling has a matching parent ID, use that
141
  $parent_id = $post->post_parent;
142
  $next_post_parent = $nextid ? wp_get_post_parent_id( $nextid ) : false;
143
- if ( $previd == $next_post_parent ) { // if the preceding post is the parent of the next post, move it inside
144
  $parent_id = $next_post_parent;
145
  } elseif ( $next_post_parent !== $parent_id ) { // otherwise, if the next post's parent isn't the same as our parent, we need to study
146
  $prev_post_parent = $previd ? wp_get_post_parent_id( $previd ) : false;
@@ -173,22 +194,27 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
173
  'menu_order' => 'ASC',
174
  'title' => 'ASC',
175
  ),
176
- 'post__not_in' => $excluded,
177
  'update_post_term_cache' => false,
178
  'update_post_meta_cache' => false,
179
- 'suppress_filters' => true,
180
  'ignore_sticky_posts' => true,
181
  );
 
182
  if ( version_compare( $wp_version, '4.0', '<' ) ) {
183
  $siblings_query['orderby'] = 'menu_order title';
184
  $siblings_query['order'] = 'ASC';
185
  }
 
186
  $siblings = new WP_Query( $siblings_query ); // fetch all the siblings (relative ordering)
187
 
188
  // don't waste overhead of revisions on a menu order change (especially since they can't *all* be rolled back at once)
189
- remove_action( 'pre_post_update', 'wp_save_post_revision' );
190
 
191
  foreach ( $siblings->posts as $sibling ) :
 
 
 
 
192
 
193
  // don't handle the actual post
194
  if ( $sibling->ID === $post->ID ) {
@@ -218,7 +244,7 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
218
  }
219
 
220
  // set the menu order of the current sibling and increment the menu order
221
- if ( $sibling->menu_order != $start ) {
222
  wp_update_post( array(
223
  'ID' => $sibling->ID,
224
  'menu_order' => $start,
@@ -227,7 +253,7 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
227
  $new_pos[ $sibling->ID ] = $start;
228
  $start ++;
229
 
230
- if ( ! $nextid && $previd == $sibling->ID ) {
231
  wp_update_post( array(
232
  'ID' => $post->ID,
233
  'menu_order' => $start,
@@ -281,7 +307,7 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
281
  }
282
 
283
  $return_data->new_pos = $new_pos;
284
- die( json_encode( $return_data ) );
285
  }
286
 
287
  /**
@@ -292,7 +318,7 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
292
  * @return array
293
  */
294
  public static function sort_by_order_link( $views ) {
295
- $class = ( get_query_var( 'orderby' ) == 'menu_order title' ) ? 'current' : '';
296
  $query_string = remove_query_arg( array( 'orderby', 'order' ) );
297
  if ( ! is_post_type_hierarchical( get_post_type() ) ) {
298
  $query_string = add_query_arg( 'orderby', 'menu_order title', $query_string );
1
  <?php
2
+ /**
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.3.3
7
+ * Requires at least: 3.8
8
+ * Author: Jake Goldman, 10up
9
+ * Author URI: https://10up.com
10
+ * License: GPLv2 or later
11
+ * License URI: https://www.gnu.org/licenses/gpl-2.0.html
12
+ * Text Domain: simple-page-ordering
13
+ */
14
 
15
  if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
16
 
65
 
66
  // is post type sortable?
67
  $sortable = ( post_type_supports( $post_type, 'page-attributes' ) || is_post_type_hierarchical( $post_type ) ); // check permission
68
+ $sortable = apply_filters( 'simple_page_ordering_is_sortable', $sortable, $post_type );
69
+ if ( ! $sortable ) {
70
  return;
71
  }
72
 
88
  */
89
  public static function wp() {
90
  $orderby = get_query_var( 'orderby' );
91
+ $screen = get_current_screen();
92
  if ( ( is_string( $orderby ) && 0 === strpos( $orderby, 'menu_order' ) ) || ( isset( $orderby['menu_order'] ) && 'ASC' === $orderby['menu_order'] ) ) {
93
  $script_name = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '/assets/js/src/simple-page-ordering.js' : '/assets/js/simple-page-ordering.min.js';
94
  wp_enqueue_script( 'simple-page-ordering', plugins_url( $script_name, __FILE__ ), array( 'jquery-ui-sortable' ), '2.1', true );
95
+ wp_localize_script(
96
+ 'simple-page-ordering',
97
+ 'simple_page_ordering_localized_data',
98
+ array(
99
+ '_wpnonce' => wp_create_nonce( 'simple-page-ordering_' . $screen->id ),
100
+ 'screen_id' => (string) $screen->id,
101
+ )
102
+ );
103
  wp_enqueue_style( 'simple-page-ordering', plugins_url( '/assets/css/simple-page-ordering.css', __FILE__ ) );
104
  }
105
  }
122
  die( - 1 );
123
  }
124
 
125
+ // do we have a nonce that verifies?
126
+ if ( empty( $_POST['_wpnonce'] ) || empty( $_POST['screen_id'] ) ) {
127
+ // no nonce to verify...
128
+ die( -1 );
129
+ }
130
+
131
+ check_admin_referer( 'simple-page-ordering_' . sanitize_key( $_POST['screen_id'] ) );
132
+
133
  // real post?
134
+ $post = empty( $_POST['id'] ) ? false : get_post( (int) $_POST['id'] );
135
+ if ( ! $post ) {
136
  die( - 1 );
137
  }
138
 
141
  die( - 1 );
142
  }
143
 
144
+ // Badly written plug-in hooks for save post can break things.
145
  if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
146
+ error_reporting( 0 ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting
147
  }
148
 
149
  global $wp_version;
151
  $previd = empty( $_POST['previd'] ) ? false : (int) $_POST['previd'];
152
  $nextid = empty( $_POST['nextid'] ) ? false : (int) $_POST['nextid'];
153
  $start = empty( $_POST['start'] ) ? 1 : (int) $_POST['start'];
154
+ $excluded = empty( $_POST['excluded'] ) ? array( $post->ID ) : array_filter( (array) json_decode( $_POST['excluded'] ), 'intval' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
155
 
156
  $new_pos = array(); // store new positions for ajax
157
  $return_data = new stdClass;
161
  // attempt to get the intended parent... if either sibling has a matching parent ID, use that
162
  $parent_id = $post->post_parent;
163
  $next_post_parent = $nextid ? wp_get_post_parent_id( $nextid ) : false;
164
+ if ( $previd === $next_post_parent ) { // if the preceding post is the parent of the next post, move it inside
165
  $parent_id = $next_post_parent;
166
  } elseif ( $next_post_parent !== $parent_id ) { // otherwise, if the next post's parent isn't the same as our parent, we need to study
167
  $prev_post_parent = $previd ? wp_get_post_parent_id( $previd ) : false;
194
  'menu_order' => 'ASC',
195
  'title' => 'ASC',
196
  ),
 
197
  'update_post_term_cache' => false,
198
  'update_post_meta_cache' => false,
199
+ 'suppress_filters' => true, // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.SuppressFiltersTrue
200
  'ignore_sticky_posts' => true,
201
  );
202
+
203
  if ( version_compare( $wp_version, '4.0', '<' ) ) {
204
  $siblings_query['orderby'] = 'menu_order title';
205
  $siblings_query['order'] = 'ASC';
206
  }
207
+
208
  $siblings = new WP_Query( $siblings_query ); // fetch all the siblings (relative ordering)
209
 
210
  // don't waste overhead of revisions on a menu order change (especially since they can't *all* be rolled back at once)
211
+ remove_action( 'post_updated', 'wp_save_post_revision' );
212
 
213
  foreach ( $siblings->posts as $sibling ) :
214
+ // Skip the excluded posts.
215
+ if ( in_array( $sibling->ID, $excluded, true ) ) {
216
+ continue;
217
+ }
218
 
219
  // don't handle the actual post
220
  if ( $sibling->ID === $post->ID ) {
244
  }
245
 
246
  // set the menu order of the current sibling and increment the menu order
247
+ if ( $sibling->menu_order !== $start ) {
248
  wp_update_post( array(
249
  'ID' => $sibling->ID,
250
  'menu_order' => $start,
253
  $new_pos[ $sibling->ID ] = $start;
254
  $start ++;
255
 
256
+ if ( ! $nextid && $previd === $sibling->ID ) {
257
  wp_update_post( array(
258
  'ID' => $post->ID,
259
  'menu_order' => $start,
307
  }
308
 
309
  $return_data->new_pos = $new_pos;
310
+ die( wp_json_encode( $return_data ) );
311
  }
312
 
313
  /**
318
  * @return array
319
  */
320
  public static function sort_by_order_link( $views ) {
321
+ $class = ( get_query_var( 'orderby' ) === 'menu_order title' ) ? 'current' : '';
322
  $query_string = remove_query_arg( array( 'orderby', 'order' ) );
323
  if ( ! is_post_type_hierarchical( get_post_type() ) ) {
324
  $query_string = add_query_arg( 'orderby', 'menu_order title', $query_string );