Skip to content

Commit a4e0bf6

Browse files
authored
Fixes _doing_it_wrong() messages being displayed on WordPress 6.7 due to translating too early (#3616)
* Register plugin textdomain on init * Refactor WC_Stripe_Privacy to move all registering of exporters/erasers to be after init * Don't instantiate main Stripe gateway class before init * Add changelog entry
1 parent f1da2be commit a4e0bf6

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Fix - Fix ECE modal not loading on pay for order page when coupon is applied.
99
* Fix - Do not load express payment buttons on switch subscription page.
1010
* 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.
11+
* Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled).
1112

1213
= 8.9.0 - 2024-11-14 =
1314
* Update - Enhance webhook processing to enable retrieving orders using payment_intent metadata.

includes/admin/class-wc-stripe-privacy.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ class WC_Stripe_Privacy extends WC_Abstract_Privacy {
88
* Constructor
99
*/
1010
public function __construct() {
11-
parent::__construct( __( 'Stripe', 'woocommerce-gateway-stripe' ) );
11+
parent::__construct();
12+
13+
add_action( 'init', [ $this, 'register_erasers_exporters' ] );
14+
add_filter( 'woocommerce_get_settings_account', [ $this, 'account_settings' ] );
15+
}
16+
17+
/**
18+
* Register erasers and exporters.
19+
*/
20+
public function register_erasers_exporters() {
21+
$this->name = __( 'Stripe', 'woocommerce-gateway-stripe' );
1222

1323
$this->add_exporter( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe' ), [ $this, 'order_data_exporter' ] );
1424

@@ -20,8 +30,6 @@ public function __construct() {
2030

2131
$this->add_eraser( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), [ $this, 'customer_data_eraser' ] );
2232
$this->add_eraser( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Data', 'woocommerce-gateway-stripe' ), [ $this, 'order_data_eraser' ] );
23-
24-
add_filter( 'woocommerce_get_settings_account', [ $this, 'account_settings' ] );
2533
}
2634

2735
/**

includes/admin/class-wc-stripe-settings-controller.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class WC_Stripe_Settings_Controller {
2020
/**
2121
* The Stripe gateway instance.
2222
*
23-
* @var WC_Stripe_Payment_Gateway
23+
* @var WC_Stripe_Payment_Gateway|null
2424
*/
2525
private $gateway;
2626

@@ -29,9 +29,10 @@ class WC_Stripe_Settings_Controller {
2929
*
3030
* @param WC_Stripe_Account $account Stripe account
3131
*/
32-
public function __construct( WC_Stripe_Account $account, WC_Stripe_Payment_Gateway $gateway ) {
32+
public function __construct( WC_Stripe_Account $account, WC_Stripe_Payment_Gateway $gateway = null ) {
3333
$this->account = $account;
3434
$this->gateway = $gateway;
35+
3536
add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
3637
add_action( 'wc_stripe_gateway_admin_options_wrapper', [ $this, 'admin_options' ] );
3738
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
4445
add_action( 'update_option_woocommerce_gateway_order', [ $this, 'set_stripe_gateways_in_list' ] );
4546
}
4647

48+
/**
49+
* Fetches the Stripe gateway instance.
50+
*/
51+
private function get_gateway() {
52+
if ( ! $this->gateway ) {
53+
$this->gateway = WC_Stripe::get_instance()->get_main_stripe_gateway();
54+
}
55+
56+
return $this->gateway;
57+
}
58+
4759
/**
4860
* Sets the Stripe gateways in the 'woocommerce_gateway_order' option which contains the list of all the gateways.
4961
* This function is called when the 'woocommerce_gateway_order' option is updated.
@@ -69,7 +81,7 @@ public function set_stripe_gateways_in_list( $ordering ) {
6981
*/
7082
public function hide_refund_button_for_uncaptured_orders( $order ) {
7183
try {
72-
$intent = $this->gateway->get_intent_from_order( $order );
84+
$intent = $this->get_gateway()->get_intent_from_order( $order );
7385

7486
if ( $intent && 'requires_capture' === $intent->status ) {
7587
$no_refunds_button = __( 'Refunding unavailable', 'woocommerce-gateway-stripe' );
@@ -171,7 +183,7 @@ public function admin_scripts( $hook_suffix ) {
171183
'stripe_oauth_url' => $oauth_url,
172184
'stripe_test_oauth_url' => $test_oauth_url,
173185
'show_customization_notice' => get_option( 'wc_stripe_show_customization_notice', 'yes' ) === 'yes' ? true : false,
174-
'is_test_mode' => $this->gateway->is_in_test_mode(),
186+
'is_test_mode' => $this->get_gateway()->is_in_test_mode(),
175187
'plugin_version' => WC_STRIPE_VERSION,
176188
'account_country' => $this->account->get_account_country(),
177189
'are_apms_deprecated' => WC_Stripe_Feature_Flags::are_apms_deprecated(),

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
118118
* Fix - Fix ECE modal not loading on pay for order page when coupon is applied.
119119
* Fix - Do not load express payment buttons on switch subscription page.
120120
* 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.
121+
* Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled).
121122

122123
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

woocommerce-gateway-stripe.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function init() {
285285
require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-payment-requests-controller.php';
286286
new WC_Stripe_Payment_Requests_Controller();
287287
} else {
288-
new WC_Stripe_Settings_Controller( $this->account, $this->get_main_stripe_gateway() );
288+
new WC_Stripe_Settings_Controller( $this->account );
289289
}
290290

291291
if ( WC_Stripe_Feature_Flags::is_upe_checkout_enabled() ) {
@@ -318,6 +318,7 @@ public function init() {
318318

319319
// Intitialize the class for updating subscriptions' Legacy SEPA payment methods.
320320
add_action( 'init', [ $this, 'initialize_subscriptions_updater' ] );
321+
add_action( 'init', [ $this, 'load_plugin_textdomain' ] );
321322
}
322323

323324
/**
@@ -787,6 +788,10 @@ public function initialize_subscriptions_updater() {
787788
$updater->init();
788789
$updater->maybe_update();
789790
}
791+
792+
public function load_plugin_textdomain() {
793+
load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
794+
}
790795
}
791796

792797
$plugin = WC_Stripe::get_instance();
@@ -799,8 +804,6 @@ public function initialize_subscriptions_updater() {
799804
add_action( 'plugins_loaded', 'woocommerce_gateway_stripe_init' );
800805

801806
function woocommerce_gateway_stripe_init() {
802-
load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
803-
804807
if ( ! class_exists( 'WooCommerce' ) ) {
805808
add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' );
806809
return;

0 commit comments

Comments
 (0)