admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('adaire_migration'), 'postUrl' => admin_url('post.php'), ]); } add_action('admin_enqueue_scripts', 'adaire_blocks_enqueue_migration_assets'); /** * Enqueue the editor-side receiver script inside the hidden iframe. * * Only loaded when ?adaire_auto_migrate=1 is in the URL so it adds zero * overhead to normal editor sessions. */ function adaire_blocks_enqueue_migration_editor_script() { if ( empty( $_GET['adaire_auto_migrate'] ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } $version = defined('ADAIRE_BLOCKS_VERSION') ? ADAIRE_BLOCKS_VERSION : '1.0.0'; wp_enqueue_script( 'adaire-blocks-migration-editor', plugin_dir_url(__FILE__) . 'js/block-migration-editor.js', ['wp-data', 'wp-blocks', 'wp-block-editor', 'wp-editor'], $version, true ); } add_action('enqueue_block_editor_assets', 'adaire_blocks_enqueue_migration_editor_script'); /** * Migration page HTML */ function adaire_blocks_migration_page() { if (!current_user_can('manage_options')) { wp_die('Unauthorized access'); } ?>

Adaire Blocks Migration Tool

Update All Blocks (Queue-Based Migration)

This tool uses a queue-based system to find all posts, pages, custom post types, and reusable block patterns that contain Adaire Blocks and re-save them with the current block structure. Use this after updating the plugin to fix block validation errors.

What this does:

⚠️ Important:

Note: Scans all public post types that support the block editor, plus reusable block patterns (wp_block).

'Unauthorized']); } // Collect all public post types that use the block editor. $scannable_types = []; foreach (get_post_types(['public' => true], 'objects') as $type) { if ($type->name === 'attachment' || $type->name === 'wp_block') { continue; } if (post_type_supports($type->name, 'editor')) { $scannable_types[] = $type->name; } } // Allow site owners to narrow or extend the list. $scannable_types = apply_filters('adaire_migration_post_types', $scannable_types); $items_to_migrate = []; $posts_count = 0; $patterns_count = 0; $posts_checked = 0; $patterns_checked = 0; // --- posts / pages / custom post types --- if (!empty($scannable_types)) { $all_posts = get_posts([ 'post_type' => $scannable_types, 'post_status' => ['publish', 'draft', 'pending', 'private'], 'posts_per_page' => -1, 'fields' => 'all', 'no_found_rows' => true, ]); $posts_checked = count($all_posts); foreach ($all_posts as $post) { if (has_blocks($post->post_content) && adaire_has_adaire_blocks(parse_blocks($post->post_content))) { $items_to_migrate[] = [ 'id' => $post->ID, 'title' => $post->post_title ?: "(no title — ID {$post->ID})", 'type' => 'post', ]; $posts_count++; } } } // --- reusable block patterns (wp_block) --- $all_patterns = get_posts([ 'post_type' => 'wp_block', 'post_status' => ['publish', 'draft', 'pending', 'private'], 'posts_per_page' => -1, 'fields' => 'all', 'no_found_rows' => true, ]); $patterns_checked = count($all_patterns); foreach ($all_patterns as $pattern) { if (has_blocks($pattern->post_content) && adaire_has_adaire_blocks(parse_blocks($pattern->post_content))) { $items_to_migrate[] = [ 'id' => $pattern->ID, 'title' => $pattern->post_title ?: "Untitled Pattern (ID {$pattern->ID})", 'type' => 'pattern', ]; $patterns_count++; } } wp_send_json_success([ 'items' => $items_to_migrate, 'posts_count' => $posts_count, 'patterns_count' => $patterns_count, 'posts_checked' => $posts_checked, 'patterns_checked' => $patterns_checked, ]); } add_action('wp_ajax_adaire_get_posts_to_migrate', 'adaire_get_posts_to_migrate'); /** * Recursively check whether a parsed blocks array contains at least one * Adaire Blocks block (namespace create-block/). */ function adaire_has_adaire_blocks($blocks) { foreach ($blocks as $block) { if (isset($block['blockName']) && strpos($block['blockName'], 'create-block/') === 0) { return true; } if (!empty($block['innerBlocks']) && adaire_has_adaire_blocks($block['innerBlocks'])) { return true; } } return false; }