table_builder_block_migrate_old_blocks(); set_transient( 'table_builder_block_migrate', TABLE_BUILDER_BLOCK_PLUGIN_VERSION ); } } } } } /** * Rewrites legacy "gutenkit/table-builder*" block markup to the current * "tablebuilder/table-builder*" namespace across all matching posts. * * @return void */ public function table_builder_block_migrate_old_blocks() { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-off migration run at most once per plugin upgrade (see migrate_old_blocks() above), not a per-request query; caching would add complexity for no benefit here. $posts = $wpdb->get_results( " SELECT ID, post_content FROM {$wpdb->posts} WHERE post_type IN ('post', 'page', 'your_custom_post_type') AND post_status IN ('publish', 'draft', 'pending', 'private') AND post_content LIKE '%gutenkit/%' " ); foreach ( $posts as $post ) { $updated_content = str_replace( array( 'wp:gutenkit/table-builder', 'wp:gutenkit/table-builder-row', 'wp:gutenkit/table-builder-item', 'gutenkit/table-builder', 'gutenkit/table-builder-row', 'gutenkit/table-builder-item', ), array( 'wp:tablebuilder/table-builder', 'wp:tablebuilder/table-builder-row', 'wp:tablebuilder/table-builder-item', 'tablebuilder/table-builder', 'tablebuilder/table-builder-row', 'tablebuilder/table-builder-item', ), $post->post_content ); if ( $updated_content !== $post->post_content ) { wp_update_post( array( 'ID' => $post->ID, 'post_content' => $updated_content, ) ); } } } }