@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | function wpinv_get_default_country() { |
| 16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
| 16 | + $country = wpinv_get_option('default_country', 'UK'); |
|
| 17 | 17 | |
| 18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
| 18 | + return apply_filters('wpinv_default_country', $country); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -24,59 +24,59 @@ discard block |
||
| 24 | 24 | * @param string $country The country code to sanitize |
| 25 | 25 | * @return array |
| 26 | 26 | */ |
| 27 | -function wpinv_sanitize_country( $country ) { |
|
| 27 | +function wpinv_sanitize_country($country) { |
|
| 28 | 28 | |
| 29 | 29 | // Enure the country is specified |
| 30 | - if ( empty( $country ) ) { |
|
| 30 | + if (empty($country)) { |
|
| 31 | 31 | $country = wpinv_get_default_country(); |
| 32 | 32 | } |
| 33 | - return trim( wpinv_utf8_strtoupper( $country ) ); |
|
| 33 | + return trim(wpinv_utf8_strtoupper($country)); |
|
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | -function wpinv_is_base_country( $country ) { |
|
| 37 | +function wpinv_is_base_country($country) { |
|
| 38 | 38 | $base_country = wpinv_get_default_country(); |
| 39 | 39 | |
| 40 | - if ( $base_country === 'UK' ) { |
|
| 40 | + if ($base_country === 'UK') { |
|
| 41 | 41 | $base_country = 'GB'; |
| 42 | 42 | } |
| 43 | - if ( $country == 'UK' ) { |
|
| 43 | + if ($country == 'UK') { |
|
| 44 | 44 | $country = 'GB'; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - return ( $country && $country === $base_country ) ? true : false; |
|
| 47 | + return ($country && $country === $base_country) ? true : false; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | -function wpinv_country_name( $country_code = '' ) { |
|
| 50 | +function wpinv_country_name($country_code = '') { |
|
| 51 | 51 | $countries = wpinv_get_country_list(); |
| 52 | 52 | $country_code = $country_code == 'UK' ? 'GB' : $country_code; |
| 53 | - $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code; |
|
| 53 | + $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code; |
|
| 54 | 54 | |
| 55 | - return apply_filters( 'wpinv_country_name', $country, $country_code ); |
|
| 55 | + return apply_filters('wpinv_country_name', $country, $country_code); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function wpinv_get_default_state() { |
| 59 | - $state = wpinv_get_option( 'default_state', false ); |
|
| 59 | + $state = wpinv_get_option('default_state', false); |
|
| 60 | 60 | |
| 61 | - return apply_filters( 'wpinv_default_state', $state ); |
|
| 61 | + return apply_filters('wpinv_default_state', $state); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | -function wpinv_state_name( $state_code = '', $country_code = '' ) { |
|
| 64 | +function wpinv_state_name($state_code = '', $country_code = '') { |
|
| 65 | 65 | $state = $state_code; |
| 66 | 66 | |
| 67 | - if ( !empty( $country_code ) ) { |
|
| 68 | - $states = wpinv_get_country_states( $country_code ); |
|
| 67 | + if (!empty($country_code)) { |
|
| 68 | + $states = wpinv_get_country_states($country_code); |
|
| 69 | 69 | |
| 70 | - $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state; |
|
| 70 | + $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
|
| 73 | + return apply_filters('wpinv_state_name', $state, $state_code, $country_code); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | function wpinv_store_address() { |
| 77 | - $address = wpinv_get_option( 'store_address', '' ); |
|
| 77 | + $address = wpinv_get_option('store_address', ''); |
|
| 78 | 78 | |
| 79 | - return apply_filters( 'wpinv_store_address', $address ); |
|
| 79 | + return apply_filters('wpinv_store_address', $address); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -109,24 +109,24 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @param WPInv_Invoice $invoice |
| 111 | 111 | */ |
| 112 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
| 112 | +function getpaid_save_invoice_user_address($invoice) { |
|
| 113 | 113 | |
| 114 | 114 | // Retrieve the invoice. |
| 115 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 115 | + $invoice = wpinv_get_invoice($invoice); |
|
| 116 | 116 | |
| 117 | 117 | // Abort if it does not exist. |
| 118 | - if ( empty( $invoice ) ) { |
|
| 118 | + if (empty($invoice)) { |
|
| 119 | 119 | return; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - foreach ( getpaid_user_address_fields() as $field ) { |
|
| 122 | + foreach (getpaid_user_address_fields() as $field) { |
|
| 123 | 123 | |
| 124 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
| 125 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
| 124 | + if (is_callable(array($invoice, "get_$field"))) { |
|
| 125 | + $value = call_user_func(array($invoice, "get_$field")); |
|
| 126 | 126 | |
| 127 | 127 | // Only save if it is not empty. |
| 128 | - if ( ! empty( $value ) ) { |
|
| 129 | - update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value ); |
|
| 128 | + if (!empty($value)) { |
|
| 129 | + update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | } |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | } |
| 137 | -add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' ); |
|
| 138 | -add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' ); |
|
| 137 | +add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address'); |
|
| 138 | +add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address'); |
|
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * Retrieves a saved user address. |
@@ -144,14 +144,14 @@ discard block |
||
| 144 | 144 | * @param bool $with_default Whether or not we should use the default country and state. |
| 145 | 145 | * @return array |
| 146 | 146 | */ |
| 147 | -function wpinv_get_user_address( $user_id = 0, $with_default = true ) { |
|
| 147 | +function wpinv_get_user_address($user_id = 0, $with_default = true) { |
|
| 148 | 148 | |
| 149 | 149 | // Prepare the user id. |
| 150 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
| 151 | - $user_info = get_userdata( $user_id ); |
|
| 150 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
| 151 | + $user_info = get_userdata($user_id); |
|
| 152 | 152 | |
| 153 | 153 | // Abort if non exists. |
| 154 | - if ( empty( $user_info ) ) { |
|
| 154 | + if (empty($user_info)) { |
|
| 155 | 155 | return array(); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -161,27 +161,27 @@ discard block |
||
| 161 | 161 | 'email' => $user_info->user_email, |
| 162 | 162 | ); |
| 163 | 163 | |
| 164 | - foreach ( getpaid_user_address_fields() as $field ) { |
|
| 165 | - $address[$field] = getpaid_get_user_address_field( $user_id, $field ); |
|
| 164 | + foreach (getpaid_user_address_fields() as $field) { |
|
| 165 | + $address[$field] = getpaid_get_user_address_field($user_id, $field); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if ( ! $with_default ) { |
|
| 168 | + if (!$with_default) { |
|
| 169 | 169 | return $address; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if ( isset( $address['first_name'] ) && empty( $address['first_name'] ) ) { |
|
| 172 | + if (isset($address['first_name']) && empty($address['first_name'])) { |
|
| 173 | 173 | $address['first_name'] = $user_info->first_name; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if ( isset( $address['last_name'] ) && empty( $address['last_name'] ) ) { |
|
| 176 | + if (isset($address['last_name']) && empty($address['last_name'])) { |
|
| 177 | 177 | $address['last_name'] = $user_info->last_name; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if ( isset( $address['state'] ) && empty( $address['state'] ) ) { |
|
| 180 | + if (isset($address['state']) && empty($address['state'])) { |
|
| 181 | 181 | $address['state'] = wpinv_get_default_state(); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if ( isset( $address['country'] ) && empty( $address['country'] ) ) { |
|
| 184 | + if (isset($address['country']) && empty($address['country'])) { |
|
| 185 | 185 | $address['country'] = wpinv_get_default_country(); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @param string $field The field to use. |
| 196 | 196 | * @return string|null |
| 197 | 197 | */ |
| 198 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
| 198 | +function getpaid_get_user_address_field($user_id, $field) { |
|
| 199 | 199 | |
| 200 | 200 | $prefixes = array( |
| 201 | 201 | '_wpinv_', |
@@ -203,15 +203,15 @@ discard block |
||
| 203 | 203 | '' |
| 204 | 204 | ); |
| 205 | 205 | |
| 206 | - foreach ( $prefixes as $prefix ) { |
|
| 206 | + foreach ($prefixes as $prefix) { |
|
| 207 | 207 | |
| 208 | 208 | // Meta table. |
| 209 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
| 209 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
| 210 | 210 | |
| 211 | 211 | // UWP table. |
| 212 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
| 212 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
| 213 | 213 | |
| 214 | - if ( ! empty( $value ) ) { |
|
| 214 | + if (!empty($value)) { |
|
| 215 | 215 | return $value; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -228,16 +228,16 @@ discard block |
||
| 228 | 228 | * @param string $return What to return. |
| 229 | 229 | * @return array |
| 230 | 230 | */ |
| 231 | -function wpinv_get_continents( $return = 'all' ) { |
|
| 231 | +function wpinv_get_continents($return = 'all') { |
|
| 232 | 232 | |
| 233 | - $continents = wpinv_get_data( 'continents' ); |
|
| 233 | + $continents = wpinv_get_data('continents'); |
|
| 234 | 234 | |
| 235 | - switch( $return ) { |
|
| 235 | + switch ($return) { |
|
| 236 | 236 | case 'name' : |
| 237 | - return wp_list_pluck( $continents, 'name' ); |
|
| 237 | + return wp_list_pluck($continents, 'name'); |
|
| 238 | 238 | break; |
| 239 | 239 | case 'countries' : |
| 240 | - return wp_list_pluck( $continents, 'countries' ); |
|
| 240 | + return wp_list_pluck($continents, 'countries'); |
|
| 241 | 241 | break; |
| 242 | 242 | default : |
| 243 | 243 | return $continents; |
@@ -253,12 +253,12 @@ discard block |
||
| 253 | 253 | * @param string $country Country code. If no code is specified, defaults to the default country. |
| 254 | 254 | * @return string |
| 255 | 255 | */ |
| 256 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
| 256 | +function wpinv_get_continent_code_for_country($country = false) { |
|
| 257 | 257 | |
| 258 | - $country = wpinv_sanitize_country( $country ); |
|
| 258 | + $country = wpinv_sanitize_country($country); |
|
| 259 | 259 | |
| 260 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
| 261 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
| 260 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
| 261 | + if (false !== array_search($country, $countries, true)) { |
|
| 262 | 262 | return $continent_code; |
| 263 | 263 | } |
| 264 | 264 | } |
@@ -274,13 +274,13 @@ discard block |
||
| 274 | 274 | * @param string $country Country code. If no code is specified, defaults to the default country. |
| 275 | 275 | * @return array |
| 276 | 276 | */ |
| 277 | -function wpinv_get_country_calling_code( $country = null) { |
|
| 277 | +function wpinv_get_country_calling_code($country = null) { |
|
| 278 | 278 | |
| 279 | - $country = wpinv_sanitize_country( $country ); |
|
| 280 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
| 281 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
| 279 | + $country = wpinv_sanitize_country($country); |
|
| 280 | + $codes = wpinv_get_data('phone-codes'); |
|
| 281 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
| 282 | 282 | |
| 283 | - if ( is_array( $code ) ) { |
|
| 283 | + if (is_array($code)) { |
|
| 284 | 284 | return $code[0]; |
| 285 | 285 | } |
| 286 | 286 | return $code; |
@@ -293,8 +293,8 @@ discard block |
||
| 293 | 293 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 294 | 294 | * @return array |
| 295 | 295 | */ |
| 296 | -function wpinv_get_country_list( $first_empty = false ) { |
|
| 297 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
| 296 | +function wpinv_get_country_list($first_empty = false) { |
|
| 297 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -304,22 +304,22 @@ discard block |
||
| 304 | 304 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 305 | 305 | * @return array |
| 306 | 306 | */ |
| 307 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
| 307 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
| 308 | 308 | |
| 309 | 309 | // Prepare the country. |
| 310 | - $country = wpinv_sanitize_country( $country ); |
|
| 310 | + $country = wpinv_sanitize_country($country); |
|
| 311 | 311 | |
| 312 | 312 | // Fetch all states. |
| 313 | - $all_states = wpinv_get_data( 'states' ); |
|
| 313 | + $all_states = wpinv_get_data('states'); |
|
| 314 | 314 | |
| 315 | 315 | // Fetch the specified country's states. |
| 316 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ; |
|
| 317 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
| 318 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
| 316 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
| 317 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
| 318 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
| 319 | 319 | |
| 320 | - asort( $states ); |
|
| 320 | + asort($states); |
|
| 321 | 321 | |
| 322 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
| 322 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @return array |
| 330 | 330 | */ |
| 331 | 331 | function wpinv_get_us_states_list() { |
| 332 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
| 332 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | * @return array |
| 340 | 340 | */ |
| 341 | 341 | function wpinv_get_canada_states_list() { |
| 342 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
| 342 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | /** |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | * @return array |
| 350 | 350 | */ |
| 351 | 351 | function wpinv_get_australia_states_list() { |
| 352 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
| 352 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * @return array |
| 360 | 360 | */ |
| 361 | 361 | function wpinv_get_bangladesh_states_list() { |
| 362 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
| 362 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | * @return array |
| 370 | 370 | */ |
| 371 | 371 | function wpinv_get_brazil_states_list() { |
| 372 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
| 372 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * @return array |
| 380 | 380 | */ |
| 381 | 381 | function wpinv_get_bulgaria_states_list() { |
| 382 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
| 382 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * @return array |
| 390 | 390 | */ |
| 391 | 391 | function wpinv_get_hong_kong_states_list() { |
| 392 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
| 392 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @return array |
| 400 | 400 | */ |
| 401 | 401 | function wpinv_get_hungary_states_list() { |
| 402 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
| 402 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | * @return array |
| 410 | 410 | */ |
| 411 | 411 | function wpinv_get_japan_states_list() { |
| 412 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
| 412 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | * @return array |
| 420 | 420 | */ |
| 421 | 421 | function wpinv_get_china_states_list() { |
| 422 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
| 422 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | /** |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | * @return array |
| 430 | 430 | */ |
| 431 | 431 | function wpinv_get_new_zealand_states_list() { |
| 432 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
| 432 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | /** |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | * @return array |
| 440 | 440 | */ |
| 441 | 441 | function wpinv_get_peru_states_list() { |
| 442 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
| 442 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | * @return array |
| 450 | 450 | */ |
| 451 | 451 | function wpinv_get_indonesia_states_list() { |
| 452 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
| 452 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | * @return array |
| 460 | 460 | */ |
| 461 | 461 | function wpinv_get_india_states_list() { |
| 462 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
| 462 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | /** |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | * @return array |
| 470 | 470 | */ |
| 471 | 471 | function wpinv_get_iran_states_list() { |
| 472 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
| 472 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | /** |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | * @return array |
| 480 | 480 | */ |
| 481 | 481 | function wpinv_get_italy_states_list() { |
| 482 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
| 482 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | * @return array |
| 490 | 490 | */ |
| 491 | 491 | function wpinv_get_malaysia_states_list() { |
| 492 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
| 492 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | * @return array |
| 500 | 500 | */ |
| 501 | 501 | function wpinv_get_mexico_states_list() { |
| 502 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
| 502 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | * @return array |
| 510 | 510 | */ |
| 511 | 511 | function wpinv_get_nepal_states_list() { |
| 512 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
| 512 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | * @return array |
| 520 | 520 | */ |
| 521 | 521 | function wpinv_get_south_africa_states_list() { |
| 522 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
| 522 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | /** |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | * @return array |
| 530 | 530 | */ |
| 531 | 531 | function wpinv_get_thailand_states_list() { |
| 532 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
| 532 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | * @return array |
| 540 | 540 | */ |
| 541 | 541 | function wpinv_get_turkey_states_list() { |
| 542 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
| 542 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | /** |
@@ -549,28 +549,28 @@ discard block |
||
| 549 | 549 | * @return array |
| 550 | 550 | */ |
| 551 | 551 | function wpinv_get_spain_states_list() { |
| 552 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
| 552 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | function wpinv_get_states_field() { |
| 556 | - if( empty( $_POST['country'] ) ) { |
|
| 556 | + if (empty($_POST['country'])) { |
|
| 557 | 557 | $_POST['country'] = wpinv_get_default_country(); |
| 558 | 558 | } |
| 559 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
| 559 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
| 560 | 560 | |
| 561 | - if( !empty( $states ) ) { |
|
| 562 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
| 561 | + if (!empty($states)) { |
|
| 562 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
| 563 | 563 | |
| 564 | 564 | $args = array( |
| 565 | 565 | 'name' => $sanitized_field_name, |
| 566 | 566 | 'id' => $sanitized_field_name, |
| 567 | 567 | 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
| 568 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
| 568 | + 'options' => array_merge(array('' => ''), $states), |
|
| 569 | 569 | 'show_option_all' => false, |
| 570 | 570 | 'show_option_none' => false |
| 571 | 571 | ); |
| 572 | 572 | |
| 573 | - $response = wpinv_html_select( $args ); |
|
| 573 | + $response = wpinv_html_select($args); |
|
| 574 | 574 | |
| 575 | 575 | } else { |
| 576 | 576 | $response = 'nostates'; |
@@ -579,10 +579,10 @@ discard block |
||
| 579 | 579 | return $response; |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
| 583 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
| 582 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
| 583 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
| 584 | 584 | |
| 585 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
| 585 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | */ |
| 595 | 595 | function wpinv_get_address_formats() { |
| 596 | 596 | |
| 597 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
| 597 | + return apply_filters('wpinv_localisation_address_formats', |
|
| 598 | 598 | array( |
| 599 | 599 | 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
| 600 | 600 | 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
@@ -643,9 +643,9 @@ discard block |
||
| 643 | 643 | * @see `wpinv_get_invoice_address_replacements` |
| 644 | 644 | * @return string |
| 645 | 645 | */ |
| 646 | -function wpinv_get_full_address_format( $country = false) { |
|
| 646 | +function wpinv_get_full_address_format($country = false) { |
|
| 647 | 647 | |
| 648 | - if( empty( $country ) ) { |
|
| 648 | + if (empty($country)) { |
|
| 649 | 649 | $country = wpinv_get_default_country(); |
| 650 | 650 | } |
| 651 | 651 | |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | $formats = wpinv_get_address_formats(); |
| 654 | 654 | |
| 655 | 655 | // Get format for the specified country. |
| 656 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
| 656 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
| 657 | 657 | |
| 658 | 658 | /** |
| 659 | 659 | * Filters the address format to use on Invoices. |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | * @param string $format The address format to use. |
| 666 | 666 | * @param string $country The country who's address format is being retrieved. |
| 667 | 667 | */ |
| 668 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
| 668 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | * @param array $billing_details customer's billing details |
| 677 | 677 | * @return array |
| 678 | 678 | */ |
| 679 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
| 679 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
| 680 | 680 | |
| 681 | 681 | $default_args = array( |
| 682 | 682 | 'address' => '', |
@@ -689,22 +689,22 @@ discard block |
||
| 689 | 689 | 'company' => '', |
| 690 | 690 | ); |
| 691 | 691 | |
| 692 | - $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
|
| 692 | + $args = map_deep(wp_parse_args($billing_details, $default_args), 'trim'); |
|
| 693 | 693 | $state = $args['state']; |
| 694 | 694 | $country = $args['country']; |
| 695 | 695 | |
| 696 | 696 | // Handle full country name. |
| 697 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
| 697 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
| 698 | 698 | |
| 699 | 699 | // Handle full state name. |
| 700 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
| 700 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
| 701 | 701 | |
| 702 | 702 | $args['postcode'] = $args['zip']; |
| 703 | 703 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
| 704 | 704 | $args['state'] = $full_state; |
| 705 | 705 | $args['state_code'] = $state; |
| 706 | 706 | $args['country'] = $full_country; |
| 707 | - $args['country_code']= $country; |
|
| 707 | + $args['country_code'] = $country; |
|
| 708 | 708 | |
| 709 | 709 | /** |
| 710 | 710 | * Filters the address format replacements to use on Invoices. |
@@ -715,14 +715,14 @@ discard block |
||
| 715 | 715 | * @param array $replacements The address replacements to use. |
| 716 | 716 | * @param array $billing_details The billing details to use. |
| 717 | 717 | */ |
| 718 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
| 718 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
| 719 | 719 | |
| 720 | 720 | $return = array(); |
| 721 | 721 | |
| 722 | - foreach( $replacements as $key => $value ) { |
|
| 723 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
| 722 | + foreach ($replacements as $key => $value) { |
|
| 723 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
| 724 | 724 | $return['{{' . $key . '}}'] = $value; |
| 725 | - $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value ); |
|
| 725 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | return $return; |
@@ -736,6 +736,6 @@ discard block |
||
| 736 | 736 | * @since 1.0.14 |
| 737 | 737 | * @return string |
| 738 | 738 | */ |
| 739 | -function wpinv_trim_formatted_address_line( $line ) { |
|
| 740 | - return trim( $line, ', ' ); |
|
| 739 | +function wpinv_trim_formatted_address_line($line) { |
|
| 740 | + return trim($line, ', '); |
|
| 741 | 741 | } |
| 742 | 742 | \ No newline at end of file |
@@ -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' ), |
|
| 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' ), |
|
| 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 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Post types Class |
@@ -18,10 +18,10 @@ discard block |
||
| 18 | 18 | * Hook in methods. |
| 19 | 19 | */ |
| 20 | 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' ) ); |
|
| 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 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public static function register_post_types() { |
| 31 | 31 | |
| 32 | - if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
| 32 | + if (!is_blog_installed() || post_type_exists('wpi_item')) { |
|
| 33 | 33 | return; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | // Fires before registering post types. |
| 37 | - do_action( 'getpaid_register_post_types' ); |
|
| 37 | + do_action('getpaid_register_post_types'); |
|
| 38 | 38 | |
| 39 | 39 | // Register item post type. |
| 40 | 40 | register_post_type( |
@@ -43,29 +43,29 @@ discard block |
||
| 43 | 43 | 'wpinv_register_post_type_invoice_item', |
| 44 | 44 | array( |
| 45 | 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' ) |
|
| 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 | 60 | ), |
| 61 | - 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
| 61 | + 'description' => __('This is where you can add new invoice items.', 'invoicing'), |
|
| 62 | 62 | 'public' => false, |
| 63 | 63 | 'has_archive' => false, |
| 64 | 64 | '_builtin' => false, |
| 65 | 65 | 'show_ui' => true, |
| 66 | 66 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
| 67 | 67 | 'show_in_nav_menus' => false, |
| 68 | - 'supports' => array( 'title', 'excerpt' ), |
|
| 68 | + 'supports' => array('title', 'excerpt'), |
|
| 69 | 69 | 'rewrite' => false, |
| 70 | 70 | 'query_var' => false, |
| 71 | 71 | 'capability_type' => 'wpi_item', |
@@ -83,22 +83,22 @@ discard block |
||
| 83 | 83 | 'wpinv_register_post_type_payment_form', |
| 84 | 84 | array( |
| 85 | 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' ) |
|
| 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 | 100 | ), |
| 101 | - 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
| 101 | + 'description' => __('Add new payment forms.', 'invoicing'), |
|
| 102 | 102 | 'public' => false, |
| 103 | 103 | 'show_ui' => true, |
| 104 | 104 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | 'has_archive' => false, |
| 110 | 110 | 'hierarchical' => false, |
| 111 | 111 | 'menu_position' => null, |
| 112 | - 'supports' => array( 'title' ), |
|
| 112 | + 'supports' => array('title'), |
|
| 113 | 113 | 'menu_icon' => 'dashicons-media-form', |
| 114 | 114 | ) |
| 115 | 115 | ) |
@@ -122,32 +122,32 @@ discard block |
||
| 122 | 122 | 'wpinv_register_post_type_invoice', |
| 123 | 123 | array( |
| 124 | 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' ), |
|
| 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 | 149 | ), |
| 150 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
| 150 | + 'description' => __('This is where invoices are stored.', 'invoicing'), |
|
| 151 | 151 | 'public' => true, |
| 152 | 152 | 'has_archive' => false, |
| 153 | 153 | 'publicly_queryable' => true, |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | 'show_ui' => true, |
| 156 | 156 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
| 157 | 157 | 'show_in_nav_menus' => false, |
| 158 | - 'supports' => array( 'title', 'author', 'excerpt' ), |
|
| 158 | + 'supports' => array('title', 'author', 'excerpt'), |
|
| 159 | 159 | 'rewrite' => array( |
| 160 | 160 | 'slug' => 'invoice', |
| 161 | 161 | 'with_front' => false, |
@@ -179,32 +179,32 @@ discard block |
||
| 179 | 179 | 'wpinv_register_post_type_discount', |
| 180 | 180 | array( |
| 181 | 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' ), |
|
| 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 | 206 | ), |
| 207 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
| 207 | + 'description' => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'), |
|
| 208 | 208 | 'public' => false, |
| 209 | 209 | 'can_export' => true, |
| 210 | 210 | '_builtin' => false, |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | 'map_meta_cap' => true, |
| 219 | 219 | 'has_archive' => false, |
| 220 | 220 | 'hierarchical' => false, |
| 221 | - 'supports' => array( 'title', 'excerpt' ), |
|
| 221 | + 'supports' => array('title', 'excerpt'), |
|
| 222 | 222 | 'show_in_nav_menus' => false, |
| 223 | 223 | 'show_in_admin_bar' => true, |
| 224 | 224 | 'menu_position' => null, |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | ) |
| 227 | 227 | ); |
| 228 | 228 | |
| 229 | - do_action( 'getpaid_after_register_post_types' ); |
|
| 229 | + do_action('getpaid_after_register_post_types'); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -239,79 +239,79 @@ discard block |
||
| 239 | 239 | array( |
| 240 | 240 | |
| 241 | 241 | 'wpi-pending' => array( |
| 242 | - 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
| 242 | + 'label' => _x('Pending Payment', 'Invoice status', 'invoicing'), |
|
| 243 | 243 | 'public' => true, |
| 244 | 244 | 'exclude_from_search' => true, |
| 245 | 245 | 'show_in_admin_all_list' => true, |
| 246 | 246 | 'show_in_admin_status_list' => true, |
| 247 | 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' ) |
|
| 248 | + 'label_count' => _n_noop('Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing') |
|
| 249 | 249 | ), |
| 250 | 250 | |
| 251 | 251 | 'wpi-processing' => array( |
| 252 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
| 252 | + 'label' => _x('Processing', 'Invoice status', 'invoicing'), |
|
| 253 | 253 | 'public' => true, |
| 254 | 254 | 'exclude_from_search' => true, |
| 255 | 255 | 'show_in_admin_all_list' => true, |
| 256 | 256 | 'show_in_admin_status_list' => true, |
| 257 | 257 | /* translators: %s: number of invoices */ |
| 258 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
| 258 | + 'label_count' => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing') |
|
| 259 | 259 | ), |
| 260 | 260 | |
| 261 | 261 | 'wpi-onhold' => array( |
| 262 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
| 262 | + 'label' => _x('On Hold', 'Invoice status', 'invoicing'), |
|
| 263 | 263 | 'public' => true, |
| 264 | 264 | 'exclude_from_search' => true, |
| 265 | 265 | 'show_in_admin_all_list' => true, |
| 266 | 266 | 'show_in_admin_status_list' => true, |
| 267 | 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' ) |
|
| 268 | + 'label_count' => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing') |
|
| 269 | 269 | ), |
| 270 | 270 | |
| 271 | 271 | 'wpi-cancelled' => array( |
| 272 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
| 272 | + 'label' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
| 273 | 273 | 'public' => true, |
| 274 | 274 | 'exclude_from_search' => true, |
| 275 | 275 | 'show_in_admin_all_list' => true, |
| 276 | 276 | 'show_in_admin_status_list' => true, |
| 277 | 277 | /* translators: %s: number of invoices */ |
| 278 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
| 278 | + 'label_count' => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing') |
|
| 279 | 279 | ), |
| 280 | 280 | |
| 281 | 281 | 'wpi-refunded' => array( |
| 282 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
| 282 | + 'label' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
| 283 | 283 | 'public' => true, |
| 284 | 284 | 'exclude_from_search' => true, |
| 285 | 285 | 'show_in_admin_all_list' => true, |
| 286 | 286 | 'show_in_admin_status_list' => true, |
| 287 | 287 | /* translators: %s: number of invoices */ |
| 288 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
| 288 | + 'label_count' => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing') |
|
| 289 | 289 | ), |
| 290 | 290 | |
| 291 | 291 | 'wpi-failed' => array( |
| 292 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
| 292 | + 'label' => _x('Failed', 'Invoice status', 'invoicing'), |
|
| 293 | 293 | 'public' => true, |
| 294 | 294 | 'exclude_from_search' => true, |
| 295 | 295 | 'show_in_admin_all_list' => true, |
| 296 | 296 | 'show_in_admin_status_list' => true, |
| 297 | 297 | /* translators: %s: number of invoices */ |
| 298 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
| 298 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing') |
|
| 299 | 299 | ), |
| 300 | 300 | |
| 301 | 301 | 'wpi-renewal' => array( |
| 302 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
| 302 | + 'label' => _x('Renewal', 'Invoice status', 'invoicing'), |
|
| 303 | 303 | 'public' => true, |
| 304 | 304 | 'exclude_from_search' => true, |
| 305 | 305 | 'show_in_admin_all_list' => true, |
| 306 | 306 | 'show_in_admin_status_list' => true, |
| 307 | 307 | /* translators: %s: number of invoices */ |
| 308 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
| 308 | + 'label_count' => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing') |
|
| 309 | 309 | ) |
| 310 | 310 | ) |
| 311 | 311 | ); |
| 312 | 312 | |
| 313 | - foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
| 314 | - register_post_status( $invoice_statuse, $args ); |
|
| 313 | + foreach ($invoice_statuses as $invoice_statuse => $args) { |
|
| 314 | + register_post_status($invoice_statuse, $args); |
|
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
@@ -327,8 +327,8 @@ discard block |
||
| 327 | 327 | * |
| 328 | 328 | */ |
| 329 | 329 | public static function maybe_flush_rewrite_rules() { |
| 330 | - if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
| 331 | - update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
| 330 | + if (!get_option('getpaid_flushed_rewrite_rules')) { |
|
| 331 | + update_option('getpaid_flushed_rewrite_rules', '1'); |
|
| 332 | 332 | self::flush_rewrite_rules(); |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | - exit; |
|
| 12 | + exit; |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -21,356 +21,356 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class GetPaid_Data { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * ID for this object. |
|
| 26 | - * |
|
| 27 | - * @since 1.0.19 |
|
| 28 | - * @var int |
|
| 29 | - */ |
|
| 30 | - protected $id = 0; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Core data for this object. Name value pairs (name + default value). |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Core data changes for this object. |
|
| 42 | - * |
|
| 43 | - * @since 1.0.19 |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $changes = array(); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * This is false until the object is read from the DB. |
|
| 50 | - * |
|
| 51 | - * @since 1.0.19 |
|
| 52 | - * @var bool |
|
| 53 | - */ |
|
| 54 | - protected $object_read = false; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * This is the name of this object type. |
|
| 58 | - * |
|
| 59 | - * @since 1.0.19 |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - protected $object_type = 'data'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Extra data for this object. Name value pairs (name + default value). |
|
| 66 | - * Used as a standard way for sub classes (like item types) to add |
|
| 67 | - * additional information to an inherited class. |
|
| 68 | - * |
|
| 69 | - * @since 1.0.19 |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - protected $extra_data = array(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Set to _data on construct so we can track and reset data if needed. |
|
| 76 | - * |
|
| 77 | - * @since 1.0.19 |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - protected $default_data = array(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Contains a reference to the data store for this class. |
|
| 84 | - * |
|
| 85 | - * @since 1.0.19 |
|
| 86 | - * @var GetPaid_Data_Store |
|
| 87 | - */ |
|
| 88 | - protected $data_store; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Stores meta in cache for future reads. |
|
| 92 | - * A group must be set to to enable caching. |
|
| 93 | - * |
|
| 94 | - * @since 1.0.19 |
|
| 95 | - * @var string |
|
| 96 | - */ |
|
| 97 | - protected $cache_group = ''; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Stores the last error. |
|
| 101 | - * |
|
| 102 | - * @since 1.0.19 |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $last_error = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Stores additional meta data. |
|
| 109 | - * |
|
| 110 | - * @since 1.0.19 |
|
| 111 | - * @var array |
|
| 112 | - */ |
|
| 113 | - protected $meta_data = null; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Default constructor. |
|
| 117 | - * |
|
| 118 | - * @param int|object|array $read ID to load from the DB (optional) or already queried data. |
|
| 119 | - */ |
|
| 120 | - public function __construct( $read = 0 ) { |
|
| 121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
| 122 | - $this->default_data = $this->data; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Only store the object ID to avoid serializing the data object instance. |
|
| 127 | - * |
|
| 128 | - * @return array |
|
| 129 | - */ |
|
| 130 | - public function __sleep() { |
|
| 131 | - return array( 'id' ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Re-run the constructor with the object ID. |
|
| 136 | - * |
|
| 137 | - * If the object no longer exists, remove the ID. |
|
| 138 | - */ |
|
| 139 | - public function __wakeup() { |
|
| 140 | - $this->__construct( absint( $this->id ) ); |
|
| 141 | - |
|
| 142 | - if ( ! empty( $this->last_error ) ) { |
|
| 143 | - $this->set_id( 0 ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * When the object is cloned, make sure meta is duplicated correctly. |
|
| 150 | - * |
|
| 151 | - * @since 1.0.19 |
|
| 152 | - */ |
|
| 153 | - public function __clone() { |
|
| 154 | - $this->maybe_read_meta_data(); |
|
| 155 | - if ( ! empty( $this->meta_data ) ) { |
|
| 156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
| 158 | - if ( ! empty( $meta->id ) ) { |
|
| 159 | - $this->meta_data[ $array_key ]->id = null; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Get the data store. |
|
| 167 | - * |
|
| 168 | - * @since 1.0.19 |
|
| 169 | - * @return object |
|
| 170 | - */ |
|
| 171 | - public function get_data_store() { |
|
| 172 | - return $this->data_store; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Get the object type. |
|
| 177 | - * |
|
| 178 | - * @since 1.0.19 |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function get_object_type() { |
|
| 182 | - return $this->object_type; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Returns the unique ID for this object. |
|
| 187 | - * |
|
| 188 | - * @since 1.0.19 |
|
| 189 | - * @return int |
|
| 190 | - */ |
|
| 191 | - public function get_id() { |
|
| 192 | - return $this->id; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Get form status. |
|
| 197 | - * |
|
| 198 | - * @since 1.0.19 |
|
| 199 | - * @param string $context View or edit context. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public function get_status( $context = 'view' ) { |
|
| 203 | - return $this->get_prop( 'status', $context ); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Delete an object, set the ID to 0, and return result. |
|
| 208 | - * |
|
| 209 | - * @since 1.0.19 |
|
| 210 | - * @param bool $force_delete Should the data be deleted permanently. |
|
| 211 | - * @return bool result |
|
| 212 | - */ |
|
| 213 | - public function delete( $force_delete = false ) { |
|
| 214 | - if ( $this->data_store ) { |
|
| 215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
| 216 | - $this->set_id( 0 ); |
|
| 217 | - return true; |
|
| 218 | - } |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Save should create or update based on object existence. |
|
| 224 | - * |
|
| 225 | - * @since 1.0.19 |
|
| 226 | - * @return int |
|
| 227 | - */ |
|
| 228 | - public function save() { |
|
| 229 | - if ( ! $this->data_store ) { |
|
| 230 | - return $this->get_id(); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
| 235 | - * |
|
| 236 | - * @param GetPaid_Data $this The object being saved. |
|
| 237 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 238 | - */ |
|
| 239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 240 | - |
|
| 241 | - if ( $this->get_id() ) { |
|
| 242 | - $this->data_store->update( $this ); |
|
| 243 | - } else { |
|
| 244 | - $this->data_store->create( $this ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Trigger action after saving to the DB. |
|
| 249 | - * |
|
| 250 | - * @param GetPaid_Data $this The object being saved. |
|
| 251 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 252 | - */ |
|
| 253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 254 | - |
|
| 255 | - return $this->get_id(); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Change data to JSON format. |
|
| 260 | - * |
|
| 261 | - * @since 1.0.19 |
|
| 262 | - * @return string Data in JSON format. |
|
| 263 | - */ |
|
| 264 | - public function __toString() { |
|
| 265 | - return wp_json_encode( $this->get_data() ); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Returns all data for this object. |
|
| 270 | - * |
|
| 271 | - * @since 1.0.19 |
|
| 272 | - * @return array |
|
| 273 | - */ |
|
| 274 | - public function get_data() { |
|
| 275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Returns array of expected data keys for this object. |
|
| 280 | - * |
|
| 281 | - * @since 1.0.19 |
|
| 282 | - * @return array |
|
| 283 | - */ |
|
| 284 | - public function get_data_keys() { |
|
| 285 | - return array_keys( $this->data ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Returns all "extra" data keys for an object (for sub objects like item types). |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @return array |
|
| 293 | - */ |
|
| 294 | - public function get_extra_data_keys() { |
|
| 295 | - return array_keys( $this->extra_data ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Filter null meta values from array. |
|
| 300 | - * |
|
| 301 | - * @since 1.0.19 |
|
| 302 | - * @param mixed $meta Meta value to check. |
|
| 303 | - * @return bool |
|
| 304 | - */ |
|
| 305 | - protected function filter_null_meta( $meta ) { |
|
| 306 | - return ! is_null( $meta->value ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Get All Meta Data. |
|
| 311 | - * |
|
| 312 | - * @since 1.0.19 |
|
| 313 | - * @return array of objects. |
|
| 314 | - */ |
|
| 315 | - public function get_meta_data() { |
|
| 316 | - $this->maybe_read_meta_data(); |
|
| 317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Check if the key is an internal one. |
|
| 322 | - * |
|
| 323 | - * @since 1.0.19 |
|
| 324 | - * @param string $key Key to check. |
|
| 325 | - * @return bool true if it's an internal key, false otherwise |
|
| 326 | - */ |
|
| 327 | - protected function is_internal_meta_key( $key ) { |
|
| 328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
| 329 | - |
|
| 330 | - if ( ! $internal_meta_key ) { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
| 335 | - |
|
| 336 | - if ( ! $has_setter_or_getter ) { |
|
| 337 | - return false; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /* translators: %s: $key Key to check */ |
|
| 341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 342 | - |
|
| 343 | - return true; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Magic method for setting data fields. |
|
| 348 | - * |
|
| 349 | - * This method does not update custom fields in the database. |
|
| 350 | - * |
|
| 351 | - * @since 1.0.19 |
|
| 352 | - * @access public |
|
| 353 | - * |
|
| 354 | - */ |
|
| 355 | - public function __set( $key, $value ) { |
|
| 356 | - |
|
| 357 | - if ( 'id' == strtolower( $key ) ) { |
|
| 358 | - return $this->set_id( $value ); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if ( method_exists( $this, "set_$key") ) { |
|
| 362 | - |
|
| 363 | - /* translators: %s: $key Key to set */ |
|
| 364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 365 | - |
|
| 366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
| 367 | - } else { |
|
| 368 | - $this->set_prop( $key, $value ); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 24 | + /** |
|
| 25 | + * ID for this object. |
|
| 26 | + * |
|
| 27 | + * @since 1.0.19 |
|
| 28 | + * @var int |
|
| 29 | + */ |
|
| 30 | + protected $id = 0; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Core data for this object. Name value pairs (name + default value). |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Core data changes for this object. |
|
| 42 | + * |
|
| 43 | + * @since 1.0.19 |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $changes = array(); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * This is false until the object is read from the DB. |
|
| 50 | + * |
|
| 51 | + * @since 1.0.19 |
|
| 52 | + * @var bool |
|
| 53 | + */ |
|
| 54 | + protected $object_read = false; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * This is the name of this object type. |
|
| 58 | + * |
|
| 59 | + * @since 1.0.19 |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + protected $object_type = 'data'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Extra data for this object. Name value pairs (name + default value). |
|
| 66 | + * Used as a standard way for sub classes (like item types) to add |
|
| 67 | + * additional information to an inherited class. |
|
| 68 | + * |
|
| 69 | + * @since 1.0.19 |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + protected $extra_data = array(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Set to _data on construct so we can track and reset data if needed. |
|
| 76 | + * |
|
| 77 | + * @since 1.0.19 |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + protected $default_data = array(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Contains a reference to the data store for this class. |
|
| 84 | + * |
|
| 85 | + * @since 1.0.19 |
|
| 86 | + * @var GetPaid_Data_Store |
|
| 87 | + */ |
|
| 88 | + protected $data_store; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Stores meta in cache for future reads. |
|
| 92 | + * A group must be set to to enable caching. |
|
| 93 | + * |
|
| 94 | + * @since 1.0.19 |
|
| 95 | + * @var string |
|
| 96 | + */ |
|
| 97 | + protected $cache_group = ''; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Stores the last error. |
|
| 101 | + * |
|
| 102 | + * @since 1.0.19 |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $last_error = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Stores additional meta data. |
|
| 109 | + * |
|
| 110 | + * @since 1.0.19 |
|
| 111 | + * @var array |
|
| 112 | + */ |
|
| 113 | + protected $meta_data = null; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Default constructor. |
|
| 117 | + * |
|
| 118 | + * @param int|object|array $read ID to load from the DB (optional) or already queried data. |
|
| 119 | + */ |
|
| 120 | + public function __construct( $read = 0 ) { |
|
| 121 | + $this->data = array_merge( $this->data, $this->extra_data ); |
|
| 122 | + $this->default_data = $this->data; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Only store the object ID to avoid serializing the data object instance. |
|
| 127 | + * |
|
| 128 | + * @return array |
|
| 129 | + */ |
|
| 130 | + public function __sleep() { |
|
| 131 | + return array( 'id' ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Re-run the constructor with the object ID. |
|
| 136 | + * |
|
| 137 | + * If the object no longer exists, remove the ID. |
|
| 138 | + */ |
|
| 139 | + public function __wakeup() { |
|
| 140 | + $this->__construct( absint( $this->id ) ); |
|
| 141 | + |
|
| 142 | + if ( ! empty( $this->last_error ) ) { |
|
| 143 | + $this->set_id( 0 ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * When the object is cloned, make sure meta is duplicated correctly. |
|
| 150 | + * |
|
| 151 | + * @since 1.0.19 |
|
| 152 | + */ |
|
| 153 | + public function __clone() { |
|
| 154 | + $this->maybe_read_meta_data(); |
|
| 155 | + if ( ! empty( $this->meta_data ) ) { |
|
| 156 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 157 | + $this->meta_data[ $array_key ] = clone $meta; |
|
| 158 | + if ( ! empty( $meta->id ) ) { |
|
| 159 | + $this->meta_data[ $array_key ]->id = null; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Get the data store. |
|
| 167 | + * |
|
| 168 | + * @since 1.0.19 |
|
| 169 | + * @return object |
|
| 170 | + */ |
|
| 171 | + public function get_data_store() { |
|
| 172 | + return $this->data_store; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Get the object type. |
|
| 177 | + * |
|
| 178 | + * @since 1.0.19 |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function get_object_type() { |
|
| 182 | + return $this->object_type; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Returns the unique ID for this object. |
|
| 187 | + * |
|
| 188 | + * @since 1.0.19 |
|
| 189 | + * @return int |
|
| 190 | + */ |
|
| 191 | + public function get_id() { |
|
| 192 | + return $this->id; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Get form status. |
|
| 197 | + * |
|
| 198 | + * @since 1.0.19 |
|
| 199 | + * @param string $context View or edit context. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public function get_status( $context = 'view' ) { |
|
| 203 | + return $this->get_prop( 'status', $context ); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Delete an object, set the ID to 0, and return result. |
|
| 208 | + * |
|
| 209 | + * @since 1.0.19 |
|
| 210 | + * @param bool $force_delete Should the data be deleted permanently. |
|
| 211 | + * @return bool result |
|
| 212 | + */ |
|
| 213 | + public function delete( $force_delete = false ) { |
|
| 214 | + if ( $this->data_store ) { |
|
| 215 | + $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
| 216 | + $this->set_id( 0 ); |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Save should create or update based on object existence. |
|
| 224 | + * |
|
| 225 | + * @since 1.0.19 |
|
| 226 | + * @return int |
|
| 227 | + */ |
|
| 228 | + public function save() { |
|
| 229 | + if ( ! $this->data_store ) { |
|
| 230 | + return $this->get_id(); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
| 235 | + * |
|
| 236 | + * @param GetPaid_Data $this The object being saved. |
|
| 237 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 238 | + */ |
|
| 239 | + do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 240 | + |
|
| 241 | + if ( $this->get_id() ) { |
|
| 242 | + $this->data_store->update( $this ); |
|
| 243 | + } else { |
|
| 244 | + $this->data_store->create( $this ); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Trigger action after saving to the DB. |
|
| 249 | + * |
|
| 250 | + * @param GetPaid_Data $this The object being saved. |
|
| 251 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 252 | + */ |
|
| 253 | + do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 254 | + |
|
| 255 | + return $this->get_id(); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Change data to JSON format. |
|
| 260 | + * |
|
| 261 | + * @since 1.0.19 |
|
| 262 | + * @return string Data in JSON format. |
|
| 263 | + */ |
|
| 264 | + public function __toString() { |
|
| 265 | + return wp_json_encode( $this->get_data() ); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Returns all data for this object. |
|
| 270 | + * |
|
| 271 | + * @since 1.0.19 |
|
| 272 | + * @return array |
|
| 273 | + */ |
|
| 274 | + public function get_data() { |
|
| 275 | + return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Returns array of expected data keys for this object. |
|
| 280 | + * |
|
| 281 | + * @since 1.0.19 |
|
| 282 | + * @return array |
|
| 283 | + */ |
|
| 284 | + public function get_data_keys() { |
|
| 285 | + return array_keys( $this->data ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Returns all "extra" data keys for an object (for sub objects like item types). |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @return array |
|
| 293 | + */ |
|
| 294 | + public function get_extra_data_keys() { |
|
| 295 | + return array_keys( $this->extra_data ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Filter null meta values from array. |
|
| 300 | + * |
|
| 301 | + * @since 1.0.19 |
|
| 302 | + * @param mixed $meta Meta value to check. |
|
| 303 | + * @return bool |
|
| 304 | + */ |
|
| 305 | + protected function filter_null_meta( $meta ) { |
|
| 306 | + return ! is_null( $meta->value ); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Get All Meta Data. |
|
| 311 | + * |
|
| 312 | + * @since 1.0.19 |
|
| 313 | + * @return array of objects. |
|
| 314 | + */ |
|
| 315 | + public function get_meta_data() { |
|
| 316 | + $this->maybe_read_meta_data(); |
|
| 317 | + return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Check if the key is an internal one. |
|
| 322 | + * |
|
| 323 | + * @since 1.0.19 |
|
| 324 | + * @param string $key Key to check. |
|
| 325 | + * @return bool true if it's an internal key, false otherwise |
|
| 326 | + */ |
|
| 327 | + protected function is_internal_meta_key( $key ) { |
|
| 328 | + $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
| 329 | + |
|
| 330 | + if ( ! $internal_meta_key ) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
| 335 | + |
|
| 336 | + if ( ! $has_setter_or_getter ) { |
|
| 337 | + return false; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /* translators: %s: $key Key to check */ |
|
| 341 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 342 | + |
|
| 343 | + return true; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Magic method for setting data fields. |
|
| 348 | + * |
|
| 349 | + * This method does not update custom fields in the database. |
|
| 350 | + * |
|
| 351 | + * @since 1.0.19 |
|
| 352 | + * @access public |
|
| 353 | + * |
|
| 354 | + */ |
|
| 355 | + public function __set( $key, $value ) { |
|
| 356 | + |
|
| 357 | + if ( 'id' == strtolower( $key ) ) { |
|
| 358 | + return $this->set_id( $value ); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if ( method_exists( $this, "set_$key") ) { |
|
| 362 | + |
|
| 363 | + /* translators: %s: $key Key to set */ |
|
| 364 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 365 | + |
|
| 366 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
| 367 | + } else { |
|
| 368 | + $this->set_prop( $key, $value ); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | 374 | * Margic method for retrieving a property. |
| 375 | 375 | */ |
| 376 | 376 | public function __get( $key ) { |
@@ -378,10 +378,10 @@ discard block |
||
| 378 | 378 | // Check if we have a helper method for that. |
| 379 | 379 | if ( method_exists( $this, 'get_' . $key ) ) { |
| 380 | 380 | |
| 381 | - if ( 'post_type' != $key ) { |
|
| 382 | - /* translators: %s: $key Key to set */ |
|
| 383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 384 | - } |
|
| 381 | + if ( 'post_type' != $key ) { |
|
| 382 | + /* translators: %s: $key Key to set */ |
|
| 383 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | 386 | return call_user_func( array( $this, 'get_' . $key ) ); |
| 387 | 387 | } |
@@ -391,509 +391,509 @@ discard block |
||
| 391 | 391 | return $this->post->$key; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - return $this->get_prop( $key ); |
|
| 395 | - |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Get Meta Data by Key. |
|
| 400 | - * |
|
| 401 | - * @since 1.0.19 |
|
| 402 | - * @param string $key Meta Key. |
|
| 403 | - * @param bool $single return first found meta with key, or all with $key. |
|
| 404 | - * @param string $context What the value is for. Valid values are view and edit. |
|
| 405 | - * @return mixed |
|
| 406 | - */ |
|
| 407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
| 408 | - |
|
| 409 | - // Check if this is an internal meta key. |
|
| 410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
| 411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
| 412 | - if ( $this->is_internal_meta_key( $_key ) ) { |
|
| 413 | - $function = 'get_' . $_key; |
|
| 414 | - |
|
| 415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 416 | - return $this->{$function}(); |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - // Read the meta data if not yet read. |
|
| 421 | - $this->maybe_read_meta_data(); |
|
| 422 | - $meta_data = $this->get_meta_data(); |
|
| 423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
| 424 | - $value = $single ? '' : array(); |
|
| 425 | - |
|
| 426 | - if ( ! empty( $array_keys ) ) { |
|
| 427 | - // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
| 428 | - if ( $single ) { |
|
| 429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
| 430 | - } else { |
|
| 431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - if ( 'view' === $context ) { |
|
| 436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - return $value; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * See if meta data exists, since get_meta always returns a '' or array(). |
|
| 444 | - * |
|
| 445 | - * @since 1.0.19 |
|
| 446 | - * @param string $key Meta Key. |
|
| 447 | - * @return boolean |
|
| 448 | - */ |
|
| 449 | - public function meta_exists( $key = '' ) { |
|
| 450 | - $this->maybe_read_meta_data(); |
|
| 451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
| 452 | - return in_array( $key, $array_keys, true ); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Set all meta data from array. |
|
| 457 | - * |
|
| 458 | - * @since 1.0.19 |
|
| 459 | - * @param array $data Key/Value pairs. |
|
| 460 | - */ |
|
| 461 | - public function set_meta_data( $data ) { |
|
| 462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
| 463 | - $this->maybe_read_meta_data(); |
|
| 464 | - foreach ( $data as $meta ) { |
|
| 465 | - $meta = (array) $meta; |
|
| 466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
| 467 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 468 | - array( |
|
| 469 | - 'id' => $meta['id'], |
|
| 470 | - 'key' => $meta['key'], |
|
| 471 | - 'value' => $meta['value'], |
|
| 472 | - ) |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Add meta data. |
|
| 481 | - * |
|
| 482 | - * @since 1.0.19 |
|
| 483 | - * |
|
| 484 | - * @param string $key Meta key. |
|
| 485 | - * @param string|array $value Meta value. |
|
| 486 | - * @param bool $unique Should this be a unique key?. |
|
| 487 | - */ |
|
| 488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
| 489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 490 | - $function = 'set_' . $key; |
|
| 491 | - |
|
| 492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 493 | - return $this->{$function}( $value ); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - $this->maybe_read_meta_data(); |
|
| 498 | - if ( $unique ) { |
|
| 499 | - $this->delete_meta_data( $key ); |
|
| 500 | - } |
|
| 501 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 502 | - array( |
|
| 503 | - 'key' => $key, |
|
| 504 | - 'value' => $value, |
|
| 505 | - ) |
|
| 506 | - ); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * Update meta data by key or ID, if provided. |
|
| 511 | - * |
|
| 512 | - * @since 1.0.19 |
|
| 513 | - * |
|
| 514 | - * @param string $key Meta key. |
|
| 515 | - * @param string|array $value Meta value. |
|
| 516 | - * @param int $meta_id Meta ID. |
|
| 517 | - */ |
|
| 518 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
| 519 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 520 | - $function = 'set_' . $key; |
|
| 521 | - |
|
| 522 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 523 | - return $this->{$function}( $value ); |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $this->maybe_read_meta_data(); |
|
| 528 | - |
|
| 529 | - $array_key = false; |
|
| 530 | - |
|
| 531 | - if ( $meta_id ) { |
|
| 532 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
| 533 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
| 534 | - } else { |
|
| 535 | - // Find matches by key. |
|
| 536 | - $matches = array(); |
|
| 537 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
| 538 | - if ( $meta->key === $key ) { |
|
| 539 | - $matches[] = $meta_data_array_key; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - if ( ! empty( $matches ) ) { |
|
| 544 | - // Set matches to null so only one key gets the new value. |
|
| 545 | - foreach ( $matches as $meta_data_array_key ) { |
|
| 546 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
| 547 | - } |
|
| 548 | - $array_key = current( $matches ); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - if ( false !== $array_key ) { |
|
| 553 | - $meta = $this->meta_data[ $array_key ]; |
|
| 554 | - $meta->key = $key; |
|
| 555 | - $meta->value = $value; |
|
| 556 | - } else { |
|
| 557 | - $this->add_meta_data( $key, $value, true ); |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Delete meta data. |
|
| 563 | - * |
|
| 564 | - * @since 1.0.19 |
|
| 565 | - * @param string $key Meta key. |
|
| 566 | - */ |
|
| 567 | - public function delete_meta_data( $key ) { |
|
| 568 | - $this->maybe_read_meta_data(); |
|
| 569 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
| 570 | - |
|
| 571 | - if ( $array_keys ) { |
|
| 572 | - foreach ( $array_keys as $array_key ) { |
|
| 573 | - $this->meta_data[ $array_key ]->value = null; |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Delete meta data. |
|
| 580 | - * |
|
| 581 | - * @since 1.0.19 |
|
| 582 | - * @param int $mid Meta ID. |
|
| 583 | - */ |
|
| 584 | - public function delete_meta_data_by_mid( $mid ) { |
|
| 585 | - $this->maybe_read_meta_data(); |
|
| 586 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
| 587 | - |
|
| 588 | - if ( $array_keys ) { |
|
| 589 | - foreach ( $array_keys as $array_key ) { |
|
| 590 | - $this->meta_data[ $array_key ]->value = null; |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Read meta data if null. |
|
| 597 | - * |
|
| 598 | - * @since 1.0.19 |
|
| 599 | - */ |
|
| 600 | - protected function maybe_read_meta_data() { |
|
| 601 | - if ( is_null( $this->meta_data ) ) { |
|
| 602 | - $this->read_meta_data(); |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * Read Meta Data from the database. Ignore any internal properties. |
|
| 608 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
| 612 | - */ |
|
| 613 | - public function read_meta_data( $force_read = false ) { |
|
| 614 | - $this->meta_data = array(); |
|
| 615 | - $cache_loaded = false; |
|
| 616 | - |
|
| 617 | - if ( ! $this->get_id() ) { |
|
| 618 | - return; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - if ( ! $this->data_store ) { |
|
| 622 | - return; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - if ( ! empty( $this->cache_group ) ) { |
|
| 626 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - if ( ! $force_read ) { |
|
| 630 | - if ( ! empty( $this->cache_group ) ) { |
|
| 631 | - $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
| 632 | - $cache_loaded = ! empty( $cached_meta ); |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
| 637 | - if ( $raw_meta_data ) { |
|
| 638 | - foreach ( $raw_meta_data as $meta ) { |
|
| 639 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 640 | - array( |
|
| 641 | - 'id' => (int) $meta->meta_id, |
|
| 642 | - 'key' => $meta->meta_key, |
|
| 643 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
| 644 | - ) |
|
| 645 | - ); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
| 649 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Update Meta Data in the database. |
|
| 656 | - * |
|
| 657 | - * @since 1.0.19 |
|
| 658 | - */ |
|
| 659 | - public function save_meta_data() { |
|
| 660 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
| 661 | - return; |
|
| 662 | - } |
|
| 663 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 664 | - if ( is_null( $meta->value ) ) { |
|
| 665 | - if ( ! empty( $meta->id ) ) { |
|
| 666 | - $this->data_store->delete_meta( $this, $meta ); |
|
| 667 | - unset( $this->meta_data[ $array_key ] ); |
|
| 668 | - } |
|
| 669 | - } elseif ( empty( $meta->id ) ) { |
|
| 670 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
| 671 | - $meta->apply_changes(); |
|
| 672 | - } else { |
|
| 673 | - if ( $meta->get_changes() ) { |
|
| 674 | - $this->data_store->update_meta( $this, $meta ); |
|
| 675 | - $meta->apply_changes(); |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - if ( ! empty( $this->cache_group ) ) { |
|
| 680 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 681 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Set ID. |
|
| 687 | - * |
|
| 688 | - * @since 1.0.19 |
|
| 689 | - * @param int $id ID. |
|
| 690 | - */ |
|
| 691 | - public function set_id( $id ) { |
|
| 692 | - $this->id = absint( $id ); |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Sets item status. |
|
| 697 | - * |
|
| 698 | - * @since 1.0.19 |
|
| 699 | - * @param string $status New status. |
|
| 700 | - * @return array details of change. |
|
| 701 | - */ |
|
| 702 | - public function set_status( $status ) { |
|
| 394 | + return $this->get_prop( $key ); |
|
| 395 | + |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Get Meta Data by Key. |
|
| 400 | + * |
|
| 401 | + * @since 1.0.19 |
|
| 402 | + * @param string $key Meta Key. |
|
| 403 | + * @param bool $single return first found meta with key, or all with $key. |
|
| 404 | + * @param string $context What the value is for. Valid values are view and edit. |
|
| 405 | + * @return mixed |
|
| 406 | + */ |
|
| 407 | + public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
| 408 | + |
|
| 409 | + // Check if this is an internal meta key. |
|
| 410 | + $_key = str_replace( '_wpinv', '', $key ); |
|
| 411 | + $_key = str_replace( 'wpinv', '', $_key ); |
|
| 412 | + if ( $this->is_internal_meta_key( $_key ) ) { |
|
| 413 | + $function = 'get_' . $_key; |
|
| 414 | + |
|
| 415 | + if ( is_callable( array( $this, $function ) ) ) { |
|
| 416 | + return $this->{$function}(); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + // Read the meta data if not yet read. |
|
| 421 | + $this->maybe_read_meta_data(); |
|
| 422 | + $meta_data = $this->get_meta_data(); |
|
| 423 | + $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
| 424 | + $value = $single ? '' : array(); |
|
| 425 | + |
|
| 426 | + if ( ! empty( $array_keys ) ) { |
|
| 427 | + // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
| 428 | + if ( $single ) { |
|
| 429 | + $value = $meta_data[ current( $array_keys ) ]->value; |
|
| 430 | + } else { |
|
| 431 | + $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + if ( 'view' === $context ) { |
|
| 436 | + $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + return $value; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * See if meta data exists, since get_meta always returns a '' or array(). |
|
| 444 | + * |
|
| 445 | + * @since 1.0.19 |
|
| 446 | + * @param string $key Meta Key. |
|
| 447 | + * @return boolean |
|
| 448 | + */ |
|
| 449 | + public function meta_exists( $key = '' ) { |
|
| 450 | + $this->maybe_read_meta_data(); |
|
| 451 | + $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
| 452 | + return in_array( $key, $array_keys, true ); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Set all meta data from array. |
|
| 457 | + * |
|
| 458 | + * @since 1.0.19 |
|
| 459 | + * @param array $data Key/Value pairs. |
|
| 460 | + */ |
|
| 461 | + public function set_meta_data( $data ) { |
|
| 462 | + if ( ! empty( $data ) && is_array( $data ) ) { |
|
| 463 | + $this->maybe_read_meta_data(); |
|
| 464 | + foreach ( $data as $meta ) { |
|
| 465 | + $meta = (array) $meta; |
|
| 466 | + if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
| 467 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 468 | + array( |
|
| 469 | + 'id' => $meta['id'], |
|
| 470 | + 'key' => $meta['key'], |
|
| 471 | + 'value' => $meta['value'], |
|
| 472 | + ) |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Add meta data. |
|
| 481 | + * |
|
| 482 | + * @since 1.0.19 |
|
| 483 | + * |
|
| 484 | + * @param string $key Meta key. |
|
| 485 | + * @param string|array $value Meta value. |
|
| 486 | + * @param bool $unique Should this be a unique key?. |
|
| 487 | + */ |
|
| 488 | + public function add_meta_data( $key, $value, $unique = false ) { |
|
| 489 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
| 490 | + $function = 'set_' . $key; |
|
| 491 | + |
|
| 492 | + if ( is_callable( array( $this, $function ) ) ) { |
|
| 493 | + return $this->{$function}( $value ); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + $this->maybe_read_meta_data(); |
|
| 498 | + if ( $unique ) { |
|
| 499 | + $this->delete_meta_data( $key ); |
|
| 500 | + } |
|
| 501 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 502 | + array( |
|
| 503 | + 'key' => $key, |
|
| 504 | + 'value' => $value, |
|
| 505 | + ) |
|
| 506 | + ); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * Update meta data by key or ID, if provided. |
|
| 511 | + * |
|
| 512 | + * @since 1.0.19 |
|
| 513 | + * |
|
| 514 | + * @param string $key Meta key. |
|
| 515 | + * @param string|array $value Meta value. |
|
| 516 | + * @param int $meta_id Meta ID. |
|
| 517 | + */ |
|
| 518 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
| 519 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
| 520 | + $function = 'set_' . $key; |
|
| 521 | + |
|
| 522 | + if ( is_callable( array( $this, $function ) ) ) { |
|
| 523 | + return $this->{$function}( $value ); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $this->maybe_read_meta_data(); |
|
| 528 | + |
|
| 529 | + $array_key = false; |
|
| 530 | + |
|
| 531 | + if ( $meta_id ) { |
|
| 532 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
| 533 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
| 534 | + } else { |
|
| 535 | + // Find matches by key. |
|
| 536 | + $matches = array(); |
|
| 537 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
| 538 | + if ( $meta->key === $key ) { |
|
| 539 | + $matches[] = $meta_data_array_key; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + if ( ! empty( $matches ) ) { |
|
| 544 | + // Set matches to null so only one key gets the new value. |
|
| 545 | + foreach ( $matches as $meta_data_array_key ) { |
|
| 546 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
| 547 | + } |
|
| 548 | + $array_key = current( $matches ); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + if ( false !== $array_key ) { |
|
| 553 | + $meta = $this->meta_data[ $array_key ]; |
|
| 554 | + $meta->key = $key; |
|
| 555 | + $meta->value = $value; |
|
| 556 | + } else { |
|
| 557 | + $this->add_meta_data( $key, $value, true ); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Delete meta data. |
|
| 563 | + * |
|
| 564 | + * @since 1.0.19 |
|
| 565 | + * @param string $key Meta key. |
|
| 566 | + */ |
|
| 567 | + public function delete_meta_data( $key ) { |
|
| 568 | + $this->maybe_read_meta_data(); |
|
| 569 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
| 570 | + |
|
| 571 | + if ( $array_keys ) { |
|
| 572 | + foreach ( $array_keys as $array_key ) { |
|
| 573 | + $this->meta_data[ $array_key ]->value = null; |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Delete meta data. |
|
| 580 | + * |
|
| 581 | + * @since 1.0.19 |
|
| 582 | + * @param int $mid Meta ID. |
|
| 583 | + */ |
|
| 584 | + public function delete_meta_data_by_mid( $mid ) { |
|
| 585 | + $this->maybe_read_meta_data(); |
|
| 586 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
| 587 | + |
|
| 588 | + if ( $array_keys ) { |
|
| 589 | + foreach ( $array_keys as $array_key ) { |
|
| 590 | + $this->meta_data[ $array_key ]->value = null; |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Read meta data if null. |
|
| 597 | + * |
|
| 598 | + * @since 1.0.19 |
|
| 599 | + */ |
|
| 600 | + protected function maybe_read_meta_data() { |
|
| 601 | + if ( is_null( $this->meta_data ) ) { |
|
| 602 | + $this->read_meta_data(); |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * Read Meta Data from the database. Ignore any internal properties. |
|
| 608 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
| 609 | + * |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
| 612 | + */ |
|
| 613 | + public function read_meta_data( $force_read = false ) { |
|
| 614 | + $this->meta_data = array(); |
|
| 615 | + $cache_loaded = false; |
|
| 616 | + |
|
| 617 | + if ( ! $this->get_id() ) { |
|
| 618 | + return; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + if ( ! $this->data_store ) { |
|
| 622 | + return; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + if ( ! empty( $this->cache_group ) ) { |
|
| 626 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + if ( ! $force_read ) { |
|
| 630 | + if ( ! empty( $this->cache_group ) ) { |
|
| 631 | + $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
| 632 | + $cache_loaded = ! empty( $cached_meta ); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
| 637 | + if ( $raw_meta_data ) { |
|
| 638 | + foreach ( $raw_meta_data as $meta ) { |
|
| 639 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 640 | + array( |
|
| 641 | + 'id' => (int) $meta->meta_id, |
|
| 642 | + 'key' => $meta->meta_key, |
|
| 643 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
| 644 | + ) |
|
| 645 | + ); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
| 649 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Update Meta Data in the database. |
|
| 656 | + * |
|
| 657 | + * @since 1.0.19 |
|
| 658 | + */ |
|
| 659 | + public function save_meta_data() { |
|
| 660 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
| 661 | + return; |
|
| 662 | + } |
|
| 663 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 664 | + if ( is_null( $meta->value ) ) { |
|
| 665 | + if ( ! empty( $meta->id ) ) { |
|
| 666 | + $this->data_store->delete_meta( $this, $meta ); |
|
| 667 | + unset( $this->meta_data[ $array_key ] ); |
|
| 668 | + } |
|
| 669 | + } elseif ( empty( $meta->id ) ) { |
|
| 670 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
| 671 | + $meta->apply_changes(); |
|
| 672 | + } else { |
|
| 673 | + if ( $meta->get_changes() ) { |
|
| 674 | + $this->data_store->update_meta( $this, $meta ); |
|
| 675 | + $meta->apply_changes(); |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + if ( ! empty( $this->cache_group ) ) { |
|
| 680 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 681 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Set ID. |
|
| 687 | + * |
|
| 688 | + * @since 1.0.19 |
|
| 689 | + * @param int $id ID. |
|
| 690 | + */ |
|
| 691 | + public function set_id( $id ) { |
|
| 692 | + $this->id = absint( $id ); |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Sets item status. |
|
| 697 | + * |
|
| 698 | + * @since 1.0.19 |
|
| 699 | + * @param string $status New status. |
|
| 700 | + * @return array details of change. |
|
| 701 | + */ |
|
| 702 | + public function set_status( $status ) { |
|
| 703 | 703 | $old_status = $this->get_status(); |
| 704 | 704 | |
| 705 | - $this->set_prop( 'status', $status ); |
|
| 706 | - |
|
| 707 | - return array( |
|
| 708 | - 'from' => $old_status, |
|
| 709 | - 'to' => $status, |
|
| 710 | - ); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * Set all props to default values. |
|
| 715 | - * |
|
| 716 | - * @since 1.0.19 |
|
| 717 | - */ |
|
| 718 | - public function set_defaults() { |
|
| 719 | - $this->data = $this->default_data; |
|
| 720 | - $this->changes = array(); |
|
| 721 | - $this->set_object_read( false ); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * Set object read property. |
|
| 726 | - * |
|
| 727 | - * @since 1.0.19 |
|
| 728 | - * @param boolean $read Should read?. |
|
| 729 | - */ |
|
| 730 | - public function set_object_read( $read = true ) { |
|
| 731 | - $this->object_read = (bool) $read; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * Get object read property. |
|
| 736 | - * |
|
| 737 | - * @since 1.0.19 |
|
| 738 | - * @return boolean |
|
| 739 | - */ |
|
| 740 | - public function get_object_read() { |
|
| 741 | - return (bool) $this->object_read; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
| 746 | - * Only sets using public methods. |
|
| 747 | - * |
|
| 748 | - * @since 1.0.19 |
|
| 749 | - * |
|
| 750 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
| 751 | - * @param string $context In what context to run this. |
|
| 752 | - * |
|
| 753 | - * @return bool|WP_Error |
|
| 754 | - */ |
|
| 755 | - public function set_props( $props, $context = 'set' ) { |
|
| 756 | - $errors = false; |
|
| 757 | - |
|
| 758 | - foreach ( $props as $prop => $value ) { |
|
| 759 | - try { |
|
| 760 | - /** |
|
| 761 | - * Checks if the prop being set is allowed, and the value is not null. |
|
| 762 | - */ |
|
| 763 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
| 764 | - continue; |
|
| 765 | - } |
|
| 766 | - $setter = "set_$prop"; |
|
| 767 | - |
|
| 768 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
| 769 | - $this->{$setter}( $value ); |
|
| 770 | - } |
|
| 771 | - } catch ( Exception $e ) { |
|
| 772 | - if ( ! $errors ) { |
|
| 773 | - $errors = new WP_Error(); |
|
| 774 | - } |
|
| 775 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
| 776 | - $this->last_error = $e->getMessage(); |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * Sets a prop for a setter method. |
|
| 785 | - * |
|
| 786 | - * This stores changes in a special array so we can track what needs saving |
|
| 787 | - * the the DB later. |
|
| 788 | - * |
|
| 789 | - * @since 1.0.19 |
|
| 790 | - * @param string $prop Name of prop to set. |
|
| 791 | - * @param mixed $value Value of the prop. |
|
| 792 | - */ |
|
| 793 | - protected function set_prop( $prop, $value ) { |
|
| 794 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 795 | - if ( true === $this->object_read ) { |
|
| 796 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
| 797 | - $this->changes[ $prop ] = $value; |
|
| 798 | - } |
|
| 799 | - } else { |
|
| 800 | - $this->data[ $prop ] = $value; |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * Return data changes only. |
|
| 807 | - * |
|
| 808 | - * @since 1.0.19 |
|
| 809 | - * @return array |
|
| 810 | - */ |
|
| 811 | - public function get_changes() { |
|
| 812 | - return $this->changes; |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * Merge changes with data and clear. |
|
| 817 | - * |
|
| 818 | - * @since 1.0.19 |
|
| 819 | - */ |
|
| 820 | - public function apply_changes() { |
|
| 821 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
| 822 | - $this->changes = array(); |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * Prefix for action and filter hooks on data. |
|
| 827 | - * |
|
| 828 | - * @since 1.0.19 |
|
| 829 | - * @return string |
|
| 830 | - */ |
|
| 831 | - protected function get_hook_prefix() { |
|
| 832 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * Gets a prop for a getter method. |
|
| 837 | - * |
|
| 838 | - * Gets the value from either current pending changes, or the data itself. |
|
| 839 | - * Context controls what happens to the value before it's returned. |
|
| 840 | - * |
|
| 841 | - * @since 1.0.19 |
|
| 842 | - * @param string $prop Name of prop to get. |
|
| 843 | - * @param string $context What the value is for. Valid values are view and edit. |
|
| 844 | - * @return mixed |
|
| 845 | - */ |
|
| 846 | - protected function get_prop( $prop, $context = 'view' ) { |
|
| 847 | - $value = null; |
|
| 848 | - |
|
| 849 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 850 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
| 851 | - |
|
| 852 | - if ( 'view' === $context ) { |
|
| 853 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
| 854 | - } |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - return $value; |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
| 862 | - * |
|
| 863 | - * @since 1.0.19 |
|
| 864 | - * @param string $prop Name of prop to set. |
|
| 865 | - * @param string|integer $value Value of the prop. |
|
| 866 | - */ |
|
| 867 | - protected function set_date_prop( $prop, $value ) { |
|
| 868 | - |
|
| 869 | - if ( empty( $value ) ) { |
|
| 870 | - $this->set_prop( $prop, null ); |
|
| 871 | - return; |
|
| 872 | - } |
|
| 873 | - $this->set_prop( $prop, $value ); |
|
| 874 | - |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
| 879 | - * |
|
| 880 | - * @since 1.0.19 |
|
| 881 | - * @param string $code Error code. |
|
| 882 | - * @param string $message Error message. |
|
| 883 | - */ |
|
| 884 | - protected function error( $code, $message ) { |
|
| 885 | - $this->last_error = $message; |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * Checks if the object is saved in the database |
|
| 890 | - * |
|
| 891 | - * @since 1.0.19 |
|
| 892 | - * @return bool |
|
| 893 | - */ |
|
| 894 | - public function exists() { |
|
| 895 | - $id = $this->get_id(); |
|
| 896 | - return ! empty( $id ); |
|
| 897 | - } |
|
| 705 | + $this->set_prop( 'status', $status ); |
|
| 706 | + |
|
| 707 | + return array( |
|
| 708 | + 'from' => $old_status, |
|
| 709 | + 'to' => $status, |
|
| 710 | + ); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * Set all props to default values. |
|
| 715 | + * |
|
| 716 | + * @since 1.0.19 |
|
| 717 | + */ |
|
| 718 | + public function set_defaults() { |
|
| 719 | + $this->data = $this->default_data; |
|
| 720 | + $this->changes = array(); |
|
| 721 | + $this->set_object_read( false ); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * Set object read property. |
|
| 726 | + * |
|
| 727 | + * @since 1.0.19 |
|
| 728 | + * @param boolean $read Should read?. |
|
| 729 | + */ |
|
| 730 | + public function set_object_read( $read = true ) { |
|
| 731 | + $this->object_read = (bool) $read; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * Get object read property. |
|
| 736 | + * |
|
| 737 | + * @since 1.0.19 |
|
| 738 | + * @return boolean |
|
| 739 | + */ |
|
| 740 | + public function get_object_read() { |
|
| 741 | + return (bool) $this->object_read; |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
| 746 | + * Only sets using public methods. |
|
| 747 | + * |
|
| 748 | + * @since 1.0.19 |
|
| 749 | + * |
|
| 750 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
| 751 | + * @param string $context In what context to run this. |
|
| 752 | + * |
|
| 753 | + * @return bool|WP_Error |
|
| 754 | + */ |
|
| 755 | + public function set_props( $props, $context = 'set' ) { |
|
| 756 | + $errors = false; |
|
| 757 | + |
|
| 758 | + foreach ( $props as $prop => $value ) { |
|
| 759 | + try { |
|
| 760 | + /** |
|
| 761 | + * Checks if the prop being set is allowed, and the value is not null. |
|
| 762 | + */ |
|
| 763 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
| 764 | + continue; |
|
| 765 | + } |
|
| 766 | + $setter = "set_$prop"; |
|
| 767 | + |
|
| 768 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
| 769 | + $this->{$setter}( $value ); |
|
| 770 | + } |
|
| 771 | + } catch ( Exception $e ) { |
|
| 772 | + if ( ! $errors ) { |
|
| 773 | + $errors = new WP_Error(); |
|
| 774 | + } |
|
| 775 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
| 776 | + $this->last_error = $e->getMessage(); |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * Sets a prop for a setter method. |
|
| 785 | + * |
|
| 786 | + * This stores changes in a special array so we can track what needs saving |
|
| 787 | + * the the DB later. |
|
| 788 | + * |
|
| 789 | + * @since 1.0.19 |
|
| 790 | + * @param string $prop Name of prop to set. |
|
| 791 | + * @param mixed $value Value of the prop. |
|
| 792 | + */ |
|
| 793 | + protected function set_prop( $prop, $value ) { |
|
| 794 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
| 795 | + if ( true === $this->object_read ) { |
|
| 796 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
| 797 | + $this->changes[ $prop ] = $value; |
|
| 798 | + } |
|
| 799 | + } else { |
|
| 800 | + $this->data[ $prop ] = $value; |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * Return data changes only. |
|
| 807 | + * |
|
| 808 | + * @since 1.0.19 |
|
| 809 | + * @return array |
|
| 810 | + */ |
|
| 811 | + public function get_changes() { |
|
| 812 | + return $this->changes; |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * Merge changes with data and clear. |
|
| 817 | + * |
|
| 818 | + * @since 1.0.19 |
|
| 819 | + */ |
|
| 820 | + public function apply_changes() { |
|
| 821 | + $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
| 822 | + $this->changes = array(); |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * Prefix for action and filter hooks on data. |
|
| 827 | + * |
|
| 828 | + * @since 1.0.19 |
|
| 829 | + * @return string |
|
| 830 | + */ |
|
| 831 | + protected function get_hook_prefix() { |
|
| 832 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * Gets a prop for a getter method. |
|
| 837 | + * |
|
| 838 | + * Gets the value from either current pending changes, or the data itself. |
|
| 839 | + * Context controls what happens to the value before it's returned. |
|
| 840 | + * |
|
| 841 | + * @since 1.0.19 |
|
| 842 | + * @param string $prop Name of prop to get. |
|
| 843 | + * @param string $context What the value is for. Valid values are view and edit. |
|
| 844 | + * @return mixed |
|
| 845 | + */ |
|
| 846 | + protected function get_prop( $prop, $context = 'view' ) { |
|
| 847 | + $value = null; |
|
| 848 | + |
|
| 849 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
| 850 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
| 851 | + |
|
| 852 | + if ( 'view' === $context ) { |
|
| 853 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + return $value; |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
| 862 | + * |
|
| 863 | + * @since 1.0.19 |
|
| 864 | + * @param string $prop Name of prop to set. |
|
| 865 | + * @param string|integer $value Value of the prop. |
|
| 866 | + */ |
|
| 867 | + protected function set_date_prop( $prop, $value ) { |
|
| 868 | + |
|
| 869 | + if ( empty( $value ) ) { |
|
| 870 | + $this->set_prop( $prop, null ); |
|
| 871 | + return; |
|
| 872 | + } |
|
| 873 | + $this->set_prop( $prop, $value ); |
|
| 874 | + |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
| 879 | + * |
|
| 880 | + * @since 1.0.19 |
|
| 881 | + * @param string $code Error code. |
|
| 882 | + * @param string $message Error message. |
|
| 883 | + */ |
|
| 884 | + protected function error( $code, $message ) { |
|
| 885 | + $this->last_error = $message; |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * Checks if the object is saved in the database |
|
| 890 | + * |
|
| 891 | + * @since 1.0.19 |
|
| 892 | + * @return bool |
|
| 893 | + */ |
|
| 894 | + public function exists() { |
|
| 895 | + $id = $this->get_id(); |
|
| 896 | + return ! empty( $id ); |
|
| 897 | + } |
|
| 898 | 898 | |
| 899 | 899 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | +if (!defined('ABSPATH')) { |
|
| 12 | 12 | exit; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @param int|object|array $read ID to load from the DB (optional) or already queried data. |
| 119 | 119 | */ |
| 120 | - public function __construct( $read = 0 ) { |
|
| 121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
| 120 | + public function __construct($read = 0) { |
|
| 121 | + $this->data = array_merge($this->data, $this->extra_data); |
|
| 122 | 122 | $this->default_data = $this->data; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @return array |
| 129 | 129 | */ |
| 130 | 130 | public function __sleep() { |
| 131 | - return array( 'id' ); |
|
| 131 | + return array('id'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | * If the object no longer exists, remove the ID. |
| 138 | 138 | */ |
| 139 | 139 | public function __wakeup() { |
| 140 | - $this->__construct( absint( $this->id ) ); |
|
| 140 | + $this->__construct(absint($this->id)); |
|
| 141 | 141 | |
| 142 | - if ( ! empty( $this->last_error ) ) { |
|
| 143 | - $this->set_id( 0 ); |
|
| 142 | + if (!empty($this->last_error)) { |
|
| 143 | + $this->set_id(0); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | } |
@@ -152,11 +152,11 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function __clone() { |
| 154 | 154 | $this->maybe_read_meta_data(); |
| 155 | - if ( ! empty( $this->meta_data ) ) { |
|
| 156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
| 158 | - if ( ! empty( $meta->id ) ) { |
|
| 159 | - $this->meta_data[ $array_key ]->id = null; |
|
| 155 | + if (!empty($this->meta_data)) { |
|
| 156 | + foreach ($this->meta_data as $array_key => $meta) { |
|
| 157 | + $this->meta_data[$array_key] = clone $meta; |
|
| 158 | + if (!empty($meta->id)) { |
|
| 159 | + $this->meta_data[$array_key]->id = null; |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -199,8 +199,8 @@ discard block |
||
| 199 | 199 | * @param string $context View or edit context. |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public function get_status( $context = 'view' ) { |
|
| 203 | - return $this->get_prop( 'status', $context ); |
|
| 202 | + public function get_status($context = 'view') { |
|
| 203 | + return $this->get_prop('status', $context); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | * @param bool $force_delete Should the data be deleted permanently. |
| 211 | 211 | * @return bool result |
| 212 | 212 | */ |
| 213 | - public function delete( $force_delete = false ) { |
|
| 214 | - if ( $this->data_store ) { |
|
| 215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
| 216 | - $this->set_id( 0 ); |
|
| 213 | + public function delete($force_delete = false) { |
|
| 214 | + if ($this->data_store) { |
|
| 215 | + $this->data_store->delete($this, array('force_delete' => $force_delete)); |
|
| 216 | + $this->set_id(0); |
|
| 217 | 217 | return true; |
| 218 | 218 | } |
| 219 | 219 | return false; |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @return int |
| 227 | 227 | */ |
| 228 | 228 | public function save() { |
| 229 | - if ( ! $this->data_store ) { |
|
| 229 | + if (!$this->data_store) { |
|
| 230 | 230 | return $this->get_id(); |
| 231 | 231 | } |
| 232 | 232 | |
@@ -236,12 +236,12 @@ discard block |
||
| 236 | 236 | * @param GetPaid_Data $this The object being saved. |
| 237 | 237 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
| 238 | 238 | */ |
| 239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 239 | + do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
| 240 | 240 | |
| 241 | - if ( $this->get_id() ) { |
|
| 242 | - $this->data_store->update( $this ); |
|
| 241 | + if ($this->get_id()) { |
|
| 242 | + $this->data_store->update($this); |
|
| 243 | 243 | } else { |
| 244 | - $this->data_store->create( $this ); |
|
| 244 | + $this->data_store->create($this); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @param GetPaid_Data $this The object being saved. |
| 251 | 251 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
| 252 | 252 | */ |
| 253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 253 | + do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
| 254 | 254 | |
| 255 | 255 | return $this->get_id(); |
| 256 | 256 | } |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * @return string Data in JSON format. |
| 263 | 263 | */ |
| 264 | 264 | public function __toString() { |
| 265 | - return wp_json_encode( $this->get_data() ); |
|
| 265 | + return wp_json_encode($this->get_data()); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @return array |
| 273 | 273 | */ |
| 274 | 274 | public function get_data() { |
| 275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
| 275 | + return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data())); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @return array |
| 283 | 283 | */ |
| 284 | 284 | public function get_data_keys() { |
| 285 | - return array_keys( $this->data ); |
|
| 285 | + return array_keys($this->data); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | * @return array |
| 293 | 293 | */ |
| 294 | 294 | public function get_extra_data_keys() { |
| 295 | - return array_keys( $this->extra_data ); |
|
| 295 | + return array_keys($this->extra_data); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -302,8 +302,8 @@ discard block |
||
| 302 | 302 | * @param mixed $meta Meta value to check. |
| 303 | 303 | * @return bool |
| 304 | 304 | */ |
| 305 | - protected function filter_null_meta( $meta ) { |
|
| 306 | - return ! is_null( $meta->value ); |
|
| 305 | + protected function filter_null_meta($meta) { |
|
| 306 | + return !is_null($meta->value); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | */ |
| 315 | 315 | public function get_meta_data() { |
| 316 | 316 | $this->maybe_read_meta_data(); |
| 317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
| 317 | + return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta'))); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -324,21 +324,21 @@ discard block |
||
| 324 | 324 | * @param string $key Key to check. |
| 325 | 325 | * @return bool true if it's an internal key, false otherwise |
| 326 | 326 | */ |
| 327 | - protected function is_internal_meta_key( $key ) { |
|
| 328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
| 327 | + protected function is_internal_meta_key($key) { |
|
| 328 | + $internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true); |
|
| 329 | 329 | |
| 330 | - if ( ! $internal_meta_key ) { |
|
| 330 | + if (!$internal_meta_key) { |
|
| 331 | 331 | return false; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
| 334 | + $has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key)); |
|
| 335 | 335 | |
| 336 | - if ( ! $has_setter_or_getter ) { |
|
| 336 | + if (!$has_setter_or_getter) { |
|
| 337 | 337 | return false; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /* translators: %s: $key Key to check */ |
| 341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 341 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
| 342 | 342 | |
| 343 | 343 | return true; |
| 344 | 344 | } |
@@ -352,20 +352,20 @@ discard block |
||
| 352 | 352 | * @access public |
| 353 | 353 | * |
| 354 | 354 | */ |
| 355 | - public function __set( $key, $value ) { |
|
| 355 | + public function __set($key, $value) { |
|
| 356 | 356 | |
| 357 | - if ( 'id' == strtolower( $key ) ) { |
|
| 358 | - return $this->set_id( $value ); |
|
| 357 | + if ('id' == strtolower($key)) { |
|
| 358 | + return $this->set_id($value); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if ( method_exists( $this, "set_$key") ) { |
|
| 361 | + if (method_exists($this, "set_$key")) { |
|
| 362 | 362 | |
| 363 | 363 | /* translators: %s: $key Key to set */ |
| 364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 364 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
| 365 | 365 | |
| 366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
| 366 | + call_user_func(array($this, "set_$key"), $value); |
|
| 367 | 367 | } else { |
| 368 | - $this->set_prop( $key, $value ); |
|
| 368 | + $this->set_prop($key, $value); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | } |
@@ -373,25 +373,25 @@ discard block |
||
| 373 | 373 | /** |
| 374 | 374 | * Margic method for retrieving a property. |
| 375 | 375 | */ |
| 376 | - public function __get( $key ) { |
|
| 376 | + public function __get($key) { |
|
| 377 | 377 | |
| 378 | 378 | // Check if we have a helper method for that. |
| 379 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 379 | + if (method_exists($this, 'get_' . $key)) { |
|
| 380 | 380 | |
| 381 | - if ( 'post_type' != $key ) { |
|
| 381 | + if ('post_type' != $key) { |
|
| 382 | 382 | /* translators: %s: $key Key to set */ |
| 383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 383 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 386 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | // Check if the key is in the associated $post object. |
| 390 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
| 390 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
| 391 | 391 | return $this->post->$key; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - return $this->get_prop( $key ); |
|
| 394 | + return $this->get_prop($key); |
|
| 395 | 395 | |
| 396 | 396 | } |
| 397 | 397 | |
@@ -404,15 +404,15 @@ discard block |
||
| 404 | 404 | * @param string $context What the value is for. Valid values are view and edit. |
| 405 | 405 | * @return mixed |
| 406 | 406 | */ |
| 407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
| 407 | + public function get_meta($key = '', $single = true, $context = 'view') { |
|
| 408 | 408 | |
| 409 | 409 | // Check if this is an internal meta key. |
| 410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
| 411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
| 412 | - if ( $this->is_internal_meta_key( $_key ) ) { |
|
| 410 | + $_key = str_replace('_wpinv', '', $key); |
|
| 411 | + $_key = str_replace('wpinv', '', $_key); |
|
| 412 | + if ($this->is_internal_meta_key($_key)) { |
|
| 413 | 413 | $function = 'get_' . $_key; |
| 414 | 414 | |
| 415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 415 | + if (is_callable(array($this, $function))) { |
|
| 416 | 416 | return $this->{$function}(); |
| 417 | 417 | } |
| 418 | 418 | } |
@@ -420,20 +420,20 @@ discard block |
||
| 420 | 420 | // Read the meta data if not yet read. |
| 421 | 421 | $this->maybe_read_meta_data(); |
| 422 | 422 | $meta_data = $this->get_meta_data(); |
| 423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
| 423 | + $array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true); |
|
| 424 | 424 | $value = $single ? '' : array(); |
| 425 | 425 | |
| 426 | - if ( ! empty( $array_keys ) ) { |
|
| 426 | + if (!empty($array_keys)) { |
|
| 427 | 427 | // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
| 428 | - if ( $single ) { |
|
| 429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
| 428 | + if ($single) { |
|
| 429 | + $value = $meta_data[current($array_keys)]->value; |
|
| 430 | 430 | } else { |
| 431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
| 431 | + $value = array_intersect_key($meta_data, array_flip($array_keys)); |
|
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - if ( 'view' === $context ) { |
|
| 436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
| 435 | + if ('view' === $context) { |
|
| 436 | + $value = apply_filters($this->get_hook_prefix() . $key, $value, $this); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | return $value; |
@@ -446,10 +446,10 @@ discard block |
||
| 446 | 446 | * @param string $key Meta Key. |
| 447 | 447 | * @return boolean |
| 448 | 448 | */ |
| 449 | - public function meta_exists( $key = '' ) { |
|
| 449 | + public function meta_exists($key = '') { |
|
| 450 | 450 | $this->maybe_read_meta_data(); |
| 451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
| 452 | - return in_array( $key, $array_keys, true ); |
|
| 451 | + $array_keys = wp_list_pluck($this->get_meta_data(), 'key'); |
|
| 452 | + return in_array($key, $array_keys, true); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -458,12 +458,12 @@ discard block |
||
| 458 | 458 | * @since 1.0.19 |
| 459 | 459 | * @param array $data Key/Value pairs. |
| 460 | 460 | */ |
| 461 | - public function set_meta_data( $data ) { |
|
| 462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
| 461 | + public function set_meta_data($data) { |
|
| 462 | + if (!empty($data) && is_array($data)) { |
|
| 463 | 463 | $this->maybe_read_meta_data(); |
| 464 | - foreach ( $data as $meta ) { |
|
| 464 | + foreach ($data as $meta) { |
|
| 465 | 465 | $meta = (array) $meta; |
| 466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
| 466 | + if (isset($meta['key'], $meta['value'], $meta['id'])) { |
|
| 467 | 467 | $this->meta_data[] = new GetPaid_Meta_Data( |
| 468 | 468 | array( |
| 469 | 469 | 'id' => $meta['id'], |
@@ -485,18 +485,18 @@ discard block |
||
| 485 | 485 | * @param string|array $value Meta value. |
| 486 | 486 | * @param bool $unique Should this be a unique key?. |
| 487 | 487 | */ |
| 488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
| 489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 488 | + public function add_meta_data($key, $value, $unique = false) { |
|
| 489 | + if ($this->is_internal_meta_key($key)) { |
|
| 490 | 490 | $function = 'set_' . $key; |
| 491 | 491 | |
| 492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 493 | - return $this->{$function}( $value ); |
|
| 492 | + if (is_callable(array($this, $function))) { |
|
| 493 | + return $this->{$function}($value); |
|
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | $this->maybe_read_meta_data(); |
| 498 | - if ( $unique ) { |
|
| 499 | - $this->delete_meta_data( $key ); |
|
| 498 | + if ($unique) { |
|
| 499 | + $this->delete_meta_data($key); |
|
| 500 | 500 | } |
| 501 | 501 | $this->meta_data[] = new GetPaid_Meta_Data( |
| 502 | 502 | array( |
@@ -515,12 +515,12 @@ discard block |
||
| 515 | 515 | * @param string|array $value Meta value. |
| 516 | 516 | * @param int $meta_id Meta ID. |
| 517 | 517 | */ |
| 518 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
| 519 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 518 | + public function update_meta_data($key, $value, $meta_id = 0) { |
|
| 519 | + if ($this->is_internal_meta_key($key)) { |
|
| 520 | 520 | $function = 'set_' . $key; |
| 521 | 521 | |
| 522 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 523 | - return $this->{$function}( $value ); |
|
| 522 | + if (is_callable(array($this, $function))) { |
|
| 523 | + return $this->{$function}($value); |
|
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | 526 | |
@@ -528,33 +528,33 @@ discard block |
||
| 528 | 528 | |
| 529 | 529 | $array_key = false; |
| 530 | 530 | |
| 531 | - if ( $meta_id ) { |
|
| 532 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
| 533 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
| 531 | + if ($meta_id) { |
|
| 532 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true); |
|
| 533 | + $array_key = $array_keys ? current($array_keys) : false; |
|
| 534 | 534 | } else { |
| 535 | 535 | // Find matches by key. |
| 536 | 536 | $matches = array(); |
| 537 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
| 538 | - if ( $meta->key === $key ) { |
|
| 537 | + foreach ($this->meta_data as $meta_data_array_key => $meta) { |
|
| 538 | + if ($meta->key === $key) { |
|
| 539 | 539 | $matches[] = $meta_data_array_key; |
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - if ( ! empty( $matches ) ) { |
|
| 543 | + if (!empty($matches)) { |
|
| 544 | 544 | // Set matches to null so only one key gets the new value. |
| 545 | - foreach ( $matches as $meta_data_array_key ) { |
|
| 546 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
| 545 | + foreach ($matches as $meta_data_array_key) { |
|
| 546 | + $this->meta_data[$meta_data_array_key]->value = null; |
|
| 547 | 547 | } |
| 548 | - $array_key = current( $matches ); |
|
| 548 | + $array_key = current($matches); |
|
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - if ( false !== $array_key ) { |
|
| 553 | - $meta = $this->meta_data[ $array_key ]; |
|
| 552 | + if (false !== $array_key) { |
|
| 553 | + $meta = $this->meta_data[$array_key]; |
|
| 554 | 554 | $meta->key = $key; |
| 555 | 555 | $meta->value = $value; |
| 556 | 556 | } else { |
| 557 | - $this->add_meta_data( $key, $value, true ); |
|
| 557 | + $this->add_meta_data($key, $value, true); |
|
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | |
@@ -564,13 +564,13 @@ discard block |
||
| 564 | 564 | * @since 1.0.19 |
| 565 | 565 | * @param string $key Meta key. |
| 566 | 566 | */ |
| 567 | - public function delete_meta_data( $key ) { |
|
| 567 | + public function delete_meta_data($key) { |
|
| 568 | 568 | $this->maybe_read_meta_data(); |
| 569 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
| 569 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true); |
|
| 570 | 570 | |
| 571 | - if ( $array_keys ) { |
|
| 572 | - foreach ( $array_keys as $array_key ) { |
|
| 573 | - $this->meta_data[ $array_key ]->value = null; |
|
| 571 | + if ($array_keys) { |
|
| 572 | + foreach ($array_keys as $array_key) { |
|
| 573 | + $this->meta_data[$array_key]->value = null; |
|
| 574 | 574 | } |
| 575 | 575 | } |
| 576 | 576 | } |
@@ -581,13 +581,13 @@ discard block |
||
| 581 | 581 | * @since 1.0.19 |
| 582 | 582 | * @param int $mid Meta ID. |
| 583 | 583 | */ |
| 584 | - public function delete_meta_data_by_mid( $mid ) { |
|
| 584 | + public function delete_meta_data_by_mid($mid) { |
|
| 585 | 585 | $this->maybe_read_meta_data(); |
| 586 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
| 586 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true); |
|
| 587 | 587 | |
| 588 | - if ( $array_keys ) { |
|
| 589 | - foreach ( $array_keys as $array_key ) { |
|
| 590 | - $this->meta_data[ $array_key ]->value = null; |
|
| 588 | + if ($array_keys) { |
|
| 589 | + foreach ($array_keys as $array_key) { |
|
| 590 | + $this->meta_data[$array_key]->value = null; |
|
| 591 | 591 | } |
| 592 | 592 | } |
| 593 | 593 | } |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | * @since 1.0.19 |
| 599 | 599 | */ |
| 600 | 600 | protected function maybe_read_meta_data() { |
| 601 | - if ( is_null( $this->meta_data ) ) { |
|
| 601 | + if (is_null($this->meta_data)) { |
|
| 602 | 602 | $this->read_meta_data(); |
| 603 | 603 | } |
| 604 | 604 | } |
@@ -610,43 +610,43 @@ discard block |
||
| 610 | 610 | * @since 1.0.19 |
| 611 | 611 | * @param bool $force_read True to force a new DB read (and update cache). |
| 612 | 612 | */ |
| 613 | - public function read_meta_data( $force_read = false ) { |
|
| 613 | + public function read_meta_data($force_read = false) { |
|
| 614 | 614 | $this->meta_data = array(); |
| 615 | 615 | $cache_loaded = false; |
| 616 | 616 | |
| 617 | - if ( ! $this->get_id() ) { |
|
| 617 | + if (!$this->get_id()) { |
|
| 618 | 618 | return; |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | - if ( ! $this->data_store ) { |
|
| 621 | + if (!$this->data_store) { |
|
| 622 | 622 | return; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - if ( ! empty( $this->cache_group ) ) { |
|
| 626 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 625 | + if (!empty($this->cache_group)) { |
|
| 626 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - if ( ! $force_read ) { |
|
| 630 | - if ( ! empty( $this->cache_group ) ) { |
|
| 631 | - $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
| 632 | - $cache_loaded = ! empty( $cached_meta ); |
|
| 629 | + if (!$force_read) { |
|
| 630 | + if (!empty($this->cache_group)) { |
|
| 631 | + $cached_meta = wp_cache_get($cache_key, $this->cache_group); |
|
| 632 | + $cache_loaded = !empty($cached_meta); |
|
| 633 | 633 | } |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | - $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
| 637 | - if ( $raw_meta_data ) { |
|
| 638 | - foreach ( $raw_meta_data as $meta ) { |
|
| 636 | + $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this); |
|
| 637 | + if ($raw_meta_data) { |
|
| 638 | + foreach ($raw_meta_data as $meta) { |
|
| 639 | 639 | $this->meta_data[] = new GetPaid_Meta_Data( |
| 640 | 640 | array( |
| 641 | 641 | 'id' => (int) $meta->meta_id, |
| 642 | 642 | 'key' => $meta->meta_key, |
| 643 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
| 643 | + 'value' => maybe_unserialize($meta->meta_value), |
|
| 644 | 644 | ) |
| 645 | 645 | ); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
| 649 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
| 648 | + if (!$cache_loaded && !empty($this->cache_group)) { |
|
| 649 | + wp_cache_set($cache_key, $raw_meta_data, $this->cache_group); |
|
| 650 | 650 | } |
| 651 | 651 | } |
| 652 | 652 | } |
@@ -657,28 +657,28 @@ discard block |
||
| 657 | 657 | * @since 1.0.19 |
| 658 | 658 | */ |
| 659 | 659 | public function save_meta_data() { |
| 660 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
| 660 | + if (!$this->data_store || is_null($this->meta_data)) { |
|
| 661 | 661 | return; |
| 662 | 662 | } |
| 663 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 664 | - if ( is_null( $meta->value ) ) { |
|
| 665 | - if ( ! empty( $meta->id ) ) { |
|
| 666 | - $this->data_store->delete_meta( $this, $meta ); |
|
| 667 | - unset( $this->meta_data[ $array_key ] ); |
|
| 663 | + foreach ($this->meta_data as $array_key => $meta) { |
|
| 664 | + if (is_null($meta->value)) { |
|
| 665 | + if (!empty($meta->id)) { |
|
| 666 | + $this->data_store->delete_meta($this, $meta); |
|
| 667 | + unset($this->meta_data[$array_key]); |
|
| 668 | 668 | } |
| 669 | - } elseif ( empty( $meta->id ) ) { |
|
| 670 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
| 669 | + } elseif (empty($meta->id)) { |
|
| 670 | + $meta->id = $this->data_store->add_meta($this, $meta); |
|
| 671 | 671 | $meta->apply_changes(); |
| 672 | 672 | } else { |
| 673 | - if ( $meta->get_changes() ) { |
|
| 674 | - $this->data_store->update_meta( $this, $meta ); |
|
| 673 | + if ($meta->get_changes()) { |
|
| 674 | + $this->data_store->update_meta($this, $meta); |
|
| 675 | 675 | $meta->apply_changes(); |
| 676 | 676 | } |
| 677 | 677 | } |
| 678 | 678 | } |
| 679 | - if ( ! empty( $this->cache_group ) ) { |
|
| 680 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 681 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
| 679 | + if (!empty($this->cache_group)) { |
|
| 680 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
| 681 | + wp_cache_delete($cache_key, $this->cache_group); |
|
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | 684 | |
@@ -688,8 +688,8 @@ discard block |
||
| 688 | 688 | * @since 1.0.19 |
| 689 | 689 | * @param int $id ID. |
| 690 | 690 | */ |
| 691 | - public function set_id( $id ) { |
|
| 692 | - $this->id = absint( $id ); |
|
| 691 | + public function set_id($id) { |
|
| 692 | + $this->id = absint($id); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -699,10 +699,10 @@ discard block |
||
| 699 | 699 | * @param string $status New status. |
| 700 | 700 | * @return array details of change. |
| 701 | 701 | */ |
| 702 | - public function set_status( $status ) { |
|
| 702 | + public function set_status($status) { |
|
| 703 | 703 | $old_status = $this->get_status(); |
| 704 | 704 | |
| 705 | - $this->set_prop( 'status', $status ); |
|
| 705 | + $this->set_prop('status', $status); |
|
| 706 | 706 | |
| 707 | 707 | return array( |
| 708 | 708 | 'from' => $old_status, |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | public function set_defaults() { |
| 719 | 719 | $this->data = $this->default_data; |
| 720 | 720 | $this->changes = array(); |
| 721 | - $this->set_object_read( false ); |
|
| 721 | + $this->set_object_read(false); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | * @since 1.0.19 |
| 728 | 728 | * @param boolean $read Should read?. |
| 729 | 729 | */ |
| 730 | - public function set_object_read( $read = true ) { |
|
| 730 | + public function set_object_read($read = true) { |
|
| 731 | 731 | $this->object_read = (bool) $read; |
| 732 | 732 | } |
| 733 | 733 | |
@@ -752,32 +752,32 @@ discard block |
||
| 752 | 752 | * |
| 753 | 753 | * @return bool|WP_Error |
| 754 | 754 | */ |
| 755 | - public function set_props( $props, $context = 'set' ) { |
|
| 755 | + public function set_props($props, $context = 'set') { |
|
| 756 | 756 | $errors = false; |
| 757 | 757 | |
| 758 | - foreach ( $props as $prop => $value ) { |
|
| 758 | + foreach ($props as $prop => $value) { |
|
| 759 | 759 | try { |
| 760 | 760 | /** |
| 761 | 761 | * Checks if the prop being set is allowed, and the value is not null. |
| 762 | 762 | */ |
| 763 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
| 763 | + if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) { |
|
| 764 | 764 | continue; |
| 765 | 765 | } |
| 766 | 766 | $setter = "set_$prop"; |
| 767 | 767 | |
| 768 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
| 769 | - $this->{$setter}( $value ); |
|
| 768 | + if (is_callable(array($this, $setter))) { |
|
| 769 | + $this->{$setter}($value); |
|
| 770 | 770 | } |
| 771 | - } catch ( Exception $e ) { |
|
| 772 | - if ( ! $errors ) { |
|
| 771 | + } catch (Exception $e) { |
|
| 772 | + if (!$errors) { |
|
| 773 | 773 | $errors = new WP_Error(); |
| 774 | 774 | } |
| 775 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
| 775 | + $errors->add($e->getCode(), $e->getMessage()); |
|
| 776 | 776 | $this->last_error = $e->getMessage(); |
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
| 780 | + return $errors && count($errors->get_error_codes()) ? $errors : true; |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | /** |
@@ -790,14 +790,14 @@ discard block |
||
| 790 | 790 | * @param string $prop Name of prop to set. |
| 791 | 791 | * @param mixed $value Value of the prop. |
| 792 | 792 | */ |
| 793 | - protected function set_prop( $prop, $value ) { |
|
| 794 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 795 | - if ( true === $this->object_read ) { |
|
| 796 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
| 797 | - $this->changes[ $prop ] = $value; |
|
| 793 | + protected function set_prop($prop, $value) { |
|
| 794 | + if (array_key_exists($prop, $this->data)) { |
|
| 795 | + if (true === $this->object_read) { |
|
| 796 | + if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) { |
|
| 797 | + $this->changes[$prop] = $value; |
|
| 798 | 798 | } |
| 799 | 799 | } else { |
| 800 | - $this->data[ $prop ] = $value; |
|
| 800 | + $this->data[$prop] = $value; |
|
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | } |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | * @since 1.0.19 |
| 819 | 819 | */ |
| 820 | 820 | public function apply_changes() { |
| 821 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
| 821 | + $this->data = array_replace_recursive($this->data, $this->changes); |
|
| 822 | 822 | $this->changes = array(); |
| 823 | 823 | } |
| 824 | 824 | |
@@ -843,14 +843,14 @@ discard block |
||
| 843 | 843 | * @param string $context What the value is for. Valid values are view and edit. |
| 844 | 844 | * @return mixed |
| 845 | 845 | */ |
| 846 | - protected function get_prop( $prop, $context = 'view' ) { |
|
| 846 | + protected function get_prop($prop, $context = 'view') { |
|
| 847 | 847 | $value = null; |
| 848 | 848 | |
| 849 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 850 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
| 849 | + if (array_key_exists($prop, $this->data)) { |
|
| 850 | + $value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop]; |
|
| 851 | 851 | |
| 852 | - if ( 'view' === $context ) { |
|
| 853 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
| 852 | + if ('view' === $context) { |
|
| 853 | + $value = apply_filters($this->get_hook_prefix() . $prop, $value, $this); |
|
| 854 | 854 | } |
| 855 | 855 | } |
| 856 | 856 | |
@@ -864,13 +864,13 @@ discard block |
||
| 864 | 864 | * @param string $prop Name of prop to set. |
| 865 | 865 | * @param string|integer $value Value of the prop. |
| 866 | 866 | */ |
| 867 | - protected function set_date_prop( $prop, $value ) { |
|
| 867 | + protected function set_date_prop($prop, $value) { |
|
| 868 | 868 | |
| 869 | - if ( empty( $value ) ) { |
|
| 870 | - $this->set_prop( $prop, null ); |
|
| 869 | + if (empty($value)) { |
|
| 870 | + $this->set_prop($prop, null); |
|
| 871 | 871 | return; |
| 872 | 872 | } |
| 873 | - $this->set_prop( $prop, $value ); |
|
| 873 | + $this->set_prop($prop, $value); |
|
| 874 | 874 | |
| 875 | 875 | } |
| 876 | 876 | |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | * @param string $code Error code. |
| 882 | 882 | * @param string $message Error message. |
| 883 | 883 | */ |
| 884 | - protected function error( $code, $message ) { |
|
| 884 | + protected function error($code, $message) { |
|
| 885 | 885 | $this->last_error = $message; |
| 886 | 886 | } |
| 887 | 887 | |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | */ |
| 894 | 894 | public function exists() { |
| 895 | 895 | $id = $this->get_id(); |
| 896 | - return ! empty( $id ); |
|
| 896 | + return !empty($id); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | - exit; |
|
| 8 | + exit; |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | /** |
@@ -15,510 +15,510 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
| 20 | - * |
|
| 21 | - * @since 1.0.19 |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $internal_meta_keys = array( |
|
| 25 | - '_wpinv_subscr_profile_id', |
|
| 26 | - '_wpinv_taxes', |
|
| 27 | - '_wpinv_fees', |
|
| 28 | - '_wpinv_discounts', |
|
| 29 | - '_wpinv_submission_id', |
|
| 30 | - '_wpinv_payment_form', |
|
| 31 | - '_wpinv_is_viewed', |
|
| 32 | - 'wpinv_email_cc', |
|
| 33 | - 'wpinv_template' |
|
| 34 | - ); |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * A map of meta keys to data props. |
|
| 38 | - * |
|
| 39 | - * @since 1.0.19 |
|
| 40 | - * |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - protected $meta_key_to_props = array( |
|
| 44 | - '_wpinv_subscr_profile_id' => 'subscription_id', |
|
| 45 | - '_wpinv_taxes' => 'taxes', |
|
| 46 | - '_wpinv_fees' => 'fees', |
|
| 47 | - '_wpinv_discounts' => 'discounts', |
|
| 48 | - '_wpinv_submission_id' => 'submission_id', |
|
| 49 | - '_wpinv_payment_form' => 'payment_form', |
|
| 50 | - '_wpinv_is_viewed' => 'is_viewed', |
|
| 51 | - 'wpinv_email_cc' => 'email_cc', |
|
| 52 | - 'wpinv_template' => 'template', |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * A map of database fields to data props. |
|
| 57 | - * |
|
| 58 | - * @since 1.0.19 |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - protected $database_fields_to_props = array( |
|
| 63 | - 'post_id' => 'id', |
|
| 64 | - 'number' => 'number', |
|
| 65 | - 'currency' => 'currency', |
|
| 66 | - 'key' => 'key', |
|
| 67 | - 'type' => 'type', |
|
| 68 | - 'mode' => 'mode', |
|
| 69 | - 'user_ip' => 'user_ip', |
|
| 70 | - 'first_name' => 'first_name', |
|
| 71 | - 'last_name' => 'last_name', |
|
| 72 | - 'address' => 'address', |
|
| 73 | - 'city' => 'city', |
|
| 74 | - 'state' => 'state', |
|
| 75 | - 'country' => 'country', |
|
| 76 | - 'zip' => 'zip', |
|
| 77 | - 'zip' => 'zip', |
|
| 78 | - 'adddress_confirmed' => 'address_confirmed', |
|
| 79 | - 'gateway' => 'gateway', |
|
| 80 | - 'transaction_id' => 'transaction_id', |
|
| 81 | - 'currency' => 'currency', |
|
| 82 | - 'subtotal' => 'subtotal', |
|
| 83 | - 'tax' => 'total_tax', |
|
| 84 | - 'fees_total' => 'total_fees', |
|
| 85 | - 'discount' => 'total_discount', |
|
| 86 | - 'total' => 'total', |
|
| 87 | - 'discount_code' => 'discount_code', |
|
| 88 | - 'disable_taxes' => 'disable_taxes', |
|
| 89 | - 'due_date' => 'due_date', |
|
| 90 | - 'completed_date' => 'completed_date', |
|
| 91 | - 'company' => 'company', |
|
| 92 | - 'vat_number' => 'vat_number', |
|
| 93 | - 'vat_rate' => 'vat_rate', |
|
| 94 | - ); |
|
| 95 | - |
|
| 96 | - /* |
|
| 18 | + /** |
|
| 19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
| 20 | + * |
|
| 21 | + * @since 1.0.19 |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $internal_meta_keys = array( |
|
| 25 | + '_wpinv_subscr_profile_id', |
|
| 26 | + '_wpinv_taxes', |
|
| 27 | + '_wpinv_fees', |
|
| 28 | + '_wpinv_discounts', |
|
| 29 | + '_wpinv_submission_id', |
|
| 30 | + '_wpinv_payment_form', |
|
| 31 | + '_wpinv_is_viewed', |
|
| 32 | + 'wpinv_email_cc', |
|
| 33 | + 'wpinv_template' |
|
| 34 | + ); |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * A map of meta keys to data props. |
|
| 38 | + * |
|
| 39 | + * @since 1.0.19 |
|
| 40 | + * |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + protected $meta_key_to_props = array( |
|
| 44 | + '_wpinv_subscr_profile_id' => 'subscription_id', |
|
| 45 | + '_wpinv_taxes' => 'taxes', |
|
| 46 | + '_wpinv_fees' => 'fees', |
|
| 47 | + '_wpinv_discounts' => 'discounts', |
|
| 48 | + '_wpinv_submission_id' => 'submission_id', |
|
| 49 | + '_wpinv_payment_form' => 'payment_form', |
|
| 50 | + '_wpinv_is_viewed' => 'is_viewed', |
|
| 51 | + 'wpinv_email_cc' => 'email_cc', |
|
| 52 | + 'wpinv_template' => 'template', |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * A map of database fields to data props. |
|
| 57 | + * |
|
| 58 | + * @since 1.0.19 |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + protected $database_fields_to_props = array( |
|
| 63 | + 'post_id' => 'id', |
|
| 64 | + 'number' => 'number', |
|
| 65 | + 'currency' => 'currency', |
|
| 66 | + 'key' => 'key', |
|
| 67 | + 'type' => 'type', |
|
| 68 | + 'mode' => 'mode', |
|
| 69 | + 'user_ip' => 'user_ip', |
|
| 70 | + 'first_name' => 'first_name', |
|
| 71 | + 'last_name' => 'last_name', |
|
| 72 | + 'address' => 'address', |
|
| 73 | + 'city' => 'city', |
|
| 74 | + 'state' => 'state', |
|
| 75 | + 'country' => 'country', |
|
| 76 | + 'zip' => 'zip', |
|
| 77 | + 'zip' => 'zip', |
|
| 78 | + 'adddress_confirmed' => 'address_confirmed', |
|
| 79 | + 'gateway' => 'gateway', |
|
| 80 | + 'transaction_id' => 'transaction_id', |
|
| 81 | + 'currency' => 'currency', |
|
| 82 | + 'subtotal' => 'subtotal', |
|
| 83 | + 'tax' => 'total_tax', |
|
| 84 | + 'fees_total' => 'total_fees', |
|
| 85 | + 'discount' => 'total_discount', |
|
| 86 | + 'total' => 'total', |
|
| 87 | + 'discount_code' => 'discount_code', |
|
| 88 | + 'disable_taxes' => 'disable_taxes', |
|
| 89 | + 'due_date' => 'due_date', |
|
| 90 | + 'completed_date' => 'completed_date', |
|
| 91 | + 'company' => 'company', |
|
| 92 | + 'vat_number' => 'vat_number', |
|
| 93 | + 'vat_rate' => 'vat_rate', |
|
| 94 | + ); |
|
| 95 | + |
|
| 96 | + /* |
|
| 97 | 97 | |-------------------------------------------------------------------------- |
| 98 | 98 | | CRUD Methods |
| 99 | 99 | |-------------------------------------------------------------------------- |
| 100 | 100 | */ |
| 101 | - /** |
|
| 102 | - * Method to create a new invoice in the database. |
|
| 103 | - * |
|
| 104 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 105 | - */ |
|
| 106 | - public function create( &$invoice ) { |
|
| 107 | - $invoice->set_version( WPINV_VERSION ); |
|
| 108 | - $invoice->set_date_created( current_time('mysql') ); |
|
| 109 | - |
|
| 110 | - // Create a new post. |
|
| 111 | - $id = wp_insert_post( |
|
| 112 | - apply_filters( |
|
| 113 | - 'getpaid_new_invoice_data', |
|
| 114 | - array( |
|
| 115 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
| 116 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
| 117 | - 'post_status' => $this->get_post_status( $invoice ), |
|
| 118 | - 'ping_status' => 'closed', |
|
| 119 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
| 120 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
| 121 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
| 122 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
| 123 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
| 124 | - ) |
|
| 125 | - ), |
|
| 126 | - true |
|
| 127 | - ); |
|
| 128 | - |
|
| 129 | - if ( $id && ! is_wp_error( $id ) ) { |
|
| 130 | - |
|
| 131 | - // Update the new id and regenerate a title. |
|
| 132 | - $invoice->set_id( $id ); |
|
| 133 | - wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) ); |
|
| 134 | - |
|
| 135 | - // Ensure both the key and number are set. |
|
| 136 | - $invoice->get_key(); |
|
| 137 | - $invoice->get_number(); |
|
| 138 | - |
|
| 139 | - // Save special fields and items. |
|
| 140 | - $this->save_special_fields( $invoice ); |
|
| 141 | - $this->save_items( $invoice ); |
|
| 142 | - |
|
| 143 | - // Update meta data. |
|
| 144 | - $this->update_post_meta( $invoice ); |
|
| 145 | - $invoice->save_meta_data(); |
|
| 146 | - |
|
| 147 | - // Apply changes. |
|
| 148 | - $invoice->apply_changes(); |
|
| 149 | - $this->clear_caches( $invoice ); |
|
| 150 | - |
|
| 151 | - // Fires after a new invoice is created. |
|
| 152 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 153 | - return true; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if ( is_wp_error( $id ) ) { |
|
| 157 | - $invoice->last_error = $id->get_error_message(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return false; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Method to read an invoice from the database. |
|
| 165 | - * |
|
| 166 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 167 | - * |
|
| 168 | - */ |
|
| 169 | - public function read( &$invoice ) { |
|
| 170 | - |
|
| 171 | - $invoice->set_defaults(); |
|
| 172 | - $invoice_object = get_post( $invoice->get_id() ); |
|
| 173 | - |
|
| 174 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
| 175 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
| 176 | - $invoice->set_id( 0 ); |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $invoice->set_props( |
|
| 181 | - array( |
|
| 182 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
| 183 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
| 184 | - 'status' => $invoice_object->post_status, |
|
| 185 | - 'author' => $invoice_object->post_author, |
|
| 186 | - 'description' => $invoice_object->post_excerpt, |
|
| 187 | - 'parent_id' => $invoice_object->post_parent, |
|
| 188 | - 'name' => $invoice_object->post_title, |
|
| 189 | - 'path' => $invoice_object->post_name, |
|
| 190 | - 'post_type' => $invoice_object->post_type, |
|
| 191 | - ) |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - $invoice->set_type( $invoice_object->post_type ); |
|
| 195 | - |
|
| 196 | - $this->read_object_data( $invoice, $invoice_object ); |
|
| 197 | - $this->add_special_fields( $invoice ); |
|
| 198 | - $this->add_items( $invoice ); |
|
| 199 | - $invoice->read_meta_data(); |
|
| 200 | - $invoice->set_object_read( true ); |
|
| 201 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 202 | - |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Method to update an invoice in the database. |
|
| 207 | - * |
|
| 208 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 209 | - */ |
|
| 210 | - public function update( &$invoice ) { |
|
| 211 | - $invoice->save_meta_data(); |
|
| 212 | - $invoice->set_version( WPINV_VERSION ); |
|
| 213 | - |
|
| 214 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
| 215 | - $invoice->set_date_created( current_time('mysql') ); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // Ensure both the key and number are set. |
|
| 219 | - $invoice->get_key(); |
|
| 220 | - $invoice->get_number(); |
|
| 221 | - |
|
| 222 | - // Grab the current status so we can compare. |
|
| 223 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
| 224 | - |
|
| 225 | - $changes = $invoice->get_changes(); |
|
| 226 | - |
|
| 227 | - // Only update the post when the post data changes. |
|
| 228 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
| 229 | - $post_data = array( |
|
| 230 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
| 231 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
| 232 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
| 233 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
| 234 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
| 235 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
| 236 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
| 237 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
| 238 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
| 239 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
| 240 | - ); |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
| 244 | - * to update data, since wp_update_post spawns more calls to the |
|
| 245 | - * save_post action. |
|
| 246 | - * |
|
| 247 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
| 248 | - * or an update purely from CRUD. |
|
| 249 | - */ |
|
| 250 | - if ( doing_action( 'save_post' ) ) { |
|
| 251 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
| 252 | - clean_post_cache( $invoice->get_id() ); |
|
| 253 | - } else { |
|
| 254 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
| 255 | - } |
|
| 256 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // Update meta data. |
|
| 260 | - $this->update_post_meta( $invoice ); |
|
| 261 | - |
|
| 262 | - // Save special fields and items. |
|
| 263 | - $this->save_special_fields( $invoice ); |
|
| 264 | - $this->save_items( $invoice ); |
|
| 265 | - |
|
| 266 | - // Apply the changes. |
|
| 267 | - $invoice->apply_changes(); |
|
| 268 | - |
|
| 269 | - // Clear caches. |
|
| 270 | - $this->clear_caches( $invoice ); |
|
| 271 | - |
|
| 272 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
| 273 | - $new_status = $invoice->get_status( 'edit' ); |
|
| 274 | - |
|
| 275 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
| 276 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 277 | - } else { |
|
| 278 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /* |
|
| 101 | + /** |
|
| 102 | + * Method to create a new invoice in the database. |
|
| 103 | + * |
|
| 104 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 105 | + */ |
|
| 106 | + public function create( &$invoice ) { |
|
| 107 | + $invoice->set_version( WPINV_VERSION ); |
|
| 108 | + $invoice->set_date_created( current_time('mysql') ); |
|
| 109 | + |
|
| 110 | + // Create a new post. |
|
| 111 | + $id = wp_insert_post( |
|
| 112 | + apply_filters( |
|
| 113 | + 'getpaid_new_invoice_data', |
|
| 114 | + array( |
|
| 115 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
| 116 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
| 117 | + 'post_status' => $this->get_post_status( $invoice ), |
|
| 118 | + 'ping_status' => 'closed', |
|
| 119 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
| 120 | + 'post_title' => $invoice->get_title( 'edit' ), |
|
| 121 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
| 122 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
| 123 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
| 124 | + ) |
|
| 125 | + ), |
|
| 126 | + true |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + if ( $id && ! is_wp_error( $id ) ) { |
|
| 130 | + |
|
| 131 | + // Update the new id and regenerate a title. |
|
| 132 | + $invoice->set_id( $id ); |
|
| 133 | + wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) ); |
|
| 134 | + |
|
| 135 | + // Ensure both the key and number are set. |
|
| 136 | + $invoice->get_key(); |
|
| 137 | + $invoice->get_number(); |
|
| 138 | + |
|
| 139 | + // Save special fields and items. |
|
| 140 | + $this->save_special_fields( $invoice ); |
|
| 141 | + $this->save_items( $invoice ); |
|
| 142 | + |
|
| 143 | + // Update meta data. |
|
| 144 | + $this->update_post_meta( $invoice ); |
|
| 145 | + $invoice->save_meta_data(); |
|
| 146 | + |
|
| 147 | + // Apply changes. |
|
| 148 | + $invoice->apply_changes(); |
|
| 149 | + $this->clear_caches( $invoice ); |
|
| 150 | + |
|
| 151 | + // Fires after a new invoice is created. |
|
| 152 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 153 | + return true; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if ( is_wp_error( $id ) ) { |
|
| 157 | + $invoice->last_error = $id->get_error_message(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return false; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Method to read an invoice from the database. |
|
| 165 | + * |
|
| 166 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 167 | + * |
|
| 168 | + */ |
|
| 169 | + public function read( &$invoice ) { |
|
| 170 | + |
|
| 171 | + $invoice->set_defaults(); |
|
| 172 | + $invoice_object = get_post( $invoice->get_id() ); |
|
| 173 | + |
|
| 174 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
| 175 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
| 176 | + $invoice->set_id( 0 ); |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $invoice->set_props( |
|
| 181 | + array( |
|
| 182 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
| 183 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
| 184 | + 'status' => $invoice_object->post_status, |
|
| 185 | + 'author' => $invoice_object->post_author, |
|
| 186 | + 'description' => $invoice_object->post_excerpt, |
|
| 187 | + 'parent_id' => $invoice_object->post_parent, |
|
| 188 | + 'name' => $invoice_object->post_title, |
|
| 189 | + 'path' => $invoice_object->post_name, |
|
| 190 | + 'post_type' => $invoice_object->post_type, |
|
| 191 | + ) |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + $invoice->set_type( $invoice_object->post_type ); |
|
| 195 | + |
|
| 196 | + $this->read_object_data( $invoice, $invoice_object ); |
|
| 197 | + $this->add_special_fields( $invoice ); |
|
| 198 | + $this->add_items( $invoice ); |
|
| 199 | + $invoice->read_meta_data(); |
|
| 200 | + $invoice->set_object_read( true ); |
|
| 201 | + do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 202 | + |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Method to update an invoice in the database. |
|
| 207 | + * |
|
| 208 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 209 | + */ |
|
| 210 | + public function update( &$invoice ) { |
|
| 211 | + $invoice->save_meta_data(); |
|
| 212 | + $invoice->set_version( WPINV_VERSION ); |
|
| 213 | + |
|
| 214 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
| 215 | + $invoice->set_date_created( current_time('mysql') ); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // Ensure both the key and number are set. |
|
| 219 | + $invoice->get_key(); |
|
| 220 | + $invoice->get_number(); |
|
| 221 | + |
|
| 222 | + // Grab the current status so we can compare. |
|
| 223 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
| 224 | + |
|
| 225 | + $changes = $invoice->get_changes(); |
|
| 226 | + |
|
| 227 | + // Only update the post when the post data changes. |
|
| 228 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
| 229 | + $post_data = array( |
|
| 230 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
| 231 | + 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
| 232 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
| 233 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
| 234 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
| 235 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
| 236 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
| 237 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
| 238 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
| 239 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
| 240 | + ); |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
| 244 | + * to update data, since wp_update_post spawns more calls to the |
|
| 245 | + * save_post action. |
|
| 246 | + * |
|
| 247 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
| 248 | + * or an update purely from CRUD. |
|
| 249 | + */ |
|
| 250 | + if ( doing_action( 'save_post' ) ) { |
|
| 251 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
| 252 | + clean_post_cache( $invoice->get_id() ); |
|
| 253 | + } else { |
|
| 254 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
| 255 | + } |
|
| 256 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // Update meta data. |
|
| 260 | + $this->update_post_meta( $invoice ); |
|
| 261 | + |
|
| 262 | + // Save special fields and items. |
|
| 263 | + $this->save_special_fields( $invoice ); |
|
| 264 | + $this->save_items( $invoice ); |
|
| 265 | + |
|
| 266 | + // Apply the changes. |
|
| 267 | + $invoice->apply_changes(); |
|
| 268 | + |
|
| 269 | + // Clear caches. |
|
| 270 | + $this->clear_caches( $invoice ); |
|
| 271 | + |
|
| 272 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
| 273 | + $new_status = $invoice->get_status( 'edit' ); |
|
| 274 | + |
|
| 275 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
| 276 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 277 | + } else { |
|
| 278 | + do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /* |
|
| 284 | 284 | |-------------------------------------------------------------------------- |
| 285 | 285 | | Additional Methods |
| 286 | 286 | |-------------------------------------------------------------------------- |
| 287 | 287 | */ |
| 288 | 288 | |
| 289 | - /** |
|
| 289 | + /** |
|
| 290 | 290 | * Retrieves special fields and adds to the invoice. |
| 291 | - * |
|
| 292 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 291 | + * |
|
| 292 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 293 | 293 | */ |
| 294 | 294 | public function add_special_fields( &$invoice ) { |
| 295 | - global $wpdb; |
|
| 295 | + global $wpdb; |
|
| 296 | 296 | |
| 297 | - // Maybe retrieve from the cache. |
|
| 298 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
| 297 | + // Maybe retrieve from the cache. |
|
| 298 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
| 299 | 299 | |
| 300 | - // If not found, retrieve from the db. |
|
| 301 | - if ( false === $data ) { |
|
| 302 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 300 | + // If not found, retrieve from the db. |
|
| 301 | + if ( false === $data ) { |
|
| 302 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 303 | 303 | |
| 304 | - $data = $wpdb->get_row( |
|
| 305 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
| 306 | - ARRAY_A |
|
| 307 | - ); |
|
| 304 | + $data = $wpdb->get_row( |
|
| 305 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
| 306 | + ARRAY_A |
|
| 307 | + ); |
|
| 308 | 308 | |
| 309 | - // Update the cache with our data |
|
| 310 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
| 309 | + // Update the cache with our data |
|
| 310 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
| 311 | 311 | |
| 312 | - } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - // Abort if the data does not exist. |
|
| 315 | - if ( empty( $data ) ) { |
|
| 316 | - $invoice->set_object_read( true ); |
|
| 317 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
| 318 | - return; |
|
| 319 | - } |
|
| 314 | + // Abort if the data does not exist. |
|
| 315 | + if ( empty( $data ) ) { |
|
| 316 | + $invoice->set_object_read( true ); |
|
| 317 | + $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
| 318 | + return; |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | - $props = array(); |
|
| 321 | + $props = array(); |
|
| 322 | 322 | |
| 323 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
| 323 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
| 324 | 324 | |
| 325 | - if ( $db_field == 'post_id' ) { |
|
| 326 | - continue; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - $props[ $prop ] = $data[ $db_field ]; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - $invoice->set_props( $props ); |
|
| 333 | - |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Gets a list of special fields that need updated based on change state |
|
| 338 | - * or if they are present in the database or not. |
|
| 339 | - * |
|
| 340 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
| 341 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
| 342 | - */ |
|
| 343 | - protected function get_special_fields_to_update( $invoice ) { |
|
| 344 | - $fields_to_update = array(); |
|
| 345 | - $changed_props = $invoice->get_changes(); |
|
| 346 | - |
|
| 347 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
| 348 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
| 349 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
| 350 | - $fields_to_update[ $database_field ] = $prop; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - return $fields_to_update; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
| 359 | - * |
|
| 360 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
| 361 | - * @since 1.0.19 |
|
| 362 | - */ |
|
| 363 | - protected function update_special_fields( &$invoice ) { |
|
| 364 | - global $wpdb; |
|
| 365 | - |
|
| 366 | - $updated_props = array(); |
|
| 367 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
| 368 | - |
|
| 369 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
| 370 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
| 371 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
| 372 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
| 373 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - if ( ! empty( $updated_props ) ) { |
|
| 377 | - |
|
| 378 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 379 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
| 380 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
| 381 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
| 382 | - |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Helper method that inserts special fields to the database. |
|
| 389 | - * |
|
| 390 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
| 391 | - * @since 1.0.19 |
|
| 392 | - */ |
|
| 393 | - protected function insert_special_fields( &$invoice ) { |
|
| 394 | - global $wpdb; |
|
| 395 | - |
|
| 396 | - $updated_props = array(); |
|
| 397 | - |
|
| 398 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
| 399 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
| 400 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
| 401 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
| 402 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 406 | - $wpdb->insert( $table, $updated_props ); |
|
| 407 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
| 408 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
| 409 | - |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 325 | + if ( $db_field == 'post_id' ) { |
|
| 326 | + continue; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + $props[ $prop ] = $data[ $db_field ]; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + $invoice->set_props( $props ); |
|
| 333 | + |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Gets a list of special fields that need updated based on change state |
|
| 338 | + * or if they are present in the database or not. |
|
| 339 | + * |
|
| 340 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
| 341 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
| 342 | + */ |
|
| 343 | + protected function get_special_fields_to_update( $invoice ) { |
|
| 344 | + $fields_to_update = array(); |
|
| 345 | + $changed_props = $invoice->get_changes(); |
|
| 346 | + |
|
| 347 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
| 348 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
| 349 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
| 350 | + $fields_to_update[ $database_field ] = $prop; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + return $fields_to_update; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
| 359 | + * |
|
| 360 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
| 361 | + * @since 1.0.19 |
|
| 362 | + */ |
|
| 363 | + protected function update_special_fields( &$invoice ) { |
|
| 364 | + global $wpdb; |
|
| 365 | + |
|
| 366 | + $updated_props = array(); |
|
| 367 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
| 368 | + |
|
| 369 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
| 370 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
| 371 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
| 372 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
| 373 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + if ( ! empty( $updated_props ) ) { |
|
| 377 | + |
|
| 378 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 379 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
| 380 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
| 381 | + do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
| 382 | + |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Helper method that inserts special fields to the database. |
|
| 389 | + * |
|
| 390 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
| 391 | + * @since 1.0.19 |
|
| 392 | + */ |
|
| 393 | + protected function insert_special_fields( &$invoice ) { |
|
| 394 | + global $wpdb; |
|
| 395 | + |
|
| 396 | + $updated_props = array(); |
|
| 397 | + |
|
| 398 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
| 399 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
| 400 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
| 401 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
| 402 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 406 | + $wpdb->insert( $table, $updated_props ); |
|
| 407 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
| 408 | + do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
| 409 | + |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | 413 | * Saves all special fields. |
| 414 | - * |
|
| 415 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 414 | + * |
|
| 415 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 416 | 416 | */ |
| 417 | 417 | public function save_special_fields( $invoice ) { |
| 418 | - global $wpdb; |
|
| 418 | + global $wpdb; |
|
| 419 | 419 | |
| 420 | - // The invoices table. |
|
| 421 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 422 | - $id = (int) $invoice->get_id(); |
|
| 420 | + // The invoices table. |
|
| 421 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 422 | + $id = (int) $invoice->get_id(); |
|
| 423 | 423 | |
| 424 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
| 424 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
| 425 | 425 | |
| 426 | - $this->update_special_fields( $invoice ); |
|
| 426 | + $this->update_special_fields( $invoice ); |
|
| 427 | 427 | |
| 428 | - } else { |
|
| 428 | + } else { |
|
| 429 | 429 | |
| 430 | - $this->insert_special_fields( $invoice ); |
|
| 430 | + $this->insert_special_fields( $invoice ); |
|
| 431 | 431 | |
| 432 | - } |
|
| 432 | + } |
|
| 433 | 433 | |
| 434 | - } |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - /** |
|
| 436 | + /** |
|
| 437 | 437 | * Set's up cart details. |
| 438 | - * |
|
| 439 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 438 | + * |
|
| 439 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 440 | 440 | */ |
| 441 | 441 | public function add_items( &$invoice ) { |
| 442 | - global $wpdb; |
|
| 442 | + global $wpdb; |
|
| 443 | 443 | |
| 444 | - // Maybe retrieve from the cache. |
|
| 445 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
| 444 | + // Maybe retrieve from the cache. |
|
| 445 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
| 446 | 446 | |
| 447 | - // If not found, retrieve from the db. |
|
| 448 | - if ( false === $items ) { |
|
| 449 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 447 | + // If not found, retrieve from the db. |
|
| 448 | + if ( false === $items ) { |
|
| 449 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 450 | 450 | |
| 451 | - $items = $wpdb->get_results( |
|
| 452 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
| 453 | - ); |
|
| 451 | + $items = $wpdb->get_results( |
|
| 452 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
| 453 | + ); |
|
| 454 | 454 | |
| 455 | - // Update the cache with our data |
|
| 456 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
| 455 | + // Update the cache with our data |
|
| 456 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
| 457 | 457 | |
| 458 | - } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - // Abort if no items found. |
|
| 460 | + // Abort if no items found. |
|
| 461 | 461 | if ( empty( $items ) ) { |
| 462 | 462 | return; |
| 463 | - } |
|
| 463 | + } |
|
| 464 | 464 | |
| 465 | - foreach ( $items as $item_data ) { |
|
| 466 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
| 465 | + foreach ( $items as $item_data ) { |
|
| 466 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
| 467 | 467 | |
| 468 | - // Set item data. |
|
| 469 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
| 470 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
| 471 | - $item->set_name( $item_data->item_name ); |
|
| 472 | - $item->set_description( $item_data->item_description ); |
|
| 473 | - $item->set_price( $item_data->item_price ); |
|
| 474 | - $item->set_quantity( $item_data->quantity ); |
|
| 475 | - $item->set_item_meta( $item_data->meta ); |
|
| 468 | + // Set item data. |
|
| 469 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
| 470 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
| 471 | + $item->set_name( $item_data->item_name ); |
|
| 472 | + $item->set_description( $item_data->item_description ); |
|
| 473 | + $item->set_price( $item_data->item_price ); |
|
| 474 | + $item->set_quantity( $item_data->quantity ); |
|
| 475 | + $item->set_item_meta( $item_data->meta ); |
|
| 476 | 476 | |
| 477 | - $invoice->add_item( $item ); |
|
| 478 | - } |
|
| 477 | + $invoice->add_item( $item ); |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - } |
|
| 480 | + } |
|
| 481 | 481 | |
| 482 | - /** |
|
| 482 | + /** |
|
| 483 | 483 | * Saves cart details. |
| 484 | - * |
|
| 485 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 484 | + * |
|
| 485 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 486 | 486 | */ |
| 487 | 487 | public function save_items( $invoice ) { |
| 488 | 488 | |
| 489 | - // Delete previously existing items. |
|
| 490 | - $this->delete_items( $invoice ); |
|
| 489 | + // Delete previously existing items. |
|
| 490 | + $this->delete_items( $invoice ); |
|
| 491 | 491 | |
| 492 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
| 492 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
| 493 | 493 | |
| 494 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
| 495 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
| 496 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
| 497 | - } |
|
| 494 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
| 495 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
| 496 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
| 500 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
| 499 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
| 500 | + do_action( "getpaid_invoice_save_items", $invoice ); |
|
| 501 | 501 | |
| 502 | - } |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - /** |
|
| 504 | + /** |
|
| 505 | 505 | * Deletes an invoice's cart details from the database. |
| 506 | - * |
|
| 507 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 506 | + * |
|
| 507 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 508 | 508 | */ |
| 509 | 509 | public function delete_items( $invoice ) { |
| 510 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
| 511 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
| 512 | - } |
|
| 510 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
| 511 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
| 512 | + } |
|
| 513 | 513 | |
| 514 | - /** |
|
| 514 | + /** |
|
| 515 | 515 | * Deletes an invoice's special fields from the database. |
| 516 | - * |
|
| 517 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 516 | + * |
|
| 517 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 518 | 518 | */ |
| 519 | 519 | public function delete_special_fields( $invoice ) { |
| 520 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
| 521 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
| 520 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
| 521 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * GetPaid_Invoice_Data_Store class file. |
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 7 | +if (!defined('ABSPATH')) { |
|
| 8 | 8 | exit; |
| 9 | 9 | } |
| 10 | 10 | |
@@ -103,57 +103,57 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @param WPInv_Invoice $invoice Invoice object. |
| 105 | 105 | */ |
| 106 | - public function create( &$invoice ) { |
|
| 107 | - $invoice->set_version( WPINV_VERSION ); |
|
| 108 | - $invoice->set_date_created( current_time('mysql') ); |
|
| 106 | + public function create(&$invoice) { |
|
| 107 | + $invoice->set_version(WPINV_VERSION); |
|
| 108 | + $invoice->set_date_created(current_time('mysql')); |
|
| 109 | 109 | |
| 110 | 110 | // Create a new post. |
| 111 | 111 | $id = wp_insert_post( |
| 112 | 112 | apply_filters( |
| 113 | 113 | 'getpaid_new_invoice_data', |
| 114 | 114 | array( |
| 115 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
| 116 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
| 117 | - 'post_status' => $this->get_post_status( $invoice ), |
|
| 115 | + 'post_date' => $invoice->get_date_created('edit'), |
|
| 116 | + 'post_type' => $invoice->get_post_type('edit'), |
|
| 117 | + 'post_status' => $this->get_post_status($invoice), |
|
| 118 | 118 | 'ping_status' => 'closed', |
| 119 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
| 120 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
| 121 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
| 122 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
| 123 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
| 119 | + 'post_author' => $invoice->get_user_id('edit'), |
|
| 120 | + 'post_title' => $invoice->get_title('edit'), |
|
| 121 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
| 122 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
| 123 | + 'post_name' => $invoice->get_path('edit'), |
|
| 124 | 124 | ) |
| 125 | 125 | ), |
| 126 | 126 | true |
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | - if ( $id && ! is_wp_error( $id ) ) { |
|
| 129 | + if ($id && !is_wp_error($id)) { |
|
| 130 | 130 | |
| 131 | 131 | // Update the new id and regenerate a title. |
| 132 | - $invoice->set_id( $id ); |
|
| 133 | - wp_update_post( array( 'ID' => $invoice->get_id(), 'post_title' => $invoice->get_number( 'edit' ) ) ); |
|
| 132 | + $invoice->set_id($id); |
|
| 133 | + wp_update_post(array('ID' => $invoice->get_id(), 'post_title' => $invoice->get_number('edit'))); |
|
| 134 | 134 | |
| 135 | 135 | // Ensure both the key and number are set. |
| 136 | 136 | $invoice->get_key(); |
| 137 | 137 | $invoice->get_number(); |
| 138 | 138 | |
| 139 | 139 | // Save special fields and items. |
| 140 | - $this->save_special_fields( $invoice ); |
|
| 141 | - $this->save_items( $invoice ); |
|
| 140 | + $this->save_special_fields($invoice); |
|
| 141 | + $this->save_items($invoice); |
|
| 142 | 142 | |
| 143 | 143 | // Update meta data. |
| 144 | - $this->update_post_meta( $invoice ); |
|
| 144 | + $this->update_post_meta($invoice); |
|
| 145 | 145 | $invoice->save_meta_data(); |
| 146 | 146 | |
| 147 | 147 | // Apply changes. |
| 148 | 148 | $invoice->apply_changes(); |
| 149 | - $this->clear_caches( $invoice ); |
|
| 149 | + $this->clear_caches($invoice); |
|
| 150 | 150 | |
| 151 | 151 | // Fires after a new invoice is created. |
| 152 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 152 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
| 153 | 153 | return true; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if ( is_wp_error( $id ) ) { |
|
| 156 | + if (is_wp_error($id)) { |
|
| 157 | 157 | $invoice->last_error = $id->get_error_message(); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -166,14 +166,14 @@ discard block |
||
| 166 | 166 | * @param WPInv_Invoice $invoice Invoice object. |
| 167 | 167 | * |
| 168 | 168 | */ |
| 169 | - public function read( &$invoice ) { |
|
| 169 | + public function read(&$invoice) { |
|
| 170 | 170 | |
| 171 | 171 | $invoice->set_defaults(); |
| 172 | - $invoice_object = get_post( $invoice->get_id() ); |
|
| 172 | + $invoice_object = get_post($invoice->get_id()); |
|
| 173 | 173 | |
| 174 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
| 175 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
| 176 | - $invoice->set_id( 0 ); |
|
| 174 | + if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) { |
|
| 175 | + $invoice->last_error = __('Invalid invoice.', 'invoicing'); |
|
| 176 | + $invoice->set_id(0); |
|
| 177 | 177 | return false; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -191,14 +191,14 @@ discard block |
||
| 191 | 191 | ) |
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | - $invoice->set_type( $invoice_object->post_type ); |
|
| 194 | + $invoice->set_type($invoice_object->post_type); |
|
| 195 | 195 | |
| 196 | - $this->read_object_data( $invoice, $invoice_object ); |
|
| 197 | - $this->add_special_fields( $invoice ); |
|
| 198 | - $this->add_items( $invoice ); |
|
| 196 | + $this->read_object_data($invoice, $invoice_object); |
|
| 197 | + $this->add_special_fields($invoice); |
|
| 198 | + $this->add_items($invoice); |
|
| 199 | 199 | $invoice->read_meta_data(); |
| 200 | - $invoice->set_object_read( true ); |
|
| 201 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 200 | + $invoice->set_object_read(true); |
|
| 201 | + do_action('getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
| 202 | 202 | |
| 203 | 203 | } |
| 204 | 204 | |
@@ -207,12 +207,12 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @param WPInv_Invoice $invoice Invoice object. |
| 209 | 209 | */ |
| 210 | - public function update( &$invoice ) { |
|
| 210 | + public function update(&$invoice) { |
|
| 211 | 211 | $invoice->save_meta_data(); |
| 212 | - $invoice->set_version( WPINV_VERSION ); |
|
| 212 | + $invoice->set_version(WPINV_VERSION); |
|
| 213 | 213 | |
| 214 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
| 215 | - $invoice->set_date_created( current_time('mysql') ); |
|
| 214 | + if (null === $invoice->get_date_created('edit')) { |
|
| 215 | + $invoice->set_date_created(current_time('mysql')); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | // Ensure both the key and number are set. |
@@ -220,23 +220,23 @@ discard block |
||
| 220 | 220 | $invoice->get_number(); |
| 221 | 221 | |
| 222 | 222 | // Grab the current status so we can compare. |
| 223 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
| 223 | + $previous_status = get_post_status($invoice->get_id()); |
|
| 224 | 224 | |
| 225 | 225 | $changes = $invoice->get_changes(); |
| 226 | 226 | |
| 227 | 227 | // Only update the post when the post data changes. |
| 228 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
| 228 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) { |
|
| 229 | 229 | $post_data = array( |
| 230 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
| 231 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
| 232 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
| 233 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
| 234 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
| 235 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
| 236 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
| 237 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
| 238 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
| 239 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
| 230 | + 'post_date' => $invoice->get_date_created('edit'), |
|
| 231 | + 'post_date_gmt' => $invoice->get_date_created_gmt('edit'), |
|
| 232 | + 'post_status' => $invoice->get_status('edit'), |
|
| 233 | + 'post_title' => $invoice->get_name('edit'), |
|
| 234 | + 'post_author' => $invoice->get_user_id('edit'), |
|
| 235 | + 'post_modified' => $invoice->get_date_modified('edit'), |
|
| 236 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
| 237 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
| 238 | + 'post_name' => $invoice->get_path('edit'), |
|
| 239 | + 'post_type' => $invoice->get_post_type('edit'), |
|
| 240 | 240 | ); |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -247,35 +247,35 @@ discard block |
||
| 247 | 247 | * This ensures hooks are fired by either WP itself (admin screen save), |
| 248 | 248 | * or an update purely from CRUD. |
| 249 | 249 | */ |
| 250 | - if ( doing_action( 'save_post' ) ) { |
|
| 251 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
| 252 | - clean_post_cache( $invoice->get_id() ); |
|
| 250 | + if (doing_action('save_post')) { |
|
| 251 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id())); |
|
| 252 | + clean_post_cache($invoice->get_id()); |
|
| 253 | 253 | } else { |
| 254 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
| 254 | + wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data)); |
|
| 255 | 255 | } |
| 256 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
| 256 | + $invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Update meta data. |
| 260 | - $this->update_post_meta( $invoice ); |
|
| 260 | + $this->update_post_meta($invoice); |
|
| 261 | 261 | |
| 262 | 262 | // Save special fields and items. |
| 263 | - $this->save_special_fields( $invoice ); |
|
| 264 | - $this->save_items( $invoice ); |
|
| 263 | + $this->save_special_fields($invoice); |
|
| 264 | + $this->save_items($invoice); |
|
| 265 | 265 | |
| 266 | 266 | // Apply the changes. |
| 267 | 267 | $invoice->apply_changes(); |
| 268 | 268 | |
| 269 | 269 | // Clear caches. |
| 270 | - $this->clear_caches( $invoice ); |
|
| 270 | + $this->clear_caches($invoice); |
|
| 271 | 271 | |
| 272 | 272 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
| 273 | - $new_status = $invoice->get_status( 'edit' ); |
|
| 273 | + $new_status = $invoice->get_status('edit'); |
|
| 274 | 274 | |
| 275 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
| 276 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 275 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
| 276 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
| 277 | 277 | } else { |
| 278 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
| 278 | + do_action('getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | } |
@@ -291,45 +291,45 @@ discard block |
||
| 291 | 291 | * |
| 292 | 292 | * @param WPInv_Invoice $invoice Invoice object. |
| 293 | 293 | */ |
| 294 | - public function add_special_fields( &$invoice ) { |
|
| 294 | + public function add_special_fields(&$invoice) { |
|
| 295 | 295 | global $wpdb; |
| 296 | 296 | |
| 297 | 297 | // Maybe retrieve from the cache. |
| 298 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
| 298 | + $data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
| 299 | 299 | |
| 300 | 300 | // If not found, retrieve from the db. |
| 301 | - if ( false === $data ) { |
|
| 302 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 301 | + if (false === $data) { |
|
| 302 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 303 | 303 | |
| 304 | 304 | $data = $wpdb->get_row( |
| 305 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
| 305 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()), |
|
| 306 | 306 | ARRAY_A |
| 307 | 307 | ); |
| 308 | 308 | |
| 309 | 309 | // Update the cache with our data |
| 310 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
| 310 | + wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields'); |
|
| 311 | 311 | |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | // Abort if the data does not exist. |
| 315 | - if ( empty( $data ) ) { |
|
| 316 | - $invoice->set_object_read( true ); |
|
| 317 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
| 315 | + if (empty($data)) { |
|
| 316 | + $invoice->set_object_read(true); |
|
| 317 | + $invoice->set_props(wpinv_get_user_address($invoice->get_user_id())); |
|
| 318 | 318 | return; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | $props = array(); |
| 322 | 322 | |
| 323 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
| 323 | + foreach ($this->database_fields_to_props as $db_field => $prop) { |
|
| 324 | 324 | |
| 325 | - if ( $db_field == 'post_id' ) { |
|
| 325 | + if ($db_field == 'post_id') { |
|
| 326 | 326 | continue; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - $props[ $prop ] = $data[ $db_field ]; |
|
| 329 | + $props[$prop] = $data[$db_field]; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - $invoice->set_props( $props ); |
|
| 332 | + $invoice->set_props($props); |
|
| 333 | 333 | |
| 334 | 334 | } |
| 335 | 335 | |
@@ -340,14 +340,14 @@ discard block |
||
| 340 | 340 | * @param WPInv_Invoice $invoice The Invoice object. |
| 341 | 341 | * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
| 342 | 342 | */ |
| 343 | - protected function get_special_fields_to_update( $invoice ) { |
|
| 343 | + protected function get_special_fields_to_update($invoice) { |
|
| 344 | 344 | $fields_to_update = array(); |
| 345 | - $changed_props = $invoice->get_changes(); |
|
| 345 | + $changed_props = $invoice->get_changes(); |
|
| 346 | 346 | |
| 347 | 347 | // Props should be updated if they are a part of the $changed array or don't exist yet. |
| 348 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
| 349 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
| 350 | - $fields_to_update[ $database_field ] = $prop; |
|
| 348 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
| 349 | + if (array_key_exists($prop, $changed_props)) { |
|
| 350 | + $fields_to_update[$database_field] = $prop; |
|
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
@@ -360,25 +360,25 @@ discard block |
||
| 360 | 360 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
| 361 | 361 | * @since 1.0.19 |
| 362 | 362 | */ |
| 363 | - protected function update_special_fields( &$invoice ) { |
|
| 363 | + protected function update_special_fields(&$invoice) { |
|
| 364 | 364 | global $wpdb; |
| 365 | 365 | |
| 366 | 366 | $updated_props = array(); |
| 367 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
| 367 | + $fields_to_update = $this->get_special_fields_to_update($invoice); |
|
| 368 | 368 | |
| 369 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
| 370 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
| 371 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
| 372 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
| 373 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
| 369 | + foreach ($fields_to_update as $database_field => $prop) { |
|
| 370 | + $value = $invoice->{"get_$prop"}('edit'); |
|
| 371 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
| 372 | + $value = is_bool($value) ? (int) $value : $value; |
|
| 373 | + $updated_props[$database_field] = maybe_serialize($value); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - if ( ! empty( $updated_props ) ) { |
|
| 376 | + if (!empty($updated_props)) { |
|
| 377 | 377 | |
| 378 | 378 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 379 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
| 380 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
| 381 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
| 379 | + $wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id())); |
|
| 380 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
| 381 | + do_action("getpaid_invoice_update_database_fields", $invoice, $updated_props); |
|
| 382 | 382 | |
| 383 | 383 | } |
| 384 | 384 | |
@@ -390,22 +390,22 @@ discard block |
||
| 390 | 390 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
| 391 | 391 | * @since 1.0.19 |
| 392 | 392 | */ |
| 393 | - protected function insert_special_fields( &$invoice ) { |
|
| 393 | + protected function insert_special_fields(&$invoice) { |
|
| 394 | 394 | global $wpdb; |
| 395 | 395 | |
| 396 | - $updated_props = array(); |
|
| 396 | + $updated_props = array(); |
|
| 397 | 397 | |
| 398 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
| 399 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
| 400 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
| 401 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
| 402 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
| 398 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
| 399 | + $value = $invoice->{"get_$prop"}('edit'); |
|
| 400 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
| 401 | + $value = is_bool($value) ? (int) $value : $value; |
|
| 402 | + $updated_props[$database_field] = maybe_serialize($value); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 406 | - $wpdb->insert( $table, $updated_props ); |
|
| 407 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
| 408 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
| 406 | + $wpdb->insert($table, $updated_props); |
|
| 407 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
| 408 | + do_action("getpaid_invoice_insert_database_fields", $invoice, $updated_props); |
|
| 409 | 409 | |
| 410 | 410 | } |
| 411 | 411 | |
@@ -414,20 +414,20 @@ discard block |
||
| 414 | 414 | * |
| 415 | 415 | * @param WPInv_Invoice $invoice Invoice object. |
| 416 | 416 | */ |
| 417 | - public function save_special_fields( $invoice ) { |
|
| 417 | + public function save_special_fields($invoice) { |
|
| 418 | 418 | global $wpdb; |
| 419 | 419 | |
| 420 | 420 | // The invoices table. |
| 421 | 421 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 422 | 422 | $id = (int) $invoice->get_id(); |
| 423 | 423 | |
| 424 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
| 424 | + if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) { |
|
| 425 | 425 | |
| 426 | - $this->update_special_fields( $invoice ); |
|
| 426 | + $this->update_special_fields($invoice); |
|
| 427 | 427 | |
| 428 | 428 | } else { |
| 429 | 429 | |
| 430 | - $this->insert_special_fields( $invoice ); |
|
| 430 | + $this->insert_special_fields($invoice); |
|
| 431 | 431 | |
| 432 | 432 | } |
| 433 | 433 | |
@@ -438,43 +438,43 @@ discard block |
||
| 438 | 438 | * |
| 439 | 439 | * @param WPInv_Invoice $invoice Invoice object. |
| 440 | 440 | */ |
| 441 | - public function add_items( &$invoice ) { |
|
| 441 | + public function add_items(&$invoice) { |
|
| 442 | 442 | global $wpdb; |
| 443 | 443 | |
| 444 | 444 | // Maybe retrieve from the cache. |
| 445 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
| 445 | + $items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
| 446 | 446 | |
| 447 | 447 | // If not found, retrieve from the db. |
| 448 | - if ( false === $items ) { |
|
| 449 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 448 | + if (false === $items) { |
|
| 449 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 450 | 450 | |
| 451 | 451 | $items = $wpdb->get_results( |
| 452 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
| 452 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id()) |
|
| 453 | 453 | ); |
| 454 | 454 | |
| 455 | 455 | // Update the cache with our data |
| 456 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
| 456 | + wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details'); |
|
| 457 | 457 | |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | // Abort if no items found. |
| 461 | - if ( empty( $items ) ) { |
|
| 461 | + if (empty($items)) { |
|
| 462 | 462 | return; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - foreach ( $items as $item_data ) { |
|
| 466 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
| 465 | + foreach ($items as $item_data) { |
|
| 466 | + $item = new GetPaid_Form_Item($item_data->item_id); |
|
| 467 | 467 | |
| 468 | 468 | // Set item data. |
| 469 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
| 470 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
| 471 | - $item->set_name( $item_data->item_name ); |
|
| 472 | - $item->set_description( $item_data->item_description ); |
|
| 473 | - $item->set_price( $item_data->item_price ); |
|
| 474 | - $item->set_quantity( $item_data->quantity ); |
|
| 475 | - $item->set_item_meta( $item_data->meta ); |
|
| 476 | - |
|
| 477 | - $invoice->add_item( $item ); |
|
| 469 | + $item->item_tax = wpinv_sanitize_amount($item_data->tax); |
|
| 470 | + $item->item_discount = wpinv_sanitize_amount($item_data->discount); |
|
| 471 | + $item->set_name($item_data->item_name); |
|
| 472 | + $item->set_description($item_data->item_description); |
|
| 473 | + $item->set_price($item_data->item_price); |
|
| 474 | + $item->set_quantity($item_data->quantity); |
|
| 475 | + $item->set_item_meta($item_data->meta); |
|
| 476 | + |
|
| 477 | + $invoice->add_item($item); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | } |
@@ -484,20 +484,20 @@ discard block |
||
| 484 | 484 | * |
| 485 | 485 | * @param WPInv_Invoice $invoice Invoice object. |
| 486 | 486 | */ |
| 487 | - public function save_items( $invoice ) { |
|
| 487 | + public function save_items($invoice) { |
|
| 488 | 488 | |
| 489 | 489 | // Delete previously existing items. |
| 490 | - $this->delete_items( $invoice ); |
|
| 490 | + $this->delete_items($invoice); |
|
| 491 | 491 | |
| 492 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
| 492 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
| 493 | 493 | |
| 494 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
| 495 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
| 496 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
| 494 | + foreach ($invoice->get_cart_details() as $item_data) { |
|
| 495 | + $item_data = array_map('maybe_serialize', $item_data); |
|
| 496 | + $GLOBALS['wpdb']->insert($table, $item_data); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
| 500 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
| 499 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
| 500 | + do_action("getpaid_invoice_save_items", $invoice); |
|
| 501 | 501 | |
| 502 | 502 | } |
| 503 | 503 | |
@@ -506,9 +506,9 @@ discard block |
||
| 506 | 506 | * |
| 507 | 507 | * @param WPInv_Invoice $invoice Invoice object. |
| 508 | 508 | */ |
| 509 | - public function delete_items( $invoice ) { |
|
| 510 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
| 511 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
| 509 | + public function delete_items($invoice) { |
|
| 510 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
| 511 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -516,9 +516,9 @@ discard block |
||
| 516 | 516 | * |
| 517 | 517 | * @param WPInv_Invoice $invoice Invoice object. |
| 518 | 518 | */ |
| 519 | - public function delete_special_fields( $invoice ) { |
|
| 520 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
| 521 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
| 519 | + public function delete_special_fields($invoice) { |
|
| 520 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
| 521 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | } |
@@ -14,744 +14,744 @@ 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 | - * Session instance. |
|
| 26 | - * |
|
| 27 | - * @var WPInv_Session_Handler |
|
| 28 | - */ |
|
| 29 | - public $session; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Notes instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Notes |
|
| 35 | - */ |
|
| 36 | - public $notes; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Reports instance. |
|
| 40 | - * |
|
| 41 | - * @var WPInv_Reports |
|
| 42 | - */ |
|
| 43 | - public $reports; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * API instance. |
|
| 47 | - * |
|
| 48 | - * @var WPInv_API |
|
| 49 | - */ |
|
| 50 | - public $api; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Form elements instance. |
|
| 54 | - * |
|
| 55 | - * @var WPInv_Payment_Form_Elements |
|
| 56 | - */ |
|
| 57 | - public $form_elements; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Tax instance. |
|
| 61 | - * |
|
| 62 | - * @var WPInv_EUVat |
|
| 63 | - */ |
|
| 64 | - public $tax; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param array An array of payment gateways. |
|
| 68 | - */ |
|
| 69 | - public $gateways; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Post types instance. |
|
| 73 | - * |
|
| 74 | - * @var GetPaid_Post_Types |
|
| 75 | - */ |
|
| 76 | - public $post_types; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Class constructor. |
|
| 80 | - */ |
|
| 81 | - public function __construct() { |
|
| 82 | - $this->define_constants(); |
|
| 83 | - $this->includes(); |
|
| 84 | - $this->init_hooks(); |
|
| 85 | - $this->set_properties(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Define class properties. |
|
| 90 | - */ |
|
| 91 | - public function set_properties() { |
|
| 92 | - |
|
| 93 | - $this->session = new WPInv_Session_Handler(); |
|
| 94 | - $GLOBALS['wpi_session'] = $this->session; // Backwards compatibility. |
|
| 95 | - $this->notes = new WPInv_Notes(); |
|
| 96 | - $this->reports = new WPInv_Reports(); |
|
| 97 | - $this->api = new WPInv_API(); |
|
| 98 | - $this->form_elements = new WPInv_Payment_Form_Elements(); |
|
| 99 | - $this->tax = new WPInv_EUVat(); |
|
| 100 | - $this->post_types = new GetPaid_Post_Types(); |
|
| 101 | - $this->tax->init(); |
|
| 102 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
| 103 | - |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Define plugin constants. |
|
| 108 | - */ |
|
| 109 | - public function define_constants() { |
|
| 110 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 111 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 112 | - $this->version = WPINV_VERSION; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Hook into actions and filters. |
|
| 117 | - * |
|
| 118 | - * @since 1.0.19 |
|
| 119 | - */ |
|
| 120 | - protected function init_hooks() { |
|
| 121 | - /* Internationalize the text strings used. */ |
|
| 122 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 123 | - |
|
| 124 | - /* Perform actions on admin initialization. */ |
|
| 125 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 126 | - |
|
| 127 | - // Init the plugin after WordPress inits. |
|
| 128 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 129 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
| 130 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 131 | - |
|
| 132 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 133 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 137 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 138 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 139 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 140 | - |
|
| 141 | - if ( is_admin() ) { |
|
| 142 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 143 | - add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 144 | - add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) ); |
|
| 145 | - |
|
| 146 | - } else { |
|
| 147 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 151 | - |
|
| 152 | - // Fires after registering core hooks. |
|
| 153 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 154 | - |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Maybe show the AyeCode Connect Notice. |
|
| 159 | - */ |
|
| 160 | - public function init_ayecode_connect_helper(){ |
|
| 161 | - // AyeCode Connect notice |
|
| 162 | - if ( is_admin() ){ |
|
| 163 | - // set the strings so they can be translated |
|
| 164 | - $strings = array( |
|
| 165 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 166 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 167 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 168 | - 'connect_button' => __("Connect Site","invoicing"), |
|
| 169 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
| 170 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 171 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 172 | - ); |
|
| 173 | - new AyeCode_Connect_Helper($strings,array('wpi-addons')); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function plugins_loaded() { |
|
| 178 | - /* Internationalize the text strings used. */ |
|
| 179 | - $this->load_textdomain(); |
|
| 180 | - |
|
| 181 | - do_action( 'wpinv_loaded' ); |
|
| 182 | - |
|
| 183 | - // Fix oxygen page builder conflict |
|
| 184 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 185 | - wpinv_oxygen_fix_conflict(); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Load the translation of the plugin. |
|
| 191 | - * |
|
| 192 | - * @since 1.0 |
|
| 193 | - */ |
|
| 194 | - public function load_textdomain( $locale = NULL ) { |
|
| 195 | - if ( empty( $locale ) ) { |
|
| 196 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 200 | - |
|
| 201 | - unload_textdomain( 'invoicing' ); |
|
| 202 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 203 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Define language constants. |
|
| 207 | - */ |
|
| 208 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Include required core files used in admin and on the frontend. |
|
| 213 | - */ |
|
| 214 | - public function includes() { |
|
| 215 | - |
|
| 216 | - // Start with the settings. |
|
| 217 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 218 | - |
|
| 219 | - // Packages/libraries. |
|
| 220 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 221 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 222 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
| 223 | - |
|
| 224 | - // Load functions. |
|
| 225 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 226 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 227 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 228 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 229 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 230 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 231 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 232 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 233 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 234 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 235 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 236 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 237 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 238 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 239 | - |
|
| 240 | - // Register autoloader. |
|
| 241 | - try { |
|
| 242 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 243 | - } catch ( Exception $e ) { |
|
| 244 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 248 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 249 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 250 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 251 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 252 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 253 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 254 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 255 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 256 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 257 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
| 259 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 260 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 261 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 262 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 263 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 264 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 265 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 266 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 267 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 268 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 269 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 270 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Load the tax class. |
|
| 274 | - */ |
|
| 275 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
| 276 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 280 | - if ( !empty( $gateways ) ) { |
|
| 281 | - foreach ( $gateways as $gateway ) { |
|
| 282 | - if ( $gateway == 'manual' ) { |
|
| 283 | - continue; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
| 287 | - |
|
| 288 | - if ( file_exists( $gateway_file ) ) { |
|
| 289 | - require_once( $gateway_file ); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 295 | - GetPaid_Post_Types_Admin::init(); |
|
| 296 | - |
|
| 297 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 298 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 299 | - //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
| 300 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 301 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 302 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 303 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 304 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 305 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 306 | - //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 307 | - // load the user class only on the users.php page |
|
| 308 | - global $pagenow; |
|
| 309 | - if($pagenow=='users.php'){ |
|
| 310 | - new WPInv_Admin_Users(); |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - // Register cli commands |
|
| 315 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 316 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 317 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - // include css inliner |
|
| 321 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 322 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Class autoloader |
|
| 330 | - * |
|
| 331 | - * @param string $class_name The name of the class to load. |
|
| 332 | - * @access public |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @return void |
|
| 335 | - */ |
|
| 336 | - public function autoload( $class_name ) { |
|
| 337 | - |
|
| 338 | - // Normalize the class name... |
|
| 339 | - $class_name = strtolower( $class_name ); |
|
| 340 | - |
|
| 341 | - // ... and make sure it is our class. |
|
| 342 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 343 | - return; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Next, prepare the file name from the class. |
|
| 347 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 348 | - |
|
| 349 | - // Base path of the classes. |
|
| 350 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 351 | - |
|
| 352 | - // And an array of possible locations in order of importance. |
|
| 353 | - $locations = array( |
|
| 354 | - "$plugin_path/includes", |
|
| 355 | - "$plugin_path/includes/data-stores", |
|
| 356 | - "$plugin_path/includes/gateways", |
|
| 357 | - "$plugin_path/includes/api", |
|
| 358 | - "$plugin_path/includes/admin", |
|
| 359 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 360 | - ); |
|
| 361 | - |
|
| 362 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 363 | - |
|
| 364 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 365 | - include trailingslashit( $location ) . $file_name; |
|
| 366 | - break; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Inits hooks etc. |
|
| 375 | - */ |
|
| 376 | - public function init() { |
|
| 377 | - |
|
| 378 | - // Fires before getpaid inits. |
|
| 379 | - do_action( 'before_getpaid_init', $this ); |
|
| 380 | - |
|
| 381 | - // Load default gateways. |
|
| 382 | - $gateways = apply_filters( |
|
| 383 | - 'getpaid_default_gateways', |
|
| 384 | - array( |
|
| 385 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 386 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 387 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 388 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 389 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 390 | - ) |
|
| 391 | - ); |
|
| 392 | - |
|
| 393 | - foreach ( $gateways as $id => $class ) { |
|
| 394 | - $this->gateways[ $id ] = new $class(); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - // Fires after getpaid inits. |
|
| 398 | - do_action( 'getpaid_init', $this ); |
|
| 399 | - |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Checks if this is an IPN request and processes it. |
|
| 404 | - */ |
|
| 405 | - public function maybe_process_ipn() { |
|
| 406 | - |
|
| 407 | - // Ensure that this is an IPN request. |
|
| 408 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 409 | - return; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 413 | - |
|
| 414 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 415 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 416 | - exit; |
|
| 417 | - |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - public function admin_init() { |
|
| 421 | - $this->default_payment_form = wpinv_get_default_payment_form(); |
|
| 422 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - public function activation_redirect() { |
|
| 426 | - // Bail if no activation redirect |
|
| 427 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 428 | - return; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - // Delete the redirect transient |
|
| 432 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 433 | - |
|
| 434 | - // Bail if activating from network, or bulk |
|
| 435 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 436 | - return; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 440 | - exit; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - public function enqueue_scripts() { |
|
| 444 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 445 | - |
|
| 446 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 447 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 448 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 449 | - |
|
| 450 | - // Register scripts |
|
| 451 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 452 | - 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' ) ); |
|
| 453 | - |
|
| 454 | - $localize = array(); |
|
| 455 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 456 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 457 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
| 458 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
| 459 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
| 460 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
| 461 | - $localize['decimals'] = wpinv_decimals(); |
|
| 462 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 463 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 464 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 465 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 466 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 467 | - |
|
| 468 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 469 | - |
|
| 470 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 471 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
| 472 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
| 473 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 474 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 475 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 476 | - } |
|
| 477 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 478 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 482 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 483 | - |
|
| 484 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 485 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 486 | - |
|
| 487 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 488 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - public function admin_enqueue_scripts( $hook ) { |
|
| 492 | - global $post, $pagenow; |
|
| 493 | - |
|
| 494 | - $post_type = wpinv_admin_post_type(); |
|
| 495 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 496 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
| 497 | - |
|
| 498 | - $jquery_ui_css = false; |
|
| 499 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 500 | - $jquery_ui_css = true; |
|
| 501 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
| 502 | - $jquery_ui_css = true; |
|
| 503 | - } |
|
| 504 | - if ( $jquery_ui_css ) { |
|
| 505 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 506 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
| 507 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
| 508 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 512 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 513 | - |
|
| 514 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
| 515 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version ); |
|
| 516 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 517 | - |
|
| 518 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
| 519 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 520 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 521 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
| 522 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
| 526 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 530 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 531 | - |
|
| 532 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 533 | - |
|
| 534 | - if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 535 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
| 536 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
| 537 | - if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api)) { |
|
| 538 | - wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 539 | - wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true); |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 544 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 545 | - |
|
| 546 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
| 547 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), $version ); |
|
| 548 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 549 | - |
|
| 550 | - $localize = array(); |
|
| 551 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 552 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 553 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 554 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 555 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 556 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 557 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 558 | - $localize['tax'] = wpinv_tax_amount(); |
|
| 559 | - $localize['discount'] = wpinv_discount_amount(); |
|
| 560 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
| 561 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
| 562 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
| 563 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
| 564 | - $localize['decimals'] = wpinv_decimals(); |
|
| 565 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 566 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 567 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
| 568 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 569 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 570 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 571 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 572 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
| 573 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 574 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
| 575 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 576 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
| 577 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
| 578 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
| 579 | - $localize['item_description'] = __( 'Item Description', 'invoicing' ); |
|
| 580 | - $localize['discount_description'] = __( 'Discount Description', 'invoicing' ); |
|
| 581 | - $localize['invoice_description'] = __( 'Invoice Description', 'invoicing' ); |
|
| 582 | - $localize['searching'] = __( 'Searching', 'invoicing' ); |
|
| 583 | - |
|
| 584 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
| 585 | - |
|
| 586 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 587 | - |
|
| 588 | - // Load payment form scripts on our admin pages only. |
|
| 589 | - if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) { |
|
| 590 | - |
|
| 591 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
| 592 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 593 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 594 | - |
|
| 595 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 596 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 597 | - |
|
| 598 | - wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
| 599 | - 'elements' => $this->form_elements->get_elements(), |
|
| 600 | - 'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
| 601 | - 'all_items' => $this->form_elements->get_published_items(), |
|
| 602 | - 'currency' => wpinv_currency_symbol(), |
|
| 603 | - 'position' => wpinv_currency_position(), |
|
| 604 | - 'decimals' => (int) wpinv_decimals(), |
|
| 605 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
| 606 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
| 607 | - 'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
| 608 | - 'is_default' => $post->ID == $this->default_payment_form, |
|
| 609 | - ) ); |
|
| 610 | - |
|
| 611 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 615 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
| 616 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - if ( $page == 'wpinv-reports' ) { |
|
| 620 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - public function admin_body_class( $classes ) { |
|
| 626 | - global $pagenow, $post, $current_screen; |
|
| 627 | - |
|
| 628 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
| 629 | - $classes .= ' wpinv-cpt'; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 633 | - |
|
| 634 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
| 635 | - if ( $add_class ) { |
|
| 636 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - $settings_class = array(); |
|
| 640 | - if ( $page == 'wpinv-settings' ) { |
|
| 641 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 642 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
| 646 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - if ( !empty( $settings_class ) ) { |
|
| 653 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - $post_type = wpinv_admin_post_type(); |
|
| 657 | - |
|
| 658 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 659 | - return $classes .= ' wpinv'; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
| 663 | - $classes .= ' wpi-editable-n'; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $classes; |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - public function admin_print_scripts_edit_php() { |
|
| 670 | - |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - public function wpinv_actions() { |
|
| 674 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 675 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - public function pre_get_posts( $wp_query ) { |
|
| 680 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 681 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - return $wp_query; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - public function bp_invoicing_init() { |
|
| 688 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Register widgets |
|
| 693 | - * |
|
| 694 | - */ |
|
| 695 | - public function register_widgets() { |
|
| 696 | - $widgets = apply_filters( |
|
| 697 | - 'getpaid_widget_classes', |
|
| 698 | - array( |
|
| 699 | - 'WPInv_Checkout_Widget', |
|
| 700 | - 'WPInv_History_Widget', |
|
| 701 | - 'WPInv_Receipt_Widget', |
|
| 702 | - 'WPInv_Subscriptions_Widget', |
|
| 703 | - 'WPInv_Buy_Item_Widget', |
|
| 704 | - 'WPInv_Messages_Widget', |
|
| 705 | - 'WPInv_GetPaid_Widget' |
|
| 706 | - ) |
|
| 707 | - ); |
|
| 708 | - |
|
| 709 | - foreach ( $widgets as $widget ) { |
|
| 710 | - register_widget( $widget ); |
|
| 711 | - } |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Session instance. |
|
| 26 | + * |
|
| 27 | + * @var WPInv_Session_Handler |
|
| 28 | + */ |
|
| 29 | + public $session; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Notes instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Notes |
|
| 35 | + */ |
|
| 36 | + public $notes; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Reports instance. |
|
| 40 | + * |
|
| 41 | + * @var WPInv_Reports |
|
| 42 | + */ |
|
| 43 | + public $reports; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * API instance. |
|
| 47 | + * |
|
| 48 | + * @var WPInv_API |
|
| 49 | + */ |
|
| 50 | + public $api; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Form elements instance. |
|
| 54 | + * |
|
| 55 | + * @var WPInv_Payment_Form_Elements |
|
| 56 | + */ |
|
| 57 | + public $form_elements; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Tax instance. |
|
| 61 | + * |
|
| 62 | + * @var WPInv_EUVat |
|
| 63 | + */ |
|
| 64 | + public $tax; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param array An array of payment gateways. |
|
| 68 | + */ |
|
| 69 | + public $gateways; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Post types instance. |
|
| 73 | + * |
|
| 74 | + * @var GetPaid_Post_Types |
|
| 75 | + */ |
|
| 76 | + public $post_types; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Class constructor. |
|
| 80 | + */ |
|
| 81 | + public function __construct() { |
|
| 82 | + $this->define_constants(); |
|
| 83 | + $this->includes(); |
|
| 84 | + $this->init_hooks(); |
|
| 85 | + $this->set_properties(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Define class properties. |
|
| 90 | + */ |
|
| 91 | + public function set_properties() { |
|
| 92 | + |
|
| 93 | + $this->session = new WPInv_Session_Handler(); |
|
| 94 | + $GLOBALS['wpi_session'] = $this->session; // Backwards compatibility. |
|
| 95 | + $this->notes = new WPInv_Notes(); |
|
| 96 | + $this->reports = new WPInv_Reports(); |
|
| 97 | + $this->api = new WPInv_API(); |
|
| 98 | + $this->form_elements = new WPInv_Payment_Form_Elements(); |
|
| 99 | + $this->tax = new WPInv_EUVat(); |
|
| 100 | + $this->post_types = new GetPaid_Post_Types(); |
|
| 101 | + $this->tax->init(); |
|
| 102 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
| 103 | + |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Define plugin constants. |
|
| 108 | + */ |
|
| 109 | + public function define_constants() { |
|
| 110 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 111 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 112 | + $this->version = WPINV_VERSION; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Hook into actions and filters. |
|
| 117 | + * |
|
| 118 | + * @since 1.0.19 |
|
| 119 | + */ |
|
| 120 | + protected function init_hooks() { |
|
| 121 | + /* Internationalize the text strings used. */ |
|
| 122 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 123 | + |
|
| 124 | + /* Perform actions on admin initialization. */ |
|
| 125 | + add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 126 | + |
|
| 127 | + // Init the plugin after WordPress inits. |
|
| 128 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 129 | + add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
| 130 | + add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 131 | + |
|
| 132 | + if ( class_exists( 'BuddyPress' ) ) { |
|
| 133 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 137 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 138 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 139 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 140 | + |
|
| 141 | + if ( is_admin() ) { |
|
| 142 | + add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 143 | + add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 144 | + add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) ); |
|
| 145 | + |
|
| 146 | + } else { |
|
| 147 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 151 | + |
|
| 152 | + // Fires after registering core hooks. |
|
| 153 | + do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 154 | + |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Maybe show the AyeCode Connect Notice. |
|
| 159 | + */ |
|
| 160 | + public function init_ayecode_connect_helper(){ |
|
| 161 | + // AyeCode Connect notice |
|
| 162 | + if ( is_admin() ){ |
|
| 163 | + // set the strings so they can be translated |
|
| 164 | + $strings = array( |
|
| 165 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 166 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 167 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 168 | + 'connect_button' => __("Connect Site","invoicing"), |
|
| 169 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
| 170 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 171 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 172 | + ); |
|
| 173 | + new AyeCode_Connect_Helper($strings,array('wpi-addons')); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function plugins_loaded() { |
|
| 178 | + /* Internationalize the text strings used. */ |
|
| 179 | + $this->load_textdomain(); |
|
| 180 | + |
|
| 181 | + do_action( 'wpinv_loaded' ); |
|
| 182 | + |
|
| 183 | + // Fix oxygen page builder conflict |
|
| 184 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 185 | + wpinv_oxygen_fix_conflict(); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Load the translation of the plugin. |
|
| 191 | + * |
|
| 192 | + * @since 1.0 |
|
| 193 | + */ |
|
| 194 | + public function load_textdomain( $locale = NULL ) { |
|
| 195 | + if ( empty( $locale ) ) { |
|
| 196 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 200 | + |
|
| 201 | + unload_textdomain( 'invoicing' ); |
|
| 202 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 203 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Define language constants. |
|
| 207 | + */ |
|
| 208 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Include required core files used in admin and on the frontend. |
|
| 213 | + */ |
|
| 214 | + public function includes() { |
|
| 215 | + |
|
| 216 | + // Start with the settings. |
|
| 217 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 218 | + |
|
| 219 | + // Packages/libraries. |
|
| 220 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 221 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 222 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
| 223 | + |
|
| 224 | + // Load functions. |
|
| 225 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 226 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 227 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 228 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 229 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 230 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 231 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 232 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 233 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 234 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 235 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 236 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 237 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 238 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 239 | + |
|
| 240 | + // Register autoloader. |
|
| 241 | + try { |
|
| 242 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 243 | + } catch ( Exception $e ) { |
|
| 244 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 248 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 249 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 250 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 251 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 252 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 253 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 254 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 255 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 256 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 257 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 258 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
| 259 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 260 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 261 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 262 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 263 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 264 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 265 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 266 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 267 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 268 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 269 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 270 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Load the tax class. |
|
| 274 | + */ |
|
| 275 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
| 276 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 280 | + if ( !empty( $gateways ) ) { |
|
| 281 | + foreach ( $gateways as $gateway ) { |
|
| 282 | + if ( $gateway == 'manual' ) { |
|
| 283 | + continue; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
| 287 | + |
|
| 288 | + if ( file_exists( $gateway_file ) ) { |
|
| 289 | + require_once( $gateway_file ); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 295 | + GetPaid_Post_Types_Admin::init(); |
|
| 296 | + |
|
| 297 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 298 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 299 | + //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
| 300 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 301 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 302 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 303 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 304 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 305 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 306 | + //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 307 | + // load the user class only on the users.php page |
|
| 308 | + global $pagenow; |
|
| 309 | + if($pagenow=='users.php'){ |
|
| 310 | + new WPInv_Admin_Users(); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // Register cli commands |
|
| 315 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 316 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 317 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + // include css inliner |
|
| 321 | + if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 322 | + include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Class autoloader |
|
| 330 | + * |
|
| 331 | + * @param string $class_name The name of the class to load. |
|
| 332 | + * @access public |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @return void |
|
| 335 | + */ |
|
| 336 | + public function autoload( $class_name ) { |
|
| 337 | + |
|
| 338 | + // Normalize the class name... |
|
| 339 | + $class_name = strtolower( $class_name ); |
|
| 340 | + |
|
| 341 | + // ... and make sure it is our class. |
|
| 342 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 343 | + return; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Next, prepare the file name from the class. |
|
| 347 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 348 | + |
|
| 349 | + // Base path of the classes. |
|
| 350 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 351 | + |
|
| 352 | + // And an array of possible locations in order of importance. |
|
| 353 | + $locations = array( |
|
| 354 | + "$plugin_path/includes", |
|
| 355 | + "$plugin_path/includes/data-stores", |
|
| 356 | + "$plugin_path/includes/gateways", |
|
| 357 | + "$plugin_path/includes/api", |
|
| 358 | + "$plugin_path/includes/admin", |
|
| 359 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 360 | + ); |
|
| 361 | + |
|
| 362 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 363 | + |
|
| 364 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 365 | + include trailingslashit( $location ) . $file_name; |
|
| 366 | + break; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Inits hooks etc. |
|
| 375 | + */ |
|
| 376 | + public function init() { |
|
| 377 | + |
|
| 378 | + // Fires before getpaid inits. |
|
| 379 | + do_action( 'before_getpaid_init', $this ); |
|
| 380 | + |
|
| 381 | + // Load default gateways. |
|
| 382 | + $gateways = apply_filters( |
|
| 383 | + 'getpaid_default_gateways', |
|
| 384 | + array( |
|
| 385 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 386 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 387 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 388 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 389 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 390 | + ) |
|
| 391 | + ); |
|
| 392 | + |
|
| 393 | + foreach ( $gateways as $id => $class ) { |
|
| 394 | + $this->gateways[ $id ] = new $class(); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + // Fires after getpaid inits. |
|
| 398 | + do_action( 'getpaid_init', $this ); |
|
| 399 | + |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Checks if this is an IPN request and processes it. |
|
| 404 | + */ |
|
| 405 | + public function maybe_process_ipn() { |
|
| 406 | + |
|
| 407 | + // Ensure that this is an IPN request. |
|
| 408 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 409 | + return; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 413 | + |
|
| 414 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 415 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 416 | + exit; |
|
| 417 | + |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + public function admin_init() { |
|
| 421 | + $this->default_payment_form = wpinv_get_default_payment_form(); |
|
| 422 | + add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + public function activation_redirect() { |
|
| 426 | + // Bail if no activation redirect |
|
| 427 | + if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 428 | + return; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + // Delete the redirect transient |
|
| 432 | + delete_transient( '_wpinv_activation_redirect' ); |
|
| 433 | + |
|
| 434 | + // Bail if activating from network, or bulk |
|
| 435 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 436 | + return; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 440 | + exit; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + public function enqueue_scripts() { |
|
| 444 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 445 | + |
|
| 446 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 447 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 448 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
| 449 | + |
|
| 450 | + // Register scripts |
|
| 451 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 452 | + 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' ) ); |
|
| 453 | + |
|
| 454 | + $localize = array(); |
|
| 455 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 456 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 457 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
| 458 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
| 459 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
| 460 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
| 461 | + $localize['decimals'] = wpinv_decimals(); |
|
| 462 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 463 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 464 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 465 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 466 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 467 | + |
|
| 468 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 469 | + |
|
| 470 | + wp_enqueue_script( 'jquery-blockui' ); |
|
| 471 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
| 472 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
| 473 | + if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 474 | + if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 475 | + wp_dequeue_script( 'google-maps-api' ); |
|
| 476 | + } |
|
| 477 | + wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 478 | + wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 482 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 483 | + |
|
| 484 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
| 485 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 486 | + |
|
| 487 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 488 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + public function admin_enqueue_scripts( $hook ) { |
|
| 492 | + global $post, $pagenow; |
|
| 493 | + |
|
| 494 | + $post_type = wpinv_admin_post_type(); |
|
| 495 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 496 | + $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
| 497 | + |
|
| 498 | + $jquery_ui_css = false; |
|
| 499 | + if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 500 | + $jquery_ui_css = true; |
|
| 501 | + } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
| 502 | + $jquery_ui_css = true; |
|
| 503 | + } |
|
| 504 | + if ( $jquery_ui_css ) { |
|
| 505 | + wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 506 | + wp_enqueue_style( 'jquery-ui-css' ); |
|
| 507 | + wp_deregister_style( 'yoast-seo-select2' ); |
|
| 508 | + wp_deregister_style( 'yoast-seo-monorepo' ); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 512 | + wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 513 | + |
|
| 514 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
| 515 | + wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version ); |
|
| 516 | + wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 517 | + |
|
| 518 | + $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
| 519 | + if ( $page == 'wpinv-subscriptions' ) { |
|
| 520 | + wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 521 | + wp_deregister_style( 'yoast-seo-select2' ); |
|
| 522 | + wp_deregister_style( 'yoast-seo-monorepo' ); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
| 526 | + wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + wp_enqueue_style( 'wp-color-picker' ); |
|
| 530 | + wp_enqueue_script( 'wp-color-picker' ); |
|
| 531 | + |
|
| 532 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 533 | + |
|
| 534 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 535 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
| 536 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
| 537 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api)) { |
|
| 538 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 539 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 544 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 545 | + |
|
| 546 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
| 547 | + wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), $version ); |
|
| 548 | + wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 549 | + |
|
| 550 | + $localize = array(); |
|
| 551 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 552 | + $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 553 | + $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 554 | + $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 555 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 556 | + $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 557 | + $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 558 | + $localize['tax'] = wpinv_tax_amount(); |
|
| 559 | + $localize['discount'] = wpinv_discount_amount(); |
|
| 560 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
| 561 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
| 562 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
| 563 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
| 564 | + $localize['decimals'] = wpinv_decimals(); |
|
| 565 | + $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 566 | + $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 567 | + $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
| 568 | + $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 569 | + $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 570 | + $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 571 | + $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 572 | + $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
| 573 | + $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 574 | + $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
| 575 | + $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 576 | + $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
| 577 | + $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
| 578 | + $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
| 579 | + $localize['item_description'] = __( 'Item Description', 'invoicing' ); |
|
| 580 | + $localize['discount_description'] = __( 'Discount Description', 'invoicing' ); |
|
| 581 | + $localize['invoice_description'] = __( 'Invoice Description', 'invoicing' ); |
|
| 582 | + $localize['searching'] = __( 'Searching', 'invoicing' ); |
|
| 583 | + |
|
| 584 | + $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
| 585 | + |
|
| 586 | + wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 587 | + |
|
| 588 | + // Load payment form scripts on our admin pages only. |
|
| 589 | + if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) { |
|
| 590 | + |
|
| 591 | + wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
| 592 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 593 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 594 | + |
|
| 595 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 596 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 597 | + |
|
| 598 | + wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
| 599 | + 'elements' => $this->form_elements->get_elements(), |
|
| 600 | + 'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
| 601 | + 'all_items' => $this->form_elements->get_published_items(), |
|
| 602 | + 'currency' => wpinv_currency_symbol(), |
|
| 603 | + 'position' => wpinv_currency_position(), |
|
| 604 | + 'decimals' => (int) wpinv_decimals(), |
|
| 605 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
| 606 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
| 607 | + 'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
| 608 | + 'is_default' => $post->ID == $this->default_payment_form, |
|
| 609 | + ) ); |
|
| 610 | + |
|
| 611 | + wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + if ( $page == 'wpinv-subscriptions' ) { |
|
| 615 | + wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
| 616 | + wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + if ( $page == 'wpinv-reports' ) { |
|
| 620 | + wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + public function admin_body_class( $classes ) { |
|
| 626 | + global $pagenow, $post, $current_screen; |
|
| 627 | + |
|
| 628 | + if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
| 629 | + $classes .= ' wpinv-cpt'; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 633 | + |
|
| 634 | + $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
| 635 | + if ( $add_class ) { |
|
| 636 | + $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + $settings_class = array(); |
|
| 640 | + if ( $page == 'wpinv-settings' ) { |
|
| 641 | + if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 642 | + $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + if ( !empty( $_REQUEST['section'] ) ) { |
|
| 646 | + $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + if ( !empty( $settings_class ) ) { |
|
| 653 | + $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + $post_type = wpinv_admin_post_type(); |
|
| 657 | + |
|
| 658 | + if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 659 | + return $classes .= ' wpinv'; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
| 663 | + $classes .= ' wpi-editable-n'; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return $classes; |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + public function admin_print_scripts_edit_php() { |
|
| 670 | + |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + public function wpinv_actions() { |
|
| 674 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 675 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + public function pre_get_posts( $wp_query ) { |
|
| 680 | + if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 681 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + return $wp_query; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + public function bp_invoicing_init() { |
|
| 688 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Register widgets |
|
| 693 | + * |
|
| 694 | + */ |
|
| 695 | + public function register_widgets() { |
|
| 696 | + $widgets = apply_filters( |
|
| 697 | + 'getpaid_widget_classes', |
|
| 698 | + array( |
|
| 699 | + 'WPInv_Checkout_Widget', |
|
| 700 | + 'WPInv_History_Widget', |
|
| 701 | + 'WPInv_Receipt_Widget', |
|
| 702 | + 'WPInv_Subscriptions_Widget', |
|
| 703 | + 'WPInv_Buy_Item_Widget', |
|
| 704 | + 'WPInv_Messages_Widget', |
|
| 705 | + 'WPInv_GetPaid_Widget' |
|
| 706 | + ) |
|
| 707 | + ); |
|
| 708 | + |
|
| 709 | + foreach ( $widgets as $widget ) { |
|
| 710 | + register_widget( $widget ); |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - } |
|
| 713 | + } |
|
| 714 | 714 | |
| 715 | - /** |
|
| 716 | - * Remove our pages from yoast sitemaps. |
|
| 717 | - * |
|
| 718 | - * @since 1.0.19 |
|
| 719 | - * @param int[] $excluded_posts_ids |
|
| 720 | - */ |
|
| 721 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 715 | + /** |
|
| 716 | + * Remove our pages from yoast sitemaps. |
|
| 717 | + * |
|
| 718 | + * @since 1.0.19 |
|
| 719 | + * @param int[] $excluded_posts_ids |
|
| 720 | + */ |
|
| 721 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 722 | 722 | |
| 723 | - // Ensure that we have an array. |
|
| 724 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 725 | - $excluded_posts_ids = array(); |
|
| 726 | - } |
|
| 723 | + // Ensure that we have an array. |
|
| 724 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 725 | + $excluded_posts_ids = array(); |
|
| 726 | + } |
|
| 727 | 727 | |
| 728 | - // Prepare our pages. |
|
| 729 | - $our_pages = array(); |
|
| 728 | + // Prepare our pages. |
|
| 729 | + $our_pages = array(); |
|
| 730 | 730 | |
| 731 | - // Checkout page. |
|
| 732 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 731 | + // Checkout page. |
|
| 732 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 733 | 733 | |
| 734 | - // Success page. |
|
| 735 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 734 | + // Success page. |
|
| 735 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 736 | 736 | |
| 737 | - // Failure page. |
|
| 738 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 737 | + // Failure page. |
|
| 738 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 739 | 739 | |
| 740 | - // History page. |
|
| 741 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 740 | + // History page. |
|
| 741 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 742 | 742 | |
| 743 | - // Subscriptions page. |
|
| 744 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 743 | + // Subscriptions page. |
|
| 744 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 745 | 745 | |
| 746 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 746 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 747 | 747 | |
| 748 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 749 | - return array_unique( $excluded_posts_ids ); |
|
| 748 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 749 | + return array_unique( $excluded_posts_ids ); |
|
| 750 | 750 | |
| 751 | - } |
|
| 751 | + } |
|
| 752 | 752 | |
| 753 | - public function wp_footer() { |
|
| 754 | - echo ' |
|
| 753 | + public function wp_footer() { |
|
| 754 | + echo ' |
|
| 755 | 755 | <div class="bsui"> |
| 756 | 756 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
| 757 | 757 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -762,6 +762,6 @@ discard block |
||
| 762 | 762 | </div> |
| 763 | 763 | </div> |
| 764 | 764 | '; |
| 765 | - } |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | 767 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 1.0.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Main Invoicing class. |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | * Define plugin constants. |
| 108 | 108 | */ |
| 109 | 109 | public function define_constants() { |
| 110 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 111 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 110 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 111 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 112 | 112 | $this->version = WPINV_VERSION; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -119,58 +119,58 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | protected function init_hooks() { |
| 121 | 121 | /* Internationalize the text strings used. */ |
| 122 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 122 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 123 | 123 | |
| 124 | 124 | /* Perform actions on admin initialization. */ |
| 125 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 125 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
| 126 | 126 | |
| 127 | 127 | // Init the plugin after WordPress inits. |
| 128 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 129 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
| 130 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 128 | + add_action('init', array($this, 'init'), 1); |
|
| 129 | + add_action('getpaid_init', array($this, 'maybe_process_ipn'), 5); |
|
| 130 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
| 131 | 131 | |
| 132 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 133 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 132 | + if (class_exists('BuddyPress')) { |
|
| 133 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 137 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 138 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 139 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 136 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 137 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
| 138 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
| 139 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
| 140 | 140 | |
| 141 | - if ( is_admin() ) { |
|
| 142 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 143 | - add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 144 | - add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) ); |
|
| 141 | + if (is_admin()) { |
|
| 142 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
| 143 | + add_filter('admin_body_class', array(&$this, 'admin_body_class')); |
|
| 144 | + add_action('admin_init', array(&$this, 'init_ayecode_connect_helper')); |
|
| 145 | 145 | |
| 146 | 146 | } else { |
| 147 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 147 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 150 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
| 151 | 151 | |
| 152 | 152 | // Fires after registering core hooks. |
| 153 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 153 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
| 154 | 154 | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | 158 | * Maybe show the AyeCode Connect Notice. |
| 159 | 159 | */ |
| 160 | - public function init_ayecode_connect_helper(){ |
|
| 160 | + public function init_ayecode_connect_helper() { |
|
| 161 | 161 | // AyeCode Connect notice |
| 162 | - if ( is_admin() ){ |
|
| 162 | + if (is_admin()) { |
|
| 163 | 163 | // set the strings so they can be translated |
| 164 | 164 | $strings = array( |
| 165 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 166 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 167 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 168 | - 'connect_button' => __("Connect Site","invoicing"), |
|
| 169 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
| 170 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 171 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 165 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
| 166 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
| 167 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
| 168 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
| 169 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
| 170 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
| 171 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
| 172 | 172 | ); |
| 173 | - new AyeCode_Connect_Helper($strings,array('wpi-addons')); |
|
| 173 | + new AyeCode_Connect_Helper($strings, array('wpi-addons')); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | /* Internationalize the text strings used. */ |
| 179 | 179 | $this->load_textdomain(); |
| 180 | 180 | |
| 181 | - do_action( 'wpinv_loaded' ); |
|
| 181 | + do_action('wpinv_loaded'); |
|
| 182 | 182 | |
| 183 | 183 | // Fix oxygen page builder conflict |
| 184 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 184 | + if (function_exists('ct_css_output')) { |
|
| 185 | 185 | wpinv_oxygen_fix_conflict(); |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -191,21 +191,21 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @since 1.0 |
| 193 | 193 | */ |
| 194 | - public function load_textdomain( $locale = NULL ) { |
|
| 195 | - if ( empty( $locale ) ) { |
|
| 196 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 194 | + public function load_textdomain($locale = NULL) { |
|
| 195 | + if (empty($locale)) { |
|
| 196 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 199 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
| 200 | 200 | |
| 201 | - unload_textdomain( 'invoicing' ); |
|
| 202 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 203 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 201 | + unload_textdomain('invoicing'); |
|
| 202 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 203 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | 206 | * Define language constants. |
| 207 | 207 | */ |
| 208 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 208 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -214,115 +214,115 @@ discard block |
||
| 214 | 214 | public function includes() { |
| 215 | 215 | |
| 216 | 216 | // Start with the settings. |
| 217 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 217 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 218 | 218 | |
| 219 | 219 | // Packages/libraries. |
| 220 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 221 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 222 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
| 220 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
| 221 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
| 222 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php'); |
|
| 223 | 223 | |
| 224 | 224 | // Load functions. |
| 225 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 226 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 227 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 228 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 229 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 230 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 231 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 232 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 233 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 234 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 235 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 236 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 237 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 238 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 225 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
| 226 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 227 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 228 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 229 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 230 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 231 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 232 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
| 233 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 234 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 235 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 236 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 237 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 238 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
| 239 | 239 | |
| 240 | 240 | // Register autoloader. |
| 241 | 241 | try { |
| 242 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 243 | - } catch ( Exception $e ) { |
|
| 244 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 248 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 249 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 250 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 251 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 252 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 253 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 254 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 255 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 256 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 257 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
| 259 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 260 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 261 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 262 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 263 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 264 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 265 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 266 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 267 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 268 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 269 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 270 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
| 242 | + spl_autoload_register(array($this, 'autoload'), true); |
|
| 243 | + } catch (Exception $e) { |
|
| 244 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
| 248 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
| 249 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 250 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 251 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 252 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
| 253 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
| 254 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
| 255 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
| 256 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
| 257 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
| 258 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
| 259 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
| 260 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
| 261 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
| 262 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
| 263 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
| 264 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
| 265 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
| 266 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
| 267 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
| 268 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
| 269 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
| 270 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php'); |
|
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | 273 | * Load the tax class. |
| 274 | 274 | */ |
| 275 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
| 276 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 275 | + if (!class_exists('WPInv_EUVat')) { |
|
| 276 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 280 | - if ( !empty( $gateways ) ) { |
|
| 281 | - foreach ( $gateways as $gateway ) { |
|
| 282 | - if ( $gateway == 'manual' ) { |
|
| 279 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 280 | + if (!empty($gateways)) { |
|
| 281 | + foreach ($gateways as $gateway) { |
|
| 282 | + if ($gateway == 'manual') { |
|
| 283 | 283 | continue; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
| 287 | 287 | |
| 288 | - if ( file_exists( $gateway_file ) ) { |
|
| 289 | - require_once( $gateway_file ); |
|
| 288 | + if (file_exists($gateway_file)) { |
|
| 289 | + require_once($gateway_file); |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 294 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 295 | 295 | GetPaid_Post_Types_Admin::init(); |
| 296 | 296 | |
| 297 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 298 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 297 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 298 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 299 | 299 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
| 300 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 301 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 302 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 303 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 304 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 305 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 300 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
| 301 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 302 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 303 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
| 304 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
| 305 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
| 306 | 306 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
| 307 | 307 | // load the user class only on the users.php page |
| 308 | 308 | global $pagenow; |
| 309 | - if($pagenow=='users.php'){ |
|
| 309 | + if ($pagenow == 'users.php') { |
|
| 310 | 310 | new WPInv_Admin_Users(); |
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | // Register cli commands |
| 315 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 316 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 317 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 315 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 316 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
| 317 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // include css inliner |
| 321 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 322 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 321 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
| 322 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 325 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -333,21 +333,21 @@ discard block |
||
| 333 | 333 | * @since 1.0.19 |
| 334 | 334 | * @return void |
| 335 | 335 | */ |
| 336 | - public function autoload( $class_name ) { |
|
| 336 | + public function autoload($class_name) { |
|
| 337 | 337 | |
| 338 | 338 | // Normalize the class name... |
| 339 | - $class_name = strtolower( $class_name ); |
|
| 339 | + $class_name = strtolower($class_name); |
|
| 340 | 340 | |
| 341 | 341 | // ... and make sure it is our class. |
| 342 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 342 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
| 343 | 343 | return; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // Next, prepare the file name from the class. |
| 347 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 347 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
| 348 | 348 | |
| 349 | 349 | // Base path of the classes. |
| 350 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 350 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
| 351 | 351 | |
| 352 | 352 | // And an array of possible locations in order of importance. |
| 353 | 353 | $locations = array( |
@@ -359,10 +359,10 @@ discard block |
||
| 359 | 359 | "$plugin_path/includes/admin/meta-boxes", |
| 360 | 360 | ); |
| 361 | 361 | |
| 362 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 362 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
| 363 | 363 | |
| 364 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 365 | - include trailingslashit( $location ) . $file_name; |
|
| 364 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
| 365 | + include trailingslashit($location) . $file_name; |
|
| 366 | 366 | break; |
| 367 | 367 | } |
| 368 | 368 | |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | public function init() { |
| 377 | 377 | |
| 378 | 378 | // Fires before getpaid inits. |
| 379 | - do_action( 'before_getpaid_init', $this ); |
|
| 379 | + do_action('before_getpaid_init', $this); |
|
| 380 | 380 | |
| 381 | 381 | // Load default gateways. |
| 382 | 382 | $gateways = apply_filters( |
@@ -390,12 +390,12 @@ discard block |
||
| 390 | 390 | ) |
| 391 | 391 | ); |
| 392 | 392 | |
| 393 | - foreach ( $gateways as $id => $class ) { |
|
| 394 | - $this->gateways[ $id ] = new $class(); |
|
| 393 | + foreach ($gateways as $id => $class) { |
|
| 394 | + $this->gateways[$id] = new $class(); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // Fires after getpaid inits. |
| 398 | - do_action( 'getpaid_init', $this ); |
|
| 398 | + do_action('getpaid_init', $this); |
|
| 399 | 399 | |
| 400 | 400 | } |
| 401 | 401 | |
@@ -405,131 +405,131 @@ discard block |
||
| 405 | 405 | public function maybe_process_ipn() { |
| 406 | 406 | |
| 407 | 407 | // Ensure that this is an IPN request. |
| 408 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 408 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
| 409 | 409 | return; |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 412 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
| 413 | 413 | |
| 414 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 415 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 414 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
| 415 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
| 416 | 416 | exit; |
| 417 | 417 | |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | public function admin_init() { |
| 421 | 421 | $this->default_payment_form = wpinv_get_default_payment_form(); |
| 422 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 422 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | public function activation_redirect() { |
| 426 | 426 | // Bail if no activation redirect |
| 427 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 427 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
| 428 | 428 | return; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | // Delete the redirect transient |
| 432 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 432 | + delete_transient('_wpinv_activation_redirect'); |
|
| 433 | 433 | |
| 434 | 434 | // Bail if activating from network, or bulk |
| 435 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 435 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 436 | 436 | return; |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 439 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
| 440 | 440 | exit; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | public function enqueue_scripts() { |
| 444 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 444 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 445 | 445 | |
| 446 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 447 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 448 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 446 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
| 447 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
| 448 | + wp_enqueue_style('wpinv_front_style'); |
|
| 449 | 449 | |
| 450 | 450 | // Register scripts |
| 451 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 452 | - 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' ) ); |
|
| 451 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 452 | + 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')); |
|
| 453 | 453 | |
| 454 | 454 | $localize = array(); |
| 455 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 456 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 455 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 456 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 457 | 457 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 458 | 458 | $localize['currency_pos'] = wpinv_currency_position(); |
| 459 | 459 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 460 | 460 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 461 | 461 | $localize['decimals'] = wpinv_decimals(); |
| 462 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 462 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
| 463 | 463 | $localize['UseTaxes'] = wpinv_use_taxes(); |
| 464 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 465 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 466 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 464 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
| 465 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
| 466 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
| 467 | 467 | |
| 468 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 468 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 469 | 469 | |
| 470 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 470 | + wp_enqueue_script('jquery-blockui'); |
|
| 471 | 471 | $autofill_api = wpinv_get_option('address_autofill_api'); |
| 472 | 472 | $autofill_active = wpinv_get_option('address_autofill_active'); |
| 473 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 474 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 475 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 473 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
| 474 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
| 475 | + wp_dequeue_script('google-maps-api'); |
|
| 476 | 476 | } |
| 477 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 478 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 477 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 478 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 482 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 481 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
| 482 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 483 | 483 | |
| 484 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 485 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 484 | + wp_enqueue_script('wpinv-front-script'); |
|
| 485 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 486 | 486 | |
| 487 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 488 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
| 487 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
| 488 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | - public function admin_enqueue_scripts( $hook ) { |
|
| 491 | + public function admin_enqueue_scripts($hook) { |
|
| 492 | 492 | global $post, $pagenow; |
| 493 | 493 | |
| 494 | 494 | $post_type = wpinv_admin_post_type(); |
| 495 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 496 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
| 495 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 496 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
| 497 | 497 | |
| 498 | 498 | $jquery_ui_css = false; |
| 499 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 499 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 500 | 500 | $jquery_ui_css = true; |
| 501 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
| 501 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
| 502 | 502 | $jquery_ui_css = true; |
| 503 | 503 | } |
| 504 | - if ( $jquery_ui_css ) { |
|
| 505 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 506 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
| 507 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
| 508 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
| 504 | + if ($jquery_ui_css) { |
|
| 505 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
| 506 | + wp_enqueue_style('jquery-ui-css'); |
|
| 507 | + wp_deregister_style('yoast-seo-select2'); |
|
| 508 | + wp_deregister_style('yoast-seo-monorepo'); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 512 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 511 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
| 512 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
| 513 | 513 | |
| 514 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
| 515 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version ); |
|
| 516 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 514 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
| 515 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version); |
|
| 516 | + wp_enqueue_style('wpinv_admin_style'); |
|
| 517 | 517 | |
| 518 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
| 519 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 520 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 521 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
| 522 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
| 518 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
| 519 | + if ($page == 'wpinv-subscriptions') { |
|
| 520 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 521 | + wp_deregister_style('yoast-seo-select2'); |
|
| 522 | + wp_deregister_style('yoast-seo-monorepo'); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
| 526 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 525 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
| 526 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 530 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 529 | + wp_enqueue_style('wp-color-picker'); |
|
| 530 | + wp_enqueue_script('wp-color-picker'); |
|
| 531 | 531 | |
| 532 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 532 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 533 | 533 | |
| 534 | 534 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
| 535 | 535 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -540,21 +540,21 @@ discard block |
||
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 544 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 543 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
| 544 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 545 | 545 | |
| 546 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
| 547 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), $version ); |
|
| 548 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 546 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
| 547 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version); |
|
| 548 | + wp_enqueue_script('wpinv-admin-script'); |
|
| 549 | 549 | |
| 550 | 550 | $localize = array(); |
| 551 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 552 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 553 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 554 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 555 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 556 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 557 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 551 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 552 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
| 553 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 554 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
| 555 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
| 556 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
| 557 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
| 558 | 558 | $localize['tax'] = wpinv_tax_amount(); |
| 559 | 559 | $localize['discount'] = wpinv_discount_amount(); |
| 560 | 560 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -562,104 +562,104 @@ discard block |
||
| 562 | 562 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 563 | 563 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 564 | 564 | $localize['decimals'] = wpinv_decimals(); |
| 565 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 566 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 567 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
| 568 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 569 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 570 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 571 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 572 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
| 573 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 574 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
| 575 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 576 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
| 577 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
| 578 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
| 579 | - $localize['item_description'] = __( 'Item Description', 'invoicing' ); |
|
| 580 | - $localize['discount_description'] = __( 'Discount Description', 'invoicing' ); |
|
| 581 | - $localize['invoice_description'] = __( 'Invoice Description', 'invoicing' ); |
|
| 582 | - $localize['searching'] = __( 'Searching', 'invoicing' ); |
|
| 583 | - |
|
| 584 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
| 585 | - |
|
| 586 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 565 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
| 566 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
| 567 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
| 568 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
| 569 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
| 570 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
| 571 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
| 572 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
| 573 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
| 574 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
| 575 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
| 576 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
| 577 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
| 578 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
| 579 | + $localize['item_description'] = __('Item Description', 'invoicing'); |
|
| 580 | + $localize['discount_description'] = __('Discount Description', 'invoicing'); |
|
| 581 | + $localize['invoice_description'] = __('Invoice Description', 'invoicing'); |
|
| 582 | + $localize['searching'] = __('Searching', 'invoicing'); |
|
| 583 | + |
|
| 584 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
| 585 | + |
|
| 586 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
| 587 | 587 | |
| 588 | 588 | // Load payment form scripts on our admin pages only. |
| 589 | - if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) { |
|
| 589 | + if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) { |
|
| 590 | 590 | |
| 591 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
| 592 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 593 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 591 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
| 592 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
| 593 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
| 594 | 594 | |
| 595 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 596 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 595 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
| 596 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
| 597 | 597 | |
| 598 | - wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
| 598 | + wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
| 599 | 599 | 'elements' => $this->form_elements->get_elements(), |
| 600 | - 'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
| 600 | + 'form_elements' => $this->form_elements->get_form_elements($post->ID), |
|
| 601 | 601 | 'all_items' => $this->form_elements->get_published_items(), |
| 602 | 602 | 'currency' => wpinv_currency_symbol(), |
| 603 | 603 | 'position' => wpinv_currency_position(), |
| 604 | 604 | 'decimals' => (int) wpinv_decimals(), |
| 605 | 605 | 'thousands_sep' => wpinv_thousands_separator(), |
| 606 | 606 | 'decimals_sep' => wpinv_decimal_separator(), |
| 607 | - 'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
| 607 | + 'form_items' => $this->form_elements->get_form_items($post->ID), |
|
| 608 | 608 | 'is_default' => $post->ID == $this->default_payment_form, |
| 609 | - ) ); |
|
| 609 | + )); |
|
| 610 | 610 | |
| 611 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
| 611 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 615 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
| 616 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
| 614 | + if ($page == 'wpinv-subscriptions') { |
|
| 615 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
| 616 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | - if ( $page == 'wpinv-reports' ) { |
|
| 620 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
| 619 | + if ($page == 'wpinv-reports') { |
|
| 620 | + wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7'); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - public function admin_body_class( $classes ) { |
|
| 625 | + public function admin_body_class($classes) { |
|
| 626 | 626 | global $pagenow, $post, $current_screen; |
| 627 | 627 | |
| 628 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
| 628 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) { |
|
| 629 | 629 | $classes .= ' wpinv-cpt'; |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 632 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
| 633 | 633 | |
| 634 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
| 635 | - if ( $add_class ) { |
|
| 636 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
| 634 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
| 635 | + if ($add_class) { |
|
| 636 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | $settings_class = array(); |
| 640 | - if ( $page == 'wpinv-settings' ) { |
|
| 641 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 642 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 640 | + if ($page == 'wpinv-settings') { |
|
| 641 | + if (!empty($_REQUEST['tab'])) { |
|
| 642 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
| 646 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 645 | + if (!empty($_REQUEST['section'])) { |
|
| 646 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 649 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - if ( !empty( $settings_class ) ) { |
|
| 653 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 652 | + if (!empty($settings_class)) { |
|
| 653 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | $post_type = wpinv_admin_post_type(); |
| 657 | 657 | |
| 658 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 658 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
| 659 | 659 | return $classes .= ' wpinv'; |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
| 662 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
| 663 | 663 | $classes .= ' wpi-editable-n'; |
| 664 | 664 | } |
| 665 | 665 | |
@@ -671,21 +671,21 @@ discard block |
||
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | public function wpinv_actions() { |
| 674 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 675 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 674 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 675 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 676 | 676 | } |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - public function pre_get_posts( $wp_query ) { |
|
| 680 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 681 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 679 | + public function pre_get_posts($wp_query) { |
|
| 680 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 681 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | return $wp_query; |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | public function bp_invoicing_init() { |
| 688 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 688 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -706,8 +706,8 @@ discard block |
||
| 706 | 706 | ) |
| 707 | 707 | ); |
| 708 | 708 | |
| 709 | - foreach ( $widgets as $widget ) { |
|
| 710 | - register_widget( $widget ); |
|
| 709 | + foreach ($widgets as $widget) { |
|
| 710 | + register_widget($widget); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | } |
@@ -718,10 +718,10 @@ discard block |
||
| 718 | 718 | * @since 1.0.19 |
| 719 | 719 | * @param int[] $excluded_posts_ids |
| 720 | 720 | */ |
| 721 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 721 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
| 722 | 722 | |
| 723 | 723 | // Ensure that we have an array. |
| 724 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 724 | + if (!is_array($excluded_posts_ids)) { |
|
| 725 | 725 | $excluded_posts_ids = array(); |
| 726 | 726 | } |
| 727 | 727 | |
@@ -729,24 +729,24 @@ discard block |
||
| 729 | 729 | $our_pages = array(); |
| 730 | 730 | |
| 731 | 731 | // Checkout page. |
| 732 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 732 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
| 733 | 733 | |
| 734 | 734 | // Success page. |
| 735 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 735 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
| 736 | 736 | |
| 737 | 737 | // Failure page. |
| 738 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 738 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
| 739 | 739 | |
| 740 | 740 | // History page. |
| 741 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 741 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
| 742 | 742 | |
| 743 | 743 | // Subscriptions page. |
| 744 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 744 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
| 745 | 745 | |
| 746 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 746 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
| 747 | 747 | |
| 748 | 748 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
| 749 | - return array_unique( $excluded_posts_ids ); |
|
| 749 | + return array_unique($excluded_posts_ids); |
|
| 750 | 750 | |
| 751 | 751 | } |
| 752 | 752 | |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Returns the errors as html |
@@ -14,27 +14,27 @@ discard block |
||
| 14 | 14 | * @param clear whether or not to clear the errors. |
| 15 | 15 | * @since 1.0.19 |
| 16 | 16 | */ |
| 17 | -function getpaid_get_errors_html( $clear = true ) { |
|
| 17 | +function getpaid_get_errors_html($clear = true) { |
|
| 18 | 18 | |
| 19 | 19 | $errors = ''; |
| 20 | - foreach ( wpinv_get_errors() as $error_id => $error ) { |
|
| 21 | - $type = 'error'; |
|
| 20 | + foreach (wpinv_get_errors() as $error_id => $error) { |
|
| 21 | + $type = 'error'; |
|
| 22 | 22 | |
| 23 | - if ( is_array( $error ) ) { |
|
| 23 | + if (is_array($error)) { |
|
| 24 | 24 | $type = $error['type']; |
| 25 | 25 | $error = $error['text']; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | $errors .= aui()->alert( |
| 29 | 29 | array( |
| 30 | - 'content' => wp_kses_post( $error ), |
|
| 30 | + 'content' => wp_kses_post($error), |
|
| 31 | 31 | 'type' => $type, |
| 32 | 32 | ) |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if ( $clear ){ |
|
| 37 | + if ($clear) { |
|
| 38 | 38 | wpinv_clear_errors(); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | 57 | function wpinv_get_errors() { |
| 58 | - $errors = getpaid()->session->get( 'wpinv_errors' ); |
|
| 59 | - return is_array( $errors ) ? $errors : array(); |
|
| 58 | + $errors = getpaid()->session->get('wpinv_errors'); |
|
| 59 | + return is_array($errors) ? $errors : array(); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | * @param string $error_message The error message. |
| 67 | 67 | * @param string $type Either error, info, warning, primary, dark, light or success. |
| 68 | 68 | */ |
| 69 | -function wpinv_set_error( $error_id, $error_message, $type = 'error' ) { |
|
| 69 | +function wpinv_set_error($error_id, $error_message, $type = 'error') { |
|
| 70 | 70 | |
| 71 | 71 | $errors = wpinv_get_errors(); |
| 72 | - $errors[ $error_id ] = array( |
|
| 72 | + $errors[$error_id] = array( |
|
| 73 | 73 | 'type' => $type, |
| 74 | 74 | 'text' => $error_message, |
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | - getpaid()->session->set( 'wpinv_errors', $errors ); |
|
| 77 | + getpaid()->session->set('wpinv_errors', $errors); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | */ |
| 84 | 84 | function wpinv_has_errors() { |
| 85 | - return count( wpinv_get_errors() ) > 0; |
|
| 85 | + return count(wpinv_get_errors()) > 0; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | */ |
| 92 | 92 | function wpinv_clear_errors() { |
| 93 | - getpaid()->session->set( 'wpinv_errors', null ); |
|
| 93 | + getpaid()->session->set('wpinv_errors', null); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * Clears a single error. |
| 98 | 98 | * |
| 99 | 99 | */ |
| 100 | -function wpinv_unset_error( $error_id ) { |
|
| 100 | +function wpinv_unset_error($error_id) { |
|
| 101 | 101 | $errors = wpinv_get_errors(); |
| 102 | 102 | |
| 103 | - if ( isset( $errors[ $error_id ] ) ) { |
|
| 104 | - unset( $errors[ $error_id ] ); |
|
| 103 | + if (isset($errors[$error_id])) { |
|
| 104 | + unset($errors[$error_id]); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - getpaid()->session->set( 'wpinv_errors', $errors ); |
|
| 107 | + getpaid()->session->set('wpinv_errors', $errors); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -115,15 +115,15 @@ discard block |
||
| 115 | 115 | * @param string $message Message to log. |
| 116 | 116 | * @param string $version Version the message was added in. |
| 117 | 117 | */ |
| 118 | -function getpaid_doing_it_wrong( $function, $message, $version ) { |
|
| 118 | +function getpaid_doing_it_wrong($function, $message, $version) { |
|
| 119 | 119 | |
| 120 | 120 | $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
| 121 | 121 | |
| 122 | - if ( is_ajax() || defined( 'REST_REQUEST' ) ) { |
|
| 123 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
| 124 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
| 122 | + if (is_ajax() || defined('REST_REQUEST')) { |
|
| 123 | + do_action('doing_it_wrong_run', $function, $message, $version); |
|
| 124 | + error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}."); |
|
| 125 | 125 | } else { |
| 126 | - _doing_it_wrong( $function, $message, $version ); |
|
| 126 | + _doing_it_wrong($function, $message, $version); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | } |