80,
'width' => 240,
'flex-height' => true,
'flex-width' => true,
) );
add_theme_support( 'html5', array(
'search-form','comment-form','comment-list','gallery','caption','script','style','navigation-widgets',
) );
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' );
// ✅ Add default RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// ✅ Enable support for custom background and header
add_theme_support( 'custom-background' );
add_theme_support( 'custom-header' );
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_setup' );
/* Content width */
if ( ! isset( $content_width ) ) {
$content_width = 720;
}
/* -----------------------------
* 3) Widgets
* ----------------------------- */
function bongoto_widgets_init() {
for ( $i = 1; $i <= 4; $i++ ) {
register_sidebar( array(
'name' => sprintf( __( 'Footer Column %d', 'bongoto' ), $i ),
'id' => "footer-$i",
'description' => __( 'Add widgets here to appear in the footer.', 'bongoto' ),
'before_widget' => '',
'before_title' => '
',
) );
}
register_sidebar( array(
'name' => __( 'Sidebar', 'bongoto' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here for posts/pages if needed.', 'bongoto' ),
'before_widget' => '',
'before_title' => '',
) );
// Shop sidebar
register_sidebar( array(
'name' => __( 'Shop Sidebar', 'bongoto' ),
'id' => 'shop-sidebar',
'description' => __( 'Widgets shown on the WooCommerce shop and product archive pages.', 'bongoto' ),
'before_widget' => '',
'before_title' => '',
) );
}
add_action( 'widgets_init', 'bongoto_widgets_init' );
/* -----------------------------
* 5) Body Classes
* ----------------------------- */
function bongoto_body_class( $classes ) {
$is_pro = ( defined( 'BONGOTO_IS_PRO' ) && BONGOTO_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_body_class' );
/* -----------------------------
* 6) 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', // unified Dokan compatibility
);
foreach ( $includes as $rel ) {
$path = BONGOTO_DIR . ltrim( $rel, '/' );
if ( file_exists( $path ) ) require_once $path;
}
/* -----------------------------
* 7) Search Form Fallback
* ----------------------------- */
function bongoto_get_search_form( $echo = true ) {
ob_start();
get_template_part( 'searchform' );
$form = ob_get_clean();
if ( $echo ) { echo $form; return; }
return $form;
}
/* -----------------------------
* 8) Ajax Placeholder
* ----------------------------- */
function bongoto_ajax_placeholder() {
wp_send_json_success( array( 'message' => __( 'OK', 'bongoto' ) ) );
}
add_action( 'wp_ajax_bongoto_ping', 'bongoto_ajax_placeholder' );
add_action( 'wp_ajax_nopriv_bongoto_ping', 'bongoto_ajax_placeholder' );
/* =========================================================
* WooCommerce Customization
* ========================================================= */
function bongoto_loop_columns() {
return 4;
}
add_filter( 'loop_shop_columns', 'bongoto_loop_columns' );
function bongoto_products_per_page( $cols ) {
return 16;
}
add_filter( 'loop_shop_per_page', 'bongoto_products_per_page', 20 );
/* =========================================================
* Header CTA URL override
* guest/customer → My Account + ?become_vendor=1
* seller/admin → Upload (dokan.php auto)
* ========================================================= */
add_filter( 'bongoto/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' );
$out['url'] = add_query_arg( 'become_vendor', '1', $my_account );
}
return $out;
}, 999 );
/* =========================================================
* Legacy route redirect
* /my-account/bongoto-become-vendor/ → My Account + ?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-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: Auto-import Elementor Home JSON (and lock editing)
* File location expected: /assets/elementor/bongoto-home-01.json
* ========================================================= */
/** JSON ফাইলের পাথ */
if ( ! function_exists( 'bongoto_home_json_path' ) ) {
function bongoto_home_json_path() {
$file = trailingslashit( get_template_directory() ) . 'assets/elementor/bongoto-home-01.json';
return file_exists( $file ) ? $file : '';
}
}
/** Elementor JSON ইমপোর্টার → নতুন Home পেজ তৈরি/আপডেট করে */
if ( ! function_exists( 'bongoto_import_home_from_json' ) ) {
function bongoto_import_home_from_json() {
$path = bongoto_home_json_path();
if ( ! $path ) {
return new WP_Error( 'missing_json', __( 'Home JSON file not found.', 'bongoto' ) );
}
$json = file_get_contents( $path );
if ( empty( $json ) ) {
return new WP_Error( 'empty_json', __( 'Home JSON file is empty.', 'bongoto' ) );
}
// পেজ আগে থেকে থাকলে সেটাই নেবো
$page = get_page_by_title( 'Home' );
if ( $page && $page->ID ) {
$page_id = (int) $page->ID;
} else {
$page_id = wp_insert_post( array(
'post_title' => 'Home',
'post_type' => 'page',
'post_status' => 'publish',
) );
if ( is_wp_error( $page_id ) ) {
return $page_id;
}
}
// Elementor ইনস্টল থাকলে _elementor_data লিখে দিই, না থাকলে প্লেইন কনটেন্ট রাখি
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 ) );
// প্লেইন কনটেন্ট ক্লিয়ার করে দিই যাতে Elementor ডাটা-ই রেন্ডার হয়
wp_update_post( array( 'ID' => $page_id, 'post_content' => '' ) );
} else {
// Elementor নাই— ছোট একটা প্লেসহোল্ডার রাখি
$placeholder = ''
. esc_html__( 'Please install/activate Elementor to render the Bongoto Home layout.', 'bongoto' )
. '
';
wp_update_post( array( 'ID' => $page_id, 'post_content' => $placeholder ) );
}
// ফ্রন্ট পেজ হিসেবে সেট
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $page_id );
// Pro অ্যাক্টিভ না থাকলে—এই পেজ লক করে দিই
if ( ! bongoto_is_pro_active() ) {
update_post_meta( $page_id, '_bongoto_locked', '1' );
} else {
delete_post_meta( $page_id, '_bongoto_locked' );
}
return $page_id;
}
}
/** থিম একটিভ হলে—অটো ইমপোর্ট (যদি আগে থেকে ফ্রন্টপেজ সেট না থাকে) */
add_action( 'after_switch_theme', function() {
// আগে থেকে ফ্রন্ট পেজ সেট থাকলে জোর না করি
if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) {
return;
}
bongoto_import_home_from_json();
} );
/** ম্যানুয়াল অ্যাডমিন টুল (Tools → Bongoto: Import Home) */
if ( is_admin() ) {
add_action( 'admin_menu', function() {
// Ensure current user has proper capability before adding the page
if ( current_user_can( 'manage_options' ) ) {
add_management_page(
'Bongoto Import Home',
'Bongoto Import Home',
'manage_options',
'bongoto-import-home',
function () {
if ( isset( $_POST['bongoto_do_import'] ) && check_admin_referer( 'bongoto_import_home' ) ) {
$res = bongoto_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: Import Home
';
}
);
}
});
}
/* Plugin Check */
if ( ! function_exists( 'bongoto_is_pro_active' ) ) {
function bongoto_is_pro_active() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
return is_plugin_active( 'bongoto-pro/bongoto-pro.php' );
}
}
/**
* 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
if (is_user_logged_in()) {
$user = wp_get_current_user();
if (
in_array('administrator', (array) $user->roles) ||
in_array('vendor', (array) $user->roles) ||
in_array('seller', (array) $user->roles)
) {
return true;
}
}
// যদি প্রোডাক্ট ফ্রি হয় (price == 0) → purchasable true, যাতে custom button দেখানো যায়
if ((float)$product->get_price() === 0.0) {
return true;
}
return $purchasable;
}, 999, 2);
/**
* Free Product এ "Read More" এর পরিবর্তে "Free Download" বাটন দেখাবে (গেস্ট/কাস্টমারদের জন্য)
*/
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());
// "Free Download" বাটন
$button = '
Free Download
';
}
return $button;
}, 999, 2);
/**
* Allow Bongoto Pro headers (2–5)
*/
add_filter( 'bongoto/header/allowed_variants', function( $allowed ) {
if ( apply_filters( 'bongoto/is_pro_active', false ) ) {
return array( 1, 2, 3, 4, 5 );
}
return array( 1 );
});
/**
* Try rendering Bongoto Pro header
*/
add_action( 'get_template_part_template-parts/headers/header', function( $slug, $name ) {
if ( apply_filters( 'bongoto/is_pro_active', false ) && in_array( $name, array( '2','3','4','5' ), true ) ) {
$rendered = apply_filters( 'bongoto/pro/try_render_header', false, $name );
if ( $rendered ) {
exit; // prevent default header part loading
}
}
}, 10, 2 );
/**
* 🔄 Set default WooCommerce shop sorting to "Sort by latest"
*/
function bongoto_default_sort_by_latest( $sort_by ) {
// Set default sorting to 'date' (Sort by latest)
return 'date';
}
add_filter( 'woocommerce_default_catalog_orderby', 'bongoto_default_sort_by_latest' );
/**
* Load comment reply script only when needed
*/
function bongoto_enqueue_comment_reply() {
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'bongoto_enqueue_comment_reply' );
/**
* Template functions for comments
*/
if ( ! function_exists( 'bongoto_list_comments' ) ) {
function bongoto_list_comments( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
?>
id="li-comment-">
is_main_query() && $query->is_search() ) {
$query->set( 'post_type', 'product' );
}
}
add_action( 'pre_get_posts', 'bongoto_marketplace_search_products_only' );
/* Cart UI for header */
function bongoto_enqueue_cart_styles() {
wp_enqueue_style( 'bongoto-cart', get_template_directory_uri() . '/assets/css/cart.css', array(), '1.0' );
}
add_action( 'wp_enqueue_scripts', 'bongoto_enqueue_cart_styles' );
/* Footer Style (Optimized Version) */
function bongoto_enqueue_footer_css() {
// Main CSS
$main_path = get_template_directory() . '/assets/css/main.css';
$footer_path = get_template_directory() . '/assets/css/footer.css';
$main_ver = file_exists($main_path) ? filemtime($main_path) : '1.0';
$footer_ver = file_exists($footer_path) ? filemtime($footer_path) : '1.0';
// Load CSS
wp_enqueue_style(
'bongoto-main',
get_template_directory_uri() . '/assets/css/main.css',
array(),
$main_ver
);
wp_enqueue_style(
'bongoto-footer',
get_template_directory_uri() . '/assets/css/footer.css',
array('bongoto-main'),
$footer_ver
);
}
add_action('wp_enqueue_scripts', 'bongoto_enqueue_footer_css');