@@ -12,228 +12,228 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission taxes. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $taxes = array(); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Whether or not we should skip the taxes. |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $skip_taxes = false; |
|
| 15 | + /** |
|
| 16 | + * Submission taxes. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $taxes = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Whether or not we should skip the taxes. |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $skip_taxes = false; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Validate VAT number. |
|
| 35 | - $this->validate_vat( $submission ); |
|
| 36 | - |
|
| 37 | - if ( $this->skip_taxes ) { |
|
| 38 | - return; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - foreach ( $submission->get_items() as $item ) { |
|
| 42 | - $this->process_item_tax( $item, $submission ); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - // Process any existing invoice taxes. |
|
| 46 | - if ( $submission->has_invoice() ) { |
|
| 47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Maybe process tax. |
|
| 54 | - * |
|
| 55 | - * @since 1.0.19 |
|
| 56 | - * @param GetPaid_Form_Item $item |
|
| 57 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | - */ |
|
| 59 | - public function process_item_tax( $item, $submission ) { |
|
| 60 | - |
|
| 61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 65 | - |
|
| 66 | - foreach ( $taxes as $name => $amount ) { |
|
| 67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | - |
|
| 70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 71 | - |
|
| 72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 73 | - $this->taxes[ $name ] = $tax; |
|
| 74 | - continue; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 79 | - |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Checks if the submission has a digital item. |
|
| 86 | - * |
|
| 87 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 88 | - * @since 1.0.19 |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function has_digital_item( $submission ) { |
|
| 92 | - |
|
| 93 | - foreach ( $submission->get_items() as $item ) { |
|
| 94 | - |
|
| 95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Checks if this is an eu store. |
|
| 106 | - * |
|
| 107 | - * @since 1.0.19 |
|
| 108 | - * @return bool |
|
| 109 | - */ |
|
| 110 | - public static function is_eu_store() { |
|
| 111 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Checks if this is an eu country. |
|
| 116 | - * |
|
| 117 | - * @param string $country |
|
| 118 | - * @since 1.0.19 |
|
| 119 | - * @return bool |
|
| 120 | - */ |
|
| 121 | - public static function is_eu_country( $country ) { |
|
| 122 | - return getpaid_is_eu_state( $country ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Checks if this is an eu purchase. |
|
| 127 | - * |
|
| 128 | - * @param string $customer_country |
|
| 129 | - * @since 1.0.19 |
|
| 130 | - * @return bool |
|
| 131 | - */ |
|
| 132 | - public static function is_eu_transaction( $customer_country ) { |
|
| 133 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Retrieves the vat number. |
|
| 138 | - * |
|
| 139 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 140 | - * @since 1.0.19 |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function get_vat_number( $submission ) { |
|
| 144 | - |
|
| 145 | - // Retrieve from the posted number. |
|
| 146 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 147 | - if ( ! is_null( $vat_number ) ) { |
|
| 148 | - return wpinv_clean( $vat_number ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Retrieves the company. |
|
| 156 | - * |
|
| 157 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 158 | - * @since 1.0.19 |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function get_company( $submission ) { |
|
| 162 | - |
|
| 163 | - // Retrieve from the posted data. |
|
| 164 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 165 | - if ( ! empty( $company ) ) { |
|
| 166 | - return wpinv_clean( $company ); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // Retrieve from the invoice. |
|
| 170 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Checks if we require a VAT number. |
|
| 175 | - * |
|
| 176 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 177 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 178 | - * @since 1.0.19 |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 182 | - |
|
| 183 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 184 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 185 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
| 186 | - |
|
| 187 | - return $prevent_b2c && $is_eu; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Validate VAT data. |
|
| 192 | - * |
|
| 193 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 194 | - * @since 1.0.19 |
|
| 195 | - */ |
|
| 196 | - public function validate_vat( $submission ) { |
|
| 197 | - |
|
| 198 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 199 | - |
|
| 200 | - // Abort if we are not validating vat numbers. |
|
| 201 | - if ( ! $in_eu ) { |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Validate VAT number. |
|
| 35 | + $this->validate_vat( $submission ); |
|
| 36 | + |
|
| 37 | + if ( $this->skip_taxes ) { |
|
| 202 | 38 | return; |
| 203 | - } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + foreach ( $submission->get_items() as $item ) { |
|
| 42 | + $this->process_item_tax( $item, $submission ); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + // Process any existing invoice taxes. |
|
| 46 | + if ( $submission->has_invoice() ) { |
|
| 47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Maybe process tax. |
|
| 54 | + * |
|
| 55 | + * @since 1.0.19 |
|
| 56 | + * @param GetPaid_Form_Item $item |
|
| 57 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | + */ |
|
| 59 | + public function process_item_tax( $item, $submission ) { |
|
| 60 | + |
|
| 61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 64 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 65 | + |
|
| 66 | + foreach ( $taxes as $name => $amount ) { |
|
| 67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | + |
|
| 70 | + $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 71 | + |
|
| 72 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 73 | + $this->taxes[ $name ] = $tax; |
|
| 74 | + continue; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 78 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 79 | + |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Checks if the submission has a digital item. |
|
| 86 | + * |
|
| 87 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 88 | + * @since 1.0.19 |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function has_digital_item( $submission ) { |
|
| 92 | + |
|
| 93 | + foreach ( $submission->get_items() as $item ) { |
|
| 94 | + |
|
| 95 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + } |
|
| 204 | 100 | |
| 205 | - // Prepare variables. |
|
| 206 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 207 | - $ip_country = getpaid_get_ip_country(); |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Checks if this is an eu store. |
|
| 106 | + * |
|
| 107 | + * @since 1.0.19 |
|
| 108 | + * @return bool |
|
| 109 | + */ |
|
| 110 | + public static function is_eu_store() { |
|
| 111 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Checks if this is an eu country. |
|
| 116 | + * |
|
| 117 | + * @param string $country |
|
| 118 | + * @since 1.0.19 |
|
| 119 | + * @return bool |
|
| 120 | + */ |
|
| 121 | + public static function is_eu_country( $country ) { |
|
| 122 | + return getpaid_is_eu_state( $country ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Checks if this is an eu purchase. |
|
| 127 | + * |
|
| 128 | + * @param string $customer_country |
|
| 129 | + * @since 1.0.19 |
|
| 130 | + * @return bool |
|
| 131 | + */ |
|
| 132 | + public static function is_eu_transaction( $customer_country ) { |
|
| 133 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Retrieves the vat number. |
|
| 138 | + * |
|
| 139 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 140 | + * @since 1.0.19 |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function get_vat_number( $submission ) { |
|
| 144 | + |
|
| 145 | + // Retrieve from the posted number. |
|
| 146 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 147 | + if ( ! is_null( $vat_number ) ) { |
|
| 148 | + return wpinv_clean( $vat_number ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Retrieves the company. |
|
| 156 | + * |
|
| 157 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 158 | + * @since 1.0.19 |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function get_company( $submission ) { |
|
| 162 | + |
|
| 163 | + // Retrieve from the posted data. |
|
| 164 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 165 | + if ( ! empty( $company ) ) { |
|
| 166 | + return wpinv_clean( $company ); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // Retrieve from the invoice. |
|
| 170 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Checks if we require a VAT number. |
|
| 175 | + * |
|
| 176 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 177 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 178 | + * @since 1.0.19 |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 182 | + |
|
| 183 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 184 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 185 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
| 186 | + |
|
| 187 | + return $prevent_b2c && $is_eu; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Validate VAT data. |
|
| 192 | + * |
|
| 193 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 194 | + * @since 1.0.19 |
|
| 195 | + */ |
|
| 196 | + public function validate_vat( $submission ) { |
|
| 197 | + |
|
| 198 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 199 | + |
|
| 200 | + // Abort if we are not validating vat numbers. |
|
| 201 | + if ( ! $in_eu ) { |
|
| 202 | + return; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // Prepare variables. |
|
| 206 | + $vat_number = $this->get_vat_number( $submission ); |
|
| 207 | + $ip_country = getpaid_get_ip_country(); |
|
| 208 | 208 | $is_eu = $this->is_eu_country( $submission->country ); |
| 209 | 209 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
| 210 | 210 | |
| 211 | - // Maybe abort early for initial fetches. |
|
| 212 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 213 | - return; |
|
| 214 | - } |
|
| 211 | + // Maybe abort early for initial fetches. |
|
| 212 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - // If we're preventing business to consumer purchases, |
|
| 217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 216 | + // If we're preventing business to consumer purchases, |
|
| 217 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 218 | 218 | |
| 219 | - // Ensure that a vat number has been specified. |
|
| 220 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
| 219 | + // Ensure that a vat number has been specified. |
|
| 220 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
| 221 | 221 | |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - if ( empty( $vat_number ) ) { |
|
| 225 | - return; |
|
| 226 | - } |
|
| 224 | + if ( empty( $vat_number ) ) { |
|
| 225 | + return; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 229 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 230 | - } |
|
| 228 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 229 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 233 | - return; |
|
| 234 | - } |
|
| 232 | + if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 233 | + return; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - $this->skip_taxes = true; |
|
| 237 | - } |
|
| 236 | + $this->skip_taxes = true; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | 239 | } |
@@ -11,18 +11,18 @@ discard block |
||
| 11 | 11 | * @return mixed|void |
| 12 | 12 | */ |
| 13 | 13 | function sd_pagenow_exclude(){ |
| 14 | - return apply_filters( 'sd_pagenow_exclude', array( |
|
| 15 | - 'upload.php', |
|
| 16 | - 'edit-comments.php', |
|
| 17 | - 'edit-tags.php', |
|
| 18 | - 'index.php', |
|
| 19 | - 'media-new.php', |
|
| 20 | - 'options-discussion.php', |
|
| 21 | - 'options-writing.php', |
|
| 22 | - 'edit.php', |
|
| 23 | - 'themes.php', |
|
| 24 | - 'users.php', |
|
| 25 | - ) ); |
|
| 14 | + return apply_filters( 'sd_pagenow_exclude', array( |
|
| 15 | + 'upload.php', |
|
| 16 | + 'edit-comments.php', |
|
| 17 | + 'edit-tags.php', |
|
| 18 | + 'index.php', |
|
| 19 | + 'media-new.php', |
|
| 20 | + 'options-discussion.php', |
|
| 21 | + 'options-writing.php', |
|
| 22 | + 'edit.php', |
|
| 23 | + 'themes.php', |
|
| 24 | + 'users.php', |
|
| 25 | + ) ); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -34,5 +34,5 @@ discard block |
||
| 34 | 34 | * @return mixed|void |
| 35 | 35 | */ |
| 36 | 36 | function sd_widget_exclude(){ |
| 37 | - return apply_filters( 'sd_widget_exclude', array() ); |
|
| 37 | + return apply_filters( 'sd_widget_exclude', array() ); |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -12,38 +12,38 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission items. |
|
| 17 | - * @var GetPaid_Form_Item[] |
|
| 18 | - */ |
|
| 19 | - public $items = array(); |
|
| 15 | + /** |
|
| 16 | + * Submission items. |
|
| 17 | + * @var GetPaid_Form_Item[] |
|
| 18 | + */ |
|
| 19 | + public $items = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $data = $submission->get_data(); |
|
| 29 | - $payment_form = $submission->get_payment_form(); |
|
| 30 | - |
|
| 31 | - // Prepare the selected items. |
|
| 32 | - $selected_items = array(); |
|
| 33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // (Maybe) set form items. |
|
| 38 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
| 39 | - |
|
| 40 | - // Confirm items key. |
|
| 41 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 42 | - if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
| 43 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $items = array(); |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $data = $submission->get_data(); |
|
| 29 | + $payment_form = $submission->get_payment_form(); |
|
| 30 | + |
|
| 31 | + // Prepare the selected items. |
|
| 32 | + $selected_items = array(); |
|
| 33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // (Maybe) set form items. |
|
| 38 | + if ( isset( $data['getpaid-form-items'] ) ) { |
|
| 39 | + |
|
| 40 | + // Confirm items key. |
|
| 41 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 42 | + if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
| 43 | + throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $items = array(); |
|
| 47 | 47 | $item_ids = array(); |
| 48 | 48 | |
| 49 | 49 | foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
@@ -74,58 +74,58 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | $payment_form->set_items( $items ); |
| 76 | 76 | |
| 77 | - } |
|
| 78 | - |
|
| 79 | - // Process each individual item. |
|
| 80 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 81 | - $this->process_item( $item, $selected_items, $submission ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - } |
|
| 77 | + } |
|
| 85 | 78 | |
| 86 | - /** |
|
| 87 | - * Process a single item. |
|
| 88 | - * |
|
| 89 | - * @param GetPaid_Form_Item $item |
|
| 90 | - * @param array $selected_items |
|
| 91 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 92 | - */ |
|
| 93 | - public function process_item( $item, $selected_items, $submission ) { |
|
| 79 | + // Process each individual item. |
|
| 80 | + foreach ( $payment_form->get_items() as $item ) { |
|
| 81 | + $this->process_item( $item, $selected_items, $submission ); |
|
| 82 | + } |
|
| 94 | 83 | |
| 95 | - // Abort if this is an optional item and it has not been selected. |
|
| 96 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 97 | - return; |
|
| 98 | - } |
|
| 84 | + } |
|
| 99 | 85 | |
| 100 | - // (maybe) let customers change the quantities and prices. |
|
| 101 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 102 | - |
|
| 103 | - // Maybe change the quantities. |
|
| 104 | - if ( $item->allows_quantities() ) { |
|
| 105 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 106 | - } |
|
| 86 | + /** |
|
| 87 | + * Process a single item. |
|
| 88 | + * |
|
| 89 | + * @param GetPaid_Form_Item $item |
|
| 90 | + * @param array $selected_items |
|
| 91 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 92 | + */ |
|
| 93 | + public function process_item( $item, $selected_items, $submission ) { |
|
| 94 | + |
|
| 95 | + // Abort if this is an optional item and it has not been selected. |
|
| 96 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // (maybe) let customers change the quantities and prices. |
|
| 101 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 102 | + |
|
| 103 | + // Maybe change the quantities. |
|
| 104 | + if ( $item->allows_quantities() ) { |
|
| 105 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - // Maybe change the price. |
|
| 109 | - if ( $item->user_can_set_their_price() ) { |
|
| 110 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 108 | + // Maybe change the price. |
|
| 109 | + if ( $item->user_can_set_their_price() ) { |
|
| 110 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 111 | 111 | |
| 112 | - if ( $item->get_minimum_price() > $price ) { |
|
| 113 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
| 114 | - } |
|
| 112 | + if ( $item->get_minimum_price() > $price ) { |
|
| 113 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - $item->set_price( $price ); |
|
| 116 | + $item->set_price( $price ); |
|
| 117 | 117 | |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - if ( 0 == $item->get_quantity() ) { |
|
| 123 | - return; |
|
| 124 | - } |
|
| 122 | + if ( 0 == $item->get_quantity() ) { |
|
| 123 | + return; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - // Save the item. |
|
| 127 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
| 126 | + // Save the item. |
|
| 127 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
| 128 | 128 | |
| 129 | - } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | - exit; // Exit if accessed directly |
|
| 11 | + exit; // Exit if accessed directly |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Output the metabox. |
|
| 21 | - * |
|
| 22 | - * @param WP_Post $post |
|
| 23 | - */ |
|
| 20 | + * Output the metabox. |
|
| 21 | + * |
|
| 22 | + * @param WP_Post $post |
|
| 23 | + */ |
|
| 24 | 24 | public static function output( $post ) { |
| 25 | 25 | |
| 26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
| 371 | - * Save meta box data. |
|
| 372 | - * |
|
| 373 | - * @param int $post_id |
|
| 374 | - */ |
|
| 375 | - public static function save( $post_id ) { |
|
| 371 | + * Save meta box data. |
|
| 372 | + * |
|
| 373 | + * @param int $post_id |
|
| 374 | + */ |
|
| 375 | + public static function save( $post_id ) { |
|
| 376 | 376 | |
| 377 | 377 | // Prepare the discount. |
| 378 | 378 | $discount = new WPInv_Discount( $post_id ); |
| 379 | 379 | |
| 380 | 380 | // Load new data. |
| 381 | 381 | $discount->set_props( |
| 382 | - array( |
|
| 383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
| 384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
| 385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
| 386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
| 387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
| 382 | + array( |
|
| 383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
| 384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
| 385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
| 386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
| 387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
| 388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
| 389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
| 390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
| 391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
| 392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
| 393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
| 394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
| 395 | - ) |
|
| 389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
| 390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
| 391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
| 392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
| 393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
| 394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
| 395 | + ) |
|
| 396 | 396 | ); |
| 397 | 397 | |
| 398 | - $discount->save(); |
|
| 399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
| 400 | - } |
|
| 398 | + $discount->save(); |
|
| 399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
| 400 | + } |
|
| 401 | 401 | } |
@@ -13,65 +13,65 @@ discard block |
||
| 13 | 13 | class GetPaid_Worldpay_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'worldpay'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Payment method order. |
|
| 24 | - * |
|
| 25 | - * @var int |
|
| 26 | - */ |
|
| 23 | + * Payment method order. |
|
| 24 | + * |
|
| 25 | + * @var int |
|
| 26 | + */ |
|
| 27 | 27 | public $order = 5; |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Endpoint for requests from Worldpay. |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $notify_url; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Endpoint for requests to Worldpay. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 30 | + * Endpoint for requests from Worldpay. |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $notify_url; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Endpoint for requests to Worldpay. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | 41 | protected $endpoint; |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * An array of features that this gateway supports. |
|
| 45 | - * |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 44 | + * An array of features that this gateway supports. |
|
| 45 | + * |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | 48 | protected $supports = array( 'sandbox' ); |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Currencies this gateway is allowed for. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 51 | + * Currencies this gateway is allowed for. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * URL to view a transaction. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 58 | + * URL to view a transaction. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a subscription. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 65 | + * URL to view a subscription. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * Class constructor. |
|
| 73 | - */ |
|
| 74 | - public function __construct() { |
|
| 72 | + * Class constructor. |
|
| 73 | + */ |
|
| 74 | + public function __construct() { |
|
| 75 | 75 | |
| 76 | 76 | $this->method_title = __( 'Worldpay', 'invoicing' ); |
| 77 | 77 | $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | - * Process Payment. |
|
| 89 | - * |
|
| 90 | - * |
|
| 91 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | - * @param array $submission_data Posted checkout fields. |
|
| 93 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 88 | + * Process Payment. |
|
| 89 | + * |
|
| 90 | + * |
|
| 91 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | + * @param array $submission_data Posted checkout fields. |
|
| 93 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 97 | 97 | |
| 98 | 98 | // Get redirect url. |
| 99 | 99 | $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
@@ -128,31 +128,31 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | - * Get the Worldpay request URL for an invoice. |
|
| 132 | - * |
|
| 133 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function get_request_url( $invoice ) { |
|
| 131 | + * Get the Worldpay request URL for an invoice. |
|
| 132 | + * |
|
| 133 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function get_request_url( $invoice ) { |
|
| 137 | 137 | |
| 138 | 138 | // Endpoint for this request |
| 139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 139 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 140 | 140 | |
| 141 | 141 | return $this->endpoint; |
| 142 | 142 | |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * Get Worldpay Args for passing to Worldpay. |
|
| 147 | - * |
|
| 148 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 151 | - protected function get_worldpay_args( $invoice ) { |
|
| 152 | - |
|
| 153 | - return apply_filters( |
|
| 154 | - 'getpaid_worldpay_args', |
|
| 155 | - array( |
|
| 146 | + * Get Worldpay Args for passing to Worldpay. |
|
| 147 | + * |
|
| 148 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | + protected function get_worldpay_args( $invoice ) { |
|
| 152 | + |
|
| 153 | + return apply_filters( |
|
| 154 | + 'getpaid_worldpay_args', |
|
| 155 | + array( |
|
| 156 | 156 | 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
| 157 | 157 | 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
| 158 | 158 | 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
@@ -177,18 +177,18 @@ discard block |
||
| 177 | 177 | 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
| 178 | 178 | 'compName' => wpinv_clean( $invoice->get_company() ), |
| 179 | 179 | ), |
| 180 | - $invoice |
|
| 181 | - ); |
|
| 180 | + $invoice |
|
| 181 | + ); |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | - * Secures worldpay args with an md5 hash. |
|
| 187 | - * |
|
| 188 | - * @param array $args Gateway args. |
|
| 189 | - * @return array |
|
| 190 | - */ |
|
| 191 | - public function hash_args( $args ) { |
|
| 186 | + * Secures worldpay args with an md5 hash. |
|
| 187 | + * |
|
| 188 | + * @param array $args Gateway args. |
|
| 189 | + * @return array |
|
| 190 | + */ |
|
| 191 | + public function hash_args( $args ) { |
|
| 192 | 192 | |
| 193 | 193 | $md5_secret = $this->get_option( 'md5_secret' ); |
| 194 | 194 | |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | - * Processes ipns and marks payments as complete. |
|
| 208 | - * |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function verify_ipn() { |
|
| 207 | + * Processes ipns and marks payments as complete. |
|
| 208 | + * |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function verify_ipn() { |
|
| 212 | 212 | |
| 213 | 213 | // Validate the IPN. |
| 214 | 214 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | - } |
|
| 215 | + wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | // Process the IPN. |
| 219 | 219 | $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - // Update the ip address. |
|
| 233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 232 | + // Update the ip address. |
|
| 233 | + if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 234 | 234 | $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | - * Check Worldpay IPN validity. |
|
| 261 | - */ |
|
| 262 | - public function validate_ipn() { |
|
| 260 | + * Check Worldpay IPN validity. |
|
| 261 | + */ |
|
| 262 | + public function validate_ipn() { |
|
| 263 | 263 | |
| 264 | 264 | wpinv_error_log( 'Validating Worldpay IPN response' ); |
| 265 | 265 | |
@@ -305,11 +305,11 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | - * Filters the gateway settings. |
|
| 309 | - * |
|
| 310 | - * @param array $admin_settings |
|
| 311 | - */ |
|
| 312 | - public function admin_settings( $admin_settings ) { |
|
| 308 | + * Filters the gateway settings. |
|
| 309 | + * |
|
| 310 | + * @param array $admin_settings |
|
| 311 | + */ |
|
| 312 | + public function admin_settings( $admin_settings ) { |
|
| 313 | 313 | |
| 314 | 314 | $currencies = sprintf( |
| 315 | 315 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | 'readonly' => true |
| 351 | 351 | ); |
| 352 | 352 | |
| 353 | - return $admin_settings; |
|
| 354 | - } |
|
| 353 | + return $admin_settings; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; // Exit if accessed directly |
|
| 10 | + exit; // Exit if accessed directly |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -15,22 +15,22 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class GetPaid_Meta_Box_Invoice_Shipping_Address { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Output the metabox. |
|
| 20 | - * |
|
| 21 | - * @param WP_Post $post |
|
| 22 | - */ |
|
| 23 | - public static function output( $post ) { |
|
| 18 | + /** |
|
| 19 | + * Output the metabox. |
|
| 20 | + * |
|
| 21 | + * @param WP_Post $post |
|
| 22 | + */ |
|
| 23 | + public static function output( $post ) { |
|
| 24 | 24 | |
| 25 | - // Retrieve shipping address. |
|
| 26 | - $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
| 25 | + // Retrieve shipping address. |
|
| 26 | + $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
| 27 | 27 | |
| 28 | - // Abort if it is invalid. |
|
| 29 | - if ( ! is_array( $shipping_address ) ) { |
|
| 30 | - return; |
|
| 31 | - } |
|
| 28 | + // Abort if it is invalid. |
|
| 29 | + if ( ! is_array( $shipping_address ) ) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - ?> |
|
| 33 | + ?> |
|
| 34 | 34 | |
| 35 | 35 | <div class="bsui"> |
| 36 | 36 | |
@@ -55,31 +55,31 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | <?php |
| 57 | 57 | |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Prepares a value. |
|
| 62 | - * |
|
| 63 | - * @param array $address |
|
| 64 | - * @param string $key |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public static function prepare_for_display( $address, $key ) { |
|
| 60 | + /** |
|
| 61 | + * Prepares a value. |
|
| 62 | + * |
|
| 63 | + * @param array $address |
|
| 64 | + * @param string $key |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public static function prepare_for_display( $address, $key ) { |
|
| 68 | 68 | |
| 69 | - // Prepare the value. |
|
| 70 | - $value = $address[ $key ]; |
|
| 69 | + // Prepare the value. |
|
| 70 | + $value = $address[ $key ]; |
|
| 71 | 71 | |
| 72 | - if ( $key == 'country' ) { |
|
| 73 | - $value = wpinv_country_name( $value ); |
|
| 74 | - } |
|
| 72 | + if ( $key == 'country' ) { |
|
| 73 | + $value = wpinv_country_name( $value ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - if ( $key == 'state' ) { |
|
| 77 | - $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
| 78 | - $value = wpinv_state_name( $value, $country ); |
|
| 79 | - } |
|
| 76 | + if ( $key == 'state' ) { |
|
| 77 | + $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
| 78 | + $value = wpinv_state_name( $value, $country ); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - return esc_html( $value ); |
|
| 81 | + return esc_html( $value ); |
|
| 82 | 82 | |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | } |
@@ -13,703 +13,703 @@ discard block |
||
| 13 | 13 | class GetPaid_Post_Types_Admin { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Hook in methods. |
|
| 17 | - */ |
|
| 18 | - public static function init() { |
|
| 19 | - |
|
| 20 | - // Init metaboxes. |
|
| 21 | - GetPaid_Metaboxes::init(); |
|
| 22 | - |
|
| 23 | - // Filter the post updated messages. |
|
| 24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | - |
|
| 26 | - // Filter post actions. |
|
| 27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
| 29 | - |
|
| 30 | - // Invoice table columns. |
|
| 31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
| 34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
| 35 | - |
|
| 36 | - // Items table columns. |
|
| 37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 43 | - |
|
| 44 | - // Payment forms columns. |
|
| 45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 48 | - |
|
| 49 | - // Discount table columns. |
|
| 50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 52 | - |
|
| 53 | - // Deleting posts. |
|
| 54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 56 | - |
|
| 57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Post updated messages. |
|
| 62 | - */ |
|
| 63 | - public static function post_updated_messages( $messages ) { |
|
| 64 | - global $post; |
|
| 65 | - |
|
| 66 | - $messages['wpi_discount'] = array( |
|
| 67 | - 0 => '', |
|
| 68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - $messages['wpi_payment_form'] = array( |
|
| 81 | - 0 => '', |
|
| 82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 92 | - ); |
|
| 93 | - |
|
| 94 | - return $messages; |
|
| 95 | - |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Post row actions. |
|
| 100 | - */ |
|
| 101 | - public static function post_row_actions( $actions, $post ) { |
|
| 102 | - |
|
| 103 | - $post = get_post( $post ); |
|
| 104 | - |
|
| 105 | - // We do not want to edit the default payment form. |
|
| 106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
| 107 | - |
|
| 108 | - if ( $post->ID == wpinv_get_default_payment_form() ) { |
|
| 109 | - unset( $actions['trash'] ); |
|
| 110 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $actions['duplicate'] = sprintf( |
|
| 114 | - '<a href="%1$s">%2$s</a>', |
|
| 115 | - esc_url( |
|
| 116 | - wp_nonce_url( |
|
| 117 | - add_query_arg( |
|
| 118 | - array( |
|
| 119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
| 120 | - 'form_id' => $post->ID |
|
| 121 | - ) |
|
| 122 | - ), |
|
| 123 | - 'getpaid-nonce', |
|
| 124 | - 'getpaid-nonce' |
|
| 125 | - ) |
|
| 126 | - ), |
|
| 127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 128 | - ); |
|
| 129 | - |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return $actions; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 16 | + * Hook in methods. |
|
| 17 | + */ |
|
| 18 | + public static function init() { |
|
| 19 | + |
|
| 20 | + // Init metaboxes. |
|
| 21 | + GetPaid_Metaboxes::init(); |
|
| 22 | + |
|
| 23 | + // Filter the post updated messages. |
|
| 24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | + |
|
| 26 | + // Filter post actions. |
|
| 27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
| 29 | + |
|
| 30 | + // Invoice table columns. |
|
| 31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
| 34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
| 35 | + |
|
| 36 | + // Items table columns. |
|
| 37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 43 | + |
|
| 44 | + // Payment forms columns. |
|
| 45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 48 | + |
|
| 49 | + // Discount table columns. |
|
| 50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 52 | + |
|
| 53 | + // Deleting posts. |
|
| 54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 56 | + |
|
| 57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Post updated messages. |
|
| 62 | + */ |
|
| 63 | + public static function post_updated_messages( $messages ) { |
|
| 64 | + global $post; |
|
| 65 | + |
|
| 66 | + $messages['wpi_discount'] = array( |
|
| 67 | + 0 => '', |
|
| 68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + $messages['wpi_payment_form'] = array( |
|
| 81 | + 0 => '', |
|
| 82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 92 | + ); |
|
| 93 | + |
|
| 94 | + return $messages; |
|
| 95 | + |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Post row actions. |
|
| 100 | + */ |
|
| 101 | + public static function post_row_actions( $actions, $post ) { |
|
| 102 | + |
|
| 103 | + $post = get_post( $post ); |
|
| 104 | + |
|
| 105 | + // We do not want to edit the default payment form. |
|
| 106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
| 107 | + |
|
| 108 | + if ( $post->ID == wpinv_get_default_payment_form() ) { |
|
| 109 | + unset( $actions['trash'] ); |
|
| 110 | + unset( $actions['inline hide-if-no-js'] ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $actions['duplicate'] = sprintf( |
|
| 114 | + '<a href="%1$s">%2$s</a>', |
|
| 115 | + esc_url( |
|
| 116 | + wp_nonce_url( |
|
| 117 | + add_query_arg( |
|
| 118 | + array( |
|
| 119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
| 120 | + 'form_id' => $post->ID |
|
| 121 | + ) |
|
| 122 | + ), |
|
| 123 | + 'getpaid-nonce', |
|
| 124 | + 'getpaid-nonce' |
|
| 125 | + ) |
|
| 126 | + ), |
|
| 127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 128 | + ); |
|
| 129 | + |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return $actions; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | 136 | * Remove bulk edit option from admin side quote listing |
| 137 | 137 | * |
| 138 | 138 | * @since 1.0.0 |
| 139 | 139 | * @param array $actions post actions |
| 140 | - * @param WP_Post $post |
|
| 140 | + * @param WP_Post $post |
|
| 141 | 141 | * @return array $actions actions without edit option |
| 142 | 142 | */ |
| 143 | 143 | public static function filter_invoice_row_actions( $actions, $post ) { |
| 144 | 144 | |
| 145 | 145 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
| 146 | 146 | |
| 147 | - $actions = array(); |
|
| 148 | - $invoice = new WPInv_Invoice( $post ); |
|
| 149 | - |
|
| 150 | - $actions['edit'] = sprintf( |
|
| 151 | - '<a href="%1$s">%2$s</a>', |
|
| 152 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
| 153 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
| 154 | - ); |
|
| 155 | - |
|
| 156 | - if ( ! $invoice->is_draft() ) { |
|
| 157 | - |
|
| 158 | - $actions['view'] = sprintf( |
|
| 159 | - '<a href="%1$s">%2$s</a>', |
|
| 160 | - esc_url( $invoice->get_view_url() ), |
|
| 161 | - sprintf( |
|
| 162 | - esc_html( __( 'View %s', 'invoicing' ) ), |
|
| 163 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
| 164 | - ) |
|
| 165 | - ); |
|
| 166 | - |
|
| 167 | - $actions['send'] = sprintf( |
|
| 168 | - '<a href="%1$s">%2$s</a>', |
|
| 169 | - esc_url( |
|
| 170 | - wp_nonce_url( |
|
| 171 | - add_query_arg( |
|
| 172 | - array( |
|
| 173 | - 'getpaid-admin-action' => 'send_invoice', |
|
| 174 | - 'invoice_id' => $invoice->get_id() |
|
| 175 | - ) |
|
| 176 | - ), |
|
| 177 | - 'getpaid-nonce', |
|
| 178 | - 'getpaid-nonce' |
|
| 179 | - ) |
|
| 180 | - ), |
|
| 181 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
| 182 | - ); |
|
| 183 | - |
|
| 184 | - } |
|
| 147 | + $actions = array(); |
|
| 148 | + $invoice = new WPInv_Invoice( $post ); |
|
| 149 | + |
|
| 150 | + $actions['edit'] = sprintf( |
|
| 151 | + '<a href="%1$s">%2$s</a>', |
|
| 152 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
| 153 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
| 154 | + ); |
|
| 155 | + |
|
| 156 | + if ( ! $invoice->is_draft() ) { |
|
| 157 | + |
|
| 158 | + $actions['view'] = sprintf( |
|
| 159 | + '<a href="%1$s">%2$s</a>', |
|
| 160 | + esc_url( $invoice->get_view_url() ), |
|
| 161 | + sprintf( |
|
| 162 | + esc_html( __( 'View %s', 'invoicing' ) ), |
|
| 163 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
| 164 | + ) |
|
| 165 | + ); |
|
| 166 | + |
|
| 167 | + $actions['send'] = sprintf( |
|
| 168 | + '<a href="%1$s">%2$s</a>', |
|
| 169 | + esc_url( |
|
| 170 | + wp_nonce_url( |
|
| 171 | + add_query_arg( |
|
| 172 | + array( |
|
| 173 | + 'getpaid-admin-action' => 'send_invoice', |
|
| 174 | + 'invoice_id' => $invoice->get_id() |
|
| 175 | + ) |
|
| 176 | + ), |
|
| 177 | + 'getpaid-nonce', |
|
| 178 | + 'getpaid-nonce' |
|
| 179 | + ) |
|
| 180 | + ), |
|
| 181 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
| 182 | + ); |
|
| 183 | + |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | return $actions; |
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Returns an array of invoice table columns. |
|
| 193 | - */ |
|
| 194 | - public static function invoice_columns( $columns ) { |
|
| 195 | - |
|
| 196 | - $columns = array( |
|
| 197 | - 'cb' => $columns['cb'], |
|
| 198 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
| 199 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 200 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
| 201 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
| 202 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 203 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 204 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 205 | - ); |
|
| 206 | - |
|
| 207 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Displays invoice table columns. |
|
| 212 | - */ |
|
| 213 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 214 | - |
|
| 215 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 216 | - |
|
| 217 | - switch ( $column_name ) { |
|
| 218 | - |
|
| 219 | - case 'invoice_date' : |
|
| 220 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 221 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
| 222 | - echo "<span title='$date_time'>$date</span>"; |
|
| 223 | - break; |
|
| 224 | - |
|
| 225 | - case 'payment_date' : |
|
| 226 | - |
|
| 227 | - if ( $invoice->is_paid() ) { |
|
| 228 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
| 229 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
| 230 | - echo "<span title='$date_time'>$date</span>"; |
|
| 231 | - } else { |
|
| 232 | - echo "—"; |
|
| 233 | - } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Returns an array of invoice table columns. |
|
| 193 | + */ |
|
| 194 | + public static function invoice_columns( $columns ) { |
|
| 195 | + |
|
| 196 | + $columns = array( |
|
| 197 | + 'cb' => $columns['cb'], |
|
| 198 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
| 199 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 200 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
| 201 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
| 202 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 203 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 204 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 205 | + ); |
|
| 206 | + |
|
| 207 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Displays invoice table columns. |
|
| 212 | + */ |
|
| 213 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 214 | + |
|
| 215 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 216 | + |
|
| 217 | + switch ( $column_name ) { |
|
| 218 | + |
|
| 219 | + case 'invoice_date' : |
|
| 220 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 221 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
| 222 | + echo "<span title='$date_time'>$date</span>"; |
|
| 223 | + break; |
|
| 224 | + |
|
| 225 | + case 'payment_date' : |
|
| 226 | + |
|
| 227 | + if ( $invoice->is_paid() ) { |
|
| 228 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
| 229 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
| 230 | + echo "<span title='$date_time'>$date</span>"; |
|
| 231 | + } else { |
|
| 232 | + echo "—"; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - break; |
|
| 235 | + break; |
|
| 236 | 236 | |
| 237 | - case 'amount' : |
|
| 237 | + case 'amount' : |
|
| 238 | 238 | |
| 239 | - $amount = $invoice->get_total(); |
|
| 240 | - $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
| 239 | + $amount = $invoice->get_total(); |
|
| 240 | + $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
| 241 | 241 | |
| 242 | - if ( $invoice->is_refunded() ) { |
|
| 243 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
| 244 | - echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
| 245 | - } else { |
|
| 242 | + if ( $invoice->is_refunded() ) { |
|
| 243 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
| 244 | + echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
| 245 | + } else { |
|
| 246 | 246 | |
| 247 | - $discount = $invoice->get_total_discount(); |
|
| 247 | + $discount = $invoice->get_total_discount(); |
|
| 248 | 248 | |
| 249 | - if ( ! empty( $discount ) ) { |
|
| 250 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
| 251 | - echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
| 252 | - } else { |
|
| 253 | - echo $formated_amount; |
|
| 254 | - } |
|
| 249 | + if ( ! empty( $discount ) ) { |
|
| 250 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
| 251 | + echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
| 252 | + } else { |
|
| 253 | + echo $formated_amount; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - } |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - break; |
|
| 258 | + break; |
|
| 259 | 259 | |
| 260 | - case 'status' : |
|
| 261 | - $status = esc_html( $invoice->get_status() ); |
|
| 262 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
| 260 | + case 'status' : |
|
| 261 | + $status = esc_html( $invoice->get_status() ); |
|
| 262 | + $status_label = esc_html( $invoice->get_status_nicename() ); |
|
| 263 | 263 | |
| 264 | - // If it is paid, show the gateway title. |
|
| 265 | - if ( $invoice->is_paid() ) { |
|
| 266 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
| 267 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 264 | + // If it is paid, show the gateway title. |
|
| 265 | + if ( $invoice->is_paid() ) { |
|
| 266 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
| 267 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 268 | 268 | |
| 269 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
| 270 | - } else { |
|
| 271 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
| 272 | - } |
|
| 269 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
| 270 | + } else { |
|
| 271 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - // If it is not paid, display the overdue and view status. |
|
| 275 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 274 | + // If it is not paid, display the overdue and view status. |
|
| 275 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 276 | 276 | |
| 277 | - // Invoice view status. |
|
| 278 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 279 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 280 | - } else { |
|
| 281 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 282 | - } |
|
| 277 | + // Invoice view status. |
|
| 278 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 279 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 280 | + } else { |
|
| 281 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - // Display the overview status. |
|
| 285 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 286 | - $due_date = $invoice->get_due_date(); |
|
| 287 | - $fomatted = getpaid_format_date( $due_date ); |
|
| 284 | + // Display the overview status. |
|
| 285 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 286 | + $due_date = $invoice->get_due_date(); |
|
| 287 | + $fomatted = getpaid_format_date( $due_date ); |
|
| 288 | 288 | |
| 289 | - if ( ! empty( $fomatted ) ) { |
|
| 290 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
| 291 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
| 292 | - } |
|
| 293 | - } |
|
| 289 | + if ( ! empty( $fomatted ) ) { |
|
| 290 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
| 291 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - break; |
|
| 297 | + break; |
|
| 298 | 298 | |
| 299 | - case 'recurring': |
|
| 299 | + case 'recurring': |
|
| 300 | 300 | |
| 301 | - if ( $invoice->is_recurring() ) { |
|
| 302 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 303 | - } else { |
|
| 304 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 305 | - } |
|
| 306 | - break; |
|
| 301 | + if ( $invoice->is_recurring() ) { |
|
| 302 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 303 | + } else { |
|
| 304 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 305 | + } |
|
| 306 | + break; |
|
| 307 | 307 | |
| 308 | - case 'number' : |
|
| 308 | + case 'number' : |
|
| 309 | 309 | |
| 310 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 311 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
| 312 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 310 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 311 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
| 312 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 313 | 313 | |
| 314 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
| 314 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
| 315 | 315 | |
| 316 | - break; |
|
| 316 | + break; |
|
| 317 | 317 | |
| 318 | - case 'customer' : |
|
| 318 | + case 'customer' : |
|
| 319 | 319 | |
| 320 | - $customer_name = $invoice->get_user_full_name(); |
|
| 320 | + $customer_name = $invoice->get_user_full_name(); |
|
| 321 | 321 | |
| 322 | - if ( empty( $customer_name ) ) { |
|
| 323 | - $customer_name = $invoice->get_email(); |
|
| 324 | - } |
|
| 322 | + if ( empty( $customer_name ) ) { |
|
| 323 | + $customer_name = $invoice->get_email(); |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - if ( ! empty( $customer_name ) ) { |
|
| 327 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 328 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 329 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
| 330 | - } else { |
|
| 331 | - echo '<div>—</div>'; |
|
| 332 | - } |
|
| 326 | + if ( ! empty( $customer_name ) ) { |
|
| 327 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 328 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 329 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
| 330 | + } else { |
|
| 331 | + echo '<div>—</div>'; |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - break; |
|
| 334 | + break; |
|
| 335 | 335 | |
| 336 | - } |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | - } |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - /** |
|
| 341 | - * Displays invoice bulk actions. |
|
| 342 | - */ |
|
| 343 | - public static function invoice_bulk_actions( $actions ) { |
|
| 344 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
| 345 | - return $actions; |
|
| 346 | - } |
|
| 340 | + /** |
|
| 341 | + * Displays invoice bulk actions. |
|
| 342 | + */ |
|
| 343 | + public static function invoice_bulk_actions( $actions ) { |
|
| 344 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
| 345 | + return $actions; |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - /** |
|
| 349 | - * Processes invoice bulk actions. |
|
| 350 | - */ |
|
| 351 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
| 348 | + /** |
|
| 349 | + * Processes invoice bulk actions. |
|
| 350 | + */ |
|
| 351 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
| 352 | 352 | |
| 353 | - if ( $action == 'resend-invoice' ) { |
|
| 353 | + if ( $action == 'resend-invoice' ) { |
|
| 354 | 354 | |
| 355 | - $success = false; |
|
| 356 | - foreach ( $post_ids as $post_id ) { |
|
| 357 | - $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
| 358 | - } |
|
| 355 | + $success = false; |
|
| 356 | + foreach ( $post_ids as $post_id ) { |
|
| 357 | + $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - if ( $success ) { |
|
| 361 | - getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) ); |
|
| 362 | - } else { |
|
| 363 | - getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) ); |
|
| 364 | - } |
|
| 360 | + if ( $success ) { |
|
| 361 | + getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) ); |
|
| 362 | + } else { |
|
| 363 | + getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) ); |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - return $redirect_url; |
|
| 368 | + return $redirect_url; |
|
| 369 | 369 | |
| 370 | - } |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | - /** |
|
| 373 | - * Returns an array of payment forms table columns. |
|
| 374 | - */ |
|
| 375 | - public static function payment_form_columns( $columns ) { |
|
| 372 | + /** |
|
| 373 | + * Returns an array of payment forms table columns. |
|
| 374 | + */ |
|
| 375 | + public static function payment_form_columns( $columns ) { |
|
| 376 | 376 | |
| 377 | - $columns = array( |
|
| 378 | - 'cb' => $columns['cb'], |
|
| 379 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 380 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 381 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 382 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 383 | - 'items' => __( 'Items', 'invoicing' ), |
|
| 384 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 385 | - ); |
|
| 377 | + $columns = array( |
|
| 378 | + 'cb' => $columns['cb'], |
|
| 379 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 380 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 381 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 382 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 383 | + 'items' => __( 'Items', 'invoicing' ), |
|
| 384 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 385 | + ); |
|
| 386 | 386 | |
| 387 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 387 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 388 | 388 | |
| 389 | - } |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | - /** |
|
| 392 | - * Displays payment form table columns. |
|
| 393 | - */ |
|
| 394 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 391 | + /** |
|
| 392 | + * Displays payment form table columns. |
|
| 393 | + */ |
|
| 394 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 395 | 395 | |
| 396 | - // Retrieve the payment form. |
|
| 397 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
| 396 | + // Retrieve the payment form. |
|
| 397 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
| 398 | 398 | |
| 399 | - switch ( $column_name ) { |
|
| 399 | + switch ( $column_name ) { |
|
| 400 | 400 | |
| 401 | - case 'earnings' : |
|
| 402 | - echo wpinv_price( $form->get_earned() ); |
|
| 403 | - break; |
|
| 401 | + case 'earnings' : |
|
| 402 | + echo wpinv_price( $form->get_earned() ); |
|
| 403 | + break; |
|
| 404 | 404 | |
| 405 | - case 'refunds' : |
|
| 406 | - echo wpinv_price( $form->get_refunded() ); |
|
| 407 | - break; |
|
| 405 | + case 'refunds' : |
|
| 406 | + echo wpinv_price( $form->get_refunded() ); |
|
| 407 | + break; |
|
| 408 | 408 | |
| 409 | - case 'refunds' : |
|
| 410 | - echo wpinv_price( $form->get_refunded() ); |
|
| 411 | - break; |
|
| 409 | + case 'refunds' : |
|
| 410 | + echo wpinv_price( $form->get_refunded() ); |
|
| 411 | + break; |
|
| 412 | 412 | |
| 413 | - case 'shortcode' : |
|
| 413 | + case 'shortcode' : |
|
| 414 | 414 | |
| 415 | - if ( $form->is_default() ) { |
|
| 416 | - echo '—'; |
|
| 417 | - } else { |
|
| 418 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 419 | - } |
|
| 415 | + if ( $form->is_default() ) { |
|
| 416 | + echo '—'; |
|
| 417 | + } else { |
|
| 418 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - break; |
|
| 421 | + break; |
|
| 422 | 422 | |
| 423 | - case 'items' : |
|
| 423 | + case 'items' : |
|
| 424 | 424 | |
| 425 | - $items = $form->get_items(); |
|
| 425 | + $items = $form->get_items(); |
|
| 426 | 426 | |
| 427 | - if ( $form->is_default() || empty( $items ) ) { |
|
| 428 | - echo '—'; |
|
| 429 | - return; |
|
| 430 | - } |
|
| 427 | + if ( $form->is_default() || empty( $items ) ) { |
|
| 428 | + echo '—'; |
|
| 429 | + return; |
|
| 430 | + } |
|
| 431 | 431 | |
| 432 | - $_items = array(); |
|
| 432 | + $_items = array(); |
|
| 433 | 433 | |
| 434 | - foreach ( $items as $item ) { |
|
| 435 | - $url = $item->get_edit_url(); |
|
| 434 | + foreach ( $items as $item ) { |
|
| 435 | + $url = $item->get_edit_url(); |
|
| 436 | 436 | |
| 437 | - if ( empty( $url ) ) { |
|
| 438 | - $_items[] = esc_html( $item->get_name() ); |
|
| 439 | - } else { |
|
| 440 | - $_items[] = sprintf( |
|
| 441 | - '<a href="%s">%s</a>', |
|
| 442 | - esc_url( $url ), |
|
| 443 | - esc_html( $item->get_name() ) |
|
| 444 | - ); |
|
| 445 | - } |
|
| 437 | + if ( empty( $url ) ) { |
|
| 438 | + $_items[] = esc_html( $item->get_name() ); |
|
| 439 | + } else { |
|
| 440 | + $_items[] = sprintf( |
|
| 441 | + '<a href="%s">%s</a>', |
|
| 442 | + esc_url( $url ), |
|
| 443 | + esc_html( $item->get_name() ) |
|
| 444 | + ); |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - } |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - echo implode( '<br>', $_items ); |
|
| 449 | + echo implode( '<br>', $_items ); |
|
| 450 | 450 | |
| 451 | - break; |
|
| 451 | + break; |
|
| 452 | 452 | |
| 453 | - } |
|
| 453 | + } |
|
| 454 | 454 | |
| 455 | - } |
|
| 455 | + } |
|
| 456 | 456 | |
| 457 | - /** |
|
| 458 | - * Filters post states. |
|
| 459 | - */ |
|
| 460 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
| 457 | + /** |
|
| 458 | + * Filters post states. |
|
| 459 | + */ |
|
| 460 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
| 461 | 461 | |
| 462 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
| 463 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
| 464 | - } |
|
| 462 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
| 463 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - return $post_states; |
|
| 467 | - |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Returns an array of coupon table columns. |
|
| 472 | - */ |
|
| 473 | - public static function discount_columns( $columns ) { |
|
| 474 | - |
|
| 475 | - $columns = array( |
|
| 476 | - 'cb' => $columns['cb'], |
|
| 477 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 478 | - 'code' => __( 'Code', 'invoicing' ), |
|
| 479 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 480 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 481 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 482 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 483 | - ); |
|
| 484 | - |
|
| 485 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * Filters post states. |
|
| 490 | - */ |
|
| 491 | - public static function filter_discount_state( $post_states, $post ) { |
|
| 492 | - |
|
| 493 | - if ( 'wpi_discount' == $post->post_type ) { |
|
| 494 | - |
|
| 495 | - $discount = new WPInv_Discount( $post ); |
|
| 496 | - |
|
| 497 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 498 | - |
|
| 499 | - if ( $status != 'publish' ) { |
|
| 500 | - return array( |
|
| 501 | - 'discount_status' => wpinv_discount_status( $status ), |
|
| 502 | - ); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - return array(); |
|
| 506 | - |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - return $post_states; |
|
| 510 | - |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Returns an array of items table columns. |
|
| 515 | - */ |
|
| 516 | - public static function item_columns( $columns ) { |
|
| 517 | - |
|
| 518 | - $columns = array( |
|
| 519 | - 'cb' => $columns['cb'], |
|
| 520 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 521 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 522 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
| 523 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
| 524 | - 'type' => __( 'Type', 'invoicing' ), |
|
| 525 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 526 | - ); |
|
| 527 | - |
|
| 528 | - if ( ! wpinv_use_taxes() ) { |
|
| 529 | - unset( $columns['vat_rule'] ); |
|
| 530 | - unset( $columns['vat_class'] ); |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Returns an array of sortable items table columns. |
|
| 538 | - */ |
|
| 539 | - public static function sortable_item_columns( $columns ) { |
|
| 540 | - |
|
| 541 | - return array_merge( |
|
| 542 | - $columns, |
|
| 543 | - array( |
|
| 544 | - 'price' => 'price', |
|
| 545 | - 'vat_rule' => 'vat_rule', |
|
| 546 | - 'vat_class' => 'vat_class', |
|
| 547 | - 'type' => 'type', |
|
| 548 | - ) |
|
| 549 | - ); |
|
| 550 | - |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * Displays items table columns. |
|
| 555 | - */ |
|
| 556 | - public static function display_item_columns( $column_name, $post_id ) { |
|
| 466 | + return $post_states; |
|
| 467 | + |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Returns an array of coupon table columns. |
|
| 472 | + */ |
|
| 473 | + public static function discount_columns( $columns ) { |
|
| 474 | + |
|
| 475 | + $columns = array( |
|
| 476 | + 'cb' => $columns['cb'], |
|
| 477 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 478 | + 'code' => __( 'Code', 'invoicing' ), |
|
| 479 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 480 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 481 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 482 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 483 | + ); |
|
| 484 | + |
|
| 485 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * Filters post states. |
|
| 490 | + */ |
|
| 491 | + public static function filter_discount_state( $post_states, $post ) { |
|
| 492 | + |
|
| 493 | + if ( 'wpi_discount' == $post->post_type ) { |
|
| 494 | + |
|
| 495 | + $discount = new WPInv_Discount( $post ); |
|
| 496 | + |
|
| 497 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 498 | + |
|
| 499 | + if ( $status != 'publish' ) { |
|
| 500 | + return array( |
|
| 501 | + 'discount_status' => wpinv_discount_status( $status ), |
|
| 502 | + ); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + return array(); |
|
| 506 | + |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + return $post_states; |
|
| 510 | + |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Returns an array of items table columns. |
|
| 515 | + */ |
|
| 516 | + public static function item_columns( $columns ) { |
|
| 517 | + |
|
| 518 | + $columns = array( |
|
| 519 | + 'cb' => $columns['cb'], |
|
| 520 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 521 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 522 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
| 523 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
| 524 | + 'type' => __( 'Type', 'invoicing' ), |
|
| 525 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 526 | + ); |
|
| 527 | + |
|
| 528 | + if ( ! wpinv_use_taxes() ) { |
|
| 529 | + unset( $columns['vat_rule'] ); |
|
| 530 | + unset( $columns['vat_class'] ); |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Returns an array of sortable items table columns. |
|
| 538 | + */ |
|
| 539 | + public static function sortable_item_columns( $columns ) { |
|
| 540 | + |
|
| 541 | + return array_merge( |
|
| 542 | + $columns, |
|
| 543 | + array( |
|
| 544 | + 'price' => 'price', |
|
| 545 | + 'vat_rule' => 'vat_rule', |
|
| 546 | + 'vat_class' => 'vat_class', |
|
| 547 | + 'type' => 'type', |
|
| 548 | + ) |
|
| 549 | + ); |
|
| 550 | + |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * Displays items table columns. |
|
| 555 | + */ |
|
| 556 | + public static function display_item_columns( $column_name, $post_id ) { |
|
| 557 | 557 | |
| 558 | - $item = new WPInv_Item( $post_id ); |
|
| 558 | + $item = new WPInv_Item( $post_id ); |
|
| 559 | 559 | |
| 560 | - switch ( $column_name ) { |
|
| 560 | + switch ( $column_name ) { |
|
| 561 | 561 | |
| 562 | - case 'price' : |
|
| 562 | + case 'price' : |
|
| 563 | 563 | |
| 564 | - if ( ! $item->is_recurring() ) { |
|
| 565 | - echo $item->get_the_price(); |
|
| 566 | - break; |
|
| 567 | - } |
|
| 564 | + if ( ! $item->is_recurring() ) { |
|
| 565 | + echo $item->get_the_price(); |
|
| 566 | + break; |
|
| 567 | + } |
|
| 568 | 568 | |
| 569 | - $price = wp_sprintf( |
|
| 570 | - __( '%s / %s', 'invoicing' ), |
|
| 571 | - $item->get_the_price(), |
|
| 572 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 573 | - ); |
|
| 569 | + $price = wp_sprintf( |
|
| 570 | + __( '%s / %s', 'invoicing' ), |
|
| 571 | + $item->get_the_price(), |
|
| 572 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 573 | + ); |
|
| 574 | 574 | |
| 575 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 576 | - echo $price; |
|
| 577 | - break; |
|
| 578 | - } |
|
| 575 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 576 | + echo $price; |
|
| 577 | + break; |
|
| 578 | + } |
|
| 579 | 579 | |
| 580 | - echo $item->get_the_initial_price(); |
|
| 580 | + echo $item->get_the_initial_price(); |
|
| 581 | 581 | |
| 582 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
| 583 | - break; |
|
| 582 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
| 583 | + break; |
|
| 584 | 584 | |
| 585 | - case 'vat_rule' : |
|
| 586 | - echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
| 587 | - break; |
|
| 585 | + case 'vat_rule' : |
|
| 586 | + echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
| 587 | + break; |
|
| 588 | 588 | |
| 589 | - case 'vat_class' : |
|
| 590 | - echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
| 591 | - break; |
|
| 589 | + case 'vat_class' : |
|
| 590 | + echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
| 591 | + break; |
|
| 592 | 592 | |
| 593 | - case 'shortcode' : |
|
| 594 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 595 | - break; |
|
| 593 | + case 'shortcode' : |
|
| 594 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 595 | + break; |
|
| 596 | 596 | |
| 597 | - case 'type' : |
|
| 598 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 599 | - break; |
|
| 597 | + case 'type' : |
|
| 598 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 599 | + break; |
|
| 600 | 600 | |
| 601 | - } |
|
| 601 | + } |
|
| 602 | 602 | |
| 603 | - } |
|
| 603 | + } |
|
| 604 | 604 | |
| 605 | - /** |
|
| 606 | - * Lets users filter items using taxes. |
|
| 607 | - */ |
|
| 608 | - public static function add_item_filters( $post_type ) { |
|
| 605 | + /** |
|
| 606 | + * Lets users filter items using taxes. |
|
| 607 | + */ |
|
| 608 | + public static function add_item_filters( $post_type ) { |
|
| 609 | 609 | |
| 610 | - // Abort if we're not dealing with items. |
|
| 611 | - if ( $post_type != 'wpi_item' ) { |
|
| 612 | - return; |
|
| 613 | - } |
|
| 610 | + // Abort if we're not dealing with items. |
|
| 611 | + if ( $post_type != 'wpi_item' ) { |
|
| 612 | + return; |
|
| 613 | + } |
|
| 614 | 614 | |
| 615 | - // Filter by vat rules. |
|
| 616 | - if ( wpinv_use_taxes() ) { |
|
| 615 | + // Filter by vat rules. |
|
| 616 | + if ( wpinv_use_taxes() ) { |
|
| 617 | 617 | |
| 618 | - // Sanitize selected vat rule. |
|
| 619 | - $vat_rule = ''; |
|
| 620 | - $vat_rules = getpaid_get_tax_rules(); |
|
| 621 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
| 622 | - $vat_rule = $_GET['vat_rule']; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - // Filter by VAT rule. |
|
| 626 | - echo wpinv_html_select( |
|
| 627 | - array( |
|
| 628 | - 'options' => array_merge( |
|
| 629 | - array( |
|
| 630 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
| 631 | - ), |
|
| 632 | - $vat_rules |
|
| 633 | - ), |
|
| 634 | - 'name' => 'vat_rule', |
|
| 635 | - 'id' => 'vat_rule', |
|
| 636 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
| 637 | - 'show_option_all' => false, |
|
| 638 | - 'show_option_none' => false, |
|
| 639 | - ) |
|
| 640 | - ); |
|
| 641 | - |
|
| 642 | - // Filter by VAT class. |
|
| 618 | + // Sanitize selected vat rule. |
|
| 619 | + $vat_rule = ''; |
|
| 620 | + $vat_rules = getpaid_get_tax_rules(); |
|
| 621 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
| 622 | + $vat_rule = $_GET['vat_rule']; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + // Filter by VAT rule. |
|
| 626 | + echo wpinv_html_select( |
|
| 627 | + array( |
|
| 628 | + 'options' => array_merge( |
|
| 629 | + array( |
|
| 630 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
| 631 | + ), |
|
| 632 | + $vat_rules |
|
| 633 | + ), |
|
| 634 | + 'name' => 'vat_rule', |
|
| 635 | + 'id' => 'vat_rule', |
|
| 636 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
| 637 | + 'show_option_all' => false, |
|
| 638 | + 'show_option_none' => false, |
|
| 639 | + ) |
|
| 640 | + ); |
|
| 641 | + |
|
| 642 | + // Filter by VAT class. |
|
| 643 | 643 | |
| 644 | - // Sanitize selected vat rule. |
|
| 645 | - $vat_class = ''; |
|
| 646 | - $vat_classes = getpaid_get_tax_classes(); |
|
| 647 | - if ( isset( $_GET['vat_class'] ) ) { |
|
| 648 | - $vat_class = $_GET['vat_class']; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - echo wpinv_html_select( |
|
| 652 | - array( |
|
| 653 | - 'options' => array_merge( |
|
| 654 | - array( |
|
| 655 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
| 656 | - ), |
|
| 657 | - $vat_classes |
|
| 658 | - ), |
|
| 659 | - 'name' => 'vat_class', |
|
| 660 | - 'id' => 'vat_class', |
|
| 661 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
| 662 | - 'show_option_all' => false, |
|
| 663 | - 'show_option_none' => false, |
|
| 664 | - ) |
|
| 665 | - ); |
|
| 666 | - |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - // Filter by item type. |
|
| 670 | - $type = ''; |
|
| 671 | - if ( isset( $_GET['type'] ) ) { |
|
| 672 | - $type = $_GET['type']; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - echo wpinv_html_select( |
|
| 676 | - array( |
|
| 677 | - 'options' => array_merge( |
|
| 678 | - array( |
|
| 679 | - '' => __( 'All item types', 'invoicing' ) |
|
| 680 | - ), |
|
| 681 | - wpinv_get_item_types() |
|
| 682 | - ), |
|
| 683 | - 'name' => 'type', |
|
| 684 | - 'id' => 'type', |
|
| 685 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
| 686 | - 'show_option_all' => false, |
|
| 687 | - 'show_option_none' => false, |
|
| 688 | - ) |
|
| 689 | - ); |
|
| 690 | - |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Filters the item query. |
|
| 695 | - */ |
|
| 696 | - public static function filter_item_query( $query ) { |
|
| 697 | - |
|
| 698 | - // modify the query only if it admin and main query. |
|
| 699 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
| 700 | - return $query; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - // we want to modify the query for our items. |
|
| 704 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
| 705 | - return $query; |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 709 | - $query->query_vars['meta_query'] = array(); |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - // Filter vat rule type |
|
| 644 | + // Sanitize selected vat rule. |
|
| 645 | + $vat_class = ''; |
|
| 646 | + $vat_classes = getpaid_get_tax_classes(); |
|
| 647 | + if ( isset( $_GET['vat_class'] ) ) { |
|
| 648 | + $vat_class = $_GET['vat_class']; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + echo wpinv_html_select( |
|
| 652 | + array( |
|
| 653 | + 'options' => array_merge( |
|
| 654 | + array( |
|
| 655 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
| 656 | + ), |
|
| 657 | + $vat_classes |
|
| 658 | + ), |
|
| 659 | + 'name' => 'vat_class', |
|
| 660 | + 'id' => 'vat_class', |
|
| 661 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
| 662 | + 'show_option_all' => false, |
|
| 663 | + 'show_option_none' => false, |
|
| 664 | + ) |
|
| 665 | + ); |
|
| 666 | + |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + // Filter by item type. |
|
| 670 | + $type = ''; |
|
| 671 | + if ( isset( $_GET['type'] ) ) { |
|
| 672 | + $type = $_GET['type']; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + echo wpinv_html_select( |
|
| 676 | + array( |
|
| 677 | + 'options' => array_merge( |
|
| 678 | + array( |
|
| 679 | + '' => __( 'All item types', 'invoicing' ) |
|
| 680 | + ), |
|
| 681 | + wpinv_get_item_types() |
|
| 682 | + ), |
|
| 683 | + 'name' => 'type', |
|
| 684 | + 'id' => 'type', |
|
| 685 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
| 686 | + 'show_option_all' => false, |
|
| 687 | + 'show_option_none' => false, |
|
| 688 | + ) |
|
| 689 | + ); |
|
| 690 | + |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Filters the item query. |
|
| 695 | + */ |
|
| 696 | + public static function filter_item_query( $query ) { |
|
| 697 | + |
|
| 698 | + // modify the query only if it admin and main query. |
|
| 699 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
| 700 | + return $query; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + // we want to modify the query for our items. |
|
| 704 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
| 705 | + return $query; |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 709 | + $query->query_vars['meta_query'] = array(); |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + // Filter vat rule type |
|
| 713 | 713 | if ( ! empty( $_GET['vat_rule'] ) ) { |
| 714 | 714 | $query->query_vars['meta_query'][] = array( |
| 715 | 715 | 'key' => '_wpinv_vat_rule', |
@@ -734,97 +734,97 @@ discard block |
||
| 734 | 734 | 'value' => sanitize_text_field( $_GET['type'] ), |
| 735 | 735 | 'compare' => '=' |
| 736 | 736 | ); |
| 737 | - } |
|
| 738 | - |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * Reorders items. |
|
| 743 | - */ |
|
| 744 | - public static function reorder_items( $vars ) { |
|
| 745 | - global $typenow; |
|
| 746 | - |
|
| 747 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 748 | - return $vars; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - // By item type. |
|
| 752 | - if ( 'type' == $vars['orderby'] ) { |
|
| 753 | - return array_merge( |
|
| 754 | - $vars, |
|
| 755 | - array( |
|
| 756 | - 'meta_key' => '_wpinv_type', |
|
| 757 | - 'orderby' => 'meta_value' |
|
| 758 | - ) |
|
| 759 | - ); |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - // By vat class. |
|
| 763 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
| 764 | - return array_merge( |
|
| 765 | - $vars, |
|
| 766 | - array( |
|
| 767 | - 'meta_key' => '_wpinv_vat_class', |
|
| 768 | - 'orderby' => 'meta_value' |
|
| 769 | - ) |
|
| 770 | - ); |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - // By vat rule. |
|
| 774 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
| 775 | - return array_merge( |
|
| 776 | - $vars, |
|
| 777 | - array( |
|
| 778 | - 'meta_key' => '_wpinv_vat_rule', |
|
| 779 | - 'orderby' => 'meta_value' |
|
| 780 | - ) |
|
| 781 | - ); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - // By price. |
|
| 785 | - if ( 'price' == $vars['orderby'] ) { |
|
| 786 | - return array_merge( |
|
| 787 | - $vars, |
|
| 788 | - array( |
|
| 789 | - 'meta_key' => '_wpinv_price', |
|
| 790 | - 'orderby' => 'meta_value_num' |
|
| 791 | - ) |
|
| 792 | - ); |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - return $vars; |
|
| 796 | - |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * Fired when deleting a post. |
|
| 801 | - */ |
|
| 802 | - public static function delete_post( $post_id ) { |
|
| 803 | - |
|
| 804 | - switch ( get_post_type( $post_id ) ) { |
|
| 805 | - |
|
| 806 | - case 'wpi_item' : |
|
| 807 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
| 808 | - break; |
|
| 809 | - |
|
| 810 | - case 'wpi_payment_form' : |
|
| 811 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
| 812 | - break; |
|
| 813 | - |
|
| 814 | - case 'wpi_discount' : |
|
| 815 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
| 816 | - break; |
|
| 817 | - |
|
| 818 | - case 'wpi_invoice' : |
|
| 819 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 820 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
| 821 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
| 822 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 823 | - break; |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - /** |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * Reorders items. |
|
| 743 | + */ |
|
| 744 | + public static function reorder_items( $vars ) { |
|
| 745 | + global $typenow; |
|
| 746 | + |
|
| 747 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 748 | + return $vars; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + // By item type. |
|
| 752 | + if ( 'type' == $vars['orderby'] ) { |
|
| 753 | + return array_merge( |
|
| 754 | + $vars, |
|
| 755 | + array( |
|
| 756 | + 'meta_key' => '_wpinv_type', |
|
| 757 | + 'orderby' => 'meta_value' |
|
| 758 | + ) |
|
| 759 | + ); |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + // By vat class. |
|
| 763 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
| 764 | + return array_merge( |
|
| 765 | + $vars, |
|
| 766 | + array( |
|
| 767 | + 'meta_key' => '_wpinv_vat_class', |
|
| 768 | + 'orderby' => 'meta_value' |
|
| 769 | + ) |
|
| 770 | + ); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + // By vat rule. |
|
| 774 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
| 775 | + return array_merge( |
|
| 776 | + $vars, |
|
| 777 | + array( |
|
| 778 | + 'meta_key' => '_wpinv_vat_rule', |
|
| 779 | + 'orderby' => 'meta_value' |
|
| 780 | + ) |
|
| 781 | + ); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + // By price. |
|
| 785 | + if ( 'price' == $vars['orderby'] ) { |
|
| 786 | + return array_merge( |
|
| 787 | + $vars, |
|
| 788 | + array( |
|
| 789 | + 'meta_key' => '_wpinv_price', |
|
| 790 | + 'orderby' => 'meta_value_num' |
|
| 791 | + ) |
|
| 792 | + ); |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + return $vars; |
|
| 796 | + |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * Fired when deleting a post. |
|
| 801 | + */ |
|
| 802 | + public static function delete_post( $post_id ) { |
|
| 803 | + |
|
| 804 | + switch ( get_post_type( $post_id ) ) { |
|
| 805 | + |
|
| 806 | + case 'wpi_item' : |
|
| 807 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
| 808 | + break; |
|
| 809 | + |
|
| 810 | + case 'wpi_payment_form' : |
|
| 811 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
| 812 | + break; |
|
| 813 | + |
|
| 814 | + case 'wpi_discount' : |
|
| 815 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
| 816 | + break; |
|
| 817 | + |
|
| 818 | + case 'wpi_invoice' : |
|
| 819 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 820 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
| 821 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
| 822 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 823 | + break; |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | 828 | * Add a post display state for special GetPaid pages in the page list table. |
| 829 | 829 | * |
| 830 | 830 | * @param array $post_states An array of post display states. |
@@ -838,22 +838,22 @@ discard block |
||
| 838 | 838 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
| 839 | 839 | } |
| 840 | 840 | |
| 841 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
| 841 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
| 842 | 842 | |
| 843 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
| 844 | - $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
|
| 845 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
| 846 | - $label |
|
| 847 | - ); |
|
| 848 | - } |
|
| 843 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
| 844 | + $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
|
| 845 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
| 846 | + $label |
|
| 847 | + ); |
|
| 848 | + } |
|
| 849 | 849 | |
| 850 | - } |
|
| 850 | + } |
|
| 851 | 851 | |
| 852 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
| 852 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
| 853 | 853 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
| 854 | 854 | } |
| 855 | 855 | |
| 856 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
| 856 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
| 857 | 857 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
| 858 | 858 | } |
| 859 | 859 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | // Load WP_List_Table if not loaded |
| 11 | 11 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 12 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 12 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -21,367 +21,367 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class WPInv_Customers_Table extends WP_List_Table { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var int Number of items per page |
|
| 26 | - * @since 1.0.19 |
|
| 27 | - */ |
|
| 28 | - public $per_page = 10; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var int Number of items |
|
| 32 | - * @since 1.0.19 |
|
| 33 | - */ |
|
| 34 | - public $total = 0; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Get things started |
|
| 38 | - * |
|
| 39 | - * @since 1.0.19 |
|
| 40 | - * @see WP_List_Table::__construct() |
|
| 41 | - */ |
|
| 42 | - public function __construct() { |
|
| 43 | - |
|
| 44 | - // Set parent defaults |
|
| 45 | - parent::__construct( array( |
|
| 46 | - 'singular' => 'id', |
|
| 47 | - 'plural' => 'ids', |
|
| 48 | - 'ajax' => false, |
|
| 49 | - ) ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Gets the name of the primary column. |
|
| 55 | - * |
|
| 56 | - * @since 1.0.19 |
|
| 57 | - * @access protected |
|
| 58 | - * |
|
| 59 | - * @return string Name of the primary column. |
|
| 60 | - */ |
|
| 61 | - protected function get_primary_column_name() { |
|
| 62 | - return 'name'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * This function renders most of the columns in the list table. |
|
| 67 | - * |
|
| 68 | - * @since 1.0.19 |
|
| 69 | - * |
|
| 70 | - * @param WP_User $item |
|
| 71 | - * @param string $column_name The name of the column |
|
| 72 | - * |
|
| 73 | - * @return string Column Name |
|
| 74 | - */ |
|
| 75 | - public function column_default( $item, $column_name ) { |
|
| 76 | - $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Displays the country column. |
|
| 82 | - * |
|
| 83 | - * @since 1.0.19 |
|
| 84 | - * |
|
| 85 | - * @param WP_User $user |
|
| 86 | - * |
|
| 87 | - * @return string Column Name |
|
| 88 | - */ |
|
| 89 | - public function column_country( $user ) { |
|
| 90 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | - if ( $country ) { |
|
| 92 | - $country = wpinv_country_name( $country ); |
|
| 93 | - } |
|
| 94 | - return esc_html( $country ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Displays the state column. |
|
| 99 | - * |
|
| 100 | - * @since 1.0.19 |
|
| 101 | - * |
|
| 102 | - * @param WP_User $user |
|
| 103 | - * |
|
| 104 | - * @return string Column Name |
|
| 105 | - */ |
|
| 106 | - public function column_state( $user ) { |
|
| 107 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 108 | - $state = $user->_wpinv_state; |
|
| 109 | - if ( $state ) { |
|
| 110 | - $state = wpinv_state_name( $state, $country ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return esc_html( $state ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Displays the signup column. |
|
| 118 | - * |
|
| 119 | - * @since 1.0.19 |
|
| 120 | - * |
|
| 121 | - * @param WP_User $user |
|
| 122 | - * |
|
| 123 | - * @return string Column Name |
|
| 124 | - */ |
|
| 125 | - public function column_signup( $user ) { |
|
| 126 | - return getpaid_format_date_value( $user->user_registered ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Displays the total spent column. |
|
| 131 | - * |
|
| 132 | - * @since 1.0.19 |
|
| 133 | - * |
|
| 134 | - * @param WP_User $user |
|
| 135 | - * |
|
| 136 | - * @return string Column Name |
|
| 137 | - */ |
|
| 138 | - public function column_total( $user ) { |
|
| 139 | - return wpinv_price( $this->column_total_raw( $user ) ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Displays the total spent column. |
|
| 144 | - * |
|
| 145 | - * @since 1.0.19 |
|
| 146 | - * |
|
| 147 | - * @param WP_User $user |
|
| 148 | - * |
|
| 149 | - * @return float |
|
| 150 | - */ |
|
| 151 | - public function column_total_raw( $user ) { |
|
| 152 | - |
|
| 153 | - $args = array( |
|
| 154 | - 'data' => array( |
|
| 155 | - |
|
| 156 | - 'total' => array( |
|
| 157 | - 'type' => 'invoice_data', |
|
| 158 | - 'function' => 'SUM', |
|
| 159 | - 'name' => 'total_sales', |
|
| 160 | - ) |
|
| 161 | - |
|
| 162 | - ), |
|
| 163 | - 'where' => array( |
|
| 164 | - |
|
| 165 | - 'author' => array( |
|
| 166 | - 'type' => 'post_data', |
|
| 167 | - 'value' => absint( $user->ID ), |
|
| 168 | - 'key' => 'posts.post_author', |
|
| 169 | - 'operator' => '=', |
|
| 170 | - ), |
|
| 171 | - |
|
| 172 | - ), |
|
| 173 | - 'query_type' => 'get_var', |
|
| 174 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 175 | - ); |
|
| 176 | - |
|
| 177 | - return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 178 | - |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Displays the total spent column. |
|
| 183 | - * |
|
| 184 | - * @since 1.0.19 |
|
| 185 | - * |
|
| 186 | - * @param WP_User $user |
|
| 187 | - * |
|
| 188 | - * @return string Column Name |
|
| 189 | - */ |
|
| 190 | - public function column_invoices( $user ) { |
|
| 191 | - |
|
| 192 | - $args = array( |
|
| 193 | - 'data' => array( |
|
| 194 | - |
|
| 195 | - 'ID' => array( |
|
| 196 | - 'type' => 'post_data', |
|
| 197 | - 'function' => 'COUNT', |
|
| 198 | - 'name' => 'count', |
|
| 199 | - 'distinct' => true, |
|
| 200 | - ), |
|
| 201 | - |
|
| 202 | - ), |
|
| 203 | - 'where' => array( |
|
| 204 | - |
|
| 205 | - 'author' => array( |
|
| 206 | - 'type' => 'post_data', |
|
| 207 | - 'value' => absint( $user->ID ), |
|
| 208 | - 'key' => 'posts.post_author', |
|
| 209 | - 'operator' => '=', |
|
| 210 | - ), |
|
| 211 | - |
|
| 212 | - ), |
|
| 213 | - 'query_type' => 'get_var', |
|
| 214 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 215 | - ); |
|
| 216 | - |
|
| 217 | - return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 218 | - |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Generates content for a single row of the table |
|
| 223 | - * @since 1.0.19 |
|
| 224 | - * |
|
| 225 | - * @param int $item The user id. |
|
| 226 | - */ |
|
| 227 | - public function single_row( $item ) { |
|
| 228 | - $item = get_user_by( 'id', $item ); |
|
| 229 | - |
|
| 230 | - if ( empty( $item ) ) { |
|
| 231 | - return; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - echo '<tr>'; |
|
| 235 | - $this->single_row_columns( $item ); |
|
| 236 | - echo '</tr>'; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Displays the customers name |
|
| 241 | - * |
|
| 242 | - * @param WP_User $customer customer. |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function column_name( $customer ) { |
|
| 246 | - |
|
| 247 | - // Customer view URL. |
|
| 248 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 249 | - $row_actions = $this->row_actions( |
|
| 250 | - array( |
|
| 251 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 252 | - ) |
|
| 253 | - ); |
|
| 254 | - |
|
| 255 | - // Get user's address. |
|
| 256 | - $address = wpinv_get_user_address( $customer->ID ); |
|
| 257 | - |
|
| 258 | - // Customer email address. |
|
| 259 | - $email = sanitize_email( $customer->user_email ); |
|
| 260 | - |
|
| 261 | - // Customer's avatar. |
|
| 262 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 263 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 264 | - |
|
| 265 | - // Customer's name. |
|
| 266 | - $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
| 267 | - |
|
| 268 | - if ( ! empty( $name ) ) { |
|
| 269 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 273 | - |
|
| 274 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 275 | - |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Retrieve the table columns |
|
| 280 | - * |
|
| 281 | - * @since 1.0.19 |
|
| 282 | - * @return array $columns Array of all the list table columns |
|
| 283 | - */ |
|
| 284 | - public function get_columns() { |
|
| 285 | - |
|
| 286 | - $columns = array( |
|
| 287 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 288 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 289 | - 'state' => __( 'State', 'invoicing' ), |
|
| 290 | - 'city' => __( 'City', 'invoicing' ), |
|
| 291 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 292 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 293 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 294 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 295 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 296 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 297 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 298 | - ); |
|
| 299 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 300 | - |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Retrieve the current page number |
|
| 305 | - * |
|
| 306 | - * @since 1.0.19 |
|
| 307 | - * @return int Current page number |
|
| 308 | - */ |
|
| 309 | - public function get_paged() { |
|
| 310 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Returns bulk actions. |
|
| 315 | - * |
|
| 316 | - * @since 1.0.19 |
|
| 317 | - * @return void |
|
| 318 | - */ |
|
| 319 | - public function bulk_actions( $which = '' ) { |
|
| 320 | - return array(); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Prepares the display query |
|
| 325 | - */ |
|
| 326 | - public function prepare_query() { |
|
| 327 | - global $wpdb; |
|
| 328 | - |
|
| 329 | - $post_types = ''; |
|
| 330 | - |
|
| 331 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 332 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 336 | - |
|
| 337 | - // Maybe search. |
|
| 338 | - if ( ! empty( $_POST['s'] ) ) { |
|
| 339 | - $users = get_users( |
|
| 340 | - array( |
|
| 341 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
| 342 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 343 | - 'fields' => 'ID', |
|
| 344 | - ) |
|
| 345 | - ); |
|
| 346 | - |
|
| 347 | - $users = implode( ', ', $users ); |
|
| 348 | - $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Users with invoices. |
|
| 352 | - $customers = $wpdb->get_col( |
|
| 353 | - $wpdb->prepare( |
|
| 354 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
| 355 | - $this->get_paged() * 10 - 10, |
|
| 356 | - $this->per_page |
|
| 357 | - ) |
|
| 358 | - ); |
|
| 359 | - |
|
| 360 | - $this->items = $customers; |
|
| 361 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 362 | - |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Setup the final data for the table |
|
| 367 | - * |
|
| 368 | - * @since 1.0.19 |
|
| 369 | - * @return void |
|
| 370 | - */ |
|
| 371 | - public function prepare_items() { |
|
| 372 | - $columns = $this->get_columns(); |
|
| 373 | - $hidden = array(); // No hidden columns |
|
| 374 | - $sortable = $this->get_sortable_columns(); |
|
| 375 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 376 | - $this->prepare_query(); |
|
| 377 | - |
|
| 378 | - $this->set_pagination_args( |
|
| 379 | - array( |
|
| 380 | - 'total_items' => $this->total, |
|
| 381 | - 'per_page' => $this->per_page, |
|
| 382 | - 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 383 | - ) |
|
| 384 | - ); |
|
| 385 | - |
|
| 386 | - } |
|
| 24 | + /** |
|
| 25 | + * @var int Number of items per page |
|
| 26 | + * @since 1.0.19 |
|
| 27 | + */ |
|
| 28 | + public $per_page = 10; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var int Number of items |
|
| 32 | + * @since 1.0.19 |
|
| 33 | + */ |
|
| 34 | + public $total = 0; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Get things started |
|
| 38 | + * |
|
| 39 | + * @since 1.0.19 |
|
| 40 | + * @see WP_List_Table::__construct() |
|
| 41 | + */ |
|
| 42 | + public function __construct() { |
|
| 43 | + |
|
| 44 | + // Set parent defaults |
|
| 45 | + parent::__construct( array( |
|
| 46 | + 'singular' => 'id', |
|
| 47 | + 'plural' => 'ids', |
|
| 48 | + 'ajax' => false, |
|
| 49 | + ) ); |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Gets the name of the primary column. |
|
| 55 | + * |
|
| 56 | + * @since 1.0.19 |
|
| 57 | + * @access protected |
|
| 58 | + * |
|
| 59 | + * @return string Name of the primary column. |
|
| 60 | + */ |
|
| 61 | + protected function get_primary_column_name() { |
|
| 62 | + return 'name'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * This function renders most of the columns in the list table. |
|
| 67 | + * |
|
| 68 | + * @since 1.0.19 |
|
| 69 | + * |
|
| 70 | + * @param WP_User $item |
|
| 71 | + * @param string $column_name The name of the column |
|
| 72 | + * |
|
| 73 | + * @return string Column Name |
|
| 74 | + */ |
|
| 75 | + public function column_default( $item, $column_name ) { |
|
| 76 | + $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Displays the country column. |
|
| 82 | + * |
|
| 83 | + * @since 1.0.19 |
|
| 84 | + * |
|
| 85 | + * @param WP_User $user |
|
| 86 | + * |
|
| 87 | + * @return string Column Name |
|
| 88 | + */ |
|
| 89 | + public function column_country( $user ) { |
|
| 90 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | + if ( $country ) { |
|
| 92 | + $country = wpinv_country_name( $country ); |
|
| 93 | + } |
|
| 94 | + return esc_html( $country ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Displays the state column. |
|
| 99 | + * |
|
| 100 | + * @since 1.0.19 |
|
| 101 | + * |
|
| 102 | + * @param WP_User $user |
|
| 103 | + * |
|
| 104 | + * @return string Column Name |
|
| 105 | + */ |
|
| 106 | + public function column_state( $user ) { |
|
| 107 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 108 | + $state = $user->_wpinv_state; |
|
| 109 | + if ( $state ) { |
|
| 110 | + $state = wpinv_state_name( $state, $country ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return esc_html( $state ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Displays the signup column. |
|
| 118 | + * |
|
| 119 | + * @since 1.0.19 |
|
| 120 | + * |
|
| 121 | + * @param WP_User $user |
|
| 122 | + * |
|
| 123 | + * @return string Column Name |
|
| 124 | + */ |
|
| 125 | + public function column_signup( $user ) { |
|
| 126 | + return getpaid_format_date_value( $user->user_registered ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Displays the total spent column. |
|
| 131 | + * |
|
| 132 | + * @since 1.0.19 |
|
| 133 | + * |
|
| 134 | + * @param WP_User $user |
|
| 135 | + * |
|
| 136 | + * @return string Column Name |
|
| 137 | + */ |
|
| 138 | + public function column_total( $user ) { |
|
| 139 | + return wpinv_price( $this->column_total_raw( $user ) ); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Displays the total spent column. |
|
| 144 | + * |
|
| 145 | + * @since 1.0.19 |
|
| 146 | + * |
|
| 147 | + * @param WP_User $user |
|
| 148 | + * |
|
| 149 | + * @return float |
|
| 150 | + */ |
|
| 151 | + public function column_total_raw( $user ) { |
|
| 152 | + |
|
| 153 | + $args = array( |
|
| 154 | + 'data' => array( |
|
| 155 | + |
|
| 156 | + 'total' => array( |
|
| 157 | + 'type' => 'invoice_data', |
|
| 158 | + 'function' => 'SUM', |
|
| 159 | + 'name' => 'total_sales', |
|
| 160 | + ) |
|
| 161 | + |
|
| 162 | + ), |
|
| 163 | + 'where' => array( |
|
| 164 | + |
|
| 165 | + 'author' => array( |
|
| 166 | + 'type' => 'post_data', |
|
| 167 | + 'value' => absint( $user->ID ), |
|
| 168 | + 'key' => 'posts.post_author', |
|
| 169 | + 'operator' => '=', |
|
| 170 | + ), |
|
| 171 | + |
|
| 172 | + ), |
|
| 173 | + 'query_type' => 'get_var', |
|
| 174 | + 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 175 | + ); |
|
| 176 | + |
|
| 177 | + return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 178 | + |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Displays the total spent column. |
|
| 183 | + * |
|
| 184 | + * @since 1.0.19 |
|
| 185 | + * |
|
| 186 | + * @param WP_User $user |
|
| 187 | + * |
|
| 188 | + * @return string Column Name |
|
| 189 | + */ |
|
| 190 | + public function column_invoices( $user ) { |
|
| 191 | + |
|
| 192 | + $args = array( |
|
| 193 | + 'data' => array( |
|
| 194 | + |
|
| 195 | + 'ID' => array( |
|
| 196 | + 'type' => 'post_data', |
|
| 197 | + 'function' => 'COUNT', |
|
| 198 | + 'name' => 'count', |
|
| 199 | + 'distinct' => true, |
|
| 200 | + ), |
|
| 201 | + |
|
| 202 | + ), |
|
| 203 | + 'where' => array( |
|
| 204 | + |
|
| 205 | + 'author' => array( |
|
| 206 | + 'type' => 'post_data', |
|
| 207 | + 'value' => absint( $user->ID ), |
|
| 208 | + 'key' => 'posts.post_author', |
|
| 209 | + 'operator' => '=', |
|
| 210 | + ), |
|
| 211 | + |
|
| 212 | + ), |
|
| 213 | + 'query_type' => 'get_var', |
|
| 214 | + 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 215 | + ); |
|
| 216 | + |
|
| 217 | + return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 218 | + |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Generates content for a single row of the table |
|
| 223 | + * @since 1.0.19 |
|
| 224 | + * |
|
| 225 | + * @param int $item The user id. |
|
| 226 | + */ |
|
| 227 | + public function single_row( $item ) { |
|
| 228 | + $item = get_user_by( 'id', $item ); |
|
| 229 | + |
|
| 230 | + if ( empty( $item ) ) { |
|
| 231 | + return; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + echo '<tr>'; |
|
| 235 | + $this->single_row_columns( $item ); |
|
| 236 | + echo '</tr>'; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Displays the customers name |
|
| 241 | + * |
|
| 242 | + * @param WP_User $customer customer. |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function column_name( $customer ) { |
|
| 246 | + |
|
| 247 | + // Customer view URL. |
|
| 248 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 249 | + $row_actions = $this->row_actions( |
|
| 250 | + array( |
|
| 251 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 252 | + ) |
|
| 253 | + ); |
|
| 254 | + |
|
| 255 | + // Get user's address. |
|
| 256 | + $address = wpinv_get_user_address( $customer->ID ); |
|
| 257 | + |
|
| 258 | + // Customer email address. |
|
| 259 | + $email = sanitize_email( $customer->user_email ); |
|
| 260 | + |
|
| 261 | + // Customer's avatar. |
|
| 262 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 263 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 264 | + |
|
| 265 | + // Customer's name. |
|
| 266 | + $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
| 267 | + |
|
| 268 | + if ( ! empty( $name ) ) { |
|
| 269 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 273 | + |
|
| 274 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 275 | + |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Retrieve the table columns |
|
| 280 | + * |
|
| 281 | + * @since 1.0.19 |
|
| 282 | + * @return array $columns Array of all the list table columns |
|
| 283 | + */ |
|
| 284 | + public function get_columns() { |
|
| 285 | + |
|
| 286 | + $columns = array( |
|
| 287 | + 'name' => __( 'Name', 'invoicing' ), |
|
| 288 | + 'country' => __( 'Country', 'invoicing' ), |
|
| 289 | + 'state' => __( 'State', 'invoicing' ), |
|
| 290 | + 'city' => __( 'City', 'invoicing' ), |
|
| 291 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 292 | + 'address' => __( 'Address', 'invoicing' ), |
|
| 293 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
| 294 | + 'company' => __( 'Company', 'invoicing' ), |
|
| 295 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 296 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 297 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
| 298 | + ); |
|
| 299 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 300 | + |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Retrieve the current page number |
|
| 305 | + * |
|
| 306 | + * @since 1.0.19 |
|
| 307 | + * @return int Current page number |
|
| 308 | + */ |
|
| 309 | + public function get_paged() { |
|
| 310 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Returns bulk actions. |
|
| 315 | + * |
|
| 316 | + * @since 1.0.19 |
|
| 317 | + * @return void |
|
| 318 | + */ |
|
| 319 | + public function bulk_actions( $which = '' ) { |
|
| 320 | + return array(); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Prepares the display query |
|
| 325 | + */ |
|
| 326 | + public function prepare_query() { |
|
| 327 | + global $wpdb; |
|
| 328 | + |
|
| 329 | + $post_types = ''; |
|
| 330 | + |
|
| 331 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 332 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + $post_types = rtrim( $post_types, ' OR' ); |
|
| 336 | + |
|
| 337 | + // Maybe search. |
|
| 338 | + if ( ! empty( $_POST['s'] ) ) { |
|
| 339 | + $users = get_users( |
|
| 340 | + array( |
|
| 341 | + 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
| 342 | + 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 343 | + 'fields' => 'ID', |
|
| 344 | + ) |
|
| 345 | + ); |
|
| 346 | + |
|
| 347 | + $users = implode( ', ', $users ); |
|
| 348 | + $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Users with invoices. |
|
| 352 | + $customers = $wpdb->get_col( |
|
| 353 | + $wpdb->prepare( |
|
| 354 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
| 355 | + $this->get_paged() * 10 - 10, |
|
| 356 | + $this->per_page |
|
| 357 | + ) |
|
| 358 | + ); |
|
| 359 | + |
|
| 360 | + $this->items = $customers; |
|
| 361 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 362 | + |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Setup the final data for the table |
|
| 367 | + * |
|
| 368 | + * @since 1.0.19 |
|
| 369 | + * @return void |
|
| 370 | + */ |
|
| 371 | + public function prepare_items() { |
|
| 372 | + $columns = $this->get_columns(); |
|
| 373 | + $hidden = array(); // No hidden columns |
|
| 374 | + $sortable = $this->get_sortable_columns(); |
|
| 375 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 376 | + $this->prepare_query(); |
|
| 377 | + |
|
| 378 | + $this->set_pagination_args( |
|
| 379 | + array( |
|
| 380 | + 'total_items' => $this->total, |
|
| 381 | + 'per_page' => $this->per_page, |
|
| 382 | + 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 383 | + ) |
|
| 384 | + ); |
|
| 385 | + |
|
| 386 | + } |
|
| 387 | 387 | } |
@@ -46,64 +46,64 @@ discard block |
||
| 46 | 46 | <td style="width: 65%"> |
| 47 | 47 | <?php |
| 48 | 48 | |
| 49 | - switch ( $key ) { |
|
| 49 | + switch ( $key ) { |
|
| 50 | 50 | |
| 51 | - case 'status': |
|
| 52 | - echo esc_html( $subscription->get_status_label() ); |
|
| 53 | - break; |
|
| 51 | + case 'status': |
|
| 52 | + echo esc_html( $subscription->get_status_label() ); |
|
| 53 | + break; |
|
| 54 | 54 | |
| 55 | - case 'start_date': |
|
| 56 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 57 | - break; |
|
| 55 | + case 'start_date': |
|
| 56 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 57 | + break; |
|
| 58 | 58 | |
| 59 | - case 'expiry_date': |
|
| 60 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
| 61 | - break; |
|
| 59 | + case 'expiry_date': |
|
| 60 | + echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
| 61 | + break; |
|
| 62 | 62 | |
| 63 | - case 'initial_amount': |
|
| 64 | - echo wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 63 | + case 'initial_amount': |
|
| 64 | + echo wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 65 | 65 | |
| 66 | - if ( $subscription->has_trial_period() ) { |
|
| 66 | + if ( $subscription->has_trial_period() ) { |
|
| 67 | 67 | |
| 68 | - echo "<small class='text-muted'> "; |
|
| 69 | - printf( |
|
| 70 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
| 71 | - esc_html( $subscription->get_trial_period() ) |
|
| 72 | - ); |
|
| 73 | - echo '</small>'; |
|
| 68 | + echo "<small class='text-muted'> "; |
|
| 69 | + printf( |
|
| 70 | + _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
| 71 | + esc_html( $subscription->get_trial_period() ) |
|
| 72 | + ); |
|
| 73 | + echo '</small>'; |
|
| 74 | 74 | |
| 75 | - } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - break; |
|
| 77 | + break; |
|
| 78 | 78 | |
| 79 | - case 'recurring_amount': |
|
| 80 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 81 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 82 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ); |
|
| 83 | - break; |
|
| 79 | + case 'recurring_amount': |
|
| 80 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 81 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 82 | + echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ); |
|
| 83 | + break; |
|
| 84 | 84 | |
| 85 | - case 'item': |
|
| 85 | + case 'item': |
|
| 86 | 86 | |
| 87 | - if ( empty( $subscription_group ) ) { |
|
| 88 | - echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
| 89 | - } else { |
|
| 90 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 91 | - echo implode( ' | ', $markup ); |
|
| 92 | - } |
|
| 87 | + if ( empty( $subscription_group ) ) { |
|
| 88 | + echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
| 89 | + } else { |
|
| 90 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 91 | + echo implode( ' | ', $markup ); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - break; |
|
| 94 | + break; |
|
| 95 | 95 | |
| 96 | - case 'payments': |
|
| 96 | + case 'payments': |
|
| 97 | 97 | |
| 98 | - $max_activations = (int) $subscription->get_bill_times(); |
|
| 99 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
| 98 | + $max_activations = (int) $subscription->get_bill_times(); |
|
| 99 | + echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
| 100 | 100 | |
| 101 | - break; |
|
| 101 | + break; |
|
| 102 | 102 | |
| 103 | - } |
|
| 104 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
| 103 | + } |
|
| 104 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
| 105 | 105 | |
| 106 | - ?> |
|
| 106 | + ?> |
|
| 107 | 107 | </td> |
| 108 | 108 | |
| 109 | 109 | </tr> |
@@ -130,17 +130,17 @@ discard block |
||
| 130 | 130 | <span class="form-text"> |
| 131 | 131 | |
| 132 | 132 | <?php |
| 133 | - if ( $subscription->can_cancel() ) { |
|
| 134 | - printf( |
|
| 135 | - '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
| 136 | - esc_url( $subscription->get_cancel_url() ), |
|
| 137 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
| 138 | - __( 'Cancel Subscription', 'invoicing' ) |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
| 143 | - ?> |
|
| 133 | + if ( $subscription->can_cancel() ) { |
|
| 134 | + printf( |
|
| 135 | + '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
| 136 | + esc_url( $subscription->get_cancel_url() ), |
|
| 137 | + esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
| 138 | + __( 'Cancel Subscription', 'invoicing' ) |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
| 143 | + ?> |
|
| 144 | 144 | |
| 145 | 145 | <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
| 146 | 146 | </span> |