PluginProbe
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts / 1.0.2
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts v1.0.2
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 1.0.2, at content-blocks-builder.php

254 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Content Blocks Builder by BoldBlocks
4 * Description: Gutenberg - custom content blocks made easy.
5 * Requires at least: 5.8
6 * Requires PHP: 7.0
7 * Version: 1.0.2
8 * Author: Phi Phan
9 * Author URI: https://boldblocks.net
10 * Text Domain: boldblocks
11 *
12 * @package BoldBlocks
13 * @copyright Copyright(c) 2021, Phi Phan
14 */
15
16 namespace BoldBlocks;
17
18 // Exit if accessed directly.
19 defined( 'ABSPATH' ) || exit;
20
21 if ( ! class_exists( 'ContentBlocksBuilder' ) ) :
22 /**
23 * The main class
24 */
25 class ContentBlocksBuilder {
26 /**
27 * Plugin version
28 *
29 * @var String
30 */
31 protected $version = '1.0.2';
32
33 /**
34 * Components
35 *
36 * @var Array
37 */
38 protected $components = [];
39
40 /**
41 * A dummy constructor
42 */
43 public function __construct() {}
44
45 /**
46 * Kick start function.
47 * Define constants, load dependencies
48 *
49 * @return void
50 */
51 public function initialize() {
52 // Setup constants.
53 $this->setup_constants();
54
55 // Register core components.
56 $this->register_core_components();
57
58 // Load dependencies.
59 $this->load_dependencies();
60
61 // Run hooks.
62 $this->run();
63 }
64
65 /**
66 * Setup constants
67 *
68 * @return void
69 */
70 public function setup_constants() {
71 $this->define_constant( 'BOLDBLOCKS_CBB', true );
72 $this->define_constant( 'BOLDBLOCKS_CBB_ROOT_FILE', __FILE__ );
73 $this->define_constant( 'BOLDBLOCKS_CBB_VERSION', $this->version );
74 $this->define_constant( 'BOLDBLOCKS_CBB_PATH', trailingslashit( plugin_dir_path( BOLDBLOCKS_CBB_ROOT_FILE ) ) );
75 $this->define_constant( 'BOLDBLOCKS_CBB_URL', trailingslashit( plugin_dir_url( BOLDBLOCKS_CBB_ROOT_FILE ) ) );
76 $this->define_constant( 'BOLDBLOCKS_CBB_EDITOR_SCRIPTS_HANDLE', 'boldblocks-editor-scripts' );
77 $this->define_constant( 'BOLDBLOCKS_CBB_EDITOR_STYLE_HANDLE', 'boldblocks-editor-style' );
78 $this->define_constant( 'BOLDBLOCKS_CBB_FRONTEND_STYLE_HANDLE', 'boldblocks-frontend-style' );
79 }
80
81 /**
82 * Load core components
83 *
84 * @return void
85 */
86 public function register_core_components() {
87 // Load & register core components: custom blocks, patterns, variations.
88 $this->include_file( 'includes/custom-blocks.php' );
89 $this->include_file( 'includes/patterns.php' );
90 $this->include_file( 'includes/variations.php' );
91
92 $core_components = [ CustomBlocks::class, Patterns::class, Variations::class ];
93 foreach ( $core_components as $component ) {
94 $this->register_component( $component );
95 }
96 }
97
98 /**
99 * Load dependencies
100 *
101 * @return void
102 */
103 public function load_dependencies() {}
104
105 /**
106 * Run main hooks
107 *
108 * @return void
109 */
110 public function run() {
111 // Load translations.
112 add_action( 'plugins_loaded', [ $this, 'load_textdomain' ] );
113
114 // Main hooks.
115 add_action( 'init', [ $this, 'init' ], 5 );
116
117 // Enqueue scripts for editor.
118 add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_assets' ] );
119
120 // Run all components.
121 foreach ( $this->components as $component ) {
122 $component->run();
123 }
124 }
125
126 /**
127 * Process on init hook
128 *
129 * @return void
130 */
131 public function init() {
132
133 // Run a hook when the plugin initialized.
134 do_action( 'boldblocks/init' );
135 }
136
137 /**
138 * Enqueue editor assets
139 *
140 * @return void
141 */
142 public function enqueue_block_editor_assets() {
143 // Index access file.
144 $index_asset = $this->include_file( 'build/index.asset.php' );
145
146 // Scripts.
147 wp_enqueue_script(
148 BOLDBLOCKS_CBB_EDITOR_SCRIPTS_HANDLE,
149 $this->get_file_uri( 'build/index.js' ),
150 [ 'wp-i18n', 'wp-polyfill', 'wp-components', 'wp-blocks', 'wp-core-data', 'wp-plugins', 'wp-edit-post' ],
151 $index_asset['version'],
152 true
153 );
154
155 // Editor styles.
156 wp_enqueue_style(
157 BOLDBLOCKS_CBB_EDITOR_STYLE_HANDLE,
158 $this->get_file_uri( 'build/index.css' ),
159 [],
160 $index_asset['version']
161 );
162
163 // For ajax requests.
164 wp_localize_script(
165 BOLDBLOCKS_CBB_EDITOR_SCRIPTS_HANDLE,
166 'BoldBlocks',
167 array(
168 'admin_url' => get_admin_url( get_current_blog_id() ),
169 'ajax_url' => admin_url( 'admin-ajax.php' ),
170 'nonce' => wp_create_nonce( 'boldblocks-ajax-nonce' ),
171 )
172 );
173 }
174
175 /**
176 * Load text domain
177 *
178 * @return void
179 */
180 public function load_textdomain() {
181 load_plugin_textdomain(
182 'cbb',
183 false,
184 plugin_basename( realpath( __DIR__ . '/languages' ) )
185 );
186 }
187
188 /**
189 * Register component
190 *
191 * @param string $classname The class name of the component.
192 * @return void
193 */
194 public function register_component( $classname ) {
195 $this->components[ $classname ] = new $classname();
196 }
197
198 /**
199 * Define constant
200 *
201 * @param string $name The name of the constant.
202 * @param mixed $value The value of the constant.
203 * @return void
204 */
205 public function define_constant( $name, $value ) {
206 if ( ! defined( $name ) ) {
207 define( $name, $value );
208 }
209 }
210
211 /**
212 * Include file path.
213 *
214 * @param string $path file path.
215 * @return string
216 */
217 public function include_file( $path ) {
218 return include_once BOLDBLOCKS_CBB_PATH . $path;
219 }
220
221 /**
222 * Get file uri by file path.
223 *
224 * @param string $path file path.
225 * @return string
226 */
227 public function get_file_uri( $path ) {
228 return BOLDBLOCKS_CBB_URL . $path;
229 }
230 }
231
232 /**
233 * Kick start
234 *
235 * @return ContentBlocksBuilder instance
236 */
237 function boldblocks_cbb_initialize() {
238 global $boldblocks_cbb;
239
240 // Instantiate only once.
241 if ( ! isset( $boldblocks_cbb ) ) {
242 $boldblocks_cbb = new ContentBlocksBuilder();
243 $boldblocks_cbb->initialize();
244 }
245 return $boldblocks_cbb;
246 }
247
248 // Instantiate.
249 boldblocks_cbb_initialize();
250 endif;
251
252
253
254