Passed
Push — master ( 18145d...828cff )
by Brian
05:08
created
templates/emails/wpinv-email-processing_invoice.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16 16
 echo $message_body;
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-new_invoice.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16 16
 echo $message_body;
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-completed_invoice.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16 16
 echo $message_body;
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-user_invoice.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16 16
 echo $message_body;
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-cancelled_invoice.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16 16
 echo $message_body;
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-refunded_invoice.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16 16
 echo $message_body;
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
templates/emails/wpinv-email-failed_invoice.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Print the email header.
13
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
13
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
14 14
 
15 15
 // Generate the custom message body.
16 16
 echo $message_body;
17 17
 
18 18
 // Print invoice details.
19
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
19
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
20 20
 
21 21
 // Print invoice items.
22
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the billing details.
25
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
26 26
 
27 27
 // Print the email footer.
28
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
28
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.
includes/data/admin-settings.php 1 patch
Spacing   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -8,201 +8,201 @@  discard block
 block discarded – undo
8 8
  * @version 1.0.19
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13
-$pages = wpinv_get_pages( true );
13
+$pages = wpinv_get_pages(true);
14 14
     
15 15
 $currencies = wpinv_get_currencies();
16 16
     
17 17
 $currency_code_options = array();
18
-foreach ( $currencies as $code => $name ) {
19
-    $currency_code_options[ $code ] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol( $code ) . ')';
18
+foreach ($currencies as $code => $name) {
19
+    $currency_code_options[$code] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol($code) . ')';
20 20
 }
21 21
     
22 22
 $due_payment_options       = array();
23
-$due_payment_options[0]    = __( 'Now', 'invoicing' );
24
-for ( $i = 1; $i <= 30; $i++ ) {
23
+$due_payment_options[0]    = __('Now', 'invoicing');
24
+for ($i = 1; $i <= 30; $i++) {
25 25
     $due_payment_options[$i] = $i;
26 26
 }
27 27
     
28 28
 $invoice_number_padd_options = array();
29
-for ( $i = 0; $i <= 20; $i++ ) {
29
+for ($i = 0; $i <= 20; $i++) {
30 30
     $invoice_number_padd_options[$i] = $i;
31 31
 }
32 32
     
33 33
 $currency_symbol = wpinv_currency_symbol();
34 34
     
35 35
 $last_number = $reset_number = '';
36
-if ( $last_invoice_number = get_option( 'wpinv_last_invoice_number' ) ) {
37
-    $last_invoice_number = preg_replace( '/[^0-9]/', '', $last_invoice_number );
36
+if ($last_invoice_number = get_option('wpinv_last_invoice_number')) {
37
+    $last_invoice_number = preg_replace('/[^0-9]/', '', $last_invoice_number);
38 38
 
39
-    if ( !empty( $last_invoice_number ) ) {
40
-        $last_number = ' ' . wp_sprintf( __( "( Last Invoice's sequential number: <b>%s</b> )", 'invoicing' ), $last_invoice_number );
39
+    if (!empty($last_invoice_number)) {
40
+        $last_number = ' ' . wp_sprintf(__("( Last Invoice's sequential number: <b>%s</b> )", 'invoicing'), $last_invoice_number);
41 41
     }
42 42
 
43 43
     $nonce = wp_create_nonce('reset_invoice_count');
44
-    $reset_number = '<a href="'.add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)).'" class="btn button">'.__('Force Reset Sequence', 'invoicing' ). '</a>';
44
+    $reset_number = '<a href="' . add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)) . '" class="btn button">' . __('Force Reset Sequence', 'invoicing') . '</a>';
45 45
 }
46 46
     
47 47
 $alert_wrapper_start = '<p style="color: #F00">';
48 48
 $alert_wrapper_close = '</p>';
49 49
 
50 50
 return array(
51
-    'general' => apply_filters( 'wpinv_settings_general',
51
+    'general' => apply_filters('wpinv_settings_general',
52 52
         array(
53 53
             'main' => array(
54 54
                 'location_settings' => array(
55 55
                     'id'   => 'location_settings',
56
-                    'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>',
56
+                    'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>',
57 57
                     'desc' => '',
58 58
                     'type' => 'header',
59 59
                 ),
60 60
                 'default_country' => array(
61 61
                     'id'      => 'default_country',
62
-                    'name'    => __( 'Default Country', 'invoicing' ),
63
-                    'desc'    => __( 'Where does your store operate from?', 'invoicing' ),
62
+                    'name'    => __('Default Country', 'invoicing'),
63
+                    'desc'    => __('Where does your store operate from?', 'invoicing'),
64 64
                     'type'    => 'select',
65 65
                     'options' => wpinv_get_country_list(),
66 66
                     'std'     => 'GB',
67 67
                     'class'   => 'wpi_select2',
68
-                    'placeholder' => __( 'Select a country', 'invoicing' ),
68
+                    'placeholder' => __('Select a country', 'invoicing'),
69 69
                 ),
70 70
                 'default_state' => array(
71 71
                     'id'      => 'default_state',
72
-                    'name'    => __( 'Default State / Province', 'invoicing' ),
73
-                    'desc'    => __( 'What state / province does your store operate from?', 'invoicing' ),
72
+                    'name'    => __('Default State / Province', 'invoicing'),
73
+                    'desc'    => __('What state / province does your store operate from?', 'invoicing'),
74 74
                     'type'    => 'country_states',
75 75
                     'class'   => 'wpi_select2',
76
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
76
+                    'placeholder' => __('Select a state', 'invoicing'),
77 77
                 ),
78 78
                 'store_name' => array(
79 79
                     'id'   => 'store_name',
80
-                    'name' => __( 'Store Name', 'invoicing' ),
81
-                    'desc' => __( 'Store name to print on invoices.', 'invoicing' ),
80
+                    'name' => __('Store Name', 'invoicing'),
81
+                    'desc' => __('Store name to print on invoices.', 'invoicing'),
82 82
                     'std'     => get_option('blogname'),
83 83
                     'type' => 'text',
84 84
                 ),
85 85
                 'logo' => array(
86 86
                     'id'   => 'logo',
87
-                    'name' => __( 'Logo URL', 'invoicing' ),
88
-                    'desc' => __( 'Store logo to print on invoices.', 'invoicing' ),
87
+                    'name' => __('Logo URL', 'invoicing'),
88
+                    'desc' => __('Store logo to print on invoices.', 'invoicing'),
89 89
                     'type' => 'text',
90 90
                 ),
91 91
                 'store_address' => array(
92 92
                     'id'   => 'store_address',
93
-                    'name' => __( 'Store Address', 'invoicing' ),
94
-                    'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ),
93
+                    'name' => __('Store Address', 'invoicing'),
94
+                    'desc' => __('Enter the store address to display on invoice', 'invoicing'),
95 95
                     'type' => 'textarea',
96 96
                 ),
97 97
                 'page_settings' => array(
98 98
                     'id'   => 'page_settings',
99
-                    'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>',
99
+                    'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>',
100 100
                     'desc' => '',
101 101
                     'type' => 'header',
102 102
                 ),
103 103
                 'checkout_page' => array(
104 104
                     'id'          => 'checkout_page',
105
-                    'name'        => __( 'Checkout Page', 'invoicing' ),
106
-                    'desc'        => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ),
105
+                    'name'        => __('Checkout Page', 'invoicing'),
106
+                    'desc'        => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'),
107 107
                     'type'        => 'select',
108 108
                     'options'     => $pages,
109 109
                     'class'       => 'wpi_select2',
110
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
110
+                    'placeholder' => __('Select a page', 'invoicing'),
111 111
                 ),
112 112
                 'tandc_page' => array(
113 113
                     'id'          => 'tandc_page',
114
-                    'name'        => __( 'Terms & Conditions', 'invoicing' ),
115
-                    'desc'        => __( 'If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing' ),
114
+                    'name'        => __('Terms & Conditions', 'invoicing'),
115
+                    'desc'        => __('If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing'),
116 116
                     'type'        => 'select',
117
-                    'options'     => wpinv_get_pages( true,  __( 'Select a page', 'invoicing' )),
117
+                    'options'     => wpinv_get_pages(true, __('Select a page', 'invoicing')),
118 118
                     'class'       => 'wpi_select2',
119
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
119
+                    'placeholder' => __('Select a page', 'invoicing'),
120 120
                 ),
121 121
                 'success_page' => array(
122 122
                     'id'          => 'success_page',
123
-                    'name'        => __( 'Success Page', 'invoicing' ),
124
-                    'desc'        => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ),
123
+                    'name'        => __('Success Page', 'invoicing'),
124
+                    'desc'        => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'),
125 125
                     'type'        => 'select',
126 126
                     'options'     => $pages,
127 127
                     'class'       => 'wpi_select2',
128
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
128
+                    'placeholder' => __('Select a page', 'invoicing'),
129 129
                 ),
130 130
                 'failure_page' => array(
131 131
                     'id'          => 'failure_page',
132
-                    'name'        => __( 'Failed Transaction Page', 'invoicing' ),
133
-                    'desc'        => __( 'This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing' ),
132
+                    'name'        => __('Failed Transaction Page', 'invoicing'),
133
+                    'desc'        => __('This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing'),
134 134
                     'type'        => 'select',
135 135
                     'options'     => $pages,
136 136
                     'class'       => 'wpi_select2',
137
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
137
+                    'placeholder' => __('Select a page', 'invoicing'),
138 138
                 ),
139 139
                 'invoice_history_page' => array(
140 140
                     'id'          => 'invoice_history_page',
141
-                    'name'        => __( 'Invoice History Page', 'invoicing' ),
142
-                    'desc'        => __( 'This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing' ),
141
+                    'name'        => __('Invoice History Page', 'invoicing'),
142
+                    'desc'        => __('This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing'),
143 143
                     'type'        => 'select',
144 144
                     'options'     => $pages,
145 145
                     'class'       => 'wpi_select2',
146
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
146
+                    'placeholder' => __('Select a page', 'invoicing'),
147 147
                 ),
148 148
                 'invoice_subscription_page' => array(
149 149
                     'id'          => 'invoice_subscription_page',
150
-                    'name'        => __( 'Invoice Subscriptions Page', 'invoicing' ),
151
-                    'desc'        => __( 'This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing' ),
150
+                    'name'        => __('Invoice Subscriptions Page', 'invoicing'),
151
+                    'desc'        => __('This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing'),
152 152
                     'type'        => 'select',
153 153
                     'options'     => $pages,
154 154
                     'class'       => 'wpi_select2',
155
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
155
+                    'placeholder' => __('Select a page', 'invoicing'),
156 156
                 ),
157 157
             ),
158 158
             'currency_section' => array(
159 159
                 'currency_settings' => array(
160 160
                     'id'   => 'currency_settings',
161
-                    'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>',
161
+                    'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>',
162 162
                     'desc' => '',
163 163
                     'type' => 'header',
164 164
                 ),
165 165
                 'currency' => array(
166 166
                     'id'      => 'currency',
167
-                    'name'    => __( 'Currency', 'invoicing' ),
168
-                    'desc'    => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ),
167
+                    'name'    => __('Currency', 'invoicing'),
168
+                    'desc'    => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'),
169 169
                     'type'    => 'select',
170 170
                     'class'       => 'wpi_select2',
171 171
                     'options' => $currency_code_options,
172 172
                 ),
173 173
                 'currency_position' => array(
174 174
                     'id'      => 'currency_position',
175
-                    'name'    => __( 'Currency Position', 'invoicing' ),
176
-                    'desc'    => __( 'Choose the location of the currency sign.', 'invoicing' ),
175
+                    'name'    => __('Currency Position', 'invoicing'),
176
+                    'desc'    => __('Choose the location of the currency sign.', 'invoicing'),
177 177
                     'type'    => 'select',
178 178
                     'class'   => 'wpi_select2',
179 179
                     'options'  => array(
180
-                        'left'        => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')',
181
-                        'right'       => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')',
182
-                        'left_space'  => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')',
183
-                        'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')'
180
+                        'left'        => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')',
181
+                        'right'       => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')',
182
+                        'left_space'  => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')',
183
+                        'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')'
184 184
                     )
185 185
                 ),
186 186
                 'thousands_separator' => array(
187 187
                     'id'   => 'thousands_separator',
188
-                    'name' => __( 'Thousands Separator', 'invoicing' ),
189
-                    'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ),
188
+                    'name' => __('Thousands Separator', 'invoicing'),
189
+                    'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'),
190 190
                     'type' => 'text',
191 191
                     'size' => 'small',
192 192
                     'std'  => ',',
193 193
                 ),
