diff -r c7c34916027a -r 177826044cd9 wp/wp-admin/includes/class-wp-theme-install-list-table.php --- a/wp/wp-admin/includes/class-wp-theme-install-list-table.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-admin/includes/class-wp-theme-install-list-table.php Mon Oct 14 18:28:13 2019 +0200 @@ -20,7 +20,6 @@ public $features = array(); /** - * * @return bool */ public function ajax_user_can() { @@ -28,7 +27,6 @@ } /** - * * @global array $tabs * @global string $tab * @global int $paged @@ -41,30 +39,32 @@ global $tabs, $tab, $paged, $type, $theme_field_defaults; wp_reset_vars( array( 'tab' ) ); - $search_terms = array(); + $search_terms = array(); $search_string = ''; - if ( ! empty( $_REQUEST['s'] ) ){ + if ( ! empty( $_REQUEST['s'] ) ) { $search_string = strtolower( wp_unslash( $_REQUEST['s'] ) ); - $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); + $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); } - if ( ! empty( $_REQUEST['features'] ) ) + if ( ! empty( $_REQUEST['features'] ) ) { $this->features = $_REQUEST['features']; + } $paged = $this->get_pagenum(); $per_page = 36; // These are the tabs which are shown on the page, - $tabs = array(); + $tabs = array(); $tabs['dashboard'] = __( 'Search' ); - if ( 'search' === $tab ) - $tabs['search'] = __( 'Search Results' ); - $tabs['upload'] = __( 'Upload' ); + if ( 'search' === $tab ) { + $tabs['search'] = __( 'Search Results' ); + } + $tabs['upload'] = __( 'Upload' ); $tabs['featured'] = _x( 'Featured', 'themes' ); //$tabs['popular'] = _x( 'Popular', 'themes' ); - $tabs['new'] = _x( 'Latest', 'themes' ); - $tabs['updated'] = _x( 'Recently Updated', 'themes' ); + $tabs['new'] = _x( 'Latest', 'themes' ); + $tabs['updated'] = _x( 'Recently Updated', 'themes' ); $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item. @@ -76,16 +76,21 @@ * * @since 2.8.0 * - * @param array $nonmenu_tabs The tabs that don't have a menu item on - * the Install Themes screen. + * @param string[] $nonmenu_tabs The tabs that don't have a menu item on + * the Install Themes screen. */ $nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs ); // If a non-valid menu tab has been selected, And it's not a non-menu action. - if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) + if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) { $tab = key( $tabs ); + } - $args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults ); + $args = array( + 'page' => $paged, + 'per_page' => $per_page, + 'fields' => $theme_field_defaults, + ); switch ( $tab ) { case 'search': @@ -103,8 +108,8 @@ } if ( ! empty( $this->features ) ) { - $args['tag'] = $this->features; - $_REQUEST['s'] = implode( ',', $this->features ); + $args['tag'] = $this->features; + $_REQUEST['s'] = implode( ',', $this->features ); $_REQUEST['type'] = 'tag'; } @@ -112,7 +117,7 @@ break; case 'featured': - // case 'popular': + // case 'popular': case 'new': case 'updated': $args['browse'] = $tab; @@ -136,21 +141,25 @@ */ $args = apply_filters( "install_themes_table_api_args_{$tab}", $args ); - if ( ! $args ) + if ( ! $args ) { return; + } $api = themes_api( 'query_themes', $args ); - if ( is_wp_error( $api ) ) + if ( is_wp_error( $api ) ) { wp_die( $api->get_error_message() . '

' . __( 'Try again' ) . '' ); + } $this->items = $api->themes; - $this->set_pagination_args( array( - 'total_items' => $api->info['results'], - 'per_page' => $args['per_page'], - 'infinite_scroll' => true, - ) ); + $this->set_pagination_args( + array( + 'total_items' => $api->info['results'], + 'per_page' => $args['per_page'], + 'infinite_scroll' => true, + ) + ); } /** @@ -160,7 +169,6 @@ } /** - * * @global array $tabs * @global string $tab * @return array @@ -170,9 +178,9 @@ $display_tabs = array(); foreach ( (array) $tabs as $action => $text ) { - $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : ''; - $href = self_admin_url('theme-install.php?tab=' . $action); - $display_tabs['theme-install-'.$action] = "$text"; + $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : ''; + $href = self_admin_url( 'theme-install.php?tab=' . $action ); + $display_tabs[ 'theme-install-' . $action ] = "$text"; } return $display_tabs; @@ -181,8 +189,8 @@ /** */ public function display() { - wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); -?> + wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); + ?>

