@@ -117,14 +117,14 @@ |
||
117 | 117 | */ |
118 | 118 | function getpaid_doing_it_wrong( $function, $message, $version ) { |
119 | 119 | |
120 | - $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
121 | - |
|
122 | - if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
123 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
124 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
125 | - } else { |
|
126 | - _doing_it_wrong( $function, $message, $version ); |
|
127 | - } |
|
120 | + $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
121 | + |
|
122 | + if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
123 | + do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
124 | + error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
125 | + } else { |
|
126 | + _doing_it_wrong( $function, $message, $version ); |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
130 | 130 |
@@ -13,128 +13,128 @@ |
||
13 | 13 | class GetPaid_Payment_Forms { |
14 | 14 | |
15 | 15 | /** |
16 | - * Class constructor |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - |
|
21 | - // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | - |
|
25 | - // Sync form amount whenever invoice statuses change. |
|
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | - |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Increments a form's revenue whenever there is a payment. |
|
34 | - * |
|
35 | - * @param WPInv_Invoice $invoice |
|
36 | - */ |
|
37 | - public function increment_form_revenue( $invoice ) { |
|
38 | - |
|
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | - $form->save(); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Decreases form revenue whenever invoice payment changes. |
|
49 | - * |
|
50 | - * @param WPInv_Invoice $invoice |
|
51 | - */ |
|
52 | - public function decrease_form_revenue( $invoice ) { |
|
53 | - |
|
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | - $form->save(); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates a form's failed amount. |
|
64 | - * |
|
65 | - * @param WPInv_Invoice $invoice |
|
66 | - * @param string $from |
|
67 | - * @param string $to |
|
68 | - */ |
|
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | - |
|
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | - $form->save(); |
|
79 | - } |
|
80 | - |
|
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | - $form->save(); |
|
84 | - } |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Updates a form's refunded amount. |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice |
|
92 | - * @param string $from |
|
93 | - * @param string $to |
|
94 | - */ |
|
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | - |
|
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
99 | - return; |
|
100 | - } |
|
101 | - |
|
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | - $form->save(); |
|
105 | - } |
|
106 | - |
|
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | - $form->save(); |
|
110 | - } |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Updates a form's cancelled amount. |
|
116 | - * |
|
117 | - * @param WPInv_Invoice $invoice |
|
118 | - * @param string $from |
|
119 | - * @param string $to |
|
120 | - */ |
|
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | - |
|
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | - $form->save(); |
|
131 | - } |
|
132 | - |
|
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | - $form->save(); |
|
136 | - } |
|
137 | - |
|
138 | - } |
|
16 | + * Class constructor |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + |
|
21 | + // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | + add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | + add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | + |
|
25 | + // Sync form amount whenever invoice statuses change. |
|
26 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | + |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Increments a form's revenue whenever there is a payment. |
|
34 | + * |
|
35 | + * @param WPInv_Invoice $invoice |
|
36 | + */ |
|
37 | + public function increment_form_revenue( $invoice ) { |
|
38 | + |
|
39 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | + if ( $form->get_id() ) { |
|
41 | + $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | + $form->save(); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Decreases form revenue whenever invoice payment changes. |
|
49 | + * |
|
50 | + * @param WPInv_Invoice $invoice |
|
51 | + */ |
|
52 | + public function decrease_form_revenue( $invoice ) { |
|
53 | + |
|
54 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | + if ( $form->get_id() ) { |
|
56 | + $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | + $form->save(); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates a form's failed amount. |
|
64 | + * |
|
65 | + * @param WPInv_Invoice $invoice |
|
66 | + * @param string $from |
|
67 | + * @param string $to |
|
68 | + */ |
|
69 | + public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | + |
|
71 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | + if ( $form->get_id() ) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + if ( 'wpi-failed' == $from ) { |
|
77 | + $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | + $form->save(); |
|
79 | + } |
|
80 | + |
|
81 | + if ( 'wpi-failed' == $to ) { |
|
82 | + $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | + $form->save(); |
|
84 | + } |
|
85 | + |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Updates a form's refunded amount. |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice |
|
92 | + * @param string $from |
|
93 | + * @param string $to |
|
94 | + */ |
|
95 | + public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | + |
|
97 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | + if ( $form->get_id() ) { |
|
99 | + return; |
|
100 | + } |
|
101 | + |
|
102 | + if ( 'wpi-refunded' == $from ) { |
|
103 | + $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | + $form->save(); |
|
105 | + } |
|
106 | + |
|
107 | + if ( 'wpi-refunded' == $to ) { |
|
108 | + $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | + $form->save(); |
|
110 | + } |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Updates a form's cancelled amount. |
|
116 | + * |
|
117 | + * @param WPInv_Invoice $invoice |
|
118 | + * @param string $from |
|
119 | + * @param string $to |
|
120 | + */ |
|
121 | + public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | + |
|
123 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | + if ( $form->get_id() ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ( 'wpi-cancelled' == $from ) { |
|
129 | + $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | + $form->save(); |
|
131 | + } |
|
132 | + |
|
133 | + if ( 'wpi-cancelled' == $to ) { |
|
134 | + $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | + $form->save(); |
|
136 | + } |
|
137 | + |
|
138 | + } |
|
139 | 139 | |
140 | 140 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,77 +11,77 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Pagination { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function get( $args = array() ) { |
|
22 | - global $wp_query; |
|
23 | - |
|
24 | - $defaults = array( |
|
25 | - 'class' => '', |
|
26 | - 'mid_size' => 2, |
|
27 | - 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | - 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | - 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | - 'before_paging' => '', |
|
31 | - 'after_paging' => '', |
|
32 | - 'type' => 'array', |
|
33 | - 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | - 'links' => array() // an array of links if using custom links, this includes the a tag. |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * Parse incoming $args into an array and merge it with $defaults |
|
39 | - */ |
|
40 | - $args = wp_parse_args( $args, $defaults ); |
|
41 | - |
|
42 | - $output = ''; |
|
43 | - |
|
44 | - // Don't print empty markup if there's only one page. |
|
45 | - if ( $args['total'] > 1 ) { |
|
46 | - |
|
47 | - // Set up paginated links. |
|
48 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
49 | - |
|
50 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
51 | - |
|
52 | - // make the output bootstrap ready |
|
53 | - $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
54 | - if ( ! empty( $links ) ) { |
|
55 | - foreach ( $links as $link ) { |
|
56 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
57 | - $links_html .= "<li class='page-item $active'>"; |
|
58 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
59 | - $links_html .= "</li>"; |
|
60 | - } |
|
61 | - } |
|
62 | - $links_html .= "</ul>"; |
|
63 | - |
|
64 | - if ( $links ) { |
|
65 | - $output .= '<section class="px-0 py-2 w-100">'; |
|
66 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
67 | - $output .= '</section>'; |
|
68 | - } |
|
69 | - |
|
70 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
71 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
72 | - } |
|
73 | - |
|
74 | - if ( $output ) { |
|
75 | - if ( ! empty( $args['before_paging'] ) ) { |
|
76 | - $output = $args['before_paging'] . $output; |
|
77 | - } |
|
78 | - |
|
79 | - if ( ! empty( $args['after_paging'] ) ) { |
|
80 | - $output = $output . $args['after_paging']; |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - return $output; |
|
85 | - } |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function get( $args = array() ) { |
|
22 | + global $wp_query; |
|
23 | + |
|
24 | + $defaults = array( |
|
25 | + 'class' => '', |
|
26 | + 'mid_size' => 2, |
|
27 | + 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | + 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | + 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | + 'before_paging' => '', |
|
31 | + 'after_paging' => '', |
|
32 | + 'type' => 'array', |
|
33 | + 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | + 'links' => array() // an array of links if using custom links, this includes the a tag. |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * Parse incoming $args into an array and merge it with $defaults |
|
39 | + */ |
|
40 | + $args = wp_parse_args( $args, $defaults ); |
|
41 | + |
|
42 | + $output = ''; |
|
43 | + |
|
44 | + // Don't print empty markup if there's only one page. |
|
45 | + if ( $args['total'] > 1 ) { |
|
46 | + |
|
47 | + // Set up paginated links. |
|
48 | + $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
49 | + |
|
50 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
51 | + |
|
52 | + // make the output bootstrap ready |
|
53 | + $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
54 | + if ( ! empty( $links ) ) { |
|
55 | + foreach ( $links as $link ) { |
|
56 | + $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
57 | + $links_html .= "<li class='page-item $active'>"; |
|
58 | + $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
59 | + $links_html .= "</li>"; |
|
60 | + } |
|
61 | + } |
|
62 | + $links_html .= "</ul>"; |
|
63 | + |
|
64 | + if ( $links ) { |
|
65 | + $output .= '<section class="px-0 py-2 w-100">'; |
|
66 | + $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
67 | + $output .= '</section>'; |
|
68 | + } |
|
69 | + |
|
70 | + $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
71 | + $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
72 | + } |
|
73 | + |
|
74 | + if ( $output ) { |
|
75 | + if ( ! empty( $args['before_paging'] ) ) { |
|
76 | + $output = $args['before_paging'] . $output; |
|
77 | + } |
|
78 | + |
|
79 | + if ( ! empty( $args['after_paging'] ) ) { |
|
80 | + $output = $output . $args['after_paging']; |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + return $output; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | \ No newline at end of file |
@@ -31,16 +31,16 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | - $can_checkout = true; // Always true for now |
|
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 | /** |
@@ -51,22 +51,22 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
53 | 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 ); |
|
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() { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | function wpinv_send_to_failed_page( $args = null ) { |
92 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
92 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
93 | 93 | |
94 | 94 | if ( !empty( $args ) ) { |
95 | 95 | // Check for backward compatibility |
@@ -109,55 +109,55 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | function wpinv_get_checkout_uri( $args = array() ) { |
112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
112 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
114 | 114 | |
115 | - if ( !empty( $args ) ) { |
|
116 | - // Check for backward compatibility |
|
117 | - if ( is_string( $args ) ) |
|
118 | - $args = str_replace( '?', '', $args ); |
|
115 | + if ( !empty( $args ) ) { |
|
116 | + // Check for backward compatibility |
|
117 | + if ( is_string( $args ) ) |
|
118 | + $args = str_replace( '?', '', $args ); |
|
119 | 119 | |
120 | - $args = wp_parse_args( $args ); |
|
120 | + $args = wp_parse_args( $args ); |
|
121 | 121 | |
122 | - $uri = add_query_arg( $args, $uri ); |
|
123 | - } |
|
122 | + $uri = add_query_arg( $args, $uri ); |
|
123 | + } |
|
124 | 124 | |
125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
125 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
126 | 126 | |
127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
127 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
128 | 128 | |
129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | - } |
|
129 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | + } |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
133 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | function wpinv_get_success_page_url( $query_string = null ) { |
137 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
138 | - $success_page = get_permalink( $success_page ); |
|
137 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
138 | + $success_page = get_permalink( $success_page ); |
|
139 | 139 | |
140 | - if ( $query_string ) |
|
141 | - $success_page .= $query_string; |
|
140 | + if ( $query_string ) |
|
141 | + $success_page .= $query_string; |
|
142 | 142 | |
143 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
143 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
147 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
148 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
147 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
148 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
149 | 149 | |
150 | - if ( $extras ) |
|
151 | - $uri .= $extras; |
|
150 | + if ( $extras ) |
|
151 | + $uri .= $extras; |
|
152 | 152 | |
153 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
153 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | function wpinv_is_failed_transaction_page() { |
157 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
158 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
157 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
158 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
159 | 159 | |
160 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
160 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -232,36 +232,36 @@ discard block |
||
232 | 232 | $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
233 | 233 | |
234 | 234 | if ( $require_billing_details ) { |
235 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
236 | - $required_fields['first_name'] = array( |
|
237 | - 'error_id' => 'invalid_first_name', |
|
238 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
239 | - ); |
|
240 | - } |
|
241 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
242 | - $required_fields['address'] = array( |
|
243 | - 'error_id' => 'invalid_address', |
|
244 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
245 | - ); |
|
246 | - } |
|
247 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
248 | - $required_fields['city'] = array( |
|
249 | - 'error_id' => 'invalid_city', |
|
250 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
251 | - ); |
|
252 | - } |
|
253 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
254 | - $required_fields['state'] = array( |
|
255 | - 'error_id' => 'invalid_state', |
|
256 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
257 | - ); |
|
258 | - } |
|
259 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
260 | - $required_fields['country'] = array( |
|
261 | - 'error_id' => 'invalid_country', |
|
262 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
263 | - ); |
|
264 | - } |
|
235 | + if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
236 | + $required_fields['first_name'] = array( |
|
237 | + 'error_id' => 'invalid_first_name', |
|
238 | + 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
239 | + ); |
|
240 | + } |
|
241 | + if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
242 | + $required_fields['address'] = array( |
|
243 | + 'error_id' => 'invalid_address', |
|
244 | + 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
245 | + ); |
|
246 | + } |
|
247 | + if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
248 | + $required_fields['city'] = array( |
|
249 | + 'error_id' => 'invalid_city', |
|
250 | + 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
251 | + ); |
|
252 | + } |
|
253 | + if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
254 | + $required_fields['state'] = array( |
|
255 | + 'error_id' => 'invalid_state', |
|
256 | + 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
257 | + ); |
|
258 | + } |
|
259 | + if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
260 | + $required_fields['country'] = array( |
|
261 | + 'error_id' => 'invalid_country', |
|
262 | + 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
263 | + ); |
|
264 | + } |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
@@ -15,136 +15,136 @@ |
||
15 | 15 | class WPInv_REST_Invoice_Controller extends GetPaid_REST_Posts_Controller { |
16 | 16 | |
17 | 17 | /** |
18 | - * Post type. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $post_type = 'wpi_invoice'; |
|
23 | - |
|
24 | - /** |
|
25 | - * The base of this controller's route. |
|
26 | - * |
|
27 | - * @since 1.0.13 |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $rest_base = 'invoices'; |
|
31 | - |
|
32 | - /** Contains this controller's class name. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $crud_class = 'WPInv_Invoice'; |
|
18 | + * Post type. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $post_type = 'wpi_invoice'; |
|
37 | 23 | |
38 | 24 | /** |
39 | - * Retrieves the query params for the invoices collection. |
|
40 | - * |
|
41 | - * @since 1.0.13 |
|
42 | - * |
|
43 | - * @return array Collection parameters. |
|
44 | - */ |
|
45 | - public function get_collection_params() { |
|
46 | - |
|
47 | - $params = array_merge( |
|
48 | - |
|
49 | - parent::get_collection_params(), |
|
50 | - |
|
51 | - array( |
|
52 | - |
|
53 | - |
|
54 | - 'customers' => array( |
|
55 | - 'description' => __( 'Limit result set to invoices for specific user ids.', 'invoicing' ), |
|
56 | - 'type' => 'array', |
|
57 | - 'items' => array( |
|
58 | - 'type' => 'integer', |
|
59 | - ), |
|
60 | - 'default' => array(), |
|
61 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
62 | - ), |
|
63 | - |
|
64 | - 'exclude_customers' => array( |
|
65 | - 'description' => __( 'Exclude invoices to specific users.', 'invoicing' ), |
|
66 | - 'type' => 'array', |
|
67 | - 'items' => array( |
|
68 | - 'type' => 'integer', |
|
69 | - ), |
|
70 | - 'default' => array(), |
|
71 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
72 | - ), |
|
73 | - |
|
74 | - 'parent' => array( |
|
75 | - 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
76 | - 'type' => 'array', |
|
77 | - 'items' => array( |
|
78 | - 'type' => 'integer', |
|
79 | - ), |
|
80 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
81 | - 'default' => array(), |
|
82 | - ), |
|
83 | - |
|
84 | - 'parent_exclude' => array( |
|
85 | - 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
86 | - 'type' => 'array', |
|
87 | - 'items' => array( |
|
88 | - 'type' => 'integer', |
|
89 | - ), |
|
90 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
91 | - 'default' => array(), |
|
92 | - ), |
|
93 | - |
|
94 | - ) |
|
95 | - |
|
96 | - ); |
|
97 | - |
|
98 | - // Filter collection parameters for the invoices controller. |
|
99 | - return apply_filters( 'getpaid_rest_invoices_collection_params', $params, $this ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Determine the allowed query_vars for a get_items() response and |
|
104 | - * prepare for WP_Query. |
|
105 | - * |
|
106 | - * @param array $prepared_args Prepared arguments. |
|
107 | - * @param WP_REST_Request $request Request object. |
|
108 | - * @return array $query_args |
|
109 | - */ |
|
110 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
111 | - |
|
112 | - $query_args = parent::prepare_items_query( $prepared_args ); |
|
113 | - |
|
114 | - // Retrieve invoices for specific customers. |
|
115 | - if ( ! empty( $request['customers'] ) ) { |
|
116 | - $query_args['author__in'] = $request['customers']; |
|
117 | - } |
|
118 | - |
|
119 | - // Skip invoices for specific customers. |
|
120 | - if ( ! empty( $request['exclude_customers'] ) ) { |
|
121 | - $query_args['author__not_in'] = $request['exclude_customers']; |
|
122 | - } |
|
123 | - |
|
124 | - return apply_filters( 'getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this ); |
|
125 | - |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Retrieves a valid list of post statuses. |
|
130 | - * |
|
131 | - * @since 1.0.15 |
|
132 | - * |
|
133 | - * @return array A list of registered item statuses. |
|
134 | - */ |
|
135 | - public function get_post_statuses() { |
|
136 | - return array_keys( wpinv_get_invoice_statuses( true, false, $this->post_type ) ); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Saves a single invoice. |
|
141 | - * |
|
142 | - * @param WPInv_Invoice $invoice Invoice to save. |
|
143 | - * @return WP_Error|WPInv_Invoice |
|
144 | - */ |
|
145 | - protected function save_object( $invoice ) { |
|
146 | - $invoice->recalculate_total(); |
|
147 | - return parent::save_object( $invoice ); |
|
148 | - } |
|
25 | + * The base of this controller's route. |
|
26 | + * |
|
27 | + * @since 1.0.13 |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $rest_base = 'invoices'; |
|
31 | + |
|
32 | + /** Contains this controller's class name. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $crud_class = 'WPInv_Invoice'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Retrieves the query params for the invoices collection. |
|
40 | + * |
|
41 | + * @since 1.0.13 |
|
42 | + * |
|
43 | + * @return array Collection parameters. |
|
44 | + */ |
|
45 | + public function get_collection_params() { |
|
46 | + |
|
47 | + $params = array_merge( |
|
48 | + |
|
49 | + parent::get_collection_params(), |
|
50 | + |
|
51 | + array( |
|
52 | + |
|
53 | + |
|
54 | + 'customers' => array( |
|
55 | + 'description' => __( 'Limit result set to invoices for specific user ids.', 'invoicing' ), |
|
56 | + 'type' => 'array', |
|
57 | + 'items' => array( |
|
58 | + 'type' => 'integer', |
|
59 | + ), |
|
60 | + 'default' => array(), |
|
61 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
62 | + ), |
|
63 | + |
|
64 | + 'exclude_customers' => array( |
|
65 | + 'description' => __( 'Exclude invoices to specific users.', 'invoicing' ), |
|
66 | + 'type' => 'array', |
|
67 | + 'items' => array( |
|
68 | + 'type' => 'integer', |
|
69 | + ), |
|
70 | + 'default' => array(), |
|
71 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
72 | + ), |
|
73 | + |
|
74 | + 'parent' => array( |
|
75 | + 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
76 | + 'type' => 'array', |
|
77 | + 'items' => array( |
|
78 | + 'type' => 'integer', |
|
79 | + ), |
|
80 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
81 | + 'default' => array(), |
|
82 | + ), |
|
83 | + |
|
84 | + 'parent_exclude' => array( |
|
85 | + 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
86 | + 'type' => 'array', |
|
87 | + 'items' => array( |
|
88 | + 'type' => 'integer', |
|
89 | + ), |
|
90 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
91 | + 'default' => array(), |
|
92 | + ), |
|
93 | + |
|
94 | + ) |
|
95 | + |
|
96 | + ); |
|
97 | + |
|
98 | + // Filter collection parameters for the invoices controller. |
|
99 | + return apply_filters( 'getpaid_rest_invoices_collection_params', $params, $this ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Determine the allowed query_vars for a get_items() response and |
|
104 | + * prepare for WP_Query. |
|
105 | + * |
|
106 | + * @param array $prepared_args Prepared arguments. |
|
107 | + * @param WP_REST_Request $request Request object. |
|
108 | + * @return array $query_args |
|
109 | + */ |
|
110 | + protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
111 | + |
|
112 | + $query_args = parent::prepare_items_query( $prepared_args ); |
|
113 | + |
|
114 | + // Retrieve invoices for specific customers. |
|
115 | + if ( ! empty( $request['customers'] ) ) { |
|
116 | + $query_args['author__in'] = $request['customers']; |
|
117 | + } |
|
118 | + |
|
119 | + // Skip invoices for specific customers. |
|
120 | + if ( ! empty( $request['exclude_customers'] ) ) { |
|
121 | + $query_args['author__not_in'] = $request['exclude_customers']; |
|
122 | + } |
|
123 | + |
|
124 | + return apply_filters( 'getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this ); |
|
125 | + |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Retrieves a valid list of post statuses. |
|
130 | + * |
|
131 | + * @since 1.0.15 |
|
132 | + * |
|
133 | + * @return array A list of registered item statuses. |
|
134 | + */ |
|
135 | + public function get_post_statuses() { |
|
136 | + return array_keys( wpinv_get_invoice_statuses( true, false, $this->post_type ) ); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Saves a single invoice. |
|
141 | + * |
|
142 | + * @param WPInv_Invoice $invoice Invoice to save. |
|
143 | + * @return WP_Error|WPInv_Invoice |
|
144 | + */ |
|
145 | + protected function save_object( $invoice ) { |
|
146 | + $invoice->recalculate_total(); |
|
147 | + return parent::save_object( $invoice ); |
|
148 | + } |
|
149 | 149 | |
150 | 150 | } |
@@ -56,7 +56,7 @@ |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_admin_messages() { |
59 | - settings_errors( 'wpinv-notices' ); |
|
59 | + settings_errors( 'wpinv-notices' ); |
|
60 | 60 | } |
61 | 61 | add_action( 'admin_notices', 'wpinv_admin_messages' ); |
62 | 62 |
@@ -13,154 +13,154 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_MaxMind_Database_Service { |
15 | 15 | |
16 | - /** |
|
17 | - * The name of the MaxMind database to utilize. |
|
18 | - */ |
|
19 | - const DATABASE = 'GeoLite2-Country'; |
|
20 | - |
|
21 | - /** |
|
22 | - * The extension for the MaxMind database. |
|
23 | - */ |
|
24 | - const DATABASE_EXTENSION = '.mmdb'; |
|
25 | - |
|
26 | - /** |
|
27 | - * A prefix for the MaxMind database filename. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - private $database_prefix; |
|
32 | - |
|
33 | - /** |
|
34 | - * Class constructor. |
|
35 | - * |
|
36 | - * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | - */ |
|
38 | - public function __construct( $database_prefix ) { |
|
39 | - $this->database_prefix = $database_prefix; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Fetches the path that the database should be stored. |
|
44 | - * |
|
45 | - * @return string The local database path. |
|
46 | - */ |
|
47 | - public function get_database_path() { |
|
48 | - $uploads_dir = wp_upload_dir(); |
|
49 | - |
|
50 | - $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | - if ( ! empty( $this->database_prefix ) ) { |
|
52 | - $database_path .= $this->database_prefix . '-'; |
|
53 | - } |
|
54 | - $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | - |
|
56 | - // Filter the geolocation database storage path. |
|
57 | - return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Fetches the database from the MaxMind service. |
|
62 | - * |
|
63 | - * @param string $license_key The license key to be used when downloading the database. |
|
64 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | - */ |
|
66 | - public function download_database( $license_key ) { |
|
67 | - |
|
68 | - $download_uri = add_query_arg( |
|
69 | - array( |
|
70 | - 'edition_id' => self::DATABASE, |
|
71 | - 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | - 'suffix' => 'tar.gz', |
|
73 | - ), |
|
74 | - 'https://download.maxmind.com/app/geoip_download' |
|
75 | - ); |
|
76 | - |
|
77 | - // Needed for the download_url call right below. |
|
78 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | - |
|
80 | - $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | - |
|
82 | - if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | - // Transform the error into something more informative. |
|
84 | - $error_data = $tmp_archive_path->get_error_data(); |
|
85 | - if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | - return new WP_Error( |
|
87 | - 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | - __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | - } |
|
94 | - |
|
95 | - // Extract the database from the archive. |
|
96 | - return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Extracts the downloaded database. |
|
102 | - * |
|
103 | - * @param string $tmp_archive_path The database archive path. |
|
104 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | - */ |
|
106 | - protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | - |
|
108 | - // Extract the database from the archive. |
|
109 | - $tmp_database_path = ''; |
|
110 | - |
|
111 | - try { |
|
112 | - |
|
113 | - $file = new PharData( $tmp_archive_path ); |
|
114 | - $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
115 | - |
|
116 | - $file->extractTo( |
|
117 | - dirname( $tmp_archive_path ), |
|
118 | - trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
119 | - true |
|
120 | - ); |
|
121 | - |
|
122 | - } catch ( Exception $exception ) { |
|
123 | - return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
124 | - } finally { |
|
125 | - // Remove the archive since we only care about a single file in it. |
|
126 | - unlink( $tmp_archive_path ); |
|
127 | - } |
|
128 | - |
|
129 | - return $tmp_database_path; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Fetches the ISO country code associated with an IP address. |
|
134 | - * |
|
135 | - * @param string $ip_address The IP address to find the country code for. |
|
136 | - * @return string The country code for the IP address, or empty if not found. |
|
137 | - */ |
|
138 | - public function get_iso_country_code_for_ip( $ip_address ) { |
|
139 | - $country_code = ''; |
|
140 | - |
|
141 | - if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
142 | - return $country_code; |
|
143 | - } |
|
144 | - |
|
145 | - $database_path = $this->get_database_path(); |
|
146 | - if ( ! file_exists( $database_path ) ) { |
|
147 | - return $country_code; |
|
148 | - } |
|
149 | - |
|
150 | - try { |
|
151 | - $reader = new MaxMind\Db\Reader( $database_path ); |
|
152 | - $data = $reader->get( $ip_address ); |
|
153 | - |
|
154 | - if ( isset( $data['country']['iso_code'] ) ) { |
|
155 | - $country_code = $data['country']['iso_code']; |
|
156 | - } |
|
157 | - |
|
158 | - $reader->close(); |
|
159 | - } catch ( Exception $e ) { |
|
160 | - wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
161 | - } |
|
162 | - |
|
163 | - return $country_code; |
|
164 | - } |
|
16 | + /** |
|
17 | + * The name of the MaxMind database to utilize. |
|
18 | + */ |
|
19 | + const DATABASE = 'GeoLite2-Country'; |
|
20 | + |
|
21 | + /** |
|
22 | + * The extension for the MaxMind database. |
|
23 | + */ |
|
24 | + const DATABASE_EXTENSION = '.mmdb'; |
|
25 | + |
|
26 | + /** |
|
27 | + * A prefix for the MaxMind database filename. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + private $database_prefix; |
|
32 | + |
|
33 | + /** |
|
34 | + * Class constructor. |
|
35 | + * |
|
36 | + * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | + */ |
|
38 | + public function __construct( $database_prefix ) { |
|
39 | + $this->database_prefix = $database_prefix; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Fetches the path that the database should be stored. |
|
44 | + * |
|
45 | + * @return string The local database path. |
|
46 | + */ |
|
47 | + public function get_database_path() { |
|
48 | + $uploads_dir = wp_upload_dir(); |
|
49 | + |
|
50 | + $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | + if ( ! empty( $this->database_prefix ) ) { |
|
52 | + $database_path .= $this->database_prefix . '-'; |
|
53 | + } |
|
54 | + $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | + |
|
56 | + // Filter the geolocation database storage path. |
|
57 | + return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Fetches the database from the MaxMind service. |
|
62 | + * |
|
63 | + * @param string $license_key The license key to be used when downloading the database. |
|
64 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | + */ |
|
66 | + public function download_database( $license_key ) { |
|
67 | + |
|
68 | + $download_uri = add_query_arg( |
|
69 | + array( |
|
70 | + 'edition_id' => self::DATABASE, |
|
71 | + 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | + 'suffix' => 'tar.gz', |
|
73 | + ), |
|
74 | + 'https://download.maxmind.com/app/geoip_download' |
|
75 | + ); |
|
76 | + |
|
77 | + // Needed for the download_url call right below. |
|
78 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | + |
|
80 | + $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | + |
|
82 | + if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | + // Transform the error into something more informative. |
|
84 | + $error_data = $tmp_archive_path->get_error_data(); |
|
85 | + if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | + return new WP_Error( |
|
87 | + 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | + __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | + } |
|
94 | + |
|
95 | + // Extract the database from the archive. |
|
96 | + return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Extracts the downloaded database. |
|
102 | + * |
|
103 | + * @param string $tmp_archive_path The database archive path. |
|
104 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | + */ |
|
106 | + protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | + |
|
108 | + // Extract the database from the archive. |
|
109 | + $tmp_database_path = ''; |
|
110 | + |
|
111 | + try { |
|
112 | + |
|
113 | + $file = new PharData( $tmp_archive_path ); |
|
114 | + $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
115 | + |
|
116 | + $file->extractTo( |
|
117 | + dirname( $tmp_archive_path ), |
|
118 | + trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
119 | + true |
|
120 | + ); |
|
121 | + |
|
122 | + } catch ( Exception $exception ) { |
|
123 | + return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
124 | + } finally { |
|
125 | + // Remove the archive since we only care about a single file in it. |
|
126 | + unlink( $tmp_archive_path ); |
|
127 | + } |
|
128 | + |
|
129 | + return $tmp_database_path; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Fetches the ISO country code associated with an IP address. |
|
134 | + * |
|
135 | + * @param string $ip_address The IP address to find the country code for. |
|
136 | + * @return string The country code for the IP address, or empty if not found. |
|
137 | + */ |
|
138 | + public function get_iso_country_code_for_ip( $ip_address ) { |
|
139 | + $country_code = ''; |
|
140 | + |
|
141 | + if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
142 | + return $country_code; |
|
143 | + } |
|
144 | + |
|
145 | + $database_path = $this->get_database_path(); |
|
146 | + if ( ! file_exists( $database_path ) ) { |
|
147 | + return $country_code; |
|
148 | + } |
|
149 | + |
|
150 | + try { |
|
151 | + $reader = new MaxMind\Db\Reader( $database_path ); |
|
152 | + $data = $reader->get( $ip_address ); |
|
153 | + |
|
154 | + if ( isset( $data['country']['iso_code'] ) ) { |
|
155 | + $country_code = $data['country']['iso_code']; |
|
156 | + } |
|
157 | + |
|
158 | + $reader->close(); |
|
159 | + } catch ( Exception $e ) { |
|
160 | + wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
161 | + } |
|
162 | + |
|
163 | + return $country_code; |
|
164 | + } |
|
165 | 165 | |
166 | 166 | } |
@@ -12,22 +12,22 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report_Discounts extends GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - public $field = 'discount_code'; |
|
19 | - |
|
20 | - /** |
|
21 | - * Retrieves the discounts sql. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function get_sql( $range ) { |
|
25 | - global $wpdb; |
|
26 | - |
|
27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | - $clauses = $this->get_range_sql( $range ); |
|
29 | - |
|
30 | - $sql = "SELECT |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + public $field = 'discount_code'; |
|
19 | + |
|
20 | + /** |
|
21 | + * Retrieves the discounts sql. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function get_sql( $range ) { |
|
25 | + global $wpdb; |
|
26 | + |
|
27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | + $clauses = $this->get_range_sql( $range ); |
|
29 | + |
|
30 | + $sql = "SELECT |
|
31 | 31 | meta.discount_code AS discount_code, |
32 | 32 | SUM(total) as total |
33 | 33 | FROM $wpdb->posts |
@@ -41,91 +41,91 @@ discard block |
||
41 | 41 | ORDER BY total DESC |
42 | 42 | "; |
43 | 43 | |
44 | - return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
44 | + return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
45 | 45 | |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Prepares the report stats. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function prepare_stats() { |
|
53 | - global $wpdb; |
|
54 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
55 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
56 | - } |
|
48 | + /** |
|
49 | + * Prepares the report stats. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function prepare_stats() { |
|
53 | + global $wpdb; |
|
54 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
55 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Normalizes the report stats. |
|
60 | - * |
|
61 | - */ |
|
62 | - public function normalize_stats( $stats ) { |
|
63 | - $normalized = array(); |
|
64 | - $others = 0; |
|
65 | - $did = 0; |
|
58 | + /** |
|
59 | + * Normalizes the report stats. |
|
60 | + * |
|
61 | + */ |
|
62 | + public function normalize_stats( $stats ) { |
|
63 | + $normalized = array(); |
|
64 | + $others = 0; |
|
65 | + $did = 0; |
|
66 | 66 | |
67 | - foreach ( $stats as $stat ) { |
|
67 | + foreach ( $stats as $stat ) { |
|
68 | 68 | |
69 | - if ( $did > 4 ) { |
|
69 | + if ( $did > 4 ) { |
|
70 | 70 | |
71 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
71 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
72 | 72 | |
73 | - } else { |
|
73 | + } else { |
|
74 | 74 | |
75 | - $normalized[] = array( |
|
76 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
77 | - 'discount_code' => strip_tags( $stat->discount_code ), |
|
78 | - ); |
|
75 | + $normalized[] = array( |
|
76 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
77 | + 'discount_code' => strip_tags( $stat->discount_code ), |
|
78 | + ); |
|
79 | 79 | |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - $did++; |
|
83 | - } |
|
82 | + $did++; |
|
83 | + } |
|
84 | 84 | |
85 | - if ( $others > 0 ) { |
|
85 | + if ( $others > 0 ) { |
|
86 | 86 | |
87 | - $normalized[] = array( |
|
88 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
89 | - 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
90 | - ); |
|
87 | + $normalized[] = array( |
|
88 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
89 | + 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
90 | + ); |
|
91 | 91 | |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - return $normalized; |
|
95 | - } |
|
94 | + return $normalized; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Retrieves report data. |
|
99 | - * |
|
100 | - */ |
|
101 | - public function get_data() { |
|
97 | + /** |
|
98 | + * Retrieves report data. |
|
99 | + * |
|
100 | + */ |
|
101 | + public function get_data() { |
|
102 | 102 | |
103 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
104 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
103 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
104 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
105 | 105 | |
106 | - shuffle( $colors ); |
|
106 | + shuffle( $colors ); |
|
107 | 107 | |
108 | - return array( |
|
109 | - 'data' => $data, |
|
110 | - 'backgroundColor' => $colors, |
|
111 | - ); |
|
108 | + return array( |
|
109 | + 'data' => $data, |
|
110 | + 'backgroundColor' => $colors, |
|
111 | + ); |
|
112 | 112 | |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Retrieves report labels. |
|
117 | - * |
|
118 | - */ |
|
119 | - public function get_labels() { |
|
120 | - return wp_list_pluck( $this->stats, 'discount_code' ); |
|
121 | - } |
|
115 | + /** |
|
116 | + * Retrieves report labels. |
|
117 | + * |
|
118 | + */ |
|
119 | + public function get_labels() { |
|
120 | + return wp_list_pluck( $this->stats, 'discount_code' ); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Displays the actual report. |
|
125 | - * |
|
126 | - */ |
|
127 | - public function display_stats() { |
|
128 | - ?> |
|
123 | + /** |
|
124 | + * Displays the actual report. |
|
125 | + * |
|
126 | + */ |
|
127 | + public function display_stats() { |
|
128 | + ?> |
|
129 | 129 | |
130 | 130 | <canvas id="getpaid-chartjs-earnings-discount_code"></canvas> |
131 | 131 | |
@@ -154,6 +154,6 @@ discard block |
||
154 | 154 | </script> |
155 | 155 | |
156 | 156 | <?php |
157 | - } |
|
157 | + } |
|
158 | 158 | |
159 | 159 | } |
@@ -12,23 +12,23 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report_Items extends GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - public $field = 'item_name'; |
|
19 | - |
|
20 | - /** |
|
21 | - * Retrieves the earning sql. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function get_sql( $range ) { |
|
25 | - global $wpdb; |
|
26 | - |
|
27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | - $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
29 | - $clauses = $this->get_range_sql( $range ); |
|
30 | - |
|
31 | - $sql = "SELECT |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + public $field = 'item_name'; |
|
19 | + |
|
20 | + /** |
|
21 | + * Retrieves the earning sql. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function get_sql( $range ) { |
|
25 | + global $wpdb; |
|
26 | + |
|
27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | + $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
29 | + $clauses = $this->get_range_sql( $range ); |
|
30 | + |
|
31 | + $sql = "SELECT |
|
32 | 32 | item.item_name AS item_name, |
33 | 33 | item.item_id AS item_id, |
34 | 34 | SUM(price) as total |
@@ -43,91 +43,91 @@ discard block |
||
43 | 43 | ORDER BY total DESC |
44 | 44 | "; |
45 | 45 | |
46 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
46 | + return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
47 | 47 | |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Prepares the report stats. |
|
52 | - * |
|
53 | - */ |
|
54 | - public function prepare_stats() { |
|
55 | - global $wpdb; |
|
56 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
57 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
58 | - } |
|
50 | + /** |
|
51 | + * Prepares the report stats. |
|
52 | + * |
|
53 | + */ |
|
54 | + public function prepare_stats() { |
|
55 | + global $wpdb; |
|
56 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
57 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Normalizes the report stats. |
|
62 | - * |
|
63 | - */ |
|
64 | - public function normalize_stats( $stats ) { |
|
65 | - $normalized = array(); |
|
66 | - $others = 0; |
|
67 | - $did = 0; |
|
60 | + /** |
|
61 | + * Normalizes the report stats. |
|
62 | + * |
|
63 | + */ |
|
64 | + public function normalize_stats( $stats ) { |
|
65 | + $normalized = array(); |
|
66 | + $others = 0; |
|
67 | + $did = 0; |
|
68 | 68 | |
69 | - foreach ( $stats as $stat ) { |
|
69 | + foreach ( $stats as $stat ) { |
|
70 | 70 | |
71 | - if ( $did > 4 ) { |
|
71 | + if ( $did > 4 ) { |
|
72 | 72 | |
73 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
73 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
74 | 74 | |
75 | - } else { |
|
75 | + } else { |
|
76 | 76 | |
77 | - $normalized[] = array( |
|
78 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
79 | - 'item_name' => strip_tags( $stat->item_name ), |
|
80 | - ); |
|
77 | + $normalized[] = array( |
|
78 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
79 | + 'item_name' => strip_tags( $stat->item_name ), |
|
80 | + ); |
|
81 | 81 | |
82 | - } |
|
82 | + } |
|
83 | 83 | |
84 | - $did++; |
|
85 | - } |
|
84 | + $did++; |
|
85 | + } |
|
86 | 86 | |
87 | - if ( $others > 0 ) { |
|
87 | + if ( $others > 0 ) { |
|
88 | 88 | |
89 | - $normalized[] = array( |
|
90 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
91 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
92 | - ); |
|
89 | + $normalized[] = array( |
|
90 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
91 | + 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
92 | + ); |
|
93 | 93 | |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - return $normalized; |
|
97 | - } |
|
96 | + return $normalized; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Retrieves report data. |
|
101 | - * |
|
102 | - */ |
|
103 | - public function get_data() { |
|
99 | + /** |
|
100 | + * Retrieves report data. |
|
101 | + * |
|
102 | + */ |
|
103 | + public function get_data() { |
|
104 | 104 | |
105 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
106 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
105 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
106 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
107 | 107 | |
108 | - shuffle( $colors ); |
|
108 | + shuffle( $colors ); |
|
109 | 109 | |
110 | - return array( |
|
111 | - 'data' => $data, |
|
112 | - 'backgroundColor' => $colors, |
|
113 | - ); |
|
110 | + return array( |
|
111 | + 'data' => $data, |
|
112 | + 'backgroundColor' => $colors, |
|
113 | + ); |
|
114 | 114 | |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Retrieves report labels. |
|
119 | - * |
|
120 | - */ |
|
121 | - public function get_labels() { |
|
122 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
123 | - } |
|
117 | + /** |
|
118 | + * Retrieves report labels. |
|
119 | + * |
|
120 | + */ |
|
121 | + public function get_labels() { |
|
122 | + return wp_list_pluck( $this->stats, 'item_name' ); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Displays the actual report. |
|
127 | - * |
|
128 | - */ |
|
129 | - public function display_stats() { |
|
130 | - ?> |
|
125 | + /** |
|
126 | + * Displays the actual report. |
|
127 | + * |
|
128 | + */ |
|
129 | + public function display_stats() { |
|
130 | + ?> |
|
131 | 131 | |
132 | 132 | <canvas id="getpaid-chartjs-earnings-items"></canvas> |
133 | 133 | |
@@ -156,6 +156,6 @@ discard block |
||
156 | 156 | </script> |
157 | 157 | |
158 | 158 | <?php |
159 | - } |
|
159 | + } |
|
160 | 160 | |
161 | 161 | } |