PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | lib/upgrade.php +79 -14 23.2.2 → trunk View file →
@@ -6,9 +6,9 @@
6 6 */
7 7
8 8 if ( ! defined( '_GUTENBERG_VERSION_MIGRATION' ) ) {
9 9 // It's necessary to update this version every time a new migration is needed.
10 - define( '_GUTENBERG_VERSION_MIGRATION', '22.8.0' );
10 + define( '_GUTENBERG_VERSION_MIGRATION', '23.9.0' );
11 11 }
12 12
13 13 /**
14 14 * Migrate Gutenberg's database on upgrade.
@@ -24,12 +24,16 @@
24 24 if ( version_compare( $gutenberg_installed_version, '9.8.0', '<' ) ) {
25 25 _gutenberg_migrate_remove_fse_drafts();
26 26 }
27 27
28 - if ( version_compare( $gutenberg_installed_version, '22.8.0', '<' ) ) {
29 - _gutenberg_migrate_enable_real_time_collaboration();
28 + if ( version_compare( $gutenberg_installed_version, '23.8.0', '<' ) ) {
29 + _gutenberg_migrate_remove_legacy_collaboration_options();
30 30 }
31 31
32 + if ( version_compare( $gutenberg_installed_version, '23.9.0', '<' ) ) {
33 + _gutenberg_migrate_active_templates();
34 + }
35 +
32 36 update_option( 'gutenberg_version_migration', _GUTENBERG_VERSION_MIGRATION );
33 37 }
34 38 }
35 39
@@ -63,24 +67,85 @@
63 67 delete_option( 'gutenberg_last_synchronize_theme_template-part_checks' );
64 68 }
65 69
66 70 /**
67 - * Update RTC option name.
71 + * Removes collaboration options replaced by the Real-Time Collaboration experiment.
68 72 *
69 - * @since 22.8.0
73 + * The previous values are intentionally not migrated to the experiment. Real-time
74 + * collaboration is now opt-in, so existing sites must explicitly enable the
75 + * experiment instead of being opted in by a legacy setting.
76 + *
77 + * @since 23.8.0
70 78 */
71 -function _gutenberg_migrate_enable_real_time_collaboration() {
72 - $value1 = get_option( 'enable_real_time_collaboration', '1' );
73 - $value2 = get_option( 'wp_enable_real_time_collaboration', '1' );
79 +function _gutenberg_migrate_remove_legacy_collaboration_options() {
80 + delete_option( 'enable_real_time_collaboration' );
81 + delete_option( 'wp_enable_real_time_collaboration' );
82 + delete_option( 'wp_collaboration_enabled' );
83 +}
74 84
75 - // RTC is enabled by default in the plugin, so only set the value if it was
76 - // previously disabled. Otherwise rely on the default value.
77 - if ( ! $value1 || ! $value2 ) {
78 - update_option( 'wp_collaboration_enabled', '0' );
85 +/**
86 + * Migrates templates created by the removed template activation experiment.
87 + *
88 + * The experiment allowed multiple templates with the same slug, with the
89 + * `active_templates` option deciding which one renders. Without the
90 + * experiment, WordPress expects at most one template per slug, so an inactive
91 + * duplicate could take over rendering. Move every template the experiment did
92 + * not treat as active out of the template hierarchy by renaming it to a
93 + * `custom-{slug}` slug; it remains available as a custom template.
94 + *
95 + * Only runs on sites where the `active_templates` option exists, which means
96 + * the experiment was enabled at some point.
97 + *
98 + * @since 23.9.0
99 + *
100 + * @access private
101 + * @internal
102 + */
103 +function _gutenberg_migrate_active_templates() {
104 + $active_templates = get_option( 'active_templates' );
105 +
106 + if ( ! is_array( $active_templates ) ) {
107 + // The template activation experiment was never enabled on this site.
108 + return;
79 109 }
80 110
81 - delete_option( 'enable_real_time_collaboration' );
82 - delete_option( 'wp_enable_real_time_collaboration' );
111 + $template_query = new WP_Query(
112 + array(
113 + 'post_type' => 'wp_template',
114 + 'post_status' => array( 'publish', 'draft', 'auto-draft' ),
115 + 'posts_per_page' => -1,
116 + 'no_found_rows' => true,
117 + )
118 + );
119 +
120 + foreach ( $template_query->posts as $post ) {
121 + $slug = $post->post_name;
122 +
123 + // The active template keeps its slug, so it continues to override the
124 + // theme's template as it did under the experiment.
125 + if ( isset( $active_templates[ $slug ] ) && absint( $active_templates[ $slug ] ) === $post->ID ) {
126 + continue;
127 + }
128 +
129 + $template = _build_block_template_result_from_post( $post );
130 +
131 + // Custom templates never needed activation; leave them untouched.
132 + if ( is_wp_error( $template ) || $template->is_custom ) {
133 + continue;
134 + }
135 +
136 + wp_update_post(
137 + array(
138 + 'ID' => $post->ID,
139 + 'post_name' => 'custom-' . $slug,
140 + )
141 + );
142 + // The template is a plain custom template from now on.
143 + delete_post_meta( $post->ID, 'is_wp_suggestion' );
144 + delete_post_meta( $post->ID, 'is_inactive_by_default' );
145 + }
146 +
147 + delete_option( 'active_templates' );
83 148 }
84 149
85 150 // Deletion of the `_wp_file_based` term (in _gutenberg_migrate_remove_fse_drafts) must happen
86 151 // after its taxonomy (`wp_theme`) is registered. This happens in `gutenberg_register_wp_theme_taxonomy`,