From dea07077facb168d8ebea751a2fb71a7f8cf2d63 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 13 Jun 2015 16:53:06 +0000 Subject: [PATCH] In `WP_MS_Themes_List_Table::display_rows()`: * Move the giant `switch` statement into methods * Call `->single_row_columns()`, which we now override See #29881. git-svn-id: https://develop.svn.wordpress.org/trunk@32756 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-ms-themes-list-table.php | 213 +++++++++++++----- 1 file changed, 152 insertions(+), 61 deletions(-) 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 0a8a8ada9e..0092614f89 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 @@ -336,15 +336,29 @@ class WP_MS_Themes_List_Table extends WP_List_Table { } /** - * @global string $status - * @global int $page - * @global string $s - * @global array $totals + * @since 4.3.0 * * @param WP_Theme $theme */ - public function single_row( $theme ) { - global $status, $page, $s, $totals; + public function column_cb( $theme ) { + $checkbox_id = 'checkbox_' . md5( $theme->get('Name') ); + ?> + + + errors() ) + if ( ! $theme->errors() ) { $actions['enable'] = '' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . ''; + } } else { $actions['disable'] = '' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . ''; } - if ( current_user_can('edit_themes') ) + if ( current_user_can('edit_themes') ) { $actions['edit'] = '' . __('Edit') . ''; + } - if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) ) + if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) ) { $actions['delete'] = '' . __( 'Delete' ) . ''; - + } /** * Filter the action links displayed for each theme in the Multisite * themes list table. @@ -420,17 +436,93 @@ class WP_MS_Themes_List_Table extends WP_List_Table { */ $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context ); + echo $this->row_actions( $actions, true ); + } + + /** + * @since 4.3.0 + * + * @global string $status + * @global array $totals + * + * @param WP_Theme $theme + */ + public function column_description( $theme ) { + global $status, $totals; + if ( $theme->errors() ) { + $pre = $status == 'broken' ? __( 'Broken Theme:' ) . ' ' : ''; + echo '

' . $pre . $theme->errors()->get_error_message() . '

'; + } + + if ( $this->is_site_themes ) { + $allowed = $theme->is_allowed( 'site', $this->site_id ); + } else { + $allowed = $theme->is_allowed( 'network' ); + } + $class = ! $allowed ? 'inactive' : 'active'; - $checkbox_id = "checkbox_" . md5( $theme->get('Name') ); - $checkbox = ""; - - $id = sanitize_html_class( $theme->get_stylesheet() ); - if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) $class .= ' update'; - echo ""; + echo "

" . $theme->display( 'Description' ) . "

+
"; + $stylesheet = $theme->get_stylesheet(); + $theme_meta = array(); + + if ( $theme->get('Version') ) { + $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') ); + } + $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') ); + + if ( $theme->get('ThemeURI') ) { + $theme_meta[] = '' . __( 'Visit Theme Site' ) . ''; + } + /** + * Filter the array of row meta for each theme in the Multisite themes + * list table. + * + * @since 3.1.0 + * + * @param array $theme_meta An array of the theme's metadata, + * including the version, author, and + * theme URI. + * @param string $stylesheet Directory name of the theme. + * @param WP_Theme $theme WP_Theme object. + * @param string $status Status of the theme. + */ + $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status ); + echo implode( ' | ', $theme_meta ); + + echo '
'; + } + + /** + * @since 4.3.0 + * + * @param WP_Theme $theme + * @param string $column_name + */ + public function column_default( $theme, $column_name ) { + $stylesheet = $theme->get_stylesheet(); + /** + * Fires inside each custom column of the Multisite themes list table. + * + * @since 3.1.0 + * + * @param string $column_name Name of the column. + * @param string $stylesheet Directory name of the theme. + * @param WP_Theme $theme Current WP_Theme object. + */ + do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme ); + } + + /** + * @since 4.3.0 + * + * @param WP_Theme $item + */ + public function single_row_columns( $item ) { list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { @@ -441,69 +533,68 @@ class WP_MS_Themes_List_Table extends WP_List_Table { switch ( $column_name ) { case 'cb': - echo "$checkbox"; + echo ''; + + $this->column_cb( $item ); + + echo ''; break; + case 'name': - echo "" . $theme->display('Name') . ""; - echo $this->row_actions($actions, true); + echo "" . $item->display('Name') . ""; + + $this->column_name( $item ); + echo ""; break; + case 'description': echo ""; - if ( $theme->errors() ) { - $pre = $status == 'broken' ? __( 'Broken Theme:' ) . ' ' : ''; - echo '

' . $pre . $theme->errors()->get_error_message() . '

'; - } - echo "

" . $theme->display( 'Description' ) . "

-
"; - $theme_meta = array(); + $this->column_description( $item ); - if ( $theme->get('Version') ) - $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') ); - - $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') ); - - if ( $theme->get('ThemeURI') ) - $theme_meta[] = '' . __( 'Visit Theme Site' ) . ''; - - /** - * Filter the array of row meta for each theme in the Multisite themes - * list table. - * - * @since 3.1.0 - * - * @param array $theme_meta An array of the theme's metadata, - * including the version, author, and - * theme URI. - * @param string $stylesheet Directory name of the theme. - * @param WP_Theme $theme WP_Theme object. - * @param string $status Status of the theme. - */ - $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status ); - echo implode( ' | ', $theme_meta ); - - echo '
'; echo ''; break; default: echo ""; - /** - * Fires inside each custom column of the Multisite themes list table. - * - * @since 3.1.0 - * - * @param string $column_name Name of the column. - * @param string $stylesheet Directory name of the theme. - * @param WP_Theme $theme Current WP_Theme object. - */ - do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme ); + $this->column_default( $item, $column_name ); echo ""; + break; } } + } + + /** + * @global string $status + * @global array $totals + * + * @param WP_Theme $theme + */ + public function single_row( $theme ) { + global $status, $totals; + + if ( $this->is_site_themes ) { + $allowed = $theme->is_allowed( 'site', $this->site_id ); + } else { + $allowed = $theme->is_allowed( 'network' ); + } + + $stylesheet = $theme->get_stylesheet(); + + $class = ! $allowed ? 'inactive' : 'active'; + + $id = sanitize_html_class( $theme->get_stylesheet() ); + + if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) { + $class .= ' update'; + } + + echo ""; + + $this->single_row_columns( $theme ); echo "";