194 194
                 'decimal_separator' => array(
195 195
                     'id'   => 'decimal_separator',
196
-                    'name' => __( 'Decimal Separator', 'invoicing' ),
197
-                    'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ),
196
+                    'name' => __('Decimal Separator', 'invoicing'),
197
+                    'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'),
198 198
                     'type' => 'text',
199 199
                     'size' => 'small',
200 200
                     'std'  => '.',
201 201
                 ),
202 202
                 'decimals' => array(
203 203
                     'id'   => 'decimals',
204
-                    'name' => __( 'Number of Decimals', 'invoicing' ),
205
-                    'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ),
204
+                    'name' => __('Number of Decimals', 'invoicing'),
205
+                    'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'),
206 206
                     'type' => 'number',
207 207
                     'size' => 'small',
208 208
                     'std'  => '2',
@@ -214,29 +214,29 @@  discard block
 block discarded – undo
214 214
             'labels' => array(
215 215
                 'labels' => array(
216 216
                     'id'   => 'labels_settings',
217
-                    'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>',
217
+                    'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>',
218 218
                     'desc' => '',
219 219
                     'type' => 'header',
220 220
                 ),
221 221
                 'vat_name' => array(
222 222
                     'id' => 'vat_name',
223
-                    'name' => __( 'VAT Name', 'invoicing' ),
224
-                    'desc' => __( 'Enter the VAT name', 'invoicing' ),
223
+                    'name' => __('VAT Name', 'invoicing'),
224
+                    'desc' => __('Enter the VAT name', 'invoicing'),
225 225
                     'type' => 'text',
226 226
                     'size' => 'regular',
227
-                    'std' => __( 'VAT', 'invoicing' ),
227
+                    'std' => __('VAT', 'invoicing'),
228 228
                 ),
229 229
                 'vat_invoice_notice_label' => array(
230 230
                     'id' => 'vat_invoice_notice_label',
231
-                    'name' => __( 'Invoice Notice Label', 'invoicing' ),
232
-                    'desc' => __( 'Use this to add an invoice notice section (label) to your invoices', 'invoicing' ),
231
+                    'name' => __('Invoice Notice Label', 'invoicing'),
232
+                    'desc' => __('Use this to add an invoice notice section (label) to your invoices', 'invoicing'),
233 233
                     'type' => 'text',
234 234
                     'size' => 'regular',
235 235
                 ),
236 236
                 'vat_invoice_notice' => array(
237 237
                     'id' => 'vat_invoice_notice',
238
-                    'name' => __( 'Invoice notice', 'invoicing' ),
239
-                    'desc' =>   __( 'Use this to add an invoice notice section (description) to your invoices', 'invoicing' ),
238
+                    'name' => __('Invoice notice', 'invoicing'),
239
+                    'desc' =>   __('Use this to add an invoice notice section (description) to your invoices', 'invoicing'),
240 240
                     'type' => 'text',
241 241
                     'size' => 'regular',
242 242
                 ),
@@ -248,22 +248,22 @@  discard block
 block discarded – undo
248 248
             'main' => array(
249 249
                 'gateway_settings' => array(
250 250
                     'id'   => 'api_header',
251
-                    'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>',
251
+                    'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>',
252 252
                     'desc' => '',
253 253
                     'type' => 'header',
254 254
                 ),
255 255
                 'gateways' => array(
256 256
                     'id'      => 'gateways',
257
-                    'name'    => __( 'Payment Gateways', 'invoicing' ),
258
-                    'desc'    => __( 'Choose the payment gateways you want to enable.', 'invoicing' ),
257
+                    'name'    => __('Payment Gateways', 'invoicing'),
258
+                    'desc'    => __('Choose the payment gateways you want to enable.', 'invoicing'),
259 259
                     'type'    => 'gateways',
260 260
                     'std'     => array('manual'=>1),
261 261
                     'options' => wpinv_get_payment_gateways(),
262 262
                 ),
263 263
                 'default_gateway' => array(
264 264
                     'id'      => 'default_gateway',
265
-                    'name'    => __( 'Default Gateway', 'invoicing' ),
266
-                    'desc'    => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ),
265
+                    'name'    => __('Default Gateway', 'invoicing'),
266
+                    'desc'    => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'),
267 267
                     'type'    => 'gateway_select',
268 268
                     'std'     => 'manual',
269 269
                     'class'   => 'wpi_select2',
@@ -278,19 +278,19 @@  discard block
 block discarded – undo
278 278
             'main' => array(
279 279
                 'tax_settings' => array(
280 280
                     'id'   => 'tax_settings',
281
-                    'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>',
281
+                    'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>',
282 282
                     'type' => 'header',
283 283
                 ),
284 284
                 'enable_taxes' => array(
285 285
                     'id'   => 'enable_taxes',
286
-                    'name' => __( 'Enable Taxes', 'invoicing' ),
287
-                    'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ),
286
+                    'name' => __('Enable Taxes', 'invoicing'),
287
+                    'desc' => __('Check this to enable taxes on invoices.', 'invoicing'),
288 288
                     'type' => 'checkbox',
289 289
                 ),
290 290
                 'tax_rate' => array(
291 291
                     'id'   => 'tax_rate',
292
-                    'name' => __( 'Fallback Tax Rate', 'invoicing' ),
293
-                    'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ),
292
+                    'name' => __('Fallback Tax Rate', 'invoicing'),
293
+                    'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'),
294 294
                     'type' => 'number',
295 295
                     'size' => 'small',
296 296
                     'min'  => '0',
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
             'rates' => array(
303 303
                 'tax_rates' => array(
304 304
                     'id'   => 'tax_rates',
305
-                    'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>',
306
-                    'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ),
305
+                    'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>',
306
+                    'desc' => __('Enter tax rates for specific regions.', 'invoicing'),
307 307
                     'type' => 'tax_rates',
308 308
                 ),
309 309
             )
@@ -315,68 +315,68 @@  discard block
 block discarded – undo
315 315
             'main' => array(
316 316
                 'email_settings_header' => array(
317 317
                     'id'   => 'email_settings_header',
318
-                    'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>',
318
+                    'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>',
319 319
                     'type' => 'header',
320 320
                 ),
321 321
                 'email_from_name' => array(
322 322
                     'id'   => 'email_from_name',
323
-                    'name' => __( 'From Name', 'invoicing' ),
324
-                    'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ),
325
-                    'std' => esc_attr( get_bloginfo( 'name', 'display' ) ),
323
+                    'name' => __('From Name', 'invoicing'),
324
+                    'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'),
325
+                    'std' => esc_attr(get_bloginfo('name', 'display')),
326 326
                     'type' => 'text',
327 327
                 ),
328 328
                 'email_from' => array(
329 329
                     'id'   => 'email_from',
330
-                    'name' => __( 'From Email', 'invoicing' ),
331
-                    'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close),
332
-                    'std' => get_option( 'admin_email' ),
330
+                    'name' => __('From Email', 'invoicing'),
331
+                    'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close),
332
+                    'std' => get_option('admin_email'),
333 333
                     'type' => 'text',
334 334
                 ),
335 335
                 'admin_email' => array(
336 336
                     'id'   => 'admin_email',
337
-                    'name' => __( 'Admin Email', 'invoicing' ),
338
-                    'desc' => __( 'Where should we send admin notifications?', 'invoicing' ),
339
-                    'std' => get_option( 'admin_email' ),
337
+                    'name' => __('Admin Email', 'invoicing'),
338
+                    'desc' => __('Where should we send admin notifications?', 'invoicing'),
339
+                    'std' => get_option('admin_email'),
340 340
                     'type' => 'text',
341 341
                 ),
342 342
                 'overdue_settings_header' => array(
343 343
                     'id'   => 'overdue_settings_header',
344
-                    'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>',
344
+                    'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>',
345 345
                     'type' => 'header',
346 346
                 ),
347 347
                 'overdue_active' => array(
348 348
                     'id'   => 'overdue_active',
349
-                    'name' => __( 'Enable Due Date', 'invoicing' ),
350
-                    'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ),
349
+                    'name' => __('Enable Due Date', 'invoicing'),
350
+                    'desc' => __('Check this to enable due date option for invoices.', 'invoicing'),
351 351
                     'type' => 'checkbox',
352 352
                     'std'  => false,
353 353
                 ),
354 354
                 'overdue_days' => array(
355 355
                     'id'          => 'overdue_days',
356
-                    'name'        => __( 'Default Due Date', 'invoicing' ),
357
-                    'desc'        => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ),
356
+                    'name'        => __('Default Due Date', 'invoicing'),
357
+                    'desc'        => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'),
358 358
                     'type'        => 'select',
359 359
                     'options'     => $due_payment_options,
360 360
                     'std'         => 0,
361
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
361
+                    'placeholder' => __('Select a page', 'invoicing'),
362 362
                 ),
363 363
                 'email_template_header' => array(
364 364
                     'id'   => 'email_template_header',
365
-                    'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>',
365
+                    'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>',
366 366
                     'type' => 'header',
367 367
                 ),
368 368
                 'email_header_image' => array(
369 369
                     'id'   => 'email_header_image',
370
-                    'name' => __( 'Header Image', 'invoicing' ),
371
-                    'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ),
370
+                    'name' => __('Header Image', 'invoicing'),
371
+                    'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'),
372 372
                     'std' => '',
373 373
                     'type' => 'text',
374 374
                 ),
375 375
                 'email_footer_text' => array(
376 376
                     'id'   => 'email_footer_text',
377
-                    'name' => __( 'Footer Text', 'invoicing' ),
378
-                    'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ),
379
-                    'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ),
377
+                    'name' => __('Footer Text', 'invoicing'),
378
+                    'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'),
379
+                    'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'),
380 380
                     'type' => 'textarea',
