Passed
Push — master ( 55080f...acb8be )
by Brian
04:32
created
includes/admin/class-getpaid-admin.php 1 patch
Spacing   +186 added lines, -186 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,22 +54,22 @@  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' ) );
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_send_invoice', array( $this, 'send_customer_invoice' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
66
-        add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
71
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
72
-		do_action( 'getpaid_init_admin_hooks', $this );
57
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));
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_send_invoice', array($this, 'send_customer_invoice'));
65
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
66
+        add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates'));
67
+		add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages'));
68
+		add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables'));
69
+		add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices'));
70
+		add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts'));
71
+		add_filter('admin_footer_text', array($this, 'admin_footer_text'));
72
+		do_action('getpaid_init_admin_hooks', $this);
73 73
 
74 74
     }
75 75
 
@@ -80,37 +80,37 @@  discard block
 block discarded – undo
80 80
 	public function enqeue_scripts() {
81 81
         global $current_screen, $pagenow;
82 82
 
83
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
83
+		$page    = isset($_GET['page']) ? $_GET['page'] : '';
84 84
 		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
85 85
 
86
-        if ( ! empty( $current_screen->post_type ) ) {
86
+        if (!empty($current_screen->post_type)) {
87 87
 			$page = $current_screen->post_type;
88 88
         }
89 89
 
90 90
         // General styles.
91
-        if ( false !== stripos( $page, 'wpi' ) ) {
91
+        if (false !== stripos($page, 'wpi')) {
92 92
 
93 93
             // Styles.
94
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
95
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
96
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
94
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
95
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
96
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
97 97
 
98 98
             // Scripts.
99
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
99
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
100 100
 
101
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
102
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker' ),  $version );
103
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
101
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
102
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker'), $version);
103
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
104 104
 
105 105
         }
106 106
 
107 107
         // Payment form scripts.
108
-		if ( 'wpi_payment_form' == $page && $editing ) {
108
+		if ('wpi_payment_form' == $page && $editing) {
109 109
             $this->load_payment_form_scripts();
110 110
         }
111 111
 
112
-		if ( $page == 'wpinv-subscriptions' ) {
113
-			wp_enqueue_script( 'postbox' );
112
+		if ($page == 'wpinv-subscriptions') {
113
+			wp_enqueue_script('postbox');
114 114
 		}
115 115
 
116 116
     }
@@ -123,32 +123,32 @@  discard block
 block discarded – undo
123 123
         global $post;
124 124
 
125 125
 		$date_range = array(
126
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
126
+			'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days'
127 127
 		);
128 128
 
129
-		if ( $date_range['period'] == 'custom' ) {
129
+		if ($date_range['period'] == 'custom') {
130 130
 			
131
-			if ( isset( $_GET['from'] ) ) {
132
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
131
+			if (isset($_GET['from'])) {
132
+				$date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS);
133 133
 			}
134 134
 
135
-			if ( isset( $_GET['to'] ) ) {
136
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
135
+			if (isset($_GET['to'])) {
136
+				$date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS);
137 137
 			}
138 138
 
139 139
 		}
140 140
 
141 141
         $i18n = array(
142
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
143
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
144
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
145
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
146
-			'rest_root'                 => esc_url_raw( rest_url() ),
142
+            'ajax_url'                  => admin_url('admin-ajax.php'),
143
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
144
+			'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
145
+			'rest_nonce'                => wp_create_nonce('wp_rest'),
146
+			'rest_root'                 => esc_url_raw(rest_url()),
147 147
 			'date_range'                => $date_range,
148
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
149
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
150
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
151
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
148
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
149
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
150
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
151
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
152 152
             'tax'                       => wpinv_tax_amount(),
153 153
             'discount'                  => 0,
154 154
 			'currency_symbol'           => wpinv_currency_symbol(),
@@ -157,38 +157,38 @@  discard block
 block discarded – undo
157 157
             'thousand_sep'              => wpinv_thousands_separator(),
158 158
             'decimal_sep'               => wpinv_decimal_separator(),
159 159
             'decimals'                  => wpinv_decimals(),
160
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
161
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
162
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
163
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
164
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
165
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
166
-            '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' ),
167
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
168
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
169
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
170
-            'action_edit'               => __( 'Edit', 'invoicing' ),
171
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
172
-            'item_description'          => __( 'Item Description', 'invoicing' ),
173
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
174
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
175
-			'searching'                 => __( 'Searching', 'invoicing' ),
176
-			'loading'                   => __( 'Loading...', 'invoicing' ),
177
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
178
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
160
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
161
+            'status_publish'            => wpinv_status_nicename('publish'),
162
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
163
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
164
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
165
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
166
+            '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'),
167
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
168
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
169
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
170
+            'action_edit'               => __('Edit', 'invoicing'),
171
+            'action_cancel'             => __('Cancel', 'invoicing'),
172
+            'item_description'          => __('Item Description', 'invoicing'),
173
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
174
+            'discount_description'      => __('Discount Description', 'invoicing'),
175
+			'searching'                 => __('Searching', 'invoicing'),
176
+			'loading'                   => __('Loading...', 'invoicing'),
177
+			'search_customers'          => __('Enter customer name or email', 'invoicing'),
178
+			'search_items'              => __('Enter item name', 'invoicing'),
179 179
         );
180 180
 
181
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
181
+		if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) {
182 182
 
183
-			$invoice              = new WPInv_Invoice( $post );
183
+			$invoice              = new WPInv_Invoice($post);
184 184
 			$i18n['save_invoice'] = sprintf(
185
-				__( 'Save %s', 'invoicing' ),
186
-				ucfirst( $invoice->get_invoice_quote_type() )
185
+				__('Save %s', 'invoicing'),
186
+				ucfirst($invoice->get_invoice_quote_type())
187 187
 			);
188 188
 
189 189
 			$i18n['invoice_description'] = sprintf(
190
-				__( '%s Description', 'invoicing' ),
191
-				ucfirst( $invoice->get_invoice_quote_type() )
190
+				__('%s Description', 'invoicing'),
191
+				ucfirst($invoice->get_invoice_quote_type())
192 192
 			);
193 193
 
194 194
 		}
@@ -202,24 +202,24 @@  discard block
 block discarded – undo
202 202
 	 * @param  string $footer_text
203 203
 	 * @return string
204 204
 	 */
205
-	public function admin_footer_text( $footer_text ) {
205
+	public function admin_footer_text($footer_text) {
206 206
 		global $current_screen;
207 207
 
208
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
208
+		$page = isset($_GET['page']) ? $_GET['page'] : '';
209 209
 
210
-        if ( ! empty( $current_screen->post_type ) ) {
210
+        if (!empty($current_screen->post_type)) {
211 211
 			$page = $current_screen->post_type;
212 212
         }
213 213
 
214 214
         // General styles.
215
-        if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
215
+        if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) {
216 216
 
217 217
 			// Change the footer text
218
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
218
+			if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) {
219 219
 
220
-				$rating_url  = esc_url(
220
+				$rating_url = esc_url(
221 221
 					wp_nonce_url(
222
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
222
+						admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'),
223 223
 						'getpaid-nonce',
224 224
 						'getpaid-nonce'
225 225
 						)
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 
228 228
 				$footer_text = sprintf(
229 229
 					/* translators: %s: five stars */
230
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
230
+					__('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'),
231 231
 					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
232 232
 				);
233 233
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 
236 236
 				$footer_text = sprintf(
237 237
 					/* translators: %s: GetPaid */
238
-					__( 'Thank you for using %s!', 'invoicing' ),
238
+					__('Thank you for using %s!', 'invoicing'),
239 239
 					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
240 240
 				);
241 241
 
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 * @since  2.0.0
253 253
 	 */
254 254
 	public function redirect_to_wordpress_rating_page() {
255
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
256
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
255
+		update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1);
256
+		wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post');
257 257
 		exit;
258 258
 	}
259 259
 
@@ -264,30 +264,30 @@  discard block
 block discarded – undo
264 264
 	protected function load_payment_form_scripts() {
265 265
         global $post;
266 266
 
267
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
268
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
269
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
267
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
268
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
269
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
270 270
 
271
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
272
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
271
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
272
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
273 273
 
274 274
 		wp_localize_script(
275 275
             'wpinv-admin-payment-form-script',
276 276
             'wpinvPaymentFormAdmin',
277 277
             array(
278
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
279
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
278
+				'elements'      => wpinv_get_data('payment-form-elements'),
279
+				'form_elements' => getpaid_get_payment_form_elements($post->ID),
280 280
 				'currency'      => wpinv_currency_symbol(),
281 281
 				'position'      => wpinv_currency_position(),
282 282
 				'decimals'      => (int) wpinv_decimals(),
283 283
 				'thousands_sep' => wpinv_thousands_separator(),
284 284
 				'decimals_sep'  => wpinv_decimal_separator(),
285
-				'form_items'    => gepaid_get_form_items( $post->ID ),
285
+				'form_items'    => gepaid_get_form_items($post->ID),
286 286
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
287 287
             )
288 288
         );
289 289
 
290
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
290
+        wp_enqueue_script('wpinv-admin-payment-form-script');
291 291
 
292 292
     }
293 293
 
@@ -298,25 +298,25 @@  discard block
 block discarded – undo
298 298
      * @return string
299 299
 	 *
300 300
 	 */
301
-    public function admin_body_class( $classes ) {
301
+    public function admin_body_class($classes) {
302 302
 		global $pagenow, $post, $current_screen;
303 303
 
304 304
 
305
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
305
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
306 306
 
307
-        if ( ! empty( $current_screen->post_type ) ) {
307
+        if (!empty($current_screen->post_type)) {
308 308
 			$page = $current_screen->post_type;
309 309
         }
310 310
 
311
-        if ( false !== stripos( $page, 'wpi' ) ) {
312
-            $classes .= ' wpi-' . sanitize_key( $page );
311
+        if (false !== stripos($page, 'wpi')) {
312
+            $classes .= ' wpi-' . sanitize_key($page);
313 313
         }
314 314
 
315
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
315
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
316 316
             $classes .= ' wpinv-cpt wpinv';
317 317
 		}
318 318
 		
319
-		if ( getpaid_is_invoice_post_type( $page ) ) {
319
+		if (getpaid_is_invoice_post_type($page)) {
320 320
             $classes .= ' getpaid-is-invoice-cpt';
321 321
         }
322 322
 
@@ -326,19 +326,19 @@  discard block
 block discarded – undo
326 326
     /**
327 327
 	 * Maybe show the AyeCode Connect Notice.
328 328
 	 */
329
-	public function init_ayecode_connect_helper(){
329
+	public function init_ayecode_connect_helper() {
330 330
 
331 331
         new AyeCode_Connect_Helper(
332 332
             array(
333
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
334
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
335
-				'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>" ),
336
-				'connect_button'    => __("Connect Site","invoicing"),
337
-				'connecting_button'    => __("Connecting...","invoicing"),
338
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
339
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
333
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
334
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
335
+				'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>"),
336
+				'connect_button'    => __("Connect Site", "invoicing"),
337
+				'connecting_button'    => __("Connecting...", "invoicing"),
338
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
339
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
340 340
             ),
341
-            array( 'wpi-addons' )
341
+            array('wpi-addons')
342 342
         );
343 343
 
344 344
     }
@@ -350,20 +350,20 @@  discard block
 block discarded – undo
350 350
 	 */
351 351
 	public function activation_redirect() {
352 352
 
353
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
353
+		$redirected = get_option('wpinv_redirected_to_settings');
354 354
 
355
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
355
+		if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) {
356 356
 			return;
357 357
 		}
358 358
 
359 359
 		// Bail if activating from network, or bulk
360
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
360
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
361 361
 			return;
362 362
 		}
363 363
 
364
-	    update_option( 'wpinv_redirected_to_settings', 1 );
364
+	    update_option('wpinv_redirected_to_settings', 1);
365 365
 
366
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
366
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
367 367
         exit;
368 368
 
369 369
 	}
@@ -373,9 +373,9 @@  discard block
 block discarded – undo
373 373
      */
374 374
     public function maybe_do_admin_action() {
375 375
 
376
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
377
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
378
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
376
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
377
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
378
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
379 379
         }
380 380
 
381 381
     }
@@ -385,16 +385,16 @@  discard block
 block discarded – undo
385 385
 	 * 
386 386
 	 * @param array $args
387 387
      */
388
-    public function send_customer_invoice( $args ) {
389
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
388
+    public function send_customer_invoice($args) {
389
+		$sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']));
390 390
 
391
-		if ( $sent ) {
392
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
391
+		if ($sent) {
392
+			$this->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
393 393
 		} else {
394
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
394
+			$this->show_error(__('Could not sent the invoice to the customer', 'invoicing'));
395 395
 		}
396 396
 
397
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
397
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
398 398
 		exit;
399 399
 	}
400 400
 
@@ -403,16 +403,16 @@  discard block
 block discarded – undo
403 403
 	 * 
404 404
 	 * @param array $args
405 405
      */
406
-    public function send_customer_payment_reminder( $args ) {
407
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
406
+    public function send_customer_payment_reminder($args) {
407
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
408 408
 
409
-		if ( $sent ) {
410
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
409
+		if ($sent) {
410
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
411 411
 		} else {
412
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
412
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
413 413
 		}
414 414
 
415
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
415
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
416 416
 		exit;
417 417
 	}
418 418
 
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
      */
423 423
     public function admin_reset_tax_rates() {
424 424
 
425
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
426
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
425
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
426
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
427 427
 		exit;
428 428
 
429 429
 	}
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
     public function admin_create_missing_pages() {
436 436
 		$installer = new GetPaid_Installer();
437 437
 		$installer->create_pages();
438
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
439
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
438
+		$this->show_success(__('GetPaid pages updated.', 'invoicing'));
439
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
440 440
 		exit;
441 441
 	}
442 442
 
@@ -448,35 +448,35 @@  discard block
 block discarded – undo
448 448
 		global $wpdb;
449 449
 		$installer = new GetPaid_Installer();
450 450
 
451
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
451
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'") != $wpdb->prefix . 'wpinv_subscriptions') {
452 452
 			$installer->create_subscriptions_table();
453 453
 
454
-			if ( $wpdb->last_error !== '' ) {
455
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
454
+			if ($wpdb->last_error !== '') {
455
+				$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
456 456
 			}
457 457
 		}
458 458
 
459
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
459
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") != $wpdb->prefix . 'getpaid_invoices') {
460 460
 			$installer->create_invoices_table();
461 461
 
462
-			if ( $wpdb->last_error !== '' ) {
463
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
462
+			if ($wpdb->last_error !== '') {
463
+				$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
464 464
 			}
465 465
 		}
466 466
 
467
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
467
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'") != $wpdb->prefix . 'getpaid_invoice_items') {
468 468
 			$installer->create_invoice_items_table();
469 469
 
470
-			if ( $wpdb->last_error !== '' ) {
471
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
470
+			if ($wpdb->last_error !== '') {
471
+				$this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error);
472 472
 			}
473 473
 		}
474 474
 
475
-		if ( ! $this->has_notices() ) {
476
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
475
+		if (!$this->has_notices()) {
476
+			$this->show_success(__('Your GetPaid tables have been updated.', 'invoicing'));
477 477
 		}
478 478
 
479
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
479
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
480 480
 		exit;
481 481
 	}
482 482
 
@@ -491,10 +491,10 @@  discard block
 block discarded – undo
491 491
 		$installer->migrate_old_invoices();
492 492
 
493 493
 		// Show an admin message.
494
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
494
+		$this->show_success(__('Your invoices have been migrated.', 'invoicing'));
495 495
 
496 496
 		// Redirect the admin.
497
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
497
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
498 498
 		exit;
499 499
 
500 500
 	}
@@ -508,36 +508,36 @@  discard block
 block discarded – undo
508 508
 
509 509
 		// Fetch all invoices that have discount codes.
510 510
 		$table    = $wpdb->prefix . 'getpaid_invoices';
511
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
511
+		$invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''");
512 512
 
513
-		foreach ( $invoices as $invoice ) {
513
+		foreach ($invoices as $invoice) {
514 514
 
515
-			$invoice = new WPInv_Invoice( $invoice );
515
+			$invoice = new WPInv_Invoice($invoice);
516 516
 
517
-			if ( ! $invoice->exists() ) {
517
+			if (!$invoice->exists()) {
518 518
 				continue;
519 519
 			}
520 520
 
521 521
 			// Abort if the discount does not exist or does not apply here.
522
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
523
-			if ( ! $discount->exists() ) {
522
+			$discount = new WPInv_Discount($invoice->get_discount_code());
523
+			if (!$discount->exists()) {
524 524
 				continue;
525 525
 			}
526 526
 
527
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
527
+			$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
528 528
 			$invoice->recalculate_total();
529 529
 
530
-			if ( $invoice->get_total_discount() > 0 ) {
530
+			if ($invoice->get_total_discount() > 0) {
531 531
 				$invoice->save();
532 532
 			}
533 533
 
534 534
 		}
535 535
 
536 536
 		// Show an admin message.
537
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
537
+		$this->show_success(__('Discounts have been recalculated.', 'invoicing'));
538 538
 
539 539
 		// Redirect the admin.
540
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
540
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
541 541
 		exit;
542 542
 
543 543
 	}
@@ -549,8 +549,8 @@  discard block
 block discarded – undo
549 549
      * @return array
550 550
 	 */
551 551
 	public function get_notices() {
552
-		$notices = get_option( 'wpinv_admin_notices' );
553
-        return is_array( $notices ) ? $notices : array();
552
+		$notices = get_option('wpinv_admin_notices');
553
+        return is_array($notices) ? $notices : array();
554 554
 	}
555 555
 
556 556
 	/**
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
      * @return array
561 561
 	 */
562 562
 	public function has_notices() {
563
-		return count( $this->get_notices() ) > 0;
563
+		return count($this->get_notices()) > 0;
564 564
 	}
565 565
 
566 566
 	/**
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 	 * @since       1.0.19
571 571
 	 */
572 572
 	public function clear_notices() {
573
-		delete_option( 'wpinv_admin_notices' );
573
+		delete_option('wpinv_admin_notices');
574 574
 	}
575 575
 
576 576
 	/**
@@ -579,16 +579,16 @@  discard block
 block discarded – undo
579 579
 	 * @access      public
580 580
 	 * @since       1.0.19
581 581
 	 */
582
-	public function save_notice( $type, $message ) {
582
+	public function save_notice($type, $message) {
583 583
 		$notices = $this->get_notices();
584 584
 
585
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
586
-			$notices[ $type ] = array();
585
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
586
+			$notices[$type] = array();
587 587
 		}
588 588
 
589
-		$notices[ $type ][] = $message;
589
+		$notices[$type][] = $message;
590 590
 
591
-		update_option( 'wpinv_admin_notices', $notices );
591
+		update_option('wpinv_admin_notices', $notices);
592 592
 	}
593 593
 
594 594
 	/**
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
 	 * @access      public
599 599
 	 * @since       1.0.19
600 600
 	 */
601
-	public function show_success( $msg ) {
602
-		$this->save_notice( 'success', $msg );
601
+	public function show_success($msg) {
602
+		$this->save_notice('success', $msg);
603 603
 	}
604 604
 
605 605
 	/**
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
 	 * @param       string $msg The message to qeue.
610 610
 	 * @since       1.0.19
611 611
 	 */
612
-	public function show_error( $msg ) {
613
-		$this->save_notice( 'error', $msg );
612
+	public function show_error($msg) {
613
+		$this->save_notice('error', $msg);
614 614
 	}
615 615
 
616 616
 	/**
@@ -620,8 +620,8 @@  discard block
 block discarded – undo
620 620
 	 * @param       string $msg The message to qeue.
621 621
 	 * @since       1.0.19
622 622
 	 */
623
-	public function show_warning( $msg ) {
624
-		$this->save_notice( 'warning', $msg );
623
+	public function show_warning($msg) {
624
+		$this->save_notice('warning', $msg);
625 625
 	}
626 626
 
627 627
 	/**
@@ -631,8 +631,8 @@  discard block
 block discarded – undo
631 631
 	 * @param       string $msg The message to qeue.
632 632
 	 * @since       1.0.19
633 633
 	 */
634
-	public function show_info( $msg ) {
635
-		$this->save_notice( 'info', $msg );
634
+	public function show_info($msg) {
635
+		$this->save_notice('info', $msg);
636 636
 	}
637 637
 
638 638
 	/**
@@ -646,32 +646,32 @@  discard block
 block discarded – undo
646 646
         $notices = $this->get_notices();
647 647
         $this->clear_notices();
648 648
 
649
-		foreach ( $notices as $type => $messages ) {
649
+		foreach ($notices as $type => $messages) {
650 650
 
651
-			if ( ! is_array( $messages ) ) {
651
+			if (!is_array($messages)) {
652 652
 				continue;
653 653
 			}
654 654
 
655
-            $type  = sanitize_key( $type );
656
-			foreach ( $messages as $message ) {
657
-                $message = wp_kses_post( $message );
655
+            $type = sanitize_key($type);
656
+			foreach ($messages as $message) {
657
+                $message = wp_kses_post($message);
658 658
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
659 659
             }
660 660
 
661 661
         }
662 662
 
663
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
663
+		foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) {
664 664
 
665
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
666
-				$url     = esc_url(
665
+			if (!is_numeric(wpinv_get_option($page, false))) {
666
+				$url = esc_url(
667 667
 					wp_nonce_url(
668
-						add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
668
+						add_query_arg('getpaid-admin-action', 'create_missing_pages'),
669 669
 						'getpaid-nonce',
670 670
 						'getpaid-nonce'
671 671
 					)
672 672
 				);
673
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
674
-				$message2 = __( 'Generate Pages', 'invoicing' );
673
+				$message  = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing');
674
+				$message2 = __('Generate Pages', 'invoicing');
675 675
 				echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
676 676
 				break;
677 677
 			}
Please login to merge, or discard this patch.