@@ -14,91 +14,91 @@ 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_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
67 | - 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_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
68 | 68 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
76 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
77 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
78 | - |
|
79 | - // Setup/welcome |
|
80 | - if ( ! empty( $_GET['page'] ) ) { |
|
81 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
82 | - case 'gp-setup': |
|
83 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
84 | - break; |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Register admin scripts |
|
92 | - * |
|
93 | - */ |
|
94 | - public function enqeue_scripts() { |
|
69 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
70 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
71 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
75 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
76 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
77 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
78 | + |
|
79 | + // Setup/welcome |
|
80 | + if ( ! empty( $_GET['page'] ) ) { |
|
81 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
82 | + case 'gp-setup': |
|
83 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
84 | + break; |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Register admin scripts |
|
92 | + * |
|
93 | + */ |
|
94 | + public function enqeue_scripts() { |
|
95 | 95 | global $current_screen, $pagenow; |
96 | 96 | |
97 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
98 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
97 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
98 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
99 | 99 | |
100 | 100 | if ( ! empty( $current_screen->post_type ) ) { |
101 | - $page = $current_screen->post_type; |
|
101 | + $page = $current_screen->post_type; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // General styles. |
@@ -119,53 +119,53 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | // Payment form scripts. |
122 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
122 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
123 | 123 | $this->load_payment_form_scripts(); |
124 | 124 | } |
125 | 125 | |
126 | - if ( $page == 'wpinv-subscriptions' ) { |
|
127 | - wp_enqueue_script( 'postbox' ); |
|
128 | - } |
|
126 | + if ( $page == 'wpinv-subscriptions' ) { |
|
127 | + wp_enqueue_script( 'postbox' ); |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * Returns admin js translations. |
|
134 | - * |
|
135 | - */ |
|
136 | - protected function get_admin_i18() { |
|
133 | + * Returns admin js translations. |
|
134 | + * |
|
135 | + */ |
|
136 | + protected function get_admin_i18() { |
|
137 | 137 | global $post; |
138 | 138 | |
139 | - $date_range = array( |
|
140 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
141 | - ); |
|
139 | + $date_range = array( |
|
140 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
141 | + ); |
|
142 | 142 | |
143 | - if ( $date_range['period'] == 'custom' ) { |
|
143 | + if ( $date_range['period'] == 'custom' ) { |
|
144 | 144 | |
145 | - if ( isset( $_GET['from'] ) ) { |
|
146 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
147 | - } |
|
145 | + if ( isset( $_GET['from'] ) ) { |
|
146 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
147 | + } |
|
148 | 148 | |
149 | - if ( isset( $_GET['to'] ) ) { |
|
150 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
151 | - } |
|
149 | + if ( isset( $_GET['to'] ) ) { |
|
150 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
151 | + } |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | $i18n = array( |
155 | 155 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
156 | 156 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
157 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
158 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
159 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
160 | - 'date_range' => $date_range, |
|
157 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
158 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
159 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
160 | + 'date_range' => $date_range, |
|
161 | 161 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
162 | 162 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
163 | 163 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
164 | 164 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
165 | 165 | 'tax' => wpinv_tax_amount(), |
166 | 166 | 'discount' => 0, |
167 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
168 | - 'currency' => wpinv_get_currency(), |
|
167 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
168 | + 'currency' => wpinv_get_currency(), |
|
169 | 169 | 'currency_pos' => wpinv_currency_position(), |
170 | 170 | 'thousand_sep' => wpinv_thousands_separator(), |
171 | 171 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -185,118 +185,118 @@ discard block |
||
185 | 185 | 'item_description' => __( 'Item Description', 'invoicing' ), |
186 | 186 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
187 | 187 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
188 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
189 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
190 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
191 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
192 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
188 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
189 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
190 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
191 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
192 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
193 | 193 | ); |
194 | 194 | |
195 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
195 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
196 | 196 | |
197 | - $invoice = new WPInv_Invoice( $post ); |
|
198 | - $i18n['save_invoice'] = sprintf( |
|
199 | - __( 'Save %s', 'invoicing' ), |
|
200 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
201 | - ); |
|
197 | + $invoice = new WPInv_Invoice( $post ); |
|
198 | + $i18n['save_invoice'] = sprintf( |
|
199 | + __( 'Save %s', 'invoicing' ), |
|
200 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
201 | + ); |
|
202 | 202 | |
203 | - $i18n['invoice_description'] = sprintf( |
|
204 | - __( '%s Description', 'invoicing' ), |
|
205 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
206 | - ); |
|
203 | + $i18n['invoice_description'] = sprintf( |
|
204 | + __( '%s Description', 'invoicing' ), |
|
205 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
206 | + ); |
|
207 | 207 | |
208 | - } |
|
209 | - return $i18n; |
|
210 | - } |
|
208 | + } |
|
209 | + return $i18n; |
|
210 | + } |
|
211 | 211 | |
212 | - /** |
|
213 | - * Change the admin footer text on GetPaid admin pages. |
|
214 | - * |
|
215 | - * @since 2.0.0 |
|
216 | - * @param string $footer_text |
|
217 | - * @return string |
|
218 | - */ |
|
219 | - public function admin_footer_text( $footer_text ) { |
|
220 | - global $current_screen; |
|
212 | + /** |
|
213 | + * Change the admin footer text on GetPaid admin pages. |
|
214 | + * |
|
215 | + * @since 2.0.0 |
|
216 | + * @param string $footer_text |
|
217 | + * @return string |
|
218 | + */ |
|
219 | + public function admin_footer_text( $footer_text ) { |
|
220 | + global $current_screen; |
|
221 | 221 | |
222 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
222 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
223 | 223 | |
224 | 224 | if ( ! empty( $current_screen->post_type ) ) { |
225 | - $page = $current_screen->post_type; |
|
225 | + $page = $current_screen->post_type; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // General styles. |
229 | 229 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
230 | 230 | |
231 | - // Change the footer text |
|
232 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
231 | + // Change the footer text |
|
232 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
233 | 233 | |
234 | - $rating_url = esc_url( |
|
235 | - wp_nonce_url( |
|
236 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
237 | - 'getpaid-nonce', |
|
238 | - 'getpaid-nonce' |
|
234 | + $rating_url = esc_url( |
|
235 | + wp_nonce_url( |
|
236 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
237 | + 'getpaid-nonce', |
|
238 | + 'getpaid-nonce' |
|
239 | 239 | ) |
240 | - ); |
|
240 | + ); |
|
241 | 241 | |
242 | - $footer_text = sprintf( |
|
243 | - /* translators: %s: five stars */ |
|
244 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
245 | - "<a href='$rating_url'>★★★★★</a>" |
|
246 | - ); |
|
242 | + $footer_text = sprintf( |
|
243 | + /* translators: %s: five stars */ |
|
244 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
245 | + "<a href='$rating_url'>★★★★★</a>" |
|
246 | + ); |
|
247 | 247 | |
248 | - } else { |
|
248 | + } else { |
|
249 | 249 | |
250 | - $footer_text = sprintf( |
|
251 | - /* translators: %s: GetPaid */ |
|
252 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
253 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
254 | - ); |
|
250 | + $footer_text = sprintf( |
|
251 | + /* translators: %s: GetPaid */ |
|
252 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
253 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
254 | + ); |
|
255 | 255 | |
256 | - } |
|
256 | + } |
|
257 | 257 | } |
258 | 258 | |
259 | - return $footer_text; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Redirects to wp.org to rate the plugin. |
|
264 | - * |
|
265 | - * @since 2.0.0 |
|
266 | - */ |
|
267 | - public function redirect_to_wordpress_rating_page() { |
|
268 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
269 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
270 | - exit; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Loads payment form js. |
|
275 | - * |
|
276 | - */ |
|
277 | - protected function load_payment_form_scripts() { |
|
259 | + return $footer_text; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Redirects to wp.org to rate the plugin. |
|
264 | + * |
|
265 | + * @since 2.0.0 |
|
266 | + */ |
|
267 | + public function redirect_to_wordpress_rating_page() { |
|
268 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
269 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
270 | + exit; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Loads payment form js. |
|
275 | + * |
|
276 | + */ |
|
277 | + protected function load_payment_form_scripts() { |
|
278 | 278 | global $post; |
279 | 279 | |
280 | 280 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
281 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
282 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
281 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
282 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
283 | 283 | |
284 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
285 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
284 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
285 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
286 | 286 | |
287 | - wp_localize_script( |
|
287 | + wp_localize_script( |
|
288 | 288 | 'wpinv-admin-payment-form-script', |
289 | 289 | 'wpinvPaymentFormAdmin', |
290 | 290 | array( |
291 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
292 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
293 | - 'currency' => wpinv_currency_symbol(), |
|
294 | - 'position' => wpinv_currency_position(), |
|
295 | - 'decimals' => (int) wpinv_decimals(), |
|
296 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
297 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
298 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
299 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
291 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
292 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
293 | + 'currency' => wpinv_currency_symbol(), |
|
294 | + 'position' => wpinv_currency_position(), |
|
295 | + 'decimals' => (int) wpinv_decimals(), |
|
296 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
297 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
298 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
299 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
300 | 300 | ) |
301 | 301 | ); |
302 | 302 | |
@@ -305,19 +305,19 @@ discard block |
||
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | - * Add our classes to admin pages. |
|
308 | + * Add our classes to admin pages. |
|
309 | 309 | * |
310 | 310 | * @param string $classes |
311 | 311 | * @return string |
312 | - * |
|
313 | - */ |
|
312 | + * |
|
313 | + */ |
|
314 | 314 | public function admin_body_class( $classes ) { |
315 | - global $pagenow, $post, $current_screen; |
|
315 | + global $pagenow, $post, $current_screen; |
|
316 | 316 | |
317 | 317 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
318 | 318 | |
319 | 319 | if ( ! empty( $current_screen->post_type ) ) { |
320 | - $page = $current_screen->post_type; |
|
320 | + $page = $current_screen->post_type; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -326,70 +326,70 @@ discard block |
||
326 | 326 | |
327 | 327 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
328 | 328 | $classes .= ' wpinv-cpt wpinv'; |
329 | - } |
|
329 | + } |
|
330 | 330 | |
331 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
331 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
332 | 332 | $classes .= ' getpaid-is-invoice-cpt'; |
333 | 333 | } |
334 | 334 | |
335 | - return $classes; |
|
335 | + return $classes; |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
339 | - * Maybe show the AyeCode Connect Notice. |
|
340 | - */ |
|
341 | - public function init_ayecode_connect_helper() { |
|
339 | + * Maybe show the AyeCode Connect Notice. |
|
340 | + */ |
|
341 | + public function init_ayecode_connect_helper() { |
|
342 | 342 | |
343 | - // Register with the deactivation survey class. |
|
344 | - AyeCode_Deactivation_Survey::instance( |
|
343 | + // Register with the deactivation survey class. |
|
344 | + AyeCode_Deactivation_Survey::instance( |
|
345 | 345 | array( |
346 | - 'slug' => 'invoicing', |
|
347 | - 'version' => WPINV_VERSION, |
|
348 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
349 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
350 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
346 | + 'slug' => 'invoicing', |
|
347 | + 'version' => WPINV_VERSION, |
|
348 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
349 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
350 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
351 | 351 | ) |
352 | 352 | ); |
353 | 353 | |
354 | 354 | new AyeCode_Connect_Helper( |
355 | 355 | array( |
356 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
357 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
358 | - '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>' ), |
|
359 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
360 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
361 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
362 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
356 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
357 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
358 | + '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>' ), |
|
359 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
360 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
361 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
362 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
363 | 363 | ), |
364 | 364 | array( 'wpi-addons' ) |
365 | 365 | ); |
366 | 366 | |
367 | 367 | } |
368 | 368 | |
369 | - /** |
|
370 | - * Redirect users to settings on activation. |
|
371 | - * |
|
372 | - * @return void |
|
373 | - */ |
|
374 | - public function activation_redirect() { |
|
369 | + /** |
|
370 | + * Redirect users to settings on activation. |
|
371 | + * |
|
372 | + * @return void |
|
373 | + */ |
|
374 | + public function activation_redirect() { |
|
375 | 375 | |
376 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
376 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
377 | 377 | |
378 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
379 | - return; |
|
380 | - } |
|
378 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
379 | + return; |
|
380 | + } |
|
381 | 381 | |
382 | - // Bail if activating from network, or bulk |
|
383 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
384 | - return; |
|
385 | - } |
|
382 | + // Bail if activating from network, or bulk |
|
383 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
384 | + return; |
|
385 | + } |
|
386 | 386 | |
387 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
387 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
388 | 388 | |
389 | 389 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
390 | 390 | exit; |
391 | 391 | |
392 | - } |
|
392 | + } |
|
393 | 393 | |
394 | 394 | /** |
395 | 395 | * Fires an admin action after verifying that a user can fire them. |
@@ -403,525 +403,525 @@ discard block |
||
403 | 403 | |
404 | 404 | } |
405 | 405 | |
406 | - /** |
|
406 | + /** |
|
407 | 407 | * Duplicate invoice. |
408 | - * |
|
409 | - * @param array $args |
|
408 | + * |
|
409 | + * @param array $args |
|
410 | 410 | */ |
411 | 411 | public function duplicate_invoice( $args ) { |
412 | 412 | |
413 | - if ( empty( $args['invoice_id'] ) ) { |
|
414 | - return; |
|
415 | - } |
|
413 | + if ( empty( $args['invoice_id'] ) ) { |
|
414 | + return; |
|
415 | + } |
|
416 | 416 | |
417 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
417 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
418 | 418 | |
419 | - if ( ! $invoice->exists() ) { |
|
420 | - return; |
|
421 | - } |
|
419 | + if ( ! $invoice->exists() ) { |
|
420 | + return; |
|
421 | + } |
|
422 | 422 | |
423 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
424 | - $new_invoice->save(); |
|
423 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
424 | + $new_invoice->save(); |
|
425 | 425 | |
426 | - if ( $new_invoice->exists() ) { |
|
426 | + if ( $new_invoice->exists() ) { |
|
427 | 427 | |
428 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
428 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
429 | 429 | |
430 | - wp_safe_redirect( |
|
431 | - add_query_arg( |
|
432 | - array( |
|
433 | - 'action' => 'edit', |
|
434 | - 'post' => $new_invoice->get_id(), |
|
435 | - ), |
|
436 | - admin_url( 'post.php' ) |
|
437 | - ) |
|
438 | - ); |
|
439 | - exit; |
|
430 | + wp_safe_redirect( |
|
431 | + add_query_arg( |
|
432 | + array( |
|
433 | + 'action' => 'edit', |
|
434 | + 'post' => $new_invoice->get_id(), |
|
435 | + ), |
|
436 | + admin_url( 'post.php' ) |
|
437 | + ) |
|
438 | + ); |
|
439 | + exit; |
|
440 | 440 | |
441 | - } |
|
441 | + } |
|
442 | 442 | |
443 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
443 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | |
447 | - /** |
|
447 | + /** |
|
448 | 448 | * Sends a payment reminder to a customer. |
449 | - * |
|
450 | - * @param array $args |
|
449 | + * |
|
450 | + * @param array $args |
|
451 | 451 | */ |
452 | 452 | public function duplicate_payment_form( $args ) { |
453 | 453 | |
454 | - if ( empty( $args['form_id'] ) ) { |
|
455 | - return; |
|
456 | - } |
|
457 | - |
|
458 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
454 | + if ( empty( $args['form_id'] ) ) { |
|
455 | + return; |
|
456 | + } |
|
459 | 457 | |
460 | - if ( ! $form->exists() ) { |
|
461 | - return; |
|
462 | - } |
|
458 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
463 | 459 | |
464 | - $new_form = new GetPaid_Payment_Form(); |
|
465 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
466 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
467 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
468 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
469 | - $new_form->save(); |
|
460 | + if ( ! $form->exists() ) { |
|
461 | + return; |
|
462 | + } |
|
470 | 463 | |
471 | - if ( $new_form->exists() ) { |
|
472 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
473 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
474 | - } else { |
|
475 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
476 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
477 | - } |
|
464 | + $new_form = new GetPaid_Payment_Form(); |
|
465 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
466 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
467 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
468 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
469 | + $new_form->save(); |
|
470 | + |
|
471 | + if ( $new_form->exists() ) { |
|
472 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
473 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
474 | + } else { |
|
475 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
476 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
477 | + } |
|
478 | 478 | |
479 | - wp_redirect( $url ); |
|
480 | - exit; |
|
481 | - } |
|
479 | + wp_redirect( $url ); |
|
480 | + exit; |
|
481 | + } |
|
482 | 482 | |
483 | - /** |
|
483 | + /** |
|
484 | 484 | * Sends a payment reminder to a customer. |
485 | - * |
|
486 | - * @param array $args |
|
485 | + * |
|
486 | + * @param array $args |
|
487 | 487 | */ |
488 | 488 | public function send_customer_invoice( $args ) { |
489 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
490 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
491 | - exit; |
|
492 | - } |
|
489 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
490 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
491 | + exit; |
|
492 | + } |
|
493 | 493 | |
494 | - /** |
|
494 | + /** |
|
495 | 495 | * Sends a payment reminder to a customer. |
496 | - * |
|
497 | - * @param array $args |
|
496 | + * |
|
497 | + * @param array $args |
|
498 | 498 | */ |
499 | 499 | public function send_customer_payment_reminder( $args ) { |
500 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
500 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
501 | 501 | |
502 | - if ( $sent ) { |
|
503 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
504 | - } else { |
|
505 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
506 | - } |
|
502 | + if ( $sent ) { |
|
503 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
504 | + } else { |
|
505 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
506 | + } |
|
507 | 507 | |
508 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
509 | - exit; |
|
510 | - } |
|
508 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
509 | + exit; |
|
510 | + } |
|
511 | 511 | |
512 | - /** |
|
512 | + /** |
|
513 | 513 | * Resets tax rates. |
514 | - * |
|
514 | + * |
|
515 | 515 | */ |
516 | 516 | public function admin_reset_tax_rates() { |
517 | 517 | |
518 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
519 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
520 | - exit; |
|
518 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
519 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
520 | + exit; |
|
521 | 521 | |
522 | - } |
|
522 | + } |
|
523 | 523 | |
524 | - /** |
|
524 | + /** |
|
525 | 525 | * Resets admin pages. |
526 | - * |
|
526 | + * |
|
527 | 527 | */ |
528 | 528 | public function admin_create_missing_pages() { |
529 | - $installer = new GetPaid_Installer(); |
|
530 | - $installer->create_pages(); |
|
531 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
532 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
533 | - exit; |
|
534 | - } |
|
535 | - |
|
536 | - /** |
|
529 | + $installer = new GetPaid_Installer(); |
|
530 | + $installer->create_pages(); |
|
531 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
532 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
533 | + exit; |
|
534 | + } |
|
535 | + |
|
536 | + /** |
|
537 | 537 | * Creates an missing admin tables. |
538 | - * |
|
538 | + * |
|
539 | 539 | */ |
540 | 540 | public function admin_create_missing_tables() { |
541 | - global $wpdb; |
|
542 | - $installer = new GetPaid_Installer(); |
|
541 | + global $wpdb; |
|
542 | + $installer = new GetPaid_Installer(); |
|
543 | 543 | |
544 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
545 | - $installer->create_subscriptions_table(); |
|
544 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
545 | + $installer->create_subscriptions_table(); |
|
546 | 546 | |
547 | - if ( $wpdb->last_error !== '' ) { |
|
548 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
549 | - } |
|
550 | - } |
|
547 | + if ( $wpdb->last_error !== '' ) { |
|
548 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
549 | + } |
|
550 | + } |
|
551 | 551 | |
552 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
553 | - $installer->create_invoices_table(); |
|
552 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
553 | + $installer->create_invoices_table(); |
|
554 | 554 | |
555 | - if ( '' !== $wpdb->last_error ) { |
|
556 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
557 | - } |
|
558 | - } |
|
555 | + if ( '' !== $wpdb->last_error ) { |
|
556 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
557 | + } |
|
558 | + } |
|
559 | 559 | |
560 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
561 | - $installer->create_invoice_items_table(); |
|
560 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
561 | + $installer->create_invoice_items_table(); |
|
562 | 562 | |
563 | - if ( '' !== $wpdb->last_error ) { |
|
564 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
565 | - } |
|
566 | - } |
|
563 | + if ( '' !== $wpdb->last_error ) { |
|
564 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
565 | + } |
|
566 | + } |
|
567 | 567 | |
568 | - if ( ! $this->has_notices() ) { |
|
569 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
570 | - } |
|
568 | + if ( ! $this->has_notices() ) { |
|
569 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
570 | + } |
|
571 | 571 | |
572 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
573 | - exit; |
|
574 | - } |
|
572 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
573 | + exit; |
|
574 | + } |
|
575 | 575 | |
576 | - /** |
|
576 | + /** |
|
577 | 577 | * Migrates old invoices to the new database tables. |
578 | - * |
|
578 | + * |
|
579 | 579 | */ |
580 | 580 | public function admin_migrate_old_invoices() { |
581 | 581 | |
582 | - // Migrate the invoices. |
|
583 | - $installer = new GetPaid_Installer(); |
|
584 | - $installer->migrate_old_invoices(); |
|
582 | + // Migrate the invoices. |
|
583 | + $installer = new GetPaid_Installer(); |
|
584 | + $installer->migrate_old_invoices(); |
|
585 | 585 | |
586 | - // Show an admin message. |
|
587 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
586 | + // Show an admin message. |
|
587 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
588 | 588 | |
589 | - // Redirect the admin. |
|
590 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
591 | - exit; |
|
589 | + // Redirect the admin. |
|
590 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
591 | + exit; |
|
592 | 592 | |
593 | - } |
|
593 | + } |
|
594 | 594 | |
595 | - /** |
|
595 | + /** |
|
596 | 596 | * Download customers. |
597 | - * |
|
597 | + * |
|
598 | 598 | */ |
599 | 599 | public function admin_download_customers() { |
600 | - global $wpdb; |
|
601 | - |
|
602 | - $output = fopen( 'php://output', 'w' ); |
|
603 | - |
|
604 | - if ( false === $output ) { |
|
605 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
606 | - } |
|
600 | + global $wpdb; |
|
607 | 601 | |
608 | - header( 'Content-Type:text/csv' ); |
|
609 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
602 | + $output = fopen( 'php://output', 'w' ); |
|
610 | 603 | |
611 | - $post_types = ''; |
|
604 | + if ( false === $output ) { |
|
605 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
606 | + } |
|
612 | 607 | |
613 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
614 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
615 | - } |
|
608 | + header( 'Content-Type:text/csv' ); |
|
609 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
616 | 610 | |
617 | - $post_types = rtrim( $post_types, ' OR' ); |
|
611 | + $post_types = ''; |
|
618 | 612 | |
619 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
613 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
614 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
615 | + } |
|
620 | 616 | |
621 | - $columns = array( |
|
622 | - 'name' => __( 'Name', 'invoicing' ), |
|
623 | - 'email' => __( 'Email', 'invoicing' ), |
|
624 | - 'country' => __( 'Country', 'invoicing' ), |
|
625 | - 'state' => __( 'State', 'invoicing' ), |
|
626 | - 'city' => __( 'City', 'invoicing' ), |
|
627 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
628 | - 'address' => __( 'Address', 'invoicing' ), |
|
629 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
630 | - 'company' => __( 'Company', 'invoicing' ), |
|
631 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
632 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
633 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
634 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
635 | - ); |
|
617 | + $post_types = rtrim( $post_types, ' OR' ); |
|
618 | + |
|
619 | + $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
620 | + |
|
621 | + $columns = array( |
|
622 | + 'name' => __( 'Name', 'invoicing' ), |
|
623 | + 'email' => __( 'Email', 'invoicing' ), |
|
624 | + 'country' => __( 'Country', 'invoicing' ), |
|
625 | + 'state' => __( 'State', 'invoicing' ), |
|
626 | + 'city' => __( 'City', 'invoicing' ), |
|
627 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
628 | + 'address' => __( 'Address', 'invoicing' ), |
|
629 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
630 | + 'company' => __( 'Company', 'invoicing' ), |
|
631 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
632 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
633 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
634 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
635 | + ); |
|
636 | 636 | |
637 | - // Output the csv column headers. |
|
638 | - fputcsv( $output, array_values( $columns ) ); |
|
637 | + // Output the csv column headers. |
|
638 | + fputcsv( $output, array_values( $columns ) ); |
|
639 | 639 | |
640 | - // Loop through |
|
641 | - $table = new WPInv_Customers_Table(); |
|
642 | - foreach ( $customers as $customer_id ) { |
|
640 | + // Loop through |
|
641 | + $table = new WPInv_Customers_Table(); |
|
642 | + foreach ( $customers as $customer_id ) { |
|
643 | 643 | |
644 | - $user = get_user_by( 'id', $customer_id ); |
|
645 | - $row = array(); |
|
646 | - if ( empty( $user ) ) { |
|
647 | - continue; |
|
648 | - } |
|
644 | + $user = get_user_by( 'id', $customer_id ); |
|
645 | + $row = array(); |
|
646 | + if ( empty( $user ) ) { |
|
647 | + continue; |
|
648 | + } |
|
649 | 649 | |
650 | - foreach ( array_keys( $columns ) as $column ) { |
|
650 | + foreach ( array_keys( $columns ) as $column ) { |
|
651 | 651 | |
652 | - $method = 'column_' . $column; |
|
652 | + $method = 'column_' . $column; |
|
653 | 653 | |
654 | - if ( 'name' == $column ) { |
|
655 | - $value = esc_html( $user->display_name ); |
|
656 | - } elseif ( 'email' == $column ) { |
|
657 | - $value = sanitize_email( $user->user_email ); |
|
658 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
659 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
660 | - } |
|
654 | + if ( 'name' == $column ) { |
|
655 | + $value = esc_html( $user->display_name ); |
|
656 | + } elseif ( 'email' == $column ) { |
|
657 | + $value = sanitize_email( $user->user_email ); |
|
658 | + } elseif ( is_callable( array( $table, $method ) ) ) { |
|
659 | + $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
660 | + } |
|
661 | 661 | |
662 | - if ( empty( $value ) ) { |
|
663 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
664 | - } |
|
662 | + if ( empty( $value ) ) { |
|
663 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
664 | + } |
|
665 | 665 | |
666 | - $row[] = $value; |
|
666 | + $row[] = $value; |
|
667 | 667 | |
668 | - } |
|
668 | + } |
|
669 | 669 | |
670 | - fputcsv( $output, $row ); |
|
671 | - } |
|
670 | + fputcsv( $output, $row ); |
|
671 | + } |
|
672 | 672 | |
673 | - fclose( $output ); |
|
674 | - exit; |
|
673 | + fclose( $output ); |
|
674 | + exit; |
|
675 | 675 | |
676 | - } |
|
676 | + } |
|
677 | 677 | |
678 | - /** |
|
678 | + /** |
|
679 | 679 | * Installs a plugin. |
680 | - * |
|
681 | - * @param array $data |
|
680 | + * |
|
681 | + * @param array $data |
|
682 | 682 | */ |
683 | 683 | public function admin_install_plugin( $data ) { |
684 | 684 | |
685 | - if ( ! empty( $data['plugins'] ) ) { |
|
686 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
687 | - wp_cache_flush(); |
|
685 | + if ( ! empty( $data['plugins'] ) ) { |
|
686 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
687 | + wp_cache_flush(); |
|
688 | 688 | |
689 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
690 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
691 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
692 | - $installed = $upgrader->install( $plugin_zip ); |
|
689 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
690 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
691 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
692 | + $installed = $upgrader->install( $plugin_zip ); |
|
693 | 693 | |
694 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
695 | - activate_plugin( $file, '', false, true ); |
|
696 | - } else { |
|
697 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
698 | - } |
|
694 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
695 | + activate_plugin( $file, '', false, true ); |
|
696 | + } else { |
|
697 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
698 | + } |
|
699 | 699 | } |
700 | 700 | } |
701 | 701 | |
702 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
703 | - wp_safe_redirect( $redirect ); |
|
704 | - exit; |
|
702 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
703 | + wp_safe_redirect( $redirect ); |
|
704 | + exit; |
|
705 | 705 | |
706 | - } |
|
706 | + } |
|
707 | 707 | |
708 | - /** |
|
708 | + /** |
|
709 | 709 | * Connects a gateway. |
710 | - * |
|
711 | - * @param array $data |
|
710 | + * |
|
711 | + * @param array $data |
|
712 | 712 | */ |
713 | 713 | public function admin_connect_gateway( $data ) { |
714 | 714 | |
715 | - if ( ! empty( $data['plugin'] ) ) { |
|
715 | + if ( ! empty( $data['plugin'] ) ) { |
|
716 | 716 | |
717 | - $gateway = sanitize_key( $data['plugin'] ); |
|
718 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
717 | + $gateway = sanitize_key( $data['plugin'] ); |
|
718 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
719 | 719 | |
720 | - if ( ! empty( $connect_url ) ) { |
|
721 | - wp_redirect( $connect_url ); |
|
722 | - exit; |
|
723 | - } |
|
720 | + if ( ! empty( $connect_url ) ) { |
|
721 | + wp_redirect( $connect_url ); |
|
722 | + exit; |
|
723 | + } |
|
724 | 724 | |
725 | - if ( 'stripe' == $data['plugin'] ) { |
|
726 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
727 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
728 | - wp_cache_flush(); |
|
725 | + if ( 'stripe' == $data['plugin'] ) { |
|
726 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
727 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
728 | + wp_cache_flush(); |
|
729 | 729 | |
730 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
731 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
732 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | - $upgrader->install( $plugin_zip ); |
|
734 | - } |
|
730 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
731 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
732 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | + $upgrader->install( $plugin_zip ); |
|
734 | + } |
|
735 | 735 | |
736 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
737 | - } |
|
736 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
737 | + } |
|
738 | 738 | |
739 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
740 | - if ( ! empty( $connect_url ) ) { |
|
741 | - wp_redirect( $connect_url ); |
|
742 | - exit; |
|
743 | - } |
|
739 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
740 | + if ( ! empty( $connect_url ) ) { |
|
741 | + wp_redirect( $connect_url ); |
|
742 | + exit; |
|
743 | + } |
|
744 | 744 | } |
745 | 745 | |
746 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
747 | - wp_safe_redirect( $redirect ); |
|
748 | - exit; |
|
746 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
747 | + wp_safe_redirect( $redirect ); |
|
748 | + exit; |
|
749 | 749 | |
750 | - } |
|
750 | + } |
|
751 | 751 | |
752 | - /** |
|
752 | + /** |
|
753 | 753 | * Recalculates discounts. |
754 | - * |
|
754 | + * |
|
755 | 755 | */ |
756 | 756 | public function admin_recalculate_discounts() { |
757 | - global $wpdb; |
|
757 | + global $wpdb; |
|
758 | 758 | |
759 | - // Fetch all invoices that have discount codes. |
|
760 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
761 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
759 | + // Fetch all invoices that have discount codes. |
|
760 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
761 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
762 | 762 | |
763 | - foreach ( $invoices as $invoice ) { |
|
763 | + foreach ( $invoices as $invoice ) { |
|
764 | 764 | |
765 | - $invoice = new WPInv_Invoice( $invoice ); |
|
765 | + $invoice = new WPInv_Invoice( $invoice ); |
|
766 | 766 | |
767 | - if ( ! $invoice->exists() ) { |
|
768 | - continue; |
|
769 | - } |
|
767 | + if ( ! $invoice->exists() ) { |
|
768 | + continue; |
|
769 | + } |
|
770 | 770 | |
771 | - // Abort if the discount does not exist or does not apply here. |
|
772 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
773 | - if ( ! $discount->exists() ) { |
|
774 | - continue; |
|
775 | - } |
|
771 | + // Abort if the discount does not exist or does not apply here. |
|
772 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
773 | + if ( ! $discount->exists() ) { |
|
774 | + continue; |
|
775 | + } |
|
776 | 776 | |
777 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
778 | - $invoice->recalculate_total(); |
|
777 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
778 | + $invoice->recalculate_total(); |
|
779 | 779 | |
780 | - if ( $invoice->get_total_discount() > 0 ) { |
|
781 | - $invoice->save(); |
|
782 | - } |
|
780 | + if ( $invoice->get_total_discount() > 0 ) { |
|
781 | + $invoice->save(); |
|
782 | + } |
|
783 | 783 | } |
784 | 784 | |
785 | - // Show an admin message. |
|
786 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
785 | + // Show an admin message. |
|
786 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
787 | 787 | |
788 | - // Redirect the admin. |
|
789 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
790 | - exit; |
|
788 | + // Redirect the admin. |
|
789 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
790 | + exit; |
|
791 | 791 | |
792 | - } |
|
792 | + } |
|
793 | 793 | |
794 | 794 | /** |
795 | - * Returns an array of admin notices. |
|
796 | - * |
|
797 | - * @since 1.0.19 |
|
795 | + * Returns an array of admin notices. |
|
796 | + * |
|
797 | + * @since 1.0.19 |
|
798 | 798 | * @return array |
799 | - */ |
|
800 | - public function get_notices() { |
|
801 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
799 | + */ |
|
800 | + public function get_notices() { |
|
801 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
802 | 802 | return is_array( $notices ) ? $notices : array(); |
803 | - } |
|
803 | + } |
|
804 | 804 | |
805 | - /** |
|
806 | - * Checks if we have any admin notices. |
|
807 | - * |
|
808 | - * @since 2.0.4 |
|
805 | + /** |
|
806 | + * Checks if we have any admin notices. |
|
807 | + * |
|
808 | + * @since 2.0.4 |
|
809 | 809 | * @return array |
810 | - */ |
|
811 | - public function has_notices() { |
|
812 | - return count( $this->get_notices() ) > 0; |
|
813 | - } |
|
814 | - |
|
815 | - /** |
|
816 | - * Clears all admin notices |
|
817 | - * |
|
818 | - * @access public |
|
819 | - * @since 1.0.19 |
|
820 | - */ |
|
821 | - public function clear_notices() { |
|
822 | - delete_option( 'wpinv_admin_notices' ); |
|
823 | - } |
|
824 | - |
|
825 | - /** |
|
826 | - * Saves a new admin notice |
|
827 | - * |
|
828 | - * @access public |
|
829 | - * @since 1.0.19 |
|
830 | - */ |
|
831 | - public function save_notice( $type, $message ) { |
|
832 | - $notices = $this->get_notices(); |
|
833 | - |
|
834 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
835 | - $notices[ $type ] = array(); |
|
836 | - } |
|
837 | - |
|
838 | - $notices[ $type ][] = $message; |
|
839 | - |
|
840 | - update_option( 'wpinv_admin_notices', $notices ); |
|
841 | - } |
|
842 | - |
|
843 | - /** |
|
844 | - * Displays a success notice |
|
845 | - * |
|
846 | - * @param string $msg The message to qeue. |
|
847 | - * @access public |
|
848 | - * @since 1.0.19 |
|
849 | - */ |
|
850 | - public function show_success( $msg ) { |
|
851 | - $this->save_notice( 'success', $msg ); |
|
852 | - } |
|
853 | - |
|
854 | - /** |
|
855 | - * Displays a error notice |
|
856 | - * |
|
857 | - * @access public |
|
858 | - * @param string $msg The message to qeue. |
|
859 | - * @since 1.0.19 |
|
860 | - */ |
|
861 | - public function show_error( $msg ) { |
|
862 | - $this->save_notice( 'error', $msg ); |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * Displays a warning notice |
|
867 | - * |
|
868 | - * @access public |
|
869 | - * @param string $msg The message to qeue. |
|
870 | - * @since 1.0.19 |
|
871 | - */ |
|
872 | - public function show_warning( $msg ) { |
|
873 | - $this->save_notice( 'warning', $msg ); |
|
874 | - } |
|
875 | - |
|
876 | - /** |
|
877 | - * Displays a info notice |
|
878 | - * |
|
879 | - * @access public |
|
880 | - * @param string $msg The message to qeue. |
|
881 | - * @since 1.0.19 |
|
882 | - */ |
|
883 | - public function show_info( $msg ) { |
|
884 | - $this->save_notice( 'info', $msg ); |
|
885 | - } |
|
886 | - |
|
887 | - /** |
|
888 | - * Show notices |
|
889 | - * |
|
890 | - * @access public |
|
891 | - * @since 1.0.19 |
|
892 | - */ |
|
893 | - public function show_notices() { |
|
810 | + */ |
|
811 | + public function has_notices() { |
|
812 | + return count( $this->get_notices() ) > 0; |
|
813 | + } |
|
814 | + |
|
815 | + /** |
|
816 | + * Clears all admin notices |
|
817 | + * |
|
818 | + * @access public |
|
819 | + * @since 1.0.19 |
|
820 | + */ |
|
821 | + public function clear_notices() { |
|
822 | + delete_option( 'wpinv_admin_notices' ); |
|
823 | + } |
|
824 | + |
|
825 | + /** |
|
826 | + * Saves a new admin notice |
|
827 | + * |
|
828 | + * @access public |
|
829 | + * @since 1.0.19 |
|
830 | + */ |
|
831 | + public function save_notice( $type, $message ) { |
|
832 | + $notices = $this->get_notices(); |
|
833 | + |
|
834 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
835 | + $notices[ $type ] = array(); |
|
836 | + } |
|
837 | + |
|
838 | + $notices[ $type ][] = $message; |
|
839 | + |
|
840 | + update_option( 'wpinv_admin_notices', $notices ); |
|
841 | + } |
|
842 | + |
|
843 | + /** |
|
844 | + * Displays a success notice |
|
845 | + * |
|
846 | + * @param string $msg The message to qeue. |
|
847 | + * @access public |
|
848 | + * @since 1.0.19 |
|
849 | + */ |
|
850 | + public function show_success( $msg ) { |
|
851 | + $this->save_notice( 'success', $msg ); |
|
852 | + } |
|
853 | + |
|
854 | + /** |
|
855 | + * Displays a error notice |
|
856 | + * |
|
857 | + * @access public |
|
858 | + * @param string $msg The message to qeue. |
|
859 | + * @since 1.0.19 |
|
860 | + */ |
|
861 | + public function show_error( $msg ) { |
|
862 | + $this->save_notice( 'error', $msg ); |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Displays a warning notice |
|
867 | + * |
|
868 | + * @access public |
|
869 | + * @param string $msg The message to qeue. |
|
870 | + * @since 1.0.19 |
|
871 | + */ |
|
872 | + public function show_warning( $msg ) { |
|
873 | + $this->save_notice( 'warning', $msg ); |
|
874 | + } |
|
875 | + |
|
876 | + /** |
|
877 | + * Displays a info notice |
|
878 | + * |
|
879 | + * @access public |
|
880 | + * @param string $msg The message to qeue. |
|
881 | + * @since 1.0.19 |
|
882 | + */ |
|
883 | + public function show_info( $msg ) { |
|
884 | + $this->save_notice( 'info', $msg ); |
|
885 | + } |
|
886 | + |
|
887 | + /** |
|
888 | + * Show notices |
|
889 | + * |
|
890 | + * @access public |
|
891 | + * @since 1.0.19 |
|
892 | + */ |
|
893 | + public function show_notices() { |
|
894 | 894 | |
895 | 895 | $notices = $this->get_notices(); |
896 | 896 | $this->clear_notices(); |
897 | 897 | |
898 | - foreach ( $notices as $type => $messages ) { |
|
898 | + foreach ( $notices as $type => $messages ) { |
|
899 | 899 | |
900 | - if ( ! is_array( $messages ) ) { |
|
901 | - continue; |
|
902 | - } |
|
900 | + if ( ! is_array( $messages ) ) { |
|
901 | + continue; |
|
902 | + } |
|
903 | 903 | |
904 | 904 | $type = esc_attr( $type ); |
905 | - foreach ( $messages as $message ) { |
|
906 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
905 | + foreach ( $messages as $message ) { |
|
906 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
907 | 907 | } |
908 | 908 | } |
909 | 909 | |
910 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
911 | - |
|
912 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
913 | - $url = wp_nonce_url( |
|
914 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
915 | - 'getpaid-nonce', |
|
916 | - 'getpaid-nonce' |
|
917 | - ); |
|
918 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
919 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
920 | - 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>" ); |
|
921 | - break; |
|
922 | - } |
|
910 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
911 | + |
|
912 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
913 | + $url = wp_nonce_url( |
|
914 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
915 | + 'getpaid-nonce', |
|
916 | + 'getpaid-nonce' |
|
917 | + ); |
|
918 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
919 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
920 | + 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>" ); |
|
921 | + break; |
|
922 | + } |
|
923 | 923 | } |
924 | 924 | |
925 | - } |
|
925 | + } |
|
926 | 926 | |
927 | 927 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The main admin class. |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct() { |
41 | 41 | |
42 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
42 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
43 | + $this->admin_url = plugins_url('/', __FILE__); |
|
44 | 44 | $this->reports = new GetPaid_Reports(); |
45 | 45 | |
46 | - if ( is_admin() ) { |
|
46 | + if (is_admin()) { |
|
47 | 47 | $this->init_admin_hooks(); |
48 | 48 | } |
49 | 49 | |
@@ -54,33 +54,33 @@ discard block |
||
54 | 54 | * |
55 | 55 | */ |
56 | 56 | private function init_admin_hooks() { |
57 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
|
58 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
59 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
60 | - add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
|
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_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
76 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
77 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
57 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'), 9); |
|
58 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
59 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
60 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
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_duplicate_invoice', array($this, 'duplicate_invoice')); |
|
66 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
67 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
68 | + add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates')); |
|
69 | + add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages')); |
|
70 | + add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables')); |
|
71 | + add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices')); |
|
72 | + add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers')); |
|
73 | + add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts')); |
|
74 | + add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin')); |
|
75 | + add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway')); |
|
76 | + add_filter('admin_footer_text', array($this, 'admin_footer_text')); |
|
77 | + do_action('getpaid_init_admin_hooks', $this); |
|
78 | 78 | |
79 | 79 | // Setup/welcome |
80 | - if ( ! empty( $_GET['page'] ) ) { |
|
81 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
80 | + if (!empty($_GET['page'])) { |
|
81 | + switch (sanitize_text_field($_GET['page'])) { |
|
82 | 82 | case 'gp-setup': |
83 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
83 | + include_once dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php'; |
|
84 | 84 | break; |
85 | 85 | } |
86 | 86 | } |
@@ -94,37 +94,37 @@ discard block |
||
94 | 94 | public function enqeue_scripts() { |
95 | 95 | global $current_screen, $pagenow; |
96 | 96 | |
97 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
97 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
98 | 98 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
99 | 99 | |
100 | - if ( ! empty( $current_screen->post_type ) ) { |
|
100 | + if (!empty($current_screen->post_type)) { |
|
101 | 101 | $page = $current_screen->post_type; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // General styles. |
105 | - if ( false !== stripos( $page, 'wpi' ) || false !== stripos( $page, 'getpaid' ) || 'gp-setup' == $page || false !== stripos( $page, 'geodir-tickets' ) ) { |
|
105 | + if (false !== stripos($page, 'wpi') || false !== stripos($page, 'getpaid') || 'gp-setup' == $page || false !== stripos($page, 'geodir-tickets')) { |
|
106 | 106 | |
107 | 107 | // Styles. |
108 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
109 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
110 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
108 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
109 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
110 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
111 | 111 | |
112 | 112 | // Scripts. |
113 | - wp_enqueue_script( 'select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
113 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
114 | 114 | |
115 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
116 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ), $version ); |
|
117 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
115 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
116 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version); |
|
117 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Payment form scripts. |
122 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
122 | + if ('wpi_payment_form' == $page && $editing) { |
|
123 | 123 | $this->load_payment_form_scripts(); |
124 | 124 | } |
125 | 125 | |
126 | - if ( $page == 'wpinv-subscriptions' ) { |
|
127 | - wp_enqueue_script( 'postbox' ); |
|
126 | + if ($page == 'wpinv-subscriptions') { |
|
127 | + wp_enqueue_script('postbox'); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | } |
@@ -137,31 +137,31 @@ discard block |
||
137 | 137 | global $post; |
138 | 138 | |
139 | 139 | $date_range = array( |
140 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
140 | + 'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days', |
|
141 | 141 | ); |
142 | 142 | |
143 | - if ( $date_range['period'] == 'custom' ) { |
|
143 | + if ($date_range['period'] == 'custom') { |
|
144 | 144 | |
145 | - if ( isset( $_GET['from'] ) ) { |
|
146 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
145 | + if (isset($_GET['from'])) { |
|
146 | + $date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS); |
|
147 | 147 | } |
148 | 148 | |
149 | - if ( isset( $_GET['to'] ) ) { |
|
150 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
149 | + if (isset($_GET['to'])) { |
|
150 | + $date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
154 | 154 | $i18n = array( |
155 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
156 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
157 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
158 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
159 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
155 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
156 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
157 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
158 | + 'rest_nonce' => wp_create_nonce('wp_rest'), |
|
159 | + 'rest_root' => esc_url_raw(rest_url()), |
|
160 | 160 | 'date_range' => $date_range, |
161 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
162 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
163 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
164 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
161 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
162 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
163 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
164 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
165 | 165 | 'tax' => wpinv_tax_amount(), |
166 | 166 | 'discount' => 0, |
167 | 167 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -170,39 +170,39 @@ discard block |
||
170 | 170 | 'thousand_sep' => wpinv_thousands_separator(), |
171 | 171 | 'decimal_sep' => wpinv_decimal_separator(), |
172 | 172 | 'decimals' => wpinv_decimals(), |
173 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
174 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
175 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
176 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
177 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
178 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
179 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
180 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
181 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
182 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
183 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
184 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
185 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
186 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
187 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
188 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
189 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
190 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
191 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
192 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
173 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
174 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
175 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
176 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
177 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
178 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
179 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
180 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
181 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
182 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
183 | + 'action_edit' => __('Edit', 'invoicing'), |
|
184 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
185 | + 'item_description' => __('Item Description', 'invoicing'), |
|
186 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
187 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
188 | + 'searching' => __('Searching', 'invoicing'), |
|
189 | + 'loading' => __('Loading...', 'invoicing'), |
|
190 | + 'search_customers' => __('Enter customer name or email', 'invoicing'), |
|
191 | + 'search_items' => __('Enter item name', 'invoicing'), |
|
192 | + 'graphs' => array_merge(array('refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'), array_keys(wpinv_get_report_graphs())), |
|
193 | 193 | ); |
194 | 194 | |
195 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
195 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
196 | 196 | |
197 | - $invoice = new WPInv_Invoice( $post ); |
|
197 | + $invoice = new WPInv_Invoice($post); |
|
198 | 198 | $i18n['save_invoice'] = sprintf( |
199 | - __( 'Save %s', 'invoicing' ), |
|
200 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
199 | + __('Save %s', 'invoicing'), |
|
200 | + ucfirst($invoice->get_invoice_quote_type()) |
|
201 | 201 | ); |
202 | 202 | |
203 | 203 | $i18n['invoice_description'] = sprintf( |
204 | - __( '%s Description', 'invoicing' ), |
|
205 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
204 | + __('%s Description', 'invoicing'), |
|
205 | + ucfirst($invoice->get_invoice_quote_type()) |
|
206 | 206 | ); |
207 | 207 | |
208 | 208 | } |
@@ -216,24 +216,24 @@ discard block |
||
216 | 216 | * @param string $footer_text |
217 | 217 | * @return string |
218 | 218 | */ |
219 | - public function admin_footer_text( $footer_text ) { |
|
219 | + public function admin_footer_text($footer_text) { |
|
220 | 220 | global $current_screen; |
221 | 221 | |
222 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
222 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
223 | 223 | |
224 | - if ( ! empty( $current_screen->post_type ) ) { |
|
224 | + if (!empty($current_screen->post_type)) { |
|
225 | 225 | $page = $current_screen->post_type; |
226 | 226 | } |
227 | 227 | |
228 | 228 | // General styles. |
229 | - if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
|
229 | + if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) { |
|
230 | 230 | |
231 | 231 | // Change the footer text |
232 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
232 | + if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) { |
|
233 | 233 | |
234 | - $rating_url = esc_url( |
|
234 | + $rating_url = esc_url( |
|
235 | 235 | wp_nonce_url( |
236 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
236 | + admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'), |
|
237 | 237 | 'getpaid-nonce', |
238 | 238 | 'getpaid-nonce' |
239 | 239 | ) |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | |
242 | 242 | $footer_text = sprintf( |
243 | 243 | /* translators: %s: five stars */ |
244 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
244 | + __('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'), |
|
245 | 245 | "<a href='$rating_url'>★★★★★</a>" |
246 | 246 | ); |
247 | 247 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | $footer_text = sprintf( |
251 | 251 | /* translators: %s: GetPaid */ |
252 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
252 | + __('Thank you for using %s!', 'invoicing'), |
|
253 | 253 | "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
254 | 254 | ); |
255 | 255 | |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | * @since 2.0.0 |
266 | 266 | */ |
267 | 267 | public function redirect_to_wordpress_rating_page() { |
268 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
269 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
268 | + update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1); |
|
269 | + wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post'); |
|
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
@@ -277,30 +277,30 @@ discard block |
||
277 | 277 | protected function load_payment_form_scripts() { |
278 | 278 | global $post; |
279 | 279 | |
280 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
|
281 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
282 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
280 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION); |
|
281 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
282 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
283 | 283 | |
284 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
285 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
284 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
285 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable', 'wp-hooks'), $version); |
|
286 | 286 | |
287 | 287 | wp_localize_script( |
288 | 288 | 'wpinv-admin-payment-form-script', |
289 | 289 | 'wpinvPaymentFormAdmin', |
290 | 290 | array( |
291 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
292 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
291 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
292 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
293 | 293 | 'currency' => wpinv_currency_symbol(), |
294 | 294 | 'position' => wpinv_currency_position(), |
295 | 295 | 'decimals' => (int) wpinv_decimals(), |
296 | 296 | 'thousands_sep' => wpinv_thousands_separator(), |
297 | 297 | 'decimals_sep' => wpinv_decimal_separator(), |
298 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
298 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
299 | 299 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
300 | 300 | ) |
301 | 301 | ); |
302 | 302 | |
303 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
303 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
304 | 304 | |
305 | 305 | } |
306 | 306 | |
@@ -311,24 +311,24 @@ discard block |
||
311 | 311 | * @return string |
312 | 312 | * |
313 | 313 | */ |
314 | - public function admin_body_class( $classes ) { |
|
314 | + public function admin_body_class($classes) { |
|
315 | 315 | global $pagenow, $post, $current_screen; |
316 | 316 | |
317 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
317 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
318 | 318 | |
319 | - if ( ! empty( $current_screen->post_type ) ) { |
|
319 | + if (!empty($current_screen->post_type)) { |
|
320 | 320 | $page = $current_screen->post_type; |
321 | 321 | } |
322 | 322 | |
323 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
324 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
323 | + if (false !== stripos($page, 'wpi')) { |
|
324 | + $classes .= ' wpi-' . sanitize_key($page); |
|
325 | 325 | } |
326 | 326 | |
327 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
327 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
328 | 328 | $classes .= ' wpinv-cpt wpinv'; |
329 | 329 | } |
330 | 330 | |
331 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
331 | + if (getpaid_is_invoice_post_type($page)) { |
|
332 | 332 | $classes .= ' getpaid-is-invoice-cpt'; |
333 | 333 | } |
334 | 334 | |
@@ -347,21 +347,21 @@ discard block |
||
347 | 347 | 'version' => WPINV_VERSION, |
348 | 348 | 'support_url' => 'https://wpgetpaid.com/support/', |
349 | 349 | 'documentation_url' => 'https://docs.wpgetpaid.com/', |
350 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
350 | + 'activated' => (int) get_option('gepaid_installed_on'), |
|
351 | 351 | ) |
352 | 352 | ); |
353 | 353 | |
354 | 354 | new AyeCode_Connect_Helper( |
355 | 355 | array( |
356 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
357 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
358 | - '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>' ), |
|
359 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
360 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
361 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
362 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
356 | + 'connect_title' => __('WP Invoicing - an AyeCode product!', 'invoicing'), |
|
357 | + 'connect_external' => __('Please confirm you wish to connect your site?', 'invoicing'), |
|
358 | + '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>'), |
|
359 | + 'connect_button' => __('Connect Site', 'invoicing'), |
|
360 | + 'connecting_button' => __('Connecting...', 'invoicing'), |
|
361 | + 'error_localhost' => __('This service will only work with a live domain, not a localhost.', 'invoicing'), |
|
362 | + 'error' => __('Something went wrong, please refresh and try again.', 'invoicing'), |
|
363 | 363 | ), |
364 | - array( 'wpi-addons' ) |
|
364 | + array('wpi-addons') |
|
365 | 365 | ); |
366 | 366 | |
367 | 367 | } |
@@ -373,20 +373,20 @@ discard block |
||
373 | 373 | */ |
374 | 374 | public function activation_redirect() { |
375 | 375 | |
376 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
376 | + $redirected = get_option('wpinv_redirected_to_settings'); |
|
377 | 377 | |
378 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
378 | + if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) { |
|
379 | 379 | return; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // Bail if activating from network, or bulk |
383 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
383 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
384 | 384 | return; |
385 | 385 | } |
386 | 386 | |
387 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
387 | + update_option('wpinv_redirected_to_settings', 1); |
|
388 | 388 | |
389 | - wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
|
389 | + wp_safe_redirect(admin_url('index.php?page=gp-setup')); |
|
390 | 390 | exit; |
391 | 391 | |
392 | 392 | } |
@@ -396,9 +396,9 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public function maybe_do_admin_action() { |
398 | 398 | |
399 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
400 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
401 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
399 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
400 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
401 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | } |
@@ -408,24 +408,24 @@ discard block |
||
408 | 408 | * |
409 | 409 | * @param array $args |
410 | 410 | */ |
411 | - public function duplicate_invoice( $args ) { |
|
411 | + public function duplicate_invoice($args) { |
|
412 | 412 | |
413 | - if ( empty( $args['invoice_id'] ) ) { |
|
413 | + if (empty($args['invoice_id'])) { |
|
414 | 414 | return; |
415 | 415 | } |
416 | 416 | |
417 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
417 | + $invoice = new WPInv_Invoice((int) $args['invoice_id']); |
|
418 | 418 | |
419 | - if ( ! $invoice->exists() ) { |
|
419 | + if (!$invoice->exists()) { |
|
420 | 420 | return; |
421 | 421 | } |
422 | 422 | |
423 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
423 | + $new_invoice = getpaid_duplicate_invoice($invoice); |
|
424 | 424 | $new_invoice->save(); |
425 | 425 | |
426 | - if ( $new_invoice->exists() ) { |
|
426 | + if ($new_invoice->exists()) { |
|
427 | 427 | |
428 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
428 | + getpaid_admin()->show_success(__('Invoice duplicated successfully.', 'newsletter-optin-box')); |
|
429 | 429 | |
430 | 430 | wp_safe_redirect( |
431 | 431 | add_query_arg( |
@@ -433,14 +433,14 @@ discard block |
||
433 | 433 | 'action' => 'edit', |
434 | 434 | 'post' => $new_invoice->get_id(), |
435 | 435 | ), |
436 | - admin_url( 'post.php' ) |
|
436 | + admin_url('post.php') |
|
437 | 437 | ) |
438 | 438 | ); |
439 | 439 | exit; |
440 | 440 | |
441 | 441 | } |
442 | 442 | |
443 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
443 | + getpaid_admin()->show_error(__('There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box')); |
|
444 | 444 | |
445 | 445 | } |
446 | 446 | |
@@ -449,34 +449,34 @@ discard block |
||
449 | 449 | * |
450 | 450 | * @param array $args |
451 | 451 | */ |
452 | - public function duplicate_payment_form( $args ) { |
|
452 | + public function duplicate_payment_form($args) { |
|
453 | 453 | |
454 | - if ( empty( $args['form_id'] ) ) { |
|
454 | + if (empty($args['form_id'])) { |
|
455 | 455 | return; |
456 | 456 | } |
457 | 457 | |
458 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
458 | + $form = new GetPaid_Payment_Form((int) $args['form_id']); |
|
459 | 459 | |
460 | - if ( ! $form->exists() ) { |
|
460 | + if (!$form->exists()) { |
|
461 | 461 | return; |
462 | 462 | } |
463 | 463 | |
464 | 464 | $new_form = new GetPaid_Payment_Form(); |
465 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
466 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
467 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
468 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
465 | + $new_form->set_author($form->get_author('edit')); |
|
466 | + $new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing')); |
|
467 | + $new_form->set_elements($form->get_elements('edit')); |
|
468 | + $new_form->set_items($form->get_items('edit')); |
|
469 | 469 | $new_form->save(); |
470 | 470 | |
471 | - if ( $new_form->exists() ) { |
|
472 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
473 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
471 | + if ($new_form->exists()) { |
|
472 | + $this->show_success(__('Form duplicated successfully', 'invoicing')); |
|
473 | + $url = get_edit_post_link($new_form->get_id(), 'edit'); |
|
474 | 474 | } else { |
475 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
476 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
475 | + $this->show_error(__('Unable to duplicate form', 'invoicing')); |
|
476 | + $url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce')); |
|
477 | 477 | } |
478 | 478 | |
479 | - wp_redirect( $url ); |
|
479 | + wp_redirect($url); |
|
480 | 480 | exit; |
481 | 481 | } |
482 | 482 | |
@@ -485,9 +485,9 @@ discard block |
||
485 | 485 | * |
486 | 486 | * @param array $args |
487 | 487 | */ |
488 | - public function send_customer_invoice( $args ) { |
|
489 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
490 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
488 | + public function send_customer_invoice($args) { |
|
489 | + getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true); |
|
490 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
491 | 491 | exit; |
492 | 492 | } |
493 | 493 | |
@@ -496,16 +496,16 @@ discard block |
||
496 | 496 | * |
497 | 497 | * @param array $args |
498 | 498 | */ |
499 | - public function send_customer_payment_reminder( $args ) { |
|
500 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
499 | + public function send_customer_payment_reminder($args) { |
|
500 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
501 | 501 | |
502 | - if ( $sent ) { |
|
503 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
502 | + if ($sent) { |
|
503 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
504 | 504 | } else { |
505 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
505 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
506 | 506 | } |
507 | 507 | |
508 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
508 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
509 | 509 | exit; |
510 | 510 | } |
511 | 511 | |
@@ -515,8 +515,8 @@ discard block |
||
515 | 515 | */ |
516 | 516 | public function admin_reset_tax_rates() { |
517 | 517 | |
518 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
519 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
518 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
519 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
520 | 520 | exit; |
521 | 521 | |
522 | 522 | } |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | public function admin_create_missing_pages() { |
529 | 529 | $installer = new GetPaid_Installer(); |
530 | 530 | $installer->create_pages(); |
531 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
532 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
531 | + $this->show_success(__('GetPaid pages updated.', 'invoicing')); |
|
532 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
533 | 533 | exit; |
534 | 534 | } |
535 | 535 | |
@@ -541,35 +541,35 @@ discard block |
||
541 | 541 | global $wpdb; |
542 | 542 | $installer = new GetPaid_Installer(); |
543 | 543 | |
544 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
544 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'") != $wpdb->prefix . 'wpinv_subscriptions') { |
|
545 | 545 | $installer->create_subscriptions_table(); |
546 | 546 | |
547 | - if ( $wpdb->last_error !== '' ) { |
|
548 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
547 | + if ($wpdb->last_error !== '') { |
|
548 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
552 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") != $wpdb->prefix . 'getpaid_invoices') { |
|
553 | 553 | $installer->create_invoices_table(); |
554 | 554 | |
555 | - if ( '' !== $wpdb->last_error ) { |
|
556 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
555 | + if ('' !== $wpdb->last_error) { |
|
556 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
560 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
560 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'") != $wpdb->prefix . 'getpaid_invoice_items') { |
|
561 | 561 | $installer->create_invoice_items_table(); |
562 | 562 | |
563 | - if ( '' !== $wpdb->last_error ) { |
|
564 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
563 | + if ('' !== $wpdb->last_error) { |
|
564 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
568 | - if ( ! $this->has_notices() ) { |
|
569 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
568 | + if (!$this->has_notices()) { |
|
569 | + $this->show_success(__('Your GetPaid tables have been updated.', 'invoicing')); |
|
570 | 570 | } |
571 | 571 | |
572 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
572 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
573 | 573 | exit; |
574 | 574 | } |
575 | 575 | |
@@ -584,10 +584,10 @@ discard block |
||
584 | 584 | $installer->migrate_old_invoices(); |
585 | 585 | |
586 | 586 | // Show an admin message. |
587 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
587 | + $this->show_success(__('Your invoices have been migrated.', 'invoicing')); |
|
588 | 588 | |
589 | 589 | // Redirect the admin. |
590 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
590 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
591 | 591 | exit; |
592 | 592 | |
593 | 593 | } |
@@ -599,78 +599,78 @@ discard block |
||
599 | 599 | public function admin_download_customers() { |
600 | 600 | global $wpdb; |
601 | 601 | |
602 | - $output = fopen( 'php://output', 'w' ); |
|
602 | + $output = fopen('php://output', 'w'); |
|
603 | 603 | |
604 | - if ( false === $output ) { |
|
605 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
604 | + if (false === $output) { |
|
605 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
606 | 606 | } |
607 | 607 | |
608 | - header( 'Content-Type:text/csv' ); |
|
609 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
608 | + header('Content-Type:text/csv'); |
|
609 | + header('Content-Disposition:attachment;filename=customers.csv'); |
|
610 | 610 | |
611 | 611 | $post_types = ''; |
612 | 612 | |
613 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
614 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
613 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
614 | + $post_types .= $wpdb->prepare('post_type=%s OR ', $post_type); |
|
615 | 615 | } |
616 | 616 | |
617 | - $post_types = rtrim( $post_types, ' OR' ); |
|
617 | + $post_types = rtrim($post_types, ' OR'); |
|
618 | 618 | |
619 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
619 | + $customers = $wpdb->get_col("SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"); |
|
620 | 620 | |
621 | 621 | $columns = array( |
622 | - 'name' => __( 'Name', 'invoicing' ), |
|
623 | - 'email' => __( 'Email', 'invoicing' ), |
|
624 | - 'country' => __( 'Country', 'invoicing' ), |
|
625 | - 'state' => __( 'State', 'invoicing' ), |
|
626 | - 'city' => __( 'City', 'invoicing' ), |
|
627 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
628 | - 'address' => __( 'Address', 'invoicing' ), |
|
629 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
630 | - 'company' => __( 'Company', 'invoicing' ), |
|
631 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
632 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
633 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
634 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
622 | + 'name' => __('Name', 'invoicing'), |
|
623 | + 'email' => __('Email', 'invoicing'), |
|
624 | + 'country' => __('Country', 'invoicing'), |
|
625 | + 'state' => __('State', 'invoicing'), |
|
626 | + 'city' => __('City', 'invoicing'), |
|
627 | + 'zip' => __('ZIP', 'invoicing'), |
|
628 | + 'address' => __('Address', 'invoicing'), |
|
629 | + 'phone' => __('Phone', 'invoicing'), |
|
630 | + 'company' => __('Company', 'invoicing'), |
|
631 | + 'company_id' => __('Company ID', 'invoicing'), |
|
632 | + 'invoices' => __('Invoices', 'invoicing'), |
|
633 | + 'total_raw' => __('Total Spend', 'invoicing'), |
|
634 | + 'signup' => __('Date created', 'invoicing'), |
|
635 | 635 | ); |
636 | 636 | |
637 | 637 | // Output the csv column headers. |
638 | - fputcsv( $output, array_values( $columns ) ); |
|
638 | + fputcsv($output, array_values($columns)); |
|
639 | 639 | |
640 | 640 | // Loop through |
641 | 641 | $table = new WPInv_Customers_Table(); |
642 | - foreach ( $customers as $customer_id ) { |
|
642 | + foreach ($customers as $customer_id) { |
|
643 | 643 | |
644 | - $user = get_user_by( 'id', $customer_id ); |
|
644 | + $user = get_user_by('id', $customer_id); |
|
645 | 645 | $row = array(); |
646 | - if ( empty( $user ) ) { |
|
646 | + if (empty($user)) { |
|
647 | 647 | continue; |
648 | 648 | } |
649 | 649 | |
650 | - foreach ( array_keys( $columns ) as $column ) { |
|
650 | + foreach (array_keys($columns) as $column) { |
|
651 | 651 | |
652 | 652 | $method = 'column_' . $column; |
653 | 653 | |
654 | - if ( 'name' == $column ) { |
|
655 | - $value = esc_html( $user->display_name ); |
|
656 | - } elseif ( 'email' == $column ) { |
|
657 | - $value = sanitize_email( $user->user_email ); |
|
658 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
659 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
654 | + if ('name' == $column) { |
|
655 | + $value = esc_html($user->display_name); |
|
656 | + } elseif ('email' == $column) { |
|
657 | + $value = sanitize_email($user->user_email); |
|
658 | + } elseif (is_callable(array($table, $method))) { |
|
659 | + $value = wp_strip_all_tags($table->$method($user)); |
|
660 | 660 | } |
661 | 661 | |
662 | - if ( empty( $value ) ) { |
|
663 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
662 | + if (empty($value)) { |
|
663 | + $value = esc_html(get_user_meta($user->ID, '_wpinv_' . $column, true)); |
|
664 | 664 | } |
665 | 665 | |
666 | 666 | $row[] = $value; |
667 | 667 | |
668 | 668 | } |
669 | 669 | |
670 | - fputcsv( $output, $row ); |
|
670 | + fputcsv($output, $row); |
|
671 | 671 | } |
672 | 672 | |
673 | - fclose( $output ); |
|
673 | + fclose($output); |
|
674 | 674 | exit; |
675 | 675 | |
676 | 676 | } |
@@ -680,27 +680,27 @@ discard block |
||
680 | 680 | * |
681 | 681 | * @param array $data |
682 | 682 | */ |
683 | - public function admin_install_plugin( $data ) { |
|
683 | + public function admin_install_plugin($data) { |
|
684 | 684 | |
685 | - if ( ! empty( $data['plugins'] ) ) { |
|
685 | + if (!empty($data['plugins'])) { |
|
686 | 686 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
687 | 687 | wp_cache_flush(); |
688 | 688 | |
689 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
690 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
691 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
692 | - $installed = $upgrader->install( $plugin_zip ); |
|
689 | + foreach ($data['plugins'] as $slug => $file) { |
|
690 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip'); |
|
691 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
692 | + $installed = $upgrader->install($plugin_zip); |
|
693 | 693 | |
694 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
695 | - activate_plugin( $file, '', false, true ); |
|
694 | + if (!is_wp_error($installed) && $installed) { |
|
695 | + activate_plugin($file, '', false, true); |
|
696 | 696 | } else { |
697 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
697 | + wpinv_error_log($upgrader->skin->get_upgrade_messages(), false); |
|
698 | 698 | } |
699 | 699 | } |
700 | 700 | } |
701 | 701 | |
702 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
703 | - wp_safe_redirect( $redirect ); |
|
702 | + $redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php'); |
|
703 | + wp_safe_redirect($redirect); |
|
704 | 704 | exit; |
705 | 705 | |
706 | 706 | } |
@@ -710,41 +710,41 @@ discard block |
||
710 | 710 | * |
711 | 711 | * @param array $data |
712 | 712 | */ |
713 | - public function admin_connect_gateway( $data ) { |
|
713 | + public function admin_connect_gateway($data) { |
|
714 | 714 | |
715 | - if ( ! empty( $data['plugin'] ) ) { |
|
715 | + if (!empty($data['plugin'])) { |
|
716 | 716 | |
717 | - $gateway = sanitize_key( $data['plugin'] ); |
|
718 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
717 | + $gateway = sanitize_key($data['plugin']); |
|
718 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
719 | 719 | |
720 | - if ( ! empty( $connect_url ) ) { |
|
721 | - wp_redirect( $connect_url ); |
|
720 | + if (!empty($connect_url)) { |
|
721 | + wp_redirect($connect_url); |
|
722 | 722 | exit; |
723 | 723 | } |
724 | 724 | |
725 | - if ( 'stripe' == $data['plugin'] ) { |
|
725 | + if ('stripe' == $data['plugin']) { |
|
726 | 726 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
727 | 727 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
728 | 728 | wp_cache_flush(); |
729 | 729 | |
730 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
731 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
732 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | - $upgrader->install( $plugin_zip ); |
|
730 | + if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) { |
|
731 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip'); |
|
732 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
733 | + $upgrader->install($plugin_zip); |
|
734 | 734 | } |
735 | 735 | |
736 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
736 | + activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true); |
|
737 | 737 | } |
738 | 738 | |
739 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
740 | - if ( ! empty( $connect_url ) ) { |
|
741 | - wp_redirect( $connect_url ); |
|
739 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
740 | + if (!empty($connect_url)) { |
|
741 | + wp_redirect($connect_url); |
|
742 | 742 | exit; |
743 | 743 | } |
744 | 744 | } |
745 | 745 | |
746 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
747 | - wp_safe_redirect( $redirect ); |
|
746 | + $redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
|
747 | + wp_safe_redirect($redirect); |
|
748 | 748 | exit; |
749 | 749 | |
750 | 750 | } |
@@ -758,35 +758,35 @@ discard block |
||
758 | 758 | |
759 | 759 | // Fetch all invoices that have discount codes. |
760 | 760 | $table = $wpdb->prefix . 'getpaid_invoices'; |
761 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
761 | + $invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''"); |
|
762 | 762 | |
763 | - foreach ( $invoices as $invoice ) { |
|
763 | + foreach ($invoices as $invoice) { |
|
764 | 764 | |
765 | - $invoice = new WPInv_Invoice( $invoice ); |
|
765 | + $invoice = new WPInv_Invoice($invoice); |
|
766 | 766 | |
767 | - if ( ! $invoice->exists() ) { |
|
767 | + if (!$invoice->exists()) { |
|
768 | 768 | continue; |
769 | 769 | } |
770 | 770 | |
771 | 771 | // Abort if the discount does not exist or does not apply here. |
772 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
773 | - if ( ! $discount->exists() ) { |
|
772 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
773 | + if (!$discount->exists()) { |
|
774 | 774 | continue; |
775 | 775 | } |
776 | 776 | |
777 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
777 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
778 | 778 | $invoice->recalculate_total(); |
779 | 779 | |
780 | - if ( $invoice->get_total_discount() > 0 ) { |
|
780 | + if ($invoice->get_total_discount() > 0) { |
|
781 | 781 | $invoice->save(); |
782 | 782 | } |
783 | 783 | } |
784 | 784 | |
785 | 785 | // Show an admin message. |
786 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
786 | + $this->show_success(__('Discounts have been recalculated.', 'invoicing')); |
|
787 | 787 | |
788 | 788 | // Redirect the admin. |
789 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
789 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
790 | 790 | exit; |
791 | 791 | |
792 | 792 | } |
@@ -798,8 +798,8 @@ discard block |
||
798 | 798 | * @return array |
799 | 799 | */ |
800 | 800 | public function get_notices() { |
801 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
802 | - return is_array( $notices ) ? $notices : array(); |
|
801 | + $notices = get_option('wpinv_admin_notices'); |
|
802 | + return is_array($notices) ? $notices : array(); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | * @return array |
810 | 810 | */ |
811 | 811 | public function has_notices() { |
812 | - return count( $this->get_notices() ) > 0; |
|
812 | + return count($this->get_notices()) > 0; |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | * @since 1.0.19 |
820 | 820 | */ |
821 | 821 | public function clear_notices() { |
822 | - delete_option( 'wpinv_admin_notices' ); |
|
822 | + delete_option('wpinv_admin_notices'); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | /** |
@@ -828,16 +828,16 @@ discard block |
||
828 | 828 | * @access public |
829 | 829 | * @since 1.0.19 |
830 | 830 | */ |
831 | - public function save_notice( $type, $message ) { |
|
831 | + public function save_notice($type, $message) { |
|
832 | 832 | $notices = $this->get_notices(); |
833 | 833 | |
834 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
835 | - $notices[ $type ] = array(); |
|
834 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
835 | + $notices[$type] = array(); |
|
836 | 836 | } |
837 | 837 | |
838 | - $notices[ $type ][] = $message; |
|
838 | + $notices[$type][] = $message; |
|
839 | 839 | |
840 | - update_option( 'wpinv_admin_notices', $notices ); |
|
840 | + update_option('wpinv_admin_notices', $notices); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
@@ -847,8 +847,8 @@ discard block |
||
847 | 847 | * @access public |
848 | 848 | * @since 1.0.19 |
849 | 849 | */ |
850 | - public function show_success( $msg ) { |
|
851 | - $this->save_notice( 'success', $msg ); |
|
850 | + public function show_success($msg) { |
|
851 | + $this->save_notice('success', $msg); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
@@ -858,8 +858,8 @@ discard block |
||
858 | 858 | * @param string $msg The message to qeue. |
859 | 859 | * @since 1.0.19 |
860 | 860 | */ |
861 | - public function show_error( $msg ) { |
|
862 | - $this->save_notice( 'error', $msg ); |
|
861 | + public function show_error($msg) { |
|
862 | + $this->save_notice('error', $msg); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | /** |
@@ -869,8 +869,8 @@ discard block |
||
869 | 869 | * @param string $msg The message to qeue. |
870 | 870 | * @since 1.0.19 |
871 | 871 | */ |
872 | - public function show_warning( $msg ) { |
|
873 | - $this->save_notice( 'warning', $msg ); |
|
872 | + public function show_warning($msg) { |
|
873 | + $this->save_notice('warning', $msg); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @param string $msg The message to qeue. |
881 | 881 | * @since 1.0.19 |
882 | 882 | */ |
883 | - public function show_info( $msg ) { |
|
884 | - $this->save_notice( 'info', $msg ); |
|
883 | + public function show_info($msg) { |
|
884 | + $this->save_notice('info', $msg); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
@@ -895,29 +895,29 @@ discard block |
||
895 | 895 | $notices = $this->get_notices(); |
896 | 896 | $this->clear_notices(); |
897 | 897 | |
898 | - foreach ( $notices as $type => $messages ) { |
|
898 | + foreach ($notices as $type => $messages) { |
|
899 | 899 | |
900 | - if ( ! is_array( $messages ) ) { |
|
900 | + if (!is_array($messages)) { |
|
901 | 901 | continue; |
902 | 902 | } |
903 | 903 | |
904 | - $type = esc_attr( $type ); |
|
905 | - foreach ( $messages as $message ) { |
|
906 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
904 | + $type = esc_attr($type); |
|
905 | + foreach ($messages as $message) { |
|
906 | + echo wp_kses_post("<div class='notice notice-$type is-dismissible'><p>$message</p></div>"); |
|
907 | 907 | } |
908 | 908 | } |
909 | 909 | |
910 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
910 | + foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) { |
|
911 | 911 | |
912 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
913 | - $url = wp_nonce_url( |
|
914 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
912 | + if (!is_numeric(wpinv_get_option($page, false))) { |
|
913 | + $url = wp_nonce_url( |
|
914 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
915 | 915 | 'getpaid-nonce', |
916 | 916 | 'getpaid-nonce' |
917 | 917 | ); |
918 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
919 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
920 | - 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>" ); |
|
918 | + $message = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing'); |
|
919 | + $message2 = __('Generate Pages', 'invoicing'); |
|
920 | + 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>"); |
|
921 | 921 | break; |
922 | 922 | } |
923 | 923 | } |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'bank_transfer'; |
21 | 21 | |
22 | - /** |
|
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
22 | + /** |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 8; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 8; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -44,24 +44,24 @@ discard block |
||
44 | 44 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
45 | 45 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | + add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | + add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | + add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | - * Process Payment. |
|
58 | - * |
|
59 | - * @param WPInv_Invoice $invoice Invoice. |
|
60 | - * @param array $submission_data Posted checkout fields. |
|
61 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + * Process Payment. |
|
58 | + * |
|
59 | + * @param WPInv_Invoice $invoice Invoice. |
|
60 | + * @param array $submission_data Posted checkout fields. |
|
61 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | 67 | $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
@@ -82,66 +82,66 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * Output for the order received page. |
|
86 | - * |
|
87 | - * @param WPInv_Invoice $invoice Invoice. |
|
88 | - */ |
|
89 | - public function thankyou_page( $invoice ) { |
|
85 | + * Output for the order received page. |
|
86 | + * |
|
87 | + * @param WPInv_Invoice $invoice Invoice. |
|
88 | + */ |
|
89 | + public function thankyou_page( $invoice ) { |
|
90 | 90 | |
91 | 91 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
92 | 92 | |
93 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
93 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
94 | 94 | |
95 | 95 | if ( ! empty( $this->instructions ) ) { |
96 | 96 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details( $invoice ); |
|
100 | 100 | |
101 | - echo '</div>'; |
|
101 | + echo '</div>'; |
|
102 | 102 | |
103 | 103 | } |
104 | 104 | |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | /** |
108 | - * Add content to the WPI emails. |
|
109 | - * |
|
110 | - * @param WPInv_Invoice $invoice Invoice. |
|
111 | - * @param string $email_type Email format: plain text or HTML. |
|
112 | - * @param bool $sent_to_admin Sent to admin. |
|
113 | - */ |
|
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
108 | + * Add content to the WPI emails. |
|
109 | + * |
|
110 | + * @param WPInv_Invoice $invoice Invoice. |
|
111 | + * @param string $email_type Email format: plain text or HTML. |
|
112 | + * @param bool $sent_to_admin Sent to admin. |
|
113 | + */ |
|
114 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
117 | 117 | |
118 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
118 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ( $this->instructions ) { |
|
121 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details( $invoice ); |
|
125 | 125 | |
126 | - echo '</div>'; |
|
126 | + echo '</div>'; |
|
127 | 127 | |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * Get bank details and place into a list format. |
|
134 | - * |
|
135 | - * @param WPInv_Invoice $invoice Invoice. |
|
136 | - */ |
|
137 | - protected function bank_details( $invoice ) { |
|
133 | + * Get bank details and place into a list format. |
|
134 | + * |
|
135 | + * @param WPInv_Invoice $invoice Invoice. |
|
136 | + */ |
|
137 | + protected function bank_details( $invoice ) { |
|
138 | 138 | |
139 | - // Get the invoice country and country $locale. |
|
140 | - $country = $invoice->get_country(); |
|
141 | - $locale = $this->get_country_locale(); |
|
139 | + // Get the invoice country and country $locale. |
|
140 | + $country = $invoice->get_country(); |
|
141 | + $locale = $this->get_country_locale(); |
|
142 | 142 | |
143 | - // Get sortcode label in the $locale array and use appropriate one. |
|
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
143 | + // Get sortcode label in the $locale array and use appropriate one. |
|
144 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | 147 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | |
161 | 161 | if ( ! empty( $value ) ) { |
162 | 162 | $bank_info[ $field ] = array( |
163 | - 'label' => $label, |
|
164 | - 'value' => $value, |
|
165 | - ); |
|
163 | + 'label' => $label, |
|
164 | + 'value' => $value, |
|
165 | + ); |
|
166 | 166 | } |
167 | - } |
|
167 | + } |
|
168 | 168 | |
169 | 169 | $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
170 | 170 | |
@@ -172,139 +172,139 @@ discard block |
||
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
176 | + |
|
177 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
178 | + |
|
179 | + foreach ( $bank_info as $key => $data ) { |
|
180 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
181 | + } |
|
182 | + |
|
183 | + echo '</table>'; |
|
176 | 184 | |
177 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
185 | + } |
|
178 | 186 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
180 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
181 | - } |
|
187 | + /** |
|
188 | + * Get country locale if localized. |
|
189 | + * |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + public function get_country_locale() { |
|
193 | + |
|
194 | + if ( empty( $this->locale ) ) { |
|
195 | + |
|
196 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
197 | + $this->locale = apply_filters( |
|
198 | + 'getpaid_get_bank_transfer_locale', |
|
199 | + array( |
|
200 | + 'AU' => array( |
|
201 | + 'sortcode' => array( |
|
202 | + 'label' => __( 'BSB', 'invoicing' ), |
|
203 | + ), |
|
204 | + ), |
|
205 | + 'CA' => array( |
|
206 | + 'sortcode' => array( |
|
207 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
208 | + ), |
|
209 | + ), |
|
210 | + 'IN' => array( |
|
211 | + 'sortcode' => array( |
|
212 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
213 | + ), |
|
214 | + ), |
|
215 | + 'IT' => array( |
|
216 | + 'sortcode' => array( |
|
217 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
218 | + ), |
|
219 | + ), |
|
220 | + 'NZ' => array( |
|
221 | + 'sortcode' => array( |
|
222 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
223 | + ), |
|
224 | + ), |
|
225 | + 'SE' => array( |
|
226 | + 'sortcode' => array( |
|
227 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
228 | + ), |
|
229 | + ), |
|
230 | + 'US' => array( |
|
231 | + 'sortcode' => array( |
|
232 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
233 | + ), |
|
234 | + ), |
|
235 | + 'ZA' => array( |
|
236 | + 'sortcode' => array( |
|
237 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
238 | + ), |
|
239 | + ), |
|
240 | + ) |
|
241 | + ); |
|
182 | 242 | |
183 | - echo '</table>'; |
|
243 | + } |
|
244 | + |
|
245 | + return $this->locale; |
|
184 | 246 | |
185 | 247 | } |
186 | 248 | |
187 | 249 | /** |
188 | - * Get country locale if localized. |
|
189 | - * |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - public function get_country_locale() { |
|
193 | - |
|
194 | - if ( empty( $this->locale ) ) { |
|
195 | - |
|
196 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
197 | - $this->locale = apply_filters( |
|
198 | - 'getpaid_get_bank_transfer_locale', |
|
199 | - array( |
|
200 | - 'AU' => array( |
|
201 | - 'sortcode' => array( |
|
202 | - 'label' => __( 'BSB', 'invoicing' ), |
|
203 | - ), |
|
204 | - ), |
|
205 | - 'CA' => array( |
|
206 | - 'sortcode' => array( |
|
207 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
208 | - ), |
|
209 | - ), |
|
210 | - 'IN' => array( |
|
211 | - 'sortcode' => array( |
|
212 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
213 | - ), |
|
214 | - ), |
|
215 | - 'IT' => array( |
|
216 | - 'sortcode' => array( |
|
217 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
218 | - ), |
|
219 | - ), |
|
220 | - 'NZ' => array( |
|
221 | - 'sortcode' => array( |
|
222 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
223 | - ), |
|
224 | - ), |
|
225 | - 'SE' => array( |
|
226 | - 'sortcode' => array( |
|
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
228 | - ), |
|
229 | - ), |
|
230 | - 'US' => array( |
|
231 | - 'sortcode' => array( |
|
232 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
233 | - ), |
|
234 | - ), |
|
235 | - 'ZA' => array( |
|
236 | - 'sortcode' => array( |
|
237 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
238 | - ), |
|
239 | - ), |
|
240 | - ) |
|
241 | - ); |
|
242 | - |
|
243 | - } |
|
244 | - |
|
245 | - return $this->locale; |
|
246 | - |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Filters the gateway settings. |
|
251 | - * |
|
252 | - * @param array $admin_settings |
|
253 | - */ |
|
254 | - public function admin_settings( $admin_settings ) { |
|
250 | + * Filters the gateway settings. |
|
251 | + * |
|
252 | + * @param array $admin_settings |
|
253 | + */ |
|
254 | + public function admin_settings( $admin_settings ) { |
|
255 | 255 | |
256 | 256 | $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
257 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
257 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
258 | 258 | |
259 | - $locale = $this->get_country_locale(); |
|
259 | + $locale = $this->get_country_locale(); |
|
260 | 260 | |
261 | - // Get sortcode label in the $locale array and use appropriate one. |
|
262 | - $country = wpinv_default_billing_country(); |
|
263 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
261 | + // Get sortcode label in the $locale array and use appropriate one. |
|
262 | + $country = wpinv_default_billing_country(); |
|
263 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
264 | 264 | |
265 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
265 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_name', |
268 | 268 | 'name' => __( 'Account Name', 'invoicing' ), |
269 | - ); |
|
269 | + ); |
|
270 | 270 | |
271 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
271 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_ac_no', |
274 | 274 | 'name' => __( 'Account Number', 'invoicing' ), |
275 | - ); |
|
275 | + ); |
|
276 | 276 | |
277 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
277 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_bank_name', |
280 | 280 | 'name' => __( 'Bank Name', 'invoicing' ), |
281 | - ); |
|
281 | + ); |
|
282 | 282 | |
283 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
283 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_ifsc', |
286 | 286 | 'name' => __( 'IFSC Code', 'invoicing' ), |
287 | - ); |
|
287 | + ); |
|
288 | 288 | |
289 | - $admin_settings['bank_transfer_iban'] = array( |
|
289 | + $admin_settings['bank_transfer_iban'] = array( |
|
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_iban', |
292 | 292 | 'name' => __( 'IBAN', 'invoicing' ), |
293 | - ); |
|
293 | + ); |
|
294 | 294 | |
295 | - $admin_settings['bank_transfer_bic'] = array( |
|
295 | + $admin_settings['bank_transfer_bic'] = array( |
|
296 | 296 | 'type' => 'text', |
297 | 297 | 'id' => 'bank_transfer_bic', |
298 | 298 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
299 | - ); |
|
299 | + ); |
|
300 | 300 | |
301 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
302 | - 'type' => 'text', |
|
303 | - 'id' => 'bank_transfer_sort_code', |
|
304 | - 'name' => $sortcode, |
|
305 | - ); |
|
301 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
302 | + 'type' => 'text', |
|
303 | + 'id' => 'bank_transfer_sort_code', |
|
304 | + 'name' => $sortcode, |
|
305 | + ); |
|
306 | 306 | |
307 | - $admin_settings['bank_transfer_info'] = array( |
|
307 | + $admin_settings['bank_transfer_info'] = array( |
|
308 | 308 | 'id' => 'bank_transfer_info', |
309 | 309 | 'name' => __( 'Instructions', 'invoicing' ), |
310 | 310 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -314,17 +314,17 @@ discard block |
||
314 | 314 | 'rows' => 5, |
315 | 315 | ); |
316 | 316 | |
317 | - return $admin_settings; |
|
318 | - } |
|
317 | + return $admin_settings; |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * Processes invoice addons. |
|
322 | - * |
|
323 | - * @param WPInv_Invoice $invoice |
|
324 | - * @param GetPaid_Form_Item[] $items |
|
325 | - * @return WPInv_Invoice |
|
326 | - */ |
|
327 | - public function process_addons( $invoice, $items ) { |
|
320 | + /** |
|
321 | + * Processes invoice addons. |
|
322 | + * |
|
323 | + * @param WPInv_Invoice $invoice |
|
324 | + * @param GetPaid_Form_Item[] $items |
|
325 | + * @return WPInv_Invoice |
|
326 | + */ |
|
327 | + public function process_addons( $invoice, $items ) { |
|
328 | 328 | |
329 | 329 | foreach ( $items as $item ) { |
330 | 330 | $invoice->add_item( $item ); |
@@ -332,66 +332,66 @@ discard block |
||
332 | 332 | |
333 | 333 | $invoice->recalculate_total(); |
334 | 334 | $invoice->save(); |
335 | - } |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
338 | - * (Maybe) renews a bank transfer subscription profile. |
|
339 | - * |
|
340 | - * |
|
337 | + /** |
|
338 | + * (Maybe) renews a bank transfer subscription profile. |
|
339 | + * |
|
340 | + * |
|
341 | 341 | * @param WPInv_Subscription $subscription |
342 | - */ |
|
343 | - public function maybe_renew_subscription( $subscription ) { |
|
342 | + */ |
|
343 | + public function maybe_renew_subscription( $subscription ) { |
|
344 | 344 | |
345 | 345 | // Ensure its our subscription && it's active. |
346 | 346 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
347 | - $subscription->create_payment(); |
|
347 | + $subscription->create_payment(); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | } |
351 | 351 | |
352 | - /** |
|
353 | - * Process a bank transfer payment. |
|
354 | - * |
|
355 | - * |
|
352 | + /** |
|
353 | + * Process a bank transfer payment. |
|
354 | + * |
|
355 | + * |
|
356 | 356 | * @param WPInv_Invoice $invoice |
357 | - */ |
|
358 | - public function invoice_paid( $invoice ) { |
|
359 | - |
|
360 | - // Abort if not paid by bank transfer. |
|
361 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
362 | - return; |
|
363 | - } |
|
364 | - |
|
365 | - // Is it a parent payment? |
|
366 | - if ( 0 == $invoice->get_parent_id() ) { |
|
367 | - |
|
368 | - // (Maybe) activate subscriptions. |
|
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
370 | - |
|
371 | - if ( ! empty( $subscriptions ) ) { |
|
372 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
373 | - |
|
374 | - foreach ( $subscriptions as $subscription ) { |
|
375 | - if ( $subscription->exists() ) { |
|
376 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
378 | - |
|
379 | - $subscription->set_next_renewal_date( $expiry ); |
|
380 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
382 | - $subscription->activate(); |
|
383 | - } |
|
384 | - } |
|
357 | + */ |
|
358 | + public function invoice_paid( $invoice ) { |
|
359 | + |
|
360 | + // Abort if not paid by bank transfer. |
|
361 | + if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
362 | + return; |
|
363 | + } |
|
364 | + |
|
365 | + // Is it a parent payment? |
|
366 | + if ( 0 == $invoice->get_parent_id() ) { |
|
367 | + |
|
368 | + // (Maybe) activate subscriptions. |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
370 | + |
|
371 | + if ( ! empty( $subscriptions ) ) { |
|
372 | + $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
373 | + |
|
374 | + foreach ( $subscriptions as $subscription ) { |
|
375 | + if ( $subscription->exists() ) { |
|
376 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | + $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
378 | + |
|
379 | + $subscription->set_next_renewal_date( $expiry ); |
|
380 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | + $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
382 | + $subscription->activate(); |
|
383 | + } |
|
384 | + } |
|
385 | 385 | } |
386 | 386 | } else { |
387 | 387 | |
388 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
388 | + $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
389 | 389 | |
390 | - // Renew the subscription. |
|
391 | - if ( $subscription && $subscription->exists() ) { |
|
392 | - $subscription->add_payment( array(), $invoice ); |
|
393 | - $subscription->renew(); |
|
394 | - } |
|
390 | + // Renew the subscription. |
|
391 | + if ( $subscription && $subscription->exists() ) { |
|
392 | + $subscription->add_payment( array(), $invoice ); |
|
393 | + $subscription->renew(); |
|
394 | + } |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Bank transfer Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Direct bank transfer', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Bank transfer', 'invoicing' ); |
|
44 | - $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
|
45 | - $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
|
42 | + $this->title = __('Direct bank transfer', 'invoicing'); |
|
43 | + $this->method_title = __('Bank transfer', 'invoicing'); |
|
44 | + $this->checkout_button_text = __('Proceed', 'invoicing'); |
|
45 | + $this->instructions = apply_filters('wpinv_bank_instructions', $this->get_option('info')); |
|
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action('wpinv_receipt_end', array($this, 'thankyou_page')); |
|
48 | + add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40); |
|
49 | + add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11); |
|
50 | + add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3); |
|
51 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
52 | + add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
62 | 62 | * @return array |
63 | 63 | */ |
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | + public function process_payment($invoice, $submission_data, $submission) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | - $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
|
67 | + $invoice->set_transaction_id($invoice->generate_key('bt_')); |
|
68 | 68 | |
69 | 69 | // Set it as pending payment. |
70 | - if ( ! $invoice->needs_payment() ) { |
|
70 | + if (!$invoice->needs_payment()) { |
|
71 | 71 | $invoice->mark_paid(); |
72 | - } elseif ( ! $invoice->is_paid() ) { |
|
73 | - $invoice->set_status( 'wpi-onhold' ); |
|
72 | + } elseif (!$invoice->is_paid()) { |
|
73 | + $invoice->set_status('wpi-onhold'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Save it. |
77 | 77 | $invoice->save(); |
78 | 78 | |
79 | 79 | // Send to the success page. |
80 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
80 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
@@ -86,17 +86,17 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param WPInv_Invoice $invoice Invoice. |
88 | 88 | */ |
89 | - public function thankyou_page( $invoice ) { |
|
89 | + public function thankyou_page($invoice) { |
|
90 | 90 | |
91 | - if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
91 | + if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
92 | 92 | |
93 | 93 | echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
94 | 94 | |
95 | - if ( ! empty( $this->instructions ) ) { |
|
96 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
|
95 | + if (!empty($this->instructions)) { |
|
96 | + echo wp_kses_post(wpautop(wptexturize($this->instructions))); |
|
97 | 97 | } |
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details($invoice); |
|
100 | 100 | |
101 | 101 | echo '</div>'; |
102 | 102 | |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | * @param string $email_type Email format: plain text or HTML. |
112 | 112 | * @param bool $sent_to_admin Sent to admin. |
113 | 113 | */ |
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
114 | + public function email_instructions($invoice, $email_type, $sent_to_admin) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
117 | 117 | |
118 | 118 | echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ($this->instructions) { |
|
121 | + echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details($invoice); |
|
125 | 125 | |
126 | 126 | echo '</div>'; |
127 | 127 | |
@@ -134,50 +134,50 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param WPInv_Invoice $invoice Invoice. |
136 | 136 | */ |
137 | - protected function bank_details( $invoice ) { |
|
137 | + protected function bank_details($invoice) { |
|
138 | 138 | |
139 | 139 | // Get the invoice country and country $locale. |
140 | 140 | $country = $invoice->get_country(); |
141 | 141 | $locale = $this->get_country_locale(); |
142 | 142 | |
143 | 143 | // Get sortcode label in the $locale array and use appropriate one. |
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
144 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | - 'ac_name' => __( 'Account Name', 'invoicing' ), |
|
148 | - 'ac_no' => __( 'Account Number', 'invoicing' ), |
|
149 | - 'bank_name' => __( 'Bank Name', 'invoicing' ), |
|
150 | - 'ifsc' => __( 'IFSC code', 'invoicing' ), |
|
151 | - 'iban' => __( 'IBAN', 'invoicing' ), |
|
152 | - 'bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
147 | + 'ac_name' => __('Account Name', 'invoicing'), |
|
148 | + 'ac_no' => __('Account Number', 'invoicing'), |
|
149 | + 'bank_name' => __('Bank Name', 'invoicing'), |
|
150 | + 'ifsc' => __('IFSC code', 'invoicing'), |
|
151 | + 'iban' => __('IBAN', 'invoicing'), |
|
152 | + 'bic' => __('BIC/Swift code', 'invoicing'), |
|
153 | 153 | 'sort_code' => $sortcode, |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $bank_info = array(); |
157 | 157 | |
158 | - foreach ( $bank_fields as $field => $label ) { |
|
159 | - $value = $this->get_option( $field ); |
|
158 | + foreach ($bank_fields as $field => $label) { |
|
159 | + $value = $this->get_option($field); |
|
160 | 160 | |
161 | - if ( ! empty( $value ) ) { |
|
162 | - $bank_info[ $field ] = array( |
|
161 | + if (!empty($value)) { |
|
162 | + $bank_info[$field] = array( |
|
163 | 163 | 'label' => $label, |
164 | 164 | 'value' => $value, |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
|
169 | + $bank_info = apply_filters('wpinv_bank_info', $bank_info, $invoice); |
|
170 | 170 | |
171 | - if ( empty( $bank_info ) ) { |
|
171 | + if (empty($bank_info)) { |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'), $invoice)) . '</h3>' . PHP_EOL; |
|
176 | 176 | |
177 | 177 | echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
178 | 178 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
180 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
179 | + foreach ($bank_info as $key => $data) { |
|
180 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr($key) . "'><th class='font-weight-bold'>" . wp_kses_post($data['label']) . "</th><td class='w-75'>" . wp_kses_post(wptexturize($data['value'])) . '</td></tr>' . PHP_EOL; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | echo '</table>'; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function get_country_locale() { |
193 | 193 | |
194 | - if ( empty( $this->locale ) ) { |
|
194 | + if (empty($this->locale)) { |
|
195 | 195 | |
196 | 196 | // Locale information to be used - only those that are not 'Sort Code'. |
197 | 197 | $this->locale = apply_filters( |
@@ -199,42 +199,42 @@ discard block |
||
199 | 199 | array( |
200 | 200 | 'AU' => array( |
201 | 201 | 'sortcode' => array( |
202 | - 'label' => __( 'BSB', 'invoicing' ), |
|
202 | + 'label' => __('BSB', 'invoicing'), |
|
203 | 203 | ), |
204 | 204 | ), |
205 | 205 | 'CA' => array( |
206 | 206 | 'sortcode' => array( |
207 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
207 | + 'label' => __('Bank transit number', 'invoicing'), |
|
208 | 208 | ), |
209 | 209 | ), |
210 | 210 | 'IN' => array( |
211 | 211 | 'sortcode' => array( |
212 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
212 | + 'label' => __('IFSC', 'invoicing'), |
|
213 | 213 | ), |
214 | 214 | ), |
215 | 215 | 'IT' => array( |
216 | 216 | 'sortcode' => array( |
217 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
217 | + 'label' => __('Branch sort', 'invoicing'), |
|
218 | 218 | ), |
219 | 219 | ), |
220 | 220 | 'NZ' => array( |
221 | 221 | 'sortcode' => array( |
222 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
222 | + 'label' => __('Bank code', 'invoicing'), |
|
223 | 223 | ), |
224 | 224 | ), |
225 | 225 | 'SE' => array( |
226 | 226 | 'sortcode' => array( |
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
227 | + 'label' => __('Bank code', 'invoicing'), |
|
228 | 228 | ), |
229 | 229 | ), |
230 | 230 | 'US' => array( |
231 | 231 | 'sortcode' => array( |
232 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
232 | + 'label' => __('Routing number', 'invoicing'), |
|
233 | 233 | ), |
234 | 234 | ), |
235 | 235 | 'ZA' => array( |
236 | 236 | 'sortcode' => array( |
237 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
237 | + 'label' => __('Branch code', 'invoicing'), |
|
238 | 238 | ), |
239 | 239 | ), |
240 | 240 | ) |
@@ -251,51 +251,51 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param array $admin_settings |
253 | 253 | */ |
254 | - public function admin_settings( $admin_settings ) { |
|
254 | + public function admin_settings($admin_settings) { |
|
255 | 255 | |
256 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
257 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
256 | + $admin_settings['bank_transfer_desc']['std'] = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'); |
|
257 | + $admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing'); |
|
258 | 258 | |
259 | - $locale = $this->get_country_locale(); |
|
259 | + $locale = $this->get_country_locale(); |
|
260 | 260 | |
261 | 261 | // Get sortcode label in the $locale array and use appropriate one. |
262 | 262 | $country = wpinv_default_billing_country(); |
263 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
263 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
264 | 264 | |
265 | 265 | $admin_settings['bank_transfer_ac_name'] = array( |
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_name', |
268 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
268 | + 'name' => __('Account Name', 'invoicing'), |
|
269 | 269 | ); |
270 | 270 | |
271 | 271 | $admin_settings['bank_transfer_ac_no'] = array( |
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_ac_no', |
274 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
274 | + 'name' => __('Account Number', 'invoicing'), |
|
275 | 275 | ); |
276 | 276 | |
277 | 277 | $admin_settings['bank_transfer_bank_name'] = array( |
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_bank_name', |
280 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
280 | + 'name' => __('Bank Name', 'invoicing'), |
|
281 | 281 | ); |
282 | 282 | |
283 | 283 | $admin_settings['bank_transfer_ifsc'] = array( |
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_ifsc', |
286 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
286 | + 'name' => __('IFSC Code', 'invoicing'), |
|
287 | 287 | ); |
288 | 288 | |
289 | 289 | $admin_settings['bank_transfer_iban'] = array( |
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_iban', |
292 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
292 | + 'name' => __('IBAN', 'invoicing'), |
|
293 | 293 | ); |
294 | 294 | |
295 | 295 | $admin_settings['bank_transfer_bic'] = array( |
296 | 296 | 'type' => 'text', |
297 | 297 | 'id' => 'bank_transfer_bic', |
298 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
298 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
299 | 299 | ); |
300 | 300 | |
301 | 301 | $admin_settings['bank_transfer_sort_code'] = array( |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | |
307 | 307 | $admin_settings['bank_transfer_info'] = array( |
308 | 308 | 'id' => 'bank_transfer_info', |
309 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
310 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
309 | + 'name' => __('Instructions', 'invoicing'), |
|
310 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
311 | 311 | 'type' => 'textarea', |
312 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
312 | + 'std' => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'), |
|
313 | 313 | 'cols' => 50, |
314 | 314 | 'rows' => 5, |
315 | 315 | ); |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param GetPaid_Form_Item[] $items |
325 | 325 | * @return WPInv_Invoice |
326 | 326 | */ |
327 | - public function process_addons( $invoice, $items ) { |
|
327 | + public function process_addons($invoice, $items) { |
|
328 | 328 | |
329 | - foreach ( $items as $item ) { |
|
330 | - $invoice->add_item( $item ); |
|
329 | + foreach ($items as $item) { |
|
330 | + $invoice->add_item($item); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | $invoice->recalculate_total(); |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | * |
341 | 341 | * @param WPInv_Subscription $subscription |
342 | 342 | */ |
343 | - public function maybe_renew_subscription( $subscription ) { |
|
343 | + public function maybe_renew_subscription($subscription) { |
|
344 | 344 | |
345 | 345 | // Ensure its our subscription && it's active. |
346 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
346 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
347 | 347 | $subscription->create_payment(); |
348 | 348 | } |
349 | 349 | |
@@ -355,41 +355,41 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function invoice_paid( $invoice ) { |
|
358 | + public function invoice_paid($invoice) { |
|
359 | 359 | |
360 | 360 | // Abort if not paid by bank transfer. |
361 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
361 | + if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Is it a parent payment? |
366 | - if ( 0 == $invoice->get_parent_id() ) { |
|
366 | + if (0 == $invoice->get_parent_id()) { |
|
367 | 367 | |
368 | 368 | // (Maybe) activate subscriptions. |
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
370 | 370 | |
371 | - if ( ! empty( $subscriptions ) ) { |
|
372 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
371 | + if (!empty($subscriptions)) { |
|
372 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
373 | 373 | |
374 | - foreach ( $subscriptions as $subscription ) { |
|
375 | - if ( $subscription->exists() ) { |
|
376 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
374 | + foreach ($subscriptions as $subscription) { |
|
375 | + if ($subscription->exists()) { |
|
376 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
377 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
378 | 378 | |
379 | - $subscription->set_next_renewal_date( $expiry ); |
|
380 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
379 | + $subscription->set_next_renewal_date($expiry); |
|
380 | + $subscription->set_date_created(current_time('mysql')); |
|
381 | + $subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id()); |
|
382 | 382 | $subscription->activate(); |
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
386 | 386 | } else { |
387 | 387 | |
388 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
388 | + $subscription = getpaid_get_subscription($invoice->get_subscription_id()); |
|
389 | 389 | |
390 | 390 | // Renew the subscription. |
391 | - if ( $subscription && $subscription->exists() ) { |
|
392 | - $subscription->add_payment( array(), $invoice ); |
|
391 | + if ($subscription && $subscription->exists()) { |
|
392 | + $subscription->add_payment(array(), $invoice); |
|
393 | 393 | $subscription->renew(); |
394 | 394 | } |
395 | 395 | } |
@@ -14,143 +14,143 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
16 | 16 | |
17 | - /** |
|
18 | - * Register the widget with WordPress. |
|
19 | - * |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - |
|
23 | - $options = array( |
|
24 | - 'textdomain' => 'invoicing', |
|
25 | - 'block-icon' => 'controls-repeat', |
|
26 | - 'block-category' => 'widgets', |
|
27 | - 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
28 | - 'class_name' => __CLASS__, |
|
29 | - 'base_id' => 'wpinv_subscriptions', |
|
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | - 'widget_ops' => array( |
|
32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | - ), |
|
35 | - 'arguments' => array( |
|
36 | - 'title' => array( |
|
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | - 'type' => 'text', |
|
40 | - 'desc_tip' => true, |
|
41 | - 'default' => '', |
|
42 | - 'advanced' => false, |
|
43 | - ), |
|
44 | - ), |
|
45 | - |
|
46 | - ); |
|
47 | - |
|
48 | - parent::__construct( $options ); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Retrieves current user's subscriptions. |
|
53 | - * |
|
54 | - * @return GetPaid_Subscriptions_Query |
|
55 | - */ |
|
56 | - public function get_subscriptions() { |
|
57 | - |
|
58 | - // Prepare license args. |
|
59 | - $args = array( |
|
60 | - 'customer_in' => get_current_user_id(), |
|
61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | - ); |
|
63 | - |
|
64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * The Super block output function. |
|
70 | - * |
|
71 | - * @param array $args |
|
72 | - * @param array $widget_args |
|
73 | - * @param string $content |
|
74 | - * |
|
75 | - * @return mixed|string|bool |
|
76 | - */ |
|
77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | - |
|
79 | - // Ensure that the user is logged in. |
|
80 | - if ( ! is_user_logged_in() ) { |
|
81 | - |
|
82 | - return aui()->alert( |
|
83 | - array( |
|
84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | - 'type' => 'error', |
|
86 | - ) |
|
87 | - ); |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - // Are we displaying a single subscription? |
|
92 | - if ( isset( $_GET['subscription'] ) ) { |
|
93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
94 | - } |
|
95 | - |
|
96 | - // Retrieve the user's subscriptions. |
|
97 | - $subscriptions = $this->get_subscriptions(); |
|
98 | - |
|
99 | - // Start the output buffer. |
|
100 | - ob_start(); |
|
101 | - |
|
102 | - // Backwards compatibility. |
|
103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | - |
|
105 | - // Display errors and notices. |
|
106 | - wpinv_print_errors(); |
|
107 | - |
|
108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | - |
|
110 | - // Print the table header. |
|
111 | - $this->print_table_header(); |
|
112 | - |
|
113 | - // Print table body. |
|
114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
115 | - |
|
116 | - // Print table footer. |
|
117 | - $this->print_table_footer(); |
|
118 | - |
|
119 | - // Print the navigation. |
|
120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
121 | - |
|
122 | - // Backwards compatibility. |
|
123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | - |
|
125 | - // Return the output. |
|
126 | - return ob_get_clean(); |
|
127 | - |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Retrieves the subscription columns. |
|
132 | - * |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function get_subscriptions_table_columns() { |
|
17 | + /** |
|
18 | + * Register the widget with WordPress. |
|
19 | + * |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + |
|
23 | + $options = array( |
|
24 | + 'textdomain' => 'invoicing', |
|
25 | + 'block-icon' => 'controls-repeat', |
|
26 | + 'block-category' => 'widgets', |
|
27 | + 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
28 | + 'class_name' => __CLASS__, |
|
29 | + 'base_id' => 'wpinv_subscriptions', |
|
30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | + 'widget_ops' => array( |
|
32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | + ), |
|
35 | + 'arguments' => array( |
|
36 | + 'title' => array( |
|
37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | + 'type' => 'text', |
|
40 | + 'desc_tip' => true, |
|
41 | + 'default' => '', |
|
42 | + 'advanced' => false, |
|
43 | + ), |
|
44 | + ), |
|
45 | + |
|
46 | + ); |
|
47 | + |
|
48 | + parent::__construct( $options ); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Retrieves current user's subscriptions. |
|
53 | + * |
|
54 | + * @return GetPaid_Subscriptions_Query |
|
55 | + */ |
|
56 | + public function get_subscriptions() { |
|
57 | + |
|
58 | + // Prepare license args. |
|
59 | + $args = array( |
|
60 | + 'customer_in' => get_current_user_id(), |
|
61 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | + ); |
|
63 | + |
|
64 | + return new GetPaid_Subscriptions_Query( $args ); |
|
65 | + |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * The Super block output function. |
|
70 | + * |
|
71 | + * @param array $args |
|
72 | + * @param array $widget_args |
|
73 | + * @param string $content |
|
74 | + * |
|
75 | + * @return mixed|string|bool |
|
76 | + */ |
|
77 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | + |
|
79 | + // Ensure that the user is logged in. |
|
80 | + if ( ! is_user_logged_in() ) { |
|
81 | + |
|
82 | + return aui()->alert( |
|
83 | + array( |
|
84 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | + 'type' => 'error', |
|
86 | + ) |
|
87 | + ); |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + // Are we displaying a single subscription? |
|
92 | + if ( isset( $_GET['subscription'] ) ) { |
|
93 | + return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
94 | + } |
|
95 | + |
|
96 | + // Retrieve the user's subscriptions. |
|
97 | + $subscriptions = $this->get_subscriptions(); |
|
98 | + |
|
99 | + // Start the output buffer. |
|
100 | + ob_start(); |
|
101 | + |
|
102 | + // Backwards compatibility. |
|
103 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | + |
|
105 | + // Display errors and notices. |
|
106 | + wpinv_print_errors(); |
|
107 | + |
|
108 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | + |
|
110 | + // Print the table header. |
|
111 | + $this->print_table_header(); |
|
112 | + |
|
113 | + // Print table body. |
|
114 | + $this->print_table_body( $subscriptions->get_results() ); |
|
115 | + |
|
116 | + // Print table footer. |
|
117 | + $this->print_table_footer(); |
|
118 | + |
|
119 | + // Print the navigation. |
|
120 | + $this->print_navigation( $subscriptions->get_total() ); |
|
121 | + |
|
122 | + // Backwards compatibility. |
|
123 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | + |
|
125 | + // Return the output. |
|
126 | + return ob_get_clean(); |
|
127 | + |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Retrieves the subscription columns. |
|
132 | + * |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function get_subscriptions_table_columns() { |
|
136 | 136 | |
137 | - $columns = array( |
|
138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | - 'status' => __( 'Status', 'invoicing' ), |
|
142 | - ); |
|
137 | + $columns = array( |
|
138 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | + 'status' => __( 'Status', 'invoicing' ), |
|
142 | + ); |
|
143 | 143 | |
144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | - } |
|
144 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Displays the table header. |
|
149 | - * |
|
150 | - */ |
|
151 | - public function print_table_header() { |
|
147 | + /** |
|
148 | + * Displays the table header. |
|
149 | + * |
|
150 | + */ |
|
151 | + public function print_table_header() { |
|
152 | 152 | |
153 | - ?> |
|
153 | + ?> |
|
154 | 154 | |
155 | 155 | <table class="table table-bordered table-striped"> |
156 | 156 | |
@@ -166,122 +166,122 @@ discard block |
||
166 | 166 | |
167 | 167 | <?php |
168 | 168 | |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Displays the table body. |
|
173 | - * |
|
174 | - * @param WPInv_Subscription[] $subscriptions |
|
175 | - */ |
|
176 | - public function print_table_body( $subscriptions ) { |
|
171 | + /** |
|
172 | + * Displays the table body. |
|
173 | + * |
|
174 | + * @param WPInv_Subscription[] $subscriptions |
|
175 | + */ |
|
176 | + public function print_table_body( $subscriptions ) { |
|
177 | 177 | |
178 | - if ( empty( $subscriptions ) ) { |
|
179 | - $this->print_table_body_no_subscriptions(); |
|
180 | - } else { |
|
181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | - } |
|
178 | + if ( empty( $subscriptions ) ) { |
|
179 | + $this->print_table_body_no_subscriptions(); |
|
180 | + } else { |
|
181 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | + } |
|
183 | 183 | |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Displays the table body if no subscriptions were found. |
|
188 | - * |
|
189 | - */ |
|
190 | - public function print_table_body_no_subscriptions() { |
|
186 | + /** |
|
187 | + * Displays the table body if no subscriptions were found. |
|
188 | + * |
|
189 | + */ |
|
190 | + public function print_table_body_no_subscriptions() { |
|
191 | 191 | |
192 | - ?> |
|
192 | + ?> |
|
193 | 193 | <tbody> |
194 | 194 | |
195 | 195 | <tr> |
196 | 196 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
197 | 197 | |
198 | 198 | <?php |
199 | - aui()->alert( |
|
200 | - array( |
|
201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | - 'type' => 'warning', |
|
203 | - ), |
|
199 | + aui()->alert( |
|
200 | + array( |
|
201 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | + 'type' => 'warning', |
|
203 | + ), |
|
204 | 204 | true |
205 | - ); |
|
206 | - ?> |
|
205 | + ); |
|
206 | + ?> |
|
207 | 207 | |
208 | 208 | </td> |
209 | 209 | </tr> |
210 | 210 | |
211 | 211 | </tbody> |
212 | 212 | <?php |
213 | - } |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Displays the table body if subscriptions were found. |
|
217 | - * |
|
218 | - * @param WPInv_Subscription[] $subscriptions |
|
219 | - */ |
|
220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
215 | + /** |
|
216 | + * Displays the table body if subscriptions were found. |
|
217 | + * |
|
218 | + * @param WPInv_Subscription[] $subscriptions |
|
219 | + */ |
|
220 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
221 | 221 | |
222 | - ?> |
|
222 | + ?> |
|
223 | 223 | <tbody> |
224 | 224 | |
225 | 225 | <?php foreach ( $subscriptions as $subscription ) : ?> |
226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
227 | 227 | <?php |
228 | - wpinv_get_template( |
|
229 | - 'subscriptions/subscriptions-table-row.php', |
|
230 | - array( |
|
231 | - 'subscription' => $subscription, |
|
232 | - 'widget' => $this, |
|
233 | - ) |
|
234 | - ); |
|
235 | - ?> |
|
228 | + wpinv_get_template( |
|
229 | + 'subscriptions/subscriptions-table-row.php', |
|
230 | + array( |
|
231 | + 'subscription' => $subscription, |
|
232 | + 'widget' => $this, |
|
233 | + ) |
|
234 | + ); |
|
235 | + ?> |
|
236 | 236 | </tr> |
237 | 237 | <?php endforeach; ?> |
238 | 238 | |
239 | 239 | </tbody> |
240 | 240 | <?php |
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Adds row actions to a column |
|
245 | - * |
|
246 | - * @param string $content column content |
|
247 | - * @param WPInv_Subscription $subscription |
|
248 | - * @since 1.0.0 |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function add_row_actions( $content, $subscription ) { |
|
252 | - |
|
253 | - // Prepare row actions. |
|
254 | - $actions = array(); |
|
255 | - |
|
256 | - // View subscription action. |
|
257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
260 | - |
|
261 | - // Filter the actions. |
|
262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
263 | - |
|
264 | - $sanitized = array(); |
|
265 | - foreach ( $actions as $key => $action ) { |
|
266 | - $key = sanitize_html_class( $key ); |
|
267 | - $action = wp_kses_post( $action ); |
|
268 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
269 | - } |
|
270 | - |
|
271 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
273 | - $row_actions .= '</small>'; |
|
274 | - |
|
275 | - return $content . $row_actions; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Displays the table footer. |
|
280 | - * |
|
281 | - */ |
|
282 | - public function print_table_footer() { |
|
283 | - |
|
284 | - ?> |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Adds row actions to a column |
|
245 | + * |
|
246 | + * @param string $content column content |
|
247 | + * @param WPInv_Subscription $subscription |
|
248 | + * @since 1.0.0 |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function add_row_actions( $content, $subscription ) { |
|
252 | + |
|
253 | + // Prepare row actions. |
|
254 | + $actions = array(); |
|
255 | + |
|
256 | + // View subscription action. |
|
257 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
260 | + |
|
261 | + // Filter the actions. |
|
262 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
263 | + |
|
264 | + $sanitized = array(); |
|
265 | + foreach ( $actions as $key => $action ) { |
|
266 | + $key = sanitize_html_class( $key ); |
|
267 | + $action = wp_kses_post( $action ); |
|
268 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
269 | + } |
|
270 | + |
|
271 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
272 | + $row_actions .= implode( ' | ', $sanitized ); |
|
273 | + $row_actions .= '</small>'; |
|
274 | + |
|
275 | + return $content . $row_actions; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Displays the table footer. |
|
280 | + * |
|
281 | + */ |
|
282 | + public function print_table_footer() { |
|
283 | + |
|
284 | + ?> |
|
285 | 285 | |
286 | 286 | <tfoot> |
287 | 287 | <tr> |
@@ -296,145 +296,145 @@ discard block |
||
296 | 296 | </table> |
297 | 297 | <?php |
298 | 298 | |
299 | - } |
|
299 | + } |
|
300 | 300 | |
301 | - /** |
|
302 | - * Displays the navigation. |
|
303 | - * |
|
304 | - * @param int $total |
|
305 | - */ |
|
306 | - public function print_navigation( $total ) { |
|
301 | + /** |
|
302 | + * Displays the navigation. |
|
303 | + * |
|
304 | + * @param int $total |
|
305 | + */ |
|
306 | + public function print_navigation( $total ) { |
|
307 | 307 | |
308 | - if ( $total < 1 ) { |
|
308 | + if ( $total < 1 ) { |
|
309 | 309 | |
310 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
311 | - $args = array( |
|
312 | - 'customer_in' => get_current_user_id(), |
|
313 | - 'fields' => 'id', |
|
314 | - ); |
|
310 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
311 | + $args = array( |
|
312 | + 'customer_in' => get_current_user_id(), |
|
313 | + 'fields' => 'id', |
|
314 | + ); |
|
315 | 315 | |
316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
317 | - $total = $count_query->get_total(); |
|
318 | - } |
|
316 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
317 | + $total = $count_query->get_total(); |
|
318 | + } |
|
319 | 319 | |
320 | - // Abort if we do not have pages. |
|
321 | - if ( 2 > $total ) { |
|
322 | - return; |
|
323 | - } |
|
320 | + // Abort if we do not have pages. |
|
321 | + if ( 2 > $total ) { |
|
322 | + return; |
|
323 | + } |
|
324 | 324 | |
325 | - ?> |
|
325 | + ?> |
|
326 | 326 | |
327 | 327 | <div class="getpaid-subscriptions-pagination"> |
328 | 328 | <?php |
329 | - $big = 999999; |
|
330 | - |
|
331 | - echo wp_kses_post( |
|
332 | - getpaid_paginate_links( |
|
333 | - array( |
|
334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
335 | - 'format' => '?paged=%#%', |
|
336 | - 'total' => (int) ceil( $total / 10 ), |
|
337 | - ) |
|
338 | - ) |
|
339 | - ); |
|
340 | - ?> |
|
329 | + $big = 999999; |
|
330 | + |
|
331 | + echo wp_kses_post( |
|
332 | + getpaid_paginate_links( |
|
333 | + array( |
|
334 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
335 | + 'format' => '?paged=%#%', |
|
336 | + 'total' => (int) ceil( $total / 10 ), |
|
337 | + ) |
|
338 | + ) |
|
339 | + ); |
|
340 | + ?> |
|
341 | 341 | </div> |
342 | 342 | |
343 | 343 | <?php |
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Returns a single subscription's columns. |
|
348 | - * |
|
349 | - * @param WPInv_Subscription $subscription |
|
350 | - * |
|
351 | - * @return array |
|
352 | - */ |
|
353 | - public function get_single_subscription_columns( $subscription ) { |
|
354 | - |
|
355 | - // Prepare subscription detail columns. |
|
356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
358 | - $fields = apply_filters( |
|
359 | - 'getpaid_single_subscription_details_fields', |
|
360 | - array( |
|
361 | - 'status' => __( 'Status', 'invoicing' ), |
|
362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
367 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
368 | - ), |
|
369 | - $subscription, |
|
370 | - $items_count |
|
371 | - ); |
|
372 | - |
|
373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
374 | - |
|
375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
377 | - } |
|
378 | - |
|
379 | - if ( 'pending' === $subscription->get_status() ) { |
|
380 | - unset( $fields['expiry_date'] ); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
385 | - unset( $fields['start_date'] ); |
|
386 | - } |
|
387 | - |
|
388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
389 | - unset( $fields['initial_amount'] ); |
|
390 | - } |
|
391 | - |
|
392 | - return $fields; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Displays a single subscription. |
|
397 | - * |
|
398 | - * @param string $subscription |
|
399 | - * |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function display_single_subscription( $subscription ) { |
|
403 | - |
|
404 | - // Fetch the subscription. |
|
405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
406 | - |
|
407 | - if ( ! $subscription->exists() ) { |
|
408 | - |
|
409 | - return aui()->alert( |
|
410 | - array( |
|
411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
412 | - 'type' => 'error', |
|
413 | - ) |
|
414 | - ); |
|
415 | - |
|
416 | - } |
|
417 | - |
|
418 | - // Ensure that the user owns this subscription key. |
|
419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
420 | - |
|
421 | - return aui()->alert( |
|
422 | - array( |
|
423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
424 | - 'type' => 'error', |
|
425 | - ) |
|
426 | - ); |
|
427 | - |
|
428 | - } |
|
429 | - |
|
430 | - return wpinv_get_template_html( |
|
431 | - 'subscriptions/subscription-details.php', |
|
432 | - array( |
|
433 | - 'subscription' => $subscription, |
|
434 | - 'widget' => $this, |
|
435 | - ) |
|
436 | - ); |
|
437 | - |
|
438 | - } |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Returns a single subscription's columns. |
|
348 | + * |
|
349 | + * @param WPInv_Subscription $subscription |
|
350 | + * |
|
351 | + * @return array |
|
352 | + */ |
|
353 | + public function get_single_subscription_columns( $subscription ) { |
|
354 | + |
|
355 | + // Prepare subscription detail columns. |
|
356 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
357 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
358 | + $fields = apply_filters( |
|
359 | + 'getpaid_single_subscription_details_fields', |
|
360 | + array( |
|
361 | + 'status' => __( 'Status', 'invoicing' ), |
|
362 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
363 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
364 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
365 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
366 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
367 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
368 | + ), |
|
369 | + $subscription, |
|
370 | + $items_count |
|
371 | + ); |
|
372 | + |
|
373 | + if ( isset( $fields['expiry_date'] ) ) { |
|
374 | + |
|
375 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
376 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
377 | + } |
|
378 | + |
|
379 | + if ( 'pending' === $subscription->get_status() ) { |
|
380 | + unset( $fields['expiry_date'] ); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
385 | + unset( $fields['start_date'] ); |
|
386 | + } |
|
387 | + |
|
388 | + if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
389 | + unset( $fields['initial_amount'] ); |
|
390 | + } |
|
391 | + |
|
392 | + return $fields; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Displays a single subscription. |
|
397 | + * |
|
398 | + * @param string $subscription |
|
399 | + * |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function display_single_subscription( $subscription ) { |
|
403 | + |
|
404 | + // Fetch the subscription. |
|
405 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
406 | + |
|
407 | + if ( ! $subscription->exists() ) { |
|
408 | + |
|
409 | + return aui()->alert( |
|
410 | + array( |
|
411 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
412 | + 'type' => 'error', |
|
413 | + ) |
|
414 | + ); |
|
415 | + |
|
416 | + } |
|
417 | + |
|
418 | + // Ensure that the user owns this subscription key. |
|
419 | + if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
420 | + |
|
421 | + return aui()->alert( |
|
422 | + array( |
|
423 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
424 | + 'type' => 'error', |
|
425 | + ) |
|
426 | + ); |
|
427 | + |
|
428 | + } |
|
429 | + |
|
430 | + return wpinv_get_template_html( |
|
431 | + 'subscriptions/subscription-details.php', |
|
432 | + array( |
|
433 | + 'subscription' => $subscription, |
|
434 | + 'widget' => $this, |
|
435 | + ) |
|
436 | + ); |
|
437 | + |
|
438 | + } |
|
439 | 439 | |
440 | 440 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.0 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Contains the subscriptions widget. |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
28 | 28 | 'class_name' => __CLASS__, |
29 | 29 | 'base_id' => 'wpinv_subscriptions', |
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
30 | + 'name' => __('GetPaid > Subscriptions', 'invoicing'), |
|
31 | 31 | 'widget_ops' => array( |
32 | 32 | 'classname' => 'getpaid-subscriptions bsui', |
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
33 | + 'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'), |
|
34 | 34 | ), |
35 | 35 | 'arguments' => array( |
36 | 36 | 'title' => array( |
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
37 | + 'title' => __('Widget title', 'invoicing'), |
|
38 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
39 | 39 | 'type' => 'text', |
40 | 40 | 'desc_tip' => true, |
41 | 41 | 'default' => '', |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | ); |
47 | 47 | |
48 | - parent::__construct( $options ); |
|
48 | + parent::__construct($options); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | public function get_subscriptions() { |
57 | 57 | |
58 | 58 | // Prepare license args. |
59 | - $args = array( |
|
59 | + $args = array( |
|
60 | 60 | 'customer_in' => get_current_user_id(), |
61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
61 | + 'paged' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
62 | 62 | ); |
63 | 63 | |
64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
64 | + return new GetPaid_Subscriptions_Query($args); |
|
65 | 65 | |
66 | 66 | } |
67 | 67 | |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return mixed|string|bool |
76 | 76 | */ |
77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
77 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
78 | 78 | |
79 | 79 | // Ensure that the user is logged in. |
80 | - if ( ! is_user_logged_in() ) { |
|
80 | + if (!is_user_logged_in()) { |
|
81 | 81 | |
82 | 82 | return aui()->alert( |
83 | 83 | array( |
84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
84 | + 'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')), |
|
85 | 85 | 'type' => 'error', |
86 | 86 | ) |
87 | 87 | ); |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | // Are we displaying a single subscription? |
92 | - if ( isset( $_GET['subscription'] ) ) { |
|
93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
92 | + if (isset($_GET['subscription'])) { |
|
93 | + return $this->display_single_subscription(intval($_GET['subscription'])); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | // Retrieve the user's subscriptions. |
@@ -100,27 +100,27 @@ discard block |
||
100 | 100 | ob_start(); |
101 | 101 | |
102 | 102 | // Backwards compatibility. |
103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
103 | + do_action('wpinv_before_user_subscriptions'); |
|
104 | 104 | |
105 | 105 | // Display errors and notices. |
106 | 106 | wpinv_print_errors(); |
107 | 107 | |
108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
108 | + do_action('getpaid_license_manager_before_subscriptions', $subscriptions); |
|
109 | 109 | |
110 | 110 | // Print the table header. |
111 | 111 | $this->print_table_header(); |
112 | 112 | |
113 | 113 | // Print table body. |
114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
114 | + $this->print_table_body($subscriptions->get_results()); |
|
115 | 115 | |
116 | 116 | // Print table footer. |
117 | 117 | $this->print_table_footer(); |
118 | 118 | |
119 | 119 | // Print the navigation. |
120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
120 | + $this->print_navigation($subscriptions->get_total()); |
|
121 | 121 | |
122 | 122 | // Backwards compatibility. |
123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
123 | + do_action('wpinv_after_user_subscriptions'); |
|
124 | 124 | |
125 | 125 | // Return the output. |
126 | 126 | return ob_get_clean(); |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | public function get_subscriptions_table_columns() { |
136 | 136 | |
137 | 137 | $columns = array( |
138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | - 'status' => __( 'Status', 'invoicing' ), |
|
138 | + 'subscription' => __('Subscription', 'invoicing'), |
|
139 | + 'amount' => __('Amount', 'invoicing'), |
|
140 | + 'renewal-date' => __('Next payment', 'invoicing'), |
|
141 | + 'status' => __('Status', 'invoicing'), |
|
142 | 142 | ); |
143 | 143 | |
144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
144 | + return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | |
157 | 157 | <thead> |
158 | 158 | <tr> |
159 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
160 | - <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr( $key ); ?>"> |
|
161 | - <?php echo esc_html( $label ); ?> |
|
159 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
160 | + <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr($key); ?>"> |
|
161 | + <?php echo esc_html($label); ?> |
|
162 | 162 | </th> |
163 | 163 | <?php endforeach; ?> |
164 | 164 | </tr> |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @param WPInv_Subscription[] $subscriptions |
175 | 175 | */ |
176 | - public function print_table_body( $subscriptions ) { |
|
176 | + public function print_table_body($subscriptions) { |
|
177 | 177 | |
178 | - if ( empty( $subscriptions ) ) { |
|
178 | + if (empty($subscriptions)) { |
|
179 | 179 | $this->print_table_body_no_subscriptions(); |
180 | 180 | } else { |
181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
181 | + $this->print_table_body_subscriptions($subscriptions); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | } |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | <tbody> |
194 | 194 | |
195 | 195 | <tr> |
196 | - <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
|
196 | + <td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>"> |
|
197 | 197 | |
198 | 198 | <?php |
199 | 199 | aui()->alert( |
200 | 200 | array( |
201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
201 | + 'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')), |
|
202 | 202 | 'type' => 'warning', |
203 | 203 | ), |
204 | 204 | true |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @param WPInv_Subscription[] $subscriptions |
219 | 219 | */ |
220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
220 | + public function print_table_body_subscriptions($subscriptions) { |
|
221 | 221 | |
222 | 222 | ?> |
223 | 223 | <tbody> |
224 | 224 | |
225 | - <?php foreach ( $subscriptions as $subscription ) : ?> |
|
225 | + <?php foreach ($subscriptions as $subscription) : ?> |
|
226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
227 | 227 | <?php |
228 | 228 | wpinv_get_template( |
@@ -248,28 +248,28 @@ discard block |
||
248 | 248 | * @since 1.0.0 |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function add_row_actions( $content, $subscription ) { |
|
251 | + public function add_row_actions($content, $subscription) { |
|
252 | 252 | |
253 | 253 | // Prepare row actions. |
254 | 254 | $actions = array(); |
255 | 255 | |
256 | 256 | // View subscription action. |
257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
257 | + $view_url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
258 | + $view_url = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), $view_url)); |
|
259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
260 | 260 | |
261 | 261 | // Filter the actions. |
262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
262 | + $actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription); |
|
263 | 263 | |
264 | - $sanitized = array(); |
|
265 | - foreach ( $actions as $key => $action ) { |
|
266 | - $key = sanitize_html_class( $key ); |
|
267 | - $action = wp_kses_post( $action ); |
|
264 | + $sanitized = array(); |
|
265 | + foreach ($actions as $key => $action) { |
|
266 | + $key = sanitize_html_class($key); |
|
267 | + $action = wp_kses_post($action); |
|
268 | 268 | $sanitized[] = "<span class='$key'>$action</span>"; |
269 | 269 | } |
270 | 270 | |
271 | 271 | $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
272 | + $row_actions .= implode(' | ', $sanitized); |
|
273 | 273 | $row_actions .= '</small>'; |
274 | 274 | |
275 | 275 | return $content . $row_actions; |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | |
286 | 286 | <tfoot> |
287 | 287 | <tr> |
288 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
289 | - <th class="font-weight-bold getpaid-subscriptions-<?php echo esc_attr( $key ); ?>"> |
|
290 | - <?php echo esc_html( $label ); ?> |
|
288 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
289 | + <th class="font-weight-bold getpaid-subscriptions-<?php echo esc_attr($key); ?>"> |
|
290 | + <?php echo esc_html($label); ?> |
|
291 | 291 | </th> |
292 | 292 | <?php endforeach; ?> |
293 | 293 | </tr> |
@@ -303,22 +303,22 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @param int $total |
305 | 305 | */ |
306 | - public function print_navigation( $total ) { |
|
306 | + public function print_navigation($total) { |
|
307 | 307 | |
308 | - if ( $total < 1 ) { |
|
308 | + if ($total < 1) { |
|
309 | 309 | |
310 | 310 | // Out-of-bounds, run the query again without LIMIT for total count. |
311 | - $args = array( |
|
311 | + $args = array( |
|
312 | 312 | 'customer_in' => get_current_user_id(), |
313 | 313 | 'fields' => 'id', |
314 | 314 | ); |
315 | 315 | |
316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
316 | + $count_query = new GetPaid_Subscriptions_Query($args); |
|
317 | 317 | $total = $count_query->get_total(); |
318 | 318 | } |
319 | 319 | |
320 | 320 | // Abort if we do not have pages. |
321 | - if ( 2 > $total ) { |
|
321 | + if (2 > $total) { |
|
322 | 322 | return; |
323 | 323 | } |
324 | 324 | |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | echo wp_kses_post( |
332 | 332 | getpaid_paginate_links( |
333 | 333 | array( |
334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
334 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
335 | 335 | 'format' => '?paged=%#%', |
336 | - 'total' => (int) ceil( $total / 10 ), |
|
336 | + 'total' => (int) ceil($total / 10), |
|
337 | 337 | ) |
338 | 338 | ) |
339 | 339 | ); |
@@ -350,43 +350,43 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @return array |
352 | 352 | */ |
353 | - public function get_single_subscription_columns( $subscription ) { |
|
353 | + public function get_single_subscription_columns($subscription) { |
|
354 | 354 | |
355 | 355 | // Prepare subscription detail columns. |
356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
356 | + $subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
357 | + $items_count = empty($subscription_group) ? 1 : count($subscription_group['items']); |
|
358 | 358 | $fields = apply_filters( |
359 | 359 | 'getpaid_single_subscription_details_fields', |
360 | 360 | array( |
361 | - 'status' => __( 'Status', 'invoicing' ), |
|
362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
367 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
361 | + 'status' => __('Status', 'invoicing'), |
|
362 | + 'initial_amount' => __('Initial amount', 'invoicing'), |
|
363 | + 'recurring_amount' => __('Recurring amount', 'invoicing'), |
|
364 | + 'start_date' => __('Start date', 'invoicing'), |
|
365 | + 'expiry_date' => __('Next payment', 'invoicing'), |
|
366 | + 'payments' => __('Payments', 'invoicing'), |
|
367 | + 'item' => _n('Item', 'Items', $items_count, 'invoicing'), |
|
368 | 368 | ), |
369 | 369 | $subscription, |
370 | 370 | $items_count |
371 | 371 | ); |
372 | 372 | |
373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
373 | + if (isset($fields['expiry_date'])) { |
|
374 | 374 | |
375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
375 | + if (!$subscription->is_active() || $subscription->is_last_renewal()) { |
|
376 | + $fields['expiry_date'] = __('End date', 'invoicing'); |
|
377 | 377 | } |
378 | 378 | |
379 | - if ( 'pending' === $subscription->get_status() ) { |
|
380 | - unset( $fields['expiry_date'] ); |
|
379 | + if ('pending' === $subscription->get_status()) { |
|
380 | + unset($fields['expiry_date']); |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
385 | - unset( $fields['start_date'] ); |
|
384 | + if (isset($fields['start_date']) && 'pending' === $subscription->get_status()) { |
|
385 | + unset($fields['start_date']); |
|
386 | 386 | } |
387 | 387 | |
388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
389 | - unset( $fields['initial_amount'] ); |
|
388 | + if ($subscription->get_initial_amount() === $subscription->get_recurring_amount()) { |
|
389 | + unset($fields['initial_amount']); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return $fields; |
@@ -399,16 +399,16 @@ discard block |
||
399 | 399 | * |
400 | 400 | * @return string |
401 | 401 | */ |
402 | - public function display_single_subscription( $subscription ) { |
|
402 | + public function display_single_subscription($subscription) { |
|
403 | 403 | |
404 | 404 | // Fetch the subscription. |
405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
405 | + $subscription = new WPInv_Subscription((int) $subscription); |
|
406 | 406 | |
407 | - if ( ! $subscription->exists() ) { |
|
407 | + if (!$subscription->exists()) { |
|
408 | 408 | |
409 | 409 | return aui()->alert( |
410 | 410 | array( |
411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
411 | + 'content' => wp_kses_post(__('Subscription not found.', 'invoicing')), |
|
412 | 412 | 'type' => 'error', |
413 | 413 | ) |
414 | 414 | ); |
@@ -416,11 +416,11 @@ discard block |
||
416 | 416 | } |
417 | 417 | |
418 | 418 | // Ensure that the user owns this subscription key. |
419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
419 | + if (get_current_user_id() != $subscription->get_customer_id() && !wpinv_current_user_can_manage_invoicing()) { |
|
420 | 420 | |
421 | 421 | return aui()->alert( |
422 | 422 | array( |
423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
423 | + 'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')), |
|
424 | 424 | 'type' => 'error', |
425 | 425 | ) |
426 | 426 | ); |
@@ -12,489 +12,489 @@ |
||
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 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
52 | - |
|
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
129 | - $merge_tags = array( |
|
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | - ); |
|
149 | - |
|
150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | - |
|
152 | - if ( is_array( $payment_form_data ) ) { |
|
153 | - |
|
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
155 | - |
|
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | - |
|
159 | - if ( is_scalar( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | - } |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Helper function to send an email. |
|
170 | - * |
|
171 | - * @param WPInv_Invoice $invoice |
|
172 | - * @param GetPaid_Notification_Email $email |
|
173 | - * @param string $type |
|
174 | - * @param string|array $recipients |
|
175 | - * @param array $extra_args Extra template args. |
|
176 | - */ |
|
177 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
178 | - |
|
179 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
180 | - |
|
181 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
182 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | - return; |
|
184 | - } |
|
185 | - |
|
186 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
187 | - $merge_tags = $email->get_merge_tags(); |
|
188 | - |
|
189 | - $result = $mailer->send( |
|
190 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
191 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
192 | - $email->get_content( $merge_tags, $extra_args ), |
|
193 | - $email->get_attachments() |
|
194 | - ); |
|
195 | - |
|
196 | - // Maybe send a copy to the admin. |
|
197 | - if ( $email->include_admin_bcc() ) { |
|
198 | - $mailer->send( |
|
199 | - wpinv_get_admin_email(), |
|
200 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
201 | - $email->get_content( $merge_tags ), |
|
202 | - $email->get_attachments() |
|
203 | - ); |
|
204 | - } |
|
205 | - |
|
206 | - if ( $result ) { |
|
207 | - $invoice->add_system_note( |
|
208 | - sprintf( |
|
209 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
210 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
211 | - sanitize_key( $type ), |
|
212 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
213 | - ) |
|
214 | - ); |
|
215 | - } else { |
|
216 | - $invoice->add_system_note( |
|
217 | - sprintf( |
|
218 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
219 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - |
|
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | - |
|
228 | - return $result; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Also send emails to any cc users. |
|
233 | - * |
|
234 | - * @param array $recipients |
|
235 | - * @param GetPaid_Notification_Email $email |
|
236 | - */ |
|
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
238 | - |
|
239 | - if ( ! $email->is_admin_email() ) { |
|
240 | - $cc = $email->object->get_email_cc(); |
|
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | - |
|
243 | - if ( ! empty( $cc ) ) { |
|
244 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | - } |
|
247 | - |
|
248 | - if ( ! empty( $cc_2 ) ) { |
|
249 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - return $recipients; |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Sends a new invoice notification. |
|
260 | - * |
|
261 | - * @param WPInv_Invoice $invoice |
|
262 | - */ |
|
263 | - public function new_invoice( $invoice ) { |
|
264 | - |
|
265 | - // Only send this email for invoices created via the admin page. |
|
266 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
267 | - return; |
|
268 | - } |
|
269 | - |
|
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | - $recipient = wpinv_get_admin_email(); |
|
272 | - |
|
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | - |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Sends a cancelled invoice notification. |
|
279 | - * |
|
280 | - * @param WPInv_Invoice $invoice |
|
281 | - */ |
|
282 | - public function cancelled_invoice( $invoice ) { |
|
283 | - |
|
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | - $recipient = $invoice->get_email(); |
|
286 | - |
|
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Sends a failed invoice notification. |
|
292 | - * |
|
293 | - * @param WPInv_Invoice $invoice |
|
294 | - */ |
|
295 | - public function failed_invoice( $invoice ) { |
|
296 | - |
|
297 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
298 | - $recipient = wpinv_get_admin_email(); |
|
299 | - |
|
300 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
301 | - |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Sends a notification whenever an invoice is put on hold. |
|
306 | - * |
|
307 | - * @param WPInv_Invoice $invoice |
|
308 | - */ |
|
309 | - public function onhold_invoice( $invoice ) { |
|
310 | - |
|
311 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
312 | - $recipient = $invoice->get_email(); |
|
313 | - |
|
314 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
315 | - |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
320 | - * |
|
321 | - * @param WPInv_Invoice $invoice |
|
322 | - */ |
|
323 | - public function processing_invoice( $invoice ) { |
|
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 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
52 | + |
|
53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
129 | + $merge_tags = array( |
|
130 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | + '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | + '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
141 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | + '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | + ); |
|
149 | + |
|
150 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | + |
|
152 | + if ( is_array( $payment_form_data ) ) { |
|
324 | 153 | |
325 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
326 | - $recipient = $invoice->get_email(); |
|
327 | - |
|
328 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
329 | - |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Sends a notification whenever an invoice is paid. |
|
334 | - * |
|
335 | - * @param WPInv_Invoice $invoice |
|
336 | - */ |
|
337 | - public function completed_invoice( $invoice ) { |
|
154 | + foreach ( $payment_form_data as $label => $value ) { |
|
338 | 155 | |
339 | - // (Maybe) abort if it is a renewal invoice. |
|
340 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
341 | - return; |
|
342 | - } |
|
343 | - |
|
344 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
345 | - $recipient = $invoice->get_email(); |
|
156 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
346 | 158 | |
347 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
159 | + if ( is_scalar( $value ) ) { |
|
160 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + } |
|
162 | + } |
|
163 | + } |
|
348 | 164 | |
349 | - } |
|
165 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
166 | + } |
|
350 | 167 | |
351 | - /** |
|
352 | - * Sends a notification whenever an invoice is refunded. |
|
353 | - * |
|
354 | - * @param WPInv_Invoice $invoice |
|
355 | - */ |
|
356 | - public function refunded_invoice( $invoice ) { |
|
168 | + /** |
|
169 | + * Helper function to send an email. |
|
170 | + * |
|
171 | + * @param WPInv_Invoice $invoice |
|
172 | + * @param GetPaid_Notification_Email $email |
|
173 | + * @param string $type |
|
174 | + * @param string|array $recipients |
|
175 | + * @param array $extra_args Extra template args. |
|
176 | + */ |
|
177 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
357 | 178 | |
358 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
359 | - $recipient = $invoice->get_email(); |
|
360 | - |
|
361 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
179 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
180 | + |
|
181 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
182 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | + return; |
|
184 | + } |
|
185 | + |
|
186 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
187 | + $merge_tags = $email->get_merge_tags(); |
|
188 | + |
|
189 | + $result = $mailer->send( |
|
190 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
191 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
192 | + $email->get_content( $merge_tags, $extra_args ), |
|
193 | + $email->get_attachments() |
|
194 | + ); |
|
362 | 195 | |
363 | - } |
|
196 | + // Maybe send a copy to the admin. |
|
197 | + if ( $email->include_admin_bcc() ) { |
|
198 | + $mailer->send( |
|
199 | + wpinv_get_admin_email(), |
|
200 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
201 | + $email->get_content( $merge_tags ), |
|
202 | + $email->get_attachments() |
|
203 | + ); |
|
204 | + } |
|
205 | + |
|
206 | + if ( $result ) { |
|
207 | + $invoice->add_system_note( |
|
208 | + sprintf( |
|
209 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
210 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
211 | + sanitize_key( $type ), |
|
212 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
213 | + ) |
|
214 | + ); |
|
215 | + } else { |
|
216 | + $invoice->add_system_note( |
|
217 | + sprintf( |
|
218 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
219 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
220 | + sanitize_key( $type ), |
|
221 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + |
|
226 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | + |
|
228 | + return $result; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Also send emails to any cc users. |
|
233 | + * |
|
234 | + * @param array $recipients |
|
235 | + * @param GetPaid_Notification_Email $email |
|
236 | + */ |
|
237 | + public function filter_email_recipients( $recipients, $email ) { |
|
238 | + |
|
239 | + if ( ! $email->is_admin_email() ) { |
|
240 | + $cc = $email->object->get_email_cc(); |
|
241 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | + |
|
243 | + if ( ! empty( $cc ) ) { |
|
244 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | + } |
|
247 | + |
|
248 | + if ( ! empty( $cc_2 ) ) { |
|
249 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + return $recipients; |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Sends a new invoice notification. |
|
260 | + * |
|
261 | + * @param WPInv_Invoice $invoice |
|
262 | + */ |
|
263 | + public function new_invoice( $invoice ) { |
|
264 | + |
|
265 | + // Only send this email for invoices created via the admin page. |
|
266 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
267 | + return; |
|
268 | + } |
|
269 | + |
|
270 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $recipient = wpinv_get_admin_email(); |
|
272 | + |
|
273 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | + |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Sends a cancelled invoice notification. |
|
279 | + * |
|
280 | + * @param WPInv_Invoice $invoice |
|
281 | + */ |
|
282 | + public function cancelled_invoice( $invoice ) { |
|
283 | + |
|
284 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $recipient = $invoice->get_email(); |
|
286 | + |
|
287 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Sends a failed invoice notification. |
|
292 | + * |
|
293 | + * @param WPInv_Invoice $invoice |
|
294 | + */ |
|
295 | + public function failed_invoice( $invoice ) { |
|
296 | + |
|
297 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
298 | + $recipient = wpinv_get_admin_email(); |
|
299 | + |
|
300 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
301 | + |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Sends a notification whenever an invoice is put on hold. |
|
306 | + * |
|
307 | + * @param WPInv_Invoice $invoice |
|
308 | + */ |
|
309 | + public function onhold_invoice( $invoice ) { |
|
310 | + |
|
311 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
312 | + $recipient = $invoice->get_email(); |
|
313 | + |
|
314 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
315 | + |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
320 | + * |
|
321 | + * @param WPInv_Invoice $invoice |
|
322 | + */ |
|
323 | + public function processing_invoice( $invoice ) { |
|
364 | 324 | |
365 | - /** |
|
366 | - * Notifies a user about new invoices |
|
367 | - * |
|
368 | - * @param WPInv_Invoice $invoice |
|
369 | - * @param bool $force |
|
370 | - */ |
|
371 | - public function user_invoice( $invoice, $force = false ) { |
|
325 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
326 | + $recipient = $invoice->get_email(); |
|
327 | + |
|
328 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
329 | + |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Sends a notification whenever an invoice is paid. |
|
334 | + * |
|
335 | + * @param WPInv_Invoice $invoice |
|
336 | + */ |
|
337 | + public function completed_invoice( $invoice ) { |
|
372 | 338 | |
373 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
374 | - return; |
|
375 | - } |
|
376 | - |
|
377 | - // Only send this email for invoices created via the admin page. |
|
378 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
379 | - return; |
|
380 | - } |
|
339 | + // (Maybe) abort if it is a renewal invoice. |
|
340 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
341 | + return; |
|
342 | + } |
|
343 | + |
|
344 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
345 | + $recipient = $invoice->get_email(); |
|
381 | 346 | |
382 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
383 | - $recipient = $invoice->get_email(); |
|
384 | - |
|
385 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
347 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
386 | 348 | |
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Checks if an invoice is a payment form invoice. |
|
391 | - * |
|
392 | - * @param int $invoice |
|
393 | - * @return bool |
|
394 | - */ |
|
395 | - public function is_payment_form_invoice( $invoice ) { |
|
396 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
397 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
398 | - } |
|
349 | + } |
|
399 | 350 | |
400 | - /** |
|
401 | - * Notifies admin about new invoice notes |
|
402 | - * |
|
403 | - * @param WPInv_Invoice $invoice |
|
404 | - * @param string $note |
|
405 | - */ |
|
406 | - public function user_note( $invoice, $note ) { |
|
407 | - |
|
408 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
409 | - $recipient = $invoice->get_email(); |
|
351 | + /** |
|
352 | + * Sends a notification whenever an invoice is refunded. |
|
353 | + * |
|
354 | + * @param WPInv_Invoice $invoice |
|
355 | + */ |
|
356 | + public function refunded_invoice( $invoice ) { |
|
410 | 357 | |
411 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
412 | - |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * (Force) Sends overdue notices. |
|
417 | - * |
|
418 | - * @param WPInv_Invoice $invoice |
|
419 | - */ |
|
420 | - public function force_send_overdue_notice( $invoice ) { |
|
421 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
422 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Sends overdue notices. |
|
427 | - * |
|
428 | - * @TODO: Create an invoices query class. |
|
429 | - */ |
|
430 | - public function overdue() { |
|
431 | - global $wpdb; |
|
432 | - |
|
433 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
434 | - |
|
435 | - // Fetch reminder days. |
|
436 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
437 | - |
|
438 | - // Abort if non is set. |
|
439 | - if ( empty( $reminder_days ) ) { |
|
440 | - return; |
|
441 | - } |
|
442 | - |
|
443 | - // Retrieve date query. |
|
444 | - $date_query = $this->get_date_query( $reminder_days ); |
|
445 | - |
|
446 | - // Invoices table. |
|
447 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
448 | - |
|
449 | - // Fetch invoices. |
|
450 | - $invoices = $wpdb->get_col( |
|
451 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
358 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
359 | + $recipient = $invoice->get_email(); |
|
360 | + |
|
361 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Notifies a user about new invoices |
|
367 | + * |
|
368 | + * @param WPInv_Invoice $invoice |
|
369 | + * @param bool $force |
|
370 | + */ |
|
371 | + public function user_invoice( $invoice, $force = false ) { |
|
372 | + |
|
373 | + if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
374 | + return; |
|
375 | + } |
|
376 | + |
|
377 | + // Only send this email for invoices created via the admin page. |
|
378 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
379 | + return; |
|
380 | + } |
|
381 | + |
|
382 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
383 | + $recipient = $invoice->get_email(); |
|
384 | + |
|
385 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Checks if an invoice is a payment form invoice. |
|
391 | + * |
|
392 | + * @param int $invoice |
|
393 | + * @return bool |
|
394 | + */ |
|
395 | + public function is_payment_form_invoice( $invoice ) { |
|
396 | + $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
397 | + return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Notifies admin about new invoice notes |
|
402 | + * |
|
403 | + * @param WPInv_Invoice $invoice |
|
404 | + * @param string $note |
|
405 | + */ |
|
406 | + public function user_note( $invoice, $note ) { |
|
407 | + |
|
408 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
409 | + $recipient = $invoice->get_email(); |
|
410 | + |
|
411 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
412 | + |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * (Force) Sends overdue notices. |
|
417 | + * |
|
418 | + * @param WPInv_Invoice $invoice |
|
419 | + */ |
|
420 | + public function force_send_overdue_notice( $invoice ) { |
|
421 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
422 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Sends overdue notices. |
|
427 | + * |
|
428 | + * @TODO: Create an invoices query class. |
|
429 | + */ |
|
430 | + public function overdue() { |
|
431 | + global $wpdb; |
|
432 | + |
|
433 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
434 | + |
|
435 | + // Fetch reminder days. |
|
436 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
437 | + |
|
438 | + // Abort if non is set. |
|
439 | + if ( empty( $reminder_days ) ) { |
|
440 | + return; |
|
441 | + } |
|
442 | + |
|
443 | + // Retrieve date query. |
|
444 | + $date_query = $this->get_date_query( $reminder_days ); |
|
445 | + |
|
446 | + // Invoices table. |
|
447 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
448 | + |
|
449 | + // Fetch invoices. |
|
450 | + $invoices = $wpdb->get_col( |
|
451 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
452 | 452 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
453 | 453 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
454 | 454 | ); |
455 | 455 | |
456 | - foreach ( $invoices as $invoice ) { |
|
456 | + foreach ( $invoices as $invoice ) { |
|
457 | 457 | |
458 | - // Only send this email for invoices created via the admin page. |
|
459 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
460 | - $invoice = new WPInv_Invoice( $invoice ); |
|
461 | - $email->object = $invoice; |
|
458 | + // Only send this email for invoices created via the admin page. |
|
459 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
460 | + $invoice = new WPInv_Invoice( $invoice ); |
|
461 | + $email->object = $invoice; |
|
462 | 462 | |
463 | - if ( $invoice->needs_payment() ) { |
|
464 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
465 | - } |
|
463 | + if ( $invoice->needs_payment() ) { |
|
464 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
465 | + } |
|
466 | 466 | } |
467 | 467 | } |
468 | 468 | |
469 | - } |
|
469 | + } |
|
470 | 470 | |
471 | - /** |
|
472 | - * Calculates the date query for an invoices query |
|
473 | - * |
|
474 | - * @param array $reminder_days |
|
475 | - * @return string |
|
476 | - */ |
|
477 | - public function get_date_query( $reminder_days ) { |
|
471 | + /** |
|
472 | + * Calculates the date query for an invoices query |
|
473 | + * |
|
474 | + * @param array $reminder_days |
|
475 | + * @return string |
|
476 | + */ |
|
477 | + public function get_date_query( $reminder_days ) { |
|
478 | 478 | |
479 | - $date_query = array( |
|
480 | - 'relation' => 'OR', |
|
481 | - ); |
|
479 | + $date_query = array( |
|
480 | + 'relation' => 'OR', |
|
481 | + ); |
|
482 | 482 | |
483 | - foreach ( $reminder_days as $days ) { |
|
484 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
483 | + foreach ( $reminder_days as $days ) { |
|
484 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
485 | 485 | |
486 | - $date_query[] = array( |
|
487 | - 'year' => $date['year'], |
|
488 | - 'month' => $date['month'], |
|
489 | - 'day' => $date['day'], |
|
490 | - ); |
|
486 | + $date_query[] = array( |
|
487 | + 'year' => $date['year'], |
|
488 | + 'month' => $date['month'], |
|
489 | + 'day' => $date['day'], |
|
490 | + ); |
|
491 | 491 | |
492 | - } |
|
492 | + } |
|
493 | 493 | |
494 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
494 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
495 | 495 | |
496 | - return $date_query->get_sql(); |
|
496 | + return $date_query->get_sql(); |
|
497 | 497 | |
498 | - } |
|
498 | + } |
|
499 | 499 | |
500 | 500 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class handles invoice notificaiton emails. |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $this->invoice_actions = apply_filters( |
29 | 29 | 'getpaid_notification_email_invoice_triggers', |
30 | 30 | array( |
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
31 | + 'getpaid_new_invoice' => array('new_invoice', 'user_invoice'), |
|
32 | 32 | 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
33 | 33 | 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
34 | 34 | 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function init_hooks() { |
52 | 52 | |
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
53 | + add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2); |
|
54 | + add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2); |
|
55 | 55 | |
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
56 | + foreach ($this->invoice_actions as $hook => $email_type) { |
|
57 | + $this->init_email_type_hook($hook, $email_type); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -64,25 +64,25 @@ discard block |
||
64 | 64 | * @param string $hook |
65 | 65 | * @param string|array $email_type |
66 | 66 | */ |
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
67 | + public function init_email_type_hook($hook, $email_type) { |
|
68 | 68 | |
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
69 | + $email_type = wpinv_parse_list($email_type); |
|
70 | 70 | |
71 | - foreach ( $email_type as $type ) { |
|
71 | + foreach ($email_type as $type) { |
|
72 | 72 | |
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
73 | + $email = new GetPaid_Notification_Email($type); |
|
74 | 74 | |
75 | 75 | // Abort if it is not active. |
76 | - if ( ! $email->is_active() ) { |
|
76 | + if (!$email->is_active()) { |
|
77 | 77 | continue; |
78 | 78 | } |
79 | 79 | |
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
80 | + if (method_exists($this, $type)) { |
|
81 | + add_action($hook, array($this, $type), 100, 2); |
|
82 | 82 | continue; |
83 | 83 | } |
84 | 84 | |
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | + do_action('getpaid_invoice_init_email_type_hook', $type, $hook); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | } |
@@ -93,19 +93,19 @@ discard block |
||
93 | 93 | * @param array $merge_tags |
94 | 94 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
95 | 95 | */ |
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | + public function invoice_merge_tags($merge_tags, $object) { |
|
97 | 97 | |
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | + if (is_a($object, 'WPInv_Invoice')) { |
|
99 | 99 | return array_merge( |
100 | 100 | $merge_tags, |
101 | - $this->get_invoice_merge_tags( $object ) |
|
101 | + $this->get_invoice_merge_tags($object) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | + if (is_a($object, 'WPInv_Subscription')) { |
|
106 | 106 | return array_merge( |
107 | 107 | $merge_tags, |
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | + $this->get_invoice_merge_tags($object->get_parent_payment()) |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
@@ -119,50 +119,50 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return array |
121 | 121 | */ |
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
122 | + public function get_invoice_merge_tags($invoice) { |
|
123 | 123 | |
124 | 124 | // Abort if it does not exist. |
125 | - if ( ! $invoice->get_id() ) { |
|
125 | + if (!$invoice->get_id()) { |
|
126 | 126 | return array(); |
127 | 127 | } |
128 | 128 | |
129 | 129 | $merge_tags = array( |
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
130 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
131 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
132 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
133 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
134 | + '{email}' => sanitize_email($invoice->get_email()), |
|
135 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
136 | + '{invoice_currency}' => sanitize_text_field($invoice->get_currency()), |
|
137 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())), |
|
138 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
139 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
140 | + '{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()), |
|
141 | + '{invoice_date}' => getpaid_format_date_value($invoice->get_date_created()), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')), |
|
143 | + '{invoice_quote}' => sanitize_text_field(strtolower($invoice->get_label())), |
|
144 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_label())), |
|
145 | + '{invoice_description}' => wp_kses_post($invoice->get_description()), |
|
146 | + '{subscription_name}' => wp_kses_post($invoice->get_subscription_name()), |
|
147 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | |
150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
150 | + $payment_form_data = $invoice->get_meta('payment_form_data', true); |
|
151 | 151 | |
152 | - if ( is_array( $payment_form_data ) ) { |
|
152 | + if (is_array($payment_form_data)) { |
|
153 | 153 | |
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
154 | + foreach ($payment_form_data as $label => $value) { |
|
155 | 155 | |
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
156 | + $label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label)); |
|
157 | + $value = is_array($value) ? implode(', ', $value) : $value; |
|
158 | 158 | |
159 | - if ( is_scalar( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
159 | + if (is_scalar($value)) { |
|
160 | + $merge_tags["{{$label}}"] = wp_kses_post($value); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
165 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * @param string|array $recipients |
175 | 175 | * @param array $extra_args Extra template args. |
176 | 176 | */ |
177 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
177 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
178 | 178 | |
179 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
179 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
180 | 180 | |
181 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
182 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
181 | + $skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice'); |
|
182 | + if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) { |
|
183 | 183 | return; |
184 | 184 | } |
185 | 185 | |
@@ -187,43 +187,43 @@ discard block |
||
187 | 187 | $merge_tags = $email->get_merge_tags(); |
188 | 188 | |
189 | 189 | $result = $mailer->send( |
190 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
191 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
192 | - $email->get_content( $merge_tags, $extra_args ), |
|
190 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
191 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
192 | + $email->get_content($merge_tags, $extra_args), |
|
193 | 193 | $email->get_attachments() |
194 | 194 | ); |
195 | 195 | |
196 | 196 | // Maybe send a copy to the admin. |
197 | - if ( $email->include_admin_bcc() ) { |
|
197 | + if ($email->include_admin_bcc()) { |
|
198 | 198 | $mailer->send( |
199 | 199 | wpinv_get_admin_email(), |
200 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
201 | - $email->get_content( $merge_tags ), |
|
200 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
201 | + $email->get_content($merge_tags), |
|
202 | 202 | $email->get_attachments() |
203 | 203 | ); |
204 | 204 | } |
205 | 205 | |
206 | - if ( $result ) { |
|
206 | + if ($result) { |
|
207 | 207 | $invoice->add_system_note( |
208 | 208 | sprintf( |
209 | 209 | // translators: %1 is the email type, %2 is the invoice recipient. |
210 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
211 | - sanitize_key( $type ), |
|
212 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
210 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
211 | + sanitize_key($type), |
|
212 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
213 | 213 | ) |
214 | 214 | ); |
215 | 215 | } else { |
216 | 216 | $invoice->add_system_note( |
217 | 217 | sprintf( |
218 | 218 | // translators: %1 is the email type, %2 is the invoice recipient. |
219 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
219 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
220 | + sanitize_key($type), |
|
221 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
226 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
227 | 227 | |
228 | 228 | return $result; |
229 | 229 | } |
@@ -234,20 +234,20 @@ discard block |
||
234 | 234 | * @param array $recipients |
235 | 235 | * @param GetPaid_Notification_Email $email |
236 | 236 | */ |
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
237 | + public function filter_email_recipients($recipients, $email) { |
|
238 | 238 | |
239 | - if ( ! $email->is_admin_email() ) { |
|
239 | + if (!$email->is_admin_email()) { |
|
240 | 240 | $cc = $email->object->get_email_cc(); |
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
241 | + $cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true); |
|
242 | 242 | |
243 | - if ( ! empty( $cc ) ) { |
|
244 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
243 | + if (!empty($cc)) { |
|
244 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
245 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
246 | 246 | } |
247 | 247 | |
248 | - if ( ! empty( $cc_2 ) ) { |
|
249 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
248 | + if (!empty($cc_2)) { |
|
249 | + $cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2)); |
|
250 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc_2))); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -260,17 +260,17 @@ discard block |
||
260 | 260 | * |
261 | 261 | * @param WPInv_Invoice $invoice |
262 | 262 | */ |
263 | - public function new_invoice( $invoice ) { |
|
263 | + public function new_invoice($invoice) { |
|
264 | 264 | |
265 | 265 | // Only send this email for invoices created via the admin page. |
266 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
266 | + if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) { |
|
267 | 267 | return; |
268 | 268 | } |
269 | 269 | |
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
270 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
271 | 271 | $recipient = wpinv_get_admin_email(); |
272 | 272 | |
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
273 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
274 | 274 | |
275 | 275 | } |
276 | 276 | |
@@ -279,12 +279,12 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @param WPInv_Invoice $invoice |
281 | 281 | */ |
282 | - public function cancelled_invoice( $invoice ) { |
|
282 | + public function cancelled_invoice($invoice) { |
|
283 | 283 | |
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
284 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
285 | 285 | $recipient = $invoice->get_email(); |
286 | 286 | |
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
287 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @param WPInv_Invoice $invoice |
294 | 294 | */ |
295 | - public function failed_invoice( $invoice ) { |
|
295 | + public function failed_invoice($invoice) { |
|
296 | 296 | |
297 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
297 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
298 | 298 | $recipient = wpinv_get_admin_email(); |
299 | 299 | |
300 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
300 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
301 | 301 | |
302 | 302 | } |
303 | 303 | |
@@ -306,12 +306,12 @@ discard block |
||
306 | 306 | * |
307 | 307 | * @param WPInv_Invoice $invoice |
308 | 308 | */ |
309 | - public function onhold_invoice( $invoice ) { |
|
309 | + public function onhold_invoice($invoice) { |
|
310 | 310 | |
311 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
311 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
312 | 312 | $recipient = $invoice->get_email(); |
313 | 313 | |
314 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
314 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
315 | 315 | |
316 | 316 | } |
317 | 317 | |
@@ -320,12 +320,12 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @param WPInv_Invoice $invoice |
322 | 322 | */ |
323 | - public function processing_invoice( $invoice ) { |
|
323 | + public function processing_invoice($invoice) { |
|
324 | 324 | |
325 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
325 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
326 | 326 | $recipient = $invoice->get_email(); |
327 | 327 | |
328 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
328 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
329 | 329 | |
330 | 330 | } |
331 | 331 | |
@@ -334,17 +334,17 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @param WPInv_Invoice $invoice |
336 | 336 | */ |
337 | - public function completed_invoice( $invoice ) { |
|
337 | + public function completed_invoice($invoice) { |
|
338 | 338 | |
339 | 339 | // (Maybe) abort if it is a renewal invoice. |
340 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
340 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
344 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
345 | 345 | $recipient = $invoice->get_email(); |
346 | 346 | |
347 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
347 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
348 | 348 | |
349 | 349 | } |
350 | 350 | |
@@ -353,12 +353,12 @@ discard block |
||
353 | 353 | * |
354 | 354 | * @param WPInv_Invoice $invoice |
355 | 355 | */ |
356 | - public function refunded_invoice( $invoice ) { |
|
356 | + public function refunded_invoice($invoice) { |
|
357 | 357 | |
358 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
358 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
359 | 359 | $recipient = $invoice->get_email(); |
360 | 360 | |
361 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
361 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
362 | 362 | |
363 | 363 | } |
364 | 364 | |
@@ -368,21 +368,21 @@ discard block |
||
368 | 368 | * @param WPInv_Invoice $invoice |
369 | 369 | * @param bool $force |
370 | 370 | */ |
371 | - public function user_invoice( $invoice, $force = false ) { |
|
371 | + public function user_invoice($invoice, $force = false) { |
|
372 | 372 | |
373 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
373 | + if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | 377 | // Only send this email for invoices created via the admin page. |
378 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
378 | + if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
379 | 379 | return; |
380 | 380 | } |
381 | 381 | |
382 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
382 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
383 | 383 | $recipient = $invoice->get_email(); |
384 | 384 | |
385 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
385 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
386 | 386 | |
387 | 387 | } |
388 | 388 | |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | * @param int $invoice |
393 | 393 | * @return bool |
394 | 394 | */ |
395 | - public function is_payment_form_invoice( $invoice ) { |
|
396 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
397 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
395 | + public function is_payment_form_invoice($invoice) { |
|
396 | + $is_payment_form_invoice = empty($_GET['getpaid-admin-action']) && ('payment_form' === get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' === get_post_meta($invoice, 'wpinv_created_via', true)); |
|
397 | + return apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -403,12 +403,12 @@ discard block |
||
403 | 403 | * @param WPInv_Invoice $invoice |
404 | 404 | * @param string $note |
405 | 405 | */ |
406 | - public function user_note( $invoice, $note ) { |
|
406 | + public function user_note($invoice, $note) { |
|
407 | 407 | |
408 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
408 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
409 | 409 | $recipient = $invoice->get_email(); |
410 | 410 | |
411 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
411 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
412 | 412 | |
413 | 413 | } |
414 | 414 | |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | * |
418 | 418 | * @param WPInv_Invoice $invoice |
419 | 419 | */ |
420 | - public function force_send_overdue_notice( $invoice ) { |
|
421 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
422 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
420 | + public function force_send_overdue_notice($invoice) { |
|
421 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
422 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -430,38 +430,38 @@ discard block |
||
430 | 430 | public function overdue() { |
431 | 431 | global $wpdb; |
432 | 432 | |
433 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
433 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
434 | 434 | |
435 | 435 | // Fetch reminder days. |
436 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
436 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
437 | 437 | |
438 | 438 | // Abort if non is set. |
439 | - if ( empty( $reminder_days ) ) { |
|
439 | + if (empty($reminder_days)) { |
|
440 | 440 | return; |
441 | 441 | } |
442 | 442 | |
443 | 443 | // Retrieve date query. |
444 | - $date_query = $this->get_date_query( $reminder_days ); |
|
444 | + $date_query = $this->get_date_query($reminder_days); |
|
445 | 445 | |
446 | 446 | // Invoices table. |
447 | 447 | $table = $wpdb->prefix . 'getpaid_invoices'; |
448 | 448 | |
449 | 449 | // Fetch invoices. |
450 | - $invoices = $wpdb->get_col( |
|
450 | + $invoices = $wpdb->get_col( |
|
451 | 451 | "SELECT posts.ID FROM $wpdb->posts as posts |
452 | 452 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
453 | 453 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
454 | 454 | ); |
455 | 455 | |
456 | - foreach ( $invoices as $invoice ) { |
|
456 | + foreach ($invoices as $invoice) { |
|
457 | 457 | |
458 | 458 | // Only send this email for invoices created via the admin page. |
459 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
460 | - $invoice = new WPInv_Invoice( $invoice ); |
|
459 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
460 | + $invoice = new WPInv_Invoice($invoice); |
|
461 | 461 | $email->object = $invoice; |
462 | 462 | |
463 | - if ( $invoice->needs_payment() ) { |
|
464 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
463 | + if ($invoice->needs_payment()) { |
|
464 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | } |
@@ -474,14 +474,14 @@ discard block |
||
474 | 474 | * @param array $reminder_days |
475 | 475 | * @return string |
476 | 476 | */ |
477 | - public function get_date_query( $reminder_days ) { |
|
477 | + public function get_date_query($reminder_days) { |
|
478 | 478 | |
479 | 479 | $date_query = array( |
480 | 480 | 'relation' => 'OR', |
481 | 481 | ); |
482 | 482 | |
483 | - foreach ( $reminder_days as $days ) { |
|
484 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
483 | + foreach ($reminder_days as $days) { |
|
484 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
485 | 485 | |
486 | 486 | $date_query[] = array( |
487 | 487 | 'year' => $date['year'], |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | |
492 | 492 | } |
493 | 493 | |
494 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
494 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
495 | 495 | |
496 | 496 | return $date_query->get_sql(); |
497 | 497 |
@@ -12,47 +12,47 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Export { |
14 | 14 | |
15 | - /** |
|
16 | - * Displays the reports tab. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function display() { |
|
20 | - |
|
21 | - echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | - $this->display_post_type_export( $post_type ); |
|
24 | - } |
|
25 | - $this->display_subscription_export(); |
|
26 | - echo '</div>'; |
|
27 | - |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Retrieves the download url. |
|
32 | - * |
|
33 | - */ |
|
34 | - public function get_download_url( $post_type ) { |
|
35 | - |
|
36 | - return wp_nonce_url( |
|
37 | - add_query_arg( |
|
38 | - array( |
|
39 | - 'getpaid-admin-action' => 'export_invoices', |
|
40 | - 'post_type' => urlencode( $post_type ), |
|
41 | - ) |
|
42 | - ), |
|
43 | - 'getpaid-nonce', |
|
44 | - 'getpaid-nonce' |
|
45 | - ); |
|
46 | - |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Displays a single post type export card. |
|
51 | - * |
|
52 | - */ |
|
53 | - public function display_post_type_export( $post_type ) { |
|
54 | - |
|
55 | - ?> |
|
15 | + /** |
|
16 | + * Displays the reports tab. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function display() { |
|
20 | + |
|
21 | + echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | + $this->display_post_type_export( $post_type ); |
|
24 | + } |
|
25 | + $this->display_subscription_export(); |
|
26 | + echo '</div>'; |
|
27 | + |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Retrieves the download url. |
|
32 | + * |
|
33 | + */ |
|
34 | + public function get_download_url( $post_type ) { |
|
35 | + |
|
36 | + return wp_nonce_url( |
|
37 | + add_query_arg( |
|
38 | + array( |
|
39 | + 'getpaid-admin-action' => 'export_invoices', |
|
40 | + 'post_type' => urlencode( $post_type ), |
|
41 | + ) |
|
42 | + ), |
|
43 | + 'getpaid-nonce', |
|
44 | + 'getpaid-nonce' |
|
45 | + ); |
|
46 | + |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Displays a single post type export card. |
|
51 | + * |
|
52 | + */ |
|
53 | + public function display_post_type_export( $post_type ) { |
|
54 | + |
|
55 | + ?> |
|
56 | 56 | |
57 | 57 | <div class="col-12 col-md-6"> |
58 | 58 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | <div class="card-header"> |
61 | 61 | <strong> |
62 | 62 | <?php |
63 | - printf( |
|
64 | - esc_html__( 'Export %s', 'invoicing' ), |
|
65 | - esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
66 | - ); |
|
67 | - ?> |
|
63 | + printf( |
|
64 | + esc_html__( 'Export %s', 'invoicing' ), |
|
65 | + esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
66 | + ); |
|
67 | + ?> |
|
68 | 68 | </strong> |
69 | 69 | </div> |
70 | 70 | |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
74 | 74 | |
75 | 75 | <?php |
76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | - ?> |
|
76 | + $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | + $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | + $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | + $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | + ?> |
|
82 | 82 | |
83 | 83 | </form> |
84 | 84 | |
@@ -89,128 +89,128 @@ discard block |
||
89 | 89 | |
90 | 90 | <?php |
91 | 91 | |
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Generates the from date input field. |
|
96 | - * |
|
97 | - */ |
|
98 | - public function generate_from_date( $post_type ) { |
|
99 | - |
|
100 | - return aui()->input( |
|
101 | - array( |
|
102 | - 'type' => 'datepicker', |
|
103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | - 'name' => 'from_date', |
|
105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
106 | - 'placeholder' => 'YYYY-MM-DD', |
|
107 | - 'extra_attributes' => array( |
|
108 | - 'data-enable-time' => 'false', |
|
109 | - 'data-allow-input' => 'true', |
|
110 | - ), |
|
111 | - ), |
|
112 | - false |
|
113 | - ); |
|
114 | - |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Generates the to date input field. |
|
119 | - * |
|
120 | - */ |
|
121 | - public function generate_to_date( $post_type ) { |
|
122 | - |
|
123 | - return aui()->input( |
|
124 | - array( |
|
125 | - 'name' => 'to_date', |
|
126 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
127 | - 'placeholder' => 'yy-mm-dd', |
|
128 | - 'label' => __( 'To Date', 'invoicing' ), |
|
129 | - 'label_type' => 'vertical', |
|
130 | - 'label_class' => 'd-block', |
|
131 | - 'type' => 'datepicker', |
|
132 | - ) |
|
133 | - ); |
|
134 | - |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Generates the to post status select field. |
|
139 | - * |
|
140 | - */ |
|
141 | - public function generate_post_status_select( $post_type ) { |
|
142 | - |
|
143 | - if ( 'subscriptions' === $post_type ) { |
|
144 | - $options = getpaid_get_subscription_statuses(); |
|
145 | - } else { |
|
146 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
147 | - } |
|
148 | - |
|
149 | - return aui()->select( |
|
150 | - array( |
|
151 | - 'name' => 'status', |
|
152 | - 'id' => esc_attr( "$post_type-status" ), |
|
153 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
154 | - 'label' => __( 'Status', 'invoicing' ), |
|
155 | - 'label_type' => 'vertical', |
|
156 | - 'label_class' => 'd-block', |
|
157 | - 'options' => $options, |
|
158 | - ) |
|
159 | - ); |
|
160 | - |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Generates the to file type select field. |
|
165 | - * |
|
166 | - */ |
|
167 | - public function generate_file_type_select( $post_type ) { |
|
168 | - |
|
169 | - return aui()->select( |
|
170 | - array( |
|
171 | - 'name' => 'file_type', |
|
172 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
173 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
174 | - 'label' => __( 'Export File', 'invoicing' ), |
|
175 | - 'label_type' => 'vertical', |
|
176 | - 'label_class' => 'd-block', |
|
177 | - 'options' => array( |
|
178 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
179 | - 'xml' => __( 'XML', 'invoicing' ), |
|
180 | - 'json' => __( 'JSON', 'invoicing' ), |
|
181 | - ), |
|
182 | - ) |
|
183 | - ); |
|
184 | - |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Displays a field's markup. |
|
189 | - * |
|
190 | - */ |
|
191 | - public function display_markup( $markup ) { |
|
192 | - |
|
193 | - echo wp_kses( |
|
194 | - str_replace( |
|
195 | - array( |
|
196 | - 'form-control', |
|
197 | - 'custom-select', |
|
198 | - ), |
|
199 | - 'regular-text', |
|
200 | - $markup |
|
201 | - ), |
|
202 | - getpaid_allowed_html() |
|
203 | - ); |
|
204 | - |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Displays a subscription export card. |
|
209 | - * |
|
210 | - */ |
|
211 | - public function display_subscription_export() { |
|
212 | - |
|
213 | - ?> |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Generates the from date input field. |
|
96 | + * |
|
97 | + */ |
|
98 | + public function generate_from_date( $post_type ) { |
|
99 | + |
|
100 | + return aui()->input( |
|
101 | + array( |
|
102 | + 'type' => 'datepicker', |
|
103 | + 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | + 'name' => 'from_date', |
|
105 | + 'label' => __( 'From Date', 'invoicing' ), |
|
106 | + 'placeholder' => 'YYYY-MM-DD', |
|
107 | + 'extra_attributes' => array( |
|
108 | + 'data-enable-time' => 'false', |
|
109 | + 'data-allow-input' => 'true', |
|
110 | + ), |
|
111 | + ), |
|
112 | + false |
|
113 | + ); |
|
114 | + |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Generates the to date input field. |
|
119 | + * |
|
120 | + */ |
|
121 | + public function generate_to_date( $post_type ) { |
|
122 | + |
|
123 | + return aui()->input( |
|
124 | + array( |
|
125 | + 'name' => 'to_date', |
|
126 | + 'id' => esc_attr( "$post_type-to_date" ), |
|
127 | + 'placeholder' => 'yy-mm-dd', |
|
128 | + 'label' => __( 'To Date', 'invoicing' ), |
|
129 | + 'label_type' => 'vertical', |
|
130 | + 'label_class' => 'd-block', |
|
131 | + 'type' => 'datepicker', |
|
132 | + ) |
|
133 | + ); |
|
134 | + |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Generates the to post status select field. |
|
139 | + * |
|
140 | + */ |
|
141 | + public function generate_post_status_select( $post_type ) { |
|
142 | + |
|
143 | + if ( 'subscriptions' === $post_type ) { |
|
144 | + $options = getpaid_get_subscription_statuses(); |
|
145 | + } else { |
|
146 | + $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
147 | + } |
|
148 | + |
|
149 | + return aui()->select( |
|
150 | + array( |
|
151 | + 'name' => 'status', |
|
152 | + 'id' => esc_attr( "$post_type-status" ), |
|
153 | + 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
154 | + 'label' => __( 'Status', 'invoicing' ), |
|
155 | + 'label_type' => 'vertical', |
|
156 | + 'label_class' => 'd-block', |
|
157 | + 'options' => $options, |
|
158 | + ) |
|
159 | + ); |
|
160 | + |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Generates the to file type select field. |
|
165 | + * |
|
166 | + */ |
|
167 | + public function generate_file_type_select( $post_type ) { |
|
168 | + |
|
169 | + return aui()->select( |
|
170 | + array( |
|
171 | + 'name' => 'file_type', |
|
172 | + 'id' => esc_attr( "$post_type-file_type" ), |
|
173 | + 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
174 | + 'label' => __( 'Export File', 'invoicing' ), |
|
175 | + 'label_type' => 'vertical', |
|
176 | + 'label_class' => 'd-block', |
|
177 | + 'options' => array( |
|
178 | + 'csv' => __( 'CSV', 'invoicing' ), |
|
179 | + 'xml' => __( 'XML', 'invoicing' ), |
|
180 | + 'json' => __( 'JSON', 'invoicing' ), |
|
181 | + ), |
|
182 | + ) |
|
183 | + ); |
|
184 | + |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Displays a field's markup. |
|
189 | + * |
|
190 | + */ |
|
191 | + public function display_markup( $markup ) { |
|
192 | + |
|
193 | + echo wp_kses( |
|
194 | + str_replace( |
|
195 | + array( |
|
196 | + 'form-control', |
|
197 | + 'custom-select', |
|
198 | + ), |
|
199 | + 'regular-text', |
|
200 | + $markup |
|
201 | + ), |
|
202 | + getpaid_allowed_html() |
|
203 | + ); |
|
204 | + |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Displays a subscription export card. |
|
209 | + * |
|
210 | + */ |
|
211 | + public function display_subscription_export() { |
|
212 | + |
|
213 | + ?> |
|
214 | 214 | |
215 | 215 | <div class="col-12 col-md-6"> |
216 | 216 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
227 | 227 | |
228 | 228 | <?php |
229 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
230 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
231 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
232 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
233 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
234 | - ?> |
|
229 | + $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
230 | + $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
231 | + $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
232 | + $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
233 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
234 | + ?> |
|
235 | 235 | |
236 | 236 | </form> |
237 | 237 | |
@@ -242,6 +242,6 @@ discard block |
||
242 | 242 | |
243 | 243 | <?php |
244 | 244 | |
245 | - } |
|
245 | + } |
|
246 | 246 | |
247 | 247 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Export Class. |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | public function display() { |
20 | 20 | |
21 | 21 | echo "<div class='row mt-4' style='max-width: 920px;' >"; |
22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | - $this->display_post_type_export( $post_type ); |
|
22 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
23 | + $this->display_post_type_export($post_type); |
|
24 | 24 | } |
25 | 25 | $this->display_subscription_export(); |
26 | 26 | echo '</div>'; |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * Retrieves the download url. |
32 | 32 | * |
33 | 33 | */ |
34 | - public function get_download_url( $post_type ) { |
|
34 | + public function get_download_url($post_type) { |
|
35 | 35 | |
36 | 36 | return wp_nonce_url( |
37 | 37 | add_query_arg( |
38 | 38 | array( |
39 | 39 | 'getpaid-admin-action' => 'export_invoices', |
40 | - 'post_type' => urlencode( $post_type ), |
|
40 | + 'post_type' => urlencode($post_type), |
|
41 | 41 | ) |
42 | 42 | ), |
43 | 43 | 'getpaid-nonce', |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * Displays a single post type export card. |
51 | 51 | * |
52 | 52 | */ |
53 | - public function display_post_type_export( $post_type ) { |
|
53 | + public function display_post_type_export($post_type) { |
|
54 | 54 | |
55 | 55 | ?> |
56 | 56 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | <strong> |
62 | 62 | <?php |
63 | 63 | printf( |
64 | - esc_html__( 'Export %s', 'invoicing' ), |
|
65 | - esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
64 | + esc_html__('Export %s', 'invoicing'), |
|
65 | + esc_html(getpaid_get_post_type_label($post_type)) |
|
66 | 66 | ); |
67 | 67 | ?> |
68 | 68 | </strong> |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | |
71 | 71 | <div class="card-body"> |
72 | 72 | |
73 | - <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
|
73 | + <form method="post" action="<?php echo esc_url($this->get_download_url($post_type)); ?>"> |
|
74 | 74 | |
75 | 75 | <?php |
76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
76 | + $this->display_markup($this->generate_from_date($post_type)); |
|
77 | + $this->display_markup($this->generate_to_date($post_type)); |
|
78 | + $this->display_markup($this->generate_post_status_select($post_type)); |
|
79 | + $this->display_markup($this->generate_file_type_select($post_type)); |
|
80 | + submit_button(__('Download', 'invoicing')); |
|
81 | 81 | ?> |
82 | 82 | |
83 | 83 | </form> |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * Generates the from date input field. |
96 | 96 | * |
97 | 97 | */ |
98 | - public function generate_from_date( $post_type ) { |
|
98 | + public function generate_from_date($post_type) { |
|
99 | 99 | |
100 | 100 | return aui()->input( |
101 | 101 | array( |
102 | 102 | 'type' => 'datepicker', |
103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
103 | + 'id' => esc_attr("$post_type-from_date"), |
|
104 | 104 | 'name' => 'from_date', |
105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
105 | + 'label' => __('From Date', 'invoicing'), |
|
106 | 106 | 'placeholder' => 'YYYY-MM-DD', |
107 | 107 | 'extra_attributes' => array( |
108 | 108 | 'data-enable-time' => 'false', |
@@ -118,14 +118,14 @@ discard block |
||
118 | 118 | * Generates the to date input field. |
119 | 119 | * |
120 | 120 | */ |
121 | - public function generate_to_date( $post_type ) { |
|
121 | + public function generate_to_date($post_type) { |
|
122 | 122 | |
123 | 123 | return aui()->input( |
124 | 124 | array( |
125 | 125 | 'name' => 'to_date', |
126 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
126 | + 'id' => esc_attr("$post_type-to_date"), |
|
127 | 127 | 'placeholder' => 'yy-mm-dd', |
128 | - 'label' => __( 'To Date', 'invoicing' ), |
|
128 | + 'label' => __('To Date', 'invoicing'), |
|
129 | 129 | 'label_type' => 'vertical', |
130 | 130 | 'label_class' => 'd-block', |
131 | 131 | 'type' => 'datepicker', |
@@ -138,20 +138,20 @@ discard block |
||
138 | 138 | * Generates the to post status select field. |
139 | 139 | * |
140 | 140 | */ |
141 | - public function generate_post_status_select( $post_type ) { |
|
141 | + public function generate_post_status_select($post_type) { |
|
142 | 142 | |
143 | - if ( 'subscriptions' === $post_type ) { |
|
143 | + if ('subscriptions' === $post_type) { |
|
144 | 144 | $options = getpaid_get_subscription_statuses(); |
145 | 145 | } else { |
146 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
146 | + $options = wpinv_get_invoice_statuses(true, false, $post_type); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return aui()->select( |
150 | 150 | array( |
151 | 151 | 'name' => 'status', |
152 | - 'id' => esc_attr( "$post_type-status" ), |
|
153 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
154 | - 'label' => __( 'Status', 'invoicing' ), |
|
152 | + 'id' => esc_attr("$post_type-status"), |
|
153 | + 'placeholder' => __('All Statuses', 'invoicing'), |
|
154 | + 'label' => __('Status', 'invoicing'), |
|
155 | 155 | 'label_type' => 'vertical', |
156 | 156 | 'label_class' => 'd-block', |
157 | 157 | 'options' => $options, |
@@ -164,20 +164,20 @@ discard block |
||
164 | 164 | * Generates the to file type select field. |
165 | 165 | * |
166 | 166 | */ |
167 | - public function generate_file_type_select( $post_type ) { |
|
167 | + public function generate_file_type_select($post_type) { |
|
168 | 168 | |
169 | 169 | return aui()->select( |
170 | 170 | array( |
171 | 171 | 'name' => 'file_type', |
172 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
173 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
174 | - 'label' => __( 'Export File', 'invoicing' ), |
|
172 | + 'id' => esc_attr("$post_type-file_type"), |
|
173 | + 'placeholder' => __('Select File Type', 'invoicing'), |
|
174 | + 'label' => __('Export File', 'invoicing'), |
|
175 | 175 | 'label_type' => 'vertical', |
176 | 176 | 'label_class' => 'd-block', |
177 | 177 | 'options' => array( |
178 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
179 | - 'xml' => __( 'XML', 'invoicing' ), |
|
180 | - 'json' => __( 'JSON', 'invoicing' ), |
|
178 | + 'csv' => __('CSV', 'invoicing'), |
|
179 | + 'xml' => __('XML', 'invoicing'), |
|
180 | + 'json' => __('JSON', 'invoicing'), |
|
181 | 181 | ), |
182 | 182 | ) |
183 | 183 | ); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * Displays a field's markup. |
189 | 189 | * |
190 | 190 | */ |
191 | - public function display_markup( $markup ) { |
|
191 | + public function display_markup($markup) { |
|
192 | 192 | |
193 | 193 | echo wp_kses( |
194 | 194 | str_replace( |
@@ -217,20 +217,20 @@ discard block |
||
217 | 217 | |
218 | 218 | <div class="card-header"> |
219 | 219 | <strong> |
220 | - <?php esc_html_e( 'Export Subscriptions', 'invoicing' ); ?> |
|
220 | + <?php esc_html_e('Export Subscriptions', 'invoicing'); ?> |
|
221 | 221 | </strong> |
222 | 222 | </div> |
223 | 223 | |
224 | 224 | <div class="card-body"> |
225 | 225 | |
226 | - <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
|
226 | + <form method="post" action="<?php echo esc_url($this->get_download_url('subscriptions')); ?>"> |
|
227 | 227 | |
228 | 228 | <?php |
229 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
230 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
231 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
232 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
233 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
229 | + $this->display_markup($this->generate_from_date('subscriptions')); |
|
230 | + $this->display_markup($this->generate_to_date('subscriptions')); |
|
231 | + $this->display_markup($this->generate_post_status_select('subscriptions')); |
|
232 | + $this->display_markup($this->generate_file_type_select('subscriptions')); |
|
233 | + submit_button(__('Download', 'invoicing')); |
|
234 | 234 | ?> |
235 | 235 | |
236 | 236 | </form> |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email_Sender { |
14 | 14 | |
15 | 15 | /** |
16 | - * Whether or not we should inline CSS into the email. |
|
17 | - */ |
|
18 | - public $inline_css = true; |
|
16 | + * Whether or not we should inline CSS into the email. |
|
17 | + */ |
|
18 | + public $inline_css = true; |
|
19 | 19 | |
20 | 20 | /** |
21 | - * The wp_mail() data. |
|
22 | - */ |
|
21 | + * The wp_mail() data. |
|
22 | + */ |
|
23 | 23 | public $wp_mail_data = null; |
24 | 24 | |
25 | 25 | /** |
26 | - * Sends a new email. |
|
26 | + * Sends a new email. |
|
27 | 27 | * |
28 | 28 | * @param string|array $to The recipients email or an array of recipient emails. |
29 | 29 | * @param string $subject The email's subject. |
@@ -31,49 +31,49 @@ discard block |
||
31 | 31 | * @param array $attachments The email attachments. |
32 | 32 | * |
33 | 33 | * @return bool |
34 | - */ |
|
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
34 | + */ |
|
35 | + public function send( $to, $subject, $email, $attachments = array() ) { |
|
36 | 36 | |
37 | - /* |
|
37 | + /* |
|
38 | 38 | * Allow to filter data on per-email basis. |
39 | 39 | */ |
40 | - $data = apply_filters( |
|
41 | - 'getpaid_email_data', |
|
42 | - array( |
|
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
46 | - 'headers' => $this->get_headers(), |
|
47 | - 'attachments' => $attachments, |
|
48 | - ), |
|
49 | - $this |
|
50 | - ); |
|
40 | + $data = apply_filters( |
|
41 | + 'getpaid_email_data', |
|
42 | + array( |
|
43 | + 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | + 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
45 | + 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
46 | + 'headers' => $this->get_headers(), |
|
47 | + 'attachments' => $attachments, |
|
48 | + ), |
|
49 | + $this |
|
50 | + ); |
|
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | 53 | $data = (array) wp_unslash( $data ); |
54 | 54 | |
55 | 55 | // Cache it. |
56 | - $this->wp_mail_data = $data; |
|
56 | + $this->wp_mail_data = $data; |
|
57 | 57 | |
58 | - // Attach our own hooks. |
|
59 | - $this->before_sending(); |
|
58 | + // Attach our own hooks. |
|
59 | + $this->before_sending(); |
|
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | 63 | foreach ( $this->wp_mail_data['to'] as $to ) { |
64 | - $result = $this->_send( $to, $data ); |
|
64 | + $result = $this->_send( $to, $data ); |
|
65 | 65 | } |
66 | 66 | |
67 | - // Remove our hooks. |
|
68 | - $this->after_sending(); |
|
67 | + // Remove our hooks. |
|
68 | + $this->after_sending(); |
|
69 | 69 | |
70 | - $this->wp_mail_data = null; |
|
70 | + $this->wp_mail_data = null; |
|
71 | 71 | |
72 | - return $result; |
|
73 | - } |
|
72 | + return $result; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Does the actual sending. |
|
75 | + /** |
|
76 | + * Does the actual sending. |
|
77 | 77 | * |
78 | 78 | * @param string $to The recipient's email. |
79 | 79 | * @param array $data The email's data. |
@@ -81,81 +81,81 @@ discard block |
||
81 | 81 | * @param array $attachments The email attachments. |
82 | 82 | * |
83 | 83 | * @return bool |
84 | - */ |
|
85 | - protected function _send( $to, $data ) { |
|
86 | - |
|
87 | - // Prepare the sending function. |
|
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | - |
|
90 | - // Send the actual email. |
|
91 | - $result = call_user_func( |
|
92 | - $sending_function, |
|
93 | - $to, |
|
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | - $data['email'], |
|
96 | - $data['headers'], |
|
97 | - $data['attachments'] |
|
98 | - ); |
|
99 | - |
|
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | - } |
|
104 | - |
|
105 | - return $result; |
|
106 | - } |
|
84 | + */ |
|
85 | + protected function _send( $to, $data ) { |
|
86 | + |
|
87 | + // Prepare the sending function. |
|
88 | + $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | + |
|
90 | + // Send the actual email. |
|
91 | + $result = call_user_func( |
|
92 | + $sending_function, |
|
93 | + $to, |
|
94 | + html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | + $data['email'], |
|
96 | + $data['headers'], |
|
97 | + $data['attachments'] |
|
98 | + ); |
|
99 | + |
|
100 | + if ( ! $result ) { |
|
101 | + $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | + wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | + } |
|
104 | + |
|
105 | + return $result; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | /** |
109 | - * Retrieves email headers. |
|
110 | - */ |
|
111 | - public function get_headers() { |
|
109 | + * Retrieves email headers. |
|
110 | + */ |
|
111 | + public function get_headers() { |
|
112 | 112 | |
113 | - $name = $this->get_from_name(); |
|
114 | - $reply_to = $this->get_reply_to(); |
|
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
113 | + $name = $this->get_from_name(); |
|
114 | + $reply_to = $this->get_reply_to(); |
|
115 | + $headers = array( "Reply-To:$name <$reply_to>" ); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
118 | 118 | |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | /** |
122 | - * Fires before an email is sent |
|
123 | - * |
|
124 | - * @since 1.0.0 |
|
125 | - */ |
|
126 | - public function before_sending() { |
|
122 | + * Fires before an email is sent |
|
123 | + * |
|
124 | + * @since 1.0.0 |
|
125 | + */ |
|
126 | + public function before_sending() { |
|
127 | 127 | |
128 | 128 | do_action( 'getpaid_before_send_email', $this ); |
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
129 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | + add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | + add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | 136 | /** |
137 | - * Returns the from name. |
|
138 | - */ |
|
139 | - public function get_from_name() { |
|
137 | + * Returns the from name. |
|
138 | + */ |
|
139 | + public function get_from_name() { |
|
140 | 140 | |
141 | 141 | $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if ( empty( $from_name ) ) { |
|
144 | + $from_name = get_bloginfo( 'name' ); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | - * Returns the from email. |
|
152 | - */ |
|
153 | - public function get_from_address() { |
|
151 | + * Returns the from email. |
|
152 | + */ |
|
153 | + public function get_from_address() { |
|
154 | 154 | |
155 | 155 | $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
158 | - $from_address = $this->default_from_address(); |
|
157 | + if ( ! is_email( $from_address ) ) { |
|
158 | + $from_address = $this->default_from_address(); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return $from_address; |
@@ -163,75 +163,75 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * The default emails from address. |
|
167 | - * |
|
168 | - * Defaults to wordpress@$sitename |
|
169 | - * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | - * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | - * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | - * |
|
173 | - */ |
|
174 | - public function default_from_address() { |
|
175 | - |
|
176 | - // Get the site domain and get rid of www. |
|
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
180 | - } |
|
181 | - |
|
182 | - $from_email = 'wordpress@' . $sitename; |
|
183 | - |
|
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
166 | + * The default emails from address. |
|
167 | + * |
|
168 | + * Defaults to wordpress@$sitename |
|
169 | + * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | + * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | + * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | + * |
|
173 | + */ |
|
174 | + public function default_from_address() { |
|
175 | + |
|
176 | + // Get the site domain and get rid of www. |
|
177 | + $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | + if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | + $sitename = substr( $sitename, 4 ); |
|
180 | + } |
|
181 | + |
|
182 | + $from_email = 'wordpress@' . $sitename; |
|
183 | + |
|
184 | + return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | - * Get the email reply-to. |
|
190 | - * |
|
191 | - * |
|
192 | - * @return string The email reply-to address. |
|
193 | - */ |
|
194 | - public function get_reply_to() { |
|
189 | + * Get the email reply-to. |
|
190 | + * |
|
191 | + * |
|
192 | + * @return string The email reply-to address. |
|
193 | + */ |
|
194 | + public function get_reply_to() { |
|
195 | 195 | |
196 | - $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
196 | + $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
200 | - } |
|
198 | + if ( ! is_email( $reply_to ) ) { |
|
199 | + $reply_to = get_option( 'admin_email' ); |
|
200 | + } |
|
201 | 201 | |
202 | - return $reply_to; |
|
202 | + return $reply_to; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | - * Get the email content type. |
|
207 | - * |
|
208 | - */ |
|
209 | - public function get_content_type() { |
|
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
206 | + * Get the email content type. |
|
207 | + * |
|
208 | + */ |
|
209 | + public function get_content_type() { |
|
210 | + return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | - * Ensures that our email messages are not messed up by template plugins. |
|
215 | - * |
|
216 | - * @return array wp_mail_data. |
|
217 | - */ |
|
218 | - public function ensure_email_content( $args ) { |
|
219 | - $args['message'] = $this->wp_mail_data['email']; |
|
220 | - return $args; |
|
214 | + * Ensures that our email messages are not messed up by template plugins. |
|
215 | + * |
|
216 | + * @return array wp_mail_data. |
|
217 | + */ |
|
218 | + public function ensure_email_content( $args ) { |
|
219 | + $args['message'] = $this->wp_mail_data['email']; |
|
220 | + return $args; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | - * A little house keeping after an email is sent. |
|
225 | - * |
|
226 | - */ |
|
227 | - public function after_sending() { |
|
224 | + * A little house keeping after an email is sent. |
|
225 | + * |
|
226 | + */ |
|
227 | + public function after_sending() { |
|
228 | 228 | |
229 | 229 | do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
230 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | + remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | + remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
234 | 234 | |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | 237 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This function is responsible for sending emails. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return bool |
34 | 34 | */ |
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
35 | + public function send($to, $subject, $email, $attachments = array()) { |
|
36 | 36 | |
37 | 37 | /* |
38 | 38 | * Allow to filter data on per-email basis. |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | $data = apply_filters( |
41 | 41 | 'getpaid_email_data', |
42 | 42 | array( |
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
43 | + 'to' => array_filter(array_unique(wpinv_parse_list($to))), |
|
44 | + 'subject' => htmlspecialchars_decode(wp_strip_all_tags($subject), ENT_QUOTES), |
|
45 | + 'email' => apply_filters('wpinv_mail_content', $email), |
|
46 | 46 | 'headers' => $this->get_headers(), |
47 | 47 | 'attachments' => $attachments, |
48 | 48 | ), |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | ); |
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | - $data = (array) wp_unslash( $data ); |
|
53 | + $data = (array) wp_unslash($data); |
|
54 | 54 | |
55 | 55 | // Cache it. |
56 | 56 | $this->wp_mail_data = $data; |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | - foreach ( $this->wp_mail_data['to'] as $to ) { |
|
64 | - $result = $this->_send( $to, $data ); |
|
63 | + foreach ($this->wp_mail_data['to'] as $to) { |
|
64 | + $result = $this->_send($to, $data); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Remove our hooks. |
@@ -82,24 +82,24 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - protected function _send( $to, $data ) { |
|
85 | + protected function _send($to, $data) { |
|
86 | 86 | |
87 | 87 | // Prepare the sending function. |
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
88 | + $sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail'); |
|
89 | 89 | |
90 | 90 | // Send the actual email. |
91 | 91 | $result = call_user_func( |
92 | 92 | $sending_function, |
93 | 93 | $to, |
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
94 | + html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')), |
|
95 | 95 | $data['email'], |
96 | 96 | $data['headers'], |
97 | 97 | $data['attachments'] |
98 | 98 | ); |
99 | 99 | |
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
100 | + if (!$result) { |
|
101 | + $log_message = wp_sprintf(__("\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']); |
|
102 | + wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $result; |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | |
113 | 113 | $name = $this->get_from_name(); |
114 | 114 | $reply_to = $this->get_reply_to(); |
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
115 | + $headers = array("Reply-To:$name <$reply_to>"); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters('getpaid_email_headers', $headers, $this); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function before_sending() { |
127 | 127 | |
128 | - do_action( 'getpaid_before_send_email', $this ); |
|
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
128 | + do_action('getpaid_before_send_email', $this); |
|
129 | + add_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
130 | + add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
131 | + add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
132 | + add_filter('wp_mail', array($this, 'ensure_email_content'), 1000); |
|
133 | 133 | |
134 | 134 | } |
135 | 135 | |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function get_from_name() { |
140 | 140 | |
141 | - $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
|
141 | + $from_name = wpinv_get_option('email_from_name', get_bloginfo('name')); |
|
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if (empty($from_name)) { |
|
144 | + $from_name = get_bloginfo('name'); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode($from_name, ENT_QUOTES); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function get_from_address() { |
154 | 154 | |
155 | - $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
|
155 | + $from_address = wpinv_get_option('email_from', $this->default_from_address()); |
|
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
157 | + if (!is_email($from_address)) { |
|
158 | 158 | $from_address = $this->default_from_address(); |
159 | 159 | } |
160 | 160 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | public function default_from_address() { |
175 | 175 | |
176 | 176 | // Get the site domain and get rid of www. |
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
177 | + $sitename = strtolower($_SERVER['SERVER_NAME']); |
|
178 | + if (substr($sitename, 0, 4) == 'www.') { |
|
179 | + $sitename = substr($sitename, 4); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | $from_email = 'wordpress@' . $sitename; |
183 | 183 | |
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
184 | + return apply_filters('getpaid_default_from_address', $from_email); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function get_reply_to() { |
195 | 195 | |
196 | - $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
196 | + $reply_to = current(wpinv_parse_list(wpinv_get_admin_email())); |
|
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
198 | + if (!is_email($reply_to)) { |
|
199 | + $reply_to = get_option('admin_email'); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return $reply_to; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | */ |
209 | 209 | public function get_content_type() { |
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
210 | + return apply_filters('getpaid_email_content_type', 'text/html', $this); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return array wp_mail_data. |
217 | 217 | */ |
218 | - public function ensure_email_content( $args ) { |
|
218 | + public function ensure_email_content($args) { |
|
219 | 219 | $args['message'] = $this->wp_mail_data['email']; |
220 | 220 | return $args; |
221 | 221 | } |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function after_sending() { |
228 | 228 | |
229 | - do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
|
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
229 | + do_action('getpaid_after_send_email', $this->wp_mail_data); |
|
230 | + remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
231 | + remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
232 | + remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
233 | + remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000); |
|
234 | 234 | |
235 | 235 | } |
236 | 236 |
@@ -12,184 +12,184 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
133 | 117 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
138 | 125 | |
139 | - return $invoice; |
|
140 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
141 | 131 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
132 | + $invoice = $submission->get_invoice(); |
|
150 | 133 | |
151 | - $submission = $this->payment_form_submission; |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
152 | 138 | |
153 | - // Set-up the invoice details. |
|
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + |
|
153 | + // Set-up the invoice details. |
|
154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | 157 | $invoice->set_items( $items ); |
158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | + $invoice->set_currency( $submission->get_currency() ); |
|
163 | 163 | |
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | - } |
|
164 | + if ( $submission->has_shipping() ) { |
|
165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | + } |
|
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
171 | + if ( $submission->has_discount_code() ) { |
|
172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
173 | - } |
|
174 | - |
|
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
176 | - return $invoice; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Retrieves the submission's customer. |
|
181 | - * |
|
182 | - * @return int The customer id. |
|
183 | - */ |
|
184 | - protected function get_submission_customer() { |
|
185 | - $submission = $this->payment_form_submission; |
|
186 | - |
|
187 | - // If this is an existing invoice... |
|
188 | - if ( $submission->has_invoice() ) { |
|
189 | - return $submission->get_invoice()->get_user_id(); |
|
190 | - } |
|
191 | - |
|
192 | - // (Maybe) create the user. |
|
173 | + } |
|
174 | + |
|
175 | + getpaid_maybe_add_default_address( $invoice ); |
|
176 | + return $invoice; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Retrieves the submission's customer. |
|
181 | + * |
|
182 | + * @return int The customer id. |
|
183 | + */ |
|
184 | + protected function get_submission_customer() { |
|
185 | + $submission = $this->payment_form_submission; |
|
186 | + |
|
187 | + // If this is an existing invoice... |
|
188 | + if ( $submission->has_invoice() ) { |
|
189 | + return $submission->get_invoice()->get_user_id(); |
|
190 | + } |
|
191 | + |
|
192 | + // (Maybe) create the user. |
|
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | 195 | if ( empty( $user ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | if ( empty( $user ) ) { |
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | + $name = implode( '', array_filter( $name ) ); |
|
202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
203 | 203 | |
204 | - // (Maybe) send new user notification. |
|
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
208 | - } |
|
209 | - } |
|
204 | + // (Maybe) send new user notification. |
|
205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | 211 | if ( is_wp_error( $user ) ) { |
212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
214 | 214 | |
215 | 215 | if ( is_numeric( $user ) ) { |
216 | 216 | return $user; |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - return $user->ID; |
|
219 | + return $user->ID; |
|
220 | 220 | |
221 | - } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
223 | + /** |
|
224 | 224 | * Prepares submission data for saving to the database. |
225 | 225 | * |
226 | - * @return array |
|
226 | + * @return array |
|
227 | 227 | */ |
228 | 228 | public function prepare_submission_data_for_saving() { |
229 | 229 | |
230 | - $submission = $this->payment_form_submission; |
|
230 | + $submission = $this->payment_form_submission; |
|
231 | 231 | |
232 | - // Prepared submission details. |
|
232 | + // Prepared submission details. |
|
233 | 233 | $prepared = array( |
234 | - 'all' => array(), |
|
235 | - 'meta' => array(), |
|
236 | - ); |
|
234 | + 'all' => array(), |
|
235 | + 'meta' => array(), |
|
236 | + ); |
|
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | - // Loop through the submitted details. |
|
241 | + // Loop through the submitted details. |
|
242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
243 | 243 | |
244 | - // Skip premade fields. |
|
244 | + // Skip premade fields. |
|
245 | 245 | if ( ! empty( $field['premade'] ) ) { |
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | - // Ensure address is provided. |
|
250 | - if ( $field['type'] == 'address' ) { |
|
249 | + // Ensure address is provided. |
|
250 | + if ( $field['type'] == 'address' ) { |
|
251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ( $field['fields'] as $address_field ) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
266 | 266 | // Handle misc fields. |
267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
268 | 268 | |
269 | - // Uploads. |
|
270 | - if ( $field['type'] == 'file_upload' ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
269 | + // Uploads. |
|
270 | + if ( $field['type'] == 'file_upload' ) { |
|
271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | - } |
|
273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | + } |
|
276 | 276 | |
277 | - $value = array(); |
|
277 | + $value = array(); |
|
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | - $value[] = sprintf( |
|
281 | - '<a href="%s" target="_blank">%s</a>', |
|
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
284 | - ); |
|
285 | - } |
|
279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + $value[] = sprintf( |
|
281 | + '<a href="%s" target="_blank">%s</a>', |
|
282 | + esc_url_raw( $url ), |
|
283 | + esc_html( $name ) |
|
284 | + ); |
|
285 | + } |
|
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode( ' | ', $value ); |
|
288 | 288 | |
289 | - } elseif ( $field['type'] == 'checkbox' ) { |
|
290 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | - } else { |
|
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | - } |
|
289 | + } elseif ( $field['type'] == 'checkbox' ) { |
|
290 | + $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | + } else { |
|
292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
@@ -298,188 +298,188 @@ discard block |
||
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | - } |
|
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | + } |
|
304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | - return $prepared; |
|
309 | + return $prepared; |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
313 | + /** |
|
314 | 314 | * Retrieves address details. |
315 | 315 | * |
316 | - * @return array |
|
317 | - * @param WPInv_Invoice $invoice |
|
318 | - * @param string $type |
|
316 | + * @return array |
|
317 | + * @param WPInv_Invoice $invoice |
|
318 | + * @param string $type |
|
319 | 319 | */ |
320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
321 | 321 | |
322 | - $data = $this->payment_form_submission->get_data(); |
|
323 | - $type = sanitize_key( $type ); |
|
324 | - $address = array(); |
|
325 | - $prepared = array(); |
|
322 | + $data = $this->payment_form_submission->get_data(); |
|
323 | + $type = sanitize_key( $type ); |
|
324 | + $address = array(); |
|
325 | + $prepared = array(); |
|
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
329 | - } |
|
327 | + if ( ! empty( $data[ $type ] ) ) { |
|
328 | + $address = $data[ $type ]; |
|
329 | + } |
|
330 | 330 | |
331 | - // Clean address details. |
|
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | - } |
|
331 | + // Clean address details. |
|
332 | + foreach ( $address as $key => $value ) { |
|
333 | + $key = sanitize_key( $key ); |
|
334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
335 | + $value = wpinv_clean( $value ); |
|
336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | + } |
|
338 | 338 | |
339 | - // Filter address details. |
|
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
339 | + // Filter address details. |
|
340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | 341 | |
342 | - // Remove non-whitelisted values. |
|
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
342 | + // Remove non-whitelisted values. |
|
343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | 344 | |
345 | - } |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
347 | + /** |
|
348 | 348 | * Prepares the billing details. |
349 | 349 | * |
350 | - * @return array |
|
351 | - * @param WPInv_Invoice $invoice |
|
350 | + * @return array |
|
351 | + * @param WPInv_Invoice $invoice |
|
352 | 352 | */ |
353 | 353 | protected function prepare_billing_info( &$invoice ) { |
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
356 | 356 | |
357 | - // Update the invoice with the billing details. |
|
358 | - $invoice->set_props( $billing_address ); |
|
357 | + // Update the invoice with the billing details. |
|
358 | + $invoice->set_props( $billing_address ); |
|
359 | 359 | |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
362 | + /** |
|
363 | 363 | * Prepares the shipping details. |
364 | 364 | * |
365 | - * @return array |
|
366 | - * @param WPInv_Invoice $invoice |
|
365 | + * @return array |
|
366 | + * @param WPInv_Invoice $invoice |
|
367 | 367 | */ |
368 | 368 | protected function prepare_shipping_info( $invoice ) { |
369 | 369 | |
370 | - $data = $this->payment_form_submission->get_data(); |
|
370 | + $data = $this->payment_form_submission->get_data(); |
|
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | - } |
|
372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | + } |
|
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
377 | 377 | |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Confirms the submission is valid and send users to the gateway. |
|
382 | - * |
|
383 | - * @param WPInv_Invoice $invoice |
|
384 | - * @param array $prepared_payment_form_data |
|
385 | - * @param array $shipping |
|
386 | - */ |
|
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
380 | + /** |
|
381 | + * Confirms the submission is valid and send users to the gateway. |
|
382 | + * |
|
383 | + * @param WPInv_Invoice $invoice |
|
384 | + * @param array $prepared_payment_form_data |
|
385 | + * @param array $shipping |
|
386 | + */ |
|
387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
388 | 388 | |
389 | - // Ensure the invoice exists. |
|
389 | + // Ensure the invoice exists. |
|
390 | 390 | if ( ! $invoice->exists() ) { |
391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
392 | 392 | } |
393 | 393 | |
394 | - // Save payment form data. |
|
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
394 | + // Save payment form data. |
|
395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | - } |
|
400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | + } |
|
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | - } |
|
404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | + } |
|
407 | 407 | } |
408 | 408 | |
409 | - // Save payment form data. |
|
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
409 | + // Save payment form data. |
|
410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | 411 | if ( ! empty( $shipping ) ) { |
412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | - // Backwards compatibility. |
|
415 | + // Backwards compatibility. |
|
416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
417 | 417 | |
418 | - $this->process_payment( $invoice ); |
|
418 | + $this->process_payment( $invoice ); |
|
419 | 419 | |
420 | 420 | // If we are here, there was an error. |
421 | - wpinv_send_back_to_checkout( $invoice ); |
|
421 | + wpinv_send_back_to_checkout( $invoice ); |
|
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Processes the actual payment. |
|
427 | - * |
|
428 | - * @param WPInv_Invoice $invoice |
|
429 | - */ |
|
430 | - protected function process_payment( $invoice ) { |
|
425 | + /** |
|
426 | + * Processes the actual payment. |
|
427 | + * |
|
428 | + * @param WPInv_Invoice $invoice |
|
429 | + */ |
|
430 | + protected function process_payment( $invoice ) { |
|
431 | 431 | |
432 | - // Clear any checkout errors. |
|
433 | - wpinv_clear_errors(); |
|
432 | + // Clear any checkout errors. |
|
433 | + wpinv_clear_errors(); |
|
434 | 434 | |
435 | - // No need to send free invoices to the gateway. |
|
436 | - if ( $invoice->is_free() ) { |
|
437 | - $this->process_free_payment( $invoice ); |
|
438 | - } |
|
435 | + // No need to send free invoices to the gateway. |
|
436 | + if ( $invoice->is_free() ) { |
|
437 | + $this->process_free_payment( $invoice ); |
|
438 | + } |
|
439 | 439 | |
440 | - $submission = $this->payment_form_submission; |
|
440 | + $submission = $this->payment_form_submission; |
|
441 | 441 | |
442 | - // Fires before sending to the gateway. |
|
443 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
442 | + // Fires before sending to the gateway. |
|
443 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
444 | 444 | |
445 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
446 | - $submission_data = $submission->get_data(); |
|
447 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
445 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
446 | + $submission_data = $submission->get_data(); |
|
447 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
449 | 449 | |
450 | - // Validate the currency. |
|
451 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
453 | - } |
|
450 | + // Validate the currency. |
|
451 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
453 | + } |
|
454 | 454 | |
455 | - // Check to see if we have any errors. |
|
456 | - if ( wpinv_get_errors() ) { |
|
457 | - wpinv_send_back_to_checkout( $invoice ); |
|
458 | - } |
|
455 | + // Check to see if we have any errors. |
|
456 | + if ( wpinv_get_errors() ) { |
|
457 | + wpinv_send_back_to_checkout( $invoice ); |
|
458 | + } |
|
459 | 459 | |
460 | - // Send info to the gateway for payment processing |
|
461 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
460 | + // Send info to the gateway for payment processing |
|
461 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
462 | 462 | |
463 | - // Backwards compatibility. |
|
464 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
463 | + // Backwards compatibility. |
|
464 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | |
468 | - /** |
|
469 | - * Marks the invoice as paid in case the checkout is free. |
|
470 | - * |
|
471 | - * @param WPInv_Invoice $invoice |
|
472 | - */ |
|
473 | - protected function process_free_payment( $invoice ) { |
|
468 | + /** |
|
469 | + * Marks the invoice as paid in case the checkout is free. |
|
470 | + * |
|
471 | + * @param WPInv_Invoice $invoice |
|
472 | + */ |
|
473 | + protected function process_free_payment( $invoice ) { |
|
474 | 474 | |
475 | - $invoice->set_gateway( 'none' ); |
|
476 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
477 | - $invoice->mark_paid(); |
|
478 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
475 | + $invoice->set_gateway( 'none' ); |
|
476 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
477 | + $invoice->mark_paid(); |
|
478 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
479 | 479 | |
480 | - } |
|
480 | + } |
|
481 | 481 | |
482 | - /** |
|
482 | + /** |
|
483 | 483 | * Sends a redrect response to payment details. |
484 | 484 | * |
485 | 485 | */ |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 50 | $invoice->recalculate_total(); |
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
54 | 54 | |
55 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wp_send_json_error(__('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 134 | // Make sure that it is neither paid or refunded. |
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,33 +146,33 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | |
153 | 153 | // Set-up the invoice details. |
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | - $invoice->set_items( $items ); |
|
158 | - $invoice->set_fees( $submission->get_fees() ); |
|
159 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
163 | - |
|
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
154 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
155 | + $invoice->set_user_id($this->get_submission_customer()); |
|
156 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
157 | + $invoice->set_items($items); |
|
158 | + $invoice->set_fees($submission->get_fees()); |
|
159 | + $invoice->set_taxes($submission->get_taxes()); |
|
160 | + $invoice->set_discounts($submission->get_discounts()); |
|
161 | + $invoice->set_gateway($submission->get_field('wpi-gateway')); |
|
162 | + $invoice->set_currency($submission->get_currency()); |
|
163 | + |
|
164 | + if ($submission->has_shipping()) { |
|
165 | + $invoice->set_shipping($submission->get_shipping()); |
|
166 | 166 | } |
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
169 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
172 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
171 | + if ($submission->has_discount_code()) { |
|
172 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
173 | 173 | } |
174 | 174 | |
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
175 | + getpaid_maybe_add_default_address($invoice); |
|
176 | 176 | return $invoice; |
177 | 177 | } |
178 | 178 | |
@@ -185,34 +185,34 @@ discard block |
||
185 | 185 | $submission = $this->payment_form_submission; |
186 | 186 | |
187 | 187 | // If this is an existing invoice... |
188 | - if ( $submission->has_invoice() ) { |
|
188 | + if ($submission->has_invoice()) { |
|
189 | 189 | return $submission->get_invoice()->get_user_id(); |
190 | 190 | } |
191 | 191 | |
192 | 192 | // (Maybe) create the user. |
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | - if ( empty( $user ) ) { |
|
196 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
195 | + if (empty($user)) { |
|
196 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( empty( $user ) ) { |
|
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
202 | - $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
|
199 | + if (empty($user)) { |
|
200 | + $name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing')); |
|
201 | + $name = implode('', array_filter($name)); |
|
202 | + $user = wpinv_create_user($submission->get_billing_email(), $name); |
|
203 | 203 | |
204 | 204 | // (Maybe) send new user notification. |
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
205 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
206 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
207 | + wp_send_new_user_notifications($user, 'user'); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
211 | - if ( is_wp_error( $user ) ) { |
|
212 | - wp_send_json_error( $user->get_error_message() ); |
|
211 | + if (is_wp_error($user)) { |
|
212 | + wp_send_json_error($user->get_error_message()); |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( is_numeric( $user ) ) { |
|
215 | + if (is_numeric($user)) { |
|
216 | 216 | return $user; |
217 | 217 | } |
218 | 218 | |
@@ -236,72 +236,72 @@ discard block |
||
236 | 236 | ); |
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | 241 | // Loop through the submitted details. |
242 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
242 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
243 | 243 | |
244 | 244 | // Skip premade fields. |
245 | - if ( ! empty( $field['premade'] ) ) { |
|
245 | + if (!empty($field['premade'])) { |
|
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | 249 | // Ensure address is provided. |
250 | - if ( $field['type'] == 'address' ) { |
|
251 | - $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
250 | + if ($field['type'] == 'address') { |
|
251 | + $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ($field['fields'] as $address_field) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
255 | + if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { |
|
256 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
263 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
262 | + if (!$submission->is_required_field_set($field)) { |
|
263 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | // Handle misc fields. |
267 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
267 | + if (isset($data[$field['id']])) { |
|
268 | 268 | |
269 | 269 | // Uploads. |
270 | - if ( $field['type'] == 'file_upload' ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
270 | + if ($field['type'] == 'file_upload') { |
|
271 | + $max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
273 | + if (count($data[$field['id']]) > $max_file_num) { |
|
274 | + wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing')); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | $value = array(); |
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
279 | + foreach ($data[$field['id']] as $url => $name) { |
|
280 | 280 | $value[] = sprintf( |
281 | 281 | '<a href="%s" target="_blank">%s</a>', |
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
282 | + esc_url_raw($url), |
|
283 | + esc_html($name) |
|
284 | 284 | ); |
285 | 285 | } |
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode(' | ', $value); |
|
288 | 288 | |
289 | - } elseif ( $field['type'] == 'checkbox' ) { |
|
290 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
289 | + } elseif ($field['type'] == 'checkbox') { |
|
290 | + $value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
291 | 291 | } else { |
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
292 | + $value = wp_kses_post($data[$field['id']]); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
297 | - if ( isset( $field['label'] ) ) { |
|
297 | + if (isset($field['label'])) { |
|
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if (!empty($field['add_meta'])) { |
|
302 | + $prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
303 | 303 | } |
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | + $prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | } |
@@ -317,30 +317,30 @@ discard block |
||
317 | 317 | * @param WPInv_Invoice $invoice |
318 | 318 | * @param string $type |
319 | 319 | */ |
320 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
320 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
321 | 321 | |
322 | 322 | $data = $this->payment_form_submission->get_data(); |
323 | - $type = sanitize_key( $type ); |
|
323 | + $type = sanitize_key($type); |
|
324 | 324 | $address = array(); |
325 | 325 | $prepared = array(); |
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
327 | + if (!empty($data[$type])) { |
|
328 | + $address = $data[$type]; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // Clean address details. |
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
332 | + foreach ($address as $key => $value) { |
|
333 | + $key = sanitize_key($key); |
|
334 | + $key = str_replace('wpinv_', '', $key); |
|
335 | + $value = wpinv_clean($value); |
|
336 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Filter address details. |
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
340 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
341 | 341 | |
342 | 342 | // Remove non-whitelisted values. |
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
343 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
344 | 344 | |
345 | 345 | } |
346 | 346 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | * @return array |
351 | 351 | * @param WPInv_Invoice $invoice |
352 | 352 | */ |
353 | - protected function prepare_billing_info( &$invoice ) { |
|
353 | + protected function prepare_billing_info(&$invoice) { |
|
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
356 | 356 | |
357 | 357 | // Update the invoice with the billing details. |
358 | - $invoice->set_props( $billing_address ); |
|
358 | + $invoice->set_props($billing_address); |
|
359 | 359 | |
360 | 360 | } |
361 | 361 | |
@@ -365,15 +365,15 @@ discard block |
||
365 | 365 | * @return array |
366 | 366 | * @param WPInv_Invoice $invoice |
367 | 367 | */ |
368 | - protected function prepare_shipping_info( $invoice ) { |
|
368 | + protected function prepare_shipping_info($invoice) { |
|
369 | 369 | |
370 | 370 | $data = $this->payment_form_submission->get_data(); |
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
372 | + if (empty($data['same-shipping-address'])) { |
|
373 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
374 | 374 | } |
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details($invoice, 'billing'); |
|
377 | 377 | |
378 | 378 | } |
379 | 379 | |
@@ -384,41 +384,41 @@ discard block |
||
384 | 384 | * @param array $prepared_payment_form_data |
385 | 385 | * @param array $shipping |
386 | 386 | */ |
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
387 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
388 | 388 | |
389 | 389 | // Ensure the invoice exists. |
390 | - if ( ! $invoice->exists() ) { |
|
391 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
390 | + if (!$invoice->exists()) { |
|
391 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // Save payment form data. |
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
395 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
396 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
397 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
398 | + if (!empty($prepared_payment_form_data)) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
400 | + if (!empty($prepared_payment_form_data['all'])) { |
|
401 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
402 | 402 | } |
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
404 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
405 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | 409 | // Save payment form data. |
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | - if ( ! empty( $shipping ) ) { |
|
412 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
410 | + $shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission); |
|
411 | + if (!empty($shipping)) { |
|
412 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | // Backwards compatibility. |
416 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
416 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
417 | 417 | |
418 | - $this->process_payment( $invoice ); |
|
418 | + $this->process_payment($invoice); |
|
419 | 419 | |
420 | 420 | // If we are here, there was an error. |
421 | - wpinv_send_back_to_checkout( $invoice ); |
|
421 | + wpinv_send_back_to_checkout($invoice); |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
@@ -427,41 +427,41 @@ discard block |
||
427 | 427 | * |
428 | 428 | * @param WPInv_Invoice $invoice |
429 | 429 | */ |
430 | - protected function process_payment( $invoice ) { |
|
430 | + protected function process_payment($invoice) { |
|
431 | 431 | |
432 | 432 | // Clear any checkout errors. |
433 | 433 | wpinv_clear_errors(); |
434 | 434 | |
435 | 435 | // No need to send free invoices to the gateway. |
436 | - if ( $invoice->is_free() ) { |
|
437 | - $this->process_free_payment( $invoice ); |
|
436 | + if ($invoice->is_free()) { |
|
437 | + $this->process_free_payment($invoice); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | $submission = $this->payment_form_submission; |
441 | 441 | |
442 | 442 | // Fires before sending to the gateway. |
443 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
443 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
444 | 444 | |
445 | 445 | // Allow the sumission data to be modified before it is sent to the gateway. |
446 | 446 | $submission_data = $submission->get_data(); |
447 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
447 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
448 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
449 | 449 | |
450 | 450 | // Validate the currency. |
451 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
451 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
452 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing')); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | // Check to see if we have any errors. |
456 | - if ( wpinv_get_errors() ) { |
|
457 | - wpinv_send_back_to_checkout( $invoice ); |
|
456 | + if (wpinv_get_errors()) { |
|
457 | + wpinv_send_back_to_checkout($invoice); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | // Send info to the gateway for payment processing |
461 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
461 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
462 | 462 | |
463 | 463 | // Backwards compatibility. |
464 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
464 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
465 | 465 | |
466 | 466 | } |
467 | 467 | |
@@ -470,12 +470,12 @@ discard block |
||
470 | 470 | * |
471 | 471 | * @param WPInv_Invoice $invoice |
472 | 472 | */ |
473 | - protected function process_free_payment( $invoice ) { |
|
473 | + protected function process_free_payment($invoice) { |
|
474 | 474 | |
475 | - $invoice->set_gateway( 'none' ); |
|
476 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
475 | + $invoice->set_gateway('none'); |
|
476 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
477 | 477 | $invoice->mark_paid(); |
478 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
478 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
479 | 479 | |
480 | 480 | } |
481 | 481 | |
@@ -483,9 +483,9 @@ discard block |
||
483 | 483 | * Sends a redrect response to payment details. |
484 | 484 | * |
485 | 485 | */ |
486 | - public function send_redirect_response( $url ) { |
|
487 | - $url = urlencode( $url ); |
|
488 | - wp_send_json_success( $url ); |
|
486 | + public function send_redirect_response($url) { |
|
487 | + $url = urlencode($url); |
|
488 | + wp_send_json_success($url); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | } |
@@ -17,45 +17,45 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class BP_GetPaid_Component extends BP_Component { |
19 | 19 | |
20 | - /** |
|
21 | - * Start the component setup process. |
|
22 | - * |
|
23 | - * @since 2.1.5 |
|
24 | - */ |
|
25 | - public function __construct() { |
|
26 | - parent::start( |
|
27 | - 'getpaid', |
|
28 | - 'GetPaid', |
|
29 | - buddypress()->plugin_dir, |
|
30 | - array( |
|
31 | - 'adminbar_myaccount_order' => 30, |
|
32 | - ) |
|
33 | - ); |
|
34 | - } |
|
20 | + /** |
|
21 | + * Start the component setup process. |
|
22 | + * |
|
23 | + * @since 2.1.5 |
|
24 | + */ |
|
25 | + public function __construct() { |
|
26 | + parent::start( |
|
27 | + 'getpaid', |
|
28 | + 'GetPaid', |
|
29 | + buddypress()->plugin_dir, |
|
30 | + array( |
|
31 | + 'adminbar_myaccount_order' => 30, |
|
32 | + ) |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Set up component global variables. |
|
38 | - * |
|
39 | - * @since 2.1.5 |
|
40 | - * |
|
41 | - * |
|
42 | - * @param array $args { |
|
43 | - * All values are optional. |
|
44 | - * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | - * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | - * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | - * component has a root directory (the slug will be overridden by the |
|
48 | - * post_name of the directory page). Default: the slug of the directory page |
|
49 | - * if one is found, otherwise an empty string. |
|
50 | - * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | - * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | - * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | - * 'Search Groups...'. |
|
54 | - * @type array $global_tables Optional. An array of database table names. |
|
55 | - * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | - * } |
|
57 | - */ |
|
58 | - public function setup_globals( $args = array() ) { |
|
37 | + * Set up component global variables. |
|
38 | + * |
|
39 | + * @since 2.1.5 |
|
40 | + * |
|
41 | + * |
|
42 | + * @param array $args { |
|
43 | + * All values are optional. |
|
44 | + * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | + * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | + * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | + * component has a root directory (the slug will be overridden by the |
|
48 | + * post_name of the directory page). Default: the slug of the directory page |
|
49 | + * if one is found, otherwise an empty string. |
|
50 | + * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | + * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | + * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | + * 'Search Groups...'. |
|
54 | + * @type array $global_tables Optional. An array of database table names. |
|
55 | + * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | + * } |
|
57 | + */ |
|
58 | + public function setup_globals( $args = array() ) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -64,21 +64,21 @@ discard block |
||
64 | 64 | 'has_directory' => false, |
65 | 65 | ) |
66 | 66 | ); |
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Set up component navigation. |
|
71 | - * |
|
72 | - * @since 2.1.5 |
|
73 | - * |
|
74 | - * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | - * |
|
76 | - * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | - * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | - */ |
|
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | - |
|
81 | - // Abort if the integration is inactive. |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Set up component navigation. |
|
71 | + * |
|
72 | + * @since 2.1.5 |
|
73 | + * |
|
74 | + * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | + * |
|
76 | + * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | + * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | + */ |
|
79 | + public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | + |
|
81 | + // Abort if the integration is inactive. |
|
82 | 82 | if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
83 | 83 | return; |
84 | 84 | } |
@@ -88,25 +88,25 @@ discard block |
||
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | - // Determine user to use. |
|
92 | - $user_domain = bp_loggedin_user_domain(); |
|
93 | - $slug = 'getpaid'; |
|
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | - |
|
96 | - // Add 'Payments' to the main navigation. |
|
97 | - $main_nav = array( |
|
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | - 'slug' => $slug, |
|
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
91 | + // Determine user to use. |
|
92 | + $user_domain = bp_loggedin_user_domain(); |
|
93 | + $slug = 'getpaid'; |
|
94 | + $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | + |
|
96 | + // Add 'Payments' to the main navigation. |
|
97 | + $main_nav = array( |
|
98 | + 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | + 'slug' => $slug, |
|
100 | + 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | + 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | + 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | - 'item_css_id' => $this->id, |
|
105 | - 'parent_url' => $user_domain, |
|
106 | - 'parent_slug' => buddypress()->slug, |
|
107 | - ); |
|
104 | + 'item_css_id' => $this->id, |
|
105 | + 'parent_url' => $user_domain, |
|
106 | + 'parent_slug' => buddypress()->slug, |
|
107 | + ); |
|
108 | 108 | |
109 | - // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
109 | + // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
110 | 110 | foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | 118 | 'screen_function' => function() use ( $tab ) { |
119 | - $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | - $this->display_current_tab(); |
|
119 | + $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | + $this->display_current_tab(); |
|
121 | 121 | }, |
122 | 122 | 'show_for_displayed_user' => false, |
123 | 123 | 'item_css_id' => "getpaid-bp-$_slug", |
@@ -125,27 +125,27 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Set up the component entries in the WordPress Admin Bar. |
|
133 | - * |
|
134 | - * @since 2.1.5 |
|
135 | - * |
|
136 | - * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | - * parameter array. |
|
138 | - * |
|
139 | - * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | - * description. |
|
141 | - */ |
|
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
128 | + parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | + } |
|
143 | 130 | |
144 | - // Menus for logged in user. |
|
145 | - if ( is_user_logged_in() ) { |
|
146 | - |
|
147 | - // Setup the logged in user variables. |
|
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
131 | + /** |
|
132 | + * Set up the component entries in the WordPress Admin Bar. |
|
133 | + * |
|
134 | + * @since 2.1.5 |
|
135 | + * |
|
136 | + * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | + * parameter array. |
|
138 | + * |
|
139 | + * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | + * description. |
|
141 | + */ |
|
142 | + public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
143 | + |
|
144 | + // Menus for logged in user. |
|
145 | + if ( is_user_logged_in() ) { |
|
146 | + |
|
147 | + // Setup the logged in user variables. |
|
148 | + $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
@@ -168,48 +168,48 @@ discard block |
||
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Retrieves the current tab. |
|
176 | - * |
|
177 | - * @since 2.1.5 |
|
178 | - */ |
|
179 | - public function get_current_tab() { |
|
180 | - global $getpaid_bp_current_tab; |
|
181 | - |
|
182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
183 | - return array( |
|
184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
185 | - 'content' => '[wpinv_history]', |
|
186 | - 'icon' => 'fas fa-file-invoice', |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - return $getpaid_bp_current_tab; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Displays the current tab. |
|
195 | - * |
|
196 | - * @since 2.1.5 |
|
197 | - */ |
|
198 | - public function display_current_tab() { |
|
199 | - |
|
200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
171 | + parent::setup_admin_bar( $wp_admin_nav ); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Retrieves the current tab. |
|
176 | + * |
|
177 | + * @since 2.1.5 |
|
178 | + */ |
|
179 | + public function get_current_tab() { |
|
180 | + global $getpaid_bp_current_tab; |
|
181 | + |
|
182 | + if ( empty( $getpaid_bp_current_tab ) ) { |
|
183 | + return array( |
|
184 | + 'label' => __( 'Invoices', 'invoicing' ), |
|
185 | + 'content' => '[wpinv_history]', |
|
186 | + 'icon' => 'fas fa-file-invoice', |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + return $getpaid_bp_current_tab; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Displays the current tab. |
|
195 | + * |
|
196 | + * @since 2.1.5 |
|
197 | + */ |
|
198 | + public function display_current_tab() { |
|
199 | + |
|
200 | + add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | + $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
202 | 202 | |
203 | 203 | bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Handles the actual display of the current tab. |
|
208 | - * |
|
209 | - * @since 2.1.5 |
|
210 | - */ |
|
211 | - public function handle_display_current_tab() { |
|
212 | - echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
213 | - } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Handles the actual display of the current tab. |
|
208 | + * |
|
209 | + * @since 2.1.5 |
|
210 | + */ |
|
211 | + public function handle_display_current_tab() { |
|
212 | + echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
213 | + } |
|
214 | 214 | |
215 | 215 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | // Exit if accessed directly. |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Main GetPaid Class. |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @type array $meta_tables Optional. An array of metadata table names. |
56 | 56 | * } |
57 | 57 | */ |
58 | - public function setup_globals( $args = array() ) { |
|
58 | + public function setup_globals($args = array()) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -76,30 +76,30 @@ discard block |
||
76 | 76 | * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
77 | 77 | * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
78 | 78 | */ |
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
79 | + public function setup_nav($main_nav = array(), $sub_nav = array()) { |
|
80 | 80 | |
81 | 81 | // Abort if the integration is inactive. |
82 | - if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
|
82 | + if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Or a user is not viewing their profile. |
87 | - if ( bp_displayed_user_id() !== bp_loggedin_user_id() ) { |
|
87 | + if (bp_displayed_user_id() !== bp_loggedin_user_id()) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | 91 | // Determine user to use. |
92 | 92 | $user_domain = bp_loggedin_user_domain(); |
93 | 93 | $slug = 'getpaid'; |
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
94 | + $payments_link = trailingslashit($user_domain . $slug); |
|
95 | 95 | |
96 | 96 | // Add 'Payments' to the main navigation. |
97 | 97 | $main_nav = array( |
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
98 | + 'name' => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'), |
|
99 | 99 | 'slug' => $slug, |
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
100 | + 'position' => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug), |
|
101 | + 'screen_function' => array($this, 'display_current_tab'), |
|
102 | + 'default_subnav_slug' => apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | 104 | 'item_css_id' => $this->id, |
105 | 105 | 'parent_url' => $user_domain, |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ); |
108 | 108 | |
109 | 109 | // Add the subnav items to the payments nav item if we are using a theme that supports this. |
110 | - foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
|
110 | + foreach (getpaid_get_user_content_tabs() as $_slug => $tab) { |
|
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
113 | 113 | 'name' => $tab['label'], |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | 'parent_url' => $payments_link, |
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | - 'screen_function' => function() use ( $tab ) { |
|
118 | + 'screen_function' => function() use ($tab) { |
|
119 | 119 | $GLOBALS['getpaid_bp_current_tab'] = $tab; |
120 | 120 | $this->display_current_tab(); |
121 | 121 | }, |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
128 | + parent::setup_nav($main_nav, $sub_nav); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -139,36 +139,36 @@ discard block |
||
139 | 139 | * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
140 | 140 | * description. |
141 | 141 | */ |
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
142 | + public function setup_admin_bar($wp_admin_nav = array()) { |
|
143 | 143 | |
144 | 144 | // Menus for logged in user. |
145 | - if ( is_user_logged_in() ) { |
|
145 | + if (is_user_logged_in()) { |
|
146 | 146 | |
147 | 147 | // Setup the logged in user variables. |
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
148 | + $payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/'); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
152 | 152 | 'parent' => buddypress()->my_account_menu_id, |
153 | 153 | 'id' => 'my-account-getpaid', |
154 | - 'title' => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ), |
|
155 | - 'href' => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
154 | + 'title' => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'), |
|
155 | + 'href' => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
156 | 156 | ); |
157 | 157 | |
158 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
158 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
159 | 159 | |
160 | 160 | $wp_admin_nav[] = array( |
161 | 161 | 'parent' => 'my-account-getpaid', |
162 | 162 | 'id' => 'my-account-getpaid' . $slug, |
163 | 163 | 'title' => $tab['label'], |
164 | - 'href' => trailingslashit( $payments_link . $slug ), |
|
164 | + 'href' => trailingslashit($payments_link . $slug), |
|
165 | 165 | 'position' => 20, |
166 | 166 | ); |
167 | 167 | |
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
171 | + parent::setup_admin_bar($wp_admin_nav); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | public function get_current_tab() { |
180 | 180 | global $getpaid_bp_current_tab; |
181 | 181 | |
182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
182 | + if (empty($getpaid_bp_current_tab)) { |
|
183 | 183 | return array( |
184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
184 | + 'label' => __('Invoices', 'invoicing'), |
|
185 | 185 | 'content' => '[wpinv_history]', |
186 | 186 | 'icon' => 'fas fa-file-invoice', |
187 | 187 | ); |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function display_current_tab() { |
199 | 199 | |
200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
200 | + add_action('bp_template_content', array($this, 'handle_display_current_tab')); |
|
201 | + $template = apply_filters('bp_core_template_plugin', 'members/single/plugins'); |
|
202 | 202 | |
203 | - bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
|
203 | + bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template)); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @since 2.1.5 |
210 | 210 | */ |
211 | 211 | public function handle_display_current_tab() { |
212 | - echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
212 | + echo getpaid_prepare_user_content_tab($this->get_current_tab()); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | } |
@@ -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">'; |
|
75 | - echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', 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">'; |
|
75 | + echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', 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 | <div class="input-group-prepend"> |
@@ -179,44 +179,44 @@ discard block |
||
179 | 179 | |
180 | 180 | <?php |
181 | 181 | |
182 | - } else { |
|
183 | - echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); |
|
182 | + } else { |
|
183 | + echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); |
|
184 | 184 | |
185 | - ?> |
|
185 | + ?> |
|
186 | 186 | <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() ); ?>'> |
187 | 187 | <?php |
188 | - } |
|
188 | + } |
|
189 | 189 | |
190 | - printf( |
|
190 | + printf( |
|
191 | 191 | '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>', |
192 | - // translators: %s is the item subtotal. |
|
192 | + // translators: %s is the item subtotal. |
|
193 | 193 | sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) ) |
194 | 194 | ); |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - // Item quantity. |
|
198 | - if ( 'quantity' === $key ) { |
|
197 | + // Item quantity. |
|
198 | + if ( 'quantity' === $key ) { |
|
199 | 199 | |
200 | - if ( $item->allows_quantities() ) { |
|
201 | - ?> |
|
200 | + if ( $item->allows_quantities() ) { |
|
201 | + ?> |
|
202 | 202 | <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> |
203 | 203 | <?php |
204 | - } else { |
|
205 | - echo (float) $item->get_quantity(); |
|
206 | - echo ' '; |
|
207 | - ?> |
|
204 | + } else { |
|
205 | + echo (float) $item->get_quantity(); |
|
206 | + echo ' '; |
|
207 | + ?> |
|
208 | 208 | <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(); ?>'> |
209 | 209 | <?php |
210 | - } |
|
210 | + } |
|
211 | 211 | } |
212 | 212 | |
213 | - // Item sub total. |
|
214 | - if ( 'subtotal' === $key ) { |
|
215 | - echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
216 | - } |
|
213 | + // Item sub total. |
|
214 | + if ( 'subtotal' === $key ) { |
|
215 | + echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
216 | + } |
|
217 | 217 | |
218 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
219 | - ?> |
|
218 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
219 | + ?> |
|
220 | 220 | |
221 | 221 | </div> |
222 | 222 |
@@ -9,28 +9,28 @@ discard block |
||
9 | 9 | * @var GetPaid_Form_Item $item |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -do_action( 'getpaid_before_payment_form_cart_item', $form, $item ); |
|
14 | +do_action('getpaid_before_payment_form_cart_item', $form, $item); |
|
15 | 15 | |
16 | 16 | $currency = $form->get_currency(); |
17 | -$max_qty = wpinv_item_max_buyable_quantity( $item->get_id() ); |
|
17 | +$max_qty = wpinv_item_max_buyable_quantity($item->get_id()); |
|
18 | 18 | ?> |
19 | 19 | <div class='getpaid-payment-form-items-cart-item getpaid-<?php echo $item->is_required() ? 'required' : 'selectable'; ?> item-<?php echo (int) $item->get_id(); ?> border-bottom py-2 px-3'> |
20 | 20 | |
21 | 21 | <div class="form-row align-items-center needs-validation"> |
22 | 22 | |
23 | - <?php foreach ( array_keys( $columns ) as $key ) : ?> |
|
23 | + <?php foreach (array_keys($columns) as $key) : ?> |
|
24 | 24 | |
25 | - <div class="<?php echo 'name' === $key ? 'col-6' : 'col'; ?> <?php echo ( in_array( $key, array( 'subtotal', 'quantity', 'tax_rate' ), true ) ) ? 'd-none d-sm-block' : ''; ?> position-relative getpaid-form-cart-item-<?php echo esc_attr( $key ); ?> getpaid-form-cart-item-<?php echo esc_attr( $key ); ?>-<?php echo (int) $item->get_id(); ?>"> |
|
25 | + <div class="<?php echo 'name' === $key ? 'col-6' : 'col'; ?> <?php echo (in_array($key, array('subtotal', 'quantity', 'tax_rate'), true)) ? 'd-none d-sm-block' : ''; ?> position-relative getpaid-form-cart-item-<?php echo esc_attr($key); ?> getpaid-form-cart-item-<?php echo esc_attr($key); ?>-<?php echo (int) $item->get_id(); ?>"> |
|
26 | 26 | |
27 | 27 | <?php |
28 | 28 | |
29 | 29 | // Fires before printing a line item column. |
30 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
30 | + do_action("getpaid_form_cart_item_before_$key", $item, $form); |
|
31 | 31 | |
32 | 32 | // Item name. |
33 | - if ( 'name' === $key ) { |
|
33 | + if ('name' === $key) { |
|
34 | 34 | |
35 | 35 | |
36 | 36 | ob_start(); |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Add an optional description. |
39 | 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>'; |
|
41 | + if (!empty($description)) { |
|
42 | + echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post($description) . '</small>'; |
|
43 | 43 | } |
44 | 44 | |
45 | 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>'; |
|
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 | 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 | 55 | edit_post_link( |
56 | - __( 'Edit this item.', 'invoicing' ), |
|
56 | + __('Edit this item.', 'invoicing'), |
|
57 | 57 | '<small class="form-text text-muted">', |
58 | 58 | '</small>', |
59 | 59 | $item->get_id(), |
@@ -65,30 +65,30 @@ discard block |
||
65 | 65 | $description = ob_get_clean(); |
66 | 66 | |
67 | 67 | // Display the name. |
68 | - $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
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 ) { |
|
72 | + if ($has_featured_image) { |
|
73 | 73 | echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
74 | 74 | echo '<div class="getpaid-form-item-image-container mr-2">'; |
75 | - echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
75 | + echo get_the_post_thumbnail($item->get_id(), 'thumbnail', array('class' => 'getpaid-form-item-image mb-0')); |
|
76 | 76 | echo '</div>'; |
77 | 77 | echo '<div class="getpaid-form-item-name-container">'; |
78 | 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 ) ); |
|
82 | + if (!empty($description)) { |
|
83 | + printf('<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post($description)); |
|
84 | 84 | } |
85 | 85 | |
86 | - if ( $item->allows_quantities() ) { |
|
86 | + if ($item->allows_quantities()) { |
|
87 | 87 | printf( |
88 | 88 | '<small class="d-sm-none text-muted form-text">%s</small>', |
89 | 89 | sprintf( |
90 | 90 | // translators: %s is the item quantity. |
91 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
91 | + esc_html__('Qty %s', 'invoicing'), |
|
92 | 92 | sprintf( |
93 | 93 | '<input |
94 | 94 | type="number" |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | max="%s" |
101 | 101 | >', |
102 | 102 | (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
103 | - floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
103 | + floatval(null !== $max_qty ? $max_qty : 1000000000000) |
|
104 | 104 | ) |
105 | 105 | ) |
106 | 106 | ); |
@@ -109,70 +109,70 @@ discard block |
||
109 | 109 | '<small class="d-sm-none text-muted form-text">%s</small>', |
110 | 110 | sprintf( |
111 | 111 | // translators: %s is the item quantity. |
112 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
112 | + esc_html__('Qty %s', 'invoicing'), |
|
113 | 113 | (float) $item->get_quantity() |
114 | 114 | ) |
115 | 115 | ); |
116 | 116 | } |
117 | 117 | |
118 | - if ( $has_featured_image ) { |
|
118 | + if ($has_featured_image) { |
|
119 | 119 | echo '</div>'; |
120 | 120 | echo '</div>'; |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | 124 | // Item price. |
125 | - if ( 'price' === $key ) { |
|
125 | + if ('price' === $key) { |
|
126 | 126 | |
127 | 127 | // Set the currency position. |
128 | 128 | $position = wpinv_currency_position(); |
129 | 129 | |
130 | - if ( 'left_space' === $position ) { |
|
130 | + if ('left_space' === $position) { |
|
131 | 131 | $position = 'left'; |
132 | 132 | } |
133 | 133 | |
134 | - if ( 'right_space' === $position ) { |
|
134 | + if ('right_space' === $position) { |
|
135 | 135 | $position = 'right'; |
136 | 136 | } |
137 | 137 | |
138 | - if ( $item->user_can_set_their_price() ) { |
|
139 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
138 | + if ($item->user_can_set_their_price()) { |
|
139 | + $price = max((float) $item->get_price(), (float) $item->get_minimum_price()); |
|
140 | 140 | $minimum = (float) $item->get_minimum_price(); |
141 | 141 | $validate_minimum = ''; |
142 | 142 | $class = ''; |
143 | 143 | $data_minimum = ''; |
144 | 144 | |
145 | - if ( $minimum > 0 ) { |
|
145 | + if ($minimum > 0) { |
|
146 | 146 | $validate_minimum = sprintf( |
147 | 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 ) ) |
|
148 | + esc_attr__('The minimum allowed amount is %s', 'invoicing'), |
|
149 | + wp_strip_all_tags(wpinv_price($minimum, $currency)) |
|
150 | 150 | ); |
151 | 151 | |
152 | 152 | $class = 'getpaid-validate-minimum-amount'; |
153 | 153 | |
154 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
154 | + $data_minimum = "data-minimum-amount='" . esc_attr(getpaid_unstandardize_amount($minimum)) . "'"; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | ?> |
158 | 158 | <div class="input-group input-group-sm"> |
159 | - <?php if ( 'left' === $position ) : ?> |
|
159 | + <?php if ('left' === $position) : ?> |
|
160 | 160 | <div class="input-group-prepend"> |
161 | - <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span> |
|
161 | + <span class="input-group-text"><?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span> |
|
162 | 162 | </div> |
163 | 163 | <?php endif; ?> |
164 | 164 | |
165 | - <input type="text" <?php echo wp_kses_post( $data_minimum ); ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo esc_attr( getpaid_unstandardize_amount( $price ) ); ?>" placeholder="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price() ) ); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo esc_attr( $class ); ?>" style="width: 64px; line-height: 1; min-height: 35px;"> |
|
165 | + <input type="text" <?php echo wp_kses_post($data_minimum); ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo esc_attr(getpaid_unstandardize_amount($price)); ?>" placeholder="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_minimum_price())); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo esc_attr($class); ?>" style="width: 64px; line-height: 1; min-height: 35px;"> |
|
166 | 166 | |
167 | - <?php if ( ! empty( $validate_minimum ) ) : ?> |
|
167 | + <?php if (!empty($validate_minimum)) : ?> |
|
168 | 168 | <div class="invalid-tooltip"> |
169 | - <?php echo wp_kses_post( $validate_minimum ); ?> |
|
169 | + <?php echo wp_kses_post($validate_minimum); ?> |
|
170 | 170 | </div> |
171 | 171 | <?php endif; ?> |
172 | 172 | |
173 | - <?php if ( 'left' !== $position ) : ?> |
|
173 | + <?php if ('left' !== $position) : ?> |
|
174 | 174 | <div class="input-group-append"> |
175 | - <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span> |
|
175 | + <span class="input-group-text"><?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span> |
|
176 | 176 | </div> |
177 | 177 | <?php endif; ?> |
178 | 178 | </div> |
@@ -180,24 +180,24 @@ discard block |
||
180 | 180 | <?php |
181 | 181 | |
182 | 182 | } else { |
183 | - echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); |
|
183 | + echo wp_kses_post(wpinv_price($item->get_price(), $currency)); |
|
184 | 184 | |
185 | 185 | ?> |
186 | - <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() ); ?>'> |
|
186 | + <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()); ?>'> |
|
187 | 187 | <?php |
188 | 188 | } |
189 | 189 | |
190 | 190 | printf( |
191 | 191 | '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>', |
192 | 192 | // translators: %s is the item subtotal. |
193 | - sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) ) |
|
193 | + sprintf(esc_html__('Subtotal: %s', 'invoicing'), wp_kses_post(wpinv_price($item->get_sub_total(), $currency))) |
|
194 | 194 | ); |
195 | 195 | } |
196 | 196 | |
197 | 197 | // Item quantity. |
198 | - if ( 'quantity' === $key ) { |
|
198 | + if ('quantity' === $key) { |
|
199 | 199 | |
200 | - if ( $item->allows_quantities() ) { |
|
200 | + if ($item->allows_quantities()) { |
|
201 | 201 | ?> |
202 | 202 | <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> |
203 | 203 | <?php |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | } |
212 | 212 | |
213 | 213 | // Item sub total. |
214 | - if ( 'subtotal' === $key ) { |
|
215 | - echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
214 | + if ('subtotal' === $key) { |
|
215 | + echo wp_kses_post(wpinv_price($item->get_sub_total(), $currency)); |
|
216 | 216 | } |
217 | 217 | |
218 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
218 | + do_action("getpaid_payment_form_cart_item_$key", $item, $form); |
|
219 | 219 | ?> |
220 | 220 | |
221 | 221 | </div> |
@@ -226,4 +226,4 @@ discard block |
||
226 | 226 | |
227 | 227 | </div> |
228 | 228 | <?php |
229 | -do_action( 'getpaid_payment_form_cart_item', $form, $item ); |
|
229 | +do_action('getpaid_payment_form_cart_item', $form, $item); |