/** * WCFM Vendor Store URL Functions * * @package Reign-child * @subpackage WCFM Vendor Extensions * @since 1.0.0 * @author WB COM * * This file contains functions for retrieving a WCFM vendor's store URL * and providing it via shortcode for easy use in content. */ /** * Shortcode to display the current user's vendor store URL if they are a vendor * * @param array $atts Shortcode attributes * @return string Formatted HTML link or # if conditions not met * * Usage: * [vendor_store_url] - Default link text "My Store" * [vendor_store_url text="Visit My Store"] - Custom link text * [vendor_store_url text="My Chef Profile" class="custom-button"] - Custom CSS class */ function wbcom_get_vendor_store_url_shortcode($atts) { // Default attributes $atts = shortcode_atts( array( 'text' => 'My Store', // Default link text 'class' => 'vendor-store-link', // Default CSS class ), $atts, 'vendor_store_url' ); // Check if user is logged in if (!is_user_logged_in()) { return '#'; // Return # if not logged in } // Get current user $current_user = wp_get_current_user(); $user_id = $current_user->ID; // Check if user is a vendor (has wcfm_vendor role) if (!in_array('wcfm_vendor', (array) $current_user->roles)) { return '#'; // Return # if not a vendor } // Get the vendor's store URL if (function_exists('wcfmmp_get_store_url')) { $store_url = wcfmmp_get_store_url($user_id); // Return formatted link return '' . esc_html($atts['text']) . ''; } return '#'; // Return # if function doesn't exist } add_shortcode('vendor_store_url', 'wbcom_get_vendor_store_url_shortcode'); /** * Function to programmatically get vendor store URL * * @param int $user_id User ID (optional, defaults to current user) * @return string Store URL or # if conditions not met * * Can be used in theme files with: * Or for specific user: */ function wbcom_get_wcfm_vendor_store_url($user_id = 0) { // If no user ID is provided, use current user if ($user_id === 0 && is_user_logged_in()) { $user_id = get_current_user_id(); } // Check if user exists and is a vendor if ($user_id > 0) { $user = get_userdata($user_id); if ($user && in_array('wcfm_vendor', (array) $user->roles)) { // Get the vendor's store URL if (function_exists('wcfmmp_get_store_url')) { return wcfmmp_get_store_url($user_id); } } } return '#'; // Return # if not a vendor or if function doesn't exist }