Plugin Directory

Changeset 888474


Ignore:
Timestamp:
04/06/2014 08:31:46 PM (12 years ago)
Author:
jakemgold
Message:
  • Updated look and feel to better match WordPress 3.8 admin redesign
  • Improved awareness of and compatibility with Quick Edit (inline editor)
  • Prevent collisions with themes and plugins bundling Simple Page Ordering
Location:
simple-page-ordering
Files:
13 added
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • simple-page-ordering/trunk/readme.txt

    r720603 r888474  
    33Donate 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.4
    6 Tested up to: 3.6
    7 Stable tag: 2.1.2
     5Requires at least: 3.8
     6Tested up to: 3.9
     7Stable tag: 2.2
    88
    99Order your pages and other hierarchical post types with simple drag and drop right from the standard page list.
     
    7878== Changelog ==
    7979
     80= 2.2 =
     81* Updated look and feel to better match WordPress 3.8 admin redesign
     82* Improved awareness of and compatibility with Quick Edit (inline editor)
     83* Prevent collisions with themes and plugins bundling Simple Page Ordering
     84
    8085= 2.1.2 =
    8186* Bug fix: hierarchical custom post types without page-attributes was still broken - doh!
  • simple-page-ordering/trunk/simple-page-ordering.css

    r715085 r888474  
    22    cursor: move;
    33}
    4 .wp-list-table .spo-updating tr {
     4
     5.wp-list-table .spo-updating tr,
     6.wp-list-table .ui-sortable tr.inline-editor {
    57    cursor: default;
    68}
     9
    710.wp-list-table .ui-sortable-placeholder {
    8     border: 0;
    9     height: 51px;
    10     background: #808080;
    11     background-image: -webkit-gradient(linear, left bottom, left top, from(#6d6d6d), to(#808080));
    12     background-image: -webkit-linear-gradient(bottom, #6d6d6d, #808080);
    13     background-image:    -moz-linear-gradient(bottom, #6d6d6d, #808080);
    14     background-image:      -o-linear-gradient(bottom, #6d6d6d, #808080);
    15     background-image: linear-gradient(to top, #6d6d6d, #808080);
     11    outline: 1px dashed #bbb;
     12    background: #F1F1F1;
    1613    visibility: visible !important;
    1714}
    1815.wp-list-table .ui-sortable-helper {
    1916    background-color: #fff;
    20     margin-left: -1px;
    21     border: 1px solid #dfdfdf;
     17    outline: 1px solid #e1e1e1;
    2218}
    23 .wp-list-table .ui-sortable-helper th,
    24 .wp-list-table .ui-sortable-helper td {
    25     border-bottom-width: 0 !important;
    26 }
    27 
    2819.spo-updating-row .check-column {
    29     background: url('../../../wp-admin/images/wpspin_light.gif') center no-repeat;
     20    background: url('../../../wp-admin/images/spinner.gif') 11px 11px no-repeat;
    3021}
    3122@media print,
     
    3425(min-resolution: 120dpi) {
    3526    .spo-updating-row .check-column {
    36         background-image: url('../../../wp-admin/images/wpspin_light-2x.gif');
    37         background-size: 16px 16px;
     27        background-image: url('../../../wp-admin/images/spinner-2x.gif');
     28        background-size: 20px 20px;
    3829    }
    3930}
  • simple-page-ordering/trunk/simple-page-ordering.dev.js

    r720603 r888474  
    6464    axis: 'y',
    6565    containment: 'table.widefat',
    66     scrollSensitivity: 40,
    6766    cancel: '.inline-edit-row',
    68     distance: 5,
    69     opacity: .85,
    70     forceHelperSize: true,
     67    distance: 2,
     68    opacity: .8,
     69    tolerance: 'pointer',
     70    start: function(e, ui){
     71        if ( typeof(inlineEditPost) !== 'undefined' ) {
     72            inlineEditPost.revert();
     73        }
     74        ui.placeholder.height(ui.item.height());
     75    },
    7176    update: function(event, ui) {
    7277        sortable_post_table.sortable('disable').addClass('spo-updating');
     
    100105            }
    101106        }
     107        // fix quick edit
    102108    }
    103109});
  • simple-page-ordering/trunk/simple-page-ordering.js

    r720603 r888474  
    1 function update_simple_ordering_callback(e){if("children"===e){window.location.reload();return}var t=jQuery.parseJSON(e);var n=t.new_pos;for(var r in n){if("next"===r)continue;var i=document.getElementById("inline_"+r);if(null!==i&&n.hasOwnProperty(r)){var s=i.querySelector(".menu_order");if(undefined!==n[r]["menu_order"]){if(null!==s)s.innerHTML=n[r]["menu_order"];var o=i.querySelector(".post_parent");if(null!==o)o.innerHTML=n[r]["post_parent"];var u=null;var a=i.querySelector(".post_title");if(null!==a)u=a.innerHTML;var f=0;while(f<n[r]["depth"]){u="— "+u;f++}var l=i.parentNode.querySelector(".row-title");if(null!==l&&null!==u)l.innerHTML=u}else if(null!==s){s.innerHTML=n[r]}}}if(t.next){jQuery.post(ajaxurl,{action:"simple_page_ordering",id:t.next["id"],previd:t.next["previd"],nextid:t.next["nextid"],start:t.next["start"],excluded:t.next["excluded"]},update_simple_ordering_callback)}else{jQuery(document.querySelector(".spo-updating-row")).removeClass("spo-updating-row");sortable_post_table.removeClass("spo-updating").sortable("enable")}}var sortable_post_table=jQuery(document.querySelector(".wp-list-table tbody"));sortable_post_table.sortable({items:"> tr",cursor:"move",axis:"y",containment:"table.widefat",scrollSensitivity:40,cancel:".inline-edit-row",distance:5,opacity:.85,forceHelperSize:true,update:function(e,t){sortable_post_table.sortable("disable").addClass("spo-updating");t.item.addClass("spo-updating-row");var n=t.item[0].id.substr(5);var r=false;var i=t.item.prev();if(i.length>0){r=i.attr("id").substr(5)}var s=false;var o=t.item.next();if(o.length>0){s=o.attr("id").substr(5)}jQuery.post(ajaxurl,{action:"simple_page_ordering",id:n,previd:r,nextid:s},update_simple_ordering_callback);var u=document.querySelectorAll("tr.iedit"),a=u.length;while(a--){if(a%2==0){jQuery(u[a]).addClass("alternate")}else{jQuery(u[a]).removeClass("alternate")}}}})
     1function update_simple_ordering_callback(e){if("children"===e){window.location.reload();return}var t=jQuery.parseJSON(e);var n=t.new_pos;for(var r in n){if("next"===r)continue;var i=document.getElementById("inline_"+r);if(null!==i&&n.hasOwnProperty(r)){var s=i.querySelector(".menu_order");if(undefined!==n[r]["menu_order"]){if(null!==s)s.innerHTML=n[r]["menu_order"];var o=i.querySelector(".post_parent");if(null!==o)o.innerHTML=n[r]["post_parent"];var u=null;var a=i.querySelector(".post_title");if(null!==a)u=a.innerHTML;var f=0;while(f<n[r]["depth"]){u="&mdash; "+u;f++}var l=i.parentNode.querySelector(".row-title");if(null!==l&&null!==u)l.innerHTML=u}else if(null!==s){s.innerHTML=n[r]}}}if(t.next){jQuery.post(ajaxurl,{action:"simple_page_ordering",id:t.next["id"],previd:t.next["previd"],nextid:t.next["nextid"],start:t.next["start"],excluded:t.next["excluded"]},update_simple_ordering_callback)}else{jQuery(document.querySelector(".spo-updating-row")).removeClass("spo-updating-row");sortable_post_table.removeClass("spo-updating").sortable("enable")}}var sortable_post_table=jQuery(document.querySelector(".wp-list-table tbody"));sortable_post_table.sortable({items:"> tr",cursor:"move",axis:"y",containment:"table.widefat",cancel:".inline-edit-row",distance:2,opacity:.8,tolerance:"pointer",start:function(e,t){if(typeof inlineEditPost!=="undefined"){inlineEditPost.revert()}t.placeholder.height(t.item.height())},update:function(e,t){sortable_post_table.sortable("disable").addClass("spo-updating");t.item.addClass("spo-updating-row");var n=t.item[0].id.substr(5);var r=false;var i=t.item.prev();if(i.length>0){r=i.attr("id").substr(5)}var s=false;var o=t.item.next();if(o.length>0){s=o.attr("id").substr(5)}jQuery.post(ajaxurl,{action:"simple_page_ordering",id:n,previd:r,nextid:s},update_simple_ordering_callback);var u=document.querySelectorAll("tr.iedit"),a=u.length;while(a--){if(a%2==0){jQuery(u[a]).addClass("alternate")}else{jQuery(u[a]).removeClass("alternate")}}}})
  • simple-page-ordering/trunk/simple-page-ordering.php

    r720603 r888474  
    44Plugin URI: http://10up.com/plugins/simple-page-ordering-wordpress/
    55Description: Order your pages and hierarchical post types using drag and drop on the built in page list. For further instructions, open the "Help" tab on the Pages screen.
    6 Version: 2.1.2
     6Version: 2.2
    77Author: Jake Goldman, 10up
    88Author URI: http://10up.com
     
    1010 */
    1111
     12if ( ! class_exists( 'Simple_Page_Ordering' ) ) :
     13
    1214class Simple_Page_Ordering {
    1315
    14     public function __construct() {
    15         add_action( 'load-edit.php', array( $this, 'load_edit_screen' ) );
    16         add_action( 'wp_ajax_simple_page_ordering', array( $this, 'ajax_simple_page_ordering' ) );
    17     }
    18 
    19     public function load_edit_screen() {
     16    /**
     17     * Handles initializing this class and returning the singleton instance after it's been cached.
     18     *
     19     * @return null|Simple_page_Ordering
     20     */
     21    public static function get_instance() {
     22        // Store the instance locally to avoid private static replication
     23        static $instance = null;
     24
     25        if ( null === $instance ) {
     26            $instance = new self();
     27            self::_add_actions();
     28        }
     29
     30        return $instance;
     31    }
     32
     33    /**
     34     * An empty constructor
     35     */
     36    public function __construct() { /* Purposely do nothing here */ }
     37
     38    /**
     39     * Handles registering hooks that initialize this plugin.
     40     */
     41    public static function _add_actions() {
     42        add_action( 'load-edit.php', array( __CLASS__, 'load_edit_screen' ) );
     43        add_action( 'wp_ajax_simple_page_ordering', array( __CLASS__, 'ajax_simple_page_ordering' ) );
     44    }
     45
     46    /**
     47     * Load up page ordering scripts for the edit screen
     48     */
     49    public static function load_edit_screen() {
    2050        $screen = get_current_screen();
    2151        $post_type = $screen->post_type;
     
    2353        // is post type sortable?
    2454        $sortable = ( post_type_supports( $post_type, 'page-attributes' ) || is_post_type_hierarchical( $post_type ) );     // check permission
    25         if ( ! $sortable = apply_filters( 'simple_page_ordering_is_sortable', $sortable, $post_type ) )
     55        if ( ! $sortable = apply_filters( 'simple_page_ordering_is_sortable', $sortable, $post_type ) ) {
    2656            return;
     57        }
    2758
    2859        // does user have the right to manage these post objects?
    29         if ( ! $this->check_edit_others_caps( $post_type ) )
     60        if ( ! self::check_edit_others_caps( $post_type ) ) {
    3061            return;
    31 
    32         add_filter( 'views_' . $screen->id, array( $this, 'sort_by_order_link' )  );        // add view by menu order to views
    33         add_action( 'wp', array( $this, 'wp' ) );
    34         add_action( 'admin_head', array( $this, 'admin_head' ) );
    35     }
    36 
    37     public function wp() {
    38         if ( 0 === strpos( get_query_var('orderby'), 'menu_order' ) ) { // we can only sort if we're organized by menu order
     62        }
     63
     64        add_filter( 'views_' . $screen->id, array( __CLASS__, 'sort_by_order_link' )  );        // add view by menu order to views
     65        add_action( 'wp', array( __CLASS__, 'wp' ) );
     66        add_action( 'admin_head', array( __CLASS__, 'admin_head' ) );
     67    }
     68
     69    /**
     70     * when we load up our posts query, if we're actually sorting by menu order, initialize sorting scripts
     71     */
     72    public static function wp() {
     73        if ( 0 === strpos( get_query_var('orderby'), 'menu_order' ) ) {
    3974            $script_name = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'simple-page-ordering.dev.js' : 'simple-page-ordering.js';
    4075            wp_enqueue_script( 'simple-page-ordering', plugins_url( $script_name, __FILE__ ), array('jquery-ui-sortable'), '2.1', true );
     
    4378    }
    4479
    45     public function admin_head() {
     80    /**
     81     * Add page ordering help to the help tab
     82     */
     83    public static function admin_head() {
    4684        $screen = get_current_screen();
    4785        $screen->add_help_tab(array(
     
    5290    }
    5391
    54     public function ajax_simple_page_ordering() {
     92    public static function ajax_simple_page_ordering() {
    5593        // check and make sure we have what we need
    56         if ( empty( $_POST['id'] ) || ( !isset( $_POST['previd'] ) && !isset( $_POST['nextid'] ) ) )
     94        if ( empty( $_POST['id'] ) || ( !isset( $_POST['previd'] ) && !isset( $_POST['nextid'] ) ) ) {
    5795            die(-1);
     96        }
    5897
    5998        // real post?
    60         if ( ! $post = get_post( $_POST['id'] ) )
     99        if ( ! $post = get_post( $_POST['id'] ) ) {
    61100            die(-1);
     101        }
    62102
    63103        // does user have the right to manage these post objects?
    64         if ( ! $this->check_edit_others_caps( $post->post_type ) )
     104        if ( ! self::check_edit_others_caps( $post->post_type ) ) {
    65105            die(-1);
     106        }
    66107
    67108        // badly written plug-in hooks for save post can break things
    68         if ( !defined( 'WP_DEBUG' ) || !WP_DEBUG )
     109        if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
    69110            error_reporting( 0 );
     111        }
    70112
    71113        $previd = empty( $_POST['previd'] ) ? false : (int) $_POST['previd'];
     
    91133        }
    92134        // if the next post's parent isn't our parent, it might as well be false (irrelevant to our query)
    93         if ( $next_post_parent !== $parent_id )
     135        if ( $next_post_parent !== $parent_id ) {
    94136            $nextid = false;
     137        }
    95138
    96139        $max_sortable_posts = (int) apply_filters( 'simple_page_ordering_limit', 50 );  // should reliably be able to do about 50 at a time
    97         if ( $max_sortable_posts < 5 )  // don't be ridiculous!
     140        if ( $max_sortable_posts < 5 ) {    // don't be ridiculous!
    98141            $max_sortable_posts = 50;
     142        }
    99143
    100144        // we need to handle all post stati, except trash (in case of custom stati)
     
    124168
    125169            // don't handle the actual post
    126             if ( $sibling->ID === $post->ID )
     170            if ( $sibling->ID === $post->ID ) {
    127171                continue;
     172            }
    128173
    129174            // if this is the post that comes after our repositioned post, set our repositioned post position and increment menu order
     
    211256    }
    212257
    213     public function sort_by_order_link( $views ) {
     258    /**
     259     * Append a sort by order link to the post actions
     260     *
     261     * @param string $views
     262     * @return string
     263     */
     264    public static function sort_by_order_link( $views ) {
    214265        $class = ( get_query_var('orderby') == 'menu_order title' ) ? 'current' : '';
    215266        $query_string = remove_query_arg(array( 'orderby', 'order' ));
     
    222273     * Checks to see if the current user has the capability to "edit others" for a post type
    223274     *
    224      * @param (string) $post_type Post type name
    225      * @return (bool) True or false
    226      */
    227     public function check_edit_others_caps( $post_type ) {
     275     * @param string $post_type Post type name
     276     * @return bool True or false
     277     */
     278    private static function check_edit_others_caps( $post_type ) {
    228279        $post_type_object = get_post_type_object( $post_type );
    229280        $edit_others_cap = empty( $post_type_object ) ? 'edit_others_' . $post_type . 's' : $post_type_object->cap->edit_others_posts;
     
    232283}
    233284
    234 $simple_page_ordering = new Simple_Page_Ordering;
     285Simple_Page_Ordering::get_instance();
     286
     287endif;
Note: See TracChangeset for help on using the changeset viewer.