381 381
                     'class' => 'regular-text',
382 382
                     'rows' => 2,
@@ -384,29 +384,29 @@  discard block
 block discarded – undo
384 384
                 ),
385 385
                 'email_base_color' => array(
386 386
                     'id'   => 'email_base_color',
387
-                    'name' => __( 'Base Color', 'invoicing' ),
388
-                    'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ),
387
+                    'name' => __('Base Color', 'invoicing'),
388
+                    'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'),
389 389
                     'std' => '#557da2',
390 390
                     'type' => 'color',
391 391
                 ),
392 392
                 'email_background_color' => array(
393 393
                     'id'   => 'email_background_color',
394
-                    'name' => __( 'Background Color', 'invoicing' ),
395
-                    'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ),
394
+                    'name' => __('Background Color', 'invoicing'),
395
+                    'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'),
396 396
                     'std' => '#f5f5f5',
397 397
                     'type' => 'color',
398 398
                 ),
399 399
                 'email_body_background_color' => array(
400 400
                     'id'   => 'email_body_background_color',
401
-                    'name' => __( 'Body Background Color', 'invoicing' ),
402
-                    'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ),
401
+                    'name' => __('Body Background Color', 'invoicing'),
402
+                    'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'),
403 403
                     'std' => '#fdfdfd',
404 404
                     'type' => 'color',
405 405
                 ),
406 406
                 'email_text_color' => array(
407 407
                     'id'   => 'email_text_color',
408
-                    'name' => __( 'Body Text Color', 'invoicing' ),
409
-                    'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ),
408
+                    'name' => __('Body Text Color', 'invoicing'),
409
+                    'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'),
410 410
                     'std' => '#505050',
411 411
                     'type' => 'color',
412 412
                 ),
@@ -425,17 +425,17 @@  discard block
 block discarded – undo
425 425
             'main' => array(
426 426
                 'invoicing_privacy_policy_settings' => array(
427 427
                     'id'   => 'invoicing_privacy_policy_settings',
428
-                    'name' => '<h3>' . __( 'Privacy Policy', 'invoicing' ) . '</h3>',
428
+                    'name' => '<h3>' . __('Privacy Policy', 'invoicing') . '</h3>',
429 429
                     'type' => 'header',
430 430
                 ),
431 431
                 'privacy_page' => array(
432 432
                     'id'          => 'privacy_page',
433
-                    'name'        => __( 'Privacy Page', 'invoicing' ),
434
-                    'desc'        => __( 'If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing' ),
433
+                    'name'        => __('Privacy Page', 'invoicing'),
434
+                    'desc'        => __('If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing'),
435 435
                     'type'        => 'select',
436
-                    'options'     => wpinv_get_pages( true,  __( 'Select a page', 'invoicing' )),
436
+                    'options'     => wpinv_get_pages(true, __('Select a page', 'invoicing')),
437 437
                     'class'       => 'wpi_select2',
438
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
438
+                    'placeholder' => __('Select a page', 'invoicing'),
439 439
                 ),
440 440
             ),
441 441
         )
@@ -446,19 +446,19 @@  discard block
 block discarded – undo
446 446
             'main' => array(
447 447
                 'invoice_number_format_settings' => array(
448 448
                     'id'   => 'invoice_number_format_settings',
449
-                    'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>',
449
+                    'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>',
450 450
                     'type' => 'header',
451 451
                 ),
452 452
                 'sequential_invoice_number' => array(
453 453
                     'id'   => 'sequential_invoice_number',
454
-                    'name' => __( 'Sequential Invoice Numbers', 'invoicing' ),
455
-                    'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing' ) . $reset_number,
454
+                    'name' => __('Sequential Invoice Numbers', 'invoicing'),
455
+                    'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing') . $reset_number,
456 456
                     'type' => 'checkbox',
457 457
                 ),
458 458
                 'invoice_sequence_start' => array(
459 459
                     'id'   => 'invoice_sequence_start',
460
-                    'name' => __( 'Sequential Starting Number', 'invoicing' ),
461
-                    'desc' => __( 'The number at which the invoice number sequence should begin.', 'invoicing' ) . $last_number,
460
+                    'name' => __('Sequential Starting Number', 'invoicing'),
461
+                    'desc' => __('The number at which the invoice number sequence should begin.', 'invoicing') . $last_number,
462 462
                     'type' => 'number',
463 463
                     'size' => 'small',
464 464
                     'std'  => '1',
@@ -466,8 +466,8 @@  discard block
 block discarded – undo
466 466
                 ),
467 467
                 'invoice_number_padd' => array(
468 468
                     'id'      => 'invoice_number_padd',
469
-                    'name'    => __( 'Minimum Digits', 'invoicing' ),
470
-                    'desc'    => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ),
469
+                    'name'    => __('Minimum Digits', 'invoicing'),
470
+                    'desc'    => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'),
471 471
                     'type'    => 'select',
472 472
                     'options' => $invoice_number_padd_options,
473 473
                     'std'     => 5,
@@ -475,8 +475,8 @@  discard block
 block discarded – undo
475 475
                 ),
476 476
                 'invoice_number_prefix' => array(
477 477
                     'id' => 'invoice_number_prefix',
478
-                    'name' => __( 'Invoice Number Prefix', 'invoicing' ),
479
-                    'desc' => __( 'Prefix for all invoice numbers. Ex: INV-', 'invoicing' ),
478
+                    'name' => __('Invoice Number Prefix', 'invoicing'),
479
+                    'desc' => __('Prefix for all invoice numbers. Ex: INV-', 'invoicing'),
480 480
                     'type' => 'text',
481 481
                     'size' => 'regular',
482 482
                     'std' => 'INV-',
@@ -484,32 +484,32 @@  discard block
 block discarded – undo
484 484
                 ),
485 485
                 'invoice_number_postfix' => array(
486 486
                     'id' => 'invoice_number_postfix',
487
-                    'name' => __( 'Invoice Number Postfix', 'invoicing' ),
488
-                    'desc' => __( 'Postfix for all invoice numbers.', 'invoicing' ),
487
+                    'name' => __('Invoice Number Postfix', 'invoicing'),
488
+                    'desc' => __('Postfix for all invoice numbers.', 'invoicing'),
489 489
                     'type' => 'text',
490 490
                     'size' => 'regular',
491 491
                     'std' => ''
492 492
                 ),
493 493
                 'checkout_settings' => array(
494 494
                     'id'   => 'checkout_settings',
495
-                    'name' => '<h3>' . __( 'Checkout Settings', 'invoicing' ) . '</h3>',
495
+                    'name' => '<h3>' . __('Checkout Settings', 'invoicing') . '</h3>',
496 496
                     'type' => 'header',
497 497
                 ),
498 498
                 'login_to_checkout' => array(
499 499
                     'id'   => 'login_to_checkout',
500
-                    'name' => __( 'Require Login To Checkout', 'invoicing' ),
501
-                    'desc' => __( 'If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing' ),
500
+                    'name' => __('Require Login To Checkout', 'invoicing'),
501
+                    'desc' => __('If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing'),
502 502
                     'type' => 'checkbox',
503 503
                 ),
504 504
                 'uninstall_settings' => array(
505 505
                     'id'   => 'uninstall_settings',
506
-                    'name' => '<h3>' . __( 'Uninstall Settings', 'invoicing' ) . '</h3>',
506
+                    'name' => '<h3>' . __('Uninstall Settings', 'invoicing') . '</h3>',
507 507
                     'type' => 'header',
508 508
                 ),
509 509
                 'remove_data_on_unistall' => array(
510 510
                     'id'   => 'remove_data_on_unistall',
511
-                    'name' => __( 'Remove Data on Uninstall?', 'invoicing' ),
512
-                    'desc' => __( 'Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing' ),
511
+                    'name' => __('Remove Data on Uninstall?', 'invoicing'),
512
+                    'desc' => __('Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing'),
513 513
                     'type' => 'checkbox',
514 514
                     'std'  => ''
515 515
                 ),
@@ -517,20 +517,20 @@  discard block
 block discarded – undo
