| @@ -24,13 +24,17 @@ | ||
| 24 | 24 | * Set categories and patterns. |
| 25 | 25 | */ |
| 26 | 26 | public function __construct() { |
| 27 | 27 | $this->categories = [ |
| 28 | - 'surecart_form' => [ 'label' => __( 'Checkout Form', 'surecart' ) ], | |
| 28 | + 'surecart_form' => [ 'label' => __( 'Checkout Form', 'surecart' ) ], | |
| 29 | + 'surecart_shop' => [ 'label' => __( 'Shop', 'surecart' ) ], | |
| 30 | + 'surecart_product_page' => [ 'label' => __( 'Product Page', 'surecart' ) ], | |
| 31 | + 'surecart_related_products' => [ 'label' => __( 'Related Products', 'surecart' ) ], | |
| 29 | 32 | ]; |
| 30 | 33 | |
| 31 | 34 | $this->patterns = [ |
| 32 | 35 | 'default', |
| 36 | + 'full-page', | |
| 33 | 37 | 'simple', |
| 34 | 38 | 'sections', |
| 35 | 39 | 'two-column', |
| 36 | 40 | 'donation', |
| @@ -50,9 +54,9 @@ | ||
| 50 | 54 | /** |
| 51 | 55 | * Register block patterns and |
| 52 | 56 | */ |
| 53 | 57 | public function registerPatternsAndCategories() { |
| 54 | - // $this->registerCategories(); | |
| 58 | + $this->registerCategories(); | |
| 55 | 59 | $this->registerPatterns(); |
| 56 | 60 | } |
| 57 | 61 | |
| 58 | 62 | /** |
| @@ -88,8 +92,28 @@ | ||
| 88 | 92 | * |
| 89 | 93 | * @return void |
| 90 | 94 | */ |
| 91 | 95 | public function registerPatterns() { |
| 96 | + // register the block patterns from patterns directory. | |
| 97 | + $patterns = glob( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'templates/patterns/*.php' ); | |
| 98 | + | |
| 99 | + // sort by priority key. | |
| 100 | + usort( | |
| 101 | + $patterns, | |
| 102 | + function ( $a, $b ) { | |
| 103 | + $a = require $a; | |
| 104 | + $b = require $b; | |
| 105 | + return ( $a['priority'] ?? 0 ) <=> ( $b['priority'] ?? 0 ); | |
| 106 | + } | |
| 107 | + ); | |
| 108 | + | |
| 109 | + foreach ( $patterns as $pattern_file ) { | |
| 110 | + register_block_pattern( | |
| 111 | + 'surecart-' . basename( $pattern_file, '.php' ), | |
| 112 | + require $pattern_file | |
| 113 | + ); | |
| 114 | + } | |
| 115 | + | |
| 92 | 116 | /** |
| 93 | 117 | * Filters the plugin block patterns. |
| 94 | 118 | * |
| 95 | 119 | * @param array $patterns List of block patterns by name. |