$active, 'message' => $active ? __( 'License active', 'bongoto-marketplace' ) : $msg, ); // 🕒 Cache for 30 minutes set_transient( 'bongoto_marketplace_license_check_cache', $response, 30 * MINUTE_IN_SECONDS ); wp_send_json( $response ); } /* ========================================================= * 🔄 Localize script to pass AJAX URL (Priority fixed) * ========================================================= */ add_action( 'wp_enqueue_scripts', function() { wp_localize_script( 'bongoto-header', 'bongoto_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'no_pro_message' => __( '🚫 Please activate Bongoto Marketplace Pro license to use this feature.', 'bongoto-marketplace' ), )); }, 25); /* ========================================================================================================== */ /* ----------------------------- * Constants * ----------------------------- */ if ( ! defined( 'BONGOTO_MARKETPLACE_VERSION' ) ) { define( 'BONGOTO_MARKETPLACE_VERSION', '1.0.0' ); } if ( ! defined( 'BONGOTO_MARKETPLACE_DIR' ) ) { define( 'BONGOTO_MARKETPLACE_DIR', trailingslashit( get_template_directory() ) ); } if ( ! defined( 'BONGOTO_MARKETPLACE_URI' ) ) { define( 'BONGOTO_MARKETPLACE_URI', trailingslashit( get_template_directory_uri() ) ); } if ( ! defined( 'BONGOTO_MARKETPLACE_ASSETS_URI' ) ) { define( 'BONGOTO_MARKETPLACE_ASSETS_URI', BONGOTO_MARKETPLACE_URI . 'assets/' ); } /* ----------------------------- * 1) Utility: File version * ----------------------------- */ if ( ! function_exists( 'bongoto_marketplace_file_version' ) ) { function bongoto_marketplace_file_version( $relative_path ) { $path = BONGOTO_MARKETPLACE_DIR . ltrim( $relative_path, '/' ); return file_exists( $path ) ? (string) filemtime( $path ) : BONGOTO_MARKETPLACE_VERSION; } } /* ----------------------------- * 2) Theme Setup * ----------------------------- */ if ( ! function_exists( 'bongoto_marketplace_setup' ) ) { function bongoto_marketplace_setup() { // Textdomain load load_theme_textdomain( 'bongoto-marketplace', BONGOTO_MARKETPLACE_DIR . 'languages' ); // Required Theme Supports add_theme_support( 'automatic-feed-links' ); add_theme_support( 'title-tag' ); add_theme_support( 'post-thumbnails' ); // Image sizes add_image_size( 'bongoto_marketplace-thumb', 540, 360, true ); add_image_size( 'bongoto_marketplace-card', 720, 480, true ); // Custom logo add_theme_support( 'custom-logo', array( 'height' => 80, 'width' => 240, 'flex-height' => true, 'flex-width' => true, ) ); // HTML5 support add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'script', 'style', 'navigation-widgets', ) ); // Editor & Block supports add_theme_support( 'wp-block-styles' ); add_theme_support( 'editor-styles' ); add_editor_style( 'assets/css/main.css' ); add_theme_support( 'align-wide' ); add_theme_support( 'responsive-embeds' ); add_theme_support( 'woocommerce' ); // Navigation menus register_nav_menus( array( 'primary' => __( 'Primary Menu', 'bongoto-marketplace' ), 'footer' => __( 'Footer Menu', 'bongoto-marketplace' ), 'topbar' => __( 'Top Bar Menu', 'bongoto-marketplace' ), ) ); } } add_action( 'after_setup_theme', 'bongoto_marketplace_setup' ); /* Content width */ if ( ! isset( $content_width ) ) { $content_width = 720; } /* ----------------------------- * 3) Widgets * ----------------------------- */ function bongoto_marketplace_widgets_init() { for ( $i = 1; $i <= 4; $i++ ) { register_sidebar( array( 'name' => sprintf( __( 'Footer Column %d', 'bongoto-marketplace' ), $i ), 'id' => "footer-$i", 'description' => __( 'Add widgets here to appear in the footer.', 'bongoto-marketplace' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } register_sidebar( array( 'name' => __( 'Sidebar', 'bongoto-marketplace' ), 'id' => 'sidebar-1', 'description' => __( 'Add widgets here for posts/pages if needed.', 'bongoto-marketplace' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Shop Sidebar', 'bongoto-marketplace' ), 'id' => 'shop-sidebar', 'description' => __( 'Widgets shown on the WooCommerce shop and product archive pages.', 'bongoto-marketplace' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'bongoto_marketplace_widgets_init' ); /* ----------------------------- * 4) Body Classes * ----------------------------- */ function bongoto_marketplace_body_class( $classes ) { $is_pro = ( defined( 'BONGOTO_MARKETPLACE_IS_PRO' ) && BONGOTO_MARKETPLACE_IS_PRO ); $classes[] = $is_pro ? 'bongoto-pro-active' : 'bongoto-free'; if ( class_exists( 'WooCommerce' ) ) $classes[] = 'has-woocommerce'; if ( class_exists( 'WeDevs_Dokan' ) ) $classes[] = 'has-dokan'; return $classes; } add_filter( 'body_class', 'bongoto_marketplace_body_class' ); /* ----------------------------- * 5) Includes * ----------------------------- */ $includes = array( 'inc/setup.php', 'inc/assets.php', 'inc/template-functions.php', 'inc/hooks.php', 'inc/security.php', 'inc/demo-setup.php', 'inc/admin/welcome.php', 'inc/customizer/customizer.php', 'inc/customizer/sanitize.php', 'inc/customizer/options-general.php', 'inc/customizer/options-header.php', 'inc/customizer/options-footer.php', 'inc/customizer/controls/class-sortable-control.php', 'inc/class-bongoto-header-manager.php', 'inc/class-bongoto-footer-manager.php', 'inc/compatibility/elementor.php', 'inc/compatibility/woocommerce.php', 'inc/compatibility/dokan.php', ); foreach ( $includes as $rel ) { $path = BONGOTO_MARKETPLACE_DIR . ltrim( $rel, '/' ); if ( file_exists( $path ) ) { require_once $path; } } /* ----------------------------- * 6) Search Form Fallback * ----------------------------- */ function bongoto_marketplace_get_search_form( $echo = true ) { ob_start(); get_template_part( 'searchform' ); $form = ob_get_clean(); if ( $echo ) { echo $form; return; } return $form; } /* ----------------------------- * 7) Ajax Placeholder * ----------------------------- */ function bongoto_marketplace_ajax_placeholder() { wp_send_json_success( array( 'message' => __( 'OK', 'bongoto-marketplace' ) ) ); } add_action( 'wp_ajax_bongoto_marketplace_ping', 'bongoto_marketplace_ajax_placeholder' ); add_action( 'wp_ajax_nopriv_bongoto_marketplace_ping', 'bongoto_marketplace_ajax_placeholder' ); /* ========================================================= * 8) WooCommerce Customization * ========================================================= */ // WooCommerce grid layout → 4 columns function bongoto_marketplace_loop_columns() { return 4; } add_filter( 'loop_shop_columns', 'bongoto_marketplace_loop_columns' ); // Products per page → 16 function bongoto_marketplace_products_per_page( $cols ) { return 16; } add_filter( 'loop_shop_per_page', 'bongoto_marketplace_products_per_page', 20 ); // Default shop sorting → Sort by latest function bongoto_marketplace_default_sort_by_latest( $sort_by ) { return 'date'; } add_filter( 'woocommerce_default_catalog_orderby', 'bongoto_marketplace_default_sort_by_latest' ); /* ========================================================= * Header CTA URL override * guest/customer → My Account + ?become_vendor=1 * seller/admin → Upload (Dokan auto) * ========================================================= */ add_filter( 'bongoto_marketplace/header_cta', function ( $out ) { $is_seller = is_user_logged_in() && ( ( function_exists( 'dokan_is_user_seller' ) && dokan_is_user_seller( get_current_user_id() ) ) || current_user_can( 'manage_options' ) ); if ( ! $is_seller ) { $my_account = function_exists( 'wc_get_page_permalink' ) ? wc_get_page_permalink( 'myaccount' ) : home_url( '/my-account/' ); $out['label'] = __( 'Start Selling', 'bongoto-marketplace' ); $out['url'] = add_query_arg( 'become_vendor', '1', $my_account ); } return $out; }, 999 ); /* ========================================================= * Legacy route redirect * /my-account/bongoto-marketplace-become-vendor/ → ?become_vendor=1 * ========================================================= */ add_action( 'template_redirect', function () { $req_path = trim( (string) parse_url( $_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH ), '/' ); if ( $req_path === 'my-account/bongoto-marketplace-become-vendor' ) { $my_account = function_exists( 'wc_get_page_permalink' ) ? wc_get_page_permalink( 'myaccount' ) : home_url( '/my-account/' ); wp_safe_redirect( add_query_arg( 'become_vendor', '1', $my_account ), 301 ); exit; } } ); /* ========================================================= * Bongoto Marketplace → Auto-import Elementor Home JSON * File location: /assets/elementor/bongoto-marketplace-home-01.json * ========================================================= */ /** Pro ডিটেক্টর */ if ( ! function_exists( 'bongoto_marketplace_is_pro_active' ) ) { function bongoto_marketplace_is_pro_active() { $is = false; if ( defined( 'BONGOTO_MARKETPLACE_PRO_ACTIVE' ) && BONGOTO_MARKETPLACE_PRO_ACTIVE ) { $is = true; } if ( class_exists( 'Bongoto_Marketplace_Pro' ) ) { $is = true; } return (bool) apply_filters( 'bongoto_marketplace/is_pro_active', $is ); } } /** JSON ফাইলের পাথ */ if ( ! function_exists( 'bongoto_marketplace_home_json_path' ) ) { function bongoto_marketplace_home_json_path() { $file = trailingslashit( get_template_directory() ) . 'assets/elementor/bongoto-marketplace-home-01.json'; return file_exists( $file ) ? $file : ''; } } /** Elementor JSON ইমপোর্টার */ if ( ! function_exists( 'bongoto_marketplace_import_home_from_json' ) ) { function bongoto_marketplace_import_home_from_json() { $path = bongoto_marketplace_home_json_path(); if ( ! $path ) { return new WP_Error( 'missing_json', __( 'Home JSON file not found.', 'bongoto-marketplace' ) ); } $json = file_get_contents( $path ); if ( empty( $json ) ) { return new WP_Error( 'empty_json', __( 'Home JSON file is empty.', 'bongoto-marketplace' ) ); } $page = get_page_by_title( 'Home' ); $page_id = $page ? (int) $page->ID : wp_insert_post([ 'post_title' => 'Home', 'post_type' => 'page', 'post_status' => 'publish', ]); 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([ 'ID' => $page_id, 'post_content' => '' ]); } else { $placeholder = '
' . esc_html__( 'Please install/activate Elementor to render the Bongoto Marketplace Home layout.', 'bongoto-marketplace' ) . '
'; wp_update_post([ 'ID' => $page_id, 'post_content' => $placeholder ]); } update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', $page_id ); if ( ! bongoto_marketplace_is_pro_active() ) { update_post_meta( $page_id, '_bongoto_marketplace_locked', '1' ); } else { delete_post_meta( $page_id, '_bongoto_marketplace_locked' ); } return $page_id; } } /** থিম একটিভ হলে অটো ইমপোর্ট */ add_action( 'after_switch_theme', function() { if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) { return; } bongoto_marketplace_import_home_from_json(); } ); /** ম্যানুয়াল অ্যাডমিন টুল */ add_action( 'admin_menu', function() { add_management_page( 'Bongoto Marketplace Import Home', 'Bongoto Marketplace Import Home', 'manage_options', 'bongoto-marketplace-import-home', function () { if ( isset( $_POST['bongoto_marketplace_do_import'] ) && check_admin_referer( 'bongoto_marketplace_import_home' ) ) { $res = bongoto_marketplace_import_home_from_json(); if ( is_wp_error( $res ) ) { echo '

' . esc_html( $res->get_error_message() ) . '

'; } else { echo '

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

'; } } echo '

Bongoto Marketplace: Import Home

'; wp_nonce_field( 'bongoto_marketplace_import_home' ); submit_button( __( 'Import bongoto-marketplace-home-01.json', 'bongoto-marketplace' ), 'primary', 'bongoto_marketplace_do_import' ); echo '
'; } ); } ); /* ========================================================================================================== * 🔒 WooCommerce Enhancements: Free Download & Pro Header Integration * ========================================================================================================== */ /** * Force show Add to Cart and Buy Now buttons for admins & vendors * Show Free Download button for guests/customers if product is free */ add_filter( 'woocommerce_is_purchasable', function( $purchasable, $product ) { // ✅ Admin / Vendor / Seller → সবসময় purchasable true if ( is_user_logged_in() ) { $user = wp_get_current_user(); if ( in_array( 'administrator', (array) $user->roles, true ) || in_array( 'vendor', (array) $user->roles, true ) || in_array( 'seller', (array) $user->roles, true ) ) { return true; } } // ✅ ফ্রি প্রোডাক্ট → purchasable true (custom button দেখানোর জন্য) if ( (float) $product->get_price() === 0.0 ) { return true; } return $purchasable; }, 999, 2 ); /** * Replace "Read More" with "Free Download" button for free products */ add_filter( 'woocommerce_loop_add_to_cart_link', function( $button, $product ) { if ( (float) $product->get_price() === 0.0 ) { $product_url = get_permalink( $product->get_id() ); $button = '' . esc_html__( 'Free Download', 'bongoto-marketplace' ) . ''; } return $button; }, 999, 2 ); /* ========================================================= * Allow Bongoto Pro Headers (2–5) * ========================================================= */ add_filter( 'bongoto_marketplace/header/allowed_variants', function( $allowed ) { if ( apply_filters( 'bongoto_marketplace/is_pro_active', false ) ) { return array( 1, 2, 3, 4, 5 ); } return array( 1 ); }); /** * Try rendering Bongoto Pro headers dynamically (via Pro plugin) */ add_action( 'get_template_part_template-parts/headers/header', function( $slug, $name ) { if ( apply_filters( 'bongoto_marketplace/is_pro_active', false ) && in_array( $name, array( '2','3','4','5' ), true ) ) { $rendered = apply_filters( 'bongoto_marketplace/pro/try_render_header', false, $name ); if ( $rendered ) { exit; // prevent default header loading } } }, 10, 2 ); /* ========================================================= * Optional: Add missing CSS classes for Theme Check * ========================================================= */ /* These are recommended by WordPress Theme Review */ add_action( 'wp_head', function() { echo ''; });