<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[52279] trunk: Administration: For block themes, link to Site Editor interface instead of Customizer in Dashboard's welcome panel and Themes interface.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/52279">52279</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/52279","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>hellofromTonya</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-11-30 14:25:34 +0000 (Tue, 30 Nov 2021)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/changeset/18749">[18749]</a>, <a href="https://core.trac.wordpress.org/changeset/35483">[35483]</a>, <a href="https://core.trac.wordpress.org/changeset/42013">[42013]</a>, <a href="https://core.trac.wordpress.org/changeset/42169">[42169]</a>.
Props antonvlasenko, jameskoster, hellofromTonya, matveb, noisysocks, poena, sergeybiryukov.
Fixes <a href="https://core.trac.wordpress.org/ticket/54460">#54460</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesdashboardphp">trunk/src/wp-admin/includes/dashboard.php</a></li>
<li><a href="#trunksrcwpadminincludesthemephp">trunk/src/wp-admin/includes/theme.php</a></li>
<li><a href="#trunksrcwpadminthemeeditorphp">trunk/src/wp-admin/theme-editor.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemephp">trunk/src/wp-includes/class-wp-theme.php</a></li>
<li><a href="#trunktestsphpunitteststhemethemeDirphp">trunk/tests/phpunit/tests/theme/themeDir.php</a></li>
<li><a href="#trunktestsphpunitteststhemewpThemephp">trunk/tests/phpunit/tests/theme/wpTheme.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>trunk/tests/phpunit/data/themedir1/test-block-child-theme/</li>
<li><a href="#trunktestsphpunitdatathemedir1testblockchildthemepagehomephp">trunk/tests/phpunit/data/themedir1/test-block-child-theme/page-home.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir1testblockchildthemestylecss">trunk/tests/phpunit/data/themedir1/test-block-child-theme/style.css</a></li>
<li>trunk/tests/phpunit/data/themedir1/test-block-child-theme/templates/</li>
<li><a href="#trunktestsphpunitdatathemedir1testblockchildthemetemplatespage1html">trunk/tests/phpunit/data/themedir1/test-block-child-theme/templates/page-1.html</a></li>
<li>trunk/tests/phpunit/data/themedir1/test-block-theme/</li>
<li><a href="#trunktestsphpunitdatathemedir1testblockthemeindexphp">trunk/tests/phpunit/data/themedir1/test-block-theme/index.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir1testblockthemepage1php">trunk/tests/phpunit/data/themedir1/test-block-theme/page-1.php</a></li>
<li><a href="#trunktestsphpunitdatathemedir1testblockthemestylecss">trunk/tests/phpunit/data/themedir1/test-block-theme/style.css</a></li>
<li>trunk/tests/phpunit/data/themedir1/test-block-theme/templates/</li>
<li><a href="#trunktestsphpunitdatathemedir1testblockthemetemplatesindexhtml">trunk/tests/phpunit/data/themedir1/test-block-theme/templates/index.html</a></li>
<li><a href="#trunktestsphpunitdatathemedir1testblockthemetemplatespagehomehtml">trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page-home.html</a></li>
<li><a href="#trunktestsphpunitdatathemedir1testblockthemetemplatespagehtml">trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesdashboardphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/dashboard.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/dashboard.php 2021-11-30 08:31:48 UTC (rev 52278)
+++ trunk/src/wp-admin/includes/dashboard.php 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1987,8 +1987,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Displays a welcome panel to introduce users to WordPress.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.3.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.9.0 Send users to the Site Editor if the current theme is block-based.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_welcome_panel() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $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();
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="welcome-panel-content">
</span><span class="cx" style="display: block; padding: 0 10px"> <h2><?php _e( 'Welcome to WordPress!' ); ?></h2>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1995,13 +2006,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <p class="about-description"><?php _e( 'We’ve assembled some links to get you started:' ); ?></p>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="welcome-panel-column-container">
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="welcome-panel-column">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php if ( current_user_can( 'customize' ) ) : ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php if ( $customize_url ) : ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <h3><?php _e( 'Get Started' ); ?></h3>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <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>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo $customize_url; ?>"><?php _e( 'Customize Your Site' ); ?></a>
</ins><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <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>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php $themes_link = current_user_can( 'customize' ) ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php $themes_link = $can_customize && ! $is_block_based_theme ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <p class="hide-if-no-customize">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> /* translators: %s: URL to Themes panel in Customizer or Themes screen. */
</span></span></pre></div>
<a id="trunksrcwpadminincludesthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/theme.php 2021-11-30 08:31:48 UTC (rev 52278)
+++ trunk/src/wp-admin/includes/theme.php 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -701,7 +701,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $customize_action = null;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $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 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $customize_action = esc_url(
</span><span class="cx" style="display: block; padding: 0 10px"> add_query_arg(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span></span></pre></div>
<a id="trunksrcwpadminthemeeditorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/theme-editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/theme-editor.php 2021-11-30 08:31:48 UTC (rev 52278)
+++ trunk/src/wp-admin/theme-editor.php 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -196,7 +196,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php if ( preg_match( '/\.css$/', $file ) ) : ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_template_theme() && current_user_can( 'customize' ) ) : ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <div id="message" class="notice-info notice">
</span><span class="cx" style="display: block; padding: 0 10px"> <p><strong><?php _e( 'Did you know?' ); ?></strong></p>
</span><span class="cx" style="display: block; padding: 0 10px"> <p>
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-theme.php 2021-11-30 08:31:48 UTC (rev 52278)
+++ trunk/src/wp-includes/class-wp-theme.php 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1461,6 +1461,64 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * 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 );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Determines the latest WordPress default theme that is installed.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * This hits the filesystem.
</span></span></pre></div>
<a id="trunktestsphpunitdatathemedir1testblockchildthemepagehomephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/test-block-child-theme/page-home.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/test-block-child-theme/page-home.php (rev 0)
+++ trunk/tests/phpunit/data/themedir1/test-block-child-theme/page-home.php 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,3 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+echo 'PHP template for page with slug "home"';
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/test-block-child-theme/page-home.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir1testblockchildthemestylecss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/test-block-child-theme/style.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/test-block-child-theme/style.css (rev 0)
+++ trunk/tests/phpunit/data/themedir1/test-block-child-theme/style.css 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,4 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/*
+Theme Name: Test Block Child Theme
+Template: test-block-theme
+*/
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/test-block-child-theme/style.css
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir1testblockchildthemetemplatespage1html"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/test-block-child-theme/templates/page-1.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/test-block-child-theme/templates/page-1.html (rev 0)
+++ trunk/tests/phpunit/data/themedir1/test-block-child-theme/templates/page-1.html 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,3 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<!-- wp:paragraph -->
+<p>Page (ID 1) Template</p>
+<!-- /wp:paragraph -->
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/test-block-child-theme/templates/page-1.html
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir1testblockthemeindexphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/test-block-theme/index.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/test-block-theme/index.php (rev 0)
+++ trunk/tests/phpunit/data/themedir1/test-block-theme/index.php 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,2 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+// This file is for test purposes only.
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/test-block-theme/index.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir1testblockthemepage1php"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/test-block-theme/page-1.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/test-block-theme/page-1.php (rev 0)
+++ trunk/tests/phpunit/data/themedir1/test-block-theme/page-1.php 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,3 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+echo 'PHP template for page with ID 1';
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/test-block-theme/page-1.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir1testblockthemestylecss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/test-block-theme/style.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/test-block-theme/style.css (rev 0)
+++ trunk/tests/phpunit/data/themedir1/test-block-theme/style.css 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,3 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/*
+Theme Name: Test Block Theme
+*/
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/test-block-theme/style.css
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir1testblockthemetemplatesindexhtml"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/test-block-theme/templates/index.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/test-block-theme/templates/index.html (rev 0)
+++ trunk/tests/phpunit/data/themedir1/test-block-theme/templates/index.html 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,3 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<!-- wp:paragraph -->
+<p>Index Template</p>
+<!-- /wp:paragraph -->
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/test-block-theme/templates/index.html
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir1testblockthemetemplatespagehomehtml"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page-home.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page-home.html (rev 0)
+++ trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page-home.html 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,3 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<!-- wp:paragraph -->
+<p>Page (Home) Template</p>
+<!-- /wp:paragraph -->
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page-home.html
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitdatathemedir1testblockthemetemplatespagehtml"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page.html (rev 0)
+++ trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page.html 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,3 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<!-- wp:paragraph -->
+<p>Page Template</p>
+<!-- /wp:paragraph -->
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/data/themedir1/test-block-theme/templates/page.html
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitteststhemethemeDirphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme/themeDir.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme/themeDir.php 2021-11-30 08:31:48 UTC (rev 52278)
+++ trunk/tests/phpunit/tests/theme/themeDir.php 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -163,6 +163,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'REST Theme',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Block Theme',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Block Theme Child Theme',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Test Block Theme',
+ 'Test Block Child Theme',
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> sort( $theme_names );
</span></span></pre></div>
<a id="trunktestsphpunitteststhemewpThemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme/wpTheme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme/wpTheme.php 2021-11-30 08:31:48 UTC (rev 52278)
+++ trunk/tests/phpunit/tests/theme/wpTheme.php 2021-11-30 14:25:34 UTC (rev 52279)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -246,4 +246,117 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSameSetsWithIndex( $allowed_themes, $new_allowed_themes );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @dataProvider data_is_block_based
+ * @ticket 54460
+ *
+ * @covers WP_Theme::is_block_based
+ *
+ * @param string $theme_dir Directory of the theme to test.
+ * @param bool $expected Expected result.
+ */
+ public function test_is_block_based( $theme_dir, $expected ) {
+ $theme = new WP_Theme( $theme_dir, $this->theme_root );
+ $actual = $theme->is_block_based();
+
+ if ( $expected ) {
+ $this->assertTrue( $actual );
+ } else {
+ $this->assertFalse( $actual );
+ }
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array
+ */
+ public function data_is_block_based() {
+ return array(
+ 'default - non-block theme' => array(
+ 'theme_dir' => 'default',
+ 'expected' => false,
+ ),
+ 'parent block theme' => array(
+ 'theme_dir' => 'test-block-theme',
+ 'expected' => true,
+ ),
+ 'child block theme' => array(
+ 'theme_dir' => 'test-block-child-theme',
+ 'expected' => true,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider data_get_file_path
+ * @ticket 54460
+ *
+ * @covers WP_Theme::get_file_path
+ *
+ * @param string $theme_dir Directory of the theme to test.
+ * @param string $file Given file name to test.
+ * @param string $expected Expected file path.
+ */
+ public function test_get_file_path( $theme_dir, $file, $expected ) {
+ $theme = new WP_Theme( $theme_dir, $this->theme_root );
+
+ $this->assertStringEndsWith( $expected, $theme->get_file_path( $file ) );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array
+ */
+ public function data_get_file_path() {
+ return array(
+ 'no theme: no file given' => array(
+ 'theme_dir' => 'nonexistent',
+ 'file' => '',
+ 'expected' => '/nonexistent',
+ ),
+ 'parent theme: no file given' => array(
+ 'theme_dir' => 'test-block-theme',
+ 'file' => '',
+ 'expected' => '/test-block-theme',
+ ),
+ 'child theme: no file given' => array(
+ 'theme_dir' => 'test-block-child-theme',
+ 'file' => '',
+ 'expected' => '/test-block-child-theme',
+ ),
+ 'nonexistent theme: file given' => array(
+ 'theme_dir' => 'nonexistent',
+ 'file' => '/templates/page.html',
+ 'expected' => '/nonexistent/templates/page.html',
+ ),
+ 'parent theme: file exists' => array(
+ 'theme_dir' => 'test-block-theme',
+ 'file' => '/templates/page-home.html',
+ 'expected' => '/test-block-theme/templates/page-home.html',
+ ),
+ 'parent theme: file does not exist' => array(
+ 'theme_dir' => 'test-block-theme',
+ 'file' => '/templates/nonexistent.html',
+ 'expected' => '/test-block-theme/templates/nonexistent.html',
+ ),
+ 'child theme: file exists' => array(
+ 'theme_dir' => 'test-block-child-theme',
+ 'file' => '/templates/page-1.html',
+ 'expected' => '/test-block-child-theme/templates/page-1.html',
+ ),
+ 'child theme: file does not exist' => array(
+ 'theme_dir' => 'test-block-child-theme',
+ 'file' => '/templates/nonexistent.html',
+ 'expected' => '/test-block-theme/templates/nonexistent.html',
+ ),
+ 'child theme: file exists in parent, not in child' => array(
+ 'theme_dir' => 'test-block-child-theme',
+ 'file' => '/templates/page.html',
+ 'expected' => '/test-block-theme/templates/page.html',
+ ),
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>