Passed
Push — master ( f76276...ca99e2 )
by Stiofan
03:29
created
templates/emails/wpinv-email-user_note.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-do_action( 'wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note );
8
+do_action('wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note);
9 9
 
10
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
10
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
11 11
 
12
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note );
16
+do_action('wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -14,73 +14,73 @@  discard block
 block discarded – undo
14 14
     }
15 15
     
16 16
     public function init() {
17
-        do_action( 'wpinv_class_notes_init', $this );
17
+        do_action('wpinv_class_notes_init', $this);
18 18
     }
19 19
     
20 20
     public function includes() {
21
-        do_action( 'wpinv_class_notes_includes', $this );
21
+        do_action('wpinv_class_notes_includes', $this);
22 22
     }
23 23
     
24 24
     public function actions() {
25 25
         // Secure inovice notes
26
-        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
26
+        add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
27 27
         
28 28
         // Count comments
29
-        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 );
29
+        add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2);
30 30
         
31 31
         // Delete comments count cache whenever there is a new comment or a comment status changes
32
-        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
33
-        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
32
+        add_action('wp_insert_comment', array($this, 'delete_comments_count_cache'));
33
+        add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache'));
34 34
         
35
-        do_action( 'wpinv_class_notes_actions', $this );
35
+        do_action('wpinv_class_notes_actions', $this);
36 36
     }
37 37
         
38
-    public function set_invoice_note_type( $query ) {
39
-        $post_ID        = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
38
+    public function set_invoice_note_type($query) {
39
+        $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
40 40
         
41
-        if ( $post_ID && in_array(get_post_type( $post_ID ), array($this->invoice_post_type, 'wpi_quote' )) ) {
41
+        if ($post_ID && in_array(get_post_type($post_ID), array($this->invoice_post_type, 'wpi_quote'))) {
42 42
             $query->query_vars['type__in']      = $this->comment_type;
43 43
             $query->query_vars['type__not_in']  = '';
44 44
         } else {        
45
-            if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) {
46
-                if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) {
47
-                    $key = array_search( $this->comment_type, $type_in );
48
-                    unset( $query->query_vars['type__in'][$key] );
49
-                } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) {
45
+            if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) {
46
+                if (is_array($type_in) && in_array($this->comment_type, $type_in)) {
47
+                    $key = array_search($this->comment_type, $type_in);
48
+                    unset($query->query_vars['type__in'][$key]);
49
+                } else if (!is_array($type_in) && $type_in == $this->comment_type) {
50 50
                     $query->query_vars['type__in'] = '';
51 51
                 }
52 52
             }
53 53
             
54
-            if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) {
55
-                if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) {
54
+            if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) {
55
+                if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) {
56 56
                     $query->query_vars['type__not_in'][] = $this->comment_type;
57
-                } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) {
57
+                } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) {
58 58
                     $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in'];
59 59
                     $query->query_vars['type__not_in'][] = $this->comment_type;
60 60
                 }
61 61
             } else {
62
-                $query->query_vars['type__not_in']  = $this->comment_type;
62
+                $query->query_vars['type__not_in'] = $this->comment_type;
63 63
             }
64 64
         }
65 65
         
66 66
         return $query;
67 67
     }
68 68
     
69
-    public function get_invoice_notes( $invoice_id = 0, $type = '' ) {
69
+    public function get_invoice_notes($invoice_id = 0, $type = '') {
70 70
         $args = array( 
71 71
             'post_id'   => $invoice_id,
72 72
             'orderby'   => 'comment_ID',
73 73
             'order'     => 'ASC',
74 74
         );
75 75
         
76
-        if ( $type == 'customer' ) {
76
+        if ($type == 'customer') {
77 77
             $args['meta_key']   = '_wpi_customer_note';
78 78
             $args['meta_value'] = 1;
79 79
         }
80 80
         
81
-        $args   = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
81
+        $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
82 82
         
83
-        return get_comments( $args );
83
+        return get_comments($args);
84 84
     }
85 85
     
86 86
     /**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @return void
92 92
      */
93 93
     public function delete_comments_count_cache() {
94
-        delete_transient( 'wpinv_count_comments' );
94
+        delete_transient('wpinv_count_comments');
95 95
     }
96 96
     
97 97
     /**
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
      * @param  int    $post_id Post ID.
103 103
      * @return object
104 104
      */
105
-    public function wp_count_comments( $stats, $post_id ) {
105
+    public function wp_count_comments($stats, $post_id) {
106 106
         global $wpdb;
107 107
 
108
-        if ( 0 === $post_id ) {
109
-            $stats = get_transient( 'wpinv_count_comments' );
108
+        if (0 === $post_id) {
109
+            $stats = get_transient('wpinv_count_comments');
110 110
 
111
-            if ( ! $stats ) {
111
+            if (!$stats) {
112 112
                 $stats = array();
113 113
 
114
-                $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A );
114
+                $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A);
115 115
 
116 116
                 $total = 0;
117 117
                 $approved = array(
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
                     'post-trashed' => 'post-trashed',
123 123
                 );
124 124
 
125
-                foreach ( (array) $count as $row ) {
125
+                foreach ((array)$count as $row) {
126 126
                     // Do not count post-trashed toward totals.
127
-                    if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) {
127
+                    if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) {
128 128
                         $total += $row['num_comments'];
129 129
                     }
130
-                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
131
-                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
130
+                    if (isset($approved[$row['comment_approved']])) {
131
+                        $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
132 132
                     }
133 133
                 }
134 134
 
135 135
                 $stats['total_comments'] = $total;
136 136
                 $stats['all'] = $total;
137
-                foreach ( $approved as $key ) {
138
-                    if ( empty( $stats[ $key ] ) ) {
139
-                        $stats[ $key ] = 0;
137
+                foreach ($approved as $key) {
138
+                    if (empty($stats[$key])) {
139
+                        $stats[$key] = 0;
140 140
                     }
141 141
                 }
142 142
 
143
-                $stats = (object) $stats;
144
-                set_transient( 'wpinv_count_comments', $stats );
143
+                $stats = (object)$stats;
144
+                set_transient('wpinv_count_comments', $stats);
145 145
             }
146 146
         }
147 147
 
Please login to merge, or discard this patch.
templates/emails/wpinv-email-new_invoice.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 ?>
8 8
 
9
-<p><?php printf( __( 'You have received payment from %s. The invoice is as follows:', 'invoicing' ), $invoice->get_user_full_name() ); ?></p>
9
+<p><?php printf(__('You have received payment from %s. The invoice is as follows:', 'invoicing'), $invoice->get_user_full_name()); ?></p>
10 10
 
11 11
 <?php
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-invoice-details.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -1,72 +1,72 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6 6
 global $wpinv_euvat;
7 7
 
8
-$sent_to_admin  = !empty( $sent_to_admin ) ? true : false;
9
-if ( $sent_to_admin ) {
10
-    $invoice_url = get_edit_post_link( $invoice->ID );
8
+$sent_to_admin = !empty($sent_to_admin) ? true : false;
9
+if ($sent_to_admin) {
10
+    $invoice_url = get_edit_post_link($invoice->ID);
11 11
 } else {
12
-    $secret = !empty( $email_type ) && $email_type == 'user_invoice' ? true : false;
13
-    $invoice_url = $invoice->get_view_url( $secret );
12
+    $secret = !empty($email_type) && $email_type == 'user_invoice' ? true : false;
13
+    $invoice_url = $invoice->get_view_url($secret);
14 14
 }
15 15
 $use_taxes = wpinv_use_taxes();
16 16
 $vat_name = $wpinv_euvat->get_vat_name();
17 17
 
18
-do_action( 'wpinv_email_before_invoice_details', $invoice, $sent_to_admin ); ?>
18
+do_action('wpinv_email_before_invoice_details', $invoice, $sent_to_admin); ?>
19 19
 <div id="wpinv-email-details">
20
-    <h3 class="wpinv-details-t"><?php echo apply_filters( 'wpinv_email_details_title', __( 'Invoice Details', 'invoicing' ), $invoice ); ?></h3>
20
+    <h3 class="wpinv-details-t"><?php echo apply_filters('wpinv_email_details_title', __('Invoice Details', 'invoicing'), $invoice); ?></h3>
21 21
     <table class="table table-bordered table-sm">
22
-        <?php if ( $invoice_number = $invoice->get_number() ) { ?>
22
+        <?php if ($invoice_number = $invoice->get_number()) { ?>
23 23
             <tr>
24
-                <td><?php echo apply_filters( 'wpinv_email_details_number', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></td>
25
-                <td><a href="<?php echo esc_url( $invoice_url ) ;?>"><?php echo $invoice_number; ?></a></td>
24
+                <td><?php echo apply_filters('wpinv_email_details_number', __('Invoice Number', 'invoicing'), $invoice); ?></td>
25
+                <td><a href="<?php echo esc_url($invoice_url); ?>"><?php echo $invoice_number; ?></a></td>
26 26
             </tr>
27 27
         <?php } ?>
28 28
         <tr>
29
-            <td><?php echo apply_filters( 'wpinv_email_details_status', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></td>
30
-            <td><?php echo $invoice->get_status( true ); ?></td>
29
+            <td><?php echo apply_filters('wpinv_email_details_status', __('Invoice Status', 'invoicing'), $invoice); ?></td>
30
+            <td><?php echo $invoice->get_status(true); ?></td>
31 31
         </tr>
32
-        <?php if ( $invoice->is_renewal() ) { ?>
32
+        <?php if ($invoice->is_renewal()) { ?>
33 33
         <tr>
34
-            <td><?php _e( 'Parent Invoice', 'invoicing' ); ?></td>
35
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
34
+            <td><?php _e('Parent Invoice', 'invoicing'); ?></td>
35
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
36 36
         </tr>
37 37
         <?php } ?>
38 38
         <tr>
39
-            <td><?php _e( 'Payment Method', 'invoicing' ); ?></td>
39
+            <td><?php _e('Payment Method', 'invoicing'); ?></td>
40 40
             <td><?php echo $invoice->get_gateway_title(); ?></td>
41 41
         </tr>
42
-        <?php if ( $invoice_date = $invoice->get_invoice_date( false ) ) { ?>
42
+        <?php if ($invoice_date = $invoice->get_invoice_date(false)) { ?>
43 43
             <tr>
44
-                <td><?php echo apply_filters( 'wpinv_email_details_date', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></td>
45
-                <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $invoice_date ) ), $invoice->get_invoice_date() ); ?></td>
44
+                <td><?php echo apply_filters('wpinv_email_details_date', __('Invoice Date', 'invoicing'), $invoice); ?></td>
45
+                <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($invoice_date)), $invoice->get_invoice_date()); ?></td>
46 46
             </tr>
47 47
         <?php } ?>
48
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date() ) ) { ?>
48
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date())) { ?>
49 49
             <tr>
50
-                <td><?php _e( 'Due Date', 'invoicing' ); ?></td>
51
-                <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $due_date ) ), $invoice->get_due_date( true ) ); ?></td>
50
+                <td><?php _e('Due Date', 'invoicing'); ?></td>
51
+                <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($due_date)), $invoice->get_due_date(true)); ?></td>
52 52
             </tr>
53 53
         <?php } ?>
54
-        <?php if ( empty( $sent_to_admin ) && $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
54
+        <?php if (empty($sent_to_admin) && $owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
55 55
             <tr>
56
-                <td><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></td>
56
+                <td><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></td>
57 57
                 <td><?php echo $owner_vat_number; ?></td>
58 58
             </tr>
59 59
         <?php } ?>
60
-        <?php if ( $use_taxes && $user_vat_number = $invoice->vat_number ) { ?>
60
+        <?php if ($use_taxes && $user_vat_number = $invoice->vat_number) { ?>
61 61
             <tr>
62
-                <td><?php echo wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ); ?></td>
62
+                <td><?php echo wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name); ?></td>
63 63
                 <td><?php echo $user_vat_number; ?></td>
64 64
             </tr>
65 65
         <?php } ?>
66 66
         <tr class="table-active">
67
-            <td><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></td>
68
-            <td><strong><?php echo $invoice->get_total( true ); ?></strong></td>
67
+            <td><strong><?php _e('Total Amount', 'invoicing') ?></strong></td>
68
+            <td><strong><?php echo $invoice->get_total(true); ?></strong></td>
69 69
         </tr>
70 70
     </table>
71 71
 </div>
72
-<?php do_action( 'wpinv_email_after_invoice_details', $invoice, $sent_to_admin ); ?>
73 72
\ No newline at end of file
73
+<?php do_action('wpinv_email_after_invoice_details', $invoice, $sent_to_admin); ?>
74 74
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/admin-meta-boxes.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-function wpinv_add_meta_boxes( $post_type, $post ) {
7
+function wpinv_add_meta_boxes($post_type, $post) {
8 8
     global $wpi_mb_invoice;
9
-    if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) {
10
-        $wpi_mb_invoice = wpinv_get_invoice( $post->ID );
9
+    if ($post_type == 'wpi_invoice' && !empty($post->ID)) {
10
+        $wpi_mb_invoice = wpinv_get_invoice($post->ID);
11 11
     }
12 12
     
13
-    if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) {
14
-        add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' );
13
+    if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) {
14
+        add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high');
15 15
     }
16 16
     
17
-    if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) {
18
-        add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' );
17
+    if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) {
18
+        add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high');
19 19
     }
20 20
     
21
-    if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
22
-        add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' );
21
+    if (wpinv_is_subscription_payment($wpi_mb_invoice)) {
22
+        add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high');
23 23
     }
