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

Back Compat: Add Patterns submenu for WordPress 6.4 #60804

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

t-hamano
Copy link
Contributor

Part of #52150
Related core changeset: https://core.trac.wordpress.org/changeset/57543

What?

This PR applies the following changes implemented in WP 6.5 (Changeset 57543) to WP 6.4 and below + Gutenberg plugin environments:

  • Add a Patterns submenu (wp-admin/edit.php?post_type=wp_block) under the Appearance menu for the Classic theme
  • Allow access to the Site Editor's Patterns page (wp-admin/site-editor.php?path=%2Fpatterns) internally for the Classic theme

Why?

A roadmap for publishing the new Patterns page to the classic theme is mentioned in this comment. We originally thought that we would not be able to publish the new Patterns page to the Classic theme until the minimum version supported by the Gutenberg plugin was WP 6.5. However, we found that by filtering wp_die() itself, it is possible to publish the new Pattern page internally even in environments with WP 6.4 or lower.

This should allow us to officially publish the new Patterns page for the Classic theme in the next major WordPress release (6.6) without worrying about backwards compatibility issues.

How?

I added two hooks to accomplish the same thing with this changeset.

Testing Instructions

  • Access the test environment (http://localhost:8889/wp-admin/).
  • Enable Twenty Twenty-One or Emptyhybrid themes. Emptyhybrid theme supports block template parts.
  • Make sure that there is a Patterns submenu under the Appearance menu, and that it links to the old Patterns page (wp-admin/edit.php?post_type=wp_block).
  • Make sure you can access the new Patterns page (http://localhost:8889/wp-admin/site-editor.php?path=%2Fpatterns) directly.
  • Reload the browser after navigating pages within the Site Editor. Access should never be denied.
  • Make sure that the following URLs cannot be accessed.
    • Design: http://localhost:8889/wp-admin/site-editor.php
    • Default edit view: http://localhost:8889/wp-admin/site-editor.php?canvas=edit
    • Navigation: http://localhost:8889/wp-admin/site-editor.php?path=%2Fnavigation
    • Styles: http://localhost:8889/wp-admin/site-editor.php?path=%2Fwp_global_styles
    • Pages: http://localhost:8889/wp-admin/site-editor.php?path=%2Fpage
    • Templates: http://localhost:8889/wp-admin/site-editor.php?path=%2Fwp_template

Next Step

This PR is purely to enable changes made in WP 6.5 to work in environments below WP 6.4. In order to expose the new Patterns page to the classic theme in WP 6.6, I would like to continue working on the following tasks:

  • Gutenberg plugin: Override the Appearance > Patterns submenu to link to the new Patterns page.
  • Gutenberg plugin: Point all "Manage all patterns" links to the new Patterns page
  • core: Link the Appearance > Patterns submenu to the new Patterns page.

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") labels Apr 17, 2024
@t-hamano t-hamano self-assigned this Apr 17, 2024
@t-hamano t-hamano marked this pull request as ready for review April 17, 2024 06:13
Copy link

github-actions bot commented Apr 17, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

I'm glad there's a way to make this happen sooner for classic themes. Nice work @t-hamano 🎉

It tests well for me:

✅ Block Themes are not affected
✅ Patterns menu appears under Appearance for classic and hybrid themes
✅ Patterns menu links to wp-admin/edit.php?post_type=wp_block
✅ Site Editor patterns page could be accessed directly
✅ Not denied access to site editor's pattern page when reloading, navigating back etc.
✅ Non-pattern pages in the site editor were not accessible

The code changes reflect the relevant code within core's site-editor.php as well as other existing approaches to adding menu items e.g. Widgets.

LGTM 🚢

@youknowriad
Copy link
Contributor

Nice one indeed :)

@t-hamano
Copy link
Contributor Author

Thanks for the review!

@t-hamano t-hamano merged commit 4e9f1c3 into trunk Apr 18, 2024
72 of 73 checks passed
@t-hamano t-hamano deleted the compat/add-pattans-page-for-classic-themes branch April 18, 2024 15:30
@github-actions github-actions bot added this to the Gutenberg 18.2 milestone Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants