Completed
Push — master ( e0b7f3...35aa58 )
by Roy
13s
created
includes/admin/class-wc-stripe-admin-notices.php 1 patch
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 	 * @since 4.1.0
22 22
 	 */
23 23
 	public function __construct() {
24
-		add_action( 'admin_notices', array( $this, 'admin_notices' ) );
25
-		add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
24
+		add_action('admin_notices', array($this, 'admin_notices'));
25
+		add_action('wp_loaded', array($this, 'hide_notices'));
26 26
 	}
27 27
 
28 28
 	/**
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 	 * @since 1.0.0
32 32
 	 * @version 4.0.0
33 33
 	 */
34
-	public function add_admin_notice( $slug, $class, $message, $dismissible = false ) {
35
-		$this->notices[ $slug ] = array(
34
+	public function add_admin_notice($slug, $class, $message, $dismissible = false) {
35
+		$this->notices[$slug] = array(
36 36
 			'class'       => $class,
37 37
 			'message'     => $message,
38 38
 			'dismissible' => $dismissible,
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 * @version 4.0.0
47 47
 	 */
48 48
 	public function admin_notices() {
49
-		if ( ! current_user_can( 'manage_woocommerce' ) ) {
49
+		if ( ! current_user_can('manage_woocommerce')) {
50 50
 			return;
51 51
 		}
52 52
 
@@ -56,17 +56,17 @@  discard block
 block discarded – undo
56 56
 		// All other payment methods.
57 57
 		$this->payment_methods_check_environment();
58 58
 
59
-		foreach ( (array) $this->notices as $notice_key => $notice ) {
60
-			echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">';
59
+		foreach ((array) $this->notices as $notice_key => $notice) {
60
+			echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">';
61 61
 
62
-			if ( $notice['dismissible'] ) {
62
+			if ($notice['dismissible']) {
63 63
 				?>
64
-				<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:relative;float:right;padding:9px 0px 9px 9px 9px;text-decoration:none;"></a>
64
+				<a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:relative;float:right;padding:9px 0px 9px 9px 9px;text-decoration:none;"></a>
65 65
 				<?php
66 66
 			}
67 67
 
68 68
 			echo '<p>';
69
-			echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) );
69
+			echo wp_kses($notice['message'], array('a' => array('href' => array())));
70 70
 			echo '</p></div>';
71 71
 		}
72 72
 	}
@@ -99,93 +99,93 @@  discard block
 block discarded – undo
99 99
 	 * @version 4.0.0
100 100
 	 */
101 101
 	public function stripe_check_environment() {
102
-		$show_style_notice  = get_option( 'wc_stripe_show_style_notice' );
103
-		$show_ssl_notice    = get_option( 'wc_stripe_show_ssl_notice' );
104
-		$show_keys_notice   = get_option( 'wc_stripe_show_keys_notice' );
105
-		$show_phpver_notice = get_option( 'wc_stripe_show_phpver_notice' );
106
-		$show_wcver_notice  = get_option( 'wc_stripe_show_wcver_notice' );
107
-		$show_curl_notice   = get_option( 'wc_stripe_show_curl_notice' );
108
-		$options            = get_option( 'woocommerce_stripe_settings' );
109
-		$testmode           = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false;
110
-		$test_pub_key       = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : '';
111
-		$test_secret_key    = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : '';
112
-		$live_pub_key       = isset( $options['publishable_key'] ) ? $options['publishable_key'] : '';
113
-		$live_secret_key    = isset( $options['secret_key'] ) ? $options['secret_key'] : '';
114
-
115
-		if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) {
116
-			if ( empty( $show_style_notice ) ) {
102
+		$show_style_notice  = get_option('wc_stripe_show_style_notice');
103
+		$show_ssl_notice    = get_option('wc_stripe_show_ssl_notice');
104
+		$show_keys_notice   = get_option('wc_stripe_show_keys_notice');
105
+		$show_phpver_notice = get_option('wc_stripe_show_phpver_notice');
106
+		$show_wcver_notice  = get_option('wc_stripe_show_wcver_notice');
107
+		$show_curl_notice   = get_option('wc_stripe_show_curl_notice');
108
+		$options            = get_option('woocommerce_stripe_settings');
109
+		$testmode           = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false;
110
+		$test_pub_key       = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : '';
111
+		$test_secret_key    = isset($options['test_secret_key']) ? $options['test_secret_key'] : '';
112
+		$live_pub_key       = isset($options['publishable_key']) ? $options['publishable_key'] : '';
113
+		$live_secret_key    = isset($options['secret_key']) ? $options['secret_key'] : '';
114
+
115
+		if (isset($options['enabled']) && 'yes' === $options['enabled']) {
116
+			if (empty($show_style_notice)) {
117 117
 				/* translators: 1) int version 2) int version */
118
-				$message = __( 'WooCommerce Stripe - We recently made changes to Stripe that may impact the appearance of your checkout. If your checkout has changed unexpectedly, please follow these <a href="https://docs.woocommerce.com/document/stripe/#section-45" target="_blank">instructions</a> to fix.', 'woocommerce-gateway-stripe' );
118
+				$message = __('WooCommerce Stripe - We recently made changes to Stripe that may impact the appearance of your checkout. If your checkout has changed unexpectedly, please follow these <a href="https://docs.woocommerce.com/document/stripe/#section-45" target="_blank">instructions</a> to fix.', 'woocommerce-gateway-stripe');
119 119
 
120
-				$this->add_admin_notice( 'style', 'error', $message, true );
120
+				$this->add_admin_notice('style', 'error', $message, true);
121 121
 
122 122
 				return;
123 123
 			}
124 124
 
125
-			if ( empty( $show_phpver_notice ) ) {
126
-				if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) {
125
+			if (empty($show_phpver_notice)) {
126
+				if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) {
127 127
 					/* translators: 1) int version 2) int version */
128
-					$message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
128
+					$message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
129 129
 
130
-					$this->add_admin_notice( 'phpver', 'error', sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ), true );
130
+					$this->add_admin_notice('phpver', 'error', sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()), true);
131 131
 
132 132
 					return;
133 133
 				}
134 134
 			}
135 135
 
136
-			if ( empty( $show_wcver_notice ) ) {
137
-				if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) {
136
+			if (empty($show_wcver_notice)) {
137
+				if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) {
138 138
 					/* translators: 1) int version 2) int version */
139
-					$message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' );
139
+					$message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe');
140 140
 
141
-					$this->add_admin_notice( 'wcver', 'notice notice-warning', sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ), true );
141
+					$this->add_admin_notice('wcver', 'notice notice-warning', sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION), true);
142 142
 
143 143
 					return;
144 144
 				}
145 145
 			}
146 146
 
147
-			if ( empty( $show_curl_notice ) ) {
148
-				if ( ! function_exists( 'curl_init' ) ) {
149
-					$this->add_admin_notice( 'curl', 'notice notice-warning', __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ), true );
147
+			if (empty($show_curl_notice)) {
148
+				if ( ! function_exists('curl_init')) {
149
+					$this->add_admin_notice('curl', 'notice notice-warning', __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'), true);
150 150
 				}
151 151
 			}
152 152
 
153
-			if ( empty( $show_keys_notice ) ) {
153
+			if (empty($show_keys_notice)) {
154 154
 				$secret = WC_Stripe_API::get_secret_key();
155 155
 
156
-				if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) {
156
+				if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) {
157 157
 					$setting_link = $this->get_setting_link();
158 158
 					/* translators: 1) link */
159
-					$this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
159
+					$this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
160 160
 				}
161 161
 
162 162
 				// Check if keys are entered properly per live/test mode.
163
-				if ( $testmode ) {
163
+				if ($testmode) {
164 164
 					if (
165
-						! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key )
166
-						|| ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key )
167
-						&& ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) {
165
+						! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key)
166
+						|| ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key)
167
+						&& ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) {
168 168
 						$setting_link = $this->get_setting_link();
169 169
 						/* translators: 1) link */
170
-						$this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
170
+						$this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
171 171
 					}
172 172
 				} else {
173 173
 					if (
174
-						! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key )
175
-						|| ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key )
176
-						&& ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) {
174
+						! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key)
175
+						|| ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key)
176
+						&& ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) {
177 177
 						$setting_link = $this->get_setting_link();
178 178
 						/* translators: 1) link */
179
-						$this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true );
179
+						$this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true);
180 180
 					}
181 181
 				}
182 182
 			}
183 183
 
184
-			if ( empty( $show_ssl_notice ) ) {
184
+			if (empty($show_ssl_notice)) {
185 185
 				// Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected.
186
-				if ( ! wc_checkout_is_https() ) {
186
+				if ( ! wc_checkout_is_https()) {
187 187
 					/* translators: 1) link */
188
-					$this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but a SSL certificate is not detected. Your checkout may not be secure! Please ensure your server has a valid <a href="%1$s" target="_blank">SSL certificate</a>', 'woocommerce-gateway-stripe' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true );
188
+					$this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but a SSL certificate is not detected. Your checkout may not be secure! Please ensure your server has a valid <a href="%1$s" target="_blank">SSL certificate</a>', 'woocommerce-gateway-stripe'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true);
189 189
 				}
190 190
 			}
191 191
 		}
@@ -199,17 +199,17 @@  discard block
 block discarded – undo
199 199
 	public function payment_methods_check_environment() {
200 200
 		$payment_methods = $this->get_payment_methods();
201 201
 
202
-		foreach ( $payment_methods as $method => $class ) {
203
-			$show_notice = get_option( 'wc_stripe_show_' . strtolower( $method ) . '_notice' );
202
+		foreach ($payment_methods as $method => $class) {
203
+			$show_notice = get_option('wc_stripe_show_' . strtolower($method) . '_notice');
204 204
 			$gateway     = new $class();
205 205
 
206
-			if ( 'yes' !== $gateway->enabled || 'no' === $show_notice ) {
206
+			if ('yes' !== $gateway->enabled || 'no' === $show_notice) {
207 207
 				continue;
208 208
 			}
209 209
 
210
-			if ( ! in_array( get_woocommerce_currency(), $gateway->get_supported_currency() ) ) {
210
+			if ( ! in_array(get_woocommerce_currency(), $gateway->get_supported_currency())) {
211 211
 				/* translators: %1$s Payment method, %2$s List of supported currencies */
212
-				$this->add_admin_notice( $method, 'notice notice-error', sprintf( __( '%1$s is enabled - it requires store currency to be set to %2$s', 'woocommerce-gateway-stripe' ), $method, implode( ', ', $gateway->get_supported_currency() ) ), true );
212
+				$this->add_admin_notice($method, 'notice notice-error', sprintf(__('%1$s is enabled - it requires store currency to be set to %2$s', 'woocommerce-gateway-stripe'), $method, implode(', ', $gateway->get_supported_currency())), true);
213 213
 			}
214 214
 		}
215 215
 	}
@@ -221,62 +221,62 @@  discard block
 block discarded – undo
221 221
 	 * @version 4.0.0
222 222
 	 */
223 223
 	public function hide_notices() {
224
-		if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) {
225
-			if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) {
226
-				wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) );
224
+		if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) {
225
+			if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) {
226
+				wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe'));
227 227
 			}
228 228
 
229
-			if ( ! current_user_can( 'manage_woocommerce' ) ) {
230
-				wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
229
+			if ( ! current_user_can('manage_woocommerce')) {
230
+				wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
231 231
 			}
232 232
 
233
-			$notice = wc_clean( $_GET['wc-stripe-hide-notice'] );
233
+			$notice = wc_clean($_GET['wc-stripe-hide-notice']);
234 234
 
235
-			switch ( $notice ) {
235
+			switch ($notice) {
236 236
 				case 'style':
237
-					update_option( 'wc_stripe_show_style_notice', 'no' );
237
+					update_option('wc_stripe_show_style_notice', 'no');
238 238
 					break;
239 239
 				case 'phpver':
240
-					update_option( 'wc_stripe_show_phpver_notice', 'no' );
240
+					update_option('wc_stripe_show_phpver_notice', 'no');
241 241
 					break;
242 242
 				case 'wcver':
243
-					update_option( 'wc_stripe_show_wcver_notice', 'no' );
243
+					update_option('wc_stripe_show_wcver_notice', 'no');
244 244
 					break;
245 245
 				case 'curl':
246
-					update_option( 'wc_stripe_show_curl_notice', 'no' );
246
+					update_option('wc_stripe_show_curl_notice', 'no');
247 247
 					break;
248 248
 				case 'ssl':
249
-					update_option( 'wc_stripe_show_ssl_notice', 'no' );
249
+					update_option('wc_stripe_show_ssl_notice', 'no');
250 250
 					break;
251 251
 				case 'keys':
252
-					update_option( 'wc_stripe_show_keys_notice', 'no' );
252
+					update_option('wc_stripe_show_keys_notice', 'no');
253 253
 					break;
254 254
 				case 'Alipay':
255
-					update_option( 'wc_stripe_show_alipay_notice', 'no' );
255
+					update_option('wc_stripe_show_alipay_notice', 'no');
256 256
 					break;
257 257
 				case 'Bancontact':
258
-					update_option( 'wc_stripe_show_bancontact_notice', 'no' );
258
+					update_option('wc_stripe_show_bancontact_notice', 'no');
259 259
 					break;
260 260
 				case 'EPS':
261
-					update_option( 'wc_stripe_show_eps_notice', 'no' );
261
+					update_option('wc_stripe_show_eps_notice', 'no');
262 262
 					break;
263 263
 				case 'Giropay':
264
-					update_option( 'wc_stripe_show_giropay_notice', 'no' );
264
+					update_option('wc_stripe_show_giropay_notice', 'no');
265 265
 					break;
266 266
 				case 'iDeal':
267
-					update_option( 'wc_stripe_show_ideal_notice', 'no' );
267
+					update_option('wc_stripe_show_ideal_notice', 'no');
268 268
 					break;
269 269
 				case 'Multibanco':
270
-					update_option( 'wc_stripe_show_multibanco_notice', 'no' );
270
+					update_option('wc_stripe_show_multibanco_notice', 'no');
271 271
 					break;
272 272
 				case 'P24':
273
-					update_option( 'wc_stripe_show_p24_notice', 'no' );
273
+					update_option('wc_stripe_show_p24_notice', 'no');
274 274
 					break;
275 275
 				case 'SEPA':
276
-					update_option( 'wc_stripe_show_sepa_notice', 'no' );
276
+					update_option('wc_stripe_show_sepa_notice', 'no');
277 277
 					break;
278 278
 				case 'SOFORT':
279
-					update_option( 'wc_stripe_show_sofort_notice', 'no' );
279
+					update_option('wc_stripe_show_sofort_notice', 'no');
280 280
 					break;
281 281
 			}
282 282
 		}
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
 	 * @return string Setting link
291 291
 	 */
292 292
 	public function get_setting_link() {
293
-		$use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false;
293
+		$use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false;
294 294
 
295
-		$section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' );
295
+		$section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe');
296 296
 
297
-		return admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $section_slug );
297
+		return admin_url('admin.php?page=wc-settings&tab=checkout&section=' . $section_slug);
298 298
 	}
299 299
 }
300 300
 
Please login to merge, or discard this patch.