24 24
     
25
-    add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' );
26
-    add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' );
25
+    add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default');
26
+    add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default');
27 27
    
28
-    add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' );
29
-    add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
30
-    add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
28
+    add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high');
29
+    add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high');
30
+    add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high');
31 31
 }
32
-add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
32
+add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2);
33 33
 
34
-function wpinv_save_meta_boxes( $post_id, $post, $update = false ) {
35
-    remove_action( 'save_post', __FUNCTION__ );
34
+function wpinv_save_meta_boxes($post_id, $post, $update = false) {
35
+    remove_action('save_post', __FUNCTION__);
36 36
     
37 37
     // $post_id and $post are required
38
-    if ( empty( $post_id ) || empty( $post ) ) {
38
+    if (empty($post_id) || empty($post)) {
39 39
         return;
40 40
     }
41 41
         
42
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
42
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
43 43
         return;
44 44
     }
45 45
     
46 46
     // Dont' save meta boxes for revisions or autosaves
47
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
47
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
48 48
         return;
49 49
     }
50 50
         
51
-    if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) {
52
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
51
+    if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') {
52
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
53 53
             return;
54 54
         }
55 55
     
56
-        if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) {
57
-            WPInv_Meta_Box_Items::save( $post_id, $_POST, $post );
56
+        if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) {
57
+            WPInv_Meta_Box_Items::save($post_id, $_POST, $post);
58 58
         }
59
-    } else if ( $post->post_type == 'wpi_item' ) {
59
+    } else if ($post->post_type == 'wpi_item') {
60 60
         // verify nonce
61
-        if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
62
-            $fields                                 = array();
61
+        if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) {
62
+            $fields = array();
63 63
             $fields['_wpinv_price']              = 'wpinv_item_price';
64 64
             $fields['_wpinv_vat_class']          = 'wpinv_vat_class';
65 65
             $fields['_wpinv_vat_rule']           = 'wpinv_vat_rules';
@@ -72,256 +72,256 @@  discard block
 block discarded – undo
72 72
             $fields['_wpinv_trial_period']       = 'wpinv_trial_period';
73 73
             $fields['_wpinv_trial_interval']     = 'wpinv_trial_interval';
74 74
             
75
-            if ( !isset( $_POST['wpinv_is_recurring'] ) ) {
75
+            if (!isset($_POST['wpinv_is_recurring'])) {
76 76
                 $_POST['wpinv_is_recurring'] = 0;
77 77
             }
78 78
             
79
-            if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) {
79
+            if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) {
80 80
                 $_POST['wpinv_free_trial'] = 0;
81 81
             }
82 82
             
83
-            foreach ( $fields as $field => $name ) {
84
-                if ( isset( $_POST[ $name ] ) ) {
85
-                    if ( $field == '_wpinv_price' ) {
86
-                        if ( get_post_meta( $post_id, '_wpinv_type', true ) === 'package' ) {
87
-                            $value = wpinv_sanitize_amount( get_post_meta( $post_id, '_wpinv_price', true ) ); // Don't allow edit GD package item price.
83
+            foreach ($fields as $field => $name) {
84
+                if (isset($_POST[$name])) {
85
+                    if ($field == '_wpinv_price') {
86
+                        if (get_post_meta($post_id, '_wpinv_type', true) === 'package') {
87
+                            $value = wpinv_sanitize_amount(get_post_meta($post_id, '_wpinv_price', true)); // Don't allow edit GD package item price.
88 88
                         } else {
89
-                            $value = wpinv_sanitize_amount( $_POST[ $name ] );
89
+                            $value = wpinv_sanitize_amount($_POST[$name]);
90 90
                         }
91 91
                     } else {
92
-                        $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ];
92
+                        $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name];
93 93
                     }
94 94
                     
95
-                    $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name );
96
-                    update_post_meta( $post_id, $field, $value );
95
+                    $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name);
96
+                    update_post_meta($post_id, $field, $value);
97 97
                 }
98 98
             }
99 99
             
100
-            if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
101
-                update_post_meta( $post_id, '_wpinv_custom_id', $post_id );
100
+            if (!get_post_meta($post_id, '_wpinv_custom_id', true)) {
101
+                update_post_meta($post_id, '_wpinv_custom_id', $post_id);
102 102
             }
103 103
         }
104 104
     }
105 105
 }
106
-add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
106
+add_action('save_post', 'wpinv_save_meta_boxes', 10, 3);
107 107
 
