PluginProbe
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts / trunk
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts vtrunk
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
← All changes | includes/settings.php +100 -12 2.7.8trunk View file →
@@ -24,8 +24,15 @@
24 24 */
25 25 protected $core_blocks_version = '2.7.3';
26 26
27 27 /**
28 + * The plugin title
29 + *
30 + * @var string
31 + */
32 + private $plugin_title = 'Content Blocks Builder';
33 +
34 + /**
28 35 * The script handle
29 36 *
30 37 * @var string
31 38 */
@@ -53,9 +60,9 @@
53 60 // Enqueue settings script.
54 61 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_settings_scripts' ] );
55 62
56 63 // Do setting up stuff when the plugin is activated.
57 - add_action( 'content_block_builder_activate', [ $this, 'run_the_plugin_setup' ] );
64 + add_action( 'cbb/activate', [ $this, 'run_the_plugin_setup' ] );
58 65
59 66 // Maybe update core blocks.
60 67 add_action( 'init', [ $this, 'maybe_update_core_blocks' ] );
61 68
@@ -62,9 +69,9 @@
62 69 // Add rest api endpoint to query docs.
63 70 add_action( 'rest_api_init', [ $this, 'register_docs_endpoint' ] );
64 71
65 72 // Clear the transient cache on upgraded.
66 - add_action( 'cbb_version_upgraded', [ $this, 'clear_transient_cache' ] );
73 + add_action( 'cbb/version_upgraded', [ $this, 'clear_transient_cache' ] );
67 74
68 75 // Change the footer text for the settings pages.
69 76 add_action( 'admin_footer_text', [ $this, 'admin_footer_text' ] );
70 77
@@ -69,8 +76,14 @@
69 76 add_action( 'admin_footer_text', [ $this, 'admin_footer_text' ] );
70 77
71 78 // Purge the cache.
72 79 add_action( 'admin_init', [ $this, 'boldblocks_purge_cache' ] );
80 +
81 + // Migrate legacy options.
82 + add_action( 'cbb/version_upgraded', [ $this, 'migrate_legacy_options' ] );
83 +
84 + // Register setting fields.
85 + add_action( 'init', [ $this, 'register_settings' ] );
73 86 }
74 87
75 88 /**
76 89 * Print the admin toolbar.
@@ -97,13 +110,13 @@
97 110 'class' => '',
98 111 ],
99 112 ];
100 113
101 - $left_links = apply_filters( 'content_blocks_builder_get_header_left_links', $left_links );
114 + $left_links = apply_filters( 'cbb_get_header_left_links', $left_links );
102 115
103 116 ?>
104 117 <div class="cbb-settings-header">
105 - <h1><strong><?php esc_html_e( 'Content Blocks Builder', 'content-blocks-builder' ); ?></strong> <code><?php echo esc_html( $this->the_plugin_instance->get_plugin_version() ); ?></code></h1>
118 + <h1><strong><?php echo esc_html( $this->plugin_title ); ?></strong> <code><?php echo esc_html( $this->the_plugin_instance->get_plugin_version() ); ?></code></h1>
106 119 <ul class="lelf-links">
107 120 <?php foreach ( $left_links as $link ) : ?>
108 121 <?php
109 122 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@@ -126,9 +139,9 @@
126 139 $parent_slug = 'edit.php?post_type=boldblocks_block';
127 140
128 141 add_submenu_page(
129 142 $parent_slug,
130 - 'Content Blocks Builder',
143 + $this->plugin_title,
131 144 __( 'Settings', 'content-blocks-builder' ),
132 145 'manage_options',
133 146 'cbb-settings',
134 147 function () {
@@ -133,9 +146,9 @@
133 146 'cbb-settings',
134 147 function () {
135 148 ?>
136 149 <div class="wrap">
137 - <h2 class="screen-reader-text">Content Blocks Builder</h2>
150 + <h2 class="screen-reader-text"><?php echo esc_html( $this->plugin_title ); ?></h2>
138 151 <div class="boldblocks-settings js-boldblocks-settings-root"></div>
139 152 </div>
140 153 <?php
141 154 }
@@ -170,10 +183,11 @@
170 183 wp_add_inline_script(
171 184 $this->script_handle,
172 185 'const CBBSettings=' . wp_json_encode(
173 186 [
174 - 'nonce' => wp_create_nonce( 'cbb_purce_nonce' ),
175 - 'isPurgedCache' => $this->is_purged_cache ? 1 : 0,
187 + 'nonce' => wp_create_nonce( 'cbb_purce_nonce' ),
188 + 'isPurgedCache' => $this->is_purged_cache ? 1 : 0,
189 + 'variationNonce' => wp_create_nonce( 'cbb_variation_nonce' ),
176 190 ]
177 191 ),
178 192 'before'
179 193 );
@@ -198,16 +212,19 @@
198 212 * @return void
199 213 */
200 214 public function run_the_plugin_setup() {
201 215 // Deploy core blocks.
202 - if ( is_admin() && ! get_option( 'boldblocks_deployed_core_blocks' ) ) {
216 + if ( is_admin() && ! $this->is_deloyed_core_blocks() ) {
203 217 // Update core blocks.
204 218 $this->update_core_blocks();
205 219
206 220 // Add the marker to the settings to make sure this logic only runs one time.
207 - add_option( 'boldblocks_deployed_core_blocks', 1 );
221 + add_option( 'cbb_deployed_core_blocks', 1 );
208 222 }
209 223
224 + // Run the plugin setup.
225 + do_action( 'cbb_plugin_setup', $this->the_plugin_instance );
226 +
210 227 // Redirect to the getting started page, ignore bulk activation.
211 228 if (
212 229 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
213 230 ! ( ( isset( $_REQUEST['action'] ) && 'activate-selected' === $_REQUEST['action'] ) &&
@@ -223,9 +240,9 @@
223 240 * @return void
224 241 */
225 242 public function maybe_update_core_blocks() {
226 243 if ( is_admin() && current_user_can( 'manage_options' ) ) {
227 - $core_blocks_version = get_option( 'boldblocks_core_blocks_version' );
244 + $core_blocks_version = $this->get_core_blocks_version();
228 245 if ( ! $core_blocks_version || $core_blocks_version !== $this->core_blocks_version ) {
229 246 $this->update_core_blocks( $core_blocks_version, $this->core_blocks_version );
230 247 }
231 248 }
@@ -364,14 +381,40 @@
364 381 $post_id = wp_update_post( $updating_data );
365 382 }
366 383 }
367 384
368 - update_option( 'boldblocks_core_blocks_version', $this->core_blocks_version );
385 + update_option( 'cbb_core_blocks_version', $this->core_blocks_version );
369 386 }
370 387 }
371 388 }
372 389
373 390 /**
391 + * Migrate legacy options
392 + *
393 + * @param string $prev_version
394 + * @return void
395 + */
396 + public function migrate_legacy_options( $prev_version ) {
397 + if ( version_compare( $prev_version, '2.7.8', '<=' ) ) {
398 + $legacy_options = [
399 + 'boldblocks_pattern_categories' => 'cbb_pattern_categories',
400 + 'boldblocks_pattern_categories_all_label' => 'cbb_pattern_categories_all_label',
401 + 'boldblocks_typography' => 'cbb_typography',
402 + 'boldblocks_enable_typography' => 'cbb_enable_typography',
403 + 'boldblocks_use_bunny_fonts' => 'cbb_use_bunny_fonts',
404 + ];
405 +
406 + foreach ( $legacy_options as $old_option => $new_option ) {
407 + $option_value = get_option( $old_option );
408 + if ( $option_value ) {
409 + update_option( $new_option, $option_value );
410 + delete_option( $old_option );
411 + }
412 + }
413 + }
414 + }
415 +
416 + /**
374 417 * Build a custom endpoint to query docs.
375 418 *
376 419 * @return void
377 420 */
@@ -478,7 +521,52 @@
478 521 $this->clear_transient_cache();
479 522
480 523 $this->is_purged_cache = 1;
481 524 }
525 + }
526 +
527 + /**
528 + * Check if the core blocks have been deployed.
529 + *
530 + * @return boolean
531 + */
532 + private function is_deloyed_core_blocks() {
533 + return get_option( 'cbb_deployed_core_blocks' ) || get_option( 'boldblocks_deployed_core_blocks' );
534 + }
535 +
536 + /**
537 + * Get core blocks version.
538 + *
539 + * @return string
540 + */
541 + private function get_core_blocks_version() {
542 + $core_blocks_version = get_option( 'cbb_core_blocks_version' );
543 + if ( ! $core_blocks_version ) {
544 + $core_blocks_version = get_option( 'boldblocks_core_blocks_version' );
545 + }
546 +
547 + return $core_blocks_version;
548 + }
549 +
550 + /**
551 + * Register setting fields
552 + *
553 + * @return void
554 + */
555 + public function register_settings() {
556 + // phpcs:disable PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic
557 + register_setting(
558 + 'cbb',
559 + 'cbb_keep_data',
560 + [
561 + 'type' => 'boolean',
562 + 'sanitize_callback' => 'rest_sanitize_boolean',
563 + 'show_in_rest' => [
564 + 'name' => 'KeepDataOnUninstall',
565 + ],
566 + 'default' => false,
567 + ]
568 + );
569 + // phpcs:enable PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic
482 570 }
483 571 }
484 572 endif;