Skip to content

Commit 0e1dfe6

Browse files
committed
feat: auto-format JSON style settings on save
All payment gateway JSON style validation methods now automatically pretty-print JSON when saved in WordPress admin for better readability. Changes: - Updated validate_*_style_field() methods in all gateway classes - JSON is decoded, validated, then re-encoded with JSON_PRETTY_PRINT - Settings files formatting improvements from PHPCBF - Fixed PHPCBF to return success after fixing files in lint-staged
1 parent 24ef194 commit 0e1dfe6

File tree

8 files changed

+19
-22
lines changed

8 files changed

+19
-22
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"scripts": {
2222
"phpcs": "phpcs -n",
23-
"phpcbf": "phpcbf",
23+
"phpcbf": "phpcbf || true",
2424
"phpstan": "phpstan analyse --memory-limit=1G --no-progress",
2525
"lint": [
2626
"@phpcs",

includes/admin/monei-apple-google-settings.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
)
1616
);
1717

18-
/**
19-
* Apple Google Gateway Settings.
20-
*/
18+
/** Apple Google Gateway Settings. */
2119
return apply_filters(
2220
'wc_monei_apple_google_settings',
2321
array(
@@ -44,7 +42,7 @@
4442
'title' => __( 'Apple Pay / Google Pay Style', 'monei' ),
4543
'type' => 'textarea',
4644
'description' => __( 'Configure in JSON format the style of the Apple Pay / Google Pay component. Documentation: ', 'monei' ) . '<a href="https://docs.monei.com/docs/monei-js/reference/#paymentrequest-options" target="_blank">MONEI Payment Request Style</a>',
47-
'default' => '{\"height\": \"42\"}',
45+
'default' => '{"height": "50px"}',
4846
'css' => 'min-height: 80px;',
4947
),
5048
'title' => array(

includes/admin/monei-bizum-settings.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
)
1616
);
1717

18-
/**
19-
* Monei Bizum Gateway Settings.
20-
*/
18+
/** Monei Bizum Gateway Settings. */
2119
return apply_filters(
2220
'wc_monei_bizum_settings',
2321
array(
@@ -51,7 +49,7 @@
5149
'title' => __( 'Bizum Style', 'monei' ),
5250
'type' => 'textarea',
5351
'description' => __( 'Configure in JSON format the style of the Bizum component. Documentation: ', 'monei' ) . '<a href="https://docs.monei.com/docs/monei-js/reference/#bizum-options" target="_blank">MONEI Bizum Style</a>',
54-
'default' => '{"height": "42"}',
52+
'default' => '{"height": "50px"}',
5553
'css' => 'min-height: 80px;',
5654
),
5755
'title' => array(

includes/admin/monei-cc-settings.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
)
1616
);
1717

18-
/**
19-
* Monei Gateway Settings.
20-
*/
18+
/** Monei Gateway Settings. */
2119
return apply_filters(
2220
'wc_monei_settings',
2321
array(
@@ -51,7 +49,7 @@
5149
'title' => __( 'Card Input Style', 'monei' ),
5250
'type' => 'textarea',
5351
'description' => __( 'Configure in JSON format the style of the Card Input component. Documentation: ', 'monei' ) . '<a href="https://docs.monei.com/docs/monei-js/reference/#cardinput-style-object" target="_blank">MONEI Card Input Style</a>',
54-
'default' => '{"base": {"height": "50"}, "input": {"background": "none"}}',
52+
'default' => '{"base": {"height": "50px"}, "input": {"background": "none"}}',
5553
'css' => 'min-height: 80px;',
5654
),
5755
'title' => array(
@@ -102,6 +100,5 @@
102100
'completed' => __( 'Mark as Complete', 'monei' ),
103101
),
104102
),
105-
106103
)
107104
);

src/Gateways/PaymentMethods/WCGatewayMoneiAppleGoogle.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function validate_payment_request_style_field( $key, $value ) {
137137
$value = stripslashes( $value );
138138

139139
// Try to decode JSON
140-
json_decode( $value );
140+
$decoded = json_decode( $value, true );
141141

142142
// Check for JSON errors
143143
if ( json_last_error() !== JSON_ERROR_NONE ) {
@@ -151,7 +151,8 @@ public function validate_payment_request_style_field( $key, $value ) {
151151
return $this->get_option( 'payment_request_style', '{"height": "50px"}' );
152152
}
153153

154-
return $value;
154+
// Re-encode with pretty print for better readability in admin
155+
return wp_json_encode( $decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
155156
}
156157

157158
/**

src/Gateways/PaymentMethods/WCGatewayMoneiBizum.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function validate_bizum_style_field( $key, $value ) {
139139
$value = stripslashes( $value );
140140

141141
// Try to decode JSON
142-
json_decode( $value );
142+
$decoded = json_decode( $value, true );
143143

144144
// Check for JSON errors
145145
if ( json_last_error() !== JSON_ERROR_NONE ) {
@@ -153,7 +153,8 @@ public function validate_bizum_style_field( $key, $value ) {
153153
return $this->get_option( 'bizum_style', '{"height": "50px"}' );
154154
}
155155

156-
return $value;
156+
// Re-encode with pretty print for better readability in admin
157+
return wp_json_encode( $decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
157158
}
158159

159160
/**

src/Gateways/PaymentMethods/WCGatewayMoneiCC.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function validate_card_input_style_field( $key, $value ) {
199199
$value = stripslashes( $value );
200200

201201
// Try to decode JSON
202-
json_decode( $value );
202+
$decoded = json_decode( $value, true );
203203

204204
// Check for JSON errors
205205
if ( json_last_error() !== JSON_ERROR_NONE ) {
@@ -213,7 +213,8 @@ public function validate_card_input_style_field( $key, $value ) {
213213
return $this->get_option( 'card_input_style', '{"base": {"height": "50px"}, "input": {"background": "none"}}' );
214214
}
215215

216-
return $value;
216+
// Re-encode with pretty print for better readability in admin
217+
return wp_json_encode( $decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
217218
}
218219

219220
/**

src/Gateways/PaymentMethods/WCGatewayMoneiPaypal.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function validate_paypal_style_field( $key, $value ) {
139139
$value = stripslashes( $value );
140140

141141
// Try to decode JSON
142-
json_decode( $value );
142+
$decoded = json_decode( $value, true );
143143

144144
// Check for JSON errors
145145
if ( json_last_error() !== JSON_ERROR_NONE ) {
@@ -153,7 +153,8 @@ public function validate_paypal_style_field( $key, $value ) {
153153
return $this->get_option( 'paypal_style', '{"height": "50px", "disableMaxWidth": true}' );
154154
}
155155

156-
return $value;
156+
// Re-encode with pretty print for better readability in admin
157+
return wp_json_encode( $decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
157158
}
158159

159160
/**

0 commit comments

Comments
 (0)