get_error_message() );
// Set notice as an array so the UI can render it as an ERROR (red), not success (green)
set_transient(
'bongoto_shop_demo_notice',
array(
'type' => 'error',
'message' => __( 'Invalid purchase code. Please try again with the correct code: ', 'bongoto-shop' ) . $resp->get_error_message(),
),
180
);
wp_safe_redirect( $redirect_to );
exit;
}
if ( isset( $resp['status'] ) && 'active' === $resp['status'] ) {
update_option( 'bongoto_premium_active', true );
update_option( 'bongoto_premium_last_check', time() );
update_option( 'bongoto_premium_last_siteurl', rtrim( home_url(), '/' ) );
update_option( 'bongoto_premium_last_error', '' );
if ( function_exists( 'bongoto_shop_store_license_meta' ) ) {
bongoto_shop_store_license_meta( $resp );
}
if ( isset( $resp['features'] ) && is_array( $resp['features'] ) ) {
update_option( 'bongoto_premium_features', $resp['features'] );
}
set_transient( 'bongoto_shop_demo_notice', __( 'Success! Purchase code verified for this domain.', 'bongoto-shop' ), 120 );
// If import was already completed, hide the Quick Setup notice everywhere.
if ( (bool) get_option( 'bongoto_shop_import_completed', false ) ) {
delete_transient( 'bongoto_shop_show_setup_notice' );
}
wp_safe_redirect( $redirect_to );
exit;}
update_option( 'bongoto_premium_active', false );
update_option( 'bongoto_premium_last_error', __( 'Purchase code is not active.', 'bongoto-shop' ) );
update_option( 'bongoto_premium_last_check', time() );
update_option( 'bongoto_premium_last_siteurl', rtrim( home_url(), '/' ) );
update_option( 'bongoto_premium_last_siteurl', rtrim( home_url(), '/' ) );
if ( is_array( $resp ) && function_exists( 'bongoto_shop_store_license_meta' ) ) {
bongoto_shop_store_license_meta( $resp );
}
set_transient( 'bongoto_shop_demo_notice', __( 'Purchase code could not be verified. Please try again with the correct code.', 'bongoto-shop' ), 180 );
wp_safe_redirect( $redirect_to );
exit;
});
/**
* Validate the saved purchase code on demand.
*/
add_action( 'admin_post_bongoto_shop_validate_license', function() {
if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Forbidden' ); }
check_admin_referer( 'bongoto_shop_validate_license' );
$purchase_key = (string) get_option( 'bongoto_purchase_code', '' );
if ( '' === trim( $purchase_key ) ) {
update_option( 'bongoto_premium_active', false );
update_option( 'bongoto_premium_last_error', __( 'No purchase code found.', 'bongoto-shop' ) );
set_transient( 'bongoto_shop_demo_notice', __( 'No purchase code found.', 'bongoto-shop' ), 160 );
// Redirect back to the registered Purchase Code admin page.
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop' ) );
exit;
}
$resp = function_exists( 'bongoto_shop_validate_purchase_code' )
? bongoto_shop_validate_purchase_code( $purchase_key )
: bongoto_shop_verify_purchase_code( $purchase_key );
if ( is_wp_error( $resp ) ) {
update_option( 'bongoto_premium_last_error', $resp->get_error_message() );
set_transient( 'bongoto_shop_demo_notice', __( 'Verification failed: ', 'bongoto-shop' ) . $resp->get_error_message(), 180 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop' ) );
exit;
}
$status = isset( $resp['status'] ) ? (string) $resp['status'] : '';
// Consider these statuses as "valid/verified" responses (even if not active on this site).
// Truly invalid codes should return WP_Error from the remote endpoint.
$known_statuses = [ 'active', 'inactive', 'expired', 'over_limit', 'revoked' ];
$is_known = in_array( $status, $known_statuses, true );
update_option( 'bongoto_premium_active', ( 'active' === $status ) );
update_option( 'bongoto_premium_last_check', time() );
update_option( 'bongoto_premium_last_siteurl', rtrim( home_url(), '/' ) );
// If license becomes active and demo import is not done yet, keep showing the Quick Setup notice.
if ( 'active' === $status ) {
$import_done = (bool) get_option( 'bongoto_shop_import_completed', false ) || (bool) get_option( 'bongoto_demo_import_completed', false );
if ( ! $import_done ) {
set_transient( 'bongoto_shop_show_setup_notice', 1, 30 * DAY_IN_SECONDS );
}
}
// Store meta whenever we got a structured response.
if ( $is_known && is_array( $resp ) && function_exists( 'bongoto_shop_store_license_meta' ) ) {
bongoto_shop_store_license_meta( $resp );
}
// Build a user-friendly notice + last_error.
$notice = '';
$last_error = '';
if ( 'active' === $status ) {
$notice = __( 'Success! Purchase code is verified and active on this site.', 'bongoto-shop' );
} elseif ( 'inactive' === $status ) {
$notice = __( 'Purchase code is valid, but it is not active on this site. Click "Verify Purchase Code" to activate it.', 'bongoto-shop' );
$last_error = __( 'Purchase code is not active on this site.', 'bongoto-shop' );
} elseif ( 'expired' === $status ) {
$notice = __( 'License verified, but it has expired.', 'bongoto-shop' );
$last_error = __( 'License expired.', 'bongoto-shop' );
} elseif ( 'over_limit' === $status ) {
$notice = __( 'License verified, but you have reached the domain limit.', 'bongoto-shop' );
$last_error = __( 'Domain limit reached.', 'bongoto-shop' );
} elseif ( 'revoked' === $status ) {
$notice = __( 'License verified, but it has been revoked.', 'bongoto-shop' );
$last_error = __( 'License revoked.', 'bongoto-shop' );
} else {
// Unknown response shape; treat as failure.
$notice = __( 'Purchase code could not be verified. Please try again with the correct code.', 'bongoto-shop' );
$last_error = __( 'Purchase code verification failed.', 'bongoto-shop' );
}
update_option( 'bongoto_premium_last_error', $last_error );
set_transient( 'bongoto_shop_demo_notice', $notice, 220 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop' ) );
exit;
} );
/**
* Deactivate purchase code (local). Optionally calls server if a deactivate endpoint is configured.
*/
add_action( 'admin_post_bongoto_shop_deactivate_license', function() {
if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Forbidden' ); }
check_admin_referer( 'bongoto_shop_deactivate_license' );
$purchase_key = (string) get_option( 'bongoto_purchase_code', '' );
if ( function_exists( 'bongoto_shop_remote_deactivate_purchase_code' ) ) {
$r = bongoto_shop_remote_deactivate_purchase_code( $purchase_key );
if ( is_wp_error( $r ) ) {
// Still deactivate locally.
set_transient( 'bongoto_shop_demo_notice', __( 'Deactivated locally. Server deactivation failed: ', 'bongoto-shop' ) . $r->get_error_message(), 220 );
}
}
update_option( 'bongoto_premium_active', false );
delete_option( 'bongoto_premium_features' );
delete_option( 'bongoto_license_meta' );
update_option( 'bongoto_premium_last_check', time() );
// If license becomes active and demo import is not done yet, keep showing the Quick Setup notice.
if ( 'active' === $status ) {
$import_done = (bool) get_option( 'bongoto_shop_import_completed', false ) || (bool) get_option( 'bongoto_demo_import_completed', false );
if ( ! $import_done ) {
set_transient( 'bongoto_shop_show_setup_notice', 1, 30 * DAY_IN_SECONDS );
}
}
if ( ! get_transient( 'bongoto_shop_demo_notice' ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Deactivated for this site.', 'bongoto-shop' ), 180 );
}
$ref = wp_get_referer();
wp_safe_redirect( $ref ? $ref : admin_url( 'admin.php?page=bongoto-shop' ) );
exit;
} );
/**
* Start Import button: requires premium active.
*/
add_action( 'admin_post_bongoto_shop_go_import', function() {
if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Forbidden' ); }
check_admin_referer( 'bongoto_shop_go_import' );
$active = function_exists( 'bongoto_is_premium_active' )
? bongoto_is_premium_active()
: (bool) get_option( 'bongoto_premium_active', false );
if ( ! $active ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Please verify your purchase code first.', 'bongoto-shop' ), 120 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
});
/**
* Fetch manifest and cache.
*/
add_action( 'admin_post_bongoto_shop_fetch_manifest', function() {
if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Forbidden' ); }
check_admin_referer( 'bongoto_shop_fetch_manifest' );
$active = function_exists( 'bongoto_is_premium_active' )
? bongoto_is_premium_active()
: (bool) get_option( 'bongoto_premium_active', false );
if ( ! $active ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Please verify your purchase code first.', 'bongoto-shop' ), 120 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$manifest = bongoto_shop_fetch_manifest();
if ( ! is_wp_error( $manifest ) && is_array( $manifest ) ) {
set_transient( 'bongoto_shop_last_manifest', $manifest, 12 * HOUR_IN_SECONDS );
set_transient( 'bongoto_shop_demo_notice', __( 'Demo list refreshed.', 'bongoto-shop' ), 120 );
} else {
set_transient( 'bongoto_shop_demo_notice', __( 'Failed to fetch manifest.', 'bongoto-shop' ), 180 );
}
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
});
/**
* Run import: downloads selected items, creates home page, applies preset.
*/
add_action( 'admin_post_bongoto_shop_run_import', function() {
if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Forbidden' ); }
check_admin_referer( 'bongoto_shop_run_import' );
$active = function_exists( 'bongoto_is_premium_active' )
? bongoto_is_premium_active()
: (bool) get_option( 'bongoto_premium_active', false );
if ( ! $active ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Please verify your purchase code first.', 'bongoto-shop' ), 120 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$home_index = isset( $_POST['home_index'] ) ? (int) $_POST['home_index'] : 0;
$headers = isset( $_POST['headers'] ) ? (array) $_POST['headers'] : [];
$preset_file = isset( $_POST['preset_file'] ) ? sanitize_text_field( wp_unslash( $_POST['preset_file'] ) ) : '';
// 1) Refresh manifest (use latest)
$manifest = bongoto_shop_fetch_manifest();
if ( is_wp_error( $manifest ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Manifest error: ', 'bongoto-shop' ) . $manifest->get_error_message(), 180 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
set_transient( 'bongoto_shop_last_manifest', $manifest, 12 * HOUR_IN_SECONDS );
// 2) Apply preset first (colors)
if ( $preset_file ) {
$p = bongoto_shop_apply_customizer_preset_from_manifest( $preset_file );
if ( is_wp_error( $p ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Preset import failed: ', 'bongoto-shop' ) . $p->get_error_message(), 180 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
}
// 3) Download selected headers
if ( ! empty( $headers ) ) {
$h = bongoto_shop_download_selected_headers( $headers, $manifest );
if ( is_wp_error( $h ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Header download failed: ', 'bongoto-shop' ) . $h->get_error_message(), 180 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
}
// 4) Import Home
if ( function_exists( 'bongoto_shop_import_home_by_index_from_manifest' ) ) {
$r = bongoto_shop_import_home_by_index_from_manifest( $home_index );
if ( is_wp_error( $r ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Home import failed: ', 'bongoto-shop' ) . $r->get_error_message(), 180 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
set_transient( 'bongoto_shop_demo_notice', __( 'Import completed! Home page created and set as the front page.', 'bongoto-shop' ), 180 );
// Mark import as completed so we can hide the Quick Setup notice.
update_option( 'bongoto_shop_import_completed', 1 );
update_option( 'bongoto_shop_pro_assets_imported', 1 );
update_option( 'bongoto_demo_import_completed', 1 ); // Legacy flag used by some templates.
if ( (bool) get_option( 'bongoto_premium_active', false ) ) {
delete_transient( 'bongoto_shop_show_setup_notice' );
}
} else {
set_transient( 'bongoto_shop_demo_notice', __( 'Importer not found.', 'bongoto-shop' ), 180 );
}
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
});
add_action( 'admin_post_bongoto_shop_import_selected_items', function() {
if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Forbidden' ); }
check_admin_referer( 'bongoto_shop_import_selected_items' );
$active = function_exists( 'bongoto_is_premium_active' )
? bongoto_is_premium_active()
: (bool) get_option( 'bongoto_premium_active', false );
if ( ! $active ) {
set_transient( 'bongoto_shop_demo_notice', __( 'You need to verify your purchase code before importing.', 'bongoto-shop' ), 180 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$manifest = bongoto_shop_fetch_manifest();
if ( ! is_wp_error( $manifest ) && is_array( $manifest ) ) {
set_transient( 'bongoto_shop_last_manifest', $manifest, 12 * HOUR_IN_SECONDS );
}
// Imports
$did = [];
$warnings = [];
// Home (download only; create later from Setup page)
$do_home = ! empty( $_POST['do_home'] );
$default_home_index = isset( $_POST['default_home_index'] ) ? absint( wp_unslash( $_POST['default_home_index'] ) ) : 0;
if ( $do_home ) {
$homes = ( is_array( $manifest ) && isset( $manifest['elementor']['home_pages'] ) && is_array( $manifest['elementor']['home_pages'] ) )
? $manifest['elementor']['home_pages']
: array();
if ( ! empty( $homes ) ) {
if ( $default_home_index < 0 || $default_home_index >= count( $homes ) ) {
$default_home_index = 0;
}
$selected = $homes[ $default_home_index ] ?? null;
$file = is_array( $selected ) && ! empty( $selected['file'] ) ? ltrim( (string) $selected['file'], '/' ) : '';
if ( '' === $file ) {
set_transient( 'bongoto_shop_demo_notice', __( 'No Pro Home JSON selected.', 'bongoto-shop' ), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
// Download selected file to uploads storage (no page creation yet).
if ( function_exists( 'bongoto_shop_demo_is_allowed_file' ) && ! bongoto_shop_demo_is_allowed_file( $file ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Selected home file is not allowed.', 'bongoto-shop' ), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$base_url = trailingslashit( dirname( BONGOTO_DEMO_MANIFEST_URL ) );
$url = $base_url . $file;
if ( function_exists( 'bongoto_shop_is_allowed_demo_host' ) && ! bongoto_shop_is_allowed_demo_host( $url ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Invalid demo source URL.', 'bongoto-shop' ), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$resp = wp_remote_get( $url, function_exists( 'bongoto_shop_remote_get_args' ) ? bongoto_shop_remote_get_args( 25, 10 * 1024 * 1024 ) : array( 'timeout' => 25, 'redirection' => 3, 'reject_unsafe_urls' => true, 'sslverify' => true ) );
if ( is_wp_error( $resp ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Home download failed: ', 'bongoto-shop' ) . $resp->get_error_message(), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$code = (int) wp_remote_retrieve_response_code( $resp );
$body = (string) wp_remote_retrieve_body( $resp );
if ( 200 !== $code || '' === $body ) {
set_transient( 'bongoto_shop_demo_notice', sprintf( __( 'Home download failed (HTTP %d).', 'bongoto-shop' ), $code ), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$dest = function_exists( 'bongoto_shop_local_demo_file' ) ? bongoto_shop_local_demo_file( $file ) : '';
if ( $dest ) {
wp_mkdir_p( dirname( $dest ) );
if ( function_exists( 'bongoto_shop_fs_put_contents' ) ) { bongoto_shop_fs_put_contents( $dest, $body ); } else { @file_put_contents( $dest, $body ); } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
}
update_option( 'bongoto_shop_selected_home_index', $default_home_index );
update_option( 'bongoto_shop_selected_home_file', $file );
// Gate the "Create Home Page" step on a successful download.
// This prevents the Create button from appearing before import.
update_option( 'bongoto_shop_last_imported_home_file', $file );
$did[] = 'Home JSON';
}
}
/**
* Topbar CSS (shared asset)
* Server-only: we download this from the demo server during the Import step.
* Topbar UI/rendering will be disabled until this file exists.
*/
if ( defined( 'BONGOTO_DEMO_MANIFEST_URL' ) && function_exists( 'bongoto_shop_local_demo_file' ) ) {
$base_url = trailingslashit( dirname( BONGOTO_DEMO_MANIFEST_URL ) );
$topbar_rel = 'headers/topbar.css';
// Allowed demo asset (css).
if ( ! function_exists( 'bongoto_shop_demo_is_allowed_file' ) || bongoto_shop_demo_is_allowed_file( $topbar_rel ) ) {
$url = $base_url . $topbar_rel;
$resp = wp_remote_get( $url, function_exists( 'bongoto_shop_remote_get_args' ) ? bongoto_shop_remote_get_args( 25, 10 * 1024 * 1024 ) : array( 'timeout' => 25, 'redirection' => 3, 'reject_unsafe_urls' => true, 'sslverify' => true ) );
if ( is_wp_error( $resp ) ) {
$warnings[] = 'Topbar CSS';
} else {
$code = (int) wp_remote_retrieve_response_code( $resp );
$body = (string) wp_remote_retrieve_body( $resp );
if ( 200 !== $code || '' === $body ) {
$warnings[] = 'Topbar CSS';
} else {
$dest = bongoto_shop_local_demo_file( $topbar_rel );
if ( $dest ) {
wp_mkdir_p( dirname( $dest ) );
if ( function_exists( 'bongoto_shop_fs_put_contents' ) ) { bongoto_shop_fs_put_contents( $dest, $body ); } else { @file_put_contents( $dest, $body ); } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
$did[] = 'Topbar CSS';
}
}
}
}
}
// Headers (Pro headers are bundled in the theme; nothing to download)
// Colors
$do_colors = ! empty( $_POST['do_colors'] );
$color_index = isset( $_POST['color_index'] ) ? (int) $_POST['color_index'] : 0;
if ( $do_colors ) {
$r = bongoto_shop_apply_color_preset_by_index_from_manifest( $color_index );
if ( is_wp_error( $r ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Color preset failed: ', 'bongoto-shop' ) . $r->get_error_message(), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$did[] = 'Colors';
}
set_transient( 'bongoto_shop_demo_notice', 'Imported: ' . implode( ', ', array_unique( $did ) ) . ( ! empty( $warnings ) ? ' (Skipped: ' . implode( ', ', array_unique( $warnings ) ) . ')' : '' ) . '.', 180 );
// Mark import as completed so we can hide the Quick Setup notice.
if ( ! empty( $did ) ) {
update_option( 'bongoto_shop_import_completed', 1 );
update_option( 'bongoto_shop_pro_assets_imported', 1 );
update_option( 'bongoto_demo_import_completed', 1 ); // Legacy flag used by some templates.
if ( (bool) get_option( 'bongoto_premium_active', false ) ) {
delete_transient( 'bongoto_shop_show_setup_notice' );
}
}
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
});
/**
* Create FREE Home Page from theme-shipped Elementor JSON.
* Does NOT require purchase verification (free starter home).
*/
add_action( 'admin_post_bongoto_shop_create_free_home', function() {
if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Forbidden' ); }
check_admin_referer( 'bongoto_shop_create_free_home' );
// Safety: Free home uses Elementor + WooCommerce widgets; prevent critical errors.
$elementor_ok = class_exists( '\\Elementor\\Plugin' );
$woocommerce_ok = class_exists( 'WooCommerce' ) || function_exists( 'WC' );
if ( ! $elementor_ok || ! $woocommerce_ok ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Please install & activate Elementor and WooCommerce first (Step 1).', 'bongoto-shop' ), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-setup' ) );
exit;
}
if ( ! function_exists( 'bongoto_shop_import_home_from_local_json_file' ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Importer is missing.', 'bongoto-shop' ), 220 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-setup' ) );
exit;
}
$json = get_theme_file_path( 'assets/elementor/bongoto-shop-home.json' );
$title = __( 'Home 01', 'bongoto-shop' );
$r = bongoto_shop_import_home_from_local_json_file( $json, $title, false );
if ( is_wp_error( $r ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Failed to create Free Home: ', 'bongoto-shop' ) . $r->get_error_message(), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-setup' ) );
exit;
}
// Save for Quick Setup "View" button.
update_option( 'bongoto_shop_free_home_id', (int) $r );
// Set the created Free Home page as the Front Page.
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', (int) $r );
// Mark demo as "done" so the front-page template stops showing the Welcome screen.
// This does NOT set the page as Front Page automatically (Envato-friendly).
update_option( 'bongoto_shop_import_completed', 1 );
update_option( 'bongoto_demo_import_completed', 1 ); // Legacy flag used by some templates.
// IMPORTANT:
// Do NOT set bongoto_shop_last_created_home_id here. That option is reserved for the
// Pro demo import flow. Setting it for the Free starter home would make the Pro
// "Create Home Page" button disappear on the Demo Import page.
// Clear Elementor cache if available.
try {
if ( class_exists( '\\Elementor\\Plugin' ) && isset( \Elementor\Plugin::$instance->files_manager ) ) {
\Elementor\Plugin::$instance->files_manager->clear_cache();
}
} catch ( \Throwable $e ) { /* ignore */ }
$view = get_permalink( (int) $r );
$msg = __( 'Free Home Page created successfully.', 'bongoto-shop' );
if ( $view ) {
$msg .= ' ' . esc_html__( 'View Home Page', 'bongoto-shop' ) . '.';
}
$msg .= ' ' . __( 'You can set it as the Front Page from Settings → Reading.', 'bongoto-shop' );
set_transient( 'bongoto_shop_demo_notice', $msg, 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-setup' ) );
exit;
} );
/**
* Create PRO Home Page from demo server JSON (requires verified purchase code).
* - Downloads safe assets into uploads/bongoto-shop/demo/
* - Creates/updates a WP Page from Elementor data
*/
add_action( 'admin_post_bongoto_shop_create_pro_home', function() {
if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Forbidden' ); }
check_admin_referer( 'bongoto_shop_create_pro_home' );
$active = function_exists( 'bongoto_is_premium_active' ) ? bongoto_is_premium_active() : (bool) get_option( 'bongoto_premium_active', false );
if ( ! $active ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Purchase code is not verified. Please verify first.', 'bongoto-shop' ), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
if ( ! defined( 'BONGOTO_DEMO_MANIFEST_URL' ) || ! function_exists( 'bongoto_shop_fetch_manifest' ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Demo manifest is not configured.', 'bongoto-shop' ), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$manifest = bongoto_shop_fetch_manifest();
if ( is_wp_error( $manifest ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Manifest fetch failed: ', 'bongoto-shop' ) . $manifest->get_error_message(), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
// Pick Pro home JSON (selected during import) or fallback to first item.
$selected_file = (string) get_option( 'bongoto_shop_selected_home_file', '' );
if ( '' === $selected_file ) {
$homes = $manifest['elementor']['home_pages'] ?? [];
if ( ! is_array( $homes ) || empty( $homes ) || empty( $homes[0]['file'] ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'No Pro Home JSON found in manifest.', 'bongoto-shop' ), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$selected_file = (string) $homes[0]['file'];
}
$selected_file = ltrim( (string) $selected_file, '/' );
// Ensure the selected file was downloaded by the Import step.
// We do NOT download demo JSON files during the Create step.
$local = function_exists( 'bongoto_shop_local_demo_file' ) ? bongoto_shop_local_demo_file( $selected_file ) : '';
if ( ! $local || ! file_exists( $local ) || filesize( $local ) <= 0 ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Please click “Import Selected Items” first, then create the Home page.', 'bongoto-shop' ), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
$file = (string) $selected_file;
$r = bongoto_shop_import_home_from_manifest_file( $file );
if ( is_wp_error( $r ) ) {
set_transient( 'bongoto_shop_demo_notice', __( 'Failed to create Pro Home: ', 'bongoto-shop' ) . $r->get_error_message(), 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
}
update_option( 'bongoto_shop_last_created_home_id', (int) $r );
// Set the created Pro Home page as the Front Page (overwrites Free Home if set).
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', (int) $r );
$home_url = get_permalink( (int) $r );
$notice_html = sprintf(
/* translators: 1: home url, 2: customizer url */
__( 'Demo import successful. View Home Page or Open Customizer.', 'bongoto-shop' ),
esc_url( $home_url ),
esc_url( admin_url( 'customize.php' ) )
);
set_transient( 'bongoto_shop_demo_notice', $notice_html, 240 );
wp_safe_redirect( admin_url( 'admin.php?page=bongoto-shop-import' ) );
exit;
} );