Automattic\WooCommerce\Blocks
BlockPatterns::register_block_patterns
Register block patterns from core.
The pattern content is not loaded here. Instead, each pattern is registered with the absolute path to its source file (via the filePath property), so that core's WP_Block_Patterns_Registry loads (and caches) the content lazily, only when a pattern is actually requested. This avoids the cost of include-ing all pattern files on every request (e.g. front-end, REST, cron), where patterns are never consumed.
Метод класса: BlockPatterns{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$BlockPatterns = new BlockPatterns(); $BlockPatterns->register_block_patterns();
Код BlockPatterns::register_block_patterns() BlockPatterns::register block patterns WC 11.0.0
public function register_block_patterns() {
if ( ! class_exists( 'WP_Block_Patterns_Registry' ) ) {
return;
}
$patterns = $this->get_block_patterns();
foreach ( $patterns as $pattern ) {
// The pattern list can come from a stale or malformed site transient, so make sure the source is a
// usable string before dereferencing it, to avoid a PHP warning when building the path.
if ( empty( $pattern['source'] ) || ! is_string( $pattern['source'] ) ) {
continue;
}
$pattern_path = $this->patterns_path . '/' . $pattern['source'];
// The pattern list can come from a stale cache, so confirm the file
// still exists before registering it with a `filePath`. Without
// inline content, core would otherwise emit an undefined-content
// warning when it tries to load a missing file on demand. This
// mirrors core's own `_register_theme_block_patterns()` guard.
if ( ! file_exists( $pattern_path ) ) {
continue;
}
$pattern['source'] = $pattern_path;
$pattern['filePath'] = $pattern_path;
$this->pattern_registry->register_block_pattern( $pattern_path, $pattern );
}
}