Simple Page Ordering - Version 1.0

Version Description

  • Fix unexpected page ordering results when pages have not been explictly ordered yet (sorts by menu_order, then title, not just menu_order)
  • Support for ordering non-hierarchical post types that have "page-attributes" support
  • New filter link for "Sort by Order" to restore (hierarchical) or set (non-hierarchical, page attributes support) post list sort to menu order
  • Fix "per page" drop down filter selection not saving between page loads (was broken in 3.1)
  • Users are now forced to wait for current sort operation to finish before they can sort another item
  • Smarter about "not sortable" view states
  • Localization ready! Rough Spanish translation included.
  • Items are always ordered with positive integers (potential negative sort orders had some performance benefits in last version, but sometimes caused issues)
  • Assorted other performance and code improvements
Download this release

Release Info

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

Code changes from version 0.9.6 to 1.0

localization/simple-page-ordering-es_ES.mo ADDED
Binary file
localization/simple-page-ordering-es_ES.po ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2011 Simple Page Ordering
2
+ # This file is distributed under the same license as the Simple Page Ordering package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Simple Page Ordering 1.0\n"
6
+ "Report-Msgid-Bugs-To: \n"
7
+ "POT-Creation-Date: 2011-07-03 23:41-0500\n"
8
+ "PO-Revision-Date: 2011-07-03 23:58-0500\n"
9
+ "Last-Translator: Jake Goldman <jake@get10up.com>\n"
10
+ "Language-Team: 10up <jake@get10up.com>\n"
11
+ "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=UTF-8\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "X-Poedit-Language: Spanish\n"
15
+
16
+ #: simple-page-ordering.php:57
17
+ msgid ""
18
+ "Items can only be repositioned within their current branch in the page tree / hierarchy (next to pages with the same parent).\n"
19
+ "\n"
20
+ "If you want to move this item into a different part of the page tree, use the Quick Edit feature to change the parent before continuing."
21
+ msgstr ""
22
+ "Los productos que sólo se puede colocar dentro de su rama actual del árbol de páginas / jerarquía (al lado de las páginas con el mismo padre).\n"
23
+ "\n"
24
+ "Si desea mover este tema en una parte diferente del árbol de páginas, utilice la función de edición rápida para cambiar la matriz antes de continuar."
25
+
26
+ #: simple-page-ordering.php:71
27
+ msgid "Show all"
28
+ msgstr "Mostrar todo"
29
+
30
+ #: simple-page-ordering.php:76
31
+ msgid "per page"
32
+ msgstr "por página"
33
+
34
+ #: simple-page-ordering.php:86
35
+ msgid "Simple Page Ordering"
36
+ msgstr "Simple Page Ordering"
37
+
38
+ #: simple-page-ordering.php:86
39
+ msgid "is a plug-in by"
40
+ msgstr "es un plug-in por"
41
+
42
+ #: simple-page-ordering.php:86
43
+ msgid "that allows you to order pages and other hierarchical post types with drag and drop."
44
+ msgstr "que le permite ordenar las páginas y otros tipos de mensaje jerárquica con arrastrar y soltar."
45
+
46
+ #: simple-page-ordering.php:87
47
+ msgid "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."
48
+ msgstr "Para cambiar la posición de un elemento, basta con arrastrar y soltar en la fila de \"clic y manteniendo\" en cualquier lugar (fuera de los vínculos y formar controles) y moverla a su nueva posición."
49
+
50
+ #: simple-page-ordering.php:88
51
+ msgid "If you have a large number of pages, it may be helpful to adjust the new \"items per page\" filter located above the table and before the filter button."
52
+ msgstr "Si usted tiene un gran número de páginas, puede ser útil para ajustar el nuevo \"artículos por página\" filtro situado por encima de la tabla y antes de que el botón Filtro."
53
+
54
+ #: simple-page-ordering.php:89
55
+ msgid "To keep things relatively simple, the current version only allows you to reposition items within their current tree / hierarchy (next to pages with the same parent). If you want to move an item into or out of a different part of the page tree, use the \"quick edit\" feature to change the parent."
56
+ msgstr "Para mantener las cosas relativamente simples, la versión actual sólo le permite cambiar elementos dentro de su árbol de corriente / jerarquía (al lado de las páginas con el mismo padre). Si desea mover un elemento que entra o sale de una parte diferente del árbol de páginas, utilice el \"edición rápida\" para cambiar la matriz."
57
+
readme.txt CHANGED
@@ -1,34 +1,32 @@
1
  === Simple Page Ordering ===
