Plugin Directory

Changeset 3399343


Ignore:
Timestamp:
11/20/2025 03:34:59 AM (5 months ago)
Author:
maalypay
Message:

feat: minify blocks js file

Location:
maaly-pay
Files:
4 added
1 edited

Legend:

Unmodified
Added
Removed
  • maaly-pay/trunk/includes/class-maaly-pay-gateway-blocks.php

    r3399333 r3399343  
    77 * Class for handling Maaly Pay Gateway payment block checkout support.
    88 */
    9 final class WC_MaalyGateway_Blocks extends AbstractPaymentMethodType {
     9final class WC_MaalyGateway_Blocks extends AbstractPaymentMethodType
     10{
    1011
    1112    /**
     
    2627     * Initializes the Maaly Gateway block.
    2728     */
    28     public function initialize() {
     29    public function initialize()
     30    {
    2931        // Load settings for your gateway (if applicable)
    30         $this->settings = get_option( 'maaly_pay_settings', array() );
     32        $this->settings = get_option('maaly_pay_settings', array());
    3133
    32         $gateways       = WC()->payment_gateways->payment_gateways();
     34        $gateways = WC()->payment_gateways->payment_gateways();
    3335        // Instantiate your main payment gateway class
    34         $this->gateway = $gateways($this->name); 
     36        $this->gateway = $gateways($this->name);
    3537    }
    3638
     
    4042     * @return bool True if the payment method is active, false otherwise.
    4143     */
    42     public function is_active() {
     44    public function is_active()
     45    {
    4346        return $this->gateway->is_available(); // Or check a specific setting
    4447    }
     
    4952     * @return array The script handles for the payment method.
    5053     */
    51     public function get_payment_method_script_handles() {
     54    public function get_payment_method_script_handles()
     55    {
     56        // wp_register_script(
     57        //     'wc-maaly-pay-blocks',
     58        //     // plugins_url( 'assets/js/maaly-pay.js', __FILE__ ), // Path to your frontend script
     59        //     MAALY_PAY_PLUGIN_URL . 'assets/js/maaly-pay.js',
     60        //     ['wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'],
     61        //     '1.1.1',
     62        //     true
     63        // );
     64
     65        // if (function_exists('wp_set_script_translations')) {
     66        //     wp_set_script_translations('wc-maaly-pay-blocks');
     67        // }
     68
     69        // return ['wc-maaly-pay-blocks'];
     70
     71        $script_path = '/assets/js/blocks.js';
     72        $script_asset_path = trailingslashit(MAALY_PAY_PLUGIN_DIR) . 'assets/js/blocks.asset.php';
     73        $script_asset = file_exists($script_asset_path)
     74            ? require($script_asset_path)
     75            : array(
     76                'dependencies' => array(),
     77                'version' => '1.2.0'
     78            );
     79        $script_url = MAALY_PAY_PLUGIN_DIR . $script_path;
     80
    5281        wp_register_script(
    5382            'wc-maaly-pay-blocks',
    54             // plugins_url( 'assets/js/maaly-pay.js', __FILE__ ), // Path to your frontend script
    55             MAALY_PAY_PLUGIN_URL . 'assets/js/maaly-pay.js',
    56             [ 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n' ],
    57             '1.1.0',
     83            $script_url,
     84            $script_asset['dependencies'],
     85            $script_asset['version'],
    5886            true
    5987        );
    6088
    61         if ( function_exists( 'wp_set_script_translations' ) ) {
    62             wp_set_script_translations( 'wc-maaly-pay-blocks' );
     89        if (function_exists('wp_set_script_translations')) {
     90            wp_set_script_translations('wc-maaly-pay-blocks', 'woocommerce-gateway-maaly', trailingslashit(MAALY_PAY_PLUGIN_DIR) . 'languages/');
    6391        }
    6492
    65         return [ 'wc-maaly-pay-blocks' ];
     93        return ['wc-maaly-pay-blocks'];
    6694    }
    6795
     
    7199     * @return array The data for the payment method.
    72100     */
    73     public function get_payment_method_data() {
     101    public function get_payment_method_data()
     102    {
    74103        return [
    75             'title'       => $this->gateway->title,
     104            'title' => $this->gateway->title,
    76105            'description' => $this->gateway->description,
    77             'supports'    => array_filter( $this->gateway->supports, [ $this->gateway, 'supports' ] )
     106            'supports' => array_filter($this->gateway->supports, [$this->gateway, 'supports'])
    78107            // Add any other data needed by your frontend script
    79108        ];
Note: See TracChangeset for help on using the changeset viewer.