Skip to content

Commit 953cdab

Browse files
committed
fix: move MONEI_MAIN_FILE constant to bootstrap file and fix type hints
1. The MONEI_MAIN_FILE constant was defined in class-woocommerce-gateway-monei.php (__FILE__) but WordPress only fires plugin_action_links_{plugin} filter for the actual plugin bootstrap file (woocommerce-gateway-monei.php). This caused the Settings link to never appear in the WordPress plugins list. Fixed by defining MONEI_MAIN_FILE in woocommerce-gateway-monei.php before including the class file, so it correctly points to the plugin bootstrap. 2. Fixed PHPStan errors in MoneiAppleGoogleBlocksSupport by changing gateway property type from abstract WCMoneiPaymentGateway to concrete WCGatewayMoneiAppleGoogle class. This allows PHPStan to recognize the isGoogleAvailable() and isAppleAvailable() methods. Fixes Settings link visibility in WordPress admin.
1 parent 26b9a35 commit 953cdab

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

class-woocommerce-gateway-monei.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function define_constants() {
129129
$this->define( 'MONEI_WEB', 'https://monei.com/' );
130130
$this->define( 'MONEI_REVIEW', 'https://wordpress.org/support/plugin/monei/reviews/?rate=5#new-post' );
131131
$this->define( 'MONEI_SUPPORT', 'https://support.monei.com/' );
132-
$this->define( 'MONEI_MAIN_FILE', __FILE__ );
132+
// MONEI_MAIN_FILE now defined in woocommerce-gateway-monei.php bootstrap file
133133
}
134134

135135
/**

src/Gateways/Blocks/MoneiAppleGoogleBlocksSupport.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@
99
final class MoneiAppleGoogleBlocksSupport extends AbstractPaymentMethodType {
1010

1111
protected $name = 'monei_apple_google';
12-
/**
13-
* @var WCGatewayMoneiAppleGoogle
14-
*/
15-
public WCMoneiPaymentGateway $gateway;
12+
/** @var WCGatewayMoneiAppleGoogle */
13+
public WCGatewayMoneiAppleGoogle $gateway;
1614

1715
/**
1816
* @param WCGatewayMoneiAppleGoogle $gateway
1917
*/
20-
public function __construct( WCMoneiPaymentGateway $gateway ) {
18+
public function __construct( WCGatewayMoneiAppleGoogle $gateway ) {
2119
$this->gateway = $gateway;
2220
}
2321

2422
public function initialize() {
2523
$this->settings = get_option( 'woocommerce_monei_apple_google_settings', array() );
2624
}
2725

28-
2926
public function is_active() {
3027
// Order-pay page always uses classic checkout
3128
if ( is_checkout_pay_page() ) {
@@ -43,7 +40,6 @@ public function is_active() {
4340
return 'yes' === ( $this->get_setting( 'enabled' ) ?? 'no' );
4441
}
4542

46-
4743
public function get_payment_method_script_handles() {
4844
// Order-pay page uses classic checkout, not blocks
4945
if ( is_checkout_pay_page() ) {
@@ -88,7 +84,6 @@ public function get_payment_method_script_handles() {
8884
return array( $script_name );
8985
}
9086

91-
9287
public function get_payment_method_data() {
9388
$supports = $this->gateway->supports;
9489
$total = WC()->cart !== null ? WC()->cart->get_total( false ) : 0;
@@ -120,7 +115,6 @@ public function get_payment_method_data() {
120115
'logoGoogle' => $isGoogleEnabled ? $logoGoogle : false,
121116
'logoApple' => $isAppleEnabled ? $logoApple : false,
122117
'supports' => $supports,
123-
124118
// yes: test mode.
125119
// no: live,
126120
'testMode' => $this->gateway->getTestmode(),

woocommerce-gateway-monei.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ function delete_payment_methods_transients_on_update($upgrader_object, $options)
8585

8686
add_action('upgrader_process_complete', 'delete_payment_methods_transients_on_update', 10, 2);
8787

88+
// Define main plugin file constant for plugin_action_links filter
89+
define( 'MONEI_MAIN_FILE', __FILE__ );
90+
8891
require_once 'class-woocommerce-gateway-monei.php';
8992
function WC_Monei() {
9093
return Woocommerce_Gateway_Monei::instance();

0 commit comments

Comments
 (0)