block-supports
2 years ago
compat
2 years ago
experimental
2 years ago
README.md
2 years ago
block-editor-settings.php
2 years ago
blocks.php
2 years ago
class-wp-duotone-gutenberg.php
2 years ago
class-wp-theme-json-data-gutenberg.php
2 years ago
class-wp-theme-json-gutenberg.php
2 years ago
class-wp-theme-json-resolver-gutenberg.php
2 years ago
client-assets.php
2 years ago
demo.php
2 years ago
experiments-page.php
2 years ago
global-styles-and-settings.php
2 years ago
init.php
2 years ago
load.php
2 years ago
script-loader.php
2 years ago
theme-i18n.json
2 years ago
theme.json
2 years ago
upgrade.php
2 years ago
upgrade.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Upgrading Gutenberg's database. |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( '_GUTENBERG_VERSION_MIGRATION' ) ) { |
| 9 | // It's necessary to update this version every time a new migration is needed. |
| 10 | define( '_GUTENBERG_VERSION_MIGRATION', '9.8.0' ); |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * Migrate Gutenberg's database on upgrade. |
| 15 | * |
| 16 | * @access private |
| 17 | * @internal |
| 18 | */ |
| 19 | function _gutenberg_migrate_database() { |
| 20 | // The default value used here is the first version before migrations were added. |
| 21 | $gutenberg_installed_version = get_option( 'gutenberg_version_migration', '9.7.0' ); |
| 22 | |
| 23 | if ( _GUTENBERG_VERSION_MIGRATION !== $gutenberg_installed_version ) { |
| 24 | if ( version_compare( $gutenberg_installed_version, '9.8.0', '<' ) ) { |
| 25 | _gutenberg_migrate_remove_fse_drafts(); |
| 26 | } |
| 27 | |
| 28 | update_option( 'gutenberg_version_migration', _GUTENBERG_VERSION_MIGRATION ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Remove FSE auto drafts and associated terms. |
| 34 | * |
| 35 | * @access private |
| 36 | * @internal |
| 37 | */ |
| 38 | function _gutenberg_migrate_remove_fse_drafts() { |
| 39 | // Delete auto-draft templates and template parts. |
| 40 | $delete_query = new WP_Query( |
| 41 | array( |
| 42 | 'post_status' => array( 'auto-draft' ), |
| 43 | 'post_type' => array( 'wp_template', 'wp_template_part' ), |
| 44 | 'posts_per_page' => -1, |
| 45 | ) |
| 46 | ); |
| 47 | foreach ( $delete_query->posts as $post ) { |
| 48 | wp_delete_post( $post->ID, true ); |
| 49 | } |
| 50 | |
| 51 | // Delete _wp_file_based term. |
| 52 | $term = get_term_by( 'name', '_wp_file_based', 'wp_theme' ); |
| 53 | if ( $term ) { |
| 54 | wp_delete_term( $term->term_id, 'wp_theme' ); |
| 55 | } |
| 56 | |
| 57 | // Delete useless options. |
| 58 | delete_option( 'gutenberg_last_synchronize_theme_template_checks' ); |
| 59 | delete_option( 'gutenberg_last_synchronize_theme_template-part_checks' ); |
| 60 | } |
| 61 | |
| 62 | // Deletion of the `_wp_file_based` term (in _gutenberg_migrate_remove_fse_drafts) must happen |
| 63 | // after its taxonomy (`wp_theme`) is registered. This happens in `gutenberg_register_wp_theme_taxonomy`, |
| 64 | // which is hooked into `init` (default priority, i.e. 10). |
| 65 | add_action( 'init', '_gutenberg_migrate_database', 20 ); |
| 66 |