517 517
             'fields' => array(
518 518
                 'address_autofill_settings' => array(
519 519
                     'id'   => 'address_autofill_settings',
520
-                    'name' => '<h3>' . __( 'Google Address Auto Complete', 'invoicing' ) . '</h3>',
520
+                    'name' => '<h3>' . __('Google Address Auto Complete', 'invoicing') . '</h3>',
521 521
                     'type' => 'header',
522 522
                 ),
523 523
                 'address_autofill_active' => array(
524 524
                     'id'   => 'address_autofill_active',
525
-                    'name' => __( 'Enable/Disable', 'invoicing' ),
526
-                    'desc' => __( 'Enable google address auto complete', 'invoicing' ),
525
+                    'name' => __('Enable/Disable', 'invoicing'),
526
+                    'desc' => __('Enable google address auto complete', 'invoicing'),
527 527
                     'type' => 'checkbox',
528 528
                     'std'  => 0
529 529
                 ),
530 530
                 'address_autofill_api' => array(
531 531
                     'id' => 'address_autofill_api',
532
-                    'name' => __( 'Google Place API Key', 'invoicing' ),
533
-                    'desc' => wp_sprintf(__( 'Enter google place API key. For more information go to google place API %sdocumenation%s', 'invoicing' ), '<a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete" target="_blank">', '</a>' ),
532
+                    'name' => __('Google Place API Key', 'invoicing'),
533
+                    'desc' => wp_sprintf(__('Enter google place API key. For more information go to google place API %sdocumenation%s', 'invoicing'), '<a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete" target="_blank">', '</a>'),
534 534
                     'type' => 'text',
535 535
                     'size' => 'regular',
536 536
                     'std' => ''
@@ -539,13 +539,13 @@  discard block
 block discarded – undo
539 539
             'custom-css' => array(
540 540
                 'css_settings' => array(
541 541
                     'id'   => 'css_settings',
542
-                    'name' => '<h3>' . __( 'Custom CSS', 'invoicing' ) . '</h3>',
542
+                    'name' => '<h3>' . __('Custom CSS', 'invoicing') . '</h3>',
543 543
                     'type' => 'header',
544 544
                 ),
545 545
                 'template_custom_css' => array(
546 546
                     'id' => 'template_custom_css',
547
-                    'name' => __( 'Invoice Template CSS', 'invoicing' ),
548
-                    'desc' => __( 'Add CSS to modify appearance of the print invoice page.', 'invoicing' ),
547
+                    'name' => __('Invoice Template CSS', 'invoicing'),
548
+                    'desc' => __('Add CSS to modify appearance of the print invoice page.', 'invoicing'),
549 549
                     'type' => 'textarea',
550 550
                     'class'=> 'regular-text',
551 551
                     'rows' => 10,
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
             'main' => array(
560 560
                 'tool_settings' => array(
561 561
                     'id'   => 'tool_settings',
562
-                    'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>',
563
-                    'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ),
562
+                    'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>',
563
+                    'desc' => __('Invoicing diagnostic tools', 'invoicing'),
564 564
                     'type' => 'tools',
565 565
                 ),
566 566
             ),
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 2 patches
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Invoice_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -106,61 +106,61 @@  discard block
 block discarded – undo
106 106
 	 *
107 107
 	 * @param WPInv_Invoice $invoice Invoice object.
108 108
 	 */
109
-	public function create( &$invoice ) {
110
-		$invoice->set_version( WPINV_VERSION );
111
-		$invoice->set_date_created( current_time('mysql') );
109
+	public function create(&$invoice) {
110
+		$invoice->set_version(WPINV_VERSION);
111
+		$invoice->set_date_created(current_time('mysql'));
112 112
 
113 113
 		// Create a new post.
114 114
 		$id = wp_insert_post(
115 115
 			apply_filters(
116 116
 				'getpaid_new_invoice_data',
117 117
 				array(
118
-					'post_date'     => $invoice->get_date_created( 'edit' ),
119
-					'post_type'     => $invoice->get_post_type( 'edit' ),
120
-					'post_status'   => $this->get_post_status( $invoice ),
118
+					'post_date'     => $invoice->get_date_created('edit'),
119
+					'post_type'     => $invoice->get_post_type('edit'),
120
+					'post_status'   => $this->get_post_status($invoice),
121 121
 					'ping_status'   => 'closed',
122
-					'post_author'   => $invoice->get_user_id( 'edit' ),
123
-					'post_title'    => $invoice->get_title( 'edit' ),
124
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
125
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
122
+					'post_author'   => $invoice->get_user_id('edit'),
123
+					'post_title'    => $invoice->get_title('edit'),
124
+					'post_excerpt'  => $invoice->get_description('edit'),
125
+					'post_parent'   => $invoice->get_parent_id('edit'),
126 126
 				)
127 127
 			),
128 128
 			true
129 129
 		);
130 130
 
131
-		if ( $id && ! is_wp_error( $id ) ) {
131
+		if ($id && !is_wp_error($id)) {
132 132
 
133 133
 			// Update the new id and regenerate a title.
134
-			$invoice->set_id( $id );
134
+			$invoice->set_id($id);
135 135
 
136 136
 			$invoice->maybe_set_number();
137 137
 
138 138
 			wp_update_post(
139 139
 				array(
140 140
 					'ID'         => $invoice->get_id(),
141
-					'post_title' => $invoice->get_number( 'edit' ),
142
-					'post_name'  => $invoice->get_path( 'edit' )
141
+					'post_title' => $invoice->get_number('edit'),
142
+					'post_name'  => $invoice->get_path('edit')
143 143
 				)
144 144
 			);
145 145
 
146 146
 			// Save special fields and items.
147
-			$this->save_special_fields( $invoice );
148
-			$this->save_items( $invoice );
147
+			$this->save_special_fields($invoice);
148
+			$this->save_items($invoice);
149 149
 
150 150
 			// Update meta data.
151
-			$this->update_post_meta( $invoice );
151
+			$this->update_post_meta($invoice);
152 152
 			$invoice->save_meta_data();
153 153
 
154 154
 			// Apply changes.
155 155
 			$invoice->apply_changes();
156
-			$this->clear_caches( $invoice );
156
+			$this->clear_caches($invoice);
157 157
 
158 158
 			// Fires after a new invoice is created.
159
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
159
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice);
160 160
 			return true;
161 161
 		}
162 162
 
163
-		if ( is_wp_error( $id ) ) {
163
+		if (is_wp_error($id)) {
164 164
 			$invoice->last_error = $id->get_error_message();
165 165
 		}
166 166
 
@@ -173,14 +173,14 @@  discard block
 block discarded – undo
173 173
 	 * @param WPInv_Invoice $invoice Invoice object.
174 174
 	 *
175 175
 	 */
176
-	public function read( &$invoice ) {
176
+	public function read(&$invoice) {
177 177
 
178 178
 		$invoice->set_defaults();
179
-		$invoice_object = get_post( $invoice->get_id() );
179
+		$invoice_object = get_post($invoice->get_id());
180 180
 
181
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
182
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
183
-			$invoice->set_id( 0 );
181
+		if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) {
182
+			$invoice->last_error = __('Invalid invoice.', 'invoicing');
183
+			$invoice->set_id(0);
184 184
 			return false;
185 185
 		}
186 186
 
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
 			)
199 199
 		);
200 200
 
201
-		$invoice->set_type( $invoice_object->post_type );
201
+		$invoice->set_type($invoice_object->post_type);
202 202
 
203
-		$this->read_object_data( $invoice, $invoice_object );
204
-		$this->add_special_fields( $invoice );
205
-		$this->add_items( $invoice );
203
+		$this->read_object_data($invoice, $invoice_object);
204
+		$this->add_special_fields($invoice);
205
+		$this->add_items($invoice);
206 206
 		$invoice->read_meta_data();
207
-		$invoice->set_object_read( true );
208
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice );
207
+		$invoice->set_object_read(true);
208
+		do_action('getpaid_read_' . $invoice->get_type(), $invoice);
209 209
 
210 210
 	}
211 211
 
@@ -214,35 +214,35 @@  discard block
 block discarded – undo
214 214
 	 *
215 215
 	 * @param WPInv_Invoice $invoice Invoice object.
216 216
 	 */
217
-	public function update( &$invoice ) {
217
+	public function update(&$invoice) {
218 218
 		$invoice->save_meta_data();
219
-		$invoice->set_version( WPINV_VERSION );
219
+		$invoice->set_version(WPINV_VERSION);
220 220
 
221
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
222
-			$invoice->set_date_created(  current_time('mysql') );
221
+		if (null === $invoice->get_date_created('edit')) {
222
+			$invoice->set_date_created(current_time('mysql'));
223 223
 		}
224 224
 
225 225
 		// Ensure both the key and number are set.
226 226
 		$invoice->get_path();
227 227
 
228 228
 		// Grab the current status so we can compare.
229
-		$previous_status = get_post_status( $invoice->get_id() );
229
+		$previous_status = get_post_status($invoice->get_id());
230 230
 
231 231
 		$changes = $invoice->get_changes();
232 232
 
233 233
 		// Only update the post when the post data changes.
234
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
234
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) {
235 235
 			$post_data = array(
236
-				'post_date'         => $invoice->get_date_created( 'edit' ),
237
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
238
-				'post_status'       => $invoice->get_status( 'edit' ),
239
-				'post_title'        => $invoice->get_name( 'edit' ),
240
-				'post_author'       => $invoice->get_user_id( 'edit' ),
241
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
242
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
243
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
244
-				'post_name'         => $invoice->get_path( 'edit' ),
245
-				'post_type'         => $invoice->get_post_type( 'edit' ),
236
+				'post_date'         => $invoice->get_date_created('edit'),
237
+				'post_date_gmt'     => $invoice->get_date_created_gmt('edit'),
238
+				'post_status'       => $invoice->get_status('edit'),
239
+				'post_title'        => $invoice->get_name('edit'),
240
+				'post_author'       => $invoice->get_user_id('edit'),
241
+				'post_modified'     => $invoice->get_date_modified('edit'),
242
+				'post_excerpt'      => $invoice->get_description('edit'),
243
+				'post_parent'       => $invoice->get_parent_id('edit'),
244
+				'post_name'         => $invoice->get_path('edit'),
245
+				'post_type'         => $invoice->get_post_type('edit'),
246 246
 			);
247 247
 
248 248
 			/**
@@ -253,35 +253,35 @@  discard block
 block discarded – undo
253 253
 			 * This ensures hooks are fired by either WP itself (admin screen save),
254 254
 			 * or an update purely from CRUD.
255 255
 			 */
256
-			if ( doing_action( 'save_post' ) ) {
257
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
258
-				clean_post_cache( $invoice->get_id() );
256
+			if (doing_action('save_post')) {
257
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id()));
258
+				clean_post_cache($invoice->get_id());
259 259
 			} else {
260
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
260
+				wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data));
261 261
 			}
262
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
262
+			$invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
263 263
 		}
264 264
 
265 265
 		// Update meta data.
266
-		$this->update_post_meta( $invoice );
266
+		$this->update_post_meta($invoice);
267 267
 
268 268
 		// Save special fields and items.
269
-		$this->save_special_fields( $invoice );
270
-		$this->save_items( $invoice );
269
+		$this->save_special_fields($invoice);
270
+		$this->save_items($invoice);
271 271
 
272 272
 		// Apply the changes.
273 273
 		$invoice->apply_changes();
274 274
 
275 275
 		// Clear caches.
276
-		$this->clear_caches( $invoice );
276
+		$this->clear_caches($invoice);
277 277
 
278 278
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
279
-		$new_status = $invoice->get_status( 'edit' );
279
+		$new_status = $invoice->get_status('edit');
280 280
 
281
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
282
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
281
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
282
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice);
283 283
 		} else {
284
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice );
284
+			do_action('getpaid_update_' . $invoice->get_type(), $invoice);
285 285
 		}
