block-patterns.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. 'small-quote',
  47. 'hidden-404-content',
  48. 'hidden-search-form',
  49. 'image-with-text',
  50. 'posts-grid',
  51. 'posts-list',
  52. 'subscribe',
  53. 'tags',
  54. 'categories',
  55. );
  56. /**
  57. * Filters the theme block patterns.
  58. *
  59. * @since remote 1.0
  60. *
  61. * @param array $block_patterns List of block patterns by name.
  62. */
  63. $block_patterns = apply_filters( 'remote_block_patterns', $block_patterns );
  64. foreach ( $block_patterns as $block_pattern ) {
  65. $pattern_file = get_theme_file_path( '/inc/patterns/' . $block_pattern . '.php' );
  66. register_block_pattern(
  67. 'remote/' . $block_pattern,
  68. require $pattern_file
  69. );
  70. }
  71. }
  72. add_action( 'init', 'remote_register_block_patterns', 9 );