108 108
 function wpinv_register_item_meta_boxes() {    
109 109
     global $wpinv_euvat;
110 110
     
111
-    add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' );
111
+    add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high');
112 112
 
113
-    if ( $wpinv_euvat->allow_vat_rules() ) {
114
-        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
113
+    if ($wpinv_euvat->allow_vat_rules()) {
114
+        add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high');
115 115
     }
116 116
     
117
-    if ( $wpinv_euvat->allow_vat_classes() ) {
118
-        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
117
+    if ($wpinv_euvat->allow_vat_classes()) {
118
+        add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high');
119 119
     }
120 120
     
121
-    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
122
-    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
121
+    add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core');
122
+    add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core');
123 123
 }
124 124
 
125 125
 function wpinv_register_discount_meta_boxes() {
126
-    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
126
+    add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high');
127 127
 }
128 128
 
129
-function wpinv_discount_metabox_details( $post ) {
129
+function wpinv_discount_metabox_details($post) {
130 130
     $discount_id    = $post->ID;
131
-    $discount       = wpinv_get_discount( $discount_id );
131
+    $discount       = wpinv_get_discount($discount_id);
132 132
     
133
-    $type           = wpinv_get_discount_type( $discount_id );
134
-    $item_reqs      = wpinv_get_discount_item_reqs( $discount_id );
135
-    $excluded_items = wpinv_get_discount_excluded_items( $discount_id );
136
-    $min_total      = wpinv_get_discount_min_total( $discount_id );
137
-    $max_total      = wpinv_get_discount_max_total( $discount_id );
138
-    $max_uses       = wpinv_get_discount_max_uses( $discount_id );
139
-    $single_use     = wpinv_discount_is_single_use( $discount_id );
140
-    $recurring      = (bool)wpinv_discount_is_recurring( $discount_id );
133
+    $type           = wpinv_get_discount_type($discount_id);
134
+    $item_reqs      = wpinv_get_discount_item_reqs($discount_id);
135
+    $excluded_items = wpinv_get_discount_excluded_items($discount_id);
136
+    $min_total      = wpinv_get_discount_min_total($discount_id);
137
+    $max_total      = wpinv_get_discount_max_total($discount_id);
138
+    $max_uses       = wpinv_get_discount_max_uses($discount_id);
139
+    $single_use     = wpinv_discount_is_single_use($discount_id);
140
+    $recurring      = (bool)wpinv_discount_is_recurring($discount_id);
141 141
     
142 142
     $min_total      = $min_total > 0 ? $min_total : '';
143 143
     $max_total      = $max_total > 0 ? $max_total : '';
144 144
     $max_uses       = $max_uses > 0 ? $max_uses : '';
145 145
 ?>
146
-<?php do_action( 'wpinv_discount_form_top', $post ); ?>
147
-<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
146
+<?php do_action('wpinv_discount_form_top', $post); ?>
147
+<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?>
148 148
 <table class="form-table wpi-form-table">
149 149
     <tbody>
150
-        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
151
-        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
150
+        <?php do_action('wpinv_discount_form_first', $post); ?>
151
+        <?php do_action('wpinv_discount_form_before_code', $post); ?>
152 152
         <tr>
153 153
             <th valign="top" scope="row">
154
-                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
154
+                <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label>
155 155
             </th>
156 156
             <td>
157
-                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
158
-                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
157
+                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required>
158
+                <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p>
159 159
             </td>
160 160
         </tr>
161
-        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
161
+        <?php do_action('wpinv_discount_form_before_type', $post); ?>
162 162
         <tr>
163 163
             <th valign="top" scope="row">
164
-                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
164
+                <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label>
165 165
             </th>
166 166
             <td>
167 167
                 <select id="wpinv_discount_type" name="type" class="medium-text">
168
-                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
169
-                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
168
+                    <?php foreach (wpinv_get_discount_types() as $value => $label) { ?>
169
+                    <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option>
170 170
                     <?php } ?>
171 171
                 </select>
172
-                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
172
+                <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p>
173 173
             </td>
174 174
         </tr>
175
-        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
175
+        <?php do_action('wpinv_discount_form_before_amount', $post); ?>
176 176
         <tr>
177 177
             <th valign="top" scope="row">
178
-                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
178
+                <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label>
179 179
             </th>
180 180
             <td>
181
-                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font>
182
-                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
183
-                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
181
+                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font>
182
+                <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p>
183
+                <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p>
184 184
             </td>
185 185
         </tr>
186
-        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
186
+        <?php do_action('wpinv_discount_form_before_items', $post); ?>
187 187
         <tr>
188 188
             <th valign="top" scope="row">
189
-                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
189
+                <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label>
190 190
             </th>
191 191
             <td>
192
-                <p><?php echo wpinv_item_dropdown( array(
192
+                <p><?php echo wpinv_item_dropdown(array(
193 193
                         'name'              => 'items[]',
194 194
                         'id'                => 'items',
195 195
                         'selected'          => $item_reqs,
196 196
                         'multiple'          => true,
197 197
                         'chosen'            => true,
198 198
                         'class'             => 'medium-text',
199
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
199
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
200 200
                         'show_recurring'    => true,
201
-                    ) ); ?>
201
+                    )); ?>
202 202
                 </p>
203
-                <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p>
203
+                <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p>
204 204
             </td>
205 205
         </tr>
206
-        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
206
+        <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?>
207 207
         <tr>
208 208
             <th valign="top" scope="row">
209
-                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
209
+                <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label>
210 210
             </th>
211 211
             <td>
212
-                <p><?php echo wpinv_item_dropdown( array(
212
+                <p><?php echo wpinv_item_dropdown(array(
213 213
                         'name'              => 'excluded_items[]',
214 214
                         'id'                => 'excluded_items',
215 215
                         'selected'          => $excluded_items,
216 216
                         'multiple'          => true,
217 217
                         'chosen'            => true,
218 218
                         'class'             => 'medium-text',
219
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
219
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
220 220
                         'show_recurring'    => true,
221
-                    ) ); ?>
221
+                    )); ?>
222 222
                 </p>
223
-                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
223
+                <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p>
224 224
             </td>
225 225
         </tr>
226
-        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
226
+        <?php do_action('wpinv_discount_form_before_start', $post); ?>
227 227
         <tr>
228 228
             <th valign="top" scope="row">
229
-                <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label>
229
+                <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label>
230 230
             </th>
231 231
             <td>
232
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( wpinv_get_discount_start_date( $discount_id ) ); ?>">
233
-                <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p>
232
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr(wpinv_get_discount_start_date($discount_id)); ?>">
233
+                <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p>
234 234
             </td>
235 235
         </tr>
236
-        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
236
+        <?php do_action('wpinv_discount_form_before_expiration', $post); ?>
237 237
         <tr>
238 238
             <th valign="top" scope="row">
239
-                <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label>
239
+                <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label>
240 240
             </th>
241 241
             <td>
242
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( wpinv_get_discount_expiration( $discount_id ) ); ?>">
243
-                <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p>
242
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr(wpinv_get_discount_expiration($discount_id)); ?>">
243
+                <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p>
244 244
             </td>
245 245
         </tr>
246
-        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
246
+        <?php do_action('wpinv_discount_form_before_min_total', $post); ?>
247 247
         <tr>
248 248
             <th valign="top" scope="row">
249
-                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
249
+                <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label>
250 250
             </th>
251 251
             <td>
252 252
                 <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
253
-                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
253
+                <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
254 254
             </td>
255 255
         </tr>
256
-        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
256
+        <?php do_action('wpinv_discount_form_before_max_total', $post); ?>
257 257
         <tr>
258 258
             <th valign="top" scope="row">
259
-                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
259
+                <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label>
260 260
             </th>
261 261
             <td>
262 262
                 <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
263
-                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
263
+                <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
264 264
             </td>
265 265
         </tr>
266
-        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
266
+        <?php do_action('wpinv_discount_form_before_recurring', $post); ?>
267 267
         <tr>
268 268
             <th valign="top" scope="row">
269
-                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
269
+                <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label>
270 270
             </th>
271 271
             <td>
272 272
                 <select id="wpinv_discount_recurring" name="recurring" class="medium-text">
273
-                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
274
-                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
273
+                    <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option>
274
+                    <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option>
275 275
                 </select>
276
-                <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p>
276
+                <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p>
277 277
             </td>
278 278
         </tr>
279
-        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
279
+        <?php do_action('wpinv_discount_form_before_max_uses', $post); ?>
280 280
         <tr>
281 281
             <th valign="top" scope="row">
282
-                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
282
+                <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label>
283 283
             </th>
284 284
             <td>
285 285
                 <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
286
-                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
286
+                <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p>
287 287
             </td>
288 288
         </tr>
289
-        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
289
+        <?php do_action('wpinv_discount_form_before_single_use', $post); ?>
290 290
         <tr>
291 291
             <th valign="top" scope="row">
292
-                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
292
+                <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label>
293 293
             </th>
294 294
             <td>
295
-                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
296
-                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
295
+                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>>
296
+                <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span>
297 297
             </td>
298 298
         </tr>
299
-        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
299
+        <?php do_action('wpinv_discount_form_last', $post); ?>
300 300
     </tbody>
301 301
 </table>
302
-<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
302
+<?php do_action('wpinv_discount_form_bottom', $post); ?>
303 303
     <?php
304 304
 }
305 305
 
306
-function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
307
-    $post_type = !empty( $post ) ? $post->post_type : '';
306
+function wpinv_discount_metabox_save($post_id, $post, $update = false) {
307
+    $post_type = !empty($post) ? $post->post_type : '';
308 308
     
309
-    if ( $post_type != 'wpi_discount' ) {
309
+    if ($post_type != 'wpi_discount') {
310 310
         return;
311 311
     }
312 312
     
313
-    if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) {
313
+    if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) {
314 314
         return;
315 315
     }
316 316
     
317
-    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
317
+    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
318 318
         return;
319 319
     }
320 320
     
321
-    if ( !current_user_can( 'manage_options', $post_id ) ) {
321
+    if (!current_user_can('manage_options', $post_id)) {
322 322
         return;
323 323
     }
324 324
     
325
-    return wpinv_store_discount( $post_id, $_POST, $post, $update );
325
+    return wpinv_store_discount($post_id, $_POST, $post, $update);
326 326
 }
327
-add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );
328 327
\ No newline at end of file
328
+add_action('save_post', 'wpinv_discount_metabox_save', 10, 3);
329 329
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_Item {
6 6
     public $ID = 0;
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
     public $filter;
48 48
 
49 49
 
50
-    public function __construct( $_id = false, $_args = array() ) {
51
-        $item = WP_Post::get_instance( $_id );
52
-        return $this->setup_item( $item );
50
+    public function __construct($_id = false, $_args = array()) {
51
+        $item = WP_Post::get_instance($_id);
52
+        return $this->setup_item($item);
53 53
     }
54 54
 
55
-    private function setup_item( $item ) {
56
-        if( ! is_object( $item ) ) {
55
+    private function setup_item($item) {
56
+        if (!is_object($item)) {
57 57
             return false;
58 58
         }
59 59
 
60
-        if( ! is_a( $item, 'WP_Post' ) ) {
60
+        if (!is_a($item, 'WP_Post')) {
61 61
             return false;
62 62
         }
63 63
 
64
-        if( 'wpi_item' !== $item->post_type ) {
64
+        if ('wpi_item' !== $item->post_type) {
65 65
             return false;
66 66
         }
67 67
 
68
-        foreach ( $item as $key => $value ) {
69
-            switch ( $key ) {
68
+        foreach ($item as $key => $value) {
69
+            switch ($key) {
70 70
                 default:
71 71
                     $this->$key = $value;
72 72
                     break;
@@ -76,38 +76,38 @@  discard block
 block discarded – undo
76 76
         return true;
77 77
     }
78 78
 
79
-    public function __get( $key ) {
80
-        if ( method_exists( $this, 'get_' . $key ) ) {
81
-            return call_user_func( array( $this, 'get_' . $key ) );
79
+    public function __get($key) {
80
+        if (method_exists($this, 'get_' . $key)) {
81
+            return call_user_func(array($this, 'get_' . $key));
82 82
         } else {
83
-            return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
83
+            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
84 84
         }
85 85
     }
86 86
 
87
-    public function create( $data = array(), $wp_error = false ) {
88
-        if ( $this->ID != 0 ) {
87
+    public function create($data = array(), $wp_error = false) {
88
+        if ($this->ID != 0) {
89 89
             return false;
90 90
         }
91 91
 
92 92
         $defaults = array(
93 93
             'post_type'   => 'wpi_item',
94 94
             'post_status' => 'draft',
95
-            'post_title'  => __( 'New Invoice Item', 'invoicing' )
95
+            'post_title'  => __('New Invoice Item', 'invoicing')
96 96
         );
97 97
 
98
-        $args = wp_parse_args( $data, $defaults );
98
+        $args = wp_parse_args($data, $defaults);
99 99
 
100
-        do_action( 'wpinv_item_pre_create', $args );
100
+        do_action('wpinv_item_pre_create', $args);
101 101
 
102
-        $id = wp_insert_post( $args, $wp_error );
102
+        $id = wp_insert_post($args, $wp_error);
103 103
         if ($wp_error && is_wp_error($id)) {
104 104
             return $id;
105 105
         }
106
-        if ( !$id ) {
106
+        if (!$id) {
107 107
             return false;
108 108
         }
109 109
         
110
-        $item = WP_Post::get_instance( $id );
110
+        $item = WP_Post::get_instance($id);
111 111
         
112 112
         if (!empty($item) && !empty($data['meta'])) {
113 113
             $this->ID = $item->ID;
@@ -115,47 +115,47 @@  discard block
 block discarded – undo
115 115
         }
116 116
         
117 117
         // Set custom id if not set.
118
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
119
-            $this->save_metas( array( 'custom_id' => $id ) );
118
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
119
+            $this->save_metas(array('custom_id' => $id));
120 120
         }
121 121
 
122
-        do_action( 'wpinv_item_create', $id, $args );
122
+        do_action('wpinv_item_create', $id, $args);
123 123
 
124
-        return $this->setup_item( $item );
124
+        return $this->setup_item($item);
125 125
     }
126 126
     
127
-    public function update( $data = array(), $wp_error = false ) {
128
-        if ( !$this->ID > 0 ) {
127
+    public function update($data = array(), $wp_error = false) {
128
+        if (!$this->ID > 0) {
129 129
             return false;
130 130
         }
131 131
         
132 132
         $data['ID'] = $this->ID;
133 133
 
134
-        do_action( 'wpinv_item_pre_update', $data );
134
+        do_action('wpinv_item_pre_update', $data);
135 135
         
136
-        $id = wp_update_post( $data, $wp_error );
136
+        $id = wp_update_post($data, $wp_error);
137 137
         if ($wp_error && is_wp_error($id)) {
138 138
             return $id;
139 139
         }
140 140
         
141
-        if ( !$id ) {
141
+        if (!$id) {
142 142
             return false;
143 143
         }
144 144
 
145
-        $item = WP_Post::get_instance( $id );
145
+        $item = WP_Post::get_instance($id);
146 146
         if (!empty($item) && !empty($data['meta'])) {
147 147
             $this->ID = $item->ID;
148 148
             $this->save_metas($data['meta']);
149 149
         }
150 150
         
151 151
         // Set custom id if not set.
152
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
153
-            $this->save_metas( array( 'custom_id' => $id ) );
152
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
153
+            $this->save_metas(array('custom_id' => $id));
154 154
         }
155 155
 
156
-        do_action( 'wpinv_item_update', $id, $data );
156
+        do_action('wpinv_item_update', $id, $data);
157 157
 
158
-        return $this->setup_item( $item );
158
+        return $this->setup_item($item);
159 159
     }
160 160
 
161 161
     public function get_ID() {
@@ -163,119 +163,119 @@  discard block
 block discarded – undo
163 163
     }
164 164
 
165 165
     public function get_name() {
166
-        return get_the_title( $this->ID );
166
+        return get_the_title($this->ID);
167 167
     }
168 168
     
169 169
     public function get_title() {
170
-        return get_the_title( $this->ID );
170
+        return get_the_title($this->ID);
171 171
     }
172 172
     
173 173
     public function get_status() {
174
-        return get_post_status( $this->ID );
174
+        return get_post_status($this->ID);
175 175
     }
176 176
     
177 177
     public function get_summary() {
178
-        return get_the_excerpt( $this->ID );
178
+        return get_the_excerpt($this->ID);
179 179
     }
180 180
 
181 181
     public function get_price() {
182
-        if ( ! isset( $this->price ) ) {
183
-            $this->price = get_post_meta( $this->ID, '_wpinv_price', true );
182
+        if (!isset($this->price)) {
183
+            $this->price = get_post_meta($this->ID, '_wpinv_price', true);
184 184
             
185
-            if ( $this->price ) {
186
-                $this->price = wpinv_sanitize_amount( $this->price );
185
+            if ($this->price) {
186
+                $this->price = wpinv_sanitize_amount($this->price);
187 187
             } else {
188 188
                 $this->price = 0;
189 189
             }
190 190
         }
191 191
         
192
-        return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );
192
+        return apply_filters('wpinv_get_item_price', $this->price, $this->ID);
193 193
     }
194 194
     
195 195
     public function get_vat_rule() {
196 196
         global $wpinv_euvat;
197 197
         
198
-        if( !isset( $this->vat_rule ) ) {
199
-            $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );
198
+        if (!isset($this->vat_rule)) {
199
+            $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);
200 200
 
201
-            if ( empty( $this->vat_rule ) ) {        
201
+            if (empty($this->vat_rule)) {        
202 202
                 $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
203 203
             }
204 204
         }
205 205
         
206
-        return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );
206
+        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID);
207 207
     }
208 208
     
209 209
     public function get_vat_class() {
210
-        if( !isset( $this->vat_class ) ) {
211
-            $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );
210
+        if (!isset($this->vat_class)) {
211
+            $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);
212 212
 
213
-            if ( empty( $this->vat_class ) ) {        
213
+            if (empty($this->vat_class)) {        
214 214
                 $this->vat_class = '_standard';
215 215
             }
216 216
         }
217 217
         
218
-        return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );
218
+        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID);
219 219
     }
220 220
 
221 221
     public function get_type() {
222
-        if( ! isset( $this->type ) ) {
223
-            $this->type = get_post_meta( $this->ID, '_wpinv_type', true );
222
+        if (!isset($this->type)) {
223
+            $this->type = get_post_meta($this->ID, '_wpinv_type', true);
224 224
 
225
-            if ( empty( $this->type ) ) {
225
+            if (empty($this->type)) {
226 226
                 $this->type = 'custom';
227 227
             }
228 228
         }
229 229
 
230
-        return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );
230
+        return apply_filters('wpinv_get_item_type', $this->type, $this->ID);
231 231
     }
232 232
     
233 233
     public function get_custom_id() {
234
-        $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true );
234
+        $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true);
235 235
 
236
-        return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID );
236
+        return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID);
237 237
     }
238 238
     
239 239
     public function get_custom_name() {
240
-        $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true );
240
+        $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true);
241 241
 
242
-        return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID );
242
+        return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID);
243 243
     }
244 244
     
245 245
     public function get_custom_singular_name() {
246
-        $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true );
246
+        $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true);
247 247
 
248
-        return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID );
248
+        return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID);
249 249
     }
250 250
     
251 251
     public function get_editable() {
252
-        $editable = get_post_meta( $this->ID, '_wpinv_editable', true );
252
+        $editable = get_post_meta($this->ID, '_wpinv_editable', true);
253 253
 
254
-        return apply_filters( 'wpinv_item_get_editable', $editable, $this->ID );
254
+        return apply_filters('wpinv_item_get_editable', $editable, $this->ID);
255 255
     }
256 256
     
257 257
     public function get_excerpt() {
258
-        $excerpt = get_the_excerpt( $this->ID );
258
+        $excerpt = get_the_excerpt($this->ID);
259 259
         
260
-        return apply_filters( 'wpinv_item_get_excerpt', $excerpt, $this->ID );
260
+        return apply_filters('wpinv_item_get_excerpt', $excerpt, $this->ID);
261 261
     }
262 262
     
263 263
     public function get_is_recurring() {
264
-        $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );
264
+        $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);
265 265
 
266
-        return apply_filters( 'wpinv_item_get_is_recurring', $is_recurring, $this->ID );
266
+        return apply_filters('wpinv_item_get_is_recurring', $is_recurring, $this->ID);
267 267
 
268 268
     }
269 269
     
270
-    public function get_recurring_period( $full = false ) {
271
-        $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );
270
+    public function get_recurring_period($full = false) {
271
+        $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);
272 272
         
273
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
273
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
274 274
             $period = 'D';
275 275
         }
276 276
         
277
-        if ( $full ) {
278
-            switch( $period ) {
277
+        if ($full) {
278
+            switch ($period) {
279 279
                 case 'D':
280 280
                     $period = 'day';
281 281
                 break;
@@ -291,40 +291,40 @@  discard block
 block discarded – undo
291 291
             }
292 292
         }
293 293
 
294
-        return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );
294
+        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID);
295 295
     }
296 296
     
297 297
     public function get_recurring_interval() {
298
-        $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );
298
+        $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true);
299 299
         
300
-        if ( !$interval > 0 ) {
300
+        if (!$interval > 0) {
301 301
             $interval = 1;
302 302
         }
303 303
 
304
-        return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );
304
+        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID);
305 305
     }
306 306
     
307 307
     public function get_recurring_limit() {
308
-        $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );
308
+        $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);
309 309
 
310
-        return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );
310
+        return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID);
311 311
     }
312 312
     
313 313
     public function get_free_trial() {
314
-        $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );
314
+        $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);
315 315
 
316
-        return apply_filters( 'wpinv_item_get_free_trial', $free_trial, $this->ID );
316
+        return apply_filters('wpinv_item_get_free_trial', $free_trial, $this->ID);
317 317
     }
318 318
     
319
-    public function get_trial_period( $full = false ) {
320
-        $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );
319
+    public function get_trial_period($full = false) {
320
+        $period = get_post_meta($this->ID, '_wpinv_trial_period', true);
321 321
         
322
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
322
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
323 323
             $period = 'D';
324 324
         }
325 325
         
326
-        if ( $full ) {
327
-            switch( $period ) {
326
+        if ($full) {
327
+            switch ($period) {
328 328
                 case 'D':
329 329
                     $period = 'day';
330 330
                 break;
@@ -340,54 +340,54 @@  discard block
 block discarded – undo
340 340
             }
341 341
         }
342 342
 
343
-        return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );
343
+        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID);
344 344
     }
