@@ -13,616 +13,616 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - |
|
29 | - // Invoice table columns. |
|
30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
32 | - |
|
33 | - // Items table columns. |
|
34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
40 | - |
|
41 | - // Payment forms columns. |
|
42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
45 | - |
|
46 | - // Discount table columns. |
|
47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
48 | - |
|
49 | - // Deleting posts. |
|
50 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
51 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Post updated messages. |
|
56 | - */ |
|
57 | - public static function post_updated_messages( $messages ) { |
|
58 | - global $post; |
|
59 | - |
|
60 | - $messages['wpi_discount'] = array( |
|
61 | - 0 => '', |
|
62 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
63 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
64 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
65 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
66 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
67 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
68 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
69 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
70 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
71 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
72 | - ); |
|
73 | - |
|
74 | - $messages['wpi_payment_form'] = array( |
|
75 | - 0 => '', |
|
76 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
77 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
78 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
79 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
80 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
81 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
83 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
84 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
85 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
86 | - ); |
|
87 | - |
|
88 | - return $messages; |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Post row actions. |
|
94 | - */ |
|
95 | - public static function post_row_actions( $actions, $post ) { |
|
96 | - |
|
97 | - $post = get_post( $post ); |
|
98 | - |
|
99 | - // We do not want to edit the default payment form. |
|
100 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
101 | - unset( $actions['trash'] ); |
|
102 | - unset( $actions['inline hide-if-no-js'] ); |
|
103 | - } |
|
104 | - |
|
105 | - return $actions; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns an array of invoice table columns. |
|
110 | - */ |
|
111 | - public static function invoice_columns( $columns ) { |
|
112 | - |
|
113 | - $columns = array( |
|
114 | - 'cb' => $columns['cb'], |
|
115 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
116 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
117 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
118 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
119 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
120 | - 'status' => __( 'Status', 'invoicing' ), |
|
121 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
122 | - ); |
|
123 | - |
|
124 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Displays invoice table columns. |
|
129 | - */ |
|
130 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
131 | - |
|
132 | - $invoice = new WPInv_Invoice( $post_id ); |
|
133 | - |
|
134 | - switch ( $column_name ) { |
|
135 | - |
|
136 | - case 'invoice_date' : |
|
137 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
138 | - $date = getpaid_format_date_value( $date_time ); |
|
139 | - echo "<span title='$date_time'>$date</span>"; |
|
140 | - break; |
|
141 | - |
|
142 | - case 'amount' : |
|
143 | - |
|
144 | - $amount = $invoice->get_total(); |
|
145 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
146 | - |
|
147 | - if ( $invoice->is_refunded() ) { |
|
148 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
149 | - echo "<del>$formated_amount</del><ins>$refunded_amount</ins>"; |
|
150 | - } else { |
|
151 | - |
|
152 | - $discount = $invoice->get_total_discount(); |
|
153 | - |
|
154 | - if ( ! empty( $discount ) ) { |
|
155 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
156 | - echo "<del>$new_amount</del><ins>$formated_amount</ins>"; |
|
157 | - } else { |
|
158 | - echo $formated_amount; |
|
159 | - } |
|
160 | - |
|
161 | - } |
|
162 | - |
|
163 | - break; |
|
164 | - |
|
165 | - case 'status' : |
|
166 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
167 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
168 | - |
|
169 | - // If it is paid, show the gateway title. |
|
170 | - if ( $invoice->is_paid() ) { |
|
171 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
172 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
173 | 19 | |
174 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
175 | - } else { |
|
176 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
177 | - } |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
178 | 22 | |
179 | - // If it is not paid, display the overdue and view status. |
|
180 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
181 | 25 | |
182 | - // Invoice view status. |
|
183 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
184 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
185 | - } else { |
|
186 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
187 | - } |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
188 | 28 | |
189 | - // Display the overview status. |
|
190 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
191 | - $due_date = $invoice->get_due_date(); |
|
192 | - $fomatted = getpaid_format_date( $due_date ); |
|
29 | + // Invoice table columns. |
|
30 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
193 | 32 | |
194 | - if ( ! empty( $fomatted ) ) { |
|
195 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
196 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
197 | - } |
|
198 | - } |
|
33 | + // Items table columns. |
|
34 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
199 | 40 | |
200 | - } |
|
41 | + // Payment forms columns. |
|
42 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
201 | 45 | |
202 | - break; |
|
46 | + // Discount table columns. |
|
47 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
203 | 48 | |
204 | - case 'recurring': |
|
49 | + // Deleting posts. |
|
50 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
51 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
52 | + } |
|
205 | 53 | |
206 | - if ( $invoice->is_recurring() ) { |
|
207 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
208 | - } else { |
|
209 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
210 | - } |
|
211 | - break; |
|
54 | + /** |
|
55 | + * Post updated messages. |
|
56 | + */ |
|
57 | + public static function post_updated_messages( $messages ) { |
|
58 | + global $post; |
|
59 | + |
|
60 | + $messages['wpi_discount'] = array( |
|
61 | + 0 => '', |
|
62 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
63 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
64 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
65 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
66 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
67 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
68 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
69 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
70 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
71 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
72 | + ); |
|
73 | + |
|
74 | + $messages['wpi_payment_form'] = array( |
|
75 | + 0 => '', |
|
76 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
77 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
78 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
79 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
80 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
81 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
83 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
84 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
85 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
86 | + ); |
|
87 | + |
|
88 | + return $messages; |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Post row actions. |
|
94 | + */ |
|
95 | + public static function post_row_actions( $actions, $post ) { |
|
96 | + |
|
97 | + $post = get_post( $post ); |
|
98 | + |
|
99 | + // We do not want to edit the default payment form. |
|
100 | + if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
101 | + unset( $actions['trash'] ); |
|
102 | + unset( $actions['inline hide-if-no-js'] ); |
|
103 | + } |
|
104 | + |
|
105 | + return $actions; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns an array of invoice table columns. |
|
110 | + */ |
|
111 | + public static function invoice_columns( $columns ) { |
|
112 | + |
|
113 | + $columns = array( |
|
114 | + 'cb' => $columns['cb'], |
|
115 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
116 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
117 | + 'invoice_date' => __( 'Date', 'invoicing' ), |
|
118 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
119 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
120 | + 'status' => __( 'Status', 'invoicing' ), |
|
121 | + 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
122 | + ); |
|
123 | + |
|
124 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Displays invoice table columns. |
|
129 | + */ |
|
130 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
131 | + |
|
132 | + $invoice = new WPInv_Invoice( $post_id ); |
|
133 | + |
|
134 | + switch ( $column_name ) { |
|
135 | + |
|
136 | + case 'invoice_date' : |
|
137 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
138 | + $date = getpaid_format_date_value( $date_time ); |
|
139 | + echo "<span title='$date_time'>$date</span>"; |
|
140 | + break; |
|
141 | + |
|
142 | + case 'amount' : |
|
143 | + |
|
144 | + $amount = $invoice->get_total(); |
|
145 | + $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
146 | + |
|
147 | + if ( $invoice->is_refunded() ) { |
|
148 | + $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
149 | + echo "<del>$formated_amount</del><ins>$refunded_amount</ins>"; |
|
150 | + } else { |
|
151 | + |
|
152 | + $discount = $invoice->get_total_discount(); |
|
153 | + |
|
154 | + if ( ! empty( $discount ) ) { |
|
155 | + $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
156 | + echo "<del>$new_amount</del><ins>$formated_amount</ins>"; |
|
157 | + } else { |
|
158 | + echo $formated_amount; |
|
159 | + } |
|
160 | + |
|
161 | + } |
|
162 | + |
|
163 | + break; |
|
164 | + |
|
165 | + case 'status' : |
|
166 | + $status = sanitize_text_field( $invoice->get_status() ); |
|
167 | + $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
168 | + |
|
169 | + // If it is paid, show the gateway title. |
|
170 | + if ( $invoice->is_paid() ) { |
|
171 | + $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
172 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
212 | 173 | |
213 | - case 'number' : |
|
174 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
175 | + } else { |
|
176 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
177 | + } |
|
214 | 178 | |
215 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
216 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
217 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
179 | + // If it is not paid, display the overdue and view status. |
|
180 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
218 | 181 | |
219 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
182 | + // Invoice view status. |
|
183 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
184 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
185 | + } else { |
|
186 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
187 | + } |
|
220 | 188 | |
221 | - break; |
|
189 | + // Display the overview status. |
|
190 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
191 | + $due_date = $invoice->get_due_date(); |
|
192 | + $fomatted = getpaid_format_date( $due_date ); |
|
222 | 193 | |
223 | - case 'customer' : |
|
194 | + if ( ! empty( $fomatted ) ) { |
|
195 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
196 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + } |
|
201 | + |
|
202 | + break; |
|
203 | + |
|
204 | + case 'recurring': |
|
205 | + |
|
206 | + if ( $invoice->is_recurring() ) { |
|
207 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
208 | + } else { |
|
209 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
210 | + } |
|
211 | + break; |
|
212 | + |
|
213 | + case 'number' : |
|
214 | + |
|
215 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
216 | + $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
217 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
218 | + |
|
219 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
220 | + |
|
221 | + break; |
|
222 | + |
|
223 | + case 'customer' : |
|
224 | 224 | |
225 | - $customer_name = $invoice->get_user_full_name(); |
|
225 | + $customer_name = $invoice->get_user_full_name(); |
|
226 | 226 | |
227 | - if ( empty( $customer_name ) ) { |
|
228 | - $customer_name = $invoice->get_email(); |
|
229 | - } |
|
227 | + if ( empty( $customer_name ) ) { |
|
228 | + $customer_name = $invoice->get_email(); |
|
229 | + } |
|
230 | 230 | |
231 | - if ( ! empty( $customer_name ) ) { |
|
232 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
233 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
234 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
235 | - } else { |
|
236 | - echo '<div>—</div>'; |
|
237 | - } |
|
231 | + if ( ! empty( $customer_name ) ) { |
|
232 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
233 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
234 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
235 | + } else { |
|
236 | + echo '<div>—</div>'; |
|
237 | + } |
|
238 | + |
|
239 | + break; |
|
240 | + |
|
241 | + case 'wpi_actions' : |
|
242 | + |
|
243 | + if ( $invoice->is_draft() ) { |
|
244 | + return; |
|
245 | + } |
|
246 | + |
|
247 | + $url = esc_url( $invoice->get_view_url() ); |
|
248 | + $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
249 | + echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
250 | + |
|
251 | + $url = esc_url( |
|
252 | + wp_nonce_url( |
|
253 | + add_query_arg( |
|
254 | + array( |
|
255 | + 'getpaid-admin-action' => 'send_invoice', |
|
256 | + 'invoice_id' => $invoice->get_id() |
|
257 | + ) |
|
258 | + ), |
|
259 | + 'getpaid-nonce', |
|
260 | + 'getpaid-nonce' |
|
261 | + ) |
|
262 | + ); |
|
263 | + |
|
264 | + $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
265 | + echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
266 | + |
|
267 | + break; |
|
268 | + } |
|
238 | 269 | |
239 | - break; |
|
270 | + } |
|
240 | 271 | |
241 | - case 'wpi_actions' : |
|
242 | - |
|
243 | - if ( $invoice->is_draft() ) { |
|
244 | - return; |
|
245 | - } |
|
246 | - |
|
247 | - $url = esc_url( $invoice->get_view_url() ); |
|
248 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
249 | - echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
272 | + /** |
|
273 | + * Returns an array of payment forms table columns. |
|
274 | + */ |
|
275 | + public static function payment_form_columns( $columns ) { |
|
250 | 276 | |
251 | - $url = esc_url( |
|
252 | - wp_nonce_url( |
|
253 | - add_query_arg( |
|
254 | - array( |
|
255 | - 'getpaid-admin-action' => 'send_invoice', |
|
256 | - 'invoice_id' => $invoice->get_id() |
|
257 | - ) |
|
258 | - ), |
|
259 | - 'getpaid-nonce', |
|
260 | - 'getpaid-nonce' |
|
261 | - ) |
|
262 | - ); |
|
277 | + $columns = array( |
|
278 | + 'cb' => $columns['cb'], |
|
279 | + 'title' => __( 'Name', 'invoicing' ), |
|
280 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
281 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
282 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
283 | + 'items' => __( 'Items', 'invoicing' ), |
|
284 | + 'date' => __( 'Date', 'invoicing' ), |
|
285 | + ); |
|
263 | 286 | |
264 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
265 | - echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
287 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
266 | 288 | |
267 | - break; |
|
268 | - } |
|
289 | + } |
|
269 | 290 | |
270 | - } |
|
291 | + /** |
|
292 | + * Displays payment form table columns. |
|
293 | + */ |
|
294 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
271 | 295 | |
272 | - /** |
|
273 | - * Returns an array of payment forms table columns. |
|
274 | - */ |
|
275 | - public static function payment_form_columns( $columns ) { |
|
296 | + // Retrieve the payment form. |
|
297 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
276 | 298 | |
277 | - $columns = array( |
|
278 | - 'cb' => $columns['cb'], |
|
279 | - 'title' => __( 'Name', 'invoicing' ), |
|
280 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
281 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
282 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
283 | - 'items' => __( 'Items', 'invoicing' ), |
|
284 | - 'date' => __( 'Date', 'invoicing' ), |
|
285 | - ); |
|
299 | + switch ( $column_name ) { |
|
286 | 300 | |
287 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
301 | + case 'earnings' : |
|
302 | + echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
303 | + break; |
|
288 | 304 | |
289 | - } |
|
305 | + case 'refunds' : |
|
306 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
307 | + break; |
|
290 | 308 | |
291 | - /** |
|
292 | - * Displays payment form table columns. |
|
293 | - */ |
|
294 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
309 | + case 'refunds' : |
|
310 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
311 | + break; |
|
295 | 312 | |
296 | - // Retrieve the payment form. |
|
297 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
313 | + case 'shortcode' : |
|
298 | 314 | |
299 | - switch ( $column_name ) { |
|
315 | + if ( $form->is_default() ) { |
|
316 | + echo '—'; |
|
317 | + } else { |
|
318 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
319 | + } |
|
300 | 320 | |
301 | - case 'earnings' : |
|
302 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
303 | - break; |
|
321 | + break; |
|
304 | 322 | |
305 | - case 'refunds' : |
|
306 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
307 | - break; |
|
323 | + case 'items' : |
|
308 | 324 | |
309 | - case 'refunds' : |
|
310 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
311 | - break; |
|
325 | + $items = $form->get_items(); |
|
312 | 326 | |
313 | - case 'shortcode' : |
|
327 | + if ( $form->is_default() || empty( $items ) ) { |
|
328 | + echo '—'; |
|
329 | + return; |
|
330 | + } |
|
314 | 331 | |
315 | - if ( $form->is_default() ) { |
|
316 | - echo '—'; |
|
317 | - } else { |
|
318 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
319 | - } |
|
332 | + $_items = array(); |
|
320 | 333 | |
321 | - break; |
|
334 | + foreach ( $items as $item ) { |
|
335 | + $url = $item->get_edit_url(); |
|
322 | 336 | |
323 | - case 'items' : |
|
337 | + if ( empty( $url ) ) { |
|
338 | + $_items[] = sanitize_text_field( $item->get_name() ); |
|
339 | + } else { |
|
340 | + $_items[] = sprintf( |
|
341 | + '<a href="%s">%s</a>', |
|
342 | + esc_url( $url ), |
|
343 | + sanitize_text_field( $item->get_name() ) |
|
344 | + ); |
|
345 | + } |
|
324 | 346 | |
325 | - $items = $form->get_items(); |
|
347 | + } |
|
326 | 348 | |
327 | - if ( $form->is_default() || empty( $items ) ) { |
|
328 | - echo '—'; |
|
329 | - return; |
|
330 | - } |
|
349 | + echo implode( '<br>', $_items ); |
|
331 | 350 | |
332 | - $_items = array(); |
|
351 | + break; |
|
333 | 352 | |
334 | - foreach ( $items as $item ) { |
|
335 | - $url = $item->get_edit_url(); |
|
353 | + } |
|
336 | 354 | |
337 | - if ( empty( $url ) ) { |
|
338 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
339 | - } else { |
|
340 | - $_items[] = sprintf( |
|
341 | - '<a href="%s">%s</a>', |
|
342 | - esc_url( $url ), |
|
343 | - sanitize_text_field( $item->get_name() ) |
|
344 | - ); |
|
345 | - } |
|
355 | + } |
|
346 | 356 | |
347 | - } |
|
357 | + /** |
|
358 | + * Filters post states. |
|
359 | + */ |
|
360 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
348 | 361 | |
349 | - echo implode( '<br>', $_items ); |
|
362 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
363 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
364 | + } |
|
365 | + |
|
366 | + return $post_states; |
|
350 | 367 | |
351 | - break; |
|
368 | + } |
|
352 | 369 | |
353 | - } |
|
370 | + /** |
|
371 | + * Returns an array of coupon table columns. |
|
372 | + */ |
|
373 | + public static function discount_columns( $columns ) { |
|
374 | + |
|
375 | + $columns = array( |
|
376 | + 'cb' => $columns['cb'], |
|
377 | + 'title' => __( 'Name', 'invoicing' ), |
|
378 | + 'code' => __( 'Code', 'invoicing' ), |
|
379 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
380 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
381 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
382 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
383 | + ); |
|
384 | + |
|
385 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
386 | + } |
|
354 | 387 | |
355 | - } |
|
388 | + /** |
|
389 | + * Filters post states. |
|
390 | + */ |
|
391 | + public static function filter_discount_state( $post_states, $post ) { |
|
356 | 392 | |
357 | - /** |
|
358 | - * Filters post states. |
|
359 | - */ |
|
360 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
393 | + if ( 'wpi_discount' == $post->post_type ) { |
|
361 | 394 | |
362 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
363 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
364 | - } |
|
365 | - |
|
366 | - return $post_states; |
|
395 | + $discount = new WPInv_Discount( $post ); |
|
367 | 396 | |
368 | - } |
|
397 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
369 | 398 | |
370 | - /** |
|
371 | - * Returns an array of coupon table columns. |
|
372 | - */ |
|
373 | - public static function discount_columns( $columns ) { |
|
399 | + if ( $status != 'publish' ) { |
|
400 | + return array( |
|
401 | + 'discount_status' => wpinv_discount_status( $status ), |
|
402 | + ); |
|
403 | + } |
|
374 | 404 | |
375 | - $columns = array( |
|
376 | - 'cb' => $columns['cb'], |
|
377 | - 'title' => __( 'Name', 'invoicing' ), |
|
378 | - 'code' => __( 'Code', 'invoicing' ), |
|
379 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
380 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
381 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
382 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
383 | - ); |
|
405 | + return array(); |
|
384 | 406 | |
385 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
386 | - } |
|
407 | + } |
|
387 | 408 | |
388 | - /** |
|
389 | - * Filters post states. |
|
390 | - */ |
|
391 | - public static function filter_discount_state( $post_states, $post ) { |
|
409 | + return $post_states; |
|
392 | 410 | |
393 | - if ( 'wpi_discount' == $post->post_type ) { |
|
411 | + } |
|
394 | 412 | |
395 | - $discount = new WPInv_Discount( $post ); |
|
413 | + /** |
|
414 | + * Returns an array of items table columns. |
|
415 | + */ |
|
416 | + public static function item_columns( $columns ) { |
|
417 | + global $wpinv_euvat; |
|
418 | + |
|
419 | + $columns = array( |
|
420 | + 'cb' => $columns['cb'], |
|
421 | + 'title' => __( 'Name', 'invoicing' ), |
|
422 | + 'price' => __( 'Price', 'invoicing' ), |
|
423 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
424 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
425 | + 'type' => __( 'Type', 'invoicing' ), |
|
426 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
427 | + ); |
|
428 | + |
|
429 | + if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
430 | + unset( $columns['vat_rule'] ); |
|
431 | + } |
|
396 | 432 | |
397 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
433 | + if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
434 | + unset( $columns['vat_class'] ); |
|
435 | + } |
|
398 | 436 | |
399 | - if ( $status != 'publish' ) { |
|
400 | - return array( |
|
401 | - 'discount_status' => wpinv_discount_status( $status ), |
|
402 | - ); |
|
403 | - } |
|
437 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
438 | + } |
|
404 | 439 | |
405 | - return array(); |
|
440 | + /** |
|
441 | + * Returns an array of sortable items table columns. |
|
442 | + */ |
|
443 | + public static function sortable_item_columns( $columns ) { |
|
444 | + |
|
445 | + return array_merge( |
|
446 | + $columns, |
|
447 | + array( |
|
448 | + 'price' => 'price', |
|
449 | + 'vat_rule' => 'vat_rule', |
|
450 | + 'vat_class' => 'vat_class', |
|
451 | + 'type' => 'type', |
|
452 | + ) |
|
453 | + ); |
|
454 | + |
|
455 | + } |
|
406 | 456 | |
407 | - } |
|
457 | + /** |
|
458 | + * Displays items table columns. |
|
459 | + */ |
|
460 | + public static function display_item_columns( $column_name, $post_id ) { |
|
461 | + global $wpinv_euvat; |
|
408 | 462 | |
409 | - return $post_states; |
|
463 | + $item = new WPInv_Item( $post_id ); |
|
410 | 464 | |
411 | - } |
|
465 | + switch ( $column_name ) { |
|
412 | 466 | |
413 | - /** |
|
414 | - * Returns an array of items table columns. |
|
415 | - */ |
|
416 | - public static function item_columns( $columns ) { |
|
417 | - global $wpinv_euvat; |
|
467 | + case 'price' : |
|
418 | 468 | |
419 | - $columns = array( |
|
420 | - 'cb' => $columns['cb'], |
|
421 | - 'title' => __( 'Name', 'invoicing' ), |
|
422 | - 'price' => __( 'Price', 'invoicing' ), |
|
423 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
424 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
425 | - 'type' => __( 'Type', 'invoicing' ), |
|
426 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
427 | - ); |
|
469 | + if ( ! $item->is_recurring() ) { |
|
470 | + echo $item->get_the_price(); |
|
471 | + break; |
|
472 | + } |
|
428 | 473 | |
429 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
430 | - unset( $columns['vat_rule'] ); |
|
431 | - } |
|
474 | + $price = wp_sprintf( |
|
475 | + __( '%s / %s', 'invoicing' ), |
|
476 | + $item->get_the_price(), |
|
477 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
478 | + ); |
|
432 | 479 | |
433 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
434 | - unset( $columns['vat_class'] ); |
|
435 | - } |
|
480 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
481 | + echo $price; |
|
482 | + break; |
|
483 | + } |
|
436 | 484 | |
437 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
438 | - } |
|
485 | + echo $item->get_the_initial_price(); |
|
439 | 486 | |
440 | - /** |
|
441 | - * Returns an array of sortable items table columns. |
|
442 | - */ |
|
443 | - public static function sortable_item_columns( $columns ) { |
|
487 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
488 | + break; |
|
444 | 489 | |
445 | - return array_merge( |
|
446 | - $columns, |
|
447 | - array( |
|
448 | - 'price' => 'price', |
|
449 | - 'vat_rule' => 'vat_rule', |
|
450 | - 'vat_class' => 'vat_class', |
|
451 | - 'type' => 'type', |
|
452 | - ) |
|
453 | - ); |
|
490 | + case 'vat_rule' : |
|
491 | + echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
492 | + break; |
|
454 | 493 | |
455 | - } |
|
494 | + case 'vat_class' : |
|
495 | + echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
496 | + break; |
|
456 | 497 | |
457 | - /** |
|
458 | - * Displays items table columns. |
|
459 | - */ |
|
460 | - public static function display_item_columns( $column_name, $post_id ) { |
|
461 | - global $wpinv_euvat; |
|
498 | + case 'shortcode' : |
|
499 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
500 | + break; |
|
462 | 501 | |
463 | - $item = new WPInv_Item( $post_id ); |
|
502 | + case 'type' : |
|
503 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
504 | + break; |
|
464 | 505 | |
465 | - switch ( $column_name ) { |
|
506 | + } |
|
466 | 507 | |
467 | - case 'price' : |
|
508 | + } |
|
468 | 509 | |
469 | - if ( ! $item->is_recurring() ) { |
|
470 | - echo $item->get_the_price(); |
|
471 | - break; |
|
472 | - } |
|
510 | + /** |
|
511 | + * Lets users filter items using taxes. |
|
512 | + */ |
|
513 | + public static function add_item_filters( $post_type ) { |
|
514 | + $wpinv_euvat = getpaid_tax(); |
|
515 | + |
|
516 | + // Abort if we're not dealing with items. |
|
517 | + if ( $post_type != 'wpi_item' ) { |
|
518 | + return; |
|
519 | + } |
|
520 | + |
|
521 | + // Filter by vat rules. |
|
522 | + if ( $wpinv_euvat->allow_vat_rules() ) { |
|
523 | + |
|
524 | + // Sanitize selected vat rule. |
|
525 | + $vat_rule = ''; |
|
526 | + $vat_rules = $wpinv_euvat->get_rules(); |
|
527 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
528 | + $vat_rule = $_GET['vat_rule']; |
|
529 | + } |
|
530 | + |
|
531 | + // Filter by VAT rule. |
|
532 | + echo wpinv_html_select( |
|
533 | + array( |
|
534 | + 'options' => array_merge( |
|
535 | + array( |
|
536 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
537 | + ), |
|
538 | + $vat_rules |
|
539 | + ), |
|
540 | + 'name' => 'vat_rule', |
|
541 | + 'id' => 'vat_rule', |
|
542 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
543 | + 'show_option_all' => false, |
|
544 | + 'show_option_none' => false, |
|
545 | + 'class' => 'gdmbx2-text-medium', |
|
546 | + ) |
|
547 | + ); |
|
548 | + |
|
549 | + // Filter by VAT class. |
|
550 | + } |
|
473 | 551 | |
474 | - $price = wp_sprintf( |
|
475 | - __( '%s / %s', 'invoicing' ), |
|
476 | - $item->get_the_price(), |
|
477 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
478 | - ); |
|
552 | + // Filter by vat class. |
|
553 | + if ( $wpinv_euvat->allow_vat_classes() ) { |
|
554 | + |
|
555 | + // Sanitize selected vat rule. |
|
556 | + $vat_class = ''; |
|
557 | + $vat_classes = $wpinv_euvat->get_all_classes(); |
|
558 | + if ( isset( $_GET['vat_class'] ) ) { |
|
559 | + $vat_class = $_GET['vat_class']; |
|
560 | + } |
|
561 | + |
|
562 | + echo wpinv_html_select( |
|
563 | + array( |
|
564 | + 'options' => array_merge( |
|
565 | + array( |
|
566 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
567 | + ), |
|
568 | + $vat_classes |
|
569 | + ), |
|
570 | + 'name' => 'vat_class', |
|
571 | + 'id' => 'vat_class', |
|
572 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
573 | + 'show_option_all' => false, |
|
574 | + 'show_option_none' => false, |
|
575 | + 'class' => 'gdmbx2-text-medium', |
|
576 | + ) |
|
577 | + ); |
|
479 | 578 | |
480 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
481 | - echo $price; |
|
482 | - break; |
|
483 | - } |
|
579 | + } |
|
484 | 580 | |
485 | - echo $item->get_the_initial_price(); |
|
581 | + // Filter by item type. |
|
582 | + $type = ''; |
|
583 | + if ( isset( $_GET['type'] ) ) { |
|
584 | + $type = $_GET['type']; |
|
585 | + } |
|
486 | 586 | |
487 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
488 | - break; |
|
587 | + echo wpinv_html_select( |
|
588 | + array( |
|
589 | + 'options' => array_merge( |
|
590 | + array( |
|
591 | + '' => __( 'All item types', 'invoicing' ) |
|
592 | + ), |
|
593 | + wpinv_get_item_types() |
|
594 | + ), |
|
595 | + 'name' => 'type', |
|
596 | + 'id' => 'type', |
|
597 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
598 | + 'show_option_all' => false, |
|
599 | + 'show_option_none' => false, |
|
600 | + 'class' => 'gdmbx2-text-medium', |
|
601 | + ) |
|
602 | + ); |
|
603 | + |
|
604 | + } |
|
489 | 605 | |
490 | - case 'vat_rule' : |
|
491 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
492 | - break; |
|
606 | + /** |
|
607 | + * Filters the item query. |
|
608 | + */ |
|
609 | + public static function filter_item_query( $query ) { |
|
493 | 610 | |
494 | - case 'vat_class' : |
|
495 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
496 | - break; |
|
611 | + // modify the query only if it admin and main query. |
|
612 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
613 | + return $query; |
|
614 | + } |
|
497 | 615 | |
498 | - case 'shortcode' : |
|
499 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
500 | - break; |
|
616 | + // we want to modify the query for our items. |
|
617 | + if ( 'wpi_item' != $query->query['post_type'] ){ |
|
618 | + return $query; |
|
619 | + } |
|
501 | 620 | |
502 | - case 'type' : |
|
503 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
504 | - break; |
|
621 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
622 | + $query->query_vars['meta_query'] = array(); |
|
623 | + } |
|
505 | 624 | |
506 | - } |
|
507 | - |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Lets users filter items using taxes. |
|
512 | - */ |
|
513 | - public static function add_item_filters( $post_type ) { |
|
514 | - $wpinv_euvat = getpaid_tax(); |
|
515 | - |
|
516 | - // Abort if we're not dealing with items. |
|
517 | - if ( $post_type != 'wpi_item' ) { |
|
518 | - return; |
|
519 | - } |
|
520 | - |
|
521 | - // Filter by vat rules. |
|
522 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
523 | - |
|
524 | - // Sanitize selected vat rule. |
|
525 | - $vat_rule = ''; |
|
526 | - $vat_rules = $wpinv_euvat->get_rules(); |
|
527 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
528 | - $vat_rule = $_GET['vat_rule']; |
|
529 | - } |
|
530 | - |
|
531 | - // Filter by VAT rule. |
|
532 | - echo wpinv_html_select( |
|
533 | - array( |
|
534 | - 'options' => array_merge( |
|
535 | - array( |
|
536 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
537 | - ), |
|
538 | - $vat_rules |
|
539 | - ), |
|
540 | - 'name' => 'vat_rule', |
|
541 | - 'id' => 'vat_rule', |
|
542 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
543 | - 'show_option_all' => false, |
|
544 | - 'show_option_none' => false, |
|
545 | - 'class' => 'gdmbx2-text-medium', |
|
546 | - ) |
|
547 | - ); |
|
548 | - |
|
549 | - // Filter by VAT class. |
|
550 | - } |
|
551 | - |
|
552 | - // Filter by vat class. |
|
553 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
554 | - |
|
555 | - // Sanitize selected vat rule. |
|
556 | - $vat_class = ''; |
|
557 | - $vat_classes = $wpinv_euvat->get_all_classes(); |
|
558 | - if ( isset( $_GET['vat_class'] ) ) { |
|
559 | - $vat_class = $_GET['vat_class']; |
|
560 | - } |
|
561 | - |
|
562 | - echo wpinv_html_select( |
|
563 | - array( |
|
564 | - 'options' => array_merge( |
|
565 | - array( |
|
566 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
567 | - ), |
|
568 | - $vat_classes |
|
569 | - ), |
|
570 | - 'name' => 'vat_class', |
|
571 | - 'id' => 'vat_class', |
|
572 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
573 | - 'show_option_all' => false, |
|
574 | - 'show_option_none' => false, |
|
575 | - 'class' => 'gdmbx2-text-medium', |
|
576 | - ) |
|
577 | - ); |
|
578 | - |
|
579 | - } |
|
580 | - |
|
581 | - // Filter by item type. |
|
582 | - $type = ''; |
|
583 | - if ( isset( $_GET['type'] ) ) { |
|
584 | - $type = $_GET['type']; |
|
585 | - } |
|
586 | - |
|
587 | - echo wpinv_html_select( |
|
588 | - array( |
|
589 | - 'options' => array_merge( |
|
590 | - array( |
|
591 | - '' => __( 'All item types', 'invoicing' ) |
|
592 | - ), |
|
593 | - wpinv_get_item_types() |
|
594 | - ), |
|
595 | - 'name' => 'type', |
|
596 | - 'id' => 'type', |
|
597 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
598 | - 'show_option_all' => false, |
|
599 | - 'show_option_none' => false, |
|
600 | - 'class' => 'gdmbx2-text-medium', |
|
601 | - ) |
|
602 | - ); |
|
603 | - |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Filters the item query. |
|
608 | - */ |
|
609 | - public static function filter_item_query( $query ) { |
|
610 | - |
|
611 | - // modify the query only if it admin and main query. |
|
612 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
613 | - return $query; |
|
614 | - } |
|
615 | - |
|
616 | - // we want to modify the query for our items. |
|
617 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
618 | - return $query; |
|
619 | - } |
|
620 | - |
|
621 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
622 | - $query->query_vars['meta_query'] = array(); |
|
623 | - } |
|
624 | - |
|
625 | - // Filter vat rule type |
|
625 | + // Filter vat rule type |
|
626 | 626 | if ( ! empty( $_GET['vat_rule'] ) ) { |
627 | 627 | $query->query_vars['meta_query'][] = array( |
628 | 628 | 'key' => '_wpinv_vat_rule', |
@@ -647,94 +647,94 @@ discard block |
||
647 | 647 | 'value' => sanitize_text_field( $_GET['type'] ), |
648 | 648 | 'compare' => '=' |
649 | 649 | ); |
650 | - } |
|
651 | - |
|
652 | - } |
|
653 | - |
|
654 | - /** |
|
655 | - * Reorders items. |
|
656 | - */ |
|
657 | - public static function reorder_items( $vars ) { |
|
658 | - global $typenow; |
|
659 | - |
|
660 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
661 | - return $vars; |
|
662 | - } |
|
663 | - |
|
664 | - // By item type. |
|
665 | - if ( 'type' == $vars['orderby'] ) { |
|
666 | - return array_merge( |
|
667 | - $vars, |
|
668 | - array( |
|
669 | - 'meta_key' => '_wpinv_type', |
|
670 | - 'orderby' => 'meta_value' |
|
671 | - ) |
|
672 | - ); |
|
673 | - } |
|
674 | - |
|
675 | - // By vat class. |
|
676 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
677 | - return array_merge( |
|
678 | - $vars, |
|
679 | - array( |
|
680 | - 'meta_key' => '_wpinv_vat_class', |
|
681 | - 'orderby' => 'meta_value' |
|
682 | - ) |
|
683 | - ); |
|
684 | - } |
|
685 | - |
|
686 | - // By vat rule. |
|
687 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
688 | - return array_merge( |
|
689 | - $vars, |
|
690 | - array( |
|
691 | - 'meta_key' => '_wpinv_vat_rule', |
|
692 | - 'orderby' => 'meta_value' |
|
693 | - ) |
|
694 | - ); |
|
695 | - } |
|
696 | - |
|
697 | - // By price. |
|
698 | - if ( 'price' == $vars['orderby'] ) { |
|
699 | - return array_merge( |
|
700 | - $vars, |
|
701 | - array( |
|
702 | - 'meta_key' => '_wpinv_price', |
|
703 | - 'orderby' => 'meta_value_num' |
|
704 | - ) |
|
705 | - ); |
|
706 | - } |
|
707 | - |
|
708 | - return $vars; |
|
709 | - |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * Fired when deleting a post. |
|
714 | - */ |
|
715 | - public static function delete_post( $post_id ) { |
|
716 | - |
|
717 | - switch ( get_post_type( $post_id ) ) { |
|
718 | - |
|
719 | - case 'wpi_item' : |
|
720 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
721 | - break; |
|
722 | - |
|
723 | - case 'wpi_payment_form' : |
|
724 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
725 | - break; |
|
726 | - |
|
727 | - case 'wpi_discount' : |
|
728 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
729 | - break; |
|
730 | - |
|
731 | - case 'wpi_invoice' : |
|
732 | - $invoice = new WPInv_Invoice( $post_id ); |
|
733 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
734 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
735 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
736 | - break; |
|
737 | - } |
|
738 | - } |
|
650 | + } |
|
651 | + |
|
652 | + } |
|
653 | + |
|
654 | + /** |
|
655 | + * Reorders items. |
|
656 | + */ |
|
657 | + public static function reorder_items( $vars ) { |
|
658 | + global $typenow; |
|
659 | + |
|
660 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
661 | + return $vars; |
|
662 | + } |
|
663 | + |
|
664 | + // By item type. |
|
665 | + if ( 'type' == $vars['orderby'] ) { |
|
666 | + return array_merge( |
|
667 | + $vars, |
|
668 | + array( |
|
669 | + 'meta_key' => '_wpinv_type', |
|
670 | + 'orderby' => 'meta_value' |
|
671 | + ) |
|
672 | + ); |
|
673 | + } |
|
674 | + |
|
675 | + // By vat class. |
|
676 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
677 | + return array_merge( |
|
678 | + $vars, |
|
679 | + array( |
|
680 | + 'meta_key' => '_wpinv_vat_class', |
|
681 | + 'orderby' => 'meta_value' |
|
682 | + ) |
|
683 | + ); |
|
684 | + } |
|
685 | + |
|
686 | + // By vat rule. |
|
687 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
688 | + return array_merge( |
|
689 | + $vars, |
|
690 | + array( |
|
691 | + 'meta_key' => '_wpinv_vat_rule', |
|
692 | + 'orderby' => 'meta_value' |
|
693 | + ) |
|
694 | + ); |
|
695 | + } |
|
696 | + |
|
697 | + // By price. |
|
698 | + if ( 'price' == $vars['orderby'] ) { |
|
699 | + return array_merge( |
|
700 | + $vars, |
|
701 | + array( |
|
702 | + 'meta_key' => '_wpinv_price', |
|
703 | + 'orderby' => 'meta_value_num' |
|
704 | + ) |
|
705 | + ); |
|
706 | + } |
|
707 | + |
|
708 | + return $vars; |
|
709 | + |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * Fired when deleting a post. |
|
714 | + */ |
|
715 | + public static function delete_post( $post_id ) { |
|
716 | + |
|
717 | + switch ( get_post_type( $post_id ) ) { |
|
718 | + |
|
719 | + case 'wpi_item' : |
|
720 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
721 | + break; |
|
722 | + |
|
723 | + case 'wpi_payment_form' : |
|
724 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
725 | + break; |
|
726 | + |
|
727 | + case 'wpi_discount' : |
|
728 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
729 | + break; |
|
730 | + |
|
731 | + case 'wpi_invoice' : |
|
732 | + $invoice = new WPInv_Invoice( $post_id ); |
|
733 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
734 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
735 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
736 | + break; |
|
737 | + } |
|
738 | + } |
|
739 | 739 | |
740 | 740 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Post types Admin Class |
@@ -21,68 +21,68 @@ discard block |
||
21 | 21 | GetPaid_Metaboxes::init(); |
22 | 22 | |
23 | 23 | // Filter the post updated messages. |
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
24 | + add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages'); |
|
25 | 25 | |
26 | 26 | // Filter post actions. |
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
27 | + add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2); |
|
28 | 28 | |
29 | 29 | // Invoice table columns. |
30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
30 | + add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100); |
|
31 | + add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2); |
|
32 | 32 | |
33 | 33 | // Items table columns. |
34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
34 | + add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100); |
|
35 | + add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20); |
|
36 | + add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2); |
|
37 | + add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100); |
|
38 | + add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100); |
|
39 | + add_action('request', array(__CLASS__, 'reorder_items'), 100); |
|
40 | 40 | |
41 | 41 | // Payment forms columns. |
42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
42 | + add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100); |
|
43 | + add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2); |
|
44 | + add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2); |
|
45 | 45 | |
46 | 46 | // Discount table columns. |
47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
47 | + add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100); |
|
48 | 48 | |
49 | 49 | // Deleting posts. |
50 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
51 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
50 | + add_action('delete_post', array(__CLASS__, 'delete_post')); |
|
51 | + add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Post updated messages. |
56 | 56 | */ |
57 | - public static function post_updated_messages( $messages ) { |
|
57 | + public static function post_updated_messages($messages) { |
|
58 | 58 | global $post; |
59 | 59 | |
60 | 60 | $messages['wpi_discount'] = array( |
61 | 61 | 0 => '', |
62 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
63 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
64 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
65 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
66 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
67 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
68 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
69 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
70 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
71 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
62 | + 1 => __('Discount updated.', 'invoicing'), |
|
63 | + 2 => __('Custom field updated.', 'invoicing'), |
|
64 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
65 | + 4 => __('Discount updated.', 'invoicing'), |
|
66 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
67 | + 6 => __('Discount updated.', 'invoicing'), |
|
68 | + 7 => __('Discount saved.', 'invoicing'), |
|
69 | + 8 => __('Discount submitted.', 'invoicing'), |
|
70 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
71 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
72 | 72 | ); |
73 | 73 | |
74 | 74 | $messages['wpi_payment_form'] = array( |
75 | 75 | 0 => '', |
76 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
77 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
78 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
79 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
80 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
81 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
83 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
84 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
85 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
76 | + 1 => __('Payment Form updated.', 'invoicing'), |
|
77 | + 2 => __('Custom field updated.', 'invoicing'), |
|
78 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
79 | + 4 => __('Payment Form updated.', 'invoicing'), |
|
80 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
81 | + 6 => __('Payment Form updated.', 'invoicing'), |
|
82 | + 7 => __('Payment Form saved.', 'invoicing'), |
|
83 | + 8 => __('Payment Form submitted.', 'invoicing'), |
|
84 | + 9 => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
85 | + 10 => __('Payment Form draft updated.', 'invoicing'), |
|
86 | 86 | ); |
87 | 87 | |
88 | 88 | return $messages; |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * Post row actions. |
94 | 94 | */ |
95 | - public static function post_row_actions( $actions, $post ) { |
|
95 | + public static function post_row_actions($actions, $post) { |
|
96 | 96 | |
97 | - $post = get_post( $post ); |
|
97 | + $post = get_post($post); |
|
98 | 98 | |
99 | 99 | // We do not want to edit the default payment form. |
100 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
101 | - unset( $actions['trash'] ); |
|
102 | - unset( $actions['inline hide-if-no-js'] ); |
|
100 | + if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) { |
|
101 | + unset($actions['trash']); |
|
102 | + unset($actions['inline hide-if-no-js']); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $actions; |
@@ -108,51 +108,51 @@ discard block |
||
108 | 108 | /** |
109 | 109 | * Returns an array of invoice table columns. |
110 | 110 | */ |
111 | - public static function invoice_columns( $columns ) { |
|
111 | + public static function invoice_columns($columns) { |
|
112 | 112 | |
113 | 113 | $columns = array( |
114 | 114 | 'cb' => $columns['cb'], |
115 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
116 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
117 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
118 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
119 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
120 | - 'status' => __( 'Status', 'invoicing' ), |
|
121 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
115 | + 'number' => __('Invoice', 'invoicing'), |
|
116 | + 'customer' => __('Customer', 'invoicing'), |
|
117 | + 'invoice_date' => __('Date', 'invoicing'), |
|
118 | + 'amount' => __('Amount', 'invoicing'), |
|
119 | + 'recurring' => __('Recurring', 'invoicing'), |
|
120 | + 'status' => __('Status', 'invoicing'), |
|
121 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
124 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * Displays invoice table columns. |
129 | 129 | */ |
130 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
130 | + public static function display_invoice_columns($column_name, $post_id) { |
|
131 | 131 | |
132 | - $invoice = new WPInv_Invoice( $post_id ); |
|
132 | + $invoice = new WPInv_Invoice($post_id); |
|
133 | 133 | |
134 | - switch ( $column_name ) { |
|
134 | + switch ($column_name) { |
|
135 | 135 | |
136 | 136 | case 'invoice_date' : |
137 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
138 | - $date = getpaid_format_date_value( $date_time ); |
|
137 | + $date_time = esc_attr($invoice->get_created_date()); |
|
138 | + $date = getpaid_format_date_value($date_time); |
|
139 | 139 | echo "<span title='$date_time'>$date</span>"; |
140 | 140 | break; |
141 | 141 | |
142 | 142 | case 'amount' : |
143 | 143 | |
144 | 144 | $amount = $invoice->get_total(); |
145 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
145 | + $formated_amount = wpinv_price(wpinv_format_amount($amount), $invoice->get_currency()); |
|
146 | 146 | |
147 | - if ( $invoice->is_refunded() ) { |
|
148 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
147 | + if ($invoice->is_refunded()) { |
|
148 | + $refunded_amount = wpinv_price(wpinv_format_amount(0), $invoice->get_currency()); |
|
149 | 149 | echo "<del>$formated_amount</del><ins>$refunded_amount</ins>"; |
150 | 150 | } else { |
151 | 151 | |
152 | 152 | $discount = $invoice->get_total_discount(); |
153 | 153 | |
154 | - if ( ! empty( $discount ) ) { |
|
155 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
154 | + if (!empty($discount)) { |
|
155 | + $new_amount = wpinv_price(wpinv_format_amount($amount + $discount), $invoice->get_currency()); |
|
156 | 156 | echo "<del>$new_amount</del><ins>$formated_amount</ins>"; |
157 | 157 | } else { |
158 | 158 | echo $formated_amount; |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | break; |
164 | 164 | |
165 | 165 | case 'status' : |
166 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
167 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
166 | + $status = sanitize_text_field($invoice->get_status()); |
|
167 | + $status_label = sanitize_text_field($invoice->get_status_nicename()); |
|
168 | 168 | |
169 | 169 | // If it is paid, show the gateway title. |
170 | - if ( $invoice->is_paid() ) { |
|
171 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
172 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
170 | + if ($invoice->is_paid()) { |
|
171 | + $gateway = sanitize_text_field($invoice->get_gateway_title()); |
|
172 | + $gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway); |
|
173 | 173 | |
174 | 174 | echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
175 | 175 | } else { |
@@ -177,22 +177,22 @@ discard block |
||
177 | 177 | } |
178 | 178 | |
179 | 179 | // If it is not paid, display the overdue and view status. |
180 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
180 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
181 | 181 | |
182 | 182 | // Invoice view status. |
183 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
184 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
183 | + if (wpinv_is_invoice_viewed($invoice->get_id())) { |
|
184 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>'; |
|
185 | 185 | } else { |
186 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
186 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>'; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | // Display the overview status. |
190 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
190 | + if (wpinv_get_option('overdue_active')) { |
|
191 | 191 | $due_date = $invoice->get_due_date(); |
192 | - $fomatted = getpaid_format_date( $due_date ); |
|
192 | + $fomatted = getpaid_format_date($due_date); |
|
193 | 193 | |
194 | - if ( ! empty( $fomatted ) ) { |
|
195 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
194 | + if (!empty($fomatted)) { |
|
195 | + $date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted); |
|
196 | 196 | echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
197 | 197 | } |
198 | 198 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | |
204 | 204 | case 'recurring': |
205 | 205 | |
206 | - if ( $invoice->is_recurring() ) { |
|
206 | + if ($invoice->is_recurring()) { |
|
207 | 207 | echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
208 | 208 | } else { |
209 | 209 | echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | |
213 | 213 | case 'number' : |
214 | 214 | |
215 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
216 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
217 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
215 | + $edit_link = esc_url(get_edit_post_link($invoice->get_id())); |
|
216 | + $invoice_number = sanitize_text_field($invoice->get_number()); |
|
217 | + $invoice_details = esc_attr__('View Invoice Details', 'invoicing'); |
|
218 | 218 | |
219 | 219 | echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
220 | 220 | |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | |
225 | 225 | $customer_name = $invoice->get_user_full_name(); |
226 | 226 | |
227 | - if ( empty( $customer_name ) ) { |
|
227 | + if (empty($customer_name)) { |
|
228 | 228 | $customer_name = $invoice->get_email(); |
229 | 229 | } |
230 | 230 | |
231 | - if ( ! empty( $customer_name ) ) { |
|
232 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
233 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
231 | + if (!empty($customer_name)) { |
|
232 | + $customer_details = esc_attr__('View Customer Details', 'invoicing'); |
|
233 | + $view_link = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php'))); |
|
234 | 234 | echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
235 | 235 | } else { |
236 | 236 | echo '<div>—</div>'; |
@@ -240,12 +240,12 @@ discard block |
||
240 | 240 | |
241 | 241 | case 'wpi_actions' : |
242 | 242 | |
243 | - if ( $invoice->is_draft() ) { |
|
243 | + if ($invoice->is_draft()) { |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | |
247 | - $url = esc_url( $invoice->get_view_url() ); |
|
248 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
247 | + $url = esc_url($invoice->get_view_url()); |
|
248 | + $print = esc_attr__('Print invoice', 'invoicing'); |
|
249 | 249 | echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
250 | 250 | |
251 | 251 | $url = esc_url( |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | ) |
262 | 262 | ); |
263 | 263 | |
264 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
264 | + $send = esc_attr__('Send invoice to customer', 'invoicing'); |
|
265 | 265 | echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
266 | 266 | |
267 | 267 | break; |
@@ -272,50 +272,50 @@ discard block |
||
272 | 272 | /** |
273 | 273 | * Returns an array of payment forms table columns. |
274 | 274 | */ |
275 | - public static function payment_form_columns( $columns ) { |
|
275 | + public static function payment_form_columns($columns) { |
|
276 | 276 | |
277 | 277 | $columns = array( |
278 | 278 | 'cb' => $columns['cb'], |
279 | - 'title' => __( 'Name', 'invoicing' ), |
|
280 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
281 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
282 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
283 | - 'items' => __( 'Items', 'invoicing' ), |
|
284 | - 'date' => __( 'Date', 'invoicing' ), |
|
279 | + 'title' => __('Name', 'invoicing'), |
|
280 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
281 | + 'earnings' => __('Revenue', 'invoicing'), |
|
282 | + 'refunds' => __('Refunded', 'invoicing'), |
|
283 | + 'items' => __('Items', 'invoicing'), |
|
284 | + 'date' => __('Date', 'invoicing'), |
|
285 | 285 | ); |
286 | 286 | |
287 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
287 | + return apply_filters('wpi_payment_form_table_columns', $columns); |
|
288 | 288 | |
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
292 | 292 | * Displays payment form table columns. |
293 | 293 | */ |
294 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
294 | + public static function display_payment_form_columns($column_name, $post_id) { |
|
295 | 295 | |
296 | 296 | // Retrieve the payment form. |
297 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
297 | + $form = new GetPaid_Payment_Form($post_id); |
|
298 | 298 | |
299 | - switch ( $column_name ) { |
|
299 | + switch ($column_name) { |
|
300 | 300 | |
301 | 301 | case 'earnings' : |
302 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
302 | + echo wpinv_price(wpinv_format_amount($form->get_earned())); |
|
303 | 303 | break; |
304 | 304 | |
305 | 305 | case 'refunds' : |
306 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
306 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
307 | 307 | break; |
308 | 308 | |
309 | 309 | case 'refunds' : |
310 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
310 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
311 | 311 | break; |
312 | 312 | |
313 | 313 | case 'shortcode' : |
314 | 314 | |
315 | - if ( $form->is_default() ) { |
|
315 | + if ($form->is_default()) { |
|
316 | 316 | echo '—'; |
317 | 317 | } else { |
318 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
318 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>'; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | break; |
@@ -324,29 +324,29 @@ discard block |
||
324 | 324 | |
325 | 325 | $items = $form->get_items(); |
326 | 326 | |
327 | - if ( $form->is_default() || empty( $items ) ) { |
|
327 | + if ($form->is_default() || empty($items)) { |
|
328 | 328 | echo '—'; |
329 | 329 | return; |
330 | 330 | } |
331 | 331 | |
332 | 332 | $_items = array(); |
333 | 333 | |
334 | - foreach ( $items as $item ) { |
|
334 | + foreach ($items as $item) { |
|
335 | 335 | $url = $item->get_edit_url(); |
336 | 336 | |
337 | - if ( empty( $url ) ) { |
|
338 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
337 | + if (empty($url)) { |
|
338 | + $_items[] = sanitize_text_field($item->get_name()); |
|
339 | 339 | } else { |
340 | 340 | $_items[] = sprintf( |
341 | 341 | '<a href="%s">%s</a>', |
342 | - esc_url( $url ), |
|
343 | - sanitize_text_field( $item->get_name() ) |
|
342 | + esc_url($url), |
|
343 | + sanitize_text_field($item->get_name()) |
|
344 | 344 | ); |
345 | 345 | } |
346 | 346 | |
347 | 347 | } |
348 | 348 | |
349 | - echo implode( '<br>', $_items ); |
|
349 | + echo implode('<br>', $_items); |
|
350 | 350 | |
351 | 351 | break; |
352 | 352 | |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | /** |
358 | 358 | * Filters post states. |
359 | 359 | */ |
360 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
360 | + public static function filter_payment_form_state($post_states, $post) { |
|
361 | 361 | |
362 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
363 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
362 | + if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) { |
|
363 | + $post_states['default_form'] = __('Default Payment Form', 'invoicing'); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | return $post_states; |
@@ -370,35 +370,35 @@ discard block |
||
370 | 370 | /** |
371 | 371 | * Returns an array of coupon table columns. |
372 | 372 | */ |
373 | - public static function discount_columns( $columns ) { |
|
373 | + public static function discount_columns($columns) { |
|
374 | 374 | |
375 | 375 | $columns = array( |
376 | 376 | 'cb' => $columns['cb'], |
377 | - 'title' => __( 'Name', 'invoicing' ), |
|
378 | - 'code' => __( 'Code', 'invoicing' ), |
|
379 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
380 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
381 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
382 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
377 | + 'title' => __('Name', 'invoicing'), |
|
378 | + 'code' => __('Code', 'invoicing'), |
|
379 | + 'amount' => __('Amount', 'invoicing'), |
|
380 | + 'usage' => __('Usage / Limit', 'invoicing'), |
|
381 | + 'start_date' => __('Start Date', 'invoicing'), |
|
382 | + 'expiry_date' => __('Expiry Date', 'invoicing'), |
|
383 | 383 | ); |
384 | 384 | |
385 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
385 | + return apply_filters('wpi_discount_table_columns', $columns); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
389 | 389 | * Filters post states. |
390 | 390 | */ |
391 | - public static function filter_discount_state( $post_states, $post ) { |
|
391 | + public static function filter_discount_state($post_states, $post) { |
|
392 | 392 | |
393 | - if ( 'wpi_discount' == $post->post_type ) { |
|
393 | + if ('wpi_discount' == $post->post_type) { |
|
394 | 394 | |
395 | - $discount = new WPInv_Discount( $post ); |
|
395 | + $discount = new WPInv_Discount($post); |
|
396 | 396 | |
397 | 397 | $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
398 | 398 | |
399 | - if ( $status != 'publish' ) { |
|
399 | + if ($status != 'publish') { |
|
400 | 400 | return array( |
401 | - 'discount_status' => wpinv_discount_status( $status ), |
|
401 | + 'discount_status' => wpinv_discount_status($status), |
|
402 | 402 | ); |
403 | 403 | } |
404 | 404 | |
@@ -413,34 +413,34 @@ discard block |
||
413 | 413 | /** |
414 | 414 | * Returns an array of items table columns. |
415 | 415 | */ |
416 | - public static function item_columns( $columns ) { |
|
416 | + public static function item_columns($columns) { |
|
417 | 417 | global $wpinv_euvat; |
418 | 418 | |
419 | 419 | $columns = array( |
420 | 420 | 'cb' => $columns['cb'], |
421 | - 'title' => __( 'Name', 'invoicing' ), |
|
422 | - 'price' => __( 'Price', 'invoicing' ), |
|
423 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
424 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
425 | - 'type' => __( 'Type', 'invoicing' ), |
|
426 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
421 | + 'title' => __('Name', 'invoicing'), |
|
422 | + 'price' => __('Price', 'invoicing'), |
|
423 | + 'vat_rule' => __('VAT rule', 'invoicing'), |
|
424 | + 'vat_class' => __('VAT class', 'invoicing'), |
|
425 | + 'type' => __('Type', 'invoicing'), |
|
426 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
427 | 427 | ); |
428 | 428 | |
429 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
430 | - unset( $columns['vat_rule'] ); |
|
429 | + if (!$wpinv_euvat->allow_vat_rules()) { |
|
430 | + unset($columns['vat_rule']); |
|
431 | 431 | } |
432 | 432 | |
433 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
434 | - unset( $columns['vat_class'] ); |
|
433 | + if (!$wpinv_euvat->allow_vat_classes()) { |
|
434 | + unset($columns['vat_class']); |
|
435 | 435 | } |
436 | 436 | |
437 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
437 | + return apply_filters('wpi_item_table_columns', $columns); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
441 | 441 | * Returns an array of sortable items table columns. |
442 | 442 | */ |
443 | - public static function sortable_item_columns( $columns ) { |
|
443 | + public static function sortable_item_columns($columns) { |
|
444 | 444 | |
445 | 445 | return array_merge( |
446 | 446 | $columns, |
@@ -457,50 +457,50 @@ discard block |
||
457 | 457 | /** |
458 | 458 | * Displays items table columns. |
459 | 459 | */ |
460 | - public static function display_item_columns( $column_name, $post_id ) { |
|
460 | + public static function display_item_columns($column_name, $post_id) { |
|
461 | 461 | global $wpinv_euvat; |
462 | 462 | |
463 | - $item = new WPInv_Item( $post_id ); |
|
463 | + $item = new WPInv_Item($post_id); |
|
464 | 464 | |
465 | - switch ( $column_name ) { |
|
465 | + switch ($column_name) { |
|
466 | 466 | |
467 | 467 | case 'price' : |
468 | 468 | |
469 | - if ( ! $item->is_recurring() ) { |
|
469 | + if (!$item->is_recurring()) { |
|
470 | 470 | echo $item->get_the_price(); |
471 | 471 | break; |
472 | 472 | } |
473 | 473 | |
474 | 474 | $price = wp_sprintf( |
475 | - __( '%s / %s', 'invoicing' ), |
|
475 | + __('%s / %s', 'invoicing'), |
|
476 | 476 | $item->get_the_price(), |
477 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
477 | + getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '') |
|
478 | 478 | ); |
479 | 479 | |
480 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
480 | + if ($item->get_the_price() == $item->get_the_initial_price()) { |
|
481 | 481 | echo $price; |
482 | 482 | break; |
483 | 483 | } |
484 | 484 | |
485 | 485 | echo $item->get_the_initial_price(); |
486 | 486 | |
487 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
487 | + echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>'; |
|
488 | 488 | break; |
489 | 489 | |
490 | 490 | case 'vat_rule' : |
491 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
491 | + echo $wpinv_euvat->item_rule_label($item->get_id()); |
|
492 | 492 | break; |
493 | 493 | |
494 | 494 | case 'vat_class' : |
495 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
495 | + echo $wpinv_euvat->item_class_label($item->get_id()); |
|
496 | 496 | break; |
497 | 497 | |
498 | 498 | case 'shortcode' : |
499 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
499 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
500 | 500 | break; |
501 | 501 | |
502 | 502 | case 'type' : |
503 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
503 | + echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
504 | 504 | break; |
505 | 505 | |
506 | 506 | } |
@@ -510,22 +510,22 @@ discard block |
||
510 | 510 | /** |
511 | 511 | * Lets users filter items using taxes. |
512 | 512 | */ |
513 | - public static function add_item_filters( $post_type ) { |
|
513 | + public static function add_item_filters($post_type) { |
|
514 | 514 | $wpinv_euvat = getpaid_tax(); |
515 | 515 | |
516 | 516 | // Abort if we're not dealing with items. |
517 | - if ( $post_type != 'wpi_item' ) { |
|
517 | + if ($post_type != 'wpi_item') { |
|
518 | 518 | return; |
519 | 519 | } |
520 | 520 | |
521 | 521 | // Filter by vat rules. |
522 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
522 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
523 | 523 | |
524 | 524 | // Sanitize selected vat rule. |
525 | 525 | $vat_rule = ''; |
526 | 526 | $vat_rules = $wpinv_euvat->get_rules(); |
527 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
528 | - $vat_rule = $_GET['vat_rule']; |
|
527 | + if (isset($_GET['vat_rule'])) { |
|
528 | + $vat_rule = $_GET['vat_rule']; |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | // Filter by VAT rule. |
@@ -533,13 +533,13 @@ discard block |
||
533 | 533 | array( |
534 | 534 | 'options' => array_merge( |
535 | 535 | array( |
536 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
536 | + '' => __('All VAT rules', 'invoicing') |
|
537 | 537 | ), |
538 | 538 | $vat_rules |
539 | 539 | ), |
540 | 540 | 'name' => 'vat_rule', |
541 | 541 | 'id' => 'vat_rule', |
542 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
542 | + 'selected' => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '', |
|
543 | 543 | 'show_option_all' => false, |
544 | 544 | 'show_option_none' => false, |
545 | 545 | 'class' => 'gdmbx2-text-medium', |
@@ -550,26 +550,26 @@ discard block |
||
550 | 550 | } |
551 | 551 | |
552 | 552 | // Filter by vat class. |
553 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
553 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
554 | 554 | |
555 | 555 | // Sanitize selected vat rule. |
556 | 556 | $vat_class = ''; |
557 | 557 | $vat_classes = $wpinv_euvat->get_all_classes(); |
558 | - if ( isset( $_GET['vat_class'] ) ) { |
|
559 | - $vat_class = $_GET['vat_class']; |
|
558 | + if (isset($_GET['vat_class'])) { |
|
559 | + $vat_class = $_GET['vat_class']; |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | echo wpinv_html_select( |
563 | 563 | array( |
564 | 564 | 'options' => array_merge( |
565 | 565 | array( |
566 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
566 | + '' => __('All VAT classes', 'invoicing') |
|
567 | 567 | ), |
568 | 568 | $vat_classes |
569 | 569 | ), |
570 | 570 | 'name' => 'vat_class', |
571 | 571 | 'id' => 'vat_class', |
572 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
572 | + 'selected' => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '', |
|
573 | 573 | 'show_option_all' => false, |
574 | 574 | 'show_option_none' => false, |
575 | 575 | 'class' => 'gdmbx2-text-medium', |
@@ -579,22 +579,22 @@ discard block |
||
579 | 579 | } |
580 | 580 | |
581 | 581 | // Filter by item type. |
582 | - $type = ''; |
|
583 | - if ( isset( $_GET['type'] ) ) { |
|
584 | - $type = $_GET['type']; |
|
582 | + $type = ''; |
|
583 | + if (isset($_GET['type'])) { |
|
584 | + $type = $_GET['type']; |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | echo wpinv_html_select( |
588 | 588 | array( |
589 | 589 | 'options' => array_merge( |
590 | 590 | array( |
591 | - '' => __( 'All item types', 'invoicing' ) |
|
591 | + '' => __('All item types', 'invoicing') |
|
592 | 592 | ), |
593 | 593 | wpinv_get_item_types() |
594 | 594 | ), |
595 | 595 | 'name' => 'type', |
596 | 596 | 'id' => 'type', |
597 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
597 | + 'selected' => in_array($type, wpinv_item_types()) ? $type : '', |
|
598 | 598 | 'show_option_all' => false, |
599 | 599 | 'show_option_none' => false, |
600 | 600 | 'class' => 'gdmbx2-text-medium', |
@@ -606,45 +606,45 @@ discard block |
||
606 | 606 | /** |
607 | 607 | * Filters the item query. |
608 | 608 | */ |
609 | - public static function filter_item_query( $query ) { |
|
609 | + public static function filter_item_query($query) { |
|
610 | 610 | |
611 | 611 | // modify the query only if it admin and main query. |
612 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
612 | + if (!(is_admin() && $query->is_main_query())) { |
|
613 | 613 | return $query; |
614 | 614 | } |
615 | 615 | |
616 | 616 | // we want to modify the query for our items. |
617 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
617 | + if ('wpi_item' != $query->query['post_type']) { |
|
618 | 618 | return $query; |
619 | 619 | } |
620 | 620 | |
621 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
621 | + if (empty($query->query_vars['meta_query'])) { |
|
622 | 622 | $query->query_vars['meta_query'] = array(); |
623 | 623 | } |
624 | 624 | |
625 | 625 | // Filter vat rule type |
626 | - if ( ! empty( $_GET['vat_rule'] ) ) { |
|
626 | + if (!empty($_GET['vat_rule'])) { |
|
627 | 627 | $query->query_vars['meta_query'][] = array( |
628 | 628 | 'key' => '_wpinv_vat_rule', |
629 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
629 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
630 | 630 | 'compare' => '=' |
631 | 631 | ); |
632 | 632 | } |
633 | 633 | |
634 | 634 | // Filter vat class |
635 | - if ( ! empty( $_GET['vat_class'] ) ) { |
|
635 | + if (!empty($_GET['vat_class'])) { |
|
636 | 636 | $query->query_vars['meta_query'][] = array( |
637 | 637 | 'key' => '_wpinv_vat_class', |
638 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
638 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
639 | 639 | 'compare' => '=' |
640 | 640 | ); |
641 | 641 | } |
642 | 642 | |
643 | 643 | // Filter item type |
644 | - if ( ! empty( $_GET['type'] ) ) { |
|
644 | + if (!empty($_GET['type'])) { |
|
645 | 645 | $query->query_vars['meta_query'][] = array( |
646 | 646 | 'key' => '_wpinv_type', |
647 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
647 | + 'value' => sanitize_text_field($_GET['type']), |
|
648 | 648 | 'compare' => '=' |
649 | 649 | ); |
650 | 650 | } |
@@ -654,15 +654,15 @@ discard block |
||
654 | 654 | /** |
655 | 655 | * Reorders items. |
656 | 656 | */ |
657 | - public static function reorder_items( $vars ) { |
|
657 | + public static function reorder_items($vars) { |
|
658 | 658 | global $typenow; |
659 | 659 | |
660 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
660 | + if ('wpi_item' !== $typenow || empty($vars['orderby'])) { |
|
661 | 661 | return $vars; |
662 | 662 | } |
663 | 663 | |
664 | 664 | // By item type. |
665 | - if ( 'type' == $vars['orderby'] ) { |
|
665 | + if ('type' == $vars['orderby']) { |
|
666 | 666 | return array_merge( |
667 | 667 | $vars, |
668 | 668 | array( |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | } |
674 | 674 | |
675 | 675 | // By vat class. |
676 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
676 | + if ('vat_class' == $vars['orderby']) { |
|
677 | 677 | return array_merge( |
678 | 678 | $vars, |
679 | 679 | array( |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | // By vat rule. |
687 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
687 | + if ('vat_rule' == $vars['orderby']) { |
|
688 | 688 | return array_merge( |
689 | 689 | $vars, |
690 | 690 | array( |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | // By price. |
698 | - if ( 'price' == $vars['orderby'] ) { |
|
698 | + if ('price' == $vars['orderby']) { |
|
699 | 699 | return array_merge( |
700 | 700 | $vars, |
701 | 701 | array( |
@@ -712,27 +712,27 @@ discard block |
||
712 | 712 | /** |
713 | 713 | * Fired when deleting a post. |
714 | 714 | */ |
715 | - public static function delete_post( $post_id ) { |
|
715 | + public static function delete_post($post_id) { |
|
716 | 716 | |
717 | - switch ( get_post_type( $post_id ) ) { |
|
717 | + switch (get_post_type($post_id)) { |
|
718 | 718 | |
719 | 719 | case 'wpi_item' : |
720 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
720 | + do_action("getpaid_before_delete_item", new WPInv_Item($post_id)); |
|
721 | 721 | break; |
722 | 722 | |
723 | 723 | case 'wpi_payment_form' : |
724 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
724 | + do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id)); |
|
725 | 725 | break; |
726 | 726 | |
727 | 727 | case 'wpi_discount' : |
728 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
728 | + do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id)); |
|
729 | 729 | break; |
730 | 730 | |
731 | 731 | case 'wpi_invoice' : |
732 | - $invoice = new WPInv_Invoice( $post_id ); |
|
733 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
734 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
735 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
732 | + $invoice = new WPInv_Invoice($post_id); |
|
733 | + do_action("getpaid_before_delete_invoice", $invoice); |
|
734 | + $invoice->get_data_store()->delete_items($invoice); |
|
735 | + $invoice->get_data_store()->delete_special_fields($invoice); |
|
736 | 736 | break; |
737 | 737 | } |
738 | 738 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if (!defined('ABSPATH')) { |
|
9 | 9 | exit; // Exit if accessed directly |
10 | 10 | } |
11 | 11 | |
@@ -19,16 +19,16 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @param WP_Post $post |
21 | 21 | */ |
22 | - public static function output( $post ) { |
|
22 | + public static function output($post) { |
|
23 | 23 | |
24 | 24 | // Fetch the invoice. |
25 | - $invoice = new WPInv_Invoice( $post ); |
|
25 | + $invoice = new WPInv_Invoice($post); |
|
26 | 26 | |
27 | 27 | // Fetch the subscription. |
28 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
28 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
29 | 29 | |
30 | 30 | echo '<div class="bsui">'; |
31 | - getpaid_admin_subscription_details_metabox( /** @scrutinizer ignore-type */$subscription ); |
|
31 | + getpaid_admin_subscription_details_metabox(/** @scrutinizer ignore-type */$subscription); |
|
32 | 32 | echo '</div>'; |
33 | 33 | |
34 | 34 | } |
@@ -38,16 +38,16 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @param WP_Post $post |
40 | 40 | */ |
41 | - public static function output_invoices( $post ) { |
|
41 | + public static function output_invoices($post) { |
|
42 | 42 | |
43 | 43 | // Fetch the invoice. |
44 | - $invoice = new WPInv_Invoice( $post ); |
|
44 | + $invoice = new WPInv_Invoice($post); |
|
45 | 45 | |
46 | 46 | // Fetch the subscription. |
47 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
47 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
48 | 48 | |
49 | 49 | echo '<div class="bsui">'; |
50 | - getpaid_admin_subscription_invoice_details_metabox( /** @scrutinizer ignore-type */$subscription ); |
|
50 | + getpaid_admin_subscription_invoice_details_metabox(/** @scrutinizer ignore-type */$subscription); |
|
51 | 51 | echo '</div>'; |
52 | 52 | |
53 | 53 | } |
@@ -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,55 +10,55 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form 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 = 'payment_form'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'payment_form'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'payment_form'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Form Data array. This is the core form data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'status' => 'draft', |
|
34 | - 'version' => '', |
|
35 | - 'date_created' => null, |
|
27 | + * Form Data array. This is the core form data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'status' => 'draft', |
|
34 | + 'version' => '', |
|
35 | + 'date_created' => null, |
|
36 | 36 | 'date_modified' => null, |
37 | 37 | 'name' => '', |
38 | 38 | 'author' => 1, |
39 | 39 | 'elements' => null, |
40 | - 'items' => null, |
|
41 | - 'earned' => 0, |
|
42 | - 'refunded' => 0, |
|
43 | - 'cancelled' => 0, |
|
44 | - 'failed' => 0, |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Stores meta in cache for future reads. |
|
49 | - * |
|
50 | - * A group must be set to to enable caching. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $cache_group = 'getpaid_forms'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | - * |
|
59 | - * @var WPInv_Invoice |
|
60 | - */ |
|
61 | - public $invoice = 0; |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Stores meta in cache for future reads. |
|
49 | + * |
|
50 | + * A group must be set to to enable caching. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $cache_group = 'getpaid_forms'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | + * |
|
59 | + * @var WPInv_Invoice |
|
60 | + */ |
|
61 | + public $invoice = 0; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | protected $post = null; |
69 | 69 | |
70 | 70 | /** |
71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | - * |
|
73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | - */ |
|
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | + * |
|
73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | + */ |
|
75 | + public function __construct( $form = 0 ) { |
|
76 | + parent::__construct( $form ); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | + $this->set_id( $form ); |
|
80 | + } elseif ( $form instanceof self ) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
83 | - $this->invoice = $form->invoice; |
|
82 | + $this->set_id( $form->get_id() ); |
|
83 | + $this->invoice = $form->invoice; |
|
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
87 | - } else { |
|
88 | - $this->set_object_read( true ); |
|
89 | - } |
|
85 | + } elseif ( ! empty( $form->ID ) ) { |
|
86 | + $this->set_id( $form->ID ); |
|
87 | + } else { |
|
88 | + $this->set_object_read( true ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
94 | + if ( $this->get_id() > 0 ) { |
|
95 | 95 | $this->post = get_post( $this->get_id() ); |
96 | - $this->data_store->read( $this ); |
|
96 | + $this->data_store->read( $this ); |
|
97 | 97 | } |
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /* |
102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,349 +114,349 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | /** |
117 | - * Get plugin version when the form was created. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * @param string $context View or edit context. |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
117 | + * Get plugin version when the form was created. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * @param string $context View or edit context. |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_version( $context = 'view' ) { |
|
124 | + return $this->get_prop( 'version', $context ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get date when the form was created. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @param string $context View or edit context. |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
128 | + * Get date when the form was created. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @param string $context View or edit context. |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_date_created( $context = 'view' ) { |
|
135 | + return $this->get_prop( 'date_created', $context ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Get GMT date when the form was created. |
|
140 | - * |
|
141 | - * @since 1.0.19 |
|
142 | - * @param string $context View or edit context. |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
139 | + * Get GMT date when the form was created. |
|
140 | + * |
|
141 | + * @since 1.0.19 |
|
142 | + * @param string $context View or edit context. |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
146 | 146 | $date = $this->get_date_created( $context ); |
147 | 147 | |
148 | 148 | if ( $date ) { |
149 | 149 | $date = get_gmt_from_date( $date ); |
150 | 150 | } |
151 | - return $date; |
|
151 | + return $date; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get date when the form was last modified. |
|
156 | - * |
|
157 | - * @since 1.0.19 |
|
158 | - * @param string $context View or edit context. |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
155 | + * Get date when the form was last modified. |
|
156 | + * |
|
157 | + * @since 1.0.19 |
|
158 | + * @param string $context View or edit context. |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_date_modified( $context = 'view' ) { |
|
162 | + return $this->get_prop( 'date_modified', $context ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * Get GMT date when the form was last modified. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @param string $context View or edit context. |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
166 | + * Get GMT date when the form was last modified. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @param string $context View or edit context. |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | 173 | $date = $this->get_date_modified( $context ); |
174 | 174 | |
175 | 175 | if ( $date ) { |
176 | 176 | $date = get_gmt_from_date( $date ); |
177 | 177 | } |
178 | - return $date; |
|
178 | + return $date; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get the form name. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
182 | + * Get the form name. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function get_name( $context = 'view' ) { |
|
189 | + return $this->get_prop( 'name', $context ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Alias of self::get_name(). |
|
194 | - * |
|
195 | - * @since 1.0.19 |
|
196 | - * @param string $context View or edit context. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
201 | - } |
|
193 | + * Alias of self::get_name(). |
|
194 | + * |
|
195 | + * @since 1.0.19 |
|
196 | + * @param string $context View or edit context. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function get_title( $context = 'view' ) { |
|
200 | + return $this->get_name( $context ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | /** |
204 | - * Get the owner of the form. |
|
205 | - * |
|
206 | - * @since 1.0.19 |
|
207 | - * @param string $context View or edit context. |
|
208 | - * @return int |
|
209 | - */ |
|
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
204 | + * Get the owner of the form. |
|
205 | + * |
|
206 | + * @since 1.0.19 |
|
207 | + * @param string $context View or edit context. |
|
208 | + * @return int |
|
209 | + */ |
|
210 | + public function get_author( $context = 'view' ) { |
|
211 | + return (int) $this->get_prop( 'author', $context ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Get the elements that make up the form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
215 | + * Get the elements that make up the form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function get_elements( $context = 'view' ) { |
|
222 | + $elements = $this->get_prop( 'elements', $context ); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Ensure that all required elements exist. |
|
229 | - $_elements = array(); |
|
230 | - foreach ( $elements as $element ) { |
|
228 | + // Ensure that all required elements exist. |
|
229 | + $_elements = array(); |
|
230 | + foreach ( $elements as $element ) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
233 | 233 | |
234 | - $_elements[] = array( |
|
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | - 'id' => 'gtscicd', |
|
237 | - 'name' => 'gtscicd', |
|
238 | - 'type' => 'gateway_select', |
|
239 | - 'premade' => true |
|
234 | + $_elements[] = array( |
|
235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | + 'id' => 'gtscicd', |
|
237 | + 'name' => 'gtscicd', |
|
238 | + 'type' => 'gateway_select', |
|
239 | + 'premade' => true |
|
240 | 240 | |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - $_elements[] = $element; |
|
245 | + $_elements[] = $element; |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | return $_elements; |
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the items sold via the form. |
|
254 | - * |
|
255 | - * @since 1.0.19 |
|
256 | - * @param string $context View or edit context. |
|
257 | - * @param string $return objects or arrays. |
|
258 | - * @return GetPaid_Form_Item[] |
|
259 | - */ |
|
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
262 | - |
|
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the items sold via the form. |
|
254 | + * |
|
255 | + * @since 1.0.19 |
|
256 | + * @param string $context View or edit context. |
|
257 | + * @param string $return objects or arrays. |
|
258 | + * @return GetPaid_Form_Item[] |
|
259 | + */ |
|
260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | + $items = $this->get_prop( 'items', $context ); |
|
262 | + |
|
263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
265 | - } |
|
265 | + } |
|
266 | + |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
266 | 269 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
270 | + foreach ( $items as $key => $value ) { |
|
269 | 271 | |
270 | - foreach ( $items as $key => $value ) { |
|
272 | + //Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
271 | 274 | |
272 | - //Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
274 | 278 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
279 | + continue; |
|
278 | 280 | |
279 | - continue; |
|
281 | + } |
|
280 | 282 | |
281 | - } |
|
283 | + // $item_id => $quantity |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
282 | 286 | |
283 | - // $item_id => $quantity |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
287 | + if ( $item->can_purchase() ) { |
|
288 | + $item->set_quantity( $value ); |
|
289 | + $prepared[] = $item; |
|
290 | + } |
|
286 | 291 | |
287 | - if ( $item->can_purchase() ) { |
|
288 | - $item->set_quantity( $value ); |
|
289 | - $prepared[] = $item; |
|
290 | - } |
|
292 | + continue; |
|
293 | + } |
|
291 | 294 | |
292 | - continue; |
|
293 | - } |
|
295 | + // $item_id => array( 'price' => 10 ) |
|
296 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
297 | + $item = new GetPaid_Form_Item( $key ); |
|
294 | 298 | |
295 | - // $item_id => array( 'price' => 10 ) |
|
296 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
297 | - $item = new GetPaid_Form_Item( $key ); |
|
299 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
300 | + $item->set_price( $value['price'] ); |
|
301 | + } |
|
298 | 302 | |
299 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
300 | - $item->set_price( $value['price'] ); |
|
301 | - } |
|
303 | + if ( $item->can_purchase() ) { |
|
304 | + $prepared[] = $item; |
|
305 | + } |
|
302 | 306 | |
303 | - if ( $item->can_purchase() ) { |
|
304 | - $prepared[] = $item; |
|
305 | - } |
|
307 | + continue; |
|
308 | + } |
|
306 | 309 | |
307 | - continue; |
|
308 | - } |
|
310 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
309 | 311 | |
310 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
312 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
311 | 313 | |
312 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
314 | + if ( ! $item->can_purchase() ) { |
|
315 | + continue; |
|
316 | + } |
|
313 | 317 | |
314 | - if ( ! $item->can_purchase() ) { |
|
315 | - continue; |
|
316 | - } |
|
318 | + // Sub-total (Cart items). |
|
319 | + if ( isset( $value['subtotal'] ) ) { |
|
320 | + $item->set_price( $value['subtotal'] ); |
|
321 | + } |
|
317 | 322 | |
318 | - // Sub-total (Cart items). |
|
319 | - if ( isset( $value['subtotal'] ) ) { |
|
320 | - $item->set_price( $value['subtotal'] ); |
|
321 | - } |
|
323 | + if ( isset( $value['quantity'] ) ) { |
|
324 | + $item->set_quantity( $value['quantity'] ); |
|
325 | + } |
|
326 | + |
|
327 | + if ( isset( $value['allow_quantities'] ) ) { |
|
328 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
329 | + } |
|
330 | + |
|
331 | + if ( isset( $value['required'] ) ) { |
|
332 | + $item->set_is_required( $value['required'] ); |
|
333 | + } |
|
334 | + |
|
335 | + if ( isset( $value['description'] ) ) { |
|
336 | + $item->set_custom_description( $value['description'] ); |
|
337 | + } |
|
338 | + |
|
339 | + $prepared[] = $item; |
|
340 | + continue; |
|
341 | + |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + if ( 'objects' == $return && 'view' == $context ) { |
|
346 | + return $prepared; |
|
347 | + } |
|
348 | + |
|
349 | + $items = array(); |
|
350 | + foreach ( $prepared as $item ) { |
|
351 | + $items[] = $item->prepare_data_for_use(); |
|
352 | + } |
|
353 | + |
|
354 | + return $items; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Get a single item belonging to the form. |
|
359 | + * |
|
360 | + * @since 1.0.19 |
|
361 | + * @param int $item_id The item id to return. |
|
362 | + * @return GetPaid_Form_Item|bool |
|
363 | + */ |
|
364 | + public function get_item( $item_id ) { |
|
365 | + |
|
366 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
367 | + return false; |
|
368 | + } |
|
369 | + |
|
370 | + foreach( $this->get_items() as $item ) { |
|
371 | + if ( $item->get_id() == (int) $item_id ) { |
|
372 | + return $item; |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + return false; |
|
377 | + |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Gets a single element. |
|
382 | + * |
|
383 | + * @since 1.0.19 |
|
384 | + * @param string $element_type The element type to return. |
|
385 | + * @return array|bool |
|
386 | + */ |
|
387 | + public function get_element_type( $element_type ) { |
|
388 | + |
|
389 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
390 | + return false; |
|
391 | + } |
|
392 | + |
|
393 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
394 | + |
|
395 | + if ( $element['type'] == $element_type ) { |
|
396 | + return $element; |
|
397 | + } |
|
398 | + |
|
399 | + } |
|
400 | + |
|
401 | + return false; |
|
402 | + |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Get the total amount earned via this form. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @param string $context View or edit context. |
|
410 | + * @return array |
|
411 | + */ |
|
412 | + public function get_earned( $context = 'view' ) { |
|
413 | + return $this->get_prop( 'earned', $context ); |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Get the total amount refunded via this form. |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + * @param string $context View or edit context. |
|
421 | + * @return array |
|
422 | + */ |
|
423 | + public function get_refunded( $context = 'view' ) { |
|
424 | + return $this->get_prop( 'refunded', $context ); |
|
425 | + } |
|
322 | 426 | |
323 | - if ( isset( $value['quantity'] ) ) { |
|
324 | - $item->set_quantity( $value['quantity'] ); |
|
325 | - } |
|
427 | + /** |
|
428 | + * Get the total amount cancelled via this form. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return array |
|
433 | + */ |
|
434 | + public function get_cancelled( $context = 'view' ) { |
|
435 | + return $this->get_prop( 'cancelled', $context ); |
|
436 | + } |
|
326 | 437 | |
327 | - if ( isset( $value['allow_quantities'] ) ) { |
|
328 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
329 | - } |
|
438 | + /** |
|
439 | + * Get the total amount failed via this form. |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return array |
|
444 | + */ |
|
445 | + public function get_failed( $context = 'view' ) { |
|
446 | + return $this->get_prop( 'failed', $context ); |
|
447 | + } |
|
330 | 448 | |
331 | - if ( isset( $value['required'] ) ) { |
|
332 | - $item->set_is_required( $value['required'] ); |
|
333 | - } |
|
334 | - |
|
335 | - if ( isset( $value['description'] ) ) { |
|
336 | - $item->set_custom_description( $value['description'] ); |
|
337 | - } |
|
338 | - |
|
339 | - $prepared[] = $item; |
|
340 | - continue; |
|
341 | - |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - if ( 'objects' == $return && 'view' == $context ) { |
|
346 | - return $prepared; |
|
347 | - } |
|
348 | - |
|
349 | - $items = array(); |
|
350 | - foreach ( $prepared as $item ) { |
|
351 | - $items[] = $item->prepare_data_for_use(); |
|
352 | - } |
|
353 | - |
|
354 | - return $items; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Get a single item belonging to the form. |
|
359 | - * |
|
360 | - * @since 1.0.19 |
|
361 | - * @param int $item_id The item id to return. |
|
362 | - * @return GetPaid_Form_Item|bool |
|
363 | - */ |
|
364 | - public function get_item( $item_id ) { |
|
365 | - |
|
366 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
367 | - return false; |
|
368 | - } |
|
369 | - |
|
370 | - foreach( $this->get_items() as $item ) { |
|
371 | - if ( $item->get_id() == (int) $item_id ) { |
|
372 | - return $item; |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - return false; |
|
377 | - |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Gets a single element. |
|
382 | - * |
|
383 | - * @since 1.0.19 |
|
384 | - * @param string $element_type The element type to return. |
|
385 | - * @return array|bool |
|
386 | - */ |
|
387 | - public function get_element_type( $element_type ) { |
|
388 | - |
|
389 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
390 | - return false; |
|
391 | - } |
|
392 | - |
|
393 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
394 | - |
|
395 | - if ( $element['type'] == $element_type ) { |
|
396 | - return $element; |
|
397 | - } |
|
398 | - |
|
399 | - } |
|
400 | - |
|
401 | - return false; |
|
402 | - |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Get the total amount earned via this form. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @param string $context View or edit context. |
|
410 | - * @return array |
|
411 | - */ |
|
412 | - public function get_earned( $context = 'view' ) { |
|
413 | - return $this->get_prop( 'earned', $context ); |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Get the total amount refunded via this form. |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - * @param string $context View or edit context. |
|
421 | - * @return array |
|
422 | - */ |
|
423 | - public function get_refunded( $context = 'view' ) { |
|
424 | - return $this->get_prop( 'refunded', $context ); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Get the total amount cancelled via this form. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return array |
|
433 | - */ |
|
434 | - public function get_cancelled( $context = 'view' ) { |
|
435 | - return $this->get_prop( 'cancelled', $context ); |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Get the total amount failed via this form. |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return array |
|
444 | - */ |
|
445 | - public function get_failed( $context = 'view' ) { |
|
446 | - return $this->get_prop( 'failed', $context ); |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * Get the currency. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - public function get_currency() { |
|
457 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
459 | - } |
|
449 | + /** |
|
450 | + * Get the currency. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + public function get_currency() { |
|
457 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
459 | + } |
|
460 | 460 | |
461 | 461 | /* |
462 | 462 | |-------------------------------------------------------------------------- |
@@ -469,22 +469,22 @@ discard block |
||
469 | 469 | */ |
470 | 470 | |
471 | 471 | /** |
472 | - * Set plugin version when the item was created. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - */ |
|
476 | - public function set_version( $value ) { |
|
477 | - $this->set_prop( 'version', $value ); |
|
472 | + * Set plugin version when the item was created. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + */ |
|
476 | + public function set_version( $value ) { |
|
477 | + $this->set_prop( 'version', $value ); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
481 | - * Set date when the item was created. |
|
482 | - * |
|
483 | - * @since 1.0.19 |
|
484 | - * @param string $value Value to set. |
|
481 | + * Set date when the item was created. |
|
482 | + * |
|
483 | + * @since 1.0.19 |
|
484 | + * @param string $value Value to set. |
|
485 | 485 | * @return bool Whether or not the date was set. |
486 | - */ |
|
487 | - public function set_date_created( $value ) { |
|
486 | + */ |
|
487 | + public function set_date_created( $value ) { |
|
488 | 488 | $date = strtotime( $value ); |
489 | 489 | |
490 | 490 | if ( $date ) { |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
500 | - * Set date when the item was last modified. |
|
501 | - * |
|
502 | - * @since 1.0.19 |
|
503 | - * @param string $value Value to set. |
|
500 | + * Set date when the item was last modified. |
|
501 | + * |
|
502 | + * @since 1.0.19 |
|
503 | + * @param string $value Value to set. |
|
504 | 504 | * @return bool Whether or not the date was set. |
505 | - */ |
|
506 | - public function set_date_modified( $value ) { |
|
505 | + */ |
|
506 | + public function set_date_modified( $value ) { |
|
507 | 507 | $date = strtotime( $value ); |
508 | 508 | |
509 | 509 | if ( $date ) { |
@@ -516,118 +516,118 @@ discard block |
||
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
519 | - * Set the item name. |
|
520 | - * |
|
521 | - * @since 1.0.19 |
|
522 | - * @param string $value New name. |
|
523 | - */ |
|
524 | - public function set_name( $value ) { |
|
525 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
526 | - } |
|
527 | - |
|
528 | - /** |
|
529 | - * Alias of self::set_name(). |
|
530 | - * |
|
531 | - * @since 1.0.19 |
|
532 | - * @param string $value New name. |
|
533 | - */ |
|
534 | - public function set_title( $value ) { |
|
535 | - $this->set_name( $value ); |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Set the owner of the item. |
|
540 | - * |
|
541 | - * @since 1.0.19 |
|
542 | - * @param int $value New author. |
|
543 | - */ |
|
544 | - public function set_author( $value ) { |
|
545 | - $this->set_prop( 'author', (int) $value ); |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Set the form elements. |
|
550 | - * |
|
551 | - * @since 1.0.19 |
|
552 | - * @param array $value Form elements. |
|
553 | - */ |
|
554 | - public function set_elements( $value ) { |
|
555 | - if ( is_array( $value ) ) { |
|
556 | - $this->set_prop( 'elements', $value ); |
|
557 | - } |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Set the form items. |
|
562 | - * |
|
563 | - * @since 1.0.19 |
|
564 | - * @param array $value Form elements. |
|
565 | - */ |
|
566 | - public function set_items( $value ) { |
|
567 | - if ( is_array( $value ) ) { |
|
568 | - $this->set_prop( 'items', $value ); |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Set the total amount earned via this form. |
|
574 | - * |
|
575 | - * @since 1.0.19 |
|
576 | - * @param float $value Amount earned. |
|
577 | - */ |
|
578 | - public function set_earned( $value ) { |
|
579 | - $value = max( (float) $value, 0 ); |
|
580 | - $this->set_prop( 'earned', $value ); |
|
581 | - } |
|
582 | - |
|
583 | - /** |
|
584 | - * Set the total amount refunded via this form. |
|
585 | - * |
|
586 | - * @since 1.0.19 |
|
587 | - * @param float $value Amount refunded. |
|
588 | - */ |
|
589 | - public function set_refunded( $value ) { |
|
590 | - $value = max( (float) $value, 0 ); |
|
591 | - $this->set_prop( 'refunded', $value ); |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * Set the total amount cancelled via this form. |
|
596 | - * |
|
597 | - * @since 1.0.19 |
|
598 | - * @param float $value Amount cancelled. |
|
599 | - */ |
|
600 | - public function set_cancelled( $value ) { |
|
601 | - $value = max( (float) $value, 0 ); |
|
602 | - $this->set_prop( 'cancelled', $value ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Set the total amount failed via this form. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param float $value Amount cancelled. |
|
610 | - */ |
|
611 | - public function set_failed( $value ) { |
|
612 | - $value = max( (float) $value, 0 ); |
|
613 | - $this->set_prop( 'failed', $value ); |
|
614 | - } |
|
519 | + * Set the item name. |
|
520 | + * |
|
521 | + * @since 1.0.19 |
|
522 | + * @param string $value New name. |
|
523 | + */ |
|
524 | + public function set_name( $value ) { |
|
525 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
526 | + } |
|
527 | + |
|
528 | + /** |
|
529 | + * Alias of self::set_name(). |
|
530 | + * |
|
531 | + * @since 1.0.19 |
|
532 | + * @param string $value New name. |
|
533 | + */ |
|
534 | + public function set_title( $value ) { |
|
535 | + $this->set_name( $value ); |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Set the owner of the item. |
|
540 | + * |
|
541 | + * @since 1.0.19 |
|
542 | + * @param int $value New author. |
|
543 | + */ |
|
544 | + public function set_author( $value ) { |
|
545 | + $this->set_prop( 'author', (int) $value ); |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Set the form elements. |
|
550 | + * |
|
551 | + * @since 1.0.19 |
|
552 | + * @param array $value Form elements. |
|
553 | + */ |
|
554 | + public function set_elements( $value ) { |
|
555 | + if ( is_array( $value ) ) { |
|
556 | + $this->set_prop( 'elements', $value ); |
|
557 | + } |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Set the form items. |
|
562 | + * |
|
563 | + * @since 1.0.19 |
|
564 | + * @param array $value Form elements. |
|
565 | + */ |
|
566 | + public function set_items( $value ) { |
|
567 | + if ( is_array( $value ) ) { |
|
568 | + $this->set_prop( 'items', $value ); |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Set the total amount earned via this form. |
|
574 | + * |
|
575 | + * @since 1.0.19 |
|
576 | + * @param float $value Amount earned. |
|
577 | + */ |
|
578 | + public function set_earned( $value ) { |
|
579 | + $value = max( (float) $value, 0 ); |
|
580 | + $this->set_prop( 'earned', $value ); |
|
581 | + } |
|
582 | + |
|
583 | + /** |
|
584 | + * Set the total amount refunded via this form. |
|
585 | + * |
|
586 | + * @since 1.0.19 |
|
587 | + * @param float $value Amount refunded. |
|
588 | + */ |
|
589 | + public function set_refunded( $value ) { |
|
590 | + $value = max( (float) $value, 0 ); |
|
591 | + $this->set_prop( 'refunded', $value ); |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Set the total amount cancelled via this form. |
|
596 | + * |
|
597 | + * @since 1.0.19 |
|
598 | + * @param float $value Amount cancelled. |
|
599 | + */ |
|
600 | + public function set_cancelled( $value ) { |
|
601 | + $value = max( (float) $value, 0 ); |
|
602 | + $this->set_prop( 'cancelled', $value ); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Set the total amount failed via this form. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param float $value Amount cancelled. |
|
610 | + */ |
|
611 | + public function set_failed( $value ) { |
|
612 | + $value = max( (float) $value, 0 ); |
|
613 | + $this->set_prop( 'failed', $value ); |
|
614 | + } |
|
615 | 615 | |
616 | 616 | /** |
617 | 617 | * Create an item. For backwards compatibilty. |
618 | 618 | * |
619 | 619 | * @deprecated |
620 | - * @return int item id |
|
620 | + * @return int item id |
|
621 | 621 | */ |
622 | 622 | public function create( $data = array() ) { |
623 | 623 | |
624 | - // Set the properties. |
|
625 | - if ( is_array( $data ) ) { |
|
626 | - $this->set_props( $data ); |
|
627 | - } |
|
624 | + // Set the properties. |
|
625 | + if ( is_array( $data ) ) { |
|
626 | + $this->set_props( $data ); |
|
627 | + } |
|
628 | 628 | |
629 | - // Save the item. |
|
630 | - return $this->save(); |
|
629 | + // Save the item. |
|
630 | + return $this->save(); |
|
631 | 631 | |
632 | 632 | } |
633 | 633 | |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | * Updates an item. For backwards compatibilty. |
636 | 636 | * |
637 | 637 | * @deprecated |
638 | - * @return int item id |
|
638 | + * @return int item id |
|
639 | 639 | */ |
640 | 640 | public function update( $data = array() ) { |
641 | 641 | return $this->create( $data ); |
@@ -651,22 +651,22 @@ discard block |
||
651 | 651 | */ |
652 | 652 | |
653 | 653 | /** |
654 | - * Checks whether this is the default payment form. |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - * @return bool |
|
658 | - */ |
|
654 | + * Checks whether this is the default payment form. |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + * @return bool |
|
658 | + */ |
|
659 | 659 | public function is_default() { |
660 | 660 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
661 | 661 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
662 | - } |
|
662 | + } |
|
663 | 663 | |
664 | 664 | /** |
665 | - * Checks whether the form is active. |
|
666 | - * |
|
667 | - * @since 1.0.19 |
|
668 | - * @return bool |
|
669 | - */ |
|
665 | + * Checks whether the form is active. |
|
666 | + * |
|
667 | + * @since 1.0.19 |
|
668 | + * @return bool |
|
669 | + */ |
|
670 | 670 | public function is_active() { |
671 | 671 | $is_active = 0 !== (int) $this->get_id(); |
672 | 672 | |
@@ -675,70 +675,70 @@ discard block |
||
675 | 675 | } |
676 | 676 | |
677 | 677 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Checks whether the form has a given item. |
|
682 | - * |
|
683 | - * @since 1.0.19 |
|
684 | - * @return bool |
|
685 | - */ |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Checks whether the form has a given item. |
|
682 | + * |
|
683 | + * @since 1.0.19 |
|
684 | + * @return bool |
|
685 | + */ |
|
686 | 686 | public function has_item( $item_id ) { |
687 | 687 | return false !== $this->get_item( $item_id ); |
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Checks whether the form has a given element. |
|
692 | - * |
|
693 | - * @since 1.0.19 |
|
694 | - * @return bool |
|
695 | - */ |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Checks whether the form has a given element. |
|
692 | + * |
|
693 | + * @since 1.0.19 |
|
694 | + * @return bool |
|
695 | + */ |
|
696 | 696 | public function has_element_type( $element_type ) { |
697 | 697 | return false !== $this->get_element_type( $element_type ); |
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Checks whether this form is recurring or not. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - * @return bool |
|
705 | - */ |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Checks whether this form is recurring or not. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + * @return bool |
|
705 | + */ |
|
706 | 706 | public function is_recurring() { |
707 | 707 | |
708 | - if ( ! empty( $this->invoice ) ) { |
|
709 | - return $this->invoice->is_recurring(); |
|
710 | - } |
|
708 | + if ( ! empty( $this->invoice ) ) { |
|
709 | + return $this->invoice->is_recurring(); |
|
710 | + } |
|
711 | 711 | |
712 | - foreach ( $this->get_items() as $item ) { |
|
712 | + foreach ( $this->get_items() as $item ) { |
|
713 | 713 | |
714 | - if ( $item->is_recurring() ) { |
|
715 | - return true; |
|
716 | - } |
|
714 | + if ( $item->is_recurring() ) { |
|
715 | + return true; |
|
716 | + } |
|
717 | 717 | |
718 | - } |
|
718 | + } |
|
719 | 719 | |
720 | 720 | return false; |
721 | - } |
|
721 | + } |
|
722 | 722 | |
723 | - /** |
|
724 | - * Retrieves the form's html. |
|
725 | - * |
|
726 | - * @since 1.0.19 |
|
727 | - */ |
|
723 | + /** |
|
724 | + * Retrieves the form's html. |
|
725 | + * |
|
726 | + * @since 1.0.19 |
|
727 | + */ |
|
728 | 728 | public function get_html() { |
729 | 729 | |
730 | - // Return the HTML. |
|
731 | - return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) ); |
|
730 | + // Return the HTML. |
|
731 | + return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) ); |
|
732 | 732 | |
733 | - } |
|
733 | + } |
|
734 | 734 | |
735 | - /** |
|
736 | - * Displays the payment form. |
|
737 | - * |
|
738 | - * @since 1.0.19 |
|
739 | - */ |
|
735 | + /** |
|
736 | + * Displays the payment form. |
|
737 | + * |
|
738 | + * @since 1.0.19 |
|
739 | + */ |
|
740 | 740 | public function display() { |
741 | - echo $this->get_html(); |
|
741 | + echo $this->get_html(); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
74 | 74 | */ |
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
75 | + public function __construct($form = 0) { |
|
76 | + parent::__construct($form); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if (is_numeric($form) && $form > 0) { |
|
79 | + $this->set_id($form); |
|
80 | + } elseif ($form instanceof self) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
82 | + $this->set_id($form->get_id()); |
|
83 | 83 | $this->invoice = $form->invoice; |
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
85 | + } elseif (!empty($form->ID)) { |
|
86 | + $this->set_id($form->ID); |
|
87 | 87 | } else { |
88 | - $this->set_object_read( true ); |
|
88 | + $this->set_object_read(true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
95 | - $this->post = get_post( $this->get_id() ); |
|
96 | - $this->data_store->read( $this ); |
|
94 | + if ($this->get_id() > 0) { |
|
95 | + $this->post = get_post($this->get_id()); |
|
96 | + $this->data_store->read($this); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $context View or edit context. |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
123 | + public function get_version($context = 'view') { |
|
124 | + return $this->get_prop('version', $context); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param string $context View or edit context. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
134 | + public function get_date_created($context = 'view') { |
|
135 | + return $this->get_prop('date_created', $context); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param string $context View or edit context. |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
146 | - $date = $this->get_date_created( $context ); |
|
145 | + public function get_date_created_gmt($context = 'view') { |
|
146 | + $date = $this->get_date_created($context); |
|
147 | 147 | |
148 | - if ( $date ) { |
|
149 | - $date = get_gmt_from_date( $date ); |
|
148 | + if ($date) { |
|
149 | + $date = get_gmt_from_date($date); |
|
150 | 150 | } |
151 | 151 | return $date; |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string $context View or edit context. |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
161 | + public function get_date_modified($context = 'view') { |
|
162 | + return $this->get_prop('date_modified', $context); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $context View or edit context. |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | - $date = $this->get_date_modified( $context ); |
|
172 | + public function get_date_modified_gmt($context = 'view') { |
|
173 | + $date = $this->get_date_modified($context); |
|
174 | 174 | |
175 | - if ( $date ) { |
|
176 | - $date = get_gmt_from_date( $date ); |
|
175 | + if ($date) { |
|
176 | + $date = get_gmt_from_date($date); |
|
177 | 177 | } |
178 | 178 | return $date; |
179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
188 | + public function get_name($context = 'view') { |
|
189 | + return $this->get_prop('name', $context); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string $context View or edit context. |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
199 | + public function get_title($context = 'view') { |
|
200 | + return $this->get_name($context); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string $context View or edit context. |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
210 | + public function get_author($context = 'view') { |
|
211 | + return (int) $this->get_prop('author', $context); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
221 | + public function get_elements($context = 'view') { |
|
222 | + $elements = $this->get_prop('elements', $context); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
224 | + if (empty($elements) || !is_array($elements)) { |
|
225 | + return wpinv_get_data('sample-payment-form'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // Ensure that all required elements exist. |
229 | 229 | $_elements = array(); |
230 | - foreach ( $elements as $element ) { |
|
230 | + foreach ($elements as $element) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
233 | 233 | |
234 | 234 | $_elements[] = array( |
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
236 | 236 | 'id' => 'gtscicd', |
237 | 237 | 'name' => 'gtscicd', |
238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param string $return objects or arrays. |
258 | 258 | * @return GetPaid_Form_Item[] |
259 | 259 | */ |
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
260 | + public function get_items($context = 'view', $return = 'objects') { |
|
261 | + $items = $this->get_prop('items', $context); |
|
262 | 262 | |
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
263 | + if (empty($items) || !is_array($items)) { |
|
264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Convert the items. |
268 | 268 | $prepared = array(); |
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ($items as $key => $value) { |
|
271 | 271 | |
272 | 272 | //Form items. |
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
273 | + if ($value instanceof GetPaid_Form_Item) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
275 | + if ($value->can_purchase()) { |
|
276 | 276 | $prepared[] = $value; |
277 | 277 | } |
278 | 278 | |
@@ -281,11 +281,11 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity |
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
284 | + if (is_numeric($key) && is_numeric($value)) { |
|
285 | + $item = new GetPaid_Form_Item($key); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
288 | - $item->set_quantity( $value ); |
|
287 | + if ($item->can_purchase()) { |
|
288 | + $item->set_quantity($value); |
|
289 | 289 | $prepared[] = $item; |
290 | 290 | } |
291 | 291 | |
@@ -293,47 +293,47 @@ discard block |
||
293 | 293 | } |
294 | 294 | |
295 | 295 | // $item_id => array( 'price' => 10 ) |
296 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
297 | - $item = new GetPaid_Form_Item( $key ); |
|
296 | + if (is_numeric($key) && is_array($value)) { |
|
297 | + $item = new GetPaid_Form_Item($key); |
|
298 | 298 | |
299 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
300 | - $item->set_price( $value['price'] ); |
|
299 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
300 | + $item->set_price($value['price']); |
|
301 | 301 | } |
302 | 302 | |
303 | - if ( $item->can_purchase() ) { |
|
303 | + if ($item->can_purchase()) { |
|
304 | 304 | $prepared[] = $item; |
305 | 305 | } |
306 | 306 | |
307 | 307 | continue; |
308 | 308 | } |
309 | 309 | |
310 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
310 | + if (is_array($value) && isset($value['id'])) { |
|
311 | 311 | |
312 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
312 | + $item = new GetPaid_Form_Item($value['id']); |
|
313 | 313 | |
314 | - if ( ! $item->can_purchase() ) { |
|
314 | + if (!$item->can_purchase()) { |
|
315 | 315 | continue; |
316 | 316 | } |
317 | 317 | |
318 | 318 | // Sub-total (Cart items). |
319 | - if ( isset( $value['subtotal'] ) ) { |
|
320 | - $item->set_price( $value['subtotal'] ); |
|
319 | + if (isset($value['subtotal'])) { |
|
320 | + $item->set_price($value['subtotal']); |
|
321 | 321 | } |
322 | 322 | |
323 | - if ( isset( $value['quantity'] ) ) { |
|
324 | - $item->set_quantity( $value['quantity'] ); |
|
323 | + if (isset($value['quantity'])) { |
|
324 | + $item->set_quantity($value['quantity']); |
|
325 | 325 | } |
326 | 326 | |
327 | - if ( isset( $value['allow_quantities'] ) ) { |
|
328 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
327 | + if (isset($value['allow_quantities'])) { |
|
328 | + $item->set_allow_quantities($value['allow_quantities']); |
|
329 | 329 | } |
330 | 330 | |
331 | - if ( isset( $value['required'] ) ) { |
|
332 | - $item->set_is_required( $value['required'] ); |
|
331 | + if (isset($value['required'])) { |
|
332 | + $item->set_is_required($value['required']); |
|
333 | 333 | } |
334 | 334 | |
335 | - if ( isset( $value['description'] ) ) { |
|
336 | - $item->set_custom_description( $value['description'] ); |
|
335 | + if (isset($value['description'])) { |
|
336 | + $item->set_custom_description($value['description']); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | $prepared[] = $item; |
@@ -342,12 +342,12 @@ discard block |
||
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
345 | - if ( 'objects' == $return && 'view' == $context ) { |
|
345 | + if ('objects' == $return && 'view' == $context) { |
|
346 | 346 | return $prepared; |
347 | 347 | } |
348 | 348 | |
349 | 349 | $items = array(); |
350 | - foreach ( $prepared as $item ) { |
|
350 | + foreach ($prepared as $item) { |
|
351 | 351 | $items[] = $item->prepare_data_for_use(); |
352 | 352 | } |
353 | 353 | |
@@ -361,14 +361,14 @@ discard block |
||
361 | 361 | * @param int $item_id The item id to return. |
362 | 362 | * @return GetPaid_Form_Item|bool |
363 | 363 | */ |
364 | - public function get_item( $item_id ) { |
|
364 | + public function get_item($item_id) { |
|
365 | 365 | |
366 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
366 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
367 | 367 | return false; |
368 | 368 | } |
369 | 369 | |
370 | - foreach( $this->get_items() as $item ) { |
|
371 | - if ( $item->get_id() == (int) $item_id ) { |
|
370 | + foreach ($this->get_items() as $item) { |
|
371 | + if ($item->get_id() == (int) $item_id) { |
|
372 | 372 | return $item; |
373 | 373 | } |
374 | 374 | } |
@@ -384,15 +384,15 @@ discard block |
||
384 | 384 | * @param string $element_type The element type to return. |
385 | 385 | * @return array|bool |
386 | 386 | */ |
387 | - public function get_element_type( $element_type ) { |
|
387 | + public function get_element_type($element_type) { |
|
388 | 388 | |
389 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
389 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
390 | 390 | return false; |
391 | 391 | } |
392 | 392 | |
393 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
393 | + foreach ($this->get_prop('elements') as $element) { |
|
394 | 394 | |
395 | - if ( $element['type'] == $element_type ) { |
|
395 | + if ($element['type'] == $element_type) { |
|
396 | 396 | return $element; |
397 | 397 | } |
398 | 398 | |
@@ -409,8 +409,8 @@ discard block |
||
409 | 409 | * @param string $context View or edit context. |
410 | 410 | * @return array |
411 | 411 | */ |
412 | - public function get_earned( $context = 'view' ) { |
|
413 | - return $this->get_prop( 'earned', $context ); |
|
412 | + public function get_earned($context = 'view') { |
|
413 | + return $this->get_prop('earned', $context); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | * @param string $context View or edit context. |
421 | 421 | * @return array |
422 | 422 | */ |
423 | - public function get_refunded( $context = 'view' ) { |
|
424 | - return $this->get_prop( 'refunded', $context ); |
|
423 | + public function get_refunded($context = 'view') { |
|
424 | + return $this->get_prop('refunded', $context); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | * @param string $context View or edit context. |
432 | 432 | * @return array |
433 | 433 | */ |
434 | - public function get_cancelled( $context = 'view' ) { |
|
435 | - return $this->get_prop( 'cancelled', $context ); |
|
434 | + public function get_cancelled($context = 'view') { |
|
435 | + return $this->get_prop('cancelled', $context); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | * @param string $context View or edit context. |
443 | 443 | * @return array |
444 | 444 | */ |
445 | - public function get_failed( $context = 'view' ) { |
|
446 | - return $this->get_prop( 'failed', $context ); |
|
445 | + public function get_failed($context = 'view') { |
|
446 | + return $this->get_prop('failed', $context); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | * @return string |
455 | 455 | */ |
456 | 456 | public function get_currency() { |
457 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
457 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /* |
@@ -473,8 +473,8 @@ discard block |
||
473 | 473 | * |
474 | 474 | * @since 1.0.19 |
475 | 475 | */ |
476 | - public function set_version( $value ) { |
|
477 | - $this->set_prop( 'version', $value ); |
|
476 | + public function set_version($value) { |
|
477 | + $this->set_prop('version', $value); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
@@ -484,11 +484,11 @@ discard block |
||
484 | 484 | * @param string $value Value to set. |
485 | 485 | * @return bool Whether or not the date was set. |
486 | 486 | */ |
487 | - public function set_date_created( $value ) { |
|
488 | - $date = strtotime( $value ); |
|
487 | + public function set_date_created($value) { |
|
488 | + $date = strtotime($value); |
|
489 | 489 | |
490 | - if ( $date ) { |
|
491 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
490 | + if ($date) { |
|
491 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
492 | 492 | return true; |
493 | 493 | } |
494 | 494 | |
@@ -503,11 +503,11 @@ discard block |
||
503 | 503 | * @param string $value Value to set. |
504 | 504 | * @return bool Whether or not the date was set. |
505 | 505 | */ |
506 | - public function set_date_modified( $value ) { |
|
507 | - $date = strtotime( $value ); |
|
506 | + public function set_date_modified($value) { |
|
507 | + $date = strtotime($value); |
|
508 | 508 | |
509 | - if ( $date ) { |
|
510 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
509 | + if ($date) { |
|
510 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
511 | 511 | return true; |
512 | 512 | } |
513 | 513 | |
@@ -521,8 +521,8 @@ discard block |
||
521 | 521 | * @since 1.0.19 |
522 | 522 | * @param string $value New name. |
523 | 523 | */ |
524 | - public function set_name( $value ) { |
|
525 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
524 | + public function set_name($value) { |
|
525 | + $this->set_prop('name', sanitize_text_field($value)); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -531,8 +531,8 @@ discard block |
||
531 | 531 | * @since 1.0.19 |
532 | 532 | * @param string $value New name. |
533 | 533 | */ |
534 | - public function set_title( $value ) { |
|
535 | - $this->set_name( $value ); |
|
534 | + public function set_title($value) { |
|
535 | + $this->set_name($value); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -541,8 +541,8 @@ discard block |
||
541 | 541 | * @since 1.0.19 |
542 | 542 | * @param int $value New author. |
543 | 543 | */ |
544 | - public function set_author( $value ) { |
|
545 | - $this->set_prop( 'author', (int) $value ); |
|
544 | + public function set_author($value) { |
|
545 | + $this->set_prop('author', (int) $value); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | * @since 1.0.19 |
552 | 552 | * @param array $value Form elements. |
553 | 553 | */ |
554 | - public function set_elements( $value ) { |
|
555 | - if ( is_array( $value ) ) { |
|
556 | - $this->set_prop( 'elements', $value ); |
|
554 | + public function set_elements($value) { |
|
555 | + if (is_array($value)) { |
|
556 | + $this->set_prop('elements', $value); |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
@@ -563,9 +563,9 @@ discard block |
||
563 | 563 | * @since 1.0.19 |
564 | 564 | * @param array $value Form elements. |
565 | 565 | */ |
566 | - public function set_items( $value ) { |
|
567 | - if ( is_array( $value ) ) { |
|
568 | - $this->set_prop( 'items', $value ); |
|
566 | + public function set_items($value) { |
|
567 | + if (is_array($value)) { |
|
568 | + $this->set_prop('items', $value); |
|
569 | 569 | } |
570 | 570 | } |
571 | 571 | |
@@ -575,9 +575,9 @@ discard block |
||
575 | 575 | * @since 1.0.19 |
576 | 576 | * @param float $value Amount earned. |
577 | 577 | */ |
578 | - public function set_earned( $value ) { |
|
579 | - $value = max( (float) $value, 0 ); |
|
580 | - $this->set_prop( 'earned', $value ); |
|
578 | + public function set_earned($value) { |
|
579 | + $value = max((float) $value, 0); |
|
580 | + $this->set_prop('earned', $value); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -586,9 +586,9 @@ discard block |
||
586 | 586 | * @since 1.0.19 |
587 | 587 | * @param float $value Amount refunded. |
588 | 588 | */ |
589 | - public function set_refunded( $value ) { |
|
590 | - $value = max( (float) $value, 0 ); |
|
591 | - $this->set_prop( 'refunded', $value ); |
|
589 | + public function set_refunded($value) { |
|
590 | + $value = max((float) $value, 0); |
|
591 | + $this->set_prop('refunded', $value); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -597,9 +597,9 @@ discard block |
||
597 | 597 | * @since 1.0.19 |
598 | 598 | * @param float $value Amount cancelled. |
599 | 599 | */ |
600 | - public function set_cancelled( $value ) { |
|
601 | - $value = max( (float) $value, 0 ); |
|
602 | - $this->set_prop( 'cancelled', $value ); |
|
600 | + public function set_cancelled($value) { |
|
601 | + $value = max((float) $value, 0); |
|
602 | + $this->set_prop('cancelled', $value); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
@@ -608,9 +608,9 @@ discard block |
||
608 | 608 | * @since 1.0.19 |
609 | 609 | * @param float $value Amount cancelled. |
610 | 610 | */ |
611 | - public function set_failed( $value ) { |
|
612 | - $value = max( (float) $value, 0 ); |
|
613 | - $this->set_prop( 'failed', $value ); |
|
611 | + public function set_failed($value) { |
|
612 | + $value = max((float) $value, 0); |
|
613 | + $this->set_prop('failed', $value); |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | /** |
@@ -619,11 +619,11 @@ discard block |
||
619 | 619 | * @deprecated |
620 | 620 | * @return int item id |
621 | 621 | */ |
622 | - public function create( $data = array() ) { |
|
622 | + public function create($data = array()) { |
|
623 | 623 | |
624 | 624 | // Set the properties. |
625 | - if ( is_array( $data ) ) { |
|
626 | - $this->set_props( $data ); |
|
625 | + if (is_array($data)) { |
|
626 | + $this->set_props($data); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | // Save the item. |
@@ -637,8 +637,8 @@ discard block |
||
637 | 637 | * @deprecated |
638 | 638 | * @return int item id |
639 | 639 | */ |
640 | - public function update( $data = array() ) { |
|
641 | - return $this->create( $data ); |
|
640 | + public function update($data = array()) { |
|
641 | + return $this->create($data); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | /* |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | */ |
659 | 659 | public function is_default() { |
660 | 660 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
661 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
661 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | /** |
@@ -670,11 +670,11 @@ discard block |
||
670 | 670 | public function is_active() { |
671 | 671 | $is_active = 0 !== (int) $this->get_id(); |
672 | 672 | |
673 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
673 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
674 | 674 | $is_active = false; |
675 | 675 | } |
676 | 676 | |
677 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
677 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
@@ -683,8 +683,8 @@ discard block |
||
683 | 683 | * @since 1.0.19 |
684 | 684 | * @return bool |
685 | 685 | */ |
686 | - public function has_item( $item_id ) { |
|
687 | - return false !== $this->get_item( $item_id ); |
|
686 | + public function has_item($item_id) { |
|
687 | + return false !== $this->get_item($item_id); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | /** |
@@ -693,8 +693,8 @@ discard block |
||
693 | 693 | * @since 1.0.19 |
694 | 694 | * @return bool |
695 | 695 | */ |
696 | - public function has_element_type( $element_type ) { |
|
697 | - return false !== $this->get_element_type( $element_type ); |
|
696 | + public function has_element_type($element_type) { |
|
697 | + return false !== $this->get_element_type($element_type); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
@@ -705,13 +705,13 @@ discard block |
||
705 | 705 | */ |
706 | 706 | public function is_recurring() { |
707 | 707 | |
708 | - if ( ! empty( $this->invoice ) ) { |
|
708 | + if (!empty($this->invoice)) { |
|
709 | 709 | return $this->invoice->is_recurring(); |
710 | 710 | } |
711 | 711 | |
712 | - foreach ( $this->get_items() as $item ) { |
|
712 | + foreach ($this->get_items() as $item) { |
|
713 | 713 | |
714 | - if ( $item->is_recurring() ) { |
|
714 | + if ($item->is_recurring()) { |
|
715 | 715 | return true; |
716 | 716 | } |
717 | 717 | |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | public function get_html() { |
729 | 729 | |
730 | 730 | // Return the HTML. |
731 | - return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) ); |
|
731 | + return wpinv_get_template_html('payment-forms/form.php', array('form' => $this)); |
|
732 | 732 | |
733 | 733 | } |
734 | 734 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | /** |
9 | 9 | * Main Subscriptions class. |
10 | 10 | * |
@@ -14,31 +14,31 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * Class constructor. |
16 | 16 | */ |
17 | - public function __construct(){ |
|
17 | + public function __construct() { |
|
18 | 18 | |
19 | 19 | // Fire gateway specific hooks when a subscription changes. |
20 | - add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 ); |
|
20 | + add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3); |
|
21 | 21 | |
22 | 22 | // De-activate a subscription whenever the invoice changes payment statuses. |
23 | - add_action( 'getpaid_invoice_status_wpi-refunded', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
24 | - add_action( 'getpaid_invoice_status_wpi-failed', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
25 | - add_action( 'getpaid_invoice_status_wpi-cancelled', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
26 | - add_action( 'getpaid_invoice_status_wpi-pending', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
23 | + add_action('getpaid_invoice_status_wpi-refunded', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
24 | + add_action('getpaid_invoice_status_wpi-failed', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
25 | + add_action('getpaid_invoice_status_wpi-cancelled', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
26 | + add_action('getpaid_invoice_status_wpi-pending', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
27 | 27 | |
28 | 28 | // Handles subscription cancelations. |
29 | - add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) ); |
|
29 | + add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription')); |
|
30 | 30 | |
31 | 31 | // Create a subscription whenever an invoice is created, (and update it when it is updated). |
32 | - add_action( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ) ); |
|
33 | - add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ) ); |
|
32 | + add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription')); |
|
33 | + add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription')); |
|
34 | 34 | |
35 | 35 | // Handles admin subscription update actions. |
36 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
37 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
38 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) ); |
|
36 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
37 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
38 | + add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription')); |
|
39 | 39 | |
40 | 40 | // Filter invoice item row actions. |
41 | - add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 ); |
|
41 | + add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | * @param WPInv_Invoice $invoice |
48 | 48 | * @return WPInv_Subscription|bool |
49 | 49 | */ |
50 | - public function get_invoice_subscription( $invoice ) { |
|
50 | + public function get_invoice_subscription($invoice) { |
|
51 | 51 | $subscription_id = $invoice->get_subscription_id(); |
52 | 52 | |
53 | 53 | // Fallback to the parent invoice if the child invoice has no subscription id. |
54 | - if ( empty( $subscription_id && $invoice->is_renewal() ) ) { |
|
54 | + if (empty($subscription_id && $invoice->is_renewal())) { |
|
55 | 55 | $subscription_id = $invoice->get_parent_payment()->get_subscription_id(); |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Fetch the subscription. |
59 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
59 | + $subscription = new WPInv_Subscription($subscription_id); |
|
60 | 60 | |
61 | 61 | // Return subscription or use a fallback for backwards compatibility. |
62 | - return $subscription->get_id() ? $subscription : wpinv_get_subscription( $invoice ); |
|
62 | + return $subscription->get_id() ? $subscription : wpinv_get_subscription($invoice); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param WPInv_Invoice $invoice |
69 | 69 | */ |
70 | - public function maybe_deactivate_invoice_subscription( $invoice ) { |
|
70 | + public function maybe_deactivate_invoice_subscription($invoice) { |
|
71 | 71 | |
72 | - $subscription = $this->get_invoice_subscription( $invoice ); |
|
72 | + $subscription = $this->get_invoice_subscription($invoice); |
|
73 | 73 | |
74 | 74 | // Abort if the subscription is missing or not active. |
75 | - if ( empty( $subscription ) || ! $subscription->is_active() ) { |
|
75 | + if (empty($subscription) || !$subscription->is_active()) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | 78 | |
79 | - $subscription->set_status( 'pending' ); |
|
79 | + $subscription->set_status('pending'); |
|
80 | 80 | $subscription->save(); |
81 | 81 | |
82 | 82 | } |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | * @param string $from |
89 | 89 | * @param string $to |
90 | 90 | */ |
91 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
91 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
92 | 92 | |
93 | 93 | $gateway = $subscription->get_gateway(); |
94 | 94 | |
95 | - if ( ! empty( $gateway ) ) { |
|
96 | - $gateway = sanitize_key( $gateway ); |
|
97 | - $from = sanitize_key( $from ); |
|
98 | - $to = sanitize_key( $to ); |
|
99 | - do_action( "getpaid_{$gateway}subscription_$to", $subscription, $from ); |
|
95 | + if (!empty($gateway)) { |
|
96 | + $gateway = sanitize_key($gateway); |
|
97 | + $from = sanitize_key($from); |
|
98 | + $to = sanitize_key($to); |
|
99 | + do_action("getpaid_{$gateway}subscription_$to", $subscription, $from); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * @deprecated |
110 | 110 | * @return mixed|string|void |
111 | 111 | */ |
112 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1 ) { |
|
113 | - return getpaid_get_subscription_period_label( $period, $frequency_count ); |
|
112 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
113 | + return getpaid_get_subscription_period_label($period, $frequency_count); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,29 +120,29 @@ discard block |
||
120 | 120 | * @since 1.0.0 |
121 | 121 | * @return void |
122 | 122 | */ |
123 | - public function user_cancel_single_subscription( $data ) { |
|
123 | + public function user_cancel_single_subscription($data) { |
|
124 | 124 | |
125 | 125 | // Ensure there is a subscription to cancel. |
126 | - if ( empty( $data['subscription'] ) ) { |
|
126 | + if (empty($data['subscription'])) { |
|
127 | 127 | return; |
128 | 128 | } |
129 | 129 | |
130 | - $subscription = new WPInv_Subscription( (int) $data['subscription'] ); |
|
130 | + $subscription = new WPInv_Subscription((int) $data['subscription']); |
|
131 | 131 | |
132 | 132 | // Ensure that it exists and that it belongs to the current user. |
133 | - if ( ! $subscription->get_id() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
134 | - wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) ); |
|
133 | + if (!$subscription->get_id() || $subscription->get_customer_id() != get_current_user_id()) { |
|
134 | + wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing')); |
|
135 | 135 | |
136 | 136 | // Can it be cancelled. |
137 | - } else if ( ! $subscription->can_cancel() ) { |
|
138 | - wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) ); |
|
137 | + } else if (!$subscription->can_cancel()) { |
|
138 | + wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing')); |
|
139 | 139 | |
140 | 140 | |
141 | 141 | // Cancel it. |
142 | 142 | } else { |
143 | 143 | |
144 | 144 | $subscription->cancel(); |
145 | - wpinv_set_error( 'cancelled', __( 'This subscription has been cancelled.', 'invoicing' ), 'info' ); |
|
145 | + wpinv_set_error('cancelled', __('This subscription has been cancelled.', 'invoicing'), 'info'); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $redirect = add_query_arg( |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | ) |
153 | 153 | ); |
154 | 154 | |
155 | - wp_safe_redirect( esc_url( $redirect ) ); |
|
155 | + wp_safe_redirect(esc_url($redirect)); |
|
156 | 156 | exit; |
157 | 157 | |
158 | 158 | } |
@@ -164,15 +164,15 @@ discard block |
||
164 | 164 | * @param WPInv_Invoice $invoice |
165 | 165 | * @since 1.0.0 |
166 | 166 | */ |
167 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
167 | + public function maybe_create_invoice_subscription($invoice) { |
|
168 | 168 | |
169 | 169 | // Abort if it is not recurring. |
170 | - if ( $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
170 | + if ($invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
174 | 174 | $subscription = new WPInv_Subscription(); |
175 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
175 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
176 | 176 | |
177 | 177 | } |
178 | 178 | |
@@ -183,31 +183,31 @@ discard block |
||
183 | 183 | * @param WPInv_Invoice $invoice |
184 | 184 | * @since 1.0.19 |
185 | 185 | */ |
186 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
186 | + public function maybe_update_invoice_subscription($invoice) { |
|
187 | 187 | |
188 | 188 | // Do not process renewals. |
189 | - if ( $invoice->is_renewal() ) { |
|
189 | + if ($invoice->is_renewal()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | 193 | // (Maybe) create a new subscription. |
194 | - if ( ! $invoice->get_subscription_id() ) { |
|
195 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
194 | + if (!$invoice->get_subscription_id()) { |
|
195 | + return $this->maybe_create_invoice_subscription($invoice); |
|
196 | 196 | } |
197 | 197 | |
198 | - $subscription = new WPInv_Subscription( $invoice->get_subscription_id() ); |
|
198 | + $subscription = new WPInv_Subscription($invoice->get_subscription_id()); |
|
199 | 199 | |
200 | 200 | // In case the subscription was deleted... |
201 | - if ( ! $subscription->get_id() ) { |
|
202 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
201 | + if (!$subscription->get_id()) { |
|
202 | + return $this->maybe_create_invoice_subscription($invoice); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | // Abort if an invoice is paid and already has a subscription. |
206 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
206 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
207 | 207 | return; |
208 | 208 | } |
209 | 209 | |
210 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
210 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
211 | 211 | |
212 | 212 | } |
213 | 213 | |
@@ -219,55 +219,55 @@ discard block |
||
219 | 219 | * @param WPInv_Invoice $invoice |
220 | 220 | * @since 1.0.19 |
221 | 221 | */ |
222 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
222 | + public function update_invoice_subscription($subscription, $invoice) { |
|
223 | 223 | |
224 | 224 | // Delete the subscription if an invoice is free or nolonger recurring. |
225 | - if ( $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
225 | + if ($invoice->is_free() || !$invoice->is_recurring()) { |
|
226 | 226 | return $subscription->delete(); |
227 | 227 | } |
228 | 228 | |
229 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
230 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
231 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
232 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
233 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
234 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
229 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
230 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
231 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
232 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
233 | + $subscription->set_date_created(current_time('mysql')); |
|
234 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
235 | 235 | |
236 | 236 | // Get the recurring item and abort if it does not exist. |
237 | - $subscription_item = $invoice->get_recurring( true ); |
|
238 | - if ( ! $subscription_item->get_id() ) { |
|
237 | + $subscription_item = $invoice->get_recurring(true); |
|
238 | + if (!$subscription_item->get_id()) { |
|
239 | 239 | $invoice->set_subscription_id(0); |
240 | 240 | $invoice->save(); |
241 | 241 | return $subscription->delete(); |
242 | 242 | } |
243 | 243 | |
244 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
245 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
246 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
247 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
244 | + $subscription->set_product_id($subscription_item->get_id()); |
|
245 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
246 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
247 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
248 | 248 | |
249 | 249 | // Calculate the next renewal date. |
250 | - $period = $subscription_item->get_recurring_period( true ); |
|
250 | + $period = $subscription_item->get_recurring_period(true); |
|
251 | 251 | $interval = $subscription_item->get_recurring_interval(); |
252 | 252 | |
253 | 253 | // If the subscription item has a trial period... |
254 | - if ( $subscription_item->has_free_trial() ) { |
|
255 | - $period = $subscription_item->get_trial_period( true ); |
|
254 | + if ($subscription_item->has_free_trial()) { |
|
255 | + $period = $subscription_item->get_trial_period(true); |
|
256 | 256 | $interval = $subscription_item->get_trial_interval(); |
257 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
258 | - $subscription->set_status( 'trialling' ); |
|
257 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
258 | + $subscription->set_status('trialling'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
262 | - if ( $invoice->has_free_trial() ) { |
|
263 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
264 | - $subscription->set_status( 'trialling' ); |
|
262 | + if ($invoice->has_free_trial()) { |
|
263 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
264 | + $subscription->set_status('trialling'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Calculate the next renewal date. |
268 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
268 | + $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created()))); |
|
269 | 269 | |
270 | - $subscription->set_next_renewal_date( $expiration ); |
|
270 | + $subscription->set_next_renewal_date($expiration); |
|
271 | 271 | return $subscription->save(); |
272 | 272 | |
273 | 273 | } |
@@ -278,21 +278,21 @@ discard block |
||
278 | 278 | * @param array $data |
279 | 279 | * @since 1.0.19 |
280 | 280 | */ |
281 | - public function admin_update_single_subscription( $args ) { |
|
281 | + public function admin_update_single_subscription($args) { |
|
282 | 282 | |
283 | 283 | // Ensure the subscription exists and that a status has been given. |
284 | - if ( empty( $args['subscription_id'] ) || empty( $args['subscription_status'] ) ) { |
|
284 | + if (empty($args['subscription_id']) || empty($args['subscription_status'])) { |
|
285 | 285 | return; |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Retrieve the subscriptions. |
289 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
289 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
290 | 290 | |
291 | - if ( $subscription->get_id() ) { |
|
291 | + if ($subscription->get_id()) { |
|
292 | 292 | |
293 | - $subscription->set_status( $args['subscription_status'] ); |
|
293 | + $subscription->set_status($args['subscription_status']); |
|
294 | 294 | $subscription->save(); |
295 | - getpaid_admin()->show_info( __( 'Your changes have been saved', 'invoicing' ) ); |
|
295 | + getpaid_admin()->show_info(__('Your changes have been saved', 'invoicing')); |
|
296 | 296 | |
297 | 297 | } |
298 | 298 | |
@@ -304,25 +304,25 @@ discard block |
||
304 | 304 | * @param array $data |
305 | 305 | * @since 1.0.19 |
306 | 306 | */ |
307 | - public function admin_renew_single_subscription( $args ) { |
|
307 | + public function admin_renew_single_subscription($args) { |
|
308 | 308 | |
309 | 309 | // Ensure the subscription exists and that a status has been given. |
310 | - if ( empty( $args['id'] ) ) { |
|
310 | + if (empty($args['id'])) { |
|
311 | 311 | return; |
312 | 312 | } |
313 | 313 | |
314 | 314 | // Retrieve the subscriptions. |
315 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
315 | + $subscription = new WPInv_Subscription($args['id']); |
|
316 | 316 | |
317 | - if ( $subscription->get_id() ) { |
|
317 | + if ($subscription->get_id()) { |
|
318 | 318 | |
319 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
319 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
320 | 320 | |
321 | - if ( $subscription->add_payment( $args ) ) { |
|
321 | + if ($subscription->add_payment($args)) { |
|
322 | 322 | $subscription->renew(); |
323 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
323 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
324 | 324 | } else { |
325 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
325 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | wp_safe_redirect( |
@@ -345,20 +345,20 @@ discard block |
||
345 | 345 | * @param array $data |
346 | 346 | * @since 1.0.19 |
347 | 347 | */ |
348 | - public function admin_delete_single_subscription( $args ) { |
|
348 | + public function admin_delete_single_subscription($args) { |
|
349 | 349 | |
350 | 350 | // Ensure the subscription exists and that a status has been given. |
351 | - if ( empty( $args['id'] ) ) { |
|
351 | + if (empty($args['id'])) { |
|
352 | 352 | return; |
353 | 353 | } |
354 | 354 | |
355 | 355 | // Retrieve the subscriptions. |
356 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
356 | + $subscription = new WPInv_Subscription($args['id']); |
|
357 | 357 | |
358 | - if ( $subscription->delete() ) { |
|
359 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
358 | + if ($subscription->delete()) { |
|
359 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
360 | 360 | } else { |
361 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
361 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | $redirected = wp_safe_redirect( |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | ) |
372 | 372 | ); |
373 | 373 | |
374 | - if ( $redirected ) { |
|
374 | + if ($redirected) { |
|
375 | 375 | exit; |
376 | 376 | } |
377 | 377 | |
@@ -384,10 +384,10 @@ discard block |
||
384 | 384 | * @param WPInv_Item $item |
385 | 385 | * @param WPInv_Invoice $invoice |
386 | 386 | */ |
387 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
387 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
388 | 388 | |
389 | 389 | // Fetch item subscription. |
390 | - $args = array( |
|
390 | + $args = array( |
|
391 | 391 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
392 | 392 | 'item_in' => $item->get_id(), |
393 | 393 | 'number' => 1, |
@@ -395,13 +395,13 @@ discard block |
||
395 | 395 | 'fields' => 'id', |
396 | 396 | ); |
397 | 397 | |
398 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
398 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
399 | 399 | $subscription = $subscription->get_results(); |
400 | 400 | |
401 | 401 | // In case we found a match... |
402 | - if ( ! empty( $subscription ) ) { |
|
403 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
404 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'getpaid-license-manager' ) . '</a>'; |
|
402 | + if (!empty($subscription)) { |
|
403 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
404 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'getpaid-license-manager') . '</a>'; |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | return $actions; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @param int the item ID to retrieve. |
15 | 15 | * @return WPInv_Item|false |
16 | 16 | */ |
17 | -function wpinv_get_item_by_id( $id ) { |
|
18 | - $item = wpinv_get_item( $id ); |
|
19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
17 | +function wpinv_get_item_by_id($id) { |
|
18 | + $item = wpinv_get_item($id); |
|
19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return WPInv_Item|false |
26 | 26 | */ |
27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
28 | 28 | |
29 | - if ( 'id' == strtolower( $field ) ) { |
|
30 | - return wpinv_get_item_by_id( $field ); |
|
29 | + if ('id' == strtolower($field)) { |
|
30 | + return wpinv_get_item_by_id($field); |
|
31 | 31 | } |
32 | 32 | |
33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
34 | - return $id ? wpinv_get_item( $id ) : false; |
|
33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
34 | + return $id ? wpinv_get_item($id) : false; |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
@@ -41,22 +41,22 @@ discard block |
||
41 | 41 | * @param int|WPInv_Item the item to retrieve. |
42 | 42 | * @return WPInv_Item|false |
43 | 43 | */ |
44 | -function wpinv_get_item( $item = 0 ) { |
|
44 | +function wpinv_get_item($item = 0) { |
|
45 | 45 | |
46 | - if ( empty( $item ) ) { |
|
46 | + if (empty($item)) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
50 | - $item = new WPInv_Item( $item ); |
|
50 | + $item = new WPInv_Item($item); |
|
51 | 51 | return $item->get_id() ? $item : false; |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | -function wpinv_get_all_items( $args = array() ) { |
|
55 | +function wpinv_get_all_items($args = array()) { |
|
56 | 56 | |
57 | - $args = wp_parse_args( $args, array( |
|
58 | - 'status' => array( 'publish' ), |
|
59 | - 'limit' => get_option( 'posts_per_page' ), |
|
57 | + $args = wp_parse_args($args, array( |
|
58 | + 'status' => array('publish'), |
|
59 | + 'limit' => get_option('posts_per_page'), |
|
60 | 60 | 'page' => 1, |
61 | 61 | 'exclude' => array(), |
62 | 62 | 'orderby' => 'date', |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | 'meta_query' => array(), |
66 | 66 | 'return' => 'objects', |
67 | 67 | 'paginate' => false, |
68 | - ) ); |
|
68 | + )); |
|
69 | 69 | |
70 | 70 | $wp_query_args = array( |
71 | 71 | 'post_type' => 'wpi_item', |
@@ -75,26 +75,26 @@ discard block |
||
75 | 75 | 'fields' => 'ids', |
76 | 76 | 'orderby' => $args['orderby'], |
77 | 77 | 'order' => $args['order'], |
78 | - 'paged' => absint( $args['page'] ), |
|
78 | + 'paged' => absint($args['page']), |
|
79 | 79 | ); |
80 | 80 | |
81 | - if ( ! empty( $args['exclude'] ) ) { |
|
82 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
81 | + if (!empty($args['exclude'])) { |
|
82 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
83 | 83 | } |
84 | 84 | |
85 | - if ( ! $args['paginate' ] ) { |
|
85 | + if (!$args['paginate']) { |
|
86 | 86 | $wp_query_args['no_found_rows'] = true; |
87 | 87 | } |
88 | 88 | |
89 | - if ( ! empty( $args['search'] ) ) { |
|
89 | + if (!empty($args['search'])) { |
|
90 | 90 | $wp_query_args['s'] = $args['search']; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
94 | - $types = wpinv_parse_list( $args['type'] ); |
|
93 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
94 | + $types = wpinv_parse_list($args['type']); |
|
95 | 95 | $wp_query_args['meta_query'][] = array( |
96 | 96 | 'key' => '_wpinv_type', |
97 | - 'value' => implode( ',', $types ), |
|
97 | + 'value' => implode(',', $types), |
|
98 | 98 | 'compare' => 'IN', |
99 | 99 | ); |
100 | 100 | } |
@@ -102,17 +102,17 @@ discard block |
||
102 | 102 | $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
103 | 103 | |
104 | 104 | // Get results. |
105 | - $items = new WP_Query( $wp_query_args ); |
|
105 | + $items = new WP_Query($wp_query_args); |
|
106 | 106 | |
107 | - if ( 'objects' === $args['return'] ) { |
|
108 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
109 | - } elseif ( 'self' === $args['return'] ) { |
|
107 | + if ('objects' === $args['return']) { |
|
108 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
109 | + } elseif ('self' === $args['return']) { |
|
110 | 110 | return $items; |
111 | 111 | } else { |
112 | 112 | $return = $items->posts; |
113 | 113 | } |
114 | 114 | |
115 | - if ( $args['paginate' ] ) { |
|
115 | + if ($args['paginate']) { |
|
116 | 116 | return (object) array( |
117 | 117 | 'items' => $return, |
118 | 118 | 'total' => $items->found_posts, |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
128 | - if( empty( $item_id ) ) { |
|
127 | +function wpinv_is_free_item($item_id = 0) { |
|
128 | + if (empty($item_id)) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | - $item = new WPInv_Item( $item_id ); |
|
132 | + $item = new WPInv_Item($item_id); |
|
133 | 133 | |
134 | 134 | return $item->is_free(); |
135 | 135 | } |
@@ -139,128 +139,128 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
141 | 141 | */ |
142 | -function wpinv_item_is_editable( $item = 0 ) { |
|
142 | +function wpinv_item_is_editable($item = 0) { |
|
143 | 143 | |
144 | 144 | // Fetch the item. |
145 | - $item = new WPInv_Item( $item ); |
|
145 | + $item = new WPInv_Item($item); |
|
146 | 146 | |
147 | 147 | // Check if it is editable. |
148 | 148 | return $item->is_editable(); |
149 | 149 | } |
150 | 150 | |
151 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
152 | - if( empty( $item_id ) ) { |
|
151 | +function wpinv_get_item_price($item_id = 0) { |
|
152 | + if (empty($item_id)) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - $item = new WPInv_Item( $item_id ); |
|
156 | + $item = new WPInv_Item($item_id); |
|
157 | 157 | |
158 | 158 | return $item->get_price(); |
159 | 159 | } |
160 | 160 | |
161 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
162 | - if( empty( $item_id ) ) { |
|
161 | +function wpinv_is_recurring_item($item_id = 0) { |
|
162 | + if (empty($item_id)) { |
|
163 | 163 | return false; |
164 | 164 | } |
165 | 165 | |
166 | - $item = new WPInv_Item( $item_id ); |
|
166 | + $item = new WPInv_Item($item_id); |
|
167 | 167 | |
168 | 168 | return $item->is_recurring(); |
169 | 169 | } |
170 | 170 | |
171 | -function wpinv_item_price( $item_id = 0 ) { |
|
172 | - if( empty( $item_id ) ) { |
|
171 | +function wpinv_item_price($item_id = 0) { |
|
172 | + if (empty($item_id)) { |
|
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | |
176 | - $price = wpinv_get_item_price( $item_id ); |
|
177 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
176 | + $price = wpinv_get_item_price($item_id); |
|
177 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
178 | 178 | |
179 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
179 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
180 | 180 | } |
181 | 181 | |
182 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
183 | - if ( empty( $item_id ) ) { |
|
182 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
183 | + if (empty($item_id)) { |
|
184 | 184 | $item_id = get_the_ID(); |
185 | 185 | } |
186 | 186 | |
187 | - $price = wpinv_item_price( $item_id ); |
|
187 | + $price = wpinv_item_price($item_id); |
|
188 | 188 | |
189 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
189 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
190 | 190 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
191 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
191 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
192 | 192 | |
193 | - if ( $echo ) { |
|
193 | + if ($echo) { |
|
194 | 194 | echo $formatted_price; |
195 | 195 | } else { |
196 | 196 | return $formatted_price; |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
201 | - if ( is_null( $amount_override ) ) { |
|
202 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
200 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
201 | + if (is_null($amount_override)) { |
|
202 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
203 | 203 | } else { |
204 | 204 | $original_price = $amount_override; |
205 | 205 | } |
206 | 206 | |
207 | 207 | $price = $original_price; |
208 | 208 | |
209 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
209 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
210 | 210 | } |
211 | 211 | |
212 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
213 | - if( empty( $item_id ) ) { |
|
212 | +function wpinv_item_custom_singular_name($item_id) { |
|
213 | + if (empty($item_id)) { |
|
214 | 214 | return false; |
215 | 215 | } |
216 | 216 | |
217 | - $item = new WPInv_Item( $item_id ); |
|
217 | + $item = new WPInv_Item($item_id); |
|
218 | 218 | |
219 | 219 | return $item->get_custom_singular_name(); |
220 | 220 | } |
221 | 221 | |
222 | 222 | function wpinv_get_item_types() { |
223 | 223 | $item_types = array( |
224 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
225 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
224 | + 'custom' => __('Standard', 'invoicing'), |
|
225 | + 'fee' => __('Fee', 'invoicing'), |
|
226 | 226 | ); |
227 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
227 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function wpinv_item_types() { |
231 | 231 | $item_types = wpinv_get_item_types(); |
232 | 232 | |
233 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
233 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
234 | 234 | } |
235 | 235 | |
236 | -function wpinv_get_item_type( $item_id ) { |
|
237 | - if( empty( $item_id ) ) { |
|
236 | +function wpinv_get_item_type($item_id) { |
|
237 | + if (empty($item_id)) { |
|
238 | 238 | return false; |
239 | 239 | } |
240 | 240 | |
241 | - $item = new WPInv_Item( $item_id ); |
|
241 | + $item = new WPInv_Item($item_id); |
|
242 | 242 | |
243 | 243 | return $item->get_type(); |
244 | 244 | } |
245 | 245 | |
246 | -function wpinv_item_type( $item_id ) { |
|
246 | +function wpinv_item_type($item_id) { |
|
247 | 247 | $item_types = wpinv_get_item_types(); |
248 | 248 | |
249 | - $item_type = wpinv_get_item_type( $item_id ); |
|
249 | + $item_type = wpinv_get_item_type($item_id); |
|
250 | 250 | |
251 | - if ( empty( $item_type ) ) { |
|
251 | + if (empty($item_type)) { |
|
252 | 252 | $item_type = '-'; |
253 | 253 | } |
254 | 254 | |
255 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
255 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
256 | 256 | |
257 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
257 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
260 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
261 | 261 | global $wpinv_logs; |
262 | 262 | |
263 | - if ( empty( $wpinv_logs ) ) { |
|
263 | + if (empty($wpinv_logs)) { |
|
264 | 264 | return false; |
265 | 265 | } |
266 | 266 | |
@@ -269,278 +269,278 @@ discard block |
||
269 | 269 | 'log_type' => 'wpi_item' |
270 | 270 | ); |
271 | 271 | |
272 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
272 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
273 | 273 | |
274 | 274 | $log_meta = array( |
275 | 275 | 'user_info' => $user_info, |
276 | 276 | 'user_id' => $user_id, |
277 | - 'file_id' => (int)$file_id, |
|
277 | + 'file_id' => (int) $file_id, |
|
278 | 278 | 'ip' => $ip, |
279 | 279 | 'invoice_id'=> $invoice_id, |
280 | 280 | ); |
281 | 281 | |
282 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
282 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
286 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
285 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
286 | + if ('wpi_item' !== get_post_type($item_id)) |
|
287 | 287 | return; |
288 | 288 | |
289 | 289 | global $wpinv_logs; |
290 | 290 | |
291 | - if ( empty( $wpinv_logs ) ) { |
|
291 | + if (empty($wpinv_logs)) { |
|
292 | 292 | return false; |
293 | 293 | } |
294 | 294 | |
295 | 295 | // Remove all log entries related to this item |
296 | - $wpinv_logs->delete_logs( $item_id ); |
|
296 | + $wpinv_logs->delete_logs($item_id); |
|
297 | 297 | } |
298 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
298 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
299 | 299 | |
300 | -function wpinv_get_random_item( $post_ids = true ) { |
|
301 | - wpinv_get_random_items( 1, $post_ids ); |
|
300 | +function wpinv_get_random_item($post_ids = true) { |
|
301 | + wpinv_get_random_items(1, $post_ids); |
|
302 | 302 | } |
303 | 303 | |
304 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
305 | - if ( $post_ids ) { |
|
306 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
304 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
305 | + if ($post_ids) { |
|
306 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
307 | 307 | } else { |
308 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
308 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
309 | 309 | } |
310 | 310 | |
311 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
311 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
312 | 312 | |
313 | - return get_posts( $args ); |
|
313 | + return get_posts($args); |
|
314 | 314 | } |
315 | 315 | |
316 | -function wpinv_get_item_token( $url = '' ) { |
|
316 | +function wpinv_get_item_token($url = '') { |
|
317 | 317 | $args = array(); |
318 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
319 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
318 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
319 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
320 | 320 | |
321 | - $parts = parse_url( $url ); |
|
321 | + $parts = parse_url($url); |
|
322 | 322 | $options = array(); |
323 | 323 | |
324 | - if ( isset( $parts['query'] ) ) { |
|
325 | - wp_parse_str( $parts['query'], $query_args ); |
|
324 | + if (isset($parts['query'])) { |
|
325 | + wp_parse_str($parts['query'], $query_args); |
|
326 | 326 | |
327 | - if ( ! empty( $query_args['o'] ) ) { |
|
328 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
327 | + if (!empty($query_args['o'])) { |
|
328 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
329 | 329 | |
330 | - if ( in_array( 'ip', $options ) ) { |
|
330 | + if (in_array('ip', $options)) { |
|
331 | 331 | $args['ip'] = wpinv_get_ip(); |
332 | 332 | } |
333 | 333 | |
334 | - if ( in_array( 'ua', $options ) ) { |
|
334 | + if (in_array('ua', $options)) { |
|
335 | 335 | $ua = wpinv_get_user_agent(); |
336 | - $args['user_agent'] = rawurlencode( $ua ); |
|
336 | + $args['user_agent'] = rawurlencode($ua); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
341 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
342 | 342 | |
343 | 343 | $args['secret'] = $secret; |
344 | 344 | $args['token'] = false; |
345 | 345 | |
346 | - $url = add_query_arg( $args, $url ); |
|
347 | - $parts = parse_url( $url ); |
|
346 | + $url = add_query_arg($args, $url); |
|
347 | + $parts = parse_url($url); |
|
348 | 348 | |
349 | - if ( ! isset( $parts['path'] ) ) { |
|
349 | + if (!isset($parts['path'])) { |
|
350 | 350 | $parts['path'] = ''; |
351 | 351 | } |
352 | 352 | |
353 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
353 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
354 | 354 | |
355 | 355 | return $token; |
356 | 356 | } |
357 | 357 | |
358 | -function wpinv_validate_url_token( $url = '' ) { |
|
358 | +function wpinv_validate_url_token($url = '') { |
|
359 | 359 | $ret = false; |
360 | - $parts = parse_url( $url ); |
|
360 | + $parts = parse_url($url); |
|
361 | 361 | |
362 | - if ( isset( $parts['query'] ) ) { |
|
363 | - wp_parse_str( $parts['query'], $query_args ); |
|
362 | + if (isset($parts['query'])) { |
|
363 | + wp_parse_str($parts['query'], $query_args); |
|
364 | 364 | |
365 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
365 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
366 | 366 | 'item', |
367 | 367 | 'ttl', |
368 | 368 | 'token' |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | |
371 | 371 | $remove = array(); |
372 | 372 | |
373 | - foreach( $query_args as $key => $value ) { |
|
374 | - if( false === in_array( $key, $allowed ) ) { |
|
373 | + foreach ($query_args as $key => $value) { |
|
374 | + if (false === in_array($key, $allowed)) { |
|
375 | 375 | $remove[] = $key; |
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
379 | - if( ! empty( $remove ) ) { |
|
380 | - $url = remove_query_arg( $remove, $url ); |
|
379 | + if (!empty($remove)) { |
|
380 | + $url = remove_query_arg($remove, $url); |
|
381 | 381 | } |
382 | 382 | |
383 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
384 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
383 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
384 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
387 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
388 | 388 | $ret = true; |
389 | 389 | } |
390 | 390 | |
391 | 391 | } |
392 | 392 | |
393 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
393 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
394 | 394 | } |
395 | 395 | |
396 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
396 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
397 | 397 | $cart_items = wpinv_get_cart_contents(); |
398 | 398 | |
399 | 399 | $ret = false; |
400 | 400 | |
401 | - if ( is_array( $cart_items ) ) { |
|
402 | - foreach ( $cart_items as $item ) { |
|
403 | - if ( $item['id'] == $item_id ) { |
|
401 | + if (is_array($cart_items)) { |
|
402 | + foreach ($cart_items as $item) { |
|
403 | + if ($item['id'] == $item_id) { |
|
404 | 404 | $ret = true; |
405 | 405 | break; |
406 | 406 | } |
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
410 | + return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
411 | 411 | } |
412 | 412 | |
413 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
413 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
414 | 414 | $tax = 0; |
415 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
416 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
417 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
415 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
416 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
417 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
418 | 418 | |
419 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
419 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
420 | 420 | } |
421 | 421 | |
422 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
422 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_cart_item_price( $item, $currency = '' ) { |
|
425 | +function wpinv_cart_item_price($item, $currency = '') { |
|
426 | 426 | |
427 | - if( empty( $currency ) ) { |
|
427 | + if (empty($currency)) { |
|
428 | 428 | $currency = wpinv_get_currency(); |
429 | 429 | } |
430 | 430 | |
431 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
432 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
433 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
431 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
432 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
433 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
434 | 434 | |
435 | - if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
436 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
435 | + if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
436 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
437 | 437 | $price += $tax; |
438 | 438 | } |
439 | 439 | |
440 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
440 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
441 | 441 | $price -= $tax; |
442 | 442 | } |
443 | 443 | } |
444 | 444 | |
445 | - $price = wpinv_price( wpinv_format_amount( $price ), $currency ); |
|
445 | + $price = wpinv_price(wpinv_format_amount($price), $currency); |
|
446 | 446 | |
447 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
447 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
448 | 448 | } |
449 | 449 | |
450 | -function wpinv_cart_item_subtotal( $item, $currency = '' ) { |
|
450 | +function wpinv_cart_item_subtotal($item, $currency = '') { |
|
451 | 451 | |
452 | - if( empty( $currency ) ) { |
|
452 | + if (empty($currency)) { |
|
453 | 453 | $currency = wpinv_get_currency(); |
454 | 454 | } |
455 | 455 | |
456 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
457 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ), $currency ); |
|
456 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
457 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal), $currency); |
|
458 | 458 | |
459 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
459 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
460 | 460 | } |
461 | 461 | |
462 | -function wpinv_cart_item_tax( $item, $currency = '' ) { |
|
462 | +function wpinv_cart_item_tax($item, $currency = '') { |
|
463 | 463 | $tax = ''; |
464 | 464 | $tax_rate = ''; |
465 | 465 | |
466 | - if( empty( $currency ) ) { |
|
466 | + if (empty($currency)) { |
|
467 | 467 | $currency = wpinv_get_currency(); |
468 | 468 | } |
469 | 469 | |
470 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
471 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency ); |
|
472 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
473 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
470 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
471 | + $tax = wpinv_price(wpinv_format_amount($item['tax']), $currency); |
|
472 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
473 | + $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : ''; |
|
474 | 474 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
475 | 475 | } |
476 | 476 | |
477 | - $tax = $tax . $tax_rate; |
|
477 | + $tax = $tax . $tax_rate; |
|
478 | 478 | |
479 | - if ( $tax === '' ) { |
|
479 | + if ($tax === '') { |
|
480 | 480 | $tax = 0; // Zero tax |
481 | 481 | } |
482 | 482 | |
483 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
483 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
484 | 484 | } |
485 | 485 | |
486 | -function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) { |
|
486 | +function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) { |
|
487 | 487 | $price = 0; |
488 | 488 | |
489 | 489 | // Set custom price |
490 | - if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) { |
|
490 | + if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') { |
|
491 | 491 | $price = $cart_item['custom_price']; |
492 | 492 | } else { |
493 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
493 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
494 | 494 | |
495 | - if ( $variable_prices ) { |
|
496 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
495 | + if ($variable_prices) { |
|
496 | + $prices = wpinv_get_variable_prices($item_id); |
|
497 | 497 | |
498 | - if ( $prices ) { |
|
499 | - if( ! empty( $options ) ) { |
|
500 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
498 | + if ($prices) { |
|
499 | + if (!empty($options)) { |
|
500 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
501 | 501 | } else { |
502 | 502 | $price = false; |
503 | 503 | } |
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
507 | - if( ! $variable_prices || false === $price ) { |
|
508 | - if($cart_item['item_price'] > 0){ |
|
507 | + if (!$variable_prices || false === $price) { |
|
508 | + if ($cart_item['item_price'] > 0) { |
|
509 | 509 | $price = $cart_item['item_price']; |
510 | 510 | } else { |
511 | 511 | // Get the standard Item price if not using variable prices |
512 | - $price = wpinv_get_item_price( $item_id ); |
|
512 | + $price = wpinv_get_item_price($item_id); |
|
513 | 513 | } |
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
517 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
518 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
517 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
518 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
519 | 519 | } |
520 | 520 | |
521 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive ); |
|
521 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive); |
|
522 | 522 | } |
523 | 523 | |
524 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
525 | - if( isset( $item['item_number'] ) ) { |
|
526 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
524 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
525 | + if (isset($item['item_number'])) { |
|
526 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
527 | 527 | } else { |
528 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
528 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
529 | 529 | } |
530 | 530 | return $price_id; |
531 | 531 | } |
532 | 532 | |
533 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
534 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
535 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
536 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
537 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
533 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
534 | + $price_id = (int) wpinv_get_cart_item_price_id($item); |
|
535 | + $prices = wpinv_get_variable_prices($item['id']); |
|
536 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
537 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
538 | 538 | } |
539 | 539 | |
540 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
541 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
540 | +function wpinv_get_cart_item_name($item = array()) { |
|
541 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
542 | 542 | |
543 | - if ( empty( $item_title ) ) { |
|
543 | + if (empty($item_title)) { |
|
544 | 544 | $item_title = $item['id']; |
545 | 545 | } |
546 | 546 | |
@@ -550,23 +550,23 @@ discard block |
||
550 | 550 | } |
551 | 551 | */ |
552 | 552 | |
553 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
553 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
554 | 554 | } |
555 | 555 | |
556 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
556 | +function wpinv_has_variable_prices($item_id = 0) { |
|
557 | 557 | return false; |
558 | 558 | } |
559 | 559 | |
560 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
560 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
561 | 561 | $cart_items = wpinv_get_cart_contents(); |
562 | 562 | |
563 | - if ( !is_array( $cart_items ) ) { |
|
563 | + if (!is_array($cart_items)) { |
|
564 | 564 | return false; // Empty cart |
565 | 565 | } else { |
566 | - foreach ( $cart_items as $position => $item ) { |
|
567 | - if ( $item['id'] == $item_id ) { |
|
568 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
569 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
566 | + foreach ($cart_items as $position => $item) { |
|
567 | + if ($item['id'] == $item_id) { |
|
568 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
569 | + if ((int) $options['price_id'] == (int) $item['options']['price_id']) { |
|
570 | 570 | return $position; |
571 | 571 | } |
572 | 572 | } else { |
@@ -579,80 +579,80 @@ discard block |
||
579 | 579 | return false; // Not found |
580 | 580 | } |
581 | 581 | |
582 | -function wpinv_get_cart_item_quantity( $item ) { |
|
583 | - if ( wpinv_item_quantities_enabled() ) { |
|
584 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
582 | +function wpinv_get_cart_item_quantity($item) { |
|
583 | + if (wpinv_item_quantities_enabled()) { |
|
584 | + $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
585 | 585 | } else { |
586 | 586 | $quantity = 1; |
587 | 587 | } |
588 | 588 | |
589 | - if ( $quantity < 1 ) { |
|
589 | + if ($quantity < 1) { |
|
590 | 590 | $quantity = 1; |
591 | 591 | } |
592 | 592 | |
593 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
593 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
594 | 594 | } |
595 | 595 | |
596 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
597 | - if ( empty( $item ) ) { |
|
596 | +function wpinv_get_item_suffix($item, $html = true) { |
|
597 | + if (empty($item)) { |
|
598 | 598 | return NULL; |
599 | 599 | } |
600 | 600 | |
601 | - if ( is_int( $item ) ) { |
|
602 | - $item = new WPInv_Item( $item ); |
|
601 | + if (is_int($item)) { |
|
602 | + $item = new WPInv_Item($item); |
|
603 | 603 | } |
604 | 604 | |
605 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
605 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
606 | 606 | return NULL; |
607 | 607 | } |
608 | 608 | |
609 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
609 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
610 | 610 | |
611 | - if ( !$html && $suffix ) { |
|
612 | - $suffix = strip_tags( $suffix ); |
|
611 | + if (!$html && $suffix) { |
|
612 | + $suffix = strip_tags($suffix); |
|
613 | 613 | } |
614 | 614 | |
615 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
615 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
616 | 616 | } |
617 | 617 | |
618 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
619 | - if ( empty( $item ) ) { |
|
618 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
619 | + if (empty($item)) { |
|
620 | 620 | return NULL; |
621 | 621 | } |
622 | 622 | |
623 | - if ( is_int( $item ) ) { |
|
624 | - $item = new WPInv_Item( $item ); |
|
623 | + if (is_int($item)) { |
|
624 | + $item = new WPInv_Item($item); |
|
625 | 625 | } |
626 | 626 | |
627 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
627 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
628 | 628 | return NULL; |
629 | 629 | } |
630 | 630 | |
631 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
631 | + do_action('wpinv_pre_delete_item', $item); |
|
632 | 632 | |
633 | - wp_delete_post( $item->ID, $force_delete ); |
|
633 | + wp_delete_post($item->ID, $force_delete); |
|
634 | 634 | |
635 | - do_action( 'wpinv_post_delete_item', $item ); |
|
635 | + do_action('wpinv_post_delete_item', $item); |
|
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_can_delete_item( $post_id ) { |
|
638 | +function wpinv_can_delete_item($post_id) { |
|
639 | 639 | $return = wpinv_current_user_can_manage_invoicing() ? true : false; |
640 | 640 | |
641 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
641 | + if ($return && wpinv_item_in_use($post_id)) { |
|
642 | 642 | $return = false; // Don't delete item already use in invoices. |
643 | 643 | } |
644 | 644 | |
645 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
645 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | function wpinv_admin_action_delete() { |
649 | 649 | $screen = get_current_screen(); |
650 | 650 | |
651 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
651 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
652 | 652 | $post_ids = array(); |
653 | 653 | |
654 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
655 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
654 | + foreach ($_REQUEST['post'] as $post_id) { |
|
655 | + if (!wpinv_can_delete_item($post_id)) { |
|
656 | 656 | continue; |
657 | 657 | } |
658 | 658 | |
@@ -662,39 +662,39 @@ discard block |
||
662 | 662 | $_REQUEST['post'] = $post_ids; |
663 | 663 | } |
664 | 664 | } |
665 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
666 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
665 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
666 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
667 | 667 | |
668 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
669 | - if ( $post->post_type == 'wpi_item' ) { |
|
670 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
668 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
669 | + if ($post->post_type == 'wpi_item') { |
|
670 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
671 | 671 | return true; |
672 | 672 | } |
673 | 673 | } |
674 | 674 | |
675 | 675 | return $check; |
676 | 676 | } |
677 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
677 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
678 | 678 | |
679 | -function wpinv_item_in_use( $item_id ) { |
|
679 | +function wpinv_item_in_use($item_id) { |
|
680 | 680 | global $wpdb, $wpi_items_in_use; |
681 | 681 | |
682 | - if ( !$item_id > 0 ) { |
|
682 | + if (!$item_id > 0) { |
|
683 | 683 | return false; |
684 | 684 | } |
685 | 685 | |
686 | - if ( !empty( $wpi_items_in_use ) ) { |
|
687 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
686 | + if (!empty($wpi_items_in_use)) { |
|
687 | + if (isset($wpi_items_in_use[$item_id])) { |
|
688 | 688 | return $wpi_items_in_use[$item_id]; |
689 | 689 | } |
690 | 690 | } else { |
691 | 691 | $wpi_items_in_use = array(); |
692 | 692 | } |
693 | 693 | |
694 | - $statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
694 | + $statuses = array_keys(wpinv_get_invoice_statuses(true, true)); |
|
695 | 695 | |
696 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
697 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
696 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )"; |
|
697 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
698 | 698 | |
699 | 699 | $wpi_items_in_use[$item_id] = $in_use; |
700 | 700 | |
@@ -737,45 +737,45 @@ discard block |
||
737 | 737 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
738 | 738 | * @return bool|WP_Error|WPInv_Item |
739 | 739 | */ |
740 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
740 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
741 | 741 | |
742 | 742 | // Prepare the item. |
743 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
744 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
745 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
743 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
744 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
745 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
746 | 746 | |
747 | - if ( ! empty( $item ) ) { |
|
747 | + if (!empty($item)) { |
|
748 | 748 | $args['ID'] = $item->get_id(); |
749 | 749 | } |
750 | 750 | |
751 | 751 | } |
752 | 752 | |
753 | 753 | // Do we have an item? |
754 | - if ( ! empty( $args['ID'] ) ) { |
|
755 | - $item = new WPInv_Item( $args['ID'] ); |
|
754 | + if (!empty($args['ID'])) { |
|
755 | + $item = new WPInv_Item($args['ID']); |
|
756 | 756 | } else { |
757 | 757 | $item = new WPInv_Item(); |
758 | 758 | } |
759 | 759 | |
760 | 760 | // Do we have an error? |
761 | - if ( ! empty( $item->last_error ) ) { |
|
762 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
761 | + if (!empty($item->last_error)) { |
|
762 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | // Update item props. |
766 | - $item->set_props( $args ); |
|
766 | + $item->set_props($args); |
|
767 | 767 | |
768 | 768 | // Save the item. |
769 | 769 | $item->save(); |
770 | 770 | |
771 | 771 | // Do we have an error? |
772 | - if ( ! empty( $item->last_error ) ) { |
|
773 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
772 | + if (!empty($item->last_error)) { |
|
773 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | // Was the item saved? |
777 | - if ( ! $item->get_id() ) { |
|
778 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
777 | + if (!$item->get_id()) { |
|
778 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | return $item; |
@@ -787,14 +787,14 @@ discard block |
||
787 | 787 | * |
788 | 788 | * @see wpinv_create_item() |
789 | 789 | */ |
790 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
791 | - return wpinv_create_item( $args, $wp_error ); |
|
790 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
791 | + return wpinv_create_item($args, $wp_error); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | /** |
795 | 795 | * Sanitizes a recurring period |
796 | 796 | */ |
797 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
797 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
798 | 798 | |
799 | 799 | $periods = array( |
800 | 800 | 'D' => 'day', |
@@ -803,11 +803,11 @@ discard block |
||
803 | 803 | 'Y' => 'year', |
804 | 804 | ); |
805 | 805 | |
806 | - if ( ! isset( $periods[ $period ] ) ) { |
|
806 | + if (!isset($periods[$period])) { |
|
807 | 807 | $period = 'D'; |
808 | 808 | } |
809 | 809 | |
810 | - return $full ? $periods[ $period ] : $period; |
|
810 | + return $full ? $periods[$period] : $period; |
|
811 | 811 | |
812 | 812 | } |
813 | 813 | |
@@ -816,27 +816,27 @@ discard block |
||
816 | 816 | * |
817 | 817 | * @param WPInv_Item $item |
818 | 818 | */ |
819 | -function getpaid_item_recurring_price_help_text( $item, $currency = '' ) { |
|
819 | +function getpaid_item_recurring_price_help_text($item, $currency = '') { |
|
820 | 820 | |
821 | 821 | // Abort if it is not recurring. |
822 | - if ( ! $item->is_recurring() ) { |
|
822 | + if (!$item->is_recurring()) { |
|
823 | 823 | return ''; |
824 | 824 | } |
825 | 825 | |
826 | - $initial_price = wpinv_price( wpinv_sanitize_amount( $item->get_initial_price() ), $currency ); |
|
827 | - $recurring_price = wpinv_price( wpinv_sanitize_amount( $item->get_recurring_price() ), $currency ); |
|
828 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
826 | + $initial_price = wpinv_price(wpinv_sanitize_amount($item->get_initial_price()), $currency); |
|
827 | + $recurring_price = wpinv_price(wpinv_sanitize_amount($item->get_recurring_price()), $currency); |
|
828 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
829 | 829 | |
830 | 830 | // For free trial items. |
831 | - if ( $item->has_free_trial() ) { |
|
832 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
831 | + if ($item->has_free_trial()) { |
|
832 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
833 | 833 | |
834 | - if ( 0 == $item->get_initial_price() ) { |
|
834 | + if (0 == $item->get_initial_price()) { |
|
835 | 835 | |
836 | 836 | return sprintf( |
837 | 837 | |
838 | 838 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
839 | - _x( 'Free for %1$s then %3$s / %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
839 | + _x('Free for %1$s then %3$s / %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
840 | 840 | $trial_period, |
841 | 841 | $recurring_price, |
842 | 842 | $period |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | return sprintf( |
849 | 849 | |
850 | 850 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
851 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
851 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
852 | 852 | $initial_price, |
853 | 853 | $trial_period, |
854 | 854 | $recurring_price, |
@@ -858,12 +858,12 @@ discard block |
||
858 | 858 | |
859 | 859 | } |
860 | 860 | |
861 | - if ( $initial_price == $recurring_price ) { |
|
861 | + if ($initial_price == $recurring_price) { |
|
862 | 862 | |
863 | 863 | return sprintf( |
864 | 864 | |
865 | 865 | // translators: $1: is the recurring price, $2: is the susbcription period |
866 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
866 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
867 | 867 | $recurring_price, |
868 | 868 | $period |
869 | 869 | |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | return sprintf( |
875 | 875 | |
876 | 876 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
877 | - _x( 'Initial payment of %1$s then %3$s / %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
877 | + _x('Initial payment of %1$s then %3$s / %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
878 | 878 | $initial_price, |
879 | 879 | $recurring_price, |
880 | 880 | $period |
@@ -13,282 +13,282 @@ |
||
13 | 13 | class GetPaid_Subscription_Notification_Emails { |
14 | 14 | |
15 | 15 | /** |
16 | - * The array of subscription email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $subscription_actions; |
|
16 | + * The array of subscription email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $subscription_actions; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Class constructor |
|
23 | + * Class constructor |
|
24 | 24 | * |
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->subscription_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_subscription_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | - ) |
|
37 | - ); |
|
38 | - |
|
39 | - $this->init_hooks(); |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->subscription_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_subscription_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | + ) |
|
37 | + ); |
|
38 | + |
|
39 | + $this->init_hooks(); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | - * Registers email hooks. |
|
45 | - */ |
|
46 | - public function init_hooks() { |
|
47 | - |
|
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | - |
|
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | - |
|
53 | - if ( ! $email->is_active() ) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | - continue; |
|
60 | - } |
|
61 | - |
|
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email ); |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Filters subscription merge tags. |
|
70 | - * |
|
71 | - * @param array $merge_tags |
|
72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | - */ |
|
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
75 | - |
|
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | - $merge_tags = array_merge( |
|
78 | - $merge_tags, |
|
79 | - $this->get_subscription_merge_tags( $object ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - return $merge_tags; |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates subscription merge tags. |
|
89 | - * |
|
90 | - * @param WPInv_Subscription $subscription |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
94 | - |
|
95 | - // Abort if it does not exist. |
|
96 | - if ( ! $subscription->get_id() ) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $invoice = $subscription->get_parent_invoice(); |
|
101 | - return array( |
|
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ), |
|
108 | - '{subscription_initial_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | - ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Checks if we should send a notification for a subscription. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function should_send_notification( $invoice ) { |
|
123 | - return 0 != $invoice->get_id(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns notification recipients. |
|
128 | - * |
|
129 | - * @param WPInv_Invoice $invoice |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
134 | - |
|
135 | - $cc = $invoice->get_email_cc(); |
|
136 | - |
|
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | - } |
|
141 | - |
|
142 | - return $recipients; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Helper function to send an email. |
|
147 | - * |
|
148 | - * @param WPInv_Subscription $subscription |
|
149 | - * @param GetPaid_Notification_Email $email |
|
150 | - * @param string $type |
|
151 | - * @param array $extra_args Extra template args. |
|
152 | - */ |
|
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | - |
|
155 | - // Abort in case the parent invoice does not exist. |
|
156 | - $invoice = $subscription->get_parent_invoice(); |
|
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | - return; |
|
159 | - } |
|
160 | - |
|
161 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
162 | - |
|
163 | - $recipients = $this->get_recipients( $invoice ); |
|
164 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
165 | - $merge_tags = $email->get_merge_tags(); |
|
166 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
167 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
168 | - $attachments = $email->get_attachments(); |
|
169 | - |
|
170 | - $result = $mailer->send( |
|
171 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
172 | - $subject, |
|
173 | - $content, |
|
174 | - $attachments |
|
175 | - ); |
|
176 | - |
|
177 | - // Maybe send a copy to the admin. |
|
178 | - if ( $email->include_admin_bcc() ) { |
|
179 | - $mailer->send( |
|
180 | - wpinv_get_admin_email(), |
|
181 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
182 | - $content, |
|
183 | - $attachments |
|
184 | - ); |
|
185 | - } |
|
186 | - |
|
187 | - if ( ! $result ) { |
|
188 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
189 | - } |
|
190 | - |
|
191 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
192 | - |
|
193 | - } |
|
44 | + * Registers email hooks. |
|
45 | + */ |
|
46 | + public function init_hooks() { |
|
47 | + |
|
48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | + |
|
51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | + |
|
53 | + if ( ! $email->is_active() ) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $email_type ) ) { |
|
58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | + continue; |
|
60 | + } |
|
61 | + |
|
62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email ); |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
194 | 67 | |
195 | 68 | /** |
196 | - * Sends a new trial notification. |
|
197 | - * |
|
198 | - * @param WPInv_Subscription $subscription |
|
199 | - */ |
|
200 | - public function subscription_trial( $subscription ) { |
|
69 | + * Filters subscription merge tags. |
|
70 | + * |
|
71 | + * @param array $merge_tags |
|
72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | + */ |
|
74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
201 | 75 | |
202 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
203 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | + $merge_tags = array_merge( |
|
78 | + $merge_tags, |
|
79 | + $this->get_subscription_merge_tags( $object ) |
|
80 | + ); |
|
81 | + } |
|
204 | 82 | |
205 | - } |
|
83 | + return $merge_tags; |
|
206 | 84 | |
207 | - /** |
|
208 | - * Sends a cancelled subscription notification. |
|
209 | - * |
|
210 | - * @param WPInv_Subscription $subscription |
|
211 | - */ |
|
212 | - public function subscription_cancelled( $subscription ) { |
|
85 | + } |
|
213 | 86 | |
214 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
215 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
87 | + /** |
|
88 | + * Generates subscription merge tags. |
|
89 | + * |
|
90 | + * @param WPInv_Subscription $subscription |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function get_subscription_merge_tags( $subscription ) { |
|
94 | + |
|
95 | + // Abort if it does not exist. |
|
96 | + if ( ! $subscription->get_id() ) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | + return array( |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | + '{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ), |
|
108 | + '{subscription_initial_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | + ); |
|
216 | 113 | |
217 | - } |
|
114 | + } |
|
218 | 115 | |
219 | - /** |
|
220 | - * Sends a subscription expired notification. |
|
221 | - * |
|
222 | - * @param WPInv_Subscription $subscription |
|
223 | - */ |
|
224 | - public function subscription_expired( $subscription ) { |
|
116 | + /** |
|
117 | + * Checks if we should send a notification for a subscription. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function should_send_notification( $invoice ) { |
|
123 | + return 0 != $invoice->get_id(); |
|
124 | + } |
|
225 | 125 | |
226 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
227 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
126 | + /** |
|
127 | + * Returns notification recipients. |
|
128 | + * |
|
129 | + * @param WPInv_Invoice $invoice |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function get_recipients( $invoice ) { |
|
133 | + $recipients = array( $invoice->get_email() ); |
|
228 | 134 | |
229 | - } |
|
135 | + $cc = $invoice->get_email_cc(); |
|
230 | 136 | |
231 | - /** |
|
232 | - * Sends a completed subscription notification. |
|
233 | - * |
|
234 | - * @param WPInv_Subscription $subscription |
|
235 | - */ |
|
236 | - public function subscription_complete( $subscription ) { |
|
137 | + if ( ! empty( $cc ) ) { |
|
138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | + } |
|
237 | 141 | |
238 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
239 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
142 | + return $recipients; |
|
143 | + } |
|
240 | 144 | |
241 | - } |
|
145 | + /** |
|
146 | + * Helper function to send an email. |
|
147 | + * |
|
148 | + * @param WPInv_Subscription $subscription |
|
149 | + * @param GetPaid_Notification_Email $email |
|
150 | + * @param string $type |
|
151 | + * @param array $extra_args Extra template args. |
|
152 | + */ |
|
153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | + |
|
155 | + // Abort in case the parent invoice does not exist. |
|
156 | + $invoice = $subscription->get_parent_invoice(); |
|
157 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | + return; |
|
159 | + } |
|
160 | + |
|
161 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
162 | + |
|
163 | + $recipients = $this->get_recipients( $invoice ); |
|
164 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
165 | + $merge_tags = $email->get_merge_tags(); |
|
166 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
167 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
168 | + $attachments = $email->get_attachments(); |
|
169 | + |
|
170 | + $result = $mailer->send( |
|
171 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
172 | + $subject, |
|
173 | + $content, |
|
174 | + $attachments |
|
175 | + ); |
|
176 | + |
|
177 | + // Maybe send a copy to the admin. |
|
178 | + if ( $email->include_admin_bcc() ) { |
|
179 | + $mailer->send( |
|
180 | + wpinv_get_admin_email(), |
|
181 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
182 | + $content, |
|
183 | + $attachments |
|
184 | + ); |
|
185 | + } |
|
186 | + |
|
187 | + if ( ! $result ) { |
|
188 | + $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
189 | + } |
|
190 | + |
|
191 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
242 | 192 | |
243 | - /** |
|
244 | - * Sends a subscription renewal reminder notification. |
|
245 | - * |
|
246 | - */ |
|
247 | - public function renewal_reminder() { |
|
193 | + } |
|
248 | 194 | |
249 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
195 | + /** |
|
196 | + * Sends a new trial notification. |
|
197 | + * |
|
198 | + * @param WPInv_Subscription $subscription |
|
199 | + */ |
|
200 | + public function subscription_trial( $subscription ) { |
|
250 | 201 | |
251 | - // Fetch reminder days. |
|
252 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
202 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
203 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
253 | 204 | |
254 | - // Abort if non is set. |
|
255 | - if ( empty( $reminder_days ) ) { |
|
256 | - return; |
|
257 | - } |
|
205 | + } |
|
258 | 206 | |
259 | - // Fetch matching subscriptions. |
|
207 | + /** |
|
208 | + * Sends a cancelled subscription notification. |
|
209 | + * |
|
210 | + * @param WPInv_Subscription $subscription |
|
211 | + */ |
|
212 | + public function subscription_cancelled( $subscription ) { |
|
213 | + |
|
214 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
215 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Sends a subscription expired notification. |
|
221 | + * |
|
222 | + * @param WPInv_Subscription $subscription |
|
223 | + */ |
|
224 | + public function subscription_expired( $subscription ) { |
|
225 | + |
|
226 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
227 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
228 | + |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Sends a completed subscription notification. |
|
233 | + * |
|
234 | + * @param WPInv_Subscription $subscription |
|
235 | + */ |
|
236 | + public function subscription_complete( $subscription ) { |
|
237 | + |
|
238 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
239 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Sends a subscription renewal reminder notification. |
|
245 | + * |
|
246 | + */ |
|
247 | + public function renewal_reminder() { |
|
248 | + |
|
249 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
250 | + |
|
251 | + // Fetch reminder days. |
|
252 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
253 | + |
|
254 | + // Abort if non is set. |
|
255 | + if ( empty( $reminder_days ) ) { |
|
256 | + return; |
|
257 | + } |
|
258 | + |
|
259 | + // Fetch matching subscriptions. |
|
260 | 260 | $args = array( |
261 | 261 | 'number' => -1, |
262 | - 'count_total' => false, |
|
263 | - 'status' => 'trialling active', |
|
262 | + 'count_total' => false, |
|
263 | + 'status' => 'trialling active', |
|
264 | 264 | 'date_expires_query' => array( |
265 | - 'relation' => 'OR' |
|
265 | + 'relation' => 'OR' |
|
266 | 266 | ), |
267 | - ); |
|
267 | + ); |
|
268 | 268 | |
269 | - foreach ( $reminder_days as $days ) { |
|
270 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
269 | + foreach ( $reminder_days as $days ) { |
|
270 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
271 | 271 | |
272 | - $args['date_expires_query'][] = array( |
|
273 | - 'year' => $date['year'], |
|
274 | - 'month' => $date['month'], |
|
275 | - 'day' => $date['day'], |
|
276 | - ); |
|
272 | + $args['date_expires_query'][] = array( |
|
273 | + 'year' => $date['year'], |
|
274 | + 'month' => $date['month'], |
|
275 | + 'day' => $date['day'], |
|
276 | + ); |
|
277 | 277 | |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
280 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
281 | 281 | |
282 | 282 | foreach ( $subscriptions as $subscription ) { |
283 | 283 | |
284 | - // Skip packages. |
|
285 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
286 | - $email->object = $subscription; |
|
287 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
288 | - } |
|
284 | + // Skip packages. |
|
285 | + if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
286 | + $email->object = $subscription; |
|
287 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
288 | + } |
|
289 | 289 | |
290 | - } |
|
290 | + } |
|
291 | 291 | |
292 | - } |
|
292 | + } |
|
293 | 293 | |
294 | 294 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class handles subscription notificaiton emails. |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function init_hooks() { |
47 | 47 | |
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
48 | + add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2); |
|
49 | + foreach ($this->subscription_actions as $hook => $email_type) { |
|
50 | 50 | |
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
51 | + $email = new GetPaid_Notification_Email($email_type); |
|
52 | 52 | |
53 | - if ( ! $email->is_active() ) { |
|
53 | + if (!$email->is_active()) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
57 | + if (method_exists($this, $email_type)) { |
|
58 | + add_action($hook, array($this, $email_type), 100, 2); |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email ); |
|
62 | + do_action('getpaid_subscription_notification_email_register_hook', $email); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | * @param array $merge_tags |
72 | 72 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
73 | 73 | */ |
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
74 | + public function subscription_merge_tags($merge_tags, $object) { |
|
75 | 75 | |
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
76 | + if (is_a($object, 'WPInv_Subscription')) { |
|
77 | 77 | $merge_tags = array_merge( |
78 | 78 | $merge_tags, |
79 | - $this->get_subscription_merge_tags( $object ) |
|
79 | + $this->get_subscription_merge_tags($object) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -90,25 +90,25 @@ discard block |
||
90 | 90 | * @param WPInv_Subscription $subscription |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
93 | + public function get_subscription_merge_tags($subscription) { |
|
94 | 94 | |
95 | 95 | // Abort if it does not exist. |
96 | - if ( ! $subscription->get_id() ) { |
|
96 | + if (!$subscription->get_id()) { |
|
97 | 97 | return array(); |
98 | 98 | } |
99 | 99 | |
100 | - $invoice = $subscription->get_parent_invoice(); |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | 101 | return array( |
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ), |
|
108 | - '{subscription_initial_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')), |
|
103 | + '{subscription_created}' => getpaid_format_date_value($subscription->get_date_created()), |
|
104 | + '{subscription_status}' => sanitize_text_field($subscription->get_status_label()), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field($subscription->get_profile_id()), |
|
106 | + '{subscription_id}' => absint($subscription->get_id()), |
|
107 | + '{subscription_recurring_amount}' => wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $invoice->get_currency()), |
|
108 | + '{subscription_initial_amount}' => wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $invoice->get_currency()), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''), |
|
110 | 110 | '{subscription_bill_times}' => $subscription->get_bill_times(), |
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
111 | + '{subscription_url}' => esc_url($subscription->get_view_url()), |
|
112 | 112 | ); |
113 | 113 | |
114 | 114 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return bool |
121 | 121 | */ |
122 | - public function should_send_notification( $invoice ) { |
|
122 | + public function should_send_notification($invoice) { |
|
123 | 123 | return 0 != $invoice->get_id(); |
124 | 124 | } |
125 | 125 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * @param WPInv_Invoice $invoice |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
132 | + public function get_recipients($invoice) { |
|
133 | + $recipients = array($invoice->get_email()); |
|
134 | 134 | |
135 | 135 | $cc = $invoice->get_email_cc(); |
136 | 136 | |
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
137 | + if (!empty($cc)) { |
|
138 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
139 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return $recipients; |
@@ -150,45 +150,45 @@ discard block |
||
150 | 150 | * @param string $type |
151 | 151 | * @param array $extra_args Extra template args. |
152 | 152 | */ |
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
153 | + public function send_email($subscription, $email, $type, $extra_args = array()) { |
|
154 | 154 | |
155 | 155 | // Abort in case the parent invoice does not exist. |
156 | 156 | $invoice = $subscription->get_parent_invoice(); |
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
157 | + if (!$this->should_send_notification($invoice)) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | |
161 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
161 | + do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email); |
|
162 | 162 | |
163 | - $recipients = $this->get_recipients( $invoice ); |
|
163 | + $recipients = $this->get_recipients($invoice); |
|
164 | 164 | $mailer = new GetPaid_Notification_Email_Sender(); |
165 | 165 | $merge_tags = $email->get_merge_tags(); |
166 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
167 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
166 | + $content = $email->get_content($merge_tags, $extra_args); |
|
167 | + $subject = $email->add_merge_tags($email->get_subject(), $merge_tags); |
|
168 | 168 | $attachments = $email->get_attachments(); |
169 | 169 | |
170 | 170 | $result = $mailer->send( |
171 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
171 | + apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email), |
|
172 | 172 | $subject, |
173 | 173 | $content, |
174 | 174 | $attachments |
175 | 175 | ); |
176 | 176 | |
177 | 177 | // Maybe send a copy to the admin. |
178 | - if ( $email->include_admin_bcc() ) { |
|
178 | + if ($email->include_admin_bcc()) { |
|
179 | 179 | $mailer->send( |
180 | 180 | wpinv_get_admin_email(), |
181 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
181 | + $subject . __(' - ADMIN BCC COPY', 'invoicing'), |
|
182 | 182 | $content, |
183 | 183 | $attachments |
184 | 184 | ); |
185 | 185 | } |
186 | 186 | |
187 | - if ( ! $result ) { |
|
188 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
187 | + if (!$result) { |
|
188 | + $subscription->get_parent_invoice()->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
189 | 189 | } |
190 | 190 | |
191 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
191 | + do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email); |
|
192 | 192 | |
193 | 193 | } |
194 | 194 | |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @param WPInv_Subscription $subscription |
199 | 199 | */ |
200 | - public function subscription_trial( $subscription ) { |
|
200 | + public function subscription_trial($subscription) { |
|
201 | 201 | |
202 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
203 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
202 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
203 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
204 | 204 | |
205 | 205 | } |
206 | 206 | |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | * |
210 | 210 | * @param WPInv_Subscription $subscription |
211 | 211 | */ |
212 | - public function subscription_cancelled( $subscription ) { |
|
212 | + public function subscription_cancelled($subscription) { |
|
213 | 213 | |
214 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
215 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
214 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
215 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
216 | 216 | |
217 | 217 | } |
218 | 218 | |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @param WPInv_Subscription $subscription |
223 | 223 | */ |
224 | - public function subscription_expired( $subscription ) { |
|
224 | + public function subscription_expired($subscription) { |
|
225 | 225 | |
226 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
227 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
226 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
227 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
228 | 228 | |
229 | 229 | } |
230 | 230 | |
@@ -233,10 +233,10 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @param WPInv_Subscription $subscription |
235 | 235 | */ |
236 | - public function subscription_complete( $subscription ) { |
|
236 | + public function subscription_complete($subscription) { |
|
237 | 237 | |
238 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
239 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
238 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
239 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
240 | 240 | |
241 | 241 | } |
242 | 242 | |
@@ -246,18 +246,18 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function renewal_reminder() { |
248 | 248 | |
249 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
249 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
250 | 250 | |
251 | 251 | // Fetch reminder days. |
252 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
252 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
253 | 253 | |
254 | 254 | // Abort if non is set. |
255 | - if ( empty( $reminder_days ) ) { |
|
255 | + if (empty($reminder_days)) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | 258 | |
259 | 259 | // Fetch matching subscriptions. |
260 | - $args = array( |
|
260 | + $args = array( |
|
261 | 261 | 'number' => -1, |
262 | 262 | 'count_total' => false, |
263 | 263 | 'status' => 'trialling active', |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | ), |
267 | 267 | ); |
268 | 268 | |
269 | - foreach ( $reminder_days as $days ) { |
|
270 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
269 | + foreach ($reminder_days as $days) { |
|
270 | + $date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp')))); |
|
271 | 271 | |
272 | 272 | $args['date_expires_query'][] = array( |
273 | 273 | 'year' => $date['year'], |
@@ -277,14 +277,14 @@ discard block |
||
277 | 277 | |
278 | 278 | } |
279 | 279 | |
280 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
280 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
281 | 281 | |
282 | - foreach ( $subscriptions as $subscription ) { |
|
282 | + foreach ($subscriptions as $subscription) { |
|
283 | 283 | |
284 | 284 | // Skip packages. |
285 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
285 | + if (get_post_meta($subscription->get_product_id(), '_wpinv_type', true) != 'package') { |
|
286 | 286 | $email->object = $subscription; |
287 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
287 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Personal data exporters. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WPInv_Privacy_Exporters Class. |
@@ -17,38 +17,38 @@ discard block |
||
17 | 17 | * @param int $page Page. |
18 | 18 | * @return array An array of invoice data in name value pairs |
19 | 19 | */ |
20 | - public static function customer_invoice_data_exporter( $email_address, $page ) { |
|
20 | + public static function customer_invoice_data_exporter($email_address, $page) { |
|
21 | 21 | $done = false; |
22 | 22 | $page = (int) $page; |
23 | 23 | $data_to_export = array(); |
24 | 24 | |
25 | - $user = get_user_by( 'email', $email_address ); |
|
26 | - if ( ! $user instanceof WP_User ) { |
|
25 | + $user = get_user_by('email', $email_address); |
|
26 | + if (!$user instanceof WP_User) { |
|
27 | 27 | return array( |
28 | 28 | 'data' => $data_to_export, |
29 | 29 | 'done' => true, |
30 | 30 | ); |
31 | 31 | } |
32 | 32 | |
33 | - $args = array( |
|
33 | + $args = array( |
|
34 | 34 | 'limit' => 30, |
35 | 35 | 'page' => $page, |
36 | 36 | 'user' => $user->ID, |
37 | 37 | ); |
38 | 38 | |
39 | - $invoices = wpinv_get_invoices( $args ); |
|
39 | + $invoices = wpinv_get_invoices($args); |
|
40 | 40 | |
41 | - if ( 0 < count( $invoices ) ) { |
|
42 | - foreach ( $invoices as $invoice ) { |
|
41 | + if (0 < count($invoices)) { |
|
42 | + foreach ($invoices as $invoice) { |
|
43 | 43 | $data_to_export[] = array( |
44 | 44 | 'group_id' => 'customer_invoices', |
45 | - 'group_label' => __( 'Invoicing Data', 'invoicing' ), |
|
46 | - 'group_description' => __( 'Customer invoicing data.', 'invoicing' ), |
|
45 | + 'group_label' => __('Invoicing Data', 'invoicing'), |
|
46 | + 'group_description' => __('Customer invoicing data.', 'invoicing'), |
|
47 | 47 | 'item_id' => "wpinv-{$invoice->ID}", |
48 | - 'data' => self::get_customer_invoice_data( $invoice ), |
|
48 | + 'data' => self::get_customer_invoice_data($invoice), |
|
49 | 49 | ); |
50 | 50 | } |
51 | - $done = 30 > count( $invoices ); |
|
51 | + $done = 30 > count($invoices); |
|
52 | 52 | } else { |
53 | 53 | $done = true; |
54 | 54 | } |
@@ -66,59 +66,59 @@ discard block |
||
66 | 66 | * @param WPInv_Invoice $invoice invoice object. |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - public static function get_customer_invoice_data( $invoice ) { |
|
69 | + public static function get_customer_invoice_data($invoice) { |
|
70 | 70 | $personal_data = array(); |
71 | 71 | |
72 | 72 | $props_to_export = array( |
73 | - 'number' => __( 'Invoice Number', 'invoicing' ), |
|
74 | - 'created_date' => __( 'Invoice Date', 'invoicing' ), |
|
75 | - 'status' => __( 'Invoice Status', 'invoicing' ), |
|
76 | - 'total' => __( 'Invoice Total', 'invoicing' ), |
|
77 | - 'items' => __( 'Invoice Items', 'invoicing' ), |
|
78 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
79 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
80 | - 'email' => __( 'Email Address', 'invoicing' ), |
|
81 | - '_wpinv_company' => __( 'Company', 'invoicing' ), |
|
82 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
83 | - 'address' => __( 'Address', 'invoicing' ), |
|
84 | - '_wpinv_city' => __( 'City', 'invoicing' ), |
|
85 | - '_wpinv_country' => __( 'Country', 'invoicing' ), |
|
86 | - '_wpinv_state' => __( 'State', 'invoicing' ), |
|
87 | - '_wpinv_zip' => __( 'Zip Code', 'invoicing' ), |
|
73 | + 'number' => __('Invoice Number', 'invoicing'), |
|
74 | + 'created_date' => __('Invoice Date', 'invoicing'), |
|
75 | + 'status' => __('Invoice Status', 'invoicing'), |
|
76 | + 'total' => __('Invoice Total', 'invoicing'), |
|
77 | + 'items' => __('Invoice Items', 'invoicing'), |
|
78 | + 'first_name' => __('First Name', 'invoicing'), |
|
79 | + 'last_name' => __('Last Name', 'invoicing'), |
|
80 | + 'email' => __('Email Address', 'invoicing'), |
|
81 | + '_wpinv_company' => __('Company', 'invoicing'), |
|
82 | + 'phone' => __('Phone Number', 'invoicing'), |
|
83 | + 'address' => __('Address', 'invoicing'), |
|
84 | + '_wpinv_city' => __('City', 'invoicing'), |
|
85 | + '_wpinv_country' => __('Country', 'invoicing'), |
|
86 | + '_wpinv_state' => __('State', 'invoicing'), |
|
87 | + '_wpinv_zip' => __('Zip Code', 'invoicing'), |
|
88 | 88 | ); |
89 | 89 | |
90 | - $subscription = wpinv_get_subscription( $invoice ); |
|
90 | + $subscription = wpinv_get_subscription($invoice); |
|
91 | 91 | $period = $initial_amt = $bill_times = $billed = $renewal_date = ''; |
92 | 92 | |
93 | - if ( $invoice->is_recurring() && !empty( $subscription ) ) { |
|
94 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(),$subscription->get_frequency() ); |
|
95 | - $period = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ) . ' / ' . $frequency; |
|
96 | - $initial_amt = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
97 | - $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->get_bill_times() == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->get_bill_times() ); |
|
98 | - $renewal_date = ! empty( $subscription->expiration ) ? getpaid_format_date( $subscription->expiration ) : __( 'N/A', 'invoicing' ); |
|
99 | - |
|
100 | - $props_to_export['period'] = __( 'Billing Cycle', 'invoicing' ); |
|
101 | - $props_to_export['initial_amount'] = __( 'Initial Amount', 'invoicing' ); |
|
102 | - $props_to_export['bill_times'] = __( 'Times Billed', 'invoicing' ); |
|
103 | - $props_to_export['renewal_date'] = __( 'Renewal Date', 'invoicing' ); |
|
93 | + if ($invoice->is_recurring() && !empty($subscription)) { |
|
94 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency()); |
|
95 | + $period = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency()) . ' / ' . $frequency; |
|
96 | + $initial_amt = wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency()); |
|
97 | + $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->get_bill_times() == 0) ? __('Until Cancelled', 'invoicing') : $subscription->get_bill_times()); |
|
98 | + $renewal_date = !empty($subscription->expiration) ? getpaid_format_date($subscription->expiration) : __('N/A', 'invoicing'); |
|
99 | + |
|
100 | + $props_to_export['period'] = __('Billing Cycle', 'invoicing'); |
|
101 | + $props_to_export['initial_amount'] = __('Initial Amount', 'invoicing'); |
|
102 | + $props_to_export['bill_times'] = __('Times Billed', 'invoicing'); |
|
103 | + $props_to_export['renewal_date'] = __('Renewal Date', 'invoicing'); |
|
104 | 104 | } |
105 | 105 | |
106 | - $props_to_export['ip'] = __( 'IP Address', 'invoicing' ); |
|
107 | - $props_to_export['view_url'] = __( 'Invoice Link', 'invoicing' ); |
|
106 | + $props_to_export['ip'] = __('IP Address', 'invoicing'); |
|
107 | + $props_to_export['view_url'] = __('Invoice Link', 'invoicing'); |
|
108 | 108 | |
109 | - $props_to_export = apply_filters( 'wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
109 | + $props_to_export = apply_filters('wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
110 | 110 | |
111 | - foreach ( $props_to_export as $prop => $name ) { |
|
111 | + foreach ($props_to_export as $prop => $name) { |
|
112 | 112 | $value = ''; |
113 | 113 | |
114 | - switch ( $prop ) { |
|
114 | + switch ($prop) { |
|
115 | 115 | case 'items': |
116 | 116 | $item_names = array(); |
117 | - foreach ( $invoice->get_cart_details() as $key => $cart_item ) { |
|
118 | - $item_quantity = $cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
117 | + foreach ($invoice->get_cart_details() as $key => $cart_item) { |
|
118 | + $item_quantity = $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
119 | 119 | $item_names[] = $cart_item['name'] . ' x ' . $item_quantity; |
120 | 120 | } |
121 | - $value = implode( ', ', $item_names ); |
|
121 | + $value = implode(', ', $item_names); |
|
122 | 122 | break; |
123 | 123 | case 'status': |
124 | 124 | $value = $invoice->get_status(true); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $value = $renewal_date; |
140 | 140 | break; |
141 | 141 | default: |
142 | - if ( is_callable( array( $invoice, 'get_' . $prop ) ) ) { |
|
142 | + if (is_callable(array($invoice, 'get_' . $prop))) { |
|
143 | 143 | $value = $invoice->{"get_$prop"}(); |
144 | 144 | } else { |
145 | 145 | $value = $invoice->get_meta($prop); |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | break; |
148 | 148 | } |
149 | 149 | |
150 | - $value = apply_filters( 'wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice ); |
|
150 | + $value = apply_filters('wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice); |
|
151 | 151 | |
152 | - if ( $value ) { |
|
152 | + if ($value) { |
|
153 | 153 | $personal_data[] = array( |
154 | 154 | 'name' => $name, |
155 | 155 | 'value' => $value, |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | } |
160 | 160 | |
161 | - $personal_data = apply_filters( 'wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice ); |
|
161 | + $personal_data = apply_filters('wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice); |
|
162 | 162 | |
163 | 163 | return $personal_data; |
164 | 164 |
@@ -43,64 +43,64 @@ discard block |
||
43 | 43 | <td class="w-75"> |
44 | 44 | <?php |
45 | 45 | |
46 | - switch ( $key ) { |
|
46 | + switch ( $key ) { |
|
47 | 47 | |
48 | - case 'status': |
|
49 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
50 | - break; |
|
48 | + case 'status': |
|
49 | + echo sanitize_text_field( $subscription->get_status_label() ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'start_date': |
|
53 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
54 | - break; |
|
52 | + case 'start_date': |
|
53 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'expiry_date': |
|
57 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
58 | - break; |
|
56 | + case 'expiry_date': |
|
57 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
58 | + break; |
|
59 | 59 | |
60 | - case 'initial_amount': |
|
61 | - echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
60 | + case 'initial_amount': |
|
61 | + echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
62 | 62 | |
63 | - if ( $subscription->has_trial_period() ) { |
|
63 | + if ( $subscription->has_trial_period() ) { |
|
64 | 64 | |
65 | - echo "<small class='text-muted'> "; |
|
66 | - printf( |
|
67 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
69 | - ); |
|
70 | - echo '</small>'; |
|
65 | + echo "<small class='text-muted'> "; |
|
66 | + printf( |
|
67 | + _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | + sanitize_text_field( $subscription->get_trial_period() ) |
|
69 | + ); |
|
70 | + echo '</small>'; |
|
71 | 71 | |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - break; |
|
74 | + break; |
|
75 | 75 | |
76 | - case 'recurring_amount': |
|
77 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
78 | - $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
80 | - break; |
|
76 | + case 'recurring_amount': |
|
77 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
78 | + $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | + echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
80 | + break; |
|
81 | 81 | |
82 | - case 'item': |
|
83 | - $item = get_post( $subscription->get_product_id() ); |
|
82 | + case 'item': |
|
83 | + $item = get_post( $subscription->get_product_id() ); |
|
84 | 84 | |
85 | - if ( ! empty( $item ) ) { |
|
86 | - echo esc_html( get_the_title( $item ) ); |
|
87 | - } else { |
|
88 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
89 | - } |
|
85 | + if ( ! empty( $item ) ) { |
|
86 | + echo esc_html( get_the_title( $item ) ); |
|
87 | + } else { |
|
88 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
89 | + } |
|
90 | 90 | |
91 | - break; |
|
91 | + break; |
|
92 | 92 | |
93 | - case 'payments': |
|
93 | + case 'payments': |
|
94 | 94 | |
95 | - $max_activations = (int) $subscription->get_bill_times(); |
|
96 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
95 | + $max_activations = (int) $subscription->get_bill_times(); |
|
96 | + echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
97 | 97 | |
98 | - break; |
|
98 | + break; |
|
99 | 99 | |
100 | - } |
|
101 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
100 | + } |
|
101 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
102 | 102 | |
103 | - ?> |
|
103 | + ?> |
|
104 | 104 | </td> |
105 | 105 | |
106 | 106 | </tr> |
@@ -117,15 +117,15 @@ discard block |
||
117 | 117 | <span class="form-text"> |
118 | 118 | |
119 | 119 | <?php |
120 | - if ( $subscription->can_cancel() ) { |
|
121 | - printf( |
|
122 | - '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
123 | - esc_url( $subscription->get_cancel_url() ), |
|
124 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
125 | - __( 'Cancel Subscription', 'invoicing' ) |
|
126 | - ); |
|
127 | - } |
|
128 | - ?> |
|
120 | + if ( $subscription->can_cancel() ) { |
|
121 | + printf( |
|
122 | + '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
123 | + esc_url( $subscription->get_cancel_url() ), |
|
124 | + esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
125 | + __( 'Cancel Subscription', 'invoicing' ) |
|
126 | + ); |
|
127 | + } |
|
128 | + ?> |
|
129 | 129 | |
130 | 130 | <a href="<?php echo esc_url( get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
131 | 131 | </span> |
132 | 132 | \ No newline at end of file |
@@ -9,14 +9,14 @@ discard block |
||
9 | 9 | * @var WPInv_Subscriptions_Widget $widget |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
14 | +do_action('getpaid_single_subscription_before_notices', $subscription); |
|
15 | 15 | |
16 | 16 | // Display errors and notices. |
17 | 17 | wpinv_print_errors(); |
18 | 18 | |
19 | -do_action( 'getpaid_before_single_subscription', $subscription ); |
|
19 | +do_action('getpaid_before_single_subscription', $subscription); |
|
20 | 20 | |
21 | 21 | ?> |
22 | 22 | |
@@ -28,44 +28,44 @@ discard block |
||
28 | 28 | |
29 | 29 | </style> |
30 | 30 | |
31 | -<h2 class="mb-1 h4"><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
31 | +<h2 class="mb-1 h4"><?php _e('Subscription Details', 'invoicing'); ?></h2> |
|
32 | 32 | <table class="table table-bordered"> |
33 | 33 | <tbody> |
34 | 34 | |
35 | - <?php foreach ( $widget->get_single_subscription_columns( $subscription ) as $key => $label ) : ?> |
|
35 | + <?php foreach ($widget->get_single_subscription_columns($subscription) as $key => $label) : ?> |
|
36 | 36 | |
37 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
37 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
38 | 38 | |
39 | 39 | <th class="w-25" style="font-weight: 500;"> |
40 | - <?php echo sanitize_text_field( $label ); ?> |
|
40 | + <?php echo sanitize_text_field($label); ?> |
|
41 | 41 | </th> |
42 | 42 | |
43 | 43 | <td class="w-75"> |
44 | 44 | <?php |
45 | 45 | |
46 | - switch ( $key ) { |
|
46 | + switch ($key) { |
|
47 | 47 | |
48 | 48 | case 'status': |
49 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
49 | + echo sanitize_text_field($subscription->get_status_label()); |
|
50 | 50 | break; |
51 | 51 | |
52 | 52 | case 'start_date': |
53 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
53 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_date_created())); |
|
54 | 54 | break; |
55 | 55 | |
56 | 56 | case 'expiry_date': |
57 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
57 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_next_renewal_date())); |
|
58 | 58 | break; |
59 | 59 | |
60 | 60 | case 'initial_amount': |
61 | - echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
61 | + echo wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency()); |
|
62 | 62 | |
63 | - if ( $subscription->has_trial_period() ) { |
|
63 | + if ($subscription->has_trial_period()) { |
|
64 | 64 | |
65 | 65 | echo "<small class='text-muted'> "; |
66 | 66 | printf( |
67 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
67 | + _x('( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing'), |
|
68 | + sanitize_text_field($subscription->get_trial_period()) |
|
69 | 69 | ); |
70 | 70 | echo '</small>'; |
71 | 71 | |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | break; |
75 | 75 | |
76 | 76 | case 'recurring_amount': |
77 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
78 | - $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
77 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
78 | + $amount = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency()); |
|
79 | + echo strtolower("<strong style='font-weight: 500;'>$amount</strong> / $frequency"); |
|
80 | 80 | break; |
81 | 81 | |
82 | 82 | case 'item': |
83 | - $item = get_post( $subscription->get_product_id() ); |
|
83 | + $item = get_post($subscription->get_product_id()); |
|
84 | 84 | |
85 | - if ( ! empty( $item ) ) { |
|
86 | - echo esc_html( get_the_title( $item ) ); |
|
85 | + if (!empty($item)) { |
|
86 | + echo esc_html(get_the_title($item)); |
|
87 | 87 | } else { |
88 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
88 | + echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id()); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | break; |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | case 'payments': |
94 | 94 | |
95 | 95 | $max_activations = (int) $subscription->get_bill_times(); |
96 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
96 | + echo (int) $subscription->get_times_billed() . ' / ' . (empty($max_activations) ? "∞" : $max_activations); |
|
97 | 97 | |
98 | 98 | break; |
99 | 99 | |
100 | 100 | } |
101 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
101 | + do_action("getpaid_render_single_subscription_column_$key", $subscription); |
|
102 | 102 | |
103 | 103 | ?> |
104 | 104 | </td> |
@@ -110,22 +110,22 @@ discard block |
||
110 | 110 | </tbody> |
111 | 111 | </table> |
112 | 112 | |
113 | -<h2 class='mt-5 mb-1 h4'><?php _e( 'Subscription Invoices', 'invoicing' ); ?></h2> |
|
113 | +<h2 class='mt-5 mb-1 h4'><?php _e('Subscription Invoices', 'invoicing'); ?></h2> |
|
114 | 114 | |
115 | -<?php echo getpaid_admin_subscription_invoice_details_metabox( $subscription ); ?> |
|
115 | +<?php echo getpaid_admin_subscription_invoice_details_metabox($subscription); ?> |
|
116 | 116 | |
117 | 117 | <span class="form-text"> |
118 | 118 | |
119 | 119 | <?php |
120 | - if ( $subscription->can_cancel() ) { |
|
120 | + if ($subscription->can_cancel()) { |
|
121 | 121 | printf( |
122 | 122 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
123 | - esc_url( $subscription->get_cancel_url() ), |
|
124 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
125 | - __( 'Cancel Subscription', 'invoicing' ) |
|
123 | + esc_url($subscription->get_cancel_url()), |
|
124 | + esc_attr__('Are you sure you want to cancel this subscription?', 'invoicing'), |
|
125 | + __('Cancel Subscription', 'invoicing') |
|
126 | 126 | ); |
127 | 127 | } |
128 | 128 | ?> |
129 | 129 | |
130 | - <a href="<?php echo esc_url( get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
|
130 | + <a href="<?php echo esc_url(get_permalink((int) wpinv_get_option('invoice_subscription_page'))); ?>" class="btn btn-secondary btn-sm"><?php _e('Go Back', 'invoicing'); ?></a> |
|
131 | 131 | </span> |
132 | 132 | \ No newline at end of file |
@@ -13,38 +13,38 @@ |
||
13 | 13 | |
14 | 14 | foreach ( array_keys( $widget->get_subscriptions_table_columns() ) as $column ) : |
15 | 15 | |
16 | - $class = sanitize_html_class( $column ); |
|
17 | - echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
|
16 | + $class = sanitize_html_class( $column ); |
|
17 | + echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
|
18 | 18 | |
19 | - do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
19 | + do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
20 | 20 | |
21 | - switch( $column ) : |
|
21 | + switch( $column ) : |
|
22 | 22 | |
23 | - case 'subscription': |
|
24 | - $subscription_id = (int) $subscription->get_id(); |
|
25 | - $url = esc_url( $subscription->get_view_url() ); |
|
26 | - echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
27 | - break; |
|
23 | + case 'subscription': |
|
24 | + $subscription_id = (int) $subscription->get_id(); |
|
25 | + $url = esc_url( $subscription->get_view_url() ); |
|
26 | + echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
27 | + break; |
|
28 | 28 | |
29 | - case 'status': |
|
30 | - echo $subscription->get_status_label(); |
|
31 | - break; |
|
29 | + case 'status': |
|
30 | + echo $subscription->get_status_label(); |
|
31 | + break; |
|
32 | 32 | |
33 | - case 'renewal-date': |
|
34 | - $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
35 | - echo $subscription->is_active() ? $renewal : "—"; |
|
36 | - break; |
|
33 | + case 'renewal-date': |
|
34 | + $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
35 | + echo $subscription->is_active() ? $renewal : "—"; |
|
36 | + break; |
|
37 | 37 | |
38 | - case 'amount': |
|
39 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
40 | - $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
41 | - echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
|
42 | - break; |
|
38 | + case 'amount': |
|
39 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
40 | + $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
41 | + echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
|
42 | + break; |
|
43 | 43 | |
44 | - endswitch; |
|
44 | + endswitch; |
|
45 | 45 | |
46 | - do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
46 | + do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
47 | 47 | |
48 | - echo '</td>'; |
|
48 | + echo '</td>'; |
|
49 | 49 | |
50 | 50 | endforeach; |
@@ -9,21 +9,21 @@ discard block |
||
9 | 9 | * @var WPInv_Subscriptions_Widget $widget |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -foreach ( array_keys( $widget->get_subscriptions_table_columns() ) as $column ) : |
|
14 | +foreach (array_keys($widget->get_subscriptions_table_columns()) as $column) : |
|
15 | 15 | |
16 | - $class = sanitize_html_class( $column ); |
|
16 | + $class = sanitize_html_class($column); |
|
17 | 17 | echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
18 | 18 | |
19 | - do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
19 | + do_action("getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription); |
|
20 | 20 | |
21 | - switch( $column ) : |
|
21 | + switch ($column) : |
|
22 | 22 | |
23 | 23 | case 'subscription': |
24 | 24 | $subscription_id = (int) $subscription->get_id(); |
25 | - $url = esc_url( $subscription->get_view_url() ); |
|
26 | - echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
25 | + $url = esc_url($subscription->get_view_url()); |
|
26 | + echo $widget->add_row_actions("<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription); |
|
27 | 27 | break; |
28 | 28 | |
29 | 29 | case 'status': |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | break; |
32 | 32 | |
33 | 33 | case 'renewal-date': |
34 | - $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
34 | + $renewal = getpaid_format_date_value($subscription->get_next_renewal_date()); |
|
35 | 35 | echo $subscription->is_active() ? $renewal : "—"; |
36 | 36 | break; |
37 | 37 | |
38 | 38 | case 'amount': |
39 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
40 | - $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
39 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
40 | + $amount = wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($subscription->get_recurring_amount())), $subscription->get_parent_payment()->get_currency()); |
|
41 | 41 | echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
42 | 42 | break; |
43 | 43 | |
44 | 44 | endswitch; |
45 | 45 | |
46 | - do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
46 | + do_action("getpaid_subscriptions_frontend_subscription_table_$column", $subscription); |
|
47 | 47 | |
48 | 48 | echo '</td>'; |
49 | 49 |