2
- Contributors: jakemgold, thinkoomph
3
- Donate link: http://www.get10up.com/plugins/simple-page-ordering-wordpress/
4
  Tags: order, re-order, ordering, pages, page, manage, menu_order, hierarchical, ajax, drag-and-drop, admin
5
- Requires at least: 3.0.1
6
- Tested up to: 3.1
7
- Stable tag: 0.9.6
8
 
9
  Order your pages and other hierarchical post types with simple drag and drop. Also adds a drop down to change items per page.
10
 
11
  == Description ==
12
 
13
- Order your pages (and any hierarchical custom post types) with simple drag and drop on the page (or custom type) management / list screen.
14
 
15
- The following video is from an earlier build (0.7) that has been refined.
16
 
17
  [youtube http://www.youtube.com/watch?v=wWEVW78VF30]
18
 
19
- Simply drag and drop the page into your desired position! It's that simple. No new admin menus pages, no dedicated clunky user interfaces. Just drag and drop on the page list screen.
20
 
21
- To facilitate the menu order management on sites with many pages, the plug-in also adds a new drop down filter allowing you to customize the paging (pages per page) on the page admin screen. Your last choice will even be saved whenever you return (on a user to user basis and post type by post type basis)!
22
 
23
  The plug-in is "capabilities smart" - only users with the ability to edit others' pages (i.e. editors and administrators) will be able to reorder pages.
24
 
25
  Integrated help is included! Just click the "help" tab toward the top right of the screen; the help is below the standard help for the screen.
26
 
27
- Note that this plug-in only allows drag and drop resort within the same branch in the page tree / hierarchy for a given page. You can instantly change the hierarchy by using the Quick Edit feature built into WordPress and changing the "Parent" option. This may be addressed in the future, but the intention is to avoid confusion about "where" you're trying to put the page. For example, if you move a page after another page's last child, are you trying to make it a child of the other page, or position it after the other page? Ideas are welcome.
28
 
29
- This plug-in is being released as a "beta" in the Google sense. There are no known issues, but it requires much more comprehensive testing with custom post types and environments with large number of pages before we can label it "1.0". You must have JavaScript enabled for this plug-in to work.
30
-
31
- Please note that the plug-in is currently only minimally compatible with Internet Explorer 7 and earlier, due to limitations within those browsers.
32
 
33
 
34
  == Installation ==
@@ -48,6 +46,17 @@ folder to the `/wp-content/plugins/` directory
48
 
49
  == Changelog ==
50
 
 
 
 
 
 
 
 
 
 
 
 
51
  = 0.9.6 =
52
  * Fix for broken inline editing (quick edit) fields in Firefox
53
 
1
  === Simple Page Ordering ===
2
+ Contributors: jakemgold, 10up, thinkoomph
3
+ Donate link: http://get10up.com/plugins/simple-page-ordering-wordpress/
4
  Tags: order, re-order, ordering, pages, page, manage, menu_order, hierarchical, ajax, drag-and-drop, admin
5
+ Requires at least: 3.1
6
+ Tested up to: 3.2.1
7
+ Stable tag: 1.0
8
 
9
  Order your pages and other hierarchical post types with simple drag and drop. Also adds a drop down to change items per page.
10
 
11
  == Description ==
12
 
13
+ Order your pages, hierarchical custom post types, or custom post types with "page-attributes" with simple drag and drop on the usual page list screen.
14
 
15
+ The following video is from an early build (0.7) that has been significantly refined, but still demonstrates the concept.
16
 
17
  [youtube http://www.youtube.com/watch?v=wWEVW78VF30]
18
 
19
+ Simply drag and drop the page into your desired position! It's that simple. No new admin menus pages, no clunky user interfaces that feel bolted onto WordPress. Just drag and drop on the page or post-type list screen.
20
 
21
+ To facilitate menu order management on sites with many pages, the plug-in also adds a new drop down filter allowing you to customize the paging (pages per page) on the page admin screen. Your last choice will even be saved whenever you return (on a user to user basis and post type by post type basis)!
22
 
23
  The plug-in is "capabilities smart" - only users with the ability to edit others' pages (i.e. editors and administrators) will be able to reorder pages.
24
 
25
  Integrated help is included! Just click the "help" tab toward the top right of the screen; the help is below the standard help for the screen.
26
 
27
+ Note that this plug-in only allows drag and drop resort within the same "branch" in the page tree / hierarchy. You can still instantly change the hierarchy by using the Quick Edit feature built into WordPress and changing the "Parent". The intention is to avoid confusion about "where" the user is trying to put the page. For example, when moving a page after another page's last child, are you trying to make it a child of the other page, or position it after the other page? Ideas are welcome.
28
 
29
+ You must have JavaScript enabled for this plug-in to work. Please note that the plug-in is currently only minimally compatible with Internet Explorer 7 and earlier, due to limitations within those browsers.
 
 
30
 
31
 
32
  == Installation ==
46
 
47
  == Changelog ==
48
 
49
+ = 1.0 =
50
+ * Fix unexpected page ordering results when pages have not been explictly ordered yet (sorts by menu_order, then title, not just menu_order)
51
+ * Support for ordering non-hierarchical post types that have "page-attributes" support
52
+ * New filter link for "Sort by Order" to restore (hierarchical) or set (non-hierarchical, page attributes support) post list sort to menu order
53
+ * Fix "per page" drop down filter selection not saving between page loads (was broken in 3.1)
54
+ * Users are now forced to wait for current sort operation to finish before they can sort another item
55
+ * Smarter about "not sortable" view states
56
+ * Localization ready! Rough Spanish translation included.
57
+ * Items are always ordered with positive integers (potential negative sort orders had some performance benefits in last version, but sometimes caused issues)
58
+ * Assorted other performance and code improvements
59
+
60
  = 0.9.6 =
61
  * Fix for broken inline editing (quick edit) fields in Firefox
62
 
screenshot-1.png CHANGED
Binary file
simple-page-ordering.js CHANGED
@@ -1,5 +1,3 @@
1
- if ( jQuery('table.widefat th.sorted').length < 1 ) {
2
-
3
  jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move');
4
 
5
  jQuery("table.widefat tbody").sortable({
@@ -19,9 +17,12 @@ jQuery("table.widefat tbody").sortable({
19
  },
20
  stop: function(event, ui) {
21
  ui.item.removeAttr('style');
22
- ui.item.children('td,th').css('border-bottom-width','1px');
23
  },
24
  update: function(event, ui) {
 
 
 
25
  var postid = ui.item.find('.check-column input').val(); // this post id
26
  var postparent = ui.item.find('.post_parent').html(); // post parent
27
 
@@ -45,7 +46,9 @@ jQuery("table.widefat tbody").sortable({
45
  // if previous and next not at same tree level, or next not at same tree level and the previous is the parent of the next, or just moved item beneath its own children
46
  if ( ( prevpostid == undefined && nextpostid == undefined ) || ( nextpostid == undefined && nextpostparent == prevpostid ) || ( nextpostid != undefined && prevpostparent == postid ) ) {
47
  jQuery("table.widefat tbody").sortable('cancel');
48
- alert( "Items can only be repositioned within their current branch in the page tree / hierarchy (next to pages with the same parent).\n\nIf you want to move this item into a different part of the page tree, use the Quick Edit feature to change the parent before continuing." );
 
 
49
  return;
50
  }
51
 
@@ -59,6 +62,8 @@ jQuery("table.widefat tbody").sortable({
59
  var changes = jQuery.parseJSON(response);
60
  jQuery.each(changes, function(key,value) { jQuery('#inline_'+key+' .menu_order').html(value); });
61
  ui.item.find('.check-column input').show().siblings('img').remove();
 
 
62
  }
63
  });
64
 
@@ -69,6 +74,4 @@ jQuery("table.widefat tbody").sortable({
69
  else jQuery(this).removeClass('alternate');
70
  });
71
  }
72
- });
73
-
74
- }
 
 
1
  jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move');
2
 
3
  jQuery("table.widefat tbody").sortable({
17
  },
18
  stop: function(event, ui) {
19
  ui.item.removeAttr('style');
20
+ ui.item.children('td,th').css('border-bottom-width','1px');
21
  },
22
  update: function(event, ui) {
23
+ jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','default');
24
+ jQuery("table.widefat tbody").sortable('disable');
25
+
26
  var postid = ui.item.find('.check-column input').val(); // this post id
27
  var postparent = ui.item.find('.post_parent').html(); // post parent
28
 
46
  // if previous and next not at same tree level, or next not at same tree level and the previous is the parent of the next, or just moved item beneath its own children
47
  if ( ( prevpostid == undefined && nextpostid == undefined ) || ( nextpostid == undefined && nextpostparent == prevpostid ) || ( nextpostid != undefined && prevpostparent == postid ) ) {
48
  jQuery("table.widefat tbody").sortable('cancel');
49
+ alert( simple_page_ordering_l10n.RepositionTree );
50
+ jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move');
51
+ jQuery("table.widefat tbody").sortable('enable');
52
  return;
53
  }
54
 
62
  var changes = jQuery.parseJSON(response);
63
  jQuery.each(changes, function(key,value) { jQuery('#inline_'+key+' .menu_order').html(value); });
64
  ui.item.find('.check-column input').show().siblings('img').remove();
65
+ jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move');
66
+ jQuery("table.widefat tbody").sortable('enable');
67
  }
68
  });
69
 
74
  else jQuery(this).removeClass('alternate');
75
  });
76
  }
