Passed
Push — master ( 53920d...da0522 )
by Brian
11:00
created
includes/admin/class-getpaid-admin.php 1 patch
Spacing   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * The main admin class.
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
     /**
38 38
 	 * Class constructor.
39 39
 	 */
40
-	public function __construct(){
40
+	public function __construct() {
41 41
 
42
-        $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
42
+        $this->admin_path = plugin_dir_path(__FILE__);
43
+		$this->admin_url   = plugins_url('/', __FILE__);
44 44
 		$this->reports     = new GetPaid_Reports();
45 45
 
46
-        if ( is_admin() ) {
46
+        if (is_admin()) {
47 47
 			$this->init_admin_hooks();
48 48
         }
49 49
 
@@ -54,33 +54,33 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 */
56 56
 	private function init_admin_hooks() {
57
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 );
58
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60
-        add_action( 'admin_init', array( $this, 'activation_redirect') );
61
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
66
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
68
-        add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
74
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
75
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
76
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
77
-		do_action( 'getpaid_init_admin_hooks', $this );
57
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'), 9);
58
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
59
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
60
+        add_action('admin_init', array($this, 'activation_redirect'));
61
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
62
+		add_action('admin_notices', array($this, 'show_notices'));
63
+		add_action('getpaid_authenticated_admin_action_rate_plugin', array($this, 'redirect_to_wordpress_rating_page'));
64
+		add_action('getpaid_authenticated_admin_action_duplicate_form', array($this, 'duplicate_payment_form'));
65
+		add_action('getpaid_authenticated_admin_action_duplicate_invoice', array($this, 'duplicate_invoice'));
66
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
67
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
68
+        add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates'));
69
+		add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages'));
70
+		add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables'));
71
+		add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices'));
72
+		add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers'));
73
+		add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts'));
74
+		add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin'));
75
+		add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway'));
76
+		add_filter('admin_footer_text', array($this, 'admin_footer_text'));
77
+		do_action('getpaid_init_admin_hooks', $this);
78 78
 
79 79
 		// Setup/welcome
80
-		if ( ! empty( $_GET['page'] ) ) {
81
-			switch ( $_GET['page'] ) {
80
+		if (!empty($_GET['page'])) {
81
+			switch ($_GET['page']) {
82 82
 				case 'gp-setup' :
83
-					include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
83
+					include_once(dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php');
84 84
 					break;
85 85
 			}
86 86
 		}
@@ -94,37 +94,37 @@  discard block
 block discarded – undo
94 94
 	public function enqeue_scripts() {
95 95
         global $current_screen, $pagenow;
96 96
 
97
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
97
+		$page    = isset($_GET['page']) ? $_GET['page'] : '';
98 98
 		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
99 99
 
100
-        if ( ! empty( $current_screen->post_type ) ) {
100
+        if (!empty($current_screen->post_type)) {
101 101
 			$page = $current_screen->post_type;
102 102
         }
103 103
 
104 104
         // General styles.
105
-        if ( false !== stripos( $page, 'wpi' ) || false !== stripos( $page, 'getpaid' ) || 'gp-setup' == $page || 'geodir-tickets' == $page ) {
105
+        if (false !== stripos($page, 'wpi') || false !== stripos($page, 'getpaid') || 'gp-setup' == $page || 'geodir-tickets' == $page) {
106 106
 
107 107
             // Styles.
108
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
109
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
110
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
108
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
109
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
110
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
111 111
 
112 112
             // Scripts.
113
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
113
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
114 114
 
115
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
116
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ),  $version );
117
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
115
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
116
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version);
117
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
118 118
 
119 119
         }
120 120
 
121 121
         // Payment form scripts.
122
-		if ( 'wpi_payment_form' == $page && $editing ) {
122
+		if ('wpi_payment_form' == $page && $editing) {
123 123
             $this->load_payment_form_scripts();
124 124
         }
125 125
 
126
-		if ( $page == 'wpinv-subscriptions' ) {
127
-			wp_enqueue_script( 'postbox' );
126
+		if ($page == 'wpinv-subscriptions') {
127
+			wp_enqueue_script('postbox');
128 128
 		}
129 129
 
130 130
     }
@@ -137,32 +137,32 @@  discard block
 block discarded – undo
137 137
         global $post;
138 138
 
139 139
 		$date_range = array(
140
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
140
+			'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days'
141 141
 		);
142 142
 
143
-		if ( $date_range['period'] == 'custom' ) {
143
+		if ($date_range['period'] == 'custom') {
144 144
 			
145
-			if ( isset( $_GET['from'] ) ) {
146
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
145
+			if (isset($_GET['from'])) {
146
+				$date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS);
147 147
 			}
148 148
 
149
-			if ( isset( $_GET['to'] ) ) {
150
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
149
+			if (isset($_GET['to'])) {
150
+				$date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS);
151 151
 			}
152 152
 
153 153
 		}
154 154
 
155 155
         $i18n = array(
156
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
157
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
158
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
159
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
160
-			'rest_root'                 => esc_url_raw( rest_url() ),
156
+            'ajax_url'                  => admin_url('admin-ajax.php'),
157
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
158
+			'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
159
+			'rest_nonce'                => wp_create_nonce('wp_rest'),
160
+			'rest_root'                 => esc_url_raw(rest_url()),
161 161
 			'date_range'                => $date_range,
162
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
163
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
164
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
165
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
162
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
163
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
164
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
165
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
166 166
             'tax'                       => wpinv_tax_amount(),
167 167
             'discount'                  => 0,
168 168
 			'currency_symbol'           => wpinv_currency_symbol(),
@@ -171,38 +171,38 @@  discard block
 block discarded – undo
171 171
             'thousand_sep'              => wpinv_thousands_separator(),
172 172
             'decimal_sep'               => wpinv_decimal_separator(),
173 173
             'decimals'                  => wpinv_decimals(),
174
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
175
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
176
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
177
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
178
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
179
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
180
-            'confirmCalcTotals'         => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ),
181
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
182
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
183
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
184
-            'action_edit'               => __( 'Edit', 'invoicing' ),
185
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
186
-            'item_description'          => __( 'Item Description', 'invoicing' ),
187
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
188
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
189
-			'searching'                 => __( 'Searching', 'invoicing' ),
190
-			'loading'                   => __( 'Loading...', 'invoicing' ),
191
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
192
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
174
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
175
+            'status_publish'            => wpinv_status_nicename('publish'),
176
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
177
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
178
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
179
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
180
+            'confirmCalcTotals'         => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'),
181
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
182
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
183
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
184
+            'action_edit'               => __('Edit', 'invoicing'),
185
+            'action_cancel'             => __('Cancel', 'invoicing'),
186
+            'item_description'          => __('Item Description', 'invoicing'),
187
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
188
+            'discount_description'      => __('Discount Description', 'invoicing'),
189
+			'searching'                 => __('Searching', 'invoicing'),
190
+			'loading'                   => __('Loading...', 'invoicing'),
191
+			'search_customers'          => __('Enter customer name or email', 'invoicing'),
192
+			'search_items'              => __('Enter item name', 'invoicing'),
193 193
         );
194 194
 
195
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
195
+		if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) {
196 196
 
197
-			$invoice              = new WPInv_Invoice( $post );
197
+			$invoice              = new WPInv_Invoice($post);
198 198
 			$i18n['save_invoice'] = sprintf(
199
-				__( 'Save %s', 'invoicing' ),
200
-				ucfirst( $invoice->get_invoice_quote_type() )
199
+				__('Save %s', 'invoicing'),
200
+				ucfirst($invoice->get_invoice_quote_type())
201 201
 			);
202 202
 
203 203
 			$i18n['invoice_description'] = sprintf(
204
-				__( '%s Description', 'invoicing' ),
205
-				ucfirst( $invoice->get_invoice_quote_type() )
204
+				__('%s Description', 'invoicing'),
205
+				ucfirst($invoice->get_invoice_quote_type())
206 206
 			);
207 207
 
208 208
 		}
@@ -216,24 +216,24 @@  discard block
 block discarded – undo
216 216
 	 * @param  string $footer_text
217 217
 	 * @return string
218 218
 	 */
219
-	public function admin_footer_text( $footer_text ) {
219
+	public function admin_footer_text($footer_text) {
220 220
 		global $current_screen;
221 221
 
222
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
222
+		$page = isset($_GET['page']) ? $_GET['page'] : '';
223 223
 
224
-        if ( ! empty( $current_screen->post_type ) ) {
224
+        if (!empty($current_screen->post_type)) {
225 225
 			$page = $current_screen->post_type;
226 226
         }
227 227
 
228 228
         // General styles.
229
-        if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
229
+        if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) {
230 230
 
231 231
 			// Change the footer text
232
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
232
+			if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) {
233 233
 
234
-				$rating_url  = esc_url(
234
+				$rating_url = esc_url(
235 235
 					wp_nonce_url(
236
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
236
+						admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'),
237 237
 						'getpaid-nonce',
238 238
 						'getpaid-nonce'
239 239
 						)
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 
242 242
 				$footer_text = sprintf(
243 243
 					/* translators: %s: five stars */
244
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
244
+					__('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'),
245 245
 					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
246 246
 				);
247 247
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 
250 250
 				$footer_text = sprintf(
251 251
 					/* translators: %s: GetPaid */
252
-					__( 'Thank you for using %s!', 'invoicing' ),
252
+					__('Thank you for using %s!', 'invoicing'),
253 253
 					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
254 254
 				);
255 255
 
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 	 * @since  2.0.0
267 267
 	 */
268 268
 	public function redirect_to_wordpress_rating_page() {
269
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
270
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
269
+		update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1);
270
+		wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post');
271 271
 		exit;
272 272
 	}
273 273
 
@@ -278,30 +278,30 @@  discard block
 block discarded – undo
278 278
 	protected function load_payment_form_scripts() {
279 279
         global $post;
280 280
 
281
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION );
282
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
283
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
281
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION);
282
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
283
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
284 284
 
285
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
286
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ),  $version );
285
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
286
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable', 'wp-hooks'), $version);
287 287
 
288 288
 		wp_localize_script(
289 289
             'wpinv-admin-payment-form-script',
290 290
             'wpinvPaymentFormAdmin',
291 291
             array(
292
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
293
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
292
+				'elements'      => wpinv_get_data('payment-form-elements'),
293
+				'form_elements' => getpaid_get_payment_form_elements($post->ID),
294 294
 				'currency'      => wpinv_currency_symbol(),
295 295
 				'position'      => wpinv_currency_position(),
296 296
 				'decimals'      => (int) wpinv_decimals(),
297 297
 				'thousands_sep' => wpinv_thousands_separator(),
298 298
 				'decimals_sep'  => wpinv_decimal_separator(),
299
-				'form_items'    => gepaid_get_form_items( $post->ID ),
299
+				'form_items'    => gepaid_get_form_items($post->ID),
300 300
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
301 301
             )
302 302
         );
303 303
 
304
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
304
+        wp_enqueue_script('wpinv-admin-payment-form-script');
305 305
 
306 306
     }
307 307
 
@@ -312,25 +312,25 @@  discard block
 block discarded – undo
312 312
      * @return string
313 313
 	 *
314 314
 	 */
315
-    public function admin_body_class( $classes ) {
315
+    public function admin_body_class($classes) {
316 316
 		global $pagenow, $post, $current_screen;
317 317
 
318 318
 
319
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
319
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
320 320
 
321
-        if ( ! empty( $current_screen->post_type ) ) {
321
+        if (!empty($current_screen->post_type)) {
322 322
 			$page = $current_screen->post_type;
323 323
         }
324 324
 
325
-        if ( false !== stripos( $page, 'wpi' ) ) {
326
-            $classes .= ' wpi-' . sanitize_key( $page );
325
+        if (false !== stripos($page, 'wpi')) {
326
+            $classes .= ' wpi-' . sanitize_key($page);
327 327
         }
328 328
 
329
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
329
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
330 330
             $classes .= ' wpinv-cpt wpinv';
331 331
 		}
332 332
 		
333
-		if ( getpaid_is_invoice_post_type( $page ) ) {
333
+		if (getpaid_is_invoice_post_type($page)) {
334 334
             $classes .= ' getpaid-is-invoice-cpt';
335 335
         }
336 336
 
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
     /**
341 341
 	 * Maybe show the AyeCode Connect Notice.
342 342
 	 */
343
-	public function init_ayecode_connect_helper(){
343
+	public function init_ayecode_connect_helper() {
344 344
 
345 345
 		// Register with the deactivation survey class.
346 346
 		AyeCode_Deactivation_Survey::instance(array(
@@ -348,20 +348,20 @@  discard block
 block discarded – undo
348 348
 			'version'	        => WPINV_VERSION,
349 349
 			'support_url'       => 'https://wpgetpaid.com/support/',
350 350
 			'documentation_url' => 'https://docs.wpgetpaid.com/',
351
-			'activated'         => (int) get_option( 'gepaid_installed_on' ),
351
+			'activated'         => (int) get_option('gepaid_installed_on'),
352 352
 		));
353 353
 
354 354
         new AyeCode_Connect_Helper(
355 355
             array(
356
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
357
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
358
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
359
-				'connect_button'    => __("Connect Site","invoicing"),
360
-				'connecting_button'    => __("Connecting...","invoicing"),
361
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
362
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
356
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
357
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
358
+				'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
359
+				'connect_button'    => __("Connect Site", "invoicing"),
360
+				'connecting_button'    => __("Connecting...", "invoicing"),
361
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
362
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
363 363
             ),
364
-            array( 'wpi-addons' )
364
+            array('wpi-addons')
365 365
         );
366 366
 
367 367
     }
@@ -373,20 +373,20 @@  discard block
 block discarded – undo
373 373
 	 */
374 374
 	public function activation_redirect() {
375 375
 
376
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
376
+		$redirected = get_option('wpinv_redirected_to_settings');
377 377
 
378
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
378
+		if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) {
379 379
 			return;
380 380
 		}
381 381
 
382 382
 		// Bail if activating from network, or bulk
383
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
383
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
384 384
 			return;
385 385
 		}
386 386
 
387
-	    update_option( 'wpinv_redirected_to_settings', 1 );
387
+	    update_option('wpinv_redirected_to_settings', 1);
388 388
 
389
-        wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
389
+        wp_safe_redirect(admin_url('index.php?page=gp-setup'));
390 390
         exit;
391 391
 
392 392
 	}
@@ -396,9 +396,9 @@  discard block
 block discarded – undo
396 396
      */
397 397
     public function maybe_do_admin_action() {
398 398
 
399
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
400
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
401
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
399
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
400
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
401
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
402 402
         }
403 403
 
404 404
     }
@@ -408,24 +408,24 @@  discard block
 block discarded – undo
408 408
 	 * 
409 409
 	 * @param array $args
410 410
      */
411
-    public function duplicate_invoice( $args ) {
411
+    public function duplicate_invoice($args) {
412 412
 
413
-		if ( empty( $args['invoice_id'] ) ) {
413
+		if (empty($args['invoice_id'])) {
414 414
 			return;
415 415
 		}
416 416
 
417
-		$invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
417
+		$invoice = new WPInv_Invoice((int) $args['invoice_id']);
418 418
 
419
-		if ( ! $invoice->exists() ) {
419
+		if (!$invoice->exists()) {
420 420
 			return;
421 421
 		}
422 422
 
423
-		$new_invoice = getpaid_duplicate_invoice( $invoice );
423
+		$new_invoice = getpaid_duplicate_invoice($invoice);
424 424
 		$new_invoice->save();
425 425
 
426
-		if ( $new_invoice->exists() ) {
426
+		if ($new_invoice->exists()) {
427 427
 
428
-			getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) );
428
+			getpaid_admin()->show_success(__('Invoice duplicated successfully.', 'newsletter-optin-box'));
429 429
 
430 430
 			wp_safe_redirect(
431 431
 				add_query_arg(
@@ -433,14 +433,14 @@  discard block
 block discarded – undo
433 433
 						'action' => 'edit',
434 434
 						'post' => $new_invoice->get_id(),
435 435
 					),
436
-					admin_url( 'post.php' )
436
+					admin_url('post.php')
437 437
 				)
438 438
 			);
439 439
 			exit;
440 440
 
441 441
 		}
442 442
 
443
-		getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) );
443
+		getpaid_admin()->show_error(__('There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box'));
444 444
 
445 445
 	}
446 446
 
@@ -449,34 +449,34 @@  discard block
 block discarded – undo
449 449
 	 * 
450 450
 	 * @param array $args
451 451
      */
452
-    public function duplicate_payment_form( $args ) {
452
+    public function duplicate_payment_form($args) {
453 453
 
454
-		if ( empty( $args['form_id'] ) ) {
454
+		if (empty($args['form_id'])) {
455 455
 			return;
456 456
 		}
457 457
 
458
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
458
+		$form = new GetPaid_Payment_Form((int) $args['form_id']);
459 459
 
460
-		if ( ! $form->exists() ) {
460
+		if (!$form->exists()) {
461 461
 			return;
462 462
 		}
463 463
 
464 464
 		$new_form = new GetPaid_Payment_Form();
465
-		$new_form->set_author( $form->get_author( 'edit' ) );
466
-		$new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
467
-		$new_form->set_elements( $form->get_elements( 'edit' ) );
468
-		$new_form->set_items( $form->get_items( 'edit' ) );
465
+		$new_form->set_author($form->get_author('edit'));
466
+		$new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing'));
467
+		$new_form->set_elements($form->get_elements('edit'));
468
+		$new_form->set_items($form->get_items('edit'));
469 469
 		$new_form->save();
470 470
 
471
-		if ( $new_form->exists() ) {
472
-			$this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
473
-			$url = get_edit_post_link( $new_form->get_id(), 'edit' );
471
+		if ($new_form->exists()) {
472
+			$this->show_success(__('Form duplicated successfully', 'invoicing'));
473
+			$url = get_edit_post_link($new_form->get_id(), 'edit');
474 474
 		} else {
475
-			$this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
476
-			$url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
475
+			$this->show_error(__('Unable to duplicate form', 'invoicing'));
476
+			$url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce'));
477 477
 		}
478 478
 
479
-		wp_redirect( $url );
479
+		wp_redirect($url);
480 480
 		exit;
481 481
 	}
482 482
 
@@ -485,9 +485,9 @@  discard block
 block discarded – undo
485 485
 	 * 
486 486
 	 * @param array $args
487 487
      */
488
-    public function send_customer_invoice( $args ) {
489
-		getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
490
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
488
+    public function send_customer_invoice($args) {
489
+		getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true);
490
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
491 491
 		exit;
492 492
 	}
493 493
 
@@ -496,16 +496,16 @@  discard block
 block discarded – undo
496 496
 	 * 
497 497
 	 * @param array $args
498 498
      */
499
-    public function send_customer_payment_reminder( $args ) {
500
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
499
+    public function send_customer_payment_reminder($args) {
500
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
501 501
 
502
-		if ( $sent ) {
503
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
502
+		if ($sent) {
503
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
504 504
 		} else {
505
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
505
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
506 506
 		}
507 507
 
508
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
508
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
509 509
 		exit;
510 510
 	}
511 511
 
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
      */
516 516
     public function admin_reset_tax_rates() {
517 517
 
518
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
519
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
518
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
519
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
520 520
 		exit;
521 521
 
522 522
 	}
@@ -528,8 +528,8 @@  discard block
 block discarded – undo
528 528
     public function admin_create_missing_pages() {
529 529
 		$installer = new GetPaid_Installer();
530 530
 		$installer->create_pages();
531
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
532
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
531
+		$this->show_success(__('GetPaid pages updated.', 'invoicing'));
532
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
533 533
 		exit;
534 534
 	}
535 535
 
@@ -541,35 +541,35 @@  discard block
 block discarded – undo
541 541
 		global $wpdb;
542 542
 		$installer = new GetPaid_Installer();
543 543
 
544
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
544
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'") != $wpdb->prefix . 'wpinv_subscriptions') {
545 545
 			$installer->create_subscriptions_table();
546 546
 
547
-			if ( $wpdb->last_error !== '' ) {
548
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
547
+			if ($wpdb->last_error !== '') {
548
+				$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
549 549
 			}
550 550
 		}
551 551
 
552
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
552
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") != $wpdb->prefix . 'getpaid_invoices') {
553 553
 			$installer->create_invoices_table();
554 554
 
555
-			if ( $wpdb->last_error !== '' ) {
556
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
555
+			if ($wpdb->last_error !== '') {
556
+				$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
557 557
 			}
558 558
 		}
559 559
 
560
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
560
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'") != $wpdb->prefix . 'getpaid_invoice_items') {
561 561
 			$installer->create_invoice_items_table();
562 562
 
563
-			if ( $wpdb->last_error !== '' ) {
564
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
563
+			if ($wpdb->last_error !== '') {
564
+				$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
565 565
 			}
566 566
 		}
567 567
 
568
-		if ( ! $this->has_notices() ) {
569
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
568
+		if (!$this->has_notices()) {
569
+			$this->show_success(__('Your GetPaid tables have been updated.', 'invoicing'));
570 570
 		}
571 571
 
572
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
572
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
573 573
 		exit;
574 574
 	}
575 575
 
@@ -584,10 +584,10 @@  discard block
 block discarded – undo
584 584
 		$installer->migrate_old_invoices();
585 585
 
586 586
 		// Show an admin message.
587
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
587
+		$this->show_success(__('Your invoices have been migrated.', 'invoicing'));
588 588
 
589 589
 		// Redirect the admin.
590
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
590
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
591 591
 		exit;
592 592
 
593 593
 	}
@@ -599,18 +599,18 @@  discard block
 block discarded – undo
599 599
     public function admin_download_customers() {
600 600
 		global $wpdb;
601 601
 
602
-		$output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
602
+		$output = fopen('php://output', 'w') or die(__('Unsupported server', 'invoicing'));
603 603
 
604
-		header( "Content-Type:text/csv" );
605
-		header( "Content-Disposition:attachment;filename=customers.csv" );
604
+		header("Content-Type:text/csv");
605
+		header("Content-Disposition:attachment;filename=customers.csv");
606 606
 
607 607
 		$post_types = '';
608 608
 
609
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
610
-			$post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
609
+		foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) {
610
+			$post_types .= $wpdb->prepare("post_type=%s OR ", $post_type);
611 611
 		}
612 612
 
613
-		$post_types = rtrim( $post_types, ' OR' );
613
+		$post_types = rtrim($post_types, ' OR');
614 614
 
615 615
 		$customers = $wpdb->get_col(
616 616
 			$wpdb->prepare(
@@ -619,58 +619,58 @@  discard block
 block discarded – undo
619 619
 		);
620 620
 
621 621
 		$columns = array(
622
-			'name'     => __( 'Name', 'invoicing' ),
623
-			'email'    => __( 'Email', 'invoicing' ),
624
-			'country'  => __( 'Country', 'invoicing' ),
625
-			'state'    => __( 'State', 'invoicing' ),
626
-			'city'     => __( 'City', 'invoicing' ),
627
-			'zip'      => __( 'ZIP', 'invoicing' ),
628
-			'address'  => __( 'Address', 'invoicing' ),
629
-			'phone'    => __( 'Phone', 'invoicing' ),
630
-			'company'  => __( 'Company', 'invoicing' ),
631
-			'company_id'  => __( 'Company ID', 'invoicing' ),
632
-			'invoices' => __( 'Invoices', 'invoicing' ),
633
-			'total_raw' => __( 'Total Spend', 'invoicing' ),
634
-			'signup'   => __( 'Date created', 'invoicing' ),
622
+			'name'     => __('Name', 'invoicing'),
623
+			'email'    => __('Email', 'invoicing'),
624
+			'country'  => __('Country', 'invoicing'),
625
+			'state'    => __('State', 'invoicing'),
626
+			'city'     => __('City', 'invoicing'),
627
+			'zip'      => __('ZIP', 'invoicing'),
628
+			'address'  => __('Address', 'invoicing'),
629
+			'phone'    => __('Phone', 'invoicing'),
630
+			'company'  => __('Company', 'invoicing'),
631
+			'company_id'  => __('Company ID', 'invoicing'),
632
+			'invoices' => __('Invoices', 'invoicing'),
633
+			'total_raw' => __('Total Spend', 'invoicing'),
634
+			'signup'   => __('Date created', 'invoicing'),
635 635
 		);
636 636
 
637 637
 		// Output the csv column headers.
638
-		fputcsv( $output, array_values( $columns ) );
638
+		fputcsv($output, array_values($columns));
639 639
 
640 640
 		// Loop through
641 641
 		$table = new WPInv_Customers_Table();
642
-		foreach ( $customers as $customer_id ) {
642
+		foreach ($customers as $customer_id) {
643 643
 
644
-			$user = get_user_by( 'id', $customer_id );
644
+			$user = get_user_by('id', $customer_id);
645 645
 			$row  = array();
646
-			if ( empty( $user ) ) {
646
+			if (empty($user)) {
647 647
 				continue;
648 648
 			}
649 649
 
650
-			foreach ( array_keys( $columns ) as $column ) {
650
+			foreach (array_keys($columns) as $column) {
651 651
 
652 652
 				$method = 'column_' . $column;
653 653
 
654
-				if ( 'name' == $column ) {
655
-					$value = esc_html( $user->display_name );
656
-				} else if( 'email' == $column ) {
657
-					$value = sanitize_email( $user->user_email );
658
-				} else if ( is_callable( array( $table, $method ) ) ) {
659
-					$value = strip_tags( $table->$method( $user ) );
654
+				if ('name' == $column) {
655
+					$value = esc_html($user->display_name);
656
+				} else if ('email' == $column) {
657
+					$value = sanitize_email($user->user_email);
658
+				} else if (is_callable(array($table, $method))) {
659
+					$value = strip_tags($table->$method($user));
660 660
 				}
661 661
 
662
-				if ( empty( $value ) ) {
663
-					$value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
662
+				if (empty($value)) {
663
+					$value = esc_html(get_user_meta($user->ID, '_wpinv_' . $column, true));
664 664
 				}
665 665
 
666 666
 				$row[] = $value;
667 667
 
668 668
 			}
669 669
 
670
-			fputcsv( $output, $row );
670
+			fputcsv($output, $row);
671 671
 		}
672 672
 
673
-		fclose( $output );
673
+		fclose($output);
674 674
 		exit;
675 675
 
676 676
 	}
@@ -680,29 +680,29 @@  discard block
 block discarded – undo
680 680
 	 *
681 681
 	 * @param array $data
682 682
      */
683
-    public function admin_install_plugin( $data ) {
683
+    public function admin_install_plugin($data) {
684 684
 
685
-		if ( ! empty( $data['plugins'] ) ) {
685
+		if (!empty($data['plugins'])) {
686 686
 			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
687 687
 			wp_cache_flush();
688 688
 
689
-			foreach ( $data['plugins'] as $slug => $file ) {
690
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
691
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
692
-				$installed  = $upgrader->install( $plugin_zip );
689
+			foreach ($data['plugins'] as $slug => $file) {
690
+				$plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip');
691
+				$upgrader   = new Plugin_Upgrader(new Automatic_Upgrader_Skin());
692
+				$installed  = $upgrader->install($plugin_zip);
693 693
 
694
-				if ( ! is_wp_error( $installed ) && $installed ) {
695
-					activate_plugin( $file, '', false, true );
694
+				if (!is_wp_error($installed) && $installed) {
695
+					activate_plugin($file, '', false, true);
696 696
 				} else {
697
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
697
+					wpinv_error_log($upgrader->skin->get_upgrade_messages(), false);
698 698
 				}
699 699
 
700 700
 			}
701 701
 
702 702
 		}
703 703
 
704
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
705
-		wp_safe_redirect( $redirect );
704
+		$redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php');
705
+		wp_safe_redirect($redirect);
706 706
 		exit;
707 707
 
708 708
 	}
@@ -712,42 +712,42 @@  discard block
 block discarded – undo
712 712
 	 *
713 713
 	 * @param array $data
714 714
      */
715
-    public function admin_connect_gateway( $data ) {
715
+    public function admin_connect_gateway($data) {
716 716
 
717
-		if ( ! empty( $data['plugin'] ) ) {
717
+		if (!empty($data['plugin'])) {
718 718
 
719
-			$gateway     = sanitize_key( $data['plugin'] );
720
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
719
+			$gateway     = sanitize_key($data['plugin']);
720
+			$connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data);
721 721
 
722
-			if ( ! empty( $connect_url ) ) {
723
-				wp_redirect( $connect_url );
722
+			if (!empty($connect_url)) {
723
+				wp_redirect($connect_url);
724 724
 				exit;
725 725
 			}
726 726
 
727
-			if ( 'stripe' == $data['plugin'] ) {
727
+			if ('stripe' == $data['plugin']) {
728 728
 				require_once ABSPATH . 'wp-admin/includes/plugin.php';
729 729
 				include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
730 730
 				wp_cache_flush();
731 731
 
732
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
733
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
734
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
735
-					$upgrader->install( $plugin_zip );
732
+				if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) {
733
+					$plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip');
734
+					$upgrader   = new Plugin_Upgrader(new Automatic_Upgrader_Skin());
735
+					$upgrader->install($plugin_zip);
736 736
 				}
737 737
 
738
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
738
+				activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true);
739 739
 			}
740 740
 
741
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
742
-			if ( ! empty( $connect_url ) ) {
743
-				wp_redirect( $connect_url );
741
+			$connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data);
742
+			if (!empty($connect_url)) {
743
+				wp_redirect($connect_url);
744 744
 				exit;
745 745
 			}
746 746
 
747 747
 		}
748 748
 
749
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
750
-		wp_safe_redirect( $redirect );
749
+		$redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways');
750
+		wp_safe_redirect($redirect);
751 751
 		exit;
752 752
 
753 753
 	}
@@ -761,36 +761,36 @@  discard block
 block discarded – undo
761 761
 
762 762
 		// Fetch all invoices that have discount codes.
763 763
 		$table    = $wpdb->prefix . 'getpaid_invoices';
764
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
764
+		$invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''");
765 765
 
766
-		foreach ( $invoices as $invoice ) {
766
+		foreach ($invoices as $invoice) {
767 767
 
768
-			$invoice = new WPInv_Invoice( $invoice );
768
+			$invoice = new WPInv_Invoice($invoice);
769 769
 
770
-			if ( ! $invoice->exists() ) {
770
+			if (!$invoice->exists()) {
771 771
 				continue;
772 772
 			}
773 773
 
774 774
 			// Abort if the discount does not exist or does not apply here.
775
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
776
-			if ( ! $discount->exists() ) {
775
+			$discount = new WPInv_Discount($invoice->get_discount_code());
776
+			if (!$discount->exists()) {
777 777
 				continue;
778 778
 			}
779 779
 
780
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
780
+			$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
781 781
 			$invoice->recalculate_total();
782 782
 
783
-			if ( $invoice->get_total_discount() > 0 ) {
783
+			if ($invoice->get_total_discount() > 0) {
784 784
 				$invoice->save();
785 785
 			}
786 786
 
787 787
 		}
788 788
 
789 789
 		// Show an admin message.
790
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
790
+		$this->show_success(__('Discounts have been recalculated.', 'invoicing'));
791 791
 
792 792
 		// Redirect the admin.
793
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
793
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
794 794
 		exit;
795 795
 
796 796
 	}
@@ -802,8 +802,8 @@  discard block
 block discarded – undo
802 802
      * @return array
803 803
 	 */
804 804
 	public function get_notices() {
805
-		$notices = get_option( 'wpinv_admin_notices' );
806
-        return is_array( $notices ) ? $notices : array();
805
+		$notices = get_option('wpinv_admin_notices');
806
+        return is_array($notices) ? $notices : array();
807 807
 	}
808 808
 
809 809
 	/**
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
      * @return array
814 814
 	 */
815 815
 	public function has_notices() {
816
-		return count( $this->get_notices() ) > 0;
816
+		return count($this->get_notices()) > 0;
817 817
 	}
818 818
 
819 819
 	/**
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 	 * @since       1.0.19
824 824
 	 */
825 825
 	public function clear_notices() {
826
-		delete_option( 'wpinv_admin_notices' );
826
+		delete_option('wpinv_admin_notices');
827 827
 	}
828 828
 
829 829
 	/**
@@ -832,16 +832,16 @@  discard block
 block discarded – undo
832 832
 	 * @access      public
833 833
 	 * @since       1.0.19
834 834
 	 */
835
-	public function save_notice( $type, $message ) {
835
+	public function save_notice($type, $message) {
836 836
 		$notices = $this->get_notices();
837 837
 
838
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
839
-			$notices[ $type ] = array();
838
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
839
+			$notices[$type] = array();
840 840
 		}
841 841
 
842
-		$notices[ $type ][] = $message;
842
+		$notices[$type][] = $message;
843 843
 
844
-		update_option( 'wpinv_admin_notices', $notices );
844
+		update_option('wpinv_admin_notices', $notices);
845 845
 	}
846 846
 
847 847
 	/**
@@ -851,8 +851,8 @@  discard block
 block discarded – undo
851 851
 	 * @access      public
852 852
 	 * @since       1.0.19
853 853
 	 */
854
-	public function show_success( $msg ) {
855
-		$this->save_notice( 'success', $msg );
854
+	public function show_success($msg) {
855
+		$this->save_notice('success', $msg);
856 856
 	}
857 857
 
858 858
 	/**
@@ -862,8 +862,8 @@  discard block
 block discarded – undo
862 862
 	 * @param       string $msg The message to qeue.
863 863
 	 * @since       1.0.19
864 864
 	 */
865
-	public function show_error( $msg ) {
866
-		$this->save_notice( 'error', $msg );
865
+	public function show_error($msg) {
866
+		$this->save_notice('error', $msg);
867 867
 	}
868 868
 
869 869
 	/**
@@ -873,8 +873,8 @@  discard block
 block discarded – undo
873 873
 	 * @param       string $msg The message to qeue.
874 874
 	 * @since       1.0.19
875 875
 	 */
876
-	public function show_warning( $msg ) {
877
-		$this->save_notice( 'warning', $msg );
876
+	public function show_warning($msg) {
877
+		$this->save_notice('warning', $msg);
878 878
 	}
879 879
 
880 880
 	/**
@@ -884,8 +884,8 @@  discard block
 block discarded – undo
884 884
 	 * @param       string $msg The message to qeue.
885 885
 	 * @since       1.0.19
886 886
 	 */
887
-	public function show_info( $msg ) {
888
-		$this->save_notice( 'info', $msg );
887
+	public function show_info($msg) {
888
+		$this->save_notice('info', $msg);
889 889
 	}
890 890
 
891 891
 	/**
@@ -899,30 +899,30 @@  discard block
 block discarded – undo
899 899
         $notices = $this->get_notices();
900 900
         $this->clear_notices();
901 901
 
902
-		foreach ( $notices as $type => $messages ) {
902
+		foreach ($notices as $type => $messages) {
903 903
 
904
-			if ( ! is_array( $messages ) ) {
904
+			if (!is_array($messages)) {
905 905
 				continue;
906 906
 			}
907 907
 
908
-            $type  = sanitize_key( $type );
909
-			foreach ( $messages as $message ) {
910
-                $message = wp_kses_post( $message );
908
+            $type = sanitize_key($type);
909
+			foreach ($messages as $message) {
910
+                $message = wp_kses_post($message);
911 911
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
912 912
             }
913 913
 
914 914
         }
915 915
 
916
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
916
+		foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) {
917 917
 
918
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
919
-				$url     = wp_nonce_url(
920
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
918
+			if (!is_numeric(wpinv_get_option($page, false))) {
919
+				$url = wp_nonce_url(
920
+					add_query_arg('getpaid-admin-action', 'create_missing_pages'),
921 921
 					'getpaid-nonce',
922 922
 					'getpaid-nonce'
923 923
 				);
924
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
925
-				$message2 = __( 'Generate Pages', 'invoicing' );
924
+				$message  = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing');
925
+				$message2 = __('Generate Pages', 'invoicing');
926 926
 				echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
927 927
 				break;
928 928
 			}
Please login to merge, or discard this patch.