Skip to content

Commit 6bce616

Browse files
committed
deprecate block defaults
1 parent cbd689f commit 6bce616

File tree

20 files changed

+92
-12
lines changed

20 files changed

+92
-12
lines changed

plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ function is_frontend() {
239239
require_once( plugin_dir_path( __FILE__ ) . 'src/plugins/global-settings/color-schemes/deprecated/index.php' ); // We need to add this so the filter for deprecation gets applied.
240240
require_once( plugin_dir_path( __FILE__ ) . 'src/plugins/global-settings/color-schemes/index.php' );
241241
require_once( plugin_dir_path( __FILE__ ) . 'src/plugins/global-settings/preset-controls/index.php' );
242-
require_once( plugin_dir_path( __FILE__ ) . 'src/custom-block-styles.php' );
243242
require_once( plugin_dir_path( __FILE__ ) . 'src/css-optimize.php' );
244243
require_once( plugin_dir_path( __FILE__ ) . 'src/compatibility/index.php' );
245244
if ( ! is_admin() ) {
@@ -292,6 +291,7 @@ function is_frontend() {
292291
require_once( plugin_dir_path( __FILE__ ) . 'src/deprecated/navigation-panel-pre-enabled.php' );
293292
require_once( plugin_dir_path( __FILE__ ) . 'src/deprecated/font-awesome-version.php' );
294293
require_once( plugin_dir_path( __FILE__ ) . 'src/deprecated/global-color-schemes.php' );
294+
require_once( plugin_dir_path( __FILE__ ) . 'src/deprecated/block-defaults.php' );
295295

296296
/**
297297
* V2 Deprecated

src/deprecated/block-defaults.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Block Defaults are deprecated since v3.18.0
4+
*
5+
*/
6+
7+
// Exit if accessed directly.
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
12+
if ( ! function_exists( 'stackable_deprecated_block_defaults_option' ) ) {
13+
14+
function stackable_deprecated_block_defaults_option() {
15+
// If true, Block Defaults will be enabled in the editor
16+
register_setting(
17+
'stackable_editor_settings',
18+
'stackable_enable_block_defaults',
19+
array(
20+
'type' => 'boolean',
21+
'description' => __( 'Use Block Defaults in the editor', STACKABLE_I18N ),
22+
'sanitize_callback' => 'sanitize_text_field',
23+
'show_in_rest' => true,
24+
'default' => false,
25+
)
26+
);
27+
}
28+
29+
function stackable_add_deprecated_block_defaults_setting( $settings ) {
30+
$settings['stackable_enable_block_defaults'] = boolval( get_option( 'stackable_enable_block_defaults', false ) );
31+
return $settings;
32+
}
33+
34+
// Make setting available in the editor.
35+
add_filter( 'stackable_js_settings', 'stackable_add_deprecated_block_defaults_setting' );
36+
add_action( 'init', 'stackable_deprecated_block_defaults_option' );
37+
}
38+
39+
if ( ! function_exists( 'stackable_deprecated_block_defaults' ) ) {
40+
41+
/**
42+
* Upon upgrading to v3.18.0 or later, Block Defaults will be enabled only if existing Block Defaults are present;
43+
* otherwise, they will be disabled.
44+
* For new installations, Block Defaults will be disabled by default.
45+
*/
46+
function stackable_deprecated_block_defaults( $old_version, $new_version ) {
47+
if ( ! empty( $old_version ) && version_compare( $old_version, "3.18.0", "<" ) ) {
48+
49+
// set option to true if there are saved block defaults
50+
if ( ! empty( get_option( 'stackable_block_styles', [] ) ) ) {
51+
update_option( 'stackable_enable_block_defaults', true, false );
52+
}
53+
}
54+
}
55+
56+
function stackable_require_block_defaults_script() {
57+
if ( get_option( 'stackable_enable_block_defaults', false ) ) {
58+
require_once( plugin_dir_path( __FILE__ ) . 'block-defaults/custom-block-styles.php' );
59+
}
60+
}
61+
62+
add_action( 'stackable_early_version_upgraded', 'stackable_deprecated_block_defaults', 10, 2 );
63+
add_action( 'init', 'stackable_require_block_defaults_script' );
64+
}

src/custom-block-styles.php renamed to src/deprecated/block-defaults/custom-block-styles.php

File renamed without changes.

src/plugins/global-settings/block-defaults/editor.scss renamed to src/deprecated/block-defaults/global-settings/editor.scss

File renamed without changes.

src/plugins/global-settings/block-defaults/index.js renamed to src/deprecated/block-defaults/global-settings/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/default-blocks', ou
5151
>
5252
<p className="components-base-control__help">
5353
{ __( 'Manage how Stackable blocks look when they\'re inserted.', i18n ) }
54-
&nbsp;
54+
&nbsp;
5555
<a href="https://docs.wpstackable.com/article/480-how-to-use-block-defaults?utm_source=wp-global-settings&utm_campaign=learnmore&utm_medium=gutenberg" target="_docs">
5656
{ __( 'Learn more about Block Defaults', i18n ) }
5757
</a>

src/plugins/global-settings/block-defaults/readme.md renamed to src/deprecated/block-defaults/global-settings/readme.md

File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { settings as stackableSettings } from 'stackable'
2+
3+
// Conditionally import scripts
4+
if ( stackableSettings.stackable_enable_block_defaults ) {
5+
import( './save-block' )
6+
import( './global-settings' )
7+
}

src/plugins/save-block/custom-block-styles-editor.js renamed to src/deprecated/block-defaults/save-block/custom-block-styles-editor.js

File renamed without changes.
File renamed without changes.

src/plugins/save-block/index.js renamed to src/deprecated/block-defaults/save-block/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import './store'
55
import './variation-picker'
66
import './custom-block-styles-editor'
77
import SaveMenu from './save-menu'
8-
import { useSavedDefaultBlockStyle } from '~stackable/hooks'
8+
import { useSavedDefaultBlockStyle } from './use-saved-default-block-style'
99
import { settings } from 'stackable'
1010

1111
/**

0 commit comments

Comments
 (0)