@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | class WPInv_EUVat { |
| 6 | 6 | private static $is_ajax = false; |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | private static $instance = false; |
| 9 | 9 | |
| 10 | 10 | public static function get_instance() { |
| 11 | - if ( !self::$instance ) { |
|
| 11 | + if (!self::$instance) { |
|
| 12 | 12 | self::$instance = new self(); |
| 13 | 13 | self::$instance->actions(); |
| 14 | 14 | } |
@@ -17,137 +17,137 @@ discard block |
||
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function __construct() { |
| 20 | - self::$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 20 | + self::$is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 21 | 21 | self::$default_country = wpinv_get_default_country(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public static function actions() { |
| 25 | - if ( is_admin() ) { |
|
| 26 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) ); |
|
| 27 | - add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); |
|
| 28 | - add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) ); |
|
| 29 | - add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) ); |
|
| 30 | - add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) ); |
|
| 31 | - add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
| 32 | - add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
| 33 | - add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
| 34 | - add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
| 35 | - add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
| 36 | - add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
| 37 | - add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
| 38 | - add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) ); |
|
| 42 | - add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 ); |
|
| 43 | - add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 ); |
|
| 44 | - add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
| 45 | - add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
| 46 | - add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
| 47 | - add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
| 48 | - add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 ); |
|
| 49 | - if ( wpinv_use_taxes() ) { |
|
| 50 | - add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) ); |
|
| 51 | - if ( self::allow_vat_rules() ) { |
|
| 52 | - add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 ); |
|
| 53 | - add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 ); |
|
| 25 | + if (is_admin()) { |
|
| 26 | + add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts')); |
|
| 27 | + add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); |
|
| 28 | + add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings')); |
|
| 29 | + add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings')); |
|
| 30 | + add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates')); |
|
| 31 | + add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
| 32 | + add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
| 33 | + add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
| 34 | + add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
| 35 | + add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
| 36 | + add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
| 37 | + add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
| 38 | + add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts')); |
|
| 42 | + add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10); |
|
| 43 | + add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10); |
|
| 44 | + add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
| 45 | + add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
| 46 | + add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
| 47 | + add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
| 48 | + add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1); |
|
| 49 | + if (wpinv_use_taxes()) { |
|
| 50 | + add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields')); |
|
| 51 | + if (self::allow_vat_rules()) { |
|
| 52 | + add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2); |
|
| 53 | + add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public static function get_eu_states( $sort = true ) { |
|
| 59 | - $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); |
|
| 60 | - if ( $sort ) { |
|
| 61 | - $sort = sort( $eu_states ); |
|
| 58 | + public static function get_eu_states($sort = true) { |
|
| 59 | + $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'); |
|
| 60 | + if ($sort) { |
|
| 61 | + $sort = sort($eu_states); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
|
| 64 | + return apply_filters('wpinv_get_eu_states', $eu_states, $sort); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - public static function get_gst_countries( $sort = true ) { |
|
| 68 | - $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
|
| 67 | + public static function get_gst_countries($sort = true) { |
|
| 68 | + $gst_countries = array('AU', 'NZ', 'CA', 'CN'); |
|
| 69 | 69 | |
| 70 | - if ( $sort ) { |
|
| 71 | - $sort = sort( $gst_countries ); |
|
| 70 | + if ($sort) { |
|
| 71 | + $sort = sort($gst_countries); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
|
| 74 | + return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public static function is_eu_state( $country_code ) { |
|
| 78 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
|
| 77 | + public static function is_eu_state($country_code) { |
|
| 78 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false; |
|
| 79 | 79 | |
| 80 | - return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
|
| 80 | + return apply_filters('wpinv_is_eu_state', $return, $country_code); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public static function is_gst_country( $country_code ) { |
|
| 84 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
|
| 83 | + public static function is_gst_country($country_code) { |
|
| 84 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false; |
|
| 85 | 85 | |
| 86 | - return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
|
| 86 | + return apply_filters('wpinv_is_gst_country', $return, $country_code); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | public static function enqueue_vat_scripts() { |
| 90 | - if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) { |
|
| 90 | + if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) { |
|
| 91 | 91 | self::load_vat_scripts(); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - public static function load_vat_scripts(){ |
|
| 96 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 95 | + public static function load_vat_scripts() { |
|
| 96 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 97 | 97 | |
| 98 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 99 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 98 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 99 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 100 | 100 | |
| 101 | - $vat_name = self::get_vat_name(); |
|
| 101 | + $vat_name = self::get_vat_name(); |
|
| 102 | 102 | |
| 103 | 103 | $vars = array(); |
| 104 | 104 | $vars['UseTaxes'] = wpinv_use_taxes(); |
| 105 | 105 | $vars['EUStates'] = self::get_eu_states(); |
| 106 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
| 107 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
| 108 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
| 109 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
| 110 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
| 111 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
| 112 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
| 113 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
| 106 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
| 107 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
| 108 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
| 109 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
| 110 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
| 111 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
| 112 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
| 113 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
| 114 | 114 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
| 115 | 115 | $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true; |
| 116 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
| 117 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
| 118 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
| 119 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
| 120 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
| 121 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
| 122 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
| 123 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
| 124 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
| 125 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
| 126 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 127 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 128 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
| 116 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
| 117 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
| 118 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
| 119 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
| 120 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
| 121 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
| 122 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
| 123 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
| 124 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
| 125 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
| 126 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 127 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 128 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
| 129 | 129 | $vars['isFront'] = is_admin() ? false : true; |
| 130 | 130 | $vars['baseCountry'] = wpinv_get_default_country(); |
| 131 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
| 132 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
| 131 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
| 132 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
| 133 | 133 | |
| 134 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
| 135 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
| 136 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
| 134 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
| 135 | + wp_enqueue_script('wpinv-vat-script'); |
|
| 136 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | public static function enqueue_admin_scripts() { |
| 140 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
| 140 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
| 141 | 141 | self::load_vat_scripts(); |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - public static function section_vat_settings( $sections ) { |
|
| 146 | - if ( !empty( $sections ) ) { |
|
| 147 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
| 145 | + public static function section_vat_settings($sections) { |
|
| 146 | + if (!empty($sections)) { |
|
| 147 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
| 148 | 148 | |
| 149 | - if ( self::allow_vat_classes() ) { |
|
| 150 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
| 149 | + if (self::allow_vat_classes()) { |
|
| 150 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | return $sections; |
@@ -156,52 +156,52 @@ discard block |
||
| 156 | 156 | public static function vat_rates_settings() { |
| 157 | 157 | $vat_classes = self::get_rate_classes(); |
| 158 | 158 | $vat_rates = array(); |
| 159 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
| 160 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
| 159 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
| 160 | + $current_url = remove_query_arg('wpi_sub'); |
|
| 161 | 161 | |
| 162 | 162 | $vat_rates['vat_rates_header'] = array( |
| 163 | 163 | 'id' => 'vat_rates_header', |
| 164 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
| 164 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
| 165 | 165 | 'desc' => '', |
| 166 | 166 | 'type' => 'header', |
| 167 | 167 | 'size' => 'regular' |
| 168 | 168 | ); |
| 169 | 169 | $vat_rates['vat_rates_class'] = array( |
| 170 | 170 | 'id' => 'vat_rates_class', |
| 171 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
| 172 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
| 171 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
| 172 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
| 173 | 173 | 'type' => 'select', |
| 174 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
| 175 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
| 174 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
| 175 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
| 176 | 176 | 'selected' => $vat_class, |
| 177 | 177 | 'class' => 'wpi_select2', |
| 178 | 178 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
| 179 | 179 | ); |
| 180 | 180 | |
| 181 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
| 181 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
| 182 | 182 | $vat_rates['vat_rate_delete'] = array( |
| 183 | 183 | 'id' => 'vat_rate_delete', |
| 184 | 184 | 'type' => 'vat_rate_delete', |
| 185 | 185 | ); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if ( $vat_class == '_new' ) { |
|
| 188 | + if ($vat_class == '_new') { |
|
| 189 | 189 | $vat_rates['vat_rates_settings'] = array( |
| 190 | 190 | 'id' => 'vat_rates_settings', |
| 191 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
| 191 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
| 192 | 192 | 'type' => 'header', |
| 193 | 193 | ); |
| 194 | 194 | $vat_rates['vat_rate_name'] = array( |
| 195 | 195 | 'id' => 'vat_rate_name', |
| 196 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 197 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
| 196 | + 'name' => __('Name', 'invoicing'), |
|
| 197 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
| 198 | 198 | 'type' => 'text', |
| 199 | 199 | 'size' => 'regular', |
| 200 | 200 | ); |
| 201 | 201 | $vat_rates['vat_rate_desc'] = array( |
| 202 | 202 | 'id' => 'vat_rate_desc', |
| 203 | - 'name' => __( 'Description', 'invoicing' ), |
|
| 204 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
| 203 | + 'name' => __('Description', 'invoicing'), |
|
| 204 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
| 205 | 205 | 'type' => 'text', |
| 206 | 206 | 'size' => 'regular', |
| 207 | 207 | ); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $vat_rates['vat_rates'] = array( |
| 214 | 214 | 'id' => 'vat_rates', |
| 215 | 215 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
| 216 | - 'desc' => self::get_class_desc( $vat_class ), |
|
| 216 | + 'desc' => self::get_class_desc($vat_class), |
|
| 217 | 217 | 'type' => 'vat_rates', |
| 218 | 218 | ); |
| 219 | 219 | } |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | return $vat_rates; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - public static function vat_settings( $settings ) { |
|
| 225 | - if ( !empty( $settings ) ) { |
|
| 224 | + public static function vat_settings($settings) { |
|
| 225 | + if (!empty($settings)) { |
|
| 226 | 226 | $vat_settings = array(); |
| 227 | 227 | $vat_settings['vat_company_title'] = array( |
| 228 | 228 | 'id' => 'vat_company_title', |
| 229 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
| 229 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
| 230 | 230 | 'desc' => '', |
| 231 | 231 | 'type' => 'header', |
| 232 | 232 | 'size' => 'regular' |
@@ -234,22 +234,22 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | $vat_settings['vat_company_name'] = array( |
| 236 | 236 | 'id' => 'vat_company_name', |
| 237 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
| 238 | - 'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
| 237 | + 'name' => __('Your Company Name', 'invoicing'), |
|
| 238 | + 'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
| 239 | 239 | 'type' => 'text', |
| 240 | 240 | 'size' => 'regular', |
| 241 | 241 | ); |
| 242 | 242 | |
| 243 | 243 | $vat_settings['vat_number'] = array( |
| 244 | 244 | 'id' => 'vat_number', |
| 245 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
| 245 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
| 246 | 246 | 'type' => 'vat_number', |
| 247 | 247 | 'size' => 'regular', |
| 248 | 248 | ); |
| 249 | 249 | |
| 250 | 250 | $vat_settings['vat_settings_title'] = array( |
| 251 | 251 | 'id' => 'vat_settings_title', |
| 252 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
| 252 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
| 253 | 253 | 'desc' => '', |
| 254 | 254 | 'type' => 'header', |
| 255 | 255 | 'size' => 'regular' |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | $vat_settings['apply_vat_rules'] = array( |
| 259 | 259 | 'id' => 'apply_vat_rules', |
| 260 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
| 261 | - 'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>', |
|
| 260 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
| 261 | + 'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>', |
|
| 262 | 262 | 'type' => 'checkbox', |
| 263 | 263 | 'std' => '1' |
| 264 | 264 | ); |
@@ -274,8 +274,8 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
| 276 | 276 | 'id' => 'vat_prevent_b2c_purchase', |
| 277 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
| 278 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
| 277 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
| 278 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
| 279 | 279 | 'type' => 'checkbox' |
| 280 | 280 | ); |
| 281 | 281 | |
@@ -283,22 +283,22 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | $vat_settings['vat_same_country_rule'] = array( |
| 285 | 285 | 'id' => 'vat_same_country_rule', |
| 286 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
| 287 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
| 286 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
| 287 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
| 288 | 288 | 'type' => 'select', |
| 289 | 289 | 'options' => array( |
| 290 | - '' => __( 'Normal', 'invoicing' ), |
|
| 291 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
| 292 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
| 290 | + '' => __('Normal', 'invoicing'), |
|
| 291 | + 'no' => __('No VAT', 'invoicing'), |
|
| 292 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
| 293 | 293 | ), |
| 294 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
| 294 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
| 295 | 295 | 'std' => '', |
| 296 | 296 | 'class' => 'wpi_select2', |
| 297 | 297 | ); |
| 298 | 298 | |
| 299 | 299 | $vat_settings['vat_checkout_title'] = array( |
| 300 | 300 | 'id' => 'vat_checkout_title', |
| 301 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
| 301 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
| 302 | 302 | 'desc' => '', |
| 303 | 303 | 'type' => 'header', |
| 304 | 304 | 'size' => 'regular' |
@@ -306,14 +306,14 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | $vat_settings['vat_disable_fields'] = array( |
| 308 | 308 | 'id' => 'vat_disable_fields', |
| 309 | - 'name' => __( 'Disable VAT Fields', 'invoicing' ), |
|
| 310 | - 'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>', |
|
| 309 | + 'name' => __('Disable VAT Fields', 'invoicing'), |
|
| 310 | + 'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>', |
|
| 311 | 311 | 'type' => 'checkbox' |
| 312 | 312 | ); |
| 313 | 313 | |
| 314 | 314 | $vat_settings['vat_ip_lookup'] = array( |
| 315 | 315 | 'id' => 'vat_ip_lookup', |
| 316 | - 'name' => __( 'IP Country Look-up', 'invoicing' ), |
|
| 316 | + 'name' => __('IP Country Look-up', 'invoicing'), |
|
| 317 | 317 | 'type' => 'vat_ip_lookup', |
| 318 | 318 | 'size' => 'regular', |
| 319 | 319 | 'std' => 'default', |
@@ -322,21 +322,21 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | $vat_settings['hide_ip_address'] = array( |
| 324 | 324 | 'id' => 'hide_ip_address', |
| 325 | - 'name' => __( 'Hide IP Info at Checkout', 'invoicing' ), |
|
| 326 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
| 325 | + 'name' => __('Hide IP Info at Checkout', 'invoicing'), |
|
| 326 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
| 327 | 327 | 'type' => 'checkbox' |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | 330 | $vat_settings['vat_ip_country_default'] = array( |
| 331 | 331 | 'id' => 'vat_ip_country_default', |
| 332 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
| 333 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
| 332 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
| 333 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
| 334 | 334 | 'type' => 'checkbox' |
| 335 | 335 | ); |
| 336 | 336 | |
| 337 | 337 | $vat_settings['vies_validation_title'] = array( |
| 338 | 338 | 'id' => 'vies_validation_title', |
| 339 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
| 339 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
| 340 | 340 | 'desc' => '', |
| 341 | 341 | 'type' => 'header', |
| 342 | 342 | 'size' => 'regular' |
@@ -344,37 +344,37 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | $vat_settings['vat_vies_check'] = array( |
| 346 | 346 | 'id' => 'vat_vies_check', |
| 347 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
| 348 | - 'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
| 347 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
| 348 | + 'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
| 349 | 349 | 'type' => 'checkbox' |
| 350 | 350 | ); |
| 351 | 351 | |
| 352 | 352 | $vat_settings['vat_disable_company_name_check'] = array( |
| 353 | 353 | 'id' => 'vat_disable_company_name_check', |
| 354 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
| 355 | - 'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
| 354 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
| 355 | + 'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
| 356 | 356 | 'type' => 'checkbox' |
| 357 | 357 | ); |
| 358 | 358 | |
| 359 | 359 | $vat_settings['vat_offline_check'] = array( |
| 360 | 360 | 'id' => 'vat_offline_check', |
| 361 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
| 362 | - 'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ), |
|
| 361 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
| 362 | + 'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'), |
|
| 363 | 363 | 'type' => 'checkbox' |
| 364 | 364 | ); |
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | $settings['vat'] = $vat_settings; |
| 368 | 368 | |
| 369 | - if ( self::allow_vat_classes() ) { |
|
| 369 | + if (self::allow_vat_classes()) { |
|
| 370 | 370 | $settings['vat_rates'] = self::vat_rates_settings(); |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $eu_fallback_rate = array( |
| 374 | 374 | 'id' => 'eu_fallback_rate', |
| 375 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
| 375 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
| 376 | 376 | 'type' => 'eu_fallback_rate', |
| 377 | - 'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ), |
|
| 377 | + 'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'), |
|
| 378 | 378 | 'std' => '20', |
| 379 | 379 | 'size' => 'small' |
| 380 | 380 | ); |
@@ -390,11 +390,11 @@ discard block |
||
| 390 | 390 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
| 391 | 391 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
| 392 | 392 | |
| 393 | - if ( !is_dir( $destination_dir ) ) { |
|
| 394 | - mkdir( $destination_dir ); |
|
| 393 | + if (!is_dir($destination_dir)) { |
|
| 394 | + mkdir($destination_dir); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - $database_files = array( |
|
| 397 | + $database_files = array( |
|
| 398 | 398 | 'country' => array( |
| 399 | 399 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
| 400 | 400 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -405,57 +405,57 @@ discard block |
||
| 405 | 405 | ) |
| 406 | 406 | ); |
| 407 | 407 | |
| 408 | - foreach( $database_files as $database => $files ) { |
|
| 409 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
| 408 | + foreach ($database_files as $database => $files) { |
|
| 409 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
| 410 | 410 | |
| 411 | - if ( empty( $result['success'] ) ) { |
|
| 411 | + if (empty($result['success'])) { |
|
| 412 | 412 | echo $result['message']; |
| 413 | 413 | exit; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
| 417 | - echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
| 416 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
| 417 | + echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | exit; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
| 423 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
| 424 | 424 | $success = false; |
| 425 | 425 | $message = ''; |
| 426 | 426 | |
| 427 | - if ( !function_exists( 'download_url' ) ) { |
|
| 428 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 427 | + if (!function_exists('download_url')) { |
|
| 428 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - $temp_file = download_url( $source_url ); |
|
| 431 | + $temp_file = download_url($source_url); |
|
| 432 | 432 | |
| 433 | - if ( is_wp_error( $temp_file ) ) { |
|
| 434 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
| 433 | + if (is_wp_error($temp_file)) { |
|
| 434 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
| 435 | 435 | } else { |
| 436 | - $handle = gzopen( $temp_file, 'rb' ); |
|
| 436 | + $handle = gzopen($temp_file, 'rb'); |
|
| 437 | 437 | |
| 438 | - if ( $handle ) { |
|
| 439 | - $fopen = fopen( $destination_file, 'wb' ); |
|
| 440 | - if ( $fopen ) { |
|
| 441 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
| 442 | - fwrite( $fopen, $data ); |
|
| 438 | + if ($handle) { |
|
| 439 | + $fopen = fopen($destination_file, 'wb'); |
|
| 440 | + if ($fopen) { |
|
| 441 | + while (($data = gzread($handle, 4096)) != false) { |
|
| 442 | + fwrite($fopen, $data); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - gzclose( $handle ); |
|
| 446 | - fclose( $fopen ); |
|
| 445 | + gzclose($handle); |
|
| 446 | + fclose($fopen); |
|
| 447 | 447 | |
| 448 | 448 | $success = true; |
| 449 | 449 | } else { |
| 450 | - gzclose( $handle ); |
|
| 451 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
| 450 | + gzclose($handle); |
|
| 451 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
| 452 | 452 | } |
| 453 | 453 | } else { |
| 454 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
| 454 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - if ( file_exists( $temp_file ) ) { |
|
| 458 | - unlink( $temp_file ); |
|
| 457 | + if (file_exists($temp_file)) { |
|
| 458 | + unlink($temp_file); |
|
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
@@ -467,11 +467,11 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | public static function load_geoip2() { |
| 470 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
| 470 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
| 471 | 471 | return; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
| 474 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
| 475 | 475 | $maxmind_db_files = array( |
| 476 | 476 | 'Reader/Decoder.php', |
| 477 | 477 | 'Reader/InvalidDatabaseException.php', |
@@ -480,12 +480,12 @@ discard block |
||
| 480 | 480 | 'Reader.php', |
| 481 | 481 | ); |
| 482 | 482 | |
| 483 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
| 484 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
| 483 | + foreach ($maxmind_db_files as $key => $file) { |
|
| 484 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
| 488 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
| 489 | 489 | $geoip2_files = array( |
| 490 | 490 | 'ProviderInterface.php', |
| 491 | 491 | 'Compat/JsonSerializable.php', |
@@ -519,23 +519,23 @@ discard block |
||
| 519 | 519 | 'WebService/Client.php', |
| 520 | 520 | ); |
| 521 | 521 | |
| 522 | - foreach ( $geoip2_files as $key => $file ) { |
|
| 523 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
| 522 | + foreach ($geoip2_files as $key => $file) { |
|
| 523 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
| 527 | + define('WPINV_GEOIP2_LODDED', true); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | public static function geoip2_country_dbfile() { |
| 531 | 531 | $upload_dir = wp_upload_dir(); |
| 532 | 532 | |
| 533 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
| 533 | + if (!isset($upload_dir['basedir'])) { |
|
| 534 | 534 | return false; |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
| 538 | - if ( !file_exists( $filename ) ) { |
|
| 538 | + if (!file_exists($filename)) { |
|
| 539 | 539 | return false; |
| 540 | 540 | } |
| 541 | 541 | |
@@ -545,12 +545,12 @@ discard block |
||
| 545 | 545 | public static function geoip2_city_dbfile() { |
| 546 | 546 | $upload_dir = wp_upload_dir(); |
| 547 | 547 | |
| 548 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
| 548 | + if (!isset($upload_dir['basedir'])) { |
|
| 549 | 549 | return false; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
| 553 | - if ( !file_exists( $filename ) ) { |
|
| 553 | + if (!file_exists($filename)) { |
|
| 554 | 554 | return false; |
| 555 | 555 | } |
| 556 | 556 | |
@@ -561,10 +561,10 @@ discard block |
||
| 561 | 561 | try { |
| 562 | 562 | self::load_geoip2(); |
| 563 | 563 | |
| 564 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
| 565 | - return new \GeoIp2\Database\Reader( $filename ); |
|
| 564 | + if ($filename = self::geoip2_country_dbfile()) { |
|
| 565 | + return new \GeoIp2\Database\Reader($filename); |
|
| 566 | 566 | } |
| 567 | - } catch( Exception $e ) { |
|
| 567 | + } catch (Exception $e) { |
|
| 568 | 568 | return false; |
| 569 | 569 | } |
| 570 | 570 | |
@@ -575,173 +575,173 @@ discard block |
||
| 575 | 575 | try { |
| 576 | 576 | self::load_geoip2(); |
| 577 | 577 | |
| 578 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
| 579 | - return new \GeoIp2\Database\Reader( $filename ); |
|
| 578 | + if ($filename = self::geoip2_city_dbfile()) { |
|
| 579 | + return new \GeoIp2\Database\Reader($filename); |
|
| 580 | 580 | } |
| 581 | - } catch( Exception $e ) { |
|
| 581 | + } catch (Exception $e) { |
|
| 582 | 582 | return false; |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | return false; |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - public static function geoip2_country_record( $ip_address ) { |
|
| 588 | + public static function geoip2_country_record($ip_address) { |
|
| 589 | 589 | try { |
| 590 | 590 | $reader = self::geoip2_country_reader(); |
| 591 | 591 | |
| 592 | - if ( $reader ) { |
|
| 593 | - $record = $reader->country( $ip_address ); |
|
| 592 | + if ($reader) { |
|
| 593 | + $record = $reader->country($ip_address); |
|
| 594 | 594 | |
| 595 | - if ( !empty( $record->country->isoCode ) ) { |
|
| 595 | + if (!empty($record->country->isoCode)) { |
|
| 596 | 596 | return $record; |
| 597 | 597 | } |
| 598 | 598 | } |
| 599 | - } catch(\InvalidArgumentException $e) { |
|
| 600 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 599 | + } catch (\InvalidArgumentException $e) { |
|
| 600 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 601 | 601 | |
| 602 | 602 | return false; |
| 603 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 604 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 603 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 604 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 605 | 605 | |
| 606 | 606 | return false; |
| 607 | - } catch( Exception $e ) { |
|
| 607 | + } catch (Exception $e) { |
|
| 608 | 608 | return false; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | return false; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - public static function geoip2_city_record( $ip_address ) { |
|
| 614 | + public static function geoip2_city_record($ip_address) { |
|
| 615 | 615 | try { |
| 616 | 616 | $reader = self::geoip2_city_reader(); |
| 617 | 617 | |
| 618 | - if ( $reader ) { |
|
| 619 | - $record = $reader->city( $ip_address ); |
|
| 618 | + if ($reader) { |
|
| 619 | + $record = $reader->city($ip_address); |
|
| 620 | 620 | |
| 621 | - if ( !empty( $record->country->isoCode ) ) { |
|
| 621 | + if (!empty($record->country->isoCode)) { |
|
| 622 | 622 | return $record; |
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | - } catch(\InvalidArgumentException $e) { |
|
| 626 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 625 | + } catch (\InvalidArgumentException $e) { |
|
| 626 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 627 | 627 | |
| 628 | 628 | return false; |
| 629 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 630 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 629 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 630 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 631 | 631 | |
| 632 | 632 | return false; |
| 633 | - } catch( Exception $e ) { |
|
| 633 | + } catch (Exception $e) { |
|
| 634 | 634 | return false; |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | return false; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - public static function geoip2_country_code( $ip_address ) { |
|
| 641 | - $record = self::geoip2_country_record( $ip_address ); |
|
| 642 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
| 640 | + public static function geoip2_country_code($ip_address) { |
|
| 641 | + $record = self::geoip2_country_record($ip_address); |
|
| 642 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | // Find country by IP address. |
| 646 | - public static function get_country_by_ip( $ip = '' ) { |
|
| 646 | + public static function get_country_by_ip($ip = '') { |
|
| 647 | 647 | global $wpinv_ip_address_country; |
| 648 | 648 | |
| 649 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
| 649 | + if (!empty($wpinv_ip_address_country)) { |
|
| 650 | 650 | return $wpinv_ip_address_country; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | - if ( empty( $ip ) ) { |
|
| 653 | + if (empty($ip)) { |
|
| 654 | 654 | $ip = wpinv_get_ip(); |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
| 658 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
| 657 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
| 658 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
| 659 | 659 | |
| 660 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
| 661 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
| 660 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
| 661 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
| 662 | 662 | try { |
| 663 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
| 664 | - } catch( Exception $e ) { |
|
| 665 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
| 663 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
| 664 | + } catch (Exception $e) { |
|
| 665 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
| 666 | 666 | } |
| 667 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
| 668 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
| 669 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
| 670 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
| 667 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
| 668 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
| 669 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
| 670 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
| 671 | 671 | |
| 672 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
| 672 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
| 673 | 673 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
| 674 | 674 | } |
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
| 678 | + if (empty($wpinv_ip_address_country)) { |
|
| 679 | 679 | $wpinv_ip_address_country = wpinv_get_default_country(); |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | return $wpinv_ip_address_country; |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - public static function sanitize_vat_settings( $input ) { |
|
| 685 | + public static function sanitize_vat_settings($input) { |
|
| 686 | 686 | global $wpinv_options; |
| 687 | 687 | |
| 688 | 688 | $valid = false; |
| 689 | 689 | $message = ''; |
| 690 | 690 | |
| 691 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 692 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
| 693 | - $valid = self::offline_check( $input['vat_number'] ); |
|
| 691 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 692 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
| 693 | + $valid = self::offline_check($input['vat_number']); |
|
| 694 | 694 | } else { |
| 695 | 695 | $valid = true; |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
| 698 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
| 699 | 699 | } else { |
| 700 | - $result = self::check_vat( $input['vat_number'] ); |
|
| 700 | + $result = self::check_vat($input['vat_number']); |
|
| 701 | 701 | |
| 702 | - if ( empty( $result['valid'] ) ) { |
|
| 702 | + if (empty($result['valid'])) { |
|
| 703 | 703 | $valid = false; |
| 704 | 704 | $message = $result['message']; |
| 705 | 705 | } else { |
| 706 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
| 707 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
| 706 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
| 707 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
| 708 | 708 | } |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
| 712 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
| 711 | + if ($message && self::is_vat_validated() != $valid) { |
|
| 712 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | $input['vat_valid'] = $valid; |
| 716 | 716 | return $input; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - public static function sanitize_vat_rates( $input ) { |
|
| 720 | - if( !current_user_can( 'manage_options' ) ) { |
|
| 721 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
| 719 | + public static function sanitize_vat_rates($input) { |
|
| 720 | + if (!current_user_can('manage_options')) { |
|
| 721 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
| 722 | 722 | return $input; |
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | $vat_classes = self::get_rate_classes(); |
| 726 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
| 726 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
| 727 | 727 | |
| 728 | - if ( empty( $vat_class ) ) { |
|
| 729 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
| 728 | + if (empty($vat_class)) { |
|
| 729 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
| 730 | 730 | |
| 731 | 731 | return $input; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
| 734 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
| 735 | 735 | |
| 736 | - if ( $vat_class === '_standard' ) { |
|
| 736 | + if ($vat_class === '_standard') { |
|
| 737 | 737 | // Save the active rates in the invoice settings |
| 738 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
| 738 | + update_option('wpinv_tax_rates', $new_rates); |
|
| 739 | 739 | } else { |
| 740 | 740 | // Get the existing set of rates |
| 741 | 741 | $rates = self::get_non_standard_rates(); |
| 742 | 742 | $rates[$vat_class] = $new_rates; |
| 743 | 743 | |
| 744 | - update_option( 'wpinv_vat_rates', $rates ); |
|
| 744 | + update_option('wpinv_vat_rates', $rates); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | return $input; |
@@ -751,71 +751,71 @@ discard block |
||
| 751 | 751 | $response = array(); |
| 752 | 752 | $response['success'] = false; |
| 753 | 753 | |
| 754 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 755 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 756 | - wp_send_json( $response ); |
|
| 754 | + if (!current_user_can('manage_options')) { |
|
| 755 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 756 | + wp_send_json($response); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
| 760 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
| 759 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
| 760 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
| 761 | 761 | |
| 762 | - if ( empty( $vat_class_name ) ) { |
|
| 763 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
| 764 | - wp_send_json( $response ); |
|
| 762 | + if (empty($vat_class_name)) { |
|
| 763 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
| 764 | + wp_send_json($response); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | $vat_classes = (array)self::get_rate_classes(); |
| 768 | 768 | |
| 769 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
| 770 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
| 771 | - wp_send_json( $response ); |
|
| 769 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
| 770 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
| 771 | + wp_send_json($response); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
| 775 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
| 774 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
| 775 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
| 776 | 776 | |
| 777 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
| 778 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
| 777 | + $vat_classes = (array)self::get_rate_classes(true); |
|
| 778 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
| 779 | 779 | |
| 780 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
| 780 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
| 781 | 781 | |
| 782 | 782 | $response['success'] = true; |
| 783 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
| 783 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
| 784 | 784 | |
| 785 | - wp_send_json( $response ); |
|
| 785 | + wp_send_json($response); |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | public static function delete_class() { |
| 789 | 789 | $response = array(); |
| 790 | 790 | $response['success'] = false; |
| 791 | 791 | |
| 792 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
| 793 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 794 | - wp_send_json( $response ); |
|
| 792 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
| 793 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 794 | + wp_send_json($response); |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
| 797 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
| 798 | 798 | $vat_classes = (array)self::get_rate_classes(); |
| 799 | 799 | |
| 800 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
| 801 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
| 802 | - wp_send_json( $response ); |
|
| 800 | + if (!isset($vat_classes[$vat_class])) { |
|
| 801 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
| 802 | + wp_send_json($response); |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
| 806 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
| 807 | - wp_send_json( $response ); |
|
| 805 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
| 806 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
| 807 | + wp_send_json($response); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
| 811 | - unset( $vat_classes[$vat_class] ); |
|
| 810 | + $vat_classes = (array)self::get_rate_classes(true); |
|
| 811 | + unset($vat_classes[$vat_class]); |
|
| 812 | 812 | |
| 813 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
| 813 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
| 814 | 814 | |
| 815 | 815 | $response['success'] = true; |
| 816 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
| 816 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
| 817 | 817 | |
| 818 | - wp_send_json( $response ); |
|
| 818 | + wp_send_json($response); |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | public static function update_eu_rates() { |
@@ -824,72 +824,72 @@ discard block |
||
| 824 | 824 | $response['error'] = null; |
| 825 | 825 | $response['data'] = null; |
| 826 | 826 | |
| 827 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 828 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 829 | - wp_send_json( $response ); |
|
| 827 | + if (!current_user_can('manage_options')) { |
|
| 828 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 829 | + wp_send_json($response); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
| 833 | - $euvatrates = self::request_euvatrates( $group ); |
|
| 832 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
| 833 | + $euvatrates = self::request_euvatrates($group); |
|
| 834 | 834 | |
| 835 | - if ( !empty( $euvatrates ) ) { |
|
| 836 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
| 835 | + if (!empty($euvatrates)) { |
|
| 836 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
| 837 | 837 | $response['success'] = true; |
| 838 | 838 | $response['data']['rates'] = $euvatrates['rates']; |
| 839 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
| 839 | + } else if (!empty($euvatrates['error'])) { |
|
| 840 | 840 | $response['error'] = $euvatrates['error']; |
| 841 | 841 | } |
| 842 | 842 | } |
| 843 | 843 | |
| 844 | - wp_send_json( $response ); |
|
| 844 | + wp_send_json($response); |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | public static function hide_vat_fields() { |
| 848 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
| 848 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
| 849 | 849 | |
| 850 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
| 850 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | public static function same_country_rule() { |
| 854 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
| 854 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
| 855 | 855 | |
| 856 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
| 856 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | public static function get_vat_name() { |
| 860 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
| 861 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
| 860 | + $vat_name = wpinv_get_option('vat_name'); |
|
| 861 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
| 862 | 862 | |
| 863 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
| 863 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | public static function get_company_name() { |
| 867 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
| 867 | + $company_name = wpinv_get_option('vat_company_name'); |
|
| 868 | 868 | |
| 869 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
| 869 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | public static function get_vat_number() { |
| 873 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
| 873 | + $vat_number = wpinv_get_option('vat_number'); |
|
| 874 | 874 | |
| 875 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
| 875 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | public static function is_vat_validated() { |
| 879 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
| 879 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
| 880 | 880 | |
| 881 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
| 881 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
| 885 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
| 884 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
| 885 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
| 886 | 886 | |
| 887 | - if ( empty( $country_code ) ) { |
|
| 888 | - $country_code = substr( $vat_number, 0, 2 ); |
|
| 887 | + if (empty($country_code)) { |
|
| 888 | + $country_code = substr($vat_number, 0, 2); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
| 892 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
| 891 | + if (strpos($vat_number, $country_code) === 0) { |
|
| 892 | + $vat = str_replace($country_code, '', $vat_number); |
|
| 893 | 893 | } else { |
| 894 | 894 | $vat = $country_code . $vat_number; |
| 895 | 895 | } |
@@ -902,140 +902,140 @@ discard block |
||
| 902 | 902 | return $return; |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
| 906 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
| 905 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
| 906 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
| 907 | 907 | $vat_number = $vat['vat_number']; |
| 908 | 908 | $country_code = $vat['iso']; |
| 909 | 909 | $regex = array(); |
| 910 | 910 | |
| 911 | - switch ( $country_code ) { |
|
| 911 | + switch ($country_code) { |
|
| 912 | 912 | case 'AT': |
| 913 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
| 913 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
| 914 | 914 | break; |
| 915 | 915 | case 'BE': |
| 916 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
| 916 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
| 917 | 917 | break; |
| 918 | 918 | case 'BG': |
| 919 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
| 919 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
| 920 | 920 | break; |
| 921 | 921 | case 'CH': |
| 922 | 922 | case 'CHE': |
| 923 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
| 923 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
| 924 | 924 | break; |
| 925 | 925 | case 'CY': |
| 926 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
| 926 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
| 927 | 927 | break; |
| 928 | 928 | case 'CZ': |
| 929 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
| 929 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
| 930 | 930 | break; |
| 931 | 931 | case 'DE': |
| 932 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
| 932 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
| 933 | 933 | break; |
| 934 | 934 | case 'DK': |
| 935 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
| 935 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
| 936 | 936 | break; |
| 937 | 937 | case 'EE': |
| 938 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
| 938 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
| 939 | 939 | break; |
| 940 | 940 | case 'EL': |
| 941 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
| 941 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
| 942 | 942 | break; |
| 943 | 943 | case 'ES': |
| 944 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
| 945 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
| 946 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
| 947 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
| 944 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
| 945 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
| 946 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
| 947 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
| 948 | 948 | break; |
| 949 | 949 | case 'EU': |
| 950 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
| 950 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
| 951 | 951 | break; |
| 952 | 952 | case 'FI': |
| 953 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
| 953 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
| 954 | 954 | break; |
| 955 | 955 | case 'FR': |
| 956 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
| 957 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
| 958 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
| 959 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
| 956 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
| 957 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
| 958 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
| 959 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
| 960 | 960 | break; |
| 961 | 961 | case 'GB': |
| 962 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
| 963 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
| 964 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
| 965 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
| 962 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
| 963 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
| 964 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
| 965 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
| 966 | 966 | break; |
| 967 | 967 | case 'GR': |
| 968 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
| 968 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
| 969 | 969 | break; |
| 970 | 970 | case 'HR': |
| 971 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
| 971 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
| 972 | 972 | break; |
| 973 | 973 | case 'HU': |
| 974 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
| 974 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
| 975 | 975 | break; |
| 976 | 976 | case 'IE': |
| 977 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
| 978 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
| 979 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
| 977 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
| 978 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
| 979 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
| 980 | 980 | break; |
| 981 | 981 | case 'IT': |
| 982 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
| 982 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
| 983 | 983 | break; |
| 984 | 984 | case 'LV': |
| 985 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
| 985 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
| 986 | 986 | break; |
| 987 | 987 | case 'LT': |
| 988 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
| 988 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
| 989 | 989 | break; |
| 990 | 990 | case 'LU': |
| 991 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
| 991 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
| 992 | 992 | break; |
| 993 | 993 | case 'MT': |
| 994 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
| 994 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
| 995 | 995 | break; |
| 996 | 996 | case 'NL': |
| 997 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
| 997 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
| 998 | 998 | break; |
| 999 | 999 | case 'NO': |
| 1000 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
| 1000 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
| 1001 | 1001 | break; |
| 1002 | 1002 | case 'PL': |
| 1003 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
| 1003 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
| 1004 | 1004 | break; |
| 1005 | 1005 | case 'PT': |
| 1006 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
| 1006 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
| 1007 | 1007 | break; |
| 1008 | 1008 | case 'RO': |
| 1009 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
| 1009 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
| 1010 | 1010 | break; |
| 1011 | 1011 | case 'RS': |
| 1012 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
| 1012 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
| 1013 | 1013 | break; |
| 1014 | 1014 | case 'SI': |
| 1015 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
| 1015 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
| 1016 | 1016 | break; |
| 1017 | 1017 | case 'SK': |
| 1018 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
| 1018 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
| 1019 | 1019 | break; |
| 1020 | 1020 | case 'SE': |
| 1021 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
| 1021 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
| 1022 | 1022 | break; |
| 1023 | 1023 | default: |
| 1024 | 1024 | $regex = array(); |
| 1025 | 1025 | break; |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | - if ( empty( $regex ) ) { |
|
| 1028 | + if (empty($regex)) { |
|
| 1029 | 1029 | return false; |
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | - foreach ( $regex as $pattern ) { |
|
| 1032 | + foreach ($regex as $pattern) { |
|
| 1033 | 1033 | $matches = null; |
| 1034 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
| 1034 | + preg_match_all($pattern, $vat_number, $matches); |
|
| 1035 | 1035 | |
| 1036 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
| 1037 | - if ( $formatted ) { |
|
| 1038 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
| 1036 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
| 1037 | + if ($formatted) { |
|
| 1038 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
| 1039 | 1039 | } else { |
| 1040 | 1040 | return true; |
| 1041 | 1041 | } |
@@ -1045,75 +1045,75 @@ discard block |
||
| 1045 | 1045 | return false; |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
| 1049 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
| 1048 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
| 1049 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
| 1050 | 1050 | $vat_number = $vat['vat']; |
| 1051 | 1051 | $iso = $vat['iso']; |
| 1052 | 1052 | |
| 1053 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
| 1053 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
| 1054 | 1054 | |
| 1055 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 1056 | - $response = file_get_contents( $url ); |
|
| 1057 | - } else if ( function_exists( 'curl_init' ) ) { |
|
| 1055 | + if (ini_get('allow_url_fopen')) { |
|
| 1056 | + $response = file_get_contents($url); |
|
| 1057 | + } else if (function_exists('curl_init')) { |
|
| 1058 | 1058 | $ch = curl_init(); |
| 1059 | 1059 | |
| 1060 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
| 1061 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
| 1062 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
| 1063 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
| 1064 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
| 1060 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 1061 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
| 1062 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 1063 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 1064 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 1065 | 1065 | |
| 1066 | - $response = curl_exec( $ch ); |
|
| 1066 | + $response = curl_exec($ch); |
|
| 1067 | 1067 | |
| 1068 | - if ( curl_errno( $ch ) ) { |
|
| 1069 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
| 1068 | + if (curl_errno($ch)) { |
|
| 1069 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
| 1070 | 1070 | $response = ''; |
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | - curl_close( $ch ); |
|
| 1073 | + curl_close($ch); |
|
| 1074 | 1074 | } else { |
| 1075 | - wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' ); |
|
| 1075 | + wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR'); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | - if ( empty( $response ) ) { |
|
| 1078 | + if (empty($response)) { |
|
| 1079 | 1079 | return $result; |
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
| 1082 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
| 1083 | 1083 | return false; |
| 1084 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
| 1085 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
| 1084 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
| 1085 | + $content = explode("valid VAT number", htmlentities($response)); |
|
| 1086 | 1086 | |
| 1087 | - if ( !empty( $content[1] ) ) { |
|
| 1088 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
| 1087 | + if (!empty($content[1])) { |
|
| 1088 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
| 1089 | 1089 | |
| 1090 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
| 1090 | + if (!empty($matches[2]) && $matches[3]) { |
|
| 1091 | 1091 | $return = array(); |
| 1092 | 1092 | |
| 1093 | - foreach ( $matches[2] as $key => $label ) { |
|
| 1094 | - $label = trim( $label ); |
|
| 1093 | + foreach ($matches[2] as $key => $label) { |
|
| 1094 | + $label = trim($label); |
|
| 1095 | 1095 | |
| 1096 | - switch ( strtolower( $label ) ) { |
|
| 1096 | + switch (strtolower($label)) { |
|
| 1097 | 1097 | case 'member state': |
| 1098 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1098 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
| 1099 | 1099 | break; |
| 1100 | 1100 | case 'vat number': |
| 1101 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1101 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
| 1102 | 1102 | break; |
| 1103 | 1103 | case 'name': |
| 1104 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1104 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
| 1105 | 1105 | break; |
| 1106 | 1106 | case 'address': |
| 1107 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
| 1108 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
| 1107 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
| 1108 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
| 1109 | 1109 | break; |
| 1110 | 1110 | case 'consultation number': |
| 1111 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1111 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
| 1112 | 1112 | break; |
| 1113 | 1113 | } |
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | - if ( !empty( $return ) ) { |
|
| 1116 | + if (!empty($return)) { |
|
| 1117 | 1117 | return $return; |
| 1118 | 1118 | } |
| 1119 | 1119 | } |
@@ -1125,55 +1125,55 @@ discard block |
||
| 1125 | 1125 | } |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
| 1128 | + public static function check_vat($vat_number, $country_code = '') { |
|
| 1129 | 1129 | $vat_name = self::get_vat_name(); |
| 1130 | 1130 | |
| 1131 | 1131 | $return = array(); |
| 1132 | 1132 | $return['valid'] = false; |
| 1133 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 1133 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 1134 | 1134 | |
| 1135 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
| 1135 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
| 1136 | 1136 | return $return; |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | - $response = self::vies_check( $vat_number, $country_code ); |
|
| 1139 | + $response = self::vies_check($vat_number, $country_code); |
|
| 1140 | 1140 | |
| 1141 | - if ( $response ) { |
|
| 1142 | - $return['valid'] = true; |
|
| 1141 | + if ($response) { |
|
| 1142 | + $return['valid'] = true; |
|
| 1143 | 1143 | |
| 1144 | - if ( is_array( $response ) ) { |
|
| 1145 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
| 1146 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
| 1144 | + if (is_array($response)) { |
|
| 1145 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
| 1146 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
| 1147 | 1147 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
| 1148 | 1148 | } |
| 1149 | 1149 | } else { |
| 1150 | 1150 | $return['valid'] = false; |
| 1151 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
| 1151 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | 1154 | return $return; |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - public static function request_euvatrates( $group ) { |
|
| 1157 | + public static function request_euvatrates($group) { |
|
| 1158 | 1158 | $response = array(); |
| 1159 | 1159 | $response['success'] = false; |
| 1160 | 1160 | $response['error'] = null; |
| 1161 | 1161 | $response['eurates'] = null; |
| 1162 | 1162 | |
| 1163 | 1163 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
| 1164 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
| 1165 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
| 1164 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
| 1165 | + $api_response = wp_remote_get($euvatrates_url); |
|
| 1166 | 1166 | |
| 1167 | 1167 | try { |
| 1168 | - if ( is_wp_error( $api_response ) ) { |
|
| 1169 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
| 1168 | + if (is_wp_error($api_response)) { |
|
| 1169 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
| 1170 | 1170 | } else { |
| 1171 | - $body = json_decode( $api_response['body'] ); |
|
| 1171 | + $body = json_decode($api_response['body']); |
|
| 1172 | 1172 | |
| 1173 | - if ( isset( $body->rates ) ) { |
|
| 1173 | + if (isset($body->rates)) { |
|
| 1174 | 1174 | $rates = array(); |
| 1175 | 1175 | |
| 1176 | - foreach ( $body->rates as $country_code => $rate ) { |
|
| 1176 | + foreach ($body->rates as $country_code => $rate) { |
|
| 1177 | 1177 | $vat_rate = array(); |
| 1178 | 1178 | $vat_rate['country'] = $rate->country; |
| 1179 | 1179 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1181,7 +1181,7 @@ discard block |
||
| 1181 | 1181 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
| 1182 | 1182 | $vat_rate['parking'] = (float)$rate->parking_rate; |
| 1183 | 1183 | |
| 1184 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
| 1184 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
| 1185 | 1185 | $vat_rate_group = array(); |
| 1186 | 1186 | $vat_rate_group['country'] = $rate->country; |
| 1187 | 1187 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1193,79 +1193,79 @@ discard block |
||
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | 1195 | $response['success'] = true; |
| 1196 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
| 1196 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
| 1197 | 1197 | } else { |
| 1198 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
| 1198 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | } |
| 1201 | - } catch ( Exception $e ) { |
|
| 1202 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
| 1201 | + } catch (Exception $e) { |
|
| 1202 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
| 1205 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
| 1208 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
| 1209 | 1209 | global $wpi_item_id, $wpi_country; |
| 1210 | 1210 | |
| 1211 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1212 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
| 1213 | - } else if ( !empty( $_POST['country'] ) ) { |
|
| 1214 | - $country_code = trim( $_POST['country'] ); |
|
| 1215 | - } else if ( !empty( $wpi_country ) ) { |
|
| 1211 | + if (!empty($_POST['wpinv_country'])) { |
|
| 1212 | + $country_code = trim($_POST['wpinv_country']); |
|
| 1213 | + } else if (!empty($_POST['country'])) { |
|
| 1214 | + $country_code = trim($_POST['country']); |
|
| 1215 | + } else if (!empty($wpi_country)) { |
|
| 1216 | 1216 | $country_code = $wpi_country; |
| 1217 | 1217 | } else { |
| 1218 | - $country_code = self::get_user_country( '', $user_id ); |
|
| 1218 | + $country_code = self::get_user_country('', $user_id); |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | - if ( $is_digital === null && $wpi_item_id ) { |
|
| 1222 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
| 1221 | + if ($is_digital === null && $wpi_item_id) { |
|
| 1222 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
| 1223 | 1223 | } |
| 1224 | 1224 | |
| 1225 | - if ( !empty( $country_code ) ) { |
|
| 1226 | - $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) ); |
|
| 1225 | + if (!empty($country_code)) { |
|
| 1226 | + $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country)); |
|
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
| 1229 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | - public static function tax_label( $label = '' ) { |
|
| 1232 | + public static function tax_label($label = '') { |
|
| 1233 | 1233 | global $wpi_requires_vat; |
| 1234 | 1234 | |
| 1235 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
| 1236 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
| 1235 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
| 1236 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
| 1239 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | public static function standard_rates_label() { |
| 1243 | - return __( 'Standard Rates', 'invoicing' ); |
|
| 1243 | + return __('Standard Rates', 'invoicing'); |
|
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | - public static function get_rate_classes( $with_desc = false ) { |
|
| 1247 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
| 1248 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
| 1246 | + public static function get_rate_classes($with_desc = false) { |
|
| 1247 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
| 1248 | + $classes = maybe_unserialize($rate_classes_option); |
|
| 1249 | 1249 | |
| 1250 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
| 1250 | + if (empty($classes) || !is_array($classes)) { |
|
| 1251 | 1251 | $classes = array(); |
| 1252 | 1252 | } |
| 1253 | 1253 | |
| 1254 | 1254 | $rate_classes = array(); |
| 1255 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
| 1256 | - if ( $with_desc ) { |
|
| 1257 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
| 1255 | + if (!array_key_exists('_standard', $classes)) { |
|
| 1256 | + if ($with_desc) { |
|
| 1257 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
| 1258 | 1258 | } else { |
| 1259 | 1259 | $rate_classes['_standard'] = self::standard_rates_label(); |
| 1260 | 1260 | } |
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | - foreach ( $classes as $key => $class ) { |
|
| 1264 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
| 1265 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
| 1263 | + foreach ($classes as $key => $class) { |
|
| 1264 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
| 1265 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
| 1266 | 1266 | |
| 1267 | - if ( $with_desc ) { |
|
| 1268 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
| 1267 | + if ($with_desc) { |
|
| 1268 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
| 1269 | 1269 | } else { |
| 1270 | 1270 | $rate_classes[$key] = $name; |
| 1271 | 1271 | } |
@@ -1276,15 +1276,15 @@ discard block |
||
| 1276 | 1276 | |
| 1277 | 1277 | public static function get_all_classes() { |
| 1278 | 1278 | $classes = self::get_rate_classes(); |
| 1279 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
| 1279 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
| 1280 | 1280 | |
| 1281 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
| 1281 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | - public static function get_class_desc( $rate_class ) { |
|
| 1285 | - $rate_classes = self::get_rate_classes( true ); |
|
| 1284 | + public static function get_class_desc($rate_class) { |
|
| 1285 | + $rate_classes = self::get_rate_classes(true); |
|
| 1286 | 1286 | |
| 1287 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
| 1287 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
| 1288 | 1288 | return $rate_classes[$rate_class]['desc']; |
| 1289 | 1289 | } |
| 1290 | 1290 | |
@@ -1300,106 +1300,106 @@ discard block |
||
| 1300 | 1300 | 'increased' => 'Increased' |
| 1301 | 1301 | ); |
| 1302 | 1302 | |
| 1303 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
| 1303 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | public static function get_rules() { |
| 1307 | 1307 | $vat_rules = array( |
| 1308 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
| 1309 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
| 1308 | + 'digital' => __('Digital Product', 'invoicing'), |
|
| 1309 | + 'physical' => __('Physical Product', 'invoicing') |
|
| 1310 | 1310 | ); |
| 1311 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
| 1311 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | - public static function get_vat_rates( $class ) { |
|
| 1315 | - if ( $class === '_standard' ) { |
|
| 1314 | + public static function get_vat_rates($class) { |
|
| 1315 | + if ($class === '_standard') { |
|
| 1316 | 1316 | return wpinv_get_tax_rates(); |
| 1317 | 1317 | } |
| 1318 | 1318 | |
| 1319 | 1319 | $rates = self::get_non_standard_rates(); |
| 1320 | 1320 | |
| 1321 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
| 1321 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | public static function get_non_standard_rates() { |
| 1325 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
| 1326 | - return is_array( $option ) ? $option : array(); |
|
| 1325 | + $option = get_option('wpinv_vat_rates', array()); |
|
| 1326 | + return is_array($option) ? $option : array(); |
|
| 1327 | 1327 | } |
| 1328 | 1328 | |
| 1329 | 1329 | public static function allow_vat_rules() { |
| 1330 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
| 1330 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | public static function allow_vat_classes() { |
| 1334 | 1334 | return false; // TODO |
| 1335 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
| 1335 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
| 1336 | 1336 | } |
| 1337 | 1337 | |
| 1338 | - public static function get_item_class( $postID ) { |
|
| 1339 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
| 1338 | + public static function get_item_class($postID) { |
|
| 1339 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
| 1340 | 1340 | |
| 1341 | - if ( empty( $class ) ) { |
|
| 1341 | + if (empty($class)) { |
|
| 1342 | 1342 | $class = '_standard'; |
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
| 1345 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | - public static function item_class_label( $postID ) { |
|
| 1348 | + public static function item_class_label($postID) { |
|
| 1349 | 1349 | $vat_classes = self::get_all_classes(); |
| 1350 | 1350 | |
| 1351 | - $class = self::get_item_class( $postID ); |
|
| 1352 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
| 1351 | + $class = self::get_item_class($postID); |
|
| 1352 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
| 1353 | 1353 | |
| 1354 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
| 1354 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 1357 | - public static function get_item_rule( $postID ) { |
|
| 1358 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
| 1357 | + public static function get_item_rule($postID) { |
|
| 1358 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
| 1359 | 1359 | |
| 1360 | - if ( empty( $rule_type ) ) { |
|
| 1360 | + if (empty($rule_type)) { |
|
| 1361 | 1361 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
| 1362 | 1362 | } |
| 1363 | 1363 | |
| 1364 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
| 1364 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
| 1365 | 1365 | } |
| 1366 | 1366 | |
| 1367 | - public static function item_rule_label( $postID ) { |
|
| 1367 | + public static function item_rule_label($postID) { |
|
| 1368 | 1368 | $vat_rules = self::get_rules(); |
| 1369 | - $vat_rule = self::get_item_rule( $postID ); |
|
| 1370 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
| 1369 | + $vat_rule = self::get_item_rule($postID); |
|
| 1370 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
| 1371 | 1371 | |
| 1372 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
| 1372 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
| 1376 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
| 1375 | + public static function item_has_digital_rule($item_id = 0) { |
|
| 1376 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
| 1377 | 1377 | } |
| 1378 | 1378 | |
| 1379 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
| 1380 | - if ( !self::allow_vat_rules() ) { |
|
| 1379 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
| 1380 | + if (!self::allow_vat_rules()) { |
|
| 1381 | 1381 | return false; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - if ( empty( $invoice ) ) { |
|
| 1384 | + if (empty($invoice)) { |
|
| 1385 | 1385 | return true; |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | - if ( is_int( $invoice ) ) { |
|
| 1389 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 1388 | + if (is_int($invoice)) { |
|
| 1389 | + $invoice = new WPInv_Invoice($invoice); |
|
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
| 1392 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
| 1393 | 1393 | return true; |
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | - $cart_items = $invoice->get_cart_details(); |
|
| 1396 | + $cart_items = $invoice->get_cart_details(); |
|
| 1397 | 1397 | |
| 1398 | - if ( !empty( $cart_items ) ) { |
|
| 1398 | + if (!empty($cart_items)) { |
|
| 1399 | 1399 | $has_digital_rule = false; |
| 1400 | 1400 | |
| 1401 | - foreach ( $cart_items as $key => $item ) { |
|
| 1402 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
| 1401 | + foreach ($cart_items as $key => $item) { |
|
| 1402 | + if (self::item_has_digital_rule($item['id'])) { |
|
| 1403 | 1403 | $has_digital_rule = true; |
| 1404 | 1404 | break; |
| 1405 | 1405 | } |
@@ -1411,67 +1411,67 @@ discard block |
||
| 1411 | 1411 | return $has_digital_rule; |
| 1412 | 1412 | } |
| 1413 | 1413 | |
| 1414 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
| 1415 | - if ( !wpinv_use_taxes() ) { |
|
| 1414 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
| 1415 | + if (!wpinv_use_taxes()) { |
|
| 1416 | 1416 | return false; |
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | $is_taxable = true; |
| 1420 | 1420 | |
| 1421 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
| 1421 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
| 1422 | 1422 | $is_taxable = false; |
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
| 1425 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
| 1428 | + public static function find_rate($country, $state, $rate, $class) { |
|
| 1429 | 1429 | global $wpi_zero_tax; |
| 1430 | 1430 | |
| 1431 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
| 1431 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
| 1432 | 1432 | return 0; |
| 1433 | 1433 | } |
| 1434 | 1434 | |
| 1435 | - $tax_rates = wpinv_get_tax_rates(); |
|
| 1435 | + $tax_rates = wpinv_get_tax_rates(); |
|
| 1436 | 1436 | |
| 1437 | - if ( $class !== '_standard' ) { |
|
| 1438 | - $class_rates = self::get_vat_rates( $class ); |
|
| 1437 | + if ($class !== '_standard') { |
|
| 1438 | + $class_rates = self::get_vat_rates($class); |
|
| 1439 | 1439 | |
| 1440 | - if ( is_array( $class_rates ) ) { |
|
| 1440 | + if (is_array($class_rates)) { |
|
| 1441 | 1441 | $indexed_class_rates = array(); |
| 1442 | 1442 | |
| 1443 | - foreach ( $class_rates as $key => $cr ) { |
|
| 1443 | + foreach ($class_rates as $key => $cr) { |
|
| 1444 | 1444 | $indexed_class_rates[$cr['country']] = $cr; |
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
| 1447 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
| 1448 | 1448 | $tr_country = $tr['country']; |
| 1449 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
| 1449 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
| 1450 | 1450 | return $tr; |
| 1451 | 1451 | } |
| 1452 | 1452 | $icr = $indexed_class_rates[$tr_country]; |
| 1453 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
| 1453 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
| 1454 | 1454 | |
| 1455 | - }, $tax_rates, $class_rates ); |
|
| 1455 | + }, $tax_rates, $class_rates); |
|
| 1456 | 1456 | } |
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | - if ( !empty( $tax_rates ) ) { |
|
| 1460 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
| 1461 | - if ( $country != $tax_rate['country'] ) |
|
| 1459 | + if (!empty($tax_rates)) { |
|
| 1460 | + foreach ($tax_rates as $key => $tax_rate) { |
|
| 1461 | + if ($country != $tax_rate['country']) |
|
| 1462 | 1462 | continue; |
| 1463 | 1463 | |
| 1464 | - if ( !empty( $tax_rate['global'] ) ) { |
|
| 1465 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
| 1466 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
| 1464 | + if (!empty($tax_rate['global'])) { |
|
| 1465 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
| 1466 | + $rate = number_format($tax_rate['rate'], 4); |
|
| 1467 | 1467 | } |
| 1468 | 1468 | } else { |
| 1469 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
| 1469 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
| 1470 | 1470 | continue; |
| 1471 | 1471 | |
| 1472 | 1472 | $state_rate = $tax_rate['rate']; |
| 1473 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
| 1474 | - $rate = number_format( $state_rate, 4 ); |
|
| 1473 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
| 1474 | + $rate = number_format($state_rate, 4); |
|
| 1475 | 1475 | } |
| 1476 | 1476 | } |
| 1477 | 1477 | } |
@@ -1480,84 +1480,84 @@ discard block |
||
| 1480 | 1480 | return $rate; |
| 1481 | 1481 | } |
| 1482 | 1482 | |
| 1483 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
| 1483 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
| 1484 | 1484 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
| 1485 | 1485 | |
| 1486 | 1486 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
| 1487 | 1487 | $allow_vat_classes = self::allow_vat_classes(); |
| 1488 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
| 1488 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
| 1489 | 1489 | |
| 1490 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
| 1490 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
| 1491 | 1491 | return 0; |
| 1492 | - } else if ( !$allow_vat_classes ) { |
|
| 1492 | + } else if (!$allow_vat_classes) { |
|
| 1493 | 1493 | $class = '_standard'; |
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1496 | + if (!empty($_POST['wpinv_country'])) { |
|
| 1497 | 1497 | $post_country = $_POST['wpinv_country']; |
| 1498 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1498 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
| 1499 | 1499 | $post_country = $_POST['wpinv_country']; |
| 1500 | - } elseif( !empty( $_POST['country'] ) ) { |
|
| 1500 | + } elseif (!empty($_POST['country'])) { |
|
| 1501 | 1501 | $post_country = $_POST['country']; |
| 1502 | 1502 | } else { |
| 1503 | 1503 | $post_country = ''; |
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
| 1507 | - $base_country = wpinv_is_base_country( $country ); |
|
| 1506 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
| 1507 | + $base_country = wpinv_is_base_country($country); |
|
| 1508 | 1508 | |
| 1509 | - $requires_vat = self::requires_vat( 0, false ); |
|
| 1510 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
| 1511 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
| 1509 | + $requires_vat = self::requires_vat(0, false); |
|
| 1510 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
| 1511 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
| 1512 | 1512 | |
| 1513 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
| 1513 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
| 1514 | 1514 | $rate = 0; |
| 1515 | - } else if ( $requires_vat ) { |
|
| 1516 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
| 1515 | + } else if ($requires_vat) { |
|
| 1516 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
| 1517 | 1517 | $vat_info = self::current_vat_data(); |
| 1518 | 1518 | |
| 1519 | - if ( is_array( $vat_info ) ) { |
|
| 1520 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
| 1519 | + if (is_array($vat_info)) { |
|
| 1520 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
| 1521 | 1521 | } |
| 1522 | 1522 | |
| 1523 | - if ( $country == 'UK' ) { |
|
| 1523 | + if ($country == 'UK') { |
|
| 1524 | 1524 | $country = 'GB'; |
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | - if ( !empty( $vat_number ) ) { |
|
| 1527 | + if (!empty($vat_number)) { |
|
| 1528 | 1528 | $rate = 0; |
| 1529 | 1529 | } else { |
| 1530 | - $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
| 1530 | + $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
| 1534 | - if ( $base_country ) { |
|
| 1535 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
| 1533 | + if (empty($vat_number) && !$is_digital) { |
|
| 1534 | + if ($base_country) { |
|
| 1535 | + $rate = self::find_rate($country, null, $rate, $class); |
|
| 1536 | 1536 | } else { |
| 1537 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
| 1537 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
| 1538 | 1538 | $rate = $wpinv_options['eu_fallback_rate']; |
| 1539 | - } else if( !empty( $country ) ) { |
|
| 1540 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1539 | + } else if (!empty($country)) { |
|
| 1540 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1541 | 1541 | } |
| 1542 | 1542 | } |
| 1543 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
| 1544 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
| 1543 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
| 1544 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
| 1545 | 1545 | $rate = $wpinv_options['eu_fallback_rate']; |
| 1546 | - } else if( !empty( $country ) ) { |
|
| 1547 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1546 | + } else if (!empty($country)) { |
|
| 1547 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1548 | 1548 | } |
| 1549 | 1549 | } |
| 1550 | 1550 | } else { |
| 1551 | - if ( $is_digital ) { |
|
| 1551 | + if ($is_digital) { |
|
| 1552 | 1552 | $ip_country_code = self::get_country_by_ip(); |
| 1553 | 1553 | |
| 1554 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
| 1555 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
| 1554 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
| 1555 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
| 1556 | 1556 | } else { |
| 1557 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1557 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1558 | 1558 | } |
| 1559 | 1559 | } else { |
| 1560 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1560 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1561 | 1561 | } |
| 1562 | 1562 | } |
| 1563 | 1563 | |
@@ -1567,48 +1567,48 @@ discard block |
||
| 1567 | 1567 | public static function current_vat_data() { |
| 1568 | 1568 | global $wpi_session; |
| 1569 | 1569 | |
| 1570 | - return $wpi_session->get( 'user_vat_data' ); |
|
| 1570 | + return $wpi_session->get('user_vat_data'); |
|
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
| 1574 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
| 1573 | + public static function get_user_country($country = '', $user_id = 0) { |
|
| 1574 | + $user_address = wpinv_get_user_address($user_id, false); |
|
| 1575 | 1575 | |
| 1576 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
| 1576 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
| 1577 | 1577 | $country = ''; |
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
| 1581 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
| 1580 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
| 1581 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
| 1582 | 1582 | |
| 1583 | - if ( empty( $result ) ) { |
|
| 1583 | + if (empty($result)) { |
|
| 1584 | 1584 | $result = self::get_country_by_ip(); |
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | 1587 | return $result; |
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
| 1590 | + public static function set_user_country($country = '', $user_id = 0) { |
|
| 1591 | 1591 | global $wpi_userID; |
| 1592 | 1592 | |
| 1593 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
| 1593 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
| 1594 | 1594 | $country = wpinv_get_default_country(); |
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | return $country; |
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
| 1600 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
| 1601 | 1601 | global $wpi_current_id, $wpi_userID; |
| 1602 | 1602 | |
| 1603 | - if ( !empty( $_POST['new_user'] ) ) { |
|
| 1603 | + if (!empty($_POST['new_user'])) { |
|
| 1604 | 1604 | return ''; |
| 1605 | 1605 | } |
| 1606 | 1606 | |
| 1607 | - if ( empty( $user_id ) ) { |
|
| 1608 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
| 1607 | + if (empty($user_id)) { |
|
| 1608 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
| 1611 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
| 1612 | 1612 | |
| 1613 | 1613 | /* TODO |
| 1614 | 1614 | if ( $is_valid && $vat_number ) { |
@@ -1619,38 +1619,38 @@ discard block |
||
| 1619 | 1619 | } |
| 1620 | 1620 | */ |
| 1621 | 1621 | |
| 1622 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
| 1622 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
| 1625 | + public static function get_user_company($company = '', $user_id = 0) { |
|
| 1626 | 1626 | global $wpi_current_id, $wpi_userID; |
| 1627 | 1627 | |
| 1628 | - if ( empty( $user_id ) ) { |
|
| 1629 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
| 1628 | + if (empty($user_id)) { |
|
| 1629 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
| 1630 | 1630 | } |
| 1631 | 1631 | |
| 1632 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
| 1632 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
| 1633 | 1633 | |
| 1634 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
| 1634 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
| 1638 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
| 1637 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
| 1638 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
| 1639 | 1639 | |
| 1640 | - if ( is_user_logged_in() && $save ) { |
|
| 1640 | + if (is_user_logged_in() && $save) { |
|
| 1641 | 1641 | $user_id = get_current_user_id(); |
| 1642 | 1642 | |
| 1643 | - if ( !empty( $vat_number ) ) { |
|
| 1644 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
| 1643 | + if (!empty($vat_number)) { |
|
| 1644 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
| 1645 | 1645 | } else { |
| 1646 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
| 1646 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | - if ( !empty( $company ) ) { |
|
| 1650 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
| 1649 | + if (!empty($company)) { |
|
| 1650 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
| 1651 | 1651 | } else { |
| 1652 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
| 1653 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
| 1652 | + delete_user_meta($user_id, '_wpinv_company'); |
|
| 1653 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
| 1654 | 1654 | } |
| 1655 | 1655 | } |
| 1656 | 1656 | |
@@ -1660,113 +1660,113 @@ discard block |
||
| 1660 | 1660 | public static function ajax_vat_validate() { |
| 1661 | 1661 | global $wpinv_options, $wpi_session; |
| 1662 | 1662 | |
| 1663 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
| 1663 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
| 1664 | 1664 | $response = array(); |
| 1665 | 1665 | $response['success'] = false; |
| 1666 | 1666 | |
| 1667 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
| 1668 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
| 1669 | - wp_send_json( $response ); |
|
| 1667 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
| 1668 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
| 1669 | + wp_send_json($response); |
|
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | - $vat_name = self::get_vat_name(); |
|
| 1672 | + $vat_name = self::get_vat_name(); |
|
| 1673 | 1673 | |
| 1674 | - if ( $is_checkout ) { |
|
| 1674 | + if ($is_checkout) { |
|
| 1675 | 1675 | $invoice = wpinv_get_invoice_cart(); |
| 1676 | 1676 | |
| 1677 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
| 1677 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
| 1678 | 1678 | $vat_info = array(); |
| 1679 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1679 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1680 | 1680 | |
| 1681 | 1681 | self::save_user_vat_details(); |
| 1682 | 1682 | |
| 1683 | 1683 | $response['success'] = true; |
| 1684 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
| 1685 | - wp_send_json( $response ); |
|
| 1684 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
| 1685 | + wp_send_json($response); |
|
| 1686 | 1686 | } |
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
| 1690 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
| 1689 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
| 1690 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
| 1691 | 1691 | |
| 1692 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1693 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
| 1694 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
| 1692 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1693 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
| 1694 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | - if ( empty( $vat_number ) ) { |
|
| 1698 | - if ( $is_checkout ) { |
|
| 1697 | + if (empty($vat_number)) { |
|
| 1698 | + if ($is_checkout) { |
|
| 1699 | 1699 | $response['success'] = true; |
| 1700 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
| 1700 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
| 1701 | 1701 | |
| 1702 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1702 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1703 | 1703 | $vat_info['number'] = ""; |
| 1704 | 1704 | $vat_info['valid'] = true; |
| 1705 | 1705 | |
| 1706 | - self::save_user_vat_details( $company ); |
|
| 1706 | + self::save_user_vat_details($company); |
|
| 1707 | 1707 | } else { |
| 1708 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
| 1708 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
| 1709 | 1709 | |
| 1710 | 1710 | $vat_info['valid'] = false; |
| 1711 | 1711 | } |
| 1712 | 1712 | |
| 1713 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1714 | - wp_send_json( $response ); |
|
| 1713 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1714 | + wp_send_json($response); |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | - if ( empty( $company ) ) { |
|
| 1717 | + if (empty($company)) { |
|
| 1718 | 1718 | $vat_info['valid'] = false; |
| 1719 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1719 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1720 | 1720 | |
| 1721 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
| 1722 | - wp_send_json( $response ); |
|
| 1721 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
| 1722 | + wp_send_json($response); |
|
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 1726 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
| 1725 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 1726 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
| 1727 | 1727 | $vat_info['valid'] = false; |
| 1728 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1728 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1729 | 1729 | |
| 1730 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 1731 | - wp_send_json( $response ); |
|
| 1730 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 1731 | + wp_send_json($response); |
|
| 1732 | 1732 | } |
| 1733 | 1733 | |
| 1734 | 1734 | $response['success'] = true; |
| 1735 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 1735 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 1736 | 1736 | } else { |
| 1737 | - $result = self::check_vat( $vat_number ); |
|
| 1737 | + $result = self::check_vat($vat_number); |
|
| 1738 | 1738 | |
| 1739 | - if ( empty( $result['valid'] ) ) { |
|
| 1739 | + if (empty($result['valid'])) { |
|
| 1740 | 1740 | $response['error'] = $result['message']; |
| 1741 | - wp_send_json( $response ); |
|
| 1741 | + wp_send_json($response); |
|
| 1742 | 1742 | } |
| 1743 | 1743 | |
| 1744 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
| 1745 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
| 1744 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
| 1745 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
| 1746 | 1746 | |
| 1747 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
| 1747 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
| 1748 | 1748 | |
| 1749 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
| 1749 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
| 1750 | 1750 | $response['success'] = true; |
| 1751 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 1751 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 1752 | 1752 | } else { |
| 1753 | 1753 | $vat_info['valid'] = false; |
| 1754 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1754 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1755 | 1755 | |
| 1756 | 1756 | $response['success'] = false; |
| 1757 | - $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
| 1758 | - wp_send_json( $response ); |
|
| 1757 | + $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
| 1758 | + wp_send_json($response); |
|
| 1759 | 1759 | } |
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | - if ( $is_checkout ) { |
|
| 1763 | - self::save_user_vat_details( $company, $vat_number ); |
|
| 1762 | + if ($is_checkout) { |
|
| 1763 | + self::save_user_vat_details($company, $vat_number); |
|
| 1764 | 1764 | |
| 1765 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
| 1766 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1765 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
| 1766 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1767 | 1767 | } |
| 1768 | 1768 | |
| 1769 | - wp_send_json( $response ); |
|
| 1769 | + wp_send_json($response); |
|
| 1770 | 1770 | } |
| 1771 | 1771 | |
| 1772 | 1772 | public static function ajax_vat_reset() { |
@@ -1775,161 +1775,161 @@ discard block |
||
| 1775 | 1775 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
| 1776 | 1776 | $vat_number = self::get_user_vat_number(); |
| 1777 | 1777 | |
| 1778 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
| 1779 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1778 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
| 1779 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1780 | 1780 | |
| 1781 | 1781 | $response = array(); |
| 1782 | 1782 | $response['success'] = true; |
| 1783 | 1783 | $response['data']['company'] = $company; |
| 1784 | 1784 | $response['data']['number'] = $vat_number; |
| 1785 | 1785 | |
| 1786 | - wp_send_json( $response ); |
|
| 1786 | + wp_send_json($response); |
|
| 1787 | 1787 | } |
| 1788 | 1788 | |
| 1789 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
| 1789 | + public static function checkout_vat_validate($valid_data, $post) { |
|
| 1790 | 1790 | global $wpinv_options, $wpi_session; |
| 1791 | 1791 | |
| 1792 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
| 1792 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
| 1793 | 1793 | |
| 1794 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
| 1795 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
| 1794 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
| 1795 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
| 1796 | 1796 | return; |
| 1797 | 1797 | } |
| 1798 | 1798 | |
| 1799 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
| 1800 | - $wpi_session->set( 'user_vat_data', null ); |
|
| 1799 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
| 1800 | + $wpi_session->set('user_vat_data', null); |
|
| 1801 | 1801 | |
| 1802 | 1802 | $invoice = wpinv_get_invoice_cart(); |
| 1803 | 1803 | $amount = $invoice->get_total(); |
| 1804 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
| 1805 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
| 1804 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
| 1805 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
| 1806 | 1806 | |
| 1807 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
| 1808 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
| 1809 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
| 1810 | - if ( empty( $country ) ) { |
|
| 1807 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
| 1808 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
| 1809 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
| 1810 | + if (empty($country)) { |
|
| 1811 | 1811 | $country = wpinv_default_billing_country(); |
| 1812 | 1812 | } |
| 1813 | 1813 | |
| 1814 | - if ( !$is_digital && $no_vat ) { |
|
| 1814 | + if (!$is_digital && $no_vat) { |
|
| 1815 | 1815 | return; |
| 1816 | 1816 | } |
| 1817 | 1817 | |
| 1818 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
| 1818 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
| 1819 | 1819 | |
| 1820 | 1820 | $ip_country_code = self::get_country_by_ip(); |
| 1821 | - $is_eu_state = self::is_eu_state( $country ); |
|
| 1822 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
| 1821 | + $is_eu_state = self::is_eu_state($country); |
|
| 1822 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
| 1823 | 1823 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
| 1824 | 1824 | |
| 1825 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
| 1825 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
| 1826 | 1826 | $vat_data['adddress_confirmed'] = false; |
| 1827 | 1827 | |
| 1828 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
| 1829 | - if ( $ip_country_code != $country ) { |
|
| 1830 | - wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) ); |
|
| 1828 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
| 1829 | + if ($ip_country_code != $country) { |
|
| 1830 | + wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>')); |
|
| 1831 | 1831 | } |
| 1832 | 1832 | } else { |
| 1833 | 1833 | $vat_data['adddress_confirmed'] = true; |
| 1834 | 1834 | } |
| 1835 | 1835 | } |
| 1836 | 1836 | |
| 1837 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
| 1838 | - if ( $is_eu_state ) { |
|
| 1839 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) ); |
|
| 1840 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
| 1841 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
| 1837 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
| 1838 | + if ($is_eu_state) { |
|
| 1839 | + wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name)); |
|
| 1840 | + } else if ($is_digital && $is_eu_state_ip) { |
|
| 1841 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
| 1842 | 1842 | } |
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
| 1845 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
| 1846 | 1846 | return; |
| 1847 | 1847 | } |
| 1848 | 1848 | |
| 1849 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
| 1850 | - $vat_data['valid'] = $vat_saved['valid']; |
|
| 1849 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
| 1850 | + $vat_data['valid'] = $vat_saved['valid']; |
|
| 1851 | 1851 | } |
| 1852 | 1852 | |
| 1853 | - if ( $company !== null ) { |
|
| 1853 | + if ($company !== null) { |
|
| 1854 | 1854 | $vat_data['company'] = $company; |
| 1855 | 1855 | } |
| 1856 | 1856 | |
| 1857 | 1857 | $message = ''; |
| 1858 | - if ( $vat_number !== null ) { |
|
| 1858 | + if ($vat_number !== null) { |
|
| 1859 | 1859 | $vat_data['number'] = $vat_number; |
| 1860 | 1860 | |
| 1861 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
| 1862 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 1863 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
| 1861 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
| 1862 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 1863 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
| 1864 | 1864 | $vat_data['valid'] = false; |
| 1865 | 1865 | } |
| 1866 | 1866 | } else { |
| 1867 | - $result = self::check_vat( $vat_number ); |
|
| 1867 | + $result = self::check_vat($vat_number); |
|
| 1868 | 1868 | |
| 1869 | - if ( !empty( $result['valid'] ) ) { |
|
| 1869 | + if (!empty($result['valid'])) { |
|
| 1870 | 1870 | $vat_data['valid'] = true; |
| 1871 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
| 1872 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
| 1871 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
| 1872 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
| 1873 | 1873 | |
| 1874 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
| 1874 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
| 1875 | 1875 | |
| 1876 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
| 1876 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
| 1877 | 1877 | $vat_data['valid'] = false; |
| 1878 | 1878 | |
| 1879 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
| 1879 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
| 1880 | 1880 | } |
| 1881 | 1881 | } else { |
| 1882 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
| 1882 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
| 1883 | 1883 | } |
| 1884 | 1884 | } |
| 1885 | 1885 | |
| 1886 | - if ( !$vat_data['valid'] ) { |
|
| 1887 | - $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' ); |
|
| 1888 | - wpinv_set_error( 'vat_validation', $error ); |
|
| 1886 | + if (!$vat_data['valid']) { |
|
| 1887 | + $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : ''); |
|
| 1888 | + wpinv_set_error('vat_validation', $error); |
|
| 1889 | 1889 | } |
| 1890 | 1890 | } |
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
| 1893 | + $wpi_session->set('user_vat_data', $vat_data); |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | - public static function checkout_vat_fields( $billing_details ) { |
|
| 1896 | + public static function checkout_vat_fields($billing_details) { |
|
| 1897 | 1897 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
| 1898 | 1898 | |
| 1899 | 1899 | $ip_address = wpinv_get_ip(); |
| 1900 | 1900 | $ip_country_code = self::get_country_by_ip(); |
| 1901 | 1901 | |
| 1902 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
| 1902 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
| 1903 | 1903 | $invoice = wpinv_get_invoice_cart(); |
| 1904 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
| 1904 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
| 1905 | 1905 | $wpi_country = $invoice->country; |
| 1906 | 1906 | |
| 1907 | - $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital ); |
|
| 1907 | + $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital); |
|
| 1908 | 1908 | $wpi_requires_vat = $requires_vat; |
| 1909 | 1909 | |
| 1910 | 1910 | $company = self::get_user_company(); |
| 1911 | 1911 | $vat_number = self::get_user_vat_number(); |
| 1912 | 1912 | |
| 1913 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
| 1914 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1913 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
| 1914 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1915 | 1915 | |
| 1916 | - if ( is_array( $vat_info ) ) { |
|
| 1917 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
| 1918 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
| 1919 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
| 1916 | + if (is_array($vat_info)) { |
|
| 1917 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
| 1918 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
| 1919 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
| 1920 | 1920 | } |
| 1921 | 1921 | |
| 1922 | 1922 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
| 1923 | 1923 | |
| 1924 | - if ( $ip_country_code == 'UK' ) { |
|
| 1924 | + if ($ip_country_code == 'UK') { |
|
| 1925 | 1925 | $ip_country_code = 'GB'; |
| 1926 | 1926 | } |
| 1927 | 1927 | |
| 1928 | - if ( $selected_country == 'UK' ) { |
|
| 1928 | + if ($selected_country == 'UK') { |
|
| 1929 | 1929 | $selected_country = 'GB'; |
| 1930 | 1930 | } |
| 1931 | 1931 | |
| 1932 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
| 1932 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
| 1933 | 1933 | $requires_vat = false; |
| 1934 | 1934 | } |
| 1935 | 1935 | |
@@ -1937,52 +1937,52 @@ discard block |
||
| 1937 | 1937 | $display_validate_btn = 'none'; |
| 1938 | 1938 | $display_reset_btn = 'none'; |
| 1939 | 1939 | |
| 1940 | - if ( !empty( $vat_number ) && $validated ) { |
|
| 1941 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
| 1940 | + if (!empty($vat_number) && $validated) { |
|
| 1941 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
| 1942 | 1942 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
| 1943 | 1943 | $display_reset_btn = 'block'; |
| 1944 | 1944 | } else { |
| 1945 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
| 1946 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
| 1945 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
| 1946 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
| 1947 | 1947 | $display_validate_btn = 'block'; |
| 1948 | 1948 | } |
| 1949 | 1949 | |
| 1950 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
| 1950 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
| 1951 | 1951 | ?> |
| 1952 | 1952 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
| 1953 | 1953 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
| 1954 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
| 1954 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
| 1955 | 1955 | <div id="wpinv-fields-box" class="panel-body"> |
| 1956 | 1956 | <p id="wpi_show_vat_note"> |
| 1957 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
| 1957 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
| 1958 | 1958 | </p> |
| 1959 | 1959 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
| 1960 | 1960 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1961 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
| 1961 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
| 1962 | 1962 | <?php |
| 1963 | - echo wpinv_html_text( array( |
|
| 1963 | + echo wpinv_html_text(array( |
|
| 1964 | 1964 | 'id' => 'wpinv_company', |
| 1965 | 1965 | 'name' => 'wpinv_company', |
| 1966 | 1966 | 'value' => $company, |
| 1967 | 1967 | 'class' => 'wpi-input form-control', |
| 1968 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
| 1969 | - ) ); |
|
| 1968 | + 'placeholder' => __('Company name', 'invoicing'), |
|
| 1969 | + )); |
|
| 1970 | 1970 | ?> |
| 1971 | 1971 | </p> |
| 1972 | 1972 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
| 1973 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
| 1973 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
| 1974 | 1974 | <span id="wpinv_vat_number-wrap"> |
| 1975 | 1975 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
| 1976 | - <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
| 1977 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
| 1976 | + <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
| 1977 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
| 1978 | 1978 | </span> |
| 1979 | 1979 | </p> |
| 1980 | 1980 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
| 1981 | - <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button> |
|
| 1982 | - <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button> |
|
| 1981 | + <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button> |
|
| 1982 | + <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button> |
|
| 1983 | 1983 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
| 1984 | 1984 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
| 1985 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
| 1985 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
| 1986 | 1986 | </p> |
| 1987 | 1987 | </div> |
| 1988 | 1988 | </div> |
@@ -1996,32 +1996,32 @@ discard block |
||
| 1996 | 1996 | </span> |
| 1997 | 1997 | </div> |
| 1998 | 1998 | </div> |
| 1999 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
| 2000 | - $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
| 1999 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
| 2000 | + $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
| 2001 | 2001 | ?> |
| 2002 | 2002 | <div class="wpi-ip-info clearfix panel panel-info"> |
| 2003 | 2003 | <div id="wpinv-fields-box" class="panel-body"> |
| 2004 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
| 2004 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
| 2005 | 2005 | </div> |
| 2006 | 2006 | </div> |
| 2007 | 2007 | <?php } |
| 2008 | 2008 | } |
| 2009 | 2009 | |
| 2010 | - public static function show_vat_notice( $invoice ) { |
|
| 2011 | - if ( empty( $invoice ) ) { |
|
| 2010 | + public static function show_vat_notice($invoice) { |
|
| 2011 | + if (empty($invoice)) { |
|
| 2012 | 2012 | return NULL; |
| 2013 | 2013 | } |
| 2014 | 2014 | |
| 2015 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
| 2016 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
| 2017 | - if ( $label || $notice ) { |
|
| 2015 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
| 2016 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
| 2017 | + if ($label || $notice) { |
|
| 2018 | 2018 | ?> |
| 2019 | 2019 | <div class="row wpinv-vat-notice"> |
| 2020 | 2020 | <div class="col-sm-12"> |
| 2021 | - <?php if ( $label ) { ?> |
|
| 2022 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
| 2023 | - <?php } if ( $notice ) { ?> |
|
| 2024 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
| 2021 | + <?php if ($label) { ?> |
|
| 2022 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
| 2023 | + <?php } if ($notice) { ?> |
|
| 2024 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
| 2025 | 2025 | <?php } ?> |
| 2026 | 2026 | </div> |
| 2027 | 2027 | </div> |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | -if ( ! class_exists( 'WP_Super_Duper' ) ) { |
|
| 6 | +if (!class_exists('WP_Super_Duper')) { |
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | /** |
@@ -39,27 +39,27 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * Take the array options and use them to build. |
| 41 | 41 | */ |
| 42 | - public function __construct( $options ) { |
|
| 42 | + public function __construct($options) { |
|
| 43 | 43 | global $sd_widgets; |
| 44 | 44 | |
| 45 | - $sd_widgets[ $options['base_id'] ] = array( |
|
| 45 | + $sd_widgets[$options['base_id']] = array( |
|
| 46 | 46 | 'name' => $options['name'], |
| 47 | 47 | 'class_name' => $options['class_name'] |
| 48 | 48 | ); |
| 49 | - $this->base_id = $options['base_id']; |
|
| 49 | + $this->base_id = $options['base_id']; |
|
| 50 | 50 | // lets filter the options before we do anything |
| 51 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 52 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 53 | - $options = $this->add_name_from_key( $options ); |
|
| 51 | + $options = apply_filters("wp_super_duper_options", $options); |
|
| 52 | + $options = apply_filters("wp_super_duper_options_{$this->base_id}", $options); |
|
| 53 | + $options = $this->add_name_from_key($options); |
|
| 54 | 54 | $this->options = $options; |
| 55 | 55 | |
| 56 | 56 | $this->base_id = $options['base_id']; |
| 57 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 57 | + $this->arguments = isset($options['arguments']) ? $options['arguments'] : array(); |
|
| 58 | 58 | |
| 59 | 59 | // init parent |
| 60 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 60 | + parent::__construct($options['base_id'], $options['name'], $options['widget_ops']); |
|
| 61 | 61 | |
| 62 | - if ( isset( $options['class_name'] ) ) { |
|
| 62 | + if (isset($options['class_name'])) { |
|
| 63 | 63 | // register widget |
| 64 | 64 | $this->class_name = $options['class_name']; |
| 65 | 65 | |
@@ -67,47 +67,47 @@ discard block |
||
| 67 | 67 | $this->register_shortcode(); |
| 68 | 68 | |
| 69 | 69 | // register block |
| 70 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 70 | + add_action('admin_enqueue_scripts', array($this, 'register_block')); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // add the CSS and JS we need ONCE |
| 74 | 74 | global $sd_widget_scripts; |
| 75 | 75 | |
| 76 | - if ( ! $sd_widget_scripts ) { |
|
| 77 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 78 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 79 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 76 | + if (!$sd_widget_scripts) { |
|
| 77 | + wp_add_inline_script('admin-widgets', $this->widget_js()); |
|
| 78 | + wp_add_inline_script('customize-controls', $this->widget_js()); |
|
| 79 | + wp_add_inline_style('widgets', $this->widget_css()); |
|
| 80 | 80 | |
| 81 | 81 | $sd_widget_scripts = true; |
| 82 | 82 | |
| 83 | 83 | // add shortcode insert button once |
| 84 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 85 | - if ( $this->is_preview() ) { |
|
| 86 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 84 | + add_action('media_buttons', array($this, 'shortcode_insert_button')); |
|
| 85 | + if ($this->is_preview()) { |
|
| 86 | + add_action('wp_footer', array($this, 'shortcode_insert_button_script')); |
|
| 87 | 87 | // this makes the insert button work for elementor |
| 88 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 88 | + add_action('elementor/editor/after_enqueue_scripts', array( |
|
| 89 | 89 | $this, |
| 90 | 90 | 'shortcode_insert_button_script' |
| 91 | - ) ); // for elementor |
|
| 91 | + )); // for elementor |
|
| 92 | 92 | } |
| 93 | 93 | // this makes the insert button work for cornerstone |
| 94 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
| 94 | + add_action('wp_print_footer_scripts', array(__CLASS__, 'maybe_cornerstone_builder')); |
|
| 95 | 95 | |
| 96 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 97 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 96 | + add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings')); |
|
| 97 | + add_action('wp_ajax_super_duper_get_picker', array(__CLASS__, 'get_picker')); |
|
| 98 | 98 | |
| 99 | 99 | // add generator text to admin head |
| 100 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 100 | + add_action('admin_head', array($this, 'generator')); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 103 | + do_action('wp_super_duper_widget_init', $options, $this); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | 107 | * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
| 108 | 108 | */ |
| 109 | - public static function maybe_cornerstone_builder(){ |
|
| 110 | - if(did_action('cornerstone_before_boot_app')){ |
|
| 109 | + public static function maybe_cornerstone_builder() { |
|
| 110 | + if (did_action('cornerstone_before_boot_app')) { |
|
| 111 | 111 | self::shortcode_insert_button_script(); |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | * @return string |
| 121 | 121 | */ |
| 122 | - public static function get_picker( $editor_id = '' ) { |
|
| 122 | + public static function get_picker($editor_id = '') { |
|
| 123 | 123 | |
| 124 | 124 | ob_start(); |
| 125 | - if ( isset( $_POST['editor_id'] ) ) { |
|
| 126 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 127 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 125 | + if (isset($_POST['editor_id'])) { |
|
| 126 | + $editor_id = esc_attr($_POST['editor_id']); |
|
| 127 | + } elseif (isset($_REQUEST['et_fb'])) { |
|
| 128 | 128 | $editor_id = 'main_content_content_vb_tiny_mce'; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -133,12 +133,12 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | <div class="sd-shortcode-left-wrap"> |
| 135 | 135 | <?php |
| 136 | - asort( $sd_widgets ); |
|
| 137 | - if ( ! empty( $sd_widgets ) ) { |
|
| 136 | + asort($sd_widgets); |
|
| 137 | + if (!empty($sd_widgets)) { |
|
| 138 | 138 | echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
| 139 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 140 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 141 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 139 | + echo "<option>" . __('Select shortcode') . "</option>"; |
|
| 140 | + foreach ($sd_widgets as $shortcode => $class) { |
|
| 141 | + echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>"; |
|
| 142 | 142 | } |
| 143 | 143 | echo "</select>"; |
| 144 | 144 | |
@@ -151,37 +151,37 @@ discard block |
||
| 151 | 151 | <div class="sd-shortcode-right-wrap"> |
| 152 | 152 | <textarea id='sd-shortcode-output' disabled></textarea> |
| 153 | 153 | <div id='sd-shortcode-output-actions'> |
| 154 | - <?php if ( $editor_id != '' ) { ?> |
|
| 154 | + <?php if ($editor_id != '') { ?> |
|
| 155 | 155 | <button class="button sd-insert-shortcode-button" |
| 156 | - onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
|
| 156 | + onclick="sd_insert_shortcode(<?php if (!empty($editor_id)) { |
|
| 157 | 157 | echo "'" . $editor_id . "'"; |
| 158 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 158 | + } ?>)"><?php _e('Insert shortcode'); ?></button> |
|
| 159 | 159 | <?php } ?> |
| 160 | 160 | <button class="button" |
| 161 | - onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
|
| 161 | + onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button> |
|
| 162 | 162 | </div> |
| 163 | 163 | </div> |
| 164 | 164 | <?php |
| 165 | 165 | |
| 166 | 166 | $html = ob_get_clean(); |
| 167 | 167 | |
| 168 | - if ( wp_doing_ajax() ) { |
|
| 168 | + if (wp_doing_ajax()) { |
|
| 169 | 169 | echo $html; |
| 170 | 170 | $should_die = true; |
| 171 | 171 | |
| 172 | 172 | // some builder get the editor via ajax so we should not die on those ocasions |
| 173 | 173 | $dont_die = array( |
| 174 | - 'parent_tag',// WP Bakery |
|
| 174 | + 'parent_tag', // WP Bakery |
|
| 175 | 175 | 'avia_request' // enfold |
| 176 | 176 | ); |
| 177 | 177 | |
| 178 | - foreach ( $dont_die as $request ) { |
|
| 179 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 178 | + foreach ($dont_die as $request) { |
|
| 179 | + if (isset($_REQUEST[$request])) { |
|
| 180 | 180 | $should_die = false; |
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if ( $should_die ) { |
|
| 184 | + if ($should_die) { |
|
| 185 | 185 | wp_die(); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -208,16 +208,16 @@ discard block |
||
| 208 | 208 | public static function get_widget_settings() { |
| 209 | 209 | global $sd_widgets; |
| 210 | 210 | |
| 211 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 212 | - if ( ! $shortcode ) { |
|
| 211 | + $shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : ''; |
|
| 212 | + if (!$shortcode) { |
|
| 213 | 213 | wp_die(); |
| 214 | 214 | } |
| 215 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 216 | - if ( ! $widget_args ) { |
|
| 215 | + $widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : ''; |
|
| 216 | + if (!$widget_args) { |
|
| 217 | 217 | wp_die(); |
| 218 | 218 | } |
| 219 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 220 | - if ( ! $class_name ) { |
|
| 219 | + $class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 220 | + if (!$class_name) { |
|
| 221 | 221 | wp_die(); |
| 222 | 222 | } |
| 223 | 223 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $widget = new $class_name; |
| 226 | 226 | |
| 227 | 227 | ob_start(); |
| 228 | - $widget->form( array() ); |
|
| 228 | + $widget->form(array()); |
|
| 229 | 229 | $form = ob_get_clean(); |
| 230 | 230 | echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
| 231 | 231 | echo "<style>" . $widget->widget_css() . "</style>"; |
@@ -243,9 +243,9 @@ discard block |
||
| 243 | 243 | * @param string $editor_id Optional. Shortcode editor id. Default null. |
| 244 | 244 | * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
| 245 | 245 | */ |
| 246 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 246 | + public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') { |
|
| 247 | 247 | global $sd_widgets, $shortcode_insert_button_once; |
| 248 | - if ( $shortcode_insert_button_once ) { |
|
| 248 | + if ($shortcode_insert_button_once) { |
|
| 249 | 249 | return; |
| 250 | 250 | } |
| 251 | 251 | add_thickbox(); |
@@ -255,18 +255,18 @@ discard block |
||
| 255 | 255 | * Cornerstone makes us play dirty tricks :/ |
| 256 | 256 | * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
| 257 | 257 | */ |
| 258 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 258 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
| 259 | 259 | echo '<span id="insert-media-button">'; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - echo self::shortcode_button( 'this', 'true' ); |
|
| 262 | + echo self::shortcode_button('this', 'true'); |
|
| 263 | 263 | |
| 264 | 264 | // see opening note |
| 265 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 265 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
| 266 | 266 | echo '</span>'; // end #insert-media-button |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 269 | + self::shortcode_insert_button_script($editor_id, $insert_shortcode_function); |
|
| 270 | 270 | $shortcode_insert_button_once = true; |
| 271 | 271 | } |
| 272 | 272 | |
@@ -278,12 +278,12 @@ discard block |
||
| 278 | 278 | * |
| 279 | 279 | * @return mixed |
| 280 | 280 | */ |
| 281 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 281 | + public static function shortcode_button($id = '', $search_for_id = '') { |
|
| 282 | 282 | ob_start(); |
| 283 | 283 | ?> |
| 284 | 284 | <span class="sd-lable-shortcode-inserter"> |
| 285 | 285 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
| 286 | - if ( $search_for_id ) { |
|
| 286 | + if ($search_for_id) { |
|
| 287 | 287 | echo "," . $search_for_id; |
| 288 | 288 | } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
| 289 | 289 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | $html = ob_get_clean(); |
| 300 | 300 | |
| 301 | 301 | // remove line breaks so we can use it in js |
| 302 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 302 | + return preg_replace("/\r|\n/", "", trim($html)); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | jQuery($this).data('sd-widget-enabled', true); |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
| 360 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
| 361 | 361 | var form = jQuery($this).parents('' + $selector + ''); |
| 362 | 362 | |
| 363 | 363 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -394,10 +394,10 @@ discard block |
||
| 394 | 394 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 395 | 395 | */ |
| 396 | 396 | |
| 397 | - return str_replace( array( |
|
| 397 | + return str_replace(array( |
|
| 398 | 398 | '<script>', |
| 399 | 399 | '</script>' |
| 400 | - ), '', $output ); |
|
| 400 | + ), '', $output); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * @param string $editor_id |
| 409 | 409 | * @param string $insert_shortcode_function |
| 410 | 410 | */ |
| 411 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 411 | + public static function shortcode_insert_button_script($editor_id = '', $insert_shortcode_function = '') { |
|
| 412 | 412 | ?> |
| 413 | 413 | <style> |
| 414 | 414 | .sd-shortcode-left-wrap { |
@@ -528,15 +528,15 @@ discard block |
||
| 528 | 528 | } |
| 529 | 529 | </style> |
| 530 | 530 | <?php |
| 531 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 531 | + if (class_exists('SiteOrigin_Panels')) { |
|
| 532 | 532 | echo "<script>" . self::siteorigin_js() . "</script>"; |
| 533 | 533 | } |
| 534 | 534 | ?> |
| 535 | 535 | <script> |
| 536 | 536 | <?php |
| 537 | - if(! empty( $insert_shortcode_function )){ |
|
| 537 | + if (!empty($insert_shortcode_function)) { |
|
| 538 | 538 | echo $insert_shortcode_function; |
| 539 | - }else{ |
|
| 539 | + } else { |
|
| 540 | 540 | |
| 541 | 541 | /** |
| 542 | 542 | * Function for super duper insert shortcode. |
@@ -551,9 +551,9 @@ discard block |
||
| 551 | 551 | if (!$editor_id) { |
| 552 | 552 | |
| 553 | 553 | <?php |
| 554 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 554 | + if (isset($_REQUEST['et_fb'])) { |
|
| 555 | 555 | echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
| 556 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 556 | + } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') { |
|
| 557 | 557 | echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
| 558 | 558 | } else { |
| 559 | 559 | echo '$editor_id = "#wp-content-editor-container textarea";'; |
@@ -633,11 +633,11 @@ discard block |
||
| 633 | 633 | 'shortcode': $short_code, |
| 634 | 634 | 'attributes': 123, |
| 635 | 635 | 'post_id': 321, |
| 636 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 636 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 637 | 637 | }; |
| 638 | 638 | |
| 639 | 639 | if (typeof ajaxurl === 'undefined') { |
| 640 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' );?>"; |
|
| 640 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | jQuery.post(ajaxurl, data, function (response) { |
@@ -835,11 +835,11 @@ discard block |
||
| 835 | 835 | var data = { |
| 836 | 836 | 'action': 'super_duper_get_picker', |
| 837 | 837 | 'editor_id': $id, |
| 838 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_picker' );?>' |
|
| 838 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_picker'); ?>' |
|
| 839 | 839 | }; |
| 840 | 840 | |
| 841 | 841 | if (!ajaxurl) { |
| 842 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>"; |
|
| 842 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | jQuery.post(ajaxurl, data, function (response) { |
@@ -860,9 +860,9 @@ discard block |
||
| 860 | 860 | */ |
| 861 | 861 | function sd_shortcode_button($id) { |
| 862 | 862 | if ($id) { |
| 863 | - return '<?php echo self::shortcode_button( "\\''+\$id+'\\'" );?>'; |
|
| 863 | + return '<?php echo self::shortcode_button("\\''+\$id+'\\'"); ?>'; |
|
| 864 | 864 | } else { |
| 865 | - return '<?php echo self::shortcode_button();?>'; |
|
| 865 | + return '<?php echo self::shortcode_button(); ?>'; |
|
| 866 | 866 | } |
| 867 | 867 | } |
| 868 | 868 | |
@@ -904,10 +904,10 @@ discard block |
||
| 904 | 904 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 905 | 905 | */ |
| 906 | 906 | |
| 907 | - return str_replace( array( |
|
| 907 | + return str_replace(array( |
|
| 908 | 908 | '<style>', |
| 909 | 909 | '</style>' |
| 910 | - ), '', $output ); |
|
| 910 | + ), '', $output); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | jQuery($this).data('sd-widget-enabled', true); |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
| 980 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
| 981 | 981 | var form = jQuery($this).parents('' + $selector + ''); |
| 982 | 982 | |
| 983 | 983 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | }); |
| 1070 | 1070 | |
| 1071 | 1071 | } |
| 1072 | - <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
| 1072 | + <?php do_action('wp_super_duper_widget_js', $this); ?> |
|
| 1073 | 1073 | </script> |
| 1074 | 1074 | <?php |
| 1075 | 1075 | $output = ob_get_clean(); |
@@ -1078,10 +1078,10 @@ discard block |
||
| 1078 | 1078 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1079 | 1079 | */ |
| 1080 | 1080 | |
| 1081 | - return str_replace( array( |
|
| 1081 | + return str_replace(array( |
|
| 1082 | 1082 | '<script>', |
| 1083 | 1083 | '</script>' |
| 1084 | - ), '', $output ); |
|
| 1084 | + ), '', $output); |
|
| 1085 | 1085 | } |
| 1086 | 1086 | |
| 1087 | 1087 | |
@@ -1092,14 +1092,14 @@ discard block |
||
| 1092 | 1092 | * |
| 1093 | 1093 | * @return mixed |
| 1094 | 1094 | */ |
| 1095 | - private function add_name_from_key( $options, $arguments = false ) { |
|
| 1096 | - if ( ! empty( $options['arguments'] ) ) { |
|
| 1097 | - foreach ( $options['arguments'] as $key => $val ) { |
|
| 1098 | - $options['arguments'][ $key ]['name'] = $key; |
|
| 1095 | + private function add_name_from_key($options, $arguments = false) { |
|
| 1096 | + if (!empty($options['arguments'])) { |
|
| 1097 | + foreach ($options['arguments'] as $key => $val) { |
|
| 1098 | + $options['arguments'][$key]['name'] = $key; |
|
| 1099 | 1099 | } |
| 1100 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1101 | - foreach ( $options as $key => $val ) { |
|
| 1102 | - $options[ $key ]['name'] = $key; |
|
| 1100 | + } elseif ($arguments && is_array($options) && !empty($options)) { |
|
| 1101 | + foreach ($options as $key => $val) { |
|
| 1102 | + $options[$key]['name'] = $key; |
|
| 1103 | 1103 | } |
| 1104 | 1104 | } |
| 1105 | 1105 | |
@@ -1112,8 +1112,8 @@ discard block |
||
| 1112 | 1112 | * @since 1.0.0 |
| 1113 | 1113 | */ |
| 1114 | 1114 | public function register_shortcode() { |
| 1115 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1116 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1115 | + add_shortcode($this->base_id, array($this, 'shortcode_output')); |
|
| 1116 | + add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode')); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | /** |
@@ -1123,33 +1123,33 @@ discard block |
||
| 1123 | 1123 | */ |
| 1124 | 1124 | public static function render_shortcode() { |
| 1125 | 1125 | |
| 1126 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1127 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1126 | + check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true); |
|
| 1127 | + if (!current_user_can('manage_options')) { |
|
| 1128 | 1128 | wp_die(); |
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | // we might need the $post value here so lets set it. |
| 1132 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1133 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1134 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1132 | + if (isset($_POST['post_id']) && $_POST['post_id']) { |
|
| 1133 | + $post_obj = get_post(absint($_POST['post_id'])); |
|
| 1134 | + if (!empty($post_obj) && empty($post)) { |
|
| 1135 | 1135 | global $post; |
| 1136 | 1136 | $post = $post_obj; |
| 1137 | 1137 | } |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1141 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1142 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1140 | + if (isset($_POST['shortcode']) && $_POST['shortcode']) { |
|
| 1141 | + $shortcode_name = sanitize_title_with_dashes($_POST['shortcode']); |
|
| 1142 | + $attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1143 | 1143 | $attributes = ''; |
| 1144 | - if ( ! empty( $attributes_array ) ) { |
|
| 1145 | - foreach ( $attributes_array as $key => $value ) { |
|
| 1146 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1144 | + if (!empty($attributes_array)) { |
|
| 1145 | + foreach ($attributes_array as $key => $value) { |
|
| 1146 | + $attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' "; |
|
| 1147 | 1147 | } |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
| 1151 | 1151 | |
| 1152 | - echo do_shortcode( $shortcode ); |
|
| 1152 | + echo do_shortcode($shortcode); |
|
| 1153 | 1153 | |
| 1154 | 1154 | } |
| 1155 | 1155 | wp_die(); |
@@ -1163,37 +1163,37 @@ discard block |
||
| 1163 | 1163 | * |
| 1164 | 1164 | * @return string |
| 1165 | 1165 | */ |
| 1166 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1167 | - $args = self::argument_values( $args ); |
|
| 1166 | + public function shortcode_output($args = array(), $content = '') { |
|
| 1167 | + $args = self::argument_values($args); |
|
| 1168 | 1168 | |
| 1169 | 1169 | // add extra argument so we know its a output to gutenberg |
| 1170 | 1170 | //$args |
| 1171 | - $args = $this->string_to_bool( $args ); |
|
| 1171 | + $args = $this->string_to_bool($args); |
|
| 1172 | 1172 | |
| 1173 | 1173 | |
| 1174 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1174 | + $calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : ''; |
|
| 1175 | 1175 | |
| 1176 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
| 1177 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
| 1176 | + $calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this); |
|
| 1177 | + $calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this); |
|
| 1178 | 1178 | |
| 1179 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1180 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
| 1179 | + $attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this); |
|
| 1180 | + $attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this); |
|
| 1181 | 1181 | |
| 1182 | 1182 | $shortcode_args = array(); |
| 1183 | 1183 | $output = ''; |
| 1184 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1185 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1186 | - if ( $main_content && ! $no_wrap ) { |
|
| 1184 | + $no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false; |
|
| 1185 | + $main_content = $this->output($args, $shortcode_args, $content); |
|
| 1186 | + if ($main_content && !$no_wrap) { |
|
| 1187 | 1187 | // wrap the shortcode in a dive with the same class as the widget |
| 1188 | 1188 | $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
| 1189 | - if ( ! empty( $args['title'] ) ) { |
|
| 1189 | + if (!empty($args['title'])) { |
|
| 1190 | 1190 | // if its a shortcode and there is a title try to grab the title wrappers |
| 1191 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1192 | - if ( empty( $instance ) ) { |
|
| 1191 | + $shortcode_args = array('before_title' => '', 'after_title' => ''); |
|
| 1192 | + if (empty($instance)) { |
|
| 1193 | 1193 | global $wp_registered_sidebars; |
| 1194 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1195 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1196 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1194 | + if (!empty($wp_registered_sidebars)) { |
|
| 1195 | + foreach ($wp_registered_sidebars as $sidebar) { |
|
| 1196 | + if (!empty($sidebar['before_title'])) { |
|
| 1197 | 1197 | $shortcode_args['before_title'] = $sidebar['before_title']; |
| 1198 | 1198 | $shortcode_args['after_title'] = $sidebar['after_title']; |
| 1199 | 1199 | break; |
@@ -1201,17 +1201,17 @@ discard block |
||
| 1201 | 1201 | } |
| 1202 | 1202 | } |
| 1203 | 1203 | } |
| 1204 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1204 | + $output .= $this->output_title($shortcode_args, $args); |
|
| 1205 | 1205 | } |
| 1206 | 1206 | $output .= $main_content; |
| 1207 | 1207 | $output .= '</div>'; |
| 1208 | - } elseif ( $main_content && $no_wrap ) { |
|
| 1208 | + } elseif ($main_content && $no_wrap) { |
|
| 1209 | 1209 | $output .= $main_content; |
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | // if preview show a placeholder if empty |
| 1213 | - if ( $this->is_preview() && $output == '' ) { |
|
| 1214 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
| 1213 | + if ($this->is_preview() && $output == '') { |
|
| 1214 | + $output = $this->preview_placeholder_text("[{" . $this->base_id . "}]"); |
|
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | 1217 | return $output; |
@@ -1224,8 +1224,8 @@ discard block |
||
| 1224 | 1224 | * |
| 1225 | 1225 | * @return string |
| 1226 | 1226 | */ |
| 1227 | - public function preview_placeholder_text( $name = '' ) { |
|
| 1228 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1227 | + public function preview_placeholder_text($name = '') { |
|
| 1228 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf(__('Placeholder for: %s'), $name) . "</div>"; |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1235,13 +1235,13 @@ discard block |
||
| 1235 | 1235 | * |
| 1236 | 1236 | * @return mixed |
| 1237 | 1237 | */ |
| 1238 | - public function string_to_bool( $options ) { |
|
| 1238 | + public function string_to_bool($options) { |
|
| 1239 | 1239 | // convert bool strings to booleans |
| 1240 | - foreach ( $options as $key => $val ) { |
|
| 1241 | - if ( $val == 'false' ) { |
|
| 1242 | - $options[ $key ] = false; |
|
| 1243 | - } elseif ( $val == 'true' ) { |
|
| 1244 | - $options[ $key ] = true; |
|
| 1240 | + foreach ($options as $key => $val) { |
|
| 1241 | + if ($val == 'false') { |
|
| 1242 | + $options[$key] = false; |
|
| 1243 | + } elseif ($val == 'true') { |
|
| 1244 | + $options[$key] = true; |
|
| 1245 | 1245 | } |
| 1246 | 1246 | } |
| 1247 | 1247 | |
@@ -1257,27 +1257,27 @@ discard block |
||
| 1257 | 1257 | * |
| 1258 | 1258 | * @return array |
| 1259 | 1259 | */ |
| 1260 | - public function argument_values( $instance ) { |
|
| 1260 | + public function argument_values($instance) { |
|
| 1261 | 1261 | $argument_values = array(); |
| 1262 | 1262 | |
| 1263 | 1263 | // set widget instance |
| 1264 | 1264 | $this->instance = $instance; |
| 1265 | 1265 | |
| 1266 | - if ( empty( $this->arguments ) ) { |
|
| 1266 | + if (empty($this->arguments)) { |
|
| 1267 | 1267 | $this->arguments = $this->get_arguments(); |
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | - if ( ! empty( $this->arguments ) ) { |
|
| 1271 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1270 | + if (!empty($this->arguments)) { |
|
| 1271 | + foreach ($this->arguments as $key => $args) { |
|
| 1272 | 1272 | // set the input name from the key |
| 1273 | 1273 | $args['name'] = $key; |
| 1274 | 1274 | // |
| 1275 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1276 | - if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
| 1275 | + $argument_values[$key] = isset($instance[$key]) ? $instance[$key] : ''; |
|
| 1276 | + if ($args['type'] == 'checkbox' && $argument_values[$key] == '') { |
|
| 1277 | 1277 | // don't set default for an empty checkbox |
| 1278 | 1278 | } |
| 1279 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1280 | - $argument_values[ $key ] = $args['default']; |
|
| 1279 | + elseif ($argument_values[$key] == '' && isset($args['default'])) { |
|
| 1280 | + $argument_values[$key] = $args['default']; |
|
| 1281 | 1281 | } |
| 1282 | 1282 | } |
| 1283 | 1283 | } |
@@ -1304,12 +1304,12 @@ discard block |
||
| 1304 | 1304 | * @return array Get arguments. |
| 1305 | 1305 | */ |
| 1306 | 1306 | public function get_arguments() { |
| 1307 | - if ( empty( $this->arguments ) ) { |
|
| 1307 | + if (empty($this->arguments)) { |
|
| 1308 | 1308 | $this->arguments = $this->set_arguments(); |
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1312 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1311 | + $this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance); |
|
| 1312 | + $this->arguments = $this->add_name_from_key($this->arguments, true); |
|
| 1313 | 1313 | |
| 1314 | 1314 | return $this->arguments; |
| 1315 | 1315 | } |
@@ -1321,7 +1321,7 @@ discard block |
||
| 1321 | 1321 | * @param array $widget_args |
| 1322 | 1322 | * @param string $content |
| 1323 | 1323 | */ |
| 1324 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1324 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 1325 | 1325 | |
| 1326 | 1326 | } |
| 1327 | 1327 | |
@@ -1329,10 +1329,10 @@ discard block |
||
| 1329 | 1329 | * Add the dynamic block code inline when the wp-block in enqueued. |
| 1330 | 1330 | */ |
| 1331 | 1331 | public function register_block() { |
| 1332 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1333 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1332 | + wp_add_inline_script('wp-blocks', $this->block()); |
|
| 1333 | + if (class_exists('SiteOrigin_Panels')) { |
|
| 1334 | 1334 | |
| 1335 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1335 | + wp_add_inline_script('wp-blocks', $this->siteorigin_js()); |
|
| 1336 | 1336 | |
| 1337 | 1337 | } |
| 1338 | 1338 | } |
@@ -1347,13 +1347,13 @@ discard block |
||
| 1347 | 1347 | $show = false; |
| 1348 | 1348 | $arguments = $this->arguments; |
| 1349 | 1349 | |
| 1350 | - if ( empty( $arguments ) ) { |
|
| 1350 | + if (empty($arguments)) { |
|
| 1351 | 1351 | $arguments = $this->get_arguments(); |
| 1352 | 1352 | } |
| 1353 | 1353 | |
| 1354 | - if ( ! empty( $arguments ) ) { |
|
| 1355 | - foreach ( $arguments as $argument ) { |
|
| 1356 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1354 | + if (!empty($arguments)) { |
|
| 1355 | + foreach ($arguments as $argument) { |
|
| 1356 | + if (isset($argument['advanced']) && $argument['advanced']) { |
|
| 1357 | 1357 | $show = true; |
| 1358 | 1358 | } |
| 1359 | 1359 | } |
@@ -1405,12 +1405,12 @@ discard block |
||
| 1405 | 1405 | * @return {?WPBlock} The block, if it has been successfully |
| 1406 | 1406 | * registered; otherwise `undefined`. |
| 1407 | 1407 | */ |
| 1408 | - registerBlockType('<?php echo str_replace( "_", "-", sanitize_title_with_dashes( $this->options['textdomain'] ) . '/' . sanitize_title_with_dashes( $this->options['class_name'] ) ); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
| 1409 | - title: '<?php echo $this->options['name'];?>', // Block title. |
|
| 1410 | - description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title. |
|
| 1411 | - icon: '<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
| 1412 | - category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
| 1413 | - <?php if ( isset( $this->options['block-keywords'] ) ) { |
|
| 1408 | + registerBlockType('<?php echo str_replace("_", "-", sanitize_title_with_dashes($this->options['textdomain']) . '/' . sanitize_title_with_dashes($this->options['class_name'])); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
| 1409 | + title: '<?php echo $this->options['name']; ?>', // Block title. |
|
| 1410 | + description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title. |
|
| 1411 | + icon: '<?php echo isset($this->options['block-icon']) ? esc_attr($this->options['block-icon']) : 'shield-alt'; ?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
| 1412 | + category: '<?php echo isset($this->options['block-category']) ? esc_attr($this->options['block-category']) : 'common'; ?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
| 1413 | + <?php if (isset($this->options['block-keywords'])) { |
|
| 1414 | 1414 | echo "keywords : " . $this->options['block-keywords'] . ","; |
| 1415 | 1415 | }?> |
| 1416 | 1416 | |
@@ -1420,10 +1420,10 @@ discard block |
||
| 1420 | 1420 | |
| 1421 | 1421 | $show_alignment = false; |
| 1422 | 1422 | |
| 1423 | - if ( ! empty( $this->arguments ) ) { |
|
| 1423 | + if (!empty($this->arguments)) { |
|
| 1424 | 1424 | echo "attributes : {"; |
| 1425 | 1425 | |
| 1426 | - if ( $show_advanced ) { |
|
| 1426 | + if ($show_advanced) { |
|
| 1427 | 1427 | echo "show_advanced: {"; |
| 1428 | 1428 | echo " type: 'boolean',"; |
| 1429 | 1429 | echo " default: false,"; |
@@ -1431,42 +1431,42 @@ discard block |
||
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | // block wrap element |
| 1434 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1434 | + if (isset($this->options['block-wrap'])) { //@todo we should validate this? |
|
| 1435 | 1435 | echo "block_wrap: {"; |
| 1436 | 1436 | echo " type: 'string',"; |
| 1437 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1437 | + echo " default: '" . esc_attr($this->options['block-wrap']) . "',"; |
|
| 1438 | 1438 | echo "},"; |
| 1439 | 1439 | } |
| 1440 | 1440 | |
| 1441 | 1441 | |
| 1442 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1442 | + foreach ($this->arguments as $key => $args) { |
|
| 1443 | 1443 | |
| 1444 | 1444 | // set if we should show alignment |
| 1445 | - if ( $key == 'alignment' ) { |
|
| 1445 | + if ($key == 'alignment') { |
|
| 1446 | 1446 | $show_alignment = true; |
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | $extra = ''; |
| 1450 | 1450 | |
| 1451 | - if ( $args['type'] == 'checkbox' ) { |
|
| 1451 | + if ($args['type'] == 'checkbox') { |
|
| 1452 | 1452 | $type = 'boolean'; |
| 1453 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1454 | - } elseif ( $args['type'] == 'number' ) { |
|
| 1453 | + $default = isset($args['default']) && $args['default'] ? 'true' : 'false'; |
|
| 1454 | + } elseif ($args['type'] == 'number') { |
|
| 1455 | 1455 | $type = 'number'; |
| 1456 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1457 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1456 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1457 | + } elseif ($args['type'] == 'select' && !empty($args['multiple'])) { |
|
| 1458 | 1458 | $type = 'array'; |
| 1459 | - if ( is_array( $args['default'] ) ) { |
|
| 1460 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1459 | + if (is_array($args['default'])) { |
|
| 1460 | + $default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]"; |
|
| 1461 | 1461 | } else { |
| 1462 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1462 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1463 | 1463 | } |
| 1464 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1464 | + } elseif ($args['type'] == 'multiselect') { |
|
| 1465 | 1465 | $type = 'array'; |
| 1466 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1466 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1467 | 1467 | } else { |
| 1468 | 1468 | $type = 'string'; |
| 1469 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1469 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1470 | 1470 | } |
| 1471 | 1471 | echo $key . " : {"; |
| 1472 | 1472 | echo "type : '$type',"; |
@@ -1496,12 +1496,12 @@ discard block |
||
| 1496 | 1496 | is_fetching = true; |
| 1497 | 1497 | var data = { |
| 1498 | 1498 | 'action': 'super_duper_output_shortcode', |
| 1499 | - 'shortcode': '<?php echo $this->options['base_id'];?>', |
|
| 1499 | + 'shortcode': '<?php echo $this->options['base_id']; ?>', |
|
| 1500 | 1500 | 'attributes': props.attributes, |
| 1501 | - 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
|
| 1501 | + 'post_id': <?php global $post; if (isset($post->ID)) { |
|
| 1502 | 1502 | echo $post->ID; |
| 1503 | 1503 | }?>, |
| 1504 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 1504 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 1505 | 1505 | }; |
| 1506 | 1506 | |
| 1507 | 1507 | jQuery.post(ajaxurl, data, function (response) { |
@@ -1510,7 +1510,7 @@ discard block |
||
| 1510 | 1510 | |
| 1511 | 1511 | // if the content is empty then we place some placeholder text |
| 1512 | 1512 | if (env == '') { |
| 1513 | - env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>"; |
|
| 1513 | + env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>"; |
|
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | 1516 | props.setAttributes({content: env}); |
@@ -1529,7 +1529,7 @@ discard block |
||
| 1529 | 1529 | |
| 1530 | 1530 | el(wp.editor.BlockControls, {key: 'controls'}, |
| 1531 | 1531 | |
| 1532 | - <?php if($show_alignment){?> |
|
| 1532 | + <?php if ($show_alignment) {?> |
|
| 1533 | 1533 | el( |
| 1534 | 1534 | wp.editor.AlignmentToolbar, |
| 1535 | 1535 | { |
@@ -1547,9 +1547,9 @@ discard block |
||
| 1547 | 1547 | |
| 1548 | 1548 | <?php |
| 1549 | 1549 | |
| 1550 | - if(! empty( $this->arguments )){ |
|
| 1550 | + if (!empty($this->arguments)) { |
|
| 1551 | 1551 | |
| 1552 | - if ( $show_advanced ) { |
|
| 1552 | + if ($show_advanced) { |
|
| 1553 | 1553 | ?> |
| 1554 | 1554 | el( |
| 1555 | 1555 | wp.components.ToggleControl, |
@@ -1565,76 +1565,76 @@ discard block |
||
| 1565 | 1565 | |
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | - foreach($this->arguments as $key => $args){ |
|
| 1569 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 1568 | + foreach ($this->arguments as $key => $args) { |
|
| 1569 | + $custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : ''; |
|
| 1570 | 1570 | $options = ''; |
| 1571 | 1571 | $extra = ''; |
| 1572 | 1572 | $require = ''; |
| 1573 | 1573 | $onchange = "props.setAttributes({ $key: $key } )"; |
| 1574 | 1574 | $value = "props.attributes.$key"; |
| 1575 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
| 1576 | - if ( in_array( $args['type'], $text_type ) ) { |
|
| 1575 | + $text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color'); |
|
| 1576 | + if (in_array($args['type'], $text_type)) { |
|
| 1577 | 1577 | $type = 'TextControl'; |
| 1578 | 1578 | // Save numbers as numbers and not strings |
| 1579 | - if ( $args['type'] == 'number' ) { |
|
| 1579 | + if ($args['type'] == 'number') { |
|
| 1580 | 1580 | $onchange = "props.setAttributes({ $key: Number($key) } )"; |
| 1581 | 1581 | } |
| 1582 | 1582 | } |
| 1583 | 1583 | // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we may have to add our own https://github.com/WordPress/gutenberg/issues/14378 |
| 1584 | 1584 | // $type = 'ColorPicker'; |
| 1585 | 1585 | // } |
| 1586 | - elseif ( $args['type'] == 'checkbox' ) { |
|
| 1586 | + elseif ($args['type'] == 'checkbox') { |
|
| 1587 | 1587 | $type = 'CheckboxControl'; |
| 1588 | 1588 | $extra .= "checked: props.attributes.$key,"; |
| 1589 | 1589 | $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
| 1590 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 1590 | + } elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') { |
|
| 1591 | 1591 | $type = 'SelectControl'; |
| 1592 | - if ( ! empty( $args['options'] ) ) { |
|
| 1592 | + if (!empty($args['options'])) { |
|
| 1593 | 1593 | $options .= "options : ["; |
| 1594 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 1595 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
| 1594 | + foreach ($args['options'] as $option_val => $option_label) { |
|
| 1595 | + $options .= "{ value : '" . esc_attr($option_val) . "', label : '" . esc_attr($option_label) . "' },"; |
|
| 1596 | 1596 | } |
| 1597 | 1597 | $options .= "],"; |
| 1598 | 1598 | } |
| 1599 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1599 | + if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 1600 | 1600 | $extra .= ' multiple: true, '; |
| 1601 | 1601 | //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
| 1602 | 1602 | //$value = "['edit', 'delete']"; |
| 1603 | 1603 | } |
| 1604 | - } elseif ( $args['type'] == 'alignment' ) { |
|
| 1604 | + } elseif ($args['type'] == 'alignment') { |
|
| 1605 | 1605 | $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
| 1606 | 1606 | } else { |
| 1607 | - continue;// if we have not implemented the control then don't break the JS. |
|
| 1607 | + continue; // if we have not implemented the control then don't break the JS. |
|
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | // add show only if advanced |
| 1611 | - if ( ! empty( $args['advanced'] ) ) { |
|
| 1611 | + if (!empty($args['advanced'])) { |
|
| 1612 | 1612 | echo "props.attributes.show_advanced && "; |
| 1613 | 1613 | } |
| 1614 | 1614 | // add setting require if defined |
| 1615 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 1616 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
| 1615 | + if (!empty($args['element_require'])) { |
|
| 1616 | + echo $this->block_props_replace($args['element_require'], true) . " && "; |
|
| 1617 | 1617 | } |
| 1618 | 1618 | ?> |
| 1619 | 1619 | el( |
| 1620 | - wp.components.<?php echo esc_attr( $type );?>, |
|
| 1620 | + wp.components.<?php echo esc_attr($type); ?>, |
|
| 1621 | 1621 | { |
| 1622 | - label: '<?php echo esc_attr( $args['title'] );?>', |
|
| 1623 | - help: '<?php if ( isset( $args['desc'] ) ) { |
|
| 1624 | - echo esc_attr( $args['desc'] ); |
|
| 1622 | + label: '<?php echo esc_attr($args['title']); ?>', |
|
| 1623 | + help: '<?php if (isset($args['desc'])) { |
|
| 1624 | + echo esc_attr($args['desc']); |
|
| 1625 | 1625 | }?>', |
| 1626 | - value: <?php echo $value;?>, |
|
| 1627 | - <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
|
| 1628 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
| 1626 | + value: <?php echo $value; ?>, |
|
| 1627 | + <?php if ($type == 'TextControl' && $args['type'] != 'text') { |
|
| 1628 | + echo "type: '" . esc_attr($args['type']) . "',"; |
|
| 1629 | 1629 | }?> |
| 1630 | - <?php if ( ! empty( $args['placeholder'] ) ) { |
|
| 1631 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
| 1630 | + <?php if (!empty($args['placeholder'])) { |
|
| 1631 | + echo "placeholder: '" . esc_attr($args['placeholder']) . "',"; |
|
| 1632 | 1632 | }?> |
| 1633 | - <?php echo $options;?> |
|
| 1634 | - <?php echo $extra;?> |
|
| 1635 | - <?php echo $custom_attributes;?> |
|
| 1636 | - onChange: function ( <?php echo $key;?> ) { |
|
| 1637 | - <?php echo $onchange;?> |
|
| 1633 | + <?php echo $options; ?> |
|
| 1634 | + <?php echo $extra; ?> |
|
| 1635 | + <?php echo $custom_attributes; ?> |
|
| 1636 | + onChange: function ( <?php echo $key; ?> ) { |
|
| 1637 | + <?php echo $onchange; ?> |
|
| 1638 | 1638 | } |
| 1639 | 1639 | } |
| 1640 | 1640 | ), |
@@ -1647,9 +1647,9 @@ discard block |
||
| 1647 | 1647 | |
| 1648 | 1648 | <?php |
| 1649 | 1649 | // If the user sets block-output array then build it |
| 1650 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1651 | - $this->block_element( $this->options['block-output'] ); |
|
| 1652 | - }else{ |
|
| 1650 | + if (!empty($this->options['block-output'])) { |
|
| 1651 | + $this->block_element($this->options['block-output']); |
|
| 1652 | + } else { |
|
| 1653 | 1653 | // if no block-output is set then we try and get the shortcode html output via ajax. |
| 1654 | 1654 | ?> |
| 1655 | 1655 | el('div', { |
@@ -1673,14 +1673,14 @@ discard block |
||
| 1673 | 1673 | var align = ''; |
| 1674 | 1674 | |
| 1675 | 1675 | // build the shortcode. |
| 1676 | - var content = "[<?php echo $this->options['base_id'];?>"; |
|
| 1676 | + var content = "[<?php echo $this->options['base_id']; ?>"; |
|
| 1677 | 1677 | <?php |
| 1678 | 1678 | |
| 1679 | - if(! empty( $this->arguments )){ |
|
| 1680 | - foreach($this->arguments as $key => $args){ |
|
| 1679 | + if (!empty($this->arguments)) { |
|
| 1680 | + foreach ($this->arguments as $key => $args) { |
|
| 1681 | 1681 | ?> |
| 1682 | - if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
|
| 1683 | - content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
|
| 1682 | + if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) { |
|
| 1683 | + content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' "; |
|
| 1684 | 1684 | } |
| 1685 | 1685 | <?php |
| 1686 | 1686 | } |
@@ -1721,10 +1721,10 @@ discard block |
||
| 1721 | 1721 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1722 | 1722 | */ |
| 1723 | 1723 | |
| 1724 | - return str_replace( array( |
|
| 1724 | + return str_replace(array( |
|
| 1725 | 1725 | '<script>', |
| 1726 | 1726 | '</script>' |
| 1727 | - ), '', $output ); |
|
| 1727 | + ), '', $output); |
|
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | 1730 | /** |
@@ -1736,16 +1736,16 @@ discard block |
||
| 1736 | 1736 | * |
| 1737 | 1737 | * @return string |
| 1738 | 1738 | */ |
| 1739 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 1739 | + public function array_to_attributes($custom_attributes, $html = false) { |
|
| 1740 | 1740 | $attributes = ''; |
| 1741 | - if ( ! empty( $custom_attributes ) ) { |
|
| 1741 | + if (!empty($custom_attributes)) { |
|
| 1742 | 1742 | |
| 1743 | - if ( $html ) { |
|
| 1744 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1743 | + if ($html) { |
|
| 1744 | + foreach ($custom_attributes as $key => $val) { |
|
| 1745 | 1745 | $attributes .= " $key='$val' "; |
| 1746 | 1746 | } |
| 1747 | 1747 | } else { |
| 1748 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 1748 | + foreach ($custom_attributes as $key => $val) { |
|
| 1749 | 1749 | $attributes .= "'$key': '$val',"; |
| 1750 | 1750 | } |
| 1751 | 1751 | } |
@@ -1761,86 +1761,86 @@ discard block |
||
| 1761 | 1761 | * |
| 1762 | 1762 | * @param $args |
| 1763 | 1763 | */ |
| 1764 | - public function block_element( $args ) { |
|
| 1764 | + public function block_element($args) { |
|
| 1765 | 1765 | |
| 1766 | 1766 | |
| 1767 | - if ( ! empty( $args ) ) { |
|
| 1768 | - foreach ( $args as $element => $new_args ) { |
|
| 1767 | + if (!empty($args)) { |
|
| 1768 | + foreach ($args as $element => $new_args) { |
|
| 1769 | 1769 | |
| 1770 | - if ( is_array( $new_args ) ) { // its an element |
|
| 1770 | + if (is_array($new_args)) { // its an element |
|
| 1771 | 1771 | |
| 1772 | 1772 | |
| 1773 | - if ( isset( $new_args['element'] ) ) { |
|
| 1773 | + if (isset($new_args['element'])) { |
|
| 1774 | 1774 | |
| 1775 | - if ( isset( $new_args['element_require'] ) ) { |
|
| 1776 | - echo str_replace( array( |
|
| 1775 | + if (isset($new_args['element_require'])) { |
|
| 1776 | + echo str_replace(array( |
|
| 1777 | 1777 | "'+", |
| 1778 | 1778 | "+'" |
| 1779 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 1780 | - unset( $new_args['element_require'] ); |
|
| 1779 | + ), '', $this->block_props_replace($new_args['element_require'])) . " && "; |
|
| 1780 | + unset($new_args['element_require']); |
|
| 1781 | 1781 | } |
| 1782 | 1782 | |
| 1783 | 1783 | echo "\n el( '" . $new_args['element'] . "', {"; |
| 1784 | 1784 | |
| 1785 | 1785 | // get the attributes |
| 1786 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1786 | + foreach ($new_args as $new_key => $new_value) { |
|
| 1787 | 1787 | |
| 1788 | 1788 | |
| 1789 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 1789 | + if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) { |
|
| 1790 | 1790 | // do nothing |
| 1791 | 1791 | } else { |
| 1792 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 1792 | + echo $this->block_element(array($new_key => $new_value)); |
|
| 1793 | 1793 | } |
| 1794 | 1794 | } |
| 1795 | 1795 | |
| 1796 | - echo "},";// end attributes |
|
| 1796 | + echo "},"; // end attributes |
|
| 1797 | 1797 | |
| 1798 | 1798 | // get the content |
| 1799 | 1799 | $first_item = 0; |
| 1800 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 1801 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 1800 | + foreach ($new_args as $new_key => $new_value) { |
|
| 1801 | + if ($new_key === 'content' || is_array($new_value)) { |
|
| 1802 | 1802 | |
| 1803 | - if ( $new_key === 'content' ) { |
|
| 1804 | - echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
| 1803 | + if ($new_key === 'content') { |
|
| 1804 | + echo "'" . $this->block_props_replace($new_value) . "'"; |
|
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | - if ( is_array( $new_value ) ) { |
|
| 1807 | + if (is_array($new_value)) { |
|
| 1808 | 1808 | |
| 1809 | - if ( isset( $new_value['element_require'] ) ) { |
|
| 1810 | - echo str_replace( array( |
|
| 1809 | + if (isset($new_value['element_require'])) { |
|
| 1810 | + echo str_replace(array( |
|
| 1811 | 1811 | "'+", |
| 1812 | 1812 | "+'" |
| 1813 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 1814 | - unset( $new_value['element_require'] ); |
|
| 1813 | + ), '', $this->block_props_replace($new_value['element_require'])) . " && "; |
|
| 1814 | + unset($new_value['element_require']); |
|
| 1815 | 1815 | } |
| 1816 | 1816 | |
| 1817 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
| 1817 | + if (isset($new_value['element_repeat'])) { |
|
| 1818 | 1818 | $x = 1; |
| 1819 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 1820 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1821 | - $x ++; |
|
| 1819 | + while ($x <= absint($new_value['element_repeat'])) { |
|
| 1820 | + $this->block_element(array('' => $new_value)); |
|
| 1821 | + $x++; |
|
| 1822 | 1822 | } |
| 1823 | 1823 | } else { |
| 1824 | - $this->block_element( array( '' => $new_value ) ); |
|
| 1824 | + $this->block_element(array('' => $new_value)); |
|
| 1825 | 1825 | } |
| 1826 | 1826 | } |
| 1827 | - $first_item ++; |
|
| 1827 | + $first_item++; |
|
| 1828 | 1828 | } |
| 1829 | 1829 | } |
| 1830 | 1830 | |
| 1831 | - echo ")";// end content |
|
| 1831 | + echo ")"; // end content |
|
| 1832 | 1832 | |
| 1833 | 1833 | echo ", \n"; |
| 1834 | 1834 | |
| 1835 | 1835 | } |
| 1836 | 1836 | } else { |
| 1837 | 1837 | |
| 1838 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 1839 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 1840 | - } elseif ( $element == 'style' ) { |
|
| 1841 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 1838 | + if (substr($element, 0, 3) === "if_") { |
|
| 1839 | + echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ","; |
|
| 1840 | + } elseif ($element == 'style') { |
|
| 1841 | + echo $element . ": " . $this->block_props_replace($new_args) . ","; |
|
| 1842 | 1842 | } else { |
| 1843 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 1843 | + echo $element . ": '" . $this->block_props_replace($new_args) . "',"; |
|
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | 1846 | } |
@@ -1855,12 +1855,12 @@ discard block |
||
| 1855 | 1855 | * |
| 1856 | 1856 | * @return mixed |
| 1857 | 1857 | */ |
| 1858 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
| 1858 | + public function block_props_replace($string, $no_wrap = false) { |
|
| 1859 | 1859 | |
| 1860 | - if ( $no_wrap ) { |
|
| 1861 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 1860 | + if ($no_wrap) { |
|
| 1861 | + $string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string); |
|
| 1862 | 1862 | } else { |
| 1863 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 1863 | + $string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string); |
|
| 1864 | 1864 | } |
| 1865 | 1865 | |
| 1866 | 1866 | return $string; |
@@ -1872,37 +1872,37 @@ discard block |
||
| 1872 | 1872 | * @param array $args |
| 1873 | 1873 | * @param array $instance |
| 1874 | 1874 | */ |
| 1875 | - public function widget( $args, $instance ) { |
|
| 1875 | + public function widget($args, $instance) { |
|
| 1876 | 1876 | |
| 1877 | 1877 | // get the filtered values |
| 1878 | - $argument_values = $this->argument_values( $instance ); |
|
| 1879 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
| 1880 | - $output = $this->output( $argument_values, $args ); |
|
| 1878 | + $argument_values = $this->argument_values($instance); |
|
| 1879 | + $argument_values = $this->string_to_bool($argument_values); |
|
| 1880 | + $output = $this->output($argument_values, $args); |
|
| 1881 | 1881 | |
| 1882 | - if ( $output ) { |
|
| 1882 | + if ($output) { |
|
| 1883 | 1883 | // Before widget |
| 1884 | 1884 | $before_widget = $args['before_widget']; |
| 1885 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 1886 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 1885 | + $before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this); |
|
| 1886 | + $before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this); |
|
| 1887 | 1887 | |
| 1888 | 1888 | // After widget |
| 1889 | 1889 | $after_widget = $args['after_widget']; |
| 1890 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 1891 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 1890 | + $after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this); |
|
| 1891 | + $after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this); |
|
| 1892 | 1892 | |
| 1893 | 1893 | echo $before_widget; |
| 1894 | 1894 | // elementor strips the widget wrapping div so we check for and add it back if needed |
| 1895 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1896 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
| 1895 | + if ($this->is_elementor_widget_output()) { |
|
| 1896 | + echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($this->options['widget_ops']['classname']) . "'>" : ''; |
|
| 1897 | 1897 | } |
| 1898 | - echo $this->output_title( $args, $instance ); |
|
| 1898 | + echo $this->output_title($args, $instance); |
|
| 1899 | 1899 | echo $output; |
| 1900 | - if ( $this->is_elementor_widget_output() ) { |
|
| 1901 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 1900 | + if ($this->is_elementor_widget_output()) { |
|
| 1901 | + echo !empty($this->options['widget_ops']['classname']) ? "</span>" : ''; |
|
| 1902 | 1902 | } |
| 1903 | 1903 | echo $after_widget; |
| 1904 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 1905 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 1904 | + } elseif ($this->is_preview() && $output == '') {// if preview show a placeholder if empty |
|
| 1905 | + $output = $this->preview_placeholder_text("{{" . $this->base_id . "}}"); |
|
| 1906 | 1906 | echo $output; |
| 1907 | 1907 | } |
| 1908 | 1908 | } |
@@ -1915,7 +1915,7 @@ discard block |
||
| 1915 | 1915 | */ |
| 1916 | 1916 | public function is_elementor_widget_output() { |
| 1917 | 1917 | $result = false; |
| 1918 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 1918 | + if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') { |
|
| 1919 | 1919 | $result = true; |
| 1920 | 1920 | } |
| 1921 | 1921 | |
@@ -1930,7 +1930,7 @@ discard block |
||
| 1930 | 1930 | */ |
| 1931 | 1931 | public function is_elementor_preview() { |
| 1932 | 1932 | $result = false; |
| 1933 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 1933 | + if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax')) { |
|
| 1934 | 1934 | $result = true; |
| 1935 | 1935 | } |
| 1936 | 1936 | |
@@ -1945,7 +1945,7 @@ discard block |
||
| 1945 | 1945 | */ |
| 1946 | 1946 | public function is_divi_preview() { |
| 1947 | 1947 | $result = false; |
| 1948 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 1948 | + if (isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) { |
|
| 1949 | 1949 | $result = true; |
| 1950 | 1950 | } |
| 1951 | 1951 | |
@@ -1960,7 +1960,7 @@ discard block |
||
| 1960 | 1960 | */ |
| 1961 | 1961 | public function is_beaver_preview() { |
| 1962 | 1962 | $result = false; |
| 1963 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 1963 | + if (isset($_REQUEST['fl_builder'])) { |
|
| 1964 | 1964 | $result = true; |
| 1965 | 1965 | } |
| 1966 | 1966 | |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | */ |
| 1976 | 1976 | public function is_siteorigin_preview() { |
| 1977 | 1977 | $result = false; |
| 1978 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 1978 | + if (!empty($_REQUEST['siteorigin_panels_live_editor'])) { |
|
| 1979 | 1979 | $result = true; |
| 1980 | 1980 | } |
| 1981 | 1981 | |
@@ -1990,7 +1990,7 @@ discard block |
||
| 1990 | 1990 | */ |
| 1991 | 1991 | public function is_cornerstone_preview() { |
| 1992 | 1992 | $result = false; |
| 1993 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 1993 | + if (!empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint') { |
|
| 1994 | 1994 | $result = true; |
| 1995 | 1995 | } |
| 1996 | 1996 | |
@@ -2005,15 +2005,15 @@ discard block |
||
| 2005 | 2005 | */ |
| 2006 | 2006 | public function is_preview() { |
| 2007 | 2007 | $preview = false; |
| 2008 | - if ( $this->is_divi_preview() ) { |
|
| 2008 | + if ($this->is_divi_preview()) { |
|
| 2009 | 2009 | $preview = true; |
| 2010 | - } elseif ( $this->is_elementor_preview() ) { |
|
| 2010 | + } elseif ($this->is_elementor_preview()) { |
|
| 2011 | 2011 | $preview = true; |
| 2012 | - } elseif ( $this->is_beaver_preview() ) { |
|
| 2012 | + } elseif ($this->is_beaver_preview()) { |
|
| 2013 | 2013 | $preview = true; |
| 2014 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2014 | + } elseif ($this->is_siteorigin_preview()) { |
|
| 2015 | 2015 | $preview = true; |
| 2016 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2016 | + } elseif ($this->is_cornerstone_preview()) { |
|
| 2017 | 2017 | $preview = true; |
| 2018 | 2018 | } |
| 2019 | 2019 | |
@@ -2028,11 +2028,11 @@ discard block |
||
| 2028 | 2028 | * |
| 2029 | 2029 | * @return string |
| 2030 | 2030 | */ |
| 2031 | - public function output_title( $args, $instance = array() ) { |
|
| 2031 | + public function output_title($args, $instance = array()) { |
|
| 2032 | 2032 | $output = ''; |
| 2033 | - if ( ! empty( $instance['title'] ) ) { |
|
| 2033 | + if (!empty($instance['title'])) { |
|
| 2034 | 2034 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
| 2035 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2035 | + $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); |
|
| 2036 | 2036 | $output = $args['before_title'] . $title . $args['after_title']; |
| 2037 | 2037 | } |
| 2038 | 2038 | |
@@ -2044,7 +2044,7 @@ discard block |
||
| 2044 | 2044 | * |
| 2045 | 2045 | * @param array $instance The widget options. |
| 2046 | 2046 | */ |
| 2047 | - public function form( $instance ) { |
|
| 2047 | + public function form($instance) { |
|
| 2048 | 2048 | |
| 2049 | 2049 | // set widget instance |
| 2050 | 2050 | $this->instance = $instance; |
@@ -2052,12 +2052,12 @@ discard block |
||
| 2052 | 2052 | // set it as a SD widget |
| 2053 | 2053 | echo $this->widget_advanced_toggle(); |
| 2054 | 2054 | |
| 2055 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2055 | + echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>"; |
|
| 2056 | 2056 | $arguments = $this->get_arguments(); |
| 2057 | 2057 | |
| 2058 | - if ( is_array( $arguments ) ) { |
|
| 2059 | - foreach ( $arguments as $key => $args ) { |
|
| 2060 | - $this->widget_inputs( $args, $instance ); |
|
| 2058 | + if (is_array($arguments)) { |
|
| 2059 | + foreach ($arguments as $key => $args) { |
|
| 2060 | + $this->widget_inputs($args, $instance); |
|
| 2061 | 2061 | } |
| 2062 | 2062 | } |
| 2063 | 2063 | } |
@@ -2070,7 +2070,7 @@ discard block |
||
| 2070 | 2070 | public function widget_advanced_toggle() { |
| 2071 | 2071 | |
| 2072 | 2072 | $output = ''; |
| 2073 | - if ( $this->block_show_advanced() ) { |
|
| 2073 | + if ($this->block_show_advanced()) { |
|
| 2074 | 2074 | $val = 1; |
| 2075 | 2075 | } else { |
| 2076 | 2076 | $val = 0; |
@@ -2090,14 +2090,14 @@ discard block |
||
| 2090 | 2090 | * |
| 2091 | 2091 | * @return string $output |
| 2092 | 2092 | */ |
| 2093 | - public function convert_element_require( $input ) { |
|
| 2093 | + public function convert_element_require($input) { |
|
| 2094 | 2094 | |
| 2095 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2095 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
| 2096 | 2096 | |
| 2097 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2097 | + $output = esc_attr(str_replace(array("[%", "%]"), array( |
|
| 2098 | 2098 | "jQuery(form).find('[data-argument=\"", |
| 2099 | 2099 | "\"]').find('input,select').val()" |
| 2100 | - ), $input ) ); |
|
| 2100 | + ), $input)); |
|
| 2101 | 2101 | |
| 2102 | 2102 | return $output; |
| 2103 | 2103 | } |
@@ -2108,54 +2108,54 @@ discard block |
||
| 2108 | 2108 | * @param $args |
| 2109 | 2109 | * @param $instance |
| 2110 | 2110 | */ |
| 2111 | - public function widget_inputs( $args, $instance ) { |
|
| 2111 | + public function widget_inputs($args, $instance) { |
|
| 2112 | 2112 | |
| 2113 | 2113 | $class = ""; |
| 2114 | 2114 | $element_require = ""; |
| 2115 | 2115 | $custom_attributes = ""; |
| 2116 | 2116 | |
| 2117 | 2117 | // get value |
| 2118 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2119 | - $value = $instance[ $args['name'] ]; |
|
| 2120 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2121 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2118 | + if (isset($instance[$args['name']])) { |
|
| 2119 | + $value = $instance[$args['name']]; |
|
| 2120 | + } elseif (!isset($instance[$args['name']]) && !empty($args['default'])) { |
|
| 2121 | + $value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']); |
|
| 2122 | 2122 | } else { |
| 2123 | 2123 | $value = ''; |
| 2124 | 2124 | } |
| 2125 | 2125 | |
| 2126 | 2126 | // get placeholder |
| 2127 | - if ( ! empty( $args['placeholder'] ) ) { |
|
| 2128 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2127 | + if (!empty($args['placeholder'])) { |
|
| 2128 | + $placeholder = "placeholder='" . esc_html($args['placeholder']) . "'"; |
|
| 2129 | 2129 | } else { |
| 2130 | 2130 | $placeholder = ''; |
| 2131 | 2131 | } |
| 2132 | 2132 | |
| 2133 | 2133 | // get if advanced |
| 2134 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2134 | + if (isset($args['advanced']) && $args['advanced']) { |
|
| 2135 | 2135 | $class .= " sd-advanced-setting "; |
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | 2138 | // element_require |
| 2139 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2139 | + if (isset($args['element_require']) && $args['element_require']) { |
|
| 2140 | 2140 | $element_require = $args['element_require']; |
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | // custom_attributes |
| 2144 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2145 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2144 | + if (isset($args['custom_attributes']) && $args['custom_attributes']) { |
|
| 2145 | + $custom_attributes = $this->array_to_attributes($args['custom_attributes'], true); |
|
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | 2148 | // before wrapper |
| 2149 | 2149 | ?> |
| 2150 | - <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
|
| 2151 | - data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
|
| 2152 | - data-element_require='<?php if ( $element_require ) { |
|
| 2153 | - echo $this->convert_element_require( $element_require ); |
|
| 2150 | + <p class="sd-argument <?php echo esc_attr($class); ?>" |
|
| 2151 | + data-argument='<?php echo esc_attr($args['name']); ?>' |
|
| 2152 | + data-element_require='<?php if ($element_require) { |
|
| 2153 | + echo $this->convert_element_require($element_require); |
|
| 2154 | 2154 | } ?>' |
| 2155 | 2155 | > |
| 2156 | 2156 | <?php |
| 2157 | 2157 | |
| 2158 | - switch ( $args['type'] ) { |
|
| 2158 | + switch ($args['type']) { |
|
| 2159 | 2159 | //array('text','password','number','email','tel','url','color') |
| 2160 | 2160 | case "text": |
| 2161 | 2161 | case "password": |
@@ -2166,46 +2166,46 @@ discard block |
||
| 2166 | 2166 | case "color": |
| 2167 | 2167 | ?> |
| 2168 | 2168 | <label |
| 2169 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2169 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2170 | 2170 | <input <?php echo $placeholder; ?> class="widefat" |
| 2171 | 2171 | <?php echo $custom_attributes; ?> |
| 2172 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2173 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" |
|
| 2174 | - type="<?php echo esc_attr( $args['type'] ); ?>" |
|
| 2175 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 2172 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2173 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" |
|
| 2174 | + type="<?php echo esc_attr($args['type']); ?>" |
|
| 2175 | + value="<?php echo esc_attr($value); ?>"> |
|
| 2176 | 2176 | <?php |
| 2177 | 2177 | |
| 2178 | 2178 | break; |
| 2179 | 2179 | case "select": |
| 2180 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2181 | - if ( $multiple ) { |
|
| 2182 | - if ( empty( $value ) ) { |
|
| 2180 | + $multiple = isset($args['multiple']) && $args['multiple'] ? true : false; |
|
| 2181 | + if ($multiple) { |
|
| 2182 | + if (empty($value)) { |
|
| 2183 | 2183 | $value = array(); |
| 2184 | 2184 | } |
| 2185 | 2185 | } |
| 2186 | 2186 | ?> |
| 2187 | 2187 | <label |
| 2188 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2188 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2189 | 2189 | <select <?php echo $placeholder; ?> class="widefat" |
| 2190 | 2190 | <?php echo $custom_attributes; ?> |
| 2191 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2192 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
|
| 2193 | - if ( $multiple ) { |
|
| 2191 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2192 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); |
|
| 2193 | + if ($multiple) { |
|
| 2194 | 2194 | echo "[]"; |
| 2195 | 2195 | } ?>" |
| 2196 | - <?php if ( $multiple ) { |
|
| 2196 | + <?php if ($multiple) { |
|
| 2197 | 2197 | echo "multiple"; |
| 2198 | 2198 | } //@todo not implemented yet due to gutenberg not supporting it |
| 2199 | 2199 | ?> |
| 2200 | 2200 | > |
| 2201 | 2201 | <?php |
| 2202 | 2202 | |
| 2203 | - if ( ! empty( $args['options'] ) ) { |
|
| 2204 | - foreach ( $args['options'] as $val => $label ) { |
|
| 2205 | - if ( $multiple ) { |
|
| 2206 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2203 | + if (!empty($args['options'])) { |
|
| 2204 | + foreach ($args['options'] as $val => $label) { |
|
| 2205 | + if ($multiple) { |
|
| 2206 | + $selected = in_array($val, $value) ? 'selected="selected"' : ''; |
|
| 2207 | 2207 | } else { |
| 2208 | - $selected = selected( $value, $val, false ); |
|
| 2208 | + $selected = selected($value, $val, false); |
|
| 2209 | 2209 | } |
| 2210 | 2210 | echo "<option value='$val' " . $selected . ">$label</option>"; |
| 2211 | 2211 | } |
@@ -2217,20 +2217,20 @@ discard block |
||
| 2217 | 2217 | case "checkbox": |
| 2218 | 2218 | ?> |
| 2219 | 2219 | <input <?php echo $placeholder; ?> |
| 2220 | - <?php checked( 1, $value, true ) ?> |
|
| 2220 | + <?php checked(1, $value, true) ?> |
|
| 2221 | 2221 | <?php echo $custom_attributes; ?> |
| 2222 | - class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2223 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox" |
|
| 2222 | + class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2223 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox" |
|
| 2224 | 2224 | value="1"> |
| 2225 | 2225 | <label |
| 2226 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2226 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2227 | 2227 | <?php |
| 2228 | 2228 | break; |
| 2229 | 2229 | case "hidden": |
| 2230 | 2230 | ?> |
| 2231 | - <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2232 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
|
| 2233 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 2231 | + <input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2232 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden" |
|
| 2233 | + value="<?php echo esc_attr($value); ?>"> |
|
| 2234 | 2234 | <?php |
| 2235 | 2235 | break; |
| 2236 | 2236 | default: |
@@ -2252,14 +2252,14 @@ discard block |
||
| 2252 | 2252 | * @return string |
| 2253 | 2253 | * @todo, need to make its own tooltip script |
| 2254 | 2254 | */ |
| 2255 | - public function widget_field_desc( $args ) { |
|
| 2255 | + public function widget_field_desc($args) { |
|
| 2256 | 2256 | |
| 2257 | 2257 | $description = ''; |
| 2258 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2259 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2260 | - $description = $this->desc_tip( $args['desc'] ); |
|
| 2258 | + if (isset($args['desc']) && $args['desc']) { |
|
| 2259 | + if (isset($args['desc_tip']) && $args['desc_tip']) { |
|
| 2260 | + $description = $this->desc_tip($args['desc']); |
|
| 2261 | 2261 | } else { |
| 2262 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2262 | + $description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>'; |
|
| 2263 | 2263 | } |
| 2264 | 2264 | } |
| 2265 | 2265 | |
@@ -2274,11 +2274,11 @@ discard block |
||
| 2274 | 2274 | * |
| 2275 | 2275 | * @return string |
| 2276 | 2276 | */ |
| 2277 | - function desc_tip( $tip, $allow_html = false ) { |
|
| 2278 | - if ( $allow_html ) { |
|
| 2279 | - $tip = $this->sanitize_tooltip( $tip ); |
|
| 2277 | + function desc_tip($tip, $allow_html = false) { |
|
| 2278 | + if ($allow_html) { |
|
| 2279 | + $tip = $this->sanitize_tooltip($tip); |
|
| 2280 | 2280 | } else { |
| 2281 | - $tip = esc_attr( $tip ); |
|
| 2281 | + $tip = esc_attr($tip); |
|
| 2282 | 2282 | } |
| 2283 | 2283 | |
| 2284 | 2284 | return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -2291,8 +2291,8 @@ discard block |
||
| 2291 | 2291 | * |
| 2292 | 2292 | * @return string |
| 2293 | 2293 | */ |
| 2294 | - public function sanitize_tooltip( $var ) { |
|
| 2295 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2294 | + public function sanitize_tooltip($var) { |
|
| 2295 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
| 2296 | 2296 | 'br' => array(), |
| 2297 | 2297 | 'em' => array(), |
| 2298 | 2298 | 'strong' => array(), |
@@ -2302,7 +2302,7 @@ discard block |
||
| 2302 | 2302 | 'li' => array(), |
| 2303 | 2303 | 'ol' => array(), |
| 2304 | 2304 | 'p' => array(), |
| 2305 | - ) ) ); |
|
| 2305 | + ))); |
|
| 2306 | 2306 | } |
| 2307 | 2307 | |
| 2308 | 2308 | /** |
@@ -2314,23 +2314,23 @@ discard block |
||
| 2314 | 2314 | * @return array |
| 2315 | 2315 | * @todo we should add some sanitation here. |
| 2316 | 2316 | */ |
| 2317 | - public function update( $new_instance, $old_instance ) { |
|
| 2317 | + public function update($new_instance, $old_instance) { |
|
| 2318 | 2318 | |
| 2319 | 2319 | //save the widget |
| 2320 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2320 | + $instance = array_merge((array)$old_instance, (array)$new_instance); |
|
| 2321 | 2321 | |
| 2322 | 2322 | // set widget instance |
| 2323 | 2323 | $this->instance = $instance; |
| 2324 | 2324 | |
| 2325 | - if ( empty( $this->arguments ) ) { |
|
| 2325 | + if (empty($this->arguments)) { |
|
| 2326 | 2326 | $this->get_arguments(); |
| 2327 | 2327 | } |
| 2328 | 2328 | |
| 2329 | 2329 | // check for checkboxes |
| 2330 | - if ( ! empty( $this->arguments ) ) { |
|
| 2331 | - foreach ( $this->arguments as $argument ) { |
|
| 2332 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2333 | - $instance[ $argument['name'] ] = '0'; |
|
| 2330 | + if (!empty($this->arguments)) { |
|
| 2331 | + foreach ($this->arguments as $argument) { |
|
| 2332 | + if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) { |
|
| 2333 | + $instance[$argument['name']] = '0'; |
|
| 2334 | 2334 | } |
| 2335 | 2335 | } |
| 2336 | 2336 | } |
@@ -2348,7 +2348,7 @@ discard block |
||
| 2348 | 2348 | */ |
| 2349 | 2349 | public function is_block_content_call() { |
| 2350 | 2350 | $result = false; |
| 2351 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2351 | + if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') { |
|
| 2352 | 2352 | $result = true; |
| 2353 | 2353 | } |
| 2354 | 2354 | |
@@ -7,245 +7,245 @@ 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 | -function wpinv_columns( $columns ) { |
|
| 14 | +function wpinv_columns($columns) { |
|
| 15 | 15 | $columns = array( |
| 16 | 16 | 'cb' => $columns['cb'], |
| 17 | - 'number' => __( 'Number', 'invoicing' ), |
|
| 18 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 19 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 20 | - 'invoice_date' => __( 'Created Date', 'invoicing' ), |
|
| 21 | - 'payment_date' => __( 'Payment Date', 'invoicing' ), |
|
| 22 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 23 | - 'ID' => __( 'ID', 'invoicing' ), |
|
| 24 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
| 17 | + 'number' => __('Number', 'invoicing'), |
|
| 18 | + 'customer' => __('Customer', 'invoicing'), |
|
| 19 | + 'amount' => __('Amount', 'invoicing'), |
|
| 20 | + 'invoice_date' => __('Created Date', 'invoicing'), |
|
| 21 | + 'payment_date' => __('Payment Date', 'invoicing'), |
|
| 22 | + 'status' => __('Status', 'invoicing'), |
|
| 23 | + 'ID' => __('ID', 'invoicing'), |
|
| 24 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
| 25 | 25 | ); |
| 26 | 26 | |
| 27 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 27 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
| 28 | 28 | } |
| 29 | -add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' ); |
|
| 29 | +add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns'); |
|
| 30 | 30 | |
| 31 | -function wpinv_bulk_actions( $actions ) { |
|
| 32 | - if ( isset( $actions['edit'] ) ) { |
|
| 33 | - unset( $actions['edit'] ); |
|
| 31 | +function wpinv_bulk_actions($actions) { |
|
| 32 | + if (isset($actions['edit'])) { |
|
| 33 | + unset($actions['edit']); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | return $actions; |
| 37 | 37 | } |
| 38 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
| 39 | -add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' ); |
|
| 38 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
| 39 | +add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions'); |
|
| 40 | 40 | |
| 41 | -function wpinv_sortable_columns( $columns ) { |
|
| 41 | +function wpinv_sortable_columns($columns) { |
|
| 42 | 42 | $columns = array( |
| 43 | - 'ID' => array( 'ID', true ), |
|
| 44 | - 'number' => array( 'number', false ), |
|
| 45 | - 'amount' => array( 'amount', false ), |
|
| 46 | - 'invoice_date' => array( 'date', false ), |
|
| 47 | - 'payment_date' => array( 'payment_date', true ), |
|
| 48 | - 'customer' => array( 'customer', false ), |
|
| 49 | - 'status' => array( 'status', false ), |
|
| 43 | + 'ID' => array('ID', true), |
|
| 44 | + 'number' => array('number', false), |
|
| 45 | + 'amount' => array('amount', false), |
|
| 46 | + 'invoice_date' => array('date', false), |
|
| 47 | + 'payment_date' => array('payment_date', true), |
|
| 48 | + 'customer' => array('customer', false), |
|
| 49 | + 'status' => array('status', false), |
|
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | - return apply_filters( 'wpi_invoice_table_sortable_columns', $columns ); |
|
| 52 | + return apply_filters('wpi_invoice_table_sortable_columns', $columns); |
|
| 53 | 53 | } |
| 54 | -add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' ); |
|
| 54 | +add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns'); |
|
| 55 | 55 | |
| 56 | -add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
| 57 | -function wpinv_posts_custom_column( $column_name, $post_id = 0 ) { |
|
| 56 | +add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
| 57 | +function wpinv_posts_custom_column($column_name, $post_id = 0) { |
|
| 58 | 58 | global $post, $wpi_invoice; |
| 59 | 59 | |
| 60 | - if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) { |
|
| 61 | - $wpi_invoice = new WPInv_Invoice( $post->ID ); |
|
| 60 | + if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) { |
|
| 61 | + $wpi_invoice = new WPInv_Invoice($post->ID); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $value = NULL; |
| 65 | 65 | |
| 66 | - switch ( $column_name ) { |
|
| 66 | + switch ($column_name) { |
|
| 67 | 67 | case 'email' : |
| 68 | - $value = $wpi_invoice->get_email(); |
|
| 68 | + $value = $wpi_invoice->get_email(); |
|
| 69 | 69 | break; |
| 70 | 70 | case 'customer' : |
| 71 | 71 | $customer_name = $wpi_invoice->get_user_full_name(); |
| 72 | - $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' ); |
|
| 73 | - $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>'; |
|
| 74 | - if ( $email = $wpi_invoice->get_email() ) { |
|
| 72 | + $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing'); |
|
| 73 | + $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>'; |
|
| 74 | + if ($email = $wpi_invoice->get_email()) { |
|
| 75 | 75 | $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>'; |
| 76 | 76 | } |
| 77 | 77 | break; |
| 78 | 78 | case 'amount' : |
| 79 | - echo $wpi_invoice->get_total( true ); |
|
| 79 | + echo $wpi_invoice->get_total(true); |
|
| 80 | 80 | break; |
| 81 | 81 | case 'invoice_date' : |
| 82 | - $date_format = get_option( 'date_format' ); |
|
| 83 | - $time_format = get_option( 'time_format' ); |
|
| 84 | - $date_time_format = $date_format . ' '. $time_format; |
|
| 82 | + $date_format = get_option('date_format'); |
|
| 83 | + $time_format = get_option('time_format'); |
|
| 84 | + $date_time_format = $date_format . ' ' . $time_format; |
|
| 85 | 85 | |
| 86 | 86 | $m_time = $post->post_date; |
| 87 | - $h_time = mysql2date( $date_format, $m_time ); |
|
| 87 | + $h_time = mysql2date($date_format, $m_time); |
|
| 88 | 88 | |
| 89 | - $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
| 89 | + $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
| 90 | 90 | break; |
| 91 | 91 | case 'payment_date' : |
| 92 | - if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) { |
|
| 93 | - $date_format = get_option( 'date_format' ); |
|
| 94 | - $time_format = get_option( 'time_format' ); |
|
| 95 | - $date_time_format = $date_format . ' '. $time_format; |
|
| 92 | + if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) { |
|
| 93 | + $date_format = get_option('date_format'); |
|
| 94 | + $time_format = get_option('time_format'); |
|
| 95 | + $date_time_format = $date_format . ' ' . $time_format; |
|
| 96 | 96 | |
| 97 | 97 | $m_time = $date_completed; |
| 98 | - $h_time = mysql2date( $date_format, $m_time ); |
|
| 98 | + $h_time = mysql2date($date_format, $m_time); |
|
| 99 | 99 | |
| 100 | - $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
| 100 | + $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
| 101 | 101 | } else { |
| 102 | 102 | $value = '-'; |
| 103 | 103 | } |
| 104 | 104 | break; |
| 105 | 105 | case 'status' : |
| 106 | - $value = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' ); |
|
| 107 | - $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID ); |
|
| 108 | - if ( 1 == $is_viewed ) { |
|
| 109 | - $value .= ' <i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 106 | + $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''); |
|
| 107 | + $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID); |
|
| 108 | + if (1 == $is_viewed) { |
|
| 109 | + $value .= ' <i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>'; |
|
| 110 | 110 | } |
| 111 | - if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() ) && ( $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ) ) ) { |
|
| 112 | - $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>'; |
|
| 111 | + if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded()) && ($gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway()))) { |
|
| 112 | + $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>'; |
|
| 113 | 113 | } |
| 114 | 114 | break; |
| 115 | 115 | case 'number' : |
| 116 | - $edit_link = get_edit_post_link( $post->ID ); |
|
| 117 | - $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>'; |
|
| 116 | + $edit_link = get_edit_post_link($post->ID); |
|
| 117 | + $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>'; |
|
| 118 | 118 | break; |
| 119 | 119 | case 'wpi_actions' : |
| 120 | 120 | $value = ''; |
| 121 | - if ( !empty( $post->post_name ) ) { |
|
| 122 | - $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
| 121 | + if (!empty($post->post_name)) { |
|
| 122 | + $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if ( $email = $wpi_invoice->get_email() ) { |
|
| 126 | - $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
| 125 | + if ($email = $wpi_invoice->get_email()) { |
|
| 126 | + $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | break; |
| 130 | 130 | default: |
| 131 | - $value = isset( $post->$column_name ) ? $post->$column_name : ''; |
|
| 131 | + $value = isset($post->$column_name) ? $post->$column_name : ''; |
|
| 132 | 132 | break; |
| 133 | 133 | |
| 134 | 134 | } |
| 135 | - $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name ); |
|
| 135 | + $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name); |
|
| 136 | 136 | |
| 137 | - if ( $value !== NULL ) { |
|
| 137 | + if ($value !== NULL) { |
|
| 138 | 138 | echo $value; |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | -function wpinv_admin_post_id( $id = 0 ) { |
|
| 142 | +function wpinv_admin_post_id($id = 0) { |
|
| 143 | 143 | global $post; |
| 144 | 144 | |
| 145 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
| 145 | + if (isset($id) && !empty($id)) { |
|
| 146 | 146 | return (int)$id; |
| 147 | - } else if ( get_the_ID() ) { |
|
| 148 | - return (int) get_the_ID(); |
|
| 149 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
| 150 | - return (int) $post->ID; |
|
| 151 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
| 152 | - return (int) $_GET['post']; |
|
| 153 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
| 154 | - return (int) $_GET['id']; |
|
| 155 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
| 156 | - return (int) $_POST['id']; |
|
| 147 | + } else if (get_the_ID()) { |
|
| 148 | + return (int)get_the_ID(); |
|
| 149 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
| 150 | + return (int)$post->ID; |
|
| 151 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
| 152 | + return (int)$_GET['post']; |
|
| 153 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
| 154 | + return (int)$_GET['id']; |
|
| 155 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
| 156 | + return (int)$_POST['id']; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | return null; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | -function wpinv_admin_post_type( $id = 0 ) { |
|
| 163 | - if ( !$id ) { |
|
| 162 | +function wpinv_admin_post_type($id = 0) { |
|
| 163 | + if (!$id) { |
|
| 164 | 164 | $id = wpinv_admin_post_id(); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $type = get_post_type( $id ); |
|
| 167 | + $type = get_post_type($id); |
|
| 168 | 168 | |
| 169 | - if ( !$type ) { |
|
| 170 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
| 169 | + if (!$type) { |
|
| 170 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
| 173 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | function wpinv_admin_messages() { |
| 177 | 177 | global $wpinv_options, $pagenow, $post; |
| 178 | 178 | |
| 179 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 180 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
| 179 | + if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 180 | + add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 184 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
| 183 | + if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 184 | + add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error'); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 188 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
| 187 | + if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 188 | + add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error'); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 192 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
| 191 | + if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 192 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated'); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 196 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
| 195 | + if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 196 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error'); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 200 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
| 199 | + if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 200 | + add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 204 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
| 203 | + if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 204 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error'); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 208 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
| 207 | + if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 208 | + add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated'); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 212 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
| 211 | + if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 212 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error'); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 216 | - add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
|
| 215 | + if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 216 | + add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated'); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 220 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
| 219 | + if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 220 | + add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated'); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 224 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
| 223 | + if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 224 | + add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated'); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 228 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
| 227 | + if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 228 | + add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated'); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
| 232 | - $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
| 231 | + if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) { |
|
| 232 | + $message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID); |
|
| 233 | 233 | |
| 234 | - if ( !empty( $message ) ) { |
|
| 235 | - add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
| 234 | + if (!empty($message)) { |
|
| 235 | + add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated'); |
|
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - settings_errors( 'wpinv-notices' ); |
|
| 239 | + settings_errors('wpinv-notices'); |
|
| 240 | 240 | } |
| 241 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
| 241 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
| 242 | 242 | |
| 243 | -add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
|
| 244 | -function wpinv_show_test_payment_gateway_notice(){ |
|
| 245 | - add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
|
| 243 | +add_action('admin_init', 'wpinv_show_test_payment_gateway_notice'); |
|
| 244 | +function wpinv_show_test_payment_gateway_notice() { |
|
| 245 | + add_action('admin_notices', 'wpinv_test_payment_gateway_messages'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | -function wpinv_test_payment_gateway_messages(){ |
|
| 248 | +function wpinv_test_payment_gateway_messages() { |
|
| 249 | 249 | $gateways = wpinv_get_enabled_payment_gateways(); |
| 250 | 250 | $name = array(); $test_gateways = ''; |
| 251 | 251 | if ($gateways) { |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | $test_gateways = implode(', ', $name); |
| 258 | 258 | } |
| 259 | - if(isset($test_gateways) && !empty($test_gateways)){ |
|
| 259 | + if (isset($test_gateways) && !empty($test_gateways)) { |
|
| 260 | 260 | $link = admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
| 261 | - $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link ); |
|
| 261 | + $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link); |
|
| 262 | 262 | ?> |
| 263 | 263 | <div class="notice notice-warning is-dismissible"> |
| 264 | 264 | <p><?php echo $notice; ?></p> |
@@ -267,29 +267,29 @@ discard block |
||
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | -function wpinv_items_columns( $existing_columns ) { |
|
| 270 | +function wpinv_items_columns($existing_columns) { |
|
| 271 | 271 | global $wpinv_euvat; |
| 272 | 272 | |
| 273 | 273 | $columns = array(); |
| 274 | 274 | $columns['cb'] = $existing_columns['cb']; |
| 275 | - $columns['title'] = __( 'Title', 'invoicing' ); |
|
| 276 | - $columns['price'] = __( 'Price', 'invoicing' ); |
|
| 277 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 278 | - $columns['vat_rule'] = __( 'VAT rule type', 'invoicing' ); |
|
| 275 | + $columns['title'] = __('Title', 'invoicing'); |
|
| 276 | + $columns['price'] = __('Price', 'invoicing'); |
|
| 277 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
| 278 | + $columns['vat_rule'] = __('VAT rule type', 'invoicing'); |
|
| 279 | 279 | } |
| 280 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 281 | - $columns['vat_class'] = __( 'VAT class', 'invoicing' ); |
|
| 280 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
| 281 | + $columns['vat_class'] = __('VAT class', 'invoicing'); |
|
| 282 | 282 | } |
| 283 | - $columns['type'] = __( 'Type', 'invoicing' ); |
|
| 284 | - $columns['recurring'] = __( 'Recurring', 'invoicing' ); |
|
| 285 | - $columns['date'] = __( 'Date', 'invoicing' ); |
|
| 286 | - $columns['id'] = __( 'ID', 'invoicing' ); |
|
| 283 | + $columns['type'] = __('Type', 'invoicing'); |
|
| 284 | + $columns['recurring'] = __('Recurring', 'invoicing'); |
|
| 285 | + $columns['date'] = __('Date', 'invoicing'); |
|
| 286 | + $columns['id'] = __('ID', 'invoicing'); |
|
| 287 | 287 | |
| 288 | - return apply_filters( 'wpinv_items_columns', $columns ); |
|
| 288 | + return apply_filters('wpinv_items_columns', $columns); |
|
| 289 | 289 | } |
| 290 | -add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' ); |
|
| 290 | +add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns'); |
|
| 291 | 291 | |
| 292 | -function wpinv_items_sortable_columns( $columns ) { |
|
| 292 | +function wpinv_items_sortable_columns($columns) { |
|
| 293 | 293 | $columns['price'] = 'price'; |
| 294 | 294 | $columns['vat_rule'] = 'vat_rule'; |
| 295 | 295 | $columns['vat_class'] = 'vat_class'; |
@@ -299,151 +299,151 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | return $columns; |
| 301 | 301 | } |
| 302 | -add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' ); |
|
| 302 | +add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns'); |
|
| 303 | 303 | |
| 304 | -function wpinv_items_table_custom_column( $column ) { |
|
| 304 | +function wpinv_items_table_custom_column($column) { |
|
| 305 | 305 | global $wpinv_euvat, $post, $wpi_item; |
| 306 | 306 | |
| 307 | - if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) { |
|
| 308 | - $wpi_item = new WPInv_Item( $post->ID ); |
|
| 307 | + if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) { |
|
| 308 | + $wpi_item = new WPInv_Item($post->ID); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - switch ( $column ) { |
|
| 311 | + switch ($column) { |
|
| 312 | 312 | case 'price' : |
| 313 | - echo wpinv_item_price( $post->ID ); |
|
| 313 | + echo wpinv_item_price($post->ID); |
|
| 314 | 314 | break; |
| 315 | 315 | case 'vat_rule' : |
| 316 | - echo $wpinv_euvat->item_rule_label( $post->ID ); |
|
| 316 | + echo $wpinv_euvat->item_rule_label($post->ID); |
|
| 317 | 317 | break; |
| 318 | 318 | case 'vat_class' : |
| 319 | - echo $wpinv_euvat->item_class_label( $post->ID ); |
|
| 319 | + echo $wpinv_euvat->item_class_label($post->ID); |
|
| 320 | 320 | break; |
| 321 | 321 | case 'type' : |
| 322 | - echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>'; |
|
| 322 | + echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>'; |
|
| 323 | 323 | break; |
| 324 | 324 | case 'recurring' : |
| 325 | - echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' ); |
|
| 325 | + echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>'); |
|
| 326 | 326 | break; |
| 327 | 327 | case 'id' : |
| 328 | 328 | echo $post->ID; |
| 329 | 329 | echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
| 330 | - <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
|
| 331 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 332 | - echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |
|
| 330 | + <div class="price">' . wpinv_get_item_price($post->ID) . '</div>'; |
|
| 331 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
| 332 | + echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>'; |
|
| 333 | 333 | } |
| 334 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 335 | - echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>'; |
|
| 334 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
| 335 | + echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>'; |
|
| 336 | 336 | } |
| 337 | - echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div> |
|
| 337 | + echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div> |
|
| 338 | 338 | </div>'; |
| 339 | 339 | break; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post ); |
|
| 342 | + do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post); |
|
| 343 | 343 | } |
| 344 | -add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' ); |
|
| 344 | +add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column'); |
|
| 345 | 345 | |
| 346 | 346 | function wpinv_add_items_filters() { |
| 347 | 347 | global $wpinv_euvat, $typenow; |
| 348 | 348 | |
| 349 | 349 | // Checks if the current post type is 'item' |
| 350 | - if ( $typenow == 'wpi_item') { |
|
| 351 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 352 | - echo wpinv_html_select( array( |
|
| 353 | - 'options' => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ), |
|
| 350 | + if ($typenow == 'wpi_item') { |
|
| 351 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
| 352 | + echo wpinv_html_select(array( |
|
| 353 | + 'options' => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()), |
|
| 354 | 354 | 'name' => 'vat_rule', |
| 355 | 355 | 'id' => 'vat_rule', |
| 356 | - 'selected' => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ), |
|
| 356 | + 'selected' => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''), |
|
| 357 | 357 | 'show_option_all' => false, |
| 358 | 358 | 'show_option_none' => false, |
| 359 | 359 | 'class' => 'gdmbx2-text-medium wpi_select2', |
| 360 | - ) ); |
|
| 360 | + )); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 364 | - echo wpinv_html_select( array( |
|
| 365 | - 'options' => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ), |
|
| 363 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
| 364 | + echo wpinv_html_select(array( |
|
| 365 | + 'options' => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()), |
|
| 366 | 366 | 'name' => 'vat_class', |
| 367 | 367 | 'id' => 'vat_class', |
| 368 | - 'selected' => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ), |
|
| 368 | + 'selected' => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''), |
|
| 369 | 369 | 'show_option_all' => false, |
| 370 | 370 | 'show_option_none' => false, |
| 371 | 371 | 'class' => 'gdmbx2-text-medium wpi_select2', |
| 372 | - ) ); |
|
| 372 | + )); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - echo wpinv_html_select( array( |
|
| 376 | - 'options' => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ), |
|
| 375 | + echo wpinv_html_select(array( |
|
| 376 | + 'options' => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()), |
|
| 377 | 377 | 'name' => 'type', |
| 378 | 378 | 'id' => 'type', |
| 379 | - 'selected' => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ), |
|
| 379 | + 'selected' => (isset($_GET['type']) ? $_GET['type'] : ''), |
|
| 380 | 380 | 'show_option_all' => false, |
| 381 | 381 | 'show_option_none' => false, |
| 382 | 382 | 'class' => 'gdmbx2-text-medium', |
| 383 | - ) ); |
|
| 383 | + )); |
|
| 384 | 384 | |
| 385 | - if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) { |
|
| 385 | + if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) { |
|
| 386 | 386 | echo '<input type="hidden" name="all_posts" value="1" />'; |
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | -add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 ); |
|
| 390 | +add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100); |
|
| 391 | 391 | |
| 392 | -function wpinv_send_invoice_after_save( $invoice ) { |
|
| 393 | - if ( empty( $_POST['wpi_save_send'] ) ) { |
|
| 392 | +function wpinv_send_invoice_after_save($invoice) { |
|
| 393 | + if (empty($_POST['wpi_save_send'])) { |
|
| 394 | 394 | return; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) { |
|
| 398 | - wpinv_user_invoice_notification( $invoice->ID ); |
|
| 397 | + if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) { |
|
| 398 | + wpinv_user_invoice_notification($invoice->ID); |
|
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | -add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 ); |
|
| 401 | +add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1); |
|
| 402 | 402 | |
| 403 | -function wpinv_send_register_new_user( $data, $postarr ) { |
|
| 404 | - if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) { |
|
| 405 | - $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false; |
|
| 406 | - $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL; |
|
| 403 | +function wpinv_send_register_new_user($data, $postarr) { |
|
| 404 | + if (current_user_can('manage_options') && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) { |
|
| 405 | + $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false; |
|
| 406 | + $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL; |
|
| 407 | 407 | |
| 408 | - if ( $is_new_user && $email && !email_exists( $email ) ) { |
|
| 409 | - $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : ''; |
|
| 410 | - $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : ''; |
|
| 411 | - $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : ''; |
|
| 412 | - $user_nicename = $display_name ? trim( $display_name ) : $email; |
|
| 413 | - $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : ''; |
|
| 408 | + if ($is_new_user && $email && !email_exists($email)) { |
|
| 409 | + $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : ''; |
|
| 410 | + $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : ''; |
|
| 411 | + $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : ''; |
|
| 412 | + $user_nicename = $display_name ? trim($display_name) : $email; |
|
| 413 | + $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : ''; |
|
| 414 | 414 | |
| 415 | - $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true ); |
|
| 416 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
| 415 | + $user_login = sanitize_user(str_replace(' ', '', $display_name), true); |
|
| 416 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
| 417 | 417 | $new_user_login = strstr($email, '@', true); |
| 418 | - if ( validate_username( $user_login ) && username_exists( $user_login ) ) { |
|
| 419 | - $user_login = sanitize_user($new_user_login, true ); |
|
| 418 | + if (validate_username($user_login) && username_exists($user_login)) { |
|
| 419 | + $user_login = sanitize_user($new_user_login, true); |
|
| 420 | 420 | } |
| 421 | - if ( validate_username( $user_login ) && username_exists( $user_login ) ) { |
|
| 422 | - $user_append_text = rand(10,1000); |
|
| 423 | - $user_login = sanitize_user($new_user_login.$user_append_text, true ); |
|
| 421 | + if (validate_username($user_login) && username_exists($user_login)) { |
|
| 422 | + $user_append_text = rand(10, 1000); |
|
| 423 | + $user_login = sanitize_user($new_user_login . $user_append_text, true); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
| 426 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
| 427 | 427 | $user_login = $email; |
| 428 | 428 | } |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | $userdata = array( |
| 432 | 432 | 'user_login' => $user_login, |
| 433 | - 'user_pass' => wp_generate_password( 12, false ), |
|
| 434 | - 'user_email' => sanitize_text_field( $email ), |
|
| 433 | + 'user_pass' => wp_generate_password(12, false), |
|
| 434 | + 'user_email' => sanitize_text_field($email), |
|
| 435 | 435 | 'first_name' => $first_name, |
| 436 | 436 | 'last_name' => $last_name, |
| 437 | - 'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ), |
|
| 437 | + 'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50), |
|
| 438 | 438 | 'nickname' => $display_name, |
| 439 | 439 | 'display_name' => $display_name, |
| 440 | 440 | ); |
| 441 | 441 | |
| 442 | - $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata ); |
|
| 442 | + $userdata = apply_filters('wpinv_register_new_user_data', $userdata); |
|
| 443 | 443 | |
| 444 | - $new_user_id = wp_insert_user( $userdata ); |
|
| 444 | + $new_user_id = wp_insert_user($userdata); |
|
| 445 | 445 | |
| 446 | - if ( !is_wp_error( $new_user_id ) ) { |
|
| 446 | + if (!is_wp_error($new_user_id)) { |
|
| 447 | 447 | $data['post_author'] = $new_user_id; |
| 448 | 448 | $_POST['post_author'] = $new_user_id; |
| 449 | 449 | $_POST['post_author_override'] = $new_user_id; |
@@ -464,72 +464,72 @@ discard block |
||
| 464 | 464 | |
| 465 | 465 | $meta = array(); |
| 466 | 466 | ///$meta['_wpinv_user_id'] = $new_user_id; |
| 467 | - foreach ( $meta_fields as $field ) { |
|
| 468 | - $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : ''; |
|
| 467 | + foreach ($meta_fields as $field) { |
|
| 468 | + $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : ''; |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id ); |
|
| 471 | + $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id); |
|
| 472 | 472 | |
| 473 | 473 | // Update user meta. |
| 474 | - foreach ( $meta as $key => $value ) { |
|
| 475 | - update_user_meta( $new_user_id, $key, $value ); |
|
| 474 | + foreach ($meta as $key => $value) { |
|
| 475 | + update_user_meta($new_user_id, $key, $value); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - if ( function_exists( 'wp_send_new_user_notifications' ) ) { |
|
| 478 | + if (function_exists('wp_send_new_user_notifications')) { |
|
| 479 | 479 | // Send email notifications related to the creation of new user. |
| 480 | - wp_send_new_user_notifications( $new_user_id, 'user' ); |
|
| 480 | + wp_send_new_user_notifications($new_user_id, 'user'); |
|
| 481 | 481 | } |
| 482 | 482 | } else { |
| 483 | - wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ ); |
|
| 483 | + wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__); |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | return $data; |
| 489 | 489 | } |
| 490 | -add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 ); |
|
| 490 | +add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2); |
|
| 491 | 491 | |
| 492 | -function wpinv_show_recurring_supported_gateways( $item_ID ) { |
|
| 492 | +function wpinv_show_recurring_supported_gateways($item_ID) { |
|
| 493 | 493 | $all_gateways = wpinv_get_payment_gateways(); |
| 494 | 494 | |
| 495 | - if ( !empty( $all_gateways ) ) { |
|
| 495 | + if (!empty($all_gateways)) { |
|
| 496 | 496 | $gateways = array(); |
| 497 | 497 | |
| 498 | - foreach ( $all_gateways as $key => $gateway ) { |
|
| 499 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
| 498 | + foreach ($all_gateways as $key => $gateway) { |
|
| 499 | + if (wpinv_gateway_support_subscription($key)) { |
|
| 500 | 500 | $gateways[] = $gateway['admin_label']; |
| 501 | 501 | } |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - if ( !empty( $gateways ) ) { |
|
| 504 | + if (!empty($gateways)) { |
|
| 505 | 505 | ?> |
| 506 | - <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span> |
|
| 506 | + <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span> |
|
| 507 | 507 | <?php |
| 508 | 508 | } |
| 509 | 509 | } |
| 510 | 510 | } |
| 511 | -add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 ); |
|
| 511 | +add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1); |
|
| 512 | 512 | |
| 513 | -function wpinv_post_updated_messages( $messages ) { |
|
| 513 | +function wpinv_post_updated_messages($messages) { |
|
| 514 | 514 | global $post, $post_ID; |
| 515 | 515 | |
| 516 | 516 | $messages['wpi_discount'] = array( |
| 517 | 517 | 0 => '', |
| 518 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 519 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 520 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 521 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 522 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 523 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 524 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 525 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 526 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 527 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 518 | + 1 => __('Discount updated.', 'invoicing'), |
|
| 519 | + 2 => __('Custom field updated.', 'invoicing'), |
|
| 520 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
| 521 | + 4 => __('Discount updated.', 'invoicing'), |
|
| 522 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int)$_GET['revision'], false)) : false, |
|
| 523 | + 6 => __('Discount updated.', 'invoicing'), |
|
| 524 | + 7 => __('Discount saved.', 'invoicing'), |
|
| 525 | + 8 => __('Discount submitted.', 'invoicing'), |
|
| 526 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
| 527 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
| 528 | 528 | ); |
| 529 | 529 | |
| 530 | 530 | return $messages; |
| 531 | 531 | } |
| 532 | -add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 ); |
|
| 532 | +add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1); |
|
| 533 | 533 | |
| 534 | 534 | add_action('admin_init', 'admin_init_example_type'); |
| 535 | 535 | |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | function admin_init_example_type() { |
| 540 | 540 | global $typenow; |
| 541 | 541 | |
| 542 | - if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) { |
|
| 542 | + if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') { |
|
| 543 | 543 | add_filter('posts_search', 'posts_search_example_type', 10, 2); |
| 544 | 544 | } |
| 545 | 545 | } |
@@ -554,9 +554,9 @@ discard block |
||
| 554 | 554 | global $wpdb; |
| 555 | 555 | |
| 556 | 556 | if ($query->is_main_query() && !empty($query->query['s'])) { |
| 557 | - $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )"; |
|
| 558 | - if ( ! empty( $search ) ) { |
|
| 559 | - $search = preg_replace( '/^ AND /', '', $search ); |
|
| 557 | + $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )"; |
|
| 558 | + if (!empty($search)) { |
|
| 559 | + $search = preg_replace('/^ AND /', '', $search); |
|
| 560 | 560 | $search = " AND ( {$search} OR ( {$conditions_str} ) )"; |
| 561 | 561 | } else { |
| 562 | 562 | $search = " AND ( {$conditions_str} )"; |
@@ -566,9 +566,9 @@ discard block |
||
| 566 | 566 | return $search; |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | -add_action( 'admin_init', 'wpinv_reset_invoice_count' ); |
|
| 570 | -function wpinv_reset_invoice_count(){ |
|
| 571 | - if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
| 569 | +add_action('admin_init', 'wpinv_reset_invoice_count'); |
|
| 570 | +function wpinv_reset_invoice_count() { |
|
| 571 | + if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
| 572 | 572 | wpinv_update_option('invoice_sequence_start', 1); |
| 573 | 573 | delete_option('wpinv_last_invoice_number'); |
| 574 | 574 | $url = add_query_arg(array('reset_invoice_done' => 1)); |
@@ -579,8 +579,8 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | add_action('admin_notices', 'wpinv_invoice_count_reset_message'); |
| 582 | -function wpinv_invoice_count_reset_message(){ |
|
| 583 | - if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) { |
|
| 582 | +function wpinv_invoice_count_reset_message() { |
|
| 583 | + if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) { |
|
| 584 | 584 | $notice = __('Invoice number sequence reset successfully.', 'invoicing'); |
| 585 | 585 | ?> |
| 586 | 586 | <div class="notice notice-success is-dismissible"> |
@@ -7,90 +7,90 @@ 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_get_discount_types() { |
| 15 | 15 | $discount_types = array( |
| 16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
| 17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
| 16 | + 'percent' => __('Percentage', 'invoicing'), |
|
| 17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
| 18 | 18 | ); |
| 19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
| 19 | + return (array)apply_filters('wpinv_discount_types', $discount_types); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
| 22 | +function wpinv_get_discount_type_name($type = '') { |
|
| 23 | 23 | $types = wpinv_get_discount_types(); |
| 24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
| 24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | -function wpinv_delete_discount( $data ) { |
|
| 28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 27 | +function wpinv_delete_discount($data) { |
|
| 28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if( ! current_user_can( 'manage_options' ) ) { |
|
| 33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 32 | + if (!current_user_can('manage_options')) { |
|
| 33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $discount_id = $data['discount']; |
| 37 | - wpinv_remove_discount( $discount_id ); |
|
| 37 | + wpinv_remove_discount($discount_id); |
|
| 38 | 38 | } |
| 39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
| 39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
| 40 | 40 | |
| 41 | -function wpinv_activate_discount( $data ) { |
|
| 42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 41 | +function wpinv_activate_discount($data) { |
|
| 42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if( ! current_user_can( 'manage_options' ) ) { |
|
| 47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 46 | + if (!current_user_can('manage_options')) { |
|
| 47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $id = absint( $data['discount'] ); |
|
| 51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
| 50 | + $id = absint($data['discount']); |
|
| 51 | + wpinv_update_discount_status($id, 'publish'); |
|
| 52 | 52 | } |
| 53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
| 53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
| 54 | 54 | |
| 55 | -function wpinv_deactivate_discount( $data ) { |
|
| 56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 55 | +function wpinv_deactivate_discount($data) { |
|
| 56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if( ! current_user_can( 'manage_options' ) ) { |
|
| 61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 60 | + if (!current_user_can('manage_options')) { |
|
| 61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $id = absint( $data['discount'] ); |
|
| 65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
| 64 | + $id = absint($data['discount']); |
|
| 65 | + wpinv_update_discount_status($id, 'pending'); |
|
| 66 | 66 | } |
| 67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
| 67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
| 68 | 68 | |
| 69 | -function wpinv_get_discounts( $args = array() ) { |
|
| 69 | +function wpinv_get_discounts($args = array()) { |
|
| 70 | 70 | $defaults = array( |
| 71 | 71 | 'post_type' => 'wpi_discount', |
| 72 | 72 | 'posts_per_page' => 20, |
| 73 | 73 | 'paged' => null, |
| 74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
| 74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | - $args = wp_parse_args( $args, $defaults ); |
|
| 77 | + $args = wp_parse_args($args, $defaults); |
|
| 78 | 78 | |
| 79 | - $discounts = get_posts( $args ); |
|
| 79 | + $discounts = get_posts($args); |
|
| 80 | 80 | |
| 81 | - if ( $discounts ) { |
|
| 81 | + if ($discounts) { |
|
| 82 | 82 | return $discounts; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
| 85 | + if (!$discounts && !empty($args['s'])) { |
|
| 86 | 86 | $args['meta_key'] = '_wpi_discount_code'; |
| 87 | 87 | $args['meta_value'] = $args['s']; |
| 88 | 88 | $args['meta_compare'] = 'LIKE'; |
| 89 | - unset( $args['s'] ); |
|
| 90 | - $discounts = get_posts( $args ); |
|
| 89 | + unset($args['s']); |
|
| 90 | + $discounts = get_posts($args); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if( $discounts ) { |
|
| 93 | + if ($discounts) { |
|
| 94 | 94 | return $discounts; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | $discounts = wpinv_get_discounts(); |
| 104 | 104 | |
| 105 | - if ( $discounts) { |
|
| 106 | - foreach ( $discounts as $discount ) { |
|
| 107 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
| 105 | + if ($discounts) { |
|
| 106 | + foreach ($discounts as $discount) { |
|
| 107 | + if (wpinv_is_discount_active($discount->ID)) { |
|
| 108 | 108 | $has_active = true; |
| 109 | 109 | break; |
| 110 | 110 | } |
@@ -113,38 +113,38 @@ discard block |
||
| 113 | 113 | return $has_active; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
| 117 | - if( empty( $discount_id ) ) { |
|
| 116 | +function wpinv_get_discount($discount_id = 0) { |
|
| 117 | + if (empty($discount_id)) { |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
| 121 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $discount = get_post( $discount_id ); |
|
| 125 | + $discount = get_post($discount_id); |
|
| 126 | 126 | |
| 127 | 127 | return $discount; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
| 131 | - if( empty( $code ) || ! is_string( $code ) ) { |
|
| 130 | +function wpinv_get_discount_by_code($code = '') { |
|
| 131 | + if (empty($code) || !is_string($code)) { |
|
| 132 | 132 | return false; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - return wpinv_get_discount_by( 'code', $code ); |
|
| 135 | + return wpinv_get_discount_by('code', $code); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
| 139 | - if( empty( $field ) || empty( $value ) ) { |
|
| 138 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
| 139 | + if (empty($field) || empty($value)) { |
|
| 140 | 140 | return false; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if( ! is_string( $field ) ) { |
|
| 143 | + if (!is_string($field)) { |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - switch( strtolower( $field ) ) { |
|
| 147 | + switch (strtolower($field)) { |
|
| 148 | 148 | |
| 149 | 149 | case 'code': |
| 150 | 150 | $meta_query = array(); |
@@ -154,32 +154,32 @@ discard block |
||
| 154 | 154 | 'compare' => '=' |
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | - $discount = wpinv_get_discounts( array( |
|
| 157 | + $discount = wpinv_get_discounts(array( |
|
| 158 | 158 | 'posts_per_page' => 1, |
| 159 | 159 | 'post_status' => 'any', |
| 160 | 160 | 'meta_query' => $meta_query, |
| 161 | - ) ); |
|
| 161 | + )); |
|
| 162 | 162 | |
| 163 | - if( $discount ) { |
|
| 163 | + if ($discount) { |
|
| 164 | 164 | $discount = $discount[0]; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | break; |
| 168 | 168 | |
| 169 | 169 | case 'id': |
| 170 | - $discount = wpinv_get_discount( $value ); |
|
| 170 | + $discount = wpinv_get_discount($value); |
|
| 171 | 171 | |
| 172 | 172 | break; |
| 173 | 173 | |
| 174 | 174 | case 'name': |
| 175 | - $discount = get_posts( array( |
|
| 175 | + $discount = get_posts(array( |
|
| 176 | 176 | 'post_type' => 'wpi_discount', |
| 177 | 177 | 'name' => $value, |
| 178 | 178 | 'posts_per_page' => 1, |
| 179 | 179 | 'post_status' => 'any' |
| 180 | - ) ); |
|
| 180 | + )); |
|
| 181 | 181 | |
| 182 | - if( $discount ) { |
|
| 182 | + if ($discount) { |
|
| 183 | 183 | $discount = $discount[0]; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -189,96 +189,96 @@ discard block |
||
| 189 | 189 | return false; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if( ! empty( $discount ) ) { |
|
| 192 | + if (!empty($discount)) { |
|
| 193 | 193 | return $discount; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
| 199 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
| 200 | 200 | $meta = array( |
| 201 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
| 202 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
| 203 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
| 204 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
| 205 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
| 206 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
| 207 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
| 208 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
| 209 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
| 210 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
| 211 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
| 212 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
| 213 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
| 201 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
| 202 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
| 203 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
| 204 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
| 205 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
| 206 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
| 207 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
| 208 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
| 209 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
| 210 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
| 211 | + 'is_recurring' => isset($data['recurring']) ? (bool)$data['recurring'] : false, |
|
| 212 | + 'is_single_use' => isset($data['single_use']) ? (bool)$data['single_use'] : false, |
|
| 213 | + 'uses' => isset($data['uses']) ? (int)$data['uses'] : false, |
|
| 214 | 214 | ); |
| 215 | 215 | |
| 216 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
| 216 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
| 217 | 217 | $meta['amount'] = 100; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if ( !empty( $meta['start'] ) ) { |
|
| 221 | - $meta['start'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) ); |
|
| 220 | + if (!empty($meta['start'])) { |
|
| 221 | + $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start'])); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if ( !empty( $meta['expiration'] ) ) { |
|
| 225 | - $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) ); |
|
| 224 | + if (!empty($meta['expiration'])) { |
|
| 225 | + $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration'])); |
|
| 226 | 226 | |
| 227 | - if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) { |
|
| 227 | + if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) { |
|
| 228 | 228 | $meta['expiration'] = $meta['start']; |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ( $meta['uses'] === false ) { |
|
| 233 | - unset( $meta['uses'] ); |
|
| 232 | + if ($meta['uses'] === false) { |
|
| 233 | + unset($meta['uses']); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if ( ! empty( $meta['items'] ) ) { |
|
| 237 | - foreach ( $meta['items'] as $key => $item ) { |
|
| 238 | - if ( 0 === intval( $item ) ) { |
|
| 239 | - unset( $meta['items'][ $key ] ); |
|
| 236 | + if (!empty($meta['items'])) { |
|
| 237 | + foreach ($meta['items'] as $key => $item) { |
|
| 238 | + if (0 === intval($item)) { |
|
| 239 | + unset($meta['items'][$key]); |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
| 245 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
| 246 | - if ( 0 === intval( $item ) ) { |
|
| 247 | - unset( $meta['excluded_items'][ $key ] ); |
|
| 244 | + if (!empty($meta['excluded_items'])) { |
|
| 245 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
| 246 | + if (0 === intval($item)) { |
|
| 247 | + unset($meta['excluded_items'][$key]); |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
| 252 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
| 253 | 253 | |
| 254 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
| 254 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
| 255 | 255 | |
| 256 | - foreach( $meta as $key => $value ) { |
|
| 257 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
| 256 | + foreach ($meta as $key => $value) { |
|
| 257 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
| 260 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
| 261 | 261 | |
| 262 | 262 | return $post_id; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
| 266 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
| 265 | +function wpinv_remove_discount($discount_id = 0) { |
|
| 266 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
| 267 | 267 | |
| 268 | - wp_delete_post( $discount_id, true ); |
|
| 268 | + wp_delete_post($discount_id, true); |
|
| 269 | 269 | |
| 270 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
| 270 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
| 274 | - $discount = wpinv_get_discount( $code_id ); |
|
| 273 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
| 274 | + $discount = wpinv_get_discount($code_id); |
|
| 275 | 275 | |
| 276 | - if ( $discount ) { |
|
| 277 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
| 276 | + if ($discount) { |
|
| 277 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
| 278 | 278 | |
| 279 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
| 279 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
| 280 | 280 | |
| 281 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
| 281 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
| 282 | 282 | |
| 283 | 283 | return true; |
| 284 | 284 | } |
@@ -286,173 +286,173 @@ discard block |
||
| 286 | 286 | return false; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | -function wpinv_discount_exists( $code_id ) { |
|
| 290 | - if ( wpinv_get_discount( $code_id ) ) { |
|
| 289 | +function wpinv_discount_exists($code_id) { |
|
| 290 | + if (wpinv_get_discount($code_id)) { |
|
| 291 | 291 | return true; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | return false; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | -function wpinv_is_discount_active( $code_id = null ) { |
|
| 298 | - $discount = wpinv_get_discount( $code_id ); |
|
| 297 | +function wpinv_is_discount_active($code_id = null) { |
|
| 298 | + $discount = wpinv_get_discount($code_id); |
|
| 299 | 299 | $return = false; |
| 300 | 300 | |
| 301 | - if ( $discount ) { |
|
| 302 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
| 303 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 304 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
| 301 | + if ($discount) { |
|
| 302 | + if (wpinv_is_discount_expired($code_id)) { |
|
| 303 | + if (defined('DOING_AJAX')) { |
|
| 304 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
| 305 | 305 | } |
| 306 | - } elseif ( $discount->post_status == 'publish' ) { |
|
| 306 | + } elseif ($discount->post_status == 'publish') { |
|
| 307 | 307 | $return = true; |
| 308 | 308 | } else { |
| 309 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 310 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
| 309 | + if (defined('DOING_AJAX')) { |
|
| 310 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
| 315 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | -function wpinv_get_discount_code( $code_id = null ) { |
|
| 319 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
| 318 | +function wpinv_get_discount_code($code_id = null) { |
|
| 319 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
| 320 | 320 | |
| 321 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
| 321 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
| 325 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
| 324 | +function wpinv_get_discount_start_date($code_id = null) { |
|
| 325 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
| 326 | 326 | |
| 327 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
| 327 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
| 331 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
| 330 | +function wpinv_get_discount_expiration($code_id = null) { |
|
| 331 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
| 332 | 332 | |
| 333 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
| 333 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
| 337 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
| 336 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
| 337 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
| 338 | 338 | |
| 339 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
| 339 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
| 343 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
| 342 | +function wpinv_get_discount_uses($code_id = null) { |
|
| 343 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
| 344 | 344 | |
| 345 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
| 345 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
| 349 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
| 348 | +function wpinv_get_discount_min_total($code_id = null) { |
|
| 349 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
| 350 | 350 | |
| 351 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
| 351 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
| 355 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
| 354 | +function wpinv_get_discount_max_total($code_id = null) { |
|
| 355 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
| 356 | 356 | |
| 357 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
| 357 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
| 361 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
| 360 | +function wpinv_get_discount_amount($code_id = null) { |
|
| 361 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
| 362 | 362 | |
| 363 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
| 363 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
| 367 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
| 366 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
| 367 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
| 368 | 368 | |
| 369 | - if ( $name ) { |
|
| 370 | - $name = wpinv_get_discount_type_name( $type ); |
|
| 369 | + if ($name) { |
|
| 370 | + $name = wpinv_get_discount_type_name($type); |
|
| 371 | 371 | |
| 372 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
| 372 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
| 375 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | -function wpinv_discount_status( $status ) { |
|
| 379 | - switch( $status ){ |
|
| 378 | +function wpinv_discount_status($status) { |
|
| 379 | + switch ($status) { |
|
| 380 | 380 | case 'expired' : |
| 381 | - $name = __( 'Expired', 'invoicing' ); |
|
| 381 | + $name = __('Expired', 'invoicing'); |
|
| 382 | 382 | break; |
| 383 | 383 | case 'publish' : |
| 384 | 384 | case 'active' : |
| 385 | - $name = __( 'Active', 'invoicing' ); |
|
| 385 | + $name = __('Active', 'invoicing'); |
|
| 386 | 386 | break; |
| 387 | 387 | default : |
| 388 | - $name = __( 'Inactive', 'invoicing' ); |
|
| 388 | + $name = __('Inactive', 'invoicing'); |
|
| 389 | 389 | break; |
| 390 | 390 | } |
| 391 | 391 | return $name; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
| 395 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
| 394 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
| 395 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
| 396 | 396 | |
| 397 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
| 397 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
| 398 | 398 | $excluded_items = array(); |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
| 401 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
| 405 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
| 404 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
| 405 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
| 406 | 406 | |
| 407 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
| 407 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
| 408 | 408 | $item_reqs = array(); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
| 411 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
| 415 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
| 414 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
| 415 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
| 419 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
| 418 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
| 419 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
| 423 | - $discount = wpinv_get_discount( $code_id ); |
|
| 422 | +function wpinv_is_discount_expired($code_id = null) { |
|
| 423 | + $discount = wpinv_get_discount($code_id); |
|
| 424 | 424 | $return = false; |
| 425 | 425 | |
| 426 | - if ( $discount ) { |
|
| 427 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
| 428 | - if ( $expiration ) { |
|
| 429 | - $expiration = strtotime( $expiration ); |
|
| 430 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
| 426 | + if ($discount) { |
|
| 427 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
| 428 | + if ($expiration) { |
|
| 429 | + $expiration = strtotime($expiration); |
|
| 430 | + if ($expiration < current_time('timestamp')) { |
|
| 431 | 431 | // Discount is expired |
| 432 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
| 432 | + wpinv_update_discount_status($code_id, 'pending'); |
|
| 433 | 433 | $return = true; |
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
| 438 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | -function wpinv_is_discount_started( $code_id = null ) { |
|
| 442 | - $discount = wpinv_get_discount( $code_id ); |
|
| 441 | +function wpinv_is_discount_started($code_id = null) { |
|
| 442 | + $discount = wpinv_get_discount($code_id); |
|
| 443 | 443 | $return = false; |
| 444 | 444 | |
| 445 | - if ( $discount ) { |
|
| 446 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
| 445 | + if ($discount) { |
|
| 446 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
| 447 | 447 | |
| 448 | - if ( $start_date ) { |
|
| 449 | - $start_date = strtotime( $start_date ); |
|
| 448 | + if ($start_date) { |
|
| 449 | + $start_date = strtotime($start_date); |
|
| 450 | 450 | |
| 451 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
| 451 | + if ($start_date < current_time('timestamp')) { |
|
| 452 | 452 | // Discount has past the start date |
| 453 | 453 | $return = true; |
| 454 | 454 | } else { |
| 455 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
| 455 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
| 456 | 456 | } |
| 457 | 457 | } else { |
| 458 | 458 | // No start date for this discount, so has to be true |
@@ -460,159 +460,159 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
| 463 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
| 467 | - $discount = wpinv_get_discount( $code_id ); |
|
| 466 | +function wpinv_check_discount_dates($code_id = null) { |
|
| 467 | + $discount = wpinv_get_discount($code_id); |
|
| 468 | 468 | $return = false; |
| 469 | 469 | |
| 470 | - if ( $discount ) { |
|
| 471 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
| 470 | + if ($discount) { |
|
| 471 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
| 472 | 472 | |
| 473 | - if ( $start_date ) { |
|
| 474 | - $start_date = strtotime( $start_date ); |
|
| 473 | + if ($start_date) { |
|
| 474 | + $start_date = strtotime($start_date); |
|
| 475 | 475 | |
| 476 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
| 476 | + if ($start_date < current_time('timestamp')) { |
|
| 477 | 477 | // Discount has past the start date |
| 478 | 478 | $return = true; |
| 479 | 479 | } else { |
| 480 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
| 480 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
| 481 | 481 | } |
| 482 | 482 | } else { |
| 483 | 483 | // No start date for this discount, so has to be true |
| 484 | 484 | $return = true; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - if ( $return ) { |
|
| 488 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
| 487 | + if ($return) { |
|
| 488 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
| 489 | 489 | |
| 490 | - if ( $expiration ) { |
|
| 491 | - $expiration = strtotime( $expiration ); |
|
| 492 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
| 490 | + if ($expiration) { |
|
| 491 | + $expiration = strtotime($expiration); |
|
| 492 | + if ($expiration < current_time('timestamp')) { |
|
| 493 | 493 | // Discount is expired |
| 494 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
| 494 | + wpinv_update_discount_status($code_id, 'pending'); |
|
| 495 | 495 | $return = true; |
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
| 501 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
| 505 | - $discount = wpinv_get_discount( $code_id ); |
|
| 504 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
| 505 | + $discount = wpinv_get_discount($code_id); |
|
| 506 | 506 | $return = false; |
| 507 | 507 | |
| 508 | - if ( $discount ) { |
|
| 509 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
| 508 | + if ($discount) { |
|
| 509 | + $uses = wpinv_get_discount_uses($code_id); |
|
| 510 | 510 | // Large number that will never be reached |
| 511 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
| 511 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
| 512 | 512 | // Should never be greater than, but just in case |
| 513 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
| 513 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
| 514 | 514 | // Discount is maxed out |
| 515 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
| 515 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
| 516 | 516 | $return = true; |
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
| 520 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
| 524 | - $discount = wpinv_get_discount( $code_id ); |
|
| 523 | +function wpinv_discount_is_min_met($code_id = null) { |
|
| 524 | + $discount = wpinv_get_discount($code_id); |
|
| 525 | 525 | $return = false; |
| 526 | 526 | |
| 527 | - if ( $discount ) { |
|
| 528 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
| 529 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
| 527 | + if ($discount) { |
|
| 528 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
| 529 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
| 530 | 530 | |
| 531 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
| 531 | + if (!$min > 0 || $cart_amount >= $min) { |
|
| 532 | 532 | // Minimum has been met |
| 533 | 533 | $return = true; |
| 534 | 534 | } else { |
| 535 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
| 535 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
| 536 | 536 | } |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
| 539 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
| 543 | - $discount = wpinv_get_discount( $code_id ); |
|
| 542 | +function wpinv_discount_is_max_met($code_id = null) { |
|
| 543 | + $discount = wpinv_get_discount($code_id); |
|
| 544 | 544 | $return = false; |
| 545 | 545 | |
| 546 | - if ( $discount ) { |
|
| 547 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
| 548 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
| 546 | + if ($discount) { |
|
| 547 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
| 548 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
| 549 | 549 | |
| 550 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
| 550 | + if (!$max > 0 || $cart_amount <= $max) { |
|
| 551 | 551 | // Minimum has been met |
| 552 | 552 | $return = true; |
| 553 | 553 | } else { |
| 554 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
| 554 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
| 558 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
| 562 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
| 563 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
| 561 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
| 562 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
| 563 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
| 567 | - if ( $code ) { |
|
| 568 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
| 566 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
| 567 | + if ($code) { |
|
| 568 | + $discount = wpinv_get_discount_by_code($code_id); |
|
| 569 | 569 | |
| 570 | - if ( !empty( $discount ) ) { |
|
| 570 | + if (!empty($discount)) { |
|
| 571 | 571 | $code_id = $discount->ID; |
| 572 | 572 | } |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
| 575 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
| 576 | 576 | |
| 577 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
| 577 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
| 581 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 582 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
| 583 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
| 580 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
| 581 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 582 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
| 583 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
| 584 | 584 | $cart_items = wpinv_get_cart_contents(); |
| 585 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
| 585 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
| 586 | 586 | $ret = false; |
| 587 | 587 | |
| 588 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
| 588 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
| 589 | 589 | $ret = true; |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | // Normalize our data for item requirements, exclusions and cart data |
| 593 | 593 | // First absint the items, then sort, and reset the array keys |
| 594 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
| 595 | - asort( $item_reqs ); |
|
| 596 | - $item_reqs = array_values( $item_reqs ); |
|
| 594 | + $item_reqs = array_map('absint', $item_reqs); |
|
| 595 | + asort($item_reqs); |
|
| 596 | + $item_reqs = array_values($item_reqs); |
|
| 597 | 597 | |
| 598 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
| 599 | - asort( $excluded_ps ); |
|
| 600 | - $excluded_ps = array_values( $excluded_ps ); |
|
| 598 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
| 599 | + asort($excluded_ps); |
|
| 600 | + $excluded_ps = array_values($excluded_ps); |
|
| 601 | 601 | |
| 602 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
| 603 | - asort( $cart_ids ); |
|
| 604 | - $cart_ids = array_values( $cart_ids ); |
|
| 602 | + $cart_ids = array_map('absint', $cart_ids); |
|
| 603 | + asort($cart_ids); |
|
| 604 | + $cart_ids = array_values($cart_ids); |
|
| 605 | 605 | |
| 606 | 606 | // Ensure we have requirements before proceeding |
| 607 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
| 608 | - switch( $condition ) { |
|
| 607 | + if (!$ret && !empty($item_reqs)) { |
|
| 608 | + switch ($condition) { |
|
| 609 | 609 | case 'all' : |
| 610 | 610 | // Default back to true |
| 611 | 611 | $ret = true; |
| 612 | 612 | |
| 613 | - foreach ( $item_reqs as $item_id ) { |
|
| 614 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
| 615 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 613 | + foreach ($item_reqs as $item_id) { |
|
| 614 | + if (!wpinv_item_in_cart($item_id)) { |
|
| 615 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 616 | 616 | $ret = false; |
| 617 | 617 | break; |
| 618 | 618 | } |
@@ -621,15 +621,15 @@ discard block |
||
| 621 | 621 | break; |
| 622 | 622 | |
| 623 | 623 | default : // Any |
| 624 | - foreach ( $item_reqs as $item_id ) { |
|
| 625 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
| 624 | + foreach ($item_reqs as $item_id) { |
|
| 625 | + if (wpinv_item_in_cart($item_id)) { |
|
| 626 | 626 | $ret = true; |
| 627 | 627 | break; |
| 628 | 628 | } |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - if( ! $ret ) { |
|
| 632 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 631 | + if (!$ret) { |
|
| 632 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | break; |
@@ -638,70 +638,70 @@ discard block |
||
| 638 | 638 | $ret = true; |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - if( ! empty( $excluded_ps ) ) { |
|
| 641 | + if (!empty($excluded_ps)) { |
|
| 642 | 642 | // Check that there are items other than excluded ones in the cart |
| 643 | - if( $cart_ids == $excluded_ps ) { |
|
| 644 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
| 643 | + if ($cart_ids == $excluded_ps) { |
|
| 644 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
| 645 | 645 | $ret = false; |
| 646 | 646 | } |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
| 649 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
| 652 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
| 653 | 653 | global $wpi_checkout_id; |
| 654 | 654 | |
| 655 | 655 | $return = false; |
| 656 | 656 | |
| 657 | - if ( empty( $code_id ) ) { |
|
| 658 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
| 657 | + if (empty($code_id)) { |
|
| 658 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
| 659 | 659 | |
| 660 | - if( empty( $code_id ) ) { |
|
| 660 | + if (empty($code_id)) { |
|
| 661 | 661 | return false; // No discount was found |
| 662 | 662 | } |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
| 665 | + if (wpinv_discount_is_single_use($code_id)) { |
|
| 666 | 666 | $payments = array(); |
| 667 | 667 | |
| 668 | 668 | $user_id = 0; |
| 669 | - if ( is_int( $user ) ) { |
|
| 670 | - $user_id = absint( $user ); |
|
| 671 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
| 669 | + if (is_int($user)) { |
|
| 670 | + $user_id = absint($user); |
|
| 671 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
| 672 | 672 | $user_id = $user_data->ID; |
| 673 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
| 673 | + } else if ($user_data = get_user_by('login', $user)) { |
|
| 674 | 674 | $user_id = $user_data->ID; |
| 675 | - } else if ( absint( $user ) > 0 ) { |
|
| 676 | - $user_id = absint( $user ); |
|
| 675 | + } else if (absint($user) > 0) { |
|
| 676 | + $user_id = absint($user); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - if ( !empty( $user_id ) ) { |
|
| 680 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
| 681 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id |
|
| 679 | + if (!empty($user_id)) { |
|
| 680 | + $query = array('user' => $user_id, 'limit' => false); |
|
| 681 | + $payments = wpinv_get_invoices($query); // Get all payments with matching user id |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | - if ( $payments ) { |
|
| 685 | - foreach ( $payments as $payment ) { |
|
| 684 | + if ($payments) { |
|
| 685 | + foreach ($payments as $payment) { |
|
| 686 | 686 | // Don't count discount used for current invoice chekcout. |
| 687 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
| 687 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
| 688 | 688 | continue; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
| 691 | + if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) { |
|
| 692 | 692 | continue; |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | - $discounts = $payment->get_discounts( true ); |
|
| 696 | - if ( empty( $discounts ) ) { |
|
| 695 | + $discounts = $payment->get_discounts(true); |
|
| 696 | + if (empty($discounts)) { |
|
| 697 | 697 | continue; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
| 700 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
| 701 | 701 | |
| 702 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
| 703 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
| 704 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
| 702 | + if (!empty($discounts) && is_array($discounts)) { |
|
| 703 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
| 704 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
| 705 | 705 | $return = true; |
| 706 | 706 | break; |
| 707 | 707 | } |
@@ -710,61 +710,61 @@ discard block |
||
| 710 | 710 | } |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
| 713 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
| 716 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
| 717 | 717 | $return = false; |
| 718 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
| 719 | - $user = trim( $user ); |
|
| 718 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
| 719 | + $user = trim($user); |
|
| 720 | 720 | |
| 721 | - if ( wpinv_get_cart_contents() ) { |
|
| 722 | - if ( $discount_id ) { |
|
| 721 | + if (wpinv_get_cart_contents()) { |
|
| 722 | + if ($discount_id) { |
|
| 723 | 723 | if ( |
| 724 | - wpinv_is_discount_active( $discount_id ) && |
|
| 725 | - wpinv_check_discount_dates( $discount_id ) && |
|
| 726 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
| 727 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
| 728 | - wpinv_discount_is_min_met( $discount_id ) && |
|
| 729 | - wpinv_discount_is_max_met( $discount_id ) && |
|
| 730 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
| 724 | + wpinv_is_discount_active($discount_id) && |
|
| 725 | + wpinv_check_discount_dates($discount_id) && |
|
| 726 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
| 727 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
| 728 | + wpinv_discount_is_min_met($discount_id) && |
|
| 729 | + wpinv_discount_is_max_met($discount_id) && |
|
| 730 | + wpinv_discount_item_reqs_met($discount_id) |
|
| 731 | 731 | ) { |
| 732 | 732 | $return = true; |
| 733 | 733 | } |
| 734 | - } elseif( $set_error ) { |
|
| 735 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
| 734 | + } elseif ($set_error) { |
|
| 735 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
| 739 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | -function wpinv_get_discount_id_by_code( $code ) { |
|
| 743 | - $discount = wpinv_get_discount_by_code( $code ); |
|
| 744 | - if( $discount ) { |
|
| 742 | +function wpinv_get_discount_id_by_code($code) { |
|
| 743 | + $discount = wpinv_get_discount_by_code($code); |
|
| 744 | + if ($discount) { |
|
| 745 | 745 | return $discount->ID; |
| 746 | 746 | } |
| 747 | 747 | return false; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
| 750 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
| 751 | 751 | $amount = $base_price; |
| 752 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
| 752 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
| 753 | 753 | |
| 754 | - if( $discount_id ) { |
|
| 755 | - $type = wpinv_get_discount_type( $discount_id ); |
|
| 756 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
| 754 | + if ($discount_id) { |
|
| 755 | + $type = wpinv_get_discount_type($discount_id); |
|
| 756 | + $rate = wpinv_get_discount_amount($discount_id); |
|
| 757 | 757 | |
| 758 | - if ( $type == 'flat' ) { |
|
| 758 | + if ($type == 'flat') { |
|
| 759 | 759 | // Set amount |
| 760 | 760 | $amount = $base_price - $rate; |
| 761 | - if ( $amount < 0 ) { |
|
| 761 | + if ($amount < 0) { |
|
| 762 | 762 | $amount = 0; |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | } else { |
| 766 | 766 | // Percentage discount |
| 767 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
| 767 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | } else { |
@@ -773,108 +773,108 @@ discard block |
||
| 773 | 773 | |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
| 776 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | -function wpinv_increase_discount_usage( $code ) { |
|
| 779 | +function wpinv_increase_discount_usage($code) { |
|
| 780 | 780 | |
| 781 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
| 782 | - $uses = wpinv_get_discount_uses( $id ); |
|
| 781 | + $id = wpinv_get_discount_id_by_code($code); |
|
| 782 | + $uses = wpinv_get_discount_uses($id); |
|
| 783 | 783 | |
| 784 | - if ( $uses ) { |
|
| 784 | + if ($uses) { |
|
| 785 | 785 | $uses++; |
| 786 | 786 | } else { |
| 787 | 787 | $uses = 1; |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
| 790 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
| 791 | 791 | |
| 792 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
| 792 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
| 793 | 793 | |
| 794 | 794 | return $uses; |
| 795 | 795 | |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | -function wpinv_decrease_discount_usage( $code ) { |
|
| 798 | +function wpinv_decrease_discount_usage($code) { |
|
| 799 | 799 | |
| 800 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
| 801 | - $uses = wpinv_get_discount_uses( $id ); |
|
| 800 | + $id = wpinv_get_discount_id_by_code($code); |
|
| 801 | + $uses = wpinv_get_discount_uses($id); |
|
| 802 | 802 | |
| 803 | - if ( $uses ) { |
|
| 803 | + if ($uses) { |
|
| 804 | 804 | $uses--; |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | - if ( $uses < 0 ) { |
|
| 807 | + if ($uses < 0) { |
|
| 808 | 808 | $uses = 0; |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
| 811 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
| 812 | 812 | |
| 813 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
| 813 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
| 814 | 814 | |
| 815 | 815 | return $uses; |
| 816 | 816 | |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
| 820 | - if ( $type == 'flat' ) { |
|
| 821 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
| 819 | +function wpinv_format_discount_rate($type, $amount) { |
|
| 820 | + if ($type == 'flat') { |
|
| 821 | + return wpinv_price(wpinv_format_amount($amount)); |
|
| 822 | 822 | } else { |
| 823 | 823 | return $amount . '%'; |
| 824 | 824 | } |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | -function wpinv_set_cart_discount( $code = '' ) { |
|
| 828 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
| 827 | +function wpinv_set_cart_discount($code = '') { |
|
| 828 | + if (wpinv_multiple_discounts_allowed()) { |
|
| 829 | 829 | // Get all active cart discounts |
| 830 | 830 | $discounts = wpinv_get_cart_discounts(); |
| 831 | 831 | } else { |
| 832 | 832 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
| 833 | 833 | } |
| 834 | 834 | |
| 835 | - if ( $discounts ) { |
|
| 836 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
| 837 | - if( false !== $key ) { |
|
| 838 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
| 835 | + if ($discounts) { |
|
| 836 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
| 837 | + if (false !== $key) { |
|
| 838 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
| 839 | 839 | } |
| 840 | 840 | $discounts[] = $code; |
| 841 | 841 | } else { |
| 842 | 842 | $discounts = array(); |
| 843 | 843 | $discounts[] = $code; |
| 844 | 844 | } |
| 845 | - $discounts = array_values( $discounts ); |
|
| 845 | + $discounts = array_values($discounts); |
|
| 846 | 846 | |
| 847 | 847 | $data = wpinv_get_checkout_session(); |
| 848 | - if ( empty( $data ) ) { |
|
| 848 | + if (empty($data)) { |
|
| 849 | 849 | $data = array(); |
| 850 | 850 | } else { |
| 851 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 852 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
| 853 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 851 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 852 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
| 853 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 854 | 854 | } |
| 855 | 855 | } |
| 856 | 856 | $data['cart_discounts'] = $discounts; |
| 857 | 857 | |
| 858 | - wpinv_set_checkout_session( $data ); |
|
| 858 | + wpinv_set_checkout_session($data); |
|
| 859 | 859 | |
| 860 | 860 | return $discounts; |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
| 863 | +function wpinv_unset_cart_discount($code = '') { |
|
| 864 | 864 | $discounts = wpinv_get_cart_discounts(); |
| 865 | 865 | |
| 866 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
| 867 | - $key = array_search( $code, $discounts ); |
|
| 868 | - unset( $discounts[ $key ] ); |
|
| 866 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
| 867 | + $key = array_search($code, $discounts); |
|
| 868 | + unset($discounts[$key]); |
|
| 869 | 869 | |
| 870 | 870 | $data = wpinv_get_checkout_session(); |
| 871 | 871 | $data['cart_discounts'] = $discounts; |
| 872 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 873 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
| 874 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 872 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 873 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
| 874 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | - wpinv_set_checkout_session( $data ); |
|
| 877 | + wpinv_set_checkout_session($data); |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | return $discounts; |
@@ -883,27 +883,27 @@ discard block |
||
| 883 | 883 | function wpinv_unset_all_cart_discounts() { |
| 884 | 884 | $data = wpinv_get_checkout_session(); |
| 885 | 885 | |
| 886 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
| 887 | - unset( $data['cart_discounts'] ); |
|
| 886 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
| 887 | + unset($data['cart_discounts']); |
|
| 888 | 888 | |
| 889 | - wpinv_set_checkout_session( $data ); |
|
| 889 | + wpinv_set_checkout_session($data); |
|
| 890 | 890 | return true; |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | return false; |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
| 896 | +function wpinv_get_cart_discounts($items = array()) { |
|
| 897 | 897 | $session = wpinv_get_checkout_session(); |
| 898 | 898 | |
| 899 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
| 899 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
| 900 | 900 | return $discounts; |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
| 903 | +function wpinv_cart_has_discounts($items = array()) { |
|
| 904 | 904 | $ret = false; |
| 905 | 905 | |
| 906 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
| 906 | + if (wpinv_get_cart_discounts($items)) { |
|
| 907 | 907 | $ret = true; |
| 908 | 908 | } |
| 909 | 909 | |
@@ -914,131 +914,131 @@ discard block |
||
| 914 | 914 | } |
| 915 | 915 | */ |
| 916 | 916 | |
| 917 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
| 917 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
| 920 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
| 921 | 921 | $amount = 0.00; |
| 922 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 922 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 923 | 923 | |
| 924 | - if ( $items ) { |
|
| 925 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
| 924 | + if ($items) { |
|
| 925 | + $discounts = wp_list_pluck($items, 'discount'); |
|
| 926 | 926 | |
| 927 | - if ( is_array( $discounts ) ) { |
|
| 928 | - $discounts = array_map( 'floatval', $discounts ); |
|
| 929 | - $amount = array_sum( $discounts ); |
|
| 927 | + if (is_array($discounts)) { |
|
| 928 | + $discounts = array_map('floatval', $discounts); |
|
| 929 | + $amount = array_sum($discounts); |
|
| 930 | 930 | } |
| 931 | 931 | } |
| 932 | 932 | |
| 933 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
| 933 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
| 937 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 936 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
| 937 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 938 | 938 | |
| 939 | - if ( empty( $discount ) || empty( $items ) ) { |
|
| 939 | + if (empty($discount) || empty($items)) { |
|
| 940 | 940 | return 0; |
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | $amount = 0; |
| 944 | 944 | |
| 945 | - foreach ( $items as $item ) { |
|
| 946 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
| 945 | + foreach ($items as $item) { |
|
| 946 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
| 947 | 947 | } |
| 948 | 948 | |
| 949 | - $amount = wpinv_round_amount( $amount ); |
|
| 949 | + $amount = wpinv_round_amount($amount); |
|
| 950 | 950 | |
| 951 | 951 | return $amount; |
| 952 | 952 | } |
| 953 | 953 | |
| 954 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
| 954 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
| 955 | 955 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 956 | 956 | |
| 957 | 957 | $amount = 0; |
| 958 | 958 | |
| 959 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
| 959 | + if (empty($item) || empty($item['id'])) { |
|
| 960 | 960 | return $amount; |
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - if ( empty( $item['quantity'] ) ) { |
|
| 963 | + if (empty($item['quantity'])) { |
|
| 964 | 964 | return $amount; |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | - if ( empty( $item['options'] ) ) { |
|
| 967 | + if (empty($item['options'])) { |
|
| 968 | 968 | $item['options'] = array(); |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | - $price = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] ); |
|
| 971 | + $price = wpinv_get_cart_item_price($item['id'], $item, $item['options']); |
|
| 972 | 972 | $discounted_price = $price; |
| 973 | 973 | |
| 974 | 974 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
| 975 | - if ( empty( $discounts ) ) { |
|
| 975 | + if (empty($discounts)) { |
|
| 976 | 976 | return $amount; |
| 977 | 977 | } |
| 978 | 978 | |
| 979 | - if ( $discounts ) { |
|
| 980 | - if ( is_array( $discounts ) ) { |
|
| 981 | - $discounts = array_values( $discounts ); |
|
| 979 | + if ($discounts) { |
|
| 980 | + if (is_array($discounts)) { |
|
| 981 | + $discounts = array_values($discounts); |
|
| 982 | 982 | } else { |
| 983 | - $discounts = explode( ',', $discounts ); |
|
| 983 | + $discounts = explode(',', $discounts); |
|
| 984 | 984 | } |
| 985 | 985 | } |
| 986 | 986 | |
| 987 | - if( $discounts ) { |
|
| 988 | - foreach ( $discounts as $discount ) { |
|
| 989 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 987 | + if ($discounts) { |
|
| 988 | + foreach ($discounts as $discount) { |
|
| 989 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
| 990 | 990 | |
| 991 | 991 | // Check discount exists |
| 992 | - if( ! $code_id ) { |
|
| 992 | + if (!$code_id) { |
|
| 993 | 993 | continue; |
| 994 | 994 | } |
| 995 | 995 | |
| 996 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 997 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 996 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 997 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 998 | 998 | |
| 999 | 999 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
| 1000 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
| 1001 | - foreach ( $reqs as $item_id ) { |
|
| 1002 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
| 1003 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
| 1000 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
| 1001 | + foreach ($reqs as $item_id) { |
|
| 1002 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
| 1003 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
| 1004 | 1004 | } |
| 1005 | 1005 | } |
| 1006 | 1006 | } else { |
| 1007 | 1007 | // This is a global cart discount |
| 1008 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
| 1009 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
| 1008 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 1009 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
| 1010 | 1010 | $items_subtotal = 0.00; |
| 1011 | 1011 | $cart_items = wpinv_get_cart_contents(); |
| 1012 | 1012 | |
| 1013 | - foreach ( $cart_items as $cart_item ) { |
|
| 1014 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
| 1015 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
| 1016 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options ); |
|
| 1013 | + foreach ($cart_items as $cart_item) { |
|
| 1014 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
| 1015 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
| 1016 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options); |
|
| 1017 | 1017 | $items_subtotal += $item_price * $cart_item['quantity']; |
| 1018 | 1018 | } |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
| 1022 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
| 1021 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
| 1022 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
| 1023 | 1023 | $discounted_amount = $code_amount * $subtotal_percent; |
| 1024 | 1024 | $discounted_price -= $discounted_amount; |
| 1025 | 1025 | |
| 1026 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
| 1026 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
| 1027 | 1027 | |
| 1028 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
| 1028 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
| 1029 | 1029 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
| 1030 | 1030 | $discounted_price -= $adjustment; |
| 1031 | 1031 | } |
| 1032 | 1032 | } else { |
| 1033 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
| 1033 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | } |
| 1036 | 1036 | } |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
| 1039 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
| 1040 | 1040 | |
| 1041 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
| 1041 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
| 1042 | 1042 | $amount = $amount * $item['quantity']; |
| 1043 | 1043 | } |
| 1044 | 1044 | } |
@@ -1046,59 +1046,59 @@ discard block |
||
| 1046 | 1046 | return $amount; |
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
| 1050 | - echo wpinv_get_cart_discounts_html( $items ); |
|
| 1049 | +function wpinv_cart_discounts_html($items = array()) { |
|
| 1050 | + echo wpinv_get_cart_discounts_html($items); |
|
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
| 1053 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
| 1054 | 1054 | global $wpi_cart_columns; |
| 1055 | 1055 | |
| 1056 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 1056 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 1057 | 1057 | |
| 1058 | - if ( !$discounts ) { |
|
| 1059 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
| 1058 | + if (!$discounts) { |
|
| 1059 | + $discounts = wpinv_get_cart_discounts($items); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | - if ( !$discounts ) { |
|
| 1062 | + if (!$discounts) { |
|
| 1063 | 1063 | return; |
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
| 1066 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
| 1067 | 1067 | |
| 1068 | 1068 | $html = ''; |
| 1069 | 1069 | |
| 1070 | - foreach ( $discounts as $discount ) { |
|
| 1071 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 1072 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
| 1073 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
| 1074 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
| 1075 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
| 1070 | + foreach ($discounts as $discount) { |
|
| 1071 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
| 1072 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
| 1073 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
| 1074 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
| 1075 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
| 1076 | 1076 | |
| 1077 | 1077 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
| 1078 | 1078 | ob_start(); |
| 1079 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
| 1079 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
| 1080 | 1080 | $html .= ob_get_clean(); |
| 1081 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>'; |
|
| 1081 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>'; |
|
| 1082 | 1082 | ob_start(); |
| 1083 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
| 1083 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
| 1084 | 1084 | $html .= ob_get_clean(); |
| 1085 | 1085 | $html .= '</tr>'; |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
| 1088 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
| 1091 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
| 1092 | 1092 | $discounts = wpinv_get_cart_discounts(); |
| 1093 | 1093 | |
| 1094 | - if ( empty( $discounts ) ) { |
|
| 1094 | + if (empty($discounts)) { |
|
| 1095 | 1095 | return false; |
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
| 1099 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
| 1098 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
| 1099 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
| 1100 | 1100 | |
| 1101 | - if ( $echo ) { |
|
| 1101 | + if ($echo) { |
|
| 1102 | 1102 | echo $amount; |
| 1103 | 1103 | } |
| 1104 | 1104 | |
@@ -1106,135 +1106,135 @@ discard block |
||
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | function wpinv_remove_cart_discount() { |
| 1109 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
| 1109 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
| 1110 | 1110 | return; |
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1113 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1114 | 1114 | |
| 1115 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
| 1115 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
| 1116 | 1116 | |
| 1117 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1117 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1118 | 1118 | |
| 1119 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
| 1119 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
| 1120 | 1120 | } |
| 1121 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
| 1121 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
| 1122 | 1122 | |
| 1123 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
| 1123 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
| 1124 | 1124 | $discounts = wpinv_get_cart_discounts(); |
| 1125 | 1125 | |
| 1126 | - if ( !$discounts ) { |
|
| 1126 | + if (!$discounts) { |
|
| 1127 | 1127 | return; |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | - foreach ( $discounts as $discount ) { |
|
| 1131 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
| 1132 | - wpinv_unset_cart_discount( $discount ); |
|
| 1130 | + foreach ($discounts as $discount) { |
|
| 1131 | + if (!wpinv_is_discount_valid($discount)) { |
|
| 1132 | + wpinv_unset_cart_discount($discount); |
|
| 1133 | 1133 | } |
| 1134 | 1134 | } |
| 1135 | 1135 | } |
| 1136 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
| 1136 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
| 1137 | 1137 | |
| 1138 | 1138 | function wpinv_multiple_discounts_allowed() { |
| 1139 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
| 1140 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
| 1139 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
| 1140 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | function wpinv_listen_for_cart_discount() { |
| 1144 | 1144 | global $wpi_session; |
| 1145 | 1145 | |
| 1146 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
| 1146 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
| 1147 | 1147 | return; |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
| 1150 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
| 1151 | 1151 | |
| 1152 | - $wpi_session->set( 'preset_discount', $code ); |
|
| 1152 | + $wpi_session->set('preset_discount', $code); |
|
| 1153 | 1153 | } |
| 1154 | 1154 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
| 1155 | 1155 | |
| 1156 | 1156 | function wpinv_apply_preset_discount() { |
| 1157 | 1157 | global $wpi_session; |
| 1158 | 1158 | |
| 1159 | - $code = $wpi_session->get( 'preset_discount' ); |
|
| 1159 | + $code = $wpi_session->get('preset_discount'); |
|
| 1160 | 1160 | |
| 1161 | - if ( !$code ) { |
|
| 1161 | + if (!$code) { |
|
| 1162 | 1162 | return; |
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
| 1165 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
| 1166 | 1166 | return; |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
| 1169 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
| 1170 | 1170 | |
| 1171 | - wpinv_set_cart_discount( $code ); |
|
| 1171 | + wpinv_set_cart_discount($code); |
|
| 1172 | 1172 | |
| 1173 | - $wpi_session->set( 'preset_discount', null ); |
|
| 1173 | + $wpi_session->set('preset_discount', null); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
| 1176 | 1176 | |
| 1177 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
| 1178 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
| 1179 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
| 1177 | +function wpinv_get_discount_label($code, $echo = true) { |
|
| 1178 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
| 1179 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
| 1180 | 1180 | |
| 1181 | - if ( $echo ) { |
|
| 1181 | + if ($echo) { |
|
| 1182 | 1182 | echo $label; |
| 1183 | 1183 | } else { |
| 1184 | 1184 | return $label; |
| 1185 | 1185 | } |
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
| 1189 | - $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code ); |
|
| 1190 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
| 1188 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
| 1189 | + $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code); |
|
| 1190 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
| 1191 | 1191 | |
| 1192 | - if ( $echo ) { |
|
| 1192 | + if ($echo) { |
|
| 1193 | 1193 | echo $label; |
| 1194 | 1194 | } else { |
| 1195 | 1195 | return $label; |
| 1196 | 1196 | } |
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
| 1200 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
| 1199 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
| 1200 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
| 1201 | 1201 | return true; |
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | return $check; |
| 1205 | 1205 | } |
| 1206 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
| 1206 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
| 1207 | 1207 | |
| 1208 | 1208 | function wpinv_checkout_form_validate_discounts() { |
| 1209 | 1209 | global $wpi_checkout_id; |
| 1210 | 1210 | |
| 1211 | 1211 | $discounts = wpinv_get_cart_discounts(); |
| 1212 | 1212 | |
| 1213 | - if ( !empty( $discounts ) ) { |
|
| 1213 | + if (!empty($discounts)) { |
|
| 1214 | 1214 | $invalid = false; |
| 1215 | 1215 | |
| 1216 | - foreach ( $discounts as $key => $code ) { |
|
| 1217 | - if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) { |
|
| 1216 | + foreach ($discounts as $key => $code) { |
|
| 1217 | + if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) { |
|
| 1218 | 1218 | $invalid = true; |
| 1219 | 1219 | |
| 1220 | - wpinv_unset_cart_discount( $code ); |
|
| 1220 | + wpinv_unset_cart_discount($code); |
|
| 1221 | 1221 | } |
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | - if ( $invalid ) { |
|
| 1224 | + if ($invalid) { |
|
| 1225 | 1225 | $errors = wpinv_get_errors(); |
| 1226 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1227 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
| 1228 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
| 1226 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1227 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
| 1228 | + wpinv_set_error('wpinv-discount-error', $error); |
|
| 1229 | 1229 | |
| 1230 | - wpinv_recalculate_tax( true ); |
|
| 1230 | + wpinv_recalculate_tax(true); |
|
| 1231 | 1231 | } |
| 1232 | 1232 | } |
| 1233 | 1233 | } |
| 1234 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
| 1234 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
| 1235 | 1235 | |
| 1236 | 1236 | function wpinv_discount_amount() { |
| 1237 | 1237 | $output = 0.00; |
| 1238 | 1238 | |
| 1239 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
| 1239 | + return apply_filters('wpinv_discount_amount', $output); |
|
| 1240 | 1240 | } |
| 1241 | 1241 | \ No newline at end of file |
@@ -1,19 +1,19 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
| 6 | - if( empty( $field ) || empty( $value ) ) { |
|
| 5 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
| 6 | + if (empty($field) || empty($value)) { |
|
| 7 | 7 | return false; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | $posts = array(); |
| 11 | 11 | |
| 12 | - switch( strtolower( $field ) ) { |
|
| 12 | + switch (strtolower($field)) { |
|
| 13 | 13 | case 'id': |
| 14 | - $item = new WPInv_Item( $value ); |
|
| 14 | + $item = new WPInv_Item($value); |
|
| 15 | 15 | |
| 16 | - if ( !empty( $item ) && $item->post_type == 'wpi_item' ) { |
|
| 16 | + if (!empty($item) && $item->post_type == 'wpi_item') { |
|
| 17 | 17 | return $item; |
| 18 | 18 | } |
| 19 | 19 | return false; |
@@ -22,16 +22,16 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | case 'slug': |
| 24 | 24 | case 'name': |
| 25 | - $posts = get_posts( array( |
|
| 25 | + $posts = get_posts(array( |
|
| 26 | 26 | 'post_type' => 'wpi_item', |
| 27 | 27 | 'name' => $value, |
| 28 | 28 | 'posts_per_page' => 1, |
| 29 | 29 | 'post_status' => 'any' |
| 30 | - ) ); |
|
| 30 | + )); |
|
| 31 | 31 | |
| 32 | 32 | break; |
| 33 | 33 | case 'custom_id': |
| 34 | - if ( empty( $value ) || empty( $type ) ) { |
|
| 34 | + if (empty($value) || empty($type)) { |
|
| 35 | 35 | return false; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | 'post_status' => 'any', |
| 52 | 52 | 'orderby' => 'ID', |
| 53 | 53 | 'order' => 'ASC', |
| 54 | - 'meta_query' => array( $meta_query ) |
|
| 54 | + 'meta_query' => array($meta_query) |
|
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | - $posts = get_posts( $args ); |
|
| 57 | + $posts = get_posts($args); |
|
| 58 | 58 | |
| 59 | 59 | break; |
| 60 | 60 | |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if ( !empty( $posts[0] ) ) { |
|
| 66 | - $item = new WPInv_Item( $posts[0]->ID ); |
|
| 65 | + if (!empty($posts[0])) { |
|
| 66 | + $item = new WPInv_Item($posts[0]->ID); |
|
| 67 | 67 | |
| 68 | - if ( !empty( $item ) && $item->post_type == 'wpi_item' ) { |
|
| 68 | + if (!empty($item) && $item->post_type == 'wpi_item') { |
|
| 69 | 69 | return $item; |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | -function wpinv_get_item( $item = 0 ) { |
|
| 77 | - if ( is_numeric( $item ) ) { |
|
| 78 | - $item = get_post( $item ); |
|
| 79 | - if ( ! $item || 'wpi_item' !== $item->post_type ) |
|
| 76 | +function wpinv_get_item($item = 0) { |
|
| 77 | + if (is_numeric($item)) { |
|
| 78 | + $item = get_post($item); |
|
| 79 | + if (!$item || 'wpi_item' !== $item->post_type) |
|
| 80 | 80 | return null; |
| 81 | 81 | return $item; |
| 82 | 82 | } |
@@ -89,150 +89,150 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $item = get_posts($args); |
| 91 | 91 | |
| 92 | - if ( $item ) { |
|
| 92 | + if ($item) { |
|
| 93 | 93 | return $item[0]; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | return null; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
| 100 | - if( empty( $item_id ) ) { |
|
| 99 | +function wpinv_is_free_item($item_id = 0) { |
|
| 100 | + if (empty($item_id)) { |
|
| 101 | 101 | return false; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $item = new WPInv_Item( $item_id ); |
|
| 104 | + $item = new WPInv_Item($item_id); |
|
| 105 | 105 | |
| 106 | 106 | return $item->is_free(); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | -function wpinv_item_is_editable( $item = 0 ) { |
|
| 110 | - if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) { |
|
| 109 | +function wpinv_item_is_editable($item = 0) { |
|
| 110 | + if (!empty($item) && is_a($item, 'WP_Post')) { |
|
| 111 | 111 | $item = $item->ID; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if ( empty( $item ) ) { |
|
| 114 | + if (empty($item)) { |
|
| 115 | 115 | return true; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - $item = new WPInv_Item( $item ); |
|
| 118 | + $item = new WPInv_Item($item); |
|
| 119 | 119 | |
| 120 | - return (bool) $item->is_editable(); |
|
| 120 | + return (bool)$item->is_editable(); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
| 124 | - if( empty( $item_id ) ) { |
|
| 123 | +function wpinv_get_item_price($item_id = 0) { |
|
| 124 | + if (empty($item_id)) { |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $item = new WPInv_Item( $item_id ); |
|
| 128 | + $item = new WPInv_Item($item_id); |
|
| 129 | 129 | |
| 130 | 130 | return $item->get_price(); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
| 134 | - if( empty( $item_id ) ) { |
|
| 133 | +function wpinv_is_recurring_item($item_id = 0) { |
|
| 134 | + if (empty($item_id)) { |
|
| 135 | 135 | return false; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - $item = new WPInv_Item( $item_id ); |
|
| 138 | + $item = new WPInv_Item($item_id); |
|
| 139 | 139 | |
| 140 | 140 | return $item->is_recurring(); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | -function wpinv_item_price( $item_id = 0 ) { |
|
| 144 | - if( empty( $item_id ) ) { |
|
| 143 | +function wpinv_item_price($item_id = 0) { |
|
| 144 | + if (empty($item_id)) { |
|
| 145 | 145 | return false; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $price = wpinv_get_item_price( $item_id ); |
|
| 149 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
| 148 | + $price = wpinv_get_item_price($item_id); |
|
| 149 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
| 150 | 150 | |
| 151 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
| 151 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
| 155 | - if ( empty( $item_id ) ) { |
|
| 154 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
| 155 | + if (empty($item_id)) { |
|
| 156 | 156 | $item_id = get_the_ID(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $price = wpinv_item_price( $item_id ); |
|
| 159 | + $price = wpinv_item_price($item_id); |
|
| 160 | 160 | |
| 161 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
| 161 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
| 162 | 162 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
| 163 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
| 163 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
| 164 | 164 | |
| 165 | - if ( $echo ) { |
|
| 165 | + if ($echo) { |
|
| 166 | 166 | echo $formatted_price; |
| 167 | 167 | } else { |
| 168 | 168 | return $formatted_price; |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
| 173 | - if ( is_null( $amount_override ) ) { |
|
| 174 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
| 172 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
| 173 | + if (is_null($amount_override)) { |
|
| 174 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
| 175 | 175 | } else { |
| 176 | 176 | $original_price = $amount_override; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | $price = $original_price; |
| 180 | 180 | |
| 181 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
| 181 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
| 185 | - if( empty( $item_id ) ) { |
|
| 184 | +function wpinv_item_custom_singular_name($item_id) { |
|
| 185 | + if (empty($item_id)) { |
|
| 186 | 186 | return false; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - $item = new WPInv_Item( $item_id ); |
|
| 189 | + $item = new WPInv_Item($item_id); |
|
| 190 | 190 | |
| 191 | 191 | return $item->get_custom_singular_name(); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | function wpinv_get_item_types() { |
| 195 | 195 | $item_types = array( |
| 196 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 197 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 196 | + 'custom' => __('Standard', 'invoicing'), |
|
| 197 | + 'fee' => __('Fee', 'invoicing'), |
|
| 198 | 198 | ); |
| 199 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
| 199 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function wpinv_item_types() { |
| 203 | 203 | $item_types = wpinv_get_item_types(); |
| 204 | 204 | |
| 205 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
| 205 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | -function wpinv_get_item_type( $item_id ) { |
|
| 209 | - if( empty( $item_id ) ) { |
|
| 208 | +function wpinv_get_item_type($item_id) { |
|
| 209 | + if (empty($item_id)) { |
|
| 210 | 210 | return false; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - $item = new WPInv_Item( $item_id ); |
|
| 213 | + $item = new WPInv_Item($item_id); |
|
| 214 | 214 | |
| 215 | 215 | return $item->get_type(); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | -function wpinv_item_type( $item_id ) { |
|
| 218 | +function wpinv_item_type($item_id) { |
|
| 219 | 219 | $item_types = wpinv_get_item_types(); |
| 220 | 220 | |
| 221 | - $item_type = wpinv_get_item_type( $item_id ); |
|
| 221 | + $item_type = wpinv_get_item_type($item_id); |
|
| 222 | 222 | |
| 223 | - if ( empty( $item_type ) ) { |
|
| 223 | + if (empty($item_type)) { |
|
| 224 | 224 | $item_type = '-'; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
| 227 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
| 228 | 228 | |
| 229 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
| 229 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
| 232 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
| 233 | 233 | global $wpinv_logs; |
| 234 | 234 | |
| 235 | - if ( empty( $wpinv_logs ) ) { |
|
| 235 | + if (empty($wpinv_logs)) { |
|
| 236 | 236 | return false; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | 'log_type' => 'wpi_item' |
| 242 | 242 | ); |
| 243 | 243 | |
| 244 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
| 244 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
| 245 | 245 | |
| 246 | 246 | $log_meta = array( |
| 247 | 247 | 'user_info' => $user_info, |
@@ -251,257 +251,257 @@ discard block |
||
| 251 | 251 | 'invoice_id'=> $invoice_id, |
| 252 | 252 | ); |
| 253 | 253 | |
| 254 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
| 254 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
| 258 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
| 257 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
| 258 | + if ('wpi_item' !== get_post_type($item_id)) |
|
| 259 | 259 | return; |
| 260 | 260 | |
| 261 | 261 | global $wpinv_logs; |
| 262 | 262 | |
| 263 | - if ( empty( $wpinv_logs ) ) { |
|
| 263 | + if (empty($wpinv_logs)) { |
|
| 264 | 264 | return false; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // Remove all log entries related to this item |
| 268 | - $wpinv_logs->delete_logs( $item_id ); |
|
| 268 | + $wpinv_logs->delete_logs($item_id); |
|
| 269 | 269 | } |
| 270 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
| 270 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
| 271 | 271 | |
| 272 | -function wpinv_get_random_item( $post_ids = true ) { |
|
| 273 | - wpinv_get_random_items( 1, $post_ids ); |
|
| 272 | +function wpinv_get_random_item($post_ids = true) { |
|
| 273 | + wpinv_get_random_items(1, $post_ids); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
| 277 | - if ( $post_ids ) { |
|
| 278 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
| 276 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
| 277 | + if ($post_ids) { |
|
| 278 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
| 279 | 279 | } else { |
| 280 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
| 280 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
| 283 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
| 284 | 284 | |
| 285 | - return get_posts( $args ); |
|
| 285 | + return get_posts($args); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | -function wpinv_get_item_token( $url = '' ) { |
|
| 288 | +function wpinv_get_item_token($url = '') { |
|
| 289 | 289 | $args = array(); |
| 290 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
| 291 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
| 290 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
| 291 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
| 292 | 292 | |
| 293 | - $parts = parse_url( $url ); |
|
| 293 | + $parts = parse_url($url); |
|
| 294 | 294 | $options = array(); |
| 295 | 295 | |
| 296 | - if ( isset( $parts['query'] ) ) { |
|
| 297 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 296 | + if (isset($parts['query'])) { |
|
| 297 | + wp_parse_str($parts['query'], $query_args); |
|
| 298 | 298 | |
| 299 | - if ( ! empty( $query_args['o'] ) ) { |
|
| 300 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
| 299 | + if (!empty($query_args['o'])) { |
|
| 300 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
| 301 | 301 | |
| 302 | - if ( in_array( 'ip', $options ) ) { |
|
| 302 | + if (in_array('ip', $options)) { |
|
| 303 | 303 | $args['ip'] = wpinv_get_ip(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if ( in_array( 'ua', $options ) ) { |
|
| 306 | + if (in_array('ua', $options)) { |
|
| 307 | 307 | $ua = wpinv_get_user_agent(); |
| 308 | - $args['user_agent'] = rawurlencode( $ua ); |
|
| 308 | + $args['user_agent'] = rawurlencode($ua); |
|
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
| 313 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
| 314 | 314 | |
| 315 | 315 | $args['secret'] = $secret; |
| 316 | 316 | $args['token'] = false; |
| 317 | 317 | |
| 318 | - $url = add_query_arg( $args, $url ); |
|
| 319 | - $parts = parse_url( $url ); |
|
| 318 | + $url = add_query_arg($args, $url); |
|
| 319 | + $parts = parse_url($url); |
|
| 320 | 320 | |
| 321 | - if ( ! isset( $parts['path'] ) ) { |
|
| 321 | + if (!isset($parts['path'])) { |
|
| 322 | 322 | $parts['path'] = ''; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
| 325 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
| 326 | 326 | |
| 327 | 327 | return $token; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | -function wpinv_validate_url_token( $url = '' ) { |
|
| 330 | +function wpinv_validate_url_token($url = '') { |
|
| 331 | 331 | $ret = false; |
| 332 | - $parts = parse_url( $url ); |
|
| 332 | + $parts = parse_url($url); |
|
| 333 | 333 | |
| 334 | - if ( isset( $parts['query'] ) ) { |
|
| 335 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 334 | + if (isset($parts['query'])) { |
|
| 335 | + wp_parse_str($parts['query'], $query_args); |
|
| 336 | 336 | |
| 337 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
| 337 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
| 338 | 338 | 'item', |
| 339 | 339 | 'ttl', |
| 340 | 340 | 'token' |
| 341 | - ) ); |
|
| 341 | + )); |
|
| 342 | 342 | |
| 343 | 343 | $remove = array(); |
| 344 | 344 | |
| 345 | - foreach( $query_args as $key => $value ) { |
|
| 346 | - if( false === in_array( $key, $allowed ) ) { |
|
| 345 | + foreach ($query_args as $key => $value) { |
|
| 346 | + if (false === in_array($key, $allowed)) { |
|
| 347 | 347 | $remove[] = $key; |
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - if( ! empty( $remove ) ) { |
|
| 352 | - $url = remove_query_arg( $remove, $url ); |
|
| 351 | + if (!empty($remove)) { |
|
| 352 | + $url = remove_query_arg($remove, $url); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
| 356 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 355 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
| 356 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
| 359 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
| 360 | 360 | $ret = true; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
| 365 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
| 368 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
| 369 | 369 | $cart_items = wpinv_get_cart_contents(); |
| 370 | 370 | |
| 371 | 371 | $ret = false; |
| 372 | 372 | |
| 373 | - if ( is_array( $cart_items ) ) { |
|
| 374 | - foreach ( $cart_items as $item ) { |
|
| 375 | - if ( $item['id'] == $item_id ) { |
|
| 373 | + if (is_array($cart_items)) { |
|
| 374 | + foreach ($cart_items as $item) { |
|
| 375 | + if ($item['id'] == $item_id) { |
|
| 376 | 376 | $ret = true; |
| 377 | 377 | break; |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
| 382 | + return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
| 385 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
| 386 | 386 | $tax = 0; |
| 387 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 388 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
| 389 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
| 387 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
| 388 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
| 389 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
| 390 | 390 | |
| 391 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
| 391 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
| 394 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | -function wpinv_cart_item_price( $item ) { |
|
| 397 | +function wpinv_cart_item_price($item) { |
|
| 398 | 398 | $use_taxes = wpinv_use_taxes(); |
| 399 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
| 400 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
| 401 | - $options = isset( $item['options'] ) ? $item['options'] : array(); |
|
| 402 | - $price_id = isset( $options['price_id'] ) ? $options['price_id'] : false; |
|
| 403 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
| 404 | - |
|
| 405 | - if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 406 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
| 399 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
| 400 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
| 401 | + $options = isset($item['options']) ? $item['options'] : array(); |
|
| 402 | + $price_id = isset($options['price_id']) ? $options['price_id'] : false; |
|
| 403 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
| 404 | + |
|
| 405 | + if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
| 406 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
| 407 | 407 | $price += $tax; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
| 410 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
| 411 | 411 | $price -= $tax; |
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
| 415 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
| 416 | 416 | |
| 417 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
| 417 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | -function wpinv_cart_item_subtotal( $item ) { |
|
| 421 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
| 422 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ) ); |
|
| 420 | +function wpinv_cart_item_subtotal($item) { |
|
| 421 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
| 422 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal)); |
|
| 423 | 423 | |
| 424 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
| 424 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | -function wpinv_cart_item_tax( $item ) { |
|
| 427 | +function wpinv_cart_item_tax($item) { |
|
| 428 | 428 | $tax = ''; |
| 429 | 429 | $tax_rate = ''; |
| 430 | 430 | |
| 431 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
| 432 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
| 433 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
| 434 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 431 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
| 432 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
| 433 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
| 434 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 435 | 435 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - $tax = $tax . $tax_rate; |
|
| 438 | + $tax = $tax . $tax_rate; |
|
| 439 | 439 | |
| 440 | - if ( $tax === '' ) { |
|
| 440 | + if ($tax === '') { |
|
| 441 | 441 | $tax = 0; // Zero tax |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
| 444 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | -function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) { |
|
| 447 | +function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) { |
|
| 448 | 448 | $price = 0; |
| 449 | 449 | |
| 450 | 450 | // Set custom price |
| 451 | - if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) { |
|
| 451 | + if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') { |
|
| 452 | 452 | $price = $cart_item['custom_price']; |
| 453 | 453 | } else { |
| 454 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
| 454 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
| 455 | 455 | |
| 456 | - if ( $variable_prices ) { |
|
| 457 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
| 456 | + if ($variable_prices) { |
|
| 457 | + $prices = wpinv_get_variable_prices($item_id); |
|
| 458 | 458 | |
| 459 | - if ( $prices ) { |
|
| 460 | - if( ! empty( $options ) ) { |
|
| 461 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
| 459 | + if ($prices) { |
|
| 460 | + if (!empty($options)) { |
|
| 461 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
| 462 | 462 | } else { |
| 463 | 463 | $price = false; |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - if( ! $variable_prices || false === $price ) { |
|
| 469 | - if($cart_item['item_price'] > 0){ |
|
| 468 | + if (!$variable_prices || false === $price) { |
|
| 469 | + if ($cart_item['item_price'] > 0) { |
|
| 470 | 470 | $price = $cart_item['item_price']; |
| 471 | 471 | } else { |
| 472 | 472 | // Get the standard Item price if not using variable prices |
| 473 | - $price = wpinv_get_item_price( $item_id ); |
|
| 473 | + $price = wpinv_get_item_price($item_id); |
|
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
| 479 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
| 478 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
| 479 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive ); |
|
| 482 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
| 486 | - if( isset( $item['item_number'] ) ) { |
|
| 487 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
| 485 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
| 486 | + if (isset($item['item_number'])) { |
|
| 487 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
| 488 | 488 | } else { |
| 489 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
| 489 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
| 490 | 490 | } |
| 491 | 491 | return $price_id; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
| 495 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
| 496 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
| 497 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
| 498 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
| 494 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
| 495 | + $price_id = (int)wpinv_get_cart_item_price_id($item); |
|
| 496 | + $prices = wpinv_get_variable_prices($item['id']); |
|
| 497 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
| 498 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
| 502 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
| 501 | +function wpinv_get_cart_item_name($item = array()) { |
|
| 502 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
| 503 | 503 | |
| 504 | - if ( empty( $item_title ) ) { |
|
| 504 | + if (empty($item_title)) { |
|
| 505 | 505 | $item_title = $item['id']; |
| 506 | 506 | } |
| 507 | 507 | |
@@ -511,23 +511,23 @@ discard block |
||
| 511 | 511 | } |
| 512 | 512 | */ |
| 513 | 513 | |
| 514 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
| 514 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
| 517 | +function wpinv_has_variable_prices($item_id = 0) { |
|
| 518 | 518 | return false; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
| 521 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
| 522 | 522 | $cart_items = wpinv_get_cart_contents(); |
| 523 | 523 | |
| 524 | - if ( !is_array( $cart_items ) ) { |
|
| 524 | + if (!is_array($cart_items)) { |
|
| 525 | 525 | return false; // Empty cart |
| 526 | 526 | } else { |
| 527 | - foreach ( $cart_items as $position => $item ) { |
|
| 528 | - if ( $item['id'] == $item_id ) { |
|
| 529 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
| 530 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
| 527 | + foreach ($cart_items as $position => $item) { |
|
| 528 | + if ($item['id'] == $item_id) { |
|
| 529 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
| 530 | + if ((int)$options['price_id'] == (int)$item['options']['price_id']) { |
|
| 531 | 531 | return $position; |
| 532 | 532 | } |
| 533 | 533 | } else { |
@@ -540,80 +540,80 @@ discard block |
||
| 540 | 540 | return false; // Not found |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | -function wpinv_get_cart_item_quantity( $item ) { |
|
| 544 | - if ( wpinv_item_quantities_enabled() ) { |
|
| 545 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 543 | +function wpinv_get_cart_item_quantity($item) { |
|
| 544 | + if (wpinv_item_quantities_enabled()) { |
|
| 545 | + $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 546 | 546 | } else { |
| 547 | 547 | $quantity = 1; |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - if ( $quantity < 1 ) { |
|
| 550 | + if ($quantity < 1) { |
|
| 551 | 551 | $quantity = 1; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
| 554 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
| 558 | - if ( empty( $item ) ) { |
|
| 557 | +function wpinv_get_item_suffix($item, $html = true) { |
|
| 558 | + if (empty($item)) { |
|
| 559 | 559 | return NULL; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - if ( is_int( $item ) ) { |
|
| 563 | - $item = new WPInv_Item( $item ); |
|
| 562 | + if (is_int($item)) { |
|
| 563 | + $item = new WPInv_Item($item); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 566 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 567 | 567 | return NULL; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
| 570 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
| 571 | 571 | |
| 572 | - if ( !$html && $suffix ) { |
|
| 573 | - $suffix = strip_tags( $suffix ); |
|
| 572 | + if (!$html && $suffix) { |
|
| 573 | + $suffix = strip_tags($suffix); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
| 576 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
| 580 | - if ( empty( $item ) ) { |
|
| 579 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
| 580 | + if (empty($item)) { |
|
| 581 | 581 | return NULL; |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - if ( is_int( $item ) ) { |
|
| 585 | - $item = new WPInv_Item( $item ); |
|
| 584 | + if (is_int($item)) { |
|
| 585 | + $item = new WPInv_Item($item); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 588 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 589 | 589 | return NULL; |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
| 592 | + do_action('wpinv_pre_delete_item', $item); |
|
| 593 | 593 | |
| 594 | - wp_delete_post( $item->ID, $force_delete ); |
|
| 594 | + wp_delete_post($item->ID, $force_delete); |
|
| 595 | 595 | |
| 596 | - do_action( 'wpinv_post_delete_item', $item ); |
|
| 596 | + do_action('wpinv_post_delete_item', $item); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | -function wpinv_can_delete_item( $post_id ) { |
|
| 600 | - $return = current_user_can( 'manage_options' ) ? true : false; |
|
| 599 | +function wpinv_can_delete_item($post_id) { |
|
| 600 | + $return = current_user_can('manage_options') ? true : false; |
|
| 601 | 601 | |
| 602 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
| 602 | + if ($return && wpinv_item_in_use($post_id)) { |
|
| 603 | 603 | $return = false; // Don't delete item already use in invoices. |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
| 606 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | function wpinv_admin_action_delete() { |
| 610 | 610 | $screen = get_current_screen(); |
| 611 | 611 | |
| 612 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
| 612 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
| 613 | 613 | $post_ids = array(); |
| 614 | 614 | |
| 615 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
| 616 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
| 615 | + foreach ($_REQUEST['post'] as $post_id) { |
|
| 616 | + if (!wpinv_can_delete_item($post_id)) { |
|
| 617 | 617 | continue; |
| 618 | 618 | } |
| 619 | 619 | |
@@ -623,86 +623,86 @@ discard block |
||
| 623 | 623 | $_REQUEST['post'] = $post_ids; |
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
| 627 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
| 626 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
| 627 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
| 628 | 628 | |
| 629 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
| 630 | - if ( $post->post_type == 'wpi_item' ) { |
|
| 631 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
| 629 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
| 630 | + if ($post->post_type == 'wpi_item') { |
|
| 631 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
| 632 | 632 | return true; |
| 633 | 633 | } |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | return $check; |
| 637 | 637 | } |
| 638 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
| 638 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
| 639 | 639 | |
| 640 | -function wpinv_item_in_use( $item_id ) { |
|
| 640 | +function wpinv_item_in_use($item_id) { |
|
| 641 | 641 | global $wpdb, $wpi_items_in_use; |
| 642 | 642 | |
| 643 | - if ( !$item_id > 0 ) { |
|
| 643 | + if (!$item_id > 0) { |
|
| 644 | 644 | return false; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - if ( !empty( $wpi_items_in_use ) ) { |
|
| 648 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
| 647 | + if (!empty($wpi_items_in_use)) { |
|
| 648 | + if (isset($wpi_items_in_use[$item_id])) { |
|
| 649 | 649 | return $wpi_items_in_use[$item_id]; |
| 650 | 650 | } |
| 651 | 651 | } else { |
| 652 | 652 | $wpi_items_in_use = array(); |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - $statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
| 655 | + $statuses = array_keys(wpinv_get_invoice_statuses(true, true)); |
|
| 656 | 656 | |
| 657 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
| 658 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
| 657 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
| 658 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
| 659 | 659 | |
| 660 | 660 | $wpi_items_in_use[$item_id] = $in_use; |
| 661 | 661 | |
| 662 | 662 | return $in_use; |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | -function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) { |
|
| 665 | +function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) { |
|
| 666 | 666 | // Set some defaults |
| 667 | 667 | $defaults = array( |
| 668 | - 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
| 669 | - 'title' => '', // Required. Item title. |
|
| 670 | - 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
| 671 | - 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
| 672 | - 'status' => 'pending', // Optional. pending, publish |
|
| 673 | - 'custom_name' => '', // Optional. Plural sub title for item. |
|
| 674 | - 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
| 675 | - 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
| 676 | - 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
| 677 | - 'excerpt' => '', // Optional. Item short description |
|
| 668 | + 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
| 669 | + 'title' => '', // Required. Item title. |
|
| 670 | + 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
| 671 | + 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
| 672 | + 'status' => 'pending', // Optional. pending, publish |
|
| 673 | + 'custom_name' => '', // Optional. Plural sub title for item. |
|
| 674 | + 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
| 675 | + 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
| 676 | + 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
| 677 | + 'excerpt' => '', // Optional. Item short description |
|
| 678 | 678 | /* Recurring item fields */ |
| 679 | - 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
| 680 | - 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 681 | - 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
| 682 | - 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
| 683 | - 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
| 684 | - 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 685 | - 'trial_interval' => 0, // Optional. Any integer number. |
|
| 679 | + 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
| 680 | + 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 681 | + 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
| 682 | + 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
| 683 | + 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
| 684 | + 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 685 | + 'trial_interval' => 0, // Optional. Any integer number. |
|
| 686 | 686 | ); |
| 687 | 687 | |
| 688 | - $data = wp_parse_args( $args, $defaults ); |
|
| 688 | + $data = wp_parse_args($args, $defaults); |
|
| 689 | 689 | |
| 690 | - if ( empty( $data['type'] ) ) { |
|
| 690 | + if (empty($data['type'])) { |
|
| 691 | 691 | $data['type'] = 'custom'; |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | - if ( !empty( $data['custom_id'] ) ) { |
|
| 695 | - $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] ); |
|
| 694 | + if (!empty($data['custom_id'])) { |
|
| 695 | + $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']); |
|
| 696 | 696 | } else { |
| 697 | 697 | $item = NULL; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - if ( !empty( $item ) ) { |
|
| 701 | - if ( $force_update ) { |
|
| 702 | - if ( empty( $args['ID'] ) ) { |
|
| 700 | + if (!empty($item)) { |
|
| 701 | + if ($force_update) { |
|
| 702 | + if (empty($args['ID'])) { |
|
| 703 | 703 | $args['ID'] = $item->ID; |
| 704 | 704 | } |
| 705 | - return wpinv_update_item( $args, $wp_error ); |
|
| 705 | + return wpinv_update_item($args, $wp_error); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | return $item; |
@@ -713,19 +713,19 @@ discard block |
||
| 713 | 713 | $meta['custom_id'] = $data['custom_id']; |
| 714 | 714 | $meta['custom_singular_name'] = $data['custom_singular_name']; |
| 715 | 715 | $meta['custom_name'] = $data['custom_name']; |
| 716 | - $meta['price'] = wpinv_round_amount( $data['price'] ); |
|
| 716 | + $meta['price'] = wpinv_round_amount($data['price']); |
|
| 717 | 717 | $meta['editable'] = (int)$data['editable']; |
| 718 | 718 | $meta['vat_rule'] = $data['vat_rule']; |
| 719 | 719 | $meta['vat_class'] = '_standard'; |
| 720 | 720 | |
| 721 | - if ( !empty( $data['is_recurring'] ) ) { |
|
| 721 | + if (!empty($data['is_recurring'])) { |
|
| 722 | 722 | $meta['is_recurring'] = $data['is_recurring']; |
| 723 | 723 | $meta['recurring_period'] = $data['recurring_period']; |
| 724 | - $meta['recurring_interval'] = absint( $data['recurring_interval'] ); |
|
| 725 | - $meta['recurring_limit'] = absint( $data['recurring_limit'] ); |
|
| 724 | + $meta['recurring_interval'] = absint($data['recurring_interval']); |
|
| 725 | + $meta['recurring_limit'] = absint($data['recurring_limit']); |
|
| 726 | 726 | $meta['free_trial'] = $data['free_trial']; |
| 727 | 727 | $meta['trial_period'] = $data['trial_period']; |
| 728 | - $meta['trial_interval'] = absint( $data['trial_interval'] ); |
|
| 728 | + $meta['trial_interval'] = absint($data['trial_interval']); |
|
| 729 | 729 | } else { |
| 730 | 730 | $meta['is_recurring'] = 0; |
| 731 | 731 | $meta['recurring_period'] = ''; |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | $meta['trial_interval'] = ''; |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - $post_data = array( |
|
| 739 | + $post_data = array( |
|
| 740 | 740 | 'post_title' => $data['title'], |
| 741 | 741 | 'post_excerpt' => $data['excerpt'], |
| 742 | 742 | 'post_status' => $data['status'], |
@@ -744,89 +744,89 @@ discard block |
||
| 744 | 744 | ); |
| 745 | 745 | |
| 746 | 746 | $item = new WPInv_Item(); |
| 747 | - $return = $item->create( $post_data, $wp_error ); |
|
| 747 | + $return = $item->create($post_data, $wp_error); |
|
| 748 | 748 | |
| 749 | - if ( $return && !empty( $item ) && !is_wp_error( $return ) ) { |
|
| 749 | + if ($return && !empty($item) && !is_wp_error($return)) { |
|
| 750 | 750 | return $item; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | - if ( $wp_error && is_wp_error( $return ) ) { |
|
| 753 | + if ($wp_error && is_wp_error($return)) { |
|
| 754 | 754 | return $return; |
| 755 | 755 | } |
| 756 | 756 | return 0; |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
| 760 | - $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL; |
|
| 759 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
| 760 | + $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL; |
|
| 761 | 761 | |
| 762 | - if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) { |
|
| 763 | - if ( $wp_error ) { |
|
| 764 | - return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) ); |
|
| 762 | + if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) { |
|
| 763 | + if ($wp_error) { |
|
| 764 | + return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing')); |
|
| 765 | 765 | } |
| 766 | 766 | return 0; |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | - if ( !empty( $args['custom_id'] ) ) { |
|
| 770 | - $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) ); |
|
| 769 | + if (!empty($args['custom_id'])) { |
|
| 770 | + $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type)); |
|
| 771 | 771 | |
| 772 | - if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) { |
|
| 773 | - if ( $wp_error ) { |
|
| 774 | - return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) ); |
|
| 772 | + if (!empty($item_exists) && $item_exists->ID != $args['ID']) { |
|
| 773 | + if ($wp_error) { |
|
| 774 | + return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing')); |
|
| 775 | 775 | } |
| 776 | 776 | return 0; |
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | - $meta_fields = array( 'type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval' ); |
|
| 780 | + $meta_fields = array('type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval'); |
|
| 781 | 781 | |
| 782 | 782 | $post_data = array(); |
| 783 | - if ( isset( $args['title'] ) ) { |
|
| 783 | + if (isset($args['title'])) { |
|
| 784 | 784 | $post_data['post_title'] = $args['title']; |
| 785 | 785 | } |
| 786 | - if ( isset( $args['excerpt'] ) ) { |
|
| 786 | + if (isset($args['excerpt'])) { |
|
| 787 | 787 | $post_data['post_excerpt'] = $args['excerpt']; |
| 788 | 788 | } |
| 789 | - if ( isset( $args['status'] ) ) { |
|
| 789 | + if (isset($args['status'])) { |
|
| 790 | 790 | $post_data['post_status'] = $args['status']; |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | - foreach ( $meta_fields as $meta_field ) { |
|
| 794 | - if ( isset( $args[ $meta_field ] ) ) { |
|
| 795 | - $value = $args[ $meta_field ]; |
|
| 793 | + foreach ($meta_fields as $meta_field) { |
|
| 794 | + if (isset($args[$meta_field])) { |
|
| 795 | + $value = $args[$meta_field]; |
|
| 796 | 796 | |
| 797 | - switch ( $meta_field ) { |
|
| 797 | + switch ($meta_field) { |
|
| 798 | 798 | case 'price': |
| 799 | - $value = wpinv_round_amount( $value ); |
|
| 799 | + $value = wpinv_round_amount($value); |
|
| 800 | 800 | break; |
| 801 | 801 | case 'recurring_interval': |
| 802 | 802 | case 'recurring_limit': |
| 803 | 803 | case 'trial_interval': |
| 804 | - $value = absint( $value ); |
|
| 804 | + $value = absint($value); |
|
| 805 | 805 | break; |
| 806 | 806 | case 'editable': |
| 807 | - $value = (int) $value; |
|
| 807 | + $value = (int)$value; |
|
| 808 | 808 | break; |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | - $post_data['meta'][ $meta_field ] = $value; |
|
| 811 | + $post_data['meta'][$meta_field] = $value; |
|
| 812 | 812 | }; |
| 813 | 813 | } |
| 814 | 814 | |
| 815 | - if ( empty( $post_data ) ) { |
|
| 816 | - if ( $wp_error ) { |
|
| 817 | - return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) ); |
|
| 815 | + if (empty($post_data)) { |
|
| 816 | + if ($wp_error) { |
|
| 817 | + return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing')); |
|
| 818 | 818 | } |
| 819 | 819 | return 0; |
| 820 | 820 | } |
| 821 | 821 | $post_data['ID'] = $args['ID']; |
| 822 | 822 | |
| 823 | - $return = $item->update( $post_data, $wp_error ); |
|
| 823 | + $return = $item->update($post_data, $wp_error); |
|
| 824 | 824 | |
| 825 | - if ( $return && !empty( $item ) && !is_wp_error( $return ) ) { |
|
| 825 | + if ($return && !empty($item) && !is_wp_error($return)) { |
|
| 826 | 826 | return $item; |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | - if ( $wp_error && is_wp_error( $return ) ) { |
|
| 829 | + if ($wp_error && is_wp_error($return)) { |
|
| 830 | 830 | return $return; |
| 831 | 831 | } |
| 832 | 832 | return 0; |
@@ -12,19 +12,19 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // MUST have WordPress. |
| 15 | -if ( !defined( 'WPINC' ) ) { |
|
| 16 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 15 | +if (!defined('WPINC')) { |
|
| 16 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -if ( !defined( 'WPINV_VERSION' ) ) { |
|
| 20 | - define( 'WPINV_VERSION', '1.0.9' ); |
|
| 19 | +if (!defined('WPINV_VERSION')) { |
|
| 20 | + define('WPINV_VERSION', '1.0.9'); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -if ( !defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
| 24 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 23 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
| 24 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wpinv.php'; |
|
| 27 | +require plugin_dir_path(__FILE__) . 'includes/class-wpinv.php'; |
|
| 28 | 28 | |
| 29 | 29 | function wpinv_run() { |
| 30 | 30 | global $invoicing; |
@@ -7,40 +7,40 @@ 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_get_invoice_cart_id() { |
| 15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
| 16 | 16 | |
| 17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
| 17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
| 18 | 18 | return $wpinv_checkout['invoice_id']; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | return NULL; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
| 25 | - if ( empty( $invoice_data ) ) { |
|
| 24 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
| 25 | + if (empty($invoice_data)) { |
|
| 26 | 26 | return false; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
| 30 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0; |
|
| 29 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
| 30 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
| 33 | + if (empty($invoice_data['user_id'])) { |
|
| 34 | 34 | $invoice_data['user_id'] = get_current_user_id(); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
| 37 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0; |
|
| 38 | 38 | |
| 39 | - if ( empty( $invoice_data['status'] ) ) { |
|
| 39 | + if (empty($invoice_data['status'])) { |
|
| 40 | 40 | $invoice_data['status'] = 'wpi-pending'; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if ( empty( $invoice_data['ip'] ) ) { |
|
| 43 | + if (empty($invoice_data['ip'])) { |
|
| 44 | 44 | $invoice_data['ip'] = wpinv_get_ip(); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | 'status' => $invoice_data['status'], |
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
| 55 | - if ( is_wp_error( $invoice ) ) { |
|
| 54 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
| 55 | + if (is_wp_error($invoice)) { |
|
| 56 | 56 | return $wp_error ? $invoice : 0; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
| 59 | + if (empty($invoice_data['invoice_id'])) { |
|
| 60 | 60 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -79,24 +79,24 @@ discard block |
||
| 79 | 79 | 'discount' => array(), |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
| 83 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
| 84 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
| 82 | + if ($user_id = (int)$invoice->get_user_id()) { |
|
| 83 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
| 84 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
| 88 | + if (empty($invoice_data['user_info'])) { |
|
| 89 | 89 | $invoice_data['user_info'] = array(); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
| 92 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
| 93 | 93 | |
| 94 | - if ( empty( $user_info['first_name'] ) ) { |
|
| 94 | + if (empty($user_info['first_name'])) { |
|
| 95 | 95 | $user_info['first_name'] = $default_user_info['first_name']; |
| 96 | 96 | $user_info['last_name'] = $default_user_info['last_name']; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if ( empty( $user_info['country'] ) ) { |
|
| 99 | + if (empty($user_info['country'])) { |
|
| 100 | 100 | $user_info['country'] = $default_user_info['country']; |
| 101 | 101 | $user_info['state'] = $default_user_info['state']; |
| 102 | 102 | $user_info['city'] = $default_user_info['city']; |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | $user_info['phone'] = $default_user_info['phone']; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
| 108 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
| 109 | 109 | $user_info['discount'] = (array)$user_info['discount']; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Payment details |
| 113 | 113 | $payment_details = array(); |
| 114 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
| 114 | + if (!empty($invoice_data['payment_details'])) { |
|
| 115 | 115 | $default_payment_details = array( |
| 116 | 116 | 'gateway' => 'manual', |
| 117 | 117 | 'gateway_title' => '', |
@@ -119,56 +119,56 @@ discard block |
||
| 119 | 119 | 'transaction_id' => '', |
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
| 122 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
| 123 | 123 | |
| 124 | - if ( empty( $payment_details['gateway'] ) ) { |
|
| 124 | + if (empty($payment_details['gateway'])) { |
|
| 125 | 125 | $payment_details['gateway'] = 'manual'; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if ( empty( $payment_details['currency'] ) ) { |
|
| 128 | + if (empty($payment_details['currency'])) { |
|
| 129 | 129 | $payment_details['currency'] = wpinv_get_default_country(); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
| 133 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
| 132 | + if (empty($payment_details['gateway_title'])) { |
|
| 133 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) ); |
|
| 138 | - |
|
| 139 | - if ( !empty( $payment_details ) ) { |
|
| 140 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
| 141 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
| 142 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
| 143 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $invoice->set( 'user_info', $user_info ); |
|
| 147 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
| 148 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
| 149 | - $invoice->set( 'address', $user_info['address'] ); |
|
| 150 | - $invoice->set( 'company', $user_info['company'] ); |
|
| 151 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
| 152 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
| 153 | - $invoice->set( 'city', $user_info['city'] ); |
|
| 154 | - $invoice->set( 'country', $user_info['country'] ); |
|
| 155 | - $invoice->set( 'state', $user_info['state'] ); |
|
| 156 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
| 157 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
| 158 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
| 159 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
| 160 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
| 161 | - |
|
| 162 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
| 163 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
| 164 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 165 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 166 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
| 167 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
| 137 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending')); |
|
| 138 | + |
|
| 139 | + if (!empty($payment_details)) { |
|
| 140 | + $invoice->set('currency', $payment_details['currency']); |
|
| 141 | + $invoice->set('gateway', $payment_details['gateway']); |
|
| 142 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
| 143 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $invoice->set('user_info', $user_info); |
|
| 147 | + $invoice->set('first_name', $user_info['first_name']); |
|
| 148 | + $invoice->set('last_name', $user_info['last_name']); |
|
| 149 | + $invoice->set('address', $user_info['address']); |
|
| 150 | + $invoice->set('company', $user_info['company']); |
|
| 151 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
| 152 | + $invoice->set('phone', $user_info['phone']); |
|
| 153 | + $invoice->set('city', $user_info['city']); |
|
| 154 | + $invoice->set('country', $user_info['country']); |
|
| 155 | + $invoice->set('state', $user_info['state']); |
|
| 156 | + $invoice->set('zip', $user_info['zip']); |
|
| 157 | + $invoice->set('discounts', $user_info['discount']); |
|
| 158 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
| 159 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
| 160 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
| 161 | + |
|
| 162 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
| 163 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
| 164 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 165 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 166 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
| 167 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
| 168 | 168 | |
| 169 | - $post_item = new WPInv_Item( $item_id ); |
|
| 170 | - if ( !empty( $post_item ) ) { |
|
| 171 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
| 169 | + $post_item = new WPInv_Item($item_id); |
|
| 170 | + if (!empty($post_item)) { |
|
| 171 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
| 172 | 172 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
| 173 | 173 | } else { |
| 174 | 174 | continue; |
@@ -178,253 +178,253 @@ discard block |
||
| 178 | 178 | 'name' => $name, |
| 179 | 179 | 'quantity' => $quantity, |
| 180 | 180 | 'item_price' => $item_price, |
| 181 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 182 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
| 183 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
| 184 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 185 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
| 181 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 182 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
| 183 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
| 184 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 185 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
| 186 | 186 | ); |
| 187 | 187 | |
| 188 | - $invoice->add_item( $item_id, $args ); |
|
| 188 | + $invoice->add_item($item_id, $args); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
| 192 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
| 193 | 193 | |
| 194 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
| 195 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
| 194 | + if (isset($invoice_data['post_date'])) { |
|
| 195 | + $invoice->set('date', $invoice_data['post_date']); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Invoice due date |
| 199 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
| 200 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
| 199 | + if (isset($invoice_data['due_date'])) { |
|
| 200 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | $invoice->save(); |
| 204 | 204 | |
| 205 | 205 | // Add notes |
| 206 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
| 207 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
| 206 | + if (!empty($invoice_data['private_note'])) { |
|
| 207 | + $invoice->add_note($invoice_data['private_note']); |
|
| 208 | 208 | } |
| 209 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
| 210 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
| 209 | + if (!empty($invoice_data['user_note'])) { |
|
| 210 | + $invoice->add_note($invoice_data['user_note'], true); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
| 213 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
| 214 | 214 | |
| 215 | - if ( ! empty( $invoice->ID ) ) { |
|
| 215 | + if (!empty($invoice->ID)) { |
|
| 216 | 216 | global $wpi_userID, $wpinv_ip_address_country; |
| 217 | 217 | |
| 218 | 218 | $checkout_session = wpinv_get_checkout_session(); |
| 219 | 219 | |
| 220 | 220 | $data_session = array(); |
| 221 | 221 | $data_session['invoice_id'] = $invoice->ID; |
| 222 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 222 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
| 223 | 223 | |
| 224 | - wpinv_set_checkout_session( $data_session ); |
|
| 224 | + wpinv_set_checkout_session($data_session); |
|
| 225 | 225 | |
| 226 | 226 | $wpi_userID = (int)$invoice->get_user_id(); |
| 227 | 227 | |
| 228 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
| 228 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
| 229 | 229 | $_POST['state'] = $invoice->state; |
| 230 | 230 | |
| 231 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 232 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 231 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 232 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 233 | 233 | |
| 234 | 234 | $wpinv_ip_address_country = $invoice->country; |
| 235 | 235 | |
| 236 | - $invoice = $invoice->recalculate_totals( true ); |
|
| 236 | + $invoice = $invoice->recalculate_totals(true); |
|
| 237 | 237 | |
| 238 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 238 | + wpinv_set_checkout_session($checkout_session); |
|
| 239 | 239 | |
| 240 | 240 | return $invoice; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if ( $wp_error ) { |
|
| 244 | - if ( is_wp_error( $invoice ) ) { |
|
| 243 | + if ($wp_error) { |
|
| 244 | + if (is_wp_error($invoice)) { |
|
| 245 | 245 | return $invoice; |
| 246 | 246 | } else { |
| 247 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
| 247 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
| 248 | 248 | } |
| 249 | 249 | } else { |
| 250 | 250 | return 0; |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | -function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) { |
|
| 255 | - $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL; |
|
| 254 | +function wpinv_update_invoice($invoice_data = array(), $wp_error = false) { |
|
| 255 | + $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL; |
|
| 256 | 256 | |
| 257 | - if ( !$invoice_ID ) { |
|
| 258 | - if ( $wp_error ) { |
|
| 259 | - return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ); |
|
| 257 | + if (!$invoice_ID) { |
|
| 258 | + if ($wp_error) { |
|
| 259 | + return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')); |
|
| 260 | 260 | } |
| 261 | 261 | return 0; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - $invoice = wpinv_get_invoice( $invoice_ID ); |
|
| 264 | + $invoice = wpinv_get_invoice($invoice_ID); |
|
| 265 | 265 | |
| 266 | - $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL; |
|
| 266 | + $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL; |
|
| 267 | 267 | |
| 268 | - if ( empty( $invoice->ID ) ) { |
|
| 269 | - if ( $wp_error ) { |
|
| 270 | - return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) ); |
|
| 268 | + if (empty($invoice->ID)) { |
|
| 269 | + if ($wp_error) { |
|
| 270 | + return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing')); |
|
| 271 | 271 | } |
| 272 | 272 | return 0; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) { |
|
| 276 | - if ( $wp_error ) { |
|
| 277 | - return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) ); |
|
| 275 | + if (!$invoice->has_status(array('wpi-pending'))) { |
|
| 276 | + if ($wp_error) { |
|
| 277 | + return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing')); |
|
| 278 | 278 | } |
| 279 | 279 | return 0; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // Invoice status |
| 283 | - if ( !empty( $invoice_data['status'] ) ) { |
|
| 284 | - $invoice->set( 'status', $invoice_data['status'] ); |
|
| 283 | + if (!empty($invoice_data['status'])) { |
|
| 284 | + $invoice->set('status', $invoice_data['status']); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // Invoice date |
| 288 | - if ( !empty( $invoice_data['post_date'] ) ) { |
|
| 289 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
| 288 | + if (!empty($invoice_data['post_date'])) { |
|
| 289 | + $invoice->set('date', $invoice_data['post_date']); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // Invoice due date |
| 293 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
| 294 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
| 293 | + if (isset($invoice_data['due_date'])) { |
|
| 294 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // Invoice IP address |
| 298 | - if ( !empty( $invoice_data['ip'] ) ) { |
|
| 299 | - $invoice->set( 'ip', $invoice_data['ip'] ); |
|
| 298 | + if (!empty($invoice_data['ip'])) { |
|
| 299 | + $invoice->set('ip', $invoice_data['ip']); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // User info |
| 303 | - if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) { |
|
| 304 | - $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info ); |
|
| 303 | + if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) { |
|
| 304 | + $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info); |
|
| 305 | 305 | |
| 306 | - if ( $discounts = $invoice->get_discounts() ) { |
|
| 306 | + if ($discounts = $invoice->get_discounts()) { |
|
| 307 | 307 | $set_discount = $discounts; |
| 308 | 308 | } else { |
| 309 | 309 | $set_discount = ''; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // Manage discount |
| 313 | - if ( !empty( $invoice_data['user_info']['discount'] ) ) { |
|
| 313 | + if (!empty($invoice_data['user_info']['discount'])) { |
|
| 314 | 314 | // Remove discount |
| 315 | - if ( $invoice_data['user_info']['discount'] == 'none' ) { |
|
| 315 | + if ($invoice_data['user_info']['discount'] == 'none') { |
|
| 316 | 316 | $set_discount = ''; |
| 317 | 317 | } else { |
| 318 | 318 | $set_discount = $invoice_data['user_info']['discount']; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - $invoice->set( 'discounts', $set_discount ); |
|
| 321 | + $invoice->set('discounts', $set_discount); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | $user_info['discount'] = $set_discount; |
| 325 | 325 | |
| 326 | - $invoice->set( 'user_info', $user_info ); |
|
| 326 | + $invoice->set('user_info', $user_info); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) { |
|
| 330 | - $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array(); |
|
| 329 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) { |
|
| 330 | + $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array(); |
|
| 331 | 331 | |
| 332 | - if ( !empty( $remove_items[0]['id'] ) ) { |
|
| 333 | - foreach ( $remove_items as $item ) { |
|
| 334 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 335 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 336 | - if ( empty( $item_id ) ) { |
|
| 332 | + if (!empty($remove_items[0]['id'])) { |
|
| 333 | + foreach ($remove_items as $item) { |
|
| 334 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 335 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 336 | + if (empty($item_id)) { |
|
| 337 | 337 | continue; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - foreach ( $invoice->cart_details as $cart_index => $cart_item ) { |
|
| 341 | - if ( $item_id == $cart_item['id'] ) { |
|
| 340 | + foreach ($invoice->cart_details as $cart_index => $cart_item) { |
|
| 341 | + if ($item_id == $cart_item['id']) { |
|
| 342 | 342 | $args = array( |
| 343 | 343 | 'id' => $item_id, |
| 344 | 344 | 'quantity' => $quantity, |
| 345 | 345 | 'cart_index' => $cart_index |
| 346 | 346 | ); |
| 347 | 347 | |
| 348 | - $invoice->remove_item( $item_id, $args ); |
|
| 348 | + $invoice->remove_item($item_id, $args); |
|
| 349 | 349 | break; |
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array(); |
|
| 355 | + $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array(); |
|
| 356 | 356 | |
| 357 | - if ( !empty( $add_items[0]['id'] ) ) { |
|
| 358 | - foreach ( $add_items as $item ) { |
|
| 359 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 360 | - $post_item = new WPInv_Item( $item_id ); |
|
| 361 | - if ( empty( $post_item ) ) { |
|
| 357 | + if (!empty($add_items[0]['id'])) { |
|
| 358 | + foreach ($add_items as $item) { |
|
| 359 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 360 | + $post_item = new WPInv_Item($item_id); |
|
| 361 | + if (empty($post_item)) { |
|
| 362 | 362 | continue; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | $valid_item = true; |
| 366 | - if ( !empty( $recurring_item ) ) { |
|
| 367 | - if ( $recurring_item->ID != $item_id ) { |
|
| 366 | + if (!empty($recurring_item)) { |
|
| 367 | + if ($recurring_item->ID != $item_id) { |
|
| 368 | 368 | $valid_item = false; |
| 369 | 369 | } |
| 370 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
| 370 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
| 371 | 371 | $valid_item = false; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - if ( !$valid_item ) { |
|
| 375 | - if ( $wp_error ) { |
|
| 376 | - return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) ); |
|
| 374 | + if (!$valid_item) { |
|
| 375 | + if ($wp_error) { |
|
| 376 | + return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing')); |
|
| 377 | 377 | } |
| 378 | 378 | return 0; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 382 | - $name = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name(); |
|
| 383 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price(); |
|
| 381 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 382 | + $name = !empty($item['name']) ? $item['name'] : $post_item->get_name(); |
|
| 383 | + $item_price = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price(); |
|
| 384 | 384 | |
| 385 | 385 | $args = array( |
| 386 | 386 | 'name' => $name, |
| 387 | 387 | 'quantity' => $quantity, |
| 388 | 388 | 'item_price' => $item_price, |
| 389 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 390 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0, |
|
| 391 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
| 392 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 393 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
| 389 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 390 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0, |
|
| 391 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
| 392 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 393 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
| 394 | 394 | ); |
| 395 | 395 | |
| 396 | - $invoice->add_item( $item_id, $args ); |
|
| 396 | + $invoice->add_item($item_id, $args); |
|
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | // Payment details |
| 402 | - if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) { |
|
| 403 | - if ( !empty( $payment_details['gateway'] ) ) { |
|
| 404 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
| 402 | + if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) { |
|
| 403 | + if (!empty($payment_details['gateway'])) { |
|
| 404 | + $invoice->set('gateway', $payment_details['gateway']); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - if ( !empty( $payment_details['transaction_id'] ) ) { |
|
| 408 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
| 407 | + if (!empty($payment_details['transaction_id'])) { |
|
| 408 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data ); |
|
| 412 | + do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data); |
|
| 413 | 413 | |
| 414 | 414 | // Parent invoice |
| 415 | - if ( !empty( $invoice_data['parent'] ) ) { |
|
| 416 | - $invoice->set( 'parent_invoice', $invoice_data['parent'] ); |
|
| 415 | + if (!empty($invoice_data['parent'])) { |
|
| 416 | + $invoice->set('parent_invoice', $invoice_data['parent']); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | // Save invoice data. |
| 420 | 420 | $invoice->save(); |
| 421 | 421 | |
| 422 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
| 423 | - if ( $wp_error ) { |
|
| 424 | - if ( is_wp_error( $invoice ) ) { |
|
| 422 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
| 423 | + if ($wp_error) { |
|
| 424 | + if (is_wp_error($invoice)) { |
|
| 425 | 425 | return $invoice; |
| 426 | 426 | } else { |
| 427 | - return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) ); |
|
| 427 | + return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing')); |
|
| 428 | 428 | } |
| 429 | 429 | } else { |
| 430 | 430 | return 0; |
@@ -432,13 +432,13 @@ discard block |
||
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | // Add private note |
| 435 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
| 436 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
| 435 | + if (!empty($invoice_data['private_note'])) { |
|
| 436 | + $invoice->add_note($invoice_data['private_note']); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // Add user note |
| 440 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
| 441 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
| 440 | + if (!empty($invoice_data['user_note'])) { |
|
| 441 | + $invoice->add_note($invoice_data['user_note'], true); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | global $wpi_userID, $wpinv_ip_address_country; |
@@ -447,450 +447,450 @@ discard block |
||
| 447 | 447 | |
| 448 | 448 | $data_session = array(); |
| 449 | 449 | $data_session['invoice_id'] = $invoice->ID; |
| 450 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 450 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
| 451 | 451 | |
| 452 | - wpinv_set_checkout_session( $data_session ); |
|
| 452 | + wpinv_set_checkout_session($data_session); |
|
| 453 | 453 | |
| 454 | 454 | $wpi_userID = (int)$invoice->get_user_id(); |
| 455 | 455 | |
| 456 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
| 456 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
| 457 | 457 | $_POST['state'] = $invoice->state; |
| 458 | 458 | |
| 459 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 460 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 459 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 460 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 461 | 461 | |
| 462 | 462 | $wpinv_ip_address_country = $invoice->country; |
| 463 | 463 | |
| 464 | - $invoice = $invoice->recalculate_totals( true ); |
|
| 464 | + $invoice = $invoice->recalculate_totals(true); |
|
| 465 | 465 | |
| 466 | - do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data ); |
|
| 466 | + do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data); |
|
| 467 | 467 | |
| 468 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 468 | + wpinv_set_checkout_session($checkout_session); |
|
| 469 | 469 | |
| 470 | 470 | return $invoice; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
| 474 | - if ( $cart && empty( $invoice_id ) ) { |
|
| 473 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
| 474 | + if ($cart && empty($invoice_id)) { |
|
| 475 | 475 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 478 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 479 | 479 | |
| 480 | - if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) { |
|
| 480 | + if (!empty($invoice) && !empty($invoice->ID)) { |
|
| 481 | 481 | return $invoice; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | return NULL; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
| 488 | - return wpinv_get_invoice( $invoice_id, true ); |
|
| 487 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
| 488 | + return wpinv_get_invoice($invoice_id, true); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
| 492 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 491 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
| 492 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 493 | 493 | return $invoice->get_description(); |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
| 497 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 496 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
| 497 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 498 | 498 | return $invoice->get_currency(); |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
| 502 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 501 | +function wpinv_get_payment_user_email($invoice_id) { |
|
| 502 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 503 | 503 | return $invoice->get_email(); |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | -function wpinv_get_user_id( $invoice_id ) { |
|
| 507 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 506 | +function wpinv_get_user_id($invoice_id) { |
|
| 507 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 508 | 508 | return $invoice->get_user_id(); |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
| 512 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 511 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
| 512 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 513 | 513 | |
| 514 | - return $invoice->get_status( $return_label ); |
|
| 514 | + return $invoice->get_status($return_label); |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
| 518 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 517 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
| 518 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 519 | 519 | |
| 520 | - return $invoice->get_gateway( $return_label ); |
|
| 520 | + return $invoice->get_gateway($return_label); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
| 524 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 523 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
| 524 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 525 | 525 | |
| 526 | 526 | return $invoice->get_gateway_title(); |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
| 530 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 529 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
| 530 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 531 | 531 | |
| 532 | 532 | return $invoice->get_transaction_id(); |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
| 535 | +function wpinv_get_id_by_transaction_id($key) { |
|
| 536 | 536 | global $wpdb; |
| 537 | 537 | |
| 538 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 538 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
| 539 | 539 | |
| 540 | - if ( $invoice_id != NULL ) |
|
| 540 | + if ($invoice_id != NULL) |
|
| 541 | 541 | return $invoice_id; |
| 542 | 542 | |
| 543 | 543 | return 0; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 547 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 546 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 547 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 548 | 548 | |
| 549 | - return $invoice->get_meta( $meta_key, $single ); |
|
| 549 | + return $invoice->get_meta($meta_key, $single); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 553 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 552 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 553 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 554 | 554 | |
| 555 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
| 555 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
| 559 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 558 | +function wpinv_get_items($invoice_id = 0) { |
|
| 559 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 560 | 560 | |
| 561 | 561 | $items = $invoice->get_items(); |
| 562 | 562 | $invoice_currency = $invoice->get_currency(); |
| 563 | 563 | |
| 564 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
| 565 | - foreach ( $items as $key => $item ) { |
|
| 564 | + if (!empty($items) && is_array($items)) { |
|
| 565 | + foreach ($items as $key => $item) { |
|
| 566 | 566 | $items[$key]['currency'] = $invoice_currency; |
| 567 | 567 | |
| 568 | - if ( !isset( $cart_item['subtotal'] ) ) { |
|
| 568 | + if (!isset($cart_item['subtotal'])) { |
|
| 569 | 569 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
| 570 | 570 | } |
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
| 574 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
| 578 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 577 | +function wpinv_get_fees($invoice_id = 0) { |
|
| 578 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 579 | 579 | $fees = $invoice->get_fees(); |
| 580 | 580 | |
| 581 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
| 581 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
| 585 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 584 | +function wpinv_get_invoice_ip($invoice_id) { |
|
| 585 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 586 | 586 | return $invoice->get_ip(); |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
| 590 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 589 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
| 590 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 591 | 591 | return $invoice->get_user_info(); |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
| 595 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 594 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
| 595 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 596 | 596 | |
| 597 | - return $invoice->get_subtotal( $currency ); |
|
| 597 | + return $invoice->get_subtotal($currency); |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
| 601 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 600 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
| 601 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 602 | 602 | |
| 603 | - return $invoice->get_tax( $currency ); |
|
| 603 | + return $invoice->get_tax($currency); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
| 607 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 606 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
| 607 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 608 | 608 | |
| 609 | - return $invoice->get_discount( $currency, $dash ); |
|
| 609 | + return $invoice->get_discount($currency, $dash); |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
| 613 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 612 | +function wpinv_discount_code($invoice_id = 0) { |
|
| 613 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 614 | 614 | |
| 615 | 615 | return $invoice->get_discount_code(); |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
| 619 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 618 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
| 619 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 620 | 620 | |
| 621 | - return $invoice->get_total( $currency ); |
|
| 621 | + return $invoice->get_total($currency); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | -function wpinv_get_date_created( $invoice_id = 0, $format = '' ) { |
|
| 625 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 624 | +function wpinv_get_date_created($invoice_id = 0, $format = '') { |
|
| 625 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 626 | 626 | |
| 627 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
| 627 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
| 628 | 628 | $date_created = $invoice->get_created_date(); |
| 629 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
| 629 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
| 630 | 630 | |
| 631 | 631 | return $date_created; |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) { |
|
| 635 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 634 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) { |
|
| 635 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 636 | 636 | |
| 637 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
| 637 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
| 638 | 638 | $date_completed = $invoice->get_completed_date(); |
| 639 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
| 640 | - if ( $invoice_date == '' && $default ) { |
|
| 641 | - $invoice_date = wpinv_get_date_created( $invoice_id, $format ); |
|
| 639 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
| 640 | + if ($invoice_date == '' && $default) { |
|
| 641 | + $invoice_date = wpinv_get_date_created($invoice_id, $format); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | return $invoice_date; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
| 648 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 647 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
| 648 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 649 | 649 | |
| 650 | 650 | return $invoice->vat_number; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
| 654 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 653 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
| 654 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 655 | 655 | |
| 656 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
| 656 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
| 659 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
| 660 | 660 | global $invoicing; |
| 661 | 661 | |
| 662 | - if ( empty( $invoice_id ) ) { |
|
| 662 | + if (empty($invoice_id)) { |
|
| 663 | 663 | return NULL; |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
| 666 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
| 667 | 667 | |
| 668 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
| 668 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
| 672 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 671 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
| 672 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 673 | 673 | return $invoice->get_key(); |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
| 677 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 676 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
| 677 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 678 | 678 | return $invoice->get_number(); |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
| 681 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
| 682 | 682 | $cart_items = wpinv_get_cart_content_details(); |
| 683 | 683 | $items = array(); |
| 684 | 684 | |
| 685 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 685 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 686 | 686 | |
| 687 | - if( $cart_items ) { |
|
| 687 | + if ($cart_items) { |
|
| 688 | 688 | |
| 689 | - foreach( $cart_items as $item ) { |
|
| 689 | + foreach ($cart_items as $item) { |
|
| 690 | 690 | |
| 691 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
| 692 | - $items[] = $item; |
|
| 691 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 692 | + $items[] = $item; |
|
| 693 | 693 | } |
| 694 | 694 | } |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 697 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 698 | 698 | |
| 699 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
| 699 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
| 702 | +function wpinv_get_cart_items_subtotal($items) { |
|
| 703 | 703 | $subtotal = 0.00; |
| 704 | 704 | |
| 705 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
| 706 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
| 705 | + if (is_array($items) && !empty($items)) { |
|
| 706 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
| 707 | 707 | |
| 708 | - if( is_array( $prices ) ) { |
|
| 709 | - $subtotal = array_sum( $prices ); |
|
| 708 | + if (is_array($prices)) { |
|
| 709 | + $subtotal = array_sum($prices); |
|
| 710 | 710 | } else { |
| 711 | 711 | $subtotal = 0.00; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - if( $subtotal < 0 ) { |
|
| 714 | + if ($subtotal < 0) { |
|
| 715 | 715 | $subtotal = 0.00; |
| 716 | 716 | } |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
| 719 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
| 723 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 724 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 722 | +function wpinv_get_cart_subtotal($items = array()) { |
|
| 723 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 724 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 725 | 725 | |
| 726 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
| 726 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | -function wpinv_cart_subtotal( $items = array() ) { |
|
| 730 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
| 729 | +function wpinv_cart_subtotal($items = array()) { |
|
| 730 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
| 731 | 731 | |
| 732 | 732 | return $price; |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
| 736 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
| 737 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
| 738 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
| 735 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
| 736 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
| 737 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
| 738 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
| 739 | 739 | $fees = (float)wpinv_get_cart_fee_total(); |
| 740 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 740 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 741 | 741 | $total = 0; |
| 742 | 742 | } else { |
| 743 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 743 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - if ( $total < 0 ) { |
|
| 746 | + if ($total < 0) { |
|
| 747 | 747 | $total = 0.00; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
| 750 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
| 751 | 751 | |
| 752 | - return wpinv_sanitize_amount( $total ); |
|
| 752 | + return wpinv_sanitize_amount($total); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
| 755 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
| 756 | 756 | global $cart_total; |
| 757 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
| 758 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
| 757 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
| 758 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
| 759 | 759 | |
| 760 | 760 | $cart_total = $total; |
| 761 | 761 | |
| 762 | - if ( !$echo ) { |
|
| 762 | + if (!$echo) { |
|
| 763 | 763 | return $total; |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | echo $total; |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | -function wpinv_get_cart_tax( $items = array() ) { |
|
| 769 | +function wpinv_get_cart_tax($items = array()) { |
|
| 770 | 770 | $cart_tax = 0; |
| 771 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 771 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 772 | 772 | |
| 773 | - if ( $items ) { |
|
| 774 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
| 773 | + if ($items) { |
|
| 774 | + $taxes = wp_list_pluck($items, 'tax'); |
|
| 775 | 775 | |
| 776 | - if( is_array( $taxes ) ) { |
|
| 777 | - $cart_tax = array_sum( $taxes ); |
|
| 776 | + if (is_array($taxes)) { |
|
| 777 | + $cart_tax = array_sum($taxes); |
|
| 778 | 778 | } |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | $cart_tax += wpinv_get_cart_fee_tax(); |
| 782 | 782 | |
| 783 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
| 783 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
| 787 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
| 788 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
| 786 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
| 787 | + $cart_tax = wpinv_get_cart_tax($items); |
|
| 788 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
| 789 | 789 | |
| 790 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
| 790 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
| 791 | 791 | |
| 792 | - if ( !$echo ) { |
|
| 792 | + if (!$echo) { |
|
| 793 | 793 | return $tax; |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | echo $tax; |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
| 799 | +function wpinv_get_cart_discount_code($items = array()) { |
|
| 800 | 800 | $invoice = wpinv_get_invoice_cart(); |
| 801 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
| 801 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
| 802 | 802 | |
| 803 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
| 803 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
| 807 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
| 806 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
| 807 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
| 808 | 808 | |
| 809 | - if ( $cart_discount_code != '' ) { |
|
| 809 | + if ($cart_discount_code != '') { |
|
| 810 | 810 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
| 813 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
| 814 | 814 | |
| 815 | - if ( !$echo ) { |
|
| 815 | + if (!$echo) { |
|
| 816 | 816 | return $discount_code; |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | echo $discount_code; |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | -function wpinv_get_cart_discount( $items = array() ) { |
|
| 822 | +function wpinv_get_cart_discount($items = array()) { |
|
| 823 | 823 | $invoice = wpinv_get_invoice_cart(); |
| 824 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
| 824 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
| 825 | 825 | |
| 826 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
| 826 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
| 830 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
| 831 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
| 829 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
| 830 | + $cart_discount = wpinv_get_cart_discount($items); |
|
| 831 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
| 832 | 832 | |
| 833 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
| 833 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
| 834 | 834 | |
| 835 | - if ( !$echo ) { |
|
| 835 | + if (!$echo) { |
|
| 836 | 836 | return $discount; |
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | echo $discount; |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
| 843 | - $item = new WPInv_Item( $item_id ); |
|
| 842 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
| 843 | + $item = new WPInv_Item($item_id); |
|
| 844 | 844 | |
| 845 | - return $item->get_fees( $type, $item_id ); |
|
| 845 | + return $item->get_fees($type, $item_id); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | function wpinv_get_cart_fee_total() { |
| 849 | - $total = 0; |
|
| 849 | + $total = 0; |
|
| 850 | 850 | $fees = wpinv_get_cart_fees(); |
| 851 | 851 | |
| 852 | - if ( $fees ) { |
|
| 853 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 852 | + if ($fees) { |
|
| 853 | + foreach ($fees as $fee_id => $fee) { |
|
| 854 | 854 | $total += $fee['amount']; |
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
| 858 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | function wpinv_get_cart_fee_tax() { |
| 862 | 862 | $tax = 0; |
| 863 | 863 | $fees = wpinv_get_cart_fees(); |
| 864 | 864 | |
| 865 | - if ( $fees ) { |
|
| 866 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 867 | - if( ! empty( $fee['no_tax'] ) ) { |
|
| 865 | + if ($fees) { |
|
| 866 | + foreach ($fees as $fee_id => $fee) { |
|
| 867 | + if (!empty($fee['no_tax'])) { |
|
| 868 | 868 | continue; |
| 869 | 869 | } |
| 870 | 870 | |
| 871 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
| 871 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
| 872 | 872 | } |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
| 875 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | function wpinv_cart_has_recurring_item() { |
| 879 | 879 | $cart_items = wpinv_get_cart_contents(); |
| 880 | 880 | |
| 881 | - if ( empty( $cart_items ) ) { |
|
| 881 | + if (empty($cart_items)) { |
|
| 882 | 882 | return false; |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | $has_subscription = false; |
| 886 | - foreach( $cart_items as $cart_item ) { |
|
| 887 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 886 | + foreach ($cart_items as $cart_item) { |
|
| 887 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 888 | 888 | $has_subscription = true; |
| 889 | 889 | break; |
| 890 | 890 | } |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
| 893 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | function wpinv_cart_has_free_trial() { |
@@ -898,97 +898,97 @@ discard block |
||
| 898 | 898 | |
| 899 | 899 | $free_trial = false; |
| 900 | 900 | |
| 901 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 901 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 902 | 902 | $free_trial = true; |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
| 905 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | function wpinv_get_cart_contents() { |
| 909 | 909 | $cart_details = wpinv_get_cart_details(); |
| 910 | 910 | |
| 911 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
| 911 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | function wpinv_get_cart_content_details() { |
| 915 | 915 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 916 | 916 | $cart_items = wpinv_get_cart_contents(); |
| 917 | 917 | |
| 918 | - if ( empty( $cart_items ) ) { |
|
| 918 | + if (empty($cart_items)) { |
|
| 919 | 919 | return false; |
| 920 | 920 | } |
| 921 | 921 | $invoice = wpinv_get_invoice_cart(); |
| 922 | - if ( empty( $invoice ) ) { |
|
| 922 | + if (empty($invoice)) { |
|
| 923 | 923 | return false; |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | $details = array(); |
| 927 | - $length = count( $cart_items ) - 1; |
|
| 927 | + $length = count($cart_items) - 1; |
|
| 928 | 928 | |
| 929 | - if ( empty( $_POST['country'] ) ) { |
|
| 929 | + if (empty($_POST['country'])) { |
|
| 930 | 930 | $_POST['country'] = $invoice->country; |
| 931 | 931 | } |
| 932 | - if ( !isset( $_POST['state'] ) ) { |
|
| 932 | + if (!isset($_POST['state'])) { |
|
| 933 | 933 | $_POST['state'] = $invoice->state; |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | - foreach( $cart_items as $key => $item ) { |
|
| 937 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
| 938 | - if ( empty( $item_id ) ) { |
|
| 936 | + foreach ($cart_items as $key => $item) { |
|
| 937 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
| 938 | + if (empty($item_id)) { |
|
| 939 | 939 | continue; |
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | $wpi_current_id = $invoice->ID; |
| 943 | 943 | $wpi_item_id = $item_id; |
| 944 | 944 | |
| 945 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
| 945 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
| 946 | 946 | $item_price = $item['custom_price']; |
| 947 | 947 | } else { |
| 948 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
| 948 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
| 949 | 949 | $item_price = $item['item_price']; |
| 950 | 950 | } else { |
| 951 | - $item_price = wpinv_get_item_price( $item_id ); |
|
| 951 | + $item_price = wpinv_get_item_price($item_id); |
|
| 952 | 952 | } |
| 953 | 953 | } |
| 954 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
| 955 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
| 956 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
| 957 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
| 954 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
| 955 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
| 956 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
| 957 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
| 958 | 958 | |
| 959 | 959 | $subtotal = $item_price * $quantity; |
| 960 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
| 961 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
| 962 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
| 960 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
| 961 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
| 962 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
| 963 | 963 | |
| 964 | - if ( wpinv_prices_include_tax() ) { |
|
| 965 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 964 | + if (wpinv_prices_include_tax()) { |
|
| 965 | + $subtotal -= wpinv_round_amount($tax); |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | - $total = $subtotal - $discount + $tax; |
|
| 968 | + $total = $subtotal - $discount + $tax; |
|
| 969 | 969 | |
| 970 | 970 | // Do not allow totals to go negatve |
| 971 | - if( $total < 0 ) { |
|
| 971 | + if ($total < 0) { |
|
| 972 | 972 | $total = 0; |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | - $details[ $key ] = array( |
|
| 975 | + $details[$key] = array( |
|
| 976 | 976 | 'id' => $item_id, |
| 977 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
| 978 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 979 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 977 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
| 978 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 979 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 980 | 980 | 'quantity' => $quantity, |
| 981 | - 'discount' => wpinv_round_amount( $discount ), |
|
| 982 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 983 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 984 | - 'price' => wpinv_round_amount( $total ), |
|
| 981 | + 'discount' => wpinv_round_amount($discount), |
|
| 982 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 983 | + 'tax' => wpinv_round_amount($tax), |
|
| 984 | + 'price' => wpinv_round_amount($total), |
|
| 985 | 985 | 'vat_rates_class' => $tax_class, |
| 986 | 986 | 'vat_rate' => $tax_rate, |
| 987 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 987 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 988 | 988 | 'fees' => $fees, |
| 989 | 989 | ); |
| 990 | 990 | |
| 991 | - if ( $wpinv_is_last_cart_item ) { |
|
| 991 | + if ($wpinv_is_last_cart_item) { |
|
| 992 | 992 | $wpinv_is_last_cart_item = false; |
| 993 | 993 | $wpinv_flat_discount_total = 0.00; |
| 994 | 994 | } |
@@ -997,67 +997,67 @@ discard block |
||
| 997 | 997 | return $details; |
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
| 1000 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
| 1001 | 1001 | global $ajax_cart_details; |
| 1002 | 1002 | |
| 1003 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 1003 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 1004 | 1004 | $cart_details = $ajax_cart_details; |
| 1005 | - if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) { |
|
| 1005 | + if (empty($cart_details) && !empty($invoice->cart_details)) { |
|
| 1006 | 1006 | $cart_details = $invoice->cart_details; |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
| 1010 | - $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country(); |
|
| 1009 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
| 1010 | + $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country(); |
|
| 1011 | 1011 | |
| 1012 | - foreach ( $cart_details as $key => $cart_item ) { |
|
| 1013 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
| 1012 | + foreach ($cart_details as $key => $cart_item) { |
|
| 1013 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
| 1014 | 1014 | |
| 1015 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
| 1016 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
| 1015 | + if (!isset($cart_item['subtotal'])) { |
|
| 1016 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
| 1017 | 1017 | } |
| 1018 | 1018 | } |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
| 1021 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
| 1025 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
| 1024 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
| 1025 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
| 1026 | 1026 | return; |
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | - if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) { |
|
| 1029 | + if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) { |
|
| 1030 | 1030 | return; |
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1033 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1034 | 1034 | |
| 1035 | - $old_status = wpinv_status_nicename( $old_status ); |
|
| 1036 | - $new_status = wpinv_status_nicename( $new_status ); |
|
| 1035 | + $old_status = wpinv_status_nicename($old_status); |
|
| 1036 | + $new_status = wpinv_status_nicename($new_status); |
|
| 1037 | 1037 | |
| 1038 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
| 1038 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
| 1039 | 1039 | |
| 1040 | 1040 | // Add note |
| 1041 | - return $invoice->add_note( $status_change, false, false, true ); |
|
| 1041 | + return $invoice->add_note($status_change, false, false, true); |
|
| 1042 | 1042 | } |
| 1043 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
| 1043 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
| 1044 | 1044 | |
| 1045 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
| 1045 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
| 1046 | 1046 | global $wpi_has_free_trial; |
| 1047 | 1047 | |
| 1048 | 1048 | $wpi_has_free_trial = false; |
| 1049 | 1049 | |
| 1050 | - if ( $old_status == 'publish' ) { |
|
| 1050 | + if ($old_status == 'publish') { |
|
| 1051 | 1051 | return; // Make sure that payments are only paid once |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | // Make sure the payment completion is only processed when new status is paid |
| 1055 | - if ( $new_status != 'publish' ) { |
|
| 1055 | + if ($new_status != 'publish') { |
|
| 1056 | 1056 | return; |
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 1060 | - if ( empty( $invoice ) ) { |
|
| 1059 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 1060 | + if (empty($invoice)) { |
|
| 1061 | 1061 | return; |
| 1062 | 1062 | } |
| 1063 | 1063 | |
@@ -1065,58 +1065,58 @@ discard block |
||
| 1065 | 1065 | $completed_date = $invoice->completed_date; |
| 1066 | 1066 | $cart_details = $invoice->cart_details; |
| 1067 | 1067 | |
| 1068 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
| 1068 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
| 1069 | 1069 | |
| 1070 | - if ( is_array( $cart_details ) ) { |
|
| 1070 | + if (is_array($cart_details)) { |
|
| 1071 | 1071 | // Increase purchase count and earnings |
| 1072 | - foreach ( $cart_details as $cart_index => $item ) { |
|
| 1072 | + foreach ($cart_details as $cart_index => $item) { |
|
| 1073 | 1073 | // Ensure these actions only run once, ever |
| 1074 | - if ( empty( $completed_date ) ) { |
|
| 1075 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
| 1074 | + if (empty($completed_date)) { |
|
| 1075 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | } |
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | 1080 | // Check for discount codes and increment their use counts |
| 1081 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
| 1082 | - if( ! empty( $discounts ) ) { |
|
| 1083 | - foreach( $discounts as $code ) { |
|
| 1084 | - wpinv_increase_discount_usage( $code ); |
|
| 1081 | + if ($discounts = $invoice->get_discounts(true)) { |
|
| 1082 | + if (!empty($discounts)) { |
|
| 1083 | + foreach ($discounts as $code) { |
|
| 1084 | + wpinv_increase_discount_usage($code); |
|
| 1085 | 1085 | } |
| 1086 | 1086 | } |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | // Ensure this action only runs once ever |
| 1090 | - if( empty( $completed_date ) ) { |
|
| 1090 | + if (empty($completed_date)) { |
|
| 1091 | 1091 | // Save the completed date |
| 1092 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
| 1092 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
| 1093 | 1093 | $invoice->save(); |
| 1094 | 1094 | |
| 1095 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
| 1095 | + do_action('wpinv_complete_payment', $invoice_id); |
|
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | 1098 | // Empty the shopping cart |
| 1099 | 1099 | wpinv_empty_cart(); |
| 1100 | 1100 | } |
| 1101 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
| 1101 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
| 1102 | 1102 | |
| 1103 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
| 1104 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
| 1103 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
| 1104 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
| 1105 | 1105 | |
| 1106 | - if ( empty( $invoice ) ) { |
|
| 1106 | + if (empty($invoice)) { |
|
| 1107 | 1107 | return false; |
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | - return $invoice->update_status( $new_status ); |
|
| 1110 | + return $invoice->update_status($new_status); |
|
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
| 1113 | +function wpinv_cart_has_fees($type = 'all') { |
|
| 1114 | 1114 | return false; |
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | function wpinv_validate_checkout_fields() { |
| 1118 | 1118 | // Check if there is $_POST |
| 1119 | - if ( empty( $_POST ) ) { |
|
| 1119 | + if (empty($_POST)) { |
|
| 1120 | 1120 | return false; |
| 1121 | 1121 | } |
| 1122 | 1122 | |
@@ -1128,11 +1128,11 @@ discard block |
||
| 1128 | 1128 | ); |
| 1129 | 1129 | |
| 1130 | 1130 | // Validate agree to terms |
| 1131 | - $page = wpinv_get_option( 'tandc_page' ); |
|
| 1132 | - if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){ |
|
| 1131 | + $page = wpinv_get_option('tandc_page'); |
|
| 1132 | + if (isset($page) && (int)$page > 0 && apply_filters('wpinv_checkout_show_terms', true)) { |
|
| 1133 | 1133 | // Validate agree to terms |
| 1134 | - if ( ! isset( $_POST['wpi_terms'] ) || !$_POST['wpi_terms'] ) { |
|
| 1135 | - wpinv_set_error( 'accept_terms', apply_filters( 'wpinv_accept_terms_error_text', __( 'You must accept terms and conditions', 'invoicing' ) ) ); |
|
| 1134 | + if (!isset($_POST['wpi_terms']) || !$_POST['wpi_terms']) { |
|
| 1135 | + wpinv_set_error('accept_terms', apply_filters('wpinv_accept_terms_error_text', __('You must accept terms and conditions', 'invoicing'))); |
|
| 1136 | 1136 | } |
| 1137 | 1137 | } |
| 1138 | 1138 | |
@@ -1148,26 +1148,26 @@ discard block |
||
| 1148 | 1148 | |
| 1149 | 1149 | $invoice = wpinv_get_invoice_cart(); |
| 1150 | 1150 | $has_subscription = $invoice->is_recurring(); |
| 1151 | - if ( empty( $invoice ) ) { |
|
| 1152 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
| 1151 | + if (empty($invoice)) { |
|
| 1152 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
| 1153 | 1153 | return $gateway; |
| 1154 | 1154 | } |
| 1155 | 1155 | |
| 1156 | 1156 | // Check if a gateway value is present |
| 1157 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
| 1158 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
| 1157 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
| 1158 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
| 1159 | 1159 | |
| 1160 | - if ( $invoice->is_free() ) { |
|
| 1160 | + if ($invoice->is_free()) { |
|
| 1161 | 1161 | $gateway = 'manual'; |
| 1162 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
| 1163 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
| 1164 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 1165 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
| 1162 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
| 1163 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
| 1164 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
| 1165 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
| 1166 | 1166 | } |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
| 1170 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
| 1169 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
| 1170 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | 1173 | return $gateway; |
@@ -1181,10 +1181,10 @@ discard block |
||
| 1181 | 1181 | |
| 1182 | 1182 | $error = false; |
| 1183 | 1183 | // If we have discounts, loop through them |
| 1184 | - if ( ! empty( $discounts ) ) { |
|
| 1185 | - foreach ( $discounts as $discount ) { |
|
| 1184 | + if (!empty($discounts)) { |
|
| 1185 | + foreach ($discounts as $discount) { |
|
| 1186 | 1186 | // Check if valid |
| 1187 | - if ( !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) { |
|
| 1187 | + if (!wpinv_is_discount_valid($discount, (int)$wpi_cart->get_user_id())) { |
|
| 1188 | 1188 | // Discount is not valid |
| 1189 | 1189 | $error = true; |
| 1190 | 1190 | } |
@@ -1194,20 +1194,20 @@ discard block |
||
| 1194 | 1194 | return NULL; |
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | - if ( $error && !wpinv_get_errors() ) { |
|
| 1198 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
| 1197 | + if ($error && !wpinv_get_errors()) { |
|
| 1198 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | - return implode( ',', $discounts ); |
|
| 1201 | + return implode(',', $discounts); |
|
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | function wpinv_checkout_validate_cc() { |
| 1205 | 1205 | $card_data = wpinv_checkout_get_cc_info(); |
| 1206 | 1206 | |
| 1207 | 1207 | // Validate the card zip |
| 1208 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
| 1209 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
| 1210 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
| 1208 | + if (!empty($card_data['wpinv_zip'])) { |
|
| 1209 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
| 1210 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
| 1211 | 1211 | } |
| 1212 | 1212 | } |
| 1213 | 1213 | |
@@ -1217,28 +1217,28 @@ discard block |
||
| 1217 | 1217 | |
| 1218 | 1218 | function wpinv_checkout_get_cc_info() { |
| 1219 | 1219 | $cc_info = array(); |
| 1220 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 1221 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 1222 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 1223 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 1224 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 1225 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
| 1226 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
| 1227 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
| 1228 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
| 1229 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
| 1220 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
| 1221 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
| 1222 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
| 1223 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
| 1224 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
| 1225 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
| 1226 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
| 1227 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
| 1228 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
| 1229 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
| 1230 | 1230 | |
| 1231 | 1231 | // Return cc info |
| 1232 | 1232 | return $cc_info; |
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
| 1235 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
| 1236 | 1236 | $ret = false; |
| 1237 | 1237 | |
| 1238 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
| 1238 | + if (empty($zip) || empty($country_code)) |
|
| 1239 | 1239 | return $ret; |
| 1240 | 1240 | |
| 1241 | - $country_code = strtoupper( $country_code ); |
|
| 1241 | + $country_code = strtoupper($country_code); |
|
| 1242 | 1242 | |
| 1243 | 1243 | $zip_regex = array( |
| 1244 | 1244 | "AD" => "AD\d{3}", |
@@ -1398,24 +1398,24 @@ discard block |
||
| 1398 | 1398 | "ZM" => "\d{5}" |
| 1399 | 1399 | ); |
| 1400 | 1400 | |
| 1401 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
| 1401 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
| 1402 | 1402 | $ret = true; |
| 1403 | 1403 | |
| 1404 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
| 1404 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | 1407 | function wpinv_checkout_validate_agree_to_terms() { |
| 1408 | 1408 | // Validate agree to terms |
| 1409 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
| 1409 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
| 1410 | 1410 | // User did not agree |
| 1411 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
| 1411 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
| 1412 | 1412 | } |
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | 1415 | function wpinv_checkout_validate_invoice_user() { |
| 1416 | 1416 | global $wpi_cart, $user_ID; |
| 1417 | 1417 | |
| 1418 | - if(empty($wpi_cart)){ |
|
| 1418 | + if (empty($wpi_cart)) { |
|
| 1419 | 1419 | $wpi_cart = wpinv_get_invoice_cart(); |
| 1420 | 1420 | } |
| 1421 | 1421 | |
@@ -1425,45 +1425,45 @@ discard block |
||
| 1425 | 1425 | ); |
| 1426 | 1426 | |
| 1427 | 1427 | // If guest checkout allowed |
| 1428 | - if ( !wpinv_require_login_to_checkout() ) { |
|
| 1428 | + if (!wpinv_require_login_to_checkout()) { |
|
| 1429 | 1429 | return $valid_user_data; |
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | // Verify there is a user_ID |
| 1433 | - if ( $user_ID == $invoice_user ) { |
|
| 1433 | + if ($user_ID == $invoice_user) { |
|
| 1434 | 1434 | // Get the logged in user data |
| 1435 | - $user_data = get_userdata( $user_ID ); |
|
| 1436 | - $required_fields = wpinv_checkout_required_fields(); |
|
| 1435 | + $user_data = get_userdata($user_ID); |
|
| 1436 | + $required_fields = wpinv_checkout_required_fields(); |
|
| 1437 | 1437 | |
| 1438 | 1438 | // Loop through required fields and show error messages |
| 1439 | - if ( !empty( $required_fields ) ) { |
|
| 1440 | - foreach ( $required_fields as $field_name => $value ) { |
|
| 1441 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
| 1442 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
| 1439 | + if (!empty($required_fields)) { |
|
| 1440 | + foreach ($required_fields as $field_name => $value) { |
|
| 1441 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
| 1442 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
| 1443 | 1443 | } |
| 1444 | 1444 | } |
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | 1447 | // Verify data |
| 1448 | - if ( $user_data ) { |
|
| 1448 | + if ($user_data) { |
|
| 1449 | 1449 | // Collected logged in user data |
| 1450 | 1450 | $valid_user_data = array( |
| 1451 | 1451 | 'user_id' => $user_ID, |
| 1452 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
| 1453 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
| 1454 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
| 1452 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
| 1453 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
| 1454 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
| 1455 | 1455 | ); |
| 1456 | 1456 | |
| 1457 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
| 1458 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
| 1457 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
| 1458 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
| 1459 | 1459 | } |
| 1460 | 1460 | } else { |
| 1461 | 1461 | // Set invalid user error |
| 1462 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
| 1462 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
| 1463 | 1463 | } |
| 1464 | 1464 | } else { |
| 1465 | 1465 | // Set invalid user error |
| 1466 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
| 1466 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | 1469 | // Return user data |
@@ -1475,27 +1475,27 @@ discard block |
||
| 1475 | 1475 | |
| 1476 | 1476 | $data = array(); |
| 1477 | 1477 | |
| 1478 | - if ( is_user_logged_in() ) { |
|
| 1479 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
| 1478 | + if (is_user_logged_in()) { |
|
| 1479 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id())) { |
|
| 1480 | 1480 | $data['user_id'] = (int)get_current_user_id(); |
| 1481 | 1481 | } else { |
| 1482 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
| 1482 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | } else { |
| 1485 | 1485 | // If guest checkout allowed |
| 1486 | - if ( !wpinv_require_login_to_checkout() ) { |
|
| 1486 | + if (!wpinv_require_login_to_checkout()) { |
|
| 1487 | 1487 | $data['user_id'] = 0; |
| 1488 | 1488 | } else { |
| 1489 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
| 1489 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
| 1490 | 1490 | } |
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | 1493 | return $data; |
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
| 1496 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
| 1497 | 1497 | |
| 1498 | - if ( !empty( $valid_data['current_user']['user_id'] ) ) { |
|
| 1498 | + if (!empty($valid_data['current_user']['user_id'])) { |
|
| 1499 | 1499 | $user = $valid_data['current_user']; |
| 1500 | 1500 | } else { |
| 1501 | 1501 | // Set the valid invoice user |
@@ -1503,7 +1503,7 @@ discard block |
||
| 1503 | 1503 | } |
| 1504 | 1504 | |
| 1505 | 1505 | // Verify invoice have an user |
| 1506 | - if ( false === $user || empty( $user ) ) { |
|
| 1506 | + if (false === $user || empty($user)) { |
|
| 1507 | 1507 | return false; |
| 1508 | 1508 | } |
| 1509 | 1509 | |
@@ -1520,11 +1520,11 @@ discard block |
||
| 1520 | 1520 | 'zip', |
| 1521 | 1521 | ); |
| 1522 | 1522 | |
| 1523 | - foreach ( $address_fields as $field ) { |
|
| 1524 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
| 1523 | + foreach ($address_fields as $field) { |
|
| 1524 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
| 1525 | 1525 | |
| 1526 | - if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) { |
|
| 1527 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
| 1526 | + if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) { |
|
| 1527 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
| 1528 | 1528 | } |
| 1529 | 1529 | } |
| 1530 | 1530 | |
@@ -1532,28 +1532,28 @@ discard block |
||
| 1532 | 1532 | return $user; |
| 1533 | 1533 | } |
| 1534 | 1534 | |
| 1535 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
| 1535 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
| 1536 | 1536 | global $wpi_session; |
| 1537 | 1537 | |
| 1538 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
| 1538 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
| 1539 | 1539 | } |
| 1540 | 1540 | |
| 1541 | 1541 | function wpinv_get_checkout_session() { |
| 1542 | 1542 | global $wpi_session; |
| 1543 | 1543 | |
| 1544 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
| 1544 | + return $wpi_session->get('wpinv_checkout'); |
|
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | 1547 | function wpinv_empty_cart() { |
| 1548 | 1548 | global $wpi_session; |
| 1549 | 1549 | |
| 1550 | 1550 | // Remove cart contents |
| 1551 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
| 1551 | + $wpi_session->set('wpinv_checkout', NULL); |
|
| 1552 | 1552 | |
| 1553 | 1553 | // Remove all cart fees |
| 1554 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
| 1554 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
| 1555 | 1555 | |
| 1556 | - do_action( 'wpinv_empty_cart' ); |
|
| 1556 | + do_action('wpinv_empty_cart'); |
|
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | 1559 | function wpinv_process_checkout() { |
@@ -1562,7 +1562,7 @@ discard block |
||
| 1562 | 1562 | wpinv_clear_errors(); |
| 1563 | 1563 | |
| 1564 | 1564 | $invoice = wpinv_get_invoice_cart(); |
| 1565 | - if ( empty( $invoice ) ) { |
|
| 1565 | + if (empty($invoice)) { |
|
| 1566 | 1566 | return false; |
| 1567 | 1567 | } |
| 1568 | 1568 | |
@@ -1570,42 +1570,42 @@ discard block |
||
| 1570 | 1570 | |
| 1571 | 1571 | $wpi_checkout_id = $invoice->ID; |
| 1572 | 1572 | |
| 1573 | - do_action( 'wpinv_pre_process_checkout' ); |
|
| 1573 | + do_action('wpinv_pre_process_checkout'); |
|
| 1574 | 1574 | |
| 1575 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
| 1575 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
| 1576 | 1576 | $valid_data = false; |
| 1577 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
| 1577 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
| 1578 | 1578 | } else { |
| 1579 | 1579 | // Validate the form $_POST data |
| 1580 | 1580 | $valid_data = wpinv_validate_checkout_fields(); |
| 1581 | 1581 | |
| 1582 | 1582 | // Allow themes and plugins to hook to errors |
| 1583 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
| 1583 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 1586 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 1587 | 1587 | |
| 1588 | 1588 | // Validate the user |
| 1589 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
| 1589 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
| 1590 | 1590 | |
| 1591 | 1591 | // Let extensions validate fields after user is logged in if user has used login/registration form |
| 1592 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
| 1592 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
| 1593 | 1593 | |
| 1594 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
| 1595 | - if ( $is_ajax ) { |
|
| 1596 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
| 1594 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
| 1595 | + if ($is_ajax) { |
|
| 1596 | + do_action('wpinv_ajax_checkout_errors'); |
|
| 1597 | 1597 | die(); |
| 1598 | 1598 | } else { |
| 1599 | 1599 | return false; |
| 1600 | 1600 | } |
| 1601 | 1601 | } |
| 1602 | 1602 | |
| 1603 | - if ( $is_ajax ) { |
|
| 1603 | + if ($is_ajax) { |
|
| 1604 | 1604 | // Save address fields. |
| 1605 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
| 1606 | - foreach ( $address_fields as $field ) { |
|
| 1607 | - if ( isset( $user[$field] ) ) { |
|
| 1608 | - $invoice->set( $field, $user[$field] ); |
|
| 1605 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
| 1606 | + foreach ($address_fields as $field) { |
|
| 1607 | + if (isset($user[$field])) { |
|
| 1608 | + $invoice->set($field, $user[$field]); |
|
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | 1611 | $invoice->save(); |
@@ -1613,15 +1613,15 @@ discard block |
||
| 1613 | 1613 | |
| 1614 | 1614 | $response['success'] = true; |
| 1615 | 1615 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 1616 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
| 1616 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
| 1617 | 1617 | $response['data']['discount'] = $invoice->get_discount(); |
| 1618 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
| 1618 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
| 1619 | 1619 | $response['data']['tax'] = $invoice->get_tax(); |
| 1620 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
| 1620 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
| 1621 | 1621 | $response['data']['total'] = $invoice->get_total(); |
| 1622 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
| 1622 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
| 1623 | 1623 | |
| 1624 | - wp_send_json( $response ); |
|
| 1624 | + wp_send_json($response); |
|
| 1625 | 1625 | } |
| 1626 | 1626 | |
| 1627 | 1627 | $user_info = array( |
@@ -1643,42 +1643,42 @@ discard block |
||
| 1643 | 1643 | |
| 1644 | 1644 | // Setup invoice information |
| 1645 | 1645 | $invoice_data = array( |
| 1646 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
| 1646 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
| 1647 | 1647 | 'items' => $cart_items, |
| 1648 | 1648 | 'cart_discounts' => $discounts, |
| 1649 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1650 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
| 1651 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
| 1652 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
| 1653 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
| 1649 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1650 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
| 1651 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
| 1652 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
| 1653 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
| 1654 | 1654 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
| 1655 | 1655 | 'user_email' => $user['email'], |
| 1656 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
| 1657 | - 'user_info' => stripslashes_deep( $user_info ), |
|
| 1656 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
| 1657 | + 'user_info' => stripslashes_deep($user_info), |
|
| 1658 | 1658 | 'post_data' => $_POST, |
| 1659 | 1659 | 'cart_details' => $cart_items, |
| 1660 | 1660 | 'gateway' => $valid_data['gateway'], |
| 1661 | 1661 | 'card_info' => $valid_data['cc_info'] |
| 1662 | 1662 | ); |
| 1663 | 1663 | |
| 1664 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1665 | - if ( is_array( $vat_info ) ) { |
|
| 1664 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1665 | + if (is_array($vat_info)) { |
|
| 1666 | 1666 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
| 1667 | 1667 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
| 1668 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1668 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1669 | 1669 | |
| 1670 | 1670 | // Add the VAT rate to each item in the cart |
| 1671 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
| 1671 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
| 1672 | 1672 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
| 1673 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
| 1673 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
| 1674 | 1674 | } |
| 1675 | 1675 | } |
| 1676 | 1676 | |
| 1677 | 1677 | // Save vat fields. |
| 1678 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
| 1679 | - foreach ( $address_fields as $field ) { |
|
| 1680 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
| 1681 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
| 1678 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
| 1679 | + foreach ($address_fields as $field) { |
|
| 1680 | + if (isset($invoice_data['user_info'][$field])) { |
|
| 1681 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
| 1682 | 1682 | } |
| 1683 | 1683 | |
| 1684 | 1684 | $invoice->save(); |
@@ -1688,55 +1688,55 @@ discard block |
||
| 1688 | 1688 | $valid_data['user'] = $user; |
| 1689 | 1689 | |
| 1690 | 1690 | // Allow themes and plugins to hook before the gateway |
| 1691 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
| 1691 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
| 1692 | 1692 | |
| 1693 | 1693 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
| 1694 | - if ( !$invoice_data['price'] ) { |
|
| 1694 | + if (!$invoice_data['price']) { |
|
| 1695 | 1695 | // Revert to manual |
| 1696 | 1696 | $invoice_data['gateway'] = 'manual'; |
| 1697 | 1697 | $_POST['wpi-gateway'] = 'manual'; |
| 1698 | 1698 | } |
| 1699 | 1699 | |
| 1700 | 1700 | // Allow the invoice data to be modified before it is sent to the gateway |
| 1701 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
| 1701 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
| 1702 | 1702 | |
| 1703 | - if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) { |
|
| 1703 | + if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') { |
|
| 1704 | 1704 | $mode = 'test'; |
| 1705 | 1705 | } else { |
| 1706 | - $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live'; |
|
| 1706 | + $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'; |
|
| 1707 | 1707 | } |
| 1708 | 1708 | |
| 1709 | 1709 | // Setup the data we're storing in the purchase session |
| 1710 | 1710 | $session_data = $invoice_data; |
| 1711 | 1711 | // Make sure credit card numbers are never stored in sessions |
| 1712 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
| 1713 | - unset( $session_data['card_info']['card_number'] ); |
|
| 1712 | + if (!empty($session_data['card_info']['card_number'])) { |
|
| 1713 | + unset($session_data['card_info']['card_number']); |
|
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | 1716 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
| 1717 | - wpinv_set_checkout_session( $invoice_data ); |
|
| 1717 | + wpinv_set_checkout_session($invoice_data); |
|
| 1718 | 1718 | |
| 1719 | 1719 | // Set gateway |
| 1720 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
| 1721 | - $invoice->update_meta( '_wpinv_mode', $mode ); |
|
| 1722 | - $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) ); |
|
| 1720 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
| 1721 | + $invoice->update_meta('_wpinv_mode', $mode); |
|
| 1722 | + $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp'))); |
|
| 1723 | 1723 | |
| 1724 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
| 1724 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
| 1725 | 1725 | |
| 1726 | 1726 | // Send info to the gateway for payment processing |
| 1727 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
| 1727 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
| 1728 | 1728 | die(); |
| 1729 | 1729 | } |
| 1730 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
| 1730 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
| 1731 | 1731 | |
| 1732 | -function wpinv_get_invoices( $args ) { |
|
| 1733 | - $args = wp_parse_args( $args, array( |
|
| 1734 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 1732 | +function wpinv_get_invoices($args) { |
|
| 1733 | + $args = wp_parse_args($args, array( |
|
| 1734 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
| 1735 | 1735 | 'type' => 'wpi_invoice', |
| 1736 | 1736 | 'parent' => null, |
| 1737 | 1737 | 'user' => null, |
| 1738 | 1738 | 'email' => '', |
| 1739 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 1739 | + 'limit' => get_option('posts_per_page'), |
|
| 1740 | 1740 | 'offset' => null, |
| 1741 | 1741 | 'page' => 1, |
| 1742 | 1742 | 'exclude' => array(), |
@@ -1744,7 +1744,7 @@ discard block |
||
| 1744 | 1744 | 'order' => 'DESC', |
| 1745 | 1745 | 'return' => 'objects', |
| 1746 | 1746 | 'paginate' => false, |
| 1747 | - ) ); |
|
| 1747 | + )); |
|
| 1748 | 1748 | |
| 1749 | 1749 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
| 1750 | 1750 | $map_legacy = array( |
@@ -1757,18 +1757,18 @@ discard block |
||
| 1757 | 1757 | 'paged' => 'page', |
| 1758 | 1758 | ); |
| 1759 | 1759 | |
| 1760 | - foreach ( $map_legacy as $from => $to ) { |
|
| 1761 | - if ( isset( $args[ $from ] ) ) { |
|
| 1762 | - $args[ $to ] = $args[ $from ]; |
|
| 1760 | + foreach ($map_legacy as $from => $to) { |
|
| 1761 | + if (isset($args[$from])) { |
|
| 1762 | + $args[$to] = $args[$from]; |
|
| 1763 | 1763 | } |
| 1764 | 1764 | } |
| 1765 | 1765 | |
| 1766 | - if ( get_query_var( 'paged' ) ) |
|
| 1766 | + if (get_query_var('paged')) |
|
| 1767 | 1767 | $args['page'] = get_query_var('paged'); |
| 1768 | - else if ( get_query_var( 'page' ) ) |
|
| 1769 | - $args['page'] = get_query_var( 'page' ); |
|
| 1770 | - else if ( !empty( $args[ 'page' ] ) ) |
|
| 1771 | - $args['page'] = $args[ 'page' ]; |
|
| 1768 | + else if (get_query_var('page')) |
|
| 1769 | + $args['page'] = get_query_var('page'); |
|
| 1770 | + else if (!empty($args['page'])) |
|
| 1771 | + $args['page'] = $args['page']; |
|
| 1772 | 1772 | else |
| 1773 | 1773 | $args['page'] = 1; |
| 1774 | 1774 | |
@@ -1781,49 +1781,49 @@ discard block |
||
| 1781 | 1781 | 'post_status' => $args['status'], |
| 1782 | 1782 | 'posts_per_page' => $args['limit'], |
| 1783 | 1783 | 'meta_query' => array(), |
| 1784 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
| 1784 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
| 1785 | 1785 | 'fields' => 'ids', |
| 1786 | 1786 | 'orderby' => $args['orderby'], |
| 1787 | 1787 | 'order' => $args['order'], |
| 1788 | 1788 | ); |
| 1789 | 1789 | |
| 1790 | - if ( !empty( $args['user'] ) ) { |
|
| 1791 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
| 1790 | + if (!empty($args['user'])) { |
|
| 1791 | + $wp_query_args['author'] = absint($args['user']); |
|
| 1792 | 1792 | } |
| 1793 | 1793 | |
| 1794 | - if ( ! is_null( $args['parent'] ) ) { |
|
| 1795 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
| 1794 | + if (!is_null($args['parent'])) { |
|
| 1795 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
| 1796 | 1796 | } |
| 1797 | 1797 | |
| 1798 | - if ( ! is_null( $args['offset'] ) ) { |
|
| 1799 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
| 1798 | + if (!is_null($args['offset'])) { |
|
| 1799 | + $wp_query_args['offset'] = absint($args['offset']); |
|
| 1800 | 1800 | } else { |
| 1801 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
| 1801 | + $wp_query_args['paged'] = absint($args['page']); |
|
| 1802 | 1802 | } |
| 1803 | 1803 | |
| 1804 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 1805 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 1804 | + if (!empty($args['exclude'])) { |
|
| 1805 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 1806 | 1806 | } |
| 1807 | 1807 | |
| 1808 | - if ( ! $args['paginate' ] ) { |
|
| 1808 | + if (!$args['paginate']) { |
|
| 1809 | 1809 | $wp_query_args['no_found_rows'] = true; |
| 1810 | 1810 | } |
| 1811 | 1811 | |
| 1812 | 1812 | $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args); |
| 1813 | 1813 | |
| 1814 | 1814 | // Get results. |
| 1815 | - $invoices = new WP_Query( $wp_query_args ); |
|
| 1815 | + $invoices = new WP_Query($wp_query_args); |
|
| 1816 | 1816 | |
| 1817 | - if ( 'objects' === $args['return'] ) { |
|
| 1818 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
| 1819 | - } elseif ( 'self' === $args['return'] ) { |
|
| 1817 | + if ('objects' === $args['return']) { |
|
| 1818 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
| 1819 | + } elseif ('self' === $args['return']) { |
|
| 1820 | 1820 | return $invoices; |
| 1821 | 1821 | } else { |
| 1822 | 1822 | $return = $invoices->posts; |
| 1823 | 1823 | } |
| 1824 | 1824 | |
| 1825 | - if ( $args['paginate' ] ) { |
|
| 1826 | - return (object) array( |
|
| 1825 | + if ($args['paginate']) { |
|
| 1826 | + return (object)array( |
|
| 1827 | 1827 | 'invoices' => $return, |
| 1828 | 1828 | 'total' => $invoices->found_posts, |
| 1829 | 1829 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1835,22 +1835,22 @@ discard block |
||
| 1835 | 1835 | |
| 1836 | 1836 | function wpinv_get_user_invoices_columns() { |
| 1837 | 1837 | $columns = array( |
| 1838 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1839 | - 'created-date' => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1840 | - 'payment-date' => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1841 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
| 1842 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
| 1843 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
| 1838 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
| 1839 | + 'created-date' => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'), |
|
| 1840 | + 'payment-date' => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'), |
|
| 1841 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
| 1842 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
| 1843 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
| 1844 | 1844 | ); |
| 1845 | 1845 | |
| 1846 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
| 1846 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
| 1847 | 1847 | } |
| 1848 | 1848 | |
| 1849 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
| 1849 | +function wpinv_payment_receipt($atts, $content = null) { |
|
| 1850 | 1850 | global $wpinv_receipt_args; |
| 1851 | 1851 | |
| 1852 | - $wpinv_receipt_args = shortcode_atts( array( |
|
| 1853 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
| 1852 | + $wpinv_receipt_args = shortcode_atts(array( |
|
| 1853 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
| 1854 | 1854 | 'price' => true, |
| 1855 | 1855 | 'discount' => true, |
| 1856 | 1856 | 'items' => true, |
@@ -1859,195 +1859,195 @@ discard block |
||
| 1859 | 1859 | 'invoice_key' => false, |
| 1860 | 1860 | 'payment_method' => true, |
| 1861 | 1861 | 'invoice_id' => true |
| 1862 | - ), $atts, 'wpinv_receipt' ); |
|
| 1862 | + ), $atts, 'wpinv_receipt'); |
|
| 1863 | 1863 | |
| 1864 | 1864 | $session = wpinv_get_checkout_session(); |
| 1865 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 1866 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
| 1867 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
| 1865 | + if (isset($_GET['invoice_key'])) { |
|
| 1866 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
| 1867 | + } else if ($session && isset($session['invoice_key'])) { |
|
| 1868 | 1868 | $invoice_key = $session['invoice_key']; |
| 1869 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
| 1869 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
| 1870 | 1870 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
| 1871 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1872 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
| 1871 | + } else if (isset($_GET['invoice-id'])) { |
|
| 1872 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
| 1873 | 1873 | } |
| 1874 | 1874 | |
| 1875 | 1875 | // No key found |
| 1876 | - if ( ! isset( $invoice_key ) ) { |
|
| 1876 | + if (!isset($invoice_key)) { |
|
| 1877 | 1877 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1878 | 1878 | } |
| 1879 | 1879 | |
| 1880 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1881 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 1882 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 1880 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1881 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 1882 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 1883 | 1883 | $invoice_id = (int)$_GET['invoice-id']; |
| 1884 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 1884 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
| 1885 | 1885 | } |
| 1886 | 1886 | |
| 1887 | 1887 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
| 1888 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
| 1888 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
| 1889 | 1889 | // login redirect |
| 1890 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
| 1890 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
| 1893 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
| 1894 | 1894 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | 1897 | ob_start(); |
| 1898 | 1898 | |
| 1899 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
| 1899 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
| 1900 | 1900 | |
| 1901 | 1901 | $display = ob_get_clean(); |
| 1902 | 1902 | |
| 1903 | 1903 | return $display; |
| 1904 | 1904 | } |
| 1905 | 1905 | |
| 1906 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
| 1906 | +function wpinv_get_invoice_id_by_key($key) { |
|
| 1907 | 1907 | global $wpdb; |
| 1908 | 1908 | |
| 1909 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 1909 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
| 1910 | 1910 | |
| 1911 | - if ( $invoice_id != NULL ) |
|
| 1911 | + if ($invoice_id != NULL) |
|
| 1912 | 1912 | return $invoice_id; |
| 1913 | 1913 | |
| 1914 | 1914 | return 0; |
| 1915 | 1915 | } |
| 1916 | 1916 | |
| 1917 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
| 1917 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
| 1918 | 1918 | $return = false; |
| 1919 | 1919 | |
| 1920 | - if ( empty( $invoice_key ) ) { |
|
| 1920 | + if (empty($invoice_key)) { |
|
| 1921 | 1921 | return $return; |
| 1922 | 1922 | } |
| 1923 | 1923 | |
| 1924 | 1924 | global $wpinv_receipt_args; |
| 1925 | 1925 | |
| 1926 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1927 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1928 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
| 1926 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1927 | + if (isset($_GET['invoice-id'])) { |
|
| 1928 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
| 1929 | 1929 | } |
| 1930 | 1930 | |
| 1931 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
| 1931 | + if (empty($wpinv_receipt_args['id'])) { |
|
| 1932 | 1932 | return $return; |
| 1933 | 1933 | } |
| 1934 | 1934 | |
| 1935 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
| 1936 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
| 1935 | + $invoice = wpinv_get_invoice($wpinv_receipt_args['id']); |
|
| 1936 | + if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) { |
|
| 1937 | 1937 | return $return; |
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | - if ( is_user_logged_in() ) { |
|
| 1941 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
| 1940 | + if (is_user_logged_in()) { |
|
| 1941 | + if ((int)$invoice->get_user_id() === (int)get_current_user_id()) { |
|
| 1942 | 1942 | $return = true; |
| 1943 | 1943 | } |
| 1944 | 1944 | } |
| 1945 | 1945 | |
| 1946 | 1946 | $session = wpinv_get_checkout_session(); |
| 1947 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
| 1948 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1947 | + if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) { |
|
| 1948 | + $check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1949 | 1949 | |
| 1950 | - if ( wpinv_require_login_to_checkout() ) { |
|
| 1950 | + if (wpinv_require_login_to_checkout()) { |
|
| 1951 | 1951 | $return = $return && $check_key === $invoice_key; |
| 1952 | 1952 | } else { |
| 1953 | 1953 | $return = $check_key === $invoice_key; |
| 1954 | 1954 | } |
| 1955 | 1955 | } |
| 1956 | 1956 | |
| 1957 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
| 1957 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
| 1958 | 1958 | } |
| 1959 | 1959 | |
| 1960 | 1960 | function wpinv_pay_for_invoice() { |
| 1961 | 1961 | global $wpinv_euvat; |
| 1962 | 1962 | |
| 1963 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 1963 | + if (isset($_GET['invoice_key'])) { |
|
| 1964 | 1964 | $checkout_uri = wpinv_get_checkout_uri(); |
| 1965 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
| 1965 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
| 1966 | 1966 | |
| 1967 | - if ( empty( $invoice_key ) ) { |
|
| 1968 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
| 1969 | - wp_redirect( $checkout_uri ); |
|
| 1967 | + if (empty($invoice_key)) { |
|
| 1968 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
| 1969 | + wp_redirect($checkout_uri); |
|
| 1970 | 1970 | wpinv_die(); |
| 1971 | 1971 | } |
| 1972 | 1972 | |
| 1973 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
| 1973 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
| 1974 | 1974 | |
| 1975 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1976 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 1977 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 1975 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1976 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 1977 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 1978 | 1978 | $invoice_id = (int)$_GET['invoice-id']; |
| 1979 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 1979 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
| 1980 | 1980 | } |
| 1981 | 1981 | |
| 1982 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
| 1983 | - if ( $invoice->needs_payment() ) { |
|
| 1982 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
| 1983 | + if ($invoice->needs_payment()) { |
|
| 1984 | 1984 | $data = array(); |
| 1985 | 1985 | $data['invoice_id'] = $invoice_id; |
| 1986 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 1986 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 1987 | 1987 | |
| 1988 | - wpinv_set_checkout_session( $data ); |
|
| 1988 | + wpinv_set_checkout_session($data); |
|
| 1989 | 1989 | |
| 1990 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
| 1990 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
| 1991 | 1991 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
| 1992 | 1992 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
| 1993 | 1993 | |
| 1994 | - wpinv_recalculate_tax( true ); |
|
| 1994 | + wpinv_recalculate_tax(true); |
|
| 1995 | 1995 | } |
| 1996 | 1996 | |
| 1997 | 1997 | } else { |
| 1998 | 1998 | $checkout_uri = $invoice->get_view_url(); |
| 1999 | 1999 | } |
| 2000 | 2000 | } else { |
| 2001 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
| 2001 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
| 2002 | 2002 | |
| 2003 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
| 2003 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
| 2004 | 2004 | } |
| 2005 | 2005 | |
| 2006 | - wp_redirect( $checkout_uri ); |
|
| 2006 | + wp_redirect($checkout_uri); |
|
| 2007 | 2007 | wpinv_die(); |
| 2008 | 2008 | } |
| 2009 | 2009 | } |
| 2010 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
| 2010 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
| 2011 | 2011 | |
| 2012 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
| 2013 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
| 2014 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
| 2012 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
| 2013 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
| 2014 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
| 2015 | 2015 | $user_id = $invoice->get_user_id(); |
| 2016 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
| 2016 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
| 2017 | 2017 | |
| 2018 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
| 2019 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
| 2018 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
| 2019 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
| 2020 | 2020 | |
| 2021 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
| 2021 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
| 2022 | 2022 | wpinv_die(); |
| 2023 | 2023 | } |
| 2024 | 2024 | } |
| 2025 | 2025 | } |
| 2026 | 2026 | } |
| 2027 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
| 2027 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
| 2028 | 2028 | |
| 2029 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
| 2030 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
| 2029 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
| 2030 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
| 2031 | 2031 | |
| 2032 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
| 2032 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
| 2033 | 2033 | return false; |
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 2036 | - if ( empty( $transaction_id ) ) { |
|
| 2036 | + if (empty($transaction_id)) { |
|
| 2037 | 2037 | $transaction_id = $invoice_id; |
| 2038 | 2038 | } |
| 2039 | 2039 | |
| 2040 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
| 2040 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
| 2041 | 2041 | |
| 2042 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
| 2042 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
| 2043 | 2043 | } |
| 2044 | 2044 | |
| 2045 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
| 2046 | - if ( empty( $status_display ) ) { |
|
| 2047 | - $status_display = wpinv_status_nicename( $status ); |
|
| 2045 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
| 2046 | + if (empty($status_display)) { |
|
| 2047 | + $status_display = wpinv_status_nicename($status); |
|
| 2048 | 2048 | } |
| 2049 | 2049 | |
| 2050 | - switch ( $status ) { |
|
| 2050 | + switch ($status) { |
|
| 2051 | 2051 | case 'publish' : |
| 2052 | 2052 | case 'wpi-renewal' : |
| 2053 | 2053 | $class = 'label-success'; |
@@ -2072,257 +2072,257 @@ discard block |
||
| 2072 | 2072 | |
| 2073 | 2073 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
| 2074 | 2074 | |
| 2075 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
| 2075 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
| 2076 | 2076 | } |
| 2077 | 2077 | |
| 2078 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
| 2079 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
| 2080 | - if ( null !== $check ) { |
|
| 2078 | +function wpinv_format_invoice_number($number, $type = '') { |
|
| 2079 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
| 2080 | + if (null !== $check) { |
|
| 2081 | 2081 | return $check; |
| 2082 | 2082 | } |
| 2083 | 2083 | |
| 2084 | - if ( !empty( $number ) && !is_numeric( $number ) ) { |
|
| 2084 | + if (!empty($number) && !is_numeric($number)) { |
|
| 2085 | 2085 | return $number; |
| 2086 | 2086 | } |
| 2087 | 2087 | |
| 2088 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
| 2089 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 2090 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 2088 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
| 2089 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 2090 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 2091 | 2091 | |
| 2092 | - $padd = absint( $padd ); |
|
| 2093 | - $formatted_number = absint( $number ); |
|
| 2092 | + $padd = absint($padd); |
|
| 2093 | + $formatted_number = absint($number); |
|
| 2094 | 2094 | |
| 2095 | - if ( $padd > 0 ) { |
|
| 2096 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
| 2095 | + if ($padd > 0) { |
|
| 2096 | + $formatted_number = zeroise($formatted_number, $padd); |
|
| 2097 | 2097 | } |
| 2098 | 2098 | |
| 2099 | 2099 | $formatted_number = $prefix . $formatted_number . $postfix; |
| 2100 | 2100 | |
| 2101 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
| 2101 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
| 2102 | 2102 | } |
| 2103 | 2103 | |
| 2104 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
| 2105 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
| 2106 | - if ( null !== $check ) { |
|
| 2104 | +function wpinv_get_next_invoice_number($type = '') { |
|
| 2105 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
| 2106 | + if (null !== $check) { |
|
| 2107 | 2107 | return $check; |
| 2108 | 2108 | } |
| 2109 | 2109 | |
| 2110 | - if ( !wpinv_sequential_number_active() ) { |
|
| 2110 | + if (!wpinv_sequential_number_active()) { |
|
| 2111 | 2111 | return false; |
| 2112 | 2112 | } |
| 2113 | 2113 | |
| 2114 | - $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 ); |
|
| 2115 | - $start = wpinv_get_option( 'invoice_sequence_start', 1 ); |
|
| 2116 | - if ( !absint( $start ) > 0 ) { |
|
| 2114 | + $number = $last_number = get_option('wpinv_last_invoice_number', 0); |
|
| 2115 | + $start = wpinv_get_option('invoice_sequence_start', 1); |
|
| 2116 | + if (!absint($start) > 0) { |
|
| 2117 | 2117 | $start = 1; |
| 2118 | 2118 | } |
| 2119 | 2119 | $increment_number = true; |
| 2120 | 2120 | $save_number = false; |
| 2121 | 2121 | |
| 2122 | - if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) { |
|
| 2123 | - $number = wpinv_clean_invoice_number( $number ); |
|
| 2122 | + if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) { |
|
| 2123 | + $number = wpinv_clean_invoice_number($number); |
|
| 2124 | 2124 | } |
| 2125 | 2125 | |
| 2126 | - if ( empty( $number ) ) { |
|
| 2127 | - if ( !( $last_number === 0 || $last_number === '0' ) ) { |
|
| 2128 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) ); |
|
| 2126 | + if (empty($number)) { |
|
| 2127 | + if (!($last_number === 0 || $last_number === '0')) { |
|
| 2128 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true)))); |
|
| 2129 | 2129 | |
| 2130 | - if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) { |
|
| 2131 | - if ( is_numeric( $invoice_number ) ) { |
|
| 2130 | + if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) { |
|
| 2131 | + if (is_numeric($invoice_number)) { |
|
| 2132 | 2132 | $number = $invoice_number; |
| 2133 | 2133 | } else { |
| 2134 | - $number = wpinv_clean_invoice_number( $invoice_number ); |
|
| 2134 | + $number = wpinv_clean_invoice_number($invoice_number); |
|
| 2135 | 2135 | } |
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | - if ( empty( $number ) ) { |
|
| 2138 | + if (empty($number)) { |
|
| 2139 | 2139 | $increment_number = false; |
| 2140 | 2140 | $number = $start; |
| 2141 | - $save_number = ( $number - 1 ); |
|
| 2141 | + $save_number = ($number - 1); |
|
| 2142 | 2142 | } else { |
| 2143 | 2143 | $save_number = $number; |
| 2144 | 2144 | } |
| 2145 | 2145 | } |
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | - if ( $start > $number ) { |
|
| 2148 | + if ($start > $number) { |
|
| 2149 | 2149 | $increment_number = false; |
| 2150 | 2150 | $number = $start; |
| 2151 | - $save_number = ( $number - 1 ); |
|
| 2151 | + $save_number = ($number - 1); |
|
| 2152 | 2152 | } |
| 2153 | 2153 | |
| 2154 | - if ( $save_number !== false ) { |
|
| 2155 | - update_option( 'wpinv_last_invoice_number', $save_number ); |
|
| 2154 | + if ($save_number !== false) { |
|
| 2155 | + update_option('wpinv_last_invoice_number', $save_number); |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
| 2158 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
| 2159 | 2159 | |
| 2160 | - if ( $increment_number ) { |
|
| 2160 | + if ($increment_number) { |
|
| 2161 | 2161 | $number++; |
| 2162 | 2162 | } |
| 2163 | 2163 | |
| 2164 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
| 2164 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
| 2165 | 2165 | } |
| 2166 | 2166 | |
| 2167 | -function wpinv_clean_invoice_number( $number, $type = '' ) { |
|
| 2168 | - $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type ); |
|
| 2169 | - if ( null !== $check ) { |
|
| 2167 | +function wpinv_clean_invoice_number($number, $type = '') { |
|
| 2168 | + $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type); |
|
| 2169 | + if (null !== $check) { |
|
| 2170 | 2170 | return $check; |
| 2171 | 2171 | } |
| 2172 | 2172 | |
| 2173 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 2174 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 2173 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 2174 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 2175 | 2175 | |
| 2176 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
| 2176 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
| 2177 | 2177 | |
| 2178 | - $length = strlen( $number ); |
|
| 2179 | - $postfix_pos = strrpos( $number, $postfix ); |
|
| 2178 | + $length = strlen($number); |
|
| 2179 | + $postfix_pos = strrpos($number, $postfix); |
|
| 2180 | 2180 | |
| 2181 | - if ( false !== $postfix_pos ) { |
|
| 2182 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
| 2181 | + if (false !== $postfix_pos) { |
|
| 2182 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
| 2183 | 2183 | } |
| 2184 | 2184 | |
| 2185 | - $number = intval( $number ); |
|
| 2185 | + $number = intval($number); |
|
| 2186 | 2186 | |
| 2187 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
| 2187 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
| 2188 | 2188 | } |
| 2189 | 2189 | |
| 2190 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
| 2190 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
| 2191 | 2191 | global $wpdb; |
| 2192 | 2192 | |
| 2193 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
| 2194 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type ); |
|
| 2193 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
| 2194 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type); |
|
| 2195 | 2195 | } |
| 2196 | 2196 | |
| 2197 | - if ( !$update ) { |
|
| 2198 | - $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) ); |
|
| 2199 | - clean_post_cache( $post_ID ); |
|
| 2197 | + if (!$update) { |
|
| 2198 | + $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID)); |
|
| 2199 | + clean_post_cache($post_ID); |
|
| 2200 | 2200 | } |
| 2201 | 2201 | } |
| 2202 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
| 2202 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
| 2203 | 2203 | |
| 2204 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
| 2205 | - if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) { |
|
| 2206 | - wpinv_update_invoice_number( $post_ID, true, $post_after->post_type ); |
|
| 2204 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
| 2205 | + if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) { |
|
| 2206 | + wpinv_update_invoice_number($post_ID, true, $post_after->post_type); |
|
| 2207 | 2207 | } |
| 2208 | 2208 | } |
| 2209 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
| 2209 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
| 2210 | 2210 | |
| 2211 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) { |
|
| 2211 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') { |
|
| 2212 | 2212 | global $wpdb; |
| 2213 | 2213 | |
| 2214 | - $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type ); |
|
| 2215 | - if ( null !== $check ) { |
|
| 2214 | + $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type); |
|
| 2215 | + if (null !== $check) { |
|
| 2216 | 2216 | return $check; |
| 2217 | 2217 | } |
| 2218 | 2218 | |
| 2219 | - if ( wpinv_sequential_number_active() ) { |
|
| 2219 | + if (wpinv_sequential_number_active()) { |
|
| 2220 | 2220 | $number = wpinv_get_next_invoice_number(); |
| 2221 | 2221 | |
| 2222 | - if ( $save_sequential ) { |
|
| 2223 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
| 2222 | + if ($save_sequential) { |
|
| 2223 | + update_option('wpinv_last_invoice_number', $number); |
|
| 2224 | 2224 | } |
| 2225 | 2225 | } else { |
| 2226 | 2226 | $number = $post_ID; |
| 2227 | 2227 | } |
| 2228 | 2228 | |
| 2229 | - $number = wpinv_format_invoice_number( $number ); |
|
| 2229 | + $number = wpinv_format_invoice_number($number); |
|
| 2230 | 2230 | |
| 2231 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
| 2231 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
| 2232 | 2232 | |
| 2233 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
| 2233 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
| 2234 | 2234 | |
| 2235 | - clean_post_cache( $post_ID ); |
|
| 2235 | + clean_post_cache($post_ID); |
|
| 2236 | 2236 | |
| 2237 | 2237 | return $number; |
| 2238 | 2238 | } |
| 2239 | 2239 | |
| 2240 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
| 2241 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
| 2240 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
| 2241 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
| 2242 | 2242 | } |
| 2243 | 2243 | |
| 2244 | -function wpinv_generate_post_name( $post_ID ) { |
|
| 2245 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
| 2246 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
| 2244 | +function wpinv_generate_post_name($post_ID) { |
|
| 2245 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
| 2246 | + $post_name = sanitize_title($prefix . $post_ID); |
|
| 2247 | 2247 | |
| 2248 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
| 2248 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | -function wpinv_is_invoice_viewed( $invoice_id ) { |
|
| 2252 | - if ( empty( $invoice_id ) ) { |
|
| 2251 | +function wpinv_is_invoice_viewed($invoice_id) { |
|
| 2252 | + if (empty($invoice_id)) { |
|
| 2253 | 2253 | return false; |
| 2254 | 2254 | } |
| 2255 | 2255 | |
| 2256 | - $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true ); |
|
| 2256 | + $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true); |
|
| 2257 | 2257 | |
| 2258 | - if ( isset($viewed_meta) && 1 == $viewed_meta ) { |
|
| 2258 | + if (isset($viewed_meta) && 1 == $viewed_meta) { |
|
| 2259 | 2259 | $is_viewed = true; |
| 2260 | 2260 | } else { |
| 2261 | 2261 | $is_viewed = false; |
| 2262 | 2262 | } |
| 2263 | 2263 | |
| 2264 | - return apply_filters( 'wpinv_is_invoice_viewed', $is_viewed, $invoice_id ); |
|
| 2264 | + return apply_filters('wpinv_is_invoice_viewed', $is_viewed, $invoice_id); |
|
| 2265 | 2265 | } |
| 2266 | 2266 | |
| 2267 | 2267 | function wpinv_mark_invoice_viewed() { |
| 2268 | 2268 | |
| 2269 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 2269 | + if (isset($_GET['invoice_key'])) { |
|
| 2270 | 2270 | $invoice_key = urldecode($_GET['invoice_key']); |
| 2271 | 2271 | |
| 2272 | 2272 | $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
| 2273 | 2273 | $invoice = new WPInv_Invoice($invoice_id); |
| 2274 | 2274 | |
| 2275 | - if(!$invoice_id){ |
|
| 2275 | + if (!$invoice_id) { |
|
| 2276 | 2276 | return; |
| 2277 | 2277 | } |
| 2278 | 2278 | |
| 2279 | - if( is_user_logged_in()){ |
|
| 2279 | + if (is_user_logged_in()) { |
|
| 2280 | 2280 | $current_user = wp_get_current_user(); |
| 2281 | - if(!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()){ |
|
| 2282 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2281 | + if (!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()) { |
|
| 2282 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
| 2283 | 2283 | } |
| 2284 | 2284 | } else { |
| 2285 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2285 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
| 2286 | 2286 | } |
| 2287 | 2287 | } |
| 2288 | 2288 | |
| 2289 | 2289 | } |
| 2290 | -add_action( 'init', 'wpinv_mark_invoice_viewed' ); |
|
| 2290 | +add_action('init', 'wpinv_mark_invoice_viewed'); |
|
| 2291 | 2291 | |
| 2292 | -function wpinv_get_subscription( $invoice, $by_parent = false ) { |
|
| 2293 | - if ( empty( $invoice ) ) { |
|
| 2292 | +function wpinv_get_subscription($invoice, $by_parent = false) { |
|
| 2293 | + if (empty($invoice)) { |
|
| 2294 | 2294 | return false; |
| 2295 | 2295 | } |
| 2296 | 2296 | |
| 2297 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 2298 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 2297 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
| 2298 | + $invoice = wpinv_get_invoice($invoice); |
|
| 2299 | 2299 | } |
| 2300 | 2300 | |
| 2301 | - if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
| 2301 | + if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) { |
|
| 2302 | 2302 | return false; |
| 2303 | 2303 | } |
| 2304 | 2304 | |
| 2305 | - $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID; |
|
| 2305 | + $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID; |
|
| 2306 | 2306 | |
| 2307 | 2307 | $subs_db = new WPInv_Subscriptions_DB; |
| 2308 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) ); |
|
| 2308 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1)); |
|
| 2309 | 2309 | |
| 2310 | - if ( ! empty( $subs ) ) { |
|
| 2311 | - return reset( $subs ); |
|
| 2310 | + if (!empty($subs)) { |
|
| 2311 | + return reset($subs); |
|
| 2312 | 2312 | } |
| 2313 | 2313 | |
| 2314 | 2314 | return false; |
| 2315 | 2315 | } |
| 2316 | 2316 | |
| 2317 | -function wpinv_filter_posts_clauses( $clauses, $wp_query ) { |
|
| 2317 | +function wpinv_filter_posts_clauses($clauses, $wp_query) { |
|
| 2318 | 2318 | global $wpdb; |
| 2319 | 2319 | |
| 2320 | - if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) { |
|
| 2321 | - if ( !empty( $clauses['join'] ) ) { |
|
| 2320 | + if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') { |
|
| 2321 | + if (!empty($clauses['join'])) { |
|
| 2322 | 2322 | $clauses['join'] .= " "; |
| 2323 | 2323 | } |
| 2324 | 2324 | |
| 2325 | - if ( !empty( $clauses['fields'] ) ) { |
|
| 2325 | + if (!empty($clauses['fields'])) { |
|
| 2326 | 2326 | $clauses['fields'] .= ", "; |
| 2327 | 2327 | } |
| 2328 | 2328 | |
@@ -2333,4 +2333,4 @@ discard block |
||
| 2333 | 2333 | |
| 2334 | 2334 | return $clauses; |
| 2335 | 2335 | } |
| 2336 | -add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 ); |
|
| 2337 | 2336 | \ No newline at end of file |
| 2337 | +add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2); |
|
| 2338 | 2338 | \ No newline at end of file |
@@ -1,66 +1,66 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // MUST have WordPress. |
| 3 | -if ( !defined( 'WPINC' ) ) { |
|
| 4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 3 | +if (!defined('WPINC')) { |
|
| 4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | -function wpinv_get_option( $key = '', $default = false ) { |
|
| 7 | +function wpinv_get_option($key = '', $default = false) { |
|
| 8 | 8 | global $wpinv_options; |
| 9 | 9 | |
| 10 | - $value = isset( $wpinv_options[ $key ] ) ? $wpinv_options[ $key ] : $default; |
|
| 11 | - $value = apply_filters( 'wpinv_get_option', $value, $key, $default ); |
|
| 10 | + $value = isset($wpinv_options[$key]) ? $wpinv_options[$key] : $default; |
|
| 11 | + $value = apply_filters('wpinv_get_option', $value, $key, $default); |
|
| 12 | 12 | |
| 13 | - return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default ); |
|
| 13 | + return apply_filters('wpinv_get_option_' . $key, $value, $key, $default); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | -function wpinv_update_option( $key = '', $value = false ) { |
|
| 16 | +function wpinv_update_option($key = '', $value = false) { |
|
| 17 | 17 | // If no key, exit |
| 18 | - if ( empty( $key ) ) { |
|
| 18 | + if (empty($key)) { |
|
| 19 | 19 | return false; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - if ( empty( $value ) ) { |
|
| 23 | - $remove_option = wpinv_delete_option( $key ); |
|
| 22 | + if (empty($value)) { |
|
| 23 | + $remove_option = wpinv_delete_option($key); |
|
| 24 | 24 | return $remove_option; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // First let's grab the current settings |
| 28 | - $options = get_option( 'wpinv_settings' ); |
|
| 28 | + $options = get_option('wpinv_settings'); |
|
| 29 | 29 | |
| 30 | 30 | // Let other plugin alter the value |
| 31 | - $value = apply_filters( 'wpinv_update_option', $value, $key ); |
|
| 31 | + $value = apply_filters('wpinv_update_option', $value, $key); |
|
| 32 | 32 | |
| 33 | 33 | // Next let's try to update the value |
| 34 | - $options[ $key ] = $value; |
|
| 35 | - $did_update = update_option( 'wpinv_settings', $options ); |
|
| 34 | + $options[$key] = $value; |
|
| 35 | + $did_update = update_option('wpinv_settings', $options); |
|
| 36 | 36 | |
| 37 | 37 | // If it's updated, let's update the global variable |
| 38 | - if ( $did_update ) { |
|
| 38 | + if ($did_update) { |
|
| 39 | 39 | global $wpinv_options; |
| 40 | - $wpinv_options[ $key ] = $value; |
|
| 40 | + $wpinv_options[$key] = $value; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | return $did_update; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | -function wpinv_delete_option( $key = '' ) { |
|
| 46 | +function wpinv_delete_option($key = '') { |
|
| 47 | 47 | // If no key, exit |
| 48 | - if ( empty( $key ) ) { |
|
| 48 | + if (empty($key)) { |
|
| 49 | 49 | return false; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // First let's grab the current settings |
| 53 | - $options = get_option( 'wpinv_settings' ); |
|
| 53 | + $options = get_option('wpinv_settings'); |
|
| 54 | 54 | |
| 55 | 55 | // Next let's try to update the value |
| 56 | - if( isset( $options[ $key ] ) ) { |
|
| 57 | - unset( $options[ $key ] ); |
|
| 56 | + if (isset($options[$key])) { |
|
| 57 | + unset($options[$key]); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $did_update = update_option( 'wpinv_settings', $options ); |
|
| 60 | + $did_update = update_option('wpinv_settings', $options); |
|
| 61 | 61 | |
| 62 | 62 | // If it updated, let's update the global variable |
| 63 | - if ( $did_update ){ |
|
| 63 | + if ($did_update) { |
|
| 64 | 64 | global $wpinv_options; |
| 65 | 65 | $wpinv_options = $options; |
| 66 | 66 | } |
@@ -69,37 +69,37 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function wpinv_get_settings() { |
| 72 | - $settings = get_option( 'wpinv_settings' ); |
|
| 72 | + $settings = get_option('wpinv_settings'); |
|
| 73 | 73 | |
| 74 | - if ( empty( $settings ) ) { |
|
| 74 | + if (empty($settings)) { |
|
| 75 | 75 | // Update old settings with new single option |
| 76 | - $general_settings = is_array( get_option( 'wpinv_settings_general' ) ) ? get_option( 'wpinv_settings_general' ) : array(); |
|
| 77 | - $gateways_settings = is_array( get_option( 'wpinv_settings_gateways' ) ) ? get_option( 'wpinv_settings_gateways' ) : array(); |
|
| 78 | - $email_settings = is_array( get_option( 'wpinv_settings_emails' ) ) ? get_option( 'wpinv_settings_emails' ) : array(); |
|
| 79 | - $tax_settings = is_array( get_option( 'wpinv_settings_taxes' ) ) ? get_option( 'wpinv_settings_taxes' ) : array(); |
|
| 80 | - $misc_settings = is_array( get_option( 'wpinv_settings_misc' ) ) ? get_option( 'wpinv_settings_misc' ) : array(); |
|
| 81 | - $tool_settings = is_array( get_option( 'wpinv_settings_tools' ) ) ? get_option( 'wpinv_settings_tools' ) : array(); |
|
| 76 | + $general_settings = is_array(get_option('wpinv_settings_general')) ? get_option('wpinv_settings_general') : array(); |
|
| 77 | + $gateways_settings = is_array(get_option('wpinv_settings_gateways')) ? get_option('wpinv_settings_gateways') : array(); |
|
| 78 | + $email_settings = is_array(get_option('wpinv_settings_emails')) ? get_option('wpinv_settings_emails') : array(); |
|
| 79 | + $tax_settings = is_array(get_option('wpinv_settings_taxes')) ? get_option('wpinv_settings_taxes') : array(); |
|
| 80 | + $misc_settings = is_array(get_option('wpinv_settings_misc')) ? get_option('wpinv_settings_misc') : array(); |
|
| 81 | + $tool_settings = is_array(get_option('wpinv_settings_tools')) ? get_option('wpinv_settings_tools') : array(); |
|
| 82 | 82 | |
| 83 | - $settings = array_merge( $general_settings, $gateways_settings, $email_settings, $tax_settings, $misc_settings, $tool_settings ); |
|
| 83 | + $settings = array_merge($general_settings, $gateways_settings, $email_settings, $tax_settings, $misc_settings, $tool_settings); |
|
| 84 | 84 | |
| 85 | - update_option( 'wpinv_settings', $settings ); |
|
| 85 | + update_option('wpinv_settings', $settings); |
|
| 86 | 86 | |
| 87 | 87 | } |
| 88 | - return apply_filters( 'wpinv_get_settings', $settings ); |
|
| 88 | + return apply_filters('wpinv_get_settings', $settings); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function wpinv_register_settings() { |
| 92 | - if ( false == get_option( 'wpinv_settings' ) ) { |
|
| 93 | - add_option( 'wpinv_settings' ); |
|
| 92 | + if (false == get_option('wpinv_settings')) { |
|
| 93 | + add_option('wpinv_settings'); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $register_settings = wpinv_get_registered_settings(); |
| 97 | 97 | |
| 98 | - foreach ( $register_settings as $tab => $sections ) { |
|
| 99 | - foreach ( $sections as $section => $settings) { |
|
| 98 | + foreach ($register_settings as $tab => $sections) { |
|
| 99 | + foreach ($sections as $section => $settings) { |
|
| 100 | 100 | // Check for backwards compatibility |
| 101 | - $section_tabs = wpinv_get_settings_tab_sections( $tab ); |
|
| 102 | - if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) { |
|
| 101 | + $section_tabs = wpinv_get_settings_tab_sections($tab); |
|
| 102 | + if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) { |
|
| 103 | 103 | $section = 'main'; |
| 104 | 104 | $settings = $sections; |
| 105 | 105 | } |
@@ -111,41 +111,41 @@ discard block |
||
| 111 | 111 | 'wpinv_settings_' . $tab . '_' . $section |
| 112 | 112 | ); |
| 113 | 113 | |
| 114 | - foreach ( $settings as $option ) { |
|
| 114 | + foreach ($settings as $option) { |
|
| 115 | 115 | // For backwards compatibility |
| 116 | - if ( empty( $option['id'] ) ) { |
|
| 116 | + if (empty($option['id'])) { |
|
| 117 | 117 | continue; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $name = isset( $option['name'] ) ? $option['name'] : ''; |
|
| 120 | + $name = isset($option['name']) ? $option['name'] : ''; |
|
| 121 | 121 | |
| 122 | 122 | add_settings_field( |
| 123 | 123 | 'wpinv_settings[' . $option['id'] . ']', |
| 124 | 124 | $name, |
| 125 | - function_exists( 'wpinv_' . $option['type'] . '_callback' ) ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback', |
|
| 125 | + function_exists('wpinv_' . $option['type'] . '_callback') ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback', |
|
| 126 | 126 | 'wpinv_settings_' . $tab . '_' . $section, |
| 127 | 127 | 'wpinv_settings_' . $tab . '_' . $section, |
| 128 | 128 | array( |
| 129 | 129 | 'section' => $section, |
| 130 | - 'id' => isset( $option['id'] ) ? $option['id'] : null, |
|
| 131 | - 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '', |
|
| 132 | - 'name' => isset( $option['name'] ) ? $option['name'] : null, |
|
| 133 | - 'size' => isset( $option['size'] ) ? $option['size'] : null, |
|
| 134 | - 'options' => isset( $option['options'] ) ? $option['options'] : '', |
|
| 135 | - 'selected' => isset( $option['selected'] ) ? $option['selected'] : null, |
|
| 136 | - 'std' => isset( $option['std'] ) ? $option['std'] : '', |
|
| 137 | - 'min' => isset( $option['min'] ) ? $option['min'] : null, |
|
| 138 | - 'max' => isset( $option['max'] ) ? $option['max'] : null, |
|
| 139 | - 'step' => isset( $option['step'] ) ? $option['step'] : null, |
|
| 140 | - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, |
|
| 141 | - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, |
|
| 142 | - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, |
|
| 143 | - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
|
| 144 | - 'onchange' => !empty( $option['onchange'] ) ? $option['onchange'] : '', |
|
| 145 | - 'custom' => !empty( $option['custom'] ) ? $option['custom'] : '', |
|
| 146 | - 'class' => !empty( $option['class'] ) ? $option['class'] : '', |
|
| 147 | - 'cols' => !empty( $option['cols'] ) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50, |
|
| 148 | - 'rows' => !empty( $option['rows'] ) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5, |
|
| 130 | + 'id' => isset($option['id']) ? $option['id'] : null, |
|
| 131 | + 'desc' => !empty($option['desc']) ? $option['desc'] : '', |
|
| 132 | + 'name' => isset($option['name']) ? $option['name'] : null, |
|
| 133 | + 'size' => isset($option['size']) ? $option['size'] : null, |
|
| 134 | + 'options' => isset($option['options']) ? $option['options'] : '', |
|
| 135 | + 'selected' => isset($option['selected']) ? $option['selected'] : null, |
|
| 136 | + 'std' => isset($option['std']) ? $option['std'] : '', |
|
| 137 | + 'min' => isset($option['min']) ? $option['min'] : null, |
|
| 138 | + 'max' => isset($option['max']) ? $option['max'] : null, |
|
| 139 | + 'step' => isset($option['step']) ? $option['step'] : null, |
|
| 140 | + 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, |
|
| 141 | + 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, |
|
| 142 | + 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, |
|
| 143 | + 'faux' => isset($option['faux']) ? $option['faux'] : false, |
|
| 144 | + 'onchange' => !empty($option['onchange']) ? $option['onchange'] : '', |
|
| 145 | + 'custom' => !empty($option['custom']) ? $option['custom'] : '', |
|
| 146 | + 'class' => !empty($option['class']) ? $option['class'] : '', |
|
| 147 | + 'cols' => !empty($option['cols']) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50, |
|
| 148 | + 'rows' => !empty($option['rows']) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5, |
|
| 149 | 149 | ) |
| 150 | 150 | ); |
| 151 | 151 | } |
@@ -153,203 +153,203 @@ discard block |
||
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // Creates our settings in the options table |
| 156 | - register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
|
| 156 | + register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize'); |
|
| 157 | 157 | } |
| 158 | -add_action( 'admin_init', 'wpinv_register_settings' ); |
|
| 158 | +add_action('admin_init', 'wpinv_register_settings'); |
|
| 159 | 159 | |
| 160 | 160 | function wpinv_get_registered_settings() { |
| 161 | - $pages = wpinv_get_pages( true ); |
|
| 161 | + $pages = wpinv_get_pages(true); |
|
| 162 | 162 | |
| 163 | 163 | $currencies = wpinv_get_currencies(); |
| 164 | 164 | |
| 165 | 165 | $currency_code_options = array(); |
| 166 | - foreach ( $currencies as $code => $name ) { |
|
| 167 | - $currency_code_options[ $code ] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol( $code ) . ')'; |
|
| 166 | + foreach ($currencies as $code => $name) { |
|
| 167 | + $currency_code_options[$code] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol($code) . ')'; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | $due_payment_options = array(); |
| 171 | - $due_payment_options[0] = __( 'Now', 'invoicing' ); |
|
| 172 | - for ( $i = 1; $i <= 30; $i++ ) { |
|
| 171 | + $due_payment_options[0] = __('Now', 'invoicing'); |
|
| 172 | + for ($i = 1; $i <= 30; $i++) { |
|
| 173 | 173 | $due_payment_options[$i] = $i; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | $invoice_number_padd_options = array(); |
| 177 | - for ( $i = 0; $i <= 20; $i++ ) { |
|
| 177 | + for ($i = 0; $i <= 20; $i++) { |
|
| 178 | 178 | $invoice_number_padd_options[$i] = $i; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $currency_symbol = wpinv_currency_symbol(); |
| 182 | 182 | |
| 183 | 183 | $last_number = $reset_number = ''; |
| 184 | - if ( $last_invoice_number = get_option( 'wpinv_last_invoice_number' ) ) { |
|
| 185 | - $last_invoice_number = is_numeric( $last_invoice_number ) ? $last_invoice_number : wpinv_clean_invoice_number( $last_invoice_number ); |
|
| 184 | + if ($last_invoice_number = get_option('wpinv_last_invoice_number')) { |
|
| 185 | + $last_invoice_number = is_numeric($last_invoice_number) ? $last_invoice_number : wpinv_clean_invoice_number($last_invoice_number); |
|
| 186 | 186 | |
| 187 | - if ( !empty( $last_invoice_number ) ) { |
|
| 188 | - $last_number = ' ' . wp_sprintf( __( "( Last Invoice's sequential number: <b>%s</b> )", 'invoicing' ), $last_invoice_number ); |
|
| 187 | + if (!empty($last_invoice_number)) { |
|
| 188 | + $last_number = ' ' . wp_sprintf(__("( Last Invoice's sequential number: <b>%s</b> )", 'invoicing'), $last_invoice_number); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | $nonce = wp_create_nonce('reset_invoice_count'); |
| 192 | - $reset_number = '<a href="'.add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)).'" class="btn button">'.__('Force Reset Sequence', 'invoicing' ). '</a>'; |
|
| 192 | + $reset_number = '<a href="' . add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)) . '" class="btn button">' . __('Force Reset Sequence', 'invoicing') . '</a>'; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | $alert_wrapper_start = '<p style="color: #F00">'; |
| 196 | 196 | $alert_wrapper_close = '</p>'; |
| 197 | 197 | $wpinv_settings = array( |
| 198 | - 'general' => apply_filters( 'wpinv_settings_general', |
|
| 198 | + 'general' => apply_filters('wpinv_settings_general', |
|
| 199 | 199 | array( |
| 200 | 200 | 'main' => array( |
| 201 | 201 | 'location_settings' => array( |
| 202 | 202 | 'id' => 'location_settings', |
| 203 | - 'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>', |
|
| 203 | + 'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>', |
|
| 204 | 204 | 'desc' => '', |
| 205 | 205 | 'type' => 'header', |
| 206 | 206 | ), |
| 207 | 207 | 'default_country' => array( |
| 208 | 208 | 'id' => 'default_country', |
| 209 | - 'name' => __( 'Default Country', 'invoicing' ), |
|
| 210 | - 'desc' => __( 'Where does your store operate from?', 'invoicing' ), |
|
| 209 | + 'name' => __('Default Country', 'invoicing'), |
|
| 210 | + 'desc' => __('Where does your store operate from?', 'invoicing'), |
|
| 211 | 211 | 'type' => 'select', |
| 212 | 212 | 'options' => wpinv_get_country_list(), |
| 213 | 213 | 'std' => 'GB', |
| 214 | 214 | 'class' => 'wpi_select2', |
| 215 | - 'placeholder' => __( 'Select a country', 'invoicing' ), |
|
| 215 | + 'placeholder' => __('Select a country', 'invoicing'), |
|
| 216 | 216 | ), |
| 217 | 217 | 'default_state' => array( |
| 218 | 218 | 'id' => 'default_state', |
| 219 | - 'name' => __( 'Default State / Province', 'invoicing' ), |
|
| 220 | - 'desc' => __( 'What state / province does your store operate from?', 'invoicing' ), |
|
| 219 | + 'name' => __('Default State / Province', 'invoicing'), |
|
| 220 | + 'desc' => __('What state / province does your store operate from?', 'invoicing'), |
|
| 221 | 221 | 'type' => 'country_states', |
| 222 | 222 | 'class' => 'wpi_select2', |
| 223 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
| 223 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
| 224 | 224 | ), |
| 225 | 225 | 'store_name' => array( |
| 226 | 226 | 'id' => 'store_name', |
| 227 | - 'name' => __( 'Store Name', 'invoicing' ), |
|
| 228 | - 'desc' => __( 'Store name to print on invoices.', 'invoicing' ), |
|
| 227 | + 'name' => __('Store Name', 'invoicing'), |
|
| 228 | + 'desc' => __('Store name to print on invoices.', 'invoicing'), |
|
| 229 | 229 | 'std' => get_option('blogname'), |
| 230 | 230 | 'type' => 'text', |
| 231 | 231 | ), |
| 232 | 232 | 'logo' => array( |
| 233 | 233 | 'id' => 'logo', |
| 234 | - 'name' => __( 'Logo URL', 'invoicing' ), |
|
| 235 | - 'desc' => __( 'Store logo to print on invoices.', 'invoicing' ), |
|
| 234 | + 'name' => __('Logo URL', 'invoicing'), |
|
| 235 | + 'desc' => __('Store logo to print on invoices.', 'invoicing'), |
|
| 236 | 236 | 'type' => 'text', |
| 237 | 237 | ), |
| 238 | 238 | 'store_address' => array( |
| 239 | 239 | 'id' => 'store_address', |
| 240 | - 'name' => __( 'Store Address', 'invoicing' ), |
|
| 241 | - 'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ), |
|
| 240 | + 'name' => __('Store Address', 'invoicing'), |
|
| 241 | + 'desc' => __('Enter the store address to display on invoice', 'invoicing'), |
|
| 242 | 242 | 'type' => 'textarea', |
| 243 | 243 | ), |
| 244 | 244 | 'page_settings' => array( |
| 245 | 245 | 'id' => 'page_settings', |
| 246 | - 'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>', |
|
| 246 | + 'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>', |
|
| 247 | 247 | 'desc' => '', |
| 248 | 248 | 'type' => 'header', |
| 249 | 249 | ), |
| 250 | 250 | 'checkout_page' => array( |
| 251 | 251 | 'id' => 'checkout_page', |
| 252 | - 'name' => __( 'Checkout Page', 'invoicing' ), |
|
| 253 | - 'desc' => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ), |
|
| 252 | + 'name' => __('Checkout Page', 'invoicing'), |
|
| 253 | + 'desc' => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'), |
|
| 254 | 254 | 'type' => 'select', |
| 255 | 255 | 'options' => $pages, |
| 256 | 256 | 'class' => 'wpi_select2', |
| 257 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
| 257 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
| 258 | 258 | ), |
| 259 | 259 | 'tandc_page' => array( |
| 260 | 260 | 'id' => 'tandc_page', |
| 261 | - 'name' => __( 'Terms & Conditions', 'invoicing' ), |
|
| 262 | - 'desc' => __( 'If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing' ), |
|
| 261 | + 'name' => __('Terms & Conditions', 'invoicing'), |
|
| 262 | + 'desc' => __('If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing'), |
|
| 263 | 263 | 'type' => 'select', |
| 264 | - 'options' => wpinv_get_pages( true, __( 'Select a page', 'invoicing' )), |
|
| 264 | + 'options' => wpinv_get_pages(true, __('Select a page', 'invoicing')), |
|
| 265 | 265 | 'class' => 'wpi_select2', |
| 266 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
| 266 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
| 267 | 267 | ), |
| 268 | 268 | 'success_page' => array( |
| 269 | 269 | 'id' => 'success_page', |
| 270 | - 'name' => __( 'Success Page', 'invoicing' ), |
|
| 271 | - 'desc' => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ), |
|
| 270 | + 'name' => __('Success Page', 'invoicing'), |
|
| 271 | + 'desc' => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'), |
|
| 272 | 272 | 'type' => 'select', |
| 273 | 273 | 'options' => $pages, |
| 274 | 274 | 'class' => 'wpi_select2', |
| 275 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
| 275 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
| 276 | 276 | ), |
| 277 | 277 | 'failure_page' => array( |
| 278 | 278 | 'id' => 'failure_page', |
| 279 | - 'name' => __( 'Failed Transaction Page', 'invoicing' ), |
|
| 280 | - 'desc' => __( 'This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing' ), |
|
| 279 | + 'name' => __('Failed Transaction Page', 'invoicing'), |
|
| 280 | + 'desc' => __('This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing'), |
|
| 281 | 281 | 'type' => 'select', |
| 282 | 282 | 'options' => $pages, |
| 283 | 283 | 'class' => 'wpi_select2', |
| 284 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
| 284 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
| 285 | 285 | ), |
| 286 | 286 | 'invoice_history_page' => array( |
| 287 | 287 | 'id' => 'invoice_history_page', |
| 288 | - 'name' => __( 'Invoice History Page', 'invoicing' ), |
|
| 289 | - 'desc' => __( 'This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing' ), |
|
| 288 | + 'name' => __('Invoice History Page', 'invoicing'), |
|
| 289 | + 'desc' => __('This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing'), |
|
| 290 | 290 | 'type' => 'select', |
| 291 | 291 | 'options' => $pages, |
| 292 | 292 | 'class' => 'wpi_select2', |
| 293 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
| 293 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
| 294 | 294 | ), |
| 295 | 295 | 'invoice_subscription_page' => array( |
| 296 | 296 | 'id' => 'invoice_subscription_page', |
| 297 | - 'name' => __( 'Invoice Subscriptions Page', 'invoicing' ), |
|
| 298 | - 'desc' => __( 'This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing' ), |
|
| 297 | + 'name' => __('Invoice Subscriptions Page', 'invoicing'), |
|
| 298 | + 'desc' => __('This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing'), |
|
| 299 | 299 | 'type' => 'select', |
| 300 | 300 | 'options' => $pages, |
| 301 | 301 | 'class' => 'wpi_select2', |
| 302 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
| 302 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
| 303 | 303 | ), |
| 304 | 304 | ), |
| 305 | 305 | 'currency_section' => array( |
| 306 | 306 | 'currency_settings' => array( |
| 307 | 307 | 'id' => 'currency_settings', |
| 308 | - 'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>', |
|
| 308 | + 'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>', |
|
| 309 | 309 | 'desc' => '', |
| 310 | 310 | 'type' => 'header', |
| 311 | 311 | ), |
| 312 | 312 | 'currency' => array( |
| 313 | 313 | 'id' => 'currency', |
| 314 | - 'name' => __( 'Currency', 'invoicing' ), |
|
| 315 | - 'desc' => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ), |
|
| 314 | + 'name' => __('Currency', 'invoicing'), |
|
| 315 | + 'desc' => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'), |
|
| 316 | 316 | 'type' => 'select', |
| 317 | 317 | 'class' => 'wpi_select2', |
| 318 | 318 | 'options' => $currency_code_options, |
| 319 | 319 | ), |
| 320 | 320 | 'currency_position' => array( |
| 321 | 321 | 'id' => 'currency_position', |
| 322 | - 'name' => __( 'Currency Position', 'invoicing' ), |
|
| 323 | - 'desc' => __( 'Choose the location of the currency sign.', 'invoicing' ), |
|
| 322 | + 'name' => __('Currency Position', 'invoicing'), |
|
| 323 | + 'desc' => __('Choose the location of the currency sign.', 'invoicing'), |
|
| 324 | 324 | 'type' => 'select', |
| 325 | 325 | 'class' => 'wpi_select2', |
| 326 | 326 | 'options' => array( |
| 327 | - 'left' => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')', |
|
| 328 | - 'right' => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')', |
|
| 329 | - 'left_space' => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')', |
|
| 330 | - 'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')' |
|
| 327 | + 'left' => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')', |
|
| 328 | + 'right' => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')', |
|
| 329 | + 'left_space' => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')', |
|
| 330 | + 'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')' |
|
| 331 | 331 | ) |
| 332 | 332 | ), |
| 333 | 333 | 'thousands_separator' => array( |
| 334 | 334 | 'id' => 'thousands_separator', |
| 335 | - 'name' => __( 'Thousands Separator', 'invoicing' ), |
|
| 336 | - 'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ), |
|
| 335 | + 'name' => __('Thousands Separator', 'invoicing'), |
|
| 336 | + 'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'), |
|
| 337 | 337 | 'type' => 'text', |
| 338 | 338 | 'size' => 'small', |
| 339 | 339 | 'std' => ',', |
| 340 | 340 | ), |
| 341 | 341 | 'decimal_separator' => array( |
| 342 | 342 | 'id' => 'decimal_separator', |
| 343 | - 'name' => __( 'Decimal Separator', 'invoicing' ), |
|
| 344 | - 'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ), |
|
| 343 | + 'name' => __('Decimal Separator', 'invoicing'), |
|
| 344 | + 'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'), |
|
| 345 | 345 | 'type' => 'text', |
| 346 | 346 | 'size' => 'small', |
| 347 | 347 | 'std' => '.', |
| 348 | 348 | ), |
| 349 | 349 | 'decimals' => array( |
| 350 | 350 | 'id' => 'decimals', |
| 351 | - 'name' => __( 'Number of Decimals', 'invoicing' ), |
|
| 352 | - 'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ), |
|
| 351 | + 'name' => __('Number of Decimals', 'invoicing'), |
|
| 352 | + 'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'), |
|
| 353 | 353 | 'type' => 'number', |
| 354 | 354 | 'size' => 'small', |
| 355 | 355 | 'std' => '2', |
@@ -361,29 +361,29 @@ discard block |
||
| 361 | 361 | 'labels' => array( |
| 362 | 362 | 'labels' => array( |
| 363 | 363 | 'id' => 'labels_settings', |
| 364 | - 'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>', |
|
| 364 | + 'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>', |
|
| 365 | 365 | 'desc' => '', |
| 366 | 366 | 'type' => 'header', |
| 367 | 367 | ), |
| 368 | 368 | 'vat_name' => array( |
| 369 | 369 | 'id' => 'vat_name', |
| 370 | - 'name' => __( 'VAT Name', 'invoicing' ), |
|
| 371 | - 'desc' => __( 'Enter the VAT name', 'invoicing' ), |
|
| 370 | + 'name' => __('VAT Name', 'invoicing'), |
|
| 371 | + 'desc' => __('Enter the VAT name', 'invoicing'), |
|
| 372 | 372 | 'type' => 'text', |
| 373 | 373 | 'size' => 'regular', |
| 374 | 374 | 'std' => 'VAT' |
| 375 | 375 | ), |
| 376 | 376 | 'vat_invoice_notice_label' => array( |
| 377 | 377 | 'id' => 'vat_invoice_notice_label', |
| 378 | - 'name' => __( 'Invoice Notice Label', 'invoicing' ), |
|
| 379 | - 'desc' => __( 'Use this to add an invoice notice section (label) to your invoices', 'invoicing' ), |
|
| 378 | + 'name' => __('Invoice Notice Label', 'invoicing'), |
|
| 379 | + 'desc' => __('Use this to add an invoice notice section (label) to your invoices', 'invoicing'), |
|
| 380 | 380 | 'type' => 'text', |
| 381 | 381 | 'size' => 'regular', |
| 382 | 382 | ), |
| 383 | 383 | 'vat_invoice_notice' => array( |
| 384 | 384 | 'id' => 'vat_invoice_notice', |
| 385 | - 'name' => __( 'Invoice notice', 'invoicing' ), |
|
| 386 | - 'desc' => __( 'Use this to add an invoice notice section (description) to your invoices', 'invoicing' ), |
|
| 385 | + 'name' => __('Invoice notice', 'invoicing'), |
|
| 386 | + 'desc' => __('Use this to add an invoice notice section (description) to your invoices', 'invoicing'), |
|
| 387 | 387 | 'type' => 'text', |
| 388 | 388 | 'size' => 'regular', |
| 389 | 389 | ) |
@@ -395,22 +395,22 @@ discard block |
||
| 395 | 395 | 'main' => array( |
| 396 | 396 | 'gateway_settings' => array( |
| 397 | 397 | 'id' => 'api_header', |
| 398 | - 'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>', |
|
| 398 | + 'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>', |
|
| 399 | 399 | 'desc' => '', |
| 400 | 400 | 'type' => 'header', |
| 401 | 401 | ), |
| 402 | 402 | 'gateways' => array( |
| 403 | 403 | 'id' => 'gateways', |
| 404 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
| 405 | - 'desc' => __( 'Choose the payment gateways you want to enable.', 'invoicing' ), |
|
| 404 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
| 405 | + 'desc' => __('Choose the payment gateways you want to enable.', 'invoicing'), |
|
| 406 | 406 | 'type' => 'gateways', |
| 407 | 407 | 'std' => array('manual'=>1), |
| 408 | 408 | 'options' => wpinv_get_payment_gateways(), |
| 409 | 409 | ), |
| 410 | 410 | 'default_gateway' => array( |
| 411 | 411 | 'id' => 'default_gateway', |
| 412 | - 'name' => __( 'Default Gateway', 'invoicing' ), |
|
| 413 | - 'desc' => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ), |
|
| 412 | + 'name' => __('Default Gateway', 'invoicing'), |
|
| 413 | + 'desc' => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'), |
|
| 414 | 414 | 'type' => 'gateway_select', |
| 415 | 415 | 'std' => 'manual', |
| 416 | 416 | 'class' => 'wpi_select2', |
@@ -425,19 +425,19 @@ discard block |
||
| 425 | 425 | 'main' => array( |
| 426 | 426 | 'tax_settings' => array( |
| 427 | 427 | 'id' => 'tax_settings', |
| 428 | - 'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>', |
|
| 428 | + 'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>', |
|
| 429 | 429 | 'type' => 'header', |
| 430 | 430 | ), |
| 431 | 431 | 'enable_taxes' => array( |
| 432 | 432 | 'id' => 'enable_taxes', |
| 433 | - 'name' => __( 'Enable Taxes', 'invoicing' ), |
|
| 434 | - 'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ), |
|
| 433 | + 'name' => __('Enable Taxes', 'invoicing'), |
|
| 434 | + 'desc' => __('Check this to enable taxes on invoices.', 'invoicing'), |
|
| 435 | 435 | 'type' => 'checkbox', |
| 436 | 436 | ), |
| 437 | 437 | 'tax_rate' => array( |
| 438 | 438 | 'id' => 'tax_rate', |
| 439 | - 'name' => __( 'Fallback Tax Rate', 'invoicing' ), |
|
| 440 | - 'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ), |
|
| 439 | + 'name' => __('Fallback Tax Rate', 'invoicing'), |
|
| 440 | + 'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'), |
|
| 441 | 441 | 'type' => 'number', |
| 442 | 442 | 'size' => 'small', |
| 443 | 443 | 'min' => '0', |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | 'rates' => array( |
| 450 | 450 | 'tax_rates' => array( |
| 451 | 451 | 'id' => 'tax_rates', |
| 452 | - 'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>', |
|
| 453 | - 'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ), |
|
| 452 | + 'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>', |
|
| 453 | + 'desc' => __('Enter tax rates for specific regions.', 'invoicing'), |
|
| 454 | 454 | 'type' => 'tax_rates', |
| 455 | 455 | ), |
| 456 | 456 | ) |
@@ -462,61 +462,61 @@ discard block |
||
| 462 | 462 | 'main' => array( |
| 463 | 463 | 'email_settings_header' => array( |
| 464 | 464 | 'id' => 'email_settings_header', |
| 465 | - 'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>', |
|
| 465 | + 'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>', |
|
| 466 | 466 | 'type' => 'header', |
| 467 | 467 | ), |
| 468 | 468 | 'email_from_name' => array( |
| 469 | 469 | 'id' => 'email_from_name', |
| 470 | - 'name' => __( 'From Name', 'invoicing' ), |
|
| 471 | - 'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ), |
|
| 472 | - 'std' => esc_attr( get_bloginfo( 'name', 'display' ) ), |
|
| 470 | + 'name' => __('From Name', 'invoicing'), |
|
| 471 | + 'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'), |
|
| 472 | + 'std' => esc_attr(get_bloginfo('name', 'display')), |
|
| 473 | 473 | 'type' => 'text', |
| 474 | 474 | ), |
| 475 | 475 | 'email_from' => array( |
| 476 | 476 | 'id' => 'email_from', |
| 477 | - 'name' => __( 'From Email', 'invoicing' ), |
|
| 478 | - 'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close), |
|
| 479 | - 'std' => get_option( 'admin_email' ), |
|
| 477 | + 'name' => __('From Email', 'invoicing'), |
|
| 478 | + 'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close), |
|
| 479 | + 'std' => get_option('admin_email'), |
|
| 480 | 480 | 'type' => 'text', |
| 481 | 481 | ), |
| 482 | 482 | 'overdue_settings_header' => array( |
| 483 | 483 | 'id' => 'overdue_settings_header', |
| 484 | - 'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>', |
|
| 484 | + 'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>', |
|
| 485 | 485 | 'type' => 'header', |
| 486 | 486 | ), |
| 487 | 487 | 'overdue_active' => array( |
| 488 | 488 | 'id' => 'overdue_active', |
| 489 | - 'name' => __( 'Enable Due Date', 'invoicing' ), |
|
| 490 | - 'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ), |
|
| 489 | + 'name' => __('Enable Due Date', 'invoicing'), |
|
| 490 | + 'desc' => __('Check this to enable due date option for invoices.', 'invoicing'), |
|
| 491 | 491 | 'type' => 'checkbox', |
| 492 | 492 | 'std' => false, |
| 493 | 493 | ), |
| 494 | 494 | 'overdue_days' => array( |
| 495 | 495 | 'id' => 'overdue_days', |
| 496 | - 'name' => __( 'Default Due Date', 'invoicing' ), |
|
| 497 | - 'desc' => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ), |
|
| 496 | + 'name' => __('Default Due Date', 'invoicing'), |
|
| 497 | + 'desc' => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'), |
|
| 498 | 498 | 'type' => 'select', |
| 499 | 499 | 'options' => $due_payment_options, |
| 500 | 500 | 'std' => 0, |
| 501 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
| 501 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
| 502 | 502 | ), |
| 503 | 503 | 'email_template_header' => array( |
| 504 | 504 | 'id' => 'email_template_header', |
| 505 | - 'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>', |
|
| 505 | + 'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>', |
|
| 506 | 506 | 'type' => 'header', |
| 507 | 507 | ), |
| 508 | 508 | 'email_header_image' => array( |
| 509 | 509 | 'id' => 'email_header_image', |
| 510 | - 'name' => __( 'Header Image', 'invoicing' ), |
|
| 511 | - 'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ), |
|
| 510 | + 'name' => __('Header Image', 'invoicing'), |
|
| 511 | + 'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'), |
|
| 512 | 512 | 'std' => '', |
| 513 | 513 | 'type' => 'text', |
| 514 | 514 | ), |
| 515 | 515 | 'email_footer_text' => array( |
| 516 | 516 | 'id' => 'email_footer_text', |
| 517 | - 'name' => __( 'Footer Text', 'invoicing' ), |
|
| 518 | - 'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ), |
|
| 519 | - 'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ), |
|
| 517 | + 'name' => __('Footer Text', 'invoicing'), |
|
| 518 | + 'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'), |
|
| 519 | + 'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'), |
|
| 520 | 520 | 'type' => 'textarea', |
| 521 | 521 | 'class' => 'regular-text', |
| 522 | 522 | 'rows' => 2, |
@@ -524,29 +524,29 @@ discard block |
||
| 524 | 524 | ), |
| 525 | 525 | 'email_base_color' => array( |
| 526 | 526 | 'id' => 'email_base_color', |
| 527 | - 'name' => __( 'Base Color', 'invoicing' ), |
|
| 528 | - 'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ), |
|
| 527 | + 'name' => __('Base Color', 'invoicing'), |
|
| 528 | + 'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'), |
|
| 529 | 529 | 'std' => '#557da2', |
| 530 | 530 | 'type' => 'color', |
| 531 | 531 | ), |
| 532 | 532 | 'email_background_color' => array( |
| 533 | 533 | 'id' => 'email_background_color', |
| 534 | - 'name' => __( 'Background Color', 'invoicing' ), |
|
| 535 | - 'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ), |
|
| 534 | + 'name' => __('Background Color', 'invoicing'), |
|
| 535 | + 'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'), |
|
| 536 | 536 | 'std' => '#f5f5f5', |
| 537 | 537 | 'type' => 'color', |
| 538 | 538 | ), |
| 539 | 539 | 'email_body_background_color' => array( |
| 540 | 540 | 'id' => 'email_body_background_color', |
| 541 | - 'name' => __( 'Body Background Color', 'invoicing' ), |
|
| 542 | - 'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ), |
|
| 541 | + 'name' => __('Body Background Color', 'invoicing'), |
|
| 542 | + 'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'), |
|
| 543 | 543 | 'std' => '#fdfdfd', |
| 544 | 544 | 'type' => 'color', |
| 545 | 545 | ), |
| 546 | 546 | 'email_text_color' => array( |
| 547 | 547 | 'id' => 'email_text_color', |
| 548 | - 'name' => __( 'Body Text Color', 'invoicing' ), |
|
| 549 | - 'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ), |
|
| 548 | + 'name' => __('Body Text Color', 'invoicing'), |
|
| 549 | + 'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'), |
|
| 550 | 550 | 'std' => '#505050', |
| 551 | 551 | 'type' => 'color', |
| 552 | 552 | ), |
@@ -565,26 +565,26 @@ discard block |
||
| 565 | 565 | 'main' => array( |
| 566 | 566 | 'invoicing_privacy_policy_settings' => array( |
| 567 | 567 | 'id' => 'invoicing_privacy_policy_settings', |
| 568 | - 'name' => '<h3>' . __( 'Privacy Policy', 'invoicing' ) . '</h3>', |
|
| 568 | + 'name' => '<h3>' . __('Privacy Policy', 'invoicing') . '</h3>', |
|
| 569 | 569 | 'type' => 'header', |
| 570 | 570 | ), |
| 571 | 571 | 'privacy_page' => array( |
| 572 | 572 | 'id' => 'privacy_page', |
| 573 | - 'name' => __( 'Privacy Page', 'invoicing' ), |
|
| 574 | - 'desc' => __( 'If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing' ), |
|
| 573 | + 'name' => __('Privacy Page', 'invoicing'), |
|
| 574 | + 'desc' => __('If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing'), |
|
| 575 | 575 | 'type' => 'select', |
| 576 | - 'options' => wpinv_get_pages( true, __( 'Select a page', 'invoicing' )), |
|
| 576 | + 'options' => wpinv_get_pages(true, __('Select a page', 'invoicing')), |
|
| 577 | 577 | 'class' => 'wpi_select2', |
| 578 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
| 578 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
| 579 | 579 | ), |
| 580 | 580 | 'invoicing_privacy_checkout_message' => array( |
| 581 | 581 | 'id' => 'invoicing_privacy_checkout_message', |
| 582 | - 'name' => __( 'Checkout privacy policy', 'invoicing' ), |
|
| 583 | - 'desc' => __( 'Optionally add privacy policy message which will display on checkout page.', 'invoicing' ), |
|
| 582 | + 'name' => __('Checkout privacy policy', 'invoicing'), |
|
| 583 | + 'desc' => __('Optionally add privacy policy message which will display on checkout page.', 'invoicing'), |
|
| 584 | 584 | 'type' => 'textarea', |
| 585 | 585 | 'class'=> 'regular-text', |
| 586 | 586 | 'rows' => 4, |
| 587 | - 'std' => sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ), |
|
| 587 | + 'std' => sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'), |
|
| 588 | 588 | ), |
| 589 | 589 | ), |
| 590 | 590 | ) |
@@ -595,19 +595,19 @@ discard block |
||
| 595 | 595 | 'main' => array( |
| 596 | 596 | 'invoice_number_format_settings' => array( |
| 597 | 597 | 'id' => 'invoice_number_format_settings', |
| 598 | - 'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>', |
|
| 598 | + 'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>', |
|
| 599 | 599 | 'type' => 'header', |
| 600 | 600 | ), |
| 601 | 601 | 'sequential_invoice_number' => array( |
| 602 | 602 | 'id' => 'sequential_invoice_number', |
| 603 | - 'name' => __( 'Sequential Invoice Numbers', 'invoicing' ), |
|
| 604 | - 'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing' ) . $reset_number, |
|
| 603 | + 'name' => __('Sequential Invoice Numbers', 'invoicing'), |
|
| 604 | + 'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing') . $reset_number, |
|
| 605 | 605 | 'type' => 'checkbox', |
| 606 | 606 | ), |
| 607 | 607 | 'invoice_sequence_start' => array( |
| 608 | 608 | 'id' => 'invoice_sequence_start', |
| 609 | - 'name' => __( 'Sequential Starting Number', 'invoicing' ), |
|
| 610 | - 'desc' => __( 'The number at which the invoice number sequence should begin.', 'invoicing' ) . $last_number, |
|
| 609 | + 'name' => __('Sequential Starting Number', 'invoicing'), |
|
| 610 | + 'desc' => __('The number at which the invoice number sequence should begin.', 'invoicing') . $last_number, |
|
| 611 | 611 | 'type' => 'number', |
| 612 | 612 | 'size' => 'small', |
| 613 | 613 | 'std' => '1', |
@@ -615,8 +615,8 @@ discard block |
||
| 615 | 615 | ), |
| 616 | 616 | 'invoice_number_padd' => array( |
| 617 | 617 | 'id' => 'invoice_number_padd', |
| 618 | - 'name' => __( 'Minimum Digits', 'invoicing' ), |
|
| 619 | - 'desc' => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ), |
|
| 618 | + 'name' => __('Minimum Digits', 'invoicing'), |
|
| 619 | + 'desc' => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'), |
|
| 620 | 620 | 'type' => 'select', |
| 621 | 621 | 'options' => $invoice_number_padd_options, |
| 622 | 622 | 'std' => 5, |
@@ -624,8 +624,8 @@ discard block |
||
| 624 | 624 | ), |
| 625 | 625 | 'invoice_number_prefix' => array( |
| 626 | 626 | 'id' => 'invoice_number_prefix', |
| 627 | - 'name' => __( 'Invoice Number Prefix', 'invoicing' ), |
|
| 628 | - 'desc' => __( 'Prefix for all invoice numbers. Ex: WPINV-', 'invoicing' ), |
|
| 627 | + 'name' => __('Invoice Number Prefix', 'invoicing'), |
|
| 628 | + 'desc' => __('Prefix for all invoice numbers. Ex: WPINV-', 'invoicing'), |
|
| 629 | 629 | 'type' => 'text', |
| 630 | 630 | 'size' => 'regular', |
| 631 | 631 | 'std' => 'WPINV-', |
@@ -633,32 +633,32 @@ discard block |
||
| 633 | 633 | ), |
| 634 | 634 | 'invoice_number_postfix' => array( |
| 635 | 635 | 'id' => 'invoice_number_postfix', |
| 636 | - 'name' => __( 'Invoice Number Postfix', 'invoicing' ), |
|
| 637 | - 'desc' => __( 'Postfix for all invoice numbers.', 'invoicing' ), |
|
| 636 | + 'name' => __('Invoice Number Postfix', 'invoicing'), |
|
| 637 | + 'desc' => __('Postfix for all invoice numbers.', 'invoicing'), |
|
| 638 | 638 | 'type' => 'text', |
| 639 | 639 | 'size' => 'regular', |
| 640 | 640 | 'std' => '' |
| 641 | 641 | ), |
| 642 | 642 | 'checkout_settings' => array( |
| 643 | 643 | 'id' => 'checkout_settings', |
| 644 | - 'name' => '<h3>' . __( 'Checkout Settings', 'invoicing' ) . '</h3>', |
|
| 644 | + 'name' => '<h3>' . __('Checkout Settings', 'invoicing') . '</h3>', |
|
| 645 | 645 | 'type' => 'header', |
| 646 | 646 | ), |
| 647 | 647 | 'login_to_checkout' => array( |
| 648 | 648 | 'id' => 'login_to_checkout', |
| 649 | - 'name' => __( 'Require Login To Checkout', 'invoicing' ), |
|
| 650 | - 'desc' => __( 'If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing' ), |
|
| 649 | + 'name' => __('Require Login To Checkout', 'invoicing'), |
|
| 650 | + 'desc' => __('If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing'), |
|
| 651 | 651 | 'type' => 'checkbox', |
| 652 | 652 | ), |
| 653 | 653 | 'uninstall_settings' => array( |
| 654 | 654 | 'id' => 'uninstall_settings', |
| 655 | - 'name' => '<h3>' . __( 'Uninstall Settings', 'invoicing' ) . '</h3>', |
|
| 655 | + 'name' => '<h3>' . __('Uninstall Settings', 'invoicing') . '</h3>', |
|
| 656 | 656 | 'type' => 'header', |
| 657 | 657 | ), |
| 658 | 658 | 'remove_data_on_unistall' => array( |
| 659 | 659 | 'id' => 'remove_data_on_unistall', |
| 660 | - 'name' => __( 'Remove Data on Uninstall?', 'invoicing' ), |
|
| 661 | - 'desc' => __( 'Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing' ), |
|
| 660 | + 'name' => __('Remove Data on Uninstall?', 'invoicing'), |
|
| 661 | + 'desc' => __('Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing'), |
|
| 662 | 662 | 'type' => 'checkbox', |
| 663 | 663 | 'std' => '' |
| 664 | 664 | ), |
@@ -666,80 +666,80 @@ discard block |
||
| 666 | 666 | 'fields' => array( |
| 667 | 667 | 'fields_settings' => array( |
| 668 | 668 | 'id' => 'fields_settings', |
| 669 | - 'name' => '<h3>' . __( 'Address Fields', 'invoicing' ) . '</h3>', |
|
| 670 | - 'desc' => __( 'Tick fields which are mandatory in invoice address fields.', 'invoicing' ), |
|
| 669 | + 'name' => '<h3>' . __('Address Fields', 'invoicing') . '</h3>', |
|
| 670 | + 'desc' => __('Tick fields which are mandatory in invoice address fields.', 'invoicing'), |
|
| 671 | 671 | 'type' => 'header', |
| 672 | 672 | ), |
| 673 | 673 | 'fname_mandatory' => array( |
| 674 | 674 | 'id' => 'fname_mandatory', |
| 675 | - 'name' => __( 'First Name', 'invoicing' ), |
|
| 675 | + 'name' => __('First Name', 'invoicing'), |
|
| 676 | 676 | 'type' => 'checkbox', |
| 677 | 677 | 'std' => true, |
| 678 | 678 | ), |
| 679 | 679 | 'lname_mandatory' => array( |
| 680 | 680 | 'id' => 'lname_mandatory', |
| 681 | - 'name' => __( 'Last Name', 'invoicing' ), |
|
| 681 | + 'name' => __('Last Name', 'invoicing'), |
|
| 682 | 682 | 'type' => 'checkbox', |
| 683 | 683 | 'std' => true, |
| 684 | 684 | ), |
| 685 | 685 | 'address_mandatory' => array( |
| 686 | 686 | 'id' => 'address_mandatory', |
| 687 | - 'name' => __( 'Address', 'invoicing' ), |
|
| 687 | + 'name' => __('Address', 'invoicing'), |
|
| 688 | 688 | 'type' => 'checkbox', |
| 689 | 689 | 'std' => true, |
| 690 | 690 | ), |
| 691 | 691 | 'city_mandatory' => array( |
| 692 | 692 | 'id' => 'city_mandatory', |
| 693 | - 'name' => __( 'City', 'invoicing' ), |
|
| 693 | + 'name' => __('City', 'invoicing'), |
|
| 694 | 694 | 'type' => 'checkbox', |
| 695 | 695 | 'std' => true, |
| 696 | 696 | ), |
| 697 | 697 | 'country_mandatory' => array( |
| 698 | 698 | 'id' => 'country_mandatory', |
| 699 | - 'name' => __( 'Country', 'invoicing' ), |
|
| 699 | + 'name' => __('Country', 'invoicing'), |
|
| 700 | 700 | 'type' => 'checkbox', |
| 701 | 701 | 'std' => true, |
| 702 | 702 | ), |
| 703 | 703 | 'state_mandatory' => array( |
| 704 | 704 | 'id' => 'state_mandatory', |
| 705 | - 'name' => __( 'State / Province', 'invoicing' ), |
|
| 705 | + 'name' => __('State / Province', 'invoicing'), |
|
| 706 | 706 | 'type' => 'checkbox', |
| 707 | 707 | 'std' => true, |
| 708 | 708 | ), |
| 709 | 709 | 'zip_mandatory' => array( |
| 710 | 710 | 'id' => 'zip_mandatory', |
| 711 | - 'name' => __( 'ZIP / Postcode', 'invoicing' ), |
|
| 711 | + 'name' => __('ZIP / Postcode', 'invoicing'), |
|
| 712 | 712 | 'type' => 'checkbox', |
| 713 | 713 | 'std' => true, |
| 714 | 714 | ), |
| 715 | 715 | 'phone_mandatory' => array( |
| 716 | 716 | 'id' => 'phone_mandatory', |
| 717 | - 'name' => __( 'Phone Number', 'invoicing' ), |
|
| 717 | + 'name' => __('Phone Number', 'invoicing'), |
|
| 718 | 718 | 'type' => 'checkbox', |
| 719 | 719 | 'std' => true, |
| 720 | 720 | ), |
| 721 | 721 | 'force_show_company' => array( |
| 722 | 722 | 'id' => 'force_show_company', |
| 723 | - 'name' => __( 'Force show company name at checkout.', 'invoicing' ), |
|
| 723 | + 'name' => __('Force show company name at checkout.', 'invoicing'), |
|
| 724 | 724 | 'type' => 'checkbox', |
| 725 | 725 | 'std' => false, |
| 726 | 726 | ), |
| 727 | 727 | 'address_autofill_settings' => array( |
| 728 | 728 | 'id' => 'address_autofill_settings', |
| 729 | - 'name' => '<h3>' . __( 'Google Address Auto Complete', 'invoicing' ) . '</h3>', |
|
| 729 | + 'name' => '<h3>' . __('Google Address Auto Complete', 'invoicing') . '</h3>', |
|
| 730 | 730 | 'type' => 'header', |
| 731 | 731 | ), |
| 732 | 732 | 'address_autofill_active' => array( |
| 733 | 733 | 'id' => 'address_autofill_active', |
| 734 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 735 | - 'desc' => __( 'Enable google address auto complete', 'invoicing' ), |
|
| 734 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 735 | + 'desc' => __('Enable google address auto complete', 'invoicing'), |
|
| 736 | 736 | 'type' => 'checkbox', |
| 737 | 737 | 'std' => 0 |
| 738 | 738 | ), |
| 739 | 739 | 'address_autofill_api' => array( |
| 740 | 740 | 'id' => 'address_autofill_api', |
| 741 | - 'name' => __( 'Google Place API Key', 'invoicing' ), |
|
| 742 | - 'desc' => wp_sprintf(__( 'Enter google place API key. For more information go to google place API %sdocumenation%s', 'invoicing' ), '<a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete" target="_blank">', '</a>' ), |
|
| 741 | + 'name' => __('Google Place API Key', 'invoicing'), |
|
| 742 | + 'desc' => wp_sprintf(__('Enter google place API key. For more information go to google place API %sdocumenation%s', 'invoicing'), '<a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete" target="_blank">', '</a>'), |
|
| 743 | 743 | 'type' => 'text', |
| 744 | 744 | 'size' => 'regular', |
| 745 | 745 | 'std' => '' |
@@ -748,13 +748,13 @@ discard block |
||
| 748 | 748 | 'custom-css' => array( |
| 749 | 749 | 'css_settings' => array( |
| 750 | 750 | 'id' => 'css_settings', |
| 751 | - 'name' => '<h3>' . __( 'Custom CSS', 'invoicing' ) . '</h3>', |
|
| 751 | + 'name' => '<h3>' . __('Custom CSS', 'invoicing') . '</h3>', |
|
| 752 | 752 | 'type' => 'header', |
| 753 | 753 | ), |
| 754 | 754 | 'template_custom_css' => array( |
| 755 | 755 | 'id' => 'template_custom_css', |
| 756 | - 'name' => __( 'Invoice Template CSS', 'invoicing' ), |
|
| 757 | - 'desc' => __( 'Add CSS to modify appearance of the print invoice page.', 'invoicing' ), |
|
| 756 | + 'name' => __('Invoice Template CSS', 'invoicing'), |
|
| 757 | + 'desc' => __('Add CSS to modify appearance of the print invoice page.', 'invoicing'), |
|
| 758 | 758 | 'type' => 'textarea', |
| 759 | 759 | 'class'=> 'regular-text', |
| 760 | 760 | 'rows' => 10, |
@@ -768,8 +768,8 @@ discard block |
||
| 768 | 768 | 'main' => array( |
| 769 | 769 | 'tool_settings' => array( |
| 770 | 770 | 'id' => 'tool_settings', |
| 771 | - 'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>', |
|
| 772 | - 'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ), |
|
| 771 | + 'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>', |
|
| 772 | + 'desc' => __('Invoicing diagnostic tools', 'invoicing'), |
|
| 773 | 773 | 'type' => 'tools', |
| 774 | 774 | ), |
| 775 | 775 | ), |
@@ -777,136 +777,136 @@ discard block |
||
| 777 | 777 | ) |
| 778 | 778 | ); |
| 779 | 779 | |
| 780 | - return apply_filters( 'wpinv_registered_settings', $wpinv_settings ); |
|
| 780 | + return apply_filters('wpinv_registered_settings', $wpinv_settings); |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | -function wpinv_settings_sanitize( $input = array() ) { |
|
| 783 | +function wpinv_settings_sanitize($input = array()) { |
|
| 784 | 784 | global $wpinv_options; |
| 785 | 785 | |
| 786 | - if ( empty( $_POST['_wp_http_referer'] ) ) { |
|
| 786 | + if (empty($_POST['_wp_http_referer'])) { |
|
| 787 | 787 | return $input; |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | - parse_str( $_POST['_wp_http_referer'], $referrer ); |
|
| 790 | + parse_str($_POST['_wp_http_referer'], $referrer); |
|
| 791 | 791 | |
| 792 | 792 | $settings = wpinv_get_registered_settings(); |
| 793 | - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
|
| 794 | - $section = isset( $referrer['section'] ) ? $referrer['section'] : 'main'; |
|
| 793 | + $tab = isset($referrer['tab']) ? $referrer['tab'] : 'general'; |
|
| 794 | + $section = isset($referrer['section']) ? $referrer['section'] : 'main'; |
|
| 795 | 795 | |
| 796 | 796 | $input = $input ? $input : array(); |
| 797 | - $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input ); |
|
| 798 | - $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input ); |
|
| 797 | + $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input); |
|
| 798 | + $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input); |
|
| 799 | 799 | |
| 800 | 800 | // Loop through each setting being saved and pass it through a sanitization filter |
| 801 | - foreach ( $input as $key => $value ) { |
|
| 801 | + foreach ($input as $key => $value) { |
|
| 802 | 802 | // Get the setting type (checkbox, select, etc) |
| 803 | - $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false; |
|
| 803 | + $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false; |
|
| 804 | 804 | |
| 805 | - if ( $type ) { |
|
| 805 | + if ($type) { |
|
| 806 | 806 | // Field type specific filter |
| 807 | - $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key ); |
|
| 807 | + $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | // General filter |
| 811 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
| 811 | + $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | // Loop through the whitelist and unset any that are empty for the tab being saved |
| 815 | - $main_settings = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections |
|
| 816 | - $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array(); |
|
| 815 | + $main_settings = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections |
|
| 816 | + $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array(); |
|
| 817 | 817 | |
| 818 | - $found_settings = array_merge( $main_settings, $section_settings ); |
|
| 818 | + $found_settings = array_merge($main_settings, $section_settings); |
|
| 819 | 819 | |
| 820 | - if ( ! empty( $found_settings ) ) { |
|
| 821 | - foreach ( $found_settings as $key => $value ) { |
|
| 820 | + if (!empty($found_settings)) { |
|
| 821 | + foreach ($found_settings as $key => $value) { |
|
| 822 | 822 | |
| 823 | 823 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
| 824 | - if ( is_numeric( $key ) ) { |
|
| 824 | + if (is_numeric($key)) { |
|
| 825 | 825 | $key = $value['id']; |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - if ( empty( $input[ $key ] ) ) { |
|
| 829 | - unset( $wpinv_options[ $key ] ); |
|
| 828 | + if (empty($input[$key])) { |
|
| 829 | + unset($wpinv_options[$key]); |
|
| 830 | 830 | } |
| 831 | 831 | } |
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | // Merge our new settings with the existing |
| 835 | - $output = array_merge( $wpinv_options, $input ); |
|
| 835 | + $output = array_merge($wpinv_options, $input); |
|
| 836 | 836 | |
| 837 | - add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' ); |
|
| 837 | + add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated'); |
|
| 838 | 838 | |
| 839 | 839 | return $output; |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | -function wpinv_settings_sanitize_misc_accounting( $input ) { |
|
| 842 | +function wpinv_settings_sanitize_misc_accounting($input) { |
|
| 843 | 843 | global $wpinv_options, $wpi_session; |
| 844 | 844 | |
| 845 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 845 | + if (!current_user_can('manage_options')) { |
|
| 846 | 846 | return $input; |
| 847 | 847 | } |
| 848 | 848 | |
| 849 | - if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) { |
|
| 849 | + if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) { |
|
| 850 | 850 | // Shows an admin notice about upgrading previous order numbers |
| 851 | - $wpi_session->set( 'upgrade_sequential', '1' ); |
|
| 851 | + $wpi_session->set('upgrade_sequential', '1'); |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | return $input; |
| 855 | 855 | } |
| 856 | -add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' ); |
|
| 856 | +add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting'); |
|
| 857 | 857 | |
| 858 | -function wpinv_settings_sanitize_tax_rates( $input ) { |
|
| 859 | - if( !current_user_can( 'manage_options' ) ) { |
|
| 858 | +function wpinv_settings_sanitize_tax_rates($input) { |
|
| 859 | + if (!current_user_can('manage_options')) { |
|
| 860 | 860 | return $input; |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | - $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array(); |
|
| 863 | + $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array(); |
|
| 864 | 864 | |
| 865 | 865 | $tax_rates = array(); |
| 866 | 866 | |
| 867 | - if ( !empty( $new_rates ) ) { |
|
| 868 | - foreach ( $new_rates as $rate ) { |
|
| 869 | - if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) { |
|
| 867 | + if (!empty($new_rates)) { |
|
| 868 | + foreach ($new_rates as $rate) { |
|
| 869 | + if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) { |
|
| 870 | 870 | continue; |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 ); |
|
| 873 | + $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4); |
|
| 874 | 874 | |
| 875 | 875 | $tax_rates[] = $rate; |
| 876 | 876 | } |
| 877 | 877 | } |
| 878 | 878 | |
| 879 | - update_option( 'wpinv_tax_rates', $tax_rates ); |
|
| 879 | + update_option('wpinv_tax_rates', $tax_rates); |
|
| 880 | 880 | |
| 881 | 881 | return $input; |
| 882 | 882 | } |
| 883 | -add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' ); |
|
| 883 | +add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates'); |
|
| 884 | 884 | |
| 885 | -function wpinv_sanitize_text_field( $input ) { |
|
| 886 | - return trim( $input ); |
|
| 885 | +function wpinv_sanitize_text_field($input) { |
|
| 886 | + return trim($input); |
|
| 887 | 887 | } |
| 888 | -add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' ); |
|
| 888 | +add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field'); |
|
| 889 | 889 | |
| 890 | 890 | function wpinv_get_settings_tabs() { |
| 891 | 891 | $tabs = array(); |
| 892 | - $tabs['general'] = __( 'General', 'invoicing' ); |
|
| 893 | - $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
|
| 894 | - $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
|
| 895 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
| 896 | - $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
|
| 897 | - $tabs['misc'] = __( 'Misc', 'invoicing' ); |
|
| 898 | - $tabs['tools'] = __( 'Tools', 'invoicing' ); |
|
| 899 | - |
|
| 900 | - return apply_filters( 'wpinv_settings_tabs', $tabs ); |
|
| 892 | + $tabs['general'] = __('General', 'invoicing'); |
|
| 893 | + $tabs['gateways'] = __('Payment Gateways', 'invoicing'); |
|
| 894 | + $tabs['taxes'] = __('Taxes', 'invoicing'); |
|
| 895 | + $tabs['emails'] = __('Emails', 'invoicing'); |
|
| 896 | + $tabs['privacy'] = __('Privacy', 'invoicing'); |
|
| 897 | + $tabs['misc'] = __('Misc', 'invoicing'); |
|
| 898 | + $tabs['tools'] = __('Tools', 'invoicing'); |
|
| 899 | + |
|
| 900 | + return apply_filters('wpinv_settings_tabs', $tabs); |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | -function wpinv_get_settings_tab_sections( $tab = false ) { |
|
| 903 | +function wpinv_get_settings_tab_sections($tab = false) { |
|
| 904 | 904 | $tabs = false; |
| 905 | 905 | $sections = wpinv_get_registered_settings_sections(); |
| 906 | 906 | |
| 907 | - if( $tab && ! empty( $sections[ $tab ] ) ) { |
|
| 908 | - $tabs = $sections[ $tab ]; |
|
| 909 | - } else if ( $tab ) { |
|
| 907 | + if ($tab && !empty($sections[$tab])) { |
|
| 908 | + $tabs = $sections[$tab]; |
|
| 909 | + } else if ($tab) { |
|
| 910 | 910 | $tabs = false; |
| 911 | 911 | } |
| 912 | 912 | |
@@ -916,143 +916,143 @@ discard block |
||
| 916 | 916 | function wpinv_get_registered_settings_sections() { |
| 917 | 917 | static $sections = false; |
| 918 | 918 | |
| 919 | - if ( false !== $sections ) { |
|
| 919 | + if (false !== $sections) { |
|
| 920 | 920 | return $sections; |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | $sections = array( |
| 924 | - 'general' => apply_filters( 'wpinv_settings_sections_general', array( |
|
| 925 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
| 926 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
| 927 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
| 928 | - ) ), |
|
| 929 | - 'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array( |
|
| 930 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
| 931 | - ) ), |
|
| 932 | - 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
|
| 933 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
| 934 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
| 935 | - ) ), |
|
| 936 | - 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
|
| 937 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
| 938 | - ) ), |
|
| 939 | - 'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array( |
|
| 940 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
| 941 | - ) ), |
|
| 942 | - 'misc' => apply_filters( 'wpinv_settings_sections_misc', array( |
|
| 943 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
| 944 | - 'fields' => __( 'Fields Settings', 'invoicing' ), |
|
| 945 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
| 946 | - ) ), |
|
| 947 | - 'tools' => apply_filters( 'wpinv_settings_sections_tools', array( |
|
| 948 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
| 949 | - ) ), |
|
| 924 | + 'general' => apply_filters('wpinv_settings_sections_general', array( |
|
| 925 | + 'main' => __('General Settings', 'invoicing'), |
|
| 926 | + 'currency_section' => __('Currency Settings', 'invoicing'), |
|
| 927 | + 'labels' => __('Label Texts', 'invoicing'), |
|
| 928 | + )), |
|
| 929 | + 'gateways' => apply_filters('wpinv_settings_sections_gateways', array( |
|
| 930 | + 'main' => __('Gateway Settings', 'invoicing'), |
|
| 931 | + )), |
|
| 932 | + 'taxes' => apply_filters('wpinv_settings_sections_taxes', array( |
|
| 933 | + 'main' => __('Tax Settings', 'invoicing'), |
|
| 934 | + 'rates' => __('Tax Rates', 'invoicing'), |
|
| 935 | + )), |
|
| 936 | + 'emails' => apply_filters('wpinv_settings_sections_emails', array( |
|
| 937 | + 'main' => __('Email Settings', 'invoicing'), |
|
| 938 | + )), |
|
| 939 | + 'privacy' => apply_filters('wpinv_settings_sections_privacy', array( |
|
| 940 | + 'main' => __('Privacy policy', 'invoicing'), |
|
| 941 | + )), |
|
| 942 | + 'misc' => apply_filters('wpinv_settings_sections_misc', array( |
|
| 943 | + 'main' => __('Miscellaneous', 'invoicing'), |
|
| 944 | + 'fields' => __('Fields Settings', 'invoicing'), |
|
| 945 | + 'custom-css' => __('Custom CSS', 'invoicing'), |
|
| 946 | + )), |
|
| 947 | + 'tools' => apply_filters('wpinv_settings_sections_tools', array( |
|
| 948 | + 'main' => __('Diagnostic Tools', 'invoicing'), |
|
| 949 | + )), |
|
| 950 | 950 | ); |
| 951 | 951 | |
| 952 | - $sections = apply_filters( 'wpinv_settings_sections', $sections ); |
|
| 952 | + $sections = apply_filters('wpinv_settings_sections', $sections); |
|
| 953 | 953 | |
| 954 | 954 | return $sections; |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | -function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
|
| 957 | +function wpinv_get_pages($with_slug = false, $default_label = NULL) { |
|
| 958 | 958 | $pages_options = array(); |
| 959 | 959 | |
| 960 | - if( $default_label !== NULL && $default_label !== false ) { |
|
| 961 | - $pages_options = array( '' => $default_label ); // Blank option |
|
| 960 | + if ($default_label !== NULL && $default_label !== false) { |
|
| 961 | + $pages_options = array('' => $default_label); // Blank option |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | $pages = get_pages(); |
| 965 | - if ( $pages ) { |
|
| 966 | - foreach ( $pages as $page ) { |
|
| 965 | + if ($pages) { |
|
| 966 | + foreach ($pages as $page) { |
|
| 967 | 967 | $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
| 968 | - $pages_options[ $page->ID ] = $title; |
|
| 968 | + $pages_options[$page->ID] = $title; |
|
| 969 | 969 | } |
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | return $pages_options; |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | -function wpinv_header_callback( $args ) { |
|
| 976 | - if ( !empty( $args['desc'] ) ) { |
|
| 975 | +function wpinv_header_callback($args) { |
|
| 976 | + if (!empty($args['desc'])) { |
|
| 977 | 977 | echo $args['desc']; |
| 978 | 978 | } |
| 979 | 979 | } |
| 980 | 980 | |
| 981 | -function wpinv_hidden_callback( $args ) { |
|
| 981 | +function wpinv_hidden_callback($args) { |
|
| 982 | 982 | global $wpinv_options; |
| 983 | 983 | |
| 984 | - if ( isset( $args['set_value'] ) ) { |
|
| 984 | + if (isset($args['set_value'])) { |
|
| 985 | 985 | $value = $args['set_value']; |
| 986 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 987 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 986 | + } elseif (isset($wpinv_options[$args['id']])) { |
|
| 987 | + $value = $wpinv_options[$args['id']]; |
|
| 988 | 988 | } else { |
| 989 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 989 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 990 | 990 | } |
| 991 | 991 | |
| 992 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 992 | + if (isset($args['faux']) && true === $args['faux']) { |
|
| 993 | 993 | $args['readonly'] = true; |
| 994 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 994 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 995 | 995 | $name = ''; |
| 996 | 996 | } else { |
| 997 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 997 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 1000 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />'; |
|
| 1001 | 1001 | |
| 1002 | 1002 | echo $html; |
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | -function wpinv_checkbox_callback( $args ) { |
|
| 1005 | +function wpinv_checkbox_callback($args) { |
|
| 1006 | 1006 | global $wpinv_options; |
| 1007 | 1007 | |
| 1008 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1008 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1009 | 1009 | |
| 1010 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 1010 | + if (isset($args['faux']) && true === $args['faux']) { |
|
| 1011 | 1011 | $name = ''; |
| 1012 | 1012 | } else { |
| 1013 | 1013 | $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | - $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : ''; |
|
| 1016 | + $checked = isset($wpinv_options[$args['id']]) ? checked(1, $wpinv_options[$args['id']], false) : ''; |
|
| 1017 | 1017 | $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
| 1018 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1018 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1019 | 1019 | |
| 1020 | 1020 | echo $html; |
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | -function wpinv_multicheck_callback( $args ) { |
|
| 1023 | +function wpinv_multicheck_callback($args) { |
|
| 1024 | 1024 | global $wpinv_options; |
| 1025 | 1025 | |
| 1026 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1027 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
| 1026 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1027 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
| 1028 | 1028 | |
| 1029 | - if ( ! empty( $args['options'] ) ) { |
|
| 1029 | + if (!empty($args['options'])) { |
|
| 1030 | 1030 | echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
| 1031 | - foreach( $args['options'] as $key => $option ): |
|
| 1032 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 1033 | - if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { |
|
| 1031 | + foreach ($args['options'] as $key => $option): |
|
| 1032 | + $sanitize_key = wpinv_sanitize_key($key); |
|
| 1033 | + if (isset($wpinv_options[$args['id']][$sanitize_key])) { |
|
| 1034 | 1034 | $enabled = $sanitize_key; |
| 1035 | 1035 | } else { |
| 1036 | 1036 | $enabled = NULL; |
| 1037 | 1037 | } |
| 1038 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
| 1039 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
| 1038 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/> '; |
|
| 1039 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>'; |
|
| 1040 | 1040 | endforeach; |
| 1041 | 1041 | echo '</div>'; |
| 1042 | 1042 | echo '<p class="description">' . $args['desc'] . '</p>'; |
| 1043 | 1043 | } |
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | -function wpinv_payment_icons_callback( $args ) { |
|
| 1046 | +function wpinv_payment_icons_callback($args) { |
|
| 1047 | 1047 | global $wpinv_options; |
| 1048 | 1048 | |
| 1049 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1049 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1050 | 1050 | |
| 1051 | - if ( ! empty( $args['options'] ) ) { |
|
| 1052 | - foreach( $args['options'] as $key => $option ) { |
|
| 1053 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 1051 | + if (!empty($args['options'])) { |
|
| 1052 | + foreach ($args['options'] as $key => $option) { |
|
| 1053 | + $sanitize_key = wpinv_sanitize_key($key); |
|
| 1054 | 1054 | |
| 1055 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
| 1055 | + if (isset($wpinv_options[$args['id']][$key])) { |
|
| 1056 | 1056 | $enabled = $option; |
| 1057 | 1057 | } else { |
| 1058 | 1058 | $enabled = NULL; |
@@ -1060,197 +1060,197 @@ discard block |
||
| 1060 | 1060 | |
| 1061 | 1061 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
| 1062 | 1062 | |
| 1063 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
| 1063 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/> '; |
|
| 1064 | 1064 | |
| 1065 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
| 1066 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 1065 | + if (wpinv_string_is_image_url($key)) { |
|
| 1066 | + echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 1067 | 1067 | } else { |
| 1068 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
| 1068 | + $card = strtolower(str_replace(' ', '', $option)); |
|
| 1069 | 1069 | |
| 1070 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
| 1071 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
| 1070 | + if (has_filter('wpinv_accepted_payment_' . $card . '_image')) { |
|
| 1071 | + $image = apply_filters('wpinv_accepted_payment_' . $card . '_image', ''); |
|
| 1072 | 1072 | } else { |
| 1073 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
| 1073 | + $image = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false); |
|
| 1074 | 1074 | $content_dir = WP_CONTENT_DIR; |
| 1075 | 1075 | |
| 1076 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
| 1076 | + if (function_exists('wp_normalize_path')) { |
|
| 1077 | 1077 | // Replaces backslashes with forward slashes for Windows systems |
| 1078 | - $image = wp_normalize_path( $image ); |
|
| 1079 | - $content_dir = wp_normalize_path( $content_dir ); |
|
| 1078 | + $image = wp_normalize_path($image); |
|
| 1079 | + $content_dir = wp_normalize_path($content_dir); |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
| 1082 | + $image = str_replace($content_dir, content_url(), $image); |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 1085 | + echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 1086 | 1086 | } |
| 1087 | 1087 | echo $option . '</label>'; |
| 1088 | 1088 | } |
| 1089 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 1089 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>'; |
|
| 1090 | 1090 | } |
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | -function wpinv_radio_callback( $args ) { |
|
| 1093 | +function wpinv_radio_callback($args) { |
|
| 1094 | 1094 | global $wpinv_options; |
| 1095 | 1095 | |
| 1096 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1096 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1097 | 1097 | |
| 1098 | - foreach ( $args['options'] as $key => $option ) : |
|
| 1099 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 1098 | + foreach ($args['options'] as $key => $option) : |
|
| 1099 | + $sanitize_key = wpinv_sanitize_key($key); |
|
| 1100 | 1100 | |
| 1101 | 1101 | $checked = false; |
| 1102 | 1102 | |
| 1103 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
| 1103 | + if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key) |
|
| 1104 | 1104 | $checked = true; |
| 1105 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
| 1105 | + elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']])) |
|
| 1106 | 1106 | $checked = true; |
| 1107 | 1107 | |
| 1108 | 1108 | echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
| 1109 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
| 1109 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>'; |
|
| 1110 | 1110 | endforeach; |
| 1111 | 1111 | |
| 1112 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 1112 | + echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>'; |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | -function wpinv_gateways_callback( $args ) { |
|
| 1115 | +function wpinv_gateways_callback($args) { |
|
| 1116 | 1116 | global $wpinv_options; |
| 1117 | 1117 | |
| 1118 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1118 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1119 | 1119 | |
| 1120 | - foreach ( $args['options'] as $key => $option ) : |
|
| 1121 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 1120 | + foreach ($args['options'] as $key => $option) : |
|
| 1121 | + $sanitize_key = wpinv_sanitize_key($key); |
|
| 1122 | 1122 | |
| 1123 | - if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
|
| 1123 | + if (isset($wpinv_options['gateways'][$key])) |
|
| 1124 | 1124 | $enabled = '1'; |
| 1125 | 1125 | else |
| 1126 | 1126 | $enabled = null; |
| 1127 | 1127 | |
| 1128 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
| 1129 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
| 1128 | + echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
| 1129 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>'; |
|
| 1130 | 1130 | endforeach; |
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | function wpinv_gateway_select_callback($args) { |
| 1134 | 1134 | global $wpinv_options; |
| 1135 | 1135 | |
| 1136 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1137 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
| 1136 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1137 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
| 1138 | 1138 | |
| 1139 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
| 1139 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >'; |
|
| 1140 | 1140 | |
| 1141 | - foreach ( $args['options'] as $key => $option ) : |
|
| 1142 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 1143 | - $selected = selected( $key, $args['selected'], false ); |
|
| 1141 | + foreach ($args['options'] as $key => $option) : |
|
| 1142 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
| 1143 | + $selected = selected($key, $args['selected'], false); |
|
| 1144 | 1144 | } else { |
| 1145 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
|
| 1145 | + $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : ''; |
|
| 1146 | 1146 | } |
| 1147 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
| 1147 | + echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>'; |
|
| 1148 | 1148 | endforeach; |
| 1149 | 1149 | |
| 1150 | 1150 | echo '</select>'; |
| 1151 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1151 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | -function wpinv_text_callback( $args ) { |
|
| 1154 | +function wpinv_text_callback($args) { |
|
| 1155 | 1155 | global $wpinv_options; |
| 1156 | 1156 | |
| 1157 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1157 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1158 | 1158 | |
| 1159 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1160 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1159 | + if (isset($wpinv_options[$args['id']])) { |
|
| 1160 | + $value = $wpinv_options[$args['id']]; |
|
| 1161 | 1161 | } else { |
| 1162 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1162 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 1165 | + if (isset($args['faux']) && true === $args['faux']) { |
|
| 1166 | 1166 | $args['readonly'] = true; |
| 1167 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1167 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1168 | 1168 | $name = ''; |
| 1169 | 1169 | } else { |
| 1170 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 1170 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
| 1171 | 1171 | } |
| 1172 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 1172 | + $class = !empty($args['class']) ? sanitize_html_class($args['class']) : ''; |
|
| 1173 | 1173 | |
| 1174 | 1174 | $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
| 1175 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1176 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
| 1177 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1175 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
| 1176 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>'; |
|
| 1177 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1178 | 1178 | |
| 1179 | 1179 | echo $html; |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | -function wpinv_number_callback( $args ) { |
|
| 1182 | +function wpinv_number_callback($args) { |
|
| 1183 | 1183 | global $wpinv_options; |
| 1184 | 1184 | |
| 1185 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1185 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1186 | 1186 | |
| 1187 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1188 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1187 | + if (isset($wpinv_options[$args['id']])) { |
|
| 1188 | + $value = $wpinv_options[$args['id']]; |
|
| 1189 | 1189 | } else { |
| 1190 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1190 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 1193 | + if (isset($args['faux']) && true === $args['faux']) { |
|
| 1194 | 1194 | $args['readonly'] = true; |
| 1195 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1195 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1196 | 1196 | $name = ''; |
| 1197 | 1197 | } else { |
| 1198 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 1198 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
| 1202 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
| 1203 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
| 1204 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 1201 | + $max = isset($args['max']) ? $args['max'] : 999999; |
|
| 1202 | + $min = isset($args['min']) ? $args['min'] : 0; |
|
| 1203 | + $step = isset($args['step']) ? $args['step'] : 1; |
|
| 1204 | + $class = !empty($args['class']) ? sanitize_html_class($args['class']) : ''; |
|
| 1205 | 1205 | |
| 1206 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1207 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 1208 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1206 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
| 1207 | + $html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
| 1208 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1209 | 1209 | |
| 1210 | 1210 | echo $html; |
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | -function wpinv_textarea_callback( $args ) { |
|
| 1213 | +function wpinv_textarea_callback($args) { |
|
| 1214 | 1214 | global $wpinv_options; |
| 1215 | 1215 | |
| 1216 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1216 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1217 | 1217 | |
| 1218 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1219 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1218 | + if (isset($wpinv_options[$args['id']])) { |
|
| 1219 | + $value = $wpinv_options[$args['id']]; |
|
| 1220 | 1220 | } else { |
| 1221 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1221 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1225 | - $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
|
| 1224 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
| 1225 | + $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text'; |
|
| 1226 | 1226 | |
| 1227 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 1228 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1227 | + $html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
| 1228 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1229 | 1229 | |
| 1230 | 1230 | echo $html; |
| 1231 | 1231 | } |
| 1232 | 1232 | |
| 1233 | -function wpinv_password_callback( $args ) { |
|
| 1233 | +function wpinv_password_callback($args) { |
|
| 1234 | 1234 | global $wpinv_options; |
| 1235 | 1235 | |
| 1236 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1236 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1237 | 1237 | |
| 1238 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1239 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1238 | + if (isset($wpinv_options[$args['id']])) { |
|
| 1239 | + $value = $wpinv_options[$args['id']]; |
|
| 1240 | 1240 | } else { |
| 1241 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1241 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1245 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
| 1246 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1244 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
| 1245 | + $html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>'; |
|
| 1246 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1247 | 1247 | |
| 1248 | 1248 | echo $html; |
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | function wpinv_missing_callback($args) { |
| 1252 | 1252 | printf( |
| 1253 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
| 1253 | + __('The callback function used for the %s setting is missing.', 'invoicing'), |
|
| 1254 | 1254 | '<strong>' . $args['id'] . '</strong>' |
| 1255 | 1255 | ); |
| 1256 | 1256 | } |
@@ -1258,133 +1258,133 @@ discard block |
||
| 1258 | 1258 | function wpinv_select_callback($args) { |
| 1259 | 1259 | global $wpinv_options; |
| 1260 | 1260 | |
| 1261 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1261 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1262 | 1262 | |
| 1263 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1264 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1263 | + if (isset($wpinv_options[$args['id']])) { |
|
| 1264 | + $value = $wpinv_options[$args['id']]; |
|
| 1265 | 1265 | } else { |
| 1266 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1266 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 1269 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
| 1270 | 1270 | $value = $args['selected']; |
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | - if ( isset( $args['placeholder'] ) ) { |
|
| 1273 | + if (isset($args['placeholder'])) { |
|
| 1274 | 1274 | $placeholder = $args['placeholder']; |
| 1275 | 1275 | } else { |
| 1276 | 1276 | $placeholder = ''; |
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | - if( !empty( $args['onchange'] ) ) { |
|
| 1280 | - $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
| 1279 | + if (!empty($args['onchange'])) { |
|
| 1280 | + $onchange = ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
| 1281 | 1281 | } else { |
| 1282 | 1282 | $onchange = ''; |
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
| 1285 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
| 1286 | 1286 | |
| 1287 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
| 1287 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" name="wpinv_settings[' . esc_attr($args['id']) . ']" data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />'; |
|
| 1288 | 1288 | |
| 1289 | - foreach ( $args['options'] as $option => $name ) { |
|
| 1290 | - $selected = selected( $option, $value, false ); |
|
| 1291 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 1289 | + foreach ($args['options'] as $option => $name) { |
|
| 1290 | + $selected = selected($option, $value, false); |
|
| 1291 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | $html .= '</select>'; |
| 1295 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1295 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1296 | 1296 | |
| 1297 | 1297 | echo $html; |
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | -function wpinv_color_select_callback( $args ) { |
|
| 1300 | +function wpinv_color_select_callback($args) { |
|
| 1301 | 1301 | global $wpinv_options; |
| 1302 | 1302 | |
| 1303 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1303 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1304 | 1304 | |
| 1305 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1306 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1305 | + if (isset($wpinv_options[$args['id']])) { |
|
| 1306 | + $value = $wpinv_options[$args['id']]; |
|
| 1307 | 1307 | } else { |
| 1308 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1308 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
| 1311 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>'; |
|
| 1312 | 1312 | |
| 1313 | - foreach ( $args['options'] as $option => $color ) { |
|
| 1314 | - $selected = selected( $option, $value, false ); |
|
| 1315 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
| 1313 | + foreach ($args['options'] as $option => $color) { |
|
| 1314 | + $selected = selected($option, $value, false); |
|
| 1315 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>'; |
|
| 1316 | 1316 | } |
| 1317 | 1317 | |
| 1318 | 1318 | $html .= '</select>'; |
| 1319 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1319 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1320 | 1320 | |
| 1321 | 1321 | echo $html; |
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | -function wpinv_rich_editor_callback( $args ) { |
|
| 1324 | +function wpinv_rich_editor_callback($args) { |
|
| 1325 | 1325 | global $wpinv_options, $wp_version; |
| 1326 | 1326 | |
| 1327 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1327 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1328 | 1328 | |
| 1329 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1330 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1329 | + if (isset($wpinv_options[$args['id']])) { |
|
| 1330 | + $value = $wpinv_options[$args['id']]; |
|
| 1331 | 1331 | |
| 1332 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
| 1333 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1332 | + if (empty($args['allow_blank']) && empty($value)) { |
|
| 1333 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1334 | 1334 | } |
| 1335 | 1335 | } else { |
| 1336 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1336 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
| 1339 | + $rows = isset($args['size']) ? $args['size'] : 20; |
|
| 1340 | 1340 | |
| 1341 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
| 1341 | + if ($wp_version >= 3.3 && function_exists('wp_editor')) { |
|
| 1342 | 1342 | ob_start(); |
| 1343 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
| 1343 | + wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows), 'media_buttons' => false)); |
|
| 1344 | 1344 | $html = ob_get_clean(); |
| 1345 | 1345 | } else { |
| 1346 | - $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 1346 | + $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
| 1347 | 1347 | } |
| 1348 | 1348 | |
| 1349 | - $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1349 | + $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1350 | 1350 | |
| 1351 | 1351 | echo $html; |
| 1352 | 1352 | } |
| 1353 | 1353 | |
| 1354 | -function wpinv_upload_callback( $args ) { |
|
| 1354 | +function wpinv_upload_callback($args) { |
|
| 1355 | 1355 | global $wpinv_options; |
| 1356 | 1356 | |
| 1357 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1357 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1358 | 1358 | |
| 1359 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1359 | + if (isset($wpinv_options[$args['id']])) { |
|
| 1360 | 1360 | $value = $wpinv_options[$args['id']]; |
| 1361 | 1361 | } else { |
| 1362 | 1362 | $value = isset($args['std']) ? $args['std'] : ''; |
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1366 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 1367 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
| 1368 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1365 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
| 1366 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
| 1367 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>'; |
|
| 1368 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1369 | 1369 | |
| 1370 | 1370 | echo $html; |
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | -function wpinv_color_callback( $args ) { |
|
| 1373 | +function wpinv_color_callback($args) { |
|
| 1374 | 1374 | global $wpinv_options; |
| 1375 | 1375 | |
| 1376 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1376 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1377 | 1377 | |
| 1378 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1379 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1378 | + if (isset($wpinv_options[$args['id']])) { |
|
| 1379 | + $value = $wpinv_options[$args['id']]; |
|
| 1380 | 1380 | } else { |
| 1381 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1381 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1384 | + $default = isset($args['std']) ? $args['std'] : ''; |
|
| 1385 | 1385 | |
| 1386 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
| 1387 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1386 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />'; |
|
| 1387 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1388 | 1388 | |
| 1389 | 1389 | echo $html; |
| 1390 | 1390 | } |
@@ -1392,9 +1392,9 @@ discard block |
||
| 1392 | 1392 | function wpinv_country_states_callback($args) { |
| 1393 | 1393 | global $wpinv_options; |
| 1394 | 1394 | |
| 1395 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 1395 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 1396 | 1396 | |
| 1397 | - if ( isset( $args['placeholder'] ) ) { |
|
| 1397 | + if (isset($args['placeholder'])) { |
|
| 1398 | 1398 | $placeholder = $args['placeholder']; |
| 1399 | 1399 | } else { |
| 1400 | 1400 | $placeholder = ''; |
@@ -1402,16 +1402,16 @@ discard block |
||
| 1402 | 1402 | |
| 1403 | 1403 | $states = wpinv_get_country_states(); |
| 1404 | 1404 | |
| 1405 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
| 1406 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
| 1405 | + $class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
| 1406 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>'; |
|
| 1407 | 1407 | |
| 1408 | - foreach ( $states as $option => $name ) { |
|
| 1409 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
| 1410 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 1408 | + foreach ($states as $option => $name) { |
|
| 1409 | + $selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : ''; |
|
| 1410 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
| 1411 | 1411 | } |
| 1412 | 1412 | |
| 1413 | 1413 | $html .= '</select>'; |
| 1414 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1414 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
| 1415 | 1415 | |
| 1416 | 1416 | echo $html; |
| 1417 | 1417 | } |
@@ -1426,96 +1426,96 @@ discard block |
||
| 1426 | 1426 | <table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts"> |
| 1427 | 1427 | <thead> |
| 1428 | 1428 | <tr> |
| 1429 | - <th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
| 1430 | - <th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th> |
|
| 1431 | - <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
| 1432 | - <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
| 1433 | - <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th> |
|
| 1434 | - <th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th> |
|
| 1429 | + <th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th> |
|
| 1430 | + <th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th> |
|
| 1431 | + <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
| 1432 | + <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
| 1433 | + <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th> |
|
| 1434 | + <th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th> |
|
| 1435 | 1435 | </tr> |
| 1436 | 1436 | </thead> |
| 1437 | 1437 | <tbody> |
| 1438 | - <?php if( !empty( $rates ) ) : ?> |
|
| 1439 | - <?php foreach( $rates as $key => $rate ) : ?> |
|
| 1438 | + <?php if (!empty($rates)) : ?> |
|
| 1439 | + <?php foreach ($rates as $key => $rate) : ?> |
|
| 1440 | 1440 | <?php |
| 1441 | - $sanitized_key = wpinv_sanitize_key( $key ); |
|
| 1441 | + $sanitized_key = wpinv_sanitize_key($key); |
|
| 1442 | 1442 | ?> |
| 1443 | 1443 | <tr> |
| 1444 | 1444 | <td class="wpinv_tax_country"> |
| 1445 | 1445 | <?php |
| 1446 | - echo wpinv_html_select( array( |
|
| 1447 | - 'options' => wpinv_get_country_list( true ), |
|
| 1446 | + echo wpinv_html_select(array( |
|
| 1447 | + 'options' => wpinv_get_country_list(true), |
|
| 1448 | 1448 | 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
| 1449 | 1449 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
| 1450 | 1450 | 'selected' => $rate['country'], |
| 1451 | 1451 | 'show_option_all' => false, |
| 1452 | 1452 | 'show_option_none' => false, |
| 1453 | 1453 | 'class' => 'wpinv-tax-country wpi_select2', |
| 1454 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 1455 | - ) ); |
|
| 1454 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
| 1455 | + )); |
|
| 1456 | 1456 | ?> |
| 1457 | 1457 | </td> |
| 1458 | 1458 | <td class="wpinv_tax_state"> |
| 1459 | 1459 | <?php |
| 1460 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
| 1461 | - if( !empty( $states ) ) { |
|
| 1462 | - echo wpinv_html_select( array( |
|
| 1463 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
| 1460 | + $states = wpinv_get_country_states($rate['country']); |
|
| 1461 | + if (!empty($states)) { |
|
| 1462 | + echo wpinv_html_select(array( |
|
| 1463 | + 'options' => array_merge(array('' => ''), $states), |
|
| 1464 | 1464 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
| 1465 | 1465 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
| 1466 | 1466 | 'selected' => $rate['state'], |
| 1467 | 1467 | 'show_option_all' => false, |
| 1468 | 1468 | 'show_option_none' => false, |
| 1469 | 1469 | 'class' => 'wpi_select2', |
| 1470 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
| 1471 | - ) ); |
|
| 1470 | + 'placeholder' => __('Choose a state', 'invoicing') |
|
| 1471 | + )); |
|
| 1472 | 1472 | } else { |
| 1473 | - echo wpinv_html_text( array( |
|
| 1473 | + echo wpinv_html_text(array( |
|
| 1474 | 1474 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
| 1475 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
| 1475 | + 'value' => !empty($rate['state']) ? $rate['state'] : '', |
|
| 1476 | 1476 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
| 1477 | - ) ); |
|
| 1477 | + )); |
|
| 1478 | 1478 | } |
| 1479 | 1479 | ?> |
| 1480 | 1480 | </td> |
| 1481 | 1481 | <td class="wpinv_tax_global"> |
| 1482 | - <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
|
| 1483 | - <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
| 1482 | + <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/> |
|
| 1483 | + <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
| 1484 | 1484 | </td> |
| 1485 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td> |
|
| 1486 | - <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td> |
|
| 1487 | - <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
| 1485 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td> |
|
| 1486 | + <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td> |
|
| 1487 | + <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
| 1488 | 1488 | </tr> |
| 1489 | 1489 | <?php endforeach; ?> |
| 1490 | 1490 | <?php else : ?> |
| 1491 | 1491 | <tr> |
| 1492 | 1492 | <td class="wpinv_tax_country"> |
| 1493 | 1493 | <?php |
| 1494 | - echo wpinv_html_select( array( |
|
| 1495 | - 'options' => wpinv_get_country_list( true ), |
|
| 1494 | + echo wpinv_html_select(array( |
|
| 1495 | + 'options' => wpinv_get_country_list(true), |
|
| 1496 | 1496 | 'name' => 'tax_rates[0][country]', |
| 1497 | 1497 | 'show_option_all' => false, |
| 1498 | 1498 | 'show_option_none' => false, |
| 1499 | 1499 | 'class' => 'wpinv-tax-country wpi_select2', |
| 1500 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 1501 | - ) ); ?> |
|
| 1500 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
| 1501 | + )); ?> |
|
| 1502 | 1502 | </td> |
| 1503 | 1503 | <td class="wpinv_tax_state"> |
| 1504 | - <?php echo wpinv_html_text( array( |
|
| 1504 | + <?php echo wpinv_html_text(array( |
|
| 1505 | 1505 | 'name' => 'tax_rates[0][state]' |
| 1506 | - ) ); ?> |
|
| 1506 | + )); ?> |
|
| 1507 | 1507 | </td> |
| 1508 | 1508 | <td class="wpinv_tax_global"> |
| 1509 | 1509 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
| 1510 | - <label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
| 1510 | + <label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
| 1511 | 1511 | </td> |
| 1512 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td> |
|
| 1512 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>"/></td> |
|
| 1513 | 1513 | <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td> |
| 1514 | - <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
| 1514 | + <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
| 1515 | 1515 | </tr> |
| 1516 | 1516 | <?php endif; ?> |
| 1517 | 1517 | </tbody> |
| 1518 | - <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
|
| 1518 | + <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot> |
|
| 1519 | 1519 | </table> |
| 1520 | 1520 | <?php |
| 1521 | 1521 | echo ob_get_clean(); |
@@ -1526,76 +1526,76 @@ discard block |
||
| 1526 | 1526 | ob_start(); ?> |
| 1527 | 1527 | </td><tr> |
| 1528 | 1528 | <td colspan="2" class="wpinv_tools_tdbox"> |
| 1529 | - <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
| 1530 | - <?php do_action( 'wpinv_tools_before' ); ?> |
|
| 1529 | + <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
| 1530 | + <?php do_action('wpinv_tools_before'); ?> |
|
| 1531 | 1531 | <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts"> |
| 1532 | 1532 | <thead> |
| 1533 | 1533 | <tr> |
| 1534 | - <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th> |
|
| 1535 | - <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th> |
|
| 1536 | - <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th> |
|
| 1534 | + <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th> |
|
| 1535 | + <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th> |
|
| 1536 | + <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th> |
|
| 1537 | 1537 | </tr> |
| 1538 | 1538 | </thead> |
| 1539 | - <?php do_action( 'wpinv_tools_row' ); ?> |
|
| 1539 | + <?php do_action('wpinv_tools_row'); ?> |
|
| 1540 | 1540 | <tbody> |
| 1541 | 1541 | </tbody> |
| 1542 | 1542 | </table> |
| 1543 | - <?php do_action( 'wpinv_tools_after' ); ?> |
|
| 1543 | + <?php do_action('wpinv_tools_after'); ?> |
|
| 1544 | 1544 | <?php |
| 1545 | 1545 | echo ob_get_clean(); |
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | -function wpinv_descriptive_text_callback( $args ) { |
|
| 1549 | - echo wp_kses_post( $args['desc'] ); |
|
| 1548 | +function wpinv_descriptive_text_callback($args) { |
|
| 1549 | + echo wp_kses_post($args['desc']); |
|
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | -function wpinv_hook_callback( $args ) { |
|
| 1553 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
| 1552 | +function wpinv_hook_callback($args) { |
|
| 1553 | + do_action('wpinv_' . $args['id'], $args); |
|
| 1554 | 1554 | } |
| 1555 | 1555 | |
| 1556 | 1556 | function wpinv_set_settings_cap() { |
| 1557 | 1557 | return 'manage_options'; |
| 1558 | 1558 | } |
| 1559 | -add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
|
| 1559 | +add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap'); |
|
| 1560 | 1560 | |
| 1561 | -function wpinv_settings_sanitize_input( $value, $key ) { |
|
| 1562 | - if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) { |
|
| 1563 | - $value = wpinv_sanitize_amount( $value, 4 ); |
|
| 1561 | +function wpinv_settings_sanitize_input($value, $key) { |
|
| 1562 | + if ($key == 'tax_rate' || $key == 'eu_fallback_rate') { |
|
| 1563 | + $value = wpinv_sanitize_amount($value, 4); |
|
| 1564 | 1564 | $value = $value >= 100 ? 99 : $value; |
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | return $value; |
| 1568 | 1568 | } |
| 1569 | -add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 ); |
|
| 1569 | +add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2); |
|
| 1570 | 1570 | |
| 1571 | -function wpinv_on_update_settings( $old_value, $value, $option ) { |
|
| 1572 | - $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : ''; |
|
| 1573 | - $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : ''; |
|
| 1571 | +function wpinv_on_update_settings($old_value, $value, $option) { |
|
| 1572 | + $old = !empty($old_value['remove_data_on_unistall']) ? 1 : ''; |
|
| 1573 | + $new = !empty($value['remove_data_on_unistall']) ? 1 : ''; |
|
| 1574 | 1574 | |
| 1575 | - if ( $old != $new ) { |
|
| 1576 | - update_option( 'wpinv_remove_data_on_invoice_unistall', $new ); |
|
| 1575 | + if ($old != $new) { |
|
| 1576 | + update_option('wpinv_remove_data_on_invoice_unistall', $new); |
|
| 1577 | 1577 | } |
| 1578 | 1578 | } |
| 1579 | -add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 ); |
|
| 1580 | -add_action( 'wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1581 | -add_action( 'wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1582 | -add_action( 'wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1583 | -add_action( 'wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1584 | -add_action( 'wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1585 | -add_action( 'wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1586 | -add_action( 'wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1587 | -add_action( 'wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1588 | -add_action( 'wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1589 | -add_action( 'wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
| 1590 | - |
|
| 1591 | -function wpinv_settings_tab_bottom_emails( $active_tab, $section ) { |
|
| 1579 | +add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3); |
|
| 1580 | +add_action('wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1581 | +add_action('wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1582 | +add_action('wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1583 | +add_action('wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1584 | +add_action('wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1585 | +add_action('wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1586 | +add_action('wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1587 | +add_action('wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1588 | +add_action('wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1589 | +add_action('wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
| 1590 | + |
|
| 1591 | +function wpinv_settings_tab_bottom_emails($active_tab, $section) { |
|
| 1592 | 1592 | ?> |
| 1593 | 1593 | <div class="wpinv-email-wc-row "> |
| 1594 | 1594 | <div class="wpinv-email-wc-td"> |
| 1595 | - <h3 class="wpinv-email-wc-title"><?php echo apply_filters( 'wpinv_settings_email_wildcards_title', __( 'Wildcards For Emails', 'invoicing' ) ); ?></h3> |
|
| 1595 | + <h3 class="wpinv-email-wc-title"><?php echo apply_filters('wpinv_settings_email_wildcards_title', __('Wildcards For Emails', 'invoicing')); ?></h3> |
|
| 1596 | 1596 | <p class="wpinv-email-wc-description"> |
| 1597 | 1597 | <?php |
| 1598 | - $description = __( 'The following wildcards can be used in email subjects, heading and content:<br> |
|
| 1598 | + $description = __('The following wildcards can be used in email subjects, heading and content:<br> |
|
| 1599 | 1599 | <strong>{site_title} :</strong> Site Title<br> |
| 1600 | 1600 | <strong>{name} :</strong> Customer\'s full name<br> |
| 1601 | 1601 | <strong>{first_name} :</strong> Customer\'s first name<br> |
@@ -1609,7 +1609,7 @@ discard block |
||
| 1609 | 1609 | <strong>{invoice_due_date} :</strong> The date the invoice is due<br> |
| 1610 | 1610 | <strong>{date} :</strong> Today\'s date.<br> |
| 1611 | 1611 | <strong>{is_was} :</strong> If due date of invoice is past, displays "was" otherwise displays "is"<br> |
| 1612 | - <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing' ); |
|
| 1612 | + <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing'); |
|
| 1613 | 1613 | echo apply_filters('wpinv_settings_email_wildcards_description', $description, $active_tab, $section); |
| 1614 | 1614 | ?> |
| 1615 | 1615 | </p> |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Admin View: Page - Addons |
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 6 | +if (!defined('ABSPATH')) { |
|
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | add_ThickBox(); |
@@ -11,77 +11,77 @@ discard block |
||
| 11 | 11 | <div class="wrap wpi_addons_wrap"> |
| 12 | 12 | <h1><?php echo get_admin_page_title(); ?></h1> |
| 13 | 13 | |
| 14 | - <?php if ( $tabs ){ ?> |
|
| 14 | + <?php if ($tabs) { ?> |
|
| 15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
| 16 | 16 | <?php |
| 17 | - foreach ( $tabs as $name => $label ) { |
|
| 18 | - echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
| 17 | + foreach ($tabs as $name => $label) { |
|
| 18 | + echo '<a href="' . admin_url('admin.php?page=wpi-addons&tab=' . $name) . '" class="nav-tab ' . ($current_tab == $name ? 'nav-tab-active' : '') . '">' . $label . '</a>'; |
|
| 19 | 19 | } |
| 20 | - do_action( 'wpi_addons_tabs' ); |
|
| 20 | + do_action('wpi_addons_tabs'); |
|
| 21 | 21 | ?> |
| 22 | 22 | </nav> |
| 23 | 23 | |
| 24 | 24 | <?php |
| 25 | 25 | |
| 26 | - if($current_tab == 'membership'){ |
|
| 26 | + if ($current_tab == 'membership') { |
|
| 27 | 27 | |
| 28 | 28 | ?> |
| 29 | 29 | |
| 30 | 30 | <div class="wpi-membership-tab-conatiner"> |
| 31 | 31 | <h2>With our WPInvoicing Membership you get access to all our products!</h2> |
| 32 | 32 | <p><a class="button button-primary" href="https://wpinvoicing.com/downloads/membership/">View Memberships</a></p> |
| 33 | - <?php if(defined('WP_EASY_UPDATES_ACTIVE')){?> |
|
| 33 | + <?php if (defined('WP_EASY_UPDATES_ACTIVE')) {?> |
|
| 34 | 34 | |
| 35 | 35 | <h2>Have a membership key?</h2> |
| 36 | 36 | |
| 37 | 37 | <p> |
| 38 | 38 | <?php |
| 39 | - $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
| 40 | - echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108)); |
|
| 39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com', '1'); |
|
| 40 | + echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership', array(95, 106, 108)); |
|
| 41 | 41 | ?> |
| 42 | 42 | </p> |
| 43 | 43 | <?php }?> |
| 44 | 44 | </div> |
| 45 | 45 | |
| 46 | 46 | <?php |
| 47 | - }else{ |
|
| 47 | + } else { |
|
| 48 | 48 | $installed_plugins = get_plugins(); |
| 49 | 49 | $addon_obj = new WPInv_Admin_Addons(); |
| 50 | - if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
| 50 | + if ($addons = $addon_obj->get_section_data($current_tab)) : |
|
| 51 | 51 | ?> |
| 52 | - <ul class="wpi-products"><?php foreach ( $addons as $addon ) : |
|
| 53 | - if(965==$addon->info->id){continue;}// don't show quote add on |
|
| 52 | + <ul class="wpi-products"><?php foreach ($addons as $addon) : |
|
| 53 | + if (965 == $addon->info->id) {continue; }// don't show quote add on |
|
| 54 | 54 | ?><li class="wpi-product"> |
| 55 | 55 | <div class="wpi-product-title"> |
| 56 | 56 | <h3><?php |
| 57 | - if ( ! empty( $addon->info->excerpt) ){ |
|
| 58 | - echo wpi_help_tip( $addon->info->excerpt ); |
|
| 57 | + if (!empty($addon->info->excerpt)) { |
|
| 58 | + echo wpi_help_tip($addon->info->excerpt); |
|
| 59 | 59 | } |
| 60 | - echo esc_html( $addon->info->title ); ?></h3> |
|
| 60 | + echo esc_html($addon->info->title); ?></h3> |
|
| 61 | 61 | </div> |
| 62 | 62 | |
| 63 | 63 | <span class="wpi-product-image"> |
| 64 | - <?php if ( ! empty( $addon->info->thumbnail) ) : ?> |
|
| 65 | - <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
|
| 64 | + <?php if (!empty($addon->info->thumbnail)) : ?> |
|
| 65 | + <img src="<?php echo esc_attr($addon->info->thumbnail); ?>"/> |
|
| 66 | 66 | <?php endif; |
| 67 | 67 | |
| 68 | - if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
| 69 | - echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&TB_iframe=true&width=770&height=660" class="thickbox" >'; |
|
| 70 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
| 68 | + if (isset($addon->info->link) && substr($addon->info->link, 0, 21) === "https://wordpress.org") { |
|
| 69 | + echo '<a href="' . admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug) . '&TB_iframe=true&width=770&height=660" class="thickbox" >'; |
|
| 70 | + echo '<span class="wpi-product-info">' . __('More info', 'invoicing') . '</span>'; |
|
| 71 | 71 | echo '</a>'; |
| 72 | - }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
| 73 | - if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
| 74 | - $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&TB_iframe=true&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com'); |
|
| 75 | - }else{ |
|
| 72 | + }elseif (isset($addon->info->link) && substr($addon->info->link, 0, 23) === "https://wpinvoicing.com") { |
|
| 73 | + if (defined('WP_EASY_UPDATES_ACTIVE')) { |
|
| 74 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&TB_iframe=true&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpinvoicing.com'); |
|
| 75 | + } else { |
|
| 76 | 76 | // if installed show activation link |
| 77 | - if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
| 77 | + if (isset($installed_plugins['wp-easy-updates/external-updates.php'])) { |
|
| 78 | 78 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
| 79 | - }else{ |
|
| 79 | + } else { |
|
| 80 | 80 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | - echo '<a href="'.$url.'" class="thickbox">'; |
|
| 84 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
| 83 | + echo '<a href="' . $url . '" class="thickbox">'; |
|
| 84 | + echo '<span class="wpi-product-info">' . __('More info', 'invoicing') . '</span>'; |
|
| 85 | 85 | echo '</a>'; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | <span class="wpi-product-button"> |
| 94 | 94 | <?php |
| 95 | - $addon_obj->output_button( $addon ); |
|
| 95 | + $addon_obj->output_button($addon); |
|
| 96 | 96 | ?> |
| 97 | 97 | </span> |
| 98 | 98 | |
@@ -106,21 +106,21 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | <div class="clearfix" ></div> |
| 108 | 108 | |
| 109 | - <?php if($current_tab =='addons'){ ?> |
|
| 110 | - <p><?php printf( __( 'All of our Invoicing Addons can be found on WPInvoicing.com here: <a href="%s">Invoicing Addons</a>', 'invoicing' ), 'https://wpinvoicing.com/downloads/category/addons/' ); ?></p> |
|
| 111 | - <?php } if($current_tab =='gateways'){ ?> |
|
| 112 | - <p><?php printf( __( 'All of our Invoicing Payment Gateways can be found on WPInvoicing.com here: <a href="%s">Invoicing Payment Gateways</a>', 'invoicing' ), 'https://wpinvoicing.com/downloads/category/gateways/' ); ?></p> |
|
| 109 | + <?php if ($current_tab == 'addons') { ?> |
|
| 110 | + <p><?php printf(__('All of our Invoicing Addons can be found on WPInvoicing.com here: <a href="%s">Invoicing Addons</a>', 'invoicing'), 'https://wpinvoicing.com/downloads/category/addons/'); ?></p> |
|
| 111 | + <?php } if ($current_tab == 'gateways') { ?> |
|
| 112 | + <p><?php printf(__('All of our Invoicing Payment Gateways can be found on WPInvoicing.com here: <a href="%s">Invoicing Payment Gateways</a>', 'invoicing'), 'https://wpinvoicing.com/downloads/category/gateways/'); ?></p> |
|
| 113 | 113 | <?php } ?> |
| 114 | 114 | |
| 115 | - <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php printf( __("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.",'invoicing'),wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php'));?></span></div> |
|
| 116 | - <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php printf( __("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.",'invoicing'),admin_url("plugin-install.php?tab=upload&wpeu-install=true"));?></span></div> |
|
| 115 | + <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php printf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing'), wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php')); ?></span></div> |
|
| 116 | + <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php printf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing'), admin_url("plugin-install.php?tab=upload&wpeu-install=true")); ?></span></div> |
|
| 117 | 117 | <div id="wpeu-licence-popup" style="display:none;"> |
| 118 | 118 | <span class="wpi-notification noti-white"> |
| 119 | - <h3 class="wpeu-licence-title"><?php _e("Licence key",'invoicing');?></h3> |
|
| 120 | - <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key",'invoicing');?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install",'invoicing');?></button> |
|
| 119 | + <h3 class="wpeu-licence-title"><?php _e("Licence key", 'invoicing'); ?></h3> |
|
| 120 | + <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key", 'invoicing'); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install", 'invoicing'); ?></button> |
|
| 121 | 121 | <br> |
| 122 | 122 | <?php |
| 123 | - echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
| 123 | + echo sprintf(__('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>'); |
|
| 124 | 124 | ?> |
| 125 | 125 | </span> |
| 126 | 126 | </div> |