@@ -26,71 +26,71 @@ discard block |
||
26 | 26 | |
27 | 27 | <?php |
28 | 28 | |
29 | - // Fires before printing a line item column. |
|
30 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
29 | + // Fires before printing a line item column. |
|
30 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
31 | 31 | |
32 | - // Item name. |
|
33 | - if ( 'name' === $key ) { |
|
32 | + // Item name. |
|
33 | + if ( 'name' === $key ) { |
|
34 | 34 | |
35 | 35 | |
36 | - ob_start(); |
|
36 | + ob_start(); |
|
37 | 37 | |
38 | - // Add an optional description. |
|
39 | - $description = $item->get_description(); |
|
38 | + // Add an optional description. |
|
39 | + $description = $item->get_description(); |
|
40 | 40 | |
41 | - if ( ! empty( $description ) ) { |
|
42 | - echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
43 | - } |
|
41 | + if ( ! empty( $description ) ) { |
|
42 | + echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
43 | + } |
|
44 | 44 | |
45 | - // Price help text. |
|
46 | - $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
47 | - if ( $description ) { |
|
48 | - echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
49 | - } |
|
45 | + // Price help text. |
|
46 | + $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
47 | + if ( $description ) { |
|
48 | + echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
49 | + } |
|
50 | 50 | |
51 | - do_action( 'getpaid_payment_form_cart_item_description', $item, $form ); |
|
51 | + do_action( 'getpaid_payment_form_cart_item_description', $item, $form ); |
|
52 | 52 | |
53 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
53 | + if ( wpinv_current_user_can_manage_invoicing() ) { |
|
54 | 54 | |
55 | - edit_post_link( |
|
56 | - __( 'Edit this item.', 'invoicing' ), |
|
57 | - '<small class="form-text text-muted">', |
|
58 | - '</small>', |
|
59 | - $item->get_id(), |
|
60 | - 'text-danger' |
|
61 | - ); |
|
55 | + edit_post_link( |
|
56 | + __( 'Edit this item.', 'invoicing' ), |
|
57 | + '<small class="form-text text-muted">', |
|
58 | + '</small>', |
|
59 | + $item->get_id(), |
|
60 | + 'text-danger' |
|
61 | + ); |
|
62 | 62 | |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - $description = ob_get_clean(); |
|
65 | + $description = ob_get_clean(); |
|
66 | 66 | |
67 | - // Display the name. |
|
68 | - $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
67 | + // Display the name. |
|
68 | + $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
69 | 69 | |
70 | - $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
70 | + $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
71 | 71 | |
72 | - if ( $has_featured_image ) { |
|
73 | - echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
74 | - echo '<div class="getpaid-form-item-image-container mr-2" style="width:85px;">'; |
|
75 | - echo get_the_post_thumbnail( $item->get_id(), array( 75, 75 ), array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
76 | - echo '</div>'; |
|
77 | - echo '<div class="getpaid-form-item-name-container">'; |
|
78 | - } |
|
72 | + if ( $has_featured_image ) { |
|
73 | + echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
74 | + echo '<div class="getpaid-form-item-image-container mr-2" style="width:85px;">'; |
|
75 | + echo get_the_post_thumbnail( $item->get_id(), array( 75, 75 ), array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
76 | + echo '</div>'; |
|
77 | + echo '<div class="getpaid-form-item-name-container">'; |
|
78 | + } |
|
79 | 79 | |
80 | - echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>'; |
|
80 | + echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>'; |
|
81 | 81 | |
82 | - if ( ! empty( $description ) ) { |
|
83 | - printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) ); |
|
84 | - } |
|
82 | + if ( ! empty( $description ) ) { |
|
83 | + printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - if ( $item->allows_quantities() ) { |
|
87 | - printf( |
|
88 | - '<small class="d-sm-none text-muted form-text">%s</small>', |
|
89 | - sprintf( |
|
90 | - // translators: %s is the item quantity. |
|
91 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
92 | - sprintf( |
|
93 | - '<input |
|
86 | + if ( $item->allows_quantities() ) { |
|
87 | + printf( |
|
88 | + '<small class="d-sm-none text-muted form-text">%s</small>', |
|
89 | + sprintf( |
|
90 | + // translators: %s is the item quantity. |
|
91 | + esc_html__( 'Qty %s', 'invoicing' ), |
|
92 | + sprintf( |
|
93 | + '<input |
|
94 | 94 | type="number" |
95 | 95 | step="0.01" |
96 | 96 | style="width: 48px;" |
@@ -99,62 +99,62 @@ discard block |
||
99 | 99 | min="1" |
100 | 100 | max="%s" |
101 | 101 | >', |
102 | - (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
|
103 | - floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
104 | - ) |
|
105 | - ) |
|
106 | - ); |
|
107 | - } else { |
|
108 | - printf( |
|
109 | - '<small class="d-sm-none text-muted form-text">%s</small>', |
|
110 | - sprintf( |
|
111 | - // translators: %s is the item quantity. |
|
112 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
113 | - (float) $item->get_quantity() |
|
114 | - ) |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - if ( $has_featured_image ) { |
|
119 | - echo '</div>'; |
|
120 | - echo '</div>'; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - // Item price. |
|
125 | - if ( 'price' === $key ) { |
|
126 | - |
|
127 | - // Set the currency position. |
|
128 | - $position = wpinv_currency_position(); |
|
129 | - |
|
130 | - if ( 'left_space' === $position ) { |
|
131 | - $position = 'left'; |
|
132 | - } |
|
133 | - |
|
134 | - if ( 'right_space' === $position ) { |
|
135 | - $position = 'right'; |
|
136 | - } |
|
137 | - |
|
138 | - if ( $item->user_can_set_their_price() ) { |
|
139 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
140 | - $minimum = (float) $item->get_minimum_price(); |
|
141 | - $validate_minimum = ''; |
|
142 | - $class = ''; |
|
143 | - $data_minimum = ''; |
|
144 | - |
|
145 | - if ( $minimum > 0 ) { |
|
146 | - $validate_minimum = sprintf( |
|
147 | - // translators: %s is the minimum price. |
|
148 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
149 | - wp_strip_all_tags( wpinv_price( $minimum, $currency ) ) |
|
150 | - ); |
|
151 | - |
|
152 | - $class = 'getpaid-validate-minimum-amount'; |
|
153 | - |
|
154 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
155 | - } |
|
156 | - |
|
157 | - ?> |
|
102 | + (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
|
103 | + floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
104 | + ) |
|
105 | + ) |
|
106 | + ); |
|
107 | + } else { |
|
108 | + printf( |
|
109 | + '<small class="d-sm-none text-muted form-text">%s</small>', |
|
110 | + sprintf( |
|
111 | + // translators: %s is the item quantity. |
|
112 | + esc_html__( 'Qty %s', 'invoicing' ), |
|
113 | + (float) $item->get_quantity() |
|
114 | + ) |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + if ( $has_featured_image ) { |
|
119 | + echo '</div>'; |
|
120 | + echo '</div>'; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + // Item price. |
|
125 | + if ( 'price' === $key ) { |
|
126 | + |
|
127 | + // Set the currency position. |
|
128 | + $position = wpinv_currency_position(); |
|
129 | + |
|
130 | + if ( 'left_space' === $position ) { |
|
131 | + $position = 'left'; |
|
132 | + } |
|
133 | + |
|
134 | + if ( 'right_space' === $position ) { |
|
135 | + $position = 'right'; |
|
136 | + } |
|
137 | + |
|
138 | + if ( $item->user_can_set_their_price() ) { |
|
139 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
140 | + $minimum = (float) $item->get_minimum_price(); |
|
141 | + $validate_minimum = ''; |
|
142 | + $class = ''; |
|
143 | + $data_minimum = ''; |
|
144 | + |
|
145 | + if ( $minimum > 0 ) { |
|
146 | + $validate_minimum = sprintf( |
|
147 | + // translators: %s is the minimum price. |
|
148 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
149 | + wp_strip_all_tags( wpinv_price( $minimum, $currency ) ) |
|
150 | + ); |
|
151 | + |
|
152 | + $class = 'getpaid-validate-minimum-amount'; |
|
153 | + |
|
154 | + $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
155 | + } |
|
156 | + |
|
157 | + ?> |
|
158 | 158 | <div class="input-group input-group-sm"> |
159 | 159 | <?php if ( 'left' === $position ) : ?> |
160 | 160 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
@@ -195,46 +195,46 @@ discard block |
||
195 | 195 | |
196 | 196 | <?php |
197 | 197 | |
198 | - } else { |
|
199 | - ?> |
|
198 | + } else { |
|
199 | + ?> |
|
200 | 200 | <span class="getpaid-items-<?php echo (int) $item->get_id(); ?>-view-price"> |
201 | 201 | <?php echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); ?> |
202 | 202 | </span> |
203 | 203 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
204 | 204 | <?php |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - printf( |
|
207 | + printf( |
|
208 | 208 | '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>', |
209 | - // translators: %s is the item subtotal. |
|
209 | + // translators: %s is the item subtotal. |
|
210 | 210 | sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) ) |
211 | 211 | ); |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - // Item quantity. |
|
215 | - if ( 'quantity' === $key ) { |
|
214 | + // Item quantity. |
|
215 | + if ( 'quantity' === $key ) { |
|
216 | 216 | |
217 | - if ( $item->allows_quantities() ) { |
|
218 | - ?> |
|
217 | + if ( $item->allows_quantities() ) { |
|
218 | + ?> |
|
219 | 219 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type="number" step="any" style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required> |
220 | 220 | <?php |
221 | - } else { |
|
222 | - ?> |
|
221 | + } else { |
|
222 | + ?> |
|
223 | 223 | <span class="getpaid-items-<?php echo (int) $item->get_id(); ?>-view-quantity"> |
224 | 224 | <?php echo (float) $item->get_quantity(); ?> |
225 | 225 | </span> |
226 | 226 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
227 | 227 | <?php |
228 | - } |
|
228 | + } |
|
229 | 229 | } |
230 | 230 | |
231 | - // Item sub total. |
|
232 | - if ( 'subtotal' === $key ) { |
|
233 | - echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
234 | - } |
|
231 | + // Item sub total. |
|
232 | + if ( 'subtotal' === $key ) { |
|
233 | + echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
234 | + } |
|
235 | 235 | |
236 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
237 | - ?> |
|
236 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
237 | + ?> |
|
238 | 238 | |
239 | 239 | </div> |
240 | 240 |
@@ -18,63 +18,63 @@ |
||
18 | 18 | <?php foreach ( array_keys( $columns ) as $column ) : ?> |
19 | 19 | <td class="<?php echo 'name' == $column ? 'text-left' : 'text-right'; ?> wpinv_cart_item_<?php echo esc_attr( $column ); ?>"> |
20 | 20 | <?php |
21 | - // Fires before printing a line item column. |
|
22 | - do_action( "getpaid_email_line_item_before_$column", $item, $invoice ); |
|
21 | + // Fires before printing a line item column. |
|
22 | + do_action( "getpaid_email_line_item_before_$column", $item, $invoice ); |
|
23 | 23 | |
24 | - // Item name. |
|
25 | - if ( 'name' == $column ) { |
|
26 | - $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
24 | + // Item name. |
|
25 | + if ( 'name' == $column ) { |
|
26 | + $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
27 | 27 | |
28 | - if ( $has_featured_image ) { |
|
29 | - echo '<div class="getpaid-email-item-image-wrap" style="min-height:80px">'; |
|
30 | - echo '<div class="getpaid-email-image-wrap" style="display:inline-block;width:80px;height:80px;">'; |
|
31 | - echo get_the_post_thumbnail( $item->get_id(), array( 75, 75 ), array( 'class' => 'wpinv-email-item-image' ) ); |
|
32 | - echo '</div>'; |
|
33 | - echo '<div class="getpaid-email-item-name-wrap" style="display:inline-block;vertical-align:top;max-width:360px;">'; |
|
34 | - } |
|
28 | + if ( $has_featured_image ) { |
|
29 | + echo '<div class="getpaid-email-item-image-wrap" style="min-height:80px">'; |
|
30 | + echo '<div class="getpaid-email-image-wrap" style="display:inline-block;width:80px;height:80px;">'; |
|
31 | + echo get_the_post_thumbnail( $item->get_id(), array( 75, 75 ), array( 'class' => 'wpinv-email-item-image' ) ); |
|
32 | + echo '</div>'; |
|
33 | + echo '<div class="getpaid-email-item-name-wrap" style="display:inline-block;vertical-align:top;max-width:360px;">'; |
|
34 | + } |
|
35 | 35 | |
36 | - // Display the name. |
|
37 | - echo '<div class="wpinv_email_cart_item_title">' . esc_html( $item->get_name() ) . '</div>'; |
|
36 | + // Display the name. |
|
37 | + echo '<div class="wpinv_email_cart_item_title">' . esc_html( $item->get_name() ) . '</div>'; |
|
38 | 38 | |
39 | - // And an optional description. |
|
40 | - $description = $item->get_description(); |
|
39 | + // And an optional description. |
|
40 | + $description = $item->get_description(); |
|
41 | 41 | |
42 | - if ( ! empty( $description ) ) { |
|
43 | - echo "<p class='small'>" . wp_kses_post( $description ) . "</p>"; |
|
44 | - } |
|
42 | + if ( ! empty( $description ) ) { |
|
43 | + echo "<p class='small'>" . wp_kses_post( $description ) . "</p>"; |
|
44 | + } |
|
45 | 45 | |
46 | - if ( $has_featured_image ) { |
|
47 | - echo '</div>'; |
|
48 | - echo '</div>'; |
|
49 | - } |
|
50 | - } |
|
46 | + if ( $has_featured_image ) { |
|
47 | + echo '</div>'; |
|
48 | + echo '</div>'; |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - // Item price. |
|
53 | - if ( 'price' == $column ) { |
|
54 | - // Display the item price (or recurring price if this is a renewal invoice) |
|
55 | - $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
|
56 | - wpinv_the_price( $price, $invoice->get_currency() ); |
|
57 | - } |
|
52 | + // Item price. |
|
53 | + if ( 'price' == $column ) { |
|
54 | + // Display the item price (or recurring price if this is a renewal invoice) |
|
55 | + $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
|
56 | + wpinv_the_price( $price, $invoice->get_currency() ); |
|
57 | + } |
|
58 | 58 | |
59 | - // Item quantity. |
|
60 | - if ( 'quantity' == $column ) { |
|
61 | - echo (float) $item->get_quantity(); |
|
62 | - } |
|
59 | + // Item quantity. |
|
60 | + if ( 'quantity' == $column ) { |
|
61 | + echo (float) $item->get_quantity(); |
|
62 | + } |
|
63 | 63 | |
64 | - // Tax rate. |
|
65 | - if ( 'tax_rate' == $column ) { |
|
66 | - echo floatval( round( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
67 | - } |
|
64 | + // Tax rate. |
|
65 | + if ( 'tax_rate' == $column ) { |
|
66 | + echo floatval( round( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
67 | + } |
|
68 | 68 | |
69 | - // Item sub total. |
|
70 | - if ( 'subtotal' == $column ) { |
|
71 | - $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
|
72 | - wpinv_the_price( $subtotal, $invoice->get_currency() ); |
|
73 | - } |
|
69 | + // Item sub total. |
|
70 | + if ( 'subtotal' == $column ) { |
|
71 | + $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
|
72 | + wpinv_the_price( $subtotal, $invoice->get_currency() ); |
|
73 | + } |
|
74 | 74 | |
75 | - // Fires when printing a line item column. |
|
76 | - do_action( "getpaid_email_line_item_$column", $item, $invoice ); |
|
77 | - ?> |
|
75 | + // Fires when printing a line item column. |
|
76 | + do_action( "getpaid_email_line_item_$column", $item, $invoice ); |
|
77 | + ?> |
|
78 | 78 | </td> |
79 | 79 | <?php endforeach; ?> |
80 | 80 | </tr> |
@@ -26,90 +26,90 @@ |
||
26 | 26 | |
27 | 27 | <?php |
28 | 28 | |
29 | - // Fires before printing a line item column. |
|
30 | - do_action( "getpaid_invoice_line_item_before_$column", $item, $invoice ); |
|
29 | + // Fires before printing a line item column. |
|
30 | + do_action( "getpaid_invoice_line_item_before_$column", $item, $invoice ); |
|
31 | 31 | |
32 | - // Item name. |
|
33 | - if ( 'name' === $column ) { |
|
32 | + // Item name. |
|
33 | + if ( 'name' === $column ) { |
|
34 | 34 | |
35 | - $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
35 | + $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
36 | 36 | |
37 | - if ( $has_featured_image ) { |
|
38 | - echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
39 | - echo '<div class="getpaid-form-item-image-container mr-2" style="width:85px;">'; |
|
40 | - echo get_the_post_thumbnail( $item->get_id(), array( 75, 75 ), array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
41 | - echo '</div>'; |
|
42 | - echo '<div class="getpaid-form-item-name-container">'; |
|
43 | - } |
|
37 | + if ( $has_featured_image ) { |
|
38 | + echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
39 | + echo '<div class="getpaid-form-item-image-container mr-2" style="width:85px;">'; |
|
40 | + echo get_the_post_thumbnail( $item->get_id(), array( 75, 75 ), array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
41 | + echo '</div>'; |
|
42 | + echo '<div class="getpaid-form-item-name-container">'; |
|
43 | + } |
|
44 | 44 | |
45 | - // Display the name. |
|
46 | - echo '<div class="mb-1">' . esc_html( $item->get_name() ) . '</div>'; |
|
45 | + // Display the name. |
|
46 | + echo '<div class="mb-1">' . esc_html( $item->get_name() ) . '</div>'; |
|
47 | 47 | |
48 | - // And an optional description. |
|
49 | - $description = $item->get_description(); |
|
48 | + // And an optional description. |
|
49 | + $description = $item->get_description(); |
|
50 | 50 | |
51 | - if ( ! empty( $description ) ) { |
|
52 | - echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
53 | - } |
|
51 | + if ( ! empty( $description ) ) { |
|
52 | + echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
53 | + } |
|
54 | 54 | |
55 | - // Fires before printing the line item actions. |
|
56 | - do_action( 'getpaid_before_invoice_line_item_actions', $item, $invoice ); |
|
55 | + // Fires before printing the line item actions. |
|
56 | + do_action( 'getpaid_before_invoice_line_item_actions', $item, $invoice ); |
|
57 | 57 | |
58 | - $actions = apply_filters( 'getpaid-invoice-page-line-item-actions', array(), $item, $invoice ); |
|
58 | + $actions = apply_filters( 'getpaid-invoice-page-line-item-actions', array(), $item, $invoice ); |
|
59 | 59 | |
60 | - if ( ! empty( $actions ) ) { |
|
60 | + if ( ! empty( $actions ) ) { |
|
61 | 61 | |
62 | - $sanitized = array(); |
|
63 | - foreach ( $actions as $key => $item_action ) { |
|
64 | - $key = sanitize_html_class( $key ); |
|
65 | - $item_action = wp_kses_post( $item_action ); |
|
66 | - $sanitized[] = "<span class='$key'>$item_action</span>"; |
|
67 | - } |
|
62 | + $sanitized = array(); |
|
63 | + foreach ( $actions as $key => $item_action ) { |
|
64 | + $key = sanitize_html_class( $key ); |
|
65 | + $item_action = wp_kses_post( $item_action ); |
|
66 | + $sanitized[] = "<span class='$key'>$item_action</span>"; |
|
67 | + } |
|
68 | 68 | |
69 | - echo "<small class='form-text getpaid-line-item-actions'>"; |
|
70 | - echo wp_kses_post( implode( ' | ', $sanitized ) ); |
|
71 | - echo '</small>'; |
|
69 | + echo "<small class='form-text getpaid-line-item-actions'>"; |
|
70 | + echo wp_kses_post( implode( ' | ', $sanitized ) ); |
|
71 | + echo '</small>'; |
|
72 | 72 | |
73 | - } |
|
73 | + } |
|
74 | 74 | |
75 | - if ( $has_featured_image ) { |
|
76 | - echo '</div>'; |
|
77 | - echo '</div>'; |
|
78 | - } |
|
79 | - } |
|
75 | + if ( $has_featured_image ) { |
|
76 | + echo '</div>'; |
|
77 | + echo '</div>'; |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - // Item price. |
|
82 | - if ( 'price' === $column ) { |
|
81 | + // Item price. |
|
82 | + if ( 'price' === $column ) { |
|
83 | 83 | |
84 | - // Display the item price (or recurring price if this is a renewal invoice) |
|
85 | - $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
|
86 | - wpinv_the_price( $price, $invoice->get_currency() ); |
|
84 | + // Display the item price (or recurring price if this is a renewal invoice) |
|
85 | + $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
|
86 | + wpinv_the_price( $price, $invoice->get_currency() ); |
|
87 | 87 | |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - // Tax rate. |
|
91 | - if ( 'tax_rate' === $column ) { |
|
92 | - echo floatval( round( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
93 | - } |
|
90 | + // Tax rate. |
|
91 | + if ( 'tax_rate' === $column ) { |
|
92 | + echo floatval( round( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
93 | + } |
|
94 | 94 | |
95 | - // Item quantity. |
|
96 | - if ( 'quantity' === $column ) { |
|
97 | - echo (float) $item->get_quantity(); |
|
98 | - } |
|
95 | + // Item quantity. |
|
96 | + if ( 'quantity' === $column ) { |
|
97 | + echo (float) $item->get_quantity(); |
|
98 | + } |
|
99 | 99 | |
100 | - // Item sub total. |
|
101 | - if ( 'subtotal' === $column ) { |
|
102 | - $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
|
103 | - wpinv_the_price( $subtotal, $invoice->get_currency() ); |
|
104 | - } |
|
100 | + // Item sub total. |
|
101 | + if ( 'subtotal' === $column ) { |
|
102 | + $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
|
103 | + wpinv_the_price( $subtotal, $invoice->get_currency() ); |
|
104 | + } |
|
105 | 105 | |
106 | - // Fires when printing a line item column. |
|
107 | - do_action( "getpaid_invoice_line_item_$column", $item, $invoice ); |
|
106 | + // Fires when printing a line item column. |
|
107 | + do_action( "getpaid_invoice_line_item_$column", $item, $invoice ); |
|
108 | 108 | |
109 | - // Fires after printing a line item column. |
|
110 | - do_action( "getpaid_invoice_line_item_after_$column", $item, $invoice ); |
|
109 | + // Fires after printing a line item column. |
|
110 | + do_action( "getpaid_invoice_line_item_after_$column", $item, $invoice ); |
|
111 | 111 | |
112 | - ?> |
|
112 | + ?> |
|
113 | 113 | |
114 | 114 | </div> |
115 | 115 |
@@ -15,125 +15,125 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $data_store_name = 'subscription'; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'subscription'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Item Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'customer_id' => 0, |
|
40 | - 'frequency' => 1, |
|
41 | - 'period' => 'D', |
|
42 | - 'initial_amount' => null, |
|
43 | - 'recurring_amount' => null, |
|
44 | - 'bill_times' => 0, |
|
45 | - 'transaction_id' => '', |
|
46 | - 'parent_payment_id' => null, |
|
47 | - 'product_id' => 0, |
|
48 | - 'created' => '0000-00-00 00:00:00', |
|
49 | - 'expiration' => '0000-00-00 00:00:00', |
|
50 | - 'trial_period' => '', |
|
51 | - 'status' => 'pending', |
|
52 | - 'profile_id' => '', |
|
53 | - 'gateway' => '', |
|
54 | - 'customer' => '', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * Stores the status transition information. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - protected $status_transition = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | - * |
|
68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | - * @param bool $deprecated |
|
70 | - */ |
|
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | - |
|
73 | - parent::__construct( $subscription ); |
|
74 | - |
|
75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | - $this->set_id( $subscription ); |
|
77 | - } elseif ( $subscription instanceof self ) { |
|
78 | - $this->set_id( $subscription->get_id() ); |
|
79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | - $this->set_id( $subscription_id ); |
|
81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
82 | - $this->set_id( $subscription->id ); |
|
83 | - } else { |
|
84 | - $this->set_object_read( true ); |
|
85 | - } |
|
86 | - |
|
87 | - // Load the datastore. |
|
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | - |
|
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | - * |
|
99 | - * |
|
100 | - * @static |
|
101 | - * @param string $value |
|
102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | - * @since 1.0.19 |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $data_store_name = 'subscription'; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'subscription'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Item Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'customer_id' => 0, |
|
40 | + 'frequency' => 1, |
|
41 | + 'period' => 'D', |
|
42 | + 'initial_amount' => null, |
|
43 | + 'recurring_amount' => null, |
|
44 | + 'bill_times' => 0, |
|
45 | + 'transaction_id' => '', |
|
46 | + 'parent_payment_id' => null, |
|
47 | + 'product_id' => 0, |
|
48 | + 'created' => '0000-00-00 00:00:00', |
|
49 | + 'expiration' => '0000-00-00 00:00:00', |
|
50 | + 'trial_period' => '', |
|
51 | + 'status' => 'pending', |
|
52 | + 'profile_id' => '', |
|
53 | + 'gateway' => '', |
|
54 | + 'customer' => '', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * Stores the status transition information. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + protected $status_transition = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | + * |
|
68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | + * @param bool $deprecated |
|
70 | + */ |
|
71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | + |
|
73 | + parent::__construct( $subscription ); |
|
74 | + |
|
75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | + $this->set_id( $subscription ); |
|
77 | + } elseif ( $subscription instanceof self ) { |
|
78 | + $this->set_id( $subscription->get_id() ); |
|
79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | + $this->set_id( $subscription_id ); |
|
81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
82 | + $this->set_id( $subscription->id ); |
|
83 | + } else { |
|
84 | + $this->set_object_read( true ); |
|
85 | + } |
|
86 | + |
|
87 | + // Load the datastore. |
|
88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | + |
|
90 | + if ( $this->get_id() > 0 ) { |
|
91 | + $this->data_store->read( $this ); |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | + * |
|
99 | + * |
|
100 | + * @static |
|
101 | + * @param string $value |
|
102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | + * @since 1.0.19 |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | - // Trim the value. |
|
110 | - $value = trim( $value ); |
|
109 | + // Trim the value. |
|
110 | + $value = trim( $value ); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
113 | - return 0; |
|
114 | - } |
|
112 | + if ( empty( $value ) ) { |
|
113 | + return 0; |
|
114 | + } |
|
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
117 | - $field = 'parent_payment_id'; |
|
118 | - } |
|
116 | + if ( 'invoice_id' == $field ) { |
|
117 | + $field = 'parent_payment_id'; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | // Valid fields. |
121 | 121 | $fields = array( |
122 | - 'parent_payment_id', |
|
123 | - 'transaction_id', |
|
124 | - 'profile_id', |
|
125 | - ); |
|
126 | - |
|
127 | - // Ensure a field has been passed. |
|
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | - return 0; |
|
130 | - } |
|
131 | - |
|
132 | - // Maybe retrieve from the cache. |
|
133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | - if ( ! empty( $subscription_id ) ) { |
|
135 | - return $subscription_id; |
|
136 | - } |
|
122 | + 'parent_payment_id', |
|
123 | + 'transaction_id', |
|
124 | + 'profile_id', |
|
125 | + ); |
|
126 | + |
|
127 | + // Ensure a field has been passed. |
|
128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | + return 0; |
|
130 | + } |
|
131 | + |
|
132 | + // Maybe retrieve from the cache. |
|
133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | + if ( ! empty( $subscription_id ) ) { |
|
135 | + return $subscription_id; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,42 +141,42 @@ discard block |
||
141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
142 | 142 | ); |
143 | 143 | |
144 | - if ( empty( $subscription_id ) ) { |
|
145 | - return 0; |
|
146 | - } |
|
144 | + if ( empty( $subscription_id ) ) { |
|
145 | + return 0; |
|
146 | + } |
|
147 | 147 | |
148 | - // Update the cache with our data. |
|
149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
148 | + // Update the cache with our data. |
|
149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
150 | 150 | |
151 | - return $subscription_id; |
|
152 | - } |
|
151 | + return $subscription_id; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
154 | + /** |
|
155 | 155 | * Clears the subscription's cache. |
156 | 156 | */ |
157 | 157 | public function clear_cache() { |
158 | - $caches = array( |
|
159 | - 'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(), |
|
160 | - 'getpaid_subscription_transaction_ids_to_subscription_ids' => $this->get_transaction_id(), |
|
161 | - 'getpaid_subscription_profile_ids_to_subscription_ids' => $this->get_profile_id(), |
|
162 | - 'getpaid_subscriptions' => $this->get_id(), |
|
163 | - ); |
|
164 | - |
|
165 | - foreach ( $caches as $cache => $value ) { |
|
166 | - if ( '' !== $value && false !== $value ) { |
|
167 | - wp_cache_delete( $value, $cache ); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
158 | + $caches = array( |
|
159 | + 'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(), |
|
160 | + 'getpaid_subscription_transaction_ids_to_subscription_ids' => $this->get_transaction_id(), |
|
161 | + 'getpaid_subscription_profile_ids_to_subscription_ids' => $this->get_profile_id(), |
|
162 | + 'getpaid_subscriptions' => $this->get_id(), |
|
163 | + ); |
|
164 | + |
|
165 | + foreach ( $caches as $cache => $value ) { |
|
166 | + if ( '' !== $value && false !== $value ) { |
|
167 | + wp_cache_delete( $value, $cache ); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | 173 | * Checks if a subscription key is set. |
174 | 174 | */ |
175 | 175 | public function _isset( $key ) { |
176 | 176 | return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - /* |
|
179 | + /* |
|
180 | 180 | |-------------------------------------------------------------------------- |
181 | 181 | | CRUD methods |
182 | 182 | |-------------------------------------------------------------------------- |
@@ -185,57 +185,57 @@ discard block |
||
185 | 185 | | |
186 | 186 | */ |
187 | 187 | |
188 | - /* |
|
188 | + /* |
|
189 | 189 | |-------------------------------------------------------------------------- |
190 | 190 | | Getters |
191 | 191 | |-------------------------------------------------------------------------- |
192 | 192 | */ |
193 | 193 | |
194 | - /** |
|
195 | - * Get customer id. |
|
196 | - * |
|
197 | - * @since 1.0.19 |
|
198 | - * @param string $context View or edit context. |
|
199 | - * @return int |
|
200 | - */ |
|
201 | - public function get_customer_id( $context = 'view' ) { |
|
202 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Get customer information. |
|
207 | - * |
|
208 | - * @since 1.0.19 |
|
209 | - * @param string $context View or edit context. |
|
210 | - * @return WP_User|false WP_User object on success, false on failure. |
|
211 | - */ |
|
212 | - public function get_customer( $context = 'view' ) { |
|
213 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Get parent invoice id. |
|
218 | - * |
|
219 | - * @since 1.0.19 |
|
220 | - * @param string $context View or edit context. |
|
221 | - * @return int |
|
222 | - */ |
|
223 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
224 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Alias for self::get_parent_invoice_id(). |
|
229 | - * |
|
230 | - * @since 1.0.19 |
|
231 | - * @param string $context View or edit context. |
|
232 | - * @return int |
|
233 | - */ |
|
194 | + /** |
|
195 | + * Get customer id. |
|
196 | + * |
|
197 | + * @since 1.0.19 |
|
198 | + * @param string $context View or edit context. |
|
199 | + * @return int |
|
200 | + */ |
|
201 | + public function get_customer_id( $context = 'view' ) { |
|
202 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Get customer information. |
|
207 | + * |
|
208 | + * @since 1.0.19 |
|
209 | + * @param string $context View or edit context. |
|
210 | + * @return WP_User|false WP_User object on success, false on failure. |
|
211 | + */ |
|
212 | + public function get_customer( $context = 'view' ) { |
|
213 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Get parent invoice id. |
|
218 | + * |
|
219 | + * @since 1.0.19 |
|
220 | + * @param string $context View or edit context. |
|
221 | + * @return int |
|
222 | + */ |
|
223 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
224 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Alias for self::get_parent_invoice_id(). |
|
229 | + * |
|
230 | + * @since 1.0.19 |
|
231 | + * @param string $context View or edit context. |
|
232 | + * @return int |
|
233 | + */ |
|
234 | 234 | public function get_parent_payment_id( $context = 'view' ) { |
235 | 235 | return $this->get_parent_invoice_id( $context ); |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
238 | + /** |
|
239 | 239 | * Alias for self::get_parent_invoice_id(). |
240 | 240 | * |
241 | 241 | * @since 1.0.0 |
@@ -245,390 +245,390 @@ discard block |
||
245 | 245 | return $this->get_parent_invoice_id( $context ); |
246 | 246 | } |
247 | 247 | |
248 | - /** |
|
249 | - * Get parent invoice. |
|
250 | - * |
|
251 | - * @since 1.0.19 |
|
252 | - * @param string $context View or edit context. |
|
253 | - * @return WPInv_Invoice |
|
254 | - */ |
|
255 | - public function get_parent_invoice( $context = 'view' ) { |
|
256 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Alias for self::get_parent_invoice(). |
|
261 | - * |
|
262 | - * @since 1.0.19 |
|
263 | - * @param string $context View or edit context. |
|
264 | - * @return WPInv_Invoice |
|
265 | - */ |
|
248 | + /** |
|
249 | + * Get parent invoice. |
|
250 | + * |
|
251 | + * @since 1.0.19 |
|
252 | + * @param string $context View or edit context. |
|
253 | + * @return WPInv_Invoice |
|
254 | + */ |
|
255 | + public function get_parent_invoice( $context = 'view' ) { |
|
256 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Alias for self::get_parent_invoice(). |
|
261 | + * |
|
262 | + * @since 1.0.19 |
|
263 | + * @param string $context View or edit context. |
|
264 | + * @return WPInv_Invoice |
|
265 | + */ |
|
266 | 266 | public function get_parent_payment( $context = 'view' ) { |
267 | 267 | return $this->get_parent_invoice( $context ); |
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Get subscription's product id. |
|
272 | - * |
|
273 | - * @since 1.0.19 |
|
274 | - * @param string $context View or edit context. |
|
275 | - * @return int |
|
276 | - */ |
|
277 | - public function get_product_id( $context = 'view' ) { |
|
278 | - return (int) $this->get_prop( 'product_id', $context ); |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Get the subscription product. |
|
283 | - * |
|
284 | - * @since 1.0.19 |
|
285 | - * @param string $context View or edit context. |
|
286 | - * @return WPInv_Item |
|
287 | - */ |
|
288 | - public function get_product( $context = 'view' ) { |
|
289 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Get parent invoice's gateway. |
|
294 | - * |
|
295 | - * Here for backwards compatibility. |
|
296 | - * |
|
297 | - * @since 1.0.19 |
|
298 | - * @param string $context View or edit context. |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - public function get_gateway( $context = 'view' ) { |
|
302 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Get the period of a renewal. |
|
307 | - * |
|
308 | - * @since 1.0.19 |
|
309 | - * @param string $context View or edit context. |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function get_period( $context = 'view' ) { |
|
313 | - return $this->get_prop( 'period', $context ); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Get number of periods each renewal is valid for. |
|
318 | - * |
|
319 | - * @since 1.0.19 |
|
320 | - * @param string $context View or edit context. |
|
321 | - * @return int |
|
322 | - */ |
|
323 | - public function get_frequency( $context = 'view' ) { |
|
324 | - return (int) $this->get_prop( 'frequency', $context ); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Get the initial amount for the subscription. |
|
329 | - * |
|
330 | - * @since 1.0.19 |
|
331 | - * @param string $context View or edit context. |
|
332 | - * @return float |
|
333 | - */ |
|
334 | - public function get_initial_amount( $context = 'view' ) { |
|
335 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Get the recurring amount for the subscription. |
|
340 | - * |
|
341 | - * @since 1.0.19 |
|
342 | - * @param string $context View or edit context. |
|
343 | - * @return float |
|
344 | - */ |
|
345 | - public function get_recurring_amount( $context = 'view' ) { |
|
346 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Get number of times that this subscription can be renewed. |
|
351 | - * |
|
352 | - * @since 1.0.19 |
|
353 | - * @param string $context View or edit context. |
|
354 | - * @return int |
|
355 | - */ |
|
356 | - public function get_bill_times( $context = 'view' ) { |
|
357 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Get transaction id of this subscription's parent invoice. |
|
362 | - * |
|
363 | - * @since 1.0.19 |
|
364 | - * @param string $context View or edit context. |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public function get_transaction_id( $context = 'view' ) { |
|
368 | - return $this->get_prop( 'transaction_id', $context ); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get the date that the subscription was created. |
|
373 | - * |
|
374 | - * @since 1.0.19 |
|
375 | - * @param string $context View or edit context. |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public function get_created( $context = 'view' ) { |
|
379 | - return $this->get_prop( 'created', $context ); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Alias for self::get_created(). |
|
384 | - * |
|
385 | - * @since 1.0.19 |
|
386 | - * @param string $context View or edit context. |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_date_created( $context = 'view' ) { |
|
390 | - return $this->get_created( $context ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Retrieves the creation date in a timestamp |
|
395 | - * |
|
396 | - * @since 1.0.0 |
|
397 | - * @return int |
|
398 | - */ |
|
399 | - public function get_time_created() { |
|
400 | - $created = $this->get_date_created(); |
|
401 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Get GMT date when the subscription was created. |
|
406 | - * |
|
407 | - * @since 1.0.19 |
|
408 | - * @param string $context View or edit context. |
|
409 | - * @return string |
|
410 | - */ |
|
411 | - public function get_date_created_gmt( $context = 'view' ) { |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Get subscription's product id. |
|
272 | + * |
|
273 | + * @since 1.0.19 |
|
274 | + * @param string $context View or edit context. |
|
275 | + * @return int |
|
276 | + */ |
|
277 | + public function get_product_id( $context = 'view' ) { |
|
278 | + return (int) $this->get_prop( 'product_id', $context ); |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Get the subscription product. |
|
283 | + * |
|
284 | + * @since 1.0.19 |
|
285 | + * @param string $context View or edit context. |
|
286 | + * @return WPInv_Item |
|
287 | + */ |
|
288 | + public function get_product( $context = 'view' ) { |
|
289 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Get parent invoice's gateway. |
|
294 | + * |
|
295 | + * Here for backwards compatibility. |
|
296 | + * |
|
297 | + * @since 1.0.19 |
|
298 | + * @param string $context View or edit context. |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + public function get_gateway( $context = 'view' ) { |
|
302 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Get the period of a renewal. |
|
307 | + * |
|
308 | + * @since 1.0.19 |
|
309 | + * @param string $context View or edit context. |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function get_period( $context = 'view' ) { |
|
313 | + return $this->get_prop( 'period', $context ); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Get number of periods each renewal is valid for. |
|
318 | + * |
|
319 | + * @since 1.0.19 |
|
320 | + * @param string $context View or edit context. |
|
321 | + * @return int |
|
322 | + */ |
|
323 | + public function get_frequency( $context = 'view' ) { |
|
324 | + return (int) $this->get_prop( 'frequency', $context ); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Get the initial amount for the subscription. |
|
329 | + * |
|
330 | + * @since 1.0.19 |
|
331 | + * @param string $context View or edit context. |
|
332 | + * @return float |
|
333 | + */ |
|
334 | + public function get_initial_amount( $context = 'view' ) { |
|
335 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Get the recurring amount for the subscription. |
|
340 | + * |
|
341 | + * @since 1.0.19 |
|
342 | + * @param string $context View or edit context. |
|
343 | + * @return float |
|
344 | + */ |
|
345 | + public function get_recurring_amount( $context = 'view' ) { |
|
346 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Get number of times that this subscription can be renewed. |
|
351 | + * |
|
352 | + * @since 1.0.19 |
|
353 | + * @param string $context View or edit context. |
|
354 | + * @return int |
|
355 | + */ |
|
356 | + public function get_bill_times( $context = 'view' ) { |
|
357 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Get transaction id of this subscription's parent invoice. |
|
362 | + * |
|
363 | + * @since 1.0.19 |
|
364 | + * @param string $context View or edit context. |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public function get_transaction_id( $context = 'view' ) { |
|
368 | + return $this->get_prop( 'transaction_id', $context ); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get the date that the subscription was created. |
|
373 | + * |
|
374 | + * @since 1.0.19 |
|
375 | + * @param string $context View or edit context. |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public function get_created( $context = 'view' ) { |
|
379 | + return $this->get_prop( 'created', $context ); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Alias for self::get_created(). |
|
384 | + * |
|
385 | + * @since 1.0.19 |
|
386 | + * @param string $context View or edit context. |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_date_created( $context = 'view' ) { |
|
390 | + return $this->get_created( $context ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Retrieves the creation date in a timestamp |
|
395 | + * |
|
396 | + * @since 1.0.0 |
|
397 | + * @return int |
|
398 | + */ |
|
399 | + public function get_time_created() { |
|
400 | + $created = $this->get_date_created(); |
|
401 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Get GMT date when the subscription was created. |
|
406 | + * |
|
407 | + * @since 1.0.19 |
|
408 | + * @param string $context View or edit context. |
|
409 | + * @return string |
|
410 | + */ |
|
411 | + public function get_date_created_gmt( $context = 'view' ) { |
|
412 | 412 | $date = $this->get_date_created( $context ); |
413 | 413 | |
414 | 414 | if ( $date ) { |
415 | 415 | $date = get_gmt_from_date( $date ); |
416 | 416 | } |
417 | - return $date; |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Get the date that the subscription will renew. |
|
422 | - * |
|
423 | - * @since 1.0.19 |
|
424 | - * @param string $context View or edit context. |
|
425 | - * @return string |
|
426 | - */ |
|
427 | - public function get_next_renewal_date( $context = 'view' ) { |
|
428 | - return $this->get_prop( 'expiration', $context ); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Alias for self::get_next_renewal_date(). |
|
433 | - * |
|
434 | - * @since 1.0.19 |
|
435 | - * @param string $context View or edit context. |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - public function get_expiration( $context = 'view' ) { |
|
439 | - return $this->get_next_renewal_date( $context ); |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Retrieves the expiration date in a timestamp |
|
444 | - * |
|
445 | - * @since 1.0.0 |
|
446 | - * @return int |
|
447 | - */ |
|
448 | - public function get_expiration_time() { |
|
449 | - $expiration = $this->get_expiration(); |
|
450 | - |
|
451 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
452 | - return current_time( 'timestamp' ); |
|
453 | - } |
|
454 | - |
|
455 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
456 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Get GMT date when the subscription will renew. |
|
461 | - * |
|
462 | - * @since 1.0.19 |
|
463 | - * @param string $context View or edit context. |
|
464 | - * @return string |
|
465 | - */ |
|
466 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
417 | + return $date; |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Get the date that the subscription will renew. |
|
422 | + * |
|
423 | + * @since 1.0.19 |
|
424 | + * @param string $context View or edit context. |
|
425 | + * @return string |
|
426 | + */ |
|
427 | + public function get_next_renewal_date( $context = 'view' ) { |
|
428 | + return $this->get_prop( 'expiration', $context ); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Alias for self::get_next_renewal_date(). |
|
433 | + * |
|
434 | + * @since 1.0.19 |
|
435 | + * @param string $context View or edit context. |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public function get_expiration( $context = 'view' ) { |
|
439 | + return $this->get_next_renewal_date( $context ); |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Retrieves the expiration date in a timestamp |
|
444 | + * |
|
445 | + * @since 1.0.0 |
|
446 | + * @return int |
|
447 | + */ |
|
448 | + public function get_expiration_time() { |
|
449 | + $expiration = $this->get_expiration(); |
|
450 | + |
|
451 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
452 | + return current_time( 'timestamp' ); |
|
453 | + } |
|
454 | + |
|
455 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
456 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Get GMT date when the subscription will renew. |
|
461 | + * |
|
462 | + * @since 1.0.19 |
|
463 | + * @param string $context View or edit context. |
|
464 | + * @return string |
|
465 | + */ |
|
466 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
467 | 467 | $date = $this->get_next_renewal_date( $context ); |
468 | 468 | |
469 | 469 | if ( $date ) { |
470 | 470 | $date = get_gmt_from_date( $date ); |
471 | 471 | } |
472 | - return $date; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Get the subscription's trial period. |
|
477 | - * |
|
478 | - * @since 1.0.19 |
|
479 | - * @param string $context View or edit context. |
|
480 | - * @return string |
|
481 | - */ |
|
482 | - public function get_trial_period( $context = 'view' ) { |
|
483 | - return $this->get_prop( 'trial_period', $context ); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Get the subscription's status. |
|
488 | - * |
|
489 | - * @since 1.0.19 |
|
490 | - * @param string $context View or edit context. |
|
491 | - * @return string |
|
492 | - */ |
|
493 | - public function get_status( $context = 'view' ) { |
|
494 | - return $this->get_prop( 'status', $context ); |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * Get the subscription's profile id. |
|
499 | - * |
|
500 | - * @since 1.0.19 |
|
501 | - * @param string $context View or edit context. |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - public function get_profile_id( $context = 'view' ) { |
|
505 | - return $this->get_prop( 'profile_id', $context ); |
|
506 | - } |
|
507 | - |
|
508 | - /* |
|
472 | + return $date; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Get the subscription's trial period. |
|
477 | + * |
|
478 | + * @since 1.0.19 |
|
479 | + * @param string $context View or edit context. |
|
480 | + * @return string |
|
481 | + */ |
|
482 | + public function get_trial_period( $context = 'view' ) { |
|
483 | + return $this->get_prop( 'trial_period', $context ); |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Get the subscription's status. |
|
488 | + * |
|
489 | + * @since 1.0.19 |
|
490 | + * @param string $context View or edit context. |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public function get_status( $context = 'view' ) { |
|
494 | + return $this->get_prop( 'status', $context ); |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * Get the subscription's profile id. |
|
499 | + * |
|
500 | + * @since 1.0.19 |
|
501 | + * @param string $context View or edit context. |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + public function get_profile_id( $context = 'view' ) { |
|
505 | + return $this->get_prop( 'profile_id', $context ); |
|
506 | + } |
|
507 | + |
|
508 | + /* |
|
509 | 509 | |-------------------------------------------------------------------------- |
510 | 510 | | Setters |
511 | 511 | |-------------------------------------------------------------------------- |
512 | 512 | */ |
513 | 513 | |
514 | - /** |
|
515 | - * Set customer id. |
|
516 | - * |
|
517 | - * @since 1.0.19 |
|
518 | - * @param int $value The customer's id. |
|
519 | - */ |
|
520 | - public function set_customer_id( $value ) { |
|
521 | - $this->set_prop( 'customer_id', (int) $value ); |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Set parent invoice id. |
|
526 | - * |
|
527 | - * @since 1.0.19 |
|
528 | - * @param int $value The parent invoice id. |
|
529 | - */ |
|
530 | - public function set_parent_invoice_id( $value ) { |
|
531 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * Alias for self::set_parent_invoice_id(). |
|
536 | - * |
|
537 | - * @since 1.0.19 |
|
538 | - * @param int $value The parent invoice id. |
|
539 | - */ |
|
540 | - public function set_parent_payment_id( $value ) { |
|
541 | - $this->set_parent_invoice_id( $value ); |
|
542 | - } |
|
514 | + /** |
|
515 | + * Set customer id. |
|
516 | + * |
|
517 | + * @since 1.0.19 |
|
518 | + * @param int $value The customer's id. |
|
519 | + */ |
|
520 | + public function set_customer_id( $value ) { |
|
521 | + $this->set_prop( 'customer_id', (int) $value ); |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Set parent invoice id. |
|
526 | + * |
|
527 | + * @since 1.0.19 |
|
528 | + * @param int $value The parent invoice id. |
|
529 | + */ |
|
530 | + public function set_parent_invoice_id( $value ) { |
|
531 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * Alias for self::set_parent_invoice_id(). |
|
536 | + * |
|
537 | + * @since 1.0.19 |
|
538 | + * @param int $value The parent invoice id. |
|
539 | + */ |
|
540 | + public function set_parent_payment_id( $value ) { |
|
541 | + $this->set_parent_invoice_id( $value ); |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Alias for self::set_parent_invoice_id(). |
|
546 | + * |
|
547 | + * @since 1.0.19 |
|
548 | + * @param int $value The parent invoice id. |
|
549 | + */ |
|
550 | + public function set_original_payment_id( $value ) { |
|
551 | + $this->set_parent_invoice_id( $value ); |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * Set subscription's product id. |
|
556 | + * |
|
557 | + * @since 1.0.19 |
|
558 | + * @param int $value The subscription product id. |
|
559 | + */ |
|
560 | + public function set_product_id( $value ) { |
|
561 | + $this->set_prop( 'product_id', (int) $value ); |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * Set the period of a renewal. |
|
566 | + * |
|
567 | + * @since 1.0.19 |
|
568 | + * @param string $value The renewal period. |
|
569 | + */ |
|
570 | + public function set_period( $value ) { |
|
571 | + $this->set_prop( 'period', $value ); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Set number of periods each renewal is valid for. |
|
576 | + * |
|
577 | + * @since 1.0.19 |
|
578 | + * @param int $value The subscription frequency. |
|
579 | + */ |
|
580 | + public function set_frequency( $value ) { |
|
581 | + $value = empty( $value ) ? 1 : (int) $value; |
|
582 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Set the initial amount for the subscription. |
|
587 | + * |
|
588 | + * @since 1.0.19 |
|
589 | + * @param float $value The initial subcription amount. |
|
590 | + */ |
|
591 | + public function set_initial_amount( $value ) { |
|
592 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Set the recurring amount for the subscription. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + * @param float $value The recurring subcription amount. |
|
600 | + */ |
|
601 | + public function set_recurring_amount( $value ) { |
|
602 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Set number of times that this subscription can be renewed. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param int $value Bill times. |
|
610 | + */ |
|
611 | + public function set_bill_times( $value ) { |
|
612 | + $this->set_prop( 'bill_times', (int) $value ); |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Get transaction id of this subscription's parent invoice. |
|
617 | + * |
|
618 | + * @since 1.0.19 |
|
619 | + * @param string $value Bill times. |
|
620 | + */ |
|
621 | + public function set_transaction_id( $value ) { |
|
622 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
623 | + } |
|
543 | 624 | |
544 | - /** |
|
545 | - * Alias for self::set_parent_invoice_id(). |
|
625 | + /** |
|
626 | + * Set date when this subscription started. |
|
546 | 627 | * |
547 | 628 | * @since 1.0.19 |
548 | - * @param int $value The parent invoice id. |
|
629 | + * @param string $value strtotime compliant date. |
|
549 | 630 | */ |
550 | - public function set_original_payment_id( $value ) { |
|
551 | - $this->set_parent_invoice_id( $value ); |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * Set subscription's product id. |
|
556 | - * |
|
557 | - * @since 1.0.19 |
|
558 | - * @param int $value The subscription product id. |
|
559 | - */ |
|
560 | - public function set_product_id( $value ) { |
|
561 | - $this->set_prop( 'product_id', (int) $value ); |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Set the period of a renewal. |
|
566 | - * |
|
567 | - * @since 1.0.19 |
|
568 | - * @param string $value The renewal period. |
|
569 | - */ |
|
570 | - public function set_period( $value ) { |
|
571 | - $this->set_prop( 'period', $value ); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Set number of periods each renewal is valid for. |
|
576 | - * |
|
577 | - * @since 1.0.19 |
|
578 | - * @param int $value The subscription frequency. |
|
579 | - */ |
|
580 | - public function set_frequency( $value ) { |
|
581 | - $value = empty( $value ) ? 1 : (int) $value; |
|
582 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Set the initial amount for the subscription. |
|
587 | - * |
|
588 | - * @since 1.0.19 |
|
589 | - * @param float $value The initial subcription amount. |
|
590 | - */ |
|
591 | - public function set_initial_amount( $value ) { |
|
592 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Set the recurring amount for the subscription. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - * @param float $value The recurring subcription amount. |
|
600 | - */ |
|
601 | - public function set_recurring_amount( $value ) { |
|
602 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Set number of times that this subscription can be renewed. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param int $value Bill times. |
|
610 | - */ |
|
611 | - public function set_bill_times( $value ) { |
|
612 | - $this->set_prop( 'bill_times', (int) $value ); |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Get transaction id of this subscription's parent invoice. |
|
617 | - * |
|
618 | - * @since 1.0.19 |
|
619 | - * @param string $value Bill times. |
|
620 | - */ |
|
621 | - public function set_transaction_id( $value ) { |
|
622 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Set date when this subscription started. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - * @param string $value strtotime compliant date. |
|
630 | - */ |
|
631 | - public function set_created( $value ) { |
|
631 | + public function set_created( $value ) { |
|
632 | 632 | $date = strtotime( $value ); |
633 | 633 | |
634 | 634 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -636,93 +636,93 @@ discard block |
||
636 | 636 | return; |
637 | 637 | } |
638 | 638 | |
639 | - $this->set_prop( 'created', '' ); |
|
639 | + $this->set_prop( 'created', '' ); |
|
640 | 640 | |
641 | - } |
|
641 | + } |
|
642 | 642 | |
643 | - /** |
|
644 | - * Alias for self::set_created(). |
|
645 | - * |
|
646 | - * @since 1.0.19 |
|
647 | - * @param string $value strtotime compliant date. |
|
648 | - */ |
|
649 | - public function set_date_created( $value ) { |
|
650 | - $this->set_created( $value ); |
|
643 | + /** |
|
644 | + * Alias for self::set_created(). |
|
645 | + * |
|
646 | + * @since 1.0.19 |
|
647 | + * @param string $value strtotime compliant date. |
|
648 | + */ |
|
649 | + public function set_date_created( $value ) { |
|
650 | + $this->set_created( $value ); |
|
651 | 651 | } |
652 | 652 | |
653 | - /** |
|
654 | - * Set the date that the subscription will renew. |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - * @param string $value strtotime compliant date. |
|
658 | - */ |
|
659 | - public function set_next_renewal_date( $value ) { |
|
660 | - $date = strtotime( $value ); |
|
653 | + /** |
|
654 | + * Set the date that the subscription will renew. |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + * @param string $value strtotime compliant date. |
|
658 | + */ |
|
659 | + public function set_next_renewal_date( $value ) { |
|
660 | + $date = strtotime( $value ); |
|
661 | 661 | |
662 | 662 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
663 | 663 | $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) ); |
664 | 664 | return; |
665 | - } |
|
666 | - |
|
667 | - $this->set_prop( 'expiration', '' ); |
|
668 | - |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Alias for self::set_next_renewal_date(). |
|
673 | - * |
|
674 | - * @since 1.0.19 |
|
675 | - * @param string $value strtotime compliant date. |
|
676 | - */ |
|
677 | - public function set_expiration( $value ) { |
|
678 | - $this->set_next_renewal_date( $value ); |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Set the subscription's trial period. |
|
683 | - * |
|
684 | - * @since 1.0.19 |
|
685 | - * @param string $value trial period e.g 1 year. |
|
686 | - */ |
|
687 | - public function set_trial_period( $value ) { |
|
688 | - $this->set_prop( 'trial_period', $value ); |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Set the subscription's status. |
|
693 | - * |
|
694 | - * @since 1.0.19 |
|
695 | - * @param string $new_status New subscription status. |
|
696 | - */ |
|
697 | - public function set_status( $new_status ) { |
|
698 | - |
|
699 | - // Abort if this is not a valid status; |
|
700 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
701 | - return; |
|
702 | - } |
|
703 | - |
|
704 | - $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
705 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
706 | - $this->status_transition = array( |
|
707 | - 'from' => $old_status, |
|
708 | - 'to' => $new_status, |
|
709 | - ); |
|
710 | - } |
|
711 | - |
|
712 | - $this->set_prop( 'status', $new_status ); |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Set the subscription's (remote) profile id. |
|
717 | - * |
|
718 | - * @since 1.0.19 |
|
719 | - * @param string $value the remote profile id. |
|
720 | - */ |
|
721 | - public function set_profile_id( $value ) { |
|
722 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
723 | - } |
|
724 | - |
|
725 | - /* |
|
665 | + } |
|
666 | + |
|
667 | + $this->set_prop( 'expiration', '' ); |
|
668 | + |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * Alias for self::set_next_renewal_date(). |
|
673 | + * |
|
674 | + * @since 1.0.19 |
|
675 | + * @param string $value strtotime compliant date. |
|
676 | + */ |
|
677 | + public function set_expiration( $value ) { |
|
678 | + $this->set_next_renewal_date( $value ); |
|
679 | + } |
|
680 | + |
|
681 | + /** |
|
682 | + * Set the subscription's trial period. |
|
683 | + * |
|
684 | + * @since 1.0.19 |
|
685 | + * @param string $value trial period e.g 1 year. |
|
686 | + */ |
|
687 | + public function set_trial_period( $value ) { |
|
688 | + $this->set_prop( 'trial_period', $value ); |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Set the subscription's status. |
|
693 | + * |
|
694 | + * @since 1.0.19 |
|
695 | + * @param string $new_status New subscription status. |
|
696 | + */ |
|
697 | + public function set_status( $new_status ) { |
|
698 | + |
|
699 | + // Abort if this is not a valid status; |
|
700 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
701 | + return; |
|
702 | + } |
|
703 | + |
|
704 | + $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
705 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
706 | + $this->status_transition = array( |
|
707 | + 'from' => $old_status, |
|
708 | + 'to' => $new_status, |
|
709 | + ); |
|
710 | + } |
|
711 | + |
|
712 | + $this->set_prop( 'status', $new_status ); |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * Set the subscription's (remote) profile id. |
|
717 | + * |
|
718 | + * @since 1.0.19 |
|
719 | + * @param string $value the remote profile id. |
|
720 | + */ |
|
721 | + public function set_profile_id( $value ) { |
|
722 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
723 | + } |
|
724 | + |
|
725 | + /* |
|
726 | 726 | |-------------------------------------------------------------------------- |
727 | 727 | | Boolean methods |
728 | 728 | |-------------------------------------------------------------------------- |
@@ -731,55 +731,55 @@ discard block |
||
731 | 731 | | |
732 | 732 | */ |
733 | 733 | |
734 | - /** |
|
734 | + /** |
|
735 | 735 | * Checks if the subscription has a given status. |
736 | - * |
|
737 | - * @param string|array String or array of strings to check for. |
|
738 | - * @return bool |
|
736 | + * |
|
737 | + * @param string|array String or array of strings to check for. |
|
738 | + * @return bool |
|
739 | 739 | */ |
740 | 740 | public function has_status( $status ) { |
741 | 741 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
742 | - } |
|
742 | + } |
|
743 | 743 | |
744 | - /** |
|
744 | + /** |
|
745 | 745 | * Checks if the subscription has a trial period. |
746 | - * |
|
747 | - * @return bool |
|
746 | + * |
|
747 | + * @return bool |
|
748 | 748 | */ |
749 | 749 | public function has_trial_period() { |
750 | - $period = $this->get_trial_period(); |
|
750 | + $period = $this->get_trial_period(); |
|
751 | 751 | return ! empty( $period ); |
752 | - } |
|
753 | - |
|
754 | - /** |
|
755 | - * Is the subscription active? |
|
756 | - * |
|
757 | - * @return bool |
|
758 | - */ |
|
759 | - public function is_active() { |
|
760 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
761 | - } |
|
762 | - |
|
763 | - /** |
|
764 | - * Is the subscription expired? |
|
765 | - * |
|
766 | - * @return bool |
|
767 | - */ |
|
768 | - public function is_expired() { |
|
769 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * Is this the last renewals? |
|
774 | - * |
|
775 | - * @return bool |
|
776 | - */ |
|
777 | - public function is_last_renewal() { |
|
778 | - $max_bills = $this->get_bill_times(); |
|
779 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
780 | - } |
|
781 | - |
|
782 | - /* |
|
752 | + } |
|
753 | + |
|
754 | + /** |
|
755 | + * Is the subscription active? |
|
756 | + * |
|
757 | + * @return bool |
|
758 | + */ |
|
759 | + public function is_active() { |
|
760 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
761 | + } |
|
762 | + |
|
763 | + /** |
|
764 | + * Is the subscription expired? |
|
765 | + * |
|
766 | + * @return bool |
|
767 | + */ |
|
768 | + public function is_expired() { |
|
769 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Is this the last renewals? |
|
774 | + * |
|
775 | + * @return bool |
|
776 | + */ |
|
777 | + public function is_last_renewal() { |
|
778 | + $max_bills = $this->get_bill_times(); |
|
779 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
780 | + } |
|
781 | + |
|
782 | + /* |
|
783 | 783 | |-------------------------------------------------------------------------- |
784 | 784 | | Additional methods |
785 | 785 | |-------------------------------------------------------------------------- |
@@ -788,27 +788,27 @@ discard block |
||
788 | 788 | | |
789 | 789 | */ |
790 | 790 | |
791 | - /** |
|
792 | - * Backwards compatibilty. |
|
793 | - */ |
|
794 | - public function create( $data = array() ) { |
|
791 | + /** |
|
792 | + * Backwards compatibilty. |
|
793 | + */ |
|
794 | + public function create( $data = array() ) { |
|
795 | 795 | |
796 | - // Set the properties. |
|
797 | - if ( is_array( $data ) ) { |
|
798 | - $this->set_props( $data ); |
|
799 | - } |
|
796 | + // Set the properties. |
|
797 | + if ( is_array( $data ) ) { |
|
798 | + $this->set_props( $data ); |
|
799 | + } |
|
800 | 800 | |
801 | - // Save the item. |
|
802 | - return $this->save(); |
|
801 | + // Save the item. |
|
802 | + return $this->save(); |
|
803 | 803 | |
804 | - } |
|
804 | + } |
|
805 | 805 | |
806 | - /** |
|
807 | - * Backwards compatibilty. |
|
808 | - */ |
|
809 | - public function update( $args = array() ) { |
|
810 | - return $this->create( $args ); |
|
811 | - } |
|
806 | + /** |
|
807 | + * Backwards compatibilty. |
|
808 | + */ |
|
809 | + public function update( $args = array() ) { |
|
810 | + return $this->create( $args ); |
|
811 | + } |
|
812 | 812 | |
813 | 813 | /** |
814 | 814 | * Retrieve renewal payments for a subscription |
@@ -818,22 +818,22 @@ discard block |
||
818 | 818 | */ |
819 | 819 | public function get_child_payments( $hide_pending = true ) { |
820 | 820 | |
821 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
821 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
822 | 822 | |
823 | - if ( ! $hide_pending ) { |
|
824 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
825 | - } |
|
823 | + if ( ! $hide_pending ) { |
|
824 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
825 | + } |
|
826 | 826 | |
827 | 827 | return get_posts( |
828 | - array( |
|
829 | - 'post_parent' => $this->get_parent_payment_id(), |
|
830 | - 'numberposts' => -1, |
|
831 | - 'post_status' => $statuses, |
|
832 | - 'orderby' => 'ID', |
|
833 | - 'order' => 'ASC', |
|
834 | - 'post_type' => 'wpi_invoice', |
|
835 | - ) |
|
836 | - ); |
|
828 | + array( |
|
829 | + 'post_parent' => $this->get_parent_payment_id(), |
|
830 | + 'numberposts' => -1, |
|
831 | + 'post_status' => $statuses, |
|
832 | + 'orderby' => 'ID', |
|
833 | + 'order' => 'ASC', |
|
834 | + 'post_type' => 'wpi_invoice', |
|
835 | + ) |
|
836 | + ); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | * @return int |
844 | 844 | */ |
845 | 845 | public function get_total_payments() { |
846 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
846 | + return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
@@ -867,202 +867,202 @@ discard block |
||
867 | 867 | * |
868 | 868 | * @since 2.4 |
869 | 869 | * @param array $args Array of values for the payment, including amount and transaction ID |
870 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
870 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
871 | 871 | * @return bool |
872 | 872 | */ |
873 | 873 | public function add_payment( $args = array(), $invoice = false ) { |
874 | 874 | |
875 | - // Process each payment once. |
|
875 | + // Process each payment once. |
|
876 | 876 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
877 | 877 | return false; |
878 | 878 | } |
879 | 879 | |
880 | - // Are we creating a new invoice? |
|
881 | - if ( empty( $invoice ) ) { |
|
882 | - $invoice = $this->create_payment( false ); |
|
880 | + // Are we creating a new invoice? |
|
881 | + if ( empty( $invoice ) ) { |
|
882 | + $invoice = $this->create_payment( false ); |
|
883 | 883 | |
884 | - if ( empty( $invoice ) ) { |
|
885 | - return false; |
|
886 | - } |
|
887 | - } |
|
884 | + if ( empty( $invoice ) ) { |
|
885 | + return false; |
|
886 | + } |
|
887 | + } |
|
888 | 888 | |
889 | - // Maybe set a transaction id. |
|
890 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
891 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
892 | - } |
|
889 | + // Maybe set a transaction id. |
|
890 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
891 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
892 | + } |
|
893 | 893 | |
894 | - // Set the completed date. |
|
895 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
894 | + // Set the completed date. |
|
895 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
896 | 896 | |
897 | - // And the gateway. |
|
898 | - if ( ! empty( $args['gateway'] ) ) { |
|
899 | - $invoice->set_gateway( $args['gateway'] ); |
|
900 | - } |
|
897 | + // And the gateway. |
|
898 | + if ( ! empty( $args['gateway'] ) ) { |
|
899 | + $invoice->set_gateway( $args['gateway'] ); |
|
900 | + } |
|
901 | 901 | |
902 | - $invoice->set_status( 'wpi-renewal' ); |
|
903 | - $invoice->save(); |
|
902 | + $invoice->set_status( 'wpi-renewal' ); |
|
903 | + $invoice->save(); |
|
904 | 904 | |
905 | - if ( ! $invoice->exists() ) { |
|
906 | - return false; |
|
907 | - } |
|
905 | + if ( ! $invoice->exists() ) { |
|
906 | + return false; |
|
907 | + } |
|
908 | 908 | |
909 | - return $this->after_add_payment( $invoice ); |
|
910 | - } |
|
909 | + return $this->after_add_payment( $invoice ); |
|
910 | + } |
|
911 | 911 | |
912 | 912 | public function after_add_payment( $invoice ) { |
913 | 913 | |
914 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
915 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
914 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
915 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
916 | 916 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
917 | 917 | |
918 | 918 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
919 | 919 | |
920 | 920 | return $invoice->get_id(); |
921 | - } |
|
921 | + } |
|
922 | 922 | |
923 | - /** |
|
923 | + /** |
|
924 | 924 | * Creates a new invoice and returns it. |
925 | 925 | * |
926 | 926 | * @since 1.0.19 |
927 | - * @param bool $save Whether we should save the invoice. |
|
927 | + * @param bool $save Whether we should save the invoice. |
|
928 | 928 | * @return WPInv_Invoice|bool |
929 | 929 | */ |
930 | 930 | public function create_payment( $save = true ) { |
931 | 931 | |
932 | - $parent_invoice = $this->get_parent_payment(); |
|
933 | - |
|
934 | - if ( ! $parent_invoice->exists() ) { |
|
935 | - return false; |
|
936 | - } |
|
937 | - |
|
938 | - // Duplicate the parent invoice. |
|
939 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
940 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
941 | - $invoice->set_subscription_id( $this->get_id() ); |
|
942 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
943 | - |
|
944 | - // Set invoice items. |
|
945 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
946 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
947 | - $invoice_items = array(); |
|
948 | - |
|
949 | - foreach ( $invoice->get_items() as $item ) { |
|
950 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
951 | - $invoice_items[] = $item; |
|
952 | - } |
|
953 | - } |
|
954 | - |
|
955 | - $invoice->set_items( $invoice_items ); |
|
956 | - |
|
957 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
958 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
959 | - } |
|
960 | - |
|
961 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
962 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
963 | - |
|
964 | - if ( $discount->exists() && $discount->is_recurring() ) { |
|
965 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
966 | - } else { |
|
967 | - // Unset discount code. |
|
968 | - $invoice->set_discount_code( '' ); |
|
969 | - |
|
970 | - $invoice->remove_discount( 'discount_code' ); |
|
971 | - } |
|
972 | - |
|
973 | - $invoice->recalculate_total(); |
|
974 | - $invoice->set_status( 'wpi-pending' ); |
|
975 | - |
|
976 | - if ( ! $save ) { |
|
977 | - return $invoice; |
|
978 | - } |
|
979 | - |
|
980 | - $invoice->save(); |
|
981 | - |
|
982 | - return $invoice->exists() ? $invoice : false; |
|
983 | - } |
|
984 | - |
|
985 | - /** |
|
986 | - * Renews or completes a subscription |
|
987 | - * |
|
988 | - * @since 1.0.0 |
|
989 | - * @return int The subscription's id |
|
990 | - */ |
|
991 | - public function renew( $calculate_from = null, $_new_expiration = null ) { |
|
992 | - // Complete subscription if applicable |
|
993 | - if ( $this->is_last_renewal() ) { |
|
994 | - return $this->complete(); |
|
995 | - } |
|
996 | - |
|
997 | - if ( ! empty( $_new_expiration ) ) { |
|
998 | - $new_expiration = $_new_expiration; |
|
999 | - } else { |
|
1000 | - // Calculate new expiration |
|
1001 | - $frequency = $this->get_frequency(); |
|
1002 | - $period = $this->get_period(); |
|
1003 | - $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
1004 | - $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
1005 | - $new_expiration = date( 'Y-m-d H:i:s', $new_expiration ); |
|
1006 | - } |
|
1007 | - |
|
1008 | - $this->set_expiration( $new_expiration ); |
|
1009 | - $this->set_status( 'active' ); |
|
1010 | - $this->save(); |
|
1011 | - |
|
1012 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
1013 | - |
|
1014 | - return $this->get_id(); |
|
1015 | - } |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * Marks a subscription as completed |
|
1019 | - * |
|
1020 | - * Subscription is completed when the number of payments matches the billing_times field |
|
1021 | - * |
|
1022 | - * @since 1.0.0 |
|
1023 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1024 | - */ |
|
1025 | - public function complete() { |
|
1026 | - |
|
1027 | - // Only mark a subscription as complete if it's not already cancelled. |
|
1028 | - if ( $this->has_status( 'cancelled' ) ) { |
|
1029 | - return false; |
|
1030 | - } |
|
1031 | - |
|
1032 | - $this->set_status( 'completed' ); |
|
1033 | - return $this->save(); |
|
1034 | - |
|
1035 | - } |
|
1036 | - |
|
1037 | - /** |
|
1038 | - * Marks a subscription as expired |
|
1039 | - * |
|
1040 | - * @since 1.0.0 |
|
1041 | - * @param bool $check_expiration |
|
1042 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1043 | - */ |
|
1044 | - public function expire( $check_expiration = false ) { |
|
1045 | - |
|
1046 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1047 | - // Do not mark as expired since real expiration date is in the future |
|
1048 | - return false; |
|
1049 | - } |
|
1050 | - |
|
1051 | - $this->set_status( 'expired' ); |
|
1052 | - return $this->save(); |
|
1053 | - |
|
1054 | - } |
|
1055 | - |
|
1056 | - /** |
|
1057 | - * Marks a subscription as failing |
|
1058 | - * |
|
1059 | - * @since 2.4.2 |
|
1060 | - * @return int Subscription id. |
|
1061 | - */ |
|
1062 | - public function failing() { |
|
1063 | - $this->set_status( 'failing' ); |
|
1064 | - return $this->save(); |
|
1065 | - } |
|
932 | + $parent_invoice = $this->get_parent_payment(); |
|
933 | + |
|
934 | + if ( ! $parent_invoice->exists() ) { |
|
935 | + return false; |
|
936 | + } |
|
937 | + |
|
938 | + // Duplicate the parent invoice. |
|
939 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
940 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
941 | + $invoice->set_subscription_id( $this->get_id() ); |
|
942 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
943 | + |
|
944 | + // Set invoice items. |
|
945 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
946 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
947 | + $invoice_items = array(); |
|
948 | + |
|
949 | + foreach ( $invoice->get_items() as $item ) { |
|
950 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
951 | + $invoice_items[] = $item; |
|
952 | + } |
|
953 | + } |
|
954 | + |
|
955 | + $invoice->set_items( $invoice_items ); |
|
956 | + |
|
957 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
958 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
959 | + } |
|
960 | + |
|
961 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
962 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
963 | + |
|
964 | + if ( $discount->exists() && $discount->is_recurring() ) { |
|
965 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
966 | + } else { |
|
967 | + // Unset discount code. |
|
968 | + $invoice->set_discount_code( '' ); |
|
969 | + |
|
970 | + $invoice->remove_discount( 'discount_code' ); |
|
971 | + } |
|
972 | + |
|
973 | + $invoice->recalculate_total(); |
|
974 | + $invoice->set_status( 'wpi-pending' ); |
|
975 | + |
|
976 | + if ( ! $save ) { |
|
977 | + return $invoice; |
|
978 | + } |
|
979 | + |
|
980 | + $invoice->save(); |
|
981 | + |
|
982 | + return $invoice->exists() ? $invoice : false; |
|
983 | + } |
|
984 | + |
|
985 | + /** |
|
986 | + * Renews or completes a subscription |
|
987 | + * |
|
988 | + * @since 1.0.0 |
|
989 | + * @return int The subscription's id |
|
990 | + */ |
|
991 | + public function renew( $calculate_from = null, $_new_expiration = null ) { |
|
992 | + // Complete subscription if applicable |
|
993 | + if ( $this->is_last_renewal() ) { |
|
994 | + return $this->complete(); |
|
995 | + } |
|
996 | + |
|
997 | + if ( ! empty( $_new_expiration ) ) { |
|
998 | + $new_expiration = $_new_expiration; |
|
999 | + } else { |
|
1000 | + // Calculate new expiration |
|
1001 | + $frequency = $this->get_frequency(); |
|
1002 | + $period = $this->get_period(); |
|
1003 | + $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
1004 | + $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
1005 | + $new_expiration = date( 'Y-m-d H:i:s', $new_expiration ); |
|
1006 | + } |
|
1007 | + |
|
1008 | + $this->set_expiration( $new_expiration ); |
|
1009 | + $this->set_status( 'active' ); |
|
1010 | + $this->save(); |
|
1011 | + |
|
1012 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
1013 | + |
|
1014 | + return $this->get_id(); |
|
1015 | + } |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * Marks a subscription as completed |
|
1019 | + * |
|
1020 | + * Subscription is completed when the number of payments matches the billing_times field |
|
1021 | + * |
|
1022 | + * @since 1.0.0 |
|
1023 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1024 | + */ |
|
1025 | + public function complete() { |
|
1026 | + |
|
1027 | + // Only mark a subscription as complete if it's not already cancelled. |
|
1028 | + if ( $this->has_status( 'cancelled' ) ) { |
|
1029 | + return false; |
|
1030 | + } |
|
1031 | + |
|
1032 | + $this->set_status( 'completed' ); |
|
1033 | + return $this->save(); |
|
1034 | + |
|
1035 | + } |
|
1036 | + |
|
1037 | + /** |
|
1038 | + * Marks a subscription as expired |
|
1039 | + * |
|
1040 | + * @since 1.0.0 |
|
1041 | + * @param bool $check_expiration |
|
1042 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1043 | + */ |
|
1044 | + public function expire( $check_expiration = false ) { |
|
1045 | + |
|
1046 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1047 | + // Do not mark as expired since real expiration date is in the future |
|
1048 | + return false; |
|
1049 | + } |
|
1050 | + |
|
1051 | + $this->set_status( 'expired' ); |
|
1052 | + return $this->save(); |
|
1053 | + |
|
1054 | + } |
|
1055 | + |
|
1056 | + /** |
|
1057 | + * Marks a subscription as failing |
|
1058 | + * |
|
1059 | + * @since 2.4.2 |
|
1060 | + * @return int Subscription id. |
|
1061 | + */ |
|
1062 | + public function failing() { |
|
1063 | + $this->set_status( 'failing' ); |
|
1064 | + return $this->save(); |
|
1065 | + } |
|
1066 | 1066 | |
1067 | 1067 | /** |
1068 | 1068 | * Marks a subscription as cancelled |
@@ -1071,19 +1071,19 @@ discard block |
||
1071 | 1071 | * @return int Subscription id. |
1072 | 1072 | */ |
1073 | 1073 | public function cancel() { |
1074 | - $this->set_status( 'cancelled' ); |
|
1075 | - return $this->save(); |
|
1074 | + $this->set_status( 'cancelled' ); |
|
1075 | + return $this->save(); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | - /** |
|
1079 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1080 | - * |
|
1081 | - * @since 1.0.0 |
|
1082 | - * @return bool |
|
1083 | - */ |
|
1084 | - public function can_cancel() { |
|
1085 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1086 | - } |
|
1078 | + /** |
|
1079 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1080 | + * |
|
1081 | + * @since 1.0.0 |
|
1082 | + * @return bool |
|
1083 | + */ |
|
1084 | + public function can_cancel() { |
|
1085 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1086 | + } |
|
1087 | 1087 | |
1088 | 1088 | /** |
1089 | 1089 | * Returns an array of subscription statuses that can be cancelled |
@@ -1096,109 +1096,109 @@ discard block |
||
1096 | 1096 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - /** |
|
1100 | - * Retrieves the URL to cancel subscription |
|
1101 | - * |
|
1102 | - * @since 1.0.0 |
|
1103 | - * @return string |
|
1104 | - */ |
|
1105 | - public function get_cancel_url() { |
|
1106 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1107 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1108 | - } |
|
1109 | - |
|
1110 | - /** |
|
1111 | - * Retrieves the URL to view a subscription |
|
1112 | - * |
|
1113 | - * @since 1.0.19 |
|
1114 | - * @return string |
|
1115 | - */ |
|
1116 | - public function get_view_url() { |
|
1117 | - |
|
1118 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1119 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1120 | - |
|
1121 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1122 | - } |
|
1123 | - |
|
1124 | - /** |
|
1125 | - * Determines if subscription can be manually renewed |
|
1126 | - * |
|
1127 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1128 | - * that can be renewed manually |
|
1129 | - * |
|
1130 | - * @since 2.5 |
|
1131 | - * @return bool |
|
1132 | - */ |
|
1133 | - public function can_renew() { |
|
1134 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1135 | - } |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * Retrieves the URL to renew a subscription |
|
1139 | - * |
|
1140 | - * @since 2.5 |
|
1141 | - * @return string |
|
1142 | - */ |
|
1143 | - public function get_renew_url() { |
|
1144 | - $url = wp_nonce_url( |
|
1099 | + /** |
|
1100 | + * Retrieves the URL to cancel subscription |
|
1101 | + * |
|
1102 | + * @since 1.0.0 |
|
1103 | + * @return string |
|
1104 | + */ |
|
1105 | + public function get_cancel_url() { |
|
1106 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1107 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1108 | + } |
|
1109 | + |
|
1110 | + /** |
|
1111 | + * Retrieves the URL to view a subscription |
|
1112 | + * |
|
1113 | + * @since 1.0.19 |
|
1114 | + * @return string |
|
1115 | + */ |
|
1116 | + public function get_view_url() { |
|
1117 | + |
|
1118 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1119 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1120 | + |
|
1121 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1122 | + } |
|
1123 | + |
|
1124 | + /** |
|
1125 | + * Determines if subscription can be manually renewed |
|
1126 | + * |
|
1127 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1128 | + * that can be renewed manually |
|
1129 | + * |
|
1130 | + * @since 2.5 |
|
1131 | + * @return bool |
|
1132 | + */ |
|
1133 | + public function can_renew() { |
|
1134 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1135 | + } |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * Retrieves the URL to renew a subscription |
|
1139 | + * |
|
1140 | + * @since 2.5 |
|
1141 | + * @return string |
|
1142 | + */ |
|
1143 | + public function get_renew_url() { |
|
1144 | + $url = wp_nonce_url( |
|
1145 | 1145 | add_query_arg( |
1146 | 1146 | array( |
1147 | - 'getpaid-action' => 'renew_subscription', |
|
1148 | - 'sub_id' => $this->get_id, |
|
1147 | + 'getpaid-action' => 'renew_subscription', |
|
1148 | + 'sub_id' => $this->get_id, |
|
1149 | 1149 | ) |
1150 | 1150 | ), |
1151 | 1151 | 'getpaid-nonce' |
1152 | 1152 | ); |
1153 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1154 | - } |
|
1155 | - |
|
1156 | - /** |
|
1157 | - * Determines if subscription can have their payment method updated |
|
1158 | - * |
|
1159 | - * @since 1.0.0 |
|
1160 | - * @return bool |
|
1161 | - */ |
|
1162 | - public function can_update() { |
|
1163 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1164 | - } |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * Retrieves the URL to update subscription |
|
1168 | - * |
|
1169 | - * @since 1.0.0 |
|
1170 | - * @return string |
|
1171 | - */ |
|
1172 | - public function get_update_url() { |
|
1173 | - $url = add_query_arg( |
|
1153 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1154 | + } |
|
1155 | + |
|
1156 | + /** |
|
1157 | + * Determines if subscription can have their payment method updated |
|
1158 | + * |
|
1159 | + * @since 1.0.0 |
|
1160 | + * @return bool |
|
1161 | + */ |
|
1162 | + public function can_update() { |
|
1163 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1164 | + } |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * Retrieves the URL to update subscription |
|
1168 | + * |
|
1169 | + * @since 1.0.0 |
|
1170 | + * @return string |
|
1171 | + */ |
|
1172 | + public function get_update_url() { |
|
1173 | + $url = add_query_arg( |
|
1174 | 1174 | array( |
1175 | - 'action' => 'update', |
|
1176 | - 'subscription_id' => $this->get_id(), |
|
1175 | + 'action' => 'update', |
|
1176 | + 'subscription_id' => $this->get_id(), |
|
1177 | 1177 | ) |
1178 | 1178 | ); |
1179 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1180 | - } |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * Retrieves the subscription status label |
|
1184 | - * |
|
1185 | - * @since 1.0.0 |
|
1186 | - * @return string |
|
1187 | - */ |
|
1188 | - public function get_status_label() { |
|
1189 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1190 | - } |
|
1191 | - |
|
1192 | - /** |
|
1193 | - * Retrieves the subscription status class |
|
1194 | - * |
|
1195 | - * @since 1.0.19 |
|
1196 | - * @return string |
|
1197 | - */ |
|
1198 | - public function get_status_class() { |
|
1199 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1200 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
1201 | - } |
|
1179 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1180 | + } |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * Retrieves the subscription status label |
|
1184 | + * |
|
1185 | + * @since 1.0.0 |
|
1186 | + * @return string |
|
1187 | + */ |
|
1188 | + public function get_status_label() { |
|
1189 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1190 | + } |
|
1191 | + |
|
1192 | + /** |
|
1193 | + * Retrieves the subscription status class |
|
1194 | + * |
|
1195 | + * @since 1.0.19 |
|
1196 | + * @return string |
|
1197 | + */ |
|
1198 | + public function get_status_class() { |
|
1199 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1200 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
1201 | + } |
|
1202 | 1202 | |
1203 | 1203 | /** |
1204 | 1204 | * Retrieves the subscription status label |
@@ -1208,11 +1208,11 @@ discard block |
||
1208 | 1208 | */ |
1209 | 1209 | public function get_status_label_html() { |
1210 | 1210 | |
1211 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1212 | - $class = esc_attr( $this->get_status_class() ); |
|
1213 | - $status = sanitize_html_class( $this->get_status() ); |
|
1211 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1212 | + $class = esc_attr( $this->get_status_class() ); |
|
1213 | + $status = sanitize_html_class( $this->get_status() ); |
|
1214 | 1214 | |
1215 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1215 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1216 | 1216 | } |
1217 | 1217 | |
1218 | 1218 | /** |
@@ -1223,75 +1223,75 @@ discard block |
||
1223 | 1223 | * @return bool |
1224 | 1224 | */ |
1225 | 1225 | public function payment_exists( $txn_id = '' ) { |
1226 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1226 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1227 | 1227 | return ! empty( $invoice_id ); |
1228 | - } |
|
1229 | - |
|
1230 | - /** |
|
1231 | - * Handle the status transition. |
|
1232 | - */ |
|
1233 | - protected function status_transition() { |
|
1234 | - $status_transition = $this->status_transition; |
|
1235 | - |
|
1236 | - // Reset status transition variable. |
|
1237 | - $this->status_transition = false; |
|
1238 | - |
|
1239 | - if ( $status_transition ) { |
|
1240 | - try { |
|
1241 | - |
|
1242 | - // Fire a hook for the status change. |
|
1243 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1244 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1245 | - |
|
1246 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1247 | - |
|
1248 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1249 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1250 | - |
|
1251 | - // Note the transition occurred. |
|
1252 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1253 | - |
|
1254 | - // Fire another hook. |
|
1255 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1256 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1257 | - |
|
1258 | - } else { |
|
1259 | - /* translators: %s: new invoice status */ |
|
1260 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1261 | - |
|
1262 | - // Note the transition occurred. |
|
1263 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1264 | - |
|
1265 | - } |
|
1266 | - } catch ( Exception $e ) { |
|
1267 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1268 | - } |
|
1269 | - } |
|
1270 | - |
|
1271 | - } |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * Save data to the database. |
|
1275 | - * |
|
1276 | - * @since 1.0.19 |
|
1277 | - * @return int subscription ID |
|
1278 | - */ |
|
1279 | - public function save() { |
|
1280 | - parent::save(); |
|
1281 | - $this->status_transition(); |
|
1282 | - return $this->get_id(); |
|
1283 | - } |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * Activates a subscription. |
|
1287 | - * |
|
1288 | - * @since 1.0.19 |
|
1289 | - * @return int subscription ID |
|
1290 | - */ |
|
1291 | - public function activate() { |
|
1292 | - $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1293 | - $this->set_status( $status ); |
|
1294 | - return $this->save(); |
|
1295 | - } |
|
1228 | + } |
|
1229 | + |
|
1230 | + /** |
|
1231 | + * Handle the status transition. |
|
1232 | + */ |
|
1233 | + protected function status_transition() { |
|
1234 | + $status_transition = $this->status_transition; |
|
1235 | + |
|
1236 | + // Reset status transition variable. |
|
1237 | + $this->status_transition = false; |
|
1238 | + |
|
1239 | + if ( $status_transition ) { |
|
1240 | + try { |
|
1241 | + |
|
1242 | + // Fire a hook for the status change. |
|
1243 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1244 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1245 | + |
|
1246 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1247 | + |
|
1248 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1249 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1250 | + |
|
1251 | + // Note the transition occurred. |
|
1252 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1253 | + |
|
1254 | + // Fire another hook. |
|
1255 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1256 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1257 | + |
|
1258 | + } else { |
|
1259 | + /* translators: %s: new invoice status */ |
|
1260 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1261 | + |
|
1262 | + // Note the transition occurred. |
|
1263 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1264 | + |
|
1265 | + } |
|
1266 | + } catch ( Exception $e ) { |
|
1267 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1268 | + } |
|
1269 | + } |
|
1270 | + |
|
1271 | + } |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * Save data to the database. |
|
1275 | + * |
|
1276 | + * @since 1.0.19 |
|
1277 | + * @return int subscription ID |
|
1278 | + */ |
|
1279 | + public function save() { |
|
1280 | + parent::save(); |
|
1281 | + $this->status_transition(); |
|
1282 | + return $this->get_id(); |
|
1283 | + } |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * Activates a subscription. |
|
1287 | + * |
|
1288 | + * @since 1.0.19 |
|
1289 | + * @return int subscription ID |
|
1290 | + */ |
|
1291 | + public function activate() { |
|
1292 | + $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1293 | + $this->set_status( $status ); |
|
1294 | + return $this->save(); |
|
1295 | + } |
|
1296 | 1296 | |
1297 | 1297 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,1305 +11,1305 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Input { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function input( $args = array() ) { |
|
22 | - global $aui_bs5; |
|
23 | - |
|
24 | - $defaults = array( |
|
25 | - 'type' => 'text', |
|
26 | - 'name' => '', |
|
27 | - 'class' => '', |
|
28 | - 'wrap_class' => '', |
|
29 | - 'id' => '', |
|
30 | - 'placeholder' => '', |
|
31 | - 'title' => '', |
|
32 | - 'value' => '', |
|
33 | - 'required' => false, |
|
34 | - 'size' => '', // sm, lg, small, large |
|
35 | - 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
36 | - 'with_hidden' => false, // Append hidden field for single checkbox. |
|
37 | - 'label' => '', |
|
38 | - 'label_after' => false, |
|
39 | - 'label_class' => '', |
|
40 | - 'label_col' => '2', |
|
41 | - 'label_type' => '', // top, horizontal, empty = hidden |
|
42 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
43 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
44 | - 'help_text' => '', |
|
45 | - 'validation_text' => '', |
|
46 | - 'validation_pattern' => '', |
|
47 | - 'no_wrap' => false, |
|
48 | - 'input_group_right' => '', |
|
49 | - 'input_group_left' => '', |
|
50 | - 'input_group_right_inside' => false, |
|
51 | - // forces the input group inside the input |
|
52 | - 'input_group_left_inside' => false, |
|
53 | - // forces the input group inside the input |
|
54 | - 'form_group_class' => '', |
|
55 | - 'step' => '', |
|
56 | - 'switch' => false, |
|
57 | - // to show checkbox as a switch |
|
58 | - 'checked' => false, |
|
59 | - // set a checkbox or radio as selected |
|
60 | - 'password_toggle' => true, |
|
61 | - // toggle view/hide password |
|
62 | - 'element_require' => '', |
|
63 | - // [%element_id%] == "1" |
|
64 | - 'extra_attributes' => array(), |
|
65 | - // an array of extra attributes |
|
66 | - 'wrap_attributes' => array() |
|
67 | - ); |
|
68 | - |
|
69 | - /** |
|
70 | - * Parse incoming $args into an array and merge it with $defaults |
|
71 | - */ |
|
72 | - $args = wp_parse_args( $args, $defaults ); |
|
73 | - $output = ''; |
|
74 | - if ( ! empty( $args['type'] ) ) { |
|
75 | - // hidden label option needs to be empty |
|
76 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
77 | - |
|
78 | - $type = sanitize_html_class( $args['type'] ); |
|
79 | - |
|
80 | - $help_text = ''; |
|
81 | - $label = ''; |
|
82 | - $label_after = $args['label_after']; |
|
83 | - $label_args = array( |
|
84 | - 'title' => $args['label'], |
|
85 | - 'for' => $args['id'], |
|
86 | - 'class' => $args['label_class'] . " ", |
|
87 | - 'label_type' => $args['label_type'], |
|
88 | - 'label_col' => $args['label_col'] |
|
89 | - ); |
|
90 | - |
|
91 | - // floating labels need label after |
|
92 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
93 | - $label_after = true; |
|
94 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
95 | - } |
|
96 | - |
|
97 | - // size |
|
98 | - $size = ''; |
|
99 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
100 | - $size = 'lg'; |
|
101 | - $args['class'] .= ' form-control-lg'; |
|
102 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
103 | - $size = 'sm'; |
|
104 | - $args['class'] .= ' form-control-sm'; |
|
105 | - } |
|
106 | - |
|
107 | - // clear function |
|
108 | - $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
109 | - |
|
110 | - // Some special sauce for files |
|
111 | - if ( $type == 'file' ) { |
|
112 | - $label_after = true; // if type file we need the label after |
|
113 | - $args['class'] .= ' custom-file-input '; |
|
114 | - } elseif ( $type == 'checkbox' ) { |
|
115 | - $label_after = true; // if type file we need the label after |
|
116 | - $args['class'] .= $aui_bs5 ? ' form-check-input c-pointer ' : ' custom-control-input c-pointer '; |
|
117 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
118 | - $orig_type = $type; |
|
119 | - $type = 'text'; |
|
120 | - $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
121 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
122 | - |
|
123 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
124 | - |
|
125 | - // Disable native datetime inputs. |
|
126 | - $disable_mobile_attr = isset( $args['extra_attributes']['data-disable-mobile'] ) ? $args['extra_attributes']['data-disable-mobile'] : 'true'; |
|
127 | - $disable_mobile_attr = apply_filters( 'aui_flatpickr_disable_disable_mobile_attr', $disable_mobile_attr, $args ); |
|
128 | - |
|
129 | - $args['extra_attributes']['data-disable-mobile'] = $disable_mobile_attr; |
|
130 | - |
|
131 | - // set a way to clear field if empty |
|
132 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
133 | - $args['input_group_right_inside'] = true; |
|
134 | - $args['clear_icon'] = true; |
|
135 | - } |
|
136 | - |
|
137 | - // enqueue the script |
|
138 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
139 | - $aui_settings->enqueue_flatpickr(); |
|
140 | - } elseif ( $type == 'iconpicker' ) { |
|
141 | - $type = 'text'; |
|
142 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function input( $args = array() ) { |
|
22 | + global $aui_bs5; |
|
23 | + |
|
24 | + $defaults = array( |
|
25 | + 'type' => 'text', |
|
26 | + 'name' => '', |
|
27 | + 'class' => '', |
|
28 | + 'wrap_class' => '', |
|
29 | + 'id' => '', |
|
30 | + 'placeholder' => '', |
|
31 | + 'title' => '', |
|
32 | + 'value' => '', |
|
33 | + 'required' => false, |
|
34 | + 'size' => '', // sm, lg, small, large |
|
35 | + 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
36 | + 'with_hidden' => false, // Append hidden field for single checkbox. |
|
37 | + 'label' => '', |
|
38 | + 'label_after' => false, |
|
39 | + 'label_class' => '', |
|
40 | + 'label_col' => '2', |
|
41 | + 'label_type' => '', // top, horizontal, empty = hidden |
|
42 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
43 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
44 | + 'help_text' => '', |
|
45 | + 'validation_text' => '', |
|
46 | + 'validation_pattern' => '', |
|
47 | + 'no_wrap' => false, |
|
48 | + 'input_group_right' => '', |
|
49 | + 'input_group_left' => '', |
|
50 | + 'input_group_right_inside' => false, |
|
51 | + // forces the input group inside the input |
|
52 | + 'input_group_left_inside' => false, |
|
53 | + // forces the input group inside the input |
|
54 | + 'form_group_class' => '', |
|
55 | + 'step' => '', |
|
56 | + 'switch' => false, |
|
57 | + // to show checkbox as a switch |
|
58 | + 'checked' => false, |
|
59 | + // set a checkbox or radio as selected |
|
60 | + 'password_toggle' => true, |
|
61 | + // toggle view/hide password |
|
62 | + 'element_require' => '', |
|
63 | + // [%element_id%] == "1" |
|
64 | + 'extra_attributes' => array(), |
|
65 | + // an array of extra attributes |
|
66 | + 'wrap_attributes' => array() |
|
67 | + ); |
|
68 | + |
|
69 | + /** |
|
70 | + * Parse incoming $args into an array and merge it with $defaults |
|
71 | + */ |
|
72 | + $args = wp_parse_args( $args, $defaults ); |
|
73 | + $output = ''; |
|
74 | + if ( ! empty( $args['type'] ) ) { |
|
75 | + // hidden label option needs to be empty |
|
76 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
77 | + |
|
78 | + $type = sanitize_html_class( $args['type'] ); |
|
79 | + |
|
80 | + $help_text = ''; |
|
81 | + $label = ''; |
|
82 | + $label_after = $args['label_after']; |
|
83 | + $label_args = array( |
|
84 | + 'title' => $args['label'], |
|
85 | + 'for' => $args['id'], |
|
86 | + 'class' => $args['label_class'] . " ", |
|
87 | + 'label_type' => $args['label_type'], |
|
88 | + 'label_col' => $args['label_col'] |
|
89 | + ); |
|
90 | + |
|
91 | + // floating labels need label after |
|
92 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
93 | + $label_after = true; |
|
94 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
95 | + } |
|
96 | + |
|
97 | + // size |
|
98 | + $size = ''; |
|
99 | + if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
100 | + $size = 'lg'; |
|
101 | + $args['class'] .= ' form-control-lg'; |
|
102 | + }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
103 | + $size = 'sm'; |
|
104 | + $args['class'] .= ' form-control-sm'; |
|
105 | + } |
|
106 | + |
|
107 | + // clear function |
|
108 | + $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
109 | + |
|
110 | + // Some special sauce for files |
|
111 | + if ( $type == 'file' ) { |
|
112 | + $label_after = true; // if type file we need the label after |
|
113 | + $args['class'] .= ' custom-file-input '; |
|
114 | + } elseif ( $type == 'checkbox' ) { |
|
115 | + $label_after = true; // if type file we need the label after |
|
116 | + $args['class'] .= $aui_bs5 ? ' form-check-input c-pointer ' : ' custom-control-input c-pointer '; |
|
117 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
118 | + $orig_type = $type; |
|
119 | + $type = 'text'; |
|
120 | + $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
121 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
122 | + |
|
123 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
124 | + |
|
125 | + // Disable native datetime inputs. |
|
126 | + $disable_mobile_attr = isset( $args['extra_attributes']['data-disable-mobile'] ) ? $args['extra_attributes']['data-disable-mobile'] : 'true'; |
|
127 | + $disable_mobile_attr = apply_filters( 'aui_flatpickr_disable_disable_mobile_attr', $disable_mobile_attr, $args ); |
|
128 | + |
|
129 | + $args['extra_attributes']['data-disable-mobile'] = $disable_mobile_attr; |
|
130 | + |
|
131 | + // set a way to clear field if empty |
|
132 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
133 | + $args['input_group_right_inside'] = true; |
|
134 | + $args['clear_icon'] = true; |
|
135 | + } |
|
136 | + |
|
137 | + // enqueue the script |
|
138 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
139 | + $aui_settings->enqueue_flatpickr(); |
|
140 | + } elseif ( $type == 'iconpicker' ) { |
|
141 | + $type = 'text'; |
|
142 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
143 | 143 | // $args['class'] .= ' bg-initial '; |
144 | 144 | |
145 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
146 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
145 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
146 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
147 | 147 | |
148 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
148 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
149 | 149 | // $args['input_group_right_inside'] = true; |
150 | - // enqueue the script |
|
151 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
152 | - $aui_settings->enqueue_iconpicker(); |
|
153 | - } |
|
154 | - |
|
155 | - if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
156 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
157 | - } |
|
158 | - |
|
159 | - // allow clear icon |
|
160 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
161 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
162 | - $args['input_group_right_inside'] = true; |
|
163 | - $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
164 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
165 | - } |
|
166 | - |
|
167 | - // open/type |
|
168 | - $output .= '<input type="' . $type . '" '; |
|
169 | - |
|
170 | - // name |
|
171 | - if ( ! empty( $args['name'] ) ) { |
|
172 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
173 | - } |
|
174 | - |
|
175 | - // id |
|
176 | - if ( ! empty( $args['id'] ) ) { |
|
177 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
178 | - } |
|
179 | - |
|
180 | - // placeholder |
|
181 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
182 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
183 | - } |
|
184 | - |
|
185 | - // title |
|
186 | - if ( ! empty( $args['title'] ) ) { |
|
187 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
188 | - } |
|
189 | - |
|
190 | - // value |
|
191 | - if ( ! empty( $args['value'] ) ) { |
|
192 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
193 | - } |
|
194 | - |
|
195 | - // checked, for radio and checkboxes |
|
196 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
197 | - $output .= ' checked '; |
|
198 | - } |
|
199 | - |
|
200 | - // validation text |
|
201 | - if ( ! empty( $args['validation_text'] ) ) { |
|
202 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
203 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
204 | - } |
|
205 | - |
|
206 | - // validation_pattern |
|
207 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
208 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
209 | - } |
|
210 | - |
|
211 | - // step (for numbers) |
|
212 | - if ( ! empty( $args['step'] ) ) { |
|
213 | - $output .= ' step="' . $args['step'] . '" '; |
|
214 | - } |
|
215 | - |
|
216 | - // required |
|
217 | - if ( ! empty( $args['required'] ) ) { |
|
218 | - $output .= ' required '; |
|
219 | - } |
|
220 | - |
|
221 | - // class |
|
222 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
223 | - $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
224 | - |
|
225 | - // data-attributes |
|
226 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
227 | - |
|
228 | - // extra attributes |
|
229 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
230 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
231 | - } |
|
232 | - |
|
233 | - // close |
|
234 | - $output .= ' >'; |
|
235 | - |
|
236 | - // help text |
|
237 | - if ( ! empty( $args['help_text'] ) ) { |
|
238 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
239 | - } |
|
240 | - |
|
241 | - // label |
|
242 | - if ( ! empty( $args['label'] ) ) { |
|
243 | - $label_base_class = ''; |
|
244 | - if ( $type == 'file' ) { |
|
245 | - $label_base_class = ' custom-file-label'; |
|
246 | - } elseif ( $type == 'checkbox' ) { |
|
247 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
248 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
249 | - $help_text = ''; |
|
250 | - //$label_args['class'] .= ' d-inline '; |
|
251 | - $args['wrap_class'] .= ' align-items-center '; |
|
252 | - }else{ |
|
253 | - |
|
254 | - } |
|
255 | - |
|
256 | - $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
257 | - } |
|
258 | - $label_args['class'] .= $label_base_class; |
|
259 | - $temp_label_args = $label_args; |
|
260 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
261 | - $label = self::label( $temp_label_args, $type ); |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - // set help text in the correct position |
|
268 | - if ( $label_after ) { |
|
269 | - $output .= $label . $help_text; |
|
270 | - } |
|
271 | - |
|
272 | - // some input types need a separate wrap |
|
273 | - if ( $type == 'file' ) { |
|
274 | - $output = self::wrap( array( |
|
275 | - 'content' => $output, |
|
276 | - 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
277 | - ) ); |
|
278 | - } elseif ( $type == 'checkbox' ) { |
|
279 | - |
|
280 | - $label_args['title'] = $args['label']; |
|
281 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
282 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
283 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
284 | - if ( $aui_bs5 ) { |
|
285 | - $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
286 | - }else{ |
|
287 | - $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
288 | - } |
|
289 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
290 | - $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
291 | - $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
292 | - } |
|
293 | - $output = self::wrap( array( |
|
294 | - 'content' => $output, |
|
295 | - 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
296 | - ) ); |
|
297 | - |
|
298 | - if ( $args['label_type'] == 'horizontal' ) { |
|
299 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
300 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
301 | - } |
|
302 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
303 | - |
|
304 | - |
|
305 | - // allow password field to toggle view |
|
306 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
150 | + // enqueue the script |
|
151 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
152 | + $aui_settings->enqueue_iconpicker(); |
|
153 | + } |
|
154 | + |
|
155 | + if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
156 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
157 | + } |
|
158 | + |
|
159 | + // allow clear icon |
|
160 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
161 | + $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
162 | + $args['input_group_right_inside'] = true; |
|
163 | + $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
164 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
165 | + } |
|
166 | + |
|
167 | + // open/type |
|
168 | + $output .= '<input type="' . $type . '" '; |
|
169 | + |
|
170 | + // name |
|
171 | + if ( ! empty( $args['name'] ) ) { |
|
172 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
173 | + } |
|
174 | + |
|
175 | + // id |
|
176 | + if ( ! empty( $args['id'] ) ) { |
|
177 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
178 | + } |
|
179 | + |
|
180 | + // placeholder |
|
181 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
182 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
183 | + } |
|
184 | + |
|
185 | + // title |
|
186 | + if ( ! empty( $args['title'] ) ) { |
|
187 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
188 | + } |
|
189 | + |
|
190 | + // value |
|
191 | + if ( ! empty( $args['value'] ) ) { |
|
192 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
193 | + } |
|
194 | + |
|
195 | + // checked, for radio and checkboxes |
|
196 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
197 | + $output .= ' checked '; |
|
198 | + } |
|
199 | + |
|
200 | + // validation text |
|
201 | + if ( ! empty( $args['validation_text'] ) ) { |
|
202 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
203 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
204 | + } |
|
205 | + |
|
206 | + // validation_pattern |
|
207 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
208 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
209 | + } |
|
210 | + |
|
211 | + // step (for numbers) |
|
212 | + if ( ! empty( $args['step'] ) ) { |
|
213 | + $output .= ' step="' . $args['step'] . '" '; |
|
214 | + } |
|
215 | + |
|
216 | + // required |
|
217 | + if ( ! empty( $args['required'] ) ) { |
|
218 | + $output .= ' required '; |
|
219 | + } |
|
220 | + |
|
221 | + // class |
|
222 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
223 | + $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
224 | + |
|
225 | + // data-attributes |
|
226 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
227 | + |
|
228 | + // extra attributes |
|
229 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
230 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
231 | + } |
|
232 | + |
|
233 | + // close |
|
234 | + $output .= ' >'; |
|
235 | + |
|
236 | + // help text |
|
237 | + if ( ! empty( $args['help_text'] ) ) { |
|
238 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
239 | + } |
|
240 | + |
|
241 | + // label |
|
242 | + if ( ! empty( $args['label'] ) ) { |
|
243 | + $label_base_class = ''; |
|
244 | + if ( $type == 'file' ) { |
|
245 | + $label_base_class = ' custom-file-label'; |
|
246 | + } elseif ( $type == 'checkbox' ) { |
|
247 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
248 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
249 | + $help_text = ''; |
|
250 | + //$label_args['class'] .= ' d-inline '; |
|
251 | + $args['wrap_class'] .= ' align-items-center '; |
|
252 | + }else{ |
|
253 | + |
|
254 | + } |
|
255 | + |
|
256 | + $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
257 | + } |
|
258 | + $label_args['class'] .= $label_base_class; |
|
259 | + $temp_label_args = $label_args; |
|
260 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
261 | + $label = self::label( $temp_label_args, $type ); |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + // set help text in the correct position |
|
268 | + if ( $label_after ) { |
|
269 | + $output .= $label . $help_text; |
|
270 | + } |
|
271 | + |
|
272 | + // some input types need a separate wrap |
|
273 | + if ( $type == 'file' ) { |
|
274 | + $output = self::wrap( array( |
|
275 | + 'content' => $output, |
|
276 | + 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
277 | + ) ); |
|
278 | + } elseif ( $type == 'checkbox' ) { |
|
279 | + |
|
280 | + $label_args['title'] = $args['label']; |
|
281 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
282 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
283 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
284 | + if ( $aui_bs5 ) { |
|
285 | + $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
286 | + }else{ |
|
287 | + $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
288 | + } |
|
289 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
290 | + $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
291 | + $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
292 | + } |
|
293 | + $output = self::wrap( array( |
|
294 | + 'content' => $output, |
|
295 | + 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
296 | + ) ); |
|
297 | + |
|
298 | + if ( $args['label_type'] == 'horizontal' ) { |
|
299 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
300 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
301 | + } |
|
302 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
303 | + |
|
304 | + |
|
305 | + // allow password field to toggle view |
|
306 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
307 | 307 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
308 | 308 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
309 | 309 | if($el.hasClass(\'fa-eye\')) |
310 | 310 | {$eli.attr(\'type\',\'text\');} |
311 | 311 | else{$eli.attr(\'type\',\'password\');}" |
312 | 312 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
313 | - } |
|
314 | - |
|
315 | - // input group wraps |
|
316 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
317 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
318 | - $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
319 | - $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
320 | - |
|
321 | - if ( $args['input_group_left'] ) { |
|
322 | - $output = self::wrap( array( |
|
323 | - 'content' => $output, |
|
324 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
325 | - 'input_group_left' => $args['input_group_left'], |
|
326 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
327 | - ) ); |
|
328 | - } |
|
329 | - if ( $args['input_group_right'] ) { |
|
330 | - $output = self::wrap( array( |
|
331 | - 'content' => $output, |
|
332 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
333 | - 'input_group_right' => $args['input_group_right'], |
|
334 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
335 | - ) ); |
|
336 | - } |
|
337 | - |
|
338 | - } |
|
339 | - |
|
340 | - if ( ! $label_after ) { |
|
341 | - $output .= $help_text; |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
346 | - $output = self::wrap( array( |
|
347 | - 'content' => $output, |
|
348 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
349 | - ) ); |
|
350 | - } |
|
351 | - |
|
352 | - if ( ! $label_after ) { |
|
353 | - $output = $label . $output; |
|
354 | - } |
|
355 | - |
|
356 | - // wrap |
|
357 | - if ( ! $args['no_wrap'] ) { |
|
358 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
359 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
360 | - }else{ |
|
361 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
362 | - } |
|
363 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
364 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
365 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
366 | - $output = self::wrap( array( |
|
367 | - 'content' => $output, |
|
368 | - 'class' => $wrap_class, |
|
369 | - 'element_require' => $args['element_require'], |
|
370 | - 'argument_id' => $args['id'], |
|
371 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
372 | - ) ); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - return $output; |
|
377 | - } |
|
378 | - |
|
379 | - public static function label( $args = array(), $type = '' ) { |
|
380 | - global $aui_bs5; |
|
381 | - //<label for="exampleInputEmail1">Email address</label> |
|
382 | - $defaults = array( |
|
383 | - 'title' => 'div', |
|
384 | - 'for' => '', |
|
385 | - 'class' => '', |
|
386 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
387 | - 'label_col' => '', |
|
388 | - ); |
|
389 | - |
|
390 | - /** |
|
391 | - * Parse incoming $args into an array and merge it with $defaults |
|
392 | - */ |
|
393 | - $args = wp_parse_args( $args, $defaults ); |
|
394 | - $output = ''; |
|
395 | - |
|
396 | - if ( $args['title'] ) { |
|
397 | - |
|
398 | - // maybe hide labels //@todo set a global option for visibility class |
|
399 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
400 | - $class = $args['class']; |
|
401 | - } else { |
|
402 | - $class = 'sr-only ' . $args['class']; |
|
403 | - } |
|
404 | - |
|
405 | - // maybe horizontal |
|
406 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
407 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
408 | - } |
|
409 | - |
|
410 | - if( $aui_bs5 ){ $class .= ' form-label'; } |
|
411 | - |
|
412 | - // open |
|
413 | - $output .= '<label '; |
|
414 | - |
|
415 | - // for |
|
416 | - if ( ! empty( $args['for'] ) ) { |
|
417 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
418 | - } |
|
419 | - |
|
420 | - // class |
|
421 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
422 | - $output .= ' class="' . $class . '" '; |
|
423 | - |
|
424 | - // close |
|
425 | - $output .= '>'; |
|
426 | - |
|
427 | - |
|
428 | - // title, don't escape fully as can contain html |
|
429 | - if ( ! empty( $args['title'] ) ) { |
|
430 | - $output .= wp_kses_post( $args['title'] ); |
|
431 | - } |
|
432 | - |
|
433 | - // close wrap |
|
434 | - $output .= '</label>'; |
|
435 | - |
|
436 | - |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - return $output; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Wrap some content in a HTML wrapper. |
|
445 | - * |
|
446 | - * @param array $args |
|
447 | - * |
|
448 | - * @return string |
|
449 | - */ |
|
450 | - public static function wrap( $args = array() ) { |
|
451 | - global $aui_bs5; |
|
452 | - $defaults = array( |
|
453 | - 'type' => 'div', |
|
454 | - 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
455 | - 'content' => '', |
|
456 | - 'input_group_left' => '', |
|
457 | - 'input_group_right' => '', |
|
458 | - 'input_group_left_inside' => false, |
|
459 | - 'input_group_right_inside' => false, |
|
460 | - 'element_require' => '', |
|
461 | - 'argument_id' => '', |
|
462 | - 'wrap_attributes' => array() |
|
463 | - ); |
|
464 | - |
|
465 | - /** |
|
466 | - * Parse incoming $args into an array and merge it with $defaults |
|
467 | - */ |
|
468 | - $args = wp_parse_args( $args, $defaults ); |
|
469 | - $output = ''; |
|
470 | - if ( $args['type'] ) { |
|
471 | - |
|
472 | - // open |
|
473 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
474 | - |
|
475 | - // element require |
|
476 | - if ( ! empty( $args['element_require'] ) ) { |
|
477 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
478 | - $args['class'] .= " aui-conditional-field"; |
|
479 | - } |
|
480 | - |
|
481 | - // argument_id |
|
482 | - if ( ! empty( $args['argument_id'] ) ) { |
|
483 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
484 | - } |
|
485 | - |
|
486 | - // class |
|
487 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
488 | - $output .= ' class="' . $class . '" '; |
|
489 | - |
|
490 | - // Attributes |
|
491 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
492 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
493 | - } |
|
494 | - |
|
495 | - // close wrap |
|
496 | - $output .= ' >'; |
|
497 | - |
|
498 | - |
|
499 | - // Input group left |
|
500 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
501 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
502 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
503 | - $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
313 | + } |
|
314 | + |
|
315 | + // input group wraps |
|
316 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
317 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
318 | + $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
319 | + $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
320 | + |
|
321 | + if ( $args['input_group_left'] ) { |
|
322 | + $output = self::wrap( array( |
|
323 | + 'content' => $output, |
|
324 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
325 | + 'input_group_left' => $args['input_group_left'], |
|
326 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
327 | + ) ); |
|
328 | + } |
|
329 | + if ( $args['input_group_right'] ) { |
|
330 | + $output = self::wrap( array( |
|
331 | + 'content' => $output, |
|
332 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
333 | + 'input_group_right' => $args['input_group_right'], |
|
334 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
335 | + ) ); |
|
336 | + } |
|
337 | + |
|
338 | + } |
|
339 | + |
|
340 | + if ( ! $label_after ) { |
|
341 | + $output .= $help_text; |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
346 | + $output = self::wrap( array( |
|
347 | + 'content' => $output, |
|
348 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
349 | + ) ); |
|
350 | + } |
|
351 | + |
|
352 | + if ( ! $label_after ) { |
|
353 | + $output = $label . $output; |
|
354 | + } |
|
355 | + |
|
356 | + // wrap |
|
357 | + if ( ! $args['no_wrap'] ) { |
|
358 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
359 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
360 | + }else{ |
|
361 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
362 | + } |
|
363 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
364 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
365 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
366 | + $output = self::wrap( array( |
|
367 | + 'content' => $output, |
|
368 | + 'class' => $wrap_class, |
|
369 | + 'element_require' => $args['element_require'], |
|
370 | + 'argument_id' => $args['id'], |
|
371 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
372 | + ) ); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + return $output; |
|
377 | + } |
|
378 | + |
|
379 | + public static function label( $args = array(), $type = '' ) { |
|
380 | + global $aui_bs5; |
|
381 | + //<label for="exampleInputEmail1">Email address</label> |
|
382 | + $defaults = array( |
|
383 | + 'title' => 'div', |
|
384 | + 'for' => '', |
|
385 | + 'class' => '', |
|
386 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
387 | + 'label_col' => '', |
|
388 | + ); |
|
389 | + |
|
390 | + /** |
|
391 | + * Parse incoming $args into an array and merge it with $defaults |
|
392 | + */ |
|
393 | + $args = wp_parse_args( $args, $defaults ); |
|
394 | + $output = ''; |
|
395 | + |
|
396 | + if ( $args['title'] ) { |
|
397 | + |
|
398 | + // maybe hide labels //@todo set a global option for visibility class |
|
399 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
400 | + $class = $args['class']; |
|
401 | + } else { |
|
402 | + $class = 'sr-only ' . $args['class']; |
|
403 | + } |
|
404 | + |
|
405 | + // maybe horizontal |
|
406 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
407 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
408 | + } |
|
409 | + |
|
410 | + if( $aui_bs5 ){ $class .= ' form-label'; } |
|
411 | + |
|
412 | + // open |
|
413 | + $output .= '<label '; |
|
414 | + |
|
415 | + // for |
|
416 | + if ( ! empty( $args['for'] ) ) { |
|
417 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
418 | + } |
|
419 | + |
|
420 | + // class |
|
421 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
422 | + $output .= ' class="' . $class . '" '; |
|
423 | + |
|
424 | + // close |
|
425 | + $output .= '>'; |
|
426 | + |
|
427 | + |
|
428 | + // title, don't escape fully as can contain html |
|
429 | + if ( ! empty( $args['title'] ) ) { |
|
430 | + $output .= wp_kses_post( $args['title'] ); |
|
431 | + } |
|
432 | + |
|
433 | + // close wrap |
|
434 | + $output .= '</label>'; |
|
435 | + |
|
436 | + |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + return $output; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Wrap some content in a HTML wrapper. |
|
445 | + * |
|
446 | + * @param array $args |
|
447 | + * |
|
448 | + * @return string |
|
449 | + */ |
|
450 | + public static function wrap( $args = array() ) { |
|
451 | + global $aui_bs5; |
|
452 | + $defaults = array( |
|
453 | + 'type' => 'div', |
|
454 | + 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
455 | + 'content' => '', |
|
456 | + 'input_group_left' => '', |
|
457 | + 'input_group_right' => '', |
|
458 | + 'input_group_left_inside' => false, |
|
459 | + 'input_group_right_inside' => false, |
|
460 | + 'element_require' => '', |
|
461 | + 'argument_id' => '', |
|
462 | + 'wrap_attributes' => array() |
|
463 | + ); |
|
464 | + |
|
465 | + /** |
|
466 | + * Parse incoming $args into an array and merge it with $defaults |
|
467 | + */ |
|
468 | + $args = wp_parse_args( $args, $defaults ); |
|
469 | + $output = ''; |
|
470 | + if ( $args['type'] ) { |
|
471 | + |
|
472 | + // open |
|
473 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
474 | + |
|
475 | + // element require |
|
476 | + if ( ! empty( $args['element_require'] ) ) { |
|
477 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
478 | + $args['class'] .= " aui-conditional-field"; |
|
479 | + } |
|
480 | + |
|
481 | + // argument_id |
|
482 | + if ( ! empty( $args['argument_id'] ) ) { |
|
483 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
484 | + } |
|
485 | + |
|
486 | + // class |
|
487 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
488 | + $output .= ' class="' . $class . '" '; |
|
489 | + |
|
490 | + // Attributes |
|
491 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
492 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
493 | + } |
|
494 | + |
|
495 | + // close wrap |
|
496 | + $output .= ' >'; |
|
497 | + |
|
498 | + |
|
499 | + // Input group left |
|
500 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
501 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
502 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
503 | + $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
504 | 504 | // $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
505 | - } |
|
505 | + } |
|
506 | 506 | |
507 | - // content |
|
508 | - $output .= $args['content']; |
|
507 | + // content |
|
508 | + $output .= $args['content']; |
|
509 | 509 | |
510 | - // Input group right |
|
511 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
512 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
513 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
514 | - $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
510 | + // Input group right |
|
511 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
512 | + $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
513 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
514 | + $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
515 | 515 | // $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - // close wrap |
|
520 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
521 | - |
|
522 | - |
|
523 | - } else { |
|
524 | - $output = $args['content']; |
|
525 | - } |
|
526 | - |
|
527 | - return $output; |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * Build the component. |
|
532 | - * |
|
533 | - * @param array $args |
|
534 | - * |
|
535 | - * @return string The rendered component. |
|
536 | - */ |
|
537 | - public static function textarea( $args = array() ) { |
|
538 | - global $aui_bs5; |
|
539 | - |
|
540 | - $defaults = array( |
|
541 | - 'name' => '', |
|
542 | - 'class' => '', |
|
543 | - 'wrap_class' => '', |
|
544 | - 'id' => '', |
|
545 | - 'placeholder' => '', |
|
546 | - 'title' => '', |
|
547 | - 'value' => '', |
|
548 | - 'required' => false, |
|
549 | - 'label' => '', |
|
550 | - 'label_after' => false, |
|
551 | - 'label_class' => '', |
|
552 | - 'label_type' => '', |
|
553 | - 'label_col' => '', |
|
554 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
555 | - 'input_group_right' => '', |
|
556 | - 'input_group_left' => '', |
|
557 | - 'input_group_right_inside' => false, |
|
558 | - 'form_group_class' => '', |
|
559 | - 'help_text' => '', |
|
560 | - 'validation_text' => '', |
|
561 | - 'validation_pattern' => '', |
|
562 | - 'no_wrap' => false, |
|
563 | - 'rows' => '', |
|
564 | - 'wysiwyg' => false, |
|
565 | - 'allow_tags' => false, |
|
566 | - // Allow HTML tags |
|
567 | - 'element_require' => '', |
|
568 | - // [%element_id%] == "1" |
|
569 | - 'extra_attributes' => array(), |
|
570 | - // an array of extra attributes |
|
571 | - 'wrap_attributes' => array(), |
|
572 | - ); |
|
573 | - |
|
574 | - /** |
|
575 | - * Parse incoming $args into an array and merge it with $defaults |
|
576 | - */ |
|
577 | - $args = wp_parse_args( $args, $defaults ); |
|
578 | - $output = ''; |
|
579 | - $label = ''; |
|
580 | - |
|
581 | - // hidden label option needs to be empty |
|
582 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
583 | - |
|
584 | - // floating labels don't work with wysiwyg so set it as top |
|
585 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
586 | - $args['label_type'] = 'top'; |
|
587 | - } |
|
588 | - |
|
589 | - $label_after = $args['label_after']; |
|
590 | - |
|
591 | - // floating labels need label after |
|
592 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
593 | - $label_after = true; |
|
594 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
595 | - } |
|
596 | - |
|
597 | - // label |
|
598 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
599 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
600 | - $label_args = array( |
|
601 | - 'title' => $args['label'], |
|
602 | - 'for' => $args['id'], |
|
603 | - 'class' => $args['label_class'] . " ", |
|
604 | - 'label_type' => $args['label_type'], |
|
605 | - 'label_col' => $args['label_col'] |
|
606 | - ); |
|
607 | - $label .= self::label( $label_args ); |
|
608 | - } |
|
609 | - |
|
610 | - // maybe horizontal label |
|
611 | - if ( $args['label_type'] == 'horizontal' ) { |
|
612 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
613 | - $label .= '<div class="' . $input_col . '">'; |
|
614 | - } |
|
615 | - |
|
616 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
617 | - ob_start(); |
|
618 | - $content = $args['value']; |
|
619 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
620 | - $settings = array( |
|
621 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
622 | - 'quicktags' => false, |
|
623 | - 'media_buttons' => false, |
|
624 | - 'editor_class' => 'form-control', |
|
625 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
626 | - 'teeny' => true, |
|
627 | - ); |
|
628 | - |
|
629 | - // maybe set settings if array |
|
630 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
631 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
632 | - } |
|
633 | - |
|
634 | - wp_editor( $content, $editor_id, $settings ); |
|
635 | - $output .= ob_get_clean(); |
|
636 | - } else { |
|
637 | - |
|
638 | - // open |
|
639 | - $output .= '<textarea '; |
|
640 | - |
|
641 | - // name |
|
642 | - if ( ! empty( $args['name'] ) ) { |
|
643 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
644 | - } |
|
645 | - |
|
646 | - // id |
|
647 | - if ( ! empty( $args['id'] ) ) { |
|
648 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
649 | - } |
|
650 | - |
|
651 | - // placeholder |
|
652 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
653 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
654 | - } |
|
655 | - |
|
656 | - // title |
|
657 | - if ( ! empty( $args['title'] ) ) { |
|
658 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
659 | - } |
|
660 | - |
|
661 | - // validation text |
|
662 | - if ( ! empty( $args['validation_text'] ) ) { |
|
663 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
664 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
665 | - } |
|
666 | - |
|
667 | - // validation_pattern |
|
668 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
669 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
670 | - } |
|
671 | - |
|
672 | - // required |
|
673 | - if ( ! empty( $args['required'] ) ) { |
|
674 | - $output .= ' required '; |
|
675 | - } |
|
676 | - |
|
677 | - // rows |
|
678 | - if ( ! empty( $args['rows'] ) ) { |
|
679 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - // class |
|
684 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
685 | - $output .= ' class="form-control ' . $class . '" '; |
|
686 | - |
|
687 | - // extra attributes |
|
688 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
689 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
690 | - } |
|
691 | - |
|
692 | - // close tag |
|
693 | - $output .= ' >'; |
|
694 | - |
|
695 | - // value |
|
696 | - if ( ! empty( $args['value'] ) ) { |
|
697 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
698 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
699 | - } else { |
|
700 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
701 | - } |
|
702 | - } |
|
703 | - |
|
704 | - // closing tag |
|
705 | - $output .= '</textarea>'; |
|
706 | - |
|
707 | - |
|
708 | - // input group wraps |
|
709 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
710 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
711 | - if ( $args['input_group_left'] ) { |
|
712 | - $output = self::wrap( array( |
|
713 | - 'content' => $output, |
|
714 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
715 | - 'input_group_left' => $args['input_group_left'], |
|
716 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
717 | - ) ); |
|
718 | - } |
|
719 | - if ( $args['input_group_right'] ) { |
|
720 | - $output = self::wrap( array( |
|
721 | - 'content' => $output, |
|
722 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
723 | - 'input_group_right' => $args['input_group_right'], |
|
724 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
725 | - ) ); |
|
726 | - } |
|
727 | - |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - } |
|
732 | - |
|
733 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
734 | - $label_args = array( |
|
735 | - 'title' => $args['label'], |
|
736 | - 'for' => $args['id'], |
|
737 | - 'class' => $args['label_class'] . " ", |
|
738 | - 'label_type' => $args['label_type'], |
|
739 | - 'label_col' => $args['label_col'] |
|
740 | - ); |
|
741 | - $output .= self::label( $label_args ); |
|
742 | - } |
|
743 | - |
|
744 | - // help text |
|
745 | - if ( ! empty( $args['help_text'] ) ) { |
|
746 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
747 | - } |
|
748 | - |
|
749 | - if ( ! $label_after ) { |
|
750 | - $output = $label . $output; |
|
751 | - } |
|
752 | - |
|
753 | - // maybe horizontal label |
|
754 | - if ( $args['label_type'] == 'horizontal' ) { |
|
755 | - $output .= '</div>'; |
|
756 | - } |
|
757 | - |
|
758 | - |
|
759 | - // wrap |
|
760 | - if ( ! $args['no_wrap'] ) { |
|
761 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
762 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
763 | - }else{ |
|
764 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
765 | - } |
|
766 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
767 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
768 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
769 | - $output = self::wrap( array( |
|
770 | - 'content' => $output, |
|
771 | - 'class' => $wrap_class, |
|
772 | - 'element_require' => $args['element_require'], |
|
773 | - 'argument_id' => $args['id'], |
|
774 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
775 | - ) ); |
|
776 | - } |
|
777 | - |
|
778 | - |
|
779 | - return $output; |
|
780 | - } |
|
781 | - |
|
782 | - /** |
|
783 | - * Build the component. |
|
784 | - * |
|
785 | - * @param array $args |
|
786 | - * |
|
787 | - * @return string The rendered component. |
|
788 | - */ |
|
789 | - public static function select( $args = array() ) { |
|
790 | - global $aui_bs5, $aui_has_select2, $aui_select2_enqueued; |
|
791 | - |
|
792 | - $defaults = array( |
|
793 | - 'class' => '', |
|
794 | - 'wrap_class' => '', |
|
795 | - 'id' => '', |
|
796 | - 'title' => '', |
|
797 | - 'value' => '', |
|
798 | - // can be an array or a string |
|
799 | - 'required' => false, |
|
800 | - 'label' => '', |
|
801 | - 'label_after' => false, |
|
802 | - 'label_type' => '', |
|
803 | - 'label_col' => '', |
|
804 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
805 | - 'label_class' => '', |
|
806 | - 'help_text' => '', |
|
807 | - 'placeholder' => '', |
|
808 | - 'options' => array(), |
|
809 | - // array or string |
|
810 | - 'icon' => '', |
|
811 | - 'multiple' => false, |
|
812 | - 'select2' => false, |
|
813 | - 'no_wrap' => false, |
|
814 | - 'input_group_right' => '', |
|
815 | - 'input_group_left' => '', |
|
816 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
817 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
818 | - 'form_group_class' => '', |
|
819 | - 'element_require' => '', |
|
820 | - // [%element_id%] == "1" |
|
821 | - 'extra_attributes' => array(), |
|
822 | - // an array of extra attributes |
|
823 | - 'wrap_attributes' => array(), |
|
824 | - ); |
|
825 | - |
|
826 | - /** |
|
827 | - * Parse incoming $args into an array and merge it with $defaults |
|
828 | - */ |
|
829 | - $args = wp_parse_args( $args, $defaults ); |
|
830 | - $output = ''; |
|
831 | - |
|
832 | - // for now lets hide floating labels |
|
833 | - if ( $args['label_type'] == 'floating' ) { |
|
834 | - $args['label_type'] = 'hidden'; |
|
835 | - } |
|
836 | - |
|
837 | - // hidden label option needs to be empty |
|
838 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
839 | - |
|
840 | - |
|
841 | - $label_after = $args['label_after']; |
|
842 | - |
|
843 | - // floating labels need label after |
|
844 | - if ( $args['label_type'] == 'floating' ) { |
|
845 | - $label_after = true; |
|
846 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
847 | - } |
|
848 | - |
|
849 | - // Maybe setup select2 |
|
850 | - $is_select2 = false; |
|
851 | - if ( ! empty( $args['select2'] ) ) { |
|
852 | - $args['class'] .= ' aui-select2'; |
|
853 | - $is_select2 = true; |
|
854 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
855 | - $is_select2 = true; |
|
856 | - } |
|
857 | - |
|
858 | - if ( $is_select2 && ! $aui_has_select2 ) { |
|
859 | - $aui_has_select2 = true; |
|
860 | - $conditional_select2 = apply_filters( 'aui_is_conditional_select2', true ); |
|
861 | - |
|
862 | - // Enqueue the script, |
|
863 | - if ( empty( $aui_select2_enqueued ) && $conditional_select2 === true ) { |
|
864 | - $aui_select2_enqueued = true; |
|
865 | - |
|
866 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
867 | - $aui_settings->enqueue_select2(); |
|
868 | - } |
|
869 | - } |
|
870 | - |
|
871 | - // select2 tags |
|
872 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
873 | - $args['data-tags'] = 'true'; |
|
874 | - $args['data-token-separators'] = "[',']"; |
|
875 | - $args['multiple'] = true; |
|
876 | - } |
|
877 | - |
|
878 | - // select2 placeholder |
|
879 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
880 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
881 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
882 | - } |
|
883 | - |
|
884 | - // Set hidden input to save empty value for multiselect. |
|
885 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
886 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
887 | - } |
|
888 | - |
|
889 | - // open/type |
|
890 | - $output .= '<select '; |
|
891 | - |
|
892 | - // style |
|
893 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
894 | - $output .= " style='width:100%;' "; |
|
895 | - } |
|
896 | - |
|
897 | - // element require |
|
898 | - if ( ! empty( $args['element_require'] ) ) { |
|
899 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
900 | - $args['class'] .= " aui-conditional-field"; |
|
901 | - } |
|
902 | - |
|
903 | - // class |
|
904 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
905 | - $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
906 | - $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
907 | - |
|
908 | - // name |
|
909 | - if ( ! empty( $args['name'] ) ) { |
|
910 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
911 | - } |
|
912 | - |
|
913 | - // id |
|
914 | - if ( ! empty( $args['id'] ) ) { |
|
915 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
916 | - } |
|
917 | - |
|
918 | - // title |
|
919 | - if ( ! empty( $args['title'] ) ) { |
|
920 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
921 | - } |
|
922 | - |
|
923 | - // data-attributes |
|
924 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
925 | - |
|
926 | - // aria-attributes |
|
927 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
928 | - |
|
929 | - // extra attributes |
|
930 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
931 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
932 | - } |
|
933 | - |
|
934 | - // required |
|
935 | - if ( ! empty( $args['required'] ) ) { |
|
936 | - $output .= ' required '; |
|
937 | - } |
|
938 | - |
|
939 | - // multiple |
|
940 | - if ( ! empty( $args['multiple'] ) ) { |
|
941 | - $output .= ' multiple '; |
|
942 | - } |
|
943 | - |
|
944 | - // close opening tag |
|
945 | - $output .= ' >'; |
|
946 | - |
|
947 | - // placeholder |
|
948 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
949 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
950 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
951 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
952 | - } |
|
953 | - |
|
954 | - // Options |
|
955 | - if ( ! empty( $args['options'] ) ) { |
|
956 | - |
|
957 | - if ( ! is_array( $args['options'] ) ) { |
|
958 | - $output .= $args['options']; // not the preferred way but an option |
|
959 | - } else { |
|
960 | - foreach ( $args['options'] as $val => $name ) { |
|
961 | - $selected = ''; |
|
962 | - if ( is_array( $name ) ) { |
|
963 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
964 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
965 | - |
|
966 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
967 | - } else { |
|
968 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
969 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
970 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
971 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
972 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
973 | - } elseif ( ! empty( $args['value'] ) ) { |
|
974 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
975 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
976 | - $selected = selected( $option_value, $args['value'], false ); |
|
977 | - } |
|
978 | - |
|
979 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
980 | - } |
|
981 | - } else { |
|
982 | - if ( ! empty( $args['value'] ) ) { |
|
983 | - if ( is_array( $args['value'] ) ) { |
|
984 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
985 | - } elseif ( ! empty( $args['value'] ) ) { |
|
986 | - $selected = selected( $args['value'], $val, false ); |
|
987 | - } |
|
988 | - } elseif ( $args['value'] === $val ) { |
|
989 | - $selected = selected( $args['value'], $val, false ); |
|
990 | - } |
|
991 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
992 | - } |
|
993 | - } |
|
994 | - } |
|
995 | - |
|
996 | - } |
|
997 | - |
|
998 | - // closing tag |
|
999 | - $output .= '</select>'; |
|
1000 | - |
|
1001 | - $label = ''; |
|
1002 | - $help_text = ''; |
|
1003 | - // label |
|
1004 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1005 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
1006 | - $label_args = array( |
|
1007 | - 'title' => $args['label'], |
|
1008 | - 'for' => $args['id'], |
|
1009 | - 'class' => $args['label_class'] . " ", |
|
1010 | - 'label_type' => $args['label_type'], |
|
1011 | - 'label_col' => $args['label_col'] |
|
1012 | - ); |
|
1013 | - $label = self::label( $label_args ); |
|
1014 | - } |
|
1015 | - |
|
1016 | - // help text |
|
1017 | - if ( ! empty( $args['help_text'] ) ) { |
|
1018 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - // input group wraps |
|
1022 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
1023 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
1024 | - if ( $args['input_group_left'] ) { |
|
1025 | - $output = self::wrap( array( |
|
1026 | - 'content' => $output, |
|
1027 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1028 | - 'input_group_left' => $args['input_group_left'], |
|
1029 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
1030 | - ) ); |
|
1031 | - } |
|
1032 | - if ( $args['input_group_right'] ) { |
|
1033 | - $output = self::wrap( array( |
|
1034 | - 'content' => $output, |
|
1035 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1036 | - 'input_group_right' => $args['input_group_right'], |
|
1037 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
1038 | - ) ); |
|
1039 | - } |
|
1040 | - |
|
1041 | - } |
|
1042 | - |
|
1043 | - if ( ! $label_after ) { |
|
1044 | - $output .= $help_text; |
|
1045 | - } |
|
1046 | - |
|
1047 | - |
|
1048 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1049 | - $output = self::wrap( array( |
|
1050 | - 'content' => $output, |
|
1051 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1052 | - ) ); |
|
1053 | - } |
|
1054 | - |
|
1055 | - if ( ! $label_after ) { |
|
1056 | - $output = $label . $output; |
|
1057 | - } |
|
1058 | - |
|
1059 | - // maybe horizontal label |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + // close wrap |
|
520 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
521 | + |
|
522 | + |
|
523 | + } else { |
|
524 | + $output = $args['content']; |
|
525 | + } |
|
526 | + |
|
527 | + return $output; |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Build the component. |
|
532 | + * |
|
533 | + * @param array $args |
|
534 | + * |
|
535 | + * @return string The rendered component. |
|
536 | + */ |
|
537 | + public static function textarea( $args = array() ) { |
|
538 | + global $aui_bs5; |
|
539 | + |
|
540 | + $defaults = array( |
|
541 | + 'name' => '', |
|
542 | + 'class' => '', |
|
543 | + 'wrap_class' => '', |
|
544 | + 'id' => '', |
|
545 | + 'placeholder' => '', |
|
546 | + 'title' => '', |
|
547 | + 'value' => '', |
|
548 | + 'required' => false, |
|
549 | + 'label' => '', |
|
550 | + 'label_after' => false, |
|
551 | + 'label_class' => '', |
|
552 | + 'label_type' => '', |
|
553 | + 'label_col' => '', |
|
554 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
555 | + 'input_group_right' => '', |
|
556 | + 'input_group_left' => '', |
|
557 | + 'input_group_right_inside' => false, |
|
558 | + 'form_group_class' => '', |
|
559 | + 'help_text' => '', |
|
560 | + 'validation_text' => '', |
|
561 | + 'validation_pattern' => '', |
|
562 | + 'no_wrap' => false, |
|
563 | + 'rows' => '', |
|
564 | + 'wysiwyg' => false, |
|
565 | + 'allow_tags' => false, |
|
566 | + // Allow HTML tags |
|
567 | + 'element_require' => '', |
|
568 | + // [%element_id%] == "1" |
|
569 | + 'extra_attributes' => array(), |
|
570 | + // an array of extra attributes |
|
571 | + 'wrap_attributes' => array(), |
|
572 | + ); |
|
573 | + |
|
574 | + /** |
|
575 | + * Parse incoming $args into an array and merge it with $defaults |
|
576 | + */ |
|
577 | + $args = wp_parse_args( $args, $defaults ); |
|
578 | + $output = ''; |
|
579 | + $label = ''; |
|
580 | + |
|
581 | + // hidden label option needs to be empty |
|
582 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
583 | + |
|
584 | + // floating labels don't work with wysiwyg so set it as top |
|
585 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
586 | + $args['label_type'] = 'top'; |
|
587 | + } |
|
588 | + |
|
589 | + $label_after = $args['label_after']; |
|
590 | + |
|
591 | + // floating labels need label after |
|
592 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
593 | + $label_after = true; |
|
594 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
595 | + } |
|
596 | + |
|
597 | + // label |
|
598 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
599 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
600 | + $label_args = array( |
|
601 | + 'title' => $args['label'], |
|
602 | + 'for' => $args['id'], |
|
603 | + 'class' => $args['label_class'] . " ", |
|
604 | + 'label_type' => $args['label_type'], |
|
605 | + 'label_col' => $args['label_col'] |
|
606 | + ); |
|
607 | + $label .= self::label( $label_args ); |
|
608 | + } |
|
609 | + |
|
610 | + // maybe horizontal label |
|
611 | + if ( $args['label_type'] == 'horizontal' ) { |
|
612 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
613 | + $label .= '<div class="' . $input_col . '">'; |
|
614 | + } |
|
615 | + |
|
616 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
617 | + ob_start(); |
|
618 | + $content = $args['value']; |
|
619 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
620 | + $settings = array( |
|
621 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
622 | + 'quicktags' => false, |
|
623 | + 'media_buttons' => false, |
|
624 | + 'editor_class' => 'form-control', |
|
625 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
626 | + 'teeny' => true, |
|
627 | + ); |
|
628 | + |
|
629 | + // maybe set settings if array |
|
630 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
631 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
632 | + } |
|
633 | + |
|
634 | + wp_editor( $content, $editor_id, $settings ); |
|
635 | + $output .= ob_get_clean(); |
|
636 | + } else { |
|
637 | + |
|
638 | + // open |
|
639 | + $output .= '<textarea '; |
|
640 | + |
|
641 | + // name |
|
642 | + if ( ! empty( $args['name'] ) ) { |
|
643 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
644 | + } |
|
645 | + |
|
646 | + // id |
|
647 | + if ( ! empty( $args['id'] ) ) { |
|
648 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
649 | + } |
|
650 | + |
|
651 | + // placeholder |
|
652 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
653 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
654 | + } |
|
655 | + |
|
656 | + // title |
|
657 | + if ( ! empty( $args['title'] ) ) { |
|
658 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
659 | + } |
|
660 | + |
|
661 | + // validation text |
|
662 | + if ( ! empty( $args['validation_text'] ) ) { |
|
663 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
664 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
665 | + } |
|
666 | + |
|
667 | + // validation_pattern |
|
668 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
669 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
670 | + } |
|
671 | + |
|
672 | + // required |
|
673 | + if ( ! empty( $args['required'] ) ) { |
|
674 | + $output .= ' required '; |
|
675 | + } |
|
676 | + |
|
677 | + // rows |
|
678 | + if ( ! empty( $args['rows'] ) ) { |
|
679 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + // class |
|
684 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
685 | + $output .= ' class="form-control ' . $class . '" '; |
|
686 | + |
|
687 | + // extra attributes |
|
688 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
689 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
690 | + } |
|
691 | + |
|
692 | + // close tag |
|
693 | + $output .= ' >'; |
|
694 | + |
|
695 | + // value |
|
696 | + if ( ! empty( $args['value'] ) ) { |
|
697 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
698 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
699 | + } else { |
|
700 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
701 | + } |
|
702 | + } |
|
703 | + |
|
704 | + // closing tag |
|
705 | + $output .= '</textarea>'; |
|
706 | + |
|
707 | + |
|
708 | + // input group wraps |
|
709 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
710 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
711 | + if ( $args['input_group_left'] ) { |
|
712 | + $output = self::wrap( array( |
|
713 | + 'content' => $output, |
|
714 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
715 | + 'input_group_left' => $args['input_group_left'], |
|
716 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
717 | + ) ); |
|
718 | + } |
|
719 | + if ( $args['input_group_right'] ) { |
|
720 | + $output = self::wrap( array( |
|
721 | + 'content' => $output, |
|
722 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
723 | + 'input_group_right' => $args['input_group_right'], |
|
724 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
725 | + ) ); |
|
726 | + } |
|
727 | + |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + } |
|
732 | + |
|
733 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
734 | + $label_args = array( |
|
735 | + 'title' => $args['label'], |
|
736 | + 'for' => $args['id'], |
|
737 | + 'class' => $args['label_class'] . " ", |
|
738 | + 'label_type' => $args['label_type'], |
|
739 | + 'label_col' => $args['label_col'] |
|
740 | + ); |
|
741 | + $output .= self::label( $label_args ); |
|
742 | + } |
|
743 | + |
|
744 | + // help text |
|
745 | + if ( ! empty( $args['help_text'] ) ) { |
|
746 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
747 | + } |
|
748 | + |
|
749 | + if ( ! $label_after ) { |
|
750 | + $output = $label . $output; |
|
751 | + } |
|
752 | + |
|
753 | + // maybe horizontal label |
|
754 | + if ( $args['label_type'] == 'horizontal' ) { |
|
755 | + $output .= '</div>'; |
|
756 | + } |
|
757 | + |
|
758 | + |
|
759 | + // wrap |
|
760 | + if ( ! $args['no_wrap'] ) { |
|
761 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
762 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
763 | + }else{ |
|
764 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
765 | + } |
|
766 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
767 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
768 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
769 | + $output = self::wrap( array( |
|
770 | + 'content' => $output, |
|
771 | + 'class' => $wrap_class, |
|
772 | + 'element_require' => $args['element_require'], |
|
773 | + 'argument_id' => $args['id'], |
|
774 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
775 | + ) ); |
|
776 | + } |
|
777 | + |
|
778 | + |
|
779 | + return $output; |
|
780 | + } |
|
781 | + |
|
782 | + /** |
|
783 | + * Build the component. |
|
784 | + * |
|
785 | + * @param array $args |
|
786 | + * |
|
787 | + * @return string The rendered component. |
|
788 | + */ |
|
789 | + public static function select( $args = array() ) { |
|
790 | + global $aui_bs5, $aui_has_select2, $aui_select2_enqueued; |
|
791 | + |
|
792 | + $defaults = array( |
|
793 | + 'class' => '', |
|
794 | + 'wrap_class' => '', |
|
795 | + 'id' => '', |
|
796 | + 'title' => '', |
|
797 | + 'value' => '', |
|
798 | + // can be an array or a string |
|
799 | + 'required' => false, |
|
800 | + 'label' => '', |
|
801 | + 'label_after' => false, |
|
802 | + 'label_type' => '', |
|
803 | + 'label_col' => '', |
|
804 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
805 | + 'label_class' => '', |
|
806 | + 'help_text' => '', |
|
807 | + 'placeholder' => '', |
|
808 | + 'options' => array(), |
|
809 | + // array or string |
|
810 | + 'icon' => '', |
|
811 | + 'multiple' => false, |
|
812 | + 'select2' => false, |
|
813 | + 'no_wrap' => false, |
|
814 | + 'input_group_right' => '', |
|
815 | + 'input_group_left' => '', |
|
816 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
817 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
818 | + 'form_group_class' => '', |
|
819 | + 'element_require' => '', |
|
820 | + // [%element_id%] == "1" |
|
821 | + 'extra_attributes' => array(), |
|
822 | + // an array of extra attributes |
|
823 | + 'wrap_attributes' => array(), |
|
824 | + ); |
|
825 | + |
|
826 | + /** |
|
827 | + * Parse incoming $args into an array and merge it with $defaults |
|
828 | + */ |
|
829 | + $args = wp_parse_args( $args, $defaults ); |
|
830 | + $output = ''; |
|
831 | + |
|
832 | + // for now lets hide floating labels |
|
833 | + if ( $args['label_type'] == 'floating' ) { |
|
834 | + $args['label_type'] = 'hidden'; |
|
835 | + } |
|
836 | + |
|
837 | + // hidden label option needs to be empty |
|
838 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
839 | + |
|
840 | + |
|
841 | + $label_after = $args['label_after']; |
|
842 | + |
|
843 | + // floating labels need label after |
|
844 | + if ( $args['label_type'] == 'floating' ) { |
|
845 | + $label_after = true; |
|
846 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
847 | + } |
|
848 | + |
|
849 | + // Maybe setup select2 |
|
850 | + $is_select2 = false; |
|
851 | + if ( ! empty( $args['select2'] ) ) { |
|
852 | + $args['class'] .= ' aui-select2'; |
|
853 | + $is_select2 = true; |
|
854 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
855 | + $is_select2 = true; |
|
856 | + } |
|
857 | + |
|
858 | + if ( $is_select2 && ! $aui_has_select2 ) { |
|
859 | + $aui_has_select2 = true; |
|
860 | + $conditional_select2 = apply_filters( 'aui_is_conditional_select2', true ); |
|
861 | + |
|
862 | + // Enqueue the script, |
|
863 | + if ( empty( $aui_select2_enqueued ) && $conditional_select2 === true ) { |
|
864 | + $aui_select2_enqueued = true; |
|
865 | + |
|
866 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
867 | + $aui_settings->enqueue_select2(); |
|
868 | + } |
|
869 | + } |
|
870 | + |
|
871 | + // select2 tags |
|
872 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
873 | + $args['data-tags'] = 'true'; |
|
874 | + $args['data-token-separators'] = "[',']"; |
|
875 | + $args['multiple'] = true; |
|
876 | + } |
|
877 | + |
|
878 | + // select2 placeholder |
|
879 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
880 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
881 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
882 | + } |
|
883 | + |
|
884 | + // Set hidden input to save empty value for multiselect. |
|
885 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
886 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
887 | + } |
|
888 | + |
|
889 | + // open/type |
|
890 | + $output .= '<select '; |
|
891 | + |
|
892 | + // style |
|
893 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
894 | + $output .= " style='width:100%;' "; |
|
895 | + } |
|
896 | + |
|
897 | + // element require |
|
898 | + if ( ! empty( $args['element_require'] ) ) { |
|
899 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
900 | + $args['class'] .= " aui-conditional-field"; |
|
901 | + } |
|
902 | + |
|
903 | + // class |
|
904 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
905 | + $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
906 | + $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
907 | + |
|
908 | + // name |
|
909 | + if ( ! empty( $args['name'] ) ) { |
|
910 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
911 | + } |
|
912 | + |
|
913 | + // id |
|
914 | + if ( ! empty( $args['id'] ) ) { |
|
915 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
916 | + } |
|
917 | + |
|
918 | + // title |
|
919 | + if ( ! empty( $args['title'] ) ) { |
|
920 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
921 | + } |
|
922 | + |
|
923 | + // data-attributes |
|
924 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
925 | + |
|
926 | + // aria-attributes |
|
927 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
928 | + |
|
929 | + // extra attributes |
|
930 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
931 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
932 | + } |
|
933 | + |
|
934 | + // required |
|
935 | + if ( ! empty( $args['required'] ) ) { |
|
936 | + $output .= ' required '; |
|
937 | + } |
|
938 | + |
|
939 | + // multiple |
|
940 | + if ( ! empty( $args['multiple'] ) ) { |
|
941 | + $output .= ' multiple '; |
|
942 | + } |
|
943 | + |
|
944 | + // close opening tag |
|
945 | + $output .= ' >'; |
|
946 | + |
|
947 | + // placeholder |
|
948 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
949 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
950 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
951 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
952 | + } |
|
953 | + |
|
954 | + // Options |
|
955 | + if ( ! empty( $args['options'] ) ) { |
|
956 | + |
|
957 | + if ( ! is_array( $args['options'] ) ) { |
|
958 | + $output .= $args['options']; // not the preferred way but an option |
|
959 | + } else { |
|
960 | + foreach ( $args['options'] as $val => $name ) { |
|
961 | + $selected = ''; |
|
962 | + if ( is_array( $name ) ) { |
|
963 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
964 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
965 | + |
|
966 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
967 | + } else { |
|
968 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
969 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
970 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
971 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
972 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
973 | + } elseif ( ! empty( $args['value'] ) ) { |
|
974 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
975 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
976 | + $selected = selected( $option_value, $args['value'], false ); |
|
977 | + } |
|
978 | + |
|
979 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
980 | + } |
|
981 | + } else { |
|
982 | + if ( ! empty( $args['value'] ) ) { |
|
983 | + if ( is_array( $args['value'] ) ) { |
|
984 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
985 | + } elseif ( ! empty( $args['value'] ) ) { |
|
986 | + $selected = selected( $args['value'], $val, false ); |
|
987 | + } |
|
988 | + } elseif ( $args['value'] === $val ) { |
|
989 | + $selected = selected( $args['value'], $val, false ); |
|
990 | + } |
|
991 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
992 | + } |
|
993 | + } |
|
994 | + } |
|
995 | + |
|
996 | + } |
|
997 | + |
|
998 | + // closing tag |
|
999 | + $output .= '</select>'; |
|
1000 | + |
|
1001 | + $label = ''; |
|
1002 | + $help_text = ''; |
|
1003 | + // label |
|
1004 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1005 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
1006 | + $label_args = array( |
|
1007 | + 'title' => $args['label'], |
|
1008 | + 'for' => $args['id'], |
|
1009 | + 'class' => $args['label_class'] . " ", |
|
1010 | + 'label_type' => $args['label_type'], |
|
1011 | + 'label_col' => $args['label_col'] |
|
1012 | + ); |
|
1013 | + $label = self::label( $label_args ); |
|
1014 | + } |
|
1015 | + |
|
1016 | + // help text |
|
1017 | + if ( ! empty( $args['help_text'] ) ) { |
|
1018 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + // input group wraps |
|
1022 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
1023 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
1024 | + if ( $args['input_group_left'] ) { |
|
1025 | + $output = self::wrap( array( |
|
1026 | + 'content' => $output, |
|
1027 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1028 | + 'input_group_left' => $args['input_group_left'], |
|
1029 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
1030 | + ) ); |
|
1031 | + } |
|
1032 | + if ( $args['input_group_right'] ) { |
|
1033 | + $output = self::wrap( array( |
|
1034 | + 'content' => $output, |
|
1035 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1036 | + 'input_group_right' => $args['input_group_right'], |
|
1037 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
1038 | + ) ); |
|
1039 | + } |
|
1040 | + |
|
1041 | + } |
|
1042 | + |
|
1043 | + if ( ! $label_after ) { |
|
1044 | + $output .= $help_text; |
|
1045 | + } |
|
1046 | + |
|
1047 | + |
|
1048 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1049 | + $output = self::wrap( array( |
|
1050 | + 'content' => $output, |
|
1051 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1052 | + ) ); |
|
1053 | + } |
|
1054 | + |
|
1055 | + if ( ! $label_after ) { |
|
1056 | + $output = $label . $output; |
|
1057 | + } |
|
1058 | + |
|
1059 | + // maybe horizontal label |
|
1060 | 1060 | // if ( $args['label_type'] == 'horizontal' ) { |
1061 | 1061 | // $output .= '</div>'; |
1062 | 1062 | // } |
1063 | 1063 | |
1064 | 1064 | |
1065 | - // wrap |
|
1066 | - if ( ! $args['no_wrap'] ) { |
|
1067 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
1068 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
1069 | - }else{ |
|
1070 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1071 | - } |
|
1072 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1073 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1074 | - $output = self::wrap( array( |
|
1075 | - 'content' => $output, |
|
1076 | - 'class' => $wrap_class, |
|
1077 | - 'element_require' => $args['element_require'], |
|
1078 | - 'argument_id' => $args['id'], |
|
1079 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1080 | - ) ); |
|
1081 | - } |
|
1082 | - |
|
1083 | - |
|
1084 | - return $output; |
|
1085 | - } |
|
1086 | - |
|
1087 | - /** |
|
1088 | - * Build the component. |
|
1089 | - * |
|
1090 | - * @param array $args |
|
1091 | - * |
|
1092 | - * @return string The rendered component. |
|
1093 | - */ |
|
1094 | - public static function radio( $args = array() ) { |
|
1095 | - global $aui_bs5; |
|
1096 | - |
|
1097 | - $defaults = array( |
|
1098 | - 'class' => '', |
|
1099 | - 'wrap_class' => '', |
|
1100 | - 'id' => '', |
|
1101 | - 'title' => '', |
|
1102 | - 'horizontal' => false, |
|
1103 | - // sets the lable horizontal |
|
1104 | - 'value' => '', |
|
1105 | - 'label' => '', |
|
1106 | - 'label_class' => '', |
|
1107 | - 'label_type' => '', |
|
1108 | - 'label_col' => '', |
|
1109 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1110 | - 'help_text' => '', |
|
1111 | - 'inline' => true, |
|
1112 | - 'required' => false, |
|
1113 | - 'options' => array(), |
|
1114 | - 'icon' => '', |
|
1115 | - 'no_wrap' => false, |
|
1116 | - 'element_require' => '', |
|
1117 | - // [%element_id%] == "1" |
|
1118 | - 'extra_attributes' => array(), |
|
1119 | - // an array of extra attributes |
|
1120 | - 'wrap_attributes' => array() |
|
1121 | - ); |
|
1122 | - |
|
1123 | - /** |
|
1124 | - * Parse incoming $args into an array and merge it with $defaults |
|
1125 | - */ |
|
1126 | - $args = wp_parse_args( $args, $defaults ); |
|
1127 | - |
|
1128 | - // for now lets use horizontal for floating |
|
1129 | - if ( $args['label_type'] == 'floating' ) { |
|
1130 | - $args['label_type'] = 'horizontal'; |
|
1131 | - } |
|
1132 | - |
|
1133 | - $label_args = array( |
|
1134 | - 'title' => $args['label'], |
|
1135 | - 'class' => $args['label_class'] . " pt-0 ", |
|
1136 | - 'label_type' => $args['label_type'], |
|
1137 | - 'label_col' => $args['label_col'] |
|
1138 | - ); |
|
1139 | - |
|
1140 | - if ( $args['label_type'] == 'top' || $args['label_type'] == 'hidden' ) { |
|
1141 | - $label_args['class'] .= 'd-block '; |
|
1142 | - |
|
1143 | - if ( $args['label_type'] == 'hidden' ) { |
|
1144 | - $label_args['class'] .= 'sr-only '; |
|
1145 | - } |
|
1146 | - } |
|
1147 | - |
|
1148 | - $output = ''; |
|
1149 | - |
|
1150 | - // label before |
|
1151 | - if ( ! empty( $args['label'] ) ) { |
|
1152 | - $output .= self::label( $label_args, 'radio' ); |
|
1153 | - } |
|
1154 | - |
|
1155 | - // maybe horizontal label |
|
1156 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1157 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1158 | - $output .= '<div class="' . $input_col . '">'; |
|
1159 | - } |
|
1160 | - |
|
1161 | - if ( ! empty( $args['options'] ) ) { |
|
1162 | - $count = 0; |
|
1163 | - foreach ( $args['options'] as $value => $label ) { |
|
1164 | - $option_args = $args; |
|
1165 | - $option_args['value'] = $value; |
|
1166 | - $option_args['label'] = $label; |
|
1167 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1168 | - $output .= self::radio_option( $option_args, $count ); |
|
1169 | - $count ++; |
|
1170 | - } |
|
1171 | - } |
|
1172 | - |
|
1173 | - // help text |
|
1174 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1175 | - $output .= $help_text; |
|
1176 | - |
|
1177 | - // maybe horizontal label |
|
1178 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1179 | - $output .= '</div>'; |
|
1180 | - } |
|
1181 | - |
|
1182 | - // wrap |
|
1183 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1184 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1185 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1186 | - $output = self::wrap( array( |
|
1187 | - 'content' => $output, |
|
1188 | - 'class' => $wrap_class, |
|
1189 | - 'element_require' => $args['element_require'], |
|
1190 | - 'argument_id' => $args['id'], |
|
1191 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1192 | - ) ); |
|
1193 | - |
|
1194 | - |
|
1195 | - return $output; |
|
1196 | - } |
|
1197 | - |
|
1198 | - /** |
|
1199 | - * Build the component. |
|
1200 | - * |
|
1201 | - * @param array $args |
|
1202 | - * |
|
1203 | - * @return string The rendered component. |
|
1204 | - */ |
|
1205 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1206 | - $defaults = array( |
|
1207 | - 'class' => '', |
|
1208 | - 'id' => '', |
|
1209 | - 'title' => '', |
|
1210 | - 'value' => '', |
|
1211 | - 'required' => false, |
|
1212 | - 'inline' => true, |
|
1213 | - 'label' => '', |
|
1214 | - 'options' => array(), |
|
1215 | - 'icon' => '', |
|
1216 | - 'no_wrap' => false, |
|
1217 | - 'extra_attributes' => array() // an array of extra attributes |
|
1218 | - ); |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * Parse incoming $args into an array and merge it with $defaults |
|
1222 | - */ |
|
1223 | - $args = wp_parse_args( $args, $defaults ); |
|
1224 | - |
|
1225 | - $output = ''; |
|
1226 | - |
|
1227 | - // open/type |
|
1228 | - $output .= '<input type="radio"'; |
|
1229 | - |
|
1230 | - // class |
|
1231 | - $output .= ' class="form-check-input" '; |
|
1232 | - |
|
1233 | - // name |
|
1234 | - if ( ! empty( $args['name'] ) ) { |
|
1235 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1236 | - } |
|
1237 | - |
|
1238 | - // id |
|
1239 | - if ( ! empty( $args['id'] ) ) { |
|
1240 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1241 | - } |
|
1242 | - |
|
1243 | - // title |
|
1244 | - if ( ! empty( $args['title'] ) ) { |
|
1245 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1246 | - } |
|
1247 | - |
|
1248 | - // value |
|
1249 | - if ( isset( $args['value'] ) ) { |
|
1250 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1251 | - } |
|
1252 | - |
|
1253 | - // checked, for radio and checkboxes |
|
1254 | - if ( $args['checked'] ) { |
|
1255 | - $output .= ' checked '; |
|
1256 | - } |
|
1257 | - |
|
1258 | - // data-attributes |
|
1259 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1260 | - |
|
1261 | - // aria-attributes |
|
1262 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1263 | - |
|
1264 | - // extra attributes |
|
1265 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1266 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1267 | - } |
|
1268 | - |
|
1269 | - // required |
|
1270 | - if ( ! empty( $args['required'] ) ) { |
|
1271 | - $output .= ' required '; |
|
1272 | - } |
|
1273 | - |
|
1274 | - // close opening tag |
|
1275 | - $output .= ' >'; |
|
1276 | - |
|
1277 | - // label |
|
1278 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1279 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1280 | - $output .= self::label( array( |
|
1281 | - 'title' => $args['label'], |
|
1282 | - 'for' => $args['id'] . $count, |
|
1283 | - 'class' => 'form-check-label' |
|
1284 | - ), 'radio' ); |
|
1285 | - } |
|
1286 | - |
|
1287 | - // wrap |
|
1288 | - if ( ! $args['no_wrap'] ) { |
|
1289 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1290 | - |
|
1291 | - // Unique wrap class |
|
1292 | - $uniq_class = 'fwrap'; |
|
1293 | - if ( ! empty( $args['name'] ) ) { |
|
1294 | - $uniq_class .= '-' . $args['name']; |
|
1295 | - } else if ( ! empty( $args['id'] ) ) { |
|
1296 | - $uniq_class .= '-' . $args['id']; |
|
1297 | - } |
|
1298 | - |
|
1299 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1300 | - $uniq_class .= '-' . $args['value']; |
|
1301 | - } else { |
|
1302 | - $uniq_class .= '-' . $count; |
|
1303 | - } |
|
1304 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1305 | - |
|
1306 | - $output = self::wrap( array( |
|
1307 | - 'content' => $output, |
|
1308 | - 'class' => $wrap_class |
|
1309 | - ) ); |
|
1310 | - } |
|
1311 | - |
|
1312 | - return $output; |
|
1313 | - } |
|
1065 | + // wrap |
|
1066 | + if ( ! $args['no_wrap'] ) { |
|
1067 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
1068 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
1069 | + }else{ |
|
1070 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1071 | + } |
|
1072 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1073 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1074 | + $output = self::wrap( array( |
|
1075 | + 'content' => $output, |
|
1076 | + 'class' => $wrap_class, |
|
1077 | + 'element_require' => $args['element_require'], |
|
1078 | + 'argument_id' => $args['id'], |
|
1079 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1080 | + ) ); |
|
1081 | + } |
|
1082 | + |
|
1083 | + |
|
1084 | + return $output; |
|
1085 | + } |
|
1086 | + |
|
1087 | + /** |
|
1088 | + * Build the component. |
|
1089 | + * |
|
1090 | + * @param array $args |
|
1091 | + * |
|
1092 | + * @return string The rendered component. |
|
1093 | + */ |
|
1094 | + public static function radio( $args = array() ) { |
|
1095 | + global $aui_bs5; |
|
1096 | + |
|
1097 | + $defaults = array( |
|
1098 | + 'class' => '', |
|
1099 | + 'wrap_class' => '', |
|
1100 | + 'id' => '', |
|
1101 | + 'title' => '', |
|
1102 | + 'horizontal' => false, |
|
1103 | + // sets the lable horizontal |
|
1104 | + 'value' => '', |
|
1105 | + 'label' => '', |
|
1106 | + 'label_class' => '', |
|
1107 | + 'label_type' => '', |
|
1108 | + 'label_col' => '', |
|
1109 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1110 | + 'help_text' => '', |
|
1111 | + 'inline' => true, |
|
1112 | + 'required' => false, |
|
1113 | + 'options' => array(), |
|
1114 | + 'icon' => '', |
|
1115 | + 'no_wrap' => false, |
|
1116 | + 'element_require' => '', |
|
1117 | + // [%element_id%] == "1" |
|
1118 | + 'extra_attributes' => array(), |
|
1119 | + // an array of extra attributes |
|
1120 | + 'wrap_attributes' => array() |
|
1121 | + ); |
|
1122 | + |
|
1123 | + /** |
|
1124 | + * Parse incoming $args into an array and merge it with $defaults |
|
1125 | + */ |
|
1126 | + $args = wp_parse_args( $args, $defaults ); |
|
1127 | + |
|
1128 | + // for now lets use horizontal for floating |
|
1129 | + if ( $args['label_type'] == 'floating' ) { |
|
1130 | + $args['label_type'] = 'horizontal'; |
|
1131 | + } |
|
1132 | + |
|
1133 | + $label_args = array( |
|
1134 | + 'title' => $args['label'], |
|
1135 | + 'class' => $args['label_class'] . " pt-0 ", |
|
1136 | + 'label_type' => $args['label_type'], |
|
1137 | + 'label_col' => $args['label_col'] |
|
1138 | + ); |
|
1139 | + |
|
1140 | + if ( $args['label_type'] == 'top' || $args['label_type'] == 'hidden' ) { |
|
1141 | + $label_args['class'] .= 'd-block '; |
|
1142 | + |
|
1143 | + if ( $args['label_type'] == 'hidden' ) { |
|
1144 | + $label_args['class'] .= 'sr-only '; |
|
1145 | + } |
|
1146 | + } |
|
1147 | + |
|
1148 | + $output = ''; |
|
1149 | + |
|
1150 | + // label before |
|
1151 | + if ( ! empty( $args['label'] ) ) { |
|
1152 | + $output .= self::label( $label_args, 'radio' ); |
|
1153 | + } |
|
1154 | + |
|
1155 | + // maybe horizontal label |
|
1156 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1157 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1158 | + $output .= '<div class="' . $input_col . '">'; |
|
1159 | + } |
|
1160 | + |
|
1161 | + if ( ! empty( $args['options'] ) ) { |
|
1162 | + $count = 0; |
|
1163 | + foreach ( $args['options'] as $value => $label ) { |
|
1164 | + $option_args = $args; |
|
1165 | + $option_args['value'] = $value; |
|
1166 | + $option_args['label'] = $label; |
|
1167 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1168 | + $output .= self::radio_option( $option_args, $count ); |
|
1169 | + $count ++; |
|
1170 | + } |
|
1171 | + } |
|
1172 | + |
|
1173 | + // help text |
|
1174 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1175 | + $output .= $help_text; |
|
1176 | + |
|
1177 | + // maybe horizontal label |
|
1178 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1179 | + $output .= '</div>'; |
|
1180 | + } |
|
1181 | + |
|
1182 | + // wrap |
|
1183 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1184 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1185 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1186 | + $output = self::wrap( array( |
|
1187 | + 'content' => $output, |
|
1188 | + 'class' => $wrap_class, |
|
1189 | + 'element_require' => $args['element_require'], |
|
1190 | + 'argument_id' => $args['id'], |
|
1191 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1192 | + ) ); |
|
1193 | + |
|
1194 | + |
|
1195 | + return $output; |
|
1196 | + } |
|
1197 | + |
|
1198 | + /** |
|
1199 | + * Build the component. |
|
1200 | + * |
|
1201 | + * @param array $args |
|
1202 | + * |
|
1203 | + * @return string The rendered component. |
|
1204 | + */ |
|
1205 | + public static function radio_option( $args = array(), $count = '' ) { |
|
1206 | + $defaults = array( |
|
1207 | + 'class' => '', |
|
1208 | + 'id' => '', |
|
1209 | + 'title' => '', |
|
1210 | + 'value' => '', |
|
1211 | + 'required' => false, |
|
1212 | + 'inline' => true, |
|
1213 | + 'label' => '', |
|
1214 | + 'options' => array(), |
|
1215 | + 'icon' => '', |
|
1216 | + 'no_wrap' => false, |
|
1217 | + 'extra_attributes' => array() // an array of extra attributes |
|
1218 | + ); |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * Parse incoming $args into an array and merge it with $defaults |
|
1222 | + */ |
|
1223 | + $args = wp_parse_args( $args, $defaults ); |
|
1224 | + |
|
1225 | + $output = ''; |
|
1226 | + |
|
1227 | + // open/type |
|
1228 | + $output .= '<input type="radio"'; |
|
1229 | + |
|
1230 | + // class |
|
1231 | + $output .= ' class="form-check-input" '; |
|
1232 | + |
|
1233 | + // name |
|
1234 | + if ( ! empty( $args['name'] ) ) { |
|
1235 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1236 | + } |
|
1237 | + |
|
1238 | + // id |
|
1239 | + if ( ! empty( $args['id'] ) ) { |
|
1240 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1241 | + } |
|
1242 | + |
|
1243 | + // title |
|
1244 | + if ( ! empty( $args['title'] ) ) { |
|
1245 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1246 | + } |
|
1247 | + |
|
1248 | + // value |
|
1249 | + if ( isset( $args['value'] ) ) { |
|
1250 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1251 | + } |
|
1252 | + |
|
1253 | + // checked, for radio and checkboxes |
|
1254 | + if ( $args['checked'] ) { |
|
1255 | + $output .= ' checked '; |
|
1256 | + } |
|
1257 | + |
|
1258 | + // data-attributes |
|
1259 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1260 | + |
|
1261 | + // aria-attributes |
|
1262 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1263 | + |
|
1264 | + // extra attributes |
|
1265 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
1266 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1267 | + } |
|
1268 | + |
|
1269 | + // required |
|
1270 | + if ( ! empty( $args['required'] ) ) { |
|
1271 | + $output .= ' required '; |
|
1272 | + } |
|
1273 | + |
|
1274 | + // close opening tag |
|
1275 | + $output .= ' >'; |
|
1276 | + |
|
1277 | + // label |
|
1278 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1279 | + } elseif ( ! empty( $args['label'] ) ) { |
|
1280 | + $output .= self::label( array( |
|
1281 | + 'title' => $args['label'], |
|
1282 | + 'for' => $args['id'] . $count, |
|
1283 | + 'class' => 'form-check-label' |
|
1284 | + ), 'radio' ); |
|
1285 | + } |
|
1286 | + |
|
1287 | + // wrap |
|
1288 | + if ( ! $args['no_wrap'] ) { |
|
1289 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1290 | + |
|
1291 | + // Unique wrap class |
|
1292 | + $uniq_class = 'fwrap'; |
|
1293 | + if ( ! empty( $args['name'] ) ) { |
|
1294 | + $uniq_class .= '-' . $args['name']; |
|
1295 | + } else if ( ! empty( $args['id'] ) ) { |
|
1296 | + $uniq_class .= '-' . $args['id']; |
|
1297 | + } |
|
1298 | + |
|
1299 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1300 | + $uniq_class .= '-' . $args['value']; |
|
1301 | + } else { |
|
1302 | + $uniq_class .= '-' . $count; |
|
1303 | + } |
|
1304 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1305 | + |
|
1306 | + $output = self::wrap( array( |
|
1307 | + 'content' => $output, |
|
1308 | + 'class' => $wrap_class |
|
1309 | + ) ); |
|
1310 | + } |
|
1311 | + |
|
1312 | + return $output; |
|
1313 | + } |
|
1314 | 1314 | |
1315 | 1315 | } |
1316 | 1316 | \ No newline at end of file |
@@ -14,94 +14,94 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
29 | - |
|
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | + |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct() { |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct() { |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) ); |
|
68 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
69 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
70 | 70 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
71 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
77 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
78 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
79 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
80 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
81 | - |
|
82 | - // Setup/welcome |
|
83 | - if ( ! empty( $_GET['page'] ) ) { |
|
84 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
85 | - case 'gp-setup': |
|
86 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
87 | - break; |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Register admin scripts |
|
95 | - * |
|
96 | - */ |
|
97 | - public function enqeue_scripts() { |
|
71 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
75 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
76 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
77 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
78 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
79 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
80 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
81 | + |
|
82 | + // Setup/welcome |
|
83 | + if ( ! empty( $_GET['page'] ) ) { |
|
84 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
85 | + case 'gp-setup': |
|
86 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
87 | + break; |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Register admin scripts |
|
95 | + * |
|
96 | + */ |
|
97 | + public function enqeue_scripts() { |
|
98 | 98 | global $current_screen, $pagenow; |
99 | 99 | |
100 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
101 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
100 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
101 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
102 | 102 | |
103 | 103 | if ( ! empty( $current_screen->post_type ) ) { |
104 | - $page = $current_screen->post_type; |
|
104 | + $page = $current_screen->post_type; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // General styles. |
@@ -122,53 +122,53 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | // Payment form scripts. |
125 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
125 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
126 | 126 | $this->load_payment_form_scripts(); |
127 | 127 | } |
128 | 128 | |
129 | - if ( $page == 'wpinv-subscriptions' ) { |
|
130 | - wp_enqueue_script( 'postbox' ); |
|
131 | - } |
|
129 | + if ( $page == 'wpinv-subscriptions' ) { |
|
130 | + wp_enqueue_script( 'postbox' ); |
|
131 | + } |
|
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Returns admin js translations. |
|
137 | - * |
|
138 | - */ |
|
139 | - protected function get_admin_i18() { |
|
136 | + * Returns admin js translations. |
|
137 | + * |
|
138 | + */ |
|
139 | + protected function get_admin_i18() { |
|
140 | 140 | global $post; |
141 | 141 | |
142 | - $date_range = array( |
|
143 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
144 | - ); |
|
142 | + $date_range = array( |
|
143 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
144 | + ); |
|
145 | 145 | |
146 | - if ( $date_range['period'] == 'custom' ) { |
|
146 | + if ( $date_range['period'] == 'custom' ) { |
|
147 | 147 | |
148 | - if ( isset( $_GET['from'] ) ) { |
|
149 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
150 | - } |
|
148 | + if ( isset( $_GET['from'] ) ) { |
|
149 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
150 | + } |
|
151 | 151 | |
152 | - if ( isset( $_GET['to'] ) ) { |
|
153 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
154 | - } |
|
152 | + if ( isset( $_GET['to'] ) ) { |
|
153 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | $i18n = array( |
158 | 158 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
159 | 159 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
160 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
161 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
162 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
163 | - 'date_range' => $date_range, |
|
160 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
161 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
162 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
163 | + 'date_range' => $date_range, |
|
164 | 164 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
165 | 165 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
166 | 166 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
167 | 167 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
168 | 168 | 'tax' => wpinv_tax_amount(), |
169 | 169 | 'discount' => 0, |
170 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
171 | - 'currency' => wpinv_get_currency(), |
|
170 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
171 | + 'currency' => wpinv_get_currency(), |
|
172 | 172 | 'currency_pos' => wpinv_currency_position(), |
173 | 173 | 'thousand_sep' => wpinv_thousands_separator(), |
174 | 174 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -188,117 +188,117 @@ discard block |
||
188 | 188 | 'item_description' => __( 'Item Description', 'invoicing' ), |
189 | 189 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
190 | 190 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
191 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
192 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
193 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
194 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
195 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
191 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
192 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
193 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
194 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
195 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
196 | 196 | ); |
197 | 197 | |
198 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
198 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
199 | 199 | |
200 | - $invoice = new WPInv_Invoice( $post ); |
|
201 | - $i18n['save_invoice'] = sprintf( |
|
202 | - __( 'Save %s', 'invoicing' ), |
|
203 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
204 | - ); |
|
200 | + $invoice = new WPInv_Invoice( $post ); |
|
201 | + $i18n['save_invoice'] = sprintf( |
|
202 | + __( 'Save %s', 'invoicing' ), |
|
203 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
204 | + ); |
|
205 | 205 | |
206 | - $i18n['invoice_description'] = sprintf( |
|
207 | - __( '%s Description', 'invoicing' ), |
|
208 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
209 | - ); |
|
206 | + $i18n['invoice_description'] = sprintf( |
|
207 | + __( '%s Description', 'invoicing' ), |
|
208 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
209 | + ); |
|
210 | 210 | |
211 | - } |
|
212 | - return $i18n; |
|
213 | - } |
|
211 | + } |
|
212 | + return $i18n; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Change the admin footer text on GetPaid admin pages. |
|
217 | - * |
|
218 | - * @since 2.0.0 |
|
219 | - * @param string $footer_text |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function admin_footer_text( $footer_text ) { |
|
223 | - global $current_screen; |
|
215 | + /** |
|
216 | + * Change the admin footer text on GetPaid admin pages. |
|
217 | + * |
|
218 | + * @since 2.0.0 |
|
219 | + * @param string $footer_text |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function admin_footer_text( $footer_text ) { |
|
223 | + global $current_screen; |
|
224 | 224 | |
225 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
225 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
226 | 226 | |
227 | 227 | if ( ! empty( $current_screen->post_type ) ) { |
228 | - $page = $current_screen->post_type; |
|
228 | + $page = $current_screen->post_type; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // General styles. |
232 | 232 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
233 | 233 | |
234 | - // Change the footer text |
|
235 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
234 | + // Change the footer text |
|
235 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
236 | 236 | |
237 | - $rating_url = esc_url( |
|
238 | - wp_nonce_url( |
|
239 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
240 | - 'getpaid-nonce', |
|
241 | - 'getpaid-nonce' |
|
237 | + $rating_url = esc_url( |
|
238 | + wp_nonce_url( |
|
239 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
240 | + 'getpaid-nonce', |
|
241 | + 'getpaid-nonce' |
|
242 | 242 | ) |
243 | - ); |
|
243 | + ); |
|
244 | 244 | |
245 | - $footer_text = sprintf( |
|
246 | - /* translators: %s: five stars */ |
|
247 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
248 | - "<a href='$rating_url'>★★★★★</a>" |
|
249 | - ); |
|
245 | + $footer_text = sprintf( |
|
246 | + /* translators: %s: five stars */ |
|
247 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
248 | + "<a href='$rating_url'>★★★★★</a>" |
|
249 | + ); |
|
250 | 250 | |
251 | - } else { |
|
251 | + } else { |
|
252 | 252 | |
253 | - $footer_text = sprintf( |
|
254 | - /* translators: %s: GetPaid */ |
|
255 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
256 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
257 | - ); |
|
253 | + $footer_text = sprintf( |
|
254 | + /* translators: %s: GetPaid */ |
|
255 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
256 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
257 | + ); |
|
258 | 258 | |
259 | - } |
|
259 | + } |
|
260 | 260 | } |
261 | 261 | |
262 | - return $footer_text; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Redirects to wp.org to rate the plugin. |
|
267 | - * |
|
268 | - * @since 2.0.0 |
|
269 | - */ |
|
270 | - public function redirect_to_wordpress_rating_page() { |
|
271 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
272 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
273 | - exit; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Loads payment form js. |
|
278 | - * |
|
279 | - */ |
|
280 | - protected function load_payment_form_scripts() { |
|
262 | + return $footer_text; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Redirects to wp.org to rate the plugin. |
|
267 | + * |
|
268 | + * @since 2.0.0 |
|
269 | + */ |
|
270 | + public function redirect_to_wordpress_rating_page() { |
|
271 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
272 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
273 | + exit; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Loads payment form js. |
|
278 | + * |
|
279 | + */ |
|
280 | + protected function load_payment_form_scripts() { |
|
281 | 281 | global $post; |
282 | 282 | |
283 | 283 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
284 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
285 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
284 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
285 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
286 | 286 | |
287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.min.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), WPINV_VERSION ); |
|
287 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.min.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), WPINV_VERSION ); |
|
288 | 288 | |
289 | - wp_localize_script( |
|
289 | + wp_localize_script( |
|
290 | 290 | 'wpinv-admin-payment-form-script', |
291 | 291 | 'wpinvPaymentFormAdmin', |
292 | 292 | array( |
293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | - 'currency' => wpinv_currency_symbol(), |
|
296 | - 'position' => wpinv_currency_position(), |
|
297 | - 'decimals' => (int) wpinv_decimals(), |
|
298 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
293 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | + 'currency' => wpinv_currency_symbol(), |
|
296 | + 'position' => wpinv_currency_position(), |
|
297 | + 'decimals' => (int) wpinv_decimals(), |
|
298 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
302 | 302 | ) |
303 | 303 | ); |
304 | 304 | |
@@ -307,19 +307,19 @@ discard block |
||
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | - * Add our classes to admin pages. |
|
310 | + * Add our classes to admin pages. |
|
311 | 311 | * |
312 | 312 | * @param string $classes |
313 | 313 | * @return string |
314 | - * |
|
315 | - */ |
|
314 | + * |
|
315 | + */ |
|
316 | 316 | public function admin_body_class( $classes ) { |
317 | - global $pagenow, $post, $current_screen; |
|
317 | + global $pagenow, $post, $current_screen; |
|
318 | 318 | |
319 | 319 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
320 | 320 | |
321 | 321 | if ( ! empty( $current_screen->post_type ) ) { |
322 | - $page = $current_screen->post_type; |
|
322 | + $page = $current_screen->post_type; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -328,70 +328,70 @@ discard block |
||
328 | 328 | |
329 | 329 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
330 | 330 | $classes .= ' wpinv-cpt wpinv'; |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
333 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
334 | 334 | $classes .= ' getpaid-is-invoice-cpt'; |
335 | 335 | } |
336 | 336 | |
337 | - return $classes; |
|
337 | + return $classes; |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
341 | - * Maybe show the AyeCode Connect Notice. |
|
342 | - */ |
|
343 | - public function init_ayecode_connect_helper() { |
|
341 | + * Maybe show the AyeCode Connect Notice. |
|
342 | + */ |
|
343 | + public function init_ayecode_connect_helper() { |
|
344 | 344 | |
345 | - // Register with the deactivation survey class. |
|
346 | - AyeCode_Deactivation_Survey::instance( |
|
345 | + // Register with the deactivation survey class. |
|
346 | + AyeCode_Deactivation_Survey::instance( |
|
347 | 347 | array( |
348 | - 'slug' => 'invoicing', |
|
349 | - 'version' => WPINV_VERSION, |
|
350 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
348 | + 'slug' => 'invoicing', |
|
349 | + 'version' => WPINV_VERSION, |
|
350 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
353 | 353 | ) |
354 | 354 | ); |
355 | 355 | |
356 | 356 | new AyeCode_Connect_Helper( |
357 | 357 | array( |
358 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
358 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | + 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
365 | 365 | ), |
366 | 366 | array( 'wpi-addons' ) |
367 | 367 | ); |
368 | 368 | |
369 | 369 | } |
370 | 370 | |
371 | - /** |
|
372 | - * Redirect users to settings on activation. |
|
373 | - * |
|
374 | - * @return void |
|
375 | - */ |
|
376 | - public function activation_redirect() { |
|
371 | + /** |
|
372 | + * Redirect users to settings on activation. |
|
373 | + * |
|
374 | + * @return void |
|
375 | + */ |
|
376 | + public function activation_redirect() { |
|
377 | 377 | |
378 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
378 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
379 | 379 | |
380 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | - return; |
|
382 | - } |
|
380 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | 383 | |
384 | - // Bail if activating from network, or bulk |
|
385 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | - return; |
|
387 | - } |
|
384 | + // Bail if activating from network, or bulk |
|
385 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | + return; |
|
387 | + } |
|
388 | 388 | |
389 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
389 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
390 | 390 | |
391 | 391 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
392 | 392 | exit; |
393 | 393 | |
394 | - } |
|
394 | + } |
|
395 | 395 | |
396 | 396 | /** |
397 | 397 | * Fires an admin action after verifying that a user can fire them. |
@@ -404,555 +404,555 @@ discard block |
||
404 | 404 | } |
405 | 405 | } |
406 | 406 | |
407 | - /** |
|
407 | + /** |
|
408 | 408 | * Duplicate invoice. |
409 | - * |
|
410 | - * @param array $args |
|
409 | + * |
|
410 | + * @param array $args |
|
411 | 411 | */ |
412 | 412 | public function duplicate_invoice( $args ) { |
413 | 413 | |
414 | - if ( empty( $args['invoice_id'] ) ) { |
|
415 | - return; |
|
416 | - } |
|
414 | + if ( empty( $args['invoice_id'] ) ) { |
|
415 | + return; |
|
416 | + } |
|
417 | 417 | |
418 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
418 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
419 | 419 | |
420 | - if ( ! $invoice->exists() ) { |
|
421 | - return; |
|
422 | - } |
|
420 | + if ( ! $invoice->exists() ) { |
|
421 | + return; |
|
422 | + } |
|
423 | 423 | |
424 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
425 | - $new_invoice->save(); |
|
424 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
425 | + $new_invoice->save(); |
|
426 | 426 | |
427 | - if ( $new_invoice->exists() ) { |
|
427 | + if ( $new_invoice->exists() ) { |
|
428 | 428 | |
429 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
429 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
430 | 430 | |
431 | - wp_safe_redirect( |
|
432 | - add_query_arg( |
|
433 | - array( |
|
434 | - 'action' => 'edit', |
|
435 | - 'post' => $new_invoice->get_id(), |
|
436 | - ), |
|
437 | - admin_url( 'post.php' ) |
|
438 | - ) |
|
439 | - ); |
|
440 | - exit; |
|
431 | + wp_safe_redirect( |
|
432 | + add_query_arg( |
|
433 | + array( |
|
434 | + 'action' => 'edit', |
|
435 | + 'post' => $new_invoice->get_id(), |
|
436 | + ), |
|
437 | + admin_url( 'post.php' ) |
|
438 | + ) |
|
439 | + ); |
|
440 | + exit; |
|
441 | 441 | |
442 | - } |
|
442 | + } |
|
443 | 443 | |
444 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
444 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - /** |
|
448 | + /** |
|
449 | 449 | * Refund an invoice. |
450 | - * |
|
451 | - * @param array $args |
|
450 | + * |
|
451 | + * @param array $args |
|
452 | 452 | */ |
453 | 453 | public function refund_invoice( $args ) { |
454 | 454 | |
455 | - if ( empty( $args['invoice_id'] ) ) { |
|
456 | - return; |
|
457 | - } |
|
458 | - |
|
459 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
460 | - |
|
461 | - if ( ! $invoice->exists() || $invoice->is_refunded() ) { |
|
462 | - return; |
|
463 | - } |
|
464 | - |
|
465 | - $invoice->refund(); |
|
466 | - |
|
467 | - // Refund remotely. |
|
468 | - if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) { |
|
469 | - do_action( 'getpaid_refund_invoice_remotely', $invoice ); |
|
470 | - } |
|
471 | - |
|
472 | - // Cancel subscriptions. |
|
473 | - if ( ! empty( $args['getpaid_cancel_subscription'] ) ) { |
|
474 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
475 | - |
|
476 | - if ( ! empty( $subscriptions ) ) { |
|
477 | - if ( ! is_array( $subscriptions ) ) { |
|
478 | - $subscriptions = array( $subscriptions ); |
|
479 | - } |
|
480 | - |
|
481 | - foreach ( $subscriptions as $subscription ) { |
|
482 | - $subscription->cancel(); |
|
483 | - $invoice->add_system_note( |
|
484 | - sprintf( |
|
485 | - // translators: %s: subscription ID. |
|
486 | - __( 'Subscription #%s cancelled', 'invoicing' ), |
|
487 | - $subscription->get_id() |
|
488 | - ) |
|
489 | - ); |
|
490 | - } |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - // Add notice. |
|
495 | - $this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) ); |
|
496 | - |
|
497 | - // Redirect. |
|
498 | - wp_safe_redirect( |
|
499 | - remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) ) |
|
500 | - ); |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
455 | + if ( empty( $args['invoice_id'] ) ) { |
|
456 | + return; |
|
457 | + } |
|
458 | + |
|
459 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
460 | + |
|
461 | + if ( ! $invoice->exists() || $invoice->is_refunded() ) { |
|
462 | + return; |
|
463 | + } |
|
464 | + |
|
465 | + $invoice->refund(); |
|
466 | + |
|
467 | + // Refund remotely. |
|
468 | + if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) { |
|
469 | + do_action( 'getpaid_refund_invoice_remotely', $invoice ); |
|
470 | + } |
|
471 | + |
|
472 | + // Cancel subscriptions. |
|
473 | + if ( ! empty( $args['getpaid_cancel_subscription'] ) ) { |
|
474 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
475 | + |
|
476 | + if ( ! empty( $subscriptions ) ) { |
|
477 | + if ( ! is_array( $subscriptions ) ) { |
|
478 | + $subscriptions = array( $subscriptions ); |
|
479 | + } |
|
480 | + |
|
481 | + foreach ( $subscriptions as $subscription ) { |
|
482 | + $subscription->cancel(); |
|
483 | + $invoice->add_system_note( |
|
484 | + sprintf( |
|
485 | + // translators: %s: subscription ID. |
|
486 | + __( 'Subscription #%s cancelled', 'invoicing' ), |
|
487 | + $subscription->get_id() |
|
488 | + ) |
|
489 | + ); |
|
490 | + } |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + // Add notice. |
|
495 | + $this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) ); |
|
496 | + |
|
497 | + // Redirect. |
|
498 | + wp_safe_redirect( |
|
499 | + remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) ) |
|
500 | + ); |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | 504 | * Sends a payment reminder to a customer. |
505 | - * |
|
506 | - * @param array $args |
|
505 | + * |
|
506 | + * @param array $args |
|
507 | 507 | */ |
508 | 508 | public function duplicate_payment_form( $args ) { |
509 | 509 | |
510 | - if ( empty( $args['form_id'] ) ) { |
|
511 | - return; |
|
512 | - } |
|
513 | - |
|
514 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
510 | + if ( empty( $args['form_id'] ) ) { |
|
511 | + return; |
|
512 | + } |
|
515 | 513 | |
516 | - if ( ! $form->exists() ) { |
|
517 | - return; |
|
518 | - } |
|
514 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
519 | 515 | |
520 | - $new_form = new GetPaid_Payment_Form(); |
|
521 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
522 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
523 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
524 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
525 | - $new_form->save(); |
|
516 | + if ( ! $form->exists() ) { |
|
517 | + return; |
|
518 | + } |
|
526 | 519 | |
527 | - if ( $new_form->exists() ) { |
|
528 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
529 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
530 | - } else { |
|
531 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
532 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
533 | - } |
|
520 | + $new_form = new GetPaid_Payment_Form(); |
|
521 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
522 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
523 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
524 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
525 | + $new_form->save(); |
|
526 | + |
|
527 | + if ( $new_form->exists() ) { |
|
528 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
529 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
530 | + } else { |
|
531 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
532 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
533 | + } |
|
534 | 534 | |
535 | - wp_redirect( $url ); |
|
536 | - exit; |
|
537 | - } |
|
535 | + wp_redirect( $url ); |
|
536 | + exit; |
|
537 | + } |
|
538 | 538 | |
539 | - /** |
|
539 | + /** |
|
540 | 540 | * Resets form stats. |
541 | - * |
|
542 | - * @param array $args |
|
541 | + * |
|
542 | + * @param array $args |
|
543 | 543 | */ |
544 | 544 | public function reset_form_stats( $args ) { |
545 | 545 | |
546 | - if ( empty( $args['form_id'] ) ) { |
|
547 | - return; |
|
548 | - } |
|
546 | + if ( empty( $args['form_id'] ) ) { |
|
547 | + return; |
|
548 | + } |
|
549 | 549 | |
550 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
550 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
551 | 551 | |
552 | - if ( ! $form->exists() ) { |
|
553 | - return; |
|
554 | - } |
|
552 | + if ( ! $form->exists() ) { |
|
553 | + return; |
|
554 | + } |
|
555 | 555 | |
556 | - $form->set_earned( 0 ); |
|
557 | - $form->set_refunded( 0 ); |
|
558 | - $form->set_cancelled( 0 ); |
|
559 | - $form->set_failed( 0 ); |
|
560 | - $form->save(); |
|
556 | + $form->set_earned( 0 ); |
|
557 | + $form->set_refunded( 0 ); |
|
558 | + $form->set_cancelled( 0 ); |
|
559 | + $form->set_failed( 0 ); |
|
560 | + $form->save(); |
|
561 | 561 | |
562 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
562 | + $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
563 | 563 | |
564 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
565 | - exit; |
|
566 | - } |
|
564 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
565 | + exit; |
|
566 | + } |
|
567 | 567 | |
568 | - /** |
|
568 | + /** |
|
569 | 569 | * Sends a payment reminder to a customer. |
570 | - * |
|
571 | - * @param array $args |
|
570 | + * |
|
571 | + * @param array $args |
|
572 | 572 | */ |
573 | 573 | public function send_customer_invoice( $args ) { |
574 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
575 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
576 | - exit; |
|
577 | - } |
|
574 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
575 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
576 | + exit; |
|
577 | + } |
|
578 | 578 | |
579 | - /** |
|
579 | + /** |
|
580 | 580 | * Sends a payment reminder to a customer. |
581 | - * |
|
582 | - * @param array $args |
|
581 | + * |
|
582 | + * @param array $args |
|
583 | 583 | */ |
584 | 584 | public function send_customer_payment_reminder( $args ) { |
585 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
585 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
586 | 586 | |
587 | - if ( $sent ) { |
|
588 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
589 | - } else { |
|
590 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
591 | - } |
|
587 | + if ( $sent ) { |
|
588 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
589 | + } else { |
|
590 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
591 | + } |
|
592 | 592 | |
593 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
594 | - exit; |
|
595 | - } |
|
593 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
594 | + exit; |
|
595 | + } |
|
596 | 596 | |
597 | - /** |
|
597 | + /** |
|
598 | 598 | * Resets tax rates. |
599 | - * |
|
599 | + * |
|
600 | 600 | */ |
601 | 601 | public function admin_reset_tax_rates() { |
602 | 602 | |
603 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
604 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
605 | - exit; |
|
603 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
604 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
605 | + exit; |
|
606 | 606 | |
607 | - } |
|
607 | + } |
|
608 | 608 | |
609 | - /** |
|
609 | + /** |
|
610 | 610 | * Resets admin pages. |
611 | - * |
|
611 | + * |
|
612 | 612 | */ |
613 | 613 | public function admin_create_missing_pages() { |
614 | - $installer = new GetPaid_Installer(); |
|
615 | - $installer->create_pages(); |
|
616 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
617 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
618 | - exit; |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Refreshes the permalinks. |
|
623 | - */ |
|
624 | - public function admin_refresh_permalinks() { |
|
625 | - flush_rewrite_rules(); |
|
626 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
627 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
628 | - exit; |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
614 | + $installer = new GetPaid_Installer(); |
|
615 | + $installer->create_pages(); |
|
616 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
617 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
618 | + exit; |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Refreshes the permalinks. |
|
623 | + */ |
|
624 | + public function admin_refresh_permalinks() { |
|
625 | + flush_rewrite_rules(); |
|
626 | + $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
627 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
628 | + exit; |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | 632 | * Creates missing admin tables. |
633 | - * |
|
633 | + * |
|
634 | 634 | */ |
635 | 635 | public function admin_create_missing_tables() { |
636 | - global $wpdb; |
|
636 | + global $wpdb; |
|
637 | 637 | |
638 | - GetPaid_Installer::create_db_tables(); |
|
639 | - GetPaid_Installer::migrate_old_customers(); |
|
638 | + GetPaid_Installer::create_db_tables(); |
|
639 | + GetPaid_Installer::migrate_old_customers(); |
|
640 | 640 | |
641 | - if ( '' !== $wpdb->last_error ) { |
|
642 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
643 | - } else { |
|
644 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
645 | - } |
|
641 | + if ( '' !== $wpdb->last_error ) { |
|
642 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
643 | + } else { |
|
644 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
645 | + } |
|
646 | 646 | |
647 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
648 | - exit; |
|
649 | - } |
|
647 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
648 | + exit; |
|
649 | + } |
|
650 | 650 | |
651 | - /** |
|
651 | + /** |
|
652 | 652 | * Migrates old invoices to the new database tables. |
653 | - * |
|
653 | + * |
|
654 | 654 | */ |
655 | 655 | public function admin_migrate_old_invoices() { |
656 | 656 | |
657 | - // Migrate the invoices. |
|
658 | - $installer = new GetPaid_Installer(); |
|
659 | - $installer->migrate_old_invoices(); |
|
657 | + // Migrate the invoices. |
|
658 | + $installer = new GetPaid_Installer(); |
|
659 | + $installer->migrate_old_invoices(); |
|
660 | 660 | |
661 | - // Show an admin message. |
|
662 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
661 | + // Show an admin message. |
|
662 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
663 | 663 | |
664 | - // Redirect the admin. |
|
665 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
666 | - exit; |
|
664 | + // Redirect the admin. |
|
665 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
666 | + exit; |
|
667 | 667 | |
668 | - } |
|
668 | + } |
|
669 | 669 | |
670 | - /** |
|
670 | + /** |
|
671 | 671 | * Download customers. |
672 | - * |
|
672 | + * |
|
673 | 673 | */ |
674 | 674 | public function admin_download_customers() { |
675 | 675 | |
676 | - $output = fopen( 'php://output', 'w' ); |
|
676 | + $output = fopen( 'php://output', 'w' ); |
|
677 | 677 | |
678 | - if ( false === $output ) { |
|
679 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
680 | - } |
|
678 | + if ( false === $output ) { |
|
679 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
680 | + } |
|
681 | 681 | |
682 | - header( 'Content-Type:text/csv' ); |
|
683 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
682 | + header( 'Content-Type:text/csv' ); |
|
683 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
684 | 684 | |
685 | - /** @var GetPaid_Customer[] $customers */ |
|
686 | - $customers = getpaid_get_customers( array( 'number' => -1 ) ); |
|
687 | - $columns = array_keys( GetPaid_Customer_Data_Store::get_database_fields() ); |
|
685 | + /** @var GetPaid_Customer[] $customers */ |
|
686 | + $customers = getpaid_get_customers( array( 'number' => -1 ) ); |
|
687 | + $columns = array_keys( GetPaid_Customer_Data_Store::get_database_fields() ); |
|
688 | 688 | |
689 | - // Output the csv column headers. |
|
690 | - fputcsv( $output, $columns ); |
|
689 | + // Output the csv column headers. |
|
690 | + fputcsv( $output, $columns ); |
|
691 | 691 | |
692 | - // Loop through |
|
693 | - foreach ( $customers as $customer ) { |
|
692 | + // Loop through |
|
693 | + foreach ( $customers as $customer ) { |
|
694 | 694 | |
695 | - $row = array(); |
|
695 | + $row = array(); |
|
696 | 696 | |
697 | - foreach ( $columns as $column ) { |
|
698 | - $row[] = (string) maybe_serialize( $customer->get( $column, 'edit' ) ); |
|
699 | - } |
|
697 | + foreach ( $columns as $column ) { |
|
698 | + $row[] = (string) maybe_serialize( $customer->get( $column, 'edit' ) ); |
|
699 | + } |
|
700 | 700 | |
701 | - fputcsv( $output, $row ); |
|
702 | - } |
|
701 | + fputcsv( $output, $row ); |
|
702 | + } |
|
703 | 703 | |
704 | - fclose( $output ); |
|
705 | - exit; |
|
704 | + fclose( $output ); |
|
705 | + exit; |
|
706 | 706 | |
707 | - } |
|
707 | + } |
|
708 | 708 | |
709 | - /** |
|
709 | + /** |
|
710 | 710 | * Installs a plugin. |
711 | - * |
|
712 | - * @param array $data |
|
711 | + * |
|
712 | + * @param array $data |
|
713 | 713 | */ |
714 | 714 | public function admin_install_plugin( $data ) { |
715 | 715 | |
716 | - if ( ! empty( $data['plugins'] ) ) { |
|
717 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
718 | - wp_cache_flush(); |
|
716 | + if ( ! empty( $data['plugins'] ) ) { |
|
717 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
718 | + wp_cache_flush(); |
|
719 | 719 | |
720 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
721 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
722 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
723 | - $installed = $upgrader->install( $plugin_zip ); |
|
720 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
721 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
722 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
723 | + $installed = $upgrader->install( $plugin_zip ); |
|
724 | 724 | |
725 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
726 | - activate_plugin( $file, '', false, true ); |
|
727 | - } else { |
|
728 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
729 | - } |
|
725 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
726 | + activate_plugin( $file, '', false, true ); |
|
727 | + } else { |
|
728 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
729 | + } |
|
730 | 730 | } |
731 | 731 | } |
732 | 732 | |
733 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
734 | - wp_safe_redirect( $redirect ); |
|
735 | - exit; |
|
733 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
734 | + wp_safe_redirect( $redirect ); |
|
735 | + exit; |
|
736 | 736 | |
737 | - } |
|
737 | + } |
|
738 | 738 | |
739 | - /** |
|
739 | + /** |
|
740 | 740 | * Connects a gateway. |
741 | - * |
|
742 | - * @param array $data |
|
741 | + * |
|
742 | + * @param array $data |
|
743 | 743 | */ |
744 | 744 | public function admin_connect_gateway( $data ) { |
745 | 745 | |
746 | - if ( ! empty( $data['plugin'] ) ) { |
|
746 | + if ( ! empty( $data['plugin'] ) ) { |
|
747 | 747 | |
748 | - $gateway = sanitize_key( $data['plugin'] ); |
|
749 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
748 | + $gateway = sanitize_key( $data['plugin'] ); |
|
749 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
750 | 750 | |
751 | - if ( ! empty( $connect_url ) ) { |
|
752 | - wp_redirect( $connect_url ); |
|
753 | - exit; |
|
754 | - } |
|
751 | + if ( ! empty( $connect_url ) ) { |
|
752 | + wp_redirect( $connect_url ); |
|
753 | + exit; |
|
754 | + } |
|
755 | 755 | |
756 | - if ( 'stripe' == $data['plugin'] ) { |
|
757 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
758 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
759 | - wp_cache_flush(); |
|
756 | + if ( 'stripe' == $data['plugin'] ) { |
|
757 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
758 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
759 | + wp_cache_flush(); |
|
760 | 760 | |
761 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
762 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
763 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
764 | - $upgrader->install( $plugin_zip ); |
|
765 | - } |
|
761 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
762 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
763 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
764 | + $upgrader->install( $plugin_zip ); |
|
765 | + } |
|
766 | 766 | |
767 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
768 | - } |
|
767 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
768 | + } |
|
769 | 769 | |
770 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
771 | - if ( ! empty( $connect_url ) ) { |
|
772 | - wp_redirect( $connect_url ); |
|
773 | - exit; |
|
774 | - } |
|
770 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
771 | + if ( ! empty( $connect_url ) ) { |
|
772 | + wp_redirect( $connect_url ); |
|
773 | + exit; |
|
774 | + } |
|
775 | 775 | } |
776 | 776 | |
777 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
778 | - wp_safe_redirect( $redirect ); |
|
779 | - exit; |
|
777 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
778 | + wp_safe_redirect( $redirect ); |
|
779 | + exit; |
|
780 | 780 | |
781 | - } |
|
781 | + } |
|
782 | 782 | |
783 | - /** |
|
783 | + /** |
|
784 | 784 | * Recalculates discounts. |
785 | - * |
|
785 | + * |
|
786 | 786 | */ |
787 | 787 | public function admin_recalculate_discounts() { |
788 | - global $wpdb; |
|
788 | + global $wpdb; |
|
789 | 789 | |
790 | - // Fetch all invoices that have discount codes. |
|
791 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
792 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
790 | + // Fetch all invoices that have discount codes. |
|
791 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
792 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
793 | 793 | |
794 | - foreach ( $invoices as $invoice ) { |
|
794 | + foreach ( $invoices as $invoice ) { |
|
795 | 795 | |
796 | - $invoice = new WPInv_Invoice( $invoice ); |
|
796 | + $invoice = new WPInv_Invoice( $invoice ); |
|
797 | 797 | |
798 | - if ( ! $invoice->exists() ) { |
|
799 | - continue; |
|
800 | - } |
|
798 | + if ( ! $invoice->exists() ) { |
|
799 | + continue; |
|
800 | + } |
|
801 | 801 | |
802 | - // Abort if the discount does not exist or does not apply here. |
|
803 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
804 | - if ( ! $discount->exists() ) { |
|
805 | - continue; |
|
806 | - } |
|
802 | + // Abort if the discount does not exist or does not apply here. |
|
803 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
804 | + if ( ! $discount->exists() ) { |
|
805 | + continue; |
|
806 | + } |
|
807 | 807 | |
808 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
809 | - $invoice->recalculate_total(); |
|
808 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
809 | + $invoice->recalculate_total(); |
|
810 | 810 | |
811 | - if ( $invoice->get_total_discount() > 0 ) { |
|
812 | - $invoice->save(); |
|
813 | - } |
|
811 | + if ( $invoice->get_total_discount() > 0 ) { |
|
812 | + $invoice->save(); |
|
813 | + } |
|
814 | 814 | } |
815 | 815 | |
816 | - // Show an admin message. |
|
817 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
816 | + // Show an admin message. |
|
817 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
818 | 818 | |
819 | - // Redirect the admin. |
|
820 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
821 | - exit; |
|
819 | + // Redirect the admin. |
|
820 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
821 | + exit; |
|
822 | 822 | |
823 | - } |
|
823 | + } |
|
824 | 824 | |
825 | 825 | /** |
826 | - * Returns an array of admin notices. |
|
827 | - * |
|
828 | - * @since 1.0.19 |
|
826 | + * Returns an array of admin notices. |
|
827 | + * |
|
828 | + * @since 1.0.19 |
|
829 | 829 | * @return array |
830 | - */ |
|
831 | - public function get_notices() { |
|
832 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
830 | + */ |
|
831 | + public function get_notices() { |
|
832 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
833 | 833 | return is_array( $notices ) ? $notices : array(); |
834 | - } |
|
834 | + } |
|
835 | 835 | |
836 | - /** |
|
837 | - * Checks if we have any admin notices. |
|
838 | - * |
|
839 | - * @since 2.0.4 |
|
836 | + /** |
|
837 | + * Checks if we have any admin notices. |
|
838 | + * |
|
839 | + * @since 2.0.4 |
|
840 | 840 | * @return array |
841 | - */ |
|
842 | - public function has_notices() { |
|
843 | - return count( $this->get_notices() ) > 0; |
|
844 | - } |
|
845 | - |
|
846 | - /** |
|
847 | - * Clears all admin notices |
|
848 | - * |
|
849 | - * @access public |
|
850 | - * @since 1.0.19 |
|
851 | - */ |
|
852 | - public function clear_notices() { |
|
853 | - delete_option( 'wpinv_admin_notices' ); |
|
854 | - } |
|
855 | - |
|
856 | - /** |
|
857 | - * Saves a new admin notice |
|
858 | - * |
|
859 | - * @access public |
|
860 | - * @since 1.0.19 |
|
861 | - */ |
|
862 | - public function save_notice( $type, $message ) { |
|
863 | - $notices = $this->get_notices(); |
|
864 | - |
|
865 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
866 | - $notices[ $type ] = array(); |
|
867 | - } |
|
868 | - |
|
869 | - $notices[ $type ][] = $message; |
|
870 | - |
|
871 | - update_option( 'wpinv_admin_notices', $notices ); |
|
872 | - } |
|
873 | - |
|
874 | - /** |
|
875 | - * Displays a success notice |
|
876 | - * |
|
877 | - * @param string $msg The message to qeue. |
|
878 | - * @access public |
|
879 | - * @since 1.0.19 |
|
880 | - */ |
|
881 | - public function show_success( $msg ) { |
|
882 | - $this->save_notice( 'success', $msg ); |
|
883 | - } |
|
884 | - |
|
885 | - /** |
|
886 | - * Displays a error notice |
|
887 | - * |
|
888 | - * @access public |
|
889 | - * @param string $msg The message to qeue. |
|
890 | - * @since 1.0.19 |
|
891 | - */ |
|
892 | - public function show_error( $msg ) { |
|
893 | - $this->save_notice( 'error', $msg ); |
|
894 | - } |
|
895 | - |
|
896 | - /** |
|
897 | - * Displays a warning notice |
|
898 | - * |
|
899 | - * @access public |
|
900 | - * @param string $msg The message to qeue. |
|
901 | - * @since 1.0.19 |
|
902 | - */ |
|
903 | - public function show_warning( $msg ) { |
|
904 | - $this->save_notice( 'warning', $msg ); |
|
905 | - } |
|
906 | - |
|
907 | - /** |
|
908 | - * Displays a info notice |
|
909 | - * |
|
910 | - * @access public |
|
911 | - * @param string $msg The message to qeue. |
|
912 | - * @since 1.0.19 |
|
913 | - */ |
|
914 | - public function show_info( $msg ) { |
|
915 | - $this->save_notice( 'info', $msg ); |
|
916 | - } |
|
917 | - |
|
918 | - /** |
|
919 | - * Show notices |
|
920 | - * |
|
921 | - * @access public |
|
922 | - * @since 1.0.19 |
|
923 | - */ |
|
924 | - public function show_notices() { |
|
841 | + */ |
|
842 | + public function has_notices() { |
|
843 | + return count( $this->get_notices() ) > 0; |
|
844 | + } |
|
845 | + |
|
846 | + /** |
|
847 | + * Clears all admin notices |
|
848 | + * |
|
849 | + * @access public |
|
850 | + * @since 1.0.19 |
|
851 | + */ |
|
852 | + public function clear_notices() { |
|
853 | + delete_option( 'wpinv_admin_notices' ); |
|
854 | + } |
|
855 | + |
|
856 | + /** |
|
857 | + * Saves a new admin notice |
|
858 | + * |
|
859 | + * @access public |
|
860 | + * @since 1.0.19 |
|
861 | + */ |
|
862 | + public function save_notice( $type, $message ) { |
|
863 | + $notices = $this->get_notices(); |
|
864 | + |
|
865 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
866 | + $notices[ $type ] = array(); |
|
867 | + } |
|
868 | + |
|
869 | + $notices[ $type ][] = $message; |
|
870 | + |
|
871 | + update_option( 'wpinv_admin_notices', $notices ); |
|
872 | + } |
|
873 | + |
|
874 | + /** |
|
875 | + * Displays a success notice |
|
876 | + * |
|
877 | + * @param string $msg The message to qeue. |
|
878 | + * @access public |
|
879 | + * @since 1.0.19 |
|
880 | + */ |
|
881 | + public function show_success( $msg ) { |
|
882 | + $this->save_notice( 'success', $msg ); |
|
883 | + } |
|
884 | + |
|
885 | + /** |
|
886 | + * Displays a error notice |
|
887 | + * |
|
888 | + * @access public |
|
889 | + * @param string $msg The message to qeue. |
|
890 | + * @since 1.0.19 |
|
891 | + */ |
|
892 | + public function show_error( $msg ) { |
|
893 | + $this->save_notice( 'error', $msg ); |
|
894 | + } |
|
895 | + |
|
896 | + /** |
|
897 | + * Displays a warning notice |
|
898 | + * |
|
899 | + * @access public |
|
900 | + * @param string $msg The message to qeue. |
|
901 | + * @since 1.0.19 |
|
902 | + */ |
|
903 | + public function show_warning( $msg ) { |
|
904 | + $this->save_notice( 'warning', $msg ); |
|
905 | + } |
|
906 | + |
|
907 | + /** |
|
908 | + * Displays a info notice |
|
909 | + * |
|
910 | + * @access public |
|
911 | + * @param string $msg The message to qeue. |
|
912 | + * @since 1.0.19 |
|
913 | + */ |
|
914 | + public function show_info( $msg ) { |
|
915 | + $this->save_notice( 'info', $msg ); |
|
916 | + } |
|
917 | + |
|
918 | + /** |
|
919 | + * Show notices |
|
920 | + * |
|
921 | + * @access public |
|
922 | + * @since 1.0.19 |
|
923 | + */ |
|
924 | + public function show_notices() { |
|
925 | 925 | |
926 | 926 | $notices = $this->get_notices(); |
927 | 927 | $this->clear_notices(); |
928 | 928 | |
929 | - foreach ( $notices as $type => $messages ) { |
|
929 | + foreach ( $notices as $type => $messages ) { |
|
930 | 930 | |
931 | - if ( ! is_array( $messages ) ) { |
|
932 | - continue; |
|
933 | - } |
|
931 | + if ( ! is_array( $messages ) ) { |
|
932 | + continue; |
|
933 | + } |
|
934 | 934 | |
935 | 935 | $type = esc_attr( $type ); |
936 | - foreach ( $messages as $message ) { |
|
937 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
936 | + foreach ( $messages as $message ) { |
|
937 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
938 | 938 | } |
939 | 939 | } |
940 | 940 | |
941 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
942 | - |
|
943 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
944 | - $url = wp_nonce_url( |
|
945 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
946 | - 'getpaid-nonce', |
|
947 | - 'getpaid-nonce' |
|
948 | - ); |
|
949 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
950 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
951 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
952 | - break; |
|
953 | - } |
|
941 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
942 | + |
|
943 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
944 | + $url = wp_nonce_url( |
|
945 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
946 | + 'getpaid-nonce', |
|
947 | + 'getpaid-nonce' |
|
948 | + ); |
|
949 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
950 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
951 | + echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
952 | + break; |
|
953 | + } |
|
954 | 954 | } |
955 | 955 | |
956 | - } |
|
956 | + } |
|
957 | 957 | |
958 | 958 | } |
@@ -6,246 +6,246 @@ discard block |
||
6 | 6 | |
7 | 7 | class Super_Duper_Bricks_Element extends \Bricks\Element { |
8 | 8 | |
9 | - public $widget; |
|
10 | - |
|
11 | - public function __construct( $element = null ) { |
|
12 | - |
|
13 | - |
|
14 | - $block_icon = !empty($this->widget->options['block-icon']) ? $this->widget->options['block-icon'] : ''; |
|
15 | - |
|
16 | - |
|
17 | - $this->category = !empty($this->widget->options['textdomain']) ? esc_attr( $this->widget->options['textdomain'] ) : 'Super Duper'; |
|
18 | - $this->name = $this->widget->id_base; |
|
19 | - $this->icon = (strpos($block_icon, 'fa') === 0) ? esc_attr($this->widget->options['block-icon']) : 'fas fa-globe-americas'; |
|
20 | - |
|
21 | - parent::__construct($element); |
|
22 | - } |
|
23 | - |
|
24 | - /** |
|
25 | - * Set the element name. |
|
26 | - * |
|
27 | - * @return array|string|string[]|null |
|
28 | - */ |
|
29 | - public function get_label() { |
|
30 | - $escaped_text = esc_attr( $this->widget->name ); |
|
31 | - return str_replace( ' > ', ' > ', $escaped_text ); // keep our > but have it safe |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Bricks function to set the controls |
|
36 | - * |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function set_controls() { |
|
40 | - $args = $this->sd_convert_arguments($this->widget); |
|
41 | - |
|
42 | - if (!empty($args)) { |
|
43 | - $this->controls = $this->controls + $args; |
|
44 | - } |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Set the bricks control groups from the GD ones. |
|
50 | - * |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function set_control_groups() { |
|
54 | - $args = $this->sd_get_arguments(); |
|
55 | - |
|
56 | - $groups = array(); |
|
57 | - if(!empty($args)) { |
|
58 | - foreach ($args as $k => $v) { |
|
59 | - $g_slug = !empty($v['group']) ? sanitize_title( $v['group'] ) : ''; |
|
60 | - if($g_slug && empty($groups[$g_slug])) { |
|
61 | - $groups[$g_slug] = array( |
|
62 | - 'title' => esc_html( $v['group'] ), |
|
63 | - 'tab' => 'content', |
|
64 | - ); |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
68 | - |
|
69 | - if(!empty($groups)) { |
|
70 | - $this->control_groups = $this->control_groups + $groups; |
|
71 | - } |
|
72 | - |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Get the setting input arguments. |
|
77 | - * |
|
78 | - * @return mixed |
|
79 | - */ |
|
80 | - public function sd_get_arguments() { |
|
81 | - $args = $this->widget->set_arguments(); |
|
82 | - $arg_keys_subtract = $this->sd_remove_arguments(); |
|
83 | - |
|
84 | - if ( ! empty( $arg_keys_subtract ) ) { |
|
85 | - foreach($arg_keys_subtract as $key ){ |
|
86 | - unset($args[$key]); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - return $args; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Simply use our own render function for the output. |
|
96 | - * |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function render() { |
|
100 | - $settings = $this->sd_maybe_convert_values( $this->settings ); |
|
101 | - |
|
102 | - |
|
103 | - // set the AyeCode UI calss on the wrapper |
|
104 | - $this->set_attribute( '_root', 'class', 'bsui' ); |
|
105 | - |
|
106 | - // we might need to add a placeholder here for previews. |
|
107 | - |
|
108 | - // add the bricks attributes to wrapper |
|
109 | - echo "<div {$this->render_attributes( '_root' )}>"; |
|
110 | - echo $this->widget->output($settings); |
|
111 | - echo '</div>'; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Values can never be arrays so convert if bricks setting make it an array. |
|
116 | - * |
|
117 | - * @param $settings |
|
118 | - * @return mixed |
|
119 | - */ |
|
120 | - public function sd_maybe_convert_values( $settings ) { |
|
121 | - |
|
122 | - |
|
123 | - if (!empty($settings)) { |
|
124 | - foreach( $settings as $k => $v ) { |
|
125 | - if(is_array($v)) { |
|
126 | - $value = ''; |
|
127 | - // is color |
|
128 | - if (isset($v['hex'])) { |
|
129 | - $value = $v['hex']; |
|
130 | - } elseif (isset($v['icon'])) { |
|
131 | - $value = $v['icon']; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - // set the value |
|
136 | - $settings[$k] = $value; |
|
137 | - } |
|
138 | - |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - return $settings; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Convert SD arguments to Bricks arguments. |
|
147 | - * |
|
148 | - * @param $widget |
|
149 | - * |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - public function sd_convert_arguments() |
|
153 | - { |
|
154 | - $bricks_args = array(); |
|
155 | - |
|
156 | - $args = $this->sd_get_arguments(); |
|
157 | - |
|
158 | - if (!empty($args)) { |
|
159 | - foreach ($args as $key => $arg) { |
|
160 | - |
|
161 | - // convert title |
|
162 | - if (!empty($arg['title'])) { |
|
163 | - $arg['label'] = $arg['title']; |
|
164 | - unset($arg['title']); |
|
165 | - } |
|
166 | - |
|
167 | - // set fields not to use dynamic data |
|
168 | - $arg['hasDynamicData'] = false; |
|
169 | - |
|
170 | - if (!empty($arg['group'])) { |
|
171 | - $arg['group'] = sanitize_title($arg['group']); |
|
172 | - } |
|
173 | - |
|
174 | - $arg['rerender'] = true; |
|
175 | - |
|
176 | - // required |
|
177 | - if(!empty($arg['element_require'])) { |
|
178 | - $arg['required'] = $this->sd_convert_required($arg['element_require']); |
|
179 | - unset($arg['element_require']); |
|
180 | - } |
|
181 | - |
|
182 | - // icons |
|
183 | - if ('icon' === $key) { |
|
184 | - $arg['type'] = 'icon'; |
|
185 | - } |
|
186 | - |
|
187 | - $bricks_args[$key] = $arg; |
|
188 | - |
|
189 | - } |
|
190 | - |
|
191 | - } |
|
192 | - |
|
193 | - return $bricks_args; |
|
194 | - |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Convert the SD element_required to the Bricks required syntax. |
|
199 | - * |
|
200 | - * @param $element_require |
|
201 | - * @return array |
|
202 | - */ |
|
203 | - public function sd_convert_required($element_require) { |
|
204 | - $bricks_required = []; |
|
205 | - |
|
206 | - // Handle logical OR (||) for multiple values |
|
207 | - if (strpos($element_require, '||') !== false) { |
|
208 | - preg_match('/\[%(.+?)%\] *== *"(.*?)"/', $element_require, $matches); |
|
209 | - if ($matches) { |
|
210 | - $control_id = $matches[1]; |
|
211 | - preg_match_all('/\[%.*?%\] *== *"(.*?)"/', $element_require, $value_matches); |
|
212 | - $values = $value_matches[1]; |
|
213 | - $bricks_required[] = [$control_id, '=', $values]; |
|
214 | - } |
|
215 | - return $bricks_required; |
|
216 | - } |
|
217 | - |
|
218 | - // Match individual conditions |
|
219 | - preg_match_all('/(!)?\[%(.*?)%\](?:\s*([!=<>]=?)\s*(".*?"|\'.*?\'|\d+))?/', $element_require, $matches, PREG_SET_ORDER); |
|
220 | - |
|
221 | - foreach ($matches as $match) { |
|
222 | - $is_negation = isset($match[1]) && $match[1] === '!'; |
|
223 | - $control_id = $match[2]; |
|
224 | - $operator = isset($match[3]) ? str_replace('==', '=', $match[3]) : ($is_negation ? '=' : '!='); |
|
225 | - $value = isset($match[4]) ? trim($match[4], '"\'') : ($is_negation ? '' : ''); |
|
226 | - |
|
227 | - // Adjust for negation without explicit operator |
|
228 | - if ($is_negation && !isset($match[3])) { |
|
229 | - $operator = '='; |
|
230 | - $value = ''; |
|
231 | - } |
|
232 | - |
|
233 | - $bricks_required[] = [$control_id, $operator, $value]; |
|
234 | - } |
|
235 | - |
|
236 | - return $bricks_required; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * A way to remove some settings by keys. |
|
242 | - * |
|
243 | - * @return array |
|
244 | - */ |
|
245 | - public function sd_remove_arguments() |
|
246 | - { |
|
247 | - return array(); |
|
248 | - } |
|
9 | + public $widget; |
|
10 | + |
|
11 | + public function __construct( $element = null ) { |
|
12 | + |
|
13 | + |
|
14 | + $block_icon = !empty($this->widget->options['block-icon']) ? $this->widget->options['block-icon'] : ''; |
|
15 | + |
|
16 | + |
|
17 | + $this->category = !empty($this->widget->options['textdomain']) ? esc_attr( $this->widget->options['textdomain'] ) : 'Super Duper'; |
|
18 | + $this->name = $this->widget->id_base; |
|
19 | + $this->icon = (strpos($block_icon, 'fa') === 0) ? esc_attr($this->widget->options['block-icon']) : 'fas fa-globe-americas'; |
|
20 | + |
|
21 | + parent::__construct($element); |
|
22 | + } |
|
23 | + |
|
24 | + /** |
|
25 | + * Set the element name. |
|
26 | + * |
|
27 | + * @return array|string|string[]|null |
|
28 | + */ |
|
29 | + public function get_label() { |
|
30 | + $escaped_text = esc_attr( $this->widget->name ); |
|
31 | + return str_replace( ' > ', ' > ', $escaped_text ); // keep our > but have it safe |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Bricks function to set the controls |
|
36 | + * |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function set_controls() { |
|
40 | + $args = $this->sd_convert_arguments($this->widget); |
|
41 | + |
|
42 | + if (!empty($args)) { |
|
43 | + $this->controls = $this->controls + $args; |
|
44 | + } |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Set the bricks control groups from the GD ones. |
|
50 | + * |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function set_control_groups() { |
|
54 | + $args = $this->sd_get_arguments(); |
|
55 | + |
|
56 | + $groups = array(); |
|
57 | + if(!empty($args)) { |
|
58 | + foreach ($args as $k => $v) { |
|
59 | + $g_slug = !empty($v['group']) ? sanitize_title( $v['group'] ) : ''; |
|
60 | + if($g_slug && empty($groups[$g_slug])) { |
|
61 | + $groups[$g_slug] = array( |
|
62 | + 'title' => esc_html( $v['group'] ), |
|
63 | + 'tab' => 'content', |
|
64 | + ); |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | + |
|
69 | + if(!empty($groups)) { |
|
70 | + $this->control_groups = $this->control_groups + $groups; |
|
71 | + } |
|
72 | + |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Get the setting input arguments. |
|
77 | + * |
|
78 | + * @return mixed |
|
79 | + */ |
|
80 | + public function sd_get_arguments() { |
|
81 | + $args = $this->widget->set_arguments(); |
|
82 | + $arg_keys_subtract = $this->sd_remove_arguments(); |
|
83 | + |
|
84 | + if ( ! empty( $arg_keys_subtract ) ) { |
|
85 | + foreach($arg_keys_subtract as $key ){ |
|
86 | + unset($args[$key]); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + return $args; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Simply use our own render function for the output. |
|
96 | + * |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function render() { |
|
100 | + $settings = $this->sd_maybe_convert_values( $this->settings ); |
|
101 | + |
|
102 | + |
|
103 | + // set the AyeCode UI calss on the wrapper |
|
104 | + $this->set_attribute( '_root', 'class', 'bsui' ); |
|
105 | + |
|
106 | + // we might need to add a placeholder here for previews. |
|
107 | + |
|
108 | + // add the bricks attributes to wrapper |
|
109 | + echo "<div {$this->render_attributes( '_root' )}>"; |
|
110 | + echo $this->widget->output($settings); |
|
111 | + echo '</div>'; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Values can never be arrays so convert if bricks setting make it an array. |
|
116 | + * |
|
117 | + * @param $settings |
|
118 | + * @return mixed |
|
119 | + */ |
|
120 | + public function sd_maybe_convert_values( $settings ) { |
|
121 | + |
|
122 | + |
|
123 | + if (!empty($settings)) { |
|
124 | + foreach( $settings as $k => $v ) { |
|
125 | + if(is_array($v)) { |
|
126 | + $value = ''; |
|
127 | + // is color |
|
128 | + if (isset($v['hex'])) { |
|
129 | + $value = $v['hex']; |
|
130 | + } elseif (isset($v['icon'])) { |
|
131 | + $value = $v['icon']; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + // set the value |
|
136 | + $settings[$k] = $value; |
|
137 | + } |
|
138 | + |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + return $settings; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Convert SD arguments to Bricks arguments. |
|
147 | + * |
|
148 | + * @param $widget |
|
149 | + * |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + public function sd_convert_arguments() |
|
153 | + { |
|
154 | + $bricks_args = array(); |
|
155 | + |
|
156 | + $args = $this->sd_get_arguments(); |
|
157 | + |
|
158 | + if (!empty($args)) { |
|
159 | + foreach ($args as $key => $arg) { |
|
160 | + |
|
161 | + // convert title |
|
162 | + if (!empty($arg['title'])) { |
|
163 | + $arg['label'] = $arg['title']; |
|
164 | + unset($arg['title']); |
|
165 | + } |
|
166 | + |
|
167 | + // set fields not to use dynamic data |
|
168 | + $arg['hasDynamicData'] = false; |
|
169 | + |
|
170 | + if (!empty($arg['group'])) { |
|
171 | + $arg['group'] = sanitize_title($arg['group']); |
|
172 | + } |
|
173 | + |
|
174 | + $arg['rerender'] = true; |
|
175 | + |
|
176 | + // required |
|
177 | + if(!empty($arg['element_require'])) { |
|
178 | + $arg['required'] = $this->sd_convert_required($arg['element_require']); |
|
179 | + unset($arg['element_require']); |
|
180 | + } |
|
181 | + |
|
182 | + // icons |
|
183 | + if ('icon' === $key) { |
|
184 | + $arg['type'] = 'icon'; |
|
185 | + } |
|
186 | + |
|
187 | + $bricks_args[$key] = $arg; |
|
188 | + |
|
189 | + } |
|
190 | + |
|
191 | + } |
|
192 | + |
|
193 | + return $bricks_args; |
|
194 | + |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Convert the SD element_required to the Bricks required syntax. |
|
199 | + * |
|
200 | + * @param $element_require |
|
201 | + * @return array |
|
202 | + */ |
|
203 | + public function sd_convert_required($element_require) { |
|
204 | + $bricks_required = []; |
|
205 | + |
|
206 | + // Handle logical OR (||) for multiple values |
|
207 | + if (strpos($element_require, '||') !== false) { |
|
208 | + preg_match('/\[%(.+?)%\] *== *"(.*?)"/', $element_require, $matches); |
|
209 | + if ($matches) { |
|
210 | + $control_id = $matches[1]; |
|
211 | + preg_match_all('/\[%.*?%\] *== *"(.*?)"/', $element_require, $value_matches); |
|
212 | + $values = $value_matches[1]; |
|
213 | + $bricks_required[] = [$control_id, '=', $values]; |
|
214 | + } |
|
215 | + return $bricks_required; |
|
216 | + } |
|
217 | + |
|
218 | + // Match individual conditions |
|
219 | + preg_match_all('/(!)?\[%(.*?)%\](?:\s*([!=<>]=?)\s*(".*?"|\'.*?\'|\d+))?/', $element_require, $matches, PREG_SET_ORDER); |
|
220 | + |
|
221 | + foreach ($matches as $match) { |
|
222 | + $is_negation = isset($match[1]) && $match[1] === '!'; |
|
223 | + $control_id = $match[2]; |
|
224 | + $operator = isset($match[3]) ? str_replace('==', '=', $match[3]) : ($is_negation ? '=' : '!='); |
|
225 | + $value = isset($match[4]) ? trim($match[4], '"\'') : ($is_negation ? '' : ''); |
|
226 | + |
|
227 | + // Adjust for negation without explicit operator |
|
228 | + if ($is_negation && !isset($match[3])) { |
|
229 | + $operator = '='; |
|
230 | + $value = ''; |
|
231 | + } |
|
232 | + |
|
233 | + $bricks_required[] = [$control_id, $operator, $value]; |
|
234 | + } |
|
235 | + |
|
236 | + return $bricks_required; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * A way to remove some settings by keys. |
|
242 | + * |
|
243 | + * @return array |
|
244 | + */ |
|
245 | + public function sd_remove_arguments() |
|
246 | + { |
|
247 | + return array(); |
|
248 | + } |
|
249 | 249 | |
250 | 250 | } |
251 | 251 | |
@@ -255,12 +255,12 @@ discard block |
||
255 | 255 | */ |
256 | 256 | add_action( 'wp_enqueue_scripts', function() { |
257 | 257 | |
258 | - // Check if we're in the Bricks Editor |
|
259 | - if ( isset( $_GET['bricks'] ) && $_GET['bricks'] && bricks_is_builder_main() ) { |
|
260 | - // Add inline script to the 'bricks-builder' script |
|
261 | - wp_add_inline_script( |
|
262 | - 'bricks-builder', |
|
263 | - " |
|
258 | + // Check if we're in the Bricks Editor |
|
259 | + if ( isset( $_GET['bricks'] ) && $_GET['bricks'] && bricks_is_builder_main() ) { |
|
260 | + // Add inline script to the 'bricks-builder' script |
|
261 | + wp_add_inline_script( |
|
262 | + 'bricks-builder', |
|
263 | + " |
|
264 | 264 | |
265 | 265 | (function () { |
266 | 266 | // Function to get the current breakpoint from the #bricks-preview class |
@@ -467,6 +467,6 @@ discard block |
||
467 | 467 | addIconsToLabels(); |
468 | 468 | })(); |
469 | 469 | " |
470 | - ); |
|
471 | - } |
|
470 | + ); |
|
471 | + } |
|
472 | 472 | }); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | add_action( 'init', array( $this, 'register_erasers_exporters' ) ); |
30 | 30 | } |
31 | 31 | |
32 | - /** |
|
32 | + /** |
|
33 | 33 | * Initial registration of privacy erasers and exporters. |
34 | 34 | * |
35 | 35 | * Due to the use of translation functions, this should run only after plugins loaded. |
@@ -49,25 +49,25 @@ discard block |
||
49 | 49 | public function get_privacy_message() { |
50 | 50 | |
51 | 51 | $content = '<div class="wp-suggested-text">' . |
52 | - '<h2>' . __( 'Invoices and checkout', 'invoicing' ) . '</h2>' . |
|
53 | - '<p class="privacy-policy-tutorial">' . __( 'Example privacy texts.', 'invoicing' ) . '</p>' . |
|
54 | - '<p>' . __( 'We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing' ) . '</p>' . |
|
55 | - '<p>' . __( 'Handling this data also allows us to:', 'invoicing' ) . '</p>' . |
|
56 | - '<ul>' . |
|
57 | - '<li>' . __( '- Send you important account/invoice/service information.', 'invoicing' ) . '</li>' . |
|
58 | - '<li>' . __( '- Estimate taxes based on your location.', 'invoicing' ) . '</li>' . |
|
59 | - '<li>' . __( '- Respond to your queries or complaints.', 'invoicing' ) . '</li>' . |
|
60 | - '<li>' . __( '- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
61 | - '<li>' . __( '- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing' ) . '</li>' . |
|
62 | - '<li>' . __( '- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
63 | - '</ul>' . |
|
64 | - '<p>' . __( 'In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing' ) . '</p>' . |
|
65 | - '<h2>' . __( 'What we share with others', 'invoicing' ) . '</h2>' . |
|
66 | - '<p>' . __( 'We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing' ) . '</p>' . |
|
67 | - '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing' ) . '</p>' . |
|
68 | - '<p>' . __( 'We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing' ) . '</p>' . |
|
69 | - '<p>' . __( 'Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing' ) . '</p>' . |
|
70 | - '</div>'; |
|
52 | + '<h2>' . __( 'Invoices and checkout', 'invoicing' ) . '</h2>' . |
|
53 | + '<p class="privacy-policy-tutorial">' . __( 'Example privacy texts.', 'invoicing' ) . '</p>' . |
|
54 | + '<p>' . __( 'We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing' ) . '</p>' . |
|
55 | + '<p>' . __( 'Handling this data also allows us to:', 'invoicing' ) . '</p>' . |
|
56 | + '<ul>' . |
|
57 | + '<li>' . __( '- Send you important account/invoice/service information.', 'invoicing' ) . '</li>' . |
|
58 | + '<li>' . __( '- Estimate taxes based on your location.', 'invoicing' ) . '</li>' . |
|
59 | + '<li>' . __( '- Respond to your queries or complaints.', 'invoicing' ) . '</li>' . |
|
60 | + '<li>' . __( '- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
61 | + '<li>' . __( '- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing' ) . '</li>' . |
|
62 | + '<li>' . __( '- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
63 | + '</ul>' . |
|
64 | + '<p>' . __( 'In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing' ) . '</p>' . |
|
65 | + '<h2>' . __( 'What we share with others', 'invoicing' ) . '</h2>' . |
|
66 | + '<p>' . __( 'We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing' ) . '</p>' . |
|
67 | + '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing' ) . '</p>' . |
|
68 | + '<p>' . __( 'We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing' ) . '</p>' . |
|
69 | + '<p>' . __( 'Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing' ) . '</p>' . |
|
70 | + '</div>'; |
|
71 | 71 | |
72 | 72 | return apply_filters( 'wpinv_privacy_policy_content', $content ); |
73 | 73 | } |
@@ -12,492 +12,492 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - add_action( 'init', array( $this, 'init_hooks' ) ); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Registers email hooks. |
|
49 | - */ |
|
50 | - public function init_hooks() { |
|
51 | - |
|
52 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
53 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
54 | - |
|
55 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
56 | - $this->init_email_type_hook( $hook, $email_type ); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Registers an email hook for an invoice action. |
|
62 | - * |
|
63 | - * @param string $hook |
|
64 | - * @param string|array $email_type |
|
65 | - */ |
|
66 | - public function init_email_type_hook( $hook, $email_type ) { |
|
67 | - |
|
68 | - $email_type = wpinv_parse_list( $email_type ); |
|
69 | - |
|
70 | - foreach ( $email_type as $type ) { |
|
71 | - |
|
72 | - $email = new GetPaid_Notification_Email( $type ); |
|
73 | - |
|
74 | - // Abort if it is not active. |
|
75 | - if ( ! $email->is_active() ) { |
|
76 | - continue; |
|
77 | - } |
|
78 | - |
|
79 | - if ( method_exists( $this, $type ) ) { |
|
80 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
81 | - continue; |
|
82 | - } |
|
83 | - |
|
84 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | - } |
|
86 | - |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Filters invoice merge tags. |
|
91 | - * |
|
92 | - * @param array $merge_tags |
|
93 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
94 | - */ |
|
95 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | - |
|
97 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | - return array_merge( |
|
99 | - $merge_tags, |
|
100 | - $this->get_invoice_merge_tags( $object ) |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | - return array_merge( |
|
106 | - $merge_tags, |
|
107 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - return $merge_tags; |
|
112 | - |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Generates invoice merge tags. |
|
117 | - * |
|
118 | - * @param WPInv_Invoice $invoice |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - public function get_invoice_merge_tags( $invoice ) { |
|
122 | - |
|
123 | - // Abort if it does not exist. |
|
124 | - if ( ! $invoice->get_id() ) { |
|
125 | - return array(); |
|
126 | - } |
|
127 | - |
|
128 | - $due_date = $invoice->get_due_date(); |
|
129 | - $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
130 | - $merge_tags = array( |
|
131 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
134 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
135 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
136 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
137 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
138 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
139 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
140 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
141 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
142 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
143 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
144 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
145 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
146 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
147 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
148 | - '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
149 | - ); |
|
150 | - |
|
151 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
152 | - |
|
153 | - if ( is_array( $payment_form_data ) ) { |
|
154 | - |
|
155 | - foreach ( $payment_form_data as $label => $value ) { |
|
156 | - |
|
157 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
158 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
159 | - |
|
160 | - if ( is_scalar( $value ) ) { |
|
161 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
162 | - } |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Helper function to send an email. |
|
171 | - * |
|
172 | - * @param WPInv_Invoice $invoice |
|
173 | - * @param GetPaid_Notification_Email $email |
|
174 | - * @param string $type |
|
175 | - * @param string|array $recipients |
|
176 | - * @param array $extra_args Extra template args. |
|
177 | - */ |
|
178 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
179 | - |
|
180 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
181 | - |
|
182 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
183 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
184 | - return; |
|
185 | - } |
|
186 | - |
|
187 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
188 | - $merge_tags = $email->get_merge_tags(); |
|
189 | - |
|
190 | - $result = $mailer->send( |
|
191 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
192 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
193 | - $email->get_content( $merge_tags, $extra_args ), |
|
194 | - $email->get_attachments() |
|
195 | - ); |
|
196 | - |
|
197 | - // Maybe send a copy to the admin. |
|
198 | - if ( $email->include_admin_bcc() ) { |
|
199 | - $mailer->send( |
|
200 | - wpinv_get_admin_email(), |
|
201 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
202 | - $email->get_content( $merge_tags ), |
|
203 | - $email->get_attachments() |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - if ( $result ) { |
|
208 | - $invoice->add_system_note( |
|
209 | - sprintf( |
|
210 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
211 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
212 | - sanitize_key( $type ), |
|
213 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
214 | - ) |
|
215 | - ); |
|
216 | - } else { |
|
217 | - $invoice->add_system_note( |
|
218 | - sprintf( |
|
219 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
220 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
221 | - sanitize_key( $type ), |
|
222 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
228 | - |
|
229 | - return $result; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Also send emails to any cc users. |
|
234 | - * |
|
235 | - * @param array $recipients |
|
236 | - * @param GetPaid_Notification_Email $email |
|
237 | - */ |
|
238 | - public function filter_email_recipients( $recipients, $email ) { |
|
239 | - |
|
240 | - if ( ! $email->is_admin_email() ) { |
|
241 | - $cc = $email->object->get_email_cc(); |
|
242 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
243 | - |
|
244 | - if ( ! empty( $cc ) ) { |
|
245 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
246 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
247 | - } |
|
248 | - |
|
249 | - if ( ! empty( $cc_2 ) ) { |
|
250 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
251 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - return $recipients; |
|
256 | - |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Sends a new invoice notification. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice |
|
263 | - */ |
|
264 | - public function new_invoice( $invoice ) { |
|
265 | - |
|
266 | - // Only send this email for invoices created via the admin page. |
|
267 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | - return; |
|
269 | - } |
|
270 | - |
|
271 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | - $recipient = wpinv_get_admin_email(); |
|
273 | - |
|
274 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | - |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Sends a cancelled invoice notification. |
|
280 | - * |
|
281 | - * @param WPInv_Invoice $invoice |
|
282 | - */ |
|
283 | - public function cancelled_invoice( $invoice ) { |
|
284 | - |
|
285 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | - $recipient = $invoice->get_email(); |
|
287 | - |
|
288 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Sends a failed invoice notification. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice |
|
295 | - */ |
|
296 | - public function failed_invoice( $invoice ) { |
|
297 | - |
|
298 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
299 | - $recipient = wpinv_get_admin_email(); |
|
300 | - |
|
301 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
302 | - |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Sends a notification whenever an invoice is put on hold. |
|
307 | - * |
|
308 | - * @param WPInv_Invoice $invoice |
|
309 | - */ |
|
310 | - public function onhold_invoice( $invoice ) { |
|
311 | - |
|
312 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
313 | - $recipient = $invoice->get_email(); |
|
314 | - |
|
315 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | - |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
321 | - * |
|
322 | - * @param WPInv_Invoice $invoice |
|
323 | - */ |
|
324 | - public function processing_invoice( $invoice ) { |
|
325 | - |
|
326 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
327 | - $recipient = $invoice->get_email(); |
|
328 | - |
|
329 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
330 | - |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Sends a notification whenever an invoice is paid. |
|
335 | - * |
|
336 | - * @param WPInv_Invoice $invoice |
|
337 | - */ |
|
338 | - public function completed_invoice( $invoice ) { |
|
339 | - |
|
340 | - // (Maybe) abort if it is a renewal invoice. |
|
341 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
342 | - return; |
|
343 | - } |
|
344 | - |
|
345 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
346 | - $recipient = $invoice->get_email(); |
|
347 | - |
|
348 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | - |
|
350 | - } |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + add_action( 'init', array( $this, 'init_hooks' ) ); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Registers email hooks. |
|
49 | + */ |
|
50 | + public function init_hooks() { |
|
51 | + |
|
52 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
53 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
54 | + |
|
55 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
56 | + $this->init_email_type_hook( $hook, $email_type ); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Registers an email hook for an invoice action. |
|
62 | + * |
|
63 | + * @param string $hook |
|
64 | + * @param string|array $email_type |
|
65 | + */ |
|
66 | + public function init_email_type_hook( $hook, $email_type ) { |
|
67 | + |
|
68 | + $email_type = wpinv_parse_list( $email_type ); |
|
69 | + |
|
70 | + foreach ( $email_type as $type ) { |
|
71 | + |
|
72 | + $email = new GetPaid_Notification_Email( $type ); |
|
73 | + |
|
74 | + // Abort if it is not active. |
|
75 | + if ( ! $email->is_active() ) { |
|
76 | + continue; |
|
77 | + } |
|
78 | + |
|
79 | + if ( method_exists( $this, $type ) ) { |
|
80 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
81 | + continue; |
|
82 | + } |
|
83 | + |
|
84 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | + } |
|
86 | + |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Filters invoice merge tags. |
|
91 | + * |
|
92 | + * @param array $merge_tags |
|
93 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
94 | + */ |
|
95 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | + |
|
97 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | + return array_merge( |
|
99 | + $merge_tags, |
|
100 | + $this->get_invoice_merge_tags( $object ) |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | + return array_merge( |
|
106 | + $merge_tags, |
|
107 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + return $merge_tags; |
|
112 | + |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Generates invoice merge tags. |
|
117 | + * |
|
118 | + * @param WPInv_Invoice $invoice |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + public function get_invoice_merge_tags( $invoice ) { |
|
122 | + |
|
123 | + // Abort if it does not exist. |
|
124 | + if ( ! $invoice->get_id() ) { |
|
125 | + return array(); |
|
126 | + } |
|
127 | + |
|
128 | + $due_date = $invoice->get_due_date(); |
|
129 | + $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
130 | + $merge_tags = array( |
|
131 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
134 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
135 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
136 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
137 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
138 | + '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
139 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
140 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
141 | + '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
142 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
143 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
144 | + '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
145 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
146 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
147 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
148 | + '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
149 | + ); |
|
150 | + |
|
151 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
152 | + |
|
153 | + if ( is_array( $payment_form_data ) ) { |
|
154 | + |
|
155 | + foreach ( $payment_form_data as $label => $value ) { |
|
156 | + |
|
157 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
158 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
159 | + |
|
160 | + if ( is_scalar( $value ) ) { |
|
161 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
162 | + } |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
167 | + } |
|
351 | 168 | |
352 | - /** |
|
353 | - * Sends a notification whenever an invoice is refunded. |
|
354 | - * |
|
355 | - * @param WPInv_Invoice $invoice |
|
356 | - */ |
|
357 | - public function refunded_invoice( $invoice ) { |
|
358 | - |
|
359 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
360 | - $recipient = $invoice->get_email(); |
|
361 | - |
|
362 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | - |
|
364 | - } |
|
169 | + /** |
|
170 | + * Helper function to send an email. |
|
171 | + * |
|
172 | + * @param WPInv_Invoice $invoice |
|
173 | + * @param GetPaid_Notification_Email $email |
|
174 | + * @param string $type |
|
175 | + * @param string|array $recipients |
|
176 | + * @param array $extra_args Extra template args. |
|
177 | + */ |
|
178 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
365 | 179 | |
366 | - /** |
|
367 | - * Notifies a user about new invoices |
|
368 | - * |
|
369 | - * @param WPInv_Invoice $invoice |
|
370 | - * @param bool $force |
|
371 | - */ |
|
372 | - public function user_invoice( $invoice, $force = false ) { |
|
180 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
373 | 181 | |
374 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
375 | - return; |
|
376 | - } |
|
377 | - |
|
378 | - // Only send this email for invoices created via the admin page. |
|
379 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
380 | - return; |
|
381 | - } |
|
382 | - |
|
383 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
384 | - $recipient = $invoice->get_email(); |
|
385 | - |
|
386 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | - |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Checks if an invoice is a payment form invoice. |
|
392 | - * |
|
393 | - * @param int $invoice |
|
394 | - * @return bool |
|
395 | - */ |
|
396 | - public function is_payment_form_invoice( $invoice ) { |
|
397 | - $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
398 | - $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
399 | - $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
400 | - return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Notifies admin about new invoice notes |
|
405 | - * |
|
406 | - * @param WPInv_Invoice $invoice |
|
407 | - * @param string $note |
|
408 | - */ |
|
409 | - public function user_note( $invoice, $note ) { |
|
410 | - |
|
411 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
412 | - $recipient = $invoice->get_email(); |
|
413 | - |
|
414 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
415 | - |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * (Force) Sends overdue notices. |
|
420 | - * |
|
421 | - * @param WPInv_Invoice $invoice |
|
422 | - */ |
|
423 | - public function force_send_overdue_notice( $invoice ) { |
|
424 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
425 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Sends overdue notices. |
|
430 | - * |
|
431 | - * @TODO: Create an invoices query class. |
|
432 | - */ |
|
433 | - public function overdue() { |
|
434 | - global $wpdb; |
|
435 | - |
|
436 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
437 | - |
|
438 | - // Fetch reminder days. |
|
439 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
440 | - |
|
441 | - // Abort if non is set. |
|
442 | - if ( empty( $reminder_days ) ) { |
|
443 | - return; |
|
444 | - } |
|
445 | - |
|
446 | - // Retrieve date query. |
|
447 | - $date_query = $this->get_date_query( $reminder_days ); |
|
448 | - |
|
449 | - // Invoices table. |
|
450 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
451 | - |
|
452 | - // Fetch invoices. |
|
453 | - $invoices = $wpdb->get_col( |
|
454 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
182 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
183 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
184 | + return; |
|
185 | + } |
|
186 | + |
|
187 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
188 | + $merge_tags = $email->get_merge_tags(); |
|
189 | + |
|
190 | + $result = $mailer->send( |
|
191 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
192 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
193 | + $email->get_content( $merge_tags, $extra_args ), |
|
194 | + $email->get_attachments() |
|
195 | + ); |
|
196 | + |
|
197 | + // Maybe send a copy to the admin. |
|
198 | + if ( $email->include_admin_bcc() ) { |
|
199 | + $mailer->send( |
|
200 | + wpinv_get_admin_email(), |
|
201 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
202 | + $email->get_content( $merge_tags ), |
|
203 | + $email->get_attachments() |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + if ( $result ) { |
|
208 | + $invoice->add_system_note( |
|
209 | + sprintf( |
|
210 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
211 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
212 | + sanitize_key( $type ), |
|
213 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
214 | + ) |
|
215 | + ); |
|
216 | + } else { |
|
217 | + $invoice->add_system_note( |
|
218 | + sprintf( |
|
219 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
220 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
221 | + sanitize_key( $type ), |
|
222 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
228 | + |
|
229 | + return $result; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Also send emails to any cc users. |
|
234 | + * |
|
235 | + * @param array $recipients |
|
236 | + * @param GetPaid_Notification_Email $email |
|
237 | + */ |
|
238 | + public function filter_email_recipients( $recipients, $email ) { |
|
239 | + |
|
240 | + if ( ! $email->is_admin_email() ) { |
|
241 | + $cc = $email->object->get_email_cc(); |
|
242 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
243 | + |
|
244 | + if ( ! empty( $cc ) ) { |
|
245 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
246 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
247 | + } |
|
248 | + |
|
249 | + if ( ! empty( $cc_2 ) ) { |
|
250 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
251 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + return $recipients; |
|
256 | + |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Sends a new invoice notification. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice |
|
263 | + */ |
|
264 | + public function new_invoice( $invoice ) { |
|
265 | + |
|
266 | + // Only send this email for invoices created via the admin page. |
|
267 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | + return; |
|
269 | + } |
|
270 | + |
|
271 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | + $recipient = wpinv_get_admin_email(); |
|
273 | + |
|
274 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | + |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Sends a cancelled invoice notification. |
|
280 | + * |
|
281 | + * @param WPInv_Invoice $invoice |
|
282 | + */ |
|
283 | + public function cancelled_invoice( $invoice ) { |
|
284 | + |
|
285 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | + $recipient = $invoice->get_email(); |
|
287 | + |
|
288 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Sends a failed invoice notification. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice |
|
295 | + */ |
|
296 | + public function failed_invoice( $invoice ) { |
|
297 | + |
|
298 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
299 | + $recipient = wpinv_get_admin_email(); |
|
300 | + |
|
301 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
302 | + |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Sends a notification whenever an invoice is put on hold. |
|
307 | + * |
|
308 | + * @param WPInv_Invoice $invoice |
|
309 | + */ |
|
310 | + public function onhold_invoice( $invoice ) { |
|
311 | + |
|
312 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
313 | + $recipient = $invoice->get_email(); |
|
314 | + |
|
315 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | + |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
321 | + * |
|
322 | + * @param WPInv_Invoice $invoice |
|
323 | + */ |
|
324 | + public function processing_invoice( $invoice ) { |
|
325 | + |
|
326 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
327 | + $recipient = $invoice->get_email(); |
|
328 | + |
|
329 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
330 | + |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Sends a notification whenever an invoice is paid. |
|
335 | + * |
|
336 | + * @param WPInv_Invoice $invoice |
|
337 | + */ |
|
338 | + public function completed_invoice( $invoice ) { |
|
339 | + |
|
340 | + // (Maybe) abort if it is a renewal invoice. |
|
341 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
342 | + return; |
|
343 | + } |
|
344 | + |
|
345 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
346 | + $recipient = $invoice->get_email(); |
|
347 | + |
|
348 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | + |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Sends a notification whenever an invoice is refunded. |
|
354 | + * |
|
355 | + * @param WPInv_Invoice $invoice |
|
356 | + */ |
|
357 | + public function refunded_invoice( $invoice ) { |
|
358 | + |
|
359 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
360 | + $recipient = $invoice->get_email(); |
|
361 | + |
|
362 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | + |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Notifies a user about new invoices |
|
368 | + * |
|
369 | + * @param WPInv_Invoice $invoice |
|
370 | + * @param bool $force |
|
371 | + */ |
|
372 | + public function user_invoice( $invoice, $force = false ) { |
|
373 | + |
|
374 | + if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
375 | + return; |
|
376 | + } |
|
377 | + |
|
378 | + // Only send this email for invoices created via the admin page. |
|
379 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
380 | + return; |
|
381 | + } |
|
382 | + |
|
383 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
384 | + $recipient = $invoice->get_email(); |
|
385 | + |
|
386 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | + |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Checks if an invoice is a payment form invoice. |
|
392 | + * |
|
393 | + * @param int $invoice |
|
394 | + * @return bool |
|
395 | + */ |
|
396 | + public function is_payment_form_invoice( $invoice ) { |
|
397 | + $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
398 | + $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
399 | + $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
400 | + return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Notifies admin about new invoice notes |
|
405 | + * |
|
406 | + * @param WPInv_Invoice $invoice |
|
407 | + * @param string $note |
|
408 | + */ |
|
409 | + public function user_note( $invoice, $note ) { |
|
410 | + |
|
411 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
412 | + $recipient = $invoice->get_email(); |
|
413 | + |
|
414 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
415 | + |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * (Force) Sends overdue notices. |
|
420 | + * |
|
421 | + * @param WPInv_Invoice $invoice |
|
422 | + */ |
|
423 | + public function force_send_overdue_notice( $invoice ) { |
|
424 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
425 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Sends overdue notices. |
|
430 | + * |
|
431 | + * @TODO: Create an invoices query class. |
|
432 | + */ |
|
433 | + public function overdue() { |
|
434 | + global $wpdb; |
|
435 | + |
|
436 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
437 | + |
|
438 | + // Fetch reminder days. |
|
439 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
440 | + |
|
441 | + // Abort if non is set. |
|
442 | + if ( empty( $reminder_days ) ) { |
|
443 | + return; |
|
444 | + } |
|
445 | + |
|
446 | + // Retrieve date query. |
|
447 | + $date_query = $this->get_date_query( $reminder_days ); |
|
448 | + |
|
449 | + // Invoices table. |
|
450 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
451 | + |
|
452 | + // Fetch invoices. |
|
453 | + $invoices = $wpdb->get_col( |
|
454 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
455 | 455 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
456 | 456 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
457 | 457 | ); |
458 | 458 | |
459 | - foreach ( $invoices as $invoice ) { |
|
459 | + foreach ( $invoices as $invoice ) { |
|
460 | 460 | |
461 | - // Only send this email for invoices created via the admin page. |
|
462 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
463 | - $invoice = new WPInv_Invoice( $invoice ); |
|
464 | - $email->object = $invoice; |
|
461 | + // Only send this email for invoices created via the admin page. |
|
462 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
463 | + $invoice = new WPInv_Invoice( $invoice ); |
|
464 | + $email->object = $invoice; |
|
465 | 465 | |
466 | - if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
467 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
468 | - } |
|
469 | - } |
|
470 | - } |
|
466 | + if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
467 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
468 | + } |
|
469 | + } |
|
470 | + } |
|
471 | 471 | |
472 | - } |
|
472 | + } |
|
473 | 473 | |
474 | - /** |
|
475 | - * Calculates the date query for an invoices query |
|
476 | - * |
|
477 | - * @param array $reminder_days |
|
478 | - * @return string |
|
479 | - */ |
|
480 | - public function get_date_query( $reminder_days ) { |
|
474 | + /** |
|
475 | + * Calculates the date query for an invoices query |
|
476 | + * |
|
477 | + * @param array $reminder_days |
|
478 | + * @return string |
|
479 | + */ |
|
480 | + public function get_date_query( $reminder_days ) { |
|
481 | 481 | |
482 | - $date_query = array( |
|
483 | - 'relation' => 'OR', |
|
484 | - ); |
|
482 | + $date_query = array( |
|
483 | + 'relation' => 'OR', |
|
484 | + ); |
|
485 | 485 | |
486 | - foreach ( $reminder_days as $days ) { |
|
487 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
486 | + foreach ( $reminder_days as $days ) { |
|
487 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
488 | 488 | |
489 | - $date_query[] = array( |
|
490 | - 'year' => $date['year'], |
|
491 | - 'month' => $date['month'], |
|
492 | - 'day' => $date['day'], |
|
493 | - ); |
|
489 | + $date_query[] = array( |
|
490 | + 'year' => $date['year'], |
|
491 | + 'month' => $date['month'], |
|
492 | + 'day' => $date['day'], |
|
493 | + ); |
|
494 | 494 | |
495 | - } |
|
495 | + } |
|
496 | 496 | |
497 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
497 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
498 | 498 | |
499 | - return $date_query->get_sql(); |
|
499 | + return $date_query->get_sql(); |
|
500 | 500 | |
501 | - } |
|
501 | + } |
|
502 | 502 | |
503 | 503 | } |