Changeset 52279
- Timestamp:
- 11/30/2021 02:25:34 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 13 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/dashboard.php
r52204 r52279 1988 1988 * 1989 1989 * @since 3.3.0 1990 * @since 5.9.0 Send users to the Site Editor if the current theme is block-based. 1990 1991 */ 1991 1992 function wp_welcome_panel() { 1993 $customize_url = null; 1994 $can_edit_theme_options = current_user_can( 'edit_theme_options' ); 1995 $can_customize = current_user_can( 'customize' ); 1996 $is_block_based_theme = wp_is_block_template_theme(); 1997 1998 if ( $is_block_based_theme && $can_edit_theme_options ) { 1999 $customize_url = esc_url( admin_url( 'site-editor.php' ) ); 2000 } elseif ( ! $is_block_based_theme && $can_customize ) { 2001 $customize_url = wp_customize_url(); 2002 } 1992 2003 ?> 1993 2004 <div class="welcome-panel-content"> … … 1996 2007 <div class="welcome-panel-column-container"> 1997 2008 <div class="welcome-panel-column"> 1998 <?php if ( current_user_can( 'customize' )) : ?>2009 <?php if ( $customize_url ) : ?> 1999 2010 <h3><?php _e( 'Get Started' ); ?></h3> 2000 <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>2011 <a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo $customize_url; ?>"><?php _e( 'Customize Your Site' ); ?></a> 2001 2012 <?php endif; ?> 2002 2013 <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> 2003 2014 <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?> 2004 <?php $themes_link = current_user_can( 'customize' )? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>2015 <?php $themes_link = $can_customize && ! $is_block_based_theme ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?> 2005 2016 <p class="hide-if-no-customize"> 2006 2017 <?php -
trunk/src/wp-admin/includes/theme.php
r52204 r52279 702 702 703 703 $customize_action = null; 704 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { 704 705 $can_edit_theme_options = current_user_can( 'edit_theme_options' ); 706 $can_customize = current_user_can( 'customize' ); 707 $is_block_based_theme = $theme->is_block_based(); 708 709 if ( $is_block_based_theme && $can_edit_theme_options ) { 710 $customize_action = esc_url( admin_url( 'site-editor.php' ) ); 711 } elseif ( ! $is_block_based_theme && $can_customize && $can_edit_theme_options ) { 705 712 $customize_action = esc_url( 706 713 add_query_arg( -
trunk/src/wp-admin/theme-editor.php
r52053 r52279 197 197 <?php endif; ?> 198 198 199 <?php if ( preg_match( '/\.css$/', $file ) ) : ?>199 <?php if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_template_theme() && current_user_can( 'customize' ) ) : ?> 200 200 <div id="message" class="notice-info notice"> 201 201 <p><strong><?php _e( 'Did you know?' ); ?></strong></p> -
trunk/src/wp-includes/class-wp-theme.php
r52204 r52279 1462 1462 1463 1463 /** 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 /** 1464 1522 * Determines the latest WordPress default theme that is installed. 1465 1523 * -
trunk/tests/phpunit/tests/theme/themeDir.php
r52049 r52279 164 164 'Block Theme', 165 165 'Block Theme Child Theme', 166 'Test Block Theme', 167 'Test Block Child Theme', 166 168 ); 167 169 -
trunk/tests/phpunit/tests/theme/wpTheme.php
r51568 r52279 247 247 $this->assertSameSetsWithIndex( $allowed_themes, $new_allowed_themes ); 248 248 } 249 250 /** 251 * @dataProvider data_is_block_based 252 * @ticket 54460 253 * 254 * @covers WP_Theme::is_block_based 255 * 256 * @param string $theme_dir Directory of the theme to test. 257 * @param bool $expected Expected result. 258 */ 259 public function test_is_block_based( $theme_dir, $expected ) { 260 $theme = new WP_Theme( $theme_dir, $this->theme_root ); 261 $actual = $theme->is_block_based(); 262 263 if ( $expected ) { 264 $this->assertTrue( $actual ); 265 } else { 266 $this->assertFalse( $actual ); 267 } 268 } 269 270 /** 271 * Data provider. 272 * 273 * @return array 274 */ 275 public function data_is_block_based() { 276 return array( 277 'default - non-block theme' => array( 278 'theme_dir' => 'default', 279 'expected' => false, 280 ), 281 'parent block theme' => array( 282 'theme_dir' => 'test-block-theme', 283 'expected' => true, 284 ), 285 'child block theme' => array( 286 'theme_dir' => 'test-block-child-theme', 287 'expected' => true, 288 ), 289 ); 290 } 291 292 /** 293 * @dataProvider data_get_file_path 294 * @ticket 54460 295 * 296 * @covers WP_Theme::get_file_path 297 * 298 * @param string $theme_dir Directory of the theme to test. 299 * @param string $file Given file name to test. 300 * @param string $expected Expected file path. 301 */ 302 public function test_get_file_path( $theme_dir, $file, $expected ) { 303 $theme = new WP_Theme( $theme_dir, $this->theme_root ); 304 305 $this->assertStringEndsWith( $expected, $theme->get_file_path( $file ) ); 306 } 307 308 /** 309 * Data provider. 310 * 311 * @return array 312 */ 313 public function data_get_file_path() { 314 return array( 315 'no theme: no file given' => array( 316 'theme_dir' => 'nonexistent', 317 'file' => '', 318 'expected' => '/nonexistent', 319 ), 320 'parent theme: no file given' => array( 321 'theme_dir' => 'test-block-theme', 322 'file' => '', 323 'expected' => '/test-block-theme', 324 ), 325 'child theme: no file given' => array( 326 'theme_dir' => 'test-block-child-theme', 327 'file' => '', 328 'expected' => '/test-block-child-theme', 329 ), 330 'nonexistent theme: file given' => array( 331 'theme_dir' => 'nonexistent', 332 'file' => '/templates/page.html', 333 'expected' => '/nonexistent/templates/page.html', 334 ), 335 'parent theme: file exists' => array( 336 'theme_dir' => 'test-block-theme', 337 'file' => '/templates/page-home.html', 338 'expected' => '/test-block-theme/templates/page-home.html', 339 ), 340 'parent theme: file does not exist' => array( 341 'theme_dir' => 'test-block-theme', 342 'file' => '/templates/nonexistent.html', 343 'expected' => '/test-block-theme/templates/nonexistent.html', 344 ), 345 'child theme: file exists' => array( 346 'theme_dir' => 'test-block-child-theme', 347 'file' => '/templates/page-1.html', 348 'expected' => '/test-block-child-theme/templates/page-1.html', 349 ), 350 'child theme: file does not exist' => array( 351 'theme_dir' => 'test-block-child-theme', 352 'file' => '/templates/nonexistent.html', 353 'expected' => '/test-block-theme/templates/nonexistent.html', 354 ), 355 'child theme: file exists in parent, not in child' => array( 356 'theme_dir' => 'test-block-child-theme', 357 'file' => '/templates/page.html', 358 'expected' => '/test-block-theme/templates/page.html', 359 ), 360 ); 361 } 249 362 }
Note: See TracChangeset
for help on using the changeset viewer.