Passed
Pull Request — master (#840)
by Patrik
05:05
created
includes/admin/class-getpaid-admin-setup-wizard.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @version     2.4.0
11 11
  * @info        GetPaid Setup Wizard.
12 12
  */
13
-defined( 'ABSPATH' ) || exit;
13
+defined('ABSPATH') || exit;
14 14
 
15 15
 /**
16 16
  * GetPaid_Admin_Setup_Wizard class.
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	public function __construct() {
46 46
 
47
-		if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) {
48
-			add_action( 'admin_menu', array( $this, 'add_menu' ) );
49
-			add_action( 'current_screen', array( $this, 'setup_wizard' ) );
50
-			add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) );
47
+		if (apply_filters('getpaid_enable_setup_wizard', true) && wpinv_current_user_can_manage_invoicing()) {
48
+			add_action('admin_menu', array($this, 'add_menu'));
49
+			add_action('current_screen', array($this, 'setup_wizard'));
50
+			add_action('admin_init', array($this, 'remove_deprecated_functions'));
51 51
 		}
52 52
 
53 53
 	}
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 * @since 2.4.0
59 59
 	 */
60 60
 	public function add_menu() {
61
-		add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
61
+		add_dashboard_page('', '', wpinv_get_capability(), 'gp-setup', '');
62 62
 	}
63 63
 
64 64
 	/**
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function setup_wizard() {
70 70
 
71
-		if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
71
+		if (isset($_GET['page']) && 'gp-setup' === $_GET['page']) {
72 72
 			$this->setup_globals();
73 73
 			$this->maybe_save_current_step();
74 74
 			$this->display_wizard();
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	public function remove_deprecated_functions() {
81 81
 		// removes deprecated warnings from page
82 82
 		remove_action('admin_print_styles', 'print_emoji_styles');
83
-		remove_action( 'admin_head', 'wp_admin_bar_header' );
83
+		remove_action('admin_head', 'wp_admin_bar_header');
84 84
 	}
85 85
 
86 86
 	/**
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 * @since 2.4.0
102 102
 	 */
103 103
 	protected function maybe_save_current_step() {
104
-		if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
105
-			call_user_func( $this->steps[ $this->step ]['handler'], $this );
104
+		if (!empty($_POST['save_step']) && is_callable($this->steps[$this->step]['handler'])) {
105
+			call_user_func($this->steps[$this->step]['handler'], $this);
106 106
 		}
107 107
 	}
108 108
 
@@ -117,44 +117,44 @@  discard block
 block discarded – undo
117 117
 		$steps = array(
118 118
 
119 119
 			'introduction'     => array(
120
-				'name'    => __( 'Introduction', 'invoicing' ),
121
-				'view'    => array( $this, 'setup_introduction' ),
120
+				'name'    => __('Introduction', 'invoicing'),
121
+				'view'    => array($this, 'setup_introduction'),
122 122
 				'handler' => '',
123 123
 			),
124 124
 
125 125
 			'business_details' => array(
126
-				'name'    => __( 'Business Details', 'invoicing' ),
127
-				'view'    => array( $this, 'setup_business' ),
126
+				'name'    => __('Business Details', 'invoicing'),
127
+				'view'    => array($this, 'setup_business'),
128 128
 				'handler' => '',
129 129
 			),
130 130
 
131 131
 			'currency'         => array(
132
-				'name'    => __( 'Currency', 'invoicing' ),
133
-				'view'    => array( $this, 'setup_currency' ),
132
+				'name'    => __('Currency', 'invoicing'),
133
+				'view'    => array($this, 'setup_currency'),
134 134
 				'handler' => '',
135 135
 			),
136 136
 
137 137
 			'payments'         => array(
138
-				'name'    => __( 'Payment Gateways', 'invoicing' ),
139
-				'view'    => array( $this, 'setup_payments' ),
140
-				'handler' => array( $this, 'setup_payments_save' ),
138
+				'name'    => __('Payment Gateways', 'invoicing'),
139
+				'view'    => array($this, 'setup_payments'),
140
+				'handler' => array($this, 'setup_payments_save'),
141 141
 			),
142 142
 
143 143
 			'recommend'        => array(
144
-				'name'    => __( 'Recommend', 'invoicing' ),
145
-				'view'    => array( $this, 'setup_recommend' ),
144
+				'name'    => __('Recommend', 'invoicing'),
145
+				'view'    => array($this, 'setup_recommend'),
146 146
 				'handler' => '',
147 147
 			),
148 148
 
149 149
 			'next_steps'       => array(
150
-				'name'    => __( 'Get Paid', 'invoicing' ),
151
-				'view'    => array( $this, 'setup_ready' ),
150
+				'name'    => __('Get Paid', 'invoicing'),
151
+				'view'    => array($this, 'setup_ready'),
152 152
 				'handler' => '',
153 153
 			),
154 154
 
155 155
 		);
156 156
 
157
-		return apply_filters( 'getpaid_setup_wizard_steps', $steps );
157
+		return apply_filters('getpaid_setup_wizard_steps', $steps);
158 158
 
159 159
 	}
