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

Accept array of block names in registerBlockStyle #50256

Open
cbirdsong opened this issue May 2, 2023 · 1 comment
Open

Accept array of block names in registerBlockStyle #50256

cbirdsong opened this issue May 2, 2023 · 1 comment
Labels
Developer Experience Ideas about improving block and theme developer experience [Feature] Block API API that allows to express the block paradigm. [Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks [Type] Enhancement A suggestion for improvement.

Comments

@cbirdsong
Copy link

What problem does this address?

When registering block styles using wp.blocks.registerBlockStyle, I often want to add the same block style to multiple similar blocks that might need to have the same appearance, and I end up doing something like this:

var heading_blocks = ["core/heading", "core/paragraph", "core/post-title"]; // depending on the site this might also include comments title, search title, etc
heading_blocks.forEach((block) => {
  wp.blocks.registerBlockStyle(block, [
    {
      name: "subhead",
      label: "Subhead",
    },
    {
      name: "lead",
      label: "Lead",
    }
  ]);
});

var container_blocks = ["core/group", "core/column", "core/quote"];
container_blocks.forEach((block) => {
  wp.blocks.registerBlockStyle(block, [
    {
      name: "bordered-shadowed",
      label: "Bordered / Shadowed",
    }
  ]);
});

This is obviously easy enough, but it makes switching from registering a single block style to multiple block styles slightly awkward.

What is your proposed solution?

Accept either a single block name or an array of block names when calling wp.blocks.registerBlockStyle.

@ndiego ndiego added the [Type] Enhancement A suggestion for improvement. label May 2, 2023
@gziolo gziolo added [Feature] Block API API that allows to express the block paradigm. Developer Experience Ideas about improving block and theme developer experience labels May 3, 2023
@Mamaduka
Copy link
Member

Mamaduka commented May 3, 2023

I've seen similar requests for the core registration methods in the past, and the argument against them always was that they're easy to implement on the project level.

@fabiankaegy fabiankaegy added the [Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks label Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Ideas about improving block and theme developer experience [Feature] Block API API that allows to express the block paradigm. [Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks [Type] Enhancement A suggestion for improvement.
5 participants