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-terms-list-table.php

    r21323 r21914  
    1212    var $callback_args;
    1313
    14     function __construct() {
    15         global $post_type, $taxonomy, $tax;
    16 
    17         wp_reset_vars( array( 'action', 'taxonomy', 'post_type' ) );
    18 
    19         if ( empty( $taxonomy ) )
    20             $taxonomy = 'post_tag';
    21 
    22         if ( !taxonomy_exists( $taxonomy ) )
    23             wp_die( __( 'Invalid taxonomy' ) );
    24 
    25         $tax = get_taxonomy( $taxonomy );
    26 
    27         if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) )
    28             $post_type = 'post';
     14    function __construct( $args = array() ) {
     15        global $post_type, $taxonomy, $action, $tax;
    2916
    3017        parent::__construct( array(
    3118            'plural' => 'tags',
    3219            'singular' => 'tag',
     20            'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
    3321        ) );
     22
     23        $action    = $this->screen->action;
     24        $post_type = $this->screen->post_type;
     25        $taxonomy  = $this->screen->taxonomy;
     26
     27        if ( empty( $taxonomy ) )
     28            $taxonomy = 'post_tag';
     29
     30        if ( ! taxonomy_exists( $taxonomy ) )
     31            wp_die( __( 'Invalid taxonomy' ) );
     32
     33        $tax = get_taxonomy( $taxonomy );
     34
     35        // @todo Still needed? Maybe just the show_ui part.
     36        if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) )
     37            $post_type = 'post';
     38
    3439    }
    3540
    3641    function ajax_user_can() {
    37         global $tax;
    38 
    39         return current_user_can( $tax->cap->manage_terms );
     42        return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms );
    4043    }
    4144
    4245    function prepare_items() {
    43         global $taxonomy;
    44 
    45         $tags_per_page = $this->get_items_per_page( 'edit_' . $taxonomy . '_per_page' );
    46 
    47         if ( 'post_tag' == $taxonomy ) {
     46        $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' );
     47
     48        if ( 'post_tag' == $this->screen->taxonomy ) {
    4849            $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
    4950            $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
    50         } elseif ( 'category' == $taxonomy ) {
     51        } elseif ( 'category' == $this->screen->taxonomy ) {
    5152            $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
    5253        }
     
    6970
    7071        $this->set_pagination_args( array(
    71             'total_items' => wp_count_terms( $taxonomy, compact( 'search' ) ),
     72            'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
    7273            'per_page' => $tags_per_page,
    7374        ) );
     
    9495
    9596    function get_columns() {
    96         global $taxonomy, $post_type;
    97 
    9897        $columns = array(
    9998            'cb'          => '<input type="checkbox" />',
     
    103102        );
    104103
    105         if ( 'link_category' == $taxonomy ) {
     104        if ( 'link_category' == $this->screen->taxonomy ) {
    106105            $columns['links'] = __( 'Links' );
    107106        } else {
    108             $post_type_object = get_post_type_object( $post_type );
     107            $post_type_object = get_post_type_object( $this->screen->post_type );
    109108            $columns['posts'] = $post_type_object ? $post_type_object->labels->name : __( 'Posts' );
    110109        }
     
    124123
    125124    function display_rows_or_placeholder() {
    126         global $taxonomy;
     125        $taxonomy = $this->screen->taxonomy;
    127126
    128127        $args = wp_parse_args( $this->callback_args, array(
     
    232231
    233232    function column_cb( $tag ) {
    234         global $taxonomy, $tax;
    235 
    236         $default_term = get_option( 'default_' . $taxonomy );
    237 
    238         if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
     233        $default_term = get_option( 'default_' . $this->screen->taxonomy );
     234
     235        if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) && $tag->term_id != $default_term )
    239236            return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s' ), $tag->name ) . '</label>'
    240237                . '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />';
     
    244241
    245242    function column_name( $tag ) {
    246         global $taxonomy, $tax, $post_type;
     243        $taxonomy = $this->screen->taxonomy;
     244        $tax = get_taxonomy( $taxonomy );
    247245
    248246        $default_term = get_option( 'default_' . $taxonomy );
     
    251249        $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag );
    252250        $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' );
    253         $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $post_type ) );
     251        $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) );
    254252
    255253        $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
     
    285283
    286284    function column_posts( $tag ) {
    287         global $taxonomy, $post_type;
    288 
    289285        $count = number_format_i18n( $tag->count );
    290286
    291         $tax = get_taxonomy( $taxonomy );
    292 
    293         $ptype_object = get_post_type_object( $post_type );
     287        $tax = get_taxonomy( $this->screen->taxonomy );
     288
     289        $ptype_object = get_post_type_object( $this->screen->post_type );
    294290        if ( ! $ptype_object->show_ui )
    295291            return $count;
     
    301297        }
    302298
    303         if ( 'post' != $post_type )
    304             $args['post_type'] = $post_type;
     299        if ( 'post' != $this->screen->post_type )
     300            $args['post_type'] = $this->screen->post_type;
    305301
    306302        return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
     
    315311
    316312    function column_default( $tag, $column_name ) {
    317         $screen = get_current_screen();
    318 
    319         return apply_filters( "manage_{$screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
     313        return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
    320314    }
    321315
     
    326320     */
    327321    function inline_edit() {
    328         global $post_type, $tax;
     322        $tax = get_taxonomy( $this->screen->taxonomy );
    329323
    330324        if ( ! current_user_can( $tax->cap->edit_terms ) )
     
    359353                continue;
    360354
    361             do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $tax->name );
     355            do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy );
    362356        }
    363357
     
    371365            <span class="error" style="display:none;"></span>
    372366            <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
    373             <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" />
    374             <input type="hidden" name="post_type" value="<?php echo esc_attr( $post_type ); ?>" />
     367            <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" />
     368            <input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" />
    375369            <br class="clear" />
    376370        </p>
Note: See TracChangeset for help on using the changeset viewer.