@@ -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,512 +15,512 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpinv_subscr_profile_id', |
|
26 | - '_wpinv_subscription_id', |
|
27 | - '_wpinv_taxes', |
|
28 | - '_wpinv_fees', |
|
29 | - '_wpinv_discounts', |
|
30 | - '_wpinv_submission_id', |
|
31 | - '_wpinv_payment_form', |
|
32 | - '_wpinv_is_viewed', |
|
33 | - 'wpinv_email_cc', |
|
34 | - 'wpinv_template' |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * A map of meta keys to data props. |
|
39 | - * |
|
40 | - * @since 1.0.19 |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - protected $meta_key_to_props = array( |
|
45 | - '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
46 | - '_wpinv_subscription_id' => 'subscription_id', |
|
47 | - '_wpinv_taxes' => 'taxes', |
|
48 | - '_wpinv_fees' => 'fees', |
|
49 | - '_wpinv_discounts' => 'discounts', |
|
50 | - '_wpinv_submission_id' => 'submission_id', |
|
51 | - '_wpinv_payment_form' => 'payment_form', |
|
52 | - '_wpinv_is_viewed' => 'is_viewed', |
|
53 | - 'wpinv_email_cc' => 'email_cc', |
|
54 | - 'wpinv_template' => 'template', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * A map of database fields to data props. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - protected $database_fields_to_props = array( |
|
65 | - 'post_id' => 'id', |
|
66 | - 'number' => 'number', |
|
67 | - 'currency' => 'currency', |
|
68 | - 'key' => 'key', |
|
69 | - 'type' => 'type', |
|
70 | - 'mode' => 'mode', |
|
71 | - 'user_ip' => 'user_ip', |
|
72 | - 'first_name' => 'first_name', |
|
73 | - 'last_name' => 'last_name', |
|
74 | - 'address' => 'address', |
|
75 | - 'city' => 'city', |
|
76 | - 'state' => 'state', |
|
77 | - 'country' => 'country', |
|
78 | - 'zip' => 'zip', |
|
79 | - 'zip' => 'zip', |
|
80 | - 'adddress_confirmed' => 'address_confirmed', |
|
81 | - 'gateway' => 'gateway', |
|
82 | - 'transaction_id' => 'transaction_id', |
|
83 | - 'currency' => 'currency', |
|
84 | - 'subtotal' => 'subtotal', |
|
85 | - 'tax' => 'total_tax', |
|
86 | - 'fees_total' => 'total_fees', |
|
87 | - 'discount' => 'total_discount', |
|
88 | - 'total' => 'total', |
|
89 | - 'discount_code' => 'discount_code', |
|
90 | - 'disable_taxes' => 'disable_taxes', |
|
91 | - 'due_date' => 'due_date', |
|
92 | - 'completed_date' => 'completed_date', |
|
93 | - 'company' => 'company', |
|
94 | - 'vat_number' => 'vat_number', |
|
95 | - 'vat_rate' => 'vat_rate', |
|
96 | - ); |
|
97 | - |
|
98 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpinv_subscr_profile_id', |
|
26 | + '_wpinv_subscription_id', |
|
27 | + '_wpinv_taxes', |
|
28 | + '_wpinv_fees', |
|
29 | + '_wpinv_discounts', |
|
30 | + '_wpinv_submission_id', |
|
31 | + '_wpinv_payment_form', |
|
32 | + '_wpinv_is_viewed', |
|
33 | + 'wpinv_email_cc', |
|
34 | + 'wpinv_template' |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * A map of meta keys to data props. |
|
39 | + * |
|
40 | + * @since 1.0.19 |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + protected $meta_key_to_props = array( |
|
45 | + '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
46 | + '_wpinv_subscription_id' => 'subscription_id', |
|
47 | + '_wpinv_taxes' => 'taxes', |
|
48 | + '_wpinv_fees' => 'fees', |
|
49 | + '_wpinv_discounts' => 'discounts', |
|
50 | + '_wpinv_submission_id' => 'submission_id', |
|
51 | + '_wpinv_payment_form' => 'payment_form', |
|
52 | + '_wpinv_is_viewed' => 'is_viewed', |
|
53 | + 'wpinv_email_cc' => 'email_cc', |
|
54 | + 'wpinv_template' => 'template', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * A map of database fields to data props. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + protected $database_fields_to_props = array( |
|
65 | + 'post_id' => 'id', |
|
66 | + 'number' => 'number', |
|
67 | + 'currency' => 'currency', |
|
68 | + 'key' => 'key', |
|
69 | + 'type' => 'type', |
|
70 | + 'mode' => 'mode', |
|
71 | + 'user_ip' => 'user_ip', |
|
72 | + 'first_name' => 'first_name', |
|
73 | + 'last_name' => 'last_name', |
|
74 | + 'address' => 'address', |
|
75 | + 'city' => 'city', |
|
76 | + 'state' => 'state', |
|
77 | + 'country' => 'country', |
|
78 | + 'zip' => 'zip', |
|
79 | + 'zip' => 'zip', |
|
80 | + 'adddress_confirmed' => 'address_confirmed', |
|
81 | + 'gateway' => 'gateway', |
|
82 | + 'transaction_id' => 'transaction_id', |
|
83 | + 'currency' => 'currency', |
|
84 | + 'subtotal' => 'subtotal', |
|
85 | + 'tax' => 'total_tax', |
|
86 | + 'fees_total' => 'total_fees', |
|
87 | + 'discount' => 'total_discount', |
|
88 | + 'total' => 'total', |
|
89 | + 'discount_code' => 'discount_code', |
|
90 | + 'disable_taxes' => 'disable_taxes', |
|
91 | + 'due_date' => 'due_date', |
|
92 | + 'completed_date' => 'completed_date', |
|
93 | + 'company' => 'company', |
|
94 | + 'vat_number' => 'vat_number', |
|
95 | + 'vat_rate' => 'vat_rate', |
|
96 | + ); |
|
97 | + |
|
98 | + /* |
|
99 | 99 | |-------------------------------------------------------------------------- |
100 | 100 | | CRUD Methods |
101 | 101 | |-------------------------------------------------------------------------- |
102 | 102 | */ |
103 | - /** |
|
104 | - * Method to create a new invoice in the database. |
|
105 | - * |
|
106 | - * @param WPInv_Invoice $invoice Invoice object. |
|
107 | - */ |
|
108 | - public function create( &$invoice ) { |
|
109 | - $invoice->set_version( WPINV_VERSION ); |
|
110 | - $invoice->set_date_created( current_time('mysql') ); |
|
111 | - |
|
112 | - // Create a new post. |
|
113 | - $id = wp_insert_post( |
|
114 | - apply_filters( |
|
115 | - 'getpaid_new_invoice_data', |
|
116 | - array( |
|
117 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
118 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
119 | - 'post_status' => $this->get_post_status( $invoice ), |
|
120 | - 'ping_status' => 'closed', |
|
121 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
122 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
123 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
124 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
125 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
126 | - ) |
|
127 | - ), |
|
128 | - true |
|
129 | - ); |
|
130 | - |
|
131 | - if ( $id && ! is_wp_error( $id ) ) { |
|
132 | - |
|
133 | - // Update the new id and regenerate a title. |
|
134 | - $invoice->set_id( $id ); |
|
135 | - wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) ); |
|
136 | - |
|
137 | - // Ensure both the key and number are set. |
|
138 | - $invoice->get_key(); |
|
139 | - $invoice->get_number(); |
|
140 | - |
|
141 | - // Save special fields and items. |
|
142 | - $this->save_special_fields( $invoice ); |
|
143 | - $this->save_items( $invoice ); |
|
144 | - |
|
145 | - // Update meta data. |
|
146 | - $this->update_post_meta( $invoice ); |
|
147 | - $invoice->save_meta_data(); |
|
148 | - |
|
149 | - // Apply changes. |
|
150 | - $invoice->apply_changes(); |
|
151 | - $this->clear_caches( $invoice ); |
|
152 | - |
|
153 | - // Fires after a new invoice is created. |
|
154 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
155 | - return true; |
|
156 | - } |
|
157 | - |
|
158 | - if ( is_wp_error( $id ) ) { |
|
159 | - $invoice->last_error = $id->get_error_message(); |
|
160 | - } |
|
161 | - |
|
162 | - return false; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Method to read an invoice from the database. |
|
167 | - * |
|
168 | - * @param WPInv_Invoice $invoice Invoice object. |
|
169 | - * |
|
170 | - */ |
|
171 | - public function read( &$invoice ) { |
|
172 | - |
|
173 | - $invoice->set_defaults(); |
|
174 | - $invoice_object = get_post( $invoice->get_id() ); |
|
175 | - |
|
176 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
177 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
178 | - $invoice->set_id( 0 ); |
|
179 | - return false; |
|
180 | - } |
|
181 | - |
|
182 | - $invoice->set_props( |
|
183 | - array( |
|
184 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
185 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
186 | - 'status' => $invoice_object->post_status, |
|
187 | - 'author' => $invoice_object->post_author, |
|
188 | - 'description' => $invoice_object->post_excerpt, |
|
189 | - 'parent_id' => $invoice_object->post_parent, |
|
190 | - 'name' => $invoice_object->post_title, |
|
191 | - 'path' => $invoice_object->post_name, |
|
192 | - 'post_type' => $invoice_object->post_type, |
|
193 | - ) |
|
194 | - ); |
|
195 | - |
|
196 | - $invoice->set_type( $invoice_object->post_type ); |
|
197 | - |
|
198 | - $this->read_object_data( $invoice, $invoice_object ); |
|
199 | - $this->add_special_fields( $invoice ); |
|
200 | - $this->add_items( $invoice ); |
|
201 | - $invoice->read_meta_data(); |
|
202 | - $invoice->set_object_read( true ); |
|
203 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice ); |
|
204 | - |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Method to update an invoice in the database. |
|
209 | - * |
|
210 | - * @param WPInv_Invoice $invoice Invoice object. |
|
211 | - */ |
|
212 | - public function update( &$invoice ) { |
|
213 | - $invoice->save_meta_data(); |
|
214 | - $invoice->set_version( WPINV_VERSION ); |
|
215 | - |
|
216 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
217 | - $invoice->set_date_created( current_time('mysql') ); |
|
218 | - } |
|
219 | - |
|
220 | - // Ensure both the key and number are set. |
|
221 | - $invoice->get_key(); |
|
222 | - $invoice->get_number(); |
|
223 | - |
|
224 | - // Grab the current status so we can compare. |
|
225 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
226 | - |
|
227 | - $changes = $invoice->get_changes(); |
|
228 | - |
|
229 | - // Only update the post when the post data changes. |
|
230 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
231 | - $post_data = array( |
|
232 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
233 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
234 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
235 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
236 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
237 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
238 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
239 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
240 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
241 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
242 | - ); |
|
243 | - |
|
244 | - /** |
|
245 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
246 | - * to update data, since wp_update_post spawns more calls to the |
|
247 | - * save_post action. |
|
248 | - * |
|
249 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
250 | - * or an update purely from CRUD. |
|
251 | - */ |
|
252 | - if ( doing_action( 'save_post' ) ) { |
|
253 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
254 | - clean_post_cache( $invoice->get_id() ); |
|
255 | - } else { |
|
256 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
257 | - } |
|
258 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
259 | - } |
|
260 | - |
|
261 | - // Update meta data. |
|
262 | - $this->update_post_meta( $invoice ); |
|
263 | - |
|
264 | - // Save special fields and items. |
|
265 | - $this->save_special_fields( $invoice ); |
|
266 | - $this->save_items( $invoice ); |
|
267 | - |
|
268 | - // Apply the changes. |
|
269 | - $invoice->apply_changes(); |
|
270 | - |
|
271 | - // Clear caches. |
|
272 | - $this->clear_caches( $invoice ); |
|
273 | - |
|
274 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
275 | - $new_status = $invoice->get_status( 'edit' ); |
|
276 | - |
|
277 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
278 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
279 | - } else { |
|
280 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice ); |
|
281 | - } |
|
282 | - |
|
283 | - } |
|
284 | - |
|
285 | - /* |
|
103 | + /** |
|
104 | + * Method to create a new invoice in the database. |
|
105 | + * |
|
106 | + * @param WPInv_Invoice $invoice Invoice object. |
|
107 | + */ |
|
108 | + public function create( &$invoice ) { |
|
109 | + $invoice->set_version( WPINV_VERSION ); |
|
110 | + $invoice->set_date_created( current_time('mysql') ); |
|
111 | + |
|
112 | + // Create a new post. |
|
113 | + $id = wp_insert_post( |
|
114 | + apply_filters( |
|
115 | + 'getpaid_new_invoice_data', |
|
116 | + array( |
|
117 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
118 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
119 | + 'post_status' => $this->get_post_status( $invoice ), |
|
120 | + 'ping_status' => 'closed', |
|
121 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
122 | + 'post_title' => $invoice->get_title( 'edit' ), |
|
123 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
124 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
125 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
126 | + ) |
|
127 | + ), |
|
128 | + true |
|
129 | + ); |
|
130 | + |
|
131 | + if ( $id && ! is_wp_error( $id ) ) { |
|
132 | + |
|
133 | + // Update the new id and regenerate a title. |
|
134 | + $invoice->set_id( $id ); |
|
135 | + wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) ); |
|
136 | + |
|
137 | + // Ensure both the key and number are set. |
|
138 | + $invoice->get_key(); |
|
139 | + $invoice->get_number(); |
|
140 | + |
|
141 | + // Save special fields and items. |
|
142 | + $this->save_special_fields( $invoice ); |
|
143 | + $this->save_items( $invoice ); |
|
144 | + |
|
145 | + // Update meta data. |
|
146 | + $this->update_post_meta( $invoice ); |
|
147 | + $invoice->save_meta_data(); |
|
148 | + |
|
149 | + // Apply changes. |
|
150 | + $invoice->apply_changes(); |
|
151 | + $this->clear_caches( $invoice ); |
|
152 | + |
|
153 | + // Fires after a new invoice is created. |
|
154 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
155 | + return true; |
|
156 | + } |
|
157 | + |
|
158 | + if ( is_wp_error( $id ) ) { |
|
159 | + $invoice->last_error = $id->get_error_message(); |
|
160 | + } |
|
161 | + |
|
162 | + return false; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Method to read an invoice from the database. |
|
167 | + * |
|
168 | + * @param WPInv_Invoice $invoice Invoice object. |
|
169 | + * |
|
170 | + */ |
|
171 | + public function read( &$invoice ) { |
|
172 | + |
|
173 | + $invoice->set_defaults(); |
|
174 | + $invoice_object = get_post( $invoice->get_id() ); |
|
175 | + |
|
176 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
177 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
178 | + $invoice->set_id( 0 ); |
|
179 | + return false; |
|
180 | + } |
|
181 | + |
|
182 | + $invoice->set_props( |
|
183 | + array( |
|
184 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
185 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
186 | + 'status' => $invoice_object->post_status, |
|
187 | + 'author' => $invoice_object->post_author, |
|
188 | + 'description' => $invoice_object->post_excerpt, |
|
189 | + 'parent_id' => $invoice_object->post_parent, |
|
190 | + 'name' => $invoice_object->post_title, |
|
191 | + 'path' => $invoice_object->post_name, |
|
192 | + 'post_type' => $invoice_object->post_type, |
|
193 | + ) |
|
194 | + ); |
|
195 | + |
|
196 | + $invoice->set_type( $invoice_object->post_type ); |
|
197 | + |
|
198 | + $this->read_object_data( $invoice, $invoice_object ); |
|
199 | + $this->add_special_fields( $invoice ); |
|
200 | + $this->add_items( $invoice ); |
|
201 | + $invoice->read_meta_data(); |
|
202 | + $invoice->set_object_read( true ); |
|
203 | + do_action( 'getpaid_read_' . $invoice->get_type(), $invoice ); |
|
204 | + |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Method to update an invoice in the database. |
|
209 | + * |
|
210 | + * @param WPInv_Invoice $invoice Invoice object. |
|
211 | + */ |
|
212 | + public function update( &$invoice ) { |
|
213 | + $invoice->save_meta_data(); |
|
214 | + $invoice->set_version( WPINV_VERSION ); |
|
215 | + |
|
216 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
217 | + $invoice->set_date_created( current_time('mysql') ); |
|
218 | + } |
|
219 | + |
|
220 | + // Ensure both the key and number are set. |
|
221 | + $invoice->get_key(); |
|
222 | + $invoice->get_number(); |
|
223 | + |
|
224 | + // Grab the current status so we can compare. |
|
225 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
226 | + |
|
227 | + $changes = $invoice->get_changes(); |
|
228 | + |
|
229 | + // Only update the post when the post data changes. |
|
230 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
231 | + $post_data = array( |
|
232 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
233 | + 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
234 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
235 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
236 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
237 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
238 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
239 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
240 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
241 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
242 | + ); |
|
243 | + |
|
244 | + /** |
|
245 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
246 | + * to update data, since wp_update_post spawns more calls to the |
|
247 | + * save_post action. |
|
248 | + * |
|
249 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
250 | + * or an update purely from CRUD. |
|
251 | + */ |
|
252 | + if ( doing_action( 'save_post' ) ) { |
|
253 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
254 | + clean_post_cache( $invoice->get_id() ); |
|
255 | + } else { |
|
256 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
257 | + } |
|
258 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
259 | + } |
|
260 | + |
|
261 | + // Update meta data. |
|
262 | + $this->update_post_meta( $invoice ); |
|
263 | + |
|
264 | + // Save special fields and items. |
|
265 | + $this->save_special_fields( $invoice ); |
|
266 | + $this->save_items( $invoice ); |
|
267 | + |
|
268 | + // Apply the changes. |
|
269 | + $invoice->apply_changes(); |
|
270 | + |
|
271 | + // Clear caches. |
|
272 | + $this->clear_caches( $invoice ); |
|
273 | + |
|
274 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
275 | + $new_status = $invoice->get_status( 'edit' ); |
|
276 | + |
|
277 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
278 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
279 | + } else { |
|
280 | + do_action( 'getpaid_update_' . $invoice->get_type(), $invoice ); |
|
281 | + } |
|
282 | + |
|
283 | + } |
|
284 | + |
|
285 | + /* |
|
286 | 286 | |-------------------------------------------------------------------------- |
287 | 287 | | Additional Methods |
288 | 288 | |-------------------------------------------------------------------------- |
289 | 289 | */ |
290 | 290 | |
291 | - /** |
|
291 | + /** |
|
292 | 292 | * Retrieves special fields and adds to the invoice. |
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice Invoice object. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice Invoice object. |
|
295 | 295 | */ |
296 | 296 | public function add_special_fields( &$invoice ) { |
297 | - global $wpdb; |
|
297 | + global $wpdb; |
|
298 | 298 | |
299 | - // Maybe retrieve from the cache. |
|
300 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
299 | + // Maybe retrieve from the cache. |
|
300 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
301 | 301 | |
302 | - // If not found, retrieve from the db. |
|
303 | - if ( false === $data ) { |
|
304 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
302 | + // If not found, retrieve from the db. |
|
303 | + if ( false === $data ) { |
|
304 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
305 | 305 | |
306 | - $data = $wpdb->get_row( |
|
307 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
308 | - ARRAY_A |
|
309 | - ); |
|
306 | + $data = $wpdb->get_row( |
|
307 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
308 | + ARRAY_A |
|
309 | + ); |
|
310 | 310 | |
311 | - // Update the cache with our data |
|
312 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
311 | + // Update the cache with our data |
|
312 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
313 | 313 | |
314 | - } |
|
314 | + } |
|
315 | 315 | |
316 | - // Abort if the data does not exist. |
|
317 | - if ( empty( $data ) ) { |
|
318 | - $invoice->set_object_read( true ); |
|
319 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
320 | - return; |
|
321 | - } |
|
316 | + // Abort if the data does not exist. |
|
317 | + if ( empty( $data ) ) { |
|
318 | + $invoice->set_object_read( true ); |
|
319 | + $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
320 | + return; |
|
321 | + } |
|
322 | 322 | |
323 | - $props = array(); |
|
323 | + $props = array(); |
|
324 | 324 | |
325 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
325 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
326 | 326 | |
327 | - if ( $db_field == 'post_id' ) { |
|
328 | - continue; |
|
329 | - } |
|
330 | - |
|
331 | - $props[ $prop ] = $data[ $db_field ]; |
|
332 | - } |
|
333 | - |
|
334 | - $invoice->set_props( $props ); |
|
335 | - |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Gets a list of special fields that need updated based on change state |
|
340 | - * or if they are present in the database or not. |
|
341 | - * |
|
342 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
343 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
344 | - */ |
|
345 | - protected function get_special_fields_to_update( $invoice ) { |
|
346 | - $fields_to_update = array(); |
|
347 | - $changed_props = $invoice->get_changes(); |
|
348 | - |
|
349 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
350 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
351 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
352 | - $fields_to_update[ $database_field ] = $prop; |
|
353 | - } |
|
354 | - } |
|
355 | - |
|
356 | - return $fields_to_update; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
361 | - * |
|
362 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
363 | - * @since 1.0.19 |
|
364 | - */ |
|
365 | - protected function update_special_fields( &$invoice ) { |
|
366 | - global $wpdb; |
|
367 | - |
|
368 | - $updated_props = array(); |
|
369 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
370 | - |
|
371 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
372 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
373 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
374 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
375 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
376 | - } |
|
377 | - |
|
378 | - if ( ! empty( $updated_props ) ) { |
|
379 | - |
|
380 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
381 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
382 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
383 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
384 | - |
|
385 | - } |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Helper method that inserts special fields to the database. |
|
391 | - * |
|
392 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
393 | - * @since 1.0.19 |
|
394 | - */ |
|
395 | - protected function insert_special_fields( &$invoice ) { |
|
396 | - global $wpdb; |
|
397 | - |
|
398 | - $updated_props = array(); |
|
399 | - |
|
400 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
401 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
402 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
403 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
404 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
405 | - } |
|
406 | - |
|
407 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
408 | - $wpdb->insert( $table, $updated_props ); |
|
409 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
410 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
411 | - |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
327 | + if ( $db_field == 'post_id' ) { |
|
328 | + continue; |
|
329 | + } |
|
330 | + |
|
331 | + $props[ $prop ] = $data[ $db_field ]; |
|
332 | + } |
|
333 | + |
|
334 | + $invoice->set_props( $props ); |
|
335 | + |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Gets a list of special fields that need updated based on change state |
|
340 | + * or if they are present in the database or not. |
|
341 | + * |
|
342 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
343 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
344 | + */ |
|
345 | + protected function get_special_fields_to_update( $invoice ) { |
|
346 | + $fields_to_update = array(); |
|
347 | + $changed_props = $invoice->get_changes(); |
|
348 | + |
|
349 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
350 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
351 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
352 | + $fields_to_update[ $database_field ] = $prop; |
|
353 | + } |
|
354 | + } |
|
355 | + |
|
356 | + return $fields_to_update; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
361 | + * |
|
362 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
363 | + * @since 1.0.19 |
|
364 | + */ |
|
365 | + protected function update_special_fields( &$invoice ) { |
|
366 | + global $wpdb; |
|
367 | + |
|
368 | + $updated_props = array(); |
|
369 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
370 | + |
|
371 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
372 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
373 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
374 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
375 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
376 | + } |
|
377 | + |
|
378 | + if ( ! empty( $updated_props ) ) { |
|
379 | + |
|
380 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
381 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
382 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
383 | + do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
384 | + |
|
385 | + } |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Helper method that inserts special fields to the database. |
|
391 | + * |
|
392 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
393 | + * @since 1.0.19 |
|
394 | + */ |
|
395 | + protected function insert_special_fields( &$invoice ) { |
|
396 | + global $wpdb; |
|
397 | + |
|
398 | + $updated_props = array(); |
|
399 | + |
|
400 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
401 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
402 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
403 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
404 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
405 | + } |
|
406 | + |
|
407 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
408 | + $wpdb->insert( $table, $updated_props ); |
|
409 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
410 | + do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
411 | + |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | 415 | * Saves all special fields. |
416 | - * |
|
417 | - * @param WPInv_Invoice $invoice Invoice object. |
|
416 | + * |
|
417 | + * @param WPInv_Invoice $invoice Invoice object. |
|
418 | 418 | */ |
419 | 419 | public function save_special_fields( $invoice ) { |
420 | - global $wpdb; |
|
420 | + global $wpdb; |
|
421 | 421 | |
422 | - // The invoices table. |
|
423 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
424 | - $id = (int) $invoice->get_id(); |
|
422 | + // The invoices table. |
|
423 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
424 | + $id = (int) $invoice->get_id(); |
|
425 | 425 | |
426 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
426 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
427 | 427 | |
428 | - $this->update_special_fields( $invoice ); |
|
428 | + $this->update_special_fields( $invoice ); |
|
429 | 429 | |
430 | - } else { |
|
430 | + } else { |
|
431 | 431 | |
432 | - $this->insert_special_fields( $invoice ); |
|
432 | + $this->insert_special_fields( $invoice ); |
|
433 | 433 | |
434 | - } |
|
434 | + } |
|
435 | 435 | |
436 | - } |
|
436 | + } |
|
437 | 437 | |
438 | - /** |
|
438 | + /** |
|
439 | 439 | * Set's up cart details. |
440 | - * |
|
441 | - * @param WPInv_Invoice $invoice Invoice object. |
|
440 | + * |
|
441 | + * @param WPInv_Invoice $invoice Invoice object. |
|
442 | 442 | */ |
443 | 443 | public function add_items( &$invoice ) { |
444 | - global $wpdb; |
|
444 | + global $wpdb; |
|
445 | 445 | |
446 | - // Maybe retrieve from the cache. |
|
447 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
446 | + // Maybe retrieve from the cache. |
|
447 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
448 | 448 | |
449 | - // If not found, retrieve from the db. |
|
450 | - if ( false === $items ) { |
|
451 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
449 | + // If not found, retrieve from the db. |
|
450 | + if ( false === $items ) { |
|
451 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
452 | 452 | |
453 | - $items = $wpdb->get_results( |
|
454 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
455 | - ); |
|
453 | + $items = $wpdb->get_results( |
|
454 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
455 | + ); |
|
456 | 456 | |
457 | - // Update the cache with our data |
|
458 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
457 | + // Update the cache with our data |
|
458 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
459 | 459 | |
460 | - } |
|
460 | + } |
|
461 | 461 | |
462 | - // Abort if no items found. |
|
462 | + // Abort if no items found. |
|
463 | 463 | if ( empty( $items ) ) { |
464 | 464 | return; |
465 | - } |
|
465 | + } |
|
466 | 466 | |
467 | - foreach ( $items as $item_data ) { |
|
468 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
467 | + foreach ( $items as $item_data ) { |
|
468 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
469 | 469 | |
470 | - // Set item data. |
|
471 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
472 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
473 | - $item->set_name( $item_data->item_name ); |
|
474 | - $item->set_description( $item_data->item_description ); |
|
475 | - $item->set_price( $item_data->item_price ); |
|
476 | - $item->set_quantity( $item_data->quantity ); |
|
477 | - $item->set_item_meta( $item_data->meta ); |
|
470 | + // Set item data. |
|
471 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
472 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
473 | + $item->set_name( $item_data->item_name ); |
|
474 | + $item->set_description( $item_data->item_description ); |
|
475 | + $item->set_price( $item_data->item_price ); |
|
476 | + $item->set_quantity( $item_data->quantity ); |
|
477 | + $item->set_item_meta( $item_data->meta ); |
|
478 | 478 | |
479 | - $invoice->add_item( $item ); |
|
480 | - } |
|
479 | + $invoice->add_item( $item ); |
|
480 | + } |
|
481 | 481 | |
482 | - } |
|
482 | + } |
|
483 | 483 | |
484 | - /** |
|
484 | + /** |
|
485 | 485 | * Saves cart details. |
486 | - * |
|
487 | - * @param WPInv_Invoice $invoice Invoice object. |
|
486 | + * |
|
487 | + * @param WPInv_Invoice $invoice Invoice object. |
|
488 | 488 | */ |
489 | 489 | public function save_items( $invoice ) { |
490 | 490 | |
491 | - // Delete previously existing items. |
|
492 | - $this->delete_items( $invoice ); |
|
491 | + // Delete previously existing items. |
|
492 | + $this->delete_items( $invoice ); |
|
493 | 493 | |
494 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
494 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
495 | 495 | |
496 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
497 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
498 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
499 | - } |
|
496 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
497 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
498 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
499 | + } |
|
500 | 500 | |
501 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
502 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
501 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
502 | + do_action( "getpaid_invoice_save_items", $invoice ); |
|
503 | 503 | |
504 | - } |
|
504 | + } |
|
505 | 505 | |
506 | - /** |
|
506 | + /** |
|
507 | 507 | * Deletes an invoice's cart details from the database. |
508 | - * |
|
509 | - * @param WPInv_Invoice $invoice Invoice object. |
|
508 | + * |
|
509 | + * @param WPInv_Invoice $invoice Invoice object. |
|
510 | 510 | */ |
511 | 511 | public function delete_items( $invoice ) { |
512 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
513 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
514 | - } |
|
512 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
513 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
514 | + } |
|
515 | 515 | |
516 | - /** |
|
516 | + /** |
|
517 | 517 | * Deletes an invoice's special fields from the database. |
518 | - * |
|
519 | - * @param WPInv_Invoice $invoice Invoice object. |
|
518 | + * |
|
519 | + * @param WPInv_Invoice $invoice Invoice object. |
|
520 | 520 | */ |
521 | 521 | public function delete_special_fields( $invoice ) { |
522 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
523 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
522 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
523 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | } |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email_Sender { |
14 | 14 | |
15 | 15 | /** |
16 | - * Whether or not we should inline CSS into the email. |
|
17 | - */ |
|
18 | - public $inline_css = true; |
|
16 | + * Whether or not we should inline CSS into the email. |
|
17 | + */ |
|
18 | + public $inline_css = true; |
|
19 | 19 | |
20 | 20 | /** |
21 | - * The wp_mail() data. |
|
22 | - */ |
|
21 | + * The wp_mail() data. |
|
22 | + */ |
|
23 | 23 | public $wp_mail_data = null; |
24 | 24 | |
25 | 25 | /** |
26 | - * Sends a new email. |
|
26 | + * Sends a new email. |
|
27 | 27 | * |
28 | 28 | * @param string|array $to The recipients email or an array of recipient emails. |
29 | 29 | * @param string $subject The email's subject. |
@@ -31,35 +31,35 @@ discard block |
||
31 | 31 | * @param array $attachments The email attachments. |
32 | 32 | * |
33 | 33 | * @return bool |
34 | - */ |
|
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
34 | + */ |
|
35 | + public function send( $to, $subject, $email, $attachments = array() ) { |
|
36 | 36 | |
37 | - /* |
|
37 | + /* |
|
38 | 38 | * Allow to filter data on per-email basis. |
39 | 39 | */ |
40 | - $data = apply_filters( |
|
41 | - 'getpaid_email_data', |
|
42 | - array( |
|
43 | - 'to' => array_filter( wpinv_parse_list( $to ) ), |
|
44 | - 'subject' => $subject, |
|
45 | - 'email' => $email, |
|
46 | - 'headers' => $this->get_headers(), |
|
47 | - 'attachments' => $attachments, |
|
48 | - ), |
|
49 | - $this |
|
50 | - ); |
|
40 | + $data = apply_filters( |
|
41 | + 'getpaid_email_data', |
|
42 | + array( |
|
43 | + 'to' => array_filter( wpinv_parse_list( $to ) ), |
|
44 | + 'subject' => $subject, |
|
45 | + 'email' => $email, |
|
46 | + 'headers' => $this->get_headers(), |
|
47 | + 'attachments' => $attachments, |
|
48 | + ), |
|
49 | + $this |
|
50 | + ); |
|
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | 53 | $data = (array) wp_unslash( $data ); |
54 | 54 | |
55 | 55 | // Cache it. |
56 | - $this->wp_mail_data = $data; |
|
56 | + $this->wp_mail_data = $data; |
|
57 | 57 | |
58 | - // Attach our own hooks. |
|
59 | - $this->before_sending(); |
|
58 | + // Attach our own hooks. |
|
59 | + $this->before_sending(); |
|
60 | 60 | |
61 | - // Prepare the sending function. |
|
62 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
61 | + // Prepare the sending function. |
|
62 | + $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
63 | 63 | $result = false; |
64 | 64 | |
65 | 65 | foreach ( $this->wp_mail_data['to'] as $to ) { |
@@ -76,65 +76,65 @@ discard block |
||
76 | 76 | |
77 | 77 | } |
78 | 78 | |
79 | - // Remove our hooks. |
|
80 | - $this->after_sending(); |
|
79 | + // Remove our hooks. |
|
80 | + $this->after_sending(); |
|
81 | 81 | |
82 | - $this->wp_mail_data = null; |
|
82 | + $this->wp_mail_data = null; |
|
83 | 83 | |
84 | - return $result; |
|
84 | + return $result; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * Retrieves email headers. |
|
89 | - */ |
|
90 | - public function get_headers() { |
|
88 | + * Retrieves email headers. |
|
89 | + */ |
|
90 | + public function get_headers() { |
|
91 | 91 | |
92 | - $name = $this->get_from_name(); |
|
93 | - $reply_to = $this->get_reply_to(); |
|
94 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
92 | + $name = $this->get_from_name(); |
|
93 | + $reply_to = $this->get_reply_to(); |
|
94 | + $headers = array( "Reply-To:$name <$reply_to>" ); |
|
95 | 95 | |
96 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
96 | + return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
97 | 97 | |
98 | - } |
|
98 | + } |
|
99 | 99 | |
100 | 100 | /** |
101 | - * Fires before an email is sent |
|
102 | - * |
|
103 | - * @since 1.0.0 |
|
104 | - */ |
|
105 | - public function before_sending() { |
|
101 | + * Fires before an email is sent |
|
102 | + * |
|
103 | + * @since 1.0.0 |
|
104 | + */ |
|
105 | + public function before_sending() { |
|
106 | 106 | |
107 | 107 | do_action( 'getpaid_before_send_email', $this ); |
108 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
109 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
110 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
111 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
108 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
109 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
110 | + add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
111 | + add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
112 | 112 | |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | /** |
116 | - * Returns the from name. |
|
117 | - */ |
|
118 | - public function get_from_name() { |
|
116 | + * Returns the from name. |
|
117 | + */ |
|
118 | + public function get_from_name() { |
|
119 | 119 | |
120 | 120 | $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
121 | 121 | |
122 | - if ( empty( $from_name ) ) { |
|
123 | - $from_name = get_bloginfo( 'name' ); |
|
122 | + if ( empty( $from_name ) ) { |
|
123 | + $from_name = get_bloginfo( 'name' ); |
|
124 | 124 | } |
125 | 125 | |
126 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
126 | + return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | - * Returns the from email. |
|
131 | - */ |
|
132 | - public function get_from_address() { |
|
130 | + * Returns the from email. |
|
131 | + */ |
|
132 | + public function get_from_address() { |
|
133 | 133 | |
134 | 134 | $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
135 | 135 | |
136 | - if ( ! is_email( $from_address ) ) { |
|
137 | - $from_address = $this->default_from_address(); |
|
136 | + if ( ! is_email( $from_address ) ) { |
|
137 | + $from_address = $this->default_from_address(); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return $from_address; |
@@ -142,75 +142,75 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | - * The default emails from address. |
|
146 | - * |
|
147 | - * Defaults to wordpress@$sitename |
|
148 | - * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
149 | - * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
150 | - * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
151 | - * |
|
152 | - */ |
|
153 | - public function default_from_address() { |
|
154 | - |
|
155 | - // Get the site domain and get rid of www. |
|
156 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
157 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
158 | - $sitename = substr( $sitename, 4 ); |
|
159 | - } |
|
160 | - |
|
161 | - $from_email = 'wordpress@' . $sitename; |
|
162 | - |
|
163 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
145 | + * The default emails from address. |
|
146 | + * |
|
147 | + * Defaults to wordpress@$sitename |
|
148 | + * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
149 | + * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
150 | + * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
151 | + * |
|
152 | + */ |
|
153 | + public function default_from_address() { |
|
154 | + |
|
155 | + // Get the site domain and get rid of www. |
|
156 | + $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
157 | + if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
158 | + $sitename = substr( $sitename, 4 ); |
|
159 | + } |
|
160 | + |
|
161 | + $from_email = 'wordpress@' . $sitename; |
|
162 | + |
|
163 | + return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | - * Get the email reply-to. |
|
169 | - * |
|
170 | - * |
|
171 | - * @return string The email reply-to address. |
|
172 | - */ |
|
173 | - public function get_reply_to() { |
|
168 | + * Get the email reply-to. |
|
169 | + * |
|
170 | + * |
|
171 | + * @return string The email reply-to address. |
|
172 | + */ |
|
173 | + public function get_reply_to() { |
|
174 | 174 | |
175 | - $reply_to = wpinv_get_admin_email(); |
|
175 | + $reply_to = wpinv_get_admin_email(); |
|
176 | 176 | |
177 | - if ( ! is_email( $reply_to ) ) { |
|
178 | - $reply_to = get_option( 'admin_email' ); |
|
179 | - } |
|
177 | + if ( ! is_email( $reply_to ) ) { |
|
178 | + $reply_to = get_option( 'admin_email' ); |
|
179 | + } |
|
180 | 180 | |
181 | - return $reply_to; |
|
181 | + return $reply_to; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Get the email content type. |
|
186 | - * |
|
187 | - */ |
|
188 | - public function get_content_type() { |
|
189 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
185 | + * Get the email content type. |
|
186 | + * |
|
187 | + */ |
|
188 | + public function get_content_type() { |
|
189 | + return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Ensures that our email messages are not messed up by template plugins. |
|
194 | - * |
|
195 | - * @return array wp_mail_data. |
|
196 | - */ |
|
197 | - public function ensure_email_content( $args ) { |
|
198 | - $args['message'] = $this->wp_mail_data['email']; |
|
199 | - return $args; |
|
193 | + * Ensures that our email messages are not messed up by template plugins. |
|
194 | + * |
|
195 | + * @return array wp_mail_data. |
|
196 | + */ |
|
197 | + public function ensure_email_content( $args ) { |
|
198 | + $args['message'] = $this->wp_mail_data['email']; |
|
199 | + return $args; |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
203 | - * A little house keeping after an email is sent. |
|
204 | - * |
|
205 | - */ |
|
206 | - public function after_sending() { |
|
203 | + * A little house keeping after an email is sent. |
|
204 | + * |
|
205 | + */ |
|
206 | + public function after_sending() { |
|
207 | 207 | |
208 | 208 | do_action( 'after_noptin_sends_email', $this->wp_mail_data ); |
209 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
210 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
211 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
212 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
209 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
210 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
211 | + remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
212 | + remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
213 | 213 | |
214 | - } |
|
214 | + } |
|
215 | 215 | |
216 | 216 | } |
@@ -12,119 +12,119 @@ |
||
12 | 12 | */ |
13 | 13 | class WPInv_Notes { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct() { |
|
19 | - |
|
20 | - // Filter inovice notes. |
|
21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
23 | - |
|
24 | - // Fires after notes are loaded. |
|
25 | - do_action( 'wpinv_notes_init', $this ); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Filters invoice notes query to only include our notes. |
|
30 | - * |
|
31 | - * @param WP_Comment_Query $query |
|
32 | - */ |
|
33 | - public function set_invoice_note_type( $query ) { |
|
34 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
35 | - |
|
36 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
37 | - $query->query_vars['type'] = 'wpinv_note'; |
|
38 | - } else { |
|
39 | - |
|
40 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
41 | - $query->query_vars['type__not_in'] = array(); |
|
42 | - } |
|
43 | - |
|
44 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
45 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
46 | - } |
|
47 | - |
|
48 | - return $query; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Exclude notes from the comments feed. |
|
53 | - */ |
|
54 | - function wpinv_comment_feed_where( $where ){ |
|
55 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Returns an array of invoice notes. |
|
60 | - * |
|
61 | - * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
62 | - * @param string $type Optional. Pass in customer to only return customer notes. |
|
63 | - * @return WP_Comment[] |
|
64 | - */ |
|
65 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
66 | - |
|
67 | - // Default comment args. |
|
68 | - $args = array( |
|
69 | - 'post_id' => $invoice_id, |
|
70 | - 'orderby' => 'comment_ID', |
|
71 | - 'order' => 'ASC', |
|
72 | - ); |
|
73 | - |
|
74 | - // Maybe only show customer comments. |
|
75 | - if ( $type == 'customer' ) { |
|
76 | - $args['meta_key'] = '_wpi_customer_note'; |
|
77 | - $args['meta_value'] = 1; |
|
78 | - } |
|
79 | - |
|
80 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
81 | - |
|
82 | - return get_comments( $args ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Saves an invoice comment. |
|
87 | - * |
|
88 | - * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
89 | - * @param string $note The note content. |
|
90 | - * @param string $note_author The name of the author of the note. |
|
91 | - * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
92 | - * @return int|false The new note's ID on success, false on failure. |
|
93 | - */ |
|
94 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){ |
|
95 | - |
|
96 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
97 | - |
|
98 | - /** |
|
99 | - * Insert the comment. |
|
100 | - */ |
|
101 | - $note_id = wp_insert_comment( |
|
102 | - wp_filter_comment( |
|
103 | - array( |
|
104 | - 'comment_post_ID' => $invoice->get_id(), |
|
105 | - 'comment_content' => $note, |
|
106 | - 'comment_agent' => 'Invoicing', |
|
107 | - 'user_id' => get_current_user_id(), |
|
108 | - 'comment_author' => $note_author, |
|
109 | - 'comment_author_IP' => wpinv_get_ip(), |
|
110 | - 'comment_author_email' => $author_email, |
|
111 | - 'comment_author_url' => $invoice->get_view_url(), |
|
112 | - 'comment_type' => 'wpinv_note', |
|
113 | - ) |
|
114 | - ) |
|
115 | - ); |
|
116 | - |
|
117 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
118 | - |
|
119 | - // Are we notifying the customer? |
|
120 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
121 | - return $note_id; |
|
122 | - } |
|
123 | - |
|
124 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
125 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) ); |
|
126 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
127 | - return $note_id; |
|
128 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct() { |
|
19 | + |
|
20 | + // Filter inovice notes. |
|
21 | + add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
22 | + add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
23 | + |
|
24 | + // Fires after notes are loaded. |
|
25 | + do_action( 'wpinv_notes_init', $this ); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Filters invoice notes query to only include our notes. |
|
30 | + * |
|
31 | + * @param WP_Comment_Query $query |
|
32 | + */ |
|
33 | + public function set_invoice_note_type( $query ) { |
|
34 | + $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
35 | + |
|
36 | + if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
37 | + $query->query_vars['type'] = 'wpinv_note'; |
|
38 | + } else { |
|
39 | + |
|
40 | + if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
41 | + $query->query_vars['type__not_in'] = array(); |
|
42 | + } |
|
43 | + |
|
44 | + $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
45 | + $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
46 | + } |
|
47 | + |
|
48 | + return $query; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Exclude notes from the comments feed. |
|
53 | + */ |
|
54 | + function wpinv_comment_feed_where( $where ){ |
|
55 | + return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Returns an array of invoice notes. |
|
60 | + * |
|
61 | + * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
62 | + * @param string $type Optional. Pass in customer to only return customer notes. |
|
63 | + * @return WP_Comment[] |
|
64 | + */ |
|
65 | + public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
66 | + |
|
67 | + // Default comment args. |
|
68 | + $args = array( |
|
69 | + 'post_id' => $invoice_id, |
|
70 | + 'orderby' => 'comment_ID', |
|
71 | + 'order' => 'ASC', |
|
72 | + ); |
|
73 | + |
|
74 | + // Maybe only show customer comments. |
|
75 | + if ( $type == 'customer' ) { |
|
76 | + $args['meta_key'] = '_wpi_customer_note'; |
|
77 | + $args['meta_value'] = 1; |
|
78 | + } |
|
79 | + |
|
80 | + $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
81 | + |
|
82 | + return get_comments( $args ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Saves an invoice comment. |
|
87 | + * |
|
88 | + * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
89 | + * @param string $note The note content. |
|
90 | + * @param string $note_author The name of the author of the note. |
|
91 | + * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
92 | + * @return int|false The new note's ID on success, false on failure. |
|
93 | + */ |
|
94 | + function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){ |
|
95 | + |
|
96 | + do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
97 | + |
|
98 | + /** |
|
99 | + * Insert the comment. |
|
100 | + */ |
|
101 | + $note_id = wp_insert_comment( |
|
102 | + wp_filter_comment( |
|
103 | + array( |
|
104 | + 'comment_post_ID' => $invoice->get_id(), |
|
105 | + 'comment_content' => $note, |
|
106 | + 'comment_agent' => 'Invoicing', |
|
107 | + 'user_id' => get_current_user_id(), |
|
108 | + 'comment_author' => $note_author, |
|
109 | + 'comment_author_IP' => wpinv_get_ip(), |
|
110 | + 'comment_author_email' => $author_email, |
|
111 | + 'comment_author_url' => $invoice->get_view_url(), |
|
112 | + 'comment_type' => 'wpinv_note', |
|
113 | + ) |
|
114 | + ) |
|
115 | + ); |
|
116 | + |
|
117 | + do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
118 | + |
|
119 | + // Are we notifying the customer? |
|
120 | + if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
121 | + return $note_id; |
|
122 | + } |
|
123 | + |
|
124 | + add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
125 | + do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) ); |
|
126 | + do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
127 | + return $note_id; |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
@@ -15,314 +15,314 @@ |
||
15 | 15 | class GetPaid_Invoice_Notification_Emails { |
16 | 16 | |
17 | 17 | /** |
18 | - * The array of invoice email actions. |
|
19 | - * |
|
20 | - * @param array |
|
21 | - */ |
|
22 | - public $invoice_actions; |
|
18 | + * The array of invoice email actions. |
|
19 | + * |
|
20 | + * @param array |
|
21 | + */ |
|
22 | + public $invoice_actions; |
|
23 | 23 | |
24 | 24 | /** |
25 | - * Class constructor |
|
25 | + * Class constructor |
|
26 | 26 | * |
27 | - */ |
|
28 | - public function __construct() { |
|
29 | - |
|
30 | - $this->invoice_actions = apply_filters( |
|
31 | - 'getpaid_notification_email_invoice_triggers', |
|
32 | - array( |
|
33 | - 'getpaid_new_invoice' => 'new_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
36 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
38 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
39 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
40 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
41 | - 'getpaid_new_invoice' => 'user_invoice', |
|
42 | - 'getpaid_new_customer_note' => 'user_note', |
|
43 | - 'getpaid_subscriptions_daily_cron' => 'overdue', |
|
27 | + */ |
|
28 | + public function __construct() { |
|
29 | + |
|
30 | + $this->invoice_actions = apply_filters( |
|
31 | + 'getpaid_notification_email_invoice_triggers', |
|
32 | + array( |
|
33 | + 'getpaid_new_invoice' => 'new_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
36 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
38 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
39 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
40 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
41 | + 'getpaid_new_invoice' => 'user_invoice', |
|
42 | + 'getpaid_new_customer_note' => 'user_note', |
|
43 | + 'getpaid_subscriptions_daily_cron' => 'overdue', |
|
44 | 44 | |
45 | - ) |
|
46 | - ); |
|
45 | + ) |
|
46 | + ); |
|
47 | 47 | |
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | - * Registers email hooks. |
|
52 | - */ |
|
53 | - public function init_hooks() { |
|
54 | - |
|
55 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 3 ); |
|
56 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
57 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
58 | - |
|
59 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
60 | - |
|
61 | - if ( $email->is_active() && method_exists( $this, $email_type ) ) { |
|
62 | - add_action( $hook, array( $this, $email_type ), 10, 2 ); |
|
63 | - } else { |
|
64 | - do_action( 'getpaid_hook_invoice_notification_email_invoice_trigger', $email ); |
|
65 | - } |
|
66 | - |
|
67 | - } |
|
68 | - |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Filters invoice merge tags. |
|
73 | - * |
|
74 | - * @param array $merge_tags |
|
75 | - * @param string $email_type |
|
76 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
77 | - */ |
|
78 | - public function invoice_merge_tags( $merge_tags, $email_type, $object ) { |
|
79 | - |
|
80 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
81 | - $merge_tags = array_merge( |
|
82 | - $merge_tags, |
|
83 | - $this->get_invoice_merge_tags( $object ) |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
88 | - $merge_tags = array_merge( |
|
89 | - $merge_tags, |
|
90 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
91 | - ); |
|
92 | - } |
|
93 | - |
|
94 | - return apply_filters( 'getpaid_invoice_notification_merge_tags', $merge_tags, $object, $email_type, $this ); |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Generates invoice merge tags. |
|
100 | - * |
|
101 | - * @param WPInv_Invoice $invoice |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function get_invoice_merge_tags( $invoice ) { |
|
105 | - |
|
106 | - // Abort if it does not exist. |
|
107 | - if ( ! $invoice->get_id() ) { |
|
108 | - return array(); |
|
109 | - } |
|
110 | - |
|
111 | - return array( |
|
112 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
113 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
114 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
115 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
116 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
117 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
118 | - '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
119 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
120 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
121 | - '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
122 | - '{invoice_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ), |
|
123 | - '{invoice_due_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ), |
|
124 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
125 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
126 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
127 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
128 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
129 | - ); |
|
130 | - |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Helper function to send an email. |
|
135 | - * |
|
136 | - * @param WPInv_Invoice $invoice |
|
137 | - * @param GetPaid_Notification_Email $email |
|
138 | - * @param string $type |
|
139 | - * @param string|array $recipients |
|
140 | - * @param array $extra_args Extra template args. |
|
141 | - */ |
|
142 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
143 | - |
|
144 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
145 | - |
|
146 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
147 | - $merge_tags = $email->get_merge_tags(); |
|
148 | - |
|
149 | - $result = $mailer->send( |
|
150 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
151 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
152 | - $email->get_content( $merge_tags, $extra_args ), |
|
153 | - $email->get_attachments() |
|
154 | - ); |
|
155 | - |
|
156 | - // Maybe send a copy to the admin. |
|
157 | - if ( $email->include_admin_bcc() ) { |
|
158 | - $mailer->send( |
|
159 | - wpinv_get_admin_email(), |
|
160 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
161 | - $email->get_content( $merge_tags ), |
|
162 | - $email->get_attachments() |
|
163 | - ); |
|
164 | - } |
|
165 | - |
|
166 | - if ( ! $result ) { |
|
167 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
168 | - } |
|
169 | - |
|
170 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
171 | - |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Also send emails to any cc users. |
|
176 | - * |
|
177 | - * @param array $recipients |
|
178 | - * @param GetPaid_Notification_Email $email |
|
179 | - */ |
|
180 | - public function filter_email_recipients( $recipients, $email ) { |
|
181 | - |
|
182 | - if ( ! $email->is_admin_email() ) { |
|
183 | - $cc = $email->object->get_email_cc(); |
|
184 | - |
|
185 | - if ( ! empty( $cc ) ) { |
|
186 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
187 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
188 | - } |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - return $recipients; |
|
193 | - |
|
194 | - } |
|
51 | + * Registers email hooks. |
|
52 | + */ |
|
53 | + public function init_hooks() { |
|
54 | + |
|
55 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 3 ); |
|
56 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
57 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
58 | + |
|
59 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
60 | + |
|
61 | + if ( $email->is_active() && method_exists( $this, $email_type ) ) { |
|
62 | + add_action( $hook, array( $this, $email_type ), 10, 2 ); |
|
63 | + } else { |
|
64 | + do_action( 'getpaid_hook_invoice_notification_email_invoice_trigger', $email ); |
|
65 | + } |
|
66 | + |
|
67 | + } |
|
68 | + |
|
69 | + } |
|
195 | 70 | |
196 | 71 | /** |
197 | - * Sends a new invoice notification. |
|
198 | - * |
|
199 | - * @param WPInv_Invoice $invoice |
|
200 | - */ |
|
201 | - public function new_invoice( $invoice ) { |
|
72 | + * Filters invoice merge tags. |
|
73 | + * |
|
74 | + * @param array $merge_tags |
|
75 | + * @param string $email_type |
|
76 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
77 | + */ |
|
78 | + public function invoice_merge_tags( $merge_tags, $email_type, $object ) { |
|
79 | + |
|
80 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
81 | + $merge_tags = array_merge( |
|
82 | + $merge_tags, |
|
83 | + $this->get_invoice_merge_tags( $object ) |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
88 | + $merge_tags = array_merge( |
|
89 | + $merge_tags, |
|
90 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
91 | + ); |
|
92 | + } |
|
93 | + |
|
94 | + return apply_filters( 'getpaid_invoice_notification_merge_tags', $merge_tags, $object, $email_type, $this ); |
|
202 | 95 | |
203 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
204 | - $recipient = wpinv_get_admin_email(); |
|
96 | + } |
|
205 | 97 | |
206 | - $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
98 | + /** |
|
99 | + * Generates invoice merge tags. |
|
100 | + * |
|
101 | + * @param WPInv_Invoice $invoice |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function get_invoice_merge_tags( $invoice ) { |
|
105 | + |
|
106 | + // Abort if it does not exist. |
|
107 | + if ( ! $invoice->get_id() ) { |
|
108 | + return array(); |
|
109 | + } |
|
110 | + |
|
111 | + return array( |
|
112 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
113 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
114 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
115 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
116 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
117 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
118 | + '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
119 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
120 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
121 | + '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
122 | + '{invoice_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ), |
|
123 | + '{invoice_due_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ), |
|
124 | + '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
125 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
126 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
127 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
128 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
129 | + ); |
|
207 | 130 | |
208 | - } |
|
131 | + } |
|
209 | 132 | |
210 | - /** |
|
211 | - * Sends a cancelled invoice notification. |
|
212 | - * |
|
213 | - * @param WPInv_Invoice $invoice |
|
214 | - */ |
|
215 | - public function cancelled_invoice( $invoice ) { |
|
133 | + /** |
|
134 | + * Helper function to send an email. |
|
135 | + * |
|
136 | + * @param WPInv_Invoice $invoice |
|
137 | + * @param GetPaid_Notification_Email $email |
|
138 | + * @param string $type |
|
139 | + * @param string|array $recipients |
|
140 | + * @param array $extra_args Extra template args. |
|
141 | + */ |
|
142 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
143 | + |
|
144 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
145 | + |
|
146 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
147 | + $merge_tags = $email->get_merge_tags(); |
|
148 | + |
|
149 | + $result = $mailer->send( |
|
150 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
151 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
152 | + $email->get_content( $merge_tags, $extra_args ), |
|
153 | + $email->get_attachments() |
|
154 | + ); |
|
155 | + |
|
156 | + // Maybe send a copy to the admin. |
|
157 | + if ( $email->include_admin_bcc() ) { |
|
158 | + $mailer->send( |
|
159 | + wpinv_get_admin_email(), |
|
160 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
161 | + $email->get_content( $merge_tags ), |
|
162 | + $email->get_attachments() |
|
163 | + ); |
|
164 | + } |
|
165 | + |
|
166 | + if ( ! $result ) { |
|
167 | + $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
168 | + } |
|
169 | + |
|
170 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
216 | 171 | |
217 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
218 | - $recipient = wpinv_get_admin_email(); |
|
172 | + } |
|
219 | 173 | |
220 | - $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
174 | + /** |
|
175 | + * Also send emails to any cc users. |
|
176 | + * |
|
177 | + * @param array $recipients |
|
178 | + * @param GetPaid_Notification_Email $email |
|
179 | + */ |
|
180 | + public function filter_email_recipients( $recipients, $email ) { |
|
221 | 181 | |
222 | - } |
|
182 | + if ( ! $email->is_admin_email() ) { |
|
183 | + $cc = $email->object->get_email_cc(); |
|
223 | 184 | |
224 | - /** |
|
225 | - * Sends a failed invoice notification. |
|
226 | - * |
|
227 | - * @param WPInv_Invoice $invoice |
|
228 | - */ |
|
229 | - public function failed_invoice( $invoice ) { |
|
185 | + if ( ! empty( $cc ) ) { |
|
186 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
187 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
188 | + } |
|
230 | 189 | |
231 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
232 | - $recipient = wpinv_get_admin_email(); |
|
190 | + } |
|
233 | 191 | |
234 | - $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
192 | + return $recipients; |
|
235 | 193 | |
236 | - } |
|
194 | + } |
|
237 | 195 | |
238 | - /** |
|
239 | - * Sends a notification whenever an invoice is put on hold. |
|
240 | - * |
|
241 | - * @param WPInv_Invoice $invoice |
|
242 | - */ |
|
243 | - public function onhold_invoice( $invoice ) { |
|
196 | + /** |
|
197 | + * Sends a new invoice notification. |
|
198 | + * |
|
199 | + * @param WPInv_Invoice $invoice |
|
200 | + */ |
|
201 | + public function new_invoice( $invoice ) { |
|
244 | 202 | |
245 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
246 | - $recipient = $invoice->get_email(); |
|
203 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
204 | + $recipient = wpinv_get_admin_email(); |
|
247 | 205 | |
248 | - $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
206 | + $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
249 | 207 | |
250 | - } |
|
208 | + } |
|
251 | 209 | |
252 | - /** |
|
253 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
254 | - * |
|
255 | - * @param WPInv_Invoice $invoice |
|
256 | - */ |
|
257 | - public function processing_invoice( $invoice ) { |
|
210 | + /** |
|
211 | + * Sends a cancelled invoice notification. |
|
212 | + * |
|
213 | + * @param WPInv_Invoice $invoice |
|
214 | + */ |
|
215 | + public function cancelled_invoice( $invoice ) { |
|
258 | 216 | |
259 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
260 | - $recipient = $invoice->get_email(); |
|
217 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
218 | + $recipient = wpinv_get_admin_email(); |
|
261 | 219 | |
262 | - $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
220 | + $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
263 | 221 | |
264 | - } |
|
222 | + } |
|
265 | 223 | |
266 | - /** |
|
267 | - * Sends a notification whenever an invoice is paid. |
|
268 | - * |
|
269 | - * @param WPInv_Invoice $invoice |
|
270 | - */ |
|
271 | - public function completed_invoice( $invoice ) { |
|
224 | + /** |
|
225 | + * Sends a failed invoice notification. |
|
226 | + * |
|
227 | + * @param WPInv_Invoice $invoice |
|
228 | + */ |
|
229 | + public function failed_invoice( $invoice ) { |
|
272 | 230 | |
273 | - // (Maybe) abort if it is a renewal invoice. |
|
274 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
275 | - return; |
|
276 | - } |
|
231 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
232 | + $recipient = wpinv_get_admin_email(); |
|
277 | 233 | |
278 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
279 | - $recipient = $invoice->get_email(); |
|
234 | + $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
280 | 235 | |
281 | - $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
236 | + } |
|
282 | 237 | |
283 | - } |
|
238 | + /** |
|
239 | + * Sends a notification whenever an invoice is put on hold. |
|
240 | + * |
|
241 | + * @param WPInv_Invoice $invoice |
|
242 | + */ |
|
243 | + public function onhold_invoice( $invoice ) { |
|
284 | 244 | |
285 | - /** |
|
286 | - * Sends a notification whenever an invoice is refunded. |
|
287 | - * |
|
288 | - * @param WPInv_Invoice $invoice |
|
289 | - */ |
|
290 | - public function refunded_invoice( $invoice ) { |
|
245 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
246 | + $recipient = $invoice->get_email(); |
|
291 | 247 | |
292 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
293 | - $recipient = $invoice->get_email(); |
|
248 | + $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
294 | 249 | |
295 | - $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
254 | + * |
|
255 | + * @param WPInv_Invoice $invoice |
|
256 | + */ |
|
257 | + public function processing_invoice( $invoice ) { |
|
258 | + |
|
259 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
260 | + $recipient = $invoice->get_email(); |
|
261 | + |
|
262 | + $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
263 | + |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Sends a notification whenever an invoice is paid. |
|
268 | + * |
|
269 | + * @param WPInv_Invoice $invoice |
|
270 | + */ |
|
271 | + public function completed_invoice( $invoice ) { |
|
272 | + |
|
273 | + // (Maybe) abort if it is a renewal invoice. |
|
274 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
279 | + $recipient = $invoice->get_email(); |
|
280 | + |
|
281 | + $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
296 | 282 | |
297 | - } |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Sends a notification whenever an invoice is refunded. |
|
287 | + * |
|
288 | + * @param WPInv_Invoice $invoice |
|
289 | + */ |
|
290 | + public function refunded_invoice( $invoice ) { |
|
291 | + |
|
292 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
293 | + $recipient = $invoice->get_email(); |
|
294 | + |
|
295 | + $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
296 | + |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * Notifies a user about new invoices |
|
301 | - * |
|
302 | - * @param WPInv_Invoice $invoice |
|
303 | - */ |
|
304 | - public function user_invoice( $invoice ) { |
|
299 | + /** |
|
300 | + * Notifies a user about new invoices |
|
301 | + * |
|
302 | + * @param WPInv_Invoice $invoice |
|
303 | + */ |
|
304 | + public function user_invoice( $invoice ) { |
|
305 | 305 | |
306 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
307 | - $recipient = $invoice->get_email(); |
|
306 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
307 | + $recipient = $invoice->get_email(); |
|
308 | 308 | |
309 | - $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
309 | + $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * Notifies admin about new invoice notes |
|
315 | - * |
|
316 | - * @param WPInv_Invoice $invoice |
|
317 | - * @param string $note |
|
318 | - */ |
|
319 | - public function user_note( $invoice, $note ) { |
|
313 | + /** |
|
314 | + * Notifies admin about new invoice notes |
|
315 | + * |
|
316 | + * @param WPInv_Invoice $invoice |
|
317 | + * @param string $note |
|
318 | + */ |
|
319 | + public function user_note( $invoice, $note ) { |
|
320 | 320 | |
321 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
322 | - $recipient = $invoice->get_email(); |
|
321 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
322 | + $recipient = $invoice->get_email(); |
|
323 | 323 | |
324 | - $this->send_email( $invoice, $email, __METHOD__, $recipient, array( 'customer_note' => $note ) ); |
|
324 | + $this->send_email( $invoice, $email, __METHOD__, $recipient, array( 'customer_note' => $note ) ); |
|
325 | 325 | |
326 | - } |
|
326 | + } |
|
327 | 327 | |
328 | 328 | } |
@@ -13,105 +13,105 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email { |
14 | 14 | |
15 | 15 | /** |
16 | - * Contains the type of this notification email. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Contains the type of this notification email. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id; |
21 | 21 | |
22 | 22 | /** |
23 | - * Contains any object to use in filters. |
|
24 | - * |
|
25 | - * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
26 | - */ |
|
23 | + * Contains any object to use in filters. |
|
24 | + * |
|
25 | + * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
26 | + */ |
|
27 | 27 | public $object; |
28 | 28 | |
29 | 29 | /** |
30 | - * Class constructor. |
|
31 | - * |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | 32 | * @param string $id Email Type. |
33 | 33 | * @param mixed $object Optional. Associated object. |
34 | - */ |
|
35 | - public function __construct( $id, $object = false ) { |
|
34 | + */ |
|
35 | + public function __construct( $id, $object = false ) { |
|
36 | 36 | $this->id = $id; |
37 | 37 | $this->object = $object; |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | - * Retrieves the email body. |
|
42 | - * |
|
41 | + * Retrieves the email body. |
|
42 | + * |
|
43 | 43 | * @return string |
44 | - */ |
|
45 | - public function get_body() { |
|
44 | + */ |
|
45 | + public function get_body() { |
|
46 | 46 | $body = wpinv_get_option( "email_{$this->id}_body" ); |
47 | 47 | return apply_filters( 'getpaid_get_email_body', $body, $this->id, $this->object ); |
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | - * Retrieves the email subject. |
|
52 | - * |
|
51 | + * Retrieves the email subject. |
|
52 | + * |
|
53 | 53 | * @return string |
54 | - */ |
|
55 | - public function get_subject() { |
|
54 | + */ |
|
55 | + public function get_subject() { |
|
56 | 56 | $subject = wpinv_get_option( "email_{$this->id}_subject" ); |
57 | 57 | return apply_filters( 'getpaid_get_email_subject', $subject, $this->id, $this->object ); |
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | - * Retrieves the email heading. |
|
62 | - * |
|
61 | + * Retrieves the email heading. |
|
62 | + * |
|
63 | 63 | * @return string |
64 | - */ |
|
65 | - public function get_heading() { |
|
64 | + */ |
|
65 | + public function get_heading() { |
|
66 | 66 | $heading = wpinv_get_option( "email_{$this->id}_heading" ); |
67 | 67 | return apply_filters( 'getpaid_get_email_heading', $heading, $this->id, $this->object ); |
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | - * Checks if an email is active. |
|
72 | - * |
|
71 | + * Checks if an email is active. |
|
72 | + * |
|
73 | 73 | * @return bool |
74 | - */ |
|
75 | - public function is_active() { |
|
74 | + */ |
|
75 | + public function is_active() { |
|
76 | 76 | $is_active = (bool) wpinv_get_option( "email_{$this->id}_active", false ); |
77 | 77 | return apply_filters( 'getpaid_email_type_is_active', $is_active, $this->id, $this->object ); |
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
81 | - * Checks if the site's admin should receive email notifications. |
|
82 | - * |
|
81 | + * Checks if the site's admin should receive email notifications. |
|
82 | + * |
|
83 | 83 | * @return bool |
84 | - */ |
|
85 | - public function include_admin_bcc() { |
|
84 | + */ |
|
85 | + public function include_admin_bcc() { |
|
86 | 86 | $include_admin_bcc = (bool) wpinv_get_option( "email_{$this->id}_admin_bcc", false ); |
87 | 87 | return apply_filters( 'getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object ); |
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | - * Checks whether this email should be sent to the customer or admin. |
|
92 | - * |
|
91 | + * Checks whether this email should be sent to the customer or admin. |
|
92 | + * |
|
93 | 93 | * @return bool |
94 | - */ |
|
95 | - public function is_admin_email() { |
|
94 | + */ |
|
95 | + public function is_admin_email() { |
|
96 | 96 | $is_admin_email = in_array( $this->id, array( 'new_invoice', 'cancelled_invoice', 'failed_invoice' ) ); |
97 | 97 | return apply_filters( 'getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object ); |
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | - * Returns email attachments. |
|
102 | - * |
|
101 | + * Returns email attachments. |
|
102 | + * |
|
103 | 103 | * @return array |
104 | - */ |
|
105 | - public function get_attachments() { |
|
104 | + */ |
|
105 | + public function get_attachments() { |
|
106 | 106 | return apply_filters( 'getpaid_get_email_attachments', array(), $this->id, $this->object ); |
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | - * Returns an array of merge tags. |
|
111 | - * |
|
110 | + * Returns an array of merge tags. |
|
111 | + * |
|
112 | 112 | * @return array |
113 | - */ |
|
114 | - public function get_merge_tags() { |
|
113 | + */ |
|
114 | + public function get_merge_tags() { |
|
115 | 115 | |
116 | 116 | $merge_tags = array( |
117 | 117 | '{site_title}' => wpinv_get_blogname(), |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | - * Adds merge tags to a text. |
|
126 | - * |
|
125 | + * Adds merge tags to a text. |
|
126 | + * |
|
127 | 127 | * @param string string $text |
128 | 128 | * @param array $merge_tags |
129 | 129 | * @return string |
130 | - */ |
|
131 | - public function add_merge_tags( $text, $merge_tags = array() ) { |
|
130 | + */ |
|
131 | + public function add_merge_tags( $text, $merge_tags = array() ) { |
|
132 | 132 | |
133 | 133 | foreach ( $merge_tags as $key => $value ) { |
134 | 134 | $text = str_replace( $key, $value, $text ); |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | - * Returns the email content |
|
142 | - * |
|
141 | + * Returns the email content |
|
142 | + * |
|
143 | 143 | * @param array $merge_tags |
144 | 144 | * @param array $extra_args Extra template args |
145 | 145 | * @return string |
146 | - */ |
|
147 | - public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
146 | + */ |
|
147 | + public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
148 | 148 | |
149 | 149 | return wpinv_get_template_html( |
150 | 150 | "emails/wpinv-email-{$this->id}.php", |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | class WPInv_Item extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'item'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'item'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'item'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Item Data array. This is the core item data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'parent_id' => 0, |
|
34 | - 'status' => 'draft', |
|
35 | - 'version' => '', |
|
36 | - 'date_created' => null, |
|
27 | + * Item Data array. This is the core item data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'parent_id' => 0, |
|
34 | + 'status' => 'draft', |
|
35 | + 'version' => '', |
|
36 | + 'date_created' => null, |
|
37 | 37 | 'date_modified' => null, |
38 | 38 | 'name' => '', |
39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | ); |
59 | 59 | |
60 | 60 | /** |
61 | - * Stores meta in cache for future reads. |
|
62 | - * |
|
63 | - * A group must be set to to enable caching. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - protected $cache_group = 'getpaid_items'; |
|
61 | + * Stores meta in cache for future reads. |
|
62 | + * |
|
63 | + * A group must be set to to enable caching. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + protected $cache_group = 'getpaid_items'; |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
74 | 74 | protected $post = null; |
75 | 75 | |
76 | 76 | /** |
77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | - * |
|
79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | - */ |
|
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
94 | - } else { |
|
95 | - $this->set_object_read( true ); |
|
96 | - } |
|
77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | + * |
|
79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | + */ |
|
81 | + public function __construct( $item = 0 ) { |
|
82 | + parent::__construct( $item ); |
|
83 | + |
|
84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | + $this->set_id( $item ); |
|
86 | + } elseif ( $item instanceof self ) { |
|
87 | + $this->set_id( $item->get_id() ); |
|
88 | + } elseif ( ! empty( $item->ID ) ) { |
|
89 | + $this->set_id( $item->ID ); |
|
90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | + $this->set_id( $item_id ); |
|
92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | + $this->set_id( $item_id ); |
|
94 | + } else { |
|
95 | + $this->set_object_read( true ); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
101 | + if ( $this->get_id() > 0 ) { |
|
102 | 102 | $this->post = get_post( $this->get_id() ); |
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read( $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | 109 | /* |
110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
122 | 122 | */ |
123 | 123 | |
124 | 124 | /** |
125 | - * Get parent item ID. |
|
126 | - * |
|
127 | - * @since 1.0.19 |
|
128 | - * @param string $context View or edit context. |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
125 | + * Get parent item ID. |
|
126 | + * |
|
127 | + * @since 1.0.19 |
|
128 | + * @param string $context View or edit context. |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function get_parent_id( $context = 'view' ) { |
|
132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Get item status. |
|
137 | - * |
|
138 | - * @since 1.0.19 |
|
139 | - * @param string $context View or edit context. |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
136 | + * Get item status. |
|
137 | + * |
|
138 | + * @since 1.0.19 |
|
139 | + * @param string $context View or edit context. |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function get_status( $context = 'view' ) { |
|
143 | + return $this->get_prop( 'status', $context ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Get plugin version when the item was created. |
|
148 | - * |
|
149 | - * @since 1.0.19 |
|
150 | - * @param string $context View or edit context. |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
147 | + * Get plugin version when the item was created. |
|
148 | + * |
|
149 | + * @since 1.0.19 |
|
150 | + * @param string $context View or edit context. |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public function get_version( $context = 'view' ) { |
|
154 | + return $this->get_prop( 'version', $context ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | - * Get date when the item was created. |
|
159 | - * |
|
160 | - * @since 1.0.19 |
|
161 | - * @param string $context View or edit context. |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
158 | + * Get date when the item was created. |
|
159 | + * |
|
160 | + * @since 1.0.19 |
|
161 | + * @param string $context View or edit context. |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + public function get_date_created( $context = 'view' ) { |
|
165 | + return $this->get_prop( 'date_created', $context ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | - * Get GMT date when the item was created. |
|
170 | - * |
|
171 | - * @since 1.0.19 |
|
172 | - * @param string $context View or edit context. |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
169 | + * Get GMT date when the item was created. |
|
170 | + * |
|
171 | + * @since 1.0.19 |
|
172 | + * @param string $context View or edit context. |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
176 | 176 | $date = $this->get_date_created( $context ); |
177 | 177 | |
178 | 178 | if ( $date ) { |
179 | 179 | $date = get_gmt_from_date( $date ); |
180 | 180 | } |
181 | - return $date; |
|
181 | + return $date; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Get date when the item was last modified. |
|
186 | - * |
|
187 | - * @since 1.0.19 |
|
188 | - * @param string $context View or edit context. |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
185 | + * Get date when the item was last modified. |
|
186 | + * |
|
187 | + * @since 1.0.19 |
|
188 | + * @param string $context View or edit context. |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function get_date_modified( $context = 'view' ) { |
|
192 | + return $this->get_prop( 'date_modified', $context ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Get GMT date when the item was last modified. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
196 | + * Get GMT date when the item was last modified. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | 203 | $date = $this->get_date_modified( $context ); |
204 | 204 | |
205 | 205 | if ( $date ) { |
206 | 206 | $date = get_gmt_from_date( $date ); |
207 | 207 | } |
208 | - return $date; |
|
208 | + return $date; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get the item name. |
|
213 | - * |
|
214 | - * @since 1.0.19 |
|
215 | - * @param string $context View or edit context. |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
212 | + * Get the item name. |
|
213 | + * |
|
214 | + * @since 1.0.19 |
|
215 | + * @param string $context View or edit context. |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function get_name( $context = 'view' ) { |
|
219 | + return $this->get_prop( 'name', $context ); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | - * Alias of self::get_name(). |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @param string $context View or edit context. |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
223 | + * Alias of self::get_name(). |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @param string $context View or edit context. |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function get_title( $context = 'view' ) { |
|
230 | + return $this->get_name( $context ); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | - * Get the item description. |
|
235 | - * |
|
236 | - * @since 1.0.19 |
|
237 | - * @param string $context View or edit context. |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
234 | + * Get the item description. |
|
235 | + * |
|
236 | + * @since 1.0.19 |
|
237 | + * @param string $context View or edit context. |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + public function get_description( $context = 'view' ) { |
|
241 | + return $this->get_prop( 'description', $context ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * Alias of self::get_description(). |
|
246 | - * |
|
247 | - * @since 1.0.19 |
|
248 | - * @param string $context View or edit context. |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
245 | + * Alias of self::get_description(). |
|
246 | + * |
|
247 | + * @since 1.0.19 |
|
248 | + * @param string $context View or edit context. |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function get_excerpt( $context = 'view' ) { |
|
252 | + return $this->get_description( $context ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | - * Alias of self::get_description(). |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - * @param string $context View or edit context. |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
256 | + * Alias of self::get_description(). |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + * @param string $context View or edit context. |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + public function get_summary( $context = 'view' ) { |
|
263 | + return $this->get_description( $context ); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | - * Get the owner of the item. |
|
268 | - * |
|
269 | - * @since 1.0.19 |
|
270 | - * @param string $context View or edit context. |
|
271 | - * @return int |
|
272 | - */ |
|
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
275 | - } |
|
267 | + * Get the owner of the item. |
|
268 | + * |
|
269 | + * @since 1.0.19 |
|
270 | + * @param string $context View or edit context. |
|
271 | + * @return int |
|
272 | + */ |
|
273 | + public function get_author( $context = 'view' ) { |
|
274 | + return (int) $this->get_prop( 'author', $context ); |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Alias of self::get_author(). |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @param string $context View or edit context. |
|
282 | - * @return int |
|
283 | - */ |
|
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Get the price of the item. |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @param string $context View or edit context. |
|
293 | - * @return float |
|
294 | - */ |
|
295 | - public function get_price( $context = 'view' ) { |
|
277 | + /** |
|
278 | + * Alias of self::get_author(). |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @param string $context View or edit context. |
|
282 | + * @return int |
|
283 | + */ |
|
284 | + public function get_owner( $context = 'view' ) { |
|
285 | + return $this->get_author( $context ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Get the price of the item. |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @param string $context View or edit context. |
|
293 | + * @return float |
|
294 | + */ |
|
295 | + public function get_price( $context = 'view' ) { |
|
296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
297 | - } |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * Get the inital price of the item. |
|
301 | - * |
|
302 | - * @since 1.0.19 |
|
303 | - * @param string $context View or edit context. |
|
304 | - * @return float |
|
305 | - */ |
|
306 | - public function get_initial_price( $context = 'view' ) { |
|
299 | + /** |
|
300 | + * Get the inital price of the item. |
|
301 | + * |
|
302 | + * @since 1.0.19 |
|
303 | + * @param string $context View or edit context. |
|
304 | + * @return float |
|
305 | + */ |
|
306 | + public function get_initial_price( $context = 'view' ) { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price( $context ); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
311 | - $price = 0; |
|
312 | - } |
|
310 | + if ( $this->has_free_trial() ) { |
|
311 | + $price = 0; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
318 | - * Returns a formated price. |
|
319 | - * |
|
320 | - * @since 1.0.19 |
|
321 | - * @param string $context View or edit context. |
|
322 | - * @return string |
|
323 | - */ |
|
318 | + * Returns a formated price. |
|
319 | + * |
|
320 | + * @since 1.0.19 |
|
321 | + * @param string $context View or edit context. |
|
322 | + * @return string |
|
323 | + */ |
|
324 | 324 | public function get_the_price() { |
325 | 325 | return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Returns the formated initial price. |
|
330 | - * |
|
331 | - * @since 1.0.19 |
|
332 | - * @param string $context View or edit context. |
|
333 | - * @return string |
|
334 | - */ |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Returns the formated initial price. |
|
330 | + * |
|
331 | + * @since 1.0.19 |
|
332 | + * @param string $context View or edit context. |
|
333 | + * @return string |
|
334 | + */ |
|
335 | 335 | public function get_the_initial_price() { |
336 | 336 | return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | - * Get the VAT rule of the item. |
|
341 | - * |
|
342 | - * @since 1.0.19 |
|
343 | - * @param string $context View or edit context. |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - public function get_vat_rule( $context = 'view' ) { |
|
340 | + * Get the VAT rule of the item. |
|
341 | + * |
|
342 | + * @since 1.0.19 |
|
343 | + * @param string $context View or edit context. |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + public function get_vat_rule( $context = 'view' ) { |
|
347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
351 | - * Get the VAT class of the item. |
|
352 | - * |
|
353 | - * @since 1.0.19 |
|
354 | - * @param string $context View or edit context. |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function get_vat_class( $context = 'view' ) { |
|
351 | + * Get the VAT class of the item. |
|
352 | + * |
|
353 | + * @since 1.0.19 |
|
354 | + * @param string $context View or edit context. |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function get_vat_class( $context = 'view' ) { |
|
358 | 358 | return $this->get_prop( 'vat_class', $context ); |
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
362 | - * Get the type of the item. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param string $context View or edit context. |
|
366 | - * @return string |
|
367 | - */ |
|
368 | - public function get_type( $context = 'view' ) { |
|
362 | + * Get the type of the item. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param string $context View or edit context. |
|
366 | + * @return string |
|
367 | + */ |
|
368 | + public function get_type( $context = 'view' ) { |
|
369 | 369 | return $this->get_prop( 'type', $context ); |
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
373 | - * Get the custom id of the item. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $context View or edit context. |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function get_custom_id( $context = 'view' ) { |
|
373 | + * Get the custom id of the item. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $context View or edit context. |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function get_custom_id( $context = 'view' ) { |
|
380 | 380 | return $this->get_prop( 'custom_id', $context ); |
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | - * Get the custom name of the item. |
|
385 | - * |
|
386 | - * @since 1.0.19 |
|
387 | - * @param string $context View or edit context. |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - public function get_custom_name( $context = 'view' ) { |
|
384 | + * Get the custom name of the item. |
|
385 | + * |
|
386 | + * @since 1.0.19 |
|
387 | + * @param string $context View or edit context. |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + public function get_custom_name( $context = 'view' ) { |
|
391 | 391 | return $this->get_prop( 'custom_name', $context ); |
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
395 | - * Get the custom singular name of the item. |
|
396 | - * |
|
397 | - * @since 1.0.19 |
|
398 | - * @param string $context View or edit context. |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
395 | + * Get the custom singular name of the item. |
|
396 | + * |
|
397 | + * @since 1.0.19 |
|
398 | + * @param string $context View or edit context. |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
406 | - * Checks if an item is editable.. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @param string $context View or edit context. |
|
410 | - * @return int |
|
411 | - */ |
|
412 | - public function get_is_editable( $context = 'view' ) { |
|
406 | + * Checks if an item is editable.. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @param string $context View or edit context. |
|
410 | + * @return int |
|
411 | + */ |
|
412 | + public function get_is_editable( $context = 'view' ) { |
|
413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
417 | - * Alias of self::get_is_editable(). |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - * @param string $context View or edit context. |
|
421 | - * @return int |
|
422 | - */ |
|
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
417 | + * Alias of self::get_is_editable(). |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + * @param string $context View or edit context. |
|
421 | + * @return int |
|
422 | + */ |
|
423 | + public function get_editable( $context = 'view' ) { |
|
424 | + return $this->get_is_editable( $context ); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Checks if dynamic pricing is enabled. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return int |
|
433 | - */ |
|
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
428 | + * Checks if dynamic pricing is enabled. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return int |
|
433 | + */ |
|
434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return float |
|
444 | - */ |
|
445 | - public function get_minimum_price( $context = 'view' ) { |
|
439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return float |
|
444 | + */ |
|
445 | + public function get_minimum_price( $context = 'view' ) { |
|
446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Checks if this is a recurring item. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return int |
|
455 | - */ |
|
456 | - public function get_is_recurring( $context = 'view' ) { |
|
450 | + * Checks if this is a recurring item. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return int |
|
455 | + */ |
|
456 | + public function get_is_recurring( $context = 'view' ) { |
|
457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
458 | - } |
|
458 | + } |
|
459 | 459 | |
460 | - /** |
|
461 | - * Get the recurring price of the item. |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - * @param string $context View or edit context. |
|
465 | - * @return float |
|
466 | - */ |
|
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
460 | + /** |
|
461 | + * Get the recurring price of the item. |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + * @param string $context View or edit context. |
|
465 | + * @return float |
|
466 | + */ |
|
467 | + public function get_recurring_price( $context = 'view' ) { |
|
468 | + $price = $this->get_price( $context ); |
|
469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Get the formatted recurring price of the item. |
|
474 | - * |
|
475 | - * @since 1.0.19 |
|
476 | - * @param string $context View or edit context. |
|
477 | - * @return string |
|
478 | - */ |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Get the formatted recurring price of the item. |
|
474 | + * |
|
475 | + * @since 1.0.19 |
|
476 | + * @param string $context View or edit context. |
|
477 | + * @return string |
|
478 | + */ |
|
479 | 479 | public function get_the_recurring_price() { |
480 | 480 | return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) ); |
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Get the first renewal date (in timestamps) of the item. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - * @return int |
|
488 | - */ |
|
489 | - public function get_first_renewal_date() { |
|
490 | - |
|
491 | - $periods = array( |
|
492 | - 'D' => 'days', |
|
493 | - 'W' => 'weeks', |
|
494 | - 'M' => 'months', |
|
495 | - 'Y' => 'years', |
|
496 | - ); |
|
497 | - |
|
498 | - $period = $this->get_recurring_period(); |
|
499 | - $interval = $this->get_recurring_interval(); |
|
500 | - |
|
501 | - if ( $this->has_free_trial() ) { |
|
502 | - $period = $this->get_trial_period(); |
|
503 | - $interval = $this->get_trial_interval(); |
|
504 | - } |
|
505 | - |
|
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Get the first renewal date (in timestamps) of the item. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + * @return int |
|
488 | + */ |
|
489 | + public function get_first_renewal_date() { |
|
490 | + |
|
491 | + $periods = array( |
|
492 | + 'D' => 'days', |
|
493 | + 'W' => 'weeks', |
|
494 | + 'M' => 'months', |
|
495 | + 'Y' => 'years', |
|
496 | + ); |
|
497 | + |
|
498 | + $period = $this->get_recurring_period(); |
|
499 | + $interval = $this->get_recurring_interval(); |
|
500 | + |
|
501 | + if ( $this->has_free_trial() ) { |
|
502 | + $period = $this->get_trial_period(); |
|
503 | + $interval = $this->get_trial_interval(); |
|
504 | + } |
|
505 | + |
|
506 | + $period = $periods[ $period ]; |
|
507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
513 | - * Get the recurring period. |
|
514 | - * |
|
515 | - * @since 1.0.19 |
|
516 | - * @param bool $full Return abbreviation or in full. |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - public function get_recurring_period( $full = false ) { |
|
513 | + * Get the recurring period. |
|
514 | + * |
|
515 | + * @since 1.0.19 |
|
516 | + * @param bool $full Return abbreviation or in full. |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + public function get_recurring_period( $full = false ) { |
|
520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
521 | 521 | |
522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,63 +527,63 @@ discard block |
||
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
530 | - * Get the recurring interval. |
|
531 | - * |
|
532 | - * @since 1.0.19 |
|
533 | - * @param string $context View or edit context. |
|
534 | - * @return int |
|
535 | - */ |
|
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
530 | + * Get the recurring interval. |
|
531 | + * |
|
532 | + * @since 1.0.19 |
|
533 | + * @param string $context View or edit context. |
|
534 | + * @return int |
|
535 | + */ |
|
536 | + public function get_recurring_interval( $context = 'view' ) { |
|
537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
538 | 538 | |
539 | - if ( $interval < 1 ) { |
|
540 | - $interval = 1; |
|
541 | - } |
|
539 | + if ( $interval < 1 ) { |
|
540 | + $interval = 1; |
|
541 | + } |
|
542 | 542 | |
543 | 543 | return $interval; |
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Get the recurring limit. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param string $context View or edit context. |
|
551 | - * @return int |
|
552 | - */ |
|
553 | - public function get_recurring_limit( $context = 'view' ) { |
|
547 | + * Get the recurring limit. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param string $context View or edit context. |
|
551 | + * @return int |
|
552 | + */ |
|
553 | + public function get_recurring_limit( $context = 'view' ) { |
|
554 | 554 | return (int) $this->get_prop( 'recurring_limit', $context ); |
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
558 | - * Checks if we have a free trial. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param string $context View or edit context. |
|
562 | - * @return int |
|
563 | - */ |
|
564 | - public function get_is_free_trial( $context = 'view' ) { |
|
558 | + * Checks if we have a free trial. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param string $context View or edit context. |
|
562 | + * @return int |
|
563 | + */ |
|
564 | + public function get_is_free_trial( $context = 'view' ) { |
|
565 | 565 | return (int) $this->get_prop( 'is_free_trial', $context ); |
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
569 | - * Alias for self::get_is_free_trial(). |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - * @param string $context View or edit context. |
|
573 | - * @return int |
|
574 | - */ |
|
575 | - public function get_free_trial( $context = 'view' ) { |
|
569 | + * Alias for self::get_is_free_trial(). |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + * @param string $context View or edit context. |
|
573 | + * @return int |
|
574 | + */ |
|
575 | + public function get_free_trial( $context = 'view' ) { |
|
576 | 576 | return $this->get_is_free_trial( $context ); |
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
580 | - * Get the trial period. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @param bool $full Return abbreviation or in full. |
|
584 | - * @return string |
|
585 | - */ |
|
586 | - public function get_trial_period( $full = false ) { |
|
580 | + * Get the trial period. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @param bool $full Return abbreviation or in full. |
|
584 | + * @return string |
|
585 | + */ |
|
586 | + public function get_trial_period( $full = false ) { |
|
587 | 587 | $period = $this->get_prop( 'trial_period', 'view' ); |
588 | 588 | |
589 | 589 | if ( $full && ! is_bool( $full ) ) { |
@@ -594,104 +594,104 @@ discard block |
||
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
597 | - * Get the trial interval. |
|
598 | - * |
|
599 | - * @since 1.0.19 |
|
600 | - * @param string $context View or edit context. |
|
601 | - * @return int |
|
602 | - */ |
|
603 | - public function get_trial_interval( $context = 'view' ) { |
|
597 | + * Get the trial interval. |
|
598 | + * |
|
599 | + * @since 1.0.19 |
|
600 | + * @param string $context View or edit context. |
|
601 | + * @return int |
|
602 | + */ |
|
603 | + public function get_trial_interval( $context = 'view' ) { |
|
604 | 604 | return (int) $this->get_prop( 'trial_interval', $context ); |
605 | - } |
|
605 | + } |
|
606 | 606 | |
607 | - /** |
|
608 | - * Get the item's edit url. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @return string |
|
612 | - */ |
|
613 | - public function get_edit_url() { |
|
607 | + /** |
|
608 | + * Get the item's edit url. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @return string |
|
612 | + */ |
|
613 | + public function get_edit_url() { |
|
614 | 614 | return get_edit_post_link( $this->get_id() ); |
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Given an item's name/custom id, it returns its id. |
|
619 | - * |
|
620 | - * |
|
621 | - * @static |
|
622 | - * @param string $value The item name or custom id. |
|
623 | - * @param string $field Either name or custom_id. |
|
624 | - * @param string $type in case you need to search for a given type. |
|
625 | - * @since 1.0.15 |
|
626 | - * @return int |
|
627 | - */ |
|
628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | - |
|
630 | - // Trim the value. |
|
631 | - $value = sanitize_text_field( $value ); |
|
632 | - |
|
633 | - if ( empty( $value ) ) { |
|
634 | - return 0; |
|
635 | - } |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Given an item's name/custom id, it returns its id. |
|
619 | + * |
|
620 | + * |
|
621 | + * @static |
|
622 | + * @param string $value The item name or custom id. |
|
623 | + * @param string $field Either name or custom_id. |
|
624 | + * @param string $type in case you need to search for a given type. |
|
625 | + * @since 1.0.15 |
|
626 | + * @return int |
|
627 | + */ |
|
628 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | + |
|
630 | + // Trim the value. |
|
631 | + $value = sanitize_text_field( $value ); |
|
632 | + |
|
633 | + if ( empty( $value ) ) { |
|
634 | + return 0; |
|
635 | + } |
|
636 | 636 | |
637 | 637 | // Valid fields. |
638 | 638 | $fields = array( 'custom_id', 'name', 'slug' ); |
639 | 639 | |
640 | - // Ensure a field has been passed. |
|
641 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
642 | - return 0; |
|
643 | - } |
|
644 | - |
|
645 | - if ( $field == 'name' ) { |
|
646 | - $field = 'slug'; |
|
647 | - } |
|
648 | - |
|
649 | - // Maybe retrieve from the cache. |
|
650 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | - if ( ! empty( $item_id ) ) { |
|
652 | - return $item_id; |
|
653 | - } |
|
654 | - |
|
655 | - // Fetch from the db. |
|
656 | - if ( $field =='slug' ) { |
|
657 | - $items = get_posts( |
|
658 | - array( |
|
659 | - 'post_type' => 'wpi_item', |
|
660 | - 'name' => $value, |
|
661 | - 'posts_per_page' => 1, |
|
662 | - 'post_status' => 'any', |
|
663 | - ) |
|
664 | - ); |
|
665 | - } |
|
666 | - |
|
667 | - if ( $field =='custom_id' ) { |
|
668 | - $items = get_posts( |
|
669 | - array( |
|
670 | - 'post_type' => 'wpi_item', |
|
671 | - 'posts_per_page' => 1, |
|
672 | - 'post_status' => 'any', |
|
673 | - 'meta_query' => array( |
|
674 | - array( |
|
675 | - 'key' => '_wpinv_type', |
|
676 | - 'value' => $type, |
|
677 | - ), |
|
678 | - array( |
|
679 | - 'key' => '_wpinv_custom_id', |
|
680 | - 'value' => $type, |
|
681 | - ) |
|
682 | - ) |
|
683 | - ) |
|
684 | - ); |
|
685 | - } |
|
686 | - |
|
687 | - if ( empty( $items ) ) { |
|
688 | - return 0; |
|
689 | - } |
|
690 | - |
|
691 | - // Update the cache with our data |
|
692 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
693 | - |
|
694 | - return $items[0]->ID; |
|
640 | + // Ensure a field has been passed. |
|
641 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
642 | + return 0; |
|
643 | + } |
|
644 | + |
|
645 | + if ( $field == 'name' ) { |
|
646 | + $field = 'slug'; |
|
647 | + } |
|
648 | + |
|
649 | + // Maybe retrieve from the cache. |
|
650 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | + if ( ! empty( $item_id ) ) { |
|
652 | + return $item_id; |
|
653 | + } |
|
654 | + |
|
655 | + // Fetch from the db. |
|
656 | + if ( $field =='slug' ) { |
|
657 | + $items = get_posts( |
|
658 | + array( |
|
659 | + 'post_type' => 'wpi_item', |
|
660 | + 'name' => $value, |
|
661 | + 'posts_per_page' => 1, |
|
662 | + 'post_status' => 'any', |
|
663 | + ) |
|
664 | + ); |
|
665 | + } |
|
666 | + |
|
667 | + if ( $field =='custom_id' ) { |
|
668 | + $items = get_posts( |
|
669 | + array( |
|
670 | + 'post_type' => 'wpi_item', |
|
671 | + 'posts_per_page' => 1, |
|
672 | + 'post_status' => 'any', |
|
673 | + 'meta_query' => array( |
|
674 | + array( |
|
675 | + 'key' => '_wpinv_type', |
|
676 | + 'value' => $type, |
|
677 | + ), |
|
678 | + array( |
|
679 | + 'key' => '_wpinv_custom_id', |
|
680 | + 'value' => $type, |
|
681 | + ) |
|
682 | + ) |
|
683 | + ) |
|
684 | + ); |
|
685 | + } |
|
686 | + |
|
687 | + if ( empty( $items ) ) { |
|
688 | + return 0; |
|
689 | + } |
|
690 | + |
|
691 | + // Update the cache with our data |
|
692 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
693 | + |
|
694 | + return $items[0]->ID; |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -724,52 +724,52 @@ discard block |
||
724 | 724 | */ |
725 | 725 | |
726 | 726 | /** |
727 | - * Set parent order ID. |
|
728 | - * |
|
729 | - * @since 1.0.19 |
|
730 | - */ |
|
731 | - public function set_parent_id( $value ) { |
|
732 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
733 | - return; |
|
734 | - } |
|
735 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
736 | - } |
|
737 | - |
|
738 | - /** |
|
739 | - * Sets item status. |
|
740 | - * |
|
741 | - * @since 1.0.19 |
|
742 | - * @param string $status New status. |
|
743 | - * @return array details of change. |
|
744 | - */ |
|
745 | - public function set_status( $status ) { |
|
727 | + * Set parent order ID. |
|
728 | + * |
|
729 | + * @since 1.0.19 |
|
730 | + */ |
|
731 | + public function set_parent_id( $value ) { |
|
732 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
733 | + return; |
|
734 | + } |
|
735 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
736 | + } |
|
737 | + |
|
738 | + /** |
|
739 | + * Sets item status. |
|
740 | + * |
|
741 | + * @since 1.0.19 |
|
742 | + * @param string $status New status. |
|
743 | + * @return array details of change. |
|
744 | + */ |
|
745 | + public function set_status( $status ) { |
|
746 | 746 | $old_status = $this->get_status(); |
747 | 747 | |
748 | 748 | $this->set_prop( 'status', $status ); |
749 | 749 | |
750 | - return array( |
|
751 | - 'from' => $old_status, |
|
752 | - 'to' => $status, |
|
753 | - ); |
|
750 | + return array( |
|
751 | + 'from' => $old_status, |
|
752 | + 'to' => $status, |
|
753 | + ); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | /** |
757 | - * Set plugin version when the item was created. |
|
758 | - * |
|
759 | - * @since 1.0.19 |
|
760 | - */ |
|
761 | - public function set_version( $value ) { |
|
762 | - $this->set_prop( 'version', $value ); |
|
757 | + * Set plugin version when the item was created. |
|
758 | + * |
|
759 | + * @since 1.0.19 |
|
760 | + */ |
|
761 | + public function set_version( $value ) { |
|
762 | + $this->set_prop( 'version', $value ); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
766 | - * Set date when the item was created. |
|
767 | - * |
|
768 | - * @since 1.0.19 |
|
769 | - * @param string $value Value to set. |
|
766 | + * Set date when the item was created. |
|
767 | + * |
|
768 | + * @since 1.0.19 |
|
769 | + * @param string $value Value to set. |
|
770 | 770 | * @return bool Whether or not the date was set. |
771 | - */ |
|
772 | - public function set_date_created( $value ) { |
|
771 | + */ |
|
772 | + public function set_date_created( $value ) { |
|
773 | 773 | $date = strtotime( $value ); |
774 | 774 | |
775 | 775 | if ( $date ) { |
@@ -782,13 +782,13 @@ discard block |
||
782 | 782 | } |
783 | 783 | |
784 | 784 | /** |
785 | - * Set date when the item was last modified. |
|
786 | - * |
|
787 | - * @since 1.0.19 |
|
788 | - * @param string $value Value to set. |
|
785 | + * Set date when the item was last modified. |
|
786 | + * |
|
787 | + * @since 1.0.19 |
|
788 | + * @param string $value Value to set. |
|
789 | 789 | * @return bool Whether or not the date was set. |
790 | - */ |
|
791 | - public function set_date_modified( $value ) { |
|
790 | + */ |
|
791 | + public function set_date_modified( $value ) { |
|
792 | 792 | $date = strtotime( $value ); |
793 | 793 | |
794 | 794 | if ( $date ) { |
@@ -801,115 +801,115 @@ discard block |
||
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
804 | - * Set the item name. |
|
805 | - * |
|
806 | - * @since 1.0.19 |
|
807 | - * @param string $value New name. |
|
808 | - */ |
|
809 | - public function set_name( $value ) { |
|
804 | + * Set the item name. |
|
805 | + * |
|
806 | + * @since 1.0.19 |
|
807 | + * @param string $value New name. |
|
808 | + */ |
|
809 | + public function set_name( $value ) { |
|
810 | 810 | $name = sanitize_text_field( $value ); |
811 | - $this->set_prop( 'name', $name ); |
|
811 | + $this->set_prop( 'name', $name ); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | /** |
815 | - * Alias of self::set_name(). |
|
816 | - * |
|
817 | - * @since 1.0.19 |
|
818 | - * @param string $value New name. |
|
819 | - */ |
|
820 | - public function set_title( $value ) { |
|
821 | - $this->set_name( $value ); |
|
815 | + * Alias of self::set_name(). |
|
816 | + * |
|
817 | + * @since 1.0.19 |
|
818 | + * @param string $value New name. |
|
819 | + */ |
|
820 | + public function set_title( $value ) { |
|
821 | + $this->set_name( $value ); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
825 | - * Set the item description. |
|
826 | - * |
|
827 | - * @since 1.0.19 |
|
828 | - * @param string $value New description. |
|
829 | - */ |
|
830 | - public function set_description( $value ) { |
|
825 | + * Set the item description. |
|
826 | + * |
|
827 | + * @since 1.0.19 |
|
828 | + * @param string $value New description. |
|
829 | + */ |
|
830 | + public function set_description( $value ) { |
|
831 | 831 | $description = wp_kses_post( $value ); |
832 | - return $this->set_prop( 'description', $description ); |
|
832 | + return $this->set_prop( 'description', $description ); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
836 | - * Alias of self::set_description(). |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
839 | - * @param string $value New description. |
|
840 | - */ |
|
841 | - public function set_excerpt( $value ) { |
|
842 | - $this->set_description( $value ); |
|
836 | + * Alias of self::set_description(). |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | + * @param string $value New description. |
|
840 | + */ |
|
841 | + public function set_excerpt( $value ) { |
|
842 | + $this->set_description( $value ); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
846 | - * Alias of self::set_description(). |
|
847 | - * |
|
848 | - * @since 1.0.19 |
|
849 | - * @param string $value New description. |
|
850 | - */ |
|
851 | - public function set_summary( $value ) { |
|
852 | - $this->set_description( $value ); |
|
846 | + * Alias of self::set_description(). |
|
847 | + * |
|
848 | + * @since 1.0.19 |
|
849 | + * @param string $value New description. |
|
850 | + */ |
|
851 | + public function set_summary( $value ) { |
|
852 | + $this->set_description( $value ); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
856 | - * Set the owner of the item. |
|
857 | - * |
|
858 | - * @since 1.0.19 |
|
859 | - * @param int $value New author. |
|
860 | - */ |
|
861 | - public function set_author( $value ) { |
|
862 | - $this->set_prop( 'author', (int) $value ); |
|
863 | - } |
|
856 | + * Set the owner of the item. |
|
857 | + * |
|
858 | + * @since 1.0.19 |
|
859 | + * @param int $value New author. |
|
860 | + */ |
|
861 | + public function set_author( $value ) { |
|
862 | + $this->set_prop( 'author', (int) $value ); |
|
863 | + } |
|
864 | 864 | |
865 | - /** |
|
866 | - * Alias of self::set_author(). |
|
867 | - * |
|
868 | - * @since 1.0.19 |
|
869 | - * @param int $value New author. |
|
870 | - */ |
|
871 | - public function set_owner( $value ) { |
|
872 | - $this->set_author( $value ); |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * Set the price of the item. |
|
877 | - * |
|
878 | - * @since 1.0.19 |
|
879 | - * @param float $value New price. |
|
880 | - */ |
|
881 | - public function set_price( $value ) { |
|
865 | + /** |
|
866 | + * Alias of self::set_author(). |
|
867 | + * |
|
868 | + * @since 1.0.19 |
|
869 | + * @param int $value New author. |
|
870 | + */ |
|
871 | + public function set_owner( $value ) { |
|
872 | + $this->set_author( $value ); |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * Set the price of the item. |
|
877 | + * |
|
878 | + * @since 1.0.19 |
|
879 | + * @param float $value New price. |
|
880 | + */ |
|
881 | + public function set_price( $value ) { |
|
882 | 882 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
886 | - * Set the VAT rule of the item. |
|
887 | - * |
|
888 | - * @since 1.0.19 |
|
889 | - * @param string $value new rule. |
|
890 | - */ |
|
891 | - public function set_vat_rule( $value ) { |
|
886 | + * Set the VAT rule of the item. |
|
887 | + * |
|
888 | + * @since 1.0.19 |
|
889 | + * @param string $value new rule. |
|
890 | + */ |
|
891 | + public function set_vat_rule( $value ) { |
|
892 | 892 | $this->set_prop( 'vat_rule', $value ); |
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
896 | - * Set the VAT class of the item. |
|
897 | - * |
|
898 | - * @since 1.0.19 |
|
899 | - * @param string $value new class. |
|
900 | - */ |
|
901 | - public function set_vat_class( $value ) { |
|
896 | + * Set the VAT class of the item. |
|
897 | + * |
|
898 | + * @since 1.0.19 |
|
899 | + * @param string $value new class. |
|
900 | + */ |
|
901 | + public function set_vat_class( $value ) { |
|
902 | 902 | $this->set_prop( 'vat_class', $value ); |
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
906 | - * Set the type of the item. |
|
907 | - * |
|
908 | - * @since 1.0.19 |
|
909 | - * @param string $value new item type. |
|
910 | - * @return string |
|
911 | - */ |
|
912 | - public function set_type( $value ) { |
|
906 | + * Set the type of the item. |
|
907 | + * |
|
908 | + * @since 1.0.19 |
|
909 | + * @param string $value new item type. |
|
910 | + * @return string |
|
911 | + */ |
|
912 | + public function set_type( $value ) { |
|
913 | 913 | |
914 | 914 | if ( empty( $value ) ) { |
915 | 915 | $value = 'custom'; |
@@ -919,134 +919,134 @@ discard block |
||
919 | 919 | } |
920 | 920 | |
921 | 921 | /** |
922 | - * Set the custom id of the item. |
|
923 | - * |
|
924 | - * @since 1.0.19 |
|
925 | - * @param string $value new custom id. |
|
926 | - */ |
|
927 | - public function set_custom_id( $value ) { |
|
922 | + * Set the custom id of the item. |
|
923 | + * |
|
924 | + * @since 1.0.19 |
|
925 | + * @param string $value new custom id. |
|
926 | + */ |
|
927 | + public function set_custom_id( $value ) { |
|
928 | 928 | $this->set_prop( 'custom_id', $value ); |
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
932 | - * Set the custom name of the item. |
|
933 | - * |
|
934 | - * @since 1.0.19 |
|
935 | - * @param string $value new custom name. |
|
936 | - */ |
|
937 | - public function set_custom_name( $value ) { |
|
932 | + * Set the custom name of the item. |
|
933 | + * |
|
934 | + * @since 1.0.19 |
|
935 | + * @param string $value new custom name. |
|
936 | + */ |
|
937 | + public function set_custom_name( $value ) { |
|
938 | 938 | $this->set_prop( 'custom_name', $value ); |
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
942 | - * Set the custom singular name of the item. |
|
943 | - * |
|
944 | - * @since 1.0.19 |
|
945 | - * @param string $value new custom singular name. |
|
946 | - */ |
|
947 | - public function set_custom_singular_name( $value ) { |
|
942 | + * Set the custom singular name of the item. |
|
943 | + * |
|
944 | + * @since 1.0.19 |
|
945 | + * @param string $value new custom singular name. |
|
946 | + */ |
|
947 | + public function set_custom_singular_name( $value ) { |
|
948 | 948 | $this->set_prop( 'custom_singular_name', $value ); |
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
952 | - * Sets if an item is editable.. |
|
953 | - * |
|
954 | - * @since 1.0.19 |
|
955 | - * @param int|bool $value whether or not the item is editable. |
|
956 | - */ |
|
957 | - public function set_is_editable( $value ) { |
|
958 | - if ( is_numeric( $value ) ) { |
|
959 | - $this->set_prop( 'is_editable', (int) $value ); |
|
960 | - } |
|
952 | + * Sets if an item is editable.. |
|
953 | + * |
|
954 | + * @since 1.0.19 |
|
955 | + * @param int|bool $value whether or not the item is editable. |
|
956 | + */ |
|
957 | + public function set_is_editable( $value ) { |
|
958 | + if ( is_numeric( $value ) ) { |
|
959 | + $this->set_prop( 'is_editable', (int) $value ); |
|
960 | + } |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
964 | - * Sets if dynamic pricing is enabled. |
|
965 | - * |
|
966 | - * @since 1.0.19 |
|
967 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
968 | - */ |
|
969 | - public function set_is_dynamic_pricing( $value ) { |
|
964 | + * Sets if dynamic pricing is enabled. |
|
965 | + * |
|
966 | + * @since 1.0.19 |
|
967 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
968 | + */ |
|
969 | + public function set_is_dynamic_pricing( $value ) { |
|
970 | 970 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
971 | 971 | } |
972 | 972 | |
973 | 973 | /** |
974 | - * Sets the minimum price if dynamic pricing is enabled. |
|
975 | - * |
|
976 | - * @since 1.0.19 |
|
977 | - * @param float $value minimum price. |
|
978 | - */ |
|
979 | - public function set_minimum_price( $value ) { |
|
974 | + * Sets the minimum price if dynamic pricing is enabled. |
|
975 | + * |
|
976 | + * @since 1.0.19 |
|
977 | + * @param float $value minimum price. |
|
978 | + */ |
|
979 | + public function set_minimum_price( $value ) { |
|
980 | 980 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
981 | 981 | } |
982 | 982 | |
983 | 983 | /** |
984 | - * Sets if this is a recurring item. |
|
985 | - * |
|
986 | - * @since 1.0.19 |
|
987 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
988 | - */ |
|
989 | - public function set_is_recurring( $value ) { |
|
984 | + * Sets if this is a recurring item. |
|
985 | + * |
|
986 | + * @since 1.0.19 |
|
987 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
988 | + */ |
|
989 | + public function set_is_recurring( $value ) { |
|
990 | 990 | $this->set_prop( 'is_recurring', (int) $value ); |
991 | 991 | } |
992 | 992 | |
993 | 993 | /** |
994 | - * Set the recurring period. |
|
995 | - * |
|
996 | - * @since 1.0.19 |
|
997 | - * @param string $value new period. |
|
998 | - */ |
|
999 | - public function set_recurring_period( $value ) { |
|
994 | + * Set the recurring period. |
|
995 | + * |
|
996 | + * @since 1.0.19 |
|
997 | + * @param string $value new period. |
|
998 | + */ |
|
999 | + public function set_recurring_period( $value ) { |
|
1000 | 1000 | $this->set_prop( 'recurring_period', $value ); |
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | /** |
1004 | - * Set the recurring interval. |
|
1005 | - * |
|
1006 | - * @since 1.0.19 |
|
1007 | - * @param int $value recurring interval. |
|
1008 | - */ |
|
1009 | - public function set_recurring_interval( $value ) { |
|
1004 | + * Set the recurring interval. |
|
1005 | + * |
|
1006 | + * @since 1.0.19 |
|
1007 | + * @param int $value recurring interval. |
|
1008 | + */ |
|
1009 | + public function set_recurring_interval( $value ) { |
|
1010 | 1010 | return $this->set_prop( 'recurring_interval', (int) $value ); |
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | /** |
1014 | - * Get the recurring limit. |
|
1015 | - * @since 1.0.19 |
|
1016 | - * @param int $value The recurring limit. |
|
1017 | - * @return int |
|
1018 | - */ |
|
1019 | - public function set_recurring_limit( $value ) { |
|
1014 | + * Get the recurring limit. |
|
1015 | + * @since 1.0.19 |
|
1016 | + * @param int $value The recurring limit. |
|
1017 | + * @return int |
|
1018 | + */ |
|
1019 | + public function set_recurring_limit( $value ) { |
|
1020 | 1020 | $this->set_prop( 'recurring_limit', (int) $value ); |
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | /** |
1024 | - * Checks if we have a free trial. |
|
1025 | - * |
|
1026 | - * @since 1.0.19 |
|
1027 | - * @param int|bool $value whether or not it has a free trial. |
|
1028 | - */ |
|
1029 | - public function set_is_free_trial( $value ) { |
|
1024 | + * Checks if we have a free trial. |
|
1025 | + * |
|
1026 | + * @since 1.0.19 |
|
1027 | + * @param int|bool $value whether or not it has a free trial. |
|
1028 | + */ |
|
1029 | + public function set_is_free_trial( $value ) { |
|
1030 | 1030 | $this->set_prop( 'is_free_trial', (int) $value ); |
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | /** |
1034 | - * Set the trial period. |
|
1035 | - * |
|
1036 | - * @since 1.0.19 |
|
1037 | - * @param string $value trial period. |
|
1038 | - */ |
|
1039 | - public function set_trial_period( $value ) { |
|
1034 | + * Set the trial period. |
|
1035 | + * |
|
1036 | + * @since 1.0.19 |
|
1037 | + * @param string $value trial period. |
|
1038 | + */ |
|
1039 | + public function set_trial_period( $value ) { |
|
1040 | 1040 | $this->set_prop( 'trial_period', $value ); |
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | /** |
1044 | - * Set the trial interval. |
|
1045 | - * |
|
1046 | - * @since 1.0.19 |
|
1047 | - * @param int $value trial interval. |
|
1048 | - */ |
|
1049 | - public function set_trial_interval( $value ) { |
|
1044 | + * Set the trial interval. |
|
1045 | + * |
|
1046 | + * @since 1.0.19 |
|
1047 | + * @param int $value trial interval. |
|
1048 | + */ |
|
1049 | + public function set_trial_interval( $value ) { |
|
1050 | 1050 | $this->set_prop( 'trial_interval', $value ); |
1051 | 1051 | } |
1052 | 1052 | |
@@ -1054,17 +1054,17 @@ discard block |
||
1054 | 1054 | * Create an item. For backwards compatibilty. |
1055 | 1055 | * |
1056 | 1056 | * @deprecated |
1057 | - * @return int item id |
|
1057 | + * @return int item id |
|
1058 | 1058 | */ |
1059 | 1059 | public function create( $data = array() ) { |
1060 | 1060 | |
1061 | - // Set the properties. |
|
1062 | - if ( is_array( $data ) ) { |
|
1063 | - $this->set_props( $data ); |
|
1064 | - } |
|
1061 | + // Set the properties. |
|
1062 | + if ( is_array( $data ) ) { |
|
1063 | + $this->set_props( $data ); |
|
1064 | + } |
|
1065 | 1065 | |
1066 | - // Save the item. |
|
1067 | - return $this->save(); |
|
1066 | + // Save the item. |
|
1067 | + return $this->save(); |
|
1068 | 1068 | |
1069 | 1069 | } |
1070 | 1070 | |
@@ -1072,7 +1072,7 @@ discard block |
||
1072 | 1072 | * Updates an item. For backwards compatibilty. |
1073 | 1073 | * |
1074 | 1074 | * @deprecated |
1075 | - * @return int item id |
|
1075 | + * @return int item id |
|
1076 | 1076 | */ |
1077 | 1077 | public function update( $data = array() ) { |
1078 | 1078 | return $this->create( $data ); |
@@ -1088,84 +1088,84 @@ discard block |
||
1088 | 1088 | */ |
1089 | 1089 | |
1090 | 1090 | /** |
1091 | - * Checks whether the item has enabled dynamic pricing. |
|
1092 | - * |
|
1093 | - * @since 1.0.19 |
|
1094 | - * @return bool |
|
1095 | - */ |
|
1096 | - public function user_can_set_their_price() { |
|
1091 | + * Checks whether the item has enabled dynamic pricing. |
|
1092 | + * |
|
1093 | + * @since 1.0.19 |
|
1094 | + * @return bool |
|
1095 | + */ |
|
1096 | + public function user_can_set_their_price() { |
|
1097 | 1097 | return (bool) $this->get_is_dynamic_pricing(); |
1098 | - } |
|
1098 | + } |
|
1099 | 1099 | |
1100 | - /** |
|
1101 | - * Checks whether the item is recurring. |
|
1102 | - * |
|
1103 | - * @since 1.0.19 |
|
1104 | - * @return bool |
|
1105 | - */ |
|
1106 | - public function is_recurring() { |
|
1100 | + /** |
|
1101 | + * Checks whether the item is recurring. |
|
1102 | + * |
|
1103 | + * @since 1.0.19 |
|
1104 | + * @return bool |
|
1105 | + */ |
|
1106 | + public function is_recurring() { |
|
1107 | 1107 | return (bool) $this->get_is_recurring(); |
1108 | 1108 | } |
1109 | 1109 | |
1110 | 1110 | /** |
1111 | - * Checks whether the item has a free trial. |
|
1112 | - * |
|
1113 | - * @since 1.0.19 |
|
1114 | - * @return bool |
|
1115 | - */ |
|
1111 | + * Checks whether the item has a free trial. |
|
1112 | + * |
|
1113 | + * @since 1.0.19 |
|
1114 | + * @return bool |
|
1115 | + */ |
|
1116 | 1116 | public function has_free_trial() { |
1117 | 1117 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1118 | 1118 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | /** |
1122 | - * Checks whether the item is free. |
|
1123 | - * |
|
1124 | - * @since 1.0.19 |
|
1125 | - * @return bool |
|
1126 | - */ |
|
1122 | + * Checks whether the item is free. |
|
1123 | + * |
|
1124 | + * @since 1.0.19 |
|
1125 | + * @return bool |
|
1126 | + */ |
|
1127 | 1127 | public function is_free() { |
1128 | 1128 | $is_free = $this->get_price() == 0; |
1129 | 1129 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
1130 | 1130 | } |
1131 | 1131 | |
1132 | 1132 | /** |
1133 | - * Checks the item status against a passed in status. |
|
1134 | - * |
|
1135 | - * @param array|string $status Status to check. |
|
1136 | - * @return bool |
|
1137 | - */ |
|
1138 | - public function has_status( $status ) { |
|
1139 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1140 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1133 | + * Checks the item status against a passed in status. |
|
1134 | + * |
|
1135 | + * @param array|string $status Status to check. |
|
1136 | + * @return bool |
|
1137 | + */ |
|
1138 | + public function has_status( $status ) { |
|
1139 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1140 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | /** |
1144 | - * Checks the item type against a passed in types. |
|
1145 | - * |
|
1146 | - * @param array|string $type Type to check. |
|
1147 | - * @return bool |
|
1148 | - */ |
|
1149 | - public function is_type( $type ) { |
|
1150 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1151 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1152 | - } |
|
1144 | + * Checks the item type against a passed in types. |
|
1145 | + * |
|
1146 | + * @param array|string $type Type to check. |
|
1147 | + * @return bool |
|
1148 | + */ |
|
1149 | + public function is_type( $type ) { |
|
1150 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1151 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1152 | + } |
|
1153 | 1153 | |
1154 | 1154 | /** |
1155 | - * Checks whether the item is editable. |
|
1156 | - * |
|
1157 | - * @since 1.0.19 |
|
1158 | - * @return bool |
|
1159 | - */ |
|
1155 | + * Checks whether the item is editable. |
|
1156 | + * |
|
1157 | + * @since 1.0.19 |
|
1158 | + * @return bool |
|
1159 | + */ |
|
1160 | 1160 | public function is_editable() { |
1161 | 1161 | $is_editable = $this->get_is_editable(); |
1162 | 1162 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
1163 | - } |
|
1163 | + } |
|
1164 | 1164 | |
1165 | - /** |
|
1166 | - * Returns an array of cart fees. |
|
1167 | - */ |
|
1168 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1165 | + /** |
|
1166 | + * Returns an array of cart fees. |
|
1167 | + */ |
|
1168 | + public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1169 | 1169 | |
1170 | 1170 | $fees = getpaid_session()->get( 'wpi_cart_fees' ); |
1171 | 1171 | |
@@ -1208,11 +1208,11 @@ discard block |
||
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | /** |
1211 | - * Checks whether the item is purchasable. |
|
1212 | - * |
|
1213 | - * @since 1.0.19 |
|
1214 | - * @return bool |
|
1215 | - */ |
|
1211 | + * Checks whether the item is purchasable. |
|
1212 | + * |
|
1213 | + * @since 1.0.19 |
|
1214 | + * @return bool |
|
1215 | + */ |
|
1216 | 1216 | public function can_purchase() { |
1217 | 1217 | $can_purchase = null !== $this->get_id(); |
1218 | 1218 | |
@@ -1224,11 +1224,11 @@ discard block |
||
1224 | 1224 | } |
1225 | 1225 | |
1226 | 1226 | /** |
1227 | - * Checks whether the item supports dynamic pricing. |
|
1228 | - * |
|
1229 | - * @since 1.0.19 |
|
1230 | - * @return bool |
|
1231 | - */ |
|
1227 | + * Checks whether the item supports dynamic pricing. |
|
1228 | + * |
|
1229 | + * @since 1.0.19 |
|
1230 | + * @return bool |
|
1231 | + */ |
|
1232 | 1232 | public function supports_dynamic_pricing() { |
1233 | 1233 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
1234 | 1234 | } |
@@ -14,439 +14,439 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax instance. |
|
40 | - * |
|
41 | - * @var WPInv_EUVat |
|
42 | - */ |
|
43 | - public $tax; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array An array of payment gateways. |
|
47 | - */ |
|
48 | - public $gateways; |
|
49 | - |
|
50 | - /** |
|
51 | - * Class constructor. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - $this->define_constants(); |
|
55 | - $this->includes(); |
|
56 | - $this->init_hooks(); |
|
57 | - $this->set_properties(); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets a custom data property. |
|
62 | - * |
|
63 | - * @param string $prop The prop to set. |
|
64 | - * @param mixed $value The value to retrieve. |
|
65 | - */ |
|
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Gets a custom data property. |
|
72 | - * |
|
73 | - * @param string $prop The prop to set. |
|
74 | - * @return mixed The value. |
|
75 | - */ |
|
76 | - public function get( $prop ) { |
|
77 | - |
|
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
80 | - } |
|
81 | - |
|
82 | - return null; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Define class properties. |
|
87 | - */ |
|
88 | - public function set_properties() { |
|
89 | - |
|
90 | - // Sessions. |
|
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | - $this->form_elements = new WPInv_Payment_Form_Elements(); |
|
94 | - $this->tax = new WPInv_EUVat(); |
|
95 | - $this->tax->init(); |
|
96 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
97 | - |
|
98 | - // Init other objects. |
|
99 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
100 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
101 | - $this->set( 'notes', new WPInv_Notes() ); |
|
102 | - $this->set( 'api', new WPInv_API() ); |
|
103 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
104 | - $this->set( 'template', new GetPaid_Template() ); |
|
105 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
106 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
107 | - |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Define plugin constants. |
|
112 | - */ |
|
113 | - public function define_constants() { |
|
114 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
115 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
116 | - $this->version = WPINV_VERSION; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Hook into actions and filters. |
|
121 | - * |
|
122 | - * @since 1.0.19 |
|
123 | - */ |
|
124 | - protected function init_hooks() { |
|
125 | - /* Internationalize the text strings used. */ |
|
126 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
127 | - |
|
128 | - // Init the plugin after WordPress inits. |
|
129 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
130 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
131 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
132 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ) ); |
|
133 | - |
|
134 | - if ( class_exists( 'BuddyPress' ) ) { |
|
135 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
136 | - } |
|
137 | - |
|
138 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
139 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
140 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
141 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
142 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
143 | - |
|
144 | - // Fires after registering actions. |
|
145 | - do_action( 'wpinv_actions', $this ); |
|
146 | - do_action( 'getpaid_actions', $this ); |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - public function plugins_loaded() { |
|
151 | - /* Internationalize the text strings used. */ |
|
152 | - $this->load_textdomain(); |
|
153 | - |
|
154 | - do_action( 'wpinv_loaded' ); |
|
155 | - |
|
156 | - // Fix oxygen page builder conflict |
|
157 | - if ( function_exists( 'ct_css_output' ) ) { |
|
158 | - wpinv_oxygen_fix_conflict(); |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Load the translation of the plugin. |
|
164 | - * |
|
165 | - * @since 1.0 |
|
166 | - */ |
|
167 | - public function load_textdomain( $locale = NULL ) { |
|
168 | - if ( empty( $locale ) ) { |
|
169 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
170 | - } |
|
171 | - |
|
172 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
173 | - |
|
174 | - unload_textdomain( 'invoicing' ); |
|
175 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
176 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
177 | - |
|
178 | - /** |
|
179 | - * Define language constants. |
|
180 | - */ |
|
181 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Include required core files used in admin and on the frontend. |
|
186 | - */ |
|
187 | - public function includes() { |
|
188 | - |
|
189 | - // Start with the settings. |
|
190 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
191 | - |
|
192 | - // Packages/libraries. |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
196 | - |
|
197 | - // Load functions. |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
212 | - |
|
213 | - // Register autoloader. |
|
214 | - try { |
|
215 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
216 | - } catch ( Exception $e ) { |
|
217 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
218 | - } |
|
219 | - |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
242 | - |
|
243 | - /** |
|
244 | - * Load the tax class. |
|
245 | - */ |
|
246 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
247 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
248 | - } |
|
249 | - |
|
250 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
251 | - if ( !empty( $gateways ) ) { |
|
252 | - foreach ( $gateways as $gateway ) { |
|
253 | - if ( $gateway == 'manual' ) { |
|
254 | - continue; |
|
255 | - } |
|
256 | - |
|
257 | - $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
258 | - |
|
259 | - if ( file_exists( $gateway_file ) ) { |
|
260 | - require_once( $gateway_file ); |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
266 | - GetPaid_Post_Types_Admin::init(); |
|
267 | - |
|
268 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
269 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
270 | - //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
271 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
272 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
273 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
274 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
275 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
277 | - //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
278 | - // load the user class only on the users.php page |
|
279 | - global $pagenow; |
|
280 | - if($pagenow=='users.php'){ |
|
281 | - new WPInv_Admin_Users(); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - // Register cli commands |
|
286 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
287 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
288 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
289 | - } |
|
290 | - |
|
291 | - // include css inliner |
|
292 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
293 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
294 | - } |
|
295 | - |
|
296 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Class autoloader |
|
301 | - * |
|
302 | - * @param string $class_name The name of the class to load. |
|
303 | - * @access public |
|
304 | - * @since 1.0.19 |
|
305 | - * @return void |
|
306 | - */ |
|
307 | - public function autoload( $class_name ) { |
|
308 | - |
|
309 | - // Normalize the class name... |
|
310 | - $class_name = strtolower( $class_name ); |
|
311 | - |
|
312 | - // ... and make sure it is our class. |
|
313 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
314 | - return; |
|
315 | - } |
|
316 | - |
|
317 | - // Next, prepare the file name from the class. |
|
318 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
319 | - |
|
320 | - // Base path of the classes. |
|
321 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
322 | - |
|
323 | - // And an array of possible locations in order of importance. |
|
324 | - $locations = array( |
|
325 | - "$plugin_path/includes", |
|
326 | - "$plugin_path/includes/data-stores", |
|
327 | - "$plugin_path/includes/gateways", |
|
328 | - "$plugin_path/includes/api", |
|
329 | - "$plugin_path/includes/admin", |
|
330 | - "$plugin_path/includes/admin/meta-boxes", |
|
331 | - ); |
|
332 | - |
|
333 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
334 | - |
|
335 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
336 | - include trailingslashit( $location ) . $file_name; |
|
337 | - break; |
|
338 | - } |
|
339 | - |
|
340 | - } |
|
341 | - |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Inits hooks etc. |
|
346 | - */ |
|
347 | - public function init() { |
|
348 | - |
|
349 | - // Fires before getpaid inits. |
|
350 | - do_action( 'before_getpaid_init', $this ); |
|
351 | - |
|
352 | - // Load default gateways. |
|
353 | - $gateways = apply_filters( |
|
354 | - 'getpaid_default_gateways', |
|
355 | - array( |
|
356 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
357 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
358 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
359 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
360 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
361 | - ) |
|
362 | - ); |
|
363 | - |
|
364 | - foreach ( $gateways as $id => $class ) { |
|
365 | - $this->gateways[ $id ] = new $class(); |
|
366 | - } |
|
367 | - |
|
368 | - // Fires after getpaid inits. |
|
369 | - do_action( 'getpaid_init', $this ); |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Checks if this is an IPN request and processes it. |
|
375 | - */ |
|
376 | - public function maybe_process_ipn() { |
|
377 | - |
|
378 | - // Ensure that this is an IPN request. |
|
379 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
380 | - return; |
|
381 | - } |
|
382 | - |
|
383 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
384 | - |
|
385 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
386 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
387 | - exit; |
|
388 | - |
|
389 | - } |
|
390 | - |
|
391 | - public function enqueue_scripts() { |
|
392 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
393 | - |
|
394 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
395 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
396 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
397 | - |
|
398 | - // Register scripts |
|
399 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
400 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
401 | - |
|
402 | - $localize = array(); |
|
403 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
404 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
405 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
406 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
407 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
408 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
409 | - $localize['decimals'] = wpinv_decimals(); |
|
410 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
411 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
412 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
413 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
414 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
415 | - |
|
416 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
417 | - |
|
418 | - wp_enqueue_script( 'jquery-blockui' ); |
|
419 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
420 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
421 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
422 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
423 | - wp_dequeue_script( 'google-maps-api' ); |
|
424 | - } |
|
425 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
426 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
427 | - } |
|
428 | - |
|
429 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
430 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
431 | - |
|
432 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
433 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
434 | - |
|
435 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
436 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
437 | - } |
|
438 | - |
|
439 | - public function wpinv_actions() { |
|
440 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
441 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
442 | - } |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax instance. |
|
40 | + * |
|
41 | + * @var WPInv_EUVat |
|
42 | + */ |
|
43 | + public $tax; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array An array of payment gateways. |
|
47 | + */ |
|
48 | + public $gateways; |
|
49 | + |
|
50 | + /** |
|
51 | + * Class constructor. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + $this->define_constants(); |
|
55 | + $this->includes(); |
|
56 | + $this->init_hooks(); |
|
57 | + $this->set_properties(); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets a custom data property. |
|
62 | + * |
|
63 | + * @param string $prop The prop to set. |
|
64 | + * @param mixed $value The value to retrieve. |
|
65 | + */ |
|
66 | + public function set( $prop, $value ) { |
|
67 | + $this->data[ $prop ] = $value; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Gets a custom data property. |
|
72 | + * |
|
73 | + * @param string $prop The prop to set. |
|
74 | + * @return mixed The value. |
|
75 | + */ |
|
76 | + public function get( $prop ) { |
|
77 | + |
|
78 | + if ( isset( $this->data[ $prop ] ) ) { |
|
79 | + return $this->data[ $prop ]; |
|
80 | + } |
|
81 | + |
|
82 | + return null; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Define class properties. |
|
87 | + */ |
|
88 | + public function set_properties() { |
|
89 | + |
|
90 | + // Sessions. |
|
91 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | + $this->form_elements = new WPInv_Payment_Form_Elements(); |
|
94 | + $this->tax = new WPInv_EUVat(); |
|
95 | + $this->tax->init(); |
|
96 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
97 | + |
|
98 | + // Init other objects. |
|
99 | + $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
100 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
101 | + $this->set( 'notes', new WPInv_Notes() ); |
|
102 | + $this->set( 'api', new WPInv_API() ); |
|
103 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
104 | + $this->set( 'template', new GetPaid_Template() ); |
|
105 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
106 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
107 | + |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Define plugin constants. |
|
112 | + */ |
|
113 | + public function define_constants() { |
|
114 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
115 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
116 | + $this->version = WPINV_VERSION; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Hook into actions and filters. |
|
121 | + * |
|
122 | + * @since 1.0.19 |
|
123 | + */ |
|
124 | + protected function init_hooks() { |
|
125 | + /* Internationalize the text strings used. */ |
|
126 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
127 | + |
|
128 | + // Init the plugin after WordPress inits. |
|
129 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
130 | + add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
131 | + add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
132 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ) ); |
|
133 | + |
|
134 | + if ( class_exists( 'BuddyPress' ) ) { |
|
135 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
136 | + } |
|
137 | + |
|
138 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
139 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
140 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
141 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
142 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
143 | + |
|
144 | + // Fires after registering actions. |
|
145 | + do_action( 'wpinv_actions', $this ); |
|
146 | + do_action( 'getpaid_actions', $this ); |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + public function plugins_loaded() { |
|
151 | + /* Internationalize the text strings used. */ |
|
152 | + $this->load_textdomain(); |
|
153 | + |
|
154 | + do_action( 'wpinv_loaded' ); |
|
155 | + |
|
156 | + // Fix oxygen page builder conflict |
|
157 | + if ( function_exists( 'ct_css_output' ) ) { |
|
158 | + wpinv_oxygen_fix_conflict(); |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Load the translation of the plugin. |
|
164 | + * |
|
165 | + * @since 1.0 |
|
166 | + */ |
|
167 | + public function load_textdomain( $locale = NULL ) { |
|
168 | + if ( empty( $locale ) ) { |
|
169 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
170 | + } |
|
171 | + |
|
172 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
173 | + |
|
174 | + unload_textdomain( 'invoicing' ); |
|
175 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
176 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
177 | + |
|
178 | + /** |
|
179 | + * Define language constants. |
|
180 | + */ |
|
181 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Include required core files used in admin and on the frontend. |
|
186 | + */ |
|
187 | + public function includes() { |
|
188 | + |
|
189 | + // Start with the settings. |
|
190 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
191 | + |
|
192 | + // Packages/libraries. |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
196 | + |
|
197 | + // Load functions. |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
207 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
208 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
212 | + |
|
213 | + // Register autoloader. |
|
214 | + try { |
|
215 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
216 | + } catch ( Exception $e ) { |
|
217 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
218 | + } |
|
219 | + |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
242 | + |
|
243 | + /** |
|
244 | + * Load the tax class. |
|
245 | + */ |
|
246 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
247 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
248 | + } |
|
249 | + |
|
250 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
251 | + if ( !empty( $gateways ) ) { |
|
252 | + foreach ( $gateways as $gateway ) { |
|
253 | + if ( $gateway == 'manual' ) { |
|
254 | + continue; |
|
255 | + } |
|
256 | + |
|
257 | + $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
258 | + |
|
259 | + if ( file_exists( $gateway_file ) ) { |
|
260 | + require_once( $gateway_file ); |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
266 | + GetPaid_Post_Types_Admin::init(); |
|
267 | + |
|
268 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
269 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
270 | + //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
271 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
272 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
273 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
274 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
275 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
276 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
277 | + //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
278 | + // load the user class only on the users.php page |
|
279 | + global $pagenow; |
|
280 | + if($pagenow=='users.php'){ |
|
281 | + new WPInv_Admin_Users(); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + // Register cli commands |
|
286 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
287 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
288 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
289 | + } |
|
290 | + |
|
291 | + // include css inliner |
|
292 | + if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
293 | + include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
294 | + } |
|
295 | + |
|
296 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Class autoloader |
|
301 | + * |
|
302 | + * @param string $class_name The name of the class to load. |
|
303 | + * @access public |
|
304 | + * @since 1.0.19 |
|
305 | + * @return void |
|
306 | + */ |
|
307 | + public function autoload( $class_name ) { |
|
308 | + |
|
309 | + // Normalize the class name... |
|
310 | + $class_name = strtolower( $class_name ); |
|
311 | + |
|
312 | + // ... and make sure it is our class. |
|
313 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
314 | + return; |
|
315 | + } |
|
316 | + |
|
317 | + // Next, prepare the file name from the class. |
|
318 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
319 | + |
|
320 | + // Base path of the classes. |
|
321 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
322 | + |
|
323 | + // And an array of possible locations in order of importance. |
|
324 | + $locations = array( |
|
325 | + "$plugin_path/includes", |
|
326 | + "$plugin_path/includes/data-stores", |
|
327 | + "$plugin_path/includes/gateways", |
|
328 | + "$plugin_path/includes/api", |
|
329 | + "$plugin_path/includes/admin", |
|
330 | + "$plugin_path/includes/admin/meta-boxes", |
|
331 | + ); |
|
332 | + |
|
333 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
334 | + |
|
335 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
336 | + include trailingslashit( $location ) . $file_name; |
|
337 | + break; |
|
338 | + } |
|
339 | + |
|
340 | + } |
|
341 | + |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Inits hooks etc. |
|
346 | + */ |
|
347 | + public function init() { |
|
348 | + |
|
349 | + // Fires before getpaid inits. |
|
350 | + do_action( 'before_getpaid_init', $this ); |
|
351 | + |
|
352 | + // Load default gateways. |
|
353 | + $gateways = apply_filters( |
|
354 | + 'getpaid_default_gateways', |
|
355 | + array( |
|
356 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
357 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
358 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
359 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
360 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
361 | + ) |
|
362 | + ); |
|
363 | + |
|
364 | + foreach ( $gateways as $id => $class ) { |
|
365 | + $this->gateways[ $id ] = new $class(); |
|
366 | + } |
|
367 | + |
|
368 | + // Fires after getpaid inits. |
|
369 | + do_action( 'getpaid_init', $this ); |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Checks if this is an IPN request and processes it. |
|
375 | + */ |
|
376 | + public function maybe_process_ipn() { |
|
377 | + |
|
378 | + // Ensure that this is an IPN request. |
|
379 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
380 | + return; |
|
381 | + } |
|
382 | + |
|
383 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
384 | + |
|
385 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
386 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
387 | + exit; |
|
388 | + |
|
389 | + } |
|
390 | + |
|
391 | + public function enqueue_scripts() { |
|
392 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
393 | + |
|
394 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
395 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
396 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
397 | + |
|
398 | + // Register scripts |
|
399 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
400 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
401 | + |
|
402 | + $localize = array(); |
|
403 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
404 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
405 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
406 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
407 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
408 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
409 | + $localize['decimals'] = wpinv_decimals(); |
|
410 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
411 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
412 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
413 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
414 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
415 | + |
|
416 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
417 | + |
|
418 | + wp_enqueue_script( 'jquery-blockui' ); |
|
419 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
420 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
421 | + if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
422 | + if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
423 | + wp_dequeue_script( 'google-maps-api' ); |
|
424 | + } |
|
425 | + wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
426 | + wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
427 | + } |
|
428 | + |
|
429 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
430 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
431 | + |
|
432 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
433 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
434 | + |
|
435 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
436 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
437 | + } |
|
438 | + |
|
439 | + public function wpinv_actions() { |
|
440 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
441 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
442 | + } |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | 446 | * Fires an action after verifying that a user can fire them. |
447 | - * |
|
448 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
449 | - * current user owns the invoice/subscription. |
|
447 | + * |
|
448 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
449 | + * current user owns the invoice/subscription. |
|
450 | 450 | */ |
451 | 451 | public function maybe_do_authenticated_action() { |
452 | 452 | |
@@ -457,82 +457,82 @@ discard block |
||
457 | 457 | |
458 | 458 | } |
459 | 459 | |
460 | - public function pre_get_posts( $wp_query ) { |
|
461 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
462 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
463 | - } |
|
464 | - |
|
465 | - return $wp_query; |
|
466 | - } |
|
467 | - |
|
468 | - public function bp_invoicing_init() { |
|
469 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Register widgets |
|
474 | - * |
|
475 | - */ |
|
476 | - public function register_widgets() { |
|
477 | - $widgets = apply_filters( |
|
478 | - 'getpaid_widget_classes', |
|
479 | - array( |
|
480 | - 'WPInv_Checkout_Widget', |
|
481 | - 'WPInv_History_Widget', |
|
482 | - 'WPInv_Receipt_Widget', |
|
483 | - 'WPInv_Subscriptions_Widget', |
|
484 | - 'WPInv_Buy_Item_Widget', |
|
485 | - 'WPInv_Messages_Widget', |
|
486 | - 'WPInv_GetPaid_Widget' |
|
487 | - ) |
|
488 | - ); |
|
489 | - |
|
490 | - foreach ( $widgets as $widget ) { |
|
491 | - register_widget( $widget ); |
|
492 | - } |
|
460 | + public function pre_get_posts( $wp_query ) { |
|
461 | + if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
462 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
463 | + } |
|
464 | + |
|
465 | + return $wp_query; |
|
466 | + } |
|
467 | + |
|
468 | + public function bp_invoicing_init() { |
|
469 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Register widgets |
|
474 | + * |
|
475 | + */ |
|
476 | + public function register_widgets() { |
|
477 | + $widgets = apply_filters( |
|
478 | + 'getpaid_widget_classes', |
|
479 | + array( |
|
480 | + 'WPInv_Checkout_Widget', |
|
481 | + 'WPInv_History_Widget', |
|
482 | + 'WPInv_Receipt_Widget', |
|
483 | + 'WPInv_Subscriptions_Widget', |
|
484 | + 'WPInv_Buy_Item_Widget', |
|
485 | + 'WPInv_Messages_Widget', |
|
486 | + 'WPInv_GetPaid_Widget' |
|
487 | + ) |
|
488 | + ); |
|
489 | + |
|
490 | + foreach ( $widgets as $widget ) { |
|
491 | + register_widget( $widget ); |
|
492 | + } |
|
493 | 493 | |
494 | - } |
|
494 | + } |
|
495 | 495 | |
496 | - /** |
|
497 | - * Remove our pages from yoast sitemaps. |
|
498 | - * |
|
499 | - * @since 1.0.19 |
|
500 | - * @param int[] $excluded_posts_ids |
|
501 | - */ |
|
502 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
496 | + /** |
|
497 | + * Remove our pages from yoast sitemaps. |
|
498 | + * |
|
499 | + * @since 1.0.19 |
|
500 | + * @param int[] $excluded_posts_ids |
|
501 | + */ |
|
502 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
503 | 503 | |
504 | - // Ensure that we have an array. |
|
505 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
506 | - $excluded_posts_ids = array(); |
|
507 | - } |
|
504 | + // Ensure that we have an array. |
|
505 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
506 | + $excluded_posts_ids = array(); |
|
507 | + } |
|
508 | 508 | |
509 | - // Prepare our pages. |
|
510 | - $our_pages = array(); |
|
509 | + // Prepare our pages. |
|
510 | + $our_pages = array(); |
|
511 | 511 | |
512 | - // Checkout page. |
|
513 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
512 | + // Checkout page. |
|
513 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
514 | 514 | |
515 | - // Success page. |
|
516 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
515 | + // Success page. |
|
516 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
517 | 517 | |
518 | - // Failure page. |
|
519 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
518 | + // Failure page. |
|
519 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
520 | 520 | |
521 | - // History page. |
|
522 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
521 | + // History page. |
|
522 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
523 | 523 | |
524 | - // Subscriptions page. |
|
525 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
524 | + // Subscriptions page. |
|
525 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
526 | 526 | |
527 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
527 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
528 | 528 | |
529 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
530 | - return array_unique( $excluded_posts_ids ); |
|
529 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
530 | + return array_unique( $excluded_posts_ids ); |
|
531 | 531 | |
532 | - } |
|
532 | + } |
|
533 | 533 | |
534 | - public function wp_footer() { |
|
535 | - echo ' |
|
534 | + public function wp_footer() { |
|
535 | + echo ' |
|
536 | 536 | <div class="bsui"> |
537 | 537 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
538 | 538 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -543,6 +543,6 @@ discard block |
||
543 | 543 | </div> |
544 | 544 | </div> |
545 | 545 | '; |
546 | - } |
|
546 | + } |
|
547 | 547 | |
548 | 548 | } |