Simple Page Ordering - Version 2.4.0

Version Description

  • 2022-04-28 =
  • Added: REST API for reordering posts: /wp-json/simplepageordering/v1/ (props @rmccue, @ciprianimike, @cadic, @lkraav, @dinhtungdu).
  • Added: REST Endpoint Documentation.
  • Added: Documentation to exclude post types (props @dzulfriday @dinhtungdu, @jeffpaul).
  • Added: PHP8 compatibility testing GitHub Action (props @nomnom99, @dharm1025).
  • Added: Cypress E2E tests (props @dinhtungdu, @dharm1025, @faisal03).
  • Added: Dependency security scanning GitHub Action (props @jeffpaul, @nomnom99).
  • Changed: PLUGIN_VERSION to SIMPLE_PAGE_ORDERING_VERSION (props @dinhtungdu, @dkotter).
  • Changed: Bump WordPress "tested up to" version to 5.9 (props @ankitguptaindia, @phpbits, @sudip-10up).
  • Security: Bump rmccue/requests from 1.7.0 to 1.8.0 (props @dependabot).
  • Security: Bump async from 2.6.3 to 2.6.4 (props @dependabot).
Download this release

Release Info

Developer 10up
Plugin Icon 128x128 Simple Page Ordering
Version 2.4.0
Comparing to
See all releases

Code changes from version 2.3.4 to 2.4.0

Files changed (4) hide show
  1. .phpcs.xml.dist +4 -0
  2. composer.json +0 -26
  3. readme.txt +135 -108
  4. simple-page-ordering.php +185 -40
.phpcs.xml.dist ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <ruleset name="Project Rules">
3
+ <rule ref="10up-Default" />
4
+ </ruleset>
composer.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "name": "10up/simple-page-ordering",
3
- "description": "Order your pages and other hierarchical post types with simple drag and drop right from the standard page list.",
4
- "version": "2.3.4",
5
- "type": "wordpress-plugin",
6
- "keywords": [
7
- "wordpress",
8
- "10up"
9
- ],
10
- "homepage": "https://github.com/10up/simple-page-ordering",
11
- "license": "GPLv2",
12
- "authors": [
13
- {
14
- "name": "10up",
15
- "homepage": "https://10up.com/"
16
- }
17
- ],
18
- "support": {
19
- "issues": "https://github.com/10up/simple-page-ordering/issues",
20
- "source": "https://github.com/10up/simple-page-ordering"
21
- },
22
- "minimum-stability": "dev",
23
- "require-dev": {
24
- "10up/wpacceptance": "dev-master"
25
- }
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,12 +1,12 @@
1
  === Simple Page Ordering ===
2
- 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.4
7
- Stable tag: 2.3.4
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
 
@@ -68,10 +68,25 @@ This most likely means the AJAX request - the server side code - failed after yo
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
 
73
  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.
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  == Screenshots ==
76
 
77
  1. Dragging the page to its new position
@@ -79,109 +94,121 @@ This feature is already built into WordPress natively, but a bit tucked away. If
79
 
80
  == Changelog ==
81
 