77
+ });
 
 
simple-page-ordering.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Simple Page Ordering
4
  Plugin URI: http://www.get10up.com/plugins/simple-page-ordering-wordpress/
5
  Description: Order your pages and hierarchical post types using drag and drop on the built in page list. Also adds a filter for items to show per page. For further instructions, open the "Help" tab on the Pages screen.
6
- Version: 0.9.6
7
  Author: Jake Goldman (10up)
8
  Author URI: http://www.get10up.com
9
 
@@ -24,54 +24,61 @@
24
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
- class simple_page_ordering
28
- {
29
- function simple_page_ordering()
30
- {
31
- add_filter( 'edit_posts_per_page', array( $this, 'edit_posts_per_page' ), 10, 2 );
32
  add_action( 'wp_ajax_simple_page_ordering', array( $this, 'ajax_simple_page_ordering' ) );
33
  }
34
 
35
- function edit_posts_per_page( $per_page, $post_type )
36
- {
37
- if ( !current_user_can('edit_others_pages') ) // check permission
38
- return $per_page;
 
 
 
 
 
 
39
 
40
- $post_type_object = get_post_type_object( $post_type );
41
- if ( !$post_type_object->hierarchical ) // only hierarchical post types apply
42
- return $per_page;
43
-
44
- add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) ); // posts per page drop down UI
45
- wp_enqueue_script( 'simple-page-ordering', plugin_dir_url( __FILE__ ) . '/simple-page-ordering.js', array('jquery-ui-sortable'), '0.9.5', true );
46
- add_filter( 'contextual_help', array( $this, 'contextual_help' ) );
47
 
