| @@ -2,13 +2,13 @@ | ||
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * Plugin Name: Content Blocks Builder |
| 5 | 5 | * Plugin URI: https://contentblocksbuilder.com?utm_source=CBB&utm_campaign=CBB+visit+site&utm_medium=link&utm_content=Plugin+URI |
| 6 | - * Description: Design your website directly on the Gutenberg Block Editor without coding using core blocks and block themes. | |
| 7 | - * Requires at least: 6.6 | |
| 8 | - * Requires PHP: 7.4 | |
| 9 | - * Version: 2.7.5 | |
| 10 | - * Author: CBB Team | |
| 6 | + * Description: Create blocks by wrapping other blocks into containers or repeaters to create layouts like grid, carousel, popup, accordion — all in the Block Editor. Fast. Easy. Bloat-free. | |
| 7 | + * Requires at least: 6.9 | |
| 8 | + * Requires PHP: 8.0 | |
| 9 | + * Version: 2.8.14 | |
| 10 | + * Author: Phi Phan | |
| 11 | 11 | * Author URI: https://contentblocksbuilder.com?utm_source=CBB&utm_campaign=CBB+visit+site&utm_medium=link&utm_content=Author+URI |
| 12 | 12 | * License: GPL-3.0 |
| 13 | 13 | * |
| 14 | 14 | * @package BoldBlocks |
| @@ -23,9 +23,9 @@ | ||
| 23 | 23 | cbb_fs()->set_basename( false, __FILE__ ); |
| 24 | 24 | return; |
| 25 | 25 | } |
| 26 | 26 | // Include Freemius functions. |
| 27 | -require_once dirname( __FILE__ ) . '/freemius.php'; | |
| 27 | +require_once __DIR__ . '/freemius.php'; | |
| 28 | 28 | if ( !class_exists( ContentBlocksBuilder::class ) ) { |
| 29 | 29 | /** |
| 30 | 30 | * The main class |
| 31 | 31 | */ |
| @@ -34,14 +34,14 @@ | ||
| 34 | 34 | * Plugin version |
| 35 | 35 | * |
| 36 | 36 | * @var String |
| 37 | 37 | */ |
| 38 | - public $version = '2.7.5'; | |
| 38 | + public $version = '2.8.14'; | |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Components |
| 42 | 42 | * |
| 43 | - * @var Array | |
| 43 | + * @var array | |
| 44 | 44 | */ |
| 45 | 45 | protected $components = []; |
| 46 | 46 | |
| 47 | 47 | /** |
| @@ -58,9 +58,9 @@ | ||
| 58 | 58 | */ |
| 59 | 59 | private static $instance; |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | - * A dummy constructor | |
| 62 | + * The constructor | |
| 63 | 63 | */ |
| 64 | 64 | private function __construct() { |
| 65 | 65 | } |
| 66 | 66 | |
| @@ -90,10 +90,10 @@ | ||
| 90 | 90 | // Setup constants. |
| 91 | 91 | $this->setup_constants(); |
| 92 | 92 | // Load dependencies. |
| 93 | 93 | $this->load_dependencies(); |
| 94 | - // Register core components. | |
| 95 | - $this->register_core_components(); | |
| 94 | + // Register components. | |
| 95 | + $this->register_components(); | |
| 96 | 96 | // Run hooks. |
| 97 | 97 | $this->run(); |
| 98 | 98 | } |
| 99 | 99 | |
| @@ -113,47 +113,35 @@ | ||
| 113 | 113 | $this->define_constant( 'BOLDBLOCKS_CBB_FRONTEND_STYLE_HANDLE', 'boldblocks-frontend-style' ); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | - * Load core components | |
| 117 | + * Load components | |
| 118 | 118 | * |
| 119 | 119 | * @return void |
| 120 | 120 | */ |
| 121 | - public function register_core_components() { | |
| 122 | - // Load & register core components: custom blocks, patterns, variations. | |
| 123 | - $this->include_file( 'includes/custom-blocks.php' ); | |
| 124 | - $this->include_file( 'includes/variations.php' ); | |
| 125 | - $this->include_file( 'includes/patterns.php' ); | |
| 126 | - $this->include_file( 'includes/copy-post.php' ); | |
| 127 | - $this->include_file( 'includes/custom-style.php' ); | |
| 128 | - $this->include_file( 'includes/meta-revisioning.php' ); | |
| 129 | - $this->include_file( 'includes/freemius-config.php' ); | |
| 130 | - $this->include_file( 'includes/settings.php' ); | |
| 131 | - $this->include_file( 'includes/theme.php' ); | |
| 132 | - $this->include_file( 'includes/icon-library.php' ); | |
| 133 | - $this->include_file( 'includes/typography.php' ); | |
| 134 | - $this->include_file( 'includes/library.php' ); | |
| 135 | - $this->include_file( 'includes/maintenance.php' ); | |
| 136 | - $this->include_file( 'includes/block-overrides.php' ); | |
| 137 | - $core_components = [ | |
| 138 | - CustomBlocks::class, | |
| 139 | - Variations::class, | |
| 140 | - Patterns::class, | |
| 141 | - CopyPost::class, | |
| 142 | - CustomStyle::class, | |
| 143 | - MetaRevisioning::class, | |
| 144 | - Settings::class, | |
| 145 | - FreemiusConfig::class, | |
| 146 | - Theme::class, | |
| 147 | - IconLibrary::class, | |
| 148 | - Typography::class, | |
| 149 | - Library::class, | |
| 150 | - Maintenance::class, | |
| 151 | - BlockOverrides::class | |
| 121 | + public function register_components() { | |
| 122 | + // Load & register core components: custom blocks, patterns, variations, etc. | |
| 123 | + $components = [ | |
| 124 | + 'includes/custom-blocks.php' => CustomBlocks::class, | |
| 125 | + 'includes/variations.php' => Variations::class, | |
| 126 | + 'includes/patterns.php' => Patterns::class, | |
| 127 | + 'includes/copy-post.php' => CopyPost::class, | |
| 128 | + 'includes/custom-style.php' => CustomStyle::class, | |
| 129 | + 'includes/meta-revisioning.php' => MetaRevisioning::class, | |
| 130 | + 'includes/settings.php' => Settings::class, | |
| 131 | + 'includes/freemius-config.php' => FreemiusConfig::class, | |
| 132 | + 'includes/theme.php' => Theme::class, | |
| 133 | + 'includes/icon-library.php' => IconLibrary::class, | |
| 134 | + 'includes/typography.php' => Typography::class, | |
| 135 | + 'includes/library.php' => Library::class, | |
| 136 | + 'includes/maintenance.php' => Maintenance::class, | |
| 137 | + 'includes/block-overrides.php' => BlockOverrides::class, | |
| 152 | 138 | ]; |
| 153 | - foreach ( $core_components as $component ) { | |
| 154 | - $this->register_component( $component ); | |
| 139 | + foreach ( $components as $file => $classname ) { | |
| 140 | + $this->register_component( $file, $classname ); | |
| 155 | 141 | } |
| 142 | + // Register additional components. | |
| 143 | + do_action( 'cbb/register_components', $this ); | |
| 156 | 144 | } |
| 157 | 145 | |
| 158 | 146 | /** |
| 159 | 147 | * Load dependencies |
| @@ -172,16 +160,14 @@ | ||
| 172 | 160 | * |
| 173 | 161 | * @return void |
| 174 | 162 | */ |
| 175 | 163 | public function run() { |
| 176 | - // Load translations. | |
| 177 | - add_action( 'init', [$this, 'load_textdomain'] ); | |
| 178 | - // Main hooks. | |
| 164 | + // Init hook. | |
| 179 | 165 | add_action( 'init', [$this, 'init'], 5 ); |
| 180 | 166 | // Enqueue scripts for editor. |
| 181 | 167 | add_action( 'enqueue_block_assets', [$this, 'enqueue_block_assets'] ); |
| 182 | 168 | // Save version and trigger upgraded hook. |
| 183 | - add_action( 'admin_menu', [$this, 'version_upgrade'], 1 ); | |
| 169 | + add_action( 'plugins_loaded', [$this, 'version_upgrade'], 1 ); | |
| 184 | 170 | // Run all components. |
| 185 | 171 | foreach ( $this->components as $component ) { |
| 186 | 172 | $component->run(); |
| 187 | 173 | } |
| @@ -192,10 +178,17 @@ | ||
| 192 | 178 | * |
| 193 | 179 | * @return void |
| 194 | 180 | */ |
| 195 | 181 | public function init() { |
| 196 | - // Run a hook when the plugin initialized. | |
| 182 | + /** | |
| 183 | + * Fires when CBB is initialized. | |
| 184 | + * Run before components are running. | |
| 185 | + * | |
| 186 | + * @since 2.7.12 Use `cbb/init` instead of `boldblocks/init`. | |
| 187 | + */ | |
| 188 | + do_action( 'cbb/init' ); | |
| 197 | 189 | do_action( 'boldblocks/init' ); |
| 190 | + // Deprecated. | |
| 198 | 191 | } |
| 199 | 192 | |
| 200 | 193 | /** |
| 201 | 194 | * Enqueue editor assets |
| @@ -216,9 +209,9 @@ | ||
| 216 | 209 | $index_asset['dependencies'] ?? [], |
| 217 | 210 | $this->get_script_version( $index_asset ), |
| 218 | 211 | true |
| 219 | 212 | ); |
| 220 | - // For debuging. | |
| 213 | + // For debugging. | |
| 221 | 214 | $this->enqueue_debug_information( BOLDBLOCKS_CBB_EDITOR_SCRIPTS_HANDLE ); |
| 222 | 215 | // Styles. |
| 223 | 216 | wp_enqueue_style( |
| 224 | 217 | BOLDBLOCKS_CBB_EDITOR_STYLE_HANDLE, |
| @@ -234,30 +227,24 @@ | ||
| 234 | 227 | * @return void |
| 235 | 228 | */ |
| 236 | 229 | public function version_upgrade() { |
| 237 | 230 | if ( get_option( 'cbb_current_version' ) !== $this->version ) { |
| 238 | - do_action( 'cbb_version_upgraded', get_option( 'cbb_current_version' ), $this->version ); | |
| 231 | + do_action( 'cbb/version_upgraded', get_option( 'cbb_current_version' ), $this->version ); | |
| 239 | 232 | update_option( 'cbb_current_version', $this->version ); |
| 240 | 233 | } |
| 241 | 234 | } |
| 242 | 235 | |
| 243 | 236 | /** |
| 244 | - * Load text domain | |
| 245 | - * | |
| 246 | - * @return void | |
| 247 | - */ | |
| 248 | - public function load_textdomain() { | |
| 249 | - load_plugin_textdomain( 'content-blocks-builder', false, plugin_basename( realpath( __DIR__ . '/languages' ) ) ); | |
| 250 | - } | |
| 251 | - | |
| 252 | - /** | |
| 253 | 237 | * Register component |
| 254 | 238 | * |
| 239 | + * @param string $file The file path of the component. | |
| 255 | 240 | * @param string $classname The class name of the component. |
| 256 | 241 | * @return void |
| 257 | 242 | */ |
| 258 | - public function register_component( $classname ) { | |
| 259 | - $this->components[$classname] = new $classname($this); | |
| 243 | + public function register_component( $file, $classname ) { | |
| 244 | + if ( $this->include_file( $file ) ) { | |
| 245 | + $this->components[$classname] = new $classname($this); | |
| 246 | + } | |
| 260 | 247 | } |
| 261 | 248 | |
| 262 | 249 | /** |
| 263 | 250 | * Get a component by class name |
| @@ -282,9 +269,9 @@ | ||
| 282 | 269 | } |
| 283 | 270 | } |
| 284 | 271 | |
| 285 | 272 | /** |
| 286 | - * Retrn file path for file or folder. | |
| 273 | + * Return file path for file or folder. | |
| 287 | 274 | * |
| 288 | 275 | * @param string $path file path. |
| 289 | 276 | * @return string |
| 290 | 277 | */ |
| @@ -298,9 +285,17 @@ | ||
| 298 | 285 | * @param string $path file path. |
| 299 | 286 | * @return mixed |
| 300 | 287 | */ |
| 301 | 288 | public function include_file( $path ) { |
| 302 | - return include_once $this->get_file_path( $path ); | |
| 289 | + $file_path = $this->get_file_path( $path ); | |
| 290 | + if ( !file_exists( $file_path ) ) { | |
| 291 | + if ( $this->is_debug_mode() ) { | |
| 292 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log | |
| 293 | + error_log( "[CBB]: Missing file: {$file_path}" ); | |
| 294 | + } | |
| 295 | + return false; | |
| 296 | + } | |
| 297 | + return include_once $file_path; | |
| 303 | 298 | } |
| 304 | 299 | |
| 305 | 300 | /** |
| 306 | 301 | * Get file uri by file path. |
| @@ -381,9 +376,9 @@ | ||
| 381 | 376 | * |
| 382 | 377 | * @return void |
| 383 | 378 | */ |
| 384 | 379 | function content_block_builder_activate() { |
| 385 | - do_action( 'content_block_builder_activate' ); | |
| 380 | + do_action( 'cbb/activate' ); | |
| 386 | 381 | } |
| 387 | 382 | |
| 388 | 383 | register_activation_hook( __FILE__, __NAMESPACE__ . '\\content_block_builder_activate' ); |
| 389 | 384 | } |