@@ -160,50 +160,50 @@ |
||
160 | 160 | */ |
161 | 161 | function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
162 | 162 | |
163 | - $initial_discount = 0; |
|
164 | - $recurring_discount = 0; |
|
163 | + $initial_discount = 0; |
|
164 | + $recurring_discount = 0; |
|
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ( $invoice->get_items() as $item ) { |
|
167 | 167 | |
168 | - // Abort if it is not valid for this item. |
|
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
170 | - continue; |
|
171 | - } |
|
168 | + // Abort if it is not valid for this item. |
|
169 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
170 | + continue; |
|
171 | + } |
|
172 | 172 | |
173 | - // Calculate the initial amount... |
|
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
175 | - $recurring_item_discount = 0; |
|
173 | + // Calculate the initial amount... |
|
174 | + $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
175 | + $recurring_item_discount = 0; |
|
176 | 176 | |
177 | - // ... and maybe the recurring amount. |
|
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
180 | - } |
|
177 | + // ... and maybe the recurring amount. |
|
178 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
180 | + } |
|
181 | 181 | |
182 | - // Discount should not exceed discounted amount. |
|
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
182 | + // Discount should not exceed discounted amount. |
|
183 | + if ( ! $discount->is_type( 'percent' ) ) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
186 | - $item_discount = $discount->get_amount() - $initial_discount; |
|
187 | - } |
|
185 | + if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
186 | + $item_discount = $discount->get_amount() - $initial_discount; |
|
187 | + } |
|
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
190 | - $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
191 | - } |
|
189 | + if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
190 | + $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | - $initial_discount += $item_discount; |
|
195 | - $recurring_discount += $recurring_item_discount; |
|
196 | - $item->item_discount = $item_discount; |
|
197 | - $item->recurring_item_discount = $recurring_item_discount; |
|
194 | + $initial_discount += $item_discount; |
|
195 | + $recurring_discount += $recurring_item_discount; |
|
196 | + $item->item_discount = $item_discount; |
|
197 | + $item->recurring_item_discount = $recurring_item_discount; |
|
198 | 198 | |
199 | - } |
|
199 | + } |
|
200 | 200 | |
201 | - return array( |
|
202 | - 'name' => 'discount_code', |
|
203 | - 'discount_code' => $discount->get_code(), |
|
204 | - 'initial_discount' => $initial_discount, |
|
205 | - 'recurring_discount' => $recurring_discount, |
|
206 | - ); |
|
201 | + return array( |
|
202 | + 'name' => 'discount_code', |
|
203 | + 'discount_code' => $discount->get_code(), |
|
204 | + 'initial_discount' => $initial_discount, |
|
205 | + 'recurring_discount' => $recurring_discount, |
|
206 | + ); |
|
207 | 207 | |
208 | 208 | } |
209 | 209 |
@@ -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 | * Returns an array of discount type. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | return apply_filters( |
18 | 18 | 'wpinv_discount_types', |
19 | 19 | array( |
20 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
21 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
20 | + 'percent' => __('Percentage', 'invoicing'), |
|
21 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ); |
24 | 24 | } |
@@ -28,46 +28,46 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
31 | +function wpinv_get_discount_type_name($type = '') { |
|
32 | 32 | $types = wpinv_get_discount_types(); |
33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type; |
|
33 | + return isset($types[$type]) ? $types[$type] : $type; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Deletes a discount via the admin page. |
38 | 38 | * |
39 | 39 | */ |
40 | -function wpinv_delete_discount( $data ) { |
|
40 | +function wpinv_delete_discount($data) { |
|
41 | 41 | |
42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
43 | - $discount->delete( true ); |
|
42 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
43 | + $discount->delete(true); |
|
44 | 44 | |
45 | 45 | } |
46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' ); |
|
46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Deactivates a discount via the admin page. |
50 | 50 | */ |
51 | -function wpinv_activate_discount( $data ) { |
|
51 | +function wpinv_activate_discount($data) { |
|
52 | 52 | |
53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
54 | - $discount->set_status( 'publish' ); |
|
53 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
54 | + $discount->set_status('publish'); |
|
55 | 55 | $discount->save(); |
56 | 56 | |
57 | 57 | } |
58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' ); |
|
58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Activates a discount via the admin page. |
62 | 62 | */ |
63 | -function wpinv_deactivate_discount( $data ) { |
|
63 | +function wpinv_deactivate_discount($data) { |
|
64 | 64 | |
65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
66 | - $discount->set_status( 'pending' ); |
|
65 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
66 | + $discount->set_status('pending'); |
|
67 | 67 | $discount->save(); |
68 | 68 | |
69 | 69 | } |
70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Fetches a discount object. |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @since 1.0.15 |
77 | 77 | * @return WPInv_Discount |
78 | 78 | */ |
79 | -function wpinv_get_discount( $discount ) { |
|
80 | - return new WPInv_Discount( $discount ); |
|
79 | +function wpinv_get_discount($discount) { |
|
80 | + return new WPInv_Discount($discount); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @since 1.0.15 |
88 | 88 | * @return WPInv_Discount |
89 | 89 | */ |
90 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
91 | - return new WPInv_Discount( $discount ); |
|
90 | +function wpinv_get_discount_obj($discount = 0) { |
|
91 | + return new WPInv_Discount($discount); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | * @param string|int $value The field value |
99 | 99 | * @return bool|WPInv_Discount |
100 | 100 | */ |
101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
102 | - $discount = new WPInv_Discount( $value ); |
|
101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
102 | + $discount = new WPInv_Discount($value); |
|
103 | 103 | |
104 | - if ( $discount->get_id() != 0 ) { |
|
104 | + if ($discount->get_id() != 0) { |
|
105 | 105 | return $discount; |
106 | 106 | } |
107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | function wpinv_get_discount_statuses() { |
117 | 117 | |
118 | 118 | return array( |
119 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
120 | - 'publish' => __( 'Active', 'invoicing' ), |
|
121 | - 'inactive' => __( 'Inactive', 'invoicing' ), |
|
119 | + 'expired' => __('Expired', 'invoicing'), |
|
120 | + 'publish' => __('Active', 'invoicing'), |
|
121 | + 'inactive' => __('Inactive', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | 124 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * Retrieves an invoice status label. |
128 | 128 | */ |
129 | -function wpinv_discount_status( $status ) { |
|
129 | +function wpinv_discount_status($status) { |
|
130 | 130 | $statuses = wpinv_get_discount_statuses(); |
131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' ); |
|
131 | + return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
139 | 139 | * @return bool |
140 | 140 | */ |
141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
142 | 142 | |
143 | - if ( ! empty( $discount ) ) { |
|
144 | - $discount = wpinv_get_discount_obj( $discount ); |
|
143 | + if (!empty($discount)) { |
|
144 | + $discount = wpinv_get_discount_obj($discount); |
|
145 | 145 | } else { |
146 | - $discount = wpinv_get_discount_obj( $code ); |
|
146 | + $discount = wpinv_get_discount_obj($code); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $discount->get_is_recurring(); |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | * @param WPInv_Discount $discount |
159 | 159 | * @return array |
160 | 160 | */ |
161 | -function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
|
161 | +function getpaid_calculate_invoice_discount($invoice, $discount) { |
|
162 | 162 | |
163 | 163 | $initial_discount = 0; |
164 | 164 | $recurring_discount = 0; |
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ($invoice->get_items() as $item) { |
|
167 | 167 | |
168 | 168 | // Abort if it is not valid for this item. |
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
169 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Calculate the initial amount... |
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
174 | + $item_discount = $discount->get_discounted_amount($item->get_sub_total()); |
|
175 | 175 | $recurring_item_discount = 0; |
176 | 176 | |
177 | 177 | // ... and maybe the recurring amount. |
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
178 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Discount should not exceed discounted amount. |
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
183 | + if (!$discount->is_type('percent')) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
185 | + if (($initial_discount + $item_discount) > $discount->get_amount()) { |
|
186 | 186 | $item_discount = $discount->get_amount() - $initial_discount; |
187 | 187 | } |
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
189 | + if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) { |
|
190 | 190 | $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
191 | 191 | } |
192 | 192 | } |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | array( |
219 | 219 | 'post_type' => 'wpi_discount', |
220 | 220 | 'numberposts' => 1, |
221 | - 'fields' => array( 'ids' ), |
|
221 | + 'fields' => array('ids'), |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | |
225 | - return ! empty( $discounts ); |
|
225 | + return !empty($discounts); |
|
226 | 226 | |
227 | 227 | } |
@@ -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( $value ); |
|
29 | + if ('id' === strtolower($field)) { |
|
30 | + return wpinv_get_item_by_id($value); |
|
31 | 31 | } |
32 | 32 | |
33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
34 | - return empty( $id ) ? false : wpinv_get_item( $id ); |
|
33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
34 | + return empty($id) ? false : wpinv_get_item($id); |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
@@ -41,24 +41,24 @@ 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->exists() ? $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 | 57 | $args = wp_parse_args( |
58 | 58 | $args, |
59 | 59 | array( |
60 | - 'status' => array( 'publish' ), |
|
61 | - 'limit' => get_option( 'posts_per_page' ), |
|
60 | + 'status' => array('publish'), |
|
61 | + 'limit' => get_option('posts_per_page'), |
|
62 | 62 | 'page' => 1, |
63 | 63 | 'exclude' => array(), |
64 | 64 | 'orderby' => 'date', |
@@ -78,44 +78,44 @@ discard block |
||
78 | 78 | 'fields' => 'ids', |
79 | 79 | 'orderby' => $args['orderby'], |
80 | 80 | 'order' => $args['order'], |
81 | - 'paged' => absint( $args['page'] ), |
|
81 | + 'paged' => absint($args['page']), |
|
82 | 82 | ); |
83 | 83 | |
84 | - if ( ! empty( $args['exclude'] ) ) { |
|
85 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
84 | + if (!empty($args['exclude'])) { |
|
85 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
86 | 86 | } |
87 | 87 | |
88 | - if ( ! $args['paginate'] ) { |
|
88 | + if (!$args['paginate']) { |
|
89 | 89 | $wp_query_args['no_found_rows'] = true; |
90 | 90 | } |
91 | 91 | |
92 | - if ( ! empty( $args['search'] ) ) { |
|
92 | + if (!empty($args['search'])) { |
|
93 | 93 | $wp_query_args['s'] = $args['search']; |
94 | 94 | } |
95 | 95 | |
96 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
97 | - $types = wpinv_parse_list( $args['type'] ); |
|
96 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
97 | + $types = wpinv_parse_list($args['type']); |
|
98 | 98 | $wp_query_args['meta_query'][] = array( |
99 | 99 | 'key' => '_wpinv_type', |
100 | - 'value' => implode( ',', $types ), |
|
100 | + 'value' => implode(',', $types), |
|
101 | 101 | 'compare' => 'IN', |
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - $wp_query_args = apply_filters( 'wpinv_get_items_args', $wp_query_args, $args ); |
|
105 | + $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
|
106 | 106 | |
107 | 107 | // Get results. |
108 | - $items = new WP_Query( $wp_query_args ); |
|
108 | + $items = new WP_Query($wp_query_args); |
|
109 | 109 | |
110 | - if ( 'objects' === $args['return'] ) { |
|
111 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
112 | - } elseif ( 'self' === $args['return'] ) { |
|
110 | + if ('objects' === $args['return']) { |
|
111 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
112 | + } elseif ('self' === $args['return']) { |
|
113 | 113 | return $items; |
114 | 114 | } else { |
115 | 115 | $return = $items->posts; |
116 | 116 | } |
117 | 117 | |
118 | - if ( $args['paginate'] ) { |
|
118 | + if ($args['paginate']) { |
|
119 | 119 | return (object) array( |
120 | 120 | 'items' => $return, |
121 | 121 | 'total' => $items->found_posts, |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
131 | - if ( empty( $item_id ) ) { |
|
130 | +function wpinv_is_free_item($item_id = 0) { |
|
131 | + if (empty($item_id)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - $item = new WPInv_Item( $item_id ); |
|
135 | + $item = new WPInv_Item($item_id); |
|
136 | 136 | |
137 | 137 | return $item->is_free(); |
138 | 138 | } |
@@ -142,21 +142,21 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
144 | 144 | */ |
145 | -function wpinv_item_is_editable( $item = 0 ) { |
|
145 | +function wpinv_item_is_editable($item = 0) { |
|
146 | 146 | |
147 | 147 | // Fetch the item. |
148 | - $item = new WPInv_Item( $item ); |
|
148 | + $item = new WPInv_Item($item); |
|
149 | 149 | |
150 | 150 | // Check if it is editable. |
151 | 151 | return $item->is_editable(); |
152 | 152 | } |
153 | 153 | |
154 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
155 | - if ( empty( $item_id ) ) { |
|
154 | +function wpinv_get_item_price($item_id = 0) { |
|
155 | + if (empty($item_id)) { |
|
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | |
159 | - $item = new WPInv_Item( $item_id ); |
|
159 | + $item = new WPInv_Item($item_id); |
|
160 | 160 | |
161 | 161 | return $item->get_price(); |
162 | 162 | } |
@@ -166,88 +166,88 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @param WPInv_Item|int $item |
168 | 168 | */ |
169 | -function wpinv_is_recurring_item( $item = 0 ) { |
|
170 | - $item = new WPInv_Item( $item ); |
|
169 | +function wpinv_is_recurring_item($item = 0) { |
|
170 | + $item = new WPInv_Item($item); |
|
171 | 171 | return $item->is_recurring(); |
172 | 172 | } |
173 | 173 | |
174 | -function wpinv_item_price( $item_id = 0 ) { |
|
175 | - if ( empty( $item_id ) ) { |
|
174 | +function wpinv_item_price($item_id = 0) { |
|
175 | + if (empty($item_id)) { |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - $price = wpinv_get_item_price( $item_id ); |
|
180 | - $price = wpinv_price( $price ); |
|
179 | + $price = wpinv_get_item_price($item_id); |
|
180 | + $price = wpinv_price($price); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
182 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
183 | 183 | } |
184 | 184 | |
185 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
186 | - if ( is_null( $amount_override ) ) { |
|
187 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
185 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
186 | + if (is_null($amount_override)) { |
|
187 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
188 | 188 | } else { |
189 | 189 | $original_price = $amount_override; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $price = $original_price; |
193 | 193 | |
194 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
194 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
198 | - if ( empty( $item_id ) ) { |
|
197 | +function wpinv_item_custom_singular_name($item_id) { |
|
198 | + if (empty($item_id)) { |
|
199 | 199 | return false; |
200 | 200 | } |
201 | 201 | |
202 | - $item = new WPInv_Item( $item_id ); |
|
202 | + $item = new WPInv_Item($item_id); |
|
203 | 203 | |
204 | 204 | return $item->get_custom_singular_name(); |
205 | 205 | } |
206 | 206 | |
207 | 207 | function wpinv_get_item_types() { |
208 | 208 | $item_types = array( |
209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
209 | + 'custom' => __('Standard', 'invoicing'), |
|
210 | + 'fee' => __('Fee', 'invoicing'), |
|
211 | 211 | ); |
212 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
212 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | function wpinv_item_types() { |
216 | 216 | $item_types = wpinv_get_item_types(); |
217 | 217 | |
218 | - return ( ! empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
218 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
219 | 219 | } |
220 | 220 | |
221 | -function wpinv_get_item_type( $item_id ) { |
|
222 | - if ( empty( $item_id ) ) { |
|
221 | +function wpinv_get_item_type($item_id) { |
|
222 | + if (empty($item_id)) { |
|
223 | 223 | return false; |
224 | 224 | } |
225 | 225 | |
226 | - $item = new WPInv_Item( $item_id ); |
|
226 | + $item = new WPInv_Item($item_id); |
|
227 | 227 | |
228 | 228 | return $item->get_type(); |
229 | 229 | } |
230 | 230 | |
231 | -function wpinv_item_type( $item_id ) { |
|
231 | +function wpinv_item_type($item_id) { |
|
232 | 232 | $item_types = wpinv_get_item_types(); |
233 | 233 | |
234 | - $item_type = wpinv_get_item_type( $item_id ); |
|
234 | + $item_type = wpinv_get_item_type($item_id); |
|
235 | 235 | |
236 | - if ( empty( $item_type ) ) { |
|
236 | + if (empty($item_type)) { |
|
237 | 237 | $item_type = '-'; |
238 | 238 | } |
239 | 239 | |
240 | - $item_type = isset( $item_types[ $item_type ] ) ? $item_types[ $item_type ] : __( $item_type, 'invoicing' ); |
|
240 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
241 | 241 | |
242 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
242 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
243 | 243 | } |
244 | 244 | |
245 | -function wpinv_get_random_item( $post_ids = true ) { |
|
246 | - wpinv_get_random_items( 1, $post_ids ); |
|
245 | +function wpinv_get_random_item($post_ids = true) { |
|
246 | + wpinv_get_random_items(1, $post_ids); |
|
247 | 247 | } |
248 | 248 | |
249 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
250 | - if ( $post_ids ) { |
|
249 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
250 | + if ($post_ids) { |
|
251 | 251 | $args = array( |
252 | 252 | 'post_type' => 'wpi_item', |
253 | 253 | 'orderby' => 'rand', |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
265 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
266 | 266 | |
267 | - return get_posts( $args ); |
|
267 | + return get_posts($args); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | * @param WPInv_Item|int $item |
274 | 274 | * @param bool $html |
275 | 275 | */ |
276 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
276 | +function wpinv_get_item_suffix($item, $html = true) { |
|
277 | 277 | |
278 | - $item = new WPInv_Item( $item ); |
|
279 | - $suffix = $item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : ''; |
|
280 | - $suffix = $html ? $suffix : wp_strip_all_tags( $suffix ); |
|
278 | + $item = new WPInv_Item($item); |
|
279 | + $suffix = $item->is_recurring() ? ' ' . __('(r)', 'invoicing') : ''; |
|
280 | + $suffix = $html ? $suffix : wp_strip_all_tags($suffix); |
|
281 | 281 | |
282 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
282 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -288,9 +288,9 @@ discard block |
||
288 | 288 | * @param WPInv_Item|int $item |
289 | 289 | * @param bool $force_delete |
290 | 290 | */ |
291 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
292 | - $item = new WPInv_Item( $item ); |
|
293 | - $item->delete( $force_delete ); |
|
291 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
292 | + $item = new WPInv_Item($item); |
|
293 | + $item->delete($force_delete); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -329,44 +329,44 @@ discard block |
||
329 | 329 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
330 | 330 | * @return bool|WP_Error|WPInv_Item |
331 | 331 | */ |
332 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
332 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
333 | 333 | |
334 | 334 | // Prepare the item. |
335 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
336 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
337 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
335 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
336 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
337 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
338 | 338 | |
339 | - if ( ! empty( $item ) ) { |
|
339 | + if (!empty($item)) { |
|
340 | 340 | $args['ID'] = $item->get_id(); |
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Do we have an item? |
345 | - if ( ! empty( $args['ID'] ) ) { |
|
346 | - $item = new WPInv_Item( $args['ID'] ); |
|
345 | + if (!empty($args['ID'])) { |
|
346 | + $item = new WPInv_Item($args['ID']); |
|
347 | 347 | } else { |
348 | 348 | $item = new WPInv_Item(); |
349 | 349 | } |
350 | 350 | |
351 | 351 | // Do we have an error? |
352 | - if ( ! empty( $item->last_error ) ) { |
|
353 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
352 | + if (!empty($item->last_error)) { |
|
353 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // Update item props. |
357 | - $item->set_props( $args ); |
|
357 | + $item->set_props($args); |
|
358 | 358 | |
359 | 359 | // Save the item. |
360 | 360 | $item->save(); |
361 | 361 | |
362 | 362 | // Do we have an error? |
363 | - if ( ! empty( $item->last_error ) ) { |
|
364 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
363 | + if (!empty($item->last_error)) { |
|
364 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | // Was the item saved? |
368 | - if ( ! $item->get_id() ) { |
|
369 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
368 | + if (!$item->get_id()) { |
|
369 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $item; |
@@ -378,14 +378,14 @@ discard block |
||
378 | 378 | * |
379 | 379 | * @see wpinv_create_item() |
380 | 380 | */ |
381 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
382 | - return wpinv_create_item( $args, $wp_error ); |
|
381 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
382 | + return wpinv_create_item($args, $wp_error); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
386 | 386 | * Sanitizes a recurring period |
387 | 387 | */ |
388 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
388 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
389 | 389 | |
390 | 390 | $periods = array( |
391 | 391 | 'D' => 'day', |
@@ -394,16 +394,16 @@ discard block |
||
394 | 394 | 'Y' => 'year', |
395 | 395 | ); |
396 | 396 | |
397 | - if ( ! isset( $periods[ $period ] ) ) { |
|
397 | + if (!isset($periods[$period])) { |
|
398 | 398 | $period = 'D'; |
399 | 399 | } |
400 | 400 | |
401 | - return $full ? $periods[ $period ] : $period; |
|
401 | + return $full ? $periods[$period] : $period; |
|
402 | 402 | |
403 | 403 | } |
404 | 404 | |
405 | -function wpinv_item_max_buyable_quantity( $item_id ) { |
|
406 | - return apply_filters( 'wpinv_item_max_buyable_quantity', 5, $item_id ); |
|
405 | +function wpinv_item_max_buyable_quantity($item_id) { |
|
406 | + return apply_filters('wpinv_item_max_buyable_quantity', 5, $item_id); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -411,47 +411,47 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @param WPInv_Item|GetPaid_Form_Item $item |
413 | 413 | */ |
414 | -function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
|
414 | +function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) { |
|
415 | 415 | |
416 | 416 | // Abort if it is not recurring. |
417 | - if ( ! $item->is_recurring() ) { |
|
417 | + if (!$item->is_recurring()) { |
|
418 | 418 | return ''; |
419 | 419 | } |
420 | 420 | |
421 | - $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
|
422 | - $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
|
423 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
421 | + $initial_price = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price; |
|
422 | + $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price; |
|
423 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
424 | 424 | $initial_class = 'getpaid-item-initial-price'; |
425 | 425 | $recurring_class = 'getpaid-item-recurring-price'; |
426 | 426 | $bill_times = $item->get_recurring_limit(); |
427 | 427 | $bill_times_less = $bill_times - 1; |
428 | 428 | |
429 | - if ( ! empty( $bill_times ) ) { |
|
429 | + if (!empty($bill_times)) { |
|
430 | 430 | $bill_times = $item->get_recurring_interval() * $bill_times; |
431 | - $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
|
432 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
431 | + $bill_times_less = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times - $item->get_recurring_interval()); |
|
432 | + $bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times); |
|
433 | 433 | } |
434 | 434 | |
435 | - if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
|
436 | - $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
|
437 | - $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
|
435 | + if ($item instanceof GetPaid_Form_Item && false === $_initial_price) { |
|
436 | + $initial_price = wpinv_price($item->get_sub_total(), $currency); |
|
437 | + $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency); |
|
438 | 438 | } |
439 | 439 | |
440 | - if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
|
441 | - return __( 'Free forever', 'invoicing' ); |
|
440 | + if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) { |
|
441 | + return __('Free forever', 'invoicing'); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | // For free trial items. |
445 | - if ( $item->has_free_trial() ) { |
|
446 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
445 | + if ($item->has_free_trial()) { |
|
446 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
447 | 447 | |
448 | - if ( wpinv_price( 0, $currency ) == $initial_price ) { |
|
448 | + if (wpinv_price(0, $currency) == $initial_price) { |
|
449 | 449 | |
450 | - if ( empty( $bill_times ) ) { |
|
450 | + if (empty($bill_times)) { |
|
451 | 451 | |
452 | 452 | return sprintf( |
453 | 453 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
454 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
454 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
455 | 455 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
456 | 456 | "<span class='$recurring_class'>$recurring_price</span>", |
457 | 457 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | |
462 | 462 | return sprintf( |
463 | 463 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times |
464 | - _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
464 | + _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
465 | 465 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
466 | 466 | "<span class='$recurring_class'>$recurring_price</span>", |
467 | 467 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -470,11 +470,11 @@ discard block |
||
470 | 470 | |
471 | 471 | } |
472 | 472 | |
473 | - if ( empty( $bill_times ) ) { |
|
473 | + if (empty($bill_times)) { |
|
474 | 474 | |
475 | 475 | return sprintf( |
476 | 476 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
477 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
477 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
478 | 478 | "<span class='$initial_class'>$initial_price</span>", |
479 | 479 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
480 | 480 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | |
486 | 486 | return sprintf( |
487 | 487 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times |
488 | - _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ), |
|
488 | + _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'), |
|
489 | 489 | "<span class='$initial_class'>$initial_price</span>", |
490 | 490 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
491 | 491 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -495,13 +495,13 @@ discard block |
||
495 | 495 | |
496 | 496 | } |
497 | 497 | |
498 | - if ( $initial_price == $recurring_price ) { |
|
498 | + if ($initial_price == $recurring_price) { |
|
499 | 499 | |
500 | - if ( empty( $bill_times ) ) { |
|
500 | + if (empty($bill_times)) { |
|
501 | 501 | |
502 | 502 | return sprintf( |
503 | 503 | // translators: $1: is the recurring price, $2: is the susbcription period |
504 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
504 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
505 | 505 | "<span class='$recurring_class'>$recurring_price</span>", |
506 | 506 | "<span class='getpaid-item-recurring-period'>$period</span>" |
507 | 507 | ); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | |
511 | 511 | return sprintf( |
512 | 512 | // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times |
513 | - _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
513 | + _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
514 | 514 | "<span class='$recurring_class'>$recurring_price</span>", |
515 | 515 | "<span class='getpaid-item-recurring-period'>$period</span>", |
516 | 516 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -518,13 +518,13 @@ discard block |
||
518 | 518 | |
519 | 519 | } |
520 | 520 | |
521 | - if ( $initial_price == wpinv_price( 0, $currency ) ) { |
|
521 | + if ($initial_price == wpinv_price(0, $currency)) { |
|
522 | 522 | |
523 | - if ( empty( $bill_times ) ) { |
|
523 | + if (empty($bill_times)) { |
|
524 | 524 | |
525 | 525 | return sprintf( |
526 | 526 | // translators: $1: is the recurring period, $2: is the recurring price |
527 | - _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
|
527 | + _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'), |
|
528 | 528 | "<span class='getpaid-item-recurring-period'>$period</span>", |
529 | 529 | "<span class='$recurring_class'>$recurring_price</span>" |
530 | 530 | ); |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | |
534 | 534 | return sprintf( |
535 | 535 | // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times |
536 | - _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ), |
|
536 | + _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'), |
|
537 | 537 | "<span class='getpaid-item-recurring-period'>$period</span>", |
538 | 538 | "<span class='$recurring_class'>$recurring_price</span>", |
539 | 539 | "<span class='getpaid-item-recurring-bill-times'>$bill_times_less</span>" |
@@ -541,11 +541,11 @@ discard block |
||
541 | 541 | |
542 | 542 | } |
543 | 543 | |
544 | - if ( empty( $bill_times ) ) { |
|
544 | + if (empty($bill_times)) { |
|
545 | 545 | |
546 | 546 | return sprintf( |
547 | 547 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
548 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
548 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
549 | 549 | "<span class='$initial_class'>$initial_price</span>", |
550 | 550 | "<span class='$recurring_class'>$recurring_price</span>", |
551 | 551 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | |
556 | 556 | return sprintf( |
557 | 557 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times |
558 | - _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ), |
|
558 | + _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'), |
|
559 | 559 | "<span class='$initial_class'>$initial_price</span>", |
560 | 560 | "<span class='$recurring_class'>$recurring_price</span>", |
561 | 561 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -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,356 +114,356 @@ 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(); |
|
269 | + |
|
270 | + foreach ( $items as $key => $value ) { |
|
271 | + |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
274 | + |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
266 | 278 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
279 | + continue; |
|
269 | 280 | |
270 | - foreach ( $items as $key => $value ) { |
|
281 | + } |
|
271 | 282 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
283 | + // $item_id => $quantity (buy buttons) |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
274 | 286 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
287 | + if ( $item->can_purchase() ) { |
|
278 | 288 | |
279 | - continue; |
|
289 | + $value = (float) $value; |
|
290 | + $item->set_quantity( $value ); |
|
291 | + if ( 0 == $value ) { |
|
292 | + $item->set_quantity( 1 ); |
|
293 | + $item->set_allow_quantities( true ); |
|
294 | + } |
|
280 | 295 | |
281 | - } |
|
296 | + $prepared[] = $item; |
|
297 | + } |
|
282 | 298 | |
283 | - // $item_id => $quantity (buy buttons) |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
299 | + continue; |
|
300 | + } |
|
286 | 301 | |
287 | - if ( $item->can_purchase() ) { |
|
302 | + // Items saved via payment forms editor. |
|
303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
288 | 304 | |
289 | - $value = (float) $value; |
|
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
294 | - } |
|
305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
295 | 306 | |
296 | - $prepared[] = $item; |
|
297 | - } |
|
307 | + if ( ! $item->can_purchase() ) { |
|
308 | + continue; |
|
309 | + } |
|
298 | 310 | |
299 | - continue; |
|
300 | - } |
|
311 | + // Sub-total (Cart items). |
|
312 | + if ( isset( $value['subtotal'] ) ) { |
|
313 | + $item->set_price( $value['subtotal'] ); |
|
314 | + } |
|
301 | 315 | |
302 | - // Items saved via payment forms editor. |
|
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
316 | + if ( isset( $value['quantity'] ) ) { |
|
317 | + $item->set_quantity( $value['quantity'] ); |
|
318 | + } |
|
304 | 319 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | + } |
|
306 | 323 | |
307 | - if ( ! $item->can_purchase() ) { |
|
308 | - continue; |
|
309 | - } |
|
324 | + if ( isset( $value['required'] ) ) { |
|
325 | + $item->set_is_required( $value['required'] ); |
|
326 | + } |
|
310 | 327 | |
311 | - // Sub-total (Cart items). |
|
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
314 | - } |
|
328 | + if ( isset( $value['description'] ) ) { |
|
329 | + $item->set_custom_description( $value['description'] ); |
|
330 | + } |
|
315 | 331 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
318 | - } |
|
332 | + $prepared[] = $item; |
|
333 | + continue; |
|
319 | 334 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | - } |
|
335 | + } |
|
323 | 336 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
326 | - } |
|
337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | + $item = new GetPaid_Form_Item( $key ); |
|
327 | 340 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
330 | - } |
|
341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | + $item->set_price( $value['price'] ); |
|
343 | + } |
|
331 | 344 | |
332 | - $prepared[] = $item; |
|
333 | - continue; |
|
345 | + if ( $item->can_purchase() ) { |
|
346 | + $prepared[] = $item; |
|
347 | + } |
|
334 | 348 | |
335 | - } |
|
336 | - |
|
337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
340 | - |
|
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
343 | - } |
|
344 | - |
|
345 | - if ( $item->can_purchase() ) { |
|
346 | - $prepared[] = $item; |
|
347 | - } |
|
348 | - |
|
349 | - continue; |
|
350 | - } |
|
351 | - } |
|
352 | - |
|
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
354 | - return $prepared; |
|
355 | - } |
|
356 | - |
|
357 | - $items = array(); |
|
358 | - foreach ( $prepared as $item ) { |
|
359 | - $items[] = $item->prepare_data_for_use(); |
|
360 | - } |
|
361 | - |
|
362 | - return $items; |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Get a single item belonging to the form. |
|
367 | - * |
|
368 | - * @since 1.0.19 |
|
369 | - * @param int $item_id The item id to return. |
|
370 | - * @return GetPaid_Form_Item|bool |
|
371 | - */ |
|
372 | - public function get_item( $item_id ) { |
|
373 | - |
|
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | - return false; |
|
376 | - } |
|
377 | - |
|
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
380 | - return $item; |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - return false; |
|
385 | - |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Gets a single element. |
|
390 | - * |
|
391 | - * @since 1.0.19 |
|
392 | - * @param string $element_type The element type to return. |
|
393 | - * @return array|bool |
|
394 | - */ |
|
395 | - public function get_element_type( $element_type ) { |
|
396 | - |
|
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | - return false; |
|
399 | - } |
|
400 | - |
|
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | - |
|
403 | - if ( $element['type'] === $element_type ) { |
|
404 | - return $element; |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - return false; |
|
409 | - |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Get the total amount earned via this form. |
|
414 | - * |
|
415 | - * @since 1.0.19 |
|
416 | - * @param string $context View or edit context. |
|
417 | - * @return float |
|
418 | - */ |
|
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Get the total amount refunded via this form. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - * @param string $context View or edit context. |
|
428 | - * @return float |
|
429 | - */ |
|
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Get the total amount cancelled via this form. |
|
436 | - * |
|
437 | - * @since 1.0.19 |
|
438 | - * @param string $context View or edit context. |
|
439 | - * @return float |
|
440 | - */ |
|
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Get the total amount failed via this form. |
|
447 | - * |
|
448 | - * @since 1.0.19 |
|
449 | - * @param string $context View or edit context. |
|
450 | - * @return float |
|
451 | - */ |
|
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Get the currency. |
|
458 | - * |
|
459 | - * @since 1.0.19 |
|
460 | - * @param string $context View or edit context. |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public function get_currency() { |
|
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | - } |
|
349 | + continue; |
|
350 | + } |
|
351 | + } |
|
352 | + |
|
353 | + if ( 'objects' == $return && 'view' == $context ) { |
|
354 | + return $prepared; |
|
355 | + } |
|
356 | + |
|
357 | + $items = array(); |
|
358 | + foreach ( $prepared as $item ) { |
|
359 | + $items[] = $item->prepare_data_for_use(); |
|
360 | + } |
|
361 | + |
|
362 | + return $items; |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Get a single item belonging to the form. |
|
367 | + * |
|
368 | + * @since 1.0.19 |
|
369 | + * @param int $item_id The item id to return. |
|
370 | + * @return GetPaid_Form_Item|bool |
|
371 | + */ |
|
372 | + public function get_item( $item_id ) { |
|
373 | + |
|
374 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | + return false; |
|
376 | + } |
|
377 | + |
|
378 | + foreach ( $this->get_items() as $item ) { |
|
379 | + if ( $item->get_id() == (int) $item_id ) { |
|
380 | + return $item; |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + return false; |
|
385 | + |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Gets a single element. |
|
390 | + * |
|
391 | + * @since 1.0.19 |
|
392 | + * @param string $element_type The element type to return. |
|
393 | + * @return array|bool |
|
394 | + */ |
|
395 | + public function get_element_type( $element_type ) { |
|
396 | + |
|
397 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | + return false; |
|
399 | + } |
|
400 | + |
|
401 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | + |
|
403 | + if ( $element['type'] === $element_type ) { |
|
404 | + return $element; |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + return false; |
|
409 | + |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Get the total amount earned via this form. |
|
414 | + * |
|
415 | + * @since 1.0.19 |
|
416 | + * @param string $context View or edit context. |
|
417 | + * @return float |
|
418 | + */ |
|
419 | + public function get_earned( $context = 'view' ) { |
|
420 | + return $this->get_prop( 'earned', $context ); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Get the total amount refunded via this form. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + * @param string $context View or edit context. |
|
428 | + * @return float |
|
429 | + */ |
|
430 | + public function get_refunded( $context = 'view' ) { |
|
431 | + return $this->get_prop( 'refunded', $context ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Get the total amount cancelled via this form. |
|
436 | + * |
|
437 | + * @since 1.0.19 |
|
438 | + * @param string $context View or edit context. |
|
439 | + * @return float |
|
440 | + */ |
|
441 | + public function get_cancelled( $context = 'view' ) { |
|
442 | + return $this->get_prop( 'cancelled', $context ); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Get the total amount failed via this form. |
|
447 | + * |
|
448 | + * @since 1.0.19 |
|
449 | + * @param string $context View or edit context. |
|
450 | + * @return float |
|
451 | + */ |
|
452 | + public function get_failed( $context = 'view' ) { |
|
453 | + return $this->get_prop( 'failed', $context ); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Get the currency. |
|
458 | + * |
|
459 | + * @since 1.0.19 |
|
460 | + * @param string $context View or edit context. |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public function get_currency() { |
|
464 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | + } |
|
467 | 467 | |
468 | 468 | /* |
469 | 469 | |-------------------------------------------------------------------------- |
@@ -476,22 +476,22 @@ discard block |
||
476 | 476 | */ |
477 | 477 | |
478 | 478 | /** |
479 | - * Set plugin version when the item was created. |
|
480 | - * |
|
481 | - * @since 1.0.19 |
|
482 | - */ |
|
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
479 | + * Set plugin version when the item was created. |
|
480 | + * |
|
481 | + * @since 1.0.19 |
|
482 | + */ |
|
483 | + public function set_version( $value ) { |
|
484 | + $this->set_prop( 'version', $value ); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Set date when the item was created. |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - * @param string $value Value to set. |
|
488 | + * Set date when the item was created. |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + * @param string $value Value to set. |
|
492 | 492 | * @return bool Whether or not the date was set. |
493 | - */ |
|
494 | - public function set_date_created( $value ) { |
|
493 | + */ |
|
494 | + public function set_date_created( $value ) { |
|
495 | 495 | $date = strtotime( $value ); |
496 | 496 | |
497 | 497 | if ( $date ) { |
@@ -504,13 +504,13 @@ discard block |
||
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
507 | - * Set date when the item was last modified. |
|
508 | - * |
|
509 | - * @since 1.0.19 |
|
510 | - * @param string $value Value to set. |
|
507 | + * Set date when the item was last modified. |
|
508 | + * |
|
509 | + * @since 1.0.19 |
|
510 | + * @param string $value Value to set. |
|
511 | 511 | * @return bool Whether or not the date was set. |
512 | - */ |
|
513 | - public function set_date_modified( $value ) { |
|
512 | + */ |
|
513 | + public function set_date_modified( $value ) { |
|
514 | 514 | $date = strtotime( $value ); |
515 | 515 | |
516 | 516 | if ( $date ) { |
@@ -523,164 +523,164 @@ discard block |
||
523 | 523 | } |
524 | 524 | |
525 | 525 | /** |
526 | - * Set the item name. |
|
527 | - * |
|
528 | - * @since 1.0.19 |
|
529 | - * @param string $value New name. |
|
530 | - */ |
|
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Alias of self::set_name(). |
|
537 | - * |
|
538 | - * @since 1.0.19 |
|
539 | - * @param string $value New name. |
|
540 | - */ |
|
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * Set the owner of the item. |
|
547 | - * |
|
548 | - * @since 1.0.19 |
|
549 | - * @param int $value New author. |
|
550 | - */ |
|
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * Set the form elements. |
|
557 | - * |
|
558 | - * @since 1.0.19 |
|
559 | - * @sinve 2.3.4 Array values sanitized. |
|
560 | - * @param array $value Form elements. |
|
561 | - */ |
|
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
565 | - } |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Sanitize array values. |
|
570 | - * |
|
571 | - * @param $value |
|
572 | - * |
|
573 | - * @return mixed |
|
574 | - */ |
|
575 | - public function sanitize_array_values( $value ) { |
|
576 | - |
|
577 | - // sanitize |
|
578 | - if ( ! empty( $value ) ) { |
|
579 | - |
|
580 | - foreach ( $value as $key => $val_arr ) { |
|
581 | - |
|
582 | - if ( is_array( $val_arr ) ) { |
|
583 | - // check if we have sub array items. |
|
584 | - $sub_arr = array(); |
|
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
589 | - } |
|
590 | - } |
|
591 | - |
|
592 | - // we allow some html in description so we sanitize it separately. |
|
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
594 | - |
|
595 | - // sanitize array elements |
|
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
597 | - |
|
598 | - // add back the description if set |
|
599 | - if ( isset( $val_arr['description'] ) ) { |
|
526 | + * Set the item name. |
|
527 | + * |
|
528 | + * @since 1.0.19 |
|
529 | + * @param string $value New name. |
|
530 | + */ |
|
531 | + public function set_name( $value ) { |
|
532 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Alias of self::set_name(). |
|
537 | + * |
|
538 | + * @since 1.0.19 |
|
539 | + * @param string $value New name. |
|
540 | + */ |
|
541 | + public function set_title( $value ) { |
|
542 | + $this->set_name( $value ); |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * Set the owner of the item. |
|
547 | + * |
|
548 | + * @since 1.0.19 |
|
549 | + * @param int $value New author. |
|
550 | + */ |
|
551 | + public function set_author( $value ) { |
|
552 | + $this->set_prop( 'author', (int) $value ); |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * Set the form elements. |
|
557 | + * |
|
558 | + * @since 1.0.19 |
|
559 | + * @sinve 2.3.4 Array values sanitized. |
|
560 | + * @param array $value Form elements. |
|
561 | + */ |
|
562 | + public function set_elements( $value ) { |
|
563 | + if ( is_array( $value ) ) { |
|
564 | + $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
565 | + } |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Sanitize array values. |
|
570 | + * |
|
571 | + * @param $value |
|
572 | + * |
|
573 | + * @return mixed |
|
574 | + */ |
|
575 | + public function sanitize_array_values( $value ) { |
|
576 | + |
|
577 | + // sanitize |
|
578 | + if ( ! empty( $value ) ) { |
|
579 | + |
|
580 | + foreach ( $value as $key => $val_arr ) { |
|
581 | + |
|
582 | + if ( is_array( $val_arr ) ) { |
|
583 | + // check if we have sub array items. |
|
584 | + $sub_arr = array(); |
|
585 | + foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | + if ( is_array( $val2 ) ) { |
|
587 | + $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | + unset( $val_arr[ $key ][ $key2 ] ); |
|
589 | + } |
|
590 | + } |
|
591 | + |
|
592 | + // we allow some html in description so we sanitize it separately. |
|
593 | + $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
594 | + |
|
595 | + // sanitize array elements |
|
596 | + $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
597 | + |
|
598 | + // add back the description if set |
|
599 | + if ( isset( $val_arr['description'] ) ) { |
|
600 | 600 | $value[ $key ]['description'] = $help_text;} |
601 | 601 | |
602 | - // add back sub array items after its been sanitized. |
|
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
605 | - } |
|
606 | - } |
|
602 | + // add back sub array items after its been sanitized. |
|
603 | + if ( ! empty( $sub_arr ) ) { |
|
604 | + $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
605 | + } |
|
606 | + } |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | |
610 | - return $value; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Set the form items. |
|
615 | - * |
|
616 | - * @since 1.0.19 |
|
617 | - * @param array $value Form elements. |
|
618 | - */ |
|
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Set the total amount earned via this form. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - * @param float $value Amount earned. |
|
630 | - */ |
|
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Set the total amount refunded via this form. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - * @param float $value Amount refunded. |
|
641 | - */ |
|
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Set the total amount cancelled via this form. |
|
649 | - * |
|
650 | - * @since 1.0.19 |
|
651 | - * @param float $value Amount cancelled. |
|
652 | - */ |
|
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Set the total amount failed via this form. |
|
660 | - * |
|
661 | - * @since 1.0.19 |
|
662 | - * @param float $value Amount cancelled. |
|
663 | - */ |
|
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
667 | - } |
|
610 | + return $value; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Set the form items. |
|
615 | + * |
|
616 | + * @since 1.0.19 |
|
617 | + * @param array $value Form elements. |
|
618 | + */ |
|
619 | + public function set_items( $value ) { |
|
620 | + if ( is_array( $value ) ) { |
|
621 | + $this->set_prop( 'items', $value ); |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Set the total amount earned via this form. |
|
627 | + * |
|
628 | + * @since 1.0.19 |
|
629 | + * @param float $value Amount earned. |
|
630 | + */ |
|
631 | + public function set_earned( $value ) { |
|
632 | + $value = max( (float) $value, 0 ); |
|
633 | + $this->set_prop( 'earned', $value ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Set the total amount refunded via this form. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + * @param float $value Amount refunded. |
|
641 | + */ |
|
642 | + public function set_refunded( $value ) { |
|
643 | + $value = max( (float) $value, 0 ); |
|
644 | + $this->set_prop( 'refunded', $value ); |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Set the total amount cancelled via this form. |
|
649 | + * |
|
650 | + * @since 1.0.19 |
|
651 | + * @param float $value Amount cancelled. |
|
652 | + */ |
|
653 | + public function set_cancelled( $value ) { |
|
654 | + $value = max( (float) $value, 0 ); |
|
655 | + $this->set_prop( 'cancelled', $value ); |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * Set the total amount failed via this form. |
|
660 | + * |
|
661 | + * @since 1.0.19 |
|
662 | + * @param float $value Amount cancelled. |
|
663 | + */ |
|
664 | + public function set_failed( $value ) { |
|
665 | + $value = max( (float) $value, 0 ); |
|
666 | + $this->set_prop( 'failed', $value ); |
|
667 | + } |
|
668 | 668 | |
669 | 669 | /** |
670 | 670 | * Create an item. For backwards compatibilty. |
671 | 671 | * |
672 | 672 | * @deprecated |
673 | - * @return int item id |
|
673 | + * @return int item id |
|
674 | 674 | */ |
675 | 675 | public function create( $data = array() ) { |
676 | 676 | |
677 | - // Set the properties. |
|
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
680 | - } |
|
677 | + // Set the properties. |
|
678 | + if ( is_array( $data ) ) { |
|
679 | + $this->set_props( $data ); |
|
680 | + } |
|
681 | 681 | |
682 | - // Save the item. |
|
683 | - return $this->save(); |
|
682 | + // Save the item. |
|
683 | + return $this->save(); |
|
684 | 684 | |
685 | 685 | } |
686 | 686 | |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | * Updates an item. For backwards compatibilty. |
689 | 689 | * |
690 | 690 | * @deprecated |
691 | - * @return int item id |
|
691 | + * @return int item id |
|
692 | 692 | */ |
693 | 693 | public function update( $data = array() ) { |
694 | 694 | return $this->create( $data ); |
@@ -704,22 +704,22 @@ discard block |
||
704 | 704 | */ |
705 | 705 | |
706 | 706 | /** |
707 | - * Checks whether this is the default payment form. |
|
708 | - * |
|
709 | - * @since 1.0.19 |
|
710 | - * @return bool |
|
711 | - */ |
|
707 | + * Checks whether this is the default payment form. |
|
708 | + * |
|
709 | + * @since 1.0.19 |
|
710 | + * @return bool |
|
711 | + */ |
|
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | 714 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
715 | - } |
|
715 | + } |
|
716 | 716 | |
717 | 717 | /** |
718 | - * Checks whether the form is active. |
|
719 | - * |
|
720 | - * @since 1.0.19 |
|
721 | - * @return bool |
|
722 | - */ |
|
718 | + * Checks whether the form is active. |
|
719 | + * |
|
720 | + * @since 1.0.19 |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
@@ -728,81 +728,81 @@ discard block |
||
728 | 728 | } |
729 | 729 | |
730 | 730 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Checks whether the form has a given item. |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
737 | - * @return bool |
|
738 | - */ |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Checks whether the form has a given item. |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | + * @return bool |
|
738 | + */ |
|
739 | 739 | public function has_item( $item_id ) { |
740 | 740 | return false !== $this->get_item( $item_id ); |
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Checks whether the form has a given element. |
|
745 | - * |
|
746 | - * @since 1.0.19 |
|
747 | - * @return bool |
|
748 | - */ |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Checks whether the form has a given element. |
|
745 | + * |
|
746 | + * @since 1.0.19 |
|
747 | + * @return bool |
|
748 | + */ |
|
749 | 749 | public function has_element_type( $element_type ) { |
750 | 750 | return false !== $this->get_element_type( $element_type ); |
751 | - } |
|
752 | - |
|
753 | - /** |
|
754 | - * Checks whether this form is recurring or not. |
|
755 | - * |
|
756 | - * @since 1.0.19 |
|
757 | - * @return bool |
|
758 | - */ |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * Checks whether this form is recurring or not. |
|
755 | + * |
|
756 | + * @since 1.0.19 |
|
757 | + * @return bool |
|
758 | + */ |
|
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
762 | - return $this->invoice->is_recurring(); |
|
763 | - } |
|
761 | + if ( ! empty( $this->invoice ) ) { |
|
762 | + return $this->invoice->is_recurring(); |
|
763 | + } |
|
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ( $this->get_items() as $item ) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
768 | - return true; |
|
769 | - } |
|
767 | + if ( $item->is_recurring() ) { |
|
768 | + return true; |
|
769 | + } |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | return false; |
773 | - } |
|
773 | + } |
|
774 | 774 | |
775 | - /** |
|
776 | - * Retrieves the form's html. |
|
777 | - * |
|
778 | - * @since 1.0.19 |
|
779 | - */ |
|
775 | + /** |
|
776 | + * Retrieves the form's html. |
|
777 | + * |
|
778 | + * @since 1.0.19 |
|
779 | + */ |
|
780 | 780 | public function get_html( $extra_markup = '' ) { |
781 | 781 | |
782 | - // Return the HTML. |
|
783 | - return wpinv_get_template_html( |
|
784 | - 'payment-forms/form.php', |
|
785 | - array( |
|
786 | - 'form' => $this, |
|
787 | - 'extra_markup' => $extra_markup, |
|
788 | - ) |
|
789 | - ); |
|
790 | - |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * Displays the payment form. |
|
795 | - * |
|
796 | - * @since 1.0.19 |
|
797 | - */ |
|
782 | + // Return the HTML. |
|
783 | + return wpinv_get_template_html( |
|
784 | + 'payment-forms/form.php', |
|
785 | + array( |
|
786 | + 'form' => $this, |
|
787 | + 'extra_markup' => $extra_markup, |
|
788 | + ) |
|
789 | + ); |
|
790 | + |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * Displays the payment form. |
|
795 | + * |
|
796 | + * @since 1.0.19 |
|
797 | + */ |
|
798 | 798 | public function display( $extra_markup = '' ) { |
799 | - wpinv_get_template( |
|
800 | - 'payment-forms/form.php', |
|
801 | - array( |
|
802 | - 'form' => $this, |
|
803 | - 'extra_markup' => $extra_markup, |
|
804 | - ) |
|
805 | - ); |
|
799 | + wpinv_get_template( |
|
800 | + 'payment-forms/form.php', |
|
801 | + array( |
|
802 | + 'form' => $this, |
|
803 | + 'extra_markup' => $extra_markup, |
|
804 | + ) |
|
805 | + ); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | } |
@@ -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,16 +281,16 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity (buy buttons) |
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() ) { |
|
287 | + if ($item->can_purchase()) { |
|
288 | 288 | |
289 | 289 | $value = (float) $value; |
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
290 | + $item->set_quantity($value); |
|
291 | + if (0 == $value) { |
|
292 | + $item->set_quantity(1); |
|
293 | + $item->set_allow_quantities(true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Items saved via payment forms editor. |
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
303 | + if (is_array($value) && isset($value['id'])) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item($value['id']); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
307 | + if (!$item->can_purchase()) { |
|
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Sub-total (Cart items). |
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
312 | + if (isset($value['subtotal'])) { |
|
313 | + $item->set_price($value['subtotal']); |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
316 | + if (isset($value['quantity'])) { |
|
317 | + $item->set_quantity($value['quantity']); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
320 | + if (isset($value['allow_quantities'])) { |
|
321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
324 | + if (isset($value['required'])) { |
|
325 | + $item->set_is_required($value['required']); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
328 | + if (isset($value['description'])) { |
|
329 | + $item->set_custom_description($value['description']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
338 | + if (is_numeric($key) && is_array($value)) { |
|
339 | + $item = new GetPaid_Form_Item($key); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
342 | + $item->set_price($value['price']); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
345 | + if ($item->can_purchase()) { |
|
346 | 346 | $prepared[] = $item; |
347 | 347 | } |
348 | 348 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
353 | + if ('objects' == $return && 'view' == $context) { |
|
354 | 354 | return $prepared; |
355 | 355 | } |
356 | 356 | |
357 | 357 | $items = array(); |
358 | - foreach ( $prepared as $item ) { |
|
358 | + foreach ($prepared as $item) { |
|
359 | 359 | $items[] = $item->prepare_data_for_use(); |
360 | 360 | } |
361 | 361 | |
@@ -369,14 +369,14 @@ discard block |
||
369 | 369 | * @param int $item_id The item id to return. |
370 | 370 | * @return GetPaid_Form_Item|bool |
371 | 371 | */ |
372 | - public function get_item( $item_id ) { |
|
372 | + public function get_item($item_id) { |
|
373 | 373 | |
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
374 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
378 | + foreach ($this->get_items() as $item) { |
|
379 | + if ($item->get_id() == (int) $item_id) { |
|
380 | 380 | return $item; |
381 | 381 | } |
382 | 382 | } |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | * @param string $element_type The element type to return. |
393 | 393 | * @return array|bool |
394 | 394 | */ |
395 | - public function get_element_type( $element_type ) { |
|
395 | + public function get_element_type($element_type) { |
|
396 | 396 | |
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
397 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
398 | 398 | return false; |
399 | 399 | } |
400 | 400 | |
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
401 | + foreach ($this->get_prop('elements') as $element) { |
|
402 | 402 | |
403 | - if ( $element['type'] === $element_type ) { |
|
403 | + if ($element['type'] === $element_type) { |
|
404 | 404 | return $element; |
405 | 405 | } |
406 | 406 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return float |
418 | 418 | */ |
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
419 | + public function get_earned($context = 'view') { |
|
420 | + return $this->get_prop('earned', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return float |
429 | 429 | */ |
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
430 | + public function get_refunded($context = 'view') { |
|
431 | + return $this->get_prop('refunded', $context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @param string $context View or edit context. |
439 | 439 | * @return float |
440 | 440 | */ |
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
441 | + public function get_cancelled($context = 'view') { |
|
442 | + return $this->get_prop('cancelled', $context); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | * @param string $context View or edit context. |
450 | 450 | * @return float |
451 | 451 | */ |
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
452 | + public function get_failed($context = 'view') { |
|
453 | + return $this->get_prop('failed', $context); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | * @return string |
462 | 462 | */ |
463 | 463 | public function get_currency() { |
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
464 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /* |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @since 1.0.19 |
482 | 482 | */ |
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
483 | + public function set_version($value) { |
|
484 | + $this->set_prop('version', $value); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @param string $value Value to set. |
492 | 492 | * @return bool Whether or not the date was set. |
493 | 493 | */ |
494 | - public function set_date_created( $value ) { |
|
495 | - $date = strtotime( $value ); |
|
494 | + public function set_date_created($value) { |
|
495 | + $date = strtotime($value); |
|
496 | 496 | |
497 | - if ( $date ) { |
|
498 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
497 | + if ($date) { |
|
498 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
499 | 499 | return true; |
500 | 500 | } |
501 | 501 | |
@@ -510,11 +510,11 @@ discard block |
||
510 | 510 | * @param string $value Value to set. |
511 | 511 | * @return bool Whether or not the date was set. |
512 | 512 | */ |
513 | - public function set_date_modified( $value ) { |
|
514 | - $date = strtotime( $value ); |
|
513 | + public function set_date_modified($value) { |
|
514 | + $date = strtotime($value); |
|
515 | 515 | |
516 | - if ( $date ) { |
|
517 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
516 | + if ($date) { |
|
517 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
518 | 518 | return true; |
519 | 519 | } |
520 | 520 | |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | * @since 1.0.19 |
529 | 529 | * @param string $value New name. |
530 | 530 | */ |
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
531 | + public function set_name($value) { |
|
532 | + $this->set_prop('name', sanitize_text_field($value)); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @since 1.0.19 |
539 | 539 | * @param string $value New name. |
540 | 540 | */ |
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
541 | + public function set_title($value) { |
|
542 | + $this->set_name($value); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | * @since 1.0.19 |
549 | 549 | * @param int $value New author. |
550 | 550 | */ |
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
551 | + public function set_author($value) { |
|
552 | + $this->set_prop('author', (int) $value); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -559,9 +559,9 @@ discard block |
||
559 | 559 | * @sinve 2.3.4 Array values sanitized. |
560 | 560 | * @param array $value Form elements. |
561 | 561 | */ |
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
562 | + public function set_elements($value) { |
|
563 | + if (is_array($value)) { |
|
564 | + $this->set_prop('elements', wp_kses_post_deep($value)); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -572,36 +572,36 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return mixed |
574 | 574 | */ |
575 | - public function sanitize_array_values( $value ) { |
|
575 | + public function sanitize_array_values($value) { |
|
576 | 576 | |
577 | 577 | // sanitize |
578 | - if ( ! empty( $value ) ) { |
|
578 | + if (!empty($value)) { |
|
579 | 579 | |
580 | - foreach ( $value as $key => $val_arr ) { |
|
580 | + foreach ($value as $key => $val_arr) { |
|
581 | 581 | |
582 | - if ( is_array( $val_arr ) ) { |
|
582 | + if (is_array($val_arr)) { |
|
583 | 583 | // check if we have sub array items. |
584 | 584 | $sub_arr = array(); |
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
585 | + foreach ($val_arr as $key2 => $val2) { |
|
586 | + if (is_array($val2)) { |
|
587 | + $sub_arr[$key2] = $this->sanitize_array_values($val2); |
|
588 | + unset($val_arr[$key][$key2]); |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | |
592 | 592 | // we allow some html in description so we sanitize it separately. |
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
593 | + $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
|
594 | 594 | |
595 | 595 | // sanitize array elements |
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
596 | + $value[$key] = array_map('sanitize_text_field', $val_arr); |
|
597 | 597 | |
598 | 598 | // add back the description if set |
599 | - if ( isset( $val_arr['description'] ) ) { |
|
600 | -$value[ $key ]['description'] = $help_text;} |
|
599 | + if (isset($val_arr['description'])) { |
|
600 | +$value[$key]['description'] = $help_text; } |
|
601 | 601 | |
602 | 602 | // add back sub array items after its been sanitized. |
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
603 | + if (!empty($sub_arr)) { |
|
604 | + $value[$key] = array_merge($value[$key], $sub_arr); |
|
605 | 605 | } |
606 | 606 | } |
607 | 607 | } |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | * @since 1.0.19 |
617 | 617 | * @param array $value Form elements. |
618 | 618 | */ |
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
619 | + public function set_items($value) { |
|
620 | + if (is_array($value)) { |
|
621 | + $this->set_prop('items', $value); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -628,9 +628,9 @@ discard block |
||
628 | 628 | * @since 1.0.19 |
629 | 629 | * @param float $value Amount earned. |
630 | 630 | */ |
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
631 | + public function set_earned($value) { |
|
632 | + $value = max((float) $value, 0); |
|
633 | + $this->set_prop('earned', $value); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -639,9 +639,9 @@ discard block |
||
639 | 639 | * @since 1.0.19 |
640 | 640 | * @param float $value Amount refunded. |
641 | 641 | */ |
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
642 | + public function set_refunded($value) { |
|
643 | + $value = max((float) $value, 0); |
|
644 | + $this->set_prop('refunded', $value); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | * @since 1.0.19 |
651 | 651 | * @param float $value Amount cancelled. |
652 | 652 | */ |
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
653 | + public function set_cancelled($value) { |
|
654 | + $value = max((float) $value, 0); |
|
655 | + $this->set_prop('cancelled', $value); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | * @since 1.0.19 |
662 | 662 | * @param float $value Amount cancelled. |
663 | 663 | */ |
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
664 | + public function set_failed($value) { |
|
665 | + $value = max((float) $value, 0); |
|
666 | + $this->set_prop('failed', $value); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,11 +672,11 @@ discard block |
||
672 | 672 | * @deprecated |
673 | 673 | * @return int item id |
674 | 674 | */ |
675 | - public function create( $data = array() ) { |
|
675 | + public function create($data = array()) { |
|
676 | 676 | |
677 | 677 | // Set the properties. |
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
678 | + if (is_array($data)) { |
|
679 | + $this->set_props($data); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | // Save the item. |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @deprecated |
691 | 691 | * @return int item id |
692 | 692 | */ |
693 | - public function update( $data = array() ) { |
|
694 | - return $this->create( $data ); |
|
693 | + public function update($data = array()) { |
|
694 | + return $this->create($data); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /* |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
714 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -723,11 +723,11 @@ discard block |
||
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
726 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
726 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
727 | 727 | $is_active = false; |
728 | 728 | } |
729 | 729 | |
730 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
730 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | * @since 1.0.19 |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function has_item( $item_id ) { |
|
740 | - return false !== $this->get_item( $item_id ); |
|
739 | + public function has_item($item_id) { |
|
740 | + return false !== $this->get_item($item_id); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | * @since 1.0.19 |
747 | 747 | * @return bool |
748 | 748 | */ |
749 | - public function has_element_type( $element_type ) { |
|
750 | - return false !== $this->get_element_type( $element_type ); |
|
749 | + public function has_element_type($element_type) { |
|
750 | + return false !== $this->get_element_type($element_type); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | /** |
@@ -758,13 +758,13 @@ discard block |
||
758 | 758 | */ |
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
761 | + if (!empty($this->invoice)) { |
|
762 | 762 | return $this->invoice->is_recurring(); |
763 | 763 | } |
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ($this->get_items() as $item) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
767 | + if ($item->is_recurring()) { |
|
768 | 768 | return true; |
769 | 769 | } |
770 | 770 | } |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * |
778 | 778 | * @since 1.0.19 |
779 | 779 | */ |
780 | - public function get_html( $extra_markup = '' ) { |
|
780 | + public function get_html($extra_markup = '') { |
|
781 | 781 | |
782 | 782 | // Return the HTML. |
783 | 783 | return wpinv_get_template_html( |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * |
796 | 796 | * @since 1.0.19 |
797 | 797 | */ |
798 | - public function display( $extra_markup = '' ) { |
|
798 | + public function display($extra_markup = '') { |
|
799 | 799 | wpinv_get_template( |
800 | 800 | 'payment-forms/form.php', |
801 | 801 | array( |