Edit: bootstrap.php
<?php /** * Divi Packager — Theme Installer Bootstrap. * * Loaded from the child theme's functions.php when diet-installer/ is present. * Provides the import wizard and self-deletes the diet-installer/ directory * after a successful import, leaving the theme clean. * * Placeholders replaced at build time by DIET_Package_Builder: * Divi Construction Theme Installer — display name, e.g. "Nova Theme Installer" * diviconstructiontheme — package slug, e.g. "nova-theme" * 4.2.7 — Divi Packager version, e.g. "3.0.8" */ if ( ! defined( 'ABSPATH' ) ) { exit; } // Guard against double-loading (e.g. if functions.php is included twice). if ( defined( 'DIET_INSTALLER_VERSION' ) ) { return; } define( 'DIET_INSTALLER_VERSION', '4.2.7' ); define( 'DIET_INSTALLER_SLUG', 'diviconstructiontheme' ); define( 'DIET_INSTALLER_DIR', get_stylesheet_directory() . '/diet-installer/' ); define( 'DIET_INSTALLER_URL', get_stylesheet_directory_uri() . '/diet-installer/' ); define( 'DIET_INSTALLER_DATA_DIR', get_stylesheet_directory() . '/diet-installer/data/' ); // Load core installer classes. require_once DIET_INSTALLER_DIR . 'includes/class-diet-installer-admin.php'; require_once DIET_INSTALLER_DIR . 'includes/class-diet-importer.php'; // Load all individual importer classes. $diet_importer_files = glob( DIET_INSTALLER_DIR . 'includes/importers/*.php' ); if ( $diet_importer_files ) { foreach ( $diet_importer_files as $diet_file ) { require_once $diet_file; } } unset( $diet_importer_files, $diet_file ); if ( ! function_exists( 'diet_installer_replace_urls' ) ) { /** * Replace URLs in a string, handling protocol (http/https) and JSON * escaped-slash variants so that content stored by Divi 4 shortcodes, * Divi 5 block JSON, or plain HTML is always remapped correctly. * * @param string $content The string to process. * @param string $old_url The old site or attachment URL (no trailing slash). * @param string $new_url The replacement URL (no trailing slash). * @param string[] $url_map Optional map of old attachment URL => new URL. * @return string */ function diet_installer_replace_urls( $content, $old_url, $new_url, $url_map = array() ) { if ( ! is_string( $content ) ) { return $content; } $pairs = array(); if ( $old_url && $old_url !== $new_url ) { $pairs[ $old_url ] = $new_url; } foreach ( $url_map as $o => $n ) { if ( $o !== $n ) { $pairs[ $o ] = $n; } } foreach ( $pairs as $old => $new ) { $content = str_replace( $old, $new, $content ); // Protocol variant (http ↔ https). if ( strncmp( $old, 'https://', 8 ) === 0 ) { $old_alt = 'http://' . substr( $old, 8 ); $new_alt = ( strncmp( $new, 'https://', 8 ) === 0 ) ? 'http://' . substr( $new, 8 ) : $new; } elseif ( strncmp( $old, 'http://', 7 ) === 0 ) { $old_alt = 'https://' . substr( $old, 7 ); $new_alt = ( strncmp( $new, 'http://', 7 ) === 0 ) ? 'https://' . substr( $new, 7 ) : $new; } else { $old_alt = $old; $new_alt = $new; } if ( $old_alt !== $old ) { $content = str_replace( $old_alt, $new_alt, $content ); } // JSON escaped-slash variants (Divi may store URLs with \/ in JSON). $old_esc = str_replace( '/', '\/', $old ); $new_esc = str_replace( '/', '\/', $new ); $old_alt_esc = str_replace( '/', '\/', $old_alt ); $new_alt_esc = str_replace( '/', '\/', $new_alt ); if ( $old_esc !== $old ) { $content = str_replace( $old_esc, $new_esc, $content ); } if ( $old_alt_esc !== $old_alt ) { $content = str_replace( $old_alt_esc, $new_alt_esc, $content ); } } return $content; } } /** * WP-Cron handler: generate thumbnails for a single attachment. * Scheduled by DIET_Media_Importer after all media batches complete. * * @param int $attachment_id */ function diet_generate_thumbnail_handler( $attachment_id ) { require_once ABSPATH . 'wp-admin/includes/image.php'; $file = get_attached_file( $attachment_id ); if ( $file && file_exists( $file ) ) { wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); } } add_action( 'diet_generate_thumbnail', 'diet_generate_thumbnail_handler' ); // Prevent third-party activation redirects (e.g. WooCommerce setup wizard) from // hijacking our AJAX import responses. The filter runs before admin_init fires, // so it blocks wp_redirect() calls made by newly-activated plugins during that hook. // Scoped strictly to our own AJAX action — no effect on any other request. if ( wp_doing_ajax() && isset( $_POST['action'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing && 'diet_import_step' === $_POST['action'] // phpcs:ignore WordPress.Security.NonceVerification.Missing ) { add_filter( 'wp_redirect', '__return_false', PHP_INT_MAX ); } // Boot the installer admin UI directly. // functions.php is loaded AFTER plugins_loaded has already fired, // so we cannot use that hook — instantiate immediately instead. if ( is_admin() ) { new DIET_Installer_Admin(); } /** * Show a dismissible admin notice when the theme is first activated * and import has not yet been run. */ function diet_theme_installer_notice() { if ( get_option( 'diet_installer_completed' ) === get_stylesheet() ) { return; } $url = admin_url( 'admin.php?page=diet-installer' ); echo '<div class="notice notice-info"><p>'; printf( wp_kses( /* translators: %s: URL to the installer page */ __( '<strong>Divi Construction Theme Installer</strong> — Content ready to import. <a href="%s">Start Import →</a>', 'diet-installer' ), array( 'strong' => array(), 'a' => array( 'href' => array() ), ) ), esc_url( $url ) ); echo '</p></div>'; } add_action( 'admin_notices', 'diet_theme_installer_notice' ); // The diet-installer/ folder is no longer auto-deleted after import. // Use the "Cleanup" button in the Theme Installer admin page to remove it manually // once you no longer need the Restore functionality. /** * Auto-migrate Theme Builder _et_template meta ordering. * * Identical to the plugin installer migration: ensures the default TB * template is first in _et_template meta so Divi's array_filter/array_pick * pipeline finds it at index 0 and renders header/footer correctly. */ function diet_installer_maybe_fix_tb_settings() { $fixed = get_option( 'diet_installer_tb_fixed', '' ); if ( version_compare( $fixed, DIET_INSTALLER_VERSION, '>=' ) ) { return; } $tb_post_id = 0; if ( function_exists( 'et_theme_builder_get_theme_builder_post_id' ) ) { $tb_post_id = (int) et_theme_builder_get_theme_builder_post_id( true, false ); } if ( ! $tb_post_id ) { global $wpdb; $tb_post_id = (int) $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'et_theme_builder' AND post_status = 'publish' ORDER BY ID DESC LIMIT 1" ); } if ( ! $tb_post_id ) { update_option( 'diet_installer_tb_fixed', DIET_INSTALLER_VERSION ); return; } $template_ids = get_post_meta( $tb_post_id, '_et_template', false ); if ( is_array( $template_ids ) && count( $template_ids ) > 1 ) { $defaults = array(); $non_defaults = array(); foreach ( $template_ids as $tid ) { $tid = (int) $tid; if ( get_post_meta( $tid, '_et_default', true ) === '1' ) { $defaults[] = $tid; } else { $non_defaults[] = $tid; } } $sorted = array_merge( $defaults, $non_defaults ); if ( $sorted !== array_map( 'intval', $template_ids ) ) { delete_post_meta( $tb_post_id, '_et_template' ); foreach ( $sorted as $tid ) { add_post_meta( $tb_post_id, '_et_template', $tid ); } } } update_option( 'diet_installer_tb_fixed', DIET_INSTALLER_VERSION ); } add_action( 'admin_init', 'diet_installer_maybe_fix_tb_settings' );
Save
Back