286 286
 
287 287
 	}
@@ -297,45 +297,45 @@  discard block
 block discarded – undo
297 297
 	 *
298 298
 	 * @param WPInv_Invoice $invoice Invoice object.
299 299
      */
300
-    public function add_special_fields( &$invoice ) {
300
+    public function add_special_fields(&$invoice) {
301 301
 		global $wpdb;
302 302
 
303 303
 		// Maybe retrieve from the cache.
304
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
304
+		$data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields');
305 305
 
306 306
 		// If not found, retrieve from the db.
307
-		if ( false === $data ) {
308
-			$table =  $wpdb->prefix . 'getpaid_invoices';
307
+		if (false === $data) {
308
+			$table = $wpdb->prefix . 'getpaid_invoices';
309 309
 
310 310
 			$data  = $wpdb->get_row(
311
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
311
+				$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()),
312 312
 				ARRAY_A
313 313
 			);
314 314
 
315 315
 			// Update the cache with our data
316
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
316
+			wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields');
317 317
 
318 318
 		}
319 319
 
320 320
 		// Abort if the data does not exist.
321
-		if ( empty( $data ) ) {
322
-			$invoice->set_object_read( true );
323
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
321
+		if (empty($data)) {
322
+			$invoice->set_object_read(true);
323
+			$invoice->set_props(wpinv_get_user_address($invoice->get_user_id()));
324 324
 			return;
325 325
 		}
326 326
 
327 327
 		$props = array();
328 328
 
329
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
329
+		foreach ($this->database_fields_to_props as $db_field => $prop) {
330 330
 			
331
-			if ( $db_field == 'post_id' ) {
331
+			if ($db_field == 'post_id') {
332 332
 				continue;
333 333
 			}
334 334
 
335
-			$props[ $prop ] = $data[ $db_field ];
335
+			$props[$prop] = $data[$db_field];
336 336
 		}
337 337
 
338
-		$invoice->set_props( $props );
338
+		$invoice->set_props($props);
339 339
 
340 340
 	}
341 341
 
@@ -346,14 +346,14 @@  discard block
 block discarded – undo
346 346
 	 * @param  WPInv_Invoice $invoice       The Invoice object.
347 347
 	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
348 348
 	 */
349
-	protected function get_special_fields_to_update( $invoice ) {
349
+	protected function get_special_fields_to_update($invoice) {
350 350
 		$fields_to_update = array();
351
-		$changed_props   = $invoice->get_changes();
351
+		$changed_props = $invoice->get_changes();
352 352
 
353 353
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
354
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
355
-			if ( array_key_exists( $prop, $changed_props ) ) {
356
-				$fields_to_update[ $database_field ] = $prop;
354
+		foreach ($this->database_fields_to_props as $database_field => $prop) {
355
+			if (array_key_exists($prop, $changed_props)) {
356
+				$fields_to_update[$database_field] = $prop;
357 357
 			}
358 358
 		}
359 359
 
@@ -366,25 +366,25 @@  discard block
 block discarded – undo
366 366
 	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
367 367
 	 * @since 1.0.19
368 368
 	 */
369
-	protected function update_special_fields( &$invoice ) {
369
+	protected function update_special_fields(&$invoice) {
370 370
 		global $wpdb;
371 371
 
372 372
 		$updated_props    = array();
373
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
373
+		$fields_to_update = $this->get_special_fields_to_update($invoice);
374 374
 
375
-		foreach ( $fields_to_update as $database_field => $prop ) {
376
-			$value = $invoice->{"get_$prop"}( 'edit' );
377
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
378
-			$value = is_bool( $value ) ? ( int ) $value : $value;
379
-			$updated_props[ $database_field ] = maybe_serialize( $value );
375
+		foreach ($fields_to_update as $database_field => $prop) {
376
+			$value = $invoice->{"get_$prop"}('edit');
377
+			$value = is_string($value) ? wp_slash($value) : $value;
378
+			$value = is_bool($value) ? (int) $value : $value;
379
+			$updated_props[$database_field] = maybe_serialize($value);
380 380
 		}
381 381
 
382
-		if ( ! empty( $updated_props ) ) {
382
+		if (!empty($updated_props)) {
383 383
 
384 384
 			$table = $wpdb->prefix . 'getpaid_invoices';
385
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
386
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
387
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
385
+			$wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id()));
386
+			wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields');
387
+			do_action("getpaid_invoice_update_database_fields", $invoice, $updated_props);
388 388
 
389 389
 		}
390 390
 
@@ -396,22 +396,22 @@  discard block
 block discarded – undo
396 396
 	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
397 397
 	 * @since 1.0.19
398 398
 	 */
399
-	protected function insert_special_fields( &$invoice ) {
399
+	protected function insert_special_fields(&$invoice) {
400 400
 		global $wpdb;
401 401
 
402
-		$updated_props   = array();
402
+		$updated_props = array();
403 403
 
404
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
405
-			$value = $invoice->{"get_$prop"}( 'edit' );
406
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
407
-			$value = is_bool( $value ) ? ( int ) $value : $value;
408
-			$updated_props[ $database_field ] = maybe_serialize( $value );
404
+		foreach ($this->database_fields_to_props as $database_field => $prop) {
405
+			$value = $invoice->{"get_$prop"}('edit');
406
+			$value = is_string($value) ? wp_slash($value) : $value;
407
+			$value = is_bool($value) ? (int) $value : $value;
408
+			$updated_props[$database_field] = maybe_serialize($value);
409 409
 		}
410 410
 
411 411
 		$table = $wpdb->prefix . 'getpaid_invoices';
412
-		$wpdb->insert( $table, $updated_props );
413
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
414
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
412
+		$wpdb->insert($table, $updated_props);
413
+		wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields');
414
+		do_action("getpaid_invoice_insert_database_fields", $invoice, $updated_props);
415 415
 
416 416
 	}
417 417
 
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 	 *
421 421
 	 * @param WPInv_Invoice $invoice Invoice object.
422 422
      */
423
-    public function save_special_fields( & $invoice ) {
423
+    public function save_special_fields(& $invoice) {
424 424
 		global $wpdb;
425 425
 
426 426
 		// The invoices table.
@@ -428,13 +428,13 @@  discard block
 block discarded – undo
428 428
 		$id    = (int) $invoice->get_id();
429 429
 		$invoice->maybe_set_key();
430 430
 
431
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
431
+		if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) {
432 432
 
433
-			$this->update_special_fields( $invoice );
433
+			$this->update_special_fields($invoice);
434 434
 
435 435
 		} else {
436 436
 
437
-			$this->insert_special_fields( $invoice );
437
+			$this->insert_special_fields($invoice);
438 438
 
439 439
 		}
440 440
 
@@ -445,43 +445,43 @@  discard block
 block discarded – undo
445 445
 	 *
446 446
 	 * @param WPInv_Invoice $invoice Invoice object.
447 447
      */
448
-    public function add_items( &$invoice ) {
448
+    public function add_items(&$invoice) {
449 449
 		global $wpdb;
450 450
 
451 451
 		// Maybe retrieve from the cache.
452
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
452
+		$items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details');
453 453
 
454 454
 		// If not found, retrieve from the db.
455
-		if ( false === $items ) {
456
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
455
+		if (false === $items) {
456
+			$table = $wpdb->prefix . 'getpaid_invoice_items';
457 457
 
458 458
 			$items = $wpdb->get_results(
459
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
459
+				$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id())
460 460
 			);
461 461
 
462 462
 			// Update the cache with our data
463
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
463
+			wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details');
464 464
 
465 465
 		}
466 466
 
467 467
 		// Abort if no items found.
468
-        if ( empty( $items ) ) {
468
+        if (empty($items)) {
469 469
             return;
470 470
 		}
471 471
 
472
-		foreach ( $items as $item_data ) {
473
-			$item = new GetPaid_Form_Item( $item_data->item_id );
472
+		foreach ($items as $item_data) {
473
+			$item = new GetPaid_Form_Item($item_data->item_id);
474 474
 
475 475
 			// Set item data.
476
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
477
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
478
-			$item->set_name( $item_data->item_name );
479
-			$item->set_description( $item_data->item_description );
480
-			$item->set_price( $item_data->item_price );
481
-			$item->set_quantity( $item_data->quantity );
482
-			$item->set_item_meta( $item_data->meta );
483
-
484
-			$invoice->add_item( $item );
476
+			$item->item_tax      = wpinv_sanitize_amount($item_data->tax);
477
+			$item->item_discount = wpinv_sanitize_amount($item_data->discount);
478
+			$item->set_name($item_data->item_name);
479
+			$item->set_description($item_data->item_description);
480
+			$item->set_price($item_data->item_price);
481
+			$item->set_quantity($item_data->quantity);
482
+			$item->set_item_meta($item_data->meta);
483
+
484
+			$invoice->add_item($item);
485 485
 		}
486 486
 
487 487
 	}
@@ -491,20 +491,20 @@  discard block
 block discarded – undo
491 491
 	 *
492 492
 	 * @param WPInv_Invoice $invoice Invoice object.
493 493
      */
494
-    public function save_items( $invoice ) {
494
+    public function save_items($invoice) {
495 495
 
496 496
 		// Delete previously existing items.
497
-		$this->delete_items( $invoice );
497
+		$this->delete_items($invoice);
498 498
 
499
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
499
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
500 500
 
501
-		foreach ( $invoice->get_cart_details() as $item_data ) {
502
-			$item_data = array_map( 'maybe_serialize', $item_data );
503
-			$GLOBALS['wpdb']->insert( $table, $item_data );
501
+		foreach ($invoice->get_cart_details() as $item_data) {
502
+			$item_data = array_map('maybe_serialize', $item_data);
503
+			$GLOBALS['wpdb']->insert($table, $item_data);
504 504
 		}
505 505
 
506
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
507
-		do_action( "getpaid_invoice_save_items", $invoice );
506
+		wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details');
507
+		do_action("getpaid_invoice_save_items", $invoice);
508 508
 
509 509
 	}
510 510
 
@@ -513,9 +513,9 @@  discard block
 block discarded – undo
513 513
 	 *
514 514
 	 * @param WPInv_Invoice $invoice Invoice object.
515 515
      */
516
-    public function delete_items( $invoice ) {
517
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
518
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
516
+    public function delete_items($invoice) {
517
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
518
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id()));
519 519
 	}
520 520
 
521 521
 	/**
@@ -523,9 +523,9 @@  discard block
 block discarded – undo
523 523
 	 *
524 524
 	 * @param WPInv_Invoice $invoice Invoice object.
525 525
      */
526
-    public function delete_special_fields( $invoice ) {
527
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
528
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
526
+    public function delete_special_fields($invoice) {
527
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
528
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id()));
529 529
     }
530 530
 
531 531
 }
Please login to merge, or discard this patch.
Indentation   +449 added lines, -449 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,519 +15,519 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'wpinv_email_cc',
34
-		'wpinv_template',
35
-		'wpinv_created_via'
36
-	);
37
-
38
-	/**
39
-	 * A map of meta keys to data props.
40
-	 *
41
-	 * @since 1.0.19
42
-	 *
43
-	 * @var array
44
-	 */
45
-	protected $meta_key_to_props = array(
46
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
47
-		'_wpinv_subscription_id'   => 'subscription_id',
48
-		'_wpinv_taxes'             => 'taxes',
49
-		'_wpinv_fees'              => 'fees',
50
-		'_wpinv_discounts'         => 'discounts',
51
-		'_wpinv_submission_id'     => 'submission_id',
52
-		'_wpinv_payment_form'      => 'payment_form',
53
-		'_wpinv_is_viewed'         => 'is_viewed',
54
-		'wpinv_email_cc'           => 'email_cc',
55
-		'wpinv_template'           => 'template',
56
-		'wpinv_created_via'        => 'created_via',
57
-	);
58
-
59
-	/**
60
-	 * A map of database fields to data props.
61
-	 *
62
-	 * @since 1.0.19
63
-	 *
64
-	 * @var array
65
-	 */
66
-	protected $database_fields_to_props = array(
67
-		'post_id'            => 'id',
68
-		'number'             => 'number',
69
-		'currency'           => 'currency',
70
-		'key'                => 'key',
71
-		'type'               => 'type',
72
-		'mode'               => 'mode',
73
-		'user_ip'            => 'user_ip',
74
-		'first_name'         => 'first_name',
75
-		'last_name'          => 'last_name',
76
-		'address'            => 'address',
77
-		'city'               => 'city',
78
-		'state'              => 'state',
79
-		'country'            => 'country',
80
-		'zip'                => 'zip',
81
-		'zip'                => 'zip',
82
-		'adddress_confirmed' => 'address_confirmed',
83
-		'gateway'            => 'gateway',
84
-		'transaction_id'     => 'transaction_id',
85
-		'currency'           => 'currency',
86
-		'subtotal'           => 'subtotal',
87
-		'tax'                => 'total_tax',
88
-		'fees_total'         => 'total_fees',
89
-		'discount'           => 'total_discount',
90
-		'total'              => 'total',
91
-		'discount_code'      => 'discount_code',
92
-		'disable_taxes'      => 'disable_taxes',
93
-		'due_date'           => 'due_date',
94
-		'completed_date'     => 'completed_date',
95
-		'company'            => 'company',
96
-		'vat_number'         => 'vat_number',
97
-		'vat_rate'           => 'vat_rate',
98
-	);
99
-
100
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        'wpinv_email_cc',
34
+        'wpinv_template',
35
+        'wpinv_created_via'
36
+    );
37
+
38
+    /**
39
+     * A map of meta keys to data props.
40
+     *
41
+     * @since 1.0.19
42
+     *
43
+     * @var array
44
+     */
45
+    protected $meta_key_to_props = array(
46
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
47
+        '_wpinv_subscription_id'   => 'subscription_id',
48
+        '_wpinv_taxes'             => 'taxes',
49
+        '_wpinv_fees'              => 'fees',
50
+        '_wpinv_discounts'         => 'discounts',
51
+        '_wpinv_submission_id'     => 'submission_id',
52
+        '_wpinv_payment_form'      => 'payment_form',
53
+        '_wpinv_is_viewed'         => 'is_viewed',
54
+        'wpinv_email_cc'           => 'email_cc',
55
+        'wpinv_template'           => 'template',
56
+        'wpinv_created_via'        => 'created_via',
57
+    );
58
+
59
+    /**
60
+     * A map of database fields to data props.
61
+     *
62
+     * @since 1.0.19
63
+     *
64
+     * @var array
65
+     */
66
+    protected $database_fields_to_props = array(
67
+        'post_id'            => 'id',
68
+        'number'             => 'number',
69
+        'currency'           => 'currency',
70
+        'key'                => 'key',
71
+        'type'               => 'type',
72
+        'mode'               => 'mode',
73
+        'user_ip'            => 'user_ip',
74
+        'first_name'         => 'first_name',
75
+        'last_name'          => 'last_name',
76
+        'address'            => 'address',
77
+        'city'               => 'city',
78
+        'state'              => 'state',
79
+        'country'            => 'country',
80
+        'zip'                => 'zip',
81
+        'zip'                => 'zip',
82
+        'adddress_confirmed' => 'address_confirmed',
83
+        'gateway'            => 'gateway',
84
+        'transaction_id'     => 'transaction_id',
85
+        'currency'           => 'currency',
86
+        'subtotal'           => 'subtotal',
87
+        'tax'                => 'total_tax',
88
+        'fees_total'         => 'total_fees',
89
+        'discount'           => 'total_discount',
90
+        'total'              => 'total',
91
+        'discount_code'      => 'discount_code',
92
+        'disable_taxes'      => 'disable_taxes',
93
+        'due_date'           => 'due_date',
94
+        'completed_date'     => 'completed_date',
95
+        'company'            => 'company',
96
+        'vat_number'         => 'vat_number',
97
+        'vat_rate'           => 'vat_rate',
98
+    );
99
+
100
+    /*
101 101
 	|--------------------------------------------------------------------------
102 102
 	| CRUD Methods
103 103
 	|--------------------------------------------------------------------------
104 104
 	*/
105 105
 
106
-	/**
107
-	 * Method to create a new invoice in the database.
108
-	 *
109
-	 * @param WPInv_Invoice $invoice Invoice object.
110
-	 */
111
-	public function create( &$invoice ) {
112
-		$invoice->set_version( WPINV_VERSION );
113
-		$invoice->set_date_created( current_time('mysql') );
114
-
115
-		// Create a new post.
116
-		$id = wp_insert_post(
117
-			apply_filters(
118
-				'getpaid_new_invoice_data',
119
-				array(
120
-					'post_date'     => $invoice->get_date_created( 'edit' ),
121
-					'post_type'     => $invoice->get_post_type( 'edit' ),
122
-					'post_status'   => $this->get_post_status( $invoice ),
123
-					'ping_status'   => 'closed',
124
-					'post_author'   => $invoice->get_user_id( 'edit' ),
125
-					'post_title'    => $invoice->get_title( 'edit' ),
126
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
127
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
128
-				)
129
-			),
130
-			true
131
-		);
132
-
133
-		if ( $id && ! is_wp_error( $id ) ) {
134
-
135
-			// Update the new id and regenerate a title.
136
-			$invoice->set_id( $id );
137
-
138
-			$invoice->maybe_set_number();
139
-
140
-			wp_update_post(
141
-				array(
142
-					'ID'         => $invoice->get_id(),
143
-					'post_title' => $invoice->get_number( 'edit' ),
144
-					'post_name'  => $invoice->get_path( 'edit' )
145
-				)
146
-			);
147
-
148
-			// Save special fields and items.
149
-			$this->save_special_fields( $invoice );
150
-			$this->save_items( $invoice );
151
-
152
-			// Update meta data.
153
-			$this->update_post_meta( $invoice );
154
-			$invoice->save_meta_data();
155
-
156
-			// Apply changes.
157
-			$invoice->apply_changes();
158
-			$this->clear_caches( $invoice );
159
-
160
-			// Fires after a new invoice is created.
161
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
162
-			return true;
163
-		}
164
-
165
-		if ( is_wp_error( $id ) ) {
166
-			$invoice->last_error = $id->get_error_message();
167
-		}
168
-
169
-		return false;
170
-	}
171
-
172
-	/**
173
-	 * Method to read an invoice from the database.
174
-	 *
175
-	 * @param WPInv_Invoice $invoice Invoice object.
176
-	 *
177
-	 */
178
-	public function read( &$invoice ) {
179
-
180
-		$invoice->set_defaults();
181
-		$invoice_object = get_post( $invoice->get_id() );
182
-
183
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
184
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
185
-			$invoice->set_id( 0 );
186
-			return false;
187
-		}
188
-
189
-		$invoice->set_props(
190
-			array(
191
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
192
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
193
-				'status'        => $invoice_object->post_status,
194
-				'author'        => $invoice_object->post_author,
195
-				'description'   => $invoice_object->post_excerpt,
196
-				'parent_id'     => $invoice_object->post_parent,
197
-				'name'          => $invoice_object->post_title,
198
-				'path'          => $invoice_object->post_name,
199
-				'post_type'     => $invoice_object->post_type,
200
-			)
201
-		);
202
-
203
-		$invoice->set_type( $invoice_object->post_type );
204
-
205
-		$this->read_object_data( $invoice, $invoice_object );
206
-		$this->add_special_fields( $invoice );
207
-		$this->add_items( $invoice );
208
-		$invoice->read_meta_data();
209
-		$invoice->set_object_read( true );
210
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice );
211
-
212
-	}
213
-
214
-	/**
215
-	 * Method to update an invoice in the database.
216
-	 *
217
-	 * @param WPInv_Invoice $invoice Invoice object.
218
-	 */
219
-	public function update( &$invoice ) {
220
-		$invoice->save_meta_data();
221
-		$invoice->set_version( WPINV_VERSION );
222
-
223
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
224
-			$invoice->set_date_created(  current_time('mysql') );
225
-		}
226
-
227
-		// Ensure both the key and number are set.
228
-		$invoice->get_path();
229
-
230
-		// Grab the current status so we can compare.
231
-		$previous_status = get_post_status( $invoice->get_id() );
232
-
233
-		$changes = $invoice->get_changes();
234
-
235
-		// Only update the post when the post data changes.
236
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
237
-			$post_data = array(
238
-				'post_date'         => $invoice->get_date_created( 'edit' ),
239
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
240
-				'post_status'       => $invoice->get_status( 'edit' ),
241
-				'post_title'        => $invoice->get_name( 'edit' ),
242
-				'post_author'       => $invoice->get_user_id( 'edit' ),
243
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
244
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
245
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
246
-				'post_name'         => $invoice->get_path( 'edit' ),
247
-				'post_type'         => $invoice->get_post_type( 'edit' ),
248
-			);
249
-
250
-			/**
251
-			 * When updating this object, to prevent infinite loops, use $wpdb
252
-			 * to update data, since wp_update_post spawns more calls to the
253
-			 * save_post action.
254
-			 *
255
-			 * This ensures hooks are fired by either WP itself (admin screen save),
256
-			 * or an update purely from CRUD.
257
-			 */
258
-			if ( doing_action( 'save_post' ) ) {
259
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
260
-				clean_post_cache( $invoice->get_id() );
261
-			} else {
262
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
263
-			}
264
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
265
-		}
266
-
267
-		// Update meta data.
268
-		$this->update_post_meta( $invoice );
269
-
270
-		// Save special fields and items.
271
-		$this->save_special_fields( $invoice );
272
-		$this->save_items( $invoice );
273
-
274
-		// Apply the changes.
275
-		$invoice->apply_changes();
276
-
277
-		// Clear caches.
278
-		$this->clear_caches( $invoice );
279
-
280
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
281
-		$new_status = $invoice->get_status( 'edit' );
282
-
283
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
284
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
285
-		} else {
286
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice );
287
-		}
288
-
289
-	}
290
-
291
-	/*
106
+    /**
107
+     * Method to create a new invoice in the database.
108
+     *
109
+     * @param WPInv_Invoice $invoice Invoice object.
110
+     */
111
+    public function create( &$invoice ) {
112
+        $invoice->set_version( WPINV_VERSION );
113
+        $invoice->set_date_created( current_time('mysql') );
114
+
115
+        // Create a new post.
116
+        $id = wp_insert_post(
117
+            apply_filters(
118
+                'getpaid_new_invoice_data',
119
+                array(
120
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
121
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
122
+                    'post_status'   => $this->get_post_status( $invoice ),
123
+                    'ping_status'   => 'closed',
124
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
125
+                    'post_title'    => $invoice->get_title( 'edit' ),
126
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
127
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
128
+                )
129
+            ),
130
+            true
131
+        );
132
+
133
+        if ( $id && ! is_wp_error( $id ) ) {
134
+
135
+            // Update the new id and regenerate a title.
136
+            $invoice->set_id( $id );
137
+
138
+            $invoice->maybe_set_number();
139
+
140
+            wp_update_post(
141
+                array(
142
+                    'ID'         => $invoice->get_id(),
143
+                    'post_title' => $invoice->get_number( 'edit' ),
144
+                    'post_name'  => $invoice->get_path( 'edit' )
145
+                )
146
+            );
147
+
148
+            // Save special fields and items.
149
+            $this->save_special_fields( $invoice );
150
+            $this->save_items( $invoice );
151
+
152
+            // Update meta data.
153
+            $this->update_post_meta( $invoice );
154
+            $invoice->save_meta_data();
155
+
156
+            // Apply changes.
157
+            $invoice->apply_changes();
158
+            $this->clear_caches( $invoice );
159
+
160
+            // Fires after a new invoice is created.
161
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
162
+            return true;
163
+        }
164
+
165
+        if ( is_wp_error( $id ) ) {
166
+            $invoice->last_error = $id->get_error_message();
167
+        }
168
+
169
+        return false;
170
+    }
171
+
172
+    /**
173
+     * Method to read an invoice from the database.
174
+     *
175
+     * @param WPInv_Invoice $invoice Invoice object.
176
+     *
177
+     */
178
+    public function read( &$invoice ) {
179
+
180
+        $invoice->set_defaults();
181
+        $invoice_object = get_post( $invoice->get_id() );
182
+
183
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
184
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
185
+            $invoice->set_id( 0 );
186
+            return false;
187
+        }
188
+
189
+        $invoice->set_props(
190
+            array(
191
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
192
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
193
+                'status'        => $invoice_object->post_status,
194
+                'author'        => $invoice_object->post_author,
195
+                'description'   => $invoice_object->post_excerpt,
196
+                'parent_id'     => $invoice_object->post_parent,
197
+                'name'          => $invoice_object->post_title,
198
+                'path'          => $invoice_object->post_name,
199
+                'post_type'     => $invoice_object->post_type,
200
+            )
201
+        );
202
+
203
+        $invoice->set_type( $invoice_object->post_type );
204
+
205
+        $this->read_object_data( $invoice, $invoice_object );
206
+        $this->add_special_fields( $invoice );
207
+        $this->add_items( $invoice );
208
+        $invoice->read_meta_data();
209
+        $invoice->set_object_read( true );
210
+        do_action( 'getpaid_read_' . $invoice->get_type(), $invoice );
211
+
212
+    }
213
+
214
+    /**
215
+     * Method to update an invoice in the database.
216
+     *
217
+     * @param WPInv_Invoice $invoice Invoice object.
218
+     */
219
+    public function update( &$invoice ) {
220
+        $invoice->save_meta_data();
221
+        $invoice->set_version( WPINV_VERSION );
222
+
223
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
224
+            $invoice->set_date_created(  current_time('mysql') );
225
+        }
226
+
227
+        // Ensure both the key and number are set.
228
+        $invoice->get_path();
229
+
230
+        // Grab the current status so we can compare.
231
+        $previous_status = get_post_status( $invoice->get_id() );
232
+
233
+        $changes = $invoice->get_changes();
234
+
235
+        // Only update the post when the post data changes.
236
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
237
+            $post_data = array(
238
+                'post_date'         => $invoice->get_date_created( 'edit' ),
239
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
240
+                'post_status'       => $invoice->get_status( 'edit' ),
241
+                'post_title'        => $invoice->get_name( 'edit' ),
242
+                'post_author'       => $invoice->get_user_id( 'edit' ),
243
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
244
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
245
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
246
+                'post_name'         => $invoice->get_path( 'edit' ),
247
+                'post_type'         => $invoice->get_post_type( 'edit' ),
248
+            );
249
+
250
+            /**
251
+             * When updating this object, to prevent infinite loops, use $wpdb
252
+             * to update data, since wp_update_post spawns more calls to the
253
+             * save_post action.
254
+             *
255
+             * This ensures hooks are fired by either WP itself (admin screen save),
256
+             * or an update purely from CRUD.
257
+             */
258
+            if ( doing_action( 'save_post' ) ) {
259
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
260
+                clean_post_cache( $invoice->get_id() );
261
+            } else {
262
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
263
+            }
264
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
265
+        }
266
+
267
+        // Update meta data.
268
+        $this->update_post_meta( $invoice );
269
+
270
+        // Save special fields and items.
271
+        $this->save_special_fields( $invoice );
272
+        $this->save_items( $invoice );
273
+
274
+        // Apply the changes.
275
+        $invoice->apply_changes();
276
+
277
+        // Clear caches.
278
+        $this->clear_caches( $invoice );
279
+
280
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
281
+        $new_status = $invoice->get_status( 'edit' );
282
+
283
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
284
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
285
+        } else {
286
+            do_action( 'getpaid_update_' . $invoice->get_type(), $invoice );
287
+        }
288
+
289
+    }
290
+
291
+    /*
292 292
 	|--------------------------------------------------------------------------
293 293
 	| Additional Methods
294 294
 	|--------------------------------------------------------------------------
295 295
 	*/
