Plugin Directory

Changeset 3489607


Ignore:
Timestamp:
03/24/2026 04:24:31 AM (4 days ago)
Author:
smjrifle
Message:

Fix woocommerce dependency check and block checkout warning

Location:
smjrifle-qr-payments
Files:
6 edited
7 copied

Legend:

Unmodified
Added
Removed
  • smjrifle-qr-payments/tags/1.0.1/admin/class-smjrifle-qr-payments-admin.php

    r3472048 r3489607  
    1818        add_action('add_meta_boxes', array($this, 'add_meta_box'), 10, 3);
    1919        add_action('woocommerce_email_order_meta', array($this, 'receipt_email_meta'), 10, 3);
     20        add_action('admin_notices', array($this, 'checkout_block_warning'));
     21    }
     22
     23    public function checkout_block_warning()
     24    {
     25        if (!function_exists('wc_get_page_id') || !function_exists('has_block')) {
     26            return;
     27        }
     28
     29        $checkout_page_id = wc_get_page_id('checkout');
     30        if ($checkout_page_id && has_block('woocommerce/checkout', $checkout_page_id)) {
     31            $options = get_option('woocommerce_smjrifle_qr_payments_settings');
     32            if (isset($options['enabled']) && $options['enabled'] === 'yes') {
     33                echo '<div class="notice notice-warning is-dismissible"><p><strong>' . esc_html__('Smjrifle QR Payments:', 'smjrifle-qr-payments') . '</strong> ' . esc_html__('Your checkout page is currently using the WooCommerce Checkout Block. This custom payment gateway relies on the classic WooCommerce checkout shortcode. Please edit your Checkout page, remove the block, and insert the [woocommerce_checkout] shortcode for the payment method to appear.', 'smjrifle-qr-payments') . '</p></div>';
     34            }
     35        }
    2036    }
    2137
     
    6278    public function add_meta_box()
    6379    {
     80        if (!function_exists('wc_get_page_screen_id')) return;
     81        $screen = wc_get_page_screen_id('shop_order');
     82
     83        if (!$screen) {
     84            $screen = 'shop_order';
     85        }
    6486        add_meta_box(
    6587            'smjrifle-qr-payments-meta-box',
    6688            esc_html__('Payment Receipt', 'smjrifle-qr-payments'),
    6789            array($this, 'meta_box_callback'),
    68             wc_get_page_screen_id('shop-order'),
     90            $screen,
    6991            'side',
    7092            'default'
  • smjrifle-qr-payments/tags/1.0.1/includes/class-smjrifle-qr-payments.php

    r3472048 r3489607  
    1515    {
    1616        $this->plugin_name = 'smjrifle-qr-payments';
    17         $this->version = '2.0.0';
     17        $this->version = defined('SMJ_QR_PAYMENTS_VERSION') ? SMJ_QR_PAYMENTS_VERSION : '1.0.0';
    1818
    1919        $this->load_dependencies();
     
    5151    {
    5252        $this->define_public_hooks();
    53         add_action('plugins_loaded', array($this, 'init_gateway'));
     53        add_action('woocommerce_init', [$this, 'init_gateway']);
    5454    }
    5555
  • smjrifle-qr-payments/tags/1.0.1/readme.txt

    r3472048 r3489607  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.0
     7Stable tag: 1.0.1
    88License: GPL v2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • smjrifle-qr-payments/tags/1.0.1/smjrifle-qr-payments.php

    r3472048 r3489607  
    44 * Plugin Name: Smjrifle QR Payments
    55 * Description: A modern, secure, and class-based WooCommerce payment method for QR code payments.
    6  * Version: 1.0.0
     6 * Version: 1.0.1
    77 * Requires at least: 5.6
    88 * Requires PHP: 7.4
     
    1212 * License: GPL-2.0-or-later
    1313 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
     14 * Requires Plugins: woocommerce
    1415 */
    1516
     
    1920}
    2021
    21 /**
    22  * The core plugin class that is used to define internationalization,
    23  * admin-specific hooks, and public-facing site hooks.
    24  */
    25 require plugin_dir_path(__FILE__) . 'includes/class-smjrifle-qr-payments.php';
     22define('SMJ_QR_PAYMENTS_VERSION', '1.0.1');
    2623
    27 /**
    28  * Begins execution of the plugin.
    29  */
    30 function smjrifle_qr_payments_run()
     24add_action('plugins_loaded', 'smjrifle_qr_payments_init', 20);
     25
     26function smjrifle_qr_payments_init()
    3127{
     28    if (!class_exists('WooCommerce')) {
     29
     30        add_action('admin_notices', 'smjrifle_qr_missing_wc_notice');
     31
     32        add_action('admin_init', function () {
     33            deactivate_plugins(plugin_basename(__FILE__));
     34        });
     35
     36        return;
     37    }
     38
     39    require_once plugin_dir_path(__FILE__) . 'includes/class-smjrifle-qr-payments.php';
     40
    3241    $plugin = new Smjrifle_QR_Payments();
    3342    $plugin->run();
    3443}
    35 smjrifle_qr_payments_run();
     44
     45function smjrifle_qr_missing_wc_notice()
     46{
     47?>
     48    <div class="notice notice-error">
     49        <p>
     50            <strong>Smjrifle QR Payments:</strong>
     51            WooCommerce must be installed and active.
     52        </p>
     53    </div>
     54<?php
     55}
  • smjrifle-qr-payments/trunk/admin/class-smjrifle-qr-payments-admin.php

    r3472048 r3489607  
    1818        add_action('add_meta_boxes', array($this, 'add_meta_box'), 10, 3);
    1919        add_action('woocommerce_email_order_meta', array($this, 'receipt_email_meta'), 10, 3);
     20        add_action('admin_notices', array($this, 'checkout_block_warning'));
     21    }
     22
     23    public function checkout_block_warning()
     24    {
     25        if (!function_exists('wc_get_page_id') || !function_exists('has_block')) {
     26            return;
     27        }
     28
     29        $checkout_page_id = wc_get_page_id('checkout');
     30        if ($checkout_page_id && has_block('woocommerce/checkout', $checkout_page_id)) {
     31            $options = get_option('woocommerce_smjrifle_qr_payments_settings');
     32            if (isset($options['enabled']) && $options['enabled'] === 'yes') {
     33                echo '<div class="notice notice-warning is-dismissible"><p><strong>' . esc_html__('Smjrifle QR Payments:', 'smjrifle-qr-payments') . '</strong> ' . esc_html__('Your checkout page is currently using the WooCommerce Checkout Block. This custom payment gateway relies on the classic WooCommerce checkout shortcode. Please edit your Checkout page, remove the block, and insert the [woocommerce_checkout] shortcode for the payment method to appear.', 'smjrifle-qr-payments') . '</p></div>';
     34            }
     35        }
    2036    }
    2137
     
    6278    public function add_meta_box()
    6379    {
     80        if (!function_exists('wc_get_page_screen_id')) return;
     81        $screen = wc_get_page_screen_id('shop_order');
     82
     83        if (!$screen) {
     84            $screen = 'shop_order';
     85        }
    6486        add_meta_box(
    6587            'smjrifle-qr-payments-meta-box',
    6688            esc_html__('Payment Receipt', 'smjrifle-qr-payments'),
    6789            array($this, 'meta_box_callback'),
    68             wc_get_page_screen_id('shop-order'),
     90            $screen,
    6991            'side',
    7092            'default'
  • smjrifle-qr-payments/trunk/includes/class-smjrifle-qr-payments.php

    r3472048 r3489607  
    1515    {
    1616        $this->plugin_name = 'smjrifle-qr-payments';
    17         $this->version = '2.0.0';
     17        $this->version = defined('SMJ_QR_PAYMENTS_VERSION') ? SMJ_QR_PAYMENTS_VERSION : '1.0.0';
    1818
    1919        $this->load_dependencies();
     
    5151    {
    5252        $this->define_public_hooks();
    53         add_action('plugins_loaded', array($this, 'init_gateway'));
     53        add_action('woocommerce_init', [$this, 'init_gateway']);
    5454    }
    5555
  • smjrifle-qr-payments/trunk/readme.txt

    r3472048 r3489607  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.0
     7Stable tag: 1.0.1
    88License: GPL v2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • smjrifle-qr-payments/trunk/smjrifle-qr-payments.php

    r3472048 r3489607  
    44 * Plugin Name: Smjrifle QR Payments
    55 * Description: A modern, secure, and class-based WooCommerce payment method for QR code payments.
    6  * Version: 1.0.0
     6 * Version: 1.0.1
    77 * Requires at least: 5.6
    88 * Requires PHP: 7.4
     
    1212 * License: GPL-2.0-or-later
    1313 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
     14 * Requires Plugins: woocommerce
    1415 */
    1516
     
    1920}
    2021
    21 /**
    22  * The core plugin class that is used to define internationalization,
    23  * admin-specific hooks, and public-facing site hooks.
    24  */
    25 require plugin_dir_path(__FILE__) . 'includes/class-smjrifle-qr-payments.php';
     22define('SMJ_QR_PAYMENTS_VERSION', '1.0.1');
    2623
    27 /**
    28  * Begins execution of the plugin.
    29  */
    30 function smjrifle_qr_payments_run()
     24add_action('plugins_loaded', 'smjrifle_qr_payments_init', 20);
     25
     26function smjrifle_qr_payments_init()
    3127{
     28    if (!class_exists('WooCommerce')) {
     29
     30        add_action('admin_notices', 'smjrifle_qr_missing_wc_notice');
     31
     32        add_action('admin_init', function () {
     33            deactivate_plugins(plugin_basename(__FILE__));
     34        });
     35
     36        return;
     37    }
     38
     39    require_once plugin_dir_path(__FILE__) . 'includes/class-smjrifle-qr-payments.php';
     40
    3241    $plugin = new Smjrifle_QR_Payments();
    3342    $plugin->run();
    3443}
    35 smjrifle_qr_payments_run();
     44
     45function smjrifle_qr_missing_wc_notice()
     46{
     47?>
     48    <div class="notice notice-error">
     49        <p>
     50            <strong>Smjrifle QR Payments:</strong>
     51            WooCommerce must be installed and active.
     52        </p>
     53    </div>
     54<?php
     55}
Note: See TracChangeset for help on using the changeset viewer.