settings->exists() ) { $this->settings->save( $this->defaults->first_run() ); } $this->create_tables(); $this->tag_existing_content(); } public function maybe_upgrade(): void { if ( get_option( self::DB_VERSION_OPTION ) !== self::DB_VERSION ) { $this->activate(); return; } // A table lost after a migration or a restore: without it the site's post // lists come back empty. Checked at most once an hour, recreated if missing. if ( false === get_transient( 'blocklingo_tables_ok' ) ) { if ( ! $this->tables_exist() ) { $this->create_tables(); } set_transient( 'blocklingo_tables_ok', 1, HOUR_IN_SECONDS ); } } private function tables_exist(): bool { global $wpdb; foreach ( array( $this->schema->translations(), $this->schema->strings(), $this->schema->string_translations() ) as $table ) { if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ) ) !== $table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- schema check, once an hour. return false; } } return true; } public function create_tables(): void { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; foreach ( $this->schema->statements() as $sql ) { dbDelta( $sql ); } update_option( self::DB_VERSION_OPTION, self::DB_VERSION ); } /** Existing posts of the translatable types become the default language. */ public function tag_existing_content(): void { $settings = $this->settings->get(); $this->translations->tag_untagged_posts( $settings->post_types(), $settings->default_code() ); } }