Make WordPress Core


Ignore:
Timestamp:
05/19/2014 01:16:16 AM (11 years ago)
Author:
wonderboymusic
Message:

Add access modifiers to methods and members of list table classes:

  • WP_List_Table is the base class that implements __get() and __call() for BC
  • Adds unit tests to confirm that subclasses properly inherit magic methods
  • Add modifiers to subclasses: WP_Links_List_Table, WP_Media_List_Table, WP_MS_Sites_List_Table, WP_MS_Themes_List_Table, WP_MS_Users_List_Table, WP_Plugin_Install_List_Table, WP_Plugins_List_Table, WP_Posts_List_Table, WP_Terms_List_Table, WP_Theme_Install_List_Table, WP_Themes_List_Table

See #27881, #22234.

File:
1 edited

Legend:

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

    r28389 r28493  
    1717     * @access protected
    1818     */
    19     var $items;
     19    protected $items;
    2020
    2121    /**
     
    2626     * @access private
    2727     */
    28     var $_args;
     28    private $_args;
    2929
    3030    /**
     
    3535     * @access private
    3636     */
    37     var $_pagination_args = array();
     37    private $_pagination_args = array();
    3838
    3939    /**
     
    4444     * @access protected
    4545     */
    46     var $screen;
     46    protected $screen;
    4747
    4848    /**
     
    5353     * @access private
    5454     */
    55     var $_actions;
     55    private $_actions;
    5656
    5757    /**
     
    6262     * @access private
    6363     */
    64     var $_pagination;
     64    private $_pagination;
    6565
    6666    /**
     
    7070     * @access protected
    7171     */
    72     function __construct( $args = array() ) {
     72    public function __construct( $args = array() ) {
    7373        $args = wp_parse_args( $args, array(
    7474            'plural' => '',
     
    9797
    9898    /**
     99     * Make private properties readable for backwards compatibility
     100     *
     101     * @since 4.0.0
     102     * @param string $name
     103     * @return mixed
     104     */
     105    public function __get( $name ) {
     106        return $this->$name;
     107    }
     108
     109    /**
     110     * Make private/protected methods readable for backwards compatibility
     111     *
     112     * @since 4.0.0
     113     * @param string $name
     114     * @param array $arguments
     115     * @return mixed
     116     */
     117    public function __call( $name, $arguments ) {
     118        return call_user_func_array( array( $this, $name ), $arguments );
     119    }
     120
     121    /**
    99122     * Checks the current user's permissions
    100123     * @uses wp_die()
     
    104127     * @abstract
    105128     */
    106     function ajax_user_can() {
     129    public function ajax_user_can() {
    107130        die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
    108131    }
     
    116139     * @abstract
    117140     */
    118     function prepare_items() {
     141    public function prepare_items() {
    119142        die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
    120143    }
     
    126149     * @access protected
    127150     */
    128     function set_pagination_args( $args ) {
     151    protected function set_pagination_args( $args ) {
    129152        $args = wp_parse_args( $args, array(
    130153            'total_items' => 0,
     
    154177     * @return array
    155178     */
    156     function get_pagination_arg( $key ) {
     179    public function get_pagination_arg( $key ) {
    157180        if ( 'page' == $key )
    158181            return $this->get_pagenum();
     
    170193     * @return bool
    171194     */
    172     function has_items() {
     195    public function has_items() {
    173196        return !empty( $this->items );
    174197    }
     
    180203     * @access public
    181204     */
    182     function no_items() {
     205    public function no_items() {
    183206        _e( 'No items found.' );
    184207    }
     
    193216     * @param string $input_id The search input id
    194217     */
    195     function search_box( $text, $input_id ) {
     218    public function search_box( $text, $input_id ) {
    196219        if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
    197220            return;
     
    225248     * @return array
    226249     */
    227     function get_views() {
     250    protected function get_views() {
    228251        return array();
    229252    }
     
    235258     * @access public
    236259     */
    237     function views() {
     260    public function views() {
    238261        $views = $this->get_views();
    239262        /**
     
    269292     * @return array
    270293     */
    271     function get_bulk_actions() {
     294    protected function get_bulk_actions() {
    272295        return array();
    273296    }
     
    279302     * @access public
    280303     */
    281     function bulk_actions() {
     304    public function bulk_actions() {
    282305        if ( is_null( $this->_actions ) ) {
    283306            $no_new_actions = $this->_actions = $this->get_bulk_actions();
     
    327350     * @return string|bool The action name or False if no action was selected
    328351     */
    329     function current_action() {
     352    public function current_action() {
    330353        if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
    331354            return $_REQUEST['action'];
     
    347370     * @return string
    348371     */
    349     function row_actions( $actions, $always_visible = false ) {
     372    protected function row_actions( $actions, $always_visible = false ) {
    350373        $action_count = count( $actions );
    351374        $i = 0;
     
    371394     * @access protected
    372395     */
    373     function months_dropdown( $post_type ) {
     396    protected function months_dropdown( $post_type ) {
    374397        global $wpdb, $wp_locale;
    375398
     
    426449     * @access protected
    427450     */
    428     function view_switcher( $current_mode ) {
     451    protected function view_switcher( $current_mode ) {
    429452        $modes = array(
    430453            'list'    => __( 'List View' ),
     
    454477     * @param int $pending_comments
    455478     */
    456     function comments_bubble( $post_id, $pending_comments ) {
     479    protected function comments_bubble( $post_id, $pending_comments ) {
    457480        $pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) );
    458481
     
    474497     * @return int
    475498     */
    476     function get_pagenum() {
     499    protected function get_pagenum() {
    477500        $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
    478501
     
    491514     * @return int
    492515     */
    493     function get_items_per_page( $option, $default = 20 ) {
     516    protected function get_items_per_page( $option, $default = 20 ) {
    494517        $per_page = (int) get_user_option( $option );
    495518        if ( empty( $per_page ) || $per_page < 1 )
     
    517540     * @access protected
    518541     */
    519     function pagination( $which ) {
     542    protected function pagination( $which ) {
    520543        if ( empty( $this->_pagination_args ) ) {
    521544            return;
     
    612635     * @return array
    613636     */
    614     function get_columns() {
     637    protected function get_columns() {
    615638        die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
    616639    }
     
    629652     * @return array
    630653     */
    631     function get_sortable_columns() {
     654    protected function get_sortable_columns() {
    632655        return array();
    633656    }
     
    641664     * @return array
    642665     */
    643     function get_column_info() {
     666    protected function get_column_info() {
    644667        if ( isset( $this->_column_headers ) )
    645668            return $this->_column_headers;
     
    686709     * @return int
    687710     */
    688     function get_column_count() {
     711    public function get_column_count() {
    689712        list ( $columns, $hidden ) = $this->get_column_info();
    690713        $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
     
    700723     * @param bool $with_id Whether to set the id attribute or not
    701724     */
    702     function print_column_headers( $with_id = true ) {
     725    protected function print_column_headers( $with_id = true ) {
    703726        list( $columns, $hidden, $sortable ) = $this->get_column_info();
    704727
     
    768791     * @access public
    769792     */
    770     function display() {
     793    public function display() {
    771794        $singular = $this->_args['singular'];
    772795
     
    806829     * @return array
    807830     */
    808     function get_table_classes() {
     831    protected function get_table_classes() {
    809832        return array( 'widefat', 'fixed', $this->_args['plural'] );
    810833    }
     
    816839     * @access protected
    817840     */
    818     function display_tablenav( $which ) {
     841    protected function display_tablenav( $which ) {
    819842        if ( 'top' == $which )
    820843            wp_nonce_field( 'bulk-' . $this->_args['plural'] );
     
    841864     * @access protected
    842865     */
    843     function extra_tablenav( $which ) {}
     866    protected function extra_tablenav( $which ) {}
    844867
    845868    /**
     
    849872     * @access protected
    850873     */
    851     function display_rows_or_placeholder() {
     874    protected function display_rows_or_placeholder() {
    852875        if ( $this->has_items() ) {
    853876            $this->display_rows();
     
    865888     * @access protected
    866889     */
    867     function display_rows() {
     890    protected function display_rows() {
    868891        foreach ( $this->items as $item )
    869892            $this->single_row( $item );
     
    878901     * @param object $item The current item
    879902     */
    880     function single_row( $item ) {
     903    protected function single_row( $item ) {
    881904        static $row_class = '';
    882905        $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
     
    895918     * @param object $item The current item
    896919     */
    897     function single_row_columns( $item ) {
     920    protected function single_row_columns( $item ) {
    898921        list( $columns, $hidden ) = $this->get_column_info();
    899922
     
    931954     * @access public
    932955     */
    933     function ajax_response() {
     956    public function ajax_response() {
    934957        $this->prepare_items();
    935958
     
    964987     * @access private
    965988     */
    966     function _js_vars() {
     989    private function _js_vars() {
    967990        $args = array(
    968991            'class'  => get_class( $this ),
Note: See TracChangeset for help on using the changeset viewer.