WordPress.org

Make WordPress Core

Ticket #16166: garyc40.16166.2.diff

File garyc40.16166.2.diff, 6.3 KB (added by garyc40, 8 years ago)

tidy things up a bit

  • wp-admin/edit-comments.php

    diff --git wp-admin/edit-comments.php wp-admin/edit-comments.php
    index 29e5f03..98f0373 100644
    if ( !current_user_can('edit_posts') ) 
    1212        wp_die(__('Cheatin’ uh?'));
    1313
    1414$wp_list_table = get_list_table('WP_Comments_List_Table');
    15 $pagenum = $wp_list_table->get_pagenum();
    16 
    1715$doaction = $wp_list_table->current_action();
    1816
    1917if ( $doaction ) {
    if ( $doaction ) { 
    3735        $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
    3836
    3937        $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
    40         $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
     38        $redirect_to = $wp_list_table->add_query_args( $redirect_to );
    4139
    4240        foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
    4341                if ( !current_user_can( 'edit_comment', $comment_id ) )
    if ( $doaction ) { 
    102100$wp_list_table->prepare_items();
    103101
    104102$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
    105 if ( $pagenum > $total_pages && $total_pages > 0 ) {
     103if ( $wp_list_table->get_pagenum() > $total_pages && $total_pages > 0 ) {
    106104        wp_redirect( add_query_arg( 'paged', $total_pages ) );
    107105        exit;
    108106}
  • wp-admin/edit-tags.php

    diff --git wp-admin/edit-tags.php wp-admin/edit-tags.php
    index cfaba6c..cf9af28 100644
    case 'delete': 
    7878
    7979        wp_delete_term( $tag_ID, $taxonomy );
    8080
     81        $location = $wp_list_table->add_query_args( $location );
    8182        $location = add_query_arg( 'message', 2, $location );
    8283        wp_redirect( $location );
    8384        exit;
    case 'bulk-delete': 
    102103                if ( false !== strpos( $referer, 'edit-tags.php' ) )
    103104                        $location = $referer;
    104105        }
    105 
     106       
    106107        $location = add_query_arg( 'message', 6, $location );
     108        $location = $wp_list_table->add_query_args( $location );
     109
    107110        wp_redirect( $location );
    108111        exit;
    109112
  • wp-admin/edit.php

    diff --git wp-admin/edit.php wp-admin/edit.php
    index 5e0154f..da8d828 100644
    if ( !current_user_can($post_type_object->cap->edit_posts) ) 
    2424        wp_die(__('Cheatin’ uh?'));
    2525
    2626$wp_list_table = get_list_table('WP_Posts_List_Table');
    27 $pagenum = $wp_list_table->get_pagenum();
    2827
    2928// Back-compat for viewing comments of an entry
    3029foreach ( array( 'p', 'attachment_id', 'page_id' ) as $_redirect ) {
    if ( $doaction ) { 
    4140        check_admin_referer('bulk-posts');
    4241
    4342        $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
    44         $sendback = add_query_arg( 'paged', $pagenum, $sendback );
     43        $sendback = $wp_list_table->add_query_args( $sendback );
    4544        if ( strpos($sendback, 'post.php') !== false )
    4645                $sendback = admin_url($post_new_file);
    4746
    if ( 'post' != $post_type ) { 
    143142$wp_list_table->prepare_items();
    144143
    145144$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
    146 if ( $pagenum > $total_pages && $total_pages > 0 ) {
     145if ( $wp_list_table->get_pagenum() > $total_pages && $total_pages > 0 ) {
    147146        wp_redirect( add_query_arg( 'paged', $total_pages ) );
    148147        exit;
    149148}
  • wp-admin/includes/class-wp-list-table.php

    diff --git wp-admin/includes/class-wp-list-table.php wp-admin/includes/class-wp-list-table.php
    index fa2001d..084cd3f 100644
    class WP_List_Table { 
    611611                $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
    612612                return count( $columns ) - count( $hidden );
    613613        }
     614       
     615        function get_order_info() {
     616                if ( isset( $_GET['orderby'] ) )
     617                        $current_orderby = $_GET['orderby'];
     618                else
     619                        $current_orderby = '';
     620
     621                if ( ! $current_orderby )
     622                        $current_order = '';
     623                elseif ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
     624                        $current_order = 'desc';
     625                else
     626                        $current_order = 'asc';
     627                       
     628                return array($current_orderby, $current_order);
     629        }
     630       
     631        function add_query_args( $location ) {
     632                $pagenum = $this->get_pagenum();
     633                list( $current_orderby, $current_order ) = $this->get_order_info();
     634                $location = add_query_arg( 'paged', $pagenum, $location );
     635                if ( $current_orderby )
     636                        $location = add_query_arg( array( 'orderby' => $current_orderby, 'order' => $current_order ), $location );
     637               
     638                return $location;
     639        }
    614640
    615641        /**
    616642         * Print column headers, accounting for hidden and sortable columns.
    class WP_List_Table { 
    627653
    628654                $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    629655
    630                 if ( isset( $_GET['orderby'] ) )
    631                         $current_orderby = $_GET['orderby'];
    632                 else
    633                         $current_orderby = '';
    634 
    635                 if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
    636                         $current_order = 'desc';
    637                 else
    638                         $current_order = 'asc';
     656                list( $current_orderby, $current_order ) = $this->get_order_info();
    639657
    640658                foreach ( $columns as $column_key => $column_display_name ) {
    641659                        $class = array( 'manage-column', "column-$column_key" );
    class WP_List_Table { 
    728746         * @access protected
    729747         */
    730748        function display_tablenav( $which ) {
    731                 if ( 'top' == $which )
     749                if ( 'top' == $which ) {
    732750                        wp_nonce_field( 'bulk-' . $this->_args['plural'] );
     751                        list( $current_orderby, $current_order ) = $this->get_order_info();
     752                        echo '<input type="hidden" name="orderby" value="' . $current_orderby . '" /><input type="hidden" name="order" value="' . $current_order . '" />';
     753                }
    733754?>
    734755        <div class="tablenav <?php echo esc_attr( $which ); ?>">
    735756
  • wp-admin/js/list-table.dev.js

    diff --git wp-admin/js/list-table.dev.js wp-admin/js/list-table.dev.js
    index 51b52d1..2176da2 100644
    window.listTable = { 
    103103                if ( 'object' != typeof response ) {
    104104                        this.handle_error();
    105105                } else {
    106                         var tablenav = $('.tablenav-pages');
     106                        var tablenav = $('.tablenav-pages'),
     107                                order = $.query.GET('order'),
     108                                orderby = (order) ? $.query.GET('orderby') : '';
    107109
    108110                        this.stop_loading();
    109111
    window.listTable = { 
    124126                        // Disable buttons that should noop.
    125127                        tablenav.find('.first-page, .prev-page').toggleClass('disabled', 1 == $.query.GET('paged'));
    126128                        tablenav.find('.next-page, .last-page').toggleClass('disabled', response.total_pages == $.query.GET('paged'));
    127 
     129                       
     130                        $('input[name=order]').val(order);
     131                        $('input[name=orderby]').val(orderby);
     132                       
    128133                        $('th.column-cb :input').attr('checked', false);
    129134
    130135                        if ( history.replaceState ) {