in Name: MrQ Auto Builder * Description: Automatically builds the 7 pillars and 30 L3 pages with Gutenberg blocks and imports images. * Version: 1.0 * Author: Antigravity */ if (!defined('ABSPATH')) exit; add_action('init', 'mrq_auto_build_trigger'); function mrq_auto_build_trigger() { if (isset($_GET['mrq_build']) && $_GET['mrq_build'] == 'start') { if (!current_user_can('manage_options')) { wp_die('Unauthorized'); } mrq_execute_build(); wp_die('Build Complete!'); } } function mrq_execute_build() { $data_file = plugin_dir_path(__FILE__) . 'pages_data.json'; if (!file_exists($data_file)) return; $all_pages = json_decode(file_get_contents($data_file), true); function mrq_upload_image($filename) { $filepath = plugin_dir_path(__FILE__) . 'assets/' . $filename; if (!file_exists($filepath)) return ['id' => 0, 'url' => 'https://via.placeholder.com/1280x720.png?text=Missing']; $wp_upload_dir = wp_upload_dir(); $upload_path = $wp_upload_dir['path'] . '/' . $filename; copy($filepath, $upload_path); $filetype = wp_check_filetype(basename($upload_path), null); $attachment = array( 'guid' => $wp_upload_dir['url'] . '/' . basename($upload_path), 'post_mime_type' => $filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($upload_path)), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment($attachment, $upload_path); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata($attach_id, $upload_path); wp_update_attachment_metadata($attach_id, $attach_data); return ['id' => $attach_id, 'url' => wp_get_attachment_url($attach_id)]; } $image_cache = []; $pillar_map = []; // Ensure pillars exist $pillars_needed = ['tecnologia', 'ciencia', 'arte', 'comunidad', 'audiovisual', 'cine-y-tv', 'esculturas-roboticas', 'proyectos']; foreach ($pillars_needed as $slug) { $page = get_page_by_path($slug); if ($page) { $pillar_map[$slug] = $page->ID; } else { $pid = wp_insert_post([ 'post_type' => 'page', 'post_title' => ucfirst(str_replace('-', ' ', $slug)), 'post_name' => $slug, 'post_status' => 'publish', 'post_content' => '
Pillar Content
' ]); $pillar_map[$slug] = $pid; } } foreach ($all_pages as $page_slug => $data) { // Hero Image $h_img = $data['hero_img']; if (!isset($image_cache[$h_img])) $image_cache[$h_img] = mrq_upload_image($h_img); $hero_info = $image_cache[$h_img]; $hero_id = $hero_info['id']; $hero_url = $hero_info['url']; $title = $data['hero_title']; $content = "$p_tag
$p_desc