From 248b08654090ce313a03e02da9e89b9d4ea64c34 Mon Sep 17 00:00:00 2001 From: scribu Date: Fri, 24 Sep 2010 13:35:06 +0000 Subject: [PATCH] Column headers revamp: * undeprecate get_column_headers() * undeprecate get_hidden_columns() * in WP_List_Table, rename get_column_headers() to get_column_info() * remove $taxonomy argument from single_row() * merge manage_columns_prefs() into screen_meta() Fixes #14952. Fixes #14776. git-svn-id: http://svn.automattic.com/wordpress/trunk@15653 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/default-list-tables.php | 16 ++-- wp-admin/includes/deprecated.php | 42 --------- wp-admin/includes/list-table.php | 27 +++--- wp-admin/includes/template.php | 100 ++++++++++++++-------- 4 files changed, 80 insertions(+), 105 deletions(-) diff --git a/wp-admin/includes/default-list-tables.php b/wp-admin/includes/default-list-tables.php index 8e8c88516d..bb48613705 100644 --- a/wp-admin/includes/default-list-tables.php +++ b/wp-admin/includes/default-list-tables.php @@ -454,7 +454,7 @@ class WP_Posts_Table extends WP_List_Table { post_status ); ?> iedit' valign="top"> get_column_headers(); + list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class=\"$column_name column-$column_name\""; @@ -676,7 +676,7 @@ class WP_Posts_Table extends WP_List_Table { $flat_taxonomies[] = $taxonomy; } - list( $columns, $hidden ) = $this->get_column_headers(); + list( $columns, $hidden ) = $this->get_column_info(); $col_count = count( $columns ) - count( $hidden ); $m = ( isset( $mode ) && 'excerpt' == $mode ) ? 'excerpt' : 'list'; @@ -1162,7 +1162,7 @@ class WP_Media_Table extends WP_List_Table { post_status ); ?>' valign="top"> get_column_headers(); +list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class='$column_name column-$column_name'"; @@ -1727,7 +1727,7 @@ class WP_Terms_Table extends WP_List_Table { if ( ! current_user_can( $tax->cap->edit_terms ) ) return; - list( $columns, $hidden ) = $this->get_column_headers(); + list( $columns, $hidden ) = $this->get_column_info(); $col_count = count( $columns ) - count( $hidden ); ?> @@ -1996,7 +1996,7 @@ class WP_Users_Table extends WP_List_Table { $r = ""; $avatar = get_avatar( $user_object->ID, 32 ); - list( $columns, $hidden ) = $this->get_column_headers(); + list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class=\"$column_name column-$column_name\""; @@ -2648,7 +2648,7 @@ class WP_Links_Table extends WP_List_Table { > get_column_headers(); + list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class='column-$column_name'"; @@ -2869,7 +2869,7 @@ class WP_Sites_Table extends WP_List_Table { $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path']; - list( $columns, $hidden ) = $this->get_column_headers(); + list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { switch ( $column_name ) { @@ -3117,7 +3117,7 @@ class WP_MS_Users_Table extends WP_List_Table { get_column_headers(); + list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) : switch ( $column_name ) { diff --git a/wp-admin/includes/deprecated.php b/wp-admin/includes/deprecated.php index 9597c30f83..343e44132d 100644 --- a/wp-admin/includes/deprecated.php +++ b/wp-admin/includes/deprecated.php @@ -369,28 +369,6 @@ function register_column_headers($screen, $columns) { $wp_list_table->_columns = $columns; } -/** - * Get the column headers for a screen - * - * @since 2.7.0 - * @deprecated 3.1.0 - * @deprecated Use WP_List_Table - * - * @param string|object $screen The screen you want the headers for - * @return array Containing the headers in the format id => UI String - */ -function get_column_headers($screen) { - _deprecated_function( __FUNCTION__, '3.1', 'WP_List_Table' ); - - global $wp_list_table; - if ( !is_a($wp_list_table, 'WP_List_Table') ) - $wp_list_table = new _WP_List_Table_Compat($screen); - - list( $columns ) = $wp_list_table->get_column_headers(); - - return $columns; -} - /** * Prints column headers for a particular screen. * @@ -408,26 +386,6 @@ function print_column_headers($screen, $id = true) { $wp_list_table->print_column_headers($id); } -/** - * Gets hidden column names for a particular screen. - * - * @since 2.7.0 - * @deprecated 3.1.0 - * @deprecated Use WP_List_Table - * - * @param string $screen - * @return array - */ -function get_hidden_columns($screen) { - _deprecated_function( __FUNCTION__, '3.1', 'WP_List_Table' ); - - global $wp_list_table; - if ( !is_a($wp_list_table, 'WP_List_Table') ) - $wp_list_table = new _WP_List_Table_Compat($screen); - - return $wp_list_table->get_hidden_columns(); -} - // Helper class to be used only by deprecated functions class _WP_List_Table_Compat extends WP_List_Table { diff --git a/wp-admin/includes/list-table.php b/wp-admin/includes/list-table.php index 69bcd4a08e..90d367984f 100644 --- a/wp-admin/includes/list-table.php +++ b/wp-admin/includes/list-table.php @@ -69,6 +69,9 @@ class WP_List_Table { * @access protected */ function WP_List_Table( $args ) { + global $_wp_column_headers; + + $_wp_column_headers = $this->get_columns(); $args = wp_parse_args( $args, array( 'screen' => '', @@ -82,6 +85,8 @@ class WP_List_Table { if ( is_string( $this->_screen ) ) $this->_screen = convert_to_screen( $this->_screen ); + add_filter( 'manage_' . $this->_screen->id . '_columns', array( $this, 'get_columns' ) ); + if ( !$args['plural'] ) $args['plural'] = $this->_screen->base; @@ -513,18 +518,6 @@ class WP_List_Table { return array(); } - /** - * Get a list of hidden columns. - * - * @since 3.1.0 - * @access private - * - * @return array - */ - function get_hidden_columns() { - return (array) get_user_option( 'manage' . $this->_screen->id. 'columnshidden' ); - } - /** * Get a list of all, hidden and sortable columns, with filter applied * @@ -533,11 +526,11 @@ class WP_List_Table { * * @return array */ - function get_column_headers() { + function get_column_info() { if ( !isset( $this->_column_headers ) ) { - $columns = apply_filters( 'manage_' . $this->_screen->id . '_columns', $this->get_columns() ); + $columns = get_column_headers( $this->_screen ); + $hidden = get_hidden_columns( $this->_screen ); $sortable = apply_filters( 'manage_' . $this->_screen->id . '_sortable_columns', $this->get_sortable_columns() ); - $hidden = $this->get_hidden_columns(); $this->_column_headers = array( $columns, $hidden, $sortable ); } @@ -556,7 +549,7 @@ class WP_List_Table { function print_column_headers( $with_id = true ) { $screen = $this->_screen; - list( $columns, $hidden, $sortable ) = $this->get_column_headers(); + list( $columns, $hidden, $sortable ) = $this->get_column_info(); $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; @@ -746,7 +739,7 @@ class WP_List_Table { * @param $object $item The current item */ function single_row_columns( $item ) { - list( $columns, $hidden ) = $this->get_column_headers(); + list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class=\"$column_name column-$column_name\""; diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index c7bae92bf6..27a4f298f1 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -219,6 +219,42 @@ function wp_link_category_checklist( $link_id = 0 ) { } } +/** + * Get the column headers for a screen + * + * @since 2.7.0 + * + * @param string|object $screen The screen you want the headers for + * @return array Containing the headers in the format id => UI String + */ +function get_column_headers( $screen ) { + if ( is_string( $screen ) ) + $screen = convert_to_screen( $screen ); + + global $_wp_column_headers; + + if ( !isset( $_wp_column_headers[ $screen->id ] ) ) { + $_wp_column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', $_wp_column_headers ); + } + + return $_wp_column_headers[ $screen->id ]; +} + +/** + * Get a list of hidden columns. + * + * @since 2.7.0 + * + * @param string|object $screen The screen you want the hidden columns for + * @return array + */ +function get_hidden_columns( $screen ) { + if ( is_string( $screen ) ) + $screen = convert_to_screen( $screen ); + + return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' ); +} + // adds hidden fields with the data for use in the inline editor for posts and pages /** * {@internal Missing Short Description}} @@ -295,8 +331,8 @@ function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $wp_list_table = get_list_table('comments'); - $columns = $wp_list_table->get_column_headers(); - $hidden = array_intersect( array_keys( $columns ), array_filter( $wp_list_table->get_hidden_columns() ) ); + list ( $columns, $hidden ) = $wp_list_table->get_column_info(); + $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) ); $col_count = count($columns) - count($hidden); ?> @@ -1285,36 +1321,6 @@ function settings_errors( $setting = '', $sanitize = FALSE, $hide_on_update = FA echo $output; } -/** - * {@internal Missing Short Description}} - * - * @since unknown - * - * @param unknown_type $page - */ -function manage_columns_prefs( $page ) { - global $wp_list_table; - - list( $columns, $hidden ) = $wp_list_table->get_column_headers(); - - $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username'); - - foreach ( $columns as $column => $title ) { - // Can't hide these for they are special - if ( in_array( $column, $special ) ) - continue; - if ( empty( $title ) ) - continue; - - if ( 'comments' == $column ) - $title = __( 'Comments' ); - $id = "$column-hide"; - echo '\n"; - } -} - /** * {@internal Missing Short Description}} * @@ -1634,8 +1640,9 @@ function screen_meta($screen) { if ( is_string($screen) ) $screen = convert_to_screen($screen); - if ( is_a($wp_list_table, 'WP_List_Table') ) - list( $screen_columns ) = $wp_list_table->get_column_headers(); + $columns = get_column_headers( $screen ); + $hidden = get_hidden_columns( $screen ); + $meta_screens = array('index' => 'dashboard'); if ( isset($meta_screens[$screen->id]) ) { @@ -1644,7 +1651,7 @@ function screen_meta($screen) { } $show_screen = false; - if ( !empty($wp_meta_boxes[$screen->id]) || !empty($screen_columns) ) + if ( !empty($wp_meta_boxes[$screen->id]) || !empty($columns) ) $show_screen = true; $screen_options = screen_options($screen); @@ -1677,10 +1684,27 @@ function screen_meta($screen) {
-
+ if ( ! empty($columns) ) : ?> +
- + $title ) { + // Can't hide these for they are special + if ( in_array( $column, $special ) ) + continue; + if ( empty( $title ) ) + continue; + + if ( 'comments' == $column ) + $title = __( 'Comments' ); + $id = "$column-hide"; + echo '\n"; + } +?>