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 '
'; printf( wp_kses( /* translators: %s: URL to the installer page */ __( 'Divi Construction Theme Installer — Content ready to import. Start Import →', 'diet-installer' ), array( 'strong' => array(), 'a' => array( 'href' => array() ), ) ), esc_url( $url ) ); echo '