48
- if ( isset( $_GET['spo'] ) && is_numeric( $_GET['spo'] ) && ( $_GET['spo'] == -1 || ($_GET['spo']%10) == 0 ) ) :
49
 
50
- global $edit_per_page, $user_ID;
51
-
52
- $per_page = $_GET['spo'];
53
-
54
- if ( $per_page == -1 )
55
- $per_page = 99999;
56
-
57
- update_user_option( $user_ID, $edit_per_page, $per_page );
58
 
59
- endif;
60
 
61
- return $per_page;
 
 
 
 
 
 
62
  }
63
 
64
  function restrict_manage_posts()
65
  {
66
  global $per_page;
67
 
68
- $spo = isset($_GET['spo']) ? (int)$_GET['spo'] : $per_page;
69
  ?>
70
- <select name="spo" style="width: 110px;">
71
- <option<?php selected( $spo, -1 ); ?> value="-1"><?php _e('Show all'); ?></option>
72
  <?php for( $i=10;$i<=100;$i+=10 ) : ?>
73
- <option<?php selected( $spo, $i ); ?> value="<?php echo $i; ?>"><?php echo $i; ?> <?php _e('per page'); ?></option>
74
- <?php endfor; ?>
 
 
 
75
  </select>
76
  <?php
77
  }
@@ -79,93 +86,82 @@ class simple_page_ordering
79
  function contextual_help( $help )