345 345
     
346 346
     public function get_trial_interval() {
347
-        $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );
347
+        $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));
348 348
         
349
-        if ( !$interval > 0 ) {
349
+        if (!$interval > 0) {
350 350
             $interval = 1;
351 351
         }
352 352
 
353
-        return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );
353
+        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID);
354 354
     }
355 355
     
356 356
     public function get_the_price() {
357
-        $item_price = wpinv_price( wpinv_format_amount( $this->price ) );
357
+        $item_price = wpinv_price(wpinv_format_amount($this->price));
358 358
         
359
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
359
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
360 360
     }
361 361
     
362 362
     public function is_recurring() {
363 363
         $is_recurring = $this->get_is_recurring();
364 364
 
365
-        return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );
365
+        return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID);
366 366
     }
367 367
     
368 368
     public function has_free_trial() {
369 369
         $free_trial = $this->is_recurring() && $this->get_free_trial() ? true : false;
370 370
 
371
-        return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );
371
+        return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID);
372 372
     }
373 373
 
374 374
     public function is_free() {
375 375
         $is_free = false;
376 376
         
377
-        $price = get_post_meta( $this->ID, '_wpinv_price', true );
377
+        $price = get_post_meta($this->ID, '_wpinv_price', true);
378 378
 
379
-        if ( (float)$price == 0 ) {
379
+        if ((float)$price == 0) {
380 380
             $is_free = true;
381 381
         }
382 382
 
383
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
383
+        return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID);
384 384
 
385 385
     }
386 386
     
387 387
     public function is_package() {
388 388
         $is_package = $this->get_type() == 'package' ? true : false;
389 389
 
390
-        return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID );
390
+        return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID);
391 391
 
392 392
     }
393 393
     
@@ -396,15 +396,15 @@  discard block
 block discarded – undo
396 396
 
397 397
         $is_editable = $editable === 0 || $editable === '0' ? false : true;
398 398
 
399
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID );
399
+        return (bool)apply_filters('wpinv_item_is_editable', $is_editable, $this->ID);
400 400
     }
401 401
     
