mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Administration: For block themes, link to Site Editor interface instead of Customizer in Dashboard's welcome panel and Themes interface.
For block themes (like Twenty Twenty-Two), Customizer menu item is removed and replaced with the Site Editor menu item. However, other links exist in the Dashboard's welcome panel "Customize Your Site" button and the "Customize" button in each theme listed in the Appearance > Themes interface. This commit changes each of those remaining links to link to the Site Editor interface instead of the Customizer. To help identify block vs non-block themes, two method methods are introduced in `WP_Theme`: * `WP_Theme:: is_block_based()` which identifies if the theme is a block theme or not. * `WP_Theme::get_file_path()` which is similar to `get_theme_file_path()` but uses the directories within the theme object. Both of these new methods include test coverage including the addition of a parent and child block theme in test data. Follow-up to [18749], [35483], [42013], [42169]. Props antonvlasenko, jameskoster, hellofromTonya, matveb, noisysocks, poena, sergeybiryukov. Fixes #54460. Built from https://develop.svn.wordpress.org/trunk@52279 git-svn-id: http://core.svn.wordpress.org/trunk@51871 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9c9c576d88
commit
ce3aed3186
@ -1987,21 +1987,32 @@ function wp_dashboard_empty() {}
|
||||
* Displays a welcome panel to introduce users to WordPress.
|
||||
*
|
||||
* @since 3.3.0
|
||||
* @since 5.9.0 Send users to the Site Editor if the current theme is block-based.
|
||||
*/
|
||||
function wp_welcome_panel() {
|
||||
$customize_url = null;
|
||||
$can_edit_theme_options = current_user_can( 'edit_theme_options' );
|
||||
$can_customize = current_user_can( 'customize' );
|
||||
$is_block_based_theme = wp_is_block_template_theme();
|
||||
|
||||
if ( $is_block_based_theme && $can_edit_theme_options ) {
|
||||
$customize_url = esc_url( admin_url( 'site-editor.php' ) );
|
||||
} elseif ( ! $is_block_based_theme && $can_customize ) {
|
||||
$customize_url = wp_customize_url();
|
||||
}
|
||||
?>
|
||||
<div class="welcome-panel-content">
|
||||
<h2><?php _e( 'Welcome to WordPress!' ); ?></h2>
|
||||
<p class="about-description"><?php _e( 'We’ve assembled some links to get you started:' ); ?></p>
|
||||
<div class="welcome-panel-column-container">
|
||||
<div class="welcome-panel-column">
|
||||
<?php if ( current_user_can( 'customize' ) ) : ?>
|
||||
<?php if ( $customize_url ) : ?>
|
||||
<h3><?php _e( 'Get Started' ); ?></h3>
|
||||
<a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"><?php _e( 'Customize Your Site' ); ?></a>
|
||||
<a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo $customize_url; ?>"><?php _e( 'Customize Your Site' ); ?></a>
|
||||
<?php endif; ?>
|
||||
<a class="button button-primary button-hero hide-if-customize" href="<?php echo esc_url( admin_url( 'themes.php' ) ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
|
||||
<?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
|
||||
<?php $themes_link = current_user_can( 'customize' ) ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
|
||||
<?php $themes_link = $can_customize && ! $is_block_based_theme ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
|
||||
<p class="hide-if-no-customize">
|
||||
<?php
|
||||
/* translators: %s: URL to Themes panel in Customizer or Themes screen. */
|
||||
|
@ -701,7 +701,14 @@ function wp_prepare_themes_for_js( $themes = null ) {
|
||||
}
|
||||
|
||||
$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_based_theme = $theme->is_block_based();
|
||||
|
||||
if ( $is_block_based_theme && $can_edit_theme_options ) {
|
||||
$customize_action = esc_url( admin_url( 'site-editor.php' ) );
|
||||
} elseif ( ! $is_block_based_theme && $can_customize && $can_edit_theme_options ) {
|
||||
$customize_action = esc_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
|
@ -196,7 +196,7 @@ if ( $file_description !== $file_show ) {
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( preg_match( '/\.css$/', $file ) ) : ?>
|
||||
<?php if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_template_theme() && current_user_can( 'customize' ) ) : ?>
|
||||
<div id="message" class="notice-info notice">
|
||||
<p><strong><?php _e( 'Did you know?' ); ?></strong></p>
|
||||
<p>
|
||||
|
@ -1460,6 +1460,64 @@ final class WP_Theme implements ArrayAccess {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this theme is a block-based theme or not.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_block_based() {
|
||||
$paths_to_index_block_template = array(
|
||||
$this->get_file_path( '/block-templates/index.html' ),
|
||||
$this->get_file_path( '/templates/index.html' ),
|
||||
);
|
||||
|
||||
foreach ( $paths_to_index_block_template as $path_to_index_block_template ) {
|
||||
if ( is_file( $path_to_index_block_template ) && is_readable( $path_to_index_block_template ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the path of a file in the theme.
|
||||
*
|
||||
* Searches in the stylesheet directory before the template directory so themes
|
||||
* which inherit from a parent theme can just override one file.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param string $file Optional. File to search for in the stylesheet directory.
|
||||
* @return string The path of the file.
|
||||
*/
|
||||
public function get_file_path( $file = '' ) {
|
||||
$file = ltrim( $file, '/' );
|
||||
|
||||
$stylesheet_directory = $this->get_stylesheet_directory();
|
||||
$template_directory = $this->get_template_directory();
|
||||
|
||||
if ( empty( $file ) ) {
|
||||
$path = $stylesheet_directory;
|
||||
} elseif ( file_exists( $stylesheet_directory . '/' . $file ) ) {
|
||||
$path = $stylesheet_directory . '/' . $file;
|
||||
} else {
|
||||
$path = $template_directory . '/' . $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the path to a file in the theme.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param string $path The file path.
|
||||
* @param string $file The requested file to search for.
|
||||
*/
|
||||
return apply_filters( 'theme_file_path', $path, $file );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the latest WordPress default theme that is installed.
|
||||
*
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.9-alpha-52278';
|
||||
$wp_version = '5.9-alpha-52279';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user