@@ -13,264 +13,264 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_Geolocation { |
15 | 15 | |
16 | - /** |
|
17 | - * Holds the current user's IP Address. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public static $current_user_ip; |
|
22 | - |
|
23 | - /** |
|
24 | - * API endpoints for looking up a user IP address. |
|
25 | - * |
|
26 | - * For example, in case a user is on localhost. |
|
27 | - * |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected static $ip_lookup_apis = array( |
|
31 | - 'ipify' => 'http://api.ipify.org/', |
|
32 | - 'ipecho' => 'http://ipecho.net/plain', |
|
33 | - 'ident' => 'http://ident.me', |
|
34 | - 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * API endpoints for geolocating an IP address |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected static $geoip_apis = array( |
|
43 | - 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
44 | - 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Get current user IP Address. |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public static function get_ip_address() { |
|
53 | - return wpinv_get_ip(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Get user IP Address using an external service. |
|
58 | - * This can be used as a fallback for users on localhost where |
|
59 | - * get_ip_address() will be a local IP and non-geolocatable. |
|
60 | - * |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public static function get_external_ip_address() { |
|
64 | - |
|
65 | - $transient_name = 'external_ip_address_0.0.0.0'; |
|
66 | - |
|
67 | - if ( '' !== self::get_ip_address() ) { |
|
68 | - $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | - } |
|
70 | - |
|
71 | - // Try retrieving from cache. |
|
72 | - $external_ip_address = get_transient( $transient_name ); |
|
73 | - |
|
74 | - if ( false === $external_ip_address ) { |
|
75 | - $external_ip_address = '0.0.0.0'; |
|
76 | - $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | - $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | - shuffle( $ip_lookup_services_keys ); |
|
79 | - |
|
80 | - foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | - $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | - $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
83 | - |
|
84 | - if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | - $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
86 | - break; |
|
87 | - } |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
92 | - } |
|
93 | - |
|
94 | - return $external_ip_address; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Geolocate an IP address. |
|
99 | - * |
|
100 | - * @param string $ip_address IP Address. |
|
101 | - * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
102 | - * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
106 | - |
|
107 | - if ( empty( $ip_address ) ) { |
|
108 | - $ip_address = self::get_ip_address(); |
|
109 | - } |
|
110 | - |
|
111 | - // Update the current user's IP Address. |
|
112 | - self::$current_user_ip = $ip_address; |
|
113 | - |
|
114 | - // Filter to allow custom geolocation of the IP address. |
|
115 | - $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
116 | - |
|
117 | - if ( false !== $country_code ) { |
|
118 | - |
|
119 | - return array( |
|
120 | - 'country' => $country_code, |
|
121 | - 'state' => '', |
|
122 | - 'city' => '', |
|
123 | - 'postcode' => '', |
|
124 | - ); |
|
125 | - |
|
126 | - } |
|
127 | - |
|
128 | - $country_code = self::get_country_code_from_headers(); |
|
129 | - |
|
130 | - /** |
|
131 | - * Get geolocation filter. |
|
132 | - * |
|
133 | - * @since 1.0.19 |
|
134 | - * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
135 | - * @param string $ip_address IP Address. |
|
136 | - */ |
|
137 | - $geolocation = apply_filters( |
|
138 | - 'getpaid_get_geolocation', |
|
139 | - array( |
|
140 | - 'country' => $country_code, |
|
141 | - 'state' => '', |
|
142 | - 'city' => '', |
|
143 | - 'postcode' => '', |
|
144 | - ), |
|
145 | - $ip_address |
|
146 | - ); |
|
147 | - |
|
148 | - // If we still haven't found a country code, let's consider doing an API lookup. |
|
149 | - if ( '' === $geolocation['country'] && $api_fallback ) { |
|
150 | - $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
151 | - } |
|
152 | - |
|
153 | - // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
154 | - // external address. |
|
155 | - if ( '' === $geolocation['country'] && $fallback ) { |
|
156 | - $external_ip_address = self::get_external_ip_address(); |
|
157 | - |
|
158 | - // Only bother with this if the external IP differs. |
|
159 | - if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
160 | - return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - return array( |
|
166 | - 'country' => $geolocation['country'], |
|
167 | - 'state' => $geolocation['state'], |
|
168 | - 'city' => $geolocation['city'], |
|
169 | - 'postcode' => $geolocation['postcode'], |
|
170 | - ); |
|
171 | - |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Fetches the country code from the request headers, if one is available. |
|
176 | - * |
|
177 | - * @since 1.0.19 |
|
178 | - * @return string The country code pulled from the headers, or empty string if one was not found. |
|
179 | - */ |
|
180 | - protected static function get_country_code_from_headers() { |
|
181 | - $country_code = ''; |
|
182 | - |
|
183 | - $headers = array( |
|
184 | - 'MM_COUNTRY_CODE', |
|
185 | - 'GEOIP_COUNTRY_CODE', |
|
186 | - 'HTTP_CF_IPCOUNTRY', |
|
187 | - 'HTTP_X_COUNTRY_CODE', |
|
188 | - ); |
|
189 | - |
|
190 | - foreach ( $headers as $header ) { |
|
191 | - if ( empty( $_SERVER[ $header ] ) ) { |
|
192 | - continue; |
|
193 | - } |
|
194 | - |
|
195 | - $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
196 | - break; |
|
197 | - } |
|
198 | - |
|
199 | - return $country_code; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Use APIs to Geolocate the user. |
|
204 | - * |
|
205 | - * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
206 | - * Provide a name=>value pair for service-slug=>endpoint. |
|
207 | - * |
|
208 | - * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
209 | - * will be cached in a transient. |
|
210 | - * |
|
211 | - * @param string $ip_address IP address. |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - protected static function geolocate_via_api( $ip_address ) { |
|
215 | - |
|
216 | - // Retrieve from cache... |
|
217 | - $country_code = get_transient( 'geoip_' . $ip_address ); |
|
218 | - |
|
219 | - // If missing, retrieve from the API. |
|
220 | - if ( false === $country_code ) { |
|
221 | - $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
222 | - |
|
223 | - if ( empty( $geoip_services ) ) { |
|
224 | - return ''; |
|
225 | - } |
|
226 | - |
|
227 | - $geoip_services_keys = array_keys( $geoip_services ); |
|
228 | - |
|
229 | - shuffle( $geoip_services_keys ); |
|
230 | - |
|
231 | - foreach ( $geoip_services_keys as $service_name ) { |
|
232 | - |
|
233 | - $service_endpoint = $geoip_services[ $service_name ]; |
|
234 | - $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
235 | - $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
236 | - |
|
237 | - if ( ! empty( $country_code ) ) { |
|
238 | - break; |
|
239 | - } |
|
240 | - |
|
241 | - } |
|
242 | - |
|
243 | - set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
244 | - } |
|
245 | - |
|
246 | - return $country_code; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Handles geolocation response |
|
251 | - * |
|
252 | - * @param WP_Error|String $geolocation_response |
|
253 | - * @param String $geolocation_service |
|
254 | - * @return string Country code |
|
255 | - */ |
|
256 | - protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
257 | - |
|
258 | - if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
259 | - return ''; |
|
260 | - } |
|
261 | - |
|
262 | - if ( $geolocation_service === 'ipinfo.io' ) { |
|
263 | - $data = json_decode( $geolocation_response['body'] ); |
|
264 | - return empty( $data ) ? '' : $data->country; |
|
265 | - } |
|
266 | - |
|
267 | - if ( $geolocation_service === 'ip-api.com' ) { |
|
268 | - $data = json_decode( $geolocation_response['body'] ); |
|
269 | - return empty( $data ) ? '' : $data->countryCode; |
|
270 | - } |
|
271 | - |
|
272 | - return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
273 | - |
|
274 | - } |
|
16 | + /** |
|
17 | + * Holds the current user's IP Address. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public static $current_user_ip; |
|
22 | + |
|
23 | + /** |
|
24 | + * API endpoints for looking up a user IP address. |
|
25 | + * |
|
26 | + * For example, in case a user is on localhost. |
|
27 | + * |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected static $ip_lookup_apis = array( |
|
31 | + 'ipify' => 'http://api.ipify.org/', |
|
32 | + 'ipecho' => 'http://ipecho.net/plain', |
|
33 | + 'ident' => 'http://ident.me', |
|
34 | + 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * API endpoints for geolocating an IP address |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected static $geoip_apis = array( |
|
43 | + 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
44 | + 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Get current user IP Address. |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public static function get_ip_address() { |
|
53 | + return wpinv_get_ip(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Get user IP Address using an external service. |
|
58 | + * This can be used as a fallback for users on localhost where |
|
59 | + * get_ip_address() will be a local IP and non-geolocatable. |
|
60 | + * |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public static function get_external_ip_address() { |
|
64 | + |
|
65 | + $transient_name = 'external_ip_address_0.0.0.0'; |
|
66 | + |
|
67 | + if ( '' !== self::get_ip_address() ) { |
|
68 | + $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | + } |
|
70 | + |
|
71 | + // Try retrieving from cache. |
|
72 | + $external_ip_address = get_transient( $transient_name ); |
|
73 | + |
|
74 | + if ( false === $external_ip_address ) { |
|
75 | + $external_ip_address = '0.0.0.0'; |
|
76 | + $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | + $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | + shuffle( $ip_lookup_services_keys ); |
|
79 | + |
|
80 | + foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | + $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | + $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
83 | + |
|
84 | + if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | + $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
86 | + break; |
|
87 | + } |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
92 | + } |
|
93 | + |
|
94 | + return $external_ip_address; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Geolocate an IP address. |
|
99 | + * |
|
100 | + * @param string $ip_address IP Address. |
|
101 | + * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
102 | + * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
106 | + |
|
107 | + if ( empty( $ip_address ) ) { |
|
108 | + $ip_address = self::get_ip_address(); |
|
109 | + } |
|
110 | + |
|
111 | + // Update the current user's IP Address. |
|
112 | + self::$current_user_ip = $ip_address; |
|
113 | + |
|
114 | + // Filter to allow custom geolocation of the IP address. |
|
115 | + $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
116 | + |
|
117 | + if ( false !== $country_code ) { |
|
118 | + |
|
119 | + return array( |
|
120 | + 'country' => $country_code, |
|
121 | + 'state' => '', |
|
122 | + 'city' => '', |
|
123 | + 'postcode' => '', |
|
124 | + ); |
|
125 | + |
|
126 | + } |
|
127 | + |
|
128 | + $country_code = self::get_country_code_from_headers(); |
|
129 | + |
|
130 | + /** |
|
131 | + * Get geolocation filter. |
|
132 | + * |
|
133 | + * @since 1.0.19 |
|
134 | + * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
135 | + * @param string $ip_address IP Address. |
|
136 | + */ |
|
137 | + $geolocation = apply_filters( |
|
138 | + 'getpaid_get_geolocation', |
|
139 | + array( |
|
140 | + 'country' => $country_code, |
|
141 | + 'state' => '', |
|
142 | + 'city' => '', |
|
143 | + 'postcode' => '', |
|
144 | + ), |
|
145 | + $ip_address |
|
146 | + ); |
|
147 | + |
|
148 | + // If we still haven't found a country code, let's consider doing an API lookup. |
|
149 | + if ( '' === $geolocation['country'] && $api_fallback ) { |
|
150 | + $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
151 | + } |
|
152 | + |
|
153 | + // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
154 | + // external address. |
|
155 | + if ( '' === $geolocation['country'] && $fallback ) { |
|
156 | + $external_ip_address = self::get_external_ip_address(); |
|
157 | + |
|
158 | + // Only bother with this if the external IP differs. |
|
159 | + if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
160 | + return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + return array( |
|
166 | + 'country' => $geolocation['country'], |
|
167 | + 'state' => $geolocation['state'], |
|
168 | + 'city' => $geolocation['city'], |
|
169 | + 'postcode' => $geolocation['postcode'], |
|
170 | + ); |
|
171 | + |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Fetches the country code from the request headers, if one is available. |
|
176 | + * |
|
177 | + * @since 1.0.19 |
|
178 | + * @return string The country code pulled from the headers, or empty string if one was not found. |
|
179 | + */ |
|
180 | + protected static function get_country_code_from_headers() { |
|
181 | + $country_code = ''; |
|
182 | + |
|
183 | + $headers = array( |
|
184 | + 'MM_COUNTRY_CODE', |
|
185 | + 'GEOIP_COUNTRY_CODE', |
|
186 | + 'HTTP_CF_IPCOUNTRY', |
|
187 | + 'HTTP_X_COUNTRY_CODE', |
|
188 | + ); |
|
189 | + |
|
190 | + foreach ( $headers as $header ) { |
|
191 | + if ( empty( $_SERVER[ $header ] ) ) { |
|
192 | + continue; |
|
193 | + } |
|
194 | + |
|
195 | + $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
196 | + break; |
|
197 | + } |
|
198 | + |
|
199 | + return $country_code; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Use APIs to Geolocate the user. |
|
204 | + * |
|
205 | + * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
206 | + * Provide a name=>value pair for service-slug=>endpoint. |
|
207 | + * |
|
208 | + * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
209 | + * will be cached in a transient. |
|
210 | + * |
|
211 | + * @param string $ip_address IP address. |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + protected static function geolocate_via_api( $ip_address ) { |
|
215 | + |
|
216 | + // Retrieve from cache... |
|
217 | + $country_code = get_transient( 'geoip_' . $ip_address ); |
|
218 | + |
|
219 | + // If missing, retrieve from the API. |
|
220 | + if ( false === $country_code ) { |
|
221 | + $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
222 | + |
|
223 | + if ( empty( $geoip_services ) ) { |
|
224 | + return ''; |
|
225 | + } |
|
226 | + |
|
227 | + $geoip_services_keys = array_keys( $geoip_services ); |
|
228 | + |
|
229 | + shuffle( $geoip_services_keys ); |
|
230 | + |
|
231 | + foreach ( $geoip_services_keys as $service_name ) { |
|
232 | + |
|
233 | + $service_endpoint = $geoip_services[ $service_name ]; |
|
234 | + $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
235 | + $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
236 | + |
|
237 | + if ( ! empty( $country_code ) ) { |
|
238 | + break; |
|
239 | + } |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
244 | + } |
|
245 | + |
|
246 | + return $country_code; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Handles geolocation response |
|
251 | + * |
|
252 | + * @param WP_Error|String $geolocation_response |
|
253 | + * @param String $geolocation_service |
|
254 | + * @return string Country code |
|
255 | + */ |
|
256 | + protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
257 | + |
|
258 | + if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
259 | + return ''; |
|
260 | + } |
|
261 | + |
|
262 | + if ( $geolocation_service === 'ipinfo.io' ) { |
|
263 | + $data = json_decode( $geolocation_response['body'] ); |
|
264 | + return empty( $data ) ? '' : $data->country; |
|
265 | + } |
|
266 | + |
|
267 | + if ( $geolocation_service === 'ip-api.com' ) { |
|
268 | + $data = json_decode( $geolocation_response['body'] ); |
|
269 | + return empty( $data ) ? '' : $data->countryCode; |
|
270 | + } |
|
271 | + |
|
272 | + return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
273 | + |
|
274 | + } |
|
275 | 275 | |
276 | 276 | } |
@@ -13,152 +13,152 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_MaxMind_Database_Service { |
15 | 15 | |
16 | - /** |
|
17 | - * The name of the MaxMind database to utilize. |
|
18 | - */ |
|
19 | - const DATABASE = 'GeoLite2-Country'; |
|
20 | - |
|
21 | - /** |
|
22 | - * The extension for the MaxMind database. |
|
23 | - */ |
|
24 | - const DATABASE_EXTENSION = '.mmdb'; |
|
25 | - |
|
26 | - /** |
|
27 | - * A prefix for the MaxMind database filename. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - private $database_prefix; |
|
32 | - |
|
33 | - /** |
|
34 | - * Class constructor. |
|
35 | - * |
|
36 | - * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | - */ |
|
38 | - public function __construct( $database_prefix ) { |
|
39 | - $this->database_prefix = $database_prefix; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Fetches the path that the database should be stored. |
|
44 | - * |
|
45 | - * @return string The local database path. |
|
46 | - */ |
|
47 | - public function get_database_path() { |
|
48 | - $uploads_dir = wp_upload_dir(); |
|
49 | - |
|
50 | - $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | - if ( ! empty( $this->database_prefix ) ) { |
|
52 | - $database_path .= $this->database_prefix . '-'; |
|
53 | - } |
|
54 | - $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | - |
|
56 | - // Filter the geolocation database storage path. |
|
57 | - return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Fetches the database from the MaxMind service. |
|
62 | - * |
|
63 | - * @param string $license_key The license key to be used when downloading the database. |
|
64 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | - */ |
|
66 | - public function download_database( $license_key ) { |
|
67 | - |
|
68 | - $download_uri = add_query_arg( |
|
69 | - array( |
|
70 | - 'edition_id' => self::DATABASE, |
|
71 | - 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | - 'suffix' => 'tar.gz', |
|
73 | - ), |
|
74 | - 'https://download.maxmind.com/app/geoip_download' |
|
75 | - ); |
|
76 | - |
|
77 | - // Needed for the download_url call right below. |
|
78 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | - |
|
80 | - $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | - |
|
82 | - if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | - // Transform the error into something more informative. |
|
84 | - $error_data = $tmp_archive_path->get_error_data(); |
|
85 | - if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | - return new WP_Error( |
|
87 | - 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | - __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | - } |
|
94 | - |
|
95 | - // Extract the database from the archive. |
|
96 | - return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Extracts the downloaded database. |
|
102 | - * |
|
103 | - * @param string $tmp_archive_path The database archive path. |
|
104 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | - */ |
|
106 | - protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | - |
|
108 | - // Extract the database from the archive. |
|
109 | - try { |
|
110 | - |
|
111 | - $file = new PharData( $tmp_archive_path ); |
|
112 | - $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
113 | - |
|
114 | - $file->extractTo( |
|
115 | - dirname( $tmp_archive_path ), |
|
116 | - trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
117 | - true |
|
118 | - ); |
|
119 | - |
|
120 | - } catch ( Exception $exception ) { |
|
121 | - return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
122 | - } finally { |
|
123 | - // Remove the archive since we only care about a single file in it. |
|
124 | - unlink( $tmp_archive_path ); |
|
125 | - } |
|
126 | - |
|
127 | - return $tmp_database_path; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Fetches the ISO country code associated with an IP address. |
|
132 | - * |
|
133 | - * @param string $ip_address The IP address to find the country code for. |
|
134 | - * @return string The country code for the IP address, or empty if not found. |
|
135 | - */ |
|
136 | - public function get_iso_country_code_for_ip( $ip_address ) { |
|
137 | - $country_code = ''; |
|
138 | - |
|
139 | - if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
140 | - return $country_code; |
|
141 | - } |
|
142 | - |
|
143 | - $database_path = $this->get_database_path(); |
|
144 | - if ( ! file_exists( $database_path ) ) { |
|
145 | - return $country_code; |
|
146 | - } |
|
147 | - |
|
148 | - try { |
|
149 | - $reader = new MaxMind\Db\Reader( $database_path ); |
|
150 | - $data = $reader->get( $ip_address ); |
|
151 | - |
|
152 | - if ( isset( $data['country']['iso_code'] ) ) { |
|
153 | - $country_code = $data['country']['iso_code']; |
|
154 | - } |
|
155 | - |
|
156 | - $reader->close(); |
|
157 | - } catch ( Exception $e ) { |
|
158 | - wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
159 | - } |
|
160 | - |
|
161 | - return $country_code; |
|
162 | - } |
|
16 | + /** |
|
17 | + * The name of the MaxMind database to utilize. |
|
18 | + */ |
|
19 | + const DATABASE = 'GeoLite2-Country'; |
|
20 | + |
|
21 | + /** |
|
22 | + * The extension for the MaxMind database. |
|
23 | + */ |
|
24 | + const DATABASE_EXTENSION = '.mmdb'; |
|
25 | + |
|
26 | + /** |
|
27 | + * A prefix for the MaxMind database filename. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + private $database_prefix; |
|
32 | + |
|
33 | + /** |
|
34 | + * Class constructor. |
|
35 | + * |
|
36 | + * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | + */ |
|
38 | + public function __construct( $database_prefix ) { |
|
39 | + $this->database_prefix = $database_prefix; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Fetches the path that the database should be stored. |
|
44 | + * |
|
45 | + * @return string The local database path. |
|
46 | + */ |
|
47 | + public function get_database_path() { |
|
48 | + $uploads_dir = wp_upload_dir(); |
|
49 | + |
|
50 | + $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | + if ( ! empty( $this->database_prefix ) ) { |
|
52 | + $database_path .= $this->database_prefix . '-'; |
|
53 | + } |
|
54 | + $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | + |
|
56 | + // Filter the geolocation database storage path. |
|
57 | + return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Fetches the database from the MaxMind service. |
|
62 | + * |
|
63 | + * @param string $license_key The license key to be used when downloading the database. |
|
64 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | + */ |
|
66 | + public function download_database( $license_key ) { |
|
67 | + |
|
68 | + $download_uri = add_query_arg( |
|
69 | + array( |
|
70 | + 'edition_id' => self::DATABASE, |
|
71 | + 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | + 'suffix' => 'tar.gz', |
|
73 | + ), |
|
74 | + 'https://download.maxmind.com/app/geoip_download' |
|
75 | + ); |
|
76 | + |
|
77 | + // Needed for the download_url call right below. |
|
78 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | + |
|
80 | + $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | + |
|
82 | + if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | + // Transform the error into something more informative. |
|
84 | + $error_data = $tmp_archive_path->get_error_data(); |
|
85 | + if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | + return new WP_Error( |
|
87 | + 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | + __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | + } |
|
94 | + |
|
95 | + // Extract the database from the archive. |
|
96 | + return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Extracts the downloaded database. |
|
102 | + * |
|
103 | + * @param string $tmp_archive_path The database archive path. |
|
104 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | + */ |
|
106 | + protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | + |
|
108 | + // Extract the database from the archive. |
|
109 | + try { |
|
110 | + |
|
111 | + $file = new PharData( $tmp_archive_path ); |
|
112 | + $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
113 | + |
|
114 | + $file->extractTo( |
|
115 | + dirname( $tmp_archive_path ), |
|
116 | + trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
117 | + true |
|
118 | + ); |
|
119 | + |
|
120 | + } catch ( Exception $exception ) { |
|
121 | + return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
122 | + } finally { |
|
123 | + // Remove the archive since we only care about a single file in it. |
|
124 | + unlink( $tmp_archive_path ); |
|
125 | + } |
|
126 | + |
|
127 | + return $tmp_database_path; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Fetches the ISO country code associated with an IP address. |
|
132 | + * |
|
133 | + * @param string $ip_address The IP address to find the country code for. |
|
134 | + * @return string The country code for the IP address, or empty if not found. |
|
135 | + */ |
|
136 | + public function get_iso_country_code_for_ip( $ip_address ) { |
|
137 | + $country_code = ''; |
|
138 | + |
|
139 | + if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
140 | + return $country_code; |
|
141 | + } |
|
142 | + |
|
143 | + $database_path = $this->get_database_path(); |
|
144 | + if ( ! file_exists( $database_path ) ) { |
|
145 | + return $country_code; |
|
146 | + } |
|
147 | + |
|
148 | + try { |
|
149 | + $reader = new MaxMind\Db\Reader( $database_path ); |
|
150 | + $data = $reader->get( $ip_address ); |
|
151 | + |
|
152 | + if ( isset( $data['country']['iso_code'] ) ) { |
|
153 | + $country_code = $data['country']['iso_code']; |
|
154 | + } |
|
155 | + |
|
156 | + $reader->close(); |
|
157 | + } catch ( Exception $e ) { |
|
158 | + wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
159 | + } |
|
160 | + |
|
161 | + return $country_code; |
|
162 | + } |
|
163 | 163 | |
164 | 164 | } |
@@ -12,108 +12,108 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
31 | - |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Schedules a cron to run every day at 7 a.m |
|
36 | - * |
|
37 | - */ |
|
38 | - public function maybe_create_scheduled_event() { |
|
39 | - |
|
40 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
41 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
42 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Clears deprecated events. |
|
49 | - * |
|
50 | - */ |
|
51 | - public function maybe_clear_deprecated_events() { |
|
52 | - |
|
53 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
56 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
57 | - } |
|
58 | - |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Fires the old hook for backwards compatibility. |
|
63 | - * |
|
64 | - */ |
|
65 | - public function backwards_compat() { |
|
66 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Expires expired subscriptions. |
|
71 | - * |
|
72 | - */ |
|
73 | - public function maybe_expire_subscriptions() { |
|
74 | - |
|
75 | - // Fetch expired subscriptions (skips those that expire today). |
|
76 | - $args = array( |
|
77 | - 'number' => -1, |
|
78 | - 'count_total' => false, |
|
79 | - 'status' => 'trialling active failing cancelled', |
|
80 | - 'date_expires_query' => array( |
|
81 | - 'before' => 'today', |
|
82 | - 'inclusive' => false, |
|
83 | - ), |
|
84 | - ); |
|
85 | - |
|
86 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
87 | - |
|
88 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
89 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
90 | - $subscription->set_status( 'expired' ); |
|
91 | - $subscription->save(); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Logs cron runs. |
|
99 | - * |
|
100 | - */ |
|
101 | - public function log_cron_run() { |
|
102 | - wpinv_error_log( 'GetPaid Daily Cron' ); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Updates GeoIP databases. |
|
107 | - * |
|
108 | - */ |
|
109 | - public function maybe_update_geoip_databases() { |
|
110 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
111 | - |
|
112 | - if ( false === $updated ) { |
|
113 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
114 | - do_action( 'getpaid_update_geoip_databases' ); |
|
115 | - } |
|
116 | - |
|
117 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
31 | + |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Schedules a cron to run every day at 7 a.m |
|
36 | + * |
|
37 | + */ |
|
38 | + public function maybe_create_scheduled_event() { |
|
39 | + |
|
40 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
41 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
42 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Clears deprecated events. |
|
49 | + * |
|
50 | + */ |
|
51 | + public function maybe_clear_deprecated_events() { |
|
52 | + |
|
53 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
54 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
56 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
57 | + } |
|
58 | + |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Fires the old hook for backwards compatibility. |
|
63 | + * |
|
64 | + */ |
|
65 | + public function backwards_compat() { |
|
66 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Expires expired subscriptions. |
|
71 | + * |
|
72 | + */ |
|
73 | + public function maybe_expire_subscriptions() { |
|
74 | + |
|
75 | + // Fetch expired subscriptions (skips those that expire today). |
|
76 | + $args = array( |
|
77 | + 'number' => -1, |
|
78 | + 'count_total' => false, |
|
79 | + 'status' => 'trialling active failing cancelled', |
|
80 | + 'date_expires_query' => array( |
|
81 | + 'before' => 'today', |
|
82 | + 'inclusive' => false, |
|
83 | + ), |
|
84 | + ); |
|
85 | + |
|
86 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
87 | + |
|
88 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
89 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
90 | + $subscription->set_status( 'expired' ); |
|
91 | + $subscription->save(); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Logs cron runs. |
|
99 | + * |
|
100 | + */ |
|
101 | + public function log_cron_run() { |
|
102 | + wpinv_error_log( 'GetPaid Daily Cron' ); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Updates GeoIP databases. |
|
107 | + * |
|
108 | + */ |
|
109 | + public function maybe_update_geoip_databases() { |
|
110 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
111 | + |
|
112 | + if ( false === $updated ) { |
|
113 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
114 | + do_action( 'getpaid_update_geoip_databases' ); |
|
115 | + } |
|
116 | + |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |
@@ -350,23 +350,23 @@ discard block |
||
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
353 | - * |
|
354 | - * @deprecated |
|
355 | - */ |
|
353 | + * |
|
354 | + * @deprecated |
|
355 | + */ |
|
356 | 356 | public static function maxmind_folder() { |
357 | 357 | return false; |
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
361 | - * |
|
362 | - * @deprecated |
|
363 | - */ |
|
361 | + * |
|
362 | + * @deprecated |
|
363 | + */ |
|
364 | 364 | public static function geoip2_download_database() {} |
365 | 365 | |
366 | 366 | /** |
367 | - * |
|
368 | - * @deprecated |
|
369 | - */ |
|
367 | + * |
|
368 | + * @deprecated |
|
369 | + */ |
|
370 | 370 | public static function geoip2_download_file() {} |
371 | 371 | |
372 | 372 | /** |
@@ -1517,7 +1517,7 @@ discard block |
||
1517 | 1517 | $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
1518 | 1518 | |
1519 | 1519 | if ( ! $valid_company && ! empty( $wpinv_options['vat_disable_company_name_check'] ) ) { |
1520 | - return wp_sprintf( |
|
1520 | + return wp_sprintf( |
|
1521 | 1521 | __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), |
1522 | 1522 | getpaid_vat_name() |
1523 | 1523 | ); |
@@ -14,502 +14,502 @@ 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 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Define plugin constants. |
|
116 | - */ |
|
117 | - public function define_constants() { |
|
118 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
119 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
120 | - $this->version = WPINV_VERSION; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Hook into actions and filters. |
|
125 | - * |
|
126 | - * @since 1.0.19 |
|
127 | - */ |
|
128 | - protected function init_hooks() { |
|
129 | - /* Internationalize the text strings used. */ |
|
130 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
131 | - |
|
132 | - // Init the plugin after WordPress inits. |
|
133 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
134 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
135 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
136 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
137 | - |
|
138 | - if ( class_exists( 'BuddyPress' ) ) { |
|
139 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
140 | - } |
|
141 | - |
|
142 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
143 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
144 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
145 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
146 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
147 | - |
|
148 | - // Fires after registering actions. |
|
149 | - do_action( 'wpinv_actions', $this ); |
|
150 | - do_action( 'getpaid_actions', $this ); |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - public function plugins_loaded() { |
|
155 | - /* Internationalize the text strings used. */ |
|
156 | - $this->load_textdomain(); |
|
157 | - |
|
158 | - do_action( 'wpinv_loaded' ); |
|
159 | - |
|
160 | - // Fix oxygen page builder conflict |
|
161 | - if ( function_exists( 'ct_css_output' ) ) { |
|
162 | - wpinv_oxygen_fix_conflict(); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Load the translation of the plugin. |
|
168 | - * |
|
169 | - * @since 1.0 |
|
170 | - */ |
|
171 | - public function load_textdomain( $locale = NULL ) { |
|
172 | - if ( empty( $locale ) ) { |
|
173 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
174 | - } |
|
175 | - |
|
176 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
177 | - |
|
178 | - unload_textdomain( 'invoicing' ); |
|
179 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
180 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
181 | - |
|
182 | - /** |
|
183 | - * Define language constants. |
|
184 | - */ |
|
185 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Include required core files used in admin and on the frontend. |
|
190 | - */ |
|
191 | - public function includes() { |
|
192 | - |
|
193 | - // Start with the settings. |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
195 | - |
|
196 | - // Packages/libraries. |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
199 | - |
|
200 | - // Load functions. |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
216 | - |
|
217 | - // Register autoloader. |
|
218 | - try { |
|
219 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
220 | - } catch ( Exception $e ) { |
|
221 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
222 | - } |
|
223 | - |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
245 | - |
|
246 | - /** |
|
247 | - * Load the tax class. |
|
248 | - */ |
|
249 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
250 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
251 | - } |
|
252 | - |
|
253 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
254 | - GetPaid_Post_Types_Admin::init(); |
|
255 | - |
|
256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
263 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
264 | - // load the user class only on the users.php page |
|
265 | - global $pagenow; |
|
266 | - if($pagenow=='users.php'){ |
|
267 | - new WPInv_Admin_Users(); |
|
268 | - } |
|
269 | - } |
|
270 | - |
|
271 | - // Register cli commands |
|
272 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
273 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
274 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
275 | - } |
|
276 | - |
|
277 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Class autoloader |
|
282 | - * |
|
283 | - * @param string $class_name The name of the class to load. |
|
284 | - * @access public |
|
285 | - * @since 1.0.19 |
|
286 | - * @return void |
|
287 | - */ |
|
288 | - public function autoload( $class_name ) { |
|
289 | - |
|
290 | - // Normalize the class name... |
|
291 | - $class_name = strtolower( $class_name ); |
|
292 | - |
|
293 | - // ... and make sure it is our class. |
|
294 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
295 | - return; |
|
296 | - } |
|
297 | - |
|
298 | - // Next, prepare the file name from the class. |
|
299 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
300 | - |
|
301 | - // Base path of the classes. |
|
302 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
303 | - |
|
304 | - // And an array of possible locations in order of importance. |
|
305 | - $locations = array( |
|
306 | - "$plugin_path/includes", |
|
307 | - "$plugin_path/includes/data-stores", |
|
308 | - "$plugin_path/includes/gateways", |
|
309 | - "$plugin_path/includes/payments", |
|
310 | - "$plugin_path/includes/geolocation", |
|
311 | - "$plugin_path/includes/api", |
|
312 | - "$plugin_path/includes/admin", |
|
313 | - "$plugin_path/includes/admin/meta-boxes", |
|
314 | - ); |
|
315 | - |
|
316 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
317 | - |
|
318 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
319 | - include trailingslashit( $location ) . $file_name; |
|
320 | - break; |
|
321 | - } |
|
322 | - |
|
323 | - } |
|
324 | - |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Inits hooks etc. |
|
329 | - */ |
|
330 | - public function init() { |
|
331 | - |
|
332 | - // Fires before getpaid inits. |
|
333 | - do_action( 'before_getpaid_init', $this ); |
|
334 | - |
|
335 | - // Load default gateways. |
|
336 | - $gateways = apply_filters( |
|
337 | - 'getpaid_default_gateways', |
|
338 | - array( |
|
339 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
340 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
341 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
342 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
343 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
344 | - ) |
|
345 | - ); |
|
346 | - |
|
347 | - foreach ( $gateways as $id => $class ) { |
|
348 | - $this->gateways[ $id ] = new $class(); |
|
349 | - } |
|
350 | - |
|
351 | - // Fires after getpaid inits. |
|
352 | - do_action( 'getpaid_init', $this ); |
|
353 | - |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Checks if this is an IPN request and processes it. |
|
358 | - */ |
|
359 | - public function maybe_process_ipn() { |
|
360 | - |
|
361 | - // Ensure that this is an IPN request. |
|
362 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
363 | - return; |
|
364 | - } |
|
365 | - |
|
366 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
367 | - |
|
368 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
369 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
370 | - exit; |
|
371 | - |
|
372 | - } |
|
373 | - |
|
374 | - public function enqueue_scripts() { |
|
375 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
376 | - |
|
377 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
378 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
379 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
380 | - |
|
381 | - // Register scripts |
|
382 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
383 | - 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' ) ); |
|
384 | - |
|
385 | - $localize = array(); |
|
386 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
387 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
388 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
389 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
390 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
391 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
392 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
393 | - |
|
394 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
395 | - |
|
396 | - wp_enqueue_script( 'jquery-blockui' ); |
|
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 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
397 | 111 | |
398 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
399 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Define plugin constants. |
|
116 | + */ |
|
117 | + public function define_constants() { |
|
118 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
119 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
120 | + $this->version = WPINV_VERSION; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Hook into actions and filters. |
|
125 | + * |
|
126 | + * @since 1.0.19 |
|
127 | + */ |
|
128 | + protected function init_hooks() { |
|
129 | + /* Internationalize the text strings used. */ |
|
130 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
131 | + |
|
132 | + // Init the plugin after WordPress inits. |
|
133 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
134 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
135 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
136 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
137 | + |
|
138 | + if ( class_exists( 'BuddyPress' ) ) { |
|
139 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
140 | + } |
|
141 | + |
|
142 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
143 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
144 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
145 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
146 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
147 | + |
|
148 | + // Fires after registering actions. |
|
149 | + do_action( 'wpinv_actions', $this ); |
|
150 | + do_action( 'getpaid_actions', $this ); |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + public function plugins_loaded() { |
|
155 | + /* Internationalize the text strings used. */ |
|
156 | + $this->load_textdomain(); |
|
157 | + |
|
158 | + do_action( 'wpinv_loaded' ); |
|
159 | + |
|
160 | + // Fix oxygen page builder conflict |
|
161 | + if ( function_exists( 'ct_css_output' ) ) { |
|
162 | + wpinv_oxygen_fix_conflict(); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Load the translation of the plugin. |
|
168 | + * |
|
169 | + * @since 1.0 |
|
170 | + */ |
|
171 | + public function load_textdomain( $locale = NULL ) { |
|
172 | + if ( empty( $locale ) ) { |
|
173 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
174 | + } |
|
175 | + |
|
176 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
177 | + |
|
178 | + unload_textdomain( 'invoicing' ); |
|
179 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
180 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
181 | + |
|
182 | + /** |
|
183 | + * Define language constants. |
|
184 | + */ |
|
185 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Include required core files used in admin and on the frontend. |
|
190 | + */ |
|
191 | + public function includes() { |
|
192 | + |
|
193 | + // Start with the settings. |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
195 | + |
|
196 | + // Packages/libraries. |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
199 | + |
|
200 | + // Load functions. |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
207 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
208 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
215 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
216 | + |
|
217 | + // Register autoloader. |
|
218 | + try { |
|
219 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
220 | + } catch ( Exception $e ) { |
|
221 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
222 | + } |
|
223 | + |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
244 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
245 | + |
|
246 | + /** |
|
247 | + * Load the tax class. |
|
248 | + */ |
|
249 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
250 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
251 | + } |
|
252 | + |
|
253 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
254 | + GetPaid_Post_Types_Admin::init(); |
|
255 | + |
|
256 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
257 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
258 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
259 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
260 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
261 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
262 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
263 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
264 | + // load the user class only on the users.php page |
|
265 | + global $pagenow; |
|
266 | + if($pagenow=='users.php'){ |
|
267 | + new WPInv_Admin_Users(); |
|
268 | + } |
|
269 | + } |
|
270 | + |
|
271 | + // Register cli commands |
|
272 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
273 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
274 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
275 | + } |
|
276 | + |
|
277 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Class autoloader |
|
282 | + * |
|
283 | + * @param string $class_name The name of the class to load. |
|
284 | + * @access public |
|
285 | + * @since 1.0.19 |
|
286 | + * @return void |
|
287 | + */ |
|
288 | + public function autoload( $class_name ) { |
|
400 | 289 | |
401 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
402 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
403 | - |
|
404 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
405 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
406 | - } |
|
407 | - |
|
408 | - public function wpinv_actions() { |
|
409 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
410 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
411 | - } |
|
412 | - } |
|
290 | + // Normalize the class name... |
|
291 | + $class_name = strtolower( $class_name ); |
|
413 | 292 | |
414 | - /** |
|
293 | + // ... and make sure it is our class. |
|
294 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
295 | + return; |
|
296 | + } |
|
297 | + |
|
298 | + // Next, prepare the file name from the class. |
|
299 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
300 | + |
|
301 | + // Base path of the classes. |
|
302 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
303 | + |
|
304 | + // And an array of possible locations in order of importance. |
|
305 | + $locations = array( |
|
306 | + "$plugin_path/includes", |
|
307 | + "$plugin_path/includes/data-stores", |
|
308 | + "$plugin_path/includes/gateways", |
|
309 | + "$plugin_path/includes/payments", |
|
310 | + "$plugin_path/includes/geolocation", |
|
311 | + "$plugin_path/includes/api", |
|
312 | + "$plugin_path/includes/admin", |
|
313 | + "$plugin_path/includes/admin/meta-boxes", |
|
314 | + ); |
|
315 | + |
|
316 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
317 | + |
|
318 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
319 | + include trailingslashit( $location ) . $file_name; |
|
320 | + break; |
|
321 | + } |
|
322 | + |
|
323 | + } |
|
324 | + |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Inits hooks etc. |
|
329 | + */ |
|
330 | + public function init() { |
|
331 | + |
|
332 | + // Fires before getpaid inits. |
|
333 | + do_action( 'before_getpaid_init', $this ); |
|
334 | + |
|
335 | + // Load default gateways. |
|
336 | + $gateways = apply_filters( |
|
337 | + 'getpaid_default_gateways', |
|
338 | + array( |
|
339 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
340 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
341 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
342 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
343 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
344 | + ) |
|
345 | + ); |
|
346 | + |
|
347 | + foreach ( $gateways as $id => $class ) { |
|
348 | + $this->gateways[ $id ] = new $class(); |
|
349 | + } |
|
350 | + |
|
351 | + // Fires after getpaid inits. |
|
352 | + do_action( 'getpaid_init', $this ); |
|
353 | + |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Checks if this is an IPN request and processes it. |
|
358 | + */ |
|
359 | + public function maybe_process_ipn() { |
|
360 | + |
|
361 | + // Ensure that this is an IPN request. |
|
362 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
363 | + return; |
|
364 | + } |
|
365 | + |
|
366 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
367 | + |
|
368 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
369 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
370 | + exit; |
|
371 | + |
|
372 | + } |
|
373 | + |
|
374 | + public function enqueue_scripts() { |
|
375 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
376 | + |
|
377 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
378 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
379 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
380 | + |
|
381 | + // Register scripts |
|
382 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
383 | + 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' ) ); |
|
384 | + |
|
385 | + $localize = array(); |
|
386 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
387 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
388 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
389 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
390 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
391 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
392 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
393 | + |
|
394 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
395 | + |
|
396 | + wp_enqueue_script( 'jquery-blockui' ); |
|
397 | + |
|
398 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
399 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
400 | + |
|
401 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
402 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
403 | + |
|
404 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
405 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
406 | + } |
|
407 | + |
|
408 | + public function wpinv_actions() { |
|
409 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
410 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
411 | + } |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | 415 | * Fires an action after verifying that a user can fire them. |
416 | - * |
|
417 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
418 | - * current user owns the invoice/subscription. |
|
416 | + * |
|
417 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
418 | + * current user owns the invoice/subscription. |
|
419 | 419 | */ |
420 | 420 | public function maybe_do_authenticated_action() { |
421 | 421 | |
422 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
422 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
423 | 423 | |
424 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
425 | - if ( is_user_logged_in() ) { |
|
426 | - do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
427 | - } |
|
424 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
425 | + if ( is_user_logged_in() ) { |
|
426 | + do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
427 | + } |
|
428 | 428 | |
429 | - do_action( "getpaid_unauthenticated_action_$key", $_REQUEST ); |
|
429 | + do_action( "getpaid_unauthenticated_action_$key", $_REQUEST ); |
|
430 | 430 | |
431 | - } |
|
431 | + } |
|
432 | 432 | |
433 | 433 | |
434 | 434 | } |
435 | 435 | |
436 | - public function pre_get_posts( $wp_query ) { |
|
437 | - |
|
438 | - 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() ) { |
|
439 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
440 | - } |
|
441 | - |
|
442 | - return $wp_query; |
|
443 | - } |
|
444 | - |
|
445 | - public function bp_invoicing_init() { |
|
446 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * Register widgets |
|
451 | - * |
|
452 | - */ |
|
453 | - public function register_widgets() { |
|
454 | - $widgets = apply_filters( |
|
455 | - 'getpaid_widget_classes', |
|
456 | - array( |
|
457 | - 'WPInv_Checkout_Widget', |
|
458 | - 'WPInv_History_Widget', |
|
459 | - 'WPInv_Receipt_Widget', |
|
460 | - 'WPInv_Subscriptions_Widget', |
|
461 | - 'WPInv_Buy_Item_Widget', |
|
462 | - 'WPInv_Messages_Widget', |
|
463 | - 'WPInv_GetPaid_Widget' |
|
464 | - ) |
|
465 | - ); |
|
466 | - |
|
467 | - foreach ( $widgets as $widget ) { |
|
468 | - register_widget( $widget ); |
|
469 | - } |
|
436 | + public function pre_get_posts( $wp_query ) { |
|
437 | + |
|
438 | + 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() ) { |
|
439 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
440 | + } |
|
441 | + |
|
442 | + return $wp_query; |
|
443 | + } |
|
444 | + |
|
445 | + public function bp_invoicing_init() { |
|
446 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * Register widgets |
|
451 | + * |
|
452 | + */ |
|
453 | + public function register_widgets() { |
|
454 | + $widgets = apply_filters( |
|
455 | + 'getpaid_widget_classes', |
|
456 | + array( |
|
457 | + 'WPInv_Checkout_Widget', |
|
458 | + 'WPInv_History_Widget', |
|
459 | + 'WPInv_Receipt_Widget', |
|
460 | + 'WPInv_Subscriptions_Widget', |
|
461 | + 'WPInv_Buy_Item_Widget', |
|
462 | + 'WPInv_Messages_Widget', |
|
463 | + 'WPInv_GetPaid_Widget' |
|
464 | + ) |
|
465 | + ); |
|
466 | + |
|
467 | + foreach ( $widgets as $widget ) { |
|
468 | + register_widget( $widget ); |
|
469 | + } |
|
470 | 470 | |
471 | - } |
|
471 | + } |
|
472 | 472 | |
473 | - /** |
|
474 | - * Remove our pages from yoast sitemaps. |
|
475 | - * |
|
476 | - * @since 1.0.19 |
|
477 | - * @param int[] $excluded_posts_ids |
|
478 | - */ |
|
479 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
473 | + /** |
|
474 | + * Remove our pages from yoast sitemaps. |
|
475 | + * |
|
476 | + * @since 1.0.19 |
|
477 | + * @param int[] $excluded_posts_ids |
|
478 | + */ |
|
479 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
480 | 480 | |
481 | - // Ensure that we have an array. |
|
482 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
483 | - $excluded_posts_ids = array(); |
|
484 | - } |
|
481 | + // Ensure that we have an array. |
|
482 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
483 | + $excluded_posts_ids = array(); |
|
484 | + } |
|
485 | 485 | |
486 | - // Prepare our pages. |
|
487 | - $our_pages = array(); |
|
486 | + // Prepare our pages. |
|
487 | + $our_pages = array(); |
|
488 | 488 | |
489 | - // Checkout page. |
|
490 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
489 | + // Checkout page. |
|
490 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
491 | 491 | |
492 | - // Success page. |
|
493 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
492 | + // Success page. |
|
493 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
494 | 494 | |
495 | - // Failure page. |
|
496 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
495 | + // Failure page. |
|
496 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
497 | 497 | |
498 | - // History page. |
|
499 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
498 | + // History page. |
|
499 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
500 | 500 | |
501 | - // Subscriptions page. |
|
502 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
501 | + // Subscriptions page. |
|
502 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
503 | 503 | |
504 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
504 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
505 | 505 | |
506 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
507 | - return array_unique( $excluded_posts_ids ); |
|
506 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
507 | + return array_unique( $excluded_posts_ids ); |
|
508 | 508 | |
509 | - } |
|
509 | + } |
|
510 | 510 | |
511 | - public function wp_footer() { |
|
512 | - echo ' |
|
511 | + public function wp_footer() { |
|
512 | + echo ' |
|
513 | 513 | <div class="bsui"> |
514 | 514 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
515 | 515 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -520,6 +520,6 @@ discard block |
||
520 | 520 | </div> |
521 | 521 | </div> |
522 | 522 | '; |
523 | - } |
|
523 | + } |
|
524 | 524 | |
525 | 525 | } |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | class InstalledVersions |
13 | 13 | { |
14 | 14 | private static $installed = array ( |
15 | - 'root' => |
|
16 | - array ( |
|
15 | + 'root' => |
|
16 | + array ( |
|
17 | 17 | 'pretty_version' => 'dev-master', |
18 | 18 | 'version' => 'dev-master', |
19 | 19 | 'aliases' => |
@@ -21,87 +21,87 @@ discard block |
||
21 | 21 | ), |
22 | 22 | 'reference' => '58e08ab4fbfabf9d48bdecf0dce878830040d4ea', |
23 | 23 | 'name' => 'ayecode/invoicing', |
24 | - ), |
|
25 | - 'versions' => |
|
26 | - array ( |
|
24 | + ), |
|
25 | + 'versions' => |
|
26 | + array ( |
|
27 | 27 | 'ayecode/ayecode-connect-helper' => |
28 | 28 | array ( |
29 | - 'pretty_version' => '1.0.3', |
|
30 | - 'version' => '1.0.3.0', |
|
31 | - 'aliases' => |
|
32 | - array ( |
|
33 | - ), |
|
34 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
29 | + 'pretty_version' => '1.0.3', |
|
30 | + 'version' => '1.0.3.0', |
|
31 | + 'aliases' => |
|
32 | + array ( |
|
33 | + ), |
|
34 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
35 | 35 | ), |
36 | 36 | 'ayecode/invoicing' => |
37 | 37 | array ( |
38 | - 'pretty_version' => 'dev-master', |
|
39 | - 'version' => 'dev-master', |
|
40 | - 'aliases' => |
|
41 | - array ( |
|
42 | - ), |
|
43 | - 'reference' => '58e08ab4fbfabf9d48bdecf0dce878830040d4ea', |
|
38 | + 'pretty_version' => 'dev-master', |
|
39 | + 'version' => 'dev-master', |
|
40 | + 'aliases' => |
|
41 | + array ( |
|
42 | + ), |
|
43 | + 'reference' => '58e08ab4fbfabf9d48bdecf0dce878830040d4ea', |
|
44 | 44 | ), |
45 | 45 | 'ayecode/wp-ayecode-ui' => |
46 | 46 | array ( |
47 | - 'pretty_version' => '0.1.35', |
|
48 | - 'version' => '0.1.35.0', |
|
49 | - 'aliases' => |
|
50 | - array ( |
|
51 | - ), |
|
52 | - 'reference' => 'e5d7955f648c6b350a8fe72e0110b8d78645c60f', |
|
47 | + 'pretty_version' => '0.1.35', |
|
48 | + 'version' => '0.1.35.0', |
|
49 | + 'aliases' => |
|
50 | + array ( |
|
51 | + ), |
|
52 | + 'reference' => 'e5d7955f648c6b350a8fe72e0110b8d78645c60f', |
|
53 | 53 | ), |
54 | 54 | 'ayecode/wp-font-awesome-settings' => |
55 | 55 | array ( |
56 | - 'pretty_version' => '1.0.12', |
|
57 | - 'version' => '1.0.12.0', |
|
58 | - 'aliases' => |
|
59 | - array ( |
|
60 | - ), |
|
61 | - 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
56 | + 'pretty_version' => '1.0.12', |
|
57 | + 'version' => '1.0.12.0', |
|
58 | + 'aliases' => |
|
59 | + array ( |
|
60 | + ), |
|
61 | + 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
62 | 62 | ), |
63 | 63 | 'ayecode/wp-super-duper' => |
64 | 64 | array ( |
65 | - 'pretty_version' => '1.0.22', |
|
66 | - 'version' => '1.0.22.0', |
|
67 | - 'aliases' => |
|
68 | - array ( |
|
69 | - ), |
|
70 | - 'reference' => '42b638502c9e4be0877f27903df7c7ed2080bdac', |
|
65 | + 'pretty_version' => '1.0.22', |
|
66 | + 'version' => '1.0.22.0', |
|
67 | + 'aliases' => |
|
68 | + array ( |
|
69 | + ), |
|
70 | + 'reference' => '42b638502c9e4be0877f27903df7c7ed2080bdac', |
|
71 | 71 | ), |
72 | 72 | 'composer/installers' => |
73 | 73 | array ( |
74 | - 'pretty_version' => 'v1.9.0', |
|
75 | - 'version' => '1.9.0.0', |
|
76 | - 'aliases' => |
|
77 | - array ( |
|
78 | - ), |
|
79 | - 'reference' => 'b93bcf0fa1fccb0b7d176b0967d969691cd74cca', |
|
74 | + 'pretty_version' => 'v1.9.0', |
|
75 | + 'version' => '1.9.0.0', |
|
76 | + 'aliases' => |
|
77 | + array ( |
|
78 | + ), |
|
79 | + 'reference' => 'b93bcf0fa1fccb0b7d176b0967d969691cd74cca', |
|
80 | 80 | ), |
81 | 81 | 'maxmind-db/reader' => |
82 | 82 | array ( |
83 | - 'pretty_version' => 'v1.6.0', |
|
84 | - 'version' => '1.6.0.0', |
|
85 | - 'aliases' => |
|
86 | - array ( |
|
87 | - ), |
|
88 | - 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
83 | + 'pretty_version' => 'v1.6.0', |
|
84 | + 'version' => '1.6.0.0', |
|
85 | + 'aliases' => |
|
86 | + array ( |
|
87 | + ), |
|
88 | + 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
89 | 89 | ), |
90 | 90 | 'roundcube/plugin-installer' => |
91 | 91 | array ( |
92 | - 'replaced' => |
|
93 | - array ( |
|
92 | + 'replaced' => |
|
93 | + array ( |
|
94 | 94 | 0 => '*', |
95 | - ), |
|
95 | + ), |
|
96 | 96 | ), |
97 | 97 | 'shama/baton' => |
98 | 98 | array ( |
99 | - 'replaced' => |
|
100 | - array ( |
|
99 | + 'replaced' => |
|
100 | + array ( |
|
101 | 101 | 0 => '*', |
102 | - ), |
|
102 | + ), |
|
103 | + ), |
|
103 | 104 | ), |
104 | - ), |
|
105 | 105 | ); |
106 | 106 | |
107 | 107 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php return array ( |
2 | - 'root' => |
|
3 | - array ( |
|
2 | + 'root' => |
|
3 | + array ( |
|
4 | 4 | 'pretty_version' => 'dev-master', |
5 | 5 | 'version' => 'dev-master', |
6 | 6 | 'aliases' => |
@@ -8,85 +8,85 @@ discard block |
||
8 | 8 | ), |
9 | 9 | 'reference' => '58e08ab4fbfabf9d48bdecf0dce878830040d4ea', |
10 | 10 | 'name' => 'ayecode/invoicing', |
11 | - ), |
|
12 | - 'versions' => |
|
13 | - array ( |
|
11 | + ), |
|
12 | + 'versions' => |
|
13 | + array ( |
|
14 | 14 | 'ayecode/ayecode-connect-helper' => |
15 | 15 | array ( |
16 | - 'pretty_version' => '1.0.3', |
|
17 | - 'version' => '1.0.3.0', |
|
18 | - 'aliases' => |
|
19 | - array ( |
|
20 | - ), |
|
21 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
16 | + 'pretty_version' => '1.0.3', |
|
17 | + 'version' => '1.0.3.0', |
|
18 | + 'aliases' => |
|
19 | + array ( |
|
20 | + ), |
|
21 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
22 | 22 | ), |
23 | 23 | 'ayecode/invoicing' => |
24 | 24 | array ( |
25 | - 'pretty_version' => 'dev-master', |
|
26 | - 'version' => 'dev-master', |
|
27 | - 'aliases' => |
|
28 | - array ( |
|
29 | - ), |
|
30 | - 'reference' => '58e08ab4fbfabf9d48bdecf0dce878830040d4ea', |
|
25 | + 'pretty_version' => 'dev-master', |
|
26 | + 'version' => 'dev-master', |
|
27 | + 'aliases' => |
|
28 | + array ( |
|
29 | + ), |
|
30 | + 'reference' => '58e08ab4fbfabf9d48bdecf0dce878830040d4ea', |
|
31 | 31 | ), |
32 | 32 | 'ayecode/wp-ayecode-ui' => |
33 | 33 | array ( |
34 | - 'pretty_version' => '0.1.35', |
|
35 | - 'version' => '0.1.35.0', |
|
36 | - 'aliases' => |
|
37 | - array ( |
|
38 | - ), |
|
39 | - 'reference' => 'e5d7955f648c6b350a8fe72e0110b8d78645c60f', |
|
34 | + 'pretty_version' => '0.1.35', |
|
35 | + 'version' => '0.1.35.0', |
|
36 | + 'aliases' => |
|
37 | + array ( |
|
38 | + ), |
|
39 | + 'reference' => 'e5d7955f648c6b350a8fe72e0110b8d78645c60f', |
|
40 | 40 | ), |
41 | 41 | 'ayecode/wp-font-awesome-settings' => |
42 | 42 | array ( |
43 | - 'pretty_version' => '1.0.12', |
|
44 | - 'version' => '1.0.12.0', |
|
45 | - 'aliases' => |
|
46 | - array ( |
|
47 | - ), |
|
48 | - 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
43 | + 'pretty_version' => '1.0.12', |
|
44 | + 'version' => '1.0.12.0', |
|
45 | + 'aliases' => |
|
46 | + array ( |
|
47 | + ), |
|
48 | + 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
49 | 49 | ), |
50 | 50 | 'ayecode/wp-super-duper' => |
51 | 51 | array ( |
52 | - 'pretty_version' => '1.0.22', |
|
53 | - 'version' => '1.0.22.0', |
|
54 | - 'aliases' => |
|
55 | - array ( |
|
56 | - ), |
|
57 | - 'reference' => '42b638502c9e4be0877f27903df7c7ed2080bdac', |
|
52 | + 'pretty_version' => '1.0.22', |
|
53 | + 'version' => '1.0.22.0', |
|
54 | + 'aliases' => |
|
55 | + array ( |
|
56 | + ), |
|
57 | + 'reference' => '42b638502c9e4be0877f27903df7c7ed2080bdac', |
|
58 | 58 | ), |
59 | 59 | 'composer/installers' => |
60 | 60 | array ( |
61 | - 'pretty_version' => 'v1.9.0', |
|
62 | - 'version' => '1.9.0.0', |
|
63 | - 'aliases' => |
|
64 | - array ( |
|
65 | - ), |
|
66 | - 'reference' => 'b93bcf0fa1fccb0b7d176b0967d969691cd74cca', |
|
61 | + 'pretty_version' => 'v1.9.0', |
|
62 | + 'version' => '1.9.0.0', |
|
63 | + 'aliases' => |
|
64 | + array ( |
|
65 | + ), |
|
66 | + 'reference' => 'b93bcf0fa1fccb0b7d176b0967d969691cd74cca', |
|
67 | 67 | ), |
68 | 68 | 'maxmind-db/reader' => |
69 | 69 | array ( |
70 | - 'pretty_version' => 'v1.6.0', |
|
71 | - 'version' => '1.6.0.0', |
|
72 | - 'aliases' => |
|
73 | - array ( |
|
74 | - ), |
|
75 | - 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
70 | + 'pretty_version' => 'v1.6.0', |
|
71 | + 'version' => '1.6.0.0', |
|
72 | + 'aliases' => |
|
73 | + array ( |
|
74 | + ), |
|
75 | + 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
76 | 76 | ), |
77 | 77 | 'roundcube/plugin-installer' => |
78 | 78 | array ( |
79 | - 'replaced' => |
|
80 | - array ( |
|
79 | + 'replaced' => |
|
80 | + array ( |
|
81 | 81 | 0 => '*', |
82 | - ), |
|
82 | + ), |
|
83 | 83 | ), |
84 | 84 | 'shama/baton' => |
85 | 85 | array ( |
86 | - 'replaced' => |
|
87 | - array ( |
|
86 | + 'replaced' => |
|
87 | + array ( |
|
88 | 88 | 0 => '*', |
89 | - ), |
|
89 | + ), |
|
90 | + ), |
|
90 | 91 | ), |
91 | - ), |
|
92 | 92 | ); |
@@ -15,322 +15,322 @@ |
||
15 | 15 | class GetPaid_Post_Types { |
16 | 16 | |
17 | 17 | /** |
18 | - * Hook in methods. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
21 | - add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | - add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | - add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | - add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
25 | - } |
|
18 | + * Hook in methods. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | + add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | + add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | + add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | + add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Register core post types. |
|
29 | - */ |
|
30 | - public static function register_post_types() { |
|
27 | + /** |
|
28 | + * Register core post types. |
|
29 | + */ |
|
30 | + public static function register_post_types() { |
|
31 | 31 | |
32 | - if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
33 | - return; |
|
34 | - } |
|
32 | + if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - // Fires before registering post types. |
|
37 | - do_action( 'getpaid_register_post_types' ); |
|
36 | + // Fires before registering post types. |
|
37 | + do_action( 'getpaid_register_post_types' ); |
|
38 | 38 | |
39 | - // Register item post type. |
|
40 | - register_post_type( |
|
41 | - 'wpi_item', |
|
42 | - apply_filters( |
|
43 | - 'wpinv_register_post_type_invoice_item', |
|
44 | - array( |
|
45 | - 'labels' => array( |
|
46 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
47 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
48 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
49 | - 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
50 | - 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
51 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
52 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
53 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
54 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
55 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
56 | - 'search_items' => __( 'Search items', 'invoicing' ), |
|
57 | - 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
58 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
59 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
60 | - ), |
|
61 | - 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
62 | - 'public' => false, |
|
63 | - 'has_archive' => false, |
|
64 | - '_builtin' => false, |
|
65 | - 'show_ui' => true, |
|
66 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
67 | - 'show_in_nav_menus' => false, |
|
68 | - 'supports' => array( 'title', 'excerpt', 'thumbnail' ), |
|
69 | - 'rewrite' => false, |
|
70 | - 'query_var' => false, |
|
71 | - 'capability_type' => 'wpi_item', |
|
72 | - 'map_meta_cap' => true, |
|
73 | - 'show_in_admin_bar' => true, |
|
74 | - 'can_export' => true, |
|
75 | - ) |
|
76 | - ) |
|
77 | - ); |
|
39 | + // Register item post type. |
|
40 | + register_post_type( |
|
41 | + 'wpi_item', |
|
42 | + apply_filters( |
|
43 | + 'wpinv_register_post_type_invoice_item', |
|
44 | + array( |
|
45 | + 'labels' => array( |
|
46 | + 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
47 | + 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
48 | + 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
49 | + 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
50 | + 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
51 | + 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
52 | + 'new_item' => __( 'New Item', 'invoicing' ), |
|
53 | + 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
54 | + 'view_item' => __( 'View Item', 'invoicing' ), |
|
55 | + 'all_items' => __( 'Items', 'invoicing' ), |
|
56 | + 'search_items' => __( 'Search items', 'invoicing' ), |
|
57 | + 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
58 | + 'not_found' => __( 'No items found.', 'invoicing' ), |
|
59 | + 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
60 | + ), |
|
61 | + 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
62 | + 'public' => false, |
|
63 | + 'has_archive' => false, |
|
64 | + '_builtin' => false, |
|
65 | + 'show_ui' => true, |
|
66 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
67 | + 'show_in_nav_menus' => false, |
|
68 | + 'supports' => array( 'title', 'excerpt', 'thumbnail' ), |
|
69 | + 'rewrite' => false, |
|
70 | + 'query_var' => false, |
|
71 | + 'capability_type' => 'wpi_item', |
|
72 | + 'map_meta_cap' => true, |
|
73 | + 'show_in_admin_bar' => true, |
|
74 | + 'can_export' => true, |
|
75 | + ) |
|
76 | + ) |
|
77 | + ); |
|
78 | 78 | |
79 | - // Register payment form post type. |
|
80 | - register_post_type( |
|
81 | - 'wpi_payment_form', |
|
82 | - apply_filters( |
|
83 | - 'wpinv_register_post_type_payment_form', |
|
84 | - array( |
|
85 | - 'labels' => array( |
|
86 | - 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
87 | - 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
88 | - 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
89 | - 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
90 | - 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
91 | - 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
92 | - 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
93 | - 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
94 | - 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
95 | - 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
96 | - 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
97 | - 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
98 | - 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
99 | - 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
100 | - ), |
|
101 | - 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
102 | - 'public' => false, |
|
103 | - 'show_ui' => true, |
|
104 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
|
105 | - 'show_in_nav_menus' => false, |
|
106 | - 'query_var' => false, |
|
107 | - 'rewrite' => true, |
|
108 | - 'map_meta_cap' => true, |
|
109 | - 'has_archive' => false, |
|
110 | - 'hierarchical' => false, |
|
111 | - 'menu_position' => null, |
|
112 | - 'supports' => array( 'title' ), |
|
113 | - 'menu_icon' => 'dashicons-media-form', |
|
114 | - ) |
|
115 | - ) |
|
116 | - ); |
|
79 | + // Register payment form post type. |
|
80 | + register_post_type( |
|
81 | + 'wpi_payment_form', |
|
82 | + apply_filters( |
|
83 | + 'wpinv_register_post_type_payment_form', |
|
84 | + array( |
|
85 | + 'labels' => array( |
|
86 | + 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
87 | + 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
88 | + 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
89 | + 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
90 | + 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
91 | + 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
92 | + 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
93 | + 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
94 | + 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
95 | + 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
96 | + 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
97 | + 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
98 | + 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
99 | + 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
100 | + ), |
|
101 | + 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
102 | + 'public' => false, |
|
103 | + 'show_ui' => true, |
|
104 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
|
105 | + 'show_in_nav_menus' => false, |
|
106 | + 'query_var' => false, |
|
107 | + 'rewrite' => true, |
|
108 | + 'map_meta_cap' => true, |
|
109 | + 'has_archive' => false, |
|
110 | + 'hierarchical' => false, |
|
111 | + 'menu_position' => null, |
|
112 | + 'supports' => array( 'title' ), |
|
113 | + 'menu_icon' => 'dashicons-media-form', |
|
114 | + ) |
|
115 | + ) |
|
116 | + ); |
|
117 | 117 | |
118 | - // Register invoice post type. |
|
119 | - register_post_type( |
|
120 | - 'wpi_invoice', |
|
121 | - apply_filters( |
|
122 | - 'wpinv_register_post_type_invoice', |
|
123 | - array( |
|
124 | - 'labels' => array( |
|
125 | - 'name' => __( 'Invoices', 'invoicing' ), |
|
126 | - 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
127 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
128 | - 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
129 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
130 | - 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
131 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
132 | - 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
133 | - 'new_item' => __( 'New invoice', 'invoicing' ), |
|
134 | - 'view_item' => __( 'View invoice', 'invoicing' ), |
|
135 | - 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
136 | - 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
137 | - 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
138 | - 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
139 | - 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
140 | - 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
141 | - 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
142 | - 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
143 | - 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
144 | - 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
145 | - 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
146 | - 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
147 | - 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
148 | - 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
149 | - ), |
|
150 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
151 | - 'public' => true, |
|
152 | - 'has_archive' => false, |
|
153 | - 'publicly_queryable' => true, |
|
154 | - 'exclude_from_search' => true, |
|
155 | - 'show_ui' => true, |
|
156 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
157 | - 'show_in_nav_menus' => false, |
|
158 | - 'supports' => array( 'title', 'author', 'excerpt' ), |
|
159 | - 'rewrite' => array( |
|
160 | - 'slug' => 'invoice', |
|
161 | - 'with_front' => false, |
|
162 | - ), |
|
163 | - 'query_var' => false, |
|
164 | - 'capability_type' => 'wpi_invoice', |
|
165 | - 'map_meta_cap' => true, |
|
166 | - 'show_in_admin_bar' => true, |
|
167 | - 'can_export' => true, |
|
168 | - 'hierarchical' => false, |
|
169 | - 'menu_position' => null, |
|
170 | - 'menu_icon' => 'dashicons-media-spreadsheet', |
|
171 | - ) |
|
172 | - ) |
|
173 | - ); |
|
118 | + // Register invoice post type. |
|
119 | + register_post_type( |
|
120 | + 'wpi_invoice', |
|
121 | + apply_filters( |
|
122 | + 'wpinv_register_post_type_invoice', |
|
123 | + array( |
|
124 | + 'labels' => array( |
|
125 | + 'name' => __( 'Invoices', 'invoicing' ), |
|
126 | + 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
127 | + 'all_items' => __( 'Invoices', 'invoicing' ), |
|
128 | + 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
129 | + 'add_new' => __( 'Add New', 'invoicing' ), |
|
130 | + 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
131 | + 'edit' => __( 'Edit', 'invoicing' ), |
|
132 | + 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
133 | + 'new_item' => __( 'New invoice', 'invoicing' ), |
|
134 | + 'view_item' => __( 'View invoice', 'invoicing' ), |
|
135 | + 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
136 | + 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
137 | + 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
138 | + 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
139 | + 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
140 | + 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
141 | + 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
142 | + 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
143 | + 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
144 | + 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
145 | + 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
146 | + 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
147 | + 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
148 | + 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
149 | + ), |
|
150 | + 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
151 | + 'public' => true, |
|
152 | + 'has_archive' => false, |
|
153 | + 'publicly_queryable' => true, |
|
154 | + 'exclude_from_search' => true, |
|
155 | + 'show_ui' => true, |
|
156 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
157 | + 'show_in_nav_menus' => false, |
|
158 | + 'supports' => array( 'title', 'author', 'excerpt' ), |
|
159 | + 'rewrite' => array( |
|
160 | + 'slug' => 'invoice', |
|
161 | + 'with_front' => false, |
|
162 | + ), |
|
163 | + 'query_var' => false, |
|
164 | + 'capability_type' => 'wpi_invoice', |
|
165 | + 'map_meta_cap' => true, |
|
166 | + 'show_in_admin_bar' => true, |
|
167 | + 'can_export' => true, |
|
168 | + 'hierarchical' => false, |
|
169 | + 'menu_position' => null, |
|
170 | + 'menu_icon' => 'dashicons-media-spreadsheet', |
|
171 | + ) |
|
172 | + ) |
|
173 | + ); |
|
174 | 174 | |
175 | - // Register discount post type. |
|
176 | - register_post_type( |
|
177 | - 'wpi_discount', |
|
178 | - apply_filters( |
|
179 | - 'wpinv_register_post_type_discount', |
|
180 | - array( |
|
181 | - 'labels' => array( |
|
182 | - 'name' => __( 'Discounts', 'invoicing' ), |
|
183 | - 'singular_name' => __( 'Discount', 'invoicing' ), |
|
184 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
185 | - 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
186 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
187 | - 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
188 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
189 | - 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
190 | - 'new_item' => __( 'New discount', 'invoicing' ), |
|
191 | - 'view_item' => __( 'View discount', 'invoicing' ), |
|
192 | - 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
193 | - 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
194 | - 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
195 | - 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
196 | - 'parent' => __( 'Parent discount', 'invoicing' ), |
|
197 | - 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
198 | - 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
199 | - 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
200 | - 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
201 | - 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
202 | - 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
203 | - 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
204 | - 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
205 | - 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
206 | - ), |
|
207 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
208 | - 'public' => false, |
|
209 | - 'can_export' => true, |
|
210 | - '_builtin' => false, |
|
211 | - 'publicly_queryable' => false, |
|
212 | - 'exclude_from_search'=> true, |
|
213 | - 'show_ui' => true, |
|
214 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
215 | - 'query_var' => false, |
|
216 | - 'rewrite' => false, |
|
217 | - 'capability_type' => 'wpi_discount', |
|
218 | - 'map_meta_cap' => true, |
|
219 | - 'has_archive' => false, |
|
220 | - 'hierarchical' => false, |
|
221 | - 'supports' => array( 'title', 'excerpt' ), |
|
222 | - 'show_in_nav_menus' => false, |
|
223 | - 'show_in_admin_bar' => true, |
|
224 | - 'menu_position' => null, |
|
225 | - ) |
|
226 | - ) |
|
227 | - ); |
|
175 | + // Register discount post type. |
|
176 | + register_post_type( |
|
177 | + 'wpi_discount', |
|
178 | + apply_filters( |
|
179 | + 'wpinv_register_post_type_discount', |
|
180 | + array( |
|
181 | + 'labels' => array( |
|
182 | + 'name' => __( 'Discounts', 'invoicing' ), |
|
183 | + 'singular_name' => __( 'Discount', 'invoicing' ), |
|
184 | + 'all_items' => __( 'Discounts', 'invoicing' ), |
|
185 | + 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
186 | + 'add_new' => __( 'Add New', 'invoicing' ), |
|
187 | + 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
188 | + 'edit' => __( 'Edit', 'invoicing' ), |
|
189 | + 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
190 | + 'new_item' => __( 'New discount', 'invoicing' ), |
|
191 | + 'view_item' => __( 'View discount', 'invoicing' ), |
|
192 | + 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
193 | + 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
194 | + 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
195 | + 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
196 | + 'parent' => __( 'Parent discount', 'invoicing' ), |
|
197 | + 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
198 | + 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
199 | + 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
200 | + 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
201 | + 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
202 | + 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
203 | + 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
204 | + 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
205 | + 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
206 | + ), |
|
207 | + 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
208 | + 'public' => false, |
|
209 | + 'can_export' => true, |
|
210 | + '_builtin' => false, |
|
211 | + 'publicly_queryable' => false, |
|
212 | + 'exclude_from_search'=> true, |
|
213 | + 'show_ui' => true, |
|
214 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
215 | + 'query_var' => false, |
|
216 | + 'rewrite' => false, |
|
217 | + 'capability_type' => 'wpi_discount', |
|
218 | + 'map_meta_cap' => true, |
|
219 | + 'has_archive' => false, |
|
220 | + 'hierarchical' => false, |
|
221 | + 'supports' => array( 'title', 'excerpt' ), |
|
222 | + 'show_in_nav_menus' => false, |
|
223 | + 'show_in_admin_bar' => true, |
|
224 | + 'menu_position' => null, |
|
225 | + ) |
|
226 | + ) |
|
227 | + ); |
|
228 | 228 | |
229 | - do_action( 'getpaid_after_register_post_types' ); |
|
230 | - } |
|
229 | + do_action( 'getpaid_after_register_post_types' ); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Register our custom post statuses. |
|
234 | - */ |
|
235 | - public static function register_post_status() { |
|
232 | + /** |
|
233 | + * Register our custom post statuses. |
|
234 | + */ |
|
235 | + public static function register_post_status() { |
|
236 | 236 | |
237 | - $invoice_statuses = apply_filters( |
|
238 | - 'getpaid_register_invoice_post_statuses', |
|
239 | - array( |
|
237 | + $invoice_statuses = apply_filters( |
|
238 | + 'getpaid_register_invoice_post_statuses', |
|
239 | + array( |
|
240 | 240 | |
241 | - 'wpi-pending' => array( |
|
242 | - 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
243 | - 'public' => true, |
|
244 | - 'exclude_from_search' => true, |
|
245 | - 'show_in_admin_all_list' => true, |
|
246 | - 'show_in_admin_status_list' => true, |
|
247 | - /* translators: %s: number of invoices */ |
|
248 | - 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
249 | - ), |
|
241 | + 'wpi-pending' => array( |
|
242 | + 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
243 | + 'public' => true, |
|
244 | + 'exclude_from_search' => true, |
|
245 | + 'show_in_admin_all_list' => true, |
|
246 | + 'show_in_admin_status_list' => true, |
|
247 | + /* translators: %s: number of invoices */ |
|
248 | + 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
249 | + ), |
|
250 | 250 | |
251 | - 'wpi-processing' => array( |
|
252 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
253 | - 'public' => true, |
|
254 | - 'exclude_from_search' => true, |
|
255 | - 'show_in_admin_all_list' => true, |
|
256 | - 'show_in_admin_status_list' => true, |
|
257 | - /* translators: %s: number of invoices */ |
|
258 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
259 | - ), |
|
251 | + 'wpi-processing' => array( |
|
252 | + 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
253 | + 'public' => true, |
|
254 | + 'exclude_from_search' => true, |
|
255 | + 'show_in_admin_all_list' => true, |
|
256 | + 'show_in_admin_status_list' => true, |
|
257 | + /* translators: %s: number of invoices */ |
|
258 | + 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
259 | + ), |
|
260 | 260 | |
261 | - 'wpi-onhold' => array( |
|
262 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
263 | - 'public' => true, |
|
264 | - 'exclude_from_search' => true, |
|
265 | - 'show_in_admin_all_list' => true, |
|
266 | - 'show_in_admin_status_list' => true, |
|
267 | - /* translators: %s: number of invoices */ |
|
268 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
269 | - ), |
|
261 | + 'wpi-onhold' => array( |
|
262 | + 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
263 | + 'public' => true, |
|
264 | + 'exclude_from_search' => true, |
|
265 | + 'show_in_admin_all_list' => true, |
|
266 | + 'show_in_admin_status_list' => true, |
|
267 | + /* translators: %s: number of invoices */ |
|
268 | + 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
269 | + ), |
|
270 | 270 | |
271 | - 'wpi-cancelled' => array( |
|
272 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
273 | - 'public' => true, |
|
274 | - 'exclude_from_search' => true, |
|
275 | - 'show_in_admin_all_list' => true, |
|
276 | - 'show_in_admin_status_list' => true, |
|
277 | - /* translators: %s: number of invoices */ |
|
278 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
279 | - ), |
|
271 | + 'wpi-cancelled' => array( |
|
272 | + 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
273 | + 'public' => true, |
|
274 | + 'exclude_from_search' => true, |
|
275 | + 'show_in_admin_all_list' => true, |
|
276 | + 'show_in_admin_status_list' => true, |
|
277 | + /* translators: %s: number of invoices */ |
|
278 | + 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
279 | + ), |
|
280 | 280 | |
281 | - 'wpi-refunded' => array( |
|
282 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
283 | - 'public' => true, |
|
284 | - 'exclude_from_search' => true, |
|
285 | - 'show_in_admin_all_list' => true, |
|
286 | - 'show_in_admin_status_list' => true, |
|
287 | - /* translators: %s: number of invoices */ |
|
288 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
289 | - ), |
|
281 | + 'wpi-refunded' => array( |
|
282 | + 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
283 | + 'public' => true, |
|
284 | + 'exclude_from_search' => true, |
|
285 | + 'show_in_admin_all_list' => true, |
|
286 | + 'show_in_admin_status_list' => true, |
|
287 | + /* translators: %s: number of invoices */ |
|
288 | + 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
289 | + ), |
|
290 | 290 | |
291 | - 'wpi-failed' => array( |
|
292 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
293 | - 'public' => true, |
|
294 | - 'exclude_from_search' => true, |
|
295 | - 'show_in_admin_all_list' => true, |
|
296 | - 'show_in_admin_status_list' => true, |
|
297 | - /* translators: %s: number of invoices */ |
|
298 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
299 | - ), |
|
291 | + 'wpi-failed' => array( |
|
292 | + 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
293 | + 'public' => true, |
|
294 | + 'exclude_from_search' => true, |
|
295 | + 'show_in_admin_all_list' => true, |
|
296 | + 'show_in_admin_status_list' => true, |
|
297 | + /* translators: %s: number of invoices */ |
|
298 | + 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
299 | + ), |
|
300 | 300 | |
301 | - 'wpi-renewal' => array( |
|
302 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
303 | - 'public' => true, |
|
304 | - 'exclude_from_search' => true, |
|
305 | - 'show_in_admin_all_list' => true, |
|
306 | - 'show_in_admin_status_list' => true, |
|
307 | - /* translators: %s: number of invoices */ |
|
308 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
309 | - ) |
|
310 | - ) |
|
311 | - ); |
|
301 | + 'wpi-renewal' => array( |
|
302 | + 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
303 | + 'public' => true, |
|
304 | + 'exclude_from_search' => true, |
|
305 | + 'show_in_admin_all_list' => true, |
|
306 | + 'show_in_admin_status_list' => true, |
|
307 | + /* translators: %s: number of invoices */ |
|
308 | + 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
309 | + ) |
|
310 | + ) |
|
311 | + ); |
|
312 | 312 | |
313 | - foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
314 | - register_post_status( $invoice_statuse, $args ); |
|
315 | - } |
|
316 | - } |
|
313 | + foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
314 | + register_post_status( $invoice_statuse, $args ); |
|
315 | + } |
|
316 | + } |
|
317 | 317 | |
318 | - /** |
|
319 | - * Flush rewrite rules. |
|
320 | - */ |
|
321 | - public static function flush_rewrite_rules() { |
|
322 | - flush_rewrite_rules(); |
|
323 | - } |
|
318 | + /** |
|
319 | + * Flush rewrite rules. |
|
320 | + */ |
|
321 | + public static function flush_rewrite_rules() { |
|
322 | + flush_rewrite_rules(); |
|
323 | + } |
|
324 | 324 | |
325 | - /** |
|
326 | - * Flush rules to prevent 404. |
|
327 | - * |
|
328 | - */ |
|
329 | - public static function maybe_flush_rewrite_rules() { |
|
330 | - if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
331 | - update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
332 | - self::flush_rewrite_rules(); |
|
333 | - } |
|
334 | - } |
|
325 | + /** |
|
326 | + * Flush rules to prevent 404. |
|
327 | + * |
|
328 | + */ |
|
329 | + public static function maybe_flush_rewrite_rules() { |
|
330 | + if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
331 | + update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
332 | + self::flush_rewrite_rules(); |
|
333 | + } |
|
334 | + } |
|
335 | 335 | |
336 | 336 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,22 +15,22 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Meta_Box_Invoice_Shipping_Address { |
17 | 17 | |
18 | - /** |
|
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
23 | - public static function output( $post ) { |
|
18 | + /** |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | + public static function output( $post ) { |
|
24 | 24 | |
25 | - // Retrieve shipping address. |
|
26 | - $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
25 | + // Retrieve shipping address. |
|
26 | + $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
27 | 27 | |
28 | - // Abort if it is invalid. |
|
29 | - if ( ! is_array( $shipping_address ) ) { |
|
30 | - return; |
|
31 | - } |
|
28 | + // Abort if it is invalid. |
|
29 | + if ( ! is_array( $shipping_address ) ) { |
|
30 | + return; |
|
31 | + } |
|
32 | 32 | |
33 | - ?> |
|
33 | + ?> |
|
34 | 34 | |
35 | 35 | <div class="bsui"> |
36 | 36 | |
@@ -55,31 +55,31 @@ discard block |
||
55 | 55 | |
56 | 56 | <?php |
57 | 57 | |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Prepares a value. |
|
62 | - * |
|
63 | - * @param array $address |
|
64 | - * @param string $key |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public static function prepare_for_display( $address, $key ) { |
|
60 | + /** |
|
61 | + * Prepares a value. |
|
62 | + * |
|
63 | + * @param array $address |
|
64 | + * @param string $key |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public static function prepare_for_display( $address, $key ) { |
|
68 | 68 | |
69 | - // Prepare the value. |
|
70 | - $value = $address[ $key ]; |
|
69 | + // Prepare the value. |
|
70 | + $value = $address[ $key ]; |
|
71 | 71 | |
72 | - if ( $key == 'country' ) { |
|
73 | - $value = wpinv_country_name( $value ); |
|
74 | - } |
|
72 | + if ( $key == 'country' ) { |
|
73 | + $value = wpinv_country_name( $value ); |
|
74 | + } |
|
75 | 75 | |
76 | - if ( $key == 'state' ) { |
|
77 | - $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
78 | - $value = wpinv_state_name( $value, $country ); |
|
79 | - } |
|
76 | + if ( $key == 'state' ) { |
|
77 | + $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
78 | + $value = wpinv_state_name( $value, $country ); |
|
79 | + } |
|
80 | 80 | |
81 | - return sanitize_text_field( $value ); |
|
81 | + return sanitize_text_field( $value ); |
|
82 | 82 | |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |