@@ -11,55 +11,55 @@ discard block |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | 16 | // Update tables. |
17 | - if ( ! get_option( 'getpaid_created_invoice_tables' ) ) { |
|
17 | + if (!get_option('getpaid_created_invoice_tables')) { |
|
18 | 18 | wpinv_v119_upgrades(); |
19 | - update_option( 'getpaid_created_invoice_tables', true ); |
|
19 | + update_option('getpaid_created_invoice_tables', true); |
|
20 | 20 | } |
21 | 21 | |
22 | - if ( $wpi_version == WPINV_VERSION ) { |
|
22 | + if ($wpi_version == WPINV_VERSION) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 | |
26 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
26 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
27 | 27 | wpinv_v005_upgrades(); |
28 | 28 | } |
29 | 29 | |
30 | - if ( version_compare( $wpi_version, '1.0.3', '<' ) ) { |
|
30 | + if (version_compare($wpi_version, '1.0.3', '<')) { |
|
31 | 31 | wpinv_v110_upgrades(); |
32 | 32 | } |
33 | 33 | |
34 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
34 | + update_option('wpinv_version', WPINV_VERSION); |
|
35 | 35 | } |
36 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
36 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
37 | 37 | |
38 | 38 | function wpinv_v005_upgrades() { |
39 | 39 | global $wpdb; |
40 | 40 | |
41 | 41 | // Invoices status |
42 | - $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
43 | - if ( !empty( $results ) ) { |
|
44 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
42 | + $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
43 | + if (!empty($results)) { |
|
44 | + $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
45 | 45 | |
46 | 46 | // Clean post cache |
47 | - foreach ( $results as $row ) { |
|
48 | - clean_post_cache( $row->ID ); |
|
47 | + foreach ($results as $row) { |
|
48 | + clean_post_cache($row->ID); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Item meta key changes |
53 | 53 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
54 | - $results = $wpdb->get_results( $query ); |
|
54 | + $results = $wpdb->get_results($query); |
|
55 | 55 | |
56 | - if ( !empty( $results ) ) { |
|
57 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
58 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
59 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
56 | + if (!empty($results)) { |
|
57 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
58 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
59 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
60 | 60 | |
61 | - foreach ( $results as $row ) { |
|
62 | - clean_post_cache( $row->post_id ); |
|
61 | + foreach ($results as $row) { |
|
62 | + clean_post_cache($row->post_id); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -80,79 +80,79 @@ discard block |
||
80 | 80 | function wpinv_convert_old_subscriptions() { |
81 | 81 | global $wpdb; |
82 | 82 | |
83 | - $query = "SELECT ". $wpdb->posts .".ID FROM ". $wpdb->posts ." INNER JOIN ". $wpdb->postmeta ." ON ( ". $wpdb->posts .".ID = ". $wpdb->postmeta .".post_id ) WHERE 1=1 AND ". $wpdb->postmeta .".meta_key = '_wpinv_subscr_status' AND (". $wpdb->postmeta .".meta_value = 'pending' OR ". $wpdb->postmeta .".meta_value = 'active' OR ". $wpdb->postmeta .".meta_value = 'cancelled' OR ". $wpdb->postmeta .".meta_value = 'completed' OR ". $wpdb->postmeta .".meta_value = 'expired' OR ". $wpdb->postmeta .".meta_value = 'trialling' OR ". $wpdb->postmeta .".meta_value = 'failing') AND ". $wpdb->posts .".post_type = 'wpi_invoice' GROUP BY ". $wpdb->posts .".ID ORDER BY ". $wpdb->posts .".ID ASC"; |
|
83 | + $query = "SELECT " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON ( " . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id ) WHERE 1=1 AND " . $wpdb->postmeta . ".meta_key = '_wpinv_subscr_status' AND (" . $wpdb->postmeta . ".meta_value = 'pending' OR " . $wpdb->postmeta . ".meta_value = 'active' OR " . $wpdb->postmeta . ".meta_value = 'cancelled' OR " . $wpdb->postmeta . ".meta_value = 'completed' OR " . $wpdb->postmeta . ".meta_value = 'expired' OR " . $wpdb->postmeta . ".meta_value = 'trialling' OR " . $wpdb->postmeta . ".meta_value = 'failing') AND " . $wpdb->posts . ".post_type = 'wpi_invoice' GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC"; |
|
84 | 84 | |
85 | - $results = $wpdb->get_results( $query ); |
|
85 | + $results = $wpdb->get_results($query); |
|
86 | 86 | |
87 | - if ( empty( $results ) ) { |
|
87 | + if (empty($results)) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | - foreach ( $results as $row ) { |
|
92 | - $invoice = new WPInv_Invoice( $row->ID ); |
|
91 | + foreach ($results as $row) { |
|
92 | + $invoice = new WPInv_Invoice($row->ID); |
|
93 | 93 | |
94 | - if ( empty( $invoice->ID ) ) { |
|
94 | + if (empty($invoice->ID)) { |
|
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - if ( $invoice->has_status( 'wpi-renewal' ) ) { |
|
98 | + if ($invoice->has_status('wpi-renewal')) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | - $item = $invoice->get_recurring( true ); |
|
102 | + $item = $invoice->get_recurring(true); |
|
103 | 103 | |
104 | - if ( empty( $item ) ) { |
|
104 | + if (empty($item)) { |
|
105 | 105 | continue; |
106 | 106 | } |
107 | 107 | |
108 | 108 | $is_free_trial = $invoice->is_free_trial(); |
109 | - $profile_id = get_post_meta( $invoice->ID, '_wpinv_subscr_profile_id', true ); |
|
110 | - $subscription_status = get_post_meta( $invoice->ID, '_wpinv_subscr_status', true ); |
|
109 | + $profile_id = get_post_meta($invoice->ID, '_wpinv_subscr_profile_id', true); |
|
110 | + $subscription_status = get_post_meta($invoice->ID, '_wpinv_subscr_status', true); |
|
111 | 111 | $transaction_id = $invoice->get_transaction_id(); |
112 | 112 | |
113 | 113 | // Last invoice |
114 | - $query = "SELECT ID, post_date FROM ". $wpdb->posts ." WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
115 | - $last_payment = $wpdb->get_row( $query ); |
|
114 | + $query = "SELECT ID, post_date FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
115 | + $last_payment = $wpdb->get_row($query); |
|
116 | 116 | |
117 | - if ( !empty( $last_payment ) ) { |
|
118 | - $invoice_date = $last_payment->post_date; |
|
117 | + if (!empty($last_payment)) { |
|
118 | + $invoice_date = $last_payment->post_date; |
|
119 | 119 | |
120 | - $meta_profile_id = get_post_meta( $last_payment->ID, '_wpinv_subscr_profile_id', true ); |
|
121 | - $meta_transaction_id = get_post_meta( $last_payment->ID, '_wpinv_transaction_id', true ); |
|
120 | + $meta_profile_id = get_post_meta($last_payment->ID, '_wpinv_subscr_profile_id', true); |
|
121 | + $meta_transaction_id = get_post_meta($last_payment->ID, '_wpinv_transaction_id', true); |
|
122 | 122 | |
123 | - if ( !empty( $meta_profile_id ) ) { |
|
124 | - $profile_id = $meta_profile_id; |
|
123 | + if (!empty($meta_profile_id)) { |
|
124 | + $profile_id = $meta_profile_id; |
|
125 | 125 | } |
126 | 126 | |
127 | - if ( !empty( $meta_transaction_id ) ) { |
|
128 | - $transaction_id = $meta_transaction_id; |
|
127 | + if (!empty($meta_transaction_id)) { |
|
128 | + $transaction_id = $meta_transaction_id; |
|
129 | 129 | } |
130 | 130 | } else { |
131 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
131 | + $invoice_date = $invoice->get_invoice_date(false); |
|
132 | 132 | } |
133 | 133 | |
134 | - $profile_id = empty( $profile_id ) ? $invoice->ID : $profile_id; |
|
135 | - $status = empty( $subscription_status ) ? 'pending' : $subscription_status; |
|
134 | + $profile_id = empty($profile_id) ? $invoice->ID : $profile_id; |
|
135 | + $status = empty($subscription_status) ? 'pending' : $subscription_status; |
|
136 | 136 | |
137 | - $period = $item->get_recurring_period( true ); |
|
137 | + $period = $item->get_recurring_period(true); |
|
138 | 138 | $interval = $item->get_recurring_interval(); |
139 | - $bill_times = (int)$item->get_recurring_limit(); |
|
139 | + $bill_times = (int) $item->get_recurring_limit(); |
|
140 | 140 | $add_period = $interval . ' ' . $period; |
141 | 141 | $trial_period = ''; |
142 | 142 | |
143 | - if ( $invoice->is_free_trial() ) { |
|
144 | - $trial_period = $item->get_trial_period( true ); |
|
143 | + if ($invoice->is_free_trial()) { |
|
144 | + $trial_period = $item->get_trial_period(true); |
|
145 | 145 | $free_interval = $item->get_trial_interval(); |
146 | 146 | $trial_period = $free_interval . ' ' . $trial_period; |
147 | 147 | |
148 | - if ( empty( $last_payment ) ) { |
|
148 | + if (empty($last_payment)) { |
|
149 | 149 | $add_period = $trial_period; |
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
153 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
154 | - if ( strtotime( $expiration ) < strtotime( date_i18n( 'Y-m-d' ) ) ) { |
|
155 | - if ( $status == 'active' || $status == 'trialling' || $status == 'pending' ) { |
|
153 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
154 | + if (strtotime($expiration) < strtotime(date_i18n('Y-m-d'))) { |
|
155 | + if ($status == 'active' || $status == 'trialling' || $status == 'pending') { |
|
156 | 156 | $status = 'expired'; |
157 | 157 | } |
158 | 158 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | 'frequency' => $interval, |
166 | 166 | 'period' => $period, |
167 | 167 | 'initial_amount' => $invoice->get_total(), |
168 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
168 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
169 | 169 | 'bill_times' => $bill_times, |
170 | 170 | 'created' => $invoice_date, |
171 | 171 | 'expiration' => $expiration, |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | ); |
176 | 176 | |
177 | 177 | $subs_db = new WPInv_Subscriptions_DB; |
178 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) ); |
|
179 | - $subscription = reset( $subs ); |
|
178 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1)); |
|
179 | + $subscription = reset($subs); |
|
180 | 180 | |
181 | - if ( empty( $subscription ) || $subscription->id <= 0 ) { |
|
181 | + if (empty($subscription) || $subscription->id <= 0) { |
|
182 | 182 | $subscription = new WPInv_Subscription(); |
183 | - $new_sub = $subscription->create( $args ); |
|
183 | + $new_sub = $subscription->create($args); |
|
184 | 184 | |
185 | - if ( !empty( $bill_times ) && $new_sub->get_times_billed() >= $bill_times && ( 'active' == $new_sub->status || 'trialling' == $new_sub->status ) ) { |
|
185 | + if (!empty($bill_times) && $new_sub->get_times_billed() >= $bill_times && ('active' == $new_sub->status || 'trialling' == $new_sub->status)) { |
|
186 | 186 | $new_sub->complete(); // Mark completed if all times billed |
187 | 187 | } |
188 | 188 | } |
@@ -192,20 +192,20 @@ discard block |
||
192 | 192 | function wpinv_update_new_email_settings() { |
193 | 193 | global $wpinv_options; |
194 | 194 | |
195 | - $current_options = get_option( 'wpinv_settings', array() ); |
|
195 | + $current_options = get_option('wpinv_settings', array()); |
|
196 | 196 | $options = array( |
197 | - 'email_new_invoice_body' => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ), |
|
198 | - 'email_cancelled_invoice_body' => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ), |
|
199 | - 'email_failed_invoice_body' => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ), |
|
200 | - 'email_onhold_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ), |
|
201 | - 'email_processing_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ), |
|
202 | - 'email_refunded_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ), |
|
203 | - 'email_user_invoice_body' => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
204 | - 'email_user_note_body' => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ), |
|
205 | - 'email_overdue_body' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
197 | + 'email_new_invoice_body' => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'), |
|
198 | + 'email_cancelled_invoice_body' => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'), |
|
199 | + 'email_failed_invoice_body' => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'), |
|
200 | + 'email_onhold_invoice_body' => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'), |
|
201 | + 'email_processing_invoice_body' => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'), |
|
202 | + 'email_refunded_invoice_body' => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'), |
|
203 | + 'email_user_invoice_body' => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
204 | + 'email_user_note_body' => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'), |
|
205 | + 'email_overdue_body' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
206 | 206 | ); |
207 | 207 | |
208 | - foreach ($options as $option => $value){ |
|
208 | + foreach ($options as $option => $value) { |
|
209 | 209 | if (!isset($current_options[$option])) { |
210 | 210 | $current_options[$option] = $value; |
211 | 211 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | |
214 | 214 | $wpinv_options = $current_options; |
215 | 215 | |
216 | - update_option( 'wpinv_settings', $current_options ); |
|
216 | + update_option('wpinv_settings', $current_options); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | function wpinv_create_invoices_table() { |
231 | 231 | global $wpdb; |
232 | 232 | |
233 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
233 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
234 | 234 | |
235 | 235 | // Create invoices table. |
236 | 236 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | KEY `key` ( `key` ) |
275 | 275 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
276 | 276 | |
277 | - dbDelta( $sql ); |
|
277 | + dbDelta($sql); |
|
278 | 278 | |
279 | 279 | // Create invoice items table. |
280 | 280 | $table = $wpdb->prefix . 'getpaid_invoice_items'; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | KEY post_id ( post_id ) |
303 | 303 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
304 | 304 | |
305 | - dbDelta( $sql ); |
|
305 | + dbDelta($sql); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -314,29 +314,29 @@ discard block |
||
314 | 314 | $invoices = array_unique( |
315 | 315 | get_posts( |
316 | 316 | array( |
317 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
317 | + 'post_type' => array('wpi_invoice', 'wpi_quote'), |
|
318 | 318 | 'posts_per_page' => -1, |
319 | 319 | 'fields' => 'ids', |
320 | - 'post_status' => array_keys( wpinv_get_invoice_statuses( true ) ), |
|
320 | + 'post_status' => array_keys(wpinv_get_invoice_statuses(true)), |
|
321 | 321 | ) |
322 | 322 | ) |
323 | 323 | ); |
324 | 324 | $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
325 | 325 | $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
326 | 326 | |
327 | - if ( ! class_exists( 'WPInv_Legacy_Invoice' ) ) { |
|
328 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
327 | + if (!class_exists('WPInv_Legacy_Invoice')) { |
|
328 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | $invoice_rows = array(); |
332 | - foreach ( $invoices as $invoice ) { |
|
332 | + foreach ($invoices as $invoice) { |
|
333 | 333 | |
334 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
335 | - $fields = array ( |
|
334 | + $invoice = new WPInv_Legacy_Invoice($invoice); |
|
335 | + $fields = array( |
|
336 | 336 | 'post_id' => $invoice->ID, |
337 | 337 | 'number' => $invoice->get_number(), |
338 | 338 | 'key' => $invoice->get_key(), |
339 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
339 | + 'type' => str_replace('wpi_', '', $invoice->post_type), |
|
340 | 340 | 'mode' => $invoice->mode, |
341 | 341 | 'user_ip' => $invoice->get_ip(), |
342 | 342 | 'first_name' => $invoice->get_first_name(), |
@@ -365,27 +365,27 @@ discard block |
||
365 | 365 | 'custom_meta' => $invoice->payment_meta |
366 | 366 | ); |
367 | 367 | |
368 | - foreach ( $fields as $key => $val ) { |
|
369 | - if ( is_null( $val ) ) { |
|
368 | + foreach ($fields as $key => $val) { |
|
369 | + if (is_null($val)) { |
|
370 | 370 | $val = ''; |
371 | 371 | } |
372 | - $val = maybe_serialize( $val ); |
|
373 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
372 | + $val = maybe_serialize($val); |
|
373 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
374 | 374 | } |
375 | 375 | |
376 | - $fields = implode( ', ', $fields ); |
|
376 | + $fields = implode(', ', $fields); |
|
377 | 377 | $invoice_rows[] = "($fields)"; |
378 | 378 | |
379 | 379 | $item_rows = array(); |
380 | 380 | $item_columns = array(); |
381 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
381 | + foreach ($invoice->get_cart_details() as $details) { |
|
382 | 382 | $fields = array( |
383 | 383 | 'post_id' => $invoice->ID, |
384 | 384 | 'item_id' => $details['id'], |
385 | 385 | 'item_name' => $details['name'], |
386 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
386 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
387 | 387 | 'vat_rate' => $details['vat_rate'], |
388 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
388 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
389 | 389 | 'tax' => $details['tax'], |
390 | 390 | 'item_price' => $details['item_price'], |
391 | 391 | 'custom_price' => $details['custom_price'], |
@@ -397,26 +397,26 @@ discard block |
||
397 | 397 | 'fees' => $details['fees'], |
398 | 398 | ); |
399 | 399 | |
400 | - $item_columns = array_keys ( $fields ); |
|
400 | + $item_columns = array_keys($fields); |
|
401 | 401 | |
402 | - foreach ( $fields as $key => $val ) { |
|
403 | - if ( is_null( $val ) ) { |
|
402 | + foreach ($fields as $key => $val) { |
|
403 | + if (is_null($val)) { |
|
404 | 404 | $val = ''; |
405 | 405 | } |
406 | - $val = maybe_serialize( $val ); |
|
407 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
406 | + $val = maybe_serialize($val); |
|
407 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
408 | 408 | } |
409 | 409 | |
410 | - $fields = implode( ', ', $fields ); |
|
410 | + $fields = implode(', ', $fields); |
|
411 | 411 | $item_rows[] = "($fields)"; |
412 | 412 | } |
413 | 413 | |
414 | - $item_rows = implode( ', ', $item_rows ); |
|
415 | - $item_columns = implode( ', ', $item_columns ); |
|
416 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
414 | + $item_rows = implode(', ', $item_rows); |
|
415 | + $item_columns = implode(', ', $item_columns); |
|
416 | + $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows"); |
|
417 | 417 | } |
418 | 418 | |
419 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
420 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
419 | + $invoice_rows = implode(', ', $invoice_rows); |
|
420 | + $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows"); |
|
421 | 421 | |
422 | 422 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -21,79 +21,79 @@ discard block |
||
21 | 21 | public function init() { |
22 | 22 | global $wp_filesystem; |
23 | 23 | |
24 | - if ( empty( $wp_filesystem ) ) { |
|
25 | - require_once( ABSPATH . '/wp-admin/includes/file.php' ); |
|
24 | + if (empty($wp_filesystem)) { |
|
25 | + require_once(ABSPATH . '/wp-admin/includes/file.php'); |
|
26 | 26 | WP_Filesystem(); |
27 | 27 | global $wp_filesystem; |
28 | 28 | } |
29 | 29 | $this->wp_filesystem = $wp_filesystem; |
30 | 30 | |
31 | 31 | $this->export_dir = $this->export_location(); |
32 | - $this->export_url = $this->export_location( true ); |
|
32 | + $this->export_url = $this->export_location(true); |
|
33 | 33 | $this->export = 'invoicing'; |
34 | 34 | $this->filetype = 'csv'; |
35 | 35 | $this->per_page = 20; |
36 | 36 | |
37 | - do_action( 'wpinv_class_reports_init', $this ); |
|
37 | + do_action('wpinv_class_reports_init', $this); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function includes() { |
41 | - do_action( 'wpinv_class_reports_includes', $this ); |
|
41 | + do_action('wpinv_class_reports_includes', $this); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function actions() { |
45 | - if ( is_admin() ) { |
|
46 | - add_action( 'admin_menu', array( $this, 'add_submenu' ), 20 ); |
|
47 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'reports' ) ); |
|
48 | - add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) ); |
|
49 | - add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) ); |
|
50 | - add_action( 'wp_ajax_wpinv_ajax_discount_use_export', array( $this, 'discount_use_export' ) ); |
|
45 | + if (is_admin()) { |
|
46 | + add_action('admin_menu', array($this, 'add_submenu'), 20); |
|
47 | + add_action('wpinv_reports_tab_reports', array($this, 'reports')); |
|
48 | + add_action('wpinv_reports_tab_export', array($this, 'export')); |
|
49 | + add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export')); |
|
50 | + add_action('wp_ajax_wpinv_ajax_discount_use_export', array($this, 'discount_use_export')); |
|
51 | 51 | |
52 | 52 | // Export Invoices. |
53 | - add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) ); |
|
54 | - add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) ); |
|
55 | - add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) ); |
|
56 | - add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) ); |
|
53 | + add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export')); |
|
54 | + add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns')); |
|
55 | + add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data')); |
|
56 | + add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status')); |
|
57 | 57 | |
58 | 58 | // Reports. |
59 | - add_action( 'wpinv_reports_view_earnings', array( $this, 'earnings_report' ) ); |
|
60 | - add_action( 'wpinv_reports_view_gateways', array( $this, 'gateways_report' ) ); |
|
61 | - add_action( 'wpinv_reports_view_items', array( $this, 'items_report' ) ); |
|
62 | - add_action( 'wpinv_reports_view_taxes', array( $this, 'tax_report' ) ); |
|
59 | + add_action('wpinv_reports_view_earnings', array($this, 'earnings_report')); |
|
60 | + add_action('wpinv_reports_view_gateways', array($this, 'gateways_report')); |
|
61 | + add_action('wpinv_reports_view_items', array($this, 'items_report')); |
|
62 | + add_action('wpinv_reports_view_taxes', array($this, 'tax_report')); |
|
63 | 63 | } |
64 | - do_action( 'wpinv_class_reports_actions', $this ); |
|
64 | + do_action('wpinv_class_reports_actions', $this); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function add_submenu() { |
68 | 68 | global $wpi_reports_page; |
69 | - $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), wpinv_get_capability(), 'wpinv-reports', array( $this, 'reports_page' ) ); |
|
69 | + $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), wpinv_get_capability(), 'wpinv-reports', array($this, 'reports_page')); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | public function reports_page() { |
73 | 73 | |
74 | - if ( !wp_script_is( 'postbox', 'enqueued' ) ) { |
|
75 | - wp_enqueue_script( 'postbox' ); |
|
74 | + if (!wp_script_is('postbox', 'enqueued')) { |
|
75 | + wp_enqueue_script('postbox'); |
|
76 | 76 | } |
77 | 77 | |
78 | - if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) { |
|
79 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
78 | + if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) { |
|
79 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
80 | 80 | } |
81 | 81 | |
82 | - $current_page = admin_url( 'admin.php?page=wpinv-reports' ); |
|
83 | - $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
82 | + $current_page = admin_url('admin.php?page=wpinv-reports'); |
|
83 | + $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports'; |
|
84 | 84 | ?> |
85 | 85 | <div class="wrap wpi-reports-wrap"> |
86 | - <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1> |
|
86 | + <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1> |
|
87 | 87 | <h2 class="nav-tab-wrapper wp-clearfix"> |
88 | - <a href="<?php echo add_query_arg( array( 'tab' => 'reports', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'reports' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Reports', 'invoicing' ); ?></a> |
|
89 | - <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a> |
|
90 | - <?php do_action( 'wpinv_reports_page_tabs' ); ;?> |
|
88 | + <a href="<?php echo add_query_arg(array('tab' => 'reports', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'reports' ? 'nav-tab-active' : ''; ?>"><?php _e('Reports', 'invoicing'); ?></a> |
|
89 | + <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a> |
|
90 | + <?php do_action('wpinv_reports_page_tabs'); ;?> |
|
91 | 91 | </h2> |
92 | - <div class="wpi-reports-content wpi-reports-<?php echo esc_attr( $active_tab ); ?>"> |
|
92 | + <div class="wpi-reports-content wpi-reports-<?php echo esc_attr($active_tab); ?>"> |
|
93 | 93 | <?php |
94 | - do_action( 'wpinv_reports_page_top' ); |
|
95 | - do_action( 'wpinv_reports_tab_' . $active_tab ); |
|
96 | - do_action( 'wpinv_reports_page_bottom' ); |
|
94 | + do_action('wpinv_reports_page_top'); |
|
95 | + do_action('wpinv_reports_tab_' . $active_tab); |
|
96 | + do_action('wpinv_reports_page_bottom'); |
|
97 | 97 | ?> |
98 | 98 | </div> |
99 | 99 | </div> |
@@ -106,139 +106,139 @@ discard block |
||
106 | 106 | public function reports() { |
107 | 107 | |
108 | 108 | $views = array( |
109 | - 'earnings' => __( 'Earnings', 'invoicing' ), |
|
110 | - 'items' => __( 'Items', 'invoicing' ), |
|
111 | - 'gateways' => __( 'Payment Methods', 'invoicing' ), |
|
112 | - 'taxes' => __( 'Taxes', 'invoicing' ), |
|
109 | + 'earnings' => __('Earnings', 'invoicing'), |
|
110 | + 'items' => __('Items', 'invoicing'), |
|
111 | + 'gateways' => __('Payment Methods', 'invoicing'), |
|
112 | + 'taxes' => __('Taxes', 'invoicing'), |
|
113 | 113 | ); |
114 | 114 | |
115 | - $views = apply_filters( 'wpinv_report_views', $views ); |
|
115 | + $views = apply_filters('wpinv_report_views', $views); |
|
116 | 116 | $current = 'earnings'; |
117 | 117 | |
118 | - if ( isset( $_GET['view'] ) && array_key_exists( $_GET['view'], $views ) ) |
|
118 | + if (isset($_GET['view']) && array_key_exists($_GET['view'], $views)) |
|
119 | 119 | $current = $_GET['view']; |
120 | 120 | |
121 | 121 | ?> |
122 | 122 | <form id="wpinv-reports-filter" method="get" class="tablenav"> |
123 | 123 | <select id="wpinv-reports-view" name="view"> |
124 | - <option value="-1" disabled><?php _e( 'Report Type', 'invoicing' ); ?></option> |
|
125 | - <?php foreach ( $views as $view_id => $label ) : ?> |
|
126 | - <option value="<?php echo esc_attr( $view_id ); ?>" <?php selected( $view_id, $current ); ?>><?php echo $label; ?></option> |
|
124 | + <option value="-1" disabled><?php _e('Report Type', 'invoicing'); ?></option> |
|
125 | + <?php foreach ($views as $view_id => $label) : ?> |
|
126 | + <option value="<?php echo esc_attr($view_id); ?>" <?php selected($view_id, $current); ?>><?php echo $label; ?></option> |
|
127 | 127 | <?php endforeach; ?> |
128 | 128 | </select> |
129 | 129 | |
130 | - <?php do_action( 'wpinv_report_view_actions' ); ?> |
|
130 | + <?php do_action('wpinv_report_view_actions'); ?> |
|
131 | 131 | |
132 | 132 | <input type="hidden" name="page" value="wpinv-reports"/> |
133 | - <?php submit_button( __( 'Show', 'invoicing' ), 'secondary', 'submit', false ); ?> |
|
133 | + <?php submit_button(__('Show', 'invoicing'), 'secondary', 'submit', false); ?> |
|
134 | 134 | </form> |
135 | 135 | <?php |
136 | 136 | |
137 | - do_action( 'wpinv_reports_view_' . $current ); |
|
137 | + do_action('wpinv_reports_view_' . $current); |
|
138 | 138 | |
139 | 139 | } |
140 | 140 | |
141 | 141 | public function export() { |
142 | - $statuses = wpinv_get_invoice_statuses( true ); |
|
143 | - $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses ); |
|
142 | + $statuses = wpinv_get_invoice_statuses(true); |
|
143 | + $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses); |
|
144 | 144 | ?> |
145 | 145 | <div class="metabox-holder"> |
146 | 146 | <div id="post-body"> |
147 | 147 | <div id="post-body-content"> |
148 | - <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?> |
|
148 | + <?php do_action('wpinv_reports_tab_export_content_top'); ?> |
|
149 | 149 | |
150 | 150 | <div class="postbox wpi-export-invoices"> |
151 | - <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2> |
|
151 | + <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2> |
|
152 | 152 | <div class="inside"> |
153 | - <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p> |
|
153 | + <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p> |
|
154 | 154 | <form id="wpi-export-invoices" class="wpi-export-form" method="post"> |
155 | - <?php echo wpinv_html_date_field( array( |
|
155 | + <?php echo wpinv_html_date_field(array( |
|
156 | 156 | 'id' => 'wpi_export_from_date', |
157 | 157 | 'name' => 'from_date', |
158 | 158 | 'data' => array( |
159 | 159 | 'dateFormat' => 'yy-mm-dd' |
160 | 160 | ), |
161 | - 'placeholder' => __( 'From date', 'invoicing' ) ) |
|
161 | + 'placeholder' => __('From date', 'invoicing') ) |
|
162 | 162 | ); ?> |
163 | - <?php echo wpinv_html_date_field( array( |
|
163 | + <?php echo wpinv_html_date_field(array( |
|
164 | 164 | 'id' => 'wpi_export_to_date', |
165 | 165 | 'name' => 'to_date', |
166 | 166 | 'data' => array( |
167 | 167 | 'dateFormat' => 'yy-mm-dd' |
168 | 168 | ), |
169 | - 'placeholder' => __( 'To date', 'invoicing' ) ) |
|
169 | + 'placeholder' => __('To date', 'invoicing') ) |
|
170 | 170 | ); ?> |
171 | 171 | <span id="wpinv-status-wrap"> |
172 | - <?php echo wpinv_html_select( array( |
|
172 | + <?php echo wpinv_html_select(array( |
|
173 | 173 | 'options' => $statuses, |
174 | 174 | 'name' => 'status', |
175 | 175 | 'id' => 'wpi_export_status', |
176 | 176 | 'show_option_all' => false, |
177 | 177 | 'show_option_none' => false, |
178 | 178 | 'class' => 'wpi_select2', |
179 | - ) ); ?> |
|
180 | - <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?> |
|
179 | + )); ?> |
|
180 | + <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?> |
|
181 | 181 | </span> |
182 | 182 | <span id="wpinv-submit-wrap"> |
183 | 183 | <input type="hidden" value="invoices" name="export" /> |
184 | - <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" /> |
|
184 | + <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" /> |
|
185 | 185 | </span> |
186 | 186 | </form> |
187 | 187 | </div> |
188 | 188 | </div> |
189 | 189 | |
190 | 190 | <div class="postbox wpi-export-discount-uses"> |
191 | - <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Discount Use','invoicing' ); ?></span></h2> |
|
191 | + <h2 class="hndle ui-sortabled-handle"><span><?php _e('Discount Use', 'invoicing'); ?></span></h2> |
|
192 | 192 | <div class="inside"> |
193 | - <p><?php _e( 'Download a CSV of discount uses.', 'invoicing' ); ?></p> |
|
194 | - <a class="button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-ajax.php?action=wpinv_ajax_discount_use_export' ), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export' ) ); ?>"><?php _e( 'Generate CSV', 'invoicing' ); ?></a> |
|
193 | + <p><?php _e('Download a CSV of discount uses.', 'invoicing'); ?></p> |
|
194 | + <a class="button-primary" href="<?php echo esc_url(wp_nonce_url(admin_url('admin-ajax.php?action=wpinv_ajax_discount_use_export'), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export')); ?>"><?php _e('Generate CSV', 'invoicing'); ?></a> |
|
195 | 195 | </div> |
196 | 196 | </div> |
197 | 197 | |
198 | - <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?> |
|
198 | + <?php do_action('wpinv_reports_tab_export_content_bottom'); ?> |
|
199 | 199 | </div> |
200 | 200 | </div> |
201 | 201 | </div> |
202 | 202 | <?php |
203 | 203 | } |
204 | 204 | |
205 | - public function export_location( $relative = false ) { |
|
205 | + public function export_location($relative = false) { |
|
206 | 206 | $upload_dir = wp_upload_dir(); |
207 | - $export_location = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache'; |
|
208 | - $export_location = apply_filters( 'wpinv_export_location', $export_location, $relative ); |
|
207 | + $export_location = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache'; |
|
208 | + $export_location = apply_filters('wpinv_export_location', $export_location, $relative); |
|
209 | 209 | |
210 | - return trailingslashit( $export_location ); |
|
210 | + return trailingslashit($export_location); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | public function check_export_location() { |
214 | 214 | try { |
215 | - if ( empty( $this->wp_filesystem ) ) { |
|
216 | - return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' ); |
|
215 | + if (empty($this->wp_filesystem)) { |
|
216 | + return __('Filesystem ERROR: Could not access filesystem.', 'invoicing'); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( is_wp_error( $this->wp_filesystem ) ) { |
|
220 | - return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' ); |
|
219 | + if (is_wp_error($this->wp_filesystem)) { |
|
220 | + return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing'); |
|
221 | 221 | } |
222 | 222 | |
223 | - $is_dir = $this->wp_filesystem->is_dir( $this->export_dir ); |
|
224 | - $is_writeable = $is_dir && is_writeable( $this->export_dir ); |
|
223 | + $is_dir = $this->wp_filesystem->is_dir($this->export_dir); |
|
224 | + $is_writeable = $is_dir && is_writeable($this->export_dir); |
|
225 | 225 | |
226 | - if ( $is_dir && $is_writeable ) { |
|
226 | + if ($is_dir && $is_writeable) { |
|
227 | 227 | return true; |
228 | - } else if ( $is_dir && !$is_writeable ) { |
|
229 | - if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
230 | - return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir ); |
|
228 | + } else if ($is_dir && !$is_writeable) { |
|
229 | + if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) { |
|
230 | + return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | return true; |
234 | 234 | } else { |
235 | - if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
236 | - return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir ); |
|
235 | + if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) { |
|
236 | + return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | return true; |
240 | 240 | } |
241 | - } catch ( Exception $e ) { |
|
241 | + } catch (Exception $e) { |
|
242 | 242 | return $e->getMessage(); |
243 | 243 | } |
244 | 244 | } |
@@ -246,59 +246,59 @@ discard block |
||
246 | 246 | public function ajax_export() { |
247 | 247 | $response = array(); |
248 | 248 | $response['success'] = false; |
249 | - $response['msg'] = __( 'Invalid export request found.', 'invoicing' ); |
|
249 | + $response['msg'] = __('Invalid export request found.', 'invoicing'); |
|
250 | 250 | |
251 | - if ( empty( $_POST['data'] ) || ! wpinv_current_user_can_manage_invoicing() ) { |
|
252 | - wp_send_json( $response ); |
|
251 | + if (empty($_POST['data']) || !wpinv_current_user_can_manage_invoicing()) { |
|
252 | + wp_send_json($response); |
|
253 | 253 | } |
254 | 254 | |
255 | - parse_str( $_POST['data'], $data ); |
|
255 | + parse_str($_POST['data'], $data); |
|
256 | 256 | |
257 | - $data['step'] = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; |
|
257 | + $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1; |
|
258 | 258 | |
259 | - $_REQUEST = (array)$data; |
|
260 | - if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) { |
|
261 | - $response['msg'] = __( 'Security check failed.', 'invoicing' ); |
|
262 | - wp_send_json( $response ); |
|
259 | + $_REQUEST = (array) $data; |
|
260 | + if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) { |
|
261 | + $response['msg'] = __('Security check failed.', 'invoicing'); |
|
262 | + wp_send_json($response); |
|
263 | 263 | } |
264 | 264 | |
265 | - if ( ( $error = $this->check_export_location( true ) ) !== true ) { |
|
266 | - $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' ); |
|
267 | - wp_send_json( $response ); |
|
265 | + if (($error = $this->check_export_location(true)) !== true) { |
|
266 | + $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing'); |
|
267 | + wp_send_json($response); |
|
268 | 268 | } |
269 | 269 | |
270 | - $this->set_export_params( $_REQUEST ); |
|
270 | + $this->set_export_params($_REQUEST); |
|
271 | 271 | |
272 | 272 | $return = $this->process_export_step(); |
273 | 273 | $done = $this->get_export_status(); |
274 | 274 | |
275 | - if ( $return ) { |
|
275 | + if ($return) { |
|
276 | 276 | $this->step += 1; |
277 | 277 | |
278 | 278 | $response['success'] = true; |
279 | 279 | $response['msg'] = ''; |
280 | 280 | |
281 | - if ( $done >= 100 ) { |
|
281 | + if ($done >= 100) { |
|
282 | 282 | $this->step = 'done'; |
283 | - $new_filename = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype; |
|
283 | + $new_filename = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype; |
|
284 | 284 | $new_file = $this->export_dir . $new_filename; |
285 | 285 | |
286 | - if ( file_exists( $this->file ) ) { |
|
287 | - $this->wp_filesystem->move( $this->file, $new_file, true ); |
|
286 | + if (file_exists($this->file)) { |
|
287 | + $this->wp_filesystem->move($this->file, $new_file, true); |
|
288 | 288 | } |
289 | 289 | |
290 | - if ( file_exists( $new_file ) ) { |
|
291 | - $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) ); |
|
290 | + if (file_exists($new_file)) { |
|
291 | + $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2)); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
295 | 295 | $response['data']['step'] = $this->step; |
296 | 296 | $response['data']['done'] = $done; |
297 | 297 | } else { |
298 | - $response['msg'] = __( 'No data found for export.', 'invoicing' ); |
|
298 | + $response['msg'] = __('No data found for export.', 'invoicing'); |
|
299 | 299 | } |
300 | 300 | |
301 | - wp_send_json( $response ); |
|
301 | + wp_send_json($response); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public function discount_use_export() { |
308 | 308 | |
309 | - if ( ! wp_verify_nonce( $_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export' ) || ! wpinv_current_user_can_manage_invoicing() ) { |
|
309 | + if (!wp_verify_nonce($_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export') || !wpinv_current_user_can_manage_invoicing()) { |
|
310 | 310 | wp_die( -1, 403 ); |
311 | 311 | } |
312 | 312 | |
@@ -316,115 +316,115 @@ discard block |
||
316 | 316 | 'posts_per_page' => -1, |
317 | 317 | ); |
318 | 318 | |
319 | - $discounts = get_posts( $args ); |
|
319 | + $discounts = get_posts($args); |
|
320 | 320 | |
321 | - if ( empty( $discounts ) ) { |
|
322 | - die ( __( 'You have not set up any discounts', 'invoicing' ) ); |
|
321 | + if (empty($discounts)) { |
|
322 | + die (__('You have not set up any discounts', 'invoicing')); |
|
323 | 323 | } |
324 | 324 | |
325 | - $output = fopen( 'php://output', 'w' ) or die( 'Unsupported server' ); |
|
325 | + $output = fopen('php://output', 'w') or die('Unsupported server'); |
|
326 | 326 | |
327 | 327 | // Let the browser know what content we're streaming and how it should save the content. |
328 | 328 | $name = time(); |
329 | - header( "Content-Type:application/csv" ); |
|
330 | - header( "Content-Disposition:attachment;filename=noptin-subscribers-$name.csv" ); |
|
329 | + header("Content-Type:application/csv"); |
|
330 | + header("Content-Disposition:attachment;filename=noptin-subscribers-$name.csv"); |
|
331 | 331 | |
332 | 332 | // Output the csv column headers. |
333 | 333 | fputcsv( |
334 | 334 | $output, |
335 | 335 | array( |
336 | - __( 'Discount Id', 'invoicing' ), |
|
337 | - __( 'Discount Code', 'invoicing' ), |
|
338 | - __( 'Discount Type', 'invoicing' ), |
|
339 | - __( 'Discount Amount', 'invoicing' ), |
|
340 | - __( 'Uses', 'invoicing' ), |
|
336 | + __('Discount Id', 'invoicing'), |
|
337 | + __('Discount Code', 'invoicing'), |
|
338 | + __('Discount Type', 'invoicing'), |
|
339 | + __('Discount Amount', 'invoicing'), |
|
340 | + __('Uses', 'invoicing'), |
|
341 | 341 | ) |
342 | 342 | ); |
343 | 343 | |
344 | - foreach ( $discounts as $discount ) { |
|
344 | + foreach ($discounts as $discount) { |
|
345 | 345 | |
346 | 346 | $discount = (int) $discount; |
347 | 347 | $row = array( |
348 | 348 | $discount, |
349 | - get_post_meta( $discount, '_wpi_discount_code', true ), |
|
350 | - get_post_meta( $discount, '_wpi_discount_type', true ), |
|
351 | - get_post_meta( $discount, '_wpi_discount_amount', true ), |
|
352 | - (int) get_post_meta( $discount, '_wpi_discount_uses', true ) |
|
349 | + get_post_meta($discount, '_wpi_discount_code', true), |
|
350 | + get_post_meta($discount, '_wpi_discount_type', true), |
|
351 | + get_post_meta($discount, '_wpi_discount_amount', true), |
|
352 | + (int) get_post_meta($discount, '_wpi_discount_uses', true) |
|
353 | 353 | ); |
354 | - fputcsv( $output, $row ); |
|
354 | + fputcsv($output, $row); |
|
355 | 355 | } |
356 | 356 | |
357 | - fclose( $output ); |
|
357 | + fclose($output); |
|
358 | 358 | exit; |
359 | 359 | |
360 | 360 | } |
361 | 361 | |
362 | - public function set_export_params( $request ) { |
|
362 | + public function set_export_params($request) { |
|
363 | 363 | $this->empty = false; |
364 | - $this->step = !empty( $request['step'] ) ? absint( $request['step'] ) : 1; |
|
365 | - $this->export = !empty( $request['export'] ) ? $request['export'] : $this->export; |
|
364 | + $this->step = !empty($request['step']) ? absint($request['step']) : 1; |
|
365 | + $this->export = !empty($request['export']) ? $request['export'] : $this->export; |
|
366 | 366 | $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype; |
367 | 367 | $this->file = $this->export_dir . $this->filename; |
368 | 368 | |
369 | - do_action( 'wpinv_export_set_params_' . $this->export, $request ); |
|
369 | + do_action('wpinv_export_set_params_' . $this->export, $request); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | public function get_columns() { |
373 | 373 | $columns = array(); |
374 | 374 | |
375 | - return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns ); |
|
375 | + return apply_filters('wpinv_export_get_columns_' . $this->export, $columns); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | protected function get_export_file() { |
379 | 379 | $file = ''; |
380 | 380 | |
381 | - if ( $this->wp_filesystem->exists( $this->file ) ) { |
|
382 | - $file = $this->wp_filesystem->get_contents( $this->file ); |
|
381 | + if ($this->wp_filesystem->exists($this->file)) { |
|
382 | + $file = $this->wp_filesystem->get_contents($this->file); |
|
383 | 383 | } else { |
384 | - $this->wp_filesystem->put_contents( $this->file, '' ); |
|
384 | + $this->wp_filesystem->put_contents($this->file, ''); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return $file; |
388 | 388 | } |
389 | 389 | |
390 | - protected function attach_export_data( $data = '' ) { |
|
391 | - $filedata = $this->get_export_file(); |
|
392 | - $filedata .= $data; |
|
390 | + protected function attach_export_data($data = '') { |
|
391 | + $filedata = $this->get_export_file(); |
|
392 | + $filedata .= $data; |
|
393 | 393 | |
394 | - $this->wp_filesystem->put_contents( $this->file, $filedata ); |
|
394 | + $this->wp_filesystem->put_contents($this->file, $filedata); |
|
395 | 395 | |
396 | - $rows = file( $this->file, FILE_SKIP_EMPTY_LINES ); |
|
396 | + $rows = file($this->file, FILE_SKIP_EMPTY_LINES); |
|
397 | 397 | $columns = $this->get_columns(); |
398 | - $columns = empty( $columns ) ? 0 : 1; |
|
398 | + $columns = empty($columns) ? 0 : 1; |
|
399 | 399 | |
400 | - $this->empty = count( $rows ) == $columns ? true : false; |
|
400 | + $this->empty = count($rows) == $columns ? true : false; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | public function print_columns() { |
404 | 404 | $column_data = ''; |
405 | 405 | $columns = $this->get_columns(); |
406 | 406 | $i = 1; |
407 | - foreach( $columns as $key => $column ) { |
|
408 | - $column_data .= '"' . addslashes( $column ) . '"'; |
|
409 | - $column_data .= $i == count( $columns ) ? '' : ','; |
|
407 | + foreach ($columns as $key => $column) { |
|
408 | + $column_data .= '"' . addslashes($column) . '"'; |
|
409 | + $column_data .= $i == count($columns) ? '' : ','; |
|
410 | 410 | $i++; |
411 | 411 | } |
412 | 412 | $column_data .= "\r\n"; |
413 | 413 | |
414 | - $this->attach_export_data( $column_data ); |
|
414 | + $this->attach_export_data($column_data); |
|
415 | 415 | |
416 | 416 | return $column_data; |
417 | 417 | } |
418 | 418 | |
419 | 419 | public function process_export_step() { |
420 | - if ( $this->step < 2 ) { |
|
421 | - /** @scrutinizer ignore-unhandled */ @unlink( $this->file ); |
|
420 | + if ($this->step < 2) { |
|
421 | + /** @scrutinizer ignore-unhandled */ @unlink($this->file); |
|
422 | 422 | $this->print_columns(); |
423 | 423 | } |
424 | 424 | |
425 | 425 | $return = $this->print_rows(); |
426 | 426 | |
427 | - if ( $return ) { |
|
427 | + if ($return) { |
|
428 | 428 | return true; |
429 | 429 | } else { |
430 | 430 | return false; |
@@ -433,14 +433,14 @@ discard block |
||
433 | 433 | |
434 | 434 | public function get_export_status() { |
435 | 435 | $status = 100; |
436 | - return apply_filters( 'wpinv_get_export_status_' . $this->export, $status ); |
|
436 | + return apply_filters('wpinv_get_export_status_' . $this->export, $status); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | public function get_export_data() { |
440 | 440 | $data = array(); |
441 | 441 | |
442 | - $data = apply_filters( 'wpinv_export_get_data', $data ); |
|
443 | - $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data ); |
|
442 | + $data = apply_filters('wpinv_export_get_data', $data); |
|
443 | + $data = apply_filters('wpinv_export_get_data_' . $this->export, $data); |
|
444 | 444 | |
445 | 445 | return $data; |
446 | 446 | } |
@@ -450,20 +450,20 @@ discard block |
||
450 | 450 | $data = $this->get_export_data(); |
451 | 451 | $columns = $this->get_columns(); |
452 | 452 | |
453 | - if ( $data ) { |
|
454 | - foreach ( $data as $row ) { |
|
453 | + if ($data) { |
|
454 | + foreach ($data as $row) { |
|
455 | 455 | $i = 1; |
456 | - foreach ( $row as $key => $column ) { |
|
457 | - if ( array_key_exists( $key, $columns ) ) { |
|
458 | - $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"'; |
|
459 | - $row_data .= $i == count( $columns ) ? '' : ','; |
|
456 | + foreach ($row as $key => $column) { |
|
457 | + if (array_key_exists($key, $columns)) { |
|
458 | + $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"'; |
|
459 | + $row_data .= $i == count($columns) ? '' : ','; |
|
460 | 460 | $i++; |
461 | 461 | } |
462 | 462 | } |
463 | 463 | $row_data .= "\r\n"; |
464 | 464 | } |
465 | 465 | |
466 | - $this->attach_export_data( $row_data ); |
|
466 | + $this->attach_export_data($row_data); |
|
467 | 467 | |
468 | 468 | return $row_data; |
469 | 469 | } |
@@ -472,48 +472,48 @@ discard block |
||
472 | 472 | } |
473 | 473 | |
474 | 474 | // Export Invoices. |
475 | - public function set_invoices_export( $request ) { |
|
476 | - $this->from_date = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : ''; |
|
477 | - $this->to_date = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : ''; |
|
478 | - $this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish'; |
|
475 | + public function set_invoices_export($request) { |
|
476 | + $this->from_date = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : ''; |
|
477 | + $this->to_date = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : ''; |
|
478 | + $this->status = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish'; |
|
479 | 479 | } |
480 | 480 | |
481 | - public function get_invoices_columns( $columns = array() ) { |
|
481 | + public function get_invoices_columns($columns = array()) { |
|
482 | 482 | $columns = array( |
483 | - 'id' => __( 'ID', 'invoicing' ), |
|
484 | - 'number' => __( 'Number', 'invoicing' ), |
|
485 | - 'date' => __( 'Date', 'invoicing' ), |
|
486 | - 'due_date' => __( 'Due Date', 'invoicing' ), |
|
487 | - 'completed_date'=> __( 'Payment Done Date', 'invoicing' ), |
|
488 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
489 | - 'currency' => __( 'Currency', 'invoicing' ), |
|
490 | - 'items' => __( 'Items', 'invoicing' ), |
|
491 | - 'status_nicename' => __( 'Status Nicename', 'invoicing' ), |
|
492 | - 'status' => __( 'Status', 'invoicing' ), |
|
493 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
494 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
495 | - 'user_id' => __( 'User ID', 'invoicing' ), |
|
496 | - 'email' => __( 'Email', 'invoicing' ), |
|
497 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
498 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
499 | - 'address' => __( 'Address', 'invoicing' ), |
|
500 | - 'city' => __( 'City', 'invoicing' ), |
|
501 | - 'state' => __( 'State', 'invoicing' ), |
|
502 | - 'country' => __( 'Country', 'invoicing' ), |
|
503 | - 'zip' => __( 'Zipcode', 'invoicing' ), |
|
504 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
505 | - 'company' => __( 'Company', 'invoicing' ), |
|
506 | - 'vat_number' => __( 'Vat Number', 'invoicing' ), |
|
507 | - 'ip' => __( 'IP', 'invoicing' ), |
|
508 | - 'gateway' => __( 'Gateway', 'invoicing' ), |
|
509 | - 'gateway_nicename' => __( 'Gateway Nicename', 'invoicing' ), |
|
510 | - 'transaction_id'=> __( 'Transaction ID', 'invoicing' ), |
|
483 | + 'id' => __('ID', 'invoicing'), |
|
484 | + 'number' => __('Number', 'invoicing'), |
|
485 | + 'date' => __('Date', 'invoicing'), |
|
486 | + 'due_date' => __('Due Date', 'invoicing'), |
|
487 | + 'completed_date'=> __('Payment Done Date', 'invoicing'), |
|
488 | + 'amount' => __('Amount', 'invoicing'), |
|
489 | + 'currency' => __('Currency', 'invoicing'), |
|
490 | + 'items' => __('Items', 'invoicing'), |
|
491 | + 'status_nicename' => __('Status Nicename', 'invoicing'), |
|
492 | + 'status' => __('Status', 'invoicing'), |
|
493 | + 'tax' => __('Tax', 'invoicing'), |
|
494 | + 'discount' => __('Discount', 'invoicing'), |
|
495 | + 'user_id' => __('User ID', 'invoicing'), |
|
496 | + 'email' => __('Email', 'invoicing'), |
|
497 | + 'first_name' => __('First Name', 'invoicing'), |
|
498 | + 'last_name' => __('Last Name', 'invoicing'), |
|
499 | + 'address' => __('Address', 'invoicing'), |
|
500 | + 'city' => __('City', 'invoicing'), |
|
501 | + 'state' => __('State', 'invoicing'), |
|
502 | + 'country' => __('Country', 'invoicing'), |
|
503 | + 'zip' => __('Zipcode', 'invoicing'), |
|
504 | + 'phone' => __('Phone', 'invoicing'), |
|
505 | + 'company' => __('Company', 'invoicing'), |
|
506 | + 'vat_number' => __('Vat Number', 'invoicing'), |
|
507 | + 'ip' => __('IP', 'invoicing'), |
|
508 | + 'gateway' => __('Gateway', 'invoicing'), |
|
509 | + 'gateway_nicename' => __('Gateway Nicename', 'invoicing'), |
|
510 | + 'transaction_id'=> __('Transaction ID', 'invoicing'), |
|
511 | 511 | ); |
512 | 512 | |
513 | 513 | return $columns; |
514 | 514 | } |
515 | 515 | |
516 | - public function get_invoices_data( $response = array() ) { |
|
516 | + public function get_invoices_data($response = array()) { |
|
517 | 517 | $args = array( |
518 | 518 | 'limit' => $this->per_page, |
519 | 519 | 'page' => $this->step, |
@@ -521,42 +521,42 @@ discard block |
||
521 | 521 | 'orderby' => 'date', |
522 | 522 | ); |
523 | 523 | |
524 | - if ( $this->status != 'any' ) { |
|
524 | + if ($this->status != 'any') { |
|
525 | 525 | $args['status'] = $this->status; |
526 | 526 | } else { |
527 | - $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
527 | + $args['status'] = array_keys(wpinv_get_invoice_statuses(true)); |
|
528 | 528 | } |
529 | 529 | |
530 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
530 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
531 | 531 | $args['date_query'] = array( |
532 | 532 | array( |
533 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
534 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
533 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
534 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
535 | 535 | 'inclusive' => true |
536 | 536 | ) |
537 | 537 | ); |
538 | 538 | } |
539 | 539 | |
540 | - $invoices = wpinv_get_invoices( $args ); |
|
540 | + $invoices = wpinv_get_invoices($args); |
|
541 | 541 | |
542 | 542 | $data = array(); |
543 | 543 | |
544 | - if ( !empty( $invoices ) ) { |
|
545 | - foreach ( $invoices as $invoice ) { |
|
544 | + if (!empty($invoices)) { |
|
545 | + foreach ($invoices as $invoice) { |
|
546 | 546 | $items = $this->get_invoice_items($invoice); |
547 | 547 | $row = array( |
548 | 548 | 'id' => $invoice->ID, |
549 | 549 | 'number' => $invoice->get_number(), |
550 | - 'date' => $invoice->get_invoice_date( false ), |
|
551 | - 'due_date' => $invoice->get_due_date( false ), |
|
550 | + 'date' => $invoice->get_invoice_date(false), |
|
551 | + 'due_date' => $invoice->get_due_date(false), |
|
552 | 552 | 'completed_date'=> $invoice->get_completed_date(), |
553 | - 'amount' => wpinv_round_amount( $invoice->get_total() ), |
|
553 | + 'amount' => wpinv_round_amount($invoice->get_total()), |
|
554 | 554 | 'currency' => $invoice->get_currency(), |
555 | 555 | 'items' => $items, |
556 | - 'status_nicename' => $invoice->get_status( true ), |
|
556 | + 'status_nicename' => $invoice->get_status(true), |
|
557 | 557 | 'status' => $invoice->get_status(), |
558 | - 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '', |
|
559 | - 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '', |
|
558 | + 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '', |
|
559 | + 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '', |
|
560 | 560 | 'user_id' => $invoice->get_user_id(), |
561 | 561 | 'email' => $invoice->get_email(), |
562 | 562 | 'first_name' => $invoice->get_first_name(), |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | 'transaction_id'=> $invoice->gateway ? $invoice->get_transaction_id() : '', |
576 | 576 | ); |
577 | 577 | |
578 | - $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice ); |
|
578 | + $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | return $data; |
@@ -591,44 +591,44 @@ discard block |
||
591 | 591 | 'return' => 'ids', |
592 | 592 | ); |
593 | 593 | |
594 | - if ( $this->status != 'any' ) { |
|
594 | + if ($this->status != 'any') { |
|
595 | 595 | $args['status'] = $this->status; |
596 | 596 | } else { |
597 | - $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
597 | + $args['status'] = array_keys(wpinv_get_invoice_statuses(true)); |
|
598 | 598 | } |
599 | 599 | |
600 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
600 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
601 | 601 | $args['date_query'] = array( |
602 | 602 | array( |
603 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
604 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
603 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
604 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
605 | 605 | 'inclusive' => true |
606 | 606 | ) |
607 | 607 | ); |
608 | 608 | } |
609 | 609 | |
610 | - $invoices = wpinv_get_invoices( $args ); |
|
611 | - $total = !empty( $invoices ) ? count( $invoices ) : 0; |
|
610 | + $invoices = wpinv_get_invoices($args); |
|
611 | + $total = !empty($invoices) ? count($invoices) : 0; |
|
612 | 612 | $status = 100; |
613 | 613 | |
614 | - if ( $total > 0 ) { |
|
615 | - $status = ( ( $this->per_page * $this->step ) / $total ) * 100; |
|
614 | + if ($total > 0) { |
|
615 | + $status = (($this->per_page * $this->step) / $total) * 100; |
|
616 | 616 | } |
617 | 617 | |
618 | - if ( $status > 100 ) { |
|
618 | + if ($status > 100) { |
|
619 | 619 | $status = 100; |
620 | 620 | } |
621 | 621 | |
622 | 622 | return $status; |
623 | 623 | } |
624 | 624 | |
625 | - public function get_invoice_items($invoice){ |
|
626 | - if(!$invoice){ |
|
625 | + public function get_invoice_items($invoice) { |
|
626 | + if (!$invoice) { |
|
627 | 627 | return ''; |
628 | 628 | } |
629 | 629 | |
630 | 630 | $cart_details = $invoice->get_cart_details(); |
631 | - if(!empty($cart_details)){ |
|
631 | + if (!empty($cart_details)) { |
|
632 | 632 | $cart_details = maybe_serialize($cart_details); |
633 | 633 | } else { |
634 | 634 | $cart_details = ''; |
@@ -640,14 +640,14 @@ discard block |
||
640 | 640 | /** |
641 | 641 | * Returns the periods filter. |
642 | 642 | */ |
643 | - public function period_filter( $args = array() ) { |
|
643 | + public function period_filter($args = array()) { |
|
644 | 644 | |
645 | 645 | ob_start(); |
646 | 646 | |
647 | 647 | echo '<form id="wpinv-graphs-filter" method="get" style="margin-bottom: 10px;" class="tablenav">'; |
648 | 648 | echo '<input type="hidden" name="page" value="wpinv-reports">'; |
649 | 649 | |
650 | - foreach ( $args as $key => $val ) { |
|
650 | + foreach ($args as $key => $val) { |
|
651 | 651 | $key = esc_attr($key); |
652 | 652 | $val = esc_attr($val); |
653 | 653 | echo "<input type='hidden' name='$key' value='$val'>"; |
@@ -656,21 +656,21 @@ discard block |
||
656 | 656 | echo '<select id="wpinv-graphs-date-options" name="range" style="min-width: 200px;" onChange="this.form.submit()">'; |
657 | 657 | |
658 | 658 | $ranges = array( |
659 | - 'today' => __( 'Today', 'invoicing' ), |
|
660 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
661 | - 'this_week' => __( 'This Week', 'invoicing' ), |
|
662 | - 'last_week' => __( 'Last Week', 'invoicing' ), |
|
663 | - '7_days_ago' => __( 'Last 7 Days', 'invoicing' ), |
|
664 | - '30_days_ago' => __( 'Last 30 Days', 'invoicing' ), |
|
665 | - 'this_month' => __( 'This Month', 'invoicing' ), |
|
666 | - 'this_year' => __( 'This Year', 'invoicing' ), |
|
667 | - 'last_year' => __( 'Last Year', 'invoicing' ), |
|
659 | + 'today' => __('Today', 'invoicing'), |
|
660 | + 'yesterday' => __('Yesterday', 'invoicing'), |
|
661 | + 'this_week' => __('This Week', 'invoicing'), |
|
662 | + 'last_week' => __('Last Week', 'invoicing'), |
|
663 | + '7_days_ago' => __('Last 7 Days', 'invoicing'), |
|
664 | + '30_days_ago' => __('Last 30 Days', 'invoicing'), |
|
665 | + 'this_month' => __('This Month', 'invoicing'), |
|
666 | + 'this_year' => __('This Year', 'invoicing'), |
|
667 | + 'last_year' => __('Last Year', 'invoicing'), |
|
668 | 668 | ); |
669 | 669 | |
670 | - $range = isset( $_GET['range'] ) && isset( $ranges[ $_GET['range'] ] ) ? $_GET['range'] : '7_days_ago'; |
|
670 | + $range = isset($_GET['range']) && isset($ranges[$_GET['range']]) ? $_GET['range'] : '7_days_ago'; |
|
671 | 671 | |
672 | - foreach ( $ranges as $val => $label ) { |
|
673 | - $selected = selected( $range, $val, false ); |
|
672 | + foreach ($ranges as $val => $label) { |
|
673 | + $selected = selected($range, $val, false); |
|
674 | 674 | echo "<option value='$val' $selected>$label</option>"; |
675 | 675 | } |
676 | 676 | |
@@ -682,28 +682,28 @@ discard block |
||
682 | 682 | /** |
683 | 683 | * Returns the the current date range. |
684 | 684 | */ |
685 | - public function get_sql_clauses( $range ) { |
|
685 | + public function get_sql_clauses($range) { |
|
686 | 686 | |
687 | 687 | $date = 'CAST(meta.completed_date AS DATE)'; |
688 | 688 | $datetime = 'meta.completed_date'; |
689 | 689 | |
690 | 690 | // Prepare durations. |
691 | - $today = current_time( 'Y-m-d' ); |
|
692 | - $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
693 | - $sunday = date( 'Y-m-d', strtotime( 'sunday this week', current_time( 'timestamp' ) ) ); |
|
694 | - $monday = date( 'Y-m-d', strtotime( 'monday this week', current_time( 'timestamp' ) ) ); |
|
695 | - $last_sunday = date( 'Y-m-d', strtotime( 'sunday last week', current_time( 'timestamp' ) ) ); |
|
696 | - $last_monday = date( 'Y-m-d', strtotime( 'monday last week', current_time( 'timestamp' ) ) ); |
|
697 | - $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
698 | - $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
699 | - $first_day_month = date( 'Y-m-1', current_time( 'timestamp' ) ); |
|
700 | - $last_day_month = date( 'Y-m-t', current_time( 'timestamp' ) ); |
|
701 | - $first_day_last_month = date( 'Y-m-d', strtotime( 'first day of last month', current_time( 'timestamp' ) ) ); |
|
702 | - $last_day_last_month = date( 'Y-m-d', strtotime( 'last day of last month', current_time( 'timestamp' ) ) ); |
|
703 | - $first_day_year = date( 'Y-1-1', current_time( 'timestamp' ) ); |
|
704 | - $last_day_year = date( 'Y-12-31', current_time( 'timestamp' ) ); |
|
705 | - $first_day_last_year = date( 'Y-m-d', strtotime( 'first day of last year', current_time( 'timestamp' ) ) ); |
|
706 | - $last_day_last_year = date( 'Y-m-d', strtotime( 'last day of last year', current_time( 'timestamp' ) ) ); |
|
691 | + $today = current_time('Y-m-d'); |
|
692 | + $yesterday = date('Y-m-d', strtotime('-1 day', current_time('timestamp'))); |
|
693 | + $sunday = date('Y-m-d', strtotime('sunday this week', current_time('timestamp'))); |
|
694 | + $monday = date('Y-m-d', strtotime('monday this week', current_time('timestamp'))); |
|
695 | + $last_sunday = date('Y-m-d', strtotime('sunday last week', current_time('timestamp'))); |
|
696 | + $last_monday = date('Y-m-d', strtotime('monday last week', current_time('timestamp'))); |
|
697 | + $seven_days_ago = date('Y-m-d', strtotime('-7 days', current_time('timestamp'))); |
|
698 | + $thirty_days_ago = date('Y-m-d', strtotime('-30 days', current_time('timestamp'))); |
|
699 | + $first_day_month = date('Y-m-1', current_time('timestamp')); |
|
700 | + $last_day_month = date('Y-m-t', current_time('timestamp')); |
|
701 | + $first_day_last_month = date('Y-m-d', strtotime('first day of last month', current_time('timestamp'))); |
|
702 | + $last_day_last_month = date('Y-m-d', strtotime('last day of last month', current_time('timestamp'))); |
|
703 | + $first_day_year = date('Y-1-1', current_time('timestamp')); |
|
704 | + $last_day_year = date('Y-12-31', current_time('timestamp')); |
|
705 | + $first_day_last_year = date('Y-m-d', strtotime('first day of last year', current_time('timestamp'))); |
|
706 | + $last_day_last_year = date('Y-m-d', strtotime('last day of last year', current_time('timestamp'))); |
|
707 | 707 | |
708 | 708 | $ranges = array( |
709 | 709 | |
@@ -759,21 +759,21 @@ discard block |
||
759 | 759 | |
760 | 760 | ); |
761 | 761 | |
762 | - if ( ! isset( $ranges[ $range ] ) ) { |
|
762 | + if (!isset($ranges[$range])) { |
|
763 | 763 | return $ranges['7_days_ago']; |
764 | 764 | } |
765 | - return $ranges[ $range ]; |
|
765 | + return $ranges[$range]; |
|
766 | 766 | |
767 | 767 | } |
768 | 768 | |
769 | 769 | /** |
770 | 770 | * Returns the the current date ranges results. |
771 | 771 | */ |
772 | - public function get_report_results( $range ) { |
|
772 | + public function get_report_results($range) { |
|
773 | 773 | global $wpdb; |
774 | 774 | |
775 | 775 | $table = $wpdb->prefix . 'getpaid_invoices'; |
776 | - $clauses = $this->get_sql_clauses( $range ); |
|
776 | + $clauses = $this->get_sql_clauses($range); |
|
777 | 777 | $sql = "SELECT |
778 | 778 | {$clauses[0]} AS completed_date, |
779 | 779 | SUM( meta.total ) AS total, |
@@ -789,30 +789,30 @@ discard block |
||
789 | 789 | GROUP BY {$clauses[0]} |
790 | 790 | "; |
791 | 791 | |
792 | - return $wpdb->get_results( $sql ); |
|
792 | + return $wpdb->get_results($sql); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
796 | 796 | * Fill nulls. |
797 | 797 | */ |
798 | - public function fill_nulls( $data, $range ) { |
|
798 | + public function fill_nulls($data, $range) { |
|
799 | 799 | |
800 | 800 | $return = array(); |
801 | 801 | $time = current_time('timestamp'); |
802 | 802 | |
803 | - switch ( $range ) { |
|
803 | + switch ($range) { |
|
804 | 804 | case 'today' : |
805 | 805 | case 'yesterday' : |
806 | - $hour = 0; |
|
806 | + $hour = 0; |
|
807 | 807 | |
808 | - while ( $hour < 23 ) { |
|
808 | + while ($hour < 23) { |
|
809 | 809 | $amount = 0; |
810 | - if ( isset( $data[$hour] ) ) { |
|
811 | - $amount = floatval( $data[$hour] ); |
|
810 | + if (isset($data[$hour])) { |
|
811 | + $amount = floatval($data[$hour]); |
|
812 | 812 | } |
813 | 813 | |
814 | - $time = strtotime( "$range $hour:00:00" ) * 1000; |
|
815 | - $return[] = array( $time, $amount ); |
|
814 | + $time = strtotime("$range $hour:00:00") * 1000; |
|
815 | + $return[] = array($time, $amount); |
|
816 | 816 | $hour++; |
817 | 817 | } |
818 | 818 | |
@@ -820,9 +820,9 @@ discard block |
||
820 | 820 | |
821 | 821 | case 'this_month' : |
822 | 822 | case 'last_month' : |
823 | - $_range = str_replace( '_', ' ', $range ); |
|
824 | - $month = date( 'n', strtotime( $_range, $time ) ); |
|
825 | - $year = date( 'Y', strtotime( $_range, $time ) ); |
|
823 | + $_range = str_replace('_', ' ', $range); |
|
824 | + $month = date('n', strtotime($_range, $time)); |
|
825 | + $year = date('Y', strtotime($_range, $time)); |
|
826 | 826 | $days = cal_days_in_month( |
827 | 827 | CAL_GREGORIAN, |
828 | 828 | $month, |
@@ -830,14 +830,14 @@ discard block |
||
830 | 830 | ); |
831 | 831 | |
832 | 832 | $day = 1; |
833 | - while ( $days != $day ) { |
|
833 | + while ($days != $day) { |
|
834 | 834 | $amount = 0; |
835 | - if ( isset( $data[$day] ) ) { |
|
836 | - $amount = floatval( $data[$day] ); |
|
835 | + if (isset($data[$day])) { |
|
836 | + $amount = floatval($data[$day]); |
|
837 | 837 | } |
838 | 838 | |
839 | - $time = strtotime( "$year-$month-$day" ) * 1000; |
|
840 | - $return[] = array( $time, $amount ); |
|
839 | + $time = strtotime("$year-$month-$day") * 1000; |
|
840 | + $return[] = array($time, $amount); |
|
841 | 841 | $day++; |
842 | 842 | } |
843 | 843 | |
@@ -845,52 +845,52 @@ discard block |
||
845 | 845 | |
846 | 846 | case 'this_week' : |
847 | 847 | case 'last_week' : |
848 | - $_range = str_replace( '_', ' ', $range ); |
|
849 | - $days = array( 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ); |
|
848 | + $_range = str_replace('_', ' ', $range); |
|
849 | + $days = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'); |
|
850 | 850 | |
851 | - foreach ( $days as $day ) { |
|
851 | + foreach ($days as $day) { |
|
852 | 852 | |
853 | 853 | $amount = 0; |
854 | - if ( isset( $data[ ucfirst( $day ) ] ) ) { |
|
855 | - $amount = floatval( $data[ ucfirst( $day ) ] ); |
|
854 | + if (isset($data[ucfirst($day)])) { |
|
855 | + $amount = floatval($data[ucfirst($day)]); |
|
856 | 856 | } |
857 | 857 | |
858 | - $time = strtotime( "$_range $day" ) * 1000; |
|
859 | - $return[] = array( $time, $amount ); |
|
858 | + $time = strtotime("$_range $day") * 1000; |
|
859 | + $return[] = array($time, $amount); |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | break; |
863 | 863 | |
864 | 864 | case 'this_year' : |
865 | 865 | case 'last_year' : |
866 | - $_range = str_replace( '_', ' ', $range ); |
|
867 | - $year = date( 'Y', strtotime( $_range, $time ) ); |
|
868 | - $months = array( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' ); |
|
866 | + $_range = str_replace('_', ' ', $range); |
|
867 | + $year = date('Y', strtotime($_range, $time)); |
|
868 | + $months = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'); |
|
869 | 869 | |
870 | - foreach ( $months as $month ) { |
|
870 | + foreach ($months as $month) { |
|
871 | 871 | |
872 | 872 | $amount = 0; |
873 | - if ( isset( $data[$month] ) ) { |
|
874 | - $amount = floatval( $data[$month] ); |
|
873 | + if (isset($data[$month])) { |
|
874 | + $amount = floatval($data[$month]); |
|
875 | 875 | } |
876 | 876 | |
877 | - $_time = strtotime("$year-$month-01") * 1000; |
|
878 | - $return[] = array( $_time, $amount ); |
|
877 | + $_time = strtotime("$year-$month-01") * 1000; |
|
878 | + $return[] = array($_time, $amount); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | break; |
882 | 882 | case '30_days_ago' : |
883 | 883 | $days = 30; |
884 | 884 | |
885 | - while ( $days > 1 ) { |
|
885 | + while ($days > 1) { |
|
886 | 886 | $amount = 0; |
887 | - $date = date( 'j', strtotime( "-$days days", $time ) ); |
|
888 | - if ( isset( $data[$date] ) ) { |
|
889 | - $amount = floatval( $data[$date] ); |
|
887 | + $date = date('j', strtotime("-$days days", $time)); |
|
888 | + if (isset($data[$date])) { |
|
889 | + $amount = floatval($data[$date]); |
|
890 | 890 | } |
891 | 891 | |
892 | - $_time = strtotime( "-$days days", $time ) * 1000; |
|
893 | - $return[] = array( $_time, $amount ); |
|
892 | + $_time = strtotime("-$days days", $time) * 1000; |
|
893 | + $return[] = array($_time, $amount); |
|
894 | 894 | $days--; |
895 | 895 | } |
896 | 896 | |
@@ -899,15 +899,15 @@ discard block |
||
899 | 899 | default: |
900 | 900 | $days = 7; |
901 | 901 | |
902 | - while ( $days > 1 ) { |
|
902 | + while ($days > 1) { |
|
903 | 903 | $amount = 0; |
904 | - $date = date( 'j', strtotime( "-$days days", $time ) ); |
|
905 | - if ( isset( $data[$date] ) ) { |
|
906 | - $amount = floatval( $data[$date] ); |
|
904 | + $date = date('j', strtotime("-$days days", $time)); |
|
905 | + if (isset($data[$date])) { |
|
906 | + $amount = floatval($data[$date]); |
|
907 | 907 | } |
908 | 908 | |
909 | - $_time = strtotime( "-$days days", $time ) * 1000; |
|
910 | - $return[] = array( $_time, $amount ); |
|
909 | + $_time = strtotime("-$days days", $time) * 1000; |
|
910 | + $return[] = array($_time, $amount); |
|
911 | 911 | $days--; |
912 | 912 | } |
913 | 913 | |
@@ -922,33 +922,33 @@ discard block |
||
922 | 922 | * Retrieves the stats. |
923 | 923 | */ |
924 | 924 | public function get_stats() { |
925 | - $range = isset( $_GET['range'] ) ? $_GET['range'] : '7_days_ago'; |
|
926 | - $results = $this->get_report_results( $range ); |
|
927 | - $earnings = wp_list_pluck( $results, 'total', 'completed_date' ); |
|
928 | - $taxes = wp_list_pluck( $results, 'tax', 'completed_date' ); |
|
929 | - $discounts = wp_list_pluck( $results, 'discount', 'completed_date' ); |
|
930 | - $fees = wp_list_pluck( $results, 'fees_total', 'completed_date' ); |
|
925 | + $range = isset($_GET['range']) ? $_GET['range'] : '7_days_ago'; |
|
926 | + $results = $this->get_report_results($range); |
|
927 | + $earnings = wp_list_pluck($results, 'total', 'completed_date'); |
|
928 | + $taxes = wp_list_pluck($results, 'tax', 'completed_date'); |
|
929 | + $discounts = wp_list_pluck($results, 'discount', 'completed_date'); |
|
930 | + $fees = wp_list_pluck($results, 'fees_total', 'completed_date'); |
|
931 | 931 | |
932 | 932 | return array( |
933 | 933 | |
934 | 934 | array( |
935 | - 'label' => __( 'Earnings', 'invoicing' ), |
|
936 | - 'data' => $this->fill_nulls( $earnings, $range ), |
|
935 | + 'label' => __('Earnings', 'invoicing'), |
|
936 | + 'data' => $this->fill_nulls($earnings, $range), |
|
937 | 937 | ), |
938 | 938 | |
939 | 939 | array( |
940 | - 'label' => __( 'Taxes', 'invoicing' ), |
|
941 | - 'data' => $this->fill_nulls( $taxes, $range ), |
|
940 | + 'label' => __('Taxes', 'invoicing'), |
|
941 | + 'data' => $this->fill_nulls($taxes, $range), |
|
942 | 942 | ), |
943 | 943 | |
944 | 944 | array( |
945 | - 'label' => __( 'Discounts', 'invoicing' ), |
|
946 | - 'data' => $this->fill_nulls( $discounts, $range ), |
|
945 | + 'label' => __('Discounts', 'invoicing'), |
|
946 | + 'data' => $this->fill_nulls($discounts, $range), |
|
947 | 947 | ), |
948 | 948 | |
949 | 949 | array( |
950 | - 'label' => __( 'Fees', 'invoicing' ), |
|
951 | - 'data' => $this->fill_nulls( $fees, $range ), |
|
950 | + 'label' => __('Fees', 'invoicing'), |
|
951 | + 'data' => $this->fill_nulls($fees, $range), |
|
952 | 952 | ) |
953 | 953 | ); |
954 | 954 | |
@@ -958,34 +958,34 @@ discard block |
||
958 | 958 | * Retrieves the time format for stats. |
959 | 959 | */ |
960 | 960 | public function get_time_format() { |
961 | - $range = isset( $_GET['range'] ) ? $_GET['range'] : '7_days_ago'; |
|
961 | + $range = isset($_GET['range']) ? $_GET['range'] : '7_days_ago'; |
|
962 | 962 | |
963 | - switch ( $range ) { |
|
963 | + switch ($range) { |
|
964 | 964 | case 'today' : |
965 | 965 | case 'yesterday' : |
966 | - return array( 'hour', '%h %p' ); |
|
966 | + return array('hour', '%h %p'); |
|
967 | 967 | break; |
968 | 968 | |
969 | 969 | case 'this_month' : |
970 | 970 | case 'last_month' : |
971 | - return array( 'day', '%b %d' ); |
|
971 | + return array('day', '%b %d'); |
|
972 | 972 | break; |
973 | 973 | |
974 | 974 | case 'this_week' : |
975 | 975 | case 'last_week' : |
976 | - return array( 'day', '%b %d' ); |
|
976 | + return array('day', '%b %d'); |
|
977 | 977 | break; |
978 | 978 | |
979 | 979 | case 'this_year' : |
980 | 980 | case 'last_year' : |
981 | - return array( 'month', '%b' ); |
|
981 | + return array('month', '%b'); |
|
982 | 982 | break; |
983 | 983 | case '30_days_ago' : |
984 | - return array( 'day', '%b %d' ); |
|
984 | + return array('day', '%b %d'); |
|
985 | 985 | break; |
986 | 986 | |
987 | 987 | default: |
988 | - return array( 'day', '%b %d' ); |
|
988 | + return array('day', '%b %d'); |
|
989 | 989 | break; |
990 | 990 | |
991 | 991 | } |
@@ -996,11 +996,11 @@ discard block |
||
996 | 996 | */ |
997 | 997 | public function earnings_report() { |
998 | 998 | |
999 | - $data = wp_json_encode( $this->get_stats() ); |
|
999 | + $data = wp_json_encode($this->get_stats()); |
|
1000 | 1000 | $time_format = $this->get_time_format(); |
1001 | 1001 | echo ' |
1002 | 1002 | <div class="wpinv-report-container"> |
1003 | - <h3><span>' . __( 'Earnings Over Time', 'invoicing' ) .'</span></h3> |
|
1003 | + <h3><span>' . __('Earnings Over Time', 'invoicing') . '</span></h3> |
|
1004 | 1004 | ' . $this->period_filter() . ' |
1005 | 1005 | <div id="wpinv_report_graph" style="height: 450px;"></div> |
1006 | 1006 | </div> |
@@ -1009,12 +1009,12 @@ discard block |
||
1009 | 1009 | jQuery(document).ready( function() { |
1010 | 1010 | jQuery.plot( |
1011 | 1011 | jQuery("#wpinv_report_graph"), |
1012 | - ' . $data .', |
|
1012 | + ' . $data . ', |
|
1013 | 1013 | { |
1014 | 1014 | xaxis:{ |
1015 | 1015 | mode: "time", |
1016 | - timeformat: "' . $time_format[1] .'", |
|
1017 | - minTickSize: [0.5, "' . $time_format[0] .'"] |
|
1016 | + timeformat: "' . $time_format[1] . '", |
|
1017 | + minTickSize: [0.5, "' . $time_format[0] . '"] |
|
1018 | 1018 | }, |
1019 | 1019 | |
1020 | 1020 | yaxis: { |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | * Displays the gateways report. |
1043 | 1043 | */ |
1044 | 1044 | public function gateways_report() { |
1045 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-gateways-report-table.php' ); |
|
1045 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-gateways-report-table.php'); |
|
1046 | 1046 | |
1047 | 1047 | $table = new WPInv_Gateways_Report_Table(); |
1048 | 1048 | $table->prepare_items(); |
@@ -1053,12 +1053,12 @@ discard block |
||
1053 | 1053 | * Displays the items report. |
1054 | 1054 | */ |
1055 | 1055 | public function items_report() { |
1056 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-items-report-table.php' ); |
|
1056 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-items-report-table.php'); |
|
1057 | 1057 | |
1058 | 1058 | $table = new WPInv_Items_Report_Table(); |
1059 | 1059 | $table->prepare_items(); |
1060 | 1060 | $table->display(); |
1061 | - echo __( '* Items with no sales not shown.', 'invoicing' ); |
|
1061 | + echo __('* Items with no sales not shown.', 'invoicing'); |
|
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | /** |
@@ -1068,27 +1068,27 @@ discard block |
||
1068 | 1068 | */ |
1069 | 1069 | public function tax_report() { |
1070 | 1070 | |
1071 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-taxes-report-table.php' ); |
|
1071 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-taxes-report-table.php'); |
|
1072 | 1072 | $table = new WPInv_Taxes_Reports_Table(); |
1073 | 1073 | $table->prepare_items(); |
1074 | - $year = isset( $_GET['year'] ) ? absint( $_GET['year'] ) : date( 'Y' ); |
|
1074 | + $year = isset($_GET['year']) ? absint($_GET['year']) : date('Y'); |
|
1075 | 1075 | ?> |
1076 | 1076 | |
1077 | 1077 | <div class="metabox-holder" style="padding-top: 0;"> |
1078 | 1078 | <div class="postbox"> |
1079 | - <h3><span><?php _e('Tax Report','invoicing' ); ?></span></h3> |
|
1079 | + <h3><span><?php _e('Tax Report', 'invoicing'); ?></span></h3> |
|
1080 | 1080 | <div class="inside"> |
1081 | - <p><?php _e( 'This report shows the total amount collected in sales tax for the given year.', 'invoicing' ); ?></p> |
|
1081 | + <p><?php _e('This report shows the total amount collected in sales tax for the given year.', 'invoicing'); ?></p> |
|
1082 | 1082 | <form method="get"> |
1083 | - <span><?php echo $year; ?></span>: <strong><?php echo wpinv_sales_tax_for_year( $year ); ?></strong> — |
|
1083 | + <span><?php echo $year; ?></span>: <strong><?php echo wpinv_sales_tax_for_year($year); ?></strong> — |
|
1084 | 1084 | <select name="year"> |
1085 | - <?php for ( $i = 2014; $i <= date( 'Y' ); $i++ ) : ?> |
|
1086 | - <option value="<?php echo $i; ?>"<?php selected( $year, $i ); ?>><?php echo $i; ?></option> |
|
1085 | + <?php for ($i = 2014; $i <= date('Y'); $i++) : ?> |
|
1086 | + <option value="<?php echo $i; ?>"<?php selected($year, $i); ?>><?php echo $i; ?></option> |
|
1087 | 1087 | <?php endfor; ?> |
1088 | 1088 | </select> |
1089 | 1089 | <input type="hidden" name="view" value="taxes" /> |
1090 | 1090 | <input type="hidden" name="page" value="wpinv-reports"/> |
1091 | - <?php submit_button( __( 'Submit', 'invoicing' ), 'secondary', 'submit', false ); ?> |
|
1091 | + <?php submit_button(__('Submit', 'invoicing'), 'secondary', 'submit', false); ?> |
|
1092 | 1092 | </form> |
1093 | 1093 | </div><!-- .inside --> |
1094 | 1094 | </div><!-- .postbox --> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Setup menus in WP admin. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WC_Admin_Menus Class. |
@@ -13,24 +13,24 @@ discard block |
||
13 | 13 | * Hook in tabs. |
14 | 14 | */ |
15 | 15 | public function __construct() { |
16 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
17 | - add_action( 'admin_menu', array( $this, 'add_customers_menu' ), 18 ); |
|
18 | - add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 ); |
|
19 | - add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 ); |
|
20 | - add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 ); |
|
21 | - add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) ); |
|
16 | + add_action('admin_menu', array($this, 'admin_menu'), 10); |
|
17 | + add_action('admin_menu', array($this, 'add_customers_menu'), 18); |
|
18 | + add_action('admin_menu', array($this, 'add_addons_menu'), 100); |
|
19 | + add_action('admin_menu', array($this, 'add_settings_menu'), 60); |
|
20 | + add_action('admin_menu', array($this, 'remove_admin_submenus'), 10); |
|
21 | + add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes')); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function admin_menu() { |
25 | 25 | |
26 | - $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() ); |
|
26 | + $capability = apply_filters('invoicing_capability', wpinv_get_capability()); |
|
27 | 27 | add_menu_page( |
28 | - __( 'GetPaid', 'invoicing' ), |
|
29 | - __( 'GetPaid', 'invoicing' ), |
|
28 | + __('GetPaid', 'invoicing'), |
|
29 | + __('GetPaid', 'invoicing'), |
|
30 | 30 | $capability, |
31 | 31 | 'wpinv', |
32 | 32 | null, |
33 | - 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg' ) ), |
|
33 | + 'data:image/svg+xml;base64,' . base64_encode(file_get_contents(WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg')), |
|
34 | 34 | '54.123460' |
35 | 35 | ); |
36 | 36 | |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | public function add_customers_menu() { |
43 | 43 | add_submenu_page( |
44 | 44 | 'wpinv', |
45 | - __( 'Customers', 'invoicing' ), |
|
46 | - __( 'Customers', 'invoicing' ), |
|
45 | + __('Customers', 'invoicing'), |
|
46 | + __('Customers', 'invoicing'), |
|
47 | 47 | wpinv_get_capability(), |
48 | 48 | 'wpinv-customers', |
49 | - array( $this, 'customers_page' ) |
|
49 | + array($this, 'customers_page') |
|
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * Displays the customers page. |
55 | 55 | */ |
56 | 56 | public function customers_page() { |
57 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php' ); |
|
57 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php'); |
|
58 | 58 | ?> |
59 | 59 | <div class="wrap wpi-customers-wrap"> |
60 | 60 | <style> |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | width: 30%; |
63 | 63 | } |
64 | 64 | </style> |
65 | - <h1><?php echo esc_html( __( 'Customers', 'invoicing' ) ); ?></h1> |
|
65 | + <h1><?php echo esc_html(__('Customers', 'invoicing')); ?></h1> |
|
66 | 66 | <?php |
67 | 67 | $table = new WPInv_Customers_Table(); |
68 | 68 | $table->prepare_items(); |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | public function add_settings_menu() { |
79 | 79 | add_submenu_page( |
80 | 80 | 'wpinv', |
81 | - __( 'Invoice Settings', 'invoicing' ), |
|
82 | - __( 'Settings', 'invoicing' ), |
|
83 | - apply_filters( 'invoicing_capability', wpinv_get_capability() ), |
|
81 | + __('Invoice Settings', 'invoicing'), |
|
82 | + __('Settings', 'invoicing'), |
|
83 | + apply_filters('invoicing_capability', wpinv_get_capability()), |
|
84 | 84 | 'wpinv-settings', |
85 | - array( $this, 'options_page' ) |
|
85 | + array($this, 'options_page') |
|
86 | 86 | ); |
87 | 87 | } |
88 | 88 | |
89 | - public function add_addons_menu(){ |
|
90 | - if ( !apply_filters( 'wpi_show_addons_page', true ) ) { |
|
89 | + public function add_addons_menu() { |
|
90 | + if (!apply_filters('wpi_show_addons_page', true)) { |
|
91 | 91 | return; |
92 | 92 | } |
93 | 93 | |
@@ -97,78 +97,78 @@ discard block |
||
97 | 97 | __('Extensions', 'invoicing'), |
98 | 98 | 'manage_options', |
99 | 99 | 'wpi-addons', |
100 | - array( $this, 'addons_page' ) |
|
100 | + array($this, 'addons_page') |
|
101 | 101 | ); |
102 | 102 | } |
103 | 103 | |
104 | - public function addons_page(){ |
|
104 | + public function addons_page() { |
|
105 | 105 | $addon_obj = new WPInv_Admin_Addons(); |
106 | 106 | $addon_obj->output(); |
107 | 107 | } |
108 | 108 | |
109 | 109 | function options_page() { |
110 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
110 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
111 | 111 | |
112 | - if ( $page !== 'wpinv-settings' ) { |
|
112 | + if ($page !== 'wpinv-settings') { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | 116 | $settings_tabs = wpinv_get_settings_tabs(); |
117 | 117 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
118 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
119 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
118 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
119 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
120 | 120 | $key = 'main'; |
121 | 121 | |
122 | - if ( is_array( $sections ) ) { |
|
123 | - $key = key( $sections ); |
|
122 | + if (is_array($sections)) { |
|
123 | + $key = key($sections); |
|
124 | 124 | } |
125 | 125 | |
126 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
127 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
|
126 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
127 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key; |
|
128 | 128 | ob_start(); |
129 | 129 | ?> |
130 | 130 | <div class="wrap"> |
131 | 131 | <h1 class="nav-tab-wrapper"> |
132 | 132 | <?php |
133 | - foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
134 | - $tab_url = add_query_arg( array( |
|
133 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
134 | + $tab_url = add_query_arg(array( |
|
135 | 135 | 'settings-updated' => false, |
136 | 136 | 'tab' => $tab_id, |
137 | - ) ); |
|
137 | + )); |
|
138 | 138 | |
139 | 139 | // Remove the section from the tabs so we always end up at the main section |
140 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
141 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
140 | + $tab_url = remove_query_arg('section', $tab_url); |
|
141 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
142 | 142 | |
143 | 143 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
144 | 144 | |
145 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
|
146 | - echo esc_html( $tab_name ); |
|
145 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">'; |
|
146 | + echo esc_html($tab_name); |
|
147 | 147 | echo '</a>'; |
148 | 148 | } |
149 | 149 | ?> |
150 | 150 | </h1> |
151 | 151 | <?php |
152 | - $number_of_sections = count( $sections ); |
|
152 | + $number_of_sections = count($sections); |
|
153 | 153 | $number = 0; |
154 | - if ( $number_of_sections > 1 ) { |
|
154 | + if ($number_of_sections > 1) { |
|
155 | 155 | echo '<div><ul class="subsubsub">'; |
156 | - foreach( $sections as $section_id => $section_name ) { |
|
156 | + foreach ($sections as $section_id => $section_name) { |
|
157 | 157 | echo '<li>'; |
158 | 158 | $number++; |
159 | - $tab_url = add_query_arg( array( |
|
159 | + $tab_url = add_query_arg(array( |
|
160 | 160 | 'settings-updated' => false, |
161 | 161 | 'tab' => $active_tab, |
162 | 162 | 'section' => $section_id |
163 | - ) ); |
|
164 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
163 | + )); |
|
164 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
165 | 165 | $class = ''; |
166 | - if ( $section == $section_id ) { |
|
166 | + if ($section == $section_id) { |
|
167 | 167 | $class = 'current'; |
168 | 168 | } |
169 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
|
169 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>'; |
|
170 | 170 | |
171 | - if ( $number != $number_of_sections ) { |
|
171 | + if ($number != $number_of_sections) { |
|
172 | 172 | echo ' | '; |
173 | 173 | } |
174 | 174 | echo '</li>'; |
@@ -180,19 +180,19 @@ discard block |
||
180 | 180 | <form method="post" action="options.php"> |
181 | 181 | <table class="form-table"> |
182 | 182 | <?php |
183 | - settings_fields( 'wpinv_settings' ); |
|
183 | + settings_fields('wpinv_settings'); |
|
184 | 184 | |
185 | - if ( 'main' === $section ) { |
|
186 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
185 | + if ('main' === $section) { |
|
186 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
187 | 187 | } |
188 | 188 | |
189 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
190 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
191 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
189 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section); |
|
190 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section); |
|
191 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section); |
|
192 | 192 | |
193 | 193 | // For backwards compatibility |
194 | - if ( 'main' === $section ) { |
|
195 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
194 | + if ('main' === $section) { |
|
195 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
196 | 196 | } |
197 | 197 | ?> |
198 | 198 | </table> |
@@ -206,18 +206,18 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | public function remove_admin_submenus() { |
209 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
209 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
210 | 210 | } |
211 | 211 | |
212 | - public function add_nav_menu_meta_boxes(){ |
|
213 | - add_meta_box( 'wpinv_endpoints_nav_link', __( 'Invoicing Pages', 'invoicing' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' ); |
|
212 | + public function add_nav_menu_meta_boxes() { |
|
213 | + add_meta_box('wpinv_endpoints_nav_link', __('Invoicing Pages', 'invoicing'), array($this, 'nav_menu_links'), 'nav-menus', 'side', 'low'); |
|
214 | 214 | } |
215 | 215 | |
216 | - public function nav_menu_links(){ |
|
216 | + public function nav_menu_links() { |
|
217 | 217 | $endpoints = $this->get_menu_items(); |
218 | 218 | ?> |
219 | 219 | <div id="invoicing-endpoints" class="posttypediv"> |
220 | - <?php if(!empty($endpoints['pages'])){ ?> |
|
220 | + <?php if (!empty($endpoints['pages'])) { ?> |
|
221 | 221 | <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active"> |
222 | 222 | <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear"> |
223 | 223 | <?php |
@@ -229,29 +229,29 @@ discard block |
||
229 | 229 | <?php } ?> |
230 | 230 | <p class="button-controls"> |
231 | 231 | <span class="list-controls"> |
232 | - <a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints' ); ?>" class="select-all"><?php _e( 'Select all', 'invoicing' ); ?></a> |
|
232 | + <a href="<?php echo admin_url('nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints'); ?>" class="select-all"><?php _e('Select all', 'invoicing'); ?></a> |
|
233 | 233 | </span> |
234 | 234 | <span class="add-to-menu"> |
235 | - <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
235 | + <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
236 | 236 | <span class="spinner"></span> |
237 | 237 | </span> |
238 | 238 | </p> |
239 | 239 | <?php |
240 | 240 | } |
241 | 241 | |
242 | - public function get_menu_items(){ |
|
242 | + public function get_menu_items() { |
|
243 | 243 | $items = array(); |
244 | 244 | |
245 | - $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' ); |
|
246 | - if($wpinv_history_page_id > 0){ |
|
245 | + $wpinv_history_page_id = (int) wpinv_get_option('invoice_history_page'); |
|
246 | + if ($wpinv_history_page_id > 0) { |
|
247 | 247 | $item = new stdClass(); |
248 | 248 | $item->object_id = $wpinv_history_page_id; |
249 | 249 | $item->db_id = 0; |
250 | - $item->object = 'page'; |
|
250 | + $item->object = 'page'; |
|
251 | 251 | $item->menu_item_parent = 0; |
252 | 252 | $item->type = 'post_type'; |
253 | - $item->title = __('Invoice History Page','invoicing'); |
|
254 | - $item->url = get_permalink( $wpinv_history_page_id ); |
|
253 | + $item->title = __('Invoice History Page', 'invoicing'); |
|
254 | + $item->url = get_permalink($wpinv_history_page_id); |
|
255 | 255 | $item->target = ''; |
256 | 256 | $item->attr_title = ''; |
257 | 257 | $item->classes = array('wpinv-menu-item'); |
@@ -260,16 +260,16 @@ discard block |
||
260 | 260 | $items['pages'][] = $item; |
261 | 261 | } |
262 | 262 | |
263 | - $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' ); |
|
264 | - if($wpinv_sub_history_page_id > 0){ |
|
263 | + $wpinv_sub_history_page_id = (int) wpinv_get_option('invoice_subscription_page'); |
|
264 | + if ($wpinv_sub_history_page_id > 0) { |
|
265 | 265 | $item = new stdClass(); |
266 | 266 | $item->object_id = $wpinv_sub_history_page_id; |
267 | 267 | $item->db_id = 0; |
268 | - $item->object = 'page'; |
|
268 | + $item->object = 'page'; |
|
269 | 269 | $item->menu_item_parent = 0; |
270 | 270 | $item->type = 'post_type'; |
271 | - $item->title = __('Invoice Subscriptions Page','invoicing'); |
|
272 | - $item->url = get_permalink( $wpinv_sub_history_page_id ); |
|
271 | + $item->title = __('Invoice Subscriptions Page', 'invoicing'); |
|
272 | + $item->url = get_permalink($wpinv_sub_history_page_id); |
|
273 | 273 | $item->target = ''; |
274 | 274 | $item->attr_title = ''; |
275 | 275 | $item->classes = array('wpinv-menu-item'); |
@@ -278,16 +278,16 @@ discard block |
||
278 | 278 | $items['pages'][] = $item; |
279 | 279 | } |
280 | 280 | |
281 | - $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' ); |
|
282 | - if($wpinv_checkout_page_id > 0){ |
|
281 | + $wpinv_checkout_page_id = (int) wpinv_get_option('checkout_page'); |
|
282 | + if ($wpinv_checkout_page_id > 0) { |
|
283 | 283 | $item = new stdClass(); |
284 | 284 | $item->object_id = $wpinv_checkout_page_id; |
285 | 285 | $item->db_id = 0; |
286 | - $item->object = 'page'; |
|
286 | + $item->object = 'page'; |
|
287 | 287 | $item->menu_item_parent = 0; |
288 | 288 | $item->type = 'post_type'; |
289 | - $item->title = __('Checkout Page','invoicing'); |
|
290 | - $item->url = get_permalink( $wpinv_checkout_page_id ); |
|
289 | + $item->title = __('Checkout Page', 'invoicing'); |
|
290 | + $item->url = get_permalink($wpinv_checkout_page_id); |
|
291 | 291 | $item->target = ''; |
292 | 292 | $item->attr_title = ''; |
293 | 293 | $item->classes = array('wpinv-menu-item'); |
@@ -296,16 +296,16 @@ discard block |
||
296 | 296 | $items['pages'][] = $item; |
297 | 297 | } |
298 | 298 | |
299 | - $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' ); |
|
300 | - if($wpinv_tandc_page_id > 0){ |
|
299 | + $wpinv_tandc_page_id = (int) wpinv_get_option('tandc_page'); |
|
300 | + if ($wpinv_tandc_page_id > 0) { |
|
301 | 301 | $item = new stdClass(); |
302 | 302 | $item->object_id = $wpinv_tandc_page_id; |
303 | 303 | $item->db_id = 0; |
304 | - $item->object = 'page'; |
|
304 | + $item->object = 'page'; |
|
305 | 305 | $item->menu_item_parent = 0; |
306 | 306 | $item->type = 'post_type'; |
307 | - $item->title = __('Terms & Conditions','invoicing'); |
|
308 | - $item->url = get_permalink( $wpinv_tandc_page_id ); |
|
307 | + $item->title = __('Terms & Conditions', 'invoicing'); |
|
308 | + $item->url = get_permalink($wpinv_tandc_page_id); |
|
309 | 309 | $item->target = ''; |
310 | 310 | $item->attr_title = ''; |
311 | 311 | $item->classes = array('wpinv-menu-item'); |
@@ -314,16 +314,16 @@ discard block |
||
314 | 314 | $items['pages'][] = $item; |
315 | 315 | } |
316 | 316 | |
317 | - $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' ); |
|
318 | - if($wpinv_success_page_id > 0){ |
|
317 | + $wpinv_success_page_id = (int) wpinv_get_option('success_page'); |
|
318 | + if ($wpinv_success_page_id > 0) { |
|
319 | 319 | $item = new stdClass(); |
320 | 320 | $item->object_id = $wpinv_success_page_id; |
321 | 321 | $item->db_id = 0; |
322 | - $item->object = 'page'; |
|
322 | + $item->object = 'page'; |
|
323 | 323 | $item->menu_item_parent = 0; |
324 | 324 | $item->type = 'post_type'; |
325 | - $item->title = __('Success Page','invoicing'); |
|
326 | - $item->url = get_permalink( $wpinv_success_page_id ); |
|
325 | + $item->title = __('Success Page', 'invoicing'); |
|
326 | + $item->url = get_permalink($wpinv_success_page_id); |
|
327 | 327 | $item->target = ''; |
328 | 328 | $item->attr_title = ''; |
329 | 329 | $item->classes = array('wpinv-menu-item'); |
@@ -332,16 +332,16 @@ discard block |
||
332 | 332 | $items['pages'][] = $item; |
333 | 333 | } |
334 | 334 | |
335 | - $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' ); |
|
336 | - if($wpinv_failure_page_id > 0){ |
|
335 | + $wpinv_failure_page_id = (int) wpinv_get_option('failure_page'); |
|
336 | + if ($wpinv_failure_page_id > 0) { |
|
337 | 337 | $item = new stdClass(); |
338 | 338 | $item->object_id = $wpinv_failure_page_id; |
339 | 339 | $item->db_id = 0; |
340 | - $item->object = 'page'; |
|
340 | + $item->object = 'page'; |
|
341 | 341 | $item->menu_item_parent = 0; |
342 | 342 | $item->type = 'post_type'; |
343 | - $item->title = __('Failed Transaction Page','invoicing'); |
|
344 | - $item->url = get_permalink( $wpinv_failure_page_id ); |
|
343 | + $item->title = __('Failed Transaction Page', 'invoicing'); |
|
344 | + $item->url = get_permalink($wpinv_failure_page_id); |
|
345 | 345 | $item->target = ''; |
346 | 346 | $item->attr_title = ''; |
347 | 347 | $item->classes = array('wpinv-menu-item'); |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | $items['pages'][] = $item; |
351 | 351 | } |
352 | 352 | |
353 | - return apply_filters( 'wpinv_menu_items', $items ); |
|
353 | + return apply_filters('wpinv_menu_items', $items); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | } |
@@ -14,346 +14,346 @@ |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Meta type. This should match up with |
|
19 | - * the types available at https://developer.wordpress.org/reference/functions/add_metadata/. |
|
20 | - * WP defines 'post', 'user', 'comment', and 'term'. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $meta_type = 'post'; |
|
25 | - |
|
26 | - /** |
|
27 | - * This only needs set if you are using a custom metadata type. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $object_id_field_for_meta = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * Data stored in meta keys, but not considered "meta" for an object. |
|
35 | - * |
|
36 | - * @since 1.0.19 |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $internal_meta_keys = array(); |
|
41 | - |
|
42 | - /** |
|
43 | - * Meta data which should exist in the DB, even if empty. |
|
44 | - * |
|
45 | - * @since 1.0.19 |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $must_exist_meta_keys = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * A map of meta keys to data props. |
|
53 | - * |
|
54 | - * @since 1.0.19 |
|
55 | - * |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - protected $meta_key_to_props = array(); |
|
59 | - |
|
60 | - /** |
|
61 | - * Returns an array of meta for an object. |
|
62 | - * |
|
63 | - * @since 1.0.19 |
|
64 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public function read_meta( &$object ) { |
|
68 | - global $wpdb; |
|
69 | - $db_info = $this->get_db_info(); |
|
70 | - $raw_meta_data = $wpdb->get_results( |
|
71 | - $wpdb->prepare( |
|
72 | - "SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value |
|
17 | + /** |
|
18 | + * Meta type. This should match up with |
|
19 | + * the types available at https://developer.wordpress.org/reference/functions/add_metadata/. |
|
20 | + * WP defines 'post', 'user', 'comment', and 'term'. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $meta_type = 'post'; |
|
25 | + |
|
26 | + /** |
|
27 | + * This only needs set if you are using a custom metadata type. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $object_id_field_for_meta = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * Data stored in meta keys, but not considered "meta" for an object. |
|
35 | + * |
|
36 | + * @since 1.0.19 |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $internal_meta_keys = array(); |
|
41 | + |
|
42 | + /** |
|
43 | + * Meta data which should exist in the DB, even if empty. |
|
44 | + * |
|
45 | + * @since 1.0.19 |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $must_exist_meta_keys = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * A map of meta keys to data props. |
|
53 | + * |
|
54 | + * @since 1.0.19 |
|
55 | + * |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + protected $meta_key_to_props = array(); |
|
59 | + |
|
60 | + /** |
|
61 | + * Returns an array of meta for an object. |
|
62 | + * |
|
63 | + * @since 1.0.19 |
|
64 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public function read_meta( &$object ) { |
|
68 | + global $wpdb; |
|
69 | + $db_info = $this->get_db_info(); |
|
70 | + $raw_meta_data = $wpdb->get_results( |
|
71 | + $wpdb->prepare( |
|
72 | + "SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value |
|
73 | 73 | FROM {$db_info['table']} |
74 | 74 | WHERE {$db_info['object_id_field']} = %d |
75 | 75 | ORDER BY {$db_info['meta_id_field']}", |
76 | - $object->get_id() |
|
77 | - ) |
|
78 | - ); |
|
79 | - |
|
80 | - $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys ); |
|
81 | - $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) ); |
|
82 | - return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Deletes meta based on meta ID. |
|
87 | - * |
|
88 | - * @since 1.0.19 |
|
89 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
90 | - * @param stdClass $meta (containing at least ->id). |
|
91 | - */ |
|
92 | - public function delete_meta( &$object, $meta ) { |
|
93 | - delete_metadata_by_mid( $this->meta_type, $meta->id ); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Add new piece of meta. |
|
98 | - * |
|
99 | - * @since 1.0.19 |
|
100 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
101 | - * @param stdClass $meta (containing ->key and ->value). |
|
102 | - * @return int meta ID |
|
103 | - */ |
|
104 | - public function add_meta( &$object, $meta ) { |
|
105 | - return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Update meta. |
|
110 | - * |
|
111 | - * @since 1.0.19 |
|
112 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
113 | - * @param stdClass $meta (containing ->id, ->key and ->value). |
|
114 | - */ |
|
115 | - public function update_meta( &$object, $meta ) { |
|
116 | - update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key ); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Table structure is slightly different between meta types, this function will return what we need to know. |
|
121 | - * |
|
122 | - * @since 1.0.19 |
|
123 | - * @return array Array elements: table, object_id_field, meta_id_field |
|
124 | - */ |
|
125 | - protected function get_db_info() { |
|
126 | - global $wpdb; |
|
127 | - |
|
128 | - $meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well. |
|
129 | - $table = $wpdb->prefix; |
|
130 | - |
|
131 | - // If we are dealing with a type of metadata that is not a core type, the table should be prefixed. |
|
132 | - if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) { |
|
133 | - $table .= 'getpaid_'; |
|
134 | - } |
|
135 | - |
|
136 | - $table .= $this->meta_type . 'meta'; |
|
137 | - $object_id_field = $this->meta_type . '_id'; |
|
138 | - |
|
139 | - // Figure out our field names. |
|
140 | - if ( 'user' === $this->meta_type ) { |
|
141 | - $meta_id_field = 'umeta_id'; |
|
142 | - $table = $wpdb->usermeta; |
|
143 | - } |
|
144 | - |
|
145 | - if ( ! empty( $this->object_id_field_for_meta ) ) { |
|
146 | - $object_id_field = $this->object_id_field_for_meta; |
|
147 | - } |
|
148 | - |
|
149 | - return array( |
|
150 | - 'table' => $table, |
|
151 | - 'object_id_field' => $object_id_field, |
|
152 | - 'meta_id_field' => $meta_id_field, |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Internal meta keys we don't want exposed as part of meta_data. This is in |
|
158 | - * addition to all data props with _ prefix. |
|
159 | - * |
|
160 | - * @since 1.0.19 |
|
161 | - * |
|
162 | - * @param string $key Prefix to be added to meta keys. |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - protected function prefix_key( $key ) { |
|
166 | - return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Callback to remove unwanted meta data. |
|
171 | - * |
|
172 | - * @param object $meta Meta object to check if it should be excluded or not. |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - protected function exclude_internal_meta_keys( $meta ) { |
|
176 | - return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' ); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Gets a list of props and meta keys that need updated based on change state |
|
181 | - * or if they are present in the database or not. |
|
182 | - * |
|
183 | - * @param GetPaid_Data $object The GetPaid_Data object. |
|
184 | - * @param array $meta_key_to_props A mapping of meta keys => prop names. |
|
185 | - * @param string $meta_type The internal WP meta type (post, user, etc). |
|
186 | - * @return array A mapping of meta keys => prop names, filtered by ones that should be updated. |
|
187 | - */ |
|
188 | - protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) { |
|
189 | - $props_to_update = array(); |
|
190 | - $changed_props = $object->get_changes(); |
|
191 | - |
|
192 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
193 | - foreach ( $meta_key_to_props as $meta_key => $prop ) { |
|
194 | - if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) { |
|
195 | - $props_to_update[ $meta_key ] = $prop; |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - return $props_to_update; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Read object data. |
|
204 | - * |
|
205 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
206 | - * @param WP_Post $post_object Post object. |
|
207 | - * @since 1.0.19 |
|
208 | - */ |
|
209 | - protected function read_object_data( &$object, $post_object ) { |
|
210 | - $id = $object->get_id(); |
|
211 | - $props = array(); |
|
212 | - |
|
213 | - foreach ( $this->meta_key_to_props as $meta_key => $prop ) { |
|
214 | - $props[ $prop ] = get_post_meta( $id, $meta_key, true ); |
|
215 | - } |
|
216 | - |
|
217 | - // Set object properties. |
|
218 | - $object->set_props( $props ); |
|
219 | - |
|
220 | - // Gets extra data associated with the object if needed. |
|
221 | - foreach ( $object->get_extra_data_keys() as $key ) { |
|
222 | - $function = 'set_' . $key; |
|
223 | - if ( is_callable( array( $object, $function ) ) ) { |
|
224 | - $object->{$function}( get_post_meta( $object->get_id(), $key, true ) ); |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class. |
|
231 | - * |
|
232 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
233 | - * @since 1.0.19 |
|
234 | - */ |
|
235 | - protected function update_post_meta( &$object ) { |
|
236 | - |
|
237 | - $updated_props = array(); |
|
238 | - $props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props ); |
|
239 | - $object_type = $object->get_object_type(); |
|
240 | - |
|
241 | - foreach ( $props_to_update as $meta_key => $prop ) { |
|
242 | - $value = $object->{"get_$prop"}( 'edit' ); |
|
243 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
244 | - |
|
245 | - $updated = $this->update_or_delete_post_meta( $object, $meta_key, $value ); |
|
246 | - |
|
247 | - if ( $updated ) { |
|
248 | - $updated_props[] = $prop; |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props ); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Update meta data in, or delete it from, the database. |
|
257 | - * |
|
258 | - * Avoids storing meta when it's either an empty string or empty array or null. |
|
259 | - * Other empty values such as numeric 0 should still be stored. |
|
260 | - * Data-stores can force meta to exist using `must_exist_meta_keys`. |
|
261 | - * |
|
262 | - * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist. |
|
263 | - * |
|
264 | - * @param GetPaid_Data $object The GetPaid_Data object. |
|
265 | - * @param string $meta_key Meta key to update. |
|
266 | - * @param mixed $meta_value Value to save. |
|
267 | - * |
|
268 | - * @since 1.0.19 Added to prevent empty meta being stored unless required. |
|
269 | - * |
|
270 | - * @return bool True if updated/deleted. |
|
271 | - */ |
|
272 | - protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) { |
|
273 | - if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { |
|
274 | - $updated = delete_post_meta( $object->get_id(), $meta_key ); |
|
275 | - } else { |
|
276 | - $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value ); |
|
277 | - } |
|
278 | - |
|
279 | - return (bool) $updated; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Return list of internal meta keys. |
|
284 | - * |
|
285 | - * @since 1.0.19 |
|
286 | - * @return array |
|
287 | - */ |
|
288 | - public function get_internal_meta_keys() { |
|
289 | - return $this->internal_meta_keys; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Clear any caches. |
|
294 | - * |
|
295 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
296 | - * @since 1.0.19 |
|
297 | - */ |
|
298 | - protected function clear_caches( &$object ) { |
|
299 | - clean_post_cache( $object->get_id() ); |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Method to delete a data object from the database. |
|
304 | - * |
|
305 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
306 | - * @param array $args Array of args to pass to the delete method. |
|
307 | - * |
|
308 | - * @return void |
|
309 | - */ |
|
310 | - public function delete( &$object, $args = array() ) { |
|
311 | - $id = $object->get_id(); |
|
312 | - $object_type = $object->get_object_type(); |
|
313 | - |
|
314 | - if ( 'invoice' == $object_type ) { |
|
315 | - $object_type = $object->get_type(); |
|
316 | - } |
|
317 | - |
|
318 | - $args = wp_parse_args( |
|
319 | - $args, |
|
320 | - array( |
|
321 | - 'force_delete' => false, |
|
322 | - ) |
|
323 | - ); |
|
324 | - |
|
325 | - if ( ! $id ) { |
|
326 | - return; |
|
327 | - } |
|
328 | - |
|
329 | - if ( $args['force_delete'] ) { |
|
330 | - wp_delete_post( $id, true ); |
|
331 | - $object->set_id( 0 ); |
|
332 | - do_action( "getpaid_delete_$object_type", $id ); |
|
333 | - } else { |
|
334 | - wp_trash_post( $id ); |
|
335 | - $object->set_status( 'trash' ); |
|
336 | - do_action( "getpaid_trash_$object_type", $id ); |
|
337 | - } |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Get the status to save to the post object. |
|
342 | - * |
|
343 | - * |
|
344 | - * @since 1.0.19 |
|
345 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
346 | - * @return string |
|
347 | - */ |
|
348 | - protected function get_post_status( $object ) { |
|
349 | - $object_status = $object->get_status( 'edit' ); |
|
350 | - $object_type = $object->get_object_type(); |
|
351 | - |
|
352 | - if ( ! $object_status ) { |
|
353 | - $object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' ); |
|
354 | - } |
|
355 | - |
|
356 | - return $object_status; |
|
357 | - } |
|
76 | + $object->get_id() |
|
77 | + ) |
|
78 | + ); |
|
79 | + |
|
80 | + $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys ); |
|
81 | + $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) ); |
|
82 | + return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Deletes meta based on meta ID. |
|
87 | + * |
|
88 | + * @since 1.0.19 |
|
89 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
90 | + * @param stdClass $meta (containing at least ->id). |
|
91 | + */ |
|
92 | + public function delete_meta( &$object, $meta ) { |
|
93 | + delete_metadata_by_mid( $this->meta_type, $meta->id ); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Add new piece of meta. |
|
98 | + * |
|
99 | + * @since 1.0.19 |
|
100 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
101 | + * @param stdClass $meta (containing ->key and ->value). |
|
102 | + * @return int meta ID |
|
103 | + */ |
|
104 | + public function add_meta( &$object, $meta ) { |
|
105 | + return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Update meta. |
|
110 | + * |
|
111 | + * @since 1.0.19 |
|
112 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
113 | + * @param stdClass $meta (containing ->id, ->key and ->value). |
|
114 | + */ |
|
115 | + public function update_meta( &$object, $meta ) { |
|
116 | + update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key ); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Table structure is slightly different between meta types, this function will return what we need to know. |
|
121 | + * |
|
122 | + * @since 1.0.19 |
|
123 | + * @return array Array elements: table, object_id_field, meta_id_field |
|
124 | + */ |
|
125 | + protected function get_db_info() { |
|
126 | + global $wpdb; |
|
127 | + |
|
128 | + $meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well. |
|
129 | + $table = $wpdb->prefix; |
|
130 | + |
|
131 | + // If we are dealing with a type of metadata that is not a core type, the table should be prefixed. |
|
132 | + if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) { |
|
133 | + $table .= 'getpaid_'; |
|
134 | + } |
|
135 | + |
|
136 | + $table .= $this->meta_type . 'meta'; |
|
137 | + $object_id_field = $this->meta_type . '_id'; |
|
138 | + |
|
139 | + // Figure out our field names. |
|
140 | + if ( 'user' === $this->meta_type ) { |
|
141 | + $meta_id_field = 'umeta_id'; |
|
142 | + $table = $wpdb->usermeta; |
|
143 | + } |
|
144 | + |
|
145 | + if ( ! empty( $this->object_id_field_for_meta ) ) { |
|
146 | + $object_id_field = $this->object_id_field_for_meta; |
|
147 | + } |
|
148 | + |
|
149 | + return array( |
|
150 | + 'table' => $table, |
|
151 | + 'object_id_field' => $object_id_field, |
|
152 | + 'meta_id_field' => $meta_id_field, |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Internal meta keys we don't want exposed as part of meta_data. This is in |
|
158 | + * addition to all data props with _ prefix. |
|
159 | + * |
|
160 | + * @since 1.0.19 |
|
161 | + * |
|
162 | + * @param string $key Prefix to be added to meta keys. |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + protected function prefix_key( $key ) { |
|
166 | + return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Callback to remove unwanted meta data. |
|
171 | + * |
|
172 | + * @param object $meta Meta object to check if it should be excluded or not. |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + protected function exclude_internal_meta_keys( $meta ) { |
|
176 | + return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' ); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Gets a list of props and meta keys that need updated based on change state |
|
181 | + * or if they are present in the database or not. |
|
182 | + * |
|
183 | + * @param GetPaid_Data $object The GetPaid_Data object. |
|
184 | + * @param array $meta_key_to_props A mapping of meta keys => prop names. |
|
185 | + * @param string $meta_type The internal WP meta type (post, user, etc). |
|
186 | + * @return array A mapping of meta keys => prop names, filtered by ones that should be updated. |
|
187 | + */ |
|
188 | + protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) { |
|
189 | + $props_to_update = array(); |
|
190 | + $changed_props = $object->get_changes(); |
|
191 | + |
|
192 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
193 | + foreach ( $meta_key_to_props as $meta_key => $prop ) { |
|
194 | + if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) { |
|
195 | + $props_to_update[ $meta_key ] = $prop; |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + return $props_to_update; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Read object data. |
|
204 | + * |
|
205 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
206 | + * @param WP_Post $post_object Post object. |
|
207 | + * @since 1.0.19 |
|
208 | + */ |
|
209 | + protected function read_object_data( &$object, $post_object ) { |
|
210 | + $id = $object->get_id(); |
|
211 | + $props = array(); |
|
212 | + |
|
213 | + foreach ( $this->meta_key_to_props as $meta_key => $prop ) { |
|
214 | + $props[ $prop ] = get_post_meta( $id, $meta_key, true ); |
|
215 | + } |
|
216 | + |
|
217 | + // Set object properties. |
|
218 | + $object->set_props( $props ); |
|
219 | + |
|
220 | + // Gets extra data associated with the object if needed. |
|
221 | + foreach ( $object->get_extra_data_keys() as $key ) { |
|
222 | + $function = 'set_' . $key; |
|
223 | + if ( is_callable( array( $object, $function ) ) ) { |
|
224 | + $object->{$function}( get_post_meta( $object->get_id(), $key, true ) ); |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class. |
|
231 | + * |
|
232 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
233 | + * @since 1.0.19 |
|
234 | + */ |
|
235 | + protected function update_post_meta( &$object ) { |
|
236 | + |
|
237 | + $updated_props = array(); |
|
238 | + $props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props ); |
|
239 | + $object_type = $object->get_object_type(); |
|
240 | + |
|
241 | + foreach ( $props_to_update as $meta_key => $prop ) { |
|
242 | + $value = $object->{"get_$prop"}( 'edit' ); |
|
243 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
244 | + |
|
245 | + $updated = $this->update_or_delete_post_meta( $object, $meta_key, $value ); |
|
246 | + |
|
247 | + if ( $updated ) { |
|
248 | + $updated_props[] = $prop; |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props ); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Update meta data in, or delete it from, the database. |
|
257 | + * |
|
258 | + * Avoids storing meta when it's either an empty string or empty array or null. |
|
259 | + * Other empty values such as numeric 0 should still be stored. |
|
260 | + * Data-stores can force meta to exist using `must_exist_meta_keys`. |
|
261 | + * |
|
262 | + * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist. |
|
263 | + * |
|
264 | + * @param GetPaid_Data $object The GetPaid_Data object. |
|
265 | + * @param string $meta_key Meta key to update. |
|
266 | + * @param mixed $meta_value Value to save. |
|
267 | + * |
|
268 | + * @since 1.0.19 Added to prevent empty meta being stored unless required. |
|
269 | + * |
|
270 | + * @return bool True if updated/deleted. |
|
271 | + */ |
|
272 | + protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) { |
|
273 | + if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { |
|
274 | + $updated = delete_post_meta( $object->get_id(), $meta_key ); |
|
275 | + } else { |
|
276 | + $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value ); |
|
277 | + } |
|
278 | + |
|
279 | + return (bool) $updated; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Return list of internal meta keys. |
|
284 | + * |
|
285 | + * @since 1.0.19 |
|
286 | + * @return array |
|
287 | + */ |
|
288 | + public function get_internal_meta_keys() { |
|
289 | + return $this->internal_meta_keys; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Clear any caches. |
|
294 | + * |
|
295 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
296 | + * @since 1.0.19 |
|
297 | + */ |
|
298 | + protected function clear_caches( &$object ) { |
|
299 | + clean_post_cache( $object->get_id() ); |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Method to delete a data object from the database. |
|
304 | + * |
|
305 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
306 | + * @param array $args Array of args to pass to the delete method. |
|
307 | + * |
|
308 | + * @return void |
|
309 | + */ |
|
310 | + public function delete( &$object, $args = array() ) { |
|
311 | + $id = $object->get_id(); |
|
312 | + $object_type = $object->get_object_type(); |
|
313 | + |
|
314 | + if ( 'invoice' == $object_type ) { |
|
315 | + $object_type = $object->get_type(); |
|
316 | + } |
|
317 | + |
|
318 | + $args = wp_parse_args( |
|
319 | + $args, |
|
320 | + array( |
|
321 | + 'force_delete' => false, |
|
322 | + ) |
|
323 | + ); |
|
324 | + |
|
325 | + if ( ! $id ) { |
|
326 | + return; |
|
327 | + } |
|
328 | + |
|
329 | + if ( $args['force_delete'] ) { |
|
330 | + wp_delete_post( $id, true ); |
|
331 | + $object->set_id( 0 ); |
|
332 | + do_action( "getpaid_delete_$object_type", $id ); |
|
333 | + } else { |
|
334 | + wp_trash_post( $id ); |
|
335 | + $object->set_status( 'trash' ); |
|
336 | + do_action( "getpaid_trash_$object_type", $id ); |
|
337 | + } |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Get the status to save to the post object. |
|
342 | + * |
|
343 | + * |
|
344 | + * @since 1.0.19 |
|
345 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
346 | + * @return string |
|
347 | + */ |
|
348 | + protected function get_post_status( $object ) { |
|
349 | + $object_status = $object->get_status( 'edit' ); |
|
350 | + $object_type = $object->get_object_type(); |
|
351 | + |
|
352 | + if ( ! $object_status ) { |
|
353 | + $object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' ); |
|
354 | + } |
|
355 | + |
|
356 | + return $object_status; |
|
357 | + } |
|
358 | 358 | |
359 | 359 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.19 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Data_Store_WP class. |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param GetPaid_Data $object GetPaid_Data object. |
65 | 65 | * @return array |
66 | 66 | */ |
67 | - public function read_meta( &$object ) { |
|
67 | + public function read_meta(&$object) { |
|
68 | 68 | global $wpdb; |
69 | 69 | $db_info = $this->get_db_info(); |
70 | 70 | $raw_meta_data = $wpdb->get_results( |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | ) |
78 | 78 | ); |
79 | 79 | |
80 | - $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys ); |
|
81 | - $meta_data = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) ); |
|
82 | - return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this ); |
|
80 | + $this->internal_meta_keys = array_merge(array_map(array($this, 'prefix_key'), $object->get_data_keys()), $this->internal_meta_keys); |
|
81 | + $meta_data = array_filter($raw_meta_data, array($this, 'exclude_internal_meta_keys')); |
|
82 | + return apply_filters("getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | * @param GetPaid_Data $object GetPaid_Data object. |
90 | 90 | * @param stdClass $meta (containing at least ->id). |
91 | 91 | */ |
92 | - public function delete_meta( &$object, $meta ) { |
|
93 | - delete_metadata_by_mid( $this->meta_type, $meta->id ); |
|
92 | + public function delete_meta(&$object, $meta) { |
|
93 | + delete_metadata_by_mid($this->meta_type, $meta->id); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * @param stdClass $meta (containing ->key and ->value). |
102 | 102 | * @return int meta ID |
103 | 103 | */ |
104 | - public function add_meta( &$object, $meta ) { |
|
105 | - return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false ); |
|
104 | + public function add_meta(&$object, $meta) { |
|
105 | + return add_metadata($this->meta_type, $object->get_id(), $meta->key, is_string($meta->value) ? wp_slash($meta->value) : $meta->value, false); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param GetPaid_Data $object GetPaid_Data object. |
113 | 113 | * @param stdClass $meta (containing ->id, ->key and ->value). |
114 | 114 | */ |
115 | - public function update_meta( &$object, $meta ) { |
|
116 | - update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key ); |
|
115 | + public function update_meta(&$object, $meta) { |
|
116 | + update_metadata_by_mid($this->meta_type, $meta->id, $meta->value, $meta->key); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $table = $wpdb->prefix; |
130 | 130 | |
131 | 131 | // If we are dealing with a type of metadata that is not a core type, the table should be prefixed. |
132 | - if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) { |
|
132 | + if (!in_array($this->meta_type, array('post', 'user', 'comment', 'term'), true)) { |
|
133 | 133 | $table .= 'getpaid_'; |
134 | 134 | } |
135 | 135 | |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | $object_id_field = $this->meta_type . '_id'; |
138 | 138 | |
139 | 139 | // Figure out our field names. |
140 | - if ( 'user' === $this->meta_type ) { |
|
140 | + if ('user' === $this->meta_type) { |
|
141 | 141 | $meta_id_field = 'umeta_id'; |
142 | 142 | $table = $wpdb->usermeta; |
143 | 143 | } |
144 | 144 | |
145 | - if ( ! empty( $this->object_id_field_for_meta ) ) { |
|
145 | + if (!empty($this->object_id_field_for_meta)) { |
|
146 | 146 | $object_id_field = $this->object_id_field_for_meta; |
147 | 147 | } |
148 | 148 | |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | * @param string $key Prefix to be added to meta keys. |
163 | 163 | * @return string |
164 | 164 | */ |
165 | - protected function prefix_key( $key ) { |
|
166 | - return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key; |
|
165 | + protected function prefix_key($key) { |
|
166 | + return '_' === substr($key, 0, 1) ? $key : '_' . $key; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * @param object $meta Meta object to check if it should be excluded or not. |
173 | 173 | * @return bool |
174 | 174 | */ |
175 | - protected function exclude_internal_meta_keys( $meta ) { |
|
176 | - return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' ); |
|
175 | + protected function exclude_internal_meta_keys($meta) { |
|
176 | + return !in_array($meta->meta_key, $this->internal_meta_keys, true) && 0 !== stripos($meta->meta_key, 'wp_'); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | * @param string $meta_type The internal WP meta type (post, user, etc). |
186 | 186 | * @return array A mapping of meta keys => prop names, filtered by ones that should be updated. |
187 | 187 | */ |
188 | - protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) { |
|
188 | + protected function get_props_to_update($object, $meta_key_to_props, $meta_type = 'post') { |
|
189 | 189 | $props_to_update = array(); |
190 | 190 | $changed_props = $object->get_changes(); |
191 | 191 | |
192 | 192 | // Props should be updated if they are a part of the $changed array or don't exist yet. |
193 | - foreach ( $meta_key_to_props as $meta_key => $prop ) { |
|
194 | - if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) { |
|
195 | - $props_to_update[ $meta_key ] = $prop; |
|
193 | + foreach ($meta_key_to_props as $meta_key => $prop) { |
|
194 | + if (array_key_exists($prop, $changed_props) || !metadata_exists($meta_type, $object->get_id(), $meta_key)) { |
|
195 | + $props_to_update[$meta_key] = $prop; |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
@@ -206,22 +206,22 @@ discard block |
||
206 | 206 | * @param WP_Post $post_object Post object. |
207 | 207 | * @since 1.0.19 |
208 | 208 | */ |
209 | - protected function read_object_data( &$object, $post_object ) { |
|
209 | + protected function read_object_data(&$object, $post_object) { |
|
210 | 210 | $id = $object->get_id(); |
211 | 211 | $props = array(); |
212 | 212 | |
213 | - foreach ( $this->meta_key_to_props as $meta_key => $prop ) { |
|
214 | - $props[ $prop ] = get_post_meta( $id, $meta_key, true ); |
|
213 | + foreach ($this->meta_key_to_props as $meta_key => $prop) { |
|
214 | + $props[$prop] = get_post_meta($id, $meta_key, true); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | // Set object properties. |
218 | - $object->set_props( $props ); |
|
218 | + $object->set_props($props); |
|
219 | 219 | |
220 | 220 | // Gets extra data associated with the object if needed. |
221 | - foreach ( $object->get_extra_data_keys() as $key ) { |
|
221 | + foreach ($object->get_extra_data_keys() as $key) { |
|
222 | 222 | $function = 'set_' . $key; |
223 | - if ( is_callable( array( $object, $function ) ) ) { |
|
224 | - $object->{$function}( get_post_meta( $object->get_id(), $key, true ) ); |
|
223 | + if (is_callable(array($object, $function))) { |
|
224 | + $object->{$function}(get_post_meta($object->get_id(), $key, true)); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | } |
@@ -232,24 +232,24 @@ discard block |
||
232 | 232 | * @param GetPaid_Data $object GetPaid_Data object. |
233 | 233 | * @since 1.0.19 |
234 | 234 | */ |
235 | - protected function update_post_meta( &$object ) { |
|
235 | + protected function update_post_meta(&$object) { |
|
236 | 236 | |
237 | 237 | $updated_props = array(); |
238 | - $props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props ); |
|
238 | + $props_to_update = $this->get_props_to_update($object, $this->meta_key_to_props); |
|
239 | 239 | $object_type = $object->get_object_type(); |
240 | 240 | |
241 | - foreach ( $props_to_update as $meta_key => $prop ) { |
|
242 | - $value = $object->{"get_$prop"}( 'edit' ); |
|
243 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
241 | + foreach ($props_to_update as $meta_key => $prop) { |
|
242 | + $value = $object->{"get_$prop"}('edit'); |
|
243 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
244 | 244 | |
245 | - $updated = $this->update_or_delete_post_meta( $object, $meta_key, $value ); |
|
245 | + $updated = $this->update_or_delete_post_meta($object, $meta_key, $value); |
|
246 | 246 | |
247 | - if ( $updated ) { |
|
247 | + if ($updated) { |
|
248 | 248 | $updated_props[] = $prop; |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | - do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props ); |
|
252 | + do_action("getpaid_{$object_type}_object_updated_props", $object, $updated_props); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return bool True if updated/deleted. |
271 | 271 | */ |
272 | - protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) { |
|
273 | - if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) { |
|
274 | - $updated = delete_post_meta( $object->get_id(), $meta_key ); |
|
272 | + protected function update_or_delete_post_meta($object, $meta_key, $meta_value) { |
|
273 | + if (in_array($meta_value, array(array(), '', null), true) && !in_array($meta_key, $this->must_exist_meta_keys, true)) { |
|
274 | + $updated = delete_post_meta($object->get_id(), $meta_key); |
|
275 | 275 | } else { |
276 | - $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value ); |
|
276 | + $updated = update_post_meta($object->get_id(), $meta_key, $meta_value); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | return (bool) $updated; |
@@ -295,8 +295,8 @@ discard block |
||
295 | 295 | * @param GetPaid_Data $object GetPaid_Data object. |
296 | 296 | * @since 1.0.19 |
297 | 297 | */ |
298 | - protected function clear_caches( &$object ) { |
|
299 | - clean_post_cache( $object->get_id() ); |
|
298 | + protected function clear_caches(&$object) { |
|
299 | + clean_post_cache($object->get_id()); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -307,33 +307,33 @@ discard block |
||
307 | 307 | * |
308 | 308 | * @return void |
309 | 309 | */ |
310 | - public function delete( &$object, $args = array() ) { |
|
310 | + public function delete(&$object, $args = array()) { |
|
311 | 311 | $id = $object->get_id(); |
312 | 312 | $object_type = $object->get_object_type(); |
313 | 313 | |
314 | - if ( 'invoice' == $object_type ) { |
|
314 | + if ('invoice' == $object_type) { |
|
315 | 315 | $object_type = $object->get_type(); |
316 | 316 | } |
317 | 317 | |
318 | - $args = wp_parse_args( |
|
318 | + $args = wp_parse_args( |
|
319 | 319 | $args, |
320 | 320 | array( |
321 | 321 | 'force_delete' => false, |
322 | 322 | ) |
323 | 323 | ); |
324 | 324 | |
325 | - if ( ! $id ) { |
|
325 | + if (!$id) { |
|
326 | 326 | return; |
327 | 327 | } |
328 | 328 | |
329 | - if ( $args['force_delete'] ) { |
|
330 | - wp_delete_post( $id, true ); |
|
331 | - $object->set_id( 0 ); |
|
332 | - do_action( "getpaid_delete_$object_type", $id ); |
|
329 | + if ($args['force_delete']) { |
|
330 | + wp_delete_post($id, true); |
|
331 | + $object->set_id(0); |
|
332 | + do_action("getpaid_delete_$object_type", $id); |
|
333 | 333 | } else { |
334 | - wp_trash_post( $id ); |
|
335 | - $object->set_status( 'trash' ); |
|
336 | - do_action( "getpaid_trash_$object_type", $id ); |
|
334 | + wp_trash_post($id); |
|
335 | + $object->set_status('trash'); |
|
336 | + do_action("getpaid_trash_$object_type", $id); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
@@ -345,12 +345,12 @@ discard block |
||
345 | 345 | * @param GetPaid_Data $object GetPaid_Data object. |
346 | 346 | * @return string |
347 | 347 | */ |
348 | - protected function get_post_status( $object ) { |
|
349 | - $object_status = $object->get_status( 'edit' ); |
|
348 | + protected function get_post_status($object) { |
|
349 | + $object_status = $object->get_status('edit'); |
|
350 | 350 | $object_type = $object->get_object_type(); |
351 | 351 | |
352 | - if ( ! $object_status ) { |
|
353 | - $object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' ); |
|
352 | + if (!$object_status) { |
|
353 | + $object_status = apply_filters("getpaid_default_{$object_type}_status", 'draft'); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | return $object_status; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,179 +14,179 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Payment_Form_Data_Store extends GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Data stored in meta keys, but not considered "meta" for a form. |
|
19 | - * |
|
20 | - * @since 1.0.19 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $internal_meta_keys = array( |
|
24 | - 'wpinv_form_elements', |
|
25 | - 'wpinv_form_items', |
|
26 | - 'wpinv_form_earned', |
|
27 | - 'wpinv_form_refunded', |
|
28 | - 'wpinv_form_cancelled', |
|
29 | - 'wpinv_form_failed' |
|
30 | - ); |
|
31 | - |
|
32 | - /** |
|
33 | - * A map of meta keys to data props. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $meta_key_to_props = array( |
|
40 | - 'wpinv_form_elements' => 'elements', |
|
41 | - 'wpinv_form_items' => 'items', |
|
42 | - 'wpinv_form_earned' => 'earned', |
|
43 | - 'wpinv_form_refunded' => 'refunded', |
|
44 | - 'wpinv_form_cancelled' => 'cancelled', |
|
45 | - 'wpinv_form_failed' => 'failed', |
|
46 | - ); |
|
47 | - |
|
48 | - /* |
|
17 | + /** |
|
18 | + * Data stored in meta keys, but not considered "meta" for a form. |
|
19 | + * |
|
20 | + * @since 1.0.19 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $internal_meta_keys = array( |
|
24 | + 'wpinv_form_elements', |
|
25 | + 'wpinv_form_items', |
|
26 | + 'wpinv_form_earned', |
|
27 | + 'wpinv_form_refunded', |
|
28 | + 'wpinv_form_cancelled', |
|
29 | + 'wpinv_form_failed' |
|
30 | + ); |
|
31 | + |
|
32 | + /** |
|
33 | + * A map of meta keys to data props. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $meta_key_to_props = array( |
|
40 | + 'wpinv_form_elements' => 'elements', |
|
41 | + 'wpinv_form_items' => 'items', |
|
42 | + 'wpinv_form_earned' => 'earned', |
|
43 | + 'wpinv_form_refunded' => 'refunded', |
|
44 | + 'wpinv_form_cancelled' => 'cancelled', |
|
45 | + 'wpinv_form_failed' => 'failed', |
|
46 | + ); |
|
47 | + |
|
48 | + /* |
|
49 | 49 | |-------------------------------------------------------------------------- |
50 | 50 | | CRUD Methods |
51 | 51 | |-------------------------------------------------------------------------- |
52 | 52 | */ |
53 | 53 | |
54 | - /** |
|
55 | - * Method to create a new form in the database. |
|
56 | - * |
|
57 | - * @param GetPaid_Payment_Form $form Form object. |
|
58 | - */ |
|
59 | - public function create( &$form ) { |
|
60 | - $form->set_version( WPINV_VERSION ); |
|
61 | - $form->set_date_created( current_time('mysql') ); |
|
62 | - |
|
63 | - // Create a new post. |
|
64 | - $id = wp_insert_post( |
|
65 | - apply_filters( |
|
66 | - 'getpaid_new_payment_form_data', |
|
67 | - array( |
|
68 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
69 | - 'post_type' => 'wpi_payment_form', |
|
70 | - 'post_status' => $this->get_post_status( $form ), |
|
71 | - 'ping_status' => 'closed', |
|
72 | - 'post_author' => $form->get_author( 'edit' ), |
|
73 | - 'post_title' => $form->get_name( 'edit' ), |
|
74 | - ) |
|
75 | - ), |
|
76 | - true |
|
77 | - ); |
|
78 | - |
|
79 | - if ( $id && ! is_wp_error( $id ) ) { |
|
80 | - $form->set_id( $id ); |
|
81 | - $this->update_post_meta( $form ); |
|
82 | - $form->save_meta_data(); |
|
83 | - $form->apply_changes(); |
|
84 | - $this->clear_caches( $form ); |
|
85 | - do_action( 'getpaid_create_payment_form', $form->get_id(), $form ); |
|
86 | - return true; |
|
87 | - } |
|
88 | - |
|
89 | - if ( is_wp_error( $id ) ) { |
|
90 | - $form->last_error = $id->get_error_message(); |
|
91 | - } |
|
92 | - |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Method to read a form from the database. |
|
98 | - * |
|
99 | - * @param GetPaid_Payment_Form $form Form object. |
|
100 | - * |
|
101 | - */ |
|
102 | - public function read( &$form ) { |
|
103 | - |
|
104 | - $form->set_defaults(); |
|
105 | - $form_object = get_post( $form->get_id() ); |
|
106 | - |
|
107 | - if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
108 | - $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
109 | - $form->set_id( 0 ); |
|
110 | - return false; |
|
111 | - } |
|
112 | - |
|
113 | - $form->set_props( |
|
114 | - array( |
|
115 | - 'date_created' => 0 < $form_object->post_date ? $form_object->post_date : null, |
|
116 | - 'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null, |
|
117 | - 'status' => $form_object->post_status, |
|
118 | - 'name' => $form_object->post_title, |
|
119 | - 'author' => $form_object->post_author, |
|
120 | - ) |
|
121 | - ); |
|
122 | - |
|
123 | - $this->read_object_data( $form, $form_object ); |
|
124 | - $form->read_meta_data(); |
|
125 | - $form->set_object_read( true ); |
|
126 | - do_action( 'getpaid_read_payment_form', $form->get_id(), $form ); |
|
127 | - |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Method to update a form in the database. |
|
132 | - * |
|
133 | - * @param GetPaid_Payment_Form $form Form object. |
|
134 | - */ |
|
135 | - public function update( &$form ) { |
|
136 | - $form->save_meta_data(); |
|
137 | - $form->set_version( WPINV_VERSION ); |
|
138 | - |
|
139 | - if ( null === $form->get_date_created( 'edit' ) ) { |
|
140 | - $form->set_date_created( current_time('mysql') ); |
|
141 | - } |
|
142 | - |
|
143 | - // Grab the current status so we can compare. |
|
144 | - $previous_status = get_post_status( $form->get_id() ); |
|
145 | - |
|
146 | - $changes = $form->get_changes(); |
|
147 | - |
|
148 | - // Only update the post when the post data changes. |
|
149 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
150 | - $post_data = array( |
|
151 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
152 | - 'post_status' => $form->get_status( 'edit' ), |
|
153 | - 'post_title' => $form->get_name( 'edit' ), |
|
154 | - 'post_author' => $form->get_author( 'edit' ), |
|
155 | - 'post_modified' => $form->get_date_modified( 'edit' ), |
|
156 | - ); |
|
157 | - |
|
158 | - /** |
|
159 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
160 | - * to update data, since wp_update_post spawns more calls to the |
|
161 | - * save_post action. |
|
162 | - * |
|
163 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
164 | - * or an update purely from CRUD. |
|
165 | - */ |
|
166 | - if ( doing_action( 'save_post' ) ) { |
|
167 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
168 | - clean_post_cache( $form->get_id() ); |
|
169 | - } else { |
|
170 | - wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
171 | - } |
|
172 | - $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
173 | - } |
|
174 | - $this->update_post_meta( $form ); |
|
175 | - $form->apply_changes(); |
|
176 | - $this->clear_caches( $form ); |
|
177 | - |
|
178 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
179 | - $new_status = $form->get_status( 'edit' ); |
|
180 | - |
|
181 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
182 | - do_action( 'getpaid_new_payment_form', $form->get_id(), $form ); |
|
183 | - } else { |
|
184 | - do_action( 'getpaid_update_payment_form', $form->get_id(), $form ); |
|
185 | - } |
|
186 | - |
|
187 | - } |
|
188 | - |
|
189 | - /* |
|
54 | + /** |
|
55 | + * Method to create a new form in the database. |
|
56 | + * |
|
57 | + * @param GetPaid_Payment_Form $form Form object. |
|
58 | + */ |
|
59 | + public function create( &$form ) { |
|
60 | + $form->set_version( WPINV_VERSION ); |
|
61 | + $form->set_date_created( current_time('mysql') ); |
|
62 | + |
|
63 | + // Create a new post. |
|
64 | + $id = wp_insert_post( |
|
65 | + apply_filters( |
|
66 | + 'getpaid_new_payment_form_data', |
|
67 | + array( |
|
68 | + 'post_date' => $form->get_date_created( 'edit' ), |
|
69 | + 'post_type' => 'wpi_payment_form', |
|
70 | + 'post_status' => $this->get_post_status( $form ), |
|
71 | + 'ping_status' => 'closed', |
|
72 | + 'post_author' => $form->get_author( 'edit' ), |
|
73 | + 'post_title' => $form->get_name( 'edit' ), |
|
74 | + ) |
|
75 | + ), |
|
76 | + true |
|
77 | + ); |
|
78 | + |
|
79 | + if ( $id && ! is_wp_error( $id ) ) { |
|
80 | + $form->set_id( $id ); |
|
81 | + $this->update_post_meta( $form ); |
|
82 | + $form->save_meta_data(); |
|
83 | + $form->apply_changes(); |
|
84 | + $this->clear_caches( $form ); |
|
85 | + do_action( 'getpaid_create_payment_form', $form->get_id(), $form ); |
|
86 | + return true; |
|
87 | + } |
|
88 | + |
|
89 | + if ( is_wp_error( $id ) ) { |
|
90 | + $form->last_error = $id->get_error_message(); |
|
91 | + } |
|
92 | + |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Method to read a form from the database. |
|
98 | + * |
|
99 | + * @param GetPaid_Payment_Form $form Form object. |
|
100 | + * |
|
101 | + */ |
|
102 | + public function read( &$form ) { |
|
103 | + |
|
104 | + $form->set_defaults(); |
|
105 | + $form_object = get_post( $form->get_id() ); |
|
106 | + |
|
107 | + if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
108 | + $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
109 | + $form->set_id( 0 ); |
|
110 | + return false; |
|
111 | + } |
|
112 | + |
|
113 | + $form->set_props( |
|
114 | + array( |
|
115 | + 'date_created' => 0 < $form_object->post_date ? $form_object->post_date : null, |
|
116 | + 'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null, |
|
117 | + 'status' => $form_object->post_status, |
|
118 | + 'name' => $form_object->post_title, |
|
119 | + 'author' => $form_object->post_author, |
|
120 | + ) |
|
121 | + ); |
|
122 | + |
|
123 | + $this->read_object_data( $form, $form_object ); |
|
124 | + $form->read_meta_data(); |
|
125 | + $form->set_object_read( true ); |
|
126 | + do_action( 'getpaid_read_payment_form', $form->get_id(), $form ); |
|
127 | + |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Method to update a form in the database. |
|
132 | + * |
|
133 | + * @param GetPaid_Payment_Form $form Form object. |
|
134 | + */ |
|
135 | + public function update( &$form ) { |
|
136 | + $form->save_meta_data(); |
|
137 | + $form->set_version( WPINV_VERSION ); |
|
138 | + |
|
139 | + if ( null === $form->get_date_created( 'edit' ) ) { |
|
140 | + $form->set_date_created( current_time('mysql') ); |
|
141 | + } |
|
142 | + |
|
143 | + // Grab the current status so we can compare. |
|
144 | + $previous_status = get_post_status( $form->get_id() ); |
|
145 | + |
|
146 | + $changes = $form->get_changes(); |
|
147 | + |
|
148 | + // Only update the post when the post data changes. |
|
149 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
150 | + $post_data = array( |
|
151 | + 'post_date' => $form->get_date_created( 'edit' ), |
|
152 | + 'post_status' => $form->get_status( 'edit' ), |
|
153 | + 'post_title' => $form->get_name( 'edit' ), |
|
154 | + 'post_author' => $form->get_author( 'edit' ), |
|
155 | + 'post_modified' => $form->get_date_modified( 'edit' ), |
|
156 | + ); |
|
157 | + |
|
158 | + /** |
|
159 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
160 | + * to update data, since wp_update_post spawns more calls to the |
|
161 | + * save_post action. |
|
162 | + * |
|
163 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
164 | + * or an update purely from CRUD. |
|
165 | + */ |
|
166 | + if ( doing_action( 'save_post' ) ) { |
|
167 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
168 | + clean_post_cache( $form->get_id() ); |
|
169 | + } else { |
|
170 | + wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
171 | + } |
|
172 | + $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
173 | + } |
|
174 | + $this->update_post_meta( $form ); |
|
175 | + $form->apply_changes(); |
|
176 | + $this->clear_caches( $form ); |
|
177 | + |
|
178 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
179 | + $new_status = $form->get_status( 'edit' ); |
|
180 | + |
|
181 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
182 | + do_action( 'getpaid_new_payment_form', $form->get_id(), $form ); |
|
183 | + } else { |
|
184 | + do_action( 'getpaid_update_payment_form', $form->get_id(), $form ); |
|
185 | + } |
|
186 | + |
|
187 | + } |
|
188 | + |
|
189 | + /* |
|
190 | 190 | |-------------------------------------------------------------------------- |
191 | 191 | | Additional Methods |
192 | 192 | |-------------------------------------------------------------------------- |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * GetPaid_Payment_Form_Data_Store class file. |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -56,37 +56,37 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @param GetPaid_Payment_Form $form Form object. |
58 | 58 | */ |
59 | - public function create( &$form ) { |
|
60 | - $form->set_version( WPINV_VERSION ); |
|
61 | - $form->set_date_created( current_time('mysql') ); |
|
59 | + public function create(&$form) { |
|
60 | + $form->set_version(WPINV_VERSION); |
|
61 | + $form->set_date_created(current_time('mysql')); |
|
62 | 62 | |
63 | 63 | // Create a new post. |
64 | 64 | $id = wp_insert_post( |
65 | 65 | apply_filters( |
66 | 66 | 'getpaid_new_payment_form_data', |
67 | 67 | array( |
68 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
68 | + 'post_date' => $form->get_date_created('edit'), |
|
69 | 69 | 'post_type' => 'wpi_payment_form', |
70 | - 'post_status' => $this->get_post_status( $form ), |
|
70 | + 'post_status' => $this->get_post_status($form), |
|
71 | 71 | 'ping_status' => 'closed', |
72 | - 'post_author' => $form->get_author( 'edit' ), |
|
73 | - 'post_title' => $form->get_name( 'edit' ), |
|
72 | + 'post_author' => $form->get_author('edit'), |
|
73 | + 'post_title' => $form->get_name('edit'), |
|
74 | 74 | ) |
75 | 75 | ), |
76 | 76 | true |
77 | 77 | ); |
78 | 78 | |
79 | - if ( $id && ! is_wp_error( $id ) ) { |
|
80 | - $form->set_id( $id ); |
|
81 | - $this->update_post_meta( $form ); |
|
79 | + if ($id && !is_wp_error($id)) { |
|
80 | + $form->set_id($id); |
|
81 | + $this->update_post_meta($form); |
|
82 | 82 | $form->save_meta_data(); |
83 | 83 | $form->apply_changes(); |
84 | - $this->clear_caches( $form ); |
|
85 | - do_action( 'getpaid_create_payment_form', $form->get_id(), $form ); |
|
84 | + $this->clear_caches($form); |
|
85 | + do_action('getpaid_create_payment_form', $form->get_id(), $form); |
|
86 | 86 | return true; |
87 | 87 | } |
88 | 88 | |
89 | - if ( is_wp_error( $id ) ) { |
|
89 | + if (is_wp_error($id)) { |
|
90 | 90 | $form->last_error = $id->get_error_message(); |
91 | 91 | } |
92 | 92 | |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | * @param GetPaid_Payment_Form $form Form object. |
100 | 100 | * |
101 | 101 | */ |
102 | - public function read( &$form ) { |
|
102 | + public function read(&$form) { |
|
103 | 103 | |
104 | 104 | $form->set_defaults(); |
105 | - $form_object = get_post( $form->get_id() ); |
|
105 | + $form_object = get_post($form->get_id()); |
|
106 | 106 | |
107 | - if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
108 | - $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
109 | - $form->set_id( 0 ); |
|
107 | + if (!$form->get_id() || !$form_object || $form_object->post_type != 'wpi_payment_form') { |
|
108 | + $form->last_error = __('Invalid form.', 'invoicing'); |
|
109 | + $form->set_id(0); |
|
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | ) |
121 | 121 | ); |
122 | 122 | |
123 | - $this->read_object_data( $form, $form_object ); |
|
123 | + $this->read_object_data($form, $form_object); |
|
124 | 124 | $form->read_meta_data(); |
125 | - $form->set_object_read( true ); |
|
126 | - do_action( 'getpaid_read_payment_form', $form->get_id(), $form ); |
|
125 | + $form->set_object_read(true); |
|
126 | + do_action('getpaid_read_payment_form', $form->get_id(), $form); |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
@@ -132,27 +132,27 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @param GetPaid_Payment_Form $form Form object. |
134 | 134 | */ |
135 | - public function update( &$form ) { |
|
135 | + public function update(&$form) { |
|
136 | 136 | $form->save_meta_data(); |
137 | - $form->set_version( WPINV_VERSION ); |
|
137 | + $form->set_version(WPINV_VERSION); |
|
138 | 138 | |
139 | - if ( null === $form->get_date_created( 'edit' ) ) { |
|
140 | - $form->set_date_created( current_time('mysql') ); |
|
139 | + if (null === $form->get_date_created('edit')) { |
|
140 | + $form->set_date_created(current_time('mysql')); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | // Grab the current status so we can compare. |
144 | - $previous_status = get_post_status( $form->get_id() ); |
|
144 | + $previous_status = get_post_status($form->get_id()); |
|
145 | 145 | |
146 | 146 | $changes = $form->get_changes(); |
147 | 147 | |
148 | 148 | // Only update the post when the post data changes. |
149 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
149 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author'), array_keys($changes))) { |
|
150 | 150 | $post_data = array( |
151 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
152 | - 'post_status' => $form->get_status( 'edit' ), |
|
153 | - 'post_title' => $form->get_name( 'edit' ), |
|
154 | - 'post_author' => $form->get_author( 'edit' ), |
|
155 | - 'post_modified' => $form->get_date_modified( 'edit' ), |
|
151 | + 'post_date' => $form->get_date_created('edit'), |
|
152 | + 'post_status' => $form->get_status('edit'), |
|
153 | + 'post_title' => $form->get_name('edit'), |
|
154 | + 'post_author' => $form->get_author('edit'), |
|
155 | + 'post_modified' => $form->get_date_modified('edit'), |
|
156 | 156 | ); |
157 | 157 | |
158 | 158 | /** |
@@ -163,25 +163,25 @@ discard block |
||
163 | 163 | * This ensures hooks are fired by either WP itself (admin screen save), |
164 | 164 | * or an update purely from CRUD. |
165 | 165 | */ |
166 | - if ( doing_action( 'save_post' ) ) { |
|
167 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
168 | - clean_post_cache( $form->get_id() ); |
|
166 | + if (doing_action('save_post')) { |
|
167 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $form->get_id())); |
|
168 | + clean_post_cache($form->get_id()); |
|
169 | 169 | } else { |
170 | - wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
170 | + wp_update_post(array_merge(array('ID' => $form->get_id()), $post_data)); |
|
171 | 171 | } |
172 | - $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
172 | + $form->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
173 | 173 | } |
174 | - $this->update_post_meta( $form ); |
|
174 | + $this->update_post_meta($form); |
|
175 | 175 | $form->apply_changes(); |
176 | - $this->clear_caches( $form ); |
|
176 | + $this->clear_caches($form); |
|
177 | 177 | |
178 | 178 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
179 | - $new_status = $form->get_status( 'edit' ); |
|
179 | + $new_status = $form->get_status('edit'); |
|
180 | 180 | |
181 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
182 | - do_action( 'getpaid_new_payment_form', $form->get_id(), $form ); |
|
181 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
182 | + do_action('getpaid_new_payment_form', $form->get_id(), $form); |
|
183 | 183 | } else { |
184 | - do_action( 'getpaid_update_payment_form', $form->get_id(), $form ); |
|
184 | + do_action('getpaid_update_payment_form', $form->get_id(), $form); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,196 +15,196 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Discount_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 | - '_wpi_discount_code', |
|
26 | - '_wpi_discount_amount', |
|
27 | - '_wpi_discount_start', |
|
28 | - '_wpi_discount_expiration', |
|
29 | - '_wpi_discount_type', |
|
30 | - '_wpi_discount_uses', |
|
31 | - '_wpi_discount_is_single_use', |
|
32 | - '_wpi_discount_items', |
|
33 | - '_wpi_discount_excluded_items', |
|
34 | - '_wpi_discount_max_uses', |
|
35 | - '_wpi_discount_is_recurring', |
|
36 | - '_wpi_discount_min_total', |
|
37 | - '_wpi_discount_max_total', |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
41 | - * A map of meta keys to data props. |
|
42 | - * |
|
43 | - * @since 1.0.19 |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $meta_key_to_props = array( |
|
48 | - '_wpi_discount_code' => 'code', |
|
49 | - '_wpi_discount_amount' => 'amount', |
|
50 | - '_wpi_discount_start' => 'start', |
|
51 | - '_wpi_discount_expiration' => 'expiration', |
|
52 | - '_wpi_discount_type' => 'type', |
|
53 | - '_wpi_discount_uses' => 'uses', |
|
54 | - '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | - '_wpi_discount_items' => 'items', |
|
56 | - '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | - '_wpi_discount_max_uses' => 'max_uses', |
|
58 | - '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | - '_wpi_discount_min_total' => 'min_total', |
|
60 | - '_wpi_discount_max_total' => 'max_total', |
|
61 | - ); |
|
62 | - |
|
63 | - /* |
|
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 | + '_wpi_discount_code', |
|
26 | + '_wpi_discount_amount', |
|
27 | + '_wpi_discount_start', |
|
28 | + '_wpi_discount_expiration', |
|
29 | + '_wpi_discount_type', |
|
30 | + '_wpi_discount_uses', |
|
31 | + '_wpi_discount_is_single_use', |
|
32 | + '_wpi_discount_items', |
|
33 | + '_wpi_discount_excluded_items', |
|
34 | + '_wpi_discount_max_uses', |
|
35 | + '_wpi_discount_is_recurring', |
|
36 | + '_wpi_discount_min_total', |
|
37 | + '_wpi_discount_max_total', |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | + * A map of meta keys to data props. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $meta_key_to_props = array( |
|
48 | + '_wpi_discount_code' => 'code', |
|
49 | + '_wpi_discount_amount' => 'amount', |
|
50 | + '_wpi_discount_start' => 'start', |
|
51 | + '_wpi_discount_expiration' => 'expiration', |
|
52 | + '_wpi_discount_type' => 'type', |
|
53 | + '_wpi_discount_uses' => 'uses', |
|
54 | + '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | + '_wpi_discount_items' => 'items', |
|
56 | + '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | + '_wpi_discount_max_uses' => 'max_uses', |
|
58 | + '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | + '_wpi_discount_min_total' => 'min_total', |
|
60 | + '_wpi_discount_max_total' => 'max_total', |
|
61 | + ); |
|
62 | + |
|
63 | + /* |
|
64 | 64 | |-------------------------------------------------------------------------- |
65 | 65 | | CRUD Methods |
66 | 66 | |-------------------------------------------------------------------------- |
67 | 67 | */ |
68 | 68 | |
69 | - /** |
|
70 | - * Method to create a new discount in the database. |
|
71 | - * |
|
72 | - * @param WPInv_Discount $discount Discount object. |
|
73 | - */ |
|
74 | - public function create( &$discount ) { |
|
75 | - $discount->set_version( WPINV_VERSION ); |
|
76 | - $discount->set_date_created( current_time('mysql') ); |
|
77 | - |
|
78 | - // Create a new post. |
|
79 | - $id = wp_insert_post( |
|
80 | - apply_filters( |
|
81 | - 'getpaid_new_discount_data', |
|
82 | - array( |
|
83 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
84 | - 'post_type' => 'wpi_discount', |
|
85 | - 'post_status' => $this->get_post_status( $discount ), |
|
86 | - 'ping_status' => 'closed', |
|
87 | - 'post_author' => $discount->get_author( 'edit' ), |
|
88 | - 'post_title' => $discount->get_name( 'edit' ), |
|
89 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
90 | - ) |
|
91 | - ), |
|
92 | - true |
|
93 | - ); |
|
94 | - |
|
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $discount->set_id( $id ); |
|
97 | - $this->update_post_meta( $discount ); |
|
98 | - $discount->save_meta_data(); |
|
99 | - $discount->apply_changes(); |
|
100 | - $this->clear_caches( $discount ); |
|
101 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
102 | - return true; |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_wp_error( $id ) ) { |
|
106 | - $discount->last_error = $id->get_error_message(); |
|
107 | - } |
|
108 | - |
|
109 | - return false; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Method to read a discount from the database. |
|
114 | - * |
|
115 | - * @param WPInv_Discount $discount Discount object. |
|
116 | - * |
|
117 | - */ |
|
118 | - public function read( &$discount ) { |
|
119 | - |
|
120 | - $discount->set_defaults(); |
|
121 | - $discount_object = get_post( $discount->get_id() ); |
|
122 | - |
|
123 | - if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
124 | - $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
125 | - $discount->set_id( 0 ); |
|
126 | - return false; |
|
127 | - } |
|
128 | - |
|
129 | - $discount->set_props( |
|
130 | - array( |
|
131 | - 'date_created' => 0 < $discount_object->post_date ? $discount_object->post_date : null, |
|
132 | - 'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null, |
|
133 | - 'status' => $discount_object->post_status, |
|
134 | - 'name' => $discount_object->post_title, |
|
135 | - 'author' => $discount_object->post_author, |
|
136 | - 'description' => $discount_object->post_excerpt, |
|
137 | - ) |
|
138 | - ); |
|
139 | - |
|
140 | - $this->read_object_data( $discount, $discount_object ); |
|
141 | - $discount->read_meta_data(); |
|
142 | - $discount->set_object_read( true ); |
|
143 | - do_action( 'getpaid_read_discount', $discount->get_id(), $discount ); |
|
144 | - |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Method to update a discount in the database. |
|
149 | - * |
|
150 | - * @param WPInv_Discount $discount Discount object. |
|
151 | - */ |
|
152 | - public function update( &$discount ) { |
|
153 | - $discount->save_meta_data(); |
|
154 | - $discount->set_version( WPINV_VERSION ); |
|
155 | - |
|
156 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
157 | - $discount->set_date_created( current_time('mysql') ); |
|
158 | - } |
|
159 | - |
|
160 | - // Grab the current status so we can compare. |
|
161 | - $previous_status = get_post_status( $discount->get_id() ); |
|
162 | - |
|
163 | - $changes = $discount->get_changes(); |
|
164 | - |
|
165 | - // Only update the post when the post data changes. |
|
166 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
167 | - $post_data = array( |
|
168 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
169 | - 'post_status' => $discount->get_status( 'edit' ), |
|
170 | - 'post_title' => $discount->get_name( 'edit' ), |
|
171 | - 'post_author' => $discount->get_author( 'edit' ), |
|
172 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
173 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
174 | - ); |
|
175 | - |
|
176 | - /** |
|
177 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
178 | - * to update data, since wp_update_post spawns more calls to the |
|
179 | - * save_post action. |
|
180 | - * |
|
181 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
182 | - * or an update purely from CRUD. |
|
183 | - */ |
|
184 | - if ( doing_action( 'save_post' ) ) { |
|
185 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
186 | - clean_post_cache( $discount->get_id() ); |
|
187 | - } else { |
|
188 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
189 | - } |
|
190 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
191 | - } |
|
192 | - $this->update_post_meta( $discount ); |
|
193 | - $discount->apply_changes(); |
|
194 | - $this->clear_caches( $discount ); |
|
195 | - |
|
196 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
197 | - $new_status = $discount->get_status( 'edit' ); |
|
198 | - |
|
199 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
200 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
201 | - } else { |
|
202 | - do_action( 'getpaid_update_discount', $discount->get_id(), $discount ); |
|
203 | - } |
|
204 | - |
|
205 | - } |
|
206 | - |
|
207 | - /* |
|
69 | + /** |
|
70 | + * Method to create a new discount in the database. |
|
71 | + * |
|
72 | + * @param WPInv_Discount $discount Discount object. |
|
73 | + */ |
|
74 | + public function create( &$discount ) { |
|
75 | + $discount->set_version( WPINV_VERSION ); |
|
76 | + $discount->set_date_created( current_time('mysql') ); |
|
77 | + |
|
78 | + // Create a new post. |
|
79 | + $id = wp_insert_post( |
|
80 | + apply_filters( |
|
81 | + 'getpaid_new_discount_data', |
|
82 | + array( |
|
83 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
84 | + 'post_type' => 'wpi_discount', |
|
85 | + 'post_status' => $this->get_post_status( $discount ), |
|
86 | + 'ping_status' => 'closed', |
|
87 | + 'post_author' => $discount->get_author( 'edit' ), |
|
88 | + 'post_title' => $discount->get_name( 'edit' ), |
|
89 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
90 | + ) |
|
91 | + ), |
|
92 | + true |
|
93 | + ); |
|
94 | + |
|
95 | + if ( $id && ! is_wp_error( $id ) ) { |
|
96 | + $discount->set_id( $id ); |
|
97 | + $this->update_post_meta( $discount ); |
|
98 | + $discount->save_meta_data(); |
|
99 | + $discount->apply_changes(); |
|
100 | + $this->clear_caches( $discount ); |
|
101 | + do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
102 | + return true; |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_wp_error( $id ) ) { |
|
106 | + $discount->last_error = $id->get_error_message(); |
|
107 | + } |
|
108 | + |
|
109 | + return false; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Method to read a discount from the database. |
|
114 | + * |
|
115 | + * @param WPInv_Discount $discount Discount object. |
|
116 | + * |
|
117 | + */ |
|
118 | + public function read( &$discount ) { |
|
119 | + |
|
120 | + $discount->set_defaults(); |
|
121 | + $discount_object = get_post( $discount->get_id() ); |
|
122 | + |
|
123 | + if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
124 | + $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
125 | + $discount->set_id( 0 ); |
|
126 | + return false; |
|
127 | + } |
|
128 | + |
|
129 | + $discount->set_props( |
|
130 | + array( |
|
131 | + 'date_created' => 0 < $discount_object->post_date ? $discount_object->post_date : null, |
|
132 | + 'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null, |
|
133 | + 'status' => $discount_object->post_status, |
|
134 | + 'name' => $discount_object->post_title, |
|
135 | + 'author' => $discount_object->post_author, |
|
136 | + 'description' => $discount_object->post_excerpt, |
|
137 | + ) |
|
138 | + ); |
|
139 | + |
|
140 | + $this->read_object_data( $discount, $discount_object ); |
|
141 | + $discount->read_meta_data(); |
|
142 | + $discount->set_object_read( true ); |
|
143 | + do_action( 'getpaid_read_discount', $discount->get_id(), $discount ); |
|
144 | + |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Method to update a discount in the database. |
|
149 | + * |
|
150 | + * @param WPInv_Discount $discount Discount object. |
|
151 | + */ |
|
152 | + public function update( &$discount ) { |
|
153 | + $discount->save_meta_data(); |
|
154 | + $discount->set_version( WPINV_VERSION ); |
|
155 | + |
|
156 | + if ( null === $discount->get_date_created( 'edit' ) ) { |
|
157 | + $discount->set_date_created( current_time('mysql') ); |
|
158 | + } |
|
159 | + |
|
160 | + // Grab the current status so we can compare. |
|
161 | + $previous_status = get_post_status( $discount->get_id() ); |
|
162 | + |
|
163 | + $changes = $discount->get_changes(); |
|
164 | + |
|
165 | + // Only update the post when the post data changes. |
|
166 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
167 | + $post_data = array( |
|
168 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
169 | + 'post_status' => $discount->get_status( 'edit' ), |
|
170 | + 'post_title' => $discount->get_name( 'edit' ), |
|
171 | + 'post_author' => $discount->get_author( 'edit' ), |
|
172 | + 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
173 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
174 | + ); |
|
175 | + |
|
176 | + /** |
|
177 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
178 | + * to update data, since wp_update_post spawns more calls to the |
|
179 | + * save_post action. |
|
180 | + * |
|
181 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
182 | + * or an update purely from CRUD. |
|
183 | + */ |
|
184 | + if ( doing_action( 'save_post' ) ) { |
|
185 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
186 | + clean_post_cache( $discount->get_id() ); |
|
187 | + } else { |
|
188 | + wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
189 | + } |
|
190 | + $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
191 | + } |
|
192 | + $this->update_post_meta( $discount ); |
|
193 | + $discount->apply_changes(); |
|
194 | + $this->clear_caches( $discount ); |
|
195 | + |
|
196 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
197 | + $new_status = $discount->get_status( 'edit' ); |
|
198 | + |
|
199 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
200 | + do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
201 | + } else { |
|
202 | + do_action( 'getpaid_update_discount', $discount->get_id(), $discount ); |
|
203 | + } |
|
204 | + |
|
205 | + } |
|
206 | + |
|
207 | + /* |
|
208 | 208 | |-------------------------------------------------------------------------- |
209 | 209 | | Additional Methods |
210 | 210 | |-------------------------------------------------------------------------- |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Discount_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -71,38 +71,38 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @param WPInv_Discount $discount Discount object. |
73 | 73 | */ |
74 | - public function create( &$discount ) { |
|
75 | - $discount->set_version( WPINV_VERSION ); |
|
76 | - $discount->set_date_created( current_time('mysql') ); |
|
74 | + public function create(&$discount) { |
|
75 | + $discount->set_version(WPINV_VERSION); |
|
76 | + $discount->set_date_created(current_time('mysql')); |
|
77 | 77 | |
78 | 78 | // Create a new post. |
79 | 79 | $id = wp_insert_post( |
80 | 80 | apply_filters( |
81 | 81 | 'getpaid_new_discount_data', |
82 | 82 | array( |
83 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
83 | + 'post_date' => $discount->get_date_created('edit'), |
|
84 | 84 | 'post_type' => 'wpi_discount', |
85 | - 'post_status' => $this->get_post_status( $discount ), |
|
85 | + 'post_status' => $this->get_post_status($discount), |
|
86 | 86 | 'ping_status' => 'closed', |
87 | - 'post_author' => $discount->get_author( 'edit' ), |
|
88 | - 'post_title' => $discount->get_name( 'edit' ), |
|
89 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
87 | + 'post_author' => $discount->get_author('edit'), |
|
88 | + 'post_title' => $discount->get_name('edit'), |
|
89 | + 'post_excerpt' => $discount->get_description('edit'), |
|
90 | 90 | ) |
91 | 91 | ), |
92 | 92 | true |
93 | 93 | ); |
94 | 94 | |
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $discount->set_id( $id ); |
|
97 | - $this->update_post_meta( $discount ); |
|
95 | + if ($id && !is_wp_error($id)) { |
|
96 | + $discount->set_id($id); |
|
97 | + $this->update_post_meta($discount); |
|
98 | 98 | $discount->save_meta_data(); |
99 | 99 | $discount->apply_changes(); |
100 | - $this->clear_caches( $discount ); |
|
101 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
100 | + $this->clear_caches($discount); |
|
101 | + do_action('getpaid_new_discount', $discount->get_id(), $discount); |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_wp_error( $id ) ) { |
|
105 | + if (is_wp_error($id)) { |
|
106 | 106 | $discount->last_error = $id->get_error_message(); |
107 | 107 | } |
108 | 108 | |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | * @param WPInv_Discount $discount Discount object. |
116 | 116 | * |
117 | 117 | */ |
118 | - public function read( &$discount ) { |
|
118 | + public function read(&$discount) { |
|
119 | 119 | |
120 | 120 | $discount->set_defaults(); |
121 | - $discount_object = get_post( $discount->get_id() ); |
|
121 | + $discount_object = get_post($discount->get_id()); |
|
122 | 122 | |
123 | - if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
124 | - $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
125 | - $discount->set_id( 0 ); |
|
123 | + if (!$discount->get_id() || !$discount_object || $discount_object->post_type != 'wpi_discount') { |
|
124 | + $discount->last_error = __('Invalid discount.', 'invoicing'); |
|
125 | + $discount->set_id(0); |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | |
140 | - $this->read_object_data( $discount, $discount_object ); |
|
140 | + $this->read_object_data($discount, $discount_object); |
|
141 | 141 | $discount->read_meta_data(); |
142 | - $discount->set_object_read( true ); |
|
143 | - do_action( 'getpaid_read_discount', $discount->get_id(), $discount ); |
|
142 | + $discount->set_object_read(true); |
|
143 | + do_action('getpaid_read_discount', $discount->get_id(), $discount); |
|
144 | 144 | |
145 | 145 | } |
146 | 146 | |
@@ -149,28 +149,28 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param WPInv_Discount $discount Discount object. |
151 | 151 | */ |
152 | - public function update( &$discount ) { |
|
152 | + public function update(&$discount) { |
|
153 | 153 | $discount->save_meta_data(); |
154 | - $discount->set_version( WPINV_VERSION ); |
|
154 | + $discount->set_version(WPINV_VERSION); |
|
155 | 155 | |
156 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
157 | - $discount->set_date_created( current_time('mysql') ); |
|
156 | + if (null === $discount->get_date_created('edit')) { |
|
157 | + $discount->set_date_created(current_time('mysql')); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Grab the current status so we can compare. |
161 | - $previous_status = get_post_status( $discount->get_id() ); |
|
161 | + $previous_status = get_post_status($discount->get_id()); |
|
162 | 162 | |
163 | 163 | $changes = $discount->get_changes(); |
164 | 164 | |
165 | 165 | // Only update the post when the post data changes. |
166 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
166 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt'), array_keys($changes))) { |
|
167 | 167 | $post_data = array( |
168 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
169 | - 'post_status' => $discount->get_status( 'edit' ), |
|
170 | - 'post_title' => $discount->get_name( 'edit' ), |
|
171 | - 'post_author' => $discount->get_author( 'edit' ), |
|
172 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
173 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
168 | + 'post_date' => $discount->get_date_created('edit'), |
|
169 | + 'post_status' => $discount->get_status('edit'), |
|
170 | + 'post_title' => $discount->get_name('edit'), |
|
171 | + 'post_author' => $discount->get_author('edit'), |
|
172 | + 'post_modified' => $discount->get_date_modified('edit'), |
|
173 | + 'post_excerpt' => $discount->get_description('edit'), |
|
174 | 174 | ); |
175 | 175 | |
176 | 176 | /** |
@@ -181,25 +181,25 @@ discard block |
||
181 | 181 | * This ensures hooks are fired by either WP itself (admin screen save), |
182 | 182 | * or an update purely from CRUD. |
183 | 183 | */ |
184 | - if ( doing_action( 'save_post' ) ) { |
|
185 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
186 | - clean_post_cache( $discount->get_id() ); |
|
184 | + if (doing_action('save_post')) { |
|
185 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $discount->get_id())); |
|
186 | + clean_post_cache($discount->get_id()); |
|
187 | 187 | } else { |
188 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
188 | + wp_update_post(array_merge(array('ID' => $discount->get_id()), $post_data)); |
|
189 | 189 | } |
190 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
190 | + $discount->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
191 | 191 | } |
192 | - $this->update_post_meta( $discount ); |
|
192 | + $this->update_post_meta($discount); |
|
193 | 193 | $discount->apply_changes(); |
194 | - $this->clear_caches( $discount ); |
|
194 | + $this->clear_caches($discount); |
|
195 | 195 | |
196 | 196 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
197 | - $new_status = $discount->get_status( 'edit' ); |
|
197 | + $new_status = $discount->get_status('edit'); |
|
198 | 198 | |
199 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
200 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
199 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
200 | + do_action('getpaid_new_discount', $discount->get_id(), $discount); |
|
201 | 201 | } else { |
202 | - do_action( 'getpaid_update_discount', $discount->get_id(), $discount ); |
|
202 | + do_action('getpaid_update_discount', $discount->get_id(), $discount); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,228 +14,228 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | - * |
|
20 | - * @since 1.0.19 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $internal_meta_keys = array( |
|
24 | - '_wpinv_price', |
|
25 | - '_wpinv_vat_rule', |
|
26 | - '_wpinv_vat_class', |
|
27 | - '_wpinv_type', |
|
28 | - '_wpinv_custom_id', |
|
29 | - '_wpinv_custom_name', |
|
30 | - '_wpinv_custom_singular_name', |
|
31 | - '_wpinv_editable', |
|
32 | - '_wpinv_dynamic_pricing', |
|
33 | - '_minimum_price', |
|
34 | - '_wpinv_is_recurring', |
|
35 | - '_wpinv_recurring_period', |
|
36 | - '_wpinv_recurring_interval', |
|
37 | - '_wpinv_recurring_limit', |
|
38 | - '_wpinv_free_trial', |
|
39 | - '_wpinv_trial_period', |
|
40 | - '_wpinv_trial_interval' |
|
41 | - ); |
|
42 | - |
|
43 | - /** |
|
44 | - * A map of meta keys to data props. |
|
45 | - * |
|
46 | - * @since 1.0.19 |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $meta_key_to_props = array( |
|
51 | - '_wpinv_price' => 'price', |
|
52 | - '_wpinv_vat_rule' => 'vat_rule', |
|
53 | - '_wpinv_vat_class' => 'vat_class', |
|
54 | - '_wpinv_type' => 'type', |
|
55 | - '_wpinv_custom_id' => 'custom_id', |
|
56 | - '_wpinv_custom_name' => 'custom_name', |
|
57 | - '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | - '_wpinv_editable' => 'is_editable', |
|
59 | - '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | - '_minimum_price' => 'minimum_price', |
|
61 | - '_wpinv_custom_name' => 'custom_name', |
|
62 | - '_wpinv_is_recurring' => 'is_recurring', |
|
63 | - '_wpinv_recurring_period' => 'recurring_period', |
|
64 | - '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | - '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | - '_wpinv_free_trial' => 'is_free_trial', |
|
67 | - '_wpinv_trial_period' => 'trial_period', |
|
68 | - '_wpinv_trial_interval' => 'trial_interval', |
|
69 | - '_wpinv_version' => 'version', |
|
70 | - ); |
|
71 | - |
|
72 | - /* |
|
17 | + /** |
|
18 | + * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | + * |
|
20 | + * @since 1.0.19 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $internal_meta_keys = array( |
|
24 | + '_wpinv_price', |
|
25 | + '_wpinv_vat_rule', |
|
26 | + '_wpinv_vat_class', |
|
27 | + '_wpinv_type', |
|
28 | + '_wpinv_custom_id', |
|
29 | + '_wpinv_custom_name', |
|
30 | + '_wpinv_custom_singular_name', |
|
31 | + '_wpinv_editable', |
|
32 | + '_wpinv_dynamic_pricing', |
|
33 | + '_minimum_price', |
|
34 | + '_wpinv_is_recurring', |
|
35 | + '_wpinv_recurring_period', |
|
36 | + '_wpinv_recurring_interval', |
|
37 | + '_wpinv_recurring_limit', |
|
38 | + '_wpinv_free_trial', |
|
39 | + '_wpinv_trial_period', |
|
40 | + '_wpinv_trial_interval' |
|
41 | + ); |
|
42 | + |
|
43 | + /** |
|
44 | + * A map of meta keys to data props. |
|
45 | + * |
|
46 | + * @since 1.0.19 |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $meta_key_to_props = array( |
|
51 | + '_wpinv_price' => 'price', |
|
52 | + '_wpinv_vat_rule' => 'vat_rule', |
|
53 | + '_wpinv_vat_class' => 'vat_class', |
|
54 | + '_wpinv_type' => 'type', |
|
55 | + '_wpinv_custom_id' => 'custom_id', |
|
56 | + '_wpinv_custom_name' => 'custom_name', |
|
57 | + '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | + '_wpinv_editable' => 'is_editable', |
|
59 | + '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | + '_minimum_price' => 'minimum_price', |
|
61 | + '_wpinv_custom_name' => 'custom_name', |
|
62 | + '_wpinv_is_recurring' => 'is_recurring', |
|
63 | + '_wpinv_recurring_period' => 'recurring_period', |
|
64 | + '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | + '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | + '_wpinv_free_trial' => 'is_free_trial', |
|
67 | + '_wpinv_trial_period' => 'trial_period', |
|
68 | + '_wpinv_trial_interval' => 'trial_interval', |
|
69 | + '_wpinv_version' => 'version', |
|
70 | + ); |
|
71 | + |
|
72 | + /* |
|
73 | 73 | |-------------------------------------------------------------------------- |
74 | 74 | | CRUD Methods |
75 | 75 | |-------------------------------------------------------------------------- |
76 | 76 | */ |
77 | 77 | |
78 | - /** |
|
79 | - * Method to create a new item in the database. |
|
80 | - * |
|
81 | - * @param WPInv_Item $item Item object. |
|
82 | - */ |
|
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time('mysql') ); |
|
86 | - |
|
87 | - // Create a new post. |
|
88 | - $id = wp_insert_post( |
|
89 | - apply_filters( |
|
90 | - 'getpaid_new_item_data', |
|
91 | - array( |
|
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | - 'post_type' => 'wpi_item', |
|
94 | - 'post_status' => $this->get_post_status( $item ), |
|
95 | - 'ping_status' => 'closed', |
|
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
98 | - 'post_parent' => 0, |
|
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | - ) |
|
101 | - ), |
|
102 | - true |
|
103 | - ); |
|
104 | - |
|
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
108 | - $item->save_meta_data(); |
|
109 | - $item->apply_changes(); |
|
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
112 | - return true; |
|
113 | - } |
|
114 | - |
|
115 | - if ( is_wp_error( $id ) ) { |
|
116 | - $item->last_error = $id->get_error_message(); |
|
117 | - } |
|
78 | + /** |
|
79 | + * Method to create a new item in the database. |
|
80 | + * |
|
81 | + * @param WPInv_Item $item Item object. |
|
82 | + */ |
|
83 | + public function create( &$item ) { |
|
84 | + $item->set_version( WPINV_VERSION ); |
|
85 | + $item->set_date_created( current_time('mysql') ); |
|
86 | + |
|
87 | + // Create a new post. |
|
88 | + $id = wp_insert_post( |
|
89 | + apply_filters( |
|
90 | + 'getpaid_new_item_data', |
|
91 | + array( |
|
92 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | + 'post_type' => 'wpi_item', |
|
94 | + 'post_status' => $this->get_post_status( $item ), |
|
95 | + 'ping_status' => 'closed', |
|
96 | + 'post_author' => $item->get_author( 'edit' ), |
|
97 | + 'post_title' => $item->get_name( 'edit' ), |
|
98 | + 'post_parent' => 0, |
|
99 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | + ) |
|
101 | + ), |
|
102 | + true |
|
103 | + ); |
|
104 | + |
|
105 | + if ( $id && ! is_wp_error( $id ) ) { |
|
106 | + $item->set_id( $id ); |
|
107 | + $this->update_post_meta( $item ); |
|
108 | + $item->save_meta_data(); |
|
109 | + $item->apply_changes(); |
|
110 | + $this->clear_caches( $item ); |
|
111 | + do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
112 | + return true; |
|
113 | + } |
|
114 | + |
|
115 | + if ( is_wp_error( $id ) ) { |
|
116 | + $item->last_error = $id->get_error_message(); |
|
117 | + } |
|
118 | 118 | |
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Method to read an item from the database. |
|
124 | - * |
|
125 | - * @param WPInv_Item $item Item object. |
|
126 | - * |
|
127 | - */ |
|
128 | - public function read( &$item ) { |
|
129 | - |
|
130 | - $item->set_defaults(); |
|
131 | - $item_object = get_post( $item->get_id() ); |
|
132 | - |
|
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - $item->set_props( |
|
140 | - array( |
|
141 | - 'parent_id' => $item_object->post_parent, |
|
142 | - 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | - 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | - 'status' => $item_object->post_status, |
|
145 | - 'name' => $item_object->post_title, |
|
146 | - 'description' => $item_object->post_excerpt, |
|
147 | - 'author' => $item_object->post_author, |
|
148 | - ) |
|
149 | - ); |
|
150 | - |
|
151 | - $this->read_object_data( $item, $item_object ); |
|
152 | - $item->read_meta_data(); |
|
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item->get_id(), $item ); |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Method to update an item in the database. |
|
160 | - * |
|
161 | - * @param WPInv_Item $item Item object. |
|
162 | - */ |
|
163 | - public function update( &$item ) { |
|
164 | - $item->save_meta_data(); |
|
165 | - $item->set_version( WPINV_VERSION ); |
|
166 | - |
|
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time('mysql') ); |
|
169 | - } |
|
170 | - |
|
171 | - // Grab the current status so we can compare. |
|
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
173 | - |
|
174 | - $changes = $item->get_changes(); |
|
175 | - |
|
176 | - // Only update the post when the post data changes. |
|
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | - $post_data = array( |
|
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
186 | - ); |
|
187 | - |
|
188 | - /** |
|
189 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | - * to update data, since wp_update_post spawns more calls to the |
|
191 | - * save_post action. |
|
192 | - * |
|
193 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | - * or an update purely from CRUD. |
|
195 | - */ |
|
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
199 | - } else { |
|
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | - } |
|
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | - } |
|
204 | - $this->update_post_meta( $item ); |
|
205 | - $item->apply_changes(); |
|
206 | - $this->clear_caches( $item ); |
|
207 | - |
|
208 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | - $new_status = $item->get_status( 'edit' ); |
|
210 | - |
|
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
213 | - } else { |
|
214 | - do_action( 'getpaid_update_item', $item->get_id(), $item ); |
|
215 | - } |
|
216 | - |
|
217 | - } |
|
218 | - |
|
219 | - /* |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Method to read an item from the database. |
|
124 | + * |
|
125 | + * @param WPInv_Item $item Item object. |
|
126 | + * |
|
127 | + */ |
|
128 | + public function read( &$item ) { |
|
129 | + |
|
130 | + $item->set_defaults(); |
|
131 | + $item_object = get_post( $item->get_id() ); |
|
132 | + |
|
133 | + if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | + $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | + $item->set_id( 0 ); |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + $item->set_props( |
|
140 | + array( |
|
141 | + 'parent_id' => $item_object->post_parent, |
|
142 | + 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | + 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | + 'status' => $item_object->post_status, |
|
145 | + 'name' => $item_object->post_title, |
|
146 | + 'description' => $item_object->post_excerpt, |
|
147 | + 'author' => $item_object->post_author, |
|
148 | + ) |
|
149 | + ); |
|
150 | + |
|
151 | + $this->read_object_data( $item, $item_object ); |
|
152 | + $item->read_meta_data(); |
|
153 | + $item->set_object_read( true ); |
|
154 | + do_action( 'getpaid_read_item', $item->get_id(), $item ); |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Method to update an item in the database. |
|
160 | + * |
|
161 | + * @param WPInv_Item $item Item object. |
|
162 | + */ |
|
163 | + public function update( &$item ) { |
|
164 | + $item->save_meta_data(); |
|
165 | + $item->set_version( WPINV_VERSION ); |
|
166 | + |
|
167 | + if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | + $item->set_date_created( current_time('mysql') ); |
|
169 | + } |
|
170 | + |
|
171 | + // Grab the current status so we can compare. |
|
172 | + $previous_status = get_post_status( $item->get_id() ); |
|
173 | + |
|
174 | + $changes = $item->get_changes(); |
|
175 | + |
|
176 | + // Only update the post when the post data changes. |
|
177 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | + $post_data = array( |
|
179 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | + 'post_status' => $item->get_status( 'edit' ), |
|
181 | + 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | + 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | + 'post_title' => $item->get_name( 'edit' ), |
|
185 | + 'post_author' => $item->get_author( 'edit' ), |
|
186 | + ); |
|
187 | + |
|
188 | + /** |
|
189 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | + * to update data, since wp_update_post spawns more calls to the |
|
191 | + * save_post action. |
|
192 | + * |
|
193 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | + * or an update purely from CRUD. |
|
195 | + */ |
|
196 | + if ( doing_action( 'save_post' ) ) { |
|
197 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | + clean_post_cache( $item->get_id() ); |
|
199 | + } else { |
|
200 | + wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | + } |
|
202 | + $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | + } |
|
204 | + $this->update_post_meta( $item ); |
|
205 | + $item->apply_changes(); |
|
206 | + $this->clear_caches( $item ); |
|
207 | + |
|
208 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | + $new_status = $item->get_status( 'edit' ); |
|
210 | + |
|
211 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | + do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
213 | + } else { |
|
214 | + do_action( 'getpaid_update_item', $item->get_id(), $item ); |
|
215 | + } |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /* |
|
220 | 220 | |-------------------------------------------------------------------------- |
221 | 221 | | Additional Methods |
222 | 222 | |-------------------------------------------------------------------------- |
223 | 223 | */ |
224 | 224 | |
225 | - /** |
|
226 | - * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | - * |
|
228 | - * @param WPInv_Item $item WPInv_Item object. |
|
229 | - * @since 1.0.19 |
|
230 | - */ |
|
231 | - protected function update_post_meta( &$item ) { |
|
225 | + /** |
|
226 | + * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | + * |
|
228 | + * @param WPInv_Item $item WPInv_Item object. |
|
229 | + * @since 1.0.19 |
|
230 | + */ |
|
231 | + protected function update_post_meta( &$item ) { |
|
232 | 232 | |
233 | - // Ensure that we have a custom id. |
|
233 | + // Ensure that we have a custom id. |
|
234 | 234 | if ( ! $item->get_custom_id() ) { |
235 | 235 | $item->set_custom_id( $item->get_id() ); |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
239 | - } |
|
238 | + parent::update_post_meta( $item ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * GetPaid_Item_Data_Store class file. |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -80,39 +80,39 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param WPInv_Item $item Item object. |
82 | 82 | */ |
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time('mysql') ); |
|
83 | + public function create(&$item) { |
|
84 | + $item->set_version(WPINV_VERSION); |
|
85 | + $item->set_date_created(current_time('mysql')); |
|
86 | 86 | |
87 | 87 | // Create a new post. |
88 | 88 | $id = wp_insert_post( |
89 | 89 | apply_filters( |
90 | 90 | 'getpaid_new_item_data', |
91 | 91 | array( |
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
92 | + 'post_date' => $item->get_date_created('edit'), |
|
93 | 93 | 'post_type' => 'wpi_item', |
94 | - 'post_status' => $this->get_post_status( $item ), |
|
94 | + 'post_status' => $this->get_post_status($item), |
|
95 | 95 | 'ping_status' => 'closed', |
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
96 | + 'post_author' => $item->get_author('edit'), |
|
97 | + 'post_title' => $item->get_name('edit'), |
|
98 | 98 | 'post_parent' => 0, |
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
99 | + 'post_excerpt' => $item->get_description('edit'), |
|
100 | 100 | ) |
101 | 101 | ), |
102 | 102 | true |
103 | 103 | ); |
104 | 104 | |
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
105 | + if ($id && !is_wp_error($id)) { |
|
106 | + $item->set_id($id); |
|
107 | + $this->update_post_meta($item); |
|
108 | 108 | $item->save_meta_data(); |
109 | 109 | $item->apply_changes(); |
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
110 | + $this->clear_caches($item); |
|
111 | + do_action('getpaid_new_item', $item->get_id(), $item); |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
115 | - if ( is_wp_error( $id ) ) { |
|
115 | + if (is_wp_error($id)) { |
|
116 | 116 | $item->last_error = $id->get_error_message(); |
117 | 117 | } |
118 | 118 | |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | * @param WPInv_Item $item Item object. |
126 | 126 | * |
127 | 127 | */ |
128 | - public function read( &$item ) { |
|
128 | + public function read(&$item) { |
|
129 | 129 | |
130 | 130 | $item->set_defaults(); |
131 | - $item_object = get_post( $item->get_id() ); |
|
131 | + $item_object = get_post($item->get_id()); |
|
132 | 132 | |
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
133 | + if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') { |
|
134 | + $item->last_error = __('Invalid item.', 'invoicing'); |
|
135 | + $item->set_id(0); |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | ) |
149 | 149 | ); |
150 | 150 | |
151 | - $this->read_object_data( $item, $item_object ); |
|
151 | + $this->read_object_data($item, $item_object); |
|
152 | 152 | $item->read_meta_data(); |
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item->get_id(), $item ); |
|
153 | + $item->set_object_read(true); |
|
154 | + do_action('getpaid_read_item', $item->get_id(), $item); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
@@ -160,29 +160,29 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @param WPInv_Item $item Item object. |
162 | 162 | */ |
163 | - public function update( &$item ) { |
|
163 | + public function update(&$item) { |
|
164 | 164 | $item->save_meta_data(); |
165 | - $item->set_version( WPINV_VERSION ); |
|
165 | + $item->set_version(WPINV_VERSION); |
|
166 | 166 | |
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time('mysql') ); |
|
167 | + if (null === $item->get_date_created('edit')) { |
|
168 | + $item->set_date_created(current_time('mysql')); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Grab the current status so we can compare. |
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
172 | + $previous_status = get_post_status($item->get_id()); |
|
173 | 173 | |
174 | 174 | $changes = $item->get_changes(); |
175 | 175 | |
176 | 176 | // Only update the post when the post data changes. |
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
177 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author'), array_keys($changes))) { |
|
178 | 178 | $post_data = array( |
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
179 | + 'post_date' => $item->get_date_created('edit'), |
|
180 | + 'post_status' => $item->get_status('edit'), |
|
181 | + 'post_parent' => $item->get_parent_id('edit'), |
|
182 | + 'post_excerpt' => $item->get_description('edit'), |
|
183 | + 'post_modified' => $item->get_date_modified('edit'), |
|
184 | + 'post_title' => $item->get_name('edit'), |
|
185 | + 'post_author' => $item->get_author('edit'), |
|
186 | 186 | ); |
187 | 187 | |
188 | 188 | /** |
@@ -193,25 +193,25 @@ discard block |
||
193 | 193 | * This ensures hooks are fired by either WP itself (admin screen save), |
194 | 194 | * or an update purely from CRUD. |
195 | 195 | */ |
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
196 | + if (doing_action('save_post')) { |
|
197 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id())); |
|
198 | + clean_post_cache($item->get_id()); |
|
199 | 199 | } else { |
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
200 | + wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data)); |
|
201 | 201 | } |
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
202 | + $item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | 203 | } |
204 | - $this->update_post_meta( $item ); |
|
204 | + $this->update_post_meta($item); |
|
205 | 205 | $item->apply_changes(); |
206 | - $this->clear_caches( $item ); |
|
206 | + $this->clear_caches($item); |
|
207 | 207 | |
208 | 208 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
209 | - $new_status = $item->get_status( 'edit' ); |
|
209 | + $new_status = $item->get_status('edit'); |
|
210 | 210 | |
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
211 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
212 | + do_action('getpaid_new_item', $item->get_id(), $item); |
|
213 | 213 | } else { |
214 | - do_action( 'getpaid_update_item', $item->get_id(), $item ); |
|
214 | + do_action('getpaid_update_item', $item->get_id(), $item); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | } |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | * @param WPInv_Item $item WPInv_Item object. |
229 | 229 | * @since 1.0.19 |
230 | 230 | */ |
231 | - protected function update_post_meta( &$item ) { |
|
231 | + protected function update_post_meta(&$item) { |
|
232 | 232 | |
233 | 233 | // Ensure that we have a custom id. |
234 | - if ( ! $item->get_custom_id() ) { |
|
235 | - $item->set_custom_id( $item->get_id() ); |
|
234 | + if (!$item->get_custom_id()) { |
|
235 | + $item->set_custom_id($item->get_id()); |
|
236 | 236 | } |
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
238 | + parent::update_post_meta($item); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | } |
@@ -7,12 +7,12 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | <div class="p-3"> |
14 | 14 | <h2> |
15 | - <?php echo apply_filters( 'getpaid_invoice_type_label', ucfirst( $invoice->get_type() ), $invoice ); ?> |
|
15 | + <?php echo apply_filters('getpaid_invoice_type_label', ucfirst($invoice->get_type()), $invoice); ?> |
|
16 | 16 | </h2> |
17 | 17 | </div> |
18 | 18 |
@@ -7,15 +7,15 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | -<a target="_blank" class="logo-link" href="<?php echo esc_url( wpinv_get_business_website() ); ?>"> |
|
13 | +<a target="_blank" class="logo-link" href="<?php echo esc_url(wpinv_get_business_website()); ?>"> |
|
14 | 14 | |
15 | - <?php if ( $logo = wpinv_get_business_logo() ) { ?> |
|
16 | - <img class="logo" style="max-width:100%;" src="<?php echo esc_url( $logo ); ?>"> |
|
15 | + <?php if ($logo = wpinv_get_business_logo()) { ?> |
|
16 | + <img class="logo" style="max-width:100%;" src="<?php echo esc_url($logo); ?>"> |
|
17 | 17 | <?php } else { ?> |
18 | - <h1><?php echo esc_html( wpinv_get_business_name() ); ?></h1> |
|
18 | + <h1><?php echo esc_html(wpinv_get_business_name()); ?></h1> |
|
19 | 19 | <?php } ?> |
20 | 20 | |
21 | 21 | </a> |