80
  {
81
  return $help . '
82
- <p><strong>'. __( 'Simple Page Ordering' ) . '</strong></p>
83
- <p><a href="http://www.get10up.com/plugins/simple-page-ordering-wordpress/" target="_blank">Simple Page Ordering</a> is a plug-in by <a href="http://www.get10up.com" target="_blank">Jake Goldman (10up)</a>) that allows you to order pages and other hierarchical post types with drag and drop.</p>
84
- <p>To reposition an item, simply drag and drop the row by "clicking and holding" it anywhere (outside of the links and form controls) and moving it to its new position.</p>
85
- <p>If you have a large number of pages, it may be helpful to adjust the new "items per page" filter located above the table and before the filter button.</p>
86
- <p>To keep things relatively simple, the current version only allows you to reposition items within their current tree / hierarchy (next to pages with the same parent). If you want to move an item into or out of a different part of the page tree, use the "quick edit" feature to change the parent.</p>
87
  ';
88
  }
89
 
90
- function ajax_simple_page_ordering()
91
- {
92
  // check permissions again and make sure we have what we need
93
- if ( !current_user_can('edit_others_pages') || empty($_POST['id']) || ( !isset($_POST['previd']) && !isset($_POST['nextid']) ) )
94
- die(-1);
95
 
96
  // real post?
97
- if ( !$post = get_post( $_POST['id'] ) )
98
  die(-1);
99
 
100
- $previd = isset($_POST['previd']) ? $_POST['previd'] : false;
101
- $nextid = isset($_POST['nextid']) ? $_POST['nextid'] : false;
102
  $new_pos = array(); // store new positions for ajax
103
 
104
- if ( $previd )
105
- {
106
- $siblings = get_posts(array( 'depth' => 1, 'numberposts' => -1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->post_parent, 'orderby' => 'menu_order', 'order' => 'ASC', 'exclude' => $post->ID )); // fetch all the siblings (relative ordering)
107
-
108
- foreach( $siblings as $sibling ) :
109
-
110
- // start updating menu orders
111
- if ( $sibling->ID == $previd ) {
112
- $menu_order = $sibling->menu_order + 1;
113
- wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
114
- $new_pos[$post->ID] = $menu_order;
115
- continue;
116
- }
117
-
118
- // nothing left to do - numbers already sufficiently padded!
119
- if ( isset($menu_order) && $menu_order < $sibling->menu_order )
120
- break;
121
-
122
- // need to update this sibling's menu order too
123
- if ( isset($menu_order) ) {
124
- $menu_order++;
125
- wp_update_post(array( 'ID' => $sibling->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
126
- $new_pos[$sibling->ID] = $menu_order;
127
- }
128
-
129
- endforeach;
130
 
131
- }
132
 
133
- if ( !isset($menu_order) && $nextid ) {
 
 
 
 
 
134
 
135
- $siblings = get_posts(array( 'depth' => 1, 'numberposts' => -1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->post_parent, 'orderby' => 'menu_order', 'order' => 'DESC', 'exclude' => $post->ID )); // fetch all the siblings (relative ordering)
 
 
136
 
137
- foreach( $siblings as $sibling ) :
138
-
139
- // start updating menu orders
140
- if ( $sibling->ID == $nextid ) {
141
- $menu_order = $sibling->menu_order - 1;
142
- wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
143
- $new_pos[$post->ID] = $menu_order;
144
- continue;
145
- }
146
-
147
- // nothing left to do - numbers already sufficiently padded!
148
- if ( isset($menu_order) && $menu_order > $sibling->menu_order )
149
- break;
150
-
151
- // need to update this sibling's menu order too
152
- if ( isset($menu_order) ) {
153
- $menu_order--;
154
- wp_update_post(array( 'ID' => $sibling->ID, 'menu_order' => $menu_order )); // update the actual moved post to 1 after prev
155
- $new_pos[$sibling->ID] = $menu_order;
156
- }
157
 
158
- endforeach;
 
 
 
 
159
 
160
- }
161
 
162
  // if the moved post has children, we need to refresh the page
163
- $children = get_posts(array( 'depth' => 1, 'numberposts' => 1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->ID )); // fetch all the siblings (relative ordering)
164
- if ( !empty($children) )
165
  die('children');
166
 
167
  die( json_encode($new_pos) );
168
  }
 
 
 
 
 
 
 
 
 
169
  }
170
 
171
  if ( is_admin() )
3
  Plugin Name: Simple Page Ordering
4
  Plugin URI: http://www.get10up.com/plugins/simple-page-ordering-wordpress/
5
  Description: Order your pages and hierarchical post types using drag and drop on the built in page list. Also adds a filter for items to show per page. For further instructions, open the "Help" tab on the Pages screen.
6
+ Version: 1.0
7
  Author: Jake Goldman (10up)
8
  Author URI: http://www.get10up.com
9
 
24
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
+ class simple_page_ordering {
28
+
29
+ function simple_page_ordering() {
30
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
31
+ add_action( 'load-edit.php', array( $this, 'load_edit_screen' ) );
32
  add_action( 'wp_ajax_simple_page_ordering', array( $this, 'ajax_simple_page_ordering' ) );
33
  }
34
 
35
+ function admin_init() {
36
+ load_plugin_textdomain( 'simple-page-ordering', false, dirname( plugin_basename( __FILE__ ) ) . '/localization/' );
37
+ }
38
+
39
+ function load_edit_screen() {
40
+ add_action( 'wp', array( $this, 'wp_edit' ) );
41
+ }
42
+
43
+ function wp_edit() {
44
+ global $post_type, $wp_query;
45
 
46
+ if ( ! current_user_can('edit_others_pages') || ( ! post_type_supports( $post_type, 'page-attributes' ) && ! is_post_type_hierarchical( $post_type ) ) ) // check permission
47
+ return;
 
 
 
 
 
48
 
49
+ add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) ); // posts per page drop down UI
50
 
51
+ if ( isset( $_GET['per_page'] ) && ( $_GET['per_page'] == 99999 || ( $_GET['per_page']%10 ) == 0 ) )
52
+ update_user_option( get_current_user_id(), 'edit_' . $post_type . '_per_page', (int) $_GET['per_page'] );
53
+
54
+ add_filter( 'views_' . get_current_screen()->id, array( $this, 'sort_by_order_link' ) ); // add view by menu order to views
55
+ add_filter( 'contextual_help', array( $this, 'contextual_help' ) ); // add contextual help to hierarchical post screens
 
 
 
56
 
57
+ if ( $wp_query->query['orderby'] == 'menu_order title' ) { // we can only sort if we're organized by menu order; WP 3.2 and 3.1 versions
58
 
59
+ wp_enqueue_script( 'simple-page-ordering', plugin_dir_url( __FILE__ ) . 'simple-page-ordering.js', array('jquery-ui-sortable'), '0.9.7', true );
60
+ $js_trans = array(
61
+ 'RepositionTree' => __("Items can only be repositioned within their current branch in the page tree / hierarchy (next to pages with the same parent).\n\nIf you want to move this item into a different part of the page tree, use the Quick Edit feature to change the parent before continuing.", 'simple-page-ordering')
62
+ );
63
+ wp_localize_script( 'simple-page-ordering', 'simple_page_ordering_l10n', $js_trans );
64
+
65
+ }
66
  }
