@@ -14,94 +14,94 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
29 | - |
|
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | + |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct() { |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct() { |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) ); |
|
68 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
69 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
70 | 70 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
71 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
77 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
78 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
79 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
80 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
81 | - |
|
82 | - // Setup/welcome |
|
83 | - if ( ! empty( $_GET['page'] ) ) { |
|
84 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
85 | - case 'gp-setup': |
|
86 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
87 | - break; |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Register admin scripts |
|
95 | - * |
|
96 | - */ |
|
97 | - public function enqeue_scripts() { |
|
71 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
75 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
76 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
77 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
78 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
79 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
80 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
81 | + |
|
82 | + // Setup/welcome |
|
83 | + if ( ! empty( $_GET['page'] ) ) { |
|
84 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
85 | + case 'gp-setup': |
|
86 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
87 | + break; |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Register admin scripts |
|
95 | + * |
|
96 | + */ |
|
97 | + public function enqeue_scripts() { |
|
98 | 98 | global $current_screen, $pagenow; |
99 | 99 | |
100 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
101 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
100 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
101 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
102 | 102 | |
103 | 103 | if ( ! empty( $current_screen->post_type ) ) { |
104 | - $page = $current_screen->post_type; |
|
104 | + $page = $current_screen->post_type; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // General styles. |
@@ -122,53 +122,53 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | // Payment form scripts. |
125 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
125 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
126 | 126 | $this->load_payment_form_scripts(); |
127 | 127 | } |
128 | 128 | |
129 | - if ( $page == 'wpinv-subscriptions' ) { |
|
130 | - wp_enqueue_script( 'postbox' ); |
|
131 | - } |
|
129 | + if ( $page == 'wpinv-subscriptions' ) { |
|
130 | + wp_enqueue_script( 'postbox' ); |
|
131 | + } |
|
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Returns admin js translations. |
|
137 | - * |
|
138 | - */ |
|
139 | - protected function get_admin_i18() { |
|
136 | + * Returns admin js translations. |
|
137 | + * |
|
138 | + */ |
|
139 | + protected function get_admin_i18() { |
|
140 | 140 | global $post; |
141 | 141 | |
142 | - $date_range = array( |
|
143 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
144 | - ); |
|
142 | + $date_range = array( |
|
143 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
144 | + ); |
|
145 | 145 | |
146 | - if ( $date_range['period'] == 'custom' ) { |
|
146 | + if ( $date_range['period'] == 'custom' ) { |
|
147 | 147 | |
148 | - if ( isset( $_GET['from'] ) ) { |
|
149 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
150 | - } |
|
148 | + if ( isset( $_GET['from'] ) ) { |
|
149 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
150 | + } |
|
151 | 151 | |
152 | - if ( isset( $_GET['to'] ) ) { |
|
153 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
154 | - } |
|
152 | + if ( isset( $_GET['to'] ) ) { |
|
153 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | $i18n = array( |
158 | 158 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
159 | 159 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
160 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
161 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
162 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
163 | - 'date_range' => $date_range, |
|
160 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
161 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
162 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
163 | + 'date_range' => $date_range, |
|
164 | 164 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
165 | 165 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
166 | 166 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
167 | 167 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
168 | 168 | 'tax' => wpinv_tax_amount(), |
169 | 169 | 'discount' => 0, |
170 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
171 | - 'currency' => wpinv_get_currency(), |
|
170 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
171 | + 'currency' => wpinv_get_currency(), |
|
172 | 172 | 'currency_pos' => wpinv_currency_position(), |
173 | 173 | 'thousand_sep' => wpinv_thousands_separator(), |
174 | 174 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -188,117 +188,117 @@ discard block |
||
188 | 188 | 'item_description' => __( 'Item Description', 'invoicing' ), |
189 | 189 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
190 | 190 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
191 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
192 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
193 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
194 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
195 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
191 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
192 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
193 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
194 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
195 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
196 | 196 | ); |
197 | 197 | |
198 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
198 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
199 | 199 | |
200 | - $invoice = new WPInv_Invoice( $post ); |
|
201 | - $i18n['save_invoice'] = sprintf( |
|
202 | - __( 'Save %s', 'invoicing' ), |
|
203 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
204 | - ); |
|
200 | + $invoice = new WPInv_Invoice( $post ); |
|
201 | + $i18n['save_invoice'] = sprintf( |
|
202 | + __( 'Save %s', 'invoicing' ), |
|
203 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
204 | + ); |
|
205 | 205 | |
206 | - $i18n['invoice_description'] = sprintf( |
|
207 | - __( '%s Description', 'invoicing' ), |
|
208 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
209 | - ); |
|
206 | + $i18n['invoice_description'] = sprintf( |
|
207 | + __( '%s Description', 'invoicing' ), |
|
208 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
209 | + ); |
|
210 | 210 | |
211 | - } |
|
212 | - return $i18n; |
|
213 | - } |
|
211 | + } |
|
212 | + return $i18n; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Change the admin footer text on GetPaid admin pages. |
|
217 | - * |
|
218 | - * @since 2.0.0 |
|
219 | - * @param string $footer_text |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function admin_footer_text( $footer_text ) { |
|
223 | - global $current_screen; |
|
215 | + /** |
|
216 | + * Change the admin footer text on GetPaid admin pages. |
|
217 | + * |
|
218 | + * @since 2.0.0 |
|
219 | + * @param string $footer_text |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function admin_footer_text( $footer_text ) { |
|
223 | + global $current_screen; |
|
224 | 224 | |
225 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
225 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
226 | 226 | |
227 | 227 | if ( ! empty( $current_screen->post_type ) ) { |
228 | - $page = $current_screen->post_type; |
|
228 | + $page = $current_screen->post_type; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // General styles. |
232 | 232 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
233 | 233 | |
234 | - // Change the footer text |
|
235 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
234 | + // Change the footer text |
|
235 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
236 | 236 | |
237 | - $rating_url = esc_url( |
|
238 | - wp_nonce_url( |
|
239 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
240 | - 'getpaid-nonce', |
|
241 | - 'getpaid-nonce' |
|
237 | + $rating_url = esc_url( |
|
238 | + wp_nonce_url( |
|
239 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
240 | + 'getpaid-nonce', |
|
241 | + 'getpaid-nonce' |
|
242 | 242 | ) |
243 | - ); |
|
243 | + ); |
|
244 | 244 | |
245 | - $footer_text = sprintf( |
|
246 | - /* translators: %s: five stars */ |
|
247 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
248 | - "<a href='$rating_url'>★★★★★</a>" |
|
249 | - ); |
|
245 | + $footer_text = sprintf( |
|
246 | + /* translators: %s: five stars */ |
|
247 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
248 | + "<a href='$rating_url'>★★★★★</a>" |
|
249 | + ); |
|
250 | 250 | |
251 | - } else { |
|
251 | + } else { |
|
252 | 252 | |
253 | - $footer_text = sprintf( |
|
254 | - /* translators: %s: GetPaid */ |
|
255 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
256 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
257 | - ); |
|
253 | + $footer_text = sprintf( |
|
254 | + /* translators: %s: GetPaid */ |
|
255 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
256 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
257 | + ); |
|
258 | 258 | |
259 | - } |
|
259 | + } |
|
260 | 260 | } |
261 | 261 | |
262 | - return $footer_text; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Redirects to wp.org to rate the plugin. |
|
267 | - * |
|
268 | - * @since 2.0.0 |
|
269 | - */ |
|
270 | - public function redirect_to_wordpress_rating_page() { |
|
271 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
272 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
273 | - exit; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Loads payment form js. |
|
278 | - * |
|
279 | - */ |
|
280 | - protected function load_payment_form_scripts() { |
|
262 | + return $footer_text; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Redirects to wp.org to rate the plugin. |
|
267 | + * |
|
268 | + * @since 2.0.0 |
|
269 | + */ |
|
270 | + public function redirect_to_wordpress_rating_page() { |
|
271 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
272 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
273 | + exit; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Loads payment form js. |
|
278 | + * |
|
279 | + */ |
|
280 | + protected function load_payment_form_scripts() { |
|
281 | 281 | global $post; |
282 | 282 | |
283 | 283 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
284 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
285 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
284 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
285 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
286 | 286 | |
287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.min.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), WPINV_VERSION ); |
|
287 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.min.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), WPINV_VERSION ); |
|
288 | 288 | |
289 | - wp_localize_script( |
|
289 | + wp_localize_script( |
|
290 | 290 | 'wpinv-admin-payment-form-script', |
291 | 291 | 'wpinvPaymentFormAdmin', |
292 | 292 | array( |
293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | - 'currency' => wpinv_currency_symbol(), |
|
296 | - 'position' => wpinv_currency_position(), |
|
297 | - 'decimals' => (int) wpinv_decimals(), |
|
298 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
293 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | + 'currency' => wpinv_currency_symbol(), |
|
296 | + 'position' => wpinv_currency_position(), |
|
297 | + 'decimals' => (int) wpinv_decimals(), |
|
298 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
302 | 302 | ) |
303 | 303 | ); |
304 | 304 | |
@@ -307,19 +307,19 @@ discard block |
||
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | - * Add our classes to admin pages. |
|
310 | + * Add our classes to admin pages. |
|
311 | 311 | * |
312 | 312 | * @param string $classes |
313 | 313 | * @return string |
314 | - * |
|
315 | - */ |
|
314 | + * |
|
315 | + */ |
|
316 | 316 | public function admin_body_class( $classes ) { |
317 | - global $pagenow, $post, $current_screen; |
|
317 | + global $pagenow, $post, $current_screen; |
|
318 | 318 | |
319 | 319 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
320 | 320 | |
321 | 321 | if ( ! empty( $current_screen->post_type ) ) { |
322 | - $page = $current_screen->post_type; |
|
322 | + $page = $current_screen->post_type; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -328,70 +328,70 @@ discard block |
||
328 | 328 | |
329 | 329 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
330 | 330 | $classes .= ' wpinv-cpt wpinv'; |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
333 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
334 | 334 | $classes .= ' getpaid-is-invoice-cpt'; |
335 | 335 | } |
336 | 336 | |
337 | - return $classes; |
|
337 | + return $classes; |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
341 | - * Maybe show the AyeCode Connect Notice. |
|
342 | - */ |
|
343 | - public function init_ayecode_connect_helper() { |
|
341 | + * Maybe show the AyeCode Connect Notice. |
|
342 | + */ |
|
343 | + public function init_ayecode_connect_helper() { |
|
344 | 344 | |
345 | - // Register with the deactivation survey class. |
|
346 | - AyeCode_Deactivation_Survey::instance( |
|
345 | + // Register with the deactivation survey class. |
|
346 | + AyeCode_Deactivation_Survey::instance( |
|
347 | 347 | array( |
348 | - 'slug' => 'invoicing', |
|
349 | - 'version' => WPINV_VERSION, |
|
350 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
348 | + 'slug' => 'invoicing', |
|
349 | + 'version' => WPINV_VERSION, |
|
350 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
353 | 353 | ) |
354 | 354 | ); |
355 | 355 | |
356 | 356 | new AyeCode_Connect_Helper( |
357 | 357 | array( |
358 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
358 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | + 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
365 | 365 | ), |
366 | 366 | array( 'wpi-addons' ) |
367 | 367 | ); |
368 | 368 | |
369 | 369 | } |
370 | 370 | |
371 | - /** |
|
372 | - * Redirect users to settings on activation. |
|
373 | - * |
|
374 | - * @return void |
|
375 | - */ |
|
376 | - public function activation_redirect() { |
|
371 | + /** |
|
372 | + * Redirect users to settings on activation. |
|
373 | + * |
|
374 | + * @return void |
|
375 | + */ |
|
376 | + public function activation_redirect() { |
|
377 | 377 | |
378 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
378 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
379 | 379 | |
380 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | - return; |
|
382 | - } |
|
380 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | 383 | |
384 | - // Bail if activating from network, or bulk |
|
385 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | - return; |
|
387 | - } |
|
384 | + // Bail if activating from network, or bulk |
|
385 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | + return; |
|
387 | + } |
|
388 | 388 | |
389 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
389 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
390 | 390 | |
391 | 391 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
392 | 392 | exit; |
393 | 393 | |
394 | - } |
|
394 | + } |
|
395 | 395 | |
396 | 396 | /** |
397 | 397 | * Fires an admin action after verifying that a user can fire them. |
@@ -404,555 +404,555 @@ discard block |
||
404 | 404 | } |
405 | 405 | } |
406 | 406 | |
407 | - /** |
|
407 | + /** |
|
408 | 408 | * Duplicate invoice. |
409 | - * |
|
410 | - * @param array $args |
|
409 | + * |
|
410 | + * @param array $args |
|
411 | 411 | */ |
412 | 412 | public function duplicate_invoice( $args ) { |
413 | 413 | |
414 | - if ( empty( $args['invoice_id'] ) ) { |
|
415 | - return; |
|
416 | - } |
|
414 | + if ( empty( $args['invoice_id'] ) ) { |
|
415 | + return; |
|
416 | + } |
|
417 | 417 | |
418 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
418 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
419 | 419 | |
420 | - if ( ! $invoice->exists() ) { |
|
421 | - return; |
|
422 | - } |
|
420 | + if ( ! $invoice->exists() ) { |
|
421 | + return; |
|
422 | + } |
|
423 | 423 | |
424 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
425 | - $new_invoice->save(); |
|
424 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
425 | + $new_invoice->save(); |
|
426 | 426 | |
427 | - if ( $new_invoice->exists() ) { |
|
427 | + if ( $new_invoice->exists() ) { |
|
428 | 428 | |
429 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
429 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
430 | 430 | |
431 | - wp_safe_redirect( |
|
432 | - add_query_arg( |
|
433 | - array( |
|
434 | - 'action' => 'edit', |
|
435 | - 'post' => $new_invoice->get_id(), |
|
436 | - ), |
|
437 | - admin_url( 'post.php' ) |
|
438 | - ) |
|
439 | - ); |
|
440 | - exit; |
|
431 | + wp_safe_redirect( |
|
432 | + add_query_arg( |
|
433 | + array( |
|
434 | + 'action' => 'edit', |
|
435 | + 'post' => $new_invoice->get_id(), |
|
436 | + ), |
|
437 | + admin_url( 'post.php' ) |
|
438 | + ) |
|
439 | + ); |
|
440 | + exit; |
|
441 | 441 | |
442 | - } |
|
442 | + } |
|
443 | 443 | |
444 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
444 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - /** |
|
448 | + /** |
|
449 | 449 | * Refund an invoice. |
450 | - * |
|
451 | - * @param array $args |
|
450 | + * |
|
451 | + * @param array $args |
|
452 | 452 | */ |
453 | 453 | public function refund_invoice( $args ) { |
454 | 454 | |
455 | - if ( empty( $args['invoice_id'] ) ) { |
|
456 | - return; |
|
457 | - } |
|
458 | - |
|
459 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
460 | - |
|
461 | - if ( ! $invoice->exists() || $invoice->is_refunded() ) { |
|
462 | - return; |
|
463 | - } |
|
464 | - |
|
465 | - $invoice->refund(); |
|
466 | - |
|
467 | - // Refund remotely. |
|
468 | - if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) { |
|
469 | - do_action( 'getpaid_refund_invoice_remotely', $invoice ); |
|
470 | - } |
|
471 | - |
|
472 | - // Cancel subscriptions. |
|
473 | - if ( ! empty( $args['getpaid_cancel_subscription'] ) ) { |
|
474 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
475 | - |
|
476 | - if ( ! empty( $subscriptions ) ) { |
|
477 | - if ( ! is_array( $subscriptions ) ) { |
|
478 | - $subscriptions = array( $subscriptions ); |
|
479 | - } |
|
480 | - |
|
481 | - foreach ( $subscriptions as $subscription ) { |
|
482 | - $subscription->cancel(); |
|
483 | - $invoice->add_system_note( |
|
484 | - sprintf( |
|
485 | - // translators: %s: subscription ID. |
|
486 | - __( 'Subscription #%s cancelled', 'invoicing' ), |
|
487 | - $subscription->get_id() |
|
488 | - ) |
|
489 | - ); |
|
490 | - } |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - // Add notice. |
|
495 | - $this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) ); |
|
496 | - |
|
497 | - // Redirect. |
|
498 | - wp_safe_redirect( |
|
499 | - remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) ) |
|
500 | - ); |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
455 | + if ( empty( $args['invoice_id'] ) ) { |
|
456 | + return; |
|
457 | + } |
|
458 | + |
|
459 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
460 | + |
|
461 | + if ( ! $invoice->exists() || $invoice->is_refunded() ) { |
|
462 | + return; |
|
463 | + } |
|
464 | + |
|
465 | + $invoice->refund(); |
|
466 | + |
|
467 | + // Refund remotely. |
|
468 | + if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) { |
|
469 | + do_action( 'getpaid_refund_invoice_remotely', $invoice ); |
|
470 | + } |
|
471 | + |
|
472 | + // Cancel subscriptions. |
|
473 | + if ( ! empty( $args['getpaid_cancel_subscription'] ) ) { |
|
474 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
475 | + |
|
476 | + if ( ! empty( $subscriptions ) ) { |
|
477 | + if ( ! is_array( $subscriptions ) ) { |
|
478 | + $subscriptions = array( $subscriptions ); |
|
479 | + } |
|
480 | + |
|
481 | + foreach ( $subscriptions as $subscription ) { |
|
482 | + $subscription->cancel(); |
|
483 | + $invoice->add_system_note( |
|
484 | + sprintf( |
|
485 | + // translators: %s: subscription ID. |
|
486 | + __( 'Subscription #%s cancelled', 'invoicing' ), |
|
487 | + $subscription->get_id() |
|
488 | + ) |
|
489 | + ); |
|
490 | + } |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + // Add notice. |
|
495 | + $this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) ); |
|
496 | + |
|
497 | + // Redirect. |
|
498 | + wp_safe_redirect( |
|
499 | + remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) ) |
|
500 | + ); |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | 504 | * Sends a payment reminder to a customer. |
505 | - * |
|
506 | - * @param array $args |
|
505 | + * |
|
506 | + * @param array $args |
|
507 | 507 | */ |
508 | 508 | public function duplicate_payment_form( $args ) { |
509 | 509 | |
510 | - if ( empty( $args['form_id'] ) ) { |
|
511 | - return; |
|
512 | - } |
|
513 | - |
|
514 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
510 | + if ( empty( $args['form_id'] ) ) { |
|
511 | + return; |
|
512 | + } |
|
515 | 513 | |
516 | - if ( ! $form->exists() ) { |
|
517 | - return; |
|
518 | - } |
|
514 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
519 | 515 | |
520 | - $new_form = new GetPaid_Payment_Form(); |
|
521 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
522 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
523 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
524 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
525 | - $new_form->save(); |
|
516 | + if ( ! $form->exists() ) { |
|
517 | + return; |
|
518 | + } |
|
526 | 519 | |
527 | - if ( $new_form->exists() ) { |
|
528 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
529 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
530 | - } else { |
|
531 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
532 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
533 | - } |
|
520 | + $new_form = new GetPaid_Payment_Form(); |
|
521 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
522 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
523 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
524 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
525 | + $new_form->save(); |
|
526 | + |
|
527 | + if ( $new_form->exists() ) { |
|
528 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
529 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
530 | + } else { |
|
531 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
532 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
533 | + } |
|
534 | 534 | |
535 | - wp_redirect( $url ); |
|
536 | - exit; |
|
537 | - } |
|
535 | + wp_redirect( $url ); |
|
536 | + exit; |
|
537 | + } |
|
538 | 538 | |
539 | - /** |
|
539 | + /** |
|
540 | 540 | * Resets form stats. |
541 | - * |
|
542 | - * @param array $args |
|
541 | + * |
|
542 | + * @param array $args |
|
543 | 543 | */ |
544 | 544 | public function reset_form_stats( $args ) { |
545 | 545 | |
546 | - if ( empty( $args['form_id'] ) ) { |
|
547 | - return; |
|
548 | - } |
|
546 | + if ( empty( $args['form_id'] ) ) { |
|
547 | + return; |
|
548 | + } |
|
549 | 549 | |
550 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
550 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
551 | 551 | |
552 | - if ( ! $form->exists() ) { |
|
553 | - return; |
|
554 | - } |
|
552 | + if ( ! $form->exists() ) { |
|
553 | + return; |
|
554 | + } |
|
555 | 555 | |
556 | - $form->set_earned( 0 ); |
|
557 | - $form->set_refunded( 0 ); |
|
558 | - $form->set_cancelled( 0 ); |
|
559 | - $form->set_failed( 0 ); |
|
560 | - $form->save(); |
|
556 | + $form->set_earned( 0 ); |
|
557 | + $form->set_refunded( 0 ); |
|
558 | + $form->set_cancelled( 0 ); |
|
559 | + $form->set_failed( 0 ); |
|
560 | + $form->save(); |
|
561 | 561 | |
562 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
562 | + $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
563 | 563 | |
564 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
565 | - exit; |
|
566 | - } |
|
564 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
565 | + exit; |
|
566 | + } |
|
567 | 567 | |
568 | - /** |
|
568 | + /** |
|
569 | 569 | * Sends a payment reminder to a customer. |
570 | - * |
|
571 | - * @param array $args |
|
570 | + * |
|
571 | + * @param array $args |
|
572 | 572 | */ |
573 | 573 | public function send_customer_invoice( $args ) { |
574 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
575 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
576 | - exit; |
|
577 | - } |
|
574 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
575 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
576 | + exit; |
|
577 | + } |
|
578 | 578 | |
579 | - /** |
|
579 | + /** |
|
580 | 580 | * Sends a payment reminder to a customer. |
581 | - * |
|
582 | - * @param array $args |
|
581 | + * |
|
582 | + * @param array $args |
|
583 | 583 | */ |
584 | 584 | public function send_customer_payment_reminder( $args ) { |
585 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
585 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
586 | 586 | |
587 | - if ( $sent ) { |
|
588 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
589 | - } else { |
|
590 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
591 | - } |
|
587 | + if ( $sent ) { |
|
588 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
589 | + } else { |
|
590 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
591 | + } |
|
592 | 592 | |
593 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
594 | - exit; |
|
595 | - } |
|
593 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
594 | + exit; |
|
595 | + } |
|
596 | 596 | |
597 | - /** |
|
597 | + /** |
|
598 | 598 | * Resets tax rates. |
599 | - * |
|
599 | + * |
|
600 | 600 | */ |
601 | 601 | public function admin_reset_tax_rates() { |
602 | 602 | |
603 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
604 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
605 | - exit; |
|
603 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
604 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
605 | + exit; |
|
606 | 606 | |
607 | - } |
|
607 | + } |
|
608 | 608 | |
609 | - /** |
|
609 | + /** |
|
610 | 610 | * Resets admin pages. |
611 | - * |
|
611 | + * |
|
612 | 612 | */ |
613 | 613 | public function admin_create_missing_pages() { |
614 | - $installer = new GetPaid_Installer(); |
|
615 | - $installer->create_pages(); |
|
616 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
617 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
618 | - exit; |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Refreshes the permalinks. |
|
623 | - */ |
|
624 | - public function admin_refresh_permalinks() { |
|
625 | - flush_rewrite_rules(); |
|
626 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
627 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
628 | - exit; |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
614 | + $installer = new GetPaid_Installer(); |
|
615 | + $installer->create_pages(); |
|
616 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
617 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
618 | + exit; |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Refreshes the permalinks. |
|
623 | + */ |
|
624 | + public function admin_refresh_permalinks() { |
|
625 | + flush_rewrite_rules(); |
|
626 | + $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
627 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
628 | + exit; |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | 632 | * Creates missing admin tables. |
633 | - * |
|
633 | + * |
|
634 | 634 | */ |
635 | 635 | public function admin_create_missing_tables() { |
636 | - global $wpdb; |
|
636 | + global $wpdb; |
|
637 | 637 | |
638 | - GetPaid_Installer::create_db_tables(); |
|
639 | - GetPaid_Installer::migrate_old_customers(); |
|
638 | + GetPaid_Installer::create_db_tables(); |
|
639 | + GetPaid_Installer::migrate_old_customers(); |
|
640 | 640 | |
641 | - if ( '' !== $wpdb->last_error ) { |
|
642 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
643 | - } else { |
|
644 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
645 | - } |
|
641 | + if ( '' !== $wpdb->last_error ) { |
|
642 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
643 | + } else { |
|
644 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
645 | + } |
|
646 | 646 | |
647 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
648 | - exit; |
|
649 | - } |
|
647 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
648 | + exit; |
|
649 | + } |
|
650 | 650 | |
651 | - /** |
|
651 | + /** |
|
652 | 652 | * Migrates old invoices to the new database tables. |
653 | - * |
|
653 | + * |
|
654 | 654 | */ |
655 | 655 | public function admin_migrate_old_invoices() { |
656 | 656 | |
657 | - // Migrate the invoices. |
|
658 | - $installer = new GetPaid_Installer(); |
|
659 | - $installer->migrate_old_invoices(); |
|
657 | + // Migrate the invoices. |
|
658 | + $installer = new GetPaid_Installer(); |
|
659 | + $installer->migrate_old_invoices(); |
|
660 | 660 | |
661 | - // Show an admin message. |
|
662 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
661 | + // Show an admin message. |
|
662 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
663 | 663 | |
664 | - // Redirect the admin. |
|
665 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
666 | - exit; |
|
664 | + // Redirect the admin. |
|
665 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
666 | + exit; |
|
667 | 667 | |
668 | - } |
|
668 | + } |
|
669 | 669 | |
670 | - /** |
|
670 | + /** |
|
671 | 671 | * Download customers. |
672 | - * |
|
672 | + * |
|
673 | 673 | */ |
674 | 674 | public function admin_download_customers() { |
675 | 675 | |
676 | - $output = fopen( 'php://output', 'w' ); |
|
676 | + $output = fopen( 'php://output', 'w' ); |
|
677 | 677 | |
678 | - if ( false === $output ) { |
|
679 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
680 | - } |
|
678 | + if ( false === $output ) { |
|
679 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
680 | + } |
|
681 | 681 | |
682 | - header( 'Content-Type:text/csv' ); |
|
683 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
682 | + header( 'Content-Type:text/csv' ); |
|
683 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
684 | 684 | |
685 | - /** @var GetPaid_Customer[] $customers */ |
|
686 | - $customers = getpaid_get_customers( array( 'number' => -1 ) ); |
|
687 | - $columns = array_keys( GetPaid_Customer_Data_Store::get_database_fields() ); |
|
685 | + /** @var GetPaid_Customer[] $customers */ |
|
686 | + $customers = getpaid_get_customers( array( 'number' => -1 ) ); |
|
687 | + $columns = array_keys( GetPaid_Customer_Data_Store::get_database_fields() ); |
|
688 | 688 | |
689 | - // Output the csv column headers. |
|
690 | - fputcsv( $output, $columns ); |
|
689 | + // Output the csv column headers. |
|
690 | + fputcsv( $output, $columns ); |
|
691 | 691 | |
692 | - // Loop through |
|
693 | - foreach ( $customers as $customer ) { |
|
692 | + // Loop through |
|
693 | + foreach ( $customers as $customer ) { |
|
694 | 694 | |
695 | - $row = array(); |
|
695 | + $row = array(); |
|
696 | 696 | |
697 | - foreach ( $columns as $column ) { |
|
698 | - $row[] = (string) maybe_serialize( $customer->get( $column, 'edit' ) ); |
|
699 | - } |
|
697 | + foreach ( $columns as $column ) { |
|
698 | + $row[] = (string) maybe_serialize( $customer->get( $column, 'edit' ) ); |
|
699 | + } |
|
700 | 700 | |
701 | - fputcsv( $output, $row ); |
|
702 | - } |
|
701 | + fputcsv( $output, $row ); |
|
702 | + } |
|
703 | 703 | |
704 | - fclose( $output ); |
|
705 | - exit; |
|
704 | + fclose( $output ); |
|
705 | + exit; |
|
706 | 706 | |
707 | - } |
|
707 | + } |
|
708 | 708 | |
709 | - /** |
|
709 | + /** |
|
710 | 710 | * Installs a plugin. |
711 | - * |
|
712 | - * @param array $data |
|
711 | + * |
|
712 | + * @param array $data |
|
713 | 713 | */ |
714 | 714 | public function admin_install_plugin( $data ) { |
715 | 715 | |
716 | - if ( ! empty( $data['plugins'] ) ) { |
|
717 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
718 | - wp_cache_flush(); |
|
716 | + if ( ! empty( $data['plugins'] ) ) { |
|
717 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
718 | + wp_cache_flush(); |
|
719 | 719 | |
720 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
721 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
722 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
723 | - $installed = $upgrader->install( $plugin_zip ); |
|
720 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
721 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
722 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
723 | + $installed = $upgrader->install( $plugin_zip ); |
|
724 | 724 | |
725 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
726 | - activate_plugin( $file, '', false, true ); |
|
727 | - } else { |
|
728 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
729 | - } |
|
725 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
726 | + activate_plugin( $file, '', false, true ); |
|
727 | + } else { |
|
728 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
729 | + } |
|
730 | 730 | } |
731 | 731 | } |
732 | 732 | |
733 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
734 | - wp_safe_redirect( $redirect ); |
|
735 | - exit; |
|
733 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
734 | + wp_safe_redirect( $redirect ); |
|
735 | + exit; |
|
736 | 736 | |
737 | - } |
|
737 | + } |
|
738 | 738 | |
739 | - /** |
|
739 | + /** |
|
740 | 740 | * Connects a gateway. |
741 | - * |
|
742 | - * @param array $data |
|
741 | + * |
|
742 | + * @param array $data |
|
743 | 743 | */ |
744 | 744 | public function admin_connect_gateway( $data ) { |
745 | 745 | |
746 | - if ( ! empty( $data['plugin'] ) ) { |
|
746 | + if ( ! empty( $data['plugin'] ) ) { |
|
747 | 747 | |
748 | - $gateway = sanitize_key( $data['plugin'] ); |
|
749 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
748 | + $gateway = sanitize_key( $data['plugin'] ); |
|
749 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
750 | 750 | |
751 | - if ( ! empty( $connect_url ) ) { |
|
752 | - wp_redirect( $connect_url ); |
|
753 | - exit; |
|
754 | - } |
|
751 | + if ( ! empty( $connect_url ) ) { |
|
752 | + wp_redirect( $connect_url ); |
|
753 | + exit; |
|
754 | + } |
|
755 | 755 | |
756 | - if ( 'stripe' == $data['plugin'] ) { |
|
757 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
758 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
759 | - wp_cache_flush(); |
|
756 | + if ( 'stripe' == $data['plugin'] ) { |
|
757 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
758 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
759 | + wp_cache_flush(); |
|
760 | 760 | |
761 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
762 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
763 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
764 | - $upgrader->install( $plugin_zip ); |
|
765 | - } |
|
761 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
762 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
763 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
764 | + $upgrader->install( $plugin_zip ); |
|
765 | + } |
|
766 | 766 | |
767 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
768 | - } |
|
767 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
768 | + } |
|
769 | 769 | |
770 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
771 | - if ( ! empty( $connect_url ) ) { |
|
772 | - wp_redirect( $connect_url ); |
|
773 | - exit; |
|
774 | - } |
|
770 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
771 | + if ( ! empty( $connect_url ) ) { |
|
772 | + wp_redirect( $connect_url ); |
|
773 | + exit; |
|
774 | + } |
|
775 | 775 | } |
776 | 776 | |
777 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
778 | - wp_safe_redirect( $redirect ); |
|
779 | - exit; |
|
777 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
778 | + wp_safe_redirect( $redirect ); |
|
779 | + exit; |
|
780 | 780 | |
781 | - } |
|
781 | + } |
|
782 | 782 | |
783 | - /** |
|
783 | + /** |
|
784 | 784 | * Recalculates discounts. |
785 | - * |
|
785 | + * |
|
786 | 786 | */ |
787 | 787 | public function admin_recalculate_discounts() { |
788 | - global $wpdb; |
|
788 | + global $wpdb; |
|
789 | 789 | |
790 | - // Fetch all invoices that have discount codes. |
|
791 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
792 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
790 | + // Fetch all invoices that have discount codes. |
|
791 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
792 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
793 | 793 | |
794 | - foreach ( $invoices as $invoice ) { |
|
794 | + foreach ( $invoices as $invoice ) { |
|
795 | 795 | |
796 | - $invoice = new WPInv_Invoice( $invoice ); |
|
796 | + $invoice = new WPInv_Invoice( $invoice ); |
|
797 | 797 | |
798 | - if ( ! $invoice->exists() ) { |
|
799 | - continue; |
|
800 | - } |
|
798 | + if ( ! $invoice->exists() ) { |
|
799 | + continue; |
|
800 | + } |
|
801 | 801 | |
802 | - // Abort if the discount does not exist or does not apply here. |
|
803 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
804 | - if ( ! $discount->exists() ) { |
|
805 | - continue; |
|
806 | - } |
|
802 | + // Abort if the discount does not exist or does not apply here. |
|
803 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
804 | + if ( ! $discount->exists() ) { |
|
805 | + continue; |
|
806 | + } |
|
807 | 807 | |
808 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
809 | - $invoice->recalculate_total(); |
|
808 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
809 | + $invoice->recalculate_total(); |
|
810 | 810 | |
811 | - if ( $invoice->get_total_discount() > 0 ) { |
|
812 | - $invoice->save(); |
|
813 | - } |
|
811 | + if ( $invoice->get_total_discount() > 0 ) { |
|
812 | + $invoice->save(); |
|
813 | + } |
|
814 | 814 | } |
815 | 815 | |
816 | - // Show an admin message. |
|
817 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
816 | + // Show an admin message. |
|
817 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
818 | 818 | |
819 | - // Redirect the admin. |
|
820 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
821 | - exit; |
|
819 | + // Redirect the admin. |
|
820 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
821 | + exit; |
|
822 | 822 | |
823 | - } |
|
823 | + } |
|
824 | 824 | |
825 | 825 | /** |
826 | - * Returns an array of admin notices. |
|
827 | - * |
|
828 | - * @since 1.0.19 |
|
826 | + * Returns an array of admin notices. |
|
827 | + * |
|
828 | + * @since 1.0.19 |
|
829 | 829 | * @return array |
830 | - */ |
|
831 | - public function get_notices() { |
|
832 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
830 | + */ |
|
831 | + public function get_notices() { |
|
832 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
833 | 833 | return is_array( $notices ) ? $notices : array(); |
834 | - } |
|
834 | + } |
|
835 | 835 | |
836 | - /** |
|
837 | - * Checks if we have any admin notices. |
|
838 | - * |
|
839 | - * @since 2.0.4 |
|
836 | + /** |
|
837 | + * Checks if we have any admin notices. |
|
838 | + * |
|
839 | + * @since 2.0.4 |
|
840 | 840 | * @return array |
841 | - */ |
|
842 | - public function has_notices() { |
|
843 | - return count( $this->get_notices() ) > 0; |
|
844 | - } |
|
845 | - |
|
846 | - /** |
|
847 | - * Clears all admin notices |
|
848 | - * |
|
849 | - * @access public |
|
850 | - * @since 1.0.19 |
|
851 | - */ |
|
852 | - public function clear_notices() { |
|
853 | - delete_option( 'wpinv_admin_notices' ); |
|
854 | - } |
|
855 | - |
|
856 | - /** |
|
857 | - * Saves a new admin notice |
|
858 | - * |
|
859 | - * @access public |
|
860 | - * @since 1.0.19 |
|
861 | - */ |
|
862 | - public function save_notice( $type, $message ) { |
|
863 | - $notices = $this->get_notices(); |
|
864 | - |
|
865 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
866 | - $notices[ $type ] = array(); |
|
867 | - } |
|
868 | - |
|
869 | - $notices[ $type ][] = $message; |
|
870 | - |
|
871 | - update_option( 'wpinv_admin_notices', $notices ); |
|
872 | - } |
|
873 | - |
|
874 | - /** |
|
875 | - * Displays a success notice |
|
876 | - * |
|
877 | - * @param string $msg The message to qeue. |
|
878 | - * @access public |
|
879 | - * @since 1.0.19 |
|
880 | - */ |
|
881 | - public function show_success( $msg ) { |
|
882 | - $this->save_notice( 'success', $msg ); |
|
883 | - } |
|
884 | - |
|
885 | - /** |
|
886 | - * Displays a error notice |
|
887 | - * |
|
888 | - * @access public |
|
889 | - * @param string $msg The message to qeue. |
|
890 | - * @since 1.0.19 |
|
891 | - */ |
|
892 | - public function show_error( $msg ) { |
|
893 | - $this->save_notice( 'error', $msg ); |
|
894 | - } |
|
895 | - |
|
896 | - /** |
|
897 | - * Displays a warning notice |
|
898 | - * |
|
899 | - * @access public |
|
900 | - * @param string $msg The message to qeue. |
|
901 | - * @since 1.0.19 |
|
902 | - */ |
|
903 | - public function show_warning( $msg ) { |
|
904 | - $this->save_notice( 'warning', $msg ); |
|
905 | - } |
|
906 | - |
|
907 | - /** |
|
908 | - * Displays a info notice |
|
909 | - * |
|
910 | - * @access public |
|
911 | - * @param string $msg The message to qeue. |
|
912 | - * @since 1.0.19 |
|
913 | - */ |
|
914 | - public function show_info( $msg ) { |
|
915 | - $this->save_notice( 'info', $msg ); |
|
916 | - } |
|
917 | - |
|
918 | - /** |
|
919 | - * Show notices |
|
920 | - * |
|
921 | - * @access public |
|
922 | - * @since 1.0.19 |
|
923 | - */ |
|
924 | - public function show_notices() { |
|
841 | + */ |
|
842 | + public function has_notices() { |
|
843 | + return count( $this->get_notices() ) > 0; |
|
844 | + } |
|
845 | + |
|
846 | + /** |
|
847 | + * Clears all admin notices |
|
848 | + * |
|
849 | + * @access public |
|
850 | + * @since 1.0.19 |
|
851 | + */ |
|
852 | + public function clear_notices() { |
|
853 | + delete_option( 'wpinv_admin_notices' ); |
|
854 | + } |
|
855 | + |
|
856 | + /** |
|
857 | + * Saves a new admin notice |
|
858 | + * |
|
859 | + * @access public |
|
860 | + * @since 1.0.19 |
|
861 | + */ |
|
862 | + public function save_notice( $type, $message ) { |
|
863 | + $notices = $this->get_notices(); |
|
864 | + |
|
865 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
866 | + $notices[ $type ] = array(); |
|
867 | + } |
|
868 | + |
|
869 | + $notices[ $type ][] = $message; |
|
870 | + |
|
871 | + update_option( 'wpinv_admin_notices', $notices ); |
|
872 | + } |
|
873 | + |
|
874 | + /** |
|
875 | + * Displays a success notice |
|
876 | + * |
|
877 | + * @param string $msg The message to qeue. |
|
878 | + * @access public |
|
879 | + * @since 1.0.19 |
|
880 | + */ |
|
881 | + public function show_success( $msg ) { |
|
882 | + $this->save_notice( 'success', $msg ); |
|
883 | + } |
|
884 | + |
|
885 | + /** |
|
886 | + * Displays a error notice |
|
887 | + * |
|
888 | + * @access public |
|
889 | + * @param string $msg The message to qeue. |
|
890 | + * @since 1.0.19 |
|
891 | + */ |
|
892 | + public function show_error( $msg ) { |
|
893 | + $this->save_notice( 'error', $msg ); |
|
894 | + } |
|
895 | + |
|
896 | + /** |
|
897 | + * Displays a warning notice |
|
898 | + * |
|
899 | + * @access public |
|
900 | + * @param string $msg The message to qeue. |
|
901 | + * @since 1.0.19 |
|
902 | + */ |
|
903 | + public function show_warning( $msg ) { |
|
904 | + $this->save_notice( 'warning', $msg ); |
|
905 | + } |
|
906 | + |
|
907 | + /** |
|
908 | + * Displays a info notice |
|
909 | + * |
|
910 | + * @access public |
|
911 | + * @param string $msg The message to qeue. |
|
912 | + * @since 1.0.19 |
|
913 | + */ |
|
914 | + public function show_info( $msg ) { |
|
915 | + $this->save_notice( 'info', $msg ); |
|
916 | + } |
|
917 | + |
|
918 | + /** |
|
919 | + * Show notices |
|
920 | + * |
|
921 | + * @access public |
|
922 | + * @since 1.0.19 |
|
923 | + */ |
|
924 | + public function show_notices() { |
|
925 | 925 | |
926 | 926 | $notices = $this->get_notices(); |
927 | 927 | $this->clear_notices(); |
928 | 928 | |
929 | - foreach ( $notices as $type => $messages ) { |
|
929 | + foreach ( $notices as $type => $messages ) { |
|
930 | 930 | |
931 | - if ( ! is_array( $messages ) ) { |
|
932 | - continue; |
|
933 | - } |
|
931 | + if ( ! is_array( $messages ) ) { |
|
932 | + continue; |
|
933 | + } |
|
934 | 934 | |
935 | 935 | $type = esc_attr( $type ); |
936 | - foreach ( $messages as $message ) { |
|
937 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
936 | + foreach ( $messages as $message ) { |
|
937 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
938 | 938 | } |
939 | 939 | } |
940 | 940 | |
941 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
942 | - |
|
943 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
944 | - $url = wp_nonce_url( |
|
945 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
946 | - 'getpaid-nonce', |
|
947 | - 'getpaid-nonce' |
|
948 | - ); |
|
949 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
950 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
951 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
952 | - break; |
|
953 | - } |
|
941 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
942 | + |
|
943 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
944 | + $url = wp_nonce_url( |
|
945 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
946 | + 'getpaid-nonce', |
|
947 | + 'getpaid-nonce' |
|
948 | + ); |
|
949 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
950 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
951 | + echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
952 | + break; |
|
953 | + } |
|
954 | 954 | } |
955 | 955 | |
956 | - } |
|
956 | + } |
|
957 | 957 | |
958 | 958 | } |
@@ -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,36 +54,36 @@ 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_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
77 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
78 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
79 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
80 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
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_reset_form_stats', array($this, 'reset_form_stats')); |
|
66 | + add_action('getpaid_authenticated_admin_action_duplicate_invoice', array($this, 'duplicate_invoice')); |
|
67 | + add_action('getpaid_authenticated_admin_action_refund_invoice', array($this, 'refund_invoice')); |
|
68 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
69 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
70 | + add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates')); |
|
71 | + add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages')); |
|
72 | + add_action('getpaid_authenticated_admin_action_refresh_permalinks', array($this, 'admin_refresh_permalinks')); |
|
73 | + add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables')); |
|
74 | + add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices')); |
|
75 | + add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers')); |
|
76 | + add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts')); |
|
77 | + add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin')); |
|
78 | + add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway')); |
|
79 | + add_filter('admin_footer_text', array($this, 'admin_footer_text')); |
|
80 | + do_action('getpaid_init_admin_hooks', $this); |
|
81 | 81 | |
82 | 82 | // Setup/welcome |
83 | - if ( ! empty( $_GET['page'] ) ) { |
|
84 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
83 | + if (!empty($_GET['page'])) { |
|
84 | + switch (sanitize_text_field($_GET['page'])) { |
|
85 | 85 | case 'gp-setup': |
86 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
86 | + include_once dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php'; |
|
87 | 87 | break; |
88 | 88 | } |
89 | 89 | } |
@@ -97,37 +97,37 @@ discard block |
||
97 | 97 | public function enqeue_scripts() { |
98 | 98 | global $current_screen, $pagenow; |
99 | 99 | |
100 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
100 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
101 | 101 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
102 | 102 | |
103 | - if ( ! empty( $current_screen->post_type ) ) { |
|
103 | + if (!empty($current_screen->post_type)) { |
|
104 | 104 | $page = $current_screen->post_type; |
105 | 105 | } |
106 | 106 | |
107 | 107 | // General styles. |
108 | - if ( false !== stripos( $page, 'wpi' ) || false !== stripos( $page, 'getpaid' ) || 'gp-setup' == $page || false !== stripos( $page, 'geodir-tickets' ) ) { |
|
108 | + if (false !== stripos($page, 'wpi') || false !== stripos($page, 'getpaid') || 'gp-setup' == $page || false !== stripos($page, 'geodir-tickets')) { |
|
109 | 109 | |
110 | 110 | // Styles. |
111 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
112 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
113 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
111 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
112 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
113 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
114 | 114 | |
115 | 115 | // Scripts. |
116 | - wp_enqueue_script( 'select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
116 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
117 | 117 | |
118 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
119 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ), $version ); |
|
120 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
118 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
119 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version); |
|
120 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
121 | 121 | |
122 | 122 | } |
123 | 123 | |
124 | 124 | // Payment form scripts. |
125 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
125 | + if ('wpi_payment_form' == $page && $editing) { |
|
126 | 126 | $this->load_payment_form_scripts(); |
127 | 127 | } |
128 | 128 | |
129 | - if ( $page == 'wpinv-subscriptions' ) { |
|
130 | - wp_enqueue_script( 'postbox' ); |
|
129 | + if ($page == 'wpinv-subscriptions') { |
|
130 | + wp_enqueue_script('postbox'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | } |
@@ -140,31 +140,31 @@ discard block |
||
140 | 140 | global $post; |
141 | 141 | |
142 | 142 | $date_range = array( |
143 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
143 | + 'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days', |
|
144 | 144 | ); |
145 | 145 | |
146 | - if ( $date_range['period'] == 'custom' ) { |
|
146 | + if ($date_range['period'] == 'custom') { |
|
147 | 147 | |
148 | - if ( isset( $_GET['from'] ) ) { |
|
149 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
148 | + if (isset($_GET['from'])) { |
|
149 | + $date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS); |
|
150 | 150 | } |
151 | 151 | |
152 | - if ( isset( $_GET['to'] ) ) { |
|
153 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
152 | + if (isset($_GET['to'])) { |
|
153 | + $date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | 157 | $i18n = array( |
158 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
159 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
160 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
161 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
162 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
158 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
159 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
160 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
161 | + 'rest_nonce' => wp_create_nonce('wp_rest'), |
|
162 | + 'rest_root' => esc_url_raw(rest_url()), |
|
163 | 163 | 'date_range' => $date_range, |
164 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
165 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
166 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
167 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
164 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
165 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
166 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
167 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
168 | 168 | 'tax' => wpinv_tax_amount(), |
169 | 169 | 'discount' => 0, |
170 | 170 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -173,39 +173,39 @@ discard block |
||
173 | 173 | 'thousand_sep' => wpinv_thousands_separator(), |
174 | 174 | 'decimal_sep' => wpinv_decimal_separator(), |
175 | 175 | 'decimals' => wpinv_decimals(), |
176 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
177 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
178 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
179 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
180 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
181 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
182 | - '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' ), |
|
183 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
184 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
185 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
186 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
187 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
188 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
189 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
190 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
191 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
192 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
193 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
194 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
195 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
176 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
177 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
178 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
179 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
180 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
181 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
182 | + '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'), |
|
183 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
184 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
185 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
186 | + 'action_edit' => __('Edit', 'invoicing'), |
|
187 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
188 | + 'item_description' => __('Item Description', 'invoicing'), |
|
189 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
190 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
191 | + 'searching' => __('Searching', 'invoicing'), |
|
192 | + 'loading' => __('Loading...', 'invoicing'), |
|
193 | + 'search_customers' => __('Enter customer name or email', 'invoicing'), |
|
194 | + 'search_items' => __('Enter item name', 'invoicing'), |
|
195 | + 'graphs' => array_merge(array('refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'), array_keys(wpinv_get_report_graphs())), |
|
196 | 196 | ); |
197 | 197 | |
198 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
198 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
199 | 199 | |
200 | - $invoice = new WPInv_Invoice( $post ); |
|
200 | + $invoice = new WPInv_Invoice($post); |
|
201 | 201 | $i18n['save_invoice'] = sprintf( |
202 | - __( 'Save %s', 'invoicing' ), |
|
203 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
202 | + __('Save %s', 'invoicing'), |
|
203 | + ucfirst($invoice->get_invoice_quote_type()) |
|
204 | 204 | ); |
205 | 205 | |
206 | 206 | $i18n['invoice_description'] = sprintf( |
207 | - __( '%s Description', 'invoicing' ), |
|
208 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
207 | + __('%s Description', 'invoicing'), |
|
208 | + ucfirst($invoice->get_invoice_quote_type()) |
|
209 | 209 | ); |
210 | 210 | |
211 | 211 | } |
@@ -219,24 +219,24 @@ discard block |
||
219 | 219 | * @param string $footer_text |
220 | 220 | * @return string |
221 | 221 | */ |
222 | - public function admin_footer_text( $footer_text ) { |
|
222 | + public function admin_footer_text($footer_text) { |
|
223 | 223 | global $current_screen; |
224 | 224 | |
225 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
225 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
226 | 226 | |
227 | - if ( ! empty( $current_screen->post_type ) ) { |
|
227 | + if (!empty($current_screen->post_type)) { |
|
228 | 228 | $page = $current_screen->post_type; |
229 | 229 | } |
230 | 230 | |
231 | 231 | // General styles. |
232 | - if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
|
232 | + if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) { |
|
233 | 233 | |
234 | 234 | // Change the footer text |
235 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
235 | + if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) { |
|
236 | 236 | |
237 | - $rating_url = esc_url( |
|
237 | + $rating_url = esc_url( |
|
238 | 238 | wp_nonce_url( |
239 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
239 | + admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'), |
|
240 | 240 | 'getpaid-nonce', |
241 | 241 | 'getpaid-nonce' |
242 | 242 | ) |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | |
245 | 245 | $footer_text = sprintf( |
246 | 246 | /* translators: %s: five stars */ |
247 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
247 | + __('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'), |
|
248 | 248 | "<a href='$rating_url'>★★★★★</a>" |
249 | 249 | ); |
250 | 250 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | |
253 | 253 | $footer_text = sprintf( |
254 | 254 | /* translators: %s: GetPaid */ |
255 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
255 | + __('Thank you for using %s!', 'invoicing'), |
|
256 | 256 | "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
257 | 257 | ); |
258 | 258 | |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | * @since 2.0.0 |
269 | 269 | */ |
270 | 270 | public function redirect_to_wordpress_rating_page() { |
271 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
272 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
271 | + update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1); |
|
272 | + wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post'); |
|
273 | 273 | exit; |
274 | 274 | } |
275 | 275 | |
@@ -280,29 +280,29 @@ discard block |
||
280 | 280 | protected function load_payment_form_scripts() { |
281 | 281 | global $post; |
282 | 282 | |
283 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
|
284 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
285 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
283 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION); |
|
284 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
285 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
286 | 286 | |
287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.min.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), WPINV_VERSION ); |
|
287 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.min.js', array('wpinv-admin-script', 'vue_draggable', 'wp-hooks'), WPINV_VERSION); |
|
288 | 288 | |
289 | 289 | wp_localize_script( |
290 | 290 | 'wpinv-admin-payment-form-script', |
291 | 291 | 'wpinvPaymentFormAdmin', |
292 | 292 | array( |
293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
293 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
294 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
295 | 295 | 'currency' => wpinv_currency_symbol(), |
296 | 296 | 'position' => wpinv_currency_position(), |
297 | 297 | 'decimals' => (int) wpinv_decimals(), |
298 | 298 | 'thousands_sep' => wpinv_thousands_separator(), |
299 | 299 | 'decimals_sep' => wpinv_decimal_separator(), |
300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
300 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
301 | 301 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
302 | 302 | ) |
303 | 303 | ); |
304 | 304 | |
305 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
305 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
306 | 306 | |
307 | 307 | } |
308 | 308 | |
@@ -313,24 +313,24 @@ discard block |
||
313 | 313 | * @return string |
314 | 314 | * |
315 | 315 | */ |
316 | - public function admin_body_class( $classes ) { |
|
316 | + public function admin_body_class($classes) { |
|
317 | 317 | global $pagenow, $post, $current_screen; |
318 | 318 | |
319 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
319 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
320 | 320 | |
321 | - if ( ! empty( $current_screen->post_type ) ) { |
|
321 | + if (!empty($current_screen->post_type)) { |
|
322 | 322 | $page = $current_screen->post_type; |
323 | 323 | } |
324 | 324 | |
325 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
326 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
325 | + if (false !== stripos($page, 'wpi')) { |
|
326 | + $classes .= ' wpi-' . sanitize_key($page); |
|
327 | 327 | } |
328 | 328 | |
329 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
329 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
330 | 330 | $classes .= ' wpinv-cpt wpinv'; |
331 | 331 | } |
332 | 332 | |
333 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
333 | + if (getpaid_is_invoice_post_type($page)) { |
|
334 | 334 | $classes .= ' getpaid-is-invoice-cpt'; |
335 | 335 | } |
336 | 336 | |
@@ -349,21 +349,21 @@ discard block |
||
349 | 349 | 'version' => WPINV_VERSION, |
350 | 350 | 'support_url' => 'https://wpgetpaid.com/support/', |
351 | 351 | 'documentation_url' => 'https://docs.wpgetpaid.com/', |
352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
352 | + 'activated' => (int) get_option('gepaid_installed_on'), |
|
353 | 353 | ) |
354 | 354 | ); |
355 | 355 | |
356 | 356 | new AyeCode_Connect_Helper( |
357 | 357 | array( |
358 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
358 | + 'connect_title' => __('WP Invoicing - an AyeCode product!', 'invoicing'), |
|
359 | + 'connect_external' => __('Please confirm you wish to connect your site?', 'invoicing'), |
|
360 | + 'connect' => sprintf(__('<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing'), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>'), |
|
361 | + 'connect_button' => __('Connect Site', 'invoicing'), |
|
362 | + 'connecting_button' => __('Connecting...', 'invoicing'), |
|
363 | + 'error_localhost' => __('This service will only work with a live domain, not a localhost.', 'invoicing'), |
|
364 | + 'error' => __('Something went wrong, please refresh and try again.', 'invoicing'), |
|
365 | 365 | ), |
366 | - array( 'wpi-addons' ) |
|
366 | + array('wpi-addons') |
|
367 | 367 | ); |
368 | 368 | |
369 | 369 | } |
@@ -375,20 +375,20 @@ discard block |
||
375 | 375 | */ |
376 | 376 | public function activation_redirect() { |
377 | 377 | |
378 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
378 | + $redirected = get_option('wpinv_redirected_to_settings'); |
|
379 | 379 | |
380 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
380 | + if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | 384 | // Bail if activating from network, or bulk |
385 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
385 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
386 | 386 | return; |
387 | 387 | } |
388 | 388 | |
389 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
389 | + update_option('wpinv_redirected_to_settings', 1); |
|
390 | 390 | |
391 | - wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
|
391 | + wp_safe_redirect(admin_url('index.php?page=gp-setup')); |
|
392 | 392 | exit; |
393 | 393 | |
394 | 394 | } |
@@ -397,10 +397,10 @@ discard block |
||
397 | 397 | * Fires an admin action after verifying that a user can fire them. |
398 | 398 | */ |
399 | 399 | public function maybe_do_admin_action() { |
400 | - if ( isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) && wpinv_current_user_can( sanitize_text_field( $_REQUEST['getpaid-admin-action'] ), $_REQUEST ) ) { |
|
401 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
400 | + if (isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce') && wpinv_current_user_can(sanitize_text_field($_REQUEST['getpaid-admin-action']), $_REQUEST)) { |
|
401 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
402 | 402 | |
403 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
403 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
404 | 404 | } |
405 | 405 | } |
406 | 406 | |
@@ -409,24 +409,24 @@ discard block |
||
409 | 409 | * |
410 | 410 | * @param array $args |
411 | 411 | */ |
412 | - public function duplicate_invoice( $args ) { |
|
412 | + public function duplicate_invoice($args) { |
|
413 | 413 | |
414 | - if ( empty( $args['invoice_id'] ) ) { |
|
414 | + if (empty($args['invoice_id'])) { |
|
415 | 415 | return; |
416 | 416 | } |
417 | 417 | |
418 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
418 | + $invoice = new WPInv_Invoice((int) $args['invoice_id']); |
|
419 | 419 | |
420 | - if ( ! $invoice->exists() ) { |
|
420 | + if (!$invoice->exists()) { |
|
421 | 421 | return; |
422 | 422 | } |
423 | 423 | |
424 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
424 | + $new_invoice = getpaid_duplicate_invoice($invoice); |
|
425 | 425 | $new_invoice->save(); |
426 | 426 | |
427 | - if ( $new_invoice->exists() ) { |
|
427 | + if ($new_invoice->exists()) { |
|
428 | 428 | |
429 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
429 | + getpaid_admin()->show_success(__('Invoice duplicated successfully.', 'invoicing')); |
|
430 | 430 | |
431 | 431 | wp_safe_redirect( |
432 | 432 | add_query_arg( |
@@ -434,14 +434,14 @@ discard block |
||
434 | 434 | 'action' => 'edit', |
435 | 435 | 'post' => $new_invoice->get_id(), |
436 | 436 | ), |
437 | - admin_url( 'post.php' ) |
|
437 | + admin_url('post.php') |
|
438 | 438 | ) |
439 | 439 | ); |
440 | 440 | exit; |
441 | 441 | |
442 | 442 | } |
443 | 443 | |
444 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
444 | + getpaid_admin()->show_error(__('There was an error duplicating this invoice. Please try again.', 'invoicing')); |
|
445 | 445 | |
446 | 446 | } |
447 | 447 | |
@@ -450,40 +450,40 @@ discard block |
||
450 | 450 | * |
451 | 451 | * @param array $args |
452 | 452 | */ |
453 | - public function refund_invoice( $args ) { |
|
453 | + public function refund_invoice($args) { |
|
454 | 454 | |
455 | - if ( empty( $args['invoice_id'] ) ) { |
|
455 | + if (empty($args['invoice_id'])) { |
|
456 | 456 | return; |
457 | 457 | } |
458 | 458 | |
459 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
459 | + $invoice = new WPInv_Invoice((int) $args['invoice_id']); |
|
460 | 460 | |
461 | - if ( ! $invoice->exists() || $invoice->is_refunded() ) { |
|
461 | + if (!$invoice->exists() || $invoice->is_refunded()) { |
|
462 | 462 | return; |
463 | 463 | } |
464 | 464 | |
465 | 465 | $invoice->refund(); |
466 | 466 | |
467 | 467 | // Refund remotely. |
468 | - if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) { |
|
469 | - do_action( 'getpaid_refund_invoice_remotely', $invoice ); |
|
468 | + if (getpaid_payment_gateway_supports($invoice->get_gateway(), 'refunds') && !empty($args['getpaid_refund_remote'])) { |
|
469 | + do_action('getpaid_refund_invoice_remotely', $invoice); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | // Cancel subscriptions. |
473 | - if ( ! empty( $args['getpaid_cancel_subscription'] ) ) { |
|
474 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
473 | + if (!empty($args['getpaid_cancel_subscription'])) { |
|
474 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
475 | 475 | |
476 | - if ( ! empty( $subscriptions ) ) { |
|
477 | - if ( ! is_array( $subscriptions ) ) { |
|
478 | - $subscriptions = array( $subscriptions ); |
|
476 | + if (!empty($subscriptions)) { |
|
477 | + if (!is_array($subscriptions)) { |
|
478 | + $subscriptions = array($subscriptions); |
|
479 | 479 | } |
480 | 480 | |
481 | - foreach ( $subscriptions as $subscription ) { |
|
481 | + foreach ($subscriptions as $subscription) { |
|
482 | 482 | $subscription->cancel(); |
483 | 483 | $invoice->add_system_note( |
484 | 484 | sprintf( |
485 | 485 | // translators: %s: subscription ID. |
486 | - __( 'Subscription #%s cancelled', 'invoicing' ), |
|
486 | + __('Subscription #%s cancelled', 'invoicing'), |
|
487 | 487 | $subscription->get_id() |
488 | 488 | ) |
489 | 489 | ); |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | } |
493 | 493 | |
494 | 494 | // Add notice. |
495 | - $this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) ); |
|
495 | + $this->show_success(__('Invoice refunded successfully.', 'invoicing')); |
|
496 | 496 | |
497 | 497 | // Redirect. |
498 | 498 | wp_safe_redirect( |
499 | - remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) ) |
|
499 | + remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote')) |
|
500 | 500 | ); |
501 | 501 | } |
502 | 502 | |
@@ -505,34 +505,34 @@ discard block |
||
505 | 505 | * |
506 | 506 | * @param array $args |
507 | 507 | */ |
508 | - public function duplicate_payment_form( $args ) { |
|
508 | + public function duplicate_payment_form($args) { |
|
509 | 509 | |
510 | - if ( empty( $args['form_id'] ) ) { |
|
510 | + if (empty($args['form_id'])) { |
|
511 | 511 | return; |
512 | 512 | } |
513 | 513 | |
514 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
514 | + $form = new GetPaid_Payment_Form((int) $args['form_id']); |
|
515 | 515 | |
516 | - if ( ! $form->exists() ) { |
|
516 | + if (!$form->exists()) { |
|
517 | 517 | return; |
518 | 518 | } |
519 | 519 | |
520 | 520 | $new_form = new GetPaid_Payment_Form(); |
521 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
522 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
523 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
524 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
521 | + $new_form->set_author($form->get_author('edit')); |
|
522 | + $new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing')); |
|
523 | + $new_form->set_elements($form->get_elements('edit')); |
|
524 | + $new_form->set_items($form->get_items('edit')); |
|
525 | 525 | $new_form->save(); |
526 | 526 | |
527 | - if ( $new_form->exists() ) { |
|
528 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
529 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
527 | + if ($new_form->exists()) { |
|
528 | + $this->show_success(__('Form duplicated successfully', 'invoicing')); |
|
529 | + $url = get_edit_post_link($new_form->get_id(), 'edit'); |
|
530 | 530 | } else { |
531 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
532 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
531 | + $this->show_error(__('Unable to duplicate form', 'invoicing')); |
|
532 | + $url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce')); |
|
533 | 533 | } |
534 | 534 | |
535 | - wp_redirect( $url ); |
|
535 | + wp_redirect($url); |
|
536 | 536 | exit; |
537 | 537 | } |
538 | 538 | |
@@ -541,27 +541,27 @@ discard block |
||
541 | 541 | * |
542 | 542 | * @param array $args |
543 | 543 | */ |
544 | - public function reset_form_stats( $args ) { |
|
544 | + public function reset_form_stats($args) { |
|
545 | 545 | |
546 | - if ( empty( $args['form_id'] ) ) { |
|
546 | + if (empty($args['form_id'])) { |
|
547 | 547 | return; |
548 | 548 | } |
549 | 549 | |
550 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
550 | + $form = new GetPaid_Payment_Form((int) $args['form_id']); |
|
551 | 551 | |
552 | - if ( ! $form->exists() ) { |
|
552 | + if (!$form->exists()) { |
|
553 | 553 | return; |
554 | 554 | } |
555 | 555 | |
556 | - $form->set_earned( 0 ); |
|
557 | - $form->set_refunded( 0 ); |
|
558 | - $form->set_cancelled( 0 ); |
|
559 | - $form->set_failed( 0 ); |
|
556 | + $form->set_earned(0); |
|
557 | + $form->set_refunded(0); |
|
558 | + $form->set_cancelled(0); |
|
559 | + $form->set_failed(0); |
|
560 | 560 | $form->save(); |
561 | 561 | |
562 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
562 | + $this->show_success(__('Form stats reset successfully', 'invoicing')); |
|
563 | 563 | |
564 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
564 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce'))); |
|
565 | 565 | exit; |
566 | 566 | } |
567 | 567 | |
@@ -570,9 +570,9 @@ discard block |
||
570 | 570 | * |
571 | 571 | * @param array $args |
572 | 572 | */ |
573 | - public function send_customer_invoice( $args ) { |
|
574 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
575 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
573 | + public function send_customer_invoice($args) { |
|
574 | + getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true); |
|
575 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
576 | 576 | exit; |
577 | 577 | } |
578 | 578 | |
@@ -581,16 +581,16 @@ discard block |
||
581 | 581 | * |
582 | 582 | * @param array $args |
583 | 583 | */ |
584 | - public function send_customer_payment_reminder( $args ) { |
|
585 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
584 | + public function send_customer_payment_reminder($args) { |
|
585 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
586 | 586 | |
587 | - if ( $sent ) { |
|
588 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
587 | + if ($sent) { |
|
588 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
589 | 589 | } else { |
590 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
590 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
591 | 591 | } |
592 | 592 | |
593 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
593 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
594 | 594 | exit; |
595 | 595 | } |
596 | 596 | |
@@ -600,8 +600,8 @@ discard block |
||
600 | 600 | */ |
601 | 601 | public function admin_reset_tax_rates() { |
602 | 602 | |
603 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
604 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
603 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
604 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
605 | 605 | exit; |
606 | 606 | |
607 | 607 | } |
@@ -613,8 +613,8 @@ discard block |
||
613 | 613 | public function admin_create_missing_pages() { |
614 | 614 | $installer = new GetPaid_Installer(); |
615 | 615 | $installer->create_pages(); |
616 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
617 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
616 | + $this->show_success(__('GetPaid pages updated.', 'invoicing')); |
|
617 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
618 | 618 | exit; |
619 | 619 | } |
620 | 620 | |
@@ -623,8 +623,8 @@ discard block |
||
623 | 623 | */ |
624 | 624 | public function admin_refresh_permalinks() { |
625 | 625 | flush_rewrite_rules(); |
626 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
627 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
626 | + $this->show_success(__('Permalinks refreshed.', 'invoicing')); |
|
627 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
628 | 628 | exit; |
629 | 629 | } |
630 | 630 | |
@@ -638,13 +638,13 @@ discard block |
||
638 | 638 | GetPaid_Installer::create_db_tables(); |
639 | 639 | GetPaid_Installer::migrate_old_customers(); |
640 | 640 | |
641 | - if ( '' !== $wpdb->last_error ) { |
|
642 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
641 | + if ('' !== $wpdb->last_error) { |
|
642 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
643 | 643 | } else { |
644 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
644 | + $this->show_success(__('Your GetPaid tables have been updated.', 'invoicing')); |
|
645 | 645 | } |
646 | 646 | |
647 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
647 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
648 | 648 | exit; |
649 | 649 | } |
650 | 650 | |
@@ -659,10 +659,10 @@ discard block |
||
659 | 659 | $installer->migrate_old_invoices(); |
660 | 660 | |
661 | 661 | // Show an admin message. |
662 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
662 | + $this->show_success(__('Your invoices have been migrated.', 'invoicing')); |
|
663 | 663 | |
664 | 664 | // Redirect the admin. |
665 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
665 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
666 | 666 | exit; |
667 | 667 | |
668 | 668 | } |
@@ -673,35 +673,35 @@ discard block |
||
673 | 673 | */ |
674 | 674 | public function admin_download_customers() { |
675 | 675 | |
676 | - $output = fopen( 'php://output', 'w' ); |
|
676 | + $output = fopen('php://output', 'w'); |
|
677 | 677 | |
678 | - if ( false === $output ) { |
|
679 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
678 | + if (false === $output) { |
|
679 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
680 | 680 | } |
681 | 681 | |
682 | - header( 'Content-Type:text/csv' ); |
|
683 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
682 | + header('Content-Type:text/csv'); |
|
683 | + header('Content-Disposition:attachment;filename=customers.csv'); |
|
684 | 684 | |
685 | 685 | /** @var GetPaid_Customer[] $customers */ |
686 | - $customers = getpaid_get_customers( array( 'number' => -1 ) ); |
|
687 | - $columns = array_keys( GetPaid_Customer_Data_Store::get_database_fields() ); |
|
686 | + $customers = getpaid_get_customers(array('number' => -1)); |
|
687 | + $columns = array_keys(GetPaid_Customer_Data_Store::get_database_fields()); |
|
688 | 688 | |
689 | 689 | // Output the csv column headers. |
690 | - fputcsv( $output, $columns ); |
|
690 | + fputcsv($output, $columns); |
|
691 | 691 | |
692 | 692 | // Loop through |
693 | - foreach ( $customers as $customer ) { |
|
693 | + foreach ($customers as $customer) { |
|
694 | 694 | |
695 | - $row = array(); |
|
695 | + $row = array(); |
|
696 | 696 | |
697 | - foreach ( $columns as $column ) { |
|
698 | - $row[] = (string) maybe_serialize( $customer->get( $column, 'edit' ) ); |
|
697 | + foreach ($columns as $column) { |
|
698 | + $row[] = (string) maybe_serialize($customer->get($column, 'edit')); |
|
699 | 699 | } |
700 | 700 | |
701 | - fputcsv( $output, $row ); |
|
701 | + fputcsv($output, $row); |
|
702 | 702 | } |
703 | 703 | |
704 | - fclose( $output ); |
|
704 | + fclose($output); |
|
705 | 705 | exit; |
706 | 706 | |
707 | 707 | } |
@@ -711,27 +711,27 @@ discard block |
||
711 | 711 | * |
712 | 712 | * @param array $data |
713 | 713 | */ |
714 | - public function admin_install_plugin( $data ) { |
|
714 | + public function admin_install_plugin($data) { |
|
715 | 715 | |
716 | - if ( ! empty( $data['plugins'] ) ) { |
|
716 | + if (!empty($data['plugins'])) { |
|
717 | 717 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
718 | 718 | wp_cache_flush(); |
719 | 719 | |
720 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
721 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
722 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
723 | - $installed = $upgrader->install( $plugin_zip ); |
|
720 | + foreach ($data['plugins'] as $slug => $file) { |
|
721 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip'); |
|
722 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
723 | + $installed = $upgrader->install($plugin_zip); |
|
724 | 724 | |
725 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
726 | - activate_plugin( $file, '', false, true ); |
|
725 | + if (!is_wp_error($installed) && $installed) { |
|
726 | + activate_plugin($file, '', false, true); |
|
727 | 727 | } else { |
728 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
728 | + wpinv_error_log($upgrader->skin->get_upgrade_messages(), false); |
|
729 | 729 | } |
730 | 730 | } |
731 | 731 | } |
732 | 732 | |
733 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
734 | - wp_safe_redirect( $redirect ); |
|
733 | + $redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php'); |
|
734 | + wp_safe_redirect($redirect); |
|
735 | 735 | exit; |
736 | 736 | |
737 | 737 | } |
@@ -741,41 +741,41 @@ discard block |
||
741 | 741 | * |
742 | 742 | * @param array $data |
743 | 743 | */ |
744 | - public function admin_connect_gateway( $data ) { |
|
744 | + public function admin_connect_gateway($data) { |
|
745 | 745 | |
746 | - if ( ! empty( $data['plugin'] ) ) { |
|
746 | + if (!empty($data['plugin'])) { |
|
747 | 747 | |
748 | - $gateway = sanitize_key( $data['plugin'] ); |
|
749 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
748 | + $gateway = sanitize_key($data['plugin']); |
|
749 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
750 | 750 | |
751 | - if ( ! empty( $connect_url ) ) { |
|
752 | - wp_redirect( $connect_url ); |
|
751 | + if (!empty($connect_url)) { |
|
752 | + wp_redirect($connect_url); |
|
753 | 753 | exit; |
754 | 754 | } |
755 | 755 | |
756 | - if ( 'stripe' == $data['plugin'] ) { |
|
756 | + if ('stripe' == $data['plugin']) { |
|
757 | 757 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
758 | 758 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
759 | 759 | wp_cache_flush(); |
760 | 760 | |
761 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
762 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
763 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
764 | - $upgrader->install( $plugin_zip ); |
|
761 | + if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) { |
|
762 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip'); |
|
763 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
764 | + $upgrader->install($plugin_zip); |
|
765 | 765 | } |
766 | 766 | |
767 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
767 | + activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true); |
|
768 | 768 | } |
769 | 769 | |
770 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
771 | - if ( ! empty( $connect_url ) ) { |
|
772 | - wp_redirect( $connect_url ); |
|
770 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
771 | + if (!empty($connect_url)) { |
|
772 | + wp_redirect($connect_url); |
|
773 | 773 | exit; |
774 | 774 | } |
775 | 775 | } |
776 | 776 | |
777 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
778 | - wp_safe_redirect( $redirect ); |
|
777 | + $redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
|
778 | + wp_safe_redirect($redirect); |
|
779 | 779 | exit; |
780 | 780 | |
781 | 781 | } |
@@ -789,35 +789,35 @@ discard block |
||
789 | 789 | |
790 | 790 | // Fetch all invoices that have discount codes. |
791 | 791 | $table = $wpdb->prefix . 'getpaid_invoices'; |
792 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
792 | + $invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''"); |
|
793 | 793 | |
794 | - foreach ( $invoices as $invoice ) { |
|
794 | + foreach ($invoices as $invoice) { |
|
795 | 795 | |
796 | - $invoice = new WPInv_Invoice( $invoice ); |
|
796 | + $invoice = new WPInv_Invoice($invoice); |
|
797 | 797 | |
798 | - if ( ! $invoice->exists() ) { |
|
798 | + if (!$invoice->exists()) { |
|
799 | 799 | continue; |
800 | 800 | } |
801 | 801 | |
802 | 802 | // Abort if the discount does not exist or does not apply here. |
803 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
804 | - if ( ! $discount->exists() ) { |
|
803 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
804 | + if (!$discount->exists()) { |
|
805 | 805 | continue; |
806 | 806 | } |
807 | 807 | |
808 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
808 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
809 | 809 | $invoice->recalculate_total(); |
810 | 810 | |
811 | - if ( $invoice->get_total_discount() > 0 ) { |
|
811 | + if ($invoice->get_total_discount() > 0) { |
|
812 | 812 | $invoice->save(); |
813 | 813 | } |
814 | 814 | } |
815 | 815 | |
816 | 816 | // Show an admin message. |
817 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
817 | + $this->show_success(__('Discounts have been recalculated.', 'invoicing')); |
|
818 | 818 | |
819 | 819 | // Redirect the admin. |
820 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
820 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
821 | 821 | exit; |
822 | 822 | |
823 | 823 | } |
@@ -829,8 +829,8 @@ discard block |
||
829 | 829 | * @return array |
830 | 830 | */ |
831 | 831 | public function get_notices() { |
832 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
833 | - return is_array( $notices ) ? $notices : array(); |
|
832 | + $notices = get_option('wpinv_admin_notices'); |
|
833 | + return is_array($notices) ? $notices : array(); |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | /** |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | * @return array |
841 | 841 | */ |
842 | 842 | public function has_notices() { |
843 | - return count( $this->get_notices() ) > 0; |
|
843 | + return count($this->get_notices()) > 0; |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -850,7 +850,7 @@ discard block |
||
850 | 850 | * @since 1.0.19 |
851 | 851 | */ |
852 | 852 | public function clear_notices() { |
853 | - delete_option( 'wpinv_admin_notices' ); |
|
853 | + delete_option('wpinv_admin_notices'); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -859,16 +859,16 @@ discard block |
||
859 | 859 | * @access public |
860 | 860 | * @since 1.0.19 |
861 | 861 | */ |
862 | - public function save_notice( $type, $message ) { |
|
862 | + public function save_notice($type, $message) { |
|
863 | 863 | $notices = $this->get_notices(); |
864 | 864 | |
865 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
866 | - $notices[ $type ] = array(); |
|
865 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
866 | + $notices[$type] = array(); |
|
867 | 867 | } |
868 | 868 | |
869 | - $notices[ $type ][] = $message; |
|
869 | + $notices[$type][] = $message; |
|
870 | 870 | |
871 | - update_option( 'wpinv_admin_notices', $notices ); |
|
871 | + update_option('wpinv_admin_notices', $notices); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | /** |
@@ -878,8 +878,8 @@ discard block |
||
878 | 878 | * @access public |
879 | 879 | * @since 1.0.19 |
880 | 880 | */ |
881 | - public function show_success( $msg ) { |
|
882 | - $this->save_notice( 'success', $msg ); |
|
881 | + public function show_success($msg) { |
|
882 | + $this->save_notice('success', $msg); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
@@ -889,8 +889,8 @@ discard block |
||
889 | 889 | * @param string $msg The message to qeue. |
890 | 890 | * @since 1.0.19 |
891 | 891 | */ |
892 | - public function show_error( $msg ) { |
|
893 | - $this->save_notice( 'error', $msg ); |
|
892 | + public function show_error($msg) { |
|
893 | + $this->save_notice('error', $msg); |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | /** |
@@ -900,8 +900,8 @@ discard block |
||
900 | 900 | * @param string $msg The message to qeue. |
901 | 901 | * @since 1.0.19 |
902 | 902 | */ |
903 | - public function show_warning( $msg ) { |
|
904 | - $this->save_notice( 'warning', $msg ); |
|
903 | + public function show_warning($msg) { |
|
904 | + $this->save_notice('warning', $msg); |
|
905 | 905 | } |
906 | 906 | |
907 | 907 | /** |
@@ -911,8 +911,8 @@ discard block |
||
911 | 911 | * @param string $msg The message to qeue. |
912 | 912 | * @since 1.0.19 |
913 | 913 | */ |
914 | - public function show_info( $msg ) { |
|
915 | - $this->save_notice( 'info', $msg ); |
|
914 | + public function show_info($msg) { |
|
915 | + $this->save_notice('info', $msg); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | /** |
@@ -926,29 +926,29 @@ discard block |
||
926 | 926 | $notices = $this->get_notices(); |
927 | 927 | $this->clear_notices(); |
928 | 928 | |
929 | - foreach ( $notices as $type => $messages ) { |
|
929 | + foreach ($notices as $type => $messages) { |
|
930 | 930 | |
931 | - if ( ! is_array( $messages ) ) { |
|
931 | + if (!is_array($messages)) { |
|
932 | 932 | continue; |
933 | 933 | } |
934 | 934 | |
935 | - $type = esc_attr( $type ); |
|
936 | - foreach ( $messages as $message ) { |
|
937 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
935 | + $type = esc_attr($type); |
|
936 | + foreach ($messages as $message) { |
|
937 | + echo wp_kses_post("<div class='notice notice-$type is-dismissible'><p>$message</p></div>"); |
|
938 | 938 | } |
939 | 939 | } |
940 | 940 | |
941 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
941 | + foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) { |
|
942 | 942 | |
943 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
944 | - $url = wp_nonce_url( |
|
945 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
943 | + if (!is_numeric(wpinv_get_option($page, false))) { |
|
944 | + $url = wp_nonce_url( |
|
945 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
946 | 946 | 'getpaid-nonce', |
947 | 947 | 'getpaid-nonce' |
948 | 948 | ); |
949 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
950 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
951 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
949 | + $message = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing'); |
|
950 | + $message2 = __('Generate Pages', 'invoicing'); |
|
951 | + echo wp_kses_post("<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"); |
|
952 | 952 | break; |
953 | 953 | } |
954 | 954 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Personal data exporters. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WPInv_Privacy_Exporters Class. |
@@ -17,39 +17,39 @@ discard block |
||
17 | 17 | * @param int $page Page. |
18 | 18 | * @return array An array of invoice data in name value pairs |
19 | 19 | */ |
20 | - public static function customer_invoice_data_exporter( $email_address, $page ) { |
|
20 | + public static function customer_invoice_data_exporter($email_address, $page) { |
|
21 | 21 | $done = false; |
22 | 22 | $page = (int) $page; |
23 | 23 | $data_to_export = array(); |
24 | 24 | |
25 | - $user = get_user_by( 'email', $email_address ); |
|
26 | - if ( ! $user instanceof WP_User ) { |
|
25 | + $user = get_user_by('email', $email_address); |
|
26 | + if (!$user instanceof WP_User) { |
|
27 | 27 | return array( |
28 | 28 | 'data' => $data_to_export, |
29 | 29 | 'done' => true, |
30 | 30 | ); |
31 | 31 | } |
32 | 32 | |
33 | - $args = array( |
|
34 | - 'limit' => get_option( 'posts_per_page' ), |
|
33 | + $args = array( |
|
34 | + 'limit' => get_option('posts_per_page'), |
|
35 | 35 | 'page' => $page, |
36 | 36 | 'user' => $user->ID, |
37 | 37 | 'paginate' => false, |
38 | 38 | ); |
39 | 39 | |
40 | - $invoices = wpinv_get_invoices( $args ); |
|
40 | + $invoices = wpinv_get_invoices($args); |
|
41 | 41 | |
42 | - if ( 0 < count( $invoices ) ) { |
|
43 | - foreach ( $invoices as $invoice ) { |
|
42 | + if (0 < count($invoices)) { |
|
43 | + foreach ($invoices as $invoice) { |
|
44 | 44 | $data_to_export[] = array( |
45 | 45 | 'group_id' => 'customer_invoices', |
46 | - 'group_label' => __( 'GetPaid: Invoices', 'invoicing' ), |
|
47 | - 'group_description' => __( 'Customer invoices.', 'invoicing' ), |
|
46 | + 'group_label' => __('GetPaid: Invoices', 'invoicing'), |
|
47 | + 'group_description' => __('Customer invoices.', 'invoicing'), |
|
48 | 48 | 'item_id' => "wpinv-{$invoice->get_id()}", |
49 | - 'data' => self::get_customer_invoice_data( $invoice ), |
|
49 | + 'data' => self::get_customer_invoice_data($invoice), |
|
50 | 50 | ); |
51 | 51 | } |
52 | - $done = get_option( 'posts_per_page' ) > count( $invoices ); |
|
52 | + $done = get_option('posts_per_page') > count($invoices); |
|
53 | 53 | } else { |
54 | 54 | $done = true; |
55 | 55 | } |
@@ -67,122 +67,122 @@ discard block |
||
67 | 67 | * @param WPInv_Invoice $invoice invoice object. |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public static function get_customer_invoice_data( $invoice ) { |
|
70 | + public static function get_customer_invoice_data($invoice) { |
|
71 | 71 | |
72 | 72 | // Prepare basic properties. |
73 | 73 | $props_to_export = array( |
74 | 74 | 'number' => array( |
75 | - 'name' => __( 'Invoice Number', 'invoicing' ), |
|
75 | + 'name' => __('Invoice Number', 'invoicing'), |
|
76 | 76 | 'value' => $invoice->get_number(), |
77 | 77 | ), |
78 | 78 | 'created_date' => array( |
79 | - 'name' => __( 'Created Date', 'invoicing' ), |
|
79 | + 'name' => __('Created Date', 'invoicing'), |
|
80 | 80 | 'value' => $invoice->get_date_created(), |
81 | 81 | ), |
82 | 82 | 'due_date' => array( |
83 | - 'name' => __( 'Due Date', 'invoicing' ), |
|
83 | + 'name' => __('Due Date', 'invoicing'), |
|
84 | 84 | 'value' => $invoice->get_due_date(), |
85 | 85 | ), |
86 | 86 | 'items' => array( |
87 | - 'name' => __( 'Invoice Items', 'invoicing' ), |
|
88 | - 'value' => self::process_invoice_items( $invoice ), |
|
87 | + 'name' => __('Invoice Items', 'invoicing'), |
|
88 | + 'value' => self::process_invoice_items($invoice), |
|
89 | 89 | ), |
90 | 90 | 'discount' => array( |
91 | - 'name' => __( 'Invoice Discount', 'invoicing' ), |
|
92 | - 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
91 | + 'name' => __('Invoice Discount', 'invoicing'), |
|
92 | + 'value' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
93 | 93 | ), |
94 | 94 | 'total' => array( |
95 | - 'name' => __( 'Invoice Total', 'invoicing' ), |
|
96 | - 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
95 | + 'name' => __('Invoice Total', 'invoicing'), |
|
96 | + 'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
97 | 97 | ), |
98 | 98 | 'status' => array( |
99 | - 'name' => __( 'Invoice Status', 'invoicing' ), |
|
99 | + 'name' => __('Invoice Status', 'invoicing'), |
|
100 | 100 | 'value' => $invoice->get_status_nicename(), |
101 | 101 | ), |
102 | 102 | 'first_name' => array( |
103 | - 'name' => __( 'First Name', 'invoicing' ), |
|
103 | + 'name' => __('First Name', 'invoicing'), |
|
104 | 104 | 'value' => $invoice->get_first_name(), |
105 | 105 | ), |
106 | 106 | 'last_name' => array( |
107 | - 'name' => __( 'Last Name', 'invoicing' ), |
|
107 | + 'name' => __('Last Name', 'invoicing'), |
|
108 | 108 | 'value' => $invoice->get_last_name(), |
109 | 109 | ), |
110 | 110 | 'email' => array( |
111 | - 'name' => __( 'Email Address', 'invoicing' ), |
|
111 | + 'name' => __('Email Address', 'invoicing'), |
|
112 | 112 | 'value' => $invoice->get_email(), |
113 | 113 | ), |
114 | 114 | 'company' => array( |
115 | - 'name' => __( 'Company', 'invoicing' ), |
|
115 | + 'name' => __('Company', 'invoicing'), |
|
116 | 116 | 'value' => $invoice->get_company(), |
117 | 117 | ), |
118 | 118 | 'phone' => array( |
119 | - 'name' => __( 'Phone Number', 'invoicing' ), |
|
119 | + 'name' => __('Phone Number', 'invoicing'), |
|
120 | 120 | 'value' => $invoice->get_phone(), |
121 | 121 | ), |
122 | 122 | 'address' => array( |
123 | - 'name' => __( 'Address', 'invoicing' ), |
|
123 | + 'name' => __('Address', 'invoicing'), |
|
124 | 124 | 'value' => $invoice->get_address(), |
125 | 125 | ), |
126 | 126 | 'city' => array( |
127 | - 'name' => __( 'City', 'invoicing' ), |
|
127 | + 'name' => __('City', 'invoicing'), |
|
128 | 128 | 'value' => $invoice->get_city(), |
129 | 129 | ), |
130 | 130 | 'state' => array( |
131 | - 'name' => __( 'State', 'invoicing' ), |
|
131 | + 'name' => __('State', 'invoicing'), |
|
132 | 132 | 'value' => $invoice->get_state(), |
133 | 133 | ), |
134 | 134 | 'zip' => array( |
135 | - 'name' => __( 'Zip', 'invoicing' ), |
|
135 | + 'name' => __('Zip', 'invoicing'), |
|
136 | 136 | 'value' => $invoice->get_zip(), |
137 | 137 | ), |
138 | 138 | 'vat_number' => array( |
139 | - 'name' => __( 'VAT Number', 'invoicing' ), |
|
139 | + 'name' => __('VAT Number', 'invoicing'), |
|
140 | 140 | 'value' => $invoice->get_vat_number(), |
141 | 141 | ), |
142 | 142 | 'description' => array( |
143 | - 'name' => __( 'Description', 'invoicing' ), |
|
143 | + 'name' => __('Description', 'invoicing'), |
|
144 | 144 | 'value' => $invoice->get_description(), |
145 | 145 | ), |
146 | 146 | ); |
147 | 147 | |
148 | 148 | // In case the invoice is paid, add the payment date and gateway. |
149 | - if ( $invoice->is_paid() ) { |
|
149 | + if ($invoice->is_paid()) { |
|
150 | 150 | |
151 | 151 | $props_to_export['completed_date'] = array( |
152 | - 'name' => __( 'Completed Date', 'invoicing' ), |
|
152 | + 'name' => __('Completed Date', 'invoicing'), |
|
153 | 153 | 'value' => $invoice->get_completed_date(), |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $props_to_export['gateway'] = array( |
157 | - 'name' => __( 'Paid Via', 'invoicing' ), |
|
157 | + 'name' => __('Paid Via', 'invoicing'), |
|
158 | 158 | 'value' => $invoice->get_gateway(), |
159 | 159 | ); |
160 | 160 | |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Maybe add subscription details. |
164 | - $props_to_export = self::process_subscription( $invoice, $props_to_export ); |
|
164 | + $props_to_export = self::process_subscription($invoice, $props_to_export); |
|
165 | 165 | |
166 | 166 | // Add the ip address. |
167 | 167 | $props_to_export['ip'] = array( |
168 | - 'name' => __( 'IP Address', 'invoicing' ), |
|
168 | + 'name' => __('IP Address', 'invoicing'), |
|
169 | 169 | 'value' => $invoice->get_ip(), |
170 | 170 | ); |
171 | 171 | |
172 | 172 | // Add the invoice url. |
173 | 173 | $props_to_export['view_url'] = array( |
174 | - 'name' => __( 'Invoice URL', 'invoicing' ), |
|
174 | + 'name' => __('Invoice URL', 'invoicing'), |
|
175 | 175 | 'value' => $invoice->get_view_url(), |
176 | 176 | ); |
177 | 177 | |
178 | 178 | // Return the values. |
179 | - $items = apply_filters( 'getpaid_privacy_export_invoice_personal_data', array_values( $props_to_export ), $invoice ); |
|
179 | + $items = apply_filters('getpaid_privacy_export_invoice_personal_data', array_values($props_to_export), $invoice); |
|
180 | 180 | |
181 | 181 | $data = array(); |
182 | 182 | |
183 | 183 | // Unset null values to prevent PHP deprecated notice. |
184 | - foreach ( $items as $item ) { |
|
185 | - if ( isset( $item['value'] ) && ! is_null( $item['value'] ) ) { |
|
184 | + foreach ($items as $item) { |
|
185 | + if (isset($item['value']) && !is_null($item['value'])) { |
|
186 | 186 | $data[] = $item; |
187 | 187 | } |
188 | 188 | } |
@@ -198,40 +198,40 @@ discard block |
||
198 | 198 | * @param array $props invoice props. |
199 | 199 | * @return array |
200 | 200 | */ |
201 | - public static function process_subscription( $invoice, $props ) { |
|
201 | + public static function process_subscription($invoice, $props) { |
|
202 | 202 | |
203 | - $subscription = wpinv_get_subscription( $invoice ); |
|
204 | - if ( ! empty( $subscription ) ) { |
|
203 | + $subscription = wpinv_get_subscription($invoice); |
|
204 | + if (!empty($subscription)) { |
|
205 | 205 | |
206 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency() ); |
|
207 | - $period = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ) . ' / ' . $frequency; |
|
208 | - $initial_amt = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
209 | - $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->get_bill_times() == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->get_bill_times() ); |
|
210 | - $renewal_date = getpaid_format_date_value( $subscription->get_expiration() ); |
|
206 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency()); |
|
207 | + $period = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()) . ' / ' . $frequency; |
|
208 | + $initial_amt = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency()); |
|
209 | + $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->get_bill_times() == 0) ? __('Until Cancelled', 'invoicing') : $subscription->get_bill_times()); |
|
210 | + $renewal_date = getpaid_format_date_value($subscription->get_expiration()); |
|
211 | 211 | |
212 | 212 | // Billing cycle. |
213 | 213 | $props['period'] = array( |
214 | - 'name' => __( 'Billing Cycle', 'invoicing' ), |
|
214 | + 'name' => __('Billing Cycle', 'invoicing'), |
|
215 | 215 | 'value' => $period, |
216 | 216 | ); |
217 | 217 | |
218 | 218 | // Initial amount. |
219 | 219 | $props['initial_amount'] = array( |
220 | - 'name' => __( 'Initial Amount', 'invoicing' ), |
|
220 | + 'name' => __('Initial Amount', 'invoicing'), |
|
221 | 221 | 'value' => $initial_amt, |
222 | 222 | ); |
223 | 223 | |
224 | 224 | // Bill times. |
225 | 225 | $props['bill_times'] = array( |
226 | - 'name' => __( 'Times Billed', 'invoicing' ), |
|
226 | + 'name' => __('Times Billed', 'invoicing'), |
|
227 | 227 | 'value' => $bill_times, |
228 | 228 | ); |
229 | 229 | |
230 | 230 | // Add expiry date. |
231 | - if ( $subscription->is_active() ) { |
|
231 | + if ($subscription->is_active()) { |
|
232 | 232 | |
233 | 233 | $props['renewal_date'] = array( |
234 | - 'name' => __( 'Expires', 'invoicing' ), |
|
234 | + 'name' => __('Expires', 'invoicing'), |
|
235 | 235 | 'value' => $renewal_date, |
236 | 236 | ); |
237 | 237 | |
@@ -249,19 +249,19 @@ discard block |
||
249 | 249 | * @param WPInv_Invoice $invoice invoice object. |
250 | 250 | * @return array |
251 | 251 | */ |
252 | - public static function process_invoice_items( $invoice ) { |
|
252 | + public static function process_invoice_items($invoice) { |
|
253 | 253 | |
254 | 254 | $item_names = array(); |
255 | - foreach ( $invoice->get_items() as $cart_item ) { |
|
255 | + foreach ($invoice->get_items() as $cart_item) { |
|
256 | 256 | $item_names[] = sprintf( |
257 | 257 | '%s x %s - %s', |
258 | 258 | $cart_item->get_name(), |
259 | 259 | $cart_item->get_quantity(), |
260 | - wpinv_price( $invoice->is_renewal() ? $cart_item->get_recurring_sub_total() : $cart_item->get_sub_total(), $invoice->get_currency() ) |
|
260 | + wpinv_price($invoice->is_renewal() ? $cart_item->get_recurring_sub_total() : $cart_item->get_sub_total(), $invoice->get_currency()) |
|
261 | 261 | ); |
262 | 262 | } |
263 | 263 | |
264 | - return implode( ', ', $item_names ); |
|
264 | + return implode(', ', $item_names); |
|
265 | 265 | |
266 | 266 | } |
267 | 267 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | add_action( 'init', array( $this, 'register_erasers_exporters' ) ); |
30 | 30 | } |
31 | 31 | |
32 | - /** |
|
32 | + /** |
|
33 | 33 | * Initial registration of privacy erasers and exporters. |
34 | 34 | * |
35 | 35 | * Due to the use of translation functions, this should run only after plugins loaded. |
@@ -49,25 +49,25 @@ discard block |
||
49 | 49 | public function get_privacy_message() { |
50 | 50 | |
51 | 51 | $content = '<div class="wp-suggested-text">' . |
52 | - '<h2>' . __( 'Invoices and checkout', 'invoicing' ) . '</h2>' . |
|
53 | - '<p class="privacy-policy-tutorial">' . __( 'Example privacy texts.', 'invoicing' ) . '</p>' . |
|
54 | - '<p>' . __( 'We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing' ) . '</p>' . |
|
55 | - '<p>' . __( 'Handling this data also allows us to:', 'invoicing' ) . '</p>' . |
|
56 | - '<ul>' . |
|
57 | - '<li>' . __( '- Send you important account/invoice/service information.', 'invoicing' ) . '</li>' . |
|
58 | - '<li>' . __( '- Estimate taxes based on your location.', 'invoicing' ) . '</li>' . |
|
59 | - '<li>' . __( '- Respond to your queries or complaints.', 'invoicing' ) . '</li>' . |
|
60 | - '<li>' . __( '- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
61 | - '<li>' . __( '- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing' ) . '</li>' . |
|
62 | - '<li>' . __( '- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
63 | - '</ul>' . |
|
64 | - '<p>' . __( 'In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing' ) . '</p>' . |
|
65 | - '<h2>' . __( 'What we share with others', 'invoicing' ) . '</h2>' . |
|
66 | - '<p>' . __( 'We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing' ) . '</p>' . |
|
67 | - '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing' ) . '</p>' . |
|
68 | - '<p>' . __( 'We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing' ) . '</p>' . |
|
69 | - '<p>' . __( 'Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing' ) . '</p>' . |
|
70 | - '</div>'; |
|
52 | + '<h2>' . __( 'Invoices and checkout', 'invoicing' ) . '</h2>' . |
|
53 | + '<p class="privacy-policy-tutorial">' . __( 'Example privacy texts.', 'invoicing' ) . '</p>' . |
|
54 | + '<p>' . __( 'We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing' ) . '</p>' . |
|
55 | + '<p>' . __( 'Handling this data also allows us to:', 'invoicing' ) . '</p>' . |
|
56 | + '<ul>' . |
|
57 | + '<li>' . __( '- Send you important account/invoice/service information.', 'invoicing' ) . '</li>' . |
|
58 | + '<li>' . __( '- Estimate taxes based on your location.', 'invoicing' ) . '</li>' . |
|
59 | + '<li>' . __( '- Respond to your queries or complaints.', 'invoicing' ) . '</li>' . |
|
60 | + '<li>' . __( '- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
61 | + '<li>' . __( '- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing' ) . '</li>' . |
|
62 | + '<li>' . __( '- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
63 | + '</ul>' . |
|
64 | + '<p>' . __( 'In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing' ) . '</p>' . |
|
65 | + '<h2>' . __( 'What we share with others', 'invoicing' ) . '</h2>' . |
|
66 | + '<p>' . __( 'We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing' ) . '</p>' . |
|
67 | + '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing' ) . '</p>' . |
|
68 | + '<p>' . __( 'We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing' ) . '</p>' . |
|
69 | + '<p>' . __( 'Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing' ) . '</p>' . |
|
70 | + '</div>'; |
|
71 | 71 | |
72 | 72 | return apply_filters( 'wpinv_privacy_policy_content', $content ); |
73 | 73 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Privacy/GDPR related functionality which ties into WordPress functionality. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WPInv_Privacy Class. |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $this->init(); |
27 | 27 | |
28 | 28 | // Initialize data exporters and erasers. |
29 | - add_action( 'init', array( $this, 'register_erasers_exporters' ) ); |
|
29 | + add_action('init', array($this, 'register_erasers_exporters')); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * Due to the use of translation functions, this should run only after plugins loaded. |
36 | 36 | */ |
37 | 37 | public function register_erasers_exporters() { |
38 | - $this->name = __( 'GetPaid', 'invoicing' ); |
|
38 | + $this->name = __('GetPaid', 'invoicing'); |
|
39 | 39 | |
40 | 40 | // This hook registers Invoicing data exporters. |
41 | - $this->add_exporter( 'wpinv-customer-invoices', __( 'Customer Invoices', 'invoicing' ), array( 'WPInv_Privacy_Exporters', 'customer_invoice_data_exporter' ) ); |
|
41 | + $this->add_exporter('wpinv-customer-invoices', __('Customer Invoices', 'invoicing'), array('WPInv_Privacy_Exporters', 'customer_invoice_data_exporter')); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -49,27 +49,27 @@ discard block |
||
49 | 49 | public function get_privacy_message() { |
50 | 50 | |
51 | 51 | $content = '<div class="wp-suggested-text">' . |
52 | - '<h2>' . __( 'Invoices and checkout', 'invoicing' ) . '</h2>' . |
|
53 | - '<p class="privacy-policy-tutorial">' . __( 'Example privacy texts.', 'invoicing' ) . '</p>' . |
|
54 | - '<p>' . __( 'We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing' ) . '</p>' . |
|
55 | - '<p>' . __( 'Handling this data also allows us to:', 'invoicing' ) . '</p>' . |
|
52 | + '<h2>' . __('Invoices and checkout', 'invoicing') . '</h2>' . |
|
53 | + '<p class="privacy-policy-tutorial">' . __('Example privacy texts.', 'invoicing') . '</p>' . |
|
54 | + '<p>' . __('We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing') . '</p>' . |
|
55 | + '<p>' . __('Handling this data also allows us to:', 'invoicing') . '</p>' . |
|
56 | 56 | '<ul>' . |
57 | - '<li>' . __( '- Send you important account/invoice/service information.', 'invoicing' ) . '</li>' . |
|
58 | - '<li>' . __( '- Estimate taxes based on your location.', 'invoicing' ) . '</li>' . |
|
59 | - '<li>' . __( '- Respond to your queries or complaints.', 'invoicing' ) . '</li>' . |
|
60 | - '<li>' . __( '- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
61 | - '<li>' . __( '- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing' ) . '</li>' . |
|
62 | - '<li>' . __( '- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
57 | + '<li>' . __('- Send you important account/invoice/service information.', 'invoicing') . '</li>' . |
|
58 | + '<li>' . __('- Estimate taxes based on your location.', 'invoicing') . '</li>' . |
|
59 | + '<li>' . __('- Respond to your queries or complaints.', 'invoicing') . '</li>' . |
|
60 | + '<li>' . __('- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing') . '</li>' . |
|
61 | + '<li>' . __('- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing') . '</li>' . |
|
62 | + '<li>' . __('- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing') . '</li>' . |
|
63 | 63 | '</ul>' . |
64 | - '<p>' . __( 'In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing' ) . '</p>' . |
|
65 | - '<h2>' . __( 'What we share with others', 'invoicing' ) . '</h2>' . |
|
66 | - '<p>' . __( 'We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing' ) . '</p>' . |
|
67 | - '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing' ) . '</p>' . |
|
68 | - '<p>' . __( 'We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing' ) . '</p>' . |
|
69 | - '<p>' . __( 'Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing' ) . '</p>' . |
|
64 | + '<p>' . __('In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing') . '</p>' . |
|
65 | + '<h2>' . __('What we share with others', 'invoicing') . '</h2>' . |
|
66 | + '<p>' . __('We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing') . '</p>' . |
|
67 | + '<p class="privacy-policy-tutorial">' . __('In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing') . '</p>' . |
|
68 | + '<p>' . __('We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing') . '</p>' . |
|
69 | + '<p>' . __('Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing') . '</p>' . |
|
70 | 70 | '</div>'; |
71 | 71 | |
72 | - return apply_filters( 'wpinv_privacy_policy_content', $content ); |
|
72 | + return apply_filters('wpinv_privacy_policy_content', $content); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Abstract privacy class. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Abstract class that is intended to be extended by |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @param string $name Plugin identifier. |
40 | 40 | */ |
41 | - public function __construct( $name = '' ) { |
|
41 | + public function __construct($name = '') { |
|
42 | 42 | $this->name = $name; |
43 | 43 | $this->init(); |
44 | 44 | } |
@@ -47,26 +47,26 @@ discard block |
||
47 | 47 | * Hook in events. |
48 | 48 | */ |
49 | 49 | protected function init() { |
50 | - add_action( 'admin_init', array( $this, 'add_privacy_message' ) ); |
|
50 | + add_action('admin_init', array($this, 'add_privacy_message')); |
|
51 | 51 | // Register data exporters |
52 | - add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporters' ), 10 ); |
|
52 | + add_filter('wp_privacy_personal_data_exporters', array($this, 'register_exporters'), 10); |
|
53 | 53 | // Register data erasers |
54 | - add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_erasers' ) ); |
|
54 | + add_filter('wp_privacy_personal_data_erasers', array($this, 'register_erasers')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Adds the privacy message on invoicing privacy page. |
59 | 59 | */ |
60 | 60 | public function add_privacy_message() { |
61 | - if ( function_exists( 'wp_add_privacy_policy_content' ) ) { |
|
61 | + if (function_exists('wp_add_privacy_policy_content')) { |
|
62 | 62 | $content = $this->get_privacy_message(); |
63 | 63 | |
64 | - if ( $content ) { |
|
65 | - if ( empty( $this->name ) ) { |
|
66 | - $this->name = __( 'GetPaid', 'invoicing' ); |
|
64 | + if ($content) { |
|
65 | + if (empty($this->name)) { |
|
66 | + $this->name = __('GetPaid', 'invoicing'); |
|
67 | 67 | } |
68 | 68 | |
69 | - wp_add_privacy_policy_content( $this->name, $this->get_privacy_message() ); |
|
69 | + wp_add_privacy_policy_content($this->name, $this->get_privacy_message()); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | } |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * @param array $exporters List of exporter callbacks. |
88 | 88 | * @return array |
89 | 89 | */ |
90 | - public function register_exporters( $exporters = array() ) { |
|
91 | - foreach ( $this->exporters as $id => $exporter ) { |
|
92 | - $exporters[ $id ] = $exporter; |
|
90 | + public function register_exporters($exporters = array()) { |
|
91 | + foreach ($this->exporters as $id => $exporter) { |
|
92 | + $exporters[$id] = $exporter; |
|
93 | 93 | } |
94 | 94 | return $exporters; |
95 | 95 | } |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param array $erasers List of eraser callbacks. |
101 | 101 | * @return array |
102 | 102 | */ |
103 | - public function register_erasers( $erasers = array() ) { |
|
104 | - foreach ( $this->erasers as $id => $eraser ) { |
|
105 | - $erasers[ $id ] = $eraser; |
|
103 | + public function register_erasers($erasers = array()) { |
|
104 | + foreach ($this->erasers as $id => $eraser) { |
|
105 | + $erasers[$id] = $eraser; |
|
106 | 106 | } |
107 | 107 | return $erasers; |
108 | 108 | } |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return array |
118 | 118 | */ |
119 | - public function add_exporter( $id, $name, $callback ) { |
|
120 | - $this->exporters[ $id ] = array( |
|
119 | + public function add_exporter($id, $name, $callback) { |
|
120 | + $this->exporters[$id] = array( |
|
121 | 121 | 'exporter_friendly_name' => $name, |
122 | 122 | 'callback' => $callback, |
123 | 123 | ); |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @return array |
135 | 135 | */ |
136 | - public function add_eraser( $id, $name, $callback ) { |
|
137 | - $this->erasers[ $id ] = array( |
|
136 | + public function add_eraser($id, $name, $callback) { |
|
137 | + $this->erasers[$id] = array( |
|
138 | 138 | 'eraser_friendly_name' => $name, |
139 | 139 | 'callback' => $callback, |
140 | 140 | ); |
@@ -12,492 +12,492 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - add_action( 'init', array( $this, 'init_hooks' ) ); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Registers email hooks. |
|
49 | - */ |
|
50 | - public function init_hooks() { |
|
51 | - |
|
52 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
53 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
54 | - |
|
55 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
56 | - $this->init_email_type_hook( $hook, $email_type ); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Registers an email hook for an invoice action. |
|
62 | - * |
|
63 | - * @param string $hook |
|
64 | - * @param string|array $email_type |
|
65 | - */ |
|
66 | - public function init_email_type_hook( $hook, $email_type ) { |
|
67 | - |
|
68 | - $email_type = wpinv_parse_list( $email_type ); |
|
69 | - |
|
70 | - foreach ( $email_type as $type ) { |
|
71 | - |
|
72 | - $email = new GetPaid_Notification_Email( $type ); |
|
73 | - |
|
74 | - // Abort if it is not active. |
|
75 | - if ( ! $email->is_active() ) { |
|
76 | - continue; |
|
77 | - } |
|
78 | - |
|
79 | - if ( method_exists( $this, $type ) ) { |
|
80 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
81 | - continue; |
|
82 | - } |
|
83 | - |
|
84 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | - } |
|
86 | - |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Filters invoice merge tags. |
|
91 | - * |
|
92 | - * @param array $merge_tags |
|
93 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
94 | - */ |
|
95 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | - |
|
97 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | - return array_merge( |
|
99 | - $merge_tags, |
|
100 | - $this->get_invoice_merge_tags( $object ) |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | - return array_merge( |
|
106 | - $merge_tags, |
|
107 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - return $merge_tags; |
|
112 | - |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Generates invoice merge tags. |
|
117 | - * |
|
118 | - * @param WPInv_Invoice $invoice |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - public function get_invoice_merge_tags( $invoice ) { |
|
122 | - |
|
123 | - // Abort if it does not exist. |
|
124 | - if ( ! $invoice->get_id() ) { |
|
125 | - return array(); |
|
126 | - } |
|
127 | - |
|
128 | - $due_date = $invoice->get_due_date(); |
|
129 | - $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
130 | - $merge_tags = array( |
|
131 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
134 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
135 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
136 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
137 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
138 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
139 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
140 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
141 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
142 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
143 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
144 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
145 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
146 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
147 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
148 | - '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
149 | - ); |
|
150 | - |
|
151 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
152 | - |
|
153 | - if ( is_array( $payment_form_data ) ) { |
|
154 | - |
|
155 | - foreach ( $payment_form_data as $label => $value ) { |
|
156 | - |
|
157 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
158 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
159 | - |
|
160 | - if ( is_scalar( $value ) ) { |
|
161 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
162 | - } |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Helper function to send an email. |
|
171 | - * |
|
172 | - * @param WPInv_Invoice $invoice |
|
173 | - * @param GetPaid_Notification_Email $email |
|
174 | - * @param string $type |
|
175 | - * @param string|array $recipients |
|
176 | - * @param array $extra_args Extra template args. |
|
177 | - */ |
|
178 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
179 | - |
|
180 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
181 | - |
|
182 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
183 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
184 | - return; |
|
185 | - } |
|
186 | - |
|
187 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
188 | - $merge_tags = $email->get_merge_tags(); |
|
189 | - |
|
190 | - $result = $mailer->send( |
|
191 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
192 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
193 | - $email->get_content( $merge_tags, $extra_args ), |
|
194 | - $email->get_attachments() |
|
195 | - ); |
|
196 | - |
|
197 | - // Maybe send a copy to the admin. |
|
198 | - if ( $email->include_admin_bcc() ) { |
|
199 | - $mailer->send( |
|
200 | - wpinv_get_admin_email(), |
|
201 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
202 | - $email->get_content( $merge_tags ), |
|
203 | - $email->get_attachments() |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - if ( $result ) { |
|
208 | - $invoice->add_system_note( |
|
209 | - sprintf( |
|
210 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
211 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
212 | - sanitize_key( $type ), |
|
213 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
214 | - ) |
|
215 | - ); |
|
216 | - } else { |
|
217 | - $invoice->add_system_note( |
|
218 | - sprintf( |
|
219 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
220 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
221 | - sanitize_key( $type ), |
|
222 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
228 | - |
|
229 | - return $result; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Also send emails to any cc users. |
|
234 | - * |
|
235 | - * @param array $recipients |
|
236 | - * @param GetPaid_Notification_Email $email |
|
237 | - */ |
|
238 | - public function filter_email_recipients( $recipients, $email ) { |
|
239 | - |
|
240 | - if ( ! $email->is_admin_email() ) { |
|
241 | - $cc = $email->object->get_email_cc(); |
|
242 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
243 | - |
|
244 | - if ( ! empty( $cc ) ) { |
|
245 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
246 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
247 | - } |
|
248 | - |
|
249 | - if ( ! empty( $cc_2 ) ) { |
|
250 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
251 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - return $recipients; |
|
256 | - |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Sends a new invoice notification. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice |
|
263 | - */ |
|
264 | - public function new_invoice( $invoice ) { |
|
265 | - |
|
266 | - // Only send this email for invoices created via the admin page. |
|
267 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | - return; |
|
269 | - } |
|
270 | - |
|
271 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | - $recipient = wpinv_get_admin_email(); |
|
273 | - |
|
274 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | - |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Sends a cancelled invoice notification. |
|
280 | - * |
|
281 | - * @param WPInv_Invoice $invoice |
|
282 | - */ |
|
283 | - public function cancelled_invoice( $invoice ) { |
|
284 | - |
|
285 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | - $recipient = $invoice->get_email(); |
|
287 | - |
|
288 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Sends a failed invoice notification. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice |
|
295 | - */ |
|
296 | - public function failed_invoice( $invoice ) { |
|
297 | - |
|
298 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
299 | - $recipient = wpinv_get_admin_email(); |
|
300 | - |
|
301 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
302 | - |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Sends a notification whenever an invoice is put on hold. |
|
307 | - * |
|
308 | - * @param WPInv_Invoice $invoice |
|
309 | - */ |
|
310 | - public function onhold_invoice( $invoice ) { |
|
311 | - |
|
312 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
313 | - $recipient = $invoice->get_email(); |
|
314 | - |
|
315 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | - |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
321 | - * |
|
322 | - * @param WPInv_Invoice $invoice |
|
323 | - */ |
|
324 | - public function processing_invoice( $invoice ) { |
|
325 | - |
|
326 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
327 | - $recipient = $invoice->get_email(); |
|
328 | - |
|
329 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
330 | - |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Sends a notification whenever an invoice is paid. |
|
335 | - * |
|
336 | - * @param WPInv_Invoice $invoice |
|
337 | - */ |
|
338 | - public function completed_invoice( $invoice ) { |
|
339 | - |
|
340 | - // (Maybe) abort if it is a renewal invoice. |
|
341 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
342 | - return; |
|
343 | - } |
|
344 | - |
|
345 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
346 | - $recipient = $invoice->get_email(); |
|
347 | - |
|
348 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | - |
|
350 | - } |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + add_action( 'init', array( $this, 'init_hooks' ) ); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Registers email hooks. |
|
49 | + */ |
|
50 | + public function init_hooks() { |
|
51 | + |
|
52 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
53 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
54 | + |
|
55 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
56 | + $this->init_email_type_hook( $hook, $email_type ); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Registers an email hook for an invoice action. |
|
62 | + * |
|
63 | + * @param string $hook |
|
64 | + * @param string|array $email_type |
|
65 | + */ |
|
66 | + public function init_email_type_hook( $hook, $email_type ) { |
|
67 | + |
|
68 | + $email_type = wpinv_parse_list( $email_type ); |
|
69 | + |
|
70 | + foreach ( $email_type as $type ) { |
|
71 | + |
|
72 | + $email = new GetPaid_Notification_Email( $type ); |
|
73 | + |
|
74 | + // Abort if it is not active. |
|
75 | + if ( ! $email->is_active() ) { |
|
76 | + continue; |
|
77 | + } |
|
78 | + |
|
79 | + if ( method_exists( $this, $type ) ) { |
|
80 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
81 | + continue; |
|
82 | + } |
|
83 | + |
|
84 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | + } |
|
86 | + |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Filters invoice merge tags. |
|
91 | + * |
|
92 | + * @param array $merge_tags |
|
93 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
94 | + */ |
|
95 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | + |
|
97 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | + return array_merge( |
|
99 | + $merge_tags, |
|
100 | + $this->get_invoice_merge_tags( $object ) |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | + return array_merge( |
|
106 | + $merge_tags, |
|
107 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + return $merge_tags; |
|
112 | + |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Generates invoice merge tags. |
|
117 | + * |
|
118 | + * @param WPInv_Invoice $invoice |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + public function get_invoice_merge_tags( $invoice ) { |
|
122 | + |
|
123 | + // Abort if it does not exist. |
|
124 | + if ( ! $invoice->get_id() ) { |
|
125 | + return array(); |
|
126 | + } |
|
127 | + |
|
128 | + $due_date = $invoice->get_due_date(); |
|
129 | + $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
130 | + $merge_tags = array( |
|
131 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
134 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
135 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
136 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
137 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
138 | + '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
139 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
140 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
141 | + '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
142 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
143 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
144 | + '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
145 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
146 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
147 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
148 | + '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
149 | + ); |
|
150 | + |
|
151 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
152 | + |
|
153 | + if ( is_array( $payment_form_data ) ) { |
|
154 | + |
|
155 | + foreach ( $payment_form_data as $label => $value ) { |
|
156 | + |
|
157 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
158 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
159 | + |
|
160 | + if ( is_scalar( $value ) ) { |
|
161 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
162 | + } |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
167 | + } |
|
351 | 168 | |
352 | - /** |
|
353 | - * Sends a notification whenever an invoice is refunded. |
|
354 | - * |
|
355 | - * @param WPInv_Invoice $invoice |
|
356 | - */ |
|
357 | - public function refunded_invoice( $invoice ) { |
|
358 | - |
|
359 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
360 | - $recipient = $invoice->get_email(); |
|
361 | - |
|
362 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | - |
|
364 | - } |
|
169 | + /** |
|
170 | + * Helper function to send an email. |
|
171 | + * |
|
172 | + * @param WPInv_Invoice $invoice |
|
173 | + * @param GetPaid_Notification_Email $email |
|
174 | + * @param string $type |
|
175 | + * @param string|array $recipients |
|
176 | + * @param array $extra_args Extra template args. |
|
177 | + */ |
|
178 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
365 | 179 | |
366 | - /** |
|
367 | - * Notifies a user about new invoices |
|
368 | - * |
|
369 | - * @param WPInv_Invoice $invoice |
|
370 | - * @param bool $force |
|
371 | - */ |
|
372 | - public function user_invoice( $invoice, $force = false ) { |
|
180 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
373 | 181 | |
374 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
375 | - return; |
|
376 | - } |
|
377 | - |
|
378 | - // Only send this email for invoices created via the admin page. |
|
379 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
380 | - return; |
|
381 | - } |
|
382 | - |
|
383 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
384 | - $recipient = $invoice->get_email(); |
|
385 | - |
|
386 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | - |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Checks if an invoice is a payment form invoice. |
|
392 | - * |
|
393 | - * @param int $invoice |
|
394 | - * @return bool |
|
395 | - */ |
|
396 | - public function is_payment_form_invoice( $invoice ) { |
|
397 | - $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
398 | - $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
399 | - $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
400 | - return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Notifies admin about new invoice notes |
|
405 | - * |
|
406 | - * @param WPInv_Invoice $invoice |
|
407 | - * @param string $note |
|
408 | - */ |
|
409 | - public function user_note( $invoice, $note ) { |
|
410 | - |
|
411 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
412 | - $recipient = $invoice->get_email(); |
|
413 | - |
|
414 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
415 | - |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * (Force) Sends overdue notices. |
|
420 | - * |
|
421 | - * @param WPInv_Invoice $invoice |
|
422 | - */ |
|
423 | - public function force_send_overdue_notice( $invoice ) { |
|
424 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
425 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Sends overdue notices. |
|
430 | - * |
|
431 | - * @TODO: Create an invoices query class. |
|
432 | - */ |
|
433 | - public function overdue() { |
|
434 | - global $wpdb; |
|
435 | - |
|
436 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
437 | - |
|
438 | - // Fetch reminder days. |
|
439 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
440 | - |
|
441 | - // Abort if non is set. |
|
442 | - if ( empty( $reminder_days ) ) { |
|
443 | - return; |
|
444 | - } |
|
445 | - |
|
446 | - // Retrieve date query. |
|
447 | - $date_query = $this->get_date_query( $reminder_days ); |
|
448 | - |
|
449 | - // Invoices table. |
|
450 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
451 | - |
|
452 | - // Fetch invoices. |
|
453 | - $invoices = $wpdb->get_col( |
|
454 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
182 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
183 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
184 | + return; |
|
185 | + } |
|
186 | + |
|
187 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
188 | + $merge_tags = $email->get_merge_tags(); |
|
189 | + |
|
190 | + $result = $mailer->send( |
|
191 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
192 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
193 | + $email->get_content( $merge_tags, $extra_args ), |
|
194 | + $email->get_attachments() |
|
195 | + ); |
|
196 | + |
|
197 | + // Maybe send a copy to the admin. |
|
198 | + if ( $email->include_admin_bcc() ) { |
|
199 | + $mailer->send( |
|
200 | + wpinv_get_admin_email(), |
|
201 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
202 | + $email->get_content( $merge_tags ), |
|
203 | + $email->get_attachments() |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + if ( $result ) { |
|
208 | + $invoice->add_system_note( |
|
209 | + sprintf( |
|
210 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
211 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
212 | + sanitize_key( $type ), |
|
213 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
214 | + ) |
|
215 | + ); |
|
216 | + } else { |
|
217 | + $invoice->add_system_note( |
|
218 | + sprintf( |
|
219 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
220 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
221 | + sanitize_key( $type ), |
|
222 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
228 | + |
|
229 | + return $result; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Also send emails to any cc users. |
|
234 | + * |
|
235 | + * @param array $recipients |
|
236 | + * @param GetPaid_Notification_Email $email |
|
237 | + */ |
|
238 | + public function filter_email_recipients( $recipients, $email ) { |
|
239 | + |
|
240 | + if ( ! $email->is_admin_email() ) { |
|
241 | + $cc = $email->object->get_email_cc(); |
|
242 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
243 | + |
|
244 | + if ( ! empty( $cc ) ) { |
|
245 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
246 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
247 | + } |
|
248 | + |
|
249 | + if ( ! empty( $cc_2 ) ) { |
|
250 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
251 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + return $recipients; |
|
256 | + |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Sends a new invoice notification. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice |
|
263 | + */ |
|
264 | + public function new_invoice( $invoice ) { |
|
265 | + |
|
266 | + // Only send this email for invoices created via the admin page. |
|
267 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | + return; |
|
269 | + } |
|
270 | + |
|
271 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | + $recipient = wpinv_get_admin_email(); |
|
273 | + |
|
274 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | + |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Sends a cancelled invoice notification. |
|
280 | + * |
|
281 | + * @param WPInv_Invoice $invoice |
|
282 | + */ |
|
283 | + public function cancelled_invoice( $invoice ) { |
|
284 | + |
|
285 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | + $recipient = $invoice->get_email(); |
|
287 | + |
|
288 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Sends a failed invoice notification. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice |
|
295 | + */ |
|
296 | + public function failed_invoice( $invoice ) { |
|
297 | + |
|
298 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
299 | + $recipient = wpinv_get_admin_email(); |
|
300 | + |
|
301 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
302 | + |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Sends a notification whenever an invoice is put on hold. |
|
307 | + * |
|
308 | + * @param WPInv_Invoice $invoice |
|
309 | + */ |
|
310 | + public function onhold_invoice( $invoice ) { |
|
311 | + |
|
312 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
313 | + $recipient = $invoice->get_email(); |
|
314 | + |
|
315 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | + |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
321 | + * |
|
322 | + * @param WPInv_Invoice $invoice |
|
323 | + */ |
|
324 | + public function processing_invoice( $invoice ) { |
|
325 | + |
|
326 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
327 | + $recipient = $invoice->get_email(); |
|
328 | + |
|
329 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
330 | + |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Sends a notification whenever an invoice is paid. |
|
335 | + * |
|
336 | + * @param WPInv_Invoice $invoice |
|
337 | + */ |
|
338 | + public function completed_invoice( $invoice ) { |
|
339 | + |
|
340 | + // (Maybe) abort if it is a renewal invoice. |
|
341 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
342 | + return; |
|
343 | + } |
|
344 | + |
|
345 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
346 | + $recipient = $invoice->get_email(); |
|
347 | + |
|
348 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | + |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Sends a notification whenever an invoice is refunded. |
|
354 | + * |
|
355 | + * @param WPInv_Invoice $invoice |
|
356 | + */ |
|
357 | + public function refunded_invoice( $invoice ) { |
|
358 | + |
|
359 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
360 | + $recipient = $invoice->get_email(); |
|
361 | + |
|
362 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | + |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Notifies a user about new invoices |
|
368 | + * |
|
369 | + * @param WPInv_Invoice $invoice |
|
370 | + * @param bool $force |
|
371 | + */ |
|
372 | + public function user_invoice( $invoice, $force = false ) { |
|
373 | + |
|
374 | + if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
375 | + return; |
|
376 | + } |
|
377 | + |
|
378 | + // Only send this email for invoices created via the admin page. |
|
379 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
380 | + return; |
|
381 | + } |
|
382 | + |
|
383 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
384 | + $recipient = $invoice->get_email(); |
|
385 | + |
|
386 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | + |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Checks if an invoice is a payment form invoice. |
|
392 | + * |
|
393 | + * @param int $invoice |
|
394 | + * @return bool |
|
395 | + */ |
|
396 | + public function is_payment_form_invoice( $invoice ) { |
|
397 | + $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
398 | + $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
|
399 | + $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
400 | + return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Notifies admin about new invoice notes |
|
405 | + * |
|
406 | + * @param WPInv_Invoice $invoice |
|
407 | + * @param string $note |
|
408 | + */ |
|
409 | + public function user_note( $invoice, $note ) { |
|
410 | + |
|
411 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
412 | + $recipient = $invoice->get_email(); |
|
413 | + |
|
414 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
415 | + |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * (Force) Sends overdue notices. |
|
420 | + * |
|
421 | + * @param WPInv_Invoice $invoice |
|
422 | + */ |
|
423 | + public function force_send_overdue_notice( $invoice ) { |
|
424 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
425 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Sends overdue notices. |
|
430 | + * |
|
431 | + * @TODO: Create an invoices query class. |
|
432 | + */ |
|
433 | + public function overdue() { |
|
434 | + global $wpdb; |
|
435 | + |
|
436 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
437 | + |
|
438 | + // Fetch reminder days. |
|
439 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
440 | + |
|
441 | + // Abort if non is set. |
|
442 | + if ( empty( $reminder_days ) ) { |
|
443 | + return; |
|
444 | + } |
|
445 | + |
|
446 | + // Retrieve date query. |
|
447 | + $date_query = $this->get_date_query( $reminder_days ); |
|
448 | + |
|
449 | + // Invoices table. |
|
450 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
451 | + |
|
452 | + // Fetch invoices. |
|
453 | + $invoices = $wpdb->get_col( |
|
454 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
455 | 455 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
456 | 456 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
457 | 457 | ); |
458 | 458 | |
459 | - foreach ( $invoices as $invoice ) { |
|
459 | + foreach ( $invoices as $invoice ) { |
|
460 | 460 | |
461 | - // Only send this email for invoices created via the admin page. |
|
462 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
463 | - $invoice = new WPInv_Invoice( $invoice ); |
|
464 | - $email->object = $invoice; |
|
461 | + // Only send this email for invoices created via the admin page. |
|
462 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
463 | + $invoice = new WPInv_Invoice( $invoice ); |
|
464 | + $email->object = $invoice; |
|
465 | 465 | |
466 | - if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
467 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
468 | - } |
|
469 | - } |
|
470 | - } |
|
466 | + if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
467 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
468 | + } |
|
469 | + } |
|
470 | + } |
|
471 | 471 | |
472 | - } |
|
472 | + } |
|
473 | 473 | |
474 | - /** |
|
475 | - * Calculates the date query for an invoices query |
|
476 | - * |
|
477 | - * @param array $reminder_days |
|
478 | - * @return string |
|
479 | - */ |
|
480 | - public function get_date_query( $reminder_days ) { |
|
474 | + /** |
|
475 | + * Calculates the date query for an invoices query |
|
476 | + * |
|
477 | + * @param array $reminder_days |
|
478 | + * @return string |
|
479 | + */ |
|
480 | + public function get_date_query( $reminder_days ) { |
|
481 | 481 | |
482 | - $date_query = array( |
|
483 | - 'relation' => 'OR', |
|
484 | - ); |
|
482 | + $date_query = array( |
|
483 | + 'relation' => 'OR', |
|
484 | + ); |
|
485 | 485 | |
486 | - foreach ( $reminder_days as $days ) { |
|
487 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
486 | + foreach ( $reminder_days as $days ) { |
|
487 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
488 | 488 | |
489 | - $date_query[] = array( |
|
490 | - 'year' => $date['year'], |
|
491 | - 'month' => $date['month'], |
|
492 | - 'day' => $date['day'], |
|
493 | - ); |
|
489 | + $date_query[] = array( |
|
490 | + 'year' => $date['year'], |
|
491 | + 'month' => $date['month'], |
|
492 | + 'day' => $date['day'], |
|
493 | + ); |
|
494 | 494 | |
495 | - } |
|
495 | + } |
|
496 | 496 | |
497 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
497 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
498 | 498 | |
499 | - return $date_query->get_sql(); |
|
499 | + return $date_query->get_sql(); |
|
500 | 500 | |
501 | - } |
|
501 | + } |
|
502 | 502 | |
503 | 503 | } |
@@ -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', |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | ) |
42 | 42 | ); |
43 | 43 | |
44 | - add_action( 'init', array( $this, 'init_hooks' ) ); |
|
44 | + add_action('init', array($this, 'init_hooks')); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function init_hooks() { |
51 | 51 | |
52 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
53 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
52 | + add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2); |
|
53 | + add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2); |
|
54 | 54 | |
55 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
56 | - $this->init_email_type_hook( $hook, $email_type ); |
|
55 | + foreach ($this->invoice_actions as $hook => $email_type) { |
|
56 | + $this->init_email_type_hook($hook, $email_type); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -63,25 +63,25 @@ discard block |
||
63 | 63 | * @param string $hook |
64 | 64 | * @param string|array $email_type |
65 | 65 | */ |
66 | - public function init_email_type_hook( $hook, $email_type ) { |
|
66 | + public function init_email_type_hook($hook, $email_type) { |
|
67 | 67 | |
68 | - $email_type = wpinv_parse_list( $email_type ); |
|
68 | + $email_type = wpinv_parse_list($email_type); |
|
69 | 69 | |
70 | - foreach ( $email_type as $type ) { |
|
70 | + foreach ($email_type as $type) { |
|
71 | 71 | |
72 | - $email = new GetPaid_Notification_Email( $type ); |
|
72 | + $email = new GetPaid_Notification_Email($type); |
|
73 | 73 | |
74 | 74 | // Abort if it is not active. |
75 | - if ( ! $email->is_active() ) { |
|
75 | + if (!$email->is_active()) { |
|
76 | 76 | continue; |
77 | 77 | } |
78 | 78 | |
79 | - if ( method_exists( $this, $type ) ) { |
|
80 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
79 | + if (method_exists($this, $type)) { |
|
80 | + add_action($hook, array($this, $type), 100, 2); |
|
81 | 81 | continue; |
82 | 82 | } |
83 | 83 | |
84 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
84 | + do_action('getpaid_invoice_init_email_type_hook', $type, $hook); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | } |
@@ -92,19 +92,19 @@ discard block |
||
92 | 92 | * @param array $merge_tags |
93 | 93 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
94 | 94 | */ |
95 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
95 | + public function invoice_merge_tags($merge_tags, $object) { |
|
96 | 96 | |
97 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
97 | + if (is_a($object, 'WPInv_Invoice')) { |
|
98 | 98 | return array_merge( |
99 | 99 | $merge_tags, |
100 | - $this->get_invoice_merge_tags( $object ) |
|
100 | + $this->get_invoice_merge_tags($object) |
|
101 | 101 | ); |
102 | 102 | } |
103 | 103 | |
104 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
104 | + if (is_a($object, 'WPInv_Subscription')) { |
|
105 | 105 | return array_merge( |
106 | 106 | $merge_tags, |
107 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
107 | + $this->get_invoice_merge_tags($object->get_parent_payment()) |
|
108 | 108 | ); |
109 | 109 | } |
110 | 110 | |
@@ -118,52 +118,52 @@ discard block |
||
118 | 118 | * @param WPInv_Invoice $invoice |
119 | 119 | * @return array |
120 | 120 | */ |
121 | - public function get_invoice_merge_tags( $invoice ) { |
|
121 | + public function get_invoice_merge_tags($invoice) { |
|
122 | 122 | |
123 | 123 | // Abort if it does not exist. |
124 | - if ( ! $invoice->get_id() ) { |
|
124 | + if (!$invoice->get_id()) { |
|
125 | 125 | return array(); |
126 | 126 | } |
127 | 127 | |
128 | 128 | $due_date = $invoice->get_due_date(); |
129 | - $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
129 | + $due_date = empty($due_date) ? time() + MINUTE_IN_SECONDS : strtotime($due_date) + ((int) get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
130 | 130 | $merge_tags = array( |
131 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
134 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
135 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
136 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
137 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
138 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
139 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
140 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
141 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
142 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
143 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
144 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
145 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
146 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
147 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
148 | - '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
131 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
132 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
133 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
134 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
135 | + '{email}' => sanitize_email($invoice->get_email()), |
|
136 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
137 | + '{invoice_currency}' => sanitize_text_field($invoice->get_currency()), |
|
138 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())), |
|
139 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
140 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
141 | + '{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()), |
|
142 | + '{invoice_date}' => getpaid_format_date_value($invoice->get_date_created()), |
|
143 | + '{invoice_due_date}' => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')), |
|
144 | + '{invoice_quote}' => sanitize_text_field(strtolower($invoice->get_label())), |
|
145 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_label())), |
|
146 | + '{invoice_description}' => wp_kses_post($invoice->get_description()), |
|
147 | + '{subscription_name}' => wp_kses_post($invoice->get_subscription_name()), |
|
148 | + '{is_was}' => $due_date < time() ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
149 | 149 | ); |
150 | 150 | |
151 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | + $payment_form_data = $invoice->get_meta('payment_form_data', true); |
|
152 | 152 | |
153 | - if ( is_array( $payment_form_data ) ) { |
|
153 | + if (is_array($payment_form_data)) { |
|
154 | 154 | |
155 | - foreach ( $payment_form_data as $label => $value ) { |
|
155 | + foreach ($payment_form_data as $label => $value) { |
|
156 | 156 | |
157 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
158 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
157 | + $label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label)); |
|
158 | + $value = is_array($value) ? implode(', ', $value) : $value; |
|
159 | 159 | |
160 | - if ( is_scalar( $value ) ) { |
|
161 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
160 | + if (is_scalar($value)) { |
|
161 | + $merge_tags["{{$label}}"] = wp_kses_post($value); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
166 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
166 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | * @param string|array $recipients |
176 | 176 | * @param array $extra_args Extra template args. |
177 | 177 | */ |
178 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
178 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
179 | 179 | |
180 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
180 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
181 | 181 | |
182 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
183 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
182 | + $skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice'); |
|
183 | + if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) { |
|
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
@@ -188,43 +188,43 @@ discard block |
||
188 | 188 | $merge_tags = $email->get_merge_tags(); |
189 | 189 | |
190 | 190 | $result = $mailer->send( |
191 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
192 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
193 | - $email->get_content( $merge_tags, $extra_args ), |
|
191 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
192 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
193 | + $email->get_content($merge_tags, $extra_args), |
|
194 | 194 | $email->get_attachments() |
195 | 195 | ); |
196 | 196 | |
197 | 197 | // Maybe send a copy to the admin. |
198 | - if ( $email->include_admin_bcc() ) { |
|
198 | + if ($email->include_admin_bcc()) { |
|
199 | 199 | $mailer->send( |
200 | 200 | wpinv_get_admin_email(), |
201 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
202 | - $email->get_content( $merge_tags ), |
|
201 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
202 | + $email->get_content($merge_tags), |
|
203 | 203 | $email->get_attachments() |
204 | 204 | ); |
205 | 205 | } |
206 | 206 | |
207 | - if ( $result ) { |
|
207 | + if ($result) { |
|
208 | 208 | $invoice->add_system_note( |
209 | 209 | sprintf( |
210 | 210 | // translators: %1 is the email type, %2 is the invoice recipient. |
211 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
212 | - sanitize_key( $type ), |
|
213 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
211 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
212 | + sanitize_key($type), |
|
213 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
214 | 214 | ) |
215 | 215 | ); |
216 | 216 | } else { |
217 | 217 | $invoice->add_system_note( |
218 | 218 | sprintf( |
219 | 219 | // translators: %1 is the email type, %2 is the invoice recipient. |
220 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
221 | - sanitize_key( $type ), |
|
222 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
220 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
221 | + sanitize_key($type), |
|
222 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
223 | 223 | ) |
224 | 224 | ); |
225 | 225 | } |
226 | 226 | |
227 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
228 | 228 | |
229 | 229 | return $result; |
230 | 230 | } |
@@ -235,20 +235,20 @@ discard block |
||
235 | 235 | * @param array $recipients |
236 | 236 | * @param GetPaid_Notification_Email $email |
237 | 237 | */ |
238 | - public function filter_email_recipients( $recipients, $email ) { |
|
238 | + public function filter_email_recipients($recipients, $email) { |
|
239 | 239 | |
240 | - if ( ! $email->is_admin_email() ) { |
|
240 | + if (!$email->is_admin_email()) { |
|
241 | 241 | $cc = $email->object->get_email_cc(); |
242 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | + $cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true); |
|
243 | 243 | |
244 | - if ( ! empty( $cc ) ) { |
|
245 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
246 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
244 | + if (!empty($cc)) { |
|
245 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
246 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
247 | 247 | } |
248 | 248 | |
249 | - if ( ! empty( $cc_2 ) ) { |
|
250 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
251 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
249 | + if (!empty($cc_2)) { |
|
250 | + $cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2)); |
|
251 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc_2))); |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
@@ -261,17 +261,17 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @param WPInv_Invoice $invoice |
263 | 263 | */ |
264 | - public function new_invoice( $invoice ) { |
|
264 | + public function new_invoice($invoice) { |
|
265 | 265 | |
266 | 266 | // Only send this email for invoices created via the admin page. |
267 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
267 | + if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
272 | 272 | $recipient = wpinv_get_admin_email(); |
273 | 273 | |
274 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
275 | 275 | |
276 | 276 | } |
277 | 277 | |
@@ -280,12 +280,12 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @param WPInv_Invoice $invoice |
282 | 282 | */ |
283 | - public function cancelled_invoice( $invoice ) { |
|
283 | + public function cancelled_invoice($invoice) { |
|
284 | 284 | |
285 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
286 | 286 | $recipient = $invoice->get_email(); |
287 | 287 | |
288 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -293,12 +293,12 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @param WPInv_Invoice $invoice |
295 | 295 | */ |
296 | - public function failed_invoice( $invoice ) { |
|
296 | + public function failed_invoice($invoice) { |
|
297 | 297 | |
298 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
298 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
299 | 299 | $recipient = wpinv_get_admin_email(); |
300 | 300 | |
301 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
301 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
302 | 302 | |
303 | 303 | } |
304 | 304 | |
@@ -307,12 +307,12 @@ discard block |
||
307 | 307 | * |
308 | 308 | * @param WPInv_Invoice $invoice |
309 | 309 | */ |
310 | - public function onhold_invoice( $invoice ) { |
|
310 | + public function onhold_invoice($invoice) { |
|
311 | 311 | |
312 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
312 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
313 | 313 | $recipient = $invoice->get_email(); |
314 | 314 | |
315 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
315 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
316 | 316 | |
317 | 317 | } |
318 | 318 | |
@@ -321,12 +321,12 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @param WPInv_Invoice $invoice |
323 | 323 | */ |
324 | - public function processing_invoice( $invoice ) { |
|
324 | + public function processing_invoice($invoice) { |
|
325 | 325 | |
326 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
326 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
327 | 327 | $recipient = $invoice->get_email(); |
328 | 328 | |
329 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
329 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
330 | 330 | |
331 | 331 | } |
332 | 332 | |
@@ -335,17 +335,17 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @param WPInv_Invoice $invoice |
337 | 337 | */ |
338 | - public function completed_invoice( $invoice ) { |
|
338 | + public function completed_invoice($invoice) { |
|
339 | 339 | |
340 | 340 | // (Maybe) abort if it is a renewal invoice. |
341 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
341 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
342 | 342 | return; |
343 | 343 | } |
344 | 344 | |
345 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
345 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
346 | 346 | $recipient = $invoice->get_email(); |
347 | 347 | |
348 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
348 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
349 | 349 | |
350 | 350 | } |
351 | 351 | |
@@ -354,12 +354,12 @@ discard block |
||
354 | 354 | * |
355 | 355 | * @param WPInv_Invoice $invoice |
356 | 356 | */ |
357 | - public function refunded_invoice( $invoice ) { |
|
357 | + public function refunded_invoice($invoice) { |
|
358 | 358 | |
359 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
359 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
360 | 360 | $recipient = $invoice->get_email(); |
361 | 361 | |
362 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
362 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
363 | 363 | |
364 | 364 | } |
365 | 365 | |
@@ -369,21 +369,21 @@ discard block |
||
369 | 369 | * @param WPInv_Invoice $invoice |
370 | 370 | * @param bool $force |
371 | 371 | */ |
372 | - public function user_invoice( $invoice, $force = false ) { |
|
372 | + public function user_invoice($invoice, $force = false) { |
|
373 | 373 | |
374 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
374 | + if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
375 | 375 | return; |
376 | 376 | } |
377 | 377 | |
378 | 378 | // Only send this email for invoices created via the admin page. |
379 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
379 | + if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
380 | 380 | return; |
381 | 381 | } |
382 | 382 | |
383 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
383 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
384 | 384 | $recipient = $invoice->get_email(); |
385 | 385 | |
386 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
386 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
387 | 387 | |
388 | 388 | } |
389 | 389 | |
@@ -393,11 +393,11 @@ discard block |
||
393 | 393 | * @param int $invoice |
394 | 394 | * @return bool |
395 | 395 | */ |
396 | - public function is_payment_form_invoice( $invoice ) { |
|
397 | - $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
396 | + public function is_payment_form_invoice($invoice) { |
|
397 | + $created_via = get_post_meta($invoice, 'wpinv_created_via', true); |
|
398 | 398 | $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
399 | - $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
400 | - return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
399 | + $is_payment_form_invoice = apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice); |
|
400 | + return empty($_GET['getpaid-admin-action']) && $is_payment_form_invoice; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -406,12 +406,12 @@ discard block |
||
406 | 406 | * @param WPInv_Invoice $invoice |
407 | 407 | * @param string $note |
408 | 408 | */ |
409 | - public function user_note( $invoice, $note ) { |
|
409 | + public function user_note($invoice, $note) { |
|
410 | 410 | |
411 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
411 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
412 | 412 | $recipient = $invoice->get_email(); |
413 | 413 | |
414 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
414 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
415 | 415 | |
416 | 416 | } |
417 | 417 | |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @param WPInv_Invoice $invoice |
422 | 422 | */ |
423 | - public function force_send_overdue_notice( $invoice ) { |
|
424 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
425 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
423 | + public function force_send_overdue_notice($invoice) { |
|
424 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
425 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -433,38 +433,38 @@ discard block |
||
433 | 433 | public function overdue() { |
434 | 434 | global $wpdb; |
435 | 435 | |
436 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
436 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
437 | 437 | |
438 | 438 | // Fetch reminder days. |
439 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
439 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
440 | 440 | |
441 | 441 | // Abort if non is set. |
442 | - if ( empty( $reminder_days ) ) { |
|
442 | + if (empty($reminder_days)) { |
|
443 | 443 | return; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Retrieve date query. |
447 | - $date_query = $this->get_date_query( $reminder_days ); |
|
447 | + $date_query = $this->get_date_query($reminder_days); |
|
448 | 448 | |
449 | 449 | // Invoices table. |
450 | 450 | $table = $wpdb->prefix . 'getpaid_invoices'; |
451 | 451 | |
452 | 452 | // Fetch invoices. |
453 | - $invoices = $wpdb->get_col( |
|
453 | + $invoices = $wpdb->get_col( |
|
454 | 454 | "SELECT posts.ID FROM $wpdb->posts as posts |
455 | 455 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
456 | 456 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
457 | 457 | ); |
458 | 458 | |
459 | - foreach ( $invoices as $invoice ) { |
|
459 | + foreach ($invoices as $invoice) { |
|
460 | 460 | |
461 | 461 | // Only send this email for invoices created via the admin page. |
462 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
463 | - $invoice = new WPInv_Invoice( $invoice ); |
|
462 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
463 | + $invoice = new WPInv_Invoice($invoice); |
|
464 | 464 | $email->object = $invoice; |
465 | 465 | |
466 | - if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
467 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
466 | + if ($invoice->needs_payment() && !$invoice->is_renewal()) { |
|
467 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | } |
@@ -477,14 +477,14 @@ discard block |
||
477 | 477 | * @param array $reminder_days |
478 | 478 | * @return string |
479 | 479 | */ |
480 | - public function get_date_query( $reminder_days ) { |
|
480 | + public function get_date_query($reminder_days) { |
|
481 | 481 | |
482 | 482 | $date_query = array( |
483 | 483 | 'relation' => 'OR', |
484 | 484 | ); |
485 | 485 | |
486 | - foreach ( $reminder_days as $days ) { |
|
487 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
486 | + foreach ($reminder_days as $days) { |
|
487 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
488 | 488 | |
489 | 489 | $date_query[] = array( |
490 | 490 | 'year' => $date['year'], |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | |
495 | 495 | } |
496 | 496 | |
497 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
497 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
498 | 498 | |
499 | 499 | return $date_query->get_sql(); |
500 | 500 |
@@ -13,324 +13,324 @@ |
||
13 | 13 | class GetPaid_Subscription_Notification_Emails { |
14 | 14 | |
15 | 15 | /** |
16 | - * The array of subscription email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $subscription_actions; |
|
16 | + * The array of subscription email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $subscription_actions; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Class constructor |
|
23 | + * Class constructor |
|
24 | 24 | * |
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->subscription_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_subscription_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_subscription_active' => 'subscription_active', |
|
32 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
33 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
34 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
35 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
36 | - 'getpaid_daily_maintenance' => 'renewal_reminder' |
|
37 | - ) |
|
38 | - ); |
|
39 | - |
|
40 | - add_action( 'init', array( $this, 'init_hooks' ) ); |
|
41 | - } |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->subscription_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_subscription_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_subscription_active' => 'subscription_active', |
|
32 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
33 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
34 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
35 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
36 | + 'getpaid_daily_maintenance' => 'renewal_reminder' |
|
37 | + ) |
|
38 | + ); |
|
39 | + |
|
40 | + add_action( 'init', array( $this, 'init_hooks' ) ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | /** |
44 | - * Registers email hooks. |
|
45 | - */ |
|
46 | - public function init_hooks() { |
|
47 | - |
|
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | - |
|
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | - |
|
53 | - if ( ! $email->is_active() ) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | - continue; |
|
60 | - } |
|
61 | - |
|
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Filters subscription merge tags. |
|
70 | - * |
|
71 | - * @param array $merge_tags |
|
72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | - */ |
|
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
75 | - |
|
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | - $merge_tags = array_merge( |
|
78 | - $merge_tags, |
|
79 | - $this->get_subscription_merge_tags( $object ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - return $merge_tags; |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates subscription merge tags. |
|
89 | - * |
|
90 | - * @param WPInv_Subscription $subscription |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
94 | - |
|
95 | - // Abort if it does not exist. |
|
96 | - if ( ! $subscription->get_id() ) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $invoice = $subscription->get_parent_invoice(); |
|
101 | - return array( |
|
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | - ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Checks if we should send a notification for a subscription. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function should_send_notification( $invoice ) { |
|
123 | - return 0 != $invoice->get_id(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns notification recipients. |
|
128 | - * |
|
129 | - * @param WPInv_Invoice $invoice |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
134 | - |
|
135 | - $cc = $invoice->get_email_cc(); |
|
136 | - |
|
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | - } |
|
141 | - |
|
142 | - return $recipients; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Helper function to send an email. |
|
147 | - * |
|
148 | - * @param WPInv_Subscription $subscription |
|
149 | - * @param GetPaid_Notification_Email $email |
|
150 | - * @param string $type |
|
151 | - * @param array $extra_args Extra template args. |
|
152 | - */ |
|
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | - |
|
155 | - if ( empty( $subscription ) ) { |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - if ( is_array( $subscription ) ) { |
|
160 | - $subscription = current( $subscription ); |
|
161 | - } |
|
162 | - |
|
163 | - if ( ! $subscription instanceof WPInv_Subscription ) { |
|
164 | - return; |
|
165 | - } |
|
166 | - |
|
167 | - // Abort in case the parent invoice does not exist. |
|
168 | - $invoice = $subscription->get_parent_invoice(); |
|
169 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
170 | - return; |
|
171 | - } |
|
172 | - |
|
173 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
178 | - |
|
179 | - $recipients = $this->get_recipients( $invoice ); |
|
180 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
181 | - $merge_tags = $email->get_merge_tags(); |
|
182 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
183 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
184 | - $attachments = $email->get_attachments(); |
|
185 | - |
|
186 | - $result = $mailer->send( |
|
187 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
188 | - $subject, |
|
189 | - $content, |
|
190 | - $attachments |
|
191 | - ); |
|
192 | - |
|
193 | - // Maybe send a copy to the admin. |
|
194 | - if ( $email->include_admin_bcc() ) { |
|
195 | - $mailer->send( |
|
196 | - wpinv_get_admin_email(), |
|
197 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
198 | - $content, |
|
199 | - $attachments |
|
200 | - ); |
|
201 | - } |
|
202 | - |
|
203 | - if ( $result ) { |
|
204 | - $invoice->add_system_note( |
|
205 | - sprintf( |
|
206 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
207 | - sanitize_key( $type ), |
|
208 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
209 | - ) |
|
210 | - ); |
|
211 | - } else { |
|
212 | - $invoice->add_system_note( |
|
213 | - sprintf( |
|
214 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
215 | - sanitize_key( $type ), |
|
216 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
217 | - ) |
|
218 | - ); |
|
219 | - } |
|
220 | - |
|
221 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Sends a subscription active. |
|
227 | - * |
|
228 | - * @since 2.8.4 |
|
229 | - * |
|
230 | - * @param WPInv_Subscription $subscription |
|
231 | - */ |
|
232 | - public function subscription_active( $subscription ) { |
|
233 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
234 | - |
|
235 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
236 | - } |
|
44 | + * Registers email hooks. |
|
45 | + */ |
|
46 | + public function init_hooks() { |
|
47 | + |
|
48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | + |
|
51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | + |
|
53 | + if ( ! $email->is_active() ) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $email_type ) ) { |
|
58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | + continue; |
|
60 | + } |
|
61 | + |
|
62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
237 | 67 | |
238 | 68 | /** |
239 | - * Sends a new trial notification. |
|
240 | - * |
|
241 | - * @param WPInv_Subscription $subscription |
|
242 | - */ |
|
243 | - public function subscription_trial( $subscription ) { |
|
69 | + * Filters subscription merge tags. |
|
70 | + * |
|
71 | + * @param array $merge_tags |
|
72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | + */ |
|
74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
244 | 75 | |
245 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
246 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | + $merge_tags = array_merge( |
|
78 | + $merge_tags, |
|
79 | + $this->get_subscription_merge_tags( $object ) |
|
80 | + ); |
|
81 | + } |
|
247 | 82 | |
248 | - } |
|
83 | + return $merge_tags; |
|
249 | 84 | |
250 | - /** |
|
251 | - * Sends a cancelled subscription notification. |
|
252 | - * |
|
253 | - * @param WPInv_Subscription $subscription |
|
254 | - */ |
|
255 | - public function subscription_cancelled( $subscription ) { |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Generates subscription merge tags. |
|
89 | + * |
|
90 | + * @param WPInv_Subscription $subscription |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function get_subscription_merge_tags( $subscription ) { |
|
94 | + |
|
95 | + // Abort if it does not exist. |
|
96 | + if ( ! $subscription->get_id() ) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | + return array( |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | + ); |
|
113 | + |
|
114 | + } |
|
256 | 115 | |
257 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
258 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
116 | + /** |
|
117 | + * Checks if we should send a notification for a subscription. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function should_send_notification( $invoice ) { |
|
123 | + return 0 != $invoice->get_id(); |
|
124 | + } |
|
259 | 125 | |
260 | - } |
|
126 | + /** |
|
127 | + * Returns notification recipients. |
|
128 | + * |
|
129 | + * @param WPInv_Invoice $invoice |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function get_recipients( $invoice ) { |
|
133 | + $recipients = array( $invoice->get_email() ); |
|
261 | 134 | |
262 | - /** |
|
263 | - * Sends a subscription expired notification. |
|
264 | - * |
|
265 | - * @param WPInv_Subscription $subscription |
|
266 | - */ |
|
267 | - public function subscription_expired( $subscription ) { |
|
135 | + $cc = $invoice->get_email_cc(); |
|
268 | 136 | |
269 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
270 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
137 | + if ( ! empty( $cc ) ) { |
|
138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | + } |
|
271 | 141 | |
272 | - } |
|
142 | + return $recipients; |
|
143 | + } |
|
273 | 144 | |
274 | - /** |
|
275 | - * Sends a completed subscription notification. |
|
276 | - * |
|
277 | - * @param WPInv_Subscription $subscription |
|
278 | - */ |
|
279 | - public function subscription_complete( $subscription ) { |
|
145 | + /** |
|
146 | + * Helper function to send an email. |
|
147 | + * |
|
148 | + * @param WPInv_Subscription $subscription |
|
149 | + * @param GetPaid_Notification_Email $email |
|
150 | + * @param string $type |
|
151 | + * @param array $extra_args Extra template args. |
|
152 | + */ |
|
153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | + |
|
155 | + if ( empty( $subscription ) ) { |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + if ( is_array( $subscription ) ) { |
|
160 | + $subscription = current( $subscription ); |
|
161 | + } |
|
162 | + |
|
163 | + if ( ! $subscription instanceof WPInv_Subscription ) { |
|
164 | + return; |
|
165 | + } |
|
166 | + |
|
167 | + // Abort in case the parent invoice does not exist. |
|
168 | + $invoice = $subscription->get_parent_invoice(); |
|
169 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
170 | + return; |
|
171 | + } |
|
172 | + |
|
173 | + if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
178 | + |
|
179 | + $recipients = $this->get_recipients( $invoice ); |
|
180 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
181 | + $merge_tags = $email->get_merge_tags(); |
|
182 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
183 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
184 | + $attachments = $email->get_attachments(); |
|
185 | + |
|
186 | + $result = $mailer->send( |
|
187 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
188 | + $subject, |
|
189 | + $content, |
|
190 | + $attachments |
|
191 | + ); |
|
192 | + |
|
193 | + // Maybe send a copy to the admin. |
|
194 | + if ( $email->include_admin_bcc() ) { |
|
195 | + $mailer->send( |
|
196 | + wpinv_get_admin_email(), |
|
197 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
198 | + $content, |
|
199 | + $attachments |
|
200 | + ); |
|
201 | + } |
|
202 | + |
|
203 | + if ( $result ) { |
|
204 | + $invoice->add_system_note( |
|
205 | + sprintf( |
|
206 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
207 | + sanitize_key( $type ), |
|
208 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
209 | + ) |
|
210 | + ); |
|
211 | + } else { |
|
212 | + $invoice->add_system_note( |
|
213 | + sprintf( |
|
214 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
215 | + sanitize_key( $type ), |
|
216 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
217 | + ) |
|
218 | + ); |
|
219 | + } |
|
220 | + |
|
221 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
222 | + |
|
223 | + } |
|
280 | 224 | |
281 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
282 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
225 | + /** |
|
226 | + * Sends a subscription active. |
|
227 | + * |
|
228 | + * @since 2.8.4 |
|
229 | + * |
|
230 | + * @param WPInv_Subscription $subscription |
|
231 | + */ |
|
232 | + public function subscription_active( $subscription ) { |
|
233 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
283 | 234 | |
284 | - } |
|
235 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
236 | + } |
|
285 | 237 | |
286 | - /** |
|
287 | - * Sends a subscription renewal reminder notification. |
|
288 | - * |
|
289 | - */ |
|
290 | - public function renewal_reminder() { |
|
238 | + /** |
|
239 | + * Sends a new trial notification. |
|
240 | + * |
|
241 | + * @param WPInv_Subscription $subscription |
|
242 | + */ |
|
243 | + public function subscription_trial( $subscription ) { |
|
244 | + |
|
245 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
246 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
247 | + |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Sends a cancelled subscription notification. |
|
252 | + * |
|
253 | + * @param WPInv_Subscription $subscription |
|
254 | + */ |
|
255 | + public function subscription_cancelled( $subscription ) { |
|
256 | + |
|
257 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
258 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
259 | + |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Sends a subscription expired notification. |
|
264 | + * |
|
265 | + * @param WPInv_Subscription $subscription |
|
266 | + */ |
|
267 | + public function subscription_expired( $subscription ) { |
|
268 | + |
|
269 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
270 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
271 | + |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Sends a completed subscription notification. |
|
276 | + * |
|
277 | + * @param WPInv_Subscription $subscription |
|
278 | + */ |
|
279 | + public function subscription_complete( $subscription ) { |
|
280 | + |
|
281 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
282 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
283 | + |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Sends a subscription renewal reminder notification. |
|
288 | + * |
|
289 | + */ |
|
290 | + public function renewal_reminder() { |
|
291 | 291 | |
292 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
292 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
293 | 293 | |
294 | - // Fetch reminder days. |
|
295 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
294 | + // Fetch reminder days. |
|
295 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
296 | 296 | |
297 | - // Abort if non is set. |
|
298 | - if ( empty( $reminder_days ) ) { |
|
299 | - return; |
|
300 | - } |
|
297 | + // Abort if non is set. |
|
298 | + if ( empty( $reminder_days ) ) { |
|
299 | + return; |
|
300 | + } |
|
301 | 301 | |
302 | - // Fetch matching subscriptions. |
|
302 | + // Fetch matching subscriptions. |
|
303 | 303 | $args = array( |
304 | 304 | 'number' => -1, |
305 | - 'count_total' => false, |
|
306 | - 'status' => 'trialling active', |
|
305 | + 'count_total' => false, |
|
306 | + 'status' => 'trialling active', |
|
307 | 307 | 'date_expires_query' => array( |
308 | - 'relation' => 'OR', |
|
308 | + 'relation' => 'OR', |
|
309 | 309 | ), |
310 | - ); |
|
310 | + ); |
|
311 | 311 | |
312 | - foreach ( $reminder_days as $days ) { |
|
313 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
312 | + foreach ( $reminder_days as $days ) { |
|
313 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
314 | 314 | |
315 | - $args['date_expires_query'][] = array( |
|
316 | - 'year' => $date['year'], |
|
317 | - 'month' => $date['month'], |
|
318 | - 'day' => $date['day'], |
|
319 | - ); |
|
315 | + $args['date_expires_query'][] = array( |
|
316 | + 'year' => $date['year'], |
|
317 | + 'month' => $date['month'], |
|
318 | + 'day' => $date['day'], |
|
319 | + ); |
|
320 | 320 | |
321 | - } |
|
321 | + } |
|
322 | 322 | |
323 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
323 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
324 | 324 | |
325 | 325 | foreach ( $subscriptions->get_results() as $subscription ) { |
326 | 326 | |
327 | - // Skip packages. |
|
328 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
329 | - $email->object = $subscription; |
|
330 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
331 | - } |
|
332 | - } |
|
327 | + // Skip packages. |
|
328 | + if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
329 | + $email->object = $subscription; |
|
330 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
331 | + } |
|
332 | + } |
|
333 | 333 | |
334 | - } |
|
334 | + } |
|
335 | 335 | |
336 | 336 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class handles subscription notificaiton emails. |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | ) |
38 | 38 | ); |
39 | 39 | |
40 | - add_action( 'init', array( $this, 'init_hooks' ) ); |
|
40 | + add_action('init', array($this, 'init_hooks')); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function init_hooks() { |
47 | 47 | |
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
48 | + add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2); |
|
49 | + foreach ($this->subscription_actions as $hook => $email_type) { |
|
50 | 50 | |
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
51 | + $email = new GetPaid_Notification_Email($email_type); |
|
52 | 52 | |
53 | - if ( ! $email->is_active() ) { |
|
53 | + if (!$email->is_active()) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
57 | + if (method_exists($this, $email_type)) { |
|
58 | + add_action($hook, array($this, $email_type), 100, 2); |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
62 | + do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | * @param array $merge_tags |
72 | 72 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
73 | 73 | */ |
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
74 | + public function subscription_merge_tags($merge_tags, $object) { |
|
75 | 75 | |
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
76 | + if (is_a($object, 'WPInv_Subscription')) { |
|
77 | 77 | $merge_tags = array_merge( |
78 | 78 | $merge_tags, |
79 | - $this->get_subscription_merge_tags( $object ) |
|
79 | + $this->get_subscription_merge_tags($object) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -90,25 +90,25 @@ discard block |
||
90 | 90 | * @param WPInv_Subscription $subscription |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
93 | + public function get_subscription_merge_tags($subscription) { |
|
94 | 94 | |
95 | 95 | // Abort if it does not exist. |
96 | - if ( ! $subscription->get_id() ) { |
|
96 | + if (!$subscription->get_id()) { |
|
97 | 97 | return array(); |
98 | 98 | } |
99 | 99 | |
100 | - $invoice = $subscription->get_parent_invoice(); |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | 101 | return array( |
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')), |
|
103 | + '{subscription_created}' => getpaid_format_date_value($subscription->get_date_created()), |
|
104 | + '{subscription_status}' => sanitize_text_field($subscription->get_status_label()), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field($subscription->get_profile_id()), |
|
106 | + '{subscription_id}' => absint($subscription->get_id()), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''), |
|
110 | 110 | '{subscription_bill_times}' => $subscription->get_bill_times(), |
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
111 | + '{subscription_url}' => esc_url($subscription->get_view_url()), |
|
112 | 112 | ); |
113 | 113 | |
114 | 114 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return bool |
121 | 121 | */ |
122 | - public function should_send_notification( $invoice ) { |
|
122 | + public function should_send_notification($invoice) { |
|
123 | 123 | return 0 != $invoice->get_id(); |
124 | 124 | } |
125 | 125 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * @param WPInv_Invoice $invoice |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
132 | + public function get_recipients($invoice) { |
|
133 | + $recipients = array($invoice->get_email()); |
|
134 | 134 | |
135 | 135 | $cc = $invoice->get_email_cc(); |
136 | 136 | |
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
137 | + if (!empty($cc)) { |
|
138 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
139 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return $recipients; |
@@ -150,75 +150,75 @@ discard block |
||
150 | 150 | * @param string $type |
151 | 151 | * @param array $extra_args Extra template args. |
152 | 152 | */ |
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
153 | + public function send_email($subscription, $email, $type, $extra_args = array()) { |
|
154 | 154 | |
155 | - if ( empty( $subscription ) ) { |
|
155 | + if (empty($subscription)) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | - if ( is_array( $subscription ) ) { |
|
160 | - $subscription = current( $subscription ); |
|
159 | + if (is_array($subscription)) { |
|
160 | + $subscription = current($subscription); |
|
161 | 161 | } |
162 | 162 | |
163 | - if ( ! $subscription instanceof WPInv_Subscription ) { |
|
163 | + if (!$subscription instanceof WPInv_Subscription) { |
|
164 | 164 | return; |
165 | 165 | } |
166 | 166 | |
167 | 167 | // Abort in case the parent invoice does not exist. |
168 | 168 | $invoice = $subscription->get_parent_invoice(); |
169 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
169 | + if (!$this->should_send_notification($invoice)) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | |
173 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
173 | + if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) { |
|
174 | 174 | return; |
175 | 175 | } |
176 | 176 | |
177 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
177 | + do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email); |
|
178 | 178 | |
179 | - $recipients = $this->get_recipients( $invoice ); |
|
179 | + $recipients = $this->get_recipients($invoice); |
|
180 | 180 | $mailer = new GetPaid_Notification_Email_Sender(); |
181 | 181 | $merge_tags = $email->get_merge_tags(); |
182 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
183 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
182 | + $content = $email->get_content($merge_tags, $extra_args); |
|
183 | + $subject = $email->add_merge_tags($email->get_subject(), $merge_tags); |
|
184 | 184 | $attachments = $email->get_attachments(); |
185 | 185 | |
186 | 186 | $result = $mailer->send( |
187 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
187 | + apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email), |
|
188 | 188 | $subject, |
189 | 189 | $content, |
190 | 190 | $attachments |
191 | 191 | ); |
192 | 192 | |
193 | 193 | // Maybe send a copy to the admin. |
194 | - if ( $email->include_admin_bcc() ) { |
|
194 | + if ($email->include_admin_bcc()) { |
|
195 | 195 | $mailer->send( |
196 | 196 | wpinv_get_admin_email(), |
197 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
197 | + $subject . __(' - ADMIN BCC COPY', 'invoicing'), |
|
198 | 198 | $content, |
199 | 199 | $attachments |
200 | 200 | ); |
201 | 201 | } |
202 | 202 | |
203 | - if ( $result ) { |
|
203 | + if ($result) { |
|
204 | 204 | $invoice->add_system_note( |
205 | 205 | sprintf( |
206 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
207 | - sanitize_key( $type ), |
|
208 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
206 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
207 | + sanitize_key($type), |
|
208 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
209 | 209 | ) |
210 | 210 | ); |
211 | 211 | } else { |
212 | 212 | $invoice->add_system_note( |
213 | 213 | sprintf( |
214 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
215 | - sanitize_key( $type ), |
|
216 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
214 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
215 | + sanitize_key($type), |
|
216 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
217 | 217 | ) |
218 | 218 | ); |
219 | 219 | } |
220 | 220 | |
221 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
221 | + do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @param WPInv_Subscription $subscription |
231 | 231 | */ |
232 | - public function subscription_active( $subscription ) { |
|
233 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
232 | + public function subscription_active($subscription) { |
|
233 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
234 | 234 | |
235 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
235 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -240,10 +240,10 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @param WPInv_Subscription $subscription |
242 | 242 | */ |
243 | - public function subscription_trial( $subscription ) { |
|
243 | + public function subscription_trial($subscription) { |
|
244 | 244 | |
245 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
246 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
245 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
246 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
247 | 247 | |
248 | 248 | } |
249 | 249 | |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @param WPInv_Subscription $subscription |
254 | 254 | */ |
255 | - public function subscription_cancelled( $subscription ) { |
|
255 | + public function subscription_cancelled($subscription) { |
|
256 | 256 | |
257 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
258 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
257 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
258 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
259 | 259 | |
260 | 260 | } |
261 | 261 | |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | * |
265 | 265 | * @param WPInv_Subscription $subscription |
266 | 266 | */ |
267 | - public function subscription_expired( $subscription ) { |
|
267 | + public function subscription_expired($subscription) { |
|
268 | 268 | |
269 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
270 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
269 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
270 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
271 | 271 | |
272 | 272 | } |
273 | 273 | |
@@ -276,10 +276,10 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @param WPInv_Subscription $subscription |
278 | 278 | */ |
279 | - public function subscription_complete( $subscription ) { |
|
279 | + public function subscription_complete($subscription) { |
|
280 | 280 | |
281 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
282 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
281 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
282 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
283 | 283 | |
284 | 284 | } |
285 | 285 | |
@@ -289,18 +289,18 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function renewal_reminder() { |
291 | 291 | |
292 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
292 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
293 | 293 | |
294 | 294 | // Fetch reminder days. |
295 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
295 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
296 | 296 | |
297 | 297 | // Abort if non is set. |
298 | - if ( empty( $reminder_days ) ) { |
|
298 | + if (empty($reminder_days)) { |
|
299 | 299 | return; |
300 | 300 | } |
301 | 301 | |
302 | 302 | // Fetch matching subscriptions. |
303 | - $args = array( |
|
303 | + $args = array( |
|
304 | 304 | 'number' => -1, |
305 | 305 | 'count_total' => false, |
306 | 306 | 'status' => 'trialling active', |
@@ -309,8 +309,8 @@ discard block |
||
309 | 309 | ), |
310 | 310 | ); |
311 | 311 | |
312 | - foreach ( $reminder_days as $days ) { |
|
313 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
312 | + foreach ($reminder_days as $days) { |
|
313 | + $date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp')))); |
|
314 | 314 | |
315 | 315 | $args['date_expires_query'][] = array( |
316 | 316 | 'year' => $date['year'], |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | |
321 | 321 | } |
322 | 322 | |
323 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
323 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
324 | 324 | |
325 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
325 | + foreach ($subscriptions->get_results() as $subscription) { |
|
326 | 326 | |
327 | 327 | // Skip packages. |
328 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
328 | + if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) { |
|
329 | 329 | $email->object = $subscription; |
330 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
330 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 |
@@ -34,12 +34,12 @@ |
||
34 | 34 | // Prepare pagination |
35 | 35 | $pagination = paginate_links( |
36 | 36 | array( |
37 | - 'base' => add_query_arg( 'paged', '%#%' ), |
|
38 | - 'format' => '', |
|
39 | - 'prev_text' => __( '«', 'invoicing' ), |
|
40 | - 'next_text' => __( '»', 'invoicing' ), |
|
41 | - 'total' => ceil( $total_logs / $per_page ), |
|
42 | - 'current' => $page, |
|
37 | + 'base' => add_query_arg( 'paged', '%#%' ), |
|
38 | + 'format' => '', |
|
39 | + 'prev_text' => __( '«', 'invoicing' ), |
|
40 | + 'next_text' => __( '»', 'invoicing' ), |
|
41 | + 'total' => ceil( $total_logs / $per_page ), |
|
42 | + 'current' => $page, |
|
43 | 43 | ) |
44 | 44 | ); |
45 | 45 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @since 2.8.22 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * GetPaid_Anonymization_Logs Class |
@@ -19,89 +19,89 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function display_logs() { |
21 | 21 | // Check user capabilities |
22 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
22 | + if (!current_user_can('manage_options')) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 | |
26 | 26 | // Get current page number |
27 | - $page = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
27 | + $page = isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
28 | 28 | $per_page = 20; |
29 | 29 | |
30 | 30 | // Fetch logs |
31 | - $logs = $this->get_logs( $page, $per_page ); |
|
31 | + $logs = $this->get_logs($page, $per_page); |
|
32 | 32 | $total_logs = $this->get_total_logs(); |
33 | 33 | |
34 | 34 | // Prepare pagination |
35 | 35 | $pagination = paginate_links( |
36 | 36 | array( |
37 | - 'base' => add_query_arg( 'paged', '%#%' ), |
|
37 | + 'base' => add_query_arg('paged', '%#%'), |
|
38 | 38 | 'format' => '', |
39 | - 'prev_text' => __( '«', 'invoicing' ), |
|
40 | - 'next_text' => __( '»', 'invoicing' ), |
|
41 | - 'total' => ceil( $total_logs / $per_page ), |
|
39 | + 'prev_text' => __('«', 'invoicing'), |
|
40 | + 'next_text' => __('»', 'invoicing'), |
|
41 | + 'total' => ceil($total_logs / $per_page), |
|
42 | 42 | 'current' => $page, |
43 | 43 | ) |
44 | 44 | ); |
45 | 45 | |
46 | 46 | ?> |
47 | 47 | <div class="wrap getpaid-anonymization-logs"> |
48 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
48 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
49 | 49 | <div class="tablenav top"> |
50 | 50 | <div class="alignleft actions"> |
51 | 51 | <form method="get"> |
52 | 52 | <input type="hidden" name="page" value="wpinv-anonymization-logs"> |
53 | - <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date', 'invoicing' ); ?></label> |
|
53 | + <label for="filter-by-date" class="screen-reader-text"><?php _e('Filter by date', 'invoicing'); ?></label> |
|
54 | 54 | <select name="m" id="filter-by-date"> |
55 | - <option value="0"><?php _e( 'All dates', 'invoicing' ); ?></option> |
|
55 | + <option value="0"><?php _e('All dates', 'invoicing'); ?></option> |
|
56 | 56 | <?php |
57 | 57 | $months = $this->get_log_months(); |
58 | - foreach ( $months as $month ) { |
|
59 | - $selected = ( isset( $_GET['m'] ) && $_GET['m'] == $month->month ) ? ' selected="selected"' : ''; |
|
60 | - echo '<option value="' . esc_attr( $month->month ) . '"' . $selected . '>' . esc_html( $month->month_name . ' ' . $month->year ) . '</option>'; |
|
58 | + foreach ($months as $month) { |
|
59 | + $selected = (isset($_GET['m']) && $_GET['m'] == $month->month) ? ' selected="selected"' : ''; |
|
60 | + echo '<option value="' . esc_attr($month->month) . '"' . $selected . '>' . esc_html($month->month_name . ' ' . $month->year) . '</option>'; |
|
61 | 61 | } |
62 | 62 | ?> |
63 | 63 | </select> |
64 | - <?php submit_button( __( 'Filter', 'invoicing' ), '', 'filter_action', false ); ?> |
|
64 | + <?php submit_button(__('Filter', 'invoicing'), '', 'filter_action', false); ?> |
|
65 | 65 | </form> |
66 | 66 | </div> |
67 | 67 | </div> |
68 | 68 | <table class="wp-list-table widefat fixed striped"> |
69 | 69 | <thead> |
70 | 70 | <tr> |
71 | - <th><?php _e( 'Log ID', 'invoicing' ); ?></th> |
|
72 | - <th><?php _e( 'User', 'invoicing' ); ?></th> |
|
73 | - <th><?php _e( 'Action', 'invoicing' ); ?></th> |
|
74 | - <th><?php _e( 'Date', 'invoicing' ); ?></th> |
|
75 | - <th><?php _e( 'Details', 'invoicing' ); ?></th> |
|
71 | + <th><?php _e('Log ID', 'invoicing'); ?></th> |
|
72 | + <th><?php _e('User', 'invoicing'); ?></th> |
|
73 | + <th><?php _e('Action', 'invoicing'); ?></th> |
|
74 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
75 | + <th><?php _e('Details', 'invoicing'); ?></th> |
|
76 | 76 | </tr> |
77 | 77 | </thead> |
78 | 78 | <tbody> |
79 | - <?php if ( empty( $logs ) ) : ?> |
|
79 | + <?php if (empty($logs)) : ?> |
|
80 | 80 | <tr> |
81 | - <td colspan="5"><?php _e( 'No anonymization logs found.', 'invoicing' ); ?></td> |
|
81 | + <td colspan="5"><?php _e('No anonymization logs found.', 'invoicing'); ?></td> |
|
82 | 82 | </tr> |
83 | 83 | <?php else : ?> |
84 | 84 | <?php |
85 | - foreach ( $logs as $log ) : |
|
86 | - $additional_info = json_decode( $log->additional_info, true ); |
|
85 | + foreach ($logs as $log) : |
|
86 | + $additional_info = json_decode($log->additional_info, true); |
|
87 | 87 | ?> |
88 | 88 | <tr> |
89 | - <td><?php echo esc_html( $log->log_id ); ?></td> |
|
89 | + <td><?php echo esc_html($log->log_id); ?></td> |
|
90 | 90 | <td> |
91 | 91 | <?php |
92 | - $user_edit_link = get_edit_user_link( $log->user_id ); |
|
93 | - if ( $user_edit_link ) { |
|
94 | - echo '<a href="' . esc_url( $user_edit_link ) . '">' . esc_html( $log->user_id ) . '</a>'; |
|
92 | + $user_edit_link = get_edit_user_link($log->user_id); |
|
93 | + if ($user_edit_link) { |
|
94 | + echo '<a href="' . esc_url($user_edit_link) . '">' . esc_html($log->user_id) . '</a>'; |
|
95 | 95 | } else { |
96 | - echo esc_html( $log->user_id ); |
|
96 | + echo esc_html($log->user_id); |
|
97 | 97 | } |
98 | 98 | ?> |
99 | 99 | </td> |
100 | - <td><?php echo esc_html( ucfirst( $log->action ) ); ?></td> |
|
101 | - <td><?php echo esc_html( get_date_from_gmt( $log->timestamp, 'F j, Y g:i a' ) ); ?></td> |
|
100 | + <td><?php echo esc_html(ucfirst($log->action)); ?></td> |
|
101 | + <td><?php echo esc_html(get_date_from_gmt($log->timestamp, 'F j, Y g:i a')); ?></td> |
|
102 | 102 | <td> |
103 | 103 | <button class="button-link toggle-details" type="button" aria-expanded="false"> |
104 | - <span class="screen-reader-text"><?php _e( 'Show more details', 'invoicing' ); ?></span> |
|
104 | + <span class="screen-reader-text"><?php _e('Show more details', 'invoicing'); ?></span> |
|
105 | 105 | <span class="dashicons dashicons-arrow-down-alt2"></span> |
106 | 106 | </button> |
107 | 107 | </td> |
@@ -112,19 +112,19 @@ discard block |
||
112 | 112 | <table class="widefat fixed"> |
113 | 113 | <tbody> |
114 | 114 | <tr> |
115 | - <th><?php _e( 'Data Type', 'invoicing' ); ?></th> |
|
116 | - <td><?php echo esc_html( $log->data_type ); ?></td> |
|
115 | + <th><?php _e('Data Type', 'invoicing'); ?></th> |
|
116 | + <td><?php echo esc_html($log->data_type); ?></td> |
|
117 | 117 | </tr> |
118 | - <?php if ( is_array( $additional_info ) ) : ?> |
|
118 | + <?php if (is_array($additional_info)) : ?> |
|
119 | 119 | <tr> |
120 | - <th><?php _e( 'Additional Information', 'invoicing' ); ?></th> |
|
120 | + <th><?php _e('Additional Information', 'invoicing'); ?></th> |
|
121 | 121 | <td> |
122 | 122 | <table class="widefat fixed"> |
123 | 123 | <tbody> |
124 | - <?php foreach ( $additional_info as $key => $value ) : ?> |
|
124 | + <?php foreach ($additional_info as $key => $value) : ?> |
|
125 | 125 | <tr> |
126 | - <th><?php echo esc_html( $key ); ?></th> |
|
127 | - <td><?php echo esc_html( $value ); ?></td> |
|
126 | + <th><?php echo esc_html($key); ?></th> |
|
127 | + <td><?php echo esc_html($value); ?></td> |
|
128 | 128 | </tr> |
129 | 129 | <?php endforeach; ?> |
130 | 130 | </tbody> |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | <?php endif; ?> |
142 | 142 | </tbody> |
143 | 143 | </table> |
144 | - <?php if ( $pagination ) : ?> |
|
144 | + <?php if ($pagination) : ?> |
|
145 | 145 | <div class="tablenav bottom"> |
146 | 146 | <div class="tablenav-pages"> |
147 | 147 | <?php echo $pagination; ?> |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | * @param int $per_page Number of logs per page |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - private function get_logs( $page, $per_page ) { |
|
162 | + private function get_logs($page, $per_page) { |
|
163 | 163 | global $wpdb; |
164 | 164 | $table_name = $wpdb->prefix . 'getpaid_anonymization_logs'; |
165 | - $offset = ( $page - 1 ) * $per_page; |
|
165 | + $offset = ($page - 1) * $per_page; |
|
166 | 166 | |
167 | 167 | $query = $wpdb->prepare( |
168 | 168 | "SELECT * FROM $table_name ORDER BY timestamp DESC LIMIT %d OFFSET %d", |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $offset |
171 | 171 | ); |
172 | 172 | |
173 | - return $wpdb->get_results( $query ); |
|
173 | + return $wpdb->get_results($query); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | private function get_total_logs() { |
182 | 182 | global $wpdb; |
183 | 183 | $table_name = $wpdb->prefix . 'getpaid_anonymization_logs'; |
184 | - return $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" ); |
|
184 | + return $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -80,10 +80,12 @@ |
||
80 | 80 | <tr> |
81 | 81 | <td colspan="5"><?php _e( 'No anonymization logs found.', 'invoicing' ); ?></td> |
82 | 82 | </tr> |
83 | - <?php else : ?> |
|
83 | + <?php else { |
|
84 | + : ?> |
|
84 | 85 | <?php |
85 | 86 | foreach ( $logs as $log ) : |
86 | 87 | $additional_info = json_decode( $log->additional_info, true ); |
88 | +} |
|
87 | 89 | ?> |
88 | 90 | <tr> |
89 | 91 | <td><?php echo esc_html( $log->log_id ); ?></td> |
@@ -291,18 +291,18 @@ |
||
291 | 291 | |
292 | 292 | $user_meta_data = array( |
293 | 293 | 'nickname', |
294 | - 'description', |
|
295 | - 'rich_editing', |
|
296 | - 'syntax_highlighting', |
|
297 | - 'comment_shortcuts', |
|
294 | + 'description', |
|
295 | + 'rich_editing', |
|
296 | + 'syntax_highlighting', |
|
297 | + 'comment_shortcuts', |
|
298 | 298 | 'admin_color', |
299 | - 'use_ssl', |
|
300 | - 'show_admin_bar_front', |
|
301 | - 'locale', |
|
302 | - 'wp_capabilities', |
|
299 | + 'use_ssl', |
|
300 | + 'show_admin_bar_front', |
|
301 | + 'locale', |
|
302 | + 'wp_capabilities', |
|
303 | 303 | 'wp_user_level', |
304 | - 'dismissed_wp_pointers', |
|
305 | - 'show_welcome_panel', |
|
304 | + 'dismissed_wp_pointers', |
|
305 | + 'show_welcome_panel', |
|
306 | 306 | ); |
307 | 307 | |
308 | 308 | /** |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 2.8.22 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Data_Retention Class. |
@@ -35,13 +35,13 @@ discard block |
||
35 | 35 | * Class constructor. |
36 | 36 | */ |
37 | 37 | public function __construct() { |
38 | - add_filter( 'wpinv_settings_misc', array( $this, 'add_data_retention_settings' ) ); |
|
38 | + add_filter('wpinv_settings_misc', array($this, 'add_data_retention_settings')); |
|
39 | 39 | |
40 | - add_action( 'wpmu_delete_user', array( $this, 'maybe_handle_user_deletion' ), 1 ); |
|
41 | - add_action( 'delete_user', array( $this, 'maybe_handle_user_deletion' ), 1 ); |
|
42 | - add_filter( 'wp_privacy_personal_data_erasure_request', array( $this, 'handle_erasure_request' ), 10, 2 ); |
|
40 | + add_action('wpmu_delete_user', array($this, 'maybe_handle_user_deletion'), 1); |
|
41 | + add_action('delete_user', array($this, 'maybe_handle_user_deletion'), 1); |
|
42 | + add_filter('wp_privacy_personal_data_erasure_request', array($this, 'handle_erasure_request'), 10, 2); |
|
43 | 43 | |
44 | - add_action( 'getpaid_daily_maintenance', array( $this, 'perform_data_retention_cleanup' ) ); |
|
44 | + add_action('getpaid_daily_maintenance', array($this, 'perform_data_retention_cleanup')); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -50,43 +50,43 @@ discard block |
||
50 | 50 | * @param array $misc_settings Existing misc settings. |
51 | 51 | * @return array Updated misc settings. |
52 | 52 | */ |
53 | - public function add_data_retention_settings( $misc_settings ) { |
|
53 | + public function add_data_retention_settings($misc_settings) { |
|
54 | 54 | $misc_settings['data_retention'] = array( |
55 | 55 | 'id' => 'data_retention', |
56 | - 'name' => '<h3>' . __( 'Data Retention', 'invoicing' ) . '</h3>', |
|
56 | + 'name' => '<h3>' . __('Data Retention', 'invoicing') . '</h3>', |
|
57 | 57 | 'type' => 'header', |
58 | 58 | ); |
59 | 59 | |
60 | 60 | $misc_settings['data_retention_method'] = array( |
61 | 61 | 'id' => 'data_retention_method', |
62 | - 'name' => __( 'Data Handling', 'invoicing' ), |
|
63 | - 'desc' => __( 'Choose how to handle user data when deletion is required.', 'invoicing' ), |
|
62 | + 'name' => __('Data Handling', 'invoicing'), |
|
63 | + 'desc' => __('Choose how to handle user data when deletion is required.', 'invoicing'), |
|
64 | 64 | 'type' => 'select', |
65 | 65 | 'options' => array( |
66 | - 'anonymize' => __( 'Anonymize data', 'invoicing' ), |
|
67 | - 'delete' => __( 'Delete data without anonymization', 'invoicing' ), |
|
66 | + 'anonymize' => __('Anonymize data', 'invoicing'), |
|
67 | + 'delete' => __('Delete data without anonymization', 'invoicing'), |
|
68 | 68 | ), |
69 | 69 | 'std' => 'anonymize', |
70 | - 'tooltip' => __( 'Anonymization replaces personal data with non-identifiable information. Direct deletion removes all data permanently.', 'invoicing' ), |
|
70 | + 'tooltip' => __('Anonymization replaces personal data with non-identifiable information. Direct deletion removes all data permanently.', 'invoicing'), |
|
71 | 71 | ); |
72 | 72 | |
73 | 73 | $misc_settings['data_retention_period'] = array( |
74 | 74 | 'id' => 'data_retention_period', |
75 | - 'name' => __( 'Retention Period', 'invoicing' ), |
|
76 | - 'desc' => __( 'Specify how long to retain customer data after processing.', 'invoicing' ), |
|
75 | + 'name' => __('Retention Period', 'invoicing'), |
|
76 | + 'desc' => __('Specify how long to retain customer data after processing.', 'invoicing'), |
|
77 | 77 | 'type' => 'select', |
78 | 78 | 'options' => array( |
79 | - 'never' => __( 'Never delete (retain indefinitely)', 'invoicing' ), |
|
80 | - '30' => __( '30 days', 'invoicing' ), |
|
81 | - '90' => __( '90 days', 'invoicing' ), |
|
82 | - '180' => __( '6 months', 'invoicing' ), |
|
83 | - '365' => __( '1 year', 'invoicing' ), |
|
84 | - '730' => __( '2 years', 'invoicing' ), |
|
85 | - '1825' => __( '5 years', 'invoicing' ), |
|
86 | - '3650' => __( '10 years', 'invoicing' ), |
|
79 | + 'never' => __('Never delete (retain indefinitely)', 'invoicing'), |
|
80 | + '30' => __('30 days', 'invoicing'), |
|
81 | + '90' => __('90 days', 'invoicing'), |
|
82 | + '180' => __('6 months', 'invoicing'), |
|
83 | + '365' => __('1 year', 'invoicing'), |
|
84 | + '730' => __('2 years', 'invoicing'), |
|
85 | + '1825' => __('5 years', 'invoicing'), |
|
86 | + '3650' => __('10 years', 'invoicing'), |
|
87 | 87 | ), |
88 | 88 | 'std' => '3650', |
89 | - 'tooltip' => __( 'Choose how long to keep processed customer data before final action. This helps balance data minimization with business needs.', 'invoicing' ), |
|
89 | + 'tooltip' => __('Choose how long to keep processed customer data before final action. This helps balance data minimization with business needs.', 'invoicing'), |
|
90 | 90 | ); |
91 | 91 | |
92 | 92 | return $misc_settings; |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @param int $user_id The ID of the user being deleted. |
99 | 99 | */ |
100 | - public function maybe_handle_user_deletion( $user_id ) { |
|
101 | - if ( ! $this->handle_user_deletion ) { |
|
100 | + public function maybe_handle_user_deletion($user_id) { |
|
101 | + if (!$this->handle_user_deletion) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | - if ( current_user_can( 'manage_options' ) ) { |
|
106 | - $this->handle_admin_user_deletion( $user_id ); |
|
105 | + if (current_user_can('manage_options')) { |
|
106 | + $this->handle_admin_user_deletion($user_id); |
|
107 | 107 | } else { |
108 | - $this->handle_self_account_deletion( $user_id ); |
|
108 | + $this->handle_self_account_deletion($user_id); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
@@ -115,19 +115,19 @@ discard block |
||
115 | 115 | * @since 2.8.22 |
116 | 116 | * @param int $user_id The ID of the user being deleted. |
117 | 117 | */ |
118 | - public function handle_admin_user_deletion( $user_id ) { |
|
119 | - if ( $this->has_active_subscriptions( $user_id ) ) { |
|
120 | - $this->prevent_user_deletion( $user_id, 'active_subscriptions' ); |
|
118 | + public function handle_admin_user_deletion($user_id) { |
|
119 | + if ($this->has_active_subscriptions($user_id)) { |
|
120 | + $this->prevent_user_deletion($user_id, 'active_subscriptions'); |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | - if ( $this->has_paid_invoices( $user_id ) ) { |
|
125 | - $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' ); |
|
126 | - if ( 'anonymize' === $retention_method ) { |
|
127 | - $this->anonymize_user_data( $user_id ); |
|
128 | - $this->prevent_user_deletion( $user_id, 'paid_invoices' ); |
|
124 | + if ($this->has_paid_invoices($user_id)) { |
|
125 | + $retention_method = wpinv_get_option('data_retention_method', 'anonymize'); |
|
126 | + if ('anonymize' === $retention_method) { |
|
127 | + $this->anonymize_user_data($user_id); |
|
128 | + $this->prevent_user_deletion($user_id, 'paid_invoices'); |
|
129 | 129 | } else { |
130 | - $this->delete_user_data( $user_id ); |
|
130 | + $this->delete_user_data($user_id); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | } |
@@ -138,19 +138,19 @@ discard block |
||
138 | 138 | * @since 2.8.22 |
139 | 139 | * @param int $user_id The ID of the user being deleted. |
140 | 140 | */ |
141 | - public function handle_self_account_deletion( $user_id ) { |
|
142 | - $this->cancel_active_subscriptions( $user_id ); |
|
141 | + public function handle_self_account_deletion($user_id) { |
|
142 | + $this->cancel_active_subscriptions($user_id); |
|
143 | 143 | |
144 | - if ( $this->has_paid_invoices( $user_id ) ) { |
|
145 | - $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' ); |
|
144 | + if ($this->has_paid_invoices($user_id)) { |
|
145 | + $retention_method = wpinv_get_option('data_retention_method', 'anonymize'); |
|
146 | 146 | |
147 | - if ( 'anonymize' === $retention_method ) { |
|
148 | - $user = get_userdata( $user_id ); |
|
147 | + if ('anonymize' === $retention_method) { |
|
148 | + $user = get_userdata($user_id); |
|
149 | 149 | |
150 | - $this->anonymize_user_data( $user_id ); |
|
150 | + $this->anonymize_user_data($user_id); |
|
151 | 151 | |
152 | - $message = apply_filters( 'uwp_get_account_deletion_message', '', $user ); |
|
153 | - do_action( 'uwp_send_account_deletion_emails', $user, $message ); |
|
152 | + $message = apply_filters('uwp_get_account_deletion_message', '', $user); |
|
153 | + do_action('uwp_send_account_deletion_emails', $user, $message); |
|
154 | 154 | |
155 | 155 | $this->end_user_session(); |
156 | 156 | } |
@@ -164,15 +164,15 @@ discard block |
||
164 | 164 | * @param int $user_id The ID of the user being checked. |
165 | 165 | * @return bool True if user has active subscriptions, false otherwise. |
166 | 166 | */ |
167 | - private function has_active_subscriptions( $user_id ) { |
|
167 | + private function has_active_subscriptions($user_id) { |
|
168 | 168 | $subscriptions = getpaid_get_subscriptions( |
169 | 169 | array( |
170 | - 'customer_in' => array( (int) $user_id ), |
|
170 | + 'customer_in' => array((int) $user_id), |
|
171 | 171 | 'status' => 'active', |
172 | 172 | ) |
173 | 173 | ); |
174 | 174 | |
175 | - return ! empty( $subscriptions ); |
|
175 | + return !empty($subscriptions); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,15 +181,15 @@ discard block |
||
181 | 181 | * @since 2.8.22 |
182 | 182 | * @param int $user_id The ID of the user. |
183 | 183 | */ |
184 | - private function cancel_active_subscriptions( $user_id ) { |
|
184 | + private function cancel_active_subscriptions($user_id) { |
|
185 | 185 | $subscriptions = getpaid_get_subscriptions( |
186 | 186 | array( |
187 | - 'customer_in' => array( (int) $user_id ), |
|
187 | + 'customer_in' => array((int) $user_id), |
|
188 | 188 | 'status' => 'active', |
189 | 189 | ) |
190 | 190 | ); |
191 | 191 | |
192 | - foreach ( $subscriptions as $subscription ) { |
|
192 | + foreach ($subscriptions as $subscription) { |
|
193 | 193 | $subscription->cancel(); |
194 | 194 | } |
195 | 195 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @param int $user_id The ID of the user being checked. |
202 | 202 | * @return bool True if user has paid invoices, false otherwise. |
203 | 203 | */ |
204 | - private function has_paid_invoices( $user_id ) { |
|
204 | + private function has_paid_invoices($user_id) { |
|
205 | 205 | $invoices = wpinv_get_invoices( |
206 | 206 | array( |
207 | 207 | 'user' => (int) $user_id, |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | ) |
210 | 210 | ); |
211 | 211 | |
212 | - return ! empty( $invoices->total ); |
|
212 | + return !empty($invoices->total); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -219,24 +219,24 @@ discard block |
||
219 | 219 | * @param int $user_id The ID of the user being deleted. |
220 | 220 | * @param string $reason The reason for preventing deletion. |
221 | 221 | */ |
222 | - private function prevent_user_deletion( $user_id, $reason ) { |
|
223 | - $user = get_userdata( $user_id ); |
|
222 | + private function prevent_user_deletion($user_id, $reason) { |
|
223 | + $user = get_userdata($user_id); |
|
224 | 224 | |
225 | - if ( 'active_subscriptions' === $reason ) { |
|
225 | + if ('active_subscriptions' === $reason) { |
|
226 | 226 | $this->error_message = sprintf( |
227 | 227 | /* translators: %s: user login */ |
228 | - esc_html__( 'User deletion for %s has been halted. All active subscriptions should be cancelled first.', 'invoicing' ), |
|
228 | + esc_html__('User deletion for %s has been halted. All active subscriptions should be cancelled first.', 'invoicing'), |
|
229 | 229 | $user->user_login |
230 | 230 | ); |
231 | 231 | } else { |
232 | 232 | $this->error_message = sprintf( |
233 | 233 | /* translators: %s: user login */ |
234 | - esc_html__( 'User deletion for %s has been halted due to paid invoices. Data will be anonymized instead.', 'invoicing' ), |
|
234 | + esc_html__('User deletion for %s has been halted due to paid invoices. Data will be anonymized instead.', 'invoicing'), |
|
235 | 235 | $user->user_login |
236 | 236 | ); |
237 | 237 | } |
238 | 238 | |
239 | - wp_die( $this->error_message, esc_html__( 'User Deletion Halted', 'invoicing' ), array( 'response' => 403 ) ); |
|
239 | + wp_die($this->error_message, esc_html__('User Deletion Halted', 'invoicing'), array('response' => 403)); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -246,17 +246,17 @@ discard block |
||
246 | 246 | * @param int $user_id The ID of the user to anonymize. |
247 | 247 | * @return bool True on success, false on failure. |
248 | 248 | */ |
249 | - private function anonymize_user_data( $user_id ) { |
|
249 | + private function anonymize_user_data($user_id) { |
|
250 | 250 | global $wpdb; |
251 | 251 | |
252 | - $user = get_userdata( $user_id ); |
|
253 | - if ( ! $user ) { |
|
252 | + $user = get_userdata($user_id); |
|
253 | + if (!$user) { |
|
254 | 254 | return false; |
255 | 255 | } |
256 | 256 | |
257 | 257 | $table_name = $wpdb->prefix . 'getpaid_customers'; |
258 | - $deletion_date = gmdate( 'Y-m-d', strtotime( '+10 years' ) ); |
|
259 | - $hashed_email = $this->hash_email( $user->user_email ); |
|
258 | + $deletion_date = gmdate('Y-m-d', strtotime('+10 years')); |
|
259 | + $hashed_email = $this->hash_email($user->user_email); |
|
260 | 260 | |
261 | 261 | $updated = $wpdb->update( |
262 | 262 | $table_name, |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | 'email_cc' => $hashed_email, |
268 | 268 | 'phone' => '', |
269 | 269 | ), |
270 | - array( 'user_id' => (int) $user->ID ) |
|
270 | + array('user_id' => (int) $user->ID) |
|
271 | 271 | ); |
272 | 272 | |
273 | - if ( false === $updated ) { |
|
273 | + if (false === $updated) { |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @since 2.8.22 |
288 | 288 | * @param int $user_id The ID of the user being anonymized. |
289 | 289 | */ |
290 | - do_action( 'wpinv_anonymize_user_meta_data', $user->ID ); |
|
290 | + do_action('wpinv_anonymize_user_meta_data', $user->ID); |
|
291 | 291 | |
292 | 292 | $user_meta_data = array( |
293 | 293 | 'nickname', |
@@ -312,13 +312,13 @@ discard block |
||
312 | 312 | * @param array $user_meta_data The meta fields to be anonymized. |
313 | 313 | * @param int $user_id The ID of the user being anonymized. |
314 | 314 | */ |
315 | - $user_meta_data = apply_filters( 'wpinv_user_meta_data_to_anonymize', $user_meta_data, $user->ID ); |
|
315 | + $user_meta_data = apply_filters('wpinv_user_meta_data_to_anonymize', $user_meta_data, $user->ID); |
|
316 | 316 | |
317 | - foreach ( $user_meta_data as $meta_key ) { |
|
318 | - delete_user_meta( $user->ID, $meta_key ); |
|
317 | + foreach ($user_meta_data as $meta_key) { |
|
318 | + delete_user_meta($user->ID, $meta_key); |
|
319 | 319 | } |
320 | 320 | |
321 | - return $this->ensure_invoice_anonymization( $user->ID, 'anonymize' ); |
|
321 | + return $this->ensure_invoice_anonymization($user->ID, 'anonymize'); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -327,15 +327,15 @@ discard block |
||
327 | 327 | * @param int $user_id The ID of the user to delete. |
328 | 328 | * @return bool True on success, false on failure. |
329 | 329 | */ |
330 | - private function delete_user_data( $user_id ) { |
|
330 | + private function delete_user_data($user_id) { |
|
331 | 331 | // Delete associated invoices. |
332 | - $this->ensure_invoice_anonymization( $user_id, 'delete' ); |
|
332 | + $this->ensure_invoice_anonymization($user_id, 'delete'); |
|
333 | 333 | |
334 | 334 | // Delete the user. |
335 | - if ( is_multisite() ) { |
|
336 | - wpmu_delete_user( $user_id ); |
|
335 | + if (is_multisite()) { |
|
336 | + wpmu_delete_user($user_id); |
|
337 | 337 | } else { |
338 | - wp_delete_user( $user_id ); |
|
338 | + wp_delete_user($user_id); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * @since 2.8.22 |
345 | 345 | * @param int $user_id The ID of the user being deleted. |
346 | 346 | */ |
347 | - do_action( 'wpinv_delete_user_data', $user_id ); |
|
347 | + do_action('wpinv_delete_user_data', $user_id); |
|
348 | 348 | |
349 | 349 | return true; |
350 | 350 | } |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | * @param string $action The action to perform (anonymize or delete). |
358 | 358 | * @return bool True on success, false on failure. |
359 | 359 | */ |
360 | - public function ensure_invoice_anonymization( $user_id, $action = 'anonymize' ) { |
|
361 | - $invoices = wpinv_get_invoices( array( 'user' => $user_id ) ); |
|
360 | + public function ensure_invoice_anonymization($user_id, $action = 'anonymize') { |
|
361 | + $invoices = wpinv_get_invoices(array('user' => $user_id)); |
|
362 | 362 | |
363 | 363 | /** |
364 | 364 | * Filters the invoice meta fields to be anonymized. |
@@ -367,22 +367,22 @@ discard block |
||
367 | 367 | * @param array $inv_meta_data The meta fields to be anonymized. |
368 | 368 | * @param int $user_id The ID of the user being processed. |
369 | 369 | */ |
370 | - $inv_meta_data = apply_filters( 'wpinv_invoice_meta_data_to_anonymize', array(), $user_id ); |
|
370 | + $inv_meta_data = apply_filters('wpinv_invoice_meta_data_to_anonymize', array(), $user_id); |
|
371 | 371 | |
372 | - foreach ( $invoices->invoices as $invoice ) { |
|
373 | - foreach ( $inv_meta_data as $meta_key ) { |
|
374 | - delete_post_meta( $invoice->get_id(), $meta_key ); |
|
372 | + foreach ($invoices->invoices as $invoice) { |
|
373 | + foreach ($inv_meta_data as $meta_key) { |
|
374 | + delete_post_meta($invoice->get_id(), $meta_key); |
|
375 | 375 | } |
376 | 376 | |
377 | - if ( 'anonymize' === $action ) { |
|
378 | - $hashed_inv_email = $this->hash_email( $invoice->get_email() ); |
|
379 | - $hashed_inv_email_cc = $this->hash_email( $invoice->get_email_cc() ); |
|
377 | + if ('anonymize' === $action) { |
|
378 | + $hashed_inv_email = $this->hash_email($invoice->get_email()); |
|
379 | + $hashed_inv_email_cc = $this->hash_email($invoice->get_email_cc()); |
|
380 | 380 | |
381 | - $invoice->set_email( $hashed_inv_email ); |
|
382 | - $invoice->set_email_cc( $hashed_inv_email_cc ); |
|
383 | - $invoice->set_phone( '' ); |
|
384 | - $invoice->set_ip( $this->anonymize_data( $invoice->get_ip() ) ); |
|
385 | - $invoice->set_is_anonymized( 1 ); |
|
381 | + $invoice->set_email($hashed_inv_email); |
|
382 | + $invoice->set_email_cc($hashed_inv_email_cc); |
|
383 | + $invoice->set_phone(''); |
|
384 | + $invoice->set_ip($this->anonymize_data($invoice->get_ip())); |
|
385 | + $invoice->set_is_anonymized(1); |
|
386 | 386 | |
387 | 387 | /** |
388 | 388 | * Fires when anonymizing additional invoice data. |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | * @param WPInv_Invoice $invoice The invoice being anonymized. |
392 | 392 | * @param string $action The action being performed (anonymize or delete). |
393 | 393 | */ |
394 | - do_action( 'wpinv_anonymize_invoice_data', $invoice, $action ); |
|
394 | + do_action('wpinv_anonymize_invoice_data', $invoice, $action); |
|
395 | 395 | |
396 | 396 | $invoice->save(); |
397 | 397 | } else { |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
402 | - return $this->log_deletion_action( $user_id, $invoices->invoices, $action ); |
|
402 | + return $this->log_deletion_action($user_id, $invoices->invoices, $action); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -411,11 +411,11 @@ discard block |
||
411 | 411 | * @param string $action The action being performed (anonymize or delete). |
412 | 412 | * @return bool True on success, false on failure. |
413 | 413 | */ |
414 | - private function log_deletion_action( $user_id, $invoices, $action ) { |
|
414 | + private function log_deletion_action($user_id, $invoices, $action) { |
|
415 | 415 | global $wpdb; |
416 | 416 | |
417 | 417 | $table_name = $wpdb->prefix . 'getpaid_anonymization_logs'; |
418 | - $user_data = get_userdata( $user_id ); |
|
418 | + $user_data = get_userdata($user_id); |
|
419 | 419 | |
420 | 420 | $additional_info = array( |
421 | 421 | 'Username' => $user_data ? $user_data->user_login : 'N/A', |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | 'First Name' => $user_data ? $user_data->first_name : 'N/A', |
425 | 425 | 'Last Name' => $user_data ? $user_data->last_name : 'N/A', |
426 | 426 | 'Registered' => $user_data ? $user_data->user_registered : 'N/A', |
427 | - 'invoice_count' => count( $invoices ), |
|
427 | + 'invoice_count' => count($invoices), |
|
428 | 428 | ); |
429 | 429 | |
430 | 430 | |
@@ -437,43 +437,43 @@ discard block |
||
437 | 437 | * @param array $invoices The invoices being processed. |
438 | 438 | * @param string $action The action being performed (anonymize or delete). |
439 | 439 | */ |
440 | - $additional_info = apply_filters( 'wpinv_anonymization_log_additional_info', $additional_info, $user_id, $invoices, $action ); |
|
440 | + $additional_info = apply_filters('wpinv_anonymization_log_additional_info', $additional_info, $user_id, $invoices, $action); |
|
441 | 441 | |
442 | 442 | $data = array( |
443 | 443 | 'user_id' => $user_id, |
444 | - 'action' => sanitize_text_field( $action ), |
|
444 | + 'action' => sanitize_text_field($action), |
|
445 | 445 | 'data_type' => 'User Invoices', |
446 | - 'timestamp' => current_time( 'mysql' ), |
|
447 | - 'additional_info' => wp_json_encode( $additional_info ), |
|
446 | + 'timestamp' => current_time('mysql'), |
|
447 | + 'additional_info' => wp_json_encode($additional_info), |
|
448 | 448 | ); |
449 | 449 | |
450 | 450 | $format = array( |
451 | - '%d', // user_id |
|
452 | - '%s', // action |
|
453 | - '%s', // data_type |
|
454 | - '%s', // timestamp |
|
455 | - '%s', // additional_info |
|
451 | + '%d', // user_id |
|
452 | + '%s', // action |
|
453 | + '%s', // data_type |
|
454 | + '%s', // timestamp |
|
455 | + '%s', // additional_info |
|
456 | 456 | ); |
457 | 457 | |
458 | - if ( ! empty( $user_id ) && ! empty( $action ) ) { |
|
458 | + if (!empty($user_id) && !empty($action)) { |
|
459 | 459 | $result = $wpdb->update( |
460 | 460 | $table_name, |
461 | 461 | $data, |
462 | 462 | array( |
463 | 463 | 'user_id' => (int) $user_id, |
464 | - 'action' => sanitize_text_field( $action ), |
|
464 | + 'action' => sanitize_text_field($action), |
|
465 | 465 | ), |
466 | 466 | $format, |
467 | - array( '%d', '%s' ) |
|
467 | + array('%d', '%s') |
|
468 | 468 | ); |
469 | 469 | |
470 | - if ( false === $result ) { |
|
470 | + if (false === $result) { |
|
471 | 471 | // If update fails, try to insert. |
472 | - $result = $wpdb->insert( $table_name, $data, $format ); |
|
472 | + $result = $wpdb->insert($table_name, $data, $format); |
|
473 | 473 | } |
474 | 474 | |
475 | - if ( false === $result ) { |
|
476 | - wpinv_error_log( sprintf( 'Failed to log anonymization action for user ID: %d. Error: %s', $user_id, $wpdb->last_error ) ); |
|
475 | + if (false === $result) { |
|
476 | + wpinv_error_log(sprintf('Failed to log anonymization action for user ID: %d. Error: %s', $user_id, $wpdb->last_error)); |
|
477 | 477 | return false; |
478 | 478 | } |
479 | 479 | } |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @param string $action The action being performed (anonymize or delete). |
488 | 488 | * @param array $data The data that was inserted into the log. |
489 | 489 | */ |
490 | - do_action( 'wpinv_after_log_deletion_action', $user_id, $invoices, $action, $data ); |
|
490 | + do_action('wpinv_after_log_deletion_action', $user_id, $invoices, $action, $data); |
|
491 | 491 | |
492 | 492 | return true; |
493 | 493 | } |
@@ -500,20 +500,20 @@ discard block |
||
500 | 500 | * @param int $user_id The ID of the user being erased. |
501 | 501 | * @return array The modified response. |
502 | 502 | */ |
503 | - public function handle_erasure_request( $response, $user_id ) { |
|
504 | - if ( $this->has_active_subscriptions( $user_id ) ) { |
|
505 | - $response['messages'][] = esc_html__( 'User has active subscriptions. Data cannot be erased at this time.', 'invoicing' ); |
|
503 | + public function handle_erasure_request($response, $user_id) { |
|
504 | + if ($this->has_active_subscriptions($user_id)) { |
|
505 | + $response['messages'][] = esc_html__('User has active subscriptions. Data cannot be erased at this time.', 'invoicing'); |
|
506 | 506 | $response['items_removed'] = false; |
507 | - } elseif ( $this->has_paid_invoices( $user_id ) ) { |
|
508 | - $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' ); |
|
509 | - if ( 'anonymize' === $retention_method ) { |
|
510 | - $this->anonymize_user_data( $user_id ); |
|
511 | - $response['messages'][] = esc_html__( 'User data has been anonymized due to existing paid invoices.', 'invoicing' ); |
|
507 | + } elseif ($this->has_paid_invoices($user_id)) { |
|
508 | + $retention_method = wpinv_get_option('data_retention_method', 'anonymize'); |
|
509 | + if ('anonymize' === $retention_method) { |
|
510 | + $this->anonymize_user_data($user_id); |
|
511 | + $response['messages'][] = esc_html__('User data has been anonymized due to existing paid invoices.', 'invoicing'); |
|
512 | 512 | $response['items_removed'] = false; |
513 | 513 | $response['items_retained'] = true; |
514 | 514 | } else { |
515 | - $this->delete_user_data( $user_id ); |
|
516 | - $response['messages'][] = esc_html__( 'User data has been deleted.', 'invoicing' ); |
|
515 | + $this->delete_user_data($user_id); |
|
516 | + $response['messages'][] = esc_html__('User data has been deleted.', 'invoicing'); |
|
517 | 517 | $response['items_removed'] = true; |
518 | 518 | $response['items_retained'] = false; |
519 | 519 | } |
@@ -529,18 +529,18 @@ discard block |
||
529 | 529 | * @param string $email The email to hash. |
530 | 530 | * @return string The hashed email. |
531 | 531 | */ |
532 | - private function hash_email( $email ) { |
|
532 | + private function hash_email($email) { |
|
533 | 533 | $site_url = get_site_url(); |
534 | - $domain = wp_parse_url( $site_url, PHP_URL_HOST ); |
|
534 | + $domain = wp_parse_url($site_url, PHP_URL_HOST); |
|
535 | 535 | |
536 | - if ( empty( $domain ) ) { |
|
536 | + if (empty($domain)) { |
|
537 | 537 | return $email; |
538 | 538 | } |
539 | 539 | |
540 | - $clean_email = sanitize_email( strtolower( trim( $email ) ) ); |
|
541 | - $hash = wp_hash( $clean_email ); |
|
542 | - $hash = substr( $hash, 0, 20 ); |
|
543 | - $anonymized_email = sprintf( '%s@%s', $hash, $domain ); |
|
540 | + $clean_email = sanitize_email(strtolower(trim($email))); |
|
541 | + $hash = wp_hash($clean_email); |
|
542 | + $hash = substr($hash, 0, 20); |
|
543 | + $anonymized_email = sprintf('%s@%s', $hash, $domain); |
|
544 | 544 | |
545 | 545 | /** |
546 | 546 | * Filters the anonymized email before returning. |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * @param string $anonymized_email The anonymized email address. |
550 | 550 | * @param string $email The original email address. |
551 | 551 | */ |
552 | - return apply_filters( 'wpinv_anonymized_email', $anonymized_email, $email ); |
|
552 | + return apply_filters('wpinv_anonymized_email', $anonymized_email, $email); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -559,12 +559,12 @@ discard block |
||
559 | 559 | * @param string $data The data to anonymize. |
560 | 560 | * @return string The anonymized data. |
561 | 561 | */ |
562 | - private function anonymize_data( $data ) { |
|
563 | - if ( empty( $data ) ) { |
|
562 | + private function anonymize_data($data) { |
|
563 | + if (empty($data)) { |
|
564 | 564 | return ''; |
565 | 565 | } |
566 | 566 | |
567 | - return wp_privacy_anonymize_data( 'text', $data ); |
|
567 | + return wp_privacy_anonymize_data('text', $data); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
@@ -578,17 +578,17 @@ discard block |
||
578 | 578 | public function perform_data_retention_cleanup() { |
579 | 579 | global $wpdb; |
580 | 580 | |
581 | - $retention_period = wpinv_get_option( 'data_retention_period', '3650' ); |
|
581 | + $retention_period = wpinv_get_option('data_retention_period', '3650'); |
|
582 | 582 | |
583 | 583 | // If retention period is set to 'never', exit the function. |
584 | - if ( 'never' === $retention_period ) { |
|
584 | + if ('never' === $retention_period) { |
|
585 | 585 | return; |
586 | 586 | } |
587 | 587 | |
588 | 588 | $customers_table = $wpdb->prefix . 'getpaid_customers'; |
589 | 589 | |
590 | 590 | // Calculate the cutoff date for data retention. |
591 | - $cutoff_date = gmdate( 'Y-m-d', strtotime( "-$retention_period days" ) ); |
|
591 | + $cutoff_date = gmdate('Y-m-d', strtotime("-$retention_period days")); |
|
592 | 592 | |
593 | 593 | $expired_records = $wpdb->get_results( |
594 | 594 | $wpdb->prepare( |
@@ -603,18 +603,18 @@ discard block |
||
603 | 603 | * @since 2.8.22 |
604 | 604 | * @param array $expired_records Array of customer records to be processed. |
605 | 605 | */ |
606 | - do_action( 'getpaid_data_retention_before_cleanup', $expired_records ); |
|
606 | + do_action('getpaid_data_retention_before_cleanup', $expired_records); |
|
607 | 607 | |
608 | - if ( ! empty( $expired_records ) ) { |
|
608 | + if (!empty($expired_records)) { |
|
609 | 609 | // Disable our custom user deletion handling. |
610 | 610 | $this->handle_user_deletion = false; |
611 | 611 | |
612 | - foreach ( $expired_records as $record ) { |
|
612 | + foreach ($expired_records as $record) { |
|
613 | 613 | // Delete associated invoices. |
614 | - $this->ensure_invoice_anonymization( (int) $record->user_id, 'delete' ); |
|
614 | + $this->ensure_invoice_anonymization((int) $record->user_id, 'delete'); |
|
615 | 615 | |
616 | 616 | // Delete the user. |
617 | - wp_delete_user( (int) $record->user_id ); |
|
617 | + wp_delete_user((int) $record->user_id); |
|
618 | 618 | |
619 | 619 | /** |
620 | 620 | * Fires after processing each expired record during cleanup. |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | * @since 2.8.22 |
623 | 623 | * @param object $record The customer record being processed. |
624 | 624 | */ |
625 | - do_action( 'getpaid_data_retention_process_record', $record ); |
|
625 | + do_action('getpaid_data_retention_process_record', $record); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | // Re-enable our custom user deletion handling. |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | * @since 2.8.22 |
635 | 635 | * @param array $expired_records Array of customer records that were processed. |
636 | 636 | */ |
637 | - do_action( 'getpaid_data_retention_after_cleanup', $expired_records ); |
|
637 | + do_action('getpaid_data_retention_after_cleanup', $expired_records); |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | /** |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | * @param int $retention_period The current retention period in years. |
645 | 645 | * @param string $cutoff_date The cutoff date used for identifying expired records. |
646 | 646 | */ |
647 | - do_action( 'getpaid_data_retention_cleanup_complete', $retention_period, $cutoff_date ); |
|
647 | + do_action('getpaid_data_retention_cleanup_complete', $retention_period, $cutoff_date); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | /** |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | |
658 | 658 | // Redirect after deletion. |
659 | 659 | $redirect_page = home_url(); |
660 | - wp_safe_redirect( $redirect_page ); |
|
660 | + wp_safe_redirect($redirect_page); |
|
661 | 661 | exit(); |
662 | 662 | } |
663 | 663 | } |
664 | 664 | \ No newline at end of file |
@@ -12,218 +12,218 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Reports_Report |
|
17 | - */ |
|
18 | - public $handler; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
25 | - $this->handler = new GetPaid_Reports_Report(); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Prepares the datastore handler. |
|
30 | - * |
|
31 | - * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | - */ |
|
33 | - public function prepare_handler( $graph ) { |
|
34 | - |
|
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | - } |
|
38 | - |
|
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
40 | - |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Prepares the output stream. |
|
45 | - * |
|
46 | - * @return resource |
|
47 | - */ |
|
48 | - public function prepare_output() { |
|
49 | - |
|
50 | - $output = fopen( 'php://output', 'w' ); |
|
51 | - |
|
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | - } |
|
55 | - |
|
56 | - return $output; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Prepares the file type. |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function prepare_file_type( $graph ) { |
|
65 | - |
|
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | - |
|
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | - |
|
72 | - return $file_type; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Handles the actual download. |
|
77 | - * |
|
78 | - */ |
|
79 | - public function download( $graph ) { |
|
80 | - global $wpdb; |
|
81 | - |
|
82 | - $handler = $this->prepare_handler( $graph ); |
|
83 | - $stream = $this->prepare_output(); |
|
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
92 | - } else { |
|
93 | - $this->download_json( $stats, $stream, $headers ); |
|
94 | - } |
|
95 | - |
|
96 | - fclose( $stream ); |
|
97 | - exit; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Downloads graph as csv |
|
102 | - * |
|
103 | - * @param array $stats The stats being downloaded. |
|
104 | - * @param resource $stream The stream to output to. |
|
105 | - * @param array $headers The fields to stream. |
|
106 | - * @since 1.0.19 |
|
107 | - */ |
|
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
109 | - |
|
110 | - // Output the csv column headers. |
|
111 | - fputcsv( $stream, $headers ); |
|
112 | - |
|
113 | - // Loop through |
|
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
118 | - } |
|
119 | - |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Downloads graph as json |
|
124 | - * |
|
125 | - * @param array $stats The stats being downloaded. |
|
126 | - * @param resource $stream The stream to output to. |
|
127 | - * @param array $headers The fields to stream. |
|
128 | - * @since 1.0.19 |
|
129 | - */ |
|
130 | - public function download_json( $stats, $stream, $headers ) { |
|
131 | - |
|
132 | - $prepared = array(); |
|
133 | - |
|
134 | - // Loop through |
|
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | - } |
|
138 | - |
|
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Downloads graph as xml |
|
145 | - * |
|
146 | - * @param array $stats The stats being downloaded. |
|
147 | - * @param resource $stream The stream to output to. |
|
148 | - * @param array $headers The fields to stream. |
|
149 | - * @since 1.0.19 |
|
150 | - */ |
|
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
152 | - |
|
153 | - $prepared = array(); |
|
154 | - |
|
155 | - // Loop through |
|
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | - } |
|
159 | - |
|
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
162 | - |
|
163 | - fwrite( $stream, $xml->asXML() ); |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Converts stats array to xml |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @since 1.0.19 |
|
172 | - */ |
|
173 | - public function convert_array_xml( $data, $xml ) { |
|
174 | - |
|
175 | - // Loop through |
|
176 | - foreach ( $data as $key => $value ) { |
|
177 | - |
|
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | - |
|
180 | - if ( is_array( $value ) ) { |
|
181 | - |
|
182 | - if ( is_numeric( $key ) ) { |
|
183 | - $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | - } |
|
185 | - |
|
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
188 | - |
|
189 | - } else { |
|
190 | - $xml->addChild( $key, $value ? htmlspecialchars( $value ) : $value ); |
|
191 | - } |
|
15 | + /** |
|
16 | + * @var GetPaid_Reports_Report |
|
17 | + */ |
|
18 | + public $handler; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | + $this->handler = new GetPaid_Reports_Report(); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Prepares the datastore handler. |
|
30 | + * |
|
31 | + * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | + */ |
|
33 | + public function prepare_handler( $graph ) { |
|
34 | + |
|
35 | + if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | + wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | + } |
|
38 | + |
|
39 | + return new $this->handler->views[ $graph ]['class'](); |
|
40 | + |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Prepares the output stream. |
|
45 | + * |
|
46 | + * @return resource |
|
47 | + */ |
|
48 | + public function prepare_output() { |
|
49 | + |
|
50 | + $output = fopen( 'php://output', 'w' ); |
|
51 | + |
|
52 | + if ( false === $output ) { |
|
53 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | + } |
|
55 | + |
|
56 | + return $output; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Prepares the file type. |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function prepare_file_type( $graph ) { |
|
65 | + |
|
66 | + $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | + $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | + |
|
69 | + header( "Content-Type:application/$file_type" ); |
|
70 | + header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | + |
|
72 | + return $file_type; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Handles the actual download. |
|
77 | + * |
|
78 | + */ |
|
79 | + public function download( $graph ) { |
|
80 | + global $wpdb; |
|
81 | + |
|
82 | + $handler = $this->prepare_handler( $graph ); |
|
83 | + $stream = $this->prepare_output(); |
|
84 | + $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | + $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | + $file_type = $this->prepare_file_type( $graph ); |
|
87 | + |
|
88 | + if ( 'csv' == $file_type ) { |
|
89 | + $this->download_csv( $stats, $stream, $headers ); |
|
90 | + } elseif ( 'xml' == $file_type ) { |
|
91 | + $this->download_xml( $stats, $stream, $headers ); |
|
92 | + } else { |
|
93 | + $this->download_json( $stats, $stream, $headers ); |
|
94 | + } |
|
95 | + |
|
96 | + fclose( $stream ); |
|
97 | + exit; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Downloads graph as csv |
|
102 | + * |
|
103 | + * @param array $stats The stats being downloaded. |
|
104 | + * @param resource $stream The stream to output to. |
|
105 | + * @param array $headers The fields to stream. |
|
106 | + * @since 1.0.19 |
|
107 | + */ |
|
108 | + public function download_csv( $stats, $stream, $headers ) { |
|
109 | + |
|
110 | + // Output the csv column headers. |
|
111 | + fputcsv( $stream, $headers ); |
|
112 | + |
|
113 | + // Loop through |
|
114 | + foreach ( $stats as $stat ) { |
|
115 | + $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | + $row = array_map( 'maybe_serialize', $row ); |
|
117 | + fputcsv( $stream, $row ); |
|
118 | + } |
|
119 | + |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Downloads graph as json |
|
124 | + * |
|
125 | + * @param array $stats The stats being downloaded. |
|
126 | + * @param resource $stream The stream to output to. |
|
127 | + * @param array $headers The fields to stream. |
|
128 | + * @since 1.0.19 |
|
129 | + */ |
|
130 | + public function download_json( $stats, $stream, $headers ) { |
|
131 | + |
|
132 | + $prepared = array(); |
|
133 | + |
|
134 | + // Loop through |
|
135 | + foreach ( $stats as $stat ) { |
|
136 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | + } |
|
138 | + |
|
139 | + fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Downloads graph as xml |
|
145 | + * |
|
146 | + * @param array $stats The stats being downloaded. |
|
147 | + * @param resource $stream The stream to output to. |
|
148 | + * @param array $headers The fields to stream. |
|
149 | + * @since 1.0.19 |
|
150 | + */ |
|
151 | + public function download_xml( $stats, $stream, $headers ) { |
|
152 | + |
|
153 | + $prepared = array(); |
|
154 | + |
|
155 | + // Loop through |
|
156 | + foreach ( $stats as $stat ) { |
|
157 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | + } |
|
159 | + |
|
160 | + $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | + $this->convert_array_xml( $prepared, $xml ); |
|
162 | + |
|
163 | + fwrite( $stream, $xml->asXML() ); |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Converts stats array to xml |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @since 1.0.19 |
|
172 | + */ |
|
173 | + public function convert_array_xml( $data, $xml ) { |
|
174 | + |
|
175 | + // Loop through |
|
176 | + foreach ( $data as $key => $value ) { |
|
177 | + |
|
178 | + $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | + |
|
180 | + if ( is_array( $value ) ) { |
|
181 | + |
|
182 | + if ( is_numeric( $key ) ) { |
|
183 | + $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | + } |
|
185 | + |
|
186 | + $subnode = $xml->addChild( $key ); |
|
187 | + $this->convert_array_xml( $value, $subnode ); |
|
188 | + |
|
189 | + } else { |
|
190 | + $xml->addChild( $key, $value ? htmlspecialchars( $value ) : $value ); |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Prepares a single row for download. |
|
198 | - * |
|
199 | - * @param stdClass|array $row The row to prepare.. |
|
200 | - * @param array $fields The fields to stream. |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function prepare_row( $row, $fields ) { |
|
196 | + /** |
|
197 | + * Prepares a single row for download. |
|
198 | + * |
|
199 | + * @param stdClass|array $row The row to prepare.. |
|
200 | + * @param array $fields The fields to stream. |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function prepare_row( $row, $fields ) { |
|
205 | 205 | |
206 | - $prepared = array(); |
|
207 | - $row = (array) $row; |
|
206 | + $prepared = array(); |
|
207 | + $row = (array) $row; |
|
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ( $fields as $field ) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | - continue; |
|
214 | - } |
|
211 | + if ( $field === 'total' ) { |
|
212 | + $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | + continue; |
|
214 | + } |
|
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | - continue; |
|
219 | - } |
|
216 | + if ( $field === 'total_raw' ) { |
|
217 | + $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | + continue; |
|
219 | + } |
|
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
222 | 222 | |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - return $prepared; |
|
226 | - } |
|
225 | + return $prepared; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | |
229 | 229 | } |
@@ -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_Graph_Downloader Class. |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
32 | 32 | */ |
33 | - public function prepare_handler( $graph ) { |
|
33 | + public function prepare_handler($graph) { |
|
34 | 34 | |
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
35 | + if (empty($this->handler->views[$graph])) { |
|
36 | + wp_die(esc_html__('Invalid Graph', 'invoicing'), 400); |
|
37 | 37 | } |
38 | 38 | |
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
39 | + return new $this->handler->views[$graph]['class'](); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function prepare_output() { |
49 | 49 | |
50 | - $output = fopen( 'php://output', 'w' ); |
|
50 | + $output = fopen('php://output', 'w'); |
|
51 | 51 | |
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
52 | + if (false === $output) { |
|
53 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $output; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public function prepare_file_type( $graph ) { |
|
64 | + public function prepare_file_type($graph) { |
|
65 | 65 | |
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
66 | + $file_type = empty($_REQUEST['file_type']) ? 'csv' : sanitize_text_field($_REQUEST['file_type']); |
|
67 | + $file_name = wpinv_sanitize_key("getpaid-$graph-" . current_time('Y-m-d')); |
|
68 | 68 | |
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
69 | + header("Content-Type:application/$file_type"); |
|
70 | + header("Content-Disposition:attachment;filename=$file_name.$file_type"); |
|
71 | 71 | |
72 | 72 | return $file_type; |
73 | 73 | } |
@@ -76,24 +76,24 @@ discard block |
||
76 | 76 | * Handles the actual download. |
77 | 77 | * |
78 | 78 | */ |
79 | - public function download( $graph ) { |
|
79 | + public function download($graph) { |
|
80 | 80 | global $wpdb; |
81 | 81 | |
82 | - $handler = $this->prepare_handler( $graph ); |
|
82 | + $handler = $this->prepare_handler($graph); |
|
83 | 83 | $stream = $this->prepare_output(); |
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
84 | + $stats = $wpdb->get_results($handler->get_sql($handler->get_range())); |
|
85 | + $headers = array($handler->field, 'total', 'total_raw'); |
|
86 | + $file_type = $this->prepare_file_type($graph); |
|
87 | + |
|
88 | + if ('csv' == $file_type) { |
|
89 | + $this->download_csv($stats, $stream, $headers); |
|
90 | + } elseif ('xml' == $file_type) { |
|
91 | + $this->download_xml($stats, $stream, $headers); |
|
92 | 92 | } else { |
93 | - $this->download_json( $stats, $stream, $headers ); |
|
93 | + $this->download_json($stats, $stream, $headers); |
|
94 | 94 | } |
95 | 95 | |
96 | - fclose( $stream ); |
|
96 | + fclose($stream); |
|
97 | 97 | exit; |
98 | 98 | } |
99 | 99 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | * @param array $headers The fields to stream. |
106 | 106 | * @since 1.0.19 |
107 | 107 | */ |
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
108 | + public function download_csv($stats, $stream, $headers) { |
|
109 | 109 | |
110 | 110 | // Output the csv column headers. |
111 | - fputcsv( $stream, $headers ); |
|
111 | + fputcsv($stream, $headers); |
|
112 | 112 | |
113 | 113 | // Loop through |
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
114 | + foreach ($stats as $stat) { |
|
115 | + $row = array_values($this->prepare_row($stat, $headers)); |
|
116 | + $row = array_map('maybe_serialize', $row); |
|
117 | + fputcsv($stream, $row); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | } |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | * @param array $headers The fields to stream. |
128 | 128 | * @since 1.0.19 |
129 | 129 | */ |
130 | - public function download_json( $stats, $stream, $headers ) { |
|
130 | + public function download_json($stats, $stream, $headers) { |
|
131 | 131 | |
132 | 132 | $prepared = array(); |
133 | 133 | |
134 | 134 | // Loop through |
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
135 | + foreach ($stats as $stat) { |
|
136 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
137 | 137 | } |
138 | 138 | |
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
139 | + fwrite($stream, wp_json_encode($prepared)); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -148,19 +148,19 @@ discard block |
||
148 | 148 | * @param array $headers The fields to stream. |
149 | 149 | * @since 1.0.19 |
150 | 150 | */ |
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
151 | + public function download_xml($stats, $stream, $headers) { |
|
152 | 152 | |
153 | 153 | $prepared = array(); |
154 | 154 | |
155 | 155 | // Loop through |
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
156 | + foreach ($stats as $stat) { |
|
157 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
158 | 158 | } |
159 | 159 | |
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
160 | + $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
161 | + $this->convert_array_xml($prepared, $xml); |
|
162 | 162 | |
163 | - fwrite( $stream, $xml->asXML() ); |
|
163 | + fwrite($stream, $xml->asXML()); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -170,24 +170,24 @@ discard block |
||
170 | 170 | * @access public |
171 | 171 | * @since 1.0.19 |
172 | 172 | */ |
173 | - public function convert_array_xml( $data, $xml ) { |
|
173 | + public function convert_array_xml($data, $xml) { |
|
174 | 174 | |
175 | 175 | // Loop through |
176 | - foreach ( $data as $key => $value ) { |
|
176 | + foreach ($data as $key => $value) { |
|
177 | 177 | |
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
178 | + $key = preg_replace('/[^A-Za-z0-9_\-]/', '', $key); |
|
179 | 179 | |
180 | - if ( is_array( $value ) ) { |
|
180 | + if (is_array($value)) { |
|
181 | 181 | |
182 | - if ( is_numeric( $key ) ) { |
|
182 | + if (is_numeric($key)) { |
|
183 | 183 | $key = 'item' . $key; //dealing with <0/>..<n/> issues |
184 | 184 | } |
185 | 185 | |
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
186 | + $subnode = $xml->addChild($key); |
|
187 | + $this->convert_array_xml($value, $subnode); |
|
188 | 188 | |
189 | 189 | } else { |
190 | - $xml->addChild( $key, $value ? htmlspecialchars( $value ) : $value ); |
|
190 | + $xml->addChild($key, $value ? htmlspecialchars($value) : $value); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,24 +201,24 @@ discard block |
||
201 | 201 | * @since 1.0.19 |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function prepare_row( $row, $fields ) { |
|
204 | + public function prepare_row($row, $fields) { |
|
205 | 205 | |
206 | 206 | $prepared = array(); |
207 | 207 | $row = (array) $row; |
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ($fields as $field) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
211 | + if ($field === 'total') { |
|
212 | + $prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES); |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
216 | + if ($field === 'total_raw') { |
|
217 | + $prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total'])); |
|
218 | 218 | continue; |
219 | 219 | } |
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[$field] = strip_tags($row[$field]); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 |