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 = "
\"$title\"

$title

"; foreach ($data['projects'] as $i => $proj) { $p_img = $proj['img']; if (!isset($image_cache[$p_img])) $image_cache[$p_img] = mrq_upload_image($p_img); $p_info = $image_cache[$p_img]; $p_id = $p_info['id']; $p_url = $p_info['url']; $media_pos = ($i % 2 !== 0) ? "right" : "left"; $p_tag = $proj['tag']; $p_title = $proj['title']; $p_desc = str_replace('\\n', '
', $proj['desc']); $p_btn = $proj['btn']; $content .= "
\"$p_title\"

$p_tag

$p_title

$p_desc

"; } $content .= "
"; $pillar_slug = str_replace('.html', '', $data['pillar_url']); $parent_id = isset($pillar_map[$pillar_slug]) ? $pillar_map[$pillar_slug] : 0; $existing = get_page_by_path($page_slug); if ($existing) { wp_update_post([ 'ID' => $existing->ID, 'post_content' => $content, 'post_parent' => $parent_id, // Assign Kadence transparent header and fullwidth settings natively via post meta 'meta_input' => [ '_kadence_transparent_header' => 'enable', '_kadence_page_title' => 'disable', '_kadence_page_layout' => 'fullwidth', '_kadence_content_vertical_spacing' => 'disable' ] ]); } else { wp_insert_post([ 'post_type' => 'page', 'post_title' => $data['title'], 'post_name' => $page_slug, 'post_status' => 'publish', 'post_content' => $content, 'post_parent' => $parent_id, 'meta_input' => [ '_kadence_transparent_header' => 'enable', '_kadence_page_title' => 'disable', '_kadence_page_layout' => 'fullwidth', '_kadence_content_vertical_spacing' => 'disable' ] ]); } } }