items; foreach ( $themes as $theme ) { - ?> -
+
+ single_row( $theme ); - ?>
- +
+ theme_installer(); } @@ -230,15 +241,15 @@ * @param object $theme { * An object that contains theme data returned by the WordPress.org API. * - * @type string $name Theme name, e.g. 'Twenty Seventeen'. - * @type string $slug Theme slug, e.g. 'twentyseventeen'. + * @type string $name Theme name, e.g. 'Twenty Nineteen'. + * @type string $slug Theme slug, e.g. 'twentynineteen'. * @type string $version Theme version, e.g. '1.1'. * @type string $author Theme author username, e.g. 'melchoyce'. - * @type string $preview_url Preview URL, e.g. 'http://2017.wordpress.net/'. - * @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentyseventeen/'. + * @type string $preview_url Preview URL, e.g. 'http://2019.wordpress.net/'. + * @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentynineteen/'. * @type float $rating Rating score. * @type int $num_ratings The number of ratings. - * @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentyseventeen/'. + * @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentynineteen/'. * @type string $description Theme description. * @type string $download_link Theme ZIP download URL. * } @@ -246,54 +257,87 @@ public function single_row( $theme ) { global $themes_allowedtags; - if ( empty( $theme ) ) + if ( empty( $theme ) ) { return; + } - $name = wp_kses( $theme->name, $themes_allowedtags ); + $name = wp_kses( $theme->name, $themes_allowedtags ); $author = wp_kses( $theme->author, $themes_allowedtags ); - $preview_title = sprintf( __('Preview “%s”'), $name ); - $preview_url = add_query_arg( array( - 'tab' => 'theme-information', - 'theme' => $theme->slug, - ), self_admin_url( 'theme-install.php' ) ); + /* translators: %s: theme name */ + $preview_title = sprintf( __( 'Preview “%s”' ), $name ); + $preview_url = add_query_arg( + array( + 'tab' => 'theme-information', + 'theme' => $theme->slug, + ), + self_admin_url( 'theme-install.php' ) + ); $actions = array(); - $install_url = add_query_arg( array( - 'action' => 'install-theme', - 'theme' => $theme->slug, - ), self_admin_url( 'update.php' ) ); + $install_url = add_query_arg( + array( + 'action' => 'install-theme', + 'theme' => $theme->slug, + ), + self_admin_url( 'update.php' ) + ); - $update_url = add_query_arg( array( - 'action' => 'upgrade-theme', - 'theme' => $theme->slug, - ), self_admin_url( 'update.php' ) ); + $update_url = add_query_arg( + array( + 'action' => 'upgrade-theme', + 'theme' => $theme->slug, + ), + self_admin_url( 'update.php' ) + ); $status = $this->_get_theme_status( $theme ); switch ( $status ) { case 'update_available': - $actions[] = '' . __( 'Update' ) . ''; + $actions[] = sprintf( + '%s', + esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ), + /* translators: %s: theme version */ + esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ), + __( 'Update' ) + ); break; case 'newer_installed': case 'latest_installed': - $actions[] = '' . _x( 'Installed', 'theme' ) . ''; + $actions[] = sprintf( + '%s', + esc_attr__( 'This theme is already installed and is up to date' ), + _x( 'Installed', 'theme' ) + ); break; case 'install': default: - $actions[] = '' . __( 'Install Now' ) . ''; + $actions[] = sprintf( + '%s', + esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ), + /* translators: %s: theme name */ + esc_attr( sprintf( __( 'Install %s' ), $name ) ), + __( 'Install Now' ) + ); break; } - $actions[] = '' . __( 'Preview' ) . ''; + $actions[] = sprintf( + '%s', + esc_url( $preview_url ), + /* translators: %s: theme name */ + esc_attr( sprintf( __( 'Preview %s' ), $name ) ), + __( 'Preview' ) + ); /** * Filters the install action links for a theme in the Install Themes list table. * * @since 3.4.0 * - * @param array $actions An array of theme action hyperlinks. Defaults are + * @param string[] $actions An array of theme action links. Defaults are * links to Install Now, Preview, and Details. * @param WP_Theme $theme Theme object. */ @@ -305,14 +349,19 @@

-
+
+ +
@@ -375,48 +424,84 @@ public function install_theme_info( $theme ) { global $themes_allowedtags; - if ( empty( $theme ) ) + if ( empty( $theme ) ) { return; + } - $name = wp_kses( $theme->name, $themes_allowedtags ); + $name = wp_kses( $theme->name, $themes_allowedtags ); $author = wp_kses( $theme->author, $themes_allowedtags ); - $install_url = add_query_arg( array( - 'action' => 'install-theme', - 'theme' => $theme->slug, - ), self_admin_url( 'update.php' ) ); + $install_url = add_query_arg( + array( + 'action' => 'install-theme', + 'theme' => $theme->slug, + ), + self_admin_url( 'update.php' ) + ); - $update_url = add_query_arg( array( - 'action' => 'upgrade-theme', - 'theme' => $theme->slug, - ), self_admin_url( 'update.php' ) ); + $update_url = add_query_arg( + array( + 'action' => 'upgrade-theme', + 'theme' => $theme->slug, + ), + self_admin_url( 'update.php' ) + ); $status = $this->_get_theme_status( $theme ); ?> -
slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . ''; - break; - case 'newer_installed': - case 'latest_installed': - echo '' . _x( 'Installed', 'theme' ) . ''; - break; - case 'install': - default: - echo '' . __( 'Install' ) . ''; - break; - } ?> +
+ %s', + esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ), + /* translators: %s: theme version */ + esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ), + __( 'Update' ) + ); + break; + case 'newer_installed': + case 'latest_installed': + printf( + '%s', + esc_attr__( 'This theme is already installed and is up to date' ), + _x( 'Installed', 'theme' ) + ); + break; + case 'install': + default: + printf( + '%s', + esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ), + __( 'Install' ) + ); + break; + } + ?>

- - screenshot_url ) ): ?> + + + + screenshot_url ) ) : ?>
- $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings ) ); ?> + $theme->rating, + 'type' => 'percent', + 'number' => $theme->num_ratings, + ) + ); + ?>
- + version, $themes_allowedtags ); ?>
@@ -456,12 +541,13 @@ $installed_theme = wp_get_theme( $theme->slug ); if ( $installed_theme->exists() ) { - if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) ) + if ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '=' ) ) { $status = 'latest_installed'; - elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) ) + } elseif ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '>' ) ) { $status = 'newer_installed'; - else + } else { $status = 'update_available'; + } } return $status;