PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.16.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.16.0
2.16.0 2.15.0 2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 All 83 releases
← All changes | includes/migration.php +108 -0 2.8.1 → 2.16.0 View file →
@@ -5,8 +5,9 @@
5 5 exit;
6 6 }
7 7
8 8 use ABlocks\Admin\Settings;
9 +use ABlocks\Helper;
9 10
10 11 class Migration {
11 12
12 13 public static function init() {
@@ -15,8 +16,13 @@
15 16 add_filter( 'render_block_data', array( $self, 'update_attributes_backward_compatibility' ) );
16 17 }
17 18
18 19 public function run_migration() {
20 + $this->migrate_font_stack();
21 + // Must run BEFORE Settings::save_settings() so the raw option still
22 + // shows which keys were never persisted (old "missing = enabled" sites).
23 + $this->migrate_integration_block_defaults();
24 +
19 25 $ablocks_version = get_option( 'ablocks_version' );
20 26 // Save Version Number, flash role management and save permalink
21 27 if ( ABLOCKS_VERSION !== $ablocks_version ) {
22 28 Settings::save_settings();
@@ -23,8 +29,110 @@
23 29 $this->migrate_1_6_3( $ablocks_version );
24 30 $this->migrate_1_8_0( $ablocks_version );
25 31 update_option( 'ablocks_version', ABLOCKS_VERSION );
26 32 }
33 + }
34 +
35 + /**
36 + * Academy LMS, StoreEngine and ECM blocks used to default to enabled, and
37 + * old versions only persisted the "off" state — a block without an entry in
38 + * the visibility option was treated as enabled by the reader. The reader
39 + * now treats missing keys as disabled, so an old sparse save would silently
40 + * turn integration blocks off after upgrade.
41 + *
42 + * Once per integration: for every block without an explicit entry, write
43 + * `true` when the companion plugin is active (preserve the old on-by-
44 + * default behavior for sites that actually use the integration) and
45 + * `false` otherwise (new installs and sites that never had the plugin).
46 + * Blocks that already have an explicit value are the user's choice and are
47 + * left alone. No post_content scan — this is O(number of blocks).
48 + */
49 + public function migrate_integration_block_defaults() {
50 + $integrations = [
51 + 'academy' => 'academy/academy.php',
52 + 'storeengine' => 'storeengine/storeengine.php',
53 + 'ecm' => 'easy-content-manager/easy-content-manager.php',
54 + ];
55 + // _v2: an earlier version of this migration treated any `true` already
56 + // in the option as a user choice and left stale installer defaults in
57 + // place. Bump the tracker so sites that ran the old pass re-migrate.
58 + $option_key = 'ablocks_integration_blocks_migrated_v2';
59 + $done = (array) get_option( $option_key, [] );
60 + if ( ! array_diff( array_keys( $integrations ), $done ) ) {
61 + return;
62 + }
63 +
64 + $raw = get_option( ABLOCKS_BLOCKS_VISIBILITY_SETTINGS_NAME );
65 + $saved_blocks = $raw ? (array) json_decode( $raw, true ) : [];
66 + $block_names = array_keys( Settings\Blocks::get_default_data() );
67 + $changed = false;
68 +
69 + foreach ( $integrations as $prefix => $plugin_file ) {
70 + if ( in_array( $prefix, $done, true ) ) {
71 + continue;
72 + }
73 + $done[] = $prefix;
74 + $plugin_active = Helper::is_plugin_active( $plugin_file );
75 + $names = array_filter( $block_names, function ( $name ) use ( $prefix ) {
76 + return 0 === strpos( $name, $prefix . '-' );
77 + } );
78 + foreach ( $names as $name ) {
79 + if ( $plugin_active ) {
80 + // Preserve the user's choice when they have the companion
81 + // plugin. Missing keys mean the old "missing = enabled"
82 + // behavior, so write true to keep those blocks on.
83 + if ( ! array_key_exists( $name, $saved_blocks ) ) {
84 + $saved_blocks[ $name ] = true;
85 + $changed = true;
86 + }
87 + continue;
88 + }
89 + // Companion plugin not active → the blocks cannot render.
90 + // Force-disable, including any `true` left behind by the old
91 + // installer which saved on-by-default values into the option.
92 + if ( ! array_key_exists( $name, $saved_blocks ) || $saved_blocks[ $name ] ) {
93 + $saved_blocks[ $name ] = false;
94 + $changed = true;
95 + }
96 + }
97 + }
98 +
99 + if ( $changed ) {
100 + update_option( ABLOCKS_BLOCKS_VISIBILITY_SETTINGS_NAME, wp_json_encode( $saved_blocks ) );
101 + // Block classes read this global when they're constructed later in the request.
102 + $existing = isset( $GLOBALS['ablocks_blocks'] ) ? (array) $GLOBALS['ablocks_blocks'] : [];
103 + $GLOBALS['ablocks_blocks'] = (object) array_merge( $existing, $saved_blocks );
104 + }
105 + update_option( $option_key, $done );
106 + }
107 +
108 + /**
109 + * font-family declarations are now emitted as full stacks (quoted family +
110 + * metric fallback + generic) instead of a bare family name.
111 + *
112 + * Block CSS is cached in generated files and the global CSS variables live in
113 + * a transient, so both hold the old single-name output until something forces
114 + * a rebuild. Clear them once so existing pages pick up the new stacks without
115 + * anyone having to re-save every page.
116 + */
117 + public function migrate_font_stack() {
118 + if ( get_option( 'ablocks_font_stack_migrated' ) ) {
119 + return;
120 + }
121 +
122 + // Deleting generated files needs WP_Filesystem; keep that out of visitor
123 + // requests. The first admin page load after the update does the work.
124 + if ( ! is_admin() && ! ( defined( 'WP_CLI' ) && WP_CLI ) ) {
125 + return;
126 + }
127 +
128 + ( new \ABlocks\Classes\FileUpload() )->delete_files();
129 + delete_transient( 'ablocks_global_css_vars' );
130 + // Force a rebuild of the template/part/theme-builder font set, which did
131 + // not exist before this release.
132 + \ABlocks\Classes\FontCollector::flush_site_fonts();
133 +
134 + update_option( 'ablocks_font_stack_migrated', '1' );
27 135 }
28 136
29 137 public function migrate_1_6_3( $version ) {
30 138 if ( version_compare( $version, '1.6.3', '<=' ) ) {