296 296
 
297
-	/**
297
+    /**
298 298
      * Retrieves special fields and adds to the invoice.
299
-	 *
300
-	 * @param WPInv_Invoice $invoice Invoice object.
299
+     *
300
+     * @param WPInv_Invoice $invoice Invoice object.
301 301
      */
302 302
     public function add_special_fields( &$invoice ) {
303
-		global $wpdb;
303
+        global $wpdb;
304 304
 
305
-		// Maybe retrieve from the cache.
306
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
305
+        // Maybe retrieve from the cache.
306
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
307 307
 
308
-		// If not found, retrieve from the db.
309
-		if ( false === $data ) {
310
-			$table =  $wpdb->prefix . 'getpaid_invoices';
308
+        // If not found, retrieve from the db.
309
+        if ( false === $data ) {
310
+            $table =  $wpdb->prefix . 'getpaid_invoices';
311 311
 
312
-			$data  = $wpdb->get_row(
313
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
314
-				ARRAY_A
315
-			);
312
+            $data  = $wpdb->get_row(
313
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
314
+                ARRAY_A
315
+            );
316 316
 
317
-			// Update the cache with our data
318
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
317
+            // Update the cache with our data
318
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
319 319
 
320
-		}
320
+        }
321 321
 
322
-		// Abort if the data does not exist.
323
-		if ( empty( $data ) ) {
324
-			$invoice->set_object_read( true );
325
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
326
-			return;
327
-		}
322
+        // Abort if the data does not exist.
323
+        if ( empty( $data ) ) {
324
+            $invoice->set_object_read( true );
325
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
326
+            return;
327
+        }
328 328
 
329
-		$props = array();
329
+        $props = array();
330 330
 
331
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
331
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
332 332
 			
333
-			if ( $db_field == 'post_id' ) {
334
-				continue;
335
-			}
336
-
337
-			$props[ $prop ] = $data[ $db_field ];
338
-		}
339
-
340
-		$invoice->set_props( $props );
341
-
342
-	}
343
-
344
-	/**
345
-	 * Gets a list of special fields that need updated based on change state
346
-	 * or if they are present in the database or not.
347
-	 *
348
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
349
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
350
-	 */
351
-	protected function get_special_fields_to_update( $invoice ) {
352
-		$fields_to_update = array();
353
-		$changed_props   = $invoice->get_changes();
354
-
355
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
356
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
357
-			if ( array_key_exists( $prop, $changed_props ) ) {
358
-				$fields_to_update[ $database_field ] = $prop;
359
-			}
360
-		}
361
-
362
-		return $fields_to_update;
363
-	}
364
-
365
-	/**
366
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
367
-	 *
368
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
369
-	 * @since 1.0.19
370
-	 */
371
-	protected function update_special_fields( &$invoice ) {
372
-		global $wpdb;
373
-
374
-		$updated_props    = array();
375
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
376
-
377
-		foreach ( $fields_to_update as $database_field => $prop ) {
378
-			$value = $invoice->{"get_$prop"}( 'edit' );
379
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
380
-			$value = is_bool( $value ) ? ( int ) $value : $value;
381
-			$updated_props[ $database_field ] = maybe_serialize( $value );
382
-		}
383
-
384
-		if ( ! empty( $updated_props ) ) {
385
-
386
-			$table = $wpdb->prefix . 'getpaid_invoices';
387
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
388
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
389
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
390
-
391
-		}
392
-
393
-	}
394
-
395
-	/**
396
-	 * Helper method that inserts special fields to the database.
397
-	 *
398
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
399
-	 * @since 1.0.19
400
-	 */
401
-	protected function insert_special_fields( &$invoice ) {
402
-		global $wpdb;
403
-
404
-		$updated_props   = array();
405
-
406
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
407
-			$value = $invoice->{"get_$prop"}( 'edit' );
408
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
409
-			$value = is_bool( $value ) ? ( int ) $value : $value;
410
-			$updated_props[ $database_field ] = maybe_serialize( $value );
411
-		}
412
-
413
-		$table = $wpdb->prefix . 'getpaid_invoices';
414
-		$wpdb->insert( $table, $updated_props );
415
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
416
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
417
-
418
-	}
419
-
420
-	/**
333
+            if ( $db_field == 'post_id' ) {
334
+                continue;
335
+            }
336
+
337
+            $props[ $prop ] = $data[ $db_field ];
338
+        }
339
+
340
+        $invoice->set_props( $props );
341
+
342
+    }
343
+
344
+    /**
345
+     * Gets a list of special fields that need updated based on change state
346
+     * or if they are present in the database or not.
347
+     *
348
+     * @param  WPInv_Invoice $invoice       The Invoice object.
349
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
350
+     */
351
+    protected function get_special_fields_to_update( $invoice ) {
352
+        $fields_to_update = array();
353
+        $changed_props   = $invoice->get_changes();
354
+
355
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
356
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
357
+            if ( array_key_exists( $prop, $changed_props ) ) {
358
+                $fields_to_update[ $database_field ] = $prop;
359
+            }
360
+        }
361
+
362
+        return $fields_to_update;
363
+    }
364
+
365
+    /**
366
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
367
+     *
368
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
369
+     * @since 1.0.19
370
+     */
371
+    protected function update_special_fields( &$invoice ) {
372
+        global $wpdb;
373
+
374
+        $updated_props    = array();
375
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
376
+
377
+        foreach ( $fields_to_update as $database_field => $prop ) {
378
+            $value = $invoice->{"get_$prop"}( 'edit' );
379
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
380
+            $value = is_bool( $value ) ? ( int ) $value : $value;
381
+            $updated_props[ $database_field ] = maybe_serialize( $value );
382
+        }
383
+
384
+        if ( ! empty( $updated_props ) ) {
385
+
386
+            $table = $wpdb->prefix . 'getpaid_invoices';
387
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
388
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
389
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
390
+
391
+        }
392
+
393
+    }
394
+
395
+    /**
396
+     * Helper method that inserts special fields to the database.
397
+     *
398
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
399
+     * @since 1.0.19
400
+     */
401
+    protected function insert_special_fields( &$invoice ) {
402
+        global $wpdb;
403
+
404
+        $updated_props   = array();
405
+
406
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
407
+            $value = $invoice->{"get_$prop"}( 'edit' );
408
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
409
+            $value = is_bool( $value ) ? ( int ) $value : $value;
410
+            $updated_props[ $database_field ] = maybe_serialize( $value );
411
+        }
412
+
413
+        $table = $wpdb->prefix . 'getpaid_invoices';
414
+        $wpdb->insert( $table, $updated_props );
415
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
416
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
417
+
418
+    }
419
+
420
+    /**
421 421
      * Saves all special fields.
422
-	 *
423
-	 * @param WPInv_Invoice $invoice Invoice object.
422
+     *
423
+     * @param WPInv_Invoice $invoice Invoice object.
424 424
      */
