diff -r be944660c56a -r 3d72ae0968f4 wp/wp-admin/includes/theme.php --- a/wp/wp-admin/includes/theme.php Wed Sep 21 18:19:35 2022 +0200 +++ b/wp/wp-admin/includes/theme.php Tue Sep 27 16:37:53 2022 +0200 @@ -7,7 +7,7 @@ */ /** - * Remove a theme + * Removes a theme. * * @since 2.8.0 * @@ -146,7 +146,7 @@ } /** - * Tidies a filename for url display by the theme editor. + * Tidies a filename for url display by the theme file editor. * * @since 2.9.0 * @access private @@ -175,7 +175,7 @@ } /** - * Retrieve the update link if there is a theme update available. + * Retrieves the update link if there is a theme update available. * * Will return a link if there is an update available. * @@ -271,7 +271,7 @@ } /** - * Retrieve list of WordPress theme features (aka theme tags). + * Retrieves list of WordPress theme features (aka theme tags). * * @since 3.1.0 * @since 3.2.0 Added 'Gray' color and 'Featured Image Header', 'Featured Images', @@ -521,7 +521,7 @@ /** * Filters whether to override the WordPress.org Themes API. * - * Passing a non-false value will effectively short-circuit the WordPress.org API request. + * Returning a non-false value will effectively short-circuit the WordPress.org API request. * * If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST * be passed. If `$action` is 'hot_tags', an array should be passed. @@ -602,15 +602,18 @@ } } - // Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects. - if ( 'query_themes' === $action ) { - foreach ( $res->themes as $i => $theme ) { - $res->themes[ $i ] = (object) $theme; + if ( ! is_wp_error( $res ) ) { + // Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects. + if ( 'query_themes' === $action ) { + foreach ( $res->themes as $i => $theme ) { + $res->themes[ $i ] = (object) $theme; + } } - } - // Back-compat for info/1.2 API, downgrade the feature_list result back to an array. - if ( 'feature_list' === $action ) { - $res = (array) $res; + + // Back-compat for info/1.2 API, downgrade the feature_list result back to an array. + if ( 'feature_list' === $action ) { + $res = (array) $res; + } } } @@ -619,16 +622,16 @@ * * @since 2.8.0 * - * @param array|object|WP_Error $res WordPress.org Themes API response. - * @param string $action Requested action. Likely values are 'theme_information', - * 'feature_list', or 'query_themes'. - * @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. + * @param array|stdClass|WP_Error $res WordPress.org Themes API response. + * @param string $action Requested action. Likely values are 'theme_information', + * 'feature_list', or 'query_themes'. + * @param stdClass $args Arguments used to query for installer pages from the WordPress.org Themes API. */ return apply_filters( 'themes_api_result', $res, $action, $args ); } /** - * Prepare themes for JavaScript. + * Prepares themes for JavaScript. * * @since 3.8.0 * @@ -650,7 +653,7 @@ * * @param array $prepared_themes An associative array of theme data. Default empty array. * @param WP_Theme[]|null $themes An array of theme objects to prepare, if any. - * @param string $current_theme The current theme slug. + * @param string $current_theme The active theme slug. */ $prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme ); @@ -658,7 +661,7 @@ return $prepared_themes; } - // Make sure the current theme is listed first. + // Make sure the active theme is listed first. $prepared_themes[ $current_theme ] = array(); if ( null === $themes ) { @@ -698,7 +701,14 @@ } $customize_action = null; - if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { + + $can_edit_theme_options = current_user_can( 'edit_theme_options' ); + $can_customize = current_user_can( 'customize' ); + $is_block_theme = $theme->is_block_theme(); + + if ( $is_block_theme && $can_edit_theme_options ) { + $customize_action = esc_url( admin_url( 'site-editor.php' ) ); + } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) { $customize_action = esc_url( add_query_arg( array( @@ -772,6 +782,7 @@ ? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&stylesheet=' . $encoded_slug ), 'updates' ) : null, ), + 'blockTheme' => $theme->is_block_theme(), ); } @@ -795,7 +806,7 @@ } /** - * Print JS templates for the theme-browsing UI in the Customizer. + * Prints JS templates for the theme-browsing UI in the Customizer. * * @since 4.2.0 */ @@ -812,7 +823,7 @@
<# if ( data.screenshot && data.screenshot[0] ) { #> -
+
<# } else { #>
<# } #> @@ -820,7 +831,7 @@
<# if ( data.active ) { #> - + <# } #>

{{{ data.name }}}

<# if ( ! data.compatibleWP && ! data.compatiblePHP ) { #> <# } else if ( ! data.compatibleWP ) { #> <# } else if ( ! data.compatiblePHP ) { #> <# } #>

+ <# } else if ( ! data.active && data.blockTheme ) { #> +

+ + <# if ( data.actions.activate ) { #> + activate this theme, and use the Site Editor to customize it.' ), + '{{{ data.actions.activate }}}' + ); + ?> + <# } #> +

<# } #>

{{{ data.description }}}

@@ -1014,10 +1040,20 @@ <# } #> - <# if ( data.compatibleWP && data.compatiblePHP ) { #> - + <# if ( data.blockTheme ) { #> + + <# if ( data.compatibleWP && data.compatiblePHP && data.actions.activate ) { #> + + <# } #> <# } else { #> - + <# if ( data.compatibleWP && data.compatiblePHP ) { #> + + <# } else { #> + + <# } #> <# } #> <# } else { #> <# if ( data.compatibleWP && data.compatiblePHP ) { #> @@ -1149,7 +1185,7 @@ * * @since 5.2.0 * - * @global string $pagenow + * @global string $pagenow The filename of the current screen. */ function paused_themes_notice() { if ( 'themes.php' === $GLOBALS['pagenow'] ) {