Passed
Push — master ( 5bb76a...9b8253 )
by Brian
09:28 queued 05:23
created
includes/admin/class-getpaid-admin.php 1 patch
Spacing   +130 added lines, -130 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.
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
     /**
31 31
 	 * Class constructor.
32 32
 	 */
33
-	public function __construct(){
33
+	public function __construct() {
34 34
 
35
-        $this->admin_path  = plugin_dir_path( __FILE__ );
36
-        $this->admin_url   = plugins_url( '/', __FILE__ );
35
+        $this->admin_path  = plugin_dir_path(__FILE__);
36
+        $this->admin_url   = plugins_url('/', __FILE__);
37 37
 
38
-        if ( is_admin() ) {
38
+        if (is_admin()) {
39 39
 			$this->init_admin_hooks();
40 40
         }
41 41
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 */
48 48
 	private function init_admin_hooks() {
49
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52
-        add_action( 'admin_init', array( $this, 'activation_redirect') );
53
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
49
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));
50
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
51
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
52
+        add_action('admin_init', array($this, 'activation_redirect'));
53
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
54
+		add_action('admin_notices', array($this, 'show_notices'));
55
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
56
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
57
+		do_action('getpaid_init_admin_hooks', $this);
58 58
 
59 59
     }
60 60
 
@@ -65,49 +65,49 @@  discard block
 block discarded – undo
65 65
 	public function enqeue_scripts() {
66 66
         global $current_screen, $pagenow;
67 67
 
68
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
68
+		$page    = isset($_GET['page']) ? $_GET['page'] : '';
69 69
 		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
70 70
 
71
-        if ( ! empty( $current_screen->post_type ) ) {
71
+        if (!empty($current_screen->post_type)) {
72 72
 			$page = $current_screen->post_type;
73 73
         }
74 74
 
75 75
         // General styles.
76
-        if ( false !== stripos( $page, 'wpi' ) ) {
76
+        if (false !== stripos($page, 'wpi')) {
77 77
 
78 78
             // Styles.
79
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
80
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
81
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
82
-            wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
83
-            wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' );
79
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
80
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
81
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
82
+            wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
83
+            wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16');
84 84
 
85 85
             // Scripts.
86
-            wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true );
87
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
86
+            wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true);
87
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
88 88
 
89
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
90
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ),  $version );
91
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
89
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
90
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version);
91
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
92 92
 
93 93
         }
94 94
 
95 95
         // Payment form scripts.
96
-		if ( 'wpi_payment_form' == $page && $editing ) {
96
+		if ('wpi_payment_form' == $page && $editing) {
97 97
             $this->load_payment_form_scripts();
98 98
         }
99 99
 
100
-        if ( $page == 'wpinv-subscriptions' ) {
101
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
102
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
100
+        if ($page == 'wpinv-subscriptions') {
101
+			wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
102
+			wp_enqueue_script('wpinv-sub-admin-script');
103 103
 		}
104 104
 
105
-		if ( $page == 'wpinv-reports' ) {
106
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
105
+		if ($page == 'wpinv-reports') {
106
+			wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7');
107 107
 		}
108 108
 
109
-		if ( $page == 'wpinv-subscriptions' ) {
110
-			wp_enqueue_script( 'postbox' );
109
+		if ($page == 'wpinv-subscriptions') {
110
+			wp_enqueue_script('postbox');
111 111
 		}
112 112
 
113 113
     }
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
         global $post;
121 121
 
122 122
         $i18n = array(
123
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
124
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
125
-            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
126
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
127
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
128
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
129
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
123
+            'ajax_url'                  => admin_url('admin-ajax.php'),
124
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
125
+            'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
126
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
127
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
128
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
129
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
130 130
             'tax'                       => wpinv_tax_amount(),
131 131
             'discount'                  => wpinv_discount_amount(),
132 132
             'currency_symbol'           => wpinv_currency_symbol(),
@@ -134,35 +134,35 @@  discard block
 block discarded – undo
134 134
             'thousand_sep'              => wpinv_thousands_separator(),
135 135
             'decimal_sep'               => wpinv_decimal_separator(),
136 136
             'decimals'                  => wpinv_decimals(),
137
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
138
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
139
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
140
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
141
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
142
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
143
-            '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' ),
144
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
145
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
146
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
147
-            'action_edit'               => __( 'Edit', 'invoicing' ),
148
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
149
-            'item_description'          => __( 'Item Description', 'invoicing' ),
150
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
151
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
152
-            'searching'                 => __( 'Searching', 'invoicing' ),
137
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
138
+            'status_publish'            => wpinv_status_nicename('publish'),
139
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
140
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
141
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
142
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
143
+            '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'),
144
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
145
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
146
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
147
+            'action_edit'               => __('Edit', 'invoicing'),
148
+            'action_cancel'             => __('Cancel', 'invoicing'),
149
+            'item_description'          => __('Item Description', 'invoicing'),
150
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
151
+            'discount_description'      => __('Discount Description', 'invoicing'),
152
+            'searching'                 => __('Searching', 'invoicing'),
153 153
         );
154 154
 
155
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
155
+		if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) {
156 156
 
157
-			$invoice              = new WPInv_Invoice( $post );
157
+			$invoice              = new WPInv_Invoice($post);
158 158
 			$i18n['save_invoice'] = sprintf(
159
-				__( 'Save %s', 'invoicing' ),
160
-				ucfirst( $invoice->get_type() )
159
+				__('Save %s', 'invoicing'),
160
+				ucfirst($invoice->get_type())
161 161
 			);
162 162
 
163 163
 			$i18n['invoice_description'] = sprintf(
164
-				__( '%s Description', 'invoicing' ),
165
-				ucfirst( $invoice->get_type() )
164
+				__('%s Description', 'invoicing'),
165
+				ucfirst($invoice->get_type())
166 166
 			);
167 167
 
168 168
 		}
@@ -176,30 +176,30 @@  discard block
 block discarded – undo
176 176
 	protected function load_payment_form_scripts() {
177 177
         global $post;
178 178
 
179
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
180
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
181
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
179
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
180
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
181
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
182 182
 
183
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
184
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
183
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
184
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
185 185
 
186 186
 		wp_localize_script(
187 187
             'wpinv-admin-payment-form-script',
188 188
             'wpinvPaymentFormAdmin',
189 189
             array(
190
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
191
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
190
+				'elements'      => wpinv_get_data('payment-form-elements'),
191
+				'form_elements' => getpaid_get_payment_form_elements($post->ID),
192 192
 				'currency'      => wpinv_currency_symbol(),
193 193
 				'position'      => wpinv_currency_position(),
194 194
 				'decimals'      => (int) wpinv_decimals(),
195 195
 				'thousands_sep' => wpinv_thousands_separator(),
196 196
 				'decimals_sep'  => wpinv_decimal_separator(),
197
-				'form_items'    => gepaid_get_form_items( $post->ID ),
197
+				'form_items'    => gepaid_get_form_items($post->ID),
198 198
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
199 199
             )
200 200
         );
201 201
 
202
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
202
+        wp_enqueue_script('wpinv-admin-payment-form-script');
203 203
 
204 204
     }
205 205
 
@@ -210,29 +210,29 @@  discard block
 block discarded – undo
210 210
      * @return string
211 211
 	 *
212 212
 	 */
