Make WordPress Core


Ignore:
Timestamp:
11/30/2021 02:25:34 PM (4 years ago)
Author:
hellofromTonya
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme.php

    r52204 r52279  
    14621462
    14631463    /**
     1464     * Returns whether this theme is a block-based theme or not.
     1465     *
     1466     * @since 5.9.0
     1467     *
     1468     * @return bool
     1469     */
     1470    public function is_block_based() {
     1471        $paths_to_index_block_template = array(
     1472            $this->get_file_path( '/block-templates/index.html' ),
     1473            $this->get_file_path( '/templates/index.html' ),
     1474        );
     1475
     1476        foreach ( $paths_to_index_block_template as $path_to_index_block_template ) {
     1477            if ( is_file( $path_to_index_block_template ) && is_readable( $path_to_index_block_template ) ) {
     1478                return true;
     1479            }
     1480        }
     1481
     1482        return false;
     1483    }
     1484
     1485    /**
     1486     * Retrieves the path of a file in the theme.
     1487     *
     1488     * Searches in the stylesheet directory before the template directory so themes
     1489     * which inherit from a parent theme can just override one file.
     1490     *
     1491     * @since 5.9.0
     1492     *
     1493     * @param string $file Optional. File to search for in the stylesheet directory.
     1494     * @return string The path of the file.
     1495     */
     1496    public function get_file_path( $file = '' ) {
     1497        $file = ltrim( $file, '/' );
     1498
     1499        $stylesheet_directory = $this->get_stylesheet_directory();
     1500        $template_directory   = $this->get_template_directory();
     1501
     1502        if ( empty( $file ) ) {
     1503            $path = $stylesheet_directory;
     1504        } elseif ( file_exists( $stylesheet_directory . '/' . $file ) ) {
     1505            $path = $stylesheet_directory . '/' . $file;
     1506        } else {
     1507            $path = $template_directory . '/' . $file;
     1508        }
     1509
     1510        /**
     1511         * Filters the path to a file in the theme.
     1512         *
     1513         * @since 5.9.0
     1514         *
     1515         * @param string $path The file path.
     1516         * @param string $file The requested file to search for.
     1517         */
     1518        return apply_filters( 'theme_file_path', $path, $file );
     1519    }
     1520
     1521    /**
    14641522     * Determines the latest WordPress default theme that is installed.
    14651523     *
Note: See TracChangeset for help on using the changeset viewer.