__( 'Upload', 'bongoto' ), 'url' => bongoto_get_upload_url(), 'icon' => 'upload' )
: array( 'label' => __( 'Start Selling', 'bongoto' ), 'url' => bongoto_get_start_selling_url(), 'icon' => 'upload' );
return apply_filters( 'bongoto/header_cta', $payload );
}
}
/* ----------------
* 3) Body classes
* ---------------- */
if ( ! function_exists( 'bongoto_dokan_body_class' ) ) {
function bongoto_dokan_body_class( $classes ) {
if ( bongoto_is_dokan_active() ) {
$classes[] = 'has-dokan';
if ( bongoto_is_vendor_user() ) {
$classes[] = 'is-vendor';
}
}
return $classes;
}
}
add_filter( 'body_class', 'bongoto_dokan_body_class' );
/* ---------------------------------------------------------------
* 4) My Account dashboard: “Become a Seller” button (customers)
* --------------------------------------------------------------- */
if ( ! function_exists( 'bongoto_account_become_seller_button' ) ) {
function bongoto_account_become_seller_button() {
if ( ! is_user_logged_in() || bongoto_is_vendor_user() ) {
return;
}
$target = '';
if ( bongoto_is_dokan_active() && function_exists( 'dokan_get_page_url' ) ) {
$maybe = dokan_get_page_url( 'registration', 'dokan' );
if ( ! $maybe ) {
$maybe = dokan_get_page_url( 'reg', 'dokan' );
}
if ( $maybe ) {
$target = $maybe;
}
}
if ( ! $target ) {
$target = bongoto_get_start_selling_url();
}
echo '
';
}
}
add_action( 'woocommerce_account_dashboard', 'bongoto_account_become_seller_button', 25 );
/* ----------------------------------------------------------------
* 5) Auto-upgrade: ?become_vendor=1 → customer → seller (no loop)
* ---------------------------------------------------------------- */
if ( ! function_exists( 'bongoto_handle_become_vendor' ) ) {
function bongoto_handle_become_vendor() {
$param = isset( $_GET['become_vendor'] ) ? wp_unslash( $_GET['become_vendor'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( '1' !== $param ) {
return;
}
// Must be logged in; login screen will preserve redirect via login filter below.
if ( ! is_user_logged_in() ) {
return;
}
// Already a seller → dashboard.
if ( bongoto_is_vendor_user() ) {
wp_safe_redirect( bongoto_dokan_dashboard_url() );
exit;
}
$user_id = get_current_user_id();
// Prefer Dokan APIs.
if ( bongoto_is_dokan_active() ) {
if ( function_exists( 'dokan_set_new_seller_role' ) ) {
dokan_set_new_seller_role( $user_id );
} else {
$user = new WP_User( $user_id );
$user->add_role( 'seller' );
}
update_user_meta( $user_id, 'dokan_enable_selling', 'yes' );
// Bootstrap minimal profile if missing (helps first-time dashboard UX).
$profile = get_user_meta( $user_id, 'dokan_profile_settings', true );
if ( empty( $profile ) || ! is_array( $profile ) ) {
$display = wp_get_current_user()->display_name;
update_user_meta(
$user_id,
'dokan_profile_settings',
array( 'store_name' => $display ? ( $display . '\'s Store' ) : 'My Store' )
);
}
wp_safe_redirect( bongoto_dokan_dashboard_url() );
exit;
}
// If Dokan is missing, just land back on account page.
wp_safe_redirect( bongoto_safe_account_url() );
exit;
}
}
add_action( 'template_redirect', 'bongoto_handle_become_vendor', 1 );
/* -----------------------------------------------------------------
* 6) Login redirect: preserve become_vendor=1 intent after login
* ----------------------------------------------------------------- */
if ( ! function_exists( 'bongoto_login_redirect_vendor' ) ) {
/**
* @param string $redirect Default redirect.
* @param WP_User $user Logged in user.
*/
function bongoto_login_redirect_vendor( $redirect, $user ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$want_vendor = false;
// Check query param or referrer query.
$req = isset( $_REQUEST['become_vendor'] ) ? wp_unslash( $_REQUEST['become_vendor'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
if ( '1' === $req ) {
$want_vendor = true;
} else {
$ref = isset( $_SERVER['HTTP_REFERER'] ) ? wp_unslash( $_SERVER['HTTP_REFERER'] ) : '';
if ( $ref && false !== strpos( $ref, 'become_vendor=1' ) ) {
$want_vendor = true;
}
}
if ( $want_vendor ) {
return add_query_arg( 'become_vendor', '1', bongoto_safe_account_url() );
}
return $redirect;
}
}
add_filter( 'woocommerce_login_redirect', 'bongoto_login_redirect_vendor', 10, 2 );
/* --------------------------
* 7) Optional header links
* -------------------------- */
if ( ! function_exists( 'bongoto_dokan_account_link' ) ) {
function bongoto_dokan_account_link() {
$url = bongoto_safe_account_url();
echo '';
if ( function_exists( 'bongoto_icon' ) ) {
bongoto_icon( 'account', array( 'width' => 20, 'height' => 20 ) );
}
echo '' . esc_html__( 'My Account', 'bongoto' ) . '';
}
}
if ( ! function_exists( 'bongoto_dokan_store_link' ) ) {
function bongoto_dokan_store_link() {
if ( ! bongoto_is_vendor_user() ) {
return;
}
$url = bongoto_dokan_store_url();
echo '' . esc_html__( 'My Store', 'bongoto' ) . '';
}
}