Completed
Push — master ( 7d7341...ce0a54 )
by Kiran
25s queued 20s
created
includes/admin/class-getpaid-admin-setup-wizard.php 2 patches
Indentation   +388 added lines, -388 removed lines patch added patch discarded remove patch
@@ -17,402 +17,402 @@
 block discarded – undo
17 17
  */
18 18
 class GetPaid_Admin_Setup_Wizard {
19 19
 
20
-	/**
21
-	 * @var string Current Step
22
-	 */
23
-	protected $step = '';
24
-
25
-	/**
26
-	 * @var string|false Previous Step
27
-	 */
28
-	protected $previous_step = '';
29
-
30
-	/**
31
-	 * @var string|false Next Step
32
-	 */
33
-	protected $next_step = '';
34
-
35
-	/**
36
-	 * @var array All available steps for the setup wizard
37
-	 */
38
-	protected $steps = array();
39
-
40
-	/**
41
-	 * Class constructor.
42
-	 *
43
-	 * @since 2.4.0
44
-	 */
45
-	public function __construct() {
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' ) );
51
-		}
52
-
53
-	}
54
-
55
-	/**
56
-	 * Add admin menus/screens.
57
-	 *
58
-	 * @since 2.4.0
59
-	 */
60
-	public function add_menu() {
61
-		add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
62
-	}
63
-
64
-	/**
65
-	 * Sets up the setup wizard.
66
-	 *
67
-	 * @since 2.4.0
68
-	 */
69
-	public function setup_wizard() {
70
-
71
-		if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
72
-			$this->setup_globals();
73
-			$this->maybe_save_current_step();
74
-			$this->display_wizard();
75
-			exit;
76
-		}
77
-
78
-	}
79
-
80
-	public function remove_deprecated_functions() {
81
-		// removes deprecated warnings from page
82
-		remove_action('admin_print_styles', 'print_emoji_styles');
83
-		remove_action( 'admin_head', 'wp_admin_bar_header' );
84
-	}
85
-
86
-	/**
87
-	 * Sets up class variables.
88
-	 *
89
-	 * @since 2.4.0
90
-	 */
91
-	protected function setup_globals() {
92
-		$this->steps         = $this->get_setup_steps();
93
-		$this->step          = $this->get_current_step();
94
-		$this->previous_step = $this->get_previous_step();
95
-		$this->next_step     = $this->get_next_step();
96
-	}
97
-
98
-	/**
99
-	 * Saves the current step.
100
-	 *
101
-	 * @since 2.4.0
102
-	 */
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 );
106
-		}
107
-	}
108
-
109
-	/**
110
-	 * Returns the setup steps.
111
-	 *
112
-	 * @since 2.4.0
113
-	 * @return array
114
-	 */
115
-	protected function get_setup_steps() {
116
-
117
-		$steps = array(
118
-
119
-			'introduction'     => array(
120
-				'name'    => __( 'Introduction', 'invoicing' ),
121
-				'view'    => array( $this, 'setup_introduction' ),
122
-				'handler' => '',
123
-			),
124
-
125
-			'business_details' => array(
126
-				'name'    => __( 'Business Details', 'invoicing' ),
127
-				'view'    => array( $this, 'setup_business' ),
128
-				'handler' => '',
129
-			),
130
-
131
-			'currency'         => array(
132
-				'name'    => __( 'Currency', 'invoicing' ),
133
-				'view'    => array( $this, 'setup_currency' ),
134
-				'handler' => '',
135
-			),
136
-
137
-			'payments'         => array(
138
-				'name'    => __( 'Payment Gateways', 'invoicing' ),
139
-				'view'    => array( $this, 'setup_payments' ),
140
-				'handler' => array( $this, 'setup_payments_save' ),
141
-			),
142
-
143
-			'recommend'        => array(
144
-				'name'    => __( 'Recommend', 'invoicing' ),
145
-				'view'    => array( $this, 'setup_recommend' ),
146
-				'handler' => '',
147
-			),
148
-
149
-			'next_steps'       => array(
150
-				'name'    => __( 'Get Paid', 'invoicing' ),
151
-				'view'    => array( $this, 'setup_ready' ),
152
-				'handler' => '',
153
-			),
154
-
155
-		);
156
-
157
-		return apply_filters( 'getpaid_setup_wizard_steps', $steps );
158
-
159
-	}
160
-
161
-	/**
162
-	 * Returns the current step.
163
-	 *
164
-	 * @since 2.4.0
165
-	 * @return string
166
-	 */
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 ) );
170
-	}
171
-
172
-	/**
173
-	 * Returns the previous step.
174
-	 *
175
-	 * @since 2.4.0
176
-	 * @return string|false
177
-	 */
178
-	protected function get_previous_step() {
179
-
180
-		$previous = false;
181
-		$current  = $this->step;
182
-		foreach ( array_keys( $this->steps ) as $step ) {
183
-			if ( $current === $step ) {
184
-				return $previous;
185
-			}
186
-
187
-			$previous = $step;
188
-		}
189
-
190
-		return false;
191
-	}
192
-
193
-	/**
194
-	 * Returns the next step.
195
-	 *
196
-	 * @since 2.4.0
197
-	 * @return string|false
198
-	 */
199
-	protected function get_next_step() {
200
-
201
-		$on_current = false;
202
-		$current    = $this->step;
203
-		foreach ( array_keys( $this->steps ) as $step ) {
204
-
205
-			if ( $on_current ) {
206
-				return $step;
207
-			}
208
-
209
-			if ( $current === $step ) {
210
-				return $on_current = true;
211
-			}
20
+    /**
21
+     * @var string Current Step
22
+     */
23
+    protected $step = '';
24
+
25
+    /**
26
+     * @var string|false Previous Step
27
+     */
28
+    protected $previous_step = '';
29
+
30
+    /**
31
+     * @var string|false Next Step
32
+     */
33
+    protected $next_step = '';
34
+
35
+    /**
36
+     * @var array All available steps for the setup wizard
37
+     */
38
+    protected $steps = array();
39
+
40
+    /**
41
+     * Class constructor.
42
+     *
43
+     * @since 2.4.0
44
+     */
45
+    public function __construct() {
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' ) );
51
+        }
52
+
53
+    }
54
+
55
+    /**
56
+     * Add admin menus/screens.
57
+     *
58
+     * @since 2.4.0
59
+     */
60
+    public function add_menu() {
61
+        add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
62
+    }
63
+
64
+    /**
65
+     * Sets up the setup wizard.
66
+     *
67
+     * @since 2.4.0
68
+     */
69
+    public function setup_wizard() {
70
+
71
+        if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
72
+            $this->setup_globals();
73
+            $this->maybe_save_current_step();
74
+            $this->display_wizard();
75
+            exit;
76
+        }
77
+
78
+    }
79
+
80
+    public function remove_deprecated_functions() {
81
+        // removes deprecated warnings from page
82
+        remove_action('admin_print_styles', 'print_emoji_styles');
83
+        remove_action( 'admin_head', 'wp_admin_bar_header' );
84
+    }
85
+
86
+    /**
87
+     * Sets up class variables.
88
+     *
89
+     * @since 2.4.0
90
+     */
91
+    protected function setup_globals() {
92
+        $this->steps         = $this->get_setup_steps();
93
+        $this->step          = $this->get_current_step();
94
+        $this->previous_step = $this->get_previous_step();
95
+        $this->next_step     = $this->get_next_step();
96
+    }
97
+
98
+    /**
99
+     * Saves the current step.
100
+     *
101
+     * @since 2.4.0
102
+     */
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 );
106
+        }
107
+    }
108
+
109
+    /**
110
+     * Returns the setup steps.
111
+     *
112
+     * @since 2.4.0
113
+     * @return array
114
+     */
115
+    protected function get_setup_steps() {
116
+
117
+        $steps = array(
118
+
119
+            'introduction'     => array(
120
+                'name'    => __( 'Introduction', 'invoicing' ),
121
+                'view'    => array( $this, 'setup_introduction' ),
122
+                'handler' => '',
123
+            ),
124
+
125
+            'business_details' => array(
126
+                'name'    => __( 'Business Details', 'invoicing' ),
127
+                'view'    => array( $this, 'setup_business' ),
128
+                'handler' => '',
129
+            ),
130
+
131
+            'currency'         => array(
132
+                'name'    => __( 'Currency', 'invoicing' ),
133
+                'view'    => array( $this, 'setup_currency' ),
134
+                'handler' => '',
135
+            ),
136
+
137
+            'payments'         => array(
138
+                'name'    => __( 'Payment Gateways', 'invoicing' ),
139
+                'view'    => array( $this, 'setup_payments' ),
140
+                'handler' => array( $this, 'setup_payments_save' ),
141
+            ),
142
+
143
+            'recommend'        => array(
144
+                'name'    => __( 'Recommend', 'invoicing' ),
145
+                'view'    => array( $this, 'setup_recommend' ),
146
+                'handler' => '',
147
+            ),
148
+
149
+            'next_steps'       => array(
150
+                'name'    => __( 'Get Paid', 'invoicing' ),
151
+                'view'    => array( $this, 'setup_ready' ),
152
+                'handler' => '',
153
+            ),
154
+
155
+        );
156
+
157
+        return apply_filters( 'getpaid_setup_wizard_steps', $steps );
158
+
159
+    }
160
+
161
+    /**
162
+     * Returns the current step.
163
+     *
164
+     * @since 2.4.0
165
+     * @return string
166
+     */
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 ) );
170
+    }
171
+
172
+    /**
173
+     * Returns the previous step.
174
+     *
175
+     * @since 2.4.0
176
+     * @return string|false
177
+     */
178
+    protected function get_previous_step() {
179
+
180
+        $previous = false;
181
+        $current  = $this->step;
182
+        foreach ( array_keys( $this->steps ) as $step ) {
183
+            if ( $current === $step ) {
184
+                return $previous;
185
+            }
186
+
187
+            $previous = $step;
188
+        }
189
+
190
+        return false;
191
+    }
192
+
193
+    /**
194
+     * Returns the next step.
195
+     *
196
+     * @since 2.4.0
197
+     * @return string|false
198
+     */
199
+    protected function get_next_step() {
200
+
201
+        $on_current = false;
202
+        $current    = $this->step;
203
+        foreach ( array_keys( $this->steps ) as $step ) {
204
+
205
+            if ( $on_current ) {
206
+                return $step;
207
+            }
208
+
209
+            if ( $current === $step ) {
210
+                return $on_current = true;
211
+            }
212 212
 }
213 213
 
214
-		return false;
215
-	}
216
-
217
-	/**
218
-	 * Displays the setup wizard.
219
-	 *
220
-	 * @since 2.4.0
221
-	 */
222
-	public function display_wizard() {
223
-		$this->display_header();
224
-		$this->display_current_step();
225
-		$this->display_footer();
226
-	}
227
-
228
-	/**
229
-	 * Displays the Wizard Header.
230
-	 *
231
-	 * @since 2.0.0
232
-	 */
233
-	public function display_header() {
234
-		$steps     = $this->steps;
235
-		$current   = $this->step;
236
-		$next_step = $this->next_step;
237
-		array_shift( $steps );
238
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
239
-	}
240
-
241
-	/**
242
-	 * Displays the content for the current step.
243
-	 *
244
-	 * @since 2.4.0
245
-	 */
246
-	public function display_current_step() {
247
-		?>
214
+        return false;
215
+    }
216
+
217
+    /**
218
+     * Displays the setup wizard.
219
+     *
220
+     * @since 2.4.0
221
+     */
222
+    public function display_wizard() {
223
+        $this->display_header();
224
+        $this->display_current_step();
225
+        $this->display_footer();
226
+    }
227
+
228
+    /**
229
+     * Displays the Wizard Header.
230
+     *
231
+     * @since 2.0.0
232
+     */
233
+    public function display_header() {
234
+        $steps     = $this->steps;
235
+        $current   = $this->step;
236
+        $next_step = $this->next_step;
237
+        array_shift( $steps );
238
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
239
+    }
240
+
241
+    /**
242
+     * Displays the content for the current step.
243
+     *
244
+     * @since 2.4.0
245
+     */
246
+    public function display_current_step() {
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 250
 					<?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?>
251 251
 				</div>
252 252
 			</div>
253 253
 		<?php
254
-	}
255
-
256
-	/**
257
-	 * Setup Wizard Footer.
258
-	 *
259
-	 * @since 2.4.0
260
-	 */
261
-	public function display_footer() {
262
-
263
-		if ( isset( $_GET['step'] ) ) {
264
-			$label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
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>';
267
-		}
268
-
269
-		echo '</body></html>';
270
-	}
271
-
272
-	/**
273
-	 * Introduction step.
274
-	 *
275
-	 * @since 2.0.0
276
-	 */
277
-	public function setup_introduction() {
278
-		$next_url = $this->get_next_step_link();
279
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
280
-	}
281
-
282
-	/**
283
-	 * Get the URL for the next step's screen.
284
-	 *
285
-	 * @param string step   slug (default: current step)
286
-	 *
287
-	 * @return string       URL for next step if a next step exists.
288
-	 *                      Admin URL if it's the last step.
289
-	 *                      Empty string on failure.
290
-	 * @since 3.0.0
291
-	 */
292
-	public function get_next_step_link( $step = '' ) {
293
-		if ( ! $step ) {
294
-			$step = $this->step;
295
-		}
296
-
297
-		$keys = array_keys( $this->steps );
298
-		if ( end( $keys ) === $step ) {
299
-			return admin_url();
300
-		}
301
-
302
-		$step_index = array_search( $step, $keys );
303
-		if ( false === $step_index ) {
304
-			return '';
305
-		}
306
-
307
-		return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) );
308
-	}
309
-
310
-	/**
311
-	 * Setup maps api.
312
-	 *
313
-	 * @since 2.0.0
314
-	 */
315
-	public function setup_business() {
316
-		$next_url = $this->get_next_step_link();
317
-		$wizard   = $this;
318
-		$page     = 'wpinv_settings_general_main';
319
-		$section  = 'wpinv_settings_general_main';
320
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
321
-	}
322
-
323
-	/**
324
-	 * Default Location settings.
325
-	 *
326
-	 * @since 2.0.0
327
-	 */
328
-	public function setup_currency() {
329
-		$next_url = $this->get_next_step_link();
330
-		$wizard   = $this;
331
-		$page     = 'wpinv_settings_general_currency_section';
332
-		$section  = 'wpinv_settings_general_currency_section';
333
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
334
-	}
335
-
336
-	/**
337
-	 * Installation of recommended plugins.
338
-	 *
339
-	 * @since 1.0.0
340
-	 */
341
-	public function setup_recommend() {
342
-		$next_url            = $this->get_next_step_link();
343
-		$recommended_plugins = self::get_recommend_wp_plugins();
344
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
345
-	}
346
-
347
-	/**
348
-	 * A list of recommended wp.org plugins.
349
-	 * @return array
350
-	 */
351
-	public static function get_recommend_wp_plugins() {
352
-		return array(
353
-			'ayecode-connect'  => array(
354
-				'file' => 'ayecode-connect/ayecode-connect.php',
355
-				'url'  => 'https://wordpress.org/plugins/ayecode-connect/',
356
-				'slug' => 'ayecode-connect',
357
-				'name' => 'AyeCode Connect',
358
-				'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ),
359
-			),
360
-			'invoicing-quotes' => array(
361
-				'file' => 'invoicing-quotes/wpinv-quote.php',
362
-				'url'  => 'https://wordpress.org/plugins/invoicing-quotes/',
363
-				'slug' => 'invoicing-quotes',
364
-				'name' => 'Customer Quotes',
365
-				'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ),
366
-			),
367
-			'userswp'          => array(
368
-				'file' => 'userswp/userswp.php',
369
-				'url'  => 'https://wordpress.org/plugins/userswp/',
370
-				'slug' => 'userswp',
371
-				'name' => 'UsersWP',
372
-				'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ),
373
-			),
374
-		);
375
-	}
376
-
377
-	/**
378
-	 * Dummy Data setup.
379
-	 *
380
-	 * @since 2.4.0
381
-	 */
382
-	public function setup_payments() {
383
-		$next_url = $this->get_next_step_link();
384
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
385
-	}
386
-
387
-	/**
388
-	 * Dummy data save.
389
-	 *
390
-	 * This is done via ajax so we just pass onto the next step.
391
-	 *
392
-	 * @since 2.0.0
393
-	 */
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'] ) );
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 );
402
-		}
403
-
404
-		wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
405
-		exit;
406
-	}
407
-
408
-	/**
409
-	 * Final step.
410
-	 *
411
-	 * @since 2.0.0
412
-	 */
413
-	public function setup_ready() {
414
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
415
-	}
254
+    }
255
+
256
+    /**
257
+     * Setup Wizard Footer.
258
+     *
259
+     * @since 2.4.0
260
+     */
261
+    public function display_footer() {
262
+
263
+        if ( isset( $_GET['step'] ) ) {
264
+            $label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
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>';
267
+        }
268
+
269
+        echo '</body></html>';
270
+    }
271
+
272
+    /**
273
+     * Introduction step.
274
+     *
275
+     * @since 2.0.0
276
+     */
277
+    public function setup_introduction() {
278
+        $next_url = $this->get_next_step_link();
279
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
280
+    }
281
+
282
+    /**
283
+     * Get the URL for the next step's screen.
284
+     *
285
+     * @param string step   slug (default: current step)
286
+     *
287
+     * @return string       URL for next step if a next step exists.
288
+     *                      Admin URL if it's the last step.
289
+     *                      Empty string on failure.
290
+     * @since 3.0.0
291
+     */
292
+    public function get_next_step_link( $step = '' ) {
293
+        if ( ! $step ) {
294
+            $step = $this->step;
295
+        }
296
+
297
+        $keys = array_keys( $this->steps );
298
+        if ( end( $keys ) === $step ) {
299
+            return admin_url();
300
+        }
301
+
302
+        $step_index = array_search( $step, $keys );
303
+        if ( false === $step_index ) {
304
+            return '';
305
+        }
306
+
307
+        return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) );
308
+    }
309
+
310
+    /**
311
+     * Setup maps api.
312
+     *
313
+     * @since 2.0.0
314
+     */
315
+    public function setup_business() {
316
+        $next_url = $this->get_next_step_link();
317
+        $wizard   = $this;
318
+        $page     = 'wpinv_settings_general_main';
319
+        $section  = 'wpinv_settings_general_main';
320
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
321
+    }
322
+
323
+    /**
324
+     * Default Location settings.
325
+     *
326
+     * @since 2.0.0
327
+     */
328
+    public function setup_currency() {
329
+        $next_url = $this->get_next_step_link();
330
+        $wizard   = $this;
331
+        $page     = 'wpinv_settings_general_currency_section';
332
+        $section  = 'wpinv_settings_general_currency_section';
333
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
334
+    }
335
+
336
+    /**
337
+     * Installation of recommended plugins.
338
+     *
339
+     * @since 1.0.0
340
+     */
341
+    public function setup_recommend() {
342
+        $next_url            = $this->get_next_step_link();
343
+        $recommended_plugins = self::get_recommend_wp_plugins();
344
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
345
+    }
346
+
347
+    /**
348
+     * A list of recommended wp.org plugins.
349
+     * @return array
350
+     */
351
+    public static function get_recommend_wp_plugins() {
352
+        return array(
353
+            'ayecode-connect'  => array(
354
+                'file' => 'ayecode-connect/ayecode-connect.php',
355
+                'url'  => 'https://wordpress.org/plugins/ayecode-connect/',
356
+                'slug' => 'ayecode-connect',
357
+                'name' => 'AyeCode Connect',
358
+                'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ),
359
+            ),
360
+            'invoicing-quotes' => array(
361
+                'file' => 'invoicing-quotes/wpinv-quote.php',
362
+                'url'  => 'https://wordpress.org/plugins/invoicing-quotes/',
363
+                'slug' => 'invoicing-quotes',
364
+                'name' => 'Customer Quotes',
365
+                'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ),
366
+            ),
367
+            'userswp'          => array(
368
+                'file' => 'userswp/userswp.php',
369
+                'url'  => 'https://wordpress.org/plugins/userswp/',
370
+                'slug' => 'userswp',
371
+                'name' => 'UsersWP',
372
+                'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ),
373
+            ),
374
+        );
375
+    }
376
+
377
+    /**
378
+     * Dummy Data setup.
379
+     *
380
+     * @since 2.4.0
381
+     */
382
+    public function setup_payments() {
383
+        $next_url = $this->get_next_step_link();
384
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
385
+    }
386
+
387
+    /**
388
+     * Dummy data save.
389
+     *
390
+     * This is done via ajax so we just pass onto the next step.
391
+     *
392
+     * @since 2.0.0
393
+     */
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'] ) );
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 );
402
+        }
403
+
404
+        wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
405
+        exit;
406
+    }
407
+
408
+    /**
409
+     * Final step.
410
+     *
411
+     * @since 2.0.0
412
+     */
413
+    public function setup_ready() {
414
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
415
+    }
416 416
 
417 417
 }
418 418
 
Please login to merge, or discard this 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.