425 425
     public function save_special_fields( & $invoice ) {
426
-		global $wpdb;
426
+        global $wpdb;
427 427
 
428
-		// The invoices table.
429
-		$table = $wpdb->prefix . 'getpaid_invoices';
430
-		$id    = (int) $invoice->get_id();
431
-		$invoice->maybe_set_key();
428
+        // The invoices table.
429
+        $table = $wpdb->prefix . 'getpaid_invoices';
430
+        $id    = (int) $invoice->get_id();
431
+        $invoice->maybe_set_key();
432 432
 
433
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
433
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
434 434
 
435
-			$this->update_special_fields( $invoice );
435
+            $this->update_special_fields( $invoice );
436 436
 
437
-		} else {
437
+        } else {
438 438
 
439
-			$this->insert_special_fields( $invoice );
439
+            $this->insert_special_fields( $invoice );
440 440
 
441
-		}
441
+        }
442 442
 
443
-	}
443
+    }
444 444
 
445
-	/**
445
+    /**
446 446
      * Set's up cart details.
447
-	 *
448
-	 * @param WPInv_Invoice $invoice Invoice object.
447
+     *
448
+     * @param WPInv_Invoice $invoice Invoice object.
449 449
      */
450 450
     public function add_items( &$invoice ) {
451
-		global $wpdb;
451
+        global $wpdb;
452 452
 
453
-		// Maybe retrieve from the cache.
454
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
453
+        // Maybe retrieve from the cache.
454
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
455 455
 
456
-		// If not found, retrieve from the db.
457
-		if ( false === $items ) {
458
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
456
+        // If not found, retrieve from the db.
457
+        if ( false === $items ) {
458
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
459 459
 
460
-			$items = $wpdb->get_results(
461
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
462
-			);
460
+            $items = $wpdb->get_results(
461
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
462
+            );
463 463
 
464
-			// Update the cache with our data
465
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
464
+            // Update the cache with our data
465
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
466 466
 
467
-		}
467
+        }
468 468
 
469
-		// Abort if no items found.
469
+        // Abort if no items found.
470 470
         if ( empty( $items ) ) {
471 471
             return;
472
-		}
472
+        }
473 473
 
