Make WordPress Core


Ignore:
Timestamp:
09/19/2012 12:43:31 PM (14 years ago)
Author:
ryan
Message:

Reduce reliance on global variables in the list tables. Allow passing a screen ID to the list tables so that ajax handlers can set the needed screen.

Props nacin
fixes #21871

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-posts-list-table.php

    r21806 r21914  
    4646    var $sticky_posts_count = 0;
    4747
    48     function __construct() {
     48    function __construct( $args = array() ) {
    4949        global $post_type_object, $wpdb;
    5050
    51         $post_type = get_current_screen()->post_type;
     51        parent::__construct( array(
     52            'plural' => 'posts',
     53            'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     54        ) );
     55
     56        $post_type = $this->screen->post_type;
    5257        $post_type_object = get_post_type_object( $post_type );
    5358
     
    6772            $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status != 'trash' AND ID IN ($sticky_posts)", $post_type ) );
    6873        }
    69 
    70         parent::__construct( array(
    71             'plural' => 'posts',
    72         ) );
    7374    }
    7475
    7576    function ajax_user_can() {
    76         global $post_type_object;
    77 
    78         return current_user_can( $post_type_object->cap->edit_posts );
     77        return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
    7978    }
    8079
    8180    function prepare_items() {
    82         global $post_type_object, $avail_post_stati, $wp_query, $per_page, $mode;
     81        global $avail_post_stati, $wp_query, $per_page, $mode;
    8382
    8483        $avail_post_stati = wp_edit_posts_query();
    8584
    86         $this->hierarchical_display = ( $post_type_object->hierarchical && 'menu_order title' == $wp_query->query['orderby'] );
     85        $this->hierarchical_display = ( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' == $wp_query->query['orderby'] );
    8786
    8887        $total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts;
    8988
    90         $post_type = $post_type_object->name;
     89        $post_type = $this->screen->post_type;
    9190        $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
    9291        $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
     
    113112
    114113    function no_items() {
    115         global $post_type_object;
    116 
    117114        if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] )
    118             echo $post_type_object->labels->not_found_in_trash;
     115            echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
    119116        else
    120             echo $post_type_object->labels->not_found;
     117            echo get_post_type_object( $this->screen->post_type )->labels->not_found;
    121118    }
    122119
    123120    function get_views() {
    124         global $post_type_object, $locked_post_status, $avail_post_stati;
    125 
    126         $post_type = $post_type_object->name;
     121        global $locked_post_status, $avail_post_stati;
     122
     123        $post_type = $this->screen->post_type;
    127124
    128125        if ( !empty($locked_post_status) )
     
    199196
    200197    function extra_tablenav( $which ) {
    201         global $post_type_object, $cat;
     198        global $cat;
    202199?>
    203200        <div class="alignleft actions">
     
    205202        if ( 'top' == $which && !is_singular() ) {
    206203
    207             $this->months_dropdown( $post_type_object->name );
    208 
    209             if ( is_object_in_taxonomy( $post_type_object->name, 'category' ) ) {
     204            $this->months_dropdown( $this->screen->post_type );
     205
     206            if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) {
    210207                $dropdown_options = array(
    211208                    'show_option_all' => __( 'View all categories' ),
     
    222219        }
    223220
    224         if ( $this->is_trash && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
     221        if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
    225222            submit_button( __( 'Empty Trash' ), 'small apply', 'delete_all', false );
    226223        }
     
    238235
    239236    function pagination( $which ) {
    240         global $post_type_object, $mode;
     237        global $mode;
    241238
    242239        parent::pagination( $which );
    243240
    244         if ( 'top' == $which && !$post_type_object->hierarchical )
     241        if ( 'top' == $which && ! is_post_type_hierarchical( $this->screen->post_type ) )
    245242            $this->view_switcher( $mode );
    246243    }
    247244
    248245    function get_table_classes() {
    249         global $post_type_object;
    250 
    251         return array( 'widefat', 'fixed', $post_type_object->hierarchical ? 'pages' : 'posts' );
     246        return array( 'widefat', 'fixed', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
    252247    }
    253248
    254249    function get_columns() {
    255         $screen = get_current_screen();
    256 
    257         if ( empty( $screen ) )
    258             $post_type = 'post';
    259         else
    260             $post_type = $screen->post_type;
     250        $post_type = $this->screen->post_type;
    261251
    262252        $posts_columns = array();
     
    314304
    315305    function display_rows( $posts = array(), $level = 0 ) {
    316         global $wp_query, $post_type_object, $per_page;
     306        global $wp_query, $per_page;
    317307
    318308        if ( empty( $posts ) )
     
    702692        global $mode;
    703693
    704         $screen = get_current_screen();
     694        $screen = $this->screen;
    705695
    706696        $post = get_default_post_to_edit( $screen->post_type );
     
    734724        while ( $bulk < 2 ) { ?>
    735725
    736         <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-$screen->post_type ";
    737             echo $bulk ? "bulk-edit-row bulk-edit-row-$hclass bulk-edit-$screen->post_type" : "quick-edit-row quick-edit-row-$hclass inline-edit-$screen->post_type";
     726        <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-" . $screen->post_type;
     727            echo $bulk ? "bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}" : "quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}";
    738728        ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
    739729
Note: See TracChangeset for help on using the changeset viewer.