block-patterns.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Stewart: Block Patterns
  4. *
  5. * @since Stewart 1.0
  6. */
  7. /**
  8. * Registers block patterns and categories.
  9. *
  10. * @since Stewart 1.0
  11. *
  12. * @return void
  13. */
  14. function stewart_register_block_patterns() {
  15. $block_pattern_categories = array(
  16. 'footer' => array( 'label' => __( 'Footers', 'stewart' ) ),
  17. 'header' => array( 'label' => __( 'Headers', 'stewart' ) ),
  18. 'pages' => array( 'label' => __( 'Pages', 'stewart' ) ),
  19. 'sidebar' => array( 'label' => __( 'Sidebars', 'stewart' ) ),
  20. );
  21. /**
  22. * Filters the theme block pattern categories.
  23. *
  24. * @since Stewart 1.0
  25. *
  26. * @param array[] $block_pattern_categories {
  27. * An associative array of block pattern categories, keyed by category name.
  28. *
  29. * @type array[] $properties {
  30. * An array of block category properties.
  31. *
  32. * @type string $label A human-readable label for the pattern category.
  33. * }
  34. * }
  35. */
  36. $block_pattern_categories = apply_filters( 'stewart_block_pattern_categories', $block_pattern_categories );
  37. foreach ( $block_pattern_categories as $name => $properties ) {
  38. if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) {
  39. register_block_pattern_category( $name, $properties );
  40. }
  41. }
  42. $block_patterns = array(
  43. 'footer-default',
  44. 'footer-left',
  45. 'footer-right',
  46. 'footer-nav-left',
  47. 'footer-nav-right',
  48. 'header-image',
  49. 'header-traditional-background',
  50. 'header-traditional',
  51. 'page-about',
  52. 'page-contact',
  53. 'sidebar-default',
  54. 'sidebar-border',
  55. 'sidebar-background',
  56. 'sidebar-introduction',
  57. 'sidebar-blogging',
  58. 'sidebar-categories-tags',
  59. );
  60. /**
  61. * Filters the theme block patterns.
  62. *
  63. * @since Stewart 1.0
  64. *
  65. * @param array $block_patterns List of block patterns by name.
  66. */
  67. $block_patterns = apply_filters( 'stewart_block_patterns', $block_patterns );
  68. foreach ( $block_patterns as $block_pattern ) {
  69. $pattern_file = get_theme_file_path( '/inc/patterns/' . $block_pattern . '.php' );
  70. register_block_pattern(
  71. 'stewart/' . $block_pattern,
  72. require $pattern_file
  73. );
  74. }
  75. }
  76. add_action( 'init', 'stewart_register_block_patterns', 9 );