| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.13 Free | |
| 4 | + * @version 2.1.39 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2022 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2025 FirePlugins All Rights Reserved | |
| 9 | 9 | * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | namespace FireBox\Core; |
| @@ -24,12 +24,20 @@ | ||
| 24 | 24 | { |
| 25 | 25 | return; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - add_action('enqueue_block_editor_assets', [$this, 'blocks_assets']); | |
| 28 | + add_action('enqueue_block_assets', [$this, 'blocks_assets']); | |
| 29 | 29 | |
| 30 | 30 | // Register categories |
| 31 | - add_filter('block_categories_all', [$this, 'register_categories'], 10, 2); | |
| 31 | + global $wp_version; | |
| 32 | + if (version_compare($wp_version, '5.8', '>=')) | |
| 33 | + { | |
| 34 | + add_action('block_categories_all', [$this, 'register_categories'], 10, 2); | |
| 35 | + } | |
| 36 | + else | |
| 37 | + { | |
| 38 | + add_action('block_categories', [$this, 'register_categories'], 10, 2); | |
| 39 | + } | |
| 32 | 40 | |
| 33 | 41 | $this->register_blocks(); |
| 34 | 42 | } |
| 35 | 43 | |
| @@ -43,31 +51,17 @@ | ||
| 43 | 51 | * @return array |
| 44 | 52 | */ |
| 45 | 53 | public function register_categories($categories, $context) |
| 46 | 54 | { |
| 47 | - // Add FireBox category | |
| 48 | - $categories = array_merge( | |
| 55 | + return array_merge( | |
| 49 | 56 | $categories, |
| 50 | - array( | |
| 51 | - array( | |
| 52 | - 'slug' => 'firebox', | |
| 53 | - 'title' => firebox()->_('FB_PLUGIN_NAME') | |
| 54 | - ), | |
| 55 | - ) | |
| 57 | + [ | |
| 58 | + [ | |
| 59 | + 'slug' => 'firebox', | |
| 60 | + 'title' => 'FireBox' | |
| 61 | + ] | |
| 62 | + ] | |
| 56 | 63 | ); |
| 57 | - | |
| 58 | - // Add FirePlugins category | |
| 59 | - $categories = array_merge( | |
| 60 | - $categories, | |
| 61 | - array( | |
| 62 | - array( | |
| 63 | - 'slug' => 'fireplugins', | |
| 64 | - 'title' => fpframework()->_('FPF_NAME') | |
| 65 | - ), | |
| 66 | - ) | |
| 67 | - ); | |
| 68 | - | |
| 69 | - return $categories; | |
| 70 | 64 | } |
| 71 | 65 | |
| 72 | 66 | /** |
| 73 | 67 | * Initialize all blocks |
| @@ -79,9 +73,9 @@ | ||
| 79 | 73 | $ds = DIRECTORY_SEPARATOR; |
| 80 | 74 | |
| 81 | 75 | $base_dir = implode($ds, [__DIR__, 'Blocks']); |
| 82 | 76 | |
| 83 | - $files = array_diff(scandir($base_dir), ['.', '..', 'index.php', 'Block.php']); | |
| 77 | + $files = array_diff(scandir($base_dir), ['.', '..', '.DS_Store', 'index.php', 'Block.php']); | |
| 84 | 78 | |
| 85 | 79 | $namespace = '\FireBox\Core\Blocks\\'; |
| 86 | 80 | |
| 87 | 81 | foreach ($files as $item) |
| @@ -87,39 +81,24 @@ | ||
| 87 | 81 | foreach ($files as $item) |
| 88 | 82 | { |
| 89 | 83 | // Check if this is a single file and load it |
| 90 | 84 | $file = implode($ds, [$base_dir, $item]); |
| 91 | - if (is_file($file)) | |
| 85 | + | |
| 86 | + if (!is_file($file)) | |
| 92 | 87 | { |
| 93 | - $this->registerBlock($namespace . rtrim($item, '.php')); | |
| 94 | - continue; | |
| 95 | - } | |
| 96 | - | |
| 97 | - // If that's not a file, we assume it is a directory of files | |
| 98 | - $blocks = array_diff(scandir($file), ['.', '..', 'index.php']); | |
| 88 | + continue; | |
| 89 | + } | |
| 99 | 90 | |
| 100 | - foreach ($blocks as $key => $block_name) | |
| 101 | - { | |
| 102 | - $class = $namespace . $item . '\\' . rtrim($block_name, '.php'); | |
| 103 | - $this->registerBlock($class); | |
| 104 | - } | |
| 91 | + $class_name = preg_replace('/.php$/', '', $item); | |
| 92 | + | |
| 93 | + $class = $namespace . $class_name; | |
| 94 | + | |
| 95 | + $block = new $class(); | |
| 96 | + $block->register(); | |
| 105 | 97 | } |
| 106 | 98 | } |
| 107 | 99 | |
| 108 | 100 | /** |
| 109 | - * Registers the block. | |
| 110 | - * | |
| 111 | - * @param string $class | |
| 112 | - * | |
| 113 | - * @return void | |
| 114 | - */ | |
| 115 | - private function registerBlock($class) | |
| 116 | - { | |
| 117 | - $block = new $class(); | |
| 118 | - $block->register(); | |
| 119 | - } | |
| 120 | - | |
| 121 | - /** | |
| 122 | 101 | * Blocks assets. |
| 123 | 102 | * |
| 124 | 103 | * - Extends functionality of the button/image blocks by allowing to trigger a popup. |
| 125 | 104 | * It also allows us to set custom CSS Classes to these blocks without triggering a popup. |
| @@ -125,14 +104,36 @@ | ||
| 125 | 104 | * It also allows us to set custom CSS Classes to these blocks without triggering a popup. |
| 126 | 105 | */ |
| 127 | 106 | public function blocks_assets() |
| 128 | 107 | { |
| 129 | - wp_register_script( | |
| 108 | + if (!is_admin()) | |
| 109 | + { | |
| 110 | + return; | |
| 111 | + } | |
| 112 | + | |
| 113 | + wp_enqueue_script( | |
| 130 | 114 | 'fb-blocks-extend', |
| 131 | 115 | FBOX_MEDIA_ADMIN_URL . 'js/fb_blocks_extend.js', |
| 132 | - ['wp-i18n', 'wp-blocks', 'wp-editor', 'wp-components', 'wp-api-fetch'], | |
| 116 | + ['wp-i18n', 'wp-blocks', 'wp-editor', 'wp-components', 'wp-api-fetch', 'lodash'], | |
| 133 | 117 | FBOX_VERSION, |
| 134 | 118 | true |
| 135 | 119 | ); |
| 136 | - wp_enqueue_script('fb-blocks-extend'); | |
| 120 | + | |
| 121 | + // Enqueue block editor style only in Gutenberg editor | |
| 122 | + if (function_exists('get_current_screen')) | |
| 123 | + { | |
| 124 | + $screen = get_current_screen(); | |
| 125 | + if ($screen->is_block_editor) | |
| 126 | + { | |
| 127 | + if (get_post_type() === 'firebox') | |
| 128 | + { | |
| 129 | + wp_enqueue_style( | |
| 130 | + 'firebox-block-editor', | |
| 131 | + FBOX_MEDIA_ADMIN_URL . 'css/block-editor.css', | |
| 132 | + [], | |
| 133 | + FBOX_VERSION | |
| 134 | + ); | |
| 135 | + } | |
| 136 | + } | |
| 137 | + } | |
| 137 | 138 | } |
| 138 | 139 | } |