From d6a3c2a0de5f8292eab5aac0fe00b52a35d249d0 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 19 May 2014 01:16:16 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@28493 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-links-list-table.php | 18 +-- src/wp-admin/includes/class-wp-list-table.php | 105 +++++++++++------- .../includes/class-wp-media-list-table.php | 26 ++--- .../includes/class-wp-ms-sites-list-table.php | 18 +-- .../class-wp-ms-themes-list-table.php | 30 ++--- .../includes/class-wp-ms-users-list-table.php | 18 +-- .../class-wp-plugin-install-list-table.php | 16 +-- .../includes/class-wp-plugins-list-table.php | 32 +++--- .../includes/class-wp-posts-list-table.php | 46 ++++---- .../includes/class-wp-terms-list-table.php | 40 +++---- .../class-wp-theme-install-list-table.php | 24 ++-- .../includes/class-wp-themes-list-table.php | 24 ++-- tests/phpunit/includes/functions.php | 12 +- tests/phpunit/tests/basic.php | 18 +++ 14 files changed, 239 insertions(+), 188 deletions(-) diff --git a/src/wp-admin/includes/class-wp-links-list-table.php b/src/wp-admin/includes/class-wp-links-list-table.php index 98281b0367..4d5885976a 100644 --- a/src/wp-admin/includes/class-wp-links-list-table.php +++ b/src/wp-admin/includes/class-wp-links-list-table.php @@ -9,18 +9,18 @@ */ class WP_Links_List_Table extends WP_List_Table { - function __construct( $args = array() ) { + public function __construct( $args = array() ) { parent::__construct( array( 'plural' => 'bookmarks', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } - function ajax_user_can() { + public function ajax_user_can() { return current_user_can( 'manage_links' ); } - function prepare_items() { + public function prepare_items() { global $cat_id, $s, $orderby, $order; wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) ); @@ -39,18 +39,18 @@ class WP_Links_List_Table extends WP_List_Table { $this->items = get_bookmarks( $args ); } - function no_items() { + public function no_items() { _e( 'No links found.' ); } - function get_bulk_actions() { + protected function get_bulk_actions() { $actions = array(); $actions['delete'] = __( 'Delete' ); return $actions; } - function extra_tablenav( $which ) { + protected function extra_tablenav( $which ) { global $cat_id; if ( 'top' != $which ) @@ -75,7 +75,7 @@ class WP_Links_List_Table extends WP_List_Table { '', 'name' => _x( 'Name', 'link name' ), @@ -87,7 +87,7 @@ class WP_Links_List_Table extends WP_List_Table { ); } - function get_sortable_columns() { + protected function get_sortable_columns() { return array( 'name' => 'name', 'url' => 'url', @@ -96,7 +96,7 @@ class WP_Links_List_Table extends WP_List_Table { ); } - function display_rows() { + protected function display_rows() { global $cat_id; $alt = 0; diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 1dd01663e6..0e2456380e 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -16,7 +16,7 @@ class WP_List_Table { * @var array * @access protected */ - var $items; + protected $items; /** * Various information about the current table @@ -25,7 +25,7 @@ class WP_List_Table { * @var array * @access private */ - var $_args; + private $_args; /** * Various information needed for displaying the pagination @@ -34,7 +34,7 @@ class WP_List_Table { * @var array * @access private */ - var $_pagination_args = array(); + private $_pagination_args = array(); /** * The current screen @@ -43,7 +43,7 @@ class WP_List_Table { * @var object * @access protected */ - var $screen; + protected $screen; /** * Cached bulk actions @@ -52,7 +52,7 @@ class WP_List_Table { * @var array * @access private */ - var $_actions; + private $_actions; /** * Cached pagination output @@ -61,7 +61,7 @@ class WP_List_Table { * @var string * @access private */ - var $_pagination; + private $_pagination; /** * Constructor. The child class should call this constructor from its own constructor @@ -69,7 +69,7 @@ class WP_List_Table { * @param array $args An associative array with information about the current table * @access protected */ - function __construct( $args = array() ) { + public function __construct( $args = array() ) { $args = wp_parse_args( $args, array( 'plural' => '', 'singular' => '', @@ -95,6 +95,29 @@ class WP_List_Table { } } + /** + * Make private properties readable for backwards compatibility + * + * @since 4.0.0 + * @param string $name + * @return mixed + */ + public function __get( $name ) { + return $this->$name; + } + + /** + * Make private/protected methods readable for backwards compatibility + * + * @since 4.0.0 + * @param string $name + * @param array $arguments + * @return mixed + */ + public function __call( $name, $arguments ) { + return call_user_func_array( array( $this, $name ), $arguments ); + } + /** * Checks the current user's permissions * @uses wp_die() @@ -103,7 +126,7 @@ class WP_List_Table { * @access public * @abstract */ - function ajax_user_can() { + public function ajax_user_can() { die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' ); } @@ -115,7 +138,7 @@ class WP_List_Table { * @access public * @abstract */ - function prepare_items() { + public function prepare_items() { die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' ); } @@ -125,7 +148,7 @@ class WP_List_Table { * @param array $args An associative array with information about the pagination * @access protected */ - function set_pagination_args( $args ) { + protected function set_pagination_args( $args ) { $args = wp_parse_args( $args, array( 'total_items' => 0, 'total_pages' => 0, @@ -153,7 +176,7 @@ class WP_List_Table { * @param string $key * @return array */ - function get_pagination_arg( $key ) { + public function get_pagination_arg( $key ) { if ( 'page' == $key ) return $this->get_pagenum(); @@ -169,7 +192,7 @@ class WP_List_Table { * * @return bool */ - function has_items() { + public function has_items() { return !empty( $this->items ); } @@ -179,7 +202,7 @@ class WP_List_Table { * @since 3.1.0 * @access public */ - function no_items() { + public function no_items() { _e( 'No items found.' ); } @@ -192,7 +215,7 @@ class WP_List_Table { * @param string $text The search button text * @param string $input_id The search input id */ - function search_box( $text, $input_id ) { + public function search_box( $text, $input_id ) { if ( empty( $_REQUEST['s'] ) && !$this->has_items() ) return; @@ -224,7 +247,7 @@ class WP_List_Table { * * @return array */ - function get_views() { + protected function get_views() { return array(); } @@ -234,7 +257,7 @@ class WP_List_Table { * @since 3.1.0 * @access public */ - function views() { + public function views() { $views = $this->get_views(); /** * Filter the list of available list table views. @@ -268,7 +291,7 @@ class WP_List_Table { * * @return array */ - function get_bulk_actions() { + protected function get_bulk_actions() { return array(); } @@ -278,7 +301,7 @@ class WP_List_Table { * @since 3.1.0 * @access public */ - function bulk_actions() { + public function bulk_actions() { if ( is_null( $this->_actions ) ) { $no_new_actions = $this->_actions = $this->get_bulk_actions(); /** @@ -326,7 +349,7 @@ class WP_List_Table { * * @return string|bool The action name or False if no action was selected */ - function current_action() { + public function current_action() { if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) return $_REQUEST['action']; @@ -346,7 +369,7 @@ class WP_List_Table { * @param bool $always_visible Whether the actions should be always visible * @return string */ - function row_actions( $actions, $always_visible = false ) { + protected function row_actions( $actions, $always_visible = false ) { $action_count = count( $actions ); $i = 0; @@ -370,7 +393,7 @@ class WP_List_Table { * @since 3.1.0 * @access protected */ - function months_dropdown( $post_type ) { + protected function months_dropdown( $post_type ) { global $wpdb, $wp_locale; $months = $wpdb->get_results( $wpdb->prepare( " @@ -425,7 +448,7 @@ class WP_List_Table { * @since 3.1.0 * @access protected */ - function view_switcher( $current_mode ) { + protected function view_switcher( $current_mode ) { $modes = array( 'list' => __( 'List View' ), 'excerpt' => __( 'Excerpt View' ) @@ -453,7 +476,7 @@ class WP_List_Table { * @param int $post_id * @param int $pending_comments */ - function comments_bubble( $post_id, $pending_comments ) { + protected function comments_bubble( $post_id, $pending_comments ) { $pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) ); if ( $pending_comments ) @@ -473,7 +496,7 @@ class WP_List_Table { * * @return int */ - function get_pagenum() { + protected function get_pagenum() { $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0; if( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) @@ -490,7 +513,7 @@ class WP_List_Table { * * @return int */ - function get_items_per_page( $option, $default = 20 ) { + protected function get_items_per_page( $option, $default = 20 ) { $per_page = (int) get_user_option( $option ); if ( empty( $per_page ) || $per_page < 1 ) $per_page = $default; @@ -516,7 +539,7 @@ class WP_List_Table { * @since 3.1.0 * @access protected */ - function pagination( $which ) { + protected function pagination( $which ) { if ( empty( $this->_pagination_args ) ) { return; } @@ -611,7 +634,7 @@ class WP_List_Table { * * @return array */ - function get_columns() { + protected function get_columns() { die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' ); } @@ -628,7 +651,7 @@ class WP_List_Table { * * @return array */ - function get_sortable_columns() { + protected function get_sortable_columns() { return array(); } @@ -640,7 +663,7 @@ class WP_List_Table { * * @return array */ - function get_column_info() { + protected function get_column_info() { if ( isset( $this->_column_headers ) ) return $this->_column_headers; @@ -685,7 +708,7 @@ class WP_List_Table { * * @return int */ - function get_column_count() { + public function get_column_count() { list ( $columns, $hidden ) = $this->get_column_info(); $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) ); return count( $columns ) - count( $hidden ); @@ -699,7 +722,7 @@ class WP_List_Table { * * @param bool $with_id Whether to set the id attribute or not */ - function print_column_headers( $with_id = true ) { + protected function print_column_headers( $with_id = true ) { list( $columns, $hidden, $sortable ) = $this->get_column_info(); $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); @@ -767,7 +790,7 @@ class WP_List_Table { * @since 3.1.0 * @access public */ - function display() { + public function display() { $singular = $this->_args['singular']; $this->display_tablenav( 'top' ); @@ -805,7 +828,7 @@ class WP_List_Table { * * @return array */ - function get_table_classes() { + protected function get_table_classes() { return array( 'widefat', 'fixed', $this->_args['plural'] ); } @@ -815,7 +838,7 @@ class WP_List_Table { * @since 3.1.0 * @access protected */ - function display_tablenav( $which ) { + protected function display_tablenav( $which ) { if ( 'top' == $which ) wp_nonce_field( 'bulk-' . $this->_args['plural'] ); ?> @@ -840,7 +863,7 @@ class WP_List_Table { * @since 3.1.0 * @access protected */ - function extra_tablenav( $which ) {} + protected function extra_tablenav( $which ) {} /** * Generate the part of the table @@ -848,7 +871,7 @@ class WP_List_Table { * @since 3.1.0 * @access protected */ - function display_rows_or_placeholder() { + protected function display_rows_or_placeholder() { if ( $this->has_items() ) { $this->display_rows(); } else { @@ -864,7 +887,7 @@ class WP_List_Table { * @since 3.1.0 * @access protected */ - function display_rows() { + protected function display_rows() { foreach ( $this->items as $item ) $this->single_row( $item ); } @@ -877,7 +900,7 @@ class WP_List_Table { * * @param object $item The current item */ - function single_row( $item ) { + protected function single_row( $item ) { static $row_class = ''; $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); @@ -894,7 +917,7 @@ class WP_List_Table { * * @param object $item The current item */ - function single_row_columns( $item ) { + protected function single_row_columns( $item ) { list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { @@ -930,7 +953,7 @@ class WP_List_Table { * @since 3.1.0 * @access public */ - function ajax_response() { + public function ajax_response() { $this->prepare_items(); ob_start(); @@ -963,7 +986,7 @@ class WP_List_Table { * * @access private */ - function _js_vars() { + private function _js_vars() { $args = array( 'class' => get_class( $this ), 'screen' => array( diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index 0a19848ce3..9be8f1bc96 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -9,7 +9,7 @@ */ class WP_Media_List_Table extends WP_List_Table { - function __construct( $args = array() ) { + public function __construct( $args = array() ) { $this->detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] ); parent::__construct( array( @@ -18,11 +18,11 @@ class WP_Media_List_Table extends WP_List_Table { ) ); } - function ajax_user_can() { + public function ajax_user_can() { return current_user_can('upload_files'); } - function prepare_items() { + public function prepare_items() { global $lost, $wp_query, $post_mime_types, $avail_post_mime_types; $q = $_REQUEST; @@ -41,7 +41,7 @@ class WP_Media_List_Table extends WP_List_Table { ) ); } - function get_views() { + protected function get_views() { global $wpdb, $post_mime_types, $avail_post_mime_types; $type_links = array(); @@ -74,7 +74,7 @@ class WP_Media_List_Table extends WP_List_Table { return $type_links; } - function get_bulk_actions() { + protected function get_bulk_actions() { $actions = array(); $actions['delete'] = __( 'Delete Permanently' ); if ( $this->detached ) @@ -83,7 +83,7 @@ class WP_Media_List_Table extends WP_List_Table { return $actions; } - function extra_tablenav( $which ) { + protected function extra_tablenav( $which ) { ?>
'; $posts_columns['icon'] = ''; @@ -180,7 +180,7 @@ class WP_Media_List_Table extends WP_List_Table { return $posts_columns; } - function get_sortable_columns() { + protected function get_sortable_columns() { return array( 'title' => 'title', 'author' => 'author', @@ -190,7 +190,7 @@ class WP_Media_List_Table extends WP_List_Table { ); } - function display_rows() { + protected function display_rows() { global $post; add_filter( 'the_title','esc_html' ); @@ -421,7 +421,7 @@ foreach ( $columns as $column_name => $column_display_name ) { detached ) { diff --git a/src/wp-admin/includes/class-wp-ms-sites-list-table.php b/src/wp-admin/includes/class-wp-ms-sites-list-table.php index fcabfd777c..74a961b8e6 100644 --- a/src/wp-admin/includes/class-wp-ms-sites-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-sites-list-table.php @@ -9,18 +9,18 @@ */ class WP_MS_Sites_List_Table extends WP_List_Table { - function __construct( $args = array() ) { + public function __construct( $args = array() ) { parent::__construct( array( 'plural' => 'sites', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } - function ajax_user_can() { + public function ajax_user_can() { return current_user_can( 'manage_sites' ); } - function prepare_items() { + public function prepare_items() { global $s, $mode, $wpdb; $current_site = get_current_site(); @@ -120,11 +120,11 @@ class WP_MS_Sites_List_Table extends WP_List_Table { ) ); } - function no_items() { + public function no_items() { _e( 'No sites found.' ); } - function get_bulk_actions() { + protected function get_bulk_actions() { $actions = array(); if ( current_user_can( 'delete_sites' ) ) $actions['delete'] = __( 'Delete' ); @@ -134,7 +134,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table { return $actions; } - function pagination( $which ) { + protected function pagination( $which ) { global $mode; parent::pagination( $which ); @@ -143,7 +143,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table { $this->view_switcher( $mode ); } - function get_columns() { + protected function get_columns() { $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' ); $sites_columns = array( 'cb' => '', @@ -169,7 +169,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table { return $sites_columns; } - function get_sortable_columns() { + protected function get_sortable_columns() { return array( 'blogname' => 'blogname', 'lastupdated' => 'lastupdated', @@ -177,7 +177,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table { ); } - function display_rows() { + protected function display_rows() { global $mode; $status_list = array( diff --git a/src/wp-admin/includes/class-wp-ms-themes-list-table.php b/src/wp-admin/includes/class-wp-ms-themes-list-table.php index 59183c311f..512e341d0f 100644 --- a/src/wp-admin/includes/class-wp-ms-themes-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-themes-list-table.php @@ -9,10 +9,10 @@ */ class WP_MS_Themes_List_Table extends WP_List_Table { - var $site_id; - var $is_site_themes; + public $site_id; + public $is_site_themes; - function __construct( $args = array() ) { + public function __construct( $args = array() ) { global $status, $page; parent::__construct( array( @@ -32,18 +32,18 @@ class WP_MS_Themes_List_Table extends WP_List_Table { $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; } - function get_table_classes() { + protected function get_table_classes() { return array( 'widefat', 'plugins' ); // todo: remove and add CSS for .themes } - function ajax_user_can() { + public function ajax_user_can() { if ( $this->is_site_themes ) return current_user_can( 'manage_sites' ); else return current_user_can( 'manage_network_themes' ); } - function prepare_items() { + public function prepare_items() { global $status, $totals, $page, $orderby, $order, $s; wp_reset_vars( array( 'orderby', 'order', 's' ) ); @@ -131,7 +131,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table { ) ); } - function _search_callback( $theme ) { + public function _search_callback( $theme ) { static $term; if ( is_null( $term ) ) $term = wp_unslash( $_REQUEST['s'] ); @@ -152,7 +152,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table { } // Not used by any core columns. - function _order_callback( $theme_a, $theme_b ) { + public function _order_callback( $theme_a, $theme_b ) { global $orderby, $order; $a = $theme_a[ $orderby ]; @@ -167,14 +167,14 @@ class WP_MS_Themes_List_Table extends WP_List_Table { return ( $a < $b ) ? -1 : 1; } - function no_items() { + public function no_items() { if ( ! $this->has_items ) _e( 'No themes found.' ); else _e( 'You do not appear to have any themes available at this time.' ); } - function get_columns() { + protected function get_columns() { global $status; return array( @@ -184,13 +184,13 @@ class WP_MS_Themes_List_Table extends WP_List_Table { ); } - function get_sortable_columns() { + protected function get_sortable_columns() { return array( 'name' => 'name', ); } - function get_views() { + protected function get_views() { global $totals, $status; $status_links = array(); @@ -233,7 +233,7 @@ class WP_MS_Themes_List_Table extends WP_List_Table { return $status_links; } - function get_bulk_actions() { + protected function get_bulk_actions() { global $status; $actions = array(); @@ -250,12 +250,12 @@ class WP_MS_Themes_List_Table extends WP_List_Table { return $actions; } - function display_rows() { + protected function display_rows() { foreach ( $this->items as $theme ) $this->single_row( $theme ); } - function single_row( $theme ) { + protected function single_row( $theme ) { global $status, $page, $s, $totals; $context = $status; diff --git a/src/wp-admin/includes/class-wp-ms-users-list-table.php b/src/wp-admin/includes/class-wp-ms-users-list-table.php index 1196cc1602..f458ed846c 100644 --- a/src/wp-admin/includes/class-wp-ms-users-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-users-list-table.php @@ -9,11 +9,11 @@ */ class WP_MS_Users_List_Table extends WP_List_Table { - function ajax_user_can() { + public function ajax_user_can() { return current_user_can( 'manage_network_users' ); } - function prepare_items() { + public function prepare_items() { global $usersearch, $role, $wpdb, $mode; $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; @@ -69,7 +69,7 @@ class WP_MS_Users_List_Table extends WP_List_Table { ) ); } - function get_bulk_actions() { + protected function get_bulk_actions() { $actions = array(); if ( current_user_can( 'delete_users' ) ) $actions['delete'] = __( 'Delete' ); @@ -79,11 +79,11 @@ class WP_MS_Users_List_Table extends WP_List_Table { return $actions; } - function no_items() { + public function no_items() { _e( 'No users found.' ); } - function get_views() { + protected function get_views() { global $role; $total_users = get_user_count(); @@ -99,7 +99,7 @@ class WP_MS_Users_List_Table extends WP_List_Table { return $role_links; } - function pagination( $which ) { + protected function pagination( $which ) { global $mode; parent::pagination ( $which ); @@ -108,7 +108,7 @@ class WP_MS_Users_List_Table extends WP_List_Table { $this->view_switcher( $mode ); } - function get_columns() { + protected function get_columns() { $users_columns = array( 'cb' => '', 'username' => __( 'Username' ), @@ -130,7 +130,7 @@ class WP_MS_Users_List_Table extends WP_List_Table { return $users_columns; } - function get_sortable_columns() { + protected function get_sortable_columns() { return array( 'username' => 'login', 'name' => 'name', @@ -139,7 +139,7 @@ class WP_MS_Users_List_Table extends WP_List_Table { ); } - function display_rows() { + protected function display_rows() { global $mode; $alt = ''; diff --git a/src/wp-admin/includes/class-wp-plugin-install-list-table.php b/src/wp-admin/includes/class-wp-plugin-install-list-table.php index fb92084761..4e29a46d8a 100644 --- a/src/wp-admin/includes/class-wp-plugin-install-list-table.php +++ b/src/wp-admin/includes/class-wp-plugin-install-list-table.php @@ -9,11 +9,11 @@ */ class WP_Plugin_Install_List_Table extends WP_List_Table { - function ajax_user_can() { + public function ajax_user_can() { return current_user_can('install_plugins'); } - function prepare_items() { + public function prepare_items() { include( ABSPATH . 'wp-admin/includes/plugin-install.php' ); global $tabs, $tab, $paged, $type, $term; @@ -133,11 +133,11 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { ) ); } - function no_items() { + public function no_items() { _e( 'No plugins match your request.' ); } - function get_views() { + protected function get_views() { global $tabs, $tab; $display_tabs = array(); @@ -150,7 +150,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { return $display_tabs; } - function display_tablenav( $which ) { + protected function display_tablenav( $which ) { if ( 'top' == $which ) { ?>
@@ -174,11 +174,11 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { } } - function get_table_classes() { + protected function get_table_classes() { return array( 'widefat', $this->_args['plural'] ); } - function get_columns() { + protected function get_columns() { return array( 'name' => _x( 'Name', 'plugin name' ), 'version' => __( 'Version' ), @@ -187,7 +187,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { ); } - function display_rows() { + protected function display_rows() { $plugins_allowedtags = array( 'a' => array( 'href' => array(),'title' => array(), 'target' => array() ), 'abbr' => array( 'title' => array() ),'acronym' => array( 'title' => array() ), diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index 6535833710..e75c7a2c7d 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -9,7 +9,7 @@ */ class WP_Plugins_List_Table extends WP_List_Table { - function __construct( $args = array() ) { + public function __construct( $args = array() ) { global $status, $page; parent::__construct( array( @@ -27,15 +27,15 @@ class WP_Plugins_List_Table extends WP_List_Table { $page = $this->get_pagenum(); } - function get_table_classes() { + protected function get_table_classes() { return array( 'widefat', $this->_args['plural'] ); } - function ajax_user_can() { + public function ajax_user_can() { return current_user_can('activate_plugins'); } - function prepare_items() { + public function prepare_items() { global $status, $plugins, $totals, $page, $orderby, $order, $s; wp_reset_vars( array( 'orderby', 'order', 's' ) ); @@ -172,7 +172,7 @@ class WP_Plugins_List_Table extends WP_List_Table { ) ); } - function _search_callback( $plugin ) { + public function _search_callback( $plugin ) { static $term; if ( is_null( $term ) ) $term = wp_unslash( $_REQUEST['s'] ); @@ -186,7 +186,7 @@ class WP_Plugins_List_Table extends WP_List_Table { return false; } - function _order_callback( $plugin_a, $plugin_b ) { + public function _order_callback( $plugin_a, $plugin_b ) { global $orderby, $order; $a = $plugin_a[$orderby]; @@ -201,7 +201,7 @@ class WP_Plugins_List_Table extends WP_List_Table { return ( $a < $b ) ? -1 : 1; } - function no_items() { + public function no_items() { global $plugins; if ( !empty( $plugins['all'] ) ) @@ -210,7 +210,7 @@ class WP_Plugins_List_Table extends WP_List_Table { _e( 'You do not appear to have any plugins available at this time.' ); } - function get_columns() { + protected function get_columns() { global $status; return array( @@ -220,11 +220,11 @@ class WP_Plugins_List_Table extends WP_List_Table { ); } - function get_sortable_columns() { + protected function get_sortable_columns() { return array(); } - function get_views() { + protected function get_views() { global $totals, $status; $status_links = array(); @@ -268,7 +268,7 @@ class WP_Plugins_List_Table extends WP_List_Table { return $status_links; } - function get_bulk_actions() { + protected function get_bulk_actions() { global $status; $actions = array(); @@ -289,7 +289,7 @@ class WP_Plugins_List_Table extends WP_List_Table { return $actions; } - function bulk_actions() { + public function bulk_actions() { global $status; if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) @@ -298,7 +298,7 @@ class WP_Plugins_List_Table extends WP_List_Table { parent::bulk_actions(); } - function extra_tablenav( $which ) { + protected function extra_tablenav( $which ) { global $status; if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) ) @@ -316,14 +316,14 @@ class WP_Plugins_List_Table extends WP_List_Table { echo '
'; } - function current_action() { + public function current_action() { if ( isset($_POST['clear-recent-list']) ) return 'clear-recent-list'; return parent::current_action(); } - function display_rows() { + protected function display_rows() { global $status; if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) ) @@ -333,7 +333,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $this->single_row( array( $plugin_file, $plugin_data ) ); } - function single_row( $item ) { + protected function single_row( $item ) { global $status, $page, $s, $totals; list( $plugin_file, $plugin_data ) = $item; diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index 1e763f2ff3..d88aa16afc 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -16,7 +16,7 @@ class WP_Posts_List_Table extends WP_List_Table { * @var bool * @access protected */ - var $hierarchical_display; + protected $hierarchical_display; /** * Holds the number of pending comments for each post @@ -25,7 +25,7 @@ class WP_Posts_List_Table extends WP_List_Table { * @var int * @access protected */ - var $comment_pending_count; + protected $comment_pending_count; /** * Holds the number of posts for this user @@ -34,7 +34,7 @@ class WP_Posts_List_Table extends WP_List_Table { * @var int * @access private */ - var $user_posts_count; + private $user_posts_count; /** * Holds the number of posts which are sticky. @@ -43,9 +43,9 @@ class WP_Posts_List_Table extends WP_List_Table { * @var int * @access private */ - var $sticky_posts_count = 0; + private $sticky_posts_count = 0; - function __construct( $args = array() ) { + public function __construct( $args = array() ) { global $post_type_object, $wpdb; parent::__construct( array( @@ -74,11 +74,11 @@ class WP_Posts_List_Table extends WP_List_Table { } } - function ajax_user_can() { + public function ajax_user_can() { return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts ); } - function prepare_items() { + public function prepare_items() { global $avail_post_stati, $wp_query, $per_page, $mode; $avail_post_stati = wp_edit_posts_query(); @@ -109,18 +109,18 @@ class WP_Posts_List_Table extends WP_List_Table { ) ); } - function has_items() { + public function has_items() { return have_posts(); } - function no_items() { + public function no_items() { if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] ) echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash; else echo get_post_type_object( $this->screen->post_type )->labels->not_found; } - function get_views() { + protected function get_views() { global $locked_post_status, $avail_post_stati; $post_type = $this->screen->post_type; @@ -181,7 +181,7 @@ class WP_Posts_List_Table extends WP_List_Table { return $status_links; } - function get_bulk_actions() { + protected function get_bulk_actions() { $actions = array(); if ( $this->is_trash ) @@ -197,7 +197,7 @@ class WP_Posts_List_Table extends WP_List_Table { return $actions; } - function extra_tablenav( $which ) { + protected function extra_tablenav( $which ) { global $cat; ?>
@@ -239,14 +239,14 @@ class WP_Posts_List_Table extends WP_List_Table { view_switcher( $mode ); } - function get_table_classes() { + protected function get_table_classes() { return array( 'widefat', 'fixed', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' ); } - function get_columns() { + protected function get_columns() { $post_type = $this->screen->post_type; $posts_columns = array(); @@ -345,7 +345,7 @@ class WP_Posts_List_Table extends WP_List_Table { return $posts_columns; } - function get_sortable_columns() { + protected function get_sortable_columns() { return array( 'title' => 'title', 'parent' => 'parent', @@ -354,7 +354,7 @@ class WP_Posts_List_Table extends WP_List_Table { ); } - function display_rows( $posts = array(), $level = 0 ) { + protected function display_rows( $posts = array(), $level = 0 ) { global $wp_query, $per_page; if ( empty( $posts ) ) @@ -369,7 +369,7 @@ class WP_Posts_List_Table extends WP_List_Table { } } - function _display_rows( $posts, $level = 0 ) { + private function _display_rows( $posts, $level = 0 ) { global $mode; // Create array of post IDs. @@ -384,7 +384,7 @@ class WP_Posts_List_Table extends WP_List_Table { $this->single_row( $post, $level ); } - function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) { + private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) { global $wpdb; $level = 0; @@ -476,7 +476,7 @@ class WP_Posts_List_Table extends WP_List_Table { * @param int $pagenum * @param int $per_page */ - function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) { + private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) { if ( ! isset( $children_pages[$parent] ) ) return; @@ -521,7 +521,7 @@ class WP_Posts_List_Table extends WP_List_Table { unset( $children_pages[$parent] ); //required in order to keep track of orphans } - function single_row( $post, $level = 0 ) { + protected function single_row( $post, $level = 0 ) { global $mode; static $alternate; @@ -879,7 +879,7 @@ class WP_Posts_List_Table extends WP_List_Table { * * @since 3.1.0 */ - function inline_edit() { + public function inline_edit() { global $mode; $screen = $this->screen; diff --git a/src/wp-admin/includes/class-wp-terms-list-table.php b/src/wp-admin/includes/class-wp-terms-list-table.php index bff36ce99d..f1d30b2676 100644 --- a/src/wp-admin/includes/class-wp-terms-list-table.php +++ b/src/wp-admin/includes/class-wp-terms-list-table.php @@ -9,9 +9,9 @@ */ class WP_Terms_List_Table extends WP_List_Table { - var $callback_args; + public $callback_args; - function __construct( $args = array() ) { + public function __construct( $args = array() ) { global $post_type, $taxonomy, $action, $tax; parent::__construct( array( @@ -38,11 +38,11 @@ class WP_Terms_List_Table extends WP_List_Table { } - function ajax_user_can() { + public function ajax_user_can() { return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms ); } - function prepare_items() { + public function prepare_items() { $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' ); if ( 'post_tag' == $this->screen->taxonomy ) { @@ -97,26 +97,26 @@ class WP_Terms_List_Table extends WP_List_Table { ) ); } - function has_items() { + public function has_items() { // todo: populate $this->items in prepare_items() return true; } - function get_bulk_actions() { + protected function get_bulk_actions() { $actions = array(); $actions['delete'] = __( 'Delete' ); return $actions; } - function current_action() { + public function current_action() { if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) ) return 'bulk-delete'; return parent::current_action(); } - function get_columns() { + protected function get_columns() { $columns = array( 'cb' => '', 'name' => _x( 'Name', 'term name' ), @@ -134,7 +134,7 @@ class WP_Terms_List_Table extends WP_List_Table { return $columns; } - function get_sortable_columns() { + protected function get_sortable_columns() { return array( 'name' => 'name', 'description' => 'description', @@ -144,7 +144,7 @@ class WP_Terms_List_Table extends WP_List_Table { ); } - function display_rows_or_placeholder() { + protected function display_rows_or_placeholder() { $taxonomy = $this->screen->taxonomy; $args = wp_parse_args( $this->callback_args, array( @@ -193,7 +193,7 @@ class WP_Terms_List_Table extends WP_List_Table { } } - function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$count, $parent = 0, $level = 0 ) { + private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$count, $parent = 0, $level = 0 ) { $end = $start + $per_page; @@ -241,7 +241,7 @@ class WP_Terms_List_Table extends WP_List_Table { } } - function single_row( $tag, $level = 0 ) { + protected function single_row( $tag, $level = 0 ) { global $taxonomy; $tag = sanitize_term( $tag, $taxonomy ); @@ -255,7 +255,7 @@ class WP_Terms_List_Table extends WP_List_Table { echo ''; } - function column_cb( $tag ) { + public function column_cb( $tag ) { $default_term = get_option( 'default_' . $this->screen->taxonomy ); if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) && $tag->term_id != $default_term ) @@ -265,7 +265,7 @@ class WP_Terms_List_Table extends WP_List_Table { return ' '; } - function column_name( $tag ) { + public function column_name( $tag ) { $taxonomy = $this->screen->taxonomy; $tax = get_taxonomy( $taxonomy ); @@ -339,16 +339,16 @@ class WP_Terms_List_Table extends WP_List_Table { return $out; } - function column_description( $tag ) { + public function column_description( $tag ) { return $tag->description; } - function column_slug( $tag ) { + public function column_slug( $tag ) { /** This filter is documented in wp-admin/edit-tag-form.php */ return apply_filters( 'editable_slug', $tag->slug ); } - function column_posts( $tag ) { + public function column_posts( $tag ) { $count = number_format_i18n( $tag->count ); $tax = get_taxonomy( $this->screen->taxonomy ); @@ -372,14 +372,14 @@ class WP_Terms_List_Table extends WP_List_Table { return "$count"; } - function column_links( $tag ) { + public function column_links( $tag ) { $count = number_format_i18n( $tag->count ); if ( $count ) $count = "$count"; return $count; } - function column_default( $tag, $column_name ) { + public function column_default( $tag, $column_name ) { /** * Filter the displayed columns in the terms list table. * @@ -400,7 +400,7 @@ class WP_Terms_List_Table extends WP_List_Table { * * @since 3.1.0 */ - function inline_edit() { + public function inline_edit() { $tax = get_taxonomy( $this->screen->taxonomy ); if ( ! current_user_can( $tax->cap->edit_terms ) ) diff --git a/src/wp-admin/includes/class-wp-theme-install-list-table.php b/src/wp-admin/includes/class-wp-theme-install-list-table.php index 82d9d3a762..ac2d3f9650 100644 --- a/src/wp-admin/includes/class-wp-theme-install-list-table.php +++ b/src/wp-admin/includes/class-wp-theme-install-list-table.php @@ -9,13 +9,13 @@ */ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { - var $features = array(); + public $features = array(); - function ajax_user_can() { + public function ajax_user_can() { return current_user_can( 'install_themes' ); } - function prepare_items() { + public function prepare_items() { include( ABSPATH . 'wp-admin/includes/theme-install.php' ); global $tabs, $tab, $paged, $type, $theme_field_defaults; @@ -140,11 +140,11 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { ) ); } - function no_items() { + public function no_items() { _e( 'No themes match your request.' ); } - function get_views() { + protected function get_views() { global $tabs, $tab; $display_tabs = array(); @@ -157,7 +157,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { return $display_tabs; } - function display() { + public function display() { wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); ?>
@@ -183,7 +183,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { parent::tablenav( 'bottom' ); } - function display_rows() { + protected function display_rows() { $themes = $this->items; foreach ( $themes as $theme ) { ?> @@ -214,7 +214,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { * public 'description' => string 'A basic magazine style layout with a fully customizable layout through a backend interface. Designed by c.bavota of Tinker Priest Media.' * public 'download_link' => string 'http://wordpress.org/themes/download/magazine-basic.1.1.zip' */ - function single_row( $theme ) { + protected function single_row( $theme ) { global $themes_allowedtags; if ( empty( $theme ) ) @@ -294,7 +294,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { /** * Prints the wrapper for the theme installer. */ - function theme_installer() { + public function theme_installer() { ?>
@@ -323,7 +323,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { * * @param object $theme - A WordPress.org Theme API object. */ - function theme_installer_single( $theme ) { + public function theme_installer_single( $theme ) { ?>
@@ -341,7 +341,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { * * @param object $theme - A WordPress.org Theme API object. */ - function install_theme_info( $theme ) { + public function install_theme_info( $theme ) { global $themes_allowedtags; if ( empty( $theme ) ) @@ -408,7 +408,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { * @uses $tab Global; current tab within Themes->Install screen * @uses $type Global; type of search. */ - function _js_vars( $extra_args = array() ) { + private function _js_vars( $extra_args = array() ) { global $tab, $type; parent::_js_vars( compact( 'tab', 'type' ) ); } diff --git a/src/wp-admin/includes/class-wp-themes-list-table.php b/src/wp-admin/includes/class-wp-themes-list-table.php index be75de02a6..521d24b4d5 100644 --- a/src/wp-admin/includes/class-wp-themes-list-table.php +++ b/src/wp-admin/includes/class-wp-themes-list-table.php @@ -10,21 +10,21 @@ class WP_Themes_List_Table extends WP_List_Table { protected $search_terms = array(); - var $features = array(); + public $features = array(); - function __construct( $args = array() ) { + public function __construct( $args = array() ) { parent::__construct( array( 'ajax' => true, 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } - function ajax_user_can() { + public function ajax_user_can() { // Do not check edit_theme_options here. AJAX calls for available themes require switch_themes. return current_user_can( 'switch_themes' ); } - function prepare_items() { + public function prepare_items() { $themes = wp_get_themes( array( 'allowed' => true ) ); if ( ! empty( $_REQUEST['s'] ) ) @@ -57,7 +57,7 @@ class WP_Themes_List_Table extends WP_List_Table { ) ); } - function no_items() { + public function no_items() { if ( $this->search_terms || $this->features ) { _e( 'No items found.' ); return; @@ -85,7 +85,7 @@ class WP_Themes_List_Table extends WP_List_Table { printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) ); } - function tablenav( $which = 'top' ) { + public function tablenav( $which = 'top' ) { if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) return; ?> @@ -97,7 +97,7 @@ class WP_Themes_List_Table extends WP_List_Table { tablenav( 'top' ); ?> @@ -110,11 +110,11 @@ class WP_Themes_List_Table extends WP_List_Table { has_items() ) { $this->display_rows(); } else { @@ -124,7 +124,7 @@ class WP_Themes_List_Table extends WP_List_Table { } } - function display_rows() { + protected function display_rows() { $themes = $this->items; foreach ( $themes as $theme ): @@ -208,7 +208,7 @@ class WP_Themes_List_Table extends WP_List_Table { endforeach; } - function search_theme( $theme ) { + public function search_theme( $theme ) { // Search the features foreach ( $this->features as $word ) { if ( ! in_array( $word, $theme->get('Tags') ) ) @@ -249,7 +249,7 @@ class WP_Themes_List_Table extends WP_List_Table { * @uses get_pagenum() * @uses _pagination_args['total_pages'] */ - function _js_vars( $extra_args = array() ) { + private function _js_vars( $extra_args = array() ) { $search_string = isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : ''; $args = array( diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index 40c8854c26..9517730f9a 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -45,7 +45,17 @@ function _delete_all_posts() { class Basic_Object { private $foo = 'bar'; - function __get( $name ) { + public function __get( $name ) { return $this->$name; } + + public function __call( $name, $arguments ) { + return call_user_func_array( array( $this, $name ), $arguments ); + } + + private function callMe() { + return 'maybe'; + } } + +class Basic_Subclass extends Basic_Object {} \ No newline at end of file diff --git a/tests/phpunit/tests/basic.php b/tests/phpunit/tests/basic.php index 42a7218c38..c7edf790d6 100644 --- a/tests/phpunit/tests/basic.php +++ b/tests/phpunit/tests/basic.php @@ -127,4 +127,22 @@ EOF; $this->assertEquals( 'bar', $basic->foo ); } + + function test_subclass_magic_getter() { + $basic = new Basic_Subclass(); + + $this->assertEquals( 'bar', $basic->foo ); + } + + function test_call_method() { + $basic = new Basic_Object(); + + $this->assertEquals( 'maybe', $basic->callMe() ); + } + + function test_subclass_call_method() { + $basic = new Basic_Subclass(); + + $this->assertEquals( 'maybe', $basic->callMe() ); + } }