admin管理员组

文章数量:1335624

I've registered a block pattern in my custom theme (using register_block_pattern) and it's not displaying in the block patterns list so I'm trying to debug whether I registered it properly.

How could I programmatically find currently registered block patterns?

I've registered a block pattern in my custom theme (using register_block_pattern) and it's not displaying in the block patterns list so I'm trying to debug whether I registered it properly.

How could I programmatically find currently registered block patterns?

Share Improve this question asked Jun 30, 2020 at 19:07 WillWill 7617 silver badges24 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

This looks like quite new functionality, the docs say 'experimental' and the first commit of this code to the WP repo was 6 days ago from date of this writing, so wouldn't be surprised if you'll have issues with what you're doing related to it being in development.

The class that manages block patterns is easy to read:

https://github/WordPress/WordPress/blob/6d927e494c160a04b641518009995f54212cd9f6/wp-includes/class-wp-block-patterns-registry.php

So you could call e.g. the get_all_registered() method like:

WP_Block_Patterns_Registry::get_instance()->get_all_registered()

or e.g. check if your pattern is registered:

WP_Block_Patterns_Registry::get_instance()->is_registered("your_pattern_name")

I'd suggest if you're having problems you might either want to wait until it's a more stable feature or contact the people working on it (e.g. you could start by contacting the person who made that commit as it looks like they're actively working on it)

HTH!

本文标签: How to view all currently registered block patterns