block-patterns.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. 'query' => array( 'label' => __( 'Query', 'stewart' ) ),
  21. );
  22. /**
  23. * Filters the theme block pattern categories.
  24. *
  25. * @since Stewart 1.0
  26. *
  27. * @param array[] $block_pattern_categories {
  28. * An associative array of block pattern categories, keyed by category name.
  29. *
  30. * @type array[] $properties {
  31. * An array of block category properties.
  32. *
  33. * @type string $label A human-readable label for the pattern category.
  34. * }
  35. * }
  36. */
  37. $block_pattern_categories = apply_filters( 'stewart_block_pattern_categories', $block_pattern_categories );
  38. foreach ( $block_pattern_categories as $name => $properties ) {
  39. if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) {
  40. register_block_pattern_category( $name, $properties );
  41. }
  42. }
  43. $block_patterns = array(
  44. 'footer-default',
  45. 'footer-left',
  46. 'footer-right',
  47. 'footer-nav-left',
  48. 'footer-nav-right',
  49. 'header-image',
  50. 'header-traditional-background',
  51. 'header-traditional',
  52. 'page-about',
  53. 'page-contact',
  54. 'sidebar-default',
  55. 'sidebar-border',
  56. 'sidebar-background',
  57. 'sidebar-introduction',
  58. 'sidebar-blogging',
  59. 'sidebar-categories-tags',
  60. 'posts-list',
  61. );
  62. /**
  63. * Filters the theme block patterns.
  64. *
  65. * @since Stewart 1.0
  66. *
  67. * @param array $block_patterns List of block patterns by name.
  68. */
  69. $block_patterns = apply_filters( 'stewart_block_patterns', $block_patterns );
  70. foreach ( $block_patterns as $block_pattern ) {
  71. $pattern_file = get_theme_file_path( '/inc/patterns/' . $block_pattern . '.php' );
  72. register_block_pattern(
  73. 'stewart/' . $block_pattern,
  74. require $pattern_file
  75. );
  76. }
  77. }
  78. add_action( 'init', 'stewart_register_block_patterns', 9 );