block-patterns.php 2.0 KB

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