402
-    public function save_metas( $metas = array() ) {
403
-        if ( empty( $metas ) ) {
402
+    public function save_metas($metas = array()) {
403
+        if (empty($metas)) {
404 404
             return false;
405 405
         }
406 406
         
407
-        foreach ( $metas as $meta_key => $meta_value ) {
407
+        foreach ($metas as $meta_key => $meta_value) {
408 408
             $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;
409 409
             
410 410
             $this->update_meta($meta_key, $meta_value);
@@ -413,66 +413,66 @@  discard block
 block discarded – undo
413 413
         return true;
414 414
     }
415 415
 
416
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
417
-        if ( empty( $meta_key ) ) {
416
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
417
+        if (empty($meta_key)) {
418 418
             return false;
419 419
         }
420 420
         
421
-        $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );
421
+        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID);
422 422
 
423
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
423
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
424 424
     }
425 425
     
426
-    public function get_fees( $type = 'fee', $item_id = 0 ) {
426
+    public function get_fees($type = 'fee', $item_id = 0) {
427 427
         global $wpi_session;
428 428
         
429
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
429
+        $fees = $wpi_session->get('wpi_cart_fees');
430 430
 
431
-        if ( ! wpinv_get_cart_contents() ) {
431
+        if (!wpinv_get_cart_contents()) {
432 432
             // We can only get item type fees when the cart is empty
433 433
             $type = 'custom';
434 434
         }
435 435
 
436
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
437
-            foreach( $fees as $key => $fee ) {
438
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
439
-                    unset( $fees[ $key ] );
436
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
437
+            foreach ($fees as $key => $fee) {
438
+                if (!empty($fee['type']) && $type != $fee['type']) {
439
+                    unset($fees[$key]);
440 440
                 }
441 441
             }
442 442
         }
443 443
 
444
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
444
+        if (!empty($fees) && !empty($item_id)) {
445 445
             // Remove fees that don't belong to the specified Item
446
-            foreach ( $fees as $key => $fee ) {
447
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
448
-                    unset( $fees[ $key ] );
446
+            foreach ($fees as $key => $fee) {
447
+                if ((int)$item_id !== (int)$fee['custom_id']) {
448
+                    unset($fees[$key]);
449 449
                 }
450 450
             }
451 451
         }
452 452
 
453
-        if ( ! empty( $fees ) ) {
453
+        if (!empty($fees)) {
454 454
             // Remove fees that belong to a specific item but are not in the cart
455
-            foreach( $fees as $key => $fee ) {
456
-                if( empty( $fee['custom_id'] ) ) {
455
+            foreach ($fees as $key => $fee) {
456
+                if (empty($fee['custom_id'])) {
457 457
                     continue;
458 458
                 }
459 459
 
460
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
461
-                    unset( $fees[ $key ] );
460
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
461
+                    unset($fees[$key]);
462 462
                 }
463 463
             }
464 464
         }
465 465
 
466
-        return ! empty( $fees ) ? $fees : array();
466
+        return !empty($fees) ? $fees : array();
467 467
     }
468 468
     
469 469
     public function can_purchase() {
470 470
         $can_purchase = true;
471 471
 
472
-        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
472
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
473 473
             $can_purchase = false;
474 474
         }
475 475
 
476
-        return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
476
+        return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
477 477
     }
478 478
 }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = new WPInv_Item( $value );
14
+            $item = new WPInv_Item($value);
15 15
 
16
-            if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
16
+            if (!empty($item) && $item->post_type == 'wpi_item') {
17 17
                 return $item;
18 18
             }
19 19
             return false;
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
 
23 23
         case 'slug':
24 24
         case 'name':
25
-            $posts = get_posts( array(
25
+            $posts = get_posts(array(
26 26
                 'post_type'      => 'wpi_item',
27 27
                 'name'           => $value,
28 28
                 'posts_per_page' => 1,
29 29
                 'post_status'    => 'any'
30
-            ) );
30
+            ));
31 31
 
32 32
             break;
33 33
         case 'custom_id':
34
-            if ( empty( $value ) || empty( $type ) ) {
34
+            if (empty($value) || empty($type)) {
35 35
                 return false;
36 36
             }
37 37
             
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
                 'post_status'    => 'any',
52 52
                 'orderby'        => 'ID',
53 53
                 'order'          => 'ASC',
54
-                'meta_query'     => array( $meta_query )
54
+                'meta_query'     => array($meta_query)
55 55
             );
56 56
             
57
-            $posts = get_posts( $args );
57
+            $posts = get_posts($args);
58 58
 
59 59
             break;
60 60
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
             return false;
63 63
     }
64 64
     
65
-    if ( !empty( $posts[0] ) ) {
66
-        $item = new WPInv_Item( $posts[0]->ID );
65
+    if (!empty($posts[0])) {
66
+        $item = new WPInv_Item($posts[0]->ID);
67 67
 
68
-        if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
68
+        if (!empty($item) && $item->post_type == 'wpi_item') {
69 69
             return $item;
70 70
         }
71 71
     }
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
     return false;
74 74
 }
75 75
 
76
-function wpinv_get_item( $item = 0 ) {
77
-    if ( is_numeric( $item ) ) {
78
-        $item = get_post( $item );
79
-        if ( ! $item || 'wpi_item' !== $item->post_type )
76
+function wpinv_get_item($item = 0) {
77
+    if (is_numeric($item)) {
78
+        $item = get_post($item);
79
+        if (!$item || 'wpi_item' !== $item->post_type)
80 80
             return null;
81 81
         return $item;
82 82
     }
@@ -89,150 +89,150 @@  discard block
 block discarded – undo
89 89
 
90 90
     $item = get_posts($args);
91 91
 
92
-    if ( $item ) {
92
+    if ($item) {
93 93
         return $item[0];
94 94
     }
95 95
 
96 96
     return null;
97 97
 }
98 98
 
99
-function wpinv_is_free_item( $item_id = 0 ) {
100
-    if( empty( $item_id ) ) {
99
+function wpinv_is_free_item($item_id = 0) {
100
+    if (empty($item_id)) {
101 101
         return false;
102 102
     }
103 103
 
104
-    $item = new WPInv_Item( $item_id );
104
+    $item = new WPInv_Item($item_id);
105 105
     
106 106
     return $item->is_free();
107 107
 }
108 108
 
109
-function wpinv_item_is_editable( $item = 0 ) {
110
-    if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) {
109
+function wpinv_item_is_editable($item = 0) {
110
+    if (!empty($item) && is_a($item, 'WP_Post')) {
111 111
         $item = $item->ID;
112 112
     }
113 113
         
114
-    if ( empty( $item ) ) {
114
+    if (empty($item)) {
115 115
         return true;
116 116
     }
117 117
 
118
-    $item = new WPInv_Item( $item );
118
+    $item = new WPInv_Item($item);
119 119
     
120
-    return (bool) $item->is_editable();
120
+    return (bool)$item->is_editable();
121 121
 }
122 122
 
123
-function wpinv_get_item_price( $item_id = 0 ) {
124
-    if( empty( $item_id ) ) {
123
+function wpinv_get_item_price($item_id = 0) {
124
+    if (empty($item_id)) {
125 125
         return false;
126 126
     }
127 127
 
128
-    $item = new WPInv_Item( $item_id );
128
+    $item = new WPInv_Item($item_id);
129 129
     
130 130
     return $item->get_price();
131 131
 }
132 132
 
133
-function wpinv_is_recurring_item( $item_id = 0 ) {
134
-    if( empty( $item_id ) ) {
133
+function wpinv_is_recurring_item($item_id = 0) {
134
+    if (empty($item_id)) {
135 135
         return false;
136 136
     }
137 137
 
138
-    $item = new WPInv_Item( $item_id );
138
+    $item = new WPInv_Item($item_id);
139 139
     
140 140
     return $item->is_recurring();
141 141
 }
142 142
 
143
-function wpinv_item_price( $item_id = 0 ) {
144
-    if( empty( $item_id ) ) {
143
+function wpinv_item_price($item_id = 0) {
144
+    if (empty($item_id)) {
145 145
         return false;
146 146
     }
147 147
 
148
-    $price = wpinv_get_item_price( $item_id );
149
-    $price = wpinv_price( wpinv_format_amount( $price ) );
148
+    $price = wpinv_get_item_price($item_id);
149
+    $price = wpinv_price(wpinv_format_amount($price));
150 150
     
151
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
151
+    return apply_filters('wpinv_item_price', $price, $item_id);
152 152
 }
153 153
 
154
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
155
-    if ( empty( $item_id ) ) {
154
+function wpinv_item_show_price($item_id = 0, $echo = true) {
155
+    if (empty($item_id)) {
156 156
         $item_id = get_the_ID();
157 157
     }
158 158
 
159
-    $price = wpinv_item_price( $item_id );
159
+    $price = wpinv_item_price($item_id);
160 160
 
161
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
161
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
162 162
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
163
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
163
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
164 164
 
165
-    if ( $echo ) {
165
+    if ($echo) {
166 166
         echo $formatted_price;
167 167
     } else {
168 168
         return $formatted_price;
169 169
     }
170 170
 }
171 171
 
172
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
173
-    if ( is_null( $amount_override ) ) {
174
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
172
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
173
+    if (is_null($amount_override)) {
174
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
175 175
     } else {
176 176
         $original_price = $amount_override;
177 177
     }
178 178
     
179 179
     $price = $original_price;
180 180
 
181
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
181
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
182 182
 }
183 183
 
184
-function wpinv_item_custom_singular_name( $item_id ) {
185
-    if( empty( $item_id ) ) {
184
+function wpinv_item_custom_singular_name($item_id) {
185
+    if (empty($item_id)) {
186 186
         return false;
187 187
     }
188 188
 
189
-    $item = new WPInv_Item( $item_id );
189
+    $item = new WPInv_Item($item_id);
190 190
     
191 191
     return $item->get_custom_singular_name();
192 192
 }
193 193
 
194 194
 function wpinv_get_item_types() {
195 195
     $item_types = array(
196
-            'custom'    => __( 'Standard', 'invoicing' ),
197
-            'fee'       => __( 'Fee', 'invoicing' ),
196
+            'custom'    => __('Standard', 'invoicing'),
197
+            'fee'       => __('Fee', 'invoicing'),
198 198
         );
199
-    return apply_filters( 'wpinv_get_item_types', $item_types );
199
+    return apply_filters('wpinv_get_item_types', $item_types);
200 200
 }
201 201
 
202 202
 function wpinv_item_types() {
203 203
     $item_types = wpinv_get_item_types();
204 204
     
205
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
205
+    return (!empty($item_types) ? array_keys($item_types) : array());
206 206
 }
207 207
 
208
-function wpinv_get_item_type( $item_id ) {
209
-    if( empty( $item_id ) ) {
208
+function wpinv_get_item_type($item_id) {
209
+    if (empty($item_id)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    $item = new WPInv_Item( $item_id );
213
+    $item = new WPInv_Item($item_id);
214 214
     
215 215
     return $item->get_type();
216 216
 }
217 217
 
218
-function wpinv_item_type( $item_id ) {
218
+function wpinv_item_type($item_id) {
219 219
     $item_types = wpinv_get_item_types();
220 220
     
221
-    $item_type = wpinv_get_item_type( $item_id );
221
+    $item_type = wpinv_get_item_type($item_id);
222 222
     
223
-    if ( empty( $item_type ) ) {
223
+    if (empty($item_type)) {
224 224
         $item_type = '-';
225 225
     }
226 226
     
227
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
227
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
228 228
 
229
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
229
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
230 230
 }
231 231
 
232
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
232
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
233 233
     global $wpinv_logs;
234 234
     
235
-    if ( empty( $wpinv_logs ) ) {
235
+    if (empty($wpinv_logs)) {
236 236
         return false;
237 237
     }
238 238
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         'log_type'		=> 'wpi_item'
242 242
     );
243 243
 
244
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
244
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
245 245
 
246 246
     $log_meta = array(
247 247
         'user_info'	=> $user_info,
@@ -251,253 +251,253 @@  discard block
 block discarded – undo
251 251
         'invoice_id'=> $invoice_id,
252 252
     );
253 253
 
254
-    $wpinv_logs->insert_log( $log_data, $log_meta );
254
+    $wpinv_logs->insert_log($log_data, $log_meta);
255 255
 }
256 256
 
257
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
258
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
257
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
258
+    if ('wpi_item' !== get_post_type($item_id))
259 259
         return;
260 260
 
261 261
     global $wpinv_logs;
262 262
     
263
-    if ( empty( $wpinv_logs ) ) {
263
+    if (empty($wpinv_logs)) {
264 264
         return false;
265 265
     }
266 266
 
267 267
     // Remove all log entries related to this item
268
-    $wpinv_logs->delete_logs( $item_id );
268
+    $wpinv_logs->delete_logs($item_id);
269 269
 }
270
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
270
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
271 271
 
272
-function wpinv_get_random_item( $post_ids = true ) {
273
-    wpinv_get_random_items( 1, $post_ids );
272
+function wpinv_get_random_item($post_ids = true) {
273
+    wpinv_get_random_items(1, $post_ids);
274 274
 }
275 275
 
276
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
277
-    if ( $post_ids ) {
278
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
276
+function wpinv_get_random_items($num = 3, $post_ids = true) {
277
+    if ($post_ids) {
278
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
279 279
     } else {
280
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
280
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
281 281
     }
282 282
     
283
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
283
+    $args = apply_filters('wpinv_get_random_items', $args);
284 284
     
285
-    return get_posts( $args );
285
+    return get_posts($args);
286 286
 }
287 287
 
288
-function wpinv_get_item_token( $url = '' ) {
288
+function wpinv_get_item_token($url = '') {
289 289
     $args    = array();
290
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
291
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
290
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
291
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
292 292
 
293
-    $parts   = parse_url( $url );
293
+    $parts   = parse_url($url);
294 294
     $options = array();
295 295
 
296
-    if ( isset( $parts['query'] ) ) {
297
-        wp_parse_str( $parts['query'], $query_args );
296
+    if (isset($parts['query'])) {
297
+        wp_parse_str($parts['query'], $query_args);
298 298
 
299
-        if ( ! empty( $query_args['o'] ) ) {
300
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
299
+        if (!empty($query_args['o'])) {
300
+            $options = explode(':', rawurldecode($query_args['o']));
301 301
 
302
-            if ( in_array( 'ip', $options ) ) {
302
+            if (in_array('ip', $options)) {
303 303
                 $args['ip'] = wpinv_get_ip();
304 304
             }
305 305
 
306
-            if ( in_array( 'ua', $options ) ) {
306
+            if (in_array('ua', $options)) {
307 307
                 $ua = wpinv_get_user_agent();
308
-                $args['user_agent'] = rawurlencode( $ua );
308
+                $args['user_agent'] = rawurlencode($ua);
309 309
             }
310 310
         }
311 311
     }
312 312
 
313
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
313
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
314 314
 
315 315
     $args['secret'] = $secret;
316 316
     $args['token']  = false;
317 317
 
318
-    $url   = add_query_arg( $args, $url );
319
-    $parts = parse_url( $url );
318
+    $url   = add_query_arg($args, $url);
319
+    $parts = parse_url($url);
320 320
 
321
-    if ( ! isset( $parts['path'] ) ) {
321
+    if (!isset($parts['path'])) {
322 322
         $parts['path'] = '';
323 323
     }
324 324
 
325
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
325
+    $token = md5($parts['path'] . '?' . $parts['query']);
326 326
 
327 327
     return $token;
328 328
 }
329 329
 
330
-function wpinv_validate_url_token( $url = '' ) {
330
+function wpinv_validate_url_token($url = '') {
331 331
     $ret   = false;
332
-    $parts = parse_url( $url );
332
+    $parts = parse_url($url);
333 333
 
334
-    if ( isset( $parts['query'] ) ) {
335
-        wp_parse_str( $parts['query'], $query_args );
334
+    if (isset($parts['query'])) {
335
+        wp_parse_str($parts['query'], $query_args);
336 336
 
337
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
337
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
338 338
             'item',
339 339
             'ttl',
340 340
             'token'
341
-        ) );
341
+        ));
342 342
 
343 343
         $remove = array();
344 344
 
345
-        foreach( $query_args as $key => $value ) {
346
-            if( false === in_array( $key, $allowed ) ) {
345
+        foreach ($query_args as $key => $value) {
346
+            if (false === in_array($key, $allowed)) {
347 347
                 $remove[] = $key;
348 348
             }
349 349
         }
350 350
 
351
-        if( ! empty( $remove ) ) {
352
-            $url = remove_query_arg( $remove, $url );
351
+        if (!empty($remove)) {
352
+            $url = remove_query_arg($remove, $url);
353 353
         }
354 354
 
355
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
356
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
355
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
356
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
357 357
         }
358 358
 
359
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
359
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
360 360
             $ret = true;
361 361
         }
362 362
 
363 363
     }
364 364
 
365
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
365
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
366 366
 }
367 367
 
368
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
368
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
369 369
     $cart_items = wpinv_get_cart_contents();
370 370
 
371 371
     $ret = false;
372 372
 
373
-    if ( is_array( $cart_items ) ) {
374
-        foreach ( $cart_items as $item ) {
375
-            if ( $item['id'] == $item_id ) {
373
+    if (is_array($cart_items)) {
374
+        foreach ($cart_items as $item) {
375
+            if ($item['id'] == $item_id) {
376 376
                 $ret = true;
377 377
                 break;
378 378
             }
379 379
         }
380 380
     }
381 381
 
382
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
382
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
383 383
 }
384 384
 
385
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
385
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
386 386
     $tax = 0;
387
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
388
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
389
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
387
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
388
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
389
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
390 390
 
391
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
391
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
392 392
     }
393 393
 
394
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
394
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
395 395
 }
396 396
 
397
-function wpinv_cart_item_price( $item ) {
397
+function wpinv_cart_item_price($item) {
398 398
     $use_taxes  = wpinv_use_taxes();
399
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
400
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
401
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
402
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
403
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
404
-    
405
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
406
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
399
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
400
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
401
+    $options    = isset($item['options']) ? $item['options'] : array();
402
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
403
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
404
+    
405
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
406
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
407 407
             $price += $tax;
408 408
         }
409 409
         
410
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
410
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
411 411
             $price -= $tax;
412 412
         }        
413 413
     }
414 414
 
415
-    $price = wpinv_price( wpinv_format_amount( $price ) );
415
+    $price = wpinv_price(wpinv_format_amount($price));
416 416
 
417
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
417
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
418 418
 }
419 419
 
420
-function wpinv_cart_item_subtotal( $item ) {
421
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
422
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
420
+function wpinv_cart_item_subtotal($item) {
421
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
422
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
423 423
 
424
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
424
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
425 425
 }
426 426
 
427
-function wpinv_cart_item_tax( $item ) {
427
+function wpinv_cart_item_tax($item) {
428 428
     $tax        = '';
429 429
     $tax_rate   = '';
430 430
     
431
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
432
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
433
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
434
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
431
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
432
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
433
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
434
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
435 435
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
436 436
     }
437 437
     
438
-    $tax        = $tax . $tax_rate;
438
+    $tax = $tax . $tax_rate;
439 439
     
440
-    if ( $tax === '' ) {
440
+    if ($tax === '') {
441 441
         $tax = 0; // Zero tax
442 442
     }
443 443
 
444
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
444
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
445 445
 }
446 446
 
447
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
447
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
448 448
     $price = 0;
449 449
     
450 450
     // Set custom price
451
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
451
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
452 452
         $price = $cart_item['custom_price'];
453 453
     } else {
454
-        $variable_prices = wpinv_has_variable_prices( $item_id );
454
+        $variable_prices = wpinv_has_variable_prices($item_id);
455 455
 
456
-        if ( $variable_prices ) {
457
-            $prices = wpinv_get_variable_prices( $item_id );
456
+        if ($variable_prices) {
457
+            $prices = wpinv_get_variable_prices($item_id);
458 458
 
459
-            if ( $prices ) {
460
-                if( ! empty( $options ) ) {
461
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
459
+            if ($prices) {
460
+                if (!empty($options)) {
461
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
462 462
                 } else {
463 463
                     $price = false;
464 464
                 }
465 465
             }
466 466
         }
467 467
 
468
-        if( ! $variable_prices || false === $price ) {
468
+        if (!$variable_prices || false === $price) {
469 469
             // Get the standard Item price if not using variable prices
470
-            $price = wpinv_get_item_price( $item_id );
470
+            $price = wpinv_get_item_price($item_id);
471 471
         }
472 472
     }
473 473
 
474
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
475
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
474
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
475
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
476 476
     }
477 477
 
478
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
478
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
479 479
 }
480 480
 
481
-function wpinv_get_cart_item_price_id( $item = array() ) {
482
-    if( isset( $item['item_number'] ) ) {
483
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
481
+function wpinv_get_cart_item_price_id($item = array()) {
482
+    if (isset($item['item_number'])) {
483
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
484 484
     } else {
485
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
485
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
486 486
     }
487 487
     return $price_id;
488 488
 }
489 489
 
490
-function wpinv_get_cart_item_price_name( $item = array() ) {
491
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
492
-    $prices   = wpinv_get_variable_prices( $item['id'] );
493
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
494
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
490
+function wpinv_get_cart_item_price_name($item = array()) {
491
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
492
+    $prices   = wpinv_get_variable_prices($item['id']);
493
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
494
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
495 495
 }
496 496
 
497
-function wpinv_get_cart_item_name( $item = array() ) {
498
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
497
+function wpinv_get_cart_item_name($item = array()) {
498
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
499 499
 
500
-    if ( empty( $item_title ) ) {
500
+    if (empty($item_title)) {
501 501
         $item_title = $item['id'];
502 502
     }
503 503
 
@@ -507,23 +507,23 @@  discard block
 block discarded – undo
507 507
     }
508 508
     */
509 509
 
510
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
510
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
511 511
 }
512 512
 
513
-function wpinv_has_variable_prices( $item_id = 0 ) {
513
+function wpinv_has_variable_prices($item_id = 0) {
514 514
     return false;
515 515
 }
516 516
 
517
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
517
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
518 518
     $cart_items = wpinv_get_cart_contents();
519 519
 
520
-    if ( !is_array( $cart_items ) ) {
520
+    if (!is_array($cart_items)) {
521 521
         return false; // Empty cart
522 522
     } else {
523
-        foreach ( $cart_items as $position => $item ) {
524
-            if ( $item['id'] == $item_id ) {
525
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
526
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
523
+        foreach ($cart_items as $position => $item) {
524
+            if ($item['id'] == $item_id) {
525
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
526
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
527 527
                         return $position;
528 528
                     }
529 529
                 } else {
@@ -536,80 +536,80 @@  discard block
 block discarded – undo
536 536
     return false; // Not found
537 537
 }
538 538
 
539
-function wpinv_get_cart_item_quantity( $item ) {
540
-    if ( wpinv_item_quantities_enabled() ) {
541
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
539
+function wpinv_get_cart_item_quantity($item) {
540
+    if (wpinv_item_quantities_enabled()) {
541
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
542 542
     } else {
543 543
         $quantity = 1;
544 544
     }
545 545
     
546
-    if ( $quantity < 1 ) {
546
+    if ($quantity < 1) {
547 547
         $quantity = 1;
548 548
     }
549 549
     
550
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
550
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
551 551
 }
552 552
 
553
-function wpinv_get_item_suffix( $item, $html = true ) {
554
-    if ( empty( $item ) ) {
553
+function wpinv_get_item_suffix($item, $html = true) {
554
+    if (empty($item)) {
555 555
         return NULL;
556 556
     }
557 557
     
558
-    if ( is_int( $item ) ) {
559
-        $item = new WPInv_Item( $item );
558
+    if (is_int($item)) {
559
+        $item = new WPInv_Item($item);
560 560
     }
561 561
     
562
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
562
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
563 563
         return NULL;
564 564
     }
565 565
     
566
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
566
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
567 567
     
568
-    if ( !$html && $suffix ) {
569
-        $suffix = strip_tags( $suffix );
568
+    if (!$html && $suffix) {
569
+        $suffix = strip_tags($suffix);
570 570
     }
571 571
     
572
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
572
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
573 573
 }
574 574
 
575
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
576
-    if ( empty( $item ) ) {
575
+function wpinv_remove_item($item = 0, $force_delete = false) {
576
+    if (empty($item)) {
577 577
         return NULL;
578 578
     }
579 579
     
580
-    if ( is_int( $item ) ) {
581
-        $item = new WPInv_Item( $item );
580
+    if (is_int($item)) {
581
+        $item = new WPInv_Item($item);
582 582
     }
583 583
     
584
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
584
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
585 585
         return NULL;
586 586
     }
587 587
     
588
-    do_action( 'wpinv_pre_delete_item', $item );
588
+    do_action('wpinv_pre_delete_item', $item);
589 589
 
590
-    wp_delete_post( $item->ID, $force_delete );
590
+    wp_delete_post($item->ID, $force_delete);
591 591
 
592
-    do_action( 'wpinv_post_delete_item', $item );
592
+    do_action('wpinv_post_delete_item', $item);
593 593
 }
594 594
 
595
-function wpinv_can_delete_item( $post_id ) {
596
-    $return = current_user_can( 'manage_options' ) ? true : false;
595
+function wpinv_can_delete_item($post_id) {
596
+    $return = current_user_can('manage_options') ? true : false;
597 597
     
598
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
598
+    if ($return && wpinv_item_in_use($post_id)) {
599 599
         $return = false; // Don't delete item already use in invoices.
600 600
     }
601 601
     
602
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
602
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
603 603
 }
604 604
 
605 605
 function wpinv_admin_action_delete() {
606 606
     $screen = get_current_screen();
607 607
     
608
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
608
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
609 609
         $post_ids = array();
610 610
         
611
-        foreach ( $_REQUEST['post'] as $post_id ) {
612
-            if ( !wpinv_can_delete_item( $post_id ) ) {
611
+        foreach ($_REQUEST['post'] as $post_id) {
612
+            if (!wpinv_can_delete_item($post_id)) {
613 613
                 continue;
614 614
             }
615 615
             
@@ -619,86 +619,86 @@  discard block
 block discarded – undo
619 619
         $_REQUEST['post'] = $post_ids;
620 620
     }
621 621
 }
622
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
623
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
622
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
623
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
624 624
 
625
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
626
-    if ( $post->post_type == 'wpi_item' ) {
627
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
625
+function wpinv_check_delete_item($check, $post, $force_delete) {
626
+    if ($post->post_type == 'wpi_item') {
627
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
628 628
             return true;
629 629
         }
630 630
     }
631 631
     
632 632
     return $check;
633 633
 }
634
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
634
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
635 635
 
636
-function wpinv_item_in_use( $item_id ) {
636
+function wpinv_item_in_use($item_id) {
637 637
     global $wpdb, $wpi_items_in_use;
638 638
     
639
-    if ( !$item_id > 0 ) {
639
+    if (!$item_id > 0) {
640 640
         return false;
641 641
     }
642 642
     
643
-    if ( !empty( $wpi_items_in_use ) ) {
644
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
643
+    if (!empty($wpi_items_in_use)) {
644
+        if (isset($wpi_items_in_use[$item_id])) {
645 645
             return $wpi_items_in_use[$item_id];
646 646
         }
647 647
     } else {
648 648
         $wpi_items_in_use = array();
649 649
     }
650 650
     
651
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
651
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
652 652
     
653
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
654
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
653
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
654
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
655 655
     
656 656
     $wpi_items_in_use[$item_id] = $in_use;
657 657
     
658 658
     return $in_use;
659 659
 }
660 660
 
661
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
661
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
662 662
     // Set some defaults
663 663
     $defaults = array(
664
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
665
-        'title'                => '',                                                      // Required. Item title.
666
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
667
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
668
-        'status'               => 'pending',                                               // Optional. pending, publish
669
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
670
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
671
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
672
-        'editable'             => true,                                                    // Optional. Item editable from Items list page? Default true.
673
-        'excerpt'              => '',                                                      // Optional. Item short description
664
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
665
+        'title'                => '', // Required. Item title.
666
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
667
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
668
+        'status'               => 'pending', // Optional. pending, publish
669
+        'custom_name'          => '', // Optional. Plural sub title for item.
670
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
671
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
672
+        'editable'             => true, // Optional. Item editable from Items list page? Default true.
673
+        'excerpt'              => '', // Optional. Item short description
674 674
         /* Recurring item fields */
675
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
676
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
677
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
678
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
679
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
680
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
675
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
676
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
677
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
678
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
679
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
680
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
+        'trial_interval'       => 0, // Optional. Any integer number.
682 682
     );
683 683
 
684
-    $data = wp_parse_args( $args, $defaults );
684
+    $data = wp_parse_args($args, $defaults);
685 685
 
686
-    if ( empty( $data['type'] ) ) {
686
+    if (empty($data['type'])) {
687 687
         $data['type'] = 'custom';
688 688
     }
689 689
 
690
-    if ( !empty( $data['custom_id'] ) ) {
691
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
690
+    if (!empty($data['custom_id'])) {
691
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
692 692
     } else {
693 693
         $item = NULL;
694 694
     }
695 695
 
696
-    if ( !empty( $item ) ) {
697
-        if ( $force_update ) {
698
-            if ( empty( $args['ID'] ) ) {
696
+    if (!empty($item)) {
697
+        if ($force_update) {
698
+            if (empty($args['ID'])) {
699 699
                 $args['ID'] = $item->ID;
700 700
             }
701
-            return wpinv_update_item( $args, $wp_error );
701
+            return wpinv_update_item($args, $wp_error);
702 702
         }
703 703
 
704 704
         return $item;
@@ -709,19 +709,19 @@  discard block
 block discarded – undo
709 709
     $meta['custom_id']              = $data['custom_id'];
710 710
     $meta['custom_singular_name']   = $data['custom_singular_name'];
711 711
     $meta['custom_name']            = $data['custom_name'];
712
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
712
+    $meta['price']                  = wpinv_round_amount($data['price']);
713 713
     $meta['editable']               = (int)$data['editable'];
714 714
     $meta['vat_rule']               = $data['vat_rule'];
715 715
     $meta['vat_class']              = '_standard';
716 716
     
717
-    if ( !empty( $data['is_recurring'] ) ) {
717
+    if (!empty($data['is_recurring'])) {
718 718
         $meta['is_recurring']       = $data['is_recurring'];
719 719
         $meta['recurring_period']   = $data['recurring_period'];
720
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
721
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
720
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
721
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
722 722
         $meta['free_trial']         = $data['free_trial'];
723 723
         $meta['trial_period']       = $data['trial_period'];
724
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
724
+        $meta['trial_interval']     = absint($data['trial_interval']);
725 725
     } else {
726 726
         $meta['is_recurring']       = 0;
727 727
         $meta['recurring_period']   = '';
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
         $meta['trial_interval']     = '';
733 733
     }
734 734
     
735
-    $post_data  = array( 
735
+    $post_data = array( 
736 736
         'post_title'    => $data['title'],
737 737
         'post_excerpt'  => $data['excerpt'],
738 738
         'post_status'   => $data['status'],
@@ -740,86 +740,86 @@  discard block
 block discarded – undo
740 740
     );
741 741
 
742 742
     $item = new WPInv_Item();
743
-    $return = $item->create( $post_data, $wp_error );
743
+    $return = $item->create($post_data, $wp_error);
744 744
 
745
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
745
+    if ($return && !empty($item) && !is_wp_error($return)) {
746 746
         return $item;
747 747
     }
748 748
 
749
-    if ( $wp_error && is_wp_error( $return ) ) {
749
+    if ($wp_error && is_wp_error($return)) {
750 750
         return $return;
751 751
     }
752 752
     return 0;
753 753
 }
754 754
 
755
-function wpinv_update_item( $args = array(), $wp_error = false ) {
756
-    $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL;
755
+function wpinv_update_item($args = array(), $wp_error = false) {
756
+    $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL;
757 757
 
758
-    if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) {
759
-        if ( $wp_error ) {
760
-            return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) );
758
+    if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) {
759
+        if ($wp_error) {
760
+            return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing'));
761 761
         }
762 762
         return 0;
763 763
     }
764 764
     
765
-    if ( !empty( $args['custom_id'] ) ) {
766
-        $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) );
765
+    if (!empty($args['custom_id'])) {
766
+        $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type));
767 767
         
768
-        if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) {
769
-            if ( $wp_error ) {
770
-                return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) );
768
+        if (!empty($item_exists) && $item_exists->ID != $args['ID']) {
769
+            if ($wp_error) {
770
+                return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing'));
771 771
             }
772 772
             return 0;
773 773
         }
774 774
     }
775 775
 
776
-    $meta_fields = array( 'type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval' );
776
+    $meta_fields = array('type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval');
777 777
 
778 778
     $post_data = array();
779
-    if ( isset( $args['title'] ) ) { 
779
+    if (isset($args['title'])) { 
780 780
         $post_data['post_title'] = $args['title'];
781 781
     }
782
-    if ( isset( $args['excerpt'] ) ) { 
782
+    if (isset($args['excerpt'])) { 
783 783
         $post_data['post_excerpt'] = $args['excerpt'];
784 784
     }
785
-    if ( isset( $args['status'] ) ) { 
785
+    if (isset($args['status'])) { 
786 786
         $post_data['post_status'] = $args['status'];
787 787
     }
788 788
     
789
-    foreach ( $meta_fields as $meta_field ) {
790
-        if ( isset( $args[ $meta_field ] ) ) { 
791
-            $value = $args[ $meta_field ];
789
+    foreach ($meta_fields as $meta_field) {
790
+        if (isset($args[$meta_field])) { 
791
+            $value = $args[$meta_field];
792 792
 
793
-            switch ( $meta_field ) {
793
+            switch ($meta_field) {
794 794
                 case 'price':
795
-                    $value = wpinv_round_amount( $value );
795
+                    $value = wpinv_round_amount($value);
796 796
                 break;
797 797
                 case 'recurring_interval':
798 798
                 case 'recurring_limit':
799 799
                 case 'trial_interval':
800
-                    $value = absint( $value );
800
+                    $value = absint($value);
801 801
                 break;
802 802
             }
803 803
 
804
-            $post_data['meta'][ $meta_field ] = $value;
804
+            $post_data['meta'][$meta_field] = $value;
805 805
         };
806 806
     }
807 807
 
808
-    if ( empty( $post_data ) ) {
809
-        if ( $wp_error ) {
810
-            return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) );
808
+    if (empty($post_data)) {
809
+        if ($wp_error) {
810
+            return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing'));
811 811
         }
812 812
         return 0;
813 813
     }
814 814
     $post_data['ID'] = $args['ID'];
815 815
 
816
-    $return = $item->update( $post_data, $wp_error );
816
+    $return = $item->update($post_data, $wp_error);
817 817
 
818
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
818
+    if ($return && !empty($item) && !is_wp_error($return)) {
819 819
         return $item;
820 820
     }
821 821
 
822
-    if ( $wp_error && is_wp_error( $return ) ) {
822
+    if ($wp_error && is_wp_error($return)) {
823 823
         return $return;
824 824
     }
825 825
     return 0;
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -1,72 +1,72 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-add_action( 'admin_menu', 'wpinv_add_options_link', 10 );
7
+add_action('admin_menu', 'wpinv_add_options_link', 10);
8 8
 function wpinv_add_options_link() {
9 9
     global $menu;
10 10
 
11
-    if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) {
11
+    if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) {
12 12
         return;
13 13
     }
14 14
 
15
-    $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' );
15
+    $capability = apply_filters('invoicing_capability', 'manage_invoicing');
16 16
 
17
-    if ( current_user_can( 'manage_options' ) ) {
18
-        $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' );
17
+    if (current_user_can('manage_options')) {
18
+        $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv');
19 19
     }
20 20
 
21
-    $wpi_invoice = get_post_type_object( 'wpi_invoice' );
21
+    $wpi_invoice = get_post_type_object('wpi_invoice');
22 22
 
23
-    add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' );
23
+    add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460');
24 24
 
25
-    $wpi_settings_page   = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', 'wpinv_options_page' );
25
+    $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', 'wpinv_options_page');
26 26
 }
27 27
 
28
-add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 );
28
+add_action('admin_menu', 'wpinv_remove_admin_submenus', 999);
29 29
 function wpinv_remove_admin_submenus() {
30
-    remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
30
+    remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
31 31
 }
32 32
 
33
-add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );
34
-function wpinv_discount_columns( $existing_columns ) {
33
+add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns');
34
+function wpinv_discount_columns($existing_columns) {
35 35
     $columns                = array();
36 36
     $columns['cb']          = $existing_columns['cb'];
37
-    $columns['name']        = __( 'Name', 'invoicing' );
38
-    $columns['code']        = __( 'Code', 'invoicing' );
39
-    $columns['amount']      = __( 'Amount', 'invoicing' );
40
-    $columns['usage']       = __( 'Usage / Limit', 'invoicing' );
41
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
42
-    $columns['status']      = __( 'Status', 'invoicing' );
37
+    $columns['name']        = __('Name', 'invoicing');
38
+    $columns['code']        = __('Code', 'invoicing');
39
+    $columns['amount']      = __('Amount', 'invoicing');
40
+    $columns['usage']       = __('Usage / Limit', 'invoicing');
41
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
42
+    $columns['status']      = __('Status', 'invoicing');
43 43
 
44 44
     return $columns;
45 45
 }
46 46
 
47
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
48
-function wpinv_discount_custom_column( $column ) {
47
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
48
+function wpinv_discount_custom_column($column) {
49 49
     global $post;
50 50
     
51 51
     $discount = $post;
52 52
 
53
-    switch ( $column ) {
53
+    switch ($column) {
54 54
         case 'name' :
55
-            echo get_the_title( $discount->ID );
55
+            echo get_the_title($discount->ID);
56 56
         break;
57 57
         case 'code' :
58
-            echo wpinv_get_discount_code( $discount->ID );
58
+            echo wpinv_get_discount_code($discount->ID);
59 59
         break;
60 60
         case 'amount' :
61
-            echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
61
+            echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
62 62
         break;
63 63
         case 'usage_limit' :
64
-            echo wpinv_get_discount_uses( $discount->ID );
64
+            echo wpinv_get_discount_uses($discount->ID);
65 65
         break;
66 66
         case 'usage' :
67
-            $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';
68
-            if ( wpinv_get_discount_max_uses( $discount->ID ) ) {
69
-                $usage .= wpinv_get_discount_max_uses( $discount->ID );
67
+            $usage = wpinv_get_discount_uses($discount->ID) . ' / ';
68
+            if (wpinv_get_discount_max_uses($discount->ID)) {
69
+                $usage .= wpinv_get_discount_max_uses($discount->ID);
70 70
             } else {
71 71
                 $usage .= ' &infin;';
72 72
             }
@@ -74,162 +74,162 @@  discard block
 block discarded – undo
74 74
             echo $usage;
75 75
         break;
76 76
         case 'expiry_date' :
77
-            if ( wpinv_get_discount_expiration( $discount->ID ) ) {
78
-                $expiration = date_i18n( get_option( 'date_format' ), strtotime( wpinv_get_discount_expiration( $discount->ID ) ) );
77
+            if (wpinv_get_discount_expiration($discount->ID)) {
78
+                $expiration = date_i18n(get_option('date_format'), strtotime(wpinv_get_discount_expiration($discount->ID)));
79 79
             } else {
80
-                $expiration = __( 'Never', 'invoicing' );
80
+                $expiration = __('Never', 'invoicing');
81 81
             }
82 82
                 
83 83
             echo $expiration;
84 84
         break;
85 85
         case 'description' :
86
-            echo wp_kses_post( $post->post_excerpt );
86
+            echo wp_kses_post($post->post_excerpt);
87 87
         break;
88 88
         case 'status' :
89
-            $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;
89
+            $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;
90 90
             
91
-            echo wpinv_discount_status( $status );
91
+            echo wpinv_discount_status($status);
92 92
         break;
93 93
     }
94 94
 }
95 95
 
96
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
97
-function wpinv_post_row_actions( $actions, $post ) {
98
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
96
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
97
+function wpinv_post_row_actions($actions, $post) {
98
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
99 99
     
100
-    if ( $post_type == 'wpi_invoice' ) {
100
+    if ($post_type == 'wpi_invoice') {
101 101
         $actions = array();
102 102
     }
103 103
     
104
-    if ( $post_type == 'wpi_discount' ) {
105
-        $actions = wpinv_discount_row_actions( $post, $actions );
104
+    if ($post_type == 'wpi_discount') {
105
+        $actions = wpinv_discount_row_actions($post, $actions);
106 106
     }
107 107
     
108 108
     return $actions;
109 109
 }
110 110
 
111
-function wpinv_discount_row_actions( $discount, $row_actions ) {
112
-    $row_actions  = array();
113
-    $edit_link = get_edit_post_link( $discount->ID );
114
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
111
+function wpinv_discount_row_actions($discount, $row_actions) {
112
+    $row_actions = array();
113
+    $edit_link = get_edit_post_link($discount->ID);
114
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
115 115
 
116
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
117
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
118
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
119
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
116
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
117
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
118
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
119
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
120 120
     }
121 121
 
122
-    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) {
123
-        if ( isset( $row_actions['delete'] ) ) {
124
-            unset( $row_actions['delete'] ); // Don't delete used discounts.
122
+    if (wpinv_get_discount_uses($discount->ID) > 0) {
123
+        if (isset($row_actions['delete'])) {
124
+            unset($row_actions['delete']); // Don't delete used discounts.
125 125
         }
126 126
     } else {
127
-        $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>';
127
+        $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>';
128 128
     }
129 129
     
130 130
 
131
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
131
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
132 132
 
133 133
     return $row_actions;
134 134
 }
135 135
 
136
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
137
-function wpinv_table_primary_column( $default, $screen_id ) {
138
-    if ( 'edit-wpi_invoice' === $screen_id ) {
136
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
137
+function wpinv_table_primary_column($default, $screen_id) {
138
+    if ('edit-wpi_invoice' === $screen_id) {
139 139
         return 'name';
140 140
     }
141 141
     
142 142
     return $default;
143 143
 }
144 144
 
145
-function wpinv_discount_bulk_actions( $actions, $display = false ) {    
146
-    if ( !$display ) {
145
+function wpinv_discount_bulk_actions($actions, $display = false) {    
146
+    if (!$display) {
147 147
         return array();
148 148
     }
149 149
     
150 150
     $actions = array(
151
-        'activate'   => __( 'Activate', 'invoicing' ),
152
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
153
-        'delete'     => __( 'Delete', 'invoicing' ),
151
+        'activate'   => __('Activate', 'invoicing'),
152
+        'deactivate' => __('Deactivate', 'invoicing'),
153
+        'delete'     => __('Delete', 'invoicing'),
154 154
     );
155 155
     $two = '';
156 156
     $which = 'top';
157 157
     echo '</div><div class="alignleft actions bulkactions">';
158
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
159
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
160
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
158
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
159
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
160
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
161 161
 
162
-    foreach ( $actions as $name => $title ) {
162
+    foreach ($actions as $name => $title) {
163 163
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
164 164
 
165 165
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
166 166
     }
167 167
     echo "</select>";
168 168
 
169
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
169
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
170 170
     
171 171
     echo '</div><div class="alignleft actions">';
172 172
 }
173
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
173
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
174 174
 
175
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
176
-    if ( $post_type == 'wpi_discount' ) {
175
+function wpinv_disable_months_dropdown($disable, $post_type) {
176
+    if ($post_type == 'wpi_discount') {
177 177
         $disable = true;
178 178
     }
179 179
     
180 180
     return $disable;
181 181
 }
182
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
182
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
183 183
 
184 184
 function wpinv_restrict_manage_posts() {
185 185
     global $typenow;
186 186
 
187
-    if( 'wpi_discount' == $typenow ) {
187
+    if ('wpi_discount' == $typenow) {
188 188
         wpinv_discount_filters();
189 189
     }
190 190
 }
191
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
191
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
192 192
 
193 193
 function wpinv_discount_filters() {
194
-    echo wpinv_discount_bulk_actions( array(), true );
194
+    echo wpinv_discount_bulk_actions(array(), true);
195 195
     
196 196
     ?>
197 197
     <select name="discount_type" id="dropdown_wpinv_discount_type">
198
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
198
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
199 199
         <?php
200 200
             $types = wpinv_get_discount_types();
201 201
 
202
-            foreach ( $types as $name => $type ) {
203
-                echo '<option value="' . esc_attr( $name ) . '"';
202
+            foreach ($types as $name => $type) {
203
+                echo '<option value="' . esc_attr($name) . '"';
204 204
 
205
-                if ( isset( $_GET['discount_type'] ) )
206
-                    selected( $name, $_GET['discount_type'] );
205
+                if (isset($_GET['discount_type']))
206
+                    selected($name, $_GET['discount_type']);
207 207
 
208
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
208
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
209 209
             }
210 210
         ?>
211 211
     </select>
212 212
     <?php
213 213
 }
214 214
 
215
-function wpinv_request( $vars ) {
215
+function wpinv_request($vars) {
216 216
     global $typenow, $wp_query, $wp_post_statuses;
217 217
 
218
-    if ( 'wpi_invoice' === $typenow ) {
219
-        if ( !isset( $vars['post_status'] ) ) {
218
+    if ('wpi_invoice' === $typenow) {
219
+        if (!isset($vars['post_status'])) {
220 220
             $post_statuses = wpinv_get_invoice_statuses();
221 221
 
222
-            foreach ( $post_statuses as $status => $value ) {
223
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
224
-                    unset( $post_statuses[ $status ] );
222
+            foreach ($post_statuses as $status => $value) {
223
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
224
+                    unset($post_statuses[$status]);
225 225
                 }
226 226
             }
227 227
 
228
-            $vars['post_status'] = array_keys( $post_statuses );
228
+            $vars['post_status'] = array_keys($post_statuses);
229 229
         }
230 230
         
231
-        if ( isset( $vars['orderby'] ) ) {
232
-            if ( 'amount' == $vars['orderby'] ) {
231
+        if (isset($vars['orderby'])) {
232
+            if ('amount' == $vars['orderby']) {
233 233
                 $vars = array_merge(
234 234
                     $vars,
235 235
                     array(
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
                         'orderby'  => 'meta_value_num'
238 238
                     )
239 239
                 );
240
-            } else if ( 'customer' == $vars['orderby'] ) {
240
+            } else if ('customer' == $vars['orderby']) {
241 241
                 $vars = array_merge(
242 242
                     $vars,
243 243
                     array(
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
                         'orderby'  => 'meta_value'
246 246
                     )
247 247
                 );
248
-            } else if ( 'number' == $vars['orderby'] ) {
248
+            } else if ('number' == $vars['orderby']) {
249 249
                 $vars = array_merge(
250 250
                     $vars,
251 251
                     array(
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
                 );
256 256
             }
257 257
         }
258
-    } else if ( 'wpi_item' == $typenow ) {
258
+    } else if ('wpi_item' == $typenow) {
259 259
         // Check if 'orderby' is set to "price"
260
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
260
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
261 261
             $vars = array_merge(
262 262
                 $vars,
263 263
                 array(
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
         }
269 269
 
270 270
         // Check if "orderby" is set to "vat_rule"
271
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
271
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
272 272
             $vars = array_merge(
273 273
                 $vars,
274 274
                 array(
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         }
280 280
 
281 281
         // Check if "orderby" is set to "vat_class"
282
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
282
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
283 283
             $vars = array_merge(
284 284
                 $vars,
285 285
                 array(
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         }
291 291
         
292 292
         // Check if "orderby" is set to "type"
293
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
293
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
294 294
             $vars = array_merge(
295 295
                 $vars,
296 296
                 array(
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         }
302 302
         
303 303
         // Check if "orderby" is set to "recurring"
304
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
304
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
305 305
             $vars = array_merge(
306 306
                 $vars,
307 307
                 array(
@@ -311,120 +311,120 @@  discard block
 block discarded – undo
311 311
             );
312 312
         }
313 313
 
314
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
314
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
315 315
         // Filter vat rule type
316
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
316
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
317 317
             $meta_query[] = array(
318 318
                     'key'   => '_wpinv_vat_rule',
319
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
319
+                    'value' => sanitize_text_field($_GET['vat_rule']),
320 320
                     'compare' => '='
321 321
                 );
322 322
         }
323 323
         
324 324
         // Filter vat class
325
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
325
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
326 326
             $meta_query[] = array(
327 327
                     'key'   => '_wpinv_vat_class',
328
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
328
+                    'value' => sanitize_text_field($_GET['vat_class']),
329 329
                     'compare' => '='
330 330
                 );
331 331
         }
332 332
         
333 333
         // Filter item type
334
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
334
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
335 335
             $meta_query[] = array(
336 336
                     'key'   => '_wpinv_type',
337
-                    'value' => sanitize_text_field( $_GET['type'] ),
337
+                    'value' => sanitize_text_field($_GET['type']),
338 338
                     'compare' => '='
339 339
                 );
340 340
         }
341 341
         
342
-        if ( !empty( $meta_query ) ) {
342
+        if (!empty($meta_query)) {
343 343
             $vars['meta_query'] = $meta_query;
344 344
         }
345
-    } else if ( 'wpi_discount' == $typenow ) {
346
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
345
+    } else if ('wpi_discount' == $typenow) {
346
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
347 347
         // Filter vat rule type
348
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
348
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
349 349
             $meta_query[] = array(
350 350
                     'key'   => '_wpi_discount_type',
351
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
351
+                    'value' => sanitize_text_field($_GET['discount_type']),
352 352
                     'compare' => '='
353 353
                 );
354 354
         }
355 355
         
356
-        if ( !empty( $meta_query ) ) {
356
+        if (!empty($meta_query)) {
357 357
             $vars['meta_query'] = $meta_query;
358 358
         }
359 359
     }
360 360
 
361 361
     return $vars;
362 362
 }
363
-add_filter( 'request', 'wpinv_request' );
363
+add_filter('request', 'wpinv_request');
364 364
 
365 365
 function wpinv_options_page() {
366
-    $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
366
+    $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
367 367
     
368
-    if ( $page !== 'wpinv-settings' ) {
368
+    if ($page !== 'wpinv-settings') {
369 369
         return;
370 370
     }
371 371
     
372 372
     $settings_tabs = wpinv_get_settings_tabs();
373 373
     $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
374
-    $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
375
-    $sections      = wpinv_get_settings_tab_sections( $active_tab );
374
+    $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
375
+    $sections      = wpinv_get_settings_tab_sections($active_tab);
376 376
     $key           = 'main';
377 377
 
378
-    if ( is_array( $sections ) ) {
379
-        $key = key( $sections );
378
+    if (is_array($sections)) {
379
+        $key = key($sections);
380 380
     }
381 381
 
382
-    $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
383
-    $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
382
+    $registered_sections = wpinv_get_settings_tab_sections($active_tab);
383
+    $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
384 384
     ob_start();
385 385
     ?>
386 386
     <div class="wrap">
387 387
         <h1 class="nav-tab-wrapper">
388 388
             <?php
389
-            foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
390
-                $tab_url = add_query_arg( array(
389
+            foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
390
+                $tab_url = add_query_arg(array(
391 391
                     'settings-updated' => false,
392 392
                     'tab' => $tab_id,
393
-                ) );
393
+                ));
394 394
 
395 395
                 // Remove the section from the tabs so we always end up at the main section
396
-                $tab_url = remove_query_arg( 'section', $tab_url );
397
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
396
+                $tab_url = remove_query_arg('section', $tab_url);
397
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
398 398
 
399 399
                 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
400 400
 
401
-                echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
402
-                    echo esc_html( $tab_name );
401
+                echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
402
+                    echo esc_html($tab_name);
403 403
                 echo '</a>';
404 404
             }
405 405
             ?>
406 406
         </h1>
407 407
         <?php
408
-        $number_of_sections = count( $sections );
408
+        $number_of_sections = count($sections);
409 409
         $number = 0;
410
-        if ( $number_of_sections > 1 ) {
410
+        if ($number_of_sections > 1) {
411 411
             echo '<div><ul class="subsubsub">';
412
-            foreach( $sections as $section_id => $section_name ) {
412
+            foreach ($sections as $section_id => $section_name) {
413 413
                 echo '<li>';
414 414
                 $number++;
415
-                $tab_url = add_query_arg( array(
415
+                $tab_url = add_query_arg(array(
416 416
                     'settings-updated' => false,
417 417
                     'tab' => $active_tab,
418 418
                     'section' => $section_id
419
-                ) );
420
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
419
+                ));
420
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
421 421
                 $class = '';
422
-                if ( $section == $section_id ) {
422
+                if ($section == $section_id) {
423 423
                     $class = 'current';
424 424
                 }
425
-                echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
425
+                echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
426 426
 
427
-                if ( $number != $number_of_sections ) {
427
+                if ($number != $number_of_sections) {
428 428
                     echo ' | ';
429 429
                 }
430 430
                 echo '</li>';
@@ -436,19 +436,19 @@  discard block
 block discarded – undo
436 436
             <form method="post" action="options.php">
437 437
                 <table class="form-table">
438 438
                 <?php
439
-                settings_fields( 'wpinv_settings' );
439
+                settings_fields('wpinv_settings');
440 440
 
441
-                if ( 'main' === $section ) {
442
-                    do_action( 'wpinv_settings_tab_top', $active_tab );
441
+                if ('main' === $section) {
442
+                    do_action('wpinv_settings_tab_top', $active_tab);
443 443
                 }
444 444
 
445
-                do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section );
446
-                do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section );
447
-                do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section  );
445
+                do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section);
446
+                do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section);
447
+                do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section);
448 448
 
449 449
                 // For backwards compatibility
450
-                if ( 'main' === $section ) {
451
-                    do_action( 'wpinv_settings_tab_bottom', $active_tab );
450
+                if ('main' === $section) {
451
+                    do_action('wpinv_settings_tab_bottom', $active_tab);
452 452
                 }
453 453
                 ?>
454 454
                 </table>
@@ -461,53 +461,53 @@  discard block
 block discarded – undo
461 461
     echo $content;
462 462
 }
463 463
 
464
-function wpinv_item_type_class( $classes, $class, $post_id ) {
464
+function wpinv_item_type_class($classes, $class, $post_id) {
465 465
     global $pagenow, $typenow;
466 466
 
467
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
468
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
469
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
467
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
468
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
469
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
470 470
         }
471 471
         
472
-        if ( !wpinv_item_is_editable( $post_id ) ) {
472
+        if (!wpinv_item_is_editable($post_id)) {
473 473
             $classes[] = 'wpi-editable-n';
474 474
         }
475 475
     }
476 476
     return $classes;
477 477
 }
478
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
478
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
479 479
 
480 480
 function wpinv_check_quick_edit() {
481 481
     global $pagenow, $current_screen, $wpinv_item_screen;
482 482
 
483
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
484
-        if ( empty( $wpinv_item_screen ) ) {
485
-            if ( $current_screen->post_type == 'wpi_item' ) {
483
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
484
+        if (empty($wpinv_item_screen)) {
485
+            if ($current_screen->post_type == 'wpi_item') {
486 486
                 $wpinv_item_screen = 'y';
487 487
             } else {
488 488
                 $wpinv_item_screen = 'n';
489 489
             }
490 490
         }
491 491
 
492
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
493
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
494
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
492
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
493
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
494
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
495 495
         }
496 496
     }
497 497
 }
498
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
498
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
499 499
 
500
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
501
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
502
-        unset( $actions['inline hide-if-no-js'] );
500
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
501
+    if (isset($actions['inline hide-if-no-js'])) {
502
+        unset($actions['inline hide-if-no-js']);
503 503
     }
504 504
     
505
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
506
-        if ( isset( $actions['trash'] ) ) {
507
-            unset( $actions['trash'] );
505
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
506
+        if (isset($actions['trash'])) {
507
+            unset($actions['trash']);
508 508
         }
509
-        if ( isset( $actions['delete'] ) ) {
510
-            unset( $actions['delete'] );
509
+        if (isset($actions['delete'])) {
510
+            unset($actions['delete']);
511 511
         }
512 512
     }
513 513
 
@@ -524,19 +524,19 @@  discard block
 block discarded – undo
524 524
  * @param int $post_parent (default: 0) Parent for the new page
525 525
  * @return int page ID
526 526
  */
527
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
527
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
528 528
     global $wpdb;
529 529
 
530
-    $option_value = wpinv_get_option( $option );
530
+    $option_value = wpinv_get_option($option);
531 531
 
532
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
533
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
532
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
533
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
534 534
             // Valid page is already in place
535 535
             return $page_object->ID;
536 536
         }
537 537
     }
538 538
 
539
-    if(!empty($post_parent)){
539
+    if (!empty($post_parent)) {
540 540
         $page = get_page_by_path($post_parent);
541 541
         if ($page) {
542 542
             $post_parent = $page->ID;
@@ -545,40 +545,40 @@  discard block
 block discarded – undo
545 545
         }
546 546
     }
547 547
 
548
-    if ( strlen( $page_content ) > 0 ) {
548
+    if (strlen($page_content) > 0) {
549 549
         // Search for an existing page with the specified page content (typically a shortcode)
550
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
550
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
551 551
     } else {
552 552
         // Search for an existing page with the specified page slug
553
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
553
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
554 554
     }
555 555
 
556
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
556
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
557 557
 
558
-    if ( $valid_page_found ) {
559
-        if ( $option ) {
560
-            wpinv_update_option( $option, $valid_page_found );
558
+    if ($valid_page_found) {
559
+        if ($option) {
560
+            wpinv_update_option($option, $valid_page_found);
561 561
         }
562 562
         return $valid_page_found;
563 563
     }
564 564
 
565 565
     // Search for a matching valid trashed page
566
-    if ( strlen( $page_content ) > 0 ) {
566
+    if (strlen($page_content) > 0) {
567 567
         // Search for an existing page with the specified page content (typically a shortcode)
568
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
568
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
569 569
     } else {
570 570
         // Search for an existing page with the specified page slug
571
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
571
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
572 572
     }
573 573
 
574
-    if ( $trashed_page_found ) {
574
+    if ($trashed_page_found) {
575 575
         $page_id   = $trashed_page_found;
576 576
         $page_data = array(
577 577
             'ID'             => $page_id,
578 578
             'post_status'    => 'publish',
579 579
             'post_parent'    => $post_parent,
580 580
         );
581
-        wp_update_post( $page_data );
581
+        wp_update_post($page_data);
582 582
     } else {
583 583
         $page_data = array(
584 584
             'post_status'    => 'publish',
@@ -590,11 +590,11 @@  discard block
 block discarded – undo
590 590
             'post_parent'    => $post_parent,
591 591
             'comment_status' => 'closed',
592 592
         );
593
-        $page_id = wp_insert_post( $page_data );
593
+        $page_id = wp_insert_post($page_data);
594 594
     }
595 595
 
596
-    if ( $option ) {
597
-        wpinv_update_option( $option, (int)$page_id );
596
+    if ($option) {
597
+        wpinv_update_option($option, (int)$page_id);
598 598
     }
599 599
 
600 600
     return $page_id;
Please login to merge, or discard this patch.
templates/wpinv-invoice-history.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -1,80 +1,80 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-if ( !( $user_id = get_current_user_id() ) ) {
6
+if (!($user_id = get_current_user_id())) {
7 7
     ?>
8
-    <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div>
8
+    <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div>
9 9
     <?php
10 10
     return;
11 11
 }
12 12
 
13 13
 global $current_page;
14
-$current_page   = empty( $current_page ) ? 1 : absint( $current_page );
15
-$query          = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) );
16
-$user_invoices  = wpinv_get_invoices( $query );
14
+$current_page   = empty($current_page) ? 1 : absint($current_page);
15
+$query          = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true));
16
+$user_invoices  = wpinv_get_invoices($query);
17 17
 $has_invoices   = 0 < $user_invoices->total;
18 18
     
19
-do_action( 'wpinv_before_user_invoices', $has_invoices ); ?>
19
+do_action('wpinv_before_user_invoices', $has_invoices); ?>
20 20
 
21
-<?php if ( $has_invoices ) { ?>
21
+<?php if ($has_invoices) { ?>
22 22
 	<table class="table table-bordered table-hover wpi-user-invoices">
23 23
 		<thead>
24 24
 			<tr>
25
-				<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
26
-					<th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th>
25
+				<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
26
+					<th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th>
27 27
 				<?php endforeach; ?>
28 28
 			</tr>
29 29
 		</thead>
30 30
 
31 31
 		<tbody>
32
-			<?php foreach ( $user_invoices->invoices as $invoice ) {
32
+			<?php foreach ($user_invoices->invoices as $invoice) {
33 33
 				?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35
-					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36
-						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
37
-							<?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
38
-								<?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
39
-
40
-							<?php elseif ( 'invoice-number' === $column_id ) : ?>
41
-								<a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
42
-									<?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
35
+					<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
36
+						<td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>">
37
+							<?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
38
+								<?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
39
+
40
+							<?php elseif ('invoice-number' === $column_id) : ?>
41
+								<a href="<?php echo esc_url($invoice->get_view_url()); ?>">
42
+									<?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
43 43
 								</a>
44 44
 
45
-							<?php elseif ( 'invoice-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s' ); ?>
46
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
45
+							<?php elseif ('invoice-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s'); ?>
46
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
47 47
 
48
-							<?php elseif ( 'invoice-status' === $column_id ) : ?>
49
-								<?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
48
+							<?php elseif ('invoice-status' === $column_id) : ?>
49
+								<?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
50 50
 
51
-							<?php elseif ( 'invoice-total' === $column_id ) : ?>
52
-								<?php echo $invoice->get_total( true ); ?>
51
+							<?php elseif ('invoice-total' === $column_id) : ?>
52
+								<?php echo $invoice->get_total(true); ?>
53 53
 
54
-							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
54
+							<?php elseif ('invoice-actions' === $column_id) : ?>
55 55
 								<?php
56 56
 									$actions = array(
57 57
 										'pay'    => array(
58 58
 											'url'  => $invoice->get_checkout_payment_url(),
59
-											'name' => __( 'Pay Now', 'invoicing' ),
59
+											'name' => __('Pay Now', 'invoicing'),
60 60
                                             'class' => 'btn-success'
61 61
 										),
62 62
                                         'print'   => array(
63 63
 											'url'  => $invoice->get_view_url(),
64
-											'name' => __( 'Print', 'invoicing' ),
64
+											'name' => __('Print', 'invoicing'),
65 65
                                             'class' => 'btn-primary',
66 66
                                             'attrs' => 'target="_blank"'
67 67
 										)
68 68
 									);
69 69
 
70
-									if ( ! $invoice->needs_payment() ) {
71
-										unset( $actions['pay'] );
70
+									if (!$invoice->needs_payment()) {
71
+										unset($actions['pay']);
72 72
 									}
73 73
 
74
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
75
-										foreach ( $actions as $key => $action ) {
74
+									if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
75
+										foreach ($actions as $key => $action) {
76 76
 											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
77
-                                            echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
77
+                                            echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
78 78
 										}
79 79
 									}
80 80
 								?>
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 		</tbody>
87 87
 	</table>
88 88
 
89
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
89
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
90 90
 
91
-	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
91
+	<?php if (1 < $user_invoices->max_num_pages) : ?>
92 92
 		<div class="invoicing-Pagination">
93 93
 			<?php
94 94
 			$big = 999999;
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
 			else
101 101
 				$current_page = 1;
102 102
 
103
-			echo paginate_links( array(
104
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
103
+			echo paginate_links(array(
104
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
105 105
 				'format'  => '?paged=%#%',
106
-				'current' => max( 1, $current_page ),
106
+				'current' => max(1, $current_page),
107 107
 				'total'   => $user_invoices->max_num_pages,
108
-			) );
108
+			));
109 109
 			?>
110 110
 		</div>
111 111
 	<?php endif; ?>
112 112
 
113 113
 <?php } else { ?>
114 114
 	<div class="wpinv-empty alert-info">
115
-		<?php _e( 'No invoice has been made yet.', 'invoicing' ); ?>
115
+		<?php _e('No invoice has been made yet.', 'invoicing'); ?>
116 116
 	</div>
117 117
 <?php } ?>
118 118
 
119
-<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?>
119
+<?php do_action('wpinv_after_user_invoices', $has_invoices); ?>
Please login to merge, or discard this patch.