get_results( $wpdb->prepare( 'SELECT option_name, option_value, autoload FROM %i WHERE option_name LIKE %s', $wpdb->options, $wpdb->esc_like( self::OLD ) . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time migration foreach ( (array) $rows as $row ) { $new = self::new_name( $row->option_name, self::OLD, self::NEW_PREFIX ); // Copy the stored (serialized) value as is. $wpdb->query( $wpdb->prepare( 'INSERT IGNORE INTO %i (option_name, option_value, autoload) VALUES (%s, %s, %s)', $wpdb->options, $new, $row->option_value, $row->autoload ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time migration } wp_cache_delete( 'alloptions', 'options' ); wp_cache_delete( 'notoptions', 'options' ); } private static function copy_tables() { global $wpdb; $old_prefix = $wpdb->prefix . self::OLD; $tables = $wpdb->get_col( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $old_prefix ) . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time migration foreach ( (array) $tables as $old_table ) { $new_table = self::new_name( $old_table, $old_prefix, $wpdb->prefix . self::NEW_PREFIX ); if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $new_table ) ) ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time migration continue; } $wpdb->query( $wpdb->prepare( 'CREATE TABLE %i LIKE %i', $new_table, $old_table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange -- one-time migration $wpdb->query( $wpdb->prepare( 'INSERT INTO %i SELECT * FROM %i', $new_table, $old_table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time migration } } private static function copy_meta() { global $wpdb; $meta_tables = array( array( $wpdb->postmeta, 'post_id' ), array( $wpdb->termmeta, 'term_id' ), array( $wpdb->usermeta, 'user_id' ), ); foreach ( $meta_tables as $meta ) { list( $table, $object_column ) = $meta; foreach ( array( '_' . self::OLD => '_' . self::NEW_PREFIX, self::OLD => self::NEW_PREFIX ) as $old_key_prefix => $new_key_prefix ) { $wpdb->query( $wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time migration 'INSERT INTO %i (%i, meta_key, meta_value) SELECT %i, CONCAT(%s, SUBSTRING(meta_key, %d)), meta_value FROM %i WHERE meta_key LIKE %s', $table, $object_column, $object_column, $new_key_prefix, strlen( $old_key_prefix ) + 1, $table, $wpdb->esc_like( $old_key_prefix ) . '%' ) ); } } // Dismissed-notice flags are stored as "{notice id}_dismiss_notification" user meta; ids start with the prefix. wp_cache_flush_group( 'post_meta' ); wp_cache_flush_group( 'term_meta' ); wp_cache_flush_group( 'user_meta' ); } private static function clear_old_cron_events() { foreach ( (array) _get_cron_array() as $events ) { foreach ( array_keys( (array) $events ) as $hook ) { if ( strpos( $hook, self::OLD ) === 0 ) { wp_clear_scheduled_hook( $hook ); } } } } }