82
- = 2.3.4 =
83
- * **Changed:** Avoid failed reordering introduced in v2.3.3 when handling a large number of non-hierarchical items (props [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/))
84
- * **Changed:** Bump WordPress version support to 5.4 (props [@tmoorewp](https://profiles.wordpress.org/tmoorewp/))
85
- * **Fixed:** Ensure titles of reordered items appear in a human-readable way (props [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/))
86
-
87
- = 2.3.3 =
88
- * **Added:** Nonce verify for AJAX requests (props [@williampatton](https://profiles.wordpress.org/williampatton/), [@dtbaker](https://profiles.wordpress.org/dtbaker/))
89
- * **Changed:** Disable Post Revisions now using the correct action of `post_updated` (props [@blue-liquid-designs](https://profiles.wordpress.org/blue-liquid-designs/))
90
- * **Changed:** Bump WordPress version "tested up to" 5.3 (props [@adamsilverstein](https://profiles.wordpress.org/adamsilverstein/), [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/))
91
- * **Changed:** Documentation updates (props [@jeffpaul](https://profiles.wordpress.org/jeffpaul/))
92
- * **Fixed:** Mismatched localized data variable name (props [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/))
93
- * **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/))
94
-
95
- = 2.3.2 =
96
- * **Added:** Allow cancellation of drag operation by pressing escape key
97
- * **Fixed:** Allow form input elements added to a row by plugins to be interacted with
98
-
99
- = 2.3.1 =
100
- * **Fixed:** Prevent rows with hidden columns from jumping around while dragging
101
-
102
- = 2.3.0 =
103
- * **Added:** Use WordPress core's spinner class
104
- * **Added:** Grunt-based build process with Sass
105
- * **Changed:** Use `WP_Query` instead of `get_posts()` for better performance
106
- * **Changed:** Remove bundled translations in favor of WordPress.org language packs
107
- * **Fixed:** Avoid exceeding PHP's max input variables, which could cause incorrectly assigned page order
108
- * **Fixed:** Malformed URL that would take you to posts instead of pages
109
- * **Fixed:** PHPDoc and coding standards to align with 10up's Engineering Best Practices
110
-
111
- = 2.2.4 =
112
- * **Fixed:** Redundant URL encoding when sorting in admin page list
113
-
114
- = 2.2.3 =
115
- * **Fixed:** Ordering in WordPress 4.0 following core changes to `ORDER BY` in `WP_Query`
116
-
117
- = 2.2.2 =
118
- * **Added:** German localization (props [@glueckpress](https://profiles.wordpress.org/glueckpress/))
119
- * **Fixed:** Column widths no longer change when dragging a row (partial props [@griffinjt](https://profiles.wordpress.org/griffinjt/))
120
- * **Security:** Closed obscure XSS vulnerability related to Sort by Order link (props [@simon-waters](https://profiles.wordpress.org/simon-waters/))
121
-
122
- = 2.2.1 =
123
- * **Added:** Brazilian translation (props [@felds](https://profiles.wordpress.org/felds/))
124
- * **Fixed:** Bring back translations / text domain (yikes!)
125
-
126
- = 2.2.0 =
127
- * **Changed:** Look and feel to better match WordPress 3.8 admin redesign
128
- * **Changed:** Improved awareness of and compatibility with Quick Edit (inline editor)
129
- * **Fixed:** Prevent collisions with themes and plugins bundling Simple Page Ordering
130
-
131
- = 2.1.2 =
 
 
 
 
 
 
 
 
 
 
 
 
132
  * **Fixed:** Hierarchical custom post types without page-attributes was still broken - doh!
133
- * **Fixed:** Extreme edge case where post columns did not include the post title now supported
134
 
135
- = 2.1.1 =
136
- * **Fixed:** custom post types with page-attributes or hierarchical properties, but not both, breaking ordering
137
 
138
- = 2.1.0 =
139
- * **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)
140
- * **Added:** Awareness of custom post statuses (so they are not skipped during backend ordering operation)
141
- * **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
142
- * **Changed:** Major JavaScript refactoring and simplification (combined with new stylesheet) for better performance
143
 
144
- = 2.0.0 =
145
  * **Added:** Drag pages into any part of the page hierarchy! No longer limited to same branch of tree!
146
- * **Added:** Big performance improvements under the hood: leaner queries, batched requests, less processing
147
- * **Added:** New filters and hooks to extend / override default functionality
148
- * **Changed:** Scales much more reliably in situations with very high page counts due to batching of requests
149
- * **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)
150
- * **Changed:** Removed "number of pages" drop down, which is repetitive of a field accessible under Screen Options
151
- * **Changed:** Improved compatibility with newer versions of WordPress
152
-
153
- = 1.0.0 =
154
- * **Added:** Support for ordering non-hierarchical post types that have "page-attributes" support
155
- * **Added:** New filter link for "Sort by Order" to restore (hierarchical) or set (non-hierarchical, page attributes support) post list sort to menu order
156
- * **Changed:** Users are now forced to wait for current sort operation to finish before they can sort another item
157
- * **Changed:** Smarter about "not sortable" view states
158
  * **Changed:** Localization ready! Rough Spanish translation included.
159
- * **Changed:** Assorted other performance and code improvements
160
- * **Fixed:** Unexpected page ordering results when pages have not been explictly ordered yet (sorts by menu_order, then title, not just menu_order)
161
- * **Fixed:** "Per page" drop down filter selection not saving between page loads (was broken in 3.1)
162
- * **Fixed:** Items are always ordered with positive integers (potential negative sort orders had some performance benefits in last version, but sometimes caused issues)
163
-
164
- = 0.9.6 =
165
- * **Fixed:** for broken inline editing (quick edit) fields in Firefox
166
-
167
- = 0.9.5 =
168
- * **Changed:** Smarter awareness of "sorted" modes in WordPress 3.1 (can only use when sorted by menu order)
169
- * **Changed:** Smarter awareness of "quick edit" mode (can't drag)
170
- * **Changed:** Generally simplified / better organized code
171
-
172
- = 0.9.0 =
173
- * **Added:** Further directions in the plug-in description (some users were confused about how to use it)
174
- * **Added:** Basic compatibility with 3.1 RC (prevent clashes with post list sorting)
175
- * **Changed:** "Move" cursor only set if JavaScript enabled
176
- * **Fixed:** Page count display always showing "0" on non-hierarchical post types (Showing 1-X of X)
177
- * **Fixed:** Hidden menu order not updating after sort (causing Quick Edit to reset order when used right after sorting)
178
-
179
- = 0.8.4 =
180
- * **Changed:** Loosened constraints on drag and drop to ease dropping into top and bottom position
181
- * **Changed:** Improved some terminology (with custom post types in mind)
182
- * **Fixed:** Row background staying "white" after dropping into a new position
183
- * **Fixed:** Double border on the bottom of the row while dragging
184
-
185
- = 0.8.2 =
186
- * **Changed:** Simplified code - consolidated hooks
187
- * **Changed:** Updated version requirements
1
  === Simple Page Ordering ===
2
+ 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: 6.0
7
+ Stable tag: 2.4.0
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
 
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
 
73
  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.
74
 
75
+ = How can I exclude certain custom post types? =
76
+
77
+ Custom post types can be excluded by using the `simple_page_ordering_is_sortable` filter.
78
+
79
+ For example, with `excluded_post_type` as the custom post type ID, add the following snippet in the theme function file or custom plugin:
80
+
81
+ `
82
+ add_filter( 'simple_page_ordering_is_sortable', function( $sortable, $post_type ) {
83
+ if ( 'excluded_post_type' === $post_type ) {
84
+ return false;
85
+ }
86
+ return $sortable;
87
+ }, 10, 2 );
88
+ `
89
+
90
  == Screenshots ==
91
 
92
  1. Dragging the page to its new position
94
 
95
  == Changelog ==
96
 
97
+ = 2.4.0 - 2022-04-28 =
98
+ * **Added:** REST API for reordering posts: `/wp-json/simplepageordering/v1/` (props [@rmccue](https://profiles.wordpress.org/rmccue/), [@ciprianimike](https://github.com/ciprianimike), [@cadic](https://profiles.wordpress.org/cadic/), [@lkraav](https://github.com/lkraav), [@dinhtungdu](https://github.com/dinhtungdu)).
99
+ * **Added:** [REST Endpoint Documentation](https://github.com/10up/simple-page-ordering/blob/develop/README.md).
100
+ * **Added:** Documentation to exclude post types (props [@dzulfriday](https://wordpress.org/support/users/dzulfriday/) [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/), [@jeffpaul](https://profiles.wordpress.org/jeffpaul/)).
101
+ * **Added:** PHP8 compatibility testing GitHub Action (props [@nomnom99](https://profiles.wordpress.org/nomnom99/), [@dharm1025](https://profiles.wordpress.org/dharm1025/)).
102
+ * **Added:** Cypress E2E tests (props [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/), [@dharm1025](https://profiles.wordpress.org/dharm1025/), [@faisal03](https://profiles.wordpress.org/faisal03/)).
103
+ * **Added:** Dependency security scanning GitHub Action (props [@jeffpaul](https://profiles.wordpress.org/jeffpaul/), [@nomnom99](https://profiles.wordpress.org/nomnom99/)).
104
+ * **Changed:** `PLUGIN_VERSION` to `SIMPLE_PAGE_ORDERING_VERSION` (props [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/), [@dkotter](https://profiles.wordpress.org/dkotter/)).
105
+ * **Changed:** Bump WordPress "tested up to" version to 5.9 (props [@ankitguptaindia](https://github.com/ankitguptaindia), [@phpbits](https://github.com/phpbits), [@sudip-10up](https://github.com/sudip-10up)).
106
+ * **Security:** Bump rmccue/requests from 1.7.0 to 1.8.0 (props [@dependabot](https://github.com/apps/dependabot)).
107
+ * **Security:** Bump async from 2.6.3 to 2.6.4 (props [@dependabot](https://github.com/apps/dependabot)).
108
+
109
+ = 2.3.4 - 2020-04-07 =
110
+ * **Changed:** Avoid failed reordering introduced in v2.3.3 when handling a large number of non-hierarchical items (props [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/)).
111
+ * **Changed:** Bump WordPress version support to 5.4 (props [@tmoorewp](https://profiles.wordpress.org/tmoorewp/)).
112
+ * **Fixed:** Ensure titles of reordered items appear in a human-readable way (props [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/)).
113
+
114
+ = 2.3.3 - 2020-03-04 =
115
+ * **Added:** Nonce verify for AJAX requests (props [@williampatton](https://profiles.wordpress.org/williampatton/), [@dtbaker](https://profiles.wordpress.org/dtbaker/)).
116
+ * **Changed:** Disable Post Revisions now using the correct action of `post_updated` (props [@blue-liquid-designs](https://profiles.wordpress.org/blue-liquid-designs/)).
117
+ * **Changed:** Bump WordPress version "tested up to" 5.3 (props [@adamsilverstein](https://profiles.wordpress.org/adamsilverstein/), [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/)).
118
+ * **Changed:** Documentation updates (props [@jeffpaul](https://profiles.wordpress.org/jeffpaul/)).
119
+ * **Fixed:** Mismatched localized data variable name (props [@dinhtungdu](https://profiles.wordpress.org/dinhtungdu/)).
120
+ * **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/)).
121
+
122
+ = 2.3.2 - 2018-05-08 =
123
+ * **Added:** Allow cancellation of drag operation by pressing escape key.
124
+ * **Fixed:** Allow form input elements added to a row by plugins to be interacted with.
125
+
126
+ = 2.3.1 - 2018-04-13 =
127
+ * **Fixed:** Prevent rows with hidden columns from jumping around while dragging.
128
+
129
+ = 2.3.0 - 2018-03-05 =
130
+ * **Added:** Use WordPress core's spinner class.
131
+ * **Added:** Grunt-based build process with Sass.
132
+ * **Changed:** Use `WP_Query` instead of `get_posts()` for better performance.
133
+ * **Changed:** Remove bundled translations in favor of WordPress.org language packs.
134
+ * **Fixed:** Avoid exceeding PHP's max input variables, which could cause incorrectly assigned page order.
135
+ * **Fixed:** Malformed URL that would take you to posts instead of pages.
136
+ * **Fixed:** PHPDoc and coding standards to align with 10up's Engineering Best Practices.
137
+
138
+ = 2.2.4 - 2015-02-08 =
139
+ * **Fixed:** Redundant URL encoding when sorting in admin page list.
140
+
141
+ = 2.2.3 - 2014-09-27 =
142
+ * **Fixed:** Ordering in WordPress 4.0 following core changes to `ORDER BY` in `WP_Query`.
143
+
144
+ = 2.2.2 - 2014-08-19 =
145
+ * **Added:** German localization (props [@glueckpress](https://profiles.wordpress.org/glueckpress/)).
146
+ * **Fixed:** Column widths no longer change when dragging a row (partial props [@griffinjt](https://profiles.wordpress.org/griffinjt/)).
147
+ * **Security:** Closed obscure XSS vulnerability related to Sort by Order link (props [@simon-waters](https://profiles.wordpress.org/simon-waters/)).
148
+
149
+ = 2.2.1 - 2014-05-31 =
150
+ * **Added:** Brazilian translation (props [@felds](https://profiles.wordpress.org/felds/)).
151
+ * **Fixed:** Bring back translations / text domain (yikes!).
152
+
153
+ = 2.2.0 - 2014-04-06 =
154
+ * **Changed:** Look and feel to better match WordPress 3.8 admin redesign.
155
+ * **Changed:** Improved awareness of and compatibility with Quick Edit (inline editor).
156
+ * **Fixed:** Prevent collisions with themes and plugins bundling Simple Page Ordering.
157
+
158
+ = 2.1.2 - 2013-05-30 =
159
  * **Fixed:** Hierarchical custom post types without page-attributes was still broken - doh!
160
+ * **Fixed:** Extreme edge case where post columns did not include the post title now supported.
161
 
162
+ = 2.1.1 - 2013-05-27 =
163
+ * **Fixed:** custom post types with page-attributes or hierarchical properties, but not both, breaking ordering.
164
 
165
+ = 2.1.0 - 2013-05-19 =
166
+ * **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).
167
+ * **Added:** Awareness of custom post statuses (so they are not skipped during backend ordering operation).
168
+ * **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.
169
+ * **Changed:** Major JavaScript refactoring and simplification (combined with new stylesheet) for better performance.
170
 
171
+ = 2.0.0 - 2012-11-12 =
172
  * **Added:** Drag pages into any part of the page hierarchy! No longer limited to same branch of tree!
173
+ * **Added:** Big performance improvements under the hood: leaner queries, batched requests, less processing.
174
+ * **Added:** New filters and hooks to extend / override default functionality.
175
+ * **Changed:** Scales much more reliably in situations with very high page counts due to batching of requests.
176
+ * **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).
177
+ * **Changed:** Removed "number of pages" drop down, which is repetitive of a field accessible under Screen Options.
178
+ * **Changed:** Improved compatibility with newer versions of WordPress.
179
+
180
+ = 1.0.0 - 2011-07-04 =
181
+ * **Added:** Support for ordering non-hierarchical post types that have "page-attributes" support.
182
+ * **Added:** New filter link for "Sort by Order" to restore (hierarchical) or set (non-hierarchical, page attributes support) post list sort to menu order.
183
+ * **Changed:** Users are now forced to wait for current sort operation to finish before they can sort another item.
184
+ * **Changed:** Smarter about "not sortable" view states.
185
  * **Changed:** Localization ready! Rough Spanish translation included.
186
+ * **Changed:** Assorted other performance and code improvements.
187
+ * **Fixed:** Unexpected page ordering results when pages have not been explictly ordered yet (sorts by menu_order, then title, not just menu_order).
188
+ * **Fixed:** "Per page" drop down filter selection not saving between page loads (was broken in 3.1).
189
+ * **Fixed:** Items are always ordered with positive integers (potential negative sort orders had some performance benefits in last version, but sometimes caused issues).
190
+
191
+ = 0.9.6 - 2011-04-04 =
192
+ * **Fixed:** for broken inline editing (quick edit) fields in Firefox.
193
+
194
+ = 0.9.5 - 2011-03-27 =
195
+ * **Changed:** Smarter awareness of "sorted" modes in WordPress 3.1 (can only use when sorted by menu order).
196
+ * **Changed:** Smarter awareness of "quick edit" mode (can't drag).
197
+ * **Changed:** Generally simplified / better organized code.
198
+
199
+ = 0.9.0 - 2010-12-29 =
200
+ * **Added:** Further directions in the plug-in description (some users were confused about how to use it).
201
+ * **Added:** Basic compatibility with 3.1 RC (prevent clashes with post list sorting).
202
+ * **Changed:** "Move" cursor only set if JavaScript enabled.
203
+ * **Fixed:** Page count display always showing "0" on non-hierarchical post types (Showing 1-X of X).
204
+ * **Fixed:** Hidden menu order not updating after sort (causing Quick Edit to reset order when used right after sorting).
205
+
206
+ = 0.8.4 - 2010-08-24 =
207
+ * **Changed:** Loosened constraints on drag and drop to ease dropping into top and bottom position.
208
+ * **Changed:** Improved some terminology (with custom post types in mind).
209
+ * **Fixed:** Row background staying "white" after dropping into a new position.
210
+ * **Fixed:** Double border on the bottom of the row while dragging.
211
+
212
+ = 0.8.2 - 2010-08-21 =
213
+ * **Changed:** Simplified code - consolidated hooks.
214
+ * **Changed:** Updated version requirements.
simple-page-ordering.php CHANGED
@@ -3,17 +3,25 @@
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.4
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
 
 
 
 
17
  class Simple_Page_Ordering {
18
 
19
  /**
@@ -27,7 +35,7 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
27
 
28
  if ( null === $instance ) {
29
  $instance = new self();
30
- self::_add_actions();
31
  }
32
 
33
  return $instance;
@@ -43,10 +51,11 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
43
  /**
44
  * Handles registering hooks that initialize this plugin.
45
  */
46
- public static function _add_actions() {
47
  add_action( 'load-edit.php', array( __CLASS__, 'load_edit_screen' ) );
48
  add_action( 'wp_ajax_simple_page_ordering', array( __CLASS__, 'ajax_simple_page_ordering' ) );
49
  add_action( 'plugins_loaded', array( __CLASS__, 'load_textdomain' ) );
 
50
  }
51
 
52
  /**
@@ -75,10 +84,14 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
75
  return;
76
  }
77
 
78
- add_filter( 'views_' . $screen->id, array(
79
- __CLASS__,
80
- 'sort_by_order_link',
81
- ) ); // add view by menu order to views
 
 
 
 
82
  add_action( 'wp', array( __CLASS__, 'wp' ) );
83
  add_action( 'admin_head', array( __CLASS__, 'admin_head' ) );
84
  }
@@ -100,7 +113,8 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
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
  }
106
 
@@ -109,13 +123,20 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
109
  */
110
  public static function admin_head() {
111
  $screen = get_current_screen();
112
- $screen->add_help_tab( array(
113
- 'id' => 'simple_page_ordering_help_tab',
114
- 'title' => 'Simple Page Ordering',
115
- 'content' => '<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.', 'simple-page-ordering' ) . '</p>',
116
- ) );
 
 
117
  }
118
 
 
 
 
 
 
119
  public static function ajax_simple_page_ordering() {
120
  // check and make sure we have what we need
121
  if ( empty( $_POST['id'] ) || ( ! isset( $_POST['previd'] ) && ! isset( $_POST['nextid'] ) ) ) {
@@ -130,8 +151,14 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
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
  }
@@ -141,26 +168,54 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
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;
150
 
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;
158
 
159
  do_action( 'simple_page_ordering_pre_order_posts', $post, $start );
160
 
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
@@ -169,20 +224,24 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
169
  $parent_id = ( false !== $prev_post_parent ) ? $prev_post_parent : $next_post_parent;
170
  }
171
  }
 
172
  // if the next post's parent isn't our parent, it might as well be false (irrelevant to our query)
173
  if ( $next_post_parent !== $parent_id ) {
174
  $nextid = false;
175
  }
176
 
177
  $max_sortable_posts = (int) apply_filters( 'simple_page_ordering_limit', 50 ); // should reliably be able to do about 50 at a time
 
178
  if ( $max_sortable_posts < 5 ) { // don't be ridiculous!
179
  $max_sortable_posts = 50;
180
  }
181
 
182
  // we need to handle all post stati, except trash (in case of custom stati)
183
- $post_stati = get_post_stati( array(
184
- 'show_in_admin_all_list' => true,
185
- ) );
 
 
186
 
187
  $siblings_query = array(
188
  'depth' => 1,
@@ -219,17 +278,21 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
219
 
220
  // if this is the post that comes after our repositioned post, set our repositioned post position and increment menu order
221
  if ( $nextid === $sibling->ID ) {
222
- wp_update_post( array(
223
- 'ID' => $post->ID,
224
- 'menu_order' => $start,
225
- 'post_parent' => $parent_id,
226
- ) );
 
 
 
227
  $ancestors = get_post_ancestors( $post->ID );
228
  $new_pos[ $post->ID ] = array(
229
  'menu_order' => $start,
230
  'post_parent' => $parent_id,
231
  'depth' => count( $ancestors ),
232
  );
 
233
  $start ++;
234
  }
235
 
@@ -241,20 +304,25 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
241
 
242
  // set the menu order of the current sibling and increment the menu order
243
  if ( $sibling->menu_order !== $start ) {
244
- wp_update_post( array(
245
- 'ID' => $sibling->ID,
246
- 'menu_order' => $start,
247
- ) );
 
 
248
  }
249
  $new_pos[ $sibling->ID ] = $start;
250
  $start ++;
251
 
252
  if ( ! $nextid && $previd === $sibling->ID ) {
253
- wp_update_post( array(
254
- 'ID' => $post->ID,
255
- 'menu_order' => $start,
256
- 'post_parent' => $parent_id,
257
- ) );
 
 
 
258
  $ancestors = get_post_ancestors( $post->ID );
259
  $new_pos[ $post->ID ] = array(
260
  'menu_order' => $start,
@@ -298,18 +366,19 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
298
  );
299
 
300
  if ( $children->have_posts() ) {
301
- die( 'children' );
302
  }
303
  }
304
 
305
  $return_data->new_pos = $new_pos;
306
- die( wp_json_encode( $return_data ) );
 
307
  }
308
 
309
  /**
310
  * Append a sort by order link to the post actions
311
  *
312
- * @param array $views
313
  *
314
  * @return array
315
  */
@@ -338,6 +407,82 @@ if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
338
 
339
  return apply_filters( 'simple_page_ordering_edit_rights', current_user_can( $edit_others_cap ), $post_type );
340
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  }
342
 
343
  Simple_Page_Ordering::get_instance();
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.4.0
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
+ * @package simple-page-ordering
15
  */
16
 
17
+ // Useful global constants.
18
+ define( 'SIMPLE_PAGE_ORDERING_VERSION', '2.4.0' );
19
+
20
  if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
21
 
22
+ /**
23
+ * Simple_Page_Ordering class
24
+ */
25
  class Simple_Page_Ordering {
26
 
27
  /**
35
 
36
  if ( null === $instance ) {
37
  $instance = new self();
38
+ self::add_actions();
39
  }
40
 
41
  return $instance;
51
  /**
52
  * Handles registering hooks that initialize this plugin.
53
  */
54
+ public static function add_actions() {
55
  add_action( 'load-edit.php', array( __CLASS__, 'load_edit_screen' ) );
56
  add_action( 'wp_ajax_simple_page_ordering', array( __CLASS__, 'ajax_simple_page_ordering' ) );
57
  add_action( 'plugins_loaded', array( __CLASS__, 'load_textdomain' ) );
58
+ add_action( 'rest_api_init', array( __CLASS__, 'rest_api_init' ) );
59
  }
60
 
61
  /**
84
  return;
85
  }
86
 
87
+ // add view by menu order to views
88
+ add_filter(
89
+ 'views_' . $screen->id,
90
+ array(
91
+ __CLASS__,
92
+ 'sort_by_order_link',
93
+ )
94
+ );
95
  add_action( 'wp', array( __CLASS__, 'wp' ) );
96
  add_action( 'admin_head', array( __CLASS__, 'admin_head' ) );
97
  }
113
  'screen_id' => (string) $screen->id,
114
  )
115
  );
116
+
117
+ wp_enqueue_style( 'simple-page-ordering', plugins_url( '/assets/css/simple-page-ordering.css', __FILE__ ), [], SIMPLE_PAGE_ORDERING_VERSION );
118
  }
119
  }
120
 
123
  */
124
  public static function admin_head() {
125
  $screen = get_current_screen();
126
+ $screen->add_help_tab(
127
+ array(
128
+ 'id' => 'simple_page_ordering_help_tab',
129
+ 'title' => 'Simple Page Ordering',
130
+ 'content' => '<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.', 'simple-page-ordering' ) . '</p>',
131
+ )
132
+ );
133
  }
134
 
135
+ /**
136
+ * Page ordering ajax callback
137
+ *
138
+ * @return void
139
+ */
140
  public static function ajax_simple_page_ordering() {
141
  // check and make sure we have what we need
142
  if ( empty( $_POST['id'] ) || ( ! isset( $_POST['previd'] ) && ! isset( $_POST['nextid'] ) ) ) {
151
 
152
  check_admin_referer( 'simple-page-ordering_' . sanitize_key( $_POST['screen_id'] ) );
153
 
154
+ $post_id = empty( $_POST['id'] ) ? false : (int) $_POST['id'];
155
+ $previd = empty( $_POST['previd'] ) ? false : (int) $_POST['previd'];
156
+ $nextid = empty( $_POST['nextid'] ) ? false : (int) $_POST['nextid'];
157
+ $start = empty( $_POST['start'] ) ? 1 : (int) $_POST['start'];
158
+ $excluded = empty( $_POST['excluded'] ) ? array( $_POST['id'] ) : array_filter( (array) json_decode( $_POST['excluded'] ), 'intval' );
159
+
160
  // real post?
161
+ $post = empty( $post_id ) ? false : get_post( (int) $post_id );
162
  if ( ! $post ) {
163
  die( - 1 );
164
  }
168
  die( - 1 );
169
  }
170
 
171
+ $result = self::page_ordering( $post_id, $previd, $nextid, $start, $excluded );
172
+
173
+ if ( is_wp_error( $result ) ) {
174
+ die( -1 );
175
+ }
176
+
177
+ die( wp_json_encode( $result ) );
178
+ }
179
+
180
+ /**
181
+ * Page ordering function
182
+ *
183
+ * @param int $post_id The post ID.
184
+ * @param int $previd The previous post ID.
185
+ * @param int $nextid The next post ID.
186
+ * @param int $start The start index.
187
+ * @param array $excluded Array of post IDs.
188
+ *
189
+ * @return obj|WP_Error
190
+ */
191
+ public static function page_ordering( $post_id, $previd, $nextid, $start, $excluded ) {
192
+ // real post?
193
+ $post = empty( $post_id ) ? false : get_post( (int) $post_id );
194
+ if ( ! $post ) {
195
+ return new WP_Error( __( 'Missing mandatory parameters.', 'simple-page-ordering' ) );
196
+ }
197
+
198
  // Badly written plug-in hooks for save post can break things.
199
  if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
200
+ error_reporting( 0 ); // phpcs:ignore
201
  }
202
 
203
  global $wp_version;
204
 
205
+ $previd = empty( $previd ) ? false : (int) $previd;
206
+ $nextid = empty( $nextid ) ? false : (int) $nextid;
207
+ $start = empty( $start ) ? 1 : (int) $start;
208
+ $excluded = empty( $excluded ) ? array( $post_id ) : array_filter( (array) $excluded, 'intval' );
209
 
210
  $new_pos = array(); // store new positions for ajax
211
+ $return_data = new stdClass();
212
 
213
  do_action( 'simple_page_ordering_pre_order_posts', $post, $start );
214
 
215
  // attempt to get the intended parent... if either sibling has a matching parent ID, use that
216
  $parent_id = $post->post_parent;
217
  $next_post_parent = $nextid ? wp_get_post_parent_id( $nextid ) : false;
218
+
219
  if ( $previd === $next_post_parent ) { // if the preceding post is the parent of the next post, move it inside
220
  $parent_id = $next_post_parent;
221
  } elseif ( $next_post_parent !== $parent_id ) { // otherwise, if the next post's parent isn't the same as our parent, we need to study
224
  $parent_id = ( false !== $prev_post_parent ) ? $prev_post_parent : $next_post_parent;
225
  }
226
  }
227
+
228
  // if the next post's parent isn't our parent, it might as well be false (irrelevant to our query)
229
  if ( $next_post_parent !== $parent_id ) {
230
  $nextid = false;
231
  }
232
 
233
  $max_sortable_posts = (int) apply_filters( 'simple_page_ordering_limit', 50 ); // should reliably be able to do about 50 at a time
234
+
235
  if ( $max_sortable_posts < 5 ) { // don't be ridiculous!
236
  $max_sortable_posts = 50;
237
  }
238
 
239
  // we need to handle all post stati, except trash (in case of custom stati)
240
+ $post_stati = get_post_stati(
241
+ array(
242
+ 'show_in_admin_all_list' => true,
243
+ )
244
+ );
245
 
246
  $siblings_query = array(
247
  'depth' => 1,
278
 
279
  // if this is the post that comes after our repositioned post, set our repositioned post position and increment menu order
280
  if ( $nextid === $sibling->ID ) {
281
+ wp_update_post(
282
+ array(
283
+ 'ID' => $post->ID,
284
+ 'menu_order' => $start,
285
+ 'post_parent' => $parent_id,
286
+ )
287
+ );
288
+
289
  $ancestors = get_post_ancestors( $post->ID );
290
  $new_pos[ $post->ID ] = array(
291
  'menu_order' => $start,
292
  'post_parent' => $parent_id,
293
  'depth' => count( $ancestors ),
294
  );
295
+
296
  $start ++;
297
  }
298
 
304
 
305
  // set the menu order of the current sibling and increment the menu order
306
  if ( $sibling->menu_order !== $start ) {
307
+ wp_update_post(
308
+ array(
309
+ 'ID' => $sibling->ID,
310
+ 'menu_order' => $start,
311
+ )
312
+ );
313
  }
314
  $new_pos[ $sibling->ID ] = $start;
315
  $start ++;
316
 
317
  if ( ! $nextid && $previd === $sibling->ID ) {
318
+ wp_update_post(
319
+ array(
320
+ 'ID' => $post->ID,
321
+ 'menu_order' => $start,
322
+ 'post_parent' => $parent_id,
323
+ )
324
+ );
325
+
326
  $ancestors = get_post_ancestors( $post->ID );
327
  $new_pos[ $post->ID ] = array(
328
  'menu_order' => $start,
366
  );
367
 
368
  if ( $children->have_posts() ) {
369
+ return( 'children' );
370
  }
371
  }
372
 
373
  $return_data->new_pos = $new_pos;
374
+
375
+ return $return_data;
376
  }
377
 
378
  /**
379
  * Append a sort by order link to the post actions
380
  *
381
+ * @param array $views An array of available list table views.
382
  *
383
  * @return array
384
  */
407
 
408
  return apply_filters( 'simple_page_ordering_edit_rights', current_user_can( $edit_others_cap ), $post_type );
409
  }
410
+
411
+ /**
412
+ * Registers the API endpoint for sorting from the REST endpoint
413
+ */
414
+ public static function rest_api_init() {
415
+ register_rest_route(
416
+ 'simple-page-ordering/v1',
417
+ 'page_ordering',
418
+ [
419
+ 'methods' => 'POST',
420
+ 'callback' => array( __CLASS__, 'rest_page_ordering' ),
421
+ 'permission_callback' => '__return_true',
422
+ 'args' => [
423
+ 'id' => [
424
+ 'description' => 'Post ID.',
425
+ 'required' => true,
426
+ 'type' => 'numeric',
427
+ ],
428
+ 'previd' => [
429
+ 'description' => 'Previous post ID',
430
+ 'required' => true,
431
+ 'type' => 'numeric',
432
+ ],
433
+ 'nextid' => [
434
+ 'description' => 'Next post ID',
435
+ 'required' => true,
436
+ 'type' => 'numeric',
437
+ ],
438
+ 'start' => [
439
+ 'default' => 1,
440
+ 'description' => 'Start index',
441
+ 'required' => false,
442
+ 'type' => 'numeric',
443
+ ],
444
+ 'exclude' => [
445
+ 'default' => [],
446
+ 'description' => 'Array of excluded post IDs',
447
+ 'required' => false,
448
+ 'type' => 'array',
449
+ ],
450
+ ],
451
+ ]
452
+ );
453
+ }
454
+
455
+ /**
456
+ * Handle REST page sorting
457
+ *
458
+ * @param WP_REST_Request $request The REST request object.
459
+ */
460
+ public static function rest_page_ordering( WP_REST_Request $request ) {
461
+ $post_id = empty( $request->get_param( 'id' ) ) ? false : (int) $request->get_param( 'id' );
462
+ $previd = empty( $request->get_param( 'previd' ) ) ? false : (int) $request->get_param( 'previd' );
463
+ $nextid = empty( $request->get_param( 'nextid' ) ) ? false : (int) $request->get_param( 'nextid' );
464
+ $start = empty( $request->get_param( 'start' ) ) ? 1 : (int) $request->get_param( 'start' );
465
+ $excluded = empty( $request->get_param( 'excluded' ) ) ? array( $request->get_param( 'id' ) ) : array_filter( (array) json_decode( $request->get_param( 'excluded' ) ), 'intval' );
466
+
467
+ // check and make sure we have what we need
468
+ if ( empty( $post_id ) || ( ! isset( $previd ) && ! isset( $nextid ) ) ) {
469
+ return new WP_Error( __( 'Missing mandatory parameters.', 'simple-page-ordering' ) );
470
+ }
471
+
472
+ $page_ordering = self::page_ordering( $post_id, $previd, $nextid, $start, $excluded );
473
+
474
+ if ( is_wp_error( $page_ordering ) ) {
475
+ return $page_ordering;
476
+ }
477
+
478
+ return new WP_REST_Response(
479
+ array(
480
+ 'status' => 200,
481
+ 'response' => 'successs',
482
+ 'body_response' => $page_ordering,
483
+ )
484
+ );
485
+ }
486
  }
487
 
488
  Simple_Page_Ordering::get_instance();