WordPress.org

Plugin Directory

Changeset 624212


Ignore:
Timestamp:
11/12/12 21:24:07 (17 months ago)
Author:
jakemgold
Message:

Big update - version 2.0. Drag into different hierarchies, more scalable, and more!

Location:
simple-page-ordering/trunk
Files:
3 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • simple-page-ordering/trunk/localization/simple-page-ordering-es_ES.po

    r404246 r624212  
    66"Report-Msgid-Bugs-To: \n" 
    77"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" 
     8"PO-Revision-Date: 2012-09-15 16:33-0800\n" 
     9"Last-Translator: Jacob Goldman <jake@10up.com>\n" 
    1010"Language-Team: 10up <jake@get10up.com>\n" 
    1111"MIME-Version: 1.0\n" 
    1212"Content-Type: text/plain; charset=UTF-8\n" 
    1313"Content-Transfer-Encoding: 8bit\n" 
    14 "X-Poedit-Language: Spanish\n" 
     14"Language: es\n" 
    1515 
    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 
     16#: simple-page-ordering.php:63 
     17#, fuzzy 
    3918msgid "is a plug-in by" 
    4019msgstr "es un plug-in por" 
    4120 
    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." 
     21#: simple-page-ordering.php:63 
     22#, fuzzy 
     23msgid "" 
     24"that  allows you to order pages and other hierarchical post types with drag " 
     25"and drop." 
     26msgstr "" 
     27"que le permite ordenar las páginas y otros tipos de mensaje jerárquica con " 
     28"arrastrar y soltar." 
    4529 
    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." 
     30#: simple-page-ordering.php:64 
     31#, fuzzy 
     32msgid "" 
     33"To reposition an item, simply drag and drop the row by \"clicking and holding" 
     34"\" it anywhere (outside of the links and form controls) and moving it to its " 
     35"new position." 
     36msgstr "" 
     37"Para cambiar la posición de un elemento, basta con arrastrar y soltar en la " 
     38"fila de \"clic y manteniendo\" en cualquier lugar (fuera de los vínculos y " 
     39"formar controles) y moverla a su nueva posición." 
    4940 
    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  
     41#: simple-page-ordering.php:64 
     42#, fuzzy 
     43msgid "" 
     44"If you have a large number of pages, it may be helpful to adjust the items " 
     45"shown per page by opening the Screen Options tab." 
     46msgstr "" 
     47"Si usted tiene un gran número de páginas, puede ser útil para ajustar los " 
     48"elementos que se muestran por página, abra la pestaña Opciones de la " 
     49"pantalla." 
  • simple-page-ordering/trunk/readme.txt

    r442857 r624212  
    11=== Simple Page Ordering === 
    22Contributors: jakemgold, 10up, thinkoomph 
    3 Donate link: http://get10up.com/plugins/simple-page-ordering-wordpress/ 
     3Donate link: http://10up.com/plugins/simple-page-ordering-wordpress/ 
    44Tags: 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 
     5Requires at least: 3.2 
     6Tested up to: 3.4.2 
     7Stable tag: 2.0 
    88 
    9 Order your pages and other hierarchical post types with simple drag and drop. Also adds a drop down to change items per page. 
     9Order your pages and other hierarchical post types with simple drag and drop right from the standard page list. 
    1010 
    1111== Description == 
    1212 
    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.  
     13Order 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.  
    1414 
    15 The following video is from an early build (0.7) that has been significantly refined, but still demonstrates the concept. 
     15Simply 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. 
    1616 
    17 [youtube http://www.youtube.com/watch?v=wWEVW78VF30] 
     17The plug-in is "capabilities aware" - only users with the ability to edit others' pages (editors and administrators) will be able to reorder content. 
    1818 
    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. 
     19Integrated help is included: just click the "help" tab at the top right of the screen. 
    2020 
    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. 
     21Please note that the plug-in is currently only minimally compatible with Internet Explorer 7 and earlier, due to limitations within those browsers. 
    3022 
    3123 
    3224== Installation == 
    3325 
    34 1. Install easily with the WordPress plugin control panel or manually download the plugin and upload the extracted 
    35 folder to the `/wp-content/plugins/` directory 
    36 1. Activate the plugin through the 'Plugins' menu in WordPress 
    37 1. Start dragging and dropping by going to the "Page" admin menu (or custom post type equivalent)! 
     261. Install either via the WordPress.org plugin directory, or by uploading the files to your server. 
     271. Activate the plugin through the 'Plugins' menu in WordPress. 
     281. Get to work reordering your content! 
     29 
     30 
     31== Frequently Asked Questions == 
     32 
     33= Why can't I reorder my posts? = 
     34 
     35Generic posts are not displayed by menu order - they're displayed by chronology. You can theoretically add menu ordering to posts in your code (theme functions.php, plug-in) by using: 
     36 
     37`add_post_type_support( 'post', 'page-attributes' );` 
     38 
     39= Can I make my custom post type take advantage of this plug-in? = 
     40 
     41Yep. There are two ways to turn on support for Simple Page Ordering. 
     42 
     43Ideally, when you register the post type, set `hierarchical` to `true` - hierarchical post types natively order by menu order. 
     44 
     45Alternatively, when you define the features the post type supports, include `page-attributes`. This will add a `Sort by Order` option to the filter links above the drop downs. Once you sort by order, you can drag and drop the content. 
     46 
     47Finally, you can take advantage of the `simple_page_ordering_is_sortable` filter, which passes the result of the default check and the post type name, to override default behavior. 
     48 
     49= I want my non-hierarchical post type to be sortable. Help! = 
     50 
     51See the previous two answers - just add `page-attributes` to the list of supported post type features. 
     52 
     53= I reordered my posts, but the order didn't change on the front end of my site! = 
     54 
     55This plug-in doesn't change any *behavior* on the front end, it simply changes the menu order stored in WordPress. 
     56 
     57If you want a list of pages or custom post types to display in that defined order, you must change the post query's `orderby` parameter to `menu_order` (if it's not already). 
     58 
     59= I reordered my content, it seemed to work, but when I refreshed, it went back to the old order! =  
     60 
     61This most likely means the AJAX request - the server side code - failed after you dropped the content into the new position. Some shared hosts aggressively time out and limit AJAX requests. Version 2.0 batches these requests so you can try reducing the number of items it updates on each request using a filter in your theme's functions.php or a custom plug-in: 
     62 
     63`add_filter( 'simple_page_ordering_limit', function($number) { return 5; } );` 
     64 
     65Where 5 is the number of items to batch on each request (the default is 50). Note that this example uses PHP 5.3+ callback functions, so if you're still on PHP 5.2, you'll need to add a traditional callback.  
     66 
     67= What happened to the drop down box that let me change the number of items on each page in the admin?? = 
     68 
     69This 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. 
    3870 
    3971 
    4072== Screenshots == 
    4173 
    42 1. Changing the paging (items per page) 
    43741. Dragging the page to its new position 
    44751. Processing indicator 
     
    4677 
    4778== Changelog == 
     79 
     80= 2.0 = 
     81* Drag pages into any part of the page hierarchy! No longer limited to same branch of tree! 
     82* Big performance improvements under the hood: leaner queries, batched requests, less processing 
     83* Scales much more reliably in situations with very high page counts due to batching of requests 
     84* Order of the first page is now set to "1" instead of "0", so pages added after ordering are added at the top (instead of second) 
     85* Removed "number of pages" drop down, which is repetitive of a field accessible under Screen Options 
     86* New filters and hooks to extend / override default functionality 
     87* Improved compatibility with newer versions of WordPress 
    4888 
    4989= 1.0 = 
  • simple-page-ordering/trunk/simple-page-ordering.js

    r404246 r624212  
    1 jQuery('table.widefat tbody th, table.widefat tbody td').css('cursor','move'); 
    2      
    3 jQuery("table.widefat tbody").sortable({ 
    4     items: 'tr:not(.inline-edit-row)', 
    5     cursor: 'move', 
    6     axis: 'y', 
    7     containment: 'table.widefat', 
    8     scrollSensitivity: 40, 
    9     helper: function(e, ui) {                    
    10         ui.children().each(function() { jQuery(this).width(jQuery(this).width()); }); 
    11         return ui; 
    12     }, 
    13     start: function(event, ui) { 
    14         if ( ! ui.item.hasClass('alternate') ) ui.item.css( 'background-color', '#ffffff' ); 
    15         ui.item.children('td,th').css('border-bottom-width','0'); 
    16         ui.item.css( 'outline', '1px solid #dfdfdf' ); 
    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          
    29         var prevpostid = ui.item.prev().find('.check-column input').val(); 
    30         var nextpostid = ui.item.next().find('.check-column input').val(); 
    31          
    32         // can only sort in same tree 
    33                  
    34         var prevpostparent = undefined; 
    35         if ( prevpostid != undefined ) { 
    36             var prevpostparent = ui.item.prev().find('.post_parent').html() 
    37             if ( prevpostparent != postparent) prevpostid = undefined; 
    38         } 
    39          
    40         var nextpostparent = undefined; 
    41         if ( nextpostid != undefined ) { 
    42             nextpostparent = ui.item.next().find('.post_parent').html(); 
    43             if ( nextpostparent != postparent) nextpostid = undefined; 
    44         }    
    45          
    46         // if previous and next not at same tree level, or next not at same tree level and the previous is the parent of the next, or just moved item beneath its own children                   
    47         if ( ( prevpostid == undefined && nextpostid == undefined ) || ( nextpostid == undefined && nextpostparent == prevpostid ) || ( nextpostid != undefined && prevpostparent == postid ) ) { 
    48             jQuery("table.widefat tbody").sortable('cancel'); 
    49             alert( 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                      
    55         // show spinner 
    56         ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'); 
    57          
    58         // go do the sorting stuff via ajax 
    59         jQuery.post( ajaxurl, { action: 'simple_page_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, function(response){            
    60             if ( response == 'children' ) window.location.reload(); 
    61             else { 
    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          
    70         // fix cell colors 
    71         jQuery( 'table.widefat tbody tr' ).each(function(){ 
    72             var i = jQuery('table.widefat tbody tr').index(this); 
    73             if ( i%2 == 0 ) jQuery(this).addClass('alternate'); 
    74             else jQuery(this).removeClass('alternate'); 
    75         }); 
    76     } 
    77 }); 
     1function update_simple_ordering_callback(response){if(response=='children'){window.location.reload();return}var changes=jQuery.parseJSON(response);var new_pos=changes.new_pos;for(key in new_pos){if(key=='next')continue;if(jQuery('#inline_'+key).length>0){if(new_pos[key]['menu_order']!=null){jQuery('#inline_'+key+' .menu_order').html(new_pos[key]['menu_order']);jQuery('#inline_'+key+' .post_parent').html(new_pos[key]['post_parent']);var post_title=jQuery('#inline_'+key+' .post_title').html();var dashes=0;while(dashes<new_pos[key]['depth']){post_title='&mdash; '+post_title;dashes++}jQuery('tr#post-'+key+' a.row-title').html(post_title)}else{jQuery('#inline_'+key+' .menu_order').html(new_pos[key])}}}if(changes.next){jQuery.post(ajaxurl,{action:'simple_page_ordering',id:changes.next['id'],previd:changes.next['previd'],nextid:changes.next['nextid'],start:changes.next['start'],excluded:changes.next['excluded']},update_simple_ordering_callback)}else{jQuery('.check-column .waiting').siblings('input').show().siblings('img').remove();jQuery('tr.iedit').css('cursor','move');jQuery(".wp-list-table tbody").sortable('enable')}}jQuery('tr.iedit').css('cursor','move');jQuery(".wp-list-table tbody").sortable({items:'tr:not(.inline-edit-row)',cursor:'move',axis:'y',containment:'table.widefat',scrollSensitivity:40,helper:function(e,ui){ui.children().each(function(){jQuery(this).width(jQuery(this).width())});return ui},start:function(event,ui){if(!ui.item.hasClass('alternate'))ui.item.css('background-color','#ffffff');ui.item.children('td,th').css('border-bottom-width','0');ui.item.css('outline','1px solid #dfdfdf')},stop:function(event,ui){ui.item.removeAttr('style');ui.item.children('td,th').css('border-bottom-width','1px')},update:function(event,ui){jQuery('tr.iedit').css('cursor','default');jQuery(".wp-list-table tbody").sortable('disable');var postid=ui.item.attr('id').substr(5);var prevpostid=false;var prevpost=ui.item.prev();if(prevpost.length>0)prevpostid=prevpost.attr('id').substr(5);var nextpostid=false;var nextpost=ui.item.next();if(nextpost.length>0)nextpostid=nextpost.attr('id').substr(5);ui.item.find('.check-column input').hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />');jQuery.post(ajaxurl,{action:'simple_page_ordering',id:postid,previd:prevpostid,nextid:nextpostid},update_simple_ordering_callback);jQuery('tr.iedit').each(function(i){if(i%2==0)jQuery(this).addClass('alternate');else jQuery(this).removeClass('alternate')})}}); 
  • simple-page-ordering/trunk/simple-page-ordering.php

    r404246 r624212  
    11<?php 
    22/** 
    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  
    10     Plugin: Copyright 2011 10up  (email : jake@get10up.com) 
    11  
    12     This program is free software; you can redistribute it and/or modify 
    13     it under the terms of the GNU General Public License as published by 
    14     the Free Software Foundation; either version 2 of the License, or 
    15     (at your option) any later version. 
    16  
    17     This program is distributed in the hope that it will be useful, 
    18     but WITHOUT ANY WARRANTY; without even the implied warranty of 
    19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    20     GNU General Public License for more details. 
    21  
    22     You should have received a copy of the GNU General Public License 
    23     along with this program; if not, write to the Free Software 
    24     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    25 */ 
    26  
    27 class simple_page_ordering { 
    28      
    29     function simple_page_ordering() { 
    30         add_action( 'admin_init', array( $this, 'admin_init' ) ); 
     3Plugin Name: Simple Page Ordering 
     4Plugin URI: http://10up.com/plugins/simple-page-ordering-wordpress/ 
     5Description: 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. 
     6Version: 2.0 
     7Author: Jake Goldman, 10up, Oomph 
     8Author URI: http://10up.com 
     9License: GPLv2 or later 
     10 
     11This plug-in is was created by Jake Goldman with original copyright 
     12attributions for purposes of GPL enforcement assigned to Oomph Inc 
     13(pre-1.0). All modifications, updates, and support since February 2011 
     14have been provided by 10up LLC and Jake Goldman from that date forward, 
     15including the near rewrite, version 2.0. 
     16 
     17This program is free software; you can redistribute it and/or modify 
     18it under the terms of the GNU General Public License as published by 
     19the Free Software Foundation; either version 2 of the License, or 
     20(at your option) any later version. 
     21 
     22This program is distributed in the hope that it will be useful, 
     23but WITHOUT ANY WARRANTY; without even the implied warranty of 
     24MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     25GNU General Public License for more details. 
     26 
     27You should have received a copy of the GNU General Public License 
     28along with this program; if not, write to the Free Software 
     29Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
     30 */ 
     31 
     32class Simple_Page_Ordering { 
     33 
     34    public function __construct() { 
    3135        add_action( 'load-edit.php', array( $this, 'load_edit_screen' ) ); 
    3236        add_action( 'wp_ajax_simple_page_ordering', array( $this, 'ajax_simple_page_ordering' ) ); 
    3337    } 
    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 
     38 
     39    public function load_edit_screen() { 
     40        if ( ! current_user_can('edit_others_pages') ) 
    4741            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     } 
    85      
    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() { 
     42 
     43        $screen = get_current_screen(); 
     44        $sortable = ( post_type_supports( $screen->post_type, 'page-attributes' ) || is_post_type_hierarchical( $screen->post_type ) );     // check permission 
     45        $sortable = apply_filters( 'simple_page_ordering_is_sortable', $sortable, $screen->post_type ); 
     46        if ( ! $sortable ) 
     47            return; 
     48 
     49        add_filter( 'views_' . $screen->id, array( $this, 'sort_by_order_link' )  );        // add view by menu order to views 
     50        add_action( 'wp', array( $this, 'wp' ) ); 
     51        add_action( 'admin_head', array( $this, 'admin_head' ) ); 
     52    } 
     53 
     54    public function wp() { 
     55        if ( strpos( get_query_var('orderby'), 'menu_order' ) === 0 ) { // we can only sort if we're organized by menu order 
     56            $script_name = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'simple-page-ordering.dev.js' : 'simple-page-ordering.js'; 
     57            wp_enqueue_script( 'simple-page-ordering', plugins_url( $script_name, __FILE__ ), array('jquery-ui-sortable'), '2.0', true ); 
     58        } 
     59    } 
     60 
     61    public function admin_head() { 
     62        $screen = get_current_screen(); 
     63        $screen->add_help_tab(array( 
     64            'id' => 'simple_page_ordering_help_tab', 
     65            'title' => 'Simple Page Ordering', 
     66            '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>', 
     67        )); 
     68    } 
     69 
     70    public function ajax_simple_page_ordering() { 
    9871        // 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'] ) ) ) 
     72        if ( !current_user_can( 'edit_others_pages' ) || empty( $_POST['id'] ) || ( !isset( $_POST['previd'] ) && !isset( $_POST['nextid'] ) ) ) 
    10073            die(-1); 
    101          
     74 
    10275        // real post? 
    10376        if ( ! $post = get_post( $_POST['id'] ) ) 
    10477            die(-1); 
    105          
    106         $previd = isset( $_POST['previd'] ) ? $_POST['previd'] : false; 
    107         $nextid = isset( $_POST['nextid'] ) ? $_POST['nextid'] : false; 
     78 
     79        // badly written plug-in hooks for save post can break things 
     80        error_reporting( 0 ); 
     81 
     82        $previd = empty( $_POST['previd'] ) ? false : (int) $_POST['previd']; 
     83        $nextid = empty( $_POST['nextid'] ) ? false : (int) $_POST['nextid']; 
     84        $start = empty( $_POST['start'] ) ? 1 : (int) $_POST['start']; 
     85        $excluded = empty( $_POST['excluded'] ) ? array( $post->ID ) : array_filter( (array) $_POST['excluded'], 'intval' ); 
     86 
    10887        $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  
     88        $return_data = new stdClass; 
     89 
     90        do_action( 'simple_page_ordering_pre_order_posts', $post, $start ); 
     91 
     92        // attempt to get the intended parent... if either sibling has a matching parent ID, use that 
     93        $parent_id = $post->post_parent; 
     94        //$prev_post_parent = $previd ? wp_get_post_parent_id( $previd ) : false; 
     95        $next_post_parent = $nextid ? wp_get_post_parent_id( $nextid ) : false; 
     96        if ( $previd == $next_post_parent ) {   // if the preceding post is the parent of the next most, move it inside 
     97            $parent_id = $next_post_parent; 
     98        } elseif ( $next_post_parent !== $parent_id ) {  // otherwise, if the next post's parent isn't the same as our parent, we need to study 
     99            $prev_post_parent = $previd ? wp_get_post_parent_id( $previd ) : false; 
     100            if ( $prev_post_parent !== $parent_id ) // if the previous post is not our parent now, make it so! 
     101                $parent_id = ( $prev_post_parent !== false ) ? $prev_post_parent : $next_post_parent; 
     102        } 
     103        // if the next post's parent isn't our parent, it might as well be false (irrelevant to our query) 
     104        if ( $next_post_parent !== $parent_id ) 
     105            $nextid = false; 
     106 
     107        $max_sortable_posts = (int) apply_filters( 'simple_page_ordering_limit', 50 );  // should reliably be able to do about 50 at a time 
     108        if ( $max_sortable_posts < 5 ) 
     109            $max_sortable_posts = 50; 
     110 
     111        $siblings = new WP_Query(array( 
     112            'depth'                     => 1, 
     113            'posts_per_page'            => $max_sortable_posts, 
     114            'post_type'                 => $post->post_type, 
     115            'post_status'               => array( 'publish' , 'pending', 'draft', 'future', 'private' ), 
     116            'post_parent'               => $parent_id, 
     117            'orderby'                   => 'menu_order title', 
     118            'order'                     => 'ASC', 
     119            'post__not_in'              => array_merge( $excluded ), 
     120            'update_post_term_cache'    => false, 
     121            'update_post_meta_cache'    => false, 
     122            'suppress_filters'          => true, 
     123            'ignore_sticky_posts'       => true, 
    119124        )); // fetch all the siblings (relative ordering) 
    120          
    121         $menu_order = 0; 
    122              
    123         foreach( $siblings as $sibling ) : 
    124          
     125 
     126        // don't waste overhead of revisions on a menu order change (especially since they can't *all* be rolled back at once) 
     127        remove_action( 'pre_post_update', 'wp_save_post_revision' ); 
     128 
     129        foreach( $siblings->posts as $sibling ) : 
     130 
     131            // don't handle the actual post 
     132            if ( $sibling->ID == $post->ID ) 
     133                continue; 
     134 
    125135            // if this is the post that comes after our repositioned post, set our repositioned post position and increment menu order 
    126136            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              
     137                wp_update_post(array( 
     138                    'ID'            => $post->ID, 
     139                    'menu_order'    => $start, 
     140                    'post_parent'   => $parent_id, 
     141                )); 
     142                $ancestors = get_post_ancestors( $post->ID ); 
     143                $new_pos[$post->ID] = array( 
     144                    'menu_order'    => $start, 
     145                    'post_parent'   => $parent_id, 
     146                    'depth'         => count( $ancestors ), 
     147                ); 
     148                $start++; 
     149            } 
     150 
    132151            // 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 ) 
     152            if ( isset( $new_pos[$post->ID] ) && $sibling->menu_order >= $start ) { 
     153                $return_data->next = false; 
    134154                break; 
    135              
     155            } 
     156 
    136157            // 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              
     158            if ( $sibling->menu_order != $start ) { 
     159                wp_update_post(array( 
     160                    'ID'            => $sibling->ID, 
     161                    'menu_order'    => $start, 
     162                )); 
     163            } 
     164            $new_pos[$sibling->ID] = $start; 
     165            $start++; 
     166 
     167            if ( !$nextid && $previd == $sibling->ID ) { 
     168                wp_update_post(array( 
     169                    'ID'            => $post->ID, 
     170                    'menu_order'    => $start, 
     171                    'post_parent'   => $parent_id 
     172                )); 
     173                $ancestors = get_post_ancestors( $post->ID ); 
     174                $new_pos[$post->ID] = array( 
     175                    'menu_order'    => $start, 
     176                    'post_parent'   => $parent_id, 
     177                    'depth'         => count($ancestors) ); 
     178                $start++; 
     179            } 
     180 
    147181        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' : ''; 
     182 
     183        // max per request 
     184        if ( !isset( $return_data->next ) && $siblings->max_num_pages > 1 ) { 
     185            $return_data->next = array( 
     186                'id'        => $post->ID, 
     187                'previd'    => $previd, 
     188                'nextid'    => $nextid, 
     189                'start'     => $start, 
     190                'excluded'  => array_merge( array_keys( $new_pos ), $excluded ), 
     191            ); 
     192        } else { 
     193            $return_data->next = false; 
     194        } 
     195 
     196        do_action( 'simple_page_ordering_ordered_posts', $post, $new_pos ); 
     197 
     198        if ( ! $return_data->next ) { 
     199            // if the moved post has children, we need to refresh the page (unless we're continuing) 
     200            $children = get_posts(array( 
     201                'numberposts'               => 1, 
     202                'post_type'                 => $post->post_type, 
     203                'post_status'               => array('publish','pending','draft','future','private'), 
     204                'post_parent'               => $post->ID, 
     205                'update_post_term_cache'    => false, 
     206                'update_post_meta_cache'    => false, 
     207            )); 
     208 
     209            if ( ! empty( $children ) ) 
     210                die( 'children' ); 
     211        } 
     212 
     213        $return_data->new_pos = $new_pos; 
     214 
     215        die( json_encode( $return_data ) ); 
     216    } 
     217 
     218    public function sort_by_order_link( $views ) { 
     219        $class = ( get_query_var('orderby') == 'menu_order title' ) ? 'current' : ''; 
    160220        $query_string = remove_query_arg(array( 'orderby', 'order' )); 
    161221        $query_string = add_query_arg( 'orderby', urlencode('menu_order title'), $query_string ); 
     
    165225} 
    166226 
    167 if ( is_admin() ) 
    168     $simple_page_ordering = new simple_page_ordering; 
     227$simple_page_ordering = new Simple_Page_Ordering; 
Note: See TracChangeset for help on using the changeset viewer.