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

Feature: remove blocks by page template #957

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

defunctl
Copy link
Collaborator

What does this do/fix?

  • Allows developers to specify blocks that will only be selectable when certain WordPress page templates have been selected.

QA

Using this as a test example in the definer:

			Block_Page_Template_Filter::class => DI\autowire()
				->constructor( [
					 'page-templates/page-example-app.php' => [
						 Content_Loop::NAME,
					 ],
				] ),

Default template, Content Loop is not available:

image

Change to the Example React App Template and the block becomes available in real time:

image

Note: Once the block is on there, this doesn't handle removing it or antyhing.

Tests

Does this have tests?

  • Yes
  • No, this doesn't need tests because...
  • No, I need help figuring out how to write the tests.

Copy link
Contributor

@ChrisMKindred ChrisMKindred left a comment

Choose a reason for hiding this comment

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

This looks good and will be great to have. I just have one question and maybe I am missing it in the JS...
What would happen if you were to enter a block then change the template when that original block was one listed in the block_page_template_filter for the new template selected?

@defunctl
Copy link
Collaborator Author

This looks good and will be great to have. I just have one question and maybe I am missing it in the JS... What would happen if you were to enter a block then change the template when that original block was one listed in the block_page_template_filter for the new template selected?

Thanks for pointing this out, I had a note in the PR that it didn't do anything once the block is there, but it actually crashes Gutenberg if you switch templates if a filtered block is on the page.

Any suggestions on how we should best handle this for a user experience perspective? I think finding a way to warn them that they'll lose their blocks or something like that if they try to switch templates after they have filtered blocks on the page might be decent, allowing them to cancel that action.

@ChrisMKindred
Copy link
Contributor

Any suggestions on how we should best handle this for a user experience perspective? I think finding a way to warn them that they'll lose their blocks or something like that if they try to switch templates after they have filtered blocks on the page might be decent, allowing them to cancel that action.

I think a warning message with a cancel/continue option would be great. Then remove the block from the content if they continue.

@defunctl
Copy link
Collaborator Author

We are going to update this in our project first, @ScottGarrison is going to have a look :)

@defunctl defunctl marked this pull request as draft March 22, 2022 20:04
@dpellenwood dpellenwood removed their request for review September 13, 2023 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants