From 0361256bf4e7d9475cc021ad82c254777ee6b0a8 Mon Sep 17 00:00:00 2001 From: mattallan Date: Thu, 21 Nov 2024 13:51:29 +1000 Subject: [PATCH 1/4] Register plugin textdomain on init --- woocommerce-gateway-stripe.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/woocommerce-gateway-stripe.php b/woocommerce-gateway-stripe.php index 5285c37ce..37370009a 100644 --- a/woocommerce-gateway-stripe.php +++ b/woocommerce-gateway-stripe.php @@ -318,6 +318,7 @@ public function init() { // Intitialize the class for updating subscriptions' Legacy SEPA payment methods. add_action( 'init', [ $this, 'initialize_subscriptions_updater' ] ); + add_action( 'init', [ $this, 'load_plugin_textdomain' ] ); } /** @@ -787,6 +788,10 @@ public function initialize_subscriptions_updater() { $updater->init(); $updater->maybe_update(); } + + public function load_plugin_textdomain() { + load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); + } } $plugin = WC_Stripe::get_instance(); @@ -799,8 +804,6 @@ public function initialize_subscriptions_updater() { add_action( 'plugins_loaded', 'woocommerce_gateway_stripe_init' ); function woocommerce_gateway_stripe_init() { - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); - if ( ! class_exists( 'WooCommerce' ) ) { add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' ); return; From a4b1be2aa5f85f54be23c436f06439c2cd29d81d Mon Sep 17 00:00:00 2001 From: mattallan Date: Thu, 21 Nov 2024 13:54:01 +1000 Subject: [PATCH 2/4] Refactor WC_Stripe_Privacy to move all registering of exporters/erasers to be after init --- includes/admin/class-wc-stripe-privacy.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/admin/class-wc-stripe-privacy.php b/includes/admin/class-wc-stripe-privacy.php index 35eb1d528..de01186b9 100644 --- a/includes/admin/class-wc-stripe-privacy.php +++ b/includes/admin/class-wc-stripe-privacy.php @@ -8,7 +8,17 @@ class WC_Stripe_Privacy extends WC_Abstract_Privacy { * Constructor */ public function __construct() { - parent::__construct( __( 'Stripe', 'woocommerce-gateway-stripe' ) ); + parent::__construct(); + + add_action( 'init', [ $this, 'register_erasers_exporters' ] ); + add_filter( 'woocommerce_get_settings_account', [ $this, 'account_settings' ] ); + } + + /** + * Register erasers and exporters. + */ + public function register_erasers_exporters() { + $this->name = __( 'Stripe', 'woocommerce-gateway-stripe' ); $this->add_exporter( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe' ), [ $this, 'order_data_exporter' ] ); @@ -20,8 +30,6 @@ public function __construct() { $this->add_eraser( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), [ $this, 'customer_data_eraser' ] ); $this->add_eraser( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Data', 'woocommerce-gateway-stripe' ), [ $this, 'order_data_eraser' ] ); - - add_filter( 'woocommerce_get_settings_account', [ $this, 'account_settings' ] ); } /** From 5b88b55c8ce87a5e88a6891a66ffa7cb1ad7d102 Mon Sep 17 00:00:00 2001 From: mattallan Date: Thu, 21 Nov 2024 14:39:32 +1000 Subject: [PATCH 3/4] Don't instantiate main Stripe gateway class before init --- .../class-wc-stripe-settings-controller.php | 20 +++++++++++++++---- woocommerce-gateway-stripe.php | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/includes/admin/class-wc-stripe-settings-controller.php b/includes/admin/class-wc-stripe-settings-controller.php index 9e17a0cb4..dfa898497 100644 --- a/includes/admin/class-wc-stripe-settings-controller.php +++ b/includes/admin/class-wc-stripe-settings-controller.php @@ -20,7 +20,7 @@ class WC_Stripe_Settings_Controller { /** * The Stripe gateway instance. * - * @var WC_Stripe_Payment_Gateway + * @var WC_Stripe_Payment_Gateway|null */ private $gateway; @@ -29,9 +29,10 @@ class WC_Stripe_Settings_Controller { * * @param WC_Stripe_Account $account Stripe account */ - public function __construct( WC_Stripe_Account $account, WC_Stripe_Payment_Gateway $gateway ) { + public function __construct( WC_Stripe_Account $account, WC_Stripe_Payment_Gateway $gateway = null ) { $this->account = $account; $this->gateway = $gateway; + add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] ); add_action( 'wc_stripe_gateway_admin_options_wrapper', [ $this, 'admin_options' ] ); add_action( 'woocommerce_order_item_add_action_buttons', [ $this, 'hide_refund_button_for_uncaptured_orders' ] ); @@ -44,6 +45,17 @@ public function __construct( WC_Stripe_Account $account, WC_Stripe_Payment_Gatew add_action( 'update_option_woocommerce_gateway_order', [ $this, 'set_stripe_gateways_in_list' ] ); } + /** + * Fetches the Stripe gateway instance. + */ + private function get_gateway() { + if ( ! $this->gateway ) { + $this->gateway = WC_Stripe::get_instance()->get_main_stripe_gateway(); + } + + return $this->gateway; + } + /** * Sets the Stripe gateways in the 'woocommerce_gateway_order' option which contains the list of all the gateways. * This function is called when the 'woocommerce_gateway_order' option is updated. @@ -69,7 +81,7 @@ public function set_stripe_gateways_in_list( $ordering ) { */ public function hide_refund_button_for_uncaptured_orders( $order ) { try { - $intent = $this->gateway->get_intent_from_order( $order ); + $intent = $this->get_gateway()->get_intent_from_order( $order ); if ( $intent && 'requires_capture' === $intent->status ) { $no_refunds_button = __( 'Refunding unavailable', 'woocommerce-gateway-stripe' ); @@ -171,7 +183,7 @@ public function admin_scripts( $hook_suffix ) { 'stripe_oauth_url' => $oauth_url, 'stripe_test_oauth_url' => $test_oauth_url, 'show_customization_notice' => get_option( 'wc_stripe_show_customization_notice', 'yes' ) === 'yes' ? true : false, - 'is_test_mode' => $this->gateway->is_in_test_mode(), + 'is_test_mode' => $this->get_gateway()->is_in_test_mode(), 'plugin_version' => WC_STRIPE_VERSION, 'account_country' => $this->account->get_account_country(), 'are_apms_deprecated' => WC_Stripe_Feature_Flags::are_apms_deprecated(), diff --git a/woocommerce-gateway-stripe.php b/woocommerce-gateway-stripe.php index 37370009a..933a8fae0 100644 --- a/woocommerce-gateway-stripe.php +++ b/woocommerce-gateway-stripe.php @@ -285,7 +285,7 @@ public function init() { require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-payment-requests-controller.php'; new WC_Stripe_Payment_Requests_Controller(); } else { - new WC_Stripe_Settings_Controller( $this->account, $this->get_main_stripe_gateway() ); + new WC_Stripe_Settings_Controller( $this->account ); } if ( WC_Stripe_Feature_Flags::is_upe_checkout_enabled() ) { From f7df58f75ed56af2d3e1cd8a94a59e66ccb06aa7 Mon Sep 17 00:00:00 2001 From: mattallan Date: Thu, 21 Nov 2024 14:47:58 +1000 Subject: [PATCH 4/4] Add changelog entry --- changelog.txt | 1 + readme.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/changelog.txt b/changelog.txt index a89c583e1..8a5419b2d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,6 +7,7 @@ * Fix - Fix ECE modal not loading on pay for order page when coupon is applied. * Fix - Do not load express payment buttons on switch subscription page. * Fix - Return 'is_live' as true in account summary response when test mode is disabled in gateway settings and charge is enabled in Stripe account. +* Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled). = 8.9.0 - 2024-11-14 = * Update - Enhance webhook processing to enable retrieving orders using payment_intent metadata. diff --git a/readme.txt b/readme.txt index fe6d0c5e5..44099e4af 100644 --- a/readme.txt +++ b/readme.txt @@ -117,5 +117,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o * Fix - Fix ECE modal not loading on pay for order page when coupon is applied. * Fix - Do not load express payment buttons on switch subscription page. * Fix - Return 'is_live' as true in account summary response when test mode is disabled in gateway settings and charge is enabled in Stripe account. +* Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled). [See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).