block-patterns.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. //Needed until https://github.com/WordPress/gutenberg/issues/39500 is fixed.
  16. $block_pattern_categories = array(
  17. 'featured' => array( 'label' => __( 'Featured', 'remote' ) ),
  18. 'columns' => array( 'label' => __( 'Columns', 'remote' ) ),
  19. 'text' => array( 'label' => __( 'Text', 'remote' ) ),
  20. 'query' => array( 'label' => __( 'Query', 'remote' ) ),
  21. );
  22. /**
  23. * Filters the theme block pattern categories.
  24. *
  25. * @since remote 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( 'remote_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. 'hero-text',
  45. 'large-quote',
  46. 'hidden-404-content',
  47. 'hidden-search-form',
  48. 'image-with-text',
  49. 'posts-grid',
  50. 'posts-list',
  51. 'subscribe',
  52. 'tags',
  53. 'categories',
  54. );
  55. /**
  56. * Filters the theme block patterns.
  57. *
  58. * @since remote 1.0
  59. *
  60. * @param array $block_patterns List of block patterns by name.
  61. */
  62. $block_patterns = apply_filters( 'remote_block_patterns', $block_patterns );
  63. foreach ( $block_patterns as $block_pattern ) {
  64. $pattern_file = get_theme_file_path( '/inc/patterns/' . $block_pattern . '.php' );
  65. register_block_pattern(
  66. 'remote/' . $block_pattern,
  67. require $pattern_file
  68. );
  69. }
  70. }
  71. add_action( 'init', 'remote_register_block_patterns', 9 );