-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor: Fix routing for Classic themes using block-based templat…
…e parts (#48343) * Site Editor: Fix routing for Classic themes using block-based template parts * Add basic e2e tests * Update theme stylesheet name
- Loading branch information
Showing
8 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* Admin menu overrides for WP 6.2. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Updates "Template Parts" menu URL to include `path` query argument. | ||
* | ||
* Note: Remove when the minimum required WP version is 6.2. | ||
* No need to backport in core. Changes are applied in wp-admin/menu.php. | ||
*/ | ||
function gutenberg_update_template_parts_menu_url() { | ||
if ( wp_is_block_theme() ) { | ||
return; | ||
} | ||
|
||
if ( ! current_theme_supports( 'block-template-parts' ) ) { | ||
return; | ||
} | ||
|
||
global $submenu; | ||
if ( ! isset( $submenu['themes.php'] ) ) { | ||
return; | ||
} | ||
|
||
foreach ( $submenu['themes.php'] as $index => $menu_item ) { | ||
if ( str_contains( $menu_item[2], 'site-editor.php?postType=wp_template_part' ) && ! str_contains( $menu_item[2], 'path=' ) ) { | ||
$submenu['themes.php'][ $index ][2] = 'site-editor.php?postType=wp_template_part&path=/wp_template_part/all'; | ||
break; | ||
} | ||
} | ||
} | ||
add_action( 'admin_menu', 'gutenberg_update_template_parts_menu_url' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'Template Parts for Classic themes', () => { | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
await requestUtils.activateTheme( 'emptyhybrid' ); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.activateTheme( 'twentytwentyone' ); | ||
} ); | ||
|
||
test( 'can access template parts list page', async ( { admin, page } ) => { | ||
await admin.visitAdminPage( | ||
'site-editor.php', | ||
'postType=wp_template_part&path=/wp_template_part/all' | ||
); | ||
|
||
await expect( | ||
page.getByRole( 'table' ).getByRole( 'link', { name: 'header' } ) | ||
).toBeVisible(); | ||
} ); | ||
|
||
test( 'can view a template part', async ( { admin, editor, page } ) => { | ||
await admin.visitAdminPage( | ||
'site-editor.php', | ||
'postType=wp_template_part&path=/wp_template_part/all' | ||
); | ||
|
||
const templatePart = page | ||
.getByRole( 'table' ) | ||
.getByRole( 'link', { name: 'header' } ); | ||
|
||
await expect( templatePart ).toBeVisible(); | ||
await templatePart.click(); | ||
|
||
await expect( | ||
page.getByRole( 'region', { name: 'Editor content' } ) | ||
).toBeVisible(); | ||
|
||
await editor.canvas.click( 'body' ); | ||
|
||
await expect( | ||
editor.canvas.getByRole( 'document', { | ||
name: 'Block: Site Title', | ||
} ) | ||
).toBeVisible(); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
if ( ! function_exists( 'emptyhybrid_support' ) ) : | ||
function emptyhybrid_support() { | ||
|
||
// Adding support for core block visual styles. | ||
add_theme_support( 'wp-block-styles' ); | ||
|
||
// Enqueue editor styles. | ||
add_editor_style( 'style.css' ); | ||
|
||
// Enable block-based template parts support. | ||
add_theme_support( 'block-template-parts' ); | ||
} | ||
add_action( 'after_setup_theme', 'emptyhybrid_support' ); | ||
endif; | ||
|
||
/** | ||
* Enqueue scripts and styles. | ||
*/ | ||
function emptyhybrid_scripts() { | ||
// Enqueue theme stylesheet. | ||
wp_enqueue_style( 'emptyhybrid-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) ); | ||
} | ||
add_action( 'wp_enqueue_scripts', 'emptyhybrid_scripts' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!doctype html> | ||
<html <?php language_attributes(); ?>> | ||
<head> | ||
<meta charset="<?php bloginfo( 'charset' ); ?>" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<?php wp_head(); ?> | ||
</head> | ||
|
||
<body <?php body_class(); ?>> | ||
<?php wp_body_open(); ?> | ||
<div id="page" class="site"> | ||
<?php block_template_part( 'header' ); ?> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!-- wp:site-title /--> | ||
|
||
<!-- wp:site-tagline /--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
Theme Name: Emptyhybrid | ||
Theme URI: https://github.com/wordpress/gutenberg/ | ||
Author: the WordPress team | ||
Description: The testing hybrid theme. | ||
Requires at least: 6.0 | ||
Tested up to: 6.2 | ||
Requires PHP: 5.6 | ||
Version: 1.0 | ||
License: GNU General Public License v2 or later | ||
License URI: http://www.gnu.org/licenses/gpl-2.0.html | ||
Text Domain: Emptyhybrid | ||
Emptytheme WordPress Theme, (C) 2021 WordPress.org | ||
Emptytheme is distributed under the terms of the GNU GPL. | ||
*/ |