@@ -30,36 +30,36 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function wpinv_can_checkout() { |
| 33 | - $can_checkout = true; // Always true for now |
|
| 33 | + $can_checkout = true; // Always true for now |
|
| 34 | 34 | |
| 35 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 35 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function wpinv_get_success_page_uri() { |
| 39 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 40 | - $page_id = absint( $page_id ); |
|
| 39 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 40 | + $page_id = absint( $page_id ); |
|
| 41 | 41 | |
| 42 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 42 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function wpinv_get_history_page_uri() { |
| 46 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
| 47 | - $page_id = absint( $page_id ); |
|
| 46 | + $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
| 47 | + $page_id = absint( $page_id ); |
|
| 48 | 48 | |
| 49 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
| 49 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function wpinv_is_success_page() { |
| 53 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 54 | - $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 53 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 54 | + $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 55 | 55 | |
| 56 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 56 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function wpinv_is_invoice_history_page() { |
| 60 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 61 | - $ret = $ret ? is_page( $ret ) : false; |
|
| 62 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 60 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 61 | + $ret = $ret ? is_page( $ret ) : false; |
|
| 62 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function wpinv_is_subscriptions_history_page() { |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function wpinv_send_to_success_page( $args = null ) { |
| 72 | - $redirect = wpinv_get_success_page_uri(); |
|
| 72 | + $redirect = wpinv_get_success_page_uri(); |
|
| 73 | 73 | |
| 74 | 74 | if ( !empty( $args ) ) { |
| 75 | 75 | // Check for backward compatibility |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function wpinv_send_to_failed_page( $args = null ) { |
| 92 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
| 92 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
| 93 | 93 | |
| 94 | 94 | if ( !empty( $args ) ) { |
| 95 | 95 | // Check for backward compatibility |
@@ -109,72 +109,72 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | function wpinv_get_checkout_uri( $args = array() ) { |
| 112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
| 112 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 113 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
| 114 | 114 | |
| 115 | - if ( !empty( $args ) ) { |
|
| 116 | - // Check for backward compatibility |
|
| 117 | - if ( is_string( $args ) ) |
|
| 118 | - $args = str_replace( '?', '', $args ); |
|
| 115 | + if ( !empty( $args ) ) { |
|
| 116 | + // Check for backward compatibility |
|
| 117 | + if ( is_string( $args ) ) |
|
| 118 | + $args = str_replace( '?', '', $args ); |
|
| 119 | 119 | |
| 120 | - $args = wp_parse_args( $args ); |
|
| 120 | + $args = wp_parse_args( $args ); |
|
| 121 | 121 | |
| 122 | - $uri = add_query_arg( $args, $uri ); |
|
| 123 | - } |
|
| 122 | + $uri = add_query_arg( $args, $uri ); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 125 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 126 | 126 | |
| 127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 127 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 128 | 128 | |
| 129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 131 | - } |
|
| 129 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 130 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 133 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | function wpinv_send_back_to_checkout( $args = array() ) { |
| 137 | - $redirect = wpinv_get_checkout_uri(); |
|
| 137 | + $redirect = wpinv_get_checkout_uri(); |
|
| 138 | 138 | |
| 139 | - if ( ! empty( $args ) ) { |
|
| 140 | - // Check for backward compatibility |
|
| 141 | - if ( is_string( $args ) ) |
|
| 142 | - $args = str_replace( '?', '', $args ); |
|
| 139 | + if ( ! empty( $args ) ) { |
|
| 140 | + // Check for backward compatibility |
|
| 141 | + if ( is_string( $args ) ) |
|
| 142 | + $args = str_replace( '?', '', $args ); |
|
| 143 | 143 | |
| 144 | - $args = wp_parse_args( $args ); |
|
| 144 | + $args = wp_parse_args( $args ); |
|
| 145 | 145 | |
| 146 | - $redirect = add_query_arg( $args, $redirect ); |
|
| 147 | - } |
|
| 146 | + $redirect = add_query_arg( $args, $redirect ); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
| 150 | - exit; |
|
| 149 | + wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
| 150 | + exit; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | function wpinv_get_success_page_url( $query_string = null ) { |
| 154 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 155 | - $success_page = get_permalink( $success_page ); |
|
| 154 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 155 | + $success_page = get_permalink( $success_page ); |
|
| 156 | 156 | |
| 157 | - if ( $query_string ) |
|
| 158 | - $success_page .= $query_string; |
|
| 157 | + if ( $query_string ) |
|
| 158 | + $success_page .= $query_string; |
|
| 159 | 159 | |
| 160 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 160 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
| 164 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 164 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 165 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 166 | 166 | |
| 167 | - if ( $extras ) |
|
| 168 | - $uri .= $extras; |
|
| 167 | + if ( $extras ) |
|
| 168 | + $uri .= $extras; |
|
| 169 | 169 | |
| 170 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 170 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | function wpinv_is_failed_transaction_page() { |
| 174 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
| 175 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 174 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
| 175 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 176 | 176 | |
| 177 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 177 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -320,36 +320,36 @@ discard block |
||
| 320 | 320 | $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
| 321 | 321 | |
| 322 | 322 | if ( $require_billing_details ) { |
| 323 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
| 324 | - $required_fields['first_name'] = array( |
|
| 325 | - 'error_id' => 'invalid_first_name', |
|
| 326 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
| 327 | - ); |
|
| 328 | - } |
|
| 329 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
| 330 | - $required_fields['address'] = array( |
|
| 331 | - 'error_id' => 'invalid_address', |
|
| 332 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
| 333 | - ); |
|
| 334 | - } |
|
| 335 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
| 336 | - $required_fields['city'] = array( |
|
| 337 | - 'error_id' => 'invalid_city', |
|
| 338 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
| 339 | - ); |
|
| 340 | - } |
|
| 341 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
| 342 | - $required_fields['state'] = array( |
|
| 343 | - 'error_id' => 'invalid_state', |
|
| 344 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
| 345 | - ); |
|
| 346 | - } |
|
| 347 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
| 348 | - $required_fields['country'] = array( |
|
| 349 | - 'error_id' => 'invalid_country', |
|
| 350 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
| 351 | - ); |
|
| 352 | - } |
|
| 323 | + if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
| 324 | + $required_fields['first_name'] = array( |
|
| 325 | + 'error_id' => 'invalid_first_name', |
|
| 326 | + 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
| 327 | + ); |
|
| 328 | + } |
|
| 329 | + if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
| 330 | + $required_fields['address'] = array( |
|
| 331 | + 'error_id' => 'invalid_address', |
|
| 332 | + 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
| 333 | + ); |
|
| 334 | + } |
|
| 335 | + if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
| 336 | + $required_fields['city'] = array( |
|
| 337 | + 'error_id' => 'invalid_city', |
|
| 338 | + 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
| 339 | + ); |
|
| 340 | + } |
|
| 341 | + if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
| 342 | + $required_fields['state'] = array( |
|
| 343 | + 'error_id' => 'invalid_state', |
|
| 344 | + 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
| 345 | + ); |
|
| 346 | + } |
|
| 347 | + if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
| 348 | + $required_fields['country'] = array( |
|
| 349 | + 'error_id' => 'invalid_country', |
|
| 350 | + 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
@@ -7,201 +7,201 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_is_checkout() { |
| 15 | 15 | global $wp_query; |
| 16 | 16 | |
| 17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
| 18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
| 19 | - $is_checkout = is_page( wpinv_get_option( 'checkout_page' ) ); |
|
| 17 | + $is_object_set = isset($wp_query->queried_object); |
|
| 18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
| 19 | + $is_checkout = is_page(wpinv_get_option('checkout_page')); |
|
| 20 | 20 | |
| 21 | - if ( !$is_object_set ) { |
|
| 22 | - unset( $wp_query->queried_object ); |
|
| 21 | + if (!$is_object_set) { |
|
| 22 | + unset($wp_query->queried_object); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - if ( !$is_object_id_set ) { |
|
| 26 | - unset( $wp_query->queried_object_id ); |
|
| 25 | + if (!$is_object_id_set) { |
|
| 26 | + unset($wp_query->queried_object_id); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
| 29 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function wpinv_can_checkout() { |
| 33 | 33 | $can_checkout = true; // Always true for now |
| 34 | 34 | |
| 35 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 35 | + return (bool)apply_filters('wpinv_can_checkout', $can_checkout); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function wpinv_get_success_page_uri() { |
| 39 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 40 | - $page_id = absint( $page_id ); |
|
| 39 | + $page_id = wpinv_get_option('success_page', 0); |
|
| 40 | + $page_id = absint($page_id); |
|
| 41 | 41 | |
| 42 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 42 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function wpinv_get_history_page_uri() { |
| 46 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
| 47 | - $page_id = absint( $page_id ); |
|
| 46 | + $page_id = wpinv_get_option('invoice_history_page', 0); |
|
| 47 | + $page_id = absint($page_id); |
|
| 48 | 48 | |
| 49 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
| 49 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id)); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function wpinv_is_success_page() { |
| 53 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 54 | - $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 53 | + $is_success_page = wpinv_get_option('success_page', false); |
|
| 54 | + $is_success_page = isset($is_success_page) ? is_page($is_success_page) : false; |
|
| 55 | 55 | |
| 56 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 56 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function wpinv_is_invoice_history_page() { |
| 60 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 61 | - $ret = $ret ? is_page( $ret ) : false; |
|
| 62 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 60 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
| 61 | + $ret = $ret ? is_page($ret) : false; |
|
| 62 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function wpinv_is_subscriptions_history_page() { |
| 66 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 67 | - $ret = $ret ? is_page( $ret ) : false; |
|
| 68 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
| 66 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
| 67 | + $ret = $ret ? is_page($ret) : false; |
|
| 68 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | -function wpinv_send_to_success_page( $args = null ) { |
|
| 71 | +function wpinv_send_to_success_page($args = null) { |
|
| 72 | 72 | $redirect = wpinv_get_success_page_uri(); |
| 73 | 73 | |
| 74 | - if ( !empty( $args ) ) { |
|
| 74 | + if (!empty($args)) { |
|
| 75 | 75 | // Check for backward compatibility |
| 76 | - if ( is_string( $args ) ) |
|
| 77 | - $args = str_replace( '?', '', $args ); |
|
| 76 | + if (is_string($args)) |
|
| 77 | + $args = str_replace('?', '', $args); |
|
| 78 | 78 | |
| 79 | - $args = wp_parse_args( $args ); |
|
| 79 | + $args = wp_parse_args($args); |
|
| 80 | 80 | |
| 81 | - $redirect = add_query_arg( $args, $redirect ); |
|
| 81 | + $redirect = add_query_arg($args, $redirect); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 84 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 85 | 85 | |
| 86 | - $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args ); |
|
| 87 | - wp_redirect( $redirect ); |
|
| 86 | + $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args); |
|
| 87 | + wp_redirect($redirect); |
|
| 88 | 88 | exit; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | -function wpinv_send_to_failed_page( $args = null ) { |
|
| 91 | +function wpinv_send_to_failed_page($args = null) { |
|
| 92 | 92 | $redirect = wpinv_get_failed_transaction_uri(); |
| 93 | 93 | |
| 94 | - if ( !empty( $args ) ) { |
|
| 94 | + if (!empty($args)) { |
|
| 95 | 95 | // Check for backward compatibility |
| 96 | - if ( is_string( $args ) ) |
|
| 97 | - $args = str_replace( '?', '', $args ); |
|
| 96 | + if (is_string($args)) |
|
| 97 | + $args = str_replace('?', '', $args); |
|
| 98 | 98 | |
| 99 | - $args = wp_parse_args( $args ); |
|
| 99 | + $args = wp_parse_args($args); |
|
| 100 | 100 | |
| 101 | - $redirect = add_query_arg( $args, $redirect ); |
|
| 101 | + $redirect = add_query_arg($args, $redirect); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 104 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 105 | 105 | |
| 106 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
| 107 | - wp_redirect( $redirect ); |
|
| 106 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
| 107 | + wp_redirect($redirect); |
|
| 108 | 108 | exit; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
| 112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
| 111 | +function wpinv_get_checkout_uri($args = array()) { |
|
| 112 | + $uri = wpinv_get_option('checkout_page', false); |
|
| 113 | + $uri = isset($uri) ? get_permalink($uri) : NULL; |
|
| 114 | 114 | |
| 115 | - if ( !empty( $args ) ) { |
|
| 115 | + if (!empty($args)) { |
|
| 116 | 116 | // Check for backward compatibility |
| 117 | - if ( is_string( $args ) ) |
|
| 118 | - $args = str_replace( '?', '', $args ); |
|
| 117 | + if (is_string($args)) |
|
| 118 | + $args = str_replace('?', '', $args); |
|
| 119 | 119 | |
| 120 | - $args = wp_parse_args( $args ); |
|
| 120 | + $args = wp_parse_args($args); |
|
| 121 | 121 | |
| 122 | - $uri = add_query_arg( $args, $uri ); |
|
| 122 | + $uri = add_query_arg($args, $uri); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 125 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 126 | 126 | |
| 127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 127 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
| 128 | 128 | |
| 129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 129 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
| 130 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 133 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | -function wpinv_send_back_to_checkout( $args = array() ) { |
|
| 136 | +function wpinv_send_back_to_checkout($args = array()) { |
|
| 137 | 137 | $redirect = wpinv_get_checkout_uri(); |
| 138 | 138 | |
| 139 | - if ( ! empty( $args ) ) { |
|
| 139 | + if (!empty($args)) { |
|
| 140 | 140 | // Check for backward compatibility |
| 141 | - if ( is_string( $args ) ) |
|
| 142 | - $args = str_replace( '?', '', $args ); |
|
| 141 | + if (is_string($args)) |
|
| 142 | + $args = str_replace('?', '', $args); |
|
| 143 | 143 | |
| 144 | - $args = wp_parse_args( $args ); |
|
| 144 | + $args = wp_parse_args($args); |
|
| 145 | 145 | |
| 146 | - $redirect = add_query_arg( $args, $redirect ); |
|
| 146 | + $redirect = add_query_arg($args, $redirect); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
| 149 | + wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args)); |
|
| 150 | 150 | exit; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
| 154 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 155 | - $success_page = get_permalink( $success_page ); |
|
| 153 | +function wpinv_get_success_page_url($query_string = null) { |
|
| 154 | + $success_page = wpinv_get_option('success_page', 0); |
|
| 155 | + $success_page = get_permalink($success_page); |
|
| 156 | 156 | |
| 157 | - if ( $query_string ) |
|
| 157 | + if ($query_string) |
|
| 158 | 158 | $success_page .= $query_string; |
| 159 | 159 | |
| 160 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 160 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
| 164 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 163 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
| 164 | + $uri = wpinv_get_option('failure_page', ''); |
|
| 165 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
| 166 | 166 | |
| 167 | - if ( $extras ) |
|
| 167 | + if ($extras) |
|
| 168 | 168 | $uri .= $extras; |
| 169 | 169 | |
| 170 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 170 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | function wpinv_is_failed_transaction_page() { |
| 174 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
| 175 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 174 | + $ret = wpinv_get_option('failure_page', false); |
|
| 175 | + $ret = isset($ret) ? is_page($ret) : false; |
|
| 176 | 176 | |
| 177 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 177 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | -function wpinv_transaction_query( $type = 'start' ) { |
|
| 180 | +function wpinv_transaction_query($type = 'start') { |
|
| 181 | 181 | global $wpdb; |
| 182 | 182 | |
| 183 | 183 | $wpdb->hide_errors(); |
| 184 | 184 | |
| 185 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
| 186 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
| 185 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
| 186 | + define('WPINV_USE_TRANSACTIONS', true); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
| 190 | - switch ( $type ) { |
|
| 189 | + if (WPINV_USE_TRANSACTIONS) { |
|
| 190 | + switch ($type) { |
|
| 191 | 191 | case 'commit' : |
| 192 | - $wpdb->query( 'COMMIT' ); |
|
| 192 | + $wpdb->query('COMMIT'); |
|
| 193 | 193 | break; |
| 194 | 194 | case 'rollback' : |
| 195 | - $wpdb->query( 'ROLLBACK' ); |
|
| 195 | + $wpdb->query('ROLLBACK'); |
|
| 196 | 196 | break; |
| 197 | 197 | default : |
| 198 | - $wpdb->query( 'START TRANSACTION' ); |
|
| 198 | + $wpdb->query('START TRANSACTION'); |
|
| 199 | 199 | break; |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | -function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) { |
|
| 204 | +function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) { |
|
| 205 | 205 | $default_args = array( |
| 206 | 206 | 'status' => '', |
| 207 | 207 | 'user_id' => null, |
@@ -211,63 +211,63 @@ discard block |
||
| 211 | 211 | 'parent' => 0 |
| 212 | 212 | ); |
| 213 | 213 | |
| 214 | - $args = wp_parse_args( $args, $default_args ); |
|
| 214 | + $args = wp_parse_args($args, $default_args); |
|
| 215 | 215 | $invoice_data = array(); |
| 216 | 216 | |
| 217 | - if ( $args['invoice_id'] > 0 ) { |
|
| 218 | - $updating = true; |
|
| 217 | + if ($args['invoice_id'] > 0) { |
|
| 218 | + $updating = true; |
|
| 219 | 219 | $invoice_data['post_type'] = 'wpi_invoice'; |
| 220 | 220 | $invoice_data['ID'] = $args['invoice_id']; |
| 221 | 221 | } else { |
| 222 | 222 | $updating = false; |
| 223 | 223 | $invoice_data['post_type'] = 'wpi_invoice'; |
| 224 | - $invoice_data['post_status'] = apply_filters( 'wpinv_default_invoice_status', 'wpi-pending' ); |
|
| 224 | + $invoice_data['post_status'] = apply_filters('wpinv_default_invoice_status', 'wpi-pending'); |
|
| 225 | 225 | $invoice_data['ping_status'] = 'closed'; |
| 226 | - $invoice_data['post_author'] = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id(); |
|
| 227 | - $invoice_data['post_title'] = wpinv_format_invoice_number( '0' ); |
|
| 228 | - $invoice_data['post_parent'] = absint( $args['parent'] ); |
|
| 229 | - if ( !empty( $args['created_date'] ) ) { |
|
| 226 | + $invoice_data['post_author'] = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id(); |
|
| 227 | + $invoice_data['post_title'] = wpinv_format_invoice_number('0'); |
|
| 228 | + $invoice_data['post_parent'] = absint($args['parent']); |
|
| 229 | + if (!empty($args['created_date'])) { |
|
| 230 | 230 | $invoice_data['post_date'] = $args['created_date']; |
| 231 | - $invoice_data['post_date_gmt'] = get_gmt_from_date( $args['created_date'] ); |
|
| 231 | + $invoice_data['post_date_gmt'] = get_gmt_from_date($args['created_date']); |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if ( $args['status'] ) { |
|
| 236 | - if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
| 237 | - return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) ); |
|
| 235 | + if ($args['status']) { |
|
| 236 | + if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) { |
|
| 237 | + return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status'])); |
|
| 238 | 238 | } |
| 239 | - $invoice_data['post_status'] = $args['status']; |
|
| 239 | + $invoice_data['post_status'] = $args['status']; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if ( ! is_null( $args['user_note'] ) ) { |
|
| 243 | - $invoice_data['post_excerpt'] = $args['user_note']; |
|
| 242 | + if (!is_null($args['user_note'])) { |
|
| 243 | + $invoice_data['post_excerpt'] = $args['user_note']; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - if ( $updating ) { |
|
| 247 | - $invoice_id = wp_update_post( $invoice_data, true ); |
|
| 246 | + if ($updating) { |
|
| 247 | + $invoice_id = wp_update_post($invoice_data, true); |
|
| 248 | 248 | } else { |
| 249 | - $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true ); |
|
| 249 | + $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - if ( is_wp_error( $invoice_id ) ) { |
|
| 252 | + if (is_wp_error($invoice_id)) { |
|
| 253 | 253 | return $wp_error ? $invoice_id : 0; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 257 | - |
|
| 258 | - if ( !$updating ) { |
|
| 259 | - update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) ); |
|
| 260 | - update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() ); |
|
| 261 | - update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) ); |
|
| 262 | - update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() ); |
|
| 263 | - update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() ); |
|
| 264 | - update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) ); |
|
| 256 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 257 | + |
|
| 258 | + if (!$updating) { |
|
| 259 | + update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_'))); |
|
| 260 | + update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency()); |
|
| 261 | + update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax')); |
|
| 262 | + update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip()); |
|
| 263 | + update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent()); |
|
| 264 | + update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via'])); |
|
| 265 | 265 | |
| 266 | 266 | // Add invoice note |
| 267 | - $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
|
| 267 | + $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status))); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION ); |
|
| 270 | + update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION); |
|
| 271 | 271 | |
| 272 | 272 | return $invoice; |
| 273 | 273 | } |
@@ -275,184 +275,184 @@ discard block |
||
| 275 | 275 | function wpinv_get_prefix() { |
| 276 | 276 | $invoice_prefix = 'INV-'; |
| 277 | 277 | |
| 278 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
| 278 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | function wpinv_get_business_logo() { |
| 282 | - $business_logo = wpinv_get_option( 'logo' ); |
|
| 283 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
| 282 | + $business_logo = wpinv_get_option('logo'); |
|
| 283 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | function wpinv_get_business_name() { |
| 287 | 287 | $business_name = wpinv_get_option('store_name'); |
| 288 | - return apply_filters( 'wpinv_get_business_name', $business_name ); |
|
| 288 | + return apply_filters('wpinv_get_business_name', $business_name); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | function wpinv_get_blogname() { |
| 292 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
| 292 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | function wpinv_get_admin_email() { |
| 296 | - $admin_email = get_option( 'admin_email' ); |
|
| 297 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
| 296 | + $admin_email = get_option('admin_email'); |
|
| 297 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | function wpinv_get_business_website() { |
| 301 | - $business_website = home_url( '/' ); |
|
| 302 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
| 301 | + $business_website = home_url('/'); |
|
| 302 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
| 305 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
| 306 | 306 | $terms_text = ''; |
| 307 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
| 307 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | function wpinv_get_business_footer() { |
| 311 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
| 312 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
| 313 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
| 311 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
| 312 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
| 313 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | function wpinv_checkout_required_fields() { |
| 317 | 317 | $required_fields = array(); |
| 318 | 318 | |
| 319 | 319 | // Let payment gateways and other extensions determine if address fields should be required |
| 320 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
| 320 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
| 321 | 321 | |
| 322 | - if ( $require_billing_details ) { |
|
| 323 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
| 322 | + if ($require_billing_details) { |
|
| 323 | + if ((bool)wpinv_get_option('fname_mandatory')) { |
|
| 324 | 324 | $required_fields['first_name'] = array( |
| 325 | 325 | 'error_id' => 'invalid_first_name', |
| 326 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
| 326 | + 'error_message' => __('Please enter your first name', 'invoicing') |
|
| 327 | 327 | ); |
| 328 | 328 | } |
| 329 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
| 329 | + if ((bool)wpinv_get_option('address_mandatory')) { |
|
| 330 | 330 | $required_fields['address'] = array( |
| 331 | 331 | 'error_id' => 'invalid_address', |
| 332 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
| 332 | + 'error_message' => __('Please enter your address', 'invoicing') |
|
| 333 | 333 | ); |
| 334 | 334 | } |
| 335 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
| 335 | + if ((bool)wpinv_get_option('city_mandatory')) { |
|
| 336 | 336 | $required_fields['city'] = array( |
| 337 | 337 | 'error_id' => 'invalid_city', |
| 338 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
| 338 | + 'error_message' => __('Please enter your billing city', 'invoicing') |
|
| 339 | 339 | ); |
| 340 | 340 | } |
| 341 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
| 341 | + if ((bool)wpinv_get_option('state_mandatory')) { |
|
| 342 | 342 | $required_fields['state'] = array( |
| 343 | 343 | 'error_id' => 'invalid_state', |
| 344 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
| 344 | + 'error_message' => __('Please enter billing state / province', 'invoicing') |
|
| 345 | 345 | ); |
| 346 | 346 | } |
| 347 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
| 347 | + if ((bool)wpinv_get_option('country_mandatory')) { |
|
| 348 | 348 | $required_fields['country'] = array( |
| 349 | 349 | 'error_id' => 'invalid_country', |
| 350 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
| 350 | + 'error_message' => __('Please select your billing country', 'invoicing') |
|
| 351 | 351 | ); |
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
| 355 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | function wpinv_is_ssl_enforced() { |
| 359 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
| 360 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
| 359 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
| 360 | + return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | -function wpinv_user_can_view_invoice( $post ) { |
|
| 363 | +function wpinv_user_can_view_invoice($post) { |
|
| 364 | 364 | $allow = false; |
| 365 | 365 | |
| 366 | - $post = get_post( $post ); |
|
| 366 | + $post = get_post($post); |
|
| 367 | 367 | |
| 368 | - if ( empty( $post->ID ) ) { |
|
| 368 | + if (empty($post->ID)) { |
|
| 369 | 369 | return $allow; |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
| 373 | - if ( empty( $invoice->ID ) ) { |
|
| 372 | + $invoice = wpinv_get_invoice($post->ID); |
|
| 373 | + if (empty($invoice->ID)) { |
|
| 374 | 374 | return $allow; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // Don't allow trash, draft status |
| 378 | - if ( $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
| 379 | - if ( current_user_can( 'manage_options' ) ) { // Admin user |
|
| 378 | + if ($invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
| 379 | + if (current_user_can('manage_options')) { // Admin user |
|
| 380 | 380 | $allow = true; |
| 381 | 381 | } else { |
| 382 | - if ( is_user_logged_in() ) { |
|
| 383 | - if ( (int)$invoice->get_user_id() === (int)get_current_user_id() ) { |
|
| 382 | + if (is_user_logged_in()) { |
|
| 383 | + if ((int)$invoice->get_user_id() === (int)get_current_user_id()) { |
|
| 384 | 384 | $allow = true; |
| 385 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 385 | + } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
| 386 | 386 | $allow = true; |
| 387 | 387 | } |
| 388 | 388 | } else { |
| 389 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 389 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
| 390 | 390 | $allow = true; |
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - return apply_filters( 'wpinv_can_print_invoice', $allow, $post, $invoice ); |
|
| 396 | + return apply_filters('wpinv_can_print_invoice', $allow, $post, $invoice); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | function wpinv_schedule_events() { |
| 400 | 400 | // hourly, daily and twicedaily |
| 401 | - if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) { |
|
| 402 | - wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' ); |
|
| 401 | + if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) { |
|
| 402 | + wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily'); |
|
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | -add_action( 'wp', 'wpinv_schedule_events' ); |
|
| 405 | +add_action('wp', 'wpinv_schedule_events'); |
|
| 406 | 406 | |
| 407 | 407 | function wpinv_schedule_event_twicedaily() { |
| 408 | 408 | wpinv_email_payment_reminders(); |
| 409 | 409 | } |
| 410 | -add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' ); |
|
| 410 | +add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily'); |
|
| 411 | 411 | |
| 412 | 412 | function wpinv_require_login_to_checkout() { |
| 413 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
| 414 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
| 413 | + $return = wpinv_get_option('login_to_checkout', false); |
|
| 414 | + return (bool)apply_filters('wpinv_require_login_to_checkout', $return); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | -function wpinv_sequential_number_active( $type = '' ) { |
|
| 418 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
| 419 | - if ( null !== $check ) { |
|
| 417 | +function wpinv_sequential_number_active($type = '') { |
|
| 418 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
| 419 | + if (null !== $check) { |
|
| 420 | 420 | return $check; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
| 423 | + return wpinv_get_option('sequential_invoice_number'); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | -function wpinv_switch_to_locale( $locale = NULL ) { |
|
| 426 | +function wpinv_switch_to_locale($locale = NULL) { |
|
| 427 | 427 | global $invoicing, $wpi_switch_locale; |
| 428 | 428 | |
| 429 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
| 430 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
| 429 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
| 430 | + $locale = empty($locale) ? get_locale() : $locale; |
|
| 431 | 431 | |
| 432 | - switch_to_locale( $locale ); |
|
| 432 | + switch_to_locale($locale); |
|
| 433 | 433 | |
| 434 | 434 | $wpi_switch_locale = $locale; |
| 435 | 435 | |
| 436 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
| 436 | + add_filter('plugin_locale', 'get_locale'); |
|
| 437 | 437 | |
| 438 | 438 | $invoicing->load_textdomain(); |
| 439 | 439 | |
| 440 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
| 440 | + do_action('wpinv_switch_to_locale', $locale); |
|
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | function wpinv_restore_locale() { |
| 445 | 445 | global $invoicing, $wpi_switch_locale; |
| 446 | 446 | |
| 447 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
| 447 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
| 448 | 448 | restore_previous_locale(); |
| 449 | 449 | |
| 450 | 450 | $wpi_switch_locale = NULL; |
| 451 | 451 | |
| 452 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
| 452 | + remove_filter('plugin_locale', 'get_locale'); |
|
| 453 | 453 | |
| 454 | 454 | $invoicing->load_textdomain(); |
| 455 | 455 | |
| 456 | - do_action( 'wpinv_restore_locale' ); |
|
| 456 | + do_action('wpinv_restore_locale'); |
|
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | \ No newline at end of file |