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 +107 -16 2.7.7trunk 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.
@@ -83,9 +96,9 @@
83 96 // Left links.
84 97 $left_links = [
85 98 [
86 99 'url' => 'https://wordpress.org/support/plugin/content-blocks-builder',
87 - 'title' => __( 'Feedback & Support ↗', 'display-a-meta-field-as-block' ),
100 + 'title' => __( 'Feedback & Support ↗', 'content-blocks-builder' ),
88 101 'target' => '_blank',
89 102 'icon' => '<span class="dashicons dashicons-editor-help"></span> ',
90 103 'class' => '',
91 104 ],
@@ -90,9 +103,9 @@
90 103 'class' => '',
91 104 ],
92 105 [
93 106 'url' => 'https://wordpress.org/support/plugin/content-blocks-builder/reviews/#new-post',
94 - 'title' => __( 'Review ↗', 'display-a-meta-field-as-block' ),
107 + 'title' => __( 'Review ↗', 'content-blocks-builder' ),
95 108 'target' => '_blank',
96 109 'icon' => '<span class="dashicons dashicons-star-filled"></span> ',
97 110 'class' => '',
98 111 ],
@@ -97,16 +110,19 @@
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 printf( __( '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 - <?php printf( '<li %5$s><a href="%1$s" target="%3$s"%6$s>%4$s%2$s</a></li>', $link['url'], $link['title'], $link['target'], $link['icon'], ( $link['class'] ?? '' ) ? 'class="' . $link['class'] . '"' : '', $link['style'] ?? '' ? ' style="' . $link['style'] . '"' : '' ); ?>
121 + <?php
122 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
123 + printf( '<li %5$s><a href="%1$s" target="%3$s"%6$s>%4$s%2$s</a></li>', $link['url'], $link['title'], $link['target'], $link['icon'], ( $link['class'] ?? '' ) ? 'class="' . $link['class'] . '"' : '', $link['style'] ?? '' ? ' style="' . $link['style'] . '"' : '' );
124 + ?>
109 125 <?php endforeach; ?>
110 126 </ul>
111 127 </div>
112 128 <?php
@@ -123,9 +139,9 @@
123 139 $parent_slug = 'edit.php?post_type=boldblocks_block';
124 140
125 141 add_submenu_page(
126 142 $parent_slug,
127 - __( 'Content Blocks Builder' ),
143 + $this->plugin_title,
128 144 __( 'Settings', 'content-blocks-builder' ),
129 145 'manage_options',
130 146 'cbb-settings',
131 147 function () {
@@ -130,9 +146,9 @@
130 146 'cbb-settings',
131 147 function () {
132 148 ?>
133 149 <div class="wrap">
134 - <h2 class="screen-reader-text">Content Blocks Builder</h2>
150 + <h2 class="screen-reader-text"><?php echo esc_html( $this->plugin_title ); ?></h2>
135 151 <div class="boldblocks-settings js-boldblocks-settings-root"></div>
136 152 </div>
137 153 <?php
138 154 }
@@ -167,10 +183,11 @@
167 183 wp_add_inline_script(
168 184 $this->script_handle,
169 185 'const CBBSettings=' . wp_json_encode(
170 186 [
171 - 'nonce' => wp_create_nonce( 'cbb_purce_nonce' ),
172 - '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' ),
173 190 ]
174 191 ),
175 192 'before'
176 193 );
@@ -195,16 +212,19 @@
195 212 * @return void
196 213 */
197 214 public function run_the_plugin_setup() {
198 215 // Deploy core blocks.
199 - if ( is_admin() && ! get_option( 'boldblocks_deployed_core_blocks' ) ) {
216 + if ( is_admin() && ! $this->is_deloyed_core_blocks() ) {
200 217 // Update core blocks.
201 218 $this->update_core_blocks();
202 219
203 220 // Add the marker to the settings to make sure this logic only runs one time.
204 - add_option( 'boldblocks_deployed_core_blocks', 1 );
221 + add_option( 'cbb_deployed_core_blocks', 1 );
205 222 }
206 223
224 + // Run the plugin setup.
225 + do_action( 'cbb_plugin_setup', $this->the_plugin_instance );
226 +
207 227 // Redirect to the getting started page, ignore bulk activation.
208 228 if (
209 229 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
210 230 ! ( ( isset( $_REQUEST['action'] ) && 'activate-selected' === $_REQUEST['action'] ) &&
@@ -220,9 +240,9 @@
220 240 * @return void
221 241 */
222 242 public function maybe_update_core_blocks() {
223 243 if ( is_admin() && current_user_can( 'manage_options' ) ) {
224 - $core_blocks_version = get_option( 'boldblocks_core_blocks_version' );
244 + $core_blocks_version = $this->get_core_blocks_version();
225 245 if ( ! $core_blocks_version || $core_blocks_version !== $this->core_blocks_version ) {
226 246 $this->update_core_blocks( $core_blocks_version, $this->core_blocks_version );
227 247 }
228 248 }
@@ -361,14 +381,40 @@
361 381 $post_id = wp_update_post( $updating_data );
362 382 }
363 383 }
364 384
365 - update_option( 'boldblocks_core_blocks_version', $this->core_blocks_version );
385 + update_option( 'cbb_core_blocks_version', $this->core_blocks_version );
366 386 }
367 387 }
368 388 }
369 389
370 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 + /**
371 417 * Build a custom endpoint to query docs.
372 418 *
373 419 * @return void
374 420 */
@@ -442,9 +488,9 @@
442 488 public function admin_footer_text( $footer_text ) {
443 489 // Get current screen.
444 490 $current_screen = get_current_screen();
445 491 if ( 'edit.php?post_type=boldblocks_block' === $current_screen->parent_file ) {
446 - $footer_text = '<i><a href="https://contentblocksbuilder.com/?utm_source=CBB&utm_campaign=CBB+visit+site&utm_medium=link&utm_content=footer-text" target="_blank" title="' . __( 'Visit the Plugin website', 'content-blocks-builder' ) . '" style="text-decoration:none"><strong>CBB</strong></a> <code>' . esc_html__( $this->the_plugin_instance->get_plugin_version() ) . '</code>. Please <a target="_blank" href="https://wordpress.org/support/plugin/content-blocks-builder/reviews/#new-post" title="Rate the plugin" style="text-decoration:none">rate the plugin <span style="color:#ffb900">★★★★★</span></a> to help us spread the word. Thank you from the CBB team!</i>';
492 + $footer_text = '<i><a href="https://contentblocksbuilder.com/?utm_source=CBB&utm_campaign=CBB+visit+site&utm_medium=link&utm_content=footer-text" target="_blank" title="' . __( 'Visit the Plugin website', 'content-blocks-builder' ) . '" style="text-decoration:none"><strong>CBB</strong></a> <code>' . esc_html( $this->the_plugin_instance->get_plugin_version() ) . '</code>. Please <a target="_blank" href="https://wordpress.org/support/plugin/content-blocks-builder/reviews/#new-post" title="Rate the plugin" style="text-decoration:none">rate the plugin <span style="color:#ffb900">★★★★★</span></a> to help us spread the word. Thank you from the CBB team!</i>';
447 493 }
448 494
449 495 return $footer_text;
450 496 }
@@ -475,7 +521,52 @@
475 521 $this->clear_transient_cache();
476 522
477 523 $this->is_purged_cache = 1;
478 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
479 570 }
480 571 }
481 572 endif;