BlockManager.php
1 month ago
EmbedPressBlockRenderer.php
1 month ago
FallbackHandler.php
9 months ago
InitBlocks.php
9 months ago
InitBlocks.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * EmbedPress Blocks Initialization |
| 5 | * |
| 6 | * This file initializes the new EmbedPress block system |
| 7 | * using the centralized structure in the src/Blocks directory. |
| 8 | */ |
| 9 | |
| 10 | // Exit if accessed directly |
| 11 | if (!defined('ABSPATH')) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | use EmbedPress\Gutenberg\BlockManager; |
| 16 | |
| 17 | |
| 18 | /** |
| 19 | * Initialize the block manager |
| 20 | */ |
| 21 | function embedpress_init_blocks() { |
| 22 | // Only initialize if we have the required WordPress functions |
| 23 | if (!function_exists('register_block_type')) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | // Initialize the block manager instance |
| 28 | BlockManager::get_instance(); |
| 29 | |
| 30 | // Register block category if it doesn't exist |
| 31 | // add_filter('block_categories_all', 'embedpress_register_block_category', 10, 2); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Register EmbedPress block category |
| 36 | */ |
| 37 | function embedpress_register_block_category($categories, $post = null) { |
| 38 | // Check if category already exists |
| 39 | foreach ($categories as $category) { |
| 40 | if ($category['slug'] === 'embedpress') { |
| 41 | return $categories; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Check if we should use the block system |
| 48 | */ |
| 49 | function embedpress_should_use_blocks() { |
| 50 | // For now, we'll use a filter to allow enabling/disabling the block system |
| 51 | return apply_filters('embedpress_use_new_block_system', true); |
| 52 | } |
| 53 | |
| 54 | // Initialize the block system |
| 55 | if (embedpress_should_use_blocks()) { |
| 56 | add_action('init', 'embedpress_init_blocks', 5); |
| 57 | } |
| 58 |