'Version'), false); $plugin_version = !empty($plugin_data['Version']) ? $plugin_data['Version'] : '1.0.0'; } // Enqueue styles wp_enqueue_style( 'adaire-blocks-migration', plugin_dir_url(__FILE__) . 'css/block-migration.css', array(), $plugin_version ); // Enqueue scripts wp_enqueue_script( 'adaire-blocks-migration', plugin_dir_url(__FILE__) . 'js/block-migration.js', array(), $plugin_version, true ); // Localize script with PHP data wp_localize_script( 'adaire-blocks-migration', 'adaireMigration', array( 'ajaxUrl' => 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'); /** * 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 fast queue-based system to find all posts, pages, and reusable block patterns that contain Adaire Blocks and re-save them with the current block structure. This is useful when you've made changes to block code that cause validation errors.

What this does:

⚠️ Important:

Note: This tool will process both posts/pages and reusable block patterns (wp_block) that contain Adaire Blocks.

'Unauthorized']); } $items_to_migrate = []; $posts_count = 0; $patterns_count = 0; // Get all posts and pages that might contain blocks $args = [ 'post_type' => ['post', 'page'], 'post_status' => ['publish', 'draft', 'pending', 'private'], 'posts_per_page' => -1, 'fields' => 'ids', ]; $all_posts = get_posts($args); $posts_checked = count($all_posts); // Filter posts that contain Adaire Blocks foreach ($all_posts as $post_id) { $content = get_post_field('post_content', $post_id); // Check if post contains any Adaire Blocks if (has_blocks($content)) { $blocks = parse_blocks($content); if (adaire_has_adaire_blocks($blocks)) { $post = get_post($post_id); $items_to_migrate[] = [ 'id' => $post_id, 'title' => $post->post_title, 'type' => 'post', ]; $posts_count++; } } } // Get all reusable blocks/patterns (wp_block post type) $pattern_args = [ 'post_type' => 'wp_block', 'post_status' => ['publish', 'draft', 'pending', 'private'], 'posts_per_page' => -1, 'fields' => 'ids', ]; $all_patterns = get_posts($pattern_args); $patterns_checked = count($all_patterns); // Filter patterns that contain Adaire Blocks foreach ($all_patterns as $pattern_id) { $content = get_post_field('post_content', $pattern_id); // Check if pattern contains any Adaire Blocks if (has_blocks($content)) { $blocks = parse_blocks($content); if (adaire_has_adaire_blocks($blocks)) { $pattern = get_post($pattern_id); $items_to_migrate[] = [ 'id' => $pattern_id, 'title' => $pattern->post_title ? $pattern->post_title : 'Untitled Pattern', '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'); /** * Check if blocks array contains any Adaire Blocks */ function adaire_has_adaire_blocks($blocks) { foreach ($blocks as $block) { // Check if it's an Adaire Block (starts with 'create-block/') if (isset($block['blockName']) && strpos($block['blockName'], 'create-block/') === 0) { return true; } // Check inner blocks recursively if (!empty($block['innerBlocks'])) { if (adaire_has_adaire_blocks($block['innerBlocks'])) { return true; } } } return false; } // Note: Migration now happens via JavaScript in hidden iframes // Each post is loaded in the editor context where auto-recovery runs // This ensures blocks are actually recovered using the current save.js