__( 'Elementor', 'bongoto-marketplace' ), 'woocommerce/woocommerce.php' => __( 'WooCommerce', 'bongoto-marketplace' ), 'dokan-lite/dokan.php' => __( 'Dokan — Vendor Marketplace', 'bongoto-marketplace' ), 'bongoto-pro/bongoto-pro.php' => __( 'Bongoto Pro', 'bongoto-marketplace' ), ); include_once ABSPATH . 'wp-admin/includes/plugin.php'; $all_plugins = function_exists( 'get_plugins' ) ? get_plugins() : array(); $missing = array(); foreach ( $expected as $file => $label ) { if ( ! isset( $all_plugins[ $file ] ) || ! bongoto_mp_is_plugin_active( $file ) ) { $missing[] = $label; } } if ( ! empty( $missing ) ) { echo '

'; echo esc_html__( 'Some recommended plugins are missing or inactive:', 'bongoto-marketplace' ) . ' '; echo '' . esc_html( implode( ', ', $missing ) ) . '. '; echo esc_html__( 'Open the setup page to install or activate them.', 'bongoto-marketplace' ) . ' '; echo '' . esc_html__( 'Open Setup', 'bongoto-marketplace' ) . ''; echo '

'; } // Front page not set $needs_front = ( get_option( 'show_on_front' ) !== 'page' ) || ! (int) get_option( 'page_on_front' ); if ( $needs_front ) { echo '

' . esc_html__( 'A front page is not configured.', 'bongoto-marketplace' ) . ' ' . esc_html__( 'Click the button below to create/import and set a Home page.', 'bongoto-marketplace' ) . ' ' . esc_html__( 'Open Setup', 'bongoto-marketplace' ) . '

'; } // One-time “Quick Setup” notice after activation (optional legacy) if ( get_option( BONGOTO_SETUP_OPTION_DONE ) || get_option( BONGOTO_SETUP_OPTION_DISMISS ) ) { delete_transient( BONGOTO_SETUP_TRANSIENT_SHOW ); return; } if ( get_transient( BONGOTO_SETUP_TRANSIENT_SHOW ) ) { $dismiss_url = wp_nonce_url( add_query_arg( 'bongoto_mp_dismiss', '1' ), 'bongoto_mp_dismiss' ); echo '
'; echo '

' . esc_html__( 'Bongoto Marketplace — Quick Setup', 'bongoto-marketplace' ) . '

'; echo '

' . esc_html__( 'Install/activate recommended plugins or import a demo home page.', 'bongoto-marketplace' ) . '

'; echo '

' . esc_html__( 'Open Setup', 'bongoto-marketplace' ) . ' '; echo '' . esc_html__( 'Dismiss', 'bongoto-marketplace' ) . '

'; echo '
'; } } ); /** Clear transient once done/dismissed. */ add_action( 'admin_init', function () { if ( get_option( BONGOTO_SETUP_OPTION_DONE ) || get_option( BONGOTO_SETUP_OPTION_DISMISS ) ) { delete_transient( BONGOTO_SETUP_TRANSIENT_SHOW ); } } ); /** Permanent dismiss handler. */ add_action( 'admin_init', function () { $nonce = isset( $_REQUEST['_wpnonce'] ) ? wp_unslash( $_REQUEST['_wpnonce'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['bongoto_mp_dismiss'] ) && wp_verify_nonce( $nonce, 'bongoto_mp_dismiss' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended delete_transient( BONGOTO_SETUP_TRANSIENT_SHOW ); update_option( BONGOTO_SETUP_OPTION_DISMISS, time() ); wp_safe_redirect( remove_query_arg( array( 'bongoto_mp_dismiss', '_wpnonce' ) ) ); exit; } } ); /* ------------------------------------------------------- * Register Setup page * ----------------------------------------------------- */ add_action( 'admin_menu', function () { if ( ! current_user_can( 'manage_options' ) ) return; add_theme_page( __( 'Bongoto Setup', 'bongoto-marketplace' ), __( 'Bongoto Setup', 'bongoto-marketplace' ), 'manage_options', 'bongoto-marketplace-setup', 'bongoto_marketplace_render_setup_page' ); } ); /* ------------------------------------------------------- * Helpers * ----------------------------------------------------- */ function bongoto_marketplace_plugin_row( string $slug, string $label, bool $is_pro = false, string $pro_url = '' ): string { include_once ABSPATH . 'wp-admin/includes/plugin.php'; $installed = false; $active = false; $plugin_file = ''; $plugins = function_exists( 'get_plugins' ) ? get_plugins() : array(); foreach ( $plugins as $file => $data ) { if ( strpos( $file, $slug . '/' ) === 0 ) { $installed = true; $plugin_file = $file; $active = is_plugin_active( $file ); break; } } if ( ! $installed ) { if ( $is_pro && $pro_url ) { $button = '' . esc_html__( 'Get Pro', 'bongoto-marketplace' ) . ''; } else { $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug ); $button = '' . esc_html__( 'Install', 'bongoto-marketplace' ) . ''; } } elseif ( ! $active && $plugin_file ) { $url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $plugin_file ), 'activate-plugin_' . $plugin_file ); $button = '' . esc_html__( 'Activate', 'bongoto-marketplace' ) . ''; } else { $button = '' . esc_html__( 'Activated', 'bongoto-marketplace' ) . ''; } return '
  • ' . '' . esc_html( $label ) . '' . '' . $button . '' . '
  • '; } function bongoto_marketplace_list_demo_jsons(): array { $dir = trailingslashit( BONGOTO_MARKETPLACE_DIR ) . 'assets/elementor'; $list = array(); if ( is_dir( $dir ) ) { $files = glob( $dir . '/*.json' ); if ( $files ) { foreach ( $files as $abs ) { $rel = str_replace( BONGOTO_MARKETPLACE_DIR . DIRECTORY_SEPARATOR, '', $abs ); $size = filesize( $abs ); $list[] = array( 'abs' => $abs, 'rel' => $rel, 'size' => $size ? size_format( $size ) : '', ); } } } $default = $dir . '/digital-marketplace-01.json'; if ( file_exists( $default ) && ! array_filter( $list, fn( $i ) => basename( $i['abs'] ) === 'digital-marketplace-01.json' ) ) { $list[] = array( 'abs' => $default, 'rel' => 'assets/elementor/digital-marketplace-01.json', 'size' => size_format( filesize( $default ) ), ); } return $list; } /** * Create/Update "Home" page with Elementor JSON & set as front page. * * @param string $abs_json * @return string|WP_Error Page ID on success. */ function bongoto_marketplace_import_elementor_home( string $abs_json ) { if ( ! file_exists( $abs_json ) ) { return new WP_Error( 'missing_json', __( 'Selected JSON file not found.', 'bongoto-marketplace' ) ); } $json = file_get_contents( $abs_json ); if ( '' === trim( (string) $json ) ) { return new WP_Error( 'empty_json', __( 'Selected JSON file is empty.', 'bongoto-marketplace' ) ); } $page = get_page_by_title( 'Home' ); if ( $page && $page->post_type === 'page' ) { $page_id = (int) $page->ID; } else { $page_id = wp_insert_post( array( 'post_title' => 'Home', 'post_type' => 'page', 'post_status' => 'publish', 'post_content' => '', ) ); if ( is_wp_error( $page_id ) ) return $page_id; } if ( class_exists( '\Elementor\Plugin' ) ) { update_post_meta( $page_id, '_elementor_edit_mode', 'builder' ); update_post_meta( $page_id, '_elementor_template_type', 'wp-page' ); update_post_meta( $page_id, '_elementor_data', wp_slash( $json ) ); wp_update_post( array( 'ID' => $page_id, 'post_content' => '' ) ); } else { $placeholder = '
    ' . esc_html__( 'Please install & activate Elementor to render this layout.', 'bongoto-marketplace' ) . '
    '; wp_update_post( array( 'ID' => $page_id, 'post_content' => $placeholder ) ); } update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', $page_id ); update_option( BONGOTO_SETUP_OPTION_DONE, time() ); delete_transient( BONGOTO_SETUP_TRANSIENT_SHOW ); return (string) $page_id; } /** * Handle Import POST (no auto-redirect; show success notice with button). */ function bongoto_marketplace_handle_import_post() { if ( ! current_user_can( 'manage_options' ) ) return; if ( ! isset( $_POST['bongoto_mp_import_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['bongoto_mp_import_nonce'] ), 'bongoto_mp_import' ) ) { // phpcs:ignore return; } $rel = isset( $_POST['bongoto_demo_file'] ) ? sanitize_text_field( wp_unslash( $_POST['bongoto_demo_file'] ) ) : ''; if ( '' === $rel ) { add_settings_error( 'bongoto_mp', 'no_file', __( 'Please select a demo JSON file.', 'bongoto-marketplace' ), 'error' ); return; } $abs = realpath( trailingslashit( BONGOTO_MARKETPLACE_DIR ) . ltrim( $rel, '/\\' ) ); $theme_root = realpath( BONGOTO_MARKETPLACE_DIR ); if ( ! $abs || 0 !== strpos( $abs, $theme_root ) ) { add_settings_error( 'bongoto_mp', 'bad_path', __( 'Invalid file path.', 'bongoto-marketplace' ), 'error' ); return; } $res = bongoto_marketplace_import_elementor_home( $abs ); if ( is_wp_error( $res ) ) { add_settings_error( 'bongoto_mp', $res->get_error_code(), $res->get_error_message(), 'error' ); return; } $home_url = get_permalink( (int) $res ); // Back to setup with success flags (NO auto-open) wp_safe_redirect( add_query_arg( array( 'page' => 'bongoto-marketplace-setup', 'settings-updated' => 'true', 'bongoto_home_created' => '1', 'bongoto_home_url' => rawurlencode( $home_url ), ), admin_url( 'themes.php' ) ) ); exit; } add_action( 'admin_init', 'bongoto_marketplace_handle_import_post' ); /** * Render Setup page. */ function bongoto_marketplace_render_setup_page() { if ( ! current_user_can( 'manage_options' ) ) return; // Success message after import (with button only; no auto-redirect) if ( isset( $_GET['bongoto_home_created'] ) && $_GET['bongoto_home_created'] === '1' ) { $home_url = isset( $_GET['bongoto_home_url'] ) ? esc_url( wp_unslash( $_GET['bongoto_home_url'] ) ) : home_url( '/' ); echo '

    ' . esc_html__( 'Demo imported and set as the Front Page.', 'bongoto-marketplace' ) . ' ' . esc_html__( 'View Home', 'bongoto-marketplace' ) . '

    '; } settings_errors( 'bongoto_mp' ); $demos = bongoto_marketplace_list_demo_jsons(); $current_front = (int) get_option( 'page_on_front' ); $grid_css = 'display:grid;grid-template-columns:1fr 1fr 1fr;gap:20px;max-width:1200px;'; $card_css = 'background:#fff;border:1px solid #e2e8f0;border-radius:8px;'; $pad_css = 'padding:16px 18px;'; $list_css = 'list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px;'; ?>


    ' . esc_html( get_the_title( $current_front ) ?: 'Home' ) . '', (int) $current_front ); } else { esc_html_e( 'Not set', 'bongoto-marketplace' ); } ?>