PluginProbe
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts / 2.7.8
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts v2.7.8
2.8.14 2.8.13 2.8.12 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.11 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 trunk 1.0.1 1.0.2 1.1.0 1.1.1 All 147 releases
content-blocks-builder / content-blocks-builder.php

content-blocks-builder.php in Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts 2.7.8, at content-blocks-builder.php

389 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Content Blocks Builder
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.8
10 * Author: CBB Team
11 * Author URI: https://contentblocksbuilder.com?utm_source=CBB&utm_campaign=CBB+visit+site&utm_medium=link&utm_content=Author+URI
12 * License: GPL-3.0
13 *
14 * @package BoldBlocks
15 * @copyright Copyright(c) 2022, Phi Phan
16 *
17 */
18 namespace BoldBlocks;
19
20 // Exit if accessed directly.
21 defined( 'ABSPATH' ) || exit;
22 if ( function_exists( __NAMESPACE__ . '\\cbb_fs' ) ) {
23 cbb_fs()->set_basename( false, __FILE__ );
24 return;
25 }
26 // Include Freemius functions.
27 require_once dirname( __FILE__ ) . '/freemius.php';
28 if ( !class_exists( ContentBlocksBuilder::class ) ) {
29 /**
30 * The main class
31 */
32 class ContentBlocksBuilder {
33 /**
34 * Plugin version
35 *
36 * @var String
37 */
38 public $version = '2.7.8';
39
40 /**
41 * Components
42 *
43 * @var Array
44 */
45 protected $components = [];
46
47 /**
48 * The suffix for scripts
49 *
50 * @var string
51 */
52 protected $script_suffix = '';
53
54 /**
55 * Plugin instance
56 *
57 * @var ContentBlocksBuilder
58 */
59 private static $instance;
60
61 /**
62 * A dummy constructor
63 */
64 private function __construct() {
65 }
66
67 /**
68 * Initialize the instance.
69 *
70 * @return ContentBlocksBuilder
71 */
72 public static function get_instance() {
73 if ( !isset( self::$instance ) ) {
74 self::$instance = new ContentBlocksBuilder();
75 self::$instance->initialize();
76 }
77 return self::$instance;
78 }
79
80 /**
81 * Kick start function.
82 * Define constants
83 * Load dependencies
84 * Register components
85 * Run the main hooks
86 *
87 * @return void
88 */
89 public function initialize() {
90 // Setup constants.
91 $this->setup_constants();
92 // Load dependencies.
93 $this->load_dependencies();
94 // Register core components.
95 $this->register_core_components();
96 // Run hooks.
97 $this->run();
98 }
99
100 /**
101 * Setup constants
102 *
103 * @return void
104 */
105 public function setup_constants() {
106 $this->define_constant( 'BOLDBLOCKS_CBB', true );
107 $this->define_constant( 'BOLDBLOCKS_CBB_ROOT_FILE', __FILE__ );
108 $this->define_constant( 'BOLDBLOCKS_CBB_VERSION', $this->version );
109 $this->define_constant( 'BOLDBLOCKS_CBB_PATH', trailingslashit( plugin_dir_path( BOLDBLOCKS_CBB_ROOT_FILE ) ) );
110 $this->define_constant( 'BOLDBLOCKS_CBB_URL', trailingslashit( plugin_dir_url( BOLDBLOCKS_CBB_ROOT_FILE ) ) );
111 $this->define_constant( 'BOLDBLOCKS_CBB_EDITOR_SCRIPTS_HANDLE', 'boldblocks-editor-scripts' );
112 $this->define_constant( 'BOLDBLOCKS_CBB_EDITOR_STYLE_HANDLE', 'boldblocks-editor-style' );
113 $this->define_constant( 'BOLDBLOCKS_CBB_FRONTEND_STYLE_HANDLE', 'boldblocks-frontend-style' );
114 }
115
116 /**
117 * Load core components
118 *
119 * @return void
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
152 ];
153 foreach ( $core_components as $component ) {
154 $this->register_component( $component );
155 }
156 }
157
158 /**
159 * Load dependencies
160 *
161 * @return void
162 */
163 public function load_dependencies() {
164 // Load core component.
165 $this->include_file( 'includes/core-component.php' );
166 // Load post type helper.
167 $this->include_file( 'includes/post-type.php' );
168 }
169
170 /**
171 * Run main hooks
172 *
173 * @return void
174 */
175 public function run() {
176 // Load translations.
177 add_action( 'init', [$this, 'load_textdomain'] );
178 // Main hooks.
179 add_action( 'init', [$this, 'init'], 5 );
180 // Enqueue scripts for editor.
181 add_action( 'enqueue_block_assets', [$this, 'enqueue_block_assets'] );
182 // Save version and trigger upgraded hook.
183 add_action( 'admin_menu', [$this, 'version_upgrade'], 1 );
184 // Run all components.
185 foreach ( $this->components as $component ) {
186 $component->run();
187 }
188 }
189
190 /**
191 * Process on init hook
192 *
193 * @return void
194 */
195 public function init() {
196 // Run a hook when the plugin initialized.
197 do_action( 'boldblocks/init' );
198 }
199
200 /**
201 * Enqueue editor assets
202 *
203 * @return void
204 */
205 public function enqueue_block_assets() {
206 // Only load in the admin side.
207 if ( !is_admin() ) {
208 return;
209 }
210 // Index access file.
211 $index_asset = $this->include_file( 'build/index.asset.php' );
212 // Scripts.
213 wp_enqueue_script(
214 BOLDBLOCKS_CBB_EDITOR_SCRIPTS_HANDLE,
215 $this->get_file_uri( 'build/index.js' ),
216 $index_asset['dependencies'] ?? [],
217 $this->get_script_version( $index_asset ),
218 true
219 );
220 // For debuging.
221 $this->enqueue_debug_information( BOLDBLOCKS_CBB_EDITOR_SCRIPTS_HANDLE );
222 // Styles.
223 wp_enqueue_style(
224 BOLDBLOCKS_CBB_EDITOR_STYLE_HANDLE,
225 $this->get_file_uri( 'build/index.css' ),
226 [],
227 $this->get_script_version( $index_asset )
228 );
229 }
230
231 /**
232 * Save version and trigger an upgrade hook
233 *
234 * @return void
235 */
236 public function version_upgrade() {
237 if ( get_option( 'cbb_current_version' ) !== $this->version ) {
238 do_action( 'cbb_version_upgraded', get_option( 'cbb_current_version' ), $this->version );
239 update_option( 'cbb_current_version', $this->version );
240 }
241 }
242
243 /**
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 * Register component
254 *
255 * @param string $classname The class name of the component.
256 * @return void
257 */
258 public function register_component( $classname ) {
259 $this->components[$classname] = new $classname($this);
260 }
261
262 /**
263 * Get a component by class name
264 *
265 * @param string $classname The class name of the component.
266 * @return mixed
267 */
268 public function get_component( $classname ) {
269 return $this->components[$classname] ?? false;
270 }
271
272 /**
273 * Define constant
274 *
275 * @param string $name The name of the constant.
276 * @param mixed $value The value of the constant.
277 * @return void
278 */
279 public function define_constant( $name, $value ) {
280 if ( !defined( $name ) ) {
281 define( $name, $value );
282 }
283 }
284
285 /**
286 * Retrn file path for file or folder.
287 *
288 * @param string $path file path.
289 * @return string
290 */
291 public function get_file_path( $path ) {
292 return BOLDBLOCKS_CBB_PATH . $path;
293 }
294
295 /**
296 * Include file path.
297 *
298 * @param string $path file path.
299 * @return mixed
300 */
301 public function include_file( $path ) {
302 return include_once $this->get_file_path( $path );
303 }
304
305 /**
306 * Get file uri by file path.
307 *
308 * @param string $path file path.
309 * @return string
310 */
311 public function get_file_uri( $path ) {
312 return BOLDBLOCKS_CBB_URL . $path;
313 }
314
315 /**
316 * Create version for scripts/styles
317 *
318 * @param array $asset_file
319 * @return string
320 */
321 public function get_script_version( $asset_file ) {
322 return ( wp_get_environment_type() !== 'production' ? $asset_file['version'] ?? BOLDBLOCKS_CBB_VERSION : BOLDBLOCKS_CBB_VERSION );
323 }
324
325 /**
326 * Get the suffix for the scripts
327 *
328 * @return string
329 */
330 public function get_script_suffix() {
331 return $this->script_suffix;
332 }
333
334 /**
335 * Get the plugin version
336 *
337 * @return string
338 */
339 public function get_plugin_version() {
340 return $this->version;
341 }
342
343 /**
344 * Is Debugging CBB
345 *
346 * @return boolean
347 */
348 public function is_debug_mode() {
349 return defined( 'CBB_DEBUG' ) && CBB_DEBUG || 'development' === wp_get_environment_type();
350 }
351
352 /**
353 * Enqueue debug log information
354 *
355 * @param string $handle
356 * @return void
357 */
358 public function enqueue_debug_information( $handle ) {
359 wp_add_inline_script( $handle, 'var BBLOG=' . wp_json_encode( [
360 'environmentType' => ( $this->is_debug_mode() ? 'development' : wp_get_environment_type() ),
361 ] ), 'before' );
362 }
363
364 }
365
366 /**
367 * Kick start
368 *
369 * @return ContentBlocksBuilder instance
370 */
371 function boldblocks_cbb_get_instance() {
372 return ContentBlocksBuilder::get_instance();
373 }
374
375 // Instantiate.
376 boldblocks_cbb_get_instance();
377 }
378 if ( !function_exists( __NAMESPACE__ . '\\content_block_builder_activate' ) ) {
379 /**
380 * Trigger an action when the plugin is activated.
381 *
382 * @return void
383 */
384 function content_block_builder_activate() {
385 do_action( 'content_block_builder_activate' );
386 }
387
388 register_activation_hook( __FILE__, __NAMESPACE__ . '\\content_block_builder_activate' );
389 }