67
 
68
  function restrict_manage_posts()
69
  {
70
  global $per_page;
71
 
72
+ $per_page = isset( $_GET['per_page'] ) ? (int) $_GET['per_page'] : $per_page;
73
  ?>
74
+ <select name="per_page" style="width: 110px;">
75
+ <option <?php selected( $per_page, 99999 ); ?> value="99999"><?php _e( 'Show all', 'simple-page-ordering' ); ?></option>
76
  <?php for( $i=10;$i<=100;$i+=10 ) : ?>
77
+ <option <?php selected( $per_page, $i ); ?> value="<?php echo $i; ?>"><?php echo $i; ?> <?php _e( 'per page', 'simple-page-ordering' ); ?></option>
78
+ <?php endfor; ?>
79
+ <?php if ( $per_page != -1 && $per_page != 99999 && ( $per_page%10 != 0 || $per_page > 100 ) ) : ?>
80
+ <option <?php selected( true ); ?> value="<?php echo (int) $per_page; ?>"><?php echo (int) $per_page; ?> <?php _e( 'per page', 'simple-page-ordering' ); ?></option>
81
+ <?php endif; ?>
82
  </select>
83
  <?php
84
  }
86
  function contextual_help( $help )
87
  {
88
  return $help . '
89
+ <p><strong>'. __( 'Simple Page Ordering', 'simple_page_ordering' ) . '</strong></p>
90
+ <p><a href="http://www.get10up.com/plugins/simple-page-ordering-wordpress/" target="_blank">' . __( 'Simple Page Ordering', 'simple_page_ordering' ) . '</a> ' . __( 'is a plug-in by', 'simple-page-ordering' ) . ' <a href="http://www.get10up.com" target="_blank">Jake Goldman (10up)</a> ' . __( 'that allows you to order pages and other hierarchical post types with drag and drop.', 'simple-page-ordering' ) . '</p>
91
+ <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>
92
+ <p>' . __( 'If you have a large number of pages, it may be helpful to adjust the new "items per page" filter located above the table and before the filter button.', 'simple-page-ordering' ) . '</p>
93
+ <p>' . __( 'To keep things relatively simple, the current version only allows you to reposition items within their current tree / hierarchy (next to pages with the same parent). If you want to move an item into or out of a different part of the page tree, use the "quick edit" feature to change the parent.', 'simple-page-ordering' ) . '</p>
94
  ';
95
  }