213
-    public function admin_body_class( $classes ) {
213
+    public function admin_body_class($classes) {
214 214
 		global $pagenow, $post, $current_screen;
215 215
 
216 216
 
217
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
217
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
218 218
 
219
-        if ( ! empty( $current_screen->post_type ) ) {
219
+        if (!empty($current_screen->post_type)) {
220 220
 			$page = $current_screen->post_type;
221 221
         }
222 222
 
223
-        if ( false !== stripos( $page, 'wpi' ) ) {
224
-            $classes .= ' wpi-' . sanitize_key( $page );
223
+        if (false !== stripos($page, 'wpi')) {
224
+            $classes .= ' wpi-' . sanitize_key($page);
225 225
         }
226 226
 
227
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
227
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
228 228
             $classes .= ' wpinv-cpt wpinv';
229 229
 		}
230 230
 		
231
-		if ( getpaid_is_invoice_post_type( $page ) ) {
231
+		if (getpaid_is_invoice_post_type($page)) {
232 232
             $classes .= ' getpaid-is-invoice-cpt';
233 233
         }
234 234
 
235
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
235
+		if ($pagenow == 'post.php' && $page == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
236 236
 			$classes .= ' wpi-editable-n';
237 237
 		}
238 238
 
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
     /**
243 243
 	 * Maybe show the AyeCode Connect Notice.
244 244
 	 */
245
-	public function init_ayecode_connect_helper(){
245
+	public function init_ayecode_connect_helper() {
246 246
 
247 247
         new AyeCode_Connect_Helper(
248 248
             array(
249
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
250
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
251
-				'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>" ),
252
-				'connect_button'    => __("Connect Site","invoicing"),
253
-				'connecting_button'    => __("Connecting...","invoicing"),
254
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
255
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
249
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
250
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
251
+				'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>"),
252
+				'connect_button'    => __("Connect Site", "invoicing"),
253
+				'connecting_button'    => __("Connecting...", "invoicing"),
254
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
255
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
256 256
             ),
257
-            array( 'wpi-addons' )
257
+            array('wpi-addons')
258 258
         );
259 259
 
260 260
     }
@@ -265,19 +265,19 @@  discard block
 block discarded – undo
265 265
     public function activation_redirect() {
266 266
 
267 267
 		// Bail if no activation redirect.
268
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
268
+		if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) {
269 269
 			return;
270 270
 		}
271 271
 
272 272
 		// Delete the redirect transient.
273
-		delete_transient( '_wpinv_activation_redirect' );
273
+		delete_transient('_wpinv_activation_redirect');
274 274
 
275 275
 		// Bail if activating from network, or bulk
276
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
276
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
277 277
 			return;
278 278
 		}
279 279
 
280
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
280
+		wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
281 281
 		exit;
282 282
     }
283 283
 
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
      */
287 287
     public function maybe_do_admin_action() {
288 288
 
289
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
290
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
291
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
289
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
290
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
291
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
292 292
         }
293 293
 
294 294
     }
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
 	 * 
299 299
 	 * @param array $args
300 300
      */
301
-    public function send_customer_invoice( $args ) {
302
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
301
+    public function send_customer_invoice($args) {
302
+		$sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']));
303 303
 
304
-		if ( $sent ) {
305
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
304
+		if ($sent) {
305
+			$this->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
306 306
 		} else {
307
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
307
+			$this->show_error(__('Could not sent the invoice to the customer', 'invoicing'));
308 308
 		}
309 309
 
310
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
310
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
311 311
 		exit;
312 312
 	}
313 313
 
@@ -316,16 +316,16 @@  discard block
 block discarded – undo
316 316
 	 * 
317 317
 	 * @param array $args
318 318
      */
319
-    public function send_customer_payment_reminder( $args ) {
320
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
319
+    public function send_customer_payment_reminder($args) {
320
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
321 321
 
322
-		if ( $sent ) {
323
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
322
+		if ($sent) {
323
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
324 324
 		} else {
325
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
325
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
326 326
 		}
327 327
 
328
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
328
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
329 329
 		exit;
330 330
 	}
331 331
 
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
      * @return array
337 337
 	 */
338 338
 	public function get_notices() {
339
-		$notices = get_option( 'wpinv_admin_notices' );
340
-        return is_array( $notices ) ? $notices : array();
339
+		$notices = get_option('wpinv_admin_notices');
340
+        return is_array($notices) ? $notices : array();
341 341
 	}
342 342
 
343 343
 	/**
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 	 * @since       1.0.19
348 348
 	 */
349 349
 	public function clear_notices() {
350
-		delete_option( 'wpinv_admin_notices' );
350
+		delete_option('wpinv_admin_notices');
351 351
 	}
352 352
 
353 353
 	/**
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
 	 * @access      public
357 357
 	 * @since       1.0.19
358 358
 	 */
359
-	public function save_notice( $type, $message ) {
359
+	public function save_notice($type, $message) {
360 360
 		$notices = $this->get_notices();
361 361
 
362
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
363
-			$notices[ $type ] = array();
362
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
363
+			$notices[$type] = array();
364 364
 		}
365 365
 
366
-		$notices[ $type ][] = $message;
366
+		$notices[$type][] = $message;
367 367
 
368
-		update_option( 'wpinv_admin_notices', $notices );
368
+		update_option('wpinv_admin_notices', $notices);
369 369
 	}
370 370
 
371 371
 	/**
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * @access      public
376 376
 	 * @since       1.0.19
377 377
 	 */
378
-	public function show_success( $msg ) {
379
-		$this->save_notice( 'success', $msg );
378
+	public function show_success($msg) {
379
+		$this->save_notice('success', $msg);
380 380
 	}
381 381
 
382 382
 	/**
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 	 * @param       string $msg The message to qeue.
387 387
 	 * @since       1.0.19
388 388
 	 */
389
-	public function show_error( $msg ) {
390
-		$this->save_notice( 'error', $msg );
389
+	public function show_error($msg) {
390
+		$this->save_notice('error', $msg);
391 391
 	}
392 392
 
393 393
 	/**
@@ -397,8 +397,8 @@  discard block
 block discarded – undo
397 397
 	 * @param       string $msg The message to qeue.
398 398
 	 * @since       1.0.19
399 399
 	 */
400
-	public function show_warning( $msg ) {
401
-		$this->save_notice( 'warning', $msg );
400
+	public function show_warning($msg) {
401
+		$this->save_notice('warning', $msg);
402 402
 	}
403 403
 
404 404
 	/**
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 	 * @param       string $msg The message to qeue.
409 409
 	 * @since       1.0.19
410 410
 	 */
411
-	public function show_info( $msg ) {
412
-		$this->save_notice( 'info', $msg );
411
+	public function show_info($msg) {
412
+		$this->save_notice('info', $msg);
413 413
 	}
414 414
 
415 415
 	/**
@@ -423,15 +423,15 @@  discard block
 block discarded – undo
423 423
         $notices = $this->get_notices();
424 424
         $this->clear_notices();
425 425
 
426
-		foreach ( $notices as $type => $messages ) {
426
+		foreach ($notices as $type => $messages) {
427 427
 
428
-			if ( ! is_array( $messages ) ) {
428
+			if (!is_array($messages)) {
429 429
 				continue;
430 430
 			}
431 431
 
432
-            $type  = sanitize_key( $type );
433
-			foreach ( $messages as $message ) {
434
-                $message = wp_kses_post( $message );
432
+            $type = sanitize_key($type);
433
+			foreach ($messages as $message) {
434
+                $message = wp_kses_post($message);
435 435
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
436 436
             }
437 437
 
Please login to merge, or discard this patch.
includes/admin/class-wpinv-admin-menus.php 1 patch
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Setup menus in WP admin.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * WC_Admin_Menus Class.
@@ -13,25 +13,25 @@  discard block
 block discarded – undo
13 13
      * Hook in tabs.
14 14
      */
15 15
     public function __construct() {
16
-        add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 );
17
-        add_action( 'admin_menu', array( $this, 'add_customers_menu' ), 18 );
18
-        add_action( 'admin_menu', array( $this, 'add_subscriptions_menu' ), 40 );
19
-        add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 );
20
-        add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 );
21
-        add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 );
22
-        add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
16
+        add_action('admin_menu', array($this, 'admin_menu'), 10);
17
+        add_action('admin_menu', array($this, 'add_customers_menu'), 18);
18
+        add_action('admin_menu', array($this, 'add_subscriptions_menu'), 40);
19
+        add_action('admin_menu', array($this, 'add_addons_menu'), 100);
20
+        add_action('admin_menu', array($this, 'add_settings_menu'), 60);
21
+        add_action('admin_menu', array($this, 'remove_admin_submenus'), 10);
22
+        add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes'));
23 23
     }
24 24
 
25 25
     public function admin_menu() {
26 26
 
27
-        $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() );
27
+        $capability = apply_filters('invoicing_capability', wpinv_get_capability());
28 28
         add_menu_page(
29
-            __( 'GetPaid', 'invoicing' ),
30
-            __( 'GetPaid', 'invoicing' ),
29
+            __('GetPaid', 'invoicing'),
30
+            __('GetPaid', 'invoicing'),
31 31
             $capability,
32 32
             'wpinv',
33 33
             null,
34
-            'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg' ) ),
34
+            'data:image/svg+xml;base64,' . base64_encode(file_get_contents(WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg')),
35 35
             '54.123460'
36 36
         );
37 37
 
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
     public function add_customers_menu() {
44 44
         add_submenu_page(
45 45
             'wpinv',
46
-            __( 'Customers', 'invoicing' ),
47
-            __( 'Customers', 'invoicing' ),
46
+            __('Customers', 'invoicing'),
47
+            __('Customers', 'invoicing'),
48 48
             wpinv_get_capability(),
49 49
             'wpinv-customers',
50
-            array( $this, 'customers_page' )
50
+            array($this, 'customers_page')
51 51
         );
52 52
     }
53 53
 
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
     public function add_subscriptions_menu() {
58 58
         add_submenu_page(
59 59
             'wpinv',
60
-            __( 'Subscriptions', 'invoicing' ),
61
-            __( 'Subscriptions', 'invoicing' ),
60
+            __('Subscriptions', 'invoicing'),
61
+            __('Subscriptions', 'invoicing'),
62 62
             wpinv_get_capability(),
63 63
             'wpinv-subscriptions',
64 64
             'wpinv_subscriptions_page'
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      * Displays the customers page.
70 70
      */
71 71
     public function customers_page() {
72
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php' );
72
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php');
73 73
         ?>
74 74
         <div class="wrap wpi-customers-wrap">
75 75
             <style>
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
                     width: 30%;
78 78
                 }
79 79
             </style>
80
-            <h1><?php echo esc_html( __( 'Customers', 'invoicing' ) ); ?></h1>
80
+            <h1><?php echo esc_html(__('Customers', 'invoicing')); ?></h1>
81 81
             <?php
82 82
                 $table = new WPInv_Customers_Table();
83 83
                 $table->prepare_items();
@@ -93,16 +93,16 @@  discard block
 block discarded – undo
93 93
     public function add_settings_menu() {
94 94
         add_submenu_page(
95 95
             'wpinv',
96
-            __( 'Invoice Settings', 'invoicing' ),
97
-            __( 'Settings', 'invoicing' ),
98
-            apply_filters( 'invoicing_capability', wpinv_get_capability() ),
96
+            __('Invoice Settings', 'invoicing'),
97
+            __('Settings', 'invoicing'),
98
+            apply_filters('invoicing_capability', wpinv_get_capability()),
99 99
             'wpinv-settings',
100
-            array( $this, 'options_page' )
100
+            array($this, 'options_page')
101 101
         );
102 102
     }
103 103
 
104
-    public function add_addons_menu(){
105
-        if ( !apply_filters( 'wpi_show_addons_page', true ) ) {
104
+    public function add_addons_menu() {
105
+        if (!apply_filters('wpi_show_addons_page', true)) {
106 106
             return;
107 107
         }
108 108
 
@@ -112,78 +112,78 @@  discard block
 block discarded – undo
112 112
             __('Extensions', 'invoicing'),
113 113
             'manage_options',
114 114
             'wpi-addons',
115
-            array( $this, 'addons_page' )
115
+            array($this, 'addons_page')
116 116
         );
117 117
     }
118 118
 
119
-    public function addons_page(){
119
+    public function addons_page() {
120 120
         $addon_obj = new WPInv_Admin_Addons();
121 121
         $addon_obj->output();
122 122
     }
123 123
 
124 124
     function options_page() {
125
-        $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
125
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
126 126
 
127
-        if ( $page !== 'wpinv-settings' ) {
127
+        if ($page !== 'wpinv-settings') {
128 128
             return;
129 129
         }
130 130
 
131 131
         $settings_tabs = wpinv_get_settings_tabs();
132 132
         $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
133
-        $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
134
-        $sections      = wpinv_get_settings_tab_sections( $active_tab );
133
+        $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
134
+        $sections      = wpinv_get_settings_tab_sections($active_tab);
135 135
         $key           = 'main';
136 136
 
137
-        if ( is_array( $sections ) ) {
138
-            $key = key( $sections );
137
+        if (is_array($sections)) {
138
+            $key = key($sections);
139 139
         }
140 140
 
141
-        $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
142
-        $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
141
+        $registered_sections = wpinv_get_settings_tab_sections($active_tab);
142
+        $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
143 143
         ob_start();
144 144
         ?>
145 145
         <div class="wrap">
146 146
             <h1 class="nav-tab-wrapper">
147 147
                 <?php
148
-                foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
149
-                    $tab_url = add_query_arg( array(
148
+                foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
149
+                    $tab_url = add_query_arg(array(
150 150
                         'settings-updated' => false,
151 151
                         'tab' => $tab_id,
152
-                    ) );
152
+                    ));
153 153
 
154 154
                     // Remove the section from the tabs so we always end up at the main section
155
-                    $tab_url = remove_query_arg( 'section', $tab_url );
156
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
155
+                    $tab_url = remove_query_arg('section', $tab_url);
156
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
157 157
 
158 158
                     $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
159 159
 
160
-                    echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
161
-                    echo esc_html( $tab_name );
160
+                    echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
161
+                    echo esc_html($tab_name);
162 162
                     echo '</a>';
163 163
                 }
164 164
                 ?>
165 165
             </h1>
166 166
             <?php
167
-            $number_of_sections = count( $sections );
167
+            $number_of_sections = count($sections);
168 168
             $number = 0;
169
-            if ( $number_of_sections > 1 ) {
169
+            if ($number_of_sections > 1) {
170 170
                 echo '<div><ul class="subsubsub">';
171
-                foreach( $sections as $section_id => $section_name ) {
171
+                foreach ($sections as $section_id => $section_name) {
172 172
                     echo '<li>';
173 173
                     $number++;
174
-                    $tab_url = add_query_arg( array(
174
+                    $tab_url = add_query_arg(array(
175 175
                         'settings-updated' => false,
176 176
                         'tab' => $active_tab,
177 177
                         'section' => $section_id
178
-                    ) );
179
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
178
+                    ));
179
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
180 180
                     $class = '';
181
-                    if ( $section == $section_id ) {
181
+                    if ($section == $section_id) {
182 182
                         $class = 'current';
183 183
                     }
184
-                    echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
184
+                    echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
185 185
 
186
-                    if ( $number != $number_of_sections ) {
186
+                    if ($number != $number_of_sections) {
187 187
                         echo ' | ';
188 188
                     }
189 189
                     echo '</li>';
@@ -195,20 +195,20 @@  discard block
 block discarded – undo
195 195
                 <form method="post" action="options.php">
196 196
                     <table class="form-table">
197 197
                         <?php
198
-                        settings_fields( 'wpinv_settings' );
198
+                        settings_fields('wpinv_settings');
199 199
 
200
-                        if ( 'main' === $section ) {
201
-                            do_action( 'wpinv_settings_tab_top', $active_tab );
200
+                        if ('main' === $section) {
201
+                            do_action('wpinv_settings_tab_top', $active_tab);
202 202
                         }
203 203
 
204
-                        do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section );
205
-                        do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section );
206
-                        do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section );
207
-                        do_action( 'getpaid_settings_tab_bottom', $active_tab, $section );
204
+                        do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section);
205
+                        do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section);
206
+                        do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section);
207
+                        do_action('getpaid_settings_tab_bottom', $active_tab, $section);
208 208
 
209 209
                         // For backwards compatibility
210
-                        if ( 'main' === $section ) {
211
-                            do_action( 'wpinv_settings_tab_bottom', $active_tab );
210
+                        if ('main' === $section) {
211
+                            do_action('wpinv_settings_tab_bottom', $active_tab);
212 212
                         }
213 213
                         ?>
214 214
                     </table>
@@ -222,18 +222,18 @@  discard block
 block discarded – undo
222 222
     }
223 223
 
224 224
     public function remove_admin_submenus() {
225
-        remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
225
+        remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
226 226
     }
227 227
 
228
-    public function add_nav_menu_meta_boxes(){
229
-        add_meta_box( 'wpinv_endpoints_nav_link', __( 'Invoicing Pages', 'invoicing' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' );
228
+    public function add_nav_menu_meta_boxes() {
229
+        add_meta_box('wpinv_endpoints_nav_link', __('Invoicing Pages', 'invoicing'), array($this, 'nav_menu_links'), 'nav-menus', 'side', 'low');
230 230
     }
231 231
 
232
-    public function nav_menu_links(){
232
+    public function nav_menu_links() {
233 233
         $endpoints = $this->get_menu_items();
234 234
         ?>
235 235
         <div id="invoicing-endpoints" class="posttypediv">
236
-        <?php if(!empty($endpoints['pages'])){ ?>
236
+        <?php if (!empty($endpoints['pages'])) { ?>
237 237
             <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active">
238 238
                 <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear">
239 239
                     <?php
@@ -245,29 +245,29 @@  discard block
 block discarded – undo
245 245
         <?php } ?>
246 246
         <p class="button-controls">
247 247
         <span class="list-controls">
248
-            <a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints' ); ?>" class="select-all"><?php _e( 'Select all', 'invoicing' ); ?></a>
248
+            <a href="<?php echo admin_url('nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints'); ?>" class="select-all"><?php _e('Select all', 'invoicing'); ?></a>
249 249
         </span>
250 250
             <span class="add-to-menu">
251
-            <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints">
251
+            <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints">
252 252
             <span class="spinner"></span>
253 253
         </span>
254 254
         </p>
255 255
         <?php
256 256
     }
257 257
 
258
-    public function get_menu_items(){
258
+    public function get_menu_items() {
259 259
         $items = array();
260 260
 
261
-        $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' );
262
-        if($wpinv_history_page_id > 0){
261
+        $wpinv_history_page_id = (int) wpinv_get_option('invoice_history_page');
262
+        if ($wpinv_history_page_id > 0) {
263 263
             $item = new stdClass();
264 264
             $item->object_id = $wpinv_history_page_id;
265 265
             $item->db_id = 0;
266
-            $item->object =  'page';
266
+            $item->object = 'page';
267 267
             $item->menu_item_parent = 0;
268 268
             $item->type = 'post_type';
269
-            $item->title = __('Invoice History Page','invoicing');
270
-            $item->url = get_permalink( $wpinv_history_page_id );
269
+            $item->title = __('Invoice History Page', 'invoicing');
270
+            $item->url = get_permalink($wpinv_history_page_id);
271 271
             $item->target = '';
272 272
             $item->attr_title = '';
273 273
             $item->classes = array('wpinv-menu-item');
@@ -276,16 +276,16 @@  discard block
 block discarded – undo
276 276
             $items['pages'][] = $item;
277 277
         }
278 278
 
279
-        $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' );
280
-        if($wpinv_sub_history_page_id > 0){
279
+        $wpinv_sub_history_page_id = (int) wpinv_get_option('invoice_subscription_page');
280
+        if ($wpinv_sub_history_page_id > 0) {
281 281
             $item = new stdClass();
282 282
             $item->object_id = $wpinv_sub_history_page_id;
283 283
             $item->db_id = 0;
284
-            $item->object =  'page';
284
+            $item->object = 'page';
285 285
             $item->menu_item_parent = 0;
286 286
             $item->type = 'post_type';
287
-            $item->title = __('Invoice Subscriptions Page','invoicing');
288
-            $item->url = get_permalink( $wpinv_sub_history_page_id );
287
+            $item->title = __('Invoice Subscriptions Page', 'invoicing');
288
+            $item->url = get_permalink($wpinv_sub_history_page_id);
289 289
             $item->target = '';
290 290
             $item->attr_title = '';
291 291
             $item->classes = array('wpinv-menu-item');
@@ -294,16 +294,16 @@  discard block
 block discarded – undo
294 294
             $items['pages'][] = $item;
295 295
         }
296 296
 
297
-        $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' );
298
-        if($wpinv_checkout_page_id > 0){
297
+        $wpinv_checkout_page_id = (int) wpinv_get_option('checkout_page');
298
+        if ($wpinv_checkout_page_id > 0) {
299 299
             $item = new stdClass();
300 300
             $item->object_id = $wpinv_checkout_page_id;
301 301
             $item->db_id = 0;
302
-            $item->object =  'page';
302
+            $item->object = 'page';
303 303
             $item->menu_item_parent = 0;
304 304
             $item->type = 'post_type';
305
-            $item->title = __('Checkout Page','invoicing');
306
-            $item->url = get_permalink( $wpinv_checkout_page_id );
305
+            $item->title = __('Checkout Page', 'invoicing');
306
+            $item->url = get_permalink($wpinv_checkout_page_id);
307 307
             $item->target = '';
308 308
             $item->attr_title = '';
309 309
             $item->classes = array('wpinv-menu-item');
@@ -312,16 +312,16 @@  discard block
 block discarded – undo
312 312
             $items['pages'][] = $item;
313 313
         }
314 314
 
315
-        $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' );
316
-        if($wpinv_tandc_page_id > 0){
315
+        $wpinv_tandc_page_id = (int) wpinv_get_option('tandc_page');
316
+        if ($wpinv_tandc_page_id > 0) {
317 317
             $item = new stdClass();
318 318
             $item->object_id = $wpinv_tandc_page_id;
319 319
             $item->db_id = 0;
320
-            $item->object =  'page';
320
+            $item->object = 'page';
321 321
             $item->menu_item_parent = 0;
322 322
             $item->type = 'post_type';
323
-            $item->title = __('Terms & Conditions','invoicing');
324
-            $item->url = get_permalink( $wpinv_tandc_page_id );
323
+            $item->title = __('Terms & Conditions', 'invoicing');
324
+            $item->url = get_permalink($wpinv_tandc_page_id);
325 325
             $item->target = '';
326 326
             $item->attr_title = '';
327 327
             $item->classes = array('wpinv-menu-item');
@@ -330,16 +330,16 @@  discard block
 block discarded – undo
330 330
             $items['pages'][] = $item;
331 331
         }
332 332
 
333
-        $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' );
334
-        if($wpinv_success_page_id > 0){
333
+        $wpinv_success_page_id = (int) wpinv_get_option('success_page');
334
+        if ($wpinv_success_page_id > 0) {
335 335
             $item = new stdClass();
336 336
             $item->object_id = $wpinv_success_page_id;
337 337
             $item->db_id = 0;
338
-            $item->object =  'page';
338
+            $item->object = 'page';
339 339
             $item->menu_item_parent = 0;
340 340
             $item->type = 'post_type';
341
-            $item->title = __('Success Page','invoicing');
342
-            $item->url = get_permalink( $wpinv_success_page_id );
341
+            $item->title = __('Success Page', 'invoicing');
342
+            $item->url = get_permalink($wpinv_success_page_id);
343 343
             $item->target = '';
344 344
             $item->attr_title = '';
345 345
             $item->classes = array('wpinv-menu-item');
@@ -348,16 +348,16 @@  discard block
 block discarded – undo
348 348
             $items['pages'][] = $item;
349 349
         }
350 350
 
351
-        $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' );
352
-        if($wpinv_failure_page_id > 0){
351
+        $wpinv_failure_page_id = (int) wpinv_get_option('failure_page');
352
+        if ($wpinv_failure_page_id > 0) {
353 353
             $item = new stdClass();
354 354
             $item->object_id = $wpinv_failure_page_id;
355 355
             $item->db_id = 0;
356
-            $item->object =  'page';
356
+            $item->object = 'page';
357 357
             $item->menu_item_parent = 0;
358 358
             $item->type = 'post_type';
359
-            $item->title = __('Failed Transaction Page','invoicing');
360
-            $item->url = get_permalink( $wpinv_failure_page_id );
359
+            $item->title = __('Failed Transaction Page', 'invoicing');
360
+            $item->url = get_permalink($wpinv_failure_page_id);
361 361
             $item->target = '';
362 362
             $item->attr_title = '';
363 363
             $item->classes = array('wpinv-menu-item');
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
             $items['pages'][] = $item;
367 367
         }
368 368
 
369
-        return apply_filters( 'wpinv_menu_items', $items );
369
+        return apply_filters('wpinv_menu_items', $items);
370 370
     }
371 371
 
372 372
 }
Please login to merge, or discard this patch.
templates/invoice/invoice.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
         <?php
19 19
 
20 20
             // Fires when printing the header.
21
-            do_action( 'getpaid_invoice_header', $invoice );
21
+            do_action('getpaid_invoice_header', $invoice);
22 22
 
23 23
             // Print the opening wrapper.
24 24
             echo '<div class="container bg-white border mt-4 mb-4 p-4 position-relative flex-grow-1">';
25 25
 
26 26
             // Fires when printing the invoice details.
27
-            do_action( 'getpaid_invoice_details', $invoice );
27
+            do_action('getpaid_invoice_details', $invoice);
28 28
 
29 29
             // Fires when printing the invoice line items.
30
-            do_action( 'getpaid_invoice_line_items', $invoice );
30
+            do_action('getpaid_invoice_line_items', $invoice);
31 31
 
32 32
             // Print notifications.
33 33
             wpinv_print_errors();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
             echo '</div>';
37 37
 
38 38
             // Fires when printing the invoice footer.
39
-            do_action( 'getpaid_invoice_footer', $invoice );
39
+            do_action('getpaid_invoice_footer', $invoice);
40 40
 
41 41
         ?>
42 42
 
Please login to merge, or discard this patch.
templates/invoice/header-right-actions.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @var WPInv_Invoice $invoice
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 ?>
14 14
 
@@ -21,43 +21,43 @@  discard block
 block discarded – undo
21 21
             $actions[] = sprintf(
22 22
                 '<a href="javascript:void(0)" class="btn btn-sm btn-secondary invoice-action-print" onclick="window.print();">%s</a>',
23 23
                 sprintf(
24
-                    __( 'Print %s', 'invoicing' ),
25
-                    ucfirst( $invoice->get_type() )
24
+                    __('Print %s', 'invoicing'),
25
+                    ucfirst($invoice->get_type())
26 26
                 )
27 27
             );
28 28
 
29
-            if ( is_user_logged_in() ) {
29
+            if (is_user_logged_in()) {
30 30
 
31 31
                 $actions[] = sprintf(
32 32
                     '<a href="%s" class="btn btn-sm btn-secondary invoice-action-history">%s</a>',
33
-                    esc_url( wpinv_get_history_page_uri( $invoice->get_post_type() ) ),
33
+                    esc_url(wpinv_get_history_page_uri($invoice->get_post_type())),
34 34
                     sprintf(
35
-                        __( '%s History', 'invoicing' ),
36
-                        ucfirst( $invoice->get_type() )
35
+                        __('%s History', 'invoicing'),
36
+                        ucfirst($invoice->get_type())
37 37
                     )
38 38
                 );
39 39
 
40 40
             }
41 41
 
42
-            if ( wpinv_current_user_can_manage_invoicing() ) {
42
+            if (wpinv_current_user_can_manage_invoicing()) {
43 43
 
44 44
                 $actions[] = sprintf(
45 45
                     '<a href="%s" class="btn btn-sm btn-secondary invoice-action-edit">%s</a>',
46
-                    esc_url( get_edit_post_link( $invoice->get_id() ) ),
46
+                    esc_url(get_edit_post_link($invoice->get_id())),
47 47
                     sprintf(
48
-                        __( 'Edit %s', 'invoicing' ),
49
-                        ucfirst( $invoice->get_type() )
48
+                        __('Edit %s', 'invoicing'),
49
+                        ucfirst($invoice->get_type())
50 50
                     )
51 51
                 );
52 52
 
53 53
             }
54 54
 
55
-            $actions = apply_filters( 'getpaid_invoice_header_right_actions_array', $actions, $invoice );
56
-            echo implode( "&nbsp;&nbsp;", $actions );
55
+            $actions = apply_filters('getpaid_invoice_header_right_actions_array', $actions, $invoice);
56
+            echo implode("&nbsp;&nbsp;", $actions);
57 57
 
58 58
         ?>
59 59
 
60
-        <?php do_action('wpinv_invoice_display_right_actions', $invoice ); ?>
60
+        <?php do_action('wpinv_invoice_display_right_actions', $invoice); ?>
61 61
     </div>
62 62
 
63 63
 <?php
Please login to merge, or discard this patch.
templates/invoice/header-left-actions.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,19 +7,19 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14 14
         <div class="getpaid-header-left-actions">
15 15
 
16
-            <?php if ( $invoice->is_type( 'invoice' ) && $invoice->needs_payment() && ! $invoice->is_held() ): ?>
17
-                <a class="btn btn-sm btn-primary invoice-action-pay" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>">
18
-                    <?php _e( 'Pay For Invoice', 'invoicing' ); ?>
16
+            <?php if ($invoice->is_type('invoice') && $invoice->needs_payment() && !$invoice->is_held()): ?>
17
+                <a class="btn btn-sm btn-primary invoice-action-pay" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>">
18
+                    <?php _e('Pay For Invoice', 'invoicing'); ?>
19 19
                 </a>
20 20
             <?php endif; ?>
21 21
 
22
-            <?php do_action( 'wpinv_invoice_display_left_actions', $invoice ); ?>
22
+            <?php do_action('wpinv_invoice_display_left_actions', $invoice); ?>
23 23
 
24 24
         </div>
25 25
 
Please login to merge, or discard this patch.
includes/invoice-functions.php 1 patch
Spacing   +344 added lines, -344 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves the current invoice.
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 function getpaid_get_current_invoice_id() {
15 15
 
16 16
     // Ensure that we have an invoice key.
17
-    if ( empty( $_GET['invoice_key'] ) ) {
17
+    if (empty($_GET['invoice_key'])) {
18 18
         return 0;
19 19
     }
20 20
 
21 21
     // Retrieve an invoice using the key.
22
-    $invoice = new WPInv_Invoice( $_GET['invoice_key'] );
22
+    $invoice = new WPInv_Invoice($_GET['invoice_key']);
23 23
 
24 24
     // Compare the invoice key and the parsed key.
25
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) {
25
+    if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) {
26 26
         return $invoice->get_id();
27 27
     }
28 28
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Checks if the current user cna view an invoice.
34 34
  */
35
-function wpinv_user_can_view_invoice( $invoice ) {
36
-    $invoice = new WPInv_Invoice( $invoice );
35
+function wpinv_user_can_view_invoice($invoice) {
36
+    $invoice = new WPInv_Invoice($invoice);
37 37
 
38 38
     // Abort if the invoice does not exist.
39
-    if ( 0 == $invoice->get_id() ) {
39
+    if (0 == $invoice->get_id()) {
40 40
         return false;
41 41
     }
42 42
 
43 43
     // Don't allow trash, draft status
44
-    if ( $invoice->is_draft() ) {
44
+    if ($invoice->is_draft()) {
45 45
         return false;
46 46
     }
47 47
 
48 48
     // If users are not required to login to check out, compare the invoice keys.
49
-    if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && trim( $_GET['invoice_key'] ) == $invoice->get_key() ) {
49
+    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && trim($_GET['invoice_key']) == $invoice->get_key()) {
50 50
         return true;
51 51
     }
52 52
 
53 53
     // Always enable for admins..
54
-    if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user
54
+    if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->get_id())) { // Admin user
55 55
         return true;
56 56
     }
57 57
 
58 58
     // Else, ensure that this is their invoice.
59
-    if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) {
59
+    if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) {
60 60
         return true;
61 61
     }
62 62
 
63
-    return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice );
63
+    return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice);
64 64
 }
65 65
 
66 66
 /**
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69
-function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
69
+function wpinv_can_view_receipt($invoice) {
70
+	return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice);
71 71
 }
72 72
 
73 73
 /**
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_invoice_post_types() {
79 79
     $post_types = array(
80
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
81
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
80
+        'wpi_quote'   => __('Quote', 'invoicing'),
81
+        'wpi_invoice' => __('Invoice', 'invoicing'),
82 82
     );
83 83
 
84
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
84
+    return apply_filters('getpaid_invoice_post_types', $post_types);
85 85
 }
86 86
 
87 87
 /**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
  * 
91 91
  * @param string $post_type The post type to check for.
92 92
  */
93
-function getpaid_is_invoice_post_type( $post_type ) {
94
-    return ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
93
+function getpaid_is_invoice_post_type($post_type) {
94
+    return !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types());
95 95
 }
96 96
 
97 97
 /**
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
102 102
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
103 103
  */
104
-function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) {
105
-    $data[ 'invoice_id' ] = 0;
106
-    return wpinv_insert_invoice( $data, $wp_error );
104
+function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) {
105
+    $data['invoice_id'] = 0;
106
+    return wpinv_insert_invoice($data, $wp_error);
107 107
 }
108 108
 
109 109
 /**
@@ -113,36 +113,36 @@  discard block
 block discarded – undo
113 113
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
114 114
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
115 115
  */
116
-function wpinv_update_invoice( $data = array(), $wp_error = false ) {
116
+function wpinv_update_invoice($data = array(), $wp_error = false) {
117 117
 
118 118
     // Backwards compatibility.
119
-    if ( ! empty( $data['ID'] ) ) {
119
+    if (!empty($data['ID'])) {
120 120
         $data['invoice_id'] = $data['ID'];
121 121
     }
122 122
 
123 123
     // Do we have an invoice id?
124
-    if ( empty( $data['invoice_id'] ) ) {
125
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0;
124
+    if (empty($data['invoice_id'])) {
125
+        return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0;
126 126
     }
127 127
 
128 128
     // Retrieve the invoice.
129
-    $invoice = wpinv_get_invoice( $data['invoice_id'] );
129
+    $invoice = wpinv_get_invoice($data['invoice_id']);
130 130
 
131 131
     // And abort if it does not exist.
132
-    if ( empty( $invoice ) ) {
133
-        return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0;
132
+    if (empty($invoice)) {
133
+        return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0;
134 134
     }
135 135
 
136 136
     // Do not update totals for paid / refunded invoices.
137
-    if ( $invoice->is_paid() || $invoice->is_refunded() ) {
137
+    if ($invoice->is_paid() || $invoice->is_refunded()) {
138 138
 
139
-        if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) {
140
-            return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0;
139
+        if (!empty($data['items']) || !empty($data['cart_details'])) {
140
+            return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0;
141 141
         }
142 142
 
143 143
     }
144 144
 
145
-    return wpinv_insert_invoice( $data, $wp_error );
145
+    return wpinv_insert_invoice($data, $wp_error);
146 146
 
147 147
 }
148 148
 
@@ -153,34 +153,34 @@  discard block
 block discarded – undo
153 153
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
154 154
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
155 155
  */
156
-function wpinv_insert_invoice( $data = array(), $wp_error = false ) {
156
+function wpinv_insert_invoice($data = array(), $wp_error = false) {
157 157
 
158 158
     // Ensure that we have invoice data.
159
-    if ( empty( $data ) ) {
159
+    if (empty($data)) {
160 160
         return false;
161 161
     }
162 162
 
163 163
     // The invoice id will be provided when updating an invoice.
164
-    $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false;
164
+    $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false;
165 165
 
166 166
     // Retrieve the invoice.
167
-    $invoice = new WPInv_Invoice( $data['invoice_id'] );
167
+    $invoice = new WPInv_Invoice($data['invoice_id']);
168 168
 
169 169
     // Do we have an error?
170
-    if ( ! empty( $invoice->last_error ) ) {
171
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0;
170
+    if (!empty($invoice->last_error)) {
171
+        return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0;
172 172
     }
173 173
 
174 174
     // Backwards compatibility (billing address).
175
-    if ( ! empty( $data['user_info'] ) ) {
175
+    if (!empty($data['user_info'])) {
176 176
 
177
-        foreach ( $data['user_info'] as $key => $value ) {
177
+        foreach ($data['user_info'] as $key => $value) {
178 178
 
179
-            if ( $key == 'discounts' ) {
179
+            if ($key == 'discounts') {
180 180
                 $value = (array) $value;
181
-                $data[ 'discount_code' ] = empty( $value ) ? null : $value[0];
181
+                $data['discount_code'] = empty($value) ? null : $value[0];
182 182
             } else {
183
-                $data[ $key ] = $value;
183
+                $data[$key] = $value;
184 184
             }
185 185
 
186 186
         }
@@ -188,30 +188,30 @@  discard block
 block discarded – undo
188 188
     }
189 189
 
190 190
     // Backwards compatibility.
191
-    if ( ! empty( $data['payment_details'] ) ) {
191
+    if (!empty($data['payment_details'])) {
192 192
 
193
-        foreach ( $data['payment_details'] as $key => $value ) {
194
-            $data[ $key ] = $value;
193
+        foreach ($data['payment_details'] as $key => $value) {
194
+            $data[$key] = $value;
195 195
         }
196 196
 
197 197
     }
198 198
 
199 199
     // Set up the owner of the invoice.
200
-    $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id();
200
+    $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id();
201 201
 
202 202
     // Make sure the user exists.
203
-    if ( ! get_userdata( $user_id ) ) {
204
-        return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0;
203
+    if (!get_userdata($user_id)) {
204
+        return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0;
205 205
     }
206 206
 
207
-    $address = wpinv_get_user_address( $user_id );
207
+    $address = wpinv_get_user_address($user_id);
208 208
 
209
-    foreach ( $address as $key => $value ) {
209
+    foreach ($address as $key => $value) {
210 210
 
211
-        if ( $value == '' ) {
212
-            $address[ $key ] = null;
211
+        if ($value == '') {
212
+            $address[$key] = null;
213 213
         } else {
214
-            $address[ $key ] = wpinv_clean( $value );
214
+            $address[$key] = wpinv_clean($value);
215 215
         }
216 216
 
217 217
     }
@@ -222,103 +222,103 @@  discard block
 block discarded – undo
222 222
         array(
223 223
 
224 224
             // Basic info.
225
-            'template'             => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null,
226
-            'email_cc'             => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null,
227
-            'date_created'         => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null,
228
-            'due_date'             => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null,
229
-            'date_completed'       => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null,
230
-            'number'               => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null,
231
-            'key'                  => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null,
232
-            'status'               => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null,
233
-            'post_type'            => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null,
234
-            'user_ip'              => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(),
235
-            'parent_id'            => isset( $data['parent'] ) ? intval( $data['parent'] ) : null,
236
-            'mode'                 => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null,
237
-            'description'          => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null,
225
+            'template'             => isset($data['template']) ? wpinv_clean($data['template']) : null,
226
+            'email_cc'             => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null,
227
+            'date_created'         => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null,
228
+            'due_date'             => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null,
229
+            'date_completed'       => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null,
230
+            'number'               => isset($data['number']) ? wpinv_clean($data['number']) : null,
231
+            'key'                  => isset($data['key']) ? wpinv_clean($data['key']) : null,
232
+            'status'               => isset($data['status']) ? wpinv_clean($data['status']) : null,
233
+            'post_type'            => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null,
234
+            'user_ip'              => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(),
235
+            'parent_id'            => isset($data['parent']) ? intval($data['parent']) : null,
236
+            'mode'                 => isset($data['mode']) ? wpinv_clean($data['mode']) : null,
237
+            'description'          => isset($data['description']) ? wp_kses_post($data['description']) : null,
238 238
 
239 239
             // Payment info.
240
-            'disable_taxes'        => ! empty( $data['disable_taxes'] ),
241
-            'currency'             => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(),
242
-            'gateway'              => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null,
243
-            'transaction_id'       => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null,
244
-            'discount_code'        => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null,
245
-            'payment_form'         => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null,
246
-            'submission_id'        => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null,
247
-            'subscription_id'      => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null,
248
-            'is_viewed'            => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null,
249
-            'fees'                 => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null,
250
-            'discounts'            => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null,
251
-            'taxes'                => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null,
240
+            'disable_taxes'        => !empty($data['disable_taxes']),
241
+            'currency'             => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(),
242
+            'gateway'              => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null,
243
+            'transaction_id'       => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null,
244
+            'discount_code'        => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null,
245
+            'payment_form'         => isset($data['payment_form']) ? intval($data['payment_form']) : null,
246
+            'submission_id'        => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null,
247
+            'subscription_id'      => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null,
248
+            'is_viewed'            => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null,
249
+            'fees'                 => isset($data['fees']) ? wpinv_clean($data['fees']) : null,
250
+            'discounts'            => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null,
251
+            'taxes'                => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null,
252 252
             
253 253
 
254 254
             // Billing details.
255 255
             'user_id'              => $data['user_id'],
256
-            'first_name'           => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'],
257
-            'last_name'            => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'],
258
-            'address'              => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'] ,
259
-            'vat_number'           => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'],
260
-            'company'              => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'],
261
-            'zip'                  => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'],
262
-            'state'                => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'],
263
-            'city'                 => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'],
264
-            'country'              => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'],
265
-            'phone'                => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'],
266
-            'address_confirmed'    => ! empty( $data['address_confirmed'] ),
256
+            'first_name'           => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'],
257
+            'last_name'            => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'],
258
+            'address'              => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'],
259
+            'vat_number'           => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'],
260
+            'company'              => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'],
261
+            'zip'                  => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'],
262
+            'state'                => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'],
263
+            'city'                 => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'],
264
+            'country'              => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'],
265
+            'phone'                => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'],
266
+            'address_confirmed'    => !empty($data['address_confirmed']),
267 267
 
268 268
         )
269 269
 
270 270
     );
271 271
 
272 272
     // Backwards compatibililty.
273
-    if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) {
273
+    if (!empty($data['cart_details']) && is_array($data['cart_details'])) {
274 274
         $data['items'] = array();
275 275
 
276
-        foreach( $data['cart_details'] as $_item ) {
276
+        foreach ($data['cart_details'] as $_item) {
277 277
 
278 278
             // Ensure that we have an item id.
279
-            if ( empty(  $_item['id']  ) ) {
279
+            if (empty($_item['id'])) {
280 280
                 continue;
281 281
             }
282 282
 
283 283
             // Retrieve the item.
284
-            $item = new GetPaid_Form_Item(  $_item['id']  );
284
+            $item = new GetPaid_Form_Item($_item['id']);
285 285
 
286 286
             // Ensure that it is purchasable.
287
-            if ( ! $item->can_purchase() ) {
287
+            if (!$item->can_purchase()) {
288 288
                 continue;
289 289
             }
290 290
 
291 291
             // Set quantity.
292
-            if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) {
293
-                $item->set_quantity( $_item['quantity'] );
292
+            if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) {
293
+                $item->set_quantity($_item['quantity']);
294 294
             }
295 295
 
296 296
             // Set price.
297
-            if ( isset( $_item['item_price'] ) ) {
298
-                $item->set_price( $_item['item_price'] );
297
+            if (isset($_item['item_price'])) {
298
+                $item->set_price($_item['item_price']);
299 299
             }
300 300
 
301
-            if ( isset( $_item['custom_price'] ) ) {
302
-                $item->set_price( $_item['custom_price'] );
301
+            if (isset($_item['custom_price'])) {
302
+                $item->set_price($_item['custom_price']);
303 303
             }
304 304
 
305 305
             // Set name.
306
-            if ( ! empty( $_item['name'] ) ) {
307
-                $item->set_name( $_item['name'] );
306
+            if (!empty($_item['name'])) {
307
+                $item->set_name($_item['name']);
308 308
             }
309 309
 
310 310
             // Set description.
311
-            if ( isset( $_item['description'] ) ) {
312
-                $item->set_custom_description( $_item['description'] );
311
+            if (isset($_item['description'])) {
312
+                $item->set_custom_description($_item['description']);
313 313
             }
314 314
 
315 315
             // Set meta.
316
-            if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) {
316
+            if (isset($_item['meta']) && is_array($_item['meta'])) {
317 317
 
318
-                $item->set_item_meta( $_item['meta'] );
318
+                $item->set_item_meta($_item['meta']);
319 319
 
320
-                if ( isset( $_item['meta']['description'] ) ) {
321
-                    $item->set_custom_description( $_item['meta']['description'] );
320
+                if (isset($_item['meta']['description'])) {
321
+                    $item->set_custom_description($_item['meta']['description']);
322 322
                 }
323 323
 
324 324
             }
@@ -329,14 +329,14 @@  discard block
 block discarded – undo
329 329
     }
330 330
 
331 331
     // Add invoice items.
332
-    if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
332
+    if (!empty($data['items']) && is_array($data['items'])) {
333 333
 
334
-        $invoice->set_items( array() );
334
+        $invoice->set_items(array());
335 335
 
336
-        foreach ( $data['items'] as $item ) {
336
+        foreach ($data['items'] as $item) {
337 337
 
338
-            if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) {
339
-                $invoice->add_item( $item );
338
+            if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) {
339
+                $invoice->add_item($item);
340 340
             }
341 341
 
342 342
         }
@@ -347,30 +347,30 @@  discard block
 block discarded – undo
347 347
     $invoice->recalculate_total();
348 348
     $invoice->save();
349 349
 
350
-    if ( ! $invoice->get_id() ) {
351
-        return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0;
350
+    if (!$invoice->get_id()) {
351
+        return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0;
352 352
     }
353 353
 
354 354
     // Add private note.
355
-    if ( ! empty( $data['private_note'] ) ) {
356
-        $invoice->add_note( $data['private_note'] );
355
+    if (!empty($data['private_note'])) {
356
+        $invoice->add_note($data['private_note']);
357 357
     }
358 358
 
359 359
     // User notes.
360
-    if ( !empty( $data['user_note'] ) ) {
361
-        $invoice->add_note( $data['user_note'], true );
360
+    if (!empty($data['user_note'])) {
361
+        $invoice->add_note($data['user_note'], true);
362 362
     }
363 363
 
364 364
     // Created via.
365
-    if ( isset( $data['created_via'] ) ) {
366
-        update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] );
365
+    if (isset($data['created_via'])) {
366
+        update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']);
367 367
     }
368 368
 
369 369
     // Backwards compatiblity.
370
-    if ( $invoice->is_quote() ) {
370
+    if ($invoice->is_quote()) {
371 371
 
372
-        if ( isset( $data['valid_until'] ) ) {
373
-            update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] );
372
+        if (isset($data['valid_until'])) {
373
+            update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']);
374 374
         }
375 375
         return $invoice;
376 376
 
@@ -385,18 +385,18 @@  discard block
 block discarded – undo
385 385
  * @param $bool $deprecated
386 386
  * @return WPInv_Invoice|null
387 387
  */
388
-function wpinv_get_invoice( $invoice = 0, $deprecated = false ) {
388
+function wpinv_get_invoice($invoice = 0, $deprecated = false) {
389 389
 
390 390
     // If we are retrieving the invoice from the cart...
391
-    if ( $deprecated && empty( $invoice ) ) {
391
+    if ($deprecated && empty($invoice)) {
392 392
         $invoice = (int) getpaid_get_current_invoice_id();
393 393
     }
394 394
 
395 395
     // Retrieve the invoice.
396
-    $invoice = new WPInv_Invoice( $invoice );
396
+    $invoice = new WPInv_Invoice($invoice);
397 397
 
398 398
     // Check if it exists.
399
-    if ( $invoice->get_id() != 0 ) {
399
+    if ($invoice->get_id() != 0) {
400 400
         return $invoice;
401 401
     }
402 402
 
@@ -409,15 +409,15 @@  discard block
 block discarded – undo
409 409
  * @param array $args Args to search for.
410 410
  * @return WPInv_Invoice[]|int[]|object
411 411
  */
412
-function wpinv_get_invoices( $args ) {
412
+function wpinv_get_invoices($args) {
413 413
 
414 414
     // Prepare args.
415 415
     $args = wp_parse_args(
416 416
         $args,
417 417
         array(
418
-            'status'   => array_keys( wpinv_get_invoice_statuses() ),
418
+            'status'   => array_keys(wpinv_get_invoice_statuses()),
419 419
             'type'     => 'wpi_invoice',
420
-            'limit'    => get_option( 'posts_per_page' ),
420
+            'limit'    => get_option('posts_per_page'),
421 421
             'return'   => 'objects',
422 422
         )
423 423
     );
@@ -435,24 +435,24 @@  discard block
 block discarded – undo
435 435
         'post__in'       => 'include',
436 436
     );
437 437
 
438
-    foreach ( $map_legacy as $to => $from ) {
439
-        if ( isset( $args[ $from ] ) ) {
440
-            $args[ $to ] = $args[ $from ];
441
-            unset( $args[ $from ] );
438
+    foreach ($map_legacy as $to => $from) {
439
+        if (isset($args[$from])) {
440
+            $args[$to] = $args[$from];
441
+            unset($args[$from]);
442 442
         }
443 443
     }
444 444
 
445 445
     // Backwards compatibility.
446
-    if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) {
446
+    if (!empty($args['email']) && empty($args['user'])) {
447 447
         $args['user'] = $args['email'];
448
-        unset( $args['email'] );
448
+        unset($args['email']);
449 449
     }
450 450
 
451 451
     // Handle cases where the user is set as an email.
452
-    if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) {
453
-        $user = get_user_by( 'email', $args['user'] );
452
+    if (!empty($args['author']) && is_email($args['author'])) {
453
+        $user = get_user_by('email', $args['user']);
454 454
 
455
-        if ( $user ) {
455
+        if ($user) {
456 456
             $args['author'] = $user->user_email;
457 457
         }
458 458
 
@@ -463,31 +463,31 @@  discard block
 block discarded – undo
463 463
 
464 464
     // Show all posts.
465 465
     $paginate = true;
466
-    if ( isset( $args['paginate'] ) ) {
466
+    if (isset($args['paginate'])) {
467 467
         
468 468
         $paginate = $args['paginate'];
469
-        $args['no_found_rows'] = empty( $args['paginate'] );
470
-        unset( $args['paginate'] );
469
+        $args['no_found_rows'] = empty($args['paginate']);
470
+        unset($args['paginate']);
471 471
 
472 472
     }
473 473
 
474 474
     // Whether to return objects or fields.
475 475
     $return = $args['return'];
476
-    unset( $args['return'] );
476
+    unset($args['return']);
477 477
 
478 478
     // Get invoices.
479
-    $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) );
479
+    $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args));
480 480
 
481 481
     // Prepare the results.
482
-    if ( 'objects' === $return ) {
483
-        $results = array_map( 'wpinv_get_invoice', $invoices->posts );
484
-    } elseif ( 'self' === $return ) {
482
+    if ('objects' === $return) {
483
+        $results = array_map('wpinv_get_invoice', $invoices->posts);
484
+    } elseif ('self' === $return) {
485 485
         return $invoices;
486 486
     } else {
487 487
         $results = $invoices->posts;
488 488
     }
489 489
 
490
-    if ( $paginate ) {
490
+    if ($paginate) {
491 491
         return (object) array(
492 492
             'invoices'      => $results,
493 493
             'total'         => $invoices->found_posts,
@@ -505,8 +505,8 @@  discard block
 block discarded – undo
505 505
  * @param string $transaction_id The transaction id to check.
506 506
  * @return int Invoice id on success or 0 on failure
507 507
  */
508
-function wpinv_get_id_by_transaction_id( $transaction_id ) {
509
-    return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' );
508
+function wpinv_get_id_by_transaction_id($transaction_id) {
509
+    return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id');
510 510
 }
511 511
 
512 512
 /**
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
  * @param string $invoice_number The invoice number to check.
516 516
  * @return int Invoice id on success or 0 on failure
517 517
  */
518
-function wpinv_get_id_by_invoice_number( $invoice_number ) {
519
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' );
518
+function wpinv_get_id_by_invoice_number($invoice_number) {
519
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number');
520 520
 }
521 521
 
522 522
 /**
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
  * @param string $invoice_key The invoice key to check.
526 526
  * @return int Invoice id on success or 0 on failure
527 527
  */
528
-function wpinv_get_invoice_id_by_key( $invoice_key ) {
529
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' );
528
+function wpinv_get_invoice_id_by_key($invoice_key) {
529
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key');
530 530
 }
531 531
 
532 532
 /**
@@ -536,19 +536,19 @@  discard block
 block discarded – undo
536 536
  * @param string $type Optionally filter by type i.e customer|system
537 537
  * @return array|null
538 538
  */
539
-function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) {
539
+function wpinv_get_invoice_notes($invoice = 0, $type = '') {
540 540
 
541 541
     // Prepare the invoice.
542
-    $invoice = wpinv_get_invoice( $invoice );
543
-    if ( empty( $invoice ) ) {
542
+    $invoice = wpinv_get_invoice($invoice);
543
+    if (empty($invoice)) {
544 544
         return NULL;
545 545
     }
546 546
 
547 547
     // Fetch notes.
548
-    $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type );
548
+    $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type);
549 549
 
550 550
     // Filter the notes.
551
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type );
551
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type);
552 552
 }
553 553
 
554 554
 /**
@@ -556,10 +556,10 @@  discard block
 block discarded – undo
556 556
  * 
557 557
  * @param string $post_type
558 558
  */
559
-function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) {
559
+function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') {
560 560
 
561
-    $label   = getpaid_get_post_type_label( $post_type, false );
562
-    $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
561
+    $label   = getpaid_get_post_type_label($post_type, false);
562
+    $label   = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label);
563 563
     $columns = array(
564 564
 
565 565
             'invoice-number'  => array(
@@ -568,22 +568,22 @@  discard block
 block discarded – undo
568 568
             ),
569 569
 
570 570
             'created-date'    => array(
571
-                'title' => __( 'Created Date', 'invoicing' ),
571
+                'title' => __('Created Date', 'invoicing'),
572 572
                 'class' => 'text-left'
573 573
             ),
574 574
 
575 575
             'payment-date'    => array(
576
-                'title' => __( 'Payment Date', 'invoicing' ),
576
+                'title' => __('Payment Date', 'invoicing'),
577 577
                 'class' => 'text-left'
578 578
             ),
579 579
 
580 580
             'invoice-status'  => array(
581
-                'title' => __( 'Status', 'invoicing' ),
581
+                'title' => __('Status', 'invoicing'),
582 582
                 'class' => 'text-center'
583 583
             ),
584 584
 
585 585
             'invoice-total'   => array(
586
-                'title' => __( 'Total', 'invoicing' ),
586
+                'title' => __('Total', 'invoicing'),
587 587
                 'class' => 'text-right'
588 588
             ),
589 589
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 
595 595
         );
596 596
 
597
-    return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
597
+    return apply_filters('wpinv_user_invoices_columns', $columns, $post_type);
598 598
 }
599 599
 
600 600
 /**
@@ -604,59 +604,59 @@  discard block
 block discarded – undo
604 604
 
605 605
     // Find the invoice.
606 606
     $invoice_id = getpaid_get_current_invoice_id();
607
-    $invoice = new WPInv_Invoice( $invoice_id );
607
+    $invoice = new WPInv_Invoice($invoice_id);
608 608
 
609 609
     // Abort if non was found.
610
-    if ( empty( $invoice_id ) || $invoice->is_draft() ) {
610
+    if (empty($invoice_id) || $invoice->is_draft()) {
611 611
 
612 612
         return aui()->alert(
613 613
             array(
614 614
                 'type'    => 'warning',
615
-                'content' => __( 'We could not find your invoice', 'invoicing' ),
615
+                'content' => __('We could not find your invoice', 'invoicing'),
616 616
             )
617 617
         );
618 618
 
619 619
     }
620 620
 
621 621
     // Can the user view this invoice?
622
-    if ( ! wpinv_can_view_receipt( $invoice_id ) ) {
622
+    if (!wpinv_can_view_receipt($invoice_id)) {
623 623
 
624 624
         return aui()->alert(
625 625
             array(
626 626
                 'type'    => 'warning',
627
-                'content' => __( 'You are not allowed to view this receipt', 'invoicing' ),
627
+                'content' => __('You are not allowed to view this receipt', 'invoicing'),
628 628
             )
629 629
         );
630 630
 
631 631
     }
632 632
 
633 633
     // Load the template.
634
-    return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) );
634
+    return wpinv_get_template_html('invoice-receipt.php', compact('invoice'));
635 635
 
636 636
 }
637 637
 
638 638
 /**
639 639
  * Displays the invoice history.
640 640
  */
641
-function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) {
641
+function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') {
642 642
 
643 643
     // Ensure that we have a user id.
644
-    if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
644
+    if (empty($user_id) || !is_numeric($user_id)) {
645 645
         $user_id = get_current_user_id();
646 646
     }
647 647
 
648
-    $label = getpaid_get_post_type_label( $post_type );
649
-    $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label );
648
+    $label = getpaid_get_post_type_label($post_type);
649
+    $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label);
650 650
 
651 651
     // View user id.
652
-    if ( empty( $user_id ) ) {
652
+    if (empty($user_id)) {
653 653
 
654 654
         return aui()->alert(
655 655
             array(
656 656
                 'type'    => 'warning',
657 657
                 'content' => sprintf(
658
-                    __( 'You must be logged in to view your %s.', 'invoicing' ),
659
-                    strtolower( $label )
658
+                    __('You must be logged in to view your %s.', 'invoicing'),
659
+                    strtolower($label)
660 660
                 )
661 661
             )
662 662
         );
@@ -667,23 +667,23 @@  discard block
 block discarded – undo
667 667
     $invoices = wpinv_get_invoices(
668 668
 
669 669
         array(
670
-            'page'      => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
670
+            'page'      => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
671 671
             'user'      => $user_id,
672 672
             'paginate'  => true,
673 673
             'type'      => $post_type,
674
-            'status'    => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ),
674
+            'status'    => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)),
675 675
         )
676 676
 
677 677
     );
678 678
 
679
-    if ( empty( $invoices->total ) ) {
679
+    if (empty($invoices->total)) {
680 680
 
681 681
         return aui()->alert(
682 682
             array(
683 683
                 'type'    => 'info',
684 684
                 'content' => sprintf(
685
-                    __( 'No %s found.', 'invoicing' ),
686
-                    strtolower( $label )
685
+                    __('No %s found.', 'invoicing'),
686
+                    strtolower($label)
687 687
                 )
688 688
             )
689 689
         );
@@ -691,38 +691,38 @@  discard block
 block discarded – undo
691 691
     }
692 692
 
693 693
     // Load the template.
694
-    return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) );
694
+    return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type'));
695 695
 
696 696
 }
697 697
 
698 698
 /**
699 699
  * Formats an invoice number given an invoice type.
700 700
  */
701
-function wpinv_format_invoice_number( $number, $type = '' ) {
701
+function wpinv_format_invoice_number($number, $type = '') {
702 702
 
703 703
     // Allow other plugins to overide this.
704
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
705
-    if ( null !== $check ) {
704
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
705
+    if (null !== $check) {
706 706
         return $check;
707 707
     }
708 708
 
709 709
     // Ensure that we have a numeric number.
710
-    if ( ! is_numeric( $number ) ) {
710
+    if (!is_numeric($number)) {
711 711
         return $number;
712 712
     }
713 713
 
714 714
     // Format the number.
715
-    $padd             = absint( (int) wpinv_get_option( 'invoice_number_padd' ) );
716
-    $prefix           = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) );
717
-    $prefix           = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) );
718
-    $postfix          = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) );
719
-    $postfix          = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) );
720
-    $formatted_number = zeroise( absint( $number ), $padd );
715
+    $padd             = absint((int) wpinv_get_option('invoice_number_padd'));
716
+    $prefix           = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-'));
717
+    $prefix           = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type));
718
+    $postfix          = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix'));
719
+    $postfix          = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type));
720
+    $formatted_number = zeroise(absint($number), $padd);
721 721
 
722 722
     // Add the prefix and post fix.
723 723
     $formatted_number = $prefix . $formatted_number . $postfix;
724 724
 
725
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
725
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
726 726
 }
727 727
 
728 728
 /**
@@ -731,58 +731,58 @@  discard block
 block discarded – undo
731 731
  * @param string $type.
732 732
  * @return int|null|bool
733 733
  */
734
-function wpinv_get_next_invoice_number( $type = '' ) {
734
+function wpinv_get_next_invoice_number($type = '') {
735 735
 
736 736
     // Allow plugins to overide this.
737
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
738
-    if ( null !== $check ) {
737
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
738
+    if (null !== $check) {
739 739
         return $check;
740 740
     }
741 741
 
742 742
     // Ensure sequential invoice numbers is active.
743
-    if ( ! wpinv_sequential_number_active() ) {
743
+    if (!wpinv_sequential_number_active()) {
744 744
         return false;
745 745
     }
746 746
 
747 747
     // Retrieve the current number and the start number.
748
-    $number = (int) get_option( 'wpinv_last_invoice_number', 0 );
749
-    $start  = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) );
748
+    $number = (int) get_option('wpinv_last_invoice_number', 0);
749
+    $start  = absint((int) wpinv_get_option('invoice_sequence_start', 1));
750 750
 
751 751
     // Ensure that we are starting at a positive integer.
752
-    $start  = max( $start, 1 );
752
+    $start  = max($start, 1);
753 753
 
754 754
     // If this is the first invoice, use the start number.
755
-    $number = max( $start, $number );
755
+    $number = max($start, $number);
756 756
 
757 757
     // Format the invoice number.
758
-    $formatted_number = wpinv_format_invoice_number( $number, $type );
758
+    $formatted_number = wpinv_format_invoice_number($number, $type);
759 759
 
760 760
     // Ensure that this number is unique.
761
-    $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' );
761
+    $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number');
762 762
 
763 763
     // We found a match. Nice.
764
-    if ( empty( $invoice_id ) ) {
765
-        update_option( 'wpinv_last_invoice_number', $number );
766
-        return apply_filters( 'wpinv_get_next_invoice_number', $number );
764
+    if (empty($invoice_id)) {
765
+        update_option('wpinv_last_invoice_number', $number);
766
+        return apply_filters('wpinv_get_next_invoice_number', $number);
767 767
     }
768 768
 
769
-    update_option( 'wpinv_last_invoice_number', $number + 1 );
770
-    return wpinv_get_next_invoice_number( $type );
769
+    update_option('wpinv_last_invoice_number', $number + 1);
770
+    return wpinv_get_next_invoice_number($type);
771 771
 
772 772
 }
773 773
 
774 774
 /**
775 775
  * The prefix used for invoice paths.
776 776
  */
777
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
778
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
777
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
778
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
779 779
 }
780 780
 
781
-function wpinv_generate_post_name( $post_ID ) {
782
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
783
-    $post_name = sanitize_title( $prefix . $post_ID );
781
+function wpinv_generate_post_name($post_ID) {
782
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
783
+    $post_name = sanitize_title($prefix . $post_ID);
784 784
 
785
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
785
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
786 786
 }
787 787
 
788 788
 /**
@@ -790,8 +790,8 @@  discard block
 block discarded – undo
790 790
  * 
791 791
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
792 792
  */
793
-function wpinv_is_invoice_viewed( $invoice ) {
794
-    $invoice = new WPInv_Invoice( $invoice );
793
+function wpinv_is_invoice_viewed($invoice) {
794
+    $invoice = new WPInv_Invoice($invoice);
795 795
     return (bool) $invoice->get_is_viewed();
796 796
 }
797 797
 
@@ -800,17 +800,17 @@  discard block
 block discarded – undo
800 800
  * 
801 801
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
802 802
  */
803
-function getpaid_maybe_mark_invoice_as_viewed( $invoice ) {
804
-    $invoice = new WPInv_Invoice( $invoice );
803
+function getpaid_maybe_mark_invoice_as_viewed($invoice) {
804
+    $invoice = new WPInv_Invoice($invoice);
805 805
 
806
-    if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) {
807
-        $invoice->set_is_viewed( true );
806
+    if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) {
807
+        $invoice->set_is_viewed(true);
808 808
         $invoice->save();
809 809
     }
810 810
 
811 811
 }
812
-add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' );
813
-add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' );
812
+add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed');
813
+add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed');
814 814
 
815 815
 /**
816 816
  * Processes an invoice refund.
@@ -819,27 +819,27 @@  discard block
 block discarded – undo
819 819
  * @param array $status_transition
820 820
  * @todo: descrease customer/store earnings
821 821
  */
822
-function getpaid_maybe_process_refund( $invoice, $status_transition ) {
822
+function getpaid_maybe_process_refund($invoice, $status_transition) {
823 823
 
824
-    if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
824
+    if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
825 825
         return;
826 826
     }
827 827
 
828 828
     $discount_code = $invoice->get_discount_code();
829
-    if ( ! empty( $discount_code ) ) {
830
-        $discount = wpinv_get_discount_obj( $discount_code );
829
+    if (!empty($discount_code)) {
830
+        $discount = wpinv_get_discount_obj($discount_code);
831 831
 
832
-        if ( $discount->exists() ) {
832
+        if ($discount->exists()) {
833 833
             $discount->increase_usage( -1 );
834 834
         }
835 835
 
836 836
     }
837 837
 
838
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() );
839
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() );
840
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() );
838
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id());
839
+    do_action('wpinv_refund_invoice', $invoice, $invoice->get_id());
840
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id());
841 841
 }
842
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 );
842
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2);
843 843
 
844 844
 
845 845
 /**
@@ -847,48 +847,48 @@  discard block
 block discarded – undo
847 847
  *
848 848
  * @param int $invoice_id
849 849
  */
850
-function getpaid_process_invoice_payment( $invoice_id ) {
850
+function getpaid_process_invoice_payment($invoice_id) {
851 851
 
852 852
     // Fetch the invoice.
853
-    $invoice = new WPInv_Invoice( $invoice_id );
853
+    $invoice = new WPInv_Invoice($invoice_id);
854 854
 
855 855
     // We only want to do this once.
856
-    if ( 1 ==  get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) {
856
+    if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) {
857 857
         return;
858 858
     }
859 859
 
860
-    update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 );
860
+    update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1);
861 861
 
862 862
     // Fires when processing a payment.
863
-    do_action( 'getpaid_process_payment', $invoice );
863
+    do_action('getpaid_process_payment', $invoice);
864 864
 
865 865
     // Fire an action for each invoice item.
866
-    foreach( $invoice->get_items() as $item ) {
867
-        do_action( 'getpaid_process_item_payment', $item, $invoice );
866
+    foreach ($invoice->get_items() as $item) {
867
+        do_action('getpaid_process_item_payment', $item, $invoice);
868 868
     }
869 869
 
870 870
     // Increase discount usage.
871 871
     $discount_code = $invoice->get_discount_code();
872
-    if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) {
873
-        $discount = wpinv_get_discount_obj( $discount_code );
872
+    if (!empty($discount_code) && !$invoice->is_renewal()) {
873
+        $discount = wpinv_get_discount_obj($discount_code);
874 874
 
875
-        if ( $discount->exists() ) {
875
+        if ($discount->exists()) {
876 876
             $discount->increase_usage();
877 877
         }
878 878
 
879 879
     }
880 880
 
881 881
     // Record reverse vat.
882
-    if ( 'invoice' == $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
882
+    if ('invoice' == $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
883 883
 
884
-        if ( WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country( $invoice->get_country() ) ) {
885
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
884
+        if (WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country($invoice->get_country())) {
885
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
886 886
         }
887 887
 
888 888
     }
889 889
 
890 890
 }
891
-add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' );
891
+add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment');
892 892
 
893 893
 /**
894 894
  * Returns an array of invoice item columns
@@ -896,13 +896,13 @@  discard block
 block discarded – undo
896 896
  * @param int|WPInv_Invoice $invoice
897 897
  * @return array
898 898
  */
899
-function getpaid_invoice_item_columns( $invoice ) {
899
+function getpaid_invoice_item_columns($invoice) {
900 900
 
901 901
     // Prepare the invoice.
902
-    $invoice = new WPInv_Invoice( $invoice );
902
+    $invoice = new WPInv_Invoice($invoice);
903 903
 
904 904
     // Abort if there is no invoice.
905
-    if ( 0 == $invoice->get_id() ) {
905
+    if (0 == $invoice->get_id()) {
906 906
         return array();
907 907
     }
908 908
 
@@ -910,47 +910,47 @@  discard block
 block discarded – undo
910 910
     $columns = apply_filters(
911 911
         'getpaid_invoice_item_columns',
912 912
         array(
913
-            'name'     => __( 'Item', 'invoicing' ),
914
-            'price'    => __( 'Price', 'invoicing' ),
915
-            'quantity' => __( 'Quantity', 'invoicing' ),
916
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
913
+            'name'     => __('Item', 'invoicing'),
914
+            'price'    => __('Price', 'invoicing'),
915
+            'quantity' => __('Quantity', 'invoicing'),
916
+            'subtotal' => __('Subtotal', 'invoicing'),
917 917
         ),
918 918
         $invoice
919 919
     );
920 920
 
921 921
     // Quantities.
922
-    if ( isset( $columns[ 'quantity' ] ) ) {
922
+    if (isset($columns['quantity'])) {
923 923
 
924
-        if ( 'hours' == $invoice->get_template() ) {
925
-            $columns[ 'quantity' ] = __( 'Hours', 'invoicing' );
924
+        if ('hours' == $invoice->get_template()) {
925
+            $columns['quantity'] = __('Hours', 'invoicing');
926 926
         }
927 927
 
928
-        if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) {
929
-            unset( $columns[ 'quantity' ] );
928
+        if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) {
929
+            unset($columns['quantity']);
930 930
         }
931 931
 
932 932
     }
933 933
 
934 934
 
935 935
     // Price.
936
-    if ( isset( $columns[ 'price' ] ) ) {
936
+    if (isset($columns['price'])) {
937 937
 
938
-        if ( 'amount' == $invoice->get_template() ) {
939
-            $columns[ 'price' ] = __( 'Amount', 'invoicing' );
938
+        if ('amount' == $invoice->get_template()) {
939
+            $columns['price'] = __('Amount', 'invoicing');
940 940
         }
941 941
 
942
-        if ( 'hours' == $invoice->get_template() ) {
943
-            $columns[ 'price' ] = __( 'Rate', 'invoicing' );
942
+        if ('hours' == $invoice->get_template()) {
943
+            $columns['price'] = __('Rate', 'invoicing');
944 944
         }
945 945
 
946 946
     }
947 947
 
948 948
 
949 949
     // Sub total.
950
-    if ( isset( $columns[ 'subtotal' ] ) ) {
950
+    if (isset($columns['subtotal'])) {
951 951
 
952
-        if ( 'amount' == $invoice->get_template() ) {
953
-            unset( $columns[ 'subtotal' ] );
952
+        if ('amount' == $invoice->get_template()) {
953
+            unset($columns['subtotal']);
954 954
         }
955 955
 
956 956
     }
@@ -964,30 +964,30 @@  discard block
 block discarded – undo
964 964
  * @param int|WPInv_Invoice $invoice
965 965
  * @return array
966 966
  */
967
-function getpaid_invoice_totals_rows( $invoice ) {
967
+function getpaid_invoice_totals_rows($invoice) {
968 968
 
969 969
     // Prepare the invoice.
970
-    $invoice = new WPInv_Invoice( $invoice );
970
+    $invoice = new WPInv_Invoice($invoice);
971 971
 
972 972
     // Abort if there is no invoice.
973
-    if ( 0 == $invoice->get_id() ) {
973
+    if (0 == $invoice->get_id()) {
974 974
         return array();
975 975
     }
976 976
 
977 977
     $totals = apply_filters(
978 978
         'getpaid_invoice_totals_rows',
979 979
         array(
980
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
981
-            'tax'      => __( 'Tax', 'invoicing' ),
982
-            'fee'      => __( 'Fee', 'invoicing' ),
983
-            'discount' => __( 'Discount', 'invoicing' ),
984
-            'total'    => __( 'Total', 'invoicing' ),
980
+            'subtotal' => __('Subtotal', 'invoicing'),
981
+            'tax'      => __('Tax', 'invoicing'),
982
+            'fee'      => __('Fee', 'invoicing'),
983
+            'discount' => __('Discount', 'invoicing'),
984
+            'total'    => __('Total', 'invoicing'),
985 985
         ),
986 986
         $invoice
987 987
     );
988 988
 
989
-    if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) {
990
-        unset( $totals['tax'] );
989
+    if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) {
990
+        unset($totals['tax']);
991 991
     }
992 992
 
993 993
     return $totals;
@@ -998,47 +998,47 @@  discard block
 block discarded – undo
998 998
  * 
999 999
  * @param WPInv_Invoice $invoice
1000 1000
  */
1001
-function getpaid_new_invoice( $invoice ) {
1001
+function getpaid_new_invoice($invoice) {
1002 1002
 
1003
-    if ( ! $invoice->get_status() ) {
1003
+    if (!$invoice->get_status()) {
1004 1004
         return;
1005 1005
     }
1006 1006
 
1007 1007
     // Add an invoice created note.
1008 1008
     $invoice->add_note(
1009 1009
         sprintf(
1010
-            __( '%s created with the status "%s".', 'invoicing' ),
1011
-            ucfirst( $invoice->get_type() ),
1012
-            wpinv_status_nicename( $invoice->get_status(), $invoice  )
1010
+            __('%s created with the status "%s".', 'invoicing'),
1011
+            ucfirst($invoice->get_type()),
1012
+            wpinv_status_nicename($invoice->get_status(), $invoice)
1013 1013
         )
1014 1014
     );
1015 1015
 
1016 1016
 }
1017
-add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' );
1017
+add_action('getpaid_new_invoice', 'getpaid_new_invoice');
1018 1018
 
1019 1019
 /**
1020 1020
  * This function updates invoice caches.
1021 1021
  * 
1022 1022
  * @param WPInv_Invoice $invoice
1023 1023
  */
1024
-function getpaid_update_invoice_caches( $invoice ) {
1024
+function getpaid_update_invoice_caches($invoice) {
1025 1025
 
1026 1026
     // Cache invoice number.
1027
-    wp_cache_set( $invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids" );
1027
+    wp_cache_set($invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids");
1028 1028
 
1029 1029
     // Cache invoice key.
1030
-    wp_cache_set( $invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids" );
1030
+    wp_cache_set($invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids");
1031 1031
 
1032 1032
     // (Maybe) cache transaction id.
1033 1033
     $transaction_id = $invoice->get_transaction_id();
1034 1034
 
1035
-    if ( ! empty( $transaction_id ) ) {
1036
-        wp_cache_set( $transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids" );
1035
+    if (!empty($transaction_id)) {
1036
+        wp_cache_set($transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids");
1037 1037
     }
1038 1038
 
1039 1039
 }
1040
-add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 );
1041
-add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 );
1040
+add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5);
1041
+add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5);
1042 1042
 
1043 1043
 /**
1044 1044
  * Duplicates an invoice.
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
  * @param  WPInv_Invoice $old_invoice The invoice to duplicate
1049 1049
  * @return WPInv_Invoice The new invoice.
1050 1050
  */
1051
-function getpaid_duplicate_invoice( $old_invoice ) {
1051
+function getpaid_duplicate_invoice($old_invoice) {
1052 1052
 
1053 1053
     // Create the new invoice.
1054 1054
     $invoice = new WPInv_Invoice();
@@ -1109,126 +1109,126 @@  discard block
 block discarded – undo
1109 1109
  * @param WPInv_Invoice $invoice
1110 1110
  * @return array
1111 1111
  */
1112
-function getpaid_get_invoice_meta( $invoice ) {
1112
+function getpaid_get_invoice_meta($invoice) {
1113 1113
 
1114 1114
     // Load the invoice meta.
1115 1115
     $meta = array(
1116 1116
 
1117 1117
         'number' => array(
1118 1118
             'label' => sprintf(
1119
-                __( '%s Number', 'invoicing' ),
1120
-                ucfirst( $invoice->get_type() )
1119
+                __('%s Number', 'invoicing'),
1120
+                ucfirst($invoice->get_type())
1121 1121
             ),
1122
-            'value' => sanitize_text_field( $invoice->get_number() ),
1122
+            'value' => sanitize_text_field($invoice->get_number()),
1123 1123
         ),
1124 1124
 
1125 1125
         'status' => array(
1126 1126
             'label' => sprintf(
1127
-                __( '%s Status', 'invoicing' ),
1128
-                ucfirst( $invoice->get_type() )
1127
+                __('%s Status', 'invoicing'),
1128
+                ucfirst($invoice->get_type())
1129 1129
             ),
1130 1130
             'value' => $invoice->get_status_label_html(),
1131 1131
         ),
1132 1132
 
1133 1133
         'date' => array(
1134 1134
             'label' => sprintf(
1135
-                __( '%s Date', 'invoicing' ),
1136
-                ucfirst( $invoice->get_type() )
1135
+                __('%s Date', 'invoicing'),
1136
+                ucfirst($invoice->get_type())
1137 1137
             ),
1138
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
1138
+            'value' => getpaid_format_date($invoice->get_created_date()),
1139 1139
         ),
1140 1140
 
1141 1141
         'date_paid' => array(
1142
-            'label' => __( 'Paid On', 'invoicing' ),
1143
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
1142
+            'label' => __('Paid On', 'invoicing'),
1143
+            'value' => getpaid_format_date($invoice->get_completed_date()),
1144 1144
         ),
1145 1145
 
1146 1146
         'gateway'   => array(
1147
-            'label' => __( 'Payment Method', 'invoicing' ),
1148
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
1147
+            'label' => __('Payment Method', 'invoicing'),
1148
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
1149 1149
         ),
1150 1150
 
1151 1151
         'transaction_id' => array(
1152
-            'label' => __( 'Transaction ID', 'invoicing' ),
1153
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
1152
+            'label' => __('Transaction ID', 'invoicing'),
1153
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
1154 1154
         ),
1155 1155
 
1156 1156
         'due_date'  => array(
1157
-            'label' => __( 'Due Date', 'invoicing' ),
1158
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
1157
+            'label' => __('Due Date', 'invoicing'),
1158
+            'value' => getpaid_format_date($invoice->get_due_date()),
1159 1159
         ),
1160 1160
 
1161 1161
         'vat_number' => array(
1162 1162
             'label' => sprintf(
1163
-                __( '%s Number', 'invoicing' ),
1163
+                __('%s Number', 'invoicing'),
1164 1164
                 getpaid_tax()->get_vat_name()
1165 1165
             ),
1166
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
1166
+            'value' => sanitize_text_field($invoice->get_vat_number()),
1167 1167
         ),
1168 1168
 
1169 1169
     );
1170 1170
 
1171 1171
     // If it is not paid, remove the date of payment.
1172
-    if ( ! $invoice->is_paid() ) {
1173
-        unset( $meta[ 'date_paid' ] );
1174
-        unset( $meta[ 'transaction_id' ] );
1172
+    if (!$invoice->is_paid()) {
1173
+        unset($meta['date_paid']);
1174
+        unset($meta['transaction_id']);
1175 1175
     }
1176 1176
 
1177
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
1178
-        unset( $meta[ 'gateway' ] );
1177
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
1178
+        unset($meta['gateway']);
1179 1179
     }
1180 1180
 
1181 1181
     // Only display the due date if due dates are enabled.
1182
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
1183
-        unset( $meta[ 'due_date' ] );
1182
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
1183
+        unset($meta['due_date']);
1184 1184
     }
1185 1185
 
1186 1186
     // Only display the vat number if taxes are enabled.
1187
-    if ( ! wpinv_use_taxes() ) {
1188
-        unset( $meta[ 'vat_number' ] );
1187
+    if (!wpinv_use_taxes()) {
1188
+        unset($meta['vat_number']);
1189 1189
     }
1190 1190
 
1191
-    if ( $invoice->is_recurring() ) {
1191
+    if ($invoice->is_recurring()) {
1192 1192
 
1193 1193
         // Link to the parent invoice.
1194
-        if ( $invoice->is_renewal() ) {
1194
+        if ($invoice->is_renewal()) {
1195 1195
 
1196
-            $meta[ 'parent' ] = array(
1196
+            $meta['parent'] = array(
1197 1197
 
1198 1198
                 'label' => sprintf(
1199
-                    __( 'Parent %s', 'invoicing' ),
1200
-                    ucfirst( $invoice->get_type() )
1199
+                    __('Parent %s', 'invoicing'),
1200
+                    ucfirst($invoice->get_type())
1201 1201
                 ),
1202 1202
 
1203
-                'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
1203
+                'value' => wpinv_invoice_link($invoice->get_parent_id()),
1204 1204
 
1205 1205
             );
1206 1206
 
1207 1207
         }
1208 1208
 
1209
-        $subscription = wpinv_get_subscription( $invoice );
1209
+        $subscription = wpinv_get_subscription($invoice);
1210 1210
 
1211
-        if ( ! empty ( $subscription ) ) {
1211
+        if (!empty ($subscription)) {
1212 1212
 
1213 1213
             // Display the renewal date.
1214
-            if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) {
1214
+            if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) {
1215 1215
 
1216
-                $meta[ 'renewal_date' ] = array(
1216
+                $meta['renewal_date'] = array(
1217 1217
 
1218
-                    'label' => __( 'Renews On', 'invoicing' ),
1219
-                    'value' => getpaid_format_date( $subscription->get_expiration() ),
1218
+                    'label' => __('Renews On', 'invoicing'),
1219
+                    'value' => getpaid_format_date($subscription->get_expiration()),
1220 1220
         
1221 1221
                 );
1222 1222
 
1223 1223
             }
1224 1224
 
1225
-            if ( $invoice->is_parent() ) {
1225
+            if ($invoice->is_parent()) {
1226 1226
 
1227 1227
                 // Display the recurring amount.
1228
-                $meta[ 'recurring_total' ] = array(
1228
+                $meta['recurring_total'] = array(
1229 1229
 
1230
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
1231
-                    'value' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ),
1230
+                    'label' => __('Recurring Amount', 'invoicing'),
1231
+                    'value' => wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $invoice->get_currency()),
1232 1232
         
1233 1233
                 );
1234 1234
 
@@ -1238,15 +1238,15 @@  discard block
 block discarded – undo
1238 1238
     }
1239 1239
 
1240 1240
     // Add the invoice total to the meta.
1241
-    $meta[ 'invoice_total' ] = array(
1241
+    $meta['invoice_total'] = array(
1242 1242
 
1243
-        'label' => __( 'Total Amount', 'invoicing' ),
1244
-        'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ),
1243
+        'label' => __('Total Amount', 'invoicing'),
1244
+        'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()),
1245 1245
 
1246 1246
     );
1247 1247
 
1248 1248
     // Provide a way for third party plugins to filter the meta.
1249
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
1249
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
1250 1250
 
1251 1251
     return $meta;
1252 1252
 
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Are we supporting item quantities?
@@ -21,25 +21,25 @@  discard block
 block discarded – undo
21 21
 function wpinv_get_ip() {
22 22
     $ip = $_SERVER['REMOTE_ADDR'];
23 23
 
24
-    if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
25 25
         //Check ip from share internet.
26 26
         $ip = $_SERVER['HTTP_CLIENT_IP'];
27
-    } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
27
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
28 28
         //Check ip is pass from proxy.
29 29
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
30 30
     }
31 31
 
32
-    return apply_filters( 'wpinv_get_ip', $ip );
32
+    return apply_filters('wpinv_get_ip', $ip);
33 33
 }
34 34
 
35 35
 function wpinv_get_user_agent() {
36
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
37
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
36
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
37
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
38 38
     } else {
39 39
         $user_agent = '';
40 40
     }
41 41
 
42
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
42
+    return apply_filters('wpinv_get_user_agent', $user_agent);
43 43
 }
44 44
 
45 45
 /**
@@ -47,27 +47,27 @@  discard block
 block discarded – undo
47 47
  * 
48 48
  * @param string $amount The amount to sanitize.
49 49
  */
50
-function wpinv_sanitize_amount( $amount ) {
50
+function wpinv_sanitize_amount($amount) {
51 51
 
52 52
     // Format decimals.
53
-    $amount = str_replace( wpinv_decimal_separator(), '.', $amount );
53
+    $amount = str_replace(wpinv_decimal_separator(), '.', $amount);
54 54
 
55 55
     // Remove thousands.
56
-    $amount = str_replace( wpinv_thousands_separator(), '', $amount );
56
+    $amount = str_replace(wpinv_thousands_separator(), '', $amount);
57 57
 
58 58
     // Cast the remaining to a float.
59
-    return (float) preg_replace( '/[^0-9\.\-]/', '', $amount );
59
+    return (float) preg_replace('/[^0-9\.\-]/', '', $amount);
60 60
 
61 61
 }
62 62
 
63
-function wpinv_round_amount( $amount, $decimals = NULL ) {
64
-    if ( $decimals === NULL ) {
63
+function wpinv_round_amount($amount, $decimals = NULL) {
64
+    if ($decimals === NULL) {
65 65
         $decimals = wpinv_decimals();
66 66
     }
67 67
     
68
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
68
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
69 69
 
70
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
70
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
71 71
 }
72 72
 
73 73
 /**
@@ -79,32 +79,32 @@  discard block
 block discarded – undo
79 79
  * @param string|WPInv_Invoice $invoice The invoice object|post type|type
80 80
  * @return array
81 81
  */
82
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
82
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
83 83
 
84 84
 	$invoice_statuses = array(
85
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
86
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
87
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
88
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
89
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
90
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
91
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
92
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
85
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
86
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
87
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
88
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
89
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
90
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
91
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
92
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
93 93
     );
94 94
 
95
-    if ( $draft ) {
96
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
95
+    if ($draft) {
96
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
97 97
     }
98 98
 
99
-    if ( $trashed ) {
100
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
99
+    if ($trashed) {
100
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
101 101
     }
102 102
 
103
-    if ( $invoice instanceof WPInv_Invoice ) {
103
+    if ($invoice instanceof WPInv_Invoice) {
104 104
         $invoice = $invoice->get_post_type();
105 105
     }
106 106
 
107
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
107
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
108 108
 }
109 109
 
110 110
 /**
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
  * @param string $status The raw status
114 114
  * @param string|WPInv_Invoice $invoice The invoice object|post type|type
115 115
  */
116
-function wpinv_status_nicename( $status, $invoice = false ) {
117
-    $statuses = wpinv_get_invoice_statuses( true, true, $invoice );
118
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : $status;
116
+function wpinv_status_nicename($status, $invoice = false) {
117
+    $statuses = wpinv_get_invoice_statuses(true, true, $invoice);
118
+    $status   = isset($statuses[$status]) ? $statuses[$status] : $status;
119 119
 
120
-    return sanitize_text_field( $status );
120
+    return sanitize_text_field($status);
121 121
 }
122 122
 
123 123
 /**
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
  * 
126 126
  * @param string $current
127 127
  */
128
-function wpinv_get_currency( $current = '' ) {
128
+function wpinv_get_currency($current = '') {
129 129
 
130
-    if ( empty( $current ) ) {
131
-        $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) );
130
+    if (empty($current)) {
131
+        $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD'));
132 132
     }
133 133
 
134
-    return trim( strtoupper( $current ) );
134
+    return trim(strtoupper($current));
135 135
 }
136 136
 
137 137
 /**
@@ -139,25 +139,25 @@  discard block
 block discarded – undo
139 139
  * 
140 140
  * @param string|null $currency The currency code. Defaults to the default currency.
141 141
  */
142
-function wpinv_currency_symbol( $currency = null ) {
142
+function wpinv_currency_symbol($currency = null) {
143 143
 
144 144
     // Prepare the currency.
145
-    $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency );
145
+    $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency);
146 146
 
147 147
     // Fetch all symbols.
148 148
     $symbols = wpinv_get_currency_symbols();
149 149
 
150 150
     // Fetch this currencies symbol.
151
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
151
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
152 152
 
153 153
     // Filter the symbol.
154
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
154
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
155 155
 }
156 156
 
157 157
 function wpinv_currency_position() {
158
-    $position = wpinv_get_option( 'currency_position', 'left' );
158
+    $position = wpinv_get_option('currency_position', 'left');
159 159
     
160
-    return apply_filters( 'wpinv_currency_position', $position );
160
+    return apply_filters('wpinv_currency_position', $position);
161 161
 }
162 162
 
163 163
 /**
@@ -165,13 +165,13 @@  discard block
 block discarded – undo
165 165
  * 
166 166
  * @param $string|null $current
167 167
  */
168
-function wpinv_thousands_separator( $current = null ) {
168
+function wpinv_thousands_separator($current = null) {
169 169
 
170
-    if ( null == $current ) {
171
-        $current = wpinv_get_option( 'thousands_separator', '.' );
170
+    if (null == $current) {
171
+        $current = wpinv_get_option('thousands_separator', '.');
172 172
     }
173 173
 
174
-    return trim( $current );
174
+    return trim($current);
175 175
 }
176 176
 
177 177
 /**
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
  * 
180 180
  * @param $string|null $current
181 181
  */
182
-function wpinv_decimal_separator( $current = null ) {
182
+function wpinv_decimal_separator($current = null) {
183 183
 
184
-    if ( null == $current ) {
185
-        $current = wpinv_get_option( 'decimal_separator', '.' );
184
+    if (null == $current) {
185
+        $current = wpinv_get_option('decimal_separator', '.');
186 186
     }
187 187
     
188
-    return trim( $current );
188
+    return trim($current);
189 189
 }
190 190
 
191 191
 /**
@@ -193,27 +193,27 @@  discard block
 block discarded – undo
193 193
  * 
194 194
  * @param $string|null $current
195 195
  */
196
-function wpinv_decimals( $current = null ) {
196
+function wpinv_decimals($current = null) {
197 197
 
198
-    if ( null == $current ) {
199
-        $current = wpinv_get_option( 'decimals', 2 );
198
+    if (null == $current) {
199
+        $current = wpinv_get_option('decimals', 2);
200 200
     }
201 201
     
202
-    return absint( $current );
202
+    return absint($current);
203 203
 }
204 204
 
205 205
 /**
206 206
  * Retrieves a list of all supported currencies.
207 207
  */
208 208
 function wpinv_get_currencies() {
209
-    return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) );
209
+    return apply_filters('wpinv_currencies', wpinv_get_data('currencies'));
210 210
 }
211 211
 
212 212
 /**
213 213
  * Retrieves a list of all currency symbols.
214 214
  */
215 215
 function wpinv_get_currency_symbols() {
216
-    return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) );
216
+    return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols'));
217 217
 }
218 218
 
219 219
 /**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	$currency_pos = wpinv_currency_position();
226 226
 	$format       = '%1$s%2$s';
227 227
 
228
-	switch ( $currency_pos ) {
228
+	switch ($currency_pos) {
229 229
 		case 'left':
230 230
 			$format = '%1$s%2$s';
231 231
 			break;
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 			break;
241 241
 	}
242 242
 
243
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
243
+	return apply_filters('getpaid_price_format', $format, $currency_pos);
244 244
 }
245 245
 
246 246
 /**
@@ -250,25 +250,25 @@  discard block
 block discarded – undo
250 250
  * @param  string $currency Currency.
251 251
  * @return string
252 252
  */
253
-function wpinv_price( $amount = 0, $currency = '' ) {
253
+function wpinv_price($amount = 0, $currency = '') {
254 254
 
255 255
     // Backwards compatibility.
256
-    $amount             = floatval( wpinv_sanitize_amount( $amount ) );
256
+    $amount             = floatval(wpinv_sanitize_amount($amount));
257 257
 
258 258
     // Prepare variables.
259
-    $currency           = wpinv_get_currency( $currency );
259
+    $currency           = wpinv_get_currency($currency);
260 260
     $amount             = (float) $amount;
261 261
     $unformatted_amount = $amount;
262 262
     $negative           = $amount < 0;
263
-    $amount             = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) );
264
-    $amount             = wpinv_format_amount( $amount );
263
+    $amount             = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount));
264
+    $amount             = wpinv_format_amount($amount);
265 265
 
266 266
     // Format the amount.
267 267
     $format             = getpaid_get_price_format();
268
-    $formatted_amount   = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount );
268
+    $formatted_amount   = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount);
269 269
 
270 270
     // Filter the formatting.
271
-    return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount );
271
+    return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount);
272 272
 }
273 273
 
274 274
 /**
@@ -279,33 +279,33 @@  discard block
 block discarded – undo
279 279
  * @param  bool     $calculate Whether or not to apply separators.
280 280
  * @return string
281 281
  */
282
-function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) {
282
+function wpinv_format_amount($amount, $decimals = null, $calculate = false) {
283 283
     $thousands_sep = wpinv_thousands_separator();
284 284
     $decimal_sep   = wpinv_decimal_separator();
285
-    $decimals      = wpinv_decimals( $decimals );
285
+    $decimals      = wpinv_decimals($decimals);
286 286
 
287 287
     // Format decimals.
288
-    $amount = str_replace( $decimal_sep, '.', $amount );
288
+    $amount = str_replace($decimal_sep, '.', $amount);
289 289
 
290 290
     // Remove thousands.
291
-    $amount = str_replace( $thousands_sep, '', $amount );
291
+    $amount = str_replace($thousands_sep, '', $amount);
292 292
 
293 293
     // Cast the remaining to a float.
294
-    $amount = floatval( $amount );
294
+    $amount = floatval($amount);
295 295
 
296
-    if ( $calculate ) {
296
+    if ($calculate) {
297 297
         return $amount;
298 298
     }
299 299
 
300 300
     // Fomart the amount.
301
-    return number_format( $amount, $decimals, $decimal_sep, $thousands_sep );
301
+    return number_format($amount, $decimals, $decimal_sep, $thousands_sep);
302 302
 }
303 303
 
304
-function wpinv_sanitize_key( $key ) {
304
+function wpinv_sanitize_key($key) {
305 305
     $raw_key = $key;
306
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
306
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
307 307
 
308
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
308
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
309 309
 }
310 310
 
311 311
 /**
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
  * 
314 314
  * @param $str the file whose extension should be retrieved.
315 315
  */
316
-function wpinv_get_file_extension( $str ) {
317
-    $filetype = wp_check_filetype( $str );
316
+function wpinv_get_file_extension($str) {
317
+    $filetype = wp_check_filetype($str);
318 318
     return $filetype['ext'];
319 319
 }
320 320
 
@@ -323,16 +323,16 @@  discard block
 block discarded – undo
323 323
  * 
324 324
  * @param string $string
325 325
  */
326
-function wpinv_string_is_image_url( $string ) {
327
-    $extension = strtolower( wpinv_get_file_extension( $string ) );
328
-    return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true );
326
+function wpinv_string_is_image_url($string) {
327
+    $extension = strtolower(wpinv_get_file_extension($string));
328
+    return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true);
329 329
 }
330 330
 
331 331
 /**
332 332
  * Returns the current URL.
333 333
  */
334 334
 function wpinv_get_current_page_url() {
335
-    return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
335
+    return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
336 336
 }
337 337
 
338 338
 /**
@@ -342,46 +342,46 @@  discard block
 block discarded – undo
342 342
  * @param string $name  Constant name.
343 343
  * @param mixed  $value Value.
344 344
  */
345
-function getpaid_maybe_define_constant( $name, $value ) {
346
-	if ( ! defined( $name ) ) {
347
-		define( $name, $value );
345
+function getpaid_maybe_define_constant($name, $value) {
346
+	if (!defined($name)) {
347
+		define($name, $value);
348 348
 	}
349 349
 }
350 350
 
351 351
 function wpinv_get_php_arg_separator_output() {
352
-	return ini_get( 'arg_separator.output' );
352
+	return ini_get('arg_separator.output');
353 353
 }
354 354
 
355
-function wpinv_rgb_from_hex( $color ) {
356
-    $color = str_replace( '#', '', $color );
355
+function wpinv_rgb_from_hex($color) {
356
+    $color = str_replace('#', '', $color);
357 357
 
358 358
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
359
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
360
-    if ( empty( $color ) ) {
359
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
360
+    if (empty($color)) {
361 361
         return NULL;
362 362
     }
363 363
 
364
-    $color = str_split( $color );
364
+    $color = str_split($color);
365 365
 
366 366
     $rgb      = array();
367
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
368
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
369
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
367
+    $rgb['R'] = hexdec($color[0] . $color[1]);
368
+    $rgb['G'] = hexdec($color[2] . $color[3]);
369
+    $rgb['B'] = hexdec($color[4] . $color[5]);
370 370
 
371 371
     return $rgb;
372 372
 }
373 373
 
374
-function wpinv_hex_darker( $color, $factor = 30 ) {
375
-    $base  = wpinv_rgb_from_hex( $color );
374
+function wpinv_hex_darker($color, $factor = 30) {
375
+    $base  = wpinv_rgb_from_hex($color);
376 376
     $color = '#';
377 377
 
378
-    foreach ( $base as $k => $v ) {
378
+    foreach ($base as $k => $v) {
379 379
         $amount      = $v / 100;
380
-        $amount      = round( $amount * $factor );
380
+        $amount      = round($amount * $factor);
381 381
         $new_decimal = $v - $amount;
382 382
 
383
-        $new_hex_component = dechex( $new_decimal );
384
-        if ( strlen( $new_hex_component ) < 2 ) {
383
+        $new_hex_component = dechex($new_decimal);
384
+        if (strlen($new_hex_component) < 2) {
385 385
             $new_hex_component = "0" . $new_hex_component;
386 386
         }
387 387
         $color .= $new_hex_component;
@@ -390,18 +390,18 @@  discard block
 block discarded – undo
390 390
     return $color;
391 391
 }
392 392
 
393
-function wpinv_hex_lighter( $color, $factor = 30 ) {
394
-    $base  = wpinv_rgb_from_hex( $color );
393
+function wpinv_hex_lighter($color, $factor = 30) {
394
+    $base  = wpinv_rgb_from_hex($color);
395 395
     $color = '#';
396 396
 
397
-    foreach ( $base as $k => $v ) {
397
+    foreach ($base as $k => $v) {
398 398
         $amount      = 255 - $v;
399 399
         $amount      = $amount / 100;
400
-        $amount      = round( $amount * $factor );
400
+        $amount      = round($amount * $factor);
401 401
         $new_decimal = $v + $amount;
402 402
 
403
-        $new_hex_component = dechex( $new_decimal );
404
-        if ( strlen( $new_hex_component ) < 2 ) {
403
+        $new_hex_component = dechex($new_decimal);
404
+        if (strlen($new_hex_component) < 2) {
405 405
             $new_hex_component = "0" . $new_hex_component;
406 406
         }
407 407
         $color .= $new_hex_component;
@@ -410,22 +410,22 @@  discard block
 block discarded – undo
410 410
     return $color;
411 411
 }
412 412
 
413
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
414
-    $hex = str_replace( '#', '', $color );
413
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
414
+    $hex = str_replace('#', '', $color);
415 415
 
416
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
417
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
418
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
416
+    $c_r = hexdec(substr($hex, 0, 2));
417
+    $c_g = hexdec(substr($hex, 2, 2));
418
+    $c_b = hexdec(substr($hex, 4, 2));
419 419
 
420
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
420
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
421 421
 
422 422
     return $brightness > 155 ? $dark : $light;
423 423
 }
424 424
 
425
-function wpinv_format_hex( $hex ) {
426
-    $hex = trim( str_replace( '#', '', $hex ) );
425
+function wpinv_format_hex($hex) {
426
+    $hex = trim(str_replace('#', '', $hex));
427 427
 
428
-    if ( strlen( $hex ) == 3 ) {
428
+    if (strlen($hex) == 3) {
429 429
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
430 430
     }
431 431
 
@@ -445,12 +445,12 @@  discard block
 block discarded – undo
445 445
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
446 446
  * @return string
447 447
  */
448
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
449
-    if ( function_exists( 'mb_strimwidth' ) ) {
450
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
448
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
449
+    if (function_exists('mb_strimwidth')) {
450
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
451 451
     }
452 452
     
453
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
453
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
454 454
 }
455 455
 
456 456
 /**
@@ -462,28 +462,28 @@  discard block
 block discarded – undo
462 462
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
463 463
  * @return int Returns the number of characters in string.
464 464
  */
465
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
466
-    if ( function_exists( 'mb_strlen' ) ) {
467
-        return mb_strlen( $str, $encoding );
465
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
466
+    if (function_exists('mb_strlen')) {
467
+        return mb_strlen($str, $encoding);
468 468
     }
469 469
         
470
-    return strlen( $str );
470
+    return strlen($str);
471 471
 }
472 472
 
473
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
474
-    if ( function_exists( 'mb_strtolower' ) ) {
475
-        return mb_strtolower( $str, $encoding );
473
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
474
+    if (function_exists('mb_strtolower')) {
475
+        return mb_strtolower($str, $encoding);
476 476
     }
477 477
     
478
-    return strtolower( $str );
478
+    return strtolower($str);
479 479
 }
480 480
 
481
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
482
-    if ( function_exists( 'mb_strtoupper' ) ) {
483
-        return mb_strtoupper( $str, $encoding );
481
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
482
+    if (function_exists('mb_strtoupper')) {
483
+        return mb_strtoupper($str, $encoding);
484 484
     }
485 485
     
486
-    return strtoupper( $str );
486
+    return strtoupper($str);
487 487
 }
488 488
 
489 489
 /**
@@ -497,12 +497,12 @@  discard block
 block discarded – undo
497 497
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
498 498
  * @return int Returns the position of the first occurrence of search in the string.
499 499
  */
500
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
501
-    if ( function_exists( 'mb_strpos' ) ) {
502
-        return mb_strpos( $str, $find, $offset, $encoding );
500
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
501
+    if (function_exists('mb_strpos')) {
502
+        return mb_strpos($str, $find, $offset, $encoding);
503 503
     }
504 504
         
505
-    return strpos( $str, $find, $offset );
505
+    return strpos($str, $find, $offset);
506 506
 }
507 507
 
508 508
 /**
@@ -516,12 +516,12 @@  discard block
 block discarded – undo
516 516
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
517 517
  * @return int Returns the position of the last occurrence of search.
518 518
  */
519
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
520
-    if ( function_exists( 'mb_strrpos' ) ) {
521
-        return mb_strrpos( $str, $find, $offset, $encoding );
519
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
520
+    if (function_exists('mb_strrpos')) {
521
+        return mb_strrpos($str, $find, $offset, $encoding);
522 522
     }
523 523
         
524
-    return strrpos( $str, $find, $offset );
524
+    return strrpos($str, $find, $offset);
525 525
 }
526 526
 
527 527
 /**
@@ -536,16 +536,16 @@  discard block
 block discarded – undo
536 536
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
537 537
  * @return string
538 538
  */
539
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
540
-    if ( function_exists( 'mb_substr' ) ) {
541
-        if ( $length === null ) {
542
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
539
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
540
+    if (function_exists('mb_substr')) {
541
+        if ($length === null) {
542
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
543 543
         } else {
544
-            return mb_substr( $str, $start, $length, $encoding );
544
+            return mb_substr($str, $start, $length, $encoding);
545 545
         }
546 546
     }
547 547
         
548
-    return substr( $str, $start, $length );
548
+    return substr($str, $start, $length);
549 549
 }
550 550
 
551 551
 /**
@@ -557,48 +557,48 @@  discard block
 block discarded – undo
557 557
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
558 558
  * @return string The width of string.
559 559
  */
560
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
561
-    if ( function_exists( 'mb_strwidth' ) ) {
562
-        return mb_strwidth( $str, $encoding );
560
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
561
+    if (function_exists('mb_strwidth')) {
562
+        return mb_strwidth($str, $encoding);
563 563
     }
564 564
     
565
-    return wpinv_utf8_strlen( $str, $encoding );
565
+    return wpinv_utf8_strlen($str, $encoding);
566 566
 }
567 567
 
568
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
569
-    if ( function_exists( 'mb_strlen' ) ) {
570
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
568
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
569
+    if (function_exists('mb_strlen')) {
570
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
571 571
         $str_end = "";
572 572
         
573
-        if ( $lower_str_end ) {
574
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
573
+        if ($lower_str_end) {
574
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
575 575
         } else {
576
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
576
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
577 577
         }
578 578
 
579 579
         return $first_letter . $str_end;
580 580
     }
581 581
     
582
-    return ucfirst( $str );
582
+    return ucfirst($str);
583 583
 }
584 584
 
585
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
586
-    if ( function_exists( 'mb_convert_case' ) ) {
587
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
585
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
586
+    if (function_exists('mb_convert_case')) {
587
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
588 588
     }
589 589
     
590
-    return ucwords( $str );
590
+    return ucwords($str);
591 591
 }
592 592
 
593
-function wpinv_period_in_days( $period, $unit ) {
594
-    $period = absint( $period );
593
+function wpinv_period_in_days($period, $unit) {
594
+    $period = absint($period);
595 595
     
596
-    if ( $period > 0 ) {
597
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
596
+    if ($period > 0) {
597
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
598 598
             $period = $period * 7;
599
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
599
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
600 600
             $period = $period * 30;
601
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
601
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
602 602
             $period = $period * 365;
603 603
         }
604 604
     }
@@ -606,14 +606,14 @@  discard block
 block discarded – undo
606 606
     return $period;
607 607
 }
608 608
 
609
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
610
-    if ( function_exists( 'cal_days_in_month' ) ) {
611
-        return cal_days_in_month( $calendar, $month, $year );
609
+function wpinv_cal_days_in_month($calendar, $month, $year) {
610
+    if (function_exists('cal_days_in_month')) {
611
+        return cal_days_in_month($calendar, $month, $year);
612 612
     }
613 613
 
614 614
     // Fallback in case the calendar extension is not loaded in PHP
615 615
     // Only supports Gregorian calendar
616
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
616
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
617 617
 }
618 618
 
619 619
 /**
@@ -624,12 +624,12 @@  discard block
 block discarded – undo
624 624
  *
625 625
  * @return string
626 626
  */
627
-function wpi_help_tip( $tip, $allow_html = false ) {
627
+function wpi_help_tip($tip, $allow_html = false) {
628 628
 
629
-    if ( $allow_html ) {
630
-        $tip = wpi_sanitize_tooltip( $tip );
629
+    if ($allow_html) {
630
+        $tip = wpi_sanitize_tooltip($tip);
631 631
     } else {
632
-        $tip = esc_attr( $tip );
632
+        $tip = esc_attr($tip);
633 633
     }
634 634
 
635 635
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -643,8 +643,8 @@  discard block
 block discarded – undo
643 643
  * @param string $var
644 644
  * @return string
645 645
  */
646
-function wpi_sanitize_tooltip( $var ) {
647
-    return wp_kses( html_entity_decode( $var ), array(
646
+function wpi_sanitize_tooltip($var) {
647
+    return wp_kses(html_entity_decode($var), array(
648 648
         'br'     => array(),
649 649
         'em'     => array(),
650 650
         'strong' => array(),
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
         'li'     => array(),
656 656
         'ol'     => array(),
657 657
         'p'      => array(),
658
-    ) );
658
+    ));
659 659
 }
660 660
 
661 661
 /**
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
  */
666 666
 function wpinv_get_screen_ids() {
667 667
 
668
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
668
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
669 669
 
670 670
     $screen_ids = array(
671 671
         'toplevel_page_' . $screen_id,
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
         'invoicing_page_wpi-addons',
684 684
     );
685 685
 
686
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
686
+    return apply_filters('wpinv_screen_ids', $screen_ids);
687 687
 }
688 688
 
689 689
 /**
@@ -694,14 +694,14 @@  discard block
 block discarded – undo
694 694
  * @param array|string $list List of values.
695 695
  * @return array Sanitized array of values.
696 696
  */
697
-function wpinv_parse_list( $list ) {
697
+function wpinv_parse_list($list) {
698 698
 
699
-    if ( empty( $list ) ) {
699
+    if (empty($list)) {
700 700
         $list = array();
701 701
     }
702 702
 
703
-	if ( ! is_array( $list ) ) {
704
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
703
+	if (!is_array($list)) {
704
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
705 705
 	}
706 706
 
707 707
 	return $list;
@@ -715,16 +715,16 @@  discard block
 block discarded – undo
715 715
  * @param string $key Type of data to fetch.
716 716
  * @return mixed Fetched data.
717 717
  */
718
-function wpinv_get_data( $key ) {
718
+function wpinv_get_data($key) {
719 719
 
720 720
     // Try fetching it from the cache.
721
-    $data = wp_cache_get( "wpinv-data-$key", 'wpinv' );
722
-    if( $data ) {
721
+    $data = wp_cache_get("wpinv-data-$key", 'wpinv');
722
+    if ($data) {
723 723
         return $data;
724 724
     }
725 725
 
726
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
727
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
726
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
727
+	wp_cache_set("wpinv-data-$key", $data, 'wpinv');
728 728
 
729 729
 	return $data;
730 730
 }
@@ -738,10 +738,10 @@  discard block
 block discarded – undo
738 738
  * @param bool $first_empty Whether or not the first item in the list should be empty
739 739
  * @return mixed Fetched data.
740 740
  */
741
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
741
+function wpinv_maybe_add_empty_option($options, $first_empty) {
742 742
 
743
-    if ( ! empty( $options ) && $first_empty ) {
744
-        return array_merge( array( '' => '' ), $options );
743
+    if (!empty($options) && $first_empty) {
744
+        return array_merge(array('' => ''), $options);
745 745
     }
746 746
     return $options;
747 747
 
@@ -753,21 +753,21 @@  discard block
 block discarded – undo
753 753
  * @param mixed $var Data to sanitize.
754 754
  * @return string|array
755 755
  */
756
-function wpinv_clean( $var ) {
756
+function wpinv_clean($var) {
757 757
 
758
-	if ( is_array( $var ) ) {
759
-		return array_map( 'wpinv_clean', $var );
758
+	if (is_array($var)) {
759
+		return array_map('wpinv_clean', $var);
760 760
     }
761 761
 
762
-    if ( is_object( $var ) ) {
763
-		$object_vars = get_object_vars( $var );
764
-		foreach ( $object_vars as $property_name => $property_value ) {
765
-			$var->$property_name = wpinv_clean( $property_value );
762
+    if (is_object($var)) {
763
+		$object_vars = get_object_vars($var);
764
+		foreach ($object_vars as $property_name => $property_value) {
765
+			$var->$property_name = wpinv_clean($property_value);
766 766
         }
767 767
         return $var;
768 768
 	}
769 769
     
770
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
770
+    return is_string($var) ? sanitize_text_field($var) : $var;
771 771
 }
772 772
 
773 773
 /**
@@ -776,43 +776,43 @@  discard block
 block discarded – undo
776 776
  * @param string $str Data to convert.
777 777
  * @return string|array
778 778
  */
779
-function getpaid_convert_price_string_to_options( $str ) {
779
+function getpaid_convert_price_string_to_options($str) {
780 780
 
781
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
782
-    $options     = array();
781
+	$raw_options = array_map('trim', explode(',', $str));
782
+    $options = array();
783 783
 
784
-    foreach ( $raw_options as $option ) {
784
+    foreach ($raw_options as $option) {
785 785
 
786
-        if ( '' == $option ) {
786
+        if ('' == $option) {
787 787
             continue;
788 788
         }
789 789
 
790
-        $option = array_map( 'trim', explode( '|', $option ) );
790
+        $option = array_map('trim', explode('|', $option));
791 791
 
792 792
         $price = null;
793 793
         $label = null;
794 794
 
795
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
796
-            $label  = $option[0];
795
+        if (isset($option[0]) && '' != $option[0]) {
796
+            $label = $option[0];
797 797
         }
798 798
 
799
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
799
+        if (isset($option[1]) && '' != $option[1]) {
800 800
             $price = $option[1];
801 801
         }
802 802
 
803
-        if ( ! isset( $price ) ) {
803
+        if (!isset($price)) {
804 804
             $price = $label;
805 805
         }
806 806
 
807
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
807
+        if (!isset($price) || !is_numeric($price)) {
808 808
             continue;
809 809
         }
810 810
 
811
-        if ( ! isset( $label ) ) {
811
+        if (!isset($label)) {
812 812
             $label = $price;
813 813
         }
814 814
 
815
-        $options[ $price ] = $label;
815
+        $options[$price] = $label;
816 816
     }
817 817
 
818 818
     return $options;
@@ -821,22 +821,22 @@  discard block
 block discarded – undo
821 821
 /**
822 822
  * Returns the help tip.
823 823
  */
824
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
825
-    $additional_classes = sanitize_html_class( $additional_classes );
826
-    $tip                = esc_attr__( $tip );
824
+function getpaid_get_help_tip($tip, $additional_classes = '') {
825
+    $additional_classes = sanitize_html_class($additional_classes);
826
+    $tip                = esc_attr__($tip);
827 827
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
828 828
 }
829 829
 
830 830
 /**
831 831
  * Formats a date
832 832
  */
833
-function getpaid_format_date( $date ) {
833
+function getpaid_format_date($date) {
834 834
 
835
-    if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) {
835
+    if (empty($date) || $date == '0000-00-00 00:00:00') {
836 836
         return '';
837 837
     }
838 838
 
839
-    return date_i18n( getpaid_date_format(), strtotime( $date ) );
839
+    return date_i18n(getpaid_date_format(), strtotime($date));
840 840
 
841 841
 }
842 842
 
@@ -845,9 +845,9 @@  discard block
 block discarded – undo
845 845
  *
846 846
  * @return string
847 847
  */
848
-function getpaid_format_date_value( $date, $default = "&mdash;" ) {
849
-    $date = getpaid_format_date( $date );
850
-    return empty( $date ) ? $default : $date;
848
+function getpaid_format_date_value($date, $default = "&mdash;") {
849
+    $date = getpaid_format_date($date);
850
+    return empty($date) ? $default : $date;
851 851
 }
852 852
 
853 853
 /**
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
  * @return string
857 857
  */
858 858
 function getpaid_date_format() {
859
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
859
+	return apply_filters('getpaid_date_format', get_option('date_format'));
860 860
 }
861 861
 
862 862
 /**
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
  * @return string
866 866
  */
867 867
 function getpaid_time_format() {
868
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
868
+	return apply_filters('getpaid_time_format', get_option('time_format'));
869 869
 }
870 870
 
871 871
 /**
@@ -875,16 +875,16 @@  discard block
 block discarded – undo
875 875
  * @param  integer $limit Limit size in characters.
876 876
  * @return string
877 877
  */
878
-function getpaid_limit_length( $string, $limit ) {
878
+function getpaid_limit_length($string, $limit) {
879 879
     $str_limit = $limit - 3;
880 880
 
881
-	if ( function_exists( 'mb_strimwidth' ) ) {
882
-		if ( mb_strlen( $string ) > $limit ) {
883
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
881
+	if (function_exists('mb_strimwidth')) {
882
+		if (mb_strlen($string) > $limit) {
883
+			$string = mb_strimwidth($string, 0, $str_limit) . '...';
884 884
 		}
885 885
 	} else {
886
-		if ( strlen( $string ) > $limit ) {
887
-			$string = substr( $string, 0, $str_limit ) . '...';
886
+		if (strlen($string) > $limit) {
887
+			$string = substr($string, 0, $str_limit) . '...';
888 888
 		}
889 889
 	}
890 890
     return $string;
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
  * @since 1.0.19
899 899
  */
900 900
 function getpaid_api() {
901
-    return getpaid()->get( 'api' );
901
+    return getpaid()->get('api');
902 902
 }
903 903
 
904 904
 /**
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
  * @since 1.0.19
909 909
  */
910 910
 function getpaid_post_types() {
911
-    return getpaid()->get( 'post_types' );
911
+    return getpaid()->get('post_types');
912 912
 }
913 913
 
914 914
 /**
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
  * @since 1.0.19
919 919
  */
920 920
 function getpaid_session() {
921
-    return getpaid()->get( 'session' );
921
+    return getpaid()->get('session');
922 922
 }
923 923
 
924 924
 /**
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
  * @since 1.0.19
929 929
  */
930 930
 function getpaid_notes() {
931
-    return getpaid()->get( 'notes' );
931
+    return getpaid()->get('notes');
932 932
 }
933 933
 
934 934
 /**
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
  * @return GetPaid_Admin
938 938
  */
939 939
 function getpaid_admin() {
940
-    return getpaid()->get( 'admin' );
940
+    return getpaid()->get('admin');
941 941
 }
942 942
 
943 943
 /**
@@ -947,8 +947,8 @@  discard block
 block discarded – undo
947 947
  * @param string $base the base url
948 948
  * @return string
949 949
  */
950
-function getpaid_get_authenticated_action_url( $action, $base = false ) {
951
-    return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' );
950
+function getpaid_get_authenticated_action_url($action, $base = false) {
951
+    return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce');
952 952
 }
953 953
 
954 954
 /**
@@ -956,11 +956,11 @@  discard block
 block discarded – undo
956 956
  *
957 957
  * @return string
958 958
  */
959
-function getpaid_get_post_type_label( $post_type, $plural = true ) {
959
+function getpaid_get_post_type_label($post_type, $plural = true) {
960 960
 
961
-    $post_type = get_post_type_object( $post_type );
961
+    $post_type = get_post_type_object($post_type);
962 962
 
963
-    if ( ! is_object( $post_type ) ) {
963
+    if (!is_object($post_type)) {
964 964
         return null;
965 965
     }
966 966
 
Please login to merge, or discard this patch.
templates/invoice-history.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -7,25 +7,25 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Current page.
13
-$current_page   = empty( $_GET[ 'page' ] ) ? 1 : absint( $_GET[ 'page' ] );
13
+$current_page = empty($_GET['page']) ? 1 : absint($_GET['page']);
14 14
 
15 15
 // Fires before displaying user invoices.
16
-do_action( 'wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type );
16
+do_action('wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type);
17 17
 
18 18
 ?>
19 19
 
20
-	<table class="table table-bordered table-hover getpaid-user-invoices <?php echo sanitize_html_class( $post_type ); ?>">
20
+	<table class="table table-bordered table-hover getpaid-user-invoices <?php echo sanitize_html_class($post_type); ?>">
21 21
 
22 22
 
23 23
 		<thead>
24 24
 			<tr>
25 25
 
26
-				<?php foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) : ?>
27
-					<th class="<?php echo sanitize_html_class( $column_id ); ?> <?php echo ( ! empty( $column_name['class'] ) ? sanitize_html_class( $column_name['class'] ) : '');?> border-bottom-0">
28
-						<span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span>
26
+				<?php foreach (wpinv_get_user_invoices_columns($post_type) as $column_id => $column_name) : ?>
27
+					<th class="<?php echo sanitize_html_class($column_id); ?> <?php echo (!empty($column_name['class']) ? sanitize_html_class($column_name['class']) : ''); ?> border-bottom-0">
28
+						<span class="nobr"><?php echo esc_html($column_name['title']); ?></span>
29 29
 					</th>
30 30
 				<?php endforeach; ?>
31 31
 
@@ -35,33 +35,33 @@  discard block
 block discarded – undo
35 35
 
36 36
 
37 37
 		<tbody>
38
-			<?php foreach ( $invoices->invoices as $invoice ) : ?>
38
+			<?php foreach ($invoices->invoices as $invoice) : ?>
39 39
 
40 40
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
41 41
 					<?php
42 42
 
43
-						foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) :
43
+						foreach (wpinv_get_user_invoices_columns($post_type) as $column_id => $column_name) :
44 44
 
45
-							$column_id = sanitize_html_class( $column_id );
46
-							$class     = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] );
45
+							$column_id = sanitize_html_class($column_id);
46
+							$class     = empty($column_name['class']) ? '' : sanitize_html_class($column_name['class']);
47 47
 
48 48
 							echo "<td class='$column_id $class'>";
49
-							switch ( $column_id ) {
49
+							switch ($column_id) {
50 50
 
51 51
 								case 'invoice-number':
52
-									echo wpinv_invoice_link( $invoice );
52
+									echo wpinv_invoice_link($invoice);
53 53
 									break;
54 54
 
55 55
 								case 'created-date':
56
-									echo getpaid_format_date_value( $invoice->get_date_created() );
56
+									echo getpaid_format_date_value($invoice->get_date_created());
57 57
 									break;
58 58
 
59 59
 								case 'payment-date':
60 60
 
61
-									if ( $invoice->needs_payment() ) {
61
+									if ($invoice->needs_payment()) {
62 62
 										echo "&mdash;";
63 63
 									} else {
64
-										echo getpaid_format_date_value( $invoice->get_date_completed() );
64
+										echo getpaid_format_date_value($invoice->get_date_completed());
65 65
 									}
66 66
 
67 67
 									break;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 									break;
73 73
 
74 74
 								case 'invoice-total':
75
-									echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) );
75
+									echo wpinv_price(wpinv_format_amount($invoice->get_total()));
76 76
 
77 77
 									break;
78 78
 
@@ -82,39 +82,39 @@  discard block
 block discarded – undo
82 82
 
83 83
 										'pay'       => array(
84 84
 											'url'   => $invoice->get_checkout_payment_url(),
85
-											'name'  => __( 'Pay Now', 'invoicing' ),
85
+											'name'  => __('Pay Now', 'invoicing'),
86 86
                                             'class' => 'btn-success'
87 87
 										),
88 88
 
89 89
                                         'print'     => array(
90 90
 											'url'   => $invoice->get_view_url(),
91
-											'name'  => __( 'View', 'invoicing' ),
91
+											'name'  => __('View', 'invoicing'),
92 92
                                             'class' => 'btn-secondary',
93 93
                                             'attrs' => 'target="_blank"'
94 94
 										)
95 95
 									);
96 96
 
97
-									if ( ! $invoice->needs_payment() ) {
98
-										unset( $actions['pay'] );
97
+									if (!$invoice->needs_payment()) {
98
+										unset($actions['pay']);
99 99
 									}
100 100
 
101
-									$actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice, $post_type );
101
+									$actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice, $post_type);
102 102
 
103
-									foreach ( $actions as $key => $action ) {
103
+									foreach ($actions as $key => $action) {
104 104
 										$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
105
-										echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
105
+										echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
106 106
 									}
107 107
 
108 108
 									break;
109 109
 
110 110
 								default:
111
-									do_action( "wpinv_user_invoices_column_$column_id", $invoice );
111
+									do_action("wpinv_user_invoices_column_$column_id", $invoice);
112 112
 									break;
113 113
 
114 114
 
115 115
 							}
116 116
 
117
-							do_action( "wpinv_user_invoices_column_after_$column_id", $invoice );
117
+							do_action("wpinv_user_invoices_column_after_$column_id", $invoice);
118 118
 
119 119
 							echo '</td>';
120 120
 
@@ -127,20 +127,20 @@  discard block
 block discarded – undo
127 127
 		</tbody>
128 128
 	</table>
129 129
 
130
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
130
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
131 131
 
132
-	<?php if ( 1 < $invoices->max_num_pages ) : ?>
132
+	<?php if (1 < $invoices->max_num_pages) : ?>
133 133
 		<div class="invoicing-Pagination">
134 134
 			<?php
135 135
 			$big = 999999;
136 136
 
137
-			echo paginate_links( array(
138
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
137
+			echo paginate_links(array(
138
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
139 139
 				'format'  => '?paged=%#%',
140 140
 				'total'   => $invoices->max_num_pages,
141
-			) );
141
+			));
142 142
 			?>
143 143
 		</div>
144 144
 	<?php endif; ?>
145 145
 
146
-<?php do_action( 'wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type  ); ?>
146
+<?php do_action('wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type); ?>
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
     
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -102,36 +102,36 @@  discard block
 block discarded – undo
102 102
             'ip_geolocation'              => true,
103 103
         );
104 104
 
105
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
106
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
107
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
105
+        foreach ($ajax_events as $ajax_event => $nopriv) {
106
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
107
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
108 108
 
109
-            if ( $nopriv ) {
110
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
112
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+            if ($nopriv) {
110
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
113 113
             }
114 114
         }
115 115
     }
116 116
     
117 117
     public static function add_note() {
118
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
118
+        check_ajax_referer('add-invoice-note', '_nonce');
119 119
 
120
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
120
+        if (!wpinv_current_user_can_manage_invoicing()) {
121 121
             die(-1);
122 122
         }
123 123
 
124
-        $post_id   = absint( $_POST['post_id'] );
125
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
126
-        $note_type = sanitize_text_field( $_POST['note_type'] );
124
+        $post_id   = absint($_POST['post_id']);
125
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
126
+        $note_type = sanitize_text_field($_POST['note_type']);
127 127
 
128 128
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
129 129
 
130
-        if ( $post_id > 0 ) {
131
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
130
+        if ($post_id > 0) {
131
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
132 132
 
133
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
134
-                wpinv_get_invoice_note_line_item( $note_id );
133
+            if ($note_id > 0 && !is_wp_error($note_id)) {
134
+                wpinv_get_invoice_note_line_item($note_id);
135 135
             }
136 136
         }
137 137
 
@@ -139,16 +139,16 @@  discard block
 block discarded – undo
139 139
     }
140 140
 
141 141
     public static function delete_note() {
142
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
142
+        check_ajax_referer('delete-invoice-note', '_nonce');
143 143
 
144
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
144
+        if (!wpinv_current_user_can_manage_invoicing()) {
145 145
             die(-1);
146 146
         }
147 147
 
148
-        $note_id = (int)$_POST['note_id'];
148
+        $note_id = (int) $_POST['note_id'];
149 149
 
150
-        if ( $note_id > 0 ) {
151
-            wp_delete_comment( $note_id, true );
150
+        if ($note_id > 0) {
151
+            wp_delete_comment($note_id, true);
152 152
         }
153 153
 
154 154
         die();
@@ -166,34 +166,34 @@  discard block
 block discarded – undo
166 166
     public static function get_billing_details() {
167 167
 
168 168
         // Verify nonce.
169
-        check_ajax_referer( 'wpinv-nonce' );
169
+        check_ajax_referer('wpinv-nonce');
170 170
 
171 171
         // Can the user manage the plugin?
172
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
172
+        if (!wpinv_current_user_can_manage_invoicing()) {
173 173
             die(-1);
174 174
         }
175 175
 
176 176
         // Do we have a user id?
177 177
         $user_id = $_GET['user_id'];
178 178
 
179
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
179
+        if (empty($user_id) || !is_numeric($user_id)) {
180 180
             die(-1);
181 181
         }
182 182
 
183 183
         // Fetch the billing details.
184
-        $billing_details    = wpinv_get_user_address( $user_id );
185
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
184
+        $billing_details    = wpinv_get_user_address($user_id);
185
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
186 186
 
187 187
         // unset the user id and email.
188
-        $to_ignore = array( 'user_id', 'email' );
188
+        $to_ignore = array('user_id', 'email');
189 189
 
190
-        foreach ( $to_ignore as $key ) {
191
-            if ( isset( $billing_details[ $key ] ) ) {
192
-                unset( $billing_details[ $key ] );
190
+        foreach ($to_ignore as $key) {
191
+            if (isset($billing_details[$key])) {
192
+                unset($billing_details[$key]);
193 193
             }
194 194
         }
195 195
 
196
-        wp_send_json_success( $billing_details );
196
+        wp_send_json_success($billing_details);
197 197
 
198 198
     }
199 199
 
@@ -203,47 +203,47 @@  discard block
 block discarded – undo
203 203
     public static function check_new_user_email() {
204 204
 
205 205
         // Verify nonce.
206
-        check_ajax_referer( 'wpinv-nonce' );
206
+        check_ajax_referer('wpinv-nonce');
207 207
 
208 208
         // Can the user manage the plugin?
209
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
209
+        if (!wpinv_current_user_can_manage_invoicing()) {
210 210
             die(-1);
211 211
         }
212 212
 
213 213
         // We need an email address.
214
-        if ( empty( $_GET['email'] ) ) {
215
-            _e( "Provide the new user's email address", 'invoicing' );
214
+        if (empty($_GET['email'])) {
215
+            _e("Provide the new user's email address", 'invoicing');
216 216
             exit;
217 217
         }
218 218
 
219 219
         // Ensure the email is valid.
220
-        $email = sanitize_text_field( $_GET['email'] );
221
-        if ( ! is_email( $email ) ) {
222
-            _e( 'Invalid email address', 'invoicing' );
220
+        $email = sanitize_text_field($_GET['email']);
221
+        if (!is_email($email)) {
222
+            _e('Invalid email address', 'invoicing');
223 223
             exit;
224 224
         }
225 225
 
226 226
         // And it does not exist.
227
-        if ( email_exists( $email ) ) {
228
-            _e( 'A user with this email address already exists', 'invoicing' );
227
+        if (email_exists($email)) {
228
+            _e('A user with this email address already exists', 'invoicing');
229 229
             exit;
230 230
         }
231 231
 
232
-        wp_send_json_success( true );
232
+        wp_send_json_success(true);
233 233
     }
234 234
     
235 235
     public static function run_tool() {
236
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
237
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
236
+        check_ajax_referer('wpinv-nonce', '_nonce');
237
+        if (!wpinv_current_user_can_manage_invoicing()) {
238 238
             die(-1);
239 239
         }
240 240
         
241
-        $tool = sanitize_text_field( $_POST['tool'] );
241
+        $tool = sanitize_text_field($_POST['tool']);
242 242
         
243
-        do_action( 'wpinv_run_tool' );
243
+        do_action('wpinv_run_tool');
244 244
         
245
-        if ( !empty( $tool ) ) {
246
-            do_action( 'wpinv_tool_' . $tool );
245
+        if (!empty($tool)) {
246
+            do_action('wpinv_tool_' . $tool);
247 247
         }
248 248
     }
249 249
 
@@ -253,27 +253,27 @@  discard block
 block discarded – undo
253 253
     public static function get_payment_form() {
254 254
 
255 255
         // Check nonce.
256
-        check_ajax_referer( 'getpaid_form_nonce' );
256
+        check_ajax_referer('getpaid_form_nonce');
257 257
 
258 258
         // Is the request set up correctly?
259
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
259
+		if (empty($_GET['form']) && empty($_GET['item'])) {
260 260
 			echo aui()->alert(
261 261
 				array(
262 262
 					'type'    => 'warning',
263
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
263
+					'content' => __('No payment form or item provided', 'invoicing'),
264 264
 				)
265 265
             );
266 266
             exit;
267 267
         }
268 268
 
269 269
         // Payment form or button?
270
-		if ( ! empty( $_GET['form'] ) ) {
271
-            getpaid_display_payment_form( $_GET['form'] );
272
-		} else if( ! empty( $_GET['invoice'] ) ) {
273
-		    getpaid_display_invoice_payment_form( $_GET['invoice'] );
270
+		if (!empty($_GET['form'])) {
271
+            getpaid_display_payment_form($_GET['form']);
272
+		} else if (!empty($_GET['invoice'])) {
273
+		    getpaid_display_invoice_payment_form($_GET['invoice']);
274 274
         } else {
275
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
276
-		    getpaid_display_item_payment_form( $items );
275
+			$items = getpaid_convert_items_to_array($_GET['item']);
276
+		    getpaid_display_item_payment_form($items);
277 277
         }
278 278
 
279 279
         exit;
@@ -288,17 +288,17 @@  discard block
 block discarded – undo
288 288
     public static function payment_form() {
289 289
 
290 290
         // Check nonce.
291
-        check_ajax_referer( 'getpaid_form_nonce' );
291
+        check_ajax_referer('getpaid_form_nonce');
292 292
 
293 293
         // ... form fields...
294
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
295
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
294
+        if (empty($_POST['getpaid_payment_form_submission'])) {
295
+            _e('Error: Reload the page and try again.', 'invoicing');
296 296
             exit;
297 297
         }
298 298
 
299 299
         // Process the payment form.
300
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
301
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
300
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
301
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
302 302
         $checkout->process_checkout();
303 303
 
304 304
         exit;
@@ -311,51 +311,51 @@  discard block
 block discarded – undo
311 311
      */
312 312
     public static function get_payment_form_states_field() {
313 313
 
314
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
314
+        if (empty($_GET['country']) || empty($_GET['form'])) {
315 315
             exit;
316 316
         }
317 317
 
318
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
318
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
319 319
 
320
-        if ( empty( $elements ) ) {
320
+        if (empty($elements)) {
321 321
             exit;
322 322
         }
323 323
 
324 324
         $address_fields = array();
325
-        foreach ( $elements as $element ) {
326
-            if ( 'address' === $element['type'] ) {
325
+        foreach ($elements as $element) {
326
+            if ('address' === $element['type']) {
327 327
                 $address_fields = $element;
328 328
                 break;
329 329
             }
330 330
         }
331 331
 
332
-        if ( empty( $address_fields ) ) {
332
+        if (empty($address_fields)) {
333 333
             exit;
334 334
         }
335 335
 
336
-        foreach ( $address_fields['fields'] as $address_field ) {
336
+        foreach ($address_fields['fields'] as $address_field) {
337 337
 
338
-            if ( 'wpinv_state' == $address_field['name'] ) {
338
+            if ('wpinv_state' == $address_field['name']) {
339 339
 
340
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
341
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
342
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
343
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
340
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
341
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
342
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
343
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
344 344
 
345
-                if ( ! empty( $address_field['required'] ) ) {
345
+                if (!empty($address_field['required'])) {
346 346
                     $label .= "<span class='text-danger'> *</span>";
347 347
                 }
348 348
 
349
-                $html = getpaid_get_states_select_markup (
350
-                    sanitize_text_field( $_GET['country'] ),
349
+                $html = getpaid_get_states_select_markup(
350
+                    sanitize_text_field($_GET['country']),
351 351
                     $value,
352 352
                     $placeholder,
353 353
                     $label,
354 354
                     $description,
355
-                    ! empty( $address_field['required'] )
355
+                    !empty($address_field['required'])
356 356
                 );
357 357
 
358
-                wp_send_json_success( $html );
358
+                wp_send_json_success($html);
359 359
                 exit;
360 360
 
361 361
             }
@@ -371,56 +371,56 @@  discard block
 block discarded – undo
371 371
     public static function recalculate_invoice_totals() {
372 372
 
373 373
         // Verify nonce.
374
-        check_ajax_referer( 'wpinv-nonce' );
374
+        check_ajax_referer('wpinv-nonce');
375 375
 
376
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
376
+        if (!wpinv_current_user_can_manage_invoicing()) {
377 377
             exit;
378 378
         }
379 379
 
380 380
         // We need an invoice.
381
-        if ( empty( $_POST['post_id'] ) ) {
381
+        if (empty($_POST['post_id'])) {
382 382
             exit;
383 383
         }
384 384
 
385 385
         // Fetch the invoice.
386
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
386
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
387 387
 
388 388
         // Ensure it exists.
389
-        if ( ! $invoice->get_id() ) {
389
+        if (!$invoice->get_id()) {
390 390
             exit;
391 391
         }
392 392
 
393 393
         // Maybe set the country, state, currency.
394
-        foreach ( array( 'country', 'state', 'currency' ) as $key ) {
395
-            if ( isset( $_POST[ $key ] ) ) {
394
+        foreach (array('country', 'state', 'currency') as $key) {
395
+            if (isset($_POST[$key])) {
396 396
                 $method = "set_$key";
397
-                $invoice->$method( $_POST[ $key ] );
397
+                $invoice->$method($_POST[$key]);
398 398
             }
399 399
         }
400 400
 
401 401
         // Maybe disable taxes.
402
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
402
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
403 403
 
404 404
         // Recalculate totals.
405 405
         $invoice->recalculate_total();
406 406
 
407
-        $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() );
407
+        $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency());
408 408
 
409
-        if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
410
-            $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() );
411
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
409
+        if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
410
+            $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency());
411
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
412 412
         }
413 413
 
414 414
         $totals = array(
415
-            'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ),
416
-            'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ),
417
-            'tax'      => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ),
415
+            'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()),
416
+            'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()),
417
+            'tax'      => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()),
418 418
             'total'    => $total,
419 419
         );
420 420
 
421
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
421
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
422 422
 
423
-        wp_send_json_success( compact( 'totals' ) );
423
+        wp_send_json_success(compact('totals'));
424 424
     }
425 425
 
426 426
     /**
@@ -429,33 +429,33 @@  discard block
 block discarded – undo
429 429
     public static function get_invoice_items() {
430 430
 
431 431
         // Verify nonce.
432
-        check_ajax_referer( 'wpinv-nonce' );
432
+        check_ajax_referer('wpinv-nonce');
433 433
 
434
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
434
+        if (!wpinv_current_user_can_manage_invoicing()) {
435 435
             exit;
436 436
         }
437 437
 
438 438
         // We need an invoice and items.
439
-        if ( empty( $_POST['post_id'] ) ) {
439
+        if (empty($_POST['post_id'])) {
440 440
             exit;
441 441
         }
442 442
 
443 443
         // Fetch the invoice.
444
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
444
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
445 445
 
446 446
         // Ensure it exists.
447
-        if ( ! $invoice->get_id() ) {
447
+        if (!$invoice->get_id()) {
448 448
             exit;
449 449
         }
450 450
 
451 451
         // Return an array of invoice items.
452 452
         $items = array();
453 453
 
454
-        foreach ( $invoice->get_items() as $item_id => $item ) {
455
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
454
+        foreach ($invoice->get_items() as $item_id => $item) {
455
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
456 456
         }
457 457
 
458
-        wp_send_json_success( compact( 'items' ) );
458
+        wp_send_json_success(compact('items'));
459 459
     }
460 460
 
461 461
     /**
@@ -464,50 +464,50 @@  discard block
 block discarded – undo
464 464
     public static function edit_invoice_item() {
465 465
 
466 466
         // Verify nonce.
467
-        check_ajax_referer( 'wpinv-nonce' );
467
+        check_ajax_referer('wpinv-nonce');
468 468
 
469
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
469
+        if (!wpinv_current_user_can_manage_invoicing()) {
470 470
             exit;
471 471
         }
472 472
 
473 473
         // We need an invoice and item details.
474
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
474
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
475 475
             exit;
476 476
         }
477 477
 
478 478
         // Fetch the invoice.
479
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
479
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
480 480
 
481 481
         // Ensure it exists and its not been paid for.
482
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
482
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
483 483
             exit;
484 484
         }
485 485
 
486 486
         // Format the data.
487
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
487
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
488 488
 
489 489
         // Ensure that we have an item id.
490
-        if ( empty( $data['id'] ) ) {
490
+        if (empty($data['id'])) {
491 491
             exit;
492 492
         }
493 493
 
494 494
         // Abort if the invoice does not have the specified item.
495
-        $item = $invoice->get_item( (int) $data['id'] );
495
+        $item = $invoice->get_item((int) $data['id']);
496 496
 
497
-        if ( empty( $item ) ) {
497
+        if (empty($item)) {
498 498
             exit;
499 499
         }
500 500
 
501 501
         // Update the item.
502
-        $item->set_price( $data['price'] );
503
-        $item->set_name( $data['name'] );
504
-        $item->set_description( $data['description'] );
505
-        $item->set_quantity( $data['quantity'] );
502
+        $item->set_price($data['price']);
503
+        $item->set_name($data['name']);
504
+        $item->set_description($data['description']);
505
+        $item->set_quantity($data['quantity']);
506 506
 
507 507
         // Add it to the invoice.
508
-        $error = $invoice->add_item( $item );
508
+        $error = $invoice->add_item($item);
509 509
         $alert = false;
510
-        if ( is_wp_error( $error ) ) {
510
+        if (is_wp_error($error)) {
511 511
             $alert = $error->get_error_message();
512 512
         }
513 513
 
@@ -520,11 +520,11 @@  discard block
 block discarded – undo
520 520
         // Return an array of invoice items.
521 521
         $items = array();
522 522
 
523
-        foreach ( $invoice->get_items() as $item_id => $item ) {
524
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
523
+        foreach ($invoice->get_items() as $item_id => $item) {
524
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
525 525
         }
526 526
 
527
-        wp_send_json_success( compact( 'items', 'alert' ) );
527
+        wp_send_json_success(compact('items', 'alert'));
528 528
     }
529 529
 
530 530
     /**
@@ -533,33 +533,33 @@  discard block
 block discarded – undo
533 533
     public static function remove_invoice_item() {
534 534
 
535 535
         // Verify nonce.
536
-        check_ajax_referer( 'wpinv-nonce' );
536
+        check_ajax_referer('wpinv-nonce');
537 537
 
538
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
538
+        if (!wpinv_current_user_can_manage_invoicing()) {
539 539
             exit;
540 540
         }
541 541
 
542 542
         // We need an invoice and an item.
543
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
543
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
544 544
             exit;
545 545
         }
546 546
 
547 547
         // Fetch the invoice.
548
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
548
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
549 549
 
550 550
         // Ensure it exists and its not been paid for.
551
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
551
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
552 552
             exit;
553 553
         }
554 554
 
555 555
         // Abort if the invoice does not have the specified item.
556
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
556
+        $item = $invoice->get_item((int) $_POST['item_id']);
557 557
 
558
-        if ( empty( $item ) ) {
558
+        if (empty($item)) {
559 559
             exit;
560 560
         }
561 561
 
562
-        $invoice->remove_item( (int) $_POST['item_id'] );
562
+        $invoice->remove_item((int) $_POST['item_id']);
563 563
 
564 564
         // Update totals.
565 565
         $invoice->recalculate_total();
@@ -570,11 +570,11 @@  discard block
 block discarded – undo
570 570
         // Return an array of invoice items.
571 571
         $items = array();
572 572
 
573
-        foreach ( $invoice->get_items() as $item_id => $item ) {
574
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
573
+        foreach ($invoice->get_items() as $item_id => $item) {
574
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
575 575
         }
576 576
 
577
-        wp_send_json_success( compact( 'items' ) );
577
+        wp_send_json_success(compact('items'));
578 578
     }
579 579
 
580 580
     /**
@@ -583,39 +583,39 @@  discard block
 block discarded – undo
583 583
     public static function add_invoice_items() {
584 584
 
585 585
         // Verify nonce.
586
-        check_ajax_referer( 'wpinv-nonce' );
586
+        check_ajax_referer('wpinv-nonce');
587 587
 
588
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
588
+        if (!wpinv_current_user_can_manage_invoicing()) {
589 589
             exit;
590 590
         }
591 591
 
592 592
         // We need an invoice and items.
593
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
593
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
594 594
             exit;
595 595
         }
596 596
 
597 597
         // Fetch the invoice.
598
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
598
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
599 599
         $alert   = false;
600 600
 
601 601
         // Ensure it exists and its not been paid for.
602
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
602
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
603 603
             exit;
604 604
         }
605 605
 
606 606
         // Add the items.
607
-        foreach ( $_POST['items'] as $data ) {
607
+        foreach ($_POST['items'] as $data) {
608 608
 
609
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
609
+            $item = new GetPaid_Form_Item($data['id']);
610 610
 
611
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
612
-                $item->set_quantity( $data[ 'qty' ] );
611
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
612
+                $item->set_quantity($data['qty']);
613 613
             }
614 614
 
615
-            if ( $item->get_id() > 0 ) {
616
-                $error = $invoice->add_item( $item );
615
+            if ($item->get_id() > 0) {
616
+                $error = $invoice->add_item($item);
617 617
 
618
-                if ( is_wp_error( $error ) ) {
618
+                if (is_wp_error($error)) {
619 619
                     $alert = $error->get_error_message();
620 620
                 }
621 621
 
@@ -630,11 +630,11 @@  discard block
 block discarded – undo
630 630
         // Return an array of invoice items.
631 631
         $items = array();
632 632
 
633
-        foreach ( $invoice->get_items() as $item_id => $item ) {
634
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
633
+        foreach ($invoice->get_items() as $item_id => $item) {
634
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
635 635
         }
636 636
 
637
-        wp_send_json_success( compact( 'items', 'alert' ) );
637
+        wp_send_json_success(compact('items', 'alert'));
638 638
     }
639 639
 
640 640
     /**
@@ -643,15 +643,15 @@  discard block
 block discarded – undo
643 643
     public static function get_invoicing_items() {
644 644
 
645 645
         // Verify nonce.
646
-        check_ajax_referer( 'wpinv-nonce' );
646
+        check_ajax_referer('wpinv-nonce');
647 647
 
648
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
648
+        if (!wpinv_current_user_can_manage_invoicing()) {
649 649
             exit;
650 650
         }
651 651
 
652 652
         // We need a search term.
653
-        if ( empty( $_GET['search'] ) ) {
654
-            wp_send_json_success( array() );
653
+        if (empty($_GET['search'])) {
654
+            wp_send_json_success(array());
655 655
         }
656 656
 
657 657
         // Retrieve items.
@@ -660,8 +660,8 @@  discard block
 block discarded – undo
660 660
             'orderby'        => 'title',
661 661
             'order'          => 'ASC',
662 662
             'posts_per_page' => -1,
663
-            'post_status'    => array( 'publish' ),
664
-            's'              => trim( $_GET['search'] ),
663
+            'post_status'    => array('publish'),
664
+            's'              => trim($_GET['search']),
665 665
             'meta_query'     => array(
666 666
                 array(
667 667
                     'key'       => '_wpinv_type',
@@ -671,22 +671,22 @@  discard block
 block discarded – undo
671 671
             )
672 672
         );
673 673
 
674
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
674
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
675 675
         $data  = array();
676 676
 
677 677
 
678
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
678
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
679 679
 
680
-        foreach ( $items as $item ) {
681
-            $item      = new GetPaid_Form_Item( $item );
680
+        foreach ($items as $item) {
681
+            $item = new GetPaid_Form_Item($item);
682 682
             $data[] = array(
683 683
                 'id'        => (int) $item->get_id(),
684
-                'text'      => strip_tags( $item->get_name() ),
685
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
684
+                'text'      => strip_tags($item->get_name()),
685
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
686 686
             );
687 687
         }
688 688
 
689
-        wp_send_json_success( $data );
689
+        wp_send_json_success($data);
690 690
 
691 691
     }
692 692
 
@@ -696,24 +696,24 @@  discard block
 block discarded – undo
696 696
     public static function get_aui_states_field() {
697 697
 
698 698
         // Verify nonce.
699
-        check_ajax_referer( 'wpinv-nonce' );
699
+        check_ajax_referer('wpinv-nonce');
700 700
 
701 701
         // We need a country.
702
-        if ( empty( $_GET['country'] ) ) {
702
+        if (empty($_GET['country'])) {
703 703
             exit;
704 704
         }
705 705
 
706
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
707
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
706
+        $states = wpinv_get_country_states(trim($_GET['country']));
707
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
708 708
 
709
-        if ( empty( $states ) ) {
709
+        if (empty($states)) {
710 710
 
711 711
             $html = aui()->input(
712 712
                 array(
713 713
                     'type'        => 'text',
714 714
                     'id'          => 'wpinv_state',
715 715
                     'name'        => 'wpinv_state',
716
-                    'label'       => __( 'State', 'invoicing' ),
716
+                    'label'       => __('State', 'invoicing'),
717 717
                     'label_type'  => 'vertical',
718 718
                     'placeholder' => 'Liège',
719 719
                     'class'       => 'form-control-sm',
@@ -727,9 +727,9 @@  discard block
 block discarded – undo
727 727
                 array(
728 728
                     'id'          => 'wpinv_state',
729 729
                     'name'        => 'wpinv_state',
730
-                    'label'       => __( 'State', 'invoicing' ),
730
+                    'label'       => __('State', 'invoicing'),
731 731
                     'label_type'  => 'vertical',
732
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
732
+                    'placeholder' => __('Select a state', 'invoicing'),
733 733
                     'class'       => 'form-control-sm',
734 734
                     'value'       => $state,
735 735
                     'options'     => $states,
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
         wp_send_json_success(
744 744
             array(
745 745
                 'html'   => $html,
746
-                'select' => ! empty ( $states )
746
+                'select' => !empty ($states)
747 747
             )
748 748
         );
749 749
 
@@ -757,46 +757,46 @@  discard block
 block discarded – undo
757 757
     public static function ip_geolocation() {
758 758
 
759 759
         // Check nonce.
760
-        check_ajax_referer( 'getpaid-ip-location' );
760
+        check_ajax_referer('getpaid-ip-location');
761 761
 
762 762
         // IP address.
763
-        if ( empty( $_GET['ip'] ) || ! rest_is_ip_address( $_GET['ip'] ) ) {
764
-            _e( 'Invalid IP Address.', 'invoicing' );
763
+        if (empty($_GET['ip']) || !rest_is_ip_address($_GET['ip'])) {
764
+            _e('Invalid IP Address.', 'invoicing');
765 765
             exit;
766 766
         }
767 767
 
768 768
         // Retrieve location info.
769
-        $location = getpaid_geolocate_ip_address( $_GET['ip'] );
769
+        $location = getpaid_geolocate_ip_address($_GET['ip']);
770 770
 
771
-        if ( empty( $location ) ) {
772
-            _e( 'Unable to find geolocation for the IP Address.', 'invoicing' );
771
+        if (empty($location)) {
772
+            _e('Unable to find geolocation for the IP Address.', 'invoicing');
773 773
             exit;
774 774
         }
775 775
 
776 776
         // Sorry.
777
-        extract( $location );
777
+        extract($location);
778 778
 
779 779
         // Prepare the address.
780 780
         $content = '';
781 781
 
782
-        if ( ! empty( $location['city'] ) ) {
783
-            $content .=  $location['city']  . ', ';
782
+        if (!empty($location['city'])) {
783
+            $content .= $location['city'] . ', ';
784 784
         }
785 785
         
786
-        if ( ! empty( $location['region'] ) ) {
787
-            $content .=  $location['region']  . ', ';
786
+        if (!empty($location['region'])) {
787
+            $content .= $location['region'] . ', ';
788 788
         }
789 789
         
790
-        $content .=  $location['country'] . ' (' . $location['iso'] . ')';
790
+        $content .= $location['country'] . ' (' . $location['iso'] . ')';
791 791
 
792 792
         $location['address'] = $content;
793 793
 
794
-        $content  = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $content ) . '</p>';
795
-        $content .= '<p>'. $location['credit'] . '</p>';
794
+        $content  = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $content) . '</p>';
795
+        $content .= '<p>' . $location['credit'] . '</p>';
796 796
 
797 797
         $location['content'] = $content;
798 798
 
799
-        wpinv_get_template( 'geolocation.php', $location );
799
+        wpinv_get_template('geolocation.php', $location);
800 800
 
801 801
         exit;
802 802
     }
@@ -809,11 +809,11 @@  discard block
 block discarded – undo
809 809
     public static function payment_form_refresh_prices() {
810 810
 
811 811
         // Check nonce.
812
-        check_ajax_referer( 'getpaid_form_nonce' );
812
+        check_ajax_referer('getpaid_form_nonce');
813 813
 
814 814
         // ... form fields...
815
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
816
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
815
+        if (empty($_POST['getpaid_payment_form_submission'])) {
816
+            _e('Error: Reload the page and try again.', 'invoicing');
817 817
             exit;
818 818
         }
819 819
 
@@ -821,18 +821,18 @@  discard block
 block discarded – undo
821 821
         $submission = new GetPaid_Payment_Form_Submission();
822 822
 
823 823
         // Do we have an error?
824
-        if ( ! empty( $submission->last_error ) ) {
824
+        if (!empty($submission->last_error)) {
825 825
             echo $submission->last_error;
826 826
             exit;
827 827
         }
828 828
 
829 829
         // Prepare the response.
830
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
830
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
831 831
         
832 832
         // Filter the response.
833
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
833
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
834 834
 
835
-        wp_send_json_success( $response );
835
+        wp_send_json_success($response);
836 836
     }
837 837
 
838 838
 }
Please login to merge, or discard this patch.