@@ -14,30 +14,30 @@ discard block |
||
| 14 | 14 | class WPInv_Invoice extends GetPaid_Data { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Which data store to load. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 17 | + * Which data store to load. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | 21 | protected $data_store_name = 'invoice'; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * This is the name of this object type. |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 24 | + * This is the name of this object type. |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | 28 | protected $object_type = 'invoice'; |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 32 | - * |
|
| 33 | - * @since 1.0.19 |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected $data = array( |
|
| 37 | - 'parent_id' => 0, |
|
| 38 | - 'status' => 'wpi-pending', |
|
| 39 | - 'version' => '', |
|
| 40 | - 'date_created' => null, |
|
| 31 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 32 | + * |
|
| 33 | + * @since 1.0.19 |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected $data = array( |
|
| 37 | + 'parent_id' => 0, |
|
| 38 | + 'status' => 'wpi-pending', |
|
| 39 | + 'version' => '', |
|
| 40 | + 'date_created' => null, |
|
| 41 | 41 | 'date_modified' => null, |
| 42 | 42 | 'due_date' => null, |
| 43 | 43 | 'completed_date' => null, |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | 'transaction_id' => '', |
| 80 | 80 | 'currency' => '', |
| 81 | 81 | 'disable_taxes' => false, |
| 82 | - 'subscription_id' => null, |
|
| 83 | - 'is_viewed' => false, |
|
| 84 | - 'email_cc' => '', |
|
| 85 | - 'template' => 'quantity', // hours, amount only |
|
| 82 | + 'subscription_id' => null, |
|
| 83 | + 'is_viewed' => false, |
|
| 84 | + 'email_cc' => '', |
|
| 85 | + 'template' => 'quantity', // hours, amount only |
|
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | - * Stores meta in cache for future reads. |
|
| 90 | - * |
|
| 91 | - * A group must be set to to enable caching. |
|
| 92 | - * |
|
| 93 | - * @var string |
|
| 94 | - */ |
|
| 95 | - protected $cache_group = 'getpaid_invoices'; |
|
| 89 | + * Stores meta in cache for future reads. |
|
| 90 | + * |
|
| 91 | + * A group must be set to to enable caching. |
|
| 92 | + * |
|
| 93 | + * @var string |
|
| 94 | + */ |
|
| 95 | + protected $cache_group = 'getpaid_invoices'; |
|
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * Stores a reference to the original WP_Post object |
@@ -106,104 +106,104 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @var int |
| 108 | 108 | */ |
| 109 | - protected $recurring_item = null; |
|
| 109 | + protected $recurring_item = null; |
|
| 110 | 110 | |
| 111 | - /** |
|
| 111 | + /** |
|
| 112 | 112 | * Stores an array of item totals. |
| 113 | - * |
|
| 114 | - * e.g $totals['discount'] = array( |
|
| 115 | - * 'initial' => 10, |
|
| 116 | - * 'recurring' => 10, |
|
| 117 | - * ) |
|
| 113 | + * |
|
| 114 | + * e.g $totals['discount'] = array( |
|
| 115 | + * 'initial' => 10, |
|
| 116 | + * 'recurring' => 10, |
|
| 117 | + * ) |
|
| 118 | 118 | * |
| 119 | 119 | * @var array |
| 120 | 120 | */ |
| 121 | - protected $totals = array(); |
|
| 121 | + protected $totals = array(); |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Stores the status transition information. |
|
| 125 | - * |
|
| 126 | - * @since 1.0.19 |
|
| 127 | - * @var bool |
|
| 128 | - */ |
|
| 129 | - protected $status_transition = false; |
|
| 123 | + /** |
|
| 124 | + * Stores the status transition information. |
|
| 125 | + * |
|
| 126 | + * @since 1.0.19 |
|
| 127 | + * @var bool |
|
| 128 | + */ |
|
| 129 | + protected $status_transition = false; |
|
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 133 | - * |
|
| 134 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 135 | - */ |
|
| 132 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 133 | + * |
|
| 134 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 135 | + */ |
|
| 136 | 136 | public function __construct( $invoice = false ) { |
| 137 | 137 | |
| 138 | 138 | parent::__construct( $invoice ); |
| 139 | 139 | |
| 140 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
| 141 | - $this->set_id( $invoice ); |
|
| 142 | - } elseif ( $invoice instanceof self ) { |
|
| 143 | - $this->set_id( $invoice->get_id() ); |
|
| 144 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
| 145 | - $this->set_id( $invoice->ID ); |
|
| 146 | - } elseif ( is_array( $invoice ) ) { |
|
| 147 | - $this->set_props( $invoice ); |
|
| 148 | - |
|
| 149 | - if ( isset( $invoice['ID'] ) ) { |
|
| 150 | - $this->set_id( $invoice['ID'] ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 154 | - $this->set_id( $invoice_id ); |
|
| 155 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 156 | - $this->set_id( $invoice_id ); |
|
| 157 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 158 | - $this->set_id( $invoice_id ); |
|
| 159 | - }else { |
|
| 160 | - $this->set_object_read( true ); |
|
| 161 | - } |
|
| 140 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
| 141 | + $this->set_id( $invoice ); |
|
| 142 | + } elseif ( $invoice instanceof self ) { |
|
| 143 | + $this->set_id( $invoice->get_id() ); |
|
| 144 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
| 145 | + $this->set_id( $invoice->ID ); |
|
| 146 | + } elseif ( is_array( $invoice ) ) { |
|
| 147 | + $this->set_props( $invoice ); |
|
| 148 | + |
|
| 149 | + if ( isset( $invoice['ID'] ) ) { |
|
| 150 | + $this->set_id( $invoice['ID'] ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 154 | + $this->set_id( $invoice_id ); |
|
| 155 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 156 | + $this->set_id( $invoice_id ); |
|
| 157 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 158 | + $this->set_id( $invoice_id ); |
|
| 159 | + }else { |
|
| 160 | + $this->set_object_read( true ); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | // Load the datastore. |
| 164 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 164 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 165 | 165 | |
| 166 | - if ( $this->get_id() > 0 ) { |
|
| 166 | + if ( $this->get_id() > 0 ) { |
|
| 167 | 167 | $this->post = get_post( $this->get_id() ); |
| 168 | 168 | $this->ID = $this->get_id(); |
| 169 | - $this->data_store->read( $this ); |
|
| 169 | + $this->data_store->read( $this ); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | - * Given an invoice key/number, it returns its id. |
|
| 176 | - * |
|
| 177 | - * |
|
| 178 | - * @static |
|
| 179 | - * @param string $value The invoice key or number |
|
| 180 | - * @param string $field Either key, transaction_id or number. |
|
| 181 | - * @since 1.0.15 |
|
| 182 | - * @return int |
|
| 183 | - */ |
|
| 184 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 175 | + * Given an invoice key/number, it returns its id. |
|
| 176 | + * |
|
| 177 | + * |
|
| 178 | + * @static |
|
| 179 | + * @param string $value The invoice key or number |
|
| 180 | + * @param string $field Either key, transaction_id or number. |
|
| 181 | + * @since 1.0.15 |
|
| 182 | + * @return int |
|
| 183 | + */ |
|
| 184 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 185 | 185 | global $wpdb; |
| 186 | 186 | |
| 187 | - // Trim the value. |
|
| 188 | - $value = trim( $value ); |
|
| 187 | + // Trim the value. |
|
| 188 | + $value = trim( $value ); |
|
| 189 | 189 | |
| 190 | - if ( empty( $value ) ) { |
|
| 191 | - return 0; |
|
| 192 | - } |
|
| 190 | + if ( empty( $value ) ) { |
|
| 191 | + return 0; |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | 194 | // Valid fields. |
| 195 | 195 | $fields = array( 'key', 'number', 'transaction_id' ); |
| 196 | 196 | |
| 197 | - // Ensure a field has been passed. |
|
| 198 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 199 | - return 0; |
|
| 200 | - } |
|
| 197 | + // Ensure a field has been passed. |
|
| 198 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 199 | + return 0; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - // Maybe retrieve from the cache. |
|
| 203 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 204 | - if ( false !== $invoice_id ) { |
|
| 205 | - return $invoice_id; |
|
| 206 | - } |
|
| 202 | + // Maybe retrieve from the cache. |
|
| 203 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 204 | + if ( false !== $invoice_id ) { |
|
| 205 | + return $invoice_id; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | // Fetch from the db. |
| 209 | 209 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -211,10 +211,10 @@ discard block |
||
| 211 | 211 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 212 | 212 | ); |
| 213 | 213 | |
| 214 | - // Update the cache with our data |
|
| 215 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 214 | + // Update the cache with our data |
|
| 215 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 216 | 216 | |
| 217 | - return $invoice_id; |
|
| 217 | + return $invoice_id; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -240,80 +240,80 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | - * Get parent invoice ID. |
|
| 244 | - * |
|
| 245 | - * @since 1.0.19 |
|
| 246 | - * @param string $context View or edit context. |
|
| 247 | - * @return int |
|
| 248 | - */ |
|
| 249 | - public function get_parent_id( $context = 'view' ) { |
|
| 250 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 243 | + * Get parent invoice ID. |
|
| 244 | + * |
|
| 245 | + * @since 1.0.19 |
|
| 246 | + * @param string $context View or edit context. |
|
| 247 | + * @return int |
|
| 248 | + */ |
|
| 249 | + public function get_parent_id( $context = 'view' ) { |
|
| 250 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | - * Get parent invoice. |
|
| 255 | - * |
|
| 256 | - * @since 1.0.19 |
|
| 257 | - * @return WPInv_Invoice |
|
| 258 | - */ |
|
| 254 | + * Get parent invoice. |
|
| 255 | + * |
|
| 256 | + * @since 1.0.19 |
|
| 257 | + * @return WPInv_Invoice |
|
| 258 | + */ |
|
| 259 | 259 | public function get_parent_payment() { |
| 260 | 260 | return new WPInv_Invoice( $this->get_parent_id() ); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
| 264 | - * Alias for self::get_parent_payment(). |
|
| 265 | - * |
|
| 266 | - * @since 1.0.19 |
|
| 267 | - * @return WPInv_Invoice |
|
| 268 | - */ |
|
| 264 | + * Alias for self::get_parent_payment(). |
|
| 265 | + * |
|
| 266 | + * @since 1.0.19 |
|
| 267 | + * @return WPInv_Invoice |
|
| 268 | + */ |
|
| 269 | 269 | public function get_parent() { |
| 270 | 270 | return $this->get_parent_payment(); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
| 274 | - * Get invoice status. |
|
| 275 | - * |
|
| 276 | - * @since 1.0.19 |
|
| 277 | - * @param string $context View or edit context. |
|
| 278 | - * @return string |
|
| 279 | - */ |
|
| 280 | - public function get_status( $context = 'view' ) { |
|
| 281 | - return $this->get_prop( 'status', $context ); |
|
| 282 | - } |
|
| 274 | + * Get invoice status. |
|
| 275 | + * |
|
| 276 | + * @since 1.0.19 |
|
| 277 | + * @param string $context View or edit context. |
|
| 278 | + * @return string |
|
| 279 | + */ |
|
| 280 | + public function get_status( $context = 'view' ) { |
|
| 281 | + return $this->get_prop( 'status', $context ); |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * Retrieves an array of possible invoice statuses. |
|
| 286 | - * |
|
| 287 | - * @since 1.0.19 |
|
| 288 | - * @return array |
|
| 289 | - */ |
|
| 290 | - public function get_all_statuses() { |
|
| 291 | - |
|
| 292 | - $statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
| 293 | - |
|
| 294 | - // For backwards compatibility. |
|
| 295 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
| 284 | + /** |
|
| 285 | + * Retrieves an array of possible invoice statuses. |
|
| 286 | + * |
|
| 287 | + * @since 1.0.19 |
|
| 288 | + * @return array |
|
| 289 | + */ |
|
| 290 | + public function get_all_statuses() { |
|
| 291 | + |
|
| 292 | + $statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
| 293 | + |
|
| 294 | + // For backwards compatibility. |
|
| 295 | + if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
| 296 | 296 | $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
| 297 | - } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - return $statuses; |
|
| 299 | + return $statuses; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
| 303 | - * Get invoice status nice name. |
|
| 304 | - * |
|
| 305 | - * @since 1.0.19 |
|
| 306 | - * @return string |
|
| 307 | - */ |
|
| 303 | + * Get invoice status nice name. |
|
| 304 | + * |
|
| 305 | + * @since 1.0.19 |
|
| 306 | + * @return string |
|
| 307 | + */ |
|
| 308 | 308 | public function get_status_nicename() { |
| 309 | - $statuses = $this->get_all_statuses(); |
|
| 309 | + $statuses = $this->get_all_statuses(); |
|
| 310 | 310 | |
| 311 | 311 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
| 312 | 312 | |
| 313 | 313 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - /** |
|
| 316 | + /** |
|
| 317 | 317 | * Retrieves the invoice status label html |
| 318 | 318 | * |
| 319 | 319 | * @since 1.0.0 |
@@ -321,27 +321,27 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | public function get_status_label_html() { |
| 323 | 323 | |
| 324 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 325 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 324 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 325 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 326 | 326 | |
| 327 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>"; |
|
| 328 | - } |
|
| 327 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>"; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | 330 | /** |
| 331 | - * Get plugin version when the invoice was created. |
|
| 332 | - * |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @param string $context View or edit context. |
|
| 335 | - * @return string |
|
| 336 | - */ |
|
| 337 | - public function get_version( $context = 'view' ) { |
|
| 338 | - return $this->get_prop( 'version', $context ); |
|
| 339 | - } |
|
| 331 | + * Get plugin version when the invoice was created. |
|
| 332 | + * |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @param string $context View or edit context. |
|
| 335 | + * @return string |
|
| 336 | + */ |
|
| 337 | + public function get_version( $context = 'view' ) { |
|
| 338 | + return $this->get_prop( 'version', $context ); |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * @deprecated |
|
| 343 | - */ |
|
| 344 | - public function get_invoice_date( $formatted = true ) { |
|
| 341 | + /** |
|
| 342 | + * @deprecated |
|
| 343 | + */ |
|
| 344 | + public function get_invoice_date( $formatted = true ) { |
|
| 345 | 345 | $date_completed = $this->get_date_completed(); |
| 346 | 346 | $invoice_date = $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
| 347 | 347 | |
@@ -358,187 +358,187 @@ discard block |
||
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
| 361 | - * Get date when the invoice was created. |
|
| 362 | - * |
|
| 363 | - * @since 1.0.19 |
|
| 364 | - * @param string $context View or edit context. |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 367 | - public function get_date_created( $context = 'view' ) { |
|
| 368 | - return $this->get_prop( 'date_created', $context ); |
|
| 369 | - } |
|
| 361 | + * Get date when the invoice was created. |
|
| 362 | + * |
|
| 363 | + * @since 1.0.19 |
|
| 364 | + * @param string $context View or edit context. |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | + public function get_date_created( $context = 'view' ) { |
|
| 368 | + return $this->get_prop( 'date_created', $context ); |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | - /** |
|
| 372 | - * Alias for self::get_date_created(). |
|
| 373 | - * |
|
| 374 | - * @since 1.0.19 |
|
| 375 | - * @param string $context View or edit context. |
|
| 376 | - * @return string |
|
| 377 | - */ |
|
| 378 | - public function get_created_date( $context = 'view' ) { |
|
| 379 | - return $this->get_date_created( $context ); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Get GMT date when the invoice was created. |
|
| 384 | - * |
|
| 385 | - * @since 1.0.19 |
|
| 386 | - * @param string $context View or edit context. |
|
| 387 | - * @return string |
|
| 388 | - */ |
|
| 389 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 371 | + /** |
|
| 372 | + * Alias for self::get_date_created(). |
|
| 373 | + * |
|
| 374 | + * @since 1.0.19 |
|
| 375 | + * @param string $context View or edit context. |
|
| 376 | + * @return string |
|
| 377 | + */ |
|
| 378 | + public function get_created_date( $context = 'view' ) { |
|
| 379 | + return $this->get_date_created( $context ); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Get GMT date when the invoice was created. |
|
| 384 | + * |
|
| 385 | + * @since 1.0.19 |
|
| 386 | + * @param string $context View or edit context. |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 389 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 390 | 390 | $date = $this->get_date_created( $context ); |
| 391 | 391 | |
| 392 | 392 | if ( $date ) { |
| 393 | 393 | $date = get_gmt_from_date( $date ); |
| 394 | 394 | } |
| 395 | - return $date; |
|
| 395 | + return $date; |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
| 399 | - * Get date when the invoice was last modified. |
|
| 400 | - * |
|
| 401 | - * @since 1.0.19 |
|
| 402 | - * @param string $context View or edit context. |
|
| 403 | - * @return string |
|
| 404 | - */ |
|
| 405 | - public function get_date_modified( $context = 'view' ) { |
|
| 406 | - return $this->get_prop( 'date_modified', $context ); |
|
| 407 | - } |
|
| 399 | + * Get date when the invoice was last modified. |
|
| 400 | + * |
|
| 401 | + * @since 1.0.19 |
|
| 402 | + * @param string $context View or edit context. |
|
| 403 | + * @return string |
|
| 404 | + */ |
|
| 405 | + public function get_date_modified( $context = 'view' ) { |
|
| 406 | + return $this->get_prop( 'date_modified', $context ); |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - /** |
|
| 410 | - * Alias for self::get_date_modified(). |
|
| 411 | - * |
|
| 412 | - * @since 1.0.19 |
|
| 413 | - * @param string $context View or edit context. |
|
| 414 | - * @return string |
|
| 415 | - */ |
|
| 416 | - public function get_modified_date( $context = 'view' ) { |
|
| 417 | - return $this->get_date_modified( $context ); |
|
| 409 | + /** |
|
| 410 | + * Alias for self::get_date_modified(). |
|
| 411 | + * |
|
| 412 | + * @since 1.0.19 |
|
| 413 | + * @param string $context View or edit context. |
|
| 414 | + * @return string |
|
| 415 | + */ |
|
| 416 | + public function get_modified_date( $context = 'view' ) { |
|
| 417 | + return $this->get_date_modified( $context ); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
| 421 | - * Get GMT date when the invoice was last modified. |
|
| 422 | - * |
|
| 423 | - * @since 1.0.19 |
|
| 424 | - * @param string $context View or edit context. |
|
| 425 | - * @return string |
|
| 426 | - */ |
|
| 427 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 421 | + * Get GMT date when the invoice was last modified. |
|
| 422 | + * |
|
| 423 | + * @since 1.0.19 |
|
| 424 | + * @param string $context View or edit context. |
|
| 425 | + * @return string |
|
| 426 | + */ |
|
| 427 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 428 | 428 | $date = $this->get_date_modified( $context ); |
| 429 | 429 | |
| 430 | 430 | if ( $date ) { |
| 431 | 431 | $date = get_gmt_from_date( $date ); |
| 432 | 432 | } |
| 433 | - return $date; |
|
| 433 | + return $date; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
| 437 | - * Get the invoice due date. |
|
| 438 | - * |
|
| 439 | - * @since 1.0.19 |
|
| 440 | - * @param string $context View or edit context. |
|
| 441 | - * @return string |
|
| 442 | - */ |
|
| 443 | - public function get_due_date( $context = 'view' ) { |
|
| 444 | - return $this->get_prop( 'due_date', $context ); |
|
| 437 | + * Get the invoice due date. |
|
| 438 | + * |
|
| 439 | + * @since 1.0.19 |
|
| 440 | + * @param string $context View or edit context. |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + public function get_due_date( $context = 'view' ) { |
|
| 444 | + return $this->get_prop( 'due_date', $context ); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
| 448 | - * Alias for self::get_due_date(). |
|
| 449 | - * |
|
| 450 | - * @since 1.0.19 |
|
| 451 | - * @param string $context View or edit context. |
|
| 452 | - * @return string |
|
| 453 | - */ |
|
| 454 | - public function get_date_due( $context = 'view' ) { |
|
| 455 | - return $this->get_due_date( $context ); |
|
| 448 | + * Alias for self::get_due_date(). |
|
| 449 | + * |
|
| 450 | + * @since 1.0.19 |
|
| 451 | + * @param string $context View or edit context. |
|
| 452 | + * @return string |
|
| 453 | + */ |
|
| 454 | + public function get_date_due( $context = 'view' ) { |
|
| 455 | + return $this->get_due_date( $context ); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
| 459 | - * Get the invoice GMT due date. |
|
| 460 | - * |
|
| 461 | - * @since 1.0.19 |
|
| 462 | - * @param string $context View or edit context. |
|
| 463 | - * @return string |
|
| 464 | - */ |
|
| 465 | - public function get_due_date_gmt( $context = 'view' ) { |
|
| 459 | + * Get the invoice GMT due date. |
|
| 460 | + * |
|
| 461 | + * @since 1.0.19 |
|
| 462 | + * @param string $context View or edit context. |
|
| 463 | + * @return string |
|
| 464 | + */ |
|
| 465 | + public function get_due_date_gmt( $context = 'view' ) { |
|
| 466 | 466 | $date = $this->get_due_date( $context ); |
| 467 | 467 | |
| 468 | 468 | if ( $date ) { |
| 469 | 469 | $date = get_gmt_from_date( $date ); |
| 470 | 470 | } |
| 471 | - return $date; |
|
| 471 | + return $date; |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | /** |
| 475 | - * Alias for self::get_due_date_gmt(). |
|
| 476 | - * |
|
| 477 | - * @since 1.0.19 |
|
| 478 | - * @param string $context View or edit context. |
|
| 479 | - * @return string |
|
| 480 | - */ |
|
| 481 | - public function get_gmt_date_due( $context = 'view' ) { |
|
| 482 | - return $this->get_due_date_gmt( $context ); |
|
| 475 | + * Alias for self::get_due_date_gmt(). |
|
| 476 | + * |
|
| 477 | + * @since 1.0.19 |
|
| 478 | + * @param string $context View or edit context. |
|
| 479 | + * @return string |
|
| 480 | + */ |
|
| 481 | + public function get_gmt_date_due( $context = 'view' ) { |
|
| 482 | + return $this->get_due_date_gmt( $context ); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
| 486 | - * Get date when the invoice was completed. |
|
| 487 | - * |
|
| 488 | - * @since 1.0.19 |
|
| 489 | - * @param string $context View or edit context. |
|
| 490 | - * @return string |
|
| 491 | - */ |
|
| 492 | - public function get_completed_date( $context = 'view' ) { |
|
| 493 | - return $this->get_prop( 'completed_date', $context ); |
|
| 486 | + * Get date when the invoice was completed. |
|
| 487 | + * |
|
| 488 | + * @since 1.0.19 |
|
| 489 | + * @param string $context View or edit context. |
|
| 490 | + * @return string |
|
| 491 | + */ |
|
| 492 | + public function get_completed_date( $context = 'view' ) { |
|
| 493 | + return $this->get_prop( 'completed_date', $context ); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
| 497 | - * Alias for self::get_completed_date(). |
|
| 498 | - * |
|
| 499 | - * @since 1.0.19 |
|
| 500 | - * @param string $context View or edit context. |
|
| 501 | - * @return string |
|
| 502 | - */ |
|
| 503 | - public function get_date_completed( $context = 'view' ) { |
|
| 504 | - return $this->get_completed_date( $context ); |
|
| 497 | + * Alias for self::get_completed_date(). |
|
| 498 | + * |
|
| 499 | + * @since 1.0.19 |
|
| 500 | + * @param string $context View or edit context. |
|
| 501 | + * @return string |
|
| 502 | + */ |
|
| 503 | + public function get_date_completed( $context = 'view' ) { |
|
| 504 | + return $this->get_completed_date( $context ); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
| 508 | - * Get GMT date when the invoice was was completed. |
|
| 509 | - * |
|
| 510 | - * @since 1.0.19 |
|
| 511 | - * @param string $context View or edit context. |
|
| 512 | - * @return string |
|
| 513 | - */ |
|
| 514 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
| 508 | + * Get GMT date when the invoice was was completed. |
|
| 509 | + * |
|
| 510 | + * @since 1.0.19 |
|
| 511 | + * @param string $context View or edit context. |
|
| 512 | + * @return string |
|
| 513 | + */ |
|
| 514 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
| 515 | 515 | $date = $this->get_completed_date( $context ); |
| 516 | 516 | |
| 517 | 517 | if ( $date ) { |
| 518 | 518 | $date = get_gmt_from_date( $date ); |
| 519 | 519 | } |
| 520 | - return $date; |
|
| 520 | + return $date; |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
| 524 | - * Alias for self::get_completed_date_gmt(). |
|
| 525 | - * |
|
| 526 | - * @since 1.0.19 |
|
| 527 | - * @param string $context View or edit context. |
|
| 528 | - * @return string |
|
| 529 | - */ |
|
| 530 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
| 531 | - return $this->get_completed_date_gmt( $context ); |
|
| 524 | + * Alias for self::get_completed_date_gmt(). |
|
| 525 | + * |
|
| 526 | + * @since 1.0.19 |
|
| 527 | + * @param string $context View or edit context. |
|
| 528 | + * @return string |
|
| 529 | + */ |
|
| 530 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
| 531 | + return $this->get_completed_date_gmt( $context ); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
| 535 | - * Get the invoice number. |
|
| 536 | - * |
|
| 537 | - * @since 1.0.19 |
|
| 538 | - * @param string $context View or edit context. |
|
| 539 | - * @return string |
|
| 540 | - */ |
|
| 541 | - public function get_number( $context = 'view' ) { |
|
| 535 | + * Get the invoice number. |
|
| 536 | + * |
|
| 537 | + * @since 1.0.19 |
|
| 538 | + * @param string $context View or edit context. |
|
| 539 | + * @return string |
|
| 540 | + */ |
|
| 541 | + public function get_number( $context = 'view' ) { |
|
| 542 | 542 | $number = $this->get_prop( 'number', $context ); |
| 543 | 543 | |
| 544 | 544 | if ( empty( $number ) ) { |
@@ -546,17 +546,17 @@ discard block |
||
| 546 | 546 | $this->set_number( $number ); |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | - return $number; |
|
| 549 | + return $number; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
| 553 | - * Get the invoice key. |
|
| 554 | - * |
|
| 555 | - * @since 1.0.19 |
|
| 556 | - * @param string $context View or edit context. |
|
| 557 | - * @return string |
|
| 558 | - */ |
|
| 559 | - public function get_key( $context = 'view' ) { |
|
| 553 | + * Get the invoice key. |
|
| 554 | + * |
|
| 555 | + * @since 1.0.19 |
|
| 556 | + * @param string $context View or edit context. |
|
| 557 | + * @return string |
|
| 558 | + */ |
|
| 559 | + public function get_key( $context = 'view' ) { |
|
| 560 | 560 | $key = $this->get_prop( 'key', $context ); |
| 561 | 561 | |
| 562 | 562 | if ( empty( $key ) ) { |
@@ -564,24 +564,24 @@ discard block |
||
| 564 | 564 | $this->set_key( $key ); |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - return $key; |
|
| 567 | + return $key; |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | /** |
| 571 | - * Get the invoice type. |
|
| 572 | - * |
|
| 573 | - * @since 1.0.19 |
|
| 574 | - * @param string $context View or edit context. |
|
| 575 | - * @return string |
|
| 576 | - */ |
|
| 577 | - public function get_type( $context = 'view' ) { |
|
| 571 | + * Get the invoice type. |
|
| 572 | + * |
|
| 573 | + * @since 1.0.19 |
|
| 574 | + * @param string $context View or edit context. |
|
| 575 | + * @return string |
|
| 576 | + */ |
|
| 577 | + public function get_type( $context = 'view' ) { |
|
| 578 | 578 | return $this->get_prop( 'type', $context ); |
| 579 | - } |
|
| 579 | + } |
|
| 580 | 580 | |
| 581 | - /** |
|
| 582 | - * @deprecated |
|
| 583 | - */ |
|
| 584 | - public function get_invoice_quote_type( $post_id ) { |
|
| 581 | + /** |
|
| 582 | + * @deprecated |
|
| 583 | + */ |
|
| 584 | + public function get_invoice_quote_type( $post_id ) { |
|
| 585 | 585 | if ( empty( $post_id ) ) { |
| 586 | 586 | return ''; |
| 587 | 587 | } |
@@ -598,35 +598,35 @@ discard block |
||
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
| 601 | - * Get the invoice post type. |
|
| 602 | - * |
|
| 603 | - * @since 1.0.19 |
|
| 604 | - * @param string $context View or edit context. |
|
| 605 | - * @return string |
|
| 606 | - */ |
|
| 607 | - public function get_post_type( $context = 'view' ) { |
|
| 601 | + * Get the invoice post type. |
|
| 602 | + * |
|
| 603 | + * @since 1.0.19 |
|
| 604 | + * @param string $context View or edit context. |
|
| 605 | + * @return string |
|
| 606 | + */ |
|
| 607 | + public function get_post_type( $context = 'view' ) { |
|
| 608 | 608 | return $this->get_prop( 'post_type', $context ); |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | /** |
| 612 | - * Get the invoice mode. |
|
| 613 | - * |
|
| 614 | - * @since 1.0.19 |
|
| 615 | - * @param string $context View or edit context. |
|
| 616 | - * @return string |
|
| 617 | - */ |
|
| 618 | - public function get_mode( $context = 'view' ) { |
|
| 612 | + * Get the invoice mode. |
|
| 613 | + * |
|
| 614 | + * @since 1.0.19 |
|
| 615 | + * @param string $context View or edit context. |
|
| 616 | + * @return string |
|
| 617 | + */ |
|
| 618 | + public function get_mode( $context = 'view' ) { |
|
| 619 | 619 | return $this->get_prop( 'mode', $context ); |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
| 623 | - * Get the invoice path. |
|
| 624 | - * |
|
| 625 | - * @since 1.0.19 |
|
| 626 | - * @param string $context View or edit context. |
|
| 627 | - * @return string |
|
| 628 | - */ |
|
| 629 | - public function get_path( $context = 'view' ) { |
|
| 623 | + * Get the invoice path. |
|
| 624 | + * |
|
| 625 | + * @since 1.0.19 |
|
| 626 | + * @param string $context View or edit context. |
|
| 627 | + * @return string |
|
| 628 | + */ |
|
| 629 | + public function get_path( $context = 'view' ) { |
|
| 630 | 630 | $path = $this->get_prop( 'path', $context ); |
| 631 | 631 | |
| 632 | 632 | if ( empty( $path ) ) { |
@@ -634,71 +634,71 @@ discard block |
||
| 634 | 634 | $path = sanitize_title( $prefix . $this->get_id() ); |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | - return $path; |
|
| 637 | + return $path; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
| 641 | - * Get the invoice name/title. |
|
| 642 | - * |
|
| 643 | - * @since 1.0.19 |
|
| 644 | - * @param string $context View or edit context. |
|
| 645 | - * @return string |
|
| 646 | - */ |
|
| 647 | - public function get_name( $context = 'view' ) { |
|
| 641 | + * Get the invoice name/title. |
|
| 642 | + * |
|
| 643 | + * @since 1.0.19 |
|
| 644 | + * @param string $context View or edit context. |
|
| 645 | + * @return string |
|
| 646 | + */ |
|
| 647 | + public function get_name( $context = 'view' ) { |
|
| 648 | 648 | return $this->get_prop( 'title', $context ); |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | /** |
| 652 | - * Alias of self::get_name(). |
|
| 653 | - * |
|
| 654 | - * @since 1.0.19 |
|
| 655 | - * @param string $context View or edit context. |
|
| 656 | - * @return string |
|
| 657 | - */ |
|
| 658 | - public function get_title( $context = 'view' ) { |
|
| 659 | - return $this->get_name( $context ); |
|
| 652 | + * Alias of self::get_name(). |
|
| 653 | + * |
|
| 654 | + * @since 1.0.19 |
|
| 655 | + * @param string $context View or edit context. |
|
| 656 | + * @return string |
|
| 657 | + */ |
|
| 658 | + public function get_title( $context = 'view' ) { |
|
| 659 | + return $this->get_name( $context ); |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | /** |
| 663 | - * Get the invoice description. |
|
| 664 | - * |
|
| 665 | - * @since 1.0.19 |
|
| 666 | - * @param string $context View or edit context. |
|
| 667 | - * @return string |
|
| 668 | - */ |
|
| 669 | - public function get_description( $context = 'view' ) { |
|
| 670 | - return $this->get_prop( 'description', $context ); |
|
| 663 | + * Get the invoice description. |
|
| 664 | + * |
|
| 665 | + * @since 1.0.19 |
|
| 666 | + * @param string $context View or edit context. |
|
| 667 | + * @return string |
|
| 668 | + */ |
|
| 669 | + public function get_description( $context = 'view' ) { |
|
| 670 | + return $this->get_prop( 'description', $context ); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
| 674 | - * Alias of self::get_description(). |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - * @param string $context View or edit context. |
|
| 678 | - * @return string |
|
| 679 | - */ |
|
| 680 | - public function get_excerpt( $context = 'view' ) { |
|
| 681 | - return $this->get_description( $context ); |
|
| 674 | + * Alias of self::get_description(). |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + * @param string $context View or edit context. |
|
| 678 | + * @return string |
|
| 679 | + */ |
|
| 680 | + public function get_excerpt( $context = 'view' ) { |
|
| 681 | + return $this->get_description( $context ); |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | /** |
| 685 | - * Alias of self::get_description(). |
|
| 686 | - * |
|
| 687 | - * @since 1.0.19 |
|
| 688 | - * @param string $context View or edit context. |
|
| 689 | - * @return string |
|
| 690 | - */ |
|
| 691 | - public function get_summary( $context = 'view' ) { |
|
| 692 | - return $this->get_description( $context ); |
|
| 685 | + * Alias of self::get_description(). |
|
| 686 | + * |
|
| 687 | + * @since 1.0.19 |
|
| 688 | + * @param string $context View or edit context. |
|
| 689 | + * @return string |
|
| 690 | + */ |
|
| 691 | + public function get_summary( $context = 'view' ) { |
|
| 692 | + return $this->get_description( $context ); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
| 696 | - * Returns the user info. |
|
| 697 | - * |
|
| 698 | - * @since 1.0.19 |
|
| 696 | + * Returns the user info. |
|
| 697 | + * |
|
| 698 | + * @since 1.0.19 |
|
| 699 | 699 | * @param string $context View or edit context. |
| 700 | - * @return array |
|
| 701 | - */ |
|
| 700 | + * @return array |
|
| 701 | + */ |
|
| 702 | 702 | public function get_user_info( $context = 'view' ) { |
| 703 | 703 | |
| 704 | 704 | $user_info = array( |
@@ -715,605 +715,605 @@ discard block |
||
| 715 | 715 | 'company' => $this->get_company( $context ), |
| 716 | 716 | 'vat_number' => $this->get_vat_number( $context ), |
| 717 | 717 | 'discount' => $this->get_discount_code( $context ), |
| 718 | - ); |
|
| 718 | + ); |
|
| 719 | 719 | |
| 720 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 720 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 721 | 721 | |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
| 725 | - * Get the customer id. |
|
| 726 | - * |
|
| 727 | - * @since 1.0.19 |
|
| 728 | - * @param string $context View or edit context. |
|
| 729 | - * @return int |
|
| 730 | - */ |
|
| 731 | - public function get_author( $context = 'view' ) { |
|
| 732 | - return (int) $this->get_prop( 'author', $context ); |
|
| 725 | + * Get the customer id. |
|
| 726 | + * |
|
| 727 | + * @since 1.0.19 |
|
| 728 | + * @param string $context View or edit context. |
|
| 729 | + * @return int |
|
| 730 | + */ |
|
| 731 | + public function get_author( $context = 'view' ) { |
|
| 732 | + return (int) $this->get_prop( 'author', $context ); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | /** |
| 736 | - * Alias of self::get_author(). |
|
| 737 | - * |
|
| 738 | - * @since 1.0.19 |
|
| 739 | - * @param string $context View or edit context. |
|
| 740 | - * @return int |
|
| 741 | - */ |
|
| 742 | - public function get_user_id( $context = 'view' ) { |
|
| 743 | - return $this->get_author( $context ); |
|
| 736 | + * Alias of self::get_author(). |
|
| 737 | + * |
|
| 738 | + * @since 1.0.19 |
|
| 739 | + * @param string $context View or edit context. |
|
| 740 | + * @return int |
|
| 741 | + */ |
|
| 742 | + public function get_user_id( $context = 'view' ) { |
|
| 743 | + return $this->get_author( $context ); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - /** |
|
| 747 | - * Alias of self::get_author(). |
|
| 748 | - * |
|
| 749 | - * @since 1.0.19 |
|
| 750 | - * @param string $context View or edit context. |
|
| 751 | - * @return int |
|
| 752 | - */ |
|
| 753 | - public function get_customer_id( $context = 'view' ) { |
|
| 754 | - return $this->get_author( $context ); |
|
| 746 | + /** |
|
| 747 | + * Alias of self::get_author(). |
|
| 748 | + * |
|
| 749 | + * @since 1.0.19 |
|
| 750 | + * @param string $context View or edit context. |
|
| 751 | + * @return int |
|
| 752 | + */ |
|
| 753 | + public function get_customer_id( $context = 'view' ) { |
|
| 754 | + return $this->get_author( $context ); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | /** |
| 758 | - * Get the customer's ip. |
|
| 759 | - * |
|
| 760 | - * @since 1.0.19 |
|
| 761 | - * @param string $context View or edit context. |
|
| 762 | - * @return string |
|
| 763 | - */ |
|
| 764 | - public function get_ip( $context = 'view' ) { |
|
| 765 | - return $this->get_prop( 'user_ip', $context ); |
|
| 758 | + * Get the customer's ip. |
|
| 759 | + * |
|
| 760 | + * @since 1.0.19 |
|
| 761 | + * @param string $context View or edit context. |
|
| 762 | + * @return string |
|
| 763 | + */ |
|
| 764 | + public function get_ip( $context = 'view' ) { |
|
| 765 | + return $this->get_prop( 'user_ip', $context ); |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | /** |
| 769 | - * Alias of self::get_ip(). |
|
| 770 | - * |
|
| 771 | - * @since 1.0.19 |
|
| 772 | - * @param string $context View or edit context. |
|
| 773 | - * @return string |
|
| 774 | - */ |
|
| 775 | - public function get_user_ip( $context = 'view' ) { |
|
| 776 | - return $this->get_ip( $context ); |
|
| 769 | + * Alias of self::get_ip(). |
|
| 770 | + * |
|
| 771 | + * @since 1.0.19 |
|
| 772 | + * @param string $context View or edit context. |
|
| 773 | + * @return string |
|
| 774 | + */ |
|
| 775 | + public function get_user_ip( $context = 'view' ) { |
|
| 776 | + return $this->get_ip( $context ); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | - /** |
|
| 780 | - * Alias of self::get_ip(). |
|
| 781 | - * |
|
| 782 | - * @since 1.0.19 |
|
| 783 | - * @param string $context View or edit context. |
|
| 784 | - * @return string |
|
| 785 | - */ |
|
| 786 | - public function get_customer_ip( $context = 'view' ) { |
|
| 787 | - return $this->get_ip( $context ); |
|
| 779 | + /** |
|
| 780 | + * Alias of self::get_ip(). |
|
| 781 | + * |
|
| 782 | + * @since 1.0.19 |
|
| 783 | + * @param string $context View or edit context. |
|
| 784 | + * @return string |
|
| 785 | + */ |
|
| 786 | + public function get_customer_ip( $context = 'view' ) { |
|
| 787 | + return $this->get_ip( $context ); |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | /** |
| 791 | - * Get the customer's first name. |
|
| 792 | - * |
|
| 793 | - * @since 1.0.19 |
|
| 794 | - * @param string $context View or edit context. |
|
| 795 | - * @return string |
|
| 796 | - */ |
|
| 797 | - public function get_first_name( $context = 'view' ) { |
|
| 798 | - return $this->get_prop( 'first_name', $context ); |
|
| 791 | + * Get the customer's first name. |
|
| 792 | + * |
|
| 793 | + * @since 1.0.19 |
|
| 794 | + * @param string $context View or edit context. |
|
| 795 | + * @return string |
|
| 796 | + */ |
|
| 797 | + public function get_first_name( $context = 'view' ) { |
|
| 798 | + return $this->get_prop( 'first_name', $context ); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | /** |
| 802 | - * Alias of self::get_first_name(). |
|
| 803 | - * |
|
| 804 | - * @since 1.0.19 |
|
| 805 | - * @param string $context View or edit context. |
|
| 806 | - * @return int |
|
| 807 | - */ |
|
| 808 | - public function get_user_first_name( $context = 'view' ) { |
|
| 809 | - return $this->get_first_name( $context ); |
|
| 802 | + * Alias of self::get_first_name(). |
|
| 803 | + * |
|
| 804 | + * @since 1.0.19 |
|
| 805 | + * @param string $context View or edit context. |
|
| 806 | + * @return int |
|
| 807 | + */ |
|
| 808 | + public function get_user_first_name( $context = 'view' ) { |
|
| 809 | + return $this->get_first_name( $context ); |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - /** |
|
| 813 | - * Alias of self::get_first_name(). |
|
| 814 | - * |
|
| 815 | - * @since 1.0.19 |
|
| 816 | - * @param string $context View or edit context. |
|
| 817 | - * @return int |
|
| 818 | - */ |
|
| 819 | - public function get_customer_first_name( $context = 'view' ) { |
|
| 820 | - return $this->get_first_name( $context ); |
|
| 812 | + /** |
|
| 813 | + * Alias of self::get_first_name(). |
|
| 814 | + * |
|
| 815 | + * @since 1.0.19 |
|
| 816 | + * @param string $context View or edit context. |
|
| 817 | + * @return int |
|
| 818 | + */ |
|
| 819 | + public function get_customer_first_name( $context = 'view' ) { |
|
| 820 | + return $this->get_first_name( $context ); |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | /** |
| 824 | - * Get the customer's last name. |
|
| 825 | - * |
|
| 826 | - * @since 1.0.19 |
|
| 827 | - * @param string $context View or edit context. |
|
| 828 | - * @return string |
|
| 829 | - */ |
|
| 830 | - public function get_last_name( $context = 'view' ) { |
|
| 831 | - return $this->get_prop( 'last_name', $context ); |
|
| 824 | + * Get the customer's last name. |
|
| 825 | + * |
|
| 826 | + * @since 1.0.19 |
|
| 827 | + * @param string $context View or edit context. |
|
| 828 | + * @return string |
|
| 829 | + */ |
|
| 830 | + public function get_last_name( $context = 'view' ) { |
|
| 831 | + return $this->get_prop( 'last_name', $context ); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
| 835 | - * Alias of self::get_last_name(). |
|
| 836 | - * |
|
| 837 | - * @since 1.0.19 |
|
| 838 | - * @param string $context View or edit context. |
|
| 839 | - * @return int |
|
| 840 | - */ |
|
| 841 | - public function get_user_last_name( $context = 'view' ) { |
|
| 842 | - return $this->get_last_name( $context ); |
|
| 835 | + * Alias of self::get_last_name(). |
|
| 836 | + * |
|
| 837 | + * @since 1.0.19 |
|
| 838 | + * @param string $context View or edit context. |
|
| 839 | + * @return int |
|
| 840 | + */ |
|
| 841 | + public function get_user_last_name( $context = 'view' ) { |
|
| 842 | + return $this->get_last_name( $context ); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | /** |
| 846 | - * Alias of self::get_last_name(). |
|
| 847 | - * |
|
| 848 | - * @since 1.0.19 |
|
| 849 | - * @param string $context View or edit context. |
|
| 850 | - * @return int |
|
| 851 | - */ |
|
| 852 | - public function get_customer_last_name( $context = 'view' ) { |
|
| 853 | - return $this->get_last_name( $context ); |
|
| 846 | + * Alias of self::get_last_name(). |
|
| 847 | + * |
|
| 848 | + * @since 1.0.19 |
|
| 849 | + * @param string $context View or edit context. |
|
| 850 | + * @return int |
|
| 851 | + */ |
|
| 852 | + public function get_customer_last_name( $context = 'view' ) { |
|
| 853 | + return $this->get_last_name( $context ); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | /** |
| 857 | - * Get the customer's full name. |
|
| 858 | - * |
|
| 859 | - * @since 1.0.19 |
|
| 860 | - * @param string $context View or edit context. |
|
| 861 | - * @return string |
|
| 862 | - */ |
|
| 863 | - public function get_full_name( $context = 'view' ) { |
|
| 864 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 857 | + * Get the customer's full name. |
|
| 858 | + * |
|
| 859 | + * @since 1.0.19 |
|
| 860 | + * @param string $context View or edit context. |
|
| 861 | + * @return string |
|
| 862 | + */ |
|
| 863 | + public function get_full_name( $context = 'view' ) { |
|
| 864 | + return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | /** |
| 868 | - * Alias of self::get_full_name(). |
|
| 869 | - * |
|
| 870 | - * @since 1.0.19 |
|
| 871 | - * @param string $context View or edit context. |
|
| 872 | - * @return int |
|
| 873 | - */ |
|
| 874 | - public function get_user_full_name( $context = 'view' ) { |
|
| 875 | - return $this->get_full_name( $context ); |
|
| 868 | + * Alias of self::get_full_name(). |
|
| 869 | + * |
|
| 870 | + * @since 1.0.19 |
|
| 871 | + * @param string $context View or edit context. |
|
| 872 | + * @return int |
|
| 873 | + */ |
|
| 874 | + public function get_user_full_name( $context = 'view' ) { |
|
| 875 | + return $this->get_full_name( $context ); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
| 879 | - * Alias of self::get_full_name(). |
|
| 880 | - * |
|
| 881 | - * @since 1.0.19 |
|
| 882 | - * @param string $context View or edit context. |
|
| 883 | - * @return int |
|
| 884 | - */ |
|
| 885 | - public function get_customer_full_name( $context = 'view' ) { |
|
| 886 | - return $this->get_full_name( $context ); |
|
| 879 | + * Alias of self::get_full_name(). |
|
| 880 | + * |
|
| 881 | + * @since 1.0.19 |
|
| 882 | + * @param string $context View or edit context. |
|
| 883 | + * @return int |
|
| 884 | + */ |
|
| 885 | + public function get_customer_full_name( $context = 'view' ) { |
|
| 886 | + return $this->get_full_name( $context ); |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | /** |
| 890 | - * Get the customer's phone number. |
|
| 891 | - * |
|
| 892 | - * @since 1.0.19 |
|
| 893 | - * @param string $context View or edit context. |
|
| 894 | - * @return string |
|
| 895 | - */ |
|
| 896 | - public function get_phone( $context = 'view' ) { |
|
| 897 | - return $this->get_prop( 'phone', $context ); |
|
| 890 | + * Get the customer's phone number. |
|
| 891 | + * |
|
| 892 | + * @since 1.0.19 |
|
| 893 | + * @param string $context View or edit context. |
|
| 894 | + * @return string |
|
| 895 | + */ |
|
| 896 | + public function get_phone( $context = 'view' ) { |
|
| 897 | + return $this->get_prop( 'phone', $context ); |
|
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | /** |
| 901 | - * Alias of self::get_phone(). |
|
| 902 | - * |
|
| 903 | - * @since 1.0.19 |
|
| 904 | - * @param string $context View or edit context. |
|
| 905 | - * @return int |
|
| 906 | - */ |
|
| 907 | - public function get_phone_number( $context = 'view' ) { |
|
| 908 | - return $this->get_phone( $context ); |
|
| 901 | + * Alias of self::get_phone(). |
|
| 902 | + * |
|
| 903 | + * @since 1.0.19 |
|
| 904 | + * @param string $context View or edit context. |
|
| 905 | + * @return int |
|
| 906 | + */ |
|
| 907 | + public function get_phone_number( $context = 'view' ) { |
|
| 908 | + return $this->get_phone( $context ); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | /** |
| 912 | - * Alias of self::get_phone(). |
|
| 913 | - * |
|
| 914 | - * @since 1.0.19 |
|
| 915 | - * @param string $context View or edit context. |
|
| 916 | - * @return int |
|
| 917 | - */ |
|
| 918 | - public function get_user_phone( $context = 'view' ) { |
|
| 919 | - return $this->get_phone( $context ); |
|
| 912 | + * Alias of self::get_phone(). |
|
| 913 | + * |
|
| 914 | + * @since 1.0.19 |
|
| 915 | + * @param string $context View or edit context. |
|
| 916 | + * @return int |
|
| 917 | + */ |
|
| 918 | + public function get_user_phone( $context = 'view' ) { |
|
| 919 | + return $this->get_phone( $context ); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
| 923 | - * Alias of self::get_phone(). |
|
| 924 | - * |
|
| 925 | - * @since 1.0.19 |
|
| 926 | - * @param string $context View or edit context. |
|
| 927 | - * @return int |
|
| 928 | - */ |
|
| 929 | - public function get_customer_phone( $context = 'view' ) { |
|
| 930 | - return $this->get_phone( $context ); |
|
| 923 | + * Alias of self::get_phone(). |
|
| 924 | + * |
|
| 925 | + * @since 1.0.19 |
|
| 926 | + * @param string $context View or edit context. |
|
| 927 | + * @return int |
|
| 928 | + */ |
|
| 929 | + public function get_customer_phone( $context = 'view' ) { |
|
| 930 | + return $this->get_phone( $context ); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | 933 | /** |
| 934 | - * Get the customer's email address. |
|
| 935 | - * |
|
| 936 | - * @since 1.0.19 |
|
| 937 | - * @param string $context View or edit context. |
|
| 938 | - * @return string |
|
| 939 | - */ |
|
| 940 | - public function get_email( $context = 'view' ) { |
|
| 941 | - return $this->get_prop( 'email', $context ); |
|
| 934 | + * Get the customer's email address. |
|
| 935 | + * |
|
| 936 | + * @since 1.0.19 |
|
| 937 | + * @param string $context View or edit context. |
|
| 938 | + * @return string |
|
| 939 | + */ |
|
| 940 | + public function get_email( $context = 'view' ) { |
|
| 941 | + return $this->get_prop( 'email', $context ); |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | /** |
| 945 | - * Alias of self::get_email(). |
|
| 946 | - * |
|
| 947 | - * @since 1.0.19 |
|
| 948 | - * @param string $context View or edit context. |
|
| 949 | - * @return string |
|
| 950 | - */ |
|
| 951 | - public function get_email_address( $context = 'view' ) { |
|
| 952 | - return $this->get_email( $context ); |
|
| 945 | + * Alias of self::get_email(). |
|
| 946 | + * |
|
| 947 | + * @since 1.0.19 |
|
| 948 | + * @param string $context View or edit context. |
|
| 949 | + * @return string |
|
| 950 | + */ |
|
| 951 | + public function get_email_address( $context = 'view' ) { |
|
| 952 | + return $this->get_email( $context ); |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | /** |
| 956 | - * Alias of self::get_email(). |
|
| 957 | - * |
|
| 958 | - * @since 1.0.19 |
|
| 959 | - * @param string $context View or edit context. |
|
| 960 | - * @return int |
|
| 961 | - */ |
|
| 962 | - public function get_user_email( $context = 'view' ) { |
|
| 963 | - return $this->get_email( $context ); |
|
| 956 | + * Alias of self::get_email(). |
|
| 957 | + * |
|
| 958 | + * @since 1.0.19 |
|
| 959 | + * @param string $context View or edit context. |
|
| 960 | + * @return int |
|
| 961 | + */ |
|
| 962 | + public function get_user_email( $context = 'view' ) { |
|
| 963 | + return $this->get_email( $context ); |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | /** |
| 967 | - * Alias of self::get_email(). |
|
| 968 | - * |
|
| 969 | - * @since 1.0.19 |
|
| 970 | - * @param string $context View or edit context. |
|
| 971 | - * @return int |
|
| 972 | - */ |
|
| 973 | - public function get_customer_email( $context = 'view' ) { |
|
| 974 | - return $this->get_email( $context ); |
|
| 967 | + * Alias of self::get_email(). |
|
| 968 | + * |
|
| 969 | + * @since 1.0.19 |
|
| 970 | + * @param string $context View or edit context. |
|
| 971 | + * @return int |
|
| 972 | + */ |
|
| 973 | + public function get_customer_email( $context = 'view' ) { |
|
| 974 | + return $this->get_email( $context ); |
|
| 975 | 975 | } |
| 976 | 976 | |
| 977 | 977 | /** |
| 978 | - * Get the customer's country. |
|
| 979 | - * |
|
| 980 | - * @since 1.0.19 |
|
| 981 | - * @param string $context View or edit context. |
|
| 982 | - * @return string |
|
| 983 | - */ |
|
| 984 | - public function get_country( $context = 'view' ) { |
|
| 985 | - $country = $this->get_prop( 'country', $context ); |
|
| 986 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 978 | + * Get the customer's country. |
|
| 979 | + * |
|
| 980 | + * @since 1.0.19 |
|
| 981 | + * @param string $context View or edit context. |
|
| 982 | + * @return string |
|
| 983 | + */ |
|
| 984 | + public function get_country( $context = 'view' ) { |
|
| 985 | + $country = $this->get_prop( 'country', $context ); |
|
| 986 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | /** |
| 990 | - * Alias of self::get_country(). |
|
| 991 | - * |
|
| 992 | - * @since 1.0.19 |
|
| 993 | - * @param string $context View or edit context. |
|
| 994 | - * @return int |
|
| 995 | - */ |
|
| 996 | - public function get_user_country( $context = 'view' ) { |
|
| 997 | - return $this->get_country( $context ); |
|
| 990 | + * Alias of self::get_country(). |
|
| 991 | + * |
|
| 992 | + * @since 1.0.19 |
|
| 993 | + * @param string $context View or edit context. |
|
| 994 | + * @return int |
|
| 995 | + */ |
|
| 996 | + public function get_user_country( $context = 'view' ) { |
|
| 997 | + return $this->get_country( $context ); |
|
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | 1000 | /** |
| 1001 | - * Alias of self::get_country(). |
|
| 1002 | - * |
|
| 1003 | - * @since 1.0.19 |
|
| 1004 | - * @param string $context View or edit context. |
|
| 1005 | - * @return int |
|
| 1006 | - */ |
|
| 1007 | - public function get_customer_country( $context = 'view' ) { |
|
| 1008 | - return $this->get_country( $context ); |
|
| 1001 | + * Alias of self::get_country(). |
|
| 1002 | + * |
|
| 1003 | + * @since 1.0.19 |
|
| 1004 | + * @param string $context View or edit context. |
|
| 1005 | + * @return int |
|
| 1006 | + */ |
|
| 1007 | + public function get_customer_country( $context = 'view' ) { |
|
| 1008 | + return $this->get_country( $context ); |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | /** |
| 1012 | - * Get the customer's state. |
|
| 1013 | - * |
|
| 1014 | - * @since 1.0.19 |
|
| 1015 | - * @param string $context View or edit context. |
|
| 1016 | - * @return string |
|
| 1017 | - */ |
|
| 1018 | - public function get_state( $context = 'view' ) { |
|
| 1019 | - $state = $this->get_prop( 'state', $context ); |
|
| 1020 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1012 | + * Get the customer's state. |
|
| 1013 | + * |
|
| 1014 | + * @since 1.0.19 |
|
| 1015 | + * @param string $context View or edit context. |
|
| 1016 | + * @return string |
|
| 1017 | + */ |
|
| 1018 | + public function get_state( $context = 'view' ) { |
|
| 1019 | + $state = $this->get_prop( 'state', $context ); |
|
| 1020 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | /** |
| 1024 | - * Alias of self::get_state(). |
|
| 1025 | - * |
|
| 1026 | - * @since 1.0.19 |
|
| 1027 | - * @param string $context View or edit context. |
|
| 1028 | - * @return int |
|
| 1029 | - */ |
|
| 1030 | - public function get_user_state( $context = 'view' ) { |
|
| 1031 | - return $this->get_state( $context ); |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1024 | + * Alias of self::get_state(). |
|
| 1025 | + * |
|
| 1026 | + * @since 1.0.19 |
|
| 1027 | + * @param string $context View or edit context. |
|
| 1028 | + * @return int |
|
| 1029 | + */ |
|
| 1030 | + public function get_user_state( $context = 'view' ) { |
|
| 1031 | + return $this->get_state( $context ); |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + /** |
|
| 1035 | + * Alias of self::get_state(). |
|
| 1036 | + * |
|
| 1037 | + * @since 1.0.19 |
|
| 1038 | + * @param string $context View or edit context. |
|
| 1039 | + * @return int |
|
| 1040 | + */ |
|
| 1041 | + public function get_customer_state( $context = 'view' ) { |
|
| 1042 | + return $this->get_state( $context ); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * Get the customer's city. |
|
| 1047 | + * |
|
| 1048 | + * @since 1.0.19 |
|
| 1049 | + * @param string $context View or edit context. |
|
| 1050 | + * @return string |
|
| 1051 | + */ |
|
| 1052 | + public function get_city( $context = 'view' ) { |
|
| 1053 | + return $this->get_prop( 'city', $context ); |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * Alias of self::get_city(). |
|
| 1058 | + * |
|
| 1059 | + * @since 1.0.19 |
|
| 1060 | + * @param string $context View or edit context. |
|
| 1061 | + * @return string |
|
| 1062 | + */ |
|
| 1063 | + public function get_user_city( $context = 'view' ) { |
|
| 1064 | + return $this->get_city( $context ); |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1034 | 1067 | /** |
| 1035 | - * Alias of self::get_state(). |
|
| 1036 | - * |
|
| 1037 | - * @since 1.0.19 |
|
| 1038 | - * @param string $context View or edit context. |
|
| 1039 | - * @return int |
|
| 1040 | - */ |
|
| 1041 | - public function get_customer_state( $context = 'view' ) { |
|
| 1042 | - return $this->get_state( $context ); |
|
| 1068 | + * Alias of self::get_city(). |
|
| 1069 | + * |
|
| 1070 | + * @since 1.0.19 |
|
| 1071 | + * @param string $context View or edit context. |
|
| 1072 | + * @return string |
|
| 1073 | + */ |
|
| 1074 | + public function get_customer_city( $context = 'view' ) { |
|
| 1075 | + return $this->get_city( $context ); |
|
| 1043 | 1076 | } |
| 1044 | 1077 | |
| 1045 | 1078 | /** |
| 1046 | - * Get the customer's city. |
|
| 1047 | - * |
|
| 1048 | - * @since 1.0.19 |
|
| 1049 | - * @param string $context View or edit context. |
|
| 1050 | - * @return string |
|
| 1051 | - */ |
|
| 1052 | - public function get_city( $context = 'view' ) { |
|
| 1053 | - return $this->get_prop( 'city', $context ); |
|
| 1079 | + * Get the customer's zip. |
|
| 1080 | + * |
|
| 1081 | + * @since 1.0.19 |
|
| 1082 | + * @param string $context View or edit context. |
|
| 1083 | + * @return string |
|
| 1084 | + */ |
|
| 1085 | + public function get_zip( $context = 'view' ) { |
|
| 1086 | + return $this->get_prop( 'zip', $context ); |
|
| 1054 | 1087 | } |
| 1055 | 1088 | |
| 1056 | 1089 | /** |
| 1057 | - * Alias of self::get_city(). |
|
| 1058 | - * |
|
| 1059 | - * @since 1.0.19 |
|
| 1060 | - * @param string $context View or edit context. |
|
| 1061 | - * @return string |
|
| 1062 | - */ |
|
| 1063 | - public function get_user_city( $context = 'view' ) { |
|
| 1064 | - return $this->get_city( $context ); |
|
| 1090 | + * Alias of self::get_zip(). |
|
| 1091 | + * |
|
| 1092 | + * @since 1.0.19 |
|
| 1093 | + * @param string $context View or edit context. |
|
| 1094 | + * @return string |
|
| 1095 | + */ |
|
| 1096 | + public function get_user_zip( $context = 'view' ) { |
|
| 1097 | + return $this->get_zip( $context ); |
|
| 1065 | 1098 | } |
| 1066 | 1099 | |
| 1067 | 1100 | /** |
| 1068 | - * Alias of self::get_city(). |
|
| 1069 | - * |
|
| 1070 | - * @since 1.0.19 |
|
| 1071 | - * @param string $context View or edit context. |
|
| 1072 | - * @return string |
|
| 1073 | - */ |
|
| 1074 | - public function get_customer_city( $context = 'view' ) { |
|
| 1075 | - return $this->get_city( $context ); |
|
| 1101 | + * Alias of self::get_zip(). |
|
| 1102 | + * |
|
| 1103 | + * @since 1.0.19 |
|
| 1104 | + * @param string $context View or edit context. |
|
| 1105 | + * @return string |
|
| 1106 | + */ |
|
| 1107 | + public function get_customer_zip( $context = 'view' ) { |
|
| 1108 | + return $this->get_zip( $context ); |
|
| 1076 | 1109 | } |
| 1077 | 1110 | |
| 1078 | 1111 | /** |
| 1079 | - * Get the customer's zip. |
|
| 1080 | - * |
|
| 1081 | - * @since 1.0.19 |
|
| 1082 | - * @param string $context View or edit context. |
|
| 1083 | - * @return string |
|
| 1084 | - */ |
|
| 1085 | - public function get_zip( $context = 'view' ) { |
|
| 1086 | - return $this->get_prop( 'zip', $context ); |
|
| 1112 | + * Get the customer's company. |
|
| 1113 | + * |
|
| 1114 | + * @since 1.0.19 |
|
| 1115 | + * @param string $context View or edit context. |
|
| 1116 | + * @return string |
|
| 1117 | + */ |
|
| 1118 | + public function get_company( $context = 'view' ) { |
|
| 1119 | + return $this->get_prop( 'company', $context ); |
|
| 1087 | 1120 | } |
| 1088 | 1121 | |
| 1089 | 1122 | /** |
| 1090 | - * Alias of self::get_zip(). |
|
| 1091 | - * |
|
| 1092 | - * @since 1.0.19 |
|
| 1093 | - * @param string $context View or edit context. |
|
| 1094 | - * @return string |
|
| 1095 | - */ |
|
| 1096 | - public function get_user_zip( $context = 'view' ) { |
|
| 1097 | - return $this->get_zip( $context ); |
|
| 1123 | + * Alias of self::get_company(). |
|
| 1124 | + * |
|
| 1125 | + * @since 1.0.19 |
|
| 1126 | + * @param string $context View or edit context. |
|
| 1127 | + * @return string |
|
| 1128 | + */ |
|
| 1129 | + public function get_user_company( $context = 'view' ) { |
|
| 1130 | + return $this->get_company( $context ); |
|
| 1098 | 1131 | } |
| 1099 | 1132 | |
| 1100 | 1133 | /** |
| 1101 | - * Alias of self::get_zip(). |
|
| 1102 | - * |
|
| 1103 | - * @since 1.0.19 |
|
| 1104 | - * @param string $context View or edit context. |
|
| 1105 | - * @return string |
|
| 1106 | - */ |
|
| 1107 | - public function get_customer_zip( $context = 'view' ) { |
|
| 1108 | - return $this->get_zip( $context ); |
|
| 1134 | + * Alias of self::get_company(). |
|
| 1135 | + * |
|
| 1136 | + * @since 1.0.19 |
|
| 1137 | + * @param string $context View or edit context. |
|
| 1138 | + * @return string |
|
| 1139 | + */ |
|
| 1140 | + public function get_customer_company( $context = 'view' ) { |
|
| 1141 | + return $this->get_company( $context ); |
|
| 1109 | 1142 | } |
| 1110 | 1143 | |
| 1111 | 1144 | /** |
| 1112 | - * Get the customer's company. |
|
| 1113 | - * |
|
| 1114 | - * @since 1.0.19 |
|
| 1115 | - * @param string $context View or edit context. |
|
| 1116 | - * @return string |
|
| 1117 | - */ |
|
| 1118 | - public function get_company( $context = 'view' ) { |
|
| 1119 | - return $this->get_prop( 'company', $context ); |
|
| 1145 | + * Get the customer's vat number. |
|
| 1146 | + * |
|
| 1147 | + * @since 1.0.19 |
|
| 1148 | + * @param string $context View or edit context. |
|
| 1149 | + * @return string |
|
| 1150 | + */ |
|
| 1151 | + public function get_vat_number( $context = 'view' ) { |
|
| 1152 | + return $this->get_prop( 'vat_number', $context ); |
|
| 1120 | 1153 | } |
| 1121 | 1154 | |
| 1122 | 1155 | /** |
| 1123 | - * Alias of self::get_company(). |
|
| 1124 | - * |
|
| 1125 | - * @since 1.0.19 |
|
| 1126 | - * @param string $context View or edit context. |
|
| 1127 | - * @return string |
|
| 1128 | - */ |
|
| 1129 | - public function get_user_company( $context = 'view' ) { |
|
| 1130 | - return $this->get_company( $context ); |
|
| 1156 | + * Alias of self::get_vat_number(). |
|
| 1157 | + * |
|
| 1158 | + * @since 1.0.19 |
|
| 1159 | + * @param string $context View or edit context. |
|
| 1160 | + * @return string |
|
| 1161 | + */ |
|
| 1162 | + public function get_user_vat_number( $context = 'view' ) { |
|
| 1163 | + return $this->get_vat_number( $context ); |
|
| 1131 | 1164 | } |
| 1132 | 1165 | |
| 1133 | 1166 | /** |
| 1134 | - * Alias of self::get_company(). |
|
| 1135 | - * |
|
| 1136 | - * @since 1.0.19 |
|
| 1137 | - * @param string $context View or edit context. |
|
| 1138 | - * @return string |
|
| 1139 | - */ |
|
| 1140 | - public function get_customer_company( $context = 'view' ) { |
|
| 1141 | - return $this->get_company( $context ); |
|
| 1167 | + * Alias of self::get_vat_number(). |
|
| 1168 | + * |
|
| 1169 | + * @since 1.0.19 |
|
| 1170 | + * @param string $context View or edit context. |
|
| 1171 | + * @return string |
|
| 1172 | + */ |
|
| 1173 | + public function get_customer_vat_number( $context = 'view' ) { |
|
| 1174 | + return $this->get_vat_number( $context ); |
|
| 1142 | 1175 | } |
| 1143 | 1176 | |
| 1144 | 1177 | /** |
| 1145 | - * Get the customer's vat number. |
|
| 1146 | - * |
|
| 1147 | - * @since 1.0.19 |
|
| 1148 | - * @param string $context View or edit context. |
|
| 1149 | - * @return string |
|
| 1150 | - */ |
|
| 1151 | - public function get_vat_number( $context = 'view' ) { |
|
| 1152 | - return $this->get_prop( 'vat_number', $context ); |
|
| 1178 | + * Get the customer's vat rate. |
|
| 1179 | + * |
|
| 1180 | + * @since 1.0.19 |
|
| 1181 | + * @param string $context View or edit context. |
|
| 1182 | + * @return string |
|
| 1183 | + */ |
|
| 1184 | + public function get_vat_rate( $context = 'view' ) { |
|
| 1185 | + return $this->get_prop( 'vat_rate', $context ); |
|
| 1153 | 1186 | } |
| 1154 | 1187 | |
| 1155 | 1188 | /** |
| 1156 | - * Alias of self::get_vat_number(). |
|
| 1157 | - * |
|
| 1158 | - * @since 1.0.19 |
|
| 1159 | - * @param string $context View or edit context. |
|
| 1160 | - * @return string |
|
| 1161 | - */ |
|
| 1162 | - public function get_user_vat_number( $context = 'view' ) { |
|
| 1163 | - return $this->get_vat_number( $context ); |
|
| 1189 | + * Alias of self::get_vat_rate(). |
|
| 1190 | + * |
|
| 1191 | + * @since 1.0.19 |
|
| 1192 | + * @param string $context View or edit context. |
|
| 1193 | + * @return string |
|
| 1194 | + */ |
|
| 1195 | + public function get_user_vat_rate( $context = 'view' ) { |
|
| 1196 | + return $this->get_vat_rate( $context ); |
|
| 1164 | 1197 | } |
| 1165 | 1198 | |
| 1166 | 1199 | /** |
| 1167 | - * Alias of self::get_vat_number(). |
|
| 1168 | - * |
|
| 1169 | - * @since 1.0.19 |
|
| 1170 | - * @param string $context View or edit context. |
|
| 1171 | - * @return string |
|
| 1172 | - */ |
|
| 1173 | - public function get_customer_vat_number( $context = 'view' ) { |
|
| 1174 | - return $this->get_vat_number( $context ); |
|
| 1200 | + * Alias of self::get_vat_rate(). |
|
| 1201 | + * |
|
| 1202 | + * @since 1.0.19 |
|
| 1203 | + * @param string $context View or edit context. |
|
| 1204 | + * @return string |
|
| 1205 | + */ |
|
| 1206 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1207 | + return $this->get_vat_rate( $context ); |
|
| 1175 | 1208 | } |
| 1176 | 1209 | |
| 1177 | 1210 | /** |
| 1178 | - * Get the customer's vat rate. |
|
| 1179 | - * |
|
| 1180 | - * @since 1.0.19 |
|
| 1181 | - * @param string $context View or edit context. |
|
| 1182 | - * @return string |
|
| 1183 | - */ |
|
| 1184 | - public function get_vat_rate( $context = 'view' ) { |
|
| 1185 | - return $this->get_prop( 'vat_rate', $context ); |
|
| 1211 | + * Get the customer's address. |
|
| 1212 | + * |
|
| 1213 | + * @since 1.0.19 |
|
| 1214 | + * @param string $context View or edit context. |
|
| 1215 | + * @return string |
|
| 1216 | + */ |
|
| 1217 | + public function get_address( $context = 'view' ) { |
|
| 1218 | + return $this->get_prop( 'address', $context ); |
|
| 1186 | 1219 | } |
| 1187 | 1220 | |
| 1188 | 1221 | /** |
| 1189 | - * Alias of self::get_vat_rate(). |
|
| 1190 | - * |
|
| 1191 | - * @since 1.0.19 |
|
| 1192 | - * @param string $context View or edit context. |
|
| 1193 | - * @return string |
|
| 1194 | - */ |
|
| 1195 | - public function get_user_vat_rate( $context = 'view' ) { |
|
| 1196 | - return $this->get_vat_rate( $context ); |
|
| 1222 | + * Alias of self::get_address(). |
|
| 1223 | + * |
|
| 1224 | + * @since 1.0.19 |
|
| 1225 | + * @param string $context View or edit context. |
|
| 1226 | + * @return string |
|
| 1227 | + */ |
|
| 1228 | + public function get_user_address( $context = 'view' ) { |
|
| 1229 | + return $this->get_address( $context ); |
|
| 1197 | 1230 | } |
| 1198 | 1231 | |
| 1199 | 1232 | /** |
| 1200 | - * Alias of self::get_vat_rate(). |
|
| 1201 | - * |
|
| 1202 | - * @since 1.0.19 |
|
| 1203 | - * @param string $context View or edit context. |
|
| 1204 | - * @return string |
|
| 1205 | - */ |
|
| 1206 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1207 | - return $this->get_vat_rate( $context ); |
|
| 1233 | + * Alias of self::get_address(). |
|
| 1234 | + * |
|
| 1235 | + * @since 1.0.19 |
|
| 1236 | + * @param string $context View or edit context. |
|
| 1237 | + * @return string |
|
| 1238 | + */ |
|
| 1239 | + public function get_customer_address( $context = 'view' ) { |
|
| 1240 | + return $this->get_address( $context ); |
|
| 1208 | 1241 | } |
| 1209 | 1242 | |
| 1210 | 1243 | /** |
| 1211 | - * Get the customer's address. |
|
| 1212 | - * |
|
| 1213 | - * @since 1.0.19 |
|
| 1214 | - * @param string $context View or edit context. |
|
| 1215 | - * @return string |
|
| 1216 | - */ |
|
| 1217 | - public function get_address( $context = 'view' ) { |
|
| 1218 | - return $this->get_prop( 'address', $context ); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - /** |
|
| 1222 | - * Alias of self::get_address(). |
|
| 1223 | - * |
|
| 1224 | - * @since 1.0.19 |
|
| 1225 | - * @param string $context View or edit context. |
|
| 1226 | - * @return string |
|
| 1227 | - */ |
|
| 1228 | - public function get_user_address( $context = 'view' ) { |
|
| 1229 | - return $this->get_address( $context ); |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - /** |
|
| 1233 | - * Alias of self::get_address(). |
|
| 1234 | - * |
|
| 1235 | - * @since 1.0.19 |
|
| 1236 | - * @param string $context View or edit context. |
|
| 1237 | - * @return string |
|
| 1238 | - */ |
|
| 1239 | - public function get_customer_address( $context = 'view' ) { |
|
| 1240 | - return $this->get_address( $context ); |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * Get whether the customer has viewed the invoice or not. |
|
| 1245 | - * |
|
| 1246 | - * @since 1.0.19 |
|
| 1247 | - * @param string $context View or edit context. |
|
| 1248 | - * @return bool |
|
| 1249 | - */ |
|
| 1250 | - public function get_is_viewed( $context = 'view' ) { |
|
| 1251 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Get other recipients for invoice communications. |
|
| 1256 | - * |
|
| 1257 | - * @since 1.0.19 |
|
| 1258 | - * @param string $context View or edit context. |
|
| 1259 | - * @return bool |
|
| 1260 | - */ |
|
| 1261 | - public function get_email_cc( $context = 'view' ) { |
|
| 1262 | - return $this->get_prop( 'email_cc', $context ); |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - /** |
|
| 1266 | - * Get invoice template. |
|
| 1267 | - * |
|
| 1268 | - * @since 1.0.19 |
|
| 1269 | - * @param string $context View or edit context. |
|
| 1270 | - * @return bool |
|
| 1271 | - */ |
|
| 1272 | - public function get_template( $context = 'view' ) { |
|
| 1273 | - return $this->get_prop( 'template', $context ); |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * Get whether the customer has confirmed their address. |
|
| 1278 | - * |
|
| 1279 | - * @since 1.0.19 |
|
| 1280 | - * @param string $context View or edit context. |
|
| 1281 | - * @return bool |
|
| 1282 | - */ |
|
| 1283 | - public function get_address_confirmed( $context = 'view' ) { |
|
| 1284 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1285 | - } |
|
| 1286 | - |
|
| 1287 | - /** |
|
| 1288 | - * Alias of self::get_address_confirmed(). |
|
| 1289 | - * |
|
| 1290 | - * @since 1.0.19 |
|
| 1291 | - * @param string $context View or edit context. |
|
| 1292 | - * @return bool |
|
| 1293 | - */ |
|
| 1294 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1295 | - return $this->get_address_confirmed( $context ); |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - /** |
|
| 1299 | - * Alias of self::get_address(). |
|
| 1300 | - * |
|
| 1301 | - * @since 1.0.19 |
|
| 1302 | - * @param string $context View or edit context. |
|
| 1303 | - * @return bool |
|
| 1304 | - */ |
|
| 1305 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1306 | - return $this->get_address_confirmed( $context ); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * Get the invoice subtotal. |
|
| 1311 | - * |
|
| 1312 | - * @since 1.0.19 |
|
| 1313 | - * @param string $context View or edit context. |
|
| 1314 | - * @return float |
|
| 1315 | - */ |
|
| 1316 | - public function get_subtotal( $context = 'view' ) { |
|
| 1244 | + * Get whether the customer has viewed the invoice or not. |
|
| 1245 | + * |
|
| 1246 | + * @since 1.0.19 |
|
| 1247 | + * @param string $context View or edit context. |
|
| 1248 | + * @return bool |
|
| 1249 | + */ |
|
| 1250 | + public function get_is_viewed( $context = 'view' ) { |
|
| 1251 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Get other recipients for invoice communications. |
|
| 1256 | + * |
|
| 1257 | + * @since 1.0.19 |
|
| 1258 | + * @param string $context View or edit context. |
|
| 1259 | + * @return bool |
|
| 1260 | + */ |
|
| 1261 | + public function get_email_cc( $context = 'view' ) { |
|
| 1262 | + return $this->get_prop( 'email_cc', $context ); |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + /** |
|
| 1266 | + * Get invoice template. |
|
| 1267 | + * |
|
| 1268 | + * @since 1.0.19 |
|
| 1269 | + * @param string $context View or edit context. |
|
| 1270 | + * @return bool |
|
| 1271 | + */ |
|
| 1272 | + public function get_template( $context = 'view' ) { |
|
| 1273 | + return $this->get_prop( 'template', $context ); |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * Get whether the customer has confirmed their address. |
|
| 1278 | + * |
|
| 1279 | + * @since 1.0.19 |
|
| 1280 | + * @param string $context View or edit context. |
|
| 1281 | + * @return bool |
|
| 1282 | + */ |
|
| 1283 | + public function get_address_confirmed( $context = 'view' ) { |
|
| 1284 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1285 | + } |
|
| 1286 | + |
|
| 1287 | + /** |
|
| 1288 | + * Alias of self::get_address_confirmed(). |
|
| 1289 | + * |
|
| 1290 | + * @since 1.0.19 |
|
| 1291 | + * @param string $context View or edit context. |
|
| 1292 | + * @return bool |
|
| 1293 | + */ |
|
| 1294 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1295 | + return $this->get_address_confirmed( $context ); |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + /** |
|
| 1299 | + * Alias of self::get_address(). |
|
| 1300 | + * |
|
| 1301 | + * @since 1.0.19 |
|
| 1302 | + * @param string $context View or edit context. |
|
| 1303 | + * @return bool |
|
| 1304 | + */ |
|
| 1305 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1306 | + return $this->get_address_confirmed( $context ); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * Get the invoice subtotal. |
|
| 1311 | + * |
|
| 1312 | + * @since 1.0.19 |
|
| 1313 | + * @param string $context View or edit context. |
|
| 1314 | + * @return float |
|
| 1315 | + */ |
|
| 1316 | + public function get_subtotal( $context = 'view' ) { |
|
| 1317 | 1317 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
| 1318 | 1318 | |
| 1319 | 1319 | // Backwards compatibility. |
@@ -1325,165 +1325,165 @@ discard block |
||
| 1325 | 1325 | } |
| 1326 | 1326 | |
| 1327 | 1327 | /** |
| 1328 | - * Get the invoice discount total. |
|
| 1329 | - * |
|
| 1330 | - * @since 1.0.19 |
|
| 1331 | - * @param string $context View or edit context. |
|
| 1332 | - * @return float |
|
| 1333 | - */ |
|
| 1334 | - public function get_total_discount( $context = 'view' ) { |
|
| 1335 | - return (float) $this->get_prop( 'total_discount', $context ); |
|
| 1328 | + * Get the invoice discount total. |
|
| 1329 | + * |
|
| 1330 | + * @since 1.0.19 |
|
| 1331 | + * @param string $context View or edit context. |
|
| 1332 | + * @return float |
|
| 1333 | + */ |
|
| 1334 | + public function get_total_discount( $context = 'view' ) { |
|
| 1335 | + return (float) $this->get_prop( 'total_discount', $context ); |
|
| 1336 | 1336 | } |
| 1337 | 1337 | |
| 1338 | 1338 | /** |
| 1339 | - * Get the invoice tax total. |
|
| 1340 | - * |
|
| 1341 | - * @since 1.0.19 |
|
| 1342 | - * @param string $context View or edit context. |
|
| 1343 | - * @return float |
|
| 1344 | - */ |
|
| 1345 | - public function get_total_tax( $context = 'view' ) { |
|
| 1346 | - return (float) $this->get_prop( 'total_tax', $context ); |
|
| 1347 | - } |
|
| 1339 | + * Get the invoice tax total. |
|
| 1340 | + * |
|
| 1341 | + * @since 1.0.19 |
|
| 1342 | + * @param string $context View or edit context. |
|
| 1343 | + * @return float |
|
| 1344 | + */ |
|
| 1345 | + public function get_total_tax( $context = 'view' ) { |
|
| 1346 | + return (float) $this->get_prop( 'total_tax', $context ); |
|
| 1347 | + } |
|
| 1348 | 1348 | |
| 1349 | - /** |
|
| 1350 | - * @deprecated |
|
| 1351 | - */ |
|
| 1352 | - public function get_final_tax( $currency = false ) { |
|
| 1353 | - $tax = $this->get_total_tax(); |
|
| 1349 | + /** |
|
| 1350 | + * @deprecated |
|
| 1351 | + */ |
|
| 1352 | + public function get_final_tax( $currency = false ) { |
|
| 1353 | + $tax = $this->get_total_tax(); |
|
| 1354 | 1354 | |
| 1355 | 1355 | if ( $currency ) { |
| 1356 | - return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
| 1356 | + return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | 1359 | return $tax; |
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | 1362 | /** |
| 1363 | - * Get the invoice fees total. |
|
| 1364 | - * |
|
| 1365 | - * @since 1.0.19 |
|
| 1366 | - * @param string $context View or edit context. |
|
| 1367 | - * @return float |
|
| 1368 | - */ |
|
| 1369 | - public function get_total_fees( $context = 'view' ) { |
|
| 1370 | - return (float) $this->get_prop( 'total_fees', $context ); |
|
| 1363 | + * Get the invoice fees total. |
|
| 1364 | + * |
|
| 1365 | + * @since 1.0.19 |
|
| 1366 | + * @param string $context View or edit context. |
|
| 1367 | + * @return float |
|
| 1368 | + */ |
|
| 1369 | + public function get_total_fees( $context = 'view' ) { |
|
| 1370 | + return (float) $this->get_prop( 'total_fees', $context ); |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | /** |
| 1374 | - * Alias for self::get_total_fees(). |
|
| 1375 | - * |
|
| 1376 | - * @since 1.0.19 |
|
| 1377 | - * @param string $context View or edit context. |
|
| 1378 | - * @return float |
|
| 1379 | - */ |
|
| 1380 | - public function get_fees_total( $context = 'view' ) { |
|
| 1381 | - return $this->get_total_fees( $context ); |
|
| 1374 | + * Alias for self::get_total_fees(). |
|
| 1375 | + * |
|
| 1376 | + * @since 1.0.19 |
|
| 1377 | + * @param string $context View or edit context. |
|
| 1378 | + * @return float |
|
| 1379 | + */ |
|
| 1380 | + public function get_fees_total( $context = 'view' ) { |
|
| 1381 | + return $this->get_total_fees( $context ); |
|
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | 1384 | /** |
| 1385 | - * Get the invoice total. |
|
| 1386 | - * |
|
| 1387 | - * @since 1.0.19 |
|
| 1385 | + * Get the invoice total. |
|
| 1386 | + * |
|
| 1387 | + * @since 1.0.19 |
|
| 1388 | 1388 | * @return float |
| 1389 | - */ |
|
| 1390 | - public function get_total() { |
|
| 1391 | - $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
| 1392 | - return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
| 1393 | - } |
|
| 1389 | + */ |
|
| 1390 | + public function get_total() { |
|
| 1391 | + $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
| 1392 | + return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
| 1393 | + } |
|
| 1394 | 1394 | |
| 1395 | - /** |
|
| 1396 | - * Get the invoice totals. |
|
| 1397 | - * |
|
| 1398 | - * @since 1.0.19 |
|
| 1395 | + /** |
|
| 1396 | + * Get the invoice totals. |
|
| 1397 | + * |
|
| 1398 | + * @since 1.0.19 |
|
| 1399 | 1399 | * @return float |
| 1400 | - */ |
|
| 1401 | - public function get_totals() { |
|
| 1402 | - return $this->totals; |
|
| 1400 | + */ |
|
| 1401 | + public function get_totals() { |
|
| 1402 | + return $this->totals; |
|
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | /** |
| 1406 | - * Get the initial invoice total. |
|
| 1407 | - * |
|
| 1408 | - * @since 1.0.19 |
|
| 1406 | + * Get the initial invoice total. |
|
| 1407 | + * |
|
| 1408 | + * @since 1.0.19 |
|
| 1409 | 1409 | * @param string $context View or edit context. |
| 1410 | 1410 | * @return float |
| 1411 | - */ |
|
| 1411 | + */ |
|
| 1412 | 1412 | public function get_initial_total() { |
| 1413 | 1413 | |
| 1414 | - if ( empty( $this->totals ) ) { |
|
| 1415 | - $this->recalculate_total(); |
|
| 1416 | - } |
|
| 1414 | + if ( empty( $this->totals ) ) { |
|
| 1415 | + $this->recalculate_total(); |
|
| 1416 | + } |
|
| 1417 | 1417 | |
| 1418 | - $tax = $this->totals['tax']['initial']; |
|
| 1419 | - $fee = $this->totals['fee']['initial']; |
|
| 1420 | - $discount = $this->totals['discount']['initial']; |
|
| 1421 | - $subtotal = $this->totals['subtotal']['initial']; |
|
| 1422 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1418 | + $tax = $this->totals['tax']['initial']; |
|
| 1419 | + $fee = $this->totals['fee']['initial']; |
|
| 1420 | + $discount = $this->totals['discount']['initial']; |
|
| 1421 | + $subtotal = $this->totals['subtotal']['initial']; |
|
| 1422 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1423 | 1423 | |
| 1424 | - if ( 0 > $total ) { |
|
| 1425 | - $total = 0; |
|
| 1426 | - } |
|
| 1424 | + if ( 0 > $total ) { |
|
| 1425 | + $total = 0; |
|
| 1426 | + } |
|
| 1427 | 1427 | |
| 1428 | 1428 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
| 1429 | - } |
|
| 1429 | + } |
|
| 1430 | 1430 | |
| 1431 | - /** |
|
| 1432 | - * Get the recurring invoice total. |
|
| 1433 | - * |
|
| 1434 | - * @since 1.0.19 |
|
| 1431 | + /** |
|
| 1432 | + * Get the recurring invoice total. |
|
| 1433 | + * |
|
| 1434 | + * @since 1.0.19 |
|
| 1435 | 1435 | * @param string $context View or edit context. |
| 1436 | 1436 | * @return float |
| 1437 | - */ |
|
| 1437 | + */ |
|
| 1438 | 1438 | public function get_recurring_total() { |
| 1439 | 1439 | |
| 1440 | - if ( empty( $this->totals ) ) { |
|
| 1441 | - $this->recalculate_total(); |
|
| 1442 | - } |
|
| 1440 | + if ( empty( $this->totals ) ) { |
|
| 1441 | + $this->recalculate_total(); |
|
| 1442 | + } |
|
| 1443 | 1443 | |
| 1444 | - $tax = $this->totals['tax']['recurring']; |
|
| 1445 | - $fee = $this->totals['fee']['recurring']; |
|
| 1446 | - $discount = $this->totals['discount']['recurring']; |
|
| 1447 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1448 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1444 | + $tax = $this->totals['tax']['recurring']; |
|
| 1445 | + $fee = $this->totals['fee']['recurring']; |
|
| 1446 | + $discount = $this->totals['discount']['recurring']; |
|
| 1447 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1448 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1449 | 1449 | |
| 1450 | - if ( 0 > $total ) { |
|
| 1451 | - $total = 0; |
|
| 1452 | - } |
|
| 1450 | + if ( 0 > $total ) { |
|
| 1451 | + $total = 0; |
|
| 1452 | + } |
|
| 1453 | 1453 | |
| 1454 | 1454 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
| 1455 | - } |
|
| 1455 | + } |
|
| 1456 | 1456 | |
| 1457 | - /** |
|
| 1458 | - * Returns recurring payment details. |
|
| 1459 | - * |
|
| 1460 | - * @since 1.0.19 |
|
| 1457 | + /** |
|
| 1458 | + * Returns recurring payment details. |
|
| 1459 | + * |
|
| 1460 | + * @since 1.0.19 |
|
| 1461 | 1461 | * @param string $field Optionally provide a field to return. |
| 1462 | - * @param string $currency Whether to include the currency. |
|
| 1462 | + * @param string $currency Whether to include the currency. |
|
| 1463 | 1463 | * @return float |
| 1464 | - */ |
|
| 1464 | + */ |
|
| 1465 | 1465 | public function get_recurring_details( $field = '', $currency = false ) { |
| 1466 | 1466 | |
| 1467 | - // Maybe recalculate totals. |
|
| 1468 | - if ( empty( $this->totals ) ) { |
|
| 1469 | - $this->recalculate_total(); |
|
| 1470 | - } |
|
| 1467 | + // Maybe recalculate totals. |
|
| 1468 | + if ( empty( $this->totals ) ) { |
|
| 1469 | + $this->recalculate_total(); |
|
| 1470 | + } |
|
| 1471 | 1471 | |
| 1472 | - // Prepare recurring totals. |
|
| 1472 | + // Prepare recurring totals. |
|
| 1473 | 1473 | $data = apply_filters( |
| 1474 | - 'wpinv_get_invoice_recurring_details', |
|
| 1475 | - array( |
|
| 1476 | - 'cart_details' => $this->get_cart_details(), |
|
| 1477 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1478 | - 'discount' => $this->totals['discount']['recurring'], |
|
| 1479 | - 'tax' => $this->totals['tax']['recurring'], |
|
| 1480 | - 'fee' => $this->totals['fee']['recurring'], |
|
| 1481 | - 'total' => $this->get_recurring_total(), |
|
| 1482 | - ), |
|
| 1483 | - $this, |
|
| 1484 | - $field, |
|
| 1485 | - $currency |
|
| 1486 | - ); |
|
| 1474 | + 'wpinv_get_invoice_recurring_details', |
|
| 1475 | + array( |
|
| 1476 | + 'cart_details' => $this->get_cart_details(), |
|
| 1477 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1478 | + 'discount' => $this->totals['discount']['recurring'], |
|
| 1479 | + 'tax' => $this->totals['tax']['recurring'], |
|
| 1480 | + 'fee' => $this->totals['fee']['recurring'], |
|
| 1481 | + 'total' => $this->get_recurring_total(), |
|
| 1482 | + ), |
|
| 1483 | + $this, |
|
| 1484 | + $field, |
|
| 1485 | + $currency |
|
| 1486 | + ); |
|
| 1487 | 1487 | |
| 1488 | 1488 | if ( isset( $data[$field] ) ) { |
| 1489 | 1489 | return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
@@ -1493,145 +1493,145 @@ discard block |
||
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | 1495 | /** |
| 1496 | - * Get the invoice fees. |
|
| 1497 | - * |
|
| 1498 | - * @since 1.0.19 |
|
| 1499 | - * @param string $context View or edit context. |
|
| 1500 | - * @return array |
|
| 1501 | - */ |
|
| 1502 | - public function get_fees( $context = 'view' ) { |
|
| 1503 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1496 | + * Get the invoice fees. |
|
| 1497 | + * |
|
| 1498 | + * @since 1.0.19 |
|
| 1499 | + * @param string $context View or edit context. |
|
| 1500 | + * @return array |
|
| 1501 | + */ |
|
| 1502 | + public function get_fees( $context = 'view' ) { |
|
| 1503 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | /** |
| 1507 | - * Get the invoice discounts. |
|
| 1508 | - * |
|
| 1509 | - * @since 1.0.19 |
|
| 1510 | - * @param string $context View or edit context. |
|
| 1511 | - * @return array |
|
| 1512 | - */ |
|
| 1513 | - public function get_discounts( $context = 'view' ) { |
|
| 1514 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1507 | + * Get the invoice discounts. |
|
| 1508 | + * |
|
| 1509 | + * @since 1.0.19 |
|
| 1510 | + * @param string $context View or edit context. |
|
| 1511 | + * @return array |
|
| 1512 | + */ |
|
| 1513 | + public function get_discounts( $context = 'view' ) { |
|
| 1514 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | /** |
| 1518 | - * Get the invoice taxes. |
|
| 1519 | - * |
|
| 1520 | - * @since 1.0.19 |
|
| 1521 | - * @param string $context View or edit context. |
|
| 1522 | - * @return array |
|
| 1523 | - */ |
|
| 1524 | - public function get_taxes( $context = 'view' ) { |
|
| 1525 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1518 | + * Get the invoice taxes. |
|
| 1519 | + * |
|
| 1520 | + * @since 1.0.19 |
|
| 1521 | + * @param string $context View or edit context. |
|
| 1522 | + * @return array |
|
| 1523 | + */ |
|
| 1524 | + public function get_taxes( $context = 'view' ) { |
|
| 1525 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | 1528 | /** |
| 1529 | - * Get the invoice items. |
|
| 1530 | - * |
|
| 1531 | - * @since 1.0.19 |
|
| 1532 | - * @param string $context View or edit context. |
|
| 1533 | - * @return GetPaid_Form_Item[] |
|
| 1534 | - */ |
|
| 1535 | - public function get_items( $context = 'view' ) { |
|
| 1529 | + * Get the invoice items. |
|
| 1530 | + * |
|
| 1531 | + * @since 1.0.19 |
|
| 1532 | + * @param string $context View or edit context. |
|
| 1533 | + * @return GetPaid_Form_Item[] |
|
| 1534 | + */ |
|
| 1535 | + public function get_items( $context = 'view' ) { |
|
| 1536 | 1536 | return $this->get_prop( 'items', $context ); |
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | /** |
| 1540 | - * Get the invoice's payment form. |
|
| 1541 | - * |
|
| 1542 | - * @since 1.0.19 |
|
| 1543 | - * @param string $context View or edit context. |
|
| 1544 | - * @return int |
|
| 1545 | - */ |
|
| 1546 | - public function get_payment_form( $context = 'view' ) { |
|
| 1547 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1540 | + * Get the invoice's payment form. |
|
| 1541 | + * |
|
| 1542 | + * @since 1.0.19 |
|
| 1543 | + * @param string $context View or edit context. |
|
| 1544 | + * @return int |
|
| 1545 | + */ |
|
| 1546 | + public function get_payment_form( $context = 'view' ) { |
|
| 1547 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | /** |
| 1551 | - * Get the invoice's submission id. |
|
| 1552 | - * |
|
| 1553 | - * @since 1.0.19 |
|
| 1554 | - * @param string $context View or edit context. |
|
| 1555 | - * @return string |
|
| 1556 | - */ |
|
| 1557 | - public function get_submission_id( $context = 'view' ) { |
|
| 1558 | - return $this->get_prop( 'submission_id', $context ); |
|
| 1551 | + * Get the invoice's submission id. |
|
| 1552 | + * |
|
| 1553 | + * @since 1.0.19 |
|
| 1554 | + * @param string $context View or edit context. |
|
| 1555 | + * @return string |
|
| 1556 | + */ |
|
| 1557 | + public function get_submission_id( $context = 'view' ) { |
|
| 1558 | + return $this->get_prop( 'submission_id', $context ); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | /** |
| 1562 | - * Get the invoice's discount code. |
|
| 1563 | - * |
|
| 1564 | - * @since 1.0.19 |
|
| 1565 | - * @param string $context View or edit context. |
|
| 1566 | - * @return string |
|
| 1567 | - */ |
|
| 1568 | - public function get_discount_code( $context = 'view' ) { |
|
| 1569 | - return $this->get_prop( 'discount_code', $context ); |
|
| 1562 | + * Get the invoice's discount code. |
|
| 1563 | + * |
|
| 1564 | + * @since 1.0.19 |
|
| 1565 | + * @param string $context View or edit context. |
|
| 1566 | + * @return string |
|
| 1567 | + */ |
|
| 1568 | + public function get_discount_code( $context = 'view' ) { |
|
| 1569 | + return $this->get_prop( 'discount_code', $context ); |
|
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | 1572 | /** |
| 1573 | - * Get the invoice's gateway. |
|
| 1574 | - * |
|
| 1575 | - * @since 1.0.19 |
|
| 1576 | - * @param string $context View or edit context. |
|
| 1577 | - * @return string |
|
| 1578 | - */ |
|
| 1579 | - public function get_gateway( $context = 'view' ) { |
|
| 1580 | - return $this->get_prop( 'gateway', $context ); |
|
| 1573 | + * Get the invoice's gateway. |
|
| 1574 | + * |
|
| 1575 | + * @since 1.0.19 |
|
| 1576 | + * @param string $context View or edit context. |
|
| 1577 | + * @return string |
|
| 1578 | + */ |
|
| 1579 | + public function get_gateway( $context = 'view' ) { |
|
| 1580 | + return $this->get_prop( 'gateway', $context ); |
|
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | /** |
| 1584 | - * Get the invoice's gateway display title. |
|
| 1585 | - * |
|
| 1586 | - * @since 1.0.19 |
|
| 1587 | - * @return string |
|
| 1588 | - */ |
|
| 1584 | + * Get the invoice's gateway display title. |
|
| 1585 | + * |
|
| 1586 | + * @since 1.0.19 |
|
| 1587 | + * @return string |
|
| 1588 | + */ |
|
| 1589 | 1589 | public function get_gateway_title() { |
| 1590 | 1590 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
| 1591 | 1591 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
| 1592 | 1592 | } |
| 1593 | 1593 | |
| 1594 | 1594 | /** |
| 1595 | - * Get the invoice's transaction id. |
|
| 1596 | - * |
|
| 1597 | - * @since 1.0.19 |
|
| 1598 | - * @param string $context View or edit context. |
|
| 1599 | - * @return string |
|
| 1600 | - */ |
|
| 1601 | - public function get_transaction_id( $context = 'view' ) { |
|
| 1602 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 1595 | + * Get the invoice's transaction id. |
|
| 1596 | + * |
|
| 1597 | + * @since 1.0.19 |
|
| 1598 | + * @param string $context View or edit context. |
|
| 1599 | + * @return string |
|
| 1600 | + */ |
|
| 1601 | + public function get_transaction_id( $context = 'view' ) { |
|
| 1602 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 1603 | 1603 | } |
| 1604 | 1604 | |
| 1605 | 1605 | /** |
| 1606 | - * Get the invoice's currency. |
|
| 1607 | - * |
|
| 1608 | - * @since 1.0.19 |
|
| 1609 | - * @param string $context View or edit context. |
|
| 1610 | - * @return string |
|
| 1611 | - */ |
|
| 1612 | - public function get_currency( $context = 'view' ) { |
|
| 1606 | + * Get the invoice's currency. |
|
| 1607 | + * |
|
| 1608 | + * @since 1.0.19 |
|
| 1609 | + * @param string $context View or edit context. |
|
| 1610 | + * @return string |
|
| 1611 | + */ |
|
| 1612 | + public function get_currency( $context = 'view' ) { |
|
| 1613 | 1613 | $currency = $this->get_prop( 'currency', $context ); |
| 1614 | 1614 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
| 1615 | 1615 | } |
| 1616 | 1616 | |
| 1617 | 1617 | /** |
| 1618 | - * Checks if we are charging taxes for this invoice. |
|
| 1619 | - * |
|
| 1620 | - * @since 1.0.19 |
|
| 1621 | - * @param string $context View or edit context. |
|
| 1622 | - * @return bool |
|
| 1623 | - */ |
|
| 1624 | - public function get_disable_taxes( $context = 'view' ) { |
|
| 1618 | + * Checks if we are charging taxes for this invoice. |
|
| 1619 | + * |
|
| 1620 | + * @since 1.0.19 |
|
| 1621 | + * @param string $context View or edit context. |
|
| 1622 | + * @return bool |
|
| 1623 | + */ |
|
| 1624 | + public function get_disable_taxes( $context = 'view' ) { |
|
| 1625 | 1625 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | /** |
| 1629 | - * Retrieves the remote subscription id for an invoice. |
|
| 1630 | - * |
|
| 1631 | - * @since 1.0.19 |
|
| 1632 | - * @param string $context View or edit context. |
|
| 1633 | - * @return int |
|
| 1634 | - */ |
|
| 1629 | + * Retrieves the remote subscription id for an invoice. |
|
| 1630 | + * |
|
| 1631 | + * @since 1.0.19 |
|
| 1632 | + * @param string $context View or edit context. |
|
| 1633 | + * @return int |
|
| 1634 | + */ |
|
| 1635 | 1635 | public function get_subscription_id( $context = 'view' ) { |
| 1636 | 1636 | $subscription_id = $this->get_prop( 'subscription_id', $context ); |
| 1637 | 1637 | |
@@ -1644,12 +1644,12 @@ discard block |
||
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | 1646 | /** |
| 1647 | - * Retrieves the payment meta for an invoice. |
|
| 1648 | - * |
|
| 1649 | - * @since 1.0.19 |
|
| 1650 | - * @param string $context View or edit context. |
|
| 1651 | - * @return array |
|
| 1652 | - */ |
|
| 1647 | + * Retrieves the payment meta for an invoice. |
|
| 1648 | + * |
|
| 1649 | + * @since 1.0.19 |
|
| 1650 | + * @param string $context View or edit context. |
|
| 1651 | + * @return array |
|
| 1652 | + */ |
|
| 1653 | 1653 | public function get_payment_meta( $context = 'view' ) { |
| 1654 | 1654 | |
| 1655 | 1655 | return array( |
@@ -1669,11 +1669,11 @@ discard block |
||
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | /** |
| 1672 | - * Retrieves the cart details for an invoice. |
|
| 1673 | - * |
|
| 1674 | - * @since 1.0.19 |
|
| 1675 | - * @return array |
|
| 1676 | - */ |
|
| 1672 | + * Retrieves the cart details for an invoice. |
|
| 1673 | + * |
|
| 1674 | + * @since 1.0.19 |
|
| 1675 | + * @return array |
|
| 1676 | + */ |
|
| 1677 | 1677 | public function get_cart_details() { |
| 1678 | 1678 | $items = $this->get_items(); |
| 1679 | 1679 | $cart_details = array(); |
@@ -1683,16 +1683,16 @@ discard block |
||
| 1683 | 1683 | } |
| 1684 | 1684 | |
| 1685 | 1685 | return $cart_details; |
| 1686 | - } |
|
| 1686 | + } |
|
| 1687 | 1687 | |
| 1688 | - /** |
|
| 1689 | - * Retrieves the recurring item. |
|
| 1690 | - * |
|
| 1691 | - * @return null|GetPaid_Form_Item|int |
|
| 1692 | - */ |
|
| 1693 | - public function get_recurring( $object = false ) { |
|
| 1688 | + /** |
|
| 1689 | + * Retrieves the recurring item. |
|
| 1690 | + * |
|
| 1691 | + * @return null|GetPaid_Form_Item|int |
|
| 1692 | + */ |
|
| 1693 | + public function get_recurring( $object = false ) { |
|
| 1694 | 1694 | |
| 1695 | - // Are we returning an object? |
|
| 1695 | + // Are we returning an object? |
|
| 1696 | 1696 | if ( $object ) { |
| 1697 | 1697 | return $this->get_item( $this->recurring_item ); |
| 1698 | 1698 | } |
@@ -1700,100 +1700,100 @@ discard block |
||
| 1700 | 1700 | return $this->recurring_item; |
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | - /** |
|
| 1704 | - * Retrieves the subscription name. |
|
| 1705 | - * |
|
| 1706 | - * @since 1.0.19 |
|
| 1707 | - * @return string |
|
| 1708 | - */ |
|
| 1709 | - public function get_subscription_name() { |
|
| 1703 | + /** |
|
| 1704 | + * Retrieves the subscription name. |
|
| 1705 | + * |
|
| 1706 | + * @since 1.0.19 |
|
| 1707 | + * @return string |
|
| 1708 | + */ |
|
| 1709 | + public function get_subscription_name() { |
|
| 1710 | 1710 | |
| 1711 | - // Retrieve the recurring name |
|
| 1711 | + // Retrieve the recurring name |
|
| 1712 | 1712 | $item = $this->get_recurring( true ); |
| 1713 | 1713 | |
| 1714 | - // Abort if it does not exist. |
|
| 1714 | + // Abort if it does not exist. |
|
| 1715 | 1715 | if ( empty( $item ) ) { |
| 1716 | 1716 | return ''; |
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | - // Return the item name. |
|
| 1719 | + // Return the item name. |
|
| 1720 | 1720 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
| 1721 | - } |
|
| 1722 | - |
|
| 1723 | - /** |
|
| 1724 | - * Retrieves the view url. |
|
| 1725 | - * |
|
| 1726 | - * @since 1.0.19 |
|
| 1727 | - * @return string |
|
| 1728 | - */ |
|
| 1729 | - public function get_view_url() { |
|
| 1721 | + } |
|
| 1722 | + |
|
| 1723 | + /** |
|
| 1724 | + * Retrieves the view url. |
|
| 1725 | + * |
|
| 1726 | + * @since 1.0.19 |
|
| 1727 | + * @return string |
|
| 1728 | + */ |
|
| 1729 | + public function get_view_url() { |
|
| 1730 | 1730 | $invoice_url = get_permalink( $this->get_id() ); |
| 1731 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1731 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1732 | 1732 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
| 1733 | - } |
|
| 1733 | + } |
|
| 1734 | 1734 | |
| 1735 | - /** |
|
| 1736 | - * Retrieves the payment url. |
|
| 1737 | - * |
|
| 1738 | - * @since 1.0.19 |
|
| 1739 | - * @return string |
|
| 1740 | - */ |
|
| 1741 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1735 | + /** |
|
| 1736 | + * Retrieves the payment url. |
|
| 1737 | + * |
|
| 1738 | + * @since 1.0.19 |
|
| 1739 | + * @return string |
|
| 1740 | + */ |
|
| 1741 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1742 | 1742 | |
| 1743 | - // Retrieve the checkout url. |
|
| 1743 | + // Retrieve the checkout url. |
|
| 1744 | 1744 | $pay_url = wpinv_get_checkout_uri(); |
| 1745 | 1745 | |
| 1746 | - // Maybe force ssl. |
|
| 1746 | + // Maybe force ssl. |
|
| 1747 | 1747 | if ( is_ssl() ) { |
| 1748 | 1748 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
| 1749 | 1749 | } |
| 1750 | 1750 | |
| 1751 | - // Add the invoice key. |
|
| 1752 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1751 | + // Add the invoice key. |
|
| 1752 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1753 | 1753 | |
| 1754 | - // (Maybe?) add a secret |
|
| 1754 | + // (Maybe?) add a secret |
|
| 1755 | 1755 | if ( $secret ) { |
| 1756 | 1756 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
| 1757 | 1757 | } |
| 1758 | 1758 | |
| 1759 | 1759 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
| 1760 | - } |
|
| 1760 | + } |
|
| 1761 | 1761 | |
| 1762 | - /** |
|
| 1763 | - * Retrieves the receipt url. |
|
| 1764 | - * |
|
| 1765 | - * @since 1.0.19 |
|
| 1766 | - * @return string |
|
| 1767 | - */ |
|
| 1768 | - public function get_receipt_url() { |
|
| 1769 | - |
|
| 1770 | - // Retrieve the checkout url. |
|
| 1762 | + /** |
|
| 1763 | + * Retrieves the receipt url. |
|
| 1764 | + * |
|
| 1765 | + * @since 1.0.19 |
|
| 1766 | + * @return string |
|
| 1767 | + */ |
|
| 1768 | + public function get_receipt_url() { |
|
| 1769 | + |
|
| 1770 | + // Retrieve the checkout url. |
|
| 1771 | 1771 | $receipt_url = wpinv_get_success_page_uri(); |
| 1772 | 1772 | |
| 1773 | - // Maybe force ssl. |
|
| 1773 | + // Maybe force ssl. |
|
| 1774 | 1774 | if ( is_ssl() ) { |
| 1775 | 1775 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
| 1776 | 1776 | } |
| 1777 | 1777 | |
| 1778 | - // Add the invoice key. |
|
| 1779 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1778 | + // Add the invoice key. |
|
| 1779 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1780 | 1780 | |
| 1781 | 1781 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
| 1782 | 1782 | } |
| 1783 | 1783 | |
| 1784 | 1784 | /** |
| 1785 | - * Magic method for accessing invoice properties. |
|
| 1786 | - * |
|
| 1787 | - * @since 1.0.15 |
|
| 1788 | - * @access public |
|
| 1789 | - * |
|
| 1790 | - * @param string $key Discount data to retrieve |
|
| 1791 | - * @param string $context View or edit context. |
|
| 1792 | - * @return mixed Value of the given invoice property (if set). |
|
| 1793 | - */ |
|
| 1794 | - public function get( $key, $context = 'view' ) { |
|
| 1785 | + * Magic method for accessing invoice properties. |
|
| 1786 | + * |
|
| 1787 | + * @since 1.0.15 |
|
| 1788 | + * @access public |
|
| 1789 | + * |
|
| 1790 | + * @param string $key Discount data to retrieve |
|
| 1791 | + * @param string $context View or edit context. |
|
| 1792 | + * @return mixed Value of the given invoice property (if set). |
|
| 1793 | + */ |
|
| 1794 | + public function get( $key, $context = 'view' ) { |
|
| 1795 | 1795 | return $this->get_prop( $key, $context ); |
| 1796 | - } |
|
| 1796 | + } |
|
| 1797 | 1797 | |
| 1798 | 1798 | /* |
| 1799 | 1799 | |-------------------------------------------------------------------------- |
@@ -1806,130 +1806,130 @@ discard block |
||
| 1806 | 1806 | */ |
| 1807 | 1807 | |
| 1808 | 1808 | /** |
| 1809 | - * Magic method for setting invoice properties. |
|
| 1810 | - * |
|
| 1811 | - * @since 1.0.19 |
|
| 1812 | - * @access public |
|
| 1813 | - * |
|
| 1814 | - * @param string $key Discount data to retrieve |
|
| 1815 | - * @param mixed $value new value. |
|
| 1816 | - * @return mixed Value of the given invoice property (if set). |
|
| 1817 | - */ |
|
| 1818 | - public function set( $key, $value ) { |
|
| 1809 | + * Magic method for setting invoice properties. |
|
| 1810 | + * |
|
| 1811 | + * @since 1.0.19 |
|
| 1812 | + * @access public |
|
| 1813 | + * |
|
| 1814 | + * @param string $key Discount data to retrieve |
|
| 1815 | + * @param mixed $value new value. |
|
| 1816 | + * @return mixed Value of the given invoice property (if set). |
|
| 1817 | + */ |
|
| 1818 | + public function set( $key, $value ) { |
|
| 1819 | 1819 | |
| 1820 | 1820 | $setter = "set_$key"; |
| 1821 | 1821 | if ( is_callable( array( $this, $setter ) ) ) { |
| 1822 | 1822 | $this->{$setter}( $value ); |
| 1823 | 1823 | } |
| 1824 | 1824 | |
| 1825 | - } |
|
| 1825 | + } |
|
| 1826 | 1826 | |
| 1827 | - /** |
|
| 1828 | - * Sets item status. |
|
| 1829 | - * |
|
| 1830 | - * @since 1.0.19 |
|
| 1831 | - * @param string $new_status New status. |
|
| 1832 | - * @param string $note Optional note to add. |
|
| 1833 | - * @param bool $manual_update Is this a manual status change?. |
|
| 1834 | - * @return array details of change. |
|
| 1835 | - */ |
|
| 1836 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 1837 | - $old_status = $this->get_status(); |
|
| 1827 | + /** |
|
| 1828 | + * Sets item status. |
|
| 1829 | + * |
|
| 1830 | + * @since 1.0.19 |
|
| 1831 | + * @param string $new_status New status. |
|
| 1832 | + * @param string $note Optional note to add. |
|
| 1833 | + * @param bool $manual_update Is this a manual status change?. |
|
| 1834 | + * @return array details of change. |
|
| 1835 | + */ |
|
| 1836 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 1837 | + $old_status = $this->get_status(); |
|
| 1838 | 1838 | |
| 1839 | - $statuses = $this->get_all_statuses(); |
|
| 1839 | + $statuses = $this->get_all_statuses(); |
|
| 1840 | 1840 | |
| 1841 | - if ( isset( $statuses[ 'draft' ] ) ) { |
|
| 1842 | - unset( $statuses[ 'draft' ] ); |
|
| 1843 | - } |
|
| 1841 | + if ( isset( $statuses[ 'draft' ] ) ) { |
|
| 1842 | + unset( $statuses[ 'draft' ] ); |
|
| 1843 | + } |
|
| 1844 | 1844 | |
| 1845 | - $this->set_prop( 'status', $new_status ); |
|
| 1845 | + $this->set_prop( 'status', $new_status ); |
|
| 1846 | 1846 | |
| 1847 | - // If setting the status, ensure it's set to a valid status. |
|
| 1848 | - if ( true === $this->object_read ) { |
|
| 1847 | + // If setting the status, ensure it's set to a valid status. |
|
| 1848 | + if ( true === $this->object_read ) { |
|
| 1849 | 1849 | |
| 1850 | - // Only allow valid new status. |
|
| 1851 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1852 | - $new_status = 'wpi-pending'; |
|
| 1853 | - } |
|
| 1850 | + // Only allow valid new status. |
|
| 1851 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1852 | + $new_status = 'wpi-pending'; |
|
| 1853 | + } |
|
| 1854 | 1854 | |
| 1855 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 1856 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1857 | - $old_status = 'wpi-pending'; |
|
| 1858 | - } |
|
| 1855 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 1856 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1857 | + $old_status = 'wpi-pending'; |
|
| 1858 | + } |
|
| 1859 | 1859 | |
| 1860 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 1861 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 1862 | - $old_status = 'wpi-pending'; |
|
| 1863 | - } |
|
| 1860 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 1861 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 1862 | + $old_status = 'wpi-pending'; |
|
| 1863 | + } |
|
| 1864 | 1864 | |
| 1865 | - } |
|
| 1865 | + } |
|
| 1866 | 1866 | |
| 1867 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 1868 | - $this->status_transition = array( |
|
| 1869 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 1870 | - 'to' => $new_status, |
|
| 1871 | - 'note' => $note, |
|
| 1872 | - 'manual' => (bool) $manual_update, |
|
| 1873 | - ); |
|
| 1867 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 1868 | + $this->status_transition = array( |
|
| 1869 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 1870 | + 'to' => $new_status, |
|
| 1871 | + 'note' => $note, |
|
| 1872 | + 'manual' => (bool) $manual_update, |
|
| 1873 | + ); |
|
| 1874 | 1874 | |
| 1875 | - if ( $manual_update ) { |
|
| 1876 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
| 1877 | - } |
|
| 1875 | + if ( $manual_update ) { |
|
| 1876 | + do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
| 1877 | + } |
|
| 1878 | 1878 | |
| 1879 | - $this->maybe_set_date_paid(); |
|
| 1879 | + $this->maybe_set_date_paid(); |
|
| 1880 | 1880 | |
| 1881 | - } |
|
| 1881 | + } |
|
| 1882 | 1882 | |
| 1883 | - return array( |
|
| 1884 | - 'from' => $old_status, |
|
| 1885 | - 'to' => $new_status, |
|
| 1886 | - ); |
|
| 1887 | - } |
|
| 1883 | + return array( |
|
| 1884 | + 'from' => $old_status, |
|
| 1885 | + 'to' => $new_status, |
|
| 1886 | + ); |
|
| 1887 | + } |
|
| 1888 | 1888 | |
| 1889 | - /** |
|
| 1890 | - * Maybe set date paid. |
|
| 1891 | - * |
|
| 1892 | - * Sets the date paid variable when transitioning to the payment complete |
|
| 1893 | - * order status. |
|
| 1894 | - * |
|
| 1895 | - * @since 1.0.19 |
|
| 1896 | - */ |
|
| 1897 | - public function maybe_set_date_paid() { |
|
| 1889 | + /** |
|
| 1890 | + * Maybe set date paid. |
|
| 1891 | + * |
|
| 1892 | + * Sets the date paid variable when transitioning to the payment complete |
|
| 1893 | + * order status. |
|
| 1894 | + * |
|
| 1895 | + * @since 1.0.19 |
|
| 1896 | + */ |
|
| 1897 | + public function maybe_set_date_paid() { |
|
| 1898 | 1898 | |
| 1899 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 1900 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 1901 | - } |
|
| 1902 | - } |
|
| 1899 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 1900 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 1901 | + } |
|
| 1902 | + } |
|
| 1903 | 1903 | |
| 1904 | 1904 | /** |
| 1905 | - * Set parent invoice ID. |
|
| 1906 | - * |
|
| 1907 | - * @since 1.0.19 |
|
| 1908 | - */ |
|
| 1909 | - public function set_parent_id( $value ) { |
|
| 1910 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
| 1911 | - return; |
|
| 1912 | - } |
|
| 1913 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 1905 | + * Set parent invoice ID. |
|
| 1906 | + * |
|
| 1907 | + * @since 1.0.19 |
|
| 1908 | + */ |
|
| 1909 | + public function set_parent_id( $value ) { |
|
| 1910 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
| 1911 | + return; |
|
| 1912 | + } |
|
| 1913 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 1914 | 1914 | } |
| 1915 | 1915 | |
| 1916 | 1916 | /** |
| 1917 | - * Set plugin version when the invoice was created. |
|
| 1918 | - * |
|
| 1919 | - * @since 1.0.19 |
|
| 1920 | - */ |
|
| 1921 | - public function set_version( $value ) { |
|
| 1922 | - $this->set_prop( 'version', $value ); |
|
| 1917 | + * Set plugin version when the invoice was created. |
|
| 1918 | + * |
|
| 1919 | + * @since 1.0.19 |
|
| 1920 | + */ |
|
| 1921 | + public function set_version( $value ) { |
|
| 1922 | + $this->set_prop( 'version', $value ); |
|
| 1923 | 1923 | } |
| 1924 | - |
|
| 1925 | - /** |
|
| 1926 | - * Set date when the invoice was created. |
|
| 1927 | - * |
|
| 1928 | - * @since 1.0.19 |
|
| 1929 | - * @param string $value Value to set. |
|
| 1924 | + |
|
| 1925 | + /** |
|
| 1926 | + * Set date when the invoice was created. |
|
| 1927 | + * |
|
| 1928 | + * @since 1.0.19 |
|
| 1929 | + * @param string $value Value to set. |
|
| 1930 | 1930 | * @return bool Whether or not the date was set. |
| 1931 | - */ |
|
| 1932 | - public function set_date_created( $value ) { |
|
| 1931 | + */ |
|
| 1932 | + public function set_date_created( $value ) { |
|
| 1933 | 1933 | $date = strtotime( $value ); |
| 1934 | 1934 | |
| 1935 | 1935 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1942,13 +1942,13 @@ discard block |
||
| 1942 | 1942 | } |
| 1943 | 1943 | |
| 1944 | 1944 | /** |
| 1945 | - * Set date invoice due date. |
|
| 1946 | - * |
|
| 1947 | - * @since 1.0.19 |
|
| 1948 | - * @param string $value Value to set. |
|
| 1945 | + * Set date invoice due date. |
|
| 1946 | + * |
|
| 1947 | + * @since 1.0.19 |
|
| 1948 | + * @param string $value Value to set. |
|
| 1949 | 1949 | * @return bool Whether or not the date was set. |
| 1950 | - */ |
|
| 1951 | - public function set_due_date( $value ) { |
|
| 1950 | + */ |
|
| 1951 | + public function set_due_date( $value ) { |
|
| 1952 | 1952 | $date = strtotime( $value ); |
| 1953 | 1953 | |
| 1954 | 1954 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1956,29 +1956,29 @@ discard block |
||
| 1956 | 1956 | return true; |
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | - $this->set_prop( 'due_date', '' ); |
|
| 1959 | + $this->set_prop( 'due_date', '' ); |
|
| 1960 | 1960 | return false; |
| 1961 | 1961 | |
| 1962 | 1962 | } |
| 1963 | 1963 | |
| 1964 | 1964 | /** |
| 1965 | - * Alias of self::set_due_date(). |
|
| 1966 | - * |
|
| 1967 | - * @since 1.0.19 |
|
| 1968 | - * @param string $value New name. |
|
| 1969 | - */ |
|
| 1970 | - public function set_date_due( $value ) { |
|
| 1971 | - $this->set_due_date( $value ); |
|
| 1965 | + * Alias of self::set_due_date(). |
|
| 1966 | + * |
|
| 1967 | + * @since 1.0.19 |
|
| 1968 | + * @param string $value New name. |
|
| 1969 | + */ |
|
| 1970 | + public function set_date_due( $value ) { |
|
| 1971 | + $this->set_due_date( $value ); |
|
| 1972 | 1972 | } |
| 1973 | 1973 | |
| 1974 | 1974 | /** |
| 1975 | - * Set date invoice was completed. |
|
| 1976 | - * |
|
| 1977 | - * @since 1.0.19 |
|
| 1978 | - * @param string $value Value to set. |
|
| 1975 | + * Set date invoice was completed. |
|
| 1976 | + * |
|
| 1977 | + * @since 1.0.19 |
|
| 1978 | + * @param string $value Value to set. |
|
| 1979 | 1979 | * @return bool Whether or not the date was set. |
| 1980 | - */ |
|
| 1981 | - public function set_completed_date( $value ) { |
|
| 1980 | + */ |
|
| 1981 | + public function set_completed_date( $value ) { |
|
| 1982 | 1982 | $date = strtotime( $value ); |
| 1983 | 1983 | |
| 1984 | 1984 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1986,29 +1986,29 @@ discard block |
||
| 1986 | 1986 | return true; |
| 1987 | 1987 | } |
| 1988 | 1988 | |
| 1989 | - $this->set_prop( 'completed_date', '' ); |
|
| 1989 | + $this->set_prop( 'completed_date', '' ); |
|
| 1990 | 1990 | return false; |
| 1991 | 1991 | |
| 1992 | 1992 | } |
| 1993 | 1993 | |
| 1994 | 1994 | /** |
| 1995 | - * Alias of self::set_completed_date(). |
|
| 1996 | - * |
|
| 1997 | - * @since 1.0.19 |
|
| 1998 | - * @param string $value New name. |
|
| 1999 | - */ |
|
| 2000 | - public function set_date_completed( $value ) { |
|
| 2001 | - $this->set_completed_date( $value ); |
|
| 1995 | + * Alias of self::set_completed_date(). |
|
| 1996 | + * |
|
| 1997 | + * @since 1.0.19 |
|
| 1998 | + * @param string $value New name. |
|
| 1999 | + */ |
|
| 2000 | + public function set_date_completed( $value ) { |
|
| 2001 | + $this->set_completed_date( $value ); |
|
| 2002 | 2002 | } |
| 2003 | 2003 | |
| 2004 | 2004 | /** |
| 2005 | - * Set date when the invoice was last modified. |
|
| 2006 | - * |
|
| 2007 | - * @since 1.0.19 |
|
| 2008 | - * @param string $value Value to set. |
|
| 2005 | + * Set date when the invoice was last modified. |
|
| 2006 | + * |
|
| 2007 | + * @since 1.0.19 |
|
| 2008 | + * @param string $value Value to set. |
|
| 2009 | 2009 | * @return bool Whether or not the date was set. |
| 2010 | - */ |
|
| 2011 | - public function set_date_modified( $value ) { |
|
| 2010 | + */ |
|
| 2011 | + public function set_date_modified( $value ) { |
|
| 2012 | 2012 | $date = strtotime( $value ); |
| 2013 | 2013 | |
| 2014 | 2014 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2016,706 +2016,706 @@ discard block |
||
| 2016 | 2016 | return true; |
| 2017 | 2017 | } |
| 2018 | 2018 | |
| 2019 | - $this->set_prop( 'date_modified', '' ); |
|
| 2019 | + $this->set_prop( 'date_modified', '' ); |
|
| 2020 | 2020 | return false; |
| 2021 | 2021 | |
| 2022 | 2022 | } |
| 2023 | 2023 | |
| 2024 | 2024 | /** |
| 2025 | - * Set the invoice number. |
|
| 2026 | - * |
|
| 2027 | - * @since 1.0.19 |
|
| 2028 | - * @param string $value New number. |
|
| 2029 | - */ |
|
| 2030 | - public function set_number( $value ) { |
|
| 2025 | + * Set the invoice number. |
|
| 2026 | + * |
|
| 2027 | + * @since 1.0.19 |
|
| 2028 | + * @param string $value New number. |
|
| 2029 | + */ |
|
| 2030 | + public function set_number( $value ) { |
|
| 2031 | 2031 | $number = sanitize_text_field( $value ); |
| 2032 | - $this->set_prop( 'number', $number ); |
|
| 2032 | + $this->set_prop( 'number', $number ); |
|
| 2033 | 2033 | } |
| 2034 | 2034 | |
| 2035 | 2035 | /** |
| 2036 | - * Set the invoice type. |
|
| 2037 | - * |
|
| 2038 | - * @since 1.0.19 |
|
| 2039 | - * @param string $value Type. |
|
| 2040 | - */ |
|
| 2041 | - public function set_type( $value ) { |
|
| 2036 | + * Set the invoice type. |
|
| 2037 | + * |
|
| 2038 | + * @since 1.0.19 |
|
| 2039 | + * @param string $value Type. |
|
| 2040 | + */ |
|
| 2041 | + public function set_type( $value ) { |
|
| 2042 | 2042 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
| 2043 | - $this->set_prop( 'type', $type ); |
|
| 2044 | - } |
|
| 2043 | + $this->set_prop( 'type', $type ); |
|
| 2044 | + } |
|
| 2045 | 2045 | |
| 2046 | 2046 | /** |
| 2047 | - * Set the invoice post type. |
|
| 2048 | - * |
|
| 2049 | - * @since 1.0.19 |
|
| 2050 | - * @param string $value Post type. |
|
| 2051 | - */ |
|
| 2052 | - public function set_post_type( $value ) { |
|
| 2047 | + * Set the invoice post type. |
|
| 2048 | + * |
|
| 2049 | + * @since 1.0.19 |
|
| 2050 | + * @param string $value Post type. |
|
| 2051 | + */ |
|
| 2052 | + public function set_post_type( $value ) { |
|
| 2053 | 2053 | if ( getpaid_is_invoice_post_type( $value ) ) { |
| 2054 | - $this->set_type( $value ); |
|
| 2054 | + $this->set_type( $value ); |
|
| 2055 | 2055 | $this->set_prop( 'post_type', $value ); |
| 2056 | 2056 | } |
| 2057 | 2057 | } |
| 2058 | 2058 | |
| 2059 | 2059 | /** |
| 2060 | - * Set the invoice key. |
|
| 2061 | - * |
|
| 2062 | - * @since 1.0.19 |
|
| 2063 | - * @param string $value New key. |
|
| 2064 | - */ |
|
| 2065 | - public function set_key( $value ) { |
|
| 2060 | + * Set the invoice key. |
|
| 2061 | + * |
|
| 2062 | + * @since 1.0.19 |
|
| 2063 | + * @param string $value New key. |
|
| 2064 | + */ |
|
| 2065 | + public function set_key( $value ) { |
|
| 2066 | 2066 | $key = sanitize_text_field( $value ); |
| 2067 | - $this->set_prop( 'key', $key ); |
|
| 2067 | + $this->set_prop( 'key', $key ); |
|
| 2068 | 2068 | } |
| 2069 | 2069 | |
| 2070 | 2070 | /** |
| 2071 | - * Set the invoice mode. |
|
| 2072 | - * |
|
| 2073 | - * @since 1.0.19 |
|
| 2074 | - * @param string $value mode. |
|
| 2075 | - */ |
|
| 2076 | - public function set_mode( $value ) { |
|
| 2071 | + * Set the invoice mode. |
|
| 2072 | + * |
|
| 2073 | + * @since 1.0.19 |
|
| 2074 | + * @param string $value mode. |
|
| 2075 | + */ |
|
| 2076 | + public function set_mode( $value ) { |
|
| 2077 | 2077 | if ( ! in_array( $value, array( 'live', 'test' ) ) ) { |
| 2078 | 2078 | $this->set_prop( 'value', $value ); |
| 2079 | 2079 | } |
| 2080 | 2080 | } |
| 2081 | 2081 | |
| 2082 | 2082 | /** |
| 2083 | - * Set the invoice path. |
|
| 2084 | - * |
|
| 2085 | - * @since 1.0.19 |
|
| 2086 | - * @param string $value path. |
|
| 2087 | - */ |
|
| 2088 | - public function set_path( $value ) { |
|
| 2083 | + * Set the invoice path. |
|
| 2084 | + * |
|
| 2085 | + * @since 1.0.19 |
|
| 2086 | + * @param string $value path. |
|
| 2087 | + */ |
|
| 2088 | + public function set_path( $value ) { |
|
| 2089 | 2089 | $this->set_prop( 'path', $value ); |
| 2090 | 2090 | } |
| 2091 | 2091 | |
| 2092 | 2092 | /** |
| 2093 | - * Set the invoice name. |
|
| 2094 | - * |
|
| 2095 | - * @since 1.0.19 |
|
| 2096 | - * @param string $value New name. |
|
| 2097 | - */ |
|
| 2098 | - public function set_name( $value ) { |
|
| 2093 | + * Set the invoice name. |
|
| 2094 | + * |
|
| 2095 | + * @since 1.0.19 |
|
| 2096 | + * @param string $value New name. |
|
| 2097 | + */ |
|
| 2098 | + public function set_name( $value ) { |
|
| 2099 | 2099 | $name = sanitize_text_field( $value ); |
| 2100 | - $this->set_prop( 'name', $name ); |
|
| 2100 | + $this->set_prop( 'name', $name ); |
|
| 2101 | 2101 | } |
| 2102 | 2102 | |
| 2103 | 2103 | /** |
| 2104 | - * Alias of self::set_name(). |
|
| 2105 | - * |
|
| 2106 | - * @since 1.0.19 |
|
| 2107 | - * @param string $value New name. |
|
| 2108 | - */ |
|
| 2109 | - public function set_title( $value ) { |
|
| 2110 | - $this->set_name( $value ); |
|
| 2104 | + * Alias of self::set_name(). |
|
| 2105 | + * |
|
| 2106 | + * @since 1.0.19 |
|
| 2107 | + * @param string $value New name. |
|
| 2108 | + */ |
|
| 2109 | + public function set_title( $value ) { |
|
| 2110 | + $this->set_name( $value ); |
|
| 2111 | 2111 | } |
| 2112 | 2112 | |
| 2113 | 2113 | /** |
| 2114 | - * Set the invoice description. |
|
| 2115 | - * |
|
| 2116 | - * @since 1.0.19 |
|
| 2117 | - * @param string $value New description. |
|
| 2118 | - */ |
|
| 2119 | - public function set_description( $value ) { |
|
| 2114 | + * Set the invoice description. |
|
| 2115 | + * |
|
| 2116 | + * @since 1.0.19 |
|
| 2117 | + * @param string $value New description. |
|
| 2118 | + */ |
|
| 2119 | + public function set_description( $value ) { |
|
| 2120 | 2120 | $description = wp_kses_post( $value ); |
| 2121 | - return $this->set_prop( 'description', $description ); |
|
| 2121 | + return $this->set_prop( 'description', $description ); |
|
| 2122 | 2122 | } |
| 2123 | 2123 | |
| 2124 | 2124 | /** |
| 2125 | - * Alias of self::set_description(). |
|
| 2126 | - * |
|
| 2127 | - * @since 1.0.19 |
|
| 2128 | - * @param string $value New description. |
|
| 2129 | - */ |
|
| 2130 | - public function set_excerpt( $value ) { |
|
| 2131 | - $this->set_description( $value ); |
|
| 2125 | + * Alias of self::set_description(). |
|
| 2126 | + * |
|
| 2127 | + * @since 1.0.19 |
|
| 2128 | + * @param string $value New description. |
|
| 2129 | + */ |
|
| 2130 | + public function set_excerpt( $value ) { |
|
| 2131 | + $this->set_description( $value ); |
|
| 2132 | 2132 | } |
| 2133 | 2133 | |
| 2134 | 2134 | /** |
| 2135 | - * Alias of self::set_description(). |
|
| 2136 | - * |
|
| 2137 | - * @since 1.0.19 |
|
| 2138 | - * @param string $value New description. |
|
| 2139 | - */ |
|
| 2140 | - public function set_summary( $value ) { |
|
| 2141 | - $this->set_description( $value ); |
|
| 2135 | + * Alias of self::set_description(). |
|
| 2136 | + * |
|
| 2137 | + * @since 1.0.19 |
|
| 2138 | + * @param string $value New description. |
|
| 2139 | + */ |
|
| 2140 | + public function set_summary( $value ) { |
|
| 2141 | + $this->set_description( $value ); |
|
| 2142 | 2142 | } |
| 2143 | 2143 | |
| 2144 | 2144 | /** |
| 2145 | - * Set the receiver of the invoice. |
|
| 2146 | - * |
|
| 2147 | - * @since 1.0.19 |
|
| 2148 | - * @param int $value New author. |
|
| 2149 | - */ |
|
| 2150 | - public function set_author( $value ) { |
|
| 2151 | - $user = get_user_by( 'id', (int) $value ); |
|
| 2145 | + * Set the receiver of the invoice. |
|
| 2146 | + * |
|
| 2147 | + * @since 1.0.19 |
|
| 2148 | + * @param int $value New author. |
|
| 2149 | + */ |
|
| 2150 | + public function set_author( $value ) { |
|
| 2151 | + $user = get_user_by( 'id', (int) $value ); |
|
| 2152 | 2152 | |
| 2153 | - if ( $user && $user->ID ) { |
|
| 2154 | - $this->set_prop( 'author', $user->ID ); |
|
| 2155 | - $this->set_prop( 'email', $user->user_email ); |
|
| 2156 | - } |
|
| 2153 | + if ( $user && $user->ID ) { |
|
| 2154 | + $this->set_prop( 'author', $user->ID ); |
|
| 2155 | + $this->set_prop( 'email', $user->user_email ); |
|
| 2156 | + } |
|
| 2157 | 2157 | |
| 2158 | 2158 | } |
| 2159 | 2159 | |
| 2160 | 2160 | /** |
| 2161 | - * Alias of self::set_author(). |
|
| 2162 | - * |
|
| 2163 | - * @since 1.0.19 |
|
| 2164 | - * @param int $value New user id. |
|
| 2165 | - */ |
|
| 2166 | - public function set_user_id( $value ) { |
|
| 2167 | - $this->set_author( $value ); |
|
| 2161 | + * Alias of self::set_author(). |
|
| 2162 | + * |
|
| 2163 | + * @since 1.0.19 |
|
| 2164 | + * @param int $value New user id. |
|
| 2165 | + */ |
|
| 2166 | + public function set_user_id( $value ) { |
|
| 2167 | + $this->set_author( $value ); |
|
| 2168 | 2168 | } |
| 2169 | 2169 | |
| 2170 | 2170 | /** |
| 2171 | - * Alias of self::set_author(). |
|
| 2172 | - * |
|
| 2173 | - * @since 1.0.19 |
|
| 2174 | - * @param int $value New user id. |
|
| 2175 | - */ |
|
| 2176 | - public function set_customer_id( $value ) { |
|
| 2177 | - $this->set_author( $value ); |
|
| 2171 | + * Alias of self::set_author(). |
|
| 2172 | + * |
|
| 2173 | + * @since 1.0.19 |
|
| 2174 | + * @param int $value New user id. |
|
| 2175 | + */ |
|
| 2176 | + public function set_customer_id( $value ) { |
|
| 2177 | + $this->set_author( $value ); |
|
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | 2180 | /** |
| 2181 | - * Set the customer's ip. |
|
| 2182 | - * |
|
| 2183 | - * @since 1.0.19 |
|
| 2184 | - * @param string $value ip address. |
|
| 2185 | - */ |
|
| 2186 | - public function set_ip( $value ) { |
|
| 2187 | - $this->set_prop( 'ip', $value ); |
|
| 2181 | + * Set the customer's ip. |
|
| 2182 | + * |
|
| 2183 | + * @since 1.0.19 |
|
| 2184 | + * @param string $value ip address. |
|
| 2185 | + */ |
|
| 2186 | + public function set_ip( $value ) { |
|
| 2187 | + $this->set_prop( 'ip', $value ); |
|
| 2188 | 2188 | } |
| 2189 | 2189 | |
| 2190 | 2190 | /** |
| 2191 | - * Alias of self::set_ip(). |
|
| 2192 | - * |
|
| 2193 | - * @since 1.0.19 |
|
| 2194 | - * @param string $value ip address. |
|
| 2195 | - */ |
|
| 2196 | - public function set_user_ip( $value ) { |
|
| 2197 | - $this->set_ip( $value ); |
|
| 2191 | + * Alias of self::set_ip(). |
|
| 2192 | + * |
|
| 2193 | + * @since 1.0.19 |
|
| 2194 | + * @param string $value ip address. |
|
| 2195 | + */ |
|
| 2196 | + public function set_user_ip( $value ) { |
|
| 2197 | + $this->set_ip( $value ); |
|
| 2198 | 2198 | } |
| 2199 | 2199 | |
| 2200 | 2200 | /** |
| 2201 | - * Set the customer's first name. |
|
| 2202 | - * |
|
| 2203 | - * @since 1.0.19 |
|
| 2204 | - * @param string $value first name. |
|
| 2205 | - */ |
|
| 2206 | - public function set_first_name( $value ) { |
|
| 2207 | - $this->set_prop( 'first_name', $value ); |
|
| 2201 | + * Set the customer's first name. |
|
| 2202 | + * |
|
| 2203 | + * @since 1.0.19 |
|
| 2204 | + * @param string $value first name. |
|
| 2205 | + */ |
|
| 2206 | + public function set_first_name( $value ) { |
|
| 2207 | + $this->set_prop( 'first_name', $value ); |
|
| 2208 | 2208 | } |
| 2209 | 2209 | |
| 2210 | 2210 | /** |
| 2211 | - * Alias of self::set_first_name(). |
|
| 2212 | - * |
|
| 2213 | - * @since 1.0.19 |
|
| 2214 | - * @param string $value first name. |
|
| 2215 | - */ |
|
| 2216 | - public function set_user_first_name( $value ) { |
|
| 2217 | - $this->set_first_name( $value ); |
|
| 2211 | + * Alias of self::set_first_name(). |
|
| 2212 | + * |
|
| 2213 | + * @since 1.0.19 |
|
| 2214 | + * @param string $value first name. |
|
| 2215 | + */ |
|
| 2216 | + public function set_user_first_name( $value ) { |
|
| 2217 | + $this->set_first_name( $value ); |
|
| 2218 | 2218 | } |
| 2219 | 2219 | |
| 2220 | 2220 | /** |
| 2221 | - * Alias of self::set_first_name(). |
|
| 2222 | - * |
|
| 2223 | - * @since 1.0.19 |
|
| 2224 | - * @param string $value first name. |
|
| 2225 | - */ |
|
| 2226 | - public function set_customer_first_name( $value ) { |
|
| 2227 | - $this->set_first_name( $value ); |
|
| 2221 | + * Alias of self::set_first_name(). |
|
| 2222 | + * |
|
| 2223 | + * @since 1.0.19 |
|
| 2224 | + * @param string $value first name. |
|
| 2225 | + */ |
|
| 2226 | + public function set_customer_first_name( $value ) { |
|
| 2227 | + $this->set_first_name( $value ); |
|
| 2228 | 2228 | } |
| 2229 | 2229 | |
| 2230 | 2230 | /** |
| 2231 | - * Set the customer's last name. |
|
| 2232 | - * |
|
| 2233 | - * @since 1.0.19 |
|
| 2234 | - * @param string $value last name. |
|
| 2235 | - */ |
|
| 2236 | - public function set_last_name( $value ) { |
|
| 2237 | - $this->set_prop( 'last_name', $value ); |
|
| 2231 | + * Set the customer's last name. |
|
| 2232 | + * |
|
| 2233 | + * @since 1.0.19 |
|
| 2234 | + * @param string $value last name. |
|
| 2235 | + */ |
|
| 2236 | + public function set_last_name( $value ) { |
|
| 2237 | + $this->set_prop( 'last_name', $value ); |
|
| 2238 | 2238 | } |
| 2239 | 2239 | |
| 2240 | 2240 | /** |
| 2241 | - * Alias of self::set_last_name(). |
|
| 2242 | - * |
|
| 2243 | - * @since 1.0.19 |
|
| 2244 | - * @param string $value last name. |
|
| 2245 | - */ |
|
| 2246 | - public function set_user_last_name( $value ) { |
|
| 2247 | - $this->set_last_name( $value ); |
|
| 2241 | + * Alias of self::set_last_name(). |
|
| 2242 | + * |
|
| 2243 | + * @since 1.0.19 |
|
| 2244 | + * @param string $value last name. |
|
| 2245 | + */ |
|
| 2246 | + public function set_user_last_name( $value ) { |
|
| 2247 | + $this->set_last_name( $value ); |
|
| 2248 | 2248 | } |
| 2249 | 2249 | |
| 2250 | 2250 | /** |
| 2251 | - * Alias of self::set_last_name(). |
|
| 2252 | - * |
|
| 2253 | - * @since 1.0.19 |
|
| 2254 | - * @param string $value last name. |
|
| 2255 | - */ |
|
| 2256 | - public function set_customer_last_name( $value ) { |
|
| 2257 | - $this->set_last_name( $value ); |
|
| 2251 | + * Alias of self::set_last_name(). |
|
| 2252 | + * |
|
| 2253 | + * @since 1.0.19 |
|
| 2254 | + * @param string $value last name. |
|
| 2255 | + */ |
|
| 2256 | + public function set_customer_last_name( $value ) { |
|
| 2257 | + $this->set_last_name( $value ); |
|
| 2258 | 2258 | } |
| 2259 | 2259 | |
| 2260 | 2260 | /** |
| 2261 | - * Set the customer's phone number. |
|
| 2262 | - * |
|
| 2263 | - * @since 1.0.19 |
|
| 2264 | - * @param string $value phone. |
|
| 2265 | - */ |
|
| 2266 | - public function set_phone( $value ) { |
|
| 2267 | - $this->set_prop( 'phone', $value ); |
|
| 2261 | + * Set the customer's phone number. |
|
| 2262 | + * |
|
| 2263 | + * @since 1.0.19 |
|
| 2264 | + * @param string $value phone. |
|
| 2265 | + */ |
|
| 2266 | + public function set_phone( $value ) { |
|
| 2267 | + $this->set_prop( 'phone', $value ); |
|
| 2268 | 2268 | } |
| 2269 | 2269 | |
| 2270 | 2270 | /** |
| 2271 | - * Alias of self::set_phone(). |
|
| 2272 | - * |
|
| 2273 | - * @since 1.0.19 |
|
| 2274 | - * @param string $value phone. |
|
| 2275 | - */ |
|
| 2276 | - public function set_user_phone( $value ) { |
|
| 2277 | - $this->set_phone( $value ); |
|
| 2271 | + * Alias of self::set_phone(). |
|
| 2272 | + * |
|
| 2273 | + * @since 1.0.19 |
|
| 2274 | + * @param string $value phone. |
|
| 2275 | + */ |
|
| 2276 | + public function set_user_phone( $value ) { |
|
| 2277 | + $this->set_phone( $value ); |
|
| 2278 | + } |
|
| 2279 | + |
|
| 2280 | + /** |
|
| 2281 | + * Alias of self::set_phone(). |
|
| 2282 | + * |
|
| 2283 | + * @since 1.0.19 |
|
| 2284 | + * @param string $value phone. |
|
| 2285 | + */ |
|
| 2286 | + public function set_customer_phone( $value ) { |
|
| 2287 | + $this->set_phone( $value ); |
|
| 2288 | + } |
|
| 2289 | + |
|
| 2290 | + /** |
|
| 2291 | + * Alias of self::set_phone(). |
|
| 2292 | + * |
|
| 2293 | + * @since 1.0.19 |
|
| 2294 | + * @param string $value phone. |
|
| 2295 | + */ |
|
| 2296 | + public function set_phone_number( $value ) { |
|
| 2297 | + $this->set_phone( $value ); |
|
| 2278 | 2298 | } |
| 2279 | 2299 | |
| 2280 | 2300 | /** |
| 2281 | - * Alias of self::set_phone(). |
|
| 2282 | - * |
|
| 2283 | - * @since 1.0.19 |
|
| 2284 | - * @param string $value phone. |
|
| 2285 | - */ |
|
| 2286 | - public function set_customer_phone( $value ) { |
|
| 2287 | - $this->set_phone( $value ); |
|
| 2301 | + * Set the customer's email address. |
|
| 2302 | + * |
|
| 2303 | + * @since 1.0.19 |
|
| 2304 | + * @param string $value email address. |
|
| 2305 | + */ |
|
| 2306 | + public function set_email( $value ) { |
|
| 2307 | + $this->set_prop( 'email', $value ); |
|
| 2288 | 2308 | } |
| 2289 | 2309 | |
| 2290 | 2310 | /** |
| 2291 | - * Alias of self::set_phone(). |
|
| 2292 | - * |
|
| 2293 | - * @since 1.0.19 |
|
| 2294 | - * @param string $value phone. |
|
| 2295 | - */ |
|
| 2296 | - public function set_phone_number( $value ) { |
|
| 2297 | - $this->set_phone( $value ); |
|
| 2311 | + * Alias of self::set_email(). |
|
| 2312 | + * |
|
| 2313 | + * @since 1.0.19 |
|
| 2314 | + * @param string $value email address. |
|
| 2315 | + */ |
|
| 2316 | + public function set_user_email( $value ) { |
|
| 2317 | + $this->set_email( $value ); |
|
| 2298 | 2318 | } |
| 2299 | 2319 | |
| 2300 | 2320 | /** |
| 2301 | - * Set the customer's email address. |
|
| 2302 | - * |
|
| 2303 | - * @since 1.0.19 |
|
| 2304 | - * @param string $value email address. |
|
| 2305 | - */ |
|
| 2306 | - public function set_email( $value ) { |
|
| 2307 | - $this->set_prop( 'email', $value ); |
|
| 2321 | + * Alias of self::set_email(). |
|
| 2322 | + * |
|
| 2323 | + * @since 1.0.19 |
|
| 2324 | + * @param string $value email address. |
|
| 2325 | + */ |
|
| 2326 | + public function set_email_address( $value ) { |
|
| 2327 | + $this->set_email( $value ); |
|
| 2328 | + } |
|
| 2329 | + |
|
| 2330 | + /** |
|
| 2331 | + * Alias of self::set_email(). |
|
| 2332 | + * |
|
| 2333 | + * @since 1.0.19 |
|
| 2334 | + * @param string $value email address. |
|
| 2335 | + */ |
|
| 2336 | + public function set_customer_email( $value ) { |
|
| 2337 | + $this->set_email( $value ); |
|
| 2308 | 2338 | } |
| 2309 | 2339 | |
| 2310 | 2340 | /** |
| 2311 | - * Alias of self::set_email(). |
|
| 2312 | - * |
|
| 2313 | - * @since 1.0.19 |
|
| 2314 | - * @param string $value email address. |
|
| 2315 | - */ |
|
| 2316 | - public function set_user_email( $value ) { |
|
| 2317 | - $this->set_email( $value ); |
|
| 2341 | + * Set the customer's country. |
|
| 2342 | + * |
|
| 2343 | + * @since 1.0.19 |
|
| 2344 | + * @param string $value country. |
|
| 2345 | + */ |
|
| 2346 | + public function set_country( $value ) { |
|
| 2347 | + $this->set_prop( 'country', $value ); |
|
| 2318 | 2348 | } |
| 2319 | 2349 | |
| 2320 | 2350 | /** |
| 2321 | - * Alias of self::set_email(). |
|
| 2322 | - * |
|
| 2323 | - * @since 1.0.19 |
|
| 2324 | - * @param string $value email address. |
|
| 2325 | - */ |
|
| 2326 | - public function set_email_address( $value ) { |
|
| 2327 | - $this->set_email( $value ); |
|
| 2351 | + * Alias of self::set_country(). |
|
| 2352 | + * |
|
| 2353 | + * @since 1.0.19 |
|
| 2354 | + * @param string $value country. |
|
| 2355 | + */ |
|
| 2356 | + public function set_user_country( $value ) { |
|
| 2357 | + $this->set_country( $value ); |
|
| 2328 | 2358 | } |
| 2329 | 2359 | |
| 2330 | 2360 | /** |
| 2331 | - * Alias of self::set_email(). |
|
| 2332 | - * |
|
| 2333 | - * @since 1.0.19 |
|
| 2334 | - * @param string $value email address. |
|
| 2335 | - */ |
|
| 2336 | - public function set_customer_email( $value ) { |
|
| 2337 | - $this->set_email( $value ); |
|
| 2361 | + * Alias of self::set_country(). |
|
| 2362 | + * |
|
| 2363 | + * @since 1.0.19 |
|
| 2364 | + * @param string $value country. |
|
| 2365 | + */ |
|
| 2366 | + public function set_customer_country( $value ) { |
|
| 2367 | + $this->set_country( $value ); |
|
| 2338 | 2368 | } |
| 2339 | 2369 | |
| 2340 | 2370 | /** |
| 2341 | - * Set the customer's country. |
|
| 2342 | - * |
|
| 2343 | - * @since 1.0.19 |
|
| 2344 | - * @param string $value country. |
|
| 2345 | - */ |
|
| 2346 | - public function set_country( $value ) { |
|
| 2347 | - $this->set_prop( 'country', $value ); |
|
| 2371 | + * Set the customer's state. |
|
| 2372 | + * |
|
| 2373 | + * @since 1.0.19 |
|
| 2374 | + * @param string $value state. |
|
| 2375 | + */ |
|
| 2376 | + public function set_state( $value ) { |
|
| 2377 | + $this->set_prop( 'state', $value ); |
|
| 2348 | 2378 | } |
| 2349 | 2379 | |
| 2350 | 2380 | /** |
| 2351 | - * Alias of self::set_country(). |
|
| 2352 | - * |
|
| 2353 | - * @since 1.0.19 |
|
| 2354 | - * @param string $value country. |
|
| 2355 | - */ |
|
| 2356 | - public function set_user_country( $value ) { |
|
| 2357 | - $this->set_country( $value ); |
|
| 2381 | + * Alias of self::set_state(). |
|
| 2382 | + * |
|
| 2383 | + * @since 1.0.19 |
|
| 2384 | + * @param string $value state. |
|
| 2385 | + */ |
|
| 2386 | + public function set_user_state( $value ) { |
|
| 2387 | + $this->set_state( $value ); |
|
| 2358 | 2388 | } |
| 2359 | 2389 | |
| 2360 | 2390 | /** |
| 2361 | - * Alias of self::set_country(). |
|
| 2362 | - * |
|
| 2363 | - * @since 1.0.19 |
|
| 2364 | - * @param string $value country. |
|
| 2365 | - */ |
|
| 2366 | - public function set_customer_country( $value ) { |
|
| 2367 | - $this->set_country( $value ); |
|
| 2391 | + * Alias of self::set_state(). |
|
| 2392 | + * |
|
| 2393 | + * @since 1.0.19 |
|
| 2394 | + * @param string $value state. |
|
| 2395 | + */ |
|
| 2396 | + public function set_customer_state( $value ) { |
|
| 2397 | + $this->set_state( $value ); |
|
| 2368 | 2398 | } |
| 2369 | 2399 | |
| 2370 | 2400 | /** |
| 2371 | - * Set the customer's state. |
|
| 2372 | - * |
|
| 2373 | - * @since 1.0.19 |
|
| 2374 | - * @param string $value state. |
|
| 2375 | - */ |
|
| 2376 | - public function set_state( $value ) { |
|
| 2377 | - $this->set_prop( 'state', $value ); |
|
| 2401 | + * Set the customer's city. |
|
| 2402 | + * |
|
| 2403 | + * @since 1.0.19 |
|
| 2404 | + * @param string $value city. |
|
| 2405 | + */ |
|
| 2406 | + public function set_city( $value ) { |
|
| 2407 | + $this->set_prop( 'city', $value ); |
|
| 2378 | 2408 | } |
| 2379 | 2409 | |
| 2380 | 2410 | /** |
| 2381 | - * Alias of self::set_state(). |
|
| 2382 | - * |
|
| 2383 | - * @since 1.0.19 |
|
| 2384 | - * @param string $value state. |
|
| 2385 | - */ |
|
| 2386 | - public function set_user_state( $value ) { |
|
| 2387 | - $this->set_state( $value ); |
|
| 2411 | + * Alias of self::set_city(). |
|
| 2412 | + * |
|
| 2413 | + * @since 1.0.19 |
|
| 2414 | + * @param string $value city. |
|
| 2415 | + */ |
|
| 2416 | + public function set_user_city( $value ) { |
|
| 2417 | + $this->set_city( $value ); |
|
| 2388 | 2418 | } |
| 2389 | 2419 | |
| 2390 | 2420 | /** |
| 2391 | - * Alias of self::set_state(). |
|
| 2392 | - * |
|
| 2393 | - * @since 1.0.19 |
|
| 2394 | - * @param string $value state. |
|
| 2395 | - */ |
|
| 2396 | - public function set_customer_state( $value ) { |
|
| 2397 | - $this->set_state( $value ); |
|
| 2421 | + * Alias of self::set_city(). |
|
| 2422 | + * |
|
| 2423 | + * @since 1.0.19 |
|
| 2424 | + * @param string $value city. |
|
| 2425 | + */ |
|
| 2426 | + public function set_customer_city( $value ) { |
|
| 2427 | + $this->set_city( $value ); |
|
| 2398 | 2428 | } |
| 2399 | 2429 | |
| 2400 | 2430 | /** |
| 2401 | - * Set the customer's city. |
|
| 2402 | - * |
|
| 2403 | - * @since 1.0.19 |
|
| 2404 | - * @param string $value city. |
|
| 2405 | - */ |
|
| 2406 | - public function set_city( $value ) { |
|
| 2407 | - $this->set_prop( 'city', $value ); |
|
| 2431 | + * Set the customer's zip code. |
|
| 2432 | + * |
|
| 2433 | + * @since 1.0.19 |
|
| 2434 | + * @param string $value zip. |
|
| 2435 | + */ |
|
| 2436 | + public function set_zip( $value ) { |
|
| 2437 | + $this->set_prop( 'zip', $value ); |
|
| 2408 | 2438 | } |
| 2409 | 2439 | |
| 2410 | 2440 | /** |
| 2411 | - * Alias of self::set_city(). |
|
| 2412 | - * |
|
| 2413 | - * @since 1.0.19 |
|
| 2414 | - * @param string $value city. |
|
| 2415 | - */ |
|
| 2416 | - public function set_user_city( $value ) { |
|
| 2417 | - $this->set_city( $value ); |
|
| 2441 | + * Alias of self::set_zip(). |
|
| 2442 | + * |
|
| 2443 | + * @since 1.0.19 |
|
| 2444 | + * @param string $value zip. |
|
| 2445 | + */ |
|
| 2446 | + public function set_user_zip( $value ) { |
|
| 2447 | + $this->set_zip( $value ); |
|
| 2418 | 2448 | } |
| 2419 | 2449 | |
| 2420 | 2450 | /** |
| 2421 | - * Alias of self::set_city(). |
|
| 2422 | - * |
|
| 2423 | - * @since 1.0.19 |
|
| 2424 | - * @param string $value city. |
|
| 2425 | - */ |
|
| 2426 | - public function set_customer_city( $value ) { |
|
| 2427 | - $this->set_city( $value ); |
|
| 2451 | + * Alias of self::set_zip(). |
|
| 2452 | + * |
|
| 2453 | + * @since 1.0.19 |
|
| 2454 | + * @param string $value zip. |
|
| 2455 | + */ |
|
| 2456 | + public function set_customer_zip( $value ) { |
|
| 2457 | + $this->set_zip( $value ); |
|
| 2428 | 2458 | } |
| 2429 | 2459 | |
| 2430 | 2460 | /** |
| 2431 | - * Set the customer's zip code. |
|
| 2432 | - * |
|
| 2433 | - * @since 1.0.19 |
|
| 2434 | - * @param string $value zip. |
|
| 2435 | - */ |
|
| 2436 | - public function set_zip( $value ) { |
|
| 2437 | - $this->set_prop( 'zip', $value ); |
|
| 2461 | + * Set the customer's company. |
|
| 2462 | + * |
|
| 2463 | + * @since 1.0.19 |
|
| 2464 | + * @param string $value company. |
|
| 2465 | + */ |
|
| 2466 | + public function set_company( $value ) { |
|
| 2467 | + $this->set_prop( 'company', $value ); |
|
| 2438 | 2468 | } |
| 2439 | 2469 | |
| 2440 | 2470 | /** |
| 2441 | - * Alias of self::set_zip(). |
|
| 2442 | - * |
|
| 2443 | - * @since 1.0.19 |
|
| 2444 | - * @param string $value zip. |
|
| 2445 | - */ |
|
| 2446 | - public function set_user_zip( $value ) { |
|
| 2447 | - $this->set_zip( $value ); |
|
| 2471 | + * Alias of self::set_company(). |
|
| 2472 | + * |
|
| 2473 | + * @since 1.0.19 |
|
| 2474 | + * @param string $value company. |
|
| 2475 | + */ |
|
| 2476 | + public function set_user_company( $value ) { |
|
| 2477 | + $this->set_company( $value ); |
|
| 2448 | 2478 | } |
| 2449 | 2479 | |
| 2450 | 2480 | /** |
| 2451 | - * Alias of self::set_zip(). |
|
| 2452 | - * |
|
| 2453 | - * @since 1.0.19 |
|
| 2454 | - * @param string $value zip. |
|
| 2455 | - */ |
|
| 2456 | - public function set_customer_zip( $value ) { |
|
| 2457 | - $this->set_zip( $value ); |
|
| 2481 | + * Alias of self::set_company(). |
|
| 2482 | + * |
|
| 2483 | + * @since 1.0.19 |
|
| 2484 | + * @param string $value company. |
|
| 2485 | + */ |
|
| 2486 | + public function set_customer_company( $value ) { |
|
| 2487 | + $this->set_company( $value ); |
|
| 2458 | 2488 | } |
| 2459 | 2489 | |
| 2460 | 2490 | /** |
| 2461 | - * Set the customer's company. |
|
| 2462 | - * |
|
| 2463 | - * @since 1.0.19 |
|
| 2464 | - * @param string $value company. |
|
| 2465 | - */ |
|
| 2466 | - public function set_company( $value ) { |
|
| 2467 | - $this->set_prop( 'company', $value ); |
|
| 2491 | + * Set the customer's var number. |
|
| 2492 | + * |
|
| 2493 | + * @since 1.0.19 |
|
| 2494 | + * @param string $value var number. |
|
| 2495 | + */ |
|
| 2496 | + public function set_vat_number( $value ) { |
|
| 2497 | + $this->set_prop( 'vat_number', $value ); |
|
| 2468 | 2498 | } |
| 2469 | 2499 | |
| 2470 | 2500 | /** |
| 2471 | - * Alias of self::set_company(). |
|
| 2472 | - * |
|
| 2473 | - * @since 1.0.19 |
|
| 2474 | - * @param string $value company. |
|
| 2475 | - */ |
|
| 2476 | - public function set_user_company( $value ) { |
|
| 2477 | - $this->set_company( $value ); |
|
| 2501 | + * Alias of self::set_vat_number(). |
|
| 2502 | + * |
|
| 2503 | + * @since 1.0.19 |
|
| 2504 | + * @param string $value var number. |
|
| 2505 | + */ |
|
| 2506 | + public function set_user_vat_number( $value ) { |
|
| 2507 | + $this->set_vat_number( $value ); |
|
| 2478 | 2508 | } |
| 2479 | 2509 | |
| 2480 | 2510 | /** |
| 2481 | - * Alias of self::set_company(). |
|
| 2482 | - * |
|
| 2483 | - * @since 1.0.19 |
|
| 2484 | - * @param string $value company. |
|
| 2485 | - */ |
|
| 2486 | - public function set_customer_company( $value ) { |
|
| 2487 | - $this->set_company( $value ); |
|
| 2511 | + * Alias of self::set_vat_number(). |
|
| 2512 | + * |
|
| 2513 | + * @since 1.0.19 |
|
| 2514 | + * @param string $value var number. |
|
| 2515 | + */ |
|
| 2516 | + public function set_customer_vat_number( $value ) { |
|
| 2517 | + $this->set_vat_number( $value ); |
|
| 2488 | 2518 | } |
| 2489 | 2519 | |
| 2490 | 2520 | /** |
| 2491 | - * Set the customer's var number. |
|
| 2492 | - * |
|
| 2493 | - * @since 1.0.19 |
|
| 2494 | - * @param string $value var number. |
|
| 2495 | - */ |
|
| 2496 | - public function set_vat_number( $value ) { |
|
| 2497 | - $this->set_prop( 'vat_number', $value ); |
|
| 2521 | + * Set the customer's vat rate. |
|
| 2522 | + * |
|
| 2523 | + * @since 1.0.19 |
|
| 2524 | + * @param string $value var rate. |
|
| 2525 | + */ |
|
| 2526 | + public function set_vat_rate( $value ) { |
|
| 2527 | + $this->set_prop( 'vat_rate', $value ); |
|
| 2498 | 2528 | } |
| 2499 | 2529 | |
| 2500 | 2530 | /** |
| 2501 | - * Alias of self::set_vat_number(). |
|
| 2502 | - * |
|
| 2503 | - * @since 1.0.19 |
|
| 2504 | - * @param string $value var number. |
|
| 2505 | - */ |
|
| 2506 | - public function set_user_vat_number( $value ) { |
|
| 2507 | - $this->set_vat_number( $value ); |
|
| 2531 | + * Alias of self::set_vat_rate(). |
|
| 2532 | + * |
|
| 2533 | + * @since 1.0.19 |
|
| 2534 | + * @param string $value var number. |
|
| 2535 | + */ |
|
| 2536 | + public function set_user_vat_rate( $value ) { |
|
| 2537 | + $this->set_vat_rate( $value ); |
|
| 2508 | 2538 | } |
| 2509 | 2539 | |
| 2510 | 2540 | /** |
| 2511 | - * Alias of self::set_vat_number(). |
|
| 2512 | - * |
|
| 2513 | - * @since 1.0.19 |
|
| 2514 | - * @param string $value var number. |
|
| 2515 | - */ |
|
| 2516 | - public function set_customer_vat_number( $value ) { |
|
| 2517 | - $this->set_vat_number( $value ); |
|
| 2541 | + * Alias of self::set_vat_rate(). |
|
| 2542 | + * |
|
| 2543 | + * @since 1.0.19 |
|
| 2544 | + * @param string $value var number. |
|
| 2545 | + */ |
|
| 2546 | + public function set_customer_vat_rate( $value ) { |
|
| 2547 | + $this->set_vat_rate( $value ); |
|
| 2518 | 2548 | } |
| 2519 | 2549 | |
| 2520 | 2550 | /** |
| 2521 | - * Set the customer's vat rate. |
|
| 2522 | - * |
|
| 2523 | - * @since 1.0.19 |
|
| 2524 | - * @param string $value var rate. |
|
| 2525 | - */ |
|
| 2526 | - public function set_vat_rate( $value ) { |
|
| 2527 | - $this->set_prop( 'vat_rate', $value ); |
|
| 2551 | + * Set the customer's address. |
|
| 2552 | + * |
|
| 2553 | + * @since 1.0.19 |
|
| 2554 | + * @param string $value address. |
|
| 2555 | + */ |
|
| 2556 | + public function set_address( $value ) { |
|
| 2557 | + $this->set_prop( 'address', $value ); |
|
| 2528 | 2558 | } |
| 2529 | 2559 | |
| 2530 | 2560 | /** |
| 2531 | - * Alias of self::set_vat_rate(). |
|
| 2532 | - * |
|
| 2533 | - * @since 1.0.19 |
|
| 2534 | - * @param string $value var number. |
|
| 2535 | - */ |
|
| 2536 | - public function set_user_vat_rate( $value ) { |
|
| 2537 | - $this->set_vat_rate( $value ); |
|
| 2561 | + * Alias of self::set_address(). |
|
| 2562 | + * |
|
| 2563 | + * @since 1.0.19 |
|
| 2564 | + * @param string $value address. |
|
| 2565 | + */ |
|
| 2566 | + public function set_user_address( $value ) { |
|
| 2567 | + $this->set_address( $value ); |
|
| 2538 | 2568 | } |
| 2539 | 2569 | |
| 2540 | 2570 | /** |
| 2541 | - * Alias of self::set_vat_rate(). |
|
| 2542 | - * |
|
| 2543 | - * @since 1.0.19 |
|
| 2544 | - * @param string $value var number. |
|
| 2545 | - */ |
|
| 2546 | - public function set_customer_vat_rate( $value ) { |
|
| 2547 | - $this->set_vat_rate( $value ); |
|
| 2571 | + * Alias of self::set_address(). |
|
| 2572 | + * |
|
| 2573 | + * @since 1.0.19 |
|
| 2574 | + * @param string $value address. |
|
| 2575 | + */ |
|
| 2576 | + public function set_customer_address( $value ) { |
|
| 2577 | + $this->set_address( $value ); |
|
| 2548 | 2578 | } |
| 2549 | 2579 | |
| 2550 | 2580 | /** |
| 2551 | - * Set the customer's address. |
|
| 2552 | - * |
|
| 2553 | - * @since 1.0.19 |
|
| 2554 | - * @param string $value address. |
|
| 2555 | - */ |
|
| 2556 | - public function set_address( $value ) { |
|
| 2557 | - $this->set_prop( 'address', $value ); |
|
| 2581 | + * Set whether the customer has viewed the invoice or not. |
|
| 2582 | + * |
|
| 2583 | + * @since 1.0.19 |
|
| 2584 | + * @param int|bool $value confirmed. |
|
| 2585 | + */ |
|
| 2586 | + public function set_is_viewed( $value ) { |
|
| 2587 | + $this->set_prop( 'is_viewed', $value ); |
|
| 2558 | 2588 | } |
| 2559 | 2589 | |
| 2560 | 2590 | /** |
| 2561 | - * Alias of self::set_address(). |
|
| 2562 | - * |
|
| 2563 | - * @since 1.0.19 |
|
| 2564 | - * @param string $value address. |
|
| 2565 | - */ |
|
| 2566 | - public function set_user_address( $value ) { |
|
| 2567 | - $this->set_address( $value ); |
|
| 2591 | + * Set extra email recipients. |
|
| 2592 | + * |
|
| 2593 | + * @since 1.0.19 |
|
| 2594 | + * @param string $value email recipients. |
|
| 2595 | + */ |
|
| 2596 | + public function set_email_cc( $value ) { |
|
| 2597 | + $this->set_prop( 'email_cc', $value ); |
|
| 2568 | 2598 | } |
| 2569 | 2599 | |
| 2570 | 2600 | /** |
| 2571 | - * Alias of self::set_address(). |
|
| 2572 | - * |
|
| 2573 | - * @since 1.0.19 |
|
| 2574 | - * @param string $value address. |
|
| 2575 | - */ |
|
| 2576 | - public function set_customer_address( $value ) { |
|
| 2577 | - $this->set_address( $value ); |
|
| 2601 | + * Set the invoice template. |
|
| 2602 | + * |
|
| 2603 | + * @since 1.0.19 |
|
| 2604 | + * @param string $value email recipients. |
|
| 2605 | + */ |
|
| 2606 | + public function set_template( $value ) { |
|
| 2607 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2608 | + $this->set_prop( 'template', $value ); |
|
| 2609 | + } |
|
| 2578 | 2610 | } |
| 2579 | 2611 | |
| 2580 | 2612 | /** |
| 2581 | - * Set whether the customer has viewed the invoice or not. |
|
| 2582 | - * |
|
| 2583 | - * @since 1.0.19 |
|
| 2584 | - * @param int|bool $value confirmed. |
|
| 2585 | - */ |
|
| 2586 | - public function set_is_viewed( $value ) { |
|
| 2587 | - $this->set_prop( 'is_viewed', $value ); |
|
| 2588 | - } |
|
| 2589 | - |
|
| 2590 | - /** |
|
| 2591 | - * Set extra email recipients. |
|
| 2592 | - * |
|
| 2593 | - * @since 1.0.19 |
|
| 2594 | - * @param string $value email recipients. |
|
| 2595 | - */ |
|
| 2596 | - public function set_email_cc( $value ) { |
|
| 2597 | - $this->set_prop( 'email_cc', $value ); |
|
| 2598 | - } |
|
| 2599 | - |
|
| 2600 | - /** |
|
| 2601 | - * Set the invoice template. |
|
| 2602 | - * |
|
| 2603 | - * @since 1.0.19 |
|
| 2604 | - * @param string $value email recipients. |
|
| 2605 | - */ |
|
| 2606 | - public function set_template( $value ) { |
|
| 2607 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2608 | - $this->set_prop( 'template', $value ); |
|
| 2609 | - } |
|
| 2610 | - } |
|
| 2611 | - |
|
| 2612 | - /** |
|
| 2613 | - * Set the customer's address confirmed status. |
|
| 2614 | - * |
|
| 2615 | - * @since 1.0.19 |
|
| 2616 | - * @param int|bool $value confirmed. |
|
| 2617 | - */ |
|
| 2618 | - public function set_address_confirmed( $value ) { |
|
| 2619 | - $this->set_prop( 'address_confirmed', $value ); |
|
| 2613 | + * Set the customer's address confirmed status. |
|
| 2614 | + * |
|
| 2615 | + * @since 1.0.19 |
|
| 2616 | + * @param int|bool $value confirmed. |
|
| 2617 | + */ |
|
| 2618 | + public function set_address_confirmed( $value ) { |
|
| 2619 | + $this->set_prop( 'address_confirmed', $value ); |
|
| 2620 | 2620 | } |
| 2621 | 2621 | |
| 2622 | 2622 | /** |
| 2623 | - * Alias of self::set_address_confirmed(). |
|
| 2624 | - * |
|
| 2625 | - * @since 1.0.19 |
|
| 2626 | - * @param int|bool $value confirmed. |
|
| 2627 | - */ |
|
| 2628 | - public function set_user_address_confirmed( $value ) { |
|
| 2629 | - $this->set_address_confirmed( $value ); |
|
| 2623 | + * Alias of self::set_address_confirmed(). |
|
| 2624 | + * |
|
| 2625 | + * @since 1.0.19 |
|
| 2626 | + * @param int|bool $value confirmed. |
|
| 2627 | + */ |
|
| 2628 | + public function set_user_address_confirmed( $value ) { |
|
| 2629 | + $this->set_address_confirmed( $value ); |
|
| 2630 | 2630 | } |
| 2631 | 2631 | |
| 2632 | 2632 | /** |
| 2633 | - * Alias of self::set_address_confirmed(). |
|
| 2634 | - * |
|
| 2635 | - * @since 1.0.19 |
|
| 2636 | - * @param int|bool $value confirmed. |
|
| 2637 | - */ |
|
| 2638 | - public function set_customer_address_confirmed( $value ) { |
|
| 2639 | - $this->set_address_confirmed( $value ); |
|
| 2633 | + * Alias of self::set_address_confirmed(). |
|
| 2634 | + * |
|
| 2635 | + * @since 1.0.19 |
|
| 2636 | + * @param int|bool $value confirmed. |
|
| 2637 | + */ |
|
| 2638 | + public function set_customer_address_confirmed( $value ) { |
|
| 2639 | + $this->set_address_confirmed( $value ); |
|
| 2640 | 2640 | } |
| 2641 | 2641 | |
| 2642 | 2642 | /** |
| 2643 | - * Set the invoice sub total. |
|
| 2644 | - * |
|
| 2645 | - * @since 1.0.19 |
|
| 2646 | - * @param float $value sub total. |
|
| 2647 | - */ |
|
| 2648 | - public function set_subtotal( $value ) { |
|
| 2649 | - $this->set_prop( 'subtotal', $value ); |
|
| 2643 | + * Set the invoice sub total. |
|
| 2644 | + * |
|
| 2645 | + * @since 1.0.19 |
|
| 2646 | + * @param float $value sub total. |
|
| 2647 | + */ |
|
| 2648 | + public function set_subtotal( $value ) { |
|
| 2649 | + $this->set_prop( 'subtotal', $value ); |
|
| 2650 | 2650 | } |
| 2651 | 2651 | |
| 2652 | 2652 | /** |
| 2653 | - * Set the invoice discount amount. |
|
| 2654 | - * |
|
| 2655 | - * @since 1.0.19 |
|
| 2656 | - * @param float $value discount total. |
|
| 2657 | - */ |
|
| 2658 | - public function set_total_discount( $value ) { |
|
| 2659 | - $this->set_prop( 'total_discount', $value ); |
|
| 2653 | + * Set the invoice discount amount. |
|
| 2654 | + * |
|
| 2655 | + * @since 1.0.19 |
|
| 2656 | + * @param float $value discount total. |
|
| 2657 | + */ |
|
| 2658 | + public function set_total_discount( $value ) { |
|
| 2659 | + $this->set_prop( 'total_discount', $value ); |
|
| 2660 | 2660 | } |
| 2661 | 2661 | |
| 2662 | 2662 | /** |
| 2663 | - * Alias of self::set_total_discount(). |
|
| 2664 | - * |
|
| 2665 | - * @since 1.0.19 |
|
| 2666 | - * @param float $value discount total. |
|
| 2667 | - */ |
|
| 2668 | - public function set_discount( $value ) { |
|
| 2669 | - $this->set_total_discount( $value ); |
|
| 2663 | + * Alias of self::set_total_discount(). |
|
| 2664 | + * |
|
| 2665 | + * @since 1.0.19 |
|
| 2666 | + * @param float $value discount total. |
|
| 2667 | + */ |
|
| 2668 | + public function set_discount( $value ) { |
|
| 2669 | + $this->set_total_discount( $value ); |
|
| 2670 | 2670 | } |
| 2671 | 2671 | |
| 2672 | 2672 | /** |
| 2673 | - * Set the invoice tax amount. |
|
| 2674 | - * |
|
| 2675 | - * @since 1.0.19 |
|
| 2676 | - * @param float $value tax total. |
|
| 2677 | - */ |
|
| 2678 | - public function set_total_tax( $value ) { |
|
| 2679 | - $this->set_prop( 'total_tax', $value ); |
|
| 2673 | + * Set the invoice tax amount. |
|
| 2674 | + * |
|
| 2675 | + * @since 1.0.19 |
|
| 2676 | + * @param float $value tax total. |
|
| 2677 | + */ |
|
| 2678 | + public function set_total_tax( $value ) { |
|
| 2679 | + $this->set_prop( 'total_tax', $value ); |
|
| 2680 | 2680 | } |
| 2681 | 2681 | |
| 2682 | 2682 | /** |
| 2683 | - * Alias of self::set_total_tax(). |
|
| 2684 | - * |
|
| 2685 | - * @since 1.0.19 |
|
| 2686 | - * @param float $value tax total. |
|
| 2687 | - */ |
|
| 2688 | - public function set_tax_total( $value ) { |
|
| 2689 | - $this->set_total_tax( $value ); |
|
| 2683 | + * Alias of self::set_total_tax(). |
|
| 2684 | + * |
|
| 2685 | + * @since 1.0.19 |
|
| 2686 | + * @param float $value tax total. |
|
| 2687 | + */ |
|
| 2688 | + public function set_tax_total( $value ) { |
|
| 2689 | + $this->set_total_tax( $value ); |
|
| 2690 | 2690 | } |
| 2691 | 2691 | |
| 2692 | 2692 | /** |
| 2693 | - * Set the invoice fees amount. |
|
| 2694 | - * |
|
| 2695 | - * @since 1.0.19 |
|
| 2696 | - * @param float $value fees total. |
|
| 2697 | - */ |
|
| 2698 | - public function set_total_fees( $value ) { |
|
| 2699 | - $this->set_prop( 'total_fees', $value ); |
|
| 2693 | + * Set the invoice fees amount. |
|
| 2694 | + * |
|
| 2695 | + * @since 1.0.19 |
|
| 2696 | + * @param float $value fees total. |
|
| 2697 | + */ |
|
| 2698 | + public function set_total_fees( $value ) { |
|
| 2699 | + $this->set_prop( 'total_fees', $value ); |
|
| 2700 | 2700 | } |
| 2701 | 2701 | |
| 2702 | 2702 | /** |
| 2703 | - * Alias of self::set_total_fees(). |
|
| 2704 | - * |
|
| 2705 | - * @since 1.0.19 |
|
| 2706 | - * @param float $value fees total. |
|
| 2707 | - */ |
|
| 2708 | - public function set_fees_total( $value ) { |
|
| 2709 | - $this->set_total_fees( $value ); |
|
| 2703 | + * Alias of self::set_total_fees(). |
|
| 2704 | + * |
|
| 2705 | + * @since 1.0.19 |
|
| 2706 | + * @param float $value fees total. |
|
| 2707 | + */ |
|
| 2708 | + public function set_fees_total( $value ) { |
|
| 2709 | + $this->set_total_fees( $value ); |
|
| 2710 | 2710 | } |
| 2711 | 2711 | |
| 2712 | 2712 | /** |
| 2713 | - * Set the invoice fees. |
|
| 2714 | - * |
|
| 2715 | - * @since 1.0.19 |
|
| 2716 | - * @param array $value fees. |
|
| 2717 | - */ |
|
| 2718 | - public function set_fees( $value ) { |
|
| 2713 | + * Set the invoice fees. |
|
| 2714 | + * |
|
| 2715 | + * @since 1.0.19 |
|
| 2716 | + * @param array $value fees. |
|
| 2717 | + */ |
|
| 2718 | + public function set_fees( $value ) { |
|
| 2719 | 2719 | |
| 2720 | 2720 | $this->set_prop( 'fees', array() ); |
| 2721 | 2721 | |
@@ -2733,23 +2733,23 @@ discard block |
||
| 2733 | 2733 | } |
| 2734 | 2734 | |
| 2735 | 2735 | /** |
| 2736 | - * Set the invoice taxes. |
|
| 2737 | - * |
|
| 2738 | - * @since 1.0.19 |
|
| 2739 | - * @param array $value taxes. |
|
| 2740 | - */ |
|
| 2741 | - public function set_taxes( $value ) { |
|
| 2742 | - $this->set_prop( 'taxes', $value ); |
|
| 2736 | + * Set the invoice taxes. |
|
| 2737 | + * |
|
| 2738 | + * @since 1.0.19 |
|
| 2739 | + * @param array $value taxes. |
|
| 2740 | + */ |
|
| 2741 | + public function set_taxes( $value ) { |
|
| 2742 | + $this->set_prop( 'taxes', $value ); |
|
| 2743 | 2743 | } |
| 2744 | 2744 | |
| 2745 | 2745 | /** |
| 2746 | - * Set the invoice discounts. |
|
| 2747 | - * |
|
| 2748 | - * @since 1.0.19 |
|
| 2749 | - * @param array $value discounts. |
|
| 2750 | - */ |
|
| 2751 | - public function set_discounts( $value ) { |
|
| 2752 | - $this->set_prop( 'discounts', array() ); |
|
| 2746 | + * Set the invoice discounts. |
|
| 2747 | + * |
|
| 2748 | + * @since 1.0.19 |
|
| 2749 | + * @param array $value discounts. |
|
| 2750 | + */ |
|
| 2751 | + public function set_discounts( $value ) { |
|
| 2752 | + $this->set_prop( 'discounts', array() ); |
|
| 2753 | 2753 | |
| 2754 | 2754 | // Ensure that we have an array. |
| 2755 | 2755 | if ( ! is_array( $value ) ) { |
@@ -2764,12 +2764,12 @@ discard block |
||
| 2764 | 2764 | } |
| 2765 | 2765 | |
| 2766 | 2766 | /** |
| 2767 | - * Set the invoice items. |
|
| 2768 | - * |
|
| 2769 | - * @since 1.0.19 |
|
| 2770 | - * @param GetPaid_Form_Item[] $value items. |
|
| 2771 | - */ |
|
| 2772 | - public function set_items( $value ) { |
|
| 2767 | + * Set the invoice items. |
|
| 2768 | + * |
|
| 2769 | + * @since 1.0.19 |
|
| 2770 | + * @param GetPaid_Form_Item[] $value items. |
|
| 2771 | + */ |
|
| 2772 | + public function set_items( $value ) { |
|
| 2773 | 2773 | |
| 2774 | 2774 | // Remove existing items. |
| 2775 | 2775 | $this->set_prop( 'items', array() ); |
@@ -2786,85 +2786,85 @@ discard block |
||
| 2786 | 2786 | } |
| 2787 | 2787 | |
| 2788 | 2788 | /** |
| 2789 | - * Set the payment form. |
|
| 2790 | - * |
|
| 2791 | - * @since 1.0.19 |
|
| 2792 | - * @param int $value payment form. |
|
| 2793 | - */ |
|
| 2794 | - public function set_payment_form( $value ) { |
|
| 2795 | - $this->set_prop( 'payment_form', $value ); |
|
| 2789 | + * Set the payment form. |
|
| 2790 | + * |
|
| 2791 | + * @since 1.0.19 |
|
| 2792 | + * @param int $value payment form. |
|
| 2793 | + */ |
|
| 2794 | + public function set_payment_form( $value ) { |
|
| 2795 | + $this->set_prop( 'payment_form', $value ); |
|
| 2796 | 2796 | } |
| 2797 | 2797 | |
| 2798 | 2798 | /** |
| 2799 | - * Set the submission id. |
|
| 2800 | - * |
|
| 2801 | - * @since 1.0.19 |
|
| 2802 | - * @param string $value submission id. |
|
| 2803 | - */ |
|
| 2804 | - public function set_submission_id( $value ) { |
|
| 2805 | - $this->set_prop( 'submission_id', $value ); |
|
| 2799 | + * Set the submission id. |
|
| 2800 | + * |
|
| 2801 | + * @since 1.0.19 |
|
| 2802 | + * @param string $value submission id. |
|
| 2803 | + */ |
|
| 2804 | + public function set_submission_id( $value ) { |
|
| 2805 | + $this->set_prop( 'submission_id', $value ); |
|
| 2806 | 2806 | } |
| 2807 | 2807 | |
| 2808 | 2808 | /** |
| 2809 | - * Set the discount code. |
|
| 2810 | - * |
|
| 2811 | - * @since 1.0.19 |
|
| 2812 | - * @param string $value discount code. |
|
| 2813 | - */ |
|
| 2814 | - public function set_discount_code( $value ) { |
|
| 2815 | - $this->set_prop( 'discount_code', $value ); |
|
| 2809 | + * Set the discount code. |
|
| 2810 | + * |
|
| 2811 | + * @since 1.0.19 |
|
| 2812 | + * @param string $value discount code. |
|
| 2813 | + */ |
|
| 2814 | + public function set_discount_code( $value ) { |
|
| 2815 | + $this->set_prop( 'discount_code', $value ); |
|
| 2816 | 2816 | } |
| 2817 | 2817 | |
| 2818 | 2818 | /** |
| 2819 | - * Set the gateway. |
|
| 2820 | - * |
|
| 2821 | - * @since 1.0.19 |
|
| 2822 | - * @param string $value gateway. |
|
| 2823 | - */ |
|
| 2824 | - public function set_gateway( $value ) { |
|
| 2825 | - $this->set_prop( 'gateway', $value ); |
|
| 2819 | + * Set the gateway. |
|
| 2820 | + * |
|
| 2821 | + * @since 1.0.19 |
|
| 2822 | + * @param string $value gateway. |
|
| 2823 | + */ |
|
| 2824 | + public function set_gateway( $value ) { |
|
| 2825 | + $this->set_prop( 'gateway', $value ); |
|
| 2826 | 2826 | } |
| 2827 | 2827 | |
| 2828 | 2828 | /** |
| 2829 | - * Set the transaction id. |
|
| 2830 | - * |
|
| 2831 | - * @since 1.0.19 |
|
| 2832 | - * @param string $value transaction id. |
|
| 2833 | - */ |
|
| 2834 | - public function set_transaction_id( $value ) { |
|
| 2835 | - if ( ! empty( $value ) ) { |
|
| 2836 | - $this->set_prop( 'transaction_id', $value ); |
|
| 2837 | - } |
|
| 2829 | + * Set the transaction id. |
|
| 2830 | + * |
|
| 2831 | + * @since 1.0.19 |
|
| 2832 | + * @param string $value transaction id. |
|
| 2833 | + */ |
|
| 2834 | + public function set_transaction_id( $value ) { |
|
| 2835 | + if ( ! empty( $value ) ) { |
|
| 2836 | + $this->set_prop( 'transaction_id', $value ); |
|
| 2837 | + } |
|
| 2838 | 2838 | } |
| 2839 | 2839 | |
| 2840 | 2840 | /** |
| 2841 | - * Set the currency id. |
|
| 2842 | - * |
|
| 2843 | - * @since 1.0.19 |
|
| 2844 | - * @param string $value currency id. |
|
| 2845 | - */ |
|
| 2846 | - public function set_currency( $value ) { |
|
| 2847 | - $this->set_prop( 'currency', $value ); |
|
| 2841 | + * Set the currency id. |
|
| 2842 | + * |
|
| 2843 | + * @since 1.0.19 |
|
| 2844 | + * @param string $value currency id. |
|
| 2845 | + */ |
|
| 2846 | + public function set_currency( $value ) { |
|
| 2847 | + $this->set_prop( 'currency', $value ); |
|
| 2848 | 2848 | } |
| 2849 | 2849 | |
| 2850 | - /** |
|
| 2851 | - * Set whether to disable taxes. |
|
| 2852 | - * |
|
| 2853 | - * @since 1.0.19 |
|
| 2854 | - * @param bool $value value. |
|
| 2855 | - */ |
|
| 2856 | - public function set_disable_taxes( $value ) { |
|
| 2857 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 2858 | - } |
|
| 2850 | + /** |
|
| 2851 | + * Set whether to disable taxes. |
|
| 2852 | + * |
|
| 2853 | + * @since 1.0.19 |
|
| 2854 | + * @param bool $value value. |
|
| 2855 | + */ |
|
| 2856 | + public function set_disable_taxes( $value ) { |
|
| 2857 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 2858 | + } |
|
| 2859 | 2859 | |
| 2860 | 2860 | /** |
| 2861 | - * Set the subscription id. |
|
| 2862 | - * |
|
| 2863 | - * @since 1.0.19 |
|
| 2864 | - * @param string $value subscription id. |
|
| 2865 | - */ |
|
| 2866 | - public function set_subscription_id( $value ) { |
|
| 2867 | - $this->set_prop( 'subscription_id', $value ); |
|
| 2861 | + * Set the subscription id. |
|
| 2862 | + * |
|
| 2863 | + * @since 1.0.19 |
|
| 2864 | + * @param string $value subscription id. |
|
| 2865 | + */ |
|
| 2866 | + public function set_subscription_id( $value ) { |
|
| 2867 | + $this->set_prop( 'subscription_id', $value ); |
|
| 2868 | 2868 | } |
| 2869 | 2869 | |
| 2870 | 2870 | /* |
@@ -2903,12 +2903,12 @@ discard block |
||
| 2903 | 2903 | */ |
| 2904 | 2904 | public function is_taxable() { |
| 2905 | 2905 | return ! $this->get_disable_taxes(); |
| 2906 | - } |
|
| 2906 | + } |
|
| 2907 | 2907 | |
| 2908 | - /** |
|
| 2909 | - * @deprecated |
|
| 2910 | - */ |
|
| 2911 | - public function has_vat() { |
|
| 2908 | + /** |
|
| 2909 | + * @deprecated |
|
| 2910 | + */ |
|
| 2911 | + public function has_vat() { |
|
| 2912 | 2912 | global $wpinv_euvat, $wpi_country; |
| 2913 | 2913 | |
| 2914 | 2914 | $requires_vat = false; |
@@ -2919,17 +2919,17 @@ discard block |
||
| 2919 | 2919 | } |
| 2920 | 2920 | |
| 2921 | 2921 | return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
| 2922 | - } |
|
| 2922 | + } |
|
| 2923 | 2923 | |
| 2924 | - /** |
|
| 2925 | - * Checks to see if the invoice requires payment. |
|
| 2926 | - */ |
|
| 2927 | - public function is_free() { |
|
| 2924 | + /** |
|
| 2925 | + * Checks to see if the invoice requires payment. |
|
| 2926 | + */ |
|
| 2927 | + public function is_free() { |
|
| 2928 | 2928 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
| 2929 | 2929 | |
| 2930 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 2931 | - $is_free = false; |
|
| 2932 | - } |
|
| 2930 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 2931 | + $is_free = false; |
|
| 2932 | + } |
|
| 2933 | 2933 | |
| 2934 | 2934 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
| 2935 | 2935 | } |
@@ -2940,46 +2940,46 @@ discard block |
||
| 2940 | 2940 | public function is_paid() { |
| 2941 | 2941 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
| 2942 | 2942 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
| 2943 | - } |
|
| 2943 | + } |
|
| 2944 | 2944 | |
| 2945 | - /** |
|
| 2945 | + /** |
|
| 2946 | 2946 | * Checks if the invoice needs payment. |
| 2947 | 2947 | */ |
| 2948 | - public function needs_payment() { |
|
| 2949 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 2948 | + public function needs_payment() { |
|
| 2949 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 2950 | 2950 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
| 2951 | 2951 | } |
| 2952 | 2952 | |
| 2953 | - /** |
|
| 2953 | + /** |
|
| 2954 | 2954 | * Checks if the invoice is refunded. |
| 2955 | 2955 | */ |
| 2956 | - public function is_refunded() { |
|
| 2956 | + public function is_refunded() { |
|
| 2957 | 2957 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
| 2958 | 2958 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
| 2959 | - } |
|
| 2959 | + } |
|
| 2960 | 2960 | |
| 2961 | - /** |
|
| 2961 | + /** |
|
| 2962 | 2962 | * Checks if the invoice is held. |
| 2963 | 2963 | */ |
| 2964 | - public function is_held() { |
|
| 2964 | + public function is_held() { |
|
| 2965 | 2965 | $is_held = $this->has_status( 'wpi-onhold' ); |
| 2966 | 2966 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
| 2967 | - } |
|
| 2967 | + } |
|
| 2968 | 2968 | |
| 2969 | - /** |
|
| 2969 | + /** |
|
| 2970 | 2970 | * Checks if the invoice is due. |
| 2971 | 2971 | */ |
| 2972 | - public function is_due() { |
|
| 2973 | - $due_date = $this->get_due_date(); |
|
| 2974 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 2975 | - } |
|
| 2972 | + public function is_due() { |
|
| 2973 | + $due_date = $this->get_due_date(); |
|
| 2974 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 2975 | + } |
|
| 2976 | 2976 | |
| 2977 | - /** |
|
| 2977 | + /** |
|
| 2978 | 2978 | * Checks if the invoice is draft. |
| 2979 | 2979 | */ |
| 2980 | - public function is_draft() { |
|
| 2980 | + public function is_draft() { |
|
| 2981 | 2981 | return $this->has_status( 'draft, auto-draft' ); |
| 2982 | - } |
|
| 2982 | + } |
|
| 2983 | 2983 | |
| 2984 | 2984 | /** |
| 2985 | 2985 | * Checks if the invoice has a given status. |
@@ -2987,9 +2987,9 @@ discard block |
||
| 2987 | 2987 | public function has_status( $status ) { |
| 2988 | 2988 | $status = wpinv_parse_list( $status ); |
| 2989 | 2989 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
| 2990 | - } |
|
| 2990 | + } |
|
| 2991 | 2991 | |
| 2992 | - /** |
|
| 2992 | + /** |
|
| 2993 | 2993 | * Checks if the invoice is of a given type. |
| 2994 | 2994 | */ |
| 2995 | 2995 | public function is_type( $type ) { |
@@ -3012,25 +3012,25 @@ discard block |
||
| 3012 | 3012 | */ |
| 3013 | 3013 | public function has_free_trial() { |
| 3014 | 3014 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
| 3015 | - } |
|
| 3015 | + } |
|
| 3016 | 3016 | |
| 3017 | - /** |
|
| 3017 | + /** |
|
| 3018 | 3018 | * @deprecated |
| 3019 | 3019 | */ |
| 3020 | 3020 | public function is_free_trial() { |
| 3021 | 3021 | $this->has_free_trial(); |
| 3022 | 3022 | } |
| 3023 | 3023 | |
| 3024 | - /** |
|
| 3024 | + /** |
|
| 3025 | 3025 | * Check if the initial payment if 0. |
| 3026 | 3026 | * |
| 3027 | 3027 | */ |
| 3028 | - public function is_initial_free() { |
|
| 3028 | + public function is_initial_free() { |
|
| 3029 | 3029 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
| 3030 | 3030 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
| 3031 | 3031 | } |
| 3032 | 3032 | |
| 3033 | - /** |
|
| 3033 | + /** |
|
| 3034 | 3034 | * Check if the recurring item has a free trial. |
| 3035 | 3035 | * |
| 3036 | 3036 | */ |
@@ -3043,21 +3043,21 @@ discard block |
||
| 3043 | 3043 | |
| 3044 | 3044 | $item = $this->get_recurring( true ); |
| 3045 | 3045 | return $item->has_free_trial(); |
| 3046 | - } |
|
| 3046 | + } |
|
| 3047 | 3047 | |
| 3048 | - /** |
|
| 3048 | + /** |
|
| 3049 | 3049 | * Check if the free trial is a result of a discount. |
| 3050 | 3050 | */ |
| 3051 | 3051 | public function is_free_trial_from_discount() { |
| 3052 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3053 | - } |
|
| 3052 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3053 | + } |
|
| 3054 | 3054 | |
| 3055 | - /** |
|
| 3055 | + /** |
|
| 3056 | 3056 | * @deprecated |
| 3057 | 3057 | */ |
| 3058 | 3058 | public function discount_first_payment_only() { |
| 3059 | 3059 | |
| 3060 | - $discount_code = $this->get_discount_code(); |
|
| 3060 | + $discount_code = $this->get_discount_code(); |
|
| 3061 | 3061 | if ( empty( $this->discount_code ) || ! $this->is_recurring() ) { |
| 3062 | 3062 | return true; |
| 3063 | 3063 | } |
@@ -3088,28 +3088,28 @@ discard block |
||
| 3088 | 3088 | */ |
| 3089 | 3089 | public function add_item( $item ) { |
| 3090 | 3090 | |
| 3091 | - if ( is_array( $item ) ) { |
|
| 3092 | - $item = $this->process_array_item( $item ); |
|
| 3093 | - } |
|
| 3091 | + if ( is_array( $item ) ) { |
|
| 3092 | + $item = $this->process_array_item( $item ); |
|
| 3093 | + } |
|
| 3094 | 3094 | |
| 3095 | - if ( is_numeric( $item ) ) { |
|
| 3096 | - $item = new GetPaid_Form_Item( $item ); |
|
| 3097 | - } |
|
| 3095 | + if ( is_numeric( $item ) ) { |
|
| 3096 | + $item = new GetPaid_Form_Item( $item ); |
|
| 3097 | + } |
|
| 3098 | 3098 | |
| 3099 | 3099 | // Make sure that it is available for purchase. |
| 3100 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3101 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3100 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3101 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3102 | 3102 | } |
| 3103 | 3103 | |
| 3104 | 3104 | // Do we have a recurring item? |
| 3105 | - if ( $item->is_recurring() ) { |
|
| 3105 | + if ( $item->is_recurring() ) { |
|
| 3106 | 3106 | |
| 3107 | - // An invoice can only contain one recurring item. |
|
| 3108 | - if ( ! empty( $this->recurring_item && $this->recurring_item != (int) $item->get_id() ) ) { |
|
| 3109 | - return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) ); |
|
| 3110 | - } |
|
| 3107 | + // An invoice can only contain one recurring item. |
|
| 3108 | + if ( ! empty( $this->recurring_item && $this->recurring_item != (int) $item->get_id() ) ) { |
|
| 3109 | + return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) ); |
|
| 3110 | + } |
|
| 3111 | 3111 | |
| 3112 | - $this->recurring_item = $item->get_id(); |
|
| 3112 | + $this->recurring_item = $item->get_id(); |
|
| 3113 | 3113 | } |
| 3114 | 3114 | |
| 3115 | 3115 | // Invoice id. |
@@ -3120,60 +3120,60 @@ discard block |
||
| 3120 | 3120 | $items[ (int) $item->get_id() ] = $item; |
| 3121 | 3121 | |
| 3122 | 3122 | $this->set_prop( 'items', $items ); |
| 3123 | - return true; |
|
| 3124 | - } |
|
| 3123 | + return true; |
|
| 3124 | + } |
|
| 3125 | 3125 | |
| 3126 | - /** |
|
| 3127 | - * Converts an array to an item. |
|
| 3128 | - * |
|
| 3129 | - * @since 1.0.19 |
|
| 3130 | - * @return GetPaid_Form_Item |
|
| 3131 | - */ |
|
| 3132 | - protected function process_array_item( $array ) { |
|
| 3133 | - |
|
| 3134 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3135 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 3136 | - |
|
| 3137 | - // Set item data. |
|
| 3138 | - foreach( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3139 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3140 | - $method = "set_$key"; |
|
| 3141 | - $item->$method( $array[ "item_$key" ] ); |
|
| 3142 | - } |
|
| 3143 | - } |
|
| 3144 | - |
|
| 3145 | - if ( isset( $array['quantity'] ) ) { |
|
| 3146 | - $item->set_quantity( $array['quantity'] ); |
|
| 3147 | - } |
|
| 3148 | - |
|
| 3149 | - // Set item meta. |
|
| 3150 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3151 | - $item->set_item_meta( $array['meta'] ); |
|
| 3152 | - } |
|
| 3153 | - |
|
| 3154 | - return $item; |
|
| 3155 | - |
|
| 3156 | - } |
|
| 3157 | - |
|
| 3158 | - /** |
|
| 3159 | - * Retrieves a specific item. |
|
| 3160 | - * |
|
| 3161 | - * @since 1.0.19 |
|
| 3162 | - */ |
|
| 3163 | - public function get_item( $item_id ) { |
|
| 3164 | - $items = $this->get_items(); |
|
| 3165 | - $item_id = (int) $item_id; |
|
| 3166 | - return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
| 3167 | - } |
|
| 3168 | - |
|
| 3169 | - /** |
|
| 3170 | - * Removes a specific item. |
|
| 3171 | - * |
|
| 3172 | - * @since 1.0.19 |
|
| 3173 | - */ |
|
| 3174 | - public function remove_item( $item_id ) { |
|
| 3175 | - $items = $this->get_items(); |
|
| 3176 | - $item_id = (int) $item_id; |
|
| 3126 | + /** |
|
| 3127 | + * Converts an array to an item. |
|
| 3128 | + * |
|
| 3129 | + * @since 1.0.19 |
|
| 3130 | + * @return GetPaid_Form_Item |
|
| 3131 | + */ |
|
| 3132 | + protected function process_array_item( $array ) { |
|
| 3133 | + |
|
| 3134 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3135 | + $item = new GetPaid_Form_Item( $item_id ); |
|
| 3136 | + |
|
| 3137 | + // Set item data. |
|
| 3138 | + foreach( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3139 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3140 | + $method = "set_$key"; |
|
| 3141 | + $item->$method( $array[ "item_$key" ] ); |
|
| 3142 | + } |
|
| 3143 | + } |
|
| 3144 | + |
|
| 3145 | + if ( isset( $array['quantity'] ) ) { |
|
| 3146 | + $item->set_quantity( $array['quantity'] ); |
|
| 3147 | + } |
|
| 3148 | + |
|
| 3149 | + // Set item meta. |
|
| 3150 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3151 | + $item->set_item_meta( $array['meta'] ); |
|
| 3152 | + } |
|
| 3153 | + |
|
| 3154 | + return $item; |
|
| 3155 | + |
|
| 3156 | + } |
|
| 3157 | + |
|
| 3158 | + /** |
|
| 3159 | + * Retrieves a specific item. |
|
| 3160 | + * |
|
| 3161 | + * @since 1.0.19 |
|
| 3162 | + */ |
|
| 3163 | + public function get_item( $item_id ) { |
|
| 3164 | + $items = $this->get_items(); |
|
| 3165 | + $item_id = (int) $item_id; |
|
| 3166 | + return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
| 3167 | + } |
|
| 3168 | + |
|
| 3169 | + /** |
|
| 3170 | + * Removes a specific item. |
|
| 3171 | + * |
|
| 3172 | + * @since 1.0.19 |
|
| 3173 | + */ |
|
| 3174 | + public function remove_item( $item_id ) { |
|
| 3175 | + $items = $this->get_items(); |
|
| 3176 | + $item_id = (int) $item_id; |
|
| 3177 | 3177 | |
| 3178 | 3178 | if ( $item_id == $this->recurring_item ) { |
| 3179 | 3179 | $this->recurring_item = null; |
@@ -3200,38 +3200,38 @@ discard block |
||
| 3200 | 3200 | if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) { |
| 3201 | 3201 | |
| 3202 | 3202 | $amount = $fees[ $fee ]['amount'] += $amount; |
| 3203 | - $fees[ $fee ] = array( |
|
| 3204 | - 'amount' => $amount, |
|
| 3203 | + $fees[ $fee ] = array( |
|
| 3204 | + 'amount' => $amount, |
|
| 3205 | 3205 | 'recurring' => (bool) $recurring, |
| 3206 | 3206 | ); |
| 3207 | 3207 | |
| 3208 | - } else { |
|
| 3209 | - $fees[ $fee ] = array( |
|
| 3208 | + } else { |
|
| 3209 | + $fees[ $fee ] = array( |
|
| 3210 | 3210 | 'amount' => $amount, |
| 3211 | 3211 | 'recurring' => (bool) $recurring, |
| 3212 | 3212 | ); |
| 3213 | - } |
|
| 3213 | + } |
|
| 3214 | 3214 | |
| 3215 | 3215 | $this->set_prop( 'fees', $fee ); |
| 3216 | 3216 | |
| 3217 | 3217 | } |
| 3218 | 3218 | |
| 3219 | 3219 | /** |
| 3220 | - * Retrieves a specific fee. |
|
| 3221 | - * |
|
| 3222 | - * @since 1.0.19 |
|
| 3223 | - */ |
|
| 3224 | - public function get_fee( $fee ) { |
|
| 3220 | + * Retrieves a specific fee. |
|
| 3221 | + * |
|
| 3222 | + * @since 1.0.19 |
|
| 3223 | + */ |
|
| 3224 | + public function get_fee( $fee ) { |
|
| 3225 | 3225 | $fees = $this->get_fees(); |
| 3226 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3226 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3227 | 3227 | } |
| 3228 | 3228 | |
| 3229 | 3229 | /** |
| 3230 | - * Removes a specific fee. |
|
| 3231 | - * |
|
| 3232 | - * @since 1.0.19 |
|
| 3233 | - */ |
|
| 3234 | - public function remove_fee( $fee ) { |
|
| 3230 | + * Removes a specific fee. |
|
| 3231 | + * |
|
| 3232 | + * @since 1.0.19 |
|
| 3233 | + */ |
|
| 3234 | + public function remove_fee( $fee ) { |
|
| 3235 | 3235 | $fees = $this->get_fees(); |
| 3236 | 3236 | if ( isset( $fees[ $fee ] ) ) { |
| 3237 | 3237 | unset( $fees[ $fee ] ); |
@@ -3254,44 +3254,44 @@ discard block |
||
| 3254 | 3254 | if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) { |
| 3255 | 3255 | |
| 3256 | 3256 | $amount = $discounts[ $discount ]['amount'] += $amount; |
| 3257 | - $discounts[ $discount ] = array( |
|
| 3257 | + $discounts[ $discount ] = array( |
|
| 3258 | 3258 | 'amount' => $amount, |
| 3259 | 3259 | 'recurring' => (bool) $recurring, |
| 3260 | 3260 | ); |
| 3261 | 3261 | |
| 3262 | - } else { |
|
| 3263 | - $discounts[ $discount ] = array( |
|
| 3262 | + } else { |
|
| 3263 | + $discounts[ $discount ] = array( |
|
| 3264 | 3264 | 'amount' => $amount, |
| 3265 | 3265 | 'recurring' => (bool) $recurring, |
| 3266 | 3266 | ); |
| 3267 | - } |
|
| 3267 | + } |
|
| 3268 | 3268 | |
| 3269 | 3269 | $this->set_prop( 'discounts', $discount ); |
| 3270 | 3270 | |
| 3271 | 3271 | } |
| 3272 | 3272 | |
| 3273 | 3273 | /** |
| 3274 | - * Retrieves a specific discount. |
|
| 3275 | - * |
|
| 3276 | - * @since 1.0.19 |
|
| 3277 | - */ |
|
| 3278 | - public function get_discount( $discount = false ) { |
|
| 3274 | + * Retrieves a specific discount. |
|
| 3275 | + * |
|
| 3276 | + * @since 1.0.19 |
|
| 3277 | + */ |
|
| 3278 | + public function get_discount( $discount = false ) { |
|
| 3279 | 3279 | |
| 3280 | - // Backwards compatibilty. |
|
| 3281 | - if ( empty( $discount ) ) { |
|
| 3282 | - return $this->get_total_discount(); |
|
| 3283 | - } |
|
| 3280 | + // Backwards compatibilty. |
|
| 3281 | + if ( empty( $discount ) ) { |
|
| 3282 | + return $this->get_total_discount(); |
|
| 3283 | + } |
|
| 3284 | 3284 | |
| 3285 | 3285 | $discounts = $this->get_discounts(); |
| 3286 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3286 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3287 | 3287 | } |
| 3288 | 3288 | |
| 3289 | 3289 | /** |
| 3290 | - * Removes a specific discount. |
|
| 3291 | - * |
|
| 3292 | - * @since 1.0.19 |
|
| 3293 | - */ |
|
| 3294 | - public function remove_discount( $discount ) { |
|
| 3290 | + * Removes a specific discount. |
|
| 3291 | + * |
|
| 3292 | + * @since 1.0.19 |
|
| 3293 | + */ |
|
| 3294 | + public function remove_discount( $discount ) { |
|
| 3295 | 3295 | $discounts = $this->get_discounts(); |
| 3296 | 3296 | if ( isset( $discounts[ $discount ] ) ) { |
| 3297 | 3297 | unset( $discounts[ $discount ] ); |
@@ -3317,44 +3317,44 @@ discard block |
||
| 3317 | 3317 | if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) { |
| 3318 | 3318 | |
| 3319 | 3319 | $amount = $taxes[ $tax ]['amount'] += $amount; |
| 3320 | - $taxes[ $tax ] = array( |
|
| 3320 | + $taxes[ $tax ] = array( |
|
| 3321 | 3321 | 'amount' => $amount, |
| 3322 | 3322 | 'recurring' => (bool) $recurring, |
| 3323 | 3323 | ); |
| 3324 | 3324 | |
| 3325 | - } else { |
|
| 3326 | - $taxes[ $tax ] = array( |
|
| 3325 | + } else { |
|
| 3326 | + $taxes[ $tax ] = array( |
|
| 3327 | 3327 | 'amount' => $amount, |
| 3328 | 3328 | 'recurring' => (bool) $recurring, |
| 3329 | 3329 | ); |
| 3330 | - } |
|
| 3330 | + } |
|
| 3331 | 3331 | |
| 3332 | 3332 | $this->set_prop( 'taxes', $tax ); |
| 3333 | 3333 | |
| 3334 | 3334 | } |
| 3335 | 3335 | |
| 3336 | 3336 | /** |
| 3337 | - * Retrieves a specific tax. |
|
| 3338 | - * |
|
| 3339 | - * @since 1.0.19 |
|
| 3340 | - */ |
|
| 3341 | - public function get_tax( $tax = null ) { |
|
| 3337 | + * Retrieves a specific tax. |
|
| 3338 | + * |
|
| 3339 | + * @since 1.0.19 |
|
| 3340 | + */ |
|
| 3341 | + public function get_tax( $tax = null ) { |
|
| 3342 | 3342 | |
| 3343 | - // Backwards compatility. |
|
| 3344 | - if ( empty( $tax ) ) { |
|
| 3345 | - return $this->get_total_tax(); |
|
| 3346 | - } |
|
| 3343 | + // Backwards compatility. |
|
| 3344 | + if ( empty( $tax ) ) { |
|
| 3345 | + return $this->get_total_tax(); |
|
| 3346 | + } |
|
| 3347 | 3347 | |
| 3348 | 3348 | $taxes = $this->get_taxes(); |
| 3349 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3349 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3350 | 3350 | } |
| 3351 | 3351 | |
| 3352 | 3352 | /** |
| 3353 | - * Removes a specific tax. |
|
| 3354 | - * |
|
| 3355 | - * @since 1.0.19 |
|
| 3356 | - */ |
|
| 3357 | - public function remove_tax( $tax ) { |
|
| 3353 | + * Removes a specific tax. |
|
| 3354 | + * |
|
| 3355 | + * @since 1.0.19 |
|
| 3356 | + */ |
|
| 3357 | + public function remove_tax( $tax ) { |
|
| 3358 | 3358 | $taxes = $this->get_discounts(); |
| 3359 | 3359 | if ( isset( $taxes[ $tax ] ) ) { |
| 3360 | 3360 | unset( $taxes[ $tax ] ); |
@@ -3363,160 +3363,160 @@ discard block |
||
| 3363 | 3363 | } |
| 3364 | 3364 | |
| 3365 | 3365 | /** |
| 3366 | - * Recalculates the invoice subtotal. |
|
| 3367 | - * |
|
| 3368 | - * @since 1.0.19 |
|
| 3369 | - * @return float The recalculated subtotal |
|
| 3370 | - */ |
|
| 3371 | - public function recalculate_subtotal() { |
|
| 3366 | + * Recalculates the invoice subtotal. |
|
| 3367 | + * |
|
| 3368 | + * @since 1.0.19 |
|
| 3369 | + * @return float The recalculated subtotal |
|
| 3370 | + */ |
|
| 3371 | + public function recalculate_subtotal() { |
|
| 3372 | 3372 | $items = $this->get_items(); |
| 3373 | - $subtotal = 0; |
|
| 3374 | - $recurring = 0; |
|
| 3373 | + $subtotal = 0; |
|
| 3374 | + $recurring = 0; |
|
| 3375 | 3375 | |
| 3376 | 3376 | foreach ( $items as $item ) { |
| 3377 | - $subtotal += $item->get_sub_total(); |
|
| 3378 | - $recurring += $item->get_recurring_sub_total(); |
|
| 3377 | + $subtotal += $item->get_sub_total(); |
|
| 3378 | + $recurring += $item->get_recurring_sub_total(); |
|
| 3379 | 3379 | } |
| 3380 | 3380 | |
| 3381 | - if ( $this->is_renewal() ) { |
|
| 3382 | - $this->set_subtotal( $recurring ); |
|
| 3383 | - } else { |
|
| 3384 | - $this->set_subtotal( $subtotal ); |
|
| 3385 | - } |
|
| 3381 | + if ( $this->is_renewal() ) { |
|
| 3382 | + $this->set_subtotal( $recurring ); |
|
| 3383 | + } else { |
|
| 3384 | + $this->set_subtotal( $subtotal ); |
|
| 3385 | + } |
|
| 3386 | 3386 | |
| 3387 | - $this->totals['subtotal'] = array( |
|
| 3388 | - 'initial' => $subtotal, |
|
| 3389 | - 'recurring' => $recurring, |
|
| 3390 | - ); |
|
| 3387 | + $this->totals['subtotal'] = array( |
|
| 3388 | + 'initial' => $subtotal, |
|
| 3389 | + 'recurring' => $recurring, |
|
| 3390 | + ); |
|
| 3391 | 3391 | |
| 3392 | 3392 | return $this->is_renewal() ? $recurring : $subtotal; |
| 3393 | 3393 | } |
| 3394 | 3394 | |
| 3395 | 3395 | /** |
| 3396 | - * Recalculates the invoice discount total. |
|
| 3397 | - * |
|
| 3398 | - * @since 1.0.19 |
|
| 3399 | - * @return float The recalculated discount |
|
| 3400 | - */ |
|
| 3401 | - public function recalculate_total_discount() { |
|
| 3396 | + * Recalculates the invoice discount total. |
|
| 3397 | + * |
|
| 3398 | + * @since 1.0.19 |
|
| 3399 | + * @return float The recalculated discount |
|
| 3400 | + */ |
|
| 3401 | + public function recalculate_total_discount() { |
|
| 3402 | 3402 | $discounts = $this->get_discounts(); |
| 3403 | - $discount = 0; |
|
| 3404 | - $recurring = 0; |
|
| 3403 | + $discount = 0; |
|
| 3404 | + $recurring = 0; |
|
| 3405 | 3405 | |
| 3406 | 3406 | foreach ( $discounts as $data ) { |
| 3407 | 3407 | |
| 3408 | - if ( $data['recurring'] ) { |
|
| 3409 | - $recurring += $data['amount']; |
|
| 3410 | - } else { |
|
| 3411 | - $discount += $data['amount']; |
|
| 3412 | - } |
|
| 3408 | + if ( $data['recurring'] ) { |
|
| 3409 | + $recurring += $data['amount']; |
|
| 3410 | + } else { |
|
| 3411 | + $discount += $data['amount']; |
|
| 3412 | + } |
|
| 3413 | 3413 | |
| 3414 | - } |
|
| 3414 | + } |
|
| 3415 | 3415 | |
| 3416 | - if ( $this->is_renewal() ) { |
|
| 3417 | - $this->set_total_discount( $recurring ); |
|
| 3418 | - } else { |
|
| 3419 | - $this->set_total_discount( $discount ); |
|
| 3420 | - } |
|
| 3416 | + if ( $this->is_renewal() ) { |
|
| 3417 | + $this->set_total_discount( $recurring ); |
|
| 3418 | + } else { |
|
| 3419 | + $this->set_total_discount( $discount ); |
|
| 3420 | + } |
|
| 3421 | 3421 | |
| 3422 | - $this->totals['discount'] = array( |
|
| 3423 | - 'initial' => $discount, |
|
| 3424 | - 'recurring' => $recurring, |
|
| 3425 | - ); |
|
| 3422 | + $this->totals['discount'] = array( |
|
| 3423 | + 'initial' => $discount, |
|
| 3424 | + 'recurring' => $recurring, |
|
| 3425 | + ); |
|
| 3426 | 3426 | |
| 3427 | - return $this->is_renewal() ? $recurring : $discount; |
|
| 3427 | + return $this->is_renewal() ? $recurring : $discount; |
|
| 3428 | 3428 | |
| 3429 | 3429 | } |
| 3430 | 3430 | |
| 3431 | 3431 | /** |
| 3432 | - * Recalculates the invoice tax total. |
|
| 3433 | - * |
|
| 3434 | - * @since 1.0.19 |
|
| 3435 | - * @return float The recalculated tax |
|
| 3436 | - */ |
|
| 3437 | - public function recalculate_total_tax() { |
|
| 3432 | + * Recalculates the invoice tax total. |
|
| 3433 | + * |
|
| 3434 | + * @since 1.0.19 |
|
| 3435 | + * @return float The recalculated tax |
|
| 3436 | + */ |
|
| 3437 | + public function recalculate_total_tax() { |
|
| 3438 | 3438 | $taxes = $this->get_taxes(); |
| 3439 | - $tax = 0; |
|
| 3440 | - $recurring = 0; |
|
| 3439 | + $tax = 0; |
|
| 3440 | + $recurring = 0; |
|
| 3441 | 3441 | |
| 3442 | 3442 | foreach ( $taxes as $data ) { |
| 3443 | 3443 | |
| 3444 | - if ( $data['recurring'] ) { |
|
| 3445 | - $recurring += $data['amount']; |
|
| 3446 | - } else { |
|
| 3447 | - $tax += $data['amount']; |
|
| 3448 | - } |
|
| 3444 | + if ( $data['recurring'] ) { |
|
| 3445 | + $recurring += $data['amount']; |
|
| 3446 | + } else { |
|
| 3447 | + $tax += $data['amount']; |
|
| 3448 | + } |
|
| 3449 | 3449 | |
| 3450 | - } |
|
| 3450 | + } |
|
| 3451 | 3451 | |
| 3452 | - if ( $this->is_renewal() ) { |
|
| 3453 | - $this->set_total_tax( $recurring ); |
|
| 3454 | - } else { |
|
| 3455 | - $this->set_total_tax( $tax ); |
|
| 3456 | - } |
|
| 3452 | + if ( $this->is_renewal() ) { |
|
| 3453 | + $this->set_total_tax( $recurring ); |
|
| 3454 | + } else { |
|
| 3455 | + $this->set_total_tax( $tax ); |
|
| 3456 | + } |
|
| 3457 | 3457 | |
| 3458 | - $this->totals['tax'] = array( |
|
| 3459 | - 'initial' => $tax, |
|
| 3460 | - 'recurring' => $recurring, |
|
| 3461 | - ); |
|
| 3458 | + $this->totals['tax'] = array( |
|
| 3459 | + 'initial' => $tax, |
|
| 3460 | + 'recurring' => $recurring, |
|
| 3461 | + ); |
|
| 3462 | 3462 | |
| 3463 | - return $this->is_renewal() ? $recurring : $tax; |
|
| 3463 | + return $this->is_renewal() ? $recurring : $tax; |
|
| 3464 | 3464 | |
| 3465 | 3465 | } |
| 3466 | 3466 | |
| 3467 | 3467 | /** |
| 3468 | - * Recalculates the invoice fees total. |
|
| 3469 | - * |
|
| 3470 | - * @since 1.0.19 |
|
| 3471 | - * @return float The recalculated fee |
|
| 3472 | - */ |
|
| 3473 | - public function recalculate_total_fees() { |
|
| 3474 | - $fees = $this->get_fees(); |
|
| 3475 | - $fee = 0; |
|
| 3476 | - $recurring = 0; |
|
| 3468 | + * Recalculates the invoice fees total. |
|
| 3469 | + * |
|
| 3470 | + * @since 1.0.19 |
|
| 3471 | + * @return float The recalculated fee |
|
| 3472 | + */ |
|
| 3473 | + public function recalculate_total_fees() { |
|
| 3474 | + $fees = $this->get_fees(); |
|
| 3475 | + $fee = 0; |
|
| 3476 | + $recurring = 0; |
|
| 3477 | 3477 | |
| 3478 | 3478 | foreach ( $fees as $data ) { |
| 3479 | 3479 | |
| 3480 | - if ( $data['recurring'] ) { |
|
| 3481 | - $recurring += $data['amount']; |
|
| 3482 | - } else { |
|
| 3483 | - $fee += $data['amount']; |
|
| 3484 | - } |
|
| 3480 | + if ( $data['recurring'] ) { |
|
| 3481 | + $recurring += $data['amount']; |
|
| 3482 | + } else { |
|
| 3483 | + $fee += $data['amount']; |
|
| 3484 | + } |
|
| 3485 | 3485 | |
| 3486 | - } |
|
| 3486 | + } |
|
| 3487 | 3487 | |
| 3488 | 3488 | if ( $this->is_renewal() ) { |
| 3489 | - $this->set_total_fees( $recurring ); |
|
| 3490 | - } else { |
|
| 3491 | - $this->set_total_fees( $fee ); |
|
| 3492 | - } |
|
| 3489 | + $this->set_total_fees( $recurring ); |
|
| 3490 | + } else { |
|
| 3491 | + $this->set_total_fees( $fee ); |
|
| 3492 | + } |
|
| 3493 | 3493 | |
| 3494 | - $this->totals['fee'] = array( |
|
| 3495 | - 'initial' => $fee, |
|
| 3496 | - 'recurring' => $recurring, |
|
| 3497 | - ); |
|
| 3494 | + $this->totals['fee'] = array( |
|
| 3495 | + 'initial' => $fee, |
|
| 3496 | + 'recurring' => $recurring, |
|
| 3497 | + ); |
|
| 3498 | 3498 | |
| 3499 | 3499 | $this->set_total_fees( $fee ); |
| 3500 | 3500 | return $this->is_renewal() ? $recurring : $fee; |
| 3501 | 3501 | } |
| 3502 | 3502 | |
| 3503 | 3503 | /** |
| 3504 | - * Recalculates the invoice total. |
|
| 3505 | - * |
|
| 3506 | - * @since 1.0.19 |
|
| 3504 | + * Recalculates the invoice total. |
|
| 3505 | + * |
|
| 3506 | + * @since 1.0.19 |
|
| 3507 | 3507 | * @return float The invoice total |
| 3508 | - */ |
|
| 3509 | - public function recalculate_total() { |
|
| 3508 | + */ |
|
| 3509 | + public function recalculate_total() { |
|
| 3510 | 3510 | $this->recalculate_subtotal(); |
| 3511 | 3511 | $this->recalculate_total_fees(); |
| 3512 | 3512 | $this->recalculate_total_discount(); |
| 3513 | 3513 | $this->recalculate_total_tax(); |
| 3514 | - return $this->get_total(); |
|
| 3515 | - } |
|
| 3514 | + return $this->get_total(); |
|
| 3515 | + } |
|
| 3516 | 3516 | |
| 3517 | - /** |
|
| 3518 | - * @deprecated |
|
| 3519 | - */ |
|
| 3517 | + /** |
|
| 3518 | + * @deprecated |
|
| 3519 | + */ |
|
| 3520 | 3520 | public function recalculate_totals( $temp = false ) { |
| 3521 | 3521 | $this->update_items( $temp ); |
| 3522 | 3522 | $this->save( true ); |
@@ -3534,7 +3534,7 @@ discard block |
||
| 3534 | 3534 | * Adds a note to an invoice. |
| 3535 | 3535 | * |
| 3536 | 3536 | * @param string $note The note being added. |
| 3537 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3537 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3538 | 3538 | * |
| 3539 | 3539 | */ |
| 3540 | 3540 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3544,23 +3544,23 @@ discard block |
||
| 3544 | 3544 | return false; |
| 3545 | 3545 | } |
| 3546 | 3546 | |
| 3547 | - // If this is an admin comment or it has been added by the user. |
|
| 3548 | - if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) { |
|
| 3549 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3547 | + // If this is an admin comment or it has been added by the user. |
|
| 3548 | + if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) { |
|
| 3549 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3550 | 3550 | $author = $user->display_name; |
| 3551 | 3551 | $author_email = $user->user_email; |
| 3552 | - } |
|
| 3552 | + } |
|
| 3553 | 3553 | |
| 3554 | - if ( $system ) { |
|
| 3555 | - $author = 'System'; |
|
| 3554 | + if ( $system ) { |
|
| 3555 | + $author = 'System'; |
|
| 3556 | 3556 | $author_email = '[email protected]'; |
| 3557 | - } |
|
| 3557 | + } |
|
| 3558 | 3558 | |
| 3559 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3559 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3560 | 3560 | |
| 3561 | - } |
|
| 3561 | + } |
|
| 3562 | 3562 | |
| 3563 | - /** |
|
| 3563 | + /** |
|
| 3564 | 3564 | * Generates a unique key for the invoice. |
| 3565 | 3565 | */ |
| 3566 | 3566 | public function generate_key( $string = '' ) { |
@@ -3580,106 +3580,106 @@ discard block |
||
| 3580 | 3580 | $number = wpinv_get_next_invoice_number( $this->post_type ); |
| 3581 | 3581 | } |
| 3582 | 3582 | |
| 3583 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
| 3583 | + $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
| 3584 | 3584 | |
| 3585 | - return $number; |
|
| 3586 | - } |
|
| 3585 | + return $number; |
|
| 3586 | + } |
|
| 3587 | 3587 | |
| 3588 | - /** |
|
| 3589 | - * Handle the status transition. |
|
| 3590 | - */ |
|
| 3591 | - protected function status_transition() { |
|
| 3592 | - $status_transition = $this->status_transition; |
|
| 3588 | + /** |
|
| 3589 | + * Handle the status transition. |
|
| 3590 | + */ |
|
| 3591 | + protected function status_transition() { |
|
| 3592 | + $status_transition = $this->status_transition; |
|
| 3593 | 3593 | |
| 3594 | - // Reset status transition variable. |
|
| 3595 | - $this->status_transition = false; |
|
| 3594 | + // Reset status transition variable. |
|
| 3595 | + $this->status_transition = false; |
|
| 3596 | 3596 | |
| 3597 | - if ( $status_transition ) { |
|
| 3598 | - try { |
|
| 3597 | + if ( $status_transition ) { |
|
| 3598 | + try { |
|
| 3599 | 3599 | |
| 3600 | - // Fire a hook for the status change. |
|
| 3601 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 3600 | + // Fire a hook for the status change. |
|
| 3601 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 3602 | 3602 | |
| 3603 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3604 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3603 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3604 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3605 | 3605 | |
| 3606 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 3606 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 3607 | 3607 | |
| 3608 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3609 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
| 3608 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3609 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
| 3610 | 3610 | |
| 3611 | - // Fire another hook. |
|
| 3612 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 3613 | - do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
| 3611 | + // Fire another hook. |
|
| 3612 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 3613 | + do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
| 3614 | 3614 | |
| 3615 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3616 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3615 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3616 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3617 | 3617 | |
| 3618 | - // Note the transition occurred. |
|
| 3619 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3618 | + // Note the transition occurred. |
|
| 3619 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3620 | 3620 | |
| 3621 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3622 | - if ( |
|
| 3623 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true ) |
|
| 3624 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3625 | - ) { |
|
| 3626 | - do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition ); |
|
| 3627 | - } |
|
| 3628 | - } else { |
|
| 3629 | - /* translators: %s: new invoice status */ |
|
| 3630 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
| 3621 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3622 | + if ( |
|
| 3623 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true ) |
|
| 3624 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3625 | + ) { |
|
| 3626 | + do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition ); |
|
| 3627 | + } |
|
| 3628 | + } else { |
|
| 3629 | + /* translators: %s: new invoice status */ |
|
| 3630 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
| 3631 | 3631 | |
| 3632 | - // Note the transition occurred. |
|
| 3633 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3632 | + // Note the transition occurred. |
|
| 3633 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3634 | 3634 | |
| 3635 | - } |
|
| 3636 | - } catch ( Exception $e ) { |
|
| 3637 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3638 | - } |
|
| 3639 | - } |
|
| 3640 | - } |
|
| 3635 | + } |
|
| 3636 | + } catch ( Exception $e ) { |
|
| 3637 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3638 | + } |
|
| 3639 | + } |
|
| 3640 | + } |
|
| 3641 | 3641 | |
| 3642 | - /** |
|
| 3643 | - * Updates an invoice status. |
|
| 3644 | - */ |
|
| 3645 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3642 | + /** |
|
| 3643 | + * Updates an invoice status. |
|
| 3644 | + */ |
|
| 3645 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3646 | 3646 | |
| 3647 | - // Fires before updating a status. |
|
| 3648 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3647 | + // Fires before updating a status. |
|
| 3648 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3649 | 3649 | |
| 3650 | - // Update the status. |
|
| 3651 | - $this->set_status( $new_status, $note, $manual ); |
|
| 3650 | + // Update the status. |
|
| 3651 | + $this->set_status( $new_status, $note, $manual ); |
|
| 3652 | 3652 | |
| 3653 | - // Save the order. |
|
| 3654 | - return $this->save(); |
|
| 3653 | + // Save the order. |
|
| 3654 | + return $this->save(); |
|
| 3655 | 3655 | |
| 3656 | - } |
|
| 3656 | + } |
|
| 3657 | 3657 | |
| 3658 | - /** |
|
| 3659 | - * @deprecated |
|
| 3660 | - */ |
|
| 3661 | - public function refresh_item_ids() { |
|
| 3658 | + /** |
|
| 3659 | + * @deprecated |
|
| 3660 | + */ |
|
| 3661 | + public function refresh_item_ids() { |
|
| 3662 | 3662 | $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) ); |
| 3663 | 3663 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
| 3664 | - } |
|
| 3664 | + } |
|
| 3665 | 3665 | |
| 3666 | - /** |
|
| 3667 | - * @deprecated |
|
| 3668 | - */ |
|
| 3669 | - public function update_items( $temp = false ) { |
|
| 3666 | + /** |
|
| 3667 | + * @deprecated |
|
| 3668 | + */ |
|
| 3669 | + public function update_items( $temp = false ) { |
|
| 3670 | 3670 | |
| 3671 | - $this->set_items( $this->get_items() ); |
|
| 3671 | + $this->set_items( $this->get_items() ); |
|
| 3672 | 3672 | |
| 3673 | - if ( ! $temp ) { |
|
| 3674 | - $this->save(); |
|
| 3675 | - } |
|
| 3673 | + if ( ! $temp ) { |
|
| 3674 | + $this->save(); |
|
| 3675 | + } |
|
| 3676 | 3676 | |
| 3677 | 3677 | return $this; |
| 3678 | - } |
|
| 3678 | + } |
|
| 3679 | 3679 | |
| 3680 | - /** |
|
| 3681 | - * @deprecated |
|
| 3682 | - */ |
|
| 3680 | + /** |
|
| 3681 | + * @deprecated |
|
| 3682 | + */ |
|
| 3683 | 3683 | public function validate_discount() { |
| 3684 | 3684 | |
| 3685 | 3685 | $discount_code = $this->get_discount_code(); |
@@ -3695,86 +3695,86 @@ discard block |
||
| 3695 | 3695 | |
| 3696 | 3696 | } |
| 3697 | 3697 | |
| 3698 | - /** |
|
| 3699 | - * Refunds an invoice. |
|
| 3700 | - */ |
|
| 3698 | + /** |
|
| 3699 | + * Refunds an invoice. |
|
| 3700 | + */ |
|
| 3701 | 3701 | public function refund() { |
| 3702 | - $this->set_status( 'wpi-refunded' ); |
|
| 3702 | + $this->set_status( 'wpi-refunded' ); |
|
| 3703 | 3703 | $this->save(); |
| 3704 | - } |
|
| 3704 | + } |
|
| 3705 | 3705 | |
| 3706 | - /** |
|
| 3707 | - * Marks an invoice as paid. |
|
| 3708 | - * |
|
| 3709 | - * @param string $transaction_id |
|
| 3710 | - */ |
|
| 3706 | + /** |
|
| 3707 | + * Marks an invoice as paid. |
|
| 3708 | + * |
|
| 3709 | + * @param string $transaction_id |
|
| 3710 | + */ |
|
| 3711 | 3711 | public function mark_paid( $transaction_id = null, $note = '' ) { |
| 3712 | 3712 | |
| 3713 | - // Set the transaction id. |
|
| 3714 | - if ( empty( $transaction_id ) ) { |
|
| 3715 | - $transaction_id = $this->generate_key('trans_'); |
|
| 3716 | - } |
|
| 3713 | + // Set the transaction id. |
|
| 3714 | + if ( empty( $transaction_id ) ) { |
|
| 3715 | + $transaction_id = $this->generate_key('trans_'); |
|
| 3716 | + } |
|
| 3717 | 3717 | |
| 3718 | - if ( ! $this->get_transaction_id() ) { |
|
| 3719 | - $this->set_transaction_id( $transaction_id ); |
|
| 3720 | - } |
|
| 3718 | + if ( ! $this->get_transaction_id() ) { |
|
| 3719 | + $this->set_transaction_id( $transaction_id ); |
|
| 3720 | + } |
|
| 3721 | 3721 | |
| 3722 | - if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3723 | - return $this->save(); |
|
| 3724 | - } |
|
| 3722 | + if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3723 | + return $this->save(); |
|
| 3724 | + } |
|
| 3725 | 3725 | |
| 3726 | - // Set the completed date. |
|
| 3727 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3726 | + // Set the completed date. |
|
| 3727 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3728 | 3728 | |
| 3729 | - // Set the new status. |
|
| 3730 | - if ( $this->is_renewal() ) { |
|
| 3729 | + // Set the new status. |
|
| 3730 | + if ( $this->is_renewal() ) { |
|
| 3731 | 3731 | |
| 3732 | - $_note = sprintf( |
|
| 3733 | - __( 'Renewed via %s', 'invoicing' ), |
|
| 3734 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3735 | - ); |
|
| 3732 | + $_note = sprintf( |
|
| 3733 | + __( 'Renewed via %s', 'invoicing' ), |
|
| 3734 | + $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3735 | + ); |
|
| 3736 | 3736 | |
| 3737 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3738 | - $_note = $note; |
|
| 3739 | - } |
|
| 3737 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3738 | + $_note = $note; |
|
| 3739 | + } |
|
| 3740 | 3740 | |
| 3741 | - $this->set_status( 'wpi-renewal', $_note ); |
|
| 3741 | + $this->set_status( 'wpi-renewal', $_note ); |
|
| 3742 | 3742 | |
| 3743 | - } else { |
|
| 3743 | + } else { |
|
| 3744 | 3744 | |
| 3745 | - $_note = sprintf( |
|
| 3746 | - __( 'Paid via %s', 'invoicing' ), |
|
| 3747 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3748 | - ); |
|
| 3745 | + $_note = sprintf( |
|
| 3746 | + __( 'Paid via %s', 'invoicing' ), |
|
| 3747 | + $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3748 | + ); |
|
| 3749 | 3749 | |
| 3750 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3751 | - $_note = $note; |
|
| 3752 | - } |
|
| 3750 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3751 | + $_note = $note; |
|
| 3752 | + } |
|
| 3753 | 3753 | |
| 3754 | - $this->set_status( 'publish',$_note ); |
|
| 3754 | + $this->set_status( 'publish',$_note ); |
|
| 3755 | 3755 | |
| 3756 | - } |
|
| 3756 | + } |
|
| 3757 | 3757 | |
| 3758 | - // Set checkout mode. |
|
| 3759 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 3760 | - $this->set_mode( $mode ); |
|
| 3758 | + // Set checkout mode. |
|
| 3759 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 3760 | + $this->set_mode( $mode ); |
|
| 3761 | 3761 | |
| 3762 | - // Save the invoice. |
|
| 3762 | + // Save the invoice. |
|
| 3763 | 3763 | $this->save(); |
| 3764 | - } |
|
| 3765 | - |
|
| 3766 | - |
|
| 3767 | - /** |
|
| 3768 | - * Save data to the database. |
|
| 3769 | - * |
|
| 3770 | - * @since 1.0.19 |
|
| 3771 | - * @return int invoice ID |
|
| 3772 | - */ |
|
| 3773 | - public function save() { |
|
| 3774 | - $this->maybe_set_date_paid(); |
|
| 3775 | - parent::save(); |
|
| 3776 | - $this->status_transition(); |
|
| 3777 | - return $this->get_id(); |
|
| 3778 | - } |
|
| 3764 | + } |
|
| 3765 | + |
|
| 3766 | + |
|
| 3767 | + /** |
|
| 3768 | + * Save data to the database. |
|
| 3769 | + * |
|
| 3770 | + * @since 1.0.19 |
|
| 3771 | + * @return int invoice ID |
|
| 3772 | + */ |
|
| 3773 | + public function save() { |
|
| 3774 | + $this->maybe_set_date_paid(); |
|
| 3775 | + parent::save(); |
|
| 3776 | + $this->status_transition(); |
|
| 3777 | + return $this->get_id(); |
|
| 3778 | + } |
|
| 3779 | 3779 | |
| 3780 | 3780 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Invoice class. |
@@ -133,40 +133,40 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
| 135 | 135 | */ |
| 136 | - public function __construct( $invoice = false ) { |
|
| 136 | + public function __construct($invoice = false) { |
|
| 137 | 137 | |
| 138 | - parent::__construct( $invoice ); |
|
| 138 | + parent::__construct($invoice); |
|
| 139 | 139 | |
| 140 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
| 141 | - $this->set_id( $invoice ); |
|
| 142 | - } elseif ( $invoice instanceof self ) { |
|
| 143 | - $this->set_id( $invoice->get_id() ); |
|
| 144 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
| 145 | - $this->set_id( $invoice->ID ); |
|
| 146 | - } elseif ( is_array( $invoice ) ) { |
|
| 147 | - $this->set_props( $invoice ); |
|
| 140 | + if (!empty($invoice) && is_numeric($invoice) && getpaid_is_invoice_post_type(get_post_type($invoice))) { |
|
| 141 | + $this->set_id($invoice); |
|
| 142 | + } elseif ($invoice instanceof self) { |
|
| 143 | + $this->set_id($invoice->get_id()); |
|
| 144 | + } elseif (!empty($invoice->ID)) { |
|
| 145 | + $this->set_id($invoice->ID); |
|
| 146 | + } elseif (is_array($invoice)) { |
|
| 147 | + $this->set_props($invoice); |
|
| 148 | 148 | |
| 149 | - if ( isset( $invoice['ID'] ) ) { |
|
| 150 | - $this->set_id( $invoice['ID'] ); |
|
| 149 | + if (isset($invoice['ID'])) { |
|
| 150 | + $this->set_id($invoice['ID']); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 154 | - $this->set_id( $invoice_id ); |
|
| 155 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 156 | - $this->set_id( $invoice_id ); |
|
| 157 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 158 | - $this->set_id( $invoice_id ); |
|
| 159 | - }else { |
|
| 160 | - $this->set_object_read( true ); |
|
| 153 | + } elseif (is_scalar($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'key')) { |
|
| 154 | + $this->set_id($invoice_id); |
|
| 155 | + } elseif (is_scalar($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'number')) { |
|
| 156 | + $this->set_id($invoice_id); |
|
| 157 | + } elseif (is_scalar($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'transaction_id')) { |
|
| 158 | + $this->set_id($invoice_id); |
|
| 159 | + } else { |
|
| 160 | + $this->set_object_read(true); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Load the datastore. |
| 164 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 164 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 165 | 165 | |
| 166 | - if ( $this->get_id() > 0 ) { |
|
| 167 | - $this->post = get_post( $this->get_id() ); |
|
| 166 | + if ($this->get_id() > 0) { |
|
| 167 | + $this->post = get_post($this->get_id()); |
|
| 168 | 168 | $this->ID = $this->get_id(); |
| 169 | - $this->data_store->read( $this ); |
|
| 169 | + $this->data_store->read($this); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | } |
@@ -181,38 +181,38 @@ discard block |
||
| 181 | 181 | * @since 1.0.15 |
| 182 | 182 | * @return int |
| 183 | 183 | */ |
| 184 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 184 | + public static function get_invoice_id_by_field($value, $field = 'key') { |
|
| 185 | 185 | global $wpdb; |
| 186 | 186 | |
| 187 | 187 | // Trim the value. |
| 188 | - $value = trim( $value ); |
|
| 188 | + $value = trim($value); |
|
| 189 | 189 | |
| 190 | - if ( empty( $value ) ) { |
|
| 190 | + if (empty($value)) { |
|
| 191 | 191 | return 0; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // Valid fields. |
| 195 | - $fields = array( 'key', 'number', 'transaction_id' ); |
|
| 195 | + $fields = array('key', 'number', 'transaction_id'); |
|
| 196 | 196 | |
| 197 | 197 | // Ensure a field has been passed. |
| 198 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 198 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 199 | 199 | return 0; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // Maybe retrieve from the cache. |
| 203 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 204 | - if ( false !== $invoice_id ) { |
|
| 203 | + $invoice_id = wp_cache_get($value, "getpaid_invoice_{$field}s_to_invoice_ids"); |
|
| 204 | + if (false !== $invoice_id) { |
|
| 205 | 205 | return $invoice_id; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // Fetch from the db. |
| 209 | 209 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 210 | 210 | $invoice_id = (int) $wpdb->get_var( |
| 211 | - $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
| 211 | + $wpdb->prepare("SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
| 212 | 212 | ); |
| 213 | 213 | |
| 214 | 214 | // Update the cache with our data |
| 215 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 215 | + wp_cache_set($value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids"); |
|
| 216 | 216 | |
| 217 | 217 | return $invoice_id; |
| 218 | 218 | } |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | /** |
| 221 | 221 | * Checks if an invoice key is set. |
| 222 | 222 | */ |
| 223 | - public function _isset( $key ) { |
|
| 224 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
|
| 223 | + public function _isset($key) { |
|
| 224 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /* |
@@ -246,8 +246,8 @@ discard block |
||
| 246 | 246 | * @param string $context View or edit context. |
| 247 | 247 | * @return int |
| 248 | 248 | */ |
| 249 | - public function get_parent_id( $context = 'view' ) { |
|
| 250 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 249 | + public function get_parent_id($context = 'view') { |
|
| 250 | + return (int) $this->get_prop('parent_id', $context); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return WPInv_Invoice |
| 258 | 258 | */ |
| 259 | 259 | public function get_parent_payment() { |
| 260 | - return new WPInv_Invoice( $this->get_parent_id() ); |
|
| 260 | + return new WPInv_Invoice($this->get_parent_id()); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | * @param string $context View or edit context. |
| 278 | 278 | * @return string |
| 279 | 279 | */ |
| 280 | - public function get_status( $context = 'view' ) { |
|
| 281 | - return $this->get_prop( 'status', $context ); |
|
| 280 | + public function get_status($context = 'view') { |
|
| 281 | + return $this->get_prop('status', $context); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -289,10 +289,10 @@ discard block |
||
| 289 | 289 | */ |
| 290 | 290 | public function get_all_statuses() { |
| 291 | 291 | |
| 292 | - $statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
| 292 | + $statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
| 293 | 293 | |
| 294 | 294 | // For backwards compatibility. |
| 295 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
| 295 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
| 296 | 296 | $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
| 297 | 297 | } |
| 298 | 298 | |
@@ -308,9 +308,9 @@ discard block |
||
| 308 | 308 | public function get_status_nicename() { |
| 309 | 309 | $statuses = $this->get_all_statuses(); |
| 310 | 310 | |
| 311 | - $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
|
| 311 | + $status = isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : $this->get_status(); |
|
| 312 | 312 | |
| 313 | - return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
|
| 313 | + return apply_filters('wpinv_get_invoice_status_nicename', $status, $this); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,8 +321,8 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | public function get_status_label_html() { |
| 323 | 323 | |
| 324 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 325 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 324 | + $status_label = sanitize_text_field($this->get_status_nicename()); |
|
| 325 | + $status = sanitize_html_class($this->get_status()); |
|
| 326 | 326 | |
| 327 | 327 | return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>"; |
| 328 | 328 | } |
@@ -334,27 +334,27 @@ discard block |
||
| 334 | 334 | * @param string $context View or edit context. |
| 335 | 335 | * @return string |
| 336 | 336 | */ |
| 337 | - public function get_version( $context = 'view' ) { |
|
| 338 | - return $this->get_prop( 'version', $context ); |
|
| 337 | + public function get_version($context = 'view') { |
|
| 338 | + return $this->get_prop('version', $context); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
| 342 | 342 | * @deprecated |
| 343 | 343 | */ |
| 344 | - public function get_invoice_date( $formatted = true ) { |
|
| 344 | + public function get_invoice_date($formatted = true) { |
|
| 345 | 345 | $date_completed = $this->get_date_completed(); |
| 346 | 346 | $invoice_date = $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
| 347 | 347 | |
| 348 | - if ( $invoice_date == '' ) { |
|
| 348 | + if ($invoice_date == '') { |
|
| 349 | 349 | $date_created = $this->get_date_created(); |
| 350 | 350 | $invoice_date = $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - if ( $formatted && $invoice_date ) { |
|
| 354 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
| 353 | + if ($formatted && $invoice_date) { |
|
| 354 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->get_id(), $this ); |
|
| 357 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->get_id(), $this); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | * @param string $context View or edit context. |
| 365 | 365 | * @return string |
| 366 | 366 | */ |
| 367 | - public function get_date_created( $context = 'view' ) { |
|
| 368 | - return $this->get_prop( 'date_created', $context ); |
|
| 367 | + public function get_date_created($context = 'view') { |
|
| 368 | + return $this->get_prop('date_created', $context); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | * @param string $context View or edit context. |
| 376 | 376 | * @return string |
| 377 | 377 | */ |
| 378 | - public function get_created_date( $context = 'view' ) { |
|
| 379 | - return $this->get_date_created( $context ); |
|
| 378 | + public function get_created_date($context = 'view') { |
|
| 379 | + return $this->get_date_created($context); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -386,11 +386,11 @@ discard block |
||
| 386 | 386 | * @param string $context View or edit context. |
| 387 | 387 | * @return string |
| 388 | 388 | */ |
| 389 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 390 | - $date = $this->get_date_created( $context ); |
|
| 389 | + public function get_date_created_gmt($context = 'view') { |
|
| 390 | + $date = $this->get_date_created($context); |
|
| 391 | 391 | |
| 392 | - if ( $date ) { |
|
| 393 | - $date = get_gmt_from_date( $date ); |
|
| 392 | + if ($date) { |
|
| 393 | + $date = get_gmt_from_date($date); |
|
| 394 | 394 | } |
| 395 | 395 | return $date; |
| 396 | 396 | } |
@@ -402,8 +402,8 @@ discard block |
||
| 402 | 402 | * @param string $context View or edit context. |
| 403 | 403 | * @return string |
| 404 | 404 | */ |
| 405 | - public function get_date_modified( $context = 'view' ) { |
|
| 406 | - return $this->get_prop( 'date_modified', $context ); |
|
| 405 | + public function get_date_modified($context = 'view') { |
|
| 406 | + return $this->get_prop('date_modified', $context); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -413,8 +413,8 @@ discard block |
||
| 413 | 413 | * @param string $context View or edit context. |
| 414 | 414 | * @return string |
| 415 | 415 | */ |
| 416 | - public function get_modified_date( $context = 'view' ) { |
|
| 417 | - return $this->get_date_modified( $context ); |
|
| 416 | + public function get_modified_date($context = 'view') { |
|
| 417 | + return $this->get_date_modified($context); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -424,11 +424,11 @@ discard block |
||
| 424 | 424 | * @param string $context View or edit context. |
| 425 | 425 | * @return string |
| 426 | 426 | */ |
| 427 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 428 | - $date = $this->get_date_modified( $context ); |
|
| 427 | + public function get_date_modified_gmt($context = 'view') { |
|
| 428 | + $date = $this->get_date_modified($context); |
|
| 429 | 429 | |
| 430 | - if ( $date ) { |
|
| 431 | - $date = get_gmt_from_date( $date ); |
|
| 430 | + if ($date) { |
|
| 431 | + $date = get_gmt_from_date($date); |
|
| 432 | 432 | } |
| 433 | 433 | return $date; |
| 434 | 434 | } |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | * @param string $context View or edit context. |
| 441 | 441 | * @return string |
| 442 | 442 | */ |
| 443 | - public function get_due_date( $context = 'view' ) { |
|
| 444 | - return $this->get_prop( 'due_date', $context ); |
|
| 443 | + public function get_due_date($context = 'view') { |
|
| 444 | + return $this->get_prop('due_date', $context); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -451,8 +451,8 @@ discard block |
||
| 451 | 451 | * @param string $context View or edit context. |
| 452 | 452 | * @return string |
| 453 | 453 | */ |
| 454 | - public function get_date_due( $context = 'view' ) { |
|
| 455 | - return $this->get_due_date( $context ); |
|
| 454 | + public function get_date_due($context = 'view') { |
|
| 455 | + return $this->get_due_date($context); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
@@ -462,11 +462,11 @@ discard block |
||
| 462 | 462 | * @param string $context View or edit context. |
| 463 | 463 | * @return string |
| 464 | 464 | */ |
| 465 | - public function get_due_date_gmt( $context = 'view' ) { |
|
| 466 | - $date = $this->get_due_date( $context ); |
|
| 465 | + public function get_due_date_gmt($context = 'view') { |
|
| 466 | + $date = $this->get_due_date($context); |
|
| 467 | 467 | |
| 468 | - if ( $date ) { |
|
| 469 | - $date = get_gmt_from_date( $date ); |
|
| 468 | + if ($date) { |
|
| 469 | + $date = get_gmt_from_date($date); |
|
| 470 | 470 | } |
| 471 | 471 | return $date; |
| 472 | 472 | } |
@@ -478,8 +478,8 @@ discard block |
||
| 478 | 478 | * @param string $context View or edit context. |
| 479 | 479 | * @return string |
| 480 | 480 | */ |
| 481 | - public function get_gmt_date_due( $context = 'view' ) { |
|
| 482 | - return $this->get_due_date_gmt( $context ); |
|
| 481 | + public function get_gmt_date_due($context = 'view') { |
|
| 482 | + return $this->get_due_date_gmt($context); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -489,8 +489,8 @@ discard block |
||
| 489 | 489 | * @param string $context View or edit context. |
| 490 | 490 | * @return string |
| 491 | 491 | */ |
| 492 | - public function get_completed_date( $context = 'view' ) { |
|
| 493 | - return $this->get_prop( 'completed_date', $context ); |
|
| 492 | + public function get_completed_date($context = 'view') { |
|
| 493 | + return $this->get_prop('completed_date', $context); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
@@ -500,8 +500,8 @@ discard block |
||
| 500 | 500 | * @param string $context View or edit context. |
| 501 | 501 | * @return string |
| 502 | 502 | */ |
| 503 | - public function get_date_completed( $context = 'view' ) { |
|
| 504 | - return $this->get_completed_date( $context ); |
|
| 503 | + public function get_date_completed($context = 'view') { |
|
| 504 | + return $this->get_completed_date($context); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
@@ -511,11 +511,11 @@ discard block |
||
| 511 | 511 | * @param string $context View or edit context. |
| 512 | 512 | * @return string |
| 513 | 513 | */ |
| 514 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
| 515 | - $date = $this->get_completed_date( $context ); |
|
| 514 | + public function get_completed_date_gmt($context = 'view') { |
|
| 515 | + $date = $this->get_completed_date($context); |
|
| 516 | 516 | |
| 517 | - if ( $date ) { |
|
| 518 | - $date = get_gmt_from_date( $date ); |
|
| 517 | + if ($date) { |
|
| 518 | + $date = get_gmt_from_date($date); |
|
| 519 | 519 | } |
| 520 | 520 | return $date; |
| 521 | 521 | } |
@@ -527,8 +527,8 @@ discard block |
||
| 527 | 527 | * @param string $context View or edit context. |
| 528 | 528 | * @return string |
| 529 | 529 | */ |
| 530 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
| 531 | - return $this->get_completed_date_gmt( $context ); |
|
| 530 | + public function get_gmt_completed_date($context = 'view') { |
|
| 531 | + return $this->get_completed_date_gmt($context); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -538,12 +538,12 @@ discard block |
||
| 538 | 538 | * @param string $context View or edit context. |
| 539 | 539 | * @return string |
| 540 | 540 | */ |
| 541 | - public function get_number( $context = 'view' ) { |
|
| 542 | - $number = $this->get_prop( 'number', $context ); |
|
| 541 | + public function get_number($context = 'view') { |
|
| 542 | + $number = $this->get_prop('number', $context); |
|
| 543 | 543 | |
| 544 | - if ( empty( $number ) ) { |
|
| 544 | + if (empty($number)) { |
|
| 545 | 545 | $number = $this->generate_number(); |
| 546 | - $this->set_number( $number ); |
|
| 546 | + $this->set_number($number); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | return $number; |
@@ -556,12 +556,12 @@ discard block |
||
| 556 | 556 | * @param string $context View or edit context. |
| 557 | 557 | * @return string |
| 558 | 558 | */ |
| 559 | - public function get_key( $context = 'view' ) { |
|
| 560 | - $key = $this->get_prop( 'key', $context ); |
|
| 559 | + public function get_key($context = 'view') { |
|
| 560 | + $key = $this->get_prop('key', $context); |
|
| 561 | 561 | |
| 562 | - if ( empty( $key ) ) { |
|
| 563 | - $key = $this->generate_key( $this->get_type() . '_' ); |
|
| 564 | - $this->set_key( $key ); |
|
| 562 | + if (empty($key)) { |
|
| 563 | + $key = $this->generate_key($this->get_type() . '_'); |
|
| 564 | + $this->set_key($key); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | return $key; |
@@ -574,23 +574,23 @@ discard block |
||
| 574 | 574 | * @param string $context View or edit context. |
| 575 | 575 | * @return string |
| 576 | 576 | */ |
| 577 | - public function get_type( $context = 'view' ) { |
|
| 578 | - return $this->get_prop( 'type', $context ); |
|
| 577 | + public function get_type($context = 'view') { |
|
| 578 | + return $this->get_prop('type', $context); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /** |
| 582 | 582 | * @deprecated |
| 583 | 583 | */ |
| 584 | - public function get_invoice_quote_type( $post_id ) { |
|
| 585 | - if ( empty( $post_id ) ) { |
|
| 584 | + public function get_invoice_quote_type($post_id) { |
|
| 585 | + if (empty($post_id)) { |
|
| 586 | 586 | return ''; |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | - $type = get_post_type( $post_id ); |
|
| 589 | + $type = get_post_type($post_id); |
|
| 590 | 590 | |
| 591 | - if ( 'wpi_invoice' === $type ) { |
|
| 591 | + if ('wpi_invoice' === $type) { |
|
| 592 | 592 | $post_type = __('Invoice', 'invoicing'); |
| 593 | - } else{ |
|
| 593 | + } else { |
|
| 594 | 594 | $post_type = __('Quote', 'invoicing'); |
| 595 | 595 | } |
| 596 | 596 | |
@@ -604,8 +604,8 @@ discard block |
||
| 604 | 604 | * @param string $context View or edit context. |
| 605 | 605 | * @return string |
| 606 | 606 | */ |
| 607 | - public function get_post_type( $context = 'view' ) { |
|
| 608 | - return $this->get_prop( 'post_type', $context ); |
|
| 607 | + public function get_post_type($context = 'view') { |
|
| 608 | + return $this->get_prop('post_type', $context); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | /** |
@@ -615,8 +615,8 @@ discard block |
||
| 615 | 615 | * @param string $context View or edit context. |
| 616 | 616 | * @return string |
| 617 | 617 | */ |
| 618 | - public function get_mode( $context = 'view' ) { |
|
| 619 | - return $this->get_prop( 'mode', $context ); |
|
| 618 | + public function get_mode($context = 'view') { |
|
| 619 | + return $this->get_prop('mode', $context); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -626,12 +626,12 @@ discard block |
||
| 626 | 626 | * @param string $context View or edit context. |
| 627 | 627 | * @return string |
| 628 | 628 | */ |
| 629 | - public function get_path( $context = 'view' ) { |
|
| 630 | - $path = $this->get_prop( 'path', $context ); |
|
| 629 | + public function get_path($context = 'view') { |
|
| 630 | + $path = $this->get_prop('path', $context); |
|
| 631 | 631 | |
| 632 | - if ( empty( $path ) ) { |
|
| 633 | - $prefix = apply_filters( 'wpinv_post_name_prefix', 'inv-', $this->post_type ); |
|
| 634 | - $path = sanitize_title( $prefix . $this->get_id() ); |
|
| 632 | + if (empty($path)) { |
|
| 633 | + $prefix = apply_filters('wpinv_post_name_prefix', 'inv-', $this->post_type); |
|
| 634 | + $path = sanitize_title($prefix . $this->get_id()); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | return $path; |
@@ -644,8 +644,8 @@ discard block |
||
| 644 | 644 | * @param string $context View or edit context. |
| 645 | 645 | * @return string |
| 646 | 646 | */ |
| 647 | - public function get_name( $context = 'view' ) { |
|
| 648 | - return $this->get_prop( 'title', $context ); |
|
| 647 | + public function get_name($context = 'view') { |
|
| 648 | + return $this->get_prop('title', $context); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | /** |
@@ -655,8 +655,8 @@ discard block |
||
| 655 | 655 | * @param string $context View or edit context. |
| 656 | 656 | * @return string |
| 657 | 657 | */ |
| 658 | - public function get_title( $context = 'view' ) { |
|
| 659 | - return $this->get_name( $context ); |
|
| 658 | + public function get_title($context = 'view') { |
|
| 659 | + return $this->get_name($context); |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | /** |
@@ -666,8 +666,8 @@ discard block |
||
| 666 | 666 | * @param string $context View or edit context. |
| 667 | 667 | * @return string |
| 668 | 668 | */ |
| 669 | - public function get_description( $context = 'view' ) { |
|
| 670 | - return $this->get_prop( 'description', $context ); |
|
| 669 | + public function get_description($context = 'view') { |
|
| 670 | + return $this->get_prop('description', $context); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
@@ -677,8 +677,8 @@ discard block |
||
| 677 | 677 | * @param string $context View or edit context. |
| 678 | 678 | * @return string |
| 679 | 679 | */ |
| 680 | - public function get_excerpt( $context = 'view' ) { |
|
| 681 | - return $this->get_description( $context ); |
|
| 680 | + public function get_excerpt($context = 'view') { |
|
| 681 | + return $this->get_description($context); |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | /** |
@@ -688,8 +688,8 @@ discard block |
||
| 688 | 688 | * @param string $context View or edit context. |
| 689 | 689 | * @return string |
| 690 | 690 | */ |
| 691 | - public function get_summary( $context = 'view' ) { |
|
| 692 | - return $this->get_description( $context ); |
|
| 691 | + public function get_summary($context = 'view') { |
|
| 692 | + return $this->get_description($context); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -699,25 +699,25 @@ discard block |
||
| 699 | 699 | * @param string $context View or edit context. |
| 700 | 700 | * @return array |
| 701 | 701 | */ |
| 702 | - public function get_user_info( $context = 'view' ) { |
|
| 702 | + public function get_user_info($context = 'view') { |
|
| 703 | 703 | |
| 704 | 704 | $user_info = array( |
| 705 | - 'user_id' => $this->get_user_id( $context ), |
|
| 706 | - 'email' => $this->get_email( $context ), |
|
| 707 | - 'first_name' => $this->get_first_name( $context ), |
|
| 708 | - 'last_name' => $this->get_last_name( $context ), |
|
| 709 | - 'address' => $this->get_address( $context ), |
|
| 710 | - 'phone' => $this->get_phone( $context ), |
|
| 711 | - 'city' => $this->get_city( $context ), |
|
| 712 | - 'country' => $this->get_country( $context ), |
|
| 713 | - 'state' => $this->get_state( $context ), |
|
| 714 | - 'zip' => $this->get_zip( $context ), |
|
| 715 | - 'company' => $this->get_company( $context ), |
|
| 716 | - 'vat_number' => $this->get_vat_number( $context ), |
|
| 717 | - 'discount' => $this->get_discount_code( $context ), |
|
| 705 | + 'user_id' => $this->get_user_id($context), |
|
| 706 | + 'email' => $this->get_email($context), |
|
| 707 | + 'first_name' => $this->get_first_name($context), |
|
| 708 | + 'last_name' => $this->get_last_name($context), |
|
| 709 | + 'address' => $this->get_address($context), |
|
| 710 | + 'phone' => $this->get_phone($context), |
|
| 711 | + 'city' => $this->get_city($context), |
|
| 712 | + 'country' => $this->get_country($context), |
|
| 713 | + 'state' => $this->get_state($context), |
|
| 714 | + 'zip' => $this->get_zip($context), |
|
| 715 | + 'company' => $this->get_company($context), |
|
| 716 | + 'vat_number' => $this->get_vat_number($context), |
|
| 717 | + 'discount' => $this->get_discount_code($context), |
|
| 718 | 718 | ); |
| 719 | 719 | |
| 720 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 720 | + return apply_filters('wpinv_user_info', $user_info, $this->get_id(), $this); |
|
| 721 | 721 | |
| 722 | 722 | } |
| 723 | 723 | |
@@ -728,8 +728,8 @@ discard block |
||
| 728 | 728 | * @param string $context View or edit context. |
| 729 | 729 | * @return int |
| 730 | 730 | */ |
| 731 | - public function get_author( $context = 'view' ) { |
|
| 732 | - return (int) $this->get_prop( 'author', $context ); |
|
| 731 | + public function get_author($context = 'view') { |
|
| 732 | + return (int) $this->get_prop('author', $context); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | /** |
@@ -739,8 +739,8 @@ discard block |
||
| 739 | 739 | * @param string $context View or edit context. |
| 740 | 740 | * @return int |
| 741 | 741 | */ |
| 742 | - public function get_user_id( $context = 'view' ) { |
|
| 743 | - return $this->get_author( $context ); |
|
| 742 | + public function get_user_id($context = 'view') { |
|
| 743 | + return $this->get_author($context); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -750,8 +750,8 @@ discard block |
||
| 750 | 750 | * @param string $context View or edit context. |
| 751 | 751 | * @return int |
| 752 | 752 | */ |
| 753 | - public function get_customer_id( $context = 'view' ) { |
|
| 754 | - return $this->get_author( $context ); |
|
| 753 | + public function get_customer_id($context = 'view') { |
|
| 754 | + return $this->get_author($context); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | /** |
@@ -761,8 +761,8 @@ discard block |
||
| 761 | 761 | * @param string $context View or edit context. |
| 762 | 762 | * @return string |
| 763 | 763 | */ |
| 764 | - public function get_ip( $context = 'view' ) { |
|
| 765 | - return $this->get_prop( 'user_ip', $context ); |
|
| 764 | + public function get_ip($context = 'view') { |
|
| 765 | + return $this->get_prop('user_ip', $context); |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | /** |
@@ -772,8 +772,8 @@ discard block |
||
| 772 | 772 | * @param string $context View or edit context. |
| 773 | 773 | * @return string |
| 774 | 774 | */ |
| 775 | - public function get_user_ip( $context = 'view' ) { |
|
| 776 | - return $this->get_ip( $context ); |
|
| 775 | + public function get_user_ip($context = 'view') { |
|
| 776 | + return $this->get_ip($context); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | /** |
@@ -783,8 +783,8 @@ discard block |
||
| 783 | 783 | * @param string $context View or edit context. |
| 784 | 784 | * @return string |
| 785 | 785 | */ |
| 786 | - public function get_customer_ip( $context = 'view' ) { |
|
| 787 | - return $this->get_ip( $context ); |
|
| 786 | + public function get_customer_ip($context = 'view') { |
|
| 787 | + return $this->get_ip($context); |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | /** |
@@ -794,8 +794,8 @@ discard block |
||
| 794 | 794 | * @param string $context View or edit context. |
| 795 | 795 | * @return string |
| 796 | 796 | */ |
| 797 | - public function get_first_name( $context = 'view' ) { |
|
| 798 | - return $this->get_prop( 'first_name', $context ); |
|
| 797 | + public function get_first_name($context = 'view') { |
|
| 798 | + return $this->get_prop('first_name', $context); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | /** |
@@ -805,8 +805,8 @@ discard block |
||
| 805 | 805 | * @param string $context View or edit context. |
| 806 | 806 | * @return int |
| 807 | 807 | */ |
| 808 | - public function get_user_first_name( $context = 'view' ) { |
|
| 809 | - return $this->get_first_name( $context ); |
|
| 808 | + public function get_user_first_name($context = 'view') { |
|
| 809 | + return $this->get_first_name($context); |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -816,8 +816,8 @@ discard block |
||
| 816 | 816 | * @param string $context View or edit context. |
| 817 | 817 | * @return int |
| 818 | 818 | */ |
| 819 | - public function get_customer_first_name( $context = 'view' ) { |
|
| 820 | - return $this->get_first_name( $context ); |
|
| 819 | + public function get_customer_first_name($context = 'view') { |
|
| 820 | + return $this->get_first_name($context); |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | /** |
@@ -827,8 +827,8 @@ discard block |
||
| 827 | 827 | * @param string $context View or edit context. |
| 828 | 828 | * @return string |
| 829 | 829 | */ |
| 830 | - public function get_last_name( $context = 'view' ) { |
|
| 831 | - return $this->get_prop( 'last_name', $context ); |
|
| 830 | + public function get_last_name($context = 'view') { |
|
| 831 | + return $this->get_prop('last_name', $context); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -838,8 +838,8 @@ discard block |
||
| 838 | 838 | * @param string $context View or edit context. |
| 839 | 839 | * @return int |
| 840 | 840 | */ |
| 841 | - public function get_user_last_name( $context = 'view' ) { |
|
| 842 | - return $this->get_last_name( $context ); |
|
| 841 | + public function get_user_last_name($context = 'view') { |
|
| 842 | + return $this->get_last_name($context); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | /** |
@@ -849,8 +849,8 @@ discard block |
||
| 849 | 849 | * @param string $context View or edit context. |
| 850 | 850 | * @return int |
| 851 | 851 | */ |
| 852 | - public function get_customer_last_name( $context = 'view' ) { |
|
| 853 | - return $this->get_last_name( $context ); |
|
| 852 | + public function get_customer_last_name($context = 'view') { |
|
| 853 | + return $this->get_last_name($context); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | /** |
@@ -860,8 +860,8 @@ discard block |
||
| 860 | 860 | * @param string $context View or edit context. |
| 861 | 861 | * @return string |
| 862 | 862 | */ |
| 863 | - public function get_full_name( $context = 'view' ) { |
|
| 864 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 863 | + public function get_full_name($context = 'view') { |
|
| 864 | + return trim($this->get_first_name($context) . ' ' . $this->get_last_name($context)); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | /** |
@@ -871,8 +871,8 @@ discard block |
||
| 871 | 871 | * @param string $context View or edit context. |
| 872 | 872 | * @return int |
| 873 | 873 | */ |
| 874 | - public function get_user_full_name( $context = 'view' ) { |
|
| 875 | - return $this->get_full_name( $context ); |
|
| 874 | + public function get_user_full_name($context = 'view') { |
|
| 875 | + return $this->get_full_name($context); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
@@ -882,8 +882,8 @@ discard block |
||
| 882 | 882 | * @param string $context View or edit context. |
| 883 | 883 | * @return int |
| 884 | 884 | */ |
| 885 | - public function get_customer_full_name( $context = 'view' ) { |
|
| 886 | - return $this->get_full_name( $context ); |
|
| 885 | + public function get_customer_full_name($context = 'view') { |
|
| 886 | + return $this->get_full_name($context); |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | /** |
@@ -893,8 +893,8 @@ discard block |
||
| 893 | 893 | * @param string $context View or edit context. |
| 894 | 894 | * @return string |
| 895 | 895 | */ |
| 896 | - public function get_phone( $context = 'view' ) { |
|
| 897 | - return $this->get_prop( 'phone', $context ); |
|
| 896 | + public function get_phone($context = 'view') { |
|
| 897 | + return $this->get_prop('phone', $context); |
|
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | /** |
@@ -904,8 +904,8 @@ discard block |
||
| 904 | 904 | * @param string $context View or edit context. |
| 905 | 905 | * @return int |
| 906 | 906 | */ |
| 907 | - public function get_phone_number( $context = 'view' ) { |
|
| 908 | - return $this->get_phone( $context ); |
|
| 907 | + public function get_phone_number($context = 'view') { |
|
| 908 | + return $this->get_phone($context); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | /** |
@@ -915,8 +915,8 @@ discard block |
||
| 915 | 915 | * @param string $context View or edit context. |
| 916 | 916 | * @return int |
| 917 | 917 | */ |
| 918 | - public function get_user_phone( $context = 'view' ) { |
|
| 919 | - return $this->get_phone( $context ); |
|
| 918 | + public function get_user_phone($context = 'view') { |
|
| 919 | + return $this->get_phone($context); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
@@ -926,8 +926,8 @@ discard block |
||
| 926 | 926 | * @param string $context View or edit context. |
| 927 | 927 | * @return int |
| 928 | 928 | */ |
| 929 | - public function get_customer_phone( $context = 'view' ) { |
|
| 930 | - return $this->get_phone( $context ); |
|
| 929 | + public function get_customer_phone($context = 'view') { |
|
| 930 | + return $this->get_phone($context); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | 933 | /** |
@@ -937,8 +937,8 @@ discard block |
||
| 937 | 937 | * @param string $context View or edit context. |
| 938 | 938 | * @return string |
| 939 | 939 | */ |
| 940 | - public function get_email( $context = 'view' ) { |
|
| 941 | - return $this->get_prop( 'email', $context ); |
|
| 940 | + public function get_email($context = 'view') { |
|
| 941 | + return $this->get_prop('email', $context); |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | /** |
@@ -948,8 +948,8 @@ discard block |
||
| 948 | 948 | * @param string $context View or edit context. |
| 949 | 949 | * @return string |
| 950 | 950 | */ |
| 951 | - public function get_email_address( $context = 'view' ) { |
|
| 952 | - return $this->get_email( $context ); |
|
| 951 | + public function get_email_address($context = 'view') { |
|
| 952 | + return $this->get_email($context); |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | /** |
@@ -959,8 +959,8 @@ discard block |
||
| 959 | 959 | * @param string $context View or edit context. |
| 960 | 960 | * @return int |
| 961 | 961 | */ |
| 962 | - public function get_user_email( $context = 'view' ) { |
|
| 963 | - return $this->get_email( $context ); |
|
| 962 | + public function get_user_email($context = 'view') { |
|
| 963 | + return $this->get_email($context); |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | /** |
@@ -970,8 +970,8 @@ discard block |
||
| 970 | 970 | * @param string $context View or edit context. |
| 971 | 971 | * @return int |
| 972 | 972 | */ |
| 973 | - public function get_customer_email( $context = 'view' ) { |
|
| 974 | - return $this->get_email( $context ); |
|
| 973 | + public function get_customer_email($context = 'view') { |
|
| 974 | + return $this->get_email($context); |
|
| 975 | 975 | } |
| 976 | 976 | |
| 977 | 977 | /** |
@@ -981,9 +981,9 @@ discard block |
||
| 981 | 981 | * @param string $context View or edit context. |
| 982 | 982 | * @return string |
| 983 | 983 | */ |
| 984 | - public function get_country( $context = 'view' ) { |
|
| 985 | - $country = $this->get_prop( 'country', $context ); |
|
| 986 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 984 | + public function get_country($context = 'view') { |
|
| 985 | + $country = $this->get_prop('country', $context); |
|
| 986 | + return empty($country) ? wpinv_get_default_country() : $country; |
|
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | /** |
@@ -993,8 +993,8 @@ discard block |
||
| 993 | 993 | * @param string $context View or edit context. |
| 994 | 994 | * @return int |
| 995 | 995 | */ |
| 996 | - public function get_user_country( $context = 'view' ) { |
|
| 997 | - return $this->get_country( $context ); |
|
| 996 | + public function get_user_country($context = 'view') { |
|
| 997 | + return $this->get_country($context); |
|
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | 1000 | /** |
@@ -1004,8 +1004,8 @@ discard block |
||
| 1004 | 1004 | * @param string $context View or edit context. |
| 1005 | 1005 | * @return int |
| 1006 | 1006 | */ |
| 1007 | - public function get_customer_country( $context = 'view' ) { |
|
| 1008 | - return $this->get_country( $context ); |
|
| 1007 | + public function get_customer_country($context = 'view') { |
|
| 1008 | + return $this->get_country($context); |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | /** |
@@ -1015,9 +1015,9 @@ discard block |
||
| 1015 | 1015 | * @param string $context View or edit context. |
| 1016 | 1016 | * @return string |
| 1017 | 1017 | */ |
| 1018 | - public function get_state( $context = 'view' ) { |
|
| 1019 | - $state = $this->get_prop( 'state', $context ); |
|
| 1020 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1018 | + public function get_state($context = 'view') { |
|
| 1019 | + $state = $this->get_prop('state', $context); |
|
| 1020 | + return empty($state) ? wpinv_get_default_state() : $state; |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | /** |
@@ -1027,8 +1027,8 @@ discard block |
||
| 1027 | 1027 | * @param string $context View or edit context. |
| 1028 | 1028 | * @return int |
| 1029 | 1029 | */ |
| 1030 | - public function get_user_state( $context = 'view' ) { |
|
| 1031 | - return $this->get_state( $context ); |
|
| 1030 | + public function get_user_state($context = 'view') { |
|
| 1031 | + return $this->get_state($context); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | /** |
@@ -1038,8 +1038,8 @@ discard block |
||
| 1038 | 1038 | * @param string $context View or edit context. |
| 1039 | 1039 | * @return int |
| 1040 | 1040 | */ |
| 1041 | - public function get_customer_state( $context = 'view' ) { |
|
| 1042 | - return $this->get_state( $context ); |
|
| 1041 | + public function get_customer_state($context = 'view') { |
|
| 1042 | + return $this->get_state($context); |
|
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | /** |
@@ -1049,8 +1049,8 @@ discard block |
||
| 1049 | 1049 | * @param string $context View or edit context. |
| 1050 | 1050 | * @return string |
| 1051 | 1051 | */ |
| 1052 | - public function get_city( $context = 'view' ) { |
|
| 1053 | - return $this->get_prop( 'city', $context ); |
|
| 1052 | + public function get_city($context = 'view') { |
|
| 1053 | + return $this->get_prop('city', $context); |
|
| 1054 | 1054 | } |
| 1055 | 1055 | |
| 1056 | 1056 | /** |
@@ -1060,8 +1060,8 @@ discard block |
||
| 1060 | 1060 | * @param string $context View or edit context. |
| 1061 | 1061 | * @return string |
| 1062 | 1062 | */ |
| 1063 | - public function get_user_city( $context = 'view' ) { |
|
| 1064 | - return $this->get_city( $context ); |
|
| 1063 | + public function get_user_city($context = 'view') { |
|
| 1064 | + return $this->get_city($context); |
|
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | /** |
@@ -1071,8 +1071,8 @@ discard block |
||
| 1071 | 1071 | * @param string $context View or edit context. |
| 1072 | 1072 | * @return string |
| 1073 | 1073 | */ |
| 1074 | - public function get_customer_city( $context = 'view' ) { |
|
| 1075 | - return $this->get_city( $context ); |
|
| 1074 | + public function get_customer_city($context = 'view') { |
|
| 1075 | + return $this->get_city($context); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | /** |
@@ -1082,8 +1082,8 @@ discard block |
||
| 1082 | 1082 | * @param string $context View or edit context. |
| 1083 | 1083 | * @return string |
| 1084 | 1084 | */ |
| 1085 | - public function get_zip( $context = 'view' ) { |
|
| 1086 | - return $this->get_prop( 'zip', $context ); |
|
| 1085 | + public function get_zip($context = 'view') { |
|
| 1086 | + return $this->get_prop('zip', $context); |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | /** |
@@ -1093,8 +1093,8 @@ discard block |
||
| 1093 | 1093 | * @param string $context View or edit context. |
| 1094 | 1094 | * @return string |
| 1095 | 1095 | */ |
| 1096 | - public function get_user_zip( $context = 'view' ) { |
|
| 1097 | - return $this->get_zip( $context ); |
|
| 1096 | + public function get_user_zip($context = 'view') { |
|
| 1097 | + return $this->get_zip($context); |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | /** |
@@ -1104,8 +1104,8 @@ discard block |
||
| 1104 | 1104 | * @param string $context View or edit context. |
| 1105 | 1105 | * @return string |
| 1106 | 1106 | */ |
| 1107 | - public function get_customer_zip( $context = 'view' ) { |
|
| 1108 | - return $this->get_zip( $context ); |
|
| 1107 | + public function get_customer_zip($context = 'view') { |
|
| 1108 | + return $this->get_zip($context); |
|
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | 1111 | /** |
@@ -1115,8 +1115,8 @@ discard block |
||
| 1115 | 1115 | * @param string $context View or edit context. |
| 1116 | 1116 | * @return string |
| 1117 | 1117 | */ |
| 1118 | - public function get_company( $context = 'view' ) { |
|
| 1119 | - return $this->get_prop( 'company', $context ); |
|
| 1118 | + public function get_company($context = 'view') { |
|
| 1119 | + return $this->get_prop('company', $context); |
|
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | 1122 | /** |
@@ -1126,8 +1126,8 @@ discard block |
||
| 1126 | 1126 | * @param string $context View or edit context. |
| 1127 | 1127 | * @return string |
| 1128 | 1128 | */ |
| 1129 | - public function get_user_company( $context = 'view' ) { |
|
| 1130 | - return $this->get_company( $context ); |
|
| 1129 | + public function get_user_company($context = 'view') { |
|
| 1130 | + return $this->get_company($context); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | /** |
@@ -1137,8 +1137,8 @@ discard block |
||
| 1137 | 1137 | * @param string $context View or edit context. |
| 1138 | 1138 | * @return string |
| 1139 | 1139 | */ |
| 1140 | - public function get_customer_company( $context = 'view' ) { |
|
| 1141 | - return $this->get_company( $context ); |
|
| 1140 | + public function get_customer_company($context = 'view') { |
|
| 1141 | + return $this->get_company($context); |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | /** |
@@ -1148,8 +1148,8 @@ discard block |
||
| 1148 | 1148 | * @param string $context View or edit context. |
| 1149 | 1149 | * @return string |
| 1150 | 1150 | */ |
| 1151 | - public function get_vat_number( $context = 'view' ) { |
|
| 1152 | - return $this->get_prop( 'vat_number', $context ); |
|
| 1151 | + public function get_vat_number($context = 'view') { |
|
| 1152 | + return $this->get_prop('vat_number', $context); |
|
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | /** |
@@ -1159,8 +1159,8 @@ discard block |
||
| 1159 | 1159 | * @param string $context View or edit context. |
| 1160 | 1160 | * @return string |
| 1161 | 1161 | */ |
| 1162 | - public function get_user_vat_number( $context = 'view' ) { |
|
| 1163 | - return $this->get_vat_number( $context ); |
|
| 1162 | + public function get_user_vat_number($context = 'view') { |
|
| 1163 | + return $this->get_vat_number($context); |
|
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | /** |
@@ -1170,8 +1170,8 @@ discard block |
||
| 1170 | 1170 | * @param string $context View or edit context. |
| 1171 | 1171 | * @return string |
| 1172 | 1172 | */ |
| 1173 | - public function get_customer_vat_number( $context = 'view' ) { |
|
| 1174 | - return $this->get_vat_number( $context ); |
|
| 1173 | + public function get_customer_vat_number($context = 'view') { |
|
| 1174 | + return $this->get_vat_number($context); |
|
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | /** |
@@ -1181,8 +1181,8 @@ discard block |
||
| 1181 | 1181 | * @param string $context View or edit context. |
| 1182 | 1182 | * @return string |
| 1183 | 1183 | */ |
| 1184 | - public function get_vat_rate( $context = 'view' ) { |
|
| 1185 | - return $this->get_prop( 'vat_rate', $context ); |
|
| 1184 | + public function get_vat_rate($context = 'view') { |
|
| 1185 | + return $this->get_prop('vat_rate', $context); |
|
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | 1188 | /** |
@@ -1192,8 +1192,8 @@ discard block |
||
| 1192 | 1192 | * @param string $context View or edit context. |
| 1193 | 1193 | * @return string |
| 1194 | 1194 | */ |
| 1195 | - public function get_user_vat_rate( $context = 'view' ) { |
|
| 1196 | - return $this->get_vat_rate( $context ); |
|
| 1195 | + public function get_user_vat_rate($context = 'view') { |
|
| 1196 | + return $this->get_vat_rate($context); |
|
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | /** |
@@ -1203,8 +1203,8 @@ discard block |
||
| 1203 | 1203 | * @param string $context View or edit context. |
| 1204 | 1204 | * @return string |
| 1205 | 1205 | */ |
| 1206 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1207 | - return $this->get_vat_rate( $context ); |
|
| 1206 | + public function get_customer_vat_rate($context = 'view') { |
|
| 1207 | + return $this->get_vat_rate($context); |
|
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | /** |
@@ -1214,8 +1214,8 @@ discard block |
||
| 1214 | 1214 | * @param string $context View or edit context. |
| 1215 | 1215 | * @return string |
| 1216 | 1216 | */ |
| 1217 | - public function get_address( $context = 'view' ) { |
|
| 1218 | - return $this->get_prop( 'address', $context ); |
|
| 1217 | + public function get_address($context = 'view') { |
|
| 1218 | + return $this->get_prop('address', $context); |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | /** |
@@ -1225,8 +1225,8 @@ discard block |
||
| 1225 | 1225 | * @param string $context View or edit context. |
| 1226 | 1226 | * @return string |
| 1227 | 1227 | */ |
| 1228 | - public function get_user_address( $context = 'view' ) { |
|
| 1229 | - return $this->get_address( $context ); |
|
| 1228 | + public function get_user_address($context = 'view') { |
|
| 1229 | + return $this->get_address($context); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | /** |
@@ -1236,8 +1236,8 @@ discard block |
||
| 1236 | 1236 | * @param string $context View or edit context. |
| 1237 | 1237 | * @return string |
| 1238 | 1238 | */ |
| 1239 | - public function get_customer_address( $context = 'view' ) { |
|
| 1240 | - return $this->get_address( $context ); |
|
| 1239 | + public function get_customer_address($context = 'view') { |
|
| 1240 | + return $this->get_address($context); |
|
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | /** |
@@ -1247,8 +1247,8 @@ discard block |
||
| 1247 | 1247 | * @param string $context View or edit context. |
| 1248 | 1248 | * @return bool |
| 1249 | 1249 | */ |
| 1250 | - public function get_is_viewed( $context = 'view' ) { |
|
| 1251 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1250 | + public function get_is_viewed($context = 'view') { |
|
| 1251 | + return (bool) $this->get_prop('is_viewed', $context); |
|
| 1252 | 1252 | } |
| 1253 | 1253 | |
| 1254 | 1254 | /** |
@@ -1258,8 +1258,8 @@ discard block |
||
| 1258 | 1258 | * @param string $context View or edit context. |
| 1259 | 1259 | * @return bool |
| 1260 | 1260 | */ |
| 1261 | - public function get_email_cc( $context = 'view' ) { |
|
| 1262 | - return $this->get_prop( 'email_cc', $context ); |
|
| 1261 | + public function get_email_cc($context = 'view') { |
|
| 1262 | + return $this->get_prop('email_cc', $context); |
|
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | 1265 | /** |
@@ -1269,8 +1269,8 @@ discard block |
||
| 1269 | 1269 | * @param string $context View or edit context. |
| 1270 | 1270 | * @return bool |
| 1271 | 1271 | */ |
| 1272 | - public function get_template( $context = 'view' ) { |
|
| 1273 | - return $this->get_prop( 'template', $context ); |
|
| 1272 | + public function get_template($context = 'view') { |
|
| 1273 | + return $this->get_prop('template', $context); |
|
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | /** |
@@ -1280,8 +1280,8 @@ discard block |
||
| 1280 | 1280 | * @param string $context View or edit context. |
| 1281 | 1281 | * @return bool |
| 1282 | 1282 | */ |
| 1283 | - public function get_address_confirmed( $context = 'view' ) { |
|
| 1284 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1283 | + public function get_address_confirmed($context = 'view') { |
|
| 1284 | + return (bool) $this->get_prop('address_confirmed', $context); |
|
| 1285 | 1285 | } |
| 1286 | 1286 | |
| 1287 | 1287 | /** |
@@ -1291,8 +1291,8 @@ discard block |
||
| 1291 | 1291 | * @param string $context View or edit context. |
| 1292 | 1292 | * @return bool |
| 1293 | 1293 | */ |
| 1294 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1295 | - return $this->get_address_confirmed( $context ); |
|
| 1294 | + public function get_user_address_confirmed($context = 'view') { |
|
| 1295 | + return $this->get_address_confirmed($context); |
|
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | /** |
@@ -1302,8 +1302,8 @@ discard block |
||
| 1302 | 1302 | * @param string $context View or edit context. |
| 1303 | 1303 | * @return bool |
| 1304 | 1304 | */ |
| 1305 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1306 | - return $this->get_address_confirmed( $context ); |
|
| 1305 | + public function get_customer_address_confirmed($context = 'view') { |
|
| 1306 | + return $this->get_address_confirmed($context); |
|
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | 1309 | /** |
@@ -1313,12 +1313,12 @@ discard block |
||
| 1313 | 1313 | * @param string $context View or edit context. |
| 1314 | 1314 | * @return float |
| 1315 | 1315 | */ |
| 1316 | - public function get_subtotal( $context = 'view' ) { |
|
| 1317 | - $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
|
| 1316 | + public function get_subtotal($context = 'view') { |
|
| 1317 | + $subtotal = (float) $this->get_prop('subtotal', $context); |
|
| 1318 | 1318 | |
| 1319 | 1319 | // Backwards compatibility. |
| 1320 | - if ( is_bool( $context ) && $context ) { |
|
| 1321 | - return wpinv_price( wpinv_format_amount( $subtotal ), $this->get_currency() ); |
|
| 1320 | + if (is_bool($context) && $context) { |
|
| 1321 | + return wpinv_price(wpinv_format_amount($subtotal), $this->get_currency()); |
|
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | return $subtotal; |
@@ -1331,8 +1331,8 @@ discard block |
||
| 1331 | 1331 | * @param string $context View or edit context. |
| 1332 | 1332 | * @return float |
| 1333 | 1333 | */ |
| 1334 | - public function get_total_discount( $context = 'view' ) { |
|
| 1335 | - return (float) $this->get_prop( 'total_discount', $context ); |
|
| 1334 | + public function get_total_discount($context = 'view') { |
|
| 1335 | + return (float) $this->get_prop('total_discount', $context); |
|
| 1336 | 1336 | } |
| 1337 | 1337 | |
| 1338 | 1338 | /** |
@@ -1342,18 +1342,18 @@ discard block |
||
| 1342 | 1342 | * @param string $context View or edit context. |
| 1343 | 1343 | * @return float |
| 1344 | 1344 | */ |
| 1345 | - public function get_total_tax( $context = 'view' ) { |
|
| 1346 | - return (float) $this->get_prop( 'total_tax', $context ); |
|
| 1345 | + public function get_total_tax($context = 'view') { |
|
| 1346 | + return (float) $this->get_prop('total_tax', $context); |
|
| 1347 | 1347 | } |
| 1348 | 1348 | |
| 1349 | 1349 | /** |
| 1350 | 1350 | * @deprecated |
| 1351 | 1351 | */ |
| 1352 | - public function get_final_tax( $currency = false ) { |
|
| 1352 | + public function get_final_tax($currency = false) { |
|
| 1353 | 1353 | $tax = $this->get_total_tax(); |
| 1354 | 1354 | |
| 1355 | - if ( $currency ) { |
|
| 1356 | - return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
| 1355 | + if ($currency) { |
|
| 1356 | + return wpinv_price(wpinv_format_amount($tax, NULL, false), $this->get_currency()); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | 1359 | return $tax; |
@@ -1366,8 +1366,8 @@ discard block |
||
| 1366 | 1366 | * @param string $context View or edit context. |
| 1367 | 1367 | * @return float |
| 1368 | 1368 | */ |
| 1369 | - public function get_total_fees( $context = 'view' ) { |
|
| 1370 | - return (float) $this->get_prop( 'total_fees', $context ); |
|
| 1369 | + public function get_total_fees($context = 'view') { |
|
| 1370 | + return (float) $this->get_prop('total_fees', $context); |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | /** |
@@ -1377,8 +1377,8 @@ discard block |
||
| 1377 | 1377 | * @param string $context View or edit context. |
| 1378 | 1378 | * @return float |
| 1379 | 1379 | */ |
| 1380 | - public function get_fees_total( $context = 'view' ) { |
|
| 1381 | - return $this->get_total_fees( $context ); |
|
| 1380 | + public function get_fees_total($context = 'view') { |
|
| 1381 | + return $this->get_total_fees($context); |
|
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | 1384 | /** |
@@ -1389,7 +1389,7 @@ discard block |
||
| 1389 | 1389 | */ |
| 1390 | 1390 | public function get_total() { |
| 1391 | 1391 | $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
| 1392 | - return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
| 1392 | + return apply_filters('getpaid_get_invoice_total_amount', $total, $this); |
|
| 1393 | 1393 | } |
| 1394 | 1394 | |
| 1395 | 1395 | /** |
@@ -1411,7 +1411,7 @@ discard block |
||
| 1411 | 1411 | */ |
| 1412 | 1412 | public function get_initial_total() { |
| 1413 | 1413 | |
| 1414 | - if ( empty( $this->totals ) ) { |
|
| 1414 | + if (empty($this->totals)) { |
|
| 1415 | 1415 | $this->recalculate_total(); |
| 1416 | 1416 | } |
| 1417 | 1417 | |
@@ -1421,11 +1421,11 @@ discard block |
||
| 1421 | 1421 | $subtotal = $this->totals['subtotal']['initial']; |
| 1422 | 1422 | $total = $tax + $fee - $discount + $subtotal; |
| 1423 | 1423 | |
| 1424 | - if ( 0 > $total ) { |
|
| 1424 | + if (0 > $total) { |
|
| 1425 | 1425 | $total = 0; |
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | - return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
|
| 1428 | + return apply_filters('wpinv_get_initial_invoice_total', $total, $this); |
|
| 1429 | 1429 | } |
| 1430 | 1430 | |
| 1431 | 1431 | /** |
@@ -1437,7 +1437,7 @@ discard block |
||
| 1437 | 1437 | */ |
| 1438 | 1438 | public function get_recurring_total() { |
| 1439 | 1439 | |
| 1440 | - if ( empty( $this->totals ) ) { |
|
| 1440 | + if (empty($this->totals)) { |
|
| 1441 | 1441 | $this->recalculate_total(); |
| 1442 | 1442 | } |
| 1443 | 1443 | |
@@ -1447,11 +1447,11 @@ discard block |
||
| 1447 | 1447 | $subtotal = $this->totals['subtotal']['recurring']; |
| 1448 | 1448 | $total = $tax + $fee - $discount + $subtotal; |
| 1449 | 1449 | |
| 1450 | - if ( 0 > $total ) { |
|
| 1450 | + if (0 > $total) { |
|
| 1451 | 1451 | $total = 0; |
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | - return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
|
| 1454 | + return apply_filters('wpinv_get_recurring_invoice_total', $total, $this); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | /** |
@@ -1462,10 +1462,10 @@ discard block |
||
| 1462 | 1462 | * @param string $currency Whether to include the currency. |
| 1463 | 1463 | * @return float |
| 1464 | 1464 | */ |
| 1465 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
| 1465 | + public function get_recurring_details($field = '', $currency = false) { |
|
| 1466 | 1466 | |
| 1467 | 1467 | // Maybe recalculate totals. |
| 1468 | - if ( empty( $this->totals ) ) { |
|
| 1468 | + if (empty($this->totals)) { |
|
| 1469 | 1469 | $this->recalculate_total(); |
| 1470 | 1470 | } |
| 1471 | 1471 | |
@@ -1485,8 +1485,8 @@ discard block |
||
| 1485 | 1485 | $currency |
| 1486 | 1486 | ); |
| 1487 | 1487 | |
| 1488 | - if ( isset( $data[$field] ) ) { |
|
| 1489 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
| 1488 | + if (isset($data[$field])) { |
|
| 1489 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
| 1490 | 1490 | } |
| 1491 | 1491 | |
| 1492 | 1492 | return $data; |
@@ -1499,8 +1499,8 @@ discard block |
||
| 1499 | 1499 | * @param string $context View or edit context. |
| 1500 | 1500 | * @return array |
| 1501 | 1501 | */ |
| 1502 | - public function get_fees( $context = 'view' ) { |
|
| 1503 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1502 | + public function get_fees($context = 'view') { |
|
| 1503 | + return wpinv_parse_list($this->get_prop('fees', $context)); |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | /** |
@@ -1510,8 +1510,8 @@ discard block |
||
| 1510 | 1510 | * @param string $context View or edit context. |
| 1511 | 1511 | * @return array |
| 1512 | 1512 | */ |
| 1513 | - public function get_discounts( $context = 'view' ) { |
|
| 1514 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1513 | + public function get_discounts($context = 'view') { |
|
| 1514 | + return wpinv_parse_list($this->get_prop('discounts', $context)); |
|
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | /** |
@@ -1521,8 +1521,8 @@ discard block |
||
| 1521 | 1521 | * @param string $context View or edit context. |
| 1522 | 1522 | * @return array |
| 1523 | 1523 | */ |
| 1524 | - public function get_taxes( $context = 'view' ) { |
|
| 1525 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1524 | + public function get_taxes($context = 'view') { |
|
| 1525 | + return wpinv_parse_list($this->get_prop('taxes', $context)); |
|
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | 1528 | /** |
@@ -1532,8 +1532,8 @@ discard block |
||
| 1532 | 1532 | * @param string $context View or edit context. |
| 1533 | 1533 | * @return GetPaid_Form_Item[] |
| 1534 | 1534 | */ |
| 1535 | - public function get_items( $context = 'view' ) { |
|
| 1536 | - return $this->get_prop( 'items', $context ); |
|
| 1535 | + public function get_items($context = 'view') { |
|
| 1536 | + return $this->get_prop('items', $context); |
|
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | /** |
@@ -1543,8 +1543,8 @@ discard block |
||
| 1543 | 1543 | * @param string $context View or edit context. |
| 1544 | 1544 | * @return int |
| 1545 | 1545 | */ |
| 1546 | - public function get_payment_form( $context = 'view' ) { |
|
| 1547 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1546 | + public function get_payment_form($context = 'view') { |
|
| 1547 | + return intval($this->get_prop('payment_form', $context)); |
|
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | /** |
@@ -1554,8 +1554,8 @@ discard block |
||
| 1554 | 1554 | * @param string $context View or edit context. |
| 1555 | 1555 | * @return string |
| 1556 | 1556 | */ |
| 1557 | - public function get_submission_id( $context = 'view' ) { |
|
| 1558 | - return $this->get_prop( 'submission_id', $context ); |
|
| 1557 | + public function get_submission_id($context = 'view') { |
|
| 1558 | + return $this->get_prop('submission_id', $context); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | /** |
@@ -1565,8 +1565,8 @@ discard block |
||
| 1565 | 1565 | * @param string $context View or edit context. |
| 1566 | 1566 | * @return string |
| 1567 | 1567 | */ |
| 1568 | - public function get_discount_code( $context = 'view' ) { |
|
| 1569 | - return $this->get_prop( 'discount_code', $context ); |
|
| 1568 | + public function get_discount_code($context = 'view') { |
|
| 1569 | + return $this->get_prop('discount_code', $context); |
|
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | 1572 | /** |
@@ -1576,8 +1576,8 @@ discard block |
||
| 1576 | 1576 | * @param string $context View or edit context. |
| 1577 | 1577 | * @return string |
| 1578 | 1578 | */ |
| 1579 | - public function get_gateway( $context = 'view' ) { |
|
| 1580 | - return $this->get_prop( 'gateway', $context ); |
|
| 1579 | + public function get_gateway($context = 'view') { |
|
| 1580 | + return $this->get_prop('gateway', $context); |
|
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | /** |
@@ -1587,8 +1587,8 @@ discard block |
||
| 1587 | 1587 | * @return string |
| 1588 | 1588 | */ |
| 1589 | 1589 | public function get_gateway_title() { |
| 1590 | - $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
|
| 1591 | - return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
|
| 1590 | + $title = wpinv_get_gateway_checkout_label($this->get_gateway()); |
|
| 1591 | + return apply_filters('wpinv_gateway_title', $title, $this->get_id(), $this); |
|
| 1592 | 1592 | } |
| 1593 | 1593 | |
| 1594 | 1594 | /** |
@@ -1598,8 +1598,8 @@ discard block |
||
| 1598 | 1598 | * @param string $context View or edit context. |
| 1599 | 1599 | * @return string |
| 1600 | 1600 | */ |
| 1601 | - public function get_transaction_id( $context = 'view' ) { |
|
| 1602 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 1601 | + public function get_transaction_id($context = 'view') { |
|
| 1602 | + return $this->get_prop('transaction_id', $context); |
|
| 1603 | 1603 | } |
| 1604 | 1604 | |
| 1605 | 1605 | /** |
@@ -1609,9 +1609,9 @@ discard block |
||
| 1609 | 1609 | * @param string $context View or edit context. |
| 1610 | 1610 | * @return string |
| 1611 | 1611 | */ |
| 1612 | - public function get_currency( $context = 'view' ) { |
|
| 1613 | - $currency = $this->get_prop( 'currency', $context ); |
|
| 1614 | - return empty( $currency ) ? wpinv_get_currency() : $currency; |
|
| 1612 | + public function get_currency($context = 'view') { |
|
| 1613 | + $currency = $this->get_prop('currency', $context); |
|
| 1614 | + return empty($currency) ? wpinv_get_currency() : $currency; |
|
| 1615 | 1615 | } |
| 1616 | 1616 | |
| 1617 | 1617 | /** |
@@ -1621,8 +1621,8 @@ discard block |
||
| 1621 | 1621 | * @param string $context View or edit context. |
| 1622 | 1622 | * @return bool |
| 1623 | 1623 | */ |
| 1624 | - public function get_disable_taxes( $context = 'view' ) { |
|
| 1625 | - return (bool) $this->get_prop( 'disable_taxes', $context ); |
|
| 1624 | + public function get_disable_taxes($context = 'view') { |
|
| 1625 | + return (bool) $this->get_prop('disable_taxes', $context); |
|
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | /** |
@@ -1632,12 +1632,12 @@ discard block |
||
| 1632 | 1632 | * @param string $context View or edit context. |
| 1633 | 1633 | * @return int |
| 1634 | 1634 | */ |
| 1635 | - public function get_subscription_id( $context = 'view' ) { |
|
| 1636 | - $subscription_id = $this->get_prop( 'subscription_id', $context ); |
|
| 1635 | + public function get_subscription_id($context = 'view') { |
|
| 1636 | + $subscription_id = $this->get_prop('subscription_id', $context); |
|
| 1637 | 1637 | |
| 1638 | - if ( empty( $subscription_id ) && $this->is_renewal() ) { |
|
| 1638 | + if (empty($subscription_id) && $this->is_renewal()) { |
|
| 1639 | 1639 | $parent = $this->get_parent(); |
| 1640 | - return $parent->get_subscription_id( $context ); |
|
| 1640 | + return $parent->get_subscription_id($context); |
|
| 1641 | 1641 | } |
| 1642 | 1642 | |
| 1643 | 1643 | return $subscription_id; |
@@ -1650,20 +1650,20 @@ discard block |
||
| 1650 | 1650 | * @param string $context View or edit context. |
| 1651 | 1651 | * @return array |
| 1652 | 1652 | */ |
| 1653 | - public function get_payment_meta( $context = 'view' ) { |
|
| 1653 | + public function get_payment_meta($context = 'view') { |
|
| 1654 | 1654 | |
| 1655 | 1655 | return array( |
| 1656 | - 'price' => $this->get_total( $context ), |
|
| 1657 | - 'date' => $this->get_date_created( $context ), |
|
| 1658 | - 'user_email' => $this->get_email( $context ), |
|
| 1659 | - 'invoice_key' => $this->get_key( $context ), |
|
| 1660 | - 'currency' => $this->get_currency( $context ), |
|
| 1661 | - 'items' => $this->get_items( $context ), |
|
| 1662 | - 'user_info' => $this->get_user_info( $context ), |
|
| 1656 | + 'price' => $this->get_total($context), |
|
| 1657 | + 'date' => $this->get_date_created($context), |
|
| 1658 | + 'user_email' => $this->get_email($context), |
|
| 1659 | + 'invoice_key' => $this->get_key($context), |
|
| 1660 | + 'currency' => $this->get_currency($context), |
|
| 1661 | + 'items' => $this->get_items($context), |
|
| 1662 | + 'user_info' => $this->get_user_info($context), |
|
| 1663 | 1663 | 'cart_details' => $this->get_cart_details(), |
| 1664 | - 'status' => $this->get_status( $context ), |
|
| 1665 | - 'fees' => $this->get_fees( $context ), |
|
| 1666 | - 'taxes' => $this->get_taxes( $context ), |
|
| 1664 | + 'status' => $this->get_status($context), |
|
| 1665 | + 'fees' => $this->get_fees($context), |
|
| 1666 | + 'taxes' => $this->get_taxes($context), |
|
| 1667 | 1667 | ); |
| 1668 | 1668 | |
| 1669 | 1669 | } |
@@ -1678,7 +1678,7 @@ discard block |
||
| 1678 | 1678 | $items = $this->get_items(); |
| 1679 | 1679 | $cart_details = array(); |
| 1680 | 1680 | |
| 1681 | - foreach ( $items as $item_id => $item ) { |
|
| 1681 | + foreach ($items as $item_id => $item) { |
|
| 1682 | 1682 | $cart_details[] = $item->prepare_data_for_saving(); |
| 1683 | 1683 | } |
| 1684 | 1684 | |
@@ -1690,11 +1690,11 @@ discard block |
||
| 1690 | 1690 | * |
| 1691 | 1691 | * @return null|GetPaid_Form_Item|int |
| 1692 | 1692 | */ |
| 1693 | - public function get_recurring( $object = false ) { |
|
| 1693 | + public function get_recurring($object = false) { |
|
| 1694 | 1694 | |
| 1695 | 1695 | // Are we returning an object? |
| 1696 | - if ( $object ) { |
|
| 1697 | - return $this->get_item( $this->recurring_item ); |
|
| 1696 | + if ($object) { |
|
| 1697 | + return $this->get_item($this->recurring_item); |
|
| 1698 | 1698 | } |
| 1699 | 1699 | |
| 1700 | 1700 | return $this->recurring_item; |
@@ -1709,15 +1709,15 @@ discard block |
||
| 1709 | 1709 | public function get_subscription_name() { |
| 1710 | 1710 | |
| 1711 | 1711 | // Retrieve the recurring name |
| 1712 | - $item = $this->get_recurring( true ); |
|
| 1712 | + $item = $this->get_recurring(true); |
|
| 1713 | 1713 | |
| 1714 | 1714 | // Abort if it does not exist. |
| 1715 | - if ( empty( $item ) ) { |
|
| 1715 | + if (empty($item)) { |
|
| 1716 | 1716 | return ''; |
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | 1719 | // Return the item name. |
| 1720 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
|
| 1720 | + return apply_filters('wpinv_invoice_get_subscription_name', $item->get_name(), $this); |
|
| 1721 | 1721 | } |
| 1722 | 1722 | |
| 1723 | 1723 | /** |
@@ -1727,9 +1727,9 @@ discard block |
||
| 1727 | 1727 | * @return string |
| 1728 | 1728 | */ |
| 1729 | 1729 | public function get_view_url() { |
| 1730 | - $invoice_url = get_permalink( $this->get_id() ); |
|
| 1731 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1732 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
|
| 1730 | + $invoice_url = get_permalink($this->get_id()); |
|
| 1731 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
| 1732 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this); |
|
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | 1735 | /** |
@@ -1738,25 +1738,25 @@ discard block |
||
| 1738 | 1738 | * @since 1.0.19 |
| 1739 | 1739 | * @return string |
| 1740 | 1740 | */ |
| 1741 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1741 | + public function get_checkout_payment_url($deprecated = false, $secret = false) { |
|
| 1742 | 1742 | |
| 1743 | 1743 | // Retrieve the checkout url. |
| 1744 | 1744 | $pay_url = wpinv_get_checkout_uri(); |
| 1745 | 1745 | |
| 1746 | 1746 | // Maybe force ssl. |
| 1747 | - if ( is_ssl() ) { |
|
| 1748 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
| 1747 | + if (is_ssl()) { |
|
| 1748 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
| 1749 | 1749 | } |
| 1750 | 1750 | |
| 1751 | 1751 | // Add the invoice key. |
| 1752 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1752 | + $pay_url = add_query_arg('invoice_key', $this->get_key(), $pay_url); |
|
| 1753 | 1753 | |
| 1754 | 1754 | // (Maybe?) add a secret |
| 1755 | - if ( $secret ) { |
|
| 1756 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
|
| 1755 | + if ($secret) { |
|
| 1756 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $pay_url); |
|
| 1757 | 1757 | } |
| 1758 | 1758 | |
| 1759 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
|
| 1759 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret); |
|
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | 1762 | /** |
@@ -1771,14 +1771,14 @@ discard block |
||
| 1771 | 1771 | $receipt_url = wpinv_get_success_page_uri(); |
| 1772 | 1772 | |
| 1773 | 1773 | // Maybe force ssl. |
| 1774 | - if ( is_ssl() ) { |
|
| 1775 | - $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
|
| 1774 | + if (is_ssl()) { |
|
| 1775 | + $receipt_url = str_replace('http:', 'https:', $receipt_url); |
|
| 1776 | 1776 | } |
| 1777 | 1777 | |
| 1778 | 1778 | // Add the invoice key. |
| 1779 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1779 | + $receipt_url = add_query_arg('invoice_key', $this->get_key(), $receipt_url); |
|
| 1780 | 1780 | |
| 1781 | - return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
|
| 1781 | + return apply_filters('getpaid_get_invoice_receipt_url', $receipt_url, $this); |
|
| 1782 | 1782 | } |
| 1783 | 1783 | |
| 1784 | 1784 | /** |
@@ -1791,8 +1791,8 @@ discard block |
||
| 1791 | 1791 | * @param string $context View or edit context. |
| 1792 | 1792 | * @return mixed Value of the given invoice property (if set). |
| 1793 | 1793 | */ |
| 1794 | - public function get( $key, $context = 'view' ) { |
|
| 1795 | - return $this->get_prop( $key, $context ); |
|
| 1794 | + public function get($key, $context = 'view') { |
|
| 1795 | + return $this->get_prop($key, $context); |
|
| 1796 | 1796 | } |
| 1797 | 1797 | |
| 1798 | 1798 | /* |
@@ -1815,11 +1815,11 @@ discard block |
||
| 1815 | 1815 | * @param mixed $value new value. |
| 1816 | 1816 | * @return mixed Value of the given invoice property (if set). |
| 1817 | 1817 | */ |
| 1818 | - public function set( $key, $value ) { |
|
| 1818 | + public function set($key, $value) { |
|
| 1819 | 1819 | |
| 1820 | 1820 | $setter = "set_$key"; |
| 1821 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
| 1822 | - $this->{$setter}( $value ); |
|
| 1821 | + if (is_callable(array($this, $setter))) { |
|
| 1822 | + $this->{$setter}($value); |
|
| 1823 | 1823 | } |
| 1824 | 1824 | |
| 1825 | 1825 | } |
@@ -1833,47 +1833,47 @@ discard block |
||
| 1833 | 1833 | * @param bool $manual_update Is this a manual status change?. |
| 1834 | 1834 | * @return array details of change. |
| 1835 | 1835 | */ |
| 1836 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 1836 | + public function set_status($new_status, $note = '', $manual_update = false) { |
|
| 1837 | 1837 | $old_status = $this->get_status(); |
| 1838 | 1838 | |
| 1839 | 1839 | $statuses = $this->get_all_statuses(); |
| 1840 | 1840 | |
| 1841 | - if ( isset( $statuses[ 'draft' ] ) ) { |
|
| 1842 | - unset( $statuses[ 'draft' ] ); |
|
| 1841 | + if (isset($statuses['draft'])) { |
|
| 1842 | + unset($statuses['draft']); |
|
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | - $this->set_prop( 'status', $new_status ); |
|
| 1845 | + $this->set_prop('status', $new_status); |
|
| 1846 | 1846 | |
| 1847 | 1847 | // If setting the status, ensure it's set to a valid status. |
| 1848 | - if ( true === $this->object_read ) { |
|
| 1848 | + if (true === $this->object_read) { |
|
| 1849 | 1849 | |
| 1850 | 1850 | // Only allow valid new status. |
| 1851 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1851 | + if (!array_key_exists($new_status, $statuses)) { |
|
| 1852 | 1852 | $new_status = 'wpi-pending'; |
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | 1855 | // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
| 1856 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1856 | + if ($old_status && !array_key_exists($new_status, $statuses)) { |
|
| 1857 | 1857 | $old_status = 'wpi-pending'; |
| 1858 | 1858 | } |
| 1859 | 1859 | |
| 1860 | 1860 | // Paid - Renewal (i.e when duplicating a parent invoice ) |
| 1861 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 1861 | + if ($new_status == 'wpi-pending' && $old_status == 'publish' && !$this->get_id()) { |
|
| 1862 | 1862 | $old_status = 'wpi-pending'; |
| 1863 | 1863 | } |
| 1864 | 1864 | |
| 1865 | 1865 | } |
| 1866 | 1866 | |
| 1867 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 1867 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
| 1868 | 1868 | $this->status_transition = array( |
| 1869 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 1869 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
| 1870 | 1870 | 'to' => $new_status, |
| 1871 | 1871 | 'note' => $note, |
| 1872 | 1872 | 'manual' => (bool) $manual_update, |
| 1873 | 1873 | ); |
| 1874 | 1874 | |
| 1875 | - if ( $manual_update ) { |
|
| 1876 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
| 1875 | + if ($manual_update) { |
|
| 1876 | + do_action('getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status); |
|
| 1877 | 1877 | } |
| 1878 | 1878 | |
| 1879 | 1879 | $this->maybe_set_date_paid(); |
@@ -1896,8 +1896,8 @@ discard block |
||
| 1896 | 1896 | */ |
| 1897 | 1897 | public function maybe_set_date_paid() { |
| 1898 | 1898 | |
| 1899 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 1900 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 1899 | + if (!$this->get_date_completed('edit') && $this->is_paid()) { |
|
| 1900 | + $this->set_date_completed(current_time('mysql')); |
|
| 1901 | 1901 | } |
| 1902 | 1902 | } |
| 1903 | 1903 | |
@@ -1906,11 +1906,11 @@ discard block |
||
| 1906 | 1906 | * |
| 1907 | 1907 | * @since 1.0.19 |
| 1908 | 1908 | */ |
| 1909 | - public function set_parent_id( $value ) { |
|
| 1910 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
| 1909 | + public function set_parent_id($value) { |
|
| 1910 | + if ($value && ($value === $this->get_id())) { |
|
| 1911 | 1911 | return; |
| 1912 | 1912 | } |
| 1913 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 1913 | + $this->set_prop('parent_id', absint($value)); |
|
| 1914 | 1914 | } |
| 1915 | 1915 | |
| 1916 | 1916 | /** |
@@ -1918,8 +1918,8 @@ discard block |
||
| 1918 | 1918 | * |
| 1919 | 1919 | * @since 1.0.19 |
| 1920 | 1920 | */ |
| 1921 | - public function set_version( $value ) { |
|
| 1922 | - $this->set_prop( 'version', $value ); |
|
| 1921 | + public function set_version($value) { |
|
| 1922 | + $this->set_prop('version', $value); |
|
| 1923 | 1923 | } |
| 1924 | 1924 | |
| 1925 | 1925 | /** |
@@ -1929,15 +1929,15 @@ discard block |
||
| 1929 | 1929 | * @param string $value Value to set. |
| 1930 | 1930 | * @return bool Whether or not the date was set. |
| 1931 | 1931 | */ |
| 1932 | - public function set_date_created( $value ) { |
|
| 1933 | - $date = strtotime( $value ); |
|
| 1932 | + public function set_date_created($value) { |
|
| 1933 | + $date = strtotime($value); |
|
| 1934 | 1934 | |
| 1935 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 1936 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 1935 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 1936 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
| 1937 | 1937 | return true; |
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | - return $this->set_prop( 'date_created', '' ); |
|
| 1940 | + return $this->set_prop('date_created', ''); |
|
| 1941 | 1941 | |
| 1942 | 1942 | } |
| 1943 | 1943 | |
@@ -1948,15 +1948,15 @@ discard block |
||
| 1948 | 1948 | * @param string $value Value to set. |
| 1949 | 1949 | * @return bool Whether or not the date was set. |
| 1950 | 1950 | */ |
| 1951 | - public function set_due_date( $value ) { |
|
| 1952 | - $date = strtotime( $value ); |
|
| 1951 | + public function set_due_date($value) { |
|
| 1952 | + $date = strtotime($value); |
|
| 1953 | 1953 | |
| 1954 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 1955 | - $this->set_prop( 'due_date', date( 'Y-m-d H:i:s', $date ) ); |
|
| 1954 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 1955 | + $this->set_prop('due_date', date('Y-m-d H:i:s', $date)); |
|
| 1956 | 1956 | return true; |
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | - $this->set_prop( 'due_date', '' ); |
|
| 1959 | + $this->set_prop('due_date', ''); |
|
| 1960 | 1960 | return false; |
| 1961 | 1961 | |
| 1962 | 1962 | } |
@@ -1967,8 +1967,8 @@ discard block |
||
| 1967 | 1967 | * @since 1.0.19 |
| 1968 | 1968 | * @param string $value New name. |
| 1969 | 1969 | */ |
| 1970 | - public function set_date_due( $value ) { |
|
| 1971 | - $this->set_due_date( $value ); |
|
| 1970 | + public function set_date_due($value) { |
|
| 1971 | + $this->set_due_date($value); |
|
| 1972 | 1972 | } |
| 1973 | 1973 | |
| 1974 | 1974 | /** |
@@ -1978,15 +1978,15 @@ discard block |
||
| 1978 | 1978 | * @param string $value Value to set. |
| 1979 | 1979 | * @return bool Whether or not the date was set. |
| 1980 | 1980 | */ |
| 1981 | - public function set_completed_date( $value ) { |
|
| 1982 | - $date = strtotime( $value ); |
|
| 1981 | + public function set_completed_date($value) { |
|
| 1982 | + $date = strtotime($value); |
|
| 1983 | 1983 | |
| 1984 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 1985 | - $this->set_prop( 'completed_date', date( 'Y-m-d H:i:s', $date ) ); |
|
| 1984 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 1985 | + $this->set_prop('completed_date', date('Y-m-d H:i:s', $date)); |
|
| 1986 | 1986 | return true; |
| 1987 | 1987 | } |
| 1988 | 1988 | |
| 1989 | - $this->set_prop( 'completed_date', '' ); |
|
| 1989 | + $this->set_prop('completed_date', ''); |
|
| 1990 | 1990 | return false; |
| 1991 | 1991 | |
| 1992 | 1992 | } |
@@ -1997,8 +1997,8 @@ discard block |
||
| 1997 | 1997 | * @since 1.0.19 |
| 1998 | 1998 | * @param string $value New name. |
| 1999 | 1999 | */ |
| 2000 | - public function set_date_completed( $value ) { |
|
| 2001 | - $this->set_completed_date( $value ); |
|
| 2000 | + public function set_date_completed($value) { |
|
| 2001 | + $this->set_completed_date($value); |
|
| 2002 | 2002 | } |
| 2003 | 2003 | |
| 2004 | 2004 | /** |
@@ -2008,15 +2008,15 @@ discard block |
||
| 2008 | 2008 | * @param string $value Value to set. |
| 2009 | 2009 | * @return bool Whether or not the date was set. |
| 2010 | 2010 | */ |
| 2011 | - public function set_date_modified( $value ) { |
|
| 2012 | - $date = strtotime( $value ); |
|
| 2011 | + public function set_date_modified($value) { |
|
| 2012 | + $date = strtotime($value); |
|
| 2013 | 2013 | |
| 2014 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 2015 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
| 2014 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 2015 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
| 2016 | 2016 | return true; |
| 2017 | 2017 | } |
| 2018 | 2018 | |
| 2019 | - $this->set_prop( 'date_modified', '' ); |
|
| 2019 | + $this->set_prop('date_modified', ''); |
|
| 2020 | 2020 | return false; |
| 2021 | 2021 | |
| 2022 | 2022 | } |
@@ -2027,9 +2027,9 @@ discard block |
||
| 2027 | 2027 | * @since 1.0.19 |
| 2028 | 2028 | * @param string $value New number. |
| 2029 | 2029 | */ |
| 2030 | - public function set_number( $value ) { |
|
| 2031 | - $number = sanitize_text_field( $value ); |
|
| 2032 | - $this->set_prop( 'number', $number ); |
|
| 2030 | + public function set_number($value) { |
|
| 2031 | + $number = sanitize_text_field($value); |
|
| 2032 | + $this->set_prop('number', $number); |
|
| 2033 | 2033 | } |
| 2034 | 2034 | |
| 2035 | 2035 | /** |
@@ -2038,9 +2038,9 @@ discard block |
||
| 2038 | 2038 | * @since 1.0.19 |
| 2039 | 2039 | * @param string $value Type. |
| 2040 | 2040 | */ |
| 2041 | - public function set_type( $value ) { |
|
| 2042 | - $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
|
| 2043 | - $this->set_prop( 'type', $type ); |
|
| 2041 | + public function set_type($value) { |
|
| 2042 | + $type = sanitize_text_field(str_replace('wpi_', '', $value)); |
|
| 2043 | + $this->set_prop('type', $type); |
|
| 2044 | 2044 | } |
| 2045 | 2045 | |
| 2046 | 2046 | /** |
@@ -2049,10 +2049,10 @@ discard block |
||
| 2049 | 2049 | * @since 1.0.19 |
| 2050 | 2050 | * @param string $value Post type. |
| 2051 | 2051 | */ |
| 2052 | - public function set_post_type( $value ) { |
|
| 2053 | - if ( getpaid_is_invoice_post_type( $value ) ) { |
|
| 2054 | - $this->set_type( $value ); |
|
| 2055 | - $this->set_prop( 'post_type', $value ); |
|
| 2052 | + public function set_post_type($value) { |
|
| 2053 | + if (getpaid_is_invoice_post_type($value)) { |
|
| 2054 | + $this->set_type($value); |
|
| 2055 | + $this->set_prop('post_type', $value); |
|
| 2056 | 2056 | } |
| 2057 | 2057 | } |
| 2058 | 2058 | |
@@ -2062,9 +2062,9 @@ discard block |
||
| 2062 | 2062 | * @since 1.0.19 |
| 2063 | 2063 | * @param string $value New key. |
| 2064 | 2064 | */ |
| 2065 | - public function set_key( $value ) { |
|
| 2066 | - $key = sanitize_text_field( $value ); |
|
| 2067 | - $this->set_prop( 'key', $key ); |
|
| 2065 | + public function set_key($value) { |
|
| 2066 | + $key = sanitize_text_field($value); |
|
| 2067 | + $this->set_prop('key', $key); |
|
| 2068 | 2068 | } |
| 2069 | 2069 | |
| 2070 | 2070 | /** |
@@ -2073,9 +2073,9 @@ discard block |
||
| 2073 | 2073 | * @since 1.0.19 |
| 2074 | 2074 | * @param string $value mode. |
| 2075 | 2075 | */ |
| 2076 | - public function set_mode( $value ) { |
|
| 2077 | - if ( ! in_array( $value, array( 'live', 'test' ) ) ) { |
|
| 2078 | - $this->set_prop( 'value', $value ); |
|
| 2076 | + public function set_mode($value) { |
|
| 2077 | + if (!in_array($value, array('live', 'test'))) { |
|
| 2078 | + $this->set_prop('value', $value); |
|
| 2079 | 2079 | } |
| 2080 | 2080 | } |
| 2081 | 2081 | |
@@ -2085,8 +2085,8 @@ discard block |
||
| 2085 | 2085 | * @since 1.0.19 |
| 2086 | 2086 | * @param string $value path. |
| 2087 | 2087 | */ |
| 2088 | - public function set_path( $value ) { |
|
| 2089 | - $this->set_prop( 'path', $value ); |
|
| 2088 | + public function set_path($value) { |
|
| 2089 | + $this->set_prop('path', $value); |
|
| 2090 | 2090 | } |
| 2091 | 2091 | |
| 2092 | 2092 | /** |
@@ -2095,9 +2095,9 @@ discard block |
||
| 2095 | 2095 | * @since 1.0.19 |
| 2096 | 2096 | * @param string $value New name. |
| 2097 | 2097 | */ |
| 2098 | - public function set_name( $value ) { |
|
| 2099 | - $name = sanitize_text_field( $value ); |
|
| 2100 | - $this->set_prop( 'name', $name ); |
|
| 2098 | + public function set_name($value) { |
|
| 2099 | + $name = sanitize_text_field($value); |
|
| 2100 | + $this->set_prop('name', $name); |
|
| 2101 | 2101 | } |
| 2102 | 2102 | |
| 2103 | 2103 | /** |
@@ -2106,8 +2106,8 @@ discard block |
||
| 2106 | 2106 | * @since 1.0.19 |
| 2107 | 2107 | * @param string $value New name. |
| 2108 | 2108 | */ |
| 2109 | - public function set_title( $value ) { |
|
| 2110 | - $this->set_name( $value ); |
|
| 2109 | + public function set_title($value) { |
|
| 2110 | + $this->set_name($value); |
|
| 2111 | 2111 | } |
| 2112 | 2112 | |
| 2113 | 2113 | /** |
@@ -2116,9 +2116,9 @@ discard block |
||
| 2116 | 2116 | * @since 1.0.19 |
| 2117 | 2117 | * @param string $value New description. |
| 2118 | 2118 | */ |
| 2119 | - public function set_description( $value ) { |
|
| 2120 | - $description = wp_kses_post( $value ); |
|
| 2121 | - return $this->set_prop( 'description', $description ); |
|
| 2119 | + public function set_description($value) { |
|
| 2120 | + $description = wp_kses_post($value); |
|
| 2121 | + return $this->set_prop('description', $description); |
|
| 2122 | 2122 | } |
| 2123 | 2123 | |
| 2124 | 2124 | /** |
@@ -2127,8 +2127,8 @@ discard block |
||
| 2127 | 2127 | * @since 1.0.19 |
| 2128 | 2128 | * @param string $value New description. |
| 2129 | 2129 | */ |
| 2130 | - public function set_excerpt( $value ) { |
|
| 2131 | - $this->set_description( $value ); |
|
| 2130 | + public function set_excerpt($value) { |
|
| 2131 | + $this->set_description($value); |
|
| 2132 | 2132 | } |
| 2133 | 2133 | |
| 2134 | 2134 | /** |
@@ -2137,8 +2137,8 @@ discard block |
||
| 2137 | 2137 | * @since 1.0.19 |
| 2138 | 2138 | * @param string $value New description. |
| 2139 | 2139 | */ |
| 2140 | - public function set_summary( $value ) { |
|
| 2141 | - $this->set_description( $value ); |
|
| 2140 | + public function set_summary($value) { |
|
| 2141 | + $this->set_description($value); |
|
| 2142 | 2142 | } |
| 2143 | 2143 | |
| 2144 | 2144 | /** |
@@ -2147,12 +2147,12 @@ discard block |
||
| 2147 | 2147 | * @since 1.0.19 |
| 2148 | 2148 | * @param int $value New author. |
| 2149 | 2149 | */ |
| 2150 | - public function set_author( $value ) { |
|
| 2151 | - $user = get_user_by( 'id', (int) $value ); |
|
| 2150 | + public function set_author($value) { |
|
| 2151 | + $user = get_user_by('id', (int) $value); |
|
| 2152 | 2152 | |
| 2153 | - if ( $user && $user->ID ) { |
|
| 2154 | - $this->set_prop( 'author', $user->ID ); |
|
| 2155 | - $this->set_prop( 'email', $user->user_email ); |
|
| 2153 | + if ($user && $user->ID) { |
|
| 2154 | + $this->set_prop('author', $user->ID); |
|
| 2155 | + $this->set_prop('email', $user->user_email); |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | 2158 | } |
@@ -2163,8 +2163,8 @@ discard block |
||
| 2163 | 2163 | * @since 1.0.19 |
| 2164 | 2164 | * @param int $value New user id. |
| 2165 | 2165 | */ |
| 2166 | - public function set_user_id( $value ) { |
|
| 2167 | - $this->set_author( $value ); |
|
| 2166 | + public function set_user_id($value) { |
|
| 2167 | + $this->set_author($value); |
|
| 2168 | 2168 | } |
| 2169 | 2169 | |
| 2170 | 2170 | /** |
@@ -2173,8 +2173,8 @@ discard block |
||
| 2173 | 2173 | * @since 1.0.19 |
| 2174 | 2174 | * @param int $value New user id. |
| 2175 | 2175 | */ |
| 2176 | - public function set_customer_id( $value ) { |
|
| 2177 | - $this->set_author( $value ); |
|
| 2176 | + public function set_customer_id($value) { |
|
| 2177 | + $this->set_author($value); |
|
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | 2180 | /** |
@@ -2183,8 +2183,8 @@ discard block |
||
| 2183 | 2183 | * @since 1.0.19 |
| 2184 | 2184 | * @param string $value ip address. |
| 2185 | 2185 | */ |
| 2186 | - public function set_ip( $value ) { |
|
| 2187 | - $this->set_prop( 'ip', $value ); |
|
| 2186 | + public function set_ip($value) { |
|
| 2187 | + $this->set_prop('ip', $value); |
|
| 2188 | 2188 | } |
| 2189 | 2189 | |
| 2190 | 2190 | /** |
@@ -2193,8 +2193,8 @@ discard block |
||
| 2193 | 2193 | * @since 1.0.19 |
| 2194 | 2194 | * @param string $value ip address. |
| 2195 | 2195 | */ |
| 2196 | - public function set_user_ip( $value ) { |
|
| 2197 | - $this->set_ip( $value ); |
|
| 2196 | + public function set_user_ip($value) { |
|
| 2197 | + $this->set_ip($value); |
|
| 2198 | 2198 | } |
| 2199 | 2199 | |
| 2200 | 2200 | /** |
@@ -2203,8 +2203,8 @@ discard block |
||
| 2203 | 2203 | * @since 1.0.19 |
| 2204 | 2204 | * @param string $value first name. |
| 2205 | 2205 | */ |
| 2206 | - public function set_first_name( $value ) { |
|
| 2207 | - $this->set_prop( 'first_name', $value ); |
|
| 2206 | + public function set_first_name($value) { |
|
| 2207 | + $this->set_prop('first_name', $value); |
|
| 2208 | 2208 | } |
| 2209 | 2209 | |
| 2210 | 2210 | /** |
@@ -2213,8 +2213,8 @@ discard block |
||
| 2213 | 2213 | * @since 1.0.19 |
| 2214 | 2214 | * @param string $value first name. |
| 2215 | 2215 | */ |
| 2216 | - public function set_user_first_name( $value ) { |
|
| 2217 | - $this->set_first_name( $value ); |
|
| 2216 | + public function set_user_first_name($value) { |
|
| 2217 | + $this->set_first_name($value); |
|
| 2218 | 2218 | } |
| 2219 | 2219 | |
| 2220 | 2220 | /** |
@@ -2223,8 +2223,8 @@ discard block |
||
| 2223 | 2223 | * @since 1.0.19 |
| 2224 | 2224 | * @param string $value first name. |
| 2225 | 2225 | */ |
| 2226 | - public function set_customer_first_name( $value ) { |
|
| 2227 | - $this->set_first_name( $value ); |
|
| 2226 | + public function set_customer_first_name($value) { |
|
| 2227 | + $this->set_first_name($value); |
|
| 2228 | 2228 | } |
| 2229 | 2229 | |
| 2230 | 2230 | /** |
@@ -2233,8 +2233,8 @@ discard block |
||
| 2233 | 2233 | * @since 1.0.19 |
| 2234 | 2234 | * @param string $value last name. |
| 2235 | 2235 | */ |
| 2236 | - public function set_last_name( $value ) { |
|
| 2237 | - $this->set_prop( 'last_name', $value ); |
|
| 2236 | + public function set_last_name($value) { |
|
| 2237 | + $this->set_prop('last_name', $value); |
|
| 2238 | 2238 | } |
| 2239 | 2239 | |
| 2240 | 2240 | /** |
@@ -2243,8 +2243,8 @@ discard block |
||
| 2243 | 2243 | * @since 1.0.19 |
| 2244 | 2244 | * @param string $value last name. |
| 2245 | 2245 | */ |
| 2246 | - public function set_user_last_name( $value ) { |
|
| 2247 | - $this->set_last_name( $value ); |
|
| 2246 | + public function set_user_last_name($value) { |
|
| 2247 | + $this->set_last_name($value); |
|
| 2248 | 2248 | } |
| 2249 | 2249 | |
| 2250 | 2250 | /** |
@@ -2253,8 +2253,8 @@ discard block |
||
| 2253 | 2253 | * @since 1.0.19 |
| 2254 | 2254 | * @param string $value last name. |
| 2255 | 2255 | */ |
| 2256 | - public function set_customer_last_name( $value ) { |
|
| 2257 | - $this->set_last_name( $value ); |
|
| 2256 | + public function set_customer_last_name($value) { |
|
| 2257 | + $this->set_last_name($value); |
|
| 2258 | 2258 | } |
| 2259 | 2259 | |
| 2260 | 2260 | /** |
@@ -2263,8 +2263,8 @@ discard block |
||
| 2263 | 2263 | * @since 1.0.19 |
| 2264 | 2264 | * @param string $value phone. |
| 2265 | 2265 | */ |
| 2266 | - public function set_phone( $value ) { |
|
| 2267 | - $this->set_prop( 'phone', $value ); |
|
| 2266 | + public function set_phone($value) { |
|
| 2267 | + $this->set_prop('phone', $value); |
|
| 2268 | 2268 | } |
| 2269 | 2269 | |
| 2270 | 2270 | /** |
@@ -2273,8 +2273,8 @@ discard block |
||
| 2273 | 2273 | * @since 1.0.19 |
| 2274 | 2274 | * @param string $value phone. |
| 2275 | 2275 | */ |
| 2276 | - public function set_user_phone( $value ) { |
|
| 2277 | - $this->set_phone( $value ); |
|
| 2276 | + public function set_user_phone($value) { |
|
| 2277 | + $this->set_phone($value); |
|
| 2278 | 2278 | } |
| 2279 | 2279 | |
| 2280 | 2280 | /** |
@@ -2283,8 +2283,8 @@ discard block |
||
| 2283 | 2283 | * @since 1.0.19 |
| 2284 | 2284 | * @param string $value phone. |
| 2285 | 2285 | */ |
| 2286 | - public function set_customer_phone( $value ) { |
|
| 2287 | - $this->set_phone( $value ); |
|
| 2286 | + public function set_customer_phone($value) { |
|
| 2287 | + $this->set_phone($value); |
|
| 2288 | 2288 | } |
| 2289 | 2289 | |
| 2290 | 2290 | /** |
@@ -2293,8 +2293,8 @@ discard block |
||
| 2293 | 2293 | * @since 1.0.19 |
| 2294 | 2294 | * @param string $value phone. |
| 2295 | 2295 | */ |
| 2296 | - public function set_phone_number( $value ) { |
|
| 2297 | - $this->set_phone( $value ); |
|
| 2296 | + public function set_phone_number($value) { |
|
| 2297 | + $this->set_phone($value); |
|
| 2298 | 2298 | } |
| 2299 | 2299 | |
| 2300 | 2300 | /** |
@@ -2303,8 +2303,8 @@ discard block |
||
| 2303 | 2303 | * @since 1.0.19 |
| 2304 | 2304 | * @param string $value email address. |
| 2305 | 2305 | */ |
| 2306 | - public function set_email( $value ) { |
|
| 2307 | - $this->set_prop( 'email', $value ); |
|
| 2306 | + public function set_email($value) { |
|
| 2307 | + $this->set_prop('email', $value); |
|
| 2308 | 2308 | } |
| 2309 | 2309 | |
| 2310 | 2310 | /** |
@@ -2313,8 +2313,8 @@ discard block |
||
| 2313 | 2313 | * @since 1.0.19 |
| 2314 | 2314 | * @param string $value email address. |
| 2315 | 2315 | */ |
| 2316 | - public function set_user_email( $value ) { |
|
| 2317 | - $this->set_email( $value ); |
|
| 2316 | + public function set_user_email($value) { |
|
| 2317 | + $this->set_email($value); |
|
| 2318 | 2318 | } |
| 2319 | 2319 | |
| 2320 | 2320 | /** |
@@ -2323,8 +2323,8 @@ discard block |
||
| 2323 | 2323 | * @since 1.0.19 |
| 2324 | 2324 | * @param string $value email address. |
| 2325 | 2325 | */ |
| 2326 | - public function set_email_address( $value ) { |
|
| 2327 | - $this->set_email( $value ); |
|
| 2326 | + public function set_email_address($value) { |
|
| 2327 | + $this->set_email($value); |
|
| 2328 | 2328 | } |
| 2329 | 2329 | |
| 2330 | 2330 | /** |
@@ -2333,8 +2333,8 @@ discard block |
||
| 2333 | 2333 | * @since 1.0.19 |
| 2334 | 2334 | * @param string $value email address. |
| 2335 | 2335 | */ |
| 2336 | - public function set_customer_email( $value ) { |
|
| 2337 | - $this->set_email( $value ); |
|
| 2336 | + public function set_customer_email($value) { |
|
| 2337 | + $this->set_email($value); |
|
| 2338 | 2338 | } |
| 2339 | 2339 | |
| 2340 | 2340 | /** |
@@ -2343,8 +2343,8 @@ discard block |
||
| 2343 | 2343 | * @since 1.0.19 |
| 2344 | 2344 | * @param string $value country. |
| 2345 | 2345 | */ |
| 2346 | - public function set_country( $value ) { |
|
| 2347 | - $this->set_prop( 'country', $value ); |
|
| 2346 | + public function set_country($value) { |
|
| 2347 | + $this->set_prop('country', $value); |
|
| 2348 | 2348 | } |
| 2349 | 2349 | |
| 2350 | 2350 | /** |
@@ -2353,8 +2353,8 @@ discard block |
||
| 2353 | 2353 | * @since 1.0.19 |
| 2354 | 2354 | * @param string $value country. |
| 2355 | 2355 | */ |
| 2356 | - public function set_user_country( $value ) { |
|
| 2357 | - $this->set_country( $value ); |
|
| 2356 | + public function set_user_country($value) { |
|
| 2357 | + $this->set_country($value); |
|
| 2358 | 2358 | } |
| 2359 | 2359 | |
| 2360 | 2360 | /** |
@@ -2363,8 +2363,8 @@ discard block |
||
| 2363 | 2363 | * @since 1.0.19 |
| 2364 | 2364 | * @param string $value country. |
| 2365 | 2365 | */ |
| 2366 | - public function set_customer_country( $value ) { |
|
| 2367 | - $this->set_country( $value ); |
|
| 2366 | + public function set_customer_country($value) { |
|
| 2367 | + $this->set_country($value); |
|
| 2368 | 2368 | } |
| 2369 | 2369 | |
| 2370 | 2370 | /** |
@@ -2373,8 +2373,8 @@ discard block |
||
| 2373 | 2373 | * @since 1.0.19 |
| 2374 | 2374 | * @param string $value state. |
| 2375 | 2375 | */ |
| 2376 | - public function set_state( $value ) { |
|
| 2377 | - $this->set_prop( 'state', $value ); |
|
| 2376 | + public function set_state($value) { |
|
| 2377 | + $this->set_prop('state', $value); |
|
| 2378 | 2378 | } |
| 2379 | 2379 | |
| 2380 | 2380 | /** |
@@ -2383,8 +2383,8 @@ discard block |
||
| 2383 | 2383 | * @since 1.0.19 |
| 2384 | 2384 | * @param string $value state. |
| 2385 | 2385 | */ |
| 2386 | - public function set_user_state( $value ) { |
|
| 2387 | - $this->set_state( $value ); |
|
| 2386 | + public function set_user_state($value) { |
|
| 2387 | + $this->set_state($value); |
|
| 2388 | 2388 | } |
| 2389 | 2389 | |
| 2390 | 2390 | /** |
@@ -2393,8 +2393,8 @@ discard block |
||
| 2393 | 2393 | * @since 1.0.19 |
| 2394 | 2394 | * @param string $value state. |
| 2395 | 2395 | */ |
| 2396 | - public function set_customer_state( $value ) { |
|
| 2397 | - $this->set_state( $value ); |
|
| 2396 | + public function set_customer_state($value) { |
|
| 2397 | + $this->set_state($value); |
|
| 2398 | 2398 | } |
| 2399 | 2399 | |
| 2400 | 2400 | /** |
@@ -2403,8 +2403,8 @@ discard block |
||
| 2403 | 2403 | * @since 1.0.19 |
| 2404 | 2404 | * @param string $value city. |
| 2405 | 2405 | */ |
| 2406 | - public function set_city( $value ) { |
|
| 2407 | - $this->set_prop( 'city', $value ); |
|
| 2406 | + public function set_city($value) { |
|
| 2407 | + $this->set_prop('city', $value); |
|
| 2408 | 2408 | } |
| 2409 | 2409 | |
| 2410 | 2410 | /** |
@@ -2413,8 +2413,8 @@ discard block |
||
| 2413 | 2413 | * @since 1.0.19 |
| 2414 | 2414 | * @param string $value city. |
| 2415 | 2415 | */ |
| 2416 | - public function set_user_city( $value ) { |
|
| 2417 | - $this->set_city( $value ); |
|
| 2416 | + public function set_user_city($value) { |
|
| 2417 | + $this->set_city($value); |
|
| 2418 | 2418 | } |
| 2419 | 2419 | |
| 2420 | 2420 | /** |
@@ -2423,8 +2423,8 @@ discard block |
||
| 2423 | 2423 | * @since 1.0.19 |
| 2424 | 2424 | * @param string $value city. |
| 2425 | 2425 | */ |
| 2426 | - public function set_customer_city( $value ) { |
|
| 2427 | - $this->set_city( $value ); |
|
| 2426 | + public function set_customer_city($value) { |
|
| 2427 | + $this->set_city($value); |
|
| 2428 | 2428 | } |
| 2429 | 2429 | |
| 2430 | 2430 | /** |
@@ -2433,8 +2433,8 @@ discard block |
||
| 2433 | 2433 | * @since 1.0.19 |
| 2434 | 2434 | * @param string $value zip. |
| 2435 | 2435 | */ |
| 2436 | - public function set_zip( $value ) { |
|
| 2437 | - $this->set_prop( 'zip', $value ); |
|
| 2436 | + public function set_zip($value) { |
|
| 2437 | + $this->set_prop('zip', $value); |
|
| 2438 | 2438 | } |
| 2439 | 2439 | |
| 2440 | 2440 | /** |
@@ -2443,8 +2443,8 @@ discard block |
||
| 2443 | 2443 | * @since 1.0.19 |
| 2444 | 2444 | * @param string $value zip. |
| 2445 | 2445 | */ |
| 2446 | - public function set_user_zip( $value ) { |
|
| 2447 | - $this->set_zip( $value ); |
|
| 2446 | + public function set_user_zip($value) { |
|
| 2447 | + $this->set_zip($value); |
|
| 2448 | 2448 | } |
| 2449 | 2449 | |
| 2450 | 2450 | /** |
@@ -2453,8 +2453,8 @@ discard block |
||
| 2453 | 2453 | * @since 1.0.19 |
| 2454 | 2454 | * @param string $value zip. |
| 2455 | 2455 | */ |
| 2456 | - public function set_customer_zip( $value ) { |
|
| 2457 | - $this->set_zip( $value ); |
|
| 2456 | + public function set_customer_zip($value) { |
|
| 2457 | + $this->set_zip($value); |
|
| 2458 | 2458 | } |
| 2459 | 2459 | |
| 2460 | 2460 | /** |
@@ -2463,8 +2463,8 @@ discard block |
||
| 2463 | 2463 | * @since 1.0.19 |
| 2464 | 2464 | * @param string $value company. |
| 2465 | 2465 | */ |
| 2466 | - public function set_company( $value ) { |
|
| 2467 | - $this->set_prop( 'company', $value ); |
|
| 2466 | + public function set_company($value) { |
|
| 2467 | + $this->set_prop('company', $value); |
|
| 2468 | 2468 | } |
| 2469 | 2469 | |
| 2470 | 2470 | /** |
@@ -2473,8 +2473,8 @@ discard block |
||
| 2473 | 2473 | * @since 1.0.19 |
| 2474 | 2474 | * @param string $value company. |
| 2475 | 2475 | */ |
| 2476 | - public function set_user_company( $value ) { |
|
| 2477 | - $this->set_company( $value ); |
|
| 2476 | + public function set_user_company($value) { |
|
| 2477 | + $this->set_company($value); |
|
| 2478 | 2478 | } |
| 2479 | 2479 | |
| 2480 | 2480 | /** |
@@ -2483,8 +2483,8 @@ discard block |
||
| 2483 | 2483 | * @since 1.0.19 |
| 2484 | 2484 | * @param string $value company. |
| 2485 | 2485 | */ |
| 2486 | - public function set_customer_company( $value ) { |
|
| 2487 | - $this->set_company( $value ); |
|
| 2486 | + public function set_customer_company($value) { |
|
| 2487 | + $this->set_company($value); |
|
| 2488 | 2488 | } |
| 2489 | 2489 | |
| 2490 | 2490 | /** |
@@ -2493,8 +2493,8 @@ discard block |
||
| 2493 | 2493 | * @since 1.0.19 |
| 2494 | 2494 | * @param string $value var number. |
| 2495 | 2495 | */ |
| 2496 | - public function set_vat_number( $value ) { |
|
| 2497 | - $this->set_prop( 'vat_number', $value ); |
|
| 2496 | + public function set_vat_number($value) { |
|
| 2497 | + $this->set_prop('vat_number', $value); |
|
| 2498 | 2498 | } |
| 2499 | 2499 | |
| 2500 | 2500 | /** |
@@ -2503,8 +2503,8 @@ discard block |
||
| 2503 | 2503 | * @since 1.0.19 |
| 2504 | 2504 | * @param string $value var number. |
| 2505 | 2505 | */ |
| 2506 | - public function set_user_vat_number( $value ) { |
|
| 2507 | - $this->set_vat_number( $value ); |
|
| 2506 | + public function set_user_vat_number($value) { |
|
| 2507 | + $this->set_vat_number($value); |
|
| 2508 | 2508 | } |
| 2509 | 2509 | |
| 2510 | 2510 | /** |
@@ -2513,8 +2513,8 @@ discard block |
||
| 2513 | 2513 | * @since 1.0.19 |
| 2514 | 2514 | * @param string $value var number. |
| 2515 | 2515 | */ |
| 2516 | - public function set_customer_vat_number( $value ) { |
|
| 2517 | - $this->set_vat_number( $value ); |
|
| 2516 | + public function set_customer_vat_number($value) { |
|
| 2517 | + $this->set_vat_number($value); |
|
| 2518 | 2518 | } |
| 2519 | 2519 | |
| 2520 | 2520 | /** |
@@ -2523,8 +2523,8 @@ discard block |
||
| 2523 | 2523 | * @since 1.0.19 |
| 2524 | 2524 | * @param string $value var rate. |
| 2525 | 2525 | */ |
| 2526 | - public function set_vat_rate( $value ) { |
|
| 2527 | - $this->set_prop( 'vat_rate', $value ); |
|
| 2526 | + public function set_vat_rate($value) { |
|
| 2527 | + $this->set_prop('vat_rate', $value); |
|
| 2528 | 2528 | } |
| 2529 | 2529 | |
| 2530 | 2530 | /** |
@@ -2533,8 +2533,8 @@ discard block |
||
| 2533 | 2533 | * @since 1.0.19 |
| 2534 | 2534 | * @param string $value var number. |
| 2535 | 2535 | */ |
| 2536 | - public function set_user_vat_rate( $value ) { |
|
| 2537 | - $this->set_vat_rate( $value ); |
|
| 2536 | + public function set_user_vat_rate($value) { |
|
| 2537 | + $this->set_vat_rate($value); |
|
| 2538 | 2538 | } |
| 2539 | 2539 | |
| 2540 | 2540 | /** |
@@ -2543,8 +2543,8 @@ discard block |
||
| 2543 | 2543 | * @since 1.0.19 |
| 2544 | 2544 | * @param string $value var number. |
| 2545 | 2545 | */ |
| 2546 | - public function set_customer_vat_rate( $value ) { |
|
| 2547 | - $this->set_vat_rate( $value ); |
|
| 2546 | + public function set_customer_vat_rate($value) { |
|
| 2547 | + $this->set_vat_rate($value); |
|
| 2548 | 2548 | } |
| 2549 | 2549 | |
| 2550 | 2550 | /** |
@@ -2553,8 +2553,8 @@ discard block |
||
| 2553 | 2553 | * @since 1.0.19 |
| 2554 | 2554 | * @param string $value address. |
| 2555 | 2555 | */ |
| 2556 | - public function set_address( $value ) { |
|
| 2557 | - $this->set_prop( 'address', $value ); |
|
| 2556 | + public function set_address($value) { |
|
| 2557 | + $this->set_prop('address', $value); |
|
| 2558 | 2558 | } |
| 2559 | 2559 | |
| 2560 | 2560 | /** |
@@ -2563,8 +2563,8 @@ discard block |
||
| 2563 | 2563 | * @since 1.0.19 |
| 2564 | 2564 | * @param string $value address. |
| 2565 | 2565 | */ |
| 2566 | - public function set_user_address( $value ) { |
|
| 2567 | - $this->set_address( $value ); |
|
| 2566 | + public function set_user_address($value) { |
|
| 2567 | + $this->set_address($value); |
|
| 2568 | 2568 | } |
| 2569 | 2569 | |
| 2570 | 2570 | /** |
@@ -2573,8 +2573,8 @@ discard block |
||
| 2573 | 2573 | * @since 1.0.19 |
| 2574 | 2574 | * @param string $value address. |
| 2575 | 2575 | */ |
| 2576 | - public function set_customer_address( $value ) { |
|
| 2577 | - $this->set_address( $value ); |
|
| 2576 | + public function set_customer_address($value) { |
|
| 2577 | + $this->set_address($value); |
|
| 2578 | 2578 | } |
| 2579 | 2579 | |
| 2580 | 2580 | /** |
@@ -2583,8 +2583,8 @@ discard block |
||
| 2583 | 2583 | * @since 1.0.19 |
| 2584 | 2584 | * @param int|bool $value confirmed. |
| 2585 | 2585 | */ |
| 2586 | - public function set_is_viewed( $value ) { |
|
| 2587 | - $this->set_prop( 'is_viewed', $value ); |
|
| 2586 | + public function set_is_viewed($value) { |
|
| 2587 | + $this->set_prop('is_viewed', $value); |
|
| 2588 | 2588 | } |
| 2589 | 2589 | |
| 2590 | 2590 | /** |
@@ -2593,8 +2593,8 @@ discard block |
||
| 2593 | 2593 | * @since 1.0.19 |
| 2594 | 2594 | * @param string $value email recipients. |
| 2595 | 2595 | */ |
| 2596 | - public function set_email_cc( $value ) { |
|
| 2597 | - $this->set_prop( 'email_cc', $value ); |
|
| 2596 | + public function set_email_cc($value) { |
|
| 2597 | + $this->set_prop('email_cc', $value); |
|
| 2598 | 2598 | } |
| 2599 | 2599 | |
| 2600 | 2600 | /** |
@@ -2603,9 +2603,9 @@ discard block |
||
| 2603 | 2603 | * @since 1.0.19 |
| 2604 | 2604 | * @param string $value email recipients. |
| 2605 | 2605 | */ |
| 2606 | - public function set_template( $value ) { |
|
| 2607 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2608 | - $this->set_prop( 'template', $value ); |
|
| 2606 | + public function set_template($value) { |
|
| 2607 | + if (in_array($value, array('quantity', 'hours', 'amount'))) { |
|
| 2608 | + $this->set_prop('template', $value); |
|
| 2609 | 2609 | } |
| 2610 | 2610 | } |
| 2611 | 2611 | |
@@ -2615,8 +2615,8 @@ discard block |
||
| 2615 | 2615 | * @since 1.0.19 |
| 2616 | 2616 | * @param int|bool $value confirmed. |
| 2617 | 2617 | */ |
| 2618 | - public function set_address_confirmed( $value ) { |
|
| 2619 | - $this->set_prop( 'address_confirmed', $value ); |
|
| 2618 | + public function set_address_confirmed($value) { |
|
| 2619 | + $this->set_prop('address_confirmed', $value); |
|
| 2620 | 2620 | } |
| 2621 | 2621 | |
| 2622 | 2622 | /** |
@@ -2625,8 +2625,8 @@ discard block |
||
| 2625 | 2625 | * @since 1.0.19 |
| 2626 | 2626 | * @param int|bool $value confirmed. |
| 2627 | 2627 | */ |
| 2628 | - public function set_user_address_confirmed( $value ) { |
|
| 2629 | - $this->set_address_confirmed( $value ); |
|
| 2628 | + public function set_user_address_confirmed($value) { |
|
| 2629 | + $this->set_address_confirmed($value); |
|
| 2630 | 2630 | } |
| 2631 | 2631 | |
| 2632 | 2632 | /** |
@@ -2635,8 +2635,8 @@ discard block |
||
| 2635 | 2635 | * @since 1.0.19 |
| 2636 | 2636 | * @param int|bool $value confirmed. |
| 2637 | 2637 | */ |
| 2638 | - public function set_customer_address_confirmed( $value ) { |
|
| 2639 | - $this->set_address_confirmed( $value ); |
|
| 2638 | + public function set_customer_address_confirmed($value) { |
|
| 2639 | + $this->set_address_confirmed($value); |
|
| 2640 | 2640 | } |
| 2641 | 2641 | |
| 2642 | 2642 | /** |
@@ -2645,8 +2645,8 @@ discard block |
||
| 2645 | 2645 | * @since 1.0.19 |
| 2646 | 2646 | * @param float $value sub total. |
| 2647 | 2647 | */ |
| 2648 | - public function set_subtotal( $value ) { |
|
| 2649 | - $this->set_prop( 'subtotal', $value ); |
|
| 2648 | + public function set_subtotal($value) { |
|
| 2649 | + $this->set_prop('subtotal', $value); |
|
| 2650 | 2650 | } |
| 2651 | 2651 | |
| 2652 | 2652 | /** |
@@ -2655,8 +2655,8 @@ discard block |
||
| 2655 | 2655 | * @since 1.0.19 |
| 2656 | 2656 | * @param float $value discount total. |
| 2657 | 2657 | */ |
| 2658 | - public function set_total_discount( $value ) { |
|
| 2659 | - $this->set_prop( 'total_discount', $value ); |
|
| 2658 | + public function set_total_discount($value) { |
|
| 2659 | + $this->set_prop('total_discount', $value); |
|
| 2660 | 2660 | } |
| 2661 | 2661 | |
| 2662 | 2662 | /** |
@@ -2665,8 +2665,8 @@ discard block |
||
| 2665 | 2665 | * @since 1.0.19 |
| 2666 | 2666 | * @param float $value discount total. |
| 2667 | 2667 | */ |
| 2668 | - public function set_discount( $value ) { |
|
| 2669 | - $this->set_total_discount( $value ); |
|
| 2668 | + public function set_discount($value) { |
|
| 2669 | + $this->set_total_discount($value); |
|
| 2670 | 2670 | } |
| 2671 | 2671 | |
| 2672 | 2672 | /** |
@@ -2675,8 +2675,8 @@ discard block |
||
| 2675 | 2675 | * @since 1.0.19 |
| 2676 | 2676 | * @param float $value tax total. |
| 2677 | 2677 | */ |
| 2678 | - public function set_total_tax( $value ) { |
|
| 2679 | - $this->set_prop( 'total_tax', $value ); |
|
| 2678 | + public function set_total_tax($value) { |
|
| 2679 | + $this->set_prop('total_tax', $value); |
|
| 2680 | 2680 | } |
| 2681 | 2681 | |
| 2682 | 2682 | /** |
@@ -2685,8 +2685,8 @@ discard block |
||
| 2685 | 2685 | * @since 1.0.19 |
| 2686 | 2686 | * @param float $value tax total. |
| 2687 | 2687 | */ |
| 2688 | - public function set_tax_total( $value ) { |
|
| 2689 | - $this->set_total_tax( $value ); |
|
| 2688 | + public function set_tax_total($value) { |
|
| 2689 | + $this->set_total_tax($value); |
|
| 2690 | 2690 | } |
| 2691 | 2691 | |
| 2692 | 2692 | /** |
@@ -2695,8 +2695,8 @@ discard block |
||
| 2695 | 2695 | * @since 1.0.19 |
| 2696 | 2696 | * @param float $value fees total. |
| 2697 | 2697 | */ |
| 2698 | - public function set_total_fees( $value ) { |
|
| 2699 | - $this->set_prop( 'total_fees', $value ); |
|
| 2698 | + public function set_total_fees($value) { |
|
| 2699 | + $this->set_prop('total_fees', $value); |
|
| 2700 | 2700 | } |
| 2701 | 2701 | |
| 2702 | 2702 | /** |
@@ -2705,8 +2705,8 @@ discard block |
||
| 2705 | 2705 | * @since 1.0.19 |
| 2706 | 2706 | * @param float $value fees total. |
| 2707 | 2707 | */ |
| 2708 | - public function set_fees_total( $value ) { |
|
| 2709 | - $this->set_total_fees( $value ); |
|
| 2708 | + public function set_fees_total($value) { |
|
| 2709 | + $this->set_total_fees($value); |
|
| 2710 | 2710 | } |
| 2711 | 2711 | |
| 2712 | 2712 | /** |
@@ -2715,18 +2715,18 @@ discard block |
||
| 2715 | 2715 | * @since 1.0.19 |
| 2716 | 2716 | * @param array $value fees. |
| 2717 | 2717 | */ |
| 2718 | - public function set_fees( $value ) { |
|
| 2718 | + public function set_fees($value) { |
|
| 2719 | 2719 | |
| 2720 | - $this->set_prop( 'fees', array() ); |
|
| 2720 | + $this->set_prop('fees', array()); |
|
| 2721 | 2721 | |
| 2722 | 2722 | // Ensure that we have an array. |
| 2723 | - if ( ! is_array( $value ) ) { |
|
| 2723 | + if (!is_array($value)) { |
|
| 2724 | 2724 | return; |
| 2725 | 2725 | } |
| 2726 | 2726 | |
| 2727 | - foreach ( $value as $name => $data ) { |
|
| 2728 | - if ( isset( $data['amount'] ) ) { |
|
| 2729 | - $this->add_fee( $name, $data['amount'], $data['recurring'] ); |
|
| 2727 | + foreach ($value as $name => $data) { |
|
| 2728 | + if (isset($data['amount'])) { |
|
| 2729 | + $this->add_fee($name, $data['amount'], $data['recurring']); |
|
| 2730 | 2730 | } |
| 2731 | 2731 | } |
| 2732 | 2732 | |
@@ -2738,8 +2738,8 @@ discard block |
||
| 2738 | 2738 | * @since 1.0.19 |
| 2739 | 2739 | * @param array $value taxes. |
| 2740 | 2740 | */ |
| 2741 | - public function set_taxes( $value ) { |
|
| 2742 | - $this->set_prop( 'taxes', $value ); |
|
| 2741 | + public function set_taxes($value) { |
|
| 2742 | + $this->set_prop('taxes', $value); |
|
| 2743 | 2743 | } |
| 2744 | 2744 | |
| 2745 | 2745 | /** |
@@ -2748,17 +2748,17 @@ discard block |
||
| 2748 | 2748 | * @since 1.0.19 |
| 2749 | 2749 | * @param array $value discounts. |
| 2750 | 2750 | */ |
| 2751 | - public function set_discounts( $value ) { |
|
| 2752 | - $this->set_prop( 'discounts', array() ); |
|
| 2751 | + public function set_discounts($value) { |
|
| 2752 | + $this->set_prop('discounts', array()); |
|
| 2753 | 2753 | |
| 2754 | 2754 | // Ensure that we have an array. |
| 2755 | - if ( ! is_array( $value ) ) { |
|
| 2755 | + if (!is_array($value)) { |
|
| 2756 | 2756 | return; |
| 2757 | 2757 | } |
| 2758 | 2758 | |
| 2759 | - foreach ( $value as $name => $data ) { |
|
| 2760 | - if ( isset( $data['amount'] ) ) { |
|
| 2761 | - $this->add_discount( $name, $data['amount'], $data['recurring'] ); |
|
| 2759 | + foreach ($value as $name => $data) { |
|
| 2760 | + if (isset($data['amount'])) { |
|
| 2761 | + $this->add_discount($name, $data['amount'], $data['recurring']); |
|
| 2762 | 2762 | } |
| 2763 | 2763 | } |
| 2764 | 2764 | } |
@@ -2769,18 +2769,18 @@ discard block |
||
| 2769 | 2769 | * @since 1.0.19 |
| 2770 | 2770 | * @param GetPaid_Form_Item[] $value items. |
| 2771 | 2771 | */ |
| 2772 | - public function set_items( $value ) { |
|
| 2772 | + public function set_items($value) { |
|
| 2773 | 2773 | |
| 2774 | 2774 | // Remove existing items. |
| 2775 | - $this->set_prop( 'items', array() ); |
|
| 2775 | + $this->set_prop('items', array()); |
|
| 2776 | 2776 | |
| 2777 | 2777 | // Ensure that we have an array. |
| 2778 | - if ( ! is_array( $value ) ) { |
|
| 2778 | + if (!is_array($value)) { |
|
| 2779 | 2779 | return; |
| 2780 | 2780 | } |
| 2781 | 2781 | |
| 2782 | - foreach ( $value as $item ) { |
|
| 2783 | - $this->add_item( $item ); |
|
| 2782 | + foreach ($value as $item) { |
|
| 2783 | + $this->add_item($item); |
|
| 2784 | 2784 | } |
| 2785 | 2785 | |
| 2786 | 2786 | } |
@@ -2791,8 +2791,8 @@ discard block |
||
| 2791 | 2791 | * @since 1.0.19 |
| 2792 | 2792 | * @param int $value payment form. |
| 2793 | 2793 | */ |
| 2794 | - public function set_payment_form( $value ) { |
|
| 2795 | - $this->set_prop( 'payment_form', $value ); |
|
| 2794 | + public function set_payment_form($value) { |
|
| 2795 | + $this->set_prop('payment_form', $value); |
|
| 2796 | 2796 | } |
| 2797 | 2797 | |
| 2798 | 2798 | /** |
@@ -2801,8 +2801,8 @@ discard block |
||
| 2801 | 2801 | * @since 1.0.19 |
| 2802 | 2802 | * @param string $value submission id. |
| 2803 | 2803 | */ |
| 2804 | - public function set_submission_id( $value ) { |
|
| 2805 | - $this->set_prop( 'submission_id', $value ); |
|
| 2804 | + public function set_submission_id($value) { |
|
| 2805 | + $this->set_prop('submission_id', $value); |
|
| 2806 | 2806 | } |
| 2807 | 2807 | |
| 2808 | 2808 | /** |
@@ -2811,8 +2811,8 @@ discard block |
||
| 2811 | 2811 | * @since 1.0.19 |
| 2812 | 2812 | * @param string $value discount code. |
| 2813 | 2813 | */ |
| 2814 | - public function set_discount_code( $value ) { |
|
| 2815 | - $this->set_prop( 'discount_code', $value ); |
|
| 2814 | + public function set_discount_code($value) { |
|
| 2815 | + $this->set_prop('discount_code', $value); |
|
| 2816 | 2816 | } |
| 2817 | 2817 | |
| 2818 | 2818 | /** |
@@ -2821,8 +2821,8 @@ discard block |
||
| 2821 | 2821 | * @since 1.0.19 |
| 2822 | 2822 | * @param string $value gateway. |
| 2823 | 2823 | */ |
| 2824 | - public function set_gateway( $value ) { |
|
| 2825 | - $this->set_prop( 'gateway', $value ); |
|
| 2824 | + public function set_gateway($value) { |
|
| 2825 | + $this->set_prop('gateway', $value); |
|
| 2826 | 2826 | } |
| 2827 | 2827 | |
| 2828 | 2828 | /** |
@@ -2831,9 +2831,9 @@ discard block |
||
| 2831 | 2831 | * @since 1.0.19 |
| 2832 | 2832 | * @param string $value transaction id. |
| 2833 | 2833 | */ |
| 2834 | - public function set_transaction_id( $value ) { |
|
| 2835 | - if ( ! empty( $value ) ) { |
|
| 2836 | - $this->set_prop( 'transaction_id', $value ); |
|
| 2834 | + public function set_transaction_id($value) { |
|
| 2835 | + if (!empty($value)) { |
|
| 2836 | + $this->set_prop('transaction_id', $value); |
|
| 2837 | 2837 | } |
| 2838 | 2838 | } |
| 2839 | 2839 | |
@@ -2843,8 +2843,8 @@ discard block |
||
| 2843 | 2843 | * @since 1.0.19 |
| 2844 | 2844 | * @param string $value currency id. |
| 2845 | 2845 | */ |
| 2846 | - public function set_currency( $value ) { |
|
| 2847 | - $this->set_prop( 'currency', $value ); |
|
| 2846 | + public function set_currency($value) { |
|
| 2847 | + $this->set_prop('currency', $value); |
|
| 2848 | 2848 | } |
| 2849 | 2849 | |
| 2850 | 2850 | /** |
@@ -2853,8 +2853,8 @@ discard block |
||
| 2853 | 2853 | * @since 1.0.19 |
| 2854 | 2854 | * @param bool $value value. |
| 2855 | 2855 | */ |
| 2856 | - public function set_disable_taxes( $value ) { |
|
| 2857 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 2856 | + public function set_disable_taxes($value) { |
|
| 2857 | + $this->set_prop('disable_taxes', (bool) $value); |
|
| 2858 | 2858 | } |
| 2859 | 2859 | |
| 2860 | 2860 | /** |
@@ -2863,8 +2863,8 @@ discard block |
||
| 2863 | 2863 | * @since 1.0.19 |
| 2864 | 2864 | * @param string $value subscription id. |
| 2865 | 2865 | */ |
| 2866 | - public function set_subscription_id( $value ) { |
|
| 2867 | - $this->set_prop( 'subscription_id', $value ); |
|
| 2866 | + public function set_subscription_id($value) { |
|
| 2867 | + $this->set_prop('subscription_id', $value); |
|
| 2868 | 2868 | } |
| 2869 | 2869 | |
| 2870 | 2870 | /* |
@@ -2881,28 +2881,28 @@ discard block |
||
| 2881 | 2881 | */ |
| 2882 | 2882 | public function is_parent() { |
| 2883 | 2883 | $parent = $this->get_parent_id(); |
| 2884 | - return apply_filters( 'wpinv_invoice_is_parent', empty( $parent ), $this ); |
|
| 2884 | + return apply_filters('wpinv_invoice_is_parent', empty($parent), $this); |
|
| 2885 | 2885 | } |
| 2886 | 2886 | |
| 2887 | 2887 | /** |
| 2888 | 2888 | * Checks if this is a renewal invoice. |
| 2889 | 2889 | */ |
| 2890 | 2890 | public function is_renewal() { |
| 2891 | - return ! $this->is_parent(); |
|
| 2891 | + return !$this->is_parent(); |
|
| 2892 | 2892 | } |
| 2893 | 2893 | |
| 2894 | 2894 | /** |
| 2895 | 2895 | * Checks if this is a recurring invoice. |
| 2896 | 2896 | */ |
| 2897 | 2897 | public function is_recurring() { |
| 2898 | - return $this->is_renewal() || ! empty( $this->recurring_item ); |
|
| 2898 | + return $this->is_renewal() || !empty($this->recurring_item); |
|
| 2899 | 2899 | } |
| 2900 | 2900 | |
| 2901 | 2901 | /** |
| 2902 | 2902 | * Checks if this is a taxable invoice. |
| 2903 | 2903 | */ |
| 2904 | 2904 | public function is_taxable() { |
| 2905 | - return ! $this->get_disable_taxes(); |
|
| 2905 | + return !$this->get_disable_taxes(); |
|
| 2906 | 2906 | } |
| 2907 | 2907 | |
| 2908 | 2908 | /** |
@@ -2913,57 +2913,57 @@ discard block |
||
| 2913 | 2913 | |
| 2914 | 2914 | $requires_vat = false; |
| 2915 | 2915 | |
| 2916 | - if ( $this->country ) { |
|
| 2916 | + if ($this->country) { |
|
| 2917 | 2917 | $wpi_country = $this->country; |
| 2918 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
| 2918 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
| 2919 | 2919 | } |
| 2920 | 2920 | |
| 2921 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
| 2921 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
| 2922 | 2922 | } |
| 2923 | 2923 | |
| 2924 | 2924 | /** |
| 2925 | 2925 | * Checks to see if the invoice requires payment. |
| 2926 | 2926 | */ |
| 2927 | 2927 | public function is_free() { |
| 2928 | - $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
|
| 2928 | + $is_free = ((float) wpinv_round_amount($this->get_initial_total()) == 0); |
|
| 2929 | 2929 | |
| 2930 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 2930 | + if ($this->is_recurring() && $this->get_recurring_total() > 0) { |
|
| 2931 | 2931 | $is_free = false; |
| 2932 | 2932 | } |
| 2933 | 2933 | |
| 2934 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
| 2934 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
| 2935 | 2935 | } |
| 2936 | 2936 | |
| 2937 | 2937 | /** |
| 2938 | 2938 | * Checks if the invoice is paid. |
| 2939 | 2939 | */ |
| 2940 | 2940 | public function is_paid() { |
| 2941 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
| 2942 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
| 2941 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
| 2942 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
| 2943 | 2943 | } |
| 2944 | 2944 | |
| 2945 | 2945 | /** |
| 2946 | 2946 | * Checks if the invoice needs payment. |
| 2947 | 2947 | */ |
| 2948 | 2948 | public function needs_payment() { |
| 2949 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 2950 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
|
| 2949 | + $needs_payment = !$this->is_paid() && !$this->is_refunded() && !$this->is_free(); |
|
| 2950 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this); |
|
| 2951 | 2951 | } |
| 2952 | 2952 | |
| 2953 | 2953 | /** |
| 2954 | 2954 | * Checks if the invoice is refunded. |
| 2955 | 2955 | */ |
| 2956 | 2956 | public function is_refunded() { |
| 2957 | - $is_refunded = $this->has_status( 'wpi-refunded' ); |
|
| 2958 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
| 2957 | + $is_refunded = $this->has_status('wpi-refunded'); |
|
| 2958 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
| 2959 | 2959 | } |
| 2960 | 2960 | |
| 2961 | 2961 | /** |
| 2962 | 2962 | * Checks if the invoice is held. |
| 2963 | 2963 | */ |
| 2964 | 2964 | public function is_held() { |
| 2965 | - $is_held = $this->has_status( 'wpi-onhold' ); |
|
| 2966 | - return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
|
| 2965 | + $is_held = $this->has_status('wpi-onhold'); |
|
| 2966 | + return apply_filters('wpinv_invoice_is_held', $is_held, $this); |
|
| 2967 | 2967 | } |
| 2968 | 2968 | |
| 2969 | 2969 | /** |
@@ -2971,30 +2971,30 @@ discard block |
||
| 2971 | 2971 | */ |
| 2972 | 2972 | public function is_due() { |
| 2973 | 2973 | $due_date = $this->get_due_date(); |
| 2974 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 2974 | + return empty($due_date) ? false : current_time('timestamp') > strtotime($due_date); |
|
| 2975 | 2975 | } |
| 2976 | 2976 | |
| 2977 | 2977 | /** |
| 2978 | 2978 | * Checks if the invoice is draft. |
| 2979 | 2979 | */ |
| 2980 | 2980 | public function is_draft() { |
| 2981 | - return $this->has_status( 'draft, auto-draft' ); |
|
| 2981 | + return $this->has_status('draft, auto-draft'); |
|
| 2982 | 2982 | } |
| 2983 | 2983 | |
| 2984 | 2984 | /** |
| 2985 | 2985 | * Checks if the invoice has a given status. |
| 2986 | 2986 | */ |
| 2987 | - public function has_status( $status ) { |
|
| 2988 | - $status = wpinv_parse_list( $status ); |
|
| 2989 | - return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
|
| 2987 | + public function has_status($status) { |
|
| 2988 | + $status = wpinv_parse_list($status); |
|
| 2989 | + return apply_filters('wpinv_has_status', in_array($this->get_status(), $status), $status); |
|
| 2990 | 2990 | } |
| 2991 | 2991 | |
| 2992 | 2992 | /** |
| 2993 | 2993 | * Checks if the invoice is of a given type. |
| 2994 | 2994 | */ |
| 2995 | - public function is_type( $type ) { |
|
| 2996 | - $type = wpinv_parse_list( $type ); |
|
| 2997 | - return in_array( $this->get_type(), $type ); |
|
| 2995 | + public function is_type($type) { |
|
| 2996 | + $type = wpinv_parse_list($type); |
|
| 2997 | + return in_array($this->get_type(), $type); |
|
| 2998 | 2998 | } |
| 2999 | 2999 | |
| 3000 | 3000 | /** |
@@ -3026,8 +3026,8 @@ discard block |
||
| 3026 | 3026 | * |
| 3027 | 3027 | */ |
| 3028 | 3028 | public function is_initial_free() { |
| 3029 | - $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
|
| 3030 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
|
| 3029 | + $is_initial_free = !((float) wpinv_round_amount($this->get_initial_total()) > 0); |
|
| 3030 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this); |
|
| 3031 | 3031 | } |
| 3032 | 3032 | |
| 3033 | 3033 | /** |
@@ -3037,11 +3037,11 @@ discard block |
||
| 3037 | 3037 | public function item_has_free_trial() { |
| 3038 | 3038 | |
| 3039 | 3039 | // Ensure we have a recurring item. |
| 3040 | - if ( ! $this->is_recurring() ) { |
|
| 3040 | + if (!$this->is_recurring()) { |
|
| 3041 | 3041 | return false; |
| 3042 | 3042 | } |
| 3043 | 3043 | |
| 3044 | - $item = $this->get_recurring( true ); |
|
| 3044 | + $item = $this->get_recurring(true); |
|
| 3045 | 3045 | return $item->has_free_trial(); |
| 3046 | 3046 | } |
| 3047 | 3047 | |
@@ -3049,7 +3049,7 @@ discard block |
||
| 3049 | 3049 | * Check if the free trial is a result of a discount. |
| 3050 | 3050 | */ |
| 3051 | 3051 | public function is_free_trial_from_discount() { |
| 3052 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3052 | + return $this->has_free_trial() && !$this->item_has_free_trial(); |
|
| 3053 | 3053 | } |
| 3054 | 3054 | |
| 3055 | 3055 | /** |
@@ -3058,17 +3058,17 @@ discard block |
||
| 3058 | 3058 | public function discount_first_payment_only() { |
| 3059 | 3059 | |
| 3060 | 3060 | $discount_code = $this->get_discount_code(); |
| 3061 | - if ( empty( $this->discount_code ) || ! $this->is_recurring() ) { |
|
| 3061 | + if (empty($this->discount_code) || !$this->is_recurring()) { |
|
| 3062 | 3062 | return true; |
| 3063 | 3063 | } |
| 3064 | 3064 | |
| 3065 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
| 3065 | + $discount = wpinv_get_discount_obj($discount_code); |
|
| 3066 | 3066 | |
| 3067 | - if ( ! $discount || ! $discount->exists() ) { |
|
| 3067 | + if (!$discount || !$discount->exists()) { |
|
| 3068 | 3068 | return true; |
| 3069 | 3069 | } |
| 3070 | 3070 | |
| 3071 | - return ! $discount->get_is_recurring(); |
|
| 3071 | + return !$discount->get_is_recurring(); |
|
| 3072 | 3072 | } |
| 3073 | 3073 | |
| 3074 | 3074 | /* |
@@ -3086,27 +3086,27 @@ discard block |
||
| 3086 | 3086 | * @param GetPaid_Form_Item|array $item |
| 3087 | 3087 | * @return WP_Error|Bool |
| 3088 | 3088 | */ |
| 3089 | - public function add_item( $item ) { |
|
| 3089 | + public function add_item($item) { |
|
| 3090 | 3090 | |
| 3091 | - if ( is_array( $item ) ) { |
|
| 3092 | - $item = $this->process_array_item( $item ); |
|
| 3091 | + if (is_array($item)) { |
|
| 3092 | + $item = $this->process_array_item($item); |
|
| 3093 | 3093 | } |
| 3094 | 3094 | |
| 3095 | - if ( is_numeric( $item ) ) { |
|
| 3096 | - $item = new GetPaid_Form_Item( $item ); |
|
| 3095 | + if (is_numeric($item)) { |
|
| 3096 | + $item = new GetPaid_Form_Item($item); |
|
| 3097 | 3097 | } |
| 3098 | 3098 | |
| 3099 | 3099 | // Make sure that it is available for purchase. |
| 3100 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3101 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3100 | + if ($item->get_id() > 0 && !$item->can_purchase()) { |
|
| 3101 | + return new WP_Error('invalid_item', __('This item is not available for purchase', 'invoicing')); |
|
| 3102 | 3102 | } |
| 3103 | 3103 | |
| 3104 | 3104 | // Do we have a recurring item? |
| 3105 | - if ( $item->is_recurring() ) { |
|
| 3105 | + if ($item->is_recurring()) { |
|
| 3106 | 3106 | |
| 3107 | 3107 | // An invoice can only contain one recurring item. |
| 3108 | - if ( ! empty( $this->recurring_item && $this->recurring_item != (int) $item->get_id() ) ) { |
|
| 3109 | - return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) ); |
|
| 3108 | + if (!empty($this->recurring_item && $this->recurring_item != (int) $item->get_id())) { |
|
| 3109 | + return new WP_Error('recurring_item', __('An invoice can only contain one recurring item', 'invoicing')); |
|
| 3110 | 3110 | } |
| 3111 | 3111 | |
| 3112 | 3112 | $this->recurring_item = $item->get_id(); |
@@ -3117,9 +3117,9 @@ discard block |
||
| 3117 | 3117 | |
| 3118 | 3118 | // Retrieve all items. |
| 3119 | 3119 | $items = $this->get_items(); |
| 3120 | - $items[ (int) $item->get_id() ] = $item; |
|
| 3120 | + $items[(int) $item->get_id()] = $item; |
|
| 3121 | 3121 | |
| 3122 | - $this->set_prop( 'items', $items ); |
|
| 3122 | + $this->set_prop('items', $items); |
|
| 3123 | 3123 | return true; |
| 3124 | 3124 | } |
| 3125 | 3125 | |
@@ -3129,26 +3129,26 @@ discard block |
||
| 3129 | 3129 | * @since 1.0.19 |
| 3130 | 3130 | * @return GetPaid_Form_Item |
| 3131 | 3131 | */ |
| 3132 | - protected function process_array_item( $array ) { |
|
| 3132 | + protected function process_array_item($array) { |
|
| 3133 | 3133 | |
| 3134 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3135 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 3134 | + $item_id = isset($array['item_id']) ? $array['item_id'] : 0; |
|
| 3135 | + $item = new GetPaid_Form_Item($item_id); |
|
| 3136 | 3136 | |
| 3137 | 3137 | // Set item data. |
| 3138 | - foreach( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3139 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3138 | + foreach (array('name', 'price', 'description') as $key) { |
|
| 3139 | + if (isset($array["item_$key"])) { |
|
| 3140 | 3140 | $method = "set_$key"; |
| 3141 | - $item->$method( $array[ "item_$key" ] ); |
|
| 3141 | + $item->$method($array["item_$key"]); |
|
| 3142 | 3142 | } |
| 3143 | 3143 | } |
| 3144 | 3144 | |
| 3145 | - if ( isset( $array['quantity'] ) ) { |
|
| 3146 | - $item->set_quantity( $array['quantity'] ); |
|
| 3145 | + if (isset($array['quantity'])) { |
|
| 3146 | + $item->set_quantity($array['quantity']); |
|
| 3147 | 3147 | } |
| 3148 | 3148 | |
| 3149 | 3149 | // Set item meta. |
| 3150 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3151 | - $item->set_item_meta( $array['meta'] ); |
|
| 3150 | + if (isset($array['meta']) && is_array($array['meta'])) { |
|
| 3151 | + $item->set_item_meta($array['meta']); |
|
| 3152 | 3152 | } |
| 3153 | 3153 | |
| 3154 | 3154 | return $item; |
@@ -3160,10 +3160,10 @@ discard block |
||
| 3160 | 3160 | * |
| 3161 | 3161 | * @since 1.0.19 |
| 3162 | 3162 | */ |
| 3163 | - public function get_item( $item_id ) { |
|
| 3163 | + public function get_item($item_id) { |
|
| 3164 | 3164 | $items = $this->get_items(); |
| 3165 | 3165 | $item_id = (int) $item_id; |
| 3166 | - return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
| 3166 | + return (!empty($item_id) && isset($items[$item_id])) ? $items[$item_id] : null; |
|
| 3167 | 3167 | } |
| 3168 | 3168 | |
| 3169 | 3169 | /** |
@@ -3171,17 +3171,17 @@ discard block |
||
| 3171 | 3171 | * |
| 3172 | 3172 | * @since 1.0.19 |
| 3173 | 3173 | */ |
| 3174 | - public function remove_item( $item_id ) { |
|
| 3174 | + public function remove_item($item_id) { |
|
| 3175 | 3175 | $items = $this->get_items(); |
| 3176 | 3176 | $item_id = (int) $item_id; |
| 3177 | 3177 | |
| 3178 | - if ( $item_id == $this->recurring_item ) { |
|
| 3178 | + if ($item_id == $this->recurring_item) { |
|
| 3179 | 3179 | $this->recurring_item = null; |
| 3180 | 3180 | } |
| 3181 | 3181 | |
| 3182 | - if ( isset( $items[ $item_id ] ) ) { |
|
| 3183 | - unset( $items[ $item_id ] ); |
|
| 3184 | - $this->set_prop( 'items', $items ); |
|
| 3182 | + if (isset($items[$item_id])) { |
|
| 3183 | + unset($items[$item_id]); |
|
| 3184 | + $this->set_prop('items', $items); |
|
| 3185 | 3185 | } |
| 3186 | 3186 | } |
| 3187 | 3187 | |
@@ -3192,27 +3192,27 @@ discard block |
||
| 3192 | 3192 | * @param float $value |
| 3193 | 3193 | * @return WP_Error|Bool |
| 3194 | 3194 | */ |
| 3195 | - public function add_fee( $fee, $value, $recurring = false ) { |
|
| 3195 | + public function add_fee($fee, $value, $recurring = false) { |
|
| 3196 | 3196 | |
| 3197 | - $amount = wpinv_sanitize_amount( $value ); |
|
| 3197 | + $amount = wpinv_sanitize_amount($value); |
|
| 3198 | 3198 | $fees = $this->get_fees(); |
| 3199 | 3199 | |
| 3200 | - if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) { |
|
| 3200 | + if (isset($fees[$fee]) && isset($fees[$fee]['amount'])) { |
|
| 3201 | 3201 | |
| 3202 | - $amount = $fees[ $fee ]['amount'] += $amount; |
|
| 3203 | - $fees[ $fee ] = array( |
|
| 3202 | + $amount = $fees[$fee]['amount'] += $amount; |
|
| 3203 | + $fees[$fee] = array( |
|
| 3204 | 3204 | 'amount' => $amount, |
| 3205 | 3205 | 'recurring' => (bool) $recurring, |
| 3206 | 3206 | ); |
| 3207 | 3207 | |
| 3208 | 3208 | } else { |
| 3209 | - $fees[ $fee ] = array( |
|
| 3209 | + $fees[$fee] = array( |
|
| 3210 | 3210 | 'amount' => $amount, |
| 3211 | 3211 | 'recurring' => (bool) $recurring, |
| 3212 | 3212 | ); |
| 3213 | 3213 | } |
| 3214 | 3214 | |
| 3215 | - $this->set_prop( 'fees', $fee ); |
|
| 3215 | + $this->set_prop('fees', $fee); |
|
| 3216 | 3216 | |
| 3217 | 3217 | } |
| 3218 | 3218 | |
@@ -3221,9 +3221,9 @@ discard block |
||
| 3221 | 3221 | * |
| 3222 | 3222 | * @since 1.0.19 |
| 3223 | 3223 | */ |
| 3224 | - public function get_fee( $fee ) { |
|
| 3224 | + public function get_fee($fee) { |
|
| 3225 | 3225 | $fees = $this->get_fees(); |
| 3226 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3226 | + return isset($fees[$fee]) ? $fees[$fee] : null; |
|
| 3227 | 3227 | } |
| 3228 | 3228 | |
| 3229 | 3229 | /** |
@@ -3231,11 +3231,11 @@ discard block |
||
| 3231 | 3231 | * |
| 3232 | 3232 | * @since 1.0.19 |
| 3233 | 3233 | */ |
| 3234 | - public function remove_fee( $fee ) { |
|
| 3234 | + public function remove_fee($fee) { |
|
| 3235 | 3235 | $fees = $this->get_fees(); |
| 3236 | - if ( isset( $fees[ $fee ] ) ) { |
|
| 3237 | - unset( $fees[ $fee ] ); |
|
| 3238 | - $this->set_prop( 'fees', $fees ); |
|
| 3236 | + if (isset($fees[$fee])) { |
|
| 3237 | + unset($fees[$fee]); |
|
| 3238 | + $this->set_prop('fees', $fees); |
|
| 3239 | 3239 | } |
| 3240 | 3240 | } |
| 3241 | 3241 | |
@@ -3246,27 +3246,27 @@ discard block |
||
| 3246 | 3246 | * @param float $value |
| 3247 | 3247 | * @return WP_Error|Bool |
| 3248 | 3248 | */ |
| 3249 | - public function add_discount( $discount, $value, $recurring = false ) { |
|
| 3249 | + public function add_discount($discount, $value, $recurring = false) { |
|
| 3250 | 3250 | |
| 3251 | - $amount = wpinv_sanitize_amount( $value ); |
|
| 3251 | + $amount = wpinv_sanitize_amount($value); |
|
| 3252 | 3252 | $discounts = $this->get_discounts(); |
| 3253 | 3253 | |
| 3254 | - if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) { |
|
| 3254 | + if (isset($discounts[$discount]) && isset($discounts[$discount]['amount'])) { |
|
| 3255 | 3255 | |
| 3256 | - $amount = $discounts[ $discount ]['amount'] += $amount; |
|
| 3257 | - $discounts[ $discount ] = array( |
|
| 3256 | + $amount = $discounts[$discount]['amount'] += $amount; |
|
| 3257 | + $discounts[$discount] = array( |
|
| 3258 | 3258 | 'amount' => $amount, |
| 3259 | 3259 | 'recurring' => (bool) $recurring, |
| 3260 | 3260 | ); |
| 3261 | 3261 | |
| 3262 | 3262 | } else { |
| 3263 | - $discounts[ $discount ] = array( |
|
| 3263 | + $discounts[$discount] = array( |
|
| 3264 | 3264 | 'amount' => $amount, |
| 3265 | 3265 | 'recurring' => (bool) $recurring, |
| 3266 | 3266 | ); |
| 3267 | 3267 | } |
| 3268 | 3268 | |
| 3269 | - $this->set_prop( 'discounts', $discount ); |
|
| 3269 | + $this->set_prop('discounts', $discount); |
|
| 3270 | 3270 | |
| 3271 | 3271 | } |
| 3272 | 3272 | |
@@ -3275,15 +3275,15 @@ discard block |
||
| 3275 | 3275 | * |
| 3276 | 3276 | * @since 1.0.19 |
| 3277 | 3277 | */ |
| 3278 | - public function get_discount( $discount = false ) { |
|
| 3278 | + public function get_discount($discount = false) { |
|
| 3279 | 3279 | |
| 3280 | 3280 | // Backwards compatibilty. |
| 3281 | - if ( empty( $discount ) ) { |
|
| 3281 | + if (empty($discount)) { |
|
| 3282 | 3282 | return $this->get_total_discount(); |
| 3283 | 3283 | } |
| 3284 | 3284 | |
| 3285 | 3285 | $discounts = $this->get_discounts(); |
| 3286 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3286 | + return isset($discounts[$discount]) ? $discounts[$discount] : null; |
|
| 3287 | 3287 | } |
| 3288 | 3288 | |
| 3289 | 3289 | /** |
@@ -3291,11 +3291,11 @@ discard block |
||
| 3291 | 3291 | * |
| 3292 | 3292 | * @since 1.0.19 |
| 3293 | 3293 | */ |
| 3294 | - public function remove_discount( $discount ) { |
|
| 3294 | + public function remove_discount($discount) { |
|
| 3295 | 3295 | $discounts = $this->get_discounts(); |
| 3296 | - if ( isset( $discounts[ $discount ] ) ) { |
|
| 3297 | - unset( $discounts[ $discount ] ); |
|
| 3298 | - $this->set_prop( 'discounts', $discounts ); |
|
| 3296 | + if (isset($discounts[$discount])) { |
|
| 3297 | + unset($discounts[$discount]); |
|
| 3298 | + $this->set_prop('discounts', $discounts); |
|
| 3299 | 3299 | } |
| 3300 | 3300 | } |
| 3301 | 3301 | |
@@ -3305,31 +3305,31 @@ discard block |
||
| 3305 | 3305 | * @param string $tax |
| 3306 | 3306 | * @param float $value |
| 3307 | 3307 | */ |
| 3308 | - public function add_tax( $tax, $value, $recurring = true ) { |
|
| 3308 | + public function add_tax($tax, $value, $recurring = true) { |
|
| 3309 | 3309 | |
| 3310 | - if ( ! $this->is_taxable() ) { |
|
| 3310 | + if (!$this->is_taxable()) { |
|
| 3311 | 3311 | return; |
| 3312 | 3312 | } |
| 3313 | 3313 | |
| 3314 | - $amount = wpinv_sanitize_amount( $value ); |
|
| 3314 | + $amount = wpinv_sanitize_amount($value); |
|
| 3315 | 3315 | $taxes = $this->get_taxes(); |
| 3316 | 3316 | |
| 3317 | - if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) { |
|
| 3317 | + if (isset($taxes[$tax]) && isset($taxes[$tax]['amount'])) { |
|
| 3318 | 3318 | |
| 3319 | - $amount = $taxes[ $tax ]['amount'] += $amount; |
|
| 3320 | - $taxes[ $tax ] = array( |
|
| 3319 | + $amount = $taxes[$tax]['amount'] += $amount; |
|
| 3320 | + $taxes[$tax] = array( |
|
| 3321 | 3321 | 'amount' => $amount, |
| 3322 | 3322 | 'recurring' => (bool) $recurring, |
| 3323 | 3323 | ); |
| 3324 | 3324 | |
| 3325 | 3325 | } else { |
| 3326 | - $taxes[ $tax ] = array( |
|
| 3326 | + $taxes[$tax] = array( |
|
| 3327 | 3327 | 'amount' => $amount, |
| 3328 | 3328 | 'recurring' => (bool) $recurring, |
| 3329 | 3329 | ); |
| 3330 | 3330 | } |
| 3331 | 3331 | |
| 3332 | - $this->set_prop( 'taxes', $tax ); |
|
| 3332 | + $this->set_prop('taxes', $tax); |
|
| 3333 | 3333 | |
| 3334 | 3334 | } |
| 3335 | 3335 | |
@@ -3338,15 +3338,15 @@ discard block |
||
| 3338 | 3338 | * |
| 3339 | 3339 | * @since 1.0.19 |
| 3340 | 3340 | */ |
| 3341 | - public function get_tax( $tax = null ) { |
|
| 3341 | + public function get_tax($tax = null) { |
|
| 3342 | 3342 | |
| 3343 | 3343 | // Backwards compatility. |
| 3344 | - if ( empty( $tax ) ) { |
|
| 3344 | + if (empty($tax)) { |
|
| 3345 | 3345 | return $this->get_total_tax(); |
| 3346 | 3346 | } |
| 3347 | 3347 | |
| 3348 | 3348 | $taxes = $this->get_taxes(); |
| 3349 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3349 | + return isset($taxes[$tax]) ? $taxes[$tax] : null; |
|
| 3350 | 3350 | } |
| 3351 | 3351 | |
| 3352 | 3352 | /** |
@@ -3354,11 +3354,11 @@ discard block |
||
| 3354 | 3354 | * |
| 3355 | 3355 | * @since 1.0.19 |
| 3356 | 3356 | */ |
| 3357 | - public function remove_tax( $tax ) { |
|
| 3357 | + public function remove_tax($tax) { |
|
| 3358 | 3358 | $taxes = $this->get_discounts(); |
| 3359 | - if ( isset( $taxes[ $tax ] ) ) { |
|
| 3360 | - unset( $taxes[ $tax ] ); |
|
| 3361 | - $this->set_prop( 'taxes', $taxes ); |
|
| 3359 | + if (isset($taxes[$tax])) { |
|
| 3360 | + unset($taxes[$tax]); |
|
| 3361 | + $this->set_prop('taxes', $taxes); |
|
| 3362 | 3362 | } |
| 3363 | 3363 | } |
| 3364 | 3364 | |
@@ -3369,19 +3369,19 @@ discard block |
||
| 3369 | 3369 | * @return float The recalculated subtotal |
| 3370 | 3370 | */ |
| 3371 | 3371 | public function recalculate_subtotal() { |
| 3372 | - $items = $this->get_items(); |
|
| 3372 | + $items = $this->get_items(); |
|
| 3373 | 3373 | $subtotal = 0; |
| 3374 | 3374 | $recurring = 0; |
| 3375 | 3375 | |
| 3376 | - foreach ( $items as $item ) { |
|
| 3376 | + foreach ($items as $item) { |
|
| 3377 | 3377 | $subtotal += $item->get_sub_total(); |
| 3378 | 3378 | $recurring += $item->get_recurring_sub_total(); |
| 3379 | 3379 | } |
| 3380 | 3380 | |
| 3381 | - if ( $this->is_renewal() ) { |
|
| 3382 | - $this->set_subtotal( $recurring ); |
|
| 3381 | + if ($this->is_renewal()) { |
|
| 3382 | + $this->set_subtotal($recurring); |
|
| 3383 | 3383 | } else { |
| 3384 | - $this->set_subtotal( $subtotal ); |
|
| 3384 | + $this->set_subtotal($subtotal); |
|
| 3385 | 3385 | } |
| 3386 | 3386 | |
| 3387 | 3387 | $this->totals['subtotal'] = array( |
@@ -3403,9 +3403,9 @@ discard block |
||
| 3403 | 3403 | $discount = 0; |
| 3404 | 3404 | $recurring = 0; |
| 3405 | 3405 | |
| 3406 | - foreach ( $discounts as $data ) { |
|
| 3406 | + foreach ($discounts as $data) { |
|
| 3407 | 3407 | |
| 3408 | - if ( $data['recurring'] ) { |
|
| 3408 | + if ($data['recurring']) { |
|
| 3409 | 3409 | $recurring += $data['amount']; |
| 3410 | 3410 | } else { |
| 3411 | 3411 | $discount += $data['amount']; |
@@ -3413,10 +3413,10 @@ discard block |
||
| 3413 | 3413 | |
| 3414 | 3414 | } |
| 3415 | 3415 | |
| 3416 | - if ( $this->is_renewal() ) { |
|
| 3417 | - $this->set_total_discount( $recurring ); |
|
| 3416 | + if ($this->is_renewal()) { |
|
| 3417 | + $this->set_total_discount($recurring); |
|
| 3418 | 3418 | } else { |
| 3419 | - $this->set_total_discount( $discount ); |
|
| 3419 | + $this->set_total_discount($discount); |
|
| 3420 | 3420 | } |
| 3421 | 3421 | |
| 3422 | 3422 | $this->totals['discount'] = array( |
@@ -3435,13 +3435,13 @@ discard block |
||
| 3435 | 3435 | * @return float The recalculated tax |
| 3436 | 3436 | */ |
| 3437 | 3437 | public function recalculate_total_tax() { |
| 3438 | - $taxes = $this->get_taxes(); |
|
| 3438 | + $taxes = $this->get_taxes(); |
|
| 3439 | 3439 | $tax = 0; |
| 3440 | 3440 | $recurring = 0; |
| 3441 | 3441 | |
| 3442 | - foreach ( $taxes as $data ) { |
|
| 3442 | + foreach ($taxes as $data) { |
|
| 3443 | 3443 | |
| 3444 | - if ( $data['recurring'] ) { |
|
| 3444 | + if ($data['recurring']) { |
|
| 3445 | 3445 | $recurring += $data['amount']; |
| 3446 | 3446 | } else { |
| 3447 | 3447 | $tax += $data['amount']; |
@@ -3449,10 +3449,10 @@ discard block |
||
| 3449 | 3449 | |
| 3450 | 3450 | } |
| 3451 | 3451 | |
| 3452 | - if ( $this->is_renewal() ) { |
|
| 3453 | - $this->set_total_tax( $recurring ); |
|
| 3452 | + if ($this->is_renewal()) { |
|
| 3453 | + $this->set_total_tax($recurring); |
|
| 3454 | 3454 | } else { |
| 3455 | - $this->set_total_tax( $tax ); |
|
| 3455 | + $this->set_total_tax($tax); |
|
| 3456 | 3456 | } |
| 3457 | 3457 | |
| 3458 | 3458 | $this->totals['tax'] = array( |
@@ -3475,9 +3475,9 @@ discard block |
||
| 3475 | 3475 | $fee = 0; |
| 3476 | 3476 | $recurring = 0; |
| 3477 | 3477 | |
| 3478 | - foreach ( $fees as $data ) { |
|
| 3478 | + foreach ($fees as $data) { |
|
| 3479 | 3479 | |
| 3480 | - if ( $data['recurring'] ) { |
|
| 3480 | + if ($data['recurring']) { |
|
| 3481 | 3481 | $recurring += $data['amount']; |
| 3482 | 3482 | } else { |
| 3483 | 3483 | $fee += $data['amount']; |
@@ -3485,10 +3485,10 @@ discard block |
||
| 3485 | 3485 | |
| 3486 | 3486 | } |
| 3487 | 3487 | |
| 3488 | - if ( $this->is_renewal() ) { |
|
| 3489 | - $this->set_total_fees( $recurring ); |
|
| 3488 | + if ($this->is_renewal()) { |
|
| 3489 | + $this->set_total_fees($recurring); |
|
| 3490 | 3490 | } else { |
| 3491 | - $this->set_total_fees( $fee ); |
|
| 3491 | + $this->set_total_fees($fee); |
|
| 3492 | 3492 | } |
| 3493 | 3493 | |
| 3494 | 3494 | $this->totals['fee'] = array( |
@@ -3496,7 +3496,7 @@ discard block |
||
| 3496 | 3496 | 'recurring' => $recurring, |
| 3497 | 3497 | ); |
| 3498 | 3498 | |
| 3499 | - $this->set_total_fees( $fee ); |
|
| 3499 | + $this->set_total_fees($fee); |
|
| 3500 | 3500 | return $this->is_renewal() ? $recurring : $fee; |
| 3501 | 3501 | } |
| 3502 | 3502 | |
@@ -3517,9 +3517,9 @@ discard block |
||
| 3517 | 3517 | /** |
| 3518 | 3518 | * @deprecated |
| 3519 | 3519 | */ |
| 3520 | - public function recalculate_totals( $temp = false ) { |
|
| 3521 | - $this->update_items( $temp ); |
|
| 3522 | - $this->save( true ); |
|
| 3520 | + public function recalculate_totals($temp = false) { |
|
| 3521 | + $this->update_items($temp); |
|
| 3522 | + $this->save(true); |
|
| 3523 | 3523 | return $this; |
| 3524 | 3524 | } |
| 3525 | 3525 | |
@@ -3537,36 +3537,36 @@ discard block |
||
| 3537 | 3537 | * @return int|false The new note's ID on success, false on failure. |
| 3538 | 3538 | * |
| 3539 | 3539 | */ |
| 3540 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
| 3540 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
| 3541 | 3541 | |
| 3542 | 3542 | // Bail if no note specified or this invoice is not yet saved. |
| 3543 | - if ( ! $note || $this->get_id() == 0 || ( ! is_user_logged_in() && ! $system ) ) { |
|
| 3543 | + if (!$note || $this->get_id() == 0 || (!is_user_logged_in() && !$system)) { |
|
| 3544 | 3544 | return false; |
| 3545 | 3545 | } |
| 3546 | 3546 | |
| 3547 | 3547 | // If this is an admin comment or it has been added by the user. |
| 3548 | - if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) { |
|
| 3549 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3548 | + if (is_user_logged_in() && (wpinv_current_user_can_manage_invoicing() || $added_by_user)) { |
|
| 3549 | + $user = get_user_by('id', get_current_user_id()); |
|
| 3550 | 3550 | $author = $user->display_name; |
| 3551 | 3551 | $author_email = $user->user_email; |
| 3552 | 3552 | } |
| 3553 | 3553 | |
| 3554 | - if ( $system ) { |
|
| 3555 | - $author = 'System'; |
|
| 3554 | + if ($system) { |
|
| 3555 | + $author = 'System'; |
|
| 3556 | 3556 | $author_email = '[email protected]'; |
| 3557 | 3557 | } |
| 3558 | 3558 | |
| 3559 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3559 | + return getpaid_notes()->add_invoice_note($this, $note, $author, $author_email, $customer_type); |
|
| 3560 | 3560 | |
| 3561 | 3561 | } |
| 3562 | 3562 | |
| 3563 | 3563 | /** |
| 3564 | 3564 | * Generates a unique key for the invoice. |
| 3565 | 3565 | */ |
| 3566 | - public function generate_key( $string = '' ) { |
|
| 3567 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 3566 | + public function generate_key($string = '') { |
|
| 3567 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 3568 | 3568 | return strtolower( |
| 3569 | - $string . md5( $this->get_id() . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) |
|
| 3569 | + $string . md5($this->get_id() . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true)) |
|
| 3570 | 3570 | ); |
| 3571 | 3571 | } |
| 3572 | 3572 | |
@@ -3576,11 +3576,11 @@ discard block |
||
| 3576 | 3576 | public function generate_number() { |
| 3577 | 3577 | $number = $this->get_id(); |
| 3578 | 3578 | |
| 3579 | - if ( $this->has_status( 'auto-draft' ) && wpinv_sequential_number_active( $this->post_type ) ) { |
|
| 3580 | - $number = wpinv_get_next_invoice_number( $this->post_type ); |
|
| 3579 | + if ($this->has_status('auto-draft') && wpinv_sequential_number_active($this->post_type)) { |
|
| 3580 | + $number = wpinv_get_next_invoice_number($this->post_type); |
|
| 3581 | 3581 | } |
| 3582 | 3582 | |
| 3583 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
| 3583 | + $number = wpinv_format_invoice_number($number, $this->post_type); |
|
| 3584 | 3584 | |
| 3585 | 3585 | return $number; |
| 3586 | 3586 | } |
@@ -3594,47 +3594,47 @@ discard block |
||
| 3594 | 3594 | // Reset status transition variable. |
| 3595 | 3595 | $this->status_transition = false; |
| 3596 | 3596 | |
| 3597 | - if ( $status_transition ) { |
|
| 3597 | + if ($status_transition) { |
|
| 3598 | 3598 | try { |
| 3599 | 3599 | |
| 3600 | 3600 | // Fire a hook for the status change. |
| 3601 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 3601 | + do_action('getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
| 3602 | 3602 | |
| 3603 | 3603 | // @deprecated this is deprecated and will be removed in the future. |
| 3604 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3604 | + do_action('wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from']); |
|
| 3605 | 3605 | |
| 3606 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 3606 | + if (!empty($status_transition['from'])) { |
|
| 3607 | 3607 | |
| 3608 | 3608 | /* translators: 1: old invoice status 2: new invoice status */ |
| 3609 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
| 3609 | + $transition_note = sprintf(__('Status changed from %1$s to %2$s.', 'invoicing'), wpinv_status_nicename($status_transition['from']), wpinv_status_nicename($status_transition['to'])); |
|
| 3610 | 3610 | |
| 3611 | 3611 | // Fire another hook. |
| 3612 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 3613 | - do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
| 3612 | + do_action('getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
| 3613 | + do_action('getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this); |
|
| 3614 | 3614 | |
| 3615 | 3615 | // @deprecated this is deprecated and will be removed in the future. |
| 3616 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3616 | + do_action('wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from']); |
|
| 3617 | 3617 | |
| 3618 | 3618 | // Note the transition occurred. |
| 3619 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3619 | + $this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']); |
|
| 3620 | 3620 | |
| 3621 | 3621 | // Work out if this was for a payment, and trigger a payment_status hook instead. |
| 3622 | 3622 | if ( |
| 3623 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true ) |
|
| 3624 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3623 | + in_array($status_transition['from'], array('wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded'), true) |
|
| 3624 | + && in_array($status_transition['to'], array('publish', 'wpi-processing', 'wpi-renewal'), true) |
|
| 3625 | 3625 | ) { |
| 3626 | - do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition ); |
|
| 3626 | + do_action('getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition); |
|
| 3627 | 3627 | } |
| 3628 | 3628 | } else { |
| 3629 | 3629 | /* translators: %s: new invoice status */ |
| 3630 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
| 3630 | + $transition_note = sprintf(__('Status set to %s.', 'invoicing'), wpinv_status_nicename($status_transition['to'])); |
|
| 3631 | 3631 | |
| 3632 | 3632 | // Note the transition occurred. |
| 3633 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3633 | + $this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']); |
|
| 3634 | 3634 | |
| 3635 | 3635 | } |
| 3636 | - } catch ( Exception $e ) { |
|
| 3637 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3636 | + } catch (Exception $e) { |
|
| 3637 | + $this->add_note(__('Error during status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
| 3638 | 3638 | } |
| 3639 | 3639 | } |
| 3640 | 3640 | } |
@@ -3642,13 +3642,13 @@ discard block |
||
| 3642 | 3642 | /** |
| 3643 | 3643 | * Updates an invoice status. |
| 3644 | 3644 | */ |
| 3645 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3645 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
| 3646 | 3646 | |
| 3647 | 3647 | // Fires before updating a status. |
| 3648 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3648 | + do_action('wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status('edit')); |
|
| 3649 | 3649 | |
| 3650 | 3650 | // Update the status. |
| 3651 | - $this->set_status( $new_status, $note, $manual ); |
|
| 3651 | + $this->set_status($new_status, $note, $manual); |
|
| 3652 | 3652 | |
| 3653 | 3653 | // Save the order. |
| 3654 | 3654 | return $this->save(); |
@@ -3659,18 +3659,18 @@ discard block |
||
| 3659 | 3659 | * @deprecated |
| 3660 | 3660 | */ |
| 3661 | 3661 | public function refresh_item_ids() { |
| 3662 | - $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) ); |
|
| 3663 | - update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
|
| 3662 | + $item_ids = implode(',', array_unique(array_keys($this->get_items()))); |
|
| 3663 | + update_post_meta($this->get_id(), '_wpinv_item_ids', $item_ids); |
|
| 3664 | 3664 | } |
| 3665 | 3665 | |
| 3666 | 3666 | /** |
| 3667 | 3667 | * @deprecated |
| 3668 | 3668 | */ |
| 3669 | - public function update_items( $temp = false ) { |
|
| 3669 | + public function update_items($temp = false) { |
|
| 3670 | 3670 | |
| 3671 | - $this->set_items( $this->get_items() ); |
|
| 3671 | + $this->set_items($this->get_items()); |
|
| 3672 | 3672 | |
| 3673 | - if ( ! $temp ) { |
|
| 3673 | + if (!$temp) { |
|
| 3674 | 3674 | $this->save(); |
| 3675 | 3675 | } |
| 3676 | 3676 | |
@@ -3684,11 +3684,11 @@ discard block |
||
| 3684 | 3684 | |
| 3685 | 3685 | $discount_code = $this->get_discount_code(); |
| 3686 | 3686 | |
| 3687 | - if ( empty( $discount_code ) ) { |
|
| 3687 | + if (empty($discount_code)) { |
|
| 3688 | 3688 | return false; |
| 3689 | 3689 | } |
| 3690 | 3690 | |
| 3691 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
| 3691 | + $discount = wpinv_get_discount_obj($discount_code); |
|
| 3692 | 3692 | |
| 3693 | 3693 | // Ensure it is active. |
| 3694 | 3694 | return $discount->exists(); |
@@ -3699,7 +3699,7 @@ discard block |
||
| 3699 | 3699 | * Refunds an invoice. |
| 3700 | 3700 | */ |
| 3701 | 3701 | public function refund() { |
| 3702 | - $this->set_status( 'wpi-refunded' ); |
|
| 3702 | + $this->set_status('wpi-refunded'); |
|
| 3703 | 3703 | $this->save(); |
| 3704 | 3704 | } |
| 3705 | 3705 | |
@@ -3708,56 +3708,56 @@ discard block |
||
| 3708 | 3708 | * |
| 3709 | 3709 | * @param string $transaction_id |
| 3710 | 3710 | */ |
| 3711 | - public function mark_paid( $transaction_id = null, $note = '' ) { |
|
| 3711 | + public function mark_paid($transaction_id = null, $note = '') { |
|
| 3712 | 3712 | |
| 3713 | 3713 | // Set the transaction id. |
| 3714 | - if ( empty( $transaction_id ) ) { |
|
| 3714 | + if (empty($transaction_id)) { |
|
| 3715 | 3715 | $transaction_id = $this->generate_key('trans_'); |
| 3716 | 3716 | } |
| 3717 | 3717 | |
| 3718 | - if ( ! $this->get_transaction_id() ) { |
|
| 3719 | - $this->set_transaction_id( $transaction_id ); |
|
| 3718 | + if (!$this->get_transaction_id()) { |
|
| 3719 | + $this->set_transaction_id($transaction_id); |
|
| 3720 | 3720 | } |
| 3721 | 3721 | |
| 3722 | - if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3722 | + if ($this->is_paid() && 'wpi-processing' != $this->get_status()) { |
|
| 3723 | 3723 | return $this->save(); |
| 3724 | 3724 | } |
| 3725 | 3725 | |
| 3726 | 3726 | // Set the completed date. |
| 3727 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3727 | + $this->set_date_completed(current_time('mysql')); |
|
| 3728 | 3728 | |
| 3729 | 3729 | // Set the new status. |
| 3730 | - if ( $this->is_renewal() ) { |
|
| 3730 | + if ($this->is_renewal()) { |
|
| 3731 | 3731 | |
| 3732 | 3732 | $_note = sprintf( |
| 3733 | - __( 'Renewed via %s', 'invoicing' ), |
|
| 3734 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3733 | + __('Renewed via %s', 'invoicing'), |
|
| 3734 | + $this->get_gateway_title() . empty($note) ? '' : " ($note)" |
|
| 3735 | 3735 | ); |
| 3736 | 3736 | |
| 3737 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3737 | + if ('none' == $this->get_gateway()) { |
|
| 3738 | 3738 | $_note = $note; |
| 3739 | 3739 | } |
| 3740 | 3740 | |
| 3741 | - $this->set_status( 'wpi-renewal', $_note ); |
|
| 3741 | + $this->set_status('wpi-renewal', $_note); |
|
| 3742 | 3742 | |
| 3743 | 3743 | } else { |
| 3744 | 3744 | |
| 3745 | 3745 | $_note = sprintf( |
| 3746 | - __( 'Paid via %s', 'invoicing' ), |
|
| 3747 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3746 | + __('Paid via %s', 'invoicing'), |
|
| 3747 | + $this->get_gateway_title() . empty($note) ? '' : " ($note)" |
|
| 3748 | 3748 | ); |
| 3749 | 3749 | |
| 3750 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3750 | + if ('none' == $this->get_gateway()) { |
|
| 3751 | 3751 | $_note = $note; |
| 3752 | 3752 | } |
| 3753 | 3753 | |
| 3754 | - $this->set_status( 'publish',$_note ); |
|
| 3754 | + $this->set_status('publish', $_note); |
|
| 3755 | 3755 | |
| 3756 | 3756 | } |
| 3757 | 3757 | |
| 3758 | 3758 | // Set checkout mode. |
| 3759 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 3760 | - $this->set_mode( $mode ); |
|
| 3759 | + $mode = wpinv_is_test_mode($this->get_gateway()) ? 'test' : 'live'; |
|
| 3760 | + $this->set_mode($mode); |
|
| 3761 | 3761 | |
| 3762 | 3762 | // Save the invoice. |
| 3763 | 3763 | $this->save(); |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | - exit; |
|
| 8 | + exit; |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | /** |
@@ -15,190 +15,190 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class GetPaid_Subscription_Data_Store { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * A map of database fields to data types. |
|
| 20 | - * |
|
| 21 | - * @since 1.0.19 |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $database_fields_to_data_type = array( |
|
| 25 | - 'id' => '%d', |
|
| 26 | - 'customer_id' => '%d', |
|
| 27 | - 'frequency' => '%d', |
|
| 28 | - 'period' => '%s', |
|
| 29 | - 'initial_amount' => '%s', |
|
| 30 | - 'recurring_amount' => '%s', |
|
| 31 | - 'bill_times' => '%d', |
|
| 32 | - 'transaction_id' => '%s', |
|
| 33 | - 'parent_payment_id' => '%d', |
|
| 34 | - 'product_id' => '%d', |
|
| 35 | - 'created' => '%s', |
|
| 36 | - 'expiration' => '%s', |
|
| 37 | - 'trial_period' => '%s', |
|
| 38 | - 'status' => '%s', |
|
| 39 | - 'profile_id' => '%s', |
|
| 40 | - ); |
|
| 41 | - |
|
| 42 | - /* |
|
| 18 | + /** |
|
| 19 | + * A map of database fields to data types. |
|
| 20 | + * |
|
| 21 | + * @since 1.0.19 |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $database_fields_to_data_type = array( |
|
| 25 | + 'id' => '%d', |
|
| 26 | + 'customer_id' => '%d', |
|
| 27 | + 'frequency' => '%d', |
|
| 28 | + 'period' => '%s', |
|
| 29 | + 'initial_amount' => '%s', |
|
| 30 | + 'recurring_amount' => '%s', |
|
| 31 | + 'bill_times' => '%d', |
|
| 32 | + 'transaction_id' => '%s', |
|
| 33 | + 'parent_payment_id' => '%d', |
|
| 34 | + 'product_id' => '%d', |
|
| 35 | + 'created' => '%s', |
|
| 36 | + 'expiration' => '%s', |
|
| 37 | + 'trial_period' => '%s', |
|
| 38 | + 'status' => '%s', |
|
| 39 | + 'profile_id' => '%s', |
|
| 40 | + ); |
|
| 41 | + |
|
| 42 | + /* |
|
| 43 | 43 | |-------------------------------------------------------------------------- |
| 44 | 44 | | CRUD Methods |
| 45 | 45 | |-------------------------------------------------------------------------- |
| 46 | 46 | */ |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Method to create a new subscription in the database. |
|
| 50 | - * |
|
| 51 | - * @param WPInv_Subscription $subscription Subscription object. |
|
| 52 | - */ |
|
| 53 | - public function create( &$subscription ) { |
|
| 54 | - global $wpdb; |
|
| 55 | - |
|
| 56 | - $values = array(); |
|
| 57 | - $formats = array(); |
|
| 58 | - |
|
| 59 | - $fields = $this->database_fields_to_data_type; |
|
| 60 | - unset( $fields['id'] ); |
|
| 61 | - |
|
| 62 | - foreach ( $fields as $key => $format ) { |
|
| 63 | - $method = "get_$key"; |
|
| 64 | - $values[$key] = $subscription->$method( 'edit' ); |
|
| 65 | - $formats[] = $format; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats ); |
|
| 69 | - |
|
| 70 | - if ( $result ) { |
|
| 71 | - $subscription->set_id( $wpdb->insert_id ); |
|
| 72 | - $subscription->apply_changes(); |
|
| 73 | - $subscription->clear_cache(); |
|
| 74 | - do_action( 'getpaid_new_subscription', $subscription ); |
|
| 75 | - return true; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Method to read a subscription from the database. |
|
| 83 | - * |
|
| 84 | - * @param WPInv_Subscription $subscription Subscription object. |
|
| 85 | - * |
|
| 86 | - */ |
|
| 87 | - public function read( &$subscription ) { |
|
| 88 | - global $wpdb; |
|
| 89 | - |
|
| 90 | - $subscription->set_defaults(); |
|
| 91 | - |
|
| 92 | - if ( ! $subscription->get_id() ) { |
|
| 93 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
| 94 | - $subscription->set_id( 0 ); |
|
| 95 | - return false; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // Maybe retrieve from the cache. |
|
| 99 | - $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' ); |
|
| 100 | - |
|
| 101 | - // If not found, retrieve from the db. |
|
| 102 | - if ( false === $raw_subscription ) { |
|
| 103 | - |
|
| 104 | - $raw_subscription = $wpdb->get_row( |
|
| 105 | - $wpdb->prepare( |
|
| 106 | - "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d", |
|
| 107 | - $subscription->get_id() |
|
| 108 | - ) |
|
| 109 | - ); |
|
| 110 | - |
|
| 111 | - // Update the cache with our data |
|
| 112 | - wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' ); |
|
| 113 | - |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if ( ! $raw_subscription ) { |
|
| 117 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
| 118 | - return false; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) { |
|
| 122 | - $method = "set_$key"; |
|
| 123 | - $subscription->$method( $raw_subscription->$key ); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $subscription->set_object_read( true ); |
|
| 127 | - do_action( 'getpaid_read_subscription', $subscription ); |
|
| 128 | - |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Method to update a subscription in the database. |
|
| 133 | - * |
|
| 134 | - * @param WPInv_Subscription $subscription Subscription object. |
|
| 135 | - */ |
|
| 136 | - public function update( &$subscription ) { |
|
| 137 | - global $wpdb; |
|
| 138 | - |
|
| 139 | - $changes = $subscription->get_changes(); |
|
| 140 | - $values = array(); |
|
| 141 | - $format = array(); |
|
| 142 | - |
|
| 143 | - foreach ( $this->database_fields_to_data_type as $key => $format ) { |
|
| 144 | - if ( array_key_exists( $key, $changes ) ) { |
|
| 145 | - $method = "get_$key"; |
|
| 146 | - $values[$key] = $subscription->$method( 'edit' ); |
|
| 147 | - $formats[] = $format; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if ( empty( $values ) ) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $wpdb->update( |
|
| 156 | - $wpdb->prefix . 'wpinv_subscriptions', |
|
| 157 | - $values, |
|
| 158 | - array( |
|
| 159 | - 'id' => $subscription->get_id(), |
|
| 160 | - ), |
|
| 161 | - $formats, |
|
| 162 | - '%d' |
|
| 163 | - ); |
|
| 164 | - |
|
| 165 | - // Apply the changes. |
|
| 166 | - $subscription->apply_changes(); |
|
| 167 | - |
|
| 168 | - // Delete cache. |
|
| 169 | - $subscription->clear_cache(); |
|
| 170 | - |
|
| 171 | - // Fire a hook. |
|
| 172 | - do_action( 'getpaid_update_subscription', $subscription->get_id(), $subscription ); |
|
| 173 | - |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Method to delete a subscription from the database. |
|
| 178 | - * |
|
| 179 | - * @param WPInv_Subscription $subscription |
|
| 180 | - */ |
|
| 181 | - public function delete( &$subscription ) { |
|
| 182 | - global $wpdb; |
|
| 183 | - |
|
| 184 | - $wpdb->query( |
|
| 185 | - $wpdb->prepare( |
|
| 186 | - "DELETE FROM {$wpdb->prefix}getpaid_subscriptions |
|
| 48 | + /** |
|
| 49 | + * Method to create a new subscription in the database. |
|
| 50 | + * |
|
| 51 | + * @param WPInv_Subscription $subscription Subscription object. |
|
| 52 | + */ |
|
| 53 | + public function create( &$subscription ) { |
|
| 54 | + global $wpdb; |
|
| 55 | + |
|
| 56 | + $values = array(); |
|
| 57 | + $formats = array(); |
|
| 58 | + |
|
| 59 | + $fields = $this->database_fields_to_data_type; |
|
| 60 | + unset( $fields['id'] ); |
|
| 61 | + |
|
| 62 | + foreach ( $fields as $key => $format ) { |
|
| 63 | + $method = "get_$key"; |
|
| 64 | + $values[$key] = $subscription->$method( 'edit' ); |
|
| 65 | + $formats[] = $format; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats ); |
|
| 69 | + |
|
| 70 | + if ( $result ) { |
|
| 71 | + $subscription->set_id( $wpdb->insert_id ); |
|
| 72 | + $subscription->apply_changes(); |
|
| 73 | + $subscription->clear_cache(); |
|
| 74 | + do_action( 'getpaid_new_subscription', $subscription ); |
|
| 75 | + return true; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Method to read a subscription from the database. |
|
| 83 | + * |
|
| 84 | + * @param WPInv_Subscription $subscription Subscription object. |
|
| 85 | + * |
|
| 86 | + */ |
|
| 87 | + public function read( &$subscription ) { |
|
| 88 | + global $wpdb; |
|
| 89 | + |
|
| 90 | + $subscription->set_defaults(); |
|
| 91 | + |
|
| 92 | + if ( ! $subscription->get_id() ) { |
|
| 93 | + $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
| 94 | + $subscription->set_id( 0 ); |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // Maybe retrieve from the cache. |
|
| 99 | + $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' ); |
|
| 100 | + |
|
| 101 | + // If not found, retrieve from the db. |
|
| 102 | + if ( false === $raw_subscription ) { |
|
| 103 | + |
|
| 104 | + $raw_subscription = $wpdb->get_row( |
|
| 105 | + $wpdb->prepare( |
|
| 106 | + "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d", |
|
| 107 | + $subscription->get_id() |
|
| 108 | + ) |
|
| 109 | + ); |
|
| 110 | + |
|
| 111 | + // Update the cache with our data |
|
| 112 | + wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' ); |
|
| 113 | + |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if ( ! $raw_subscription ) { |
|
| 117 | + $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
| 118 | + return false; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) { |
|
| 122 | + $method = "set_$key"; |
|
| 123 | + $subscription->$method( $raw_subscription->$key ); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $subscription->set_object_read( true ); |
|
| 127 | + do_action( 'getpaid_read_subscription', $subscription ); |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Method to update a subscription in the database. |
|
| 133 | + * |
|
| 134 | + * @param WPInv_Subscription $subscription Subscription object. |
|
| 135 | + */ |
|
| 136 | + public function update( &$subscription ) { |
|
| 137 | + global $wpdb; |
|
| 138 | + |
|
| 139 | + $changes = $subscription->get_changes(); |
|
| 140 | + $values = array(); |
|
| 141 | + $format = array(); |
|
| 142 | + |
|
| 143 | + foreach ( $this->database_fields_to_data_type as $key => $format ) { |
|
| 144 | + if ( array_key_exists( $key, $changes ) ) { |
|
| 145 | + $method = "get_$key"; |
|
| 146 | + $values[$key] = $subscription->$method( 'edit' ); |
|
| 147 | + $formats[] = $format; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if ( empty( $values ) ) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $wpdb->update( |
|
| 156 | + $wpdb->prefix . 'wpinv_subscriptions', |
|
| 157 | + $values, |
|
| 158 | + array( |
|
| 159 | + 'id' => $subscription->get_id(), |
|
| 160 | + ), |
|
| 161 | + $formats, |
|
| 162 | + '%d' |
|
| 163 | + ); |
|
| 164 | + |
|
| 165 | + // Apply the changes. |
|
| 166 | + $subscription->apply_changes(); |
|
| 167 | + |
|
| 168 | + // Delete cache. |
|
| 169 | + $subscription->clear_cache(); |
|
| 170 | + |
|
| 171 | + // Fire a hook. |
|
| 172 | + do_action( 'getpaid_update_subscription', $subscription->get_id(), $subscription ); |
|
| 173 | + |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Method to delete a subscription from the database. |
|
| 178 | + * |
|
| 179 | + * @param WPInv_Subscription $subscription |
|
| 180 | + */ |
|
| 181 | + public function delete( &$subscription ) { |
|
| 182 | + global $wpdb; |
|
| 183 | + |
|
| 184 | + $wpdb->query( |
|
| 185 | + $wpdb->prepare( |
|
| 186 | + "DELETE FROM {$wpdb->prefix}getpaid_subscriptions |
|
| 187 | 187 | WHERE id = %d", |
| 188 | - $subscription->get_id() |
|
| 189 | - ) |
|
| 190 | - ); |
|
| 188 | + $subscription->get_id() |
|
| 189 | + ) |
|
| 190 | + ); |
|
| 191 | 191 | |
| 192 | - // Delete cache. |
|
| 193 | - $subscription->clear_cache(); |
|
| 192 | + // Delete cache. |
|
| 193 | + $subscription->clear_cache(); |
|
| 194 | 194 | |
| 195 | - // Fire a hook. |
|
| 196 | - do_action( 'getpaid_delete_subscription', $subscription->get_id(), $subscription ); |
|
| 195 | + // Fire a hook. |
|
| 196 | + do_action( 'getpaid_delete_subscription', $subscription->get_id(), $subscription ); |
|
| 197 | 197 | |
| 198 | - $subscription->set_id( 0 ); |
|
| 199 | - } |
|
| 198 | + $subscription->set_id( 0 ); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /* |
|
| 201 | + /* |
|
| 202 | 202 | |-------------------------------------------------------------------------- |
| 203 | 203 | | Additional Methods |
| 204 | 204 | |-------------------------------------------------------------------------- |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * GetPaid_Subscription_Data_Store class file. |
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 7 | +if (!defined('ABSPATH')) { |
|
| 8 | 8 | exit; |
| 9 | 9 | } |
| 10 | 10 | |
@@ -50,28 +50,28 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @param WPInv_Subscription $subscription Subscription object. |
| 52 | 52 | */ |
| 53 | - public function create( &$subscription ) { |
|
| 53 | + public function create(&$subscription) { |
|
| 54 | 54 | global $wpdb; |
| 55 | 55 | |
| 56 | 56 | $values = array(); |
| 57 | 57 | $formats = array(); |
| 58 | 58 | |
| 59 | 59 | $fields = $this->database_fields_to_data_type; |
| 60 | - unset( $fields['id'] ); |
|
| 60 | + unset($fields['id']); |
|
| 61 | 61 | |
| 62 | - foreach ( $fields as $key => $format ) { |
|
| 62 | + foreach ($fields as $key => $format) { |
|
| 63 | 63 | $method = "get_$key"; |
| 64 | - $values[$key] = $subscription->$method( 'edit' ); |
|
| 64 | + $values[$key] = $subscription->$method('edit'); |
|
| 65 | 65 | $formats[] = $format; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats ); |
|
| 68 | + $result = $wpdb->insert($wpdb->prefix . 'wpinv_subscriptions', $fields, $formats); |
|
| 69 | 69 | |
| 70 | - if ( $result ) { |
|
| 71 | - $subscription->set_id( $wpdb->insert_id ); |
|
| 70 | + if ($result) { |
|
| 71 | + $subscription->set_id($wpdb->insert_id); |
|
| 72 | 72 | $subscription->apply_changes(); |
| 73 | 73 | $subscription->clear_cache(); |
| 74 | - do_action( 'getpaid_new_subscription', $subscription ); |
|
| 74 | + do_action('getpaid_new_subscription', $subscription); |
|
| 75 | 75 | return true; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -84,22 +84,22 @@ discard block |
||
| 84 | 84 | * @param WPInv_Subscription $subscription Subscription object. |
| 85 | 85 | * |
| 86 | 86 | */ |
| 87 | - public function read( &$subscription ) { |
|
| 87 | + public function read(&$subscription) { |
|
| 88 | 88 | global $wpdb; |
| 89 | 89 | |
| 90 | 90 | $subscription->set_defaults(); |
| 91 | 91 | |
| 92 | - if ( ! $subscription->get_id() ) { |
|
| 93 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
| 94 | - $subscription->set_id( 0 ); |
|
| 92 | + if (!$subscription->get_id()) { |
|
| 93 | + $subscription->last_error = __('Invalid subscription ID.', 'invoicing'); |
|
| 94 | + $subscription->set_id(0); |
|
| 95 | 95 | return false; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Maybe retrieve from the cache. |
| 99 | - $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' ); |
|
| 99 | + $raw_subscription = wp_cache_get($subscription->get_id(), 'getpaid_subscriptions'); |
|
| 100 | 100 | |
| 101 | 101 | // If not found, retrieve from the db. |
| 102 | - if ( false === $raw_subscription ) { |
|
| 102 | + if (false === $raw_subscription) { |
|
| 103 | 103 | |
| 104 | 104 | $raw_subscription = $wpdb->get_row( |
| 105 | 105 | $wpdb->prepare( |
@@ -109,22 +109,22 @@ discard block |
||
| 109 | 109 | ); |
| 110 | 110 | |
| 111 | 111 | // Update the cache with our data |
| 112 | - wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' ); |
|
| 112 | + wp_cache_set($subscription->get_id(), $raw_subscription, 'getpaid_subscriptions'); |
|
| 113 | 113 | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( ! $raw_subscription ) { |
|
| 117 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
| 116 | + if (!$raw_subscription) { |
|
| 117 | + $subscription->last_error = __('Invalid subscription ID.', 'invoicing'); |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) { |
|
| 122 | - $method = "set_$key"; |
|
| 123 | - $subscription->$method( $raw_subscription->$key ); |
|
| 121 | + foreach (array_keys($this->database_fields_to_data_type) as $key) { |
|
| 122 | + $method = "set_$key"; |
|
| 123 | + $subscription->$method($raw_subscription->$key); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - $subscription->set_object_read( true ); |
|
| 127 | - do_action( 'getpaid_read_subscription', $subscription ); |
|
| 126 | + $subscription->set_object_read(true); |
|
| 127 | + do_action('getpaid_read_subscription', $subscription); |
|
| 128 | 128 | |
| 129 | 129 | } |
| 130 | 130 | |
@@ -133,22 +133,22 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @param WPInv_Subscription $subscription Subscription object. |
| 135 | 135 | */ |
| 136 | - public function update( &$subscription ) { |
|
| 136 | + public function update(&$subscription) { |
|
| 137 | 137 | global $wpdb; |
| 138 | 138 | |
| 139 | 139 | $changes = $subscription->get_changes(); |
| 140 | 140 | $values = array(); |
| 141 | 141 | $format = array(); |
| 142 | 142 | |
| 143 | - foreach ( $this->database_fields_to_data_type as $key => $format ) { |
|
| 144 | - if ( array_key_exists( $key, $changes ) ) { |
|
| 143 | + foreach ($this->database_fields_to_data_type as $key => $format) { |
|
| 144 | + if (array_key_exists($key, $changes)) { |
|
| 145 | 145 | $method = "get_$key"; |
| 146 | - $values[$key] = $subscription->$method( 'edit' ); |
|
| 146 | + $values[$key] = $subscription->$method('edit'); |
|
| 147 | 147 | $formats[] = $format; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if ( empty( $values ) ) { |
|
| 151 | + if (empty($values)) { |
|
| 152 | 152 | return; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $subscription->clear_cache(); |
| 170 | 170 | |
| 171 | 171 | // Fire a hook. |
| 172 | - do_action( 'getpaid_update_subscription', $subscription->get_id(), $subscription ); |
|
| 172 | + do_action('getpaid_update_subscription', $subscription->get_id(), $subscription); |
|
| 173 | 173 | |
| 174 | 174 | } |
| 175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @param WPInv_Subscription $subscription |
| 180 | 180 | */ |
| 181 | - public function delete( &$subscription ) { |
|
| 181 | + public function delete(&$subscription) { |
|
| 182 | 182 | global $wpdb; |
| 183 | 183 | |
| 184 | 184 | $wpdb->query( |
@@ -193,9 +193,9 @@ discard block |
||
| 193 | 193 | $subscription->clear_cache(); |
| 194 | 194 | |
| 195 | 195 | // Fire a hook. |
| 196 | - do_action( 'getpaid_delete_subscription', $subscription->get_id(), $subscription ); |
|
| 196 | + do_action('getpaid_delete_subscription', $subscription->get_id(), $subscription); |
|
| 197 | 197 | |
| 198 | - $subscription->set_id( 0 ); |
|
| 198 | + $subscription->set_id(0); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /* |
@@ -1,11 +1,11 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | function wpinv_subscription_init() { |
| 6 | 6 | return WPInv_Subscriptions::instance(); |
| 7 | 7 | } |
| 8 | -add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 ); |
|
| 8 | +add_action('plugins_loaded', 'wpinv_subscription_init', 100); |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * WPInv_Subscriptions Class. |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * Main WPInv_Subscriptions Instance |
| 21 | 21 | */ |
| 22 | 22 | public static function instance() { |
| 23 | - if ( ! isset( self::$instance ) ) { |
|
| 23 | + if (!isset(self::$instance)) { |
|
| 24 | 24 | self::$instance = new WPInv_Subscriptions; |
| 25 | 25 | |
| 26 | 26 | self::$instance->init(); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @since 1.0.0 |
| 36 | 36 | */ |
| 37 | - private function __construct(){ |
|
| 37 | + private function __construct() { |
|
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | private function setup_constants() { |
| 64 | 64 | |
| 65 | 65 | // Make sure CAL_GREGORIAN is defined. |
| 66 | - if ( ! defined( 'CAL_GREGORIAN' ) ) { |
|
| 67 | - define( 'CAL_GREGORIAN', 1 ); |
|
| 66 | + if (!defined('CAL_GREGORIAN')) { |
|
| 67 | + define('CAL_GREGORIAN', 1); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
@@ -76,15 +76,15 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | private function actions() { |
| 78 | 78 | |
| 79 | - add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 40 ); |
|
| 80 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
| 81 | - add_action( 'init', array( $this, 'wpinv_post_actions' ) ); |
|
| 82 | - add_action( 'init', array( $this, 'wpinv_get_actions' ) ); |
|
| 83 | - add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) ); |
|
| 84 | - add_action( 'getpaid_checkout_before_gateway', array( $this, 'add_subscription' ), -999 ); |
|
| 85 | - add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) ); |
|
| 86 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
| 87 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
| 79 | + add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 40); |
|
| 80 | + add_action('admin_notices', array($this, 'notices')); |
|
| 81 | + add_action('init', array($this, 'wpinv_post_actions')); |
|
| 82 | + add_action('init', array($this, 'wpinv_get_actions')); |
|
| 83 | + add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation')); |
|
| 84 | + add_action('getpaid_checkout_before_gateway', array($this, 'add_subscription'), -999); |
|
| 85 | + add_action('wpinv_subscriptions_front_notices', array($this, 'notices')); |
|
| 86 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
| 87 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | public function wpinv_subscriptions_list() { |
| 107 | 107 | add_submenu_page( |
| 108 | 108 | 'wpinv', |
| 109 | - __( 'Subscriptions', 'invoicing' ), |
|
| 110 | - __( 'Subscriptions', 'invoicing' ), |
|
| 109 | + __('Subscriptions', 'invoicing'), |
|
| 110 | + __('Subscriptions', 'invoicing'), |
|
| 111 | 111 | wpinv_get_capability(), |
| 112 | 112 | 'wpinv-subscriptions', |
| 113 | 113 | 'wpinv_subscriptions_page' |
@@ -116,37 +116,37 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | public function notices() { |
| 118 | 118 | |
| 119 | - if( empty( $_GET['wpinv-message'] ) ) { |
|
| 119 | + if (empty($_GET['wpinv-message'])) { |
|
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $type = 'updated'; |
| 124 | 124 | $message = ''; |
| 125 | 125 | |
| 126 | - switch( strtolower( $_GET['wpinv-message'] ) ) { |
|
| 126 | + switch (strtolower($_GET['wpinv-message'])) { |
|
| 127 | 127 | |
| 128 | 128 | case 'updated' : |
| 129 | 129 | |
| 130 | - $message = __( 'Subscription updated successfully.', 'invoicing' ); |
|
| 130 | + $message = __('Subscription updated successfully.', 'invoicing'); |
|
| 131 | 131 | |
| 132 | 132 | break; |
| 133 | 133 | |
| 134 | 134 | case 'deleted' : |
| 135 | 135 | |
| 136 | - $message = __( 'Subscription deleted successfully.', 'invoicing' ); |
|
| 136 | + $message = __('Subscription deleted successfully.', 'invoicing'); |
|
| 137 | 137 | |
| 138 | 138 | break; |
| 139 | 139 | |
| 140 | 140 | case 'cancelled' : |
| 141 | 141 | |
| 142 | - $message = __( 'Subscription cancelled successfully.', 'invoicing' ); |
|
| 142 | + $message = __('Subscription cancelled successfully.', 'invoicing'); |
|
| 143 | 143 | |
| 144 | 144 | break; |
| 145 | 145 | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - if ( ! empty( $message ) ) { |
|
| 149 | - echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>'; |
|
| 148 | + if (!empty($message)) { |
|
| 149 | + echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>'; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | } |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | * @return void |
| 160 | 160 | */ |
| 161 | 161 | function wpinv_get_actions() { |
| 162 | - if ( isset( $_GET['wpinv_action'] ) ) { |
|
| 163 | - do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET ); |
|
| 162 | + if (isset($_GET['wpinv_action'])) { |
|
| 163 | + do_action('wpinv_' . $_GET['wpinv_action'], $_GET); |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | 174 | function wpinv_post_actions() { |
| 175 | - if ( isset( $_POST['wpinv_action'] ) ) { |
|
| 176 | - do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST ); |
|
| 175 | + if (isset($_POST['wpinv_action'])) { |
|
| 176 | + do_action('wpinv_' . $_POST['wpinv_action'], $_POST); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
@@ -184,29 +184,29 @@ discard block |
||
| 184 | 184 | * @param int $frequency_count The frequency of the period. |
| 185 | 185 | * @return mixed|string|void |
| 186 | 186 | */ |
| 187 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) { |
|
| 187 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
| 188 | 188 | |
| 189 | 189 | $frequency = ''; |
| 190 | 190 | //Format period details |
| 191 | - switch ( strtolower( $period ) ) { |
|
| 191 | + switch (strtolower($period)) { |
|
| 192 | 192 | case 'day' : |
| 193 | 193 | case 'd' : |
| 194 | - $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
| 194 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
| 195 | 195 | break; |
| 196 | 196 | case 'week' : |
| 197 | 197 | case 'w' : |
| 198 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
| 198 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
| 199 | 199 | break; |
| 200 | 200 | case 'month' : |
| 201 | 201 | case 'm' : |
| 202 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
| 202 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
| 203 | 203 | break; |
| 204 | 204 | case 'year' : |
| 205 | 205 | case 'y' : |
| 206 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
| 206 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
| 207 | 207 | break; |
| 208 | 208 | default : |
| 209 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
| 209 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
| 210 | 210 | break; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -221,50 +221,50 @@ discard block |
||
| 221 | 221 | * @since 1.0.0 |
| 222 | 222 | * @return void |
| 223 | 223 | */ |
| 224 | - public function wpinv_process_cancellation( $data ) { |
|
| 224 | + public function wpinv_process_cancellation($data) { |
|
| 225 | 225 | |
| 226 | 226 | |
| 227 | - if( empty( $data['sub_id'] ) ) { |
|
| 227 | + if (empty($data['sub_id'])) { |
|
| 228 | 228 | return; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if( ! is_user_logged_in() ) { |
|
| 231 | + if (!is_user_logged_in()) { |
|
| 232 | 232 | return; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) { |
|
| 236 | - wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 235 | + if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) { |
|
| 236 | + wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403)); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - $data['sub_id'] = absint( $data['sub_id'] ); |
|
| 240 | - $subscription = new WPInv_Subscription( $data['sub_id'] ); |
|
| 239 | + $data['sub_id'] = absint($data['sub_id']); |
|
| 240 | + $subscription = new WPInv_Subscription($data['sub_id']); |
|
| 241 | 241 | |
| 242 | - if( ! $subscription->can_cancel() ) { |
|
| 243 | - wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 242 | + if (!$subscription->can_cancel()) { |
|
| 243 | + wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403)); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | try { |
| 247 | 247 | |
| 248 | - do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true ); |
|
| 248 | + do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true); |
|
| 249 | 249 | |
| 250 | 250 | $subscription->cancel(); |
| 251 | 251 | |
| 252 | - if( is_admin() ) { |
|
| 252 | + if (is_admin()) { |
|
| 253 | 253 | |
| 254 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) ); |
|
| 254 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id)); |
|
| 255 | 255 | exit; |
| 256 | 256 | |
| 257 | 257 | } else { |
| 258 | 258 | |
| 259 | - $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) ); |
|
| 260 | - $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription ); |
|
| 261 | - wp_safe_redirect( $redirect ); |
|
| 259 | + $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled'))); |
|
| 260 | + $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription); |
|
| 261 | + wp_safe_redirect($redirect); |
|
| 262 | 262 | exit; |
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - } catch ( Exception $e ) { |
|
| 267 | - wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) ); |
|
| 266 | + } catch (Exception $e) { |
|
| 267 | + wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403)); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | } |
@@ -277,33 +277,33 @@ discard block |
||
| 277 | 277 | * @since 1.0.0 |
| 278 | 278 | * @return void |
| 279 | 279 | */ |
| 280 | - public function add_subscription( $invoice ) { |
|
| 280 | + public function add_subscription($invoice) { |
|
| 281 | 281 | |
| 282 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 282 | + $invoice = new WPInv_Invoice($invoice); |
|
| 283 | 283 | |
| 284 | 284 | // Abort if it is not recurring. |
| 285 | - if ( ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
| 285 | + if (!$invoice->is_recurring() || $invoice->is_renewal()) { |
|
| 286 | 286 | return; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // Should we create a subscription for the invoice? |
| 290 | - if ( apply_filters( 'wpinv_skip_invoice_subscription_creation', false, $invoice ) ) { |
|
| 290 | + if (apply_filters('wpinv_skip_invoice_subscription_creation', false, $invoice)) { |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | // Get the recurring item. |
| 295 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 295 | + $subscription_item = $invoice->get_recurring(true); |
|
| 296 | 296 | |
| 297 | 297 | // Prepare the subscription details. |
| 298 | - $period = $subscription_item->get_recurring_period( true ); |
|
| 298 | + $period = $subscription_item->get_recurring_period(true); |
|
| 299 | 299 | $interval = $subscription_item->get_recurring_interval(); |
| 300 | 300 | $add_period = $interval . ' ' . $period; |
| 301 | 301 | $trial_period = ''; |
| 302 | 302 | |
| 303 | - if ( $invoice->has_free_trial() ) { |
|
| 303 | + if ($invoice->has_free_trial()) { |
|
| 304 | 304 | |
| 305 | - if ( $subscription_item->has_free_trial() ) { |
|
| 306 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
| 305 | + if ($subscription_item->has_free_trial()) { |
|
| 306 | + $trial_period = $subscription_item->get_trial_period(true); |
|
| 307 | 307 | $free_interval = $subscription_item->get_trial_interval(); |
| 308 | 308 | } else { |
| 309 | 309 | $trial_period = $period; |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Calculate the next renewal date. |
| 319 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+ $add_period", current_time( 'timestamp' ) ) ); |
|
| 319 | + $expiration = date('Y-m-d H:i:s', strtotime("+ $add_period", current_time('timestamp'))); |
|
| 320 | 320 | |
| 321 | 321 | // Subscription arguments. |
| 322 | 322 | $args = array( |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | 'initial_amount' => $invoice->get_initial_total(), |
| 330 | 330 | 'recurring_amount' => $invoice->get_recurring_total(), |
| 331 | 331 | 'bill_times' => $subscription_item->get_recurring_limit(), |
| 332 | - 'created' => current_time( 'mysql' ), |
|
| 332 | + 'created' => current_time('mysql'), |
|
| 333 | 333 | 'expiration' => $expiration, |
| 334 | 334 | 'trial_period' => $trial_period, |
| 335 | 335 | 'profile_id' => '', |
@@ -337,19 +337,19 @@ discard block |
||
| 337 | 337 | ); |
| 338 | 338 | |
| 339 | 339 | // Create or update the subscription. |
| 340 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 340 | + $subscription = wpinv_get_subscription($invoice); |
|
| 341 | 341 | |
| 342 | - if ( empty( $subscription ) ) { |
|
| 342 | + if (empty($subscription)) { |
|
| 343 | 343 | |
| 344 | 344 | $subscription = new WPInv_Subscription(); |
| 345 | - $subscription->create( $args ); |
|
| 345 | + $subscription->create($args); |
|
| 346 | 346 | |
| 347 | 347 | } else { |
| 348 | 348 | |
| 349 | 349 | |
| 350 | - unset( $args['transaction_id'] ); |
|
| 351 | - unset( $args['profile_id'] ); |
|
| 352 | - $subscription->update( $args ); |
|
| 350 | + unset($args['transaction_id']); |
|
| 351 | + unset($args['profile_id']); |
|
| 352 | + $subscription->update($args); |
|
| 353 | 353 | |
| 354 | 354 | } |
| 355 | 355 | |
@@ -362,21 +362,21 @@ discard block |
||
| 362 | 362 | * @param array $data |
| 363 | 363 | * @since 1.0.19 |
| 364 | 364 | */ |
| 365 | - public function admin_update_single_subscription( $args ) { |
|
| 365 | + public function admin_update_single_subscription($args) { |
|
| 366 | 366 | |
| 367 | 367 | // Ensure the subscription exists and that a status has been given. |
| 368 | - if ( empty( $args['subscription_id'] ) || empty( $args['subscription_status'] ) ) { |
|
| 368 | + if (empty($args['subscription_id']) || empty($args['subscription_status'])) { |
|
| 369 | 369 | return; |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | // Retrieve the subscriptions. |
| 373 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
| 373 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
| 374 | 374 | |
| 375 | - if ( $subscription->get_id() ) { |
|
| 375 | + if ($subscription->get_id()) { |
|
| 376 | 376 | |
| 377 | - $subscription->set_status( $args['subscription_status'] ); |
|
| 377 | + $subscription->set_status($args['subscription_status']); |
|
| 378 | 378 | $subscription->save(); |
| 379 | - getpaid_admin()->show_info( __( 'Your changes have been saved', 'invoicing' ) ); |
|
| 379 | + getpaid_admin()->show_info(__('Your changes have been saved', 'invoicing')); |
|
| 380 | 380 | |
| 381 | 381 | } |
| 382 | 382 | |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * @param array $data |
| 389 | 389 | * @since 1.0.19 |
| 390 | 390 | */ |
| 391 | - public function admin_renew_single_subscription( $args ) { |
|
| 391 | + public function admin_renew_single_subscription($args) { |
|
| 392 | 392 | |
| 393 | 393 | // Ensure the subscription exists and that a status has been given. |
| 394 | - if ( empty( $args['id'] ) ) { |
|
| 394 | + if (empty($args['id'])) { |
|
| 395 | 395 | return; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | // Retrieve the subscriptions. |
| 399 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
| 399 | + $subscription = new WPInv_Subscription($args['id']); |
|
| 400 | 400 | |
| 401 | - if ( $subscription->get_id() ) { |
|
| 401 | + if ($subscription->get_id()) { |
|
| 402 | 402 | |
| 403 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
| 403 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
| 404 | 404 | |
| 405 | - if ( $subscription->add_payment( $args ) ) { |
|
| 405 | + if ($subscription->add_payment($args)) { |
|
| 406 | 406 | $subscription->renew(); |
| 407 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
| 407 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
| 408 | 408 | } else { |
| 409 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
| 409 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | wp_safe_redirect( |
@@ -7,86 +7,86 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_item_quantities_enabled() { |
| 15 | - $ret = wpinv_get_option( 'item_quantities', true ); |
|
| 15 | + $ret = wpinv_get_option('item_quantities', true); |
|
| 16 | 16 | |
| 17 | - return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret ); |
|
| 17 | + return (bool) apply_filters('wpinv_item_quantities_enabled', $ret); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function wpinv_get_ip() { |
| 21 | 21 | $ip = '127.0.0.1'; |
| 22 | 22 | |
| 23 | - if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
| 24 | - $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ); |
|
| 25 | - } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
| 26 | - $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ); |
|
| 27 | - } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) { |
|
| 28 | - $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ); |
|
| 23 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 24 | + $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
|
| 25 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 26 | + $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
|
| 27 | + } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
| 28 | + $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - return apply_filters( 'wpinv_get_ip', $ip ); |
|
| 31 | + return apply_filters('wpinv_get_ip', $ip); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | function wpinv_get_user_agent() { |
| 35 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
| 36 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
| 35 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
| 36 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
| 37 | 37 | } else { |
| 38 | 38 | $user_agent = ''; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
| 41 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | -function wpinv_sanitize_amount( $amount, $decimals = NULL ) { |
|
| 44 | +function wpinv_sanitize_amount($amount, $decimals = NULL) { |
|
| 45 | 45 | $is_negative = false; |
| 46 | 46 | $thousands_sep = wpinv_thousands_separator(); |
| 47 | 47 | $decimal_sep = wpinv_decimal_separator(); |
| 48 | - if ( $decimals === NULL ) { |
|
| 48 | + if ($decimals === NULL) { |
|
| 49 | 49 | $decimals = wpinv_decimals(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Sanitize the amount |
| 53 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
| 54 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 55 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
| 56 | - } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
| 57 | - $amount = str_replace( '.', '', $amount ); |
|
| 53 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
| 54 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 55 | + $amount = str_replace($thousands_sep, '', $amount); |
|
| 56 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
| 57 | + $amount = str_replace('.', '', $amount); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
| 61 | - } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 62 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
| 60 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
| 61 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 62 | + $amount = str_replace($thousands_sep, '', $amount); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if( $amount < 0 ) { |
|
| 65 | + if ($amount < 0) { |
|
| 66 | 66 | $is_negative = true; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
| 69 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
| 70 | 70 | |
| 71 | - $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount ); |
|
| 72 | - $amount = number_format( (double) $amount, absint( $decimals ), '.', '' ); |
|
| 71 | + $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount); |
|
| 72 | + $amount = number_format((double) $amount, absint($decimals), '.', ''); |
|
| 73 | 73 | |
| 74 | - if( $is_negative ) { |
|
| 74 | + if ($is_negative) { |
|
| 75 | 75 | $amount *= -1; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals ); |
|
| 78 | + return apply_filters('wpinv_sanitize_amount', $amount, $decimals); |
|
| 79 | 79 | } |
| 80 | -add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
| 80 | +add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
| 81 | 81 | |
| 82 | -function wpinv_round_amount( $amount, $decimals = NULL ) { |
|
| 83 | - if ( $decimals === NULL ) { |
|
| 82 | +function wpinv_round_amount($amount, $decimals = NULL) { |
|
| 83 | + if ($decimals === NULL) { |
|
| 84 | 84 | $decimals = wpinv_decimals(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) ); |
|
| 87 | + $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals))); |
|
| 88 | 88 | |
| 89 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
| 89 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -95,32 +95,32 @@ discard block |
||
| 95 | 95 | * @since 1.0.19 |
| 96 | 96 | * @return array |
| 97 | 97 | */ |
| 98 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
| 98 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
| 99 | 99 | $invoice_statuses = array( |
| 100 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
| 101 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
| 102 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
| 103 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
| 104 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
| 105 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
| 106 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
| 107 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
| 100 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
| 101 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
| 102 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
| 103 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
| 104 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
| 105 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
| 106 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
| 107 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
| 108 | 108 | ); |
| 109 | 109 | |
| 110 | - if ( $draft ) { |
|
| 111 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
| 110 | + if ($draft) { |
|
| 111 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if ( $trashed ) { |
|
| 115 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
| 114 | + if ($trashed) { |
|
| 115 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
| 118 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | -function wpinv_status_nicename( $status ) { |
|
| 122 | - $statuses = wpinv_get_invoice_statuses( true, true ); |
|
| 123 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
| 121 | +function wpinv_status_nicename($status) { |
|
| 122 | + $statuses = wpinv_get_invoice_statuses(true, true); |
|
| 123 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
| 124 | 124 | |
| 125 | 125 | return $status; |
| 126 | 126 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * Retrieves the default currency code. |
| 130 | 130 | */ |
| 131 | 131 | function wpinv_get_currency() { |
| 132 | - return apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
| 132 | + return apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -137,61 +137,61 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @param string|null $currency The currency code. Defaults to the default currency. |
| 139 | 139 | */ |
| 140 | -function wpinv_currency_symbol( $currency = null ) { |
|
| 140 | +function wpinv_currency_symbol($currency = null) { |
|
| 141 | 141 | |
| 142 | 142 | // Prepare the currency. |
| 143 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
| 143 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
| 144 | 144 | |
| 145 | 145 | // Fetch all symbols. |
| 146 | 146 | $symbols = wpinv_get_currency_symbols(); |
| 147 | 147 | |
| 148 | 148 | // Fetch this currencies symbol. |
| 149 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency; |
|
| 149 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
| 150 | 150 | |
| 151 | 151 | // Filter the symbol. |
| 152 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
| 152 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | function wpinv_currency_position() { |
| 156 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
| 156 | + $position = wpinv_get_option('currency_position', 'left'); |
|
| 157 | 157 | |
| 158 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
| 158 | + return apply_filters('wpinv_currency_position', $position); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | function wpinv_thousands_separator() { |
| 162 | - $thousand_sep = wpinv_get_option( 'thousands_separator', ',' ); |
|
| 162 | + $thousand_sep = wpinv_get_option('thousands_separator', ','); |
|
| 163 | 163 | |
| 164 | - return apply_filters( 'wpinv_thousands_separator', $thousand_sep ); |
|
| 164 | + return apply_filters('wpinv_thousands_separator', $thousand_sep); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | function wpinv_decimal_separator() { |
| 168 | - $decimal_sep = wpinv_get_option( 'decimal_separator', '.' ); |
|
| 168 | + $decimal_sep = wpinv_get_option('decimal_separator', '.'); |
|
| 169 | 169 | |
| 170 | - return apply_filters( 'wpinv_decimal_separator', $decimal_sep ); |
|
| 170 | + return apply_filters('wpinv_decimal_separator', $decimal_sep); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | function wpinv_decimals() { |
| 174 | - $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) ); |
|
| 174 | + $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2)); |
|
| 175 | 175 | |
| 176 | - return absint( $decimals ); |
|
| 176 | + return absint($decimals); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | 180 | * Retrieves a list of all supported currencies. |
| 181 | 181 | */ |
| 182 | 182 | function wpinv_get_currencies() { |
| 183 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
| 183 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
| 187 | 187 | * Retrieves a list of all currency symbols. |
| 188 | 188 | */ |
| 189 | 189 | function wpinv_get_currency_symbols() { |
| 190 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
| 190 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
| 194 | - if( empty( $currency ) ) { |
|
| 193 | +function wpinv_price($amount = '', $currency = '') { |
|
| 194 | + if (empty($currency)) { |
|
| 195 | 195 | $currency = wpinv_get_currency(); |
| 196 | 196 | } |
| 197 | 197 | |
@@ -199,14 +199,14 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $negative = $amount < 0; |
| 201 | 201 | |
| 202 | - if ( $negative ) { |
|
| 203 | - $amount = substr( $amount, 1 ); |
|
| 202 | + if ($negative) { |
|
| 203 | + $amount = substr($amount, 1); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - $symbol = wpinv_currency_symbol( $currency ); |
|
| 206 | + $symbol = wpinv_currency_symbol($currency); |
|
| 207 | 207 | |
| 208 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
| 209 | - switch ( $currency ) { |
|
| 208 | + if ($position == 'left' || $position == 'left_space') { |
|
| 209 | + switch ($currency) { |
|
| 210 | 210 | case "GBP" : |
| 211 | 211 | case "BRL" : |
| 212 | 212 | case "EUR" : |
@@ -218,15 +218,15 @@ discard block |
||
| 218 | 218 | case "NZD" : |
| 219 | 219 | case "SGD" : |
| 220 | 220 | case "JPY" : |
| 221 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 221 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 222 | 222 | break; |
| 223 | 223 | default : |
| 224 | 224 | //$price = $currency . ' ' . $amount; |
| 225 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 225 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 226 | 226 | break; |
| 227 | 227 | } |
| 228 | 228 | } else { |
| 229 | - switch ( $currency ) { |
|
| 229 | + switch ($currency) { |
|
| 230 | 230 | case "GBP" : |
| 231 | 231 | case "BRL" : |
| 232 | 232 | case "EUR" : |
@@ -237,83 +237,83 @@ discard block |
||
| 237 | 237 | case "MXN" : |
| 238 | 238 | case "SGD" : |
| 239 | 239 | case "JPY" : |
| 240 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 240 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 241 | 241 | break; |
| 242 | 242 | default : |
| 243 | 243 | //$price = $amount . ' ' . $currency; |
| 244 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 244 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 245 | 245 | break; |
| 246 | 246 | } |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if ( $negative ) { |
|
| 249 | + if ($negative) { |
|
| 250 | 250 | $price = '-' . $price; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
| 253 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
| 254 | 254 | |
| 255 | 255 | return $price; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
| 258 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
| 259 | 259 | $thousands_sep = wpinv_thousands_separator(); |
| 260 | 260 | $decimal_sep = wpinv_decimal_separator(); |
| 261 | 261 | |
| 262 | - if ( $decimals === NULL ) { |
|
| 262 | + if ($decimals === NULL) { |
|
| 263 | 263 | $decimals = wpinv_decimals(); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
| 267 | - $whole = substr( $amount, 0, $sep_found ); |
|
| 268 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
| 266 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
| 267 | + $whole = substr($amount, 0, $sep_found); |
|
| 268 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
| 269 | 269 | $amount = $whole . '.' . $part; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 273 | - $amount = str_replace( ',', '', $amount ); |
|
| 272 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 273 | + $amount = str_replace(',', '', $amount); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 277 | - $amount = str_replace( ' ', '', $amount ); |
|
| 276 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 277 | + $amount = str_replace(' ', '', $amount); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( empty( $amount ) ) { |
|
| 280 | + if (empty($amount)) { |
|
| 281 | 281 | $amount = 0; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
| 285 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
| 284 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
| 285 | + $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep); |
|
| 286 | 286 | |
| 287 | - if ( $calculate ) { |
|
| 288 | - if ( $thousands_sep === "," ) { |
|
| 289 | - $formatted = str_replace( ",", "", $formatted ); |
|
| 287 | + if ($calculate) { |
|
| 288 | + if ($thousands_sep === ",") { |
|
| 289 | + $formatted = str_replace(",", "", $formatted); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - if ( $decimal_sep === "," ) { |
|
| 293 | - $formatted = str_replace( ",", ".", $formatted ); |
|
| 292 | + if ($decimal_sep === ",") { |
|
| 293 | + $formatted = str_replace(",", ".", $formatted); |
|
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
| 297 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
| 298 | 298 | } |
| 299 | -add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
| 299 | +add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
| 300 | 300 | |
| 301 | -function wpinv_sanitize_key( $key ) { |
|
| 301 | +function wpinv_sanitize_key($key) { |
|
| 302 | 302 | $raw_key = $key; |
| 303 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
| 303 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
| 304 | 304 | |
| 305 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
| 305 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | -function wpinv_get_file_extension( $str ) { |
|
| 309 | - $parts = explode( '.', $str ); |
|
| 310 | - return end( $parts ); |
|
| 308 | +function wpinv_get_file_extension($str) { |
|
| 309 | + $parts = explode('.', $str); |
|
| 310 | + return end($parts); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | -function wpinv_string_is_image_url( $str ) { |
|
| 314 | - $ext = wpinv_get_file_extension( $str ); |
|
| 313 | +function wpinv_string_is_image_url($str) { |
|
| 314 | + $ext = wpinv_get_file_extension($str); |
|
| 315 | 315 | |
| 316 | - switch ( strtolower( $ext ) ) { |
|
| 316 | + switch (strtolower($ext)) { |
|
| 317 | 317 | case 'jpeg'; |
| 318 | 318 | case 'jpg'; |
| 319 | 319 | $return = true; |
@@ -329,33 +329,33 @@ discard block |
||
| 329 | 329 | break; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
| 332 | + return (bool) apply_filters('wpinv_string_is_image', $return, $str); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
| 336 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
| 335 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
| 336 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
| 337 | 337 | |
| 338 | - if ( true === $should_log ) { |
|
| 338 | + if (true === $should_log) { |
|
| 339 | 339 | $label = ''; |
| 340 | - if ( $file && $file !== '' ) { |
|
| 341 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
| 340 | + if ($file && $file !== '') { |
|
| 341 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if ( $title && $title !== '' ) { |
|
| 344 | + if ($title && $title !== '') { |
|
| 345 | 345 | $label = $label !== '' ? $label . ' ' : ''; |
| 346 | 346 | $label .= $title . ' '; |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
| 349 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
| 350 | 350 | |
| 351 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
| 352 | - error_log( $label . print_r( $log, true ) ); |
|
| 351 | + if (is_array($log) || is_object($log)) { |
|
| 352 | + error_log($label . print_r($log, true)); |
|
| 353 | 353 | } else { |
| 354 | - error_log( $label . $log ); |
|
| 354 | + error_log($label . $log); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - error_log( wp_debug_backtrace_summary() ); |
|
| 358 | - if ( $exit ) { |
|
| 357 | + error_log(wp_debug_backtrace_summary()); |
|
| 358 | + if ($exit) { |
|
| 359 | 359 | exit; |
| 360 | 360 | } |
| 361 | 361 | } |
@@ -363,32 +363,32 @@ discard block |
||
| 363 | 363 | |
| 364 | 364 | function wpinv_is_ajax_disabled() { |
| 365 | 365 | $retval = false; |
| 366 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
| 366 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
| 369 | +function wpinv_get_current_page_url($nocache = false) { |
|
| 370 | 370 | global $wp; |
| 371 | 371 | |
| 372 | - if ( get_option( 'permalink_structure' ) ) { |
|
| 373 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
| 372 | + if (get_option('permalink_structure')) { |
|
| 373 | + $base = trailingslashit(home_url($wp->request)); |
|
| 374 | 374 | } else { |
| 375 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
| 376 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
| 375 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
| 376 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | $scheme = is_ssl() ? 'https' : 'http'; |
| 380 | - $uri = set_url_scheme( $base, $scheme ); |
|
| 380 | + $uri = set_url_scheme($base, $scheme); |
|
| 381 | 381 | |
| 382 | - if ( is_front_page() ) { |
|
| 383 | - $uri = home_url( '/' ); |
|
| 384 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
| 382 | + if (is_front_page()) { |
|
| 383 | + $uri = home_url('/'); |
|
| 384 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
| 385 | 385 | $uri = wpinv_get_checkout_uri(); |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
| 388 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
| 389 | 389 | |
| 390 | - if ( $nocache ) { |
|
| 391 | - $uri = wpinv_add_cache_busting( $uri ); |
|
| 390 | + if ($nocache) { |
|
| 391 | + $uri = wpinv_add_cache_busting($uri); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | return $uri; |
@@ -401,46 +401,46 @@ discard block |
||
| 401 | 401 | * @param string $name Constant name. |
| 402 | 402 | * @param mixed $value Value. |
| 403 | 403 | */ |
| 404 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
| 405 | - if ( ! defined( $name ) ) { |
|
| 406 | - define( $name, $value ); |
|
| 404 | +function getpaid_maybe_define_constant($name, $value) { |
|
| 405 | + if (!defined($name)) { |
|
| 406 | + define($name, $value); |
|
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | function wpinv_get_php_arg_separator_output() { |
| 411 | - return ini_get( 'arg_separator.output' ); |
|
| 411 | + return ini_get('arg_separator.output'); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | -function wpinv_rgb_from_hex( $color ) { |
|
| 415 | - $color = str_replace( '#', '', $color ); |
|
| 414 | +function wpinv_rgb_from_hex($color) { |
|
| 415 | + $color = str_replace('#', '', $color); |
|
| 416 | 416 | |
| 417 | 417 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
| 418 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
| 419 | - if ( empty( $color ) ) { |
|
| 418 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
| 419 | + if (empty($color)) { |
|
| 420 | 420 | return NULL; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - $color = str_split( $color ); |
|
| 423 | + $color = str_split($color); |
|
| 424 | 424 | |
| 425 | 425 | $rgb = array(); |
| 426 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
| 427 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
| 428 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
| 426 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
| 427 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
| 428 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
| 429 | 429 | |
| 430 | 430 | return $rgb; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
| 434 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 433 | +function wpinv_hex_darker($color, $factor = 30) { |
|
| 434 | + $base = wpinv_rgb_from_hex($color); |
|
| 435 | 435 | $color = '#'; |
| 436 | 436 | |
| 437 | - foreach ( $base as $k => $v ) { |
|
| 437 | + foreach ($base as $k => $v) { |
|
| 438 | 438 | $amount = $v / 100; |
| 439 | - $amount = round( $amount * $factor ); |
|
| 439 | + $amount = round($amount * $factor); |
|
| 440 | 440 | $new_decimal = $v - $amount; |
| 441 | 441 | |
| 442 | - $new_hex_component = dechex( $new_decimal ); |
|
| 443 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 442 | + $new_hex_component = dechex($new_decimal); |
|
| 443 | + if (strlen($new_hex_component) < 2) { |
|
| 444 | 444 | $new_hex_component = "0" . $new_hex_component; |
| 445 | 445 | } |
| 446 | 446 | $color .= $new_hex_component; |
@@ -449,18 +449,18 @@ discard block |
||
| 449 | 449 | return $color; |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
| 453 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 452 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
| 453 | + $base = wpinv_rgb_from_hex($color); |
|
| 454 | 454 | $color = '#'; |
| 455 | 455 | |
| 456 | - foreach ( $base as $k => $v ) { |
|
| 456 | + foreach ($base as $k => $v) { |
|
| 457 | 457 | $amount = 255 - $v; |
| 458 | 458 | $amount = $amount / 100; |
| 459 | - $amount = round( $amount * $factor ); |
|
| 459 | + $amount = round($amount * $factor); |
|
| 460 | 460 | $new_decimal = $v + $amount; |
| 461 | 461 | |
| 462 | - $new_hex_component = dechex( $new_decimal ); |
|
| 463 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 462 | + $new_hex_component = dechex($new_decimal); |
|
| 463 | + if (strlen($new_hex_component) < 2) { |
|
| 464 | 464 | $new_hex_component = "0" . $new_hex_component; |
| 465 | 465 | } |
| 466 | 466 | $color .= $new_hex_component; |
@@ -469,22 +469,22 @@ discard block |
||
| 469 | 469 | return $color; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
| 473 | - $hex = str_replace( '#', '', $color ); |
|
| 472 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
| 473 | + $hex = str_replace('#', '', $color); |
|
| 474 | 474 | |
| 475 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
| 476 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
| 477 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
| 475 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
| 476 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
| 477 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
| 478 | 478 | |
| 479 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
| 479 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
| 480 | 480 | |
| 481 | 481 | return $brightness > 155 ? $dark : $light; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | -function wpinv_format_hex( $hex ) { |
|
| 485 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
| 484 | +function wpinv_format_hex($hex) { |
|
| 485 | + $hex = trim(str_replace('#', '', $hex)); |
|
| 486 | 486 | |
| 487 | - if ( strlen( $hex ) == 3 ) { |
|
| 487 | + if (strlen($hex) == 3) { |
|
| 488 | 488 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
| 489 | 489 | } |
| 490 | 490 | |
@@ -504,12 +504,12 @@ discard block |
||
| 504 | 504 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 505 | 505 | * @return string |
| 506 | 506 | */ |
| 507 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
| 508 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 509 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
| 507 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
| 508 | + if (function_exists('mb_strimwidth')) { |
|
| 509 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
| 512 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -521,28 +521,28 @@ discard block |
||
| 521 | 521 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 522 | 522 | * @return int Returns the number of characters in string. |
| 523 | 523 | */ |
| 524 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
| 525 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 526 | - return mb_strlen( $str, $encoding ); |
|
| 524 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
| 525 | + if (function_exists('mb_strlen')) { |
|
| 526 | + return mb_strlen($str, $encoding); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - return strlen( $str ); |
|
| 529 | + return strlen($str); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
| 533 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
| 534 | - return mb_strtolower( $str, $encoding ); |
|
| 532 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
| 533 | + if (function_exists('mb_strtolower')) { |
|
| 534 | + return mb_strtolower($str, $encoding); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - return strtolower( $str ); |
|
| 537 | + return strtolower($str); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
| 541 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
| 542 | - return mb_strtoupper( $str, $encoding ); |
|
| 540 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
| 541 | + if (function_exists('mb_strtoupper')) { |
|
| 542 | + return mb_strtoupper($str, $encoding); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - return strtoupper( $str ); |
|
| 545 | + return strtoupper($str); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -556,12 +556,12 @@ discard block |
||
| 556 | 556 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 557 | 557 | * @return int Returns the position of the first occurrence of search in the string. |
| 558 | 558 | */ |
| 559 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 560 | - if ( function_exists( 'mb_strpos' ) ) { |
|
| 561 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
| 559 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 560 | + if (function_exists('mb_strpos')) { |
|
| 561 | + return mb_strpos($str, $find, $offset, $encoding); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | - return strpos( $str, $find, $offset ); |
|
| 564 | + return strpos($str, $find, $offset); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -575,12 +575,12 @@ discard block |
||
| 575 | 575 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 576 | 576 | * @return int Returns the position of the last occurrence of search. |
| 577 | 577 | */ |
| 578 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 579 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
| 580 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
| 578 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 579 | + if (function_exists('mb_strrpos')) { |
|
| 580 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - return strrpos( $str, $find, $offset ); |
|
| 583 | + return strrpos($str, $find, $offset); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -595,16 +595,16 @@ discard block |
||
| 595 | 595 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 596 | 596 | * @return string |
| 597 | 597 | */ |
| 598 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
| 599 | - if ( function_exists( 'mb_substr' ) ) { |
|
| 600 | - if ( $length === null ) { |
|
| 601 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 598 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
| 599 | + if (function_exists('mb_substr')) { |
|
| 600 | + if ($length === null) { |
|
| 601 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 602 | 602 | } else { |
| 603 | - return mb_substr( $str, $start, $length, $encoding ); |
|
| 603 | + return mb_substr($str, $start, $length, $encoding); |
|
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | - return substr( $str, $start, $length ); |
|
| 607 | + return substr($str, $start, $length); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | /** |
@@ -616,48 +616,48 @@ discard block |
||
| 616 | 616 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 617 | 617 | * @return string The width of string. |
| 618 | 618 | */ |
| 619 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
| 620 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
| 621 | - return mb_strwidth( $str, $encoding ); |
|
| 619 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
| 620 | + if (function_exists('mb_strwidth')) { |
|
| 621 | + return mb_strwidth($str, $encoding); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
| 624 | + return wpinv_utf8_strlen($str, $encoding); |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
| 628 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 629 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
| 627 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
| 628 | + if (function_exists('mb_strlen')) { |
|
| 629 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
| 630 | 630 | $str_end = ""; |
| 631 | 631 | |
| 632 | - if ( $lower_str_end ) { |
|
| 633 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
| 632 | + if ($lower_str_end) { |
|
| 633 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
| 634 | 634 | } else { |
| 635 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 635 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | return $first_letter . $str_end; |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - return ucfirst( $str ); |
|
| 641 | + return ucfirst($str); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
| 645 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
| 646 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
| 644 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
| 645 | + if (function_exists('mb_convert_case')) { |
|
| 646 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - return ucwords( $str ); |
|
| 649 | + return ucwords($str); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | -function wpinv_period_in_days( $period, $unit ) { |
|
| 653 | - $period = absint( $period ); |
|
| 652 | +function wpinv_period_in_days($period, $unit) { |
|
| 653 | + $period = absint($period); |
|
| 654 | 654 | |
| 655 | - if ( $period > 0 ) { |
|
| 656 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
| 655 | + if ($period > 0) { |
|
| 656 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
| 657 | 657 | $period = $period * 7; |
| 658 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
| 658 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
| 659 | 659 | $period = $period * 30; |
| 660 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
| 660 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
| 661 | 661 | $period = $period * 365; |
| 662 | 662 | } |
| 663 | 663 | } |
@@ -665,14 +665,14 @@ discard block |
||
| 665 | 665 | return $period; |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
| 669 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
| 670 | - return cal_days_in_month( $calendar, $month, $year ); |
|
| 668 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
| 669 | + if (function_exists('cal_days_in_month')) { |
|
| 670 | + return cal_days_in_month($calendar, $month, $year); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | // Fallback in case the calendar extension is not loaded in PHP |
| 674 | 674 | // Only supports Gregorian calendar |
| 675 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
| 675 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -683,11 +683,11 @@ discard block |
||
| 683 | 683 | * |
| 684 | 684 | * @return string |
| 685 | 685 | */ |
| 686 | -function wpi_help_tip( $tip, $allow_html = false ) { |
|
| 687 | - if ( $allow_html ) { |
|
| 688 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
| 686 | +function wpi_help_tip($tip, $allow_html = false) { |
|
| 687 | + if ($allow_html) { |
|
| 688 | + $tip = wpi_sanitize_tooltip($tip); |
|
| 689 | 689 | } else { |
| 690 | - $tip = esc_attr( $tip ); |
|
| 690 | + $tip = esc_attr($tip); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -701,8 +701,8 @@ discard block |
||
| 701 | 701 | * @param string $var |
| 702 | 702 | * @return string |
| 703 | 703 | */ |
| 704 | -function wpi_sanitize_tooltip( $var ) { |
|
| 705 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 704 | +function wpi_sanitize_tooltip($var) { |
|
| 705 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
| 706 | 706 | 'br' => array(), |
| 707 | 707 | 'em' => array(), |
| 708 | 708 | 'strong' => array(), |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | 'li' => array(), |
| 713 | 713 | 'ol' => array(), |
| 714 | 714 | 'p' => array(), |
| 715 | - ) ) ); |
|
| 715 | + ))); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /** |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | */ |
| 723 | 723 | function wpinv_get_screen_ids() { |
| 724 | 724 | |
| 725 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
| 725 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
| 726 | 726 | |
| 727 | 727 | $screen_ids = array( |
| 728 | 728 | 'toplevel_page_' . $screen_id, |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | 'invoicing_page_wpi-addons', |
| 741 | 741 | ); |
| 742 | 742 | |
| 743 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
| 743 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -751,14 +751,14 @@ discard block |
||
| 751 | 751 | * @param array|string $list List of values. |
| 752 | 752 | * @return array Sanitized array of values. |
| 753 | 753 | */ |
| 754 | -function wpinv_parse_list( $list ) { |
|
| 754 | +function wpinv_parse_list($list) { |
|
| 755 | 755 | |
| 756 | - if ( empty( $list ) ) { |
|
| 756 | + if (empty($list)) { |
|
| 757 | 757 | $list = array(); |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | - if ( ! is_array( $list ) ) { |
|
| 761 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 760 | + if (!is_array($list)) { |
|
| 761 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | return $list; |
@@ -772,16 +772,16 @@ discard block |
||
| 772 | 772 | * @param string $key Type of data to fetch. |
| 773 | 773 | * @return mixed Fetched data. |
| 774 | 774 | */ |
| 775 | -function wpinv_get_data( $key ) { |
|
| 775 | +function wpinv_get_data($key) { |
|
| 776 | 776 | |
| 777 | 777 | // Try fetching it from the cache. |
| 778 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
| 779 | - if( $data ) { |
|
| 778 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
| 779 | + if ($data) { |
|
| 780 | 780 | return $data; |
| 781 | 781 | } |
| 782 | 782 | |
| 783 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
| 784 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
| 783 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
| 784 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
| 785 | 785 | |
| 786 | 786 | return $data; |
| 787 | 787 | } |
@@ -795,10 +795,10 @@ discard block |
||
| 795 | 795 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 796 | 796 | * @return mixed Fetched data. |
| 797 | 797 | */ |
| 798 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
| 798 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
| 799 | 799 | |
| 800 | - if ( ! empty( $options ) && $first_empty ) { |
|
| 801 | - return array_merge( array( '' => '' ), $options ); |
|
| 800 | + if (!empty($options) && $first_empty) { |
|
| 801 | + return array_merge(array('' => ''), $options); |
|
| 802 | 802 | } |
| 803 | 803 | return $options; |
| 804 | 804 | |
@@ -810,21 +810,21 @@ discard block |
||
| 810 | 810 | * @param mixed $var Data to sanitize. |
| 811 | 811 | * @return string|array |
| 812 | 812 | */ |
| 813 | -function wpinv_clean( $var ) { |
|
| 813 | +function wpinv_clean($var) { |
|
| 814 | 814 | |
| 815 | - if ( is_array( $var ) ) { |
|
| 816 | - return array_map( 'wpinv_clean', $var ); |
|
| 815 | + if (is_array($var)) { |
|
| 816 | + return array_map('wpinv_clean', $var); |
|
| 817 | 817 | } |
| 818 | 818 | |
| 819 | - if ( is_object( $var ) ) { |
|
| 820 | - $object_vars = get_object_vars( $var ); |
|
| 821 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
| 822 | - $var->$property_name = wpinv_clean( $property_value ); |
|
| 819 | + if (is_object($var)) { |
|
| 820 | + $object_vars = get_object_vars($var); |
|
| 821 | + foreach ($object_vars as $property_name => $property_value) { |
|
| 822 | + $var->$property_name = wpinv_clean($property_value); |
|
| 823 | 823 | } |
| 824 | 824 | return $var; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | - return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
|
| 827 | + return is_string($var) ? sanitize_text_field($var) : $var; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -833,43 +833,43 @@ discard block |
||
| 833 | 833 | * @param string $str Data to convert. |
| 834 | 834 | * @return string|array |
| 835 | 835 | */ |
| 836 | -function getpaid_convert_price_string_to_options( $str ) { |
|
| 836 | +function getpaid_convert_price_string_to_options($str) { |
|
| 837 | 837 | |
| 838 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
| 839 | - $options = array(); |
|
| 838 | + $raw_options = array_map('trim', explode(',', $str)); |
|
| 839 | + $options = array(); |
|
| 840 | 840 | |
| 841 | - foreach ( $raw_options as $option ) { |
|
| 841 | + foreach ($raw_options as $option) { |
|
| 842 | 842 | |
| 843 | - if ( '' == $option ) { |
|
| 843 | + if ('' == $option) { |
|
| 844 | 844 | continue; |
| 845 | 845 | } |
| 846 | 846 | |
| 847 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
| 847 | + $option = array_map('trim', explode('|', $option)); |
|
| 848 | 848 | |
| 849 | 849 | $price = null; |
| 850 | 850 | $label = null; |
| 851 | 851 | |
| 852 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
| 853 | - $label = $option[0]; |
|
| 852 | + if (isset($option[0]) && '' != $option[0]) { |
|
| 853 | + $label = $option[0]; |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
| 856 | + if (isset($option[1]) && '' != $option[1]) { |
|
| 857 | 857 | $price = $option[1]; |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | - if ( ! isset( $price ) ) { |
|
| 860 | + if (!isset($price)) { |
|
| 861 | 861 | $price = $label; |
| 862 | 862 | } |
| 863 | 863 | |
| 864 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
| 864 | + if (!isset($price) || !is_numeric($price)) { |
|
| 865 | 865 | continue; |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | - if ( ! isset( $label ) ) { |
|
| 868 | + if (!isset($label)) { |
|
| 869 | 869 | $label = $price; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | - $options[ $price ] = $label; |
|
| 872 | + $options[$price] = $label; |
|
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | return $options; |
@@ -878,23 +878,23 @@ discard block |
||
| 878 | 878 | /** |
| 879 | 879 | * Returns the help tip. |
| 880 | 880 | */ |
| 881 | -function getpaid_get_help_tip( $tip, $additional_classes = '' ) { |
|
| 882 | - $additional_classes = sanitize_html_class( $additional_classes ); |
|
| 883 | - $tip = esc_attr__( $tip ); |
|
| 881 | +function getpaid_get_help_tip($tip, $additional_classes = '') { |
|
| 882 | + $additional_classes = sanitize_html_class($additional_classes); |
|
| 883 | + $tip = esc_attr__($tip); |
|
| 884 | 884 | return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>"; |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | /** |
| 888 | 888 | * Formats a date |
| 889 | 889 | */ |
| 890 | -function getpaid_format_date( $date ) { |
|
| 890 | +function getpaid_format_date($date) { |
|
| 891 | 891 | |
| 892 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
| 892 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
| 893 | 893 | return ''; |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | |
| 897 | - return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $date ) ); |
|
| 897 | + return date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($date)); |
|
| 898 | 898 | |
| 899 | 899 | } |
| 900 | 900 | |
@@ -905,16 +905,16 @@ discard block |
||
| 905 | 905 | * @param integer $limit Limit size in characters. |
| 906 | 906 | * @return string |
| 907 | 907 | */ |
| 908 | -function getpaid_limit_length( $string, $limit ) { |
|
| 908 | +function getpaid_limit_length($string, $limit) { |
|
| 909 | 909 | $str_limit = $limit - 3; |
| 910 | 910 | |
| 911 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 912 | - if ( mb_strlen( $string ) > $limit ) { |
|
| 913 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
| 911 | + if (function_exists('mb_strimwidth')) { |
|
| 912 | + if (mb_strlen($string) > $limit) { |
|
| 913 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
| 914 | 914 | } |
| 915 | 915 | } else { |
| 916 | - if ( strlen( $string ) > $limit ) { |
|
| 917 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
| 916 | + if (strlen($string) > $limit) { |
|
| 917 | + $string = substr($string, 0, $str_limit) . '...'; |
|
| 918 | 918 | } |
| 919 | 919 | } |
| 920 | 920 | return $string; |
@@ -928,7 +928,7 @@ discard block |
||
| 928 | 928 | * @since 1.0.19 |
| 929 | 929 | */ |
| 930 | 930 | function getpaid_api() { |
| 931 | - return getpaid()->get( 'api' ); |
|
| 931 | + return getpaid()->get('api'); |
|
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | /** |
@@ -938,7 +938,7 @@ discard block |
||
| 938 | 938 | * @since 1.0.19 |
| 939 | 939 | */ |
| 940 | 940 | function getpaid_post_types() { |
| 941 | - return getpaid()->get( 'post_types' ); |
|
| 941 | + return getpaid()->get('post_types'); |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | /** |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | * @since 1.0.19 |
| 949 | 949 | */ |
| 950 | 950 | function getpaid_session() { |
| 951 | - return getpaid()->get( 'session' ); |
|
| 951 | + return getpaid()->get('session'); |
|
| 952 | 952 | } |
| 953 | 953 | |
| 954 | 954 | /** |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | * @since 1.0.19 |
| 959 | 959 | */ |
| 960 | 960 | function getpaid_notes() { |
| 961 | - return getpaid()->get( 'notes' ); |
|
| 961 | + return getpaid()->get('notes'); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
@@ -970,28 +970,28 @@ discard block |
||
| 970 | 970 | * |
| 971 | 971 | * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query |
| 972 | 972 | */ |
| 973 | -function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
|
| 973 | +function getpaid_get_subscriptions($args = array(), $return = 'results') { |
|
| 974 | 974 | |
| 975 | - $args = wp_parse_args( $args, array() ); |
|
| 975 | + $args = wp_parse_args($args, array()); |
|
| 976 | 976 | |
| 977 | 977 | // Do not retrieve all fields if we just want the count. |
| 978 | - if ( 'count' == $return ) { |
|
| 978 | + if ('count' == $return) { |
|
| 979 | 979 | $args['fields'] = 'id'; |
| 980 | 980 | $args['number'] = 1; |
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | // Do not count all matches if we just want the results. |
| 984 | - if ( 'results' == $return ) { |
|
| 984 | + if ('results' == $return) { |
|
| 985 | 985 | $args['count_total'] = false; |
| 986 | 986 | } |
| 987 | 987 | |
| 988 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 988 | + $query = new GetPaid_Subscriptions_Query($args); |
|
| 989 | 989 | |
| 990 | - if ( 'results' == $return ) { |
|
| 990 | + if ('results' == $return) { |
|
| 991 | 991 | return $query->get_results(); |
| 992 | 992 | } |
| 993 | 993 | |
| 994 | - if ( 'count' == $return ) { |
|
| 994 | + if ('count' == $return) { |
|
| 995 | 995 | return $query->get_total(); |
| 996 | 996 | } |
| 997 | 997 | |
@@ -1008,13 +1008,13 @@ discard block |
||
| 1008 | 1008 | return apply_filters( |
| 1009 | 1009 | 'getpaid_get_subscription_statuses', |
| 1010 | 1010 | array( |
| 1011 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
| 1012 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 1013 | - 'active' => __( 'Active', 'invoicing' ), |
|
| 1014 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
| 1015 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 1016 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
| 1017 | - 'cancelled' =>__( 'Cancelled', 'invoicing' ), |
|
| 1011 | + 'pending' => __('Pending', 'invoicing'), |
|
| 1012 | + 'trialling' => __('Trialing', 'invoicing'), |
|
| 1013 | + 'active' => __('Active', 'invoicing'), |
|
| 1014 | + 'failing' => __('Failing', 'invoicing'), |
|
| 1015 | + 'expired' => __('Expired', 'invoicing'), |
|
| 1016 | + 'completed' => __('Complete', 'invoicing'), |
|
| 1017 | + 'cancelled' =>__('Cancelled', 'invoicing'), |
|
| 1018 | 1018 | ) |
| 1019 | 1019 | ); |
| 1020 | 1020 | |
@@ -1025,9 +1025,9 @@ discard block |
||
| 1025 | 1025 | * |
| 1026 | 1026 | * @return string |
| 1027 | 1027 | */ |
| 1028 | -function getpaid_get_subscription_status_label( $status ) { |
|
| 1028 | +function getpaid_get_subscription_status_label($status) { |
|
| 1029 | 1029 | $statuses = getpaid_get_subscription_statuses(); |
| 1030 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( $status ); |
|
| 1030 | + return isset($statuses[$status]) ? $statuses[$status] : ucfirst($status); |
|
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | /** |
@@ -1057,14 +1057,14 @@ discard block |
||
| 1057 | 1057 | * |
| 1058 | 1058 | * @return array |
| 1059 | 1059 | */ |
| 1060 | -function getpaid_get_subscription_status_counts( $args = array() ) { |
|
| 1060 | +function getpaid_get_subscription_status_counts($args = array()) { |
|
| 1061 | 1061 | |
| 1062 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 1062 | + $statuses = array_keys(getpaid_get_subscription_statuses()); |
|
| 1063 | 1063 | $counts = array(); |
| 1064 | 1064 | |
| 1065 | - foreach ( $statuses as $status ) { |
|
| 1066 | - $_args = wp_parse_args( "status=$status", $args ); |
|
| 1067 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 1065 | + foreach ($statuses as $status) { |
|
| 1066 | + $_args = wp_parse_args("status=$status", $args); |
|
| 1067 | + $counts[$status] = getpaid_get_subscriptions($_args, 'count'); |
|
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | return $counts; |
@@ -1076,20 +1076,20 @@ discard block |
||
| 1076 | 1076 | * |
| 1077 | 1077 | * @return string |
| 1078 | 1078 | */ |
| 1079 | -function getpaid_get_subscription_period_label( $period ) { |
|
| 1079 | +function getpaid_get_subscription_period_label($period) { |
|
| 1080 | 1080 | |
| 1081 | 1081 | $periods = array( |
| 1082 | - 'd' => __( 'day', 'invoicing' ), |
|
| 1083 | - 'day' => __( 'day', 'invoicing' ), |
|
| 1084 | - 'w' => __( 'week', 'invoicing' ), |
|
| 1085 | - 'week' => __( 'week', 'invoicing' ), |
|
| 1086 | - 'm' => __( 'month', 'invoicing' ), |
|
| 1087 | - 'month' => __( 'month', 'invoicing' ), |
|
| 1088 | - 'y' => __( 'year', 'invoicing' ), |
|
| 1089 | - 'year' => __( 'year', 'invoicing' ), |
|
| 1082 | + 'd' => __('day', 'invoicing'), |
|
| 1083 | + 'day' => __('day', 'invoicing'), |
|
| 1084 | + 'w' => __('week', 'invoicing'), |
|
| 1085 | + 'week' => __('week', 'invoicing'), |
|
| 1086 | + 'm' => __('month', 'invoicing'), |
|
| 1087 | + 'month' => __('month', 'invoicing'), |
|
| 1088 | + 'y' => __('year', 'invoicing'), |
|
| 1089 | + 'year' => __('year', 'invoicing'), |
|
| 1090 | 1090 | ); |
| 1091 | 1091 | |
| 1092 | - return isset( $periods[ $period ] ) ? strtolower( $periods[ $period ] ) : strtolower( $periods['d'] ); |
|
| 1092 | + return isset($periods[$period]) ? strtolower($periods[$period]) : strtolower($periods['d']); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
@@ -1098,5 +1098,5 @@ discard block |
||
| 1098 | 1098 | * @return GetPaid_Admin |
| 1099 | 1099 | */ |
| 1100 | 1100 | function getpaid_admin() { |
| 1101 | - return getpaid()->get( 'admin' ); |
|
| 1101 | + return getpaid()->get('admin'); |
|
| 1102 | 1102 | } |
@@ -13,449 +13,449 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class GetPaid_Payment_Gateway { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Set if the place checkout button should be renamed on selection. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $checkout_button_text; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Boolean whether the method is enabled. |
|
| 25 | - * |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - public $enabled = true; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Payment method id. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Payment method order. |
|
| 39 | - * |
|
| 40 | - * @var int |
|
| 41 | - */ |
|
| 42 | - public $order = 10; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Payment method title for the frontend. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - public $title; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Payment method description for the frontend. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - public $description; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Gateway title. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $method_title = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gateway description. |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $method_description = ''; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Countries this gateway is allowed for. |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - public $countries; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Currencies this gateway is allowed for. |
|
| 81 | - * |
|
| 82 | - * @var array |
|
| 83 | - */ |
|
| 84 | - public $currencies; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Currencies this gateway is not allowed for. |
|
| 88 | - * |
|
| 89 | - * @var array |
|
| 90 | - */ |
|
| 91 | - public $exclude_currencies; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | - * |
|
| 96 | - * @var int |
|
| 97 | - */ |
|
| 98 | - public $max_amount = 0; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Optional URL to view a transaction. |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $view_transaction_url = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Optional URL to view a subscription. |
|
| 109 | - * |
|
| 110 | - * @var string |
|
| 111 | - */ |
|
| 112 | - public $view_subscription_url = ''; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Optional label to show for "new payment method" in the payment |
|
| 116 | - * method/token selection radio selection. |
|
| 117 | - * |
|
| 118 | - * @var string |
|
| 119 | - */ |
|
| 120 | - public $new_method_label = ''; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Contains a user's saved tokens for this gateway. |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - protected $tokens = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * An array of features that this gateway supports. |
|
| 131 | - * |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - protected $supports = array(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Class constructor. |
|
| 138 | - */ |
|
| 139 | - public function __construct() { |
|
| 140 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 141 | - |
|
| 142 | - // Register gateway. |
|
| 143 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 144 | - |
|
| 145 | - // Enable Subscriptions. |
|
| 146 | - if ( $this->supports( 'subscription' ) ) { |
|
| 147 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Enable sandbox. |
|
| 151 | - if ( $this->supports( 'sandbox' ) ) { |
|
| 152 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // Gateway settings. |
|
| 156 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 16 | + /** |
|
| 17 | + * Set if the place checkout button should be renamed on selection. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $checkout_button_text; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Boolean whether the method is enabled. |
|
| 25 | + * |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + public $enabled = true; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Payment method id. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Payment method order. |
|
| 39 | + * |
|
| 40 | + * @var int |
|
| 41 | + */ |
|
| 42 | + public $order = 10; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Payment method title for the frontend. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + public $title; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Payment method description for the frontend. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + public $description; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Gateway title. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $method_title = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gateway description. |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $method_description = ''; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Countries this gateway is allowed for. |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + public $countries; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Currencies this gateway is allowed for. |
|
| 81 | + * |
|
| 82 | + * @var array |
|
| 83 | + */ |
|
| 84 | + public $currencies; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Currencies this gateway is not allowed for. |
|
| 88 | + * |
|
| 89 | + * @var array |
|
| 90 | + */ |
|
| 91 | + public $exclude_currencies; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | + * |
|
| 96 | + * @var int |
|
| 97 | + */ |
|
| 98 | + public $max_amount = 0; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Optional URL to view a transaction. |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $view_transaction_url = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Optional URL to view a subscription. |
|
| 109 | + * |
|
| 110 | + * @var string |
|
| 111 | + */ |
|
| 112 | + public $view_subscription_url = ''; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Optional label to show for "new payment method" in the payment |
|
| 116 | + * method/token selection radio selection. |
|
| 117 | + * |
|
| 118 | + * @var string |
|
| 119 | + */ |
|
| 120 | + public $new_method_label = ''; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Contains a user's saved tokens for this gateway. |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + protected $tokens = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * An array of features that this gateway supports. |
|
| 131 | + * |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + protected $supports = array(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Class constructor. |
|
| 138 | + */ |
|
| 139 | + public function __construct() { |
|
| 140 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 141 | + |
|
| 142 | + // Register gateway. |
|
| 143 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 144 | + |
|
| 145 | + // Enable Subscriptions. |
|
| 146 | + if ( $this->supports( 'subscription' ) ) { |
|
| 147 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Enable sandbox. |
|
| 151 | + if ( $this->supports( 'sandbox' ) ) { |
|
| 152 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // Gateway settings. |
|
| 156 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 157 | 157 | |
| 158 | 158 | |
| 159 | - // Gateway checkout fiellds. |
|
| 160 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 161 | - |
|
| 162 | - // Process payment. |
|
| 163 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 159 | + // Gateway checkout fiellds. |
|
| 160 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 161 | + |
|
| 162 | + // Process payment. |
|
| 163 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 164 | + |
|
| 165 | + // Change the checkout button text. |
|
| 166 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
| 167 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // Check if a gateway is valid for a given currency. |
|
| 171 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 172 | + |
|
| 173 | + // Generate the transaction url. |
|
| 174 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 175 | + |
|
| 176 | + // Generate the subscription url. |
|
| 177 | + add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
| 178 | + |
|
| 179 | + // Confirm payments. |
|
| 180 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 181 | + |
|
| 182 | + // Verify IPNs. |
|
| 183 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 184 | + |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Checks if this gateway is a given gateway. |
|
| 189 | + * |
|
| 190 | + * @since 1.0.19 |
|
| 191 | + * @return bool |
|
| 192 | + */ |
|
| 193 | + public function is( $gateway ) { |
|
| 194 | + return $gateway == $this->id; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Returns a users saved tokens for this gateway. |
|
| 199 | + * |
|
| 200 | + * @since 1.0.19 |
|
| 201 | + * @return array |
|
| 202 | + */ |
|
| 203 | + public function get_tokens( $sandbox = null ) { |
|
| 204 | + |
|
| 205 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 206 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 207 | + |
|
| 208 | + if ( is_array( $tokens ) ) { |
|
| 209 | + $this->tokens = $tokens; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + if ( ! is_bool( $sandbox ) ) { |
|
| 215 | + return $this->tokens; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 219 | + return wp_list_filter( $this->tokens, $args ); |
|
| 220 | + |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Saves a token for this gateway. |
|
| 225 | + * |
|
| 226 | + * @since 1.0.19 |
|
| 227 | + */ |
|
| 228 | + public function save_token( $token ) { |
|
| 164 | 229 | |
| 165 | - // Change the checkout button text. |
|
| 166 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 167 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // Check if a gateway is valid for a given currency. |
|
| 171 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 172 | - |
|
| 173 | - // Generate the transaction url. |
|
| 174 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 175 | - |
|
| 176 | - // Generate the subscription url. |
|
| 177 | - add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
| 178 | - |
|
| 179 | - // Confirm payments. |
|
| 180 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 181 | - |
|
| 182 | - // Verify IPNs. |
|
| 183 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 184 | - |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Checks if this gateway is a given gateway. |
|
| 189 | - * |
|
| 190 | - * @since 1.0.19 |
|
| 191 | - * @return bool |
|
| 192 | - */ |
|
| 193 | - public function is( $gateway ) { |
|
| 194 | - return $gateway == $this->id; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Returns a users saved tokens for this gateway. |
|
| 199 | - * |
|
| 200 | - * @since 1.0.19 |
|
| 201 | - * @return array |
|
| 202 | - */ |
|
| 203 | - public function get_tokens( $sandbox = null ) { |
|
| 204 | - |
|
| 205 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 206 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 207 | - |
|
| 208 | - if ( is_array( $tokens ) ) { |
|
| 209 | - $this->tokens = $tokens; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - if ( ! is_bool( $sandbox ) ) { |
|
| 215 | - return $this->tokens; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 219 | - return wp_list_filter( $this->tokens, $args ); |
|
| 220 | - |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Saves a token for this gateway. |
|
| 225 | - * |
|
| 226 | - * @since 1.0.19 |
|
| 227 | - */ |
|
| 228 | - public function save_token( $token ) { |
|
| 229 | - |
|
| 230 | - $tokens = $this->get_tokens(); |
|
| 231 | - $tokens[] = $token; |
|
| 232 | - |
|
| 233 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 234 | - |
|
| 235 | - $this->tokens = $tokens; |
|
| 236 | - |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Return the title for admin screens. |
|
| 241 | - * |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - public function get_method_title() { |
|
| 245 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Return the description for admin screens. |
|
| 250 | - * |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - public function get_method_description() { |
|
| 254 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Get the success url. |
|
| 259 | - * |
|
| 260 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 261 | - * @return string |
|
| 262 | - */ |
|
| 263 | - public function get_return_url( $invoice ) { |
|
| 264 | - |
|
| 265 | - // Payment success url |
|
| 266 | - $return_url = add_query_arg( |
|
| 267 | - array( |
|
| 268 | - 'payment-confirm' => $this->id, |
|
| 269 | - 'invoice_key' => $invoice->get_key(), |
|
| 270 | - 'utm_nooverride' => 1 |
|
| 271 | - ), |
|
| 272 | - wpinv_get_success_page_uri() |
|
| 273 | - ); |
|
| 274 | - |
|
| 275 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Confirms payments when rendering the success page. |
|
| 280 | - * |
|
| 281 | - * @param string $content Success page content. |
|
| 282 | - * @return string |
|
| 283 | - */ |
|
| 284 | - public function get_confirm_payment( $content ) { |
|
| 230 | + $tokens = $this->get_tokens(); |
|
| 231 | + $tokens[] = $token; |
|
| 232 | + |
|
| 233 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 234 | + |
|
| 235 | + $this->tokens = $tokens; |
|
| 236 | + |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Return the title for admin screens. |
|
| 241 | + * |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + public function get_method_title() { |
|
| 245 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Return the description for admin screens. |
|
| 250 | + * |
|
| 251 | + * @return string |
|
| 252 | + */ |
|
| 253 | + public function get_method_description() { |
|
| 254 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Get the success url. |
|
| 259 | + * |
|
| 260 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 261 | + * @return string |
|
| 262 | + */ |
|
| 263 | + public function get_return_url( $invoice ) { |
|
| 264 | + |
|
| 265 | + // Payment success url |
|
| 266 | + $return_url = add_query_arg( |
|
| 267 | + array( |
|
| 268 | + 'payment-confirm' => $this->id, |
|
| 269 | + 'invoice_key' => $invoice->get_key(), |
|
| 270 | + 'utm_nooverride' => 1 |
|
| 271 | + ), |
|
| 272 | + wpinv_get_success_page_uri() |
|
| 273 | + ); |
|
| 274 | + |
|
| 275 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Confirms payments when rendering the success page. |
|
| 280 | + * |
|
| 281 | + * @param string $content Success page content. |
|
| 282 | + * @return string |
|
| 283 | + */ |
|
| 284 | + public function get_confirm_payment( $content ) { |
|
| 285 | 285 | |
| 286 | - // Retrieve the invoice. |
|
| 287 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
| 288 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 286 | + // Retrieve the invoice. |
|
| 287 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
| 288 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 289 | 289 | |
| 290 | - // Ensure that it exists and that it is pending payment. |
|
| 291 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 292 | - return $content; |
|
| 293 | - } |
|
| 290 | + // Ensure that it exists and that it is pending payment. |
|
| 291 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 292 | + return $content; |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - // Can the user view this invoice?? |
|
| 296 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 297 | - return $content; |
|
| 298 | - } |
|
| 295 | + // Can the user view this invoice?? |
|
| 296 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 297 | + return $content; |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - // Show payment processing indicator. |
|
| 301 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Processes ipns and marks payments as complete. |
|
| 306 | - * |
|
| 307 | - * @return void |
|
| 308 | - */ |
|
| 309 | - public function verify_ipn() {} |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 313 | - * |
|
| 314 | - * @param string $transaction_url transaction url. |
|
| 315 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 316 | - * @return string transaction URL, or empty string. |
|
| 317 | - */ |
|
| 318 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 319 | - |
|
| 320 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 321 | - |
|
| 322 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 323 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 324 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 325 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - return $transaction_url; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 333 | - * |
|
| 334 | - * @param string $subscription_url transaction url. |
|
| 335 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 336 | - * @return string subscription URL, or empty string. |
|
| 337 | - */ |
|
| 338 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
| 339 | - |
|
| 340 | - $profile_id = $invoice->get_subscription_id(); |
|
| 341 | - |
|
| 342 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 343 | - |
|
| 344 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 345 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 346 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 347 | - |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return $subscription_url; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Check if the gateway is available for use. |
|
| 355 | - * |
|
| 356 | - * @return bool |
|
| 357 | - */ |
|
| 358 | - public function is_available() { |
|
| 359 | - return ! empty( $this->enabled ); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Return the gateway's title. |
|
| 364 | - * |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 367 | - public function get_title() { |
|
| 368 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Return the gateway's description. |
|
| 373 | - * |
|
| 374 | - * @return string |
|
| 375 | - */ |
|
| 376 | - public function get_description() { |
|
| 377 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Process Payment. |
|
| 382 | - * |
|
| 383 | - * |
|
| 384 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 385 | - * @param array $submission_data Posted checkout fields. |
|
| 386 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 387 | - * @return void |
|
| 388 | - */ |
|
| 389 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 390 | - // Process the payment then either redirect to the success page or the gateway. |
|
| 391 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Process refund. |
|
| 396 | - * |
|
| 397 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 398 | - * a passed in amount. |
|
| 399 | - * |
|
| 400 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 401 | - * @param float $amount Refund amount. |
|
| 402 | - * @param string $reason Refund reason. |
|
| 403 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 404 | - */ |
|
| 405 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 406 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Displays the payment fields, credit cards etc. |
|
| 411 | - * |
|
| 412 | - * @param int $invoice_id 0 or invoice id. |
|
| 413 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 414 | - */ |
|
| 415 | - public function payment_fields( $invoice_id, $form ) { |
|
| 416 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Filters the gateway settings. |
|
| 421 | - * |
|
| 422 | - * @param array $admin_settings |
|
| 423 | - */ |
|
| 424 | - public function admin_settings( $admin_settings ) { |
|
| 425 | - return $admin_settings; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * Retrieves the value of a gateway setting. |
|
| 430 | - * |
|
| 431 | - * @param string $option |
|
| 432 | - */ |
|
| 433 | - public function get_option( $option, $default = false ) { |
|
| 434 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Check if a gateway supports a given feature. |
|
| 439 | - * |
|
| 440 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 441 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 442 | - * |
|
| 443 | - * @param string $feature string The name of a feature to test support for. |
|
| 444 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
| 445 | - * @since 1.0.19 |
|
| 446 | - */ |
|
| 447 | - public function supports( $feature ) { |
|
| 448 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Returns the credit card form html. |
|
| 453 | - * |
|
| 454 | - * @param bool $save whether or not to display the save button. |
|
| 455 | - */ |
|
| 300 | + // Show payment processing indicator. |
|
| 301 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Processes ipns and marks payments as complete. |
|
| 306 | + * |
|
| 307 | + * @return void |
|
| 308 | + */ |
|
| 309 | + public function verify_ipn() {} |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 313 | + * |
|
| 314 | + * @param string $transaction_url transaction url. |
|
| 315 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 316 | + * @return string transaction URL, or empty string. |
|
| 317 | + */ |
|
| 318 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 319 | + |
|
| 320 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 321 | + |
|
| 322 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 323 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 324 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 325 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + return $transaction_url; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 333 | + * |
|
| 334 | + * @param string $subscription_url transaction url. |
|
| 335 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 336 | + * @return string subscription URL, or empty string. |
|
| 337 | + */ |
|
| 338 | + public function filter_subscription_url( $subscription_url, $invoice ) { |
|
| 339 | + |
|
| 340 | + $profile_id = $invoice->get_subscription_id(); |
|
| 341 | + |
|
| 342 | + if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 343 | + |
|
| 344 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 345 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 346 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 347 | + |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return $subscription_url; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Check if the gateway is available for use. |
|
| 355 | + * |
|
| 356 | + * @return bool |
|
| 357 | + */ |
|
| 358 | + public function is_available() { |
|
| 359 | + return ! empty( $this->enabled ); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Return the gateway's title. |
|
| 364 | + * |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | + public function get_title() { |
|
| 368 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Return the gateway's description. |
|
| 373 | + * |
|
| 374 | + * @return string |
|
| 375 | + */ |
|
| 376 | + public function get_description() { |
|
| 377 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Process Payment. |
|
| 382 | + * |
|
| 383 | + * |
|
| 384 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 385 | + * @param array $submission_data Posted checkout fields. |
|
| 386 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 387 | + * @return void |
|
| 388 | + */ |
|
| 389 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 390 | + // Process the payment then either redirect to the success page or the gateway. |
|
| 391 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Process refund. |
|
| 396 | + * |
|
| 397 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 398 | + * a passed in amount. |
|
| 399 | + * |
|
| 400 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 401 | + * @param float $amount Refund amount. |
|
| 402 | + * @param string $reason Refund reason. |
|
| 403 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 404 | + */ |
|
| 405 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 406 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Displays the payment fields, credit cards etc. |
|
| 411 | + * |
|
| 412 | + * @param int $invoice_id 0 or invoice id. |
|
| 413 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 414 | + */ |
|
| 415 | + public function payment_fields( $invoice_id, $form ) { |
|
| 416 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Filters the gateway settings. |
|
| 421 | + * |
|
| 422 | + * @param array $admin_settings |
|
| 423 | + */ |
|
| 424 | + public function admin_settings( $admin_settings ) { |
|
| 425 | + return $admin_settings; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * Retrieves the value of a gateway setting. |
|
| 430 | + * |
|
| 431 | + * @param string $option |
|
| 432 | + */ |
|
| 433 | + public function get_option( $option, $default = false ) { |
|
| 434 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Check if a gateway supports a given feature. |
|
| 439 | + * |
|
| 440 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 441 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 442 | + * |
|
| 443 | + * @param string $feature string The name of a feature to test support for. |
|
| 444 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
| 445 | + * @since 1.0.19 |
|
| 446 | + */ |
|
| 447 | + public function supports( $feature ) { |
|
| 448 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Returns the credit card form html. |
|
| 453 | + * |
|
| 454 | + * @param bool $save whether or not to display the save button. |
|
| 455 | + */ |
|
| 456 | 456 | public function get_cc_form( $save = false ) { |
| 457 | 457 | |
| 458 | - ob_start(); |
|
| 458 | + ob_start(); |
|
| 459 | 459 | |
| 460 | 460 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
| 461 | 461 | |
@@ -561,175 +561,175 @@ discard block |
||
| 561 | 561 | |
| 562 | 562 | <?php |
| 563 | 563 | |
| 564 | - if ( $save ) { |
|
| 565 | - echo $this->save_payment_method_checkbox(); |
|
| 566 | - } |
|
| 564 | + if ( $save ) { |
|
| 565 | + echo $this->save_payment_method_checkbox(); |
|
| 566 | + } |
|
| 567 | 567 | |
| 568 | - ?> |
|
| 568 | + ?> |
|
| 569 | 569 | </div> |
| 570 | 570 | |
| 571 | 571 | </div> |
| 572 | 572 | <?php |
| 573 | 573 | |
| 574 | - return ob_get_clean(); |
|
| 574 | + return ob_get_clean(); |
|
| 575 | + |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Displays a new payment method entry form. |
|
| 580 | + * |
|
| 581 | + * @since 1.0.19 |
|
| 582 | + */ |
|
| 583 | + public function new_payment_method_entry( $form ) { |
|
| 584 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Grab and display our saved payment methods. |
|
| 589 | + * |
|
| 590 | + * @since 1.0.19 |
|
| 591 | + */ |
|
| 592 | + public function saved_payment_methods() { |
|
| 593 | + $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 594 | + |
|
| 595 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 596 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 597 | + } |
|
| 575 | 598 | |
| 599 | + $html .= $this->get_new_payment_method_option_html(); |
|
| 600 | + $html .= '</ul>'; |
|
| 601 | + |
|
| 602 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 576 | 603 | } |
| 577 | 604 | |
| 578 | - /** |
|
| 579 | - * Displays a new payment method entry form. |
|
| 580 | - * |
|
| 581 | - * @since 1.0.19 |
|
| 582 | - */ |
|
| 583 | - public function new_payment_method_entry( $form ) { |
|
| 584 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Grab and display our saved payment methods. |
|
| 589 | - * |
|
| 590 | - * @since 1.0.19 |
|
| 591 | - */ |
|
| 592 | - public function saved_payment_methods() { |
|
| 593 | - $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 594 | - |
|
| 595 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 596 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - $html .= $this->get_new_payment_method_option_html(); |
|
| 600 | - $html .= '</ul>'; |
|
| 601 | - |
|
| 602 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * Gets saved payment method HTML from a token. |
|
| 607 | - * |
|
| 608 | - * @since 1.0.19 |
|
| 609 | - * @param array $token Payment Token. |
|
| 610 | - * @return string Generated payment method HTML |
|
| 611 | - */ |
|
| 612 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 613 | - |
|
| 614 | - return sprintf( |
|
| 615 | - '<li class="getpaid-payment-method form-group"> |
|
| 605 | + /** |
|
| 606 | + * Gets saved payment method HTML from a token. |
|
| 607 | + * |
|
| 608 | + * @since 1.0.19 |
|
| 609 | + * @param array $token Payment Token. |
|
| 610 | + * @return string Generated payment method HTML |
|
| 611 | + */ |
|
| 612 | + public function get_saved_payment_method_option_html( $token ) { |
|
| 613 | + |
|
| 614 | + return sprintf( |
|
| 615 | + '<li class="getpaid-payment-method form-group"> |
|
| 616 | 616 | <label> |
| 617 | 617 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
| 618 | 618 | <span>%3$s</span> |
| 619 | 619 | </label> |
| 620 | 620 | </li>', |
| 621 | - esc_attr( $this->id ), |
|
| 622 | - esc_attr( $token['id'] ), |
|
| 623 | - esc_html( $token['name'] ), |
|
| 624 | - checked( empty( $token['default'] ), false, false ) |
|
| 625 | - ); |
|
| 621 | + esc_attr( $this->id ), |
|
| 622 | + esc_attr( $token['id'] ), |
|
| 623 | + esc_html( $token['name'] ), |
|
| 624 | + checked( empty( $token['default'] ), false, false ) |
|
| 625 | + ); |
|
| 626 | 626 | |
| 627 | - } |
|
| 627 | + } |
|
| 628 | 628 | |
| 629 | - /** |
|
| 630 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 631 | - * |
|
| 632 | - * @since 1.0.19 |
|
| 633 | - */ |
|
| 634 | - public function get_new_payment_method_option_html() { |
|
| 629 | + /** |
|
| 630 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 631 | + * |
|
| 632 | + * @since 1.0.19 |
|
| 633 | + */ |
|
| 634 | + public function get_new_payment_method_option_html() { |
|
| 635 | 635 | |
| 636 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 636 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 637 | 637 | |
| 638 | - return sprintf( |
|
| 639 | - '<li class="getpaid-new-payment-method"> |
|
| 638 | + return sprintf( |
|
| 639 | + '<li class="getpaid-new-payment-method"> |
|
| 640 | 640 | <label> |
| 641 | 641 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
| 642 | 642 | <span>%2$s</span> |
| 643 | 643 | </label> |
| 644 | 644 | </li>', |
| 645 | - esc_attr( $this->id ), |
|
| 646 | - esc_html( $label ) |
|
| 647 | - ); |
|
| 645 | + esc_attr( $this->id ), |
|
| 646 | + esc_html( $label ) |
|
| 647 | + ); |
|
| 648 | 648 | |
| 649 | - } |
|
| 649 | + } |
|
| 650 | 650 | |
| 651 | - /** |
|
| 652 | - * Outputs a checkbox for saving a new payment method to the database. |
|
| 653 | - * |
|
| 654 | - * @since 1.0.19 |
|
| 655 | - */ |
|
| 656 | - public function save_payment_method_checkbox() { |
|
| 651 | + /** |
|
| 652 | + * Outputs a checkbox for saving a new payment method to the database. |
|
| 653 | + * |
|
| 654 | + * @since 1.0.19 |
|
| 655 | + */ |
|
| 656 | + public function save_payment_method_checkbox() { |
|
| 657 | 657 | |
| 658 | - return sprintf( |
|
| 659 | - '<p class="form-group getpaid-save-payment-method"> |
|
| 658 | + return sprintf( |
|
| 659 | + '<p class="form-group getpaid-save-payment-method"> |
|
| 660 | 660 | <label> |
| 661 | 661 | <input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
| 662 | 662 | <span>%2$s</span> |
| 663 | 663 | </label> |
| 664 | 664 | </p>', |
| 665 | - esc_attr( $this->id ), |
|
| 666 | - esc_html__( 'Save payment method', 'invoicing' ) |
|
| 667 | - ); |
|
| 665 | + esc_attr( $this->id ), |
|
| 666 | + esc_html__( 'Save payment method', 'invoicing' ) |
|
| 667 | + ); |
|
| 668 | 668 | |
| 669 | - } |
|
| 669 | + } |
|
| 670 | 670 | |
| 671 | - /** |
|
| 672 | - * Registers the gateway. |
|
| 673 | - * |
|
| 674 | - * @return array |
|
| 675 | - */ |
|
| 676 | - public function register_gateway( $gateways ) { |
|
| 671 | + /** |
|
| 672 | + * Registers the gateway. |
|
| 673 | + * |
|
| 674 | + * @return array |
|
| 675 | + */ |
|
| 676 | + public function register_gateway( $gateways ) { |
|
| 677 | 677 | |
| 678 | - $gateways[ $this->id ] = array( |
|
| 678 | + $gateways[ $this->id ] = array( |
|
| 679 | 679 | |
| 680 | - 'admin_label' => $this->method_title, |
|
| 680 | + 'admin_label' => $this->method_title, |
|
| 681 | 681 | 'checkout_label' => $this->title, |
| 682 | - 'ordering' => $this->order, |
|
| 683 | - |
|
| 684 | - ); |
|
| 685 | - |
|
| 686 | - return $gateways; |
|
| 687 | - |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * Checks whether or not this is a sandbox request. |
|
| 692 | - * |
|
| 693 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 694 | - * @return bool |
|
| 695 | - */ |
|
| 696 | - public function is_sandbox( $invoice = null ) { |
|
| 697 | - |
|
| 698 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 699 | - return $invoice->get_mode() == 'test'; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - return wpinv_is_test_mode( $this->id ); |
|
| 703 | - |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * Renames the checkout button |
|
| 708 | - * |
|
| 709 | - * @return string |
|
| 710 | - */ |
|
| 711 | - public function rename_checkout_button() { |
|
| 712 | - return $this->checkout_button_text; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * Validate gateway currency |
|
| 717 | - * |
|
| 718 | - * @return bool |
|
| 719 | - */ |
|
| 720 | - public function validate_currency( $validation, $currency ) { |
|
| 721 | - |
|
| 722 | - // Required currencies. |
|
| 723 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 724 | - return false; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - // Excluded currencies. |
|
| 728 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 729 | - return false; |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - return $validation; |
|
| 733 | - } |
|
| 682 | + 'ordering' => $this->order, |
|
| 683 | + |
|
| 684 | + ); |
|
| 685 | + |
|
| 686 | + return $gateways; |
|
| 687 | + |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * Checks whether or not this is a sandbox request. |
|
| 692 | + * |
|
| 693 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 694 | + * @return bool |
|
| 695 | + */ |
|
| 696 | + public function is_sandbox( $invoice = null ) { |
|
| 697 | + |
|
| 698 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 699 | + return $invoice->get_mode() == 'test'; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + return wpinv_is_test_mode( $this->id ); |
|
| 703 | + |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * Renames the checkout button |
|
| 708 | + * |
|
| 709 | + * @return string |
|
| 710 | + */ |
|
| 711 | + public function rename_checkout_button() { |
|
| 712 | + return $this->checkout_button_text; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * Validate gateway currency |
|
| 717 | + * |
|
| 718 | + * @return bool |
|
| 719 | + */ |
|
| 720 | + public function validate_currency( $validation, $currency ) { |
|
| 721 | + |
|
| 722 | + // Required currencies. |
|
| 723 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 724 | + return false; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + // Excluded currencies. |
|
| 728 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 729 | + return false; |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + return $validation; |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | 735 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Abstaract Payment Gateway class. |
@@ -137,50 +137,50 @@ discard block |
||
| 137 | 137 | * Class constructor. |
| 138 | 138 | */ |
| 139 | 139 | public function __construct() { |
| 140 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 140 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
| 141 | 141 | |
| 142 | 142 | // Register gateway. |
| 143 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | + add_filter('wpinv_payment_gateways', array($this, 'register_gateway')); |
|
| 144 | 144 | |
| 145 | 145 | // Enable Subscriptions. |
| 146 | - if ( $this->supports( 'subscription' ) ) { |
|
| 147 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 146 | + if ($this->supports('subscription')) { |
|
| 147 | + add_filter("wpinv_{$this->id}_support_subscription", '__return_true'); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // Enable sandbox. |
| 151 | - if ( $this->supports( 'sandbox' ) ) { |
|
| 152 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 151 | + if ($this->supports('sandbox')) { |
|
| 152 | + add_filter("wpinv_{$this->id}_supports_sandbox", '__return_true'); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // Gateway settings. |
| 156 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 156 | + add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings')); |
|
| 157 | 157 | |
| 158 | 158 | |
| 159 | 159 | // Gateway checkout fiellds. |
| 160 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 160 | + add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2); |
|
| 161 | 161 | |
| 162 | 162 | // Process payment. |
| 163 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 163 | + add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3); |
|
| 164 | 164 | |
| 165 | 165 | // Change the checkout button text. |
| 166 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 167 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 166 | + if (!empty($this->checkout_button_text)) { |
|
| 167 | + add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button')); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // Check if a gateway is valid for a given currency. |
| 171 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 171 | + add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2); |
|
| 172 | 172 | |
| 173 | 173 | // Generate the transaction url. |
| 174 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 174 | + add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2); |
|
| 175 | 175 | |
| 176 | 176 | // Generate the subscription url. |
| 177 | - add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
| 177 | + add_filter("getpaid_gateway_{$this->id}_subscription_url", array($this, 'filter_subscription_url'), 10, 2); |
|
| 178 | 178 | |
| 179 | 179 | // Confirm payments. |
| 180 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 180 | + add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2); |
|
| 181 | 181 | |
| 182 | 182 | // Verify IPNs. |
| 183 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 183 | + add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn')); |
|
| 184 | 184 | |
| 185 | 185 | } |
| 186 | 186 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * @since 1.0.19 |
| 191 | 191 | * @return bool |
| 192 | 192 | */ |
| 193 | - public function is( $gateway ) { |
|
| 193 | + public function is($gateway) { |
|
| 194 | 194 | return $gateway == $this->id; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,23 +200,23 @@ discard block |
||
| 200 | 200 | * @since 1.0.19 |
| 201 | 201 | * @return array |
| 202 | 202 | */ |
| 203 | - public function get_tokens( $sandbox = null ) { |
|
| 203 | + public function get_tokens($sandbox = null) { |
|
| 204 | 204 | |
| 205 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 206 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 205 | + if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) { |
|
| 206 | + $tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true); |
|
| 207 | 207 | |
| 208 | - if ( is_array( $tokens ) ) { |
|
| 208 | + if (is_array($tokens)) { |
|
| 209 | 209 | $this->tokens = $tokens; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if ( ! is_bool( $sandbox ) ) { |
|
| 214 | + if (!is_bool($sandbox)) { |
|
| 215 | 215 | return $this->tokens; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 219 | - return wp_list_filter( $this->tokens, $args ); |
|
| 218 | + $args = array('type' => $sandbox ? 'sandbox' : 'live'); |
|
| 219 | + return wp_list_filter($this->tokens, $args); |
|
| 220 | 220 | |
| 221 | 221 | } |
| 222 | 222 | |
@@ -225,12 +225,12 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @since 1.0.19 |
| 227 | 227 | */ |
| 228 | - public function save_token( $token ) { |
|
| 228 | + public function save_token($token) { |
|
| 229 | 229 | |
| 230 | 230 | $tokens = $this->get_tokens(); |
| 231 | 231 | $tokens[] = $token; |
| 232 | 232 | |
| 233 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 233 | + update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens); |
|
| 234 | 234 | |
| 235 | 235 | $this->tokens = $tokens; |
| 236 | 236 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | 244 | public function get_method_title() { |
| 245 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 245 | + return apply_filters('getpaid_gateway_method_title', $this->method_title, $this); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @return string |
| 252 | 252 | */ |
| 253 | 253 | public function get_method_description() { |
| 254 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 254 | + return apply_filters('getpaid_gateway_method_description', $this->method_description, $this); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @param WPInv_Invoice $invoice Invoice object. |
| 261 | 261 | * @return string |
| 262 | 262 | */ |
| 263 | - public function get_return_url( $invoice ) { |
|
| 263 | + public function get_return_url($invoice) { |
|
| 264 | 264 | |
| 265 | 265 | // Payment success url |
| 266 | 266 | $return_url = add_query_arg( |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | wpinv_get_success_page_uri() |
| 273 | 273 | ); |
| 274 | 274 | |
| 275 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 275 | + return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -281,24 +281,24 @@ discard block |
||
| 281 | 281 | * @param string $content Success page content. |
| 282 | 282 | * @return string |
| 283 | 283 | */ |
| 284 | - public function get_confirm_payment( $content ) { |
|
| 284 | + public function get_confirm_payment($content) { |
|
| 285 | 285 | |
| 286 | 286 | // Retrieve the invoice. |
| 287 | 287 | $invoice_id = getpaid_get_current_invoice_id(); |
| 288 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 288 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 289 | 289 | |
| 290 | 290 | // Ensure that it exists and that it is pending payment. |
| 291 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 291 | + if (empty($invoice_id) || !$invoice->needs_payment()) { |
|
| 292 | 292 | return $content; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | // Can the user view this invoice?? |
| 296 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 296 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
| 297 | 297 | return $content; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | // Show payment processing indicator. |
| 301 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 301 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -315,14 +315,14 @@ discard block |
||
| 315 | 315 | * @param WPInv_Invoice $invoice Invoice object. |
| 316 | 316 | * @return string transaction URL, or empty string. |
| 317 | 317 | */ |
| 318 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 318 | + public function filter_transaction_url($transaction_url, $invoice) { |
|
| 319 | 319 | |
| 320 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 320 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 321 | 321 | |
| 322 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 323 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 324 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 325 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 322 | + if (!empty($this->view_transaction_url) && !empty($transaction_id)) { |
|
| 323 | + $transaction_url = sprintf($this->view_transaction_url, $transaction_id); |
|
| 324 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
| 325 | + $transaction_url = str_replace('{sandbox}', $replace, $transaction_url); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | return $transaction_url; |
@@ -335,15 +335,15 @@ discard block |
||
| 335 | 335 | * @param WPInv_Invoice $invoice Invoice object. |
| 336 | 336 | * @return string subscription URL, or empty string. |
| 337 | 337 | */ |
| 338 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
| 338 | + public function filter_subscription_url($subscription_url, $invoice) { |
|
| 339 | 339 | |
| 340 | - $profile_id = $invoice->get_subscription_id(); |
|
| 340 | + $profile_id = $invoice->get_subscription_id(); |
|
| 341 | 341 | |
| 342 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 342 | + if (!empty($this->view_subscription_url) && !empty($profile_id)) { |
|
| 343 | 343 | |
| 344 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 345 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 346 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 344 | + $subscription_url = sprintf($this->view_subscription_url, $profile_id); |
|
| 345 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
| 346 | + $subscription_url = str_replace('{sandbox}', $replace, $subscription_url); |
|
| 347 | 347 | |
| 348 | 348 | } |
| 349 | 349 | |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | * @return bool |
| 357 | 357 | */ |
| 358 | 358 | public function is_available() { |
| 359 | - return ! empty( $this->enabled ); |
|
| 359 | + return !empty($this->enabled); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | * @return string |
| 366 | 366 | */ |
| 367 | 367 | public function get_title() { |
| 368 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 368 | + return apply_filters('getpaid_gateway_title', $this->title, $this); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * @return string |
| 375 | 375 | */ |
| 376 | 376 | public function get_description() { |
| 377 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 377 | + return apply_filters('getpaid_gateway_description', $this->description, $this); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -386,9 +386,9 @@ discard block |
||
| 386 | 386 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 387 | 387 | * @return void |
| 388 | 388 | */ |
| 389 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 389 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 390 | 390 | // Process the payment then either redirect to the success page or the gateway. |
| 391 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 391 | + do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -402,8 +402,8 @@ discard block |
||
| 402 | 402 | * @param string $reason Refund reason. |
| 403 | 403 | * @return WP_Error|bool True or false based on success, or a WP_Error object. |
| 404 | 404 | */ |
| 405 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 406 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 405 | + public function process_refund($invoice, $amount = null, $reason = '') { |
|
| 406 | + return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -412,8 +412,8 @@ discard block |
||
| 412 | 412 | * @param int $invoice_id 0 or invoice id. |
| 413 | 413 | * @param GetPaid_Payment_Form $form Current payment form. |
| 414 | 414 | */ |
| 415 | - public function payment_fields( $invoice_id, $form ) { |
|
| 416 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 415 | + public function payment_fields($invoice_id, $form) { |
|
| 416 | + do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | /** |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | * |
| 422 | 422 | * @param array $admin_settings |
| 423 | 423 | */ |
| 424 | - public function admin_settings( $admin_settings ) { |
|
| 424 | + public function admin_settings($admin_settings) { |
|
| 425 | 425 | return $admin_settings; |
| 426 | 426 | } |
| 427 | 427 | |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | * |
| 431 | 431 | * @param string $option |
| 432 | 432 | */ |
| 433 | - public function get_option( $option, $default = false ) { |
|
| 434 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 433 | + public function get_option($option, $default = false) { |
|
| 434 | + return wpinv_get_option($this->id . '_' . $option, $default); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -444,8 +444,8 @@ discard block |
||
| 444 | 444 | * @return bool True if the gateway supports the feature, false otherwise. |
| 445 | 445 | * @since 1.0.19 |
| 446 | 446 | */ |
| 447 | - public function supports( $feature ) { |
|
| 448 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 447 | + public function supports($feature) { |
|
| 448 | + return apply_filters('getpaid_payment_gateway_supports', in_array($feature, $this->supports), $feature, $this); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -453,36 +453,36 @@ discard block |
||
| 453 | 453 | * |
| 454 | 454 | * @param bool $save whether or not to display the save button. |
| 455 | 455 | */ |
| 456 | - public function get_cc_form( $save = false ) { |
|
| 456 | + public function get_cc_form($save = false) { |
|
| 457 | 457 | |
| 458 | 458 | ob_start(); |
| 459 | 459 | |
| 460 | - $id_prefix = esc_attr( uniqid( $this->id ) ); |
|
| 460 | + $id_prefix = esc_attr(uniqid($this->id)); |
|
| 461 | 461 | |
| 462 | 462 | $months = array( |
| 463 | - '01' => __( 'January', 'invoicing' ), |
|
| 464 | - '02' => __( 'February', 'invoicing' ), |
|
| 465 | - '03' => __( 'March', 'invoicing' ), |
|
| 466 | - '04' => __( 'April', 'invoicing' ), |
|
| 467 | - '05' => __( 'May', 'invoicing' ), |
|
| 468 | - '06' => __( 'June', 'invoicing' ), |
|
| 469 | - '07' => __( 'July', 'invoicing' ), |
|
| 470 | - '08' => __( 'August', 'invoicing' ), |
|
| 471 | - '09' => __( 'September', 'invoicing' ), |
|
| 472 | - '10' => __( 'October', 'invoicing' ), |
|
| 473 | - '11' => __( 'November', 'invoicing' ), |
|
| 474 | - '12' => __( 'December', 'invoicing' ), |
|
| 463 | + '01' => __('January', 'invoicing'), |
|
| 464 | + '02' => __('February', 'invoicing'), |
|
| 465 | + '03' => __('March', 'invoicing'), |
|
| 466 | + '04' => __('April', 'invoicing'), |
|
| 467 | + '05' => __('May', 'invoicing'), |
|
| 468 | + '06' => __('June', 'invoicing'), |
|
| 469 | + '07' => __('July', 'invoicing'), |
|
| 470 | + '08' => __('August', 'invoicing'), |
|
| 471 | + '09' => __('September', 'invoicing'), |
|
| 472 | + '10' => __('October', 'invoicing'), |
|
| 473 | + '11' => __('November', 'invoicing'), |
|
| 474 | + '12' => __('December', 'invoicing'), |
|
| 475 | 475 | ); |
| 476 | 476 | |
| 477 | - $year = (int) date( 'Y', current_time( 'timestamp' ) ); |
|
| 477 | + $year = (int) date('Y', current_time('timestamp')); |
|
| 478 | 478 | $years = array(); |
| 479 | 479 | |
| 480 | - for ( $i = 0; $i <= 10; $i++ ) { |
|
| 481 | - $years[ $year + $i ] = $year + $i; |
|
| 480 | + for ($i = 0; $i <= 10; $i++) { |
|
| 481 | + $years[$year + $i] = $year + $i; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | ?> |
| 485 | - <div class="<?php echo esc_attr( $this->id );?>-cc-form getpaid-cc-form card mt-4"> |
|
| 485 | + <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form card mt-4"> |
|
| 486 | 486 | |
| 487 | 487 | |
| 488 | 488 | <div class="card-body"> |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | array( |
| 497 | 497 | 'name' => $this->id . '[cc_number]', |
| 498 | 498 | 'id' => "$id_prefix-cc-number", |
| 499 | - 'label' => __( 'Card number', 'invoicing' ), |
|
| 499 | + 'label' => __('Card number', 'invoicing'), |
|
| 500 | 500 | 'label_type' => 'vertical', |
| 501 | 501 | 'input_group_left' => '<span class="input-group-text"><i class="fa fa-credit-card"></i></span>', |
| 502 | 502 | ) |
@@ -507,17 +507,17 @@ discard block |
||
| 507 | 507 | |
| 508 | 508 | <div class="col-12 col-sm-4"> |
| 509 | 509 | <div class="form-group"> |
| 510 | - <label><?php _e( 'Expiration', 'invoicing' ); ?></label> |
|
| 510 | + <label><?php _e('Expiration', 'invoicing'); ?></label> |
|
| 511 | 511 | <div class="form-row"> |
| 512 | 512 | |
| 513 | 513 | <div class="col"> |
| 514 | - <select class="form-control" name="<?php echo esc_attr( $this->id );?>[cc_expire_month]"> |
|
| 515 | - <option disabled selected="selected"><?php _e( 'MM', 'invoicing' ); ?></option> |
|
| 514 | + <select class="form-control" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]"> |
|
| 515 | + <option disabled selected="selected"><?php _e('MM', 'invoicing'); ?></option> |
|
| 516 | 516 | |
| 517 | 517 | <?php |
| 518 | - foreach ( $months as $key => $month ) { |
|
| 519 | - $key = esc_attr( $key ); |
|
| 520 | - $month = wpinv_clean( $month ); |
|
| 518 | + foreach ($months as $key => $month) { |
|
| 519 | + $key = esc_attr($key); |
|
| 520 | + $month = wpinv_clean($month); |
|
| 521 | 521 | echo "<option value='$key'>$month</option>" . PHP_EOL; |
| 522 | 522 | } |
| 523 | 523 | ?> |
@@ -526,13 +526,13 @@ discard block |
||
| 526 | 526 | </div> |
| 527 | 527 | |
| 528 | 528 | <div class="col"> |
| 529 | - <select class="form-control" name="<?php echo esc_attr( $this->id );?>[cc_expire_year]"> |
|
| 530 | - <option disabled selected="selected"><?php _e( 'YY', 'invoicing' ); ?></option> |
|
| 529 | + <select class="form-control" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]"> |
|
| 530 | + <option disabled selected="selected"><?php _e('YY', 'invoicing'); ?></option> |
|
| 531 | 531 | |
| 532 | 532 | <?php |
| 533 | - foreach ( $years as $key => $year ) { |
|
| 534 | - $key = esc_attr( $key ); |
|
| 535 | - $year = wpinv_clean( $year ); |
|
| 533 | + foreach ($years as $key => $year) { |
|
| 534 | + $key = esc_attr($key); |
|
| 535 | + $year = wpinv_clean($year); |
|
| 536 | 536 | echo "<option value='$key'>$year</option>" . PHP_EOL; |
| 537 | 537 | } |
| 538 | 538 | ?> |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | array( |
| 551 | 551 | 'name' => $this->id . '[cc_cvv2]', |
| 552 | 552 | 'id' => "$id_prefix-cc-cvv2", |
| 553 | - 'label' => __( 'CCV', 'invoicing' ), |
|
| 553 | + 'label' => __('CCV', 'invoicing'), |
|
| 554 | 554 | 'label_type' => 'vertical', |
| 555 | 555 | ) |
| 556 | 556 | ); |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | |
| 562 | 562 | <?php |
| 563 | 563 | |
| 564 | - if ( $save ) { |
|
| 564 | + if ($save) { |
|
| 565 | 565 | echo $this->save_payment_method_checkbox(); |
| 566 | 566 | } |
| 567 | 567 | |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | * |
| 581 | 581 | * @since 1.0.19 |
| 582 | 582 | */ |
| 583 | - public function new_payment_method_entry( $form ) { |
|
| 583 | + public function new_payment_method_entry($form) { |
|
| 584 | 584 | echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
| 585 | 585 | } |
| 586 | 586 | |
@@ -590,16 +590,16 @@ discard block |
||
| 590 | 590 | * @since 1.0.19 |
| 591 | 591 | */ |
| 592 | 592 | public function saved_payment_methods() { |
| 593 | - $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 593 | + $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">'; |
|
| 594 | 594 | |
| 595 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 596 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 595 | + foreach ($this->get_tokens($this->is_sandbox()) as $token) { |
|
| 596 | + $html .= $this->get_saved_payment_method_option_html($token); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | $html .= $this->get_new_payment_method_option_html(); |
| 600 | 600 | $html .= '</ul>'; |
| 601 | 601 | |
| 602 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 602 | + echo apply_filters('getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | * @param array $token Payment Token. |
| 610 | 610 | * @return string Generated payment method HTML |
| 611 | 611 | */ |
| 612 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 612 | + public function get_saved_payment_method_option_html($token) { |
|
| 613 | 613 | |
| 614 | 614 | return sprintf( |
| 615 | 615 | '<li class="getpaid-payment-method form-group"> |
@@ -618,10 +618,10 @@ discard block |
||
| 618 | 618 | <span>%3$s</span> |
| 619 | 619 | </label> |
| 620 | 620 | </li>', |
| 621 | - esc_attr( $this->id ), |
|
| 622 | - esc_attr( $token['id'] ), |
|
| 623 | - esc_html( $token['name'] ), |
|
| 624 | - checked( empty( $token['default'] ), false, false ) |
|
| 621 | + esc_attr($this->id), |
|
| 622 | + esc_attr($token['id']), |
|
| 623 | + esc_html($token['name']), |
|
| 624 | + checked(empty($token['default']), false, false) |
|
| 625 | 625 | ); |
| 626 | 626 | |
| 627 | 627 | } |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | */ |
| 634 | 634 | public function get_new_payment_method_option_html() { |
| 635 | 635 | |
| 636 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 636 | + $label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this); |
|
| 637 | 637 | |
| 638 | 638 | return sprintf( |
| 639 | 639 | '<li class="getpaid-new-payment-method"> |
@@ -642,8 +642,8 @@ discard block |
||
| 642 | 642 | <span>%2$s</span> |
| 643 | 643 | </label> |
| 644 | 644 | </li>', |
| 645 | - esc_attr( $this->id ), |
|
| 646 | - esc_html( $label ) |
|
| 645 | + esc_attr($this->id), |
|
| 646 | + esc_html($label) |
|
| 647 | 647 | ); |
| 648 | 648 | |
| 649 | 649 | } |
@@ -662,8 +662,8 @@ discard block |
||
| 662 | 662 | <span>%2$s</span> |
| 663 | 663 | </label> |
| 664 | 664 | </p>', |
| 665 | - esc_attr( $this->id ), |
|
| 666 | - esc_html__( 'Save payment method', 'invoicing' ) |
|
| 665 | + esc_attr($this->id), |
|
| 666 | + esc_html__('Save payment method', 'invoicing') |
|
| 667 | 667 | ); |
| 668 | 668 | |
| 669 | 669 | } |
@@ -673,9 +673,9 @@ discard block |
||
| 673 | 673 | * |
| 674 | 674 | * @return array |
| 675 | 675 | */ |
| 676 | - public function register_gateway( $gateways ) { |
|
| 676 | + public function register_gateway($gateways) { |
|
| 677 | 677 | |
| 678 | - $gateways[ $this->id ] = array( |
|
| 678 | + $gateways[$this->id] = array( |
|
| 679 | 679 | |
| 680 | 680 | 'admin_label' => $this->method_title, |
| 681 | 681 | 'checkout_label' => $this->title, |
@@ -693,13 +693,13 @@ discard block |
||
| 693 | 693 | * @param WPInv_Invoice|null $invoice Invoice object or null. |
| 694 | 694 | * @return bool |
| 695 | 695 | */ |
| 696 | - public function is_sandbox( $invoice = null ) { |
|
| 696 | + public function is_sandbox($invoice = null) { |
|
| 697 | 697 | |
| 698 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 698 | + if (!empty($invoice) && !$invoice->needs_payment()) { |
|
| 699 | 699 | return $invoice->get_mode() == 'test'; |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - return wpinv_is_test_mode( $this->id ); |
|
| 702 | + return wpinv_is_test_mode($this->id); |
|
| 703 | 703 | |
| 704 | 704 | } |
| 705 | 705 | |
@@ -717,15 +717,15 @@ discard block |
||
| 717 | 717 | * |
| 718 | 718 | * @return bool |
| 719 | 719 | */ |
| 720 | - public function validate_currency( $validation, $currency ) { |
|
| 720 | + public function validate_currency($validation, $currency) { |
|
| 721 | 721 | |
| 722 | 722 | // Required currencies. |
| 723 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 723 | + if (!empty($this->currencies) && !in_array($currency, $this->currencies)) { |
|
| 724 | 724 | return false; |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | // Excluded currencies. |
| 728 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 728 | + if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) { |
|
| 729 | 729 | return false; |
| 730 | 730 | } |
| 731 | 731 | |
@@ -14,508 +14,508 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Tax instance. |
|
| 40 | - * |
|
| 41 | - * @var WPInv_EUVat |
|
| 42 | - */ |
|
| 43 | - public $tax; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param array An array of payment gateways. |
|
| 47 | - */ |
|
| 48 | - public $gateways; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Class constructor. |
|
| 52 | - */ |
|
| 53 | - public function __construct() { |
|
| 54 | - $this->define_constants(); |
|
| 55 | - $this->includes(); |
|
| 56 | - $this->init_hooks(); |
|
| 57 | - $this->set_properties(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Sets a custom data property. |
|
| 62 | - * |
|
| 63 | - * @param string $prop The prop to set. |
|
| 64 | - * @param mixed $value The value to retrieve. |
|
| 65 | - */ |
|
| 66 | - public function set( $prop, $value ) { |
|
| 67 | - $this->data[ $prop ] = $value; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Gets a custom data property. |
|
| 72 | - * |
|
| 73 | - * @param string $prop The prop to set. |
|
| 74 | - * @return mixed The value. |
|
| 75 | - */ |
|
| 76 | - public function get( $prop ) { |
|
| 77 | - |
|
| 78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 79 | - return $this->data[ $prop ]; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - return null; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Define class properties. |
|
| 87 | - */ |
|
| 88 | - public function set_properties() { |
|
| 89 | - |
|
| 90 | - // Sessions. |
|
| 91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 93 | - $this->form_elements = new WPInv_Payment_Form_Elements(); |
|
| 94 | - $this->tax = new WPInv_EUVat(); |
|
| 95 | - $this->tax->init(); |
|
| 96 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
| 97 | - |
|
| 98 | - // Init other objects. |
|
| 99 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
| 100 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 101 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 102 | - $this->set( 'api', new WPInv_API() ); |
|
| 103 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 104 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 105 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Define plugin constants. |
|
| 110 | - */ |
|
| 111 | - public function define_constants() { |
|
| 112 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 113 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 114 | - $this->version = WPINV_VERSION; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Hook into actions and filters. |
|
| 119 | - * |
|
| 120 | - * @since 1.0.19 |
|
| 121 | - */ |
|
| 122 | - protected function init_hooks() { |
|
| 123 | - /* Internationalize the text strings used. */ |
|
| 124 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 125 | - |
|
| 126 | - // Init the plugin after WordPress inits. |
|
| 127 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 128 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
| 129 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 130 | - |
|
| 131 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 132 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 136 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 137 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 138 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 139 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 140 | - |
|
| 141 | - // Fires after registering actions. |
|
| 142 | - do_action( 'wpinv_actions', $this ); |
|
| 143 | - do_action( 'getpaid_actions', $this ); |
|
| 144 | - |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - public function plugins_loaded() { |
|
| 148 | - /* Internationalize the text strings used. */ |
|
| 149 | - $this->load_textdomain(); |
|
| 150 | - |
|
| 151 | - do_action( 'wpinv_loaded' ); |
|
| 152 | - |
|
| 153 | - // Fix oxygen page builder conflict |
|
| 154 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 155 | - wpinv_oxygen_fix_conflict(); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Load the translation of the plugin. |
|
| 161 | - * |
|
| 162 | - * @since 1.0 |
|
| 163 | - */ |
|
| 164 | - public function load_textdomain( $locale = NULL ) { |
|
| 165 | - if ( empty( $locale ) ) { |
|
| 166 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 170 | - |
|
| 171 | - unload_textdomain( 'invoicing' ); |
|
| 172 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 173 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Define language constants. |
|
| 177 | - */ |
|
| 178 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Include required core files used in admin and on the frontend. |
|
| 183 | - */ |
|
| 184 | - public function includes() { |
|
| 185 | - |
|
| 186 | - // Start with the settings. |
|
| 187 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 188 | - |
|
| 189 | - // Packages/libraries. |
|
| 190 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 191 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 192 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
| 193 | - |
|
| 194 | - // Load functions. |
|
| 195 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 198 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 199 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 202 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 207 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 208 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 209 | - |
|
| 210 | - // Register autoloader. |
|
| 211 | - try { |
|
| 212 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 213 | - } catch ( Exception $e ) { |
|
| 214 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 220 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 222 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 223 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 224 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 227 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 228 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 230 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 234 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 235 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 236 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 239 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Load the tax class. |
|
| 243 | - */ |
|
| 244 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
| 245 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 249 | - if ( !empty( $gateways ) ) { |
|
| 250 | - foreach ( $gateways as $gateway ) { |
|
| 251 | - if ( $gateway == 'manual' ) { |
|
| 252 | - continue; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
| 256 | - |
|
| 257 | - if ( file_exists( $gateway_file ) ) { |
|
| 258 | - require_once( $gateway_file ); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 264 | - GetPaid_Post_Types_Admin::init(); |
|
| 265 | - |
|
| 266 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 267 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 268 | - //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
| 269 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 270 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 271 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 272 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 273 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 274 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 275 | - //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 276 | - // load the user class only on the users.php page |
|
| 277 | - global $pagenow; |
|
| 278 | - if($pagenow=='users.php'){ |
|
| 279 | - new WPInv_Admin_Users(); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // Register cli commands |
|
| 284 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 285 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 286 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // include css inliner |
|
| 290 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 291 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Class autoloader |
|
| 299 | - * |
|
| 300 | - * @param string $class_name The name of the class to load. |
|
| 301 | - * @access public |
|
| 302 | - * @since 1.0.19 |
|
| 303 | - * @return void |
|
| 304 | - */ |
|
| 305 | - public function autoload( $class_name ) { |
|
| 306 | - |
|
| 307 | - // Normalize the class name... |
|
| 308 | - $class_name = strtolower( $class_name ); |
|
| 309 | - |
|
| 310 | - // ... and make sure it is our class. |
|
| 311 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 312 | - return; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // Next, prepare the file name from the class. |
|
| 316 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 317 | - |
|
| 318 | - // Base path of the classes. |
|
| 319 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 320 | - |
|
| 321 | - // And an array of possible locations in order of importance. |
|
| 322 | - $locations = array( |
|
| 323 | - "$plugin_path/includes", |
|
| 324 | - "$plugin_path/includes/data-stores", |
|
| 325 | - "$plugin_path/includes/gateways", |
|
| 326 | - "$plugin_path/includes/api", |
|
| 327 | - "$plugin_path/includes/admin", |
|
| 328 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 332 | - |
|
| 333 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 334 | - include trailingslashit( $location ) . $file_name; |
|
| 335 | - break; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Inits hooks etc. |
|
| 344 | - */ |
|
| 345 | - public function init() { |
|
| 346 | - |
|
| 347 | - // Fires before getpaid inits. |
|
| 348 | - do_action( 'before_getpaid_init', $this ); |
|
| 349 | - |
|
| 350 | - // Load default gateways. |
|
| 351 | - $gateways = apply_filters( |
|
| 352 | - 'getpaid_default_gateways', |
|
| 353 | - array( |
|
| 354 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 355 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 356 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 357 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 358 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 359 | - ) |
|
| 360 | - ); |
|
| 361 | - |
|
| 362 | - foreach ( $gateways as $id => $class ) { |
|
| 363 | - $this->gateways[ $id ] = new $class(); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // Fires after getpaid inits. |
|
| 367 | - do_action( 'getpaid_init', $this ); |
|
| 368 | - |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Checks if this is an IPN request and processes it. |
|
| 373 | - */ |
|
| 374 | - public function maybe_process_ipn() { |
|
| 375 | - |
|
| 376 | - // Ensure that this is an IPN request. |
|
| 377 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 378 | - return; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 382 | - |
|
| 383 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 384 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 385 | - exit; |
|
| 386 | - |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - public function enqueue_scripts() { |
|
| 390 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 391 | - |
|
| 392 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 393 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 394 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 395 | - |
|
| 396 | - // Register scripts |
|
| 397 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 398 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
| 399 | - |
|
| 400 | - $localize = array(); |
|
| 401 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 402 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 403 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
| 404 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
| 405 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
| 406 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
| 407 | - $localize['decimals'] = wpinv_decimals(); |
|
| 408 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 409 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 410 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 411 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 412 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 413 | - |
|
| 414 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 415 | - |
|
| 416 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 417 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
| 418 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
| 419 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 420 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 421 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 422 | - } |
|
| 423 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 424 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 428 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 429 | - |
|
| 430 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 431 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 432 | - |
|
| 433 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 434 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - public function wpinv_actions() { |
|
| 438 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 439 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - public function pre_get_posts( $wp_query ) { |
|
| 444 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 445 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - return $wp_query; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - public function bp_invoicing_init() { |
|
| 452 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Register widgets |
|
| 457 | - * |
|
| 458 | - */ |
|
| 459 | - public function register_widgets() { |
|
| 460 | - $widgets = apply_filters( |
|
| 461 | - 'getpaid_widget_classes', |
|
| 462 | - array( |
|
| 463 | - 'WPInv_Checkout_Widget', |
|
| 464 | - 'WPInv_History_Widget', |
|
| 465 | - 'WPInv_Receipt_Widget', |
|
| 466 | - 'WPInv_Subscriptions_Widget', |
|
| 467 | - 'WPInv_Buy_Item_Widget', |
|
| 468 | - 'WPInv_Messages_Widget', |
|
| 469 | - 'WPInv_GetPaid_Widget' |
|
| 470 | - ) |
|
| 471 | - ); |
|
| 472 | - |
|
| 473 | - foreach ( $widgets as $widget ) { |
|
| 474 | - register_widget( $widget ); |
|
| 475 | - } |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Data container. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Form elements instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Payment_Form_Elements |
|
| 35 | + */ |
|
| 36 | + public $form_elements; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Tax instance. |
|
| 40 | + * |
|
| 41 | + * @var WPInv_EUVat |
|
| 42 | + */ |
|
| 43 | + public $tax; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param array An array of payment gateways. |
|
| 47 | + */ |
|
| 48 | + public $gateways; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Class constructor. |
|
| 52 | + */ |
|
| 53 | + public function __construct() { |
|
| 54 | + $this->define_constants(); |
|
| 55 | + $this->includes(); |
|
| 56 | + $this->init_hooks(); |
|
| 57 | + $this->set_properties(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Sets a custom data property. |
|
| 62 | + * |
|
| 63 | + * @param string $prop The prop to set. |
|
| 64 | + * @param mixed $value The value to retrieve. |
|
| 65 | + */ |
|
| 66 | + public function set( $prop, $value ) { |
|
| 67 | + $this->data[ $prop ] = $value; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Gets a custom data property. |
|
| 72 | + * |
|
| 73 | + * @param string $prop The prop to set. |
|
| 74 | + * @return mixed The value. |
|
| 75 | + */ |
|
| 76 | + public function get( $prop ) { |
|
| 77 | + |
|
| 78 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 79 | + return $this->data[ $prop ]; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + return null; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Define class properties. |
|
| 87 | + */ |
|
| 88 | + public function set_properties() { |
|
| 89 | + |
|
| 90 | + // Sessions. |
|
| 91 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 92 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 93 | + $this->form_elements = new WPInv_Payment_Form_Elements(); |
|
| 94 | + $this->tax = new WPInv_EUVat(); |
|
| 95 | + $this->tax->init(); |
|
| 96 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
| 97 | + |
|
| 98 | + // Init other objects. |
|
| 99 | + $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
| 100 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 101 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 102 | + $this->set( 'api', new WPInv_API() ); |
|
| 103 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 104 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 105 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Define plugin constants. |
|
| 110 | + */ |
|
| 111 | + public function define_constants() { |
|
| 112 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 113 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 114 | + $this->version = WPINV_VERSION; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Hook into actions and filters. |
|
| 119 | + * |
|
| 120 | + * @since 1.0.19 |
|
| 121 | + */ |
|
| 122 | + protected function init_hooks() { |
|
| 123 | + /* Internationalize the text strings used. */ |
|
| 124 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 125 | + |
|
| 126 | + // Init the plugin after WordPress inits. |
|
| 127 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 128 | + add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
| 129 | + add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 130 | + |
|
| 131 | + if ( class_exists( 'BuddyPress' ) ) { |
|
| 132 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 136 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 137 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 138 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 139 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 140 | + |
|
| 141 | + // Fires after registering actions. |
|
| 142 | + do_action( 'wpinv_actions', $this ); |
|
| 143 | + do_action( 'getpaid_actions', $this ); |
|
| 144 | + |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + public function plugins_loaded() { |
|
| 148 | + /* Internationalize the text strings used. */ |
|
| 149 | + $this->load_textdomain(); |
|
| 150 | + |
|
| 151 | + do_action( 'wpinv_loaded' ); |
|
| 152 | + |
|
| 153 | + // Fix oxygen page builder conflict |
|
| 154 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 155 | + wpinv_oxygen_fix_conflict(); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Load the translation of the plugin. |
|
| 161 | + * |
|
| 162 | + * @since 1.0 |
|
| 163 | + */ |
|
| 164 | + public function load_textdomain( $locale = NULL ) { |
|
| 165 | + if ( empty( $locale ) ) { |
|
| 166 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 170 | + |
|
| 171 | + unload_textdomain( 'invoicing' ); |
|
| 172 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 173 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Define language constants. |
|
| 177 | + */ |
|
| 178 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Include required core files used in admin and on the frontend. |
|
| 183 | + */ |
|
| 184 | + public function includes() { |
|
| 185 | + |
|
| 186 | + // Start with the settings. |
|
| 187 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 188 | + |
|
| 189 | + // Packages/libraries. |
|
| 190 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 191 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 192 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
| 193 | + |
|
| 194 | + // Load functions. |
|
| 195 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 198 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 199 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 202 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 207 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 208 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 209 | + |
|
| 210 | + // Register autoloader. |
|
| 211 | + try { |
|
| 212 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 213 | + } catch ( Exception $e ) { |
|
| 214 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 219 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 220 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 222 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 223 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 224 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 227 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 228 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 230 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 231 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 233 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 234 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 235 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 236 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 239 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Load the tax class. |
|
| 243 | + */ |
|
| 244 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
| 245 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 249 | + if ( !empty( $gateways ) ) { |
|
| 250 | + foreach ( $gateways as $gateway ) { |
|
| 251 | + if ( $gateway == 'manual' ) { |
|
| 252 | + continue; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
| 256 | + |
|
| 257 | + if ( file_exists( $gateway_file ) ) { |
|
| 258 | + require_once( $gateway_file ); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 264 | + GetPaid_Post_Types_Admin::init(); |
|
| 265 | + |
|
| 266 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 267 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 268 | + //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
| 269 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 270 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 271 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 272 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 273 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 274 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 275 | + //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 276 | + // load the user class only on the users.php page |
|
| 277 | + global $pagenow; |
|
| 278 | + if($pagenow=='users.php'){ |
|
| 279 | + new WPInv_Admin_Users(); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // Register cli commands |
|
| 284 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 285 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 286 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // include css inliner |
|
| 290 | + if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 291 | + include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Class autoloader |
|
| 299 | + * |
|
| 300 | + * @param string $class_name The name of the class to load. |
|
| 301 | + * @access public |
|
| 302 | + * @since 1.0.19 |
|
| 303 | + * @return void |
|
| 304 | + */ |
|
| 305 | + public function autoload( $class_name ) { |
|
| 306 | + |
|
| 307 | + // Normalize the class name... |
|
| 308 | + $class_name = strtolower( $class_name ); |
|
| 309 | + |
|
| 310 | + // ... and make sure it is our class. |
|
| 311 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 312 | + return; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // Next, prepare the file name from the class. |
|
| 316 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 317 | + |
|
| 318 | + // Base path of the classes. |
|
| 319 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 320 | + |
|
| 321 | + // And an array of possible locations in order of importance. |
|
| 322 | + $locations = array( |
|
| 323 | + "$plugin_path/includes", |
|
| 324 | + "$plugin_path/includes/data-stores", |
|
| 325 | + "$plugin_path/includes/gateways", |
|
| 326 | + "$plugin_path/includes/api", |
|
| 327 | + "$plugin_path/includes/admin", |
|
| 328 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 332 | + |
|
| 333 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 334 | + include trailingslashit( $location ) . $file_name; |
|
| 335 | + break; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Inits hooks etc. |
|
| 344 | + */ |
|
| 345 | + public function init() { |
|
| 346 | + |
|
| 347 | + // Fires before getpaid inits. |
|
| 348 | + do_action( 'before_getpaid_init', $this ); |
|
| 349 | + |
|
| 350 | + // Load default gateways. |
|
| 351 | + $gateways = apply_filters( |
|
| 352 | + 'getpaid_default_gateways', |
|
| 353 | + array( |
|
| 354 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 355 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 356 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 357 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 358 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 359 | + ) |
|
| 360 | + ); |
|
| 361 | + |
|
| 362 | + foreach ( $gateways as $id => $class ) { |
|
| 363 | + $this->gateways[ $id ] = new $class(); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // Fires after getpaid inits. |
|
| 367 | + do_action( 'getpaid_init', $this ); |
|
| 368 | + |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Checks if this is an IPN request and processes it. |
|
| 373 | + */ |
|
| 374 | + public function maybe_process_ipn() { |
|
| 375 | + |
|
| 376 | + // Ensure that this is an IPN request. |
|
| 377 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 378 | + return; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 382 | + |
|
| 383 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 384 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 385 | + exit; |
|
| 386 | + |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + public function enqueue_scripts() { |
|
| 390 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 391 | + |
|
| 392 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 393 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 394 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
| 395 | + |
|
| 396 | + // Register scripts |
|
| 397 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 398 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
| 399 | + |
|
| 400 | + $localize = array(); |
|
| 401 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 402 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 403 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
| 404 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
| 405 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
| 406 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
| 407 | + $localize['decimals'] = wpinv_decimals(); |
|
| 408 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 409 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 410 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 411 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 412 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 413 | + |
|
| 414 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 415 | + |
|
| 416 | + wp_enqueue_script( 'jquery-blockui' ); |
|
| 417 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
| 418 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
| 419 | + if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 420 | + if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 421 | + wp_dequeue_script( 'google-maps-api' ); |
|
| 422 | + } |
|
| 423 | + wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 424 | + wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 428 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 429 | + |
|
| 430 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
| 431 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 432 | + |
|
| 433 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 434 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + public function wpinv_actions() { |
|
| 438 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 439 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + public function pre_get_posts( $wp_query ) { |
|
| 444 | + if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 445 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + return $wp_query; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + public function bp_invoicing_init() { |
|
| 452 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Register widgets |
|
| 457 | + * |
|
| 458 | + */ |
|
| 459 | + public function register_widgets() { |
|
| 460 | + $widgets = apply_filters( |
|
| 461 | + 'getpaid_widget_classes', |
|
| 462 | + array( |
|
| 463 | + 'WPInv_Checkout_Widget', |
|
| 464 | + 'WPInv_History_Widget', |
|
| 465 | + 'WPInv_Receipt_Widget', |
|
| 466 | + 'WPInv_Subscriptions_Widget', |
|
| 467 | + 'WPInv_Buy_Item_Widget', |
|
| 468 | + 'WPInv_Messages_Widget', |
|
| 469 | + 'WPInv_GetPaid_Widget' |
|
| 470 | + ) |
|
| 471 | + ); |
|
| 472 | + |
|
| 473 | + foreach ( $widgets as $widget ) { |
|
| 474 | + register_widget( $widget ); |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | - } |
|
| 477 | + } |
|
| 478 | 478 | |
| 479 | - /** |
|
| 480 | - * Remove our pages from yoast sitemaps. |
|
| 481 | - * |
|
| 482 | - * @since 1.0.19 |
|
| 483 | - * @param int[] $excluded_posts_ids |
|
| 484 | - */ |
|
| 485 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 479 | + /** |
|
| 480 | + * Remove our pages from yoast sitemaps. |
|
| 481 | + * |
|
| 482 | + * @since 1.0.19 |
|
| 483 | + * @param int[] $excluded_posts_ids |
|
| 484 | + */ |
|
| 485 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 486 | 486 | |
| 487 | - // Ensure that we have an array. |
|
| 488 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 489 | - $excluded_posts_ids = array(); |
|
| 490 | - } |
|
| 487 | + // Ensure that we have an array. |
|
| 488 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 489 | + $excluded_posts_ids = array(); |
|
| 490 | + } |
|
| 491 | 491 | |
| 492 | - // Prepare our pages. |
|
| 493 | - $our_pages = array(); |
|
| 492 | + // Prepare our pages. |
|
| 493 | + $our_pages = array(); |
|
| 494 | 494 | |
| 495 | - // Checkout page. |
|
| 496 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 495 | + // Checkout page. |
|
| 496 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 497 | 497 | |
| 498 | - // Success page. |
|
| 499 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 498 | + // Success page. |
|
| 499 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 500 | 500 | |
| 501 | - // Failure page. |
|
| 502 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 501 | + // Failure page. |
|
| 502 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 503 | 503 | |
| 504 | - // History page. |
|
| 505 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 504 | + // History page. |
|
| 505 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 506 | 506 | |
| 507 | - // Subscriptions page. |
|
| 508 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 507 | + // Subscriptions page. |
|
| 508 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 509 | 509 | |
| 510 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 510 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 511 | 511 | |
| 512 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 513 | - return array_unique( $excluded_posts_ids ); |
|
| 512 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 513 | + return array_unique( $excluded_posts_ids ); |
|
| 514 | 514 | |
| 515 | - } |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | - public function wp_footer() { |
|
| 518 | - echo ' |
|
| 517 | + public function wp_footer() { |
|
| 518 | + echo ' |
|
| 519 | 519 | <div class="bsui"> |
| 520 | 520 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
| 521 | 521 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -526,6 +526,6 @@ discard block |
||
| 526 | 526 | </div> |
| 527 | 527 | </div> |
| 528 | 528 | '; |
| 529 | - } |
|
| 529 | + } |
|
| 530 | 530 | |
| 531 | 531 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 1.0.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Main Invoicing class. |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | * @param string $prop The prop to set. |
| 64 | 64 | * @param mixed $value The value to retrieve. |
| 65 | 65 | */ |
| 66 | - public function set( $prop, $value ) { |
|
| 67 | - $this->data[ $prop ] = $value; |
|
| 66 | + public function set($prop, $value) { |
|
| 67 | + $this->data[$prop] = $value; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | * @param string $prop The prop to set. |
| 74 | 74 | * @return mixed The value. |
| 75 | 75 | */ |
| 76 | - public function get( $prop ) { |
|
| 76 | + public function get($prop) { |
|
| 77 | 77 | |
| 78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 79 | - return $this->data[ $prop ]; |
|
| 78 | + if (isset($this->data[$prop])) { |
|
| 79 | + return $this->data[$prop]; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return null; |
@@ -88,29 +88,29 @@ discard block |
||
| 88 | 88 | public function set_properties() { |
| 89 | 89 | |
| 90 | 90 | // Sessions. |
| 91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 91 | + $this->set('session', new WPInv_Session_Handler()); |
|
| 92 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
| 93 | 93 | $this->form_elements = new WPInv_Payment_Form_Elements(); |
| 94 | 94 | $this->tax = new WPInv_EUVat(); |
| 95 | 95 | $this->tax->init(); |
| 96 | 96 | $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
| 97 | 97 | |
| 98 | 98 | // Init other objects. |
| 99 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
| 100 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 101 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 102 | - $this->set( 'api', new WPInv_API() ); |
|
| 103 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 104 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 105 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 99 | + $this->set('reports', new WPInv_Reports()); // TODO: Refactor. |
|
| 100 | + $this->set('session', new WPInv_Session_Handler()); |
|
| 101 | + $this->set('notes', new WPInv_Notes()); |
|
| 102 | + $this->set('api', new WPInv_API()); |
|
| 103 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
| 104 | + $this->set('template', new GetPaid_Template()); |
|
| 105 | + $this->set('admin', new GetPaid_Admin()); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * Define plugin constants. |
| 110 | 110 | */ |
| 111 | 111 | public function define_constants() { |
| 112 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 113 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 112 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 113 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 114 | 114 | $this->version = WPINV_VERSION; |
| 115 | 115 | } |
| 116 | 116 | |
@@ -121,26 +121,26 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | protected function init_hooks() { |
| 123 | 123 | /* Internationalize the text strings used. */ |
| 124 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 124 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 125 | 125 | |
| 126 | 126 | // Init the plugin after WordPress inits. |
| 127 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 128 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
| 129 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 127 | + add_action('init', array($this, 'init'), 1); |
|
| 128 | + add_action('getpaid_init', array($this, 'maybe_process_ipn'), 5); |
|
| 129 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
| 130 | 130 | |
| 131 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 132 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 131 | + if (class_exists('BuddyPress')) { |
|
| 132 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 136 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 137 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 138 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 139 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 135 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 136 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
| 137 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
| 138 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
| 139 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 140 | 140 | |
| 141 | 141 | // Fires after registering actions. |
| 142 | - do_action( 'wpinv_actions', $this ); |
|
| 143 | - do_action( 'getpaid_actions', $this ); |
|
| 142 | + do_action('wpinv_actions', $this); |
|
| 143 | + do_action('getpaid_actions', $this); |
|
| 144 | 144 | |
| 145 | 145 | } |
| 146 | 146 | |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | /* Internationalize the text strings used. */ |
| 149 | 149 | $this->load_textdomain(); |
| 150 | 150 | |
| 151 | - do_action( 'wpinv_loaded' ); |
|
| 151 | + do_action('wpinv_loaded'); |
|
| 152 | 152 | |
| 153 | 153 | // Fix oxygen page builder conflict |
| 154 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 154 | + if (function_exists('ct_css_output')) { |
|
| 155 | 155 | wpinv_oxygen_fix_conflict(); |
| 156 | 156 | } |
| 157 | 157 | } |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @since 1.0 |
| 163 | 163 | */ |
| 164 | - public function load_textdomain( $locale = NULL ) { |
|
| 165 | - if ( empty( $locale ) ) { |
|
| 166 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 164 | + public function load_textdomain($locale = NULL) { |
|
| 165 | + if (empty($locale)) { |
|
| 166 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 169 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
| 170 | 170 | |
| 171 | - unload_textdomain( 'invoicing' ); |
|
| 172 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 173 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 171 | + unload_textdomain('invoicing'); |
|
| 172 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 173 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | 176 | * Define language constants. |
| 177 | 177 | */ |
| 178 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 178 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -184,114 +184,114 @@ discard block |
||
| 184 | 184 | public function includes() { |
| 185 | 185 | |
| 186 | 186 | // Start with the settings. |
| 187 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 187 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 188 | 188 | |
| 189 | 189 | // Packages/libraries. |
| 190 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 191 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 192 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
| 190 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
| 191 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
| 192 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php'); |
|
| 193 | 193 | |
| 194 | 194 | // Load functions. |
| 195 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 198 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 199 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 202 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 207 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 208 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 195 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
| 196 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 197 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 198 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 199 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 200 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 201 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 202 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
| 203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 204 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 205 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 206 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 207 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 208 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
| 209 | 209 | |
| 210 | 210 | // Register autoloader. |
| 211 | 211 | try { |
| 212 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 213 | - } catch ( Exception $e ) { |
|
| 214 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 212 | + spl_autoload_register(array($this, 'autoload'), true); |
|
| 213 | + } catch (Exception $e) { |
|
| 214 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 220 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 222 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 223 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 224 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 227 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 228 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 230 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 234 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 235 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 236 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 239 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
| 217 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
| 218 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
| 219 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 220 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 221 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 222 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
| 223 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
| 224 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
| 225 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
| 226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
| 227 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
| 228 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
| 229 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
| 230 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
| 231 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
| 232 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
| 233 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
| 234 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
| 235 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
| 236 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
| 237 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
| 238 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
| 239 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php'); |
|
| 240 | 240 | |
| 241 | 241 | /** |
| 242 | 242 | * Load the tax class. |
| 243 | 243 | */ |
| 244 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
| 245 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 244 | + if (!class_exists('WPInv_EUVat')) { |
|
| 245 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 249 | - if ( !empty( $gateways ) ) { |
|
| 250 | - foreach ( $gateways as $gateway ) { |
|
| 251 | - if ( $gateway == 'manual' ) { |
|
| 248 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 249 | + if (!empty($gateways)) { |
|
| 250 | + foreach ($gateways as $gateway) { |
|
| 251 | + if ($gateway == 'manual') { |
|
| 252 | 252 | continue; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
| 256 | 256 | |
| 257 | - if ( file_exists( $gateway_file ) ) { |
|
| 258 | - require_once( $gateway_file ); |
|
| 257 | + if (file_exists($gateway_file)) { |
|
| 258 | + require_once($gateway_file); |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 263 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 264 | 264 | GetPaid_Post_Types_Admin::init(); |
| 265 | 265 | |
| 266 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 267 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 266 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 267 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 268 | 268 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
| 269 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 270 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 271 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 272 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 273 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 274 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 269 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
| 270 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 271 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 272 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
| 273 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
| 274 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
| 275 | 275 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
| 276 | 276 | // load the user class only on the users.php page |
| 277 | 277 | global $pagenow; |
| 278 | - if($pagenow=='users.php'){ |
|
| 278 | + if ($pagenow == 'users.php') { |
|
| 279 | 279 | new WPInv_Admin_Users(); |
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // Register cli commands |
| 284 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 285 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 286 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 284 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 285 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
| 286 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // include css inliner |
| 290 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 291 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 290 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
| 291 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 294 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -302,21 +302,21 @@ discard block |
||
| 302 | 302 | * @since 1.0.19 |
| 303 | 303 | * @return void |
| 304 | 304 | */ |
| 305 | - public function autoload( $class_name ) { |
|
| 305 | + public function autoload($class_name) { |
|
| 306 | 306 | |
| 307 | 307 | // Normalize the class name... |
| 308 | - $class_name = strtolower( $class_name ); |
|
| 308 | + $class_name = strtolower($class_name); |
|
| 309 | 309 | |
| 310 | 310 | // ... and make sure it is our class. |
| 311 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 311 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
| 312 | 312 | return; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | // Next, prepare the file name from the class. |
| 316 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 316 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
| 317 | 317 | |
| 318 | 318 | // Base path of the classes. |
| 319 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 319 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
| 320 | 320 | |
| 321 | 321 | // And an array of possible locations in order of importance. |
| 322 | 322 | $locations = array( |
@@ -328,10 +328,10 @@ discard block |
||
| 328 | 328 | "$plugin_path/includes/admin/meta-boxes", |
| 329 | 329 | ); |
| 330 | 330 | |
| 331 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 331 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
| 332 | 332 | |
| 333 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 334 | - include trailingslashit( $location ) . $file_name; |
|
| 333 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
| 334 | + include trailingslashit($location) . $file_name; |
|
| 335 | 335 | break; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | public function init() { |
| 346 | 346 | |
| 347 | 347 | // Fires before getpaid inits. |
| 348 | - do_action( 'before_getpaid_init', $this ); |
|
| 348 | + do_action('before_getpaid_init', $this); |
|
| 349 | 349 | |
| 350 | 350 | // Load default gateways. |
| 351 | 351 | $gateways = apply_filters( |
@@ -359,12 +359,12 @@ discard block |
||
| 359 | 359 | ) |
| 360 | 360 | ); |
| 361 | 361 | |
| 362 | - foreach ( $gateways as $id => $class ) { |
|
| 363 | - $this->gateways[ $id ] = new $class(); |
|
| 362 | + foreach ($gateways as $id => $class) { |
|
| 363 | + $this->gateways[$id] = new $class(); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | // Fires after getpaid inits. |
| 367 | - do_action( 'getpaid_init', $this ); |
|
| 367 | + do_action('getpaid_init', $this); |
|
| 368 | 368 | |
| 369 | 369 | } |
| 370 | 370 | |
@@ -374,82 +374,82 @@ discard block |
||
| 374 | 374 | public function maybe_process_ipn() { |
| 375 | 375 | |
| 376 | 376 | // Ensure that this is an IPN request. |
| 377 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 377 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
| 378 | 378 | return; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 381 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
| 382 | 382 | |
| 383 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 384 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 383 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
| 384 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
| 385 | 385 | exit; |
| 386 | 386 | |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | public function enqueue_scripts() { |
| 390 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 390 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 391 | 391 | |
| 392 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 393 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 394 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 392 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
| 393 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
| 394 | + wp_enqueue_style('wpinv_front_style'); |
|
| 395 | 395 | |
| 396 | 396 | // Register scripts |
| 397 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 398 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
| 397 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 398 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js')); |
|
| 399 | 399 | |
| 400 | 400 | $localize = array(); |
| 401 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 402 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 401 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 402 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 403 | 403 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 404 | 404 | $localize['currency_pos'] = wpinv_currency_position(); |
| 405 | 405 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 406 | 406 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 407 | 407 | $localize['decimals'] = wpinv_decimals(); |
| 408 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 408 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
| 409 | 409 | $localize['UseTaxes'] = wpinv_use_taxes(); |
| 410 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 411 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 412 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 410 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
| 411 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
| 412 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
| 413 | 413 | |
| 414 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 414 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 415 | 415 | |
| 416 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 416 | + wp_enqueue_script('jquery-blockui'); |
|
| 417 | 417 | $autofill_api = wpinv_get_option('address_autofill_api'); |
| 418 | 418 | $autofill_active = wpinv_get_option('address_autofill_active'); |
| 419 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 420 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 421 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 419 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
| 420 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
| 421 | + wp_dequeue_script('google-maps-api'); |
|
| 422 | 422 | } |
| 423 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 424 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 423 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 424 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 428 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 427 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
| 428 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 429 | 429 | |
| 430 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 431 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 430 | + wp_enqueue_script('wpinv-front-script'); |
|
| 431 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 432 | 432 | |
| 433 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 434 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
| 433 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
| 434 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | public function wpinv_actions() { |
| 438 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 439 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 438 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 439 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 440 | 440 | } |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - public function pre_get_posts( $wp_query ) { |
|
| 444 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 445 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 443 | + public function pre_get_posts($wp_query) { |
|
| 444 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 445 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | return $wp_query; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | public function bp_invoicing_init() { |
| 452 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 452 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -470,8 +470,8 @@ discard block |
||
| 470 | 470 | ) |
| 471 | 471 | ); |
| 472 | 472 | |
| 473 | - foreach ( $widgets as $widget ) { |
|
| 474 | - register_widget( $widget ); |
|
| 473 | + foreach ($widgets as $widget) { |
|
| 474 | + register_widget($widget); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | } |
@@ -482,10 +482,10 @@ discard block |
||
| 482 | 482 | * @since 1.0.19 |
| 483 | 483 | * @param int[] $excluded_posts_ids |
| 484 | 484 | */ |
| 485 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 485 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
| 486 | 486 | |
| 487 | 487 | // Ensure that we have an array. |
| 488 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 488 | + if (!is_array($excluded_posts_ids)) { |
|
| 489 | 489 | $excluded_posts_ids = array(); |
| 490 | 490 | } |
| 491 | 491 | |
@@ -493,24 +493,24 @@ discard block |
||
| 493 | 493 | $our_pages = array(); |
| 494 | 494 | |
| 495 | 495 | // Checkout page. |
| 496 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 496 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
| 497 | 497 | |
| 498 | 498 | // Success page. |
| 499 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 499 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
| 500 | 500 | |
| 501 | 501 | // Failure page. |
| 502 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 502 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
| 503 | 503 | |
| 504 | 504 | // History page. |
| 505 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 505 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
| 506 | 506 | |
| 507 | 507 | // Subscriptions page. |
| 508 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 508 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
| 509 | 509 | |
| 510 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 510 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
| 511 | 511 | |
| 512 | 512 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
| 513 | - return array_unique( $excluded_posts_ids ); |
|
| 513 | + return array_unique($excluded_posts_ids); |
|
| 514 | 514 | |
| 515 | 515 | } |
| 516 | 516 | |
@@ -15,127 +15,127 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Which data store to load. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $data_store_name = 'subscription'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * This is the name of this object type. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $object_type = 'subscription'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array( |
|
| 39 | - 'customer_id' => 0, |
|
| 40 | - 'frequency' => 1, |
|
| 41 | - 'period' => 'D', |
|
| 42 | - 'initial_amount' => null, |
|
| 43 | - 'recurring_amount' => null, |
|
| 44 | - 'bill_times' => 0, |
|
| 45 | - 'transaction_id' => '', |
|
| 46 | - 'parent_payment_id' => null, |
|
| 47 | - 'product_id' => 0, |
|
| 48 | - 'created' => '0000-00-00 00:00:00', |
|
| 49 | - 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | - 'trial_period' => null, |
|
| 51 | - 'status' => 'pending', |
|
| 52 | - 'profile_id' => '', |
|
| 53 | - 'gateway' => '', |
|
| 54 | - 'customer' => '', |
|
| 55 | - ); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Stores the status transition information. |
|
| 59 | - * |
|
| 60 | - * @since 1.0.19 |
|
| 61 | - * @var bool |
|
| 62 | - */ |
|
| 63 | - protected $status_transition = false; |
|
| 64 | - |
|
| 65 | - private $subs_db; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 69 | - * |
|
| 70 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 71 | - * @param bool $deprecated |
|
| 72 | - */ |
|
| 73 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 74 | - |
|
| 75 | - parent::__construct( $subscription ); |
|
| 76 | - |
|
| 77 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 78 | - $this->set_id( $subscription ); |
|
| 79 | - } elseif ( $subscription instanceof self ) { |
|
| 80 | - $this->set_id( $subscription->get_id() ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 83 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 84 | - $this->set_id( $subscription_id ); |
|
| 85 | - } else { |
|
| 86 | - $this->set_object_read( true ); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // Load the datastore. |
|
| 90 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 91 | - |
|
| 92 | - if ( $this->get_id() > 0 ) { |
|
| 93 | - $this->data_store->read( $this ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 100 | - * |
|
| 101 | - * |
|
| 102 | - * @static |
|
| 103 | - * @param string $value |
|
| 104 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 105 | - * @since 1.0.19 |
|
| 106 | - * @return int |
|
| 107 | - */ |
|
| 108 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 18 | + /** |
|
| 19 | + * Which data store to load. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $data_store_name = 'subscription'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * This is the name of this object type. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $object_type = 'subscription'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array( |
|
| 39 | + 'customer_id' => 0, |
|
| 40 | + 'frequency' => 1, |
|
| 41 | + 'period' => 'D', |
|
| 42 | + 'initial_amount' => null, |
|
| 43 | + 'recurring_amount' => null, |
|
| 44 | + 'bill_times' => 0, |
|
| 45 | + 'transaction_id' => '', |
|
| 46 | + 'parent_payment_id' => null, |
|
| 47 | + 'product_id' => 0, |
|
| 48 | + 'created' => '0000-00-00 00:00:00', |
|
| 49 | + 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | + 'trial_period' => null, |
|
| 51 | + 'status' => 'pending', |
|
| 52 | + 'profile_id' => '', |
|
| 53 | + 'gateway' => '', |
|
| 54 | + 'customer' => '', |
|
| 55 | + ); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Stores the status transition information. |
|
| 59 | + * |
|
| 60 | + * @since 1.0.19 |
|
| 61 | + * @var bool |
|
| 62 | + */ |
|
| 63 | + protected $status_transition = false; |
|
| 64 | + |
|
| 65 | + private $subs_db; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 69 | + * |
|
| 70 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 71 | + * @param bool $deprecated |
|
| 72 | + */ |
|
| 73 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
| 74 | + |
|
| 75 | + parent::__construct( $subscription ); |
|
| 76 | + |
|
| 77 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 78 | + $this->set_id( $subscription ); |
|
| 79 | + } elseif ( $subscription instanceof self ) { |
|
| 80 | + $this->set_id( $subscription->get_id() ); |
|
| 81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | + $this->set_id( $subscription->id ); |
|
| 83 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 84 | + $this->set_id( $subscription_id ); |
|
| 85 | + } else { |
|
| 86 | + $this->set_object_read( true ); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // Load the datastore. |
|
| 90 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 91 | + |
|
| 92 | + if ( $this->get_id() > 0 ) { |
|
| 93 | + $this->data_store->read( $this ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 100 | + * |
|
| 101 | + * |
|
| 102 | + * @static |
|
| 103 | + * @param string $value |
|
| 104 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 105 | + * @since 1.0.19 |
|
| 106 | + * @return int |
|
| 107 | + */ |
|
| 108 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 109 | 109 | global $wpdb; |
| 110 | 110 | |
| 111 | - // Trim the value. |
|
| 112 | - $value = trim( $value ); |
|
| 111 | + // Trim the value. |
|
| 112 | + $value = trim( $value ); |
|
| 113 | 113 | |
| 114 | - if ( empty( $value ) ) { |
|
| 115 | - return 0; |
|
| 116 | - } |
|
| 114 | + if ( empty( $value ) ) { |
|
| 115 | + return 0; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - if ( 'invoice_id' == $field ) { |
|
| 119 | - $field = 'parent_payment_id'; |
|
| 120 | - } |
|
| 118 | + if ( 'invoice_id' == $field ) { |
|
| 119 | + $field = 'parent_payment_id'; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | // Valid fields. |
| 123 | 123 | $fields = array( |
| 124 | - 'parent_payment_id', |
|
| 125 | - 'transaction_id', |
|
| 126 | - 'profile_id' |
|
| 127 | - ); |
|
| 128 | - |
|
| 129 | - // Ensure a field has been passed. |
|
| 130 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 131 | - return 0; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Maybe retrieve from the cache. |
|
| 135 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 136 | - if ( ! empty( $subscription_id ) ) { |
|
| 137 | - return $subscription_id; |
|
| 138 | - } |
|
| 124 | + 'parent_payment_id', |
|
| 125 | + 'transaction_id', |
|
| 126 | + 'profile_id' |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + // Ensure a field has been passed. |
|
| 130 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 131 | + return 0; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Maybe retrieve from the cache. |
|
| 135 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 136 | + if ( ! empty( $subscription_id ) ) { |
|
| 137 | + return $subscription_id; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | // Fetch from the db. |
| 141 | 141 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -143,34 +143,34 @@ discard block |
||
| 143 | 143 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | - if ( empty( $subscription_id ) ) { |
|
| 147 | - return 0; |
|
| 148 | - } |
|
| 146 | + if ( empty( $subscription_id ) ) { |
|
| 147 | + return 0; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - // Update the cache with our data. |
|
| 151 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 150 | + // Update the cache with our data. |
|
| 151 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 152 | 152 | |
| 153 | - return $subscription_id; |
|
| 154 | - } |
|
| 153 | + return $subscription_id; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 156 | + /** |
|
| 157 | 157 | * Clears the subscription's cache. |
| 158 | 158 | */ |
| 159 | 159 | public function clear_cache() { |
| 160 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 162 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 163 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 164 | - } |
|
| 160 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 161 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 162 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 163 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 166 | + /** |
|
| 167 | 167 | * Checks if a subscription key is set. |
| 168 | 168 | */ |
| 169 | 169 | public function _isset( $key ) { |
| 170 | 170 | return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
| 171 | - } |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - /* |
|
| 173 | + /* |
|
| 174 | 174 | |-------------------------------------------------------------------------- |
| 175 | 175 | | CRUD methods |
| 176 | 176 | |-------------------------------------------------------------------------- |
@@ -179,57 +179,57 @@ discard block |
||
| 179 | 179 | | |
| 180 | 180 | */ |
| 181 | 181 | |
| 182 | - /* |
|
| 182 | + /* |
|
| 183 | 183 | |-------------------------------------------------------------------------- |
| 184 | 184 | | Getters |
| 185 | 185 | |-------------------------------------------------------------------------- |
| 186 | 186 | */ |
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Get customer id. |
|
| 190 | - * |
|
| 191 | - * @since 1.0.19 |
|
| 192 | - * @param string $context View or edit context. |
|
| 193 | - * @return int |
|
| 194 | - */ |
|
| 195 | - public function get_customer_id( $context = 'view' ) { |
|
| 196 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Get customer information. |
|
| 201 | - * |
|
| 202 | - * @since 1.0.19 |
|
| 203 | - * @param string $context View or edit context. |
|
| 204 | - * @return WP_User|false WP_User object on success, false on failure. |
|
| 205 | - */ |
|
| 206 | - public function get_customer( $context = 'view' ) { |
|
| 207 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Get parent invoice id. |
|
| 212 | - * |
|
| 213 | - * @since 1.0.19 |
|
| 214 | - * @param string $context View or edit context. |
|
| 215 | - * @return int |
|
| 216 | - */ |
|
| 217 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 218 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Alias for self::get_parent_invoice_id(). |
|
| 223 | - * |
|
| 224 | - * @since 1.0.19 |
|
| 225 | - * @param string $context View or edit context. |
|
| 226 | - * @return int |
|
| 227 | - */ |
|
| 188 | + /** |
|
| 189 | + * Get customer id. |
|
| 190 | + * |
|
| 191 | + * @since 1.0.19 |
|
| 192 | + * @param string $context View or edit context. |
|
| 193 | + * @return int |
|
| 194 | + */ |
|
| 195 | + public function get_customer_id( $context = 'view' ) { |
|
| 196 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Get customer information. |
|
| 201 | + * |
|
| 202 | + * @since 1.0.19 |
|
| 203 | + * @param string $context View or edit context. |
|
| 204 | + * @return WP_User|false WP_User object on success, false on failure. |
|
| 205 | + */ |
|
| 206 | + public function get_customer( $context = 'view' ) { |
|
| 207 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Get parent invoice id. |
|
| 212 | + * |
|
| 213 | + * @since 1.0.19 |
|
| 214 | + * @param string $context View or edit context. |
|
| 215 | + * @return int |
|
| 216 | + */ |
|
| 217 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
| 218 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Alias for self::get_parent_invoice_id(). |
|
| 223 | + * |
|
| 224 | + * @since 1.0.19 |
|
| 225 | + * @param string $context View or edit context. |
|
| 226 | + * @return int |
|
| 227 | + */ |
|
| 228 | 228 | public function get_parent_payment_id( $context = 'view' ) { |
| 229 | 229 | return $this->get_parent_invoice_id( $context ); |
| 230 | - } |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 232 | + /** |
|
| 233 | 233 | * Alias for self::get_parent_invoice_id(). |
| 234 | 234 | * |
| 235 | 235 | * @since 1.0.0 |
@@ -239,390 +239,390 @@ discard block |
||
| 239 | 239 | return $this->get_parent_invoice_id( $context ); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * Get parent invoice. |
|
| 244 | - * |
|
| 245 | - * @since 1.0.19 |
|
| 246 | - * @param string $context View or edit context. |
|
| 247 | - * @return WPInv_Invoice |
|
| 248 | - */ |
|
| 249 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 250 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Alias for self::get_parent_invoice(). |
|
| 255 | - * |
|
| 256 | - * @since 1.0.19 |
|
| 257 | - * @param string $context View or edit context. |
|
| 258 | - * @return WPInv_Invoice |
|
| 259 | - */ |
|
| 242 | + /** |
|
| 243 | + * Get parent invoice. |
|
| 244 | + * |
|
| 245 | + * @since 1.0.19 |
|
| 246 | + * @param string $context View or edit context. |
|
| 247 | + * @return WPInv_Invoice |
|
| 248 | + */ |
|
| 249 | + public function get_parent_invoice( $context = 'view' ) { |
|
| 250 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Alias for self::get_parent_invoice(). |
|
| 255 | + * |
|
| 256 | + * @since 1.0.19 |
|
| 257 | + * @param string $context View or edit context. |
|
| 258 | + * @return WPInv_Invoice |
|
| 259 | + */ |
|
| 260 | 260 | public function get_parent_payment( $context = 'view' ) { |
| 261 | 261 | return $this->get_parent_invoice( $context ); |
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Get subscription's product id. |
|
| 266 | - * |
|
| 267 | - * @since 1.0.19 |
|
| 268 | - * @param string $context View or edit context. |
|
| 269 | - * @return int |
|
| 270 | - */ |
|
| 271 | - public function get_product_id( $context = 'view' ) { |
|
| 272 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Get the subscription product. |
|
| 277 | - * |
|
| 278 | - * @since 1.0.19 |
|
| 279 | - * @param string $context View or edit context. |
|
| 280 | - * @return WPInv_Item |
|
| 281 | - */ |
|
| 282 | - public function get_product( $context = 'view' ) { |
|
| 283 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Get parent invoice's gateway. |
|
| 288 | - * |
|
| 289 | - * Here for backwards compatibility. |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @param string $context View or edit context. |
|
| 293 | - * @return string |
|
| 294 | - */ |
|
| 295 | - public function get_gateway( $context = 'view' ) { |
|
| 296 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Get the period of a renewal. |
|
| 301 | - * |
|
| 302 | - * @since 1.0.19 |
|
| 303 | - * @param string $context View or edit context. |
|
| 304 | - * @return string |
|
| 305 | - */ |
|
| 306 | - public function get_period( $context = 'view' ) { |
|
| 307 | - return $this->get_prop( 'period', $context ); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Get number of periods each renewal is valid for. |
|
| 312 | - * |
|
| 313 | - * @since 1.0.19 |
|
| 314 | - * @param string $context View or edit context. |
|
| 315 | - * @return int |
|
| 316 | - */ |
|
| 317 | - public function get_frequency( $context = 'view' ) { |
|
| 318 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Get the initial amount for the subscription. |
|
| 323 | - * |
|
| 324 | - * @since 1.0.19 |
|
| 325 | - * @param string $context View or edit context. |
|
| 326 | - * @return float |
|
| 327 | - */ |
|
| 328 | - public function get_initial_amount( $context = 'view' ) { |
|
| 329 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Get the recurring amount for the subscription. |
|
| 334 | - * |
|
| 335 | - * @since 1.0.19 |
|
| 336 | - * @param string $context View or edit context. |
|
| 337 | - * @return float |
|
| 338 | - */ |
|
| 339 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 340 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Get number of times that this subscription can be renewed. |
|
| 345 | - * |
|
| 346 | - * @since 1.0.19 |
|
| 347 | - * @param string $context View or edit context. |
|
| 348 | - * @return int |
|
| 349 | - */ |
|
| 350 | - public function get_bill_times( $context = 'view' ) { |
|
| 351 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Get transaction id of this subscription's parent invoice. |
|
| 356 | - * |
|
| 357 | - * @since 1.0.19 |
|
| 358 | - * @param string $context View or edit context. |
|
| 359 | - * @return string |
|
| 360 | - */ |
|
| 361 | - public function get_transaction_id( $context = 'view' ) { |
|
| 362 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Get the date that the subscription was created. |
|
| 367 | - * |
|
| 368 | - * @since 1.0.19 |
|
| 369 | - * @param string $context View or edit context. |
|
| 370 | - * @return string |
|
| 371 | - */ |
|
| 372 | - public function get_created( $context = 'view' ) { |
|
| 373 | - return $this->get_prop( 'created', $context ); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Alias for self::get_created(). |
|
| 378 | - * |
|
| 379 | - * @since 1.0.19 |
|
| 380 | - * @param string $context View or edit context. |
|
| 381 | - * @return string |
|
| 382 | - */ |
|
| 383 | - public function get_date_created( $context = 'view' ) { |
|
| 384 | - return $this->get_created( $context ); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Retrieves the creation date in a timestamp |
|
| 389 | - * |
|
| 390 | - * @since 1.0.0 |
|
| 391 | - * @return int |
|
| 392 | - */ |
|
| 393 | - public function get_time_created() { |
|
| 394 | - $created = $this->get_date_created(); |
|
| 395 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Get GMT date when the subscription was created. |
|
| 400 | - * |
|
| 401 | - * @since 1.0.19 |
|
| 402 | - * @param string $context View or edit context. |
|
| 403 | - * @return string |
|
| 404 | - */ |
|
| 405 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Get subscription's product id. |
|
| 266 | + * |
|
| 267 | + * @since 1.0.19 |
|
| 268 | + * @param string $context View or edit context. |
|
| 269 | + * @return int |
|
| 270 | + */ |
|
| 271 | + public function get_product_id( $context = 'view' ) { |
|
| 272 | + return (int) $this->get_prop( 'product_id', $context ); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Get the subscription product. |
|
| 277 | + * |
|
| 278 | + * @since 1.0.19 |
|
| 279 | + * @param string $context View or edit context. |
|
| 280 | + * @return WPInv_Item |
|
| 281 | + */ |
|
| 282 | + public function get_product( $context = 'view' ) { |
|
| 283 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Get parent invoice's gateway. |
|
| 288 | + * |
|
| 289 | + * Here for backwards compatibility. |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @param string $context View or edit context. |
|
| 293 | + * @return string |
|
| 294 | + */ |
|
| 295 | + public function get_gateway( $context = 'view' ) { |
|
| 296 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Get the period of a renewal. |
|
| 301 | + * |
|
| 302 | + * @since 1.0.19 |
|
| 303 | + * @param string $context View or edit context. |
|
| 304 | + * @return string |
|
| 305 | + */ |
|
| 306 | + public function get_period( $context = 'view' ) { |
|
| 307 | + return $this->get_prop( 'period', $context ); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Get number of periods each renewal is valid for. |
|
| 312 | + * |
|
| 313 | + * @since 1.0.19 |
|
| 314 | + * @param string $context View or edit context. |
|
| 315 | + * @return int |
|
| 316 | + */ |
|
| 317 | + public function get_frequency( $context = 'view' ) { |
|
| 318 | + return (int) $this->get_prop( 'frequency', $context ); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Get the initial amount for the subscription. |
|
| 323 | + * |
|
| 324 | + * @since 1.0.19 |
|
| 325 | + * @param string $context View or edit context. |
|
| 326 | + * @return float |
|
| 327 | + */ |
|
| 328 | + public function get_initial_amount( $context = 'view' ) { |
|
| 329 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Get the recurring amount for the subscription. |
|
| 334 | + * |
|
| 335 | + * @since 1.0.19 |
|
| 336 | + * @param string $context View or edit context. |
|
| 337 | + * @return float |
|
| 338 | + */ |
|
| 339 | + public function get_recurring_amount( $context = 'view' ) { |
|
| 340 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Get number of times that this subscription can be renewed. |
|
| 345 | + * |
|
| 346 | + * @since 1.0.19 |
|
| 347 | + * @param string $context View or edit context. |
|
| 348 | + * @return int |
|
| 349 | + */ |
|
| 350 | + public function get_bill_times( $context = 'view' ) { |
|
| 351 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Get transaction id of this subscription's parent invoice. |
|
| 356 | + * |
|
| 357 | + * @since 1.0.19 |
|
| 358 | + * @param string $context View or edit context. |
|
| 359 | + * @return string |
|
| 360 | + */ |
|
| 361 | + public function get_transaction_id( $context = 'view' ) { |
|
| 362 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Get the date that the subscription was created. |
|
| 367 | + * |
|
| 368 | + * @since 1.0.19 |
|
| 369 | + * @param string $context View or edit context. |
|
| 370 | + * @return string |
|
| 371 | + */ |
|
| 372 | + public function get_created( $context = 'view' ) { |
|
| 373 | + return $this->get_prop( 'created', $context ); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Alias for self::get_created(). |
|
| 378 | + * |
|
| 379 | + * @since 1.0.19 |
|
| 380 | + * @param string $context View or edit context. |
|
| 381 | + * @return string |
|
| 382 | + */ |
|
| 383 | + public function get_date_created( $context = 'view' ) { |
|
| 384 | + return $this->get_created( $context ); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Retrieves the creation date in a timestamp |
|
| 389 | + * |
|
| 390 | + * @since 1.0.0 |
|
| 391 | + * @return int |
|
| 392 | + */ |
|
| 393 | + public function get_time_created() { |
|
| 394 | + $created = $this->get_date_created(); |
|
| 395 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Get GMT date when the subscription was created. |
|
| 400 | + * |
|
| 401 | + * @since 1.0.19 |
|
| 402 | + * @param string $context View or edit context. |
|
| 403 | + * @return string |
|
| 404 | + */ |
|
| 405 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 406 | 406 | $date = $this->get_date_created( $context ); |
| 407 | 407 | |
| 408 | 408 | if ( $date ) { |
| 409 | 409 | $date = get_gmt_from_date( $date ); |
| 410 | 410 | } |
| 411 | - return $date; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Get the date that the subscription will renew. |
|
| 416 | - * |
|
| 417 | - * @since 1.0.19 |
|
| 418 | - * @param string $context View or edit context. |
|
| 419 | - * @return string |
|
| 420 | - */ |
|
| 421 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 422 | - return $this->get_prop( 'expiration', $context ); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Alias for self::get_next_renewal_date(). |
|
| 427 | - * |
|
| 428 | - * @since 1.0.19 |
|
| 429 | - * @param string $context View or edit context. |
|
| 430 | - * @return string |
|
| 431 | - */ |
|
| 432 | - public function get_expiration( $context = 'view' ) { |
|
| 433 | - return $this->get_next_renewal_date( $context ); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Retrieves the expiration date in a timestamp |
|
| 438 | - * |
|
| 439 | - * @since 1.0.0 |
|
| 440 | - * @return int |
|
| 441 | - */ |
|
| 442 | - public function get_expiration_time() { |
|
| 443 | - $expiration = $this->get_expiration(); |
|
| 444 | - |
|
| 445 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 446 | - return current_time( 'timestamp' ); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 450 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Get GMT date when the subscription will renew. |
|
| 455 | - * |
|
| 456 | - * @since 1.0.19 |
|
| 457 | - * @param string $context View or edit context. |
|
| 458 | - * @return string |
|
| 459 | - */ |
|
| 460 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 411 | + return $date; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Get the date that the subscription will renew. |
|
| 416 | + * |
|
| 417 | + * @since 1.0.19 |
|
| 418 | + * @param string $context View or edit context. |
|
| 419 | + * @return string |
|
| 420 | + */ |
|
| 421 | + public function get_next_renewal_date( $context = 'view' ) { |
|
| 422 | + return $this->get_prop( 'expiration', $context ); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Alias for self::get_next_renewal_date(). |
|
| 427 | + * |
|
| 428 | + * @since 1.0.19 |
|
| 429 | + * @param string $context View or edit context. |
|
| 430 | + * @return string |
|
| 431 | + */ |
|
| 432 | + public function get_expiration( $context = 'view' ) { |
|
| 433 | + return $this->get_next_renewal_date( $context ); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Retrieves the expiration date in a timestamp |
|
| 438 | + * |
|
| 439 | + * @since 1.0.0 |
|
| 440 | + * @return int |
|
| 441 | + */ |
|
| 442 | + public function get_expiration_time() { |
|
| 443 | + $expiration = $this->get_expiration(); |
|
| 444 | + |
|
| 445 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 446 | + return current_time( 'timestamp' ); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 450 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Get GMT date when the subscription will renew. |
|
| 455 | + * |
|
| 456 | + * @since 1.0.19 |
|
| 457 | + * @param string $context View or edit context. |
|
| 458 | + * @return string |
|
| 459 | + */ |
|
| 460 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 461 | 461 | $date = $this->get_next_renewal_date( $context ); |
| 462 | 462 | |
| 463 | 463 | if ( $date ) { |
| 464 | 464 | $date = get_gmt_from_date( $date ); |
| 465 | 465 | } |
| 466 | - return $date; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Get the subscription's trial period. |
|
| 471 | - * |
|
| 472 | - * @since 1.0.19 |
|
| 473 | - * @param string $context View or edit context. |
|
| 474 | - * @return string |
|
| 475 | - */ |
|
| 476 | - public function get_trial_period( $context = 'view' ) { |
|
| 477 | - return $this->get_prop( 'trial_period', $context ); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * Get the subscription's status. |
|
| 482 | - * |
|
| 483 | - * @since 1.0.19 |
|
| 484 | - * @param string $context View or edit context. |
|
| 485 | - * @return string |
|
| 486 | - */ |
|
| 487 | - public function get_status( $context = 'view' ) { |
|
| 488 | - return $this->get_prop( 'status', $context ); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Get the subscription's profile id. |
|
| 493 | - * |
|
| 494 | - * @since 1.0.19 |
|
| 495 | - * @param string $context View or edit context. |
|
| 496 | - * @return string |
|
| 497 | - */ |
|
| 498 | - public function get_profile_id( $context = 'view' ) { |
|
| 499 | - return $this->get_prop( 'profile_id', $context ); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /* |
|
| 466 | + return $date; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Get the subscription's trial period. |
|
| 471 | + * |
|
| 472 | + * @since 1.0.19 |
|
| 473 | + * @param string $context View or edit context. |
|
| 474 | + * @return string |
|
| 475 | + */ |
|
| 476 | + public function get_trial_period( $context = 'view' ) { |
|
| 477 | + return $this->get_prop( 'trial_period', $context ); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * Get the subscription's status. |
|
| 482 | + * |
|
| 483 | + * @since 1.0.19 |
|
| 484 | + * @param string $context View or edit context. |
|
| 485 | + * @return string |
|
| 486 | + */ |
|
| 487 | + public function get_status( $context = 'view' ) { |
|
| 488 | + return $this->get_prop( 'status', $context ); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Get the subscription's profile id. |
|
| 493 | + * |
|
| 494 | + * @since 1.0.19 |
|
| 495 | + * @param string $context View or edit context. |
|
| 496 | + * @return string |
|
| 497 | + */ |
|
| 498 | + public function get_profile_id( $context = 'view' ) { |
|
| 499 | + return $this->get_prop( 'profile_id', $context ); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /* |
|
| 503 | 503 | |-------------------------------------------------------------------------- |
| 504 | 504 | | Setters |
| 505 | 505 | |-------------------------------------------------------------------------- |
| 506 | 506 | */ |
| 507 | 507 | |
| 508 | - /** |
|
| 509 | - * Set customer id. |
|
| 510 | - * |
|
| 511 | - * @since 1.0.19 |
|
| 512 | - * @param int $value The customer's id. |
|
| 513 | - */ |
|
| 514 | - public function set_customer_id( $value ) { |
|
| 515 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * Set parent invoice id. |
|
| 520 | - * |
|
| 521 | - * @since 1.0.19 |
|
| 522 | - * @param int $value The parent invoice id. |
|
| 523 | - */ |
|
| 524 | - public function set_parent_invoice_id( $value ) { |
|
| 525 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * Alias for self::set_parent_invoice_id(). |
|
| 530 | - * |
|
| 531 | - * @since 1.0.19 |
|
| 532 | - * @param int $value The parent invoice id. |
|
| 533 | - */ |
|
| 508 | + /** |
|
| 509 | + * Set customer id. |
|
| 510 | + * |
|
| 511 | + * @since 1.0.19 |
|
| 512 | + * @param int $value The customer's id. |
|
| 513 | + */ |
|
| 514 | + public function set_customer_id( $value ) { |
|
| 515 | + $this->set_prop( 'customer_id', (int) $value ); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * Set parent invoice id. |
|
| 520 | + * |
|
| 521 | + * @since 1.0.19 |
|
| 522 | + * @param int $value The parent invoice id. |
|
| 523 | + */ |
|
| 524 | + public function set_parent_invoice_id( $value ) { |
|
| 525 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * Alias for self::set_parent_invoice_id(). |
|
| 530 | + * |
|
| 531 | + * @since 1.0.19 |
|
| 532 | + * @param int $value The parent invoice id. |
|
| 533 | + */ |
|
| 534 | 534 | public function set_parent_payment_id( $value ) { |
| 535 | 535 | $this->set_parent_invoice_id( $value ); |
| 536 | - } |
|
| 536 | + } |
|
| 537 | 537 | |
| 538 | - /** |
|
| 538 | + /** |
|
| 539 | 539 | * Alias for self::set_parent_invoice_id(). |
| 540 | 540 | * |
| 541 | 541 | * @since 1.0.19 |
| 542 | - * @param int $value The parent invoice id. |
|
| 542 | + * @param int $value The parent invoice id. |
|
| 543 | 543 | */ |
| 544 | 544 | public function set_original_payment_id( $value ) { |
| 545 | 545 | $this->set_parent_invoice_id( $value ); |
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Set subscription's product id. |
|
| 550 | - * |
|
| 551 | - * @since 1.0.19 |
|
| 552 | - * @param int $value The subscription product id. |
|
| 553 | - */ |
|
| 554 | - public function set_product_id( $value ) { |
|
| 555 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Set the period of a renewal. |
|
| 560 | - * |
|
| 561 | - * @since 1.0.19 |
|
| 562 | - * @param string $value The renewal period. |
|
| 563 | - */ |
|
| 564 | - public function set_period( $value ) { |
|
| 565 | - $this->set_prop( 'period', $value ); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Set number of periods each renewal is valid for. |
|
| 570 | - * |
|
| 571 | - * @since 1.0.19 |
|
| 572 | - * @param int $value The subscription frequency. |
|
| 573 | - */ |
|
| 574 | - public function set_frequency( $value ) { |
|
| 575 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 576 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Set the initial amount for the subscription. |
|
| 581 | - * |
|
| 582 | - * @since 1.0.19 |
|
| 583 | - * @param float $value The initial subcription amount. |
|
| 584 | - */ |
|
| 585 | - public function set_initial_amount( $value ) { |
|
| 586 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Set the recurring amount for the subscription. |
|
| 591 | - * |
|
| 592 | - * @since 1.0.19 |
|
| 593 | - * @param float $value The recurring subcription amount. |
|
| 594 | - */ |
|
| 595 | - public function set_recurring_amount( $value ) { |
|
| 596 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * Set number of times that this subscription can be renewed. |
|
| 601 | - * |
|
| 602 | - * @since 1.0.19 |
|
| 603 | - * @param int $value Bill times. |
|
| 604 | - */ |
|
| 605 | - public function set_bill_times( $value ) { |
|
| 606 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * Get transaction id of this subscription's parent invoice. |
|
| 611 | - * |
|
| 612 | - * @since 1.0.19 |
|
| 613 | - * @param string $value Bill times. |
|
| 614 | - */ |
|
| 615 | - public function set_transaction_id( $value ) { |
|
| 616 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Set date when this subscription started. |
|
| 621 | - * |
|
| 622 | - * @since 1.0.19 |
|
| 623 | - * @param string $value strtotime compliant date. |
|
| 624 | - */ |
|
| 625 | - public function set_created( $value ) { |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Set subscription's product id. |
|
| 550 | + * |
|
| 551 | + * @since 1.0.19 |
|
| 552 | + * @param int $value The subscription product id. |
|
| 553 | + */ |
|
| 554 | + public function set_product_id( $value ) { |
|
| 555 | + $this->set_prop( 'product_id', (int) $value ); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Set the period of a renewal. |
|
| 560 | + * |
|
| 561 | + * @since 1.0.19 |
|
| 562 | + * @param string $value The renewal period. |
|
| 563 | + */ |
|
| 564 | + public function set_period( $value ) { |
|
| 565 | + $this->set_prop( 'period', $value ); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Set number of periods each renewal is valid for. |
|
| 570 | + * |
|
| 571 | + * @since 1.0.19 |
|
| 572 | + * @param int $value The subscription frequency. |
|
| 573 | + */ |
|
| 574 | + public function set_frequency( $value ) { |
|
| 575 | + $value = empty( $value ) ? 1 : (int) $value; |
|
| 576 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Set the initial amount for the subscription. |
|
| 581 | + * |
|
| 582 | + * @since 1.0.19 |
|
| 583 | + * @param float $value The initial subcription amount. |
|
| 584 | + */ |
|
| 585 | + public function set_initial_amount( $value ) { |
|
| 586 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Set the recurring amount for the subscription. |
|
| 591 | + * |
|
| 592 | + * @since 1.0.19 |
|
| 593 | + * @param float $value The recurring subcription amount. |
|
| 594 | + */ |
|
| 595 | + public function set_recurring_amount( $value ) { |
|
| 596 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * Set number of times that this subscription can be renewed. |
|
| 601 | + * |
|
| 602 | + * @since 1.0.19 |
|
| 603 | + * @param int $value Bill times. |
|
| 604 | + */ |
|
| 605 | + public function set_bill_times( $value ) { |
|
| 606 | + $this->set_prop( 'bill_times', (int) $value ); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * Get transaction id of this subscription's parent invoice. |
|
| 611 | + * |
|
| 612 | + * @since 1.0.19 |
|
| 613 | + * @param string $value Bill times. |
|
| 614 | + */ |
|
| 615 | + public function set_transaction_id( $value ) { |
|
| 616 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Set date when this subscription started. |
|
| 621 | + * |
|
| 622 | + * @since 1.0.19 |
|
| 623 | + * @param string $value strtotime compliant date. |
|
| 624 | + */ |
|
| 625 | + public function set_created( $value ) { |
|
| 626 | 626 | $date = strtotime( $value ); |
| 627 | 627 | |
| 628 | 628 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -630,94 +630,94 @@ discard block |
||
| 630 | 630 | return; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - $this->set_prop( 'created', '' ); |
|
| 633 | + $this->set_prop( 'created', '' ); |
|
| 634 | 634 | |
| 635 | - } |
|
| 635 | + } |
|
| 636 | 636 | |
| 637 | - /** |
|
| 638 | - * Alias for self::set_created(). |
|
| 639 | - * |
|
| 640 | - * @since 1.0.19 |
|
| 641 | - * @param string $value strtotime compliant date. |
|
| 642 | - */ |
|
| 643 | - public function set_date_created( $value ) { |
|
| 644 | - $this->set_created( $value ); |
|
| 637 | + /** |
|
| 638 | + * Alias for self::set_created(). |
|
| 639 | + * |
|
| 640 | + * @since 1.0.19 |
|
| 641 | + * @param string $value strtotime compliant date. |
|
| 642 | + */ |
|
| 643 | + public function set_date_created( $value ) { |
|
| 644 | + $this->set_created( $value ); |
|
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - /** |
|
| 648 | - * Set the date that the subscription will renew. |
|
| 649 | - * |
|
| 650 | - * @since 1.0.19 |
|
| 651 | - * @param string $value strtotime compliant date. |
|
| 652 | - */ |
|
| 653 | - public function set_next_renewal_date( $value ) { |
|
| 654 | - $date = strtotime( $value ); |
|
| 647 | + /** |
|
| 648 | + * Set the date that the subscription will renew. |
|
| 649 | + * |
|
| 650 | + * @since 1.0.19 |
|
| 651 | + * @param string $value strtotime compliant date. |
|
| 652 | + */ |
|
| 653 | + public function set_next_renewal_date( $value ) { |
|
| 654 | + $date = strtotime( $value ); |
|
| 655 | 655 | |
| 656 | 656 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
| 657 | 657 | $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
| 658 | 658 | return; |
| 659 | - } |
|
| 660 | - |
|
| 661 | - $this->set_prop( 'expiration', '' ); |
|
| 662 | - |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * Alias for self::set_next_renewal_date(). |
|
| 667 | - * |
|
| 668 | - * @since 1.0.19 |
|
| 669 | - * @param string $value strtotime compliant date. |
|
| 670 | - */ |
|
| 671 | - public function set_expiration( $value ) { |
|
| 672 | - $this->set_next_renewal_date( $value ); |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Set the subscription's trial period. |
|
| 677 | - * |
|
| 678 | - * @since 1.0.19 |
|
| 679 | - * @param string $value trial period e.g 1 year. |
|
| 680 | - */ |
|
| 681 | - public function set_trial_period( $value ) { |
|
| 682 | - $this->set_prop( 'trial_period', $value ); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Set the subscription's status. |
|
| 687 | - * |
|
| 688 | - * @since 1.0.19 |
|
| 689 | - * @param string $new_status New subscription status. |
|
| 690 | - */ |
|
| 691 | - public function set_status( $new_status ) { |
|
| 692 | - |
|
| 693 | - // Abort if this is not a valid status; |
|
| 694 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 695 | - return; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - $old_status = $this->get_status(); |
|
| 699 | - $this->set_prop( 'status', $new_status ); |
|
| 700 | - |
|
| 701 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 702 | - $this->status_transition = array( |
|
| 703 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 704 | - 'to' => $new_status, |
|
| 705 | - ); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * Set the subscription's (remote) profile id. |
|
| 712 | - * |
|
| 713 | - * @since 1.0.19 |
|
| 714 | - * @param string $value the remote profile id. |
|
| 715 | - */ |
|
| 716 | - public function set_profile_id( $value ) { |
|
| 717 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - /* |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + $this->set_prop( 'expiration', '' ); |
|
| 662 | + |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * Alias for self::set_next_renewal_date(). |
|
| 667 | + * |
|
| 668 | + * @since 1.0.19 |
|
| 669 | + * @param string $value strtotime compliant date. |
|
| 670 | + */ |
|
| 671 | + public function set_expiration( $value ) { |
|
| 672 | + $this->set_next_renewal_date( $value ); |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Set the subscription's trial period. |
|
| 677 | + * |
|
| 678 | + * @since 1.0.19 |
|
| 679 | + * @param string $value trial period e.g 1 year. |
|
| 680 | + */ |
|
| 681 | + public function set_trial_period( $value ) { |
|
| 682 | + $this->set_prop( 'trial_period', $value ); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Set the subscription's status. |
|
| 687 | + * |
|
| 688 | + * @since 1.0.19 |
|
| 689 | + * @param string $new_status New subscription status. |
|
| 690 | + */ |
|
| 691 | + public function set_status( $new_status ) { |
|
| 692 | + |
|
| 693 | + // Abort if this is not a valid status; |
|
| 694 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 695 | + return; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + $old_status = $this->get_status(); |
|
| 699 | + $this->set_prop( 'status', $new_status ); |
|
| 700 | + |
|
| 701 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 702 | + $this->status_transition = array( |
|
| 703 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 704 | + 'to' => $new_status, |
|
| 705 | + ); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * Set the subscription's (remote) profile id. |
|
| 712 | + * |
|
| 713 | + * @since 1.0.19 |
|
| 714 | + * @param string $value the remote profile id. |
|
| 715 | + */ |
|
| 716 | + public function set_profile_id( $value ) { |
|
| 717 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + /* |
|
| 721 | 721 | |-------------------------------------------------------------------------- |
| 722 | 722 | | Boolean methods |
| 723 | 723 | |-------------------------------------------------------------------------- |
@@ -726,45 +726,45 @@ discard block |
||
| 726 | 726 | | |
| 727 | 727 | */ |
| 728 | 728 | |
| 729 | - /** |
|
| 729 | + /** |
|
| 730 | 730 | * Checks if the subscription has a given status. |
| 731 | - * |
|
| 732 | - * @param string|array String or array of strings to check for. |
|
| 733 | - * @return bool |
|
| 731 | + * |
|
| 732 | + * @param string|array String or array of strings to check for. |
|
| 733 | + * @return bool |
|
| 734 | 734 | */ |
| 735 | 735 | public function has_status( $status ) { |
| 736 | 736 | return in_array( $this->get_status(), wpinv_parse_list( $status ) ); |
| 737 | - } |
|
| 737 | + } |
|
| 738 | 738 | |
| 739 | - /** |
|
| 739 | + /** |
|
| 740 | 740 | * Checks if the subscription has a trial period. |
| 741 | - * |
|
| 742 | - * @return bool |
|
| 741 | + * |
|
| 742 | + * @return bool |
|
| 743 | 743 | */ |
| 744 | 744 | public function has_trial_period() { |
| 745 | - $period = $this->get_trial_period(); |
|
| 745 | + $period = $this->get_trial_period(); |
|
| 746 | 746 | return ! empty( $period ); |
| 747 | - } |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * Is the subscription active? |
|
| 751 | - * |
|
| 752 | - * @return bool |
|
| 753 | - */ |
|
| 754 | - public function is_active() { |
|
| 755 | - return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' ); |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * Is the subscription expired? |
|
| 760 | - * |
|
| 761 | - * @return bool |
|
| 762 | - */ |
|
| 763 | - public function is_expired() { |
|
| 764 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - /* |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * Is the subscription active? |
|
| 751 | + * |
|
| 752 | + * @return bool |
|
| 753 | + */ |
|
| 754 | + public function is_active() { |
|
| 755 | + return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' ); |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * Is the subscription expired? |
|
| 760 | + * |
|
| 761 | + * @return bool |
|
| 762 | + */ |
|
| 763 | + public function is_expired() { |
|
| 764 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + /* |
|
| 768 | 768 | |-------------------------------------------------------------------------- |
| 769 | 769 | | Additional methods |
| 770 | 770 | |-------------------------------------------------------------------------- |
@@ -773,27 +773,27 @@ discard block |
||
| 773 | 773 | | |
| 774 | 774 | */ |
| 775 | 775 | |
| 776 | - /** |
|
| 777 | - * Backwards compatibilty. |
|
| 778 | - */ |
|
| 779 | - public function create( $data = array() ) { |
|
| 776 | + /** |
|
| 777 | + * Backwards compatibilty. |
|
| 778 | + */ |
|
| 779 | + public function create( $data = array() ) { |
|
| 780 | 780 | |
| 781 | - // Set the properties. |
|
| 782 | - if ( is_array( $data ) ) { |
|
| 783 | - $this->set_props( $data ); |
|
| 784 | - } |
|
| 781 | + // Set the properties. |
|
| 782 | + if ( is_array( $data ) ) { |
|
| 783 | + $this->set_props( $data ); |
|
| 784 | + } |
|
| 785 | 785 | |
| 786 | - // Save the item. |
|
| 787 | - return $this->save(); |
|
| 786 | + // Save the item. |
|
| 787 | + return $this->save(); |
|
| 788 | 788 | |
| 789 | - } |
|
| 789 | + } |
|
| 790 | 790 | |
| 791 | - /** |
|
| 792 | - * Backwards compatibilty. |
|
| 793 | - */ |
|
| 794 | - public function update( $args = array() ) { |
|
| 795 | - return $this->create( $args ); |
|
| 796 | - } |
|
| 791 | + /** |
|
| 792 | + * Backwards compatibilty. |
|
| 793 | + */ |
|
| 794 | + public function update( $args = array() ) { |
|
| 795 | + return $this->create( $args ); |
|
| 796 | + } |
|
| 797 | 797 | |
| 798 | 798 | /** |
| 799 | 799 | * Retrieve renewal payments for a subscription |
@@ -803,15 +803,15 @@ discard block |
||
| 803 | 803 | */ |
| 804 | 804 | public function get_child_payments() { |
| 805 | 805 | return get_posts( |
| 806 | - array( |
|
| 807 | - 'post_parent' => $this->get_parent_payment_id(), |
|
| 808 | - 'numberposts' => -1, |
|
| 809 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
| 810 | - 'orderby' => 'ID', |
|
| 811 | - 'order' => 'DESC', |
|
| 812 | - 'post_type' => 'wpi_invoice' |
|
| 813 | - ) |
|
| 814 | - ); |
|
| 806 | + array( |
|
| 807 | + 'post_parent' => $this->get_parent_payment_id(), |
|
| 808 | + 'numberposts' => -1, |
|
| 809 | + 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
| 810 | + 'orderby' => 'ID', |
|
| 811 | + 'order' => 'DESC', |
|
| 812 | + 'post_type' => 'wpi_invoice' |
|
| 813 | + ) |
|
| 814 | + ); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | /** |
@@ -821,16 +821,16 @@ discard block |
||
| 821 | 821 | * @return int |
| 822 | 822 | */ |
| 823 | 823 | public function get_total_payments() { |
| 824 | - global $wpdb; |
|
| 824 | + global $wpdb; |
|
| 825 | 825 | |
| 826 | - $count = (int) $wpdb->get_var( |
|
| 827 | - $wpdb->prepare( |
|
| 828 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 829 | - $this->get_parent_invoice_id() |
|
| 830 | - ) |
|
| 831 | - ); |
|
| 826 | + $count = (int) $wpdb->get_var( |
|
| 827 | + $wpdb->prepare( |
|
| 828 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 829 | + $this->get_parent_invoice_id() |
|
| 830 | + ) |
|
| 831 | + ); |
|
| 832 | 832 | |
| 833 | - // Maybe include parent invoice. |
|
| 833 | + // Maybe include parent invoice. |
|
| 834 | 834 | if ( ! $this->has_status( 'pending' ) ) { |
| 835 | 835 | $count++; |
| 836 | 836 | } |
@@ -859,57 +859,57 @@ discard block |
||
| 859 | 859 | * |
| 860 | 860 | * @since 2.4 |
| 861 | 861 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 862 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 862 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 863 | 863 | * @return bool |
| 864 | 864 | */ |
| 865 | 865 | public function add_payment( $args = array(), $invoice = false ) { |
| 866 | 866 | |
| 867 | - // Process each payment once. |
|
| 867 | + // Process each payment once. |
|
| 868 | 868 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
| 869 | 869 | return false; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | - // Are we creating a new invoice? |
|
| 873 | - if ( empty( $invoice ) ) { |
|
| 874 | - $invoice = $this->create_payment(); |
|
| 872 | + // Are we creating a new invoice? |
|
| 873 | + if ( empty( $invoice ) ) { |
|
| 874 | + $invoice = $this->create_payment(); |
|
| 875 | 875 | |
| 876 | - if ( empty( $invoice ) ) { |
|
| 877 | - return false; |
|
| 878 | - } |
|
| 876 | + if ( empty( $invoice ) ) { |
|
| 877 | + return false; |
|
| 878 | + } |
|
| 879 | 879 | |
| 880 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 880 | + $invoice->set_status( 'wpi-renewal' ); |
|
| 881 | 881 | |
| 882 | - } |
|
| 882 | + } |
|
| 883 | 883 | |
| 884 | - // Maybe set a transaction id. |
|
| 885 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 886 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 887 | - } |
|
| 884 | + // Maybe set a transaction id. |
|
| 885 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
| 886 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 887 | + } |
|
| 888 | 888 | |
| 889 | - // Set the completed date. |
|
| 890 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 889 | + // Set the completed date. |
|
| 890 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 891 | 891 | |
| 892 | - // And the gateway. |
|
| 893 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 894 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 895 | - } |
|
| 892 | + // And the gateway. |
|
| 893 | + if ( ! empty( $args['gateway'] ) ) { |
|
| 894 | + $invoice->set_gateway( $args['gateway'] ); |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | - $invoice->save(); |
|
| 897 | + $invoice->save(); |
|
| 898 | 898 | |
| 899 | - if ( ! $invoice->get_id() ) { |
|
| 900 | - return 0; |
|
| 901 | - } |
|
| 899 | + if ( ! $invoice->get_id() ) { |
|
| 900 | + return 0; |
|
| 901 | + } |
|
| 902 | 902 | |
| 903 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 904 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 903 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 904 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 905 | 905 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
| 906 | 906 | |
| 907 | 907 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
| 908 | 908 | |
| 909 | 909 | return $invoice->get_id(); |
| 910 | - } |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | - /** |
|
| 912 | + /** |
|
| 913 | 913 | * Creates a new invoice and returns it. |
| 914 | 914 | * |
| 915 | 915 | * @since 1.0.19 |
@@ -917,104 +917,104 @@ discard block |
||
| 917 | 917 | */ |
| 918 | 918 | public function create_payment() { |
| 919 | 919 | |
| 920 | - $parent_invoice = $this->get_parent_payment(); |
|
| 921 | - |
|
| 922 | - if ( ! $parent_invoice->get_id() ) { |
|
| 923 | - return false; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - // Duplicate the parent invoice. |
|
| 927 | - $invoice = new WPInv_Invoice(); |
|
| 928 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
| 929 | - $invoice->set_id( 0 ); |
|
| 930 | - $invoice->set_items( $parent_invoice->get_items() ); |
|
| 931 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 932 | - $invoice->set_transaction_id( '' ); |
|
| 933 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
| 934 | - $invoice->set_number( '' ); |
|
| 935 | - $invoice->set_completed_date( '' ); |
|
| 936 | - $invoice->set_status( 'wpi-pending' ); |
|
| 937 | - $invoice->recalculate_total(); |
|
| 938 | - $invoice->save(); |
|
| 939 | - |
|
| 940 | - return $invoice->get_id() ? $invoice : false; |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * Renews or completes a subscription |
|
| 945 | - * |
|
| 946 | - * @since 1.0.0 |
|
| 947 | - * @return int The subscription's id |
|
| 948 | - */ |
|
| 949 | - public function renew() { |
|
| 950 | - |
|
| 951 | - // Complete subscription if applicable |
|
| 952 | - if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
| 953 | - return $this->complete(); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - // Calculate new expiration |
|
| 957 | - $frequency = $this->get_frequency(); |
|
| 958 | - $period = $this->get_period(); |
|
| 959 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 960 | - |
|
| 961 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 962 | - $this->set_status( 'active' ); |
|
| 963 | - return $this->save(); |
|
| 964 | - |
|
| 965 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 966 | - |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - /** |
|
| 970 | - * Marks a subscription as completed |
|
| 971 | - * |
|
| 972 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 973 | - * |
|
| 974 | - * @since 1.0.0 |
|
| 975 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 976 | - */ |
|
| 977 | - public function complete() { |
|
| 978 | - |
|
| 979 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 980 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 981 | - return false; |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - $this->set_status( 'completed' ); |
|
| 985 | - return $this->save(); |
|
| 986 | - |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - /** |
|
| 990 | - * Marks a subscription as expired |
|
| 991 | - * |
|
| 992 | - * @since 1.0.0 |
|
| 993 | - * @param bool $check_expiration |
|
| 994 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 995 | - */ |
|
| 996 | - public function expire( $check_expiration = false ) { |
|
| 997 | - |
|
| 998 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 999 | - // Do not mark as expired since real expiration date is in the future |
|
| 1000 | - return false; |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - $this->set_status( 'expired' ); |
|
| 1004 | - return $this->save(); |
|
| 1005 | - |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - /** |
|
| 1009 | - * Marks a subscription as failing |
|
| 1010 | - * |
|
| 1011 | - * @since 2.4.2 |
|
| 1012 | - * @return int Subscription id. |
|
| 1013 | - */ |
|
| 1014 | - public function failing() { |
|
| 1015 | - $this->set_status( 'failing' ); |
|
| 1016 | - return $this->save(); |
|
| 1017 | - } |
|
| 920 | + $parent_invoice = $this->get_parent_payment(); |
|
| 921 | + |
|
| 922 | + if ( ! $parent_invoice->get_id() ) { |
|
| 923 | + return false; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + // Duplicate the parent invoice. |
|
| 927 | + $invoice = new WPInv_Invoice(); |
|
| 928 | + $invoice->set_props( $parent_invoice->get_data() ); |
|
| 929 | + $invoice->set_id( 0 ); |
|
| 930 | + $invoice->set_items( $parent_invoice->get_items() ); |
|
| 931 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 932 | + $invoice->set_transaction_id( '' ); |
|
| 933 | + $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
| 934 | + $invoice->set_number( '' ); |
|
| 935 | + $invoice->set_completed_date( '' ); |
|
| 936 | + $invoice->set_status( 'wpi-pending' ); |
|
| 937 | + $invoice->recalculate_total(); |
|
| 938 | + $invoice->save(); |
|
| 939 | + |
|
| 940 | + return $invoice->get_id() ? $invoice : false; |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * Renews or completes a subscription |
|
| 945 | + * |
|
| 946 | + * @since 1.0.0 |
|
| 947 | + * @return int The subscription's id |
|
| 948 | + */ |
|
| 949 | + public function renew() { |
|
| 950 | + |
|
| 951 | + // Complete subscription if applicable |
|
| 952 | + if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
| 953 | + return $this->complete(); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + // Calculate new expiration |
|
| 957 | + $frequency = $this->get_frequency(); |
|
| 958 | + $period = $this->get_period(); |
|
| 959 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 960 | + |
|
| 961 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 962 | + $this->set_status( 'active' ); |
|
| 963 | + return $this->save(); |
|
| 964 | + |
|
| 965 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
| 966 | + |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + /** |
|
| 970 | + * Marks a subscription as completed |
|
| 971 | + * |
|
| 972 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 973 | + * |
|
| 974 | + * @since 1.0.0 |
|
| 975 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 976 | + */ |
|
| 977 | + public function complete() { |
|
| 978 | + |
|
| 979 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 980 | + if ( $this->has_status( 'cancelled' ) ) { |
|
| 981 | + return false; |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + $this->set_status( 'completed' ); |
|
| 985 | + return $this->save(); |
|
| 986 | + |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + /** |
|
| 990 | + * Marks a subscription as expired |
|
| 991 | + * |
|
| 992 | + * @since 1.0.0 |
|
| 993 | + * @param bool $check_expiration |
|
| 994 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 995 | + */ |
|
| 996 | + public function expire( $check_expiration = false ) { |
|
| 997 | + |
|
| 998 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 999 | + // Do not mark as expired since real expiration date is in the future |
|
| 1000 | + return false; |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + $this->set_status( 'expired' ); |
|
| 1004 | + return $this->save(); |
|
| 1005 | + |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + /** |
|
| 1009 | + * Marks a subscription as failing |
|
| 1010 | + * |
|
| 1011 | + * @since 2.4.2 |
|
| 1012 | + * @return int Subscription id. |
|
| 1013 | + */ |
|
| 1014 | + public function failing() { |
|
| 1015 | + $this->set_status( 'failing' ); |
|
| 1016 | + return $this->save(); |
|
| 1017 | + } |
|
| 1018 | 1018 | |
| 1019 | 1019 | /** |
| 1020 | 1020 | * Marks a subscription as cancelled |
@@ -1023,19 +1023,19 @@ discard block |
||
| 1023 | 1023 | * @return int Subscription id. |
| 1024 | 1024 | */ |
| 1025 | 1025 | public function cancel() { |
| 1026 | - $this->set_status( 'cancelled' ); |
|
| 1027 | - return $this->save(); |
|
| 1026 | + $this->set_status( 'cancelled' ); |
|
| 1027 | + return $this->save(); |
|
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | - /** |
|
| 1031 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1032 | - * |
|
| 1033 | - * @since 1.0.0 |
|
| 1034 | - * @return bool |
|
| 1035 | - */ |
|
| 1036 | - public function can_cancel() { |
|
| 1037 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1038 | - } |
|
| 1030 | + /** |
|
| 1031 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1032 | + * |
|
| 1033 | + * @since 1.0.0 |
|
| 1034 | + * @return bool |
|
| 1035 | + */ |
|
| 1036 | + public function can_cancel() { |
|
| 1037 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1038 | + } |
|
| 1039 | 1039 | |
| 1040 | 1040 | /** |
| 1041 | 1041 | * Returns an array of subscription statuses that can be cancelled |
@@ -1048,82 +1048,82 @@ discard block |
||
| 1048 | 1048 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | - /** |
|
| 1052 | - * Retrieves the URL to cancel subscription |
|
| 1053 | - * |
|
| 1054 | - * @since 1.0.0 |
|
| 1055 | - * @return string |
|
| 1056 | - */ |
|
| 1057 | - public function get_cancel_url() { |
|
| 1058 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' ); |
|
| 1059 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - /** |
|
| 1063 | - * Determines if subscription can be manually renewed |
|
| 1064 | - * |
|
| 1065 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1066 | - * that can be renewed manually |
|
| 1067 | - * |
|
| 1068 | - * @since 2.5 |
|
| 1069 | - * @return bool |
|
| 1070 | - */ |
|
| 1071 | - public function can_renew() { |
|
| 1072 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * Retrieves the URL to renew a subscription |
|
| 1077 | - * |
|
| 1078 | - * @since 2.5 |
|
| 1079 | - * @return string |
|
| 1080 | - */ |
|
| 1081 | - public function get_renew_url() { |
|
| 1082 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' ); |
|
| 1083 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * Determines if subscription can have their payment method updated |
|
| 1088 | - * |
|
| 1089 | - * @since 1.0.0 |
|
| 1090 | - * @return bool |
|
| 1091 | - */ |
|
| 1092 | - public function can_update() { |
|
| 1093 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * Retrieves the URL to update subscription |
|
| 1098 | - * |
|
| 1099 | - * @since 1.0.0 |
|
| 1100 | - * @return string |
|
| 1101 | - */ |
|
| 1102 | - public function get_update_url() { |
|
| 1103 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1104 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - /** |
|
| 1108 | - * Retrieves the subscription status label |
|
| 1109 | - * |
|
| 1110 | - * @since 1.0.0 |
|
| 1111 | - * @return string |
|
| 1112 | - */ |
|
| 1113 | - public function get_status_label() { |
|
| 1114 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - /** |
|
| 1118 | - * Retrieves the subscription status class |
|
| 1119 | - * |
|
| 1120 | - * @since 1.0.19 |
|
| 1121 | - * @return string |
|
| 1122 | - */ |
|
| 1123 | - public function get_status_class() { |
|
| 1124 | - $statuses = getpaid_get_subscription_status_classes(); |
|
| 1125 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
| 1126 | - } |
|
| 1051 | + /** |
|
| 1052 | + * Retrieves the URL to cancel subscription |
|
| 1053 | + * |
|
| 1054 | + * @since 1.0.0 |
|
| 1055 | + * @return string |
|
| 1056 | + */ |
|
| 1057 | + public function get_cancel_url() { |
|
| 1058 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' ); |
|
| 1059 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + /** |
|
| 1063 | + * Determines if subscription can be manually renewed |
|
| 1064 | + * |
|
| 1065 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1066 | + * that can be renewed manually |
|
| 1067 | + * |
|
| 1068 | + * @since 2.5 |
|
| 1069 | + * @return bool |
|
| 1070 | + */ |
|
| 1071 | + public function can_renew() { |
|
| 1072 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * Retrieves the URL to renew a subscription |
|
| 1077 | + * |
|
| 1078 | + * @since 2.5 |
|
| 1079 | + * @return string |
|
| 1080 | + */ |
|
| 1081 | + public function get_renew_url() { |
|
| 1082 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' ); |
|
| 1083 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * Determines if subscription can have their payment method updated |
|
| 1088 | + * |
|
| 1089 | + * @since 1.0.0 |
|
| 1090 | + * @return bool |
|
| 1091 | + */ |
|
| 1092 | + public function can_update() { |
|
| 1093 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * Retrieves the URL to update subscription |
|
| 1098 | + * |
|
| 1099 | + * @since 1.0.0 |
|
| 1100 | + * @return string |
|
| 1101 | + */ |
|
| 1102 | + public function get_update_url() { |
|
| 1103 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1104 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + /** |
|
| 1108 | + * Retrieves the subscription status label |
|
| 1109 | + * |
|
| 1110 | + * @since 1.0.0 |
|
| 1111 | + * @return string |
|
| 1112 | + */ |
|
| 1113 | + public function get_status_label() { |
|
| 1114 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + /** |
|
| 1118 | + * Retrieves the subscription status class |
|
| 1119 | + * |
|
| 1120 | + * @since 1.0.19 |
|
| 1121 | + * @return string |
|
| 1122 | + */ |
|
| 1123 | + public function get_status_class() { |
|
| 1124 | + $statuses = getpaid_get_subscription_status_classes(); |
|
| 1125 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
| 1126 | + } |
|
| 1127 | 1127 | |
| 1128 | 1128 | /** |
| 1129 | 1129 | * Retrieves the subscription status label |
@@ -1133,11 +1133,11 @@ discard block |
||
| 1133 | 1133 | */ |
| 1134 | 1134 | public function get_status_label_html() { |
| 1135 | 1135 | |
| 1136 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1137 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1138 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
| 1136 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1137 | + $class = esc_attr( $this->get_status_class() ); |
|
| 1138 | + $status = sanitize_html_class( $this->get_status_label() ); |
|
| 1139 | 1139 | |
| 1140 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
| 1140 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | /** |
@@ -1148,63 +1148,63 @@ discard block |
||
| 1148 | 1148 | * @return bool |
| 1149 | 1149 | */ |
| 1150 | 1150 | public function payment_exists( $txn_id = '' ) { |
| 1151 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1151 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1152 | 1152 | return ! empty( $invoice_id ); |
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - /** |
|
| 1156 | - * Handle the status transition. |
|
| 1157 | - */ |
|
| 1158 | - protected function status_transition() { |
|
| 1159 | - $status_transition = $this->status_transition; |
|
| 1160 | - |
|
| 1161 | - // Reset status transition variable. |
|
| 1162 | - $this->status_transition = false; |
|
| 1163 | - |
|
| 1164 | - if ( $status_transition ) { |
|
| 1165 | - try { |
|
| 1166 | - |
|
| 1167 | - // Fire a hook for the status change. |
|
| 1168 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1169 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1170 | - |
|
| 1171 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1172 | - |
|
| 1173 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1174 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1175 | - |
|
| 1176 | - // Fire another hook. |
|
| 1177 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1178 | - do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
| 1179 | - |
|
| 1180 | - // Note the transition occurred. |
|
| 1181 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1182 | - |
|
| 1183 | - } else { |
|
| 1184 | - /* translators: %s: new invoice status */ |
|
| 1185 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1186 | - |
|
| 1187 | - // Note the transition occurred. |
|
| 1188 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1189 | - |
|
| 1190 | - } |
|
| 1191 | - } catch ( Exception $e ) { |
|
| 1192 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1193 | - } |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - /** |
|
| 1199 | - * Save data to the database. |
|
| 1200 | - * |
|
| 1201 | - * @since 1.0.19 |
|
| 1202 | - * @return int subscription ID |
|
| 1203 | - */ |
|
| 1204 | - public function save() { |
|
| 1205 | - parent::save(); |
|
| 1206 | - $this->status_transition(); |
|
| 1207 | - return $this->get_id(); |
|
| 1208 | - } |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + /** |
|
| 1156 | + * Handle the status transition. |
|
| 1157 | + */ |
|
| 1158 | + protected function status_transition() { |
|
| 1159 | + $status_transition = $this->status_transition; |
|
| 1160 | + |
|
| 1161 | + // Reset status transition variable. |
|
| 1162 | + $this->status_transition = false; |
|
| 1163 | + |
|
| 1164 | + if ( $status_transition ) { |
|
| 1165 | + try { |
|
| 1166 | + |
|
| 1167 | + // Fire a hook for the status change. |
|
| 1168 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1169 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1170 | + |
|
| 1171 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 1172 | + |
|
| 1173 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1174 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1175 | + |
|
| 1176 | + // Fire another hook. |
|
| 1177 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1178 | + do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
| 1179 | + |
|
| 1180 | + // Note the transition occurred. |
|
| 1181 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1182 | + |
|
| 1183 | + } else { |
|
| 1184 | + /* translators: %s: new invoice status */ |
|
| 1185 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1186 | + |
|
| 1187 | + // Note the transition occurred. |
|
| 1188 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1189 | + |
|
| 1190 | + } |
|
| 1191 | + } catch ( Exception $e ) { |
|
| 1192 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1193 | + } |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + /** |
|
| 1199 | + * Save data to the database. |
|
| 1200 | + * |
|
| 1201 | + * @since 1.0.19 |
|
| 1202 | + * @return int subscription ID |
|
| 1203 | + */ |
|
| 1204 | + public function save() { |
|
| 1205 | + parent::save(); |
|
| 1206 | + $this->status_transition(); |
|
| 1207 | + return $this->get_id(); |
|
| 1208 | + } |
|
| 1209 | 1209 | |
| 1210 | 1210 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * The Subscription Class |
@@ -70,27 +70,27 @@ discard block |
||
| 70 | 70 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
| 71 | 71 | * @param bool $deprecated |
| 72 | 72 | */ |
| 73 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 73 | + function __construct($subscription = 0, $deprecated = false) { |
|
| 74 | 74 | |
| 75 | - parent::__construct( $subscription ); |
|
| 75 | + parent::__construct($subscription); |
|
| 76 | 76 | |
| 77 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 78 | - $this->set_id( $subscription ); |
|
| 79 | - } elseif ( $subscription instanceof self ) { |
|
| 80 | - $this->set_id( $subscription->get_id() ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 83 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 84 | - $this->set_id( $subscription_id ); |
|
| 77 | + if (!$deprecated && !empty($subscription) && is_numeric($subscription)) { |
|
| 78 | + $this->set_id($subscription); |
|
| 79 | + } elseif ($subscription instanceof self) { |
|
| 80 | + $this->set_id($subscription->get_id()); |
|
| 81 | + } elseif (!empty($subscription->id)) { |
|
| 82 | + $this->set_id($subscription->id); |
|
| 83 | + } elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) { |
|
| 84 | + $this->set_id($subscription_id); |
|
| 85 | 85 | } else { |
| 86 | - $this->set_object_read( true ); |
|
| 86 | + $this->set_object_read(true); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Load the datastore. |
| 90 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 90 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 91 | 91 | |
| 92 | - if ( $this->get_id() > 0 ) { |
|
| 93 | - $this->data_store->read( $this ); |
|
| 92 | + if ($this->get_id() > 0) { |
|
| 93 | + $this->data_store->read($this); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | } |
@@ -105,17 +105,17 @@ discard block |
||
| 105 | 105 | * @since 1.0.19 |
| 106 | 106 | * @return int |
| 107 | 107 | */ |
| 108 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 108 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
| 109 | 109 | global $wpdb; |
| 110 | 110 | |
| 111 | 111 | // Trim the value. |
| 112 | - $value = trim( $value ); |
|
| 112 | + $value = trim($value); |
|
| 113 | 113 | |
| 114 | - if ( empty( $value ) ) { |
|
| 114 | + if (empty($value)) { |
|
| 115 | 115 | return 0; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if ( 'invoice_id' == $field ) { |
|
| 118 | + if ('invoice_id' == $field) { |
|
| 119 | 119 | $field = 'parent_payment_id'; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -127,28 +127,28 @@ discard block |
||
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | 129 | // Ensure a field has been passed. |
| 130 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 130 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 131 | 131 | return 0; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // Maybe retrieve from the cache. |
| 135 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 136 | - if ( ! empty( $subscription_id ) ) { |
|
| 135 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 136 | + if (!empty($subscription_id)) { |
|
| 137 | 137 | return $subscription_id; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // Fetch from the db. |
| 141 | 141 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
| 142 | 142 | $subscription_id = (int) $wpdb->get_var( |
| 143 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
| 143 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | - if ( empty( $subscription_id ) ) { |
|
| 146 | + if (empty($subscription_id)) { |
|
| 147 | 147 | return 0; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // Update the cache with our data. |
| 151 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 151 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 152 | 152 | |
| 153 | 153 | return $subscription_id; |
| 154 | 154 | } |
@@ -157,17 +157,17 @@ discard block |
||
| 157 | 157 | * Clears the subscription's cache. |
| 158 | 158 | */ |
| 159 | 159 | public function clear_cache() { |
| 160 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 162 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 163 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 160 | + wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids'); |
|
| 161 | + wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
| 162 | + wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
| 163 | + wp_cache_delete($this->get_id(), 'getpaid_subscriptions'); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | * Checks if a subscription key is set. |
| 168 | 168 | */ |
| 169 | - public function _isset( $key ) { |
|
| 170 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
|
| 169 | + public function _isset($key) { |
|
| 170 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /* |
@@ -192,8 +192,8 @@ discard block |
||
| 192 | 192 | * @param string $context View or edit context. |
| 193 | 193 | * @return int |
| 194 | 194 | */ |
| 195 | - public function get_customer_id( $context = 'view' ) { |
|
| 196 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | + public function get_customer_id($context = 'view') { |
|
| 196 | + return (int) $this->get_prop('customer_id', $context); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | * @param string $context View or edit context. |
| 204 | 204 | * @return WP_User|false WP_User object on success, false on failure. |
| 205 | 205 | */ |
| 206 | - public function get_customer( $context = 'view' ) { |
|
| 207 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | + public function get_customer($context = 'view') { |
|
| 207 | + return get_userdata($this->get_customer_id($context)); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -214,8 +214,8 @@ discard block |
||
| 214 | 214 | * @param string $context View or edit context. |
| 215 | 215 | * @return int |
| 216 | 216 | */ |
| 217 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 218 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | + public function get_parent_invoice_id($context = 'view') { |
|
| 218 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | * @param string $context View or edit context. |
| 226 | 226 | * @return int |
| 227 | 227 | */ |
| 228 | - public function get_parent_payment_id( $context = 'view' ) { |
|
| 229 | - return $this->get_parent_invoice_id( $context ); |
|
| 228 | + public function get_parent_payment_id($context = 'view') { |
|
| 229 | + return $this->get_parent_invoice_id($context); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -235,8 +235,8 @@ discard block |
||
| 235 | 235 | * @since 1.0.0 |
| 236 | 236 | * @return int |
| 237 | 237 | */ |
| 238 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 239 | - return $this->get_parent_invoice_id( $context ); |
|
| 238 | + public function get_original_payment_id($context = 'view') { |
|
| 239 | + return $this->get_parent_invoice_id($context); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -246,8 +246,8 @@ discard block |
||
| 246 | 246 | * @param string $context View or edit context. |
| 247 | 247 | * @return WPInv_Invoice |
| 248 | 248 | */ |
| 249 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 250 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | + public function get_parent_invoice($context = 'view') { |
|
| 250 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | * @param string $context View or edit context. |
| 258 | 258 | * @return WPInv_Invoice |
| 259 | 259 | */ |
| 260 | - public function get_parent_payment( $context = 'view' ) { |
|
| 261 | - return $this->get_parent_invoice( $context ); |
|
| 260 | + public function get_parent_payment($context = 'view') { |
|
| 261 | + return $this->get_parent_invoice($context); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -268,8 +268,8 @@ discard block |
||
| 268 | 268 | * @param string $context View or edit context. |
| 269 | 269 | * @return int |
| 270 | 270 | */ |
| 271 | - public function get_product_id( $context = 'view' ) { |
|
| 272 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | + public function get_product_id($context = 'view') { |
|
| 272 | + return (int) $this->get_prop('product_id', $context); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | * @param string $context View or edit context. |
| 280 | 280 | * @return WPInv_Item |
| 281 | 281 | */ |
| 282 | - public function get_product( $context = 'view' ) { |
|
| 283 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | + public function get_product($context = 'view') { |
|
| 283 | + return new WPInv_Item($this->get_product_id($context)); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | * @param string $context View or edit context. |
| 293 | 293 | * @return string |
| 294 | 294 | */ |
| 295 | - public function get_gateway( $context = 'view' ) { |
|
| 296 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | + public function get_gateway($context = 'view') { |
|
| 296 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | * @param string $context View or edit context. |
| 304 | 304 | * @return string |
| 305 | 305 | */ |
| 306 | - public function get_period( $context = 'view' ) { |
|
| 307 | - return $this->get_prop( 'period', $context ); |
|
| 306 | + public function get_period($context = 'view') { |
|
| 307 | + return $this->get_prop('period', $context); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | * @param string $context View or edit context. |
| 315 | 315 | * @return int |
| 316 | 316 | */ |
| 317 | - public function get_frequency( $context = 'view' ) { |
|
| 318 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | + public function get_frequency($context = 'view') { |
|
| 318 | + return (int) $this->get_prop('frequency', $context); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -325,8 +325,8 @@ discard block |
||
| 325 | 325 | * @param string $context View or edit context. |
| 326 | 326 | * @return float |
| 327 | 327 | */ |
| 328 | - public function get_initial_amount( $context = 'view' ) { |
|
| 329 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | + public function get_initial_amount($context = 'view') { |
|
| 329 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -336,8 +336,8 @@ discard block |
||
| 336 | 336 | * @param string $context View or edit context. |
| 337 | 337 | * @return float |
| 338 | 338 | */ |
| 339 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 340 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | + public function get_recurring_amount($context = 'view') { |
|
| 340 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -347,8 +347,8 @@ discard block |
||
| 347 | 347 | * @param string $context View or edit context. |
| 348 | 348 | * @return int |
| 349 | 349 | */ |
| 350 | - public function get_bill_times( $context = 'view' ) { |
|
| 351 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | + public function get_bill_times($context = 'view') { |
|
| 351 | + return (int) $this->get_prop('bill_times', $context); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -358,8 +358,8 @@ discard block |
||
| 358 | 358 | * @param string $context View or edit context. |
| 359 | 359 | * @return string |
| 360 | 360 | */ |
| 361 | - public function get_transaction_id( $context = 'view' ) { |
|
| 362 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | + public function get_transaction_id($context = 'view') { |
|
| 362 | + return $this->get_prop('transaction_id', $context); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -369,8 +369,8 @@ discard block |
||
| 369 | 369 | * @param string $context View or edit context. |
| 370 | 370 | * @return string |
| 371 | 371 | */ |
| 372 | - public function get_created( $context = 'view' ) { |
|
| 373 | - return $this->get_prop( 'created', $context ); |
|
| 372 | + public function get_created($context = 'view') { |
|
| 373 | + return $this->get_prop('created', $context); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -380,8 +380,8 @@ discard block |
||
| 380 | 380 | * @param string $context View or edit context. |
| 381 | 381 | * @return string |
| 382 | 382 | */ |
| 383 | - public function get_date_created( $context = 'view' ) { |
|
| 384 | - return $this->get_created( $context ); |
|
| 383 | + public function get_date_created($context = 'view') { |
|
| 384 | + return $this->get_created($context); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | */ |
| 393 | 393 | public function get_time_created() { |
| 394 | 394 | $created = $this->get_date_created(); |
| 395 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 395 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -402,11 +402,11 @@ discard block |
||
| 402 | 402 | * @param string $context View or edit context. |
| 403 | 403 | * @return string |
| 404 | 404 | */ |
| 405 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 406 | - $date = $this->get_date_created( $context ); |
|
| 405 | + public function get_date_created_gmt($context = 'view') { |
|
| 406 | + $date = $this->get_date_created($context); |
|
| 407 | 407 | |
| 408 | - if ( $date ) { |
|
| 409 | - $date = get_gmt_from_date( $date ); |
|
| 408 | + if ($date) { |
|
| 409 | + $date = get_gmt_from_date($date); |
|
| 410 | 410 | } |
| 411 | 411 | return $date; |
| 412 | 412 | } |
@@ -418,8 +418,8 @@ discard block |
||
| 418 | 418 | * @param string $context View or edit context. |
| 419 | 419 | * @return string |
| 420 | 420 | */ |
| 421 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 422 | - return $this->get_prop( 'expiration', $context ); |
|
| 421 | + public function get_next_renewal_date($context = 'view') { |
|
| 422 | + return $this->get_prop('expiration', $context); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | /** |
@@ -429,8 +429,8 @@ discard block |
||
| 429 | 429 | * @param string $context View or edit context. |
| 430 | 430 | * @return string |
| 431 | 431 | */ |
| 432 | - public function get_expiration( $context = 'view' ) { |
|
| 433 | - return $this->get_next_renewal_date( $context ); |
|
| 432 | + public function get_expiration($context = 'view') { |
|
| 433 | + return $this->get_next_renewal_date($context); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -442,12 +442,12 @@ discard block |
||
| 442 | 442 | public function get_expiration_time() { |
| 443 | 443 | $expiration = $this->get_expiration(); |
| 444 | 444 | |
| 445 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 446 | - return current_time( 'timestamp' ); |
|
| 445 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
| 446 | + return current_time('timestamp'); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 450 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
| 450 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -457,11 +457,11 @@ discard block |
||
| 457 | 457 | * @param string $context View or edit context. |
| 458 | 458 | * @return string |
| 459 | 459 | */ |
| 460 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 461 | - $date = $this->get_next_renewal_date( $context ); |
|
| 460 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
| 461 | + $date = $this->get_next_renewal_date($context); |
|
| 462 | 462 | |
| 463 | - if ( $date ) { |
|
| 464 | - $date = get_gmt_from_date( $date ); |
|
| 463 | + if ($date) { |
|
| 464 | + $date = get_gmt_from_date($date); |
|
| 465 | 465 | } |
| 466 | 466 | return $date; |
| 467 | 467 | } |
@@ -473,8 +473,8 @@ discard block |
||
| 473 | 473 | * @param string $context View or edit context. |
| 474 | 474 | * @return string |
| 475 | 475 | */ |
| 476 | - public function get_trial_period( $context = 'view' ) { |
|
| 477 | - return $this->get_prop( 'trial_period', $context ); |
|
| 476 | + public function get_trial_period($context = 'view') { |
|
| 477 | + return $this->get_prop('trial_period', $context); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -484,8 +484,8 @@ discard block |
||
| 484 | 484 | * @param string $context View or edit context. |
| 485 | 485 | * @return string |
| 486 | 486 | */ |
| 487 | - public function get_status( $context = 'view' ) { |
|
| 488 | - return $this->get_prop( 'status', $context ); |
|
| 487 | + public function get_status($context = 'view') { |
|
| 488 | + return $this->get_prop('status', $context); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | /** |
@@ -495,8 +495,8 @@ discard block |
||
| 495 | 495 | * @param string $context View or edit context. |
| 496 | 496 | * @return string |
| 497 | 497 | */ |
| 498 | - public function get_profile_id( $context = 'view' ) { |
|
| 499 | - return $this->get_prop( 'profile_id', $context ); |
|
| 498 | + public function get_profile_id($context = 'view') { |
|
| 499 | + return $this->get_prop('profile_id', $context); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /* |
@@ -511,8 +511,8 @@ discard block |
||
| 511 | 511 | * @since 1.0.19 |
| 512 | 512 | * @param int $value The customer's id. |
| 513 | 513 | */ |
| 514 | - public function set_customer_id( $value ) { |
|
| 515 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | + public function set_customer_id($value) { |
|
| 515 | + $this->set_prop('customer_id', (int) $value); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -521,8 +521,8 @@ discard block |
||
| 521 | 521 | * @since 1.0.19 |
| 522 | 522 | * @param int $value The parent invoice id. |
| 523 | 523 | */ |
| 524 | - public function set_parent_invoice_id( $value ) { |
|
| 525 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | + public function set_parent_invoice_id($value) { |
|
| 525 | + $this->set_prop('parent_payment_id', (int) $value); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -531,8 +531,8 @@ discard block |
||
| 531 | 531 | * @since 1.0.19 |
| 532 | 532 | * @param int $value The parent invoice id. |
| 533 | 533 | */ |
| 534 | - public function set_parent_payment_id( $value ) { |
|
| 535 | - $this->set_parent_invoice_id( $value ); |
|
| 534 | + public function set_parent_payment_id($value) { |
|
| 535 | + $this->set_parent_invoice_id($value); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | /** |
@@ -541,8 +541,8 @@ discard block |
||
| 541 | 541 | * @since 1.0.19 |
| 542 | 542 | * @param int $value The parent invoice id. |
| 543 | 543 | */ |
| 544 | - public function set_original_payment_id( $value ) { |
|
| 545 | - $this->set_parent_invoice_id( $value ); |
|
| 544 | + public function set_original_payment_id($value) { |
|
| 545 | + $this->set_parent_invoice_id($value); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -551,8 +551,8 @@ discard block |
||
| 551 | 551 | * @since 1.0.19 |
| 552 | 552 | * @param int $value The subscription product id. |
| 553 | 553 | */ |
| 554 | - public function set_product_id( $value ) { |
|
| 555 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | + public function set_product_id($value) { |
|
| 555 | + $this->set_prop('product_id', (int) $value); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | /** |
@@ -561,8 +561,8 @@ discard block |
||
| 561 | 561 | * @since 1.0.19 |
| 562 | 562 | * @param string $value The renewal period. |
| 563 | 563 | */ |
| 564 | - public function set_period( $value ) { |
|
| 565 | - $this->set_prop( 'period', $value ); |
|
| 564 | + public function set_period($value) { |
|
| 565 | + $this->set_prop('period', $value); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -571,9 +571,9 @@ discard block |
||
| 571 | 571 | * @since 1.0.19 |
| 572 | 572 | * @param int $value The subscription frequency. |
| 573 | 573 | */ |
| 574 | - public function set_frequency( $value ) { |
|
| 575 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 576 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 574 | + public function set_frequency($value) { |
|
| 575 | + $value = empty($value) ? 1 : (int) $value; |
|
| 576 | + $this->set_prop('frequency', absint($value)); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -582,8 +582,8 @@ discard block |
||
| 582 | 582 | * @since 1.0.19 |
| 583 | 583 | * @param float $value The initial subcription amount. |
| 584 | 584 | */ |
| 585 | - public function set_initial_amount( $value ) { |
|
| 586 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | + public function set_initial_amount($value) { |
|
| 586 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
@@ -592,8 +592,8 @@ discard block |
||
| 592 | 592 | * @since 1.0.19 |
| 593 | 593 | * @param float $value The recurring subcription amount. |
| 594 | 594 | */ |
| 595 | - public function set_recurring_amount( $value ) { |
|
| 596 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | + public function set_recurring_amount($value) { |
|
| 596 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -602,8 +602,8 @@ discard block |
||
| 602 | 602 | * @since 1.0.19 |
| 603 | 603 | * @param int $value Bill times. |
| 604 | 604 | */ |
| 605 | - public function set_bill_times( $value ) { |
|
| 606 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | + public function set_bill_times($value) { |
|
| 606 | + $this->set_prop('bill_times', (int) $value); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -612,8 +612,8 @@ discard block |
||
| 612 | 612 | * @since 1.0.19 |
| 613 | 613 | * @param string $value Bill times. |
| 614 | 614 | */ |
| 615 | - public function set_transaction_id( $value ) { |
|
| 616 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | + public function set_transaction_id($value) { |
|
| 616 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
@@ -622,15 +622,15 @@ discard block |
||
| 622 | 622 | * @since 1.0.19 |
| 623 | 623 | * @param string $value strtotime compliant date. |
| 624 | 624 | */ |
| 625 | - public function set_created( $value ) { |
|
| 626 | - $date = strtotime( $value ); |
|
| 625 | + public function set_created($value) { |
|
| 626 | + $date = strtotime($value); |
|
| 627 | 627 | |
| 628 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 629 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 629 | + $this->set_prop('created', date('Y-m-d H:i:s', $date)); |
|
| 630 | 630 | return; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - $this->set_prop( 'created', '' ); |
|
| 633 | + $this->set_prop('created', ''); |
|
| 634 | 634 | |
| 635 | 635 | } |
| 636 | 636 | |
@@ -640,8 +640,8 @@ discard block |
||
| 640 | 640 | * @since 1.0.19 |
| 641 | 641 | * @param string $value strtotime compliant date. |
| 642 | 642 | */ |
| 643 | - public function set_date_created( $value ) { |
|
| 644 | - $this->set_created( $value ); |
|
| 643 | + public function set_date_created($value) { |
|
| 644 | + $this->set_created($value); |
|
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | /** |
@@ -650,15 +650,15 @@ discard block |
||
| 650 | 650 | * @since 1.0.19 |
| 651 | 651 | * @param string $value strtotime compliant date. |
| 652 | 652 | */ |
| 653 | - public function set_next_renewal_date( $value ) { |
|
| 654 | - $date = strtotime( $value ); |
|
| 653 | + public function set_next_renewal_date($value) { |
|
| 654 | + $date = strtotime($value); |
|
| 655 | 655 | |
| 656 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 657 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 656 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 657 | + $this->set_prop('expiration', date('Y-m-d H:i:s', $date)); |
|
| 658 | 658 | return; |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | - $this->set_prop( 'expiration', '' ); |
|
| 661 | + $this->set_prop('expiration', ''); |
|
| 662 | 662 | |
| 663 | 663 | } |
| 664 | 664 | |
@@ -668,8 +668,8 @@ discard block |
||
| 668 | 668 | * @since 1.0.19 |
| 669 | 669 | * @param string $value strtotime compliant date. |
| 670 | 670 | */ |
| 671 | - public function set_expiration( $value ) { |
|
| 672 | - $this->set_next_renewal_date( $value ); |
|
| 671 | + public function set_expiration($value) { |
|
| 672 | + $this->set_next_renewal_date($value); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -678,8 +678,8 @@ discard block |
||
| 678 | 678 | * @since 1.0.19 |
| 679 | 679 | * @param string $value trial period e.g 1 year. |
| 680 | 680 | */ |
| 681 | - public function set_trial_period( $value ) { |
|
| 682 | - $this->set_prop( 'trial_period', $value ); |
|
| 681 | + public function set_trial_period($value) { |
|
| 682 | + $this->set_prop('trial_period', $value); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | /** |
@@ -688,19 +688,19 @@ discard block |
||
| 688 | 688 | * @since 1.0.19 |
| 689 | 689 | * @param string $new_status New subscription status. |
| 690 | 690 | */ |
| 691 | - public function set_status( $new_status ) { |
|
| 691 | + public function set_status($new_status) { |
|
| 692 | 692 | |
| 693 | 693 | // Abort if this is not a valid status; |
| 694 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 694 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
| 695 | 695 | return; |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | $old_status = $this->get_status(); |
| 699 | - $this->set_prop( 'status', $new_status ); |
|
| 699 | + $this->set_prop('status', $new_status); |
|
| 700 | 700 | |
| 701 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 701 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
| 702 | 702 | $this->status_transition = array( |
| 703 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 703 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
| 704 | 704 | 'to' => $new_status, |
| 705 | 705 | ); |
| 706 | 706 | } |
@@ -713,8 +713,8 @@ discard block |
||
| 713 | 713 | * @since 1.0.19 |
| 714 | 714 | * @param string $value the remote profile id. |
| 715 | 715 | */ |
| 716 | - public function set_profile_id( $value ) { |
|
| 717 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | + public function set_profile_id($value) { |
|
| 717 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /* |
@@ -732,8 +732,8 @@ discard block |
||
| 732 | 732 | * @param string|array String or array of strings to check for. |
| 733 | 733 | * @return bool |
| 734 | 734 | */ |
| 735 | - public function has_status( $status ) { |
|
| 736 | - return in_array( $this->get_status(), wpinv_parse_list( $status ) ); |
|
| 735 | + public function has_status($status) { |
|
| 736 | + return in_array($this->get_status(), wpinv_parse_list($status)); |
|
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | /** |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | */ |
| 744 | 744 | public function has_trial_period() { |
| 745 | 745 | $period = $this->get_trial_period(); |
| 746 | - return ! empty( $period ); |
|
| 746 | + return !empty($period); |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | * @return bool |
| 753 | 753 | */ |
| 754 | 754 | public function is_active() { |
| 755 | - return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' ); |
|
| 755 | + return $this->has_status('active trialling') && $this->get_expiration_time() > current_time('mysql'); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | /** |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | * @return bool |
| 762 | 762 | */ |
| 763 | 763 | public function is_expired() { |
| 764 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 764 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql')); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /* |
@@ -776,11 +776,11 @@ discard block |
||
| 776 | 776 | /** |
| 777 | 777 | * Backwards compatibilty. |
| 778 | 778 | */ |
| 779 | - public function create( $data = array() ) { |
|
| 779 | + public function create($data = array()) { |
|
| 780 | 780 | |
| 781 | 781 | // Set the properties. |
| 782 | - if ( is_array( $data ) ) { |
|
| 783 | - $this->set_props( $data ); |
|
| 782 | + if (is_array($data)) { |
|
| 783 | + $this->set_props($data); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | // Save the item. |
@@ -791,8 +791,8 @@ discard block |
||
| 791 | 791 | /** |
| 792 | 792 | * Backwards compatibilty. |
| 793 | 793 | */ |
| 794 | - public function update( $args = array() ) { |
|
| 795 | - return $this->create( $args ); |
|
| 794 | + public function update($args = array()) { |
|
| 795 | + return $this->create($args); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | array( |
| 807 | 807 | 'post_parent' => $this->get_parent_payment_id(), |
| 808 | 808 | 'numberposts' => -1, |
| 809 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
| 809 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
| 810 | 810 | 'orderby' => 'ID', |
| 811 | 811 | 'order' => 'DESC', |
| 812 | 812 | 'post_type' => 'wpi_invoice' |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | ); |
| 832 | 832 | |
| 833 | 833 | // Maybe include parent invoice. |
| 834 | - if ( ! $this->has_status( 'pending' ) ) { |
|
| 834 | + if (!$this->has_status('pending')) { |
|
| 835 | 835 | $count++; |
| 836 | 836 | } |
| 837 | 837 | |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | public function get_times_billed() { |
| 848 | 848 | $times_billed = $this->get_total_payments(); |
| 849 | 849 | |
| 850 | - if ( $this->has_trial_period() && $times_billed > 0 ) { |
|
| 850 | + if ($this->has_trial_period() && $times_billed > 0) { |
|
| 851 | 851 | $times_billed--; |
| 852 | 852 | } |
| 853 | 853 | |
@@ -862,49 +862,49 @@ discard block |
||
| 862 | 862 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
| 863 | 863 | * @return bool |
| 864 | 864 | */ |
| 865 | - public function add_payment( $args = array(), $invoice = false ) { |
|
| 865 | + public function add_payment($args = array(), $invoice = false) { |
|
| 866 | 866 | |
| 867 | 867 | // Process each payment once. |
| 868 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
| 868 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
| 869 | 869 | return false; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | // Are we creating a new invoice? |
| 873 | - if ( empty( $invoice ) ) { |
|
| 873 | + if (empty($invoice)) { |
|
| 874 | 874 | $invoice = $this->create_payment(); |
| 875 | 875 | |
| 876 | - if ( empty( $invoice ) ) { |
|
| 876 | + if (empty($invoice)) { |
|
| 877 | 877 | return false; |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 880 | + $invoice->set_status('wpi-renewal'); |
|
| 881 | 881 | |
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | // Maybe set a transaction id. |
| 885 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 886 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 885 | + if (!empty($args['transaction_id'])) { |
|
| 886 | + $invoice->set_transaction_id($args['transaction_id']); |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | // Set the completed date. |
| 890 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 890 | + $invoice->set_completed_date(current_time('mysql')); |
|
| 891 | 891 | |
| 892 | 892 | // And the gateway. |
| 893 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 894 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 893 | + if (!empty($args['gateway'])) { |
|
| 894 | + $invoice->set_gateway($args['gateway']); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | $invoice->save(); |
| 898 | 898 | |
| 899 | - if ( ! $invoice->get_id() ) { |
|
| 899 | + if (!$invoice->get_id()) { |
|
| 900 | 900 | return 0; |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 904 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 905 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
| 903 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
| 904 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
| 905 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
| 906 | 906 | |
| 907 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
| 907 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
| 908 | 908 | |
| 909 | 909 | return $invoice->get_id(); |
| 910 | 910 | } |
@@ -919,21 +919,21 @@ discard block |
||
| 919 | 919 | |
| 920 | 920 | $parent_invoice = $this->get_parent_payment(); |
| 921 | 921 | |
| 922 | - if ( ! $parent_invoice->get_id() ) { |
|
| 922 | + if (!$parent_invoice->get_id()) { |
|
| 923 | 923 | return false; |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | // Duplicate the parent invoice. |
| 927 | 927 | $invoice = new WPInv_Invoice(); |
| 928 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
| 929 | - $invoice->set_id( 0 ); |
|
| 930 | - $invoice->set_items( $parent_invoice->get_items() ); |
|
| 931 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 932 | - $invoice->set_transaction_id( '' ); |
|
| 933 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
| 934 | - $invoice->set_number( '' ); |
|
| 935 | - $invoice->set_completed_date( '' ); |
|
| 936 | - $invoice->set_status( 'wpi-pending' ); |
|
| 928 | + $invoice->set_props($parent_invoice->get_data()); |
|
| 929 | + $invoice->set_id(0); |
|
| 930 | + $invoice->set_items($parent_invoice->get_items()); |
|
| 931 | + $invoice->set_parent_id($parent_invoice->get_id()); |
|
| 932 | + $invoice->set_transaction_id(''); |
|
| 933 | + $invoice->set_key($invoice->generate_key('renewal_')); |
|
| 934 | + $invoice->set_number(''); |
|
| 935 | + $invoice->set_completed_date(''); |
|
| 936 | + $invoice->set_status('wpi-pending'); |
|
| 937 | 937 | $invoice->recalculate_total(); |
| 938 | 938 | $invoice->save(); |
| 939 | 939 | |
@@ -949,20 +949,20 @@ discard block |
||
| 949 | 949 | public function renew() { |
| 950 | 950 | |
| 951 | 951 | // Complete subscription if applicable |
| 952 | - if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
| 952 | + if ($this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times()) { |
|
| 953 | 953 | return $this->complete(); |
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | // Calculate new expiration |
| 957 | 957 | $frequency = $this->get_frequency(); |
| 958 | 958 | $period = $this->get_period(); |
| 959 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 959 | + $new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time()); |
|
| 960 | 960 | |
| 961 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 962 | - $this->set_status( 'active' ); |
|
| 961 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
| 962 | + $this->set_status('active'); |
|
| 963 | 963 | return $this->save(); |
| 964 | 964 | |
| 965 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 965 | + do_action('getpaid_subscription_renewed', $this); |
|
| 966 | 966 | |
| 967 | 967 | } |
| 968 | 968 | |
@@ -977,11 +977,11 @@ discard block |
||
| 977 | 977 | public function complete() { |
| 978 | 978 | |
| 979 | 979 | // Only mark a subscription as complete if it's not already cancelled. |
| 980 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 980 | + if ($this->has_status('cancelled')) { |
|
| 981 | 981 | return false; |
| 982 | 982 | } |
| 983 | 983 | |
| 984 | - $this->set_status( 'completed' ); |
|
| 984 | + $this->set_status('completed'); |
|
| 985 | 985 | return $this->save(); |
| 986 | 986 | |
| 987 | 987 | } |
@@ -993,14 +993,14 @@ discard block |
||
| 993 | 993 | * @param bool $check_expiration |
| 994 | 994 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
| 995 | 995 | */ |
| 996 | - public function expire( $check_expiration = false ) { |
|
| 996 | + public function expire($check_expiration = false) { |
|
| 997 | 997 | |
| 998 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 998 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
| 999 | 999 | // Do not mark as expired since real expiration date is in the future |
| 1000 | 1000 | return false; |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - $this->set_status( 'expired' ); |
|
| 1003 | + $this->set_status('expired'); |
|
| 1004 | 1004 | return $this->save(); |
| 1005 | 1005 | |
| 1006 | 1006 | } |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | * @return int Subscription id. |
| 1013 | 1013 | */ |
| 1014 | 1014 | public function failing() { |
| 1015 | - $this->set_status( 'failing' ); |
|
| 1015 | + $this->set_status('failing'); |
|
| 1016 | 1016 | return $this->save(); |
| 1017 | 1017 | } |
| 1018 | 1018 | |
@@ -1023,7 +1023,7 @@ discard block |
||
| 1023 | 1023 | * @return int Subscription id. |
| 1024 | 1024 | */ |
| 1025 | 1025 | public function cancel() { |
| 1026 | - $this->set_status( 'cancelled' ); |
|
| 1026 | + $this->set_status('cancelled'); |
|
| 1027 | 1027 | return $this->save(); |
| 1028 | 1028 | } |
| 1029 | 1029 | |
@@ -1034,7 +1034,7 @@ discard block |
||
| 1034 | 1034 | * @return bool |
| 1035 | 1035 | */ |
| 1036 | 1036 | public function can_cancel() { |
| 1037 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1037 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | /** |
@@ -1045,7 +1045,7 @@ discard block |
||
| 1045 | 1045 | * @return array |
| 1046 | 1046 | */ |
| 1047 | 1047 | public function get_cancellable_statuses() { |
| 1048 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
| 1048 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | /** |
@@ -1055,8 +1055,8 @@ discard block |
||
| 1055 | 1055 | * @return string |
| 1056 | 1056 | */ |
| 1057 | 1057 | public function get_cancel_url() { |
| 1058 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' ); |
|
| 1059 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1058 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id())), 'wpinv-recurring-cancel'); |
|
| 1059 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | /** |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | * @return bool |
| 1070 | 1070 | */ |
| 1071 | 1071 | public function can_renew() { |
| 1072 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1072 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | /** |
@@ -1079,8 +1079,8 @@ discard block |
||
| 1079 | 1079 | * @return string |
| 1080 | 1080 | */ |
| 1081 | 1081 | public function get_renew_url() { |
| 1082 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' ); |
|
| 1083 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1082 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'wpinv-recurring-renew'); |
|
| 1083 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | /** |
@@ -1090,7 +1090,7 @@ discard block |
||
| 1090 | 1090 | * @return bool |
| 1091 | 1091 | */ |
| 1092 | 1092 | public function can_update() { |
| 1093 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1093 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | 1096 | /** |
@@ -1100,8 +1100,8 @@ discard block |
||
| 1100 | 1100 | * @return string |
| 1101 | 1101 | */ |
| 1102 | 1102 | public function get_update_url() { |
| 1103 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1104 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1103 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id())); |
|
| 1104 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | /** |
@@ -1111,7 +1111,7 @@ discard block |
||
| 1111 | 1111 | * @return string |
| 1112 | 1112 | */ |
| 1113 | 1113 | public function get_status_label() { |
| 1114 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1114 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | /** |
@@ -1122,7 +1122,7 @@ discard block |
||
| 1122 | 1122 | */ |
| 1123 | 1123 | public function get_status_class() { |
| 1124 | 1124 | $statuses = getpaid_get_subscription_status_classes(); |
| 1125 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
| 1125 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'text-white bg-secondary'; |
|
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | /** |
@@ -1133,9 +1133,9 @@ discard block |
||
| 1133 | 1133 | */ |
| 1134 | 1134 | public function get_status_label_html() { |
| 1135 | 1135 | |
| 1136 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1137 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1138 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
| 1136 | + $status_label = sanitize_text_field($this->get_status_label()); |
|
| 1137 | + $class = esc_attr($this->get_status_class()); |
|
| 1138 | + $status = sanitize_html_class($this->get_status_label()); |
|
| 1139 | 1139 | |
| 1140 | 1140 | return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
| 1141 | 1141 | } |
@@ -1147,9 +1147,9 @@ discard block |
||
| 1147 | 1147 | * @param string $txn_id The transaction ID from the merchant processor |
| 1148 | 1148 | * @return bool |
| 1149 | 1149 | */ |
| 1150 | - public function payment_exists( $txn_id = '' ) { |
|
| 1151 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1152 | - return ! empty( $invoice_id ); |
|
| 1150 | + public function payment_exists($txn_id = '') { |
|
| 1151 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
| 1152 | + return !empty($invoice_id); |
|
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | /** |
@@ -1161,35 +1161,35 @@ discard block |
||
| 1161 | 1161 | // Reset status transition variable. |
| 1162 | 1162 | $this->status_transition = false; |
| 1163 | 1163 | |
| 1164 | - if ( $status_transition ) { |
|
| 1164 | + if ($status_transition) { |
|
| 1165 | 1165 | try { |
| 1166 | 1166 | |
| 1167 | 1167 | // Fire a hook for the status change. |
| 1168 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1169 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1168 | + do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
| 1169 | + do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition); |
|
| 1170 | 1170 | |
| 1171 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1171 | + if (!empty($status_transition['from'])) { |
|
| 1172 | 1172 | |
| 1173 | 1173 | /* translators: 1: old subscription status 2: new subscription status */ |
| 1174 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1174 | + $transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1175 | 1175 | |
| 1176 | 1176 | // Fire another hook. |
| 1177 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1178 | - do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
| 1177 | + do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
| 1178 | + do_action('getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this); |
|
| 1179 | 1179 | |
| 1180 | 1180 | // Note the transition occurred. |
| 1181 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1181 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1182 | 1182 | |
| 1183 | 1183 | } else { |
| 1184 | 1184 | /* translators: %s: new invoice status */ |
| 1185 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1185 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1186 | 1186 | |
| 1187 | 1187 | // Note the transition occurred. |
| 1188 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1188 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1189 | 1189 | |
| 1190 | 1190 | } |
| 1191 | - } catch ( Exception $e ) { |
|
| 1192 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1191 | + } catch (Exception $e) { |
|
| 1192 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
| 1193 | 1193 | } |
| 1194 | 1194 | } |
| 1195 | 1195 | |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 7 | 7 | |
| 8 | 8 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 9 | - include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 9 | + include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
@@ -14,423 +14,423 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Subscriptions_List_Table extends WP_List_Table { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * URL of this page |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - * @since 1.0.19 |
|
| 22 | - */ |
|
| 23 | - public $base_url; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Query |
|
| 27 | - * |
|
| 28 | - * @var GetPaid_Subscriptions_Query |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - */ |
|
| 31 | - public $query; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Total subscriptions |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - * @since 1.0.0 |
|
| 38 | - */ |
|
| 39 | - public $total_count; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Current status subscriptions |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - * @since 1.0.0 |
|
| 46 | - */ |
|
| 47 | - public $current_total_count; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Status counts |
|
| 51 | - * |
|
| 52 | - * @var array |
|
| 53 | - * @since 1.0.19 |
|
| 54 | - */ |
|
| 55 | - public $status_counts; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Number of results to show per page |
|
| 59 | - * |
|
| 60 | - * @var int |
|
| 61 | - * @since 1.0.0 |
|
| 62 | - */ |
|
| 63 | - public $per_page = 10; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Constructor function. |
|
| 67 | - */ |
|
| 68 | - public function __construct() { |
|
| 69 | - |
|
| 70 | - parent::__construct( |
|
| 71 | - array( |
|
| 72 | - 'singular' => 'subscription', |
|
| 73 | - 'plural' => 'subscriptions', |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - |
|
| 77 | - $this->process_bulk_action(); |
|
| 78 | - |
|
| 79 | - $this->prepare_query(); |
|
| 80 | - |
|
| 81 | - $this->base_url = remove_query_arg( 'status' ); |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Prepares the display query |
|
| 87 | - */ |
|
| 88 | - public function prepare_query() { |
|
| 89 | - |
|
| 90 | - // Prepare query args. |
|
| 91 | - $query = array( |
|
| 92 | - 'number' => $this->per_page, |
|
| 93 | - 'paged' => $this->get_paged(), |
|
| 94 | - 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all', |
|
| 95 | - 'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id', |
|
| 96 | - 'order' => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC', |
|
| 97 | - ); |
|
| 98 | - |
|
| 99 | - // Prepare class properties. |
|
| 100 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
| 101 | - $this->total_count = $this->query->get_total(); |
|
| 102 | - $this->current_total_count = $this->query->get_total(); |
|
| 103 | - $this->items = $this->query->get_results(); |
|
| 104 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
| 105 | - |
|
| 106 | - if ( 'all' != $query['status'] ) { |
|
| 107 | - unset( $query['status'] ); |
|
| 108 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Gets the list of views available on this table. |
|
| 115 | - * |
|
| 116 | - * The format is an associative array: |
|
| 117 | - * - `'id' => 'link'` |
|
| 118 | - * |
|
| 119 | - * @since 1.0.0 |
|
| 120 | - * |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - protected function get_views() { |
|
| 124 | - |
|
| 125 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
| 126 | - $views = array( |
|
| 127 | - |
|
| 128 | - 'all' => sprintf( |
|
| 129 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 130 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
| 131 | - $current === 'all' ? ' class="current"' : '', |
|
| 132 | - __('All','invoicing' ), |
|
| 133 | - $this->total_count |
|
| 134 | - ) |
|
| 135 | - |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
| 139 | - |
|
| 140 | - $views[ $status ] = sprintf( |
|
| 141 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 142 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
| 143 | - $current === $status ? ' class="current"' : '', |
|
| 144 | - sanitize_text_field( getpaid_get_subscription_status_label( $status ) ), |
|
| 145 | - $count |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $views; |
|
| 151 | - |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Render most columns |
|
| 156 | - * |
|
| 157 | - * @access private |
|
| 158 | - * @since 1.0.0 |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function column_default( $item, $column_name ) { |
|
| 162 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * This is how checkbox column renders. |
|
| 167 | - * |
|
| 168 | - * @param WPInv_Subscription $item |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 171 | - public function column_cb( $item ) { |
|
| 172 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Status column |
|
| 177 | - * |
|
| 178 | - * @param WPInv_Subscription $item |
|
| 179 | - * @since 1.0.0 |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function column_status( $item ) { |
|
| 183 | - return $item->get_status_label_html(); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Subscription column |
|
| 188 | - * |
|
| 189 | - * @param WPInv_Subscription $item |
|
| 190 | - * @since 1.0.0 |
|
| 191 | - * @return string |
|
| 192 | - */ |
|
| 193 | - public function column_subscription( $item ) { |
|
| 194 | - |
|
| 195 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 196 | - |
|
| 197 | - $user = get_userdata( $item->get_customer_id() ); |
|
| 198 | - if ( $user ) { |
|
| 199 | - |
|
| 200 | - $username = sprintf( |
|
| 201 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 202 | - absint( $user->ID ), |
|
| 203 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 204 | - ); |
|
| 205 | - |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
| 209 | - $column_content = sprintf( |
|
| 210 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
| 211 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
| 212 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
| 213 | - $username |
|
| 214 | - ); |
|
| 215 | - |
|
| 216 | - $row_actions = array(); |
|
| 217 | - |
|
| 218 | - // View subscription. |
|
| 219 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
| 220 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
| 221 | - |
|
| 222 | - // View invoice. |
|
| 223 | - $invoice = get_post( $item->get_product_id() ); |
|
| 224 | - |
|
| 225 | - if ( ! empty( $invoice ) ) { |
|
| 226 | - $view_url = get_edit_post_link( $invoice ); |
|
| 227 | - $row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
| 231 | - |
|
| 232 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Renewal date column |
|
| 237 | - * |
|
| 238 | - * @param WPInv_Subscription $item |
|
| 239 | - * @since 1.0.0 |
|
| 240 | - * @return string |
|
| 241 | - */ |
|
| 242 | - public function column_renewal_date( $item ) { |
|
| 243 | - |
|
| 244 | - $expiration = $item->get_expiration(); |
|
| 245 | - if ( ! $item->is_active() || empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 246 | - return "—"; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
| 250 | - |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Start date column |
|
| 255 | - * |
|
| 256 | - * @param WPInv_Subscription $item |
|
| 257 | - * @since 1.0.0 |
|
| 258 | - * @return string |
|
| 259 | - */ |
|
| 260 | - public function column_start_date( $item ) { |
|
| 261 | - |
|
| 262 | - $created = $item->get_date_created(); |
|
| 263 | - if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
| 264 | - return "—"; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
| 268 | - |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Amount column |
|
| 273 | - * |
|
| 274 | - * @param WPInv_Subscription $item |
|
| 275 | - * @since 1.0.19 |
|
| 276 | - * @return string |
|
| 277 | - */ |
|
| 278 | - public function column_amount( $item ) { |
|
| 279 | - |
|
| 280 | - $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_initial_amount() ) ), $item->get_parent_payment()->get_currency() ); |
|
| 281 | - $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_recurring_amount() ) ), $item->get_parent_payment()->get_currency() ); |
|
| 282 | - $period = 1 == $item->get_frequency() ? getpaid_get_subscription_period_label( $item->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_period(),$item->get_frequency() ); |
|
| 283 | - |
|
| 284 | - if ( $item->has_trial_period() ) { |
|
| 285 | - |
|
| 286 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 287 | - $amount = sprintf( |
|
| 288 | - _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 289 | - $initial, |
|
| 290 | - sanitize_text_field( $item->get_trial_period() ), |
|
| 291 | - $recurring, |
|
| 292 | - sanitize_text_field( strtolower( $period ) ) |
|
| 293 | - ); |
|
| 294 | - |
|
| 295 | - } else if ( $initial != $recurring ) { |
|
| 296 | - |
|
| 297 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
|
| 298 | - $amount = sprintf( |
|
| 299 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
| 300 | - $initial, |
|
| 301 | - $recurring, |
|
| 302 | - sanitize_text_field( strtolower( $period ) ) |
|
| 303 | - ); |
|
| 304 | - |
|
| 305 | - } else { |
|
| 306 | - |
|
| 307 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 308 | - $amount = sprintf( |
|
| 309 | - _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
| 310 | - $initial, |
|
| 311 | - sanitize_text_field( strtolower( $period ) ) |
|
| 312 | - ); |
|
| 313 | - |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Billing Times column |
|
| 321 | - * |
|
| 322 | - * @param WPInv_Subscription $item |
|
| 323 | - * @since 1.0.0 |
|
| 324 | - * @return string |
|
| 325 | - */ |
|
| 326 | - public function column_renewals( $item ) { |
|
| 327 | - $max_bills = $item->get_bill_times(); |
|
| 328 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Product ID column |
|
| 333 | - * |
|
| 334 | - * @param WPInv_Subscription $item |
|
| 335 | - * @since 1.0.0 |
|
| 336 | - * @return string |
|
| 337 | - */ |
|
| 338 | - public function column_item( $item ) { |
|
| 339 | - $_item = get_post( $item->get_product_id() ); |
|
| 340 | - |
|
| 341 | - if ( ! empty( $_item ) ) { |
|
| 342 | - $link = get_edit_post_link( $_item ); |
|
| 343 | - $link = esc_url( $link ); |
|
| 344 | - $name = esc_html( get_the_title( $_item ) ); |
|
| 345 | - return "<a href='$link'>$name</a>"; |
|
| 346 | - } else { |
|
| 347 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() ); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Retrieve the current page number |
|
| 354 | - * |
|
| 355 | - * @return int |
|
| 356 | - */ |
|
| 357 | - public function get_paged() { |
|
| 358 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Setup the final data for the table |
|
| 363 | - * |
|
| 364 | - */ |
|
| 365 | - public function prepare_items() { |
|
| 366 | - |
|
| 367 | - $columns = $this->get_columns(); |
|
| 368 | - $hidden = array(); |
|
| 369 | - $sortable = $this->get_sortable_columns(); |
|
| 370 | - |
|
| 371 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 372 | - |
|
| 373 | - $this->set_pagination_args( |
|
| 374 | - array( |
|
| 375 | - 'total_items' => $this->current_total_count, |
|
| 376 | - 'per_page' => $this->per_page, |
|
| 377 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
| 378 | - ) |
|
| 379 | - ); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Table columns |
|
| 384 | - * |
|
| 385 | - * @return array |
|
| 386 | - */ |
|
| 387 | - public function get_columns(){ |
|
| 388 | - $columns = array( |
|
| 389 | - 'cb' => '<input type="checkbox" />', |
|
| 390 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 391 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 392 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 393 | - 'renewals' => __( 'Renewals', 'invoicing' ), |
|
| 394 | - 'item' => __( 'Item', 'invoicing' ), |
|
| 395 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 396 | - ); |
|
| 397 | - |
|
| 398 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Sortable table columns. |
|
| 403 | - * |
|
| 404 | - * @return array |
|
| 405 | - */ |
|
| 406 | - public function get_sortable_columns() { |
|
| 407 | - $sortable = array( |
|
| 408 | - 'subscription' => array( 'id', true ), |
|
| 409 | - 'start_date' => array( 'created', true ), |
|
| 410 | - 'renewal_date' => array( 'expiration', true ), |
|
| 411 | - 'renewals' => array( 'bill_times', true ), |
|
| 412 | - 'item' => array( 'product_id', true ), |
|
| 413 | - 'status' => array( 'status', true ), |
|
| 414 | - ); |
|
| 415 | - |
|
| 416 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Whether the table has items to display or not |
|
| 421 | - * |
|
| 422 | - * @return bool |
|
| 423 | - */ |
|
| 424 | - public function has_items() { |
|
| 425 | - return ! empty( $this->current_total_count ); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * Processes bulk actions. |
|
| 430 | - * |
|
| 431 | - */ |
|
| 432 | - public function process_bulk_action() { |
|
| 433 | - |
|
| 434 | - } |
|
| 17 | + /** |
|
| 18 | + * URL of this page |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + * @since 1.0.19 |
|
| 22 | + */ |
|
| 23 | + public $base_url; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Query |
|
| 27 | + * |
|
| 28 | + * @var GetPaid_Subscriptions_Query |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + */ |
|
| 31 | + public $query; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Total subscriptions |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + * @since 1.0.0 |
|
| 38 | + */ |
|
| 39 | + public $total_count; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Current status subscriptions |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + * @since 1.0.0 |
|
| 46 | + */ |
|
| 47 | + public $current_total_count; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Status counts |
|
| 51 | + * |
|
| 52 | + * @var array |
|
| 53 | + * @since 1.0.19 |
|
| 54 | + */ |
|
| 55 | + public $status_counts; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Number of results to show per page |
|
| 59 | + * |
|
| 60 | + * @var int |
|
| 61 | + * @since 1.0.0 |
|
| 62 | + */ |
|
| 63 | + public $per_page = 10; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Constructor function. |
|
| 67 | + */ |
|
| 68 | + public function __construct() { |
|
| 69 | + |
|
| 70 | + parent::__construct( |
|
| 71 | + array( |
|
| 72 | + 'singular' => 'subscription', |
|
| 73 | + 'plural' => 'subscriptions', |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + |
|
| 77 | + $this->process_bulk_action(); |
|
| 78 | + |
|
| 79 | + $this->prepare_query(); |
|
| 80 | + |
|
| 81 | + $this->base_url = remove_query_arg( 'status' ); |
|
| 82 | + |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Prepares the display query |
|
| 87 | + */ |
|
| 88 | + public function prepare_query() { |
|
| 89 | + |
|
| 90 | + // Prepare query args. |
|
| 91 | + $query = array( |
|
| 92 | + 'number' => $this->per_page, |
|
| 93 | + 'paged' => $this->get_paged(), |
|
| 94 | + 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all', |
|
| 95 | + 'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id', |
|
| 96 | + 'order' => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC', |
|
| 97 | + ); |
|
| 98 | + |
|
| 99 | + // Prepare class properties. |
|
| 100 | + $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
| 101 | + $this->total_count = $this->query->get_total(); |
|
| 102 | + $this->current_total_count = $this->query->get_total(); |
|
| 103 | + $this->items = $this->query->get_results(); |
|
| 104 | + $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
| 105 | + |
|
| 106 | + if ( 'all' != $query['status'] ) { |
|
| 107 | + unset( $query['status'] ); |
|
| 108 | + $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Gets the list of views available on this table. |
|
| 115 | + * |
|
| 116 | + * The format is an associative array: |
|
| 117 | + * - `'id' => 'link'` |
|
| 118 | + * |
|
| 119 | + * @since 1.0.0 |
|
| 120 | + * |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + protected function get_views() { |
|
| 124 | + |
|
| 125 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
| 126 | + $views = array( |
|
| 127 | + |
|
| 128 | + 'all' => sprintf( |
|
| 129 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 130 | + esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
| 131 | + $current === 'all' ? ' class="current"' : '', |
|
| 132 | + __('All','invoicing' ), |
|
| 133 | + $this->total_count |
|
| 134 | + ) |
|
| 135 | + |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
| 139 | + |
|
| 140 | + $views[ $status ] = sprintf( |
|
| 141 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 142 | + esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
| 143 | + $current === $status ? ' class="current"' : '', |
|
| 144 | + sanitize_text_field( getpaid_get_subscription_status_label( $status ) ), |
|
| 145 | + $count |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $views; |
|
| 151 | + |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Render most columns |
|
| 156 | + * |
|
| 157 | + * @access private |
|
| 158 | + * @since 1.0.0 |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function column_default( $item, $column_name ) { |
|
| 162 | + return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * This is how checkbox column renders. |
|
| 167 | + * |
|
| 168 | + * @param WPInv_Subscription $item |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | + public function column_cb( $item ) { |
|
| 172 | + return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Status column |
|
| 177 | + * |
|
| 178 | + * @param WPInv_Subscription $item |
|
| 179 | + * @since 1.0.0 |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function column_status( $item ) { |
|
| 183 | + return $item->get_status_label_html(); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Subscription column |
|
| 188 | + * |
|
| 189 | + * @param WPInv_Subscription $item |
|
| 190 | + * @since 1.0.0 |
|
| 191 | + * @return string |
|
| 192 | + */ |
|
| 193 | + public function column_subscription( $item ) { |
|
| 194 | + |
|
| 195 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 196 | + |
|
| 197 | + $user = get_userdata( $item->get_customer_id() ); |
|
| 198 | + if ( $user ) { |
|
| 199 | + |
|
| 200 | + $username = sprintf( |
|
| 201 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 202 | + absint( $user->ID ), |
|
| 203 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 204 | + ); |
|
| 205 | + |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
| 209 | + $column_content = sprintf( |
|
| 210 | + _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
| 211 | + '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
| 212 | + '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
| 213 | + $username |
|
| 214 | + ); |
|
| 215 | + |
|
| 216 | + $row_actions = array(); |
|
| 217 | + |
|
| 218 | + // View subscription. |
|
| 219 | + $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
| 220 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
| 221 | + |
|
| 222 | + // View invoice. |
|
| 223 | + $invoice = get_post( $item->get_product_id() ); |
|
| 224 | + |
|
| 225 | + if ( ! empty( $invoice ) ) { |
|
| 226 | + $view_url = get_edit_post_link( $invoice ); |
|
| 227 | + $row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
| 231 | + |
|
| 232 | + return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Renewal date column |
|
| 237 | + * |
|
| 238 | + * @param WPInv_Subscription $item |
|
| 239 | + * @since 1.0.0 |
|
| 240 | + * @return string |
|
| 241 | + */ |
|
| 242 | + public function column_renewal_date( $item ) { |
|
| 243 | + |
|
| 244 | + $expiration = $item->get_expiration(); |
|
| 245 | + if ( ! $item->is_active() || empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 246 | + return "—"; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
| 250 | + |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Start date column |
|
| 255 | + * |
|
| 256 | + * @param WPInv_Subscription $item |
|
| 257 | + * @since 1.0.0 |
|
| 258 | + * @return string |
|
| 259 | + */ |
|
| 260 | + public function column_start_date( $item ) { |
|
| 261 | + |
|
| 262 | + $created = $item->get_date_created(); |
|
| 263 | + if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
| 264 | + return "—"; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
| 268 | + |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Amount column |
|
| 273 | + * |
|
| 274 | + * @param WPInv_Subscription $item |
|
| 275 | + * @since 1.0.19 |
|
| 276 | + * @return string |
|
| 277 | + */ |
|
| 278 | + public function column_amount( $item ) { |
|
| 279 | + |
|
| 280 | + $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_initial_amount() ) ), $item->get_parent_payment()->get_currency() ); |
|
| 281 | + $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_recurring_amount() ) ), $item->get_parent_payment()->get_currency() ); |
|
| 282 | + $period = 1 == $item->get_frequency() ? getpaid_get_subscription_period_label( $item->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_period(),$item->get_frequency() ); |
|
| 283 | + |
|
| 284 | + if ( $item->has_trial_period() ) { |
|
| 285 | + |
|
| 286 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 287 | + $amount = sprintf( |
|
| 288 | + _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 289 | + $initial, |
|
| 290 | + sanitize_text_field( $item->get_trial_period() ), |
|
| 291 | + $recurring, |
|
| 292 | + sanitize_text_field( strtolower( $period ) ) |
|
| 293 | + ); |
|
| 294 | + |
|
| 295 | + } else if ( $initial != $recurring ) { |
|
| 296 | + |
|
| 297 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
|
| 298 | + $amount = sprintf( |
|
| 299 | + _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
| 300 | + $initial, |
|
| 301 | + $recurring, |
|
| 302 | + sanitize_text_field( strtolower( $period ) ) |
|
| 303 | + ); |
|
| 304 | + |
|
| 305 | + } else { |
|
| 306 | + |
|
| 307 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 308 | + $amount = sprintf( |
|
| 309 | + _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
| 310 | + $initial, |
|
| 311 | + sanitize_text_field( strtolower( $period ) ) |
|
| 312 | + ); |
|
| 313 | + |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Billing Times column |
|
| 321 | + * |
|
| 322 | + * @param WPInv_Subscription $item |
|
| 323 | + * @since 1.0.0 |
|
| 324 | + * @return string |
|
| 325 | + */ |
|
| 326 | + public function column_renewals( $item ) { |
|
| 327 | + $max_bills = $item->get_bill_times(); |
|
| 328 | + return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Product ID column |
|
| 333 | + * |
|
| 334 | + * @param WPInv_Subscription $item |
|
| 335 | + * @since 1.0.0 |
|
| 336 | + * @return string |
|
| 337 | + */ |
|
| 338 | + public function column_item( $item ) { |
|
| 339 | + $_item = get_post( $item->get_product_id() ); |
|
| 340 | + |
|
| 341 | + if ( ! empty( $_item ) ) { |
|
| 342 | + $link = get_edit_post_link( $_item ); |
|
| 343 | + $link = esc_url( $link ); |
|
| 344 | + $name = esc_html( get_the_title( $_item ) ); |
|
| 345 | + return "<a href='$link'>$name</a>"; |
|
| 346 | + } else { |
|
| 347 | + return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() ); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Retrieve the current page number |
|
| 354 | + * |
|
| 355 | + * @return int |
|
| 356 | + */ |
|
| 357 | + public function get_paged() { |
|
| 358 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Setup the final data for the table |
|
| 363 | + * |
|
| 364 | + */ |
|
| 365 | + public function prepare_items() { |
|
| 366 | + |
|
| 367 | + $columns = $this->get_columns(); |
|
| 368 | + $hidden = array(); |
|
| 369 | + $sortable = $this->get_sortable_columns(); |
|
| 370 | + |
|
| 371 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 372 | + |
|
| 373 | + $this->set_pagination_args( |
|
| 374 | + array( |
|
| 375 | + 'total_items' => $this->current_total_count, |
|
| 376 | + 'per_page' => $this->per_page, |
|
| 377 | + 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
| 378 | + ) |
|
| 379 | + ); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Table columns |
|
| 384 | + * |
|
| 385 | + * @return array |
|
| 386 | + */ |
|
| 387 | + public function get_columns(){ |
|
| 388 | + $columns = array( |
|
| 389 | + 'cb' => '<input type="checkbox" />', |
|
| 390 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 391 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 392 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 393 | + 'renewals' => __( 'Renewals', 'invoicing' ), |
|
| 394 | + 'item' => __( 'Item', 'invoicing' ), |
|
| 395 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 396 | + ); |
|
| 397 | + |
|
| 398 | + return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Sortable table columns. |
|
| 403 | + * |
|
| 404 | + * @return array |
|
| 405 | + */ |
|
| 406 | + public function get_sortable_columns() { |
|
| 407 | + $sortable = array( |
|
| 408 | + 'subscription' => array( 'id', true ), |
|
| 409 | + 'start_date' => array( 'created', true ), |
|
| 410 | + 'renewal_date' => array( 'expiration', true ), |
|
| 411 | + 'renewals' => array( 'bill_times', true ), |
|
| 412 | + 'item' => array( 'product_id', true ), |
|
| 413 | + 'status' => array( 'status', true ), |
|
| 414 | + ); |
|
| 415 | + |
|
| 416 | + return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Whether the table has items to display or not |
|
| 421 | + * |
|
| 422 | + * @return bool |
|
| 423 | + */ |
|
| 424 | + public function has_items() { |
|
| 425 | + return ! empty( $this->current_total_count ); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * Processes bulk actions. |
|
| 430 | + * |
|
| 431 | + */ |
|
| 432 | + public function process_bulk_action() { |
|
| 433 | + |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | 436 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wpinv_subscriptions_page() { |
| 16 | 16 | |
| 17 | - ?> |
|
| 17 | + ?> |
|
| 18 | 18 | |
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,27 +22,27 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | 24 | |
| 25 | - // Verify user permissions. |
|
| 26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 25 | + // Verify user permissions. |
|
| 26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 27 | 27 | |
| 28 | - echo aui()->alert( |
|
| 29 | - array( |
|
| 30 | - 'type' => 'danger', |
|
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 28 | + echo aui()->alert( |
|
| 29 | + array( |
|
| 30 | + 'type' => 'danger', |
|
| 31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | 34 | |
| 35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 36 | 36 | |
| 37 | - // Display a single subscription. |
|
| 38 | - wpinv_recurring_subscription_details(); |
|
| 39 | - } else { |
|
| 37 | + // Display a single subscription. |
|
| 38 | + wpinv_recurring_subscription_details(); |
|
| 39 | + } else { |
|
| 40 | 40 | |
| 41 | - // Display a list of available subscriptions. |
|
| 42 | - getpaid_print_subscriptions_list(); |
|
| 43 | - } |
|
| 41 | + // Display a list of available subscriptions. |
|
| 42 | + getpaid_print_subscriptions_list(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - ?> |
|
| 45 | + ?> |
|
| 46 | 46 | |
| 47 | 47 | </div> |
| 48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function getpaid_print_subscriptions_list() { |
| 61 | 61 | |
| 62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | - $subscribers_table->prepare_items(); |
|
| 62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | + $subscribers_table->prepare_items(); |
|
| 64 | 64 | |
| 65 | - ?> |
|
| 65 | + ?> |
|
| 66 | 66 | <form id="subscribers-filter" class="bsui" method="get"> |
| 67 | 67 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
| 68 | 68 | <?php $subscribers_table->views(); ?> |
@@ -80,27 +80,27 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function wpinv_recurring_subscription_details() { |
| 82 | 82 | |
| 83 | - // Fetch the subscription. |
|
| 84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | - if ( ! $sub->get_id() ) { |
|
| 83 | + // Fetch the subscription. |
|
| 84 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | + if ( ! $sub->get_id() ) { |
|
| 86 | 86 | |
| 87 | - echo aui()->alert( |
|
| 88 | - array( |
|
| 89 | - 'type' => 'danger', |
|
| 90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | - ) |
|
| 92 | - ); |
|
| 87 | + echo aui()->alert( |
|
| 88 | + array( |
|
| 89 | + 'type' => 'danger', |
|
| 90 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | + ) |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - return; |
|
| 95 | - } |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // Use metaboxes to display the subscription details. |
|
| 98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 97 | + // Use metaboxes to display the subscription details. |
|
| 98 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 102 | 102 | |
| 103 | - ?> |
|
| 103 | + ?> |
|
| 104 | 104 | |
| 105 | 105 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
| 106 | 106 | |
@@ -140,28 +140,28 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | function getpaid_admin_subscription_details_metabox( $sub ) { |
| 142 | 142 | |
| 143 | - // Prepare subscription detail columns. |
|
| 144 | - $fields = apply_filters( |
|
| 145 | - 'getpaid_subscription_admin_page_fields', |
|
| 146 | - array( |
|
| 147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | - 'renewals' => __( 'Renewals', 'invoicing' ), |
|
| 153 | - 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - |
|
| 160 | - if ( ! $sub->is_active() && isset( $fields['renews_on'] ) ) { |
|
| 161 | - unset( $fields['renews_on'] ); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - ?> |
|
| 143 | + // Prepare subscription detail columns. |
|
| 144 | + $fields = apply_filters( |
|
| 145 | + 'getpaid_subscription_admin_page_fields', |
|
| 146 | + array( |
|
| 147 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | + 'renewals' => __( 'Renewals', 'invoicing' ), |
|
| 153 | + 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + |
|
| 160 | + if ( ! $sub->is_active() && isset( $fields['renews_on'] ) ) { |
|
| 161 | + unset( $fields['renews_on'] ); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + ?> |
|
| 165 | 165 | |
| 166 | 166 | <table class="table table-borderless" style="font-size: 14px;"> |
| 167 | 167 | <tbody> |
@@ -195,20 +195,20 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
| 197 | 197 | |
| 198 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 198 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 199 | 199 | |
| 200 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 201 | - if ( $user ) { |
|
| 200 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
| 201 | + if ( $user ) { |
|
| 202 | 202 | |
| 203 | - $username = sprintf( |
|
| 204 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 205 | - absint( $user->ID ), |
|
| 206 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 207 | - ); |
|
| 203 | + $username = sprintf( |
|
| 204 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 205 | + absint( $user->ID ), |
|
| 206 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 207 | + ); |
|
| 208 | 208 | |
| 209 | - } |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - echo $username; |
|
| 211 | + echo $username; |
|
| 212 | 212 | } |
| 213 | 213 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
| 214 | 214 | |
@@ -219,43 +219,43 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
| 221 | 221 | |
| 222 | - $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
| 223 | - $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
| 224 | - $period = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() ); |
|
| 222 | + $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
| 223 | + $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
| 224 | + $period = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() ); |
|
| 225 | 225 | |
| 226 | - if ( $subscription->has_trial_period() ) { |
|
| 226 | + if ( $subscription->has_trial_period() ) { |
|
| 227 | 227 | |
| 228 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 229 | - $amount = sprintf( |
|
| 230 | - _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 231 | - $initial, |
|
| 232 | - sanitize_text_field( $subscription->get_trial_period() ), |
|
| 233 | - $recurring, |
|
| 234 | - sanitize_text_field( strtolower( $period ) ) |
|
| 235 | - ); |
|
| 228 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 229 | + $amount = sprintf( |
|
| 230 | + _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 231 | + $initial, |
|
| 232 | + sanitize_text_field( $subscription->get_trial_period() ), |
|
| 233 | + $recurring, |
|
| 234 | + sanitize_text_field( strtolower( $period ) ) |
|
| 235 | + ); |
|
| 236 | 236 | |
| 237 | - } else if ( $initial != $recurring ) { |
|
| 237 | + } else if ( $initial != $recurring ) { |
|
| 238 | 238 | |
| 239 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
|
| 240 | - $amount = sprintf( |
|
| 241 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
| 242 | - $initial, |
|
| 243 | - $recurring, |
|
| 244 | - sanitize_text_field( strtolower( $period ) ) |
|
| 245 | - ); |
|
| 239 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
|
| 240 | + $amount = sprintf( |
|
| 241 | + _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
| 242 | + $initial, |
|
| 243 | + $recurring, |
|
| 244 | + sanitize_text_field( strtolower( $period ) ) |
|
| 245 | + ); |
|
| 246 | 246 | |
| 247 | - } else { |
|
| 247 | + } else { |
|
| 248 | 248 | |
| 249 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 250 | - $amount = sprintf( |
|
| 251 | - _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
| 252 | - $initial, |
|
| 253 | - sanitize_text_field( strtolower( $period ) ) |
|
| 254 | - ); |
|
| 249 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 250 | + $amount = sprintf( |
|
| 251 | + _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
| 252 | + $initial, |
|
| 253 | + sanitize_text_field( strtolower( $period ) ) |
|
| 254 | + ); |
|
| 255 | 255 | |
| 256 | - } |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - echo "<span>$amount</span>"; |
|
| 258 | + echo "<span>$amount</span>"; |
|
| 259 | 259 | } |
| 260 | 260 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
| 261 | 261 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @param WPInv_Subscription $subscription |
| 266 | 266 | */ |
| 267 | 267 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
| 268 | - echo '#' . absint( $subscription->get_id() ); |
|
| 268 | + echo '#' . absint( $subscription->get_id() ); |
|
| 269 | 269 | } |
| 270 | 270 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
| 271 | 271 | |
@@ -276,12 +276,12 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
| 278 | 278 | |
| 279 | - $created = $subscription->get_date_created(); |
|
| 280 | - if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
| 281 | - echo "—"; |
|
| 282 | - } else { |
|
| 283 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
| 284 | - } |
|
| 279 | + $created = $subscription->get_date_created(); |
|
| 280 | + if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
| 281 | + echo "—"; |
|
| 282 | + } else { |
|
| 283 | + echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | 286 | } |
| 287 | 287 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
@@ -293,12 +293,12 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
| 295 | 295 | |
| 296 | - $expiration = $subscription->get_expiration(); |
|
| 297 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 298 | - echo "—"; |
|
| 299 | - } else { |
|
| 300 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
| 301 | - } |
|
| 296 | + $expiration = $subscription->get_expiration(); |
|
| 297 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 298 | + echo "—"; |
|
| 299 | + } else { |
|
| 300 | + echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | 303 | } |
| 304 | 304 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | * @param WPInv_Subscription $subscription |
| 310 | 310 | */ |
| 311 | 311 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
| 312 | - $max_bills = $subscription->get_bill_times(); |
|
| 313 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 312 | + $max_bills = $subscription->get_bill_times(); |
|
| 313 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 314 | 314 | } |
| 315 | 315 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
| 316 | 316 | |
@@ -321,16 +321,16 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
| 323 | 323 | |
| 324 | - $item = get_post( $subscription->get_product_id() ); |
|
| 324 | + $item = get_post( $subscription->get_product_id() ); |
|
| 325 | 325 | |
| 326 | - if ( ! empty( $item ) ) { |
|
| 327 | - $link = get_edit_post_link( $item ); |
|
| 328 | - $link = esc_url( $link ); |
|
| 329 | - $name = esc_html( get_the_title( $item ) ); |
|
| 330 | - echo "<a href='$link'>$name</a>"; |
|
| 331 | - } else { |
|
| 332 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 333 | - } |
|
| 326 | + if ( ! empty( $item ) ) { |
|
| 327 | + $link = get_edit_post_link( $item ); |
|
| 328 | + $link = esc_url( $link ); |
|
| 329 | + $name = esc_html( get_the_title( $item ) ); |
|
| 330 | + echo "<a href='$link'>$name</a>"; |
|
| 331 | + } else { |
|
| 332 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | 335 | } |
| 336 | 336 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
@@ -342,13 +342,13 @@ discard block |
||
| 342 | 342 | */ |
| 343 | 343 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
| 344 | 344 | |
| 345 | - $gateway = $subscription->get_gateway(); |
|
| 345 | + $gateway = $subscription->get_gateway(); |
|
| 346 | 346 | |
| 347 | - if ( ! empty( $gateway ) ) { |
|
| 348 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 349 | - } else { |
|
| 350 | - echo "—"; |
|
| 351 | - } |
|
| 347 | + if ( ! empty( $gateway ) ) { |
|
| 348 | + echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 349 | + } else { |
|
| 350 | + echo "—"; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | 353 | } |
| 354 | 354 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * @param WPInv_Subscription $subscription |
| 360 | 360 | */ |
| 361 | 361 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
| 362 | - echo $subscription->get_status_label_html(); |
|
| 362 | + echo $subscription->get_status_label_html(); |
|
| 363 | 363 | } |
| 364 | 364 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
| 365 | 365 | |
@@ -370,14 +370,14 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
| 372 | 372 | |
| 373 | - $profile_id = $subscription->get_profile_id(); |
|
| 373 | + $profile_id = $subscription->get_profile_id(); |
|
| 374 | 374 | |
| 375 | - if ( ! empty( $profile_id ) ) { |
|
| 376 | - $profile_id = sanitize_text_field( $profile_id ); |
|
| 377 | - echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
| 378 | - } else { |
|
| 379 | - echo "—"; |
|
| 380 | - } |
|
| 375 | + if ( ! empty( $profile_id ) ) { |
|
| 376 | + $profile_id = sanitize_text_field( $profile_id ); |
|
| 377 | + echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
| 378 | + } else { |
|
| 379 | + echo "—"; |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | 382 | } |
| 383 | 383 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -389,39 +389,39 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
| 391 | 391 | |
| 392 | - ?> |
|
| 392 | + ?> |
|
| 393 | 393 | <div class="mt-3"> |
| 394 | 394 | |
| 395 | 395 | <?php |
| 396 | - echo aui()->select( |
|
| 397 | - array( |
|
| 398 | - 'options' => getpaid_get_subscription_statuses(), |
|
| 399 | - 'name' => 'subscription_status', |
|
| 400 | - 'id' => 'subscription_status_update_select', |
|
| 401 | - 'required' => true, |
|
| 402 | - 'no_wrap' => false, |
|
| 403 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 404 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 405 | - 'select2' => true, |
|
| 406 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 407 | - ) |
|
| 408 | - ); |
|
| 409 | - ?> |
|
| 396 | + echo aui()->select( |
|
| 397 | + array( |
|
| 398 | + 'options' => getpaid_get_subscription_statuses(), |
|
| 399 | + 'name' => 'subscription_status', |
|
| 400 | + 'id' => 'subscription_status_update_select', |
|
| 401 | + 'required' => true, |
|
| 402 | + 'no_wrap' => false, |
|
| 403 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 404 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 405 | + 'select2' => true, |
|
| 406 | + 'value' => $subscription->get_status( 'edit' ), |
|
| 407 | + ) |
|
| 408 | + ); |
|
| 409 | + ?> |
|
| 410 | 410 | |
| 411 | 411 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 412 | 412 | |
| 413 | 413 | <?php |
| 414 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 414 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 415 | 415 | |
| 416 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 417 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 418 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 416 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 417 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 418 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 419 | 419 | |
| 420 | - if ( $subscription->is_active() ) { |
|
| 421 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 422 | - } |
|
| 420 | + if ( $subscription->is_active() ) { |
|
| 421 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | - echo '</div></div>'; |
|
| 424 | + echo '</div></div>'; |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -431,27 +431,27 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
| 433 | 433 | |
| 434 | - $columns = apply_filters( |
|
| 435 | - 'getpaid_subscription_related_invoices_columns', |
|
| 436 | - array( |
|
| 437 | - |
|
| 438 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 439 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 440 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 441 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 442 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 443 | - ) |
|
| 444 | - ); |
|
| 445 | - |
|
| 446 | - // Prepare the invoices. |
|
| 447 | - $payments = $subscription->get_child_payments(); |
|
| 448 | - $parent = $subscription->get_parent_invoice(); |
|
| 449 | - |
|
| 450 | - if ( $parent->get_id() ) { |
|
| 451 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 452 | - } |
|
| 434 | + $columns = apply_filters( |
|
| 435 | + 'getpaid_subscription_related_invoices_columns', |
|
| 436 | + array( |
|
| 437 | + |
|
| 438 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 439 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 440 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 441 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 442 | + 'total' => __( 'Total', 'invoicing' ), |
|
| 443 | + ) |
|
| 444 | + ); |
|
| 445 | + |
|
| 446 | + // Prepare the invoices. |
|
| 447 | + $payments = $subscription->get_child_payments(); |
|
| 448 | + $parent = $subscription->get_parent_invoice(); |
|
| 449 | + |
|
| 450 | + if ( $parent->get_id() ) { |
|
| 451 | + $payments = array_merge( array( $parent ), $payments ); |
|
| 452 | + } |
|
| 453 | 453 | |
| 454 | - ?> |
|
| 454 | + ?> |
|
| 455 | 455 | <div class="m-0" style="overflow: auto;"> |
| 456 | 456 | |
| 457 | 457 | <table class="w-100 bg-white"> |
@@ -459,13 +459,13 @@ discard block |
||
| 459 | 459 | <thead> |
| 460 | 460 | <tr> |
| 461 | 461 | <?php |
| 462 | - foreach ( $columns as $key => $label ) { |
|
| 463 | - $key = esc_attr( $key ); |
|
| 464 | - $label = sanitize_text_field( $label ); |
|
| 462 | + foreach ( $columns as $key => $label ) { |
|
| 463 | + $key = esc_attr( $key ); |
|
| 464 | + $label = sanitize_text_field( $label ); |
|
| 465 | 465 | |
| 466 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
| 467 | - } |
|
| 468 | - ?> |
|
| 466 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
| 467 | + } |
|
| 468 | + ?> |
|
| 469 | 469 | </tr> |
| 470 | 470 | </thead> |
| 471 | 471 | |
@@ -473,57 +473,57 @@ discard block |
||
| 473 | 473 | |
| 474 | 474 | <?php |
| 475 | 475 | |
| 476 | - foreach( $payments as $payment ) : |
|
| 476 | + foreach( $payments as $payment ) : |
|
| 477 | 477 | |
| 478 | - // Ensure that we have an invoice. |
|
| 479 | - if ( ! is_a( $payment, 'WPInv_Invoice' ) ) { |
|
| 480 | - $payment = new WPInv_Invoice( $payment ); |
|
| 481 | - } |
|
| 478 | + // Ensure that we have an invoice. |
|
| 479 | + if ( ! is_a( $payment, 'WPInv_Invoice' ) ) { |
|
| 480 | + $payment = new WPInv_Invoice( $payment ); |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - // Abort if the invoice is invalid. |
|
| 484 | - if ( ! $payment->get_id() ) { |
|
| 485 | - continue; |
|
| 486 | - } |
|
| 483 | + // Abort if the invoice is invalid. |
|
| 484 | + if ( ! $payment->get_id() ) { |
|
| 485 | + continue; |
|
| 486 | + } |
|
| 487 | 487 | |
| 488 | - echo '<tr>'; |
|
| 488 | + echo '<tr>'; |
|
| 489 | 489 | |
| 490 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 490 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 491 | 491 | |
| 492 | - echo '<td class="p-2 text-left">'; |
|
| 492 | + echo '<td class="p-2 text-left">'; |
|
| 493 | 493 | |
| 494 | - switch( $key ) { |
|
| 494 | + switch( $key ) { |
|
| 495 | 495 | |
| 496 | - case 'total': |
|
| 497 | - echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>'; |
|
| 498 | - break; |
|
| 496 | + case 'total': |
|
| 497 | + echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>'; |
|
| 498 | + break; |
|
| 499 | 499 | |
| 500 | - case 'relationship': |
|
| 501 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 502 | - break; |
|
| 500 | + case 'relationship': |
|
| 501 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 502 | + break; |
|
| 503 | 503 | |
| 504 | - case 'date': |
|
| 505 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $payment->get_date_created() ) ); |
|
| 506 | - break; |
|
| 504 | + case 'date': |
|
| 505 | + echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $payment->get_date_created() ) ); |
|
| 506 | + break; |
|
| 507 | 507 | |
| 508 | - case 'status': |
|
| 509 | - echo $payment->get_status_label_html(); |
|
| 510 | - break; |
|
| 508 | + case 'status': |
|
| 509 | + echo $payment->get_status_label_html(); |
|
| 510 | + break; |
|
| 511 | 511 | |
| 512 | - case 'invoice': |
|
| 513 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 514 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 515 | - echo "<a href='$link'>$invoice</a>"; |
|
| 516 | - break; |
|
| 517 | - } |
|
| 512 | + case 'invoice': |
|
| 513 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 514 | + $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 515 | + echo "<a href='$link'>$invoice</a>"; |
|
| 516 | + break; |
|
| 517 | + } |
|
| 518 | 518 | |
| 519 | - echo '</td>'; |
|
| 519 | + echo '</td>'; |
|
| 520 | 520 | |
| 521 | - } |
|
| 521 | + } |
|
| 522 | 522 | |
| 523 | - echo '</tr>'; |
|
| 523 | + echo '</tr>'; |
|
| 524 | 524 | |
| 525 | - endforeach; |
|
| 526 | - ?> |
|
| 525 | + endforeach; |
|
| 526 | + ?> |
|
| 527 | 527 | |
| 528 | 528 | </tbody> |
| 529 | 529 | |
@@ -543,30 +543,30 @@ discard block |
||
| 543 | 543 | */ |
| 544 | 544 | function wpinv_recurring_process_subscription_deletion() { |
| 545 | 545 | |
| 546 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 547 | - return; |
|
| 548 | - } |
|
| 546 | + if( empty( $_POST['sub_id'] ) ) { |
|
| 547 | + return; |
|
| 548 | + } |
|
| 549 | 549 | |
| 550 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 551 | - return; |
|
| 552 | - } |
|
| 550 | + if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 551 | + return; |
|
| 552 | + } |
|
| 553 | 553 | |
| 554 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 555 | - return; |
|
| 556 | - } |
|
| 554 | + if( ! current_user_can( 'manage_invoicing') ) { |
|
| 555 | + return; |
|
| 556 | + } |
|
| 557 | 557 | |
| 558 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 559 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 560 | - } |
|
| 558 | + if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 559 | + wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 560 | + } |
|
| 561 | 561 | |
| 562 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 562 | + $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 563 | 563 | |
| 564 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 564 | + delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 565 | 565 | |
| 566 | - $subscription->delete(); |
|
| 566 | + $subscription->delete(); |
|
| 567 | 567 | |
| 568 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 569 | - exit; |
|
| 568 | + wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 569 | + exit; |
|
| 570 | 570 | |
| 571 | 571 | } |
| 572 | 572 | add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Contains functions that display the subscriptions admin page. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -defined( 'ABSPATH' ) || exit; |
|
| 6 | +defined('ABSPATH') || exit; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Render the Subscriptions page |
@@ -17,22 +17,22 @@ discard block |
||
| 17 | 17 | ?> |
| 18 | 18 | |
| 19 | 19 | <div class="wrap"> |
| 20 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
| 20 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
| 21 | 21 | <div class="bsui"> |
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | 24 | |
| 25 | 25 | // Verify user permissions. |
| 26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 26 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 27 | 27 | |
| 28 | 28 | echo aui()->alert( |
| 29 | 29 | array( |
| 30 | 30 | 'type' => 'danger', |
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 31 | + 'content' => __('You are not permitted to view this page.', 'invoicing'), |
|
| 32 | 32 | ) |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 35 | + } else if (!empty($_GET['id']) && is_numeric($_GET['id'])) { |
|
| 36 | 36 | |
| 37 | 37 | // Display a single subscription. |
| 38 | 38 | wpinv_recurring_subscription_details(); |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | function wpinv_recurring_subscription_details() { |
| 82 | 82 | |
| 83 | 83 | // Fetch the subscription. |
| 84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | - if ( ! $sub->get_id() ) { |
|
| 84 | + $sub = new WPInv_Subscription((int) $_GET['id']); |
|
| 85 | + if (!$sub->get_id()) { |
|
| 86 | 86 | |
| 87 | 87 | echo aui()->alert( |
| 88 | 88 | array( |
| 89 | 89 | 'type' => 'danger', |
| 90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 90 | + 'content' => __('Subscription not found.', 'invoicing'), |
|
| 91 | 91 | ) |
| 92 | 92 | ); |
| 93 | 93 | |
@@ -95,31 +95,31 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // Use metaboxes to display the subscription details. |
| 98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 98 | + add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal'); |
|
| 99 | + add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side'); |
|
| 100 | + add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced'); |
|
| 101 | + do_action('getpaid_admin_single_subscription_register_metabox', $sub); |
|
| 102 | 102 | |
| 103 | 103 | ?> |
| 104 | 104 | |
| 105 | - <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
|
| 105 | + <form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>"> |
|
| 106 | 106 | |
| 107 | - <?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?> |
|
| 108 | - <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> |
|
| 109 | - <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> |
|
| 107 | + <?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?> |
|
| 108 | + <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?> |
|
| 109 | + <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?> |
|
| 110 | 110 | <input type="hidden" name="getpaid-admin-action" value="update_single_subscription" /> |
| 111 | - <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" /> |
|
| 111 | + <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" /> |
|
| 112 | 112 | |
| 113 | 113 | <div id="poststuff"> |
| 114 | 114 | <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> |
| 115 | 115 | |
| 116 | 116 | <div id="postbox-container-1" class="postbox-container"> |
| 117 | - <?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?> |
|
| 117 | + <?php do_meta_boxes(get_current_screen(), 'side', $sub); ?> |
|
| 118 | 118 | </div> |
| 119 | 119 | |
| 120 | 120 | <div id="postbox-container-2" class="postbox-container"> |
| 121 | - <?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?> |
|
| 122 | - <?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?> |
|
| 121 | + <?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?> |
|
| 122 | + <?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?> |
|
| 123 | 123 | </div> |
| 124 | 124 | |
| 125 | 125 | </div> |
@@ -138,27 +138,27 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @param WPInv_Subscription $sub |
| 140 | 140 | */ |
| 141 | -function getpaid_admin_subscription_details_metabox( $sub ) { |
|
| 141 | +function getpaid_admin_subscription_details_metabox($sub) { |
|
| 142 | 142 | |
| 143 | 143 | // Prepare subscription detail columns. |
| 144 | 144 | $fields = apply_filters( |
| 145 | 145 | 'getpaid_subscription_admin_page_fields', |
| 146 | 146 | array( |
| 147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | - 'renewals' => __( 'Renewals', 'invoicing' ), |
|
| 153 | - 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 147 | + 'subscription' => __('Subscription', 'invoicing'), |
|
| 148 | + 'customer' => __('Customer', 'invoicing'), |
|
| 149 | + 'amount' => __('Amount', 'invoicing'), |
|
| 150 | + 'start_date' => __('Start Date', 'invoicing'), |
|
| 151 | + 'renews_on' => __('Next Payment', 'invoicing'), |
|
| 152 | + 'renewals' => __('Renewals', 'invoicing'), |
|
| 153 | + 'item' => __('Item', 'invoicing'), |
|
| 154 | + 'gateway' => __('Payment Method', 'invoicing'), |
|
| 155 | + 'profile_id' => __('Profile ID', 'invoicing'), |
|
| 156 | + 'status' => __('Status', 'invoicing'), |
|
| 157 | 157 | ) |
| 158 | 158 | ); |
| 159 | 159 | |
| 160 | - if ( ! $sub->is_active() && isset( $fields['renews_on'] ) ) { |
|
| 161 | - unset( $fields['renews_on'] ); |
|
| 160 | + if (!$sub->is_active() && isset($fields['renews_on'])) { |
|
| 161 | + unset($fields['renews_on']); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | ?> |
@@ -166,16 +166,16 @@ discard block |
||
| 166 | 166 | <table class="table table-borderless" style="font-size: 14px;"> |
| 167 | 167 | <tbody> |
| 168 | 168 | |
| 169 | - <?php foreach ( $fields as $key => $label ) : ?> |
|
| 169 | + <?php foreach ($fields as $key => $label) : ?> |
|
| 170 | 170 | |
| 171 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
| 171 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
| 172 | 172 | |
| 173 | 173 | <th class="w-25" style="font-weight: 500;"> |
| 174 | - <?php echo sanitize_text_field( $label ); ?> |
|
| 174 | + <?php echo sanitize_text_field($label); ?> |
|
| 175 | 175 | </th> |
| 176 | 176 | |
| 177 | 177 | <td class="w-75 text-muted"> |
| 178 | - <?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub ); ?> |
|
| 178 | + <?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub); ?> |
|
| 179 | 179 | </td> |
| 180 | 180 | |
| 181 | 181 | </tr> |
@@ -193,201 +193,201 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @param WPInv_Subscription $subscription |
| 195 | 195 | */ |
| 196 | -function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
|
| 196 | +function getpaid_admin_subscription_metabox_display_customer($subscription) { |
|
| 197 | 197 | |
| 198 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 198 | + $username = __('(Missing User)', 'invoicing'); |
|
| 199 | 199 | |
| 200 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 201 | - if ( $user ) { |
|
| 200 | + $user = get_userdata($subscription->get_customer_id()); |
|
| 201 | + if ($user) { |
|
| 202 | 202 | |
| 203 | 203 | $username = sprintf( |
| 204 | 204 | '<a href="user-edit.php?user_id=%s">%s</a>', |
| 205 | - absint( $user->ID ), |
|
| 206 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 205 | + absint($user->ID), |
|
| 206 | + !empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email) |
|
| 207 | 207 | ); |
| 208 | 208 | |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | echo $username; |
| 212 | 212 | } |
| 213 | -add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
|
| 213 | +add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer'); |
|
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | 216 | * Displays the subscription amount. |
| 217 | 217 | * |
| 218 | 218 | * @param WPInv_Subscription $subscription |
| 219 | 219 | */ |
| 220 | -function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
|
| 220 | +function getpaid_admin_subscription_metabox_display_amount($subscription) { |
|
| 221 | 221 | |
| 222 | - $initial = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
| 223 | - $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
| 224 | - $period = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() ); |
|
| 222 | + $initial = wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($subscription->get_initial_amount())), $subscription->get_parent_payment()->get_currency()); |
|
| 223 | + $recurring = wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($subscription->get_recurring_amount())), $subscription->get_parent_payment()->get_currency()); |
|
| 224 | + $period = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label($subscription->get_period()) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->get_period(), $subscription->get_frequency()); |
|
| 225 | 225 | |
| 226 | - if ( $subscription->has_trial_period() ) { |
|
| 226 | + if ($subscription->has_trial_period()) { |
|
| 227 | 227 | |
| 228 | 228 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
| 229 | 229 | $amount = sprintf( |
| 230 | - _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 230 | + _x('%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'), |
|
| 231 | 231 | $initial, |
| 232 | - sanitize_text_field( $subscription->get_trial_period() ), |
|
| 232 | + sanitize_text_field($subscription->get_trial_period()), |
|
| 233 | 233 | $recurring, |
| 234 | - sanitize_text_field( strtolower( $period ) ) |
|
| 234 | + sanitize_text_field(strtolower($period)) |
|
| 235 | 235 | ); |
| 236 | 236 | |
| 237 | - } else if ( $initial != $recurring ) { |
|
| 237 | + } else if ($initial != $recurring) { |
|
| 238 | 238 | |
| 239 | 239 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio |
| 240 | 240 | $amount = sprintf( |
| 241 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ), |
|
| 241 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing'), |
|
| 242 | 242 | $initial, |
| 243 | 243 | $recurring, |
| 244 | - sanitize_text_field( strtolower( $period ) ) |
|
| 244 | + sanitize_text_field(strtolower($period)) |
|
| 245 | 245 | ); |
| 246 | 246 | |
| 247 | 247 | } else { |
| 248 | 248 | |
| 249 | 249 | // translators: $1: is the recurring amount, $2: is the recurring period |
| 250 | 250 | $amount = sprintf( |
| 251 | - _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ), |
|
| 251 | + _x('%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing'), |
|
| 252 | 252 | $initial, |
| 253 | - sanitize_text_field( strtolower( $period ) ) |
|
| 253 | + sanitize_text_field(strtolower($period)) |
|
| 254 | 254 | ); |
| 255 | 255 | |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | echo "<span>$amount</span>"; |
| 259 | 259 | } |
| 260 | -add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
|
| 260 | +add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount'); |
|
| 261 | 261 | |
| 262 | 262 | /** |
| 263 | 263 | * Displays the subscription id. |
| 264 | 264 | * |
| 265 | 265 | * @param WPInv_Subscription $subscription |
| 266 | 266 | */ |
| 267 | -function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
|
| 268 | - echo '#' . absint( $subscription->get_id() ); |
|
| 267 | +function getpaid_admin_subscription_metabox_display_id($subscription) { |
|
| 268 | + echo '#' . absint($subscription->get_id()); |
|
| 269 | 269 | } |
| 270 | -add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
|
| 270 | +add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id'); |
|
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | 273 | * Displays the subscription renewal date. |
| 274 | 274 | * |
| 275 | 275 | * @param WPInv_Subscription $subscription |
| 276 | 276 | */ |
| 277 | -function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
|
| 277 | +function getpaid_admin_subscription_metabox_display_start_date($subscription) { |
|
| 278 | 278 | |
| 279 | 279 | $created = $subscription->get_date_created(); |
| 280 | - if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) { |
|
| 280 | + if (empty($created) || '0000-00-00 00:00:00' == $created) { |
|
| 281 | 281 | echo "—"; |
| 282 | 282 | } else { |
| 283 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) ); |
|
| 283 | + echo date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($created)); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | } |
| 287 | -add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
|
| 287 | +add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date'); |
|
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * Displays the subscription renewal date. |
| 291 | 291 | * |
| 292 | 292 | * @param WPInv_Subscription $subscription |
| 293 | 293 | */ |
| 294 | -function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
|
| 294 | +function getpaid_admin_subscription_metabox_display_renews_on($subscription) { |
|
| 295 | 295 | |
| 296 | 296 | $expiration = $subscription->get_expiration(); |
| 297 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 297 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
| 298 | 298 | echo "—"; |
| 299 | 299 | } else { |
| 300 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) ); |
|
| 300 | + echo date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($expiration)); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | } |
| 304 | -add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
|
| 304 | +add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on'); |
|
| 305 | 305 | |
| 306 | 306 | /** |
| 307 | 307 | * Displays the subscription renewal count. |
| 308 | 308 | * |
| 309 | 309 | * @param WPInv_Subscription $subscription |
| 310 | 310 | */ |
| 311 | -function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
|
| 311 | +function getpaid_admin_subscription_metabox_display_renewals($subscription) { |
|
| 312 | 312 | $max_bills = $subscription->get_bill_times(); |
| 313 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 313 | + echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "∞" : $max_bills); |
|
| 314 | 314 | } |
| 315 | -add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
|
| 315 | +add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals'); |
|
| 316 | 316 | |
| 317 | 317 | /** |
| 318 | 318 | * Displays the subscription item. |
| 319 | 319 | * |
| 320 | 320 | * @param WPInv_Subscription $subscription |
| 321 | 321 | */ |
| 322 | -function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
|
| 322 | +function getpaid_admin_subscription_metabox_display_item($subscription) { |
|
| 323 | 323 | |
| 324 | - $item = get_post( $subscription->get_product_id() ); |
|
| 324 | + $item = get_post($subscription->get_product_id()); |
|
| 325 | 325 | |
| 326 | - if ( ! empty( $item ) ) { |
|
| 327 | - $link = get_edit_post_link( $item ); |
|
| 328 | - $link = esc_url( $link ); |
|
| 329 | - $name = esc_html( get_the_title( $item ) ); |
|
| 326 | + if (!empty($item)) { |
|
| 327 | + $link = get_edit_post_link($item); |
|
| 328 | + $link = esc_url($link); |
|
| 329 | + $name = esc_html(get_the_title($item)); |
|
| 330 | 330 | echo "<a href='$link'>$name</a>"; |
| 331 | 331 | } else { |
| 332 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 332 | + echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id()); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | } |
| 336 | -add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
|
| 336 | +add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item'); |
|
| 337 | 337 | |
| 338 | 338 | /** |
| 339 | 339 | * Displays the subscription gateway. |
| 340 | 340 | * |
| 341 | 341 | * @param WPInv_Subscription $subscription |
| 342 | 342 | */ |
| 343 | -function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
|
| 343 | +function getpaid_admin_subscription_metabox_display_gateway($subscription) { |
|
| 344 | 344 | |
| 345 | 345 | $gateway = $subscription->get_gateway(); |
| 346 | 346 | |
| 347 | - if ( ! empty( $gateway ) ) { |
|
| 348 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 347 | + if (!empty($gateway)) { |
|
| 348 | + echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway)); |
|
| 349 | 349 | } else { |
| 350 | 350 | echo "—"; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | } |
| 354 | -add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
|
| 354 | +add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway'); |
|
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | 357 | * Displays the subscription status. |
| 358 | 358 | * |
| 359 | 359 | * @param WPInv_Subscription $subscription |
| 360 | 360 | */ |
| 361 | -function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
|
| 361 | +function getpaid_admin_subscription_metabox_display_status($subscription) { |
|
| 362 | 362 | echo $subscription->get_status_label_html(); |
| 363 | 363 | } |
| 364 | -add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
|
| 364 | +add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status'); |
|
| 365 | 365 | |
| 366 | 366 | /** |
| 367 | 367 | * Displays the subscription profile id. |
| 368 | 368 | * |
| 369 | 369 | * @param WPInv_Subscription $subscription |
| 370 | 370 | */ |
| 371 | -function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
|
| 371 | +function getpaid_admin_subscription_metabox_display_profile_id($subscription) { |
|
| 372 | 372 | |
| 373 | 373 | $profile_id = $subscription->get_profile_id(); |
| 374 | 374 | |
| 375 | - if ( ! empty( $profile_id ) ) { |
|
| 376 | - $profile_id = sanitize_text_field( $profile_id ); |
|
| 377 | - echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
| 375 | + if (!empty($profile_id)) { |
|
| 376 | + $profile_id = sanitize_text_field($profile_id); |
|
| 377 | + echo apply_filters('getpaid_subscription_profile_id_display', $profile_id, $subscription); |
|
| 378 | 378 | } else { |
| 379 | 379 | echo "—"; |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | } |
| 383 | -add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
|
| 383 | +add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id'); |
|
| 384 | 384 | |
| 385 | 385 | /** |
| 386 | 386 | * Displays the subscriptions update metabox. |
| 387 | 387 | * |
| 388 | 388 | * @param WPInv_Subscription $subscription |
| 389 | 389 | */ |
| 390 | -function getpaid_admin_subscription_update_metabox( $subscription ) { |
|
| 390 | +function getpaid_admin_subscription_update_metabox($subscription) { |
|
| 391 | 391 | |
| 392 | 392 | ?> |
| 393 | 393 | <div class="mt-3"> |
@@ -400,10 +400,10 @@ discard block |
||
| 400 | 400 | 'id' => 'subscription_status_update_select', |
| 401 | 401 | 'required' => true, |
| 402 | 402 | 'no_wrap' => false, |
| 403 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 404 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 403 | + 'label' => __('Subscription Status', 'invoicing'), |
|
| 404 | + 'help_text' => __('Updating the status will trigger related actions and hooks', 'invoicing'), |
|
| 405 | 405 | 'select2' => true, |
| 406 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 406 | + 'value' => $subscription->get_status('edit'), |
|
| 407 | 407 | ) |
| 408 | 408 | ); |
| 409 | 409 | ?> |
@@ -411,13 +411,13 @@ discard block |
||
| 411 | 411 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 412 | 412 | |
| 413 | 413 | <?php |
| 414 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 414 | + submit_button(__('Update', 'invoicing'), 'primary', 'submit', false); |
|
| 415 | 415 | |
| 416 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 417 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 418 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 416 | + $url = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce')); |
|
| 417 | + $anchor = __('Renew Subscription', 'invoicing'); |
|
| 418 | + $title = esc_attr__('Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing'); |
|
| 419 | 419 | |
| 420 | - if ( $subscription->is_active() ) { |
|
| 420 | + if ($subscription->is_active()) { |
|
| 421 | 421 | echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
| 422 | 422 | } |
| 423 | 423 | |
@@ -429,17 +429,17 @@ discard block |
||
| 429 | 429 | * |
| 430 | 430 | * @param WPInv_Subscription $subscription |
| 431 | 431 | */ |
| 432 | -function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
|
| 432 | +function getpaid_admin_subscription_invoice_details_metabox($subscription) { |
|
| 433 | 433 | |
| 434 | 434 | $columns = apply_filters( |
| 435 | 435 | 'getpaid_subscription_related_invoices_columns', |
| 436 | 436 | array( |
| 437 | 437 | |
| 438 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 439 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 440 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 441 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 442 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 438 | + 'invoice' => __('Invoice', 'invoicing'), |
|
| 439 | + 'relationship' => __('Relationship', 'invoicing'), |
|
| 440 | + 'date' => __('Date', 'invoicing'), |
|
| 441 | + 'status' => __('Status', 'invoicing'), |
|
| 442 | + 'total' => __('Total', 'invoicing'), |
|
| 443 | 443 | ) |
| 444 | 444 | ); |
| 445 | 445 | |
@@ -447,8 +447,8 @@ discard block |
||
| 447 | 447 | $payments = $subscription->get_child_payments(); |
| 448 | 448 | $parent = $subscription->get_parent_invoice(); |
| 449 | 449 | |
| 450 | - if ( $parent->get_id() ) { |
|
| 451 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 450 | + if ($parent->get_id()) { |
|
| 451 | + $payments = array_merge(array($parent), $payments); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | ?> |
@@ -459,9 +459,9 @@ discard block |
||
| 459 | 459 | <thead> |
| 460 | 460 | <tr> |
| 461 | 461 | <?php |
| 462 | - foreach ( $columns as $key => $label ) { |
|
| 463 | - $key = esc_attr( $key ); |
|
| 464 | - $label = sanitize_text_field( $label ); |
|
| 462 | + foreach ($columns as $key => $label) { |
|
| 463 | + $key = esc_attr($key); |
|
| 464 | + $label = sanitize_text_field($label); |
|
| 465 | 465 | |
| 466 | 466 | echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
| 467 | 467 | } |
@@ -473,36 +473,36 @@ discard block |
||
| 473 | 473 | |
| 474 | 474 | <?php |
| 475 | 475 | |
| 476 | - foreach( $payments as $payment ) : |
|
| 476 | + foreach ($payments as $payment) : |
|
| 477 | 477 | |
| 478 | 478 | // Ensure that we have an invoice. |
| 479 | - if ( ! is_a( $payment, 'WPInv_Invoice' ) ) { |
|
| 480 | - $payment = new WPInv_Invoice( $payment ); |
|
| 479 | + if (!is_a($payment, 'WPInv_Invoice')) { |
|
| 480 | + $payment = new WPInv_Invoice($payment); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | // Abort if the invoice is invalid. |
| 484 | - if ( ! $payment->get_id() ) { |
|
| 484 | + if (!$payment->get_id()) { |
|
| 485 | 485 | continue; |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | echo '<tr>'; |
| 489 | 489 | |
| 490 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 490 | + foreach (array_keys($columns) as $key) { |
|
| 491 | 491 | |
| 492 | 492 | echo '<td class="p-2 text-left">'; |
| 493 | 493 | |
| 494 | - switch( $key ) { |
|
| 494 | + switch ($key) { |
|
| 495 | 495 | |
| 496 | 496 | case 'total': |
| 497 | - echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>'; |
|
| 497 | + echo '<strong>' . wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($payment->get_total)), $payment->get_currency()) . '</strong>'; |
|
| 498 | 498 | break; |
| 499 | 499 | |
| 500 | 500 | case 'relationship': |
| 501 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 501 | + echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing'); |
|
| 502 | 502 | break; |
| 503 | 503 | |
| 504 | 504 | case 'date': |
| 505 | - echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $payment->get_date_created() ) ); |
|
| 505 | + echo date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($payment->get_date_created())); |
|
| 506 | 506 | break; |
| 507 | 507 | |
| 508 | 508 | case 'status': |
@@ -510,8 +510,8 @@ discard block |
||
| 510 | 510 | break; |
| 511 | 511 | |
| 512 | 512 | case 'invoice': |
| 513 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 514 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 513 | + $link = esc_url(get_edit_post_link($payment->get_id())); |
|
| 514 | + $invoice = sanitize_text_field($payment->get_number()); |
|
| 515 | 515 | echo "<a href='$link'>$invoice</a>"; |
| 516 | 516 | break; |
| 517 | 517 | } |
@@ -543,30 +543,30 @@ discard block |
||
| 543 | 543 | */ |
| 544 | 544 | function wpinv_recurring_process_subscription_deletion() { |
| 545 | 545 | |
| 546 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 546 | + if (empty($_POST['sub_id'])) { |
|
| 547 | 547 | return; |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 550 | + if (empty($_POST['wpinv_delete_subscription'])) { |
|
| 551 | 551 | return; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 554 | + if (!current_user_can('manage_invoicing')) { |
|
| 555 | 555 | return; |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 559 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 558 | + if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) { |
|
| 559 | + wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 562 | + $subscription = new WPInv_Subscription(absint($_POST['sub_id'])); |
|
| 563 | 563 | |
| 564 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 564 | + delete_post_meta($subscription->parent_payment_id, '_wpinv_subscription_payment'); |
|
| 565 | 565 | |
| 566 | 566 | $subscription->delete(); |
| 567 | 567 | |
| 568 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 568 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=deleted')); |
|
| 569 | 569 | exit; |
| 570 | 570 | |
| 571 | 571 | } |
| 572 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
|
| 572 | +add_action('admin_init', 'wpinv_recurring_process_subscription_deletion', 2); |
|