474
-		foreach ( $items as $item_data ) {
475
-			$item = new GetPaid_Form_Item( $item_data->item_id );
474
+        foreach ( $items as $item_data ) {
475
+            $item = new GetPaid_Form_Item( $item_data->item_id );
476 476
 
477
-			// Set item data.
478
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
479
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
480
-			$item->set_name( $item_data->item_name );
481
-			$item->set_description( $item_data->item_description );
482
-			$item->set_price( $item_data->item_price );
483
-			$item->set_quantity( $item_data->quantity );
484
-			$item->set_item_meta( $item_data->meta );
477
+            // Set item data.
478
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
479
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
480
+            $item->set_name( $item_data->item_name );
481
+            $item->set_description( $item_data->item_description );
482
+            $item->set_price( $item_data->item_price );
483
+            $item->set_quantity( $item_data->quantity );
484
+            $item->set_item_meta( $item_data->meta );
485 485
 
486
-			$invoice->add_item( $item );
487
-		}
486
+            $invoice->add_item( $item );
487
+        }
488 488
 
489
-	}
489
+    }
490 490
 
491
-	/**
491
+    /**
492 492
      * Saves cart details.
493
-	 *
494
-	 * @param WPInv_Invoice $invoice Invoice object.
493
+     *
494
+     * @param WPInv_Invoice $invoice Invoice object.
495 495
      */
496 496
     public function save_items( $invoice ) {
497 497
 
498
-		// Delete previously existing items.
499
-		$this->delete_items( $invoice );
498
+        // Delete previously existing items.
499
+        $this->delete_items( $invoice );
500 500
 
501
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
501
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
502 502
 
503
-		foreach ( $invoice->get_cart_details() as $item_data ) {
504
-			$item_data = array_map( 'maybe_serialize', $item_data );
505
-			$GLOBALS['wpdb']->insert( $table, $item_data );
506
-		}
503
+        foreach ( $invoice->get_cart_details() as $item_data ) {
504
+            $item_data = array_map( 'maybe_serialize', $item_data );
505
+            $GLOBALS['wpdb']->insert( $table, $item_data );
506
+        }
507 507
 
508
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
509
-		do_action( "getpaid_invoice_save_items", $invoice );
508
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
509
+        do_action( "getpaid_invoice_save_items", $invoice );
510 510
 
511
-	}
511
+    }
512 512
 
513
-	/**
513
+    /**
514 514
      * Deletes an invoice's cart details from the database.
515
-	 *
516
-	 * @param WPInv_Invoice $invoice Invoice object.
515
+     *
516
+     * @param WPInv_Invoice $invoice Invoice object.
517 517
      */
518 518
     public function delete_items( $invoice ) {
519
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
520
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
521
-	}
519
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
520
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
521
+    }
522 522
 
523
-	/**
523
+    /**
524 524
      * Deletes an invoice's special fields from the database.
525
-	 *
526
-	 * @param WPInv_Invoice $invoice Invoice object.
525
+     *
526
+     * @param WPInv_Invoice $invoice Invoice object.
527 527
      */
528 528
     public function delete_special_fields( $invoice ) {
529
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
530
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
529
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
530
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
531 531
     }
532 532
 
533 533
 }
Please login to merge, or discard this patch.