WordPress.org

Make WordPress Core

Ticket #16356: garyc40.16356.2.diff

File garyc40.16356.2.diff, 9.0 KB (added by garyc40, 5 years ago)

centralize redirection in set_pagination_args()

  • wp-admin/edit-comments.php

    diff --git wp-admin/edit-comments.php wp-admin/edit-comments.php
    index 40ef4a4..d84e2f9 100644
    if ( $doaction ) { 
    101101 
    102102$wp_list_table->prepare_items(); 
    103103 
    104 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); 
    105 if ( $pagenum > $total_pages && $total_pages > 0 ) { 
    106         wp_redirect( add_query_arg( 'paged', $total_pages ) ); 
    107         exit; 
    108 } 
    109  
    110104wp_enqueue_script('admin-comments'); 
    111105enqueue_comment_hotkeys_js(); 
    112106 
  • wp-admin/edit-tags.php

    diff --git wp-admin/edit-tags.php wp-admin/edit-tags.php
    index 13534de..d576b63 100644
    case 'editedtag': 
    148148break; 
    149149 
    150150default: 
    151  
    152151if ( ! empty($_REQUEST['_wp_http_referer']) ) { 
    153          wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); 
    154          exit; 
     152        $location = remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ); 
     153 
     154        if ( ! empty( $_REQUEST['paged'] ) ) 
     155                $location = add_query_arg( 'paged', $_REQUEST['paged'] ); 
     156         
     157        wp_redirect( $location ); 
     158        exit; 
    155159} 
    156160 
    157161$wp_list_table->prepare_items(); 
  • wp-admin/edit.php

    diff --git wp-admin/edit.php wp-admin/edit.php
    index 5c7b194..f55cb6e 100644
    if ( 'post' != $post_type ) { 
    142142 
    143143$wp_list_table->prepare_items(); 
    144144 
    145 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); 
    146 if ( $pagenum > $total_pages && $total_pages > 0 ) { 
    147         wp_redirect( add_query_arg( 'paged', $total_pages ) ); 
    148         exit; 
    149 } 
    150  
    151145wp_enqueue_script('inline-edit-post'); 
    152146 
    153147$title = $post_type_object->labels->name; 
  • 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 e7ce9e5..c3b20c4 100644
    class WP_List_Table { 
    138138 
    139139                if ( !$args['total_pages'] && $args['per_page'] > 0 ) 
    140140                        $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] ); 
    141  
     141                 
     142                if( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) { 
     143                        wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) ); 
     144                        exit; 
     145                } 
     146                 
    142147                $this->_pagination_args = $args; 
    143148        } 
    144149 
    class WP_List_Table { 
    443448        function get_pagenum() { 
    444449                $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0; 
    445450 
    446                 if( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) 
    447                         $pagenum = $this->_pagination_args['total_pages']; 
    448  
    449451                return max( 1, $pagenum ); 
    450452        } 
    451453 
  • wp-admin/network/edit.php

    diff --git wp-admin/network/edit.php wp-admin/network/edit.php
    index 1e06e49..9d680b4 100644
    switch ( $_GET['action'] ) { 
    427427 
    428428                        wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) ); 
    429429                } else { 
    430                         wp_redirect( network_admin_url( 'users.php' ) ); 
     430                        $location = network_admin_url( 'users.php' ); 
     431 
     432                        if ( ! empty( $_REQUEST['paged'] ) ) 
     433                                $location = add_query_arg( 'paged', $_REQUEST['paged'], $location ); 
     434                        wp_redirect( $location ); 
    431435                } 
    432436                exit(); 
    433437        break; 
  • wp-admin/network/sites.php

    diff --git wp-admin/network/sites.php wp-admin/network/sites.php
    index 8a77d63..45dd338 100644
    if ( ! current_user_can( 'manage_sites' ) ) 
    1717        wp_die( __( 'You do not have permission to access this page.' ) ); 
    1818 
    1919$wp_list_table = _get_list_table('WP_MS_Sites_List_Table'); 
    20 $pagenum = $wp_list_table->get_pagenum(); 
    2120 
    2221$title = __( 'Sites' ); 
    2322$parent_file = 'sites.php'; 
    if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( 
    8887 
    8988$wp_list_table->prepare_items(); 
    9089 
    91 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); 
    92 if ( $pagenum > $total_pages && $total_pages > 0 ) { 
    93         wp_redirect( add_query_arg( 'paged', $total_pages ) ); 
    94         exit; 
    95 } 
    96  
    9790require_once( '../admin-header.php' ); 
    9891?> 
    9992 
  • wp-admin/network/themes.php

    diff --git wp-admin/network/themes.php wp-admin/network/themes.php
    index b802f74..f8545d3 100644
    if ( !current_user_can('manage_network_themes') ) 
    2222        wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) ); 
    2323 
    2424$wp_list_table = _get_list_table('WP_MS_Themes_List_Table'); 
    25 $pagenum = $wp_list_table->get_pagenum(); 
    2625 
    2726$action = $wp_list_table->current_action(); 
    2827 
    if ( $action ) { 
    171170 
    172171$wp_list_table->prepare_items(); 
    173172 
    174 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); 
    175 if ( $pagenum > $total_pages && $total_pages > 0 ) { 
    176         wp_redirect( add_query_arg( 'paged', $total_pages ) ); 
    177         exit; 
    178 } 
    179  
    180173add_thickbox(); 
    181174 
    182175add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' )) ); 
  • wp-admin/network/users.php

    diff --git wp-admin/network/users.php wp-admin/network/users.php
    index eb59670..7e1f63c 100644
    if ( ! current_user_can( 'manage_network_users' ) ) 
    1717        wp_die( __( 'You do not have permission to access this page.' ) ); 
    1818 
    1919$wp_list_table = _get_list_table('WP_MS_Users_List_Table'); 
     20 
    2021$wp_list_table->prepare_items(); 
    2122 
    2223$title = __( 'Users' ); 
  • wp-admin/plugin-install.php

    diff --git wp-admin/plugin-install.php wp-admin/plugin-install.php
    index 971ab68..0812750 100644
    if ( is_multisite() && ! is_network_admin() ) { 
    2121} 
    2222 
    2323$wp_list_table = _get_list_table('WP_Plugin_Install_List_Table'); 
    24 $pagenum = $wp_list_table->get_pagenum(); 
     24 
    2525$wp_list_table->prepare_items(); 
    26 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); 
    27 if ( $pagenum > $total_pages && $total_pages > 0 ) { 
    28         wp_redirect( add_query_arg( 'paged', $total_pages ) ); 
    29         exit; 
    30 } 
    3126 
    3227$title = __('Install Plugins'); 
    3328$parent_file = 'plugins.php'; 
  • wp-admin/plugins.php

    diff --git wp-admin/plugins.php wp-admin/plugins.php
    index 0c36bbd..f423426 100644
    if ( !current_user_can('activate_plugins') ) 
    2020        wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) ); 
    2121 
    2222$wp_list_table = _get_list_table('WP_Plugins_List_Table'); 
    23 $pagenum = $wp_list_table->get_pagenum(); 
    2423 
    2524$action = $wp_list_table->current_action(); 
    2625 
    if ( $action ) { 
    316315 
    317316$wp_list_table->prepare_items(); 
    318317 
    319 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); 
    320 if ( $pagenum > $total_pages && $total_pages > 0 ) { 
    321         wp_redirect( add_query_arg( 'paged', $total_pages ) ); 
    322         exit; 
    323 } 
    324  
    325318wp_enqueue_script('plugin-install'); 
    326319add_thickbox(); 
    327320 
  • wp-admin/theme-install.php

    diff --git wp-admin/theme-install.php wp-admin/theme-install.php
    index 263d9a9..d92b6ae 100644
    if ( is_multisite() && ! is_network_admin() ) { 
    2121} 
    2222 
    2323$wp_list_table = _get_list_table('WP_Theme_Install_List_Table'); 
    24 $pagenum = $wp_list_table->get_pagenum(); 
     24 
    2525$wp_list_table->prepare_items(); 
    26 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); 
    27 if ( $pagenum > $total_pages && $total_pages > 0 ) { 
    28         wp_redirect( add_query_arg( 'paged', $total_pages ) ); 
    29         exit; 
    30 } 
    3126 
    3227$title = __('Install Themes'); 
    3328$parent_file = 'themes.php'; 
  • wp-admin/upload.php

    diff --git wp-admin/upload.php wp-admin/upload.php
    index 6a1d9b4..2ca11ba 100644
    if ( !current_user_can('upload_files') ) 
    1313        wp_die( __( 'You do not have permission to upload files.' ) ); 
    1414 
    1515$wp_list_table = _get_list_table('WP_Media_List_Table'); 
    16 $pagenum = $wp_list_table->get_pagenum(); 
    1716 
    1817// Handle bulk actions 
    1918$doaction = $wp_list_table->current_action(); 
    if ( $doaction ) { 
    130129 
    131130$wp_list_table->prepare_items(); 
    132131 
    133 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); 
    134 if ( $pagenum > $total_pages && $total_pages > 0 ) { 
    135         wp_redirect( add_query_arg( 'paged', $total_pages ) ); 
    136         exit; 
    137 } 
    138  
    139132$title = __('Media Library'); 
    140133$parent_file = 'upload.php'; 
    141134 
  • wp-includes/user.php

    diff --git wp-includes/user.php wp-includes/user.php
    index e39d19e..2a1a101 100644
    class WP_User_Query { 
    542542         */ 
    543543        function query() { 
    544544                global $wpdb; 
    545  
     545                 
    546546                if ( is_array( $this->query_vars['fields'] ) || 'all' == $this->query_vars['fields'] ) { 
    547547                        $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); 
    548548                } else { 
    549549                        $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); 
    550550                } 
     551                 
     552                if ( $this->query_vars['count_total'] ) 
     553                        $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where"); 
    551554 
    552555                if ( !$this->results ) 
    553556                        return; 
    554557 
    555                 if ( $this->query_vars['count_total'] ) 
    556                         $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where"); 
    557  
    558558                if ( 'all_with_meta' == $this->query_vars['fields'] ) { 
    559559                        cache_users( $this->results ); 
    560560