96
 
97
+ function ajax_simple_page_ordering() {
 
98
  // check permissions again and make sure we have what we need
99
+ if ( ! current_user_can('edit_others_pages') || empty( $_POST['id'] ) || ( ! isset( $_POST['previd'] ) && ! isset( $_POST['nextid'] ) ) )
100
+ die(-1);
101
 
102
  // real post?
103
+ if ( ! $post = get_post( $_POST['id'] ) )
104
  die(-1);
105
 
106
+ $previd = isset( $_POST['previd'] ) ? $_POST['previd'] : false;
107
+ $nextid = isset( $_POST['nextid'] ) ? $_POST['nextid'] : false;
108
  $new_pos = array(); // store new positions for ajax
109
 
110
+ $siblings = get_posts(array(
111
+ 'depth' => 1,
112
+ 'numberposts' => -1,
113
+ 'post_type' => $post->post_type,
114
+ 'post_status' => 'publish,pending,draft,future,private',
115
+ 'post_parent' => $post->post_parent,
116
+ 'orderby' => 'menu_order title',
117
+ 'order' => 'ASC',
118
+ 'exclude' => $post->ID
119
+ )); // fetch all the siblings (relative ordering)
120
+
121
+ $menu_order = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
+ foreach( $siblings as $sibling ) :
124
 
125
+ // if this is the post that comes after our repositioned post, set our repositioned post position and increment menu order
126
+ if ( $nextid == $sibling->ID ) {
127
+ wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order ));
128
+ $new_pos[$post->ID] = $menu_order;
129
+ $menu_order++;
130
+ }
131
 
132
+ // if repositioned post has been set, and new items are already in the right order, we can stop
133
+ if ( isset( $new_pos[$post->ID] ) && $sibling->menu_order >= $menu_order )
134
+ break;
135
 
136
+ // set the menu order of the current sibling and increment the menu order
137
+ wp_update_post(array( 'ID' => $sibling->ID, 'menu_order' => $menu_order ));
138
+ $new_pos[$sibling->ID] = $menu_order;
139
+ $menu_order++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
+ if ( ! $nextid && $previd == $sibling->ID ) {
142
+ wp_update_post(array( 'ID' => $post->ID, 'menu_order' => $menu_order ));
143
+ $new_pos[$post->ID] = $menu_order;
144
+ $menu_order++;
145
+ }
146
 
147
+ endforeach;
148
 
149
  // if the moved post has children, we need to refresh the page
150
+ $children = get_posts(array( 'depth' => 1, 'numberposts' => 1, 'post_type' => $post->post_type, 'post_status' => 'publish,pending,draft,future,private', 'post_parent' => $post->ID ));
151
+ if ( ! empty( $children ) )
152
  die('children');
153
 
154
  die( json_encode($new_pos) );
155
  }
156
+
157
+ function sort_by_order_link( $views ) {
158
+ global $post_type, $wp_query;
159
+ $class = ( $wp_query->query['orderby'] == 'menu_order title' ) ? 'current' : '';
160
+ $query_string = remove_query_arg(array( 'orderby', 'order' ));
161
+ $query_string = add_query_arg( 'orderby', urlencode('menu_order title'), $query_string );
162
+ $views['byorder'] = '<a href="'. $query_string . '" class="' . $class . '">Sort by Order</a>';
163
+ return $views;
164
+ }
165
  }
166
 
167
  if ( is_admin() )