@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | public $templates_url; |
21 | 21 | |
22 | 22 | /** |
23 | - * Class constructor. |
|
24 | - * |
|
25 | - * @since 1.0.19 |
|
26 | - */ |
|
27 | - public function __construct() { |
|
23 | + * Class constructor. |
|
24 | + * |
|
25 | + * @since 1.0.19 |
|
26 | + */ |
|
27 | + public function __construct() { |
|
28 | 28 | |
29 | 29 | $this->templates_dir = apply_filters( 'getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates' ); |
30 | 30 | $this->templates_url = apply_filters( 'getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates' ); |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | - * Checks if this is a preview page |
|
35 | - * |
|
36 | - * @since 1.0.19 |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function is_preview() { |
|
34 | + * Checks if this is a preview page |
|
35 | + * |
|
36 | + * @since 1.0.19 |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function is_preview() { |
|
40 | 40 | return |
41 | 41 | $this->is_divi_preview() || |
42 | 42 | $this->is_elementor_preview() || |
@@ -48,73 +48,73 @@ discard block |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | - * Checks if this is an elementor preview page |
|
52 | - * |
|
53 | - * @since 1.0.19 |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function is_elementor_preview() { |
|
57 | - return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Checks if this is a DIVI preview page |
|
62 | - * |
|
63 | - * @since 1.0.19 |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function is_divi_preview() { |
|
67 | - return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Checks if this is a beaver builder preview page |
|
72 | - * |
|
73 | - * @since 1.0.19 |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - public function is_beaver_preview() { |
|
77 | - return isset( $_REQUEST['fl_builder'] ); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Checks if this is a siteorigin builder preview page |
|
82 | - * |
|
83 | - * @since 1.0.19 |
|
84 | - * @return bool |
|
85 | - */ |
|
86 | - public function is_siteorigin_preview() { |
|
87 | - return ! empty( $_REQUEST['siteorigin_panels_live_editor'] ); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Checks if this is a cornerstone builder preview page |
|
92 | - * |
|
93 | - * @since 1.0.19 |
|
94 | - * @return bool |
|
95 | - */ |
|
96 | - public function is_cornerstone_preview() { |
|
97 | - return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint'; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Checks if this is a fusion builder preview page |
|
102 | - * |
|
103 | - * @since 1.0.19 |
|
104 | - * @return bool |
|
105 | - */ |
|
106 | - public function is_fusion_preview() { |
|
107 | - return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Checks if this is an oxygen builder preview page |
|
112 | - * |
|
113 | - * @since 1.0.19 |
|
114 | - * @return bool |
|
115 | - */ |
|
116 | - public function is_oxygen_preview() { |
|
117 | - return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ); |
|
51 | + * Checks if this is an elementor preview page |
|
52 | + * |
|
53 | + * @since 1.0.19 |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function is_elementor_preview() { |
|
57 | + return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Checks if this is a DIVI preview page |
|
62 | + * |
|
63 | + * @since 1.0.19 |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function is_divi_preview() { |
|
67 | + return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Checks if this is a beaver builder preview page |
|
72 | + * |
|
73 | + * @since 1.0.19 |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + public function is_beaver_preview() { |
|
77 | + return isset( $_REQUEST['fl_builder'] ); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Checks if this is a siteorigin builder preview page |
|
82 | + * |
|
83 | + * @since 1.0.19 |
|
84 | + * @return bool |
|
85 | + */ |
|
86 | + public function is_siteorigin_preview() { |
|
87 | + return ! empty( $_REQUEST['siteorigin_panels_live_editor'] ); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Checks if this is a cornerstone builder preview page |
|
92 | + * |
|
93 | + * @since 1.0.19 |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | + public function is_cornerstone_preview() { |
|
97 | + return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint'; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Checks if this is a fusion builder preview page |
|
102 | + * |
|
103 | + * @since 1.0.19 |
|
104 | + * @return bool |
|
105 | + */ |
|
106 | + public function is_fusion_preview() { |
|
107 | + return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Checks if this is an oxygen builder preview page |
|
112 | + * |
|
113 | + * @since 1.0.19 |
|
114 | + * @return bool |
|
115 | + */ |
|
116 | + public function is_oxygen_preview() { |
|
117 | + return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
125 | 125 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
126 | 126 | */ |
127 | - public function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
127 | + public function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
128 | 128 | |
129 | 129 | // Load the defaults for the template path and default path. |
130 | 130 | $template_path = empty( $template_path ) ? 'invoicing' : $template_path; |
@@ -146,22 +146,22 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
149 | - * Loads a template |
|
150 | - * |
|
151 | - * @since 1.0.19 |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - protected function load_template( $template_name, $template_path, $args ) { |
|
149 | + * Loads a template |
|
150 | + * |
|
151 | + * @since 1.0.19 |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + protected function load_template( $template_name, $template_path, $args ) { |
|
155 | 155 | |
156 | 156 | if ( is_array( $args ) ){ |
157 | 157 | extract( $args ); |
158 | 158 | } |
159 | 159 | |
160 | 160 | // Fires before loading a template. |
161 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $args ); |
|
161 | + do_action( 'wpinv_before_template_part', $template_name, $template_path, $args ); |
|
162 | 162 | |
163 | 163 | // Load the template. |
164 | - include( $template_path ); |
|
164 | + include( $template_path ); |
|
165 | 165 | |
166 | 166 | // Fires after loading a template. |
167 | 167 | do_action( 'wpinv_after_template_part', $template_name, $template_path, $args ); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
179 | 179 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
180 | 180 | */ |
181 | - public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
181 | + public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
182 | 182 | |
183 | 183 | // Locate the template. |
184 | 184 | $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
204 | 204 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
205 | 205 | */ |
206 | - public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
206 | + public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
207 | 207 | ob_start(); |
208 | 208 | $this->display_template( $template_name, $args, $template_path, $default_path ); |
209 | 209 | return ob_get_clean(); |
@@ -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 | } |
@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | class WPInv_Invoice extends GetPaid_Data { |
15 | 15 | |
16 | 16 | /** |
17 | - * Which data store to load. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
17 | + * Which data store to load. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | 21 | protected $data_store_name = 'invoice'; |
22 | 22 | |
23 | 23 | /** |
24 | - * This is the name of this object type. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
24 | + * This is the name of this object type. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | protected $object_type = 'invoice'; |
29 | 29 | |
30 | 30 | /** |
31 | - * Item Data array. This is the core item data exposed in APIs. |
|
32 | - * |
|
33 | - * @since 1.0.19 |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $data = array( |
|
37 | - 'parent_id' => 0, |
|
38 | - 'status' => 'wpi-pending', |
|
39 | - 'version' => '', |
|
40 | - 'date_created' => null, |
|
31 | + * Item Data array. This is the core item data exposed in APIs. |
|
32 | + * |
|
33 | + * @since 1.0.19 |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $data = array( |
|
37 | + 'parent_id' => 0, |
|
38 | + 'status' => 'wpi-pending', |
|
39 | + 'version' => '', |
|
40 | + 'date_created' => null, |
|
41 | 41 | 'date_modified' => null, |
42 | 42 | 'due_date' => null, |
43 | 43 | 'completed_date' => null, |
@@ -79,22 +79,22 @@ discard block |
||
79 | 79 | 'transaction_id' => '', |
80 | 80 | 'currency' => '', |
81 | 81 | 'disable_taxes' => false, |
82 | - 'subscription_id' => null, |
|
83 | - 'remote_subscription_id' => null, |
|
84 | - 'is_viewed' => false, |
|
85 | - 'email_cc' => '', |
|
86 | - 'template' => 'quantity', // hours, amount only |
|
87 | - 'created_via' => null, |
|
82 | + 'subscription_id' => null, |
|
83 | + 'remote_subscription_id' => null, |
|
84 | + 'is_viewed' => false, |
|
85 | + 'email_cc' => '', |
|
86 | + 'template' => 'quantity', // hours, amount only |
|
87 | + 'created_via' => null, |
|
88 | 88 | ); |
89 | 89 | |
90 | 90 | /** |
91 | - * Stores meta in cache for future reads. |
|
92 | - * |
|
93 | - * A group must be set to to enable caching. |
|
94 | - * |
|
95 | - * @var string |
|
96 | - */ |
|
97 | - protected $cache_group = 'getpaid_invoices'; |
|
91 | + * Stores meta in cache for future reads. |
|
92 | + * |
|
93 | + * A group must be set to to enable caching. |
|
94 | + * |
|
95 | + * @var string |
|
96 | + */ |
|
97 | + protected $cache_group = 'getpaid_invoices'; |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Stores a reference to the original WP_Post object |
@@ -108,104 +108,104 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @var int |
110 | 110 | */ |
111 | - protected $recurring_item = null; |
|
111 | + protected $recurring_item = null; |
|
112 | 112 | |
113 | - /** |
|
113 | + /** |
|
114 | 114 | * Stores an array of item totals. |
115 | - * |
|
116 | - * e.g $totals['discount'] = array( |
|
117 | - * 'initial' => 10, |
|
118 | - * 'recurring' => 10, |
|
119 | - * ) |
|
115 | + * |
|
116 | + * e.g $totals['discount'] = array( |
|
117 | + * 'initial' => 10, |
|
118 | + * 'recurring' => 10, |
|
119 | + * ) |
|
120 | 120 | * |
121 | 121 | * @var array |
122 | 122 | */ |
123 | - protected $totals = array(); |
|
123 | + protected $totals = array(); |
|
124 | 124 | |
125 | - /** |
|
126 | - * Stores the status transition information. |
|
127 | - * |
|
128 | - * @since 1.0.19 |
|
129 | - * @var bool |
|
130 | - */ |
|
131 | - protected $status_transition = false; |
|
125 | + /** |
|
126 | + * Stores the status transition information. |
|
127 | + * |
|
128 | + * @since 1.0.19 |
|
129 | + * @var bool |
|
130 | + */ |
|
131 | + protected $status_transition = false; |
|
132 | 132 | |
133 | 133 | /** |
134 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
135 | - * |
|
136 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
137 | - */ |
|
134 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
135 | + * |
|
136 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
137 | + */ |
|
138 | 138 | public function __construct( $invoice = false ) { |
139 | 139 | |
140 | 140 | parent::__construct( $invoice ); |
141 | 141 | |
142 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
143 | - $this->set_id( $invoice ); |
|
144 | - } elseif ( $invoice instanceof self ) { |
|
145 | - $this->set_id( $invoice->get_id() ); |
|
146 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
147 | - $this->set_id( $invoice->ID ); |
|
148 | - } elseif ( is_array( $invoice ) ) { |
|
149 | - $this->set_props( $invoice ); |
|
150 | - |
|
151 | - if ( isset( $invoice['ID'] ) ) { |
|
152 | - $this->set_id( $invoice['ID'] ); |
|
153 | - } |
|
154 | - |
|
155 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
156 | - $this->set_id( $invoice_id ); |
|
157 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
158 | - $this->set_id( $invoice_id ); |
|
159 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
160 | - $this->set_id( $invoice_id ); |
|
161 | - }else { |
|
162 | - $this->set_object_read( true ); |
|
163 | - } |
|
142 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
143 | + $this->set_id( $invoice ); |
|
144 | + } elseif ( $invoice instanceof self ) { |
|
145 | + $this->set_id( $invoice->get_id() ); |
|
146 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
147 | + $this->set_id( $invoice->ID ); |
|
148 | + } elseif ( is_array( $invoice ) ) { |
|
149 | + $this->set_props( $invoice ); |
|
150 | + |
|
151 | + if ( isset( $invoice['ID'] ) ) { |
|
152 | + $this->set_id( $invoice['ID'] ); |
|
153 | + } |
|
154 | + |
|
155 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
156 | + $this->set_id( $invoice_id ); |
|
157 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
158 | + $this->set_id( $invoice_id ); |
|
159 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
160 | + $this->set_id( $invoice_id ); |
|
161 | + }else { |
|
162 | + $this->set_object_read( true ); |
|
163 | + } |
|
164 | 164 | |
165 | 165 | // Load the datastore. |
166 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
166 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
167 | 167 | |
168 | - if ( $this->get_id() > 0 ) { |
|
168 | + if ( $this->get_id() > 0 ) { |
|
169 | 169 | $this->post = get_post( $this->get_id() ); |
170 | 170 | $this->ID = $this->get_id(); |
171 | - $this->data_store->read( $this ); |
|
171 | + $this->data_store->read( $this ); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Given an invoice key/number, it returns its id. |
|
178 | - * |
|
179 | - * |
|
180 | - * @static |
|
181 | - * @param string $value The invoice key or number |
|
182 | - * @param string $field Either key, transaction_id or number. |
|
183 | - * @since 1.0.15 |
|
184 | - * @return int |
|
185 | - */ |
|
186 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
177 | + * Given an invoice key/number, it returns its id. |
|
178 | + * |
|
179 | + * |
|
180 | + * @static |
|
181 | + * @param string $value The invoice key or number |
|
182 | + * @param string $field Either key, transaction_id or number. |
|
183 | + * @since 1.0.15 |
|
184 | + * @return int |
|
185 | + */ |
|
186 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
187 | 187 | global $wpdb; |
188 | 188 | |
189 | - // Trim the value. |
|
190 | - $value = trim( $value ); |
|
189 | + // Trim the value. |
|
190 | + $value = trim( $value ); |
|
191 | 191 | |
192 | - if ( empty( $value ) ) { |
|
193 | - return 0; |
|
194 | - } |
|
192 | + if ( empty( $value ) ) { |
|
193 | + return 0; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | // Valid fields. |
197 | 197 | $fields = array( 'key', 'number', 'transaction_id' ); |
198 | 198 | |
199 | - // Ensure a field has been passed. |
|
200 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
201 | - return 0; |
|
202 | - } |
|
199 | + // Ensure a field has been passed. |
|
200 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
201 | + return 0; |
|
202 | + } |
|
203 | 203 | |
204 | - // Maybe retrieve from the cache. |
|
205 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
206 | - if ( false !== $invoice_id ) { |
|
207 | - return $invoice_id; |
|
208 | - } |
|
204 | + // Maybe retrieve from the cache. |
|
205 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
206 | + if ( false !== $invoice_id ) { |
|
207 | + return $invoice_id; |
|
208 | + } |
|
209 | 209 | |
210 | 210 | // Fetch from the db. |
211 | 211 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
214 | 214 | ); |
215 | 215 | |
216 | - // Update the cache with our data |
|
217 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
216 | + // Update the cache with our data |
|
217 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
218 | 218 | |
219 | - return $invoice_id; |
|
219 | + return $invoice_id; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -242,72 +242,72 @@ discard block |
||
242 | 242 | */ |
243 | 243 | |
244 | 244 | /** |
245 | - * Get parent invoice ID. |
|
246 | - * |
|
247 | - * @since 1.0.19 |
|
248 | - * @param string $context View or edit context. |
|
249 | - * @return int |
|
250 | - */ |
|
251 | - public function get_parent_id( $context = 'view' ) { |
|
252 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
245 | + * Get parent invoice ID. |
|
246 | + * |
|
247 | + * @since 1.0.19 |
|
248 | + * @param string $context View or edit context. |
|
249 | + * @return int |
|
250 | + */ |
|
251 | + public function get_parent_id( $context = 'view' ) { |
|
252 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | - * Get parent invoice. |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - * @return WPInv_Invoice |
|
260 | - */ |
|
256 | + * Get parent invoice. |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + * @return WPInv_Invoice |
|
260 | + */ |
|
261 | 261 | public function get_parent_payment() { |
262 | 262 | return new WPInv_Invoice( $this->get_parent_id() ); |
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | - * Alias for self::get_parent_payment(). |
|
267 | - * |
|
268 | - * @since 1.0.19 |
|
269 | - * @return WPInv_Invoice |
|
270 | - */ |
|
266 | + * Alias for self::get_parent_payment(). |
|
267 | + * |
|
268 | + * @since 1.0.19 |
|
269 | + * @return WPInv_Invoice |
|
270 | + */ |
|
271 | 271 | public function get_parent() { |
272 | 272 | return $this->get_parent_payment(); |
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
276 | - * Get invoice status. |
|
277 | - * |
|
278 | - * @since 1.0.19 |
|
279 | - * @param string $context View or edit context. |
|
280 | - * @return string |
|
281 | - */ |
|
282 | - public function get_status( $context = 'view' ) { |
|
283 | - return $this->get_prop( 'status', $context ); |
|
284 | - } |
|
276 | + * Get invoice status. |
|
277 | + * |
|
278 | + * @since 1.0.19 |
|
279 | + * @param string $context View or edit context. |
|
280 | + * @return string |
|
281 | + */ |
|
282 | + public function get_status( $context = 'view' ) { |
|
283 | + return $this->get_prop( 'status', $context ); |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * Retrieves an array of possible invoice statuses. |
|
288 | - * |
|
289 | - * @since 1.0.19 |
|
290 | - * @return array |
|
291 | - */ |
|
292 | - public function get_all_statuses() { |
|
293 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Get invoice status nice name. |
|
298 | - * |
|
299 | - * @since 1.0.19 |
|
300 | - * @return string |
|
301 | - */ |
|
286 | + /** |
|
287 | + * Retrieves an array of possible invoice statuses. |
|
288 | + * |
|
289 | + * @since 1.0.19 |
|
290 | + * @return array |
|
291 | + */ |
|
292 | + public function get_all_statuses() { |
|
293 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Get invoice status nice name. |
|
298 | + * |
|
299 | + * @since 1.0.19 |
|
300 | + * @return string |
|
301 | + */ |
|
302 | 302 | public function get_status_nicename() { |
303 | - $statuses = $this->get_all_statuses(); |
|
303 | + $statuses = $this->get_all_statuses(); |
|
304 | 304 | |
305 | 305 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
306 | 306 | |
307 | 307 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
308 | 308 | } |
309 | 309 | |
310 | - /** |
|
310 | + /** |
|
311 | 311 | * Retrieves the invoice status label html |
312 | 312 | * |
313 | 313 | * @since 1.0.0 |
@@ -315,262 +315,262 @@ discard block |
||
315 | 315 | */ |
316 | 316 | public function get_status_label_html() { |
317 | 317 | |
318 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
319 | - $status = sanitize_html_class( $this->get_status() ); |
|
318 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
319 | + $status = sanitize_html_class( $this->get_status() ); |
|
320 | 320 | |
321 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>"; |
|
322 | - } |
|
321 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>"; |
|
322 | + } |
|
323 | 323 | |
324 | 324 | /** |
325 | - * Get plugin version when the invoice was created. |
|
326 | - * |
|
327 | - * @since 1.0.19 |
|
328 | - * @param string $context View or edit context. |
|
329 | - * @return string |
|
330 | - */ |
|
331 | - public function get_version( $context = 'view' ) { |
|
332 | - return $this->get_prop( 'version', $context ); |
|
333 | - } |
|
325 | + * Get plugin version when the invoice was created. |
|
326 | + * |
|
327 | + * @since 1.0.19 |
|
328 | + * @param string $context View or edit context. |
|
329 | + * @return string |
|
330 | + */ |
|
331 | + public function get_version( $context = 'view' ) { |
|
332 | + return $this->get_prop( 'version', $context ); |
|
333 | + } |
|
334 | 334 | |
335 | - /** |
|
336 | - * @deprecated |
|
337 | - */ |
|
338 | - public function get_invoice_date( $format = true ) { |
|
339 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
340 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
341 | - $formatted = getpaid_format_date( $date ); |
|
335 | + /** |
|
336 | + * @deprecated |
|
337 | + */ |
|
338 | + public function get_invoice_date( $format = true ) { |
|
339 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
340 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
341 | + $formatted = getpaid_format_date( $date ); |
|
342 | 342 | |
343 | - if ( $format ) { |
|
344 | - return $formatted; |
|
345 | - } |
|
343 | + if ( $format ) { |
|
344 | + return $formatted; |
|
345 | + } |
|
346 | 346 | |
347 | - return empty( $formatted ) ? '' : $date; |
|
347 | + return empty( $formatted ) ? '' : $date; |
|
348 | 348 | |
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
352 | - * Get date when the invoice was created. |
|
353 | - * |
|
354 | - * @since 1.0.19 |
|
355 | - * @param string $context View or edit context. |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function get_date_created( $context = 'view' ) { |
|
359 | - return $this->get_prop( 'date_created', $context ); |
|
360 | - } |
|
352 | + * Get date when the invoice was created. |
|
353 | + * |
|
354 | + * @since 1.0.19 |
|
355 | + * @param string $context View or edit context. |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function get_date_created( $context = 'view' ) { |
|
359 | + return $this->get_prop( 'date_created', $context ); |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
363 | - * Alias for self::get_date_created(). |
|
364 | - * |
|
365 | - * @since 1.0.19 |
|
366 | - * @param string $context View or edit context. |
|
367 | - * @return string |
|
368 | - */ |
|
369 | - public function get_created_date( $context = 'view' ) { |
|
370 | - return $this->get_date_created( $context ); |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Get GMT date when the invoice was created. |
|
375 | - * |
|
376 | - * @since 1.0.19 |
|
377 | - * @param string $context View or edit context. |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_date_created_gmt( $context = 'view' ) { |
|
362 | + /** |
|
363 | + * Alias for self::get_date_created(). |
|
364 | + * |
|
365 | + * @since 1.0.19 |
|
366 | + * @param string $context View or edit context. |
|
367 | + * @return string |
|
368 | + */ |
|
369 | + public function get_created_date( $context = 'view' ) { |
|
370 | + return $this->get_date_created( $context ); |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Get GMT date when the invoice was created. |
|
375 | + * |
|
376 | + * @since 1.0.19 |
|
377 | + * @param string $context View or edit context. |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_date_created_gmt( $context = 'view' ) { |
|
381 | 381 | $date = $this->get_date_created( $context ); |
382 | 382 | |
383 | 383 | if ( $date ) { |
384 | 384 | $date = get_gmt_from_date( $date ); |
385 | 385 | } |
386 | - return $date; |
|
386 | + return $date; |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
390 | - * Get date when the invoice was last modified. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - * @param string $context View or edit context. |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public function get_date_modified( $context = 'view' ) { |
|
397 | - return $this->get_prop( 'date_modified', $context ); |
|
398 | - } |
|
390 | + * Get date when the invoice was last modified. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + * @param string $context View or edit context. |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public function get_date_modified( $context = 'view' ) { |
|
397 | + return $this->get_prop( 'date_modified', $context ); |
|
398 | + } |
|
399 | 399 | |
400 | - /** |
|
401 | - * Alias for self::get_date_modified(). |
|
402 | - * |
|
403 | - * @since 1.0.19 |
|
404 | - * @param string $context View or edit context. |
|
405 | - * @return string |
|
406 | - */ |
|
407 | - public function get_modified_date( $context = 'view' ) { |
|
408 | - return $this->get_date_modified( $context ); |
|
400 | + /** |
|
401 | + * Alias for self::get_date_modified(). |
|
402 | + * |
|
403 | + * @since 1.0.19 |
|
404 | + * @param string $context View or edit context. |
|
405 | + * @return string |
|
406 | + */ |
|
407 | + public function get_modified_date( $context = 'view' ) { |
|
408 | + return $this->get_date_modified( $context ); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
412 | - * Get GMT date when the invoice was last modified. |
|
413 | - * |
|
414 | - * @since 1.0.19 |
|
415 | - * @param string $context View or edit context. |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
412 | + * Get GMT date when the invoice was last modified. |
|
413 | + * |
|
414 | + * @since 1.0.19 |
|
415 | + * @param string $context View or edit context. |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
419 | 419 | $date = $this->get_date_modified( $context ); |
420 | 420 | |
421 | 421 | if ( $date ) { |
422 | 422 | $date = get_gmt_from_date( $date ); |
423 | 423 | } |
424 | - return $date; |
|
424 | + return $date; |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Get the invoice due date. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return string |
|
433 | - */ |
|
434 | - public function get_due_date( $context = 'view' ) { |
|
435 | - return $this->get_prop( 'due_date', $context ); |
|
428 | + * Get the invoice due date. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return string |
|
433 | + */ |
|
434 | + public function get_due_date( $context = 'view' ) { |
|
435 | + return $this->get_prop( 'due_date', $context ); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
439 | - * Alias for self::get_due_date(). |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return string |
|
444 | - */ |
|
445 | - public function get_date_due( $context = 'view' ) { |
|
446 | - return $this->get_due_date( $context ); |
|
439 | + * Alias for self::get_due_date(). |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return string |
|
444 | + */ |
|
445 | + public function get_date_due( $context = 'view' ) { |
|
446 | + return $this->get_due_date( $context ); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Get the invoice GMT due date. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - public function get_due_date_gmt( $context = 'view' ) { |
|
450 | + * Get the invoice GMT due date. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + public function get_due_date_gmt( $context = 'view' ) { |
|
457 | 457 | $date = $this->get_due_date( $context ); |
458 | 458 | |
459 | 459 | if ( $date ) { |
460 | 460 | $date = get_gmt_from_date( $date ); |
461 | 461 | } |
462 | - return $date; |
|
462 | + return $date; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
466 | - * Alias for self::get_due_date_gmt(). |
|
467 | - * |
|
468 | - * @since 1.0.19 |
|
469 | - * @param string $context View or edit context. |
|
470 | - * @return string |
|
471 | - */ |
|
472 | - public function get_gmt_date_due( $context = 'view' ) { |
|
473 | - return $this->get_due_date_gmt( $context ); |
|
466 | + * Alias for self::get_due_date_gmt(). |
|
467 | + * |
|
468 | + * @since 1.0.19 |
|
469 | + * @param string $context View or edit context. |
|
470 | + * @return string |
|
471 | + */ |
|
472 | + public function get_gmt_date_due( $context = 'view' ) { |
|
473 | + return $this->get_due_date_gmt( $context ); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
477 | - * Get date when the invoice was completed. |
|
478 | - * |
|
479 | - * @since 1.0.19 |
|
480 | - * @param string $context View or edit context. |
|
481 | - * @return string |
|
482 | - */ |
|
483 | - public function get_completed_date( $context = 'view' ) { |
|
484 | - return $this->get_prop( 'completed_date', $context ); |
|
477 | + * Get date when the invoice was completed. |
|
478 | + * |
|
479 | + * @since 1.0.19 |
|
480 | + * @param string $context View or edit context. |
|
481 | + * @return string |
|
482 | + */ |
|
483 | + public function get_completed_date( $context = 'view' ) { |
|
484 | + return $this->get_prop( 'completed_date', $context ); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Alias for self::get_completed_date(). |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - * @param string $context View or edit context. |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function get_date_completed( $context = 'view' ) { |
|
495 | - return $this->get_completed_date( $context ); |
|
488 | + * Alias for self::get_completed_date(). |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + * @param string $context View or edit context. |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function get_date_completed( $context = 'view' ) { |
|
495 | + return $this->get_completed_date( $context ); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
499 | - * Get GMT date when the invoice was was completed. |
|
500 | - * |
|
501 | - * @since 1.0.19 |
|
502 | - * @param string $context View or edit context. |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
499 | + * Get GMT date when the invoice was was completed. |
|
500 | + * |
|
501 | + * @since 1.0.19 |
|
502 | + * @param string $context View or edit context. |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
506 | 506 | $date = $this->get_completed_date( $context ); |
507 | 507 | |
508 | 508 | if ( $date ) { |
509 | 509 | $date = get_gmt_from_date( $date ); |
510 | 510 | } |
511 | - return $date; |
|
511 | + return $date; |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | /** |
515 | - * Alias for self::get_completed_date_gmt(). |
|
516 | - * |
|
517 | - * @since 1.0.19 |
|
518 | - * @param string $context View or edit context. |
|
519 | - * @return string |
|
520 | - */ |
|
521 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
522 | - return $this->get_completed_date_gmt( $context ); |
|
515 | + * Alias for self::get_completed_date_gmt(). |
|
516 | + * |
|
517 | + * @since 1.0.19 |
|
518 | + * @param string $context View or edit context. |
|
519 | + * @return string |
|
520 | + */ |
|
521 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
522 | + return $this->get_completed_date_gmt( $context ); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | /** |
526 | - * Get the invoice number. |
|
527 | - * |
|
528 | - * @since 1.0.19 |
|
529 | - * @param string $context View or edit context. |
|
530 | - * @return string |
|
531 | - */ |
|
532 | - public function get_number( $context = 'view' ) { |
|
533 | - $number = $this->get_prop( 'number', $context ); |
|
526 | + * Get the invoice number. |
|
527 | + * |
|
528 | + * @since 1.0.19 |
|
529 | + * @param string $context View or edit context. |
|
530 | + * @return string |
|
531 | + */ |
|
532 | + public function get_number( $context = 'view' ) { |
|
533 | + $number = $this->get_prop( 'number', $context ); |
|
534 | 534 | |
535 | - if ( empty( $number ) ) { |
|
536 | - $number = $this->generate_number(); |
|
537 | - $this->set_number( $this->generate_number() ); |
|
538 | - } |
|
535 | + if ( empty( $number ) ) { |
|
536 | + $number = $this->generate_number(); |
|
537 | + $this->set_number( $this->generate_number() ); |
|
538 | + } |
|
539 | 539 | |
540 | - return $number; |
|
540 | + return $number; |
|
541 | 541 | } |
542 | 542 | |
543 | - /** |
|
544 | - * Set the invoice number. |
|
545 | - * |
|
546 | - * @since 1.0.19 |
|
547 | - */ |
|
548 | - public function maybe_set_number() { |
|
543 | + /** |
|
544 | + * Set the invoice number. |
|
545 | + * |
|
546 | + * @since 1.0.19 |
|
547 | + */ |
|
548 | + public function maybe_set_number() { |
|
549 | 549 | $number = $this->get_number(); |
550 | 550 | |
551 | 551 | if ( empty( $number ) || $this->get_id() == $number ) { |
552 | - $this->set_number( $this->generate_number() ); |
|
552 | + $this->set_number( $this->generate_number() ); |
|
553 | 553 | } |
554 | 554 | |
555 | - } |
|
555 | + } |
|
556 | 556 | |
557 | 557 | /** |
558 | - * Get the invoice key. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param string $context View or edit context. |
|
562 | - * @return string |
|
563 | - */ |
|
564 | - public function get_key( $context = 'view' ) { |
|
558 | + * Get the invoice key. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param string $context View or edit context. |
|
562 | + * @return string |
|
563 | + */ |
|
564 | + public function get_key( $context = 'view' ) { |
|
565 | 565 | return $this->get_prop( 'key', $context ); |
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Set the invoice key. |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - */ |
|
573 | - public function maybe_set_key() { |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Set the invoice key. |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + */ |
|
573 | + public function maybe_set_key() { |
|
574 | 574 | $key = $this->get_key(); |
575 | 575 | |
576 | 576 | if ( empty( $key ) ) { |
@@ -581,126 +581,126 @@ discard block |
||
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
584 | - * Get the invoice type. |
|
585 | - * |
|
586 | - * @since 1.0.19 |
|
587 | - * @param string $context View or edit context. |
|
588 | - * @return string |
|
589 | - */ |
|
590 | - public function get_type( $context = 'view' ) { |
|
584 | + * Get the invoice type. |
|
585 | + * |
|
586 | + * @since 1.0.19 |
|
587 | + * @param string $context View or edit context. |
|
588 | + * @return string |
|
589 | + */ |
|
590 | + public function get_type( $context = 'view' ) { |
|
591 | 591 | return $this->get_prop( 'type', $context ); |
592 | - } |
|
592 | + } |
|
593 | 593 | |
594 | - /** |
|
595 | - * @deprecated |
|
596 | - */ |
|
597 | - public function get_invoice_quote_type() { |
|
594 | + /** |
|
595 | + * @deprecated |
|
596 | + */ |
|
597 | + public function get_invoice_quote_type() { |
|
598 | 598 | ucfirst( $this->get_type() ); |
599 | 599 | } |
600 | 600 | |
601 | 601 | /** |
602 | - * Get the invoice post type. |
|
603 | - * |
|
604 | - * @since 1.0.19 |
|
605 | - * @param string $context View or edit context. |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public function get_post_type( $context = 'view' ) { |
|
602 | + * Get the invoice post type. |
|
603 | + * |
|
604 | + * @since 1.0.19 |
|
605 | + * @param string $context View or edit context. |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public function get_post_type( $context = 'view' ) { |
|
609 | 609 | return $this->get_prop( 'post_type', $context ); |
610 | 610 | } |
611 | 611 | |
612 | 612 | /** |
613 | - * Get the invoice mode. |
|
614 | - * |
|
615 | - * @since 1.0.19 |
|
616 | - * @param string $context View or edit context. |
|
617 | - * @return string |
|
618 | - */ |
|
619 | - public function get_mode( $context = 'view' ) { |
|
613 | + * Get the invoice mode. |
|
614 | + * |
|
615 | + * @since 1.0.19 |
|
616 | + * @param string $context View or edit context. |
|
617 | + * @return string |
|
618 | + */ |
|
619 | + public function get_mode( $context = 'view' ) { |
|
620 | 620 | return $this->get_prop( 'mode', $context ); |
621 | 621 | } |
622 | 622 | |
623 | 623 | /** |
624 | - * Get the invoice path. |
|
625 | - * |
|
626 | - * @since 1.0.19 |
|
627 | - * @param string $context View or edit context. |
|
628 | - * @return string |
|
629 | - */ |
|
630 | - public function get_path( $context = 'view' ) { |
|
624 | + * Get the invoice path. |
|
625 | + * |
|
626 | + * @since 1.0.19 |
|
627 | + * @param string $context View or edit context. |
|
628 | + * @return string |
|
629 | + */ |
|
630 | + public function get_path( $context = 'view' ) { |
|
631 | 631 | $path = $this->get_prop( 'path', $context ); |
632 | - $prefix = $this->get_type(); |
|
632 | + $prefix = $this->get_type(); |
|
633 | 633 | |
634 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
635 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
636 | - $this->set_path( $path ); |
|
637 | - } |
|
634 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
635 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
636 | + $this->set_path( $path ); |
|
637 | + } |
|
638 | 638 | |
639 | - return $path; |
|
639 | + return $path; |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | /** |
643 | - * Get the invoice name/title. |
|
644 | - * |
|
645 | - * @since 1.0.19 |
|
646 | - * @param string $context View or edit context. |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - public function get_name( $context = 'view' ) { |
|
643 | + * Get the invoice name/title. |
|
644 | + * |
|
645 | + * @since 1.0.19 |
|
646 | + * @param string $context View or edit context. |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + public function get_name( $context = 'view' ) { |
|
650 | 650 | return $this->get_prop( 'title', $context ); |
651 | 651 | } |
652 | 652 | |
653 | 653 | /** |
654 | - * Alias of self::get_name(). |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - * @param string $context View or edit context. |
|
658 | - * @return string |
|
659 | - */ |
|
660 | - public function get_title( $context = 'view' ) { |
|
661 | - return $this->get_name( $context ); |
|
654 | + * Alias of self::get_name(). |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + * @param string $context View or edit context. |
|
658 | + * @return string |
|
659 | + */ |
|
660 | + public function get_title( $context = 'view' ) { |
|
661 | + return $this->get_name( $context ); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | /** |
665 | - * Get the invoice description. |
|
666 | - * |
|
667 | - * @since 1.0.19 |
|
668 | - * @param string $context View or edit context. |
|
669 | - * @return string |
|
670 | - */ |
|
671 | - public function get_description( $context = 'view' ) { |
|
672 | - return $this->get_prop( 'description', $context ); |
|
665 | + * Get the invoice description. |
|
666 | + * |
|
667 | + * @since 1.0.19 |
|
668 | + * @param string $context View or edit context. |
|
669 | + * @return string |
|
670 | + */ |
|
671 | + public function get_description( $context = 'view' ) { |
|
672 | + return $this->get_prop( 'description', $context ); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
676 | - * Alias of self::get_description(). |
|
677 | - * |
|
678 | - * @since 1.0.19 |
|
679 | - * @param string $context View or edit context. |
|
680 | - * @return string |
|
681 | - */ |
|
682 | - public function get_excerpt( $context = 'view' ) { |
|
683 | - return $this->get_description( $context ); |
|
676 | + * Alias of self::get_description(). |
|
677 | + * |
|
678 | + * @since 1.0.19 |
|
679 | + * @param string $context View or edit context. |
|
680 | + * @return string |
|
681 | + */ |
|
682 | + public function get_excerpt( $context = 'view' ) { |
|
683 | + return $this->get_description( $context ); |
|
684 | 684 | } |
685 | 685 | |
686 | 686 | /** |
687 | - * Alias of self::get_description(). |
|
688 | - * |
|
689 | - * @since 1.0.19 |
|
690 | - * @param string $context View or edit context. |
|
691 | - * @return string |
|
692 | - */ |
|
693 | - public function get_summary( $context = 'view' ) { |
|
694 | - return $this->get_description( $context ); |
|
687 | + * Alias of self::get_description(). |
|
688 | + * |
|
689 | + * @since 1.0.19 |
|
690 | + * @param string $context View or edit context. |
|
691 | + * @return string |
|
692 | + */ |
|
693 | + public function get_summary( $context = 'view' ) { |
|
694 | + return $this->get_description( $context ); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
698 | - * Returns the user info. |
|
699 | - * |
|
700 | - * @since 1.0.19 |
|
698 | + * Returns the user info. |
|
699 | + * |
|
700 | + * @since 1.0.19 |
|
701 | 701 | * @param string $context View or edit context. |
702 | - * @return array |
|
703 | - */ |
|
702 | + * @return array |
|
703 | + */ |
|
704 | 704 | public function get_user_info( $context = 'view' ) { |
705 | 705 | |
706 | 706 | $user_info = array( |
@@ -717,616 +717,616 @@ discard block |
||
717 | 717 | 'company' => $this->get_company( $context ), |
718 | 718 | 'vat_number' => $this->get_vat_number( $context ), |
719 | 719 | 'discount' => $this->get_discount_code( $context ), |
720 | - ); |
|
720 | + ); |
|
721 | + |
|
722 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
723 | + |
|
724 | + } |
|
725 | + |
|
726 | + /** |
|
727 | + * Get the customer id. |
|
728 | + * |
|
729 | + * @since 1.0.19 |
|
730 | + * @param string $context View or edit context. |
|
731 | + * @return int |
|
732 | + */ |
|
733 | + public function get_author( $context = 'view' ) { |
|
734 | + return (int) $this->get_prop( 'author', $context ); |
|
735 | + } |
|
736 | + |
|
737 | + /** |
|
738 | + * Alias of self::get_author(). |
|
739 | + * |
|
740 | + * @since 1.0.19 |
|
741 | + * @param string $context View or edit context. |
|
742 | + * @return int |
|
743 | + */ |
|
744 | + public function get_user_id( $context = 'view' ) { |
|
745 | + return $this->get_author( $context ); |
|
746 | + } |
|
747 | + |
|
748 | + /** |
|
749 | + * Alias of self::get_author(). |
|
750 | + * |
|
751 | + * @since 1.0.19 |
|
752 | + * @param string $context View or edit context. |
|
753 | + * @return int |
|
754 | + */ |
|
755 | + public function get_customer_id( $context = 'view' ) { |
|
756 | + return $this->get_author( $context ); |
|
757 | + } |
|
758 | + |
|
759 | + /** |
|
760 | + * Get the customer's ip. |
|
761 | + * |
|
762 | + * @since 1.0.19 |
|
763 | + * @param string $context View or edit context. |
|
764 | + * @return string |
|
765 | + */ |
|
766 | + public function get_ip( $context = 'view' ) { |
|
767 | + return $this->get_prop( 'user_ip', $context ); |
|
768 | + } |
|
721 | 769 | |
722 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
770 | + /** |
|
771 | + * Alias of self::get_ip(). |
|
772 | + * |
|
773 | + * @since 1.0.19 |
|
774 | + * @param string $context View or edit context. |
|
775 | + * @return string |
|
776 | + */ |
|
777 | + public function get_user_ip( $context = 'view' ) { |
|
778 | + return $this->get_ip( $context ); |
|
779 | + } |
|
723 | 780 | |
781 | + /** |
|
782 | + * Alias of self::get_ip(). |
|
783 | + * |
|
784 | + * @since 1.0.19 |
|
785 | + * @param string $context View or edit context. |
|
786 | + * @return string |
|
787 | + */ |
|
788 | + public function get_customer_ip( $context = 'view' ) { |
|
789 | + return $this->get_ip( $context ); |
|
724 | 790 | } |
725 | 791 | |
726 | 792 | /** |
727 | - * Get the customer id. |
|
728 | - * |
|
729 | - * @since 1.0.19 |
|
730 | - * @param string $context View or edit context. |
|
731 | - * @return int |
|
732 | - */ |
|
733 | - public function get_author( $context = 'view' ) { |
|
734 | - return (int) $this->get_prop( 'author', $context ); |
|
793 | + * Get the customer's first name. |
|
794 | + * |
|
795 | + * @since 1.0.19 |
|
796 | + * @param string $context View or edit context. |
|
797 | + * @return string |
|
798 | + */ |
|
799 | + public function get_first_name( $context = 'view' ) { |
|
800 | + return $this->get_prop( 'first_name', $context ); |
|
735 | 801 | } |
736 | 802 | |
737 | 803 | /** |
738 | - * Alias of self::get_author(). |
|
739 | - * |
|
740 | - * @since 1.0.19 |
|
741 | - * @param string $context View or edit context. |
|
742 | - * @return int |
|
743 | - */ |
|
744 | - public function get_user_id( $context = 'view' ) { |
|
745 | - return $this->get_author( $context ); |
|
804 | + * Alias of self::get_first_name(). |
|
805 | + * |
|
806 | + * @since 1.0.19 |
|
807 | + * @param string $context View or edit context. |
|
808 | + * @return int |
|
809 | + */ |
|
810 | + public function get_user_first_name( $context = 'view' ) { |
|
811 | + return $this->get_first_name( $context ); |
|
746 | 812 | } |
747 | 813 | |
748 | - /** |
|
749 | - * Alias of self::get_author(). |
|
750 | - * |
|
751 | - * @since 1.0.19 |
|
752 | - * @param string $context View or edit context. |
|
753 | - * @return int |
|
754 | - */ |
|
755 | - public function get_customer_id( $context = 'view' ) { |
|
756 | - return $this->get_author( $context ); |
|
814 | + /** |
|
815 | + * Alias of self::get_first_name(). |
|
816 | + * |
|
817 | + * @since 1.0.19 |
|
818 | + * @param string $context View or edit context. |
|
819 | + * @return int |
|
820 | + */ |
|
821 | + public function get_customer_first_name( $context = 'view' ) { |
|
822 | + return $this->get_first_name( $context ); |
|
757 | 823 | } |
758 | 824 | |
759 | 825 | /** |
760 | - * Get the customer's ip. |
|
761 | - * |
|
762 | - * @since 1.0.19 |
|
763 | - * @param string $context View or edit context. |
|
764 | - * @return string |
|
765 | - */ |
|
766 | - public function get_ip( $context = 'view' ) { |
|
767 | - return $this->get_prop( 'user_ip', $context ); |
|
826 | + * Get the customer's last name. |
|
827 | + * |
|
828 | + * @since 1.0.19 |
|
829 | + * @param string $context View or edit context. |
|
830 | + * @return string |
|
831 | + */ |
|
832 | + public function get_last_name( $context = 'view' ) { |
|
833 | + return $this->get_prop( 'last_name', $context ); |
|
768 | 834 | } |
769 | 835 | |
770 | 836 | /** |
771 | - * Alias of self::get_ip(). |
|
772 | - * |
|
773 | - * @since 1.0.19 |
|
774 | - * @param string $context View or edit context. |
|
775 | - * @return string |
|
776 | - */ |
|
777 | - public function get_user_ip( $context = 'view' ) { |
|
778 | - return $this->get_ip( $context ); |
|
837 | + * Alias of self::get_last_name(). |
|
838 | + * |
|
839 | + * @since 1.0.19 |
|
840 | + * @param string $context View or edit context. |
|
841 | + * @return int |
|
842 | + */ |
|
843 | + public function get_user_last_name( $context = 'view' ) { |
|
844 | + return $this->get_last_name( $context ); |
|
779 | 845 | } |
780 | 846 | |
781 | - /** |
|
782 | - * Alias of self::get_ip(). |
|
783 | - * |
|
784 | - * @since 1.0.19 |
|
785 | - * @param string $context View or edit context. |
|
786 | - * @return string |
|
787 | - */ |
|
788 | - public function get_customer_ip( $context = 'view' ) { |
|
789 | - return $this->get_ip( $context ); |
|
847 | + /** |
|
848 | + * Alias of self::get_last_name(). |
|
849 | + * |
|
850 | + * @since 1.0.19 |
|
851 | + * @param string $context View or edit context. |
|
852 | + * @return int |
|
853 | + */ |
|
854 | + public function get_customer_last_name( $context = 'view' ) { |
|
855 | + return $this->get_last_name( $context ); |
|
790 | 856 | } |
791 | 857 | |
792 | 858 | /** |
793 | - * Get the customer's first name. |
|
794 | - * |
|
795 | - * @since 1.0.19 |
|
796 | - * @param string $context View or edit context. |
|
797 | - * @return string |
|
798 | - */ |
|
799 | - public function get_first_name( $context = 'view' ) { |
|
800 | - return $this->get_prop( 'first_name', $context ); |
|
859 | + * Get the customer's full name. |
|
860 | + * |
|
861 | + * @since 1.0.19 |
|
862 | + * @param string $context View or edit context. |
|
863 | + * @return string |
|
864 | + */ |
|
865 | + public function get_full_name( $context = 'view' ) { |
|
866 | + return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
801 | 867 | } |
802 | 868 | |
803 | 869 | /** |
804 | - * Alias of self::get_first_name(). |
|
805 | - * |
|
806 | - * @since 1.0.19 |
|
807 | - * @param string $context View or edit context. |
|
808 | - * @return int |
|
809 | - */ |
|
810 | - public function get_user_first_name( $context = 'view' ) { |
|
811 | - return $this->get_first_name( $context ); |
|
870 | + * Alias of self::get_full_name(). |
|
871 | + * |
|
872 | + * @since 1.0.19 |
|
873 | + * @param string $context View or edit context. |
|
874 | + * @return int |
|
875 | + */ |
|
876 | + public function get_user_full_name( $context = 'view' ) { |
|
877 | + return $this->get_full_name( $context ); |
|
812 | 878 | } |
813 | 879 | |
814 | - /** |
|
815 | - * Alias of self::get_first_name(). |
|
816 | - * |
|
817 | - * @since 1.0.19 |
|
818 | - * @param string $context View or edit context. |
|
819 | - * @return int |
|
820 | - */ |
|
821 | - public function get_customer_first_name( $context = 'view' ) { |
|
822 | - return $this->get_first_name( $context ); |
|
880 | + /** |
|
881 | + * Alias of self::get_full_name(). |
|
882 | + * |
|
883 | + * @since 1.0.19 |
|
884 | + * @param string $context View or edit context. |
|
885 | + * @return int |
|
886 | + */ |
|
887 | + public function get_customer_full_name( $context = 'view' ) { |
|
888 | + return $this->get_full_name( $context ); |
|
823 | 889 | } |
824 | 890 | |
825 | 891 | /** |
826 | - * Get the customer's last name. |
|
827 | - * |
|
828 | - * @since 1.0.19 |
|
829 | - * @param string $context View or edit context. |
|
830 | - * @return string |
|
831 | - */ |
|
832 | - public function get_last_name( $context = 'view' ) { |
|
833 | - return $this->get_prop( 'last_name', $context ); |
|
892 | + * Get the customer's phone number. |
|
893 | + * |
|
894 | + * @since 1.0.19 |
|
895 | + * @param string $context View or edit context. |
|
896 | + * @return string |
|
897 | + */ |
|
898 | + public function get_phone( $context = 'view' ) { |
|
899 | + return $this->get_prop( 'phone', $context ); |
|
834 | 900 | } |
835 | 901 | |
836 | 902 | /** |
837 | - * Alias of self::get_last_name(). |
|
838 | - * |
|
839 | - * @since 1.0.19 |
|
840 | - * @param string $context View or edit context. |
|
841 | - * @return int |
|
842 | - */ |
|
843 | - public function get_user_last_name( $context = 'view' ) { |
|
844 | - return $this->get_last_name( $context ); |
|
903 | + * Alias of self::get_phone(). |
|
904 | + * |
|
905 | + * @since 1.0.19 |
|
906 | + * @param string $context View or edit context. |
|
907 | + * @return int |
|
908 | + */ |
|
909 | + public function get_phone_number( $context = 'view' ) { |
|
910 | + return $this->get_phone( $context ); |
|
845 | 911 | } |
846 | 912 | |
847 | 913 | /** |
848 | - * Alias of self::get_last_name(). |
|
849 | - * |
|
850 | - * @since 1.0.19 |
|
851 | - * @param string $context View or edit context. |
|
852 | - * @return int |
|
853 | - */ |
|
854 | - public function get_customer_last_name( $context = 'view' ) { |
|
855 | - return $this->get_last_name( $context ); |
|
914 | + * Alias of self::get_phone(). |
|
915 | + * |
|
916 | + * @since 1.0.19 |
|
917 | + * @param string $context View or edit context. |
|
918 | + * @return int |
|
919 | + */ |
|
920 | + public function get_user_phone( $context = 'view' ) { |
|
921 | + return $this->get_phone( $context ); |
|
856 | 922 | } |
857 | 923 | |
858 | 924 | /** |
859 | - * Get the customer's full name. |
|
860 | - * |
|
861 | - * @since 1.0.19 |
|
862 | - * @param string $context View or edit context. |
|
863 | - * @return string |
|
864 | - */ |
|
865 | - public function get_full_name( $context = 'view' ) { |
|
866 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
925 | + * Alias of self::get_phone(). |
|
926 | + * |
|
927 | + * @since 1.0.19 |
|
928 | + * @param string $context View or edit context. |
|
929 | + * @return int |
|
930 | + */ |
|
931 | + public function get_customer_phone( $context = 'view' ) { |
|
932 | + return $this->get_phone( $context ); |
|
867 | 933 | } |
868 | 934 | |
869 | 935 | /** |
870 | - * Alias of self::get_full_name(). |
|
871 | - * |
|
872 | - * @since 1.0.19 |
|
873 | - * @param string $context View or edit context. |
|
874 | - * @return int |
|
875 | - */ |
|
876 | - public function get_user_full_name( $context = 'view' ) { |
|
877 | - return $this->get_full_name( $context ); |
|
936 | + * Get the customer's email address. |
|
937 | + * |
|
938 | + * @since 1.0.19 |
|
939 | + * @param string $context View or edit context. |
|
940 | + * @return string |
|
941 | + */ |
|
942 | + public function get_email( $context = 'view' ) { |
|
943 | + return $this->get_prop( 'email', $context ); |
|
878 | 944 | } |
879 | 945 | |
880 | 946 | /** |
881 | - * Alias of self::get_full_name(). |
|
882 | - * |
|
883 | - * @since 1.0.19 |
|
884 | - * @param string $context View or edit context. |
|
885 | - * @return int |
|
886 | - */ |
|
887 | - public function get_customer_full_name( $context = 'view' ) { |
|
888 | - return $this->get_full_name( $context ); |
|
947 | + * Alias of self::get_email(). |
|
948 | + * |
|
949 | + * @since 1.0.19 |
|
950 | + * @param string $context View or edit context. |
|
951 | + * @return string |
|
952 | + */ |
|
953 | + public function get_email_address( $context = 'view' ) { |
|
954 | + return $this->get_email( $context ); |
|
889 | 955 | } |
890 | 956 | |
891 | 957 | /** |
892 | - * Get the customer's phone number. |
|
893 | - * |
|
894 | - * @since 1.0.19 |
|
895 | - * @param string $context View or edit context. |
|
896 | - * @return string |
|
897 | - */ |
|
898 | - public function get_phone( $context = 'view' ) { |
|
899 | - return $this->get_prop( 'phone', $context ); |
|
958 | + * Alias of self::get_email(). |
|
959 | + * |
|
960 | + * @since 1.0.19 |
|
961 | + * @param string $context View or edit context. |
|
962 | + * @return int |
|
963 | + */ |
|
964 | + public function get_user_email( $context = 'view' ) { |
|
965 | + return $this->get_email( $context ); |
|
900 | 966 | } |
901 | 967 | |
902 | 968 | /** |
903 | - * Alias of self::get_phone(). |
|
904 | - * |
|
905 | - * @since 1.0.19 |
|
906 | - * @param string $context View or edit context. |
|
907 | - * @return int |
|
908 | - */ |
|
909 | - public function get_phone_number( $context = 'view' ) { |
|
910 | - return $this->get_phone( $context ); |
|
969 | + * Alias of self::get_email(). |
|
970 | + * |
|
971 | + * @since 1.0.19 |
|
972 | + * @param string $context View or edit context. |
|
973 | + * @return int |
|
974 | + */ |
|
975 | + public function get_customer_email( $context = 'view' ) { |
|
976 | + return $this->get_email( $context ); |
|
911 | 977 | } |
912 | 978 | |
913 | 979 | /** |
914 | - * Alias of self::get_phone(). |
|
915 | - * |
|
916 | - * @since 1.0.19 |
|
917 | - * @param string $context View or edit context. |
|
918 | - * @return int |
|
919 | - */ |
|
920 | - public function get_user_phone( $context = 'view' ) { |
|
921 | - return $this->get_phone( $context ); |
|
980 | + * Get the customer's country. |
|
981 | + * |
|
982 | + * @since 1.0.19 |
|
983 | + * @param string $context View or edit context. |
|
984 | + * @return string |
|
985 | + */ |
|
986 | + public function get_country( $context = 'view' ) { |
|
987 | + $country = $this->get_prop( 'country', $context ); |
|
988 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
922 | 989 | } |
923 | 990 | |
924 | 991 | /** |
925 | - * Alias of self::get_phone(). |
|
926 | - * |
|
927 | - * @since 1.0.19 |
|
928 | - * @param string $context View or edit context. |
|
929 | - * @return int |
|
930 | - */ |
|
931 | - public function get_customer_phone( $context = 'view' ) { |
|
932 | - return $this->get_phone( $context ); |
|
992 | + * Alias of self::get_country(). |
|
993 | + * |
|
994 | + * @since 1.0.19 |
|
995 | + * @param string $context View or edit context. |
|
996 | + * @return int |
|
997 | + */ |
|
998 | + public function get_user_country( $context = 'view' ) { |
|
999 | + return $this->get_country( $context ); |
|
933 | 1000 | } |
934 | 1001 | |
935 | 1002 | /** |
936 | - * Get the customer's email address. |
|
937 | - * |
|
938 | - * @since 1.0.19 |
|
939 | - * @param string $context View or edit context. |
|
940 | - * @return string |
|
941 | - */ |
|
942 | - public function get_email( $context = 'view' ) { |
|
943 | - return $this->get_prop( 'email', $context ); |
|
1003 | + * Alias of self::get_country(). |
|
1004 | + * |
|
1005 | + * @since 1.0.19 |
|
1006 | + * @param string $context View or edit context. |
|
1007 | + * @return int |
|
1008 | + */ |
|
1009 | + public function get_customer_country( $context = 'view' ) { |
|
1010 | + return $this->get_country( $context ); |
|
944 | 1011 | } |
945 | 1012 | |
946 | 1013 | /** |
947 | - * Alias of self::get_email(). |
|
948 | - * |
|
949 | - * @since 1.0.19 |
|
950 | - * @param string $context View or edit context. |
|
951 | - * @return string |
|
952 | - */ |
|
953 | - public function get_email_address( $context = 'view' ) { |
|
954 | - return $this->get_email( $context ); |
|
1014 | + * Get the customer's state. |
|
1015 | + * |
|
1016 | + * @since 1.0.19 |
|
1017 | + * @param string $context View or edit context. |
|
1018 | + * @return string |
|
1019 | + */ |
|
1020 | + public function get_state( $context = 'view' ) { |
|
1021 | + $state = $this->get_prop( 'state', $context ); |
|
1022 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
955 | 1023 | } |
956 | 1024 | |
957 | 1025 | /** |
958 | - * Alias of self::get_email(). |
|
959 | - * |
|
960 | - * @since 1.0.19 |
|
961 | - * @param string $context View or edit context. |
|
962 | - * @return int |
|
963 | - */ |
|
964 | - public function get_user_email( $context = 'view' ) { |
|
965 | - return $this->get_email( $context ); |
|
1026 | + * Alias of self::get_state(). |
|
1027 | + * |
|
1028 | + * @since 1.0.19 |
|
1029 | + * @param string $context View or edit context. |
|
1030 | + * @return int |
|
1031 | + */ |
|
1032 | + public function get_user_state( $context = 'view' ) { |
|
1033 | + return $this->get_state( $context ); |
|
966 | 1034 | } |
967 | 1035 | |
968 | 1036 | /** |
969 | - * Alias of self::get_email(). |
|
970 | - * |
|
971 | - * @since 1.0.19 |
|
972 | - * @param string $context View or edit context. |
|
973 | - * @return int |
|
974 | - */ |
|
975 | - public function get_customer_email( $context = 'view' ) { |
|
976 | - return $this->get_email( $context ); |
|
1037 | + * Alias of self::get_state(). |
|
1038 | + * |
|
1039 | + * @since 1.0.19 |
|
1040 | + * @param string $context View or edit context. |
|
1041 | + * @return int |
|
1042 | + */ |
|
1043 | + public function get_customer_state( $context = 'view' ) { |
|
1044 | + return $this->get_state( $context ); |
|
977 | 1045 | } |
978 | 1046 | |
979 | 1047 | /** |
980 | - * Get the customer's country. |
|
981 | - * |
|
982 | - * @since 1.0.19 |
|
983 | - * @param string $context View or edit context. |
|
984 | - * @return string |
|
985 | - */ |
|
986 | - public function get_country( $context = 'view' ) { |
|
987 | - $country = $this->get_prop( 'country', $context ); |
|
988 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
1048 | + * Get the customer's city. |
|
1049 | + * |
|
1050 | + * @since 1.0.19 |
|
1051 | + * @param string $context View or edit context. |
|
1052 | + * @return string |
|
1053 | + */ |
|
1054 | + public function get_city( $context = 'view' ) { |
|
1055 | + return $this->get_prop( 'city', $context ); |
|
989 | 1056 | } |
990 | 1057 | |
991 | 1058 | /** |
992 | - * Alias of self::get_country(). |
|
993 | - * |
|
994 | - * @since 1.0.19 |
|
995 | - * @param string $context View or edit context. |
|
996 | - * @return int |
|
997 | - */ |
|
998 | - public function get_user_country( $context = 'view' ) { |
|
999 | - return $this->get_country( $context ); |
|
1059 | + * Alias of self::get_city(). |
|
1060 | + * |
|
1061 | + * @since 1.0.19 |
|
1062 | + * @param string $context View or edit context. |
|
1063 | + * @return string |
|
1064 | + */ |
|
1065 | + public function get_user_city( $context = 'view' ) { |
|
1066 | + return $this->get_city( $context ); |
|
1000 | 1067 | } |
1001 | 1068 | |
1002 | 1069 | /** |
1003 | - * Alias of self::get_country(). |
|
1004 | - * |
|
1005 | - * @since 1.0.19 |
|
1006 | - * @param string $context View or edit context. |
|
1007 | - * @return int |
|
1008 | - */ |
|
1009 | - public function get_customer_country( $context = 'view' ) { |
|
1010 | - return $this->get_country( $context ); |
|
1070 | + * Alias of self::get_city(). |
|
1071 | + * |
|
1072 | + * @since 1.0.19 |
|
1073 | + * @param string $context View or edit context. |
|
1074 | + * @return string |
|
1075 | + */ |
|
1076 | + public function get_customer_city( $context = 'view' ) { |
|
1077 | + return $this->get_city( $context ); |
|
1011 | 1078 | } |
1012 | 1079 | |
1013 | 1080 | /** |
1014 | - * Get the customer's state. |
|
1015 | - * |
|
1016 | - * @since 1.0.19 |
|
1017 | - * @param string $context View or edit context. |
|
1018 | - * @return string |
|
1019 | - */ |
|
1020 | - public function get_state( $context = 'view' ) { |
|
1021 | - $state = $this->get_prop( 'state', $context ); |
|
1022 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1081 | + * Get the customer's zip. |
|
1082 | + * |
|
1083 | + * @since 1.0.19 |
|
1084 | + * @param string $context View or edit context. |
|
1085 | + * @return string |
|
1086 | + */ |
|
1087 | + public function get_zip( $context = 'view' ) { |
|
1088 | + return $this->get_prop( 'zip', $context ); |
|
1023 | 1089 | } |
1024 | 1090 | |
1025 | 1091 | /** |
1026 | - * Alias of self::get_state(). |
|
1027 | - * |
|
1028 | - * @since 1.0.19 |
|
1029 | - * @param string $context View or edit context. |
|
1030 | - * @return int |
|
1031 | - */ |
|
1032 | - public function get_user_state( $context = 'view' ) { |
|
1033 | - return $this->get_state( $context ); |
|
1092 | + * Alias of self::get_zip(). |
|
1093 | + * |
|
1094 | + * @since 1.0.19 |
|
1095 | + * @param string $context View or edit context. |
|
1096 | + * @return string |
|
1097 | + */ |
|
1098 | + public function get_user_zip( $context = 'view' ) { |
|
1099 | + return $this->get_zip( $context ); |
|
1034 | 1100 | } |
1035 | 1101 | |
1036 | 1102 | /** |
1037 | - * Alias of self::get_state(). |
|
1038 | - * |
|
1039 | - * @since 1.0.19 |
|
1040 | - * @param string $context View or edit context. |
|
1041 | - * @return int |
|
1042 | - */ |
|
1043 | - public function get_customer_state( $context = 'view' ) { |
|
1044 | - return $this->get_state( $context ); |
|
1103 | + * Alias of self::get_zip(). |
|
1104 | + * |
|
1105 | + * @since 1.0.19 |
|
1106 | + * @param string $context View or edit context. |
|
1107 | + * @return string |
|
1108 | + */ |
|
1109 | + public function get_customer_zip( $context = 'view' ) { |
|
1110 | + return $this->get_zip( $context ); |
|
1045 | 1111 | } |
1046 | 1112 | |
1047 | 1113 | /** |
1048 | - * Get the customer's city. |
|
1049 | - * |
|
1050 | - * @since 1.0.19 |
|
1051 | - * @param string $context View or edit context. |
|
1052 | - * @return string |
|
1053 | - */ |
|
1054 | - public function get_city( $context = 'view' ) { |
|
1055 | - return $this->get_prop( 'city', $context ); |
|
1114 | + * Get the customer's company. |
|
1115 | + * |
|
1116 | + * @since 1.0.19 |
|
1117 | + * @param string $context View or edit context. |
|
1118 | + * @return string |
|
1119 | + */ |
|
1120 | + public function get_company( $context = 'view' ) { |
|
1121 | + return $this->get_prop( 'company', $context ); |
|
1056 | 1122 | } |
1057 | 1123 | |
1058 | 1124 | /** |
1059 | - * Alias of self::get_city(). |
|
1060 | - * |
|
1061 | - * @since 1.0.19 |
|
1062 | - * @param string $context View or edit context. |
|
1063 | - * @return string |
|
1064 | - */ |
|
1065 | - public function get_user_city( $context = 'view' ) { |
|
1066 | - return $this->get_city( $context ); |
|
1125 | + * Alias of self::get_company(). |
|
1126 | + * |
|
1127 | + * @since 1.0.19 |
|
1128 | + * @param string $context View or edit context. |
|
1129 | + * @return string |
|
1130 | + */ |
|
1131 | + public function get_user_company( $context = 'view' ) { |
|
1132 | + return $this->get_company( $context ); |
|
1067 | 1133 | } |
1068 | 1134 | |
1069 | 1135 | /** |
1070 | - * Alias of self::get_city(). |
|
1071 | - * |
|
1072 | - * @since 1.0.19 |
|
1073 | - * @param string $context View or edit context. |
|
1074 | - * @return string |
|
1075 | - */ |
|
1076 | - public function get_customer_city( $context = 'view' ) { |
|
1077 | - return $this->get_city( $context ); |
|
1136 | + * Alias of self::get_company(). |
|
1137 | + * |
|
1138 | + * @since 1.0.19 |
|
1139 | + * @param string $context View or edit context. |
|
1140 | + * @return string |
|
1141 | + */ |
|
1142 | + public function get_customer_company( $context = 'view' ) { |
|
1143 | + return $this->get_company( $context ); |
|
1078 | 1144 | } |
1079 | 1145 | |
1080 | 1146 | /** |
1081 | - * Get the customer's zip. |
|
1082 | - * |
|
1083 | - * @since 1.0.19 |
|
1084 | - * @param string $context View or edit context. |
|
1085 | - * @return string |
|
1086 | - */ |
|
1087 | - public function get_zip( $context = 'view' ) { |
|
1088 | - return $this->get_prop( 'zip', $context ); |
|
1147 | + * Get the customer's vat number. |
|
1148 | + * |
|
1149 | + * @since 1.0.19 |
|
1150 | + * @param string $context View or edit context. |
|
1151 | + * @return string |
|
1152 | + */ |
|
1153 | + public function get_vat_number( $context = 'view' ) { |
|
1154 | + return $this->get_prop( 'vat_number', $context ); |
|
1089 | 1155 | } |
1090 | 1156 | |
1091 | 1157 | /** |
1092 | - * Alias of self::get_zip(). |
|
1093 | - * |
|
1094 | - * @since 1.0.19 |
|
1095 | - * @param string $context View or edit context. |
|
1096 | - * @return string |
|
1097 | - */ |
|
1098 | - public function get_user_zip( $context = 'view' ) { |
|
1099 | - return $this->get_zip( $context ); |
|
1158 | + * Alias of self::get_vat_number(). |
|
1159 | + * |
|
1160 | + * @since 1.0.19 |
|
1161 | + * @param string $context View or edit context. |
|
1162 | + * @return string |
|
1163 | + */ |
|
1164 | + public function get_user_vat_number( $context = 'view' ) { |
|
1165 | + return $this->get_vat_number( $context ); |
|
1100 | 1166 | } |
1101 | 1167 | |
1102 | 1168 | /** |
1103 | - * Alias of self::get_zip(). |
|
1104 | - * |
|
1105 | - * @since 1.0.19 |
|
1106 | - * @param string $context View or edit context. |
|
1107 | - * @return string |
|
1108 | - */ |
|
1109 | - public function get_customer_zip( $context = 'view' ) { |
|
1110 | - return $this->get_zip( $context ); |
|
1169 | + * Alias of self::get_vat_number(). |
|
1170 | + * |
|
1171 | + * @since 1.0.19 |
|
1172 | + * @param string $context View or edit context. |
|
1173 | + * @return string |
|
1174 | + */ |
|
1175 | + public function get_customer_vat_number( $context = 'view' ) { |
|
1176 | + return $this->get_vat_number( $context ); |
|
1111 | 1177 | } |
1112 | 1178 | |
1113 | 1179 | /** |
1114 | - * Get the customer's company. |
|
1115 | - * |
|
1116 | - * @since 1.0.19 |
|
1117 | - * @param string $context View or edit context. |
|
1118 | - * @return string |
|
1119 | - */ |
|
1120 | - public function get_company( $context = 'view' ) { |
|
1121 | - return $this->get_prop( 'company', $context ); |
|
1180 | + * Get the customer's vat rate. |
|
1181 | + * |
|
1182 | + * @since 1.0.19 |
|
1183 | + * @param string $context View or edit context. |
|
1184 | + * @return string |
|
1185 | + */ |
|
1186 | + public function get_vat_rate( $context = 'view' ) { |
|
1187 | + return $this->get_prop( 'vat_rate', $context ); |
|
1122 | 1188 | } |
1123 | 1189 | |
1124 | 1190 | /** |
1125 | - * Alias of self::get_company(). |
|
1126 | - * |
|
1127 | - * @since 1.0.19 |
|
1128 | - * @param string $context View or edit context. |
|
1129 | - * @return string |
|
1130 | - */ |
|
1131 | - public function get_user_company( $context = 'view' ) { |
|
1132 | - return $this->get_company( $context ); |
|
1191 | + * Alias of self::get_vat_rate(). |
|
1192 | + * |
|
1193 | + * @since 1.0.19 |
|
1194 | + * @param string $context View or edit context. |
|
1195 | + * @return string |
|
1196 | + */ |
|
1197 | + public function get_user_vat_rate( $context = 'view' ) { |
|
1198 | + return $this->get_vat_rate( $context ); |
|
1133 | 1199 | } |
1134 | 1200 | |
1135 | 1201 | /** |
1136 | - * Alias of self::get_company(). |
|
1137 | - * |
|
1138 | - * @since 1.0.19 |
|
1139 | - * @param string $context View or edit context. |
|
1140 | - * @return string |
|
1141 | - */ |
|
1142 | - public function get_customer_company( $context = 'view' ) { |
|
1143 | - return $this->get_company( $context ); |
|
1202 | + * Alias of self::get_vat_rate(). |
|
1203 | + * |
|
1204 | + * @since 1.0.19 |
|
1205 | + * @param string $context View or edit context. |
|
1206 | + * @return string |
|
1207 | + */ |
|
1208 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
1209 | + return $this->get_vat_rate( $context ); |
|
1144 | 1210 | } |
1145 | 1211 | |
1146 | 1212 | /** |
1147 | - * Get the customer's vat number. |
|
1148 | - * |
|
1149 | - * @since 1.0.19 |
|
1150 | - * @param string $context View or edit context. |
|
1151 | - * @return string |
|
1152 | - */ |
|
1153 | - public function get_vat_number( $context = 'view' ) { |
|
1154 | - return $this->get_prop( 'vat_number', $context ); |
|
1213 | + * Get the customer's address. |
|
1214 | + * |
|
1215 | + * @since 1.0.19 |
|
1216 | + * @param string $context View or edit context. |
|
1217 | + * @return string |
|
1218 | + */ |
|
1219 | + public function get_address( $context = 'view' ) { |
|
1220 | + return $this->get_prop( 'address', $context ); |
|
1155 | 1221 | } |
1156 | 1222 | |
1157 | 1223 | /** |
1158 | - * Alias of self::get_vat_number(). |
|
1159 | - * |
|
1160 | - * @since 1.0.19 |
|
1161 | - * @param string $context View or edit context. |
|
1162 | - * @return string |
|
1163 | - */ |
|
1164 | - public function get_user_vat_number( $context = 'view' ) { |
|
1165 | - return $this->get_vat_number( $context ); |
|
1224 | + * Alias of self::get_address(). |
|
1225 | + * |
|
1226 | + * @since 1.0.19 |
|
1227 | + * @param string $context View or edit context. |
|
1228 | + * @return string |
|
1229 | + */ |
|
1230 | + public function get_user_address( $context = 'view' ) { |
|
1231 | + return $this->get_address( $context ); |
|
1166 | 1232 | } |
1167 | 1233 | |
1168 | 1234 | /** |
1169 | - * Alias of self::get_vat_number(). |
|
1170 | - * |
|
1171 | - * @since 1.0.19 |
|
1172 | - * @param string $context View or edit context. |
|
1173 | - * @return string |
|
1174 | - */ |
|
1175 | - public function get_customer_vat_number( $context = 'view' ) { |
|
1176 | - return $this->get_vat_number( $context ); |
|
1235 | + * Alias of self::get_address(). |
|
1236 | + * |
|
1237 | + * @since 1.0.19 |
|
1238 | + * @param string $context View or edit context. |
|
1239 | + * @return string |
|
1240 | + */ |
|
1241 | + public function get_customer_address( $context = 'view' ) { |
|
1242 | + return $this->get_address( $context ); |
|
1243 | + } |
|
1244 | + |
|
1245 | + /** |
|
1246 | + * Get whether the customer has viewed the invoice or not. |
|
1247 | + * |
|
1248 | + * @since 1.0.19 |
|
1249 | + * @param string $context View or edit context. |
|
1250 | + * @return bool |
|
1251 | + */ |
|
1252 | + public function get_is_viewed( $context = 'view' ) { |
|
1253 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1254 | + } |
|
1255 | + |
|
1256 | + /** |
|
1257 | + * Get other recipients for invoice communications. |
|
1258 | + * |
|
1259 | + * @since 1.0.19 |
|
1260 | + * @param string $context View or edit context. |
|
1261 | + * @return bool |
|
1262 | + */ |
|
1263 | + public function get_email_cc( $context = 'view' ) { |
|
1264 | + return $this->get_prop( 'email_cc', $context ); |
|
1265 | + } |
|
1266 | + |
|
1267 | + /** |
|
1268 | + * Get invoice template. |
|
1269 | + * |
|
1270 | + * @since 1.0.19 |
|
1271 | + * @param string $context View or edit context. |
|
1272 | + * @return bool |
|
1273 | + */ |
|
1274 | + public function get_template( $context = 'view' ) { |
|
1275 | + return $this->get_prop( 'template', $context ); |
|
1276 | + } |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * Get invoice source. |
|
1280 | + * |
|
1281 | + * @since 1.0.19 |
|
1282 | + * @param string $context View or edit context. |
|
1283 | + * @return bool |
|
1284 | + */ |
|
1285 | + public function get_created_via( $context = 'view' ) { |
|
1286 | + return $this->get_prop( 'created_via', $context ); |
|
1177 | 1287 | } |
1178 | 1288 | |
1179 | 1289 | /** |
1180 | - * Get the customer's vat rate. |
|
1181 | - * |
|
1182 | - * @since 1.0.19 |
|
1183 | - * @param string $context View or edit context. |
|
1184 | - * @return string |
|
1185 | - */ |
|
1186 | - public function get_vat_rate( $context = 'view' ) { |
|
1187 | - return $this->get_prop( 'vat_rate', $context ); |
|
1188 | - } |
|
1189 | - |
|
1190 | - /** |
|
1191 | - * Alias of self::get_vat_rate(). |
|
1192 | - * |
|
1193 | - * @since 1.0.19 |
|
1194 | - * @param string $context View or edit context. |
|
1195 | - * @return string |
|
1196 | - */ |
|
1197 | - public function get_user_vat_rate( $context = 'view' ) { |
|
1198 | - return $this->get_vat_rate( $context ); |
|
1199 | - } |
|
1200 | - |
|
1201 | - /** |
|
1202 | - * Alias of self::get_vat_rate(). |
|
1203 | - * |
|
1204 | - * @since 1.0.19 |
|
1205 | - * @param string $context View or edit context. |
|
1206 | - * @return string |
|
1207 | - */ |
|
1208 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
1209 | - return $this->get_vat_rate( $context ); |
|
1210 | - } |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * Get the customer's address. |
|
1214 | - * |
|
1215 | - * @since 1.0.19 |
|
1216 | - * @param string $context View or edit context. |
|
1217 | - * @return string |
|
1218 | - */ |
|
1219 | - public function get_address( $context = 'view' ) { |
|
1220 | - return $this->get_prop( 'address', $context ); |
|
1221 | - } |
|
1222 | - |
|
1223 | - /** |
|
1224 | - * Alias of self::get_address(). |
|
1225 | - * |
|
1226 | - * @since 1.0.19 |
|
1227 | - * @param string $context View or edit context. |
|
1228 | - * @return string |
|
1229 | - */ |
|
1230 | - public function get_user_address( $context = 'view' ) { |
|
1231 | - return $this->get_address( $context ); |
|
1232 | - } |
|
1233 | - |
|
1234 | - /** |
|
1235 | - * Alias of self::get_address(). |
|
1236 | - * |
|
1237 | - * @since 1.0.19 |
|
1238 | - * @param string $context View or edit context. |
|
1239 | - * @return string |
|
1240 | - */ |
|
1241 | - public function get_customer_address( $context = 'view' ) { |
|
1242 | - return $this->get_address( $context ); |
|
1243 | - } |
|
1244 | - |
|
1245 | - /** |
|
1246 | - * Get whether the customer has viewed the invoice or not. |
|
1247 | - * |
|
1248 | - * @since 1.0.19 |
|
1249 | - * @param string $context View or edit context. |
|
1250 | - * @return bool |
|
1251 | - */ |
|
1252 | - public function get_is_viewed( $context = 'view' ) { |
|
1253 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1254 | - } |
|
1255 | - |
|
1256 | - /** |
|
1257 | - * Get other recipients for invoice communications. |
|
1258 | - * |
|
1259 | - * @since 1.0.19 |
|
1260 | - * @param string $context View or edit context. |
|
1261 | - * @return bool |
|
1262 | - */ |
|
1263 | - public function get_email_cc( $context = 'view' ) { |
|
1264 | - return $this->get_prop( 'email_cc', $context ); |
|
1265 | - } |
|
1266 | - |
|
1267 | - /** |
|
1268 | - * Get invoice template. |
|
1269 | - * |
|
1270 | - * @since 1.0.19 |
|
1271 | - * @param string $context View or edit context. |
|
1272 | - * @return bool |
|
1273 | - */ |
|
1274 | - public function get_template( $context = 'view' ) { |
|
1275 | - return $this->get_prop( 'template', $context ); |
|
1276 | - } |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * Get invoice source. |
|
1280 | - * |
|
1281 | - * @since 1.0.19 |
|
1282 | - * @param string $context View or edit context. |
|
1283 | - * @return bool |
|
1284 | - */ |
|
1285 | - public function get_created_via( $context = 'view' ) { |
|
1286 | - return $this->get_prop( 'created_via', $context ); |
|
1287 | - } |
|
1288 | - |
|
1289 | - /** |
|
1290 | - * Get whether the customer has confirmed their address. |
|
1291 | - * |
|
1292 | - * @since 1.0.19 |
|
1293 | - * @param string $context View or edit context. |
|
1294 | - * @return bool |
|
1295 | - */ |
|
1296 | - public function get_address_confirmed( $context = 'view' ) { |
|
1297 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1298 | - } |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * Alias of self::get_address_confirmed(). |
|
1302 | - * |
|
1303 | - * @since 1.0.19 |
|
1304 | - * @param string $context View or edit context. |
|
1305 | - * @return bool |
|
1306 | - */ |
|
1307 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1308 | - return $this->get_address_confirmed( $context ); |
|
1309 | - } |
|
1310 | - |
|
1311 | - /** |
|
1312 | - * Alias of self::get_address(). |
|
1313 | - * |
|
1314 | - * @since 1.0.19 |
|
1315 | - * @param string $context View or edit context. |
|
1316 | - * @return bool |
|
1317 | - */ |
|
1318 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1319 | - return $this->get_address_confirmed( $context ); |
|
1320 | - } |
|
1321 | - |
|
1322 | - /** |
|
1323 | - * Get the invoice subtotal. |
|
1324 | - * |
|
1325 | - * @since 1.0.19 |
|
1326 | - * @param string $context View or edit context. |
|
1327 | - * @return float |
|
1328 | - */ |
|
1329 | - public function get_subtotal( $context = 'view' ) { |
|
1290 | + * Get whether the customer has confirmed their address. |
|
1291 | + * |
|
1292 | + * @since 1.0.19 |
|
1293 | + * @param string $context View or edit context. |
|
1294 | + * @return bool |
|
1295 | + */ |
|
1296 | + public function get_address_confirmed( $context = 'view' ) { |
|
1297 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1298 | + } |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * Alias of self::get_address_confirmed(). |
|
1302 | + * |
|
1303 | + * @since 1.0.19 |
|
1304 | + * @param string $context View or edit context. |
|
1305 | + * @return bool |
|
1306 | + */ |
|
1307 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
1308 | + return $this->get_address_confirmed( $context ); |
|
1309 | + } |
|
1310 | + |
|
1311 | + /** |
|
1312 | + * Alias of self::get_address(). |
|
1313 | + * |
|
1314 | + * @since 1.0.19 |
|
1315 | + * @param string $context View or edit context. |
|
1316 | + * @return bool |
|
1317 | + */ |
|
1318 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
1319 | + return $this->get_address_confirmed( $context ); |
|
1320 | + } |
|
1321 | + |
|
1322 | + /** |
|
1323 | + * Get the invoice subtotal. |
|
1324 | + * |
|
1325 | + * @since 1.0.19 |
|
1326 | + * @param string $context View or edit context. |
|
1327 | + * @return float |
|
1328 | + */ |
|
1329 | + public function get_subtotal( $context = 'view' ) { |
|
1330 | 1330 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
1331 | 1331 | |
1332 | 1332 | // Backwards compatibility. |
@@ -1338,165 +1338,165 @@ discard block |
||
1338 | 1338 | } |
1339 | 1339 | |
1340 | 1340 | /** |
1341 | - * Get the invoice discount total. |
|
1342 | - * |
|
1343 | - * @since 1.0.19 |
|
1344 | - * @param string $context View or edit context. |
|
1345 | - * @return float |
|
1346 | - */ |
|
1347 | - public function get_total_discount( $context = 'view' ) { |
|
1348 | - return (float) $this->get_prop( 'total_discount', $context ); |
|
1341 | + * Get the invoice discount total. |
|
1342 | + * |
|
1343 | + * @since 1.0.19 |
|
1344 | + * @param string $context View or edit context. |
|
1345 | + * @return float |
|
1346 | + */ |
|
1347 | + public function get_total_discount( $context = 'view' ) { |
|
1348 | + return (float) $this->get_prop( 'total_discount', $context ); |
|
1349 | 1349 | } |
1350 | 1350 | |
1351 | 1351 | /** |
1352 | - * Get the invoice tax total. |
|
1353 | - * |
|
1354 | - * @since 1.0.19 |
|
1355 | - * @param string $context View or edit context. |
|
1356 | - * @return float |
|
1357 | - */ |
|
1358 | - public function get_total_tax( $context = 'view' ) { |
|
1359 | - return (float) $this->get_prop( 'total_tax', $context ); |
|
1360 | - } |
|
1352 | + * Get the invoice tax total. |
|
1353 | + * |
|
1354 | + * @since 1.0.19 |
|
1355 | + * @param string $context View or edit context. |
|
1356 | + * @return float |
|
1357 | + */ |
|
1358 | + public function get_total_tax( $context = 'view' ) { |
|
1359 | + return (float) $this->get_prop( 'total_tax', $context ); |
|
1360 | + } |
|
1361 | 1361 | |
1362 | - /** |
|
1363 | - * @deprecated |
|
1364 | - */ |
|
1365 | - public function get_final_tax( $currency = false ) { |
|
1366 | - $tax = $this->get_total_tax(); |
|
1362 | + /** |
|
1363 | + * @deprecated |
|
1364 | + */ |
|
1365 | + public function get_final_tax( $currency = false ) { |
|
1366 | + $tax = $this->get_total_tax(); |
|
1367 | 1367 | |
1368 | 1368 | if ( $currency ) { |
1369 | - return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
1369 | + return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
1370 | 1370 | } |
1371 | 1371 | |
1372 | 1372 | return $tax; |
1373 | 1373 | } |
1374 | 1374 | |
1375 | 1375 | /** |
1376 | - * Get the invoice fees total. |
|
1377 | - * |
|
1378 | - * @since 1.0.19 |
|
1379 | - * @param string $context View or edit context. |
|
1380 | - * @return float |
|
1381 | - */ |
|
1382 | - public function get_total_fees( $context = 'view' ) { |
|
1383 | - return (float) $this->get_prop( 'total_fees', $context ); |
|
1376 | + * Get the invoice fees total. |
|
1377 | + * |
|
1378 | + * @since 1.0.19 |
|
1379 | + * @param string $context View or edit context. |
|
1380 | + * @return float |
|
1381 | + */ |
|
1382 | + public function get_total_fees( $context = 'view' ) { |
|
1383 | + return (float) $this->get_prop( 'total_fees', $context ); |
|
1384 | 1384 | } |
1385 | 1385 | |
1386 | 1386 | /** |
1387 | - * Alias for self::get_total_fees(). |
|
1388 | - * |
|
1389 | - * @since 1.0.19 |
|
1390 | - * @param string $context View or edit context. |
|
1391 | - * @return float |
|
1392 | - */ |
|
1393 | - public function get_fees_total( $context = 'view' ) { |
|
1394 | - return $this->get_total_fees( $context ); |
|
1387 | + * Alias for self::get_total_fees(). |
|
1388 | + * |
|
1389 | + * @since 1.0.19 |
|
1390 | + * @param string $context View or edit context. |
|
1391 | + * @return float |
|
1392 | + */ |
|
1393 | + public function get_fees_total( $context = 'view' ) { |
|
1394 | + return $this->get_total_fees( $context ); |
|
1395 | 1395 | } |
1396 | 1396 | |
1397 | 1397 | /** |
1398 | - * Get the invoice total. |
|
1399 | - * |
|
1400 | - * @since 1.0.19 |
|
1398 | + * Get the invoice total. |
|
1399 | + * |
|
1400 | + * @since 1.0.19 |
|
1401 | 1401 | * @return float |
1402 | - */ |
|
1403 | - public function get_total() { |
|
1404 | - $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
1405 | - return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1406 | - } |
|
1402 | + */ |
|
1403 | + public function get_total() { |
|
1404 | + $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
1405 | + return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1406 | + } |
|
1407 | 1407 | |
1408 | - /** |
|
1409 | - * Get the invoice totals. |
|
1410 | - * |
|
1411 | - * @since 1.0.19 |
|
1408 | + /** |
|
1409 | + * Get the invoice totals. |
|
1410 | + * |
|
1411 | + * @since 1.0.19 |
|
1412 | 1412 | * @return float |
1413 | - */ |
|
1414 | - public function get_totals() { |
|
1415 | - return $this->totals; |
|
1413 | + */ |
|
1414 | + public function get_totals() { |
|
1415 | + return $this->totals; |
|
1416 | 1416 | } |
1417 | 1417 | |
1418 | 1418 | /** |
1419 | - * Get the initial invoice total. |
|
1420 | - * |
|
1421 | - * @since 1.0.19 |
|
1419 | + * Get the initial invoice total. |
|
1420 | + * |
|
1421 | + * @since 1.0.19 |
|
1422 | 1422 | * @param string $context View or edit context. |
1423 | 1423 | * @return float |
1424 | - */ |
|
1424 | + */ |
|
1425 | 1425 | public function get_initial_total() { |
1426 | 1426 | |
1427 | - if ( empty( $this->totals ) ) { |
|
1428 | - $this->recalculate_total(); |
|
1429 | - } |
|
1427 | + if ( empty( $this->totals ) ) { |
|
1428 | + $this->recalculate_total(); |
|
1429 | + } |
|
1430 | 1430 | |
1431 | - $tax = $this->totals['tax']['initial']; |
|
1432 | - $fee = $this->totals['fee']['initial']; |
|
1433 | - $discount = $this->totals['discount']['initial']; |
|
1434 | - $subtotal = $this->totals['subtotal']['initial']; |
|
1435 | - $total = $tax + $fee - $discount + $subtotal; |
|
1431 | + $tax = $this->totals['tax']['initial']; |
|
1432 | + $fee = $this->totals['fee']['initial']; |
|
1433 | + $discount = $this->totals['discount']['initial']; |
|
1434 | + $subtotal = $this->totals['subtotal']['initial']; |
|
1435 | + $total = $tax + $fee - $discount + $subtotal; |
|
1436 | 1436 | |
1437 | - if ( 0 > $total ) { |
|
1438 | - $total = 0; |
|
1439 | - } |
|
1437 | + if ( 0 > $total ) { |
|
1438 | + $total = 0; |
|
1439 | + } |
|
1440 | 1440 | |
1441 | 1441 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
1442 | - } |
|
1442 | + } |
|
1443 | 1443 | |
1444 | - /** |
|
1445 | - * Get the recurring invoice total. |
|
1446 | - * |
|
1447 | - * @since 1.0.19 |
|
1444 | + /** |
|
1445 | + * Get the recurring invoice total. |
|
1446 | + * |
|
1447 | + * @since 1.0.19 |
|
1448 | 1448 | * @param string $context View or edit context. |
1449 | 1449 | * @return float |
1450 | - */ |
|
1450 | + */ |
|
1451 | 1451 | public function get_recurring_total() { |
1452 | 1452 | |
1453 | - if ( empty( $this->totals ) ) { |
|
1454 | - $this->recalculate_total(); |
|
1455 | - } |
|
1453 | + if ( empty( $this->totals ) ) { |
|
1454 | + $this->recalculate_total(); |
|
1455 | + } |
|
1456 | 1456 | |
1457 | - $tax = $this->totals['tax']['recurring']; |
|
1458 | - $fee = $this->totals['fee']['recurring']; |
|
1459 | - $discount = $this->totals['discount']['recurring']; |
|
1460 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
1461 | - $total = $tax + $fee - $discount + $subtotal; |
|
1457 | + $tax = $this->totals['tax']['recurring']; |
|
1458 | + $fee = $this->totals['fee']['recurring']; |
|
1459 | + $discount = $this->totals['discount']['recurring']; |
|
1460 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
1461 | + $total = $tax + $fee - $discount + $subtotal; |
|
1462 | 1462 | |
1463 | - if ( 0 > $total ) { |
|
1464 | - $total = 0; |
|
1465 | - } |
|
1463 | + if ( 0 > $total ) { |
|
1464 | + $total = 0; |
|
1465 | + } |
|
1466 | 1466 | |
1467 | 1467 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
1468 | - } |
|
1468 | + } |
|
1469 | 1469 | |
1470 | - /** |
|
1471 | - * Returns recurring payment details. |
|
1472 | - * |
|
1473 | - * @since 1.0.19 |
|
1470 | + /** |
|
1471 | + * Returns recurring payment details. |
|
1472 | + * |
|
1473 | + * @since 1.0.19 |
|
1474 | 1474 | * @param string $field Optionally provide a field to return. |
1475 | - * @param string $currency Whether to include the currency. |
|
1475 | + * @param string $currency Whether to include the currency. |
|
1476 | 1476 | * @return float |
1477 | - */ |
|
1477 | + */ |
|
1478 | 1478 | public function get_recurring_details( $field = '', $currency = false ) { |
1479 | 1479 | |
1480 | - // Maybe recalculate totals. |
|
1481 | - if ( empty( $this->totals ) ) { |
|
1482 | - $this->recalculate_total(); |
|
1483 | - } |
|
1480 | + // Maybe recalculate totals. |
|
1481 | + if ( empty( $this->totals ) ) { |
|
1482 | + $this->recalculate_total(); |
|
1483 | + } |
|
1484 | 1484 | |
1485 | - // Prepare recurring totals. |
|
1485 | + // Prepare recurring totals. |
|
1486 | 1486 | $data = apply_filters( |
1487 | - 'wpinv_get_invoice_recurring_details', |
|
1488 | - array( |
|
1489 | - 'cart_details' => $this->get_cart_details(), |
|
1490 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1491 | - 'discount' => $this->totals['discount']['recurring'], |
|
1492 | - 'tax' => $this->totals['tax']['recurring'], |
|
1493 | - 'fee' => $this->totals['fee']['recurring'], |
|
1494 | - 'total' => $this->get_recurring_total(), |
|
1495 | - ), |
|
1496 | - $this, |
|
1497 | - $field, |
|
1498 | - $currency |
|
1499 | - ); |
|
1487 | + 'wpinv_get_invoice_recurring_details', |
|
1488 | + array( |
|
1489 | + 'cart_details' => $this->get_cart_details(), |
|
1490 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1491 | + 'discount' => $this->totals['discount']['recurring'], |
|
1492 | + 'tax' => $this->totals['tax']['recurring'], |
|
1493 | + 'fee' => $this->totals['fee']['recurring'], |
|
1494 | + 'total' => $this->get_recurring_total(), |
|
1495 | + ), |
|
1496 | + $this, |
|
1497 | + $field, |
|
1498 | + $currency |
|
1499 | + ); |
|
1500 | 1500 | |
1501 | 1501 | if ( isset( $data[$field] ) ) { |
1502 | 1502 | return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
@@ -1506,156 +1506,156 @@ discard block |
||
1506 | 1506 | } |
1507 | 1507 | |
1508 | 1508 | /** |
1509 | - * Get the invoice fees. |
|
1510 | - * |
|
1511 | - * @since 1.0.19 |
|
1512 | - * @param string $context View or edit context. |
|
1513 | - * @return array |
|
1514 | - */ |
|
1515 | - public function get_fees( $context = 'view' ) { |
|
1516 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1509 | + * Get the invoice fees. |
|
1510 | + * |
|
1511 | + * @since 1.0.19 |
|
1512 | + * @param string $context View or edit context. |
|
1513 | + * @return array |
|
1514 | + */ |
|
1515 | + public function get_fees( $context = 'view' ) { |
|
1516 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1517 | 1517 | } |
1518 | 1518 | |
1519 | 1519 | /** |
1520 | - * Get the invoice discounts. |
|
1521 | - * |
|
1522 | - * @since 1.0.19 |
|
1523 | - * @param string $context View or edit context. |
|
1524 | - * @return array |
|
1525 | - */ |
|
1526 | - public function get_discounts( $context = 'view' ) { |
|
1527 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1520 | + * Get the invoice discounts. |
|
1521 | + * |
|
1522 | + * @since 1.0.19 |
|
1523 | + * @param string $context View or edit context. |
|
1524 | + * @return array |
|
1525 | + */ |
|
1526 | + public function get_discounts( $context = 'view' ) { |
|
1527 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | /** |
1531 | - * Get the invoice taxes. |
|
1532 | - * |
|
1533 | - * @since 1.0.19 |
|
1534 | - * @param string $context View or edit context. |
|
1535 | - * @return array |
|
1536 | - */ |
|
1537 | - public function get_taxes( $context = 'view' ) { |
|
1538 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1531 | + * Get the invoice taxes. |
|
1532 | + * |
|
1533 | + * @since 1.0.19 |
|
1534 | + * @param string $context View or edit context. |
|
1535 | + * @return array |
|
1536 | + */ |
|
1537 | + public function get_taxes( $context = 'view' ) { |
|
1538 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1539 | 1539 | } |
1540 | 1540 | |
1541 | 1541 | /** |
1542 | - * Get the invoice items. |
|
1543 | - * |
|
1544 | - * @since 1.0.19 |
|
1545 | - * @param string $context View or edit context. |
|
1546 | - * @return GetPaid_Form_Item[] |
|
1547 | - */ |
|
1548 | - public function get_items( $context = 'view' ) { |
|
1542 | + * Get the invoice items. |
|
1543 | + * |
|
1544 | + * @since 1.0.19 |
|
1545 | + * @param string $context View or edit context. |
|
1546 | + * @return GetPaid_Form_Item[] |
|
1547 | + */ |
|
1548 | + public function get_items( $context = 'view' ) { |
|
1549 | 1549 | return $this->get_prop( 'items', $context ); |
1550 | 1550 | } |
1551 | 1551 | |
1552 | 1552 | /** |
1553 | - * Get the invoice's payment form. |
|
1554 | - * |
|
1555 | - * @since 1.0.19 |
|
1556 | - * @param string $context View or edit context. |
|
1557 | - * @return int |
|
1558 | - */ |
|
1559 | - public function get_payment_form( $context = 'view' ) { |
|
1560 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1553 | + * Get the invoice's payment form. |
|
1554 | + * |
|
1555 | + * @since 1.0.19 |
|
1556 | + * @param string $context View or edit context. |
|
1557 | + * @return int |
|
1558 | + */ |
|
1559 | + public function get_payment_form( $context = 'view' ) { |
|
1560 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1561 | 1561 | } |
1562 | 1562 | |
1563 | 1563 | /** |
1564 | - * Get the invoice's submission id. |
|
1565 | - * |
|
1566 | - * @since 1.0.19 |
|
1567 | - * @param string $context View or edit context. |
|
1568 | - * @return string |
|
1569 | - */ |
|
1570 | - public function get_submission_id( $context = 'view' ) { |
|
1571 | - return $this->get_prop( 'submission_id', $context ); |
|
1564 | + * Get the invoice's submission id. |
|
1565 | + * |
|
1566 | + * @since 1.0.19 |
|
1567 | + * @param string $context View or edit context. |
|
1568 | + * @return string |
|
1569 | + */ |
|
1570 | + public function get_submission_id( $context = 'view' ) { |
|
1571 | + return $this->get_prop( 'submission_id', $context ); |
|
1572 | 1572 | } |
1573 | 1573 | |
1574 | 1574 | /** |
1575 | - * Get the invoice's discount code. |
|
1576 | - * |
|
1577 | - * @since 1.0.19 |
|
1578 | - * @param string $context View or edit context. |
|
1579 | - * @return string |
|
1580 | - */ |
|
1581 | - public function get_discount_code( $context = 'view' ) { |
|
1582 | - return $this->get_prop( 'discount_code', $context ); |
|
1575 | + * Get the invoice's discount code. |
|
1576 | + * |
|
1577 | + * @since 1.0.19 |
|
1578 | + * @param string $context View or edit context. |
|
1579 | + * @return string |
|
1580 | + */ |
|
1581 | + public function get_discount_code( $context = 'view' ) { |
|
1582 | + return $this->get_prop( 'discount_code', $context ); |
|
1583 | 1583 | } |
1584 | 1584 | |
1585 | 1585 | /** |
1586 | - * Get the invoice's gateway. |
|
1587 | - * |
|
1588 | - * @since 1.0.19 |
|
1589 | - * @param string $context View or edit context. |
|
1590 | - * @return string |
|
1591 | - */ |
|
1592 | - public function get_gateway( $context = 'view' ) { |
|
1593 | - return $this->get_prop( 'gateway', $context ); |
|
1586 | + * Get the invoice's gateway. |
|
1587 | + * |
|
1588 | + * @since 1.0.19 |
|
1589 | + * @param string $context View or edit context. |
|
1590 | + * @return string |
|
1591 | + */ |
|
1592 | + public function get_gateway( $context = 'view' ) { |
|
1593 | + return $this->get_prop( 'gateway', $context ); |
|
1594 | 1594 | } |
1595 | 1595 | |
1596 | 1596 | /** |
1597 | - * Get the invoice's gateway display title. |
|
1598 | - * |
|
1599 | - * @since 1.0.19 |
|
1600 | - * @return string |
|
1601 | - */ |
|
1597 | + * Get the invoice's gateway display title. |
|
1598 | + * |
|
1599 | + * @since 1.0.19 |
|
1600 | + * @return string |
|
1601 | + */ |
|
1602 | 1602 | public function get_gateway_title() { |
1603 | 1603 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
1604 | 1604 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
1605 | 1605 | } |
1606 | 1606 | |
1607 | 1607 | /** |
1608 | - * Get the invoice's transaction id. |
|
1609 | - * |
|
1610 | - * @since 1.0.19 |
|
1611 | - * @param string $context View or edit context. |
|
1612 | - * @return string |
|
1613 | - */ |
|
1614 | - public function get_transaction_id( $context = 'view' ) { |
|
1615 | - return $this->get_prop( 'transaction_id', $context ); |
|
1608 | + * Get the invoice's transaction id. |
|
1609 | + * |
|
1610 | + * @since 1.0.19 |
|
1611 | + * @param string $context View or edit context. |
|
1612 | + * @return string |
|
1613 | + */ |
|
1614 | + public function get_transaction_id( $context = 'view' ) { |
|
1615 | + return $this->get_prop( 'transaction_id', $context ); |
|
1616 | 1616 | } |
1617 | 1617 | |
1618 | 1618 | /** |
1619 | - * Get the invoice's currency. |
|
1620 | - * |
|
1621 | - * @since 1.0.19 |
|
1622 | - * @param string $context View or edit context. |
|
1623 | - * @return string |
|
1624 | - */ |
|
1625 | - public function get_currency( $context = 'view' ) { |
|
1619 | + * Get the invoice's currency. |
|
1620 | + * |
|
1621 | + * @since 1.0.19 |
|
1622 | + * @param string $context View or edit context. |
|
1623 | + * @return string |
|
1624 | + */ |
|
1625 | + public function get_currency( $context = 'view' ) { |
|
1626 | 1626 | $currency = $this->get_prop( 'currency', $context ); |
1627 | 1627 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
1628 | 1628 | } |
1629 | 1629 | |
1630 | 1630 | /** |
1631 | - * Checks if we are charging taxes for this invoice. |
|
1632 | - * |
|
1633 | - * @since 1.0.19 |
|
1634 | - * @param string $context View or edit context. |
|
1635 | - * @return bool |
|
1636 | - */ |
|
1637 | - public function get_disable_taxes( $context = 'view' ) { |
|
1631 | + * Checks if we are charging taxes for this invoice. |
|
1632 | + * |
|
1633 | + * @since 1.0.19 |
|
1634 | + * @param string $context View or edit context. |
|
1635 | + * @return bool |
|
1636 | + */ |
|
1637 | + public function get_disable_taxes( $context = 'view' ) { |
|
1638 | 1638 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
1639 | 1639 | } |
1640 | 1640 | |
1641 | 1641 | /** |
1642 | - * Retrieves the subscription id for an invoice. |
|
1643 | - * |
|
1644 | - * @since 1.0.19 |
|
1645 | - * @param string $context View or edit context. |
|
1646 | - * @return int |
|
1647 | - */ |
|
1642 | + * Retrieves the subscription id for an invoice. |
|
1643 | + * |
|
1644 | + * @since 1.0.19 |
|
1645 | + * @param string $context View or edit context. |
|
1646 | + * @return int |
|
1647 | + */ |
|
1648 | 1648 | public function get_subscription_id( $context = 'view' ) { |
1649 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1650 | - } |
|
1651 | - |
|
1652 | - /** |
|
1653 | - * Retrieves the remote subscription id for an invoice. |
|
1654 | - * |
|
1655 | - * @since 1.0.19 |
|
1656 | - * @param string $context View or edit context. |
|
1657 | - * @return int |
|
1658 | - */ |
|
1649 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1650 | + } |
|
1651 | + |
|
1652 | + /** |
|
1653 | + * Retrieves the remote subscription id for an invoice. |
|
1654 | + * |
|
1655 | + * @since 1.0.19 |
|
1656 | + * @param string $context View or edit context. |
|
1657 | + * @return int |
|
1658 | + */ |
|
1659 | 1659 | public function get_remote_subscription_id( $context = 'view' ) { |
1660 | 1660 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
1661 | 1661 | |
@@ -1668,12 +1668,12 @@ discard block |
||
1668 | 1668 | } |
1669 | 1669 | |
1670 | 1670 | /** |
1671 | - * Retrieves the payment meta for an invoice. |
|
1672 | - * |
|
1673 | - * @since 1.0.19 |
|
1674 | - * @param string $context View or edit context. |
|
1675 | - * @return array |
|
1676 | - */ |
|
1671 | + * Retrieves the payment meta for an invoice. |
|
1672 | + * |
|
1673 | + * @since 1.0.19 |
|
1674 | + * @param string $context View or edit context. |
|
1675 | + * @return array |
|
1676 | + */ |
|
1677 | 1677 | public function get_payment_meta( $context = 'view' ) { |
1678 | 1678 | |
1679 | 1679 | return array( |
@@ -1693,31 +1693,31 @@ discard block |
||
1693 | 1693 | } |
1694 | 1694 | |
1695 | 1695 | /** |
1696 | - * Retrieves the cart details for an invoice. |
|
1697 | - * |
|
1698 | - * @since 1.0.19 |
|
1699 | - * @return array |
|
1700 | - */ |
|
1696 | + * Retrieves the cart details for an invoice. |
|
1697 | + * |
|
1698 | + * @since 1.0.19 |
|
1699 | + * @return array |
|
1700 | + */ |
|
1701 | 1701 | public function get_cart_details() { |
1702 | 1702 | $items = $this->get_items(); |
1703 | 1703 | $cart_details = array(); |
1704 | 1704 | |
1705 | 1705 | foreach ( $items as $item_id => $item ) { |
1706 | - $item->invoice_id = $this->get_id(); |
|
1706 | + $item->invoice_id = $this->get_id(); |
|
1707 | 1707 | $cart_details[] = $item->prepare_data_for_saving(); |
1708 | 1708 | } |
1709 | 1709 | |
1710 | 1710 | return $cart_details; |
1711 | - } |
|
1711 | + } |
|
1712 | 1712 | |
1713 | - /** |
|
1714 | - * Retrieves the recurring item. |
|
1715 | - * |
|
1716 | - * @return null|GetPaid_Form_Item|int |
|
1717 | - */ |
|
1718 | - public function get_recurring( $object = false ) { |
|
1713 | + /** |
|
1714 | + * Retrieves the recurring item. |
|
1715 | + * |
|
1716 | + * @return null|GetPaid_Form_Item|int |
|
1717 | + */ |
|
1718 | + public function get_recurring( $object = false ) { |
|
1719 | 1719 | |
1720 | - // Are we returning an object? |
|
1720 | + // Are we returning an object? |
|
1721 | 1721 | if ( $object ) { |
1722 | 1722 | return $this->get_item( $this->recurring_item ); |
1723 | 1723 | } |
@@ -1725,114 +1725,114 @@ discard block |
||
1725 | 1725 | return $this->recurring_item; |
1726 | 1726 | } |
1727 | 1727 | |
1728 | - /** |
|
1729 | - * Retrieves the subscription name. |
|
1730 | - * |
|
1731 | - * @since 1.0.19 |
|
1732 | - * @return string |
|
1733 | - */ |
|
1734 | - public function get_subscription_name() { |
|
1728 | + /** |
|
1729 | + * Retrieves the subscription name. |
|
1730 | + * |
|
1731 | + * @since 1.0.19 |
|
1732 | + * @return string |
|
1733 | + */ |
|
1734 | + public function get_subscription_name() { |
|
1735 | 1735 | |
1736 | - // Retrieve the recurring name |
|
1736 | + // Retrieve the recurring name |
|
1737 | 1737 | $item = $this->get_recurring( true ); |
1738 | 1738 | |
1739 | - // Abort if it does not exist. |
|
1739 | + // Abort if it does not exist. |
|
1740 | 1740 | if ( empty( $item ) ) { |
1741 | 1741 | return ''; |
1742 | 1742 | } |
1743 | 1743 | |
1744 | - // Return the item name. |
|
1744 | + // Return the item name. |
|
1745 | 1745 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
1746 | - } |
|
1747 | - |
|
1748 | - /** |
|
1749 | - * Retrieves the view url. |
|
1750 | - * |
|
1751 | - * @since 1.0.19 |
|
1752 | - * @return string |
|
1753 | - */ |
|
1754 | - public function get_view_url() { |
|
1746 | + } |
|
1747 | + |
|
1748 | + /** |
|
1749 | + * Retrieves the view url. |
|
1750 | + * |
|
1751 | + * @since 1.0.19 |
|
1752 | + * @return string |
|
1753 | + */ |
|
1754 | + public function get_view_url() { |
|
1755 | 1755 | $invoice_url = get_permalink( $this->get_id() ); |
1756 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1756 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1757 | 1757 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
1758 | - } |
|
1758 | + } |
|
1759 | 1759 | |
1760 | - /** |
|
1761 | - * Retrieves the payment url. |
|
1762 | - * |
|
1763 | - * @since 1.0.19 |
|
1764 | - * @return string |
|
1765 | - */ |
|
1766 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1760 | + /** |
|
1761 | + * Retrieves the payment url. |
|
1762 | + * |
|
1763 | + * @since 1.0.19 |
|
1764 | + * @return string |
|
1765 | + */ |
|
1766 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1767 | 1767 | |
1768 | - // Retrieve the checkout url. |
|
1768 | + // Retrieve the checkout url. |
|
1769 | 1769 | $pay_url = wpinv_get_checkout_uri(); |
1770 | 1770 | |
1771 | - // Maybe force ssl. |
|
1771 | + // Maybe force ssl. |
|
1772 | 1772 | if ( is_ssl() ) { |
1773 | 1773 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
1774 | 1774 | } |
1775 | 1775 | |
1776 | - // Add the invoice key. |
|
1777 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1776 | + // Add the invoice key. |
|
1777 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1778 | 1778 | |
1779 | - // (Maybe?) add a secret |
|
1779 | + // (Maybe?) add a secret |
|
1780 | 1780 | if ( $secret ) { |
1781 | 1781 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
1782 | 1782 | } |
1783 | 1783 | |
1784 | 1784 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
1785 | - } |
|
1785 | + } |
|
1786 | 1786 | |
1787 | - /** |
|
1788 | - * Retrieves the receipt url. |
|
1789 | - * |
|
1790 | - * @since 1.0.19 |
|
1791 | - * @return string |
|
1792 | - */ |
|
1793 | - public function get_receipt_url() { |
|
1794 | - |
|
1795 | - // Retrieve the checkout url. |
|
1787 | + /** |
|
1788 | + * Retrieves the receipt url. |
|
1789 | + * |
|
1790 | + * @since 1.0.19 |
|
1791 | + * @return string |
|
1792 | + */ |
|
1793 | + public function get_receipt_url() { |
|
1794 | + |
|
1795 | + // Retrieve the checkout url. |
|
1796 | 1796 | $receipt_url = wpinv_get_success_page_uri(); |
1797 | 1797 | |
1798 | - // Maybe force ssl. |
|
1798 | + // Maybe force ssl. |
|
1799 | 1799 | if ( is_ssl() ) { |
1800 | 1800 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
1801 | 1801 | } |
1802 | 1802 | |
1803 | - // Add the invoice key. |
|
1804 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1803 | + // Add the invoice key. |
|
1804 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1805 | 1805 | |
1806 | 1806 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
1807 | - } |
|
1807 | + } |
|
1808 | 1808 | |
1809 | - /** |
|
1810 | - * Retrieves the default status. |
|
1811 | - * |
|
1812 | - * @since 1.0.19 |
|
1813 | - * @return string |
|
1814 | - */ |
|
1815 | - public function get_default_status() { |
|
1816 | - |
|
1817 | - $type = $this->get_type(); |
|
1818 | - $status = "wpi-$type-pending"; |
|
1819 | - return str_replace( '-invoice', '', $status ); |
|
1820 | - |
|
1821 | - } |
|
1822 | - |
|
1823 | - /** |
|
1824 | - * Magic method for accessing invoice properties. |
|
1825 | - * |
|
1826 | - * @since 1.0.15 |
|
1827 | - * @access public |
|
1828 | - * |
|
1829 | - * @param string $key Discount data to retrieve |
|
1830 | - * @param string $context View or edit context. |
|
1831 | - * @return mixed Value of the given invoice property (if set). |
|
1832 | - */ |
|
1833 | - public function get( $key, $context = 'view' ) { |
|
1809 | + /** |
|
1810 | + * Retrieves the default status. |
|
1811 | + * |
|
1812 | + * @since 1.0.19 |
|
1813 | + * @return string |
|
1814 | + */ |
|
1815 | + public function get_default_status() { |
|
1816 | + |
|
1817 | + $type = $this->get_type(); |
|
1818 | + $status = "wpi-$type-pending"; |
|
1819 | + return str_replace( '-invoice', '', $status ); |
|
1820 | + |
|
1821 | + } |
|
1822 | + |
|
1823 | + /** |
|
1824 | + * Magic method for accessing invoice properties. |
|
1825 | + * |
|
1826 | + * @since 1.0.15 |
|
1827 | + * @access public |
|
1828 | + * |
|
1829 | + * @param string $key Discount data to retrieve |
|
1830 | + * @param string $context View or edit context. |
|
1831 | + * @return mixed Value of the given invoice property (if set). |
|
1832 | + */ |
|
1833 | + public function get( $key, $context = 'view' ) { |
|
1834 | 1834 | return $this->get_prop( $key, $context ); |
1835 | - } |
|
1835 | + } |
|
1836 | 1836 | |
1837 | 1837 | /* |
1838 | 1838 | |-------------------------------------------------------------------------- |
@@ -1845,130 +1845,130 @@ discard block |
||
1845 | 1845 | */ |
1846 | 1846 | |
1847 | 1847 | /** |
1848 | - * Magic method for setting invoice properties. |
|
1849 | - * |
|
1850 | - * @since 1.0.19 |
|
1851 | - * @access public |
|
1852 | - * |
|
1853 | - * @param string $key Discount data to retrieve |
|
1854 | - * @param mixed $value new value. |
|
1855 | - * @return mixed Value of the given invoice property (if set). |
|
1856 | - */ |
|
1857 | - public function set( $key, $value ) { |
|
1848 | + * Magic method for setting invoice properties. |
|
1849 | + * |
|
1850 | + * @since 1.0.19 |
|
1851 | + * @access public |
|
1852 | + * |
|
1853 | + * @param string $key Discount data to retrieve |
|
1854 | + * @param mixed $value new value. |
|
1855 | + * @return mixed Value of the given invoice property (if set). |
|
1856 | + */ |
|
1857 | + public function set( $key, $value ) { |
|
1858 | 1858 | |
1859 | 1859 | $setter = "set_$key"; |
1860 | 1860 | if ( is_callable( array( $this, $setter ) ) ) { |
1861 | 1861 | $this->{$setter}( $value ); |
1862 | 1862 | } |
1863 | 1863 | |
1864 | - } |
|
1864 | + } |
|
1865 | 1865 | |
1866 | - /** |
|
1867 | - * Sets item status. |
|
1868 | - * |
|
1869 | - * @since 1.0.19 |
|
1870 | - * @param string $new_status New status. |
|
1871 | - * @param string $note Optional note to add. |
|
1872 | - * @param bool $manual_update Is this a manual status change?. |
|
1873 | - * @return array details of change. |
|
1874 | - */ |
|
1875 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
1876 | - $old_status = $this->get_status(); |
|
1866 | + /** |
|
1867 | + * Sets item status. |
|
1868 | + * |
|
1869 | + * @since 1.0.19 |
|
1870 | + * @param string $new_status New status. |
|
1871 | + * @param string $note Optional note to add. |
|
1872 | + * @param bool $manual_update Is this a manual status change?. |
|
1873 | + * @return array details of change. |
|
1874 | + */ |
|
1875 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
1876 | + $old_status = $this->get_status(); |
|
1877 | 1877 | |
1878 | - $statuses = $this->get_all_statuses(); |
|
1878 | + $statuses = $this->get_all_statuses(); |
|
1879 | 1879 | |
1880 | - if ( isset( $statuses[ 'draft' ] ) ) { |
|
1881 | - unset( $statuses[ 'draft' ] ); |
|
1882 | - } |
|
1880 | + if ( isset( $statuses[ 'draft' ] ) ) { |
|
1881 | + unset( $statuses[ 'draft' ] ); |
|
1882 | + } |
|
1883 | 1883 | |
1884 | - $this->set_prop( 'status', $new_status ); |
|
1884 | + $this->set_prop( 'status', $new_status ); |
|
1885 | 1885 | |
1886 | - // If setting the status, ensure it's set to a valid status. |
|
1887 | - if ( true === $this->object_read ) { |
|
1886 | + // If setting the status, ensure it's set to a valid status. |
|
1887 | + if ( true === $this->object_read ) { |
|
1888 | 1888 | |
1889 | - // Only allow valid new status. |
|
1890 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
1891 | - $new_status = $this->get_default_status(); |
|
1892 | - } |
|
1889 | + // Only allow valid new status. |
|
1890 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
1891 | + $new_status = $this->get_default_status(); |
|
1892 | + } |
|
1893 | 1893 | |
1894 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
1895 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
1896 | - $old_status = $this->get_default_status(); |
|
1897 | - } |
|
1894 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
1895 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
1896 | + $old_status = $this->get_default_status(); |
|
1897 | + } |
|
1898 | 1898 | |
1899 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
1900 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
1901 | - $old_status = 'wpi-pending'; |
|
1902 | - } |
|
1899 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
1900 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
1901 | + $old_status = 'wpi-pending'; |
|
1902 | + } |
|
1903 | 1903 | |
1904 | - } |
|
1904 | + } |
|
1905 | 1905 | |
1906 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
1907 | - $this->status_transition = array( |
|
1908 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
1909 | - 'to' => $new_status, |
|
1910 | - 'note' => $note, |
|
1911 | - 'manual' => (bool) $manual_update, |
|
1912 | - ); |
|
1906 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
1907 | + $this->status_transition = array( |
|
1908 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
1909 | + 'to' => $new_status, |
|
1910 | + 'note' => $note, |
|
1911 | + 'manual' => (bool) $manual_update, |
|
1912 | + ); |
|
1913 | 1913 | |
1914 | - if ( $manual_update ) { |
|
1915 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
1916 | - } |
|
1914 | + if ( $manual_update ) { |
|
1915 | + do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
1916 | + } |
|
1917 | 1917 | |
1918 | - $this->maybe_set_date_paid(); |
|
1918 | + $this->maybe_set_date_paid(); |
|
1919 | 1919 | |
1920 | - } |
|
1920 | + } |
|
1921 | 1921 | |
1922 | - return array( |
|
1923 | - 'from' => $old_status, |
|
1924 | - 'to' => $new_status, |
|
1925 | - ); |
|
1926 | - } |
|
1922 | + return array( |
|
1923 | + 'from' => $old_status, |
|
1924 | + 'to' => $new_status, |
|
1925 | + ); |
|
1926 | + } |
|
1927 | 1927 | |
1928 | - /** |
|
1929 | - * Maybe set date paid. |
|
1930 | - * |
|
1931 | - * Sets the date paid variable when transitioning to the payment complete |
|
1932 | - * order status. |
|
1933 | - * |
|
1934 | - * @since 1.0.19 |
|
1935 | - */ |
|
1936 | - public function maybe_set_date_paid() { |
|
1928 | + /** |
|
1929 | + * Maybe set date paid. |
|
1930 | + * |
|
1931 | + * Sets the date paid variable when transitioning to the payment complete |
|
1932 | + * order status. |
|
1933 | + * |
|
1934 | + * @since 1.0.19 |
|
1935 | + */ |
|
1936 | + public function maybe_set_date_paid() { |
|
1937 | 1937 | |
1938 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
1939 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
1940 | - } |
|
1941 | - } |
|
1938 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
1939 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
1940 | + } |
|
1941 | + } |
|
1942 | 1942 | |
1943 | 1943 | /** |
1944 | - * Set parent invoice ID. |
|
1945 | - * |
|
1946 | - * @since 1.0.19 |
|
1947 | - */ |
|
1948 | - public function set_parent_id( $value ) { |
|
1949 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
1950 | - return; |
|
1951 | - } |
|
1952 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
1944 | + * Set parent invoice ID. |
|
1945 | + * |
|
1946 | + * @since 1.0.19 |
|
1947 | + */ |
|
1948 | + public function set_parent_id( $value ) { |
|
1949 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
1950 | + return; |
|
1951 | + } |
|
1952 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
1953 | 1953 | } |
1954 | 1954 | |
1955 | 1955 | /** |
1956 | - * Set plugin version when the invoice was created. |
|
1957 | - * |
|
1958 | - * @since 1.0.19 |
|
1959 | - */ |
|
1960 | - public function set_version( $value ) { |
|
1961 | - $this->set_prop( 'version', $value ); |
|
1956 | + * Set plugin version when the invoice was created. |
|
1957 | + * |
|
1958 | + * @since 1.0.19 |
|
1959 | + */ |
|
1960 | + public function set_version( $value ) { |
|
1961 | + $this->set_prop( 'version', $value ); |
|
1962 | 1962 | } |
1963 | - |
|
1964 | - /** |
|
1965 | - * Set date when the invoice was created. |
|
1966 | - * |
|
1967 | - * @since 1.0.19 |
|
1968 | - * @param string $value Value to set. |
|
1963 | + |
|
1964 | + /** |
|
1965 | + * Set date when the invoice was created. |
|
1966 | + * |
|
1967 | + * @since 1.0.19 |
|
1968 | + * @param string $value Value to set. |
|
1969 | 1969 | * @return bool Whether or not the date was set. |
1970 | - */ |
|
1971 | - public function set_date_created( $value ) { |
|
1970 | + */ |
|
1971 | + public function set_date_created( $value ) { |
|
1972 | 1972 | $date = strtotime( $value ); |
1973 | 1973 | |
1974 | 1974 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1981,13 +1981,13 @@ discard block |
||
1981 | 1981 | } |
1982 | 1982 | |
1983 | 1983 | /** |
1984 | - * Set date invoice due date. |
|
1985 | - * |
|
1986 | - * @since 1.0.19 |
|
1987 | - * @param string $value Value to set. |
|
1984 | + * Set date invoice due date. |
|
1985 | + * |
|
1986 | + * @since 1.0.19 |
|
1987 | + * @param string $value Value to set. |
|
1988 | 1988 | * @return bool Whether or not the date was set. |
1989 | - */ |
|
1990 | - public function set_due_date( $value ) { |
|
1989 | + */ |
|
1990 | + public function set_due_date( $value ) { |
|
1991 | 1991 | $date = strtotime( $value ); |
1992 | 1992 | |
1993 | 1993 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1995,29 +1995,29 @@ discard block |
||
1995 | 1995 | return true; |
1996 | 1996 | } |
1997 | 1997 | |
1998 | - $this->set_prop( 'due_date', '' ); |
|
1998 | + $this->set_prop( 'due_date', '' ); |
|
1999 | 1999 | return false; |
2000 | 2000 | |
2001 | 2001 | } |
2002 | 2002 | |
2003 | 2003 | /** |
2004 | - * Alias of self::set_due_date(). |
|
2005 | - * |
|
2006 | - * @since 1.0.19 |
|
2007 | - * @param string $value New name. |
|
2008 | - */ |
|
2009 | - public function set_date_due( $value ) { |
|
2010 | - $this->set_due_date( $value ); |
|
2004 | + * Alias of self::set_due_date(). |
|
2005 | + * |
|
2006 | + * @since 1.0.19 |
|
2007 | + * @param string $value New name. |
|
2008 | + */ |
|
2009 | + public function set_date_due( $value ) { |
|
2010 | + $this->set_due_date( $value ); |
|
2011 | 2011 | } |
2012 | 2012 | |
2013 | 2013 | /** |
2014 | - * Set date invoice was completed. |
|
2015 | - * |
|
2016 | - * @since 1.0.19 |
|
2017 | - * @param string $value Value to set. |
|
2014 | + * Set date invoice was completed. |
|
2015 | + * |
|
2016 | + * @since 1.0.19 |
|
2017 | + * @param string $value Value to set. |
|
2018 | 2018 | * @return bool Whether or not the date was set. |
2019 | - */ |
|
2020 | - public function set_completed_date( $value ) { |
|
2019 | + */ |
|
2020 | + public function set_completed_date( $value ) { |
|
2021 | 2021 | $date = strtotime( $value ); |
2022 | 2022 | |
2023 | 2023 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2025,29 +2025,29 @@ discard block |
||
2025 | 2025 | return true; |
2026 | 2026 | } |
2027 | 2027 | |
2028 | - $this->set_prop( 'completed_date', '' ); |
|
2028 | + $this->set_prop( 'completed_date', '' ); |
|
2029 | 2029 | return false; |
2030 | 2030 | |
2031 | 2031 | } |
2032 | 2032 | |
2033 | 2033 | /** |
2034 | - * Alias of self::set_completed_date(). |
|
2035 | - * |
|
2036 | - * @since 1.0.19 |
|
2037 | - * @param string $value New name. |
|
2038 | - */ |
|
2039 | - public function set_date_completed( $value ) { |
|
2040 | - $this->set_completed_date( $value ); |
|
2034 | + * Alias of self::set_completed_date(). |
|
2035 | + * |
|
2036 | + * @since 1.0.19 |
|
2037 | + * @param string $value New name. |
|
2038 | + */ |
|
2039 | + public function set_date_completed( $value ) { |
|
2040 | + $this->set_completed_date( $value ); |
|
2041 | 2041 | } |
2042 | 2042 | |
2043 | 2043 | /** |
2044 | - * Set date when the invoice was last modified. |
|
2045 | - * |
|
2046 | - * @since 1.0.19 |
|
2047 | - * @param string $value Value to set. |
|
2044 | + * Set date when the invoice was last modified. |
|
2045 | + * |
|
2046 | + * @since 1.0.19 |
|
2047 | + * @param string $value Value to set. |
|
2048 | 2048 | * @return bool Whether or not the date was set. |
2049 | - */ |
|
2050 | - public function set_date_modified( $value ) { |
|
2049 | + */ |
|
2050 | + public function set_date_modified( $value ) { |
|
2051 | 2051 | $date = strtotime( $value ); |
2052 | 2052 | |
2053 | 2053 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2055,763 +2055,763 @@ discard block |
||
2055 | 2055 | return true; |
2056 | 2056 | } |
2057 | 2057 | |
2058 | - $this->set_prop( 'date_modified', '' ); |
|
2058 | + $this->set_prop( 'date_modified', '' ); |
|
2059 | 2059 | return false; |
2060 | 2060 | |
2061 | 2061 | } |
2062 | 2062 | |
2063 | 2063 | /** |
2064 | - * Set the invoice number. |
|
2065 | - * |
|
2066 | - * @since 1.0.19 |
|
2067 | - * @param string $value New number. |
|
2068 | - */ |
|
2069 | - public function set_number( $value ) { |
|
2064 | + * Set the invoice number. |
|
2065 | + * |
|
2066 | + * @since 1.0.19 |
|
2067 | + * @param string $value New number. |
|
2068 | + */ |
|
2069 | + public function set_number( $value ) { |
|
2070 | 2070 | $number = sanitize_text_field( $value ); |
2071 | - $this->set_prop( 'number', $number ); |
|
2071 | + $this->set_prop( 'number', $number ); |
|
2072 | 2072 | } |
2073 | 2073 | |
2074 | 2074 | /** |
2075 | - * Set the invoice type. |
|
2076 | - * |
|
2077 | - * @since 1.0.19 |
|
2078 | - * @param string $value Type. |
|
2079 | - */ |
|
2080 | - public function set_type( $value ) { |
|
2075 | + * Set the invoice type. |
|
2076 | + * |
|
2077 | + * @since 1.0.19 |
|
2078 | + * @param string $value Type. |
|
2079 | + */ |
|
2080 | + public function set_type( $value ) { |
|
2081 | 2081 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
2082 | - $this->set_prop( 'type', $type ); |
|
2083 | - } |
|
2082 | + $this->set_prop( 'type', $type ); |
|
2083 | + } |
|
2084 | 2084 | |
2085 | 2085 | /** |
2086 | - * Set the invoice post type. |
|
2087 | - * |
|
2088 | - * @since 1.0.19 |
|
2089 | - * @param string $value Post type. |
|
2090 | - */ |
|
2091 | - public function set_post_type( $value ) { |
|
2086 | + * Set the invoice post type. |
|
2087 | + * |
|
2088 | + * @since 1.0.19 |
|
2089 | + * @param string $value Post type. |
|
2090 | + */ |
|
2091 | + public function set_post_type( $value ) { |
|
2092 | 2092 | if ( getpaid_is_invoice_post_type( $value ) ) { |
2093 | - $this->set_type( $value ); |
|
2093 | + $this->set_type( $value ); |
|
2094 | 2094 | $this->set_prop( 'post_type', $value ); |
2095 | 2095 | } |
2096 | 2096 | } |
2097 | 2097 | |
2098 | 2098 | /** |
2099 | - * Set the invoice key. |
|
2100 | - * |
|
2101 | - * @since 1.0.19 |
|
2102 | - * @param string $value New key. |
|
2103 | - */ |
|
2104 | - public function set_key( $value ) { |
|
2099 | + * Set the invoice key. |
|
2100 | + * |
|
2101 | + * @since 1.0.19 |
|
2102 | + * @param string $value New key. |
|
2103 | + */ |
|
2104 | + public function set_key( $value ) { |
|
2105 | 2105 | $key = sanitize_text_field( $value ); |
2106 | - $this->set_prop( 'key', $key ); |
|
2106 | + $this->set_prop( 'key', $key ); |
|
2107 | 2107 | } |
2108 | 2108 | |
2109 | 2109 | /** |
2110 | - * Set the invoice mode. |
|
2111 | - * |
|
2112 | - * @since 1.0.19 |
|
2113 | - * @param string $value mode. |
|
2114 | - */ |
|
2115 | - public function set_mode( $value ) { |
|
2110 | + * Set the invoice mode. |
|
2111 | + * |
|
2112 | + * @since 1.0.19 |
|
2113 | + * @param string $value mode. |
|
2114 | + */ |
|
2115 | + public function set_mode( $value ) { |
|
2116 | 2116 | if ( ! in_array( $value, array( 'live', 'test' ) ) ) { |
2117 | 2117 | $this->set_prop( 'value', $value ); |
2118 | 2118 | } |
2119 | 2119 | } |
2120 | 2120 | |
2121 | 2121 | /** |
2122 | - * Set the invoice path. |
|
2123 | - * |
|
2124 | - * @since 1.0.19 |
|
2125 | - * @param string $value path. |
|
2126 | - */ |
|
2127 | - public function set_path( $value ) { |
|
2122 | + * Set the invoice path. |
|
2123 | + * |
|
2124 | + * @since 1.0.19 |
|
2125 | + * @param string $value path. |
|
2126 | + */ |
|
2127 | + public function set_path( $value ) { |
|
2128 | 2128 | $this->set_prop( 'path', $value ); |
2129 | 2129 | } |
2130 | 2130 | |
2131 | 2131 | /** |
2132 | - * Set the invoice name. |
|
2133 | - * |
|
2134 | - * @since 1.0.19 |
|
2135 | - * @param string $value New name. |
|
2136 | - */ |
|
2137 | - public function set_name( $value ) { |
|
2132 | + * Set the invoice name. |
|
2133 | + * |
|
2134 | + * @since 1.0.19 |
|
2135 | + * @param string $value New name. |
|
2136 | + */ |
|
2137 | + public function set_name( $value ) { |
|
2138 | 2138 | $name = sanitize_text_field( $value ); |
2139 | - $this->set_prop( 'name', $name ); |
|
2139 | + $this->set_prop( 'name', $name ); |
|
2140 | 2140 | } |
2141 | 2141 | |
2142 | 2142 | /** |
2143 | - * Alias of self::set_name(). |
|
2144 | - * |
|
2145 | - * @since 1.0.19 |
|
2146 | - * @param string $value New name. |
|
2147 | - */ |
|
2148 | - public function set_title( $value ) { |
|
2149 | - $this->set_name( $value ); |
|
2143 | + * Alias of self::set_name(). |
|
2144 | + * |
|
2145 | + * @since 1.0.19 |
|
2146 | + * @param string $value New name. |
|
2147 | + */ |
|
2148 | + public function set_title( $value ) { |
|
2149 | + $this->set_name( $value ); |
|
2150 | 2150 | } |
2151 | 2151 | |
2152 | 2152 | /** |
2153 | - * Set the invoice description. |
|
2154 | - * |
|
2155 | - * @since 1.0.19 |
|
2156 | - * @param string $value New description. |
|
2157 | - */ |
|
2158 | - public function set_description( $value ) { |
|
2153 | + * Set the invoice description. |
|
2154 | + * |
|
2155 | + * @since 1.0.19 |
|
2156 | + * @param string $value New description. |
|
2157 | + */ |
|
2158 | + public function set_description( $value ) { |
|
2159 | 2159 | $description = wp_kses_post( $value ); |
2160 | - return $this->set_prop( 'description', $description ); |
|
2160 | + return $this->set_prop( 'description', $description ); |
|
2161 | + } |
|
2162 | + |
|
2163 | + /** |
|
2164 | + * Alias of self::set_description(). |
|
2165 | + * |
|
2166 | + * @since 1.0.19 |
|
2167 | + * @param string $value New description. |
|
2168 | + */ |
|
2169 | + public function set_excerpt( $value ) { |
|
2170 | + $this->set_description( $value ); |
|
2171 | + } |
|
2172 | + |
|
2173 | + /** |
|
2174 | + * Alias of self::set_description(). |
|
2175 | + * |
|
2176 | + * @since 1.0.19 |
|
2177 | + * @param string $value New description. |
|
2178 | + */ |
|
2179 | + public function set_summary( $value ) { |
|
2180 | + $this->set_description( $value ); |
|
2161 | 2181 | } |
2162 | 2182 | |
2163 | 2183 | /** |
2164 | - * Alias of self::set_description(). |
|
2165 | - * |
|
2166 | - * @since 1.0.19 |
|
2167 | - * @param string $value New description. |
|
2168 | - */ |
|
2169 | - public function set_excerpt( $value ) { |
|
2170 | - $this->set_description( $value ); |
|
2184 | + * Set the receiver of the invoice. |
|
2185 | + * |
|
2186 | + * @since 1.0.19 |
|
2187 | + * @param int $value New author. |
|
2188 | + */ |
|
2189 | + public function set_author( $value ) { |
|
2190 | + $user = get_user_by( 'id', (int) $value ); |
|
2191 | + |
|
2192 | + if ( $user && $user->ID ) { |
|
2193 | + $this->set_prop( 'author', $user->ID ); |
|
2194 | + $this->set_prop( 'email', $user->user_email ); |
|
2195 | + } |
|
2196 | + |
|
2171 | 2197 | } |
2172 | 2198 | |
2173 | 2199 | /** |
2174 | - * Alias of self::set_description(). |
|
2175 | - * |
|
2176 | - * @since 1.0.19 |
|
2177 | - * @param string $value New description. |
|
2178 | - */ |
|
2179 | - public function set_summary( $value ) { |
|
2180 | - $this->set_description( $value ); |
|
2200 | + * Alias of self::set_author(). |
|
2201 | + * |
|
2202 | + * @since 1.0.19 |
|
2203 | + * @param int $value New user id. |
|
2204 | + */ |
|
2205 | + public function set_user_id( $value ) { |
|
2206 | + $this->set_author( $value ); |
|
2181 | 2207 | } |
2182 | 2208 | |
2183 | 2209 | /** |
2184 | - * Set the receiver of the invoice. |
|
2185 | - * |
|
2186 | - * @since 1.0.19 |
|
2187 | - * @param int $value New author. |
|
2188 | - */ |
|
2189 | - public function set_author( $value ) { |
|
2190 | - $user = get_user_by( 'id', (int) $value ); |
|
2210 | + * Alias of self::set_author(). |
|
2211 | + * |
|
2212 | + * @since 1.0.19 |
|
2213 | + * @param int $value New user id. |
|
2214 | + */ |
|
2215 | + public function set_customer_id( $value ) { |
|
2216 | + $this->set_author( $value ); |
|
2217 | + } |
|
2191 | 2218 | |
2192 | - if ( $user && $user->ID ) { |
|
2193 | - $this->set_prop( 'author', $user->ID ); |
|
2194 | - $this->set_prop( 'email', $user->user_email ); |
|
2195 | - } |
|
2219 | + /** |
|
2220 | + * Set the customer's ip. |
|
2221 | + * |
|
2222 | + * @since 1.0.19 |
|
2223 | + * @param string $value ip address. |
|
2224 | + */ |
|
2225 | + public function set_ip( $value ) { |
|
2226 | + $this->set_prop( 'ip', $value ); |
|
2227 | + } |
|
2196 | 2228 | |
2229 | + /** |
|
2230 | + * Alias of self::set_ip(). |
|
2231 | + * |
|
2232 | + * @since 1.0.19 |
|
2233 | + * @param string $value ip address. |
|
2234 | + */ |
|
2235 | + public function set_user_ip( $value ) { |
|
2236 | + $this->set_ip( $value ); |
|
2197 | 2237 | } |
2198 | 2238 | |
2199 | 2239 | /** |
2200 | - * Alias of self::set_author(). |
|
2201 | - * |
|
2202 | - * @since 1.0.19 |
|
2203 | - * @param int $value New user id. |
|
2204 | - */ |
|
2205 | - public function set_user_id( $value ) { |
|
2206 | - $this->set_author( $value ); |
|
2240 | + * Set the customer's first name. |
|
2241 | + * |
|
2242 | + * @since 1.0.19 |
|
2243 | + * @param string $value first name. |
|
2244 | + */ |
|
2245 | + public function set_first_name( $value ) { |
|
2246 | + $this->set_prop( 'first_name', $value ); |
|
2207 | 2247 | } |
2208 | 2248 | |
2209 | 2249 | /** |
2210 | - * Alias of self::set_author(). |
|
2211 | - * |
|
2212 | - * @since 1.0.19 |
|
2213 | - * @param int $value New user id. |
|
2214 | - */ |
|
2215 | - public function set_customer_id( $value ) { |
|
2216 | - $this->set_author( $value ); |
|
2250 | + * Alias of self::set_first_name(). |
|
2251 | + * |
|
2252 | + * @since 1.0.19 |
|
2253 | + * @param string $value first name. |
|
2254 | + */ |
|
2255 | + public function set_user_first_name( $value ) { |
|
2256 | + $this->set_first_name( $value ); |
|
2217 | 2257 | } |
2218 | 2258 | |
2219 | 2259 | /** |
2220 | - * Set the customer's ip. |
|
2221 | - * |
|
2222 | - * @since 1.0.19 |
|
2223 | - * @param string $value ip address. |
|
2224 | - */ |
|
2225 | - public function set_ip( $value ) { |
|
2226 | - $this->set_prop( 'ip', $value ); |
|
2260 | + * Alias of self::set_first_name(). |
|
2261 | + * |
|
2262 | + * @since 1.0.19 |
|
2263 | + * @param string $value first name. |
|
2264 | + */ |
|
2265 | + public function set_customer_first_name( $value ) { |
|
2266 | + $this->set_first_name( $value ); |
|
2227 | 2267 | } |
2228 | 2268 | |
2229 | 2269 | /** |
2230 | - * Alias of self::set_ip(). |
|
2231 | - * |
|
2232 | - * @since 1.0.19 |
|
2233 | - * @param string $value ip address. |
|
2234 | - */ |
|
2235 | - public function set_user_ip( $value ) { |
|
2236 | - $this->set_ip( $value ); |
|
2270 | + * Set the customer's last name. |
|
2271 | + * |
|
2272 | + * @since 1.0.19 |
|
2273 | + * @param string $value last name. |
|
2274 | + */ |
|
2275 | + public function set_last_name( $value ) { |
|
2276 | + $this->set_prop( 'last_name', $value ); |
|
2237 | 2277 | } |
2238 | 2278 | |
2239 | 2279 | /** |
2240 | - * Set the customer's first name. |
|
2241 | - * |
|
2242 | - * @since 1.0.19 |
|
2243 | - * @param string $value first name. |
|
2244 | - */ |
|
2245 | - public function set_first_name( $value ) { |
|
2246 | - $this->set_prop( 'first_name', $value ); |
|
2280 | + * Alias of self::set_last_name(). |
|
2281 | + * |
|
2282 | + * @since 1.0.19 |
|
2283 | + * @param string $value last name. |
|
2284 | + */ |
|
2285 | + public function set_user_last_name( $value ) { |
|
2286 | + $this->set_last_name( $value ); |
|
2247 | 2287 | } |
2248 | 2288 | |
2249 | 2289 | /** |
2250 | - * Alias of self::set_first_name(). |
|
2251 | - * |
|
2252 | - * @since 1.0.19 |
|
2253 | - * @param string $value first name. |
|
2254 | - */ |
|
2255 | - public function set_user_first_name( $value ) { |
|
2256 | - $this->set_first_name( $value ); |
|
2290 | + * Alias of self::set_last_name(). |
|
2291 | + * |
|
2292 | + * @since 1.0.19 |
|
2293 | + * @param string $value last name. |
|
2294 | + */ |
|
2295 | + public function set_customer_last_name( $value ) { |
|
2296 | + $this->set_last_name( $value ); |
|
2257 | 2297 | } |
2258 | 2298 | |
2259 | 2299 | /** |
2260 | - * Alias of self::set_first_name(). |
|
2261 | - * |
|
2262 | - * @since 1.0.19 |
|
2263 | - * @param string $value first name. |
|
2264 | - */ |
|
2265 | - public function set_customer_first_name( $value ) { |
|
2266 | - $this->set_first_name( $value ); |
|
2300 | + * Set the customer's phone number. |
|
2301 | + * |
|
2302 | + * @since 1.0.19 |
|
2303 | + * @param string $value phone. |
|
2304 | + */ |
|
2305 | + public function set_phone( $value ) { |
|
2306 | + $this->set_prop( 'phone', $value ); |
|
2267 | 2307 | } |
2268 | 2308 | |
2269 | 2309 | /** |
2270 | - * Set the customer's last name. |
|
2271 | - * |
|
2272 | - * @since 1.0.19 |
|
2273 | - * @param string $value last name. |
|
2274 | - */ |
|
2275 | - public function set_last_name( $value ) { |
|
2276 | - $this->set_prop( 'last_name', $value ); |
|
2310 | + * Alias of self::set_phone(). |
|
2311 | + * |
|
2312 | + * @since 1.0.19 |
|
2313 | + * @param string $value phone. |
|
2314 | + */ |
|
2315 | + public function set_user_phone( $value ) { |
|
2316 | + $this->set_phone( $value ); |
|
2277 | 2317 | } |
2278 | 2318 | |
2279 | 2319 | /** |
2280 | - * Alias of self::set_last_name(). |
|
2281 | - * |
|
2282 | - * @since 1.0.19 |
|
2283 | - * @param string $value last name. |
|
2284 | - */ |
|
2285 | - public function set_user_last_name( $value ) { |
|
2286 | - $this->set_last_name( $value ); |
|
2320 | + * Alias of self::set_phone(). |
|
2321 | + * |
|
2322 | + * @since 1.0.19 |
|
2323 | + * @param string $value phone. |
|
2324 | + */ |
|
2325 | + public function set_customer_phone( $value ) { |
|
2326 | + $this->set_phone( $value ); |
|
2287 | 2327 | } |
2288 | 2328 | |
2289 | 2329 | /** |
2290 | - * Alias of self::set_last_name(). |
|
2291 | - * |
|
2292 | - * @since 1.0.19 |
|
2293 | - * @param string $value last name. |
|
2294 | - */ |
|
2295 | - public function set_customer_last_name( $value ) { |
|
2296 | - $this->set_last_name( $value ); |
|
2330 | + * Alias of self::set_phone(). |
|
2331 | + * |
|
2332 | + * @since 1.0.19 |
|
2333 | + * @param string $value phone. |
|
2334 | + */ |
|
2335 | + public function set_phone_number( $value ) { |
|
2336 | + $this->set_phone( $value ); |
|
2297 | 2337 | } |
2298 | 2338 | |
2299 | 2339 | /** |
2300 | - * Set the customer's phone number. |
|
2301 | - * |
|
2302 | - * @since 1.0.19 |
|
2303 | - * @param string $value phone. |
|
2304 | - */ |
|
2305 | - public function set_phone( $value ) { |
|
2306 | - $this->set_prop( 'phone', $value ); |
|
2340 | + * Set the customer's email address. |
|
2341 | + * |
|
2342 | + * @since 1.0.19 |
|
2343 | + * @param string $value email address. |
|
2344 | + */ |
|
2345 | + public function set_email( $value ) { |
|
2346 | + $this->set_prop( 'email', $value ); |
|
2307 | 2347 | } |
2308 | 2348 | |
2309 | 2349 | /** |
2310 | - * Alias of self::set_phone(). |
|
2311 | - * |
|
2312 | - * @since 1.0.19 |
|
2313 | - * @param string $value phone. |
|
2314 | - */ |
|
2315 | - public function set_user_phone( $value ) { |
|
2316 | - $this->set_phone( $value ); |
|
2350 | + * Alias of self::set_email(). |
|
2351 | + * |
|
2352 | + * @since 1.0.19 |
|
2353 | + * @param string $value email address. |
|
2354 | + */ |
|
2355 | + public function set_user_email( $value ) { |
|
2356 | + $this->set_email( $value ); |
|
2317 | 2357 | } |
2318 | 2358 | |
2319 | 2359 | /** |
2320 | - * Alias of self::set_phone(). |
|
2321 | - * |
|
2322 | - * @since 1.0.19 |
|
2323 | - * @param string $value phone. |
|
2324 | - */ |
|
2325 | - public function set_customer_phone( $value ) { |
|
2326 | - $this->set_phone( $value ); |
|
2360 | + * Alias of self::set_email(). |
|
2361 | + * |
|
2362 | + * @since 1.0.19 |
|
2363 | + * @param string $value email address. |
|
2364 | + */ |
|
2365 | + public function set_email_address( $value ) { |
|
2366 | + $this->set_email( $value ); |
|
2327 | 2367 | } |
2328 | 2368 | |
2329 | 2369 | /** |
2330 | - * Alias of self::set_phone(). |
|
2331 | - * |
|
2332 | - * @since 1.0.19 |
|
2333 | - * @param string $value phone. |
|
2334 | - */ |
|
2335 | - public function set_phone_number( $value ) { |
|
2336 | - $this->set_phone( $value ); |
|
2370 | + * Alias of self::set_email(). |
|
2371 | + * |
|
2372 | + * @since 1.0.19 |
|
2373 | + * @param string $value email address. |
|
2374 | + */ |
|
2375 | + public function set_customer_email( $value ) { |
|
2376 | + $this->set_email( $value ); |
|
2337 | 2377 | } |
2338 | 2378 | |
2339 | 2379 | /** |
2340 | - * Set the customer's email address. |
|
2341 | - * |
|
2342 | - * @since 1.0.19 |
|
2343 | - * @param string $value email address. |
|
2344 | - */ |
|
2345 | - public function set_email( $value ) { |
|
2346 | - $this->set_prop( 'email', $value ); |
|
2380 | + * Set the customer's country. |
|
2381 | + * |
|
2382 | + * @since 1.0.19 |
|
2383 | + * @param string $value country. |
|
2384 | + */ |
|
2385 | + public function set_country( $value ) { |
|
2386 | + $this->set_prop( 'country', $value ); |
|
2347 | 2387 | } |
2348 | 2388 | |
2349 | 2389 | /** |
2350 | - * Alias of self::set_email(). |
|
2351 | - * |
|
2352 | - * @since 1.0.19 |
|
2353 | - * @param string $value email address. |
|
2354 | - */ |
|
2355 | - public function set_user_email( $value ) { |
|
2356 | - $this->set_email( $value ); |
|
2390 | + * Alias of self::set_country(). |
|
2391 | + * |
|
2392 | + * @since 1.0.19 |
|
2393 | + * @param string $value country. |
|
2394 | + */ |
|
2395 | + public function set_user_country( $value ) { |
|
2396 | + $this->set_country( $value ); |
|
2357 | 2397 | } |
2358 | 2398 | |
2359 | 2399 | /** |
2360 | - * Alias of self::set_email(). |
|
2361 | - * |
|
2362 | - * @since 1.0.19 |
|
2363 | - * @param string $value email address. |
|
2364 | - */ |
|
2365 | - public function set_email_address( $value ) { |
|
2366 | - $this->set_email( $value ); |
|
2400 | + * Alias of self::set_country(). |
|
2401 | + * |
|
2402 | + * @since 1.0.19 |
|
2403 | + * @param string $value country. |
|
2404 | + */ |
|
2405 | + public function set_customer_country( $value ) { |
|
2406 | + $this->set_country( $value ); |
|
2367 | 2407 | } |
2368 | 2408 | |
2369 | 2409 | /** |
2370 | - * Alias of self::set_email(). |
|
2371 | - * |
|
2372 | - * @since 1.0.19 |
|
2373 | - * @param string $value email address. |
|
2374 | - */ |
|
2375 | - public function set_customer_email( $value ) { |
|
2376 | - $this->set_email( $value ); |
|
2410 | + * Set the customer's state. |
|
2411 | + * |
|
2412 | + * @since 1.0.19 |
|
2413 | + * @param string $value state. |
|
2414 | + */ |
|
2415 | + public function set_state( $value ) { |
|
2416 | + $this->set_prop( 'state', $value ); |
|
2377 | 2417 | } |
2378 | 2418 | |
2379 | 2419 | /** |
2380 | - * Set the customer's country. |
|
2381 | - * |
|
2382 | - * @since 1.0.19 |
|
2383 | - * @param string $value country. |
|
2384 | - */ |
|
2385 | - public function set_country( $value ) { |
|
2386 | - $this->set_prop( 'country', $value ); |
|
2420 | + * Alias of self::set_state(). |
|
2421 | + * |
|
2422 | + * @since 1.0.19 |
|
2423 | + * @param string $value state. |
|
2424 | + */ |
|
2425 | + public function set_user_state( $value ) { |
|
2426 | + $this->set_state( $value ); |
|
2387 | 2427 | } |
2388 | 2428 | |
2389 | 2429 | /** |
2390 | - * Alias of self::set_country(). |
|
2391 | - * |
|
2392 | - * @since 1.0.19 |
|
2393 | - * @param string $value country. |
|
2394 | - */ |
|
2395 | - public function set_user_country( $value ) { |
|
2396 | - $this->set_country( $value ); |
|
2430 | + * Alias of self::set_state(). |
|
2431 | + * |
|
2432 | + * @since 1.0.19 |
|
2433 | + * @param string $value state. |
|
2434 | + */ |
|
2435 | + public function set_customer_state( $value ) { |
|
2436 | + $this->set_state( $value ); |
|
2397 | 2437 | } |
2398 | 2438 | |
2399 | 2439 | /** |
2400 | - * Alias of self::set_country(). |
|
2401 | - * |
|
2402 | - * @since 1.0.19 |
|
2403 | - * @param string $value country. |
|
2404 | - */ |
|
2405 | - public function set_customer_country( $value ) { |
|
2406 | - $this->set_country( $value ); |
|
2440 | + * Set the customer's city. |
|
2441 | + * |
|
2442 | + * @since 1.0.19 |
|
2443 | + * @param string $value city. |
|
2444 | + */ |
|
2445 | + public function set_city( $value ) { |
|
2446 | + $this->set_prop( 'city', $value ); |
|
2407 | 2447 | } |
2408 | 2448 | |
2409 | 2449 | /** |
2410 | - * Set the customer's state. |
|
2411 | - * |
|
2412 | - * @since 1.0.19 |
|
2413 | - * @param string $value state. |
|
2414 | - */ |
|
2415 | - public function set_state( $value ) { |
|
2416 | - $this->set_prop( 'state', $value ); |
|
2450 | + * Alias of self::set_city(). |
|
2451 | + * |
|
2452 | + * @since 1.0.19 |
|
2453 | + * @param string $value city. |
|
2454 | + */ |
|
2455 | + public function set_user_city( $value ) { |
|
2456 | + $this->set_city( $value ); |
|
2417 | 2457 | } |
2418 | 2458 | |
2419 | 2459 | /** |
2420 | - * Alias of self::set_state(). |
|
2421 | - * |
|
2422 | - * @since 1.0.19 |
|
2423 | - * @param string $value state. |
|
2424 | - */ |
|
2425 | - public function set_user_state( $value ) { |
|
2426 | - $this->set_state( $value ); |
|
2460 | + * Alias of self::set_city(). |
|
2461 | + * |
|
2462 | + * @since 1.0.19 |
|
2463 | + * @param string $value city. |
|
2464 | + */ |
|
2465 | + public function set_customer_city( $value ) { |
|
2466 | + $this->set_city( $value ); |
|
2427 | 2467 | } |
2428 | 2468 | |
2429 | 2469 | /** |
2430 | - * Alias of self::set_state(). |
|
2431 | - * |
|
2432 | - * @since 1.0.19 |
|
2433 | - * @param string $value state. |
|
2434 | - */ |
|
2435 | - public function set_customer_state( $value ) { |
|
2436 | - $this->set_state( $value ); |
|
2470 | + * Set the customer's zip code. |
|
2471 | + * |
|
2472 | + * @since 1.0.19 |
|
2473 | + * @param string $value zip. |
|
2474 | + */ |
|
2475 | + public function set_zip( $value ) { |
|
2476 | + $this->set_prop( 'zip', $value ); |
|
2437 | 2477 | } |
2438 | 2478 | |
2439 | 2479 | /** |
2440 | - * Set the customer's city. |
|
2441 | - * |
|
2442 | - * @since 1.0.19 |
|
2443 | - * @param string $value city. |
|
2444 | - */ |
|
2445 | - public function set_city( $value ) { |
|
2446 | - $this->set_prop( 'city', $value ); |
|
2480 | + * Alias of self::set_zip(). |
|
2481 | + * |
|
2482 | + * @since 1.0.19 |
|
2483 | + * @param string $value zip. |
|
2484 | + */ |
|
2485 | + public function set_user_zip( $value ) { |
|
2486 | + $this->set_zip( $value ); |
|
2447 | 2487 | } |
2448 | 2488 | |
2449 | 2489 | /** |
2450 | - * Alias of self::set_city(). |
|
2451 | - * |
|
2452 | - * @since 1.0.19 |
|
2453 | - * @param string $value city. |
|
2454 | - */ |
|
2455 | - public function set_user_city( $value ) { |
|
2456 | - $this->set_city( $value ); |
|
2490 | + * Alias of self::set_zip(). |
|
2491 | + * |
|
2492 | + * @since 1.0.19 |
|
2493 | + * @param string $value zip. |
|
2494 | + */ |
|
2495 | + public function set_customer_zip( $value ) { |
|
2496 | + $this->set_zip( $value ); |
|
2457 | 2497 | } |
2458 | 2498 | |
2459 | 2499 | /** |
2460 | - * Alias of self::set_city(). |
|
2461 | - * |
|
2462 | - * @since 1.0.19 |
|
2463 | - * @param string $value city. |
|
2464 | - */ |
|
2465 | - public function set_customer_city( $value ) { |
|
2466 | - $this->set_city( $value ); |
|
2500 | + * Set the customer's company. |
|
2501 | + * |
|
2502 | + * @since 1.0.19 |
|
2503 | + * @param string $value company. |
|
2504 | + */ |
|
2505 | + public function set_company( $value ) { |
|
2506 | + $this->set_prop( 'company', $value ); |
|
2467 | 2507 | } |
2468 | 2508 | |
2469 | 2509 | /** |
2470 | - * Set the customer's zip code. |
|
2471 | - * |
|
2472 | - * @since 1.0.19 |
|
2473 | - * @param string $value zip. |
|
2474 | - */ |
|
2475 | - public function set_zip( $value ) { |
|
2476 | - $this->set_prop( 'zip', $value ); |
|
2510 | + * Alias of self::set_company(). |
|
2511 | + * |
|
2512 | + * @since 1.0.19 |
|
2513 | + * @param string $value company. |
|
2514 | + */ |
|
2515 | + public function set_user_company( $value ) { |
|
2516 | + $this->set_company( $value ); |
|
2477 | 2517 | } |
2478 | 2518 | |
2479 | 2519 | /** |
2480 | - * Alias of self::set_zip(). |
|
2481 | - * |
|
2482 | - * @since 1.0.19 |
|
2483 | - * @param string $value zip. |
|
2484 | - */ |
|
2485 | - public function set_user_zip( $value ) { |
|
2486 | - $this->set_zip( $value ); |
|
2520 | + * Alias of self::set_company(). |
|
2521 | + * |
|
2522 | + * @since 1.0.19 |
|
2523 | + * @param string $value company. |
|
2524 | + */ |
|
2525 | + public function set_customer_company( $value ) { |
|
2526 | + $this->set_company( $value ); |
|
2487 | 2527 | } |
2488 | 2528 | |
2489 | 2529 | /** |
2490 | - * Alias of self::set_zip(). |
|
2491 | - * |
|
2492 | - * @since 1.0.19 |
|
2493 | - * @param string $value zip. |
|
2494 | - */ |
|
2495 | - public function set_customer_zip( $value ) { |
|
2496 | - $this->set_zip( $value ); |
|
2530 | + * Set the customer's var number. |
|
2531 | + * |
|
2532 | + * @since 1.0.19 |
|
2533 | + * @param string $value var number. |
|
2534 | + */ |
|
2535 | + public function set_vat_number( $value ) { |
|
2536 | + $this->set_prop( 'vat_number', $value ); |
|
2497 | 2537 | } |
2498 | 2538 | |
2499 | 2539 | /** |
2500 | - * Set the customer's company. |
|
2501 | - * |
|
2502 | - * @since 1.0.19 |
|
2503 | - * @param string $value company. |
|
2504 | - */ |
|
2505 | - public function set_company( $value ) { |
|
2506 | - $this->set_prop( 'company', $value ); |
|
2540 | + * Alias of self::set_vat_number(). |
|
2541 | + * |
|
2542 | + * @since 1.0.19 |
|
2543 | + * @param string $value var number. |
|
2544 | + */ |
|
2545 | + public function set_user_vat_number( $value ) { |
|
2546 | + $this->set_vat_number( $value ); |
|
2507 | 2547 | } |
2508 | 2548 | |
2509 | 2549 | /** |
2510 | - * Alias of self::set_company(). |
|
2511 | - * |
|
2512 | - * @since 1.0.19 |
|
2513 | - * @param string $value company. |
|
2514 | - */ |
|
2515 | - public function set_user_company( $value ) { |
|
2516 | - $this->set_company( $value ); |
|
2550 | + * Alias of self::set_vat_number(). |
|
2551 | + * |
|
2552 | + * @since 1.0.19 |
|
2553 | + * @param string $value var number. |
|
2554 | + */ |
|
2555 | + public function set_customer_vat_number( $value ) { |
|
2556 | + $this->set_vat_number( $value ); |
|
2517 | 2557 | } |
2518 | 2558 | |
2519 | 2559 | /** |
2520 | - * Alias of self::set_company(). |
|
2521 | - * |
|
2522 | - * @since 1.0.19 |
|
2523 | - * @param string $value company. |
|
2524 | - */ |
|
2525 | - public function set_customer_company( $value ) { |
|
2526 | - $this->set_company( $value ); |
|
2560 | + * Set the customer's vat rate. |
|
2561 | + * |
|
2562 | + * @since 1.0.19 |
|
2563 | + * @param string $value var rate. |
|
2564 | + */ |
|
2565 | + public function set_vat_rate( $value ) { |
|
2566 | + $this->set_prop( 'vat_rate', $value ); |
|
2527 | 2567 | } |
2528 | 2568 | |
2529 | 2569 | /** |
2530 | - * Set the customer's var number. |
|
2531 | - * |
|
2532 | - * @since 1.0.19 |
|
2533 | - * @param string $value var number. |
|
2534 | - */ |
|
2535 | - public function set_vat_number( $value ) { |
|
2536 | - $this->set_prop( 'vat_number', $value ); |
|
2570 | + * Alias of self::set_vat_rate(). |
|
2571 | + * |
|
2572 | + * @since 1.0.19 |
|
2573 | + * @param string $value var number. |
|
2574 | + */ |
|
2575 | + public function set_user_vat_rate( $value ) { |
|
2576 | + $this->set_vat_rate( $value ); |
|
2537 | 2577 | } |
2538 | 2578 | |
2539 | 2579 | /** |
2540 | - * Alias of self::set_vat_number(). |
|
2541 | - * |
|
2542 | - * @since 1.0.19 |
|
2543 | - * @param string $value var number. |
|
2544 | - */ |
|
2545 | - public function set_user_vat_number( $value ) { |
|
2546 | - $this->set_vat_number( $value ); |
|
2580 | + * Alias of self::set_vat_rate(). |
|
2581 | + * |
|
2582 | + * @since 1.0.19 |
|
2583 | + * @param string $value var number. |
|
2584 | + */ |
|
2585 | + public function set_customer_vat_rate( $value ) { |
|
2586 | + $this->set_vat_rate( $value ); |
|
2547 | 2587 | } |
2548 | 2588 | |
2549 | 2589 | /** |
2550 | - * Alias of self::set_vat_number(). |
|
2551 | - * |
|
2552 | - * @since 1.0.19 |
|
2553 | - * @param string $value var number. |
|
2554 | - */ |
|
2555 | - public function set_customer_vat_number( $value ) { |
|
2556 | - $this->set_vat_number( $value ); |
|
2590 | + * Set the customer's address. |
|
2591 | + * |
|
2592 | + * @since 1.0.19 |
|
2593 | + * @param string $value address. |
|
2594 | + */ |
|
2595 | + public function set_address( $value ) { |
|
2596 | + $this->set_prop( 'address', $value ); |
|
2557 | 2597 | } |
2558 | 2598 | |
2559 | 2599 | /** |
2560 | - * Set the customer's vat rate. |
|
2561 | - * |
|
2562 | - * @since 1.0.19 |
|
2563 | - * @param string $value var rate. |
|
2564 | - */ |
|
2565 | - public function set_vat_rate( $value ) { |
|
2566 | - $this->set_prop( 'vat_rate', $value ); |
|
2600 | + * Alias of self::set_address(). |
|
2601 | + * |
|
2602 | + * @since 1.0.19 |
|
2603 | + * @param string $value address. |
|
2604 | + */ |
|
2605 | + public function set_user_address( $value ) { |
|
2606 | + $this->set_address( $value ); |
|
2567 | 2607 | } |
2568 | 2608 | |
2569 | 2609 | /** |
2570 | - * Alias of self::set_vat_rate(). |
|
2571 | - * |
|
2572 | - * @since 1.0.19 |
|
2573 | - * @param string $value var number. |
|
2574 | - */ |
|
2575 | - public function set_user_vat_rate( $value ) { |
|
2576 | - $this->set_vat_rate( $value ); |
|
2610 | + * Alias of self::set_address(). |
|
2611 | + * |
|
2612 | + * @since 1.0.19 |
|
2613 | + * @param string $value address. |
|
2614 | + */ |
|
2615 | + public function set_customer_address( $value ) { |
|
2616 | + $this->set_address( $value ); |
|
2577 | 2617 | } |
2578 | 2618 | |
2579 | 2619 | /** |
2580 | - * Alias of self::set_vat_rate(). |
|
2581 | - * |
|
2582 | - * @since 1.0.19 |
|
2583 | - * @param string $value var number. |
|
2584 | - */ |
|
2585 | - public function set_customer_vat_rate( $value ) { |
|
2586 | - $this->set_vat_rate( $value ); |
|
2620 | + * Set whether the customer has viewed the invoice or not. |
|
2621 | + * |
|
2622 | + * @since 1.0.19 |
|
2623 | + * @param int|bool $value confirmed. |
|
2624 | + */ |
|
2625 | + public function set_is_viewed( $value ) { |
|
2626 | + $this->set_prop( 'is_viewed', $value ); |
|
2587 | 2627 | } |
2588 | 2628 | |
2589 | 2629 | /** |
2590 | - * Set the customer's address. |
|
2591 | - * |
|
2592 | - * @since 1.0.19 |
|
2593 | - * @param string $value address. |
|
2594 | - */ |
|
2595 | - public function set_address( $value ) { |
|
2596 | - $this->set_prop( 'address', $value ); |
|
2630 | + * Set extra email recipients. |
|
2631 | + * |
|
2632 | + * @since 1.0.19 |
|
2633 | + * @param string $value email recipients. |
|
2634 | + */ |
|
2635 | + public function set_email_cc( $value ) { |
|
2636 | + $this->set_prop( 'email_cc', $value ); |
|
2597 | 2637 | } |
2598 | 2638 | |
2599 | 2639 | /** |
2600 | - * Alias of self::set_address(). |
|
2601 | - * |
|
2602 | - * @since 1.0.19 |
|
2603 | - * @param string $value address. |
|
2604 | - */ |
|
2605 | - public function set_user_address( $value ) { |
|
2606 | - $this->set_address( $value ); |
|
2640 | + * Set the invoice template. |
|
2641 | + * |
|
2642 | + * @since 1.0.19 |
|
2643 | + * @param string $value template. |
|
2644 | + */ |
|
2645 | + public function set_template( $value ) { |
|
2646 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2647 | + $this->set_prop( 'template', $value ); |
|
2648 | + } |
|
2607 | 2649 | } |
2608 | 2650 | |
2609 | 2651 | /** |
2610 | - * Alias of self::set_address(). |
|
2611 | - * |
|
2612 | - * @since 1.0.19 |
|
2613 | - * @param string $value address. |
|
2614 | - */ |
|
2615 | - public function set_customer_address( $value ) { |
|
2616 | - $this->set_address( $value ); |
|
2652 | + * Set the invoice source. |
|
2653 | + * |
|
2654 | + * @since 1.0.19 |
|
2655 | + * @param string $value email recipients. |
|
2656 | + */ |
|
2657 | + public function created_via( $value ) { |
|
2658 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2617 | 2659 | } |
2618 | 2660 | |
2619 | 2661 | /** |
2620 | - * Set whether the customer has viewed the invoice or not. |
|
2621 | - * |
|
2622 | - * @since 1.0.19 |
|
2623 | - * @param int|bool $value confirmed. |
|
2624 | - */ |
|
2625 | - public function set_is_viewed( $value ) { |
|
2626 | - $this->set_prop( 'is_viewed', $value ); |
|
2627 | - } |
|
2628 | - |
|
2629 | - /** |
|
2630 | - * Set extra email recipients. |
|
2631 | - * |
|
2632 | - * @since 1.0.19 |
|
2633 | - * @param string $value email recipients. |
|
2634 | - */ |
|
2635 | - public function set_email_cc( $value ) { |
|
2636 | - $this->set_prop( 'email_cc', $value ); |
|
2637 | - } |
|
2638 | - |
|
2639 | - /** |
|
2640 | - * Set the invoice template. |
|
2641 | - * |
|
2642 | - * @since 1.0.19 |
|
2643 | - * @param string $value template. |
|
2644 | - */ |
|
2645 | - public function set_template( $value ) { |
|
2646 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2647 | - $this->set_prop( 'template', $value ); |
|
2648 | - } |
|
2649 | - } |
|
2650 | - |
|
2651 | - /** |
|
2652 | - * Set the invoice source. |
|
2653 | - * |
|
2654 | - * @since 1.0.19 |
|
2655 | - * @param string $value email recipients. |
|
2656 | - */ |
|
2657 | - public function created_via( $value ) { |
|
2658 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2659 | - } |
|
2660 | - |
|
2661 | - /** |
|
2662 | - * Set the customer's address confirmed status. |
|
2663 | - * |
|
2664 | - * @since 1.0.19 |
|
2665 | - * @param int|bool $value confirmed. |
|
2666 | - */ |
|
2667 | - public function set_address_confirmed( $value ) { |
|
2668 | - $this->set_prop( 'address_confirmed', $value ); |
|
2662 | + * Set the customer's address confirmed status. |
|
2663 | + * |
|
2664 | + * @since 1.0.19 |
|
2665 | + * @param int|bool $value confirmed. |
|
2666 | + */ |
|
2667 | + public function set_address_confirmed( $value ) { |
|
2668 | + $this->set_prop( 'address_confirmed', $value ); |
|
2669 | 2669 | } |
2670 | 2670 | |
2671 | 2671 | /** |
2672 | - * Alias of self::set_address_confirmed(). |
|
2673 | - * |
|
2674 | - * @since 1.0.19 |
|
2675 | - * @param int|bool $value confirmed. |
|
2676 | - */ |
|
2677 | - public function set_user_address_confirmed( $value ) { |
|
2678 | - $this->set_address_confirmed( $value ); |
|
2672 | + * Alias of self::set_address_confirmed(). |
|
2673 | + * |
|
2674 | + * @since 1.0.19 |
|
2675 | + * @param int|bool $value confirmed. |
|
2676 | + */ |
|
2677 | + public function set_user_address_confirmed( $value ) { |
|
2678 | + $this->set_address_confirmed( $value ); |
|
2679 | 2679 | } |
2680 | 2680 | |
2681 | 2681 | /** |
2682 | - * Alias of self::set_address_confirmed(). |
|
2683 | - * |
|
2684 | - * @since 1.0.19 |
|
2685 | - * @param int|bool $value confirmed. |
|
2686 | - */ |
|
2687 | - public function set_customer_address_confirmed( $value ) { |
|
2688 | - $this->set_address_confirmed( $value ); |
|
2682 | + * Alias of self::set_address_confirmed(). |
|
2683 | + * |
|
2684 | + * @since 1.0.19 |
|
2685 | + * @param int|bool $value confirmed. |
|
2686 | + */ |
|
2687 | + public function set_customer_address_confirmed( $value ) { |
|
2688 | + $this->set_address_confirmed( $value ); |
|
2689 | 2689 | } |
2690 | 2690 | |
2691 | 2691 | /** |
2692 | - * Set the invoice sub total. |
|
2693 | - * |
|
2694 | - * @since 1.0.19 |
|
2695 | - * @param float $value sub total. |
|
2696 | - */ |
|
2697 | - public function set_subtotal( $value ) { |
|
2698 | - $this->set_prop( 'subtotal', $value ); |
|
2692 | + * Set the invoice sub total. |
|
2693 | + * |
|
2694 | + * @since 1.0.19 |
|
2695 | + * @param float $value sub total. |
|
2696 | + */ |
|
2697 | + public function set_subtotal( $value ) { |
|
2698 | + $this->set_prop( 'subtotal', $value ); |
|
2699 | 2699 | } |
2700 | 2700 | |
2701 | 2701 | /** |
2702 | - * Set the invoice discount amount. |
|
2703 | - * |
|
2704 | - * @since 1.0.19 |
|
2705 | - * @param float $value discount total. |
|
2706 | - */ |
|
2707 | - public function set_total_discount( $value ) { |
|
2708 | - $this->set_prop( 'total_discount', $value ); |
|
2702 | + * Set the invoice discount amount. |
|
2703 | + * |
|
2704 | + * @since 1.0.19 |
|
2705 | + * @param float $value discount total. |
|
2706 | + */ |
|
2707 | + public function set_total_discount( $value ) { |
|
2708 | + $this->set_prop( 'total_discount', $value ); |
|
2709 | 2709 | } |
2710 | 2710 | |
2711 | 2711 | /** |
2712 | - * Alias of self::set_total_discount(). |
|
2713 | - * |
|
2714 | - * @since 1.0.19 |
|
2715 | - * @param float $value discount total. |
|
2716 | - */ |
|
2717 | - public function set_discount( $value ) { |
|
2718 | - $this->set_total_discount( $value ); |
|
2712 | + * Alias of self::set_total_discount(). |
|
2713 | + * |
|
2714 | + * @since 1.0.19 |
|
2715 | + * @param float $value discount total. |
|
2716 | + */ |
|
2717 | + public function set_discount( $value ) { |
|
2718 | + $this->set_total_discount( $value ); |
|
2719 | 2719 | } |
2720 | 2720 | |
2721 | 2721 | /** |
2722 | - * Set the invoice tax amount. |
|
2723 | - * |
|
2724 | - * @since 1.0.19 |
|
2725 | - * @param float $value tax total. |
|
2726 | - */ |
|
2727 | - public function set_total_tax( $value ) { |
|
2728 | - $this->set_prop( 'total_tax', $value ); |
|
2722 | + * Set the invoice tax amount. |
|
2723 | + * |
|
2724 | + * @since 1.0.19 |
|
2725 | + * @param float $value tax total. |
|
2726 | + */ |
|
2727 | + public function set_total_tax( $value ) { |
|
2728 | + $this->set_prop( 'total_tax', $value ); |
|
2729 | 2729 | } |
2730 | 2730 | |
2731 | 2731 | /** |
2732 | - * Alias of self::set_total_tax(). |
|
2733 | - * |
|
2734 | - * @since 1.0.19 |
|
2735 | - * @param float $value tax total. |
|
2736 | - */ |
|
2737 | - public function set_tax_total( $value ) { |
|
2738 | - $this->set_total_tax( $value ); |
|
2732 | + * Alias of self::set_total_tax(). |
|
2733 | + * |
|
2734 | + * @since 1.0.19 |
|
2735 | + * @param float $value tax total. |
|
2736 | + */ |
|
2737 | + public function set_tax_total( $value ) { |
|
2738 | + $this->set_total_tax( $value ); |
|
2739 | 2739 | } |
2740 | 2740 | |
2741 | 2741 | /** |
2742 | - * Set the invoice fees amount. |
|
2743 | - * |
|
2744 | - * @since 1.0.19 |
|
2745 | - * @param float $value fees total. |
|
2746 | - */ |
|
2747 | - public function set_total_fees( $value ) { |
|
2748 | - $this->set_prop( 'total_fees', $value ); |
|
2742 | + * Set the invoice fees amount. |
|
2743 | + * |
|
2744 | + * @since 1.0.19 |
|
2745 | + * @param float $value fees total. |
|
2746 | + */ |
|
2747 | + public function set_total_fees( $value ) { |
|
2748 | + $this->set_prop( 'total_fees', $value ); |
|
2749 | 2749 | } |
2750 | 2750 | |
2751 | 2751 | /** |
2752 | - * Alias of self::set_total_fees(). |
|
2753 | - * |
|
2754 | - * @since 1.0.19 |
|
2755 | - * @param float $value fees total. |
|
2756 | - */ |
|
2757 | - public function set_fees_total( $value ) { |
|
2758 | - $this->set_total_fees( $value ); |
|
2752 | + * Alias of self::set_total_fees(). |
|
2753 | + * |
|
2754 | + * @since 1.0.19 |
|
2755 | + * @param float $value fees total. |
|
2756 | + */ |
|
2757 | + public function set_fees_total( $value ) { |
|
2758 | + $this->set_total_fees( $value ); |
|
2759 | 2759 | } |
2760 | 2760 | |
2761 | 2761 | /** |
2762 | - * Set the invoice fees. |
|
2763 | - * |
|
2764 | - * @since 1.0.19 |
|
2765 | - * @param array $value fees. |
|
2766 | - */ |
|
2767 | - public function set_fees( $value ) { |
|
2762 | + * Set the invoice fees. |
|
2763 | + * |
|
2764 | + * @since 1.0.19 |
|
2765 | + * @param array $value fees. |
|
2766 | + */ |
|
2767 | + public function set_fees( $value ) { |
|
2768 | 2768 | |
2769 | - if ( ! is_array( $value ) ) { |
|
2770 | - $value = array(); |
|
2771 | - } |
|
2769 | + if ( ! is_array( $value ) ) { |
|
2770 | + $value = array(); |
|
2771 | + } |
|
2772 | 2772 | |
2773 | - $this->set_prop( 'fees', $value ); |
|
2773 | + $this->set_prop( 'fees', $value ); |
|
2774 | 2774 | |
2775 | 2775 | } |
2776 | 2776 | |
2777 | 2777 | /** |
2778 | - * Set the invoice taxes. |
|
2779 | - * |
|
2780 | - * @since 1.0.19 |
|
2781 | - * @param array $value taxes. |
|
2782 | - */ |
|
2783 | - public function set_taxes( $value ) { |
|
2778 | + * Set the invoice taxes. |
|
2779 | + * |
|
2780 | + * @since 1.0.19 |
|
2781 | + * @param array $value taxes. |
|
2782 | + */ |
|
2783 | + public function set_taxes( $value ) { |
|
2784 | 2784 | |
2785 | - if ( ! is_array( $value ) ) { |
|
2786 | - $value = array(); |
|
2787 | - } |
|
2785 | + if ( ! is_array( $value ) ) { |
|
2786 | + $value = array(); |
|
2787 | + } |
|
2788 | 2788 | |
2789 | - $this->set_prop( 'taxes', $value ); |
|
2789 | + $this->set_prop( 'taxes', $value ); |
|
2790 | 2790 | |
2791 | 2791 | } |
2792 | 2792 | |
2793 | 2793 | /** |
2794 | - * Set the invoice discounts. |
|
2795 | - * |
|
2796 | - * @since 1.0.19 |
|
2797 | - * @param array $value discounts. |
|
2798 | - */ |
|
2799 | - public function set_discounts( $value ) { |
|
2794 | + * Set the invoice discounts. |
|
2795 | + * |
|
2796 | + * @since 1.0.19 |
|
2797 | + * @param array $value discounts. |
|
2798 | + */ |
|
2799 | + public function set_discounts( $value ) { |
|
2800 | 2800 | |
2801 | - if ( ! is_array( $value ) ) { |
|
2802 | - $value = array(); |
|
2803 | - } |
|
2801 | + if ( ! is_array( $value ) ) { |
|
2802 | + $value = array(); |
|
2803 | + } |
|
2804 | 2804 | |
2805 | - $this->set_prop( 'discounts', $value ); |
|
2805 | + $this->set_prop( 'discounts', $value ); |
|
2806 | 2806 | } |
2807 | 2807 | |
2808 | 2808 | /** |
2809 | - * Set the invoice items. |
|
2810 | - * |
|
2811 | - * @since 1.0.19 |
|
2812 | - * @param GetPaid_Form_Item[] $value items. |
|
2813 | - */ |
|
2814 | - public function set_items( $value ) { |
|
2809 | + * Set the invoice items. |
|
2810 | + * |
|
2811 | + * @since 1.0.19 |
|
2812 | + * @param GetPaid_Form_Item[] $value items. |
|
2813 | + */ |
|
2814 | + public function set_items( $value ) { |
|
2815 | 2815 | |
2816 | 2816 | // Remove existing items. |
2817 | 2817 | $this->set_prop( 'items', array() ); |
@@ -2828,95 +2828,95 @@ discard block |
||
2828 | 2828 | } |
2829 | 2829 | |
2830 | 2830 | /** |
2831 | - * Set the payment form. |
|
2832 | - * |
|
2833 | - * @since 1.0.19 |
|
2834 | - * @param int $value payment form. |
|
2835 | - */ |
|
2836 | - public function set_payment_form( $value ) { |
|
2837 | - $this->set_prop( 'payment_form', $value ); |
|
2831 | + * Set the payment form. |
|
2832 | + * |
|
2833 | + * @since 1.0.19 |
|
2834 | + * @param int $value payment form. |
|
2835 | + */ |
|
2836 | + public function set_payment_form( $value ) { |
|
2837 | + $this->set_prop( 'payment_form', $value ); |
|
2838 | 2838 | } |
2839 | 2839 | |
2840 | 2840 | /** |
2841 | - * Set the submission id. |
|
2842 | - * |
|
2843 | - * @since 1.0.19 |
|
2844 | - * @param string $value submission id. |
|
2845 | - */ |
|
2846 | - public function set_submission_id( $value ) { |
|
2847 | - $this->set_prop( 'submission_id', $value ); |
|
2841 | + * Set the submission id. |
|
2842 | + * |
|
2843 | + * @since 1.0.19 |
|
2844 | + * @param string $value submission id. |
|
2845 | + */ |
|
2846 | + public function set_submission_id( $value ) { |
|
2847 | + $this->set_prop( 'submission_id', $value ); |
|
2848 | 2848 | } |
2849 | 2849 | |
2850 | 2850 | /** |
2851 | - * Set the discount code. |
|
2852 | - * |
|
2853 | - * @since 1.0.19 |
|
2854 | - * @param string $value discount code. |
|
2855 | - */ |
|
2856 | - public function set_discount_code( $value ) { |
|
2857 | - $this->set_prop( 'discount_code', $value ); |
|
2851 | + * Set the discount code. |
|
2852 | + * |
|
2853 | + * @since 1.0.19 |
|
2854 | + * @param string $value discount code. |
|
2855 | + */ |
|
2856 | + public function set_discount_code( $value ) { |
|
2857 | + $this->set_prop( 'discount_code', $value ); |
|
2858 | 2858 | } |
2859 | 2859 | |
2860 | 2860 | /** |
2861 | - * Set the gateway. |
|
2862 | - * |
|
2863 | - * @since 1.0.19 |
|
2864 | - * @param string $value gateway. |
|
2865 | - */ |
|
2866 | - public function set_gateway( $value ) { |
|
2867 | - $this->set_prop( 'gateway', $value ); |
|
2861 | + * Set the gateway. |
|
2862 | + * |
|
2863 | + * @since 1.0.19 |
|
2864 | + * @param string $value gateway. |
|
2865 | + */ |
|
2866 | + public function set_gateway( $value ) { |
|
2867 | + $this->set_prop( 'gateway', $value ); |
|
2868 | 2868 | } |
2869 | 2869 | |
2870 | 2870 | /** |
2871 | - * Set the transaction id. |
|
2872 | - * |
|
2873 | - * @since 1.0.19 |
|
2874 | - * @param string $value transaction id. |
|
2875 | - */ |
|
2876 | - public function set_transaction_id( $value ) { |
|
2877 | - if ( ! empty( $value ) ) { |
|
2878 | - $this->set_prop( 'transaction_id', $value ); |
|
2879 | - } |
|
2871 | + * Set the transaction id. |
|
2872 | + * |
|
2873 | + * @since 1.0.19 |
|
2874 | + * @param string $value transaction id. |
|
2875 | + */ |
|
2876 | + public function set_transaction_id( $value ) { |
|
2877 | + if ( ! empty( $value ) ) { |
|
2878 | + $this->set_prop( 'transaction_id', $value ); |
|
2879 | + } |
|
2880 | 2880 | } |
2881 | 2881 | |
2882 | 2882 | /** |
2883 | - * Set the currency id. |
|
2884 | - * |
|
2885 | - * @since 1.0.19 |
|
2886 | - * @param string $value currency id. |
|
2887 | - */ |
|
2888 | - public function set_currency( $value ) { |
|
2889 | - $this->set_prop( 'currency', $value ); |
|
2883 | + * Set the currency id. |
|
2884 | + * |
|
2885 | + * @since 1.0.19 |
|
2886 | + * @param string $value currency id. |
|
2887 | + */ |
|
2888 | + public function set_currency( $value ) { |
|
2889 | + $this->set_prop( 'currency', $value ); |
|
2890 | 2890 | } |
2891 | 2891 | |
2892 | - /** |
|
2893 | - * Set whether to disable taxes. |
|
2894 | - * |
|
2895 | - * @since 1.0.19 |
|
2896 | - * @param bool $value value. |
|
2897 | - */ |
|
2898 | - public function set_disable_taxes( $value ) { |
|
2899 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
2900 | - } |
|
2892 | + /** |
|
2893 | + * Set whether to disable taxes. |
|
2894 | + * |
|
2895 | + * @since 1.0.19 |
|
2896 | + * @param bool $value value. |
|
2897 | + */ |
|
2898 | + public function set_disable_taxes( $value ) { |
|
2899 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
2900 | + } |
|
2901 | 2901 | |
2902 | 2902 | /** |
2903 | - * Set the subscription id. |
|
2904 | - * |
|
2905 | - * @since 1.0.19 |
|
2906 | - * @param string $value subscription id. |
|
2907 | - */ |
|
2908 | - public function set_subscription_id( $value ) { |
|
2909 | - $this->set_prop( 'subscription_id', $value ); |
|
2910 | - } |
|
2903 | + * Set the subscription id. |
|
2904 | + * |
|
2905 | + * @since 1.0.19 |
|
2906 | + * @param string $value subscription id. |
|
2907 | + */ |
|
2908 | + public function set_subscription_id( $value ) { |
|
2909 | + $this->set_prop( 'subscription_id', $value ); |
|
2910 | + } |
|
2911 | 2911 | |
2912 | - /** |
|
2913 | - * Set the remote subscription id. |
|
2914 | - * |
|
2915 | - * @since 1.0.19 |
|
2916 | - * @param string $value subscription id. |
|
2917 | - */ |
|
2918 | - public function set_remote_subscription_id( $value ) { |
|
2919 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
2912 | + /** |
|
2913 | + * Set the remote subscription id. |
|
2914 | + * |
|
2915 | + * @since 1.0.19 |
|
2916 | + * @param string $value subscription id. |
|
2917 | + */ |
|
2918 | + public function set_remote_subscription_id( $value ) { |
|
2919 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
2920 | 2920 | } |
2921 | 2921 | |
2922 | 2922 | /* |
@@ -2955,12 +2955,12 @@ discard block |
||
2955 | 2955 | */ |
2956 | 2956 | public function is_taxable() { |
2957 | 2957 | return ! $this->get_disable_taxes(); |
2958 | - } |
|
2958 | + } |
|
2959 | 2959 | |
2960 | - /** |
|
2961 | - * @deprecated |
|
2962 | - */ |
|
2963 | - public function has_vat() { |
|
2960 | + /** |
|
2961 | + * @deprecated |
|
2962 | + */ |
|
2963 | + public function has_vat() { |
|
2964 | 2964 | global $wpinv_euvat, $wpi_country; |
2965 | 2965 | |
2966 | 2966 | $requires_vat = false; |
@@ -2971,17 +2971,17 @@ discard block |
||
2971 | 2971 | } |
2972 | 2972 | |
2973 | 2973 | return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
2974 | - } |
|
2974 | + } |
|
2975 | 2975 | |
2976 | - /** |
|
2977 | - * Checks to see if the invoice requires payment. |
|
2978 | - */ |
|
2979 | - public function is_free() { |
|
2976 | + /** |
|
2977 | + * Checks to see if the invoice requires payment. |
|
2978 | + */ |
|
2979 | + public function is_free() { |
|
2980 | 2980 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
2981 | 2981 | |
2982 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
2983 | - $is_free = false; |
|
2984 | - } |
|
2982 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
2983 | + $is_free = false; |
|
2984 | + } |
|
2985 | 2985 | |
2986 | 2986 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
2987 | 2987 | } |
@@ -2992,46 +2992,46 @@ discard block |
||
2992 | 2992 | public function is_paid() { |
2993 | 2993 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
2994 | 2994 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
2995 | - } |
|
2995 | + } |
|
2996 | 2996 | |
2997 | - /** |
|
2997 | + /** |
|
2998 | 2998 | * Checks if the invoice needs payment. |
2999 | 2999 | */ |
3000 | - public function needs_payment() { |
|
3001 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3000 | + public function needs_payment() { |
|
3001 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3002 | 3002 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
3003 | 3003 | } |
3004 | 3004 | |
3005 | - /** |
|
3005 | + /** |
|
3006 | 3006 | * Checks if the invoice is refunded. |
3007 | 3007 | */ |
3008 | - public function is_refunded() { |
|
3008 | + public function is_refunded() { |
|
3009 | 3009 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
3010 | 3010 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
3011 | - } |
|
3011 | + } |
|
3012 | 3012 | |
3013 | - /** |
|
3013 | + /** |
|
3014 | 3014 | * Checks if the invoice is held. |
3015 | 3015 | */ |
3016 | - public function is_held() { |
|
3016 | + public function is_held() { |
|
3017 | 3017 | $is_held = $this->has_status( 'wpi-onhold' ); |
3018 | 3018 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
3019 | - } |
|
3019 | + } |
|
3020 | 3020 | |
3021 | - /** |
|
3021 | + /** |
|
3022 | 3022 | * Checks if the invoice is due. |
3023 | 3023 | */ |
3024 | - public function is_due() { |
|
3025 | - $due_date = $this->get_due_date(); |
|
3026 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3027 | - } |
|
3024 | + public function is_due() { |
|
3025 | + $due_date = $this->get_due_date(); |
|
3026 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3027 | + } |
|
3028 | 3028 | |
3029 | - /** |
|
3029 | + /** |
|
3030 | 3030 | * Checks if the invoice is draft. |
3031 | 3031 | */ |
3032 | - public function is_draft() { |
|
3032 | + public function is_draft() { |
|
3033 | 3033 | return $this->has_status( 'draft, auto-draft' ); |
3034 | - } |
|
3034 | + } |
|
3035 | 3035 | |
3036 | 3036 | /** |
3037 | 3037 | * Checks if the invoice has a given status. |
@@ -3039,9 +3039,9 @@ discard block |
||
3039 | 3039 | public function has_status( $status ) { |
3040 | 3040 | $status = wpinv_parse_list( $status ); |
3041 | 3041 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
3042 | - } |
|
3042 | + } |
|
3043 | 3043 | |
3044 | - /** |
|
3044 | + /** |
|
3045 | 3045 | * Checks if the invoice is of a given type. |
3046 | 3046 | */ |
3047 | 3047 | public function is_type( $type ) { |
@@ -3064,25 +3064,25 @@ discard block |
||
3064 | 3064 | */ |
3065 | 3065 | public function has_free_trial() { |
3066 | 3066 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
3067 | - } |
|
3067 | + } |
|
3068 | 3068 | |
3069 | - /** |
|
3069 | + /** |
|
3070 | 3070 | * @deprecated |
3071 | 3071 | */ |
3072 | 3072 | public function is_free_trial() { |
3073 | 3073 | $this->has_free_trial(); |
3074 | 3074 | } |
3075 | 3075 | |
3076 | - /** |
|
3076 | + /** |
|
3077 | 3077 | * Check if the initial payment if 0. |
3078 | 3078 | * |
3079 | 3079 | */ |
3080 | - public function is_initial_free() { |
|
3080 | + public function is_initial_free() { |
|
3081 | 3081 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
3082 | 3082 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
3083 | 3083 | } |
3084 | 3084 | |
3085 | - /** |
|
3085 | + /** |
|
3086 | 3086 | * Check if the recurring item has a free trial. |
3087 | 3087 | * |
3088 | 3088 | */ |
@@ -3095,21 +3095,21 @@ discard block |
||
3095 | 3095 | |
3096 | 3096 | $item = $this->get_recurring( true ); |
3097 | 3097 | return $item->has_free_trial(); |
3098 | - } |
|
3098 | + } |
|
3099 | 3099 | |
3100 | - /** |
|
3100 | + /** |
|
3101 | 3101 | * Check if the free trial is a result of a discount. |
3102 | 3102 | */ |
3103 | 3103 | public function is_free_trial_from_discount() { |
3104 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3105 | - } |
|
3104 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3105 | + } |
|
3106 | 3106 | |
3107 | - /** |
|
3107 | + /** |
|
3108 | 3108 | * @deprecated |
3109 | 3109 | */ |
3110 | 3110 | public function discount_first_payment_only() { |
3111 | 3111 | |
3112 | - $discount_code = $this->get_discount_code(); |
|
3112 | + $discount_code = $this->get_discount_code(); |
|
3113 | 3113 | if ( empty( $this->discount_code ) || ! $this->is_recurring() ) { |
3114 | 3114 | return true; |
3115 | 3115 | } |
@@ -3140,28 +3140,28 @@ discard block |
||
3140 | 3140 | */ |
3141 | 3141 | public function add_item( $item ) { |
3142 | 3142 | |
3143 | - if ( is_array( $item ) ) { |
|
3144 | - $item = $this->process_array_item( $item ); |
|
3145 | - } |
|
3143 | + if ( is_array( $item ) ) { |
|
3144 | + $item = $this->process_array_item( $item ); |
|
3145 | + } |
|
3146 | 3146 | |
3147 | - if ( is_numeric( $item ) ) { |
|
3148 | - $item = new GetPaid_Form_Item( $item ); |
|
3149 | - } |
|
3147 | + if ( is_numeric( $item ) ) { |
|
3148 | + $item = new GetPaid_Form_Item( $item ); |
|
3149 | + } |
|
3150 | 3150 | |
3151 | 3151 | // Make sure that it is available for purchase. |
3152 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3153 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3152 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3153 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3154 | 3154 | } |
3155 | 3155 | |
3156 | 3156 | // Do we have a recurring item? |
3157 | - if ( $item->is_recurring() ) { |
|
3157 | + if ( $item->is_recurring() ) { |
|
3158 | 3158 | |
3159 | - // An invoice can only contain one recurring item. |
|
3160 | - if ( ! empty( $this->recurring_item && $this->recurring_item != (int) $item->get_id() ) ) { |
|
3161 | - return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) ); |
|
3162 | - } |
|
3159 | + // An invoice can only contain one recurring item. |
|
3160 | + if ( ! empty( $this->recurring_item && $this->recurring_item != (int) $item->get_id() ) ) { |
|
3161 | + return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) ); |
|
3162 | + } |
|
3163 | 3163 | |
3164 | - $this->recurring_item = $item->get_id(); |
|
3164 | + $this->recurring_item = $item->get_id(); |
|
3165 | 3165 | } |
3166 | 3166 | |
3167 | 3167 | // Invoice id. |
@@ -3172,60 +3172,60 @@ discard block |
||
3172 | 3172 | $items[ (int) $item->get_id() ] = $item; |
3173 | 3173 | |
3174 | 3174 | $this->set_prop( 'items', $items ); |
3175 | - return true; |
|
3176 | - } |
|
3175 | + return true; |
|
3176 | + } |
|
3177 | 3177 | |
3178 | - /** |
|
3179 | - * Converts an array to an item. |
|
3180 | - * |
|
3181 | - * @since 1.0.19 |
|
3182 | - * @return GetPaid_Form_Item |
|
3183 | - */ |
|
3184 | - protected function process_array_item( $array ) { |
|
3178 | + /** |
|
3179 | + * Converts an array to an item. |
|
3180 | + * |
|
3181 | + * @since 1.0.19 |
|
3182 | + * @return GetPaid_Form_Item |
|
3183 | + */ |
|
3184 | + protected function process_array_item( $array ) { |
|
3185 | 3185 | |
3186 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3187 | - $item = new GetPaid_Form_Item( $item_id ); |
|
3186 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3187 | + $item = new GetPaid_Form_Item( $item_id ); |
|
3188 | 3188 | |
3189 | - // Set item data. |
|
3190 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3191 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
3192 | - $method = "set_$key"; |
|
3193 | - $item->$method( $array[ "item_$key" ] ); |
|
3194 | - } |
|
3195 | - } |
|
3189 | + // Set item data. |
|
3190 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3191 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
3192 | + $method = "set_$key"; |
|
3193 | + $item->$method( $array[ "item_$key" ] ); |
|
3194 | + } |
|
3195 | + } |
|
3196 | 3196 | |
3197 | - if ( isset( $array['quantity'] ) ) { |
|
3198 | - $item->set_quantity( $array['quantity'] ); |
|
3199 | - } |
|
3197 | + if ( isset( $array['quantity'] ) ) { |
|
3198 | + $item->set_quantity( $array['quantity'] ); |
|
3199 | + } |
|
3200 | 3200 | |
3201 | - // Set item meta. |
|
3202 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3203 | - $item->set_item_meta( $array['meta'] ); |
|
3204 | - } |
|
3201 | + // Set item meta. |
|
3202 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3203 | + $item->set_item_meta( $array['meta'] ); |
|
3204 | + } |
|
3205 | 3205 | |
3206 | - return $item; |
|
3206 | + return $item; |
|
3207 | 3207 | |
3208 | - } |
|
3208 | + } |
|
3209 | 3209 | |
3210 | 3210 | /** |
3211 | - * Retrieves a specific item. |
|
3212 | - * |
|
3213 | - * @since 1.0.19 |
|
3214 | - */ |
|
3215 | - public function get_item( $item_id ) { |
|
3216 | - $items = $this->get_items(); |
|
3217 | - $item_id = (int) $item_id; |
|
3218 | - return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
3211 | + * Retrieves a specific item. |
|
3212 | + * |
|
3213 | + * @since 1.0.19 |
|
3214 | + */ |
|
3215 | + public function get_item( $item_id ) { |
|
3216 | + $items = $this->get_items(); |
|
3217 | + $item_id = (int) $item_id; |
|
3218 | + return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
3219 | 3219 | } |
3220 | 3220 | |
3221 | 3221 | /** |
3222 | - * Removes a specific item. |
|
3223 | - * |
|
3224 | - * @since 1.0.19 |
|
3225 | - */ |
|
3226 | - public function remove_item( $item_id ) { |
|
3227 | - $items = $this->get_items(); |
|
3228 | - $item_id = (int) $item_id; |
|
3222 | + * Removes a specific item. |
|
3223 | + * |
|
3224 | + * @since 1.0.19 |
|
3225 | + */ |
|
3226 | + public function remove_item( $item_id ) { |
|
3227 | + $items = $this->get_items(); |
|
3228 | + $item_id = (int) $item_id; |
|
3229 | 3229 | |
3230 | 3230 | if ( $item_id == $this->recurring_item ) { |
3231 | 3231 | $this->recurring_item = null; |
@@ -3238,35 +3238,35 @@ discard block |
||
3238 | 3238 | } |
3239 | 3239 | |
3240 | 3240 | /** |
3241 | - * Adds a fee to the invoice. |
|
3242 | - * |
|
3243 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3244 | - * @since 1.0.19 |
|
3245 | - */ |
|
3241 | + * Adds a fee to the invoice. |
|
3242 | + * |
|
3243 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3244 | + * @since 1.0.19 |
|
3245 | + */ |
|
3246 | 3246 | public function add_fee( $fee ) { |
3247 | 3247 | |
3248 | - $fees = $this->get_fees(); |
|
3249 | - $fees[ $fee['name'] ] = $fee; |
|
3250 | - $this->set_prop( 'fees', $fees ); |
|
3248 | + $fees = $this->get_fees(); |
|
3249 | + $fees[ $fee['name'] ] = $fee; |
|
3250 | + $this->set_prop( 'fees', $fees ); |
|
3251 | 3251 | |
3252 | 3252 | } |
3253 | 3253 | |
3254 | 3254 | /** |
3255 | - * Retrieves a specific fee. |
|
3256 | - * |
|
3257 | - * @since 1.0.19 |
|
3258 | - */ |
|
3259 | - public function get_fee( $fee ) { |
|
3255 | + * Retrieves a specific fee. |
|
3256 | + * |
|
3257 | + * @since 1.0.19 |
|
3258 | + */ |
|
3259 | + public function get_fee( $fee ) { |
|
3260 | 3260 | $fees = $this->get_fees(); |
3261 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3261 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3262 | 3262 | } |
3263 | 3263 | |
3264 | 3264 | /** |
3265 | - * Removes a specific fee. |
|
3266 | - * |
|
3267 | - * @since 1.0.19 |
|
3268 | - */ |
|
3269 | - public function remove_fee( $fee ) { |
|
3265 | + * Removes a specific fee. |
|
3266 | + * |
|
3267 | + * @since 1.0.19 |
|
3268 | + */ |
|
3269 | + public function remove_fee( $fee ) { |
|
3270 | 3270 | $fees = $this->get_fees(); |
3271 | 3271 | if ( isset( $fees[ $fee ] ) ) { |
3272 | 3272 | unset( $fees[ $fee ] ); |
@@ -3274,43 +3274,43 @@ discard block |
||
3274 | 3274 | } |
3275 | 3275 | } |
3276 | 3276 | |
3277 | - /** |
|
3278 | - * Adds a discount to the invoice. |
|
3279 | - * |
|
3280 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
3281 | - * @since 1.0.19 |
|
3282 | - */ |
|
3283 | - public function add_discount( $discount ) { |
|
3277 | + /** |
|
3278 | + * Adds a discount to the invoice. |
|
3279 | + * |
|
3280 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
3281 | + * @since 1.0.19 |
|
3282 | + */ |
|
3283 | + public function add_discount( $discount ) { |
|
3284 | 3284 | |
3285 | - $discounts = $this->get_discounts(); |
|
3286 | - $discounts[ $discount['name'] ] = $discount; |
|
3287 | - $this->set_prop( 'discounts', $discounts ); |
|
3285 | + $discounts = $this->get_discounts(); |
|
3286 | + $discounts[ $discount['name'] ] = $discount; |
|
3287 | + $this->set_prop( 'discounts', $discounts ); |
|
3288 | 3288 | |
3289 | - } |
|
3289 | + } |
|
3290 | 3290 | |
3291 | 3291 | /** |
3292 | - * Retrieves a specific discount. |
|
3293 | - * |
|
3294 | - * @since 1.0.19 |
|
3295 | - * @return float |
|
3296 | - */ |
|
3297 | - public function get_discount( $discount = false ) { |
|
3292 | + * Retrieves a specific discount. |
|
3293 | + * |
|
3294 | + * @since 1.0.19 |
|
3295 | + * @return float |
|
3296 | + */ |
|
3297 | + public function get_discount( $discount = false ) { |
|
3298 | 3298 | |
3299 | - // Backwards compatibilty. |
|
3300 | - if ( empty( $discount ) ) { |
|
3301 | - return $this->get_total_discount(); |
|
3302 | - } |
|
3299 | + // Backwards compatibilty. |
|
3300 | + if ( empty( $discount ) ) { |
|
3301 | + return $this->get_total_discount(); |
|
3302 | + } |
|
3303 | 3303 | |
3304 | 3304 | $discounts = $this->get_discounts(); |
3305 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3305 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3306 | 3306 | } |
3307 | 3307 | |
3308 | 3308 | /** |
3309 | - * Removes a specific discount. |
|
3310 | - * |
|
3311 | - * @since 1.0.19 |
|
3312 | - */ |
|
3313 | - public function remove_discount( $discount ) { |
|
3309 | + * Removes a specific discount. |
|
3310 | + * |
|
3311 | + * @since 1.0.19 |
|
3312 | + */ |
|
3313 | + public function remove_discount( $discount ) { |
|
3314 | 3314 | $discounts = $this->get_discounts(); |
3315 | 3315 | if ( isset( $discounts[ $discount ] ) ) { |
3316 | 3316 | unset( $discounts[ $discount ] ); |
@@ -3327,34 +3327,34 @@ discard block |
||
3327 | 3327 | if ( $this->is_taxable() ) { |
3328 | 3328 | |
3329 | 3329 | $taxes = $this->get_taxes(); |
3330 | - $taxes[ $tax['name'] ] = $tax; |
|
3331 | - $this->set_prop( 'taxes', $tax ); |
|
3330 | + $taxes[ $tax['name'] ] = $tax; |
|
3331 | + $this->set_prop( 'taxes', $tax ); |
|
3332 | 3332 | |
3333 | 3333 | } |
3334 | 3334 | } |
3335 | 3335 | |
3336 | 3336 | /** |
3337 | - * Retrieves a specific tax. |
|
3338 | - * |
|
3339 | - * @since 1.0.19 |
|
3340 | - */ |
|
3341 | - public function get_tax( $tax = null ) { |
|
3337 | + * Retrieves a specific tax. |
|
3338 | + * |
|
3339 | + * @since 1.0.19 |
|
3340 | + */ |
|
3341 | + public function get_tax( $tax = null ) { |
|
3342 | 3342 | |
3343 | - // Backwards compatility. |
|
3344 | - if ( empty( $tax ) ) { |
|
3345 | - return $this->get_total_tax(); |
|
3346 | - } |
|
3343 | + // Backwards compatility. |
|
3344 | + if ( empty( $tax ) ) { |
|
3345 | + return $this->get_total_tax(); |
|
3346 | + } |
|
3347 | 3347 | |
3348 | 3348 | $taxes = $this->get_taxes(); |
3349 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3349 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3350 | 3350 | } |
3351 | 3351 | |
3352 | 3352 | /** |
3353 | - * Removes a specific tax. |
|
3354 | - * |
|
3355 | - * @since 1.0.19 |
|
3356 | - */ |
|
3357 | - public function remove_tax( $tax ) { |
|
3353 | + * Removes a specific tax. |
|
3354 | + * |
|
3355 | + * @since 1.0.19 |
|
3356 | + */ |
|
3357 | + public function remove_tax( $tax ) { |
|
3358 | 3358 | $taxes = $this->get_taxes(); |
3359 | 3359 | if ( isset( $taxes[ $tax ] ) ) { |
3360 | 3360 | unset( $taxes[ $tax ] ); |
@@ -3363,134 +3363,134 @@ discard block |
||
3363 | 3363 | } |
3364 | 3364 | |
3365 | 3365 | /** |
3366 | - * Recalculates the invoice subtotal. |
|
3367 | - * |
|
3368 | - * @since 1.0.19 |
|
3369 | - * @return float The recalculated subtotal |
|
3370 | - */ |
|
3371 | - public function recalculate_subtotal() { |
|
3366 | + * Recalculates the invoice subtotal. |
|
3367 | + * |
|
3368 | + * @since 1.0.19 |
|
3369 | + * @return float The recalculated subtotal |
|
3370 | + */ |
|
3371 | + public function recalculate_subtotal() { |
|
3372 | 3372 | $items = $this->get_items(); |
3373 | - $subtotal = 0; |
|
3374 | - $recurring = 0; |
|
3373 | + $subtotal = 0; |
|
3374 | + $recurring = 0; |
|
3375 | 3375 | |
3376 | 3376 | foreach ( $items as $item ) { |
3377 | - $subtotal += $item->get_sub_total(); |
|
3378 | - $recurring += $item->get_recurring_sub_total(); |
|
3377 | + $subtotal += $item->get_sub_total(); |
|
3378 | + $recurring += $item->get_recurring_sub_total(); |
|
3379 | 3379 | } |
3380 | 3380 | |
3381 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3382 | - $this->set_subtotal( $current ); |
|
3381 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3382 | + $this->set_subtotal( $current ); |
|
3383 | 3383 | |
3384 | - $this->totals['subtotal'] = array( |
|
3385 | - 'initial' => $subtotal, |
|
3386 | - 'recurring' => $recurring, |
|
3387 | - ); |
|
3384 | + $this->totals['subtotal'] = array( |
|
3385 | + 'initial' => $subtotal, |
|
3386 | + 'recurring' => $recurring, |
|
3387 | + ); |
|
3388 | 3388 | |
3389 | 3389 | return $current; |
3390 | 3390 | } |
3391 | 3391 | |
3392 | 3392 | /** |
3393 | - * Recalculates the invoice discount total. |
|
3394 | - * |
|
3395 | - * @since 1.0.19 |
|
3396 | - * @return float The recalculated discount |
|
3397 | - */ |
|
3398 | - public function recalculate_total_discount() { |
|
3393 | + * Recalculates the invoice discount total. |
|
3394 | + * |
|
3395 | + * @since 1.0.19 |
|
3396 | + * @return float The recalculated discount |
|
3397 | + */ |
|
3398 | + public function recalculate_total_discount() { |
|
3399 | 3399 | $discounts = $this->get_discounts(); |
3400 | - $discount = 0; |
|
3401 | - $recurring = 0; |
|
3400 | + $discount = 0; |
|
3401 | + $recurring = 0; |
|
3402 | 3402 | |
3403 | 3403 | foreach ( $discounts as $data ) { |
3404 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3405 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3406 | - } |
|
3404 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3405 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3406 | + } |
|
3407 | 3407 | |
3408 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
3408 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
3409 | 3409 | |
3410 | - $this->set_total_discount( $current ); |
|
3410 | + $this->set_total_discount( $current ); |
|
3411 | 3411 | |
3412 | - $this->totals['discount'] = array( |
|
3413 | - 'initial' => $discount, |
|
3414 | - 'recurring' => $recurring, |
|
3415 | - ); |
|
3412 | + $this->totals['discount'] = array( |
|
3413 | + 'initial' => $discount, |
|
3414 | + 'recurring' => $recurring, |
|
3415 | + ); |
|
3416 | 3416 | |
3417 | - return $current; |
|
3417 | + return $current; |
|
3418 | 3418 | |
3419 | 3419 | } |
3420 | 3420 | |
3421 | 3421 | /** |
3422 | - * Recalculates the invoice tax total. |
|
3423 | - * |
|
3424 | - * @since 1.0.19 |
|
3425 | - * @return float The recalculated tax |
|
3426 | - */ |
|
3427 | - public function recalculate_total_tax() { |
|
3422 | + * Recalculates the invoice tax total. |
|
3423 | + * |
|
3424 | + * @since 1.0.19 |
|
3425 | + * @return float The recalculated tax |
|
3426 | + */ |
|
3427 | + public function recalculate_total_tax() { |
|
3428 | 3428 | $taxes = $this->get_taxes(); |
3429 | - $tax = 0; |
|
3430 | - $recurring = 0; |
|
3429 | + $tax = 0; |
|
3430 | + $recurring = 0; |
|
3431 | 3431 | |
3432 | 3432 | foreach ( $taxes as $data ) { |
3433 | - $tax += wpinv_sanitize_amount( $data['initial_tax'] ); |
|
3434 | - $recurring += wpinv_sanitize_amount( $data['recurring_tax'] ); |
|
3435 | - } |
|
3433 | + $tax += wpinv_sanitize_amount( $data['initial_tax'] ); |
|
3434 | + $recurring += wpinv_sanitize_amount( $data['recurring_tax'] ); |
|
3435 | + } |
|
3436 | 3436 | |
3437 | - $current = $this->is_renewal() ? $recurring : $tax; |
|
3438 | - $this->set_total_tax( $current ); |
|
3437 | + $current = $this->is_renewal() ? $recurring : $tax; |
|
3438 | + $this->set_total_tax( $current ); |
|
3439 | 3439 | |
3440 | - $this->totals['tax'] = array( |
|
3441 | - 'initial' => $tax, |
|
3442 | - 'recurring' => $recurring, |
|
3443 | - ); |
|
3440 | + $this->totals['tax'] = array( |
|
3441 | + 'initial' => $tax, |
|
3442 | + 'recurring' => $recurring, |
|
3443 | + ); |
|
3444 | 3444 | |
3445 | - return $current; |
|
3445 | + return $current; |
|
3446 | 3446 | |
3447 | 3447 | } |
3448 | 3448 | |
3449 | 3449 | /** |
3450 | - * Recalculates the invoice fees total. |
|
3451 | - * |
|
3452 | - * @since 1.0.19 |
|
3453 | - * @return float The recalculated fee |
|
3454 | - */ |
|
3455 | - public function recalculate_total_fees() { |
|
3456 | - $fees = $this->get_fees(); |
|
3457 | - $fee = 0; |
|
3458 | - $recurring = 0; |
|
3450 | + * Recalculates the invoice fees total. |
|
3451 | + * |
|
3452 | + * @since 1.0.19 |
|
3453 | + * @return float The recalculated fee |
|
3454 | + */ |
|
3455 | + public function recalculate_total_fees() { |
|
3456 | + $fees = $this->get_fees(); |
|
3457 | + $fee = 0; |
|
3458 | + $recurring = 0; |
|
3459 | 3459 | |
3460 | 3460 | foreach ( $fees as $data ) { |
3461 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3462 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3463 | - } |
|
3461 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3462 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3463 | + } |
|
3464 | 3464 | |
3465 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
3466 | - $this->set_total_fees( $current ); |
|
3465 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
3466 | + $this->set_total_fees( $current ); |
|
3467 | 3467 | |
3468 | - $this->totals['fee'] = array( |
|
3469 | - 'initial' => $fee, |
|
3470 | - 'recurring' => $recurring, |
|
3471 | - ); |
|
3468 | + $this->totals['fee'] = array( |
|
3469 | + 'initial' => $fee, |
|
3470 | + 'recurring' => $recurring, |
|
3471 | + ); |
|
3472 | 3472 | |
3473 | 3473 | $this->set_total_fees( $fee ); |
3474 | 3474 | return $current; |
3475 | 3475 | } |
3476 | 3476 | |
3477 | 3477 | /** |
3478 | - * Recalculates the invoice total. |
|
3479 | - * |
|
3480 | - * @since 1.0.19 |
|
3478 | + * Recalculates the invoice total. |
|
3479 | + * |
|
3480 | + * @since 1.0.19 |
|
3481 | 3481 | * @return float The invoice total |
3482 | - */ |
|
3483 | - public function recalculate_total() { |
|
3482 | + */ |
|
3483 | + public function recalculate_total() { |
|
3484 | 3484 | $this->recalculate_subtotal(); |
3485 | 3485 | $this->recalculate_total_fees(); |
3486 | 3486 | $this->recalculate_total_discount(); |
3487 | 3487 | $this->recalculate_total_tax(); |
3488 | - return $this->get_total(); |
|
3489 | - } |
|
3488 | + return $this->get_total(); |
|
3489 | + } |
|
3490 | 3490 | |
3491 | - /** |
|
3492 | - * @deprecated |
|
3493 | - */ |
|
3491 | + /** |
|
3492 | + * @deprecated |
|
3493 | + */ |
|
3494 | 3494 | public function recalculate_totals( $temp = false ) { |
3495 | 3495 | $this->update_items( $temp ); |
3496 | 3496 | $this->save( true ); |
@@ -3508,7 +3508,7 @@ discard block |
||
3508 | 3508 | * Adds a note to an invoice. |
3509 | 3509 | * |
3510 | 3510 | * @param string $note The note being added. |
3511 | - * @return int|false The new note's ID on success, false on failure. |
|
3511 | + * @return int|false The new note's ID on success, false on failure. |
|
3512 | 3512 | * |
3513 | 3513 | */ |
3514 | 3514 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3518,21 +3518,21 @@ discard block |
||
3518 | 3518 | return false; |
3519 | 3519 | } |
3520 | 3520 | |
3521 | - $author = 'System'; |
|
3522 | - $author_email = '[email protected]'; |
|
3521 | + $author = 'System'; |
|
3522 | + $author_email = '[email protected]'; |
|
3523 | 3523 | |
3524 | - // If this is an admin comment or it has been added by the user. |
|
3525 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3526 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
3524 | + // If this is an admin comment or it has been added by the user. |
|
3525 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3526 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
3527 | 3527 | $author = $user->display_name; |
3528 | 3528 | $author_email = $user->user_email; |
3529 | - } |
|
3529 | + } |
|
3530 | 3530 | |
3531 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3531 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3532 | 3532 | |
3533 | - } |
|
3533 | + } |
|
3534 | 3534 | |
3535 | - /** |
|
3535 | + /** |
|
3536 | 3536 | * Generates a unique key for the invoice. |
3537 | 3537 | */ |
3538 | 3538 | public function generate_key( $string = '' ) { |
@@ -3552,113 +3552,113 @@ discard block |
||
3552 | 3552 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
3553 | 3553 | } |
3554 | 3554 | |
3555 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3556 | - |
|
3557 | - } |
|
3558 | - |
|
3559 | - /** |
|
3560 | - * Handle the status transition. |
|
3561 | - */ |
|
3562 | - protected function status_transition() { |
|
3563 | - $status_transition = $this->status_transition; |
|
3564 | - |
|
3565 | - // Reset status transition variable. |
|
3566 | - $this->status_transition = false; |
|
3567 | - |
|
3568 | - if ( $status_transition ) { |
|
3569 | - try { |
|
3555 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3570 | 3556 | |
3571 | - // Fire a hook for the status change. |
|
3572 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3573 | - |
|
3574 | - // @deprecated this is deprecated and will be removed in the future. |
|
3575 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3576 | - |
|
3577 | - if ( ! empty( $status_transition['from'] ) ) { |
|
3578 | - |
|
3579 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
3580 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3581 | - |
|
3582 | - // Fire another hook. |
|
3583 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3584 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3585 | - |
|
3586 | - // @deprecated this is deprecated and will be removed in the future. |
|
3587 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3588 | - |
|
3589 | - // Note the transition occurred. |
|
3590 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3591 | - |
|
3592 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3593 | - if ( |
|
3594 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3595 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3596 | - ) { |
|
3597 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3598 | - } |
|
3599 | - |
|
3600 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3601 | - if ( |
|
3602 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3603 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3604 | - ) { |
|
3605 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3606 | - } |
|
3607 | - } else { |
|
3608 | - /* translators: %s: new invoice status */ |
|
3609 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3610 | - |
|
3611 | - // Note the transition occurred. |
|
3612 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3557 | + } |
|
3613 | 3558 | |
3614 | - } |
|
3615 | - } catch ( Exception $e ) { |
|
3616 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3617 | - } |
|
3618 | - } |
|
3619 | - } |
|
3559 | + /** |
|
3560 | + * Handle the status transition. |
|
3561 | + */ |
|
3562 | + protected function status_transition() { |
|
3563 | + $status_transition = $this->status_transition; |
|
3564 | + |
|
3565 | + // Reset status transition variable. |
|
3566 | + $this->status_transition = false; |
|
3567 | + |
|
3568 | + if ( $status_transition ) { |
|
3569 | + try { |
|
3570 | + |
|
3571 | + // Fire a hook for the status change. |
|
3572 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3573 | + |
|
3574 | + // @deprecated this is deprecated and will be removed in the future. |
|
3575 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3576 | + |
|
3577 | + if ( ! empty( $status_transition['from'] ) ) { |
|
3578 | + |
|
3579 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
3580 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3581 | + |
|
3582 | + // Fire another hook. |
|
3583 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3584 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3585 | + |
|
3586 | + // @deprecated this is deprecated and will be removed in the future. |
|
3587 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3588 | + |
|
3589 | + // Note the transition occurred. |
|
3590 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3591 | + |
|
3592 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3593 | + if ( |
|
3594 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3595 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3596 | + ) { |
|
3597 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3598 | + } |
|
3599 | + |
|
3600 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3601 | + if ( |
|
3602 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3603 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3604 | + ) { |
|
3605 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3606 | + } |
|
3607 | + } else { |
|
3608 | + /* translators: %s: new invoice status */ |
|
3609 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3610 | + |
|
3611 | + // Note the transition occurred. |
|
3612 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3613 | + |
|
3614 | + } |
|
3615 | + } catch ( Exception $e ) { |
|
3616 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3617 | + } |
|
3618 | + } |
|
3619 | + } |
|
3620 | 3620 | |
3621 | - /** |
|
3622 | - * Updates an invoice status. |
|
3623 | - */ |
|
3624 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3621 | + /** |
|
3622 | + * Updates an invoice status. |
|
3623 | + */ |
|
3624 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3625 | 3625 | |
3626 | - // Fires before updating a status. |
|
3627 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3626 | + // Fires before updating a status. |
|
3627 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3628 | 3628 | |
3629 | - // Update the status. |
|
3630 | - $this->set_status( $new_status, $note, $manual ); |
|
3629 | + // Update the status. |
|
3630 | + $this->set_status( $new_status, $note, $manual ); |
|
3631 | 3631 | |
3632 | - // Save the order. |
|
3633 | - return $this->save(); |
|
3632 | + // Save the order. |
|
3633 | + return $this->save(); |
|
3634 | 3634 | |
3635 | - } |
|
3635 | + } |
|
3636 | 3636 | |
3637 | - /** |
|
3638 | - * @deprecated |
|
3639 | - */ |
|
3640 | - public function refresh_item_ids() { |
|
3637 | + /** |
|
3638 | + * @deprecated |
|
3639 | + */ |
|
3640 | + public function refresh_item_ids() { |
|
3641 | 3641 | $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) ); |
3642 | 3642 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
3643 | - } |
|
3643 | + } |
|
3644 | 3644 | |
3645 | - /** |
|
3646 | - * @deprecated |
|
3647 | - */ |
|
3648 | - public function update_items( $temp = false ) { |
|
3645 | + /** |
|
3646 | + * @deprecated |
|
3647 | + */ |
|
3648 | + public function update_items( $temp = false ) { |
|
3649 | 3649 | |
3650 | - $this->set_items( $this->get_items() ); |
|
3650 | + $this->set_items( $this->get_items() ); |
|
3651 | 3651 | |
3652 | - if ( ! $temp ) { |
|
3653 | - $this->save(); |
|
3654 | - } |
|
3652 | + if ( ! $temp ) { |
|
3653 | + $this->save(); |
|
3654 | + } |
|
3655 | 3655 | |
3656 | 3656 | return $this; |
3657 | - } |
|
3657 | + } |
|
3658 | 3658 | |
3659 | - /** |
|
3660 | - * @deprecated |
|
3661 | - */ |
|
3659 | + /** |
|
3660 | + * @deprecated |
|
3661 | + */ |
|
3662 | 3662 | public function validate_discount() { |
3663 | 3663 | |
3664 | 3664 | $discount_code = $this->get_discount_code(); |
@@ -3674,97 +3674,97 @@ discard block |
||
3674 | 3674 | |
3675 | 3675 | } |
3676 | 3676 | |
3677 | - /** |
|
3678 | - * Refunds an invoice. |
|
3679 | - */ |
|
3677 | + /** |
|
3678 | + * Refunds an invoice. |
|
3679 | + */ |
|
3680 | 3680 | public function refund() { |
3681 | - $this->set_status( 'wpi-refunded' ); |
|
3681 | + $this->set_status( 'wpi-refunded' ); |
|
3682 | 3682 | $this->save(); |
3683 | - } |
|
3683 | + } |
|
3684 | 3684 | |
3685 | - /** |
|
3686 | - * Marks an invoice as paid. |
|
3687 | - * |
|
3688 | - * @param string $transaction_id |
|
3689 | - */ |
|
3685 | + /** |
|
3686 | + * Marks an invoice as paid. |
|
3687 | + * |
|
3688 | + * @param string $transaction_id |
|
3689 | + */ |
|
3690 | 3690 | public function mark_paid( $transaction_id = null, $note = '' ) { |
3691 | 3691 | |
3692 | - // Set the transaction id. |
|
3693 | - if ( empty( $transaction_id ) ) { |
|
3694 | - $transaction_id = $this->generate_key('trans_'); |
|
3695 | - } |
|
3692 | + // Set the transaction id. |
|
3693 | + if ( empty( $transaction_id ) ) { |
|
3694 | + $transaction_id = $this->generate_key('trans_'); |
|
3695 | + } |
|
3696 | 3696 | |
3697 | - if ( ! $this->get_transaction_id() ) { |
|
3698 | - $this->set_transaction_id( $transaction_id ); |
|
3699 | - } |
|
3697 | + if ( ! $this->get_transaction_id() ) { |
|
3698 | + $this->set_transaction_id( $transaction_id ); |
|
3699 | + } |
|
3700 | 3700 | |
3701 | - if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
3702 | - return $this->save(); |
|
3703 | - } |
|
3701 | + if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
3702 | + return $this->save(); |
|
3703 | + } |
|
3704 | 3704 | |
3705 | - // Set the completed date. |
|
3706 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
3705 | + // Set the completed date. |
|
3706 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
3707 | 3707 | |
3708 | - // Set the new status. |
|
3709 | - if ( $this->is_renewal() ) { |
|
3708 | + // Set the new status. |
|
3709 | + if ( $this->is_renewal() ) { |
|
3710 | 3710 | |
3711 | - $_note = sprintf( |
|
3712 | - __( 'Renewed via %s', 'invoicing' ), |
|
3713 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
3714 | - ); |
|
3711 | + $_note = sprintf( |
|
3712 | + __( 'Renewed via %s', 'invoicing' ), |
|
3713 | + $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
3714 | + ); |
|
3715 | 3715 | |
3716 | - if ( 'none' == $this->get_gateway() ) { |
|
3717 | - $_note = $note; |
|
3718 | - } |
|
3716 | + if ( 'none' == $this->get_gateway() ) { |
|
3717 | + $_note = $note; |
|
3718 | + } |
|
3719 | 3719 | |
3720 | - $this->set_status( 'wpi-renewal', $_note ); |
|
3720 | + $this->set_status( 'wpi-renewal', $_note ); |
|
3721 | 3721 | |
3722 | - } else { |
|
3722 | + } else { |
|
3723 | 3723 | |
3724 | - $_note = sprintf( |
|
3725 | - __( 'Paid via %s', 'invoicing' ), |
|
3726 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
3727 | - ); |
|
3724 | + $_note = sprintf( |
|
3725 | + __( 'Paid via %s', 'invoicing' ), |
|
3726 | + $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
3727 | + ); |
|
3728 | 3728 | |
3729 | - if ( 'none' == $this->get_gateway() ) { |
|
3730 | - $_note = $note; |
|
3731 | - } |
|
3729 | + if ( 'none' == $this->get_gateway() ) { |
|
3730 | + $_note = $note; |
|
3731 | + } |
|
3732 | 3732 | |
3733 | - $this->set_status( 'publish',$_note ); |
|
3733 | + $this->set_status( 'publish',$_note ); |
|
3734 | 3734 | |
3735 | - } |
|
3735 | + } |
|
3736 | 3736 | |
3737 | - // Set checkout mode. |
|
3738 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
3739 | - $this->set_mode( $mode ); |
|
3737 | + // Set checkout mode. |
|
3738 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
3739 | + $this->set_mode( $mode ); |
|
3740 | 3740 | |
3741 | - // Save the invoice. |
|
3741 | + // Save the invoice. |
|
3742 | 3742 | $this->save(); |
3743 | - } |
|
3744 | - |
|
3745 | - |
|
3746 | - /** |
|
3747 | - * Save data to the database. |
|
3748 | - * |
|
3749 | - * @since 1.0.19 |
|
3750 | - * @return int invoice ID |
|
3751 | - */ |
|
3752 | - public function save() { |
|
3753 | - $this->maybe_set_date_paid(); |
|
3754 | - $this->maybe_set_key(); |
|
3755 | - parent::save(); |
|
3756 | - $this->clear_cache(); |
|
3757 | - $this->status_transition(); |
|
3758 | - return $this->get_id(); |
|
3759 | - } |
|
3760 | - |
|
3761 | - /** |
|
3743 | + } |
|
3744 | + |
|
3745 | + |
|
3746 | + /** |
|
3747 | + * Save data to the database. |
|
3748 | + * |
|
3749 | + * @since 1.0.19 |
|
3750 | + * @return int invoice ID |
|
3751 | + */ |
|
3752 | + public function save() { |
|
3753 | + $this->maybe_set_date_paid(); |
|
3754 | + $this->maybe_set_key(); |
|
3755 | + parent::save(); |
|
3756 | + $this->clear_cache(); |
|
3757 | + $this->status_transition(); |
|
3758 | + return $this->get_id(); |
|
3759 | + } |
|
3760 | + |
|
3761 | + /** |
|
3762 | 3762 | * Clears the subscription's cache. |
3763 | 3763 | */ |
3764 | 3764 | public function clear_cache() { |
3765 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
3766 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
3767 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
3768 | - } |
|
3765 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
3766 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
3767 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
3768 | + } |
|
3769 | 3769 | |
3770 | 3770 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,537 +15,537 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpinv_subscr_profile_id', |
|
26 | - '_wpinv_subscription_id', |
|
27 | - '_wpinv_taxes', |
|
28 | - '_wpinv_fees', |
|
29 | - '_wpinv_discounts', |
|
30 | - '_wpinv_submission_id', |
|
31 | - '_wpinv_payment_form', |
|
32 | - '_wpinv_is_viewed', |
|
33 | - 'wpinv_email_cc', |
|
34 | - 'wpinv_template', |
|
35 | - 'wpinv_created_via' |
|
36 | - ); |
|
37 | - |
|
38 | - /** |
|
39 | - * A map of meta keys to data props. |
|
40 | - * |
|
41 | - * @since 1.0.19 |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected $meta_key_to_props = array( |
|
46 | - '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
47 | - '_wpinv_subscription_id' => 'subscription_id', |
|
48 | - '_wpinv_taxes' => 'taxes', |
|
49 | - '_wpinv_fees' => 'fees', |
|
50 | - '_wpinv_discounts' => 'discounts', |
|
51 | - '_wpinv_submission_id' => 'submission_id', |
|
52 | - '_wpinv_payment_form' => 'payment_form', |
|
53 | - '_wpinv_is_viewed' => 'is_viewed', |
|
54 | - 'wpinv_email_cc' => 'email_cc', |
|
55 | - 'wpinv_template' => 'template', |
|
56 | - 'wpinv_created_via' => 'created_via', |
|
57 | - ); |
|
58 | - |
|
59 | - /** |
|
60 | - * A map of database fields to data props. |
|
61 | - * |
|
62 | - * @since 1.0.19 |
|
63 | - * |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - protected $database_fields_to_props = array( |
|
67 | - 'post_id' => 'id', |
|
68 | - 'number' => 'number', |
|
69 | - 'currency' => 'currency', |
|
70 | - 'key' => 'key', |
|
71 | - 'type' => 'type', |
|
72 | - 'mode' => 'mode', |
|
73 | - 'user_ip' => 'user_ip', |
|
74 | - 'first_name' => 'first_name', |
|
75 | - 'last_name' => 'last_name', |
|
76 | - 'address' => 'address', |
|
77 | - 'city' => 'city', |
|
78 | - 'state' => 'state', |
|
79 | - 'country' => 'country', |
|
80 | - 'zip' => 'zip', |
|
81 | - 'zip' => 'zip', |
|
82 | - 'adddress_confirmed' => 'address_confirmed', |
|
83 | - 'gateway' => 'gateway', |
|
84 | - 'transaction_id' => 'transaction_id', |
|
85 | - 'currency' => 'currency', |
|
86 | - 'subtotal' => 'subtotal', |
|
87 | - 'tax' => 'total_tax', |
|
88 | - 'fees_total' => 'total_fees', |
|
89 | - 'discount' => 'total_discount', |
|
90 | - 'total' => 'total', |
|
91 | - 'discount_code' => 'discount_code', |
|
92 | - 'disable_taxes' => 'disable_taxes', |
|
93 | - 'due_date' => 'due_date', |
|
94 | - 'completed_date' => 'completed_date', |
|
95 | - 'company' => 'company', |
|
96 | - 'vat_number' => 'vat_number', |
|
97 | - 'vat_rate' => 'vat_rate', |
|
98 | - ); |
|
99 | - |
|
100 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpinv_subscr_profile_id', |
|
26 | + '_wpinv_subscription_id', |
|
27 | + '_wpinv_taxes', |
|
28 | + '_wpinv_fees', |
|
29 | + '_wpinv_discounts', |
|
30 | + '_wpinv_submission_id', |
|
31 | + '_wpinv_payment_form', |
|
32 | + '_wpinv_is_viewed', |
|
33 | + 'wpinv_email_cc', |
|
34 | + 'wpinv_template', |
|
35 | + 'wpinv_created_via' |
|
36 | + ); |
|
37 | + |
|
38 | + /** |
|
39 | + * A map of meta keys to data props. |
|
40 | + * |
|
41 | + * @since 1.0.19 |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected $meta_key_to_props = array( |
|
46 | + '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
47 | + '_wpinv_subscription_id' => 'subscription_id', |
|
48 | + '_wpinv_taxes' => 'taxes', |
|
49 | + '_wpinv_fees' => 'fees', |
|
50 | + '_wpinv_discounts' => 'discounts', |
|
51 | + '_wpinv_submission_id' => 'submission_id', |
|
52 | + '_wpinv_payment_form' => 'payment_form', |
|
53 | + '_wpinv_is_viewed' => 'is_viewed', |
|
54 | + 'wpinv_email_cc' => 'email_cc', |
|
55 | + 'wpinv_template' => 'template', |
|
56 | + 'wpinv_created_via' => 'created_via', |
|
57 | + ); |
|
58 | + |
|
59 | + /** |
|
60 | + * A map of database fields to data props. |
|
61 | + * |
|
62 | + * @since 1.0.19 |
|
63 | + * |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + protected $database_fields_to_props = array( |
|
67 | + 'post_id' => 'id', |
|
68 | + 'number' => 'number', |
|
69 | + 'currency' => 'currency', |
|
70 | + 'key' => 'key', |
|
71 | + 'type' => 'type', |
|
72 | + 'mode' => 'mode', |
|
73 | + 'user_ip' => 'user_ip', |
|
74 | + 'first_name' => 'first_name', |
|
75 | + 'last_name' => 'last_name', |
|
76 | + 'address' => 'address', |
|
77 | + 'city' => 'city', |
|
78 | + 'state' => 'state', |
|
79 | + 'country' => 'country', |
|
80 | + 'zip' => 'zip', |
|
81 | + 'zip' => 'zip', |
|
82 | + 'adddress_confirmed' => 'address_confirmed', |
|
83 | + 'gateway' => 'gateway', |
|
84 | + 'transaction_id' => 'transaction_id', |
|
85 | + 'currency' => 'currency', |
|
86 | + 'subtotal' => 'subtotal', |
|
87 | + 'tax' => 'total_tax', |
|
88 | + 'fees_total' => 'total_fees', |
|
89 | + 'discount' => 'total_discount', |
|
90 | + 'total' => 'total', |
|
91 | + 'discount_code' => 'discount_code', |
|
92 | + 'disable_taxes' => 'disable_taxes', |
|
93 | + 'due_date' => 'due_date', |
|
94 | + 'completed_date' => 'completed_date', |
|
95 | + 'company' => 'company', |
|
96 | + 'vat_number' => 'vat_number', |
|
97 | + 'vat_rate' => 'vat_rate', |
|
98 | + ); |
|
99 | + |
|
100 | + /* |
|
101 | 101 | |-------------------------------------------------------------------------- |
102 | 102 | | CRUD Methods |
103 | 103 | |-------------------------------------------------------------------------- |
104 | 104 | */ |
105 | 105 | |
106 | - /** |
|
107 | - * Method to create a new invoice in the database. |
|
108 | - * |
|
109 | - * @param WPInv_Invoice $invoice Invoice object. |
|
110 | - */ |
|
111 | - public function create( &$invoice ) { |
|
112 | - $invoice->set_version( WPINV_VERSION ); |
|
113 | - $invoice->set_date_created( current_time('mysql') ); |
|
114 | - |
|
115 | - // Create a new post. |
|
116 | - $id = wp_insert_post( |
|
117 | - apply_filters( |
|
118 | - 'getpaid_new_invoice_data', |
|
119 | - array( |
|
120 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
121 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
122 | - 'post_status' => $this->get_post_status( $invoice ), |
|
123 | - 'ping_status' => 'closed', |
|
124 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
125 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
126 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
127 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
128 | - ) |
|
129 | - ), |
|
130 | - true |
|
131 | - ); |
|
132 | - |
|
133 | - if ( $id && ! is_wp_error( $id ) ) { |
|
134 | - |
|
135 | - // Update the new id and regenerate a title. |
|
136 | - $invoice->set_id( $id ); |
|
137 | - |
|
138 | - $invoice->maybe_set_number(); |
|
139 | - |
|
140 | - wp_update_post( |
|
141 | - array( |
|
142 | - 'ID' => $invoice->get_id(), |
|
143 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
144 | - 'post_name' => $invoice->get_path( 'edit' ) |
|
145 | - ) |
|
146 | - ); |
|
147 | - |
|
148 | - // Save special fields and items. |
|
149 | - $this->save_special_fields( $invoice ); |
|
150 | - $this->save_items( $invoice ); |
|
151 | - |
|
152 | - // Update meta data. |
|
153 | - $this->update_post_meta( $invoice ); |
|
154 | - $invoice->save_meta_data(); |
|
155 | - |
|
156 | - // Apply changes. |
|
157 | - $invoice->apply_changes(); |
|
158 | - $this->clear_caches( $invoice ); |
|
159 | - |
|
160 | - // Fires after a new invoice is created. |
|
161 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
162 | - return true; |
|
163 | - } |
|
164 | - |
|
165 | - if ( is_wp_error( $id ) ) { |
|
166 | - $invoice->last_error = $id->get_error_message(); |
|
167 | - } |
|
168 | - |
|
169 | - return false; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Method to read an invoice from the database. |
|
174 | - * |
|
175 | - * @param WPInv_Invoice $invoice Invoice object. |
|
176 | - * |
|
177 | - */ |
|
178 | - public function read( &$invoice ) { |
|
179 | - |
|
180 | - $invoice->set_defaults(); |
|
181 | - $invoice_object = get_post( $invoice->get_id() ); |
|
182 | - |
|
183 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
184 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
185 | - $invoice->set_id( 0 ); |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - $invoice->set_props( |
|
190 | - array( |
|
191 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
192 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
193 | - 'status' => $invoice_object->post_status, |
|
194 | - 'author' => $invoice_object->post_author, |
|
195 | - 'description' => $invoice_object->post_excerpt, |
|
196 | - 'parent_id' => $invoice_object->post_parent, |
|
197 | - 'name' => $invoice_object->post_title, |
|
198 | - 'path' => $invoice_object->post_name, |
|
199 | - 'post_type' => $invoice_object->post_type, |
|
200 | - ) |
|
201 | - ); |
|
202 | - |
|
203 | - $invoice->set_type( $invoice_object->post_type ); |
|
204 | - |
|
205 | - $this->read_object_data( $invoice, $invoice_object ); |
|
206 | - $this->add_special_fields( $invoice ); |
|
207 | - $this->add_items( $invoice ); |
|
208 | - $invoice->read_meta_data(); |
|
209 | - $invoice->set_object_read( true ); |
|
210 | - do_action( 'getpaid_read_invoice', $invoice ); |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Method to update an invoice in the database. |
|
216 | - * |
|
217 | - * @param WPInv_Invoice $invoice Invoice object. |
|
218 | - */ |
|
219 | - public function update( &$invoice ) { |
|
220 | - $invoice->save_meta_data(); |
|
221 | - $invoice->set_version( WPINV_VERSION ); |
|
222 | - |
|
223 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
224 | - $invoice->set_date_created( current_time('mysql') ); |
|
225 | - } |
|
226 | - |
|
227 | - // Ensure both the key and number are set. |
|
228 | - $invoice->get_path(); |
|
229 | - |
|
230 | - // Grab the current status so we can compare. |
|
231 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
232 | - |
|
233 | - $changes = $invoice->get_changes(); |
|
234 | - |
|
235 | - // Only update the post when the post data changes. |
|
236 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
237 | - $post_data = array( |
|
238 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
239 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
240 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
241 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
242 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
243 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
244 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
245 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
246 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
247 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
248 | - ); |
|
249 | - |
|
250 | - /** |
|
251 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
252 | - * to update data, since wp_update_post spawns more calls to the |
|
253 | - * save_post action. |
|
254 | - * |
|
255 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
256 | - * or an update purely from CRUD. |
|
257 | - */ |
|
258 | - if ( doing_action( 'save_post' ) ) { |
|
259 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
260 | - clean_post_cache( $invoice->get_id() ); |
|
261 | - } else { |
|
262 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
263 | - } |
|
264 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
265 | - } |
|
266 | - |
|
267 | - // Update meta data. |
|
268 | - $this->update_post_meta( $invoice ); |
|
269 | - |
|
270 | - // Save special fields and items. |
|
271 | - $this->save_special_fields( $invoice ); |
|
272 | - $this->save_items( $invoice ); |
|
273 | - |
|
274 | - // Apply the changes. |
|
275 | - $invoice->apply_changes(); |
|
276 | - |
|
277 | - // Clear caches. |
|
278 | - $this->clear_caches( $invoice ); |
|
279 | - |
|
280 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
281 | - $new_status = $invoice->get_status( 'edit' ); |
|
282 | - |
|
283 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
284 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
285 | - } else { |
|
286 | - do_action( 'getpaid_update_invoice', $invoice ); |
|
287 | - } |
|
288 | - |
|
289 | - } |
|
290 | - |
|
291 | - /* |
|
106 | + /** |
|
107 | + * Method to create a new invoice in the database. |
|
108 | + * |
|
109 | + * @param WPInv_Invoice $invoice Invoice object. |
|
110 | + */ |
|
111 | + public function create( &$invoice ) { |
|
112 | + $invoice->set_version( WPINV_VERSION ); |
|
113 | + $invoice->set_date_created( current_time('mysql') ); |
|
114 | + |
|
115 | + // Create a new post. |
|
116 | + $id = wp_insert_post( |
|
117 | + apply_filters( |
|
118 | + 'getpaid_new_invoice_data', |
|
119 | + array( |
|
120 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
121 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
122 | + 'post_status' => $this->get_post_status( $invoice ), |
|
123 | + 'ping_status' => 'closed', |
|
124 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
125 | + 'post_title' => $invoice->get_title( 'edit' ), |
|
126 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
127 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
128 | + ) |
|
129 | + ), |
|
130 | + true |
|
131 | + ); |
|
132 | + |
|
133 | + if ( $id && ! is_wp_error( $id ) ) { |
|
134 | + |
|
135 | + // Update the new id and regenerate a title. |
|
136 | + $invoice->set_id( $id ); |
|
137 | + |
|
138 | + $invoice->maybe_set_number(); |
|
139 | + |
|
140 | + wp_update_post( |
|
141 | + array( |
|
142 | + 'ID' => $invoice->get_id(), |
|
143 | + 'post_title' => $invoice->get_number( 'edit' ), |
|
144 | + 'post_name' => $invoice->get_path( 'edit' ) |
|
145 | + ) |
|
146 | + ); |
|
147 | + |
|
148 | + // Save special fields and items. |
|
149 | + $this->save_special_fields( $invoice ); |
|
150 | + $this->save_items( $invoice ); |
|
151 | + |
|
152 | + // Update meta data. |
|
153 | + $this->update_post_meta( $invoice ); |
|
154 | + $invoice->save_meta_data(); |
|
155 | + |
|
156 | + // Apply changes. |
|
157 | + $invoice->apply_changes(); |
|
158 | + $this->clear_caches( $invoice ); |
|
159 | + |
|
160 | + // Fires after a new invoice is created. |
|
161 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
162 | + return true; |
|
163 | + } |
|
164 | + |
|
165 | + if ( is_wp_error( $id ) ) { |
|
166 | + $invoice->last_error = $id->get_error_message(); |
|
167 | + } |
|
168 | + |
|
169 | + return false; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Method to read an invoice from the database. |
|
174 | + * |
|
175 | + * @param WPInv_Invoice $invoice Invoice object. |
|
176 | + * |
|
177 | + */ |
|
178 | + public function read( &$invoice ) { |
|
179 | + |
|
180 | + $invoice->set_defaults(); |
|
181 | + $invoice_object = get_post( $invoice->get_id() ); |
|
182 | + |
|
183 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
184 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
185 | + $invoice->set_id( 0 ); |
|
186 | + return false; |
|
187 | + } |
|
188 | + |
|
189 | + $invoice->set_props( |
|
190 | + array( |
|
191 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
192 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
193 | + 'status' => $invoice_object->post_status, |
|
194 | + 'author' => $invoice_object->post_author, |
|
195 | + 'description' => $invoice_object->post_excerpt, |
|
196 | + 'parent_id' => $invoice_object->post_parent, |
|
197 | + 'name' => $invoice_object->post_title, |
|
198 | + 'path' => $invoice_object->post_name, |
|
199 | + 'post_type' => $invoice_object->post_type, |
|
200 | + ) |
|
201 | + ); |
|
202 | + |
|
203 | + $invoice->set_type( $invoice_object->post_type ); |
|
204 | + |
|
205 | + $this->read_object_data( $invoice, $invoice_object ); |
|
206 | + $this->add_special_fields( $invoice ); |
|
207 | + $this->add_items( $invoice ); |
|
208 | + $invoice->read_meta_data(); |
|
209 | + $invoice->set_object_read( true ); |
|
210 | + do_action( 'getpaid_read_invoice', $invoice ); |
|
211 | + |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Method to update an invoice in the database. |
|
216 | + * |
|
217 | + * @param WPInv_Invoice $invoice Invoice object. |
|
218 | + */ |
|
219 | + public function update( &$invoice ) { |
|
220 | + $invoice->save_meta_data(); |
|
221 | + $invoice->set_version( WPINV_VERSION ); |
|
222 | + |
|
223 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
224 | + $invoice->set_date_created( current_time('mysql') ); |
|
225 | + } |
|
226 | + |
|
227 | + // Ensure both the key and number are set. |
|
228 | + $invoice->get_path(); |
|
229 | + |
|
230 | + // Grab the current status so we can compare. |
|
231 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
232 | + |
|
233 | + $changes = $invoice->get_changes(); |
|
234 | + |
|
235 | + // Only update the post when the post data changes. |
|
236 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
237 | + $post_data = array( |
|
238 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
239 | + 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
240 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
241 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
242 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
243 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
244 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
245 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
246 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
247 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
248 | + ); |
|
249 | + |
|
250 | + /** |
|
251 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
252 | + * to update data, since wp_update_post spawns more calls to the |
|
253 | + * save_post action. |
|
254 | + * |
|
255 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
256 | + * or an update purely from CRUD. |
|
257 | + */ |
|
258 | + if ( doing_action( 'save_post' ) ) { |
|
259 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
260 | + clean_post_cache( $invoice->get_id() ); |
|
261 | + } else { |
|
262 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
263 | + } |
|
264 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
265 | + } |
|
266 | + |
|
267 | + // Update meta data. |
|
268 | + $this->update_post_meta( $invoice ); |
|
269 | + |
|
270 | + // Save special fields and items. |
|
271 | + $this->save_special_fields( $invoice ); |
|
272 | + $this->save_items( $invoice ); |
|
273 | + |
|
274 | + // Apply the changes. |
|
275 | + $invoice->apply_changes(); |
|
276 | + |
|
277 | + // Clear caches. |
|
278 | + $this->clear_caches( $invoice ); |
|
279 | + |
|
280 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
281 | + $new_status = $invoice->get_status( 'edit' ); |
|
282 | + |
|
283 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
284 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
285 | + } else { |
|
286 | + do_action( 'getpaid_update_invoice', $invoice ); |
|
287 | + } |
|
288 | + |
|
289 | + } |
|
290 | + |
|
291 | + /* |
|
292 | 292 | |-------------------------------------------------------------------------- |
293 | 293 | | Additional Methods |
294 | 294 | |-------------------------------------------------------------------------- |
295 | 295 | */ |
296 | 296 | |
297 | - /** |
|
297 | + /** |
|
298 | 298 | * Retrieves special fields and adds to the invoice. |
299 | - * |
|
300 | - * @param WPInv_Invoice $invoice Invoice object. |
|
299 | + * |
|
300 | + * @param WPInv_Invoice $invoice Invoice object. |
|
301 | 301 | */ |
302 | 302 | public function add_special_fields( &$invoice ) { |
303 | - global $wpdb; |
|
303 | + global $wpdb; |
|
304 | 304 | |
305 | - // Maybe retrieve from the cache. |
|
306 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
305 | + // Maybe retrieve from the cache. |
|
306 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
307 | 307 | |
308 | - // If not found, retrieve from the db. |
|
309 | - if ( false === $data ) { |
|
310 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
308 | + // If not found, retrieve from the db. |
|
309 | + if ( false === $data ) { |
|
310 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
311 | 311 | |
312 | - $data = $wpdb->get_row( |
|
313 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
314 | - ARRAY_A |
|
315 | - ); |
|
312 | + $data = $wpdb->get_row( |
|
313 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
314 | + ARRAY_A |
|
315 | + ); |
|
316 | 316 | |
317 | - // Update the cache with our data |
|
318 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
317 | + // Update the cache with our data |
|
318 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
319 | 319 | |
320 | - } |
|
320 | + } |
|
321 | 321 | |
322 | - // Abort if the data does not exist. |
|
323 | - if ( empty( $data ) ) { |
|
324 | - $invoice->set_object_read( true ); |
|
325 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
326 | - return; |
|
327 | - } |
|
322 | + // Abort if the data does not exist. |
|
323 | + if ( empty( $data ) ) { |
|
324 | + $invoice->set_object_read( true ); |
|
325 | + $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
326 | + return; |
|
327 | + } |
|
328 | 328 | |
329 | - $props = array(); |
|
329 | + $props = array(); |
|
330 | 330 | |
331 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
331 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
332 | 332 | |
333 | - if ( $db_field == 'post_id' ) { |
|
334 | - continue; |
|
335 | - } |
|
336 | - |
|
337 | - $props[ $prop ] = $data[ $db_field ]; |
|
338 | - } |
|
339 | - |
|
340 | - $invoice->set_props( $props ); |
|
341 | - |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Gets a list of special fields that need updated based on change state |
|
346 | - * or if they are present in the database or not. |
|
347 | - * |
|
348 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
349 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
350 | - */ |
|
351 | - protected function get_special_fields_to_update( $invoice ) { |
|
352 | - $fields_to_update = array(); |
|
353 | - $changed_props = $invoice->get_changes(); |
|
354 | - |
|
355 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
356 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
357 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
358 | - $fields_to_update[ $database_field ] = $prop; |
|
359 | - } |
|
360 | - } |
|
361 | - |
|
362 | - return $fields_to_update; |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
367 | - * |
|
368 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
369 | - * @since 1.0.19 |
|
370 | - */ |
|
371 | - protected function update_special_fields( &$invoice ) { |
|
372 | - global $wpdb; |
|
373 | - |
|
374 | - $updated_props = array(); |
|
375 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
376 | - |
|
377 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
378 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
379 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
380 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
381 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
382 | - } |
|
383 | - |
|
384 | - if ( ! empty( $updated_props ) ) { |
|
385 | - |
|
386 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
387 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
388 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
389 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
390 | - |
|
391 | - } |
|
392 | - |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Helper method that inserts special fields to the database. |
|
397 | - * |
|
398 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
399 | - * @since 1.0.19 |
|
400 | - */ |
|
401 | - protected function insert_special_fields( &$invoice ) { |
|
402 | - global $wpdb; |
|
403 | - |
|
404 | - $updated_props = array(); |
|
405 | - |
|
406 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
407 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
408 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
409 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
410 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
411 | - } |
|
412 | - |
|
413 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
414 | - $wpdb->insert( $table, $updated_props ); |
|
415 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
416 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
417 | - |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
333 | + if ( $db_field == 'post_id' ) { |
|
334 | + continue; |
|
335 | + } |
|
336 | + |
|
337 | + $props[ $prop ] = $data[ $db_field ]; |
|
338 | + } |
|
339 | + |
|
340 | + $invoice->set_props( $props ); |
|
341 | + |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Gets a list of special fields that need updated based on change state |
|
346 | + * or if they are present in the database or not. |
|
347 | + * |
|
348 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
349 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
350 | + */ |
|
351 | + protected function get_special_fields_to_update( $invoice ) { |
|
352 | + $fields_to_update = array(); |
|
353 | + $changed_props = $invoice->get_changes(); |
|
354 | + |
|
355 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
356 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
357 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
358 | + $fields_to_update[ $database_field ] = $prop; |
|
359 | + } |
|
360 | + } |
|
361 | + |
|
362 | + return $fields_to_update; |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
367 | + * |
|
368 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
369 | + * @since 1.0.19 |
|
370 | + */ |
|
371 | + protected function update_special_fields( &$invoice ) { |
|
372 | + global $wpdb; |
|
373 | + |
|
374 | + $updated_props = array(); |
|
375 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
376 | + |
|
377 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
378 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
379 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
380 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
381 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
382 | + } |
|
383 | + |
|
384 | + if ( ! empty( $updated_props ) ) { |
|
385 | + |
|
386 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
387 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
388 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
389 | + do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
390 | + |
|
391 | + } |
|
392 | + |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Helper method that inserts special fields to the database. |
|
397 | + * |
|
398 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
399 | + * @since 1.0.19 |
|
400 | + */ |
|
401 | + protected function insert_special_fields( &$invoice ) { |
|
402 | + global $wpdb; |
|
403 | + |
|
404 | + $updated_props = array(); |
|
405 | + |
|
406 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
407 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
408 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
409 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
410 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
411 | + } |
|
412 | + |
|
413 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
414 | + $wpdb->insert( $table, $updated_props ); |
|
415 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
416 | + do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
417 | + |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | 421 | * Saves all special fields. |
422 | - * |
|
423 | - * @param WPInv_Invoice $invoice Invoice object. |
|
422 | + * |
|
423 | + * @param WPInv_Invoice $invoice Invoice object. |
|
424 | 424 | */ |
425 | 425 | public function save_special_fields( & $invoice ) { |
426 | - global $wpdb; |
|
426 | + global $wpdb; |
|
427 | 427 | |
428 | - // The invoices table. |
|
429 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
430 | - $id = (int) $invoice->get_id(); |
|
431 | - $invoice->maybe_set_key(); |
|
428 | + // The invoices table. |
|
429 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
430 | + $id = (int) $invoice->get_id(); |
|
431 | + $invoice->maybe_set_key(); |
|
432 | 432 | |
433 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
433 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
434 | 434 | |
435 | - $this->update_special_fields( $invoice ); |
|
435 | + $this->update_special_fields( $invoice ); |
|
436 | 436 | |
437 | - } else { |
|
437 | + } else { |
|
438 | 438 | |
439 | - $this->insert_special_fields( $invoice ); |
|
439 | + $this->insert_special_fields( $invoice ); |
|
440 | 440 | |
441 | - } |
|
441 | + } |
|
442 | 442 | |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - /** |
|
445 | + /** |
|
446 | 446 | * Set's up cart details. |
447 | - * |
|
448 | - * @param WPInv_Invoice $invoice Invoice object. |
|
447 | + * |
|
448 | + * @param WPInv_Invoice $invoice Invoice object. |
|
449 | 449 | */ |
450 | 450 | public function add_items( &$invoice ) { |
451 | - global $wpdb; |
|
451 | + global $wpdb; |
|
452 | 452 | |
453 | - // Maybe retrieve from the cache. |
|
454 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
453 | + // Maybe retrieve from the cache. |
|
454 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
455 | 455 | |
456 | - // If not found, retrieve from the db. |
|
457 | - if ( false === $items ) { |
|
458 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
456 | + // If not found, retrieve from the db. |
|
457 | + if ( false === $items ) { |
|
458 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
459 | 459 | |
460 | - $items = $wpdb->get_results( |
|
461 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
462 | - ); |
|
460 | + $items = $wpdb->get_results( |
|
461 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
462 | + ); |
|
463 | 463 | |
464 | - // Update the cache with our data |
|
465 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
464 | + // Update the cache with our data |
|
465 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
466 | 466 | |
467 | - } |
|
467 | + } |
|
468 | 468 | |
469 | - // Abort if no items found. |
|
469 | + // Abort if no items found. |
|
470 | 470 | if ( empty( $items ) ) { |
471 | 471 | return; |
472 | - } |
|
472 | + } |
|
473 | 473 | |
474 | - foreach ( $items as $item_data ) { |
|
475 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
474 | + foreach ( $items as $item_data ) { |
|
475 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
476 | 476 | |
477 | - // Set item data. |
|
478 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
479 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
480 | - $item->set_name( $item_data->item_name ); |
|
481 | - $item->set_description( $item_data->item_description ); |
|
482 | - $item->set_price( $item_data->item_price ); |
|
483 | - $item->set_quantity( $item_data->quantity ); |
|
484 | - $item->set_item_meta( $item_data->meta ); |
|
477 | + // Set item data. |
|
478 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
479 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
480 | + $item->set_name( $item_data->item_name ); |
|
481 | + $item->set_description( $item_data->item_description ); |
|
482 | + $item->set_price( $item_data->item_price ); |
|
483 | + $item->set_quantity( $item_data->quantity ); |
|
484 | + $item->set_item_meta( $item_data->meta ); |
|
485 | 485 | |
486 | - $invoice->add_item( $item ); |
|
487 | - } |
|
486 | + $invoice->add_item( $item ); |
|
487 | + } |
|
488 | 488 | |
489 | - } |
|
489 | + } |
|
490 | 490 | |
491 | - /** |
|
491 | + /** |
|
492 | 492 | * Saves cart details. |
493 | - * |
|
494 | - * @param WPInv_Invoice $invoice Invoice object. |
|
493 | + * |
|
494 | + * @param WPInv_Invoice $invoice Invoice object. |
|
495 | 495 | */ |
496 | 496 | public function save_items( $invoice ) { |
497 | 497 | |
498 | - // Delete previously existing items. |
|
499 | - $this->delete_items( $invoice ); |
|
498 | + // Delete previously existing items. |
|
499 | + $this->delete_items( $invoice ); |
|
500 | 500 | |
501 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
501 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
502 | 502 | |
503 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
504 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
505 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
506 | - } |
|
503 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
504 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
505 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
506 | + } |
|
507 | 507 | |
508 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
509 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
508 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
509 | + do_action( "getpaid_invoice_save_items", $invoice ); |
|
510 | 510 | |
511 | - } |
|
511 | + } |
|
512 | 512 | |
513 | - /** |
|
513 | + /** |
|
514 | 514 | * Deletes an invoice's cart details from the database. |
515 | - * |
|
516 | - * @param WPInv_Invoice $invoice Invoice object. |
|
515 | + * |
|
516 | + * @param WPInv_Invoice $invoice Invoice object. |
|
517 | 517 | */ |
518 | 518 | public function delete_items( $invoice ) { |
519 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
520 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
521 | - } |
|
519 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
520 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
521 | + } |
|
522 | 522 | |
523 | - /** |
|
523 | + /** |
|
524 | 524 | * Deletes an invoice's special fields from the database. |
525 | - * |
|
526 | - * @param WPInv_Invoice $invoice Invoice object. |
|
525 | + * |
|
526 | + * @param WPInv_Invoice $invoice Invoice object. |
|
527 | 527 | */ |
528 | 528 | public function delete_special_fields( $invoice ) { |
529 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
530 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
531 | - } |
|
529 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
530 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
531 | + } |
|
532 | 532 | |
533 | - /** |
|
534 | - * Get the status to save to the post object. |
|
535 | - * |
|
536 | - * |
|
537 | - * @since 1.0.19 |
|
538 | - * @param WPInv_Invoice $object GetPaid_Data object. |
|
539 | - * @return string |
|
540 | - */ |
|
541 | - protected function get_post_status( $object ) { |
|
542 | - $object_status = $object->get_status( 'edit' ); |
|
543 | - |
|
544 | - if ( ! $object_status ) { |
|
545 | - $object_status = $object->get_default_status(); |
|
546 | - } |
|
547 | - |
|
548 | - return $object_status; |
|
549 | - } |
|
533 | + /** |
|
534 | + * Get the status to save to the post object. |
|
535 | + * |
|
536 | + * |
|
537 | + * @since 1.0.19 |
|
538 | + * @param WPInv_Invoice $object GetPaid_Data object. |
|
539 | + * @return string |
|
540 | + */ |
|
541 | + protected function get_post_status( $object ) { |
|
542 | + $object_status = $object->get_status( 'edit' ); |
|
543 | + |
|
544 | + if ( ! $object_status ) { |
|
545 | + $object_status = $object->get_default_status(); |
|
546 | + } |
|
547 | + |
|
548 | + return $object_status; |
|
549 | + } |
|
550 | 550 | |
551 | 551 | } |
@@ -13,282 +13,282 @@ |
||
13 | 13 | class GetPaid_Subscription_Notification_Emails { |
14 | 14 | |
15 | 15 | /** |
16 | - * The array of subscription email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $subscription_actions; |
|
16 | + * The array of subscription email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $subscription_actions; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Class constructor |
|
23 | + * Class constructor |
|
24 | 24 | * |
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->subscription_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_subscription_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | - ) |
|
37 | - ); |
|
38 | - |
|
39 | - $this->init_hooks(); |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->subscription_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_subscription_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | + ) |
|
37 | + ); |
|
38 | + |
|
39 | + $this->init_hooks(); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | - * Registers email hooks. |
|
45 | - */ |
|
46 | - public function init_hooks() { |
|
47 | - |
|
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | - |
|
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | - |
|
53 | - if ( ! $email->is_active() ) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | - continue; |
|
60 | - } |
|
61 | - |
|
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Filters subscription merge tags. |
|
70 | - * |
|
71 | - * @param array $merge_tags |
|
72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | - */ |
|
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
75 | - |
|
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | - $merge_tags = array_merge( |
|
78 | - $merge_tags, |
|
79 | - $this->get_subscription_merge_tags( $object ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - return $merge_tags; |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates subscription merge tags. |
|
89 | - * |
|
90 | - * @param WPInv_Subscription $subscription |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
94 | - |
|
95 | - // Abort if it does not exist. |
|
96 | - if ( ! $subscription->get_id() ) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $invoice = $subscription->get_parent_invoice(); |
|
101 | - return array( |
|
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ), |
|
108 | - '{subscription_initial_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | - ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Checks if we should send a notification for a subscription. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function should_send_notification( $invoice ) { |
|
123 | - return 0 != $invoice->get_id(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns notification recipients. |
|
128 | - * |
|
129 | - * @param WPInv_Invoice $invoice |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
134 | - |
|
135 | - $cc = $invoice->get_email_cc(); |
|
136 | - |
|
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | - } |
|
141 | - |
|
142 | - return $recipients; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Helper function to send an email. |
|
147 | - * |
|
148 | - * @param WPInv_Subscription $subscription |
|
149 | - * @param GetPaid_Notification_Email $email |
|
150 | - * @param string $type |
|
151 | - * @param array $extra_args Extra template args. |
|
152 | - */ |
|
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | - |
|
155 | - // Abort in case the parent invoice does not exist. |
|
156 | - $invoice = $subscription->get_parent_invoice(); |
|
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | - return; |
|
159 | - } |
|
160 | - |
|
161 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
162 | - |
|
163 | - $recipients = $this->get_recipients( $invoice ); |
|
164 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
165 | - $merge_tags = $email->get_merge_tags(); |
|
166 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
167 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
168 | - $attachments = $email->get_attachments(); |
|
169 | - |
|
170 | - $result = $mailer->send( |
|
171 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
172 | - $subject, |
|
173 | - $content, |
|
174 | - $attachments |
|
175 | - ); |
|
176 | - |
|
177 | - // Maybe send a copy to the admin. |
|
178 | - if ( $email->include_admin_bcc() ) { |
|
179 | - $mailer->send( |
|
180 | - wpinv_get_admin_email(), |
|
181 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
182 | - $content, |
|
183 | - $attachments |
|
184 | - ); |
|
185 | - } |
|
186 | - |
|
187 | - if ( ! $result ) { |
|
188 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
189 | - } |
|
190 | - |
|
191 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
192 | - |
|
193 | - } |
|
44 | + * Registers email hooks. |
|
45 | + */ |
|
46 | + public function init_hooks() { |
|
47 | + |
|
48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | + |
|
51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | + |
|
53 | + if ( ! $email->is_active() ) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $email_type ) ) { |
|
58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | + continue; |
|
60 | + } |
|
61 | + |
|
62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
194 | 67 | |
195 | 68 | /** |
196 | - * Sends a new trial notification. |
|
197 | - * |
|
198 | - * @param WPInv_Subscription $subscription |
|
199 | - */ |
|
200 | - public function subscription_trial( $subscription ) { |
|
69 | + * Filters subscription merge tags. |
|
70 | + * |
|
71 | + * @param array $merge_tags |
|
72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | + */ |
|
74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
201 | 75 | |
202 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
203 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | + $merge_tags = array_merge( |
|
78 | + $merge_tags, |
|
79 | + $this->get_subscription_merge_tags( $object ) |
|
80 | + ); |
|
81 | + } |
|
204 | 82 | |
205 | - } |
|
83 | + return $merge_tags; |
|
206 | 84 | |
207 | - /** |
|
208 | - * Sends a cancelled subscription notification. |
|
209 | - * |
|
210 | - * @param WPInv_Subscription $subscription |
|
211 | - */ |
|
212 | - public function subscription_cancelled( $subscription ) { |
|
85 | + } |
|
213 | 86 | |
214 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
215 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
87 | + /** |
|
88 | + * Generates subscription merge tags. |
|
89 | + * |
|
90 | + * @param WPInv_Subscription $subscription |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function get_subscription_merge_tags( $subscription ) { |
|
94 | + |
|
95 | + // Abort if it does not exist. |
|
96 | + if ( ! $subscription->get_id() ) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | + return array( |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | + '{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ), |
|
108 | + '{subscription_initial_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | + ); |
|
216 | 113 | |
217 | - } |
|
114 | + } |
|
218 | 115 | |
219 | - /** |
|
220 | - * Sends a subscription expired notification. |
|
221 | - * |
|
222 | - * @param WPInv_Subscription $subscription |
|
223 | - */ |
|
224 | - public function subscription_expired( $subscription ) { |
|
116 | + /** |
|
117 | + * Checks if we should send a notification for a subscription. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function should_send_notification( $invoice ) { |
|
123 | + return 0 != $invoice->get_id(); |
|
124 | + } |
|
225 | 125 | |
226 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
227 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
126 | + /** |
|
127 | + * Returns notification recipients. |
|
128 | + * |
|
129 | + * @param WPInv_Invoice $invoice |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function get_recipients( $invoice ) { |
|
133 | + $recipients = array( $invoice->get_email() ); |
|
228 | 134 | |
229 | - } |
|
135 | + $cc = $invoice->get_email_cc(); |
|
230 | 136 | |
231 | - /** |
|
232 | - * Sends a completed subscription notification. |
|
233 | - * |
|
234 | - * @param WPInv_Subscription $subscription |
|
235 | - */ |
|
236 | - public function subscription_complete( $subscription ) { |
|
137 | + if ( ! empty( $cc ) ) { |
|
138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | + } |
|
237 | 141 | |
238 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
239 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
142 | + return $recipients; |
|
143 | + } |
|
240 | 144 | |
241 | - } |
|
145 | + /** |
|
146 | + * Helper function to send an email. |
|
147 | + * |
|
148 | + * @param WPInv_Subscription $subscription |
|
149 | + * @param GetPaid_Notification_Email $email |
|
150 | + * @param string $type |
|
151 | + * @param array $extra_args Extra template args. |
|
152 | + */ |
|
153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | + |
|
155 | + // Abort in case the parent invoice does not exist. |
|
156 | + $invoice = $subscription->get_parent_invoice(); |
|
157 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | + return; |
|
159 | + } |
|
160 | + |
|
161 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
162 | + |
|
163 | + $recipients = $this->get_recipients( $invoice ); |
|
164 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
165 | + $merge_tags = $email->get_merge_tags(); |
|
166 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
167 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
168 | + $attachments = $email->get_attachments(); |
|
169 | + |
|
170 | + $result = $mailer->send( |
|
171 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
172 | + $subject, |
|
173 | + $content, |
|
174 | + $attachments |
|
175 | + ); |
|
176 | + |
|
177 | + // Maybe send a copy to the admin. |
|
178 | + if ( $email->include_admin_bcc() ) { |
|
179 | + $mailer->send( |
|
180 | + wpinv_get_admin_email(), |
|
181 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
182 | + $content, |
|
183 | + $attachments |
|
184 | + ); |
|
185 | + } |
|
186 | + |
|
187 | + if ( ! $result ) { |
|
188 | + $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
189 | + } |
|
190 | + |
|
191 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
242 | 192 | |
243 | - /** |
|
244 | - * Sends a subscription renewal reminder notification. |
|
245 | - * |
|
246 | - */ |
|
247 | - public function renewal_reminder() { |
|
193 | + } |
|
248 | 194 | |
249 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
195 | + /** |
|
196 | + * Sends a new trial notification. |
|
197 | + * |
|
198 | + * @param WPInv_Subscription $subscription |
|
199 | + */ |
|
200 | + public function subscription_trial( $subscription ) { |
|
250 | 201 | |
251 | - // Fetch reminder days. |
|
252 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
202 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
203 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
253 | 204 | |
254 | - // Abort if non is set. |
|
255 | - if ( empty( $reminder_days ) ) { |
|
256 | - return; |
|
257 | - } |
|
205 | + } |
|
258 | 206 | |
259 | - // Fetch matching subscriptions. |
|
207 | + /** |
|
208 | + * Sends a cancelled subscription notification. |
|
209 | + * |
|
210 | + * @param WPInv_Subscription $subscription |
|
211 | + */ |
|
212 | + public function subscription_cancelled( $subscription ) { |
|
213 | + |
|
214 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
215 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Sends a subscription expired notification. |
|
221 | + * |
|
222 | + * @param WPInv_Subscription $subscription |
|
223 | + */ |
|
224 | + public function subscription_expired( $subscription ) { |
|
225 | + |
|
226 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
227 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
228 | + |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Sends a completed subscription notification. |
|
233 | + * |
|
234 | + * @param WPInv_Subscription $subscription |
|
235 | + */ |
|
236 | + public function subscription_complete( $subscription ) { |
|
237 | + |
|
238 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
239 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Sends a subscription renewal reminder notification. |
|
245 | + * |
|
246 | + */ |
|
247 | + public function renewal_reminder() { |
|
248 | + |
|
249 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
250 | + |
|
251 | + // Fetch reminder days. |
|
252 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
253 | + |
|
254 | + // Abort if non is set. |
|
255 | + if ( empty( $reminder_days ) ) { |
|
256 | + return; |
|
257 | + } |
|
258 | + |
|
259 | + // Fetch matching subscriptions. |
|
260 | 260 | $args = array( |
261 | 261 | 'number' => -1, |
262 | - 'count_total' => false, |
|
263 | - 'status' => 'trialling active', |
|
262 | + 'count_total' => false, |
|
263 | + 'status' => 'trialling active', |
|
264 | 264 | 'date_expires_query' => array( |
265 | - 'relation' => 'OR' |
|
265 | + 'relation' => 'OR' |
|
266 | 266 | ), |
267 | - ); |
|
267 | + ); |
|
268 | 268 | |
269 | - foreach ( $reminder_days as $days ) { |
|
270 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
269 | + foreach ( $reminder_days as $days ) { |
|
270 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
271 | 271 | |
272 | - $args['date_expires_query'][] = array( |
|
273 | - 'year' => $date['year'], |
|
274 | - 'month' => $date['month'], |
|
275 | - 'day' => $date['day'], |
|
276 | - ); |
|
272 | + $args['date_expires_query'][] = array( |
|
273 | + 'year' => $date['year'], |
|
274 | + 'month' => $date['month'], |
|
275 | + 'day' => $date['day'], |
|
276 | + ); |
|
277 | 277 | |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
280 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
281 | 281 | |
282 | 282 | foreach ( $subscriptions as $subscription ) { |
283 | 283 | |
284 | - // Skip packages. |
|
285 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
286 | - $email->object = $subscription; |
|
287 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
288 | - } |
|
284 | + // Skip packages. |
|
285 | + if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
286 | + $email->object = $subscription; |
|
287 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
288 | + } |
|
289 | 289 | |
290 | - } |
|
290 | + } |
|
291 | 291 | |
292 | - } |
|
292 | + } |
|
293 | 293 | |
294 | 294 | } |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | */ |
82 | 82 | function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
83 | 83 | |
84 | - $invoice_statuses = array( |
|
85 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
84 | + $invoice_statuses = array( |
|
85 | + 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
86 | 86 | 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
87 | 87 | 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
88 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
89 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
90 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
88 | + 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
89 | + 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
90 | + 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
91 | 91 | 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
92 | 92 | 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
93 | 93 | ); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $invoice = $invoice->get_post_type(); |
105 | 105 | } |
106 | 106 | |
107 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
107 | + return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -222,25 +222,25 @@ discard block |
||
222 | 222 | * @return string |
223 | 223 | */ |
224 | 224 | function getpaid_get_price_format() { |
225 | - $currency_pos = wpinv_currency_position(); |
|
226 | - $format = '%1$s%2$s'; |
|
225 | + $currency_pos = wpinv_currency_position(); |
|
226 | + $format = '%1$s%2$s'; |
|
227 | 227 | |
228 | - switch ( $currency_pos ) { |
|
229 | - case 'left': |
|
230 | - $format = '%1$s%2$s'; |
|
231 | - break; |
|
232 | - case 'right': |
|
233 | - $format = '%2$s%1$s'; |
|
234 | - break; |
|
235 | - case 'left_space': |
|
236 | - $format = '%1$s %2$s'; |
|
237 | - break; |
|
238 | - case 'right_space': |
|
239 | - $format = '%2$s %1$s'; |
|
240 | - break; |
|
241 | - } |
|
228 | + switch ( $currency_pos ) { |
|
229 | + case 'left': |
|
230 | + $format = '%1$s%2$s'; |
|
231 | + break; |
|
232 | + case 'right': |
|
233 | + $format = '%2$s%1$s'; |
|
234 | + break; |
|
235 | + case 'left_space': |
|
236 | + $format = '%1$s %2$s'; |
|
237 | + break; |
|
238 | + case 'right_space': |
|
239 | + $format = '%2$s %1$s'; |
|
240 | + break; |
|
241 | + } |
|
242 | 242 | |
243 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
243 | + return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -343,13 +343,13 @@ discard block |
||
343 | 343 | * @param mixed $value Value. |
344 | 344 | */ |
345 | 345 | function getpaid_maybe_define_constant( $name, $value ) { |
346 | - if ( ! defined( $name ) ) { |
|
347 | - define( $name, $value ); |
|
348 | - } |
|
346 | + if ( ! defined( $name ) ) { |
|
347 | + define( $name, $value ); |
|
348 | + } |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | function wpinv_get_php_arg_separator_output() { |
352 | - return ini_get( 'arg_separator.output' ); |
|
352 | + return ini_get( 'arg_separator.output' ); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | function wpinv_rgb_from_hex( $color ) { |
@@ -700,11 +700,11 @@ discard block |
||
700 | 700 | $list = array(); |
701 | 701 | } |
702 | 702 | |
703 | - if ( ! is_array( $list ) ) { |
|
704 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
705 | - } |
|
703 | + if ( ! is_array( $list ) ) { |
|
704 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
705 | + } |
|
706 | 706 | |
707 | - return $list; |
|
707 | + return $list; |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | /** |
@@ -724,9 +724,9 @@ discard block |
||
724 | 724 | } |
725 | 725 | |
726 | 726 | $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
727 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
727 | + wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
728 | 728 | |
729 | - return $data; |
|
729 | + return $data; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | /** |
@@ -755,17 +755,17 @@ discard block |
||
755 | 755 | */ |
756 | 756 | function wpinv_clean( $var ) { |
757 | 757 | |
758 | - if ( is_array( $var ) ) { |
|
759 | - return array_map( 'wpinv_clean', $var ); |
|
758 | + if ( is_array( $var ) ) { |
|
759 | + return array_map( 'wpinv_clean', $var ); |
|
760 | 760 | } |
761 | 761 | |
762 | 762 | if ( is_object( $var ) ) { |
763 | - $object_vars = get_object_vars( $var ); |
|
764 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
765 | - $var->$property_name = wpinv_clean( $property_value ); |
|
763 | + $object_vars = get_object_vars( $var ); |
|
764 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
765 | + $var->$property_name = wpinv_clean( $property_value ); |
|
766 | 766 | } |
767 | 767 | return $var; |
768 | - } |
|
768 | + } |
|
769 | 769 | |
770 | 770 | return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
771 | 771 | } |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | */ |
779 | 779 | function getpaid_convert_price_string_to_options( $str ) { |
780 | 780 | |
781 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
781 | + $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
782 | 782 | $options = array(); |
783 | 783 | |
784 | 784 | foreach ( $raw_options as $option ) { |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | * @return string |
857 | 857 | */ |
858 | 858 | function getpaid_date_format() { |
859 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
859 | + return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | /** |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | * @return string |
866 | 866 | */ |
867 | 867 | function getpaid_time_format() { |
868 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
868 | + return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | /** |
@@ -878,15 +878,15 @@ discard block |
||
878 | 878 | function getpaid_limit_length( $string, $limit ) { |
879 | 879 | $str_limit = $limit - 3; |
880 | 880 | |
881 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
882 | - if ( mb_strlen( $string ) > $limit ) { |
|
883 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
884 | - } |
|
885 | - } else { |
|
886 | - if ( strlen( $string ) > $limit ) { |
|
887 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
888 | - } |
|
889 | - } |
|
881 | + if ( function_exists( 'mb_strimwidth' ) ) { |
|
882 | + if ( mb_strlen( $string ) > $limit ) { |
|
883 | + $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
884 | + } |
|
885 | + } else { |
|
886 | + if ( strlen( $string ) > $limit ) { |
|
887 | + $string = substr( $string, 0, $str_limit ) . '...'; |
|
888 | + } |
|
889 | + } |
|
890 | 890 | return $string; |
891 | 891 | |
892 | 892 | } |
@@ -14,500 +14,500 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax instance. |
|
40 | - * |
|
41 | - * @var WPInv_EUVat |
|
42 | - */ |
|
43 | - public $tax; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array An array of payment gateways. |
|
47 | - */ |
|
48 | - public $gateways; |
|
49 | - |
|
50 | - /** |
|
51 | - * Class constructor. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - $this->define_constants(); |
|
55 | - $this->includes(); |
|
56 | - $this->init_hooks(); |
|
57 | - $this->set_properties(); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets a custom data property. |
|
62 | - * |
|
63 | - * @param string $prop The prop to set. |
|
64 | - * @param mixed $value The value to retrieve. |
|
65 | - */ |
|
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Gets a custom data property. |
|
72 | - * |
|
73 | - * @param string $prop The prop to set. |
|
74 | - * @return mixed The value. |
|
75 | - */ |
|
76 | - public function get( $prop ) { |
|
77 | - |
|
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
80 | - } |
|
81 | - |
|
82 | - return null; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Define class properties. |
|
87 | - */ |
|
88 | - public function set_properties() { |
|
89 | - |
|
90 | - // Sessions. |
|
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | - $this->tax = new WPInv_EUVat(); |
|
94 | - $this->tax->init(); |
|
95 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | - |
|
97 | - // Init other objects. |
|
98 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | - $this->set( 'notes', new WPInv_Notes() ); |
|
101 | - $this->set( 'api', new WPInv_API() ); |
|
102 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | - $this->set( 'template', new GetPaid_Template() ); |
|
104 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | - |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Define plugin constants. |
|
115 | - */ |
|
116 | - public function define_constants() { |
|
117 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | - $this->version = WPINV_VERSION; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Hook into actions and filters. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - */ |
|
127 | - protected function init_hooks() { |
|
128 | - /* Internationalize the text strings used. */ |
|
129 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | - |
|
131 | - // Init the plugin after WordPress inits. |
|
132 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
134 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
135 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | - |
|
137 | - if ( class_exists( 'BuddyPress' ) ) { |
|
138 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | - } |
|
140 | - |
|
141 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | - |
|
147 | - // Fires after registering actions. |
|
148 | - do_action( 'wpinv_actions', $this ); |
|
149 | - do_action( 'getpaid_actions', $this ); |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - public function plugins_loaded() { |
|
154 | - /* Internationalize the text strings used. */ |
|
155 | - $this->load_textdomain(); |
|
156 | - |
|
157 | - do_action( 'wpinv_loaded' ); |
|
158 | - |
|
159 | - // Fix oxygen page builder conflict |
|
160 | - if ( function_exists( 'ct_css_output' ) ) { |
|
161 | - wpinv_oxygen_fix_conflict(); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Load the translation of the plugin. |
|
167 | - * |
|
168 | - * @since 1.0 |
|
169 | - */ |
|
170 | - public function load_textdomain( $locale = NULL ) { |
|
171 | - if ( empty( $locale ) ) { |
|
172 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | - } |
|
174 | - |
|
175 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | - |
|
177 | - unload_textdomain( 'invoicing' ); |
|
178 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | - |
|
181 | - /** |
|
182 | - * Define language constants. |
|
183 | - */ |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Include required core files used in admin and on the frontend. |
|
189 | - */ |
|
190 | - public function includes() { |
|
191 | - |
|
192 | - // Start with the settings. |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | - |
|
195 | - // Packages/libraries. |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | - |
|
199 | - // Load functions. |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | - |
|
216 | - // Register autoloader. |
|
217 | - try { |
|
218 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | - } catch ( Exception $e ) { |
|
220 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | - } |
|
222 | - |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | - |
|
245 | - /** |
|
246 | - * Load the tax class. |
|
247 | - */ |
|
248 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | - } |
|
251 | - |
|
252 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | - GetPaid_Post_Types_Admin::init(); |
|
254 | - |
|
255 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | - // load the user class only on the users.php page |
|
264 | - global $pagenow; |
|
265 | - if($pagenow=='users.php'){ |
|
266 | - new WPInv_Admin_Users(); |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - // Register cli commands |
|
271 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | - } |
|
275 | - |
|
276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Class autoloader |
|
281 | - * |
|
282 | - * @param string $class_name The name of the class to load. |
|
283 | - * @access public |
|
284 | - * @since 1.0.19 |
|
285 | - * @return void |
|
286 | - */ |
|
287 | - public function autoload( $class_name ) { |
|
288 | - |
|
289 | - // Normalize the class name... |
|
290 | - $class_name = strtolower( $class_name ); |
|
291 | - |
|
292 | - // ... and make sure it is our class. |
|
293 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | - return; |
|
295 | - } |
|
296 | - |
|
297 | - // Next, prepare the file name from the class. |
|
298 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | - |
|
300 | - // Base path of the classes. |
|
301 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | - |
|
303 | - // And an array of possible locations in order of importance. |
|
304 | - $locations = array( |
|
305 | - "$plugin_path/includes", |
|
306 | - "$plugin_path/includes/data-stores", |
|
307 | - "$plugin_path/includes/gateways", |
|
308 | - "$plugin_path/includes/payments", |
|
309 | - "$plugin_path/includes/api", |
|
310 | - "$plugin_path/includes/admin", |
|
311 | - "$plugin_path/includes/admin/meta-boxes", |
|
312 | - ); |
|
313 | - |
|
314 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
315 | - |
|
316 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
317 | - include trailingslashit( $location ) . $file_name; |
|
318 | - break; |
|
319 | - } |
|
320 | - |
|
321 | - } |
|
322 | - |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Inits hooks etc. |
|
327 | - */ |
|
328 | - public function init() { |
|
329 | - |
|
330 | - // Fires before getpaid inits. |
|
331 | - do_action( 'before_getpaid_init', $this ); |
|
332 | - |
|
333 | - // Load default gateways. |
|
334 | - $gateways = apply_filters( |
|
335 | - 'getpaid_default_gateways', |
|
336 | - array( |
|
337 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
338 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
339 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
340 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
341 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
342 | - ) |
|
343 | - ); |
|
344 | - |
|
345 | - foreach ( $gateways as $id => $class ) { |
|
346 | - $this->gateways[ $id ] = new $class(); |
|
347 | - } |
|
348 | - |
|
349 | - // Fires after getpaid inits. |
|
350 | - do_action( 'getpaid_init', $this ); |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Checks if this is an IPN request and processes it. |
|
356 | - */ |
|
357 | - public function maybe_process_ipn() { |
|
358 | - |
|
359 | - // Ensure that this is an IPN request. |
|
360 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
361 | - return; |
|
362 | - } |
|
363 | - |
|
364 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
365 | - |
|
366 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
367 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
368 | - exit; |
|
369 | - |
|
370 | - } |
|
371 | - |
|
372 | - public function enqueue_scripts() { |
|
373 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
374 | - |
|
375 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
376 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
377 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
378 | - |
|
379 | - // Register scripts |
|
380 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
381 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
382 | - |
|
383 | - $localize = array(); |
|
384 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
385 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
386 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
387 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
388 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
389 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
390 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax instance. |
|
40 | + * |
|
41 | + * @var WPInv_EUVat |
|
42 | + */ |
|
43 | + public $tax; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array An array of payment gateways. |
|
47 | + */ |
|
48 | + public $gateways; |
|
49 | + |
|
50 | + /** |
|
51 | + * Class constructor. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + $this->define_constants(); |
|
55 | + $this->includes(); |
|
56 | + $this->init_hooks(); |
|
57 | + $this->set_properties(); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets a custom data property. |
|
62 | + * |
|
63 | + * @param string $prop The prop to set. |
|
64 | + * @param mixed $value The value to retrieve. |
|
65 | + */ |
|
66 | + public function set( $prop, $value ) { |
|
67 | + $this->data[ $prop ] = $value; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Gets a custom data property. |
|
72 | + * |
|
73 | + * @param string $prop The prop to set. |
|
74 | + * @return mixed The value. |
|
75 | + */ |
|
76 | + public function get( $prop ) { |
|
77 | + |
|
78 | + if ( isset( $this->data[ $prop ] ) ) { |
|
79 | + return $this->data[ $prop ]; |
|
80 | + } |
|
81 | + |
|
82 | + return null; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Define class properties. |
|
87 | + */ |
|
88 | + public function set_properties() { |
|
89 | + |
|
90 | + // Sessions. |
|
91 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | + $this->tax = new WPInv_EUVat(); |
|
94 | + $this->tax->init(); |
|
95 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | + |
|
97 | + // Init other objects. |
|
98 | + $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | + $this->set( 'notes', new WPInv_Notes() ); |
|
101 | + $this->set( 'api', new WPInv_API() ); |
|
102 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | + $this->set( 'template', new GetPaid_Template() ); |
|
104 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | + |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Define plugin constants. |
|
115 | + */ |
|
116 | + public function define_constants() { |
|
117 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | + $this->version = WPINV_VERSION; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Hook into actions and filters. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + */ |
|
127 | + protected function init_hooks() { |
|
128 | + /* Internationalize the text strings used. */ |
|
129 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | + |
|
131 | + // Init the plugin after WordPress inits. |
|
132 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
134 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
135 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | + |
|
137 | + if ( class_exists( 'BuddyPress' ) ) { |
|
138 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | + } |
|
140 | + |
|
141 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | + |
|
147 | + // Fires after registering actions. |
|
148 | + do_action( 'wpinv_actions', $this ); |
|
149 | + do_action( 'getpaid_actions', $this ); |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + public function plugins_loaded() { |
|
154 | + /* Internationalize the text strings used. */ |
|
155 | + $this->load_textdomain(); |
|
156 | + |
|
157 | + do_action( 'wpinv_loaded' ); |
|
158 | + |
|
159 | + // Fix oxygen page builder conflict |
|
160 | + if ( function_exists( 'ct_css_output' ) ) { |
|
161 | + wpinv_oxygen_fix_conflict(); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Load the translation of the plugin. |
|
167 | + * |
|
168 | + * @since 1.0 |
|
169 | + */ |
|
170 | + public function load_textdomain( $locale = NULL ) { |
|
171 | + if ( empty( $locale ) ) { |
|
172 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | + } |
|
174 | + |
|
175 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | + |
|
177 | + unload_textdomain( 'invoicing' ); |
|
178 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | + |
|
181 | + /** |
|
182 | + * Define language constants. |
|
183 | + */ |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Include required core files used in admin and on the frontend. |
|
189 | + */ |
|
190 | + public function includes() { |
|
191 | + |
|
192 | + // Start with the settings. |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | + |
|
195 | + // Packages/libraries. |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | + |
|
199 | + // Load functions. |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | + |
|
216 | + // Register autoloader. |
|
217 | + try { |
|
218 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | + } catch ( Exception $e ) { |
|
220 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | + } |
|
222 | + |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | + |
|
245 | + /** |
|
246 | + * Load the tax class. |
|
247 | + */ |
|
248 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | + } |
|
251 | + |
|
252 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | + GetPaid_Post_Types_Admin::init(); |
|
254 | + |
|
255 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | + // load the user class only on the users.php page |
|
264 | + global $pagenow; |
|
265 | + if($pagenow=='users.php'){ |
|
266 | + new WPInv_Admin_Users(); |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + // Register cli commands |
|
271 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | + } |
|
275 | + |
|
276 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | + } |
|
391 | 278 | |
392 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
393 | - |
|
394 | - wp_enqueue_script( 'jquery-blockui' ); |
|
279 | + /** |
|
280 | + * Class autoloader |
|
281 | + * |
|
282 | + * @param string $class_name The name of the class to load. |
|
283 | + * @access public |
|
284 | + * @since 1.0.19 |
|
285 | + * @return void |
|
286 | + */ |
|
287 | + public function autoload( $class_name ) { |
|
288 | + |
|
289 | + // Normalize the class name... |
|
290 | + $class_name = strtolower( $class_name ); |
|
291 | + |
|
292 | + // ... and make sure it is our class. |
|
293 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | + return; |
|
295 | + } |
|
296 | + |
|
297 | + // Next, prepare the file name from the class. |
|
298 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | + |
|
300 | + // Base path of the classes. |
|
301 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | + |
|
303 | + // And an array of possible locations in order of importance. |
|
304 | + $locations = array( |
|
305 | + "$plugin_path/includes", |
|
306 | + "$plugin_path/includes/data-stores", |
|
307 | + "$plugin_path/includes/gateways", |
|
308 | + "$plugin_path/includes/payments", |
|
309 | + "$plugin_path/includes/api", |
|
310 | + "$plugin_path/includes/admin", |
|
311 | + "$plugin_path/includes/admin/meta-boxes", |
|
312 | + ); |
|
313 | + |
|
314 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
315 | + |
|
316 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
317 | + include trailingslashit( $location ) . $file_name; |
|
318 | + break; |
|
319 | + } |
|
320 | + |
|
321 | + } |
|
322 | + |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Inits hooks etc. |
|
327 | + */ |
|
328 | + public function init() { |
|
329 | + |
|
330 | + // Fires before getpaid inits. |
|
331 | + do_action( 'before_getpaid_init', $this ); |
|
332 | + |
|
333 | + // Load default gateways. |
|
334 | + $gateways = apply_filters( |
|
335 | + 'getpaid_default_gateways', |
|
336 | + array( |
|
337 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
338 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
339 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
340 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
341 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
342 | + ) |
|
343 | + ); |
|
344 | + |
|
345 | + foreach ( $gateways as $id => $class ) { |
|
346 | + $this->gateways[ $id ] = new $class(); |
|
347 | + } |
|
348 | + |
|
349 | + // Fires after getpaid inits. |
|
350 | + do_action( 'getpaid_init', $this ); |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Checks if this is an IPN request and processes it. |
|
356 | + */ |
|
357 | + public function maybe_process_ipn() { |
|
358 | + |
|
359 | + // Ensure that this is an IPN request. |
|
360 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
361 | + return; |
|
362 | + } |
|
363 | + |
|
364 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
365 | + |
|
366 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
367 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
368 | + exit; |
|
369 | + |
|
370 | + } |
|
395 | 371 | |
396 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
397 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
372 | + public function enqueue_scripts() { |
|
373 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
398 | 374 | |
399 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
400 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
401 | - |
|
402 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
403 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
404 | - } |
|
405 | - |
|
406 | - public function wpinv_actions() { |
|
407 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
408 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
409 | - } |
|
410 | - } |
|
375 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
376 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
377 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
411 | 378 | |
412 | - /** |
|
379 | + // Register scripts |
|
380 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
381 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
382 | + |
|
383 | + $localize = array(); |
|
384 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
385 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
386 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
387 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
388 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
389 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
390 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
391 | + |
|
392 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
393 | + |
|
394 | + wp_enqueue_script( 'jquery-blockui' ); |
|
395 | + |
|
396 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
397 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
398 | + |
|
399 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
400 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
401 | + |
|
402 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
403 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
404 | + } |
|
405 | + |
|
406 | + public function wpinv_actions() { |
|
407 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
408 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | 413 | * Fires an action after verifying that a user can fire them. |
414 | - * |
|
415 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
416 | - * current user owns the invoice/subscription. |
|
414 | + * |
|
415 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
416 | + * current user owns the invoice/subscription. |
|
417 | 417 | */ |
418 | 418 | public function maybe_do_authenticated_action() { |
419 | 419 | |
420 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
420 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
421 | 421 | |
422 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
423 | - if ( is_user_logged_in() ) { |
|
424 | - do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
425 | - } |
|
422 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
423 | + if ( is_user_logged_in() ) { |
|
424 | + do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
425 | + } |
|
426 | 426 | |
427 | - do_action( "getpaid_unauthenticated_action_$key", $_REQUEST ); |
|
427 | + do_action( "getpaid_unauthenticated_action_$key", $_REQUEST ); |
|
428 | 428 | |
429 | - } |
|
429 | + } |
|
430 | 430 | |
431 | 431 | |
432 | 432 | } |
433 | 433 | |
434 | - public function pre_get_posts( $wp_query ) { |
|
435 | - |
|
436 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
437 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
438 | - } |
|
439 | - |
|
440 | - return $wp_query; |
|
441 | - } |
|
442 | - |
|
443 | - public function bp_invoicing_init() { |
|
444 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Register widgets |
|
449 | - * |
|
450 | - */ |
|
451 | - public function register_widgets() { |
|
452 | - $widgets = apply_filters( |
|
453 | - 'getpaid_widget_classes', |
|
454 | - array( |
|
455 | - 'WPInv_Checkout_Widget', |
|
456 | - 'WPInv_History_Widget', |
|
457 | - 'WPInv_Receipt_Widget', |
|
458 | - 'WPInv_Subscriptions_Widget', |
|
459 | - 'WPInv_Buy_Item_Widget', |
|
460 | - 'WPInv_Messages_Widget', |
|
461 | - 'WPInv_GetPaid_Widget' |
|
462 | - ) |
|
463 | - ); |
|
464 | - |
|
465 | - foreach ( $widgets as $widget ) { |
|
466 | - register_widget( $widget ); |
|
467 | - } |
|
434 | + public function pre_get_posts( $wp_query ) { |
|
435 | + |
|
436 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
437 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
438 | + } |
|
439 | + |
|
440 | + return $wp_query; |
|
441 | + } |
|
442 | + |
|
443 | + public function bp_invoicing_init() { |
|
444 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Register widgets |
|
449 | + * |
|
450 | + */ |
|
451 | + public function register_widgets() { |
|
452 | + $widgets = apply_filters( |
|
453 | + 'getpaid_widget_classes', |
|
454 | + array( |
|
455 | + 'WPInv_Checkout_Widget', |
|
456 | + 'WPInv_History_Widget', |
|
457 | + 'WPInv_Receipt_Widget', |
|
458 | + 'WPInv_Subscriptions_Widget', |
|
459 | + 'WPInv_Buy_Item_Widget', |
|
460 | + 'WPInv_Messages_Widget', |
|
461 | + 'WPInv_GetPaid_Widget' |
|
462 | + ) |
|
463 | + ); |
|
464 | + |
|
465 | + foreach ( $widgets as $widget ) { |
|
466 | + register_widget( $widget ); |
|
467 | + } |
|
468 | 468 | |
469 | - } |
|
469 | + } |
|
470 | 470 | |
471 | - /** |
|
472 | - * Remove our pages from yoast sitemaps. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - * @param int[] $excluded_posts_ids |
|
476 | - */ |
|
477 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
471 | + /** |
|
472 | + * Remove our pages from yoast sitemaps. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + * @param int[] $excluded_posts_ids |
|
476 | + */ |
|
477 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
478 | 478 | |
479 | - // Ensure that we have an array. |
|
480 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
481 | - $excluded_posts_ids = array(); |
|
482 | - } |
|
479 | + // Ensure that we have an array. |
|
480 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
481 | + $excluded_posts_ids = array(); |
|
482 | + } |
|
483 | 483 | |
484 | - // Prepare our pages. |
|
485 | - $our_pages = array(); |
|
484 | + // Prepare our pages. |
|
485 | + $our_pages = array(); |
|
486 | 486 | |
487 | - // Checkout page. |
|
488 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
487 | + // Checkout page. |
|
488 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
489 | 489 | |
490 | - // Success page. |
|
491 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
490 | + // Success page. |
|
491 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
492 | 492 | |
493 | - // Failure page. |
|
494 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
493 | + // Failure page. |
|
494 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
495 | 495 | |
496 | - // History page. |
|
497 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
496 | + // History page. |
|
497 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
498 | 498 | |
499 | - // Subscriptions page. |
|
500 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
499 | + // Subscriptions page. |
|
500 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
501 | 501 | |
502 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
502 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
503 | 503 | |
504 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
505 | - return array_unique( $excluded_posts_ids ); |
|
504 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
505 | + return array_unique( $excluded_posts_ids ); |
|
506 | 506 | |
507 | - } |
|
507 | + } |
|
508 | 508 | |
509 | - public function wp_footer() { |
|
510 | - echo ' |
|
509 | + public function wp_footer() { |
|
510 | + echo ' |
|
511 | 511 | <div class="bsui"> |
512 | 512 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
513 | 513 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -518,6 +518,6 @@ discard block |
||
518 | 518 | </div> |
519 | 519 | </div> |
520 | 520 | '; |
521 | - } |
|
521 | + } |
|
522 | 522 | |
523 | 523 | } |
@@ -12,443 +12,443 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
52 | - |
|
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
129 | - return array( |
|
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | - ); |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Helper function to send an email. |
|
154 | - * |
|
155 | - * @param WPInv_Invoice $invoice |
|
156 | - * @param GetPaid_Notification_Email $email |
|
157 | - * @param string $type |
|
158 | - * @param string|array $recipients |
|
159 | - * @param array $extra_args Extra template args. |
|
160 | - */ |
|
161 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
162 | - |
|
163 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
164 | - |
|
165 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
166 | - $merge_tags = $email->get_merge_tags(); |
|
167 | - |
|
168 | - $result = $mailer->send( |
|
169 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
170 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
171 | - $email->get_content( $merge_tags, $extra_args ), |
|
172 | - $email->get_attachments() |
|
173 | - ); |
|
174 | - |
|
175 | - // Maybe send a copy to the admin. |
|
176 | - if ( $email->include_admin_bcc() ) { |
|
177 | - $mailer->send( |
|
178 | - wpinv_get_admin_email(), |
|
179 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
180 | - $email->get_content( $merge_tags ), |
|
181 | - $email->get_attachments() |
|
182 | - ); |
|
183 | - } |
|
184 | - |
|
185 | - if ( ! $result ) { |
|
186 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
187 | - } |
|
188 | - |
|
189 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
190 | - |
|
191 | - return $result; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Also send emails to any cc users. |
|
196 | - * |
|
197 | - * @param array $recipients |
|
198 | - * @param GetPaid_Notification_Email $email |
|
199 | - */ |
|
200 | - public function filter_email_recipients( $recipients, $email ) { |
|
201 | - |
|
202 | - if ( ! $email->is_admin_email() ) { |
|
203 | - $cc = $email->object->get_email_cc(); |
|
204 | - |
|
205 | - if ( ! empty( $cc ) ) { |
|
206 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
207 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
208 | - } |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - return $recipients; |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Sends a new invoice notification. |
|
218 | - * |
|
219 | - * @param WPInv_Invoice $invoice |
|
220 | - */ |
|
221 | - public function new_invoice( $invoice ) { |
|
222 | - |
|
223 | - // Only send this email for invoices created via the admin page. |
|
224 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
225 | - return; |
|
226 | - } |
|
227 | - |
|
228 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
229 | - $recipient = wpinv_get_admin_email(); |
|
230 | - |
|
231 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
232 | - |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Sends a cancelled invoice notification. |
|
237 | - * |
|
238 | - * @param WPInv_Invoice $invoice |
|
239 | - */ |
|
240 | - public function cancelled_invoice( $invoice ) { |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
52 | + |
|
53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
129 | + return array( |
|
130 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | + '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
138 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | + '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | + '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
145 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | + ); |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Helper function to send an email. |
|
154 | + * |
|
155 | + * @param WPInv_Invoice $invoice |
|
156 | + * @param GetPaid_Notification_Email $email |
|
157 | + * @param string $type |
|
158 | + * @param string|array $recipients |
|
159 | + * @param array $extra_args Extra template args. |
|
160 | + */ |
|
161 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
162 | + |
|
163 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
164 | + |
|
165 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
166 | + $merge_tags = $email->get_merge_tags(); |
|
167 | + |
|
168 | + $result = $mailer->send( |
|
169 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
170 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
171 | + $email->get_content( $merge_tags, $extra_args ), |
|
172 | + $email->get_attachments() |
|
173 | + ); |
|
174 | + |
|
175 | + // Maybe send a copy to the admin. |
|
176 | + if ( $email->include_admin_bcc() ) { |
|
177 | + $mailer->send( |
|
178 | + wpinv_get_admin_email(), |
|
179 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
180 | + $email->get_content( $merge_tags ), |
|
181 | + $email->get_attachments() |
|
182 | + ); |
|
183 | + } |
|
184 | + |
|
185 | + if ( ! $result ) { |
|
186 | + $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
187 | + } |
|
188 | + |
|
189 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
190 | + |
|
191 | + return $result; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Also send emails to any cc users. |
|
196 | + * |
|
197 | + * @param array $recipients |
|
198 | + * @param GetPaid_Notification_Email $email |
|
199 | + */ |
|
200 | + public function filter_email_recipients( $recipients, $email ) { |
|
201 | + |
|
202 | + if ( ! $email->is_admin_email() ) { |
|
203 | + $cc = $email->object->get_email_cc(); |
|
204 | + |
|
205 | + if ( ! empty( $cc ) ) { |
|
206 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
207 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
208 | + } |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + return $recipients; |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Sends a new invoice notification. |
|
218 | + * |
|
219 | + * @param WPInv_Invoice $invoice |
|
220 | + */ |
|
221 | + public function new_invoice( $invoice ) { |
|
222 | + |
|
223 | + // Only send this email for invoices created via the admin page. |
|
224 | + if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | + |
|
228 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
229 | + $recipient = wpinv_get_admin_email(); |
|
230 | + |
|
231 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
232 | + |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Sends a cancelled invoice notification. |
|
237 | + * |
|
238 | + * @param WPInv_Invoice $invoice |
|
239 | + */ |
|
240 | + public function cancelled_invoice( $invoice ) { |
|
241 | 241 | |
242 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
243 | - $recipient = wpinv_get_admin_email(); |
|
242 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
243 | + $recipient = wpinv_get_admin_email(); |
|
244 | 244 | |
245 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
245 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Sends a failed invoice notification. |
|
251 | - * |
|
252 | - * @param WPInv_Invoice $invoice |
|
253 | - */ |
|
254 | - public function failed_invoice( $invoice ) { |
|
249 | + /** |
|
250 | + * Sends a failed invoice notification. |
|
251 | + * |
|
252 | + * @param WPInv_Invoice $invoice |
|
253 | + */ |
|
254 | + public function failed_invoice( $invoice ) { |
|
255 | 255 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
257 | - $recipient = wpinv_get_admin_email(); |
|
256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
257 | + $recipient = wpinv_get_admin_email(); |
|
258 | 258 | |
259 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
259 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
260 | 260 | |
261 | - } |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * Sends a notification whenever an invoice is put on hold. |
|
265 | - * |
|
266 | - * @param WPInv_Invoice $invoice |
|
267 | - */ |
|
268 | - public function onhold_invoice( $invoice ) { |
|
263 | + /** |
|
264 | + * Sends a notification whenever an invoice is put on hold. |
|
265 | + * |
|
266 | + * @param WPInv_Invoice $invoice |
|
267 | + */ |
|
268 | + public function onhold_invoice( $invoice ) { |
|
269 | 269 | |
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | - $recipient = $invoice->get_email(); |
|
270 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $recipient = $invoice->get_email(); |
|
272 | 272 | |
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
273 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | 274 | |
275 | - } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
279 | - * |
|
280 | - * @param WPInv_Invoice $invoice |
|
281 | - */ |
|
282 | - public function processing_invoice( $invoice ) { |
|
277 | + /** |
|
278 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
279 | + * |
|
280 | + * @param WPInv_Invoice $invoice |
|
281 | + */ |
|
282 | + public function processing_invoice( $invoice ) { |
|
283 | 283 | |
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | - $recipient = $invoice->get_email(); |
|
284 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $recipient = $invoice->get_email(); |
|
286 | 286 | |
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
287 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | 288 | |
289 | - } |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Sends a notification whenever an invoice is paid. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice |
|
295 | - */ |
|
296 | - public function completed_invoice( $invoice ) { |
|
291 | + /** |
|
292 | + * Sends a notification whenever an invoice is paid. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice |
|
295 | + */ |
|
296 | + public function completed_invoice( $invoice ) { |
|
297 | 297 | |
298 | - // (Maybe) abort if it is a renewal invoice. |
|
299 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
300 | - return; |
|
301 | - } |
|
298 | + // (Maybe) abort if it is a renewal invoice. |
|
299 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
300 | + return; |
|
301 | + } |
|
302 | 302 | |
303 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
304 | - $recipient = $invoice->get_email(); |
|
303 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
304 | + $recipient = $invoice->get_email(); |
|
305 | 305 | |
306 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
306 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
307 | 307 | |
308 | - } |
|
308 | + } |
|
309 | 309 | |
310 | - /** |
|
311 | - * Sends a notification whenever an invoice is refunded. |
|
312 | - * |
|
313 | - * @param WPInv_Invoice $invoice |
|
314 | - */ |
|
315 | - public function refunded_invoice( $invoice ) { |
|
310 | + /** |
|
311 | + * Sends a notification whenever an invoice is refunded. |
|
312 | + * |
|
313 | + * @param WPInv_Invoice $invoice |
|
314 | + */ |
|
315 | + public function refunded_invoice( $invoice ) { |
|
316 | 316 | |
317 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
318 | - $recipient = $invoice->get_email(); |
|
317 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
318 | + $recipient = $invoice->get_email(); |
|
319 | 319 | |
320 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
320 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
321 | 321 | |
322 | - } |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * Notifies a user about new invoices |
|
326 | - * |
|
327 | - * @param WPInv_Invoice $invoice |
|
328 | - */ |
|
329 | - public function user_invoice( $invoice ) { |
|
324 | + /** |
|
325 | + * Notifies a user about new invoices |
|
326 | + * |
|
327 | + * @param WPInv_Invoice $invoice |
|
328 | + */ |
|
329 | + public function user_invoice( $invoice ) { |
|
330 | 330 | |
331 | - // Only send this email for invoices created via the admin page. |
|
332 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
333 | - return; |
|
334 | - } |
|
331 | + // Only send this email for invoices created via the admin page. |
|
332 | + if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
333 | + return; |
|
334 | + } |
|
335 | 335 | |
336 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
337 | - $recipient = $invoice->get_email(); |
|
336 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
337 | + $recipient = $invoice->get_email(); |
|
338 | 338 | |
339 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
339 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
340 | 340 | |
341 | - } |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * Checks if an invoice is a payment form invoice. |
|
345 | - * |
|
346 | - * @param int $invoice |
|
347 | - * @return bool |
|
348 | - */ |
|
349 | - public function is_payment_form_invoice( $invoice ) { |
|
350 | - return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
351 | - } |
|
343 | + /** |
|
344 | + * Checks if an invoice is a payment form invoice. |
|
345 | + * |
|
346 | + * @param int $invoice |
|
347 | + * @return bool |
|
348 | + */ |
|
349 | + public function is_payment_form_invoice( $invoice ) { |
|
350 | + return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Notifies admin about new invoice notes |
|
355 | - * |
|
356 | - * @param WPInv_Invoice $invoice |
|
357 | - * @param string $note |
|
358 | - */ |
|
359 | - public function user_note( $invoice, $note ) { |
|
353 | + /** |
|
354 | + * Notifies admin about new invoice notes |
|
355 | + * |
|
356 | + * @param WPInv_Invoice $invoice |
|
357 | + * @param string $note |
|
358 | + */ |
|
359 | + public function user_note( $invoice, $note ) { |
|
360 | 360 | |
361 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
362 | - $recipient = $invoice->get_email(); |
|
363 | - |
|
364 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
365 | - |
|
366 | - } |
|
361 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
362 | + $recipient = $invoice->get_email(); |
|
363 | + |
|
364 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
365 | + |
|
366 | + } |
|
367 | 367 | |
368 | - /** |
|
369 | - * (Force) Sends overdue notices. |
|
370 | - * |
|
371 | - * @param WPInv_Invoice $invoice |
|
372 | - */ |
|
373 | - public function force_send_overdue_notice( $invoice ) { |
|
374 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
375 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Sends overdue notices. |
|
380 | - * |
|
381 | - * @TODO: Create an invoices query class. |
|
382 | - */ |
|
383 | - public function overdue() { |
|
384 | - global $wpdb; |
|
385 | - |
|
386 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
387 | - |
|
388 | - // Fetch reminder days. |
|
389 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
390 | - |
|
391 | - // Abort if non is set. |
|
392 | - if ( empty( $reminder_days ) ) { |
|
393 | - return; |
|
394 | - } |
|
395 | - |
|
396 | - // Retrieve date query. |
|
397 | - $date_query = $this->get_date_query( $reminder_days ); |
|
398 | - |
|
399 | - // Invoices table. |
|
400 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
401 | - |
|
402 | - // Fetch invoices. |
|
403 | - $invoices = $wpdb->get_col( |
|
404 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
368 | + /** |
|
369 | + * (Force) Sends overdue notices. |
|
370 | + * |
|
371 | + * @param WPInv_Invoice $invoice |
|
372 | + */ |
|
373 | + public function force_send_overdue_notice( $invoice ) { |
|
374 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
375 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Sends overdue notices. |
|
380 | + * |
|
381 | + * @TODO: Create an invoices query class. |
|
382 | + */ |
|
383 | + public function overdue() { |
|
384 | + global $wpdb; |
|
385 | + |
|
386 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
387 | + |
|
388 | + // Fetch reminder days. |
|
389 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
390 | + |
|
391 | + // Abort if non is set. |
|
392 | + if ( empty( $reminder_days ) ) { |
|
393 | + return; |
|
394 | + } |
|
395 | + |
|
396 | + // Retrieve date query. |
|
397 | + $date_query = $this->get_date_query( $reminder_days ); |
|
398 | + |
|
399 | + // Invoices table. |
|
400 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
401 | + |
|
402 | + // Fetch invoices. |
|
403 | + $invoices = $wpdb->get_col( |
|
404 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
405 | 405 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
406 | 406 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
407 | 407 | |
408 | - foreach ( $invoices as $invoice ) { |
|
408 | + foreach ( $invoices as $invoice ) { |
|
409 | 409 | |
410 | - // Only send this email for invoices created via the admin page. |
|
411 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
412 | - $invoice = new WPInv_Invoice( $invoice ); |
|
413 | - $email->object = $invoice; |
|
410 | + // Only send this email for invoices created via the admin page. |
|
411 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
412 | + $invoice = new WPInv_Invoice( $invoice ); |
|
413 | + $email->object = $invoice; |
|
414 | 414 | |
415 | - if ( $invoice->needs_payment() ) { |
|
416 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
417 | - } |
|
415 | + if ( $invoice->needs_payment() ) { |
|
416 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
417 | + } |
|
418 | 418 | |
419 | - } |
|
419 | + } |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Calculates the date query for an invoices query |
|
427 | - * |
|
428 | - * @param array $reminder_days |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public function get_date_query( $reminder_days ) { |
|
425 | + /** |
|
426 | + * Calculates the date query for an invoices query |
|
427 | + * |
|
428 | + * @param array $reminder_days |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public function get_date_query( $reminder_days ) { |
|
432 | 432 | |
433 | - $date_query = array( |
|
434 | - 'relation' => 'OR' |
|
435 | - ); |
|
433 | + $date_query = array( |
|
434 | + 'relation' => 'OR' |
|
435 | + ); |
|
436 | 436 | |
437 | - foreach ( $reminder_days as $days ) { |
|
438 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
437 | + foreach ( $reminder_days as $days ) { |
|
438 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
439 | 439 | |
440 | - $date_query[] = array( |
|
441 | - 'year' => $date['year'], |
|
442 | - 'month' => $date['month'], |
|
443 | - 'day' => $date['day'], |
|
444 | - ); |
|
440 | + $date_query[] = array( |
|
441 | + 'year' => $date['year'], |
|
442 | + 'month' => $date['month'], |
|
443 | + 'day' => $date['day'], |
|
444 | + ); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
448 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
449 | 449 | |
450 | - return $date_query->get_sql(); |
|
450 | + return $date_query->get_sql(); |
|
451 | 451 | |
452 | - } |
|
452 | + } |
|
453 | 453 | |
454 | 454 | } |