diff --git a/src/Settings/MollieSettingsPage.php b/src/Settings/MollieSettingsPage.php index 61e835f2..cafb4ac8 100644 --- a/src/Settings/MollieSettingsPage.php +++ b/src/Settings/MollieSettingsPage.php @@ -206,7 +206,7 @@ protected function saveApiKeys($settings) 'valueInDb' => get_option('mollie-payments-for-woocommerce_live_api_key'), 'postedValue' => isset($_POST['mollie-payments-for-woocommerce_live_api_key']) ? sanitize_text_field(wp_unslash($_POST['mollie-payments-for-woocommerce_live_api_key'])) - : '' + : '', ], 'test' => [ 'keyName' => 'mollie-payments-for-woocommerce_test_api_key', @@ -214,32 +214,13 @@ protected function saveApiKeys($settings) 'valueInDb' => get_option('mollie-payments-for-woocommerce_test_api_key'), 'postedValue' => isset($_POST['mollie-payments-for-woocommerce_test_api_key']) ? sanitize_text_field(wp_unslash($_POST['mollie-payments-for-woocommerce_test_api_key'])) - : '' - ] + : '', + ], ]; foreach ($settings as $setting) { - foreach ($apiKeys as $type => $apiKey) { - if ($setting['id'] === $apiKey['keyName']) { - if ($apiKey['postedValue'] === '**********') { - // If placeholder is detected but no DB value, validate as new key - if (!$apiKey['valueInDb']) { - $this->validateApiKeyOrRemove( - $apiKey['pattern'], - '', // No DB value; treat as new - $apiKey['keyName'] - ); - } else { - $_POST[$apiKey['keyName']] = $apiKey['valueInDb']; - } - } else { - $this->validateApiKeyOrRemove( - $apiKey['pattern'], - $apiKey['postedValue'], - $apiKey['keyName'] - ); - } - } + foreach ($apiKeys as $apiKey) { + $this->processApiKeys($setting['id'], $apiKey); } } return $settings; @@ -266,4 +247,33 @@ protected function validateApiKeyOrRemove($pattern, $value, $keyName) unset($_POST[$keyName]); } } + + /** + * @param $id + * @param array $apiKey + * @return void + */ + public function processApiKeys($id, array $apiKey): void + { + if ($id === $apiKey['keyName']) { + if ($apiKey['postedValue'] === '**********') { + // If placeholder is detected but no DB value, validate as new key + if (!$apiKey['valueInDb']) { + $this->validateApiKeyOrRemove( + $apiKey['pattern'], + '', // No DB value; treat as new + $apiKey['keyName'] + ); + } else { + $_POST[$apiKey['keyName']] = $apiKey['valueInDb']; + } + } else { + $this->validateApiKeyOrRemove( + $apiKey['pattern'], + $apiKey['postedValue'], + $apiKey['keyName'] + ); + } + } + } } diff --git a/src/Settings/Page/Section/Advanced.php b/src/Settings/Page/Section/Advanced.php index 454d0f37..a4e048a9 100644 --- a/src/Settings/Page/Section/Advanced.php +++ b/src/Settings/Page/Section/Advanced.php @@ -49,9 +49,9 @@ public function config(): array 'type' => 'select', 'options' => [ SharedDataDictionary::SETTING_LOCALE_WP_LANGUAGE => __( - 'Automatically send WordPress language', - 'mollie-payments-for-woocommerce' - ) . ' (' . __('default', 'mollie-payments-for-woocommerce') . ')', + 'Automatically send WordPress language', + 'mollie-payments-for-woocommerce' + ) . ' (' . __('default', 'mollie-payments-for-woocommerce') . ')', SharedDataDictionary::SETTING_LOCALE_DETECT_BY_BROWSER => __( 'Detect using browser language', 'mollie-payments-for-woocommerce' @@ -111,8 +111,8 @@ public function config(): array 'type' => 'select', 'options' => [ PaymentService::PAYMENT_METHOD_TYPE_ORDER => ucfirst( - PaymentService::PAYMENT_METHOD_TYPE_ORDER - ) . ' (' . __('default', 'mollie-payments-for-woocommerce') + PaymentService::PAYMENT_METHOD_TYPE_ORDER + ) . ' (' . __('default', 'mollie-payments-for-woocommerce') . ')', PaymentService::PAYMENT_METHOD_TYPE_PAYMENT => ucfirst( PaymentService::PAYMENT_METHOD_TYPE_PAYMENT @@ -203,8 +203,8 @@ class="mollie-settings-advanced-payment-desc-label button button-secondary butto 'type' => 'checkbox', 'default' => 'no', 'desc' => __("Remove options and scheduled actions from database when uninstalling the plugin.", "mollie-payments-for-woocommerce") . ' (' . strtolower( - __('Clear now', 'mollie-payments-for-woocommerce') - ) . ')', + __('Clear now', 'mollie-payments-for-woocommerce') + ) . ')', ], [ 'id' => $this->settings->getSettingId('sectionend'), @@ -263,5 +263,4 @@ protected function cleanDbIfRequested() } } } - } diff --git a/src/Settings/Page/Section/PaymentMethods.php b/src/Settings/Page/Section/PaymentMethods.php index 4bcd17a7..11fc8f67 100644 --- a/src/Settings/Page/Section/PaymentMethods.php +++ b/src/Settings/Page/Section/PaymentMethods.php @@ -37,19 +37,19 @@ public function renderGateways(): string $this->refreshIfRequested(); $titleActivePaymentMethods = __( - 'Currently Active Payment Methods', - 'mollie-payments-for-woocommerce' + 'Currently Active Payment Methods', + 'mollie-payments-for-woocommerce' ); $descriptionActivePaymentMethods = __( - 'These payment methods are active in your Mollie profile. + 'These payment methods are active in your Mollie profile. You can enable these payment methods in their settings to make them available for your customers.', - 'mollie-payments-for-woocommerce' + 'mollie-payments-for-woocommerce' ); $titleInactivePaymentMethods = __('Inactive Payment Methods', 'mollie-payments-for-woocommerce'); $descriptionInactivePaymentMethods = __( - 'These payment methods are available in your Mollie profile but are + 'These payment methods are available in your Mollie profile but are not currently active. Activate them to offer more payment options to your customers.', - 'mollie-payments-for-woocommerce' + 'mollie-payments-for-woocommerce' ); $activatedGateways = ''; @@ -70,14 +70,14 @@ public function renderGateways(): string } return $this->paymentGatewaysBlock( - $titleActivePaymentMethods, - $descriptionActivePaymentMethods, - $activatedGateways - ) . $this->paymentGatewaysBlock( - $titleInactivePaymentMethods, - $descriptionInactivePaymentMethods, - $deactivatedGateways - ); + $titleActivePaymentMethods, + $descriptionActivePaymentMethods, + $activatedGateways + ) . $this->paymentGatewaysBlock( + $titleInactivePaymentMethods, + $descriptionInactivePaymentMethods, + $deactivatedGateways + ); } protected function paymentGatewaysBlock(string $title, string $description, string $html): string @@ -98,7 +98,7 @@ protected function paymentGatewaysBlock(string $title, string $description, stri protected function getGatewaySettingsUrl(string $gatewayClassName): string { return admin_url( - 'admin.php?page=wc-settings&tab=checkout§ion=' . sanitize_title(strtolower($gatewayClassName)) + 'admin.php?page=wc-settings&tab=checkout§ion=' . sanitize_title(strtolower($gatewayClassName)) ); } @@ -177,8 +177,8 @@ protected function refreshIfRequested() isset($_GET['refresh-methods']) && isset($_GET['nonce_mollie_refresh_methods']) && wp_verify_nonce( - filter_input(INPUT_GET, 'nonce_mollie_refresh_methods', FILTER_SANITIZE_SPECIAL_CHARS), - 'nonce_mollie_refresh_methods' + filter_input(INPUT_GET, 'nonce_mollie_refresh_methods', FILTER_SANITIZE_SPECIAL_CHARS), + 'nonce_mollie_refresh_methods' ) ) { $testMode = $this->testModeEnabled; @@ -199,30 +199,30 @@ protected function paymentGatewayButton(AbstractPaymentMethod $paymentMethod, $e $paymentMethodId = $paymentMethod->getProperty('id'); $gatewayKey = 'mollie_wc_gateway_' . $paymentMethodId; $button = '' . esc_html(__( - 'Manage Payment Method', - 'mollie-payments-for-woocommerce' - )) . ''; + $gatewayKey + ) . '">' . esc_html(__( + 'Manage Payment Method', + 'mollie-payments-for-woocommerce' + )) . ''; $messageOrLink = ''; $enabledInWoo = ($paymentMethod->getSettings())['enabled'] === 'yes'; if ($enabledInMollie && $enabledInWoo) { $messageOrLink = '' . esc_html(__( - 'enabled', - 'mollie-payments-for-woocommerce' - )) . ''; + 'enabled', + 'mollie-payments-for-woocommerce' + )) . ''; } elseif ($enabledInMollie && !$enabledInWoo) { $messageOrLink = '' . esc_html(__( - 'disabled', - 'mollie-payments-for-woocommerce' - )) . ''; + 'disabled', + 'mollie-payments-for-woocommerce' + )) . ''; } else { if ($documentationLink) { $messageOrLink = "" . esc_html(__( - 'More information', - 'mollie-payments-for-woocommerce' - )) . ''; + 'More information', + 'mollie-payments-for-woocommerce' + )) . ''; } $button = '' . esc_html(__('Activate Payment Method', 'mollie-payments-for-woocommerce'))