160 160
 
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
 	 * @return string
166 166
 	 */
167 167
 	protected function get_current_step() {
168
-		$step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
169
-		return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
168
+		$step = isset($_GET['step']) ? sanitize_key($_GET['step']) : '';
169
+		return !empty($step) && in_array($step, array_keys($this->steps)) ? $step : current(array_keys($this->steps));
170 170
 	}
171 171
 
172 172
 	/**
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 
180 180
 		$previous = false;
181 181
 		$current  = $this->step;
182
-		foreach ( array_keys( $this->steps ) as $step ) {
183
-			if ( $current === $step ) {
182
+		foreach (array_keys($this->steps) as $step) {
183
+			if ($current === $step) {
184 184
 				return $previous;
185 185
 			}
186 186
 
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
 
201 201
 		$on_current = false;
202 202
 		$current    = $this->step;
203
-		foreach ( array_keys( $this->steps ) as $step ) {
203
+		foreach (array_keys($this->steps) as $step) {
204 204
 
205
-			if ( $on_current ) {
205
+			if ($on_current) {
206 206
 				return $step;
207 207
 			}
208 208
 
209
-			if ( $current === $step ) {
209
+			if ($current === $step) {
210 210
 				return $on_current = true;
211 211
 			}
212 212
 }
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
 		$steps     = $this->steps;
235 235
 		$current   = $this->step;
236 236
 		$next_step = $this->next_step;
237
-		array_shift( $steps );
238
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
237
+		array_shift($steps);
238
+		include plugin_dir_path(__FILE__) . 'views/wizard-header.php';
239 239
 	}
240 240
 
241 241
 	/**
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 		?>
248 248
 			<div class="gp-setup-content rowx mw-100 text-center mb-3">
249 249
 				<div class="col-12 col-md-5 m-auto">
250
-					<?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?>
250
+					<?php call_user_func($this->steps[$this->step]['view'], $this); ?>
251 251
 				</div>
252 252
 			</div>
253 253
 		<?php
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
 	 */
261 261
 	public function display_footer() {
262 262
 
263
-		if ( isset( $_GET['step'] ) ) {
264
-			$label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
263
+		if (isset($_GET['step'])) {
264
+			$label = $this->step == 'next_steps' ? __('Return to the WordPress Dashboard', 'invoicing') : __('Skip this step', 'invoicing');
265 265
 
266
-			echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>';
266
+			echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url($this->get_next_step_link()) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html($label) . '</a></p>';
267 267
 		}
268 268
 
269 269
 		echo '</body></html>';
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 */
277 277
 	public function setup_introduction() {
278 278
 		$next_url = $this->get_next_step_link();
279
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
279
+		include plugin_dir_path(__FILE__) . 'views/wizard-introduction.php';
280 280
 	}
281 281
 
282 282
 	/**
@@ -289,22 +289,22 @@  discard block
 block discarded – undo
289 289
 	 *                      Empty string on failure.
290 290
 	 * @since 3.0.0
291 291
 	 */
292
-	public function get_next_step_link( $step = '' ) {
293
-		if ( ! $step ) {
292
+	public function get_next_step_link($step = '') {
293
+		if (!$step) {
294 294
 			$step = $this->step;
295 295
 		}
296 296
 
297
-		$keys = array_keys( $this->steps );
298
-		if ( end( $keys ) === $step ) {
297
+		$keys = array_keys($this->steps);
298
+		if (end($keys) === $step) {
299 299
 			return admin_url();
300 300
 		}
301 301
 
302
-		$step_index = array_search( $step, $keys );
303
-		if ( false === $step_index ) {
302
+		$step_index = array_search($step, $keys);
303
+		if (false === $step_index) {
304 304
 			return '';
305 305
 		}
306 306
 
307
-		return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) );
307
+		return remove_query_arg('settings-updated', add_query_arg('step', $keys[$step_index + 1]));
308 308
 	}
309 309
 
310 310
 	/**
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 		$wizard   = $this;
318 318
 		$page     = 'wpinv_settings_general_main';
319 319
 		$section  = 'wpinv_settings_general_main';
320
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
320
+		include plugin_dir_path(__FILE__) . 'views/wizard-settings.php';
321 321
 	}
322 322
 
323 323
 	/**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 		$wizard   = $this;
331 331
 		$page     = 'wpinv_settings_general_currency_section';
332 332
 		$section  = 'wpinv_settings_general_currency_section';
333
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
333
+		include plugin_dir_path(__FILE__) . 'views/wizard-settings.php';
334 334
 	}
335 335
 
336 336
 	/**
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 	public function setup_recommend() {
342 342
 		$next_url            = $this->get_next_step_link();
343 343
 		$recommended_plugins = self::get_recommend_wp_plugins();
344
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
344
+		include plugin_dir_path(__FILE__) . 'views/wizard-plugins.php';
345 345
 	}
346 346
 
347 347
 	/**
@@ -355,21 +355,21 @@  discard block
 block discarded – undo
355 355
 				'url'  => 'https://wordpress.org/plugins/ayecode-connect/',
356 356
 				'slug' => 'ayecode-connect',
357 357
 				'name' => 'AyeCode Connect',
358
-				'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ),
358
+				'desc' => __('Documentation and Support from within your WordPress admin.', 'invoicing'),
359 359
 			),
360 360
 			'invoicing-quotes' => array(
361 361
 				'file' => 'invoicing-quotes/wpinv-quote.php',
362 362
 				'url'  => 'https://wordpress.org/plugins/invoicing-quotes/',
363 363
 				'slug' => 'invoicing-quotes',
364 364
 				'name' => 'Customer Quotes',
365
-				'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ),
365
+				'desc' => __('Create & Send Quotes to Customers and have them accept and pay.', 'invoicing'),
366 366
 			),
367 367
 			'userswp'          => array(
368 368
 				'file' => 'userswp/userswp.php',
369 369
 				'url'  => 'https://wordpress.org/plugins/userswp/',
370 370
 				'slug' => 'userswp',
371 371
 				'name' => 'UsersWP',
372
-				'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ),
372
+				'desc' => __('Frontend user login and registration as well as slick profile pages.', 'invoicing'),
373 373
 			),
374 374
 		);
375 375
 	}
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 	 */
382 382
 	public function setup_payments() {
383 383
 		$next_url = $this->get_next_step_link();
384
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
384
+		include plugin_dir_path(__FILE__) . 'views/wizard-gateways.php';
385 385
 	}
386 386
 
387 387
 	/**
@@ -392,16 +392,16 @@  discard block
 block discarded – undo
392 392
 	 * @since 2.0.0
393 393
 	 */
394 394
 	public function setup_payments_save() {
395
-		check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
396
-		wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
395
+		check_admin_referer('getpaid-setup-wizard', 'getpaid-setup-wizard');
396
+		wpinv_update_option('manual_active', !empty($_POST['enable-manual-gateway']));
397 397
 
398
-		if ( ! empty( $_POST['paypal-email'] ) ) {
399
-			wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) );
400
-			wpinv_update_option( 'paypal_active', 1 );
401
-			wpinv_update_option( 'paypal_sandbox', 0 );
398
+		if (!empty($_POST['paypal-email'])) {
399
+			wpinv_update_option('paypal_email', sanitize_email($_POST['paypal-email']));
400
+			wpinv_update_option('paypal_active', 1);
401
+			wpinv_update_option('paypal_sandbox', 0);
402 402
 		}
403 403
 
404
-		wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
404
+		wp_redirect(esc_url_raw($this->get_next_step_link()));
405 405
 		exit;
406 406
 	}
407 407
 
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 	 * @since 2.0.0
412 412
 	 */
413 413
 	public function setup_ready() {
414
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
414
+		include plugin_dir_path(__FILE__) . 'views/wizard-thank-you.php';
415 415
 	}
416 416
 
417 417
 }
Please login to merge, or discard this patch.