block-patterns.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * remote: Block Patterns
  4. *
  5. * @since remote 1.0
  6. */
  7. /**
  8. * Registers block patterns and categories.
  9. *
  10. * @since remote 1.0
  11. *
  12. * @return void
  13. */
  14. function remote_register_block_patterns() {
  15. $block_pattern_categories = array(
  16. 'pages' => array( 'label' => __( 'Pages', 'remote' ) ),
  17. );
  18. /**
  19. * Filters the theme block pattern categories.
  20. *
  21. * @since remote 1.0
  22. *
  23. * @param array[] $block_pattern_categories {
  24. * An associative array of block pattern categories, keyed by category name.
  25. *
  26. * @type array[] $properties {
  27. * An array of block category properties.
  28. *
  29. * @type string $label A human-readable label for the pattern category.
  30. * }
  31. * }
  32. */
  33. $block_pattern_categories = apply_filters( 'remote_block_pattern_categories', $block_pattern_categories );
  34. foreach ( $block_pattern_categories as $name => $properties ) {
  35. if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) {
  36. register_block_pattern_category( $name, $properties );
  37. }
  38. }
  39. $block_patterns = array(
  40. 'hero-text',
  41. 'posts-list',
  42. 'hidden-search-form',
  43. );
  44. /**
  45. * Filters the theme block patterns.
  46. *
  47. * @since remote 1.0
  48. *
  49. * @param array $block_patterns List of block patterns by name.
  50. */
  51. $block_patterns = apply_filters( 'remote_block_patterns', $block_patterns );
  52. foreach ( $block_patterns as $block_pattern ) {
  53. $pattern_file = get_theme_file_path( '/inc/patterns/' . $block_pattern . '.php' );
  54. register_block_pattern(
  55. 'remote/' . $block_pattern,
  56. require $pattern_file
  57. );
  58. }
  59. }
  60. add_action( 'init', 'remote_register_block_patterns', 9 );