Plugin Directory

Changeset 3444681


Ignore:
Timestamp:
01/22/2026 10:06:47 AM (2 months ago)
Author:
codersaiful
Message:

new and updated code updated for Bizzmudra plugin

Location:
bizzmudra
Files:
190 added
7 edited

Legend:

Unmodified
Added
Removed
  • bizzmudra/trunk/admin/class-admin.php

    r3434872 r3444681  
    11<?php
    22if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     3
    34/**
    4  * Admin Interface
     5 * Admin Interface Handler
     6 *
     7 * This class manages the admin interface for the Bizzmudra plugin.
     8 * It handles settings page registration, script/style enqueuing, and plugin action links.
     9 *
     10 * @package Bizzmudra
     11 * @since 1.0.0
    512 */
    613class BIZZMUDRA_Admin {
    714   
     15    /**
     16     * Plugin slug for menu and asset registration
     17     *
     18     * @var string
     19     */
    820    public $slug = 'bizzmudra';
     21   
     22    /**
     23     * Plugin base name for action links
     24     *
     25     * @var string
     26     */
    927    public $plugin_base = BIZZMUDRA_PLUGIN_BASE;
     28   
     29    /**
     30     * Singleton instance
     31     *
     32     * @var BIZZMUDRA_Admin|null
     33     */
    1034    private static $instance = null;
    1135   
     36    /**
     37     * Get singleton instance
     38     *
     39     * @return BIZZMUDRA_Admin
     40     */
    1241    public static function get_instance() {
    1342        if (null === self::$instance) {
     
    1746    }
    1847   
     48    /**
     49     * Constructor
     50     * Initializes admin hooks and loads the settings framework
     51     */
    1952    private function __construct() {
    20         add_action('admin_menu', array($this, 'add_menu'));
    21         add_action('admin_init', array($this, 'save_settings'));
     53        // Load the framework settings
     54        $this->load_framework();
    2255
    23         //Add settings link on plugin page and row meta links
     56        // Add settings link on plugin page and row meta links
    2457        add_filter( 'plugin_action_links_' . $this->plugin_base, array( $this, 'plugin_action_links' ) );
    2558        add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 );
     59
     60        // Enqueue admin CSS and JavaScript
     61        add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
    2662    }
    27    
     63
    2864    /**
    29      * Add admin menu
     65     * Load the options framework
     66     * Includes the framework loader file for settings panel
    3067     */
    31     public function add_menu() {
    32         add_submenu_page(
    33             'woocommerce',
    34             __('Multi Currency', 'bizzmudra'),
    35             __('Multi Currency', 'bizzmudra'),
    36             'manage_woocommerce',
    37             $this->slug,
    38             array($this, 'settings_page')
    39         );
     68    private function load_framework() {
     69        require_once BIZZMUDRA_PLUGIN_DIR . 'admin/framework-loader.php';
     70    }
     71
     72    /**
     73     * Enqueue admin scripts and styles
     74     *
     75     * Loads necessary CSS and JavaScript files for the admin settings page.
     76     * Also localizes exchange rate data for JavaScript use.
     77     */
     78    public function admin_enqueue_scripts( $hook ) {
     79        // Load scripts and styles only on our plugin settings page
     80        if ( strpos( $hook, $this->slug ) !== false ) {
     81
     82            wp_enqueue_style( 'woocommerce_admin_styles' );
     83            wp_enqueue_script( 'selectWoo' );
     84            wp_enqueue_style( 'select2' );
     85
     86            wp_enqueue_style( $this->slug . '-admin', BIZZMUDRA_PLUGIN_URL . 'assets/css/admin.css', array(), BIZZMUDRA_VERSION );
     87            wp_enqueue_script( $this->slug . '-admin', BIZZMUDRA_PLUGIN_URL . 'assets/js/admin.js', [ 'jquery', 'selectWoo' ], BIZZMUDRA_VERSION, true );
     88           
     89            // Get exchange rates for JavaScript (relative to WooCommerce base currency)
     90            $exchange_rate_instance = BIZZMUDRA_Exchange_Rate::get_instance();
     91            $exchange_rates = $exchange_rate_instance->get_all_rates_relative_to_base();
     92           
     93            // Localize script with exchange rates data and AJAX settings
     94            wp_localize_script( $this->slug . '-admin', 'bizzmudraAdmin', array(
     95                'ajax_url'       => admin_url( 'admin-ajax.php' ),
     96                'nonce'          => wp_create_nonce( 'bizzmudra_admin_nonce' ),
     97                'exchange_rates' => $exchange_rates,
     98                'base_currency'  => $exchange_rate_instance->get_base_currency(),
     99            ) );
     100        }
    40101    }
    41102
     
    63124        return $links;
    64125    }
    65     /**
    66      * Settings page
    67      */
    68     public function settings_page() {
    69         $data = BIZZMUDRA_Currency_Data::get_instance();
    70         $bizzmudra_settings = $data->get_settings();
    71        
    72         include BIZZMUDRA_PLUGIN_DIR . 'admin/views/settings.php';
    73     }
    74    
    75     /**
    76      * Save settings
    77      */
    78     public function save_settings() {
    79 
    80         $nonce = sanitize_text_field( wp_unslash( $_POST['bizzmudra_settings_nonce'] ?? '' ) );
    81        
    82         if ( empty( $nonce ) || !wp_verify_nonce($nonce, 'bizzmudra_save_settings')) {
    83             return;
    84         }
    85        
    86         if (!current_user_can('manage_woocommerce')) {
    87             return;
    88         }
    89         //use wp_unslash
    90         $bizzmudra_settings = array(
    91             'enabled' => isset($_POST['bizzmudra_enabled']) ? 1 : 0,
    92             'display_position' => isset($_POST['bizzmudra_display_position']) ? sanitize_text_field(wp_unslash($_POST['bizzmudra_display_position'])) : 'shop_page',
    93             'show_on_product_page' => isset($_POST['bizzmudra_show_on_product_page']) ? 1 : 0,
    94             'currencies' => array()
    95         );
    96 
    97         // Process currencies
    98         if (isset($_POST['bizzmudra_currencies'])) {
    99             //All Sanitization is done here in foreach
    100             //phpcs:ignore  WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    101             $currencies = wp_unslash($_POST['bizzmudra_currencies']);
    102             $currencies = is_array($currencies) ? $currencies : array();
    103             foreach ($currencies as $bizzmudra_code => $bizzmudra_currency) {
    104                 $bizzmudra_settings['currencies'][sanitize_text_field($bizzmudra_code)] = array(
    105                     'rate' => floatval($bizzmudra_currency['rate']),
    106                     'symbol' => sanitize_text_field($bizzmudra_currency['symbol']),
    107                     'position' => sanitize_text_field($bizzmudra_currency['position']),
    108                     'decimals' => intval($bizzmudra_currency['decimals']),
    109                     'enabled' => isset($bizzmudra_currency['enabled']) ? 1 : 0
    110                 );
    111             }
    112         }
    113        
    114         $data = BIZZMUDRA_Currency_Data::get_instance();
    115         $data->update_settings($bizzmudra_settings);
    116        
    117         add_settings_error('bizzmudra_messages', 'bizzmudra_message', __('Settings saved.', 'bizzmudra'), 'updated');
    118     }
    119126   
    120127}
  • bizzmudra/trunk/bizzmudra.php

    r3434872 r3444681  
    1010 *
    1111 *
    12  * Version: 1.0.3
     12 * Version: 1.0.6
    1313 * Requires at least: 6.2
    1414 * Tested up to: 6.9
     
    3232// Define plugin constants
    3333if ( ! defined( 'BIZZMUDRA_VERSION' ) ) {
    34     define( 'BIZZMUDRA_VERSION', '1.0.0' );
     34    define( 'BIZZMUDRA_VERSION', '1.0.6.3' );
    3535}
    3636if (!defined('BIZZMUDRA_PLUGIN_DIR')) {
     
    118118    private function includes() {
    119119        require_once BIZZMUDRA_PLUGIN_DIR . 'includes/functions.php';
     120        require_once BIZZMUDRA_PLUGIN_DIR . 'includes/class-exchange-rate.php';
    120121        require_once BIZZMUDRA_PLUGIN_DIR . 'includes/class-currency-data.php';
    121122        require_once BIZZMUDRA_PLUGIN_DIR . 'includes/class-price-converter.php';
     
    125126        if (is_admin()) {
    126127            require_once BIZZMUDRA_PLUGIN_DIR . 'admin/class-admin.php';
    127         } else {
    128             require_once BIZZMUDRA_PLUGIN_DIR . 'public/class-public.php';
    129128        }
     129
     130        require_once BIZZMUDRA_PLUGIN_DIR . 'public/class-public.php';
    130131    }
    131132   
     
    142143        if (is_admin()) {
    143144            BIZZMUDRA_Admin::get_instance();
    144         } else {
    145             BIZZMUDRA_Public::get_instance();
    146145        }
     146        BIZZMUDRA_Public::get_instance();
    147147    }
    148148   
     
    151151     */
    152152    public function activate() {
    153         // Set default options
     153        // Set default options using new repeater format
     154        // Using string values for consistency with framework's switch field
    154155        $default_settings = array(
    155             'enabled' => 1,
     156            'enabled' => '1',
     157            'display_position' => 'shop_page',
     158            'show_on_product_page' => '0',
    156159            'currencies' => array(
    157                 'USD' => array(
    158                     'rate' => 1,
     160                array(
     161                    'code' => 'USD',
     162                    'rate' => '1',
    159163                    'symbol' => '$',
    160164                    'position' => 'left',
    161                     'decimals' => 2
     165                    'decimals' => '2',
     166                    'enabled' => '1'
    162167                )
    163168            ),
     
    166171       
    167172        add_option('bizzmudra_settings', $default_settings);
     173
     174        // setup wizard redirection
     175        add_option( BIZZMUDRA_PLUGIN_BASE, true );
    168176    }
    169177   
  • bizzmudra/trunk/includes/class-currency-data.php

    r3433511 r3444681  
    1818        $this->settings = get_option('bizzmudra_settings', array());
    1919    }
     20
     21    /**
     22     * Convert repeater format currencies to associative array format
     23     * The framework stores currencies as an indexed array, but we need to work with currency code as key
     24     *
     25     * @param array $currencies_array Indexed array from repeater field
     26     * @return array Associative array with currency code as key
     27     */
     28    private function normalize_currencies($currencies_array) {
     29        if (empty($currencies_array) || !is_array($currencies_array)) {
     30            return array();
     31        }
     32
     33        // Check if this is an indexed array (new repeater format) or associative array (old format)
     34        // Old format: array('USD' => array('rate' => 1, ...), 'EUR' => array('rate' => 0.85, ...))
     35        // New format: array(array('code' => 'USD', 'rate' => 1, ...), array('code' => 'EUR', 'rate' => 0.85, ...))
     36        $first_key = array_key_first($currencies_array);
     37       
     38        // If the first key is a string (currency code like 'USD'), it's the old format
     39        if (is_string($first_key) && strlen($first_key) === 3) {
     40            return $currencies_array;
     41        }
     42
     43        $normalized = array();
     44       
     45        foreach ($currencies_array as $currency) {
     46            // New repeater format
     47            if (is_array($currency) && isset($currency['code'])) {
     48                $code = $currency['code'];
     49                $normalized[$code] = array(
     50                    'rate'     => isset($currency['rate']) ? floatval($currency['rate']) : 1,
     51                    // 'symbol'   => isset($currency['symbol']) ? $currency['symbol'] : $this->get_default_symbol($code),
     52                    'position' => isset($currency['position']) ? $currency['position'] : 'left',
     53                    'decimals' => isset($currency['decimals']) ? intval($currency['decimals']) : 2,
     54                    'enabled'  => isset($currency['enabled']) ? $currency['enabled'] : 1,
     55                );
     56            }
     57        }
     58       
     59        return $normalized;
     60    }
     61
     62    /**
     63     * Get default currency symbol from WooCommerce
     64     *
     65     * @param string $code Currency code
     66     * @return string Currency symbol
     67     */
     68    private function get_default_symbol($code) {
     69        if (function_exists('get_woocommerce_currency_symbol')) {
     70            return get_woocommerce_currency_symbol($code);
     71        }
     72        return $code;
     73    }
    2074   
    2175    /**
     
    2680     */
    2781    public function get_all_currencies() {
    28         return isset($this->settings['currencies']) ? $this->settings['currencies'] : array();
     82        $currencies = isset($this->settings['currencies']) ? $this->settings['currencies'] : array();
     83        return $this->normalize_currencies($currencies);
    2984    }
    3085   
     
    4398            // Default to enabled (1) if not set for backward compatibility
    4499            $is_enabled = isset($currency['enabled']) ? $currency['enabled'] : 1;
    45             if ($is_enabled) {
     100            // Use filter_var for consistent boolean evaluation (handles '1', 1, 'true', true, etc.)
     101            if (filter_var($is_enabled, FILTER_VALIDATE_BOOLEAN)) {
    46102                $enabled_currencies[$code] = $currency;
    47103            }
  • bizzmudra/trunk/includes/functions.php

    r3433511 r3444681  
    1111 */
    1212function bizzmudra_country_code_to_flag_emoji( $country_code ) {
     13    $country_code = substr($country_code, 0, 2);
    1314    $country_code = strtoupper( $country_code );
    1415    $flag = '';
  • bizzmudra/trunk/public/class-public.php

    r3433511 r3444681  
    2727       
    2828        add_filter('woocommerce_currency', array($this, 'change_currency'));
    29         add_filter('woocommerce_currency_symbol', array($this, 'change_currency_symbol'), 10, 2);
     29        // add_filter('woocommerce_currency_symbol', array($this, 'change_currency_symbol'), 10, 2);
    3030    }
    3131   
     
    170170     */
    171171    public function change_currency_symbol($symbol, $bizzmudra_currency) {
    172         $current = $this->data->get_current_currency();
    173 
    174         if ($current && $current === $bizzmudra_currency) {
    175             $custom_symbol = $this->data->get_symbol($current);
    176             if ($custom_symbol) {
    177                 return $custom_symbol;
    178             }
    179         }
     172       
     173        // $current = $this->data->get_current_currency();
     174        // if ($current && $current === $bizzmudra_currency) {
     175        //     $custom_symbol = $this->data->get_symbol($current);
     176        //     if ($custom_symbol) {
     177        //         return $custom_symbol;
     178        //     }
     179        // }
    180180       
    181181        return $symbol;
  • bizzmudra/trunk/public/class-switcher.php

    r3433511 r3444681  
    5656            return '';
    5757        }
    58        
     58
    5959        $current_currency = isset($currencies[$current]) ? $currencies[$current] : reset($currencies);
    6060        $current_code = $current ? $current : key($currencies);
     
    6464            <div class="bizzplugin-custom-dropdown">
    6565                <div class="bizzplugin-dropdown-selected" data-value="<?php echo esc_attr($current_code); ?>">
    66                     <span class="bizzplugin-flag"><?php echo esc_html( bizzmudra_country_code_to_flag_emoji(substr($current_code, 0, 2)) ); ?></span>
    67                     <span class="bizzplugin-currency-info"><?php echo esc_html($current_currency['symbol'] . ' ' . $current_code); ?></span>
     66                    <span class="bizzplugin-flag"><?php echo esc_html( bizzmudra_country_code_to_flag_emoji($current_code) ); ?></span>
     67                    <span class="bizzplugin-currency-info"><?php echo esc_html(get_woocommerce_currency_symbol($current) . ' (' . $current_code . ')' ); ?></span>
    6868                    <span class="bizzplugin-dropdown-arrow">▼</span>
    6969                </div>
     
    7171                    <?php foreach ($currencies as $bizzmudra_code => $bizzmudra_currency) : ?>
    7272                        <div class="bizzplugin-dropdown-item <?php echo ($current_code === $bizzmudra_code) ? 'bizzplugin-active' : ''; ?>" data-value="<?php echo esc_attr($bizzmudra_code); ?>">
    73                             <span class="bizzplugin-flag"><?php echo esc_html( bizzmudra_country_code_to_flag_emoji(substr($bizzmudra_code, 0, 2)) ); ?></span>
    74                             <span class="bizzplugin-currency-info"><?php echo esc_html($bizzmudra_currency['symbol'] . ' ' . $bizzmudra_code); ?></span>
     73                            <span class="bizzplugin-flag"><?php echo esc_html( bizzmudra_country_code_to_flag_emoji($bizzmudra_code) ); ?></span>
     74                            <span class="bizzplugin-currency-info"><?php echo esc_html(get_woocommerce_currency_symbol($bizzmudra_code) . ' (' . $bizzmudra_code . ')' ); ?></span>
    7575                        </div>
    7676                    <?php endforeach; ?>
  • bizzmudra/trunk/readme.txt

    r3434872 r3444681  
    77Tested up to: 6.9
    88Requires PHP: 8.0
    9 Stable tag: 1.0.3
     9Stable tag: 1.0.6
    1010License: GPLv2 or later
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8585== Changelog ==
    8686
     87= 1.0.6 =
     88* Added: Support for WooCommerce 7.9
     89* Improved: Exchange rate handling and currency conversion accuracy
     90* Fixed: Minor bugs and improved overall stability
     91* Added: Currency switcher shortcode `[bizzmudra_currency_switcher]`
     92* Added: Currency Switcher widget for sidebar display
     93* Fixed: Minor bugs and improved compatibility with latest WooCommerce version
     94* Improved code modularity and added comments for better maintainability
     95
     96
    8797= 1.0.3 =
    8898* setting page link added in plugin action links
Note: See TracChangeset for help on using the changeset viewer.