@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -13,36 +13,36 @@ 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 an option |
|
42 | - * |
|
41 | + * Retrieves an option |
|
42 | + * |
|
43 | 43 | * @return mixed |
44 | - */ |
|
45 | - public function get_option( $key ) { |
|
44 | + */ |
|
45 | + public function get_option( $key ) { |
|
46 | 46 | |
47 | 47 | $key = "email_{$this->id}_$key"; |
48 | 48 | $value = wpinv_get_option( $key, null ); |
@@ -61,80 +61,80 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | - * Retrieves the email body. |
|
65 | - * |
|
64 | + * Retrieves the email body. |
|
65 | + * |
|
66 | 66 | * @return string |
67 | - */ |
|
68 | - public function get_body() { |
|
67 | + */ |
|
68 | + public function get_body() { |
|
69 | 69 | $body = $this->get_option( 'body' ); |
70 | 70 | return apply_filters( 'getpaid_get_email_body', $body, $this->id, $this->object ); |
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | - * Retrieves the email subject. |
|
75 | - * |
|
74 | + * Retrieves the email subject. |
|
75 | + * |
|
76 | 76 | * @return string |
77 | - */ |
|
78 | - public function get_subject() { |
|
77 | + */ |
|
78 | + public function get_subject() { |
|
79 | 79 | $subject = $this->get_option( 'subject' ); |
80 | 80 | return apply_filters( 'getpaid_get_email_subject', $subject, $this->id, $this->object ); |
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | - * Retrieves the email heading. |
|
85 | - * |
|
84 | + * Retrieves the email heading. |
|
85 | + * |
|
86 | 86 | * @return string |
87 | - */ |
|
88 | - public function get_heading() { |
|
87 | + */ |
|
88 | + public function get_heading() { |
|
89 | 89 | $heading = $this->get_option( 'heading' ); |
90 | 90 | return apply_filters( 'getpaid_get_email_heading', $heading, $this->id, $this->object ); |
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Checks if an email is active. |
|
95 | - * |
|
94 | + * Checks if an email is active. |
|
95 | + * |
|
96 | 96 | * @return bool |
97 | - */ |
|
98 | - public function is_active() { |
|
97 | + */ |
|
98 | + public function is_active() { |
|
99 | 99 | $is_active = ! empty( $this->get_option( 'is_active' ) ); |
100 | 100 | return apply_filters( 'getpaid_email_type_is_active', $is_active, $this->id, $this->object ); |
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | - * Checks if the site's admin should receive email notifications. |
|
105 | - * |
|
104 | + * Checks if the site's admin should receive email notifications. |
|
105 | + * |
|
106 | 106 | * @return bool |
107 | - */ |
|
108 | - public function include_admin_bcc() { |
|
107 | + */ |
|
108 | + public function include_admin_bcc() { |
|
109 | 109 | $include_admin_bcc = ! empty( $this->get_option( 'admin_bcc' ) ); |
110 | 110 | return apply_filters( 'getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object ); |
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | - * Checks whether this email should be sent to the customer or admin. |
|
115 | - * |
|
114 | + * Checks whether this email should be sent to the customer or admin. |
|
115 | + * |
|
116 | 116 | * @return bool |
117 | - */ |
|
118 | - public function is_admin_email() { |
|
117 | + */ |
|
118 | + public function is_admin_email() { |
|
119 | 119 | $is_admin_email = in_array( $this->id, array( 'new_invoice', 'cancelled_invoice', 'failed_invoice' ) ); |
120 | 120 | return apply_filters( 'getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object ); |
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Returns email attachments. |
|
125 | - * |
|
124 | + * Returns email attachments. |
|
125 | + * |
|
126 | 126 | * @return array |
127 | - */ |
|
128 | - public function get_attachments() { |
|
127 | + */ |
|
128 | + public function get_attachments() { |
|
129 | 129 | return apply_filters( 'getpaid_get_email_attachments', array(), $this->id, $this->object ); |
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * Returns an array of merge tags. |
|
134 | - * |
|
133 | + * Returns an array of merge tags. |
|
134 | + * |
|
135 | 135 | * @return array |
136 | - */ |
|
137 | - public function get_merge_tags() { |
|
136 | + */ |
|
137 | + public function get_merge_tags() { |
|
138 | 138 | |
139 | 139 | $merge_tags = array( |
140 | 140 | '{site_title}' => wpinv_get_blogname(), |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
148 | - * Adds merge tags to a text. |
|
149 | - * |
|
148 | + * Adds merge tags to a text. |
|
149 | + * |
|
150 | 150 | * @param string string $text |
151 | 151 | * @param array $merge_tags |
152 | 152 | * @return string |
153 | - */ |
|
154 | - public function add_merge_tags( $text, $merge_tags = array() ) { |
|
153 | + */ |
|
154 | + public function add_merge_tags( $text, $merge_tags = array() ) { |
|
155 | 155 | |
156 | 156 | foreach ( $merge_tags as $key => $value ) { |
157 | 157 | $text = str_replace( $key, $value, $text ); |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
164 | - * Returns the email content |
|
165 | - * |
|
164 | + * Returns the email content |
|
165 | + * |
|
166 | 166 | * @param array $merge_tags |
167 | 167 | * @param array $extra_args Extra template args |
168 | 168 | * @return string |
169 | - */ |
|
170 | - public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
169 | + */ |
|
170 | + public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
171 | 171 | |
172 | 172 | $content = wpinv_get_template_html( |
173 | 173 | "emails/wpinv-email-{$this->id}.php", |
@@ -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,49 +31,49 @@ 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( array_unique( 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( array_unique( 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 | 61 | $result = false; |
62 | 62 | |
63 | 63 | foreach ( $this->wp_mail_data['to'] as $to ) { |
64 | - $result = $this->_send( $to, $data ); |
|
64 | + $result = $this->_send( $to, $data ); |
|
65 | 65 | } |
66 | 66 | |
67 | - // Remove our hooks. |
|
68 | - $this->after_sending(); |
|
67 | + // Remove our hooks. |
|
68 | + $this->after_sending(); |
|
69 | 69 | |
70 | - $this->wp_mail_data = null; |
|
70 | + $this->wp_mail_data = null; |
|
71 | 71 | |
72 | - return $result; |
|
73 | - } |
|
72 | + return $result; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Does the actual sending. |
|
75 | + /** |
|
76 | + * Does the actual sending. |
|
77 | 77 | * |
78 | 78 | * @param string $to The recipient's email. |
79 | 79 | * @param array $data The email's data. |
@@ -81,81 +81,81 @@ discard block |
||
81 | 81 | * @param array $attachments The email attachments. |
82 | 82 | * |
83 | 83 | * @return bool |
84 | - */ |
|
85 | - protected function _send( $to, $data ) { |
|
86 | - |
|
87 | - // Prepare the sending function. |
|
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | - |
|
90 | - // Send the actual email. |
|
91 | - $result = call_user_func( |
|
92 | - $sending_function, |
|
93 | - $to, |
|
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | - $data['email'], |
|
96 | - $data['headers'], |
|
97 | - $data['attachments'] |
|
98 | - ); |
|
99 | - |
|
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | - } |
|
104 | - |
|
105 | - return $result; |
|
106 | - } |
|
84 | + */ |
|
85 | + protected function _send( $to, $data ) { |
|
86 | + |
|
87 | + // Prepare the sending function. |
|
88 | + $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | + |
|
90 | + // Send the actual email. |
|
91 | + $result = call_user_func( |
|
92 | + $sending_function, |
|
93 | + $to, |
|
94 | + html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | + $data['email'], |
|
96 | + $data['headers'], |
|
97 | + $data['attachments'] |
|
98 | + ); |
|
99 | + |
|
100 | + if ( ! $result ) { |
|
101 | + $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | + wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | + } |
|
104 | + |
|
105 | + return $result; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | /** |
109 | - * Retrieves email headers. |
|
110 | - */ |
|
111 | - public function get_headers() { |
|
109 | + * Retrieves email headers. |
|
110 | + */ |
|
111 | + public function get_headers() { |
|
112 | 112 | |
113 | - $name = $this->get_from_name(); |
|
114 | - $reply_to = $this->get_reply_to(); |
|
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
113 | + $name = $this->get_from_name(); |
|
114 | + $reply_to = $this->get_reply_to(); |
|
115 | + $headers = array( "Reply-To:$name <$reply_to>" ); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
118 | 118 | |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | /** |
122 | - * Fires before an email is sent |
|
123 | - * |
|
124 | - * @since 1.0.0 |
|
125 | - */ |
|
126 | - public function before_sending() { |
|
122 | + * Fires before an email is sent |
|
123 | + * |
|
124 | + * @since 1.0.0 |
|
125 | + */ |
|
126 | + public function before_sending() { |
|
127 | 127 | |
128 | 128 | do_action( 'getpaid_before_send_email', $this ); |
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
129 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | + add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | + add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | 136 | /** |
137 | - * Returns the from name. |
|
138 | - */ |
|
139 | - public function get_from_name() { |
|
137 | + * Returns the from name. |
|
138 | + */ |
|
139 | + public function get_from_name() { |
|
140 | 140 | |
141 | 141 | $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if ( empty( $from_name ) ) { |
|
144 | + $from_name = get_bloginfo( 'name' ); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | - * Returns the from email. |
|
152 | - */ |
|
153 | - public function get_from_address() { |
|
151 | + * Returns the from email. |
|
152 | + */ |
|
153 | + public function get_from_address() { |
|
154 | 154 | |
155 | 155 | $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
158 | - $from_address = $this->default_from_address(); |
|
157 | + if ( ! is_email( $from_address ) ) { |
|
158 | + $from_address = $this->default_from_address(); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return $from_address; |
@@ -163,75 +163,75 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * The default emails from address. |
|
167 | - * |
|
168 | - * Defaults to wordpress@$sitename |
|
169 | - * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | - * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | - * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | - * |
|
173 | - */ |
|
174 | - public function default_from_address() { |
|
175 | - |
|
176 | - // Get the site domain and get rid of www. |
|
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
180 | - } |
|
181 | - |
|
182 | - $from_email = 'wordpress@' . $sitename; |
|
183 | - |
|
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
166 | + * The default emails from address. |
|
167 | + * |
|
168 | + * Defaults to wordpress@$sitename |
|
169 | + * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | + * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | + * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | + * |
|
173 | + */ |
|
174 | + public function default_from_address() { |
|
175 | + |
|
176 | + // Get the site domain and get rid of www. |
|
177 | + $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | + if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | + $sitename = substr( $sitename, 4 ); |
|
180 | + } |
|
181 | + |
|
182 | + $from_email = 'wordpress@' . $sitename; |
|
183 | + |
|
184 | + return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | - * Get the email reply-to. |
|
190 | - * |
|
191 | - * |
|
192 | - * @return string The email reply-to address. |
|
193 | - */ |
|
194 | - public function get_reply_to() { |
|
189 | + * Get the email reply-to. |
|
190 | + * |
|
191 | + * |
|
192 | + * @return string The email reply-to address. |
|
193 | + */ |
|
194 | + public function get_reply_to() { |
|
195 | 195 | |
196 | - $reply_to = wpinv_get_admin_email(); |
|
196 | + $reply_to = wpinv_get_admin_email(); |
|
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
200 | - } |
|
198 | + if ( ! is_email( $reply_to ) ) { |
|
199 | + $reply_to = get_option( 'admin_email' ); |
|
200 | + } |
|
201 | 201 | |
202 | - return $reply_to; |
|
202 | + return $reply_to; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | - * Get the email content type. |
|
207 | - * |
|
208 | - */ |
|
209 | - public function get_content_type() { |
|
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
206 | + * Get the email content type. |
|
207 | + * |
|
208 | + */ |
|
209 | + public function get_content_type() { |
|
210 | + return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | - * Ensures that our email messages are not messed up by template plugins. |
|
215 | - * |
|
216 | - * @return array wp_mail_data. |
|
217 | - */ |
|
218 | - public function ensure_email_content( $args ) { |
|
219 | - $args['message'] = $this->wp_mail_data['email']; |
|
220 | - return $args; |
|
214 | + * Ensures that our email messages are not messed up by template plugins. |
|
215 | + * |
|
216 | + * @return array wp_mail_data. |
|
217 | + */ |
|
218 | + public function ensure_email_content( $args ) { |
|
219 | + $args['message'] = $this->wp_mail_data['email']; |
|
220 | + return $args; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | - * A little house keeping after an email is sent. |
|
225 | - * |
|
226 | - */ |
|
227 | - public function after_sending() { |
|
224 | + * A little house keeping after an email is sent. |
|
225 | + * |
|
226 | + */ |
|
227 | + public function after_sending() { |
|
228 | 228 | |
229 | 229 | do_action( 'after_noptin_sends_email', $this->wp_mail_data ); |
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
230 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | + remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | + remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
234 | 234 | |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | 237 | } |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | 198 | |
199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | - $tip = esc_attr( $option['desc'] ); |
|
201 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
202 | - unset( $option['desc'] ); |
|
203 | - } |
|
199 | + if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | + $tip = esc_attr( $option['desc'] ); |
|
201 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
202 | + unset( $option['desc'] ); |
|
203 | + } |
|
204 | 204 | |
205 | 205 | // Loop through all tabs. |
206 | 206 | add_settings_field( |
@@ -425,333 +425,333 @@ discard block |
||
425 | 425 | } |
426 | 426 | |
427 | 427 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
428 | - $pages_options = array(); |
|
428 | + $pages_options = array(); |
|
429 | 429 | |
430 | - if( $default_label !== NULL && $default_label !== false ) { |
|
431 | - $pages_options = array( '' => $default_label ); // Blank option |
|
432 | - } |
|
430 | + if( $default_label !== NULL && $default_label !== false ) { |
|
431 | + $pages_options = array( '' => $default_label ); // Blank option |
|
432 | + } |
|
433 | 433 | |
434 | - $pages = get_pages(); |
|
435 | - if ( $pages ) { |
|
436 | - foreach ( $pages as $page ) { |
|
437 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
434 | + $pages = get_pages(); |
|
435 | + if ( $pages ) { |
|
436 | + foreach ( $pages as $page ) { |
|
437 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
438 | 438 | $pages_options[ $page->ID ] = $title; |
439 | - } |
|
440 | - } |
|
439 | + } |
|
440 | + } |
|
441 | 441 | |
442 | - return $pages_options; |
|
442 | + return $pages_options; |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | function wpinv_header_callback( $args ) { |
446 | - if ( !empty( $args['desc'] ) ) { |
|
446 | + if ( !empty( $args['desc'] ) ) { |
|
447 | 447 | echo $args['desc']; |
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | 451 | function wpinv_hidden_callback( $args ) { |
452 | - global $wpinv_options; |
|
453 | - |
|
454 | - if ( isset( $args['set_value'] ) ) { |
|
455 | - $value = $args['set_value']; |
|
456 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
457 | - $value = $wpinv_options[ $args['id'] ]; |
|
458 | - } else { |
|
459 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
460 | - } |
|
461 | - |
|
462 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
463 | - $args['readonly'] = true; |
|
464 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
465 | - $name = ''; |
|
466 | - } else { |
|
467 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
468 | - } |
|
469 | - |
|
470 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
452 | + global $wpinv_options; |
|
453 | + |
|
454 | + if ( isset( $args['set_value'] ) ) { |
|
455 | + $value = $args['set_value']; |
|
456 | + } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
457 | + $value = $wpinv_options[ $args['id'] ]; |
|
458 | + } else { |
|
459 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
460 | + } |
|
461 | + |
|
462 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
463 | + $args['readonly'] = true; |
|
464 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
465 | + $name = ''; |
|
466 | + } else { |
|
467 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
468 | + } |
|
469 | + |
|
470 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
471 | 471 | |
472 | - echo $html; |
|
472 | + echo $html; |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | function wpinv_checkbox_callback( $args ) { |
476 | - global $wpinv_options; |
|
476 | + global $wpinv_options; |
|
477 | 477 | |
478 | 478 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
479 | 479 | |
480 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
481 | - $name = ''; |
|
482 | - } else { |
|
483 | - $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
484 | - } |
|
480 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
481 | + $name = ''; |
|
482 | + } else { |
|
483 | + $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
484 | + } |
|
485 | 485 | |
486 | - $std = isset( $args['std'] ) ? $args['std'] : 0; |
|
487 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
488 | - $checked = checked( empty( $value ), false, false ); |
|
486 | + $std = isset( $args['std'] ) ? $args['std'] : 0; |
|
487 | + $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
488 | + $checked = checked( empty( $value ), false, false ); |
|
489 | 489 | |
490 | - $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
491 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
490 | + $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
491 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
492 | 492 | |
493 | - echo $html; |
|
493 | + echo $html; |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | function wpinv_multicheck_callback( $args ) { |
497 | - global $wpinv_options; |
|
497 | + global $wpinv_options; |
|
498 | 498 | |
499 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
500 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
499 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
500 | + $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
501 | 501 | |
502 | - if ( ! empty( $args['options'] ) ) { |
|
502 | + if ( ! empty( $args['options'] ) ) { |
|
503 | 503 | |
504 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
505 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
504 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
505 | + $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
506 | 506 | |
507 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
507 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
508 | 508 | foreach( $args['options'] as $key => $option ): |
509 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
510 | - if ( in_array( $sanitize_key, $value ) ) { |
|
511 | - $enabled = $sanitize_key; |
|
512 | - } else { |
|
513 | - $enabled = NULL; |
|
514 | - } |
|
515 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
516 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
517 | - endforeach; |
|
518 | - echo '</div>'; |
|
519 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
520 | - } |
|
509 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
510 | + if ( in_array( $sanitize_key, $value ) ) { |
|
511 | + $enabled = $sanitize_key; |
|
512 | + } else { |
|
513 | + $enabled = NULL; |
|
514 | + } |
|
515 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
516 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
517 | + endforeach; |
|
518 | + echo '</div>'; |
|
519 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
520 | + } |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | function wpinv_payment_icons_callback( $args ) { |
524 | - global $wpinv_options; |
|
524 | + global $wpinv_options; |
|
525 | 525 | |
526 | 526 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
527 | 527 | |
528 | - if ( ! empty( $args['options'] ) ) { |
|
529 | - foreach( $args['options'] as $key => $option ) { |
|
528 | + if ( ! empty( $args['options'] ) ) { |
|
529 | + foreach( $args['options'] as $key => $option ) { |
|
530 | 530 | $sanitize_key = wpinv_sanitize_key( $key ); |
531 | 531 | |
532 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
533 | - $enabled = $option; |
|
534 | - } else { |
|
535 | - $enabled = NULL; |
|
536 | - } |
|
537 | - |
|
538 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
539 | - |
|
540 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
541 | - |
|
542 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
543 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
544 | - } else { |
|
545 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
546 | - |
|
547 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
548 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
549 | - } else { |
|
550 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
551 | - $content_dir = WP_CONTENT_DIR; |
|
552 | - |
|
553 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
554 | - // Replaces backslashes with forward slashes for Windows systems |
|
555 | - $image = wp_normalize_path( $image ); |
|
556 | - $content_dir = wp_normalize_path( $content_dir ); |
|
557 | - } |
|
558 | - |
|
559 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
560 | - } |
|
561 | - |
|
562 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
563 | - } |
|
564 | - echo $option . '</label>'; |
|
565 | - } |
|
566 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
567 | - } |
|
532 | + if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
533 | + $enabled = $option; |
|
534 | + } else { |
|
535 | + $enabled = NULL; |
|
536 | + } |
|
537 | + |
|
538 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
539 | + |
|
540 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
541 | + |
|
542 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
543 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
544 | + } else { |
|
545 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
546 | + |
|
547 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
548 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
549 | + } else { |
|
550 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
551 | + $content_dir = WP_CONTENT_DIR; |
|
552 | + |
|
553 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
554 | + // Replaces backslashes with forward slashes for Windows systems |
|
555 | + $image = wp_normalize_path( $image ); |
|
556 | + $content_dir = wp_normalize_path( $content_dir ); |
|
557 | + } |
|
558 | + |
|
559 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
560 | + } |
|
561 | + |
|
562 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
563 | + } |
|
564 | + echo $option . '</label>'; |
|
565 | + } |
|
566 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
567 | + } |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | function wpinv_radio_callback( $args ) { |
571 | - global $wpinv_options; |
|
571 | + global $wpinv_options; |
|
572 | 572 | |
573 | 573 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
574 | 574 | |
575 | 575 | foreach ( $args['options'] as $key => $option ) : |
576 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
576 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
577 | 577 | |
578 | 578 | $checked = false; |
579 | 579 | |
580 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
581 | - $checked = true; |
|
582 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
583 | - $checked = true; |
|
580 | + if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
581 | + $checked = true; |
|
582 | + elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
583 | + $checked = true; |
|
584 | 584 | |
585 | - echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
586 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
587 | - endforeach; |
|
585 | + echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
586 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
587 | + endforeach; |
|
588 | 588 | |
589 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
589 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | function wpinv_gateways_callback( $args ) { |
593 | - global $wpinv_options; |
|
593 | + global $wpinv_options; |
|
594 | 594 | |
595 | 595 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
596 | 596 | |
597 | - foreach ( $args['options'] as $key => $option ) : |
|
598 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
597 | + foreach ( $args['options'] as $key => $option ) : |
|
598 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
599 | 599 | |
600 | 600 | if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
601 | - $enabled = '1'; |
|
602 | - else |
|
603 | - $enabled = null; |
|
601 | + $enabled = '1'; |
|
602 | + else |
|
603 | + $enabled = null; |
|
604 | 604 | |
605 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
606 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
607 | - endforeach; |
|
605 | + echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
606 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
607 | + endforeach; |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | function wpinv_gateway_select_callback($args) { |
611 | - global $wpinv_options; |
|
611 | + global $wpinv_options; |
|
612 | 612 | |
613 | 613 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
614 | 614 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
615 | 615 | |
616 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
616 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
617 | 617 | |
618 | - foreach ( $args['options'] as $key => $option ) : |
|
619 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
618 | + foreach ( $args['options'] as $key => $option ) : |
|
619 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
620 | 620 | $selected = selected( $key, $args['selected'], false ); |
621 | 621 | } else { |
622 | 622 | $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
623 | 623 | } |
624 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
625 | - endforeach; |
|
624 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
625 | + endforeach; |
|
626 | 626 | |
627 | - echo '</select>'; |
|
628 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
627 | + echo '</select>'; |
|
628 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | function wpinv_text_callback( $args ) { |
632 | - global $wpinv_options; |
|
632 | + global $wpinv_options; |
|
633 | 633 | |
634 | 634 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
635 | 635 | |
636 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
637 | - $value = $wpinv_options[ $args['id'] ]; |
|
638 | - } else { |
|
639 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
640 | - } |
|
641 | - |
|
642 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
643 | - $args['readonly'] = true; |
|
644 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
645 | - $name = ''; |
|
646 | - } else { |
|
647 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
648 | - } |
|
649 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
650 | - |
|
651 | - $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
652 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
653 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
654 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
655 | - |
|
656 | - echo $html; |
|
636 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
637 | + $value = $wpinv_options[ $args['id'] ]; |
|
638 | + } else { |
|
639 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
640 | + } |
|
641 | + |
|
642 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
643 | + $args['readonly'] = true; |
|
644 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
645 | + $name = ''; |
|
646 | + } else { |
|
647 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
648 | + } |
|
649 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
650 | + |
|
651 | + $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
652 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
653 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
654 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
655 | + |
|
656 | + echo $html; |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | function wpinv_number_callback( $args ) { |
660 | - global $wpinv_options; |
|
660 | + global $wpinv_options; |
|
661 | 661 | |
662 | 662 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
663 | 663 | |
664 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
665 | - $value = $wpinv_options[ $args['id'] ]; |
|
666 | - } else { |
|
667 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
668 | - } |
|
669 | - |
|
670 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
671 | - $args['readonly'] = true; |
|
672 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
673 | - $name = ''; |
|
674 | - } else { |
|
675 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
676 | - } |
|
677 | - |
|
678 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
679 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
680 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
681 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
682 | - |
|
683 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
684 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
685 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
686 | - |
|
687 | - echo $html; |
|
664 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
665 | + $value = $wpinv_options[ $args['id'] ]; |
|
666 | + } else { |
|
667 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
668 | + } |
|
669 | + |
|
670 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
671 | + $args['readonly'] = true; |
|
672 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
673 | + $name = ''; |
|
674 | + } else { |
|
675 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
676 | + } |
|
677 | + |
|
678 | + $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
679 | + $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
680 | + $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
681 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
682 | + |
|
683 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
684 | + $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
685 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
686 | + |
|
687 | + echo $html; |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | function wpinv_textarea_callback( $args ) { |
691 | - global $wpinv_options; |
|
691 | + global $wpinv_options; |
|
692 | 692 | |
693 | 693 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
694 | 694 | |
695 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
696 | - $value = $wpinv_options[ $args['id'] ]; |
|
697 | - } else { |
|
698 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
699 | - } |
|
695 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
696 | + $value = $wpinv_options[ $args['id'] ]; |
|
697 | + } else { |
|
698 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
699 | + } |
|
700 | 700 | |
701 | 701 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
702 | 702 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
703 | 703 | |
704 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
705 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
704 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
705 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
706 | 706 | |
707 | - echo $html; |
|
707 | + echo $html; |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | function wpinv_password_callback( $args ) { |
711 | - global $wpinv_options; |
|
711 | + global $wpinv_options; |
|
712 | 712 | |
713 | 713 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
714 | 714 | |
715 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
716 | - $value = $wpinv_options[ $args['id'] ]; |
|
717 | - } else { |
|
718 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
719 | - } |
|
715 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
716 | + $value = $wpinv_options[ $args['id'] ]; |
|
717 | + } else { |
|
718 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
719 | + } |
|
720 | 720 | |
721 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
722 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
723 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
721 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
722 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
723 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
724 | 724 | |
725 | - echo $html; |
|
725 | + echo $html; |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | function wpinv_missing_callback($args) { |
729 | - printf( |
|
730 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
731 | - '<strong>' . $args['id'] . '</strong>' |
|
732 | - ); |
|
729 | + printf( |
|
730 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
731 | + '<strong>' . $args['id'] . '</strong>' |
|
732 | + ); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | function wpinv_select_callback($args) { |
736 | - global $wpinv_options; |
|
736 | + global $wpinv_options; |
|
737 | 737 | |
738 | 738 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
739 | 739 | |
740 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
741 | - $value = $wpinv_options[ $args['id'] ]; |
|
742 | - } else { |
|
743 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
744 | - } |
|
740 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
741 | + $value = $wpinv_options[ $args['id'] ]; |
|
742 | + } else { |
|
743 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
744 | + } |
|
745 | 745 | |
746 | 746 | if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
747 | 747 | $value = $args['selected']; |
748 | 748 | } |
749 | 749 | |
750 | - if ( isset( $args['placeholder'] ) ) { |
|
751 | - $placeholder = $args['placeholder']; |
|
752 | - } else { |
|
753 | - $placeholder = ''; |
|
754 | - } |
|
750 | + if ( isset( $args['placeholder'] ) ) { |
|
751 | + $placeholder = $args['placeholder']; |
|
752 | + } else { |
|
753 | + $placeholder = ''; |
|
754 | + } |
|
755 | 755 | |
756 | 756 | if( !empty( $args['onchange'] ) ) { |
757 | 757 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
@@ -761,143 +761,143 @@ discard block |
||
761 | 761 | |
762 | 762 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
763 | 763 | |
764 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
764 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
765 | 765 | |
766 | - foreach ( $args['options'] as $option => $name ) { |
|
767 | - $selected = selected( $option, $value, false ); |
|
768 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
769 | - } |
|
766 | + foreach ( $args['options'] as $option => $name ) { |
|
767 | + $selected = selected( $option, $value, false ); |
|
768 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
769 | + } |
|
770 | 770 | |
771 | - $html .= '</select>'; |
|
772 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
771 | + $html .= '</select>'; |
|
772 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
773 | 773 | |
774 | - echo $html; |
|
774 | + echo $html; |
|
775 | 775 | } |
776 | 776 | |
777 | 777 | function wpinv_color_select_callback( $args ) { |
778 | - global $wpinv_options; |
|
778 | + global $wpinv_options; |
|
779 | 779 | |
780 | 780 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
781 | 781 | |
782 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
783 | - $value = $wpinv_options[ $args['id'] ]; |
|
784 | - } else { |
|
785 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
786 | - } |
|
782 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
783 | + $value = $wpinv_options[ $args['id'] ]; |
|
784 | + } else { |
|
785 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
786 | + } |
|
787 | 787 | |
788 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
788 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
789 | 789 | |
790 | - foreach ( $args['options'] as $option => $color ) { |
|
791 | - $selected = selected( $option, $value, false ); |
|
792 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
793 | - } |
|
790 | + foreach ( $args['options'] as $option => $color ) { |
|
791 | + $selected = selected( $option, $value, false ); |
|
792 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
793 | + } |
|
794 | 794 | |
795 | - $html .= '</select>'; |
|
796 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
795 | + $html .= '</select>'; |
|
796 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
797 | 797 | |
798 | - echo $html; |
|
798 | + echo $html; |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | function wpinv_rich_editor_callback( $args ) { |
802 | - global $wpinv_options, $wp_version; |
|
802 | + global $wpinv_options, $wp_version; |
|
803 | 803 | |
804 | 804 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
805 | 805 | |
806 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
807 | - $value = $wpinv_options[ $args['id'] ]; |
|
806 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
807 | + $value = $wpinv_options[ $args['id'] ]; |
|
808 | 808 | |
809 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
810 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
811 | - } |
|
812 | - } else { |
|
813 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
814 | - } |
|
809 | + if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
810 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
811 | + } |
|
812 | + } else { |
|
813 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
814 | + } |
|
815 | 815 | |
816 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
816 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
817 | 817 | |
818 | - $html = '<div class="getpaid-settings-editor-input">'; |
|
819 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
820 | - ob_start(); |
|
821 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
822 | - $html .= ob_get_clean(); |
|
823 | - } else { |
|
824 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
825 | - } |
|
818 | + $html = '<div class="getpaid-settings-editor-input">'; |
|
819 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
820 | + ob_start(); |
|
821 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
822 | + $html .= ob_get_clean(); |
|
823 | + } else { |
|
824 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
825 | + } |
|
826 | 826 | |
827 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
827 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
828 | 828 | |
829 | - echo $html; |
|
829 | + echo $html; |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | function wpinv_upload_callback( $args ) { |
833 | - global $wpinv_options; |
|
833 | + global $wpinv_options; |
|
834 | 834 | |
835 | 835 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
836 | 836 | |
837 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
838 | - $value = $wpinv_options[$args['id']]; |
|
839 | - } else { |
|
840 | - $value = isset($args['std']) ? $args['std'] : ''; |
|
841 | - } |
|
837 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
838 | + $value = $wpinv_options[$args['id']]; |
|
839 | + } else { |
|
840 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
841 | + } |
|
842 | 842 | |
843 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
844 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
845 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
846 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
843 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
844 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
845 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
846 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
847 | 847 | |
848 | - echo $html; |
|
848 | + echo $html; |
|
849 | 849 | } |
850 | 850 | |
851 | 851 | function wpinv_color_callback( $args ) { |
852 | - global $wpinv_options; |
|
852 | + global $wpinv_options; |
|
853 | 853 | |
854 | 854 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
855 | 855 | |
856 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
857 | - $value = $wpinv_options[ $args['id'] ]; |
|
858 | - } else { |
|
859 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
860 | - } |
|
856 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
857 | + $value = $wpinv_options[ $args['id'] ]; |
|
858 | + } else { |
|
859 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
860 | + } |
|
861 | 861 | |
862 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
862 | + $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
863 | 863 | |
864 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
865 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
864 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
865 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
866 | 866 | |
867 | - echo $html; |
|
867 | + echo $html; |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | function wpinv_country_states_callback($args) { |
871 | - global $wpinv_options; |
|
871 | + global $wpinv_options; |
|
872 | 872 | |
873 | 873 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
874 | 874 | |
875 | - if ( isset( $args['placeholder'] ) ) { |
|
876 | - $placeholder = $args['placeholder']; |
|
877 | - } else { |
|
878 | - $placeholder = ''; |
|
879 | - } |
|
875 | + if ( isset( $args['placeholder'] ) ) { |
|
876 | + $placeholder = $args['placeholder']; |
|
877 | + } else { |
|
878 | + $placeholder = ''; |
|
879 | + } |
|
880 | 880 | |
881 | - $states = wpinv_get_country_states(); |
|
881 | + $states = wpinv_get_country_states(); |
|
882 | 882 | |
883 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
884 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
883 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
884 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
885 | 885 | |
886 | - foreach ( $states as $option => $name ) { |
|
887 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
888 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
889 | - } |
|
886 | + foreach ( $states as $option => $name ) { |
|
887 | + $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
888 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
889 | + } |
|
890 | 890 | |
891 | - $html .= '</select>'; |
|
892 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
891 | + $html .= '</select>'; |
|
892 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
893 | 893 | |
894 | - echo $html; |
|
894 | + echo $html; |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | function wpinv_tax_rates_callback($args) { |
898 | - global $wpinv_options; |
|
899 | - $rates = wpinv_get_tax_rates(); |
|
900 | - ob_start(); ?> |
|
898 | + global $wpinv_options; |
|
899 | + $rates = wpinv_get_tax_rates(); |
|
900 | + ob_start(); ?> |
|
901 | 901 | </td><tr> |
902 | 902 | <td colspan="2" class="wpinv_tax_tdbox"> |
903 | 903 | <p><?php echo $args['desc']; ?></p> |
@@ -921,40 +921,40 @@ discard block |
||
921 | 921 | <tr> |
922 | 922 | <td class="wpinv_tax_country"> |
923 | 923 | <?php |
924 | - echo wpinv_html_select( array( |
|
925 | - 'options' => wpinv_get_country_list( true ), |
|
926 | - 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
924 | + echo wpinv_html_select( array( |
|
925 | + 'options' => wpinv_get_country_list( true ), |
|
926 | + 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
927 | 927 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
928 | - 'selected' => $rate['country'], |
|
929 | - 'show_option_all' => false, |
|
930 | - 'show_option_none' => false, |
|
931 | - 'class' => 'wpinv-tax-country wpi_select2', |
|
932 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
933 | - ) ); |
|
934 | - ?> |
|
928 | + 'selected' => $rate['country'], |
|
929 | + 'show_option_all' => false, |
|
930 | + 'show_option_none' => false, |
|
931 | + 'class' => 'wpinv-tax-country wpi_select2', |
|
932 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
933 | + ) ); |
|
934 | + ?> |
|
935 | 935 | </td> |
936 | 936 | <td class="wpinv_tax_state"> |
937 | 937 | <?php |
938 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
939 | - if( !empty( $states ) ) { |
|
940 | - echo wpinv_html_select( array( |
|
941 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
942 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
938 | + $states = wpinv_get_country_states( $rate['country'] ); |
|
939 | + if( !empty( $states ) ) { |
|
940 | + echo wpinv_html_select( array( |
|
941 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
942 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
943 | 943 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
944 | - 'selected' => $rate['state'], |
|
945 | - 'show_option_all' => false, |
|
946 | - 'show_option_none' => false, |
|
944 | + 'selected' => $rate['state'], |
|
945 | + 'show_option_all' => false, |
|
946 | + 'show_option_none' => false, |
|
947 | 947 | 'class' => 'wpi_select2', |
948 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
949 | - ) ); |
|
950 | - } else { |
|
951 | - echo wpinv_html_text( array( |
|
952 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
953 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
948 | + 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
949 | + ) ); |
|
950 | + } else { |
|
951 | + echo wpinv_html_text( array( |
|
952 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
953 | + 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
954 | 954 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
955 | - ) ); |
|
956 | - } |
|
957 | - ?> |
|
955 | + ) ); |
|
956 | + } |
|
957 | + ?> |
|
958 | 958 | </td> |
959 | 959 | <td class="wpinv_tax_global"> |
960 | 960 | <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
@@ -969,19 +969,19 @@ discard block |
||
969 | 969 | <tr> |
970 | 970 | <td class="wpinv_tax_country"> |
971 | 971 | <?php |
972 | - echo wpinv_html_select( array( |
|
973 | - 'options' => wpinv_get_country_list( true ), |
|
974 | - 'name' => 'tax_rates[0][country]', |
|
975 | - 'show_option_all' => false, |
|
976 | - 'show_option_none' => false, |
|
977 | - 'class' => 'wpinv-tax-country wpi_select2', |
|
978 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
979 | - ) ); ?> |
|
972 | + echo wpinv_html_select( array( |
|
973 | + 'options' => wpinv_get_country_list( true ), |
|
974 | + 'name' => 'tax_rates[0][country]', |
|
975 | + 'show_option_all' => false, |
|
976 | + 'show_option_none' => false, |
|
977 | + 'class' => 'wpinv-tax-country wpi_select2', |
|
978 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
979 | + ) ); ?> |
|
980 | 980 | </td> |
981 | 981 | <td class="wpinv_tax_state"> |
982 | 982 | <?php echo wpinv_html_text( array( |
983 | - 'name' => 'tax_rates[0][state]' |
|
984 | - ) ); ?> |
|
983 | + 'name' => 'tax_rates[0][state]' |
|
984 | + ) ); ?> |
|
985 | 985 | </td> |
986 | 986 | <td class="wpinv_tax_global"> |
987 | 987 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
@@ -996,7 +996,7 @@ discard block |
||
996 | 996 | <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
997 | 997 | </table> |
998 | 998 | <?php |
999 | - echo ob_get_clean(); |
|
999 | + echo ob_get_clean(); |
|
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | function wpinv_tools_callback($args) { |
@@ -1024,15 +1024,15 @@ discard block |
||
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | function wpinv_descriptive_text_callback( $args ) { |
1027 | - echo wp_kses_post( $args['desc'] ); |
|
1027 | + echo wp_kses_post( $args['desc'] ); |
|
1028 | 1028 | } |
1029 | 1029 | |
1030 | 1030 | function wpinv_hook_callback( $args ) { |
1031 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1031 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | function wpinv_set_settings_cap() { |
1035 | - return wpinv_get_capability(); |
|
1035 | + return wpinv_get_capability(); |
|
1036 | 1036 | } |
1037 | 1037 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
1038 | 1038 |
@@ -14,438 +14,438 @@ 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 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
108 | - |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Define plugin constants. |
|
113 | - */ |
|
114 | - public function define_constants() { |
|
115 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
116 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
117 | - $this->version = WPINV_VERSION; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Hook into actions and filters. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - */ |
|
125 | - protected function init_hooks() { |
|
126 | - /* Internationalize the text strings used. */ |
|
127 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
128 | - |
|
129 | - // Init the plugin after WordPress inits. |
|
130 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
131 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
132 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
133 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ) ); |
|
134 | - |
|
135 | - if ( class_exists( 'BuddyPress' ) ) { |
|
136 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
137 | - } |
|
138 | - |
|
139 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
140 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
141 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
142 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
143 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
144 | - |
|
145 | - // Fires after registering actions. |
|
146 | - do_action( 'wpinv_actions', $this ); |
|
147 | - do_action( 'getpaid_actions', $this ); |
|
148 | - |
|
149 | - } |
|
150 | - |
|
151 | - public function plugins_loaded() { |
|
152 | - /* Internationalize the text strings used. */ |
|
153 | - $this->load_textdomain(); |
|
154 | - |
|
155 | - do_action( 'wpinv_loaded' ); |
|
156 | - |
|
157 | - // Fix oxygen page builder conflict |
|
158 | - if ( function_exists( 'ct_css_output' ) ) { |
|
159 | - wpinv_oxygen_fix_conflict(); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Load the translation of the plugin. |
|
165 | - * |
|
166 | - * @since 1.0 |
|
167 | - */ |
|
168 | - public function load_textdomain( $locale = NULL ) { |
|
169 | - if ( empty( $locale ) ) { |
|
170 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
171 | - } |
|
172 | - |
|
173 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
174 | - |
|
175 | - unload_textdomain( 'invoicing' ); |
|
176 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
177 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
178 | - |
|
179 | - /** |
|
180 | - * Define language constants. |
|
181 | - */ |
|
182 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Include required core files used in admin and on the frontend. |
|
187 | - */ |
|
188 | - public function includes() { |
|
189 | - |
|
190 | - // Start with the settings. |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
192 | - |
|
193 | - // Packages/libraries. |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
197 | - |
|
198 | - // Load functions. |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
213 | - |
|
214 | - // Register autoloader. |
|
215 | - try { |
|
216 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
217 | - } catch ( Exception $e ) { |
|
218 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
219 | - } |
|
220 | - |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
243 | - |
|
244 | - /** |
|
245 | - * Load the tax class. |
|
246 | - */ |
|
247 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
248 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
249 | - } |
|
250 | - |
|
251 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
252 | - if ( !empty( $gateways ) ) { |
|
253 | - foreach ( $gateways as $gateway ) { |
|
254 | - if ( $gateway == 'manual' ) { |
|
255 | - continue; |
|
256 | - } |
|
257 | - |
|
258 | - $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
259 | - |
|
260 | - if ( file_exists( $gateway_file ) ) { |
|
261 | - require_once( $gateway_file ); |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
267 | - GetPaid_Post_Types_Admin::init(); |
|
268 | - |
|
269 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
270 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.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 | - // load the user class only on the users.php page |
|
278 | - global $pagenow; |
|
279 | - if($pagenow=='users.php'){ |
|
280 | - new WPInv_Admin_Users(); |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - // Register cli commands |
|
285 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
286 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
287 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
288 | - } |
|
289 | - |
|
290 | - // include css inliner |
|
291 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
292 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
293 | - } |
|
294 | - |
|
295 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Class autoloader |
|
300 | - * |
|
301 | - * @param string $class_name The name of the class to load. |
|
302 | - * @access public |
|
303 | - * @since 1.0.19 |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - public function autoload( $class_name ) { |
|
307 | - |
|
308 | - // Normalize the class name... |
|
309 | - $class_name = strtolower( $class_name ); |
|
310 | - |
|
311 | - // ... and make sure it is our class. |
|
312 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
313 | - return; |
|
314 | - } |
|
315 | - |
|
316 | - // Next, prepare the file name from the class. |
|
317 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
318 | - |
|
319 | - // Base path of the classes. |
|
320 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
321 | - |
|
322 | - // And an array of possible locations in order of importance. |
|
323 | - $locations = array( |
|
324 | - "$plugin_path/includes", |
|
325 | - "$plugin_path/includes/data-stores", |
|
326 | - "$plugin_path/includes/gateways", |
|
327 | - "$plugin_path/includes/api", |
|
328 | - "$plugin_path/includes/admin", |
|
329 | - "$plugin_path/includes/admin/meta-boxes", |
|
330 | - ); |
|
331 | - |
|
332 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
333 | - |
|
334 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
335 | - include trailingslashit( $location ) . $file_name; |
|
336 | - break; |
|
337 | - } |
|
338 | - |
|
339 | - } |
|
340 | - |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Inits hooks etc. |
|
345 | - */ |
|
346 | - public function init() { |
|
347 | - |
|
348 | - // Fires before getpaid inits. |
|
349 | - do_action( 'before_getpaid_init', $this ); |
|
350 | - |
|
351 | - // Load default gateways. |
|
352 | - $gateways = apply_filters( |
|
353 | - 'getpaid_default_gateways', |
|
354 | - array( |
|
355 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
356 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
357 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
358 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
359 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
360 | - ) |
|
361 | - ); |
|
362 | - |
|
363 | - foreach ( $gateways as $id => $class ) { |
|
364 | - $this->gateways[ $id ] = new $class(); |
|
365 | - } |
|
366 | - |
|
367 | - // Fires after getpaid inits. |
|
368 | - do_action( 'getpaid_init', $this ); |
|
369 | - |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Checks if this is an IPN request and processes it. |
|
374 | - */ |
|
375 | - public function maybe_process_ipn() { |
|
376 | - |
|
377 | - // Ensure that this is an IPN request. |
|
378 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
379 | - return; |
|
380 | - } |
|
381 | - |
|
382 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
383 | - |
|
384 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
385 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
386 | - exit; |
|
387 | - |
|
388 | - } |
|
389 | - |
|
390 | - public function enqueue_scripts() { |
|
391 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
392 | - |
|
393 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
394 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
395 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
396 | - |
|
397 | - // Register scripts |
|
398 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
399 | - 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' ) ); |
|
400 | - |
|
401 | - $localize = array(); |
|
402 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
403 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
404 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
405 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
406 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
407 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
408 | - $localize['decimals'] = wpinv_decimals(); |
|
409 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
410 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
411 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
412 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
413 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
414 | - |
|
415 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
416 | - |
|
417 | - wp_enqueue_script( 'jquery-blockui' ); |
|
418 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
419 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
420 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
421 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
422 | - wp_dequeue_script( 'google-maps-api' ); |
|
423 | - } |
|
424 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
425 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
426 | - } |
|
427 | - |
|
428 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
429 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
430 | - |
|
431 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
432 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
433 | - |
|
434 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
435 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
436 | - } |
|
437 | - |
|
438 | - public function wpinv_actions() { |
|
439 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
440 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
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 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
108 | + |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Define plugin constants. |
|
113 | + */ |
|
114 | + public function define_constants() { |
|
115 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
116 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
117 | + $this->version = WPINV_VERSION; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Hook into actions and filters. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + */ |
|
125 | + protected function init_hooks() { |
|
126 | + /* Internationalize the text strings used. */ |
|
127 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
128 | + |
|
129 | + // Init the plugin after WordPress inits. |
|
130 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
131 | + add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
132 | + add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
133 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ) ); |
|
134 | + |
|
135 | + if ( class_exists( 'BuddyPress' ) ) { |
|
136 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
137 | + } |
|
138 | + |
|
139 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
140 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
141 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
142 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
143 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
144 | + |
|
145 | + // Fires after registering actions. |
|
146 | + do_action( 'wpinv_actions', $this ); |
|
147 | + do_action( 'getpaid_actions', $this ); |
|
148 | + |
|
149 | + } |
|
150 | + |
|
151 | + public function plugins_loaded() { |
|
152 | + /* Internationalize the text strings used. */ |
|
153 | + $this->load_textdomain(); |
|
154 | + |
|
155 | + do_action( 'wpinv_loaded' ); |
|
156 | + |
|
157 | + // Fix oxygen page builder conflict |
|
158 | + if ( function_exists( 'ct_css_output' ) ) { |
|
159 | + wpinv_oxygen_fix_conflict(); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Load the translation of the plugin. |
|
165 | + * |
|
166 | + * @since 1.0 |
|
167 | + */ |
|
168 | + public function load_textdomain( $locale = NULL ) { |
|
169 | + if ( empty( $locale ) ) { |
|
170 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
171 | + } |
|
172 | + |
|
173 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
174 | + |
|
175 | + unload_textdomain( 'invoicing' ); |
|
176 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
177 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
178 | + |
|
179 | + /** |
|
180 | + * Define language constants. |
|
181 | + */ |
|
182 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Include required core files used in admin and on the frontend. |
|
187 | + */ |
|
188 | + public function includes() { |
|
189 | + |
|
190 | + // Start with the settings. |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
192 | + |
|
193 | + // Packages/libraries. |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
197 | + |
|
198 | + // Load functions. |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
206 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
207 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
208 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
213 | + |
|
214 | + // Register autoloader. |
|
215 | + try { |
|
216 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
217 | + } catch ( Exception $e ) { |
|
218 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
219 | + } |
|
220 | + |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
243 | + |
|
244 | + /** |
|
245 | + * Load the tax class. |
|
246 | + */ |
|
247 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
248 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
249 | + } |
|
250 | + |
|
251 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
252 | + if ( !empty( $gateways ) ) { |
|
253 | + foreach ( $gateways as $gateway ) { |
|
254 | + if ( $gateway == 'manual' ) { |
|
255 | + continue; |
|
256 | + } |
|
257 | + |
|
258 | + $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
259 | + |
|
260 | + if ( file_exists( $gateway_file ) ) { |
|
261 | + require_once( $gateway_file ); |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
267 | + GetPaid_Post_Types_Admin::init(); |
|
268 | + |
|
269 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
270 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.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 | + // load the user class only on the users.php page |
|
278 | + global $pagenow; |
|
279 | + if($pagenow=='users.php'){ |
|
280 | + new WPInv_Admin_Users(); |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + // Register cli commands |
|
285 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
286 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
287 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
288 | + } |
|
289 | + |
|
290 | + // include css inliner |
|
291 | + if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
292 | + include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
293 | + } |
|
294 | + |
|
295 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Class autoloader |
|
300 | + * |
|
301 | + * @param string $class_name The name of the class to load. |
|
302 | + * @access public |
|
303 | + * @since 1.0.19 |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + public function autoload( $class_name ) { |
|
307 | + |
|
308 | + // Normalize the class name... |
|
309 | + $class_name = strtolower( $class_name ); |
|
310 | + |
|
311 | + // ... and make sure it is our class. |
|
312 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
313 | + return; |
|
314 | + } |
|
315 | + |
|
316 | + // Next, prepare the file name from the class. |
|
317 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
318 | + |
|
319 | + // Base path of the classes. |
|
320 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
321 | + |
|
322 | + // And an array of possible locations in order of importance. |
|
323 | + $locations = array( |
|
324 | + "$plugin_path/includes", |
|
325 | + "$plugin_path/includes/data-stores", |
|
326 | + "$plugin_path/includes/gateways", |
|
327 | + "$plugin_path/includes/api", |
|
328 | + "$plugin_path/includes/admin", |
|
329 | + "$plugin_path/includes/admin/meta-boxes", |
|
330 | + ); |
|
331 | + |
|
332 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
333 | + |
|
334 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
335 | + include trailingslashit( $location ) . $file_name; |
|
336 | + break; |
|
337 | + } |
|
338 | + |
|
339 | + } |
|
340 | + |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Inits hooks etc. |
|
345 | + */ |
|
346 | + public function init() { |
|
347 | + |
|
348 | + // Fires before getpaid inits. |
|
349 | + do_action( 'before_getpaid_init', $this ); |
|
350 | + |
|
351 | + // Load default gateways. |
|
352 | + $gateways = apply_filters( |
|
353 | + 'getpaid_default_gateways', |
|
354 | + array( |
|
355 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
356 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
357 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
358 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
359 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
360 | + ) |
|
361 | + ); |
|
362 | + |
|
363 | + foreach ( $gateways as $id => $class ) { |
|
364 | + $this->gateways[ $id ] = new $class(); |
|
365 | + } |
|
366 | + |
|
367 | + // Fires after getpaid inits. |
|
368 | + do_action( 'getpaid_init', $this ); |
|
369 | + |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Checks if this is an IPN request and processes it. |
|
374 | + */ |
|
375 | + public function maybe_process_ipn() { |
|
376 | + |
|
377 | + // Ensure that this is an IPN request. |
|
378 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
379 | + return; |
|
380 | + } |
|
381 | + |
|
382 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
383 | + |
|
384 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
385 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
386 | + exit; |
|
387 | + |
|
388 | + } |
|
389 | + |
|
390 | + public function enqueue_scripts() { |
|
391 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
392 | + |
|
393 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
394 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
395 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
396 | + |
|
397 | + // Register scripts |
|
398 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
399 | + 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' ) ); |
|
400 | + |
|
401 | + $localize = array(); |
|
402 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
403 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
404 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
405 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
406 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
407 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
408 | + $localize['decimals'] = wpinv_decimals(); |
|
409 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
410 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
411 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
412 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
413 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
414 | + |
|
415 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
416 | + |
|
417 | + wp_enqueue_script( 'jquery-blockui' ); |
|
418 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
419 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
420 | + if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
421 | + if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
422 | + wp_dequeue_script( 'google-maps-api' ); |
|
423 | + } |
|
424 | + wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
425 | + wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
426 | + } |
|
427 | + |
|
428 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
429 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
430 | + |
|
431 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
432 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
433 | + |
|
434 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
435 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
436 | + } |
|
437 | + |
|
438 | + public function wpinv_actions() { |
|
439 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
440 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | 445 | * Fires an action after verifying that a user can fire them. |
446 | - * |
|
447 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
448 | - * current user owns the invoice/subscription. |
|
446 | + * |
|
447 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
448 | + * current user owns the invoice/subscription. |
|
449 | 449 | */ |
450 | 450 | public function maybe_do_authenticated_action() { |
451 | 451 | |
@@ -456,82 +456,82 @@ discard block |
||
456 | 456 | |
457 | 457 | } |
458 | 458 | |
459 | - public function pre_get_posts( $wp_query ) { |
|
460 | - 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() ) { |
|
461 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
462 | - } |
|
463 | - |
|
464 | - return $wp_query; |
|
465 | - } |
|
466 | - |
|
467 | - public function bp_invoicing_init() { |
|
468 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Register widgets |
|
473 | - * |
|
474 | - */ |
|
475 | - public function register_widgets() { |
|
476 | - $widgets = apply_filters( |
|
477 | - 'getpaid_widget_classes', |
|
478 | - array( |
|
479 | - 'WPInv_Checkout_Widget', |
|
480 | - 'WPInv_History_Widget', |
|
481 | - 'WPInv_Receipt_Widget', |
|
482 | - 'WPInv_Subscriptions_Widget', |
|
483 | - 'WPInv_Buy_Item_Widget', |
|
484 | - 'WPInv_Messages_Widget', |
|
485 | - 'WPInv_GetPaid_Widget' |
|
486 | - ) |
|
487 | - ); |
|
488 | - |
|
489 | - foreach ( $widgets as $widget ) { |
|
490 | - register_widget( $widget ); |
|
491 | - } |
|
459 | + public function pre_get_posts( $wp_query ) { |
|
460 | + 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() ) { |
|
461 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
462 | + } |
|
463 | + |
|
464 | + return $wp_query; |
|
465 | + } |
|
466 | + |
|
467 | + public function bp_invoicing_init() { |
|
468 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Register widgets |
|
473 | + * |
|
474 | + */ |
|
475 | + public function register_widgets() { |
|
476 | + $widgets = apply_filters( |
|
477 | + 'getpaid_widget_classes', |
|
478 | + array( |
|
479 | + 'WPInv_Checkout_Widget', |
|
480 | + 'WPInv_History_Widget', |
|
481 | + 'WPInv_Receipt_Widget', |
|
482 | + 'WPInv_Subscriptions_Widget', |
|
483 | + 'WPInv_Buy_Item_Widget', |
|
484 | + 'WPInv_Messages_Widget', |
|
485 | + 'WPInv_GetPaid_Widget' |
|
486 | + ) |
|
487 | + ); |
|
488 | + |
|
489 | + foreach ( $widgets as $widget ) { |
|
490 | + register_widget( $widget ); |
|
491 | + } |
|
492 | 492 | |
493 | - } |
|
493 | + } |
|
494 | 494 | |
495 | - /** |
|
496 | - * Remove our pages from yoast sitemaps. |
|
497 | - * |
|
498 | - * @since 1.0.19 |
|
499 | - * @param int[] $excluded_posts_ids |
|
500 | - */ |
|
501 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
495 | + /** |
|
496 | + * Remove our pages from yoast sitemaps. |
|
497 | + * |
|
498 | + * @since 1.0.19 |
|
499 | + * @param int[] $excluded_posts_ids |
|
500 | + */ |
|
501 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
502 | 502 | |
503 | - // Ensure that we have an array. |
|
504 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
505 | - $excluded_posts_ids = array(); |
|
506 | - } |
|
503 | + // Ensure that we have an array. |
|
504 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
505 | + $excluded_posts_ids = array(); |
|
506 | + } |
|
507 | 507 | |
508 | - // Prepare our pages. |
|
509 | - $our_pages = array(); |
|
508 | + // Prepare our pages. |
|
509 | + $our_pages = array(); |
|
510 | 510 | |
511 | - // Checkout page. |
|
512 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
511 | + // Checkout page. |
|
512 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
513 | 513 | |
514 | - // Success page. |
|
515 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
514 | + // Success page. |
|
515 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
516 | 516 | |
517 | - // Failure page. |
|
518 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
517 | + // Failure page. |
|
518 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
519 | 519 | |
520 | - // History page. |
|
521 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
520 | + // History page. |
|
521 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
522 | 522 | |
523 | - // Subscriptions page. |
|
524 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
523 | + // Subscriptions page. |
|
524 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
525 | 525 | |
526 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
526 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
527 | 527 | |
528 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
529 | - return array_unique( $excluded_posts_ids ); |
|
528 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
529 | + return array_unique( $excluded_posts_ids ); |
|
530 | 530 | |
531 | - } |
|
531 | + } |
|
532 | 532 | |
533 | - public function wp_footer() { |
|
534 | - echo ' |
|
533 | + public function wp_footer() { |
|
534 | + echo ' |
|
535 | 535 | <div class="bsui"> |
536 | 536 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
537 | 537 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -542,6 +542,6 @@ discard block |
||
542 | 542 | </div> |
543 | 543 | </div> |
544 | 544 | '; |
545 | - } |
|
545 | + } |
|
546 | 546 | |
547 | 547 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | $message = wpinv_email_style_body( $message ); |
186 | 186 | $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
187 | 187 | |
188 | - return $mailer->send( |
|
188 | + return $mailer->send( |
|
189 | 189 | $to, |
190 | 190 | $subject, |
191 | 191 | $message, |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
505 | 505 | |
506 | 506 | // Fetch invoices. |
507 | - $subscriptions = $wpdb->get_results( |
|
508 | - "SELECT parent_payment_id, product_id, expiration FROM $table |
|
507 | + $subscriptions = $wpdb->get_results( |
|
508 | + "SELECT parent_payment_id, product_id, expiration FROM $table |
|
509 | 509 | WHERE |
510 | 510 | $where |
511 | 511 | AND status IN ( 'trialling', 'active' )"); |
@@ -570,8 +570,8 @@ discard block |
||
570 | 570 | $table = $wpdb->prefix . 'getpaid_invoices'; |
571 | 571 | |
572 | 572 | // Fetch invoices. |
573 | - $invoices = $wpdb->get_col( |
|
574 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
573 | + $invoices = $wpdb->get_col( |
|
574 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
575 | 575 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
576 | 576 | WHERE |
577 | 577 | $where |
@@ -15,321 +15,321 @@ |
||
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 | - // Only send this email for invoices created via the admin page. |
|
307 | - $payment_form = $invoice->get_payment_form(); |
|
306 | + // Only send this email for invoices created via the admin page. |
|
307 | + $payment_form = $invoice->get_payment_form(); |
|
308 | 308 | |
309 | - if ( 1 != $payment_form && wpinv_get_default_payment_form() != $payment_form ) { |
|
310 | - return; |
|
311 | - } |
|
309 | + if ( 1 != $payment_form && wpinv_get_default_payment_form() != $payment_form ) { |
|
310 | + return; |
|
311 | + } |
|
312 | 312 | |
313 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
314 | - $recipient = $invoice->get_email(); |
|
313 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
314 | + $recipient = $invoice->get_email(); |
|
315 | 315 | |
316 | - $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
316 | + $this->send_email( $invoice, $email, __METHOD__, $recipient ); |
|
317 | 317 | |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * Notifies admin about new invoice notes |
|
322 | - * |
|
323 | - * @param WPInv_Invoice $invoice |
|
324 | - * @param string $note |
|
325 | - */ |
|
326 | - public function user_note( $invoice, $note ) { |
|
320 | + /** |
|
321 | + * Notifies admin about new invoice notes |
|
322 | + * |
|
323 | + * @param WPInv_Invoice $invoice |
|
324 | + * @param string $note |
|
325 | + */ |
|
326 | + public function user_note( $invoice, $note ) { |
|
327 | 327 | |
328 | - $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
329 | - $recipient = $invoice->get_email(); |
|
328 | + $email = new GetPaid_Notification_Email( __METHOD__, $invoice ); |
|
329 | + $recipient = $invoice->get_email(); |
|
330 | 330 | |
331 | - $this->send_email( $invoice, $email, __METHOD__, $recipient, array( 'customer_note' => $note ) ); |
|
331 | + $this->send_email( $invoice, $email, __METHOD__, $recipient, array( 'customer_note' => $note ) ); |
|
332 | 332 | |
333 | - } |
|
333 | + } |
|
334 | 334 | |
335 | 335 | } |