@@ -14,91 +14,91 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
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 | 29 | |
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct(){ |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct(){ |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
68 | 68 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
76 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
77 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
78 | - |
|
79 | - // Setup/welcome |
|
80 | - if ( ! empty( $_GET['page'] ) ) { |
|
81 | - switch ( $_GET['page'] ) { |
|
82 | - case 'gp-setup' : |
|
83 | - include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
84 | - break; |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Register admin scripts |
|
92 | - * |
|
93 | - */ |
|
94 | - public function enqeue_scripts() { |
|
69 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
70 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
71 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
75 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
76 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
77 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
78 | + |
|
79 | + // Setup/welcome |
|
80 | + if ( ! empty( $_GET['page'] ) ) { |
|
81 | + switch ( $_GET['page'] ) { |
|
82 | + case 'gp-setup' : |
|
83 | + include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
84 | + break; |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Register admin scripts |
|
92 | + * |
|
93 | + */ |
|
94 | + public function enqeue_scripts() { |
|
95 | 95 | global $current_screen, $pagenow; |
96 | 96 | |
97 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
98 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
97 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
98 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
99 | 99 | |
100 | 100 | if ( ! empty( $current_screen->post_type ) ) { |
101 | - $page = $current_screen->post_type; |
|
101 | + $page = $current_screen->post_type; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // General styles. |
@@ -119,54 +119,54 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | // Payment form scripts. |
122 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
122 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
123 | 123 | $this->load_payment_form_scripts(); |
124 | 124 | } |
125 | 125 | |
126 | - if ( $page == 'wpinv-subscriptions' ) { |
|
127 | - wp_enqueue_script( 'postbox' ); |
|
128 | - } |
|
126 | + if ( $page == 'wpinv-subscriptions' ) { |
|
127 | + wp_enqueue_script( 'postbox' ); |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * Returns admin js translations. |
|
134 | - * |
|
135 | - */ |
|
136 | - protected function get_admin_i18() { |
|
133 | + * Returns admin js translations. |
|
134 | + * |
|
135 | + */ |
|
136 | + protected function get_admin_i18() { |
|
137 | 137 | global $post; |
138 | 138 | |
139 | - $date_range = array( |
|
140 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
141 | - ); |
|
139 | + $date_range = array( |
|
140 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
141 | + ); |
|
142 | 142 | |
143 | - if ( $date_range['period'] == 'custom' ) { |
|
143 | + if ( $date_range['period'] == 'custom' ) { |
|
144 | 144 | |
145 | - if ( isset( $_GET['from'] ) ) { |
|
146 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
147 | - } |
|
145 | + if ( isset( $_GET['from'] ) ) { |
|
146 | + $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
147 | + } |
|
148 | 148 | |
149 | - if ( isset( $_GET['to'] ) ) { |
|
150 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
151 | - } |
|
149 | + if ( isset( $_GET['to'] ) ) { |
|
150 | + $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
151 | + } |
|
152 | 152 | |
153 | - } |
|
153 | + } |
|
154 | 154 | |
155 | 155 | $i18n = array( |
156 | 156 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
157 | 157 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
158 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
159 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
160 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
161 | - 'date_range' => $date_range, |
|
158 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
159 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
160 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
161 | + 'date_range' => $date_range, |
|
162 | 162 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
163 | 163 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
164 | 164 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
165 | 165 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
166 | 166 | 'tax' => wpinv_tax_amount(), |
167 | 167 | 'discount' => 0, |
168 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
169 | - 'currency' => wpinv_get_currency(), |
|
168 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
169 | + 'currency' => wpinv_get_currency(), |
|
170 | 170 | 'currency_pos' => wpinv_currency_position(), |
171 | 171 | 'thousand_sep' => wpinv_thousands_separator(), |
172 | 172 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -186,119 +186,119 @@ discard block |
||
186 | 186 | 'item_description' => __( 'Item Description', 'invoicing' ), |
187 | 187 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
188 | 188 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
189 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
190 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
191 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
192 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
193 | - 'graphs' => array_merge( ['refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'], array_keys( wpinv_get_report_graphs() ) ), |
|
189 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
190 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
191 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
192 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
193 | + 'graphs' => array_merge( ['refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'], array_keys( wpinv_get_report_graphs() ) ), |
|
194 | 194 | ); |
195 | 195 | |
196 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
196 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
197 | 197 | |
198 | - $invoice = new WPInv_Invoice( $post ); |
|
199 | - $i18n['save_invoice'] = sprintf( |
|
200 | - __( 'Save %s', 'invoicing' ), |
|
201 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
202 | - ); |
|
198 | + $invoice = new WPInv_Invoice( $post ); |
|
199 | + $i18n['save_invoice'] = sprintf( |
|
200 | + __( 'Save %s', 'invoicing' ), |
|
201 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
202 | + ); |
|
203 | 203 | |
204 | - $i18n['invoice_description'] = sprintf( |
|
205 | - __( '%s Description', 'invoicing' ), |
|
206 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
207 | - ); |
|
204 | + $i18n['invoice_description'] = sprintf( |
|
205 | + __( '%s Description', 'invoicing' ), |
|
206 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
207 | + ); |
|
208 | 208 | |
209 | - } |
|
210 | - return $i18n; |
|
211 | - } |
|
209 | + } |
|
210 | + return $i18n; |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * Change the admin footer text on GetPaid admin pages. |
|
215 | - * |
|
216 | - * @since 2.0.0 |
|
217 | - * @param string $footer_text |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - public function admin_footer_text( $footer_text ) { |
|
221 | - global $current_screen; |
|
213 | + /** |
|
214 | + * Change the admin footer text on GetPaid admin pages. |
|
215 | + * |
|
216 | + * @since 2.0.0 |
|
217 | + * @param string $footer_text |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + public function admin_footer_text( $footer_text ) { |
|
221 | + global $current_screen; |
|
222 | 222 | |
223 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
223 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
224 | 224 | |
225 | 225 | if ( ! empty( $current_screen->post_type ) ) { |
226 | - $page = $current_screen->post_type; |
|
226 | + $page = $current_screen->post_type; |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | // General styles. |
230 | 230 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
231 | 231 | |
232 | - // Change the footer text |
|
233 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
234 | - |
|
235 | - $rating_url = esc_url( |
|
236 | - wp_nonce_url( |
|
237 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
238 | - 'getpaid-nonce', |
|
239 | - 'getpaid-nonce' |
|
240 | - ) |
|
241 | - ); |
|
242 | - |
|
243 | - $footer_text = sprintf( |
|
244 | - /* translators: %s: five stars */ |
|
245 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
246 | - "<a href='$rating_url'>★★★★★</a>" |
|
247 | - ); |
|
248 | - |
|
249 | - } else { |
|
250 | - |
|
251 | - $footer_text = sprintf( |
|
252 | - /* translators: %s: GetPaid */ |
|
253 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
254 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
255 | - ); |
|
256 | - |
|
257 | - } |
|
258 | - |
|
259 | - } |
|
260 | - |
|
261 | - return $footer_text; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Redirects to wp.org to rate the plugin. |
|
266 | - * |
|
267 | - * @since 2.0.0 |
|
268 | - */ |
|
269 | - public function redirect_to_wordpress_rating_page() { |
|
270 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
272 | - exit; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Loads payment form js. |
|
277 | - * |
|
278 | - */ |
|
279 | - protected function load_payment_form_scripts() { |
|
232 | + // Change the footer text |
|
233 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
234 | + |
|
235 | + $rating_url = esc_url( |
|
236 | + wp_nonce_url( |
|
237 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
238 | + 'getpaid-nonce', |
|
239 | + 'getpaid-nonce' |
|
240 | + ) |
|
241 | + ); |
|
242 | + |
|
243 | + $footer_text = sprintf( |
|
244 | + /* translators: %s: five stars */ |
|
245 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
246 | + "<a href='$rating_url'>★★★★★</a>" |
|
247 | + ); |
|
248 | + |
|
249 | + } else { |
|
250 | + |
|
251 | + $footer_text = sprintf( |
|
252 | + /* translators: %s: GetPaid */ |
|
253 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
254 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
255 | + ); |
|
256 | + |
|
257 | + } |
|
258 | + |
|
259 | + } |
|
260 | + |
|
261 | + return $footer_text; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Redirects to wp.org to rate the plugin. |
|
266 | + * |
|
267 | + * @since 2.0.0 |
|
268 | + */ |
|
269 | + public function redirect_to_wordpress_rating_page() { |
|
270 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
272 | + exit; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Loads payment form js. |
|
277 | + * |
|
278 | + */ |
|
279 | + protected function load_payment_form_scripts() { |
|
280 | 280 | global $post; |
281 | 281 | |
282 | 282 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
283 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
283 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
285 | 285 | |
286 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
286 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
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,20 +307,20 @@ 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 | |
320 | 320 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
321 | 321 | |
322 | 322 | if ( ! empty( $current_screen->post_type ) ) { |
323 | - $page = $current_screen->post_type; |
|
323 | + $page = $current_screen->post_type; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -329,68 +329,68 @@ discard block |
||
329 | 329 | |
330 | 330 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
331 | 331 | $classes .= ' wpinv-cpt wpinv'; |
332 | - } |
|
332 | + } |
|
333 | 333 | |
334 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
334 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
335 | 335 | $classes .= ' getpaid-is-invoice-cpt'; |
336 | 336 | } |
337 | 337 | |
338 | - return $classes; |
|
338 | + return $classes; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
342 | - * Maybe show the AyeCode Connect Notice. |
|
343 | - */ |
|
344 | - public function init_ayecode_connect_helper(){ |
|
342 | + * Maybe show the AyeCode Connect Notice. |
|
343 | + */ |
|
344 | + public function init_ayecode_connect_helper(){ |
|
345 | 345 | |
346 | - // Register with the deactivation survey class. |
|
347 | - AyeCode_Deactivation_Survey::instance(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' ), |
|
353 | - )); |
|
346 | + // Register with the deactivation survey class. |
|
347 | + AyeCode_Deactivation_Survey::instance(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' ), |
|
353 | + )); |
|
354 | 354 | |
355 | 355 | new AyeCode_Connect_Helper( |
356 | 356 | array( |
357 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
358 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
359 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
360 | - 'connect_button' => __("Connect Site","invoicing"), |
|
361 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
362 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
363 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
357 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
358 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
359 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
360 | + 'connect_button' => __("Connect Site","invoicing"), |
|
361 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
362 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
363 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
364 | 364 | ), |
365 | 365 | array( 'wpi-addons' ) |
366 | 366 | ); |
367 | 367 | |
368 | 368 | } |
369 | 369 | |
370 | - /** |
|
371 | - * Redirect users to settings on activation. |
|
372 | - * |
|
373 | - * @return void |
|
374 | - */ |
|
375 | - public function activation_redirect() { |
|
370 | + /** |
|
371 | + * Redirect users to settings on activation. |
|
372 | + * |
|
373 | + * @return void |
|
374 | + */ |
|
375 | + public function activation_redirect() { |
|
376 | 376 | |
377 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
377 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
378 | 378 | |
379 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
380 | - return; |
|
381 | - } |
|
379 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
380 | + return; |
|
381 | + } |
|
382 | 382 | |
383 | - // Bail if activating from network, or bulk |
|
384 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
385 | - return; |
|
386 | - } |
|
383 | + // Bail if activating from network, or bulk |
|
384 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
385 | + return; |
|
386 | + } |
|
387 | 387 | |
388 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
388 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
389 | 389 | |
390 | 390 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
391 | 391 | exit; |
392 | 392 | |
393 | - } |
|
393 | + } |
|
394 | 394 | |
395 | 395 | /** |
396 | 396 | * Fires an admin action after verifying that a user can fire them. |
@@ -404,532 +404,532 @@ 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.', 'newsletter-optin-box' ) ); |
|
429 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
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.', 'newsletter-optin-box' ) ); |
|
444 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - /** |
|
448 | + /** |
|
449 | 449 | * Sends a payment reminder to a customer. |
450 | - * |
|
451 | - * @param array $args |
|
450 | + * |
|
451 | + * @param array $args |
|
452 | 452 | */ |
453 | 453 | public function duplicate_payment_form( $args ) { |
454 | 454 | |
455 | - if ( empty( $args['form_id'] ) ) { |
|
456 | - return; |
|
457 | - } |
|
458 | - |
|
459 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
455 | + if ( empty( $args['form_id'] ) ) { |
|
456 | + return; |
|
457 | + } |
|
460 | 458 | |
461 | - if ( ! $form->exists() ) { |
|
462 | - return; |
|
463 | - } |
|
459 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
464 | 460 | |
465 | - $new_form = new GetPaid_Payment_Form(); |
|
466 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
467 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
468 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
469 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
470 | - $new_form->save(); |
|
461 | + if ( ! $form->exists() ) { |
|
462 | + return; |
|
463 | + } |
|
471 | 464 | |
472 | - if ( $new_form->exists() ) { |
|
473 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
474 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
475 | - } else { |
|
476 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
477 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
478 | - } |
|
465 | + $new_form = new GetPaid_Payment_Form(); |
|
466 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
467 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
468 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
469 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
470 | + $new_form->save(); |
|
471 | + |
|
472 | + if ( $new_form->exists() ) { |
|
473 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
474 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
475 | + } else { |
|
476 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
477 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
478 | + } |
|
479 | 479 | |
480 | - wp_redirect( $url ); |
|
481 | - exit; |
|
482 | - } |
|
480 | + wp_redirect( $url ); |
|
481 | + exit; |
|
482 | + } |
|
483 | 483 | |
484 | - /** |
|
484 | + /** |
|
485 | 485 | * Sends a payment reminder to a customer. |
486 | - * |
|
487 | - * @param array $args |
|
486 | + * |
|
487 | + * @param array $args |
|
488 | 488 | */ |
489 | 489 | public function send_customer_invoice( $args ) { |
490 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
491 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
492 | - exit; |
|
493 | - } |
|
490 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
491 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
492 | + exit; |
|
493 | + } |
|
494 | 494 | |
495 | - /** |
|
495 | + /** |
|
496 | 496 | * Sends a payment reminder to a customer. |
497 | - * |
|
498 | - * @param array $args |
|
497 | + * |
|
498 | + * @param array $args |
|
499 | 499 | */ |
500 | 500 | public function send_customer_payment_reminder( $args ) { |
501 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
501 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
502 | 502 | |
503 | - if ( $sent ) { |
|
504 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
505 | - } else { |
|
506 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
507 | - } |
|
503 | + if ( $sent ) { |
|
504 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
505 | + } else { |
|
506 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
507 | + } |
|
508 | 508 | |
509 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
510 | - exit; |
|
511 | - } |
|
509 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
510 | + exit; |
|
511 | + } |
|
512 | 512 | |
513 | - /** |
|
513 | + /** |
|
514 | 514 | * Resets tax rates. |
515 | - * |
|
515 | + * |
|
516 | 516 | */ |
517 | 517 | public function admin_reset_tax_rates() { |
518 | 518 | |
519 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
520 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
521 | - exit; |
|
519 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
520 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
521 | + exit; |
|
522 | 522 | |
523 | - } |
|
523 | + } |
|
524 | 524 | |
525 | - /** |
|
525 | + /** |
|
526 | 526 | * Resets admin pages. |
527 | - * |
|
527 | + * |
|
528 | 528 | */ |
529 | 529 | public function admin_create_missing_pages() { |
530 | - $installer = new GetPaid_Installer(); |
|
531 | - $installer->create_pages(); |
|
532 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
533 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
534 | - exit; |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
530 | + $installer = new GetPaid_Installer(); |
|
531 | + $installer->create_pages(); |
|
532 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
533 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
534 | + exit; |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | 538 | * Creates an missing admin tables. |
539 | - * |
|
539 | + * |
|
540 | 540 | */ |
541 | 541 | public function admin_create_missing_tables() { |
542 | - global $wpdb; |
|
543 | - $installer = new GetPaid_Installer(); |
|
542 | + global $wpdb; |
|
543 | + $installer = new GetPaid_Installer(); |
|
544 | 544 | |
545 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
546 | - $installer->create_subscriptions_table(); |
|
545 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
546 | + $installer->create_subscriptions_table(); |
|
547 | 547 | |
548 | - if ( $wpdb->last_error !== '' ) { |
|
549 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
550 | - } |
|
551 | - } |
|
548 | + if ( $wpdb->last_error !== '' ) { |
|
549 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
550 | + } |
|
551 | + } |
|
552 | 552 | |
553 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
554 | - $installer->create_invoices_table(); |
|
553 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
554 | + $installer->create_invoices_table(); |
|
555 | 555 | |
556 | - if ( $wpdb->last_error !== '' ) { |
|
557 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
558 | - } |
|
559 | - } |
|
556 | + if ( $wpdb->last_error !== '' ) { |
|
557 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
558 | + } |
|
559 | + } |
|
560 | 560 | |
561 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
562 | - $installer->create_invoice_items_table(); |
|
561 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
562 | + $installer->create_invoice_items_table(); |
|
563 | 563 | |
564 | - if ( $wpdb->last_error !== '' ) { |
|
565 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
566 | - } |
|
567 | - } |
|
564 | + if ( $wpdb->last_error !== '' ) { |
|
565 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
566 | + } |
|
567 | + } |
|
568 | 568 | |
569 | - if ( ! $this->has_notices() ) { |
|
570 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
571 | - } |
|
569 | + if ( ! $this->has_notices() ) { |
|
570 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
571 | + } |
|
572 | 572 | |
573 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
574 | - exit; |
|
575 | - } |
|
573 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
574 | + exit; |
|
575 | + } |
|
576 | 576 | |
577 | - /** |
|
577 | + /** |
|
578 | 578 | * Migrates old invoices to the new database tables. |
579 | - * |
|
579 | + * |
|
580 | 580 | */ |
581 | 581 | public function admin_migrate_old_invoices() { |
582 | 582 | |
583 | - // Migrate the invoices. |
|
584 | - $installer = new GetPaid_Installer(); |
|
585 | - $installer->migrate_old_invoices(); |
|
583 | + // Migrate the invoices. |
|
584 | + $installer = new GetPaid_Installer(); |
|
585 | + $installer->migrate_old_invoices(); |
|
586 | 586 | |
587 | - // Show an admin message. |
|
588 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
587 | + // Show an admin message. |
|
588 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
589 | 589 | |
590 | - // Redirect the admin. |
|
591 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
592 | - exit; |
|
590 | + // Redirect the admin. |
|
591 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
592 | + exit; |
|
593 | 593 | |
594 | - } |
|
594 | + } |
|
595 | 595 | |
596 | - /** |
|
596 | + /** |
|
597 | 597 | * Download customers. |
598 | - * |
|
598 | + * |
|
599 | 599 | */ |
600 | 600 | public function admin_download_customers() { |
601 | - global $wpdb; |
|
601 | + global $wpdb; |
|
602 | 602 | |
603 | - $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
603 | + $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
604 | 604 | |
605 | - header( "Content-Type:text/csv" ); |
|
606 | - header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
605 | + header( "Content-Type:text/csv" ); |
|
606 | + header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
607 | 607 | |
608 | - $post_types = ''; |
|
608 | + $post_types = ''; |
|
609 | 609 | |
610 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
611 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
612 | - } |
|
610 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
611 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
612 | + } |
|
613 | 613 | |
614 | - $post_types = rtrim( $post_types, ' OR' ); |
|
614 | + $post_types = rtrim( $post_types, ' OR' ); |
|
615 | 615 | |
616 | - $customers = $wpdb->get_col( |
|
617 | - $wpdb->prepare( |
|
618 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" |
|
619 | - ) |
|
620 | - ); |
|
616 | + $customers = $wpdb->get_col( |
|
617 | + $wpdb->prepare( |
|
618 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" |
|
619 | + ) |
|
620 | + ); |
|
621 | 621 | |
622 | - $columns = array( |
|
623 | - 'name' => __( 'Name', 'invoicing' ), |
|
624 | - 'email' => __( 'Email', 'invoicing' ), |
|
625 | - 'country' => __( 'Country', 'invoicing' ), |
|
626 | - 'state' => __( 'State', 'invoicing' ), |
|
627 | - 'city' => __( 'City', 'invoicing' ), |
|
628 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
629 | - 'address' => __( 'Address', 'invoicing' ), |
|
630 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
631 | - 'company' => __( 'Company', 'invoicing' ), |
|
632 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
633 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
634 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
635 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
636 | - ); |
|
622 | + $columns = array( |
|
623 | + 'name' => __( 'Name', 'invoicing' ), |
|
624 | + 'email' => __( 'Email', 'invoicing' ), |
|
625 | + 'country' => __( 'Country', 'invoicing' ), |
|
626 | + 'state' => __( 'State', 'invoicing' ), |
|
627 | + 'city' => __( 'City', 'invoicing' ), |
|
628 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
629 | + 'address' => __( 'Address', 'invoicing' ), |
|
630 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
631 | + 'company' => __( 'Company', 'invoicing' ), |
|
632 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
633 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
634 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
635 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
636 | + ); |
|
637 | 637 | |
638 | - // Output the csv column headers. |
|
639 | - fputcsv( $output, array_values( $columns ) ); |
|
638 | + // Output the csv column headers. |
|
639 | + fputcsv( $output, array_values( $columns ) ); |
|
640 | 640 | |
641 | - // Loop through |
|
642 | - $table = new WPInv_Customers_Table(); |
|
643 | - foreach ( $customers as $customer_id ) { |
|
641 | + // Loop through |
|
642 | + $table = new WPInv_Customers_Table(); |
|
643 | + foreach ( $customers as $customer_id ) { |
|
644 | 644 | |
645 | - $user = get_user_by( 'id', $customer_id ); |
|
646 | - $row = array(); |
|
647 | - if ( empty( $user ) ) { |
|
648 | - continue; |
|
649 | - } |
|
645 | + $user = get_user_by( 'id', $customer_id ); |
|
646 | + $row = array(); |
|
647 | + if ( empty( $user ) ) { |
|
648 | + continue; |
|
649 | + } |
|
650 | 650 | |
651 | - foreach ( array_keys( $columns ) as $column ) { |
|
651 | + foreach ( array_keys( $columns ) as $column ) { |
|
652 | 652 | |
653 | - $method = 'column_' . $column; |
|
653 | + $method = 'column_' . $column; |
|
654 | 654 | |
655 | - if ( 'name' == $column ) { |
|
656 | - $value = esc_html( $user->display_name ); |
|
657 | - } else if( 'email' == $column ) { |
|
658 | - $value = sanitize_email( $user->user_email ); |
|
659 | - } else if ( is_callable( array( $table, $method ) ) ) { |
|
660 | - $value = strip_tags( $table->$method( $user ) ); |
|
661 | - } |
|
655 | + if ( 'name' == $column ) { |
|
656 | + $value = esc_html( $user->display_name ); |
|
657 | + } else if( 'email' == $column ) { |
|
658 | + $value = sanitize_email( $user->user_email ); |
|
659 | + } else if ( is_callable( array( $table, $method ) ) ) { |
|
660 | + $value = strip_tags( $table->$method( $user ) ); |
|
661 | + } |
|
662 | 662 | |
663 | - if ( empty( $value ) ) { |
|
664 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
665 | - } |
|
663 | + if ( empty( $value ) ) { |
|
664 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
665 | + } |
|
666 | 666 | |
667 | - $row[] = $value; |
|
667 | + $row[] = $value; |
|
668 | 668 | |
669 | - } |
|
669 | + } |
|
670 | 670 | |
671 | - fputcsv( $output, $row ); |
|
672 | - } |
|
671 | + fputcsv( $output, $row ); |
|
672 | + } |
|
673 | 673 | |
674 | - fclose( $output ); |
|
675 | - exit; |
|
674 | + fclose( $output ); |
|
675 | + exit; |
|
676 | 676 | |
677 | - } |
|
677 | + } |
|
678 | 678 | |
679 | - /** |
|
679 | + /** |
|
680 | 680 | * Installs a plugin. |
681 | - * |
|
682 | - * @param array $data |
|
681 | + * |
|
682 | + * @param array $data |
|
683 | 683 | */ |
684 | 684 | public function admin_install_plugin( $data ) { |
685 | 685 | |
686 | - if ( ! empty( $data['plugins'] ) ) { |
|
687 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
688 | - wp_cache_flush(); |
|
686 | + if ( ! empty( $data['plugins'] ) ) { |
|
687 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
688 | + wp_cache_flush(); |
|
689 | 689 | |
690 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
691 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
692 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
693 | - $installed = $upgrader->install( $plugin_zip ); |
|
690 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
691 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
692 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
693 | + $installed = $upgrader->install( $plugin_zip ); |
|
694 | 694 | |
695 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
696 | - activate_plugin( $file, '', false, true ); |
|
697 | - } else { |
|
698 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
699 | - } |
|
695 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
696 | + activate_plugin( $file, '', false, true ); |
|
697 | + } else { |
|
698 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
699 | + } |
|
700 | 700 | |
701 | - } |
|
701 | + } |
|
702 | 702 | |
703 | - } |
|
703 | + } |
|
704 | 704 | |
705 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
706 | - wp_safe_redirect( $redirect ); |
|
707 | - exit; |
|
705 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
706 | + wp_safe_redirect( $redirect ); |
|
707 | + exit; |
|
708 | 708 | |
709 | - } |
|
709 | + } |
|
710 | 710 | |
711 | - /** |
|
711 | + /** |
|
712 | 712 | * Connects a gateway. |
713 | - * |
|
714 | - * @param array $data |
|
713 | + * |
|
714 | + * @param array $data |
|
715 | 715 | */ |
716 | 716 | public function admin_connect_gateway( $data ) { |
717 | 717 | |
718 | - if ( ! empty( $data['plugin'] ) ) { |
|
718 | + if ( ! empty( $data['plugin'] ) ) { |
|
719 | 719 | |
720 | - $gateway = sanitize_key( $data['plugin'] ); |
|
721 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
720 | + $gateway = sanitize_key( $data['plugin'] ); |
|
721 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
722 | 722 | |
723 | - if ( ! empty( $connect_url ) ) { |
|
724 | - wp_redirect( $connect_url ); |
|
725 | - exit; |
|
726 | - } |
|
723 | + if ( ! empty( $connect_url ) ) { |
|
724 | + wp_redirect( $connect_url ); |
|
725 | + exit; |
|
726 | + } |
|
727 | 727 | |
728 | - if ( 'stripe' == $data['plugin'] ) { |
|
729 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
730 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
731 | - wp_cache_flush(); |
|
728 | + if ( 'stripe' == $data['plugin'] ) { |
|
729 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
730 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
731 | + wp_cache_flush(); |
|
732 | 732 | |
733 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
734 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
735 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
736 | - $upgrader->install( $plugin_zip ); |
|
737 | - } |
|
733 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
734 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
735 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
736 | + $upgrader->install( $plugin_zip ); |
|
737 | + } |
|
738 | 738 | |
739 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
740 | - } |
|
739 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
740 | + } |
|
741 | 741 | |
742 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
743 | - if ( ! empty( $connect_url ) ) { |
|
744 | - wp_redirect( $connect_url ); |
|
745 | - exit; |
|
746 | - } |
|
742 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
743 | + if ( ! empty( $connect_url ) ) { |
|
744 | + wp_redirect( $connect_url ); |
|
745 | + exit; |
|
746 | + } |
|
747 | 747 | |
748 | - } |
|
748 | + } |
|
749 | 749 | |
750 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
751 | - wp_safe_redirect( $redirect ); |
|
752 | - exit; |
|
750 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
751 | + wp_safe_redirect( $redirect ); |
|
752 | + exit; |
|
753 | 753 | |
754 | - } |
|
754 | + } |
|
755 | 755 | |
756 | - /** |
|
756 | + /** |
|
757 | 757 | * Recalculates discounts. |
758 | - * |
|
758 | + * |
|
759 | 759 | */ |
760 | 760 | public function admin_recalculate_discounts() { |
761 | - global $wpdb; |
|
761 | + global $wpdb; |
|
762 | 762 | |
763 | - // Fetch all invoices that have discount codes. |
|
764 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
765 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
763 | + // Fetch all invoices that have discount codes. |
|
764 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
765 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
766 | 766 | |
767 | - foreach ( $invoices as $invoice ) { |
|
767 | + foreach ( $invoices as $invoice ) { |
|
768 | 768 | |
769 | - $invoice = new WPInv_Invoice( $invoice ); |
|
769 | + $invoice = new WPInv_Invoice( $invoice ); |
|
770 | 770 | |
771 | - if ( ! $invoice->exists() ) { |
|
772 | - continue; |
|
773 | - } |
|
771 | + if ( ! $invoice->exists() ) { |
|
772 | + continue; |
|
773 | + } |
|
774 | 774 | |
775 | - // Abort if the discount does not exist or does not apply here. |
|
776 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
777 | - if ( ! $discount->exists() ) { |
|
778 | - continue; |
|
779 | - } |
|
775 | + // Abort if the discount does not exist or does not apply here. |
|
776 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
777 | + if ( ! $discount->exists() ) { |
|
778 | + continue; |
|
779 | + } |
|
780 | 780 | |
781 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
782 | - $invoice->recalculate_total(); |
|
781 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
782 | + $invoice->recalculate_total(); |
|
783 | 783 | |
784 | - if ( $invoice->get_total_discount() > 0 ) { |
|
785 | - $invoice->save(); |
|
786 | - } |
|
784 | + if ( $invoice->get_total_discount() > 0 ) { |
|
785 | + $invoice->save(); |
|
786 | + } |
|
787 | 787 | |
788 | - } |
|
788 | + } |
|
789 | 789 | |
790 | - // Show an admin message. |
|
791 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
790 | + // Show an admin message. |
|
791 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
792 | 792 | |
793 | - // Redirect the admin. |
|
794 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
795 | - exit; |
|
793 | + // Redirect the admin. |
|
794 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
795 | + exit; |
|
796 | 796 | |
797 | - } |
|
797 | + } |
|
798 | 798 | |
799 | 799 | /** |
800 | - * Returns an array of admin notices. |
|
801 | - * |
|
802 | - * @since 1.0.19 |
|
800 | + * Returns an array of admin notices. |
|
801 | + * |
|
802 | + * @since 1.0.19 |
|
803 | 803 | * @return array |
804 | - */ |
|
805 | - public function get_notices() { |
|
806 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
804 | + */ |
|
805 | + public function get_notices() { |
|
806 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
807 | 807 | return is_array( $notices ) ? $notices : array(); |
808 | - } |
|
808 | + } |
|
809 | 809 | |
810 | - /** |
|
811 | - * Checks if we have any admin notices. |
|
812 | - * |
|
813 | - * @since 2.0.4 |
|
810 | + /** |
|
811 | + * Checks if we have any admin notices. |
|
812 | + * |
|
813 | + * @since 2.0.4 |
|
814 | 814 | * @return array |
815 | - */ |
|
816 | - public function has_notices() { |
|
817 | - return count( $this->get_notices() ) > 0; |
|
818 | - } |
|
819 | - |
|
820 | - /** |
|
821 | - * Clears all admin notices |
|
822 | - * |
|
823 | - * @access public |
|
824 | - * @since 1.0.19 |
|
825 | - */ |
|
826 | - public function clear_notices() { |
|
827 | - delete_option( 'wpinv_admin_notices' ); |
|
828 | - } |
|
829 | - |
|
830 | - /** |
|
831 | - * Saves a new admin notice |
|
832 | - * |
|
833 | - * @access public |
|
834 | - * @since 1.0.19 |
|
835 | - */ |
|
836 | - public function save_notice( $type, $message ) { |
|
837 | - $notices = $this->get_notices(); |
|
838 | - |
|
839 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
840 | - $notices[ $type ] = array(); |
|
841 | - } |
|
842 | - |
|
843 | - $notices[ $type ][] = $message; |
|
844 | - |
|
845 | - update_option( 'wpinv_admin_notices', $notices ); |
|
846 | - } |
|
847 | - |
|
848 | - /** |
|
849 | - * Displays a success notice |
|
850 | - * |
|
851 | - * @param string $msg The message to qeue. |
|
852 | - * @access public |
|
853 | - * @since 1.0.19 |
|
854 | - */ |
|
855 | - public function show_success( $msg ) { |
|
856 | - $this->save_notice( 'success', $msg ); |
|
857 | - } |
|
858 | - |
|
859 | - /** |
|
860 | - * Displays a error notice |
|
861 | - * |
|
862 | - * @access public |
|
863 | - * @param string $msg The message to qeue. |
|
864 | - * @since 1.0.19 |
|
865 | - */ |
|
866 | - public function show_error( $msg ) { |
|
867 | - $this->save_notice( 'error', $msg ); |
|
868 | - } |
|
869 | - |
|
870 | - /** |
|
871 | - * Displays a warning notice |
|
872 | - * |
|
873 | - * @access public |
|
874 | - * @param string $msg The message to qeue. |
|
875 | - * @since 1.0.19 |
|
876 | - */ |
|
877 | - public function show_warning( $msg ) { |
|
878 | - $this->save_notice( 'warning', $msg ); |
|
879 | - } |
|
880 | - |
|
881 | - /** |
|
882 | - * Displays a info notice |
|
883 | - * |
|
884 | - * @access public |
|
885 | - * @param string $msg The message to qeue. |
|
886 | - * @since 1.0.19 |
|
887 | - */ |
|
888 | - public function show_info( $msg ) { |
|
889 | - $this->save_notice( 'info', $msg ); |
|
890 | - } |
|
891 | - |
|
892 | - /** |
|
893 | - * Show notices |
|
894 | - * |
|
895 | - * @access public |
|
896 | - * @since 1.0.19 |
|
897 | - */ |
|
898 | - public function show_notices() { |
|
815 | + */ |
|
816 | + public function has_notices() { |
|
817 | + return count( $this->get_notices() ) > 0; |
|
818 | + } |
|
819 | + |
|
820 | + /** |
|
821 | + * Clears all admin notices |
|
822 | + * |
|
823 | + * @access public |
|
824 | + * @since 1.0.19 |
|
825 | + */ |
|
826 | + public function clear_notices() { |
|
827 | + delete_option( 'wpinv_admin_notices' ); |
|
828 | + } |
|
829 | + |
|
830 | + /** |
|
831 | + * Saves a new admin notice |
|
832 | + * |
|
833 | + * @access public |
|
834 | + * @since 1.0.19 |
|
835 | + */ |
|
836 | + public function save_notice( $type, $message ) { |
|
837 | + $notices = $this->get_notices(); |
|
838 | + |
|
839 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
840 | + $notices[ $type ] = array(); |
|
841 | + } |
|
842 | + |
|
843 | + $notices[ $type ][] = $message; |
|
844 | + |
|
845 | + update_option( 'wpinv_admin_notices', $notices ); |
|
846 | + } |
|
847 | + |
|
848 | + /** |
|
849 | + * Displays a success notice |
|
850 | + * |
|
851 | + * @param string $msg The message to qeue. |
|
852 | + * @access public |
|
853 | + * @since 1.0.19 |
|
854 | + */ |
|
855 | + public function show_success( $msg ) { |
|
856 | + $this->save_notice( 'success', $msg ); |
|
857 | + } |
|
858 | + |
|
859 | + /** |
|
860 | + * Displays a error notice |
|
861 | + * |
|
862 | + * @access public |
|
863 | + * @param string $msg The message to qeue. |
|
864 | + * @since 1.0.19 |
|
865 | + */ |
|
866 | + public function show_error( $msg ) { |
|
867 | + $this->save_notice( 'error', $msg ); |
|
868 | + } |
|
869 | + |
|
870 | + /** |
|
871 | + * Displays a warning notice |
|
872 | + * |
|
873 | + * @access public |
|
874 | + * @param string $msg The message to qeue. |
|
875 | + * @since 1.0.19 |
|
876 | + */ |
|
877 | + public function show_warning( $msg ) { |
|
878 | + $this->save_notice( 'warning', $msg ); |
|
879 | + } |
|
880 | + |
|
881 | + /** |
|
882 | + * Displays a info notice |
|
883 | + * |
|
884 | + * @access public |
|
885 | + * @param string $msg The message to qeue. |
|
886 | + * @since 1.0.19 |
|
887 | + */ |
|
888 | + public function show_info( $msg ) { |
|
889 | + $this->save_notice( 'info', $msg ); |
|
890 | + } |
|
891 | + |
|
892 | + /** |
|
893 | + * Show notices |
|
894 | + * |
|
895 | + * @access public |
|
896 | + * @since 1.0.19 |
|
897 | + */ |
|
898 | + public function show_notices() { |
|
899 | 899 | |
900 | 900 | $notices = $this->get_notices(); |
901 | 901 | $this->clear_notices(); |
902 | 902 | |
903 | - foreach ( $notices as $type => $messages ) { |
|
903 | + foreach ( $notices as $type => $messages ) { |
|
904 | 904 | |
905 | - if ( ! is_array( $messages ) ) { |
|
906 | - continue; |
|
907 | - } |
|
905 | + if ( ! is_array( $messages ) ) { |
|
906 | + continue; |
|
907 | + } |
|
908 | 908 | |
909 | 909 | $type = sanitize_key( $type ); |
910 | - foreach ( $messages as $message ) { |
|
910 | + foreach ( $messages as $message ) { |
|
911 | 911 | $message = wp_kses_post( $message ); |
912 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
912 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
913 | 913 | } |
914 | 914 | |
915 | 915 | } |
916 | 916 | |
917 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
918 | - |
|
919 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
920 | - $url = wp_nonce_url( |
|
921 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
922 | - 'getpaid-nonce', |
|
923 | - 'getpaid-nonce' |
|
924 | - ); |
|
925 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
926 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
927 | - echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
928 | - break; |
|
929 | - } |
|
917 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
918 | + |
|
919 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
920 | + $url = wp_nonce_url( |
|
921 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
922 | + 'getpaid-nonce', |
|
923 | + 'getpaid-nonce' |
|
924 | + ); |
|
925 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
926 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
927 | + echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
928 | + break; |
|
929 | + } |
|
930 | 930 | |
931 | - } |
|
931 | + } |
|
932 | 932 | |
933 | - } |
|
933 | + } |
|
934 | 934 | |
935 | 935 | } |
@@ -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. |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * Class constructor. |
39 | 39 | */ |
40 | - public function __construct(){ |
|
40 | + public function __construct() { |
|
41 | 41 | |
42 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
42 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
43 | + $this->admin_url = plugins_url('/', __FILE__); |
|
44 | 44 | $this->reports = new GetPaid_Reports(); |
45 | 45 | |
46 | - if ( is_admin() ) { |
|
46 | + if (is_admin()) { |
|
47 | 47 | $this->init_admin_hooks(); |
48 | 48 | } |
49 | 49 | |
@@ -54,33 +54,33 @@ discard block |
||
54 | 54 | * |
55 | 55 | */ |
56 | 56 | private function init_admin_hooks() { |
57 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
|
58 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
59 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
60 | - add_action( 'admin_init', array( $this, 'activation_redirect') ); |
|
61 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
|
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
76 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
77 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
57 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'), 9); |
|
58 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
59 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
60 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
61 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
62 | + add_action('admin_notices', array($this, 'show_notices')); |
|
63 | + add_action('getpaid_authenticated_admin_action_rate_plugin', array($this, 'redirect_to_wordpress_rating_page')); |
|
64 | + add_action('getpaid_authenticated_admin_action_duplicate_form', array($this, 'duplicate_payment_form')); |
|
65 | + add_action('getpaid_authenticated_admin_action_duplicate_invoice', array($this, 'duplicate_invoice')); |
|
66 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
67 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
68 | + add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates')); |
|
69 | + add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages')); |
|
70 | + add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables')); |
|
71 | + add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices')); |
|
72 | + add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers')); |
|
73 | + add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts')); |
|
74 | + add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin')); |
|
75 | + add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway')); |
|
76 | + add_filter('admin_footer_text', array($this, 'admin_footer_text')); |
|
77 | + do_action('getpaid_init_admin_hooks', $this); |
|
78 | 78 | |
79 | 79 | // Setup/welcome |
80 | - if ( ! empty( $_GET['page'] ) ) { |
|
81 | - switch ( $_GET['page'] ) { |
|
80 | + if (!empty($_GET['page'])) { |
|
81 | + switch ($_GET['page']) { |
|
82 | 82 | case 'gp-setup' : |
83 | - include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
83 | + include_once(dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php'); |
|
84 | 84 | break; |
85 | 85 | } |
86 | 86 | } |
@@ -94,37 +94,37 @@ discard block |
||
94 | 94 | public function enqeue_scripts() { |
95 | 95 | global $current_screen, $pagenow; |
96 | 96 | |
97 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
97 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
98 | 98 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
99 | 99 | |
100 | - if ( ! empty( $current_screen->post_type ) ) { |
|
100 | + if (!empty($current_screen->post_type)) { |
|
101 | 101 | $page = $current_screen->post_type; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // General styles. |
105 | - if ( false !== stripos( $page, 'wpi' ) || false !== stripos( $page, 'getpaid' ) || 'gp-setup' == $page || 'geodir-tickets' == $page ) { |
|
105 | + if (false !== stripos($page, 'wpi') || false !== stripos($page, 'getpaid') || 'gp-setup' == $page || 'geodir-tickets' == $page) { |
|
106 | 106 | |
107 | 107 | // Styles. |
108 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
109 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
110 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
108 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
109 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
110 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
111 | 111 | |
112 | 112 | // Scripts. |
113 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
113 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
114 | 114 | |
115 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
116 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ), $version ); |
|
117 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
115 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
116 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version); |
|
117 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Payment form scripts. |
122 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
122 | + if ('wpi_payment_form' == $page && $editing) { |
|
123 | 123 | $this->load_payment_form_scripts(); |
124 | 124 | } |
125 | 125 | |
126 | - if ( $page == 'wpinv-subscriptions' ) { |
|
127 | - wp_enqueue_script( 'postbox' ); |
|
126 | + if ($page == 'wpinv-subscriptions') { |
|
127 | + wp_enqueue_script('postbox'); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | } |
@@ -137,32 +137,32 @@ discard block |
||
137 | 137 | global $post; |
138 | 138 | |
139 | 139 | $date_range = array( |
140 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
140 | + 'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days' |
|
141 | 141 | ); |
142 | 142 | |
143 | - if ( $date_range['period'] == 'custom' ) { |
|
143 | + if ($date_range['period'] == 'custom') { |
|
144 | 144 | |
145 | - if ( isset( $_GET['from'] ) ) { |
|
146 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
145 | + if (isset($_GET['from'])) { |
|
146 | + $date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS); |
|
147 | 147 | } |
148 | 148 | |
149 | - if ( isset( $_GET['to'] ) ) { |
|
150 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
149 | + if (isset($_GET['to'])) { |
|
150 | + $date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
154 | 154 | |
155 | 155 | $i18n = array( |
156 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
157 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
158 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
159 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
160 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
156 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
157 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
158 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
159 | + 'rest_nonce' => wp_create_nonce('wp_rest'), |
|
160 | + 'rest_root' => esc_url_raw(rest_url()), |
|
161 | 161 | 'date_range' => $date_range, |
162 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
163 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
164 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
165 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
162 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
163 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
164 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
165 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
166 | 166 | 'tax' => wpinv_tax_amount(), |
167 | 167 | 'discount' => 0, |
168 | 168 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -171,39 +171,39 @@ discard block |
||
171 | 171 | 'thousand_sep' => wpinv_thousands_separator(), |
172 | 172 | 'decimal_sep' => wpinv_decimal_separator(), |
173 | 173 | 'decimals' => wpinv_decimals(), |
174 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
175 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
176 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
177 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
178 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
179 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
180 | - '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' ), |
|
181 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
182 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
183 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
184 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
185 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
186 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
187 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
188 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
189 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
190 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
191 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
192 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
193 | - 'graphs' => array_merge( ['refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'], array_keys( wpinv_get_report_graphs() ) ), |
|
174 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
175 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
176 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
177 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
178 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
179 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
180 | + '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'), |
|
181 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
182 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
183 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
184 | + 'action_edit' => __('Edit', 'invoicing'), |
|
185 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
186 | + 'item_description' => __('Item Description', 'invoicing'), |
|
187 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
188 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
189 | + 'searching' => __('Searching', 'invoicing'), |
|
190 | + 'loading' => __('Loading...', 'invoicing'), |
|
191 | + 'search_customers' => __('Enter customer name or email', 'invoicing'), |
|
192 | + 'search_items' => __('Enter item name', 'invoicing'), |
|
193 | + 'graphs' => array_merge(['refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'], array_keys(wpinv_get_report_graphs())), |
|
194 | 194 | ); |
195 | 195 | |
196 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
196 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
197 | 197 | |
198 | - $invoice = new WPInv_Invoice( $post ); |
|
198 | + $invoice = new WPInv_Invoice($post); |
|
199 | 199 | $i18n['save_invoice'] = sprintf( |
200 | - __( 'Save %s', 'invoicing' ), |
|
201 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
200 | + __('Save %s', 'invoicing'), |
|
201 | + ucfirst($invoice->get_invoice_quote_type()) |
|
202 | 202 | ); |
203 | 203 | |
204 | 204 | $i18n['invoice_description'] = sprintf( |
205 | - __( '%s Description', 'invoicing' ), |
|
206 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
205 | + __('%s Description', 'invoicing'), |
|
206 | + ucfirst($invoice->get_invoice_quote_type()) |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | } |
@@ -217,24 +217,24 @@ discard block |
||
217 | 217 | * @param string $footer_text |
218 | 218 | * @return string |
219 | 219 | */ |
220 | - public function admin_footer_text( $footer_text ) { |
|
220 | + public function admin_footer_text($footer_text) { |
|
221 | 221 | global $current_screen; |
222 | 222 | |
223 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
223 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
224 | 224 | |
225 | - if ( ! empty( $current_screen->post_type ) ) { |
|
225 | + if (!empty($current_screen->post_type)) { |
|
226 | 226 | $page = $current_screen->post_type; |
227 | 227 | } |
228 | 228 | |
229 | 229 | // General styles. |
230 | - if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
|
230 | + if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) { |
|
231 | 231 | |
232 | 232 | // Change the footer text |
233 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
233 | + if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) { |
|
234 | 234 | |
235 | - $rating_url = esc_url( |
|
235 | + $rating_url = esc_url( |
|
236 | 236 | wp_nonce_url( |
237 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
237 | + admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'), |
|
238 | 238 | 'getpaid-nonce', |
239 | 239 | 'getpaid-nonce' |
240 | 240 | ) |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | $footer_text = sprintf( |
244 | 244 | /* translators: %s: five stars */ |
245 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
245 | + __('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'), |
|
246 | 246 | "<a href='$rating_url'>★★★★★</a>" |
247 | 247 | ); |
248 | 248 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | |
251 | 251 | $footer_text = sprintf( |
252 | 252 | /* translators: %s: GetPaid */ |
253 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
253 | + __('Thank you for using %s!', 'invoicing'), |
|
254 | 254 | "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
255 | 255 | ); |
256 | 256 | |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | * @since 2.0.0 |
268 | 268 | */ |
269 | 269 | public function redirect_to_wordpress_rating_page() { |
270 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
270 | + update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1); |
|
271 | + wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post'); |
|
272 | 272 | exit; |
273 | 273 | } |
274 | 274 | |
@@ -279,30 +279,30 @@ discard block |
||
279 | 279 | protected function load_payment_form_scripts() { |
280 | 280 | global $post; |
281 | 281 | |
282 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
|
283 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
282 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION); |
|
283 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
284 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
285 | 285 | |
286 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
286 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
287 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable', 'wp-hooks'), $version); |
|
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,25 +313,25 @@ 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 | 319 | |
320 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
320 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
321 | 321 | |
322 | - if ( ! empty( $current_screen->post_type ) ) { |
|
322 | + if (!empty($current_screen->post_type)) { |
|
323 | 323 | $page = $current_screen->post_type; |
324 | 324 | } |
325 | 325 | |
326 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
327 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
326 | + if (false !== stripos($page, 'wpi')) { |
|
327 | + $classes .= ' wpi-' . sanitize_key($page); |
|
328 | 328 | } |
329 | 329 | |
330 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
330 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
331 | 331 | $classes .= ' wpinv-cpt wpinv'; |
332 | 332 | } |
333 | 333 | |
334 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
334 | + if (getpaid_is_invoice_post_type($page)) { |
|
335 | 335 | $classes .= ' getpaid-is-invoice-cpt'; |
336 | 336 | } |
337 | 337 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | /** |
342 | 342 | * Maybe show the AyeCode Connect Notice. |
343 | 343 | */ |
344 | - public function init_ayecode_connect_helper(){ |
|
344 | + public function init_ayecode_connect_helper() { |
|
345 | 345 | |
346 | 346 | // Register with the deactivation survey class. |
347 | 347 | AyeCode_Deactivation_Survey::instance(array( |
@@ -349,20 +349,20 @@ 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 | new AyeCode_Connect_Helper( |
356 | 356 | array( |
357 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
358 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
359 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
360 | - 'connect_button' => __("Connect Site","invoicing"), |
|
361 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
362 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
363 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
357 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
358 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
359 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
360 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
361 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
362 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
363 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
364 | 364 | ), |
365 | - array( 'wpi-addons' ) |
|
365 | + array('wpi-addons') |
|
366 | 366 | ); |
367 | 367 | |
368 | 368 | } |
@@ -374,20 +374,20 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function activation_redirect() { |
376 | 376 | |
377 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
377 | + $redirected = get_option('wpinv_redirected_to_settings'); |
|
378 | 378 | |
379 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
379 | + if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) { |
|
380 | 380 | return; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // Bail if activating from network, or bulk |
384 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
384 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
385 | 385 | return; |
386 | 386 | } |
387 | 387 | |
388 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
388 | + update_option('wpinv_redirected_to_settings', 1); |
|
389 | 389 | |
390 | - wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
|
390 | + wp_safe_redirect(admin_url('index.php?page=gp-setup')); |
|
391 | 391 | exit; |
392 | 392 | |
393 | 393 | } |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | */ |
398 | 398 | public function maybe_do_admin_action() { |
399 | 399 | |
400 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
401 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
402 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
400 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
401 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
402 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | } |
@@ -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.', 'newsletter-optin-box' ) ); |
|
429 | + getpaid_admin()->show_success(__('Invoice duplicated successfully.', 'newsletter-optin-box')); |
|
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.', 'newsletter-optin-box' ) ); |
|
444 | + getpaid_admin()->show_error(__('There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box')); |
|
445 | 445 | |
446 | 446 | } |
447 | 447 | |
@@ -450,34 +450,34 @@ discard block |
||
450 | 450 | * |
451 | 451 | * @param array $args |
452 | 452 | */ |
453 | - public function duplicate_payment_form( $args ) { |
|
453 | + public function duplicate_payment_form($args) { |
|
454 | 454 | |
455 | - if ( empty( $args['form_id'] ) ) { |
|
455 | + if (empty($args['form_id'])) { |
|
456 | 456 | return; |
457 | 457 | } |
458 | 458 | |
459 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
459 | + $form = new GetPaid_Payment_Form((int) $args['form_id']); |
|
460 | 460 | |
461 | - if ( ! $form->exists() ) { |
|
461 | + if (!$form->exists()) { |
|
462 | 462 | return; |
463 | 463 | } |
464 | 464 | |
465 | 465 | $new_form = new GetPaid_Payment_Form(); |
466 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
467 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
468 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
469 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
466 | + $new_form->set_author($form->get_author('edit')); |
|
467 | + $new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing')); |
|
468 | + $new_form->set_elements($form->get_elements('edit')); |
|
469 | + $new_form->set_items($form->get_items('edit')); |
|
470 | 470 | $new_form->save(); |
471 | 471 | |
472 | - if ( $new_form->exists() ) { |
|
473 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
474 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
472 | + if ($new_form->exists()) { |
|
473 | + $this->show_success(__('Form duplicated successfully', 'invoicing')); |
|
474 | + $url = get_edit_post_link($new_form->get_id(), 'edit'); |
|
475 | 475 | } else { |
476 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
477 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
476 | + $this->show_error(__('Unable to duplicate form', 'invoicing')); |
|
477 | + $url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce')); |
|
478 | 478 | } |
479 | 479 | |
480 | - wp_redirect( $url ); |
|
480 | + wp_redirect($url); |
|
481 | 481 | exit; |
482 | 482 | } |
483 | 483 | |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | * |
487 | 487 | * @param array $args |
488 | 488 | */ |
489 | - public function send_customer_invoice( $args ) { |
|
490 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
491 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
489 | + public function send_customer_invoice($args) { |
|
490 | + getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true); |
|
491 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
492 | 492 | exit; |
493 | 493 | } |
494 | 494 | |
@@ -497,16 +497,16 @@ discard block |
||
497 | 497 | * |
498 | 498 | * @param array $args |
499 | 499 | */ |
500 | - public function send_customer_payment_reminder( $args ) { |
|
501 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
500 | + public function send_customer_payment_reminder($args) { |
|
501 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
502 | 502 | |
503 | - if ( $sent ) { |
|
504 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
503 | + if ($sent) { |
|
504 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
505 | 505 | } else { |
506 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
506 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
507 | 507 | } |
508 | 508 | |
509 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
509 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
510 | 510 | exit; |
511 | 511 | } |
512 | 512 | |
@@ -516,8 +516,8 @@ discard block |
||
516 | 516 | */ |
517 | 517 | public function admin_reset_tax_rates() { |
518 | 518 | |
519 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
520 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
519 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
520 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
521 | 521 | exit; |
522 | 522 | |
523 | 523 | } |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | public function admin_create_missing_pages() { |
530 | 530 | $installer = new GetPaid_Installer(); |
531 | 531 | $installer->create_pages(); |
532 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
533 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
532 | + $this->show_success(__('GetPaid pages updated.', 'invoicing')); |
|
533 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
534 | 534 | exit; |
535 | 535 | } |
536 | 536 | |
@@ -542,35 +542,35 @@ discard block |
||
542 | 542 | global $wpdb; |
543 | 543 | $installer = new GetPaid_Installer(); |
544 | 544 | |
545 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
545 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'") != $wpdb->prefix . 'wpinv_subscriptions') { |
|
546 | 546 | $installer->create_subscriptions_table(); |
547 | 547 | |
548 | - if ( $wpdb->last_error !== '' ) { |
|
549 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
548 | + if ($wpdb->last_error !== '') { |
|
549 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
550 | 550 | } |
551 | 551 | } |
552 | 552 | |
553 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
553 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") != $wpdb->prefix . 'getpaid_invoices') { |
|
554 | 554 | $installer->create_invoices_table(); |
555 | 555 | |
556 | - if ( $wpdb->last_error !== '' ) { |
|
557 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
556 | + if ($wpdb->last_error !== '') { |
|
557 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
561 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
561 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'") != $wpdb->prefix . 'getpaid_invoice_items') { |
|
562 | 562 | $installer->create_invoice_items_table(); |
563 | 563 | |
564 | - if ( $wpdb->last_error !== '' ) { |
|
565 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
564 | + if ($wpdb->last_error !== '') { |
|
565 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
569 | - if ( ! $this->has_notices() ) { |
|
570 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
569 | + if (!$this->has_notices()) { |
|
570 | + $this->show_success(__('Your GetPaid tables have been updated.', 'invoicing')); |
|
571 | 571 | } |
572 | 572 | |
573 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
573 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
574 | 574 | exit; |
575 | 575 | } |
576 | 576 | |
@@ -585,10 +585,10 @@ discard block |
||
585 | 585 | $installer->migrate_old_invoices(); |
586 | 586 | |
587 | 587 | // Show an admin message. |
588 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
588 | + $this->show_success(__('Your invoices have been migrated.', 'invoicing')); |
|
589 | 589 | |
590 | 590 | // Redirect the admin. |
591 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
591 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
592 | 592 | exit; |
593 | 593 | |
594 | 594 | } |
@@ -600,18 +600,18 @@ discard block |
||
600 | 600 | public function admin_download_customers() { |
601 | 601 | global $wpdb; |
602 | 602 | |
603 | - $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
603 | + $output = fopen('php://output', 'w') or die(__('Unsupported server', 'invoicing')); |
|
604 | 604 | |
605 | - header( "Content-Type:text/csv" ); |
|
606 | - header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
605 | + header("Content-Type:text/csv"); |
|
606 | + header("Content-Disposition:attachment;filename=customers.csv"); |
|
607 | 607 | |
608 | 608 | $post_types = ''; |
609 | 609 | |
610 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
611 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
610 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
611 | + $post_types .= $wpdb->prepare("post_type=%s OR ", $post_type); |
|
612 | 612 | } |
613 | 613 | |
614 | - $post_types = rtrim( $post_types, ' OR' ); |
|
614 | + $post_types = rtrim($post_types, ' OR'); |
|
615 | 615 | |
616 | 616 | $customers = $wpdb->get_col( |
617 | 617 | $wpdb->prepare( |
@@ -620,58 +620,58 @@ discard block |
||
620 | 620 | ); |
621 | 621 | |
622 | 622 | $columns = array( |
623 | - 'name' => __( 'Name', 'invoicing' ), |
|
624 | - 'email' => __( 'Email', 'invoicing' ), |
|
625 | - 'country' => __( 'Country', 'invoicing' ), |
|
626 | - 'state' => __( 'State', 'invoicing' ), |
|
627 | - 'city' => __( 'City', 'invoicing' ), |
|
628 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
629 | - 'address' => __( 'Address', 'invoicing' ), |
|
630 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
631 | - 'company' => __( 'Company', 'invoicing' ), |
|
632 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
633 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
634 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
635 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
623 | + 'name' => __('Name', 'invoicing'), |
|
624 | + 'email' => __('Email', 'invoicing'), |
|
625 | + 'country' => __('Country', 'invoicing'), |
|
626 | + 'state' => __('State', 'invoicing'), |
|
627 | + 'city' => __('City', 'invoicing'), |
|
628 | + 'zip' => __('ZIP', 'invoicing'), |
|
629 | + 'address' => __('Address', 'invoicing'), |
|
630 | + 'phone' => __('Phone', 'invoicing'), |
|
631 | + 'company' => __('Company', 'invoicing'), |
|
632 | + 'company_id' => __('Company ID', 'invoicing'), |
|
633 | + 'invoices' => __('Invoices', 'invoicing'), |
|
634 | + 'total_raw' => __('Total Spend', 'invoicing'), |
|
635 | + 'signup' => __('Date created', 'invoicing'), |
|
636 | 636 | ); |
637 | 637 | |
638 | 638 | // Output the csv column headers. |
639 | - fputcsv( $output, array_values( $columns ) ); |
|
639 | + fputcsv($output, array_values($columns)); |
|
640 | 640 | |
641 | 641 | // Loop through |
642 | 642 | $table = new WPInv_Customers_Table(); |
643 | - foreach ( $customers as $customer_id ) { |
|
643 | + foreach ($customers as $customer_id) { |
|
644 | 644 | |
645 | - $user = get_user_by( 'id', $customer_id ); |
|
645 | + $user = get_user_by('id', $customer_id); |
|
646 | 646 | $row = array(); |
647 | - if ( empty( $user ) ) { |
|
647 | + if (empty($user)) { |
|
648 | 648 | continue; |
649 | 649 | } |
650 | 650 | |
651 | - foreach ( array_keys( $columns ) as $column ) { |
|
651 | + foreach (array_keys($columns) as $column) { |
|
652 | 652 | |
653 | 653 | $method = 'column_' . $column; |
654 | 654 | |
655 | - if ( 'name' == $column ) { |
|
656 | - $value = esc_html( $user->display_name ); |
|
657 | - } else if( 'email' == $column ) { |
|
658 | - $value = sanitize_email( $user->user_email ); |
|
659 | - } else if ( is_callable( array( $table, $method ) ) ) { |
|
660 | - $value = strip_tags( $table->$method( $user ) ); |
|
655 | + if ('name' == $column) { |
|
656 | + $value = esc_html($user->display_name); |
|
657 | + } else if ('email' == $column) { |
|
658 | + $value = sanitize_email($user->user_email); |
|
659 | + } else if (is_callable(array($table, $method))) { |
|
660 | + $value = strip_tags($table->$method($user)); |
|
661 | 661 | } |
662 | 662 | |
663 | - if ( empty( $value ) ) { |
|
664 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
663 | + if (empty($value)) { |
|
664 | + $value = esc_html(get_user_meta($user->ID, '_wpinv_' . $column, true)); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | $row[] = $value; |
668 | 668 | |
669 | 669 | } |
670 | 670 | |
671 | - fputcsv( $output, $row ); |
|
671 | + fputcsv($output, $row); |
|
672 | 672 | } |
673 | 673 | |
674 | - fclose( $output ); |
|
674 | + fclose($output); |
|
675 | 675 | exit; |
676 | 676 | |
677 | 677 | } |
@@ -681,29 +681,29 @@ discard block |
||
681 | 681 | * |
682 | 682 | * @param array $data |
683 | 683 | */ |
684 | - public function admin_install_plugin( $data ) { |
|
684 | + public function admin_install_plugin($data) { |
|
685 | 685 | |
686 | - if ( ! empty( $data['plugins'] ) ) { |
|
686 | + if (!empty($data['plugins'])) { |
|
687 | 687 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
688 | 688 | wp_cache_flush(); |
689 | 689 | |
690 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
691 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
692 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
693 | - $installed = $upgrader->install( $plugin_zip ); |
|
690 | + foreach ($data['plugins'] as $slug => $file) { |
|
691 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip'); |
|
692 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
693 | + $installed = $upgrader->install($plugin_zip); |
|
694 | 694 | |
695 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
696 | - activate_plugin( $file, '', false, true ); |
|
695 | + if (!is_wp_error($installed) && $installed) { |
|
696 | + activate_plugin($file, '', false, true); |
|
697 | 697 | } else { |
698 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
698 | + wpinv_error_log($upgrader->skin->get_upgrade_messages(), false); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | } |
702 | 702 | |
703 | 703 | } |
704 | 704 | |
705 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
706 | - wp_safe_redirect( $redirect ); |
|
705 | + $redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php'); |
|
706 | + wp_safe_redirect($redirect); |
|
707 | 707 | exit; |
708 | 708 | |
709 | 709 | } |
@@ -713,42 +713,42 @@ discard block |
||
713 | 713 | * |
714 | 714 | * @param array $data |
715 | 715 | */ |
716 | - public function admin_connect_gateway( $data ) { |
|
716 | + public function admin_connect_gateway($data) { |
|
717 | 717 | |
718 | - if ( ! empty( $data['plugin'] ) ) { |
|
718 | + if (!empty($data['plugin'])) { |
|
719 | 719 | |
720 | - $gateway = sanitize_key( $data['plugin'] ); |
|
721 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
720 | + $gateway = sanitize_key($data['plugin']); |
|
721 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
722 | 722 | |
723 | - if ( ! empty( $connect_url ) ) { |
|
724 | - wp_redirect( $connect_url ); |
|
723 | + if (!empty($connect_url)) { |
|
724 | + wp_redirect($connect_url); |
|
725 | 725 | exit; |
726 | 726 | } |
727 | 727 | |
728 | - if ( 'stripe' == $data['plugin'] ) { |
|
728 | + if ('stripe' == $data['plugin']) { |
|
729 | 729 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
730 | 730 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
731 | 731 | wp_cache_flush(); |
732 | 732 | |
733 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
734 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
735 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
736 | - $upgrader->install( $plugin_zip ); |
|
733 | + if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) { |
|
734 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip'); |
|
735 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
736 | + $upgrader->install($plugin_zip); |
|
737 | 737 | } |
738 | 738 | |
739 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
739 | + activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true); |
|
740 | 740 | } |
741 | 741 | |
742 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
743 | - if ( ! empty( $connect_url ) ) { |
|
744 | - wp_redirect( $connect_url ); |
|
742 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
743 | + if (!empty($connect_url)) { |
|
744 | + wp_redirect($connect_url); |
|
745 | 745 | exit; |
746 | 746 | } |
747 | 747 | |
748 | 748 | } |
749 | 749 | |
750 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
751 | - wp_safe_redirect( $redirect ); |
|
750 | + $redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
|
751 | + wp_safe_redirect($redirect); |
|
752 | 752 | exit; |
753 | 753 | |
754 | 754 | } |
@@ -762,36 +762,36 @@ discard block |
||
762 | 762 | |
763 | 763 | // Fetch all invoices that have discount codes. |
764 | 764 | $table = $wpdb->prefix . 'getpaid_invoices'; |
765 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
765 | + $invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''"); |
|
766 | 766 | |
767 | - foreach ( $invoices as $invoice ) { |
|
767 | + foreach ($invoices as $invoice) { |
|
768 | 768 | |
769 | - $invoice = new WPInv_Invoice( $invoice ); |
|
769 | + $invoice = new WPInv_Invoice($invoice); |
|
770 | 770 | |
771 | - if ( ! $invoice->exists() ) { |
|
771 | + if (!$invoice->exists()) { |
|
772 | 772 | continue; |
773 | 773 | } |
774 | 774 | |
775 | 775 | // Abort if the discount does not exist or does not apply here. |
776 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
777 | - if ( ! $discount->exists() ) { |
|
776 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
777 | + if (!$discount->exists()) { |
|
778 | 778 | continue; |
779 | 779 | } |
780 | 780 | |
781 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
781 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
782 | 782 | $invoice->recalculate_total(); |
783 | 783 | |
784 | - if ( $invoice->get_total_discount() > 0 ) { |
|
784 | + if ($invoice->get_total_discount() > 0) { |
|
785 | 785 | $invoice->save(); |
786 | 786 | } |
787 | 787 | |
788 | 788 | } |
789 | 789 | |
790 | 790 | // Show an admin message. |
791 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
791 | + $this->show_success(__('Discounts have been recalculated.', 'invoicing')); |
|
792 | 792 | |
793 | 793 | // Redirect the admin. |
794 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
794 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
795 | 795 | exit; |
796 | 796 | |
797 | 797 | } |
@@ -803,8 +803,8 @@ discard block |
||
803 | 803 | * @return array |
804 | 804 | */ |
805 | 805 | public function get_notices() { |
806 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
807 | - return is_array( $notices ) ? $notices : array(); |
|
806 | + $notices = get_option('wpinv_admin_notices'); |
|
807 | + return is_array($notices) ? $notices : array(); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | /** |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | * @return array |
815 | 815 | */ |
816 | 816 | public function has_notices() { |
817 | - return count( $this->get_notices() ) > 0; |
|
817 | + return count($this->get_notices()) > 0; |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | /** |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | * @since 1.0.19 |
825 | 825 | */ |
826 | 826 | public function clear_notices() { |
827 | - delete_option( 'wpinv_admin_notices' ); |
|
827 | + delete_option('wpinv_admin_notices'); |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
@@ -833,16 +833,16 @@ discard block |
||
833 | 833 | * @access public |
834 | 834 | * @since 1.0.19 |
835 | 835 | */ |
836 | - public function save_notice( $type, $message ) { |
|
836 | + public function save_notice($type, $message) { |
|
837 | 837 | $notices = $this->get_notices(); |
838 | 838 | |
839 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
840 | - $notices[ $type ] = array(); |
|
839 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
840 | + $notices[$type] = array(); |
|
841 | 841 | } |
842 | 842 | |
843 | - $notices[ $type ][] = $message; |
|
843 | + $notices[$type][] = $message; |
|
844 | 844 | |
845 | - update_option( 'wpinv_admin_notices', $notices ); |
|
845 | + update_option('wpinv_admin_notices', $notices); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | /** |
@@ -852,8 +852,8 @@ discard block |
||
852 | 852 | * @access public |
853 | 853 | * @since 1.0.19 |
854 | 854 | */ |
855 | - public function show_success( $msg ) { |
|
856 | - $this->save_notice( 'success', $msg ); |
|
855 | + public function show_success($msg) { |
|
856 | + $this->save_notice('success', $msg); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
@@ -863,8 +863,8 @@ discard block |
||
863 | 863 | * @param string $msg The message to qeue. |
864 | 864 | * @since 1.0.19 |
865 | 865 | */ |
866 | - public function show_error( $msg ) { |
|
867 | - $this->save_notice( 'error', $msg ); |
|
866 | + public function show_error($msg) { |
|
867 | + $this->save_notice('error', $msg); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | /** |
@@ -874,8 +874,8 @@ discard block |
||
874 | 874 | * @param string $msg The message to qeue. |
875 | 875 | * @since 1.0.19 |
876 | 876 | */ |
877 | - public function show_warning( $msg ) { |
|
878 | - $this->save_notice( 'warning', $msg ); |
|
877 | + public function show_warning($msg) { |
|
878 | + $this->save_notice('warning', $msg); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | /** |
@@ -885,8 +885,8 @@ discard block |
||
885 | 885 | * @param string $msg The message to qeue. |
886 | 886 | * @since 1.0.19 |
887 | 887 | */ |
888 | - public function show_info( $msg ) { |
|
889 | - $this->save_notice( 'info', $msg ); |
|
888 | + public function show_info($msg) { |
|
889 | + $this->save_notice('info', $msg); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
@@ -900,30 +900,30 @@ discard block |
||
900 | 900 | $notices = $this->get_notices(); |
901 | 901 | $this->clear_notices(); |
902 | 902 | |
903 | - foreach ( $notices as $type => $messages ) { |
|
903 | + foreach ($notices as $type => $messages) { |
|
904 | 904 | |
905 | - if ( ! is_array( $messages ) ) { |
|
905 | + if (!is_array($messages)) { |
|
906 | 906 | continue; |
907 | 907 | } |
908 | 908 | |
909 | - $type = sanitize_key( $type ); |
|
910 | - foreach ( $messages as $message ) { |
|
911 | - $message = wp_kses_post( $message ); |
|
909 | + $type = sanitize_key($type); |
|
910 | + foreach ($messages as $message) { |
|
911 | + $message = wp_kses_post($message); |
|
912 | 912 | echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
913 | 913 | } |
914 | 914 | |
915 | 915 | } |
916 | 916 | |
917 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
917 | + foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) { |
|
918 | 918 | |
919 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
920 | - $url = wp_nonce_url( |
|
921 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
919 | + if (!is_numeric(wpinv_get_option($page, false))) { |
|
920 | + $url = wp_nonce_url( |
|
921 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
922 | 922 | 'getpaid-nonce', |
923 | 923 | 'getpaid-nonce' |
924 | 924 | ); |
925 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
926 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
925 | + $message = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing'); |
|
926 | + $message2 = __('Generate Pages', 'invoicing'); |
|
927 | 927 | echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
928 | 928 | break; |
929 | 929 | } |
@@ -18,691 +18,691 @@ |
||
18 | 18 | */ |
19 | 19 | class GetPaid_REST_Report_Sales_Controller extends GetPaid_REST_Date_Based_Controller { |
20 | 20 | |
21 | - /** |
|
22 | - * Route base. |
|
23 | - * |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $rest_base = 'reports/sales'; |
|
27 | - |
|
28 | - /** |
|
29 | - * The report data. |
|
30 | - * |
|
31 | - * @var stdClass |
|
32 | - */ |
|
33 | - public $report_data; |
|
34 | - |
|
35 | - /** |
|
36 | - * The report range. |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - public $report_range; |
|
41 | - |
|
42 | - /** |
|
43 | - * Registers the routes for the objects of the controller. |
|
44 | - * |
|
45 | - * @since 2.0.0 |
|
46 | - * |
|
47 | - * @see register_rest_route() |
|
48 | - */ |
|
49 | - public function register_namespace_routes( $namespace ) { |
|
50 | - |
|
51 | - // Get sales report. |
|
52 | - register_rest_route( |
|
53 | - $namespace, |
|
54 | - $this->rest_base, |
|
55 | - array( |
|
56 | - array( |
|
57 | - 'methods' => WP_REST_Server::READABLE, |
|
58 | - 'callback' => array( $this, 'get_items' ), |
|
59 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
60 | - 'args' => $this->get_collection_params(), |
|
61 | - ), |
|
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
63 | - ) |
|
64 | - ); |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Makes sure the current user has access to READ the report APIs. |
|
70 | - * |
|
71 | - * @since 2.0.0 |
|
72 | - * @param WP_REST_Request $request Full data about the request. |
|
73 | - * @return WP_Error|boolean |
|
74 | - */ |
|
75 | - public function get_items_permissions_check( $request ) { |
|
76 | - |
|
77 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
78 | - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
79 | - } |
|
80 | - |
|
81 | - return true; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get sales reports. |
|
86 | - * |
|
87 | - * @param WP_REST_Request $request |
|
88 | - * @return array|WP_Error |
|
89 | - */ |
|
90 | - public function get_items( $request ) { |
|
91 | - $data = array(); |
|
92 | - $item = $this->prepare_item_for_response( null, $request ); |
|
93 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
94 | - |
|
95 | - return rest_ensure_response( $data ); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Prepare a report sales object for serialization. |
|
100 | - * |
|
101 | - * @param null $_ |
|
102 | - * @param WP_REST_Request $request Request object. |
|
103 | - * @return WP_REST_Response $response Response data. |
|
104 | - */ |
|
105 | - public function prepare_item_for_response( $_, $request ) { |
|
106 | - |
|
107 | - // Set report range. |
|
108 | - $this->report_range = $this->get_date_range( $request ); |
|
109 | - |
|
110 | - $report_data = $this->get_report_data(); |
|
111 | - $period_totals = array(); |
|
112 | - |
|
113 | - // Setup period totals by ensuring each period in the interval has data. |
|
114 | - $start_date = strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS; |
|
115 | - |
|
116 | - if ( 'month' === $this->groupby ) { |
|
117 | - $start_date = strtotime( date( 'Y-m-01', $start_date ) ); |
|
118 | - } |
|
119 | - |
|
120 | - for ( $i = 0; $i < $this->interval; $i++ ) { |
|
121 | - |
|
122 | - switch ( $this->groupby ) { |
|
123 | - case 'day' : |
|
124 | - $time = date( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) ); |
|
125 | - break; |
|
126 | - default : |
|
127 | - $time = date( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) ); |
|
128 | - break; |
|
129 | - } |
|
130 | - |
|
131 | - // Set the defaults for each period. |
|
132 | - $period_totals[ $time ] = array( |
|
133 | - 'invoices' => 0, |
|
134 | - 'items' => 0, |
|
135 | - 'refunded_items' => 0, |
|
136 | - 'refunded_tax' => wpinv_round_amount( 0.00 ), |
|
137 | - 'subtotal' => wpinv_round_amount( 0.00 ), |
|
138 | - 'refunded_subtotal' => wpinv_round_amount( 0.00 ), |
|
139 | - 'refunded_fees' => wpinv_round_amount( 0.00 ), |
|
140 | - 'discount' => wpinv_round_amount( 0.00 ), |
|
141 | - ); |
|
142 | - |
|
143 | - foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
144 | - if ( ! isset( $period_totals[ $time ][ $key ] ) ) { |
|
145 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 ); |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - } |
|
150 | - |
|
151 | - // add total sales, total invoice count, total tax for each period |
|
152 | - $date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m'; |
|
153 | - foreach ( $report_data->invoices as $invoice ) { |
|
154 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
155 | - |
|
156 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
157 | - continue; |
|
158 | - } |
|
159 | - |
|
160 | - $period_totals[ $time ]['sales'] = wpinv_round_amount( $invoice->total_sales ); |
|
161 | - $period_totals[ $time ]['tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
162 | - $period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
163 | - $period_totals[ $time ]['fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - foreach ( $report_data->refunds as $invoice ) { |
|
168 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
169 | - |
|
170 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
171 | - continue; |
|
172 | - } |
|
173 | - |
|
174 | - $period_totals[ $time ]['refunds'] = wpinv_round_amount( $invoice->total_sales ); |
|
175 | - $period_totals[ $time ]['refunded_tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
176 | - $period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
177 | - $period_totals[ $time ]['refunded_fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
178 | - |
|
179 | - } |
|
180 | - |
|
181 | - foreach ( $report_data->invoice_counts as $invoice ) { |
|
182 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
183 | - |
|
184 | - if ( isset( $period_totals[ $time ] ) ) { |
|
185 | - $period_totals[ $time ]['invoices'] = (int) $invoice->count; |
|
186 | - } |
|
187 | - |
|
188 | - } |
|
189 | - |
|
190 | - // Add total invoice items for each period. |
|
191 | - foreach ( $report_data->invoice_items as $invoice_item ) { |
|
192 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : date( 'Y-m', strtotime( $invoice_item->post_date ) ); |
|
193 | - |
|
194 | - if ( isset( $period_totals[ $time ] ) ) { |
|
195 | - $period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count; |
|
196 | - } |
|
197 | - |
|
198 | - } |
|
199 | - |
|
200 | - // Add total discount for each period. |
|
201 | - foreach ( $report_data->coupons as $discount ) { |
|
202 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $discount->post_date ) ) : date( 'Y-m', strtotime( $discount->post_date ) ); |
|
203 | - |
|
204 | - if ( isset( $period_totals[ $time ] ) ) { |
|
205 | - $period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount ); |
|
206 | - } |
|
207 | - |
|
208 | - } |
|
209 | - |
|
210 | - // Extra fields. |
|
211 | - foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
212 | - |
|
213 | - // Abort unprepared. |
|
214 | - if ( ! isset( $report_data->$key ) ) { |
|
215 | - continue; |
|
216 | - } |
|
217 | - |
|
218 | - // Abort defaults. |
|
219 | - if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) { |
|
220 | - continue; |
|
221 | - } |
|
222 | - |
|
223 | - // Set values. |
|
224 | - foreach ( $report_data->$key as $item ) { |
|
225 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $item->date ) ) : date( 'Y-m', strtotime( $item->date ) ); |
|
226 | - |
|
227 | - if ( isset( $period_totals[ $time ] ) ) { |
|
228 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val ); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - unset( $report_data->$key ); |
|
233 | - } |
|
234 | - |
|
235 | - $report_data->totals = $period_totals; |
|
236 | - $report_data->grouped_by = $this->groupby; |
|
237 | - $report_data->interval = max( $this->interval, 1 ); |
|
238 | - $report_data->currency = wpinv_get_currency(); |
|
239 | - $report_data->currency_symbol = wpinv_currency_symbol(); |
|
240 | - $report_data->currency_position = wpinv_currency_position(); |
|
241 | - $report_data->decimal_places = wpinv_decimals(); |
|
242 | - $report_data->thousands_sep = wpinv_thousands_separator(); |
|
243 | - $report_data->decimals_sep = wpinv_decimal_separator(); |
|
244 | - $report_data->start_date = date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ); |
|
245 | - $report_data->end_date = date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ); |
|
246 | - $report_data->start_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ) ); |
|
247 | - $report_data->end_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ) ); |
|
248 | - $report_data->decimals_sep = wpinv_decimal_separator(); |
|
249 | - |
|
250 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
251 | - $data = $report_data; |
|
252 | - unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items ); |
|
253 | - $data = $this->add_additional_fields_to_object( (array) $data, $request ); |
|
254 | - $data = $this->filter_response_by_context( $data, $context ); |
|
255 | - |
|
256 | - // Wrap the data in a response object. |
|
257 | - $response = rest_ensure_response( $data ); |
|
258 | - $response->add_links( array( |
|
259 | - 'about' => array( |
|
260 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
261 | - ), |
|
262 | - ) ); |
|
263 | - |
|
264 | - return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request ); |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Get report data. |
|
269 | - * |
|
270 | - * @return stdClass |
|
271 | - */ |
|
272 | - public function get_report_data() { |
|
273 | - if ( empty( $this->report_data ) ) { |
|
274 | - $this->query_report_data(); |
|
275 | - } |
|
276 | - return $this->report_data; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Get all data needed for this report and store in the class. |
|
281 | - */ |
|
282 | - protected function query_report_data() { |
|
283 | - |
|
284 | - // Prepare reports. |
|
285 | - $this->report_data = (object) array( |
|
286 | - 'invoice_counts' => $this->query_invoice_counts(),//count, post_date |
|
287 | - 'coupons' => $this->query_coupon_counts(), // discount_amount, post_date |
|
288 | - 'invoice_items' => $this->query_item_counts(), // invoice_item_count, post_date |
|
289 | - 'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date |
|
290 | - 'invoices' => $this->query_invoice_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
291 | - 'refunds' => $this->query_refunded_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
292 | - 'previous_range' => $this->previous_range, |
|
293 | - ); |
|
294 | - |
|
295 | - // Calculated totals. |
|
296 | - $this->report_data->total_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) ); |
|
297 | - $this->report_data->total_sales = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) ); |
|
298 | - $this->report_data->total_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) ); |
|
299 | - $this->report_data->total_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) ); |
|
300 | - $this->report_data->subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) ); |
|
301 | - $this->report_data->net_sales = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) ); |
|
302 | - $this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) ); |
|
303 | - $this->report_data->total_refunds = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) ); |
|
304 | - $this->report_data->refunded_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) ); |
|
305 | - $this->report_data->refunded_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) ); |
|
306 | - $this->report_data->refunded_subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) ); |
|
307 | - $this->report_data->net_refunds = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) ); |
|
308 | - |
|
309 | - |
|
310 | - // Calculate average based on net. |
|
311 | - $this->report_data->average_sales = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 ); |
|
312 | - $this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 ); |
|
313 | - |
|
314 | - // Total invoices in this period, even if refunded. |
|
315 | - $this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) ); |
|
316 | - |
|
317 | - // Items invoiced in this period, even if refunded. |
|
318 | - $this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) ); |
|
319 | - |
|
320 | - // 3rd party filtering of report data |
|
321 | - $this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this ); |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Prepares invoice counts. |
|
326 | - * |
|
327 | - * @return array. |
|
328 | - */ |
|
329 | - protected function query_invoice_counts() { |
|
330 | - |
|
331 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
332 | - array( |
|
333 | - 'data' => array( |
|
334 | - 'ID' => array( |
|
335 | - 'type' => 'post_data', |
|
336 | - 'function' => 'COUNT', |
|
337 | - 'name' => 'count', |
|
338 | - 'distinct' => true, |
|
339 | - ), |
|
340 | - 'post_date' => array( |
|
341 | - 'type' => 'post_data', |
|
342 | - 'function' => '', |
|
343 | - 'name' => 'post_date', |
|
344 | - ), |
|
345 | - ), |
|
346 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
347 | - 'order_by' => 'post_date ASC', |
|
348 | - 'query_type' => 'get_results', |
|
349 | - 'filter_range' => $this->report_range, |
|
350 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
351 | - ) |
|
352 | - ); |
|
353 | - |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Prepares coupon counts. |
|
358 | - * |
|
359 | - * @return array. |
|
360 | - */ |
|
361 | - protected function query_coupon_counts() { |
|
362 | - |
|
363 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
364 | - array( |
|
365 | - 'data' => array( |
|
366 | - 'discount' => array( |
|
367 | - 'type' => 'invoice_data', |
|
368 | - 'function' => 'SUM', |
|
369 | - 'name' => 'discount_amount', |
|
370 | - ), |
|
371 | - 'post_date' => array( |
|
372 | - 'type' => 'post_data', |
|
373 | - 'function' => '', |
|
374 | - 'name' => 'post_date', |
|
375 | - ), |
|
376 | - ), |
|
377 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
378 | - 'order_by' => 'post_date ASC', |
|
379 | - 'query_type' => 'get_results', |
|
380 | - 'filter_range' => $this->report_range, |
|
381 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
382 | - ) |
|
383 | - ); |
|
384 | - |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Prepares item counts. |
|
389 | - * |
|
390 | - * @return array. |
|
391 | - */ |
|
392 | - protected function query_item_counts() { |
|
393 | - |
|
394 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
395 | - array( |
|
396 | - 'data' => array( |
|
397 | - 'quantity' => array( |
|
398 | - 'type' => 'invoice_item', |
|
399 | - 'function' => 'SUM', |
|
400 | - 'name' => 'invoice_item_count', |
|
401 | - ), |
|
402 | - 'post_date' => array( |
|
403 | - 'type' => 'post_data', |
|
404 | - 'function' => '', |
|
405 | - 'name' => 'post_date', |
|
406 | - ), |
|
407 | - ), |
|
408 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
409 | - 'order_by' => 'post_date ASC', |
|
410 | - 'query_type' => 'get_results', |
|
411 | - 'filter_range' => $this->report_range, |
|
412 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
413 | - ) |
|
414 | - ); |
|
415 | - |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * Prepares refunded item counts. |
|
420 | - * |
|
421 | - * @return array. |
|
422 | - */ |
|
423 | - protected function count_refunded_items() { |
|
424 | - |
|
425 | - return (int) GetPaid_Reports_Helper::get_invoice_report_data( |
|
426 | - array( |
|
427 | - 'data' => array( |
|
428 | - 'quantity' => array( |
|
429 | - 'type' => 'invoice_item', |
|
430 | - 'function' => 'SUM', |
|
431 | - 'name' => 'invoice_item_count', |
|
432 | - ), |
|
433 | - ), |
|
434 | - 'query_type' => 'get_var', |
|
435 | - 'filter_range' => $this->report_range, |
|
436 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
437 | - ) |
|
438 | - ); |
|
439 | - |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Prepares daily invoice totals. |
|
444 | - * |
|
445 | - * @return array. |
|
446 | - */ |
|
447 | - protected function query_invoice_totals() { |
|
448 | - |
|
449 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
450 | - array( |
|
451 | - 'data' => array( |
|
452 | - 'total' => array( |
|
453 | - 'type' => 'invoice_data', |
|
454 | - 'function' => 'SUM', |
|
455 | - 'name' => 'total_sales', |
|
456 | - ), |
|
457 | - 'tax' => array( |
|
458 | - 'type' => 'invoice_data', |
|
459 | - 'function' => 'SUM', |
|
460 | - 'name' => 'total_tax', |
|
461 | - ), |
|
462 | - 'discount' => array( |
|
463 | - 'type' => 'invoice_data', |
|
464 | - 'function' => 'SUM', |
|
465 | - 'name' => 'total_discount', |
|
466 | - ), |
|
467 | - 'fees_total' => array( |
|
468 | - 'type' => 'invoice_data', |
|
469 | - 'function' => 'SUM', |
|
470 | - 'name' => 'total_fees', |
|
471 | - ), |
|
472 | - 'subtotal' => array( |
|
473 | - 'type' => 'invoice_data', |
|
474 | - 'function' => 'SUM', |
|
475 | - 'name' => 'subtotal', |
|
476 | - ), |
|
477 | - 'post_date' => array( |
|
478 | - 'type' => 'post_data', |
|
479 | - 'function' => '', |
|
480 | - 'name' => 'post_date', |
|
481 | - ), |
|
482 | - ), |
|
483 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
484 | - 'order_by' => 'post_date ASC', |
|
485 | - 'query_type' => 'get_results', |
|
486 | - 'filter_range' => $this->report_range, |
|
487 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ), |
|
488 | - ) |
|
489 | - ); |
|
490 | - |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Prepares daily invoice totals. |
|
495 | - * |
|
496 | - * @return array. |
|
497 | - */ |
|
498 | - protected function query_refunded_totals() { |
|
499 | - |
|
500 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
501 | - array( |
|
502 | - 'data' => array( |
|
503 | - 'total' => array( |
|
504 | - 'type' => 'invoice_data', |
|
505 | - 'function' => 'SUM', |
|
506 | - 'name' => 'total_sales', |
|
507 | - ), |
|
508 | - 'tax' => array( |
|
509 | - 'type' => 'invoice_data', |
|
510 | - 'function' => 'SUM', |
|
511 | - 'name' => 'total_tax', |
|
512 | - ), |
|
513 | - 'discount' => array( |
|
514 | - 'type' => 'invoice_data', |
|
515 | - 'function' => 'SUM', |
|
516 | - 'name' => 'total_discount', |
|
517 | - ), |
|
518 | - 'fees_total' => array( |
|
519 | - 'type' => 'invoice_data', |
|
520 | - 'function' => 'SUM', |
|
521 | - 'name' => 'total_fees', |
|
522 | - ), |
|
523 | - 'subtotal' => array( |
|
524 | - 'type' => 'invoice_data', |
|
525 | - 'function' => 'SUM', |
|
526 | - 'name' => 'subtotal', |
|
527 | - ), |
|
528 | - 'post_date' => array( |
|
529 | - 'type' => 'post_data', |
|
530 | - 'function' => '', |
|
531 | - 'name' => 'post_date', |
|
532 | - ), |
|
533 | - ), |
|
534 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
535 | - 'order_by' => 'post_date ASC', |
|
536 | - 'query_type' => 'get_results', |
|
537 | - 'filter_range' => $this->report_range, |
|
538 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
539 | - ) |
|
540 | - ); |
|
541 | - |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * Get the Report's schema, conforming to JSON Schema. |
|
546 | - * |
|
547 | - * @return array |
|
548 | - */ |
|
549 | - public function get_item_schema() { |
|
550 | - |
|
551 | - $schema = array( |
|
552 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
553 | - 'title' => 'sales_report', |
|
554 | - 'type' => 'object', |
|
555 | - 'properties' => array( |
|
556 | - 'total_sales' => array( |
|
557 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
558 | - 'type' => 'string', |
|
559 | - 'context' => array( 'view' ), |
|
560 | - 'readonly' => true, |
|
561 | - ), |
|
562 | - 'net_sales' => array( |
|
563 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
564 | - 'type' => 'string', |
|
565 | - 'context' => array( 'view' ), |
|
566 | - 'readonly' => true, |
|
567 | - ), |
|
568 | - 'average_sales' => array( |
|
569 | - 'description' => __( 'Average net daily sales.', 'invoicing' ), |
|
570 | - 'type' => 'string', |
|
571 | - 'context' => array( 'view' ), |
|
572 | - 'readonly' => true, |
|
573 | - ), |
|
574 | - 'average_total_sales' => array( |
|
575 | - 'description' => __( 'Average gross daily sales.', 'invoicing' ), |
|
576 | - 'type' => 'string', |
|
577 | - 'context' => array( 'view' ), |
|
578 | - 'readonly' => true, |
|
579 | - ), |
|
580 | - 'total_invoices' => array( |
|
581 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
582 | - 'type' => 'integer', |
|
583 | - 'context' => array( 'view' ), |
|
584 | - 'readonly' => true, |
|
585 | - ), |
|
586 | - 'total_items' => array( |
|
587 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
588 | - 'type' => 'integer', |
|
589 | - 'context' => array( 'view' ), |
|
590 | - 'readonly' => true, |
|
591 | - ), |
|
592 | - 'refunded_items' => array( |
|
593 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
594 | - 'type' => 'integer', |
|
595 | - 'context' => array( 'view' ), |
|
596 | - 'readonly' => true, |
|
597 | - ), |
|
598 | - 'total_tax' => array( |
|
599 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
600 | - 'type' => 'string', |
|
601 | - 'context' => array( 'view' ), |
|
602 | - 'readonly' => true, |
|
603 | - ), |
|
604 | - 'total_refunded_tax' => array( |
|
605 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
606 | - 'type' => 'string', |
|
607 | - 'context' => array( 'view' ), |
|
608 | - 'readonly' => true, |
|
609 | - ), |
|
610 | - 'total_fees' => array( |
|
611 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
612 | - 'type' => 'string', |
|
613 | - 'context' => array( 'view' ), |
|
614 | - 'readonly' => true, |
|
615 | - ), |
|
616 | - 'total_refunds' => array( |
|
617 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
618 | - 'type' => 'integer', |
|
619 | - 'context' => array( 'view' ), |
|
620 | - 'readonly' => true, |
|
621 | - ), |
|
622 | - 'net_refunds' => array( |
|
623 | - 'description' => __( 'Net of refunded invoices.', 'invoicing' ), |
|
624 | - 'type' => 'integer', |
|
625 | - 'context' => array( 'view' ), |
|
626 | - 'readonly' => true, |
|
627 | - ), |
|
628 | - 'total_discount' => array( |
|
629 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
630 | - 'type' => 'integer', |
|
631 | - 'context' => array( 'view' ), |
|
632 | - 'readonly' => true, |
|
633 | - ), |
|
634 | - 'totals' => array( |
|
635 | - 'description' => __( 'Totals.', 'invoicing' ), |
|
636 | - 'type' => 'array', |
|
637 | - 'items' => array( |
|
638 | - 'type' => 'array', |
|
639 | - ), |
|
640 | - 'context' => array( 'view' ), |
|
641 | - 'readonly' => true, |
|
642 | - ), |
|
643 | - 'interval' => array( |
|
644 | - 'description' => __( 'Number of months/days in the report period.', 'invoicing' ), |
|
645 | - 'type' => 'integer', |
|
646 | - 'context' => array( 'view' ), |
|
647 | - 'readonly' => true, |
|
648 | - ), |
|
649 | - 'previous_range' => array( |
|
650 | - 'description' => __( 'The previous report period.', 'invoicing' ), |
|
651 | - 'type' => 'array', |
|
652 | - 'items' => array( |
|
653 | - 'type' => 'string', |
|
654 | - ), |
|
655 | - 'context' => array( 'view' ), |
|
656 | - 'readonly' => true, |
|
657 | - ), |
|
658 | - 'grouped_by' => array( |
|
659 | - 'description' => __( 'The period used to group the totals.', 'invoicing' ), |
|
660 | - 'type' => 'string', |
|
661 | - 'context' => array( 'view' ), |
|
662 | - 'enum' => array( 'day', 'month' ), |
|
663 | - 'readonly' => true, |
|
664 | - ), |
|
665 | - 'currency' => array( |
|
666 | - 'description' => __( 'The default store currency.', 'invoicing' ), |
|
667 | - 'type' => 'string', |
|
668 | - 'context' => array( 'view' ), |
|
669 | - 'readonly' => true, |
|
670 | - ), |
|
671 | - 'currency_symbol' => array( |
|
672 | - 'description' => __( 'The default store currency symbol.', 'invoicing' ), |
|
673 | - 'type' => 'string', |
|
674 | - 'context' => array( 'view' ), |
|
675 | - 'readonly' => true, |
|
676 | - ), |
|
677 | - 'currency_position' => array( |
|
678 | - 'description' => __( 'The default store currency position.', 'invoicing' ), |
|
679 | - 'type' => 'string', |
|
680 | - 'context' => array( 'view' ), |
|
681 | - 'readonly' => true, |
|
682 | - ), |
|
683 | - 'decimal_places' => array( |
|
684 | - 'description' => __( 'The default store decimal places.', 'invoicing' ), |
|
685 | - 'type' => 'string', |
|
686 | - 'context' => array( 'view' ), |
|
687 | - 'readonly' => true, |
|
688 | - ), |
|
689 | - 'thousands_sep' => array( |
|
690 | - 'description' => __( 'The default store thousands separator.', 'invoicing' ), |
|
691 | - 'type' => 'string', |
|
692 | - 'context' => array( 'view' ), |
|
693 | - 'readonly' => true, |
|
694 | - ), |
|
695 | - 'decimals_sep' => array( |
|
696 | - 'description' => __( 'The default store decimals separator.', 'invoicing' ), |
|
697 | - 'type' => 'string', |
|
698 | - 'context' => array( 'view' ), |
|
699 | - 'readonly' => true, |
|
700 | - ), |
|
701 | - ), |
|
702 | - ); |
|
703 | - |
|
704 | - return $this->add_additional_fields_schema( $schema ); |
|
705 | - |
|
706 | - } |
|
21 | + /** |
|
22 | + * Route base. |
|
23 | + * |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $rest_base = 'reports/sales'; |
|
27 | + |
|
28 | + /** |
|
29 | + * The report data. |
|
30 | + * |
|
31 | + * @var stdClass |
|
32 | + */ |
|
33 | + public $report_data; |
|
34 | + |
|
35 | + /** |
|
36 | + * The report range. |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + public $report_range; |
|
41 | + |
|
42 | + /** |
|
43 | + * Registers the routes for the objects of the controller. |
|
44 | + * |
|
45 | + * @since 2.0.0 |
|
46 | + * |
|
47 | + * @see register_rest_route() |
|
48 | + */ |
|
49 | + public function register_namespace_routes( $namespace ) { |
|
50 | + |
|
51 | + // Get sales report. |
|
52 | + register_rest_route( |
|
53 | + $namespace, |
|
54 | + $this->rest_base, |
|
55 | + array( |
|
56 | + array( |
|
57 | + 'methods' => WP_REST_Server::READABLE, |
|
58 | + 'callback' => array( $this, 'get_items' ), |
|
59 | + 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
60 | + 'args' => $this->get_collection_params(), |
|
61 | + ), |
|
62 | + 'schema' => array( $this, 'get_public_item_schema' ), |
|
63 | + ) |
|
64 | + ); |
|
65 | + |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Makes sure the current user has access to READ the report APIs. |
|
70 | + * |
|
71 | + * @since 2.0.0 |
|
72 | + * @param WP_REST_Request $request Full data about the request. |
|
73 | + * @return WP_Error|boolean |
|
74 | + */ |
|
75 | + public function get_items_permissions_check( $request ) { |
|
76 | + |
|
77 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
78 | + return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
79 | + } |
|
80 | + |
|
81 | + return true; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get sales reports. |
|
86 | + * |
|
87 | + * @param WP_REST_Request $request |
|
88 | + * @return array|WP_Error |
|
89 | + */ |
|
90 | + public function get_items( $request ) { |
|
91 | + $data = array(); |
|
92 | + $item = $this->prepare_item_for_response( null, $request ); |
|
93 | + $data[] = $this->prepare_response_for_collection( $item ); |
|
94 | + |
|
95 | + return rest_ensure_response( $data ); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Prepare a report sales object for serialization. |
|
100 | + * |
|
101 | + * @param null $_ |
|
102 | + * @param WP_REST_Request $request Request object. |
|
103 | + * @return WP_REST_Response $response Response data. |
|
104 | + */ |
|
105 | + public function prepare_item_for_response( $_, $request ) { |
|
106 | + |
|
107 | + // Set report range. |
|
108 | + $this->report_range = $this->get_date_range( $request ); |
|
109 | + |
|
110 | + $report_data = $this->get_report_data(); |
|
111 | + $period_totals = array(); |
|
112 | + |
|
113 | + // Setup period totals by ensuring each period in the interval has data. |
|
114 | + $start_date = strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS; |
|
115 | + |
|
116 | + if ( 'month' === $this->groupby ) { |
|
117 | + $start_date = strtotime( date( 'Y-m-01', $start_date ) ); |
|
118 | + } |
|
119 | + |
|
120 | + for ( $i = 0; $i < $this->interval; $i++ ) { |
|
121 | + |
|
122 | + switch ( $this->groupby ) { |
|
123 | + case 'day' : |
|
124 | + $time = date( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) ); |
|
125 | + break; |
|
126 | + default : |
|
127 | + $time = date( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) ); |
|
128 | + break; |
|
129 | + } |
|
130 | + |
|
131 | + // Set the defaults for each period. |
|
132 | + $period_totals[ $time ] = array( |
|
133 | + 'invoices' => 0, |
|
134 | + 'items' => 0, |
|
135 | + 'refunded_items' => 0, |
|
136 | + 'refunded_tax' => wpinv_round_amount( 0.00 ), |
|
137 | + 'subtotal' => wpinv_round_amount( 0.00 ), |
|
138 | + 'refunded_subtotal' => wpinv_round_amount( 0.00 ), |
|
139 | + 'refunded_fees' => wpinv_round_amount( 0.00 ), |
|
140 | + 'discount' => wpinv_round_amount( 0.00 ), |
|
141 | + ); |
|
142 | + |
|
143 | + foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
144 | + if ( ! isset( $period_totals[ $time ][ $key ] ) ) { |
|
145 | + $period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 ); |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + } |
|
150 | + |
|
151 | + // add total sales, total invoice count, total tax for each period |
|
152 | + $date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m'; |
|
153 | + foreach ( $report_data->invoices as $invoice ) { |
|
154 | + $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
155 | + |
|
156 | + if ( ! isset( $period_totals[ $time ] ) ) { |
|
157 | + continue; |
|
158 | + } |
|
159 | + |
|
160 | + $period_totals[ $time ]['sales'] = wpinv_round_amount( $invoice->total_sales ); |
|
161 | + $period_totals[ $time ]['tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
162 | + $period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
163 | + $period_totals[ $time ]['fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + foreach ( $report_data->refunds as $invoice ) { |
|
168 | + $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
169 | + |
|
170 | + if ( ! isset( $period_totals[ $time ] ) ) { |
|
171 | + continue; |
|
172 | + } |
|
173 | + |
|
174 | + $period_totals[ $time ]['refunds'] = wpinv_round_amount( $invoice->total_sales ); |
|
175 | + $period_totals[ $time ]['refunded_tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
176 | + $period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
177 | + $period_totals[ $time ]['refunded_fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
178 | + |
|
179 | + } |
|
180 | + |
|
181 | + foreach ( $report_data->invoice_counts as $invoice ) { |
|
182 | + $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
183 | + |
|
184 | + if ( isset( $period_totals[ $time ] ) ) { |
|
185 | + $period_totals[ $time ]['invoices'] = (int) $invoice->count; |
|
186 | + } |
|
187 | + |
|
188 | + } |
|
189 | + |
|
190 | + // Add total invoice items for each period. |
|
191 | + foreach ( $report_data->invoice_items as $invoice_item ) { |
|
192 | + $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : date( 'Y-m', strtotime( $invoice_item->post_date ) ); |
|
193 | + |
|
194 | + if ( isset( $period_totals[ $time ] ) ) { |
|
195 | + $period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count; |
|
196 | + } |
|
197 | + |
|
198 | + } |
|
199 | + |
|
200 | + // Add total discount for each period. |
|
201 | + foreach ( $report_data->coupons as $discount ) { |
|
202 | + $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $discount->post_date ) ) : date( 'Y-m', strtotime( $discount->post_date ) ); |
|
203 | + |
|
204 | + if ( isset( $period_totals[ $time ] ) ) { |
|
205 | + $period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount ); |
|
206 | + } |
|
207 | + |
|
208 | + } |
|
209 | + |
|
210 | + // Extra fields. |
|
211 | + foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
212 | + |
|
213 | + // Abort unprepared. |
|
214 | + if ( ! isset( $report_data->$key ) ) { |
|
215 | + continue; |
|
216 | + } |
|
217 | + |
|
218 | + // Abort defaults. |
|
219 | + if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) { |
|
220 | + continue; |
|
221 | + } |
|
222 | + |
|
223 | + // Set values. |
|
224 | + foreach ( $report_data->$key as $item ) { |
|
225 | + $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $item->date ) ) : date( 'Y-m', strtotime( $item->date ) ); |
|
226 | + |
|
227 | + if ( isset( $period_totals[ $time ] ) ) { |
|
228 | + $period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val ); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + unset( $report_data->$key ); |
|
233 | + } |
|
234 | + |
|
235 | + $report_data->totals = $period_totals; |
|
236 | + $report_data->grouped_by = $this->groupby; |
|
237 | + $report_data->interval = max( $this->interval, 1 ); |
|
238 | + $report_data->currency = wpinv_get_currency(); |
|
239 | + $report_data->currency_symbol = wpinv_currency_symbol(); |
|
240 | + $report_data->currency_position = wpinv_currency_position(); |
|
241 | + $report_data->decimal_places = wpinv_decimals(); |
|
242 | + $report_data->thousands_sep = wpinv_thousands_separator(); |
|
243 | + $report_data->decimals_sep = wpinv_decimal_separator(); |
|
244 | + $report_data->start_date = date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ); |
|
245 | + $report_data->end_date = date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ); |
|
246 | + $report_data->start_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ) ); |
|
247 | + $report_data->end_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ) ); |
|
248 | + $report_data->decimals_sep = wpinv_decimal_separator(); |
|
249 | + |
|
250 | + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
251 | + $data = $report_data; |
|
252 | + unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items ); |
|
253 | + $data = $this->add_additional_fields_to_object( (array) $data, $request ); |
|
254 | + $data = $this->filter_response_by_context( $data, $context ); |
|
255 | + |
|
256 | + // Wrap the data in a response object. |
|
257 | + $response = rest_ensure_response( $data ); |
|
258 | + $response->add_links( array( |
|
259 | + 'about' => array( |
|
260 | + 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
261 | + ), |
|
262 | + ) ); |
|
263 | + |
|
264 | + return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request ); |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Get report data. |
|
269 | + * |
|
270 | + * @return stdClass |
|
271 | + */ |
|
272 | + public function get_report_data() { |
|
273 | + if ( empty( $this->report_data ) ) { |
|
274 | + $this->query_report_data(); |
|
275 | + } |
|
276 | + return $this->report_data; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Get all data needed for this report and store in the class. |
|
281 | + */ |
|
282 | + protected function query_report_data() { |
|
283 | + |
|
284 | + // Prepare reports. |
|
285 | + $this->report_data = (object) array( |
|
286 | + 'invoice_counts' => $this->query_invoice_counts(),//count, post_date |
|
287 | + 'coupons' => $this->query_coupon_counts(), // discount_amount, post_date |
|
288 | + 'invoice_items' => $this->query_item_counts(), // invoice_item_count, post_date |
|
289 | + 'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date |
|
290 | + 'invoices' => $this->query_invoice_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
291 | + 'refunds' => $this->query_refunded_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
292 | + 'previous_range' => $this->previous_range, |
|
293 | + ); |
|
294 | + |
|
295 | + // Calculated totals. |
|
296 | + $this->report_data->total_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) ); |
|
297 | + $this->report_data->total_sales = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) ); |
|
298 | + $this->report_data->total_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) ); |
|
299 | + $this->report_data->total_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) ); |
|
300 | + $this->report_data->subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) ); |
|
301 | + $this->report_data->net_sales = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) ); |
|
302 | + $this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) ); |
|
303 | + $this->report_data->total_refunds = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) ); |
|
304 | + $this->report_data->refunded_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) ); |
|
305 | + $this->report_data->refunded_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) ); |
|
306 | + $this->report_data->refunded_subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) ); |
|
307 | + $this->report_data->net_refunds = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) ); |
|
308 | + |
|
309 | + |
|
310 | + // Calculate average based on net. |
|
311 | + $this->report_data->average_sales = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 ); |
|
312 | + $this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 ); |
|
313 | + |
|
314 | + // Total invoices in this period, even if refunded. |
|
315 | + $this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) ); |
|
316 | + |
|
317 | + // Items invoiced in this period, even if refunded. |
|
318 | + $this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) ); |
|
319 | + |
|
320 | + // 3rd party filtering of report data |
|
321 | + $this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this ); |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Prepares invoice counts. |
|
326 | + * |
|
327 | + * @return array. |
|
328 | + */ |
|
329 | + protected function query_invoice_counts() { |
|
330 | + |
|
331 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
332 | + array( |
|
333 | + 'data' => array( |
|
334 | + 'ID' => array( |
|
335 | + 'type' => 'post_data', |
|
336 | + 'function' => 'COUNT', |
|
337 | + 'name' => 'count', |
|
338 | + 'distinct' => true, |
|
339 | + ), |
|
340 | + 'post_date' => array( |
|
341 | + 'type' => 'post_data', |
|
342 | + 'function' => '', |
|
343 | + 'name' => 'post_date', |
|
344 | + ), |
|
345 | + ), |
|
346 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
347 | + 'order_by' => 'post_date ASC', |
|
348 | + 'query_type' => 'get_results', |
|
349 | + 'filter_range' => $this->report_range, |
|
350 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
351 | + ) |
|
352 | + ); |
|
353 | + |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Prepares coupon counts. |
|
358 | + * |
|
359 | + * @return array. |
|
360 | + */ |
|
361 | + protected function query_coupon_counts() { |
|
362 | + |
|
363 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
364 | + array( |
|
365 | + 'data' => array( |
|
366 | + 'discount' => array( |
|
367 | + 'type' => 'invoice_data', |
|
368 | + 'function' => 'SUM', |
|
369 | + 'name' => 'discount_amount', |
|
370 | + ), |
|
371 | + 'post_date' => array( |
|
372 | + 'type' => 'post_data', |
|
373 | + 'function' => '', |
|
374 | + 'name' => 'post_date', |
|
375 | + ), |
|
376 | + ), |
|
377 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
378 | + 'order_by' => 'post_date ASC', |
|
379 | + 'query_type' => 'get_results', |
|
380 | + 'filter_range' => $this->report_range, |
|
381 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
382 | + ) |
|
383 | + ); |
|
384 | + |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Prepares item counts. |
|
389 | + * |
|
390 | + * @return array. |
|
391 | + */ |
|
392 | + protected function query_item_counts() { |
|
393 | + |
|
394 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
395 | + array( |
|
396 | + 'data' => array( |
|
397 | + 'quantity' => array( |
|
398 | + 'type' => 'invoice_item', |
|
399 | + 'function' => 'SUM', |
|
400 | + 'name' => 'invoice_item_count', |
|
401 | + ), |
|
402 | + 'post_date' => array( |
|
403 | + 'type' => 'post_data', |
|
404 | + 'function' => '', |
|
405 | + 'name' => 'post_date', |
|
406 | + ), |
|
407 | + ), |
|
408 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
409 | + 'order_by' => 'post_date ASC', |
|
410 | + 'query_type' => 'get_results', |
|
411 | + 'filter_range' => $this->report_range, |
|
412 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
413 | + ) |
|
414 | + ); |
|
415 | + |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * Prepares refunded item counts. |
|
420 | + * |
|
421 | + * @return array. |
|
422 | + */ |
|
423 | + protected function count_refunded_items() { |
|
424 | + |
|
425 | + return (int) GetPaid_Reports_Helper::get_invoice_report_data( |
|
426 | + array( |
|
427 | + 'data' => array( |
|
428 | + 'quantity' => array( |
|
429 | + 'type' => 'invoice_item', |
|
430 | + 'function' => 'SUM', |
|
431 | + 'name' => 'invoice_item_count', |
|
432 | + ), |
|
433 | + ), |
|
434 | + 'query_type' => 'get_var', |
|
435 | + 'filter_range' => $this->report_range, |
|
436 | + 'invoice_status' => array( 'wpi-refunded' ), |
|
437 | + ) |
|
438 | + ); |
|
439 | + |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Prepares daily invoice totals. |
|
444 | + * |
|
445 | + * @return array. |
|
446 | + */ |
|
447 | + protected function query_invoice_totals() { |
|
448 | + |
|
449 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
450 | + array( |
|
451 | + 'data' => array( |
|
452 | + 'total' => array( |
|
453 | + 'type' => 'invoice_data', |
|
454 | + 'function' => 'SUM', |
|
455 | + 'name' => 'total_sales', |
|
456 | + ), |
|
457 | + 'tax' => array( |
|
458 | + 'type' => 'invoice_data', |
|
459 | + 'function' => 'SUM', |
|
460 | + 'name' => 'total_tax', |
|
461 | + ), |
|
462 | + 'discount' => array( |
|
463 | + 'type' => 'invoice_data', |
|
464 | + 'function' => 'SUM', |
|
465 | + 'name' => 'total_discount', |
|
466 | + ), |
|
467 | + 'fees_total' => array( |
|
468 | + 'type' => 'invoice_data', |
|
469 | + 'function' => 'SUM', |
|
470 | + 'name' => 'total_fees', |
|
471 | + ), |
|
472 | + 'subtotal' => array( |
|
473 | + 'type' => 'invoice_data', |
|
474 | + 'function' => 'SUM', |
|
475 | + 'name' => 'subtotal', |
|
476 | + ), |
|
477 | + 'post_date' => array( |
|
478 | + 'type' => 'post_data', |
|
479 | + 'function' => '', |
|
480 | + 'name' => 'post_date', |
|
481 | + ), |
|
482 | + ), |
|
483 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
484 | + 'order_by' => 'post_date ASC', |
|
485 | + 'query_type' => 'get_results', |
|
486 | + 'filter_range' => $this->report_range, |
|
487 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ), |
|
488 | + ) |
|
489 | + ); |
|
490 | + |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Prepares daily invoice totals. |
|
495 | + * |
|
496 | + * @return array. |
|
497 | + */ |
|
498 | + protected function query_refunded_totals() { |
|
499 | + |
|
500 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
501 | + array( |
|
502 | + 'data' => array( |
|
503 | + 'total' => array( |
|
504 | + 'type' => 'invoice_data', |
|
505 | + 'function' => 'SUM', |
|
506 | + 'name' => 'total_sales', |
|
507 | + ), |
|
508 | + 'tax' => array( |
|
509 | + 'type' => 'invoice_data', |
|
510 | + 'function' => 'SUM', |
|
511 | + 'name' => 'total_tax', |
|
512 | + ), |
|
513 | + 'discount' => array( |
|
514 | + 'type' => 'invoice_data', |
|
515 | + 'function' => 'SUM', |
|
516 | + 'name' => 'total_discount', |
|
517 | + ), |
|
518 | + 'fees_total' => array( |
|
519 | + 'type' => 'invoice_data', |
|
520 | + 'function' => 'SUM', |
|
521 | + 'name' => 'total_fees', |
|
522 | + ), |
|
523 | + 'subtotal' => array( |
|
524 | + 'type' => 'invoice_data', |
|
525 | + 'function' => 'SUM', |
|
526 | + 'name' => 'subtotal', |
|
527 | + ), |
|
528 | + 'post_date' => array( |
|
529 | + 'type' => 'post_data', |
|
530 | + 'function' => '', |
|
531 | + 'name' => 'post_date', |
|
532 | + ), |
|
533 | + ), |
|
534 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
535 | + 'order_by' => 'post_date ASC', |
|
536 | + 'query_type' => 'get_results', |
|
537 | + 'filter_range' => $this->report_range, |
|
538 | + 'invoice_status' => array( 'wpi-refunded' ), |
|
539 | + ) |
|
540 | + ); |
|
541 | + |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Get the Report's schema, conforming to JSON Schema. |
|
546 | + * |
|
547 | + * @return array |
|
548 | + */ |
|
549 | + public function get_item_schema() { |
|
550 | + |
|
551 | + $schema = array( |
|
552 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
553 | + 'title' => 'sales_report', |
|
554 | + 'type' => 'object', |
|
555 | + 'properties' => array( |
|
556 | + 'total_sales' => array( |
|
557 | + 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
558 | + 'type' => 'string', |
|
559 | + 'context' => array( 'view' ), |
|
560 | + 'readonly' => true, |
|
561 | + ), |
|
562 | + 'net_sales' => array( |
|
563 | + 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
564 | + 'type' => 'string', |
|
565 | + 'context' => array( 'view' ), |
|
566 | + 'readonly' => true, |
|
567 | + ), |
|
568 | + 'average_sales' => array( |
|
569 | + 'description' => __( 'Average net daily sales.', 'invoicing' ), |
|
570 | + 'type' => 'string', |
|
571 | + 'context' => array( 'view' ), |
|
572 | + 'readonly' => true, |
|
573 | + ), |
|
574 | + 'average_total_sales' => array( |
|
575 | + 'description' => __( 'Average gross daily sales.', 'invoicing' ), |
|
576 | + 'type' => 'string', |
|
577 | + 'context' => array( 'view' ), |
|
578 | + 'readonly' => true, |
|
579 | + ), |
|
580 | + 'total_invoices' => array( |
|
581 | + 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
582 | + 'type' => 'integer', |
|
583 | + 'context' => array( 'view' ), |
|
584 | + 'readonly' => true, |
|
585 | + ), |
|
586 | + 'total_items' => array( |
|
587 | + 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
588 | + 'type' => 'integer', |
|
589 | + 'context' => array( 'view' ), |
|
590 | + 'readonly' => true, |
|
591 | + ), |
|
592 | + 'refunded_items' => array( |
|
593 | + 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
594 | + 'type' => 'integer', |
|
595 | + 'context' => array( 'view' ), |
|
596 | + 'readonly' => true, |
|
597 | + ), |
|
598 | + 'total_tax' => array( |
|
599 | + 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
600 | + 'type' => 'string', |
|
601 | + 'context' => array( 'view' ), |
|
602 | + 'readonly' => true, |
|
603 | + ), |
|
604 | + 'total_refunded_tax' => array( |
|
605 | + 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
606 | + 'type' => 'string', |
|
607 | + 'context' => array( 'view' ), |
|
608 | + 'readonly' => true, |
|
609 | + ), |
|
610 | + 'total_fees' => array( |
|
611 | + 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
612 | + 'type' => 'string', |
|
613 | + 'context' => array( 'view' ), |
|
614 | + 'readonly' => true, |
|
615 | + ), |
|
616 | + 'total_refunds' => array( |
|
617 | + 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
618 | + 'type' => 'integer', |
|
619 | + 'context' => array( 'view' ), |
|
620 | + 'readonly' => true, |
|
621 | + ), |
|
622 | + 'net_refunds' => array( |
|
623 | + 'description' => __( 'Net of refunded invoices.', 'invoicing' ), |
|
624 | + 'type' => 'integer', |
|
625 | + 'context' => array( 'view' ), |
|
626 | + 'readonly' => true, |
|
627 | + ), |
|
628 | + 'total_discount' => array( |
|
629 | + 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
630 | + 'type' => 'integer', |
|
631 | + 'context' => array( 'view' ), |
|
632 | + 'readonly' => true, |
|
633 | + ), |
|
634 | + 'totals' => array( |
|
635 | + 'description' => __( 'Totals.', 'invoicing' ), |
|
636 | + 'type' => 'array', |
|
637 | + 'items' => array( |
|
638 | + 'type' => 'array', |
|
639 | + ), |
|
640 | + 'context' => array( 'view' ), |
|
641 | + 'readonly' => true, |
|
642 | + ), |
|
643 | + 'interval' => array( |
|
644 | + 'description' => __( 'Number of months/days in the report period.', 'invoicing' ), |
|
645 | + 'type' => 'integer', |
|
646 | + 'context' => array( 'view' ), |
|
647 | + 'readonly' => true, |
|
648 | + ), |
|
649 | + 'previous_range' => array( |
|
650 | + 'description' => __( 'The previous report period.', 'invoicing' ), |
|
651 | + 'type' => 'array', |
|
652 | + 'items' => array( |
|
653 | + 'type' => 'string', |
|
654 | + ), |
|
655 | + 'context' => array( 'view' ), |
|
656 | + 'readonly' => true, |
|
657 | + ), |
|
658 | + 'grouped_by' => array( |
|
659 | + 'description' => __( 'The period used to group the totals.', 'invoicing' ), |
|
660 | + 'type' => 'string', |
|
661 | + 'context' => array( 'view' ), |
|
662 | + 'enum' => array( 'day', 'month' ), |
|
663 | + 'readonly' => true, |
|
664 | + ), |
|
665 | + 'currency' => array( |
|
666 | + 'description' => __( 'The default store currency.', 'invoicing' ), |
|
667 | + 'type' => 'string', |
|
668 | + 'context' => array( 'view' ), |
|
669 | + 'readonly' => true, |
|
670 | + ), |
|
671 | + 'currency_symbol' => array( |
|
672 | + 'description' => __( 'The default store currency symbol.', 'invoicing' ), |
|
673 | + 'type' => 'string', |
|
674 | + 'context' => array( 'view' ), |
|
675 | + 'readonly' => true, |
|
676 | + ), |
|
677 | + 'currency_position' => array( |
|
678 | + 'description' => __( 'The default store currency position.', 'invoicing' ), |
|
679 | + 'type' => 'string', |
|
680 | + 'context' => array( 'view' ), |
|
681 | + 'readonly' => true, |
|
682 | + ), |
|
683 | + 'decimal_places' => array( |
|
684 | + 'description' => __( 'The default store decimal places.', 'invoicing' ), |
|
685 | + 'type' => 'string', |
|
686 | + 'context' => array( 'view' ), |
|
687 | + 'readonly' => true, |
|
688 | + ), |
|
689 | + 'thousands_sep' => array( |
|
690 | + 'description' => __( 'The default store thousands separator.', 'invoicing' ), |
|
691 | + 'type' => 'string', |
|
692 | + 'context' => array( 'view' ), |
|
693 | + 'readonly' => true, |
|
694 | + ), |
|
695 | + 'decimals_sep' => array( |
|
696 | + 'description' => __( 'The default store decimals separator.', 'invoicing' ), |
|
697 | + 'type' => 'string', |
|
698 | + 'context' => array( 'view' ), |
|
699 | + 'readonly' => true, |
|
700 | + ), |
|
701 | + ), |
|
702 | + ); |
|
703 | + |
|
704 | + return $this->add_additional_fields_schema( $schema ); |
|
705 | + |
|
706 | + } |
|
707 | 707 | |
708 | 708 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @since 2.0.0 |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * GetPaid REST reports controller class. |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @see register_rest_route() |
48 | 48 | */ |
49 | - public function register_namespace_routes( $namespace ) { |
|
49 | + public function register_namespace_routes($namespace) { |
|
50 | 50 | |
51 | 51 | // Get sales report. |
52 | 52 | register_rest_route( |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | array( |
56 | 56 | array( |
57 | 57 | 'methods' => WP_REST_Server::READABLE, |
58 | - 'callback' => array( $this, 'get_items' ), |
|
59 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
58 | + 'callback' => array($this, 'get_items'), |
|
59 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
60 | 60 | 'args' => $this->get_collection_params(), |
61 | 61 | ), |
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
63 | 63 | ) |
64 | 64 | ); |
65 | 65 | |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | * @param WP_REST_Request $request Full data about the request. |
73 | 73 | * @return WP_Error|boolean |
74 | 74 | */ |
75 | - public function get_items_permissions_check( $request ) { |
|
75 | + public function get_items_permissions_check($request) { |
|
76 | 76 | |
77 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
78 | - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
77 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
78 | + return new WP_Error('rest_cannot_view', __('Sorry, you cannot list resources.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | return true; |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | * @param WP_REST_Request $request |
88 | 88 | * @return array|WP_Error |
89 | 89 | */ |
90 | - public function get_items( $request ) { |
|
90 | + public function get_items($request) { |
|
91 | 91 | $data = array(); |
92 | - $item = $this->prepare_item_for_response( null, $request ); |
|
93 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
92 | + $item = $this->prepare_item_for_response(null, $request); |
|
93 | + $data[] = $this->prepare_response_for_collection($item); |
|
94 | 94 | |
95 | - return rest_ensure_response( $data ); |
|
95 | + return rest_ensure_response($data); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -102,166 +102,166 @@ discard block |
||
102 | 102 | * @param WP_REST_Request $request Request object. |
103 | 103 | * @return WP_REST_Response $response Response data. |
104 | 104 | */ |
105 | - public function prepare_item_for_response( $_, $request ) { |
|
105 | + public function prepare_item_for_response($_, $request) { |
|
106 | 106 | |
107 | 107 | // Set report range. |
108 | - $this->report_range = $this->get_date_range( $request ); |
|
108 | + $this->report_range = $this->get_date_range($request); |
|
109 | 109 | |
110 | 110 | $report_data = $this->get_report_data(); |
111 | 111 | $period_totals = array(); |
112 | 112 | |
113 | 113 | // Setup period totals by ensuring each period in the interval has data. |
114 | - $start_date = strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS; |
|
114 | + $start_date = strtotime($this->report_range['after']) + DAY_IN_SECONDS; |
|
115 | 115 | |
116 | - if ( 'month' === $this->groupby ) { |
|
117 | - $start_date = strtotime( date( 'Y-m-01', $start_date ) ); |
|
116 | + if ('month' === $this->groupby) { |
|
117 | + $start_date = strtotime(date('Y-m-01', $start_date)); |
|
118 | 118 | } |
119 | 119 | |
120 | - for ( $i = 0; $i < $this->interval; $i++ ) { |
|
120 | + for ($i = 0; $i < $this->interval; $i++) { |
|
121 | 121 | |
122 | - switch ( $this->groupby ) { |
|
122 | + switch ($this->groupby) { |
|
123 | 123 | case 'day' : |
124 | - $time = date( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) ); |
|
124 | + $time = date('Y-m-d', strtotime("+{$i} DAY", $start_date)); |
|
125 | 125 | break; |
126 | 126 | default : |
127 | - $time = date( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) ); |
|
127 | + $time = date('Y-m', strtotime("+{$i} MONTH", $start_date)); |
|
128 | 128 | break; |
129 | 129 | } |
130 | 130 | |
131 | 131 | // Set the defaults for each period. |
132 | - $period_totals[ $time ] = array( |
|
132 | + $period_totals[$time] = array( |
|
133 | 133 | 'invoices' => 0, |
134 | 134 | 'items' => 0, |
135 | 135 | 'refunded_items' => 0, |
136 | - 'refunded_tax' => wpinv_round_amount( 0.00 ), |
|
137 | - 'subtotal' => wpinv_round_amount( 0.00 ), |
|
138 | - 'refunded_subtotal' => wpinv_round_amount( 0.00 ), |
|
139 | - 'refunded_fees' => wpinv_round_amount( 0.00 ), |
|
140 | - 'discount' => wpinv_round_amount( 0.00 ), |
|
136 | + 'refunded_tax' => wpinv_round_amount(0.00), |
|
137 | + 'subtotal' => wpinv_round_amount(0.00), |
|
138 | + 'refunded_subtotal' => wpinv_round_amount(0.00), |
|
139 | + 'refunded_fees' => wpinv_round_amount(0.00), |
|
140 | + 'discount' => wpinv_round_amount(0.00), |
|
141 | 141 | ); |
142 | 142 | |
143 | - foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
144 | - if ( ! isset( $period_totals[ $time ][ $key ] ) ) { |
|
145 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 ); |
|
143 | + foreach (array_keys(wpinv_get_report_graphs()) as $key) { |
|
144 | + if (!isset($period_totals[$time][$key])) { |
|
145 | + $period_totals[$time][$key] = wpinv_round_amount(0.00); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | } |
150 | 150 | |
151 | 151 | // add total sales, total invoice count, total tax for each period |
152 | - $date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m'; |
|
153 | - foreach ( $report_data->invoices as $invoice ) { |
|
154 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
152 | + $date_format = ('day' === $this->groupby) ? 'Y-m-d' : 'Y-m'; |
|
153 | + foreach ($report_data->invoices as $invoice) { |
|
154 | + $time = date($date_format, strtotime($invoice->post_date)); |
|
155 | 155 | |
156 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
156 | + if (!isset($period_totals[$time])) { |
|
157 | 157 | continue; |
158 | 158 | } |
159 | 159 | |
160 | - $period_totals[ $time ]['sales'] = wpinv_round_amount( $invoice->total_sales ); |
|
161 | - $period_totals[ $time ]['tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
162 | - $period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
163 | - $period_totals[ $time ]['fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
160 | + $period_totals[$time]['sales'] = wpinv_round_amount($invoice->total_sales); |
|
161 | + $period_totals[$time]['tax'] = wpinv_round_amount($invoice->total_tax); |
|
162 | + $period_totals[$time]['subtotal'] = wpinv_round_amount($invoice->subtotal); |
|
163 | + $period_totals[$time]['fees'] = wpinv_round_amount($invoice->total_fees); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
167 | - foreach ( $report_data->refunds as $invoice ) { |
|
168 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
167 | + foreach ($report_data->refunds as $invoice) { |
|
168 | + $time = date($date_format, strtotime($invoice->post_date)); |
|
169 | 169 | |
170 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
170 | + if (!isset($period_totals[$time])) { |
|
171 | 171 | continue; |
172 | 172 | } |
173 | 173 | |
174 | - $period_totals[ $time ]['refunds'] = wpinv_round_amount( $invoice->total_sales ); |
|
175 | - $period_totals[ $time ]['refunded_tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
176 | - $period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
177 | - $period_totals[ $time ]['refunded_fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
174 | + $period_totals[$time]['refunds'] = wpinv_round_amount($invoice->total_sales); |
|
175 | + $period_totals[$time]['refunded_tax'] = wpinv_round_amount($invoice->total_tax); |
|
176 | + $period_totals[$time]['refunded_subtotal'] = wpinv_round_amount($invoice->subtotal); |
|
177 | + $period_totals[$time]['refunded_fees'] = wpinv_round_amount($invoice->total_fees); |
|
178 | 178 | |
179 | 179 | } |
180 | 180 | |
181 | - foreach ( $report_data->invoice_counts as $invoice ) { |
|
182 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
181 | + foreach ($report_data->invoice_counts as $invoice) { |
|
182 | + $time = date($date_format, strtotime($invoice->post_date)); |
|
183 | 183 | |
184 | - if ( isset( $period_totals[ $time ] ) ) { |
|
185 | - $period_totals[ $time ]['invoices'] = (int) $invoice->count; |
|
184 | + if (isset($period_totals[$time])) { |
|
185 | + $period_totals[$time]['invoices'] = (int) $invoice->count; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | } |
189 | 189 | |
190 | 190 | // Add total invoice items for each period. |
191 | - foreach ( $report_data->invoice_items as $invoice_item ) { |
|
192 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : date( 'Y-m', strtotime( $invoice_item->post_date ) ); |
|
191 | + foreach ($report_data->invoice_items as $invoice_item) { |
|
192 | + $time = ('day' === $this->groupby) ? date('Y-m-d', strtotime($invoice_item->post_date)) : date('Y-m', strtotime($invoice_item->post_date)); |
|
193 | 193 | |
194 | - if ( isset( $period_totals[ $time ] ) ) { |
|
195 | - $period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count; |
|
194 | + if (isset($period_totals[$time])) { |
|
195 | + $period_totals[$time]['items'] = (int) $invoice_item->invoice_item_count; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Add total discount for each period. |
201 | - foreach ( $report_data->coupons as $discount ) { |
|
202 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $discount->post_date ) ) : date( 'Y-m', strtotime( $discount->post_date ) ); |
|
201 | + foreach ($report_data->coupons as $discount) { |
|
202 | + $time = ('day' === $this->groupby) ? date('Y-m-d', strtotime($discount->post_date)) : date('Y-m', strtotime($discount->post_date)); |
|
203 | 203 | |
204 | - if ( isset( $period_totals[ $time ] ) ) { |
|
205 | - $period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount ); |
|
204 | + if (isset($period_totals[$time])) { |
|
205 | + $period_totals[$time]['discount'] = wpinv_round_amount($discount->discount_amount); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | } |
209 | 209 | |
210 | 210 | // Extra fields. |
211 | - foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
211 | + foreach (array_keys(wpinv_get_report_graphs()) as $key) { |
|
212 | 212 | |
213 | 213 | // Abort unprepared. |
214 | - if ( ! isset( $report_data->$key ) ) { |
|
214 | + if (!isset($report_data->$key)) { |
|
215 | 215 | continue; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // Abort defaults. |
219 | - if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) { |
|
219 | + if (in_array($key, array('sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items'))) { |
|
220 | 220 | continue; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Set values. |
224 | - foreach ( $report_data->$key as $item ) { |
|
225 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $item->date ) ) : date( 'Y-m', strtotime( $item->date ) ); |
|
224 | + foreach ($report_data->$key as $item) { |
|
225 | + $time = ('day' === $this->groupby) ? date('Y-m-d', strtotime($item->date)) : date('Y-m', strtotime($item->date)); |
|
226 | 226 | |
227 | - if ( isset( $period_totals[ $time ] ) ) { |
|
228 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val ); |
|
227 | + if (isset($period_totals[$time])) { |
|
228 | + $period_totals[$time][$key] = wpinv_round_amount($item->val); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - unset( $report_data->$key ); |
|
232 | + unset($report_data->$key); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | $report_data->totals = $period_totals; |
236 | 236 | $report_data->grouped_by = $this->groupby; |
237 | - $report_data->interval = max( $this->interval, 1 ); |
|
237 | + $report_data->interval = max($this->interval, 1); |
|
238 | 238 | $report_data->currency = wpinv_get_currency(); |
239 | 239 | $report_data->currency_symbol = wpinv_currency_symbol(); |
240 | 240 | $report_data->currency_position = wpinv_currency_position(); |
241 | 241 | $report_data->decimal_places = wpinv_decimals(); |
242 | 242 | $report_data->thousands_sep = wpinv_thousands_separator(); |
243 | 243 | $report_data->decimals_sep = wpinv_decimal_separator(); |
244 | - $report_data->start_date = date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ); |
|
245 | - $report_data->end_date = date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ); |
|
246 | - $report_data->start_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ) ); |
|
247 | - $report_data->end_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ) ); |
|
244 | + $report_data->start_date = date('Y-m-d', strtotime($this->report_range['after']) + DAY_IN_SECONDS); |
|
245 | + $report_data->end_date = date('Y-m-d', strtotime($this->report_range['before']) - DAY_IN_SECONDS); |
|
246 | + $report_data->start_date_locale = getpaid_format_date(date('Y-m-d', strtotime($this->report_range['after']) + DAY_IN_SECONDS)); |
|
247 | + $report_data->end_date_locale = getpaid_format_date(date('Y-m-d', strtotime($this->report_range['before']) - DAY_IN_SECONDS)); |
|
248 | 248 | $report_data->decimals_sep = wpinv_decimal_separator(); |
249 | 249 | |
250 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
250 | + $context = !empty($request['context']) ? $request['context'] : 'view'; |
|
251 | 251 | $data = $report_data; |
252 | - unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items ); |
|
253 | - $data = $this->add_additional_fields_to_object( (array) $data, $request ); |
|
254 | - $data = $this->filter_response_by_context( $data, $context ); |
|
252 | + unset($data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items); |
|
253 | + $data = $this->add_additional_fields_to_object((array) $data, $request); |
|
254 | + $data = $this->filter_response_by_context($data, $context); |
|
255 | 255 | |
256 | 256 | // Wrap the data in a response object. |
257 | - $response = rest_ensure_response( $data ); |
|
258 | - $response->add_links( array( |
|
257 | + $response = rest_ensure_response($data); |
|
258 | + $response->add_links(array( |
|
259 | 259 | 'about' => array( |
260 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
260 | + 'href' => rest_url(sprintf('%s/reports', $this->namespace)), |
|
261 | 261 | ), |
262 | - ) ); |
|
262 | + )); |
|
263 | 263 | |
264 | - return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request ); |
|
264 | + return apply_filters('getpaid_rest_prepare_report_sales', $response, $report_data, $request); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @return stdClass |
271 | 271 | */ |
272 | 272 | public function get_report_data() { |
273 | - if ( empty( $this->report_data ) ) { |
|
273 | + if (empty($this->report_data)) { |
|
274 | 274 | $this->query_report_data(); |
275 | 275 | } |
276 | 276 | return $this->report_data; |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | |
284 | 284 | // Prepare reports. |
285 | 285 | $this->report_data = (object) array( |
286 | - 'invoice_counts' => $this->query_invoice_counts(),//count, post_date |
|
286 | + 'invoice_counts' => $this->query_invoice_counts(), //count, post_date |
|
287 | 287 | 'coupons' => $this->query_coupon_counts(), // discount_amount, post_date |
288 | 288 | 'invoice_items' => $this->query_item_counts(), // invoice_item_count, post_date |
289 | 289 | 'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date |
@@ -293,32 +293,32 @@ discard block |
||
293 | 293 | ); |
294 | 294 | |
295 | 295 | // Calculated totals. |
296 | - $this->report_data->total_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) ); |
|
297 | - $this->report_data->total_sales = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) ); |
|
298 | - $this->report_data->total_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) ); |
|
299 | - $this->report_data->total_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) ); |
|
300 | - $this->report_data->subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) ); |
|
301 | - $this->report_data->net_sales = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) ); |
|
302 | - $this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) ); |
|
303 | - $this->report_data->total_refunds = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) ); |
|
304 | - $this->report_data->refunded_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) ); |
|
305 | - $this->report_data->refunded_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) ); |
|
306 | - $this->report_data->refunded_subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) ); |
|
307 | - $this->report_data->net_refunds = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) ); |
|
296 | + $this->report_data->total_tax = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_tax'))); |
|
297 | + $this->report_data->total_sales = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_sales'))); |
|
298 | + $this->report_data->total_discount = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_discount'))); |
|
299 | + $this->report_data->total_fees = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_fees'))); |
|
300 | + $this->report_data->subtotal = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'subtotal'))); |
|
301 | + $this->report_data->net_sales = wpinv_round_amount($this->report_data->total_sales - max(0, $this->report_data->total_tax)); |
|
302 | + $this->report_data->total_refunded_tax = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_tax'))); |
|
303 | + $this->report_data->total_refunds = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_sales'))); |
|
304 | + $this->report_data->refunded_discount = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_discount'))); |
|
305 | + $this->report_data->refunded_fees = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_fees'))); |
|
306 | + $this->report_data->refunded_subtotal = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'subtotal'))); |
|
307 | + $this->report_data->net_refunds = wpinv_round_amount($this->report_data->total_refunds + max(0, $this->report_data->total_refunded_tax)); |
|
308 | 308 | |
309 | 309 | |
310 | 310 | // Calculate average based on net. |
311 | - $this->report_data->average_sales = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 ); |
|
312 | - $this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 ); |
|
311 | + $this->report_data->average_sales = wpinv_round_amount($this->report_data->net_sales / max($this->interval, 1), 2); |
|
312 | + $this->report_data->average_total_sales = wpinv_round_amount($this->report_data->total_sales / max($this->interval, 1), 2); |
|
313 | 313 | |
314 | 314 | // Total invoices in this period, even if refunded. |
315 | - $this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) ); |
|
315 | + $this->report_data->total_invoices = absint(array_sum(wp_list_pluck($this->report_data->invoice_counts, 'count'))); |
|
316 | 316 | |
317 | 317 | // Items invoiced in this period, even if refunded. |
318 | - $this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) ); |
|
318 | + $this->report_data->total_items = absint(array_sum(wp_list_pluck($this->report_data->invoice_items, 'invoice_item_count'))); |
|
319 | 319 | |
320 | 320 | // 3rd party filtering of report data |
321 | - $this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this ); |
|
321 | + $this->report_data = apply_filters('getpaid_rest_api_filter_report_data', $this->report_data, $this); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -343,11 +343,11 @@ discard block |
||
343 | 343 | 'name' => 'post_date', |
344 | 344 | ), |
345 | 345 | ), |
346 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
346 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
347 | 347 | 'order_by' => 'post_date ASC', |
348 | 348 | 'query_type' => 'get_results', |
349 | 349 | 'filter_range' => $this->report_range, |
350 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
350 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal'), |
|
351 | 351 | ) |
352 | 352 | ); |
353 | 353 | |
@@ -374,11 +374,11 @@ discard block |
||
374 | 374 | 'name' => 'post_date', |
375 | 375 | ), |
376 | 376 | ), |
377 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
377 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
378 | 378 | 'order_by' => 'post_date ASC', |
379 | 379 | 'query_type' => 'get_results', |
380 | 380 | 'filter_range' => $this->report_range, |
381 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
381 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal'), |
|
382 | 382 | ) |
383 | 383 | ); |
384 | 384 | |
@@ -405,11 +405,11 @@ discard block |
||
405 | 405 | 'name' => 'post_date', |
406 | 406 | ), |
407 | 407 | ), |
408 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
408 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
409 | 409 | 'order_by' => 'post_date ASC', |
410 | 410 | 'query_type' => 'get_results', |
411 | 411 | 'filter_range' => $this->report_range, |
412 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
412 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal'), |
|
413 | 413 | ) |
414 | 414 | ); |
415 | 415 | |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | ), |
434 | 434 | 'query_type' => 'get_var', |
435 | 435 | 'filter_range' => $this->report_range, |
436 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
436 | + 'invoice_status' => array('wpi-refunded'), |
|
437 | 437 | ) |
438 | 438 | ); |
439 | 439 | |
@@ -480,11 +480,11 @@ discard block |
||
480 | 480 | 'name' => 'post_date', |
481 | 481 | ), |
482 | 482 | ), |
483 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
483 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
484 | 484 | 'order_by' => 'post_date ASC', |
485 | 485 | 'query_type' => 'get_results', |
486 | 486 | 'filter_range' => $this->report_range, |
487 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ), |
|
487 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal'), |
|
488 | 488 | ) |
489 | 489 | ); |
490 | 490 | |
@@ -531,11 +531,11 @@ discard block |
||
531 | 531 | 'name' => 'post_date', |
532 | 532 | ), |
533 | 533 | ), |
534 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
534 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
535 | 535 | 'order_by' => 'post_date ASC', |
536 | 536 | 'query_type' => 'get_results', |
537 | 537 | 'filter_range' => $this->report_range, |
538 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
538 | + 'invoice_status' => array('wpi-refunded'), |
|
539 | 539 | ) |
540 | 540 | ); |
541 | 541 | |
@@ -554,154 +554,154 @@ discard block |
||
554 | 554 | 'type' => 'object', |
555 | 555 | 'properties' => array( |
556 | 556 | 'total_sales' => array( |
557 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
557 | + 'description' => __('Gross sales in the period.', 'invoicing'), |
|
558 | 558 | 'type' => 'string', |
559 | - 'context' => array( 'view' ), |
|
559 | + 'context' => array('view'), |
|
560 | 560 | 'readonly' => true, |
561 | 561 | ), |
562 | 562 | 'net_sales' => array( |
563 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
563 | + 'description' => __('Net sales in the period.', 'invoicing'), |
|
564 | 564 | 'type' => 'string', |
565 | - 'context' => array( 'view' ), |
|
565 | + 'context' => array('view'), |
|
566 | 566 | 'readonly' => true, |
567 | 567 | ), |
568 | 568 | 'average_sales' => array( |
569 | - 'description' => __( 'Average net daily sales.', 'invoicing' ), |
|
569 | + 'description' => __('Average net daily sales.', 'invoicing'), |
|
570 | 570 | 'type' => 'string', |
571 | - 'context' => array( 'view' ), |
|
571 | + 'context' => array('view'), |
|
572 | 572 | 'readonly' => true, |
573 | 573 | ), |
574 | 574 | 'average_total_sales' => array( |
575 | - 'description' => __( 'Average gross daily sales.', 'invoicing' ), |
|
575 | + 'description' => __('Average gross daily sales.', 'invoicing'), |
|
576 | 576 | 'type' => 'string', |
577 | - 'context' => array( 'view' ), |
|
577 | + 'context' => array('view'), |
|
578 | 578 | 'readonly' => true, |
579 | 579 | ), |
580 | 580 | 'total_invoices' => array( |
581 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
581 | + 'description' => __('Number of paid invoices.', 'invoicing'), |
|
582 | 582 | 'type' => 'integer', |
583 | - 'context' => array( 'view' ), |
|
583 | + 'context' => array('view'), |
|
584 | 584 | 'readonly' => true, |
585 | 585 | ), |
586 | 586 | 'total_items' => array( |
587 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
587 | + 'description' => __('Number of items purchased.', 'invoicing'), |
|
588 | 588 | 'type' => 'integer', |
589 | - 'context' => array( 'view' ), |
|
589 | + 'context' => array('view'), |
|
590 | 590 | 'readonly' => true, |
591 | 591 | ), |
592 | 592 | 'refunded_items' => array( |
593 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
593 | + 'description' => __('Number of items refunded.', 'invoicing'), |
|
594 | 594 | 'type' => 'integer', |
595 | - 'context' => array( 'view' ), |
|
595 | + 'context' => array('view'), |
|
596 | 596 | 'readonly' => true, |
597 | 597 | ), |
598 | 598 | 'total_tax' => array( |
599 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
599 | + 'description' => __('Total charged for taxes.', 'invoicing'), |
|
600 | 600 | 'type' => 'string', |
601 | - 'context' => array( 'view' ), |
|
601 | + 'context' => array('view'), |
|
602 | 602 | 'readonly' => true, |
603 | 603 | ), |
604 | 604 | 'total_refunded_tax' => array( |
605 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
605 | + 'description' => __('Total refunded for taxes.', 'invoicing'), |
|
606 | 606 | 'type' => 'string', |
607 | - 'context' => array( 'view' ), |
|
607 | + 'context' => array('view'), |
|
608 | 608 | 'readonly' => true, |
609 | 609 | ), |
610 | 610 | 'total_fees' => array( |
611 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
611 | + 'description' => __('Total fees charged.', 'invoicing'), |
|
612 | 612 | 'type' => 'string', |
613 | - 'context' => array( 'view' ), |
|
613 | + 'context' => array('view'), |
|
614 | 614 | 'readonly' => true, |
615 | 615 | ), |
616 | 616 | 'total_refunds' => array( |
617 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
617 | + 'description' => __('Total of refunded invoices.', 'invoicing'), |
|
618 | 618 | 'type' => 'integer', |
619 | - 'context' => array( 'view' ), |
|
619 | + 'context' => array('view'), |
|
620 | 620 | 'readonly' => true, |
621 | 621 | ), |
622 | 622 | 'net_refunds' => array( |
623 | - 'description' => __( 'Net of refunded invoices.', 'invoicing' ), |
|
623 | + 'description' => __('Net of refunded invoices.', 'invoicing'), |
|
624 | 624 | 'type' => 'integer', |
625 | - 'context' => array( 'view' ), |
|
625 | + 'context' => array('view'), |
|
626 | 626 | 'readonly' => true, |
627 | 627 | ), |
628 | 628 | 'total_discount' => array( |
629 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
629 | + 'description' => __('Total of discounts used.', 'invoicing'), |
|
630 | 630 | 'type' => 'integer', |
631 | - 'context' => array( 'view' ), |
|
631 | + 'context' => array('view'), |
|
632 | 632 | 'readonly' => true, |
633 | 633 | ), |
634 | 634 | 'totals' => array( |
635 | - 'description' => __( 'Totals.', 'invoicing' ), |
|
635 | + 'description' => __('Totals.', 'invoicing'), |
|
636 | 636 | 'type' => 'array', |
637 | 637 | 'items' => array( |
638 | 638 | 'type' => 'array', |
639 | 639 | ), |
640 | - 'context' => array( 'view' ), |
|
640 | + 'context' => array('view'), |
|
641 | 641 | 'readonly' => true, |
642 | 642 | ), |
643 | 643 | 'interval' => array( |
644 | - 'description' => __( 'Number of months/days in the report period.', 'invoicing' ), |
|
644 | + 'description' => __('Number of months/days in the report period.', 'invoicing'), |
|
645 | 645 | 'type' => 'integer', |
646 | - 'context' => array( 'view' ), |
|
646 | + 'context' => array('view'), |
|
647 | 647 | 'readonly' => true, |
648 | 648 | ), |
649 | 649 | 'previous_range' => array( |
650 | - 'description' => __( 'The previous report period.', 'invoicing' ), |
|
650 | + 'description' => __('The previous report period.', 'invoicing'), |
|
651 | 651 | 'type' => 'array', |
652 | 652 | 'items' => array( |
653 | 653 | 'type' => 'string', |
654 | 654 | ), |
655 | - 'context' => array( 'view' ), |
|
655 | + 'context' => array('view'), |
|
656 | 656 | 'readonly' => true, |
657 | 657 | ), |
658 | 658 | 'grouped_by' => array( |
659 | - 'description' => __( 'The period used to group the totals.', 'invoicing' ), |
|
659 | + 'description' => __('The period used to group the totals.', 'invoicing'), |
|
660 | 660 | 'type' => 'string', |
661 | - 'context' => array( 'view' ), |
|
662 | - 'enum' => array( 'day', 'month' ), |
|
661 | + 'context' => array('view'), |
|
662 | + 'enum' => array('day', 'month'), |
|
663 | 663 | 'readonly' => true, |
664 | 664 | ), |
665 | 665 | 'currency' => array( |
666 | - 'description' => __( 'The default store currency.', 'invoicing' ), |
|
666 | + 'description' => __('The default store currency.', 'invoicing'), |
|
667 | 667 | 'type' => 'string', |
668 | - 'context' => array( 'view' ), |
|
668 | + 'context' => array('view'), |
|
669 | 669 | 'readonly' => true, |
670 | 670 | ), |
671 | 671 | 'currency_symbol' => array( |
672 | - 'description' => __( 'The default store currency symbol.', 'invoicing' ), |
|
672 | + 'description' => __('The default store currency symbol.', 'invoicing'), |
|
673 | 673 | 'type' => 'string', |
674 | - 'context' => array( 'view' ), |
|
674 | + 'context' => array('view'), |
|
675 | 675 | 'readonly' => true, |
676 | 676 | ), |
677 | 677 | 'currency_position' => array( |
678 | - 'description' => __( 'The default store currency position.', 'invoicing' ), |
|
678 | + 'description' => __('The default store currency position.', 'invoicing'), |
|
679 | 679 | 'type' => 'string', |
680 | - 'context' => array( 'view' ), |
|
680 | + 'context' => array('view'), |
|
681 | 681 | 'readonly' => true, |
682 | 682 | ), |
683 | 683 | 'decimal_places' => array( |
684 | - 'description' => __( 'The default store decimal places.', 'invoicing' ), |
|
684 | + 'description' => __('The default store decimal places.', 'invoicing'), |
|
685 | 685 | 'type' => 'string', |
686 | - 'context' => array( 'view' ), |
|
686 | + 'context' => array('view'), |
|
687 | 687 | 'readonly' => true, |
688 | 688 | ), |
689 | 689 | 'thousands_sep' => array( |
690 | - 'description' => __( 'The default store thousands separator.', 'invoicing' ), |
|
690 | + 'description' => __('The default store thousands separator.', 'invoicing'), |
|
691 | 691 | 'type' => 'string', |
692 | - 'context' => array( 'view' ), |
|
692 | + 'context' => array('view'), |
|
693 | 693 | 'readonly' => true, |
694 | 694 | ), |
695 | 695 | 'decimals_sep' => array( |
696 | - 'description' => __( 'The default store decimals separator.', 'invoicing' ), |
|
696 | + 'description' => __('The default store decimals separator.', 'invoicing'), |
|
697 | 697 | 'type' => 'string', |
698 | - 'context' => array( 'view' ), |
|
698 | + 'context' => array('view'), |
|
699 | 699 | 'readonly' => true, |
700 | 700 | ), |
701 | 701 | ), |
702 | 702 | ); |
703 | 703 | |
704 | - return $this->add_additional_fields_schema( $schema ); |
|
704 | + return $this->add_additional_fields_schema($schema); |
|
705 | 705 | |
706 | 706 | } |
707 | 707 |
@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_is_checkout() { |
15 | 15 | global $wp_query; |
16 | 16 | |
17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
19 | - $checkout_page = wpinv_get_option( 'checkout_page' ); |
|
20 | - $is_checkout = ! empty( $checkout_page ) && is_page( $checkout_page ); |
|
17 | + $is_object_set = isset($wp_query->queried_object); |
|
18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
19 | + $checkout_page = wpinv_get_option('checkout_page'); |
|
20 | + $is_checkout = !empty($checkout_page) && is_page($checkout_page); |
|
21 | 21 | |
22 | - if ( !$is_object_set ) { |
|
23 | - unset( $wp_query->queried_object ); |
|
22 | + if (!$is_object_set) { |
|
23 | + unset($wp_query->queried_object); |
|
24 | 24 | } |
25 | 25 | |
26 | - if ( !$is_object_id_set ) { |
|
27 | - unset( $wp_query->queried_object_id ); |
|
26 | + if (!$is_object_id_set) { |
|
27 | + unset($wp_query->queried_object_id); |
|
28 | 28 | } |
29 | 29 | |
30 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
30 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | 34 | $can_checkout = true; // Always true for now |
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters('wpinv_can_checkout', $can_checkout); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option('success_page', 0); |
|
41 | + $page_id = absint($page_id); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -49,139 +49,139 @@ discard block |
||
49 | 49 | * @param string $post_type The post type or invoice type. |
50 | 50 | * @return string The history page URL. |
51 | 51 | */ |
52 | -function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
|
53 | - $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
|
54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | - $page_id = absint( $page_id ); |
|
56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
52 | +function wpinv_get_history_page_uri($post_type = 'wpi_invoice') { |
|
53 | + $post_type = sanitize_key(str_replace('wpi_', '', $post_type)); |
|
54 | + $page_id = wpinv_get_option("{$post_type}_history_page", 0); |
|
55 | + $page_id = absint($page_id); |
|
56 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id), $post_type); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_success_page() { |
60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
60 | + $is_success_page = wpinv_get_option('success_page', false); |
|
61 | + $is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false; |
|
62 | 62 | |
63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
63 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_invoice_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
68 | + $ret = $ret ? is_page($ret) : false; |
|
69 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function wpinv_is_subscriptions_history_page() { |
73 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
74 | - $ret = $ret ? is_page( $ret ) : false; |
|
75 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
73 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
74 | + $ret = $ret ? is_page($ret) : false; |
|
75 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Redirects a user the success page. |
80 | 80 | */ |
81 | -function wpinv_send_to_success_page( $args = array() ) { |
|
81 | +function wpinv_send_to_success_page($args = array()) { |
|
82 | 82 | |
83 | 83 | $redirect = add_query_arg( |
84 | - wp_parse_args( $args ), |
|
84 | + wp_parse_args($args), |
|
85 | 85 | wpinv_get_success_page_uri() |
86 | 86 | ); |
87 | 87 | |
88 | - $redirect = apply_filters( 'wpinv_send_to_success_page_url', $redirect, $args ); |
|
88 | + $redirect = apply_filters('wpinv_send_to_success_page_url', $redirect, $args); |
|
89 | 89 | |
90 | - wp_redirect( $redirect ); |
|
90 | + wp_redirect($redirect); |
|
91 | 91 | exit; |
92 | 92 | } |
93 | 93 | |
94 | -function wpinv_send_to_failed_page( $args = null ) { |
|
94 | +function wpinv_send_to_failed_page($args = null) { |
|
95 | 95 | $redirect = wpinv_get_failed_transaction_uri(); |
96 | 96 | |
97 | - if ( !empty( $args ) ) { |
|
97 | + if (!empty($args)) { |
|
98 | 98 | // Check for backward compatibility |
99 | - if ( is_string( $args ) ) |
|
100 | - $args = str_replace( '?', '', $args ); |
|
99 | + if (is_string($args)) |
|
100 | + $args = str_replace('?', '', $args); |
|
101 | 101 | |
102 | - $args = wp_parse_args( $args ); |
|
102 | + $args = wp_parse_args($args); |
|
103 | 103 | |
104 | - $redirect = add_query_arg( $args, $redirect ); |
|
104 | + $redirect = add_query_arg($args, $redirect); |
|
105 | 105 | } |
106 | 106 | |
107 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
107 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
108 | 108 | |
109 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
110 | - wp_redirect( $redirect ); |
|
109 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
110 | + wp_redirect($redirect); |
|
111 | 111 | exit; |
112 | 112 | } |
113 | 113 | |
114 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
115 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
116 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
114 | +function wpinv_get_checkout_uri($args = array()) { |
|
115 | + $uri = wpinv_get_option('checkout_page', false); |
|
116 | + $uri = isset($uri) ? get_permalink($uri) : NULL; |
|
117 | 117 | |
118 | - if ( !empty( $args ) ) { |
|
118 | + if (!empty($args)) { |
|
119 | 119 | // Check for backward compatibility |
120 | - if ( is_string( $args ) ) |
|
121 | - $args = str_replace( '?', '', $args ); |
|
120 | + if (is_string($args)) |
|
121 | + $args = str_replace('?', '', $args); |
|
122 | 122 | |
123 | - $args = wp_parse_args( $args ); |
|
123 | + $args = wp_parse_args($args); |
|
124 | 124 | |
125 | - $uri = add_query_arg( $args, $uri ); |
|
125 | + $uri = add_query_arg($args, $uri); |
|
126 | 126 | } |
127 | 127 | |
128 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
128 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
129 | 129 | |
130 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
130 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
131 | 131 | |
132 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
133 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
132 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
133 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
134 | 134 | } |
135 | 135 | |
136 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
136 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
137 | 137 | } |
138 | 138 | |
139 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
140 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
141 | - $success_page = get_permalink( $success_page ); |
|
139 | +function wpinv_get_success_page_url($query_string = null) { |
|
140 | + $success_page = wpinv_get_option('success_page', 0); |
|
141 | + $success_page = get_permalink($success_page); |
|
142 | 142 | |
143 | - if ( $query_string ) |
|
143 | + if ($query_string) |
|
144 | 144 | $success_page .= $query_string; |
145 | 145 | |
146 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
146 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
150 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
151 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
149 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
150 | + $uri = wpinv_get_option('failure_page', ''); |
|
151 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
152 | 152 | |
153 | - if ( $extras ) |
|
153 | + if ($extras) |
|
154 | 154 | $uri .= $extras; |
155 | 155 | |
156 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
156 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | function wpinv_is_failed_transaction_page() { |
160 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
161 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
160 | + $ret = wpinv_get_option('failure_page', false); |
|
161 | + $ret = isset($ret) ? is_page($ret) : false; |
|
162 | 162 | |
163 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
163 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
164 | 164 | } |
165 | 165 | |
166 | -function wpinv_transaction_query( $type = 'start' ) { |
|
166 | +function wpinv_transaction_query($type = 'start') { |
|
167 | 167 | global $wpdb; |
168 | 168 | |
169 | 169 | $wpdb->hide_errors(); |
170 | 170 | |
171 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
172 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
171 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
172 | + define('WPINV_USE_TRANSACTIONS', true); |
|
173 | 173 | } |
174 | 174 | |
175 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
176 | - switch ( $type ) { |
|
175 | + if (WPINV_USE_TRANSACTIONS) { |
|
176 | + switch ($type) { |
|
177 | 177 | case 'commit' : |
178 | - $wpdb->query( 'COMMIT' ); |
|
178 | + $wpdb->query('COMMIT'); |
|
179 | 179 | break; |
180 | 180 | case 'rollback' : |
181 | - $wpdb->query( 'ROLLBACK' ); |
|
181 | + $wpdb->query('ROLLBACK'); |
|
182 | 182 | break; |
183 | 183 | default : |
184 | - $wpdb->query( 'START TRANSACTION' ); |
|
184 | + $wpdb->query('START TRANSACTION'); |
|
185 | 185 | break; |
186 | 186 | } |
187 | 187 | } |
@@ -190,146 +190,146 @@ discard block |
||
190 | 190 | function wpinv_get_prefix() { |
191 | 191 | $invoice_prefix = 'INV-'; |
192 | 192 | |
193 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
193 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | function wpinv_get_business_logo() { |
197 | - $business_logo = wpinv_get_option( 'logo' ); |
|
198 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
197 | + $business_logo = wpinv_get_option('logo'); |
|
198 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | function wpinv_get_business_name() { |
202 | - $name = wpinv_get_option( 'store_name', wpinv_get_blogname() ); |
|
202 | + $name = wpinv_get_option('store_name', wpinv_get_blogname()); |
|
203 | 203 | |
204 | - if ( empty( $name ) ) { |
|
204 | + if (empty($name)) { |
|
205 | 205 | $name = wpinv_get_blogname(); |
206 | 206 | } |
207 | 207 | |
208 | - return apply_filters( 'wpinv_get_business_name', $name ); |
|
208 | + return apply_filters('wpinv_get_business_name', $name); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | function wpinv_get_blogname() { |
212 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
212 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | function wpinv_get_admin_email() { |
216 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
217 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
216 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
217 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | function wpinv_get_business_website() { |
221 | - $business_website = home_url( '/' ); |
|
222 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
221 | + $business_website = home_url('/'); |
|
222 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
223 | 223 | } |
224 | 224 | |
225 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
225 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
226 | 226 | $terms_text = ''; |
227 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
227 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function wpinv_get_business_footer() { |
231 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
232 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
233 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
231 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
232 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
233 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | function wpinv_checkout_required_fields() { |
237 | 237 | $required_fields = array(); |
238 | 238 | |
239 | 239 | // Let payment gateways and other extensions determine if address fields should be required |
240 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
240 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
241 | 241 | |
242 | - if ( $require_billing_details ) { |
|
243 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
242 | + if ($require_billing_details) { |
|
243 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
244 | 244 | $required_fields['first_name'] = array( |
245 | 245 | 'error_id' => 'invalid_first_name', |
246 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
246 | + 'error_message' => __('Please enter your first name', 'invoicing') |
|
247 | 247 | ); |
248 | 248 | } |
249 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
249 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
250 | 250 | $required_fields['address'] = array( |
251 | 251 | 'error_id' => 'invalid_address', |
252 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
252 | + 'error_message' => __('Please enter your address', 'invoicing') |
|
253 | 253 | ); |
254 | 254 | } |
255 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
255 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
256 | 256 | $required_fields['city'] = array( |
257 | 257 | 'error_id' => 'invalid_city', |
258 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
258 | + 'error_message' => __('Please enter your billing city', 'invoicing') |
|
259 | 259 | ); |
260 | 260 | } |
261 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
261 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
262 | 262 | $required_fields['state'] = array( |
263 | 263 | 'error_id' => 'invalid_state', |
264 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
264 | + 'error_message' => __('Please enter billing state / province', 'invoicing') |
|
265 | 265 | ); |
266 | 266 | } |
267 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
267 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
268 | 268 | $required_fields['country'] = array( |
269 | 269 | 'error_id' => 'invalid_country', |
270 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
270 | + 'error_message' => __('Please select your billing country', 'invoicing') |
|
271 | 271 | ); |
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
275 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | function wpinv_is_ssl_enforced() { |
279 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
280 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
279 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
280 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | function wpinv_schedule_event_twicedaily() { |
284 | 284 | wpinv_email_payment_reminders(); |
285 | 285 | } |
286 | -add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' ); |
|
286 | +add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily'); |
|
287 | 287 | |
288 | 288 | function wpinv_require_login_to_checkout() { |
289 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
290 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
289 | + $return = wpinv_get_option('login_to_checkout', false); |
|
290 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
291 | 291 | } |
292 | 292 | |
293 | -function wpinv_sequential_number_active( $type = '' ) { |
|
294 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
295 | - if ( null !== $check ) { |
|
293 | +function wpinv_sequential_number_active($type = '') { |
|
294 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
295 | + if (null !== $check) { |
|
296 | 296 | return $check; |
297 | 297 | } |
298 | 298 | |
299 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
299 | + return wpinv_get_option('sequential_invoice_number'); |
|
300 | 300 | } |
301 | 301 | |
302 | -function wpinv_switch_to_locale( $locale = NULL ) { |
|
302 | +function wpinv_switch_to_locale($locale = NULL) { |
|
303 | 303 | global $invoicing, $wpi_switch_locale; |
304 | 304 | |
305 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
306 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
305 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
306 | + $locale = empty($locale) ? get_locale() : $locale; |
|
307 | 307 | |
308 | - switch_to_locale( $locale ); |
|
308 | + switch_to_locale($locale); |
|
309 | 309 | |
310 | 310 | $wpi_switch_locale = $locale; |
311 | 311 | |
312 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
312 | + add_filter('plugin_locale', 'get_locale'); |
|
313 | 313 | |
314 | 314 | $invoicing->load_textdomain(); |
315 | 315 | |
316 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
316 | + do_action('wpinv_switch_to_locale', $locale); |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
320 | 320 | function wpinv_restore_locale() { |
321 | 321 | global $invoicing, $wpi_switch_locale; |
322 | 322 | |
323 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
323 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
324 | 324 | restore_previous_locale(); |
325 | 325 | |
326 | 326 | $wpi_switch_locale = NULL; |
327 | 327 | |
328 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
328 | + remove_filter('plugin_locale', 'get_locale'); |
|
329 | 329 | |
330 | 330 | $invoicing->load_textdomain(); |
331 | 331 | |
332 | - do_action( 'wpinv_restore_locale' ); |
|
332 | + do_action('wpinv_restore_locale'); |
|
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
@@ -337,26 +337,26 @@ discard block |
||
337 | 337 | * Returns the default form's id. |
338 | 338 | */ |
339 | 339 | function wpinv_get_default_payment_form() { |
340 | - $form = get_option( 'wpinv_default_payment_form' ); |
|
340 | + $form = get_option('wpinv_default_payment_form'); |
|
341 | 341 | |
342 | - if ( empty( $form ) || 'publish' != get_post_status( $form ) ) { |
|
342 | + if (empty($form) || 'publish' != get_post_status($form)) { |
|
343 | 343 | $form = wp_insert_post( |
344 | 344 | array( |
345 | 345 | 'post_type' => 'wpi_payment_form', |
346 | - 'post_title' => __( 'Checkout (default)', 'invoicing' ), |
|
346 | + 'post_title' => __('Checkout (default)', 'invoicing'), |
|
347 | 347 | 'post_status' => 'publish', |
348 | 348 | 'meta_input' => array( |
349 | - 'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ), |
|
349 | + 'wpinv_form_elements' => wpinv_get_data('default-payment-form'), |
|
350 | 350 | 'wpinv_form_items' => array(), |
351 | 351 | ) |
352 | 352 | ) |
353 | 353 | ); |
354 | 354 | |
355 | - update_option( 'wpinv_default_payment_form', $form ); |
|
355 | + update_option('wpinv_default_payment_form', $form); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | // WPML support. |
359 | - $form = apply_filters( 'wpml_object_id', $form, 'wpi_payment_form', TRUE ); |
|
359 | + $form = apply_filters('wpml_object_id', $form, 'wpi_payment_form', TRUE); |
|
360 | 360 | return $form; |
361 | 361 | } |
362 | 362 | |
@@ -365,19 +365,19 @@ discard block |
||
365 | 365 | * |
366 | 366 | * @param int $payment_form |
367 | 367 | */ |
368 | -function getpaid_get_payment_form_elements( $payment_form ) { |
|
368 | +function getpaid_get_payment_form_elements($payment_form) { |
|
369 | 369 | |
370 | - if ( empty( $payment_form ) ) { |
|
371 | - return wpinv_get_data( 'sample-payment-form' ); |
|
370 | + if (empty($payment_form)) { |
|
371 | + return wpinv_get_data('sample-payment-form'); |
|
372 | 372 | } |
373 | 373 | |
374 | - $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true ); |
|
374 | + $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true); |
|
375 | 375 | |
376 | - if ( is_array( $form_elements ) ) { |
|
376 | + if (is_array($form_elements)) { |
|
377 | 377 | return $form_elements; |
378 | 378 | } |
379 | 379 | |
380 | - return wpinv_get_data( 'sample-payment-form' ); |
|
380 | + return wpinv_get_data('sample-payment-form'); |
|
381 | 381 | |
382 | 382 | } |
383 | 383 | |
@@ -386,42 +386,42 @@ discard block |
||
386 | 386 | * |
387 | 387 | * @param int $payment_form |
388 | 388 | */ |
389 | -function gepaid_get_form_items( $id ) { |
|
390 | - $form = new GetPaid_Payment_Form( $id ); |
|
389 | +function gepaid_get_form_items($id) { |
|
390 | + $form = new GetPaid_Payment_Form($id); |
|
391 | 391 | |
392 | 392 | // Is this a default form? |
393 | - if ( $form->is_default() ) { |
|
393 | + if ($form->is_default()) { |
|
394 | 394 | return array(); |
395 | 395 | } |
396 | 396 | |
397 | - return $form->get_items( 'view', 'arrays' ); |
|
397 | + return $form->get_items('view', 'arrays'); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
401 | 401 | * Trims each line in a paragraph. |
402 | 402 | * |
403 | 403 | */ |
404 | -function gepaid_trim_lines( $content ) { |
|
405 | - return implode( "\n", array_map( 'trim', explode( "\n", $content ) ) ); |
|
404 | +function gepaid_trim_lines($content) { |
|
405 | + return implode("\n", array_map('trim', explode("\n", $content))); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | |
409 | -function wpinv_add_elementor_widget_categories( $elements_manager ) { |
|
409 | +function wpinv_add_elementor_widget_categories($elements_manager) { |
|
410 | 410 | $elements_manager->add_category( |
411 | 411 | 'getpaid', |
412 | 412 | [ |
413 | - 'title' => esc_html__( 'GetPaid', 'invoicing' ), |
|
413 | + 'title' => esc_html__('GetPaid', 'invoicing'), |
|
414 | 414 | 'icon' => 'fa fa-plug', |
415 | 415 | ] |
416 | 416 | ); |
417 | 417 | } |
418 | -add_filter( 'elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories' ); |
|
418 | +add_filter('elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories'); |
|
419 | 419 | |
420 | -function wpinv_alter_elementor_widget_config( $config ){ |
|
420 | +function wpinv_alter_elementor_widget_config($config) { |
|
421 | 421 | |
422 | - if ( ! empty( $config['initial_document']['widgets'] ) ) { |
|
423 | - foreach( $config['initial_document']['widgets'] as $key => $widget){ |
|
424 | - if(substr( $key, 0, 16 ) === "wp-widget-wpinv_" || $key === "wp-widget-getpaid"){ |
|
422 | + if (!empty($config['initial_document']['widgets'])) { |
|
423 | + foreach ($config['initial_document']['widgets'] as $key => $widget) { |
|
424 | + if (substr($key, 0, 16) === "wp-widget-wpinv_" || $key === "wp-widget-getpaid") { |
|
425 | 425 | $config['initial_document']['widgets'][$key]['categories'][] = 'getpaid'; |
426 | 426 | $config['initial_document']['widgets'][$key]['hide_on_search'] = false; |
427 | 427 | $config['initial_document']['widgets'][$key]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
@@ -431,20 +431,20 @@ discard block |
||
431 | 431 | |
432 | 432 | return $config; |
433 | 433 | } |
434 | -add_filter( 'elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config' ); |
|
434 | +add_filter('elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config'); |
|
435 | 435 | |
436 | 436 | function wpinv_get_report_graphs() { |
437 | 437 | |
438 | 438 | return apply_filters( |
439 | 439 | 'getpaid_report_graphs', |
440 | 440 | array( |
441 | - 'sales' => __( 'Earnings', 'invoicing' ), |
|
442 | - 'refunds' => __( 'Refunds', 'invoicing' ), |
|
443 | - 'tax' => __( 'Taxes', 'invoicing' ), |
|
444 | - 'fees' => __( 'Fees', 'invoicing' ), |
|
445 | - 'discount' => __( 'Discounts', 'invoicing' ), |
|
446 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
447 | - 'items' => __( 'Purchased Items', 'invoicing' ), |
|
441 | + 'sales' => __('Earnings', 'invoicing'), |
|
442 | + 'refunds' => __('Refunds', 'invoicing'), |
|
443 | + 'tax' => __('Taxes', 'invoicing'), |
|
444 | + 'fees' => __('Fees', 'invoicing'), |
|
445 | + 'discount' => __('Discounts', 'invoicing'), |
|
446 | + 'invoices' => __('Invoices', 'invoicing'), |
|
447 | + 'items' => __('Purchased Items', 'invoicing'), |
|
448 | 448 | ) |
449 | 449 | ); |
450 | 450 |
@@ -12,88 +12,88 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $views; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $views; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | 25 | |
26 | - $this->views = array( |
|
26 | + $this->views = array( |
|
27 | 27 | |
28 | 28 | 'items' => array( |
29 | - 'label' => __( 'Items', 'invoicing' ), |
|
30 | - 'class' => 'GetPaid_Reports_Report_Items', |
|
31 | - ), |
|
29 | + 'label' => __( 'Items', 'invoicing' ), |
|
30 | + 'class' => 'GetPaid_Reports_Report_Items', |
|
31 | + ), |
|
32 | 32 | |
33 | - 'gateways' => array( |
|
34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
35 | - 'class' => 'GetPaid_Reports_Report_Gateways', |
|
36 | - ), |
|
33 | + 'gateways' => array( |
|
34 | + 'label' => __( 'Payment Methods', 'invoicing' ), |
|
35 | + 'class' => 'GetPaid_Reports_Report_Gateways', |
|
36 | + ), |
|
37 | 37 | |
38 | - 'discounts' => array( |
|
39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
40 | - 'class' => 'GetPaid_Reports_Report_Discounts', |
|
41 | - ), |
|
38 | + 'discounts' => array( |
|
39 | + 'label' => __( 'Discount Codes', 'invoicing' ), |
|
40 | + 'class' => 'GetPaid_Reports_Report_Discounts', |
|
41 | + ), |
|
42 | 42 | |
43 | 43 | ); |
44 | 44 | |
45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
46 | - |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Retrieves the current range. |
|
51 | - * |
|
52 | - */ |
|
53 | - public function get_range() { |
|
54 | - $valid_ranges = $this->get_periods(); |
|
55 | - |
|
56 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
57 | - return sanitize_key( $_GET['date_range'] ); |
|
58 | - } |
|
59 | - |
|
60 | - return '7_days'; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Returns an array of date ranges. |
|
65 | - * |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - public function get_periods() { |
|
69 | - |
|
70 | - $periods = array( |
|
71 | - 'today' => __( 'Today', 'invoicing' ), |
|
72 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
73 | - 'week' => __( 'This week', 'invoicing' ), |
|
74 | - 'last_week' => __( 'Last week', 'invoicing' ), |
|
75 | - '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
76 | - 'month' => __( 'This month', 'invoicing' ), |
|
77 | - 'last_month' => __( 'Last month', 'invoicing' ), |
|
78 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
79 | - 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
80 | - 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
81 | - 'year' => __( 'This year', 'invoicing' ), |
|
82 | - 'last_year' => __( 'Last Year', 'invoicing' ), |
|
83 | - 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
84 | - ); |
|
85 | - |
|
86 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Displays the range selector. |
|
91 | - * |
|
92 | - */ |
|
93 | - public function display_range_selector() { |
|
94 | - |
|
95 | - $range = $this->get_range(); |
|
96 | - ?> |
|
45 | + $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
46 | + |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Retrieves the current range. |
|
51 | + * |
|
52 | + */ |
|
53 | + public function get_range() { |
|
54 | + $valid_ranges = $this->get_periods(); |
|
55 | + |
|
56 | + if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
57 | + return sanitize_key( $_GET['date_range'] ); |
|
58 | + } |
|
59 | + |
|
60 | + return '7_days'; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Returns an array of date ranges. |
|
65 | + * |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + public function get_periods() { |
|
69 | + |
|
70 | + $periods = array( |
|
71 | + 'today' => __( 'Today', 'invoicing' ), |
|
72 | + 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
73 | + 'week' => __( 'This week', 'invoicing' ), |
|
74 | + 'last_week' => __( 'Last week', 'invoicing' ), |
|
75 | + '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
76 | + 'month' => __( 'This month', 'invoicing' ), |
|
77 | + 'last_month' => __( 'Last month', 'invoicing' ), |
|
78 | + '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
79 | + 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
80 | + 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
81 | + 'year' => __( 'This year', 'invoicing' ), |
|
82 | + 'last_year' => __( 'Last Year', 'invoicing' ), |
|
83 | + 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
84 | + ); |
|
85 | + |
|
86 | + return apply_filters( 'getpaid_earning_periods', $periods ); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Displays the range selector. |
|
91 | + * |
|
92 | + */ |
|
93 | + public function display_range_selector() { |
|
94 | + |
|
95 | + $range = $this->get_range(); |
|
96 | + ?> |
|
97 | 97 | |
98 | 98 | <form method="get" class="getpaid-filter-earnings float-right"> |
99 | 99 | <?php getpaid_hidden_field( 'page', 'wpinv-reports' ); ?> |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | </form> |
116 | 116 | |
117 | 117 | <?php |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Displays the reports tab. |
|
122 | - * |
|
123 | - */ |
|
124 | - public function display() { |
|
125 | - ?> |
|
120 | + /** |
|
121 | + * Displays the reports tab. |
|
122 | + * |
|
123 | + */ |
|
124 | + public function display() { |
|
125 | + ?> |
|
126 | 126 | |
127 | 127 | <div class="mt-4" style="max-width: 1200px;"> |
128 | 128 | |
@@ -202,16 +202,16 @@ discard block |
||
202 | 202 | |
203 | 203 | <?php |
204 | 204 | |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Displays the left side. |
|
209 | - * |
|
210 | - */ |
|
211 | - public function display_left() { |
|
212 | - $graphs = wpinv_get_report_graphs(); |
|
207 | + /** |
|
208 | + * Displays the left side. |
|
209 | + * |
|
210 | + */ |
|
211 | + public function display_left() { |
|
212 | + $graphs = wpinv_get_report_graphs(); |
|
213 | 213 | |
214 | - ?> |
|
214 | + ?> |
|
215 | 215 | |
216 | 216 | <?php foreach ( $graphs as $key => $graph ) : ?> |
217 | 217 | <div class="row mb-4"> |
@@ -230,35 +230,35 @@ discard block |
||
230 | 230 | |
231 | 231 | <?php |
232 | 232 | |
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Retrieves the download url. |
|
237 | - * |
|
238 | - */ |
|
239 | - public function get_download_url( $graph, $file_type ) { |
|
240 | - |
|
241 | - return wp_nonce_url( |
|
242 | - add_query_arg( |
|
243 | - array( |
|
244 | - 'getpaid-admin-action' => 'download_graph', |
|
245 | - 'file_type' => urlencode( $file_type ), |
|
246 | - 'graph' => urlencode( $graph ), |
|
247 | - ) |
|
248 | - ), |
|
249 | - 'getpaid-nonce', |
|
250 | - 'getpaid-nonce' |
|
251 | - ); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Retrieves the download url. |
|
237 | + * |
|
238 | + */ |
|
239 | + public function get_download_url( $graph, $file_type ) { |
|
240 | + |
|
241 | + return wp_nonce_url( |
|
242 | + add_query_arg( |
|
243 | + array( |
|
244 | + 'getpaid-admin-action' => 'download_graph', |
|
245 | + 'file_type' => urlencode( $file_type ), |
|
246 | + 'graph' => urlencode( $graph ), |
|
247 | + ) |
|
248 | + ), |
|
249 | + 'getpaid-nonce', |
|
250 | + 'getpaid-nonce' |
|
251 | + ); |
|
252 | 252 | |
253 | - } |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * Displays the right side. |
|
257 | - * |
|
258 | - */ |
|
259 | - public function display_right() { |
|
255 | + /** |
|
256 | + * Displays the right side. |
|
257 | + * |
|
258 | + */ |
|
259 | + public function display_right() { |
|
260 | 260 | |
261 | - ?> |
|
261 | + ?> |
|
262 | 262 | |
263 | 263 | <?php foreach ( $this->views as $key => $view ) : ?> |
264 | 264 | <div class="row mb-4"> |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | </div> |
288 | 288 | <div class="card-body"> |
289 | 289 | <?php |
290 | - $class = $view['class']; |
|
291 | - $class = new $class(); |
|
292 | - $class->display_stats(); |
|
293 | - ?> |
|
290 | + $class = $view['class']; |
|
291 | + $class = new $class(); |
|
292 | + $class->display_stats(); |
|
293 | + ?> |
|
294 | 294 | </div> |
295 | 295 | </div> |
296 | 296 | </div> |
@@ -299,67 +299,67 @@ discard block |
||
299 | 299 | |
300 | 300 | <?php |
301 | 301 | |
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns a list of report cards. |
|
306 | - * |
|
307 | - */ |
|
308 | - public function get_cards() { |
|
309 | - |
|
310 | - $cards = array( |
|
311 | - 'total_sales' => array( |
|
312 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
313 | - 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
314 | - ), |
|
315 | - 'net_sales' => array( |
|
316 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
317 | - 'label' => __( 'Net Revenue', 'invoicing' ), |
|
318 | - ), |
|
319 | - 'average_sales' => array( |
|
320 | - 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
321 | - 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
322 | - ), |
|
323 | - 'average_total_sales' => array( |
|
324 | - 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
325 | - 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
326 | - ), |
|
327 | - 'total_invoices' => array( |
|
328 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
329 | - 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
330 | - ), |
|
331 | - 'total_items' => array( |
|
332 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
333 | - 'label' => __( 'Purchased Items', 'invoicing' ), |
|
334 | - ), |
|
335 | - 'refunded_items' => array( |
|
336 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
337 | - 'label' => __( 'Refunded Items', 'invoicing' ), |
|
338 | - ), |
|
339 | - 'total_tax' => array( |
|
340 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
341 | - 'label' => __( 'Tax', 'invoicing' ), |
|
342 | - ), |
|
343 | - 'total_refunded_tax' => array( |
|
344 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
345 | - 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
346 | - ), |
|
347 | - 'total_fees' => array( |
|
348 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
349 | - 'label' => __( 'Fees', 'invoicing' ), |
|
350 | - ), |
|
351 | - 'total_refunds' => array( |
|
352 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
353 | - 'label' => __( 'Refunded', 'invoicing' ), |
|
354 | - ), |
|
355 | - 'total_discount' => array( |
|
356 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
357 | - 'label' => __( 'Discounted', 'invoicing' ), |
|
358 | - ), |
|
359 | - ); |
|
360 | - |
|
361 | - return apply_filters( 'wpinv_report_cards', $cards ); |
|
362 | - } |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns a list of report cards. |
|
306 | + * |
|
307 | + */ |
|
308 | + public function get_cards() { |
|
309 | + |
|
310 | + $cards = array( |
|
311 | + 'total_sales' => array( |
|
312 | + 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
313 | + 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
314 | + ), |
|
315 | + 'net_sales' => array( |
|
316 | + 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
317 | + 'label' => __( 'Net Revenue', 'invoicing' ), |
|
318 | + ), |
|
319 | + 'average_sales' => array( |
|
320 | + 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
321 | + 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
322 | + ), |
|
323 | + 'average_total_sales' => array( |
|
324 | + 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
325 | + 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
326 | + ), |
|
327 | + 'total_invoices' => array( |
|
328 | + 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
329 | + 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
330 | + ), |
|
331 | + 'total_items' => array( |
|
332 | + 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
333 | + 'label' => __( 'Purchased Items', 'invoicing' ), |
|
334 | + ), |
|
335 | + 'refunded_items' => array( |
|
336 | + 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
337 | + 'label' => __( 'Refunded Items', 'invoicing' ), |
|
338 | + ), |
|
339 | + 'total_tax' => array( |
|
340 | + 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
341 | + 'label' => __( 'Tax', 'invoicing' ), |
|
342 | + ), |
|
343 | + 'total_refunded_tax' => array( |
|
344 | + 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
345 | + 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
346 | + ), |
|
347 | + 'total_fees' => array( |
|
348 | + 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
349 | + 'label' => __( 'Fees', 'invoicing' ), |
|
350 | + ), |
|
351 | + 'total_refunds' => array( |
|
352 | + 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
353 | + 'label' => __( 'Refunded', 'invoicing' ), |
|
354 | + ), |
|
355 | + 'total_discount' => array( |
|
356 | + 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
357 | + 'label' => __( 'Discounted', 'invoicing' ), |
|
358 | + ), |
|
359 | + ); |
|
360 | + |
|
361 | + return apply_filters( 'wpinv_report_cards', $cards ); |
|
362 | + } |
|
363 | 363 | |
364 | 364 | |
365 | 365 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Report Class. |
@@ -23,26 +23,26 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct() { |
25 | 25 | |
26 | - $this->views = array( |
|
26 | + $this->views = array( |
|
27 | 27 | |
28 | 28 | 'items' => array( |
29 | - 'label' => __( 'Items', 'invoicing' ), |
|
29 | + 'label' => __('Items', 'invoicing'), |
|
30 | 30 | 'class' => 'GetPaid_Reports_Report_Items', |
31 | 31 | ), |
32 | 32 | |
33 | 33 | 'gateways' => array( |
34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
34 | + 'label' => __('Payment Methods', 'invoicing'), |
|
35 | 35 | 'class' => 'GetPaid_Reports_Report_Gateways', |
36 | 36 | ), |
37 | 37 | |
38 | 38 | 'discounts' => array( |
39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
39 | + 'label' => __('Discount Codes', 'invoicing'), |
|
40 | 40 | 'class' => 'GetPaid_Reports_Report_Discounts', |
41 | 41 | ), |
42 | 42 | |
43 | 43 | ); |
44 | 44 | |
45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
45 | + $this->views = apply_filters('wpinv_report_views', $this->views); |
|
46 | 46 | |
47 | 47 | } |
48 | 48 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | public function get_range() { |
54 | 54 | $valid_ranges = $this->get_periods(); |
55 | 55 | |
56 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
57 | - return sanitize_key( $_GET['date_range'] ); |
|
56 | + if (isset($_GET['date_range']) && array_key_exists($_GET['date_range'], $valid_ranges)) { |
|
57 | + return sanitize_key($_GET['date_range']); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return '7_days'; |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | public function get_periods() { |
69 | 69 | |
70 | 70 | $periods = array( |
71 | - 'today' => __( 'Today', 'invoicing' ), |
|
72 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
73 | - 'week' => __( 'This week', 'invoicing' ), |
|
74 | - 'last_week' => __( 'Last week', 'invoicing' ), |
|
75 | - '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
76 | - 'month' => __( 'This month', 'invoicing' ), |
|
77 | - 'last_month' => __( 'Last month', 'invoicing' ), |
|
78 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
79 | - 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
80 | - 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
81 | - 'year' => __( 'This year', 'invoicing' ), |
|
82 | - 'last_year' => __( 'Last Year', 'invoicing' ), |
|
83 | - 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
71 | + 'today' => __('Today', 'invoicing'), |
|
72 | + 'yesterday' => __('Yesterday', 'invoicing'), |
|
73 | + 'week' => __('This week', 'invoicing'), |
|
74 | + 'last_week' => __('Last week', 'invoicing'), |
|
75 | + '7_days' => __('Last 7 days', 'invoicing'), |
|
76 | + 'month' => __('This month', 'invoicing'), |
|
77 | + 'last_month' => __('Last month', 'invoicing'), |
|
78 | + '30_days' => __('Last 30 days', 'invoicing'), |
|
79 | + 'quarter' => __('This Quarter', 'invoicing'), |
|
80 | + 'last_quarter' => __('Last Quarter', 'invoicing'), |
|
81 | + 'year' => __('This year', 'invoicing'), |
|
82 | + 'last_year' => __('Last Year', 'invoicing'), |
|
83 | + 'custom' => __('Custom Date Range', 'invoicing'), |
|
84 | 84 | ); |
85 | 85 | |
86 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
86 | + return apply_filters('getpaid_earning_periods', $periods); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -96,21 +96,21 @@ discard block |
||
96 | 96 | ?> |
97 | 97 | |
98 | 98 | <form method="get" class="getpaid-filter-earnings float-right"> |
99 | - <?php getpaid_hidden_field( 'page', 'wpinv-reports' ); ?> |
|
100 | - <?php getpaid_hidden_field( 'tab', 'reports' ); ?> |
|
99 | + <?php getpaid_hidden_field('page', 'wpinv-reports'); ?> |
|
100 | + <?php getpaid_hidden_field('tab', 'reports'); ?> |
|
101 | 101 | <select name='date_range'> |
102 | - <?php foreach( $this->get_periods() as $key => $label ) :?> |
|
103 | - <option value="<?php echo sanitize_key( $key ); ?>" <?php selected( $key, $range ); ?>><?php echo sanitize_text_field( $label ); ?></option> |
|
104 | - <?php endforeach;?> |
|
102 | + <?php foreach ($this->get_periods() as $key => $label) :?> |
|
103 | + <option value="<?php echo sanitize_key($key); ?>" <?php selected($key, $range); ?>><?php echo sanitize_text_field($label); ?></option> |
|
104 | + <?php endforeach; ?> |
|
105 | 105 | </select> |
106 | 106 | <span class="getpaid-date-range-picker <?php echo 'custom' == $range ? '' : 'd-none'; ?>"> |
107 | 107 | <input type="text" name="from" class="getpaid-from align-middle" /> |
108 | - <?php _e( 'to', 'invoicing' ); ?> |
|
108 | + <?php _e('to', 'invoicing'); ?> |
|
109 | 109 | <input type="text" name="to" class="getpaid-to align-middle" /> |
110 | 110 | </span> |
111 | 111 | <button type="submit" class="button button-primary"> |
112 | 112 | <i class="fa fa-chevron-right fa-lg"></i> |
113 | - <span class="screen-reader-text"><?php _e( 'View Reports', 'invoicing' ); ?></span> |
|
113 | + <span class="screen-reader-text"><?php _e('View Reports', 'invoicing'); ?></span> |
|
114 | 114 | </button> |
115 | 115 | </form> |
116 | 116 | |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | |
160 | 160 | <div class="col-12 col-md-4"> |
161 | 161 | <div class="row getpaid-report-cards"> |
162 | - <?php foreach( $this->get_cards() as $key => $card ) : ?> |
|
162 | + <?php foreach ($this->get_cards() as $key => $card) : ?> |
|
163 | 163 | <div class="col-12 mb-4"> |
164 | 164 | |
165 | - <!-- <?php echo sanitize_text_field( $card['label'] ); ?> Card --> |
|
166 | - <div class="card p-0 m-0 shadow-none <?php echo sanitize_html_class( $key ); ?>"> |
|
165 | + <!-- <?php echo sanitize_text_field($card['label']); ?> Card --> |
|
166 | + <div class="card p-0 m-0 shadow-none <?php echo sanitize_html_class($key); ?>"> |
|
167 | 167 | |
168 | 168 | <div class="card-body"> |
169 | 169 | |
170 | 170 | <p class="getpaid-current text-uppercase small mb-2"> |
171 | - <strong><?php echo sanitize_text_field( $card['label'] ); ?></strong> |
|
172 | - <span title="<?php echo esc_attr( $card['description'] ); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span> |
|
171 | + <strong><?php echo sanitize_text_field($card['label']); ?></strong> |
|
172 | + <span title="<?php echo esc_attr($card['description']); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span> |
|
173 | 173 | </p> |
174 | 174 | <h5 class="font-weight-bold mb-0"> |
175 | 175 | <span class="getpaid-report-card-value"> |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | |
181 | 181 | <hr> |
182 | 182 | |
183 | - <p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php _e( 'Previous Period', 'invoicing' ); ?></strong></p> |
|
183 | + <p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php _e('Previous Period', 'invoicing'); ?></strong></p> |
|
184 | 184 | <h5 class="getpaid-report-card-previous-value font-weight-bold text-muted mb-0"> |
185 | 185 | <span class="spinner is-active float-none"></span> |
186 | 186 | </h5> |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | </div> |
189 | 189 | |
190 | 190 | </div> |
191 | - <!-- <?php echo sanitize_text_field( $card['label'] ); ?> Card --> |
|
191 | + <!-- <?php echo sanitize_text_field($card['label']); ?> Card --> |
|
192 | 192 | |
193 | 193 | </div> |
194 | 194 | <?php endforeach; ?> |
@@ -213,15 +213,15 @@ discard block |
||
213 | 213 | |
214 | 214 | ?> |
215 | 215 | |
216 | - <?php foreach ( $graphs as $key => $graph ) : ?> |
|
216 | + <?php foreach ($graphs as $key => $graph) : ?> |
|
217 | 217 | <div class="row mb-4"> |
218 | 218 | <div class="col-12"> |
219 | 219 | <div class="card m-0 p-0 single-report-card" style="max-width:100%"> |
220 | 220 | <div class="card-header"> |
221 | - <strong><?php echo wpinv_clean( $graph ); ?></strong> |
|
221 | + <strong><?php echo wpinv_clean($graph); ?></strong> |
|
222 | 222 | </div> |
223 | 223 | <div class="card-body"> |
224 | - <canvas id="getpaid-chartjs-<?php echo sanitize_key( $key ); ?>"></canvas> |
|
224 | + <canvas id="getpaid-chartjs-<?php echo sanitize_key($key); ?>"></canvas> |
|
225 | 225 | </div> |
226 | 226 | </div> |
227 | 227 | </div> |
@@ -236,14 +236,14 @@ discard block |
||
236 | 236 | * Retrieves the download url. |
237 | 237 | * |
238 | 238 | */ |
239 | - public function get_download_url( $graph, $file_type ) { |
|
239 | + public function get_download_url($graph, $file_type) { |
|
240 | 240 | |
241 | 241 | return wp_nonce_url( |
242 | 242 | add_query_arg( |
243 | 243 | array( |
244 | 244 | 'getpaid-admin-action' => 'download_graph', |
245 | - 'file_type' => urlencode( $file_type ), |
|
246 | - 'graph' => urlencode( $graph ), |
|
245 | + 'file_type' => urlencode($file_type), |
|
246 | + 'graph' => urlencode($graph), |
|
247 | 247 | ) |
248 | 248 | ), |
249 | 249 | 'getpaid-nonce', |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | |
261 | 261 | ?> |
262 | 262 | |
263 | - <?php foreach ( $this->views as $key => $view ) : ?> |
|
263 | + <?php foreach ($this->views as $key => $view) : ?> |
|
264 | 264 | <div class="row mb-4"> |
265 | 265 | <div class="col-12"> |
266 | 266 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -270,17 +270,17 @@ discard block |
||
270 | 270 | <strong><?php echo $view['label']; ?></strong> |
271 | 271 | </div> |
272 | 272 | <div class="col-3"> |
273 | - <a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>"> |
|
273 | + <a title="<?php esc_attr_e('Download JSON', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'json')); ?>"> |
|
274 | 274 | <i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i> |
275 | - <span class="screen-reader-text"><?php _e( 'Download JSON', 'invoicing' ); ?></span> |
|
275 | + <span class="screen-reader-text"><?php _e('Download JSON', 'invoicing'); ?></span> |
|
276 | 276 | </a> |
277 | - <a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>"> |
|
277 | + <a title="<?php esc_attr_e('Download CSV', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'csv')); ?>"> |
|
278 | 278 | <i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i> |
279 | - <span class="screen-reader-text"><?php _e( 'Download CSV', 'invoicing' ); ?></span> |
|
279 | + <span class="screen-reader-text"><?php _e('Download CSV', 'invoicing'); ?></span> |
|
280 | 280 | </a> |
281 | - <a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>"> |
|
281 | + <a title="<?php esc_attr_e('Download XML', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'xml')); ?>"> |
|
282 | 282 | <i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i> |
283 | - <span class="screen-reader-text"><?php _e( 'Download XML', 'invoicing' ); ?></span> |
|
283 | + <span class="screen-reader-text"><?php _e('Download XML', 'invoicing'); ?></span> |
|
284 | 284 | </a> |
285 | 285 | </div> |
286 | 286 | </div> |
@@ -309,56 +309,56 @@ discard block |
||
309 | 309 | |
310 | 310 | $cards = array( |
311 | 311 | 'total_sales' => array( |
312 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
313 | - 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
312 | + 'description' => __('Gross sales in the period.', 'invoicing'), |
|
313 | + 'label' => __('Gross Revenue', 'invoicing'), |
|
314 | 314 | ), |
315 | 315 | 'net_sales' => array( |
316 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
317 | - 'label' => __( 'Net Revenue', 'invoicing' ), |
|
316 | + 'description' => __('Net sales in the period.', 'invoicing'), |
|
317 | + 'label' => __('Net Revenue', 'invoicing'), |
|
318 | 318 | ), |
319 | 319 | 'average_sales' => array( |
320 | - 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
321 | - 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
320 | + 'description' => __('Average net daily/monthly sales.', 'invoicing'), |
|
321 | + 'label' => __('Avg. Net Sales', 'invoicing'), |
|
322 | 322 | ), |
323 | 323 | 'average_total_sales' => array( |
324 | - 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
325 | - 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
324 | + 'description' => __('Average gross daily/monthly sales.', 'invoicing'), |
|
325 | + 'label' => __('Avg. Gross Sales', 'invoicing'), |
|
326 | 326 | ), |
327 | 327 | 'total_invoices' => array( |
328 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
329 | - 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
328 | + 'description' => __('Number of paid invoices.', 'invoicing'), |
|
329 | + 'label' => __('Paid Invoices', 'invoicing'), |
|
330 | 330 | ), |
331 | 331 | 'total_items' => array( |
332 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
333 | - 'label' => __( 'Purchased Items', 'invoicing' ), |
|
332 | + 'description' => __('Number of items purchased.', 'invoicing'), |
|
333 | + 'label' => __('Purchased Items', 'invoicing'), |
|
334 | 334 | ), |
335 | 335 | 'refunded_items' => array( |
336 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
337 | - 'label' => __( 'Refunded Items', 'invoicing' ), |
|
336 | + 'description' => __('Number of items refunded.', 'invoicing'), |
|
337 | + 'label' => __('Refunded Items', 'invoicing'), |
|
338 | 338 | ), |
339 | 339 | 'total_tax' => array( |
340 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
341 | - 'label' => __( 'Tax', 'invoicing' ), |
|
340 | + 'description' => __('Total charged for taxes.', 'invoicing'), |
|
341 | + 'label' => __('Tax', 'invoicing'), |
|
342 | 342 | ), |
343 | 343 | 'total_refunded_tax' => array( |
344 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
345 | - 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
344 | + 'description' => __('Total refunded for taxes.', 'invoicing'), |
|
345 | + 'label' => __('Refunded Tax', 'invoicing'), |
|
346 | 346 | ), |
347 | 347 | 'total_fees' => array( |
348 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
349 | - 'label' => __( 'Fees', 'invoicing' ), |
|
348 | + 'description' => __('Total fees charged.', 'invoicing'), |
|
349 | + 'label' => __('Fees', 'invoicing'), |
|
350 | 350 | ), |
351 | 351 | 'total_refunds' => array( |
352 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
353 | - 'label' => __( 'Refunded', 'invoicing' ), |
|
352 | + 'description' => __('Total of refunded invoices.', 'invoicing'), |
|
353 | + 'label' => __('Refunded', 'invoicing'), |
|
354 | 354 | ), |
355 | 355 | 'total_discount' => array( |
356 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
357 | - 'label' => __( 'Discounted', 'invoicing' ), |
|
356 | + 'description' => __('Total of discounts used.', 'invoicing'), |
|
357 | + 'label' => __('Discounted', 'invoicing'), |
|
358 | 358 | ), |
359 | 359 | ); |
360 | 360 | |
361 | - return apply_filters( 'wpinv_report_cards', $cards ); |
|
361 | + return apply_filters('wpinv_report_cards', $cards); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 |