Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: Block theme previews #4627

Closed

Conversation

MaggieCabrera
Copy link

@MaggieCabrera MaggieCabrera commented Jun 16, 2023

Trac ticket: https://core.trac.wordpress.org/ticket/58561

This PR backports the changes made to the block theme previews. I grouped them together instead of having one PR for each change because they would all depend on each other, which made more sense.

Backports:


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

src/wp-admin/includes/theme-previews.php Outdated Show resolved Hide resolved
src/wp-admin/includes/theme-previews.php Outdated Show resolved Hide resolved
src/wp-admin/includes/theme-previews.php Outdated Show resolved Hide resolved
src/wp-admin/includes/theme-previews.php Outdated Show resolved Hide resolved
Copy link
Contributor

@audrasjb audrasjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments in this changeset :)

src/wp-admin/includes/theme-previews.php Show resolved Hide resolved
src/wp-admin/includes/theme-previews.php Show resolved Hide resolved
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaggieCabrera There are a few small but critical permission related bits to fix here, other than that this looks good.

Which Trac ticket is this PR for? Would be great if you could add it to the PR description to link the two.

src/wp-admin/themes.php Outdated Show resolved Hide resolved
src/wp-admin/includes/theme.php Outdated Show resolved Hide resolved
src/wp-admin/includes/theme.php Outdated Show resolved Hide resolved
@MaggieCabrera
Copy link
Author

@felixarntz @audrasjb would you please have another look?

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM! Can confirm that with this PR applied, a "live preview" button appears on block themes in /wp-admin/themes.php:

Screenshot 2023-06-23 at 2 09 56 pm

@peterwilsoncc
Copy link
Contributor

During testing, I'm seeing an error when the active theme is a classic theme

  1. Activate the theme Twenty Twenty-One (classic theme)
  2. Click live preview on a block theme: twenty twenty-two
  3. An error message is displayed: The theme you are currently using is not compatible with the Site Editor.

The reverse case is unaffected: it's still possible to preview a classic theme while a block theme is active.

classic-to-block

src/wp-admin/includes/theme-previews.php Outdated Show resolved Hide resolved
src/wp-admin/includes/theme-previews.php Outdated Show resolved Hide resolved
src/wp-admin/includes/theme-previews.php Outdated Show resolved Hide resolved
src/wp-admin/includes/theme-previews.php Outdated Show resolved Hide resolved
src/wp-admin/themes.php Outdated Show resolved Hide resolved
@tellthemachines
Copy link
Contributor

During testing, I'm seeing an error when the active theme is a classic theme

I suspect this is due to the npm packages not being updated yet in core. Can you confirm @MaggieCabrera ?

@MaggieCabrera
Copy link
Author

During testing, I'm seeing an error when the active theme is a classic theme

I suspect this is due to the npm packages not being updated yet in core. Can you confirm @MaggieCabrera ?

This is in fact not happening when testing that flow using Gutenberg trunk and core 6.2.2. I can't say of the top of my head what's causing it, I'm going to double-check, but most likely we are just missing the npm packages like you said.

$preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? $_GET['wp_theme_preview'] : null;
$wp_theme = wp_get_theme( $preview_stylesheet );
if ( ! is_wp_error( $wp_theme->errors() ) ) {
if ( current_filter() === 'template' ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happening here? Is this detecting if the theme has a parent? If so, I remember using $wp_theme->parent().

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this Johnny. This function (wp_get_theme_preview_path) is applied on two different filters - stylesheet and template. The return value of the function needs to be different depending on whether we are running on the stylesheet or template filter. The call to current_filter is determining which filter we are on so we know which value to return.

@scruffian
Copy link

During testing, I'm seeing an error when the active theme is a classic theme

I suspect this is due to the npm packages not being updated yet in core. Can you confirm @MaggieCabrera ?

This is not the reason why it was failing - we found the cause was an incorrect GET param on the button. Having said that we are still finding that the feature isn't working correctly on this branch because the npm packages aren't updated yet. I think we'll need to wait for this to be done before we can confirm that this is working as expected.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaggieCabrera This looks good to me now, though based on one of your comments we can probably make one improvement here so that customize isn't unnecessarily checked for block themes 👇

src/wp-admin/themes.php Outdated Show resolved Hide resolved
@peterwilsoncc
Copy link
Contributor

Thanks for the pointer, I tried running npm run sync-gutenberg-packages on this branch to see if I could test but without success. I'm going to leave it alone for the rest of the weekend and see if I have more success on Monday.

@tellthemachines
Copy link
Contributor

committed in r56059 / 1ef856c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

8 participants