@@ -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, |
@@ -60,17 +60,17 @@ discard block |
||
| 60 | 60 | 'state' => null, |
| 61 | 61 | 'zip' => null, |
| 62 | 62 | 'company' => null, |
| 63 | - 'company_id' => null, |
|
| 63 | + 'company_id' => null, |
|
| 64 | 64 | 'vat_number' => null, |
| 65 | 65 | 'vat_rate' => null, |
| 66 | 66 | 'address' => null, |
| 67 | 67 | 'address_confirmed' => false, |
| 68 | 68 | 'shipping' => null, |
| 69 | - 'subtotal' => 0, |
|
| 69 | + 'subtotal' => 0, |
|
| 70 | 70 | 'total_discount' => 0, |
| 71 | 71 | 'total_tax' => 0, |
| 72 | - 'total_fees' => 0, |
|
| 73 | - 'total' => 0, |
|
| 72 | + 'total_fees' => 0, |
|
| 73 | + 'total' => 0, |
|
| 74 | 74 | 'fees' => array(), |
| 75 | 75 | 'discounts' => array(), |
| 76 | 76 | 'taxes' => array(), |
@@ -82,22 +82,22 @@ discard block |
||
| 82 | 82 | 'transaction_id' => '', |
| 83 | 83 | 'currency' => '', |
| 84 | 84 | 'disable_taxes' => false, |
| 85 | - 'subscription_id' => null, |
|
| 86 | - 'remote_subscription_id' => null, |
|
| 87 | - 'is_viewed' => false, |
|
| 88 | - 'email_cc' => '', |
|
| 89 | - 'template' => 'quantity', // hours, amount only |
|
| 90 | - 'created_via' => null, |
|
| 85 | + 'subscription_id' => null, |
|
| 86 | + 'remote_subscription_id' => null, |
|
| 87 | + 'is_viewed' => false, |
|
| 88 | + 'email_cc' => '', |
|
| 89 | + 'template' => 'quantity', // hours, amount only |
|
| 90 | + 'created_via' => null, |
|
| 91 | 91 | ); |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | - * Stores meta in cache for future reads. |
|
| 95 | - * |
|
| 96 | - * A group must be set to to enable caching. |
|
| 97 | - * |
|
| 98 | - * @var string |
|
| 99 | - */ |
|
| 100 | - protected $cache_group = 'getpaid_invoices'; |
|
| 94 | + * Stores meta in cache for future reads. |
|
| 95 | + * |
|
| 96 | + * A group must be set to to enable caching. |
|
| 97 | + * |
|
| 98 | + * @var string |
|
| 99 | + */ |
|
| 100 | + protected $cache_group = 'getpaid_invoices'; |
|
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * Stores a reference to the original WP_Post object |
@@ -111,111 +111,111 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @var int |
| 113 | 113 | */ |
| 114 | - protected $recurring_item = null; |
|
| 114 | + protected $recurring_item = null; |
|
| 115 | 115 | |
| 116 | - /** |
|
| 116 | + /** |
|
| 117 | 117 | * Stores an array of item totals. |
| 118 | - * |
|
| 119 | - * e.g $totals['discount'] = array( |
|
| 120 | - * 'initial' => 10, |
|
| 121 | - * 'recurring' => 10, |
|
| 122 | - * ) |
|
| 118 | + * |
|
| 119 | + * e.g $totals['discount'] = array( |
|
| 120 | + * 'initial' => 10, |
|
| 121 | + * 'recurring' => 10, |
|
| 122 | + * ) |
|
| 123 | 123 | * |
| 124 | 124 | * @var array |
| 125 | 125 | */ |
| 126 | - protected $totals = array(); |
|
| 126 | + protected $totals = array(); |
|
| 127 | 127 | |
| 128 | - /** |
|
| 128 | + /** |
|
| 129 | 129 | * Tax rate. |
| 130 | - * |
|
| 130 | + * |
|
| 131 | 131 | * @var float |
| 132 | 132 | */ |
| 133 | - protected $tax_rate = 0; |
|
| 133 | + protected $tax_rate = 0; |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Stores the status transition information. |
|
| 137 | - * |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @var bool|array |
|
| 140 | - */ |
|
| 141 | - protected $status_transition = false; |
|
| 135 | + /** |
|
| 136 | + * Stores the status transition information. |
|
| 137 | + * |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @var bool|array |
|
| 140 | + */ |
|
| 141 | + protected $status_transition = false; |
|
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 145 | - * |
|
| 146 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 147 | - */ |
|
| 144 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 145 | + * |
|
| 146 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 147 | + */ |
|
| 148 | 148 | public function __construct( $invoice = 0 ) { |
| 149 | 149 | |
| 150 | 150 | parent::__construct( $invoice ); |
| 151 | 151 | |
| 152 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 153 | - $this->set_id( (int) $invoice ); |
|
| 154 | - } elseif ( $invoice instanceof self ) { |
|
| 155 | - $this->set_id( $invoice->get_id() ); |
|
| 156 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
| 157 | - $this->set_id( $invoice->ID ); |
|
| 158 | - } elseif ( is_array( $invoice ) ) { |
|
| 159 | - $this->set_props( $invoice ); |
|
| 160 | - |
|
| 161 | - if ( isset( $invoice['ID'] ) ) { |
|
| 162 | - $this->set_id( $invoice['ID'] ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 166 | - $this->set_id( $invoice_id ); |
|
| 167 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 168 | - $this->set_id( $invoice_id ); |
|
| 169 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 170 | - $this->set_id( $invoice_id ); |
|
| 171 | - } else { |
|
| 172 | - $this->set_object_read( true ); |
|
| 173 | - } |
|
| 152 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 153 | + $this->set_id( (int) $invoice ); |
|
| 154 | + } elseif ( $invoice instanceof self ) { |
|
| 155 | + $this->set_id( $invoice->get_id() ); |
|
| 156 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
| 157 | + $this->set_id( $invoice->ID ); |
|
| 158 | + } elseif ( is_array( $invoice ) ) { |
|
| 159 | + $this->set_props( $invoice ); |
|
| 160 | + |
|
| 161 | + if ( isset( $invoice['ID'] ) ) { |
|
| 162 | + $this->set_id( $invoice['ID'] ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 166 | + $this->set_id( $invoice_id ); |
|
| 167 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 168 | + $this->set_id( $invoice_id ); |
|
| 169 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 170 | + $this->set_id( $invoice_id ); |
|
| 171 | + } else { |
|
| 172 | + $this->set_object_read( true ); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | // Load the datastore. |
| 176 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 176 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 177 | 177 | |
| 178 | - if ( $this->get_id() > 0 ) { |
|
| 178 | + if ( $this->get_id() > 0 ) { |
|
| 179 | 179 | $this->post = get_post( $this->get_id() ); |
| 180 | 180 | $this->ID = $this->get_id(); |
| 181 | - $this->data_store->read( $this ); |
|
| 181 | + $this->data_store->read( $this ); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
| 187 | - * Given an invoice key/number, it returns its id. |
|
| 188 | - * |
|
| 189 | - * |
|
| 190 | - * @static |
|
| 191 | - * @param string $value The invoice key or number |
|
| 192 | - * @param string $field Either key, transaction_id or number. |
|
| 193 | - * @since 1.0.15 |
|
| 194 | - * @return int |
|
| 195 | - */ |
|
| 196 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 187 | + * Given an invoice key/number, it returns its id. |
|
| 188 | + * |
|
| 189 | + * |
|
| 190 | + * @static |
|
| 191 | + * @param string $value The invoice key or number |
|
| 192 | + * @param string $field Either key, transaction_id or number. |
|
| 193 | + * @since 1.0.15 |
|
| 194 | + * @return int |
|
| 195 | + */ |
|
| 196 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 197 | 197 | global $wpdb; |
| 198 | 198 | |
| 199 | - // Trim the value. |
|
| 200 | - $value = trim( $value ); |
|
| 199 | + // Trim the value. |
|
| 200 | + $value = trim( $value ); |
|
| 201 | 201 | |
| 202 | - if ( empty( $value ) ) { |
|
| 203 | - return 0; |
|
| 204 | - } |
|
| 202 | + if ( empty( $value ) ) { |
|
| 203 | + return 0; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | 206 | // Valid fields. |
| 207 | 207 | $fields = array( 'key', 'number', 'transaction_id' ); |
| 208 | 208 | |
| 209 | - // Ensure a field has been passed. |
|
| 210 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 211 | - return 0; |
|
| 212 | - } |
|
| 209 | + // Ensure a field has been passed. |
|
| 210 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 211 | + return 0; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - // Maybe retrieve from the cache. |
|
| 215 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 216 | - if ( false !== $invoice_id ) { |
|
| 217 | - return $invoice_id; |
|
| 218 | - } |
|
| 214 | + // Maybe retrieve from the cache. |
|
| 215 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 216 | + if ( false !== $invoice_id ) { |
|
| 217 | + return $invoice_id; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | 220 | // Fetch from the db. |
| 221 | 221 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 224 | 224 | ); |
| 225 | 225 | |
| 226 | - // Update the cache with our data |
|
| 227 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 226 | + // Update the cache with our data |
|
| 227 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 228 | 228 | |
| 229 | - return $invoice_id; |
|
| 229 | + return $invoice_id; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -252,83 +252,83 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | |
| 254 | 254 | /** |
| 255 | - * Get parent invoice ID. |
|
| 256 | - * |
|
| 257 | - * @since 1.0.19 |
|
| 258 | - * @param string $context View or edit context. |
|
| 259 | - * @return int |
|
| 260 | - */ |
|
| 261 | - public function get_parent_id( $context = 'view' ) { |
|
| 262 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 255 | + * Get parent invoice ID. |
|
| 256 | + * |
|
| 257 | + * @since 1.0.19 |
|
| 258 | + * @param string $context View or edit context. |
|
| 259 | + * @return int |
|
| 260 | + */ |
|
| 261 | + public function get_parent_id( $context = 'view' ) { |
|
| 262 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | - * Get parent invoice. |
|
| 267 | - * |
|
| 268 | - * @since 1.0.19 |
|
| 269 | - * @return WPInv_Invoice |
|
| 270 | - */ |
|
| 266 | + * Get parent invoice. |
|
| 267 | + * |
|
| 268 | + * @since 1.0.19 |
|
| 269 | + * @return WPInv_Invoice |
|
| 270 | + */ |
|
| 271 | 271 | public function get_parent_payment() { |
| 272 | 272 | return new WPInv_Invoice( $this->get_parent_id() ); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
| 276 | - * Alias for self::get_parent_payment(). |
|
| 277 | - * |
|
| 278 | - * @since 1.0.19 |
|
| 279 | - * @return WPInv_Invoice |
|
| 280 | - */ |
|
| 276 | + * Alias for self::get_parent_payment(). |
|
| 277 | + * |
|
| 278 | + * @since 1.0.19 |
|
| 279 | + * @return WPInv_Invoice |
|
| 280 | + */ |
|
| 281 | 281 | public function get_parent() { |
| 282 | 282 | return $this->get_parent_payment(); |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
| 286 | - * Get invoice status. |
|
| 287 | - * |
|
| 288 | - * @since 1.0.19 |
|
| 289 | - * @param string $context View or edit context. |
|
| 290 | - * @return string |
|
| 291 | - */ |
|
| 292 | - public function get_status( $context = 'view' ) { |
|
| 293 | - return $this->get_prop( 'status', $context ); |
|
| 294 | - } |
|
| 286 | + * Get invoice status. |
|
| 287 | + * |
|
| 288 | + * @since 1.0.19 |
|
| 289 | + * @param string $context View or edit context. |
|
| 290 | + * @return string |
|
| 291 | + */ |
|
| 292 | + public function get_status( $context = 'view' ) { |
|
| 293 | + return $this->get_prop( 'status', $context ); |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - /** |
|
| 297 | - * Retrieves an array of possible invoice statuses. |
|
| 298 | - * |
|
| 299 | - * @since 1.0.19 |
|
| 300 | - * @return array |
|
| 301 | - */ |
|
| 302 | - public function get_all_statuses() { |
|
| 303 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Get invoice status nice name. |
|
| 308 | - * |
|
| 309 | - * @since 1.0.19 |
|
| 310 | - * @return string |
|
| 311 | - */ |
|
| 296 | + /** |
|
| 297 | + * Retrieves an array of possible invoice statuses. |
|
| 298 | + * |
|
| 299 | + * @since 1.0.19 |
|
| 300 | + * @return array |
|
| 301 | + */ |
|
| 302 | + public function get_all_statuses() { |
|
| 303 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Get invoice status nice name. |
|
| 308 | + * |
|
| 309 | + * @since 1.0.19 |
|
| 310 | + * @return string |
|
| 311 | + */ |
|
| 312 | 312 | public function get_status_nicename() { |
| 313 | - $statuses = $this->get_all_statuses(); |
|
| 313 | + $statuses = $this->get_all_statuses(); |
|
| 314 | 314 | |
| 315 | 315 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
| 316 | 316 | |
| 317 | 317 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * Retrieves the invoice status class |
|
| 322 | - * |
|
| 323 | - * @since 1.0.19 |
|
| 324 | - * @return string |
|
| 325 | - */ |
|
| 326 | - public function get_status_class() { |
|
| 327 | - $statuses = getpaid_get_invoice_status_classes(); |
|
| 328 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 329 | - } |
|
| 320 | + /** |
|
| 321 | + * Retrieves the invoice status class |
|
| 322 | + * |
|
| 323 | + * @since 1.0.19 |
|
| 324 | + * @return string |
|
| 325 | + */ |
|
| 326 | + public function get_status_class() { |
|
| 327 | + $statuses = getpaid_get_invoice_status_classes(); |
|
| 328 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - /** |
|
| 331 | + /** |
|
| 332 | 332 | * Retrieves the invoice status label html |
| 333 | 333 | * |
| 334 | 334 | * @since 1.0.0 |
@@ -336,263 +336,263 @@ discard block |
||
| 336 | 336 | */ |
| 337 | 337 | public function get_status_label_html() { |
| 338 | 338 | |
| 339 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 340 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 341 | - $class = esc_attr( $this->get_status_class() ); |
|
| 339 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 340 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 341 | + $class = esc_attr( $this->get_status_class() ); |
|
| 342 | 342 | |
| 343 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 344 | - } |
|
| 343 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | 346 | /** |
| 347 | - * Get plugin version when the invoice was created. |
|
| 348 | - * |
|
| 349 | - * @since 1.0.19 |
|
| 350 | - * @param string $context View or edit context. |
|
| 351 | - * @return string |
|
| 352 | - */ |
|
| 353 | - public function get_version( $context = 'view' ) { |
|
| 354 | - return $this->get_prop( 'version', $context ); |
|
| 355 | - } |
|
| 347 | + * Get plugin version when the invoice was created. |
|
| 348 | + * |
|
| 349 | + * @since 1.0.19 |
|
| 350 | + * @param string $context View or edit context. |
|
| 351 | + * @return string |
|
| 352 | + */ |
|
| 353 | + public function get_version( $context = 'view' ) { |
|
| 354 | + return $this->get_prop( 'version', $context ); |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * @deprecated |
|
| 359 | - */ |
|
| 360 | - public function get_invoice_date( $format = true ) { |
|
| 361 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 362 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 363 | - $formatted = getpaid_format_date( $date ); |
|
| 357 | + /** |
|
| 358 | + * @deprecated |
|
| 359 | + */ |
|
| 360 | + public function get_invoice_date( $format = true ) { |
|
| 361 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 362 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 363 | + $formatted = getpaid_format_date( $date ); |
|
| 364 | 364 | |
| 365 | - if ( $format ) { |
|
| 366 | - return $formatted; |
|
| 367 | - } |
|
| 365 | + if ( $format ) { |
|
| 366 | + return $formatted; |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | - return empty( $formatted ) ? '' : $date; |
|
| 369 | + return empty( $formatted ) ? '' : $date; |
|
| 370 | 370 | |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
| 374 | - * Get date when the invoice was created. |
|
| 375 | - * |
|
| 376 | - * @since 1.0.19 |
|
| 377 | - * @param string $context View or edit context. |
|
| 378 | - * @return string |
|
| 379 | - */ |
|
| 380 | - public function get_date_created( $context = 'view' ) { |
|
| 381 | - return $this->get_prop( 'date_created', $context ); |
|
| 382 | - } |
|
| 374 | + * Get date when the invoice was created. |
|
| 375 | + * |
|
| 376 | + * @since 1.0.19 |
|
| 377 | + * @param string $context View or edit context. |
|
| 378 | + * @return string |
|
| 379 | + */ |
|
| 380 | + public function get_date_created( $context = 'view' ) { |
|
| 381 | + return $this->get_prop( 'date_created', $context ); |
|
| 382 | + } |
|
| 383 | 383 | |
| 384 | - /** |
|
| 385 | - * Alias for self::get_date_created(). |
|
| 386 | - * |
|
| 387 | - * @since 1.0.19 |
|
| 388 | - * @param string $context View or edit context. |
|
| 389 | - * @return string |
|
| 390 | - */ |
|
| 391 | - public function get_created_date( $context = 'view' ) { |
|
| 392 | - return $this->get_date_created( $context ); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Get GMT date when the invoice was created. |
|
| 397 | - * |
|
| 398 | - * @since 1.0.19 |
|
| 399 | - * @param string $context View or edit context. |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 384 | + /** |
|
| 385 | + * Alias for self::get_date_created(). |
|
| 386 | + * |
|
| 387 | + * @since 1.0.19 |
|
| 388 | + * @param string $context View or edit context. |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 391 | + public function get_created_date( $context = 'view' ) { |
|
| 392 | + return $this->get_date_created( $context ); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Get GMT date when the invoice was created. |
|
| 397 | + * |
|
| 398 | + * @since 1.0.19 |
|
| 399 | + * @param string $context View or edit context. |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 403 | 403 | $date = $this->get_date_created( $context ); |
| 404 | 404 | |
| 405 | 405 | if ( $date ) { |
| 406 | 406 | $date = get_gmt_from_date( $date ); |
| 407 | 407 | } |
| 408 | - return $date; |
|
| 408 | + return $date; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
| 412 | - * Get date when the invoice was last modified. |
|
| 413 | - * |
|
| 414 | - * @since 1.0.19 |
|
| 415 | - * @param string $context View or edit context. |
|
| 416 | - * @return string |
|
| 417 | - */ |
|
| 418 | - public function get_date_modified( $context = 'view' ) { |
|
| 419 | - return $this->get_prop( 'date_modified', $context ); |
|
| 420 | - } |
|
| 412 | + * Get date when the invoice was last modified. |
|
| 413 | + * |
|
| 414 | + * @since 1.0.19 |
|
| 415 | + * @param string $context View or edit context. |
|
| 416 | + * @return string |
|
| 417 | + */ |
|
| 418 | + public function get_date_modified( $context = 'view' ) { |
|
| 419 | + return $this->get_prop( 'date_modified', $context ); |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - /** |
|
| 423 | - * Alias for self::get_date_modified(). |
|
| 424 | - * |
|
| 425 | - * @since 1.0.19 |
|
| 426 | - * @param string $context View or edit context. |
|
| 427 | - * @return string |
|
| 428 | - */ |
|
| 429 | - public function get_modified_date( $context = 'view' ) { |
|
| 430 | - return $this->get_date_modified( $context ); |
|
| 422 | + /** |
|
| 423 | + * Alias for self::get_date_modified(). |
|
| 424 | + * |
|
| 425 | + * @since 1.0.19 |
|
| 426 | + * @param string $context View or edit context. |
|
| 427 | + * @return string |
|
| 428 | + */ |
|
| 429 | + public function get_modified_date( $context = 'view' ) { |
|
| 430 | + return $this->get_date_modified( $context ); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
| 434 | - * Get GMT date when the invoice was last modified. |
|
| 435 | - * |
|
| 436 | - * @since 1.0.19 |
|
| 437 | - * @param string $context View or edit context. |
|
| 438 | - * @return string |
|
| 439 | - */ |
|
| 440 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 434 | + * Get GMT date when the invoice was last modified. |
|
| 435 | + * |
|
| 436 | + * @since 1.0.19 |
|
| 437 | + * @param string $context View or edit context. |
|
| 438 | + * @return string |
|
| 439 | + */ |
|
| 440 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 441 | 441 | $date = $this->get_date_modified( $context ); |
| 442 | 442 | |
| 443 | 443 | if ( $date ) { |
| 444 | 444 | $date = get_gmt_from_date( $date ); |
| 445 | 445 | } |
| 446 | - return $date; |
|
| 446 | + return $date; |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
| 450 | - * Get the invoice due date. |
|
| 451 | - * |
|
| 452 | - * @since 1.0.19 |
|
| 453 | - * @param string $context View or edit context. |
|
| 454 | - * @return string |
|
| 455 | - */ |
|
| 456 | - public function get_due_date( $context = 'view' ) { |
|
| 457 | - return $this->get_prop( 'due_date', $context ); |
|
| 450 | + * Get the invoice due date. |
|
| 451 | + * |
|
| 452 | + * @since 1.0.19 |
|
| 453 | + * @param string $context View or edit context. |
|
| 454 | + * @return string |
|
| 455 | + */ |
|
| 456 | + public function get_due_date( $context = 'view' ) { |
|
| 457 | + return $this->get_prop( 'due_date', $context ); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
| 461 | - * Alias for self::get_due_date(). |
|
| 462 | - * |
|
| 463 | - * @since 1.0.19 |
|
| 464 | - * @param string $context View or edit context. |
|
| 465 | - * @return string |
|
| 466 | - */ |
|
| 467 | - public function get_date_due( $context = 'view' ) { |
|
| 468 | - return $this->get_due_date( $context ); |
|
| 461 | + * Alias for self::get_due_date(). |
|
| 462 | + * |
|
| 463 | + * @since 1.0.19 |
|
| 464 | + * @param string $context View or edit context. |
|
| 465 | + * @return string |
|
| 466 | + */ |
|
| 467 | + public function get_date_due( $context = 'view' ) { |
|
| 468 | + return $this->get_due_date( $context ); |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | /** |
| 472 | - * Get the invoice GMT due date. |
|
| 473 | - * |
|
| 474 | - * @since 1.0.19 |
|
| 475 | - * @param string $context View or edit context. |
|
| 476 | - * @return string |
|
| 477 | - */ |
|
| 478 | - public function get_due_date_gmt( $context = 'view' ) { |
|
| 472 | + * Get the invoice GMT due date. |
|
| 473 | + * |
|
| 474 | + * @since 1.0.19 |
|
| 475 | + * @param string $context View or edit context. |
|
| 476 | + * @return string |
|
| 477 | + */ |
|
| 478 | + public function get_due_date_gmt( $context = 'view' ) { |
|
| 479 | 479 | $date = $this->get_due_date( $context ); |
| 480 | 480 | |
| 481 | 481 | if ( $date ) { |
| 482 | 482 | $date = get_gmt_from_date( $date ); |
| 483 | 483 | } |
| 484 | - return $date; |
|
| 484 | + return $date; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
| 488 | - * Alias for self::get_due_date_gmt(). |
|
| 489 | - * |
|
| 490 | - * @since 1.0.19 |
|
| 491 | - * @param string $context View or edit context. |
|
| 492 | - * @return string |
|
| 493 | - */ |
|
| 494 | - public function get_gmt_date_due( $context = 'view' ) { |
|
| 495 | - return $this->get_due_date_gmt( $context ); |
|
| 488 | + * Alias for self::get_due_date_gmt(). |
|
| 489 | + * |
|
| 490 | + * @since 1.0.19 |
|
| 491 | + * @param string $context View or edit context. |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 494 | + public function get_gmt_date_due( $context = 'view' ) { |
|
| 495 | + return $this->get_due_date_gmt( $context ); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | /** |
| 499 | - * Get date when the invoice was completed. |
|
| 500 | - * |
|
| 501 | - * @since 1.0.19 |
|
| 502 | - * @param string $context View or edit context. |
|
| 503 | - * @return string |
|
| 504 | - */ |
|
| 505 | - public function get_completed_date( $context = 'view' ) { |
|
| 506 | - return $this->get_prop( 'completed_date', $context ); |
|
| 499 | + * Get date when the invoice was completed. |
|
| 500 | + * |
|
| 501 | + * @since 1.0.19 |
|
| 502 | + * @param string $context View or edit context. |
|
| 503 | + * @return string |
|
| 504 | + */ |
|
| 505 | + public function get_completed_date( $context = 'view' ) { |
|
| 506 | + return $this->get_prop( 'completed_date', $context ); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | /** |
| 510 | - * Alias for self::get_completed_date(). |
|
| 511 | - * |
|
| 512 | - * @since 1.0.19 |
|
| 513 | - * @param string $context View or edit context. |
|
| 514 | - * @return string |
|
| 515 | - */ |
|
| 516 | - public function get_date_completed( $context = 'view' ) { |
|
| 517 | - return $this->get_completed_date( $context ); |
|
| 510 | + * Alias for self::get_completed_date(). |
|
| 511 | + * |
|
| 512 | + * @since 1.0.19 |
|
| 513 | + * @param string $context View or edit context. |
|
| 514 | + * @return string |
|
| 515 | + */ |
|
| 516 | + public function get_date_completed( $context = 'view' ) { |
|
| 517 | + return $this->get_completed_date( $context ); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
| 521 | - * Get GMT date when the invoice was was completed. |
|
| 522 | - * |
|
| 523 | - * @since 1.0.19 |
|
| 524 | - * @param string $context View or edit context. |
|
| 525 | - * @return string |
|
| 526 | - */ |
|
| 527 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
| 521 | + * Get GMT date when the invoice was was completed. |
|
| 522 | + * |
|
| 523 | + * @since 1.0.19 |
|
| 524 | + * @param string $context View or edit context. |
|
| 525 | + * @return string |
|
| 526 | + */ |
|
| 527 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
| 528 | 528 | $date = $this->get_completed_date( $context ); |
| 529 | 529 | |
| 530 | 530 | if ( $date ) { |
| 531 | 531 | $date = get_gmt_from_date( $date ); |
| 532 | 532 | } |
| 533 | - return $date; |
|
| 533 | + return $date; |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
| 537 | - * Alias for self::get_completed_date_gmt(). |
|
| 538 | - * |
|
| 539 | - * @since 1.0.19 |
|
| 540 | - * @param string $context View or edit context. |
|
| 541 | - * @return string |
|
| 542 | - */ |
|
| 543 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
| 544 | - return $this->get_completed_date_gmt( $context ); |
|
| 537 | + * Alias for self::get_completed_date_gmt(). |
|
| 538 | + * |
|
| 539 | + * @since 1.0.19 |
|
| 540 | + * @param string $context View or edit context. |
|
| 541 | + * @return string |
|
| 542 | + */ |
|
| 543 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
| 544 | + return $this->get_completed_date_gmt( $context ); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
| 548 | - * Get the invoice number. |
|
| 549 | - * |
|
| 550 | - * @since 1.0.19 |
|
| 551 | - * @param string $context View or edit context. |
|
| 552 | - * @return string |
|
| 553 | - */ |
|
| 554 | - public function get_number( $context = 'view' ) { |
|
| 555 | - $number = $this->get_prop( 'number', $context ); |
|
| 548 | + * Get the invoice number. |
|
| 549 | + * |
|
| 550 | + * @since 1.0.19 |
|
| 551 | + * @param string $context View or edit context. |
|
| 552 | + * @return string |
|
| 553 | + */ |
|
| 554 | + public function get_number( $context = 'view' ) { |
|
| 555 | + $number = $this->get_prop( 'number', $context ); |
|
| 556 | 556 | |
| 557 | - if ( empty( $number ) ) { |
|
| 558 | - $number = $this->generate_number(); |
|
| 559 | - $this->set_number( $this->generate_number() ); |
|
| 560 | - } |
|
| 557 | + if ( empty( $number ) ) { |
|
| 558 | + $number = $this->generate_number(); |
|
| 559 | + $this->set_number( $this->generate_number() ); |
|
| 560 | + } |
|
| 561 | 561 | |
| 562 | - return $number; |
|
| 562 | + return $number; |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - /** |
|
| 566 | - * Set the invoice number. |
|
| 567 | - * |
|
| 568 | - * @since 1.0.19 |
|
| 569 | - */ |
|
| 570 | - public function maybe_set_number() { |
|
| 565 | + /** |
|
| 566 | + * Set the invoice number. |
|
| 567 | + * |
|
| 568 | + * @since 1.0.19 |
|
| 569 | + */ |
|
| 570 | + public function maybe_set_number() { |
|
| 571 | 571 | $number = $this->get_number(); |
| 572 | 572 | |
| 573 | 573 | if ( empty( $number ) || $this->get_id() == $number ) { |
| 574 | - $this->set_number( $this->generate_number() ); |
|
| 574 | + $this->set_number( $this->generate_number() ); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | - } |
|
| 577 | + } |
|
| 578 | 578 | |
| 579 | 579 | /** |
| 580 | - * Get the invoice key. |
|
| 581 | - * |
|
| 582 | - * @since 1.0.19 |
|
| 583 | - * @param string $context View or edit context. |
|
| 584 | - * @return string |
|
| 585 | - */ |
|
| 586 | - public function get_key( $context = 'view' ) { |
|
| 580 | + * Get the invoice key. |
|
| 581 | + * |
|
| 582 | + * @since 1.0.19 |
|
| 583 | + * @param string $context View or edit context. |
|
| 584 | + * @return string |
|
| 585 | + */ |
|
| 586 | + public function get_key( $context = 'view' ) { |
|
| 587 | 587 | return $this->get_prop( 'key', $context ); |
| 588 | - } |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * Set the invoice key. |
|
| 592 | - * |
|
| 593 | - * @since 1.0.19 |
|
| 594 | - */ |
|
| 595 | - public function maybe_set_key() { |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * Set the invoice key. |
|
| 592 | + * |
|
| 593 | + * @since 1.0.19 |
|
| 594 | + */ |
|
| 595 | + public function maybe_set_key() { |
|
| 596 | 596 | $key = $this->get_key(); |
| 597 | 597 | |
| 598 | 598 | if ( empty( $key ) ) { |
@@ -603,140 +603,140 @@ discard block |
||
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
| 606 | - * Get the invoice type. |
|
| 607 | - * |
|
| 608 | - * @since 1.0.19 |
|
| 609 | - * @param string $context View or edit context. |
|
| 610 | - * @return string |
|
| 611 | - */ |
|
| 612 | - public function get_type( $context = 'view' ) { |
|
| 606 | + * Get the invoice type. |
|
| 607 | + * |
|
| 608 | + * @since 1.0.19 |
|
| 609 | + * @param string $context View or edit context. |
|
| 610 | + * @return string |
|
| 611 | + */ |
|
| 612 | + public function get_type( $context = 'view' ) { |
|
| 613 | 613 | return $this->get_prop( 'type', $context ); |
| 614 | - } |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Returns the post type name. |
|
| 618 | - * |
|
| 619 | - * @since 1.0.19 |
|
| 620 | - * @return string |
|
| 621 | - */ |
|
| 622 | - public function get_invoice_quote_type() { |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Returns the post type name. |
|
| 618 | + * |
|
| 619 | + * @since 1.0.19 |
|
| 620 | + * @return string |
|
| 621 | + */ |
|
| 622 | + public function get_invoice_quote_type() { |
|
| 623 | 623 | return getpaid_get_post_type_label( $this->get_post_type(), false ); |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
| 627 | - * Get the invoice post type label. |
|
| 628 | - * |
|
| 629 | - * @since 1.0.19 |
|
| 630 | - * @param string $context View or edit context. |
|
| 631 | - * @return string |
|
| 632 | - */ |
|
| 633 | - public function get_label( $context = 'view' ) { |
|
| 627 | + * Get the invoice post type label. |
|
| 628 | + * |
|
| 629 | + * @since 1.0.19 |
|
| 630 | + * @param string $context View or edit context. |
|
| 631 | + * @return string |
|
| 632 | + */ |
|
| 633 | + public function get_label( $context = 'view' ) { |
|
| 634 | 634 | return getpaid_get_post_type_label( $this->get_post_type( $context ), false ); |
| 635 | - } |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * Get the invoice post type. |
|
| 639 | - * |
|
| 640 | - * @since 1.0.19 |
|
| 641 | - * @param string $context View or edit context. |
|
| 642 | - * @return string |
|
| 643 | - */ |
|
| 644 | - public function get_post_type( $context = 'view' ) { |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * Get the invoice post type. |
|
| 639 | + * |
|
| 640 | + * @since 1.0.19 |
|
| 641 | + * @param string $context View or edit context. |
|
| 642 | + * @return string |
|
| 643 | + */ |
|
| 644 | + public function get_post_type( $context = 'view' ) { |
|
| 645 | 645 | return $this->get_prop( 'post_type', $context ); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | /** |
| 649 | - * Get the invoice mode. |
|
| 650 | - * |
|
| 651 | - * @since 1.0.19 |
|
| 652 | - * @param string $context View or edit context. |
|
| 653 | - * @return string |
|
| 654 | - */ |
|
| 655 | - public function get_mode( $context = 'view' ) { |
|
| 649 | + * Get the invoice mode. |
|
| 650 | + * |
|
| 651 | + * @since 1.0.19 |
|
| 652 | + * @param string $context View or edit context. |
|
| 653 | + * @return string |
|
| 654 | + */ |
|
| 655 | + public function get_mode( $context = 'view' ) { |
|
| 656 | 656 | return $this->get_prop( 'mode', $context ); |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | /** |
| 660 | - * Get the invoice path. |
|
| 661 | - * |
|
| 662 | - * @since 1.0.19 |
|
| 663 | - * @param string $context View or edit context. |
|
| 664 | - * @return string |
|
| 665 | - */ |
|
| 666 | - public function get_path( $context = 'view' ) { |
|
| 660 | + * Get the invoice path. |
|
| 661 | + * |
|
| 662 | + * @since 1.0.19 |
|
| 663 | + * @param string $context View or edit context. |
|
| 664 | + * @return string |
|
| 665 | + */ |
|
| 666 | + public function get_path( $context = 'view' ) { |
|
| 667 | 667 | $path = $this->get_prop( 'path', $context ); |
| 668 | - $prefix = $this->get_type(); |
|
| 668 | + $prefix = $this->get_type(); |
|
| 669 | 669 | |
| 670 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 671 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 672 | - $this->set_path( $path ); |
|
| 673 | - } |
|
| 670 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 671 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 672 | + $this->set_path( $path ); |
|
| 673 | + } |
|
| 674 | 674 | |
| 675 | - return $path; |
|
| 675 | + return $path; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
| 679 | - * Get the invoice name/title. |
|
| 680 | - * |
|
| 681 | - * @since 1.0.19 |
|
| 682 | - * @param string $context View or edit context. |
|
| 683 | - * @return string |
|
| 684 | - */ |
|
| 685 | - public function get_name( $context = 'view' ) { |
|
| 679 | + * Get the invoice name/title. |
|
| 680 | + * |
|
| 681 | + * @since 1.0.19 |
|
| 682 | + * @param string $context View or edit context. |
|
| 683 | + * @return string |
|
| 684 | + */ |
|
| 685 | + public function get_name( $context = 'view' ) { |
|
| 686 | 686 | return $this->get_prop( 'title', $context ); |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | /** |
| 690 | - * Alias of self::get_name(). |
|
| 691 | - * |
|
| 692 | - * @since 1.0.19 |
|
| 693 | - * @param string $context View or edit context. |
|
| 694 | - * @return string |
|
| 695 | - */ |
|
| 696 | - public function get_title( $context = 'view' ) { |
|
| 697 | - return $this->get_name( $context ); |
|
| 690 | + * Alias of self::get_name(). |
|
| 691 | + * |
|
| 692 | + * @since 1.0.19 |
|
| 693 | + * @param string $context View or edit context. |
|
| 694 | + * @return string |
|
| 695 | + */ |
|
| 696 | + public function get_title( $context = 'view' ) { |
|
| 697 | + return $this->get_name( $context ); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
| 701 | - * Get the invoice description. |
|
| 702 | - * |
|
| 703 | - * @since 1.0.19 |
|
| 704 | - * @param string $context View or edit context. |
|
| 705 | - * @return string |
|
| 706 | - */ |
|
| 707 | - public function get_description( $context = 'view' ) { |
|
| 708 | - return $this->get_prop( 'description', $context ); |
|
| 701 | + * Get the invoice description. |
|
| 702 | + * |
|
| 703 | + * @since 1.0.19 |
|
| 704 | + * @param string $context View or edit context. |
|
| 705 | + * @return string |
|
| 706 | + */ |
|
| 707 | + public function get_description( $context = 'view' ) { |
|
| 708 | + return $this->get_prop( 'description', $context ); |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
| 712 | - * Alias of self::get_description(). |
|
| 713 | - * |
|
| 714 | - * @since 1.0.19 |
|
| 715 | - * @param string $context View or edit context. |
|
| 716 | - * @return string |
|
| 717 | - */ |
|
| 718 | - public function get_excerpt( $context = 'view' ) { |
|
| 719 | - return $this->get_description( $context ); |
|
| 712 | + * Alias of self::get_description(). |
|
| 713 | + * |
|
| 714 | + * @since 1.0.19 |
|
| 715 | + * @param string $context View or edit context. |
|
| 716 | + * @return string |
|
| 717 | + */ |
|
| 718 | + public function get_excerpt( $context = 'view' ) { |
|
| 719 | + return $this->get_description( $context ); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | /** |
| 723 | - * Alias of self::get_description(). |
|
| 724 | - * |
|
| 725 | - * @since 1.0.19 |
|
| 726 | - * @param string $context View or edit context. |
|
| 727 | - * @return string |
|
| 728 | - */ |
|
| 729 | - public function get_summary( $context = 'view' ) { |
|
| 730 | - return $this->get_description( $context ); |
|
| 723 | + * Alias of self::get_description(). |
|
| 724 | + * |
|
| 725 | + * @since 1.0.19 |
|
| 726 | + * @param string $context View or edit context. |
|
| 727 | + * @return string |
|
| 728 | + */ |
|
| 729 | + public function get_summary( $context = 'view' ) { |
|
| 730 | + return $this->get_description( $context ); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
| 734 | - * Returns the user info. |
|
| 735 | - * |
|
| 736 | - * @since 1.0.19 |
|
| 734 | + * Returns the user info. |
|
| 735 | + * |
|
| 736 | + * @since 1.0.19 |
|
| 737 | 737 | * @param string $context View or edit context. |
| 738 | - * @return array |
|
| 739 | - */ |
|
| 738 | + * @return array |
|
| 739 | + */ |
|
| 740 | 740 | public function get_user_info( $context = 'view' ) { |
| 741 | 741 | |
| 742 | 742 | $user_info = array( |
@@ -751,683 +751,683 @@ discard block |
||
| 751 | 751 | 'state' => $this->get_state( $context ), |
| 752 | 752 | 'zip' => $this->get_zip( $context ), |
| 753 | 753 | 'company' => $this->get_company( $context ), |
| 754 | - 'company_id' => $this->get_company_id( $context ), |
|
| 754 | + 'company_id' => $this->get_company_id( $context ), |
|
| 755 | 755 | 'vat_number' => $this->get_vat_number( $context ), |
| 756 | 756 | 'discount' => $this->get_discount_code( $context ), |
| 757 | - ); |
|
| 757 | + ); |
|
| 758 | 758 | |
| 759 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 759 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 760 | 760 | |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
| 764 | - * Get the customer id. |
|
| 765 | - * |
|
| 766 | - * @since 1.0.19 |
|
| 767 | - * @param string $context View or edit context. |
|
| 768 | - * @return int |
|
| 769 | - */ |
|
| 770 | - public function get_author( $context = 'view' ) { |
|
| 771 | - return (int) $this->get_prop( 'author', $context ); |
|
| 764 | + * Get the customer id. |
|
| 765 | + * |
|
| 766 | + * @since 1.0.19 |
|
| 767 | + * @param string $context View or edit context. |
|
| 768 | + * @return int |
|
| 769 | + */ |
|
| 770 | + public function get_author( $context = 'view' ) { |
|
| 771 | + return (int) $this->get_prop( 'author', $context ); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | /** |
| 775 | - * Alias of self::get_author(). |
|
| 776 | - * |
|
| 777 | - * @since 1.0.19 |
|
| 778 | - * @param string $context View or edit context. |
|
| 779 | - * @return int |
|
| 780 | - */ |
|
| 781 | - public function get_user_id( $context = 'view' ) { |
|
| 782 | - return $this->get_author( $context ); |
|
| 775 | + * Alias of self::get_author(). |
|
| 776 | + * |
|
| 777 | + * @since 1.0.19 |
|
| 778 | + * @param string $context View or edit context. |
|
| 779 | + * @return int |
|
| 780 | + */ |
|
| 781 | + public function get_user_id( $context = 'view' ) { |
|
| 782 | + return $this->get_author( $context ); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | - /** |
|
| 786 | - * Alias of self::get_author(). |
|
| 787 | - * |
|
| 788 | - * @since 1.0.19 |
|
| 789 | - * @param string $context View or edit context. |
|
| 790 | - * @return int |
|
| 791 | - */ |
|
| 792 | - public function get_customer_id( $context = 'view' ) { |
|
| 793 | - return $this->get_author( $context ); |
|
| 785 | + /** |
|
| 786 | + * Alias of self::get_author(). |
|
| 787 | + * |
|
| 788 | + * @since 1.0.19 |
|
| 789 | + * @param string $context View or edit context. |
|
| 790 | + * @return int |
|
| 791 | + */ |
|
| 792 | + public function get_customer_id( $context = 'view' ) { |
|
| 793 | + return $this->get_author( $context ); |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | /** |
| 797 | - * Get the customer's ip. |
|
| 798 | - * |
|
| 799 | - * @since 1.0.19 |
|
| 800 | - * @param string $context View or edit context. |
|
| 801 | - * @return string |
|
| 802 | - */ |
|
| 803 | - public function get_ip( $context = 'view' ) { |
|
| 804 | - return $this->get_prop( 'user_ip', $context ); |
|
| 797 | + * Get the customer's ip. |
|
| 798 | + * |
|
| 799 | + * @since 1.0.19 |
|
| 800 | + * @param string $context View or edit context. |
|
| 801 | + * @return string |
|
| 802 | + */ |
|
| 803 | + public function get_ip( $context = 'view' ) { |
|
| 804 | + return $this->get_prop( 'user_ip', $context ); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | /** |
| 808 | - * Alias of self::get_ip(). |
|
| 809 | - * |
|
| 810 | - * @since 1.0.19 |
|
| 811 | - * @param string $context View or edit context. |
|
| 812 | - * @return string |
|
| 813 | - */ |
|
| 814 | - public function get_user_ip( $context = 'view' ) { |
|
| 815 | - return $this->get_ip( $context ); |
|
| 808 | + * Alias of self::get_ip(). |
|
| 809 | + * |
|
| 810 | + * @since 1.0.19 |
|
| 811 | + * @param string $context View or edit context. |
|
| 812 | + * @return string |
|
| 813 | + */ |
|
| 814 | + public function get_user_ip( $context = 'view' ) { |
|
| 815 | + return $this->get_ip( $context ); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | - /** |
|
| 819 | - * Alias of self::get_ip(). |
|
| 820 | - * |
|
| 821 | - * @since 1.0.19 |
|
| 822 | - * @param string $context View or edit context. |
|
| 823 | - * @return string |
|
| 824 | - */ |
|
| 825 | - public function get_customer_ip( $context = 'view' ) { |
|
| 826 | - return $this->get_ip( $context ); |
|
| 818 | + /** |
|
| 819 | + * Alias of self::get_ip(). |
|
| 820 | + * |
|
| 821 | + * @since 1.0.19 |
|
| 822 | + * @param string $context View or edit context. |
|
| 823 | + * @return string |
|
| 824 | + */ |
|
| 825 | + public function get_customer_ip( $context = 'view' ) { |
|
| 826 | + return $this->get_ip( $context ); |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | /** |
| 830 | - * Get the customer's first name. |
|
| 831 | - * |
|
| 832 | - * @since 1.0.19 |
|
| 833 | - * @param string $context View or edit context. |
|
| 834 | - * @return string |
|
| 835 | - */ |
|
| 836 | - public function get_first_name( $context = 'view' ) { |
|
| 837 | - return $this->get_prop( 'first_name', $context ); |
|
| 830 | + * Get the customer's first name. |
|
| 831 | + * |
|
| 832 | + * @since 1.0.19 |
|
| 833 | + * @param string $context View or edit context. |
|
| 834 | + * @return string |
|
| 835 | + */ |
|
| 836 | + public function get_first_name( $context = 'view' ) { |
|
| 837 | + return $this->get_prop( 'first_name', $context ); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | /** |
| 841 | - * Alias of self::get_first_name(). |
|
| 842 | - * |
|
| 843 | - * @since 1.0.19 |
|
| 844 | - * @param string $context View or edit context. |
|
| 845 | - * @return string |
|
| 846 | - */ |
|
| 847 | - public function get_user_first_name( $context = 'view' ) { |
|
| 848 | - return $this->get_first_name( $context ); |
|
| 841 | + * Alias of self::get_first_name(). |
|
| 842 | + * |
|
| 843 | + * @since 1.0.19 |
|
| 844 | + * @param string $context View or edit context. |
|
| 845 | + * @return string |
|
| 846 | + */ |
|
| 847 | + public function get_user_first_name( $context = 'view' ) { |
|
| 848 | + return $this->get_first_name( $context ); |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | - /** |
|
| 852 | - * Alias of self::get_first_name(). |
|
| 853 | - * |
|
| 854 | - * @since 1.0.19 |
|
| 855 | - * @param string $context View or edit context. |
|
| 856 | - * @return string |
|
| 857 | - */ |
|
| 858 | - public function get_customer_first_name( $context = 'view' ) { |
|
| 859 | - return $this->get_first_name( $context ); |
|
| 851 | + /** |
|
| 852 | + * Alias of self::get_first_name(). |
|
| 853 | + * |
|
| 854 | + * @since 1.0.19 |
|
| 855 | + * @param string $context View or edit context. |
|
| 856 | + * @return string |
|
| 857 | + */ |
|
| 858 | + public function get_customer_first_name( $context = 'view' ) { |
|
| 859 | + return $this->get_first_name( $context ); |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | /** |
| 863 | - * Get the customer's last name. |
|
| 864 | - * |
|
| 865 | - * @since 1.0.19 |
|
| 866 | - * @param string $context View or edit context. |
|
| 867 | - * @return string |
|
| 868 | - */ |
|
| 869 | - public function get_last_name( $context = 'view' ) { |
|
| 870 | - return $this->get_prop( 'last_name', $context ); |
|
| 863 | + * Get the customer's last name. |
|
| 864 | + * |
|
| 865 | + * @since 1.0.19 |
|
| 866 | + * @param string $context View or edit context. |
|
| 867 | + * @return string |
|
| 868 | + */ |
|
| 869 | + public function get_last_name( $context = 'view' ) { |
|
| 870 | + return $this->get_prop( 'last_name', $context ); |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | /** |
| 874 | - * Alias of self::get_last_name(). |
|
| 875 | - * |
|
| 876 | - * @since 1.0.19 |
|
| 877 | - * @param string $context View or edit context. |
|
| 878 | - * @return string |
|
| 879 | - */ |
|
| 880 | - public function get_user_last_name( $context = 'view' ) { |
|
| 881 | - return $this->get_last_name( $context ); |
|
| 874 | + * Alias of self::get_last_name(). |
|
| 875 | + * |
|
| 876 | + * @since 1.0.19 |
|
| 877 | + * @param string $context View or edit context. |
|
| 878 | + * @return string |
|
| 879 | + */ |
|
| 880 | + public function get_user_last_name( $context = 'view' ) { |
|
| 881 | + return $this->get_last_name( $context ); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | /** |
| 885 | - * Alias of self::get_last_name(). |
|
| 886 | - * |
|
| 887 | - * @since 1.0.19 |
|
| 888 | - * @param string $context View or edit context. |
|
| 889 | - * @return string |
|
| 890 | - */ |
|
| 891 | - public function get_customer_last_name( $context = 'view' ) { |
|
| 892 | - return $this->get_last_name( $context ); |
|
| 885 | + * Alias of self::get_last_name(). |
|
| 886 | + * |
|
| 887 | + * @since 1.0.19 |
|
| 888 | + * @param string $context View or edit context. |
|
| 889 | + * @return string |
|
| 890 | + */ |
|
| 891 | + public function get_customer_last_name( $context = 'view' ) { |
|
| 892 | + return $this->get_last_name( $context ); |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
| 896 | - * Get the customer's full name. |
|
| 897 | - * |
|
| 898 | - * @since 1.0.19 |
|
| 899 | - * @param string $context View or edit context. |
|
| 900 | - * @return string |
|
| 901 | - */ |
|
| 902 | - public function get_full_name( $context = 'view' ) { |
|
| 903 | - $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 896 | + * Get the customer's full name. |
|
| 897 | + * |
|
| 898 | + * @since 1.0.19 |
|
| 899 | + * @param string $context View or edit context. |
|
| 900 | + * @return string |
|
| 901 | + */ |
|
| 902 | + public function get_full_name( $context = 'view' ) { |
|
| 903 | + $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 904 | 904 | |
| 905 | - if ( ! $name ) { |
|
| 906 | - $user = get_userdata( $this->get_author( $context ) ); |
|
| 905 | + if ( ! $name ) { |
|
| 906 | + $user = get_userdata( $this->get_author( $context ) ); |
|
| 907 | 907 | |
| 908 | - if ( $user ) { |
|
| 909 | - $name = $user->display_name; |
|
| 910 | - } |
|
| 911 | - } |
|
| 908 | + if ( $user ) { |
|
| 909 | + $name = $user->display_name; |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | - if ( ! $name ) { |
|
| 914 | - $name = $this->get_email( $context ); |
|
| 915 | - } |
|
| 913 | + if ( ! $name ) { |
|
| 914 | + $name = $this->get_email( $context ); |
|
| 915 | + } |
|
| 916 | 916 | |
| 917 | - return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
| 917 | + return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | /** |
| 921 | - * Alias of self::get_full_name(). |
|
| 922 | - * |
|
| 923 | - * @since 1.0.19 |
|
| 924 | - * @param string $context View or edit context. |
|
| 925 | - * @return string |
|
| 926 | - */ |
|
| 927 | - public function get_user_full_name( $context = 'view' ) { |
|
| 928 | - return $this->get_full_name( $context ); |
|
| 921 | + * Alias of self::get_full_name(). |
|
| 922 | + * |
|
| 923 | + * @since 1.0.19 |
|
| 924 | + * @param string $context View or edit context. |
|
| 925 | + * @return string |
|
| 926 | + */ |
|
| 927 | + public function get_user_full_name( $context = 'view' ) { |
|
| 928 | + return $this->get_full_name( $context ); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | /** |
| 932 | - * Alias of self::get_full_name(). |
|
| 933 | - * |
|
| 934 | - * @since 1.0.19 |
|
| 935 | - * @param string $context View or edit context. |
|
| 936 | - * @return string |
|
| 937 | - */ |
|
| 938 | - public function get_customer_full_name( $context = 'view' ) { |
|
| 939 | - return $this->get_full_name( $context ); |
|
| 932 | + * Alias of self::get_full_name(). |
|
| 933 | + * |
|
| 934 | + * @since 1.0.19 |
|
| 935 | + * @param string $context View or edit context. |
|
| 936 | + * @return string |
|
| 937 | + */ |
|
| 938 | + public function get_customer_full_name( $context = 'view' ) { |
|
| 939 | + return $this->get_full_name( $context ); |
|
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | /** |
| 943 | - * Get the customer's phone number. |
|
| 944 | - * |
|
| 945 | - * @since 1.0.19 |
|
| 946 | - * @param string $context View or edit context. |
|
| 947 | - * @return string |
|
| 948 | - */ |
|
| 949 | - public function get_phone( $context = 'view' ) { |
|
| 950 | - return $this->get_prop( 'phone', $context ); |
|
| 943 | + * Get the customer's phone number. |
|
| 944 | + * |
|
| 945 | + * @since 1.0.19 |
|
| 946 | + * @param string $context View or edit context. |
|
| 947 | + * @return string |
|
| 948 | + */ |
|
| 949 | + public function get_phone( $context = 'view' ) { |
|
| 950 | + return $this->get_prop( 'phone', $context ); |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | /** |
| 954 | - * Alias of self::get_phone(). |
|
| 955 | - * |
|
| 956 | - * @since 1.0.19 |
|
| 957 | - * @param string $context View or edit context. |
|
| 958 | - * @return string |
|
| 959 | - */ |
|
| 960 | - public function get_phone_number( $context = 'view' ) { |
|
| 961 | - return $this->get_phone( $context ); |
|
| 954 | + * Alias of self::get_phone(). |
|
| 955 | + * |
|
| 956 | + * @since 1.0.19 |
|
| 957 | + * @param string $context View or edit context. |
|
| 958 | + * @return string |
|
| 959 | + */ |
|
| 960 | + public function get_phone_number( $context = 'view' ) { |
|
| 961 | + return $this->get_phone( $context ); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
| 965 | - * Alias of self::get_phone(). |
|
| 966 | - * |
|
| 967 | - * @since 1.0.19 |
|
| 968 | - * @param string $context View or edit context. |
|
| 969 | - * @return string |
|
| 970 | - */ |
|
| 971 | - public function get_user_phone( $context = 'view' ) { |
|
| 972 | - return $this->get_phone( $context ); |
|
| 965 | + * Alias of self::get_phone(). |
|
| 966 | + * |
|
| 967 | + * @since 1.0.19 |
|
| 968 | + * @param string $context View or edit context. |
|
| 969 | + * @return string |
|
| 970 | + */ |
|
| 971 | + public function get_user_phone( $context = 'view' ) { |
|
| 972 | + return $this->get_phone( $context ); |
|
| 973 | 973 | } |
| 974 | 974 | |
| 975 | 975 | /** |
| 976 | - * Alias of self::get_phone(). |
|
| 977 | - * |
|
| 978 | - * @since 1.0.19 |
|
| 979 | - * @param string $context View or edit context. |
|
| 980 | - * @return string |
|
| 981 | - */ |
|
| 982 | - public function get_customer_phone( $context = 'view' ) { |
|
| 983 | - return $this->get_phone( $context ); |
|
| 976 | + * Alias of self::get_phone(). |
|
| 977 | + * |
|
| 978 | + * @since 1.0.19 |
|
| 979 | + * @param string $context View or edit context. |
|
| 980 | + * @return string |
|
| 981 | + */ |
|
| 982 | + public function get_customer_phone( $context = 'view' ) { |
|
| 983 | + return $this->get_phone( $context ); |
|
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | /** |
| 987 | - * Get the customer's email address. |
|
| 988 | - * |
|
| 989 | - * @since 1.0.19 |
|
| 990 | - * @param string $context View or edit context. |
|
| 991 | - * @return string |
|
| 992 | - */ |
|
| 993 | - public function get_email( $context = 'view' ) { |
|
| 994 | - return $this->get_prop( 'email', $context ); |
|
| 987 | + * Get the customer's email address. |
|
| 988 | + * |
|
| 989 | + * @since 1.0.19 |
|
| 990 | + * @param string $context View or edit context. |
|
| 991 | + * @return string |
|
| 992 | + */ |
|
| 993 | + public function get_email( $context = 'view' ) { |
|
| 994 | + return $this->get_prop( 'email', $context ); |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | /** |
| 998 | - * Alias of self::get_email(). |
|
| 999 | - * |
|
| 1000 | - * @since 1.0.19 |
|
| 1001 | - * @param string $context View or edit context. |
|
| 1002 | - * @return string |
|
| 1003 | - */ |
|
| 1004 | - public function get_email_address( $context = 'view' ) { |
|
| 1005 | - return $this->get_email( $context ); |
|
| 998 | + * Alias of self::get_email(). |
|
| 999 | + * |
|
| 1000 | + * @since 1.0.19 |
|
| 1001 | + * @param string $context View or edit context. |
|
| 1002 | + * @return string |
|
| 1003 | + */ |
|
| 1004 | + public function get_email_address( $context = 'view' ) { |
|
| 1005 | + return $this->get_email( $context ); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
| 1009 | - * Alias of self::get_email(). |
|
| 1010 | - * |
|
| 1011 | - * @since 1.0.19 |
|
| 1012 | - * @param string $context View or edit context. |
|
| 1013 | - * @return string |
|
| 1014 | - */ |
|
| 1015 | - public function get_user_email( $context = 'view' ) { |
|
| 1016 | - return $this->get_email( $context ); |
|
| 1009 | + * Alias of self::get_email(). |
|
| 1010 | + * |
|
| 1011 | + * @since 1.0.19 |
|
| 1012 | + * @param string $context View or edit context. |
|
| 1013 | + * @return string |
|
| 1014 | + */ |
|
| 1015 | + public function get_user_email( $context = 'view' ) { |
|
| 1016 | + return $this->get_email( $context ); |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | /** |
| 1020 | - * Alias of self::get_email(). |
|
| 1021 | - * |
|
| 1022 | - * @since 1.0.19 |
|
| 1023 | - * @param string $context View or edit context. |
|
| 1024 | - * @return string |
|
| 1025 | - */ |
|
| 1026 | - public function get_customer_email( $context = 'view' ) { |
|
| 1027 | - return $this->get_email( $context ); |
|
| 1020 | + * Alias of self::get_email(). |
|
| 1021 | + * |
|
| 1022 | + * @since 1.0.19 |
|
| 1023 | + * @param string $context View or edit context. |
|
| 1024 | + * @return string |
|
| 1025 | + */ |
|
| 1026 | + public function get_customer_email( $context = 'view' ) { |
|
| 1027 | + return $this->get_email( $context ); |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * Get the customer's country. |
|
| 1032 | + * |
|
| 1033 | + * @since 1.0.19 |
|
| 1034 | + * @param string $context View or edit context. |
|
| 1035 | + * @return string |
|
| 1036 | + */ |
|
| 1037 | + public function get_country( $context = 'view' ) { |
|
| 1038 | + $country = $this->get_prop( 'country', $context ); |
|
| 1039 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 1028 | 1040 | } |
| 1029 | 1041 | |
| 1030 | 1042 | /** |
| 1031 | - * Get the customer's country. |
|
| 1032 | - * |
|
| 1033 | - * @since 1.0.19 |
|
| 1034 | - * @param string $context View or edit context. |
|
| 1035 | - * @return string |
|
| 1036 | - */ |
|
| 1037 | - public function get_country( $context = 'view' ) { |
|
| 1038 | - $country = $this->get_prop( 'country', $context ); |
|
| 1039 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 1043 | + * Alias of self::get_country(). |
|
| 1044 | + * |
|
| 1045 | + * @since 1.0.19 |
|
| 1046 | + * @param string $context View or edit context. |
|
| 1047 | + * @return string |
|
| 1048 | + */ |
|
| 1049 | + public function get_user_country( $context = 'view' ) { |
|
| 1050 | + return $this->get_country( $context ); |
|
| 1040 | 1051 | } |
| 1041 | 1052 | |
| 1042 | 1053 | /** |
| 1043 | - * Alias of self::get_country(). |
|
| 1044 | - * |
|
| 1045 | - * @since 1.0.19 |
|
| 1046 | - * @param string $context View or edit context. |
|
| 1047 | - * @return string |
|
| 1048 | - */ |
|
| 1049 | - public function get_user_country( $context = 'view' ) { |
|
| 1050 | - return $this->get_country( $context ); |
|
| 1054 | + * Alias of self::get_country(). |
|
| 1055 | + * |
|
| 1056 | + * @since 1.0.19 |
|
| 1057 | + * @param string $context View or edit context. |
|
| 1058 | + * @return string |
|
| 1059 | + */ |
|
| 1060 | + public function get_customer_country( $context = 'view' ) { |
|
| 1061 | + return $this->get_country( $context ); |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + /** |
|
| 1065 | + * Get the customer's state. |
|
| 1066 | + * |
|
| 1067 | + * @since 1.0.19 |
|
| 1068 | + * @param string $context View or edit context. |
|
| 1069 | + * @return string |
|
| 1070 | + */ |
|
| 1071 | + public function get_state( $context = 'view' ) { |
|
| 1072 | + $state = $this->get_prop( 'state', $context ); |
|
| 1073 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * Alias of self::get_state(). |
|
| 1078 | + * |
|
| 1079 | + * @since 1.0.19 |
|
| 1080 | + * @param string $context View or edit context. |
|
| 1081 | + * @return string |
|
| 1082 | + */ |
|
| 1083 | + public function get_user_state( $context = 'view' ) { |
|
| 1084 | + return $this->get_state( $context ); |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * Alias of self::get_state(). |
|
| 1089 | + * |
|
| 1090 | + * @since 1.0.19 |
|
| 1091 | + * @param string $context View or edit context. |
|
| 1092 | + * @return string |
|
| 1093 | + */ |
|
| 1094 | + public function get_customer_state( $context = 'view' ) { |
|
| 1095 | + return $this->get_state( $context ); |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * Get the customer's city. |
|
| 1100 | + * |
|
| 1101 | + * @since 1.0.19 |
|
| 1102 | + * @param string $context View or edit context. |
|
| 1103 | + * @return string |
|
| 1104 | + */ |
|
| 1105 | + public function get_city( $context = 'view' ) { |
|
| 1106 | + return $this->get_prop( 'city', $context ); |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + /** |
|
| 1110 | + * Alias of self::get_city(). |
|
| 1111 | + * |
|
| 1112 | + * @since 1.0.19 |
|
| 1113 | + * @param string $context View or edit context. |
|
| 1114 | + * @return string |
|
| 1115 | + */ |
|
| 1116 | + public function get_user_city( $context = 'view' ) { |
|
| 1117 | + return $this->get_city( $context ); |
|
| 1051 | 1118 | } |
| 1052 | 1119 | |
| 1053 | 1120 | /** |
| 1054 | - * Alias of self::get_country(). |
|
| 1055 | - * |
|
| 1056 | - * @since 1.0.19 |
|
| 1057 | - * @param string $context View or edit context. |
|
| 1058 | - * @return string |
|
| 1059 | - */ |
|
| 1060 | - public function get_customer_country( $context = 'view' ) { |
|
| 1061 | - return $this->get_country( $context ); |
|
| 1121 | + * Alias of self::get_city(). |
|
| 1122 | + * |
|
| 1123 | + * @since 1.0.19 |
|
| 1124 | + * @param string $context View or edit context. |
|
| 1125 | + * @return string |
|
| 1126 | + */ |
|
| 1127 | + public function get_customer_city( $context = 'view' ) { |
|
| 1128 | + return $this->get_city( $context ); |
|
| 1062 | 1129 | } |
| 1063 | 1130 | |
| 1064 | 1131 | /** |
| 1065 | - * Get the customer's state. |
|
| 1066 | - * |
|
| 1067 | - * @since 1.0.19 |
|
| 1068 | - * @param string $context View or edit context. |
|
| 1069 | - * @return string |
|
| 1070 | - */ |
|
| 1071 | - public function get_state( $context = 'view' ) { |
|
| 1072 | - $state = $this->get_prop( 'state', $context ); |
|
| 1073 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1132 | + * Get the customer's zip. |
|
| 1133 | + * |
|
| 1134 | + * @since 1.0.19 |
|
| 1135 | + * @param string $context View or edit context. |
|
| 1136 | + * @return string |
|
| 1137 | + */ |
|
| 1138 | + public function get_zip( $context = 'view' ) { |
|
| 1139 | + return $this->get_prop( 'zip', $context ); |
|
| 1074 | 1140 | } |
| 1075 | 1141 | |
| 1076 | 1142 | /** |
| 1077 | - * Alias of self::get_state(). |
|
| 1078 | - * |
|
| 1079 | - * @since 1.0.19 |
|
| 1080 | - * @param string $context View or edit context. |
|
| 1081 | - * @return string |
|
| 1082 | - */ |
|
| 1083 | - public function get_user_state( $context = 'view' ) { |
|
| 1084 | - return $this->get_state( $context ); |
|
| 1143 | + * Alias of self::get_zip(). |
|
| 1144 | + * |
|
| 1145 | + * @since 1.0.19 |
|
| 1146 | + * @param string $context View or edit context. |
|
| 1147 | + * @return string |
|
| 1148 | + */ |
|
| 1149 | + public function get_user_zip( $context = 'view' ) { |
|
| 1150 | + return $this->get_zip( $context ); |
|
| 1085 | 1151 | } |
| 1086 | 1152 | |
| 1087 | 1153 | /** |
| 1088 | - * Alias of self::get_state(). |
|
| 1089 | - * |
|
| 1090 | - * @since 1.0.19 |
|
| 1091 | - * @param string $context View or edit context. |
|
| 1092 | - * @return string |
|
| 1093 | - */ |
|
| 1094 | - public function get_customer_state( $context = 'view' ) { |
|
| 1095 | - return $this->get_state( $context ); |
|
| 1154 | + * Alias of self::get_zip(). |
|
| 1155 | + * |
|
| 1156 | + * @since 1.0.19 |
|
| 1157 | + * @param string $context View or edit context. |
|
| 1158 | + * @return string |
|
| 1159 | + */ |
|
| 1160 | + public function get_customer_zip( $context = 'view' ) { |
|
| 1161 | + return $this->get_zip( $context ); |
|
| 1096 | 1162 | } |
| 1097 | 1163 | |
| 1098 | 1164 | /** |
| 1099 | - * Get the customer's city. |
|
| 1100 | - * |
|
| 1101 | - * @since 1.0.19 |
|
| 1102 | - * @param string $context View or edit context. |
|
| 1103 | - * @return string |
|
| 1104 | - */ |
|
| 1105 | - public function get_city( $context = 'view' ) { |
|
| 1106 | - return $this->get_prop( 'city', $context ); |
|
| 1165 | + * Get the customer's company. |
|
| 1166 | + * |
|
| 1167 | + * @since 1.0.19 |
|
| 1168 | + * @param string $context View or edit context. |
|
| 1169 | + * @return string |
|
| 1170 | + */ |
|
| 1171 | + public function get_company( $context = 'view' ) { |
|
| 1172 | + return $this->get_prop( 'company', $context ); |
|
| 1107 | 1173 | } |
| 1108 | 1174 | |
| 1109 | 1175 | /** |
| 1110 | - * Alias of self::get_city(). |
|
| 1111 | - * |
|
| 1112 | - * @since 1.0.19 |
|
| 1113 | - * @param string $context View or edit context. |
|
| 1114 | - * @return string |
|
| 1115 | - */ |
|
| 1116 | - public function get_user_city( $context = 'view' ) { |
|
| 1117 | - return $this->get_city( $context ); |
|
| 1176 | + * Alias of self::get_company(). |
|
| 1177 | + * |
|
| 1178 | + * @since 1.0.19 |
|
| 1179 | + * @param string $context View or edit context. |
|
| 1180 | + * @return string |
|
| 1181 | + */ |
|
| 1182 | + public function get_user_company( $context = 'view' ) { |
|
| 1183 | + return $this->get_company( $context ); |
|
| 1118 | 1184 | } |
| 1119 | 1185 | |
| 1120 | 1186 | /** |
| 1121 | - * Alias of self::get_city(). |
|
| 1122 | - * |
|
| 1123 | - * @since 1.0.19 |
|
| 1124 | - * @param string $context View or edit context. |
|
| 1125 | - * @return string |
|
| 1126 | - */ |
|
| 1127 | - public function get_customer_city( $context = 'view' ) { |
|
| 1128 | - return $this->get_city( $context ); |
|
| 1187 | + * Alias of self::get_company(). |
|
| 1188 | + * |
|
| 1189 | + * @since 1.0.19 |
|
| 1190 | + * @param string $context View or edit context. |
|
| 1191 | + * @return string |
|
| 1192 | + */ |
|
| 1193 | + public function get_customer_company( $context = 'view' ) { |
|
| 1194 | + return $this->get_company( $context ); |
|
| 1129 | 1195 | } |
| 1130 | 1196 | |
| 1131 | 1197 | /** |
| 1132 | - * Get the customer's zip. |
|
| 1133 | - * |
|
| 1134 | - * @since 1.0.19 |
|
| 1135 | - * @param string $context View or edit context. |
|
| 1136 | - * @return string |
|
| 1137 | - */ |
|
| 1138 | - public function get_zip( $context = 'view' ) { |
|
| 1139 | - return $this->get_prop( 'zip', $context ); |
|
| 1198 | + * Get the customer's company id. |
|
| 1199 | + * |
|
| 1200 | + * @since 1.0.19 |
|
| 1201 | + * @param string $context View or edit context. |
|
| 1202 | + * @return string |
|
| 1203 | + */ |
|
| 1204 | + public function get_company_id( $context = 'view' ) { |
|
| 1205 | + return $this->get_prop( 'company_id', $context ); |
|
| 1140 | 1206 | } |
| 1141 | 1207 | |
| 1142 | 1208 | /** |
| 1143 | - * Alias of self::get_zip(). |
|
| 1144 | - * |
|
| 1145 | - * @since 1.0.19 |
|
| 1146 | - * @param string $context View or edit context. |
|
| 1147 | - * @return string |
|
| 1148 | - */ |
|
| 1149 | - public function get_user_zip( $context = 'view' ) { |
|
| 1150 | - return $this->get_zip( $context ); |
|
| 1209 | + * Get the customer's vat number. |
|
| 1210 | + * |
|
| 1211 | + * @since 1.0.19 |
|
| 1212 | + * @param string $context View or edit context. |
|
| 1213 | + * @return string |
|
| 1214 | + */ |
|
| 1215 | + public function get_vat_number( $context = 'view' ) { |
|
| 1216 | + return $this->get_prop( 'vat_number', $context ); |
|
| 1151 | 1217 | } |
| 1152 | 1218 | |
| 1153 | 1219 | /** |
| 1154 | - * Alias of self::get_zip(). |
|
| 1155 | - * |
|
| 1156 | - * @since 1.0.19 |
|
| 1157 | - * @param string $context View or edit context. |
|
| 1158 | - * @return string |
|
| 1159 | - */ |
|
| 1160 | - public function get_customer_zip( $context = 'view' ) { |
|
| 1161 | - return $this->get_zip( $context ); |
|
| 1220 | + * Alias of self::get_vat_number(). |
|
| 1221 | + * |
|
| 1222 | + * @since 1.0.19 |
|
| 1223 | + * @param string $context View or edit context. |
|
| 1224 | + * @return string |
|
| 1225 | + */ |
|
| 1226 | + public function get_user_vat_number( $context = 'view' ) { |
|
| 1227 | + return $this->get_vat_number( $context ); |
|
| 1162 | 1228 | } |
| 1163 | 1229 | |
| 1164 | 1230 | /** |
| 1165 | - * Get the customer's company. |
|
| 1166 | - * |
|
| 1167 | - * @since 1.0.19 |
|
| 1168 | - * @param string $context View or edit context. |
|
| 1169 | - * @return string |
|
| 1170 | - */ |
|
| 1171 | - public function get_company( $context = 'view' ) { |
|
| 1172 | - return $this->get_prop( 'company', $context ); |
|
| 1231 | + * Alias of self::get_vat_number(). |
|
| 1232 | + * |
|
| 1233 | + * @since 1.0.19 |
|
| 1234 | + * @param string $context View or edit context. |
|
| 1235 | + * @return string |
|
| 1236 | + */ |
|
| 1237 | + public function get_customer_vat_number( $context = 'view' ) { |
|
| 1238 | + return $this->get_vat_number( $context ); |
|
| 1173 | 1239 | } |
| 1174 | 1240 | |
| 1175 | 1241 | /** |
| 1176 | - * Alias of self::get_company(). |
|
| 1177 | - * |
|
| 1178 | - * @since 1.0.19 |
|
| 1179 | - * @param string $context View or edit context. |
|
| 1180 | - * @return string |
|
| 1181 | - */ |
|
| 1182 | - public function get_user_company( $context = 'view' ) { |
|
| 1183 | - return $this->get_company( $context ); |
|
| 1242 | + * Get the customer's vat rate. |
|
| 1243 | + * |
|
| 1244 | + * @since 1.0.19 |
|
| 1245 | + * @param string $context View or edit context. |
|
| 1246 | + * @return string |
|
| 1247 | + */ |
|
| 1248 | + public function get_vat_rate( $context = 'view' ) { |
|
| 1249 | + return $this->get_prop( 'vat_rate', $context ); |
|
| 1184 | 1250 | } |
| 1185 | 1251 | |
| 1186 | 1252 | /** |
| 1187 | - * Alias of self::get_company(). |
|
| 1188 | - * |
|
| 1189 | - * @since 1.0.19 |
|
| 1190 | - * @param string $context View or edit context. |
|
| 1191 | - * @return string |
|
| 1192 | - */ |
|
| 1193 | - public function get_customer_company( $context = 'view' ) { |
|
| 1194 | - return $this->get_company( $context ); |
|
| 1253 | + * Alias of self::get_vat_rate(). |
|
| 1254 | + * |
|
| 1255 | + * @since 1.0.19 |
|
| 1256 | + * @param string $context View or edit context. |
|
| 1257 | + * @return string |
|
| 1258 | + */ |
|
| 1259 | + public function get_user_vat_rate( $context = 'view' ) { |
|
| 1260 | + return $this->get_vat_rate( $context ); |
|
| 1195 | 1261 | } |
| 1196 | 1262 | |
| 1197 | - /** |
|
| 1198 | - * Get the customer's company id. |
|
| 1199 | - * |
|
| 1200 | - * @since 1.0.19 |
|
| 1201 | - * @param string $context View or edit context. |
|
| 1202 | - * @return string |
|
| 1203 | - */ |
|
| 1204 | - public function get_company_id( $context = 'view' ) { |
|
| 1205 | - return $this->get_prop( 'company_id', $context ); |
|
| 1263 | + /** |
|
| 1264 | + * Alias of self::get_vat_rate(). |
|
| 1265 | + * |
|
| 1266 | + * @since 1.0.19 |
|
| 1267 | + * @param string $context View or edit context. |
|
| 1268 | + * @return string |
|
| 1269 | + */ |
|
| 1270 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1271 | + return $this->get_vat_rate( $context ); |
|
| 1206 | 1272 | } |
| 1207 | 1273 | |
| 1208 | 1274 | /** |
| 1209 | - * Get the customer's vat number. |
|
| 1210 | - * |
|
| 1211 | - * @since 1.0.19 |
|
| 1212 | - * @param string $context View or edit context. |
|
| 1213 | - * @return string |
|
| 1214 | - */ |
|
| 1215 | - public function get_vat_number( $context = 'view' ) { |
|
| 1216 | - return $this->get_prop( 'vat_number', $context ); |
|
| 1275 | + * Get the customer's address. |
|
| 1276 | + * |
|
| 1277 | + * @since 1.0.19 |
|
| 1278 | + * @param string $context View or edit context. |
|
| 1279 | + * @return string |
|
| 1280 | + */ |
|
| 1281 | + public function get_address( $context = 'view' ) { |
|
| 1282 | + return $this->get_prop( 'address', $context ); |
|
| 1217 | 1283 | } |
| 1218 | 1284 | |
| 1219 | 1285 | /** |
| 1220 | - * Alias of self::get_vat_number(). |
|
| 1221 | - * |
|
| 1222 | - * @since 1.0.19 |
|
| 1223 | - * @param string $context View or edit context. |
|
| 1224 | - * @return string |
|
| 1225 | - */ |
|
| 1226 | - public function get_user_vat_number( $context = 'view' ) { |
|
| 1227 | - return $this->get_vat_number( $context ); |
|
| 1286 | + * Alias of self::get_address(). |
|
| 1287 | + * |
|
| 1288 | + * @since 1.0.19 |
|
| 1289 | + * @param string $context View or edit context. |
|
| 1290 | + * @return string |
|
| 1291 | + */ |
|
| 1292 | + public function get_user_address( $context = 'view' ) { |
|
| 1293 | + return $this->get_address( $context ); |
|
| 1228 | 1294 | } |
| 1229 | 1295 | |
| 1230 | 1296 | /** |
| 1231 | - * Alias of self::get_vat_number(). |
|
| 1232 | - * |
|
| 1233 | - * @since 1.0.19 |
|
| 1234 | - * @param string $context View or edit context. |
|
| 1235 | - * @return string |
|
| 1236 | - */ |
|
| 1237 | - public function get_customer_vat_number( $context = 'view' ) { |
|
| 1238 | - return $this->get_vat_number( $context ); |
|
| 1297 | + * Alias of self::get_address(). |
|
| 1298 | + * |
|
| 1299 | + * @since 1.0.19 |
|
| 1300 | + * @param string $context View or edit context. |
|
| 1301 | + * @return string |
|
| 1302 | + */ |
|
| 1303 | + public function get_customer_address( $context = 'view' ) { |
|
| 1304 | + return $this->get_address( $context ); |
|
| 1239 | 1305 | } |
| 1240 | 1306 | |
| 1241 | - /** |
|
| 1242 | - * Get the customer's vat rate. |
|
| 1243 | - * |
|
| 1244 | - * @since 1.0.19 |
|
| 1245 | - * @param string $context View or edit context. |
|
| 1246 | - * @return string |
|
| 1247 | - */ |
|
| 1248 | - public function get_vat_rate( $context = 'view' ) { |
|
| 1249 | - return $this->get_prop( 'vat_rate', $context ); |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - /** |
|
| 1253 | - * Alias of self::get_vat_rate(). |
|
| 1254 | - * |
|
| 1255 | - * @since 1.0.19 |
|
| 1256 | - * @param string $context View or edit context. |
|
| 1257 | - * @return string |
|
| 1258 | - */ |
|
| 1259 | - public function get_user_vat_rate( $context = 'view' ) { |
|
| 1260 | - return $this->get_vat_rate( $context ); |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - /** |
|
| 1264 | - * Alias of self::get_vat_rate(). |
|
| 1265 | - * |
|
| 1266 | - * @since 1.0.19 |
|
| 1267 | - * @param string $context View or edit context. |
|
| 1268 | - * @return string |
|
| 1269 | - */ |
|
| 1270 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1271 | - return $this->get_vat_rate( $context ); |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - /** |
|
| 1275 | - * Get the customer's address. |
|
| 1276 | - * |
|
| 1277 | - * @since 1.0.19 |
|
| 1278 | - * @param string $context View or edit context. |
|
| 1279 | - * @return string |
|
| 1280 | - */ |
|
| 1281 | - public function get_address( $context = 'view' ) { |
|
| 1282 | - return $this->get_prop( 'address', $context ); |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * Alias of self::get_address(). |
|
| 1287 | - * |
|
| 1288 | - * @since 1.0.19 |
|
| 1289 | - * @param string $context View or edit context. |
|
| 1290 | - * @return string |
|
| 1291 | - */ |
|
| 1292 | - public function get_user_address( $context = 'view' ) { |
|
| 1293 | - return $this->get_address( $context ); |
|
| 1294 | - } |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * Alias of self::get_address(). |
|
| 1298 | - * |
|
| 1299 | - * @since 1.0.19 |
|
| 1300 | - * @param string $context View or edit context. |
|
| 1301 | - * @return string |
|
| 1302 | - */ |
|
| 1303 | - public function get_customer_address( $context = 'view' ) { |
|
| 1304 | - return $this->get_address( $context ); |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * Get whether the customer has viewed the invoice or not. |
|
| 1309 | - * |
|
| 1310 | - * @since 1.0.19 |
|
| 1311 | - * @param string $context View or edit context. |
|
| 1312 | - * @return bool |
|
| 1313 | - */ |
|
| 1314 | - public function get_is_viewed( $context = 'view' ) { |
|
| 1315 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * Get other recipients for invoice communications. |
|
| 1320 | - * |
|
| 1321 | - * @since 1.0.19 |
|
| 1322 | - * @param string $context View or edit context. |
|
| 1323 | - * @return bool |
|
| 1324 | - */ |
|
| 1325 | - public function get_email_cc( $context = 'view' ) { |
|
| 1326 | - return $this->get_prop( 'email_cc', $context ); |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - /** |
|
| 1330 | - * Get invoice template. |
|
| 1331 | - * |
|
| 1332 | - * @since 1.0.19 |
|
| 1333 | - * @param string $context View or edit context. |
|
| 1334 | - * @return bool |
|
| 1335 | - */ |
|
| 1336 | - public function get_template( $context = 'view' ) { |
|
| 1337 | - return $this->get_prop( 'template', $context ); |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - /** |
|
| 1341 | - * Get invoice source. |
|
| 1342 | - * |
|
| 1343 | - * @since 1.0.19 |
|
| 1344 | - * @param string $context View or edit context. |
|
| 1345 | - * @return bool |
|
| 1346 | - */ |
|
| 1347 | - public function get_created_via( $context = 'view' ) { |
|
| 1348 | - return $this->get_prop( 'created_via', $context ); |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * Get whether the customer has confirmed their address. |
|
| 1353 | - * |
|
| 1354 | - * @since 1.0.19 |
|
| 1355 | - * @param string $context View or edit context. |
|
| 1356 | - * @return bool |
|
| 1357 | - */ |
|
| 1358 | - public function get_address_confirmed( $context = 'view' ) { |
|
| 1359 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Alias of self::get_address_confirmed(). |
|
| 1364 | - * |
|
| 1365 | - * @since 1.0.19 |
|
| 1366 | - * @param string $context View or edit context. |
|
| 1367 | - * @return bool |
|
| 1368 | - */ |
|
| 1369 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1370 | - return $this->get_address_confirmed( $context ); |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * Alias of self::get_address(). |
|
| 1375 | - * |
|
| 1376 | - * @since 1.0.19 |
|
| 1377 | - * @param string $context View or edit context. |
|
| 1378 | - * @return bool |
|
| 1379 | - */ |
|
| 1380 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1381 | - return $this->get_address_confirmed( $context ); |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - /** |
|
| 1385 | - * Get the shipping address. |
|
| 1386 | - * |
|
| 1387 | - * @since 1.0.19 |
|
| 1388 | - * @return array|false |
|
| 1389 | - */ |
|
| 1390 | - public function get_shipping_address() { |
|
| 1391 | - |
|
| 1392 | - $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
| 1393 | - return is_array( $shipping_address ) ? $shipping_address : false; |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - /** |
|
| 1397 | - * Check if the invoice has a shipping address. |
|
| 1398 | - */ |
|
| 1399 | - public function has_shipping_address() { |
|
| 1400 | - return false !== $this->get_shipping_address(); |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - /** |
|
| 1404 | - * Get the shipping amount. |
|
| 1405 | - * |
|
| 1406 | - * @since 1.0.19 |
|
| 1407 | - * @param string $context View or edit context. |
|
| 1408 | - * @return float |
|
| 1409 | - */ |
|
| 1410 | - public function get_shipping( $context = 'view' ) { |
|
| 1411 | - |
|
| 1412 | - if ( $context = 'view' ) { |
|
| 1413 | - return floatval( $this->get_prop( 'shipping', $context ) ); |
|
| 1414 | - } |
|
| 1307 | + /** |
|
| 1308 | + * Get whether the customer has viewed the invoice or not. |
|
| 1309 | + * |
|
| 1310 | + * @since 1.0.19 |
|
| 1311 | + * @param string $context View or edit context. |
|
| 1312 | + * @return bool |
|
| 1313 | + */ |
|
| 1314 | + public function get_is_viewed( $context = 'view' ) { |
|
| 1315 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * Get other recipients for invoice communications. |
|
| 1320 | + * |
|
| 1321 | + * @since 1.0.19 |
|
| 1322 | + * @param string $context View or edit context. |
|
| 1323 | + * @return bool |
|
| 1324 | + */ |
|
| 1325 | + public function get_email_cc( $context = 'view' ) { |
|
| 1326 | + return $this->get_prop( 'email_cc', $context ); |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + /** |
|
| 1330 | + * Get invoice template. |
|
| 1331 | + * |
|
| 1332 | + * @since 1.0.19 |
|
| 1333 | + * @param string $context View or edit context. |
|
| 1334 | + * @return bool |
|
| 1335 | + */ |
|
| 1336 | + public function get_template( $context = 'view' ) { |
|
| 1337 | + return $this->get_prop( 'template', $context ); |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + /** |
|
| 1341 | + * Get invoice source. |
|
| 1342 | + * |
|
| 1343 | + * @since 1.0.19 |
|
| 1344 | + * @param string $context View or edit context. |
|
| 1345 | + * @return bool |
|
| 1346 | + */ |
|
| 1347 | + public function get_created_via( $context = 'view' ) { |
|
| 1348 | + return $this->get_prop( 'created_via', $context ); |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * Get whether the customer has confirmed their address. |
|
| 1353 | + * |
|
| 1354 | + * @since 1.0.19 |
|
| 1355 | + * @param string $context View or edit context. |
|
| 1356 | + * @return bool |
|
| 1357 | + */ |
|
| 1358 | + public function get_address_confirmed( $context = 'view' ) { |
|
| 1359 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Alias of self::get_address_confirmed(). |
|
| 1364 | + * |
|
| 1365 | + * @since 1.0.19 |
|
| 1366 | + * @param string $context View or edit context. |
|
| 1367 | + * @return bool |
|
| 1368 | + */ |
|
| 1369 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1370 | + return $this->get_address_confirmed( $context ); |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * Alias of self::get_address(). |
|
| 1375 | + * |
|
| 1376 | + * @since 1.0.19 |
|
| 1377 | + * @param string $context View or edit context. |
|
| 1378 | + * @return bool |
|
| 1379 | + */ |
|
| 1380 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1381 | + return $this->get_address_confirmed( $context ); |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + /** |
|
| 1385 | + * Get the shipping address. |
|
| 1386 | + * |
|
| 1387 | + * @since 1.0.19 |
|
| 1388 | + * @return array|false |
|
| 1389 | + */ |
|
| 1390 | + public function get_shipping_address() { |
|
| 1391 | + |
|
| 1392 | + $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
| 1393 | + return is_array( $shipping_address ) ? $shipping_address : false; |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + /** |
|
| 1397 | + * Check if the invoice has a shipping address. |
|
| 1398 | + */ |
|
| 1399 | + public function has_shipping_address() { |
|
| 1400 | + return false !== $this->get_shipping_address(); |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + /** |
|
| 1404 | + * Get the shipping amount. |
|
| 1405 | + * |
|
| 1406 | + * @since 1.0.19 |
|
| 1407 | + * @param string $context View or edit context. |
|
| 1408 | + * @return float |
|
| 1409 | + */ |
|
| 1410 | + public function get_shipping( $context = 'view' ) { |
|
| 1411 | + |
|
| 1412 | + if ( $context = 'view' ) { |
|
| 1413 | + return floatval( $this->get_prop( 'shipping', $context ) ); |
|
| 1414 | + } |
|
| 1415 | 1415 | |
| 1416 | - return $this->get_prop( 'shipping', $context ); |
|
| 1416 | + return $this->get_prop( 'shipping', $context ); |
|
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | - public function has_shipping() { |
|
| 1420 | - return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
| 1419 | + public function has_shipping() { |
|
| 1420 | + return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
| 1421 | 1421 | } |
| 1422 | 1422 | |
| 1423 | 1423 | /** |
| 1424 | - * Get the invoice subtotal. |
|
| 1425 | - * |
|
| 1426 | - * @since 1.0.19 |
|
| 1427 | - * @param string $context View or edit context. |
|
| 1428 | - * @return float |
|
| 1429 | - */ |
|
| 1430 | - public function get_subtotal( $context = 'view' ) { |
|
| 1424 | + * Get the invoice subtotal. |
|
| 1425 | + * |
|
| 1426 | + * @since 1.0.19 |
|
| 1427 | + * @param string $context View or edit context. |
|
| 1428 | + * @return float |
|
| 1429 | + */ |
|
| 1430 | + public function get_subtotal( $context = 'view' ) { |
|
| 1431 | 1431 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
| 1432 | 1432 | |
| 1433 | 1433 | // Backwards compatibility. |
@@ -1439,198 +1439,198 @@ discard block |
||
| 1439 | 1439 | } |
| 1440 | 1440 | |
| 1441 | 1441 | /** |
| 1442 | - * Get the invoice discount total. |
|
| 1443 | - * |
|
| 1444 | - * @since 1.0.19 |
|
| 1445 | - * @param string $context View or edit context. |
|
| 1446 | - * @return float |
|
| 1447 | - */ |
|
| 1448 | - public function get_total_discount( $context = 'view' ) { |
|
| 1449 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
| 1442 | + * Get the invoice discount total. |
|
| 1443 | + * |
|
| 1444 | + * @since 1.0.19 |
|
| 1445 | + * @param string $context View or edit context. |
|
| 1446 | + * @return float |
|
| 1447 | + */ |
|
| 1448 | + public function get_total_discount( $context = 'view' ) { |
|
| 1449 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | /** |
| 1453 | - * Get the invoice tax total. |
|
| 1454 | - * |
|
| 1455 | - * @since 1.0.19 |
|
| 1456 | - * @param string $context View or edit context. |
|
| 1457 | - * @return float |
|
| 1458 | - */ |
|
| 1459 | - public function get_total_tax( $context = 'view' ) { |
|
| 1460 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
| 1461 | - } |
|
| 1453 | + * Get the invoice tax total. |
|
| 1454 | + * |
|
| 1455 | + * @since 1.0.19 |
|
| 1456 | + * @param string $context View or edit context. |
|
| 1457 | + * @return float |
|
| 1458 | + */ |
|
| 1459 | + public function get_total_tax( $context = 'view' ) { |
|
| 1460 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
| 1461 | + } |
|
| 1462 | 1462 | |
| 1463 | - /** |
|
| 1464 | - * @deprecated |
|
| 1465 | - */ |
|
| 1466 | - public function get_final_tax( $currency = false ) { |
|
| 1467 | - $tax = $this->get_total_tax(); |
|
| 1463 | + /** |
|
| 1464 | + * @deprecated |
|
| 1465 | + */ |
|
| 1466 | + public function get_final_tax( $currency = false ) { |
|
| 1467 | + $tax = $this->get_total_tax(); |
|
| 1468 | 1468 | |
| 1469 | 1469 | if ( $currency ) { |
| 1470 | - return wpinv_price( $tax, $this->get_currency() ); |
|
| 1470 | + return wpinv_price( $tax, $this->get_currency() ); |
|
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | 1473 | return $tax; |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | 1476 | /** |
| 1477 | - * Get the invoice fees total. |
|
| 1478 | - * |
|
| 1479 | - * @since 1.0.19 |
|
| 1480 | - * @param string $context View or edit context. |
|
| 1481 | - * @return float |
|
| 1482 | - */ |
|
| 1483 | - public function get_total_fees( $context = 'view' ) { |
|
| 1484 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
| 1477 | + * Get the invoice fees total. |
|
| 1478 | + * |
|
| 1479 | + * @since 1.0.19 |
|
| 1480 | + * @param string $context View or edit context. |
|
| 1481 | + * @return float |
|
| 1482 | + */ |
|
| 1483 | + public function get_total_fees( $context = 'view' ) { |
|
| 1484 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + /** |
|
| 1488 | + * Alias for self::get_total_fees(). |
|
| 1489 | + * |
|
| 1490 | + * @since 1.0.19 |
|
| 1491 | + * @param string $context View or edit context. |
|
| 1492 | + * @return float |
|
| 1493 | + */ |
|
| 1494 | + public function get_fees_total( $context = 'view' ) { |
|
| 1495 | + return $this->get_total_fees( $context ); |
|
| 1485 | 1496 | } |
| 1486 | 1497 | |
| 1487 | 1498 | /** |
| 1488 | - * Alias for self::get_total_fees(). |
|
| 1489 | - * |
|
| 1490 | - * @since 1.0.19 |
|
| 1491 | - * @param string $context View or edit context. |
|
| 1492 | - * @return float |
|
| 1493 | - */ |
|
| 1494 | - public function get_fees_total( $context = 'view' ) { |
|
| 1495 | - return $this->get_total_fees( $context ); |
|
| 1499 | + * Get the invoice total. |
|
| 1500 | + * |
|
| 1501 | + * @since 1.0.19 |
|
| 1502 | + * @return float |
|
| 1503 | + */ |
|
| 1504 | + public function get_total( $context = 'view' ) { |
|
| 1505 | + $total = $this->get_prop( 'total', $context ); |
|
| 1506 | + |
|
| 1507 | + if ( $this->has_shipping() && $context == 'view' ) { |
|
| 1508 | + $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1496 | 1512 | } |
| 1497 | 1513 | |
| 1498 | 1514 | /** |
| 1499 | - * Get the invoice total. |
|
| 1500 | - * |
|
| 1501 | - * @since 1.0.19 |
|
| 1515 | + * Retrieves the non-recurring total of items. |
|
| 1516 | + * |
|
| 1517 | + * @since 2.3.0 |
|
| 1502 | 1518 | * @return float |
| 1503 | - */ |
|
| 1504 | - public function get_total( $context = 'view' ) { |
|
| 1505 | - $total = $this->get_prop( 'total', $context ); |
|
| 1506 | - |
|
| 1507 | - if ( $this->has_shipping() && $context == 'view' ) { |
|
| 1508 | - $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - /** |
|
| 1515 | - * Retrieves the non-recurring total of items. |
|
| 1516 | - * |
|
| 1517 | - * @since 2.3.0 |
|
| 1518 | - * @return float |
|
| 1519 | - */ |
|
| 1520 | - public function get_non_recurring_total() { |
|
| 1521 | - |
|
| 1522 | - $subtotal = 0; |
|
| 1523 | - foreach ( $this->get_items() as $item ) { |
|
| 1524 | - if ( ! $item->is_recurring() ) { |
|
| 1525 | - $subtotal += $item->get_sub_total(); |
|
| 1526 | - } |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - foreach ( $this->get_fees() as $fee ) { |
|
| 1530 | - if ( empty( $fee['recurring_fee'] ) ) { |
|
| 1531 | - $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 1532 | - } |
|
| 1533 | - } |
|
| 1534 | - |
|
| 1535 | - $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
| 1519 | + */ |
|
| 1520 | + public function get_non_recurring_total() { |
|
| 1521 | + |
|
| 1522 | + $subtotal = 0; |
|
| 1523 | + foreach ( $this->get_items() as $item ) { |
|
| 1524 | + if ( ! $item->is_recurring() ) { |
|
| 1525 | + $subtotal += $item->get_sub_total(); |
|
| 1526 | + } |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + foreach ( $this->get_fees() as $fee ) { |
|
| 1530 | + if ( empty( $fee['recurring_fee'] ) ) { |
|
| 1531 | + $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 1532 | + } |
|
| 1533 | + } |
|
| 1534 | + |
|
| 1535 | + $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
| 1536 | 1536 | return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this ); |
| 1537 | 1537 | |
| 1538 | 1538 | } |
| 1539 | 1539 | |
| 1540 | - /** |
|
| 1541 | - * Get the invoice totals. |
|
| 1542 | - * |
|
| 1543 | - * @since 1.0.19 |
|
| 1540 | + /** |
|
| 1541 | + * Get the invoice totals. |
|
| 1542 | + * |
|
| 1543 | + * @since 1.0.19 |
|
| 1544 | 1544 | * @return array |
| 1545 | - */ |
|
| 1546 | - public function get_totals() { |
|
| 1547 | - return $this->totals; |
|
| 1545 | + */ |
|
| 1546 | + public function get_totals() { |
|
| 1547 | + return $this->totals; |
|
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | /** |
| 1551 | - * Get the initial invoice total. |
|
| 1552 | - * |
|
| 1553 | - * @since 1.0.19 |
|
| 1551 | + * Get the initial invoice total. |
|
| 1552 | + * |
|
| 1553 | + * @since 1.0.19 |
|
| 1554 | 1554 | * @param string $context View or edit context. |
| 1555 | 1555 | * @return float |
| 1556 | - */ |
|
| 1556 | + */ |
|
| 1557 | 1557 | public function get_initial_total() { |
| 1558 | 1558 | |
| 1559 | - if ( empty( $this->totals ) ) { |
|
| 1560 | - $this->recalculate_total(); |
|
| 1561 | - } |
|
| 1559 | + if ( empty( $this->totals ) ) { |
|
| 1560 | + $this->recalculate_total(); |
|
| 1561 | + } |
|
| 1562 | 1562 | |
| 1563 | - $tax = $this->totals['tax']['initial']; |
|
| 1564 | - $fee = $this->totals['fee']['initial']; |
|
| 1565 | - $discount = $this->totals['discount']['initial']; |
|
| 1566 | - $subtotal = $this->totals['subtotal']['initial']; |
|
| 1567 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1563 | + $tax = $this->totals['tax']['initial']; |
|
| 1564 | + $fee = $this->totals['fee']['initial']; |
|
| 1565 | + $discount = $this->totals['discount']['initial']; |
|
| 1566 | + $subtotal = $this->totals['subtotal']['initial']; |
|
| 1567 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1568 | 1568 | |
| 1569 | - if ( 0 > $total ) { |
|
| 1570 | - $total = 0; |
|
| 1571 | - } |
|
| 1569 | + if ( 0 > $total ) { |
|
| 1570 | + $total = 0; |
|
| 1571 | + } |
|
| 1572 | 1572 | |
| 1573 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1573 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1574 | 1574 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
| 1575 | - } |
|
| 1575 | + } |
|
| 1576 | 1576 | |
| 1577 | - /** |
|
| 1578 | - * Get the recurring invoice total. |
|
| 1579 | - * |
|
| 1580 | - * @since 1.0.19 |
|
| 1577 | + /** |
|
| 1578 | + * Get the recurring invoice total. |
|
| 1579 | + * |
|
| 1580 | + * @since 1.0.19 |
|
| 1581 | 1581 | * @param string $context View or edit context. |
| 1582 | 1582 | * @return float |
| 1583 | - */ |
|
| 1583 | + */ |
|
| 1584 | 1584 | public function get_recurring_total() { |
| 1585 | 1585 | |
| 1586 | - if ( empty( $this->totals ) ) { |
|
| 1587 | - $this->recalculate_total(); |
|
| 1588 | - } |
|
| 1586 | + if ( empty( $this->totals ) ) { |
|
| 1587 | + $this->recalculate_total(); |
|
| 1588 | + } |
|
| 1589 | 1589 | |
| 1590 | - $tax = $this->totals['tax']['recurring']; |
|
| 1591 | - $fee = $this->totals['fee']['recurring']; |
|
| 1592 | - $discount = $this->totals['discount']['recurring']; |
|
| 1593 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1594 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1590 | + $tax = $this->totals['tax']['recurring']; |
|
| 1591 | + $fee = $this->totals['fee']['recurring']; |
|
| 1592 | + $discount = $this->totals['discount']['recurring']; |
|
| 1593 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1594 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1595 | 1595 | |
| 1596 | - if ( 0 > $total ) { |
|
| 1597 | - $total = 0; |
|
| 1598 | - } |
|
| 1596 | + if ( 0 > $total ) { |
|
| 1597 | + $total = 0; |
|
| 1598 | + } |
|
| 1599 | 1599 | |
| 1600 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1600 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1601 | 1601 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
| 1602 | - } |
|
| 1602 | + } |
|
| 1603 | 1603 | |
| 1604 | - /** |
|
| 1605 | - * Returns recurring payment details. |
|
| 1606 | - * |
|
| 1607 | - * @since 1.0.19 |
|
| 1604 | + /** |
|
| 1605 | + * Returns recurring payment details. |
|
| 1606 | + * |
|
| 1607 | + * @since 1.0.19 |
|
| 1608 | 1608 | * @param string $field Optionally provide a field to return. |
| 1609 | - * @param string $currency Whether to include the currency. |
|
| 1609 | + * @param string $currency Whether to include the currency. |
|
| 1610 | 1610 | * @return float|string |
| 1611 | - */ |
|
| 1611 | + */ |
|
| 1612 | 1612 | public function get_recurring_details( $field = '', $currency = false ) { |
| 1613 | 1613 | |
| 1614 | - // Maybe recalculate totals. |
|
| 1615 | - if ( empty( $this->totals ) ) { |
|
| 1616 | - $this->recalculate_total(); |
|
| 1617 | - } |
|
| 1614 | + // Maybe recalculate totals. |
|
| 1615 | + if ( empty( $this->totals ) ) { |
|
| 1616 | + $this->recalculate_total(); |
|
| 1617 | + } |
|
| 1618 | 1618 | |
| 1619 | - // Prepare recurring totals. |
|
| 1619 | + // Prepare recurring totals. |
|
| 1620 | 1620 | $data = apply_filters( |
| 1621 | - 'wpinv_get_invoice_recurring_details', |
|
| 1622 | - array( |
|
| 1623 | - 'cart_details' => $this->get_cart_details(), |
|
| 1624 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1625 | - 'discount' => $this->totals['discount']['recurring'], |
|
| 1626 | - 'tax' => $this->totals['tax']['recurring'], |
|
| 1627 | - 'fee' => $this->totals['fee']['recurring'], |
|
| 1628 | - 'total' => $this->get_recurring_total(), |
|
| 1629 | - ), |
|
| 1630 | - $this, |
|
| 1631 | - $field, |
|
| 1632 | - $currency |
|
| 1633 | - ); |
|
| 1621 | + 'wpinv_get_invoice_recurring_details', |
|
| 1622 | + array( |
|
| 1623 | + 'cart_details' => $this->get_cart_details(), |
|
| 1624 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1625 | + 'discount' => $this->totals['discount']['recurring'], |
|
| 1626 | + 'tax' => $this->totals['tax']['recurring'], |
|
| 1627 | + 'fee' => $this->totals['fee']['recurring'], |
|
| 1628 | + 'total' => $this->get_recurring_total(), |
|
| 1629 | + ), |
|
| 1630 | + $this, |
|
| 1631 | + $field, |
|
| 1632 | + $currency |
|
| 1633 | + ); |
|
| 1634 | 1634 | |
| 1635 | 1635 | if ( isset( $data[$field] ) ) { |
| 1636 | 1636 | return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
@@ -1640,166 +1640,166 @@ discard block |
||
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | 1642 | /** |
| 1643 | - * Get the invoice fees. |
|
| 1644 | - * |
|
| 1645 | - * @since 1.0.19 |
|
| 1646 | - * @param string $context View or edit context. |
|
| 1647 | - * @return array |
|
| 1648 | - */ |
|
| 1649 | - public function get_fees( $context = 'view' ) { |
|
| 1650 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1643 | + * Get the invoice fees. |
|
| 1644 | + * |
|
| 1645 | + * @since 1.0.19 |
|
| 1646 | + * @param string $context View or edit context. |
|
| 1647 | + * @return array |
|
| 1648 | + */ |
|
| 1649 | + public function get_fees( $context = 'view' ) { |
|
| 1650 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1651 | 1651 | } |
| 1652 | 1652 | |
| 1653 | 1653 | /** |
| 1654 | - * Get the invoice discounts. |
|
| 1655 | - * |
|
| 1656 | - * @since 1.0.19 |
|
| 1657 | - * @param string $context View or edit context. |
|
| 1658 | - * @return array |
|
| 1659 | - */ |
|
| 1660 | - public function get_discounts( $context = 'view' ) { |
|
| 1661 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1654 | + * Get the invoice discounts. |
|
| 1655 | + * |
|
| 1656 | + * @since 1.0.19 |
|
| 1657 | + * @param string $context View or edit context. |
|
| 1658 | + * @return array |
|
| 1659 | + */ |
|
| 1660 | + public function get_discounts( $context = 'view' ) { |
|
| 1661 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1662 | 1662 | } |
| 1663 | 1663 | |
| 1664 | 1664 | /** |
| 1665 | - * Get the invoice taxes. |
|
| 1666 | - * |
|
| 1667 | - * @since 1.0.19 |
|
| 1668 | - * @param string $context View or edit context. |
|
| 1669 | - * @return array |
|
| 1670 | - */ |
|
| 1671 | - public function get_taxes( $context = 'view' ) { |
|
| 1672 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1665 | + * Get the invoice taxes. |
|
| 1666 | + * |
|
| 1667 | + * @since 1.0.19 |
|
| 1668 | + * @param string $context View or edit context. |
|
| 1669 | + * @return array |
|
| 1670 | + */ |
|
| 1671 | + public function get_taxes( $context = 'view' ) { |
|
| 1672 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1673 | 1673 | } |
| 1674 | 1674 | |
| 1675 | 1675 | /** |
| 1676 | - * Get the invoice items. |
|
| 1677 | - * |
|
| 1678 | - * @since 1.0.19 |
|
| 1679 | - * @param string $context View or edit context. |
|
| 1680 | - * @return GetPaid_Form_Item[] |
|
| 1681 | - */ |
|
| 1682 | - public function get_items( $context = 'view' ) { |
|
| 1676 | + * Get the invoice items. |
|
| 1677 | + * |
|
| 1678 | + * @since 1.0.19 |
|
| 1679 | + * @param string $context View or edit context. |
|
| 1680 | + * @return GetPaid_Form_Item[] |
|
| 1681 | + */ |
|
| 1682 | + public function get_items( $context = 'view' ) { |
|
| 1683 | 1683 | return $this->get_prop( 'items', $context ); |
| 1684 | - } |
|
| 1684 | + } |
|
| 1685 | 1685 | |
| 1686 | - /** |
|
| 1687 | - * Get the invoice item ids. |
|
| 1688 | - * |
|
| 1689 | - * @since 1.0.19 |
|
| 1690 | - * @return string |
|
| 1691 | - */ |
|
| 1692 | - public function get_item_ids() { |
|
| 1693 | - return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
| 1686 | + /** |
|
| 1687 | + * Get the invoice item ids. |
|
| 1688 | + * |
|
| 1689 | + * @since 1.0.19 |
|
| 1690 | + * @return string |
|
| 1691 | + */ |
|
| 1692 | + public function get_item_ids() { |
|
| 1693 | + return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
| 1694 | 1694 | } |
| 1695 | 1695 | |
| 1696 | 1696 | /** |
| 1697 | - * Get the invoice's payment form. |
|
| 1698 | - * |
|
| 1699 | - * @since 1.0.19 |
|
| 1700 | - * @param string $context View or edit context. |
|
| 1701 | - * @return int |
|
| 1702 | - */ |
|
| 1703 | - public function get_payment_form( $context = 'view' ) { |
|
| 1704 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1697 | + * Get the invoice's payment form. |
|
| 1698 | + * |
|
| 1699 | + * @since 1.0.19 |
|
| 1700 | + * @param string $context View or edit context. |
|
| 1701 | + * @return int |
|
| 1702 | + */ |
|
| 1703 | + public function get_payment_form( $context = 'view' ) { |
|
| 1704 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | 1707 | /** |
| 1708 | - * Get the invoice's submission id. |
|
| 1709 | - * |
|
| 1710 | - * @since 1.0.19 |
|
| 1711 | - * @param string $context View or edit context. |
|
| 1712 | - * @return string |
|
| 1713 | - */ |
|
| 1714 | - public function get_submission_id( $context = 'view' ) { |
|
| 1715 | - return $this->get_prop( 'submission_id', $context ); |
|
| 1708 | + * Get the invoice's submission id. |
|
| 1709 | + * |
|
| 1710 | + * @since 1.0.19 |
|
| 1711 | + * @param string $context View or edit context. |
|
| 1712 | + * @return string |
|
| 1713 | + */ |
|
| 1714 | + public function get_submission_id( $context = 'view' ) { |
|
| 1715 | + return $this->get_prop( 'submission_id', $context ); |
|
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | 1718 | /** |
| 1719 | - * Get the invoice's discount code. |
|
| 1720 | - * |
|
| 1721 | - * @since 1.0.19 |
|
| 1722 | - * @param string $context View or edit context. |
|
| 1723 | - * @return string |
|
| 1724 | - */ |
|
| 1725 | - public function get_discount_code( $context = 'view' ) { |
|
| 1726 | - return $this->get_prop( 'discount_code', $context ); |
|
| 1719 | + * Get the invoice's discount code. |
|
| 1720 | + * |
|
| 1721 | + * @since 1.0.19 |
|
| 1722 | + * @param string $context View or edit context. |
|
| 1723 | + * @return string |
|
| 1724 | + */ |
|
| 1725 | + public function get_discount_code( $context = 'view' ) { |
|
| 1726 | + return $this->get_prop( 'discount_code', $context ); |
|
| 1727 | 1727 | } |
| 1728 | 1728 | |
| 1729 | 1729 | /** |
| 1730 | - * Get the invoice's gateway. |
|
| 1731 | - * |
|
| 1732 | - * @since 1.0.19 |
|
| 1733 | - * @param string $context View or edit context. |
|
| 1734 | - * @return string |
|
| 1735 | - */ |
|
| 1736 | - public function get_gateway( $context = 'view' ) { |
|
| 1737 | - return $this->get_prop( 'gateway', $context ); |
|
| 1730 | + * Get the invoice's gateway. |
|
| 1731 | + * |
|
| 1732 | + * @since 1.0.19 |
|
| 1733 | + * @param string $context View or edit context. |
|
| 1734 | + * @return string |
|
| 1735 | + */ |
|
| 1736 | + public function get_gateway( $context = 'view' ) { |
|
| 1737 | + return $this->get_prop( 'gateway', $context ); |
|
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | 1740 | /** |
| 1741 | - * Get the invoice's gateway display title. |
|
| 1742 | - * |
|
| 1743 | - * @since 1.0.19 |
|
| 1744 | - * @return string |
|
| 1745 | - */ |
|
| 1741 | + * Get the invoice's gateway display title. |
|
| 1742 | + * |
|
| 1743 | + * @since 1.0.19 |
|
| 1744 | + * @return string |
|
| 1745 | + */ |
|
| 1746 | 1746 | public function get_gateway_title() { |
| 1747 | 1747 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
| 1748 | 1748 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
| 1749 | 1749 | } |
| 1750 | 1750 | |
| 1751 | 1751 | /** |
| 1752 | - * Get the invoice's transaction id. |
|
| 1753 | - * |
|
| 1754 | - * @since 1.0.19 |
|
| 1755 | - * @param string $context View or edit context. |
|
| 1756 | - * @return string |
|
| 1757 | - */ |
|
| 1758 | - public function get_transaction_id( $context = 'view' ) { |
|
| 1759 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 1752 | + * Get the invoice's transaction id. |
|
| 1753 | + * |
|
| 1754 | + * @since 1.0.19 |
|
| 1755 | + * @param string $context View or edit context. |
|
| 1756 | + * @return string |
|
| 1757 | + */ |
|
| 1758 | + public function get_transaction_id( $context = 'view' ) { |
|
| 1759 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | 1762 | /** |
| 1763 | - * Get the invoice's currency. |
|
| 1764 | - * |
|
| 1765 | - * @since 1.0.19 |
|
| 1766 | - * @param string $context View or edit context. |
|
| 1767 | - * @return string |
|
| 1768 | - */ |
|
| 1769 | - public function get_currency( $context = 'view' ) { |
|
| 1763 | + * Get the invoice's currency. |
|
| 1764 | + * |
|
| 1765 | + * @since 1.0.19 |
|
| 1766 | + * @param string $context View or edit context. |
|
| 1767 | + * @return string |
|
| 1768 | + */ |
|
| 1769 | + public function get_currency( $context = 'view' ) { |
|
| 1770 | 1770 | $currency = $this->get_prop( 'currency', $context ); |
| 1771 | 1771 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
| 1772 | 1772 | } |
| 1773 | 1773 | |
| 1774 | 1774 | /** |
| 1775 | - * Checks if we are charging taxes for this invoice. |
|
| 1776 | - * |
|
| 1777 | - * @since 1.0.19 |
|
| 1778 | - * @param string $context View or edit context. |
|
| 1779 | - * @return bool |
|
| 1780 | - */ |
|
| 1781 | - public function get_disable_taxes( $context = 'view' ) { |
|
| 1775 | + * Checks if we are charging taxes for this invoice. |
|
| 1776 | + * |
|
| 1777 | + * @since 1.0.19 |
|
| 1778 | + * @param string $context View or edit context. |
|
| 1779 | + * @return bool |
|
| 1780 | + */ |
|
| 1781 | + public function get_disable_taxes( $context = 'view' ) { |
|
| 1782 | 1782 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
| 1783 | 1783 | } |
| 1784 | 1784 | |
| 1785 | 1785 | /** |
| 1786 | - * Retrieves the subscription id for an invoice. |
|
| 1787 | - * |
|
| 1788 | - * @since 1.0.19 |
|
| 1789 | - * @param string $context View or edit context. |
|
| 1790 | - * @return int |
|
| 1791 | - */ |
|
| 1786 | + * Retrieves the subscription id for an invoice. |
|
| 1787 | + * |
|
| 1788 | + * @since 1.0.19 |
|
| 1789 | + * @param string $context View or edit context. |
|
| 1790 | + * @return int |
|
| 1791 | + */ |
|
| 1792 | 1792 | public function get_subscription_id( $context = 'view' ) { |
| 1793 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1794 | - } |
|
| 1795 | - |
|
| 1796 | - /** |
|
| 1797 | - * Retrieves the remote subscription id for an invoice. |
|
| 1798 | - * |
|
| 1799 | - * @since 1.0.19 |
|
| 1800 | - * @param string $context View or edit context. |
|
| 1801 | - * @return int |
|
| 1802 | - */ |
|
| 1793 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1794 | + } |
|
| 1795 | + |
|
| 1796 | + /** |
|
| 1797 | + * Retrieves the remote subscription id for an invoice. |
|
| 1798 | + * |
|
| 1799 | + * @since 1.0.19 |
|
| 1800 | + * @param string $context View or edit context. |
|
| 1801 | + * @return int |
|
| 1802 | + */ |
|
| 1803 | 1803 | public function get_remote_subscription_id( $context = 'view' ) { |
| 1804 | 1804 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
| 1805 | 1805 | |
@@ -1812,12 +1812,12 @@ discard block |
||
| 1812 | 1812 | } |
| 1813 | 1813 | |
| 1814 | 1814 | /** |
| 1815 | - * Retrieves the payment meta for an invoice. |
|
| 1816 | - * |
|
| 1817 | - * @since 1.0.19 |
|
| 1818 | - * @param string $context View or edit context. |
|
| 1819 | - * @return array |
|
| 1820 | - */ |
|
| 1815 | + * Retrieves the payment meta for an invoice. |
|
| 1816 | + * |
|
| 1817 | + * @since 1.0.19 |
|
| 1818 | + * @param string $context View or edit context. |
|
| 1819 | + * @return array |
|
| 1820 | + */ |
|
| 1821 | 1821 | public function get_payment_meta( $context = 'view' ) { |
| 1822 | 1822 | |
| 1823 | 1823 | return array( |
@@ -1837,31 +1837,31 @@ discard block |
||
| 1837 | 1837 | } |
| 1838 | 1838 | |
| 1839 | 1839 | /** |
| 1840 | - * Retrieves the cart details for an invoice. |
|
| 1841 | - * |
|
| 1842 | - * @since 1.0.19 |
|
| 1843 | - * @return array |
|
| 1844 | - */ |
|
| 1840 | + * Retrieves the cart details for an invoice. |
|
| 1841 | + * |
|
| 1842 | + * @since 1.0.19 |
|
| 1843 | + * @return array |
|
| 1844 | + */ |
|
| 1845 | 1845 | public function get_cart_details() { |
| 1846 | 1846 | $items = $this->get_items(); |
| 1847 | 1847 | $cart_details = array(); |
| 1848 | 1848 | |
| 1849 | 1849 | foreach ( $items as $item ) { |
| 1850 | - $item->invoice_id = $this->get_id(); |
|
| 1850 | + $item->invoice_id = $this->get_id(); |
|
| 1851 | 1851 | $cart_details[] = $item->prepare_data_for_saving(); |
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | 1854 | return $cart_details; |
| 1855 | - } |
|
| 1855 | + } |
|
| 1856 | 1856 | |
| 1857 | - /** |
|
| 1858 | - * Retrieves the recurring item. |
|
| 1859 | - * |
|
| 1860 | - * @return null|GetPaid_Form_Item|int |
|
| 1861 | - */ |
|
| 1862 | - public function get_recurring( $object = false ) { |
|
| 1857 | + /** |
|
| 1858 | + * Retrieves the recurring item. |
|
| 1859 | + * |
|
| 1860 | + * @return null|GetPaid_Form_Item|int |
|
| 1861 | + */ |
|
| 1862 | + public function get_recurring( $object = false ) { |
|
| 1863 | 1863 | |
| 1864 | - // Are we returning an object? |
|
| 1864 | + // Are we returning an object? |
|
| 1865 | 1865 | if ( $object ) { |
| 1866 | 1866 | return $this->get_item( $this->recurring_item ); |
| 1867 | 1867 | } |
@@ -1869,124 +1869,124 @@ discard block |
||
| 1869 | 1869 | return $this->recurring_item; |
| 1870 | 1870 | } |
| 1871 | 1871 | |
| 1872 | - /** |
|
| 1873 | - * Retrieves the subscription name. |
|
| 1874 | - * |
|
| 1875 | - * @since 1.0.19 |
|
| 1876 | - * @return string |
|
| 1877 | - */ |
|
| 1878 | - public function get_subscription_name() { |
|
| 1872 | + /** |
|
| 1873 | + * Retrieves the subscription name. |
|
| 1874 | + * |
|
| 1875 | + * @since 1.0.19 |
|
| 1876 | + * @return string |
|
| 1877 | + */ |
|
| 1878 | + public function get_subscription_name() { |
|
| 1879 | 1879 | |
| 1880 | - // Retrieve the recurring name |
|
| 1880 | + // Retrieve the recurring name |
|
| 1881 | 1881 | $item = $this->get_recurring( true ); |
| 1882 | 1882 | |
| 1883 | - // Abort if it does not exist. |
|
| 1883 | + // Abort if it does not exist. |
|
| 1884 | 1884 | if ( empty( $item ) ) { |
| 1885 | 1885 | return ''; |
| 1886 | 1886 | } |
| 1887 | 1887 | |
| 1888 | - // Return the item name. |
|
| 1888 | + // Return the item name. |
|
| 1889 | 1889 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
| 1890 | - } |
|
| 1891 | - |
|
| 1892 | - /** |
|
| 1893 | - * Retrieves the view url. |
|
| 1894 | - * |
|
| 1895 | - * @since 1.0.19 |
|
| 1896 | - * @return string |
|
| 1897 | - */ |
|
| 1898 | - public function get_view_url() { |
|
| 1890 | + } |
|
| 1891 | + |
|
| 1892 | + /** |
|
| 1893 | + * Retrieves the view url. |
|
| 1894 | + * |
|
| 1895 | + * @since 1.0.19 |
|
| 1896 | + * @return string |
|
| 1897 | + */ |
|
| 1898 | + public function get_view_url() { |
|
| 1899 | 1899 | $invoice_url = get_permalink( $this->get_id() ); |
| 1900 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1900 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1901 | 1901 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
| 1902 | - } |
|
| 1902 | + } |
|
| 1903 | 1903 | |
| 1904 | - /** |
|
| 1905 | - * Retrieves the payment url. |
|
| 1906 | - * |
|
| 1907 | - * @since 1.0.19 |
|
| 1908 | - * @return string |
|
| 1909 | - */ |
|
| 1910 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1904 | + /** |
|
| 1905 | + * Retrieves the payment url. |
|
| 1906 | + * |
|
| 1907 | + * @since 1.0.19 |
|
| 1908 | + * @return string |
|
| 1909 | + */ |
|
| 1910 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1911 | 1911 | |
| 1912 | - // Retrieve the checkout url. |
|
| 1912 | + // Retrieve the checkout url. |
|
| 1913 | 1913 | $pay_url = wpinv_get_checkout_uri(); |
| 1914 | 1914 | |
| 1915 | - // Maybe force ssl. |
|
| 1915 | + // Maybe force ssl. |
|
| 1916 | 1916 | if ( is_ssl() ) { |
| 1917 | 1917 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
| 1918 | 1918 | } |
| 1919 | 1919 | |
| 1920 | - // Add the invoice key. |
|
| 1921 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1920 | + // Add the invoice key. |
|
| 1921 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1922 | 1922 | |
| 1923 | - // (Maybe?) add a secret |
|
| 1923 | + // (Maybe?) add a secret |
|
| 1924 | 1924 | if ( $secret ) { |
| 1925 | 1925 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
| 1926 | 1926 | } |
| 1927 | 1927 | |
| 1928 | 1928 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
| 1929 | - } |
|
| 1929 | + } |
|
| 1930 | 1930 | |
| 1931 | - /** |
|
| 1932 | - * Retrieves the receipt url. |
|
| 1933 | - * |
|
| 1934 | - * @since 1.0.19 |
|
| 1935 | - * @return string |
|
| 1936 | - */ |
|
| 1937 | - public function get_receipt_url() { |
|
| 1938 | - |
|
| 1939 | - // Retrieve the checkout url. |
|
| 1931 | + /** |
|
| 1932 | + * Retrieves the receipt url. |
|
| 1933 | + * |
|
| 1934 | + * @since 1.0.19 |
|
| 1935 | + * @return string |
|
| 1936 | + */ |
|
| 1937 | + public function get_receipt_url() { |
|
| 1938 | + |
|
| 1939 | + // Retrieve the checkout url. |
|
| 1940 | 1940 | $receipt_url = wpinv_get_success_page_uri(); |
| 1941 | 1941 | |
| 1942 | - // Maybe force ssl. |
|
| 1942 | + // Maybe force ssl. |
|
| 1943 | 1943 | if ( is_ssl() ) { |
| 1944 | 1944 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
| 1945 | 1945 | } |
| 1946 | 1946 | |
| 1947 | - // Add the invoice key. |
|
| 1948 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1947 | + // Add the invoice key. |
|
| 1948 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1949 | 1949 | |
| 1950 | 1950 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - /** |
|
| 1954 | - * Retrieves the remote transaction url. |
|
| 1955 | - * |
|
| 1956 | - * @since 1.6.0 |
|
| 1957 | - * @return string |
|
| 1958 | - */ |
|
| 1959 | - public function get_transaction_url() { |
|
| 1960 | - return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
| 1961 | - } |
|
| 1962 | - |
|
| 1963 | - /** |
|
| 1964 | - * Retrieves the default status. |
|
| 1965 | - * |
|
| 1966 | - * @since 1.0.19 |
|
| 1967 | - * @return string |
|
| 1968 | - */ |
|
| 1969 | - public function get_default_status() { |
|
| 1970 | - |
|
| 1971 | - $type = $this->get_type(); |
|
| 1972 | - $status = "wpi-$type-pending"; |
|
| 1973 | - return str_replace( '-invoice', '', $status ); |
|
| 1974 | - |
|
| 1975 | - } |
|
| 1976 | - |
|
| 1977 | - /** |
|
| 1978 | - * Magic method for accessing invoice properties. |
|
| 1979 | - * |
|
| 1980 | - * @since 1.0.15 |
|
| 1981 | - * @access public |
|
| 1982 | - * |
|
| 1983 | - * @param string $key Discount data to retrieve |
|
| 1984 | - * @param string $context View or edit context. |
|
| 1985 | - * @return mixed Value of the given invoice property (if set). |
|
| 1986 | - */ |
|
| 1987 | - public function get( $key, $context = 'view' ) { |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + /** |
|
| 1954 | + * Retrieves the remote transaction url. |
|
| 1955 | + * |
|
| 1956 | + * @since 1.6.0 |
|
| 1957 | + * @return string |
|
| 1958 | + */ |
|
| 1959 | + public function get_transaction_url() { |
|
| 1960 | + return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
| 1961 | + } |
|
| 1962 | + |
|
| 1963 | + /** |
|
| 1964 | + * Retrieves the default status. |
|
| 1965 | + * |
|
| 1966 | + * @since 1.0.19 |
|
| 1967 | + * @return string |
|
| 1968 | + */ |
|
| 1969 | + public function get_default_status() { |
|
| 1970 | + |
|
| 1971 | + $type = $this->get_type(); |
|
| 1972 | + $status = "wpi-$type-pending"; |
|
| 1973 | + return str_replace( '-invoice', '', $status ); |
|
| 1974 | + |
|
| 1975 | + } |
|
| 1976 | + |
|
| 1977 | + /** |
|
| 1978 | + * Magic method for accessing invoice properties. |
|
| 1979 | + * |
|
| 1980 | + * @since 1.0.15 |
|
| 1981 | + * @access public |
|
| 1982 | + * |
|
| 1983 | + * @param string $key Discount data to retrieve |
|
| 1984 | + * @param string $context View or edit context. |
|
| 1985 | + * @return mixed Value of the given invoice property (if set). |
|
| 1986 | + */ |
|
| 1987 | + public function get( $key, $context = 'view' ) { |
|
| 1988 | 1988 | return $this->get_prop( $key, $context ); |
| 1989 | - } |
|
| 1989 | + } |
|
| 1990 | 1990 | |
| 1991 | 1991 | /* |
| 1992 | 1992 | |-------------------------------------------------------------------------- |
@@ -1999,130 +1999,130 @@ discard block |
||
| 1999 | 1999 | */ |
| 2000 | 2000 | |
| 2001 | 2001 | /** |
| 2002 | - * Magic method for setting invoice properties. |
|
| 2003 | - * |
|
| 2004 | - * @since 1.0.19 |
|
| 2005 | - * @access public |
|
| 2006 | - * |
|
| 2007 | - * @param string $key Discount data to retrieve |
|
| 2008 | - * @param mixed $value new value. |
|
| 2009 | - * @return mixed Value of the given invoice property (if set). |
|
| 2010 | - */ |
|
| 2011 | - public function set( $key, $value ) { |
|
| 2002 | + * Magic method for setting invoice properties. |
|
| 2003 | + * |
|
| 2004 | + * @since 1.0.19 |
|
| 2005 | + * @access public |
|
| 2006 | + * |
|
| 2007 | + * @param string $key Discount data to retrieve |
|
| 2008 | + * @param mixed $value new value. |
|
| 2009 | + * @return mixed Value of the given invoice property (if set). |
|
| 2010 | + */ |
|
| 2011 | + public function set( $key, $value ) { |
|
| 2012 | 2012 | |
| 2013 | 2013 | $setter = "set_$key"; |
| 2014 | 2014 | if ( is_callable( array( $this, $setter ) ) ) { |
| 2015 | 2015 | $this->{$setter}( $value ); |
| 2016 | 2016 | } |
| 2017 | 2017 | |
| 2018 | - } |
|
| 2018 | + } |
|
| 2019 | 2019 | |
| 2020 | - /** |
|
| 2021 | - * Sets item status. |
|
| 2022 | - * |
|
| 2023 | - * @since 1.0.19 |
|
| 2024 | - * @param string $new_status New status. |
|
| 2025 | - * @param string $note Optional note to add. |
|
| 2026 | - * @param bool $manual_update Is this a manual status change?. |
|
| 2027 | - * @return array details of change. |
|
| 2028 | - */ |
|
| 2029 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 2030 | - $old_status = $this->get_status(); |
|
| 2020 | + /** |
|
| 2021 | + * Sets item status. |
|
| 2022 | + * |
|
| 2023 | + * @since 1.0.19 |
|
| 2024 | + * @param string $new_status New status. |
|
| 2025 | + * @param string $note Optional note to add. |
|
| 2026 | + * @param bool $manual_update Is this a manual status change?. |
|
| 2027 | + * @return array details of change. |
|
| 2028 | + */ |
|
| 2029 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 2030 | + $old_status = $this->get_status(); |
|
| 2031 | 2031 | |
| 2032 | - $statuses = $this->get_all_statuses(); |
|
| 2032 | + $statuses = $this->get_all_statuses(); |
|
| 2033 | 2033 | |
| 2034 | - if ( isset( $statuses[ 'draft' ] ) ) { |
|
| 2035 | - unset( $statuses[ 'draft' ] ); |
|
| 2036 | - } |
|
| 2034 | + if ( isset( $statuses[ 'draft' ] ) ) { |
|
| 2035 | + unset( $statuses[ 'draft' ] ); |
|
| 2036 | + } |
|
| 2037 | 2037 | |
| 2038 | - $this->set_prop( 'status', $new_status ); |
|
| 2038 | + $this->set_prop( 'status', $new_status ); |
|
| 2039 | 2039 | |
| 2040 | - // If setting the status, ensure it's set to a valid status. |
|
| 2041 | - if ( true === $this->object_read ) { |
|
| 2040 | + // If setting the status, ensure it's set to a valid status. |
|
| 2041 | + if ( true === $this->object_read ) { |
|
| 2042 | 2042 | |
| 2043 | - // Only allow valid new status. |
|
| 2044 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2045 | - $new_status = $this->get_default_status(); |
|
| 2046 | - } |
|
| 2043 | + // Only allow valid new status. |
|
| 2044 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2045 | + $new_status = $this->get_default_status(); |
|
| 2046 | + } |
|
| 2047 | 2047 | |
| 2048 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 2049 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2050 | - $old_status = $this->get_default_status(); |
|
| 2051 | - } |
|
| 2048 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 2049 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2050 | + $old_status = $this->get_default_status(); |
|
| 2051 | + } |
|
| 2052 | 2052 | |
| 2053 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 2054 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 2055 | - $old_status = 'wpi-pending'; |
|
| 2056 | - } |
|
| 2053 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 2054 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 2055 | + $old_status = 'wpi-pending'; |
|
| 2056 | + } |
|
| 2057 | 2057 | |
| 2058 | - if ( $old_status !== $new_status ) { |
|
| 2059 | - $this->status_transition = array( |
|
| 2060 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 2061 | - 'to' => $new_status, |
|
| 2062 | - 'note' => $note, |
|
| 2063 | - 'manual' => (bool) $manual_update, |
|
| 2064 | - ); |
|
| 2058 | + if ( $old_status !== $new_status ) { |
|
| 2059 | + $this->status_transition = array( |
|
| 2060 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 2061 | + 'to' => $new_status, |
|
| 2062 | + 'note' => $note, |
|
| 2063 | + 'manual' => (bool) $manual_update, |
|
| 2064 | + ); |
|
| 2065 | 2065 | |
| 2066 | - if ( $manual_update ) { |
|
| 2067 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
| 2068 | - } |
|
| 2066 | + if ( $manual_update ) { |
|
| 2067 | + do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
| 2068 | + } |
|
| 2069 | 2069 | |
| 2070 | - $this->maybe_set_date_paid(); |
|
| 2070 | + $this->maybe_set_date_paid(); |
|
| 2071 | 2071 | |
| 2072 | - } |
|
| 2072 | + } |
|
| 2073 | 2073 | |
| 2074 | - } |
|
| 2074 | + } |
|
| 2075 | 2075 | |
| 2076 | - return array( |
|
| 2077 | - 'from' => $old_status, |
|
| 2078 | - 'to' => $new_status, |
|
| 2079 | - ); |
|
| 2080 | - } |
|
| 2076 | + return array( |
|
| 2077 | + 'from' => $old_status, |
|
| 2078 | + 'to' => $new_status, |
|
| 2079 | + ); |
|
| 2080 | + } |
|
| 2081 | 2081 | |
| 2082 | - /** |
|
| 2083 | - * Maybe set date paid. |
|
| 2084 | - * |
|
| 2085 | - * Sets the date paid variable when transitioning to the payment complete |
|
| 2086 | - * order status. |
|
| 2087 | - * |
|
| 2088 | - * @since 1.0.19 |
|
| 2089 | - */ |
|
| 2090 | - public function maybe_set_date_paid() { |
|
| 2082 | + /** |
|
| 2083 | + * Maybe set date paid. |
|
| 2084 | + * |
|
| 2085 | + * Sets the date paid variable when transitioning to the payment complete |
|
| 2086 | + * order status. |
|
| 2087 | + * |
|
| 2088 | + * @since 1.0.19 |
|
| 2089 | + */ |
|
| 2090 | + public function maybe_set_date_paid() { |
|
| 2091 | 2091 | |
| 2092 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 2093 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 2094 | - } |
|
| 2095 | - } |
|
| 2092 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 2093 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 2094 | + } |
|
| 2095 | + } |
|
| 2096 | 2096 | |
| 2097 | 2097 | /** |
| 2098 | - * Set parent invoice ID. |
|
| 2099 | - * |
|
| 2100 | - * @since 1.0.19 |
|
| 2101 | - */ |
|
| 2102 | - public function set_parent_id( $value ) { |
|
| 2103 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
| 2104 | - return; |
|
| 2105 | - } |
|
| 2106 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 2098 | + * Set parent invoice ID. |
|
| 2099 | + * |
|
| 2100 | + * @since 1.0.19 |
|
| 2101 | + */ |
|
| 2102 | + public function set_parent_id( $value ) { |
|
| 2103 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
| 2104 | + return; |
|
| 2105 | + } |
|
| 2106 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 2107 | 2107 | } |
| 2108 | 2108 | |
| 2109 | 2109 | /** |
| 2110 | - * Set plugin version when the invoice was created. |
|
| 2111 | - * |
|
| 2112 | - * @since 1.0.19 |
|
| 2113 | - */ |
|
| 2114 | - public function set_version( $value ) { |
|
| 2115 | - $this->set_prop( 'version', $value ); |
|
| 2110 | + * Set plugin version when the invoice was created. |
|
| 2111 | + * |
|
| 2112 | + * @since 1.0.19 |
|
| 2113 | + */ |
|
| 2114 | + public function set_version( $value ) { |
|
| 2115 | + $this->set_prop( 'version', $value ); |
|
| 2116 | 2116 | } |
| 2117 | - |
|
| 2118 | - /** |
|
| 2119 | - * Set date when the invoice was created. |
|
| 2120 | - * |
|
| 2121 | - * @since 1.0.19 |
|
| 2122 | - * @param string $value Value to set. |
|
| 2117 | + |
|
| 2118 | + /** |
|
| 2119 | + * Set date when the invoice was created. |
|
| 2120 | + * |
|
| 2121 | + * @since 1.0.19 |
|
| 2122 | + * @param string $value Value to set. |
|
| 2123 | 2123 | * @return bool Whether or not the date was set. |
| 2124 | - */ |
|
| 2125 | - public function set_date_created( $value ) { |
|
| 2124 | + */ |
|
| 2125 | + public function set_date_created( $value ) { |
|
| 2126 | 2126 | $date = strtotime( $value ); |
| 2127 | 2127 | |
| 2128 | 2128 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2130,19 +2130,19 @@ discard block |
||
| 2130 | 2130 | return true; |
| 2131 | 2131 | } |
| 2132 | 2132 | |
| 2133 | - $this->set_prop( 'date_created', '' ); |
|
| 2134 | - return false; |
|
| 2133 | + $this->set_prop( 'date_created', '' ); |
|
| 2134 | + return false; |
|
| 2135 | 2135 | |
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | 2138 | /** |
| 2139 | - * Set date invoice due date. |
|
| 2140 | - * |
|
| 2141 | - * @since 1.0.19 |
|
| 2142 | - * @param string $value Value to set. |
|
| 2139 | + * Set date invoice due date. |
|
| 2140 | + * |
|
| 2141 | + * @since 1.0.19 |
|
| 2142 | + * @param string $value Value to set. |
|
| 2143 | 2143 | * @return bool Whether or not the date was set. |
| 2144 | - */ |
|
| 2145 | - public function set_due_date( $value ) { |
|
| 2144 | + */ |
|
| 2145 | + public function set_due_date( $value ) { |
|
| 2146 | 2146 | $date = strtotime( $value ); |
| 2147 | 2147 | |
| 2148 | 2148 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2150,29 +2150,29 @@ discard block |
||
| 2150 | 2150 | return true; |
| 2151 | 2151 | } |
| 2152 | 2152 | |
| 2153 | - $this->set_prop( 'due_date', '' ); |
|
| 2153 | + $this->set_prop( 'due_date', '' ); |
|
| 2154 | 2154 | return false; |
| 2155 | 2155 | |
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | 2158 | /** |
| 2159 | - * Alias of self::set_due_date(). |
|
| 2160 | - * |
|
| 2161 | - * @since 1.0.19 |
|
| 2162 | - * @param string $value New name. |
|
| 2163 | - */ |
|
| 2164 | - public function set_date_due( $value ) { |
|
| 2165 | - $this->set_due_date( $value ); |
|
| 2159 | + * Alias of self::set_due_date(). |
|
| 2160 | + * |
|
| 2161 | + * @since 1.0.19 |
|
| 2162 | + * @param string $value New name. |
|
| 2163 | + */ |
|
| 2164 | + public function set_date_due( $value ) { |
|
| 2165 | + $this->set_due_date( $value ); |
|
| 2166 | 2166 | } |
| 2167 | 2167 | |
| 2168 | 2168 | /** |
| 2169 | - * Set date invoice was completed. |
|
| 2170 | - * |
|
| 2171 | - * @since 1.0.19 |
|
| 2172 | - * @param string $value Value to set. |
|
| 2169 | + * Set date invoice was completed. |
|
| 2170 | + * |
|
| 2171 | + * @since 1.0.19 |
|
| 2172 | + * @param string $value Value to set. |
|
| 2173 | 2173 | * @return bool Whether or not the date was set. |
| 2174 | - */ |
|
| 2175 | - public function set_completed_date( $value ) { |
|
| 2174 | + */ |
|
| 2175 | + public function set_completed_date( $value ) { |
|
| 2176 | 2176 | $date = strtotime( $value ); |
| 2177 | 2177 | |
| 2178 | 2178 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2180,29 +2180,29 @@ discard block |
||
| 2180 | 2180 | return true; |
| 2181 | 2181 | } |
| 2182 | 2182 | |
| 2183 | - $this->set_prop( 'completed_date', '' ); |
|
| 2183 | + $this->set_prop( 'completed_date', '' ); |
|
| 2184 | 2184 | return false; |
| 2185 | 2185 | |
| 2186 | 2186 | } |
| 2187 | 2187 | |
| 2188 | 2188 | /** |
| 2189 | - * Alias of self::set_completed_date(). |
|
| 2190 | - * |
|
| 2191 | - * @since 1.0.19 |
|
| 2192 | - * @param string $value New name. |
|
| 2193 | - */ |
|
| 2194 | - public function set_date_completed( $value ) { |
|
| 2195 | - $this->set_completed_date( $value ); |
|
| 2189 | + * Alias of self::set_completed_date(). |
|
| 2190 | + * |
|
| 2191 | + * @since 1.0.19 |
|
| 2192 | + * @param string $value New name. |
|
| 2193 | + */ |
|
| 2194 | + public function set_date_completed( $value ) { |
|
| 2195 | + $this->set_completed_date( $value ); |
|
| 2196 | 2196 | } |
| 2197 | 2197 | |
| 2198 | 2198 | /** |
| 2199 | - * Set date when the invoice was last modified. |
|
| 2200 | - * |
|
| 2201 | - * @since 1.0.19 |
|
| 2202 | - * @param string $value Value to set. |
|
| 2199 | + * Set date when the invoice was last modified. |
|
| 2200 | + * |
|
| 2201 | + * @since 1.0.19 |
|
| 2202 | + * @param string $value Value to set. |
|
| 2203 | 2203 | * @return bool Whether or not the date was set. |
| 2204 | - */ |
|
| 2205 | - public function set_date_modified( $value ) { |
|
| 2204 | + */ |
|
| 2205 | + public function set_date_modified( $value ) { |
|
| 2206 | 2206 | $date = strtotime( $value ); |
| 2207 | 2207 | |
| 2208 | 2208 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2210,813 +2210,813 @@ discard block |
||
| 2210 | 2210 | return true; |
| 2211 | 2211 | } |
| 2212 | 2212 | |
| 2213 | - $this->set_prop( 'date_modified', '' ); |
|
| 2213 | + $this->set_prop( 'date_modified', '' ); |
|
| 2214 | 2214 | return false; |
| 2215 | 2215 | |
| 2216 | 2216 | } |
| 2217 | 2217 | |
| 2218 | 2218 | /** |
| 2219 | - * Set the invoice number. |
|
| 2220 | - * |
|
| 2221 | - * @since 1.0.19 |
|
| 2222 | - * @param string $value New number. |
|
| 2223 | - */ |
|
| 2224 | - public function set_number( $value ) { |
|
| 2219 | + * Set the invoice number. |
|
| 2220 | + * |
|
| 2221 | + * @since 1.0.19 |
|
| 2222 | + * @param string $value New number. |
|
| 2223 | + */ |
|
| 2224 | + public function set_number( $value ) { |
|
| 2225 | 2225 | $number = sanitize_text_field( $value ); |
| 2226 | - $this->set_prop( 'number', $number ); |
|
| 2226 | + $this->set_prop( 'number', $number ); |
|
| 2227 | 2227 | } |
| 2228 | 2228 | |
| 2229 | 2229 | /** |
| 2230 | - * Set the invoice type. |
|
| 2231 | - * |
|
| 2232 | - * @since 1.0.19 |
|
| 2233 | - * @param string $value Type. |
|
| 2234 | - */ |
|
| 2235 | - public function set_type( $value ) { |
|
| 2230 | + * Set the invoice type. |
|
| 2231 | + * |
|
| 2232 | + * @since 1.0.19 |
|
| 2233 | + * @param string $value Type. |
|
| 2234 | + */ |
|
| 2235 | + public function set_type( $value ) { |
|
| 2236 | 2236 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
| 2237 | - $this->set_prop( 'type', $type ); |
|
| 2238 | - } |
|
| 2237 | + $this->set_prop( 'type', $type ); |
|
| 2238 | + } |
|
| 2239 | 2239 | |
| 2240 | 2240 | /** |
| 2241 | - * Set the invoice post type. |
|
| 2242 | - * |
|
| 2243 | - * @since 1.0.19 |
|
| 2244 | - * @param string $value Post type. |
|
| 2245 | - */ |
|
| 2246 | - public function set_post_type( $value ) { |
|
| 2241 | + * Set the invoice post type. |
|
| 2242 | + * |
|
| 2243 | + * @since 1.0.19 |
|
| 2244 | + * @param string $value Post type. |
|
| 2245 | + */ |
|
| 2246 | + public function set_post_type( $value ) { |
|
| 2247 | 2247 | if ( getpaid_is_invoice_post_type( $value ) ) { |
| 2248 | - $this->set_type( $value ); |
|
| 2248 | + $this->set_type( $value ); |
|
| 2249 | 2249 | $this->set_prop( 'post_type', $value ); |
| 2250 | 2250 | } |
| 2251 | 2251 | } |
| 2252 | 2252 | |
| 2253 | 2253 | /** |
| 2254 | - * Set the invoice key. |
|
| 2255 | - * |
|
| 2256 | - * @since 1.0.19 |
|
| 2257 | - * @param string $value New key. |
|
| 2258 | - */ |
|
| 2259 | - public function set_key( $value ) { |
|
| 2254 | + * Set the invoice key. |
|
| 2255 | + * |
|
| 2256 | + * @since 1.0.19 |
|
| 2257 | + * @param string $value New key. |
|
| 2258 | + */ |
|
| 2259 | + public function set_key( $value ) { |
|
| 2260 | 2260 | $key = sanitize_text_field( $value ); |
| 2261 | - $this->set_prop( 'key', $key ); |
|
| 2261 | + $this->set_prop( 'key', $key ); |
|
| 2262 | 2262 | } |
| 2263 | 2263 | |
| 2264 | 2264 | /** |
| 2265 | - * Set the invoice mode. |
|
| 2266 | - * |
|
| 2267 | - * @since 1.0.19 |
|
| 2268 | - * @param string $value mode. |
|
| 2269 | - */ |
|
| 2270 | - public function set_mode( $value ) { |
|
| 2265 | + * Set the invoice mode. |
|
| 2266 | + * |
|
| 2267 | + * @since 1.0.19 |
|
| 2268 | + * @param string $value mode. |
|
| 2269 | + */ |
|
| 2270 | + public function set_mode( $value ) { |
|
| 2271 | 2271 | if ( in_array( $value, array( 'live', 'test' ) ) ) { |
| 2272 | 2272 | $this->set_prop( 'mode', $value ); |
| 2273 | 2273 | } |
| 2274 | 2274 | } |
| 2275 | 2275 | |
| 2276 | 2276 | /** |
| 2277 | - * Set the invoice path. |
|
| 2278 | - * |
|
| 2279 | - * @since 1.0.19 |
|
| 2280 | - * @param string $value path. |
|
| 2281 | - */ |
|
| 2282 | - public function set_path( $value ) { |
|
| 2277 | + * Set the invoice path. |
|
| 2278 | + * |
|
| 2279 | + * @since 1.0.19 |
|
| 2280 | + * @param string $value path. |
|
| 2281 | + */ |
|
| 2282 | + public function set_path( $value ) { |
|
| 2283 | 2283 | $this->set_prop( 'path', $value ); |
| 2284 | 2284 | } |
| 2285 | 2285 | |
| 2286 | 2286 | /** |
| 2287 | - * Set the invoice name. |
|
| 2288 | - * |
|
| 2289 | - * @since 1.0.19 |
|
| 2290 | - * @param string $value New name. |
|
| 2291 | - */ |
|
| 2292 | - public function set_name( $value ) { |
|
| 2287 | + * Set the invoice name. |
|
| 2288 | + * |
|
| 2289 | + * @since 1.0.19 |
|
| 2290 | + * @param string $value New name. |
|
| 2291 | + */ |
|
| 2292 | + public function set_name( $value ) { |
|
| 2293 | 2293 | $name = sanitize_text_field( $value ); |
| 2294 | - $this->set_prop( 'name', $name ); |
|
| 2294 | + $this->set_prop( 'name', $name ); |
|
| 2295 | 2295 | } |
| 2296 | 2296 | |
| 2297 | 2297 | /** |
| 2298 | - * Alias of self::set_name(). |
|
| 2299 | - * |
|
| 2300 | - * @since 1.0.19 |
|
| 2301 | - * @param string $value New name. |
|
| 2302 | - */ |
|
| 2303 | - public function set_title( $value ) { |
|
| 2304 | - $this->set_name( $value ); |
|
| 2298 | + * Alias of self::set_name(). |
|
| 2299 | + * |
|
| 2300 | + * @since 1.0.19 |
|
| 2301 | + * @param string $value New name. |
|
| 2302 | + */ |
|
| 2303 | + public function set_title( $value ) { |
|
| 2304 | + $this->set_name( $value ); |
|
| 2305 | 2305 | } |
| 2306 | 2306 | |
| 2307 | 2307 | /** |
| 2308 | - * Set the invoice description. |
|
| 2309 | - * |
|
| 2310 | - * @since 1.0.19 |
|
| 2311 | - * @param string $value New description. |
|
| 2312 | - */ |
|
| 2313 | - public function set_description( $value ) { |
|
| 2308 | + * Set the invoice description. |
|
| 2309 | + * |
|
| 2310 | + * @since 1.0.19 |
|
| 2311 | + * @param string $value New description. |
|
| 2312 | + */ |
|
| 2313 | + public function set_description( $value ) { |
|
| 2314 | 2314 | $description = wp_kses_post( $value ); |
| 2315 | - $this->set_prop( 'description', $description ); |
|
| 2315 | + $this->set_prop( 'description', $description ); |
|
| 2316 | + } |
|
| 2317 | + |
|
| 2318 | + /** |
|
| 2319 | + * Alias of self::set_description(). |
|
| 2320 | + * |
|
| 2321 | + * @since 1.0.19 |
|
| 2322 | + * @param string $value New description. |
|
| 2323 | + */ |
|
| 2324 | + public function set_excerpt( $value ) { |
|
| 2325 | + $this->set_description( $value ); |
|
| 2326 | + } |
|
| 2327 | + |
|
| 2328 | + /** |
|
| 2329 | + * Alias of self::set_description(). |
|
| 2330 | + * |
|
| 2331 | + * @since 1.0.19 |
|
| 2332 | + * @param string $value New description. |
|
| 2333 | + */ |
|
| 2334 | + public function set_summary( $value ) { |
|
| 2335 | + $this->set_description( $value ); |
|
| 2336 | + } |
|
| 2337 | + |
|
| 2338 | + /** |
|
| 2339 | + * Set the receiver of the invoice. |
|
| 2340 | + * |
|
| 2341 | + * @since 1.0.19 |
|
| 2342 | + * @param int $value New author. |
|
| 2343 | + */ |
|
| 2344 | + public function set_author( $value ) { |
|
| 2345 | + $user = get_user_by( 'id', (int) $value ); |
|
| 2346 | + |
|
| 2347 | + if ( $user && $user->ID ) { |
|
| 2348 | + $this->set_prop( 'author', $user->ID ); |
|
| 2349 | + $this->set_prop( 'email', $user->user_email ); |
|
| 2350 | + } |
|
| 2351 | + |
|
| 2352 | + } |
|
| 2353 | + |
|
| 2354 | + /** |
|
| 2355 | + * Alias of self::set_author(). |
|
| 2356 | + * |
|
| 2357 | + * @since 1.0.19 |
|
| 2358 | + * @param int $value New user id. |
|
| 2359 | + */ |
|
| 2360 | + public function set_user_id( $value ) { |
|
| 2361 | + $this->set_author( $value ); |
|
| 2362 | + } |
|
| 2363 | + |
|
| 2364 | + /** |
|
| 2365 | + * Alias of self::set_author(). |
|
| 2366 | + * |
|
| 2367 | + * @since 1.0.19 |
|
| 2368 | + * @param int $value New user id. |
|
| 2369 | + */ |
|
| 2370 | + public function set_customer_id( $value ) { |
|
| 2371 | + $this->set_author( $value ); |
|
| 2372 | + } |
|
| 2373 | + |
|
| 2374 | + /** |
|
| 2375 | + * Set the customer's ip. |
|
| 2376 | + * |
|
| 2377 | + * @since 1.0.19 |
|
| 2378 | + * @param string $value ip address. |
|
| 2379 | + */ |
|
| 2380 | + public function set_ip( $value ) { |
|
| 2381 | + $this->set_prop( 'ip', $value ); |
|
| 2382 | + } |
|
| 2383 | + |
|
| 2384 | + /** |
|
| 2385 | + * Alias of self::set_ip(). |
|
| 2386 | + * |
|
| 2387 | + * @since 1.0.19 |
|
| 2388 | + * @param string $value ip address. |
|
| 2389 | + */ |
|
| 2390 | + public function set_user_ip( $value ) { |
|
| 2391 | + $this->set_ip( $value ); |
|
| 2392 | + } |
|
| 2393 | + |
|
| 2394 | + /** |
|
| 2395 | + * Set the customer's first name. |
|
| 2396 | + * |
|
| 2397 | + * @since 1.0.19 |
|
| 2398 | + * @param string $value first name. |
|
| 2399 | + */ |
|
| 2400 | + public function set_first_name( $value ) { |
|
| 2401 | + $this->set_prop( 'first_name', $value ); |
|
| 2402 | + } |
|
| 2403 | + |
|
| 2404 | + /** |
|
| 2405 | + * Alias of self::set_first_name(). |
|
| 2406 | + * |
|
| 2407 | + * @since 1.0.19 |
|
| 2408 | + * @param string $value first name. |
|
| 2409 | + */ |
|
| 2410 | + public function set_user_first_name( $value ) { |
|
| 2411 | + $this->set_first_name( $value ); |
|
| 2412 | + } |
|
| 2413 | + |
|
| 2414 | + /** |
|
| 2415 | + * Alias of self::set_first_name(). |
|
| 2416 | + * |
|
| 2417 | + * @since 1.0.19 |
|
| 2418 | + * @param string $value first name. |
|
| 2419 | + */ |
|
| 2420 | + public function set_customer_first_name( $value ) { |
|
| 2421 | + $this->set_first_name( $value ); |
|
| 2422 | + } |
|
| 2423 | + |
|
| 2424 | + /** |
|
| 2425 | + * Set the customer's last name. |
|
| 2426 | + * |
|
| 2427 | + * @since 1.0.19 |
|
| 2428 | + * @param string $value last name. |
|
| 2429 | + */ |
|
| 2430 | + public function set_last_name( $value ) { |
|
| 2431 | + $this->set_prop( 'last_name', $value ); |
|
| 2432 | + } |
|
| 2433 | + |
|
| 2434 | + /** |
|
| 2435 | + * Alias of self::set_last_name(). |
|
| 2436 | + * |
|
| 2437 | + * @since 1.0.19 |
|
| 2438 | + * @param string $value last name. |
|
| 2439 | + */ |
|
| 2440 | + public function set_user_last_name( $value ) { |
|
| 2441 | + $this->set_last_name( $value ); |
|
| 2442 | + } |
|
| 2443 | + |
|
| 2444 | + /** |
|
| 2445 | + * Alias of self::set_last_name(). |
|
| 2446 | + * |
|
| 2447 | + * @since 1.0.19 |
|
| 2448 | + * @param string $value last name. |
|
| 2449 | + */ |
|
| 2450 | + public function set_customer_last_name( $value ) { |
|
| 2451 | + $this->set_last_name( $value ); |
|
| 2452 | + } |
|
| 2453 | + |
|
| 2454 | + /** |
|
| 2455 | + * Set the customer's phone number. |
|
| 2456 | + * |
|
| 2457 | + * @since 1.0.19 |
|
| 2458 | + * @param string $value phone. |
|
| 2459 | + */ |
|
| 2460 | + public function set_phone( $value ) { |
|
| 2461 | + $this->set_prop( 'phone', $value ); |
|
| 2316 | 2462 | } |
| 2317 | 2463 | |
| 2318 | 2464 | /** |
| 2319 | - * Alias of self::set_description(). |
|
| 2320 | - * |
|
| 2321 | - * @since 1.0.19 |
|
| 2322 | - * @param string $value New description. |
|
| 2323 | - */ |
|
| 2324 | - public function set_excerpt( $value ) { |
|
| 2325 | - $this->set_description( $value ); |
|
| 2465 | + * Alias of self::set_phone(). |
|
| 2466 | + * |
|
| 2467 | + * @since 1.0.19 |
|
| 2468 | + * @param string $value phone. |
|
| 2469 | + */ |
|
| 2470 | + public function set_user_phone( $value ) { |
|
| 2471 | + $this->set_phone( $value ); |
|
| 2326 | 2472 | } |
| 2327 | 2473 | |
| 2328 | 2474 | /** |
| 2329 | - * Alias of self::set_description(). |
|
| 2330 | - * |
|
| 2331 | - * @since 1.0.19 |
|
| 2332 | - * @param string $value New description. |
|
| 2333 | - */ |
|
| 2334 | - public function set_summary( $value ) { |
|
| 2335 | - $this->set_description( $value ); |
|
| 2475 | + * Alias of self::set_phone(). |
|
| 2476 | + * |
|
| 2477 | + * @since 1.0.19 |
|
| 2478 | + * @param string $value phone. |
|
| 2479 | + */ |
|
| 2480 | + public function set_customer_phone( $value ) { |
|
| 2481 | + $this->set_phone( $value ); |
|
| 2336 | 2482 | } |
| 2337 | 2483 | |
| 2338 | 2484 | /** |
| 2339 | - * Set the receiver of the invoice. |
|
| 2340 | - * |
|
| 2341 | - * @since 1.0.19 |
|
| 2342 | - * @param int $value New author. |
|
| 2343 | - */ |
|
| 2344 | - public function set_author( $value ) { |
|
| 2345 | - $user = get_user_by( 'id', (int) $value ); |
|
| 2485 | + * Alias of self::set_phone(). |
|
| 2486 | + * |
|
| 2487 | + * @since 1.0.19 |
|
| 2488 | + * @param string $value phone. |
|
| 2489 | + */ |
|
| 2490 | + public function set_phone_number( $value ) { |
|
| 2491 | + $this->set_phone( $value ); |
|
| 2492 | + } |
|
| 2346 | 2493 | |
| 2347 | - if ( $user && $user->ID ) { |
|
| 2348 | - $this->set_prop( 'author', $user->ID ); |
|
| 2349 | - $this->set_prop( 'email', $user->user_email ); |
|
| 2350 | - } |
|
| 2494 | + /** |
|
| 2495 | + * Set the customer's email address. |
|
| 2496 | + * |
|
| 2497 | + * @since 1.0.19 |
|
| 2498 | + * @param string $value email address. |
|
| 2499 | + */ |
|
| 2500 | + public function set_email( $value ) { |
|
| 2501 | + $this->set_prop( 'email', $value ); |
|
| 2502 | + } |
|
| 2351 | 2503 | |
| 2504 | + /** |
|
| 2505 | + * Alias of self::set_email(). |
|
| 2506 | + * |
|
| 2507 | + * @since 1.0.19 |
|
| 2508 | + * @param string $value email address. |
|
| 2509 | + */ |
|
| 2510 | + public function set_user_email( $value ) { |
|
| 2511 | + $this->set_email( $value ); |
|
| 2352 | 2512 | } |
| 2353 | 2513 | |
| 2354 | 2514 | /** |
| 2355 | - * Alias of self::set_author(). |
|
| 2356 | - * |
|
| 2357 | - * @since 1.0.19 |
|
| 2358 | - * @param int $value New user id. |
|
| 2359 | - */ |
|
| 2360 | - public function set_user_id( $value ) { |
|
| 2361 | - $this->set_author( $value ); |
|
| 2515 | + * Alias of self::set_email(). |
|
| 2516 | + * |
|
| 2517 | + * @since 1.0.19 |
|
| 2518 | + * @param string $value email address. |
|
| 2519 | + */ |
|
| 2520 | + public function set_email_address( $value ) { |
|
| 2521 | + $this->set_email( $value ); |
|
| 2362 | 2522 | } |
| 2363 | 2523 | |
| 2364 | 2524 | /** |
| 2365 | - * Alias of self::set_author(). |
|
| 2366 | - * |
|
| 2367 | - * @since 1.0.19 |
|
| 2368 | - * @param int $value New user id. |
|
| 2369 | - */ |
|
| 2370 | - public function set_customer_id( $value ) { |
|
| 2371 | - $this->set_author( $value ); |
|
| 2525 | + * Alias of self::set_email(). |
|
| 2526 | + * |
|
| 2527 | + * @since 1.0.19 |
|
| 2528 | + * @param string $value email address. |
|
| 2529 | + */ |
|
| 2530 | + public function set_customer_email( $value ) { |
|
| 2531 | + $this->set_email( $value ); |
|
| 2372 | 2532 | } |
| 2373 | 2533 | |
| 2374 | 2534 | /** |
| 2375 | - * Set the customer's ip. |
|
| 2376 | - * |
|
| 2377 | - * @since 1.0.19 |
|
| 2378 | - * @param string $value ip address. |
|
| 2379 | - */ |
|
| 2380 | - public function set_ip( $value ) { |
|
| 2381 | - $this->set_prop( 'ip', $value ); |
|
| 2535 | + * Set the customer's country. |
|
| 2536 | + * |
|
| 2537 | + * @since 1.0.19 |
|
| 2538 | + * @param string $value country. |
|
| 2539 | + */ |
|
| 2540 | + public function set_country( $value ) { |
|
| 2541 | + $this->set_prop( 'country', $value ); |
|
| 2382 | 2542 | } |
| 2383 | 2543 | |
| 2384 | 2544 | /** |
| 2385 | - * Alias of self::set_ip(). |
|
| 2386 | - * |
|
| 2387 | - * @since 1.0.19 |
|
| 2388 | - * @param string $value ip address. |
|
| 2389 | - */ |
|
| 2390 | - public function set_user_ip( $value ) { |
|
| 2391 | - $this->set_ip( $value ); |
|
| 2545 | + * Alias of self::set_country(). |
|
| 2546 | + * |
|
| 2547 | + * @since 1.0.19 |
|
| 2548 | + * @param string $value country. |
|
| 2549 | + */ |
|
| 2550 | + public function set_user_country( $value ) { |
|
| 2551 | + $this->set_country( $value ); |
|
| 2392 | 2552 | } |
| 2393 | 2553 | |
| 2394 | 2554 | /** |
| 2395 | - * Set the customer's first name. |
|
| 2396 | - * |
|
| 2397 | - * @since 1.0.19 |
|
| 2398 | - * @param string $value first name. |
|
| 2399 | - */ |
|
| 2400 | - public function set_first_name( $value ) { |
|
| 2401 | - $this->set_prop( 'first_name', $value ); |
|
| 2555 | + * Alias of self::set_country(). |
|
| 2556 | + * |
|
| 2557 | + * @since 1.0.19 |
|
| 2558 | + * @param string $value country. |
|
| 2559 | + */ |
|
| 2560 | + public function set_customer_country( $value ) { |
|
| 2561 | + $this->set_country( $value ); |
|
| 2402 | 2562 | } |
| 2403 | 2563 | |
| 2404 | 2564 | /** |
| 2405 | - * Alias of self::set_first_name(). |
|
| 2406 | - * |
|
| 2407 | - * @since 1.0.19 |
|
| 2408 | - * @param string $value first name. |
|
| 2409 | - */ |
|
| 2410 | - public function set_user_first_name( $value ) { |
|
| 2411 | - $this->set_first_name( $value ); |
|
| 2565 | + * Set the customer's state. |
|
| 2566 | + * |
|
| 2567 | + * @since 1.0.19 |
|
| 2568 | + * @param string $value state. |
|
| 2569 | + */ |
|
| 2570 | + public function set_state( $value ) { |
|
| 2571 | + $this->set_prop( 'state', $value ); |
|
| 2412 | 2572 | } |
| 2413 | 2573 | |
| 2414 | 2574 | /** |
| 2415 | - * Alias of self::set_first_name(). |
|
| 2416 | - * |
|
| 2417 | - * @since 1.0.19 |
|
| 2418 | - * @param string $value first name. |
|
| 2419 | - */ |
|
| 2420 | - public function set_customer_first_name( $value ) { |
|
| 2421 | - $this->set_first_name( $value ); |
|
| 2575 | + * Alias of self::set_state(). |
|
| 2576 | + * |
|
| 2577 | + * @since 1.0.19 |
|
| 2578 | + * @param string $value state. |
|
| 2579 | + */ |
|
| 2580 | + public function set_user_state( $value ) { |
|
| 2581 | + $this->set_state( $value ); |
|
| 2422 | 2582 | } |
| 2423 | 2583 | |
| 2424 | 2584 | /** |
| 2425 | - * Set the customer's last name. |
|
| 2426 | - * |
|
| 2427 | - * @since 1.0.19 |
|
| 2428 | - * @param string $value last name. |
|
| 2429 | - */ |
|
| 2430 | - public function set_last_name( $value ) { |
|
| 2431 | - $this->set_prop( 'last_name', $value ); |
|
| 2585 | + * Alias of self::set_state(). |
|
| 2586 | + * |
|
| 2587 | + * @since 1.0.19 |
|
| 2588 | + * @param string $value state. |
|
| 2589 | + */ |
|
| 2590 | + public function set_customer_state( $value ) { |
|
| 2591 | + $this->set_state( $value ); |
|
| 2432 | 2592 | } |
| 2433 | 2593 | |
| 2434 | 2594 | /** |
| 2435 | - * Alias of self::set_last_name(). |
|
| 2436 | - * |
|
| 2437 | - * @since 1.0.19 |
|
| 2438 | - * @param string $value last name. |
|
| 2439 | - */ |
|
| 2440 | - public function set_user_last_name( $value ) { |
|
| 2441 | - $this->set_last_name( $value ); |
|
| 2595 | + * Set the customer's city. |
|
| 2596 | + * |
|
| 2597 | + * @since 1.0.19 |
|
| 2598 | + * @param string $value city. |
|
| 2599 | + */ |
|
| 2600 | + public function set_city( $value ) { |
|
| 2601 | + $this->set_prop( 'city', $value ); |
|
| 2442 | 2602 | } |
| 2443 | 2603 | |
| 2444 | 2604 | /** |
| 2445 | - * Alias of self::set_last_name(). |
|
| 2446 | - * |
|
| 2447 | - * @since 1.0.19 |
|
| 2448 | - * @param string $value last name. |
|
| 2449 | - */ |
|
| 2450 | - public function set_customer_last_name( $value ) { |
|
| 2451 | - $this->set_last_name( $value ); |
|
| 2605 | + * Alias of self::set_city(). |
|
| 2606 | + * |
|
| 2607 | + * @since 1.0.19 |
|
| 2608 | + * @param string $value city. |
|
| 2609 | + */ |
|
| 2610 | + public function set_user_city( $value ) { |
|
| 2611 | + $this->set_city( $value ); |
|
| 2452 | 2612 | } |
| 2453 | 2613 | |
| 2454 | 2614 | /** |
| 2455 | - * Set the customer's phone number. |
|
| 2456 | - * |
|
| 2457 | - * @since 1.0.19 |
|
| 2458 | - * @param string $value phone. |
|
| 2459 | - */ |
|
| 2460 | - public function set_phone( $value ) { |
|
| 2461 | - $this->set_prop( 'phone', $value ); |
|
| 2615 | + * Alias of self::set_city(). |
|
| 2616 | + * |
|
| 2617 | + * @since 1.0.19 |
|
| 2618 | + * @param string $value city. |
|
| 2619 | + */ |
|
| 2620 | + public function set_customer_city( $value ) { |
|
| 2621 | + $this->set_city( $value ); |
|
| 2462 | 2622 | } |
| 2463 | 2623 | |
| 2464 | 2624 | /** |
| 2465 | - * Alias of self::set_phone(). |
|
| 2466 | - * |
|
| 2467 | - * @since 1.0.19 |
|
| 2468 | - * @param string $value phone. |
|
| 2469 | - */ |
|
| 2470 | - public function set_user_phone( $value ) { |
|
| 2471 | - $this->set_phone( $value ); |
|
| 2625 | + * Set the customer's zip code. |
|
| 2626 | + * |
|
| 2627 | + * @since 1.0.19 |
|
| 2628 | + * @param string $value zip. |
|
| 2629 | + */ |
|
| 2630 | + public function set_zip( $value ) { |
|
| 2631 | + $this->set_prop( 'zip', $value ); |
|
| 2472 | 2632 | } |
| 2473 | 2633 | |
| 2474 | 2634 | /** |
| 2475 | - * Alias of self::set_phone(). |
|
| 2476 | - * |
|
| 2477 | - * @since 1.0.19 |
|
| 2478 | - * @param string $value phone. |
|
| 2479 | - */ |
|
| 2480 | - public function set_customer_phone( $value ) { |
|
| 2481 | - $this->set_phone( $value ); |
|
| 2635 | + * Alias of self::set_zip(). |
|
| 2636 | + * |
|
| 2637 | + * @since 1.0.19 |
|
| 2638 | + * @param string $value zip. |
|
| 2639 | + */ |
|
| 2640 | + public function set_user_zip( $value ) { |
|
| 2641 | + $this->set_zip( $value ); |
|
| 2482 | 2642 | } |
| 2483 | 2643 | |
| 2484 | 2644 | /** |
| 2485 | - * Alias of self::set_phone(). |
|
| 2486 | - * |
|
| 2487 | - * @since 1.0.19 |
|
| 2488 | - * @param string $value phone. |
|
| 2489 | - */ |
|
| 2490 | - public function set_phone_number( $value ) { |
|
| 2491 | - $this->set_phone( $value ); |
|
| 2645 | + * Alias of self::set_zip(). |
|
| 2646 | + * |
|
| 2647 | + * @since 1.0.19 |
|
| 2648 | + * @param string $value zip. |
|
| 2649 | + */ |
|
| 2650 | + public function set_customer_zip( $value ) { |
|
| 2651 | + $this->set_zip( $value ); |
|
| 2492 | 2652 | } |
| 2493 | 2653 | |
| 2494 | 2654 | /** |
| 2495 | - * Set the customer's email address. |
|
| 2496 | - * |
|
| 2497 | - * @since 1.0.19 |
|
| 2498 | - * @param string $value email address. |
|
| 2499 | - */ |
|
| 2500 | - public function set_email( $value ) { |
|
| 2501 | - $this->set_prop( 'email', $value ); |
|
| 2655 | + * Set the customer's company. |
|
| 2656 | + * |
|
| 2657 | + * @since 1.0.19 |
|
| 2658 | + * @param string $value company. |
|
| 2659 | + */ |
|
| 2660 | + public function set_company( $value ) { |
|
| 2661 | + $this->set_prop( 'company', $value ); |
|
| 2502 | 2662 | } |
| 2503 | 2663 | |
| 2504 | 2664 | /** |
| 2505 | - * Alias of self::set_email(). |
|
| 2506 | - * |
|
| 2507 | - * @since 1.0.19 |
|
| 2508 | - * @param string $value email address. |
|
| 2509 | - */ |
|
| 2510 | - public function set_user_email( $value ) { |
|
| 2511 | - $this->set_email( $value ); |
|
| 2665 | + * Alias of self::set_company(). |
|
| 2666 | + * |
|
| 2667 | + * @since 1.0.19 |
|
| 2668 | + * @param string $value company. |
|
| 2669 | + */ |
|
| 2670 | + public function set_user_company( $value ) { |
|
| 2671 | + $this->set_company( $value ); |
|
| 2512 | 2672 | } |
| 2513 | 2673 | |
| 2514 | 2674 | /** |
| 2515 | - * Alias of self::set_email(). |
|
| 2516 | - * |
|
| 2517 | - * @since 1.0.19 |
|
| 2518 | - * @param string $value email address. |
|
| 2519 | - */ |
|
| 2520 | - public function set_email_address( $value ) { |
|
| 2521 | - $this->set_email( $value ); |
|
| 2675 | + * Alias of self::set_company(). |
|
| 2676 | + * |
|
| 2677 | + * @since 1.0.19 |
|
| 2678 | + * @param string $value company. |
|
| 2679 | + */ |
|
| 2680 | + public function set_customer_company( $value ) { |
|
| 2681 | + $this->set_company( $value ); |
|
| 2522 | 2682 | } |
| 2523 | 2683 | |
| 2524 | 2684 | /** |
| 2525 | - * Alias of self::set_email(). |
|
| 2526 | - * |
|
| 2527 | - * @since 1.0.19 |
|
| 2528 | - * @param string $value email address. |
|
| 2529 | - */ |
|
| 2530 | - public function set_customer_email( $value ) { |
|
| 2531 | - $this->set_email( $value ); |
|
| 2685 | + * Set the customer's company id. |
|
| 2686 | + * |
|
| 2687 | + * @since 1.0.19 |
|
| 2688 | + * @param string $value company id. |
|
| 2689 | + */ |
|
| 2690 | + public function set_company_id( $value ) { |
|
| 2691 | + $this->set_prop( 'company_id', $value ); |
|
| 2532 | 2692 | } |
| 2533 | 2693 | |
| 2534 | 2694 | /** |
| 2535 | - * Set the customer's country. |
|
| 2536 | - * |
|
| 2537 | - * @since 1.0.19 |
|
| 2538 | - * @param string $value country. |
|
| 2539 | - */ |
|
| 2540 | - public function set_country( $value ) { |
|
| 2541 | - $this->set_prop( 'country', $value ); |
|
| 2695 | + * Set the customer's var number. |
|
| 2696 | + * |
|
| 2697 | + * @since 1.0.19 |
|
| 2698 | + * @param string $value var number. |
|
| 2699 | + */ |
|
| 2700 | + public function set_vat_number( $value ) { |
|
| 2701 | + $this->set_prop( 'vat_number', $value ); |
|
| 2542 | 2702 | } |
| 2543 | 2703 | |
| 2544 | 2704 | /** |
| 2545 | - * Alias of self::set_country(). |
|
| 2546 | - * |
|
| 2547 | - * @since 1.0.19 |
|
| 2548 | - * @param string $value country. |
|
| 2549 | - */ |
|
| 2550 | - public function set_user_country( $value ) { |
|
| 2551 | - $this->set_country( $value ); |
|
| 2705 | + * Alias of self::set_vat_number(). |
|
| 2706 | + * |
|
| 2707 | + * @since 1.0.19 |
|
| 2708 | + * @param string $value var number. |
|
| 2709 | + */ |
|
| 2710 | + public function set_user_vat_number( $value ) { |
|
| 2711 | + $this->set_vat_number( $value ); |
|
| 2552 | 2712 | } |
| 2553 | 2713 | |
| 2554 | 2714 | /** |
| 2555 | - * Alias of self::set_country(). |
|
| 2556 | - * |
|
| 2557 | - * @since 1.0.19 |
|
| 2558 | - * @param string $value country. |
|
| 2559 | - */ |
|
| 2560 | - public function set_customer_country( $value ) { |
|
| 2561 | - $this->set_country( $value ); |
|
| 2715 | + * Alias of self::set_vat_number(). |
|
| 2716 | + * |
|
| 2717 | + * @since 1.0.19 |
|
| 2718 | + * @param string $value var number. |
|
| 2719 | + */ |
|
| 2720 | + public function set_customer_vat_number( $value ) { |
|
| 2721 | + $this->set_vat_number( $value ); |
|
| 2562 | 2722 | } |
| 2563 | 2723 | |
| 2564 | 2724 | /** |
| 2565 | - * Set the customer's state. |
|
| 2566 | - * |
|
| 2567 | - * @since 1.0.19 |
|
| 2568 | - * @param string $value state. |
|
| 2569 | - */ |
|
| 2570 | - public function set_state( $value ) { |
|
| 2571 | - $this->set_prop( 'state', $value ); |
|
| 2725 | + * Set the customer's vat rate. |
|
| 2726 | + * |
|
| 2727 | + * @since 1.0.19 |
|
| 2728 | + * @param string $value var rate. |
|
| 2729 | + */ |
|
| 2730 | + public function set_vat_rate( $value ) { |
|
| 2731 | + $this->set_prop( 'vat_rate', $value ); |
|
| 2572 | 2732 | } |
| 2573 | 2733 | |
| 2574 | 2734 | /** |
| 2575 | - * Alias of self::set_state(). |
|
| 2576 | - * |
|
| 2577 | - * @since 1.0.19 |
|
| 2578 | - * @param string $value state. |
|
| 2579 | - */ |
|
| 2580 | - public function set_user_state( $value ) { |
|
| 2581 | - $this->set_state( $value ); |
|
| 2735 | + * Alias of self::set_vat_rate(). |
|
| 2736 | + * |
|
| 2737 | + * @since 1.0.19 |
|
| 2738 | + * @param string $value var number. |
|
| 2739 | + */ |
|
| 2740 | + public function set_user_vat_rate( $value ) { |
|
| 2741 | + $this->set_vat_rate( $value ); |
|
| 2582 | 2742 | } |
| 2583 | 2743 | |
| 2584 | 2744 | /** |
| 2585 | - * Alias of self::set_state(). |
|
| 2586 | - * |
|
| 2587 | - * @since 1.0.19 |
|
| 2588 | - * @param string $value state. |
|
| 2589 | - */ |
|
| 2590 | - public function set_customer_state( $value ) { |
|
| 2591 | - $this->set_state( $value ); |
|
| 2745 | + * Alias of self::set_vat_rate(). |
|
| 2746 | + * |
|
| 2747 | + * @since 1.0.19 |
|
| 2748 | + * @param string $value var number. |
|
| 2749 | + */ |
|
| 2750 | + public function set_customer_vat_rate( $value ) { |
|
| 2751 | + $this->set_vat_rate( $value ); |
|
| 2592 | 2752 | } |
| 2593 | 2753 | |
| 2594 | 2754 | /** |
| 2595 | - * Set the customer's city. |
|
| 2596 | - * |
|
| 2597 | - * @since 1.0.19 |
|
| 2598 | - * @param string $value city. |
|
| 2599 | - */ |
|
| 2600 | - public function set_city( $value ) { |
|
| 2601 | - $this->set_prop( 'city', $value ); |
|
| 2755 | + * Set the customer's address. |
|
| 2756 | + * |
|
| 2757 | + * @since 1.0.19 |
|
| 2758 | + * @param string $value address. |
|
| 2759 | + */ |
|
| 2760 | + public function set_address( $value ) { |
|
| 2761 | + $this->set_prop( 'address', $value ); |
|
| 2602 | 2762 | } |
| 2603 | 2763 | |
| 2604 | 2764 | /** |
| 2605 | - * Alias of self::set_city(). |
|
| 2606 | - * |
|
| 2607 | - * @since 1.0.19 |
|
| 2608 | - * @param string $value city. |
|
| 2609 | - */ |
|
| 2610 | - public function set_user_city( $value ) { |
|
| 2611 | - $this->set_city( $value ); |
|
| 2765 | + * Alias of self::set_address(). |
|
| 2766 | + * |
|
| 2767 | + * @since 1.0.19 |
|
| 2768 | + * @param string $value address. |
|
| 2769 | + */ |
|
| 2770 | + public function set_user_address( $value ) { |
|
| 2771 | + $this->set_address( $value ); |
|
| 2612 | 2772 | } |
| 2613 | 2773 | |
| 2614 | 2774 | /** |
| 2615 | - * Alias of self::set_city(). |
|
| 2616 | - * |
|
| 2617 | - * @since 1.0.19 |
|
| 2618 | - * @param string $value city. |
|
| 2619 | - */ |
|
| 2620 | - public function set_customer_city( $value ) { |
|
| 2621 | - $this->set_city( $value ); |
|
| 2775 | + * Alias of self::set_address(). |
|
| 2776 | + * |
|
| 2777 | + * @since 1.0.19 |
|
| 2778 | + * @param string $value address. |
|
| 2779 | + */ |
|
| 2780 | + public function set_customer_address( $value ) { |
|
| 2781 | + $this->set_address( $value ); |
|
| 2622 | 2782 | } |
| 2623 | 2783 | |
| 2624 | 2784 | /** |
| 2625 | - * Set the customer's zip code. |
|
| 2626 | - * |
|
| 2627 | - * @since 1.0.19 |
|
| 2628 | - * @param string $value zip. |
|
| 2629 | - */ |
|
| 2630 | - public function set_zip( $value ) { |
|
| 2631 | - $this->set_prop( 'zip', $value ); |
|
| 2785 | + * Set whether the customer has viewed the invoice or not. |
|
| 2786 | + * |
|
| 2787 | + * @since 1.0.19 |
|
| 2788 | + * @param int|bool $value confirmed. |
|
| 2789 | + */ |
|
| 2790 | + public function set_is_viewed( $value ) { |
|
| 2791 | + $this->set_prop( 'is_viewed', $value ); |
|
| 2632 | 2792 | } |
| 2633 | 2793 | |
| 2634 | 2794 | /** |
| 2635 | - * Alias of self::set_zip(). |
|
| 2636 | - * |
|
| 2637 | - * @since 1.0.19 |
|
| 2638 | - * @param string $value zip. |
|
| 2639 | - */ |
|
| 2640 | - public function set_user_zip( $value ) { |
|
| 2641 | - $this->set_zip( $value ); |
|
| 2795 | + * Set extra email recipients. |
|
| 2796 | + * |
|
| 2797 | + * @since 1.0.19 |
|
| 2798 | + * @param string $value email recipients. |
|
| 2799 | + */ |
|
| 2800 | + public function set_email_cc( $value ) { |
|
| 2801 | + $this->set_prop( 'email_cc', $value ); |
|
| 2642 | 2802 | } |
| 2643 | 2803 | |
| 2644 | 2804 | /** |
| 2645 | - * Alias of self::set_zip(). |
|
| 2646 | - * |
|
| 2647 | - * @since 1.0.19 |
|
| 2648 | - * @param string $value zip. |
|
| 2649 | - */ |
|
| 2650 | - public function set_customer_zip( $value ) { |
|
| 2651 | - $this->set_zip( $value ); |
|
| 2805 | + * Set the invoice template. |
|
| 2806 | + * |
|
| 2807 | + * @since 1.0.19 |
|
| 2808 | + * @param string $value template. |
|
| 2809 | + */ |
|
| 2810 | + public function set_template( $value ) { |
|
| 2811 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2812 | + $this->set_prop( 'template', $value ); |
|
| 2813 | + } |
|
| 2652 | 2814 | } |
| 2653 | 2815 | |
| 2654 | 2816 | /** |
| 2655 | - * Set the customer's company. |
|
| 2656 | - * |
|
| 2657 | - * @since 1.0.19 |
|
| 2658 | - * @param string $value company. |
|
| 2659 | - */ |
|
| 2660 | - public function set_company( $value ) { |
|
| 2661 | - $this->set_prop( 'company', $value ); |
|
| 2817 | + * Set the invoice source. |
|
| 2818 | + * |
|
| 2819 | + * @since 1.0.19 |
|
| 2820 | + * @param string $value source. |
|
| 2821 | + * @deprecated |
|
| 2822 | + */ |
|
| 2823 | + public function created_via( $value ) { |
|
| 2824 | + $this->set_created_via( sanitize_text_field( $value ) ); |
|
| 2662 | 2825 | } |
| 2663 | 2826 | |
| 2664 | 2827 | /** |
| 2665 | - * Alias of self::set_company(). |
|
| 2666 | - * |
|
| 2667 | - * @since 1.0.19 |
|
| 2668 | - * @param string $value company. |
|
| 2669 | - */ |
|
| 2670 | - public function set_user_company( $value ) { |
|
| 2671 | - $this->set_company( $value ); |
|
| 2828 | + * Set the invoice source. |
|
| 2829 | + * |
|
| 2830 | + * @since 1.0.19 |
|
| 2831 | + * @param string $value source. |
|
| 2832 | + */ |
|
| 2833 | + public function set_created_via( $value ) { |
|
| 2834 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2672 | 2835 | } |
| 2673 | 2836 | |
| 2674 | 2837 | /** |
| 2675 | - * Alias of self::set_company(). |
|
| 2676 | - * |
|
| 2677 | - * @since 1.0.19 |
|
| 2678 | - * @param string $value company. |
|
| 2679 | - */ |
|
| 2680 | - public function set_customer_company( $value ) { |
|
| 2681 | - $this->set_company( $value ); |
|
| 2682 | - } |
|
| 2683 | - |
|
| 2684 | - /** |
|
| 2685 | - * Set the customer's company id. |
|
| 2686 | - * |
|
| 2687 | - * @since 1.0.19 |
|
| 2688 | - * @param string $value company id. |
|
| 2689 | - */ |
|
| 2690 | - public function set_company_id( $value ) { |
|
| 2691 | - $this->set_prop( 'company_id', $value ); |
|
| 2838 | + * Set the customer's address confirmed status. |
|
| 2839 | + * |
|
| 2840 | + * @since 1.0.19 |
|
| 2841 | + * @param int|bool $value confirmed. |
|
| 2842 | + */ |
|
| 2843 | + public function set_address_confirmed( $value ) { |
|
| 2844 | + $this->set_prop( 'address_confirmed', $value ); |
|
| 2692 | 2845 | } |
| 2693 | 2846 | |
| 2694 | 2847 | /** |
| 2695 | - * Set the customer's var number. |
|
| 2696 | - * |
|
| 2697 | - * @since 1.0.19 |
|
| 2698 | - * @param string $value var number. |
|
| 2699 | - */ |
|
| 2700 | - public function set_vat_number( $value ) { |
|
| 2701 | - $this->set_prop( 'vat_number', $value ); |
|
| 2848 | + * Alias of self::set_address_confirmed(). |
|
| 2849 | + * |
|
| 2850 | + * @since 1.0.19 |
|
| 2851 | + * @param int|bool $value confirmed. |
|
| 2852 | + */ |
|
| 2853 | + public function set_user_address_confirmed( $value ) { |
|
| 2854 | + $this->set_address_confirmed( $value ); |
|
| 2702 | 2855 | } |
| 2703 | 2856 | |
| 2704 | 2857 | /** |
| 2705 | - * Alias of self::set_vat_number(). |
|
| 2706 | - * |
|
| 2707 | - * @since 1.0.19 |
|
| 2708 | - * @param string $value var number. |
|
| 2709 | - */ |
|
| 2710 | - public function set_user_vat_number( $value ) { |
|
| 2711 | - $this->set_vat_number( $value ); |
|
| 2858 | + * Alias of self::set_address_confirmed(). |
|
| 2859 | + * |
|
| 2860 | + * @since 1.0.19 |
|
| 2861 | + * @param int|bool $value confirmed. |
|
| 2862 | + */ |
|
| 2863 | + public function set_customer_address_confirmed( $value ) { |
|
| 2864 | + $this->set_address_confirmed( $value ); |
|
| 2712 | 2865 | } |
| 2713 | 2866 | |
| 2714 | 2867 | /** |
| 2715 | - * Alias of self::set_vat_number(). |
|
| 2716 | - * |
|
| 2717 | - * @since 1.0.19 |
|
| 2718 | - * @param string $value var number. |
|
| 2719 | - */ |
|
| 2720 | - public function set_customer_vat_number( $value ) { |
|
| 2721 | - $this->set_vat_number( $value ); |
|
| 2868 | + * Set the shipping fee |
|
| 2869 | + * |
|
| 2870 | + * @since 1.0.19 |
|
| 2871 | + * @param float $value shipping amount. |
|
| 2872 | + */ |
|
| 2873 | + public function set_shipping( $value ) { |
|
| 2874 | + |
|
| 2875 | + if ( ! is_numeric( $value ) ) { |
|
| 2876 | + return $this->set_prop( 'shipping', null ); |
|
| 2877 | + } |
|
| 2878 | + |
|
| 2879 | + $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
| 2722 | 2880 | } |
| 2723 | 2881 | |
| 2724 | 2882 | /** |
| 2725 | - * Set the customer's vat rate. |
|
| 2726 | - * |
|
| 2727 | - * @since 1.0.19 |
|
| 2728 | - * @param string $value var rate. |
|
| 2729 | - */ |
|
| 2730 | - public function set_vat_rate( $value ) { |
|
| 2731 | - $this->set_prop( 'vat_rate', $value ); |
|
| 2883 | + * Set the invoice sub total. |
|
| 2884 | + * |
|
| 2885 | + * @since 1.0.19 |
|
| 2886 | + * @param float $value sub total. |
|
| 2887 | + */ |
|
| 2888 | + public function set_subtotal( $value ) { |
|
| 2889 | + $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
| 2732 | 2890 | } |
| 2733 | 2891 | |
| 2734 | - /** |
|
| 2735 | - * Alias of self::set_vat_rate(). |
|
| 2736 | - * |
|
| 2737 | - * @since 1.0.19 |
|
| 2738 | - * @param string $value var number. |
|
| 2739 | - */ |
|
| 2740 | - public function set_user_vat_rate( $value ) { |
|
| 2741 | - $this->set_vat_rate( $value ); |
|
| 2742 | - } |
|
| 2743 | - |
|
| 2744 | - /** |
|
| 2745 | - * Alias of self::set_vat_rate(). |
|
| 2746 | - * |
|
| 2747 | - * @since 1.0.19 |
|
| 2748 | - * @param string $value var number. |
|
| 2749 | - */ |
|
| 2750 | - public function set_customer_vat_rate( $value ) { |
|
| 2751 | - $this->set_vat_rate( $value ); |
|
| 2752 | - } |
|
| 2753 | - |
|
| 2754 | - /** |
|
| 2755 | - * Set the customer's address. |
|
| 2756 | - * |
|
| 2757 | - * @since 1.0.19 |
|
| 2758 | - * @param string $value address. |
|
| 2759 | - */ |
|
| 2760 | - public function set_address( $value ) { |
|
| 2761 | - $this->set_prop( 'address', $value ); |
|
| 2762 | - } |
|
| 2763 | - |
|
| 2764 | - /** |
|
| 2765 | - * Alias of self::set_address(). |
|
| 2766 | - * |
|
| 2767 | - * @since 1.0.19 |
|
| 2768 | - * @param string $value address. |
|
| 2769 | - */ |
|
| 2770 | - public function set_user_address( $value ) { |
|
| 2771 | - $this->set_address( $value ); |
|
| 2772 | - } |
|
| 2773 | - |
|
| 2774 | - /** |
|
| 2775 | - * Alias of self::set_address(). |
|
| 2776 | - * |
|
| 2777 | - * @since 1.0.19 |
|
| 2778 | - * @param string $value address. |
|
| 2779 | - */ |
|
| 2780 | - public function set_customer_address( $value ) { |
|
| 2781 | - $this->set_address( $value ); |
|
| 2782 | - } |
|
| 2783 | - |
|
| 2784 | - /** |
|
| 2785 | - * Set whether the customer has viewed the invoice or not. |
|
| 2786 | - * |
|
| 2787 | - * @since 1.0.19 |
|
| 2788 | - * @param int|bool $value confirmed. |
|
| 2789 | - */ |
|
| 2790 | - public function set_is_viewed( $value ) { |
|
| 2791 | - $this->set_prop( 'is_viewed', $value ); |
|
| 2792 | - } |
|
| 2793 | - |
|
| 2794 | - /** |
|
| 2795 | - * Set extra email recipients. |
|
| 2796 | - * |
|
| 2797 | - * @since 1.0.19 |
|
| 2798 | - * @param string $value email recipients. |
|
| 2799 | - */ |
|
| 2800 | - public function set_email_cc( $value ) { |
|
| 2801 | - $this->set_prop( 'email_cc', $value ); |
|
| 2802 | - } |
|
| 2803 | - |
|
| 2804 | - /** |
|
| 2805 | - * Set the invoice template. |
|
| 2806 | - * |
|
| 2807 | - * @since 1.0.19 |
|
| 2808 | - * @param string $value template. |
|
| 2809 | - */ |
|
| 2810 | - public function set_template( $value ) { |
|
| 2811 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2812 | - $this->set_prop( 'template', $value ); |
|
| 2813 | - } |
|
| 2814 | - } |
|
| 2815 | - |
|
| 2816 | - /** |
|
| 2817 | - * Set the invoice source. |
|
| 2818 | - * |
|
| 2819 | - * @since 1.0.19 |
|
| 2820 | - * @param string $value source. |
|
| 2821 | - * @deprecated |
|
| 2822 | - */ |
|
| 2823 | - public function created_via( $value ) { |
|
| 2824 | - $this->set_created_via( sanitize_text_field( $value ) ); |
|
| 2825 | - } |
|
| 2826 | - |
|
| 2827 | - /** |
|
| 2828 | - * Set the invoice source. |
|
| 2829 | - * |
|
| 2830 | - * @since 1.0.19 |
|
| 2831 | - * @param string $value source. |
|
| 2832 | - */ |
|
| 2833 | - public function set_created_via( $value ) { |
|
| 2834 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2835 | - } |
|
| 2836 | - |
|
| 2837 | - /** |
|
| 2838 | - * Set the customer's address confirmed status. |
|
| 2839 | - * |
|
| 2840 | - * @since 1.0.19 |
|
| 2841 | - * @param int|bool $value confirmed. |
|
| 2842 | - */ |
|
| 2843 | - public function set_address_confirmed( $value ) { |
|
| 2844 | - $this->set_prop( 'address_confirmed', $value ); |
|
| 2845 | - } |
|
| 2846 | - |
|
| 2847 | - /** |
|
| 2848 | - * Alias of self::set_address_confirmed(). |
|
| 2849 | - * |
|
| 2850 | - * @since 1.0.19 |
|
| 2851 | - * @param int|bool $value confirmed. |
|
| 2852 | - */ |
|
| 2853 | - public function set_user_address_confirmed( $value ) { |
|
| 2854 | - $this->set_address_confirmed( $value ); |
|
| 2855 | - } |
|
| 2856 | - |
|
| 2857 | - /** |
|
| 2858 | - * Alias of self::set_address_confirmed(). |
|
| 2859 | - * |
|
| 2860 | - * @since 1.0.19 |
|
| 2861 | - * @param int|bool $value confirmed. |
|
| 2862 | - */ |
|
| 2863 | - public function set_customer_address_confirmed( $value ) { |
|
| 2864 | - $this->set_address_confirmed( $value ); |
|
| 2865 | - } |
|
| 2866 | - |
|
| 2867 | - /** |
|
| 2868 | - * Set the shipping fee |
|
| 2869 | - * |
|
| 2870 | - * @since 1.0.19 |
|
| 2871 | - * @param float $value shipping amount. |
|
| 2872 | - */ |
|
| 2873 | - public function set_shipping( $value ) { |
|
| 2874 | - |
|
| 2875 | - if ( ! is_numeric( $value ) ) { |
|
| 2876 | - return $this->set_prop( 'shipping', null ); |
|
| 2877 | - } |
|
| 2878 | - |
|
| 2879 | - $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
| 2880 | - } |
|
| 2881 | - |
|
| 2882 | - /** |
|
| 2883 | - * Set the invoice sub total. |
|
| 2884 | - * |
|
| 2885 | - * @since 1.0.19 |
|
| 2886 | - * @param float $value sub total. |
|
| 2887 | - */ |
|
| 2888 | - public function set_subtotal( $value ) { |
|
| 2889 | - $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
| 2890 | - } |
|
| 2891 | - |
|
| 2892 | - /** |
|
| 2893 | - * Set the invoice total. |
|
| 2894 | - * |
|
| 2895 | - * @since 1.0.19 |
|
| 2896 | - * @param float $value sub total. |
|
| 2897 | - */ |
|
| 2898 | - public function set_total( $value ) { |
|
| 2899 | - $this->set_prop( 'total', max( 0, $value ) ); |
|
| 2892 | + /** |
|
| 2893 | + * Set the invoice total. |
|
| 2894 | + * |
|
| 2895 | + * @since 1.0.19 |
|
| 2896 | + * @param float $value sub total. |
|
| 2897 | + */ |
|
| 2898 | + public function set_total( $value ) { |
|
| 2899 | + $this->set_prop( 'total', max( 0, $value ) ); |
|
| 2900 | 2900 | } |
| 2901 | 2901 | |
| 2902 | 2902 | /** |
| 2903 | - * Set the invoice discount amount. |
|
| 2904 | - * |
|
| 2905 | - * @since 1.0.19 |
|
| 2906 | - * @param float $value discount total. |
|
| 2907 | - */ |
|
| 2908 | - public function set_total_discount( $value ) { |
|
| 2909 | - $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
| 2903 | + * Set the invoice discount amount. |
|
| 2904 | + * |
|
| 2905 | + * @since 1.0.19 |
|
| 2906 | + * @param float $value discount total. |
|
| 2907 | + */ |
|
| 2908 | + public function set_total_discount( $value ) { |
|
| 2909 | + $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
| 2910 | 2910 | } |
| 2911 | 2911 | |
| 2912 | 2912 | /** |
| 2913 | - * Alias of self::set_total_discount(). |
|
| 2914 | - * |
|
| 2915 | - * @since 1.0.19 |
|
| 2916 | - * @param float $value discount total. |
|
| 2917 | - */ |
|
| 2918 | - public function set_discount( $value ) { |
|
| 2919 | - $this->set_total_discount( $value ); |
|
| 2913 | + * Alias of self::set_total_discount(). |
|
| 2914 | + * |
|
| 2915 | + * @since 1.0.19 |
|
| 2916 | + * @param float $value discount total. |
|
| 2917 | + */ |
|
| 2918 | + public function set_discount( $value ) { |
|
| 2919 | + $this->set_total_discount( $value ); |
|
| 2920 | 2920 | } |
| 2921 | 2921 | |
| 2922 | 2922 | /** |
| 2923 | - * Set the invoice tax amount. |
|
| 2924 | - * |
|
| 2925 | - * @since 1.0.19 |
|
| 2926 | - * @param float $value tax total. |
|
| 2927 | - */ |
|
| 2928 | - public function set_total_tax( $value ) { |
|
| 2929 | - $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
| 2923 | + * Set the invoice tax amount. |
|
| 2924 | + * |
|
| 2925 | + * @since 1.0.19 |
|
| 2926 | + * @param float $value tax total. |
|
| 2927 | + */ |
|
| 2928 | + public function set_total_tax( $value ) { |
|
| 2929 | + $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
| 2930 | 2930 | } |
| 2931 | 2931 | |
| 2932 | 2932 | /** |
| 2933 | - * Alias of self::set_total_tax(). |
|
| 2934 | - * |
|
| 2935 | - * @since 1.0.19 |
|
| 2936 | - * @param float $value tax total. |
|
| 2937 | - */ |
|
| 2938 | - public function set_tax_total( $value ) { |
|
| 2939 | - $this->set_total_tax( $value ); |
|
| 2933 | + * Alias of self::set_total_tax(). |
|
| 2934 | + * |
|
| 2935 | + * @since 1.0.19 |
|
| 2936 | + * @param float $value tax total. |
|
| 2937 | + */ |
|
| 2938 | + public function set_tax_total( $value ) { |
|
| 2939 | + $this->set_total_tax( $value ); |
|
| 2940 | 2940 | } |
| 2941 | 2941 | |
| 2942 | 2942 | /** |
| 2943 | - * Set the invoice fees amount. |
|
| 2944 | - * |
|
| 2945 | - * @since 1.0.19 |
|
| 2946 | - * @param float $value fees total. |
|
| 2947 | - */ |
|
| 2948 | - public function set_total_fees( $value ) { |
|
| 2949 | - $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
| 2943 | + * Set the invoice fees amount. |
|
| 2944 | + * |
|
| 2945 | + * @since 1.0.19 |
|
| 2946 | + * @param float $value fees total. |
|
| 2947 | + */ |
|
| 2948 | + public function set_total_fees( $value ) { |
|
| 2949 | + $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
| 2950 | 2950 | } |
| 2951 | 2951 | |
| 2952 | 2952 | /** |
| 2953 | - * Alias of self::set_total_fees(). |
|
| 2954 | - * |
|
| 2955 | - * @since 1.0.19 |
|
| 2956 | - * @param float $value fees total. |
|
| 2957 | - */ |
|
| 2958 | - public function set_fees_total( $value ) { |
|
| 2959 | - $this->set_total_fees( $value ); |
|
| 2953 | + * Alias of self::set_total_fees(). |
|
| 2954 | + * |
|
| 2955 | + * @since 1.0.19 |
|
| 2956 | + * @param float $value fees total. |
|
| 2957 | + */ |
|
| 2958 | + public function set_fees_total( $value ) { |
|
| 2959 | + $this->set_total_fees( $value ); |
|
| 2960 | 2960 | } |
| 2961 | 2961 | |
| 2962 | 2962 | /** |
| 2963 | - * Set the invoice fees. |
|
| 2964 | - * |
|
| 2965 | - * @since 1.0.19 |
|
| 2966 | - * @param array $value fees. |
|
| 2967 | - */ |
|
| 2968 | - public function set_fees( $value ) { |
|
| 2963 | + * Set the invoice fees. |
|
| 2964 | + * |
|
| 2965 | + * @since 1.0.19 |
|
| 2966 | + * @param array $value fees. |
|
| 2967 | + */ |
|
| 2968 | + public function set_fees( $value ) { |
|
| 2969 | 2969 | |
| 2970 | - if ( ! is_array( $value ) ) { |
|
| 2971 | - $value = array(); |
|
| 2972 | - } |
|
| 2970 | + if ( ! is_array( $value ) ) { |
|
| 2971 | + $value = array(); |
|
| 2972 | + } |
|
| 2973 | 2973 | |
| 2974 | - $this->set_prop( 'fees', $value ); |
|
| 2974 | + $this->set_prop( 'fees', $value ); |
|
| 2975 | 2975 | |
| 2976 | 2976 | } |
| 2977 | 2977 | |
| 2978 | 2978 | /** |
| 2979 | - * Set the invoice taxes. |
|
| 2980 | - * |
|
| 2981 | - * @since 1.0.19 |
|
| 2982 | - * @param array $value taxes. |
|
| 2983 | - */ |
|
| 2984 | - public function set_taxes( $value ) { |
|
| 2979 | + * Set the invoice taxes. |
|
| 2980 | + * |
|
| 2981 | + * @since 1.0.19 |
|
| 2982 | + * @param array $value taxes. |
|
| 2983 | + */ |
|
| 2984 | + public function set_taxes( $value ) { |
|
| 2985 | 2985 | |
| 2986 | - if ( ! is_array( $value ) ) { |
|
| 2987 | - $value = array(); |
|
| 2988 | - } |
|
| 2986 | + if ( ! is_array( $value ) ) { |
|
| 2987 | + $value = array(); |
|
| 2988 | + } |
|
| 2989 | 2989 | |
| 2990 | - $this->set_prop( 'taxes', $value ); |
|
| 2990 | + $this->set_prop( 'taxes', $value ); |
|
| 2991 | 2991 | |
| 2992 | 2992 | } |
| 2993 | 2993 | |
| 2994 | 2994 | /** |
| 2995 | - * Set the invoice discounts. |
|
| 2996 | - * |
|
| 2997 | - * @since 1.0.19 |
|
| 2998 | - * @param array $value discounts. |
|
| 2999 | - */ |
|
| 3000 | - public function set_discounts( $value ) { |
|
| 2995 | + * Set the invoice discounts. |
|
| 2996 | + * |
|
| 2997 | + * @since 1.0.19 |
|
| 2998 | + * @param array $value discounts. |
|
| 2999 | + */ |
|
| 3000 | + public function set_discounts( $value ) { |
|
| 3001 | 3001 | |
| 3002 | - if ( ! is_array( $value ) ) { |
|
| 3003 | - $value = array(); |
|
| 3004 | - } |
|
| 3002 | + if ( ! is_array( $value ) ) { |
|
| 3003 | + $value = array(); |
|
| 3004 | + } |
|
| 3005 | 3005 | |
| 3006 | - $this->set_prop( 'discounts', $value ); |
|
| 3006 | + $this->set_prop( 'discounts', $value ); |
|
| 3007 | 3007 | } |
| 3008 | 3008 | |
| 3009 | 3009 | /** |
| 3010 | - * Set the invoice items. |
|
| 3011 | - * |
|
| 3012 | - * @since 1.0.19 |
|
| 3013 | - * @param GetPaid_Form_Item[] $value items. |
|
| 3014 | - */ |
|
| 3015 | - public function set_items( $value ) { |
|
| 3010 | + * Set the invoice items. |
|
| 3011 | + * |
|
| 3012 | + * @since 1.0.19 |
|
| 3013 | + * @param GetPaid_Form_Item[] $value items. |
|
| 3014 | + */ |
|
| 3015 | + public function set_items( $value ) { |
|
| 3016 | 3016 | |
| 3017 | 3017 | // Remove existing items. |
| 3018 | 3018 | $this->set_prop( 'items', array() ); |
| 3019 | - $this->recurring_item = null; |
|
| 3019 | + $this->recurring_item = null; |
|
| 3020 | 3020 | |
| 3021 | 3021 | // Ensure that we have an array. |
| 3022 | 3022 | if ( ! is_array( $value ) ) { |
@@ -3030,95 +3030,95 @@ discard block |
||
| 3030 | 3030 | } |
| 3031 | 3031 | |
| 3032 | 3032 | /** |
| 3033 | - * Set the payment form. |
|
| 3034 | - * |
|
| 3035 | - * @since 1.0.19 |
|
| 3036 | - * @param int $value payment form. |
|
| 3037 | - */ |
|
| 3038 | - public function set_payment_form( $value ) { |
|
| 3039 | - $this->set_prop( 'payment_form', $value ); |
|
| 3033 | + * Set the payment form. |
|
| 3034 | + * |
|
| 3035 | + * @since 1.0.19 |
|
| 3036 | + * @param int $value payment form. |
|
| 3037 | + */ |
|
| 3038 | + public function set_payment_form( $value ) { |
|
| 3039 | + $this->set_prop( 'payment_form', $value ); |
|
| 3040 | 3040 | } |
| 3041 | 3041 | |
| 3042 | 3042 | /** |
| 3043 | - * Set the submission id. |
|
| 3044 | - * |
|
| 3045 | - * @since 1.0.19 |
|
| 3046 | - * @param string $value submission id. |
|
| 3047 | - */ |
|
| 3048 | - public function set_submission_id( $value ) { |
|
| 3049 | - $this->set_prop( 'submission_id', $value ); |
|
| 3043 | + * Set the submission id. |
|
| 3044 | + * |
|
| 3045 | + * @since 1.0.19 |
|
| 3046 | + * @param string $value submission id. |
|
| 3047 | + */ |
|
| 3048 | + public function set_submission_id( $value ) { |
|
| 3049 | + $this->set_prop( 'submission_id', $value ); |
|
| 3050 | 3050 | } |
| 3051 | 3051 | |
| 3052 | 3052 | /** |
| 3053 | - * Set the discount code. |
|
| 3054 | - * |
|
| 3055 | - * @since 1.0.19 |
|
| 3056 | - * @param string $value discount code. |
|
| 3057 | - */ |
|
| 3058 | - public function set_discount_code( $value ) { |
|
| 3059 | - $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
| 3053 | + * Set the discount code. |
|
| 3054 | + * |
|
| 3055 | + * @since 1.0.19 |
|
| 3056 | + * @param string $value discount code. |
|
| 3057 | + */ |
|
| 3058 | + public function set_discount_code( $value ) { |
|
| 3059 | + $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
| 3060 | 3060 | } |
| 3061 | 3061 | |
| 3062 | 3062 | /** |
| 3063 | - * Set the gateway. |
|
| 3064 | - * |
|
| 3065 | - * @since 1.0.19 |
|
| 3066 | - * @param string $value gateway. |
|
| 3067 | - */ |
|
| 3068 | - public function set_gateway( $value ) { |
|
| 3069 | - $this->set_prop( 'gateway', $value ); |
|
| 3063 | + * Set the gateway. |
|
| 3064 | + * |
|
| 3065 | + * @since 1.0.19 |
|
| 3066 | + * @param string $value gateway. |
|
| 3067 | + */ |
|
| 3068 | + public function set_gateway( $value ) { |
|
| 3069 | + $this->set_prop( 'gateway', $value ); |
|
| 3070 | 3070 | } |
| 3071 | 3071 | |
| 3072 | 3072 | /** |
| 3073 | - * Set the transaction id. |
|
| 3074 | - * |
|
| 3075 | - * @since 1.0.19 |
|
| 3076 | - * @param string $value transaction id. |
|
| 3077 | - */ |
|
| 3078 | - public function set_transaction_id( $value ) { |
|
| 3079 | - if ( ! empty( $value ) ) { |
|
| 3080 | - $this->set_prop( 'transaction_id', $value ); |
|
| 3081 | - } |
|
| 3073 | + * Set the transaction id. |
|
| 3074 | + * |
|
| 3075 | + * @since 1.0.19 |
|
| 3076 | + * @param string $value transaction id. |
|
| 3077 | + */ |
|
| 3078 | + public function set_transaction_id( $value ) { |
|
| 3079 | + if ( ! empty( $value ) ) { |
|
| 3080 | + $this->set_prop( 'transaction_id', $value ); |
|
| 3081 | + } |
|
| 3082 | 3082 | } |
| 3083 | 3083 | |
| 3084 | 3084 | /** |
| 3085 | - * Set the currency id. |
|
| 3086 | - * |
|
| 3087 | - * @since 1.0.19 |
|
| 3088 | - * @param string $value currency id. |
|
| 3089 | - */ |
|
| 3090 | - public function set_currency( $value ) { |
|
| 3091 | - $this->set_prop( 'currency', $value ); |
|
| 3085 | + * Set the currency id. |
|
| 3086 | + * |
|
| 3087 | + * @since 1.0.19 |
|
| 3088 | + * @param string $value currency id. |
|
| 3089 | + */ |
|
| 3090 | + public function set_currency( $value ) { |
|
| 3091 | + $this->set_prop( 'currency', $value ); |
|
| 3092 | 3092 | } |
| 3093 | 3093 | |
| 3094 | - /** |
|
| 3095 | - * Set whether to disable taxes. |
|
| 3096 | - * |
|
| 3097 | - * @since 1.0.19 |
|
| 3098 | - * @param bool $value value. |
|
| 3099 | - */ |
|
| 3100 | - public function set_disable_taxes( $value ) { |
|
| 3101 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 3102 | - } |
|
| 3094 | + /** |
|
| 3095 | + * Set whether to disable taxes. |
|
| 3096 | + * |
|
| 3097 | + * @since 1.0.19 |
|
| 3098 | + * @param bool $value value. |
|
| 3099 | + */ |
|
| 3100 | + public function set_disable_taxes( $value ) { |
|
| 3101 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 3102 | + } |
|
| 3103 | 3103 | |
| 3104 | 3104 | /** |
| 3105 | - * Set the subscription id. |
|
| 3106 | - * |
|
| 3107 | - * @since 1.0.19 |
|
| 3108 | - * @param string $value subscription id. |
|
| 3109 | - */ |
|
| 3110 | - public function set_subscription_id( $value ) { |
|
| 3111 | - $this->set_prop( 'subscription_id', $value ); |
|
| 3112 | - } |
|
| 3105 | + * Set the subscription id. |
|
| 3106 | + * |
|
| 3107 | + * @since 1.0.19 |
|
| 3108 | + * @param string $value subscription id. |
|
| 3109 | + */ |
|
| 3110 | + public function set_subscription_id( $value ) { |
|
| 3111 | + $this->set_prop( 'subscription_id', $value ); |
|
| 3112 | + } |
|
| 3113 | 3113 | |
| 3114 | - /** |
|
| 3115 | - * Set the remote subscription id. |
|
| 3116 | - * |
|
| 3117 | - * @since 1.0.19 |
|
| 3118 | - * @param string $value subscription id. |
|
| 3119 | - */ |
|
| 3120 | - public function set_remote_subscription_id( $value ) { |
|
| 3121 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
| 3114 | + /** |
|
| 3115 | + * Set the remote subscription id. |
|
| 3116 | + * |
|
| 3117 | + * @since 1.0.19 |
|
| 3118 | + * @param string $value subscription id. |
|
| 3119 | + */ |
|
| 3120 | + public function set_remote_subscription_id( $value ) { |
|
| 3121 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
| 3122 | 3122 | } |
| 3123 | 3123 | |
| 3124 | 3124 | /* |
@@ -3157,24 +3157,24 @@ discard block |
||
| 3157 | 3157 | */ |
| 3158 | 3158 | public function is_taxable() { |
| 3159 | 3159 | return ! $this->get_disable_taxes(); |
| 3160 | - } |
|
| 3160 | + } |
|
| 3161 | 3161 | |
| 3162 | - /** |
|
| 3163 | - * @deprecated |
|
| 3164 | - */ |
|
| 3165 | - public function has_vat() { |
|
| 3162 | + /** |
|
| 3163 | + * @deprecated |
|
| 3164 | + */ |
|
| 3165 | + public function has_vat() { |
|
| 3166 | 3166 | return $this->is_taxable(); |
| 3167 | - } |
|
| 3167 | + } |
|
| 3168 | 3168 | |
| 3169 | - /** |
|
| 3170 | - * Checks to see if the invoice requires payment. |
|
| 3171 | - */ |
|
| 3172 | - public function is_free() { |
|
| 3169 | + /** |
|
| 3170 | + * Checks to see if the invoice requires payment. |
|
| 3171 | + */ |
|
| 3172 | + public function is_free() { |
|
| 3173 | 3173 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
| 3174 | 3174 | |
| 3175 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 3176 | - $is_free = false; |
|
| 3177 | - } |
|
| 3175 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 3176 | + $is_free = false; |
|
| 3177 | + } |
|
| 3178 | 3178 | |
| 3179 | 3179 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
| 3180 | 3180 | } |
@@ -3185,46 +3185,46 @@ discard block |
||
| 3185 | 3185 | public function is_paid() { |
| 3186 | 3186 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
| 3187 | 3187 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
| 3188 | - } |
|
| 3188 | + } |
|
| 3189 | 3189 | |
| 3190 | - /** |
|
| 3190 | + /** |
|
| 3191 | 3191 | * Checks if the invoice needs payment. |
| 3192 | 3192 | */ |
| 3193 | - public function needs_payment() { |
|
| 3194 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 3193 | + public function needs_payment() { |
|
| 3194 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 3195 | 3195 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
| 3196 | 3196 | } |
| 3197 | 3197 | |
| 3198 | - /** |
|
| 3198 | + /** |
|
| 3199 | 3199 | * Checks if the invoice is refunded. |
| 3200 | 3200 | */ |
| 3201 | - public function is_refunded() { |
|
| 3201 | + public function is_refunded() { |
|
| 3202 | 3202 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
| 3203 | 3203 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
| 3204 | - } |
|
| 3204 | + } |
|
| 3205 | 3205 | |
| 3206 | - /** |
|
| 3206 | + /** |
|
| 3207 | 3207 | * Checks if the invoice is held. |
| 3208 | 3208 | */ |
| 3209 | - public function is_held() { |
|
| 3209 | + public function is_held() { |
|
| 3210 | 3210 | $is_held = $this->has_status( 'wpi-onhold' ); |
| 3211 | 3211 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
| 3212 | - } |
|
| 3212 | + } |
|
| 3213 | 3213 | |
| 3214 | - /** |
|
| 3214 | + /** |
|
| 3215 | 3215 | * Checks if the invoice is due. |
| 3216 | 3216 | */ |
| 3217 | - public function is_due() { |
|
| 3218 | - $due_date = $this->get_due_date(); |
|
| 3219 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3220 | - } |
|
| 3217 | + public function is_due() { |
|
| 3218 | + $due_date = $this->get_due_date(); |
|
| 3219 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3220 | + } |
|
| 3221 | 3221 | |
| 3222 | - /** |
|
| 3222 | + /** |
|
| 3223 | 3223 | * Checks if the invoice is draft. |
| 3224 | 3224 | */ |
| 3225 | - public function is_draft() { |
|
| 3225 | + public function is_draft() { |
|
| 3226 | 3226 | return $this->has_status( 'draft, auto-draft' ); |
| 3227 | - } |
|
| 3227 | + } |
|
| 3228 | 3228 | |
| 3229 | 3229 | /** |
| 3230 | 3230 | * Checks if the invoice has a given status. |
@@ -3232,9 +3232,9 @@ discard block |
||
| 3232 | 3232 | public function has_status( $status ) { |
| 3233 | 3233 | $status = wpinv_parse_list( $status ); |
| 3234 | 3234 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
| 3235 | - } |
|
| 3235 | + } |
|
| 3236 | 3236 | |
| 3237 | - /** |
|
| 3237 | + /** |
|
| 3238 | 3238 | * Checks if the invoice is of a given type. |
| 3239 | 3239 | */ |
| 3240 | 3240 | public function is_type( $type ) { |
@@ -3257,25 +3257,25 @@ discard block |
||
| 3257 | 3257 | */ |
| 3258 | 3258 | public function has_free_trial() { |
| 3259 | 3259 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
| 3260 | - } |
|
| 3260 | + } |
|
| 3261 | 3261 | |
| 3262 | - /** |
|
| 3262 | + /** |
|
| 3263 | 3263 | * @deprecated |
| 3264 | 3264 | */ |
| 3265 | 3265 | public function is_free_trial() { |
| 3266 | 3266 | $this->has_free_trial(); |
| 3267 | 3267 | } |
| 3268 | 3268 | |
| 3269 | - /** |
|
| 3269 | + /** |
|
| 3270 | 3270 | * Check if the initial payment if 0. |
| 3271 | 3271 | * |
| 3272 | 3272 | */ |
| 3273 | - public function is_initial_free() { |
|
| 3273 | + public function is_initial_free() { |
|
| 3274 | 3274 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
| 3275 | 3275 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
| 3276 | 3276 | } |
| 3277 | 3277 | |
| 3278 | - /** |
|
| 3278 | + /** |
|
| 3279 | 3279 | * Check if the recurring item has a free trial. |
| 3280 | 3280 | * |
| 3281 | 3281 | */ |
@@ -3288,21 +3288,21 @@ discard block |
||
| 3288 | 3288 | |
| 3289 | 3289 | $item = $this->get_recurring( true ); |
| 3290 | 3290 | return $item->has_free_trial(); |
| 3291 | - } |
|
| 3291 | + } |
|
| 3292 | 3292 | |
| 3293 | - /** |
|
| 3293 | + /** |
|
| 3294 | 3294 | * Check if the free trial is a result of a discount. |
| 3295 | 3295 | */ |
| 3296 | 3296 | public function is_free_trial_from_discount() { |
| 3297 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3298 | - } |
|
| 3297 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3298 | + } |
|
| 3299 | 3299 | |
| 3300 | - /** |
|
| 3300 | + /** |
|
| 3301 | 3301 | * @deprecated |
| 3302 | 3302 | */ |
| 3303 | 3303 | public function discount_first_payment_only() { |
| 3304 | 3304 | |
| 3305 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3305 | + $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3306 | 3306 | if ( ! $discount->exists() || ! $this->is_recurring() ) { |
| 3307 | 3307 | return true; |
| 3308 | 3308 | } |
@@ -3327,147 +3327,147 @@ discard block |
||
| 3327 | 3327 | */ |
| 3328 | 3328 | public function add_item( $item ) { |
| 3329 | 3329 | |
| 3330 | - if ( is_array( $item ) ) { |
|
| 3331 | - $item = $this->process_array_item( $item ); |
|
| 3332 | - } |
|
| 3330 | + if ( is_array( $item ) ) { |
|
| 3331 | + $item = $this->process_array_item( $item ); |
|
| 3332 | + } |
|
| 3333 | 3333 | |
| 3334 | - if ( is_numeric( $item ) ) { |
|
| 3335 | - $item = new GetPaid_Form_Item( $item ); |
|
| 3336 | - } |
|
| 3334 | + if ( is_numeric( $item ) ) { |
|
| 3335 | + $item = new GetPaid_Form_Item( $item ); |
|
| 3336 | + } |
|
| 3337 | 3337 | |
| 3338 | 3338 | // Make sure that it is available for purchase. |
| 3339 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3340 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3339 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3340 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3341 | 3341 | } |
| 3342 | 3342 | |
| 3343 | 3343 | // Do we have a recurring item? |
| 3344 | - if ( $item->is_recurring() ) { |
|
| 3345 | - $this->recurring_item = $item->get_id(); |
|
| 3344 | + if ( $item->is_recurring() ) { |
|
| 3345 | + $this->recurring_item = $item->get_id(); |
|
| 3346 | 3346 | } |
| 3347 | 3347 | |
| 3348 | 3348 | // Invoice id. |
| 3349 | 3349 | $item->invoice_id = (int) $this->get_id(); |
| 3350 | 3350 | |
| 3351 | - // Remove duplicates. |
|
| 3352 | - $this->remove_item( $item->get_id() ); |
|
| 3351 | + // Remove duplicates. |
|
| 3352 | + $this->remove_item( $item->get_id() ); |
|
| 3353 | 3353 | |
| 3354 | - if ( 0 == $item->get_quantity() ) { |
|
| 3355 | - return; |
|
| 3356 | - } |
|
| 3354 | + if ( 0 == $item->get_quantity() ) { |
|
| 3355 | + return; |
|
| 3356 | + } |
|
| 3357 | 3357 | |
| 3358 | - // Retrieve all items. |
|
| 3358 | + // Retrieve all items. |
|
| 3359 | 3359 | $items = $this->get_items(); |
| 3360 | 3360 | |
| 3361 | - // Add new item. |
|
| 3361 | + // Add new item. |
|
| 3362 | 3362 | $items[] = $item; |
| 3363 | 3363 | |
| 3364 | 3364 | $this->set_prop( 'items', $items ); |
| 3365 | 3365 | |
| 3366 | - return true; |
|
| 3367 | - } |
|
| 3366 | + return true; |
|
| 3367 | + } |
|
| 3368 | 3368 | |
| 3369 | - /** |
|
| 3370 | - * Converts an array to an item. |
|
| 3371 | - * |
|
| 3372 | - * @since 1.0.19 |
|
| 3373 | - * @return GetPaid_Form_Item |
|
| 3374 | - */ |
|
| 3375 | - protected function process_array_item( $array ) { |
|
| 3369 | + /** |
|
| 3370 | + * Converts an array to an item. |
|
| 3371 | + * |
|
| 3372 | + * @since 1.0.19 |
|
| 3373 | + * @return GetPaid_Form_Item |
|
| 3374 | + */ |
|
| 3375 | + protected function process_array_item( $array ) { |
|
| 3376 | 3376 | |
| 3377 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3378 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 3377 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3378 | + $item = new GetPaid_Form_Item( $item_id ); |
|
| 3379 | 3379 | |
| 3380 | - // Set item data. |
|
| 3381 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3382 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3383 | - $method = "set_$key"; |
|
| 3384 | - $item->$method( $array[ "item_$key" ] ); |
|
| 3385 | - } |
|
| 3386 | - } |
|
| 3380 | + // Set item data. |
|
| 3381 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3382 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3383 | + $method = "set_$key"; |
|
| 3384 | + $item->$method( $array[ "item_$key" ] ); |
|
| 3385 | + } |
|
| 3386 | + } |
|
| 3387 | 3387 | |
| 3388 | - if ( isset( $array['quantity'] ) ) { |
|
| 3389 | - $item->set_quantity( $array['quantity'] ); |
|
| 3390 | - } |
|
| 3388 | + if ( isset( $array['quantity'] ) ) { |
|
| 3389 | + $item->set_quantity( $array['quantity'] ); |
|
| 3390 | + } |
|
| 3391 | 3391 | |
| 3392 | - // Set item meta. |
|
| 3393 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3394 | - $item->set_item_meta( $array['meta'] ); |
|
| 3395 | - } |
|
| 3392 | + // Set item meta. |
|
| 3393 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3394 | + $item->set_item_meta( $array['meta'] ); |
|
| 3395 | + } |
|
| 3396 | 3396 | |
| 3397 | - return $item; |
|
| 3397 | + return $item; |
|
| 3398 | 3398 | |
| 3399 | - } |
|
| 3399 | + } |
|
| 3400 | 3400 | |
| 3401 | 3401 | /** |
| 3402 | - * Retrieves a specific item. |
|
| 3403 | - * |
|
| 3404 | - * @since 1.0.19 |
|
| 3405 | - * @return GetPaid_Form_Item|null |
|
| 3406 | - */ |
|
| 3407 | - public function get_item( $item_id ) { |
|
| 3402 | + * Retrieves a specific item. |
|
| 3403 | + * |
|
| 3404 | + * @since 1.0.19 |
|
| 3405 | + * @return GetPaid_Form_Item|null |
|
| 3406 | + */ |
|
| 3407 | + public function get_item( $item_id ) { |
|
| 3408 | 3408 | |
| 3409 | - foreach ( $this->get_items() as $item ) { |
|
| 3410 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3411 | - return $item; |
|
| 3412 | - } |
|
| 3413 | - } |
|
| 3409 | + foreach ( $this->get_items() as $item ) { |
|
| 3410 | + if ( (int) $item_id == $item->get_id() ) { |
|
| 3411 | + return $item; |
|
| 3412 | + } |
|
| 3413 | + } |
|
| 3414 | 3414 | |
| 3415 | - return null; |
|
| 3415 | + return null; |
|
| 3416 | 3416 | } |
| 3417 | 3417 | |
| 3418 | 3418 | /** |
| 3419 | - * Removes a specific item. |
|
| 3420 | - * |
|
| 3421 | - * @since 1.0.19 |
|
| 3422 | - */ |
|
| 3423 | - public function remove_item( $item_id ) { |
|
| 3424 | - $items = $this->get_items(); |
|
| 3425 | - $item_id = (int) $item_id; |
|
| 3419 | + * Removes a specific item. |
|
| 3420 | + * |
|
| 3421 | + * @since 1.0.19 |
|
| 3422 | + */ |
|
| 3423 | + public function remove_item( $item_id ) { |
|
| 3424 | + $items = $this->get_items(); |
|
| 3425 | + $item_id = (int) $item_id; |
|
| 3426 | 3426 | |
| 3427 | - foreach ( $items as $index => $item ) { |
|
| 3428 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3429 | - unset( $items[ $index ] ); |
|
| 3430 | - $this->set_prop( 'items', $items ); |
|
| 3427 | + foreach ( $items as $index => $item ) { |
|
| 3428 | + if ( (int) $item_id == $item->get_id() ) { |
|
| 3429 | + unset( $items[ $index ] ); |
|
| 3430 | + $this->set_prop( 'items', $items ); |
|
| 3431 | 3431 | |
| 3432 | - if ( $item_id == $this->recurring_item ) { |
|
| 3433 | - $this->recurring_item = null; |
|
| 3434 | - } |
|
| 3432 | + if ( $item_id == $this->recurring_item ) { |
|
| 3433 | + $this->recurring_item = null; |
|
| 3434 | + } |
|
| 3435 | 3435 | |
| 3436 | - } |
|
| 3437 | - } |
|
| 3436 | + } |
|
| 3437 | + } |
|
| 3438 | 3438 | |
| 3439 | 3439 | } |
| 3440 | 3440 | |
| 3441 | 3441 | /** |
| 3442 | - * Adds a fee to the invoice. |
|
| 3443 | - * |
|
| 3444 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3445 | - * @since 1.0.19 |
|
| 3446 | - */ |
|
| 3442 | + * Adds a fee to the invoice. |
|
| 3443 | + * |
|
| 3444 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3445 | + * @since 1.0.19 |
|
| 3446 | + */ |
|
| 3447 | 3447 | public function add_fee( $fee ) { |
| 3448 | 3448 | |
| 3449 | - $fees = $this->get_fees(); |
|
| 3450 | - $fees[ $fee['name'] ] = $fee; |
|
| 3451 | - $this->set_prop( 'fees', $fees ); |
|
| 3449 | + $fees = $this->get_fees(); |
|
| 3450 | + $fees[ $fee['name'] ] = $fee; |
|
| 3451 | + $this->set_prop( 'fees', $fees ); |
|
| 3452 | 3452 | |
| 3453 | 3453 | } |
| 3454 | 3454 | |
| 3455 | 3455 | /** |
| 3456 | - * Retrieves a specific fee. |
|
| 3457 | - * |
|
| 3458 | - * @since 1.0.19 |
|
| 3459 | - */ |
|
| 3460 | - public function get_fee( $fee ) { |
|
| 3456 | + * Retrieves a specific fee. |
|
| 3457 | + * |
|
| 3458 | + * @since 1.0.19 |
|
| 3459 | + */ |
|
| 3460 | + public function get_fee( $fee ) { |
|
| 3461 | 3461 | $fees = $this->get_fees(); |
| 3462 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3462 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3463 | 3463 | } |
| 3464 | 3464 | |
| 3465 | 3465 | /** |
| 3466 | - * Removes a specific fee. |
|
| 3467 | - * |
|
| 3468 | - * @since 1.0.19 |
|
| 3469 | - */ |
|
| 3470 | - public function remove_fee( $fee ) { |
|
| 3466 | + * Removes a specific fee. |
|
| 3467 | + * |
|
| 3468 | + * @since 1.0.19 |
|
| 3469 | + */ |
|
| 3470 | + public function remove_fee( $fee ) { |
|
| 3471 | 3471 | $fees = $this->get_fees(); |
| 3472 | 3472 | if ( isset( $fees[ $fee ] ) ) { |
| 3473 | 3473 | unset( $fees[ $fee ] ); |
@@ -3475,55 +3475,55 @@ discard block |
||
| 3475 | 3475 | } |
| 3476 | 3476 | } |
| 3477 | 3477 | |
| 3478 | - /** |
|
| 3479 | - * Adds a discount to the invoice. |
|
| 3480 | - * |
|
| 3481 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 3482 | - * @since 1.0.19 |
|
| 3483 | - */ |
|
| 3484 | - public function add_discount( $discount ) { |
|
| 3478 | + /** |
|
| 3479 | + * Adds a discount to the invoice. |
|
| 3480 | + * |
|
| 3481 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 3482 | + * @since 1.0.19 |
|
| 3483 | + */ |
|
| 3484 | + public function add_discount( $discount ) { |
|
| 3485 | 3485 | |
| 3486 | - $discounts = $this->get_discounts(); |
|
| 3487 | - $discounts[ $discount['name'] ] = $discount; |
|
| 3488 | - $this->set_prop( 'discounts', $discounts ); |
|
| 3486 | + $discounts = $this->get_discounts(); |
|
| 3487 | + $discounts[ $discount['name'] ] = $discount; |
|
| 3488 | + $this->set_prop( 'discounts', $discounts ); |
|
| 3489 | 3489 | |
| 3490 | - } |
|
| 3490 | + } |
|
| 3491 | 3491 | |
| 3492 | 3492 | /** |
| 3493 | - * Retrieves a specific discount. |
|
| 3494 | - * |
|
| 3495 | - * @since 1.0.19 |
|
| 3496 | - * @return float |
|
| 3497 | - */ |
|
| 3498 | - public function get_discount( $discount = false ) { |
|
| 3493 | + * Retrieves a specific discount. |
|
| 3494 | + * |
|
| 3495 | + * @since 1.0.19 |
|
| 3496 | + * @return float |
|
| 3497 | + */ |
|
| 3498 | + public function get_discount( $discount = false ) { |
|
| 3499 | 3499 | |
| 3500 | - // Backwards compatibilty. |
|
| 3501 | - if ( empty( $discount ) ) { |
|
| 3502 | - return $this->get_total_discount(); |
|
| 3503 | - } |
|
| 3500 | + // Backwards compatibilty. |
|
| 3501 | + if ( empty( $discount ) ) { |
|
| 3502 | + return $this->get_total_discount(); |
|
| 3503 | + } |
|
| 3504 | 3504 | |
| 3505 | 3505 | $discounts = $this->get_discounts(); |
| 3506 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3506 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3507 | 3507 | } |
| 3508 | 3508 | |
| 3509 | 3509 | /** |
| 3510 | - * Removes a specific discount. |
|
| 3511 | - * |
|
| 3512 | - * @since 1.0.19 |
|
| 3513 | - */ |
|
| 3514 | - public function remove_discount( $discount ) { |
|
| 3510 | + * Removes a specific discount. |
|
| 3511 | + * |
|
| 3512 | + * @since 1.0.19 |
|
| 3513 | + */ |
|
| 3514 | + public function remove_discount( $discount ) { |
|
| 3515 | 3515 | $discounts = $this->get_discounts(); |
| 3516 | 3516 | if ( isset( $discounts[ $discount ] ) ) { |
| 3517 | 3517 | unset( $discounts[ $discount ] ); |
| 3518 | 3518 | $this->set_prop( 'discounts', $discounts ); |
| 3519 | 3519 | } |
| 3520 | 3520 | |
| 3521 | - if ( 'discount_code' == $discount ) { |
|
| 3522 | - foreach ( $this->get_items() as $item ) { |
|
| 3523 | - $item->item_discount = 0; |
|
| 3524 | - $item->recurring_item_discount = 0; |
|
| 3525 | - } |
|
| 3526 | - } |
|
| 3521 | + if ( 'discount_code' == $discount ) { |
|
| 3522 | + foreach ( $this->get_items() as $item ) { |
|
| 3523 | + $item->item_discount = 0; |
|
| 3524 | + $item->recurring_item_discount = 0; |
|
| 3525 | + } |
|
| 3526 | + } |
|
| 3527 | 3527 | |
| 3528 | 3528 | } |
| 3529 | 3529 | |
@@ -3536,34 +3536,34 @@ discard block |
||
| 3536 | 3536 | if ( $this->is_taxable() ) { |
| 3537 | 3537 | |
| 3538 | 3538 | $taxes = $this->get_taxes(); |
| 3539 | - $taxes[ $tax['name'] ] = $tax; |
|
| 3540 | - $this->set_prop( 'taxes', $tax ); |
|
| 3539 | + $taxes[ $tax['name'] ] = $tax; |
|
| 3540 | + $this->set_prop( 'taxes', $tax ); |
|
| 3541 | 3541 | |
| 3542 | 3542 | } |
| 3543 | 3543 | } |
| 3544 | 3544 | |
| 3545 | 3545 | /** |
| 3546 | - * Retrieves a specific tax. |
|
| 3547 | - * |
|
| 3548 | - * @since 1.0.19 |
|
| 3549 | - */ |
|
| 3550 | - public function get_tax( $tax = null ) { |
|
| 3546 | + * Retrieves a specific tax. |
|
| 3547 | + * |
|
| 3548 | + * @since 1.0.19 |
|
| 3549 | + */ |
|
| 3550 | + public function get_tax( $tax = null ) { |
|
| 3551 | 3551 | |
| 3552 | - // Backwards compatility. |
|
| 3553 | - if ( empty( $tax ) ) { |
|
| 3554 | - return $this->get_total_tax(); |
|
| 3555 | - } |
|
| 3552 | + // Backwards compatility. |
|
| 3553 | + if ( empty( $tax ) ) { |
|
| 3554 | + return $this->get_total_tax(); |
|
| 3555 | + } |
|
| 3556 | 3556 | |
| 3557 | 3557 | $taxes = $this->get_taxes(); |
| 3558 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3558 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3559 | 3559 | } |
| 3560 | 3560 | |
| 3561 | 3561 | /** |
| 3562 | - * Removes a specific tax. |
|
| 3563 | - * |
|
| 3564 | - * @since 1.0.19 |
|
| 3565 | - */ |
|
| 3566 | - public function remove_tax( $tax ) { |
|
| 3562 | + * Removes a specific tax. |
|
| 3563 | + * |
|
| 3564 | + * @since 1.0.19 |
|
| 3565 | + */ |
|
| 3566 | + public function remove_tax( $tax ) { |
|
| 3567 | 3567 | $taxes = $this->get_taxes(); |
| 3568 | 3568 | if ( isset( $taxes[ $tax ] ) ) { |
| 3569 | 3569 | unset( $taxes[ $tax ] ); |
@@ -3572,185 +3572,185 @@ discard block |
||
| 3572 | 3572 | } |
| 3573 | 3573 | |
| 3574 | 3574 | /** |
| 3575 | - * Recalculates the invoice subtotal. |
|
| 3576 | - * |
|
| 3577 | - * @since 1.0.19 |
|
| 3578 | - * @return float The recalculated subtotal |
|
| 3579 | - */ |
|
| 3580 | - public function recalculate_subtotal() { |
|
| 3575 | + * Recalculates the invoice subtotal. |
|
| 3576 | + * |
|
| 3577 | + * @since 1.0.19 |
|
| 3578 | + * @return float The recalculated subtotal |
|
| 3579 | + */ |
|
| 3580 | + public function recalculate_subtotal() { |
|
| 3581 | 3581 | $items = $this->get_items(); |
| 3582 | - $subtotal = 0; |
|
| 3583 | - $recurring = 0; |
|
| 3582 | + $subtotal = 0; |
|
| 3583 | + $recurring = 0; |
|
| 3584 | 3584 | |
| 3585 | 3585 | foreach ( $items as $item ) { |
| 3586 | - $subtotal += $item->get_sub_total( 'edit' ); |
|
| 3587 | - $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
| 3586 | + $subtotal += $item->get_sub_total( 'edit' ); |
|
| 3587 | + $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
| 3588 | 3588 | } |
| 3589 | 3589 | |
| 3590 | - if ( wpinv_prices_include_tax() ) { |
|
| 3591 | - $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
| 3592 | - $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
| 3593 | - } |
|
| 3590 | + if ( wpinv_prices_include_tax() ) { |
|
| 3591 | + $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
| 3592 | + $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
| 3593 | + } |
|
| 3594 | 3594 | |
| 3595 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3596 | - $this->set_subtotal( $current ); |
|
| 3595 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3596 | + $this->set_subtotal( $current ); |
|
| 3597 | 3597 | |
| 3598 | - $this->totals['subtotal'] = array( |
|
| 3599 | - 'initial' => $subtotal, |
|
| 3600 | - 'recurring' => $recurring, |
|
| 3601 | - ); |
|
| 3598 | + $this->totals['subtotal'] = array( |
|
| 3599 | + 'initial' => $subtotal, |
|
| 3600 | + 'recurring' => $recurring, |
|
| 3601 | + ); |
|
| 3602 | 3602 | |
| 3603 | 3603 | return $current; |
| 3604 | 3604 | } |
| 3605 | 3605 | |
| 3606 | 3606 | /** |
| 3607 | - * Recalculates the invoice discount total. |
|
| 3608 | - * |
|
| 3609 | - * @since 1.0.19 |
|
| 3610 | - * @return float The recalculated discount |
|
| 3611 | - */ |
|
| 3612 | - public function recalculate_total_discount() { |
|
| 3607 | + * Recalculates the invoice discount total. |
|
| 3608 | + * |
|
| 3609 | + * @since 1.0.19 |
|
| 3610 | + * @return float The recalculated discount |
|
| 3611 | + */ |
|
| 3612 | + public function recalculate_total_discount() { |
|
| 3613 | 3613 | $discounts = $this->get_discounts(); |
| 3614 | - $discount = 0; |
|
| 3615 | - $recurring = 0; |
|
| 3614 | + $discount = 0; |
|
| 3615 | + $recurring = 0; |
|
| 3616 | 3616 | |
| 3617 | 3617 | foreach ( $discounts as $data ) { |
| 3618 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3619 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3620 | - } |
|
| 3618 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3619 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3620 | + } |
|
| 3621 | 3621 | |
| 3622 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3622 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3623 | 3623 | |
| 3624 | - $this->set_total_discount( $current ); |
|
| 3624 | + $this->set_total_discount( $current ); |
|
| 3625 | 3625 | |
| 3626 | - $this->totals['discount'] = array( |
|
| 3627 | - 'initial' => $discount, |
|
| 3628 | - 'recurring' => $recurring, |
|
| 3629 | - ); |
|
| 3626 | + $this->totals['discount'] = array( |
|
| 3627 | + 'initial' => $discount, |
|
| 3628 | + 'recurring' => $recurring, |
|
| 3629 | + ); |
|
| 3630 | 3630 | |
| 3631 | - return $current; |
|
| 3631 | + return $current; |
|
| 3632 | 3632 | |
| 3633 | 3633 | } |
| 3634 | 3634 | |
| 3635 | 3635 | /** |
| 3636 | - * Recalculates the invoice tax total. |
|
| 3637 | - * |
|
| 3638 | - * @since 1.0.19 |
|
| 3639 | - * @return float The recalculated tax |
|
| 3640 | - */ |
|
| 3641 | - public function recalculate_total_tax() { |
|
| 3636 | + * Recalculates the invoice tax total. |
|
| 3637 | + * |
|
| 3638 | + * @since 1.0.19 |
|
| 3639 | + * @return float The recalculated tax |
|
| 3640 | + */ |
|
| 3641 | + public function recalculate_total_tax() { |
|
| 3642 | 3642 | |
| 3643 | - // Maybe disable taxes. |
|
| 3644 | - $vat_number = $this->get_vat_number(); |
|
| 3645 | - $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
| 3643 | + // Maybe disable taxes. |
|
| 3644 | + $vat_number = $this->get_vat_number(); |
|
| 3645 | + $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
| 3646 | 3646 | |
| 3647 | - if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 3648 | - $skip_tax = false; |
|
| 3649 | - } |
|
| 3647 | + if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 3648 | + $skip_tax = false; |
|
| 3649 | + } |
|
| 3650 | 3650 | |
| 3651 | - if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
| 3651 | + if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
| 3652 | 3652 | |
| 3653 | - $this->totals['tax'] = array( |
|
| 3654 | - 'initial' => 0, |
|
| 3655 | - 'recurring' => 0, |
|
| 3656 | - ); |
|
| 3653 | + $this->totals['tax'] = array( |
|
| 3654 | + 'initial' => 0, |
|
| 3655 | + 'recurring' => 0, |
|
| 3656 | + ); |
|
| 3657 | 3657 | |
| 3658 | - $this->tax_rate = 0; |
|
| 3658 | + $this->tax_rate = 0; |
|
| 3659 | 3659 | |
| 3660 | - $this->set_taxes( array() ); |
|
| 3661 | - $current = 0; |
|
| 3662 | - } else { |
|
| 3660 | + $this->set_taxes( array() ); |
|
| 3661 | + $current = 0; |
|
| 3662 | + } else { |
|
| 3663 | 3663 | |
| 3664 | - $item_taxes = array(); |
|
| 3664 | + $item_taxes = array(); |
|
| 3665 | 3665 | |
| 3666 | - foreach ( $this->get_items() as $item ) { |
|
| 3667 | - $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
| 3668 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 3669 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 3670 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 3671 | - foreach ( $taxes as $name => $amount ) { |
|
| 3672 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 3673 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 3666 | + foreach ( $this->get_items() as $item ) { |
|
| 3667 | + $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
| 3668 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 3669 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 3670 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 3671 | + foreach ( $taxes as $name => $amount ) { |
|
| 3672 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 3673 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 3674 | 3674 | |
| 3675 | - if ( ! isset( $item_taxes[ $name ] ) ) { |
|
| 3676 | - $item_taxes[ $name ] = $tax; |
|
| 3677 | - continue; |
|
| 3678 | - } |
|
| 3675 | + if ( ! isset( $item_taxes[ $name ] ) ) { |
|
| 3676 | + $item_taxes[ $name ] = $tax; |
|
| 3677 | + continue; |
|
| 3678 | + } |
|
| 3679 | 3679 | |
| 3680 | - $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 3681 | - $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3680 | + $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 3681 | + $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3682 | 3682 | |
| 3683 | - } |
|
| 3683 | + } |
|
| 3684 | 3684 | |
| 3685 | - } |
|
| 3685 | + } |
|
| 3686 | 3686 | |
| 3687 | - $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
| 3688 | - $this->set_taxes( $item_taxes ); |
|
| 3687 | + $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
| 3688 | + $this->set_taxes( $item_taxes ); |
|
| 3689 | 3689 | |
| 3690 | - $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
| 3691 | - $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
| 3690 | + $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
| 3691 | + $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
| 3692 | 3692 | |
| 3693 | - $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
| 3693 | + $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
| 3694 | 3694 | |
| 3695 | - $this->totals['tax'] = array( |
|
| 3696 | - 'initial' => $initial_tax, |
|
| 3697 | - 'recurring' => $recurring_tax, |
|
| 3698 | - ); |
|
| 3695 | + $this->totals['tax'] = array( |
|
| 3696 | + 'initial' => $initial_tax, |
|
| 3697 | + 'recurring' => $recurring_tax, |
|
| 3698 | + ); |
|
| 3699 | 3699 | |
| 3700 | - } |
|
| 3700 | + } |
|
| 3701 | 3701 | |
| 3702 | - $this->set_total_tax( $current ); |
|
| 3702 | + $this->set_total_tax( $current ); |
|
| 3703 | 3703 | |
| 3704 | - return $current; |
|
| 3704 | + return $current; |
|
| 3705 | 3705 | |
| 3706 | 3706 | } |
| 3707 | 3707 | |
| 3708 | 3708 | /** |
| 3709 | - * Recalculates the invoice fees total. |
|
| 3710 | - * |
|
| 3711 | - * @since 1.0.19 |
|
| 3712 | - * @return float The recalculated fee |
|
| 3713 | - */ |
|
| 3714 | - public function recalculate_total_fees() { |
|
| 3715 | - $fees = $this->get_fees(); |
|
| 3716 | - $fee = 0; |
|
| 3717 | - $recurring = 0; |
|
| 3709 | + * Recalculates the invoice fees total. |
|
| 3710 | + * |
|
| 3711 | + * @since 1.0.19 |
|
| 3712 | + * @return float The recalculated fee |
|
| 3713 | + */ |
|
| 3714 | + public function recalculate_total_fees() { |
|
| 3715 | + $fees = $this->get_fees(); |
|
| 3716 | + $fee = 0; |
|
| 3717 | + $recurring = 0; |
|
| 3718 | 3718 | |
| 3719 | 3719 | foreach ( $fees as $data ) { |
| 3720 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3721 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3722 | - } |
|
| 3720 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3721 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3722 | + } |
|
| 3723 | 3723 | |
| 3724 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3725 | - $this->set_total_fees( $current ); |
|
| 3724 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3725 | + $this->set_total_fees( $current ); |
|
| 3726 | 3726 | |
| 3727 | - $this->totals['fee'] = array( |
|
| 3728 | - 'initial' => $fee, |
|
| 3729 | - 'recurring' => $recurring, |
|
| 3730 | - ); |
|
| 3727 | + $this->totals['fee'] = array( |
|
| 3728 | + 'initial' => $fee, |
|
| 3729 | + 'recurring' => $recurring, |
|
| 3730 | + ); |
|
| 3731 | 3731 | |
| 3732 | 3732 | $this->set_total_fees( $fee ); |
| 3733 | 3733 | return $current; |
| 3734 | 3734 | } |
| 3735 | 3735 | |
| 3736 | 3736 | /** |
| 3737 | - * Recalculates the invoice total. |
|
| 3738 | - * |
|
| 3739 | - * @since 1.0.19 |
|
| 3737 | + * Recalculates the invoice total. |
|
| 3738 | + * |
|
| 3739 | + * @since 1.0.19 |
|
| 3740 | 3740 | * @return float The invoice total |
| 3741 | - */ |
|
| 3742 | - public function recalculate_total() { |
|
| 3741 | + */ |
|
| 3742 | + public function recalculate_total() { |
|
| 3743 | 3743 | $this->recalculate_total_fees(); |
| 3744 | 3744 | $this->recalculate_total_discount(); |
| 3745 | - $this->recalculate_total_tax(); |
|
| 3746 | - $this->recalculate_subtotal(); |
|
| 3747 | - $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
| 3748 | - return $this->get_total(); |
|
| 3749 | - } |
|
| 3750 | - |
|
| 3751 | - /** |
|
| 3752 | - * @deprecated |
|
| 3753 | - */ |
|
| 3745 | + $this->recalculate_total_tax(); |
|
| 3746 | + $this->recalculate_subtotal(); |
|
| 3747 | + $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
| 3748 | + return $this->get_total(); |
|
| 3749 | + } |
|
| 3750 | + |
|
| 3751 | + /** |
|
| 3752 | + * @deprecated |
|
| 3753 | + */ |
|
| 3754 | 3754 | public function recalculate_totals() { |
| 3755 | 3755 | $this->recalculate_total(); |
| 3756 | 3756 | $this->save( true ); |
@@ -3764,22 +3764,22 @@ discard block |
||
| 3764 | 3764 | return $this->get_data(); |
| 3765 | 3765 | } |
| 3766 | 3766 | |
| 3767 | - /** |
|
| 3767 | + /** |
|
| 3768 | 3768 | * Adds a system note to an invoice. |
| 3769 | 3769 | * |
| 3770 | 3770 | * @param string $note The note being added. |
| 3771 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3771 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3772 | 3772 | * |
| 3773 | 3773 | */ |
| 3774 | 3774 | public function add_system_note( $note ) { |
| 3775 | - return $this->add_note( $note, false, false, true ); |
|
| 3776 | - } |
|
| 3775 | + return $this->add_note( $note, false, false, true ); |
|
| 3776 | + } |
|
| 3777 | 3777 | |
| 3778 | 3778 | /** |
| 3779 | 3779 | * Adds a note to an invoice. |
| 3780 | 3780 | * |
| 3781 | 3781 | * @param string $note The note being added. |
| 3782 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3782 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3783 | 3783 | * |
| 3784 | 3784 | */ |
| 3785 | 3785 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3789,21 +3789,21 @@ discard block |
||
| 3789 | 3789 | return false; |
| 3790 | 3790 | } |
| 3791 | 3791 | |
| 3792 | - $author = 'System'; |
|
| 3793 | - $author_email = '[email protected]'; |
|
| 3792 | + $author = 'System'; |
|
| 3793 | + $author_email = '[email protected]'; |
|
| 3794 | 3794 | |
| 3795 | - // If this is an admin comment or it has been added by the user. |
|
| 3796 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3797 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3795 | + // If this is an admin comment or it has been added by the user. |
|
| 3796 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3797 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3798 | 3798 | $author = $user->display_name; |
| 3799 | 3799 | $author_email = $user->user_email; |
| 3800 | - } |
|
| 3800 | + } |
|
| 3801 | 3801 | |
| 3802 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3802 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3803 | 3803 | |
| 3804 | - } |
|
| 3804 | + } |
|
| 3805 | 3805 | |
| 3806 | - /** |
|
| 3806 | + /** |
|
| 3807 | 3807 | * Generates a unique key for the invoice. |
| 3808 | 3808 | */ |
| 3809 | 3809 | public function generate_key( $string = '' ) { |
@@ -3823,113 +3823,113 @@ discard block |
||
| 3823 | 3823 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
| 3824 | 3824 | } |
| 3825 | 3825 | |
| 3826 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3827 | - |
|
| 3828 | - } |
|
| 3829 | - |
|
| 3830 | - /** |
|
| 3831 | - * Handle the status transition. |
|
| 3832 | - */ |
|
| 3833 | - protected function status_transition() { |
|
| 3834 | - $status_transition = $this->status_transition; |
|
| 3835 | - |
|
| 3836 | - // Reset status transition variable. |
|
| 3837 | - $this->status_transition = false; |
|
| 3826 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3838 | 3827 | |
| 3839 | - if ( $status_transition ) { |
|
| 3840 | - try { |
|
| 3841 | - |
|
| 3842 | - // Fire a hook for the status change. |
|
| 3843 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3844 | - |
|
| 3845 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3846 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3847 | - |
|
| 3848 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 3849 | - |
|
| 3850 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3851 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3852 | - |
|
| 3853 | - // Fire another hook. |
|
| 3854 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3855 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3856 | - |
|
| 3857 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3858 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3859 | - |
|
| 3860 | - // Note the transition occurred. |
|
| 3861 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3862 | - |
|
| 3863 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3864 | - if ( |
|
| 3865 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3866 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3867 | - ) { |
|
| 3868 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3869 | - } |
|
| 3870 | - |
|
| 3871 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3872 | - if ( |
|
| 3873 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3874 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3875 | - ) { |
|
| 3876 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3877 | - } |
|
| 3878 | - } else { |
|
| 3879 | - /* translators: %s: new invoice status */ |
|
| 3880 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3881 | - |
|
| 3882 | - // Note the transition occurred. |
|
| 3883 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3828 | + } |
|
| 3884 | 3829 | |
| 3885 | - } |
|
| 3886 | - } catch ( Exception $e ) { |
|
| 3887 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3888 | - } |
|
| 3889 | - } |
|
| 3890 | - } |
|
| 3830 | + /** |
|
| 3831 | + * Handle the status transition. |
|
| 3832 | + */ |
|
| 3833 | + protected function status_transition() { |
|
| 3834 | + $status_transition = $this->status_transition; |
|
| 3835 | + |
|
| 3836 | + // Reset status transition variable. |
|
| 3837 | + $this->status_transition = false; |
|
| 3838 | + |
|
| 3839 | + if ( $status_transition ) { |
|
| 3840 | + try { |
|
| 3841 | + |
|
| 3842 | + // Fire a hook for the status change. |
|
| 3843 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3844 | + |
|
| 3845 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3846 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3847 | + |
|
| 3848 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 3849 | + |
|
| 3850 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3851 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3852 | + |
|
| 3853 | + // Fire another hook. |
|
| 3854 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3855 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3856 | + |
|
| 3857 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3858 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3859 | + |
|
| 3860 | + // Note the transition occurred. |
|
| 3861 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3862 | + |
|
| 3863 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3864 | + if ( |
|
| 3865 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3866 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3867 | + ) { |
|
| 3868 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3869 | + } |
|
| 3870 | + |
|
| 3871 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3872 | + if ( |
|
| 3873 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3874 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3875 | + ) { |
|
| 3876 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3877 | + } |
|
| 3878 | + } else { |
|
| 3879 | + /* translators: %s: new invoice status */ |
|
| 3880 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3881 | + |
|
| 3882 | + // Note the transition occurred. |
|
| 3883 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3884 | + |
|
| 3885 | + } |
|
| 3886 | + } catch ( Exception $e ) { |
|
| 3887 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3888 | + } |
|
| 3889 | + } |
|
| 3890 | + } |
|
| 3891 | 3891 | |
| 3892 | - /** |
|
| 3893 | - * Updates an invoice status. |
|
| 3894 | - */ |
|
| 3895 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3892 | + /** |
|
| 3893 | + * Updates an invoice status. |
|
| 3894 | + */ |
|
| 3895 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3896 | 3896 | |
| 3897 | - // Fires before updating a status. |
|
| 3898 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3897 | + // Fires before updating a status. |
|
| 3898 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3899 | 3899 | |
| 3900 | - // Update the status. |
|
| 3901 | - $this->set_status( $new_status, $note, $manual ); |
|
| 3900 | + // Update the status. |
|
| 3901 | + $this->set_status( $new_status, $note, $manual ); |
|
| 3902 | 3902 | |
| 3903 | - // Save the order. |
|
| 3904 | - return $this->save(); |
|
| 3903 | + // Save the order. |
|
| 3904 | + return $this->save(); |
|
| 3905 | 3905 | |
| 3906 | - } |
|
| 3906 | + } |
|
| 3907 | 3907 | |
| 3908 | - /** |
|
| 3909 | - * @deprecated |
|
| 3910 | - */ |
|
| 3911 | - public function refresh_item_ids() { |
|
| 3908 | + /** |
|
| 3909 | + * @deprecated |
|
| 3910 | + */ |
|
| 3911 | + public function refresh_item_ids() { |
|
| 3912 | 3912 | $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) ); |
| 3913 | 3913 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
| 3914 | - } |
|
| 3914 | + } |
|
| 3915 | 3915 | |
| 3916 | - /** |
|
| 3917 | - * @deprecated |
|
| 3918 | - */ |
|
| 3919 | - public function update_items( $temp = false ) { |
|
| 3916 | + /** |
|
| 3917 | + * @deprecated |
|
| 3918 | + */ |
|
| 3919 | + public function update_items( $temp = false ) { |
|
| 3920 | 3920 | |
| 3921 | - $this->set_items( $this->get_items() ); |
|
| 3921 | + $this->set_items( $this->get_items() ); |
|
| 3922 | 3922 | |
| 3923 | - if ( ! $temp ) { |
|
| 3924 | - $this->save(); |
|
| 3925 | - } |
|
| 3923 | + if ( ! $temp ) { |
|
| 3924 | + $this->save(); |
|
| 3925 | + } |
|
| 3926 | 3926 | |
| 3927 | 3927 | return $this; |
| 3928 | - } |
|
| 3928 | + } |
|
| 3929 | 3929 | |
| 3930 | - /** |
|
| 3931 | - * @deprecated |
|
| 3932 | - */ |
|
| 3930 | + /** |
|
| 3931 | + * @deprecated |
|
| 3932 | + */ |
|
| 3933 | 3933 | public function validate_discount() { |
| 3934 | 3934 | |
| 3935 | 3935 | $discount_code = $this->get_discount_code(); |
@@ -3945,93 +3945,93 @@ discard block |
||
| 3945 | 3945 | |
| 3946 | 3946 | } |
| 3947 | 3947 | |
| 3948 | - /** |
|
| 3949 | - * Refunds an invoice. |
|
| 3950 | - */ |
|
| 3948 | + /** |
|
| 3949 | + * Refunds an invoice. |
|
| 3950 | + */ |
|
| 3951 | 3951 | public function refund() { |
| 3952 | - $this->set_status( 'wpi-refunded' ); |
|
| 3952 | + $this->set_status( 'wpi-refunded' ); |
|
| 3953 | 3953 | $this->save(); |
| 3954 | - } |
|
| 3954 | + } |
|
| 3955 | 3955 | |
| 3956 | - /** |
|
| 3957 | - * Marks an invoice as paid. |
|
| 3958 | - * |
|
| 3959 | - * @param string $transaction_id |
|
| 3960 | - */ |
|
| 3956 | + /** |
|
| 3957 | + * Marks an invoice as paid. |
|
| 3958 | + * |
|
| 3959 | + * @param string $transaction_id |
|
| 3960 | + */ |
|
| 3961 | 3961 | public function mark_paid( $transaction_id = null, $note = '' ) { |
| 3962 | 3962 | |
| 3963 | - // Set the transaction id. |
|
| 3964 | - if ( empty( $transaction_id ) ) { |
|
| 3965 | - $transaction_id = $this->generate_key('trans_'); |
|
| 3966 | - } |
|
| 3963 | + // Set the transaction id. |
|
| 3964 | + if ( empty( $transaction_id ) ) { |
|
| 3965 | + $transaction_id = $this->generate_key('trans_'); |
|
| 3966 | + } |
|
| 3967 | 3967 | |
| 3968 | - if ( ! $this->get_transaction_id() ) { |
|
| 3969 | - $this->set_transaction_id( $transaction_id ); |
|
| 3970 | - } |
|
| 3968 | + if ( ! $this->get_transaction_id() ) { |
|
| 3969 | + $this->set_transaction_id( $transaction_id ); |
|
| 3970 | + } |
|
| 3971 | 3971 | |
| 3972 | - if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3973 | - return $this->save(); |
|
| 3974 | - } |
|
| 3972 | + if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3973 | + return $this->save(); |
|
| 3974 | + } |
|
| 3975 | 3975 | |
| 3976 | - // Set the completed date. |
|
| 3977 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3976 | + // Set the completed date. |
|
| 3977 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3978 | 3978 | |
| 3979 | - // Set the new status. |
|
| 3980 | - $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
| 3981 | - if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
| 3979 | + // Set the new status. |
|
| 3980 | + $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
| 3981 | + if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
| 3982 | 3982 | |
| 3983 | - $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
| 3984 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3983 | + $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
| 3984 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3985 | 3985 | |
| 3986 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3987 | - $_note = $note; |
|
| 3988 | - } |
|
| 3986 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3987 | + $_note = $note; |
|
| 3988 | + } |
|
| 3989 | 3989 | |
| 3990 | - $this->set_status( 'wpi-renewal', $_note ); |
|
| 3990 | + $this->set_status( 'wpi-renewal', $_note ); |
|
| 3991 | 3991 | |
| 3992 | - } else { |
|
| 3992 | + } else { |
|
| 3993 | 3993 | |
| 3994 | - $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 3995 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3994 | + $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 3995 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3996 | 3996 | |
| 3997 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3998 | - $_note = $note; |
|
| 3999 | - } |
|
| 3997 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3998 | + $_note = $note; |
|
| 3999 | + } |
|
| 4000 | 4000 | |
| 4001 | - $this->set_status( 'publish', $_note ); |
|
| 4001 | + $this->set_status( 'publish', $_note ); |
|
| 4002 | 4002 | |
| 4003 | - } |
|
| 4003 | + } |
|
| 4004 | 4004 | |
| 4005 | - // Set checkout mode. |
|
| 4006 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 4007 | - $this->set_mode( $mode ); |
|
| 4005 | + // Set checkout mode. |
|
| 4006 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 4007 | + $this->set_mode( $mode ); |
|
| 4008 | 4008 | |
| 4009 | - // Save the invoice. |
|
| 4009 | + // Save the invoice. |
|
| 4010 | 4010 | $this->save(); |
| 4011 | - } |
|
| 4012 | - |
|
| 4013 | - /** |
|
| 4014 | - * Save data to the database. |
|
| 4015 | - * |
|
| 4016 | - * @since 1.0.19 |
|
| 4017 | - * @return int invoice ID |
|
| 4018 | - */ |
|
| 4019 | - public function save() { |
|
| 4020 | - $this->maybe_set_date_paid(); |
|
| 4021 | - $this->maybe_set_key(); |
|
| 4022 | - parent::save(); |
|
| 4023 | - $this->clear_cache(); |
|
| 4024 | - $this->status_transition(); |
|
| 4025 | - return $this->get_id(); |
|
| 4026 | - } |
|
| 4027 | - |
|
| 4028 | - /** |
|
| 4011 | + } |
|
| 4012 | + |
|
| 4013 | + /** |
|
| 4014 | + * Save data to the database. |
|
| 4015 | + * |
|
| 4016 | + * @since 1.0.19 |
|
| 4017 | + * @return int invoice ID |
|
| 4018 | + */ |
|
| 4019 | + public function save() { |
|
| 4020 | + $this->maybe_set_date_paid(); |
|
| 4021 | + $this->maybe_set_key(); |
|
| 4022 | + parent::save(); |
|
| 4023 | + $this->clear_cache(); |
|
| 4024 | + $this->status_transition(); |
|
| 4025 | + return $this->get_id(); |
|
| 4026 | + } |
|
| 4027 | + |
|
| 4028 | + /** |
|
| 4029 | 4029 | * Clears the subscription's cache. |
| 4030 | 4030 | */ |
| 4031 | 4031 | public function clear_cache() { |
| 4032 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 4033 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 4034 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 4035 | - } |
|
| 4032 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 4033 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 4034 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 4035 | + } |
|
| 4036 | 4036 | |
| 4037 | 4037 | } |
@@ -18,691 +18,691 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GetPaid_REST_Report_Sales_Controller extends GetPaid_REST_Date_Based_Controller { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Route base. |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected $rest_base = 'reports/sales'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * The report data. |
|
| 30 | - * |
|
| 31 | - * @var stdClass |
|
| 32 | - */ |
|
| 33 | - public $report_data; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * The report range. |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - public $report_range; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Registers the routes for the objects of the controller. |
|
| 44 | - * |
|
| 45 | - * @since 2.0.0 |
|
| 46 | - * |
|
| 47 | - * @see register_rest_route() |
|
| 48 | - */ |
|
| 49 | - public function register_namespace_routes( $namespace ) { |
|
| 50 | - |
|
| 51 | - // Get sales report. |
|
| 52 | - register_rest_route( |
|
| 53 | - $namespace, |
|
| 54 | - $this->rest_base, |
|
| 55 | - array( |
|
| 56 | - array( |
|
| 57 | - 'methods' => WP_REST_Server::READABLE, |
|
| 58 | - 'callback' => array( $this, 'get_items' ), |
|
| 59 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 60 | - 'args' => $this->get_collection_params(), |
|
| 61 | - ), |
|
| 62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 63 | - ) |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Makes sure the current user has access to READ the report APIs. |
|
| 70 | - * |
|
| 71 | - * @since 2.0.0 |
|
| 72 | - * @param WP_REST_Request $request Full data about the request. |
|
| 73 | - * @return WP_Error|boolean |
|
| 74 | - */ |
|
| 75 | - public function get_items_permissions_check( $request ) { |
|
| 76 | - |
|
| 77 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 78 | - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - return true; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Get sales reports. |
|
| 86 | - * |
|
| 87 | - * @param WP_REST_Request $request |
|
| 88 | - * @return array|WP_Error |
|
| 89 | - */ |
|
| 90 | - public function get_items( $request ) { |
|
| 91 | - $data = array(); |
|
| 92 | - $item = $this->prepare_item_for_response( null, $request ); |
|
| 93 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 94 | - |
|
| 95 | - return rest_ensure_response( $data ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Prepare a report sales object for serialization. |
|
| 100 | - * |
|
| 101 | - * @param null $_ |
|
| 102 | - * @param WP_REST_Request $request Request object. |
|
| 103 | - * @return WP_REST_Response $response Response data. |
|
| 104 | - */ |
|
| 105 | - public function prepare_item_for_response( $_, $request ) { |
|
| 106 | - |
|
| 107 | - // Set report range. |
|
| 108 | - $this->report_range = $this->get_date_range( $request ); |
|
| 109 | - |
|
| 110 | - $report_data = $this->get_report_data(); |
|
| 111 | - $period_totals = array(); |
|
| 112 | - |
|
| 113 | - // Setup period totals by ensuring each period in the interval has data. |
|
| 114 | - $start_date = strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS; |
|
| 115 | - |
|
| 116 | - if ( 'month' === $this->groupby ) { |
|
| 117 | - $start_date = strtotime( date( 'Y-m-01', $start_date ) ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - for ( $i = 0; $i < $this->interval; $i++ ) { |
|
| 121 | - |
|
| 122 | - switch ( $this->groupby ) { |
|
| 123 | - case 'day' : |
|
| 124 | - $time = date( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) ); |
|
| 125 | - break; |
|
| 126 | - default : |
|
| 127 | - $time = date( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) ); |
|
| 128 | - break; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // Set the defaults for each period. |
|
| 132 | - $period_totals[ $time ] = array( |
|
| 133 | - 'invoices' => 0, |
|
| 134 | - 'items' => 0, |
|
| 135 | - 'refunded_items' => 0, |
|
| 136 | - 'refunded_tax' => wpinv_round_amount( 0.00 ), |
|
| 137 | - 'subtotal' => wpinv_round_amount( 0.00 ), |
|
| 138 | - 'refunded_subtotal' => wpinv_round_amount( 0.00 ), |
|
| 139 | - 'refunded_fees' => wpinv_round_amount( 0.00 ), |
|
| 140 | - 'discount' => wpinv_round_amount( 0.00 ), |
|
| 141 | - ); |
|
| 142 | - |
|
| 143 | - foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
| 144 | - if ( ! isset( $period_totals[ $time ][ $key ] ) ) { |
|
| 145 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 ); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // add total sales, total invoice count, total tax for each period |
|
| 152 | - $date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m'; |
|
| 153 | - foreach ( $report_data->invoices as $invoice ) { |
|
| 154 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 155 | - |
|
| 156 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
| 157 | - continue; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $period_totals[ $time ]['sales'] = wpinv_round_amount( $invoice->total_sales ); |
|
| 161 | - $period_totals[ $time ]['tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
| 162 | - $period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
| 163 | - $period_totals[ $time ]['fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
| 164 | - |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - foreach ( $report_data->refunds as $invoice ) { |
|
| 168 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 169 | - |
|
| 170 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
| 171 | - continue; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $period_totals[ $time ]['refunds'] = wpinv_round_amount( $invoice->total_sales ); |
|
| 175 | - $period_totals[ $time ]['refunded_tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
| 176 | - $period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
| 177 | - $period_totals[ $time ]['refunded_fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
| 178 | - |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - foreach ( $report_data->invoice_counts as $invoice ) { |
|
| 182 | - $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 183 | - |
|
| 184 | - if ( isset( $period_totals[ $time ] ) ) { |
|
| 185 | - $period_totals[ $time ]['invoices'] = (int) $invoice->count; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // Add total invoice items for each period. |
|
| 191 | - foreach ( $report_data->invoice_items as $invoice_item ) { |
|
| 192 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : date( 'Y-m', strtotime( $invoice_item->post_date ) ); |
|
| 193 | - |
|
| 194 | - if ( isset( $period_totals[ $time ] ) ) { |
|
| 195 | - $period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // Add total discount for each period. |
|
| 201 | - foreach ( $report_data->coupons as $discount ) { |
|
| 202 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $discount->post_date ) ) : date( 'Y-m', strtotime( $discount->post_date ) ); |
|
| 203 | - |
|
| 204 | - if ( isset( $period_totals[ $time ] ) ) { |
|
| 205 | - $period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // Extra fields. |
|
| 211 | - foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
| 212 | - |
|
| 213 | - // Abort unprepared. |
|
| 214 | - if ( ! isset( $report_data->$key ) ) { |
|
| 215 | - continue; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // Abort defaults. |
|
| 219 | - if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) { |
|
| 220 | - continue; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Set values. |
|
| 224 | - foreach ( $report_data->$key as $item ) { |
|
| 225 | - $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $item->date ) ) : date( 'Y-m', strtotime( $item->date ) ); |
|
| 226 | - |
|
| 227 | - if ( isset( $period_totals[ $time ] ) ) { |
|
| 228 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val ); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - unset( $report_data->$key ); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $report_data->totals = $period_totals; |
|
| 236 | - $report_data->grouped_by = $this->groupby; |
|
| 237 | - $report_data->interval = max( $this->interval, 1 ); |
|
| 238 | - $report_data->currency = wpinv_get_currency(); |
|
| 239 | - $report_data->currency_symbol = wpinv_currency_symbol(); |
|
| 240 | - $report_data->currency_position = wpinv_currency_position(); |
|
| 241 | - $report_data->decimal_places = wpinv_decimals(); |
|
| 242 | - $report_data->thousands_sep = wpinv_thousands_separator(); |
|
| 243 | - $report_data->decimals_sep = wpinv_decimal_separator(); |
|
| 244 | - $report_data->start_date = date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ); |
|
| 245 | - $report_data->end_date = date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ); |
|
| 246 | - $report_data->start_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ) ); |
|
| 247 | - $report_data->end_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ) ); |
|
| 248 | - $report_data->decimals_sep = wpinv_decimal_separator(); |
|
| 249 | - |
|
| 250 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 251 | - $data = $report_data; |
|
| 252 | - unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items ); |
|
| 253 | - $data = $this->add_additional_fields_to_object( (array) $data, $request ); |
|
| 254 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 255 | - |
|
| 256 | - // Wrap the data in a response object. |
|
| 257 | - $response = rest_ensure_response( $data ); |
|
| 258 | - $response->add_links( array( |
|
| 259 | - 'about' => array( |
|
| 260 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
| 261 | - ), |
|
| 262 | - ) ); |
|
| 263 | - |
|
| 264 | - return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request ); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Get report data. |
|
| 269 | - * |
|
| 270 | - * @return stdClass |
|
| 271 | - */ |
|
| 272 | - public function get_report_data() { |
|
| 273 | - if ( empty( $this->report_data ) ) { |
|
| 274 | - $this->query_report_data(); |
|
| 275 | - } |
|
| 276 | - return $this->report_data; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Get all data needed for this report and store in the class. |
|
| 281 | - */ |
|
| 282 | - protected function query_report_data() { |
|
| 283 | - |
|
| 284 | - // Prepare reports. |
|
| 285 | - $this->report_data = (object) array( |
|
| 286 | - 'invoice_counts' => $this->query_invoice_counts(),//count, post_date |
|
| 287 | - 'coupons' => $this->query_coupon_counts(), // discount_amount, post_date |
|
| 288 | - 'invoice_items' => $this->query_item_counts(), // invoice_item_count, post_date |
|
| 289 | - 'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date |
|
| 290 | - 'invoices' => $this->query_invoice_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
| 291 | - 'refunds' => $this->query_refunded_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
| 292 | - 'previous_range' => $this->previous_range, |
|
| 293 | - ); |
|
| 294 | - |
|
| 295 | - // Calculated totals. |
|
| 296 | - $this->report_data->total_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) ); |
|
| 297 | - $this->report_data->total_sales = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) ); |
|
| 298 | - $this->report_data->total_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) ); |
|
| 299 | - $this->report_data->total_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) ); |
|
| 300 | - $this->report_data->subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) ); |
|
| 301 | - $this->report_data->net_sales = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) ); |
|
| 302 | - $this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) ); |
|
| 303 | - $this->report_data->total_refunds = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) ); |
|
| 304 | - $this->report_data->refunded_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) ); |
|
| 305 | - $this->report_data->refunded_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) ); |
|
| 306 | - $this->report_data->refunded_subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) ); |
|
| 307 | - $this->report_data->net_refunds = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) ); |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - // Calculate average based on net. |
|
| 311 | - $this->report_data->average_sales = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 ); |
|
| 312 | - $this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 ); |
|
| 313 | - |
|
| 314 | - // Total invoices in this period, even if refunded. |
|
| 315 | - $this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) ); |
|
| 316 | - |
|
| 317 | - // Items invoiced in this period, even if refunded. |
|
| 318 | - $this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) ); |
|
| 319 | - |
|
| 320 | - // 3rd party filtering of report data |
|
| 321 | - $this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this ); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Prepares invoice counts. |
|
| 326 | - * |
|
| 327 | - * @return array. |
|
| 328 | - */ |
|
| 329 | - protected function query_invoice_counts() { |
|
| 330 | - |
|
| 331 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 332 | - array( |
|
| 333 | - 'data' => array( |
|
| 334 | - 'ID' => array( |
|
| 335 | - 'type' => 'post_data', |
|
| 336 | - 'function' => 'COUNT', |
|
| 337 | - 'name' => 'count', |
|
| 338 | - 'distinct' => true, |
|
| 339 | - ), |
|
| 340 | - 'post_date' => array( |
|
| 341 | - 'type' => 'post_data', |
|
| 342 | - 'function' => '', |
|
| 343 | - 'name' => 'post_date', |
|
| 344 | - ), |
|
| 345 | - ), |
|
| 346 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 347 | - 'order_by' => 'post_date ASC', |
|
| 348 | - 'query_type' => 'get_results', |
|
| 349 | - 'filter_range' => $this->report_range, |
|
| 350 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Prepares coupon counts. |
|
| 358 | - * |
|
| 359 | - * @return array. |
|
| 360 | - */ |
|
| 361 | - protected function query_coupon_counts() { |
|
| 362 | - |
|
| 363 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 364 | - array( |
|
| 365 | - 'data' => array( |
|
| 366 | - 'discount' => array( |
|
| 367 | - 'type' => 'invoice_data', |
|
| 368 | - 'function' => 'SUM', |
|
| 369 | - 'name' => 'discount_amount', |
|
| 370 | - ), |
|
| 371 | - 'post_date' => array( |
|
| 372 | - 'type' => 'post_data', |
|
| 373 | - 'function' => '', |
|
| 374 | - 'name' => 'post_date', |
|
| 375 | - ), |
|
| 376 | - ), |
|
| 377 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 378 | - 'order_by' => 'post_date ASC', |
|
| 379 | - 'query_type' => 'get_results', |
|
| 380 | - 'filter_range' => $this->report_range, |
|
| 381 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 382 | - ) |
|
| 383 | - ); |
|
| 384 | - |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Prepares item counts. |
|
| 389 | - * |
|
| 390 | - * @return array. |
|
| 391 | - */ |
|
| 392 | - protected function query_item_counts() { |
|
| 393 | - |
|
| 394 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 395 | - array( |
|
| 396 | - 'data' => array( |
|
| 397 | - 'quantity' => array( |
|
| 398 | - 'type' => 'invoice_item', |
|
| 399 | - 'function' => 'SUM', |
|
| 400 | - 'name' => 'invoice_item_count', |
|
| 401 | - ), |
|
| 402 | - 'post_date' => array( |
|
| 403 | - 'type' => 'post_data', |
|
| 404 | - 'function' => '', |
|
| 405 | - 'name' => 'post_date', |
|
| 406 | - ), |
|
| 407 | - ), |
|
| 408 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 409 | - 'order_by' => 'post_date ASC', |
|
| 410 | - 'query_type' => 'get_results', |
|
| 411 | - 'filter_range' => $this->report_range, |
|
| 412 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 413 | - ) |
|
| 414 | - ); |
|
| 415 | - |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * Prepares refunded item counts. |
|
| 420 | - * |
|
| 421 | - * @return array. |
|
| 422 | - */ |
|
| 423 | - protected function count_refunded_items() { |
|
| 424 | - |
|
| 425 | - return (int) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 426 | - array( |
|
| 427 | - 'data' => array( |
|
| 428 | - 'quantity' => array( |
|
| 429 | - 'type' => 'invoice_item', |
|
| 430 | - 'function' => 'SUM', |
|
| 431 | - 'name' => 'invoice_item_count', |
|
| 432 | - ), |
|
| 433 | - ), |
|
| 434 | - 'query_type' => 'get_var', |
|
| 435 | - 'filter_range' => $this->report_range, |
|
| 436 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
| 437 | - ) |
|
| 438 | - ); |
|
| 439 | - |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Prepares daily invoice totals. |
|
| 444 | - * |
|
| 445 | - * @return array. |
|
| 446 | - */ |
|
| 447 | - protected function query_invoice_totals() { |
|
| 448 | - |
|
| 449 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 450 | - array( |
|
| 451 | - 'data' => array( |
|
| 452 | - 'total' => array( |
|
| 453 | - 'type' => 'invoice_data', |
|
| 454 | - 'function' => 'SUM', |
|
| 455 | - 'name' => 'total_sales', |
|
| 456 | - ), |
|
| 457 | - 'tax' => array( |
|
| 458 | - 'type' => 'invoice_data', |
|
| 459 | - 'function' => 'SUM', |
|
| 460 | - 'name' => 'total_tax', |
|
| 461 | - ), |
|
| 462 | - 'discount' => array( |
|
| 463 | - 'type' => 'invoice_data', |
|
| 464 | - 'function' => 'SUM', |
|
| 465 | - 'name' => 'total_discount', |
|
| 466 | - ), |
|
| 467 | - 'fees_total' => array( |
|
| 468 | - 'type' => 'invoice_data', |
|
| 469 | - 'function' => 'SUM', |
|
| 470 | - 'name' => 'total_fees', |
|
| 471 | - ), |
|
| 472 | - 'subtotal' => array( |
|
| 473 | - 'type' => 'invoice_data', |
|
| 474 | - 'function' => 'SUM', |
|
| 475 | - 'name' => 'subtotal', |
|
| 476 | - ), |
|
| 477 | - 'post_date' => array( |
|
| 478 | - 'type' => 'post_data', |
|
| 479 | - 'function' => '', |
|
| 480 | - 'name' => 'post_date', |
|
| 481 | - ), |
|
| 482 | - ), |
|
| 483 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 484 | - 'order_by' => 'post_date ASC', |
|
| 485 | - 'query_type' => 'get_results', |
|
| 486 | - 'filter_range' => $this->report_range, |
|
| 487 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ), |
|
| 488 | - ) |
|
| 489 | - ); |
|
| 490 | - |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * Prepares daily invoice totals. |
|
| 495 | - * |
|
| 496 | - * @return array. |
|
| 497 | - */ |
|
| 498 | - protected function query_refunded_totals() { |
|
| 499 | - |
|
| 500 | - return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 501 | - array( |
|
| 502 | - 'data' => array( |
|
| 503 | - 'total' => array( |
|
| 504 | - 'type' => 'invoice_data', |
|
| 505 | - 'function' => 'SUM', |
|
| 506 | - 'name' => 'total_sales', |
|
| 507 | - ), |
|
| 508 | - 'tax' => array( |
|
| 509 | - 'type' => 'invoice_data', |
|
| 510 | - 'function' => 'SUM', |
|
| 511 | - 'name' => 'total_tax', |
|
| 512 | - ), |
|
| 513 | - 'discount' => array( |
|
| 514 | - 'type' => 'invoice_data', |
|
| 515 | - 'function' => 'SUM', |
|
| 516 | - 'name' => 'total_discount', |
|
| 517 | - ), |
|
| 518 | - 'fees_total' => array( |
|
| 519 | - 'type' => 'invoice_data', |
|
| 520 | - 'function' => 'SUM', |
|
| 521 | - 'name' => 'total_fees', |
|
| 522 | - ), |
|
| 523 | - 'subtotal' => array( |
|
| 524 | - 'type' => 'invoice_data', |
|
| 525 | - 'function' => 'SUM', |
|
| 526 | - 'name' => 'subtotal', |
|
| 527 | - ), |
|
| 528 | - 'post_date' => array( |
|
| 529 | - 'type' => 'post_data', |
|
| 530 | - 'function' => '', |
|
| 531 | - 'name' => 'post_date', |
|
| 532 | - ), |
|
| 533 | - ), |
|
| 534 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 535 | - 'order_by' => 'post_date ASC', |
|
| 536 | - 'query_type' => 'get_results', |
|
| 537 | - 'filter_range' => $this->report_range, |
|
| 538 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
| 539 | - ) |
|
| 540 | - ); |
|
| 541 | - |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * Get the Report's schema, conforming to JSON Schema. |
|
| 546 | - * |
|
| 547 | - * @return array |
|
| 548 | - */ |
|
| 549 | - public function get_item_schema() { |
|
| 550 | - |
|
| 551 | - $schema = array( |
|
| 552 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 553 | - 'title' => 'sales_report', |
|
| 554 | - 'type' => 'object', |
|
| 555 | - 'properties' => array( |
|
| 556 | - 'total_sales' => array( |
|
| 557 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
| 558 | - 'type' => 'string', |
|
| 559 | - 'context' => array( 'view' ), |
|
| 560 | - 'readonly' => true, |
|
| 561 | - ), |
|
| 562 | - 'net_sales' => array( |
|
| 563 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
| 564 | - 'type' => 'string', |
|
| 565 | - 'context' => array( 'view' ), |
|
| 566 | - 'readonly' => true, |
|
| 567 | - ), |
|
| 568 | - 'average_sales' => array( |
|
| 569 | - 'description' => __( 'Average net daily sales.', 'invoicing' ), |
|
| 570 | - 'type' => 'string', |
|
| 571 | - 'context' => array( 'view' ), |
|
| 572 | - 'readonly' => true, |
|
| 573 | - ), |
|
| 574 | - 'average_total_sales' => array( |
|
| 575 | - 'description' => __( 'Average gross daily sales.', 'invoicing' ), |
|
| 576 | - 'type' => 'string', |
|
| 577 | - 'context' => array( 'view' ), |
|
| 578 | - 'readonly' => true, |
|
| 579 | - ), |
|
| 580 | - 'total_invoices' => array( |
|
| 581 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
| 582 | - 'type' => 'integer', |
|
| 583 | - 'context' => array( 'view' ), |
|
| 584 | - 'readonly' => true, |
|
| 585 | - ), |
|
| 586 | - 'total_items' => array( |
|
| 587 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
| 588 | - 'type' => 'integer', |
|
| 589 | - 'context' => array( 'view' ), |
|
| 590 | - 'readonly' => true, |
|
| 591 | - ), |
|
| 592 | - 'refunded_items' => array( |
|
| 593 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
| 594 | - 'type' => 'integer', |
|
| 595 | - 'context' => array( 'view' ), |
|
| 596 | - 'readonly' => true, |
|
| 597 | - ), |
|
| 598 | - 'total_tax' => array( |
|
| 599 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
| 600 | - 'type' => 'string', |
|
| 601 | - 'context' => array( 'view' ), |
|
| 602 | - 'readonly' => true, |
|
| 603 | - ), |
|
| 604 | - 'total_refunded_tax' => array( |
|
| 605 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
| 606 | - 'type' => 'string', |
|
| 607 | - 'context' => array( 'view' ), |
|
| 608 | - 'readonly' => true, |
|
| 609 | - ), |
|
| 610 | - 'total_fees' => array( |
|
| 611 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
| 612 | - 'type' => 'string', |
|
| 613 | - 'context' => array( 'view' ), |
|
| 614 | - 'readonly' => true, |
|
| 615 | - ), |
|
| 616 | - 'total_refunds' => array( |
|
| 617 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
| 618 | - 'type' => 'integer', |
|
| 619 | - 'context' => array( 'view' ), |
|
| 620 | - 'readonly' => true, |
|
| 621 | - ), |
|
| 622 | - 'net_refunds' => array( |
|
| 623 | - 'description' => __( 'Net of refunded invoices.', 'invoicing' ), |
|
| 624 | - 'type' => 'integer', |
|
| 625 | - 'context' => array( 'view' ), |
|
| 626 | - 'readonly' => true, |
|
| 627 | - ), |
|
| 628 | - 'total_discount' => array( |
|
| 629 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
| 630 | - 'type' => 'integer', |
|
| 631 | - 'context' => array( 'view' ), |
|
| 632 | - 'readonly' => true, |
|
| 633 | - ), |
|
| 634 | - 'totals' => array( |
|
| 635 | - 'description' => __( 'Totals.', 'invoicing' ), |
|
| 636 | - 'type' => 'array', |
|
| 637 | - 'items' => array( |
|
| 638 | - 'type' => 'array', |
|
| 639 | - ), |
|
| 640 | - 'context' => array( 'view' ), |
|
| 641 | - 'readonly' => true, |
|
| 642 | - ), |
|
| 643 | - 'interval' => array( |
|
| 644 | - 'description' => __( 'Number of months/days in the report period.', 'invoicing' ), |
|
| 645 | - 'type' => 'integer', |
|
| 646 | - 'context' => array( 'view' ), |
|
| 647 | - 'readonly' => true, |
|
| 648 | - ), |
|
| 649 | - 'previous_range' => array( |
|
| 650 | - 'description' => __( 'The previous report period.', 'invoicing' ), |
|
| 651 | - 'type' => 'array', |
|
| 652 | - 'items' => array( |
|
| 653 | - 'type' => 'string', |
|
| 654 | - ), |
|
| 655 | - 'context' => array( 'view' ), |
|
| 656 | - 'readonly' => true, |
|
| 657 | - ), |
|
| 658 | - 'grouped_by' => array( |
|
| 659 | - 'description' => __( 'The period used to group the totals.', 'invoicing' ), |
|
| 660 | - 'type' => 'string', |
|
| 661 | - 'context' => array( 'view' ), |
|
| 662 | - 'enum' => array( 'day', 'month' ), |
|
| 663 | - 'readonly' => true, |
|
| 664 | - ), |
|
| 665 | - 'currency' => array( |
|
| 666 | - 'description' => __( 'The default store currency.', 'invoicing' ), |
|
| 667 | - 'type' => 'string', |
|
| 668 | - 'context' => array( 'view' ), |
|
| 669 | - 'readonly' => true, |
|
| 670 | - ), |
|
| 671 | - 'currency_symbol' => array( |
|
| 672 | - 'description' => __( 'The default store currency symbol.', 'invoicing' ), |
|
| 673 | - 'type' => 'string', |
|
| 674 | - 'context' => array( 'view' ), |
|
| 675 | - 'readonly' => true, |
|
| 676 | - ), |
|
| 677 | - 'currency_position' => array( |
|
| 678 | - 'description' => __( 'The default store currency position.', 'invoicing' ), |
|
| 679 | - 'type' => 'string', |
|
| 680 | - 'context' => array( 'view' ), |
|
| 681 | - 'readonly' => true, |
|
| 682 | - ), |
|
| 683 | - 'decimal_places' => array( |
|
| 684 | - 'description' => __( 'The default store decimal places.', 'invoicing' ), |
|
| 685 | - 'type' => 'string', |
|
| 686 | - 'context' => array( 'view' ), |
|
| 687 | - 'readonly' => true, |
|
| 688 | - ), |
|
| 689 | - 'thousands_sep' => array( |
|
| 690 | - 'description' => __( 'The default store thousands separator.', 'invoicing' ), |
|
| 691 | - 'type' => 'string', |
|
| 692 | - 'context' => array( 'view' ), |
|
| 693 | - 'readonly' => true, |
|
| 694 | - ), |
|
| 695 | - 'decimals_sep' => array( |
|
| 696 | - 'description' => __( 'The default store decimals separator.', 'invoicing' ), |
|
| 697 | - 'type' => 'string', |
|
| 698 | - 'context' => array( 'view' ), |
|
| 699 | - 'readonly' => true, |
|
| 700 | - ), |
|
| 701 | - ), |
|
| 702 | - ); |
|
| 703 | - |
|
| 704 | - return $this->add_additional_fields_schema( $schema ); |
|
| 705 | - |
|
| 706 | - } |
|
| 21 | + /** |
|
| 22 | + * Route base. |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected $rest_base = 'reports/sales'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * The report data. |
|
| 30 | + * |
|
| 31 | + * @var stdClass |
|
| 32 | + */ |
|
| 33 | + public $report_data; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * The report range. |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + public $report_range; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Registers the routes for the objects of the controller. |
|
| 44 | + * |
|
| 45 | + * @since 2.0.0 |
|
| 46 | + * |
|
| 47 | + * @see register_rest_route() |
|
| 48 | + */ |
|
| 49 | + public function register_namespace_routes( $namespace ) { |
|
| 50 | + |
|
| 51 | + // Get sales report. |
|
| 52 | + register_rest_route( |
|
| 53 | + $namespace, |
|
| 54 | + $this->rest_base, |
|
| 55 | + array( |
|
| 56 | + array( |
|
| 57 | + 'methods' => WP_REST_Server::READABLE, |
|
| 58 | + 'callback' => array( $this, 'get_items' ), |
|
| 59 | + 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
| 60 | + 'args' => $this->get_collection_params(), |
|
| 61 | + ), |
|
| 62 | + 'schema' => array( $this, 'get_public_item_schema' ), |
|
| 63 | + ) |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Makes sure the current user has access to READ the report APIs. |
|
| 70 | + * |
|
| 71 | + * @since 2.0.0 |
|
| 72 | + * @param WP_REST_Request $request Full data about the request. |
|
| 73 | + * @return WP_Error|boolean |
|
| 74 | + */ |
|
| 75 | + public function get_items_permissions_check( $request ) { |
|
| 76 | + |
|
| 77 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 78 | + return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + return true; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Get sales reports. |
|
| 86 | + * |
|
| 87 | + * @param WP_REST_Request $request |
|
| 88 | + * @return array|WP_Error |
|
| 89 | + */ |
|
| 90 | + public function get_items( $request ) { |
|
| 91 | + $data = array(); |
|
| 92 | + $item = $this->prepare_item_for_response( null, $request ); |
|
| 93 | + $data[] = $this->prepare_response_for_collection( $item ); |
|
| 94 | + |
|
| 95 | + return rest_ensure_response( $data ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Prepare a report sales object for serialization. |
|
| 100 | + * |
|
| 101 | + * @param null $_ |
|
| 102 | + * @param WP_REST_Request $request Request object. |
|
| 103 | + * @return WP_REST_Response $response Response data. |
|
| 104 | + */ |
|
| 105 | + public function prepare_item_for_response( $_, $request ) { |
|
| 106 | + |
|
| 107 | + // Set report range. |
|
| 108 | + $this->report_range = $this->get_date_range( $request ); |
|
| 109 | + |
|
| 110 | + $report_data = $this->get_report_data(); |
|
| 111 | + $period_totals = array(); |
|
| 112 | + |
|
| 113 | + // Setup period totals by ensuring each period in the interval has data. |
|
| 114 | + $start_date = strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS; |
|
| 115 | + |
|
| 116 | + if ( 'month' === $this->groupby ) { |
|
| 117 | + $start_date = strtotime( date( 'Y-m-01', $start_date ) ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + for ( $i = 0; $i < $this->interval; $i++ ) { |
|
| 121 | + |
|
| 122 | + switch ( $this->groupby ) { |
|
| 123 | + case 'day' : |
|
| 124 | + $time = date( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) ); |
|
| 125 | + break; |
|
| 126 | + default : |
|
| 127 | + $time = date( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) ); |
|
| 128 | + break; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // Set the defaults for each period. |
|
| 132 | + $period_totals[ $time ] = array( |
|
| 133 | + 'invoices' => 0, |
|
| 134 | + 'items' => 0, |
|
| 135 | + 'refunded_items' => 0, |
|
| 136 | + 'refunded_tax' => wpinv_round_amount( 0.00 ), |
|
| 137 | + 'subtotal' => wpinv_round_amount( 0.00 ), |
|
| 138 | + 'refunded_subtotal' => wpinv_round_amount( 0.00 ), |
|
| 139 | + 'refunded_fees' => wpinv_round_amount( 0.00 ), |
|
| 140 | + 'discount' => wpinv_round_amount( 0.00 ), |
|
| 141 | + ); |
|
| 142 | + |
|
| 143 | + foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
| 144 | + if ( ! isset( $period_totals[ $time ][ $key ] ) ) { |
|
| 145 | + $period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 ); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // add total sales, total invoice count, total tax for each period |
|
| 152 | + $date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m'; |
|
| 153 | + foreach ( $report_data->invoices as $invoice ) { |
|
| 154 | + $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 155 | + |
|
| 156 | + if ( ! isset( $period_totals[ $time ] ) ) { |
|
| 157 | + continue; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $period_totals[ $time ]['sales'] = wpinv_round_amount( $invoice->total_sales ); |
|
| 161 | + $period_totals[ $time ]['tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
| 162 | + $period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
| 163 | + $period_totals[ $time ]['fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
| 164 | + |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + foreach ( $report_data->refunds as $invoice ) { |
|
| 168 | + $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 169 | + |
|
| 170 | + if ( ! isset( $period_totals[ $time ] ) ) { |
|
| 171 | + continue; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $period_totals[ $time ]['refunds'] = wpinv_round_amount( $invoice->total_sales ); |
|
| 175 | + $period_totals[ $time ]['refunded_tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
| 176 | + $period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
| 177 | + $period_totals[ $time ]['refunded_fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
| 178 | + |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + foreach ( $report_data->invoice_counts as $invoice ) { |
|
| 182 | + $time = date( $date_format, strtotime( $invoice->post_date ) ); |
|
| 183 | + |
|
| 184 | + if ( isset( $period_totals[ $time ] ) ) { |
|
| 185 | + $period_totals[ $time ]['invoices'] = (int) $invoice->count; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // Add total invoice items for each period. |
|
| 191 | + foreach ( $report_data->invoice_items as $invoice_item ) { |
|
| 192 | + $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : date( 'Y-m', strtotime( $invoice_item->post_date ) ); |
|
| 193 | + |
|
| 194 | + if ( isset( $period_totals[ $time ] ) ) { |
|
| 195 | + $period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // Add total discount for each period. |
|
| 201 | + foreach ( $report_data->coupons as $discount ) { |
|
| 202 | + $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $discount->post_date ) ) : date( 'Y-m', strtotime( $discount->post_date ) ); |
|
| 203 | + |
|
| 204 | + if ( isset( $period_totals[ $time ] ) ) { |
|
| 205 | + $period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // Extra fields. |
|
| 211 | + foreach( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
| 212 | + |
|
| 213 | + // Abort unprepared. |
|
| 214 | + if ( ! isset( $report_data->$key ) ) { |
|
| 215 | + continue; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // Abort defaults. |
|
| 219 | + if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) { |
|
| 220 | + continue; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Set values. |
|
| 224 | + foreach ( $report_data->$key as $item ) { |
|
| 225 | + $time = ( 'day' === $this->groupby ) ? date( 'Y-m-d', strtotime( $item->date ) ) : date( 'Y-m', strtotime( $item->date ) ); |
|
| 226 | + |
|
| 227 | + if ( isset( $period_totals[ $time ] ) ) { |
|
| 228 | + $period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val ); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + unset( $report_data->$key ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $report_data->totals = $period_totals; |
|
| 236 | + $report_data->grouped_by = $this->groupby; |
|
| 237 | + $report_data->interval = max( $this->interval, 1 ); |
|
| 238 | + $report_data->currency = wpinv_get_currency(); |
|
| 239 | + $report_data->currency_symbol = wpinv_currency_symbol(); |
|
| 240 | + $report_data->currency_position = wpinv_currency_position(); |
|
| 241 | + $report_data->decimal_places = wpinv_decimals(); |
|
| 242 | + $report_data->thousands_sep = wpinv_thousands_separator(); |
|
| 243 | + $report_data->decimals_sep = wpinv_decimal_separator(); |
|
| 244 | + $report_data->start_date = date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ); |
|
| 245 | + $report_data->end_date = date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ); |
|
| 246 | + $report_data->start_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['after'] ) + DAY_IN_SECONDS ) ); |
|
| 247 | + $report_data->end_date_locale = getpaid_format_date( date( 'Y-m-d', strtotime( $this->report_range['before'] ) - DAY_IN_SECONDS ) ); |
|
| 248 | + $report_data->decimals_sep = wpinv_decimal_separator(); |
|
| 249 | + |
|
| 250 | + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 251 | + $data = $report_data; |
|
| 252 | + unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items ); |
|
| 253 | + $data = $this->add_additional_fields_to_object( (array) $data, $request ); |
|
| 254 | + $data = $this->filter_response_by_context( $data, $context ); |
|
| 255 | + |
|
| 256 | + // Wrap the data in a response object. |
|
| 257 | + $response = rest_ensure_response( $data ); |
|
| 258 | + $response->add_links( array( |
|
| 259 | + 'about' => array( |
|
| 260 | + 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
| 261 | + ), |
|
| 262 | + ) ); |
|
| 263 | + |
|
| 264 | + return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request ); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Get report data. |
|
| 269 | + * |
|
| 270 | + * @return stdClass |
|
| 271 | + */ |
|
| 272 | + public function get_report_data() { |
|
| 273 | + if ( empty( $this->report_data ) ) { |
|
| 274 | + $this->query_report_data(); |
|
| 275 | + } |
|
| 276 | + return $this->report_data; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Get all data needed for this report and store in the class. |
|
| 281 | + */ |
|
| 282 | + protected function query_report_data() { |
|
| 283 | + |
|
| 284 | + // Prepare reports. |
|
| 285 | + $this->report_data = (object) array( |
|
| 286 | + 'invoice_counts' => $this->query_invoice_counts(),//count, post_date |
|
| 287 | + 'coupons' => $this->query_coupon_counts(), // discount_amount, post_date |
|
| 288 | + 'invoice_items' => $this->query_item_counts(), // invoice_item_count, post_date |
|
| 289 | + 'refunded_items' => $this->count_refunded_items(), // invoice_item_count, post_date |
|
| 290 | + 'invoices' => $this->query_invoice_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
| 291 | + 'refunds' => $this->query_refunded_totals(), // total_sales, total_tax, total_discount, total_fees, subtotal, post_date |
|
| 292 | + 'previous_range' => $this->previous_range, |
|
| 293 | + ); |
|
| 294 | + |
|
| 295 | + // Calculated totals. |
|
| 296 | + $this->report_data->total_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) ); |
|
| 297 | + $this->report_data->total_sales = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) ); |
|
| 298 | + $this->report_data->total_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) ); |
|
| 299 | + $this->report_data->total_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) ); |
|
| 300 | + $this->report_data->subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) ); |
|
| 301 | + $this->report_data->net_sales = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) ); |
|
| 302 | + $this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) ); |
|
| 303 | + $this->report_data->total_refunds = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) ); |
|
| 304 | + $this->report_data->refunded_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) ); |
|
| 305 | + $this->report_data->refunded_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) ); |
|
| 306 | + $this->report_data->refunded_subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) ); |
|
| 307 | + $this->report_data->net_refunds = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) ); |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + // Calculate average based on net. |
|
| 311 | + $this->report_data->average_sales = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 ); |
|
| 312 | + $this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 ); |
|
| 313 | + |
|
| 314 | + // Total invoices in this period, even if refunded. |
|
| 315 | + $this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) ); |
|
| 316 | + |
|
| 317 | + // Items invoiced in this period, even if refunded. |
|
| 318 | + $this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) ); |
|
| 319 | + |
|
| 320 | + // 3rd party filtering of report data |
|
| 321 | + $this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this ); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Prepares invoice counts. |
|
| 326 | + * |
|
| 327 | + * @return array. |
|
| 328 | + */ |
|
| 329 | + protected function query_invoice_counts() { |
|
| 330 | + |
|
| 331 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 332 | + array( |
|
| 333 | + 'data' => array( |
|
| 334 | + 'ID' => array( |
|
| 335 | + 'type' => 'post_data', |
|
| 336 | + 'function' => 'COUNT', |
|
| 337 | + 'name' => 'count', |
|
| 338 | + 'distinct' => true, |
|
| 339 | + ), |
|
| 340 | + 'post_date' => array( |
|
| 341 | + 'type' => 'post_data', |
|
| 342 | + 'function' => '', |
|
| 343 | + 'name' => 'post_date', |
|
| 344 | + ), |
|
| 345 | + ), |
|
| 346 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 347 | + 'order_by' => 'post_date ASC', |
|
| 348 | + 'query_type' => 'get_results', |
|
| 349 | + 'filter_range' => $this->report_range, |
|
| 350 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Prepares coupon counts. |
|
| 358 | + * |
|
| 359 | + * @return array. |
|
| 360 | + */ |
|
| 361 | + protected function query_coupon_counts() { |
|
| 362 | + |
|
| 363 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 364 | + array( |
|
| 365 | + 'data' => array( |
|
| 366 | + 'discount' => array( |
|
| 367 | + 'type' => 'invoice_data', |
|
| 368 | + 'function' => 'SUM', |
|
| 369 | + 'name' => 'discount_amount', |
|
| 370 | + ), |
|
| 371 | + 'post_date' => array( |
|
| 372 | + 'type' => 'post_data', |
|
| 373 | + 'function' => '', |
|
| 374 | + 'name' => 'post_date', |
|
| 375 | + ), |
|
| 376 | + ), |
|
| 377 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 378 | + 'order_by' => 'post_date ASC', |
|
| 379 | + 'query_type' => 'get_results', |
|
| 380 | + 'filter_range' => $this->report_range, |
|
| 381 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 382 | + ) |
|
| 383 | + ); |
|
| 384 | + |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Prepares item counts. |
|
| 389 | + * |
|
| 390 | + * @return array. |
|
| 391 | + */ |
|
| 392 | + protected function query_item_counts() { |
|
| 393 | + |
|
| 394 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 395 | + array( |
|
| 396 | + 'data' => array( |
|
| 397 | + 'quantity' => array( |
|
| 398 | + 'type' => 'invoice_item', |
|
| 399 | + 'function' => 'SUM', |
|
| 400 | + 'name' => 'invoice_item_count', |
|
| 401 | + ), |
|
| 402 | + 'post_date' => array( |
|
| 403 | + 'type' => 'post_data', |
|
| 404 | + 'function' => '', |
|
| 405 | + 'name' => 'post_date', |
|
| 406 | + ), |
|
| 407 | + ), |
|
| 408 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 409 | + 'order_by' => 'post_date ASC', |
|
| 410 | + 'query_type' => 'get_results', |
|
| 411 | + 'filter_range' => $this->report_range, |
|
| 412 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
| 413 | + ) |
|
| 414 | + ); |
|
| 415 | + |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * Prepares refunded item counts. |
|
| 420 | + * |
|
| 421 | + * @return array. |
|
| 422 | + */ |
|
| 423 | + protected function count_refunded_items() { |
|
| 424 | + |
|
| 425 | + return (int) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 426 | + array( |
|
| 427 | + 'data' => array( |
|
| 428 | + 'quantity' => array( |
|
| 429 | + 'type' => 'invoice_item', |
|
| 430 | + 'function' => 'SUM', |
|
| 431 | + 'name' => 'invoice_item_count', |
|
| 432 | + ), |
|
| 433 | + ), |
|
| 434 | + 'query_type' => 'get_var', |
|
| 435 | + 'filter_range' => $this->report_range, |
|
| 436 | + 'invoice_status' => array( 'wpi-refunded' ), |
|
| 437 | + ) |
|
| 438 | + ); |
|
| 439 | + |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * Prepares daily invoice totals. |
|
| 444 | + * |
|
| 445 | + * @return array. |
|
| 446 | + */ |
|
| 447 | + protected function query_invoice_totals() { |
|
| 448 | + |
|
| 449 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 450 | + array( |
|
| 451 | + 'data' => array( |
|
| 452 | + 'total' => array( |
|
| 453 | + 'type' => 'invoice_data', |
|
| 454 | + 'function' => 'SUM', |
|
| 455 | + 'name' => 'total_sales', |
|
| 456 | + ), |
|
| 457 | + 'tax' => array( |
|
| 458 | + 'type' => 'invoice_data', |
|
| 459 | + 'function' => 'SUM', |
|
| 460 | + 'name' => 'total_tax', |
|
| 461 | + ), |
|
| 462 | + 'discount' => array( |
|
| 463 | + 'type' => 'invoice_data', |
|
| 464 | + 'function' => 'SUM', |
|
| 465 | + 'name' => 'total_discount', |
|
| 466 | + ), |
|
| 467 | + 'fees_total' => array( |
|
| 468 | + 'type' => 'invoice_data', |
|
| 469 | + 'function' => 'SUM', |
|
| 470 | + 'name' => 'total_fees', |
|
| 471 | + ), |
|
| 472 | + 'subtotal' => array( |
|
| 473 | + 'type' => 'invoice_data', |
|
| 474 | + 'function' => 'SUM', |
|
| 475 | + 'name' => 'subtotal', |
|
| 476 | + ), |
|
| 477 | + 'post_date' => array( |
|
| 478 | + 'type' => 'post_data', |
|
| 479 | + 'function' => '', |
|
| 480 | + 'name' => 'post_date', |
|
| 481 | + ), |
|
| 482 | + ), |
|
| 483 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 484 | + 'order_by' => 'post_date ASC', |
|
| 485 | + 'query_type' => 'get_results', |
|
| 486 | + 'filter_range' => $this->report_range, |
|
| 487 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ), |
|
| 488 | + ) |
|
| 489 | + ); |
|
| 490 | + |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * Prepares daily invoice totals. |
|
| 495 | + * |
|
| 496 | + * @return array. |
|
| 497 | + */ |
|
| 498 | + protected function query_refunded_totals() { |
|
| 499 | + |
|
| 500 | + return (array) GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 501 | + array( |
|
| 502 | + 'data' => array( |
|
| 503 | + 'total' => array( |
|
| 504 | + 'type' => 'invoice_data', |
|
| 505 | + 'function' => 'SUM', |
|
| 506 | + 'name' => 'total_sales', |
|
| 507 | + ), |
|
| 508 | + 'tax' => array( |
|
| 509 | + 'type' => 'invoice_data', |
|
| 510 | + 'function' => 'SUM', |
|
| 511 | + 'name' => 'total_tax', |
|
| 512 | + ), |
|
| 513 | + 'discount' => array( |
|
| 514 | + 'type' => 'invoice_data', |
|
| 515 | + 'function' => 'SUM', |
|
| 516 | + 'name' => 'total_discount', |
|
| 517 | + ), |
|
| 518 | + 'fees_total' => array( |
|
| 519 | + 'type' => 'invoice_data', |
|
| 520 | + 'function' => 'SUM', |
|
| 521 | + 'name' => 'total_fees', |
|
| 522 | + ), |
|
| 523 | + 'subtotal' => array( |
|
| 524 | + 'type' => 'invoice_data', |
|
| 525 | + 'function' => 'SUM', |
|
| 526 | + 'name' => 'subtotal', |
|
| 527 | + ), |
|
| 528 | + 'post_date' => array( |
|
| 529 | + 'type' => 'post_data', |
|
| 530 | + 'function' => '', |
|
| 531 | + 'name' => 'post_date', |
|
| 532 | + ), |
|
| 533 | + ), |
|
| 534 | + 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
| 535 | + 'order_by' => 'post_date ASC', |
|
| 536 | + 'query_type' => 'get_results', |
|
| 537 | + 'filter_range' => $this->report_range, |
|
| 538 | + 'invoice_status' => array( 'wpi-refunded' ), |
|
| 539 | + ) |
|
| 540 | + ); |
|
| 541 | + |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * Get the Report's schema, conforming to JSON Schema. |
|
| 546 | + * |
|
| 547 | + * @return array |
|
| 548 | + */ |
|
| 549 | + public function get_item_schema() { |
|
| 550 | + |
|
| 551 | + $schema = array( |
|
| 552 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 553 | + 'title' => 'sales_report', |
|
| 554 | + 'type' => 'object', |
|
| 555 | + 'properties' => array( |
|
| 556 | + 'total_sales' => array( |
|
| 557 | + 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
| 558 | + 'type' => 'string', |
|
| 559 | + 'context' => array( 'view' ), |
|
| 560 | + 'readonly' => true, |
|
| 561 | + ), |
|
| 562 | + 'net_sales' => array( |
|
| 563 | + 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
| 564 | + 'type' => 'string', |
|
| 565 | + 'context' => array( 'view' ), |
|
| 566 | + 'readonly' => true, |
|
| 567 | + ), |
|
| 568 | + 'average_sales' => array( |
|
| 569 | + 'description' => __( 'Average net daily sales.', 'invoicing' ), |
|
| 570 | + 'type' => 'string', |
|
| 571 | + 'context' => array( 'view' ), |
|
| 572 | + 'readonly' => true, |
|
| 573 | + ), |
|
| 574 | + 'average_total_sales' => array( |
|
| 575 | + 'description' => __( 'Average gross daily sales.', 'invoicing' ), |
|
| 576 | + 'type' => 'string', |
|
| 577 | + 'context' => array( 'view' ), |
|
| 578 | + 'readonly' => true, |
|
| 579 | + ), |
|
| 580 | + 'total_invoices' => array( |
|
| 581 | + 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
| 582 | + 'type' => 'integer', |
|
| 583 | + 'context' => array( 'view' ), |
|
| 584 | + 'readonly' => true, |
|
| 585 | + ), |
|
| 586 | + 'total_items' => array( |
|
| 587 | + 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
| 588 | + 'type' => 'integer', |
|
| 589 | + 'context' => array( 'view' ), |
|
| 590 | + 'readonly' => true, |
|
| 591 | + ), |
|
| 592 | + 'refunded_items' => array( |
|
| 593 | + 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
| 594 | + 'type' => 'integer', |
|
| 595 | + 'context' => array( 'view' ), |
|
| 596 | + 'readonly' => true, |
|
| 597 | + ), |
|
| 598 | + 'total_tax' => array( |
|
| 599 | + 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
| 600 | + 'type' => 'string', |
|
| 601 | + 'context' => array( 'view' ), |
|
| 602 | + 'readonly' => true, |
|
| 603 | + ), |
|
| 604 | + 'total_refunded_tax' => array( |
|
| 605 | + 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
| 606 | + 'type' => 'string', |
|
| 607 | + 'context' => array( 'view' ), |
|
| 608 | + 'readonly' => true, |
|
| 609 | + ), |
|
| 610 | + 'total_fees' => array( |
|
| 611 | + 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
| 612 | + 'type' => 'string', |
|
| 613 | + 'context' => array( 'view' ), |
|
| 614 | + 'readonly' => true, |
|
| 615 | + ), |
|
| 616 | + 'total_refunds' => array( |
|
| 617 | + 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
| 618 | + 'type' => 'integer', |
|
| 619 | + 'context' => array( 'view' ), |
|
| 620 | + 'readonly' => true, |
|
| 621 | + ), |
|
| 622 | + 'net_refunds' => array( |
|
| 623 | + 'description' => __( 'Net of refunded invoices.', 'invoicing' ), |
|
| 624 | + 'type' => 'integer', |
|
| 625 | + 'context' => array( 'view' ), |
|
| 626 | + 'readonly' => true, |
|
| 627 | + ), |
|
| 628 | + 'total_discount' => array( |
|
| 629 | + 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
| 630 | + 'type' => 'integer', |
|
| 631 | + 'context' => array( 'view' ), |
|
| 632 | + 'readonly' => true, |
|
| 633 | + ), |
|
| 634 | + 'totals' => array( |
|
| 635 | + 'description' => __( 'Totals.', 'invoicing' ), |
|
| 636 | + 'type' => 'array', |
|
| 637 | + 'items' => array( |
|
| 638 | + 'type' => 'array', |
|
| 639 | + ), |
|
| 640 | + 'context' => array( 'view' ), |
|
| 641 | + 'readonly' => true, |
|
| 642 | + ), |
|
| 643 | + 'interval' => array( |
|
| 644 | + 'description' => __( 'Number of months/days in the report period.', 'invoicing' ), |
|
| 645 | + 'type' => 'integer', |
|
| 646 | + 'context' => array( 'view' ), |
|
| 647 | + 'readonly' => true, |
|
| 648 | + ), |
|
| 649 | + 'previous_range' => array( |
|
| 650 | + 'description' => __( 'The previous report period.', 'invoicing' ), |
|
| 651 | + 'type' => 'array', |
|
| 652 | + 'items' => array( |
|
| 653 | + 'type' => 'string', |
|
| 654 | + ), |
|
| 655 | + 'context' => array( 'view' ), |
|
| 656 | + 'readonly' => true, |
|
| 657 | + ), |
|
| 658 | + 'grouped_by' => array( |
|
| 659 | + 'description' => __( 'The period used to group the totals.', 'invoicing' ), |
|
| 660 | + 'type' => 'string', |
|
| 661 | + 'context' => array( 'view' ), |
|
| 662 | + 'enum' => array( 'day', 'month' ), |
|
| 663 | + 'readonly' => true, |
|
| 664 | + ), |
|
| 665 | + 'currency' => array( |
|
| 666 | + 'description' => __( 'The default store currency.', 'invoicing' ), |
|
| 667 | + 'type' => 'string', |
|
| 668 | + 'context' => array( 'view' ), |
|
| 669 | + 'readonly' => true, |
|
| 670 | + ), |
|
| 671 | + 'currency_symbol' => array( |
|
| 672 | + 'description' => __( 'The default store currency symbol.', 'invoicing' ), |
|
| 673 | + 'type' => 'string', |
|
| 674 | + 'context' => array( 'view' ), |
|
| 675 | + 'readonly' => true, |
|
| 676 | + ), |
|
| 677 | + 'currency_position' => array( |
|
| 678 | + 'description' => __( 'The default store currency position.', 'invoicing' ), |
|
| 679 | + 'type' => 'string', |
|
| 680 | + 'context' => array( 'view' ), |
|
| 681 | + 'readonly' => true, |
|
| 682 | + ), |
|
| 683 | + 'decimal_places' => array( |
|
| 684 | + 'description' => __( 'The default store decimal places.', 'invoicing' ), |
|
| 685 | + 'type' => 'string', |
|
| 686 | + 'context' => array( 'view' ), |
|
| 687 | + 'readonly' => true, |
|
| 688 | + ), |
|
| 689 | + 'thousands_sep' => array( |
|
| 690 | + 'description' => __( 'The default store thousands separator.', 'invoicing' ), |
|
| 691 | + 'type' => 'string', |
|
| 692 | + 'context' => array( 'view' ), |
|
| 693 | + 'readonly' => true, |
|
| 694 | + ), |
|
| 695 | + 'decimals_sep' => array( |
|
| 696 | + 'description' => __( 'The default store decimals separator.', 'invoicing' ), |
|
| 697 | + 'type' => 'string', |
|
| 698 | + 'context' => array( 'view' ), |
|
| 699 | + 'readonly' => true, |
|
| 700 | + ), |
|
| 701 | + ), |
|
| 702 | + ); |
|
| 703 | + |
|
| 704 | + return $this->add_additional_fields_schema( $schema ); |
|
| 705 | + |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | 708 | } |
@@ -12,69 +12,69 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | abstract class GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - public $stats; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 25 | - $this->prepare_stats(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Retrieves the current range. |
|
| 30 | - * |
|
| 31 | - */ |
|
| 32 | - public function get_range() { |
|
| 33 | - $valid_ranges = $this->get_periods(); |
|
| 34 | - |
|
| 35 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 36 | - return sanitize_key( $_GET['date_range'] ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return '7_days'; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Returns an array of date ranges. |
|
| 44 | - * |
|
| 45 | - * @return array |
|
| 46 | - */ |
|
| 47 | - public function get_periods() { |
|
| 48 | - |
|
| 49 | - $periods = array( |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + public $stats; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | + $this->prepare_stats(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Retrieves the current range. |
|
| 30 | + * |
|
| 31 | + */ |
|
| 32 | + public function get_range() { |
|
| 33 | + $valid_ranges = $this->get_periods(); |
|
| 34 | + |
|
| 35 | + if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 36 | + return sanitize_key( $_GET['date_range'] ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return '7_days'; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Returns an array of date ranges. |
|
| 44 | + * |
|
| 45 | + * @return array |
|
| 46 | + */ |
|
| 47 | + public function get_periods() { |
|
| 48 | + |
|
| 49 | + $periods = array( |
|
| 50 | 50 | 'today' => __( 'Today', 'invoicing' ), |
| 51 | 51 | 'yesterday' => __( 'Yesterday', 'invoicing' ), |
| 52 | 52 | '7_days' => __( 'Last 7 days', 'invoicing' ), |
| 53 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 54 | - '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
| 55 | - '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
| 56 | - '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
| 57 | - '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Retrieves the current range's sql. |
|
| 65 | - * |
|
| 66 | - */ |
|
| 67 | - public function get_range_sql( $range, $date = 'CAST(meta.completed_date AS DATE)', $datetime = 'meta.comlpeted_date' ) { |
|
| 53 | + '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 54 | + '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
| 55 | + '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
| 56 | + '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
| 57 | + '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Retrieves the current range's sql. |
|
| 65 | + * |
|
| 66 | + */ |
|
| 67 | + public function get_range_sql( $range, $date = 'CAST(meta.completed_date AS DATE)', $datetime = 'meta.comlpeted_date' ) { |
|
| 68 | 68 | |
| 69 | 69 | // Prepare durations. |
| 70 | 70 | $today = current_time( 'Y-m-d' ); |
| 71 | - $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
| 72 | - $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
| 73 | - $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
| 74 | - $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
| 75 | - $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
| 76 | - $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
| 77 | - $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
| 71 | + $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
| 72 | + $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
| 73 | + $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
| 74 | + $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
| 75 | + $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
| 76 | + $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
| 77 | + $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
| 78 | 78 | |
| 79 | 79 | $ranges = array( |
| 80 | 80 | |
@@ -91,130 +91,130 @@ discard block |
||
| 91 | 91 | '7_days' => array( |
| 92 | 92 | "DATE($datetime)", |
| 93 | 93 | "$date BETWEEN '$seven_days_ago' AND '$today'" |
| 94 | - ), |
|
| 94 | + ), |
|
| 95 | 95 | |
| 96 | - '30_days' => array( |
|
| 96 | + '30_days' => array( |
|
| 97 | 97 | "DATE($datetime)", |
| 98 | 98 | "$date BETWEEN '$thirty_days_ago' AND '$today'" |
| 99 | - ), |
|
| 99 | + ), |
|
| 100 | 100 | |
| 101 | - '60_days' => array( |
|
| 101 | + '60_days' => array( |
|
| 102 | 102 | "DATE($datetime)", |
| 103 | 103 | "$date BETWEEN '$sixty_days_ago' AND '$today'" |
| 104 | - ), |
|
| 104 | + ), |
|
| 105 | 105 | |
| 106 | - '90_days' => array( |
|
| 106 | + '90_days' => array( |
|
| 107 | 107 | "WEEK($datetime)", |
| 108 | 108 | "$date BETWEEN '$ninety_days_ago' AND '$today'" |
| 109 | - ), |
|
| 109 | + ), |
|
| 110 | 110 | |
| 111 | - '180_days' => array( |
|
| 111 | + '180_days' => array( |
|
| 112 | 112 | "WEEK($datetime)", |
| 113 | 113 | "$date BETWEEN '$one_eighty_days_ago' AND '$today'" |
| 114 | - ), |
|
| 114 | + ), |
|
| 115 | 115 | |
| 116 | - '360_days' => array( |
|
| 116 | + '360_days' => array( |
|
| 117 | 117 | "WEEK($datetime)", |
| 118 | 118 | "$date BETWEEN '$three_sixty_days_ago' AND '$today'" |
| 119 | 119 | ), |
| 120 | 120 | |
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | - $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges[ '7_days' ]; |
|
| 124 | - return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
| 125 | - |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Retrieves the hours in a day |
|
| 130 | - * |
|
| 131 | - */ |
|
| 132 | - public function get_hours_in_a_day() { |
|
| 133 | - |
|
| 134 | - return array( |
|
| 135 | - '12AM' => __( '12 AM', 'invoicing'), |
|
| 136 | - '1AM' => __( '1 AM', 'invoicing'), |
|
| 137 | - '2AM' => __( '2 AM', 'invoicing'), |
|
| 138 | - '3AM' => __( '3 AM', 'invoicing'), |
|
| 139 | - '4AM' => __( '4 AM', 'invoicing'), |
|
| 140 | - '5AM' => __( '5 AM', 'invoicing'), |
|
| 141 | - '6AM' => __( '6 AM', 'invoicing'), |
|
| 142 | - '7AM' => __( '7 AM', 'invoicing'), |
|
| 143 | - '8AM' => __( '8 AM', 'invoicing'), |
|
| 144 | - '9AM' => __( '9 AM', 'invoicing'), |
|
| 145 | - '10AM' => __( '10 AM', 'invoicing'), |
|
| 146 | - '11AM' => __( '11 AM', 'invoicing'), |
|
| 147 | - '12pm' => __( '12 PM', 'invoicing'), |
|
| 148 | - '1PM' => __( '1 PM', 'invoicing'), |
|
| 149 | - '2PM' => __( '2 PM', 'invoicing'), |
|
| 150 | - '3PM' => __( '3 PM', 'invoicing'), |
|
| 151 | - '4PM' => __( '4 PM', 'invoicing'), |
|
| 152 | - '5PM' => __( '5 PM', 'invoicing'), |
|
| 153 | - '6PM' => __( '6 PM', 'invoicing'), |
|
| 154 | - '7PM' => __( '7 PM', 'invoicing'), |
|
| 155 | - '8PM' => __( '8 PM', 'invoicing'), |
|
| 156 | - '9PM' => __( '9 PM', 'invoicing'), |
|
| 157 | - '10PM' => __( '10 PM', 'invoicing'), |
|
| 158 | - '11PM' => __( '11 PM', 'invoicing'), |
|
| 159 | - ); |
|
| 160 | - |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Retrieves the days in a period |
|
| 165 | - * |
|
| 166 | - */ |
|
| 167 | - public function get_days_in_period( $days ) { |
|
| 168 | - |
|
| 169 | - $return = array(); |
|
| 170 | - $format = 'Y-m-d'; |
|
| 171 | - |
|
| 172 | - if ( $days < 8 ) { |
|
| 173 | - $format = 'D'; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - if ( $days < 32 ) { |
|
| 177 | - $format = 'M j'; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - while ( $days > 0 ) { |
|
| 181 | - |
|
| 182 | - $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 183 | - $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 184 | - $return[ $key ] = $label; |
|
| 185 | - $days--; |
|
| 186 | - |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return $return; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Retrieves the weeks in a period |
|
| 194 | - * |
|
| 195 | - */ |
|
| 196 | - public function get_weeks_in_period( $days ) { |
|
| 197 | - |
|
| 198 | - $return = array(); |
|
| 199 | - |
|
| 200 | - while ( $days > 0 ) { |
|
| 201 | - |
|
| 202 | - $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 203 | - $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 204 | - $return[ $key ] = $label; |
|
| 205 | - $days--; |
|
| 206 | - |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return $return; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Displays the report card. |
|
| 214 | - * |
|
| 215 | - */ |
|
| 216 | - public function display() { |
|
| 217 | - ?> |
|
| 123 | + $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges[ '7_days' ]; |
|
| 124 | + return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
| 125 | + |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Retrieves the hours in a day |
|
| 130 | + * |
|
| 131 | + */ |
|
| 132 | + public function get_hours_in_a_day() { |
|
| 133 | + |
|
| 134 | + return array( |
|
| 135 | + '12AM' => __( '12 AM', 'invoicing'), |
|
| 136 | + '1AM' => __( '1 AM', 'invoicing'), |
|
| 137 | + '2AM' => __( '2 AM', 'invoicing'), |
|
| 138 | + '3AM' => __( '3 AM', 'invoicing'), |
|
| 139 | + '4AM' => __( '4 AM', 'invoicing'), |
|
| 140 | + '5AM' => __( '5 AM', 'invoicing'), |
|
| 141 | + '6AM' => __( '6 AM', 'invoicing'), |
|
| 142 | + '7AM' => __( '7 AM', 'invoicing'), |
|
| 143 | + '8AM' => __( '8 AM', 'invoicing'), |
|
| 144 | + '9AM' => __( '9 AM', 'invoicing'), |
|
| 145 | + '10AM' => __( '10 AM', 'invoicing'), |
|
| 146 | + '11AM' => __( '11 AM', 'invoicing'), |
|
| 147 | + '12pm' => __( '12 PM', 'invoicing'), |
|
| 148 | + '1PM' => __( '1 PM', 'invoicing'), |
|
| 149 | + '2PM' => __( '2 PM', 'invoicing'), |
|
| 150 | + '3PM' => __( '3 PM', 'invoicing'), |
|
| 151 | + '4PM' => __( '4 PM', 'invoicing'), |
|
| 152 | + '5PM' => __( '5 PM', 'invoicing'), |
|
| 153 | + '6PM' => __( '6 PM', 'invoicing'), |
|
| 154 | + '7PM' => __( '7 PM', 'invoicing'), |
|
| 155 | + '8PM' => __( '8 PM', 'invoicing'), |
|
| 156 | + '9PM' => __( '9 PM', 'invoicing'), |
|
| 157 | + '10PM' => __( '10 PM', 'invoicing'), |
|
| 158 | + '11PM' => __( '11 PM', 'invoicing'), |
|
| 159 | + ); |
|
| 160 | + |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Retrieves the days in a period |
|
| 165 | + * |
|
| 166 | + */ |
|
| 167 | + public function get_days_in_period( $days ) { |
|
| 168 | + |
|
| 169 | + $return = array(); |
|
| 170 | + $format = 'Y-m-d'; |
|
| 171 | + |
|
| 172 | + if ( $days < 8 ) { |
|
| 173 | + $format = 'D'; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + if ( $days < 32 ) { |
|
| 177 | + $format = 'M j'; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + while ( $days > 0 ) { |
|
| 181 | + |
|
| 182 | + $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 183 | + $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 184 | + $return[ $key ] = $label; |
|
| 185 | + $days--; |
|
| 186 | + |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return $return; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Retrieves the weeks in a period |
|
| 194 | + * |
|
| 195 | + */ |
|
| 196 | + public function get_weeks_in_period( $days ) { |
|
| 197 | + |
|
| 198 | + $return = array(); |
|
| 199 | + |
|
| 200 | + while ( $days > 0 ) { |
|
| 201 | + |
|
| 202 | + $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 203 | + $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 204 | + $return[ $key ] = $label; |
|
| 205 | + $days--; |
|
| 206 | + |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return $return; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Displays the report card. |
|
| 214 | + * |
|
| 215 | + */ |
|
| 216 | + public function display() { |
|
| 217 | + ?> |
|
| 218 | 218 | |
| 219 | 219 | <div class="row"> |
| 220 | 220 | <div class="col-12"> |
@@ -228,20 +228,20 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | <?php |
| 230 | 230 | |
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Prepares the report stats. |
|
| 235 | - * |
|
| 236 | - * Extend this in child classes. |
|
| 237 | - */ |
|
| 238 | - abstract public function prepare_stats(); |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Displays the actual report. |
|
| 242 | - * |
|
| 243 | - * Extend this in child classes. |
|
| 244 | - */ |
|
| 245 | - abstract public function display_stats(); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Prepares the report stats. |
|
| 235 | + * |
|
| 236 | + * Extend this in child classes. |
|
| 237 | + */ |
|
| 238 | + abstract public function prepare_stats(); |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Displays the actual report. |
|
| 242 | + * |
|
| 243 | + * Extend this in child classes. |
|
| 244 | + */ |
|
| 245 | + abstract public function display_stats(); |
|
| 246 | 246 | |
| 247 | 247 | } |
@@ -12,294 +12,294 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Helper { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Get report totals such as invoice totals and discount amounts. |
|
| 17 | - * |
|
| 18 | - * Data example: |
|
| 19 | - * |
|
| 20 | - * 'subtotal' => array( |
|
| 21 | - * 'type' => 'invoice_data', |
|
| 22 | - * 'function' => 'SUM', |
|
| 23 | - * 'name' => 'subtotal' |
|
| 24 | - * ) |
|
| 25 | - * |
|
| 26 | - * @param array $args |
|
| 27 | - * @return mixed depending on query_type |
|
| 28 | - */ |
|
| 29 | - public static function get_invoice_report_data( $args = array() ) { |
|
| 30 | - global $wpdb; |
|
| 31 | - |
|
| 32 | - $default_args = array( |
|
| 33 | - 'data' => array(), // The data to retrieve. |
|
| 34 | - 'where' => array(), // An array of where queries. |
|
| 35 | - 'query_type' => 'get_row', // wpdb query to run. |
|
| 36 | - 'group_by' => '', // What to group results by. |
|
| 37 | - 'order_by' => '', // What to order by. |
|
| 38 | - 'limit' => '', // Results limit. |
|
| 39 | - 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
| 40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
| 41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
| 42 | - 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
| 43 | - ); |
|
| 44 | - |
|
| 45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
| 46 | - $args = wp_parse_args( $args, $default_args ); |
|
| 47 | - |
|
| 48 | - extract( $args ); |
|
| 49 | - |
|
| 50 | - if ( empty( $data ) ) { |
|
| 51 | - return ''; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $query = array(); |
|
| 55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
| 56 | - $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
| 57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
| 58 | - |
|
| 59 | - $query['where'] = " |
|
| 15 | + /** |
|
| 16 | + * Get report totals such as invoice totals and discount amounts. |
|
| 17 | + * |
|
| 18 | + * Data example: |
|
| 19 | + * |
|
| 20 | + * 'subtotal' => array( |
|
| 21 | + * 'type' => 'invoice_data', |
|
| 22 | + * 'function' => 'SUM', |
|
| 23 | + * 'name' => 'subtotal' |
|
| 24 | + * ) |
|
| 25 | + * |
|
| 26 | + * @param array $args |
|
| 27 | + * @return mixed depending on query_type |
|
| 28 | + */ |
|
| 29 | + public static function get_invoice_report_data( $args = array() ) { |
|
| 30 | + global $wpdb; |
|
| 31 | + |
|
| 32 | + $default_args = array( |
|
| 33 | + 'data' => array(), // The data to retrieve. |
|
| 34 | + 'where' => array(), // An array of where queries. |
|
| 35 | + 'query_type' => 'get_row', // wpdb query to run. |
|
| 36 | + 'group_by' => '', // What to group results by. |
|
| 37 | + 'order_by' => '', // What to order by. |
|
| 38 | + 'limit' => '', // Results limit. |
|
| 39 | + 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
| 40 | + 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
| 41 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
| 42 | + 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
| 43 | + ); |
|
| 44 | + |
|
| 45 | + $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
| 46 | + $args = wp_parse_args( $args, $default_args ); |
|
| 47 | + |
|
| 48 | + extract( $args ); |
|
| 49 | + |
|
| 50 | + if ( empty( $data ) ) { |
|
| 51 | + return ''; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + $query = array(); |
|
| 55 | + $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
| 56 | + $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
| 57 | + $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
| 58 | + |
|
| 59 | + $query['where'] = " |
|
| 60 | 60 | WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
| 61 | 61 | "; |
| 62 | 62 | |
| 63 | - if ( ! empty( $invoice_status ) ) { |
|
| 64 | - $query['where'] .= " |
|
| 63 | + if ( ! empty( $invoice_status ) ) { |
|
| 64 | + $query['where'] .= " |
|
| 65 | 65 | AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
| 66 | 66 | "; |
| 67 | - } |
|
| 68 | - |
|
| 69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
| 70 | - if ( ! empty( $invoice_status ) ) { |
|
| 71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
| 72 | - } else { |
|
| 73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
| 78 | - $query['where'] .= " |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if ( ! empty( $parent_invoice_status ) ) { |
|
| 70 | + if ( ! empty( $invoice_status ) ) { |
|
| 71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
| 72 | + } else { |
|
| 73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + if ( ! empty( $filter_range['before'] ) ) { |
|
| 78 | + $query['where'] .= " |
|
| 79 | 79 | AND posts.post_date < '" . date( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
| 80 | 80 | "; |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
| 84 | - $query['where'] .= " |
|
| 83 | + if ( ! empty( $filter_range['after'] ) ) { |
|
| 84 | + $query['where'] .= " |
|
| 85 | 85 | AND posts.post_date > '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['after'] ) ) . "' |
| 86 | 86 | "; |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - if ( ! empty( $where ) ) { |
|
| 89 | + if ( ! empty( $where ) ) { |
|
| 90 | 90 | |
| 91 | - foreach ( $where as $value ) { |
|
| 91 | + foreach ( $where as $value ) { |
|
| 92 | 92 | |
| 93 | - if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) { |
|
| 94 | - |
|
| 95 | - if ( is_array( $value['value'] ) ) { |
|
| 96 | - $value['value'] = implode( "','", $value['value'] ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if ( ! empty( $value['value'] ) ) { |
|
| 100 | - $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
| 101 | - } |
|
| 102 | - } else { |
|
| 103 | - $where_value = "{$value['operator']} '{$value['value']}'"; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ( ! empty( $where_value ) ) { |
|
| 107 | - $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - if ( $group_by ) { |
|
| 113 | - $query['group_by'] = "GROUP BY {$group_by}"; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if ( $order_by ) { |
|
| 117 | - $query['order_by'] = "ORDER BY {$order_by}"; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if ( $limit ) { |
|
| 121 | - $query['limit'] = "LIMIT {$limit}"; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
| 125 | - $query = implode( ' ', $query ); |
|
| 126 | - |
|
| 127 | - return self::execute( $query_type, $query ); |
|
| 128 | - |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Prepares the data to select. |
|
| 133 | - * |
|
| 134 | - * |
|
| 135 | - * @param array $data |
|
| 136 | - * @return array |
|
| 137 | - */ |
|
| 138 | - public static function prepare_invoice_data( $data ) { |
|
| 139 | - |
|
| 140 | - $prepared = array(); |
|
| 141 | - |
|
| 142 | - foreach ( $data as $raw_key => $value ) { |
|
| 143 | - $key = sanitize_key( $raw_key ); |
|
| 144 | - $distinct = ''; |
|
| 145 | - |
|
| 146 | - if ( isset( $value['distinct'] ) ) { |
|
| 147 | - $distinct = 'DISTINCT'; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
| 151 | - |
|
| 152 | - if ( false === $get_key ) { |
|
| 153 | - // Skip to the next foreach iteration else the query will be invalid. |
|
| 154 | - continue; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if ( ! empty( $value['function'] ) ) { |
|
| 158 | - $get = "{$value['function']}({$distinct} {$get_key})"; |
|
| 159 | - } else { |
|
| 160 | - $get = "{$distinct} {$get_key}"; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - $prepared[] = "{$get} as {$value['name']}"; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return $prepared; |
|
| 167 | - |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Prepares the joins to use. |
|
| 172 | - * |
|
| 173 | - * |
|
| 174 | - * @param array $data |
|
| 175 | - * @param bool $with_parent |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
| 179 | - global $wpdb; |
|
| 180 | - |
|
| 181 | - $prepared = array(); |
|
| 182 | - |
|
| 183 | - foreach ( $data as $raw_key => $value ) { |
|
| 184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
| 185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
| 186 | - $key = sanitize_key( $raw_key ); |
|
| 187 | - |
|
| 188 | - switch ( $type ) { |
|
| 189 | - case 'meta': |
|
| 190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
| 191 | - break; |
|
| 192 | - case 'parent_meta': |
|
| 193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
| 194 | - break; |
|
| 195 | - case 'invoice_data': |
|
| 196 | - $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
| 197 | - break; |
|
| 198 | - case 'invoice_item': |
|
| 199 | - $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
| 200 | - break; |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ( $with_parent ) { |
|
| 205 | - $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $prepared; |
|
| 209 | - |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Retrieves the appropriate table key to use. |
|
| 214 | - * |
|
| 215 | - * |
|
| 216 | - * @param string $key |
|
| 217 | - * @param string $table |
|
| 218 | - * @return string|false |
|
| 219 | - */ |
|
| 220 | - public static function get_invoice_table_key( $key, $table ) { |
|
| 221 | - |
|
| 222 | - $keys = array( |
|
| 223 | - 'meta' => "meta_{$key}.meta_value", |
|
| 224 | - 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
| 225 | - 'post_data' => "posts.{$key}", |
|
| 226 | - 'invoice_data' => "invoices.{$key}", |
|
| 227 | - 'invoice_item' => "invoice_items.{$key}", |
|
| 228 | - ); |
|
| 229 | - |
|
| 230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
| 231 | - |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Executes a query and caches the result for a minute. |
|
| 236 | - * |
|
| 237 | - * |
|
| 238 | - * @param string $query_type |
|
| 239 | - * @param string $query |
|
| 240 | - * @return mixed depending on query_type |
|
| 241 | - */ |
|
| 242 | - public static function execute( $query_type, $query ) { |
|
| 243 | - global $wpdb; |
|
| 244 | - |
|
| 245 | - $query_hash = md5( $query_type . $query ); |
|
| 246 | - $result = self::get_cached_query( $query_hash ); |
|
| 247 | - if ( $result === false ) { |
|
| 248 | - self::enable_big_selects(); |
|
| 249 | - |
|
| 250 | - $result = $wpdb->$query_type( $query ); |
|
| 251 | - self::set_cached_query( $query_hash, $result ); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return $result; |
|
| 255 | - |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Enables big mysql selects for reports, just once for this session. |
|
| 260 | - */ |
|
| 261 | - protected static function enable_big_selects() { |
|
| 262 | - static $big_selects = false; |
|
| 263 | - |
|
| 264 | - global $wpdb; |
|
| 265 | - |
|
| 266 | - if ( ! $big_selects ) { |
|
| 267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
| 268 | - $big_selects = true; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Get the cached query result or null if it's not in the cache. |
|
| 274 | - * |
|
| 275 | - * @param string $query_hash The query hash. |
|
| 276 | - * |
|
| 277 | - * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
| 278 | - */ |
|
| 279 | - protected static function get_cached_query( $query_hash ) { |
|
| 280 | - |
|
| 281 | - return wp_cache_get( |
|
| 282 | - $query_hash, |
|
| 283 | - strtolower( __CLASS__ ) |
|
| 284 | - ); |
|
| 285 | - |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Set the cached query result. |
|
| 290 | - * |
|
| 291 | - * @param string $query_hash The query hash. |
|
| 292 | - * @param mixed $data The data to cache. |
|
| 293 | - */ |
|
| 294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
| 295 | - |
|
| 296 | - wp_cache_set( |
|
| 297 | - $query_hash, |
|
| 298 | - $data, |
|
| 299 | - strtolower( __CLASS__ ), |
|
| 300 | - MINUTE_IN_SECONDS |
|
| 301 | - ); |
|
| 302 | - |
|
| 303 | - } |
|
| 93 | + if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) { |
|
| 94 | + |
|
| 95 | + if ( is_array( $value['value'] ) ) { |
|
| 96 | + $value['value'] = implode( "','", $value['value'] ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if ( ! empty( $value['value'] ) ) { |
|
| 100 | + $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
| 101 | + } |
|
| 102 | + } else { |
|
| 103 | + $where_value = "{$value['operator']} '{$value['value']}'"; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ( ! empty( $where_value ) ) { |
|
| 107 | + $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + if ( $group_by ) { |
|
| 113 | + $query['group_by'] = "GROUP BY {$group_by}"; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if ( $order_by ) { |
|
| 117 | + $query['order_by'] = "ORDER BY {$order_by}"; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if ( $limit ) { |
|
| 121 | + $query['limit'] = "LIMIT {$limit}"; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
| 125 | + $query = implode( ' ', $query ); |
|
| 126 | + |
|
| 127 | + return self::execute( $query_type, $query ); |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Prepares the data to select. |
|
| 133 | + * |
|
| 134 | + * |
|
| 135 | + * @param array $data |
|
| 136 | + * @return array |
|
| 137 | + */ |
|
| 138 | + public static function prepare_invoice_data( $data ) { |
|
| 139 | + |
|
| 140 | + $prepared = array(); |
|
| 141 | + |
|
| 142 | + foreach ( $data as $raw_key => $value ) { |
|
| 143 | + $key = sanitize_key( $raw_key ); |
|
| 144 | + $distinct = ''; |
|
| 145 | + |
|
| 146 | + if ( isset( $value['distinct'] ) ) { |
|
| 147 | + $distinct = 'DISTINCT'; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
| 151 | + |
|
| 152 | + if ( false === $get_key ) { |
|
| 153 | + // Skip to the next foreach iteration else the query will be invalid. |
|
| 154 | + continue; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if ( ! empty( $value['function'] ) ) { |
|
| 158 | + $get = "{$value['function']}({$distinct} {$get_key})"; |
|
| 159 | + } else { |
|
| 160 | + $get = "{$distinct} {$get_key}"; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + $prepared[] = "{$get} as {$value['name']}"; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return $prepared; |
|
| 167 | + |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Prepares the joins to use. |
|
| 172 | + * |
|
| 173 | + * |
|
| 174 | + * @param array $data |
|
| 175 | + * @param bool $with_parent |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + public static function prepare_invoice_joins( $data, $with_parent ) { |
|
| 179 | + global $wpdb; |
|
| 180 | + |
|
| 181 | + $prepared = array(); |
|
| 182 | + |
|
| 183 | + foreach ( $data as $raw_key => $value ) { |
|
| 184 | + $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
| 185 | + $type = isset( $value['type'] ) ? $value['type'] : false; |
|
| 186 | + $key = sanitize_key( $raw_key ); |
|
| 187 | + |
|
| 188 | + switch ( $type ) { |
|
| 189 | + case 'meta': |
|
| 190 | + $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
| 191 | + break; |
|
| 192 | + case 'parent_meta': |
|
| 193 | + $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
| 194 | + break; |
|
| 195 | + case 'invoice_data': |
|
| 196 | + $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
| 197 | + break; |
|
| 198 | + case 'invoice_item': |
|
| 199 | + $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
| 200 | + break; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ( $with_parent ) { |
|
| 205 | + $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $prepared; |
|
| 209 | + |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Retrieves the appropriate table key to use. |
|
| 214 | + * |
|
| 215 | + * |
|
| 216 | + * @param string $key |
|
| 217 | + * @param string $table |
|
| 218 | + * @return string|false |
|
| 219 | + */ |
|
| 220 | + public static function get_invoice_table_key( $key, $table ) { |
|
| 221 | + |
|
| 222 | + $keys = array( |
|
| 223 | + 'meta' => "meta_{$key}.meta_value", |
|
| 224 | + 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
| 225 | + 'post_data' => "posts.{$key}", |
|
| 226 | + 'invoice_data' => "invoices.{$key}", |
|
| 227 | + 'invoice_item' => "invoice_items.{$key}", |
|
| 228 | + ); |
|
| 229 | + |
|
| 230 | + return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
| 231 | + |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Executes a query and caches the result for a minute. |
|
| 236 | + * |
|
| 237 | + * |
|
| 238 | + * @param string $query_type |
|
| 239 | + * @param string $query |
|
| 240 | + * @return mixed depending on query_type |
|
| 241 | + */ |
|
| 242 | + public static function execute( $query_type, $query ) { |
|
| 243 | + global $wpdb; |
|
| 244 | + |
|
| 245 | + $query_hash = md5( $query_type . $query ); |
|
| 246 | + $result = self::get_cached_query( $query_hash ); |
|
| 247 | + if ( $result === false ) { |
|
| 248 | + self::enable_big_selects(); |
|
| 249 | + |
|
| 250 | + $result = $wpdb->$query_type( $query ); |
|
| 251 | + self::set_cached_query( $query_hash, $result ); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return $result; |
|
| 255 | + |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Enables big mysql selects for reports, just once for this session. |
|
| 260 | + */ |
|
| 261 | + protected static function enable_big_selects() { |
|
| 262 | + static $big_selects = false; |
|
| 263 | + |
|
| 264 | + global $wpdb; |
|
| 265 | + |
|
| 266 | + if ( ! $big_selects ) { |
|
| 267 | + $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
| 268 | + $big_selects = true; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Get the cached query result or null if it's not in the cache. |
|
| 274 | + * |
|
| 275 | + * @param string $query_hash The query hash. |
|
| 276 | + * |
|
| 277 | + * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
| 278 | + */ |
|
| 279 | + protected static function get_cached_query( $query_hash ) { |
|
| 280 | + |
|
| 281 | + return wp_cache_get( |
|
| 282 | + $query_hash, |
|
| 283 | + strtolower( __CLASS__ ) |
|
| 284 | + ); |
|
| 285 | + |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Set the cached query result. |
|
| 290 | + * |
|
| 291 | + * @param string $query_hash The query hash. |
|
| 292 | + * @param mixed $data The data to cache. |
|
| 293 | + */ |
|
| 294 | + protected static function set_cached_query( $query_hash, $data ) { |
|
| 295 | + |
|
| 296 | + wp_cache_set( |
|
| 297 | + $query_hash, |
|
| 298 | + $data, |
|
| 299 | + strtolower( __CLASS__ ), |
|
| 300 | + MINUTE_IN_SECONDS |
|
| 301 | + ); |
|
| 302 | + |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | 305 | } |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | 'advanced' => false |
| 38 | 38 | ), |
| 39 | 39 | 'id' => array( |
| 40 | - 'title' => __( 'Invoice', 'invoicing' ), |
|
| 41 | - 'desc' => __( 'Enter the invoice ID', 'invoicing' ), |
|
| 42 | - 'type' => 'text', |
|
| 43 | - 'desc_tip' => true, |
|
| 44 | - 'default' => '', |
|
| 45 | - 'placeholder' => __('1','invoicing'), |
|
| 46 | - 'advanced' => false |
|
| 47 | - ), |
|
| 40 | + 'title' => __( 'Invoice', 'invoicing' ), |
|
| 41 | + 'desc' => __( 'Enter the invoice ID', 'invoicing' ), |
|
| 42 | + 'type' => 'text', |
|
| 43 | + 'desc_tip' => true, |
|
| 44 | + 'default' => '', |
|
| 45 | + 'placeholder' => __('1','invoicing'), |
|
| 46 | + 'advanced' => false |
|
| 47 | + ), |
|
| 48 | 48 | ) |
| 49 | 49 | |
| 50 | 50 | ); |
@@ -53,26 +53,26 @@ discard block |
||
| 53 | 53 | parent::__construct( $options ); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * The Super block output function. |
|
| 58 | - * |
|
| 59 | - * @param array $args |
|
| 60 | - * @param array $widget_args |
|
| 61 | - * @param string $content |
|
| 62 | - * |
|
| 63 | - * @return mixed|string|bool |
|
| 64 | - */ |
|
| 56 | + /** |
|
| 57 | + * The Super block output function. |
|
| 58 | + * |
|
| 59 | + * @param array $args |
|
| 60 | + * @param array $widget_args |
|
| 61 | + * @param string $content |
|
| 62 | + * |
|
| 63 | + * @return mixed|string|bool |
|
| 64 | + */ |
|
| 65 | 65 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 66 | 66 | |
| 67 | 67 | // Is the shortcode set up correctly? |
| 68 | - if ( empty( $args['id'] ) ) { |
|
| 69 | - return aui()->alert( |
|
| 70 | - array( |
|
| 71 | - 'type' => 'warning', |
|
| 72 | - 'content' => __( 'Missing invoice ID', 'invoicing' ), |
|
| 73 | - ) |
|
| 74 | - ); |
|
| 75 | - } |
|
| 68 | + if ( empty( $args['id'] ) ) { |
|
| 69 | + return aui()->alert( |
|
| 70 | + array( |
|
| 71 | + 'type' => 'warning', |
|
| 72 | + 'content' => __( 'Missing invoice ID', 'invoicing' ), |
|
| 73 | + ) |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | $invoice = wpinv_get_invoice( (int) $args['id'] ); |
| 78 | 78 | |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | * Bail if we are not in WP. |
| 8 | 8 | */ |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; |
|
| 10 | + exit; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Set the version only if its the current newest while loading. |
| 15 | 15 | */ |
| 16 | 16 | add_action('after_setup_theme', function () { |
| 17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | - $this_version = "0.1.67"; |
|
| 19 | - if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | - $ayecode_ui_version = $this_version ; |
|
| 21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | - } |
|
| 17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | + $this_version = "0.1.67"; |
|
| 19 | + if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | + $ayecode_ui_version = $this_version ; |
|
| 21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | + } |
|
| 23 | 23 | },0); |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
| 27 | 27 | */ |
| 28 | 28 | add_action('after_setup_theme', function () { |
| 29 | - global $ayecode_ui_file_key; |
|
| 30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | - } |
|
| 29 | + global $ayecode_ui_file_key; |
|
| 30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | + } |
|
| 34 | 34 | },1); |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Add the function that calls the class. |
| 38 | 38 | */ |
| 39 | 39 | if(!function_exists('aui')){ |
| 40 | - function aui(){ |
|
| 41 | - if(!class_exists("AUI",false)){ |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - return AUI::instance(); |
|
| 45 | - } |
|
| 40 | + function aui(){ |
|
| 41 | + if(!class_exists("AUI",false)){ |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + return AUI::instance(); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // Exit if accessed directly |
|
| 4 | + exit; // Exit if accessed directly |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -11,470 +11,470 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI_Component_Helper { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * A component helper for generating a input name. |
|
| 16 | - * |
|
| 17 | - * @param $text |
|
| 18 | - * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
| 19 | - * |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - public static function name( $text, $multiple = false ) { |
|
| 23 | - $output = ''; |
|
| 24 | - |
|
| 25 | - if ( $text ) { |
|
| 26 | - $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
| 27 | - $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - return $output; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * A component helper for generating a item id. |
|
| 35 | - * |
|
| 36 | - * @param $text string The text to be used as the value. |
|
| 37 | - * |
|
| 38 | - * @return string The sanitized item. |
|
| 39 | - */ |
|
| 40 | - public static function id( $text ) { |
|
| 41 | - $output = ''; |
|
| 42 | - |
|
| 43 | - if ( $text ) { |
|
| 44 | - $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - return $output; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * A component helper for generating a item title. |
|
| 52 | - * |
|
| 53 | - * @param $text string The text to be used as the value. |
|
| 54 | - * |
|
| 55 | - * @return string The sanitized item. |
|
| 56 | - */ |
|
| 57 | - public static function title( $text ) { |
|
| 58 | - $output = ''; |
|
| 59 | - |
|
| 60 | - if ( $text ) { |
|
| 61 | - $output = ' title="' . esc_attr( $text ) . '" '; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - return $output; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * A component helper for generating a item value. |
|
| 69 | - * |
|
| 70 | - * @param $text string The text to be used as the value. |
|
| 71 | - * |
|
| 72 | - * @return string The sanitized item. |
|
| 73 | - */ |
|
| 74 | - public static function value( $text ) { |
|
| 75 | - $output = ''; |
|
| 76 | - |
|
| 77 | - if ( $text !== null && $text !== false ) { |
|
| 78 | - $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - return $output; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * A component helper for generating a item class attribute. |
|
| 86 | - * |
|
| 87 | - * @param $text string The text to be used as the value. |
|
| 88 | - * |
|
| 89 | - * @return string The sanitized item. |
|
| 90 | - */ |
|
| 91 | - public static function class_attr( $text ) { |
|
| 92 | - $output = ''; |
|
| 93 | - |
|
| 94 | - if ( $text ) { |
|
| 95 | - $classes = self::esc_classes( $text ); |
|
| 96 | - if ( ! empty( $classes ) ) { |
|
| 97 | - $output = ' class="' . $classes . '" '; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $output; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Escape a string of classes. |
|
| 106 | - * |
|
| 107 | - * @param $text |
|
| 108 | - * |
|
| 109 | - * @return string |
|
| 110 | - */ |
|
| 111 | - public static function esc_classes( $text ) { |
|
| 112 | - $output = ''; |
|
| 113 | - |
|
| 114 | - if ( $text ) { |
|
| 115 | - $classes = explode( " ", $text ); |
|
| 116 | - $classes = array_map( "trim", $classes ); |
|
| 117 | - $classes = array_map( "sanitize_html_class", $classes ); |
|
| 118 | - if ( ! empty( $classes ) ) { |
|
| 119 | - $output = implode( " ", $classes ); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $output; |
|
| 124 | - |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param $args |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public static function data_attributes( $args ) { |
|
| 133 | - $output = ''; |
|
| 134 | - |
|
| 135 | - if ( ! empty( $args ) ) { |
|
| 136 | - |
|
| 137 | - foreach ( $args as $key => $val ) { |
|
| 138 | - if ( substr( $key, 0, 5 ) === "data-" ) { |
|
| 139 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $output; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param $args |
|
| 149 | - * |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public static function aria_attributes( $args ) { |
|
| 153 | - $output = ''; |
|
| 154 | - |
|
| 155 | - if ( ! empty( $args ) ) { |
|
| 156 | - |
|
| 157 | - foreach ( $args as $key => $val ) { |
|
| 158 | - if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
| 159 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $output; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Build a font awesome icon from a class. |
|
| 169 | - * |
|
| 170 | - * @param $class |
|
| 171 | - * @param bool $space_after |
|
| 172 | - * @param array $extra_attributes An array of extra attributes. |
|
| 173 | - * |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
| 177 | - $output = ''; |
|
| 178 | - |
|
| 179 | - if ( $class ) { |
|
| 180 | - $classes = self::esc_classes( $class ); |
|
| 181 | - if ( ! empty( $classes ) ) { |
|
| 182 | - $output = '<i class="' . $classes . '" '; |
|
| 183 | - // extra attributes |
|
| 184 | - if ( ! empty( $extra_attributes ) ) { |
|
| 185 | - $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
| 186 | - } |
|
| 187 | - $output .= '></i>'; |
|
| 188 | - if ( $space_after ) { |
|
| 189 | - $output .= " "; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $output; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param $args |
|
| 199 | - * |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public static function extra_attributes( $args ) { |
|
| 203 | - $output = ''; |
|
| 204 | - |
|
| 205 | - if ( ! empty( $args ) ) { |
|
| 206 | - |
|
| 207 | - if ( is_array( $args ) ) { |
|
| 208 | - foreach ( $args as $key => $val ) { |
|
| 209 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
| 210 | - } |
|
| 211 | - } else { |
|
| 212 | - $output .= ' ' . $args . ' '; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $output; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @param $args |
|
| 222 | - * |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - public static function help_text( $text ) { |
|
| 226 | - $output = ''; |
|
| 227 | - |
|
| 228 | - if ( $text ) { |
|
| 229 | - $output .= '<small class="form-text text-muted">' . wp_kses_post( $text ) . '</small>'; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - return $output; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Replace element require context with JS. |
|
| 238 | - * |
|
| 239 | - * @param $input |
|
| 240 | - * |
|
| 241 | - * @return string|void |
|
| 242 | - */ |
|
| 243 | - public static function element_require( $input ) { |
|
| 244 | - |
|
| 245 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 246 | - |
|
| 247 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
| 248 | - "jQuery(form).find('[data-argument=\"", |
|
| 249 | - "\"]').find('input,select,textarea').val()", |
|
| 250 | - "\"]').find('input:checked').val()", |
|
| 251 | - ), $input ) ); |
|
| 252 | - |
|
| 253 | - if ( $output ) { |
|
| 254 | - $output = ' data-element-require="' . $output . '" '; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $output; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
| 262 | - * |
|
| 263 | - * @since 0.1.41 |
|
| 264 | - * |
|
| 265 | - * @param mixed $value The value to be stripped. |
|
| 266 | - * @param array $input Input Field. |
|
| 267 | - * |
|
| 268 | - * @return mixed Stripped value. |
|
| 269 | - */ |
|
| 270 | - public static function sanitize_html_field( $value, $input = array() ) { |
|
| 271 | - $original = $value; |
|
| 272 | - |
|
| 273 | - if ( is_array( $value ) ) { |
|
| 274 | - foreach ( $value as $index => $item ) { |
|
| 275 | - $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
| 276 | - } |
|
| 277 | - } elseif ( is_object( $value ) ) { |
|
| 278 | - $object_vars = get_object_vars( $value ); |
|
| 279 | - |
|
| 280 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
| 281 | - $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
| 282 | - } |
|
| 283 | - } else { |
|
| 284 | - $value = self::_sanitize_html_field( $value, $input ); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Filters content and keeps only allowable HTML elements. |
|
| 289 | - * |
|
| 290 | - * @since 0.1.41 |
|
| 291 | - * |
|
| 292 | - * @param string|array $value Content to filter through kses. |
|
| 293 | - * @param string|array $value Original content without filter. |
|
| 294 | - * @param array $input Input Field. |
|
| 295 | - */ |
|
| 296 | - return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Filters content and keeps only allowable HTML elements. |
|
| 301 | - * |
|
| 302 | - * This function makes sure that only the allowed HTML element names, attribute |
|
| 303 | - * names and attribute values plus only sane HTML entities will occur in |
|
| 304 | - * $string. You have to remove any slashes from PHP's magic quotes before you |
|
| 305 | - * call this function. |
|
| 306 | - * |
|
| 307 | - * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
| 308 | - * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
| 309 | - * covers all common link protocols, except for 'javascript' which should not |
|
| 310 | - * be allowed for untrusted users. |
|
| 311 | - * |
|
| 312 | - * @since 0.1.41 |
|
| 313 | - * |
|
| 314 | - * @param string|array $value Content to filter through kses. |
|
| 315 | - * @param array $input Input Field. |
|
| 316 | - * |
|
| 317 | - * @return string Filtered content with only allowed HTML elements. |
|
| 318 | - */ |
|
| 319 | - public static function _sanitize_html_field( $value, $input = array() ) { |
|
| 320 | - if ( $value === '' ) { |
|
| 321 | - return $value; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
| 325 | - |
|
| 326 | - if ( ! is_array( $allowed_html ) ) { |
|
| 327 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - $filtered = trim( wp_unslash( $value ) ); |
|
| 331 | - $filtered = wp_kses( $filtered, $allowed_html ); |
|
| 332 | - $filtered = balanceTags( $filtered ); // Balances tags |
|
| 333 | - |
|
| 334 | - return $filtered; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Returns an array of allowed HTML tags and attributes for a given context. |
|
| 339 | - * |
|
| 340 | - * @since 0.1.41 |
|
| 341 | - * |
|
| 342 | - * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
| 343 | - * 'strip', 'data', 'entities', or the name of a field filter such as |
|
| 344 | - * 'pre_user_description'. |
|
| 345 | - * @param array $input Input. |
|
| 346 | - * |
|
| 347 | - * @return array Array of allowed HTML tags and their allowed attributes. |
|
| 348 | - */ |
|
| 349 | - public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
| 350 | - $allowed_html = wp_kses_allowed_html( $context ); |
|
| 351 | - |
|
| 352 | - if ( is_array( $allowed_html ) ) { |
|
| 353 | - // <iframe> |
|
| 354 | - if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
| 355 | - $allowed_html['iframe'] = array( |
|
| 356 | - 'class' => true, |
|
| 357 | - 'id' => true, |
|
| 358 | - 'src' => true, |
|
| 359 | - 'width' => true, |
|
| 360 | - 'height' => true, |
|
| 361 | - 'frameborder' => true, |
|
| 362 | - 'marginwidth' => true, |
|
| 363 | - 'marginheight' => true, |
|
| 364 | - 'scrolling' => true, |
|
| 365 | - 'style' => true, |
|
| 366 | - 'title' => true, |
|
| 367 | - 'allow' => true, |
|
| 368 | - 'allowfullscreen' => true, |
|
| 369 | - 'data-*' => true, |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Filters the allowed html tags. |
|
| 376 | - * |
|
| 377 | - * @since 0.1.41 |
|
| 378 | - * |
|
| 379 | - * @param array[]|string $allowed_html Allowed html tags. |
|
| 380 | - * @param @param string|array $context The context for which to retrieve tags. |
|
| 381 | - * @param array $input Input field. |
|
| 382 | - */ |
|
| 383 | - return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
| 387 | - |
|
| 388 | - $class = ''; |
|
| 389 | - |
|
| 390 | - // set default if empty |
|
| 391 | - if( $label_number === '' ){ |
|
| 392 | - $label_number = 2; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
| 396 | - if ( $type == 'label' ) { |
|
| 397 | - $class = 'col-sm-' . absint( $label_number ); |
|
| 398 | - } elseif ( $type == 'input' ) { |
|
| 399 | - $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - return $class; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Sanitizes a multiline string from user input or from the database. |
|
| 408 | - * |
|
| 409 | - * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way. |
|
| 410 | - * |
|
| 411 | - * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original |
|
| 412 | - * |
|
| 413 | - * @since 0.1.66 |
|
| 414 | - * |
|
| 415 | - * @param string $str String to sanitize. |
|
| 416 | - * @return string Sanitized string. |
|
| 417 | - */ |
|
| 418 | - public static function sanitize_textarea_field( $str ) { |
|
| 419 | - $filtered = self::_sanitize_text_fields( $str, true ); |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Filters a sanitized textarea field string. |
|
| 423 | - * |
|
| 424 | - * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php |
|
| 425 | - * |
|
| 426 | - * @param string $filtered The sanitized string. |
|
| 427 | - * @param string $str The string prior to being sanitized. |
|
| 428 | - */ |
|
| 429 | - return apply_filters( 'sanitize_textarea_field', $filtered, $str ); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Internal helper function to sanitize a string from user input or from the db. |
|
| 434 | - * |
|
| 435 | - * @since 0.1.66 |
|
| 436 | - * @access private |
|
| 437 | - * |
|
| 438 | - * @param string $str String to sanitize. |
|
| 439 | - * @param bool $keep_newlines Optional. Whether to keep newlines. Default: false. |
|
| 440 | - * @return string Sanitized string. |
|
| 441 | - */ |
|
| 442 | - public static function _sanitize_text_fields( $str, $keep_newlines = false ) { |
|
| 443 | - if ( is_object( $str ) || is_array( $str ) ) { |
|
| 444 | - return ''; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - $str = (string) $str; |
|
| 448 | - |
|
| 449 | - $filtered = wp_check_invalid_utf8( $str ); |
|
| 450 | - |
|
| 451 | - if ( strpos( $filtered, '<' ) !== false ) { |
|
| 452 | - $filtered = wp_pre_kses_less_than( $filtered ); |
|
| 453 | - // This will strip extra whitespace for us. |
|
| 454 | - $filtered = wp_strip_all_tags( $filtered, false ); |
|
| 455 | - |
|
| 456 | - // Use HTML entities in a special case to make sure no later |
|
| 457 | - // newline stripping stage could lead to a functional tag. |
|
| 458 | - $filtered = str_replace( "<\n", "<\n", $filtered ); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - if ( ! $keep_newlines ) { |
|
| 462 | - $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
|
| 463 | - } |
|
| 464 | - $filtered = trim( $filtered ); |
|
| 465 | - |
|
| 466 | - $found = false; |
|
| 467 | - while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) { |
|
| 468 | - $filtered = str_replace( $match[1], '', $filtered ); |
|
| 469 | - $found = true; |
|
| 470 | - } |
|
| 471 | - unset( $match ); |
|
| 472 | - |
|
| 473 | - if ( $found ) { |
|
| 474 | - // Strip out the whitespace that may now exist after removing the octets. |
|
| 475 | - $filtered = trim( preg_replace( '` +`', ' ', $filtered ) ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - return $filtered; |
|
| 479 | - } |
|
| 14 | + /** |
|
| 15 | + * A component helper for generating a input name. |
|
| 16 | + * |
|
| 17 | + * @param $text |
|
| 18 | + * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
| 19 | + * |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + public static function name( $text, $multiple = false ) { |
|
| 23 | + $output = ''; |
|
| 24 | + |
|
| 25 | + if ( $text ) { |
|
| 26 | + $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
| 27 | + $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + return $output; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * A component helper for generating a item id. |
|
| 35 | + * |
|
| 36 | + * @param $text string The text to be used as the value. |
|
| 37 | + * |
|
| 38 | + * @return string The sanitized item. |
|
| 39 | + */ |
|
| 40 | + public static function id( $text ) { |
|
| 41 | + $output = ''; |
|
| 42 | + |
|
| 43 | + if ( $text ) { |
|
| 44 | + $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + return $output; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * A component helper for generating a item title. |
|
| 52 | + * |
|
| 53 | + * @param $text string The text to be used as the value. |
|
| 54 | + * |
|
| 55 | + * @return string The sanitized item. |
|
| 56 | + */ |
|
| 57 | + public static function title( $text ) { |
|
| 58 | + $output = ''; |
|
| 59 | + |
|
| 60 | + if ( $text ) { |
|
| 61 | + $output = ' title="' . esc_attr( $text ) . '" '; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + return $output; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * A component helper for generating a item value. |
|
| 69 | + * |
|
| 70 | + * @param $text string The text to be used as the value. |
|
| 71 | + * |
|
| 72 | + * @return string The sanitized item. |
|
| 73 | + */ |
|
| 74 | + public static function value( $text ) { |
|
| 75 | + $output = ''; |
|
| 76 | + |
|
| 77 | + if ( $text !== null && $text !== false ) { |
|
| 78 | + $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + return $output; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * A component helper for generating a item class attribute. |
|
| 86 | + * |
|
| 87 | + * @param $text string The text to be used as the value. |
|
| 88 | + * |
|
| 89 | + * @return string The sanitized item. |
|
| 90 | + */ |
|
| 91 | + public static function class_attr( $text ) { |
|
| 92 | + $output = ''; |
|
| 93 | + |
|
| 94 | + if ( $text ) { |
|
| 95 | + $classes = self::esc_classes( $text ); |
|
| 96 | + if ( ! empty( $classes ) ) { |
|
| 97 | + $output = ' class="' . $classes . '" '; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $output; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Escape a string of classes. |
|
| 106 | + * |
|
| 107 | + * @param $text |
|
| 108 | + * |
|
| 109 | + * @return string |
|
| 110 | + */ |
|
| 111 | + public static function esc_classes( $text ) { |
|
| 112 | + $output = ''; |
|
| 113 | + |
|
| 114 | + if ( $text ) { |
|
| 115 | + $classes = explode( " ", $text ); |
|
| 116 | + $classes = array_map( "trim", $classes ); |
|
| 117 | + $classes = array_map( "sanitize_html_class", $classes ); |
|
| 118 | + if ( ! empty( $classes ) ) { |
|
| 119 | + $output = implode( " ", $classes ); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $output; |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param $args |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public static function data_attributes( $args ) { |
|
| 133 | + $output = ''; |
|
| 134 | + |
|
| 135 | + if ( ! empty( $args ) ) { |
|
| 136 | + |
|
| 137 | + foreach ( $args as $key => $val ) { |
|
| 138 | + if ( substr( $key, 0, 5 ) === "data-" ) { |
|
| 139 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $output; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param $args |
|
| 149 | + * |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public static function aria_attributes( $args ) { |
|
| 153 | + $output = ''; |
|
| 154 | + |
|
| 155 | + if ( ! empty( $args ) ) { |
|
| 156 | + |
|
| 157 | + foreach ( $args as $key => $val ) { |
|
| 158 | + if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
| 159 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $output; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Build a font awesome icon from a class. |
|
| 169 | + * |
|
| 170 | + * @param $class |
|
| 171 | + * @param bool $space_after |
|
| 172 | + * @param array $extra_attributes An array of extra attributes. |
|
| 173 | + * |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
| 177 | + $output = ''; |
|
| 178 | + |
|
| 179 | + if ( $class ) { |
|
| 180 | + $classes = self::esc_classes( $class ); |
|
| 181 | + if ( ! empty( $classes ) ) { |
|
| 182 | + $output = '<i class="' . $classes . '" '; |
|
| 183 | + // extra attributes |
|
| 184 | + if ( ! empty( $extra_attributes ) ) { |
|
| 185 | + $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
| 186 | + } |
|
| 187 | + $output .= '></i>'; |
|
| 188 | + if ( $space_after ) { |
|
| 189 | + $output .= " "; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $output; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param $args |
|
| 199 | + * |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public static function extra_attributes( $args ) { |
|
| 203 | + $output = ''; |
|
| 204 | + |
|
| 205 | + if ( ! empty( $args ) ) { |
|
| 206 | + |
|
| 207 | + if ( is_array( $args ) ) { |
|
| 208 | + foreach ( $args as $key => $val ) { |
|
| 209 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
| 210 | + } |
|
| 211 | + } else { |
|
| 212 | + $output .= ' ' . $args . ' '; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return $output; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @param $args |
|
| 222 | + * |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + public static function help_text( $text ) { |
|
| 226 | + $output = ''; |
|
| 227 | + |
|
| 228 | + if ( $text ) { |
|
| 229 | + $output .= '<small class="form-text text-muted">' . wp_kses_post( $text ) . '</small>'; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + return $output; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Replace element require context with JS. |
|
| 238 | + * |
|
| 239 | + * @param $input |
|
| 240 | + * |
|
| 241 | + * @return string|void |
|
| 242 | + */ |
|
| 243 | + public static function element_require( $input ) { |
|
| 244 | + |
|
| 245 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 246 | + |
|
| 247 | + $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
| 248 | + "jQuery(form).find('[data-argument=\"", |
|
| 249 | + "\"]').find('input,select,textarea').val()", |
|
| 250 | + "\"]').find('input:checked').val()", |
|
| 251 | + ), $input ) ); |
|
| 252 | + |
|
| 253 | + if ( $output ) { |
|
| 254 | + $output = ' data-element-require="' . $output . '" '; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $output; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
| 262 | + * |
|
| 263 | + * @since 0.1.41 |
|
| 264 | + * |
|
| 265 | + * @param mixed $value The value to be stripped. |
|
| 266 | + * @param array $input Input Field. |
|
| 267 | + * |
|
| 268 | + * @return mixed Stripped value. |
|
| 269 | + */ |
|
| 270 | + public static function sanitize_html_field( $value, $input = array() ) { |
|
| 271 | + $original = $value; |
|
| 272 | + |
|
| 273 | + if ( is_array( $value ) ) { |
|
| 274 | + foreach ( $value as $index => $item ) { |
|
| 275 | + $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
| 276 | + } |
|
| 277 | + } elseif ( is_object( $value ) ) { |
|
| 278 | + $object_vars = get_object_vars( $value ); |
|
| 279 | + |
|
| 280 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
| 281 | + $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
| 282 | + } |
|
| 283 | + } else { |
|
| 284 | + $value = self::_sanitize_html_field( $value, $input ); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Filters content and keeps only allowable HTML elements. |
|
| 289 | + * |
|
| 290 | + * @since 0.1.41 |
|
| 291 | + * |
|
| 292 | + * @param string|array $value Content to filter through kses. |
|
| 293 | + * @param string|array $value Original content without filter. |
|
| 294 | + * @param array $input Input Field. |
|
| 295 | + */ |
|
| 296 | + return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Filters content and keeps only allowable HTML elements. |
|
| 301 | + * |
|
| 302 | + * This function makes sure that only the allowed HTML element names, attribute |
|
| 303 | + * names and attribute values plus only sane HTML entities will occur in |
|
| 304 | + * $string. You have to remove any slashes from PHP's magic quotes before you |
|
| 305 | + * call this function. |
|
| 306 | + * |
|
| 307 | + * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
| 308 | + * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
| 309 | + * covers all common link protocols, except for 'javascript' which should not |
|
| 310 | + * be allowed for untrusted users. |
|
| 311 | + * |
|
| 312 | + * @since 0.1.41 |
|
| 313 | + * |
|
| 314 | + * @param string|array $value Content to filter through kses. |
|
| 315 | + * @param array $input Input Field. |
|
| 316 | + * |
|
| 317 | + * @return string Filtered content with only allowed HTML elements. |
|
| 318 | + */ |
|
| 319 | + public static function _sanitize_html_field( $value, $input = array() ) { |
|
| 320 | + if ( $value === '' ) { |
|
| 321 | + return $value; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
| 325 | + |
|
| 326 | + if ( ! is_array( $allowed_html ) ) { |
|
| 327 | + $allowed_html = wp_kses_allowed_html( 'post' ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + $filtered = trim( wp_unslash( $value ) ); |
|
| 331 | + $filtered = wp_kses( $filtered, $allowed_html ); |
|
| 332 | + $filtered = balanceTags( $filtered ); // Balances tags |
|
| 333 | + |
|
| 334 | + return $filtered; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Returns an array of allowed HTML tags and attributes for a given context. |
|
| 339 | + * |
|
| 340 | + * @since 0.1.41 |
|
| 341 | + * |
|
| 342 | + * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
| 343 | + * 'strip', 'data', 'entities', or the name of a field filter such as |
|
| 344 | + * 'pre_user_description'. |
|
| 345 | + * @param array $input Input. |
|
| 346 | + * |
|
| 347 | + * @return array Array of allowed HTML tags and their allowed attributes. |
|
| 348 | + */ |
|
| 349 | + public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
| 350 | + $allowed_html = wp_kses_allowed_html( $context ); |
|
| 351 | + |
|
| 352 | + if ( is_array( $allowed_html ) ) { |
|
| 353 | + // <iframe> |
|
| 354 | + if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
| 355 | + $allowed_html['iframe'] = array( |
|
| 356 | + 'class' => true, |
|
| 357 | + 'id' => true, |
|
| 358 | + 'src' => true, |
|
| 359 | + 'width' => true, |
|
| 360 | + 'height' => true, |
|
| 361 | + 'frameborder' => true, |
|
| 362 | + 'marginwidth' => true, |
|
| 363 | + 'marginheight' => true, |
|
| 364 | + 'scrolling' => true, |
|
| 365 | + 'style' => true, |
|
| 366 | + 'title' => true, |
|
| 367 | + 'allow' => true, |
|
| 368 | + 'allowfullscreen' => true, |
|
| 369 | + 'data-*' => true, |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Filters the allowed html tags. |
|
| 376 | + * |
|
| 377 | + * @since 0.1.41 |
|
| 378 | + * |
|
| 379 | + * @param array[]|string $allowed_html Allowed html tags. |
|
| 380 | + * @param @param string|array $context The context for which to retrieve tags. |
|
| 381 | + * @param array $input Input field. |
|
| 382 | + */ |
|
| 383 | + return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
| 387 | + |
|
| 388 | + $class = ''; |
|
| 389 | + |
|
| 390 | + // set default if empty |
|
| 391 | + if( $label_number === '' ){ |
|
| 392 | + $label_number = 2; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
| 396 | + if ( $type == 'label' ) { |
|
| 397 | + $class = 'col-sm-' . absint( $label_number ); |
|
| 398 | + } elseif ( $type == 'input' ) { |
|
| 399 | + $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + return $class; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Sanitizes a multiline string from user input or from the database. |
|
| 408 | + * |
|
| 409 | + * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way. |
|
| 410 | + * |
|
| 411 | + * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original |
|
| 412 | + * |
|
| 413 | + * @since 0.1.66 |
|
| 414 | + * |
|
| 415 | + * @param string $str String to sanitize. |
|
| 416 | + * @return string Sanitized string. |
|
| 417 | + */ |
|
| 418 | + public static function sanitize_textarea_field( $str ) { |
|
| 419 | + $filtered = self::_sanitize_text_fields( $str, true ); |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Filters a sanitized textarea field string. |
|
| 423 | + * |
|
| 424 | + * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php |
|
| 425 | + * |
|
| 426 | + * @param string $filtered The sanitized string. |
|
| 427 | + * @param string $str The string prior to being sanitized. |
|
| 428 | + */ |
|
| 429 | + return apply_filters( 'sanitize_textarea_field', $filtered, $str ); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Internal helper function to sanitize a string from user input or from the db. |
|
| 434 | + * |
|
| 435 | + * @since 0.1.66 |
|
| 436 | + * @access private |
|
| 437 | + * |
|
| 438 | + * @param string $str String to sanitize. |
|
| 439 | + * @param bool $keep_newlines Optional. Whether to keep newlines. Default: false. |
|
| 440 | + * @return string Sanitized string. |
|
| 441 | + */ |
|
| 442 | + public static function _sanitize_text_fields( $str, $keep_newlines = false ) { |
|
| 443 | + if ( is_object( $str ) || is_array( $str ) ) { |
|
| 444 | + return ''; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + $str = (string) $str; |
|
| 448 | + |
|
| 449 | + $filtered = wp_check_invalid_utf8( $str ); |
|
| 450 | + |
|
| 451 | + if ( strpos( $filtered, '<' ) !== false ) { |
|
| 452 | + $filtered = wp_pre_kses_less_than( $filtered ); |
|
| 453 | + // This will strip extra whitespace for us. |
|
| 454 | + $filtered = wp_strip_all_tags( $filtered, false ); |
|
| 455 | + |
|
| 456 | + // Use HTML entities in a special case to make sure no later |
|
| 457 | + // newline stripping stage could lead to a functional tag. |
|
| 458 | + $filtered = str_replace( "<\n", "<\n", $filtered ); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + if ( ! $keep_newlines ) { |
|
| 462 | + $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
|
| 463 | + } |
|
| 464 | + $filtered = trim( $filtered ); |
|
| 465 | + |
|
| 466 | + $found = false; |
|
| 467 | + while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) { |
|
| 468 | + $filtered = str_replace( $match[1], '', $filtered ); |
|
| 469 | + $found = true; |
|
| 470 | + } |
|
| 471 | + unset( $match ); |
|
| 472 | + |
|
| 473 | + if ( $found ) { |
|
| 474 | + // Strip out the whitespace that may now exist after removing the octets. |
|
| 475 | + $filtered = trim( preg_replace( '` +`', ' ', $filtered ) ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + return $filtered; |
|
| 479 | + } |
|
| 480 | 480 | } |
| 481 | 481 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // Exit if accessed directly |
|
| 4 | + exit; // Exit if accessed directly |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -11,1210 +11,1210 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI_Component_Input { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Build the component. |
|
| 16 | - * |
|
| 17 | - * @param array $args |
|
| 18 | - * |
|
| 19 | - * @return string The rendered component. |
|
| 20 | - */ |
|
| 21 | - public static function input( $args = array() ) { |
|
| 22 | - $defaults = array( |
|
| 23 | - 'type' => 'text', |
|
| 24 | - 'name' => '', |
|
| 25 | - 'class' => '', |
|
| 26 | - 'wrap_class' => '', |
|
| 27 | - 'id' => '', |
|
| 28 | - 'placeholder' => '', |
|
| 29 | - 'title' => '', |
|
| 30 | - 'value' => '', |
|
| 31 | - 'required' => false, |
|
| 32 | - 'label' => '', |
|
| 33 | - 'label_after' => false, |
|
| 34 | - 'label_class' => '', |
|
| 35 | - 'label_col' => '2', |
|
| 36 | - 'label_type' => '', |
|
| 37 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
| 38 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 39 | - 'help_text' => '', |
|
| 40 | - 'validation_text' => '', |
|
| 41 | - 'validation_pattern' => '', |
|
| 42 | - 'no_wrap' => false, |
|
| 43 | - 'input_group_right' => '', |
|
| 44 | - 'input_group_left' => '', |
|
| 45 | - 'input_group_right_inside' => false, |
|
| 46 | - // forces the input group inside the input |
|
| 47 | - 'input_group_left_inside' => false, |
|
| 48 | - // forces the input group inside the input |
|
| 49 | - 'step' => '', |
|
| 50 | - 'switch' => false, |
|
| 51 | - // to show checkbox as a switch |
|
| 52 | - 'checked' => false, |
|
| 53 | - // set a checkbox or radio as selected |
|
| 54 | - 'password_toggle' => true, |
|
| 55 | - // toggle view/hide password |
|
| 56 | - 'element_require' => '', |
|
| 57 | - // [%element_id%] == "1" |
|
| 58 | - 'extra_attributes' => array(), |
|
| 59 | - // an array of extra attributes |
|
| 60 | - 'wrap_attributes' => array() |
|
| 61 | - ); |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 65 | - */ |
|
| 66 | - $args = wp_parse_args( $args, $defaults ); |
|
| 67 | - $output = ''; |
|
| 68 | - if ( ! empty( $args['type'] ) ) { |
|
| 69 | - // hidden label option needs to be empty |
|
| 70 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 71 | - |
|
| 72 | - $type = sanitize_html_class( $args['type'] ); |
|
| 73 | - |
|
| 74 | - $help_text = ''; |
|
| 75 | - $label = ''; |
|
| 76 | - $label_after = $args['label_after']; |
|
| 77 | - $label_args = array( |
|
| 78 | - 'title' => $args['label'], |
|
| 79 | - 'for' => $args['id'], |
|
| 80 | - 'class' => $args['label_class'] . " ", |
|
| 81 | - 'label_type' => $args['label_type'], |
|
| 82 | - 'label_col' => $args['label_col'] |
|
| 83 | - ); |
|
| 84 | - |
|
| 85 | - // floating labels need label after |
|
| 86 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
| 87 | - $label_after = true; |
|
| 88 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Some special sauce for files |
|
| 92 | - if ( $type == 'file' ) { |
|
| 93 | - $label_after = true; // if type file we need the label after |
|
| 94 | - $args['class'] .= ' custom-file-input '; |
|
| 95 | - } elseif ( $type == 'checkbox' ) { |
|
| 96 | - $label_after = true; // if type file we need the label after |
|
| 97 | - $args['class'] .= ' custom-control-input '; |
|
| 98 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
| 99 | - $type = 'text'; |
|
| 100 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 101 | - $args['class'] .= ' bg-initial '; |
|
| 102 | - |
|
| 103 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
| 104 | - // enqueue the script |
|
| 105 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 106 | - $aui_settings->enqueue_flatpickr(); |
|
| 107 | - } elseif ( $type == 'iconpicker' ) { |
|
| 108 | - $type = 'text'; |
|
| 109 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 14 | + /** |
|
| 15 | + * Build the component. |
|
| 16 | + * |
|
| 17 | + * @param array $args |
|
| 18 | + * |
|
| 19 | + * @return string The rendered component. |
|
| 20 | + */ |
|
| 21 | + public static function input( $args = array() ) { |
|
| 22 | + $defaults = array( |
|
| 23 | + 'type' => 'text', |
|
| 24 | + 'name' => '', |
|
| 25 | + 'class' => '', |
|
| 26 | + 'wrap_class' => '', |
|
| 27 | + 'id' => '', |
|
| 28 | + 'placeholder' => '', |
|
| 29 | + 'title' => '', |
|
| 30 | + 'value' => '', |
|
| 31 | + 'required' => false, |
|
| 32 | + 'label' => '', |
|
| 33 | + 'label_after' => false, |
|
| 34 | + 'label_class' => '', |
|
| 35 | + 'label_col' => '2', |
|
| 36 | + 'label_type' => '', |
|
| 37 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
| 38 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 39 | + 'help_text' => '', |
|
| 40 | + 'validation_text' => '', |
|
| 41 | + 'validation_pattern' => '', |
|
| 42 | + 'no_wrap' => false, |
|
| 43 | + 'input_group_right' => '', |
|
| 44 | + 'input_group_left' => '', |
|
| 45 | + 'input_group_right_inside' => false, |
|
| 46 | + // forces the input group inside the input |
|
| 47 | + 'input_group_left_inside' => false, |
|
| 48 | + // forces the input group inside the input |
|
| 49 | + 'step' => '', |
|
| 50 | + 'switch' => false, |
|
| 51 | + // to show checkbox as a switch |
|
| 52 | + 'checked' => false, |
|
| 53 | + // set a checkbox or radio as selected |
|
| 54 | + 'password_toggle' => true, |
|
| 55 | + // toggle view/hide password |
|
| 56 | + 'element_require' => '', |
|
| 57 | + // [%element_id%] == "1" |
|
| 58 | + 'extra_attributes' => array(), |
|
| 59 | + // an array of extra attributes |
|
| 60 | + 'wrap_attributes' => array() |
|
| 61 | + ); |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 65 | + */ |
|
| 66 | + $args = wp_parse_args( $args, $defaults ); |
|
| 67 | + $output = ''; |
|
| 68 | + if ( ! empty( $args['type'] ) ) { |
|
| 69 | + // hidden label option needs to be empty |
|
| 70 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 71 | + |
|
| 72 | + $type = sanitize_html_class( $args['type'] ); |
|
| 73 | + |
|
| 74 | + $help_text = ''; |
|
| 75 | + $label = ''; |
|
| 76 | + $label_after = $args['label_after']; |
|
| 77 | + $label_args = array( |
|
| 78 | + 'title' => $args['label'], |
|
| 79 | + 'for' => $args['id'], |
|
| 80 | + 'class' => $args['label_class'] . " ", |
|
| 81 | + 'label_type' => $args['label_type'], |
|
| 82 | + 'label_col' => $args['label_col'] |
|
| 83 | + ); |
|
| 84 | + |
|
| 85 | + // floating labels need label after |
|
| 86 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
| 87 | + $label_after = true; |
|
| 88 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Some special sauce for files |
|
| 92 | + if ( $type == 'file' ) { |
|
| 93 | + $label_after = true; // if type file we need the label after |
|
| 94 | + $args['class'] .= ' custom-file-input '; |
|
| 95 | + } elseif ( $type == 'checkbox' ) { |
|
| 96 | + $label_after = true; // if type file we need the label after |
|
| 97 | + $args['class'] .= ' custom-control-input '; |
|
| 98 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
| 99 | + $type = 'text'; |
|
| 100 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 101 | + $args['class'] .= ' bg-initial '; |
|
| 102 | + |
|
| 103 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
| 104 | + // enqueue the script |
|
| 105 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 106 | + $aui_settings->enqueue_flatpickr(); |
|
| 107 | + } elseif ( $type == 'iconpicker' ) { |
|
| 108 | + $type = 'text'; |
|
| 109 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 110 | 110 | // $args['class'] .= ' bg-initial '; |
| 111 | 111 | |
| 112 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
| 113 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
| 112 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
| 113 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
| 114 | 114 | |
| 115 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
| 115 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
| 116 | 116 | // $args['input_group_right_inside'] = true; |
| 117 | - // enqueue the script |
|
| 118 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 119 | - $aui_settings->enqueue_iconpicker(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
| 123 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - // open/type |
|
| 128 | - $output .= '<input type="' . $type . '" '; |
|
| 129 | - |
|
| 130 | - // name |
|
| 131 | - if ( ! empty( $args['name'] ) ) { |
|
| 132 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // id |
|
| 136 | - if ( ! empty( $args['id'] ) ) { |
|
| 137 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // placeholder |
|
| 141 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 142 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // title |
|
| 146 | - if ( ! empty( $args['title'] ) ) { |
|
| 147 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // value |
|
| 151 | - if ( ! empty( $args['value'] ) ) { |
|
| 152 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // checked, for radio and checkboxes |
|
| 156 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
| 157 | - $output .= ' checked '; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - // validation text |
|
| 161 | - if ( ! empty( $args['validation_text'] ) ) { |
|
| 162 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
| 163 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // validation_pattern |
|
| 167 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 168 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // step (for numbers) |
|
| 172 | - if ( ! empty( $args['step'] ) ) { |
|
| 173 | - $output .= ' step="' . $args['step'] . '" '; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // required |
|
| 177 | - if ( ! empty( $args['required'] ) ) { |
|
| 178 | - $output .= ' required '; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // class |
|
| 182 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 183 | - $output .= ' class="form-control ' . $class . '" '; |
|
| 184 | - |
|
| 185 | - // data-attributes |
|
| 186 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 187 | - |
|
| 188 | - // extra attributes |
|
| 189 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 190 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // close |
|
| 194 | - $output .= ' >'; |
|
| 195 | - |
|
| 196 | - // help text |
|
| 197 | - if ( ! empty( $args['help_text'] ) ) { |
|
| 198 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // label |
|
| 202 | - if ( ! empty( $args['label'] ) ) { |
|
| 203 | - $label_base_class = ''; |
|
| 204 | - if ( $type == 'file' ) { |
|
| 205 | - $label_base_class = ' custom-file-label'; |
|
| 206 | - } elseif ( $type == 'checkbox' ) { |
|
| 207 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
| 208 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
| 209 | - $help_text = ''; |
|
| 210 | - //$label_args['class'] .= ' d-inline '; |
|
| 211 | - $args['wrap_class'] .= ' align-items-center '; |
|
| 212 | - }else{ |
|
| 213 | - |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $label_base_class = ' custom-control-label'; |
|
| 217 | - } |
|
| 218 | - $label_args['class'] .= $label_base_class; |
|
| 219 | - $temp_label_args = $label_args; |
|
| 220 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
| 221 | - $label = self::label( $temp_label_args, $type ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - // set help text in the correct position |
|
| 228 | - if ( $label_after ) { |
|
| 229 | - $output .= $label . $help_text; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // some input types need a separate wrap |
|
| 233 | - if ( $type == 'file' ) { |
|
| 234 | - $output = self::wrap( array( |
|
| 235 | - 'content' => $output, |
|
| 236 | - 'class' => 'form-group custom-file' |
|
| 237 | - ) ); |
|
| 238 | - } elseif ( $type == 'checkbox' ) { |
|
| 239 | - |
|
| 240 | - $label_args['title'] = $args['label']; |
|
| 241 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
| 242 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
| 243 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
| 244 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
| 245 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
| 246 | - $wrap_class .= ' d-flex align-content-center'; |
|
| 247 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
| 248 | - } |
|
| 249 | - $output = self::wrap( array( |
|
| 250 | - 'content' => $output, |
|
| 251 | - 'class' => 'custom-control ' . $wrap_class |
|
| 252 | - ) ); |
|
| 253 | - |
|
| 254 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 255 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 256 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
| 257 | - } |
|
| 258 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - // allow password field to toggle view |
|
| 262 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
| 117 | + // enqueue the script |
|
| 118 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 119 | + $aui_settings->enqueue_iconpicker(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
| 123 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + // open/type |
|
| 128 | + $output .= '<input type="' . $type . '" '; |
|
| 129 | + |
|
| 130 | + // name |
|
| 131 | + if ( ! empty( $args['name'] ) ) { |
|
| 132 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // id |
|
| 136 | + if ( ! empty( $args['id'] ) ) { |
|
| 137 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // placeholder |
|
| 141 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 142 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // title |
|
| 146 | + if ( ! empty( $args['title'] ) ) { |
|
| 147 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // value |
|
| 151 | + if ( ! empty( $args['value'] ) ) { |
|
| 152 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // checked, for radio and checkboxes |
|
| 156 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
| 157 | + $output .= ' checked '; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // validation text |
|
| 161 | + if ( ! empty( $args['validation_text'] ) ) { |
|
| 162 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
| 163 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // validation_pattern |
|
| 167 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 168 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // step (for numbers) |
|
| 172 | + if ( ! empty( $args['step'] ) ) { |
|
| 173 | + $output .= ' step="' . $args['step'] . '" '; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // required |
|
| 177 | + if ( ! empty( $args['required'] ) ) { |
|
| 178 | + $output .= ' required '; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // class |
|
| 182 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 183 | + $output .= ' class="form-control ' . $class . '" '; |
|
| 184 | + |
|
| 185 | + // data-attributes |
|
| 186 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 187 | + |
|
| 188 | + // extra attributes |
|
| 189 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 190 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // close |
|
| 194 | + $output .= ' >'; |
|
| 195 | + |
|
| 196 | + // help text |
|
| 197 | + if ( ! empty( $args['help_text'] ) ) { |
|
| 198 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // label |
|
| 202 | + if ( ! empty( $args['label'] ) ) { |
|
| 203 | + $label_base_class = ''; |
|
| 204 | + if ( $type == 'file' ) { |
|
| 205 | + $label_base_class = ' custom-file-label'; |
|
| 206 | + } elseif ( $type == 'checkbox' ) { |
|
| 207 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
| 208 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
| 209 | + $help_text = ''; |
|
| 210 | + //$label_args['class'] .= ' d-inline '; |
|
| 211 | + $args['wrap_class'] .= ' align-items-center '; |
|
| 212 | + }else{ |
|
| 213 | + |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $label_base_class = ' custom-control-label'; |
|
| 217 | + } |
|
| 218 | + $label_args['class'] .= $label_base_class; |
|
| 219 | + $temp_label_args = $label_args; |
|
| 220 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
| 221 | + $label = self::label( $temp_label_args, $type ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + // set help text in the correct position |
|
| 228 | + if ( $label_after ) { |
|
| 229 | + $output .= $label . $help_text; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // some input types need a separate wrap |
|
| 233 | + if ( $type == 'file' ) { |
|
| 234 | + $output = self::wrap( array( |
|
| 235 | + 'content' => $output, |
|
| 236 | + 'class' => 'form-group custom-file' |
|
| 237 | + ) ); |
|
| 238 | + } elseif ( $type == 'checkbox' ) { |
|
| 239 | + |
|
| 240 | + $label_args['title'] = $args['label']; |
|
| 241 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
| 242 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
| 243 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
| 244 | + $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
| 245 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
| 246 | + $wrap_class .= ' d-flex align-content-center'; |
|
| 247 | + $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
| 248 | + } |
|
| 249 | + $output = self::wrap( array( |
|
| 250 | + 'content' => $output, |
|
| 251 | + 'class' => 'custom-control ' . $wrap_class |
|
| 252 | + ) ); |
|
| 253 | + |
|
| 254 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 255 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 256 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
| 257 | + } |
|
| 258 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + // allow password field to toggle view |
|
| 262 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
| 263 | 263 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
| 264 | 264 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
| 265 | 265 | if($el.hasClass(\'fa-eye\')) |
| 266 | 266 | {$eli.attr(\'type\',\'text\');} |
| 267 | 267 | else{$eli.attr(\'type\',\'password\');}" |
| 268 | 268 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
| 269 | - } |
|
| 270 | - |
|
| 271 | - // input group wraps |
|
| 272 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 273 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 274 | - if ( $args['input_group_left'] ) { |
|
| 275 | - $output = self::wrap( array( |
|
| 276 | - 'content' => $output, |
|
| 277 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 278 | - 'input_group_left' => $args['input_group_left'], |
|
| 279 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 280 | - ) ); |
|
| 281 | - } |
|
| 282 | - if ( $args['input_group_right'] ) { |
|
| 283 | - $output = self::wrap( array( |
|
| 284 | - 'content' => $output, |
|
| 285 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 286 | - 'input_group_right' => $args['input_group_right'], |
|
| 287 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 288 | - ) ); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if ( ! $label_after ) { |
|
| 294 | - $output .= $help_text; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 299 | - $output = self::wrap( array( |
|
| 300 | - 'content' => $output, |
|
| 301 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 302 | - ) ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - if ( ! $label_after ) { |
|
| 306 | - $output = $label . $output; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // wrap |
|
| 310 | - if ( ! $args['no_wrap'] ) { |
|
| 311 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
| 312 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 313 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 314 | - $output = self::wrap( array( |
|
| 315 | - 'content' => $output, |
|
| 316 | - 'class' => $wrap_class, |
|
| 317 | - 'element_require' => $args['element_require'], |
|
| 318 | - 'argument_id' => $args['id'], |
|
| 319 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 320 | - ) ); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return $output; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - public static function label( $args = array(), $type = '' ) { |
|
| 328 | - //<label for="exampleInputEmail1">Email address</label> |
|
| 329 | - $defaults = array( |
|
| 330 | - 'title' => 'div', |
|
| 331 | - 'for' => '', |
|
| 332 | - 'class' => '', |
|
| 333 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
| 334 | - 'label_col' => '', |
|
| 335 | - ); |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 339 | - */ |
|
| 340 | - $args = wp_parse_args( $args, $defaults ); |
|
| 341 | - $output = ''; |
|
| 342 | - |
|
| 343 | - if ( $args['title'] ) { |
|
| 344 | - |
|
| 345 | - // maybe hide labels //@todo set a global option for visibility class |
|
| 346 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
| 347 | - $class = $args['class']; |
|
| 348 | - } else { |
|
| 349 | - $class = 'sr-only ' . $args['class']; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - // maybe horizontal |
|
| 353 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 354 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // open |
|
| 358 | - $output .= '<label '; |
|
| 359 | - |
|
| 360 | - // for |
|
| 361 | - if ( ! empty( $args['for'] ) ) { |
|
| 362 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - // class |
|
| 366 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
| 367 | - $output .= ' class="' . $class . '" '; |
|
| 368 | - |
|
| 369 | - // close |
|
| 370 | - $output .= '>'; |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - // title, don't escape fully as can contain html |
|
| 374 | - if ( ! empty( $args['title'] ) ) { |
|
| 375 | - $output .= wp_kses_post( $args['title'] ); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // close wrap |
|
| 379 | - $output .= '</label>'; |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - return $output; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Wrap some content in a HTML wrapper. |
|
| 390 | - * |
|
| 391 | - * @param array $args |
|
| 392 | - * |
|
| 393 | - * @return string |
|
| 394 | - */ |
|
| 395 | - public static function wrap( $args = array() ) { |
|
| 396 | - $defaults = array( |
|
| 397 | - 'type' => 'div', |
|
| 398 | - 'class' => 'form-group', |
|
| 399 | - 'content' => '', |
|
| 400 | - 'input_group_left' => '', |
|
| 401 | - 'input_group_right' => '', |
|
| 402 | - 'input_group_left_inside' => false, |
|
| 403 | - 'input_group_right_inside' => false, |
|
| 404 | - 'element_require' => '', |
|
| 405 | - 'argument_id' => '', |
|
| 406 | - 'wrap_attributes' => array() |
|
| 407 | - ); |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 411 | - */ |
|
| 412 | - $args = wp_parse_args( $args, $defaults ); |
|
| 413 | - $output = ''; |
|
| 414 | - if ( $args['type'] ) { |
|
| 415 | - |
|
| 416 | - // open |
|
| 417 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
| 418 | - |
|
| 419 | - // element require |
|
| 420 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 421 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 422 | - $args['class'] .= " aui-conditional-field"; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - // argument_id |
|
| 426 | - if ( ! empty( $args['argument_id'] ) ) { |
|
| 427 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // class |
|
| 431 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 432 | - $output .= ' class="' . $class . '" '; |
|
| 433 | - |
|
| 434 | - // Attributes |
|
| 435 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
| 436 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // close wrap |
|
| 440 | - $output .= ' >'; |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - // Input group left |
|
| 444 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
| 445 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 446 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
| 447 | - $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - // content |
|
| 451 | - $output .= $args['content']; |
|
| 452 | - |
|
| 453 | - // Input group right |
|
| 454 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
| 455 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 456 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
| 457 | - $output .= '<div class="input-group-append ' . $position_class . '">' . $input_group_right . '</div>'; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - // close wrap |
|
| 462 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - } else { |
|
| 466 | - $output = $args['content']; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - return $output; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Build the component. |
|
| 474 | - * |
|
| 475 | - * @param array $args |
|
| 476 | - * |
|
| 477 | - * @return string The rendered component. |
|
| 478 | - */ |
|
| 479 | - public static function textarea( $args = array() ) { |
|
| 480 | - $defaults = array( |
|
| 481 | - 'name' => '', |
|
| 482 | - 'class' => '', |
|
| 483 | - 'wrap_class' => '', |
|
| 484 | - 'id' => '', |
|
| 485 | - 'placeholder' => '', |
|
| 486 | - 'title' => '', |
|
| 487 | - 'value' => '', |
|
| 488 | - 'required' => false, |
|
| 489 | - 'label' => '', |
|
| 490 | - 'label_after' => false, |
|
| 491 | - 'label_class' => '', |
|
| 492 | - 'label_type' => '', |
|
| 493 | - 'label_col' => '', |
|
| 494 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 495 | - 'input_group_right' => '', |
|
| 496 | - 'input_group_left' => '', |
|
| 497 | - 'input_group_right_inside' => false, |
|
| 498 | - 'help_text' => '', |
|
| 499 | - 'validation_text' => '', |
|
| 500 | - 'validation_pattern' => '', |
|
| 501 | - 'no_wrap' => false, |
|
| 502 | - 'rows' => '', |
|
| 503 | - 'wysiwyg' => false, |
|
| 504 | - 'allow_tags' => false, |
|
| 505 | - // Allow HTML tags |
|
| 506 | - 'element_require' => '', |
|
| 507 | - // [%element_id%] == "1" |
|
| 508 | - 'extra_attributes' => array(), |
|
| 509 | - // an array of extra attributes |
|
| 510 | - 'wrap_attributes' => array(), |
|
| 511 | - ); |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 515 | - */ |
|
| 516 | - $args = wp_parse_args( $args, $defaults ); |
|
| 517 | - $output = ''; |
|
| 518 | - |
|
| 519 | - // hidden label option needs to be empty |
|
| 520 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 521 | - |
|
| 522 | - // floating labels don't work with wysiwyg so set it as top |
|
| 523 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
| 524 | - $args['label_type'] = 'top'; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $label_after = $args['label_after']; |
|
| 528 | - |
|
| 529 | - // floating labels need label after |
|
| 530 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
| 531 | - $label_after = true; |
|
| 532 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - // label |
|
| 536 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 537 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 538 | - $label_args = array( |
|
| 539 | - 'title' => $args['label'], |
|
| 540 | - 'for' => $args['id'], |
|
| 541 | - 'class' => $args['label_class'] . " ", |
|
| 542 | - 'label_type' => $args['label_type'], |
|
| 543 | - 'label_col' => $args['label_col'] |
|
| 544 | - ); |
|
| 545 | - $output .= self::label( $label_args ); |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // maybe horizontal label |
|
| 549 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 550 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 551 | - $output .= '<div class="' . $input_col . '">'; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
| 555 | - ob_start(); |
|
| 556 | - $content = $args['value']; |
|
| 557 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
| 558 | - $settings = array( |
|
| 559 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
| 560 | - 'quicktags' => false, |
|
| 561 | - 'media_buttons' => false, |
|
| 562 | - 'editor_class' => 'form-control', |
|
| 563 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
| 564 | - 'teeny' => true, |
|
| 565 | - ); |
|
| 566 | - |
|
| 567 | - // maybe set settings if array |
|
| 568 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
| 569 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - wp_editor( $content, $editor_id, $settings ); |
|
| 573 | - $output .= ob_get_clean(); |
|
| 574 | - } else { |
|
| 575 | - |
|
| 576 | - // open |
|
| 577 | - $output .= '<textarea '; |
|
| 578 | - |
|
| 579 | - // name |
|
| 580 | - if ( ! empty( $args['name'] ) ) { |
|
| 581 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - // id |
|
| 585 | - if ( ! empty( $args['id'] ) ) { |
|
| 586 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - // placeholder |
|
| 590 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 591 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - // title |
|
| 595 | - if ( ! empty( $args['title'] ) ) { |
|
| 596 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - // validation text |
|
| 600 | - if ( ! empty( $args['validation_text'] ) ) { |
|
| 601 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
| 602 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - // validation_pattern |
|
| 606 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 607 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - // required |
|
| 611 | - if ( ! empty( $args['required'] ) ) { |
|
| 612 | - $output .= ' required '; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - // rows |
|
| 616 | - if ( ! empty( $args['rows'] ) ) { |
|
| 617 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - // class |
|
| 622 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 623 | - $output .= ' class="form-control ' . $class . '" '; |
|
| 624 | - |
|
| 625 | - // extra attributes |
|
| 626 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 627 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - // close tag |
|
| 631 | - $output .= ' >'; |
|
| 632 | - |
|
| 633 | - // value |
|
| 634 | - if ( ! empty( $args['value'] ) ) { |
|
| 635 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
| 636 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
| 637 | - } else { |
|
| 638 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - // closing tag |
|
| 643 | - $output .= '</textarea>'; |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - // input group wraps |
|
| 647 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 648 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 649 | - if ( $args['input_group_left'] ) { |
|
| 650 | - $output = self::wrap( array( |
|
| 651 | - 'content' => $output, |
|
| 652 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 653 | - 'input_group_left' => $args['input_group_left'], |
|
| 654 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 655 | - ) ); |
|
| 656 | - } |
|
| 657 | - if ( $args['input_group_right'] ) { |
|
| 658 | - $output = self::wrap( array( |
|
| 659 | - 'content' => $output, |
|
| 660 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 661 | - 'input_group_right' => $args['input_group_right'], |
|
| 662 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 663 | - ) ); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
| 672 | - $label_args = array( |
|
| 673 | - 'title' => $args['label'], |
|
| 674 | - 'for' => $args['id'], |
|
| 675 | - 'class' => $args['label_class'] . " ", |
|
| 676 | - 'label_type' => $args['label_type'], |
|
| 677 | - 'label_col' => $args['label_col'] |
|
| 678 | - ); |
|
| 679 | - $output .= self::label( $label_args ); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - // help text |
|
| 683 | - if ( ! empty( $args['help_text'] ) ) { |
|
| 684 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - // maybe horizontal label |
|
| 688 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 689 | - $output .= '</div>'; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - // wrap |
|
| 694 | - if ( ! $args['no_wrap'] ) { |
|
| 695 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
| 696 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 697 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 698 | - $output = self::wrap( array( |
|
| 699 | - 'content' => $output, |
|
| 700 | - 'class' => $wrap_class, |
|
| 701 | - 'element_require' => $args['element_require'], |
|
| 702 | - 'argument_id' => $args['id'], |
|
| 703 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 704 | - ) ); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - return $output; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Build the component. |
|
| 713 | - * |
|
| 714 | - * @param array $args |
|
| 715 | - * |
|
| 716 | - * @return string The rendered component. |
|
| 717 | - */ |
|
| 718 | - public static function select( $args = array() ) { |
|
| 719 | - $defaults = array( |
|
| 720 | - 'class' => '', |
|
| 721 | - 'wrap_class' => '', |
|
| 722 | - 'id' => '', |
|
| 723 | - 'title' => '', |
|
| 724 | - 'value' => '', |
|
| 725 | - // can be an array or a string |
|
| 726 | - 'required' => false, |
|
| 727 | - 'label' => '', |
|
| 728 | - 'label_after' => false, |
|
| 729 | - 'label_type' => '', |
|
| 730 | - 'label_col' => '', |
|
| 731 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 732 | - 'label_class' => '', |
|
| 733 | - 'help_text' => '', |
|
| 734 | - 'placeholder' => '', |
|
| 735 | - 'options' => array(), |
|
| 736 | - // array or string |
|
| 737 | - 'icon' => '', |
|
| 738 | - 'multiple' => false, |
|
| 739 | - 'select2' => false, |
|
| 740 | - 'no_wrap' => false, |
|
| 741 | - 'input_group_right' => '', |
|
| 742 | - 'input_group_left' => '', |
|
| 743 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
| 744 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
| 745 | - 'element_require' => '', |
|
| 746 | - // [%element_id%] == "1" |
|
| 747 | - 'extra_attributes' => array(), |
|
| 748 | - // an array of extra attributes |
|
| 749 | - 'wrap_attributes' => array(), |
|
| 750 | - ); |
|
| 751 | - |
|
| 752 | - /** |
|
| 753 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 754 | - */ |
|
| 755 | - $args = wp_parse_args( $args, $defaults ); |
|
| 756 | - $output = ''; |
|
| 757 | - |
|
| 758 | - // for now lets hide floating labels |
|
| 759 | - if ( $args['label_type'] == 'floating' ) { |
|
| 760 | - $args['label_type'] = 'hidden'; |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - // hidden label option needs to be empty |
|
| 764 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 765 | - |
|
| 766 | - |
|
| 767 | - $label_after = $args['label_after']; |
|
| 768 | - |
|
| 769 | - // floating labels need label after |
|
| 770 | - if ( $args['label_type'] == 'floating' ) { |
|
| 771 | - $label_after = true; |
|
| 772 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - // Maybe setup select2 |
|
| 776 | - $is_select2 = false; |
|
| 777 | - if ( ! empty( $args['select2'] ) ) { |
|
| 778 | - $args['class'] .= ' aui-select2'; |
|
| 779 | - $is_select2 = true; |
|
| 780 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
| 781 | - $is_select2 = true; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - // select2 tags |
|
| 785 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
| 786 | - $args['data-tags'] = 'true'; |
|
| 787 | - $args['data-token-separators'] = "[',']"; |
|
| 788 | - $args['multiple'] = true; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - // select2 placeholder |
|
| 792 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
| 793 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
| 794 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - // maybe horizontal label |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // input group wraps |
|
| 272 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 273 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 274 | + if ( $args['input_group_left'] ) { |
|
| 275 | + $output = self::wrap( array( |
|
| 276 | + 'content' => $output, |
|
| 277 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 278 | + 'input_group_left' => $args['input_group_left'], |
|
| 279 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 280 | + ) ); |
|
| 281 | + } |
|
| 282 | + if ( $args['input_group_right'] ) { |
|
| 283 | + $output = self::wrap( array( |
|
| 284 | + 'content' => $output, |
|
| 285 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 286 | + 'input_group_right' => $args['input_group_right'], |
|
| 287 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 288 | + ) ); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if ( ! $label_after ) { |
|
| 294 | + $output .= $help_text; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 299 | + $output = self::wrap( array( |
|
| 300 | + 'content' => $output, |
|
| 301 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 302 | + ) ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + if ( ! $label_after ) { |
|
| 306 | + $output = $label . $output; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // wrap |
|
| 310 | + if ( ! $args['no_wrap'] ) { |
|
| 311 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
| 312 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 313 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 314 | + $output = self::wrap( array( |
|
| 315 | + 'content' => $output, |
|
| 316 | + 'class' => $wrap_class, |
|
| 317 | + 'element_require' => $args['element_require'], |
|
| 318 | + 'argument_id' => $args['id'], |
|
| 319 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 320 | + ) ); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return $output; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + public static function label( $args = array(), $type = '' ) { |
|
| 328 | + //<label for="exampleInputEmail1">Email address</label> |
|
| 329 | + $defaults = array( |
|
| 330 | + 'title' => 'div', |
|
| 331 | + 'for' => '', |
|
| 332 | + 'class' => '', |
|
| 333 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
| 334 | + 'label_col' => '', |
|
| 335 | + ); |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 339 | + */ |
|
| 340 | + $args = wp_parse_args( $args, $defaults ); |
|
| 341 | + $output = ''; |
|
| 342 | + |
|
| 343 | + if ( $args['title'] ) { |
|
| 344 | + |
|
| 345 | + // maybe hide labels //@todo set a global option for visibility class |
|
| 346 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
| 347 | + $class = $args['class']; |
|
| 348 | + } else { |
|
| 349 | + $class = 'sr-only ' . $args['class']; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + // maybe horizontal |
|
| 353 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 354 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // open |
|
| 358 | + $output .= '<label '; |
|
| 359 | + |
|
| 360 | + // for |
|
| 361 | + if ( ! empty( $args['for'] ) ) { |
|
| 362 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + // class |
|
| 366 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
| 367 | + $output .= ' class="' . $class . '" '; |
|
| 368 | + |
|
| 369 | + // close |
|
| 370 | + $output .= '>'; |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + // title, don't escape fully as can contain html |
|
| 374 | + if ( ! empty( $args['title'] ) ) { |
|
| 375 | + $output .= wp_kses_post( $args['title'] ); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // close wrap |
|
| 379 | + $output .= '</label>'; |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + return $output; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Wrap some content in a HTML wrapper. |
|
| 390 | + * |
|
| 391 | + * @param array $args |
|
| 392 | + * |
|
| 393 | + * @return string |
|
| 394 | + */ |
|
| 395 | + public static function wrap( $args = array() ) { |
|
| 396 | + $defaults = array( |
|
| 397 | + 'type' => 'div', |
|
| 398 | + 'class' => 'form-group', |
|
| 399 | + 'content' => '', |
|
| 400 | + 'input_group_left' => '', |
|
| 401 | + 'input_group_right' => '', |
|
| 402 | + 'input_group_left_inside' => false, |
|
| 403 | + 'input_group_right_inside' => false, |
|
| 404 | + 'element_require' => '', |
|
| 405 | + 'argument_id' => '', |
|
| 406 | + 'wrap_attributes' => array() |
|
| 407 | + ); |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 411 | + */ |
|
| 412 | + $args = wp_parse_args( $args, $defaults ); |
|
| 413 | + $output = ''; |
|
| 414 | + if ( $args['type'] ) { |
|
| 415 | + |
|
| 416 | + // open |
|
| 417 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
| 418 | + |
|
| 419 | + // element require |
|
| 420 | + if ( ! empty( $args['element_require'] ) ) { |
|
| 421 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 422 | + $args['class'] .= " aui-conditional-field"; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + // argument_id |
|
| 426 | + if ( ! empty( $args['argument_id'] ) ) { |
|
| 427 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // class |
|
| 431 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 432 | + $output .= ' class="' . $class . '" '; |
|
| 433 | + |
|
| 434 | + // Attributes |
|
| 435 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
| 436 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // close wrap |
|
| 440 | + $output .= ' >'; |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + // Input group left |
|
| 444 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
| 445 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 446 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
| 447 | + $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + // content |
|
| 451 | + $output .= $args['content']; |
|
| 452 | + |
|
| 453 | + // Input group right |
|
| 454 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
| 455 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 456 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
| 457 | + $output .= '<div class="input-group-append ' . $position_class . '">' . $input_group_right . '</div>'; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + // close wrap |
|
| 462 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + } else { |
|
| 466 | + $output = $args['content']; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + return $output; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Build the component. |
|
| 474 | + * |
|
| 475 | + * @param array $args |
|
| 476 | + * |
|
| 477 | + * @return string The rendered component. |
|
| 478 | + */ |
|
| 479 | + public static function textarea( $args = array() ) { |
|
| 480 | + $defaults = array( |
|
| 481 | + 'name' => '', |
|
| 482 | + 'class' => '', |
|
| 483 | + 'wrap_class' => '', |
|
| 484 | + 'id' => '', |
|
| 485 | + 'placeholder' => '', |
|
| 486 | + 'title' => '', |
|
| 487 | + 'value' => '', |
|
| 488 | + 'required' => false, |
|
| 489 | + 'label' => '', |
|
| 490 | + 'label_after' => false, |
|
| 491 | + 'label_class' => '', |
|
| 492 | + 'label_type' => '', |
|
| 493 | + 'label_col' => '', |
|
| 494 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 495 | + 'input_group_right' => '', |
|
| 496 | + 'input_group_left' => '', |
|
| 497 | + 'input_group_right_inside' => false, |
|
| 498 | + 'help_text' => '', |
|
| 499 | + 'validation_text' => '', |
|
| 500 | + 'validation_pattern' => '', |
|
| 501 | + 'no_wrap' => false, |
|
| 502 | + 'rows' => '', |
|
| 503 | + 'wysiwyg' => false, |
|
| 504 | + 'allow_tags' => false, |
|
| 505 | + // Allow HTML tags |
|
| 506 | + 'element_require' => '', |
|
| 507 | + // [%element_id%] == "1" |
|
| 508 | + 'extra_attributes' => array(), |
|
| 509 | + // an array of extra attributes |
|
| 510 | + 'wrap_attributes' => array(), |
|
| 511 | + ); |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 515 | + */ |
|
| 516 | + $args = wp_parse_args( $args, $defaults ); |
|
| 517 | + $output = ''; |
|
| 518 | + |
|
| 519 | + // hidden label option needs to be empty |
|
| 520 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 521 | + |
|
| 522 | + // floating labels don't work with wysiwyg so set it as top |
|
| 523 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
| 524 | + $args['label_type'] = 'top'; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $label_after = $args['label_after']; |
|
| 528 | + |
|
| 529 | + // floating labels need label after |
|
| 530 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
| 531 | + $label_after = true; |
|
| 532 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + // label |
|
| 536 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 537 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 538 | + $label_args = array( |
|
| 539 | + 'title' => $args['label'], |
|
| 540 | + 'for' => $args['id'], |
|
| 541 | + 'class' => $args['label_class'] . " ", |
|
| 542 | + 'label_type' => $args['label_type'], |
|
| 543 | + 'label_col' => $args['label_col'] |
|
| 544 | + ); |
|
| 545 | + $output .= self::label( $label_args ); |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // maybe horizontal label |
|
| 549 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 550 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 551 | + $output .= '<div class="' . $input_col . '">'; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
| 555 | + ob_start(); |
|
| 556 | + $content = $args['value']; |
|
| 557 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
| 558 | + $settings = array( |
|
| 559 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
| 560 | + 'quicktags' => false, |
|
| 561 | + 'media_buttons' => false, |
|
| 562 | + 'editor_class' => 'form-control', |
|
| 563 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
| 564 | + 'teeny' => true, |
|
| 565 | + ); |
|
| 566 | + |
|
| 567 | + // maybe set settings if array |
|
| 568 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
| 569 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + wp_editor( $content, $editor_id, $settings ); |
|
| 573 | + $output .= ob_get_clean(); |
|
| 574 | + } else { |
|
| 575 | + |
|
| 576 | + // open |
|
| 577 | + $output .= '<textarea '; |
|
| 578 | + |
|
| 579 | + // name |
|
| 580 | + if ( ! empty( $args['name'] ) ) { |
|
| 581 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + // id |
|
| 585 | + if ( ! empty( $args['id'] ) ) { |
|
| 586 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + // placeholder |
|
| 590 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 591 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + // title |
|
| 595 | + if ( ! empty( $args['title'] ) ) { |
|
| 596 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + // validation text |
|
| 600 | + if ( ! empty( $args['validation_text'] ) ) { |
|
| 601 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
| 602 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + // validation_pattern |
|
| 606 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 607 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + // required |
|
| 611 | + if ( ! empty( $args['required'] ) ) { |
|
| 612 | + $output .= ' required '; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + // rows |
|
| 616 | + if ( ! empty( $args['rows'] ) ) { |
|
| 617 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + // class |
|
| 622 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 623 | + $output .= ' class="form-control ' . $class . '" '; |
|
| 624 | + |
|
| 625 | + // extra attributes |
|
| 626 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 627 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // close tag |
|
| 631 | + $output .= ' >'; |
|
| 632 | + |
|
| 633 | + // value |
|
| 634 | + if ( ! empty( $args['value'] ) ) { |
|
| 635 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
| 636 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
| 637 | + } else { |
|
| 638 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + // closing tag |
|
| 643 | + $output .= '</textarea>'; |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + // input group wraps |
|
| 647 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 648 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 649 | + if ( $args['input_group_left'] ) { |
|
| 650 | + $output = self::wrap( array( |
|
| 651 | + 'content' => $output, |
|
| 652 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 653 | + 'input_group_left' => $args['input_group_left'], |
|
| 654 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 655 | + ) ); |
|
| 656 | + } |
|
| 657 | + if ( $args['input_group_right'] ) { |
|
| 658 | + $output = self::wrap( array( |
|
| 659 | + 'content' => $output, |
|
| 660 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 661 | + 'input_group_right' => $args['input_group_right'], |
|
| 662 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 663 | + ) ); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
| 672 | + $label_args = array( |
|
| 673 | + 'title' => $args['label'], |
|
| 674 | + 'for' => $args['id'], |
|
| 675 | + 'class' => $args['label_class'] . " ", |
|
| 676 | + 'label_type' => $args['label_type'], |
|
| 677 | + 'label_col' => $args['label_col'] |
|
| 678 | + ); |
|
| 679 | + $output .= self::label( $label_args ); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + // help text |
|
| 683 | + if ( ! empty( $args['help_text'] ) ) { |
|
| 684 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + // maybe horizontal label |
|
| 688 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 689 | + $output .= '</div>'; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + // wrap |
|
| 694 | + if ( ! $args['no_wrap'] ) { |
|
| 695 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
| 696 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 697 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 698 | + $output = self::wrap( array( |
|
| 699 | + 'content' => $output, |
|
| 700 | + 'class' => $wrap_class, |
|
| 701 | + 'element_require' => $args['element_require'], |
|
| 702 | + 'argument_id' => $args['id'], |
|
| 703 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 704 | + ) ); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + return $output; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Build the component. |
|
| 713 | + * |
|
| 714 | + * @param array $args |
|
| 715 | + * |
|
| 716 | + * @return string The rendered component. |
|
| 717 | + */ |
|
| 718 | + public static function select( $args = array() ) { |
|
| 719 | + $defaults = array( |
|
| 720 | + 'class' => '', |
|
| 721 | + 'wrap_class' => '', |
|
| 722 | + 'id' => '', |
|
| 723 | + 'title' => '', |
|
| 724 | + 'value' => '', |
|
| 725 | + // can be an array or a string |
|
| 726 | + 'required' => false, |
|
| 727 | + 'label' => '', |
|
| 728 | + 'label_after' => false, |
|
| 729 | + 'label_type' => '', |
|
| 730 | + 'label_col' => '', |
|
| 731 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 732 | + 'label_class' => '', |
|
| 733 | + 'help_text' => '', |
|
| 734 | + 'placeholder' => '', |
|
| 735 | + 'options' => array(), |
|
| 736 | + // array or string |
|
| 737 | + 'icon' => '', |
|
| 738 | + 'multiple' => false, |
|
| 739 | + 'select2' => false, |
|
| 740 | + 'no_wrap' => false, |
|
| 741 | + 'input_group_right' => '', |
|
| 742 | + 'input_group_left' => '', |
|
| 743 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
| 744 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
| 745 | + 'element_require' => '', |
|
| 746 | + // [%element_id%] == "1" |
|
| 747 | + 'extra_attributes' => array(), |
|
| 748 | + // an array of extra attributes |
|
| 749 | + 'wrap_attributes' => array(), |
|
| 750 | + ); |
|
| 751 | + |
|
| 752 | + /** |
|
| 753 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 754 | + */ |
|
| 755 | + $args = wp_parse_args( $args, $defaults ); |
|
| 756 | + $output = ''; |
|
| 757 | + |
|
| 758 | + // for now lets hide floating labels |
|
| 759 | + if ( $args['label_type'] == 'floating' ) { |
|
| 760 | + $args['label_type'] = 'hidden'; |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + // hidden label option needs to be empty |
|
| 764 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 765 | + |
|
| 766 | + |
|
| 767 | + $label_after = $args['label_after']; |
|
| 768 | + |
|
| 769 | + // floating labels need label after |
|
| 770 | + if ( $args['label_type'] == 'floating' ) { |
|
| 771 | + $label_after = true; |
|
| 772 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + // Maybe setup select2 |
|
| 776 | + $is_select2 = false; |
|
| 777 | + if ( ! empty( $args['select2'] ) ) { |
|
| 778 | + $args['class'] .= ' aui-select2'; |
|
| 779 | + $is_select2 = true; |
|
| 780 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
| 781 | + $is_select2 = true; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + // select2 tags |
|
| 785 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
| 786 | + $args['data-tags'] = 'true'; |
|
| 787 | + $args['data-token-separators'] = "[',']"; |
|
| 788 | + $args['multiple'] = true; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + // select2 placeholder |
|
| 792 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
| 793 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
| 794 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + // maybe horizontal label |
|
| 800 | 800 | // if ( $args['label_type'] == 'horizontal' ) { |
| 801 | 801 | // $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
| 802 | 802 | // $output .= '<div class="' . $input_col . '">'; |
| 803 | 803 | // } |
| 804 | 804 | |
| 805 | - // Set hidden input to save empty value for multiselect. |
|
| 806 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
| 807 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>'; |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - // open/type |
|
| 811 | - $output .= '<select '; |
|
| 812 | - |
|
| 813 | - // style |
|
| 814 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
| 815 | - $output .= " style='width:100%;' "; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - // element require |
|
| 819 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 820 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 821 | - $args['class'] .= " aui-conditional-field"; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - // class |
|
| 825 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 826 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
| 827 | - |
|
| 828 | - // name |
|
| 829 | - if ( ! empty( $args['name'] ) ) { |
|
| 830 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - // id |
|
| 834 | - if ( ! empty( $args['id'] ) ) { |
|
| 835 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - // title |
|
| 839 | - if ( ! empty( $args['title'] ) ) { |
|
| 840 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - // data-attributes |
|
| 844 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 845 | - |
|
| 846 | - // aria-attributes |
|
| 847 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 848 | - |
|
| 849 | - // extra attributes |
|
| 850 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 851 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - // required |
|
| 855 | - if ( ! empty( $args['required'] ) ) { |
|
| 856 | - $output .= ' required '; |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - // multiple |
|
| 860 | - if ( ! empty( $args['multiple'] ) ) { |
|
| 861 | - $output .= ' multiple '; |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - // close opening tag |
|
| 865 | - $output .= ' >'; |
|
| 866 | - |
|
| 867 | - // placeholder |
|
| 868 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
| 869 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
| 870 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
| 871 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - // Options |
|
| 875 | - if ( ! empty( $args['options'] ) ) { |
|
| 876 | - |
|
| 877 | - if ( ! is_array( $args['options'] ) ) { |
|
| 878 | - $output .= $args['options']; // not the preferred way but an option |
|
| 879 | - } else { |
|
| 880 | - foreach ( $args['options'] as $val => $name ) { |
|
| 881 | - $selected = ''; |
|
| 882 | - if ( is_array( $name ) ) { |
|
| 883 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
| 884 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 885 | - |
|
| 886 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
| 887 | - } else { |
|
| 888 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 889 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
| 890 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
| 891 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
| 892 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
| 893 | - } elseif ( ! empty( $args['value'] ) ) { |
|
| 894 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
| 895 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
| 896 | - $selected = selected( $option_value, $args['value'], false ); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
| 900 | - } |
|
| 901 | - } else { |
|
| 902 | - if ( ! empty( $args['value'] ) ) { |
|
| 903 | - if ( is_array( $args['value'] ) ) { |
|
| 904 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
| 905 | - } elseif ( ! empty( $args['value'] ) ) { |
|
| 906 | - $selected = selected( $args['value'], $val, false ); |
|
| 907 | - } |
|
| 908 | - } elseif ( $args['value'] === $val ) { |
|
| 909 | - $selected = selected( $args['value'], $val, false ); |
|
| 910 | - } |
|
| 911 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
| 912 | - } |
|
| 913 | - } |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - } |
|
| 917 | - |
|
| 918 | - // closing tag |
|
| 919 | - $output .= '</select>'; |
|
| 920 | - |
|
| 921 | - $label = ''; |
|
| 922 | - $help_text = ''; |
|
| 923 | - // label |
|
| 924 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 925 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 926 | - $label_args = array( |
|
| 927 | - 'title' => $args['label'], |
|
| 928 | - 'for' => $args['id'], |
|
| 929 | - 'class' => $args['label_class'] . " ", |
|
| 930 | - 'label_type' => $args['label_type'], |
|
| 931 | - 'label_col' => $args['label_col'] |
|
| 932 | - ); |
|
| 933 | - $label = self::label( $label_args ); |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - // help text |
|
| 937 | - if ( ! empty( $args['help_text'] ) ) { |
|
| 938 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - // input group wraps |
|
| 942 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 943 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 944 | - if ( $args['input_group_left'] ) { |
|
| 945 | - $output = self::wrap( array( |
|
| 946 | - 'content' => $output, |
|
| 947 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 948 | - 'input_group_left' => $args['input_group_left'], |
|
| 949 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 950 | - ) ); |
|
| 951 | - } |
|
| 952 | - if ( $args['input_group_right'] ) { |
|
| 953 | - $output = self::wrap( array( |
|
| 954 | - 'content' => $output, |
|
| 955 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 956 | - 'input_group_right' => $args['input_group_right'], |
|
| 957 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 958 | - ) ); |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - if ( ! $label_after ) { |
|
| 964 | - $output .= $help_text; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - |
|
| 968 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 969 | - $output = self::wrap( array( |
|
| 970 | - 'content' => $output, |
|
| 971 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 972 | - ) ); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - if ( ! $label_after ) { |
|
| 976 | - $output = $label . $output; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - // maybe horizontal label |
|
| 805 | + // Set hidden input to save empty value for multiselect. |
|
| 806 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
| 807 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>'; |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + // open/type |
|
| 811 | + $output .= '<select '; |
|
| 812 | + |
|
| 813 | + // style |
|
| 814 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
| 815 | + $output .= " style='width:100%;' "; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + // element require |
|
| 819 | + if ( ! empty( $args['element_require'] ) ) { |
|
| 820 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 821 | + $args['class'] .= " aui-conditional-field"; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + // class |
|
| 825 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 826 | + $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
| 827 | + |
|
| 828 | + // name |
|
| 829 | + if ( ! empty( $args['name'] ) ) { |
|
| 830 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + // id |
|
| 834 | + if ( ! empty( $args['id'] ) ) { |
|
| 835 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + // title |
|
| 839 | + if ( ! empty( $args['title'] ) ) { |
|
| 840 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + // data-attributes |
|
| 844 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 845 | + |
|
| 846 | + // aria-attributes |
|
| 847 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 848 | + |
|
| 849 | + // extra attributes |
|
| 850 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 851 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + // required |
|
| 855 | + if ( ! empty( $args['required'] ) ) { |
|
| 856 | + $output .= ' required '; |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + // multiple |
|
| 860 | + if ( ! empty( $args['multiple'] ) ) { |
|
| 861 | + $output .= ' multiple '; |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + // close opening tag |
|
| 865 | + $output .= ' >'; |
|
| 866 | + |
|
| 867 | + // placeholder |
|
| 868 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
| 869 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
| 870 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
| 871 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + // Options |
|
| 875 | + if ( ! empty( $args['options'] ) ) { |
|
| 876 | + |
|
| 877 | + if ( ! is_array( $args['options'] ) ) { |
|
| 878 | + $output .= $args['options']; // not the preferred way but an option |
|
| 879 | + } else { |
|
| 880 | + foreach ( $args['options'] as $val => $name ) { |
|
| 881 | + $selected = ''; |
|
| 882 | + if ( is_array( $name ) ) { |
|
| 883 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
| 884 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 885 | + |
|
| 886 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
| 887 | + } else { |
|
| 888 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 889 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
| 890 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
| 891 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
| 892 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
| 893 | + } elseif ( ! empty( $args['value'] ) ) { |
|
| 894 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
| 895 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
| 896 | + $selected = selected( $option_value, $args['value'], false ); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
| 900 | + } |
|
| 901 | + } else { |
|
| 902 | + if ( ! empty( $args['value'] ) ) { |
|
| 903 | + if ( is_array( $args['value'] ) ) { |
|
| 904 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
| 905 | + } elseif ( ! empty( $args['value'] ) ) { |
|
| 906 | + $selected = selected( $args['value'], $val, false ); |
|
| 907 | + } |
|
| 908 | + } elseif ( $args['value'] === $val ) { |
|
| 909 | + $selected = selected( $args['value'], $val, false ); |
|
| 910 | + } |
|
| 911 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
| 912 | + } |
|
| 913 | + } |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + } |
|
| 917 | + |
|
| 918 | + // closing tag |
|
| 919 | + $output .= '</select>'; |
|
| 920 | + |
|
| 921 | + $label = ''; |
|
| 922 | + $help_text = ''; |
|
| 923 | + // label |
|
| 924 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 925 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 926 | + $label_args = array( |
|
| 927 | + 'title' => $args['label'], |
|
| 928 | + 'for' => $args['id'], |
|
| 929 | + 'class' => $args['label_class'] . " ", |
|
| 930 | + 'label_type' => $args['label_type'], |
|
| 931 | + 'label_col' => $args['label_col'] |
|
| 932 | + ); |
|
| 933 | + $label = self::label( $label_args ); |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + // help text |
|
| 937 | + if ( ! empty( $args['help_text'] ) ) { |
|
| 938 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + // input group wraps |
|
| 942 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 943 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 944 | + if ( $args['input_group_left'] ) { |
|
| 945 | + $output = self::wrap( array( |
|
| 946 | + 'content' => $output, |
|
| 947 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 948 | + 'input_group_left' => $args['input_group_left'], |
|
| 949 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 950 | + ) ); |
|
| 951 | + } |
|
| 952 | + if ( $args['input_group_right'] ) { |
|
| 953 | + $output = self::wrap( array( |
|
| 954 | + 'content' => $output, |
|
| 955 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 956 | + 'input_group_right' => $args['input_group_right'], |
|
| 957 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 958 | + ) ); |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + if ( ! $label_after ) { |
|
| 964 | + $output .= $help_text; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + |
|
| 968 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 969 | + $output = self::wrap( array( |
|
| 970 | + 'content' => $output, |
|
| 971 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 972 | + ) ); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + if ( ! $label_after ) { |
|
| 976 | + $output = $label . $output; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + // maybe horizontal label |
|
| 980 | 980 | // if ( $args['label_type'] == 'horizontal' ) { |
| 981 | 981 | // $output .= '</div>'; |
| 982 | 982 | // } |
| 983 | 983 | |
| 984 | 984 | |
| 985 | - // wrap |
|
| 986 | - if ( ! $args['no_wrap'] ) { |
|
| 987 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
| 988 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 989 | - $output = self::wrap( array( |
|
| 990 | - 'content' => $output, |
|
| 991 | - 'class' => $wrap_class, |
|
| 992 | - 'element_require' => $args['element_require'], |
|
| 993 | - 'argument_id' => $args['id'], |
|
| 994 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 995 | - ) ); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - |
|
| 999 | - return $output; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - /** |
|
| 1003 | - * Build the component. |
|
| 1004 | - * |
|
| 1005 | - * @param array $args |
|
| 1006 | - * |
|
| 1007 | - * @return string The rendered component. |
|
| 1008 | - */ |
|
| 1009 | - public static function radio( $args = array() ) { |
|
| 1010 | - $defaults = array( |
|
| 1011 | - 'class' => '', |
|
| 1012 | - 'wrap_class' => '', |
|
| 1013 | - 'id' => '', |
|
| 1014 | - 'title' => '', |
|
| 1015 | - 'horizontal' => false, |
|
| 1016 | - // sets the lable horizontal |
|
| 1017 | - 'value' => '', |
|
| 1018 | - 'label' => '', |
|
| 1019 | - 'label_class' => '', |
|
| 1020 | - 'label_type' => '', |
|
| 1021 | - 'label_col' => '', |
|
| 1022 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 1023 | - 'help_text' => '', |
|
| 1024 | - 'inline' => true, |
|
| 1025 | - 'required' => false, |
|
| 1026 | - 'options' => array(), |
|
| 1027 | - 'icon' => '', |
|
| 1028 | - 'no_wrap' => false, |
|
| 1029 | - 'element_require' => '', |
|
| 1030 | - // [%element_id%] == "1" |
|
| 1031 | - 'extra_attributes' => array(), |
|
| 1032 | - // an array of extra attributes |
|
| 1033 | - 'wrap_attributes' => array() |
|
| 1034 | - ); |
|
| 1035 | - |
|
| 1036 | - /** |
|
| 1037 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 1038 | - */ |
|
| 1039 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1040 | - |
|
| 1041 | - // for now lets use horizontal for floating |
|
| 1042 | - if ( $args['label_type'] == 'floating' ) { |
|
| 1043 | - $args['label_type'] = 'horizontal'; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - $label_args = array( |
|
| 1047 | - 'title' => $args['label'], |
|
| 1048 | - 'class' => $args['label_class'] . " pt-0 ", |
|
| 1049 | - 'label_type' => $args['label_type'], |
|
| 1050 | - 'label_col' => $args['label_col'] |
|
| 1051 | - ); |
|
| 1052 | - |
|
| 1053 | - $output = ''; |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - // label before |
|
| 1057 | - if ( ! empty( $args['label'] ) ) { |
|
| 1058 | - $output .= self::label( $label_args, 'radio' ); |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - // maybe horizontal label |
|
| 1062 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 1063 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 1064 | - $output .= '<div class="' . $input_col . '">'; |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - if ( ! empty( $args['options'] ) ) { |
|
| 1068 | - $count = 0; |
|
| 1069 | - foreach ( $args['options'] as $value => $label ) { |
|
| 1070 | - $option_args = $args; |
|
| 1071 | - $option_args['value'] = $value; |
|
| 1072 | - $option_args['label'] = $label; |
|
| 1073 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
| 1074 | - $output .= self::radio_option( $option_args, $count ); |
|
| 1075 | - $count ++; |
|
| 1076 | - } |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - // help text |
|
| 1080 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
| 1081 | - $output .= $help_text; |
|
| 1082 | - |
|
| 1083 | - // maybe horizontal label |
|
| 1084 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 1085 | - $output .= '</div>'; |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - // wrap |
|
| 1089 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
| 1090 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1091 | - $output = self::wrap( array( |
|
| 1092 | - 'content' => $output, |
|
| 1093 | - 'class' => $wrap_class, |
|
| 1094 | - 'element_require' => $args['element_require'], |
|
| 1095 | - 'argument_id' => $args['id'], |
|
| 1096 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1097 | - ) ); |
|
| 1098 | - |
|
| 1099 | - |
|
| 1100 | - return $output; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - /** |
|
| 1104 | - * Build the component. |
|
| 1105 | - * |
|
| 1106 | - * @param array $args |
|
| 1107 | - * |
|
| 1108 | - * @return string The rendered component. |
|
| 1109 | - */ |
|
| 1110 | - public static function radio_option( $args = array(), $count = '' ) { |
|
| 1111 | - $defaults = array( |
|
| 1112 | - 'class' => '', |
|
| 1113 | - 'id' => '', |
|
| 1114 | - 'title' => '', |
|
| 1115 | - 'value' => '', |
|
| 1116 | - 'required' => false, |
|
| 1117 | - 'inline' => true, |
|
| 1118 | - 'label' => '', |
|
| 1119 | - 'options' => array(), |
|
| 1120 | - 'icon' => '', |
|
| 1121 | - 'no_wrap' => false, |
|
| 1122 | - 'extra_attributes' => array() // an array of extra attributes |
|
| 1123 | - ); |
|
| 1124 | - |
|
| 1125 | - /** |
|
| 1126 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 1127 | - */ |
|
| 1128 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1129 | - |
|
| 1130 | - $output = ''; |
|
| 1131 | - |
|
| 1132 | - // open/type |
|
| 1133 | - $output .= '<input type="radio"'; |
|
| 1134 | - |
|
| 1135 | - // class |
|
| 1136 | - $output .= ' class="form-check-input" '; |
|
| 1137 | - |
|
| 1138 | - // name |
|
| 1139 | - if ( ! empty( $args['name'] ) ) { |
|
| 1140 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - // id |
|
| 1144 | - if ( ! empty( $args['id'] ) ) { |
|
| 1145 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - // title |
|
| 1149 | - if ( ! empty( $args['title'] ) ) { |
|
| 1150 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - // value |
|
| 1154 | - if ( isset( $args['value'] ) ) { |
|
| 1155 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - // checked, for radio and checkboxes |
|
| 1159 | - if ( $args['checked'] ) { |
|
| 1160 | - $output .= ' checked '; |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - // data-attributes |
|
| 1164 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 1165 | - |
|
| 1166 | - // aria-attributes |
|
| 1167 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 1168 | - |
|
| 1169 | - // extra attributes |
|
| 1170 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 1171 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - // required |
|
| 1175 | - if ( ! empty( $args['required'] ) ) { |
|
| 1176 | - $output .= ' required '; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - // close opening tag |
|
| 1180 | - $output .= ' >'; |
|
| 1181 | - |
|
| 1182 | - // label |
|
| 1183 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 1184 | - } elseif ( ! empty( $args['label'] ) ) { |
|
| 1185 | - $output .= self::label( array( |
|
| 1186 | - 'title' => $args['label'], |
|
| 1187 | - 'for' => $args['id'] . $count, |
|
| 1188 | - 'class' => 'form-check-label' |
|
| 1189 | - ), 'radio' ); |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - // wrap |
|
| 1193 | - if ( ! $args['no_wrap'] ) { |
|
| 1194 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
| 1195 | - |
|
| 1196 | - // Unique wrap class |
|
| 1197 | - $uniq_class = 'fwrap'; |
|
| 1198 | - if ( ! empty( $args['name'] ) ) { |
|
| 1199 | - $uniq_class .= '-' . $args['name']; |
|
| 1200 | - } else if ( ! empty( $args['id'] ) ) { |
|
| 1201 | - $uniq_class .= '-' . $args['id']; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
| 1205 | - $uniq_class .= '-' . $args['value']; |
|
| 1206 | - } else { |
|
| 1207 | - $uniq_class .= '-' . $count; |
|
| 1208 | - } |
|
| 1209 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
| 1210 | - |
|
| 1211 | - $output = self::wrap( array( |
|
| 1212 | - 'content' => $output, |
|
| 1213 | - 'class' => $wrap_class |
|
| 1214 | - ) ); |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - return $output; |
|
| 1218 | - } |
|
| 985 | + // wrap |
|
| 986 | + if ( ! $args['no_wrap'] ) { |
|
| 987 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
| 988 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 989 | + $output = self::wrap( array( |
|
| 990 | + 'content' => $output, |
|
| 991 | + 'class' => $wrap_class, |
|
| 992 | + 'element_require' => $args['element_require'], |
|
| 993 | + 'argument_id' => $args['id'], |
|
| 994 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 995 | + ) ); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + |
|
| 999 | + return $output; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + /** |
|
| 1003 | + * Build the component. |
|
| 1004 | + * |
|
| 1005 | + * @param array $args |
|
| 1006 | + * |
|
| 1007 | + * @return string The rendered component. |
|
| 1008 | + */ |
|
| 1009 | + public static function radio( $args = array() ) { |
|
| 1010 | + $defaults = array( |
|
| 1011 | + 'class' => '', |
|
| 1012 | + 'wrap_class' => '', |
|
| 1013 | + 'id' => '', |
|
| 1014 | + 'title' => '', |
|
| 1015 | + 'horizontal' => false, |
|
| 1016 | + // sets the lable horizontal |
|
| 1017 | + 'value' => '', |
|
| 1018 | + 'label' => '', |
|
| 1019 | + 'label_class' => '', |
|
| 1020 | + 'label_type' => '', |
|
| 1021 | + 'label_col' => '', |
|
| 1022 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 1023 | + 'help_text' => '', |
|
| 1024 | + 'inline' => true, |
|
| 1025 | + 'required' => false, |
|
| 1026 | + 'options' => array(), |
|
| 1027 | + 'icon' => '', |
|
| 1028 | + 'no_wrap' => false, |
|
| 1029 | + 'element_require' => '', |
|
| 1030 | + // [%element_id%] == "1" |
|
| 1031 | + 'extra_attributes' => array(), |
|
| 1032 | + // an array of extra attributes |
|
| 1033 | + 'wrap_attributes' => array() |
|
| 1034 | + ); |
|
| 1035 | + |
|
| 1036 | + /** |
|
| 1037 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 1038 | + */ |
|
| 1039 | + $args = wp_parse_args( $args, $defaults ); |
|
| 1040 | + |
|
| 1041 | + // for now lets use horizontal for floating |
|
| 1042 | + if ( $args['label_type'] == 'floating' ) { |
|
| 1043 | + $args['label_type'] = 'horizontal'; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + $label_args = array( |
|
| 1047 | + 'title' => $args['label'], |
|
| 1048 | + 'class' => $args['label_class'] . " pt-0 ", |
|
| 1049 | + 'label_type' => $args['label_type'], |
|
| 1050 | + 'label_col' => $args['label_col'] |
|
| 1051 | + ); |
|
| 1052 | + |
|
| 1053 | + $output = ''; |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + // label before |
|
| 1057 | + if ( ! empty( $args['label'] ) ) { |
|
| 1058 | + $output .= self::label( $label_args, 'radio' ); |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + // maybe horizontal label |
|
| 1062 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 1063 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 1064 | + $output .= '<div class="' . $input_col . '">'; |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + if ( ! empty( $args['options'] ) ) { |
|
| 1068 | + $count = 0; |
|
| 1069 | + foreach ( $args['options'] as $value => $label ) { |
|
| 1070 | + $option_args = $args; |
|
| 1071 | + $option_args['value'] = $value; |
|
| 1072 | + $option_args['label'] = $label; |
|
| 1073 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
| 1074 | + $output .= self::radio_option( $option_args, $count ); |
|
| 1075 | + $count ++; |
|
| 1076 | + } |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + // help text |
|
| 1080 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
| 1081 | + $output .= $help_text; |
|
| 1082 | + |
|
| 1083 | + // maybe horizontal label |
|
| 1084 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 1085 | + $output .= '</div>'; |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + // wrap |
|
| 1089 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
| 1090 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1091 | + $output = self::wrap( array( |
|
| 1092 | + 'content' => $output, |
|
| 1093 | + 'class' => $wrap_class, |
|
| 1094 | + 'element_require' => $args['element_require'], |
|
| 1095 | + 'argument_id' => $args['id'], |
|
| 1096 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1097 | + ) ); |
|
| 1098 | + |
|
| 1099 | + |
|
| 1100 | + return $output; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + /** |
|
| 1104 | + * Build the component. |
|
| 1105 | + * |
|
| 1106 | + * @param array $args |
|
| 1107 | + * |
|
| 1108 | + * @return string The rendered component. |
|
| 1109 | + */ |
|
| 1110 | + public static function radio_option( $args = array(), $count = '' ) { |
|
| 1111 | + $defaults = array( |
|
| 1112 | + 'class' => '', |
|
| 1113 | + 'id' => '', |
|
| 1114 | + 'title' => '', |
|
| 1115 | + 'value' => '', |
|
| 1116 | + 'required' => false, |
|
| 1117 | + 'inline' => true, |
|
| 1118 | + 'label' => '', |
|
| 1119 | + 'options' => array(), |
|
| 1120 | + 'icon' => '', |
|
| 1121 | + 'no_wrap' => false, |
|
| 1122 | + 'extra_attributes' => array() // an array of extra attributes |
|
| 1123 | + ); |
|
| 1124 | + |
|
| 1125 | + /** |
|
| 1126 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 1127 | + */ |
|
| 1128 | + $args = wp_parse_args( $args, $defaults ); |
|
| 1129 | + |
|
| 1130 | + $output = ''; |
|
| 1131 | + |
|
| 1132 | + // open/type |
|
| 1133 | + $output .= '<input type="radio"'; |
|
| 1134 | + |
|
| 1135 | + // class |
|
| 1136 | + $output .= ' class="form-check-input" '; |
|
| 1137 | + |
|
| 1138 | + // name |
|
| 1139 | + if ( ! empty( $args['name'] ) ) { |
|
| 1140 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + // id |
|
| 1144 | + if ( ! empty( $args['id'] ) ) { |
|
| 1145 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + // title |
|
| 1149 | + if ( ! empty( $args['title'] ) ) { |
|
| 1150 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 1151 | + } |
|
| 1152 | + |
|
| 1153 | + // value |
|
| 1154 | + if ( isset( $args['value'] ) ) { |
|
| 1155 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + // checked, for radio and checkboxes |
|
| 1159 | + if ( $args['checked'] ) { |
|
| 1160 | + $output .= ' checked '; |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + // data-attributes |
|
| 1164 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 1165 | + |
|
| 1166 | + // aria-attributes |
|
| 1167 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 1168 | + |
|
| 1169 | + // extra attributes |
|
| 1170 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 1171 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + // required |
|
| 1175 | + if ( ! empty( $args['required'] ) ) { |
|
| 1176 | + $output .= ' required '; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + // close opening tag |
|
| 1180 | + $output .= ' >'; |
|
| 1181 | + |
|
| 1182 | + // label |
|
| 1183 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 1184 | + } elseif ( ! empty( $args['label'] ) ) { |
|
| 1185 | + $output .= self::label( array( |
|
| 1186 | + 'title' => $args['label'], |
|
| 1187 | + 'for' => $args['id'] . $count, |
|
| 1188 | + 'class' => 'form-check-label' |
|
| 1189 | + ), 'radio' ); |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + // wrap |
|
| 1193 | + if ( ! $args['no_wrap'] ) { |
|
| 1194 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
| 1195 | + |
|
| 1196 | + // Unique wrap class |
|
| 1197 | + $uniq_class = 'fwrap'; |
|
| 1198 | + if ( ! empty( $args['name'] ) ) { |
|
| 1199 | + $uniq_class .= '-' . $args['name']; |
|
| 1200 | + } else if ( ! empty( $args['id'] ) ) { |
|
| 1201 | + $uniq_class .= '-' . $args['id']; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
| 1205 | + $uniq_class .= '-' . $args['value']; |
|
| 1206 | + } else { |
|
| 1207 | + $uniq_class .= '-' . $count; |
|
| 1208 | + } |
|
| 1209 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
| 1210 | + |
|
| 1211 | + $output = self::wrap( array( |
|
| 1212 | + 'content' => $output, |
|
| 1213 | + 'class' => $wrap_class |
|
| 1214 | + ) ); |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + return $output; |
|
| 1218 | + } |
|
| 1219 | 1219 | |
| 1220 | 1220 | } |
| 1221 | 1221 | \ No newline at end of file |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * Bail if we are not in WP. |
| 14 | 14 | */ |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; |
|
| 16 | + exit; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -21,273 +21,273 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | if ( ! class_exists( 'AyeCode_UI_Settings' ) ) { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * A Class to be able to change settings for Font Awesome. |
|
| 26 | - * |
|
| 27 | - * Class AyeCode_UI_Settings |
|
| 28 | - * @ver 1.0.0 |
|
| 29 | - * @todo decide how to implement textdomain |
|
| 30 | - */ |
|
| 31 | - class AyeCode_UI_Settings { |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Class version version. |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - public $version = '0.1.67'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Class textdomain. |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - public $textdomain = 'aui'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Latest version of Bootstrap at time of publish published. |
|
| 49 | - * |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - public $latest = "4.5.3"; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Current version of select2 being used. |
|
| 56 | - * |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - public $select2_version = "4.0.11"; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * The title. |
|
| 63 | - * |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - public $name = 'AyeCode UI'; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The relative url to the assets. |
|
| 70 | - * |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 73 | - public $url = ''; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Holds the settings values. |
|
| 77 | - * |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - private $settings; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * AyeCode_UI_Settings instance. |
|
| 84 | - * |
|
| 85 | - * @access private |
|
| 86 | - * @since 1.0.0 |
|
| 87 | - * @var AyeCode_UI_Settings There can be only one! |
|
| 88 | - */ |
|
| 89 | - private static $instance = null; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Main AyeCode_UI_Settings Instance. |
|
| 93 | - * |
|
| 94 | - * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
| 95 | - * |
|
| 96 | - * @since 1.0.0 |
|
| 97 | - * @static |
|
| 98 | - * @return AyeCode_UI_Settings - Main instance. |
|
| 99 | - */ |
|
| 100 | - public static function instance() { |
|
| 101 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
| 102 | - |
|
| 103 | - self::$instance = new AyeCode_UI_Settings; |
|
| 104 | - |
|
| 105 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 106 | - |
|
| 107 | - if ( is_admin() ) { |
|
| 108 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 109 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 110 | - |
|
| 111 | - // Maybe show example page |
|
| 112 | - add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
| 113 | - } |
|
| 24 | + /** |
|
| 25 | + * A Class to be able to change settings for Font Awesome. |
|
| 26 | + * |
|
| 27 | + * Class AyeCode_UI_Settings |
|
| 28 | + * @ver 1.0.0 |
|
| 29 | + * @todo decide how to implement textdomain |
|
| 30 | + */ |
|
| 31 | + class AyeCode_UI_Settings { |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Class version version. |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + public $version = '0.1.67'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Class textdomain. |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + public $textdomain = 'aui'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Latest version of Bootstrap at time of publish published. |
|
| 49 | + * |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + public $latest = "4.5.3"; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Current version of select2 being used. |
|
| 56 | + * |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + public $select2_version = "4.0.11"; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * The title. |
|
| 63 | + * |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + public $name = 'AyeCode UI'; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The relative url to the assets. |
|
| 70 | + * |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | + public $url = ''; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Holds the settings values. |
|
| 77 | + * |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + private $settings; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * AyeCode_UI_Settings instance. |
|
| 84 | + * |
|
| 85 | + * @access private |
|
| 86 | + * @since 1.0.0 |
|
| 87 | + * @var AyeCode_UI_Settings There can be only one! |
|
| 88 | + */ |
|
| 89 | + private static $instance = null; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Main AyeCode_UI_Settings Instance. |
|
| 93 | + * |
|
| 94 | + * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
| 95 | + * |
|
| 96 | + * @since 1.0.0 |
|
| 97 | + * @static |
|
| 98 | + * @return AyeCode_UI_Settings - Main instance. |
|
| 99 | + */ |
|
| 100 | + public static function instance() { |
|
| 101 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
| 102 | + |
|
| 103 | + self::$instance = new AyeCode_UI_Settings; |
|
| 104 | + |
|
| 105 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 106 | + |
|
| 107 | + if ( is_admin() ) { |
|
| 108 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 109 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 110 | + |
|
| 111 | + // Maybe show example page |
|
| 112 | + add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
| 115 | + add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
| 116 | 116 | |
| 117 | - do_action( 'ayecode_ui_settings_loaded' ); |
|
| 118 | - } |
|
| 117 | + do_action( 'ayecode_ui_settings_loaded' ); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return self::$instance; |
|
| 121 | - } |
|
| 120 | + return self::$instance; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Setup some constants. |
|
| 125 | - */ |
|
| 126 | - public function constants(){ |
|
| 127 | - define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
| 128 | - define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
| 129 | - if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
| 130 | - if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
| 131 | - } |
|
| 123 | + /** |
|
| 124 | + * Setup some constants. |
|
| 125 | + */ |
|
| 126 | + public function constants(){ |
|
| 127 | + define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
| 128 | + define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
| 129 | + if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
| 130 | + if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Initiate the settings and add the required action hooks. |
|
| 135 | - */ |
|
| 136 | - public function init() { |
|
| 137 | - |
|
| 138 | - // Maybe fix settings |
|
| 139 | - if ( ! empty( $_REQUEST['aui-fix-admin'] ) && !empty($_REQUEST['nonce']) && wp_verify_nonce( $_REQUEST['nonce'], "aui-fix-admin" ) ) { |
|
| 140 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
| 141 | - if ( ! empty( $db_settings ) ) { |
|
| 142 | - $db_settings['css_backend'] = 'compatibility'; |
|
| 143 | - $db_settings['js_backend'] = 'core-popper'; |
|
| 144 | - update_option( 'ayecode-ui-settings', $db_settings ); |
|
| 145 | - wp_safe_redirect(admin_url("options-general.php?page=ayecode-ui-settings&updated=true")); |
|
| 146 | - } |
|
| 147 | - } |
|
| 133 | + /** |
|
| 134 | + * Initiate the settings and add the required action hooks. |
|
| 135 | + */ |
|
| 136 | + public function init() { |
|
| 137 | + |
|
| 138 | + // Maybe fix settings |
|
| 139 | + if ( ! empty( $_REQUEST['aui-fix-admin'] ) && !empty($_REQUEST['nonce']) && wp_verify_nonce( $_REQUEST['nonce'], "aui-fix-admin" ) ) { |
|
| 140 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
| 141 | + if ( ! empty( $db_settings ) ) { |
|
| 142 | + $db_settings['css_backend'] = 'compatibility'; |
|
| 143 | + $db_settings['js_backend'] = 'core-popper'; |
|
| 144 | + update_option( 'ayecode-ui-settings', $db_settings ); |
|
| 145 | + wp_safe_redirect(admin_url("options-general.php?page=ayecode-ui-settings&updated=true")); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - $this->constants(); |
|
| 150 | - $this->settings = $this->get_settings(); |
|
| 151 | - $this->url = $this->get_url(); |
|
| 149 | + $this->constants(); |
|
| 150 | + $this->settings = $this->get_settings(); |
|
| 151 | + $this->url = $this->get_url(); |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Maybe load CSS |
|
| 155 | + * |
|
| 156 | + * We load super early in case there is a theme version that might change the colors |
|
| 157 | + */ |
|
| 158 | + if ( $this->settings['css'] ) { |
|
| 159 | + $priority = $this->is_bs3_compat() ? 100 : 1; |
|
| 160 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), $priority ); |
|
| 161 | + } |
|
| 162 | + if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
| 163 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
| 164 | + } |
|
| 152 | 165 | |
| 153 | - /** |
|
| 154 | - * Maybe load CSS |
|
| 155 | - * |
|
| 156 | - * We load super early in case there is a theme version that might change the colors |
|
| 157 | - */ |
|
| 158 | - if ( $this->settings['css'] ) { |
|
| 159 | - $priority = $this->is_bs3_compat() ? 100 : 1; |
|
| 160 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), $priority ); |
|
| 161 | - } |
|
| 162 | - if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
| 163 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // maybe load JS |
|
| 167 | - if ( $this->settings['js'] ) { |
|
| 168 | - $priority = $this->is_bs3_compat() ? 100 : 1; |
|
| 169 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
| 170 | - } |
|
| 171 | - if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
| 172 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // Maybe set the HTML font size |
|
| 176 | - if ( $this->settings['html_font_size'] ) { |
|
| 177 | - add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // Maybe show backend style error |
|
| 181 | - if( $this->settings['css_backend'] != 'compatibility' || $this->settings['js_backend'] != 'core-popper' ){ |
|
| 182 | - add_action( 'admin_notices', array( $this, 'show_admin_style_notice' ) ); |
|
| 183 | - } |
|
| 166 | + // maybe load JS |
|
| 167 | + if ( $this->settings['js'] ) { |
|
| 168 | + $priority = $this->is_bs3_compat() ? 100 : 1; |
|
| 169 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
| 170 | + } |
|
| 171 | + if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
| 172 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
| 173 | + } |
|
| 184 | 174 | |
| 185 | - } |
|
| 175 | + // Maybe set the HTML font size |
|
| 176 | + if ( $this->settings['html_font_size'] ) { |
|
| 177 | + add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
| 178 | + } |
|
| 186 | 179 | |
| 187 | - /** |
|
| 188 | - * Show admin notice if backend scripts not loaded. |
|
| 189 | - */ |
|
| 190 | - public function show_admin_style_notice(){ |
|
| 191 | - $fix_url = admin_url("options-general.php?page=ayecode-ui-settings&aui-fix-admin=true&nonce=".wp_create_nonce('aui-fix-admin')); |
|
| 192 | - $button = '<a href="'.esc_url($fix_url).'" class="button-primary">Fix Now</a>'; |
|
| 193 | - $message = __( '<b>Style Issue:</b> AyeCode UI is disable or set wrong.')." " .$button; |
|
| 194 | - echo '<div class="notice notice-error aui-settings-error-notice"><p>'.$message.'</p></div>'; |
|
| 195 | - } |
|
| 180 | + // Maybe show backend style error |
|
| 181 | + if( $this->settings['css_backend'] != 'compatibility' || $this->settings['js_backend'] != 'core-popper' ){ |
|
| 182 | + add_action( 'admin_notices', array( $this, 'show_admin_style_notice' ) ); |
|
| 183 | + } |
|
| 196 | 184 | |
| 197 | - /** |
|
| 198 | - * Check if we should load the admin scripts or not. |
|
| 199 | - * |
|
| 200 | - * @return bool |
|
| 201 | - */ |
|
| 202 | - public function load_admin_scripts(){ |
|
| 203 | - $result = true; |
|
| 204 | - |
|
| 205 | - // check if specifically disabled |
|
| 206 | - if(!empty($this->settings['disable_admin'])){ |
|
| 207 | - $url_parts = explode("\n",$this->settings['disable_admin']); |
|
| 208 | - foreach($url_parts as $part){ |
|
| 209 | - if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
| 210 | - return false; // return early, no point checking further |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 185 | + } |
|
| 214 | 186 | |
| 215 | - return $result; |
|
| 216 | - } |
|
| 187 | + /** |
|
| 188 | + * Show admin notice if backend scripts not loaded. |
|
| 189 | + */ |
|
| 190 | + public function show_admin_style_notice(){ |
|
| 191 | + $fix_url = admin_url("options-general.php?page=ayecode-ui-settings&aui-fix-admin=true&nonce=".wp_create_nonce('aui-fix-admin')); |
|
| 192 | + $button = '<a href="'.esc_url($fix_url).'" class="button-primary">Fix Now</a>'; |
|
| 193 | + $message = __( '<b>Style Issue:</b> AyeCode UI is disable or set wrong.')." " .$button; |
|
| 194 | + echo '<div class="notice notice-error aui-settings-error-notice"><p>'.$message.'</p></div>'; |
|
| 195 | + } |
|
| 217 | 196 | |
| 218 | - /** |
|
| 219 | - * Add a html font size to the footer. |
|
| 220 | - */ |
|
| 221 | - public function html_font_size(){ |
|
| 222 | - $this->settings = $this->get_settings(); |
|
| 223 | - echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
| 224 | - } |
|
| 197 | + /** |
|
| 198 | + * Check if we should load the admin scripts or not. |
|
| 199 | + * |
|
| 200 | + * @return bool |
|
| 201 | + */ |
|
| 202 | + public function load_admin_scripts(){ |
|
| 203 | + $result = true; |
|
| 204 | + |
|
| 205 | + // check if specifically disabled |
|
| 206 | + if(!empty($this->settings['disable_admin'])){ |
|
| 207 | + $url_parts = explode("\n",$this->settings['disable_admin']); |
|
| 208 | + foreach($url_parts as $part){ |
|
| 209 | + if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
| 210 | + return false; // return early, no point checking further |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + return $result; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Add a html font size to the footer. |
|
| 220 | + */ |
|
| 221 | + public function html_font_size(){ |
|
| 222 | + $this->settings = $this->get_settings(); |
|
| 223 | + echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Check if the current admin screen should load scripts. |
|
| 228 | - * |
|
| 229 | - * @return bool |
|
| 230 | - */ |
|
| 231 | - public function is_aui_screen(){ |
|
| 226 | + /** |
|
| 227 | + * Check if the current admin screen should load scripts. |
|
| 228 | + * |
|
| 229 | + * @return bool |
|
| 230 | + */ |
|
| 231 | + public function is_aui_screen(){ |
|
| 232 | 232 | // echo '###';exit; |
| 233 | - $load = false; |
|
| 234 | - // check if we should load or not |
|
| 235 | - if ( is_admin() ) { |
|
| 236 | - // Only enable on set pages |
|
| 237 | - $aui_screens = array( |
|
| 238 | - 'page', |
|
| 239 | - 'post', |
|
| 240 | - 'settings_page_ayecode-ui-settings', |
|
| 241 | - 'appearance_page_gutenberg-widgets', |
|
| 242 | - 'widgets', |
|
| 243 | - 'ayecode-ui-settings', |
|
| 244 | - 'site-editor' |
|
| 245 | - ); |
|
| 246 | - $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
| 247 | - |
|
| 248 | - $screen = get_current_screen(); |
|
| 233 | + $load = false; |
|
| 234 | + // check if we should load or not |
|
| 235 | + if ( is_admin() ) { |
|
| 236 | + // Only enable on set pages |
|
| 237 | + $aui_screens = array( |
|
| 238 | + 'page', |
|
| 239 | + 'post', |
|
| 240 | + 'settings_page_ayecode-ui-settings', |
|
| 241 | + 'appearance_page_gutenberg-widgets', |
|
| 242 | + 'widgets', |
|
| 243 | + 'ayecode-ui-settings', |
|
| 244 | + 'site-editor' |
|
| 245 | + ); |
|
| 246 | + $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
| 247 | + |
|
| 248 | + $screen = get_current_screen(); |
|
| 249 | 249 | |
| 250 | 250 | // echo '###'.$screen->id; |
| 251 | 251 | |
| 252 | - // check if we are on a AUI screen |
|
| 253 | - if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
| 254 | - $load = true; |
|
| 255 | - } |
|
| 252 | + // check if we are on a AUI screen |
|
| 253 | + if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
| 254 | + $load = true; |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - //load for widget previews in WP 5.8 |
|
| 258 | - if( !empty($_REQUEST['legacy-widget-preview'])){ |
|
| 259 | - $load = true; |
|
| 260 | - } |
|
| 261 | - } |
|
| 257 | + //load for widget previews in WP 5.8 |
|
| 258 | + if( !empty($_REQUEST['legacy-widget-preview'])){ |
|
| 259 | + $load = true; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - return apply_filters( 'aui_load_on_admin' , $load ); |
|
| 264 | - } |
|
| 263 | + return apply_filters( 'aui_load_on_admin' , $load ); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Adds the styles. |
|
| 268 | - */ |
|
| 269 | - public function enqueue_style() { |
|
| 266 | + /** |
|
| 267 | + * Adds the styles. |
|
| 268 | + */ |
|
| 269 | + public function enqueue_style() { |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | - if( is_admin() && !$this->is_aui_screen()){ |
|
| 273 | - // don't add wp-admin scripts if not requested to |
|
| 274 | - }else{ |
|
| 275 | - $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
| 272 | + if( is_admin() && !$this->is_aui_screen()){ |
|
| 273 | + // don't add wp-admin scripts if not requested to |
|
| 274 | + }else{ |
|
| 275 | + $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
| 276 | 276 | |
| 277 | - $rtl = is_rtl() ? '-rtl' : ''; |
|
| 277 | + $rtl = is_rtl() ? '-rtl' : ''; |
|
| 278 | 278 | |
| 279 | - if($this->settings[$css_setting]){ |
|
| 280 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
| 281 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
| 282 | - wp_register_style( 'ayecode-ui', $url, array(), $this->version ); |
|
| 283 | - wp_enqueue_style( 'ayecode-ui' ); |
|
| 279 | + if($this->settings[$css_setting]){ |
|
| 280 | + $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
| 281 | + $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
| 282 | + wp_register_style( 'ayecode-ui', $url, array(), $this->version ); |
|
| 283 | + wp_enqueue_style( 'ayecode-ui' ); |
|
| 284 | 284 | |
| 285 | - // flatpickr |
|
| 286 | - wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->version ); |
|
| 285 | + // flatpickr |
|
| 286 | + wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->version ); |
|
| 287 | 287 | |
| 288 | - // fix some wp-admin issues |
|
| 289 | - if(is_admin()){ |
|
| 290 | - $custom_css = " |
|
| 288 | + // fix some wp-admin issues |
|
| 289 | + if(is_admin()){ |
|
| 290 | + $custom_css = " |
|
| 291 | 291 | body{ |
| 292 | 292 | background-color: #f1f1f1; |
| 293 | 293 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
@@ -333,35 +333,35 @@ discard block |
||
| 333 | 333 | } |
| 334 | 334 | "; |
| 335 | 335 | |
| 336 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
| 337 | - $custom_css .= " |
|
| 336 | + // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
| 337 | + $custom_css .= " |
|
| 338 | 338 | .edit-post-sidebar input[type=color].components-text-control__input{ |
| 339 | 339 | padding: 0; |
| 340 | 340 | } |
| 341 | 341 | "; |
| 342 | - wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
| 343 | - } |
|
| 342 | + wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - // custom changes |
|
| 346 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
| 345 | + // custom changes |
|
| 346 | + wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
| 347 | 347 | |
| 348 | - } |
|
| 349 | - } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | 351 | |
| 352 | - } |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | - /** |
|
| 355 | - * Get inline script used if bootstrap enqueued |
|
| 356 | - * |
|
| 357 | - * If this remains small then its best to use this than to add another JS file. |
|
| 358 | - */ |
|
| 359 | - public function inline_script() { |
|
| 360 | - // Flatpickr calendar locale |
|
| 361 | - $flatpickr_locale = self::flatpickr_locale(); |
|
| 362 | - |
|
| 363 | - ob_start(); |
|
| 364 | - ?> |
|
| 354 | + /** |
|
| 355 | + * Get inline script used if bootstrap enqueued |
|
| 356 | + * |
|
| 357 | + * If this remains small then its best to use this than to add another JS file. |
|
| 358 | + */ |
|
| 359 | + public function inline_script() { |
|
| 360 | + // Flatpickr calendar locale |
|
| 361 | + $flatpickr_locale = self::flatpickr_locale(); |
|
| 362 | + |
|
| 363 | + ob_start(); |
|
| 364 | + ?> |
|
| 365 | 365 | <script> |
| 366 | 366 | /** |
| 367 | 367 | * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ). |
@@ -1196,29 +1196,29 @@ discard block |
||
| 1196 | 1196 | } |
| 1197 | 1197 | </script> |
| 1198 | 1198 | <?php |
| 1199 | - $output = ob_get_clean(); |
|
| 1199 | + $output = ob_get_clean(); |
|
| 1200 | 1200 | |
| 1201 | 1201 | |
| 1202 | 1202 | |
| 1203 | - /* |
|
| 1203 | + /* |
|
| 1204 | 1204 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1205 | 1205 | */ |
| 1206 | - return str_replace( array( |
|
| 1207 | - '<script>', |
|
| 1208 | - '</script>' |
|
| 1209 | - ), '', self::minify_js($output) ); |
|
| 1210 | - } |
|
| 1206 | + return str_replace( array( |
|
| 1207 | + '<script>', |
|
| 1208 | + '</script>' |
|
| 1209 | + ), '', self::minify_js($output) ); |
|
| 1210 | + } |
|
| 1211 | 1211 | |
| 1212 | 1212 | |
| 1213 | - /** |
|
| 1214 | - * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
| 1215 | - * |
|
| 1216 | - * @TODO we may need this when other conflicts arrise. |
|
| 1217 | - * @return mixed |
|
| 1218 | - */ |
|
| 1219 | - public static function bs3_compat_js() { |
|
| 1220 | - ob_start(); |
|
| 1221 | - ?> |
|
| 1213 | + /** |
|
| 1214 | + * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
| 1215 | + * |
|
| 1216 | + * @TODO we may need this when other conflicts arrise. |
|
| 1217 | + * @return mixed |
|
| 1218 | + */ |
|
| 1219 | + public static function bs3_compat_js() { |
|
| 1220 | + ob_start(); |
|
| 1221 | + ?> |
|
| 1222 | 1222 | <script> |
| 1223 | 1223 | <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?> |
| 1224 | 1224 | /* With Avada builder */ |
@@ -1226,20 +1226,20 @@ discard block |
||
| 1226 | 1226 | <?php } ?> |
| 1227 | 1227 | </script> |
| 1228 | 1228 | <?php |
| 1229 | - return str_replace( array( |
|
| 1230 | - '<script>', |
|
| 1231 | - '</script>' |
|
| 1232 | - ), '', ob_get_clean()); |
|
| 1233 | - } |
|
| 1229 | + return str_replace( array( |
|
| 1230 | + '<script>', |
|
| 1231 | + '</script>' |
|
| 1232 | + ), '', ob_get_clean()); |
|
| 1233 | + } |
|
| 1234 | 1234 | |
| 1235 | - /** |
|
| 1236 | - * Get inline script used if bootstrap file browser enqueued. |
|
| 1237 | - * |
|
| 1238 | - * If this remains small then its best to use this than to add another JS file. |
|
| 1239 | - */ |
|
| 1240 | - public function inline_script_file_browser(){ |
|
| 1241 | - ob_start(); |
|
| 1242 | - ?> |
|
| 1235 | + /** |
|
| 1236 | + * Get inline script used if bootstrap file browser enqueued. |
|
| 1237 | + * |
|
| 1238 | + * If this remains small then its best to use this than to add another JS file. |
|
| 1239 | + */ |
|
| 1240 | + public function inline_script_file_browser(){ |
|
| 1241 | + ob_start(); |
|
| 1242 | + ?> |
|
| 1243 | 1243 | <script> |
| 1244 | 1244 | // run on doc ready |
| 1245 | 1245 | jQuery(document).ready(function () { |
@@ -1247,203 +1247,203 @@ discard block |
||
| 1247 | 1247 | }); |
| 1248 | 1248 | </script> |
| 1249 | 1249 | <?php |
| 1250 | - $output = ob_get_clean(); |
|
| 1250 | + $output = ob_get_clean(); |
|
| 1251 | 1251 | |
| 1252 | - /* |
|
| 1252 | + /* |
|
| 1253 | 1253 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1254 | 1254 | */ |
| 1255 | - return str_replace( array( |
|
| 1256 | - '<script>', |
|
| 1257 | - '</script>' |
|
| 1258 | - ), '', $output ); |
|
| 1259 | - } |
|
| 1255 | + return str_replace( array( |
|
| 1256 | + '<script>', |
|
| 1257 | + '</script>' |
|
| 1258 | + ), '', $output ); |
|
| 1259 | + } |
|
| 1260 | 1260 | |
| 1261 | - /** |
|
| 1262 | - * Adds the Font Awesome JS. |
|
| 1263 | - */ |
|
| 1264 | - public function enqueue_scripts() { |
|
| 1261 | + /** |
|
| 1262 | + * Adds the Font Awesome JS. |
|
| 1263 | + */ |
|
| 1264 | + public function enqueue_scripts() { |
|
| 1265 | 1265 | |
| 1266 | - if( is_admin() && !$this->is_aui_screen()){ |
|
| 1267 | - // don't add wp-admin scripts if not requested to |
|
| 1268 | - }else { |
|
| 1266 | + if( is_admin() && !$this->is_aui_screen()){ |
|
| 1267 | + // don't add wp-admin scripts if not requested to |
|
| 1268 | + }else { |
|
| 1269 | 1269 | |
| 1270 | - $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
| 1270 | + $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
| 1271 | 1271 | |
| 1272 | - // select2 |
|
| 1273 | - wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
| 1272 | + // select2 |
|
| 1273 | + wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
| 1274 | 1274 | |
| 1275 | - // flatpickr |
|
| 1276 | - wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->version ); |
|
| 1275 | + // flatpickr |
|
| 1276 | + wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->version ); |
|
| 1277 | 1277 | |
| 1278 | - // flatpickr |
|
| 1279 | - wp_register_script( 'iconpicker', $this->url . 'assets/js/fontawesome-iconpicker.min.js', array(), $this->version ); |
|
| 1278 | + // flatpickr |
|
| 1279 | + wp_register_script( 'iconpicker', $this->url . 'assets/js/fontawesome-iconpicker.min.js', array(), $this->version ); |
|
| 1280 | 1280 | |
| 1281 | - // Bootstrap file browser |
|
| 1282 | - wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
| 1283 | - wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
| 1284 | - |
|
| 1285 | - $load_inline = false; |
|
| 1286 | - |
|
| 1287 | - if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
| 1288 | - // Bootstrap bundle |
|
| 1289 | - $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
| 1290 | - wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
| 1291 | - 'select2', |
|
| 1292 | - 'jquery' |
|
| 1293 | - ), $this->version, $this->is_bs3_compat() ); |
|
| 1294 | - // if in admin then add to footer for compatibility. |
|
| 1295 | - is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
| 1296 | - $script = $this->inline_script(); |
|
| 1297 | - wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
| 1298 | - } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
| 1299 | - $url = $this->url . 'assets/js/popper.min.js'; |
|
| 1300 | - wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->version ); |
|
| 1301 | - wp_enqueue_script( 'bootstrap-js-popper' ); |
|
| 1302 | - $load_inline = true; |
|
| 1303 | - } else { |
|
| 1304 | - $load_inline = true; |
|
| 1305 | - } |
|
| 1281 | + // Bootstrap file browser |
|
| 1282 | + wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
| 1283 | + wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
| 1284 | + |
|
| 1285 | + $load_inline = false; |
|
| 1286 | + |
|
| 1287 | + if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
| 1288 | + // Bootstrap bundle |
|
| 1289 | + $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
| 1290 | + wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
| 1291 | + 'select2', |
|
| 1292 | + 'jquery' |
|
| 1293 | + ), $this->version, $this->is_bs3_compat() ); |
|
| 1294 | + // if in admin then add to footer for compatibility. |
|
| 1295 | + is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
| 1296 | + $script = $this->inline_script(); |
|
| 1297 | + wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
| 1298 | + } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
| 1299 | + $url = $this->url . 'assets/js/popper.min.js'; |
|
| 1300 | + wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->version ); |
|
| 1301 | + wp_enqueue_script( 'bootstrap-js-popper' ); |
|
| 1302 | + $load_inline = true; |
|
| 1303 | + } else { |
|
| 1304 | + $load_inline = true; |
|
| 1305 | + } |
|
| 1306 | 1306 | |
| 1307 | - // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
| 1308 | - if ( $load_inline ) { |
|
| 1309 | - wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
| 1310 | - wp_enqueue_script( 'bootstrap-dummy' ); |
|
| 1311 | - $script = $this->inline_script(); |
|
| 1312 | - wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
| 1313 | - } |
|
| 1314 | - } |
|
| 1307 | + // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
| 1308 | + if ( $load_inline ) { |
|
| 1309 | + wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
| 1310 | + wp_enqueue_script( 'bootstrap-dummy' ); |
|
| 1311 | + $script = $this->inline_script(); |
|
| 1312 | + wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
| 1313 | + } |
|
| 1314 | + } |
|
| 1315 | 1315 | |
| 1316 | - } |
|
| 1316 | + } |
|
| 1317 | 1317 | |
| 1318 | - /** |
|
| 1319 | - * Enqueue flatpickr if called. |
|
| 1320 | - */ |
|
| 1321 | - public function enqueue_flatpickr(){ |
|
| 1322 | - wp_enqueue_style( 'flatpickr' ); |
|
| 1323 | - wp_enqueue_script( 'flatpickr' ); |
|
| 1324 | - } |
|
| 1318 | + /** |
|
| 1319 | + * Enqueue flatpickr if called. |
|
| 1320 | + */ |
|
| 1321 | + public function enqueue_flatpickr(){ |
|
| 1322 | + wp_enqueue_style( 'flatpickr' ); |
|
| 1323 | + wp_enqueue_script( 'flatpickr' ); |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | - /** |
|
| 1327 | - * Enqueue iconpicker if called. |
|
| 1328 | - */ |
|
| 1329 | - public function enqueue_iconpicker(){ |
|
| 1330 | - wp_enqueue_style( 'iconpicker' ); |
|
| 1331 | - wp_enqueue_script( 'iconpicker' ); |
|
| 1332 | - } |
|
| 1326 | + /** |
|
| 1327 | + * Enqueue iconpicker if called. |
|
| 1328 | + */ |
|
| 1329 | + public function enqueue_iconpicker(){ |
|
| 1330 | + wp_enqueue_style( 'iconpicker' ); |
|
| 1331 | + wp_enqueue_script( 'iconpicker' ); |
|
| 1332 | + } |
|
| 1333 | 1333 | |
| 1334 | - /** |
|
| 1335 | - * Get the url path to the current folder. |
|
| 1336 | - * |
|
| 1337 | - * @return string |
|
| 1338 | - */ |
|
| 1339 | - public function get_url() { |
|
| 1334 | + /** |
|
| 1335 | + * Get the url path to the current folder. |
|
| 1336 | + * |
|
| 1337 | + * @return string |
|
| 1338 | + */ |
|
| 1339 | + public function get_url() { |
|
| 1340 | 1340 | |
| 1341 | - $url = ''; |
|
| 1342 | - // check if we are inside a plugin |
|
| 1343 | - $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
| 1341 | + $url = ''; |
|
| 1342 | + // check if we are inside a plugin |
|
| 1343 | + $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
| 1344 | 1344 | |
| 1345 | - // add check in-case user has changed wp-content dir name. |
|
| 1346 | - $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
| 1347 | - $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
| 1348 | - $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
| 1345 | + // add check in-case user has changed wp-content dir name. |
|
| 1346 | + $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
| 1347 | + $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
| 1348 | + $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
| 1349 | 1349 | |
| 1350 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
| 1351 | - $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
| 1352 | - } |
|
| 1350 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
| 1351 | + $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
| 1352 | + } |
|
| 1353 | 1353 | |
| 1354 | - return $url; |
|
| 1355 | - } |
|
| 1354 | + return $url; |
|
| 1355 | + } |
|
| 1356 | 1356 | |
| 1357 | - /** |
|
| 1358 | - * Register the database settings with WordPress. |
|
| 1359 | - */ |
|
| 1360 | - public function register_settings() { |
|
| 1361 | - register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
| 1362 | - } |
|
| 1357 | + /** |
|
| 1358 | + * Register the database settings with WordPress. |
|
| 1359 | + */ |
|
| 1360 | + public function register_settings() { |
|
| 1361 | + register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
| 1362 | + } |
|
| 1363 | 1363 | |
| 1364 | - /** |
|
| 1365 | - * Add the WordPress settings menu item. |
|
| 1366 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 1367 | - */ |
|
| 1368 | - public function menu_item() { |
|
| 1369 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
| 1370 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
| 1371 | - $this, |
|
| 1372 | - 'settings_page' |
|
| 1373 | - ) ); |
|
| 1374 | - } |
|
| 1364 | + /** |
|
| 1365 | + * Add the WordPress settings menu item. |
|
| 1366 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 1367 | + */ |
|
| 1368 | + public function menu_item() { |
|
| 1369 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
| 1370 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
| 1371 | + $this, |
|
| 1372 | + 'settings_page' |
|
| 1373 | + ) ); |
|
| 1374 | + } |
|
| 1375 | 1375 | |
| 1376 | - /** |
|
| 1377 | - * Get a list of themes and their default JS settings. |
|
| 1378 | - * |
|
| 1379 | - * @return array |
|
| 1380 | - */ |
|
| 1381 | - public function theme_js_settings(){ |
|
| 1382 | - return array( |
|
| 1383 | - 'ayetheme' => 'popper', |
|
| 1384 | - 'listimia' => 'required', |
|
| 1385 | - 'listimia_backend' => 'core-popper', |
|
| 1386 | - //'avada' => 'required', // removed as we now add compatibility |
|
| 1387 | - ); |
|
| 1388 | - } |
|
| 1376 | + /** |
|
| 1377 | + * Get a list of themes and their default JS settings. |
|
| 1378 | + * |
|
| 1379 | + * @return array |
|
| 1380 | + */ |
|
| 1381 | + public function theme_js_settings(){ |
|
| 1382 | + return array( |
|
| 1383 | + 'ayetheme' => 'popper', |
|
| 1384 | + 'listimia' => 'required', |
|
| 1385 | + 'listimia_backend' => 'core-popper', |
|
| 1386 | + //'avada' => 'required', // removed as we now add compatibility |
|
| 1387 | + ); |
|
| 1388 | + } |
|
| 1389 | 1389 | |
| 1390 | - /** |
|
| 1391 | - * Get the current Font Awesome output settings. |
|
| 1392 | - * |
|
| 1393 | - * @return array The array of settings. |
|
| 1394 | - */ |
|
| 1395 | - public function get_settings() { |
|
| 1396 | - |
|
| 1397 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
| 1398 | - $js_default = 'core-popper'; |
|
| 1399 | - $js_default_backend = $js_default; |
|
| 1400 | - |
|
| 1401 | - // maybe set defaults (if no settings set) |
|
| 1402 | - if(empty($db_settings)){ |
|
| 1403 | - $active_theme = strtolower( get_template() ); // active parent theme. |
|
| 1404 | - $theme_js_settings = self::theme_js_settings(); |
|
| 1405 | - if(isset($theme_js_settings[$active_theme])){ |
|
| 1406 | - $js_default = $theme_js_settings[$active_theme]; |
|
| 1407 | - $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
| 1408 | - } |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - $defaults = array( |
|
| 1412 | - 'css' => 'compatibility', // core, compatibility |
|
| 1413 | - 'js' => $js_default, // js to load, core-popper, popper |
|
| 1414 | - 'html_font_size' => '16', // js to load, core-popper, popper |
|
| 1415 | - 'css_backend' => 'compatibility', // core, compatibility |
|
| 1416 | - 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
| 1417 | - 'disable_admin' => '', // URL snippets to disable loading on admin |
|
| 1418 | - ); |
|
| 1419 | - |
|
| 1420 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 1421 | - |
|
| 1422 | - /** |
|
| 1423 | - * Filter the Bootstrap settings. |
|
| 1424 | - * |
|
| 1425 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 1426 | - */ |
|
| 1427 | - return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
| 1428 | - } |
|
| 1390 | + /** |
|
| 1391 | + * Get the current Font Awesome output settings. |
|
| 1392 | + * |
|
| 1393 | + * @return array The array of settings. |
|
| 1394 | + */ |
|
| 1395 | + public function get_settings() { |
|
| 1396 | + |
|
| 1397 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
| 1398 | + $js_default = 'core-popper'; |
|
| 1399 | + $js_default_backend = $js_default; |
|
| 1400 | + |
|
| 1401 | + // maybe set defaults (if no settings set) |
|
| 1402 | + if(empty($db_settings)){ |
|
| 1403 | + $active_theme = strtolower( get_template() ); // active parent theme. |
|
| 1404 | + $theme_js_settings = self::theme_js_settings(); |
|
| 1405 | + if(isset($theme_js_settings[$active_theme])){ |
|
| 1406 | + $js_default = $theme_js_settings[$active_theme]; |
|
| 1407 | + $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
| 1408 | + } |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + $defaults = array( |
|
| 1412 | + 'css' => 'compatibility', // core, compatibility |
|
| 1413 | + 'js' => $js_default, // js to load, core-popper, popper |
|
| 1414 | + 'html_font_size' => '16', // js to load, core-popper, popper |
|
| 1415 | + 'css_backend' => 'compatibility', // core, compatibility |
|
| 1416 | + 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
| 1417 | + 'disable_admin' => '', // URL snippets to disable loading on admin |
|
| 1418 | + ); |
|
| 1419 | + |
|
| 1420 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 1421 | + |
|
| 1422 | + /** |
|
| 1423 | + * Filter the Bootstrap settings. |
|
| 1424 | + * |
|
| 1425 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 1426 | + */ |
|
| 1427 | + return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
| 1428 | + } |
|
| 1429 | 1429 | |
| 1430 | 1430 | |
| 1431 | - /** |
|
| 1432 | - * The settings page html output. |
|
| 1433 | - */ |
|
| 1434 | - public function settings_page() { |
|
| 1435 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1436 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
| 1437 | - } |
|
| 1438 | - ?> |
|
| 1431 | + /** |
|
| 1432 | + * The settings page html output. |
|
| 1433 | + */ |
|
| 1434 | + public function settings_page() { |
|
| 1435 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1436 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
| 1437 | + } |
|
| 1438 | + ?> |
|
| 1439 | 1439 | <div class="wrap"> |
| 1440 | 1440 | <h1><?php echo $this->name; ?></h1> |
| 1441 | 1441 | <p><?php _e("Here you can adjust settings if you are having compatibility issues.",'aui');?></p> |
| 1442 | 1442 | <form method="post" action="options.php"> |
| 1443 | 1443 | <?php |
| 1444 | - settings_fields( 'ayecode-ui-settings' ); |
|
| 1445 | - do_settings_sections( 'ayecode-ui-settings' ); |
|
| 1446 | - ?> |
|
| 1444 | + settings_fields( 'ayecode-ui-settings' ); |
|
| 1445 | + do_settings_sections( 'ayecode-ui-settings' ); |
|
| 1446 | + ?> |
|
| 1447 | 1447 | |
| 1448 | 1448 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
| 1449 | 1449 | <table class="form-table wpbs-table-settings"> |
@@ -1523,60 +1523,60 @@ discard block |
||
| 1523 | 1523 | </table> |
| 1524 | 1524 | |
| 1525 | 1525 | <?php |
| 1526 | - submit_button(); |
|
| 1527 | - ?> |
|
| 1526 | + submit_button(); |
|
| 1527 | + ?> |
|
| 1528 | 1528 | </form> |
| 1529 | 1529 | |
| 1530 | 1530 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
| 1531 | 1531 | </div> |
| 1532 | 1532 | |
| 1533 | 1533 | <?php |
| 1534 | - } |
|
| 1534 | + } |
|
| 1535 | 1535 | |
| 1536 | - public function customizer_settings($wp_customize){ |
|
| 1537 | - $wp_customize->add_section('aui_settings', array( |
|
| 1538 | - 'title' => __('AyeCode UI','aui'), |
|
| 1539 | - 'priority' => 120, |
|
| 1540 | - )); |
|
| 1541 | - |
|
| 1542 | - // ============================= |
|
| 1543 | - // = Color Picker = |
|
| 1544 | - // ============================= |
|
| 1545 | - $wp_customize->add_setting('aui_options[color_primary]', array( |
|
| 1546 | - 'default' => AUI_PRIMARY_COLOR, |
|
| 1547 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
| 1548 | - 'capability' => 'edit_theme_options', |
|
| 1549 | - 'type' => 'option', |
|
| 1550 | - 'transport' => 'refresh', |
|
| 1551 | - )); |
|
| 1552 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
| 1553 | - 'label' => __('Primary Color','aui'), |
|
| 1554 | - 'section' => 'aui_settings', |
|
| 1555 | - 'settings' => 'aui_options[color_primary]', |
|
| 1556 | - ))); |
|
| 1557 | - |
|
| 1558 | - $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
| 1559 | - 'default' => '#6c757d', |
|
| 1560 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
| 1561 | - 'capability' => 'edit_theme_options', |
|
| 1562 | - 'type' => 'option', |
|
| 1563 | - 'transport' => 'refresh', |
|
| 1564 | - )); |
|
| 1565 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
| 1566 | - 'label' => __('Secondary Color','aui'), |
|
| 1567 | - 'section' => 'aui_settings', |
|
| 1568 | - 'settings' => 'aui_options[color_secondary]', |
|
| 1569 | - ))); |
|
| 1570 | - } |
|
| 1536 | + public function customizer_settings($wp_customize){ |
|
| 1537 | + $wp_customize->add_section('aui_settings', array( |
|
| 1538 | + 'title' => __('AyeCode UI','aui'), |
|
| 1539 | + 'priority' => 120, |
|
| 1540 | + )); |
|
| 1541 | + |
|
| 1542 | + // ============================= |
|
| 1543 | + // = Color Picker = |
|
| 1544 | + // ============================= |
|
| 1545 | + $wp_customize->add_setting('aui_options[color_primary]', array( |
|
| 1546 | + 'default' => AUI_PRIMARY_COLOR, |
|
| 1547 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
| 1548 | + 'capability' => 'edit_theme_options', |
|
| 1549 | + 'type' => 'option', |
|
| 1550 | + 'transport' => 'refresh', |
|
| 1551 | + )); |
|
| 1552 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
| 1553 | + 'label' => __('Primary Color','aui'), |
|
| 1554 | + 'section' => 'aui_settings', |
|
| 1555 | + 'settings' => 'aui_options[color_primary]', |
|
| 1556 | + ))); |
|
| 1557 | + |
|
| 1558 | + $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
| 1559 | + 'default' => '#6c757d', |
|
| 1560 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
| 1561 | + 'capability' => 'edit_theme_options', |
|
| 1562 | + 'type' => 'option', |
|
| 1563 | + 'transport' => 'refresh', |
|
| 1564 | + )); |
|
| 1565 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
| 1566 | + 'label' => __('Secondary Color','aui'), |
|
| 1567 | + 'section' => 'aui_settings', |
|
| 1568 | + 'settings' => 'aui_options[color_secondary]', |
|
| 1569 | + ))); |
|
| 1570 | + } |
|
| 1571 | 1571 | |
| 1572 | - /** |
|
| 1573 | - * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
| 1574 | - * |
|
| 1575 | - * @return mixed |
|
| 1576 | - */ |
|
| 1577 | - public static function bs3_compat_css() { |
|
| 1578 | - ob_start(); |
|
| 1579 | - ?> |
|
| 1572 | + /** |
|
| 1573 | + * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
| 1574 | + * |
|
| 1575 | + * @return mixed |
|
| 1576 | + */ |
|
| 1577 | + public static function bs3_compat_css() { |
|
| 1578 | + ob_start(); |
|
| 1579 | + ?> |
|
| 1580 | 1580 | <style> |
| 1581 | 1581 | /* Bootstrap 3 compatibility */ |
| 1582 | 1582 | body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;} |
@@ -1605,583 +1605,583 @@ discard block |
||
| 1605 | 1605 | <?php } ?> |
| 1606 | 1606 | </style> |
| 1607 | 1607 | <?php |
| 1608 | - return str_replace( array( |
|
| 1609 | - '<style>', |
|
| 1610 | - '</style>' |
|
| 1611 | - ), '', self::minify_css( ob_get_clean() ) ); |
|
| 1612 | - } |
|
| 1608 | + return str_replace( array( |
|
| 1609 | + '<style>', |
|
| 1610 | + '</style>' |
|
| 1611 | + ), '', self::minify_css( ob_get_clean() ) ); |
|
| 1612 | + } |
|
| 1613 | 1613 | |
| 1614 | 1614 | |
| 1615 | - public static function custom_css($compatibility = true) { |
|
| 1616 | - $settings = get_option('aui_options'); |
|
| 1615 | + public static function custom_css($compatibility = true) { |
|
| 1616 | + $settings = get_option('aui_options'); |
|
| 1617 | 1617 | |
| 1618 | - ob_start(); |
|
| 1618 | + ob_start(); |
|
| 1619 | 1619 | |
| 1620 | - $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
| 1621 | - $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
| 1622 | - //AUI_PRIMARY_COLOR_ORIGINAL |
|
| 1623 | - ?> |
|
| 1620 | + $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
| 1621 | + $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
| 1622 | + //AUI_PRIMARY_COLOR_ORIGINAL |
|
| 1623 | + ?> |
|
| 1624 | 1624 | <style> |
| 1625 | 1625 | <?php |
| 1626 | 1626 | |
| 1627 | - // BS v3 compat |
|
| 1628 | - if( self::is_bs3_compat() ){ |
|
| 1629 | - echo self::bs3_compat_css(); |
|
| 1630 | - } |
|
| 1627 | + // BS v3 compat |
|
| 1628 | + if( self::is_bs3_compat() ){ |
|
| 1629 | + echo self::bs3_compat_css(); |
|
| 1630 | + } |
|
| 1631 | 1631 | |
| 1632 | - if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
| 1633 | - echo self::css_primary($primary_color,$compatibility); |
|
| 1634 | - } |
|
| 1632 | + if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
| 1633 | + echo self::css_primary($primary_color,$compatibility); |
|
| 1634 | + } |
|
| 1635 | 1635 | |
| 1636 | - if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
| 1637 | - echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
| 1638 | - } |
|
| 1636 | + if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
| 1637 | + echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
| 1638 | + } |
|
| 1639 | 1639 | |
| 1640 | - // Set admin bar z-index lower when modal is open. |
|
| 1641 | - echo ' body.modal-open #wpadminbar{z-index:999}.embed-responsive-16by9 .fluid-width-video-wrapper{padding:0 !important;position:initial}'; |
|
| 1640 | + // Set admin bar z-index lower when modal is open. |
|
| 1641 | + echo ' body.modal-open #wpadminbar{z-index:999}.embed-responsive-16by9 .fluid-width-video-wrapper{padding:0 !important;position:initial}'; |
|
| 1642 | 1642 | |
| 1643 | - if(is_admin()){ |
|
| 1644 | - echo ' body.modal-open #adminmenuwrap{z-index:999} body.modal-open #wpadminbar{z-index:1025}'; |
|
| 1645 | - } |
|
| 1643 | + if(is_admin()){ |
|
| 1644 | + echo ' body.modal-open #adminmenuwrap{z-index:999} body.modal-open #wpadminbar{z-index:1025}'; |
|
| 1645 | + } |
|
| 1646 | 1646 | ?> |
| 1647 | 1647 | </style> |
| 1648 | 1648 | <?php |
| 1649 | 1649 | |
| 1650 | 1650 | |
| 1651 | - /* |
|
| 1651 | + /* |
|
| 1652 | 1652 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1653 | 1653 | */ |
| 1654 | - return str_replace( array( |
|
| 1655 | - '<style>', |
|
| 1656 | - '</style>' |
|
| 1657 | - ), '', self::minify_css( ob_get_clean() ) ); |
|
| 1658 | - } |
|
| 1654 | + return str_replace( array( |
|
| 1655 | + '<style>', |
|
| 1656 | + '</style>' |
|
| 1657 | + ), '', self::minify_css( ob_get_clean() ) ); |
|
| 1658 | + } |
|
| 1659 | 1659 | |
| 1660 | - /** |
|
| 1661 | - * Check if we should add booststrap 3 compatibility changes. |
|
| 1662 | - * |
|
| 1663 | - * @return bool |
|
| 1664 | - */ |
|
| 1665 | - public static function is_bs3_compat(){ |
|
| 1666 | - return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
| 1667 | - } |
|
| 1660 | + /** |
|
| 1661 | + * Check if we should add booststrap 3 compatibility changes. |
|
| 1662 | + * |
|
| 1663 | + * @return bool |
|
| 1664 | + */ |
|
| 1665 | + public static function is_bs3_compat(){ |
|
| 1666 | + return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
| 1667 | + } |
|
| 1668 | 1668 | |
| 1669 | - public static function css_primary($color_code,$compatibility){; |
|
| 1670 | - $color_code = sanitize_hex_color($color_code); |
|
| 1671 | - if(!$color_code){return '';} |
|
| 1672 | - /** |
|
| 1673 | - * c = color, b = background color, o = border-color, f = fill |
|
| 1674 | - */ |
|
| 1675 | - $selectors = array( |
|
| 1676 | - 'a' => array('c'), |
|
| 1677 | - '.btn-primary' => array('b','o'), |
|
| 1678 | - '.btn-primary.disabled' => array('b','o'), |
|
| 1679 | - '.btn-primary:disabled' => array('b','o'), |
|
| 1680 | - '.btn-outline-primary' => array('c','o'), |
|
| 1681 | - '.btn-outline-primary:hover' => array('b','o'), |
|
| 1682 | - '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
| 1683 | - '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
| 1684 | - '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
| 1685 | - '.btn-link' => array('c'), |
|
| 1686 | - '.dropdown-item.active' => array('b'), |
|
| 1687 | - '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
| 1688 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
| 1669 | + public static function css_primary($color_code,$compatibility){; |
|
| 1670 | + $color_code = sanitize_hex_color($color_code); |
|
| 1671 | + if(!$color_code){return '';} |
|
| 1672 | + /** |
|
| 1673 | + * c = color, b = background color, o = border-color, f = fill |
|
| 1674 | + */ |
|
| 1675 | + $selectors = array( |
|
| 1676 | + 'a' => array('c'), |
|
| 1677 | + '.btn-primary' => array('b','o'), |
|
| 1678 | + '.btn-primary.disabled' => array('b','o'), |
|
| 1679 | + '.btn-primary:disabled' => array('b','o'), |
|
| 1680 | + '.btn-outline-primary' => array('c','o'), |
|
| 1681 | + '.btn-outline-primary:hover' => array('b','o'), |
|
| 1682 | + '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
| 1683 | + '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
| 1684 | + '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
| 1685 | + '.btn-link' => array('c'), |
|
| 1686 | + '.dropdown-item.active' => array('b'), |
|
| 1687 | + '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
| 1688 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
| 1689 | 1689 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
| 1690 | 1690 | // '.custom-range::-moz-range-thumb' => array('b'), |
| 1691 | 1691 | // '.custom-range::-ms-thumb' => array('b'), |
| 1692 | - '.nav-pills .nav-link.active' => array('b'), |
|
| 1693 | - '.nav-pills .show>.nav-link' => array('b'), |
|
| 1694 | - '.page-link' => array('c'), |
|
| 1695 | - '.page-item.active .page-link' => array('b','o'), |
|
| 1696 | - '.badge-primary' => array('b'), |
|
| 1697 | - '.alert-primary' => array('b','o'), |
|
| 1698 | - '.progress-bar' => array('b'), |
|
| 1699 | - '.list-group-item.active' => array('b','o'), |
|
| 1700 | - '.bg-primary' => array('b','f'), |
|
| 1701 | - '.btn-link.btn-primary' => array('c'), |
|
| 1702 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
| 1703 | - ); |
|
| 1704 | - |
|
| 1705 | - $important_selectors = array( |
|
| 1706 | - '.bg-primary' => array('b','f'), |
|
| 1707 | - '.border-primary' => array('o'), |
|
| 1708 | - '.text-primary' => array('c'), |
|
| 1709 | - ); |
|
| 1710 | - |
|
| 1711 | - $color = array(); |
|
| 1712 | - $color_i = array(); |
|
| 1713 | - $background = array(); |
|
| 1714 | - $background_i = array(); |
|
| 1715 | - $border = array(); |
|
| 1716 | - $border_i = array(); |
|
| 1717 | - $fill = array(); |
|
| 1718 | - $fill_i = array(); |
|
| 1719 | - |
|
| 1720 | - $output = ''; |
|
| 1721 | - |
|
| 1722 | - // build rules into each type |
|
| 1723 | - foreach($selectors as $selector => $types){ |
|
| 1724 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1725 | - $types = array_combine($types,$types); |
|
| 1726 | - if(isset($types['c'])){$color[] = $selector;} |
|
| 1727 | - if(isset($types['b'])){$background[] = $selector;} |
|
| 1728 | - if(isset($types['o'])){$border[] = $selector;} |
|
| 1729 | - if(isset($types['f'])){$fill[] = $selector;} |
|
| 1730 | - } |
|
| 1731 | - |
|
| 1732 | - // build rules into each type |
|
| 1733 | - foreach($important_selectors as $selector => $types){ |
|
| 1734 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1735 | - $types = array_combine($types,$types); |
|
| 1736 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
| 1737 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
| 1738 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
| 1739 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - // add any color rules |
|
| 1743 | - if(!empty($color)){ |
|
| 1744 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
| 1745 | - } |
|
| 1746 | - if(!empty($color_i)){ |
|
| 1747 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
| 1748 | - } |
|
| 1749 | - |
|
| 1750 | - // add any background color rules |
|
| 1751 | - if(!empty($background)){ |
|
| 1752 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
| 1753 | - } |
|
| 1754 | - if(!empty($background_i)){ |
|
| 1755 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
| 1756 | - } |
|
| 1757 | - |
|
| 1758 | - // add any border color rules |
|
| 1759 | - if(!empty($border)){ |
|
| 1760 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
| 1761 | - } |
|
| 1762 | - if(!empty($border_i)){ |
|
| 1763 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - // add any fill color rules |
|
| 1767 | - if(!empty($fill)){ |
|
| 1768 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
| 1769 | - } |
|
| 1770 | - if(!empty($fill_i)){ |
|
| 1771 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
| 1772 | - } |
|
| 1773 | - |
|
| 1774 | - |
|
| 1775 | - $prefix = $compatibility ? ".bsui " : ""; |
|
| 1776 | - |
|
| 1777 | - // darken |
|
| 1778 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
| 1779 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
| 1780 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
| 1781 | - |
|
| 1782 | - // lighten |
|
| 1783 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
| 1784 | - |
|
| 1785 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
| 1786 | - $op_25 = $color_code."40"; // 25% opacity |
|
| 1787 | - |
|
| 1788 | - |
|
| 1789 | - // button states |
|
| 1790 | - $output .= $prefix ." .btn-primary:hover, $prefix .btn-primary:focus, $prefix .btn-primary.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
| 1791 | - $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1792 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
| 1793 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1794 | - |
|
| 1795 | - |
|
| 1796 | - // dropdown's |
|
| 1797 | - $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - // input states |
|
| 1801 | - $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1802 | - |
|
| 1803 | - // page link |
|
| 1804 | - $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1805 | - |
|
| 1806 | - return $output; |
|
| 1807 | - } |
|
| 1692 | + '.nav-pills .nav-link.active' => array('b'), |
|
| 1693 | + '.nav-pills .show>.nav-link' => array('b'), |
|
| 1694 | + '.page-link' => array('c'), |
|
| 1695 | + '.page-item.active .page-link' => array('b','o'), |
|
| 1696 | + '.badge-primary' => array('b'), |
|
| 1697 | + '.alert-primary' => array('b','o'), |
|
| 1698 | + '.progress-bar' => array('b'), |
|
| 1699 | + '.list-group-item.active' => array('b','o'), |
|
| 1700 | + '.bg-primary' => array('b','f'), |
|
| 1701 | + '.btn-link.btn-primary' => array('c'), |
|
| 1702 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
| 1703 | + ); |
|
| 1704 | + |
|
| 1705 | + $important_selectors = array( |
|
| 1706 | + '.bg-primary' => array('b','f'), |
|
| 1707 | + '.border-primary' => array('o'), |
|
| 1708 | + '.text-primary' => array('c'), |
|
| 1709 | + ); |
|
| 1710 | + |
|
| 1711 | + $color = array(); |
|
| 1712 | + $color_i = array(); |
|
| 1713 | + $background = array(); |
|
| 1714 | + $background_i = array(); |
|
| 1715 | + $border = array(); |
|
| 1716 | + $border_i = array(); |
|
| 1717 | + $fill = array(); |
|
| 1718 | + $fill_i = array(); |
|
| 1719 | + |
|
| 1720 | + $output = ''; |
|
| 1721 | + |
|
| 1722 | + // build rules into each type |
|
| 1723 | + foreach($selectors as $selector => $types){ |
|
| 1724 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1725 | + $types = array_combine($types,$types); |
|
| 1726 | + if(isset($types['c'])){$color[] = $selector;} |
|
| 1727 | + if(isset($types['b'])){$background[] = $selector;} |
|
| 1728 | + if(isset($types['o'])){$border[] = $selector;} |
|
| 1729 | + if(isset($types['f'])){$fill[] = $selector;} |
|
| 1730 | + } |
|
| 1808 | 1731 | |
| 1809 | - public static function css_secondary($color_code,$compatibility){; |
|
| 1810 | - $color_code = sanitize_hex_color($color_code); |
|
| 1811 | - if(!$color_code){return '';} |
|
| 1812 | - /** |
|
| 1813 | - * c = color, b = background color, o = border-color, f = fill |
|
| 1814 | - */ |
|
| 1815 | - $selectors = array( |
|
| 1816 | - '.btn-secondary' => array('b','o'), |
|
| 1817 | - '.btn-secondary.disabled' => array('b','o'), |
|
| 1818 | - '.btn-secondary:disabled' => array('b','o'), |
|
| 1819 | - '.btn-outline-secondary' => array('c','o'), |
|
| 1820 | - '.btn-outline-secondary:hover' => array('b','o'), |
|
| 1821 | - '.btn-outline-secondary.disabled' => array('c'), |
|
| 1822 | - '.btn-outline-secondary:disabled' => array('c'), |
|
| 1823 | - '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
| 1824 | - '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
| 1825 | - '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
| 1826 | - '.badge-secondary' => array('b'), |
|
| 1827 | - '.alert-secondary' => array('b','o'), |
|
| 1828 | - '.btn-link.btn-secondary' => array('c'), |
|
| 1829 | - ); |
|
| 1830 | - |
|
| 1831 | - $important_selectors = array( |
|
| 1832 | - '.bg-secondary' => array('b','f'), |
|
| 1833 | - '.border-secondary' => array('o'), |
|
| 1834 | - '.text-secondary' => array('c'), |
|
| 1835 | - ); |
|
| 1836 | - |
|
| 1837 | - $color = array(); |
|
| 1838 | - $color_i = array(); |
|
| 1839 | - $background = array(); |
|
| 1840 | - $background_i = array(); |
|
| 1841 | - $border = array(); |
|
| 1842 | - $border_i = array(); |
|
| 1843 | - $fill = array(); |
|
| 1844 | - $fill_i = array(); |
|
| 1845 | - |
|
| 1846 | - $output = ''; |
|
| 1847 | - |
|
| 1848 | - // build rules into each type |
|
| 1849 | - foreach($selectors as $selector => $types){ |
|
| 1850 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1851 | - $types = array_combine($types,$types); |
|
| 1852 | - if(isset($types['c'])){$color[] = $selector;} |
|
| 1853 | - if(isset($types['b'])){$background[] = $selector;} |
|
| 1854 | - if(isset($types['o'])){$border[] = $selector;} |
|
| 1855 | - if(isset($types['f'])){$fill[] = $selector;} |
|
| 1856 | - } |
|
| 1857 | - |
|
| 1858 | - // build rules into each type |
|
| 1859 | - foreach($important_selectors as $selector => $types){ |
|
| 1860 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1861 | - $types = array_combine($types,$types); |
|
| 1862 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
| 1863 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
| 1864 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
| 1865 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
| 1866 | - } |
|
| 1867 | - |
|
| 1868 | - // add any color rules |
|
| 1869 | - if(!empty($color)){ |
|
| 1870 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
| 1871 | - } |
|
| 1872 | - if(!empty($color_i)){ |
|
| 1873 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
| 1874 | - } |
|
| 1875 | - |
|
| 1876 | - // add any background color rules |
|
| 1877 | - if(!empty($background)){ |
|
| 1878 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
| 1879 | - } |
|
| 1880 | - if(!empty($background_i)){ |
|
| 1881 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
| 1882 | - } |
|
| 1883 | - |
|
| 1884 | - // add any border color rules |
|
| 1885 | - if(!empty($border)){ |
|
| 1886 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
| 1887 | - } |
|
| 1888 | - if(!empty($border_i)){ |
|
| 1889 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
| 1890 | - } |
|
| 1891 | - |
|
| 1892 | - // add any fill color rules |
|
| 1893 | - if(!empty($fill)){ |
|
| 1894 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
| 1895 | - } |
|
| 1896 | - if(!empty($fill_i)){ |
|
| 1897 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
| 1898 | - } |
|
| 1899 | - |
|
| 1900 | - |
|
| 1901 | - $prefix = $compatibility ? ".bsui " : ""; |
|
| 1902 | - |
|
| 1903 | - // darken |
|
| 1904 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
| 1905 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
| 1906 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
| 1907 | - |
|
| 1908 | - // lighten |
|
| 1909 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
| 1910 | - |
|
| 1911 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
| 1912 | - $op_25 = $color_code."40"; // 25% opacity |
|
| 1913 | - |
|
| 1914 | - |
|
| 1915 | - // button states |
|
| 1916 | - $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
| 1917 | - $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1918 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
| 1919 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1920 | - |
|
| 1921 | - |
|
| 1922 | - return $output; |
|
| 1923 | - } |
|
| 1732 | + // build rules into each type |
|
| 1733 | + foreach($important_selectors as $selector => $types){ |
|
| 1734 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1735 | + $types = array_combine($types,$types); |
|
| 1736 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
| 1737 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
| 1738 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
| 1739 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
| 1740 | + } |
|
| 1924 | 1741 | |
| 1925 | - /** |
|
| 1926 | - * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
| 1927 | - * |
|
| 1928 | - * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
| 1929 | - * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
| 1930 | - * |
|
| 1931 | - * @return string |
|
| 1932 | - */ |
|
| 1933 | - public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
| 1934 | - $hexCode = ltrim($hexCode, '#'); |
|
| 1742 | + // add any color rules |
|
| 1743 | + if(!empty($color)){ |
|
| 1744 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
| 1745 | + } |
|
| 1746 | + if(!empty($color_i)){ |
|
| 1747 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
| 1748 | + } |
|
| 1935 | 1749 | |
| 1936 | - if (strlen($hexCode) == 3) { |
|
| 1937 | - $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
| 1938 | - } |
|
| 1750 | + // add any background color rules |
|
| 1751 | + if(!empty($background)){ |
|
| 1752 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
| 1753 | + } |
|
| 1754 | + if(!empty($background_i)){ |
|
| 1755 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
| 1756 | + } |
|
| 1939 | 1757 | |
| 1940 | - $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
| 1758 | + // add any border color rules |
|
| 1759 | + if(!empty($border)){ |
|
| 1760 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
| 1761 | + } |
|
| 1762 | + if(!empty($border_i)){ |
|
| 1763 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
| 1764 | + } |
|
| 1941 | 1765 | |
| 1942 | - foreach ($hexCode as & $color) { |
|
| 1943 | - $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
| 1944 | - $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
| 1766 | + // add any fill color rules |
|
| 1767 | + if(!empty($fill)){ |
|
| 1768 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
| 1769 | + } |
|
| 1770 | + if(!empty($fill_i)){ |
|
| 1771 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
| 1772 | + } |
|
| 1945 | 1773 | |
| 1946 | - $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
| 1947 | - } |
|
| 1948 | 1774 | |
| 1949 | - return '#' . implode($hexCode); |
|
| 1950 | - } |
|
| 1775 | + $prefix = $compatibility ? ".bsui " : ""; |
|
| 1951 | 1776 | |
| 1952 | - /** |
|
| 1953 | - * Check if we should display examples. |
|
| 1954 | - */ |
|
| 1955 | - public function maybe_show_examples(){ |
|
| 1956 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
| 1957 | - echo "<head>"; |
|
| 1958 | - wp_head(); |
|
| 1959 | - echo "</head>"; |
|
| 1960 | - echo "<body>"; |
|
| 1961 | - echo $this->get_examples(); |
|
| 1962 | - echo "</body>"; |
|
| 1963 | - exit; |
|
| 1964 | - } |
|
| 1965 | - } |
|
| 1777 | + // darken |
|
| 1778 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
| 1779 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
| 1780 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
| 1966 | 1781 | |
| 1967 | - /** |
|
| 1968 | - * Get developer examples. |
|
| 1969 | - * |
|
| 1970 | - * @return string |
|
| 1971 | - */ |
|
| 1972 | - public function get_examples(){ |
|
| 1973 | - $output = ''; |
|
| 1974 | - |
|
| 1975 | - |
|
| 1976 | - // open form |
|
| 1977 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
| 1978 | - |
|
| 1979 | - // input example |
|
| 1980 | - $output .= aui()->input(array( |
|
| 1981 | - 'type' => 'text', |
|
| 1982 | - 'id' => 'text-example', |
|
| 1983 | - 'name' => 'text-example', |
|
| 1984 | - 'placeholder' => 'text placeholder', |
|
| 1985 | - 'title' => 'Text input example', |
|
| 1986 | - 'value' => '', |
|
| 1987 | - 'required' => false, |
|
| 1988 | - 'help_text' => 'help text', |
|
| 1989 | - 'label' => 'Text input example label' |
|
| 1990 | - )); |
|
| 1991 | - |
|
| 1992 | - // input example |
|
| 1993 | - $output .= aui()->input(array( |
|
| 1994 | - 'type' => 'url', |
|
| 1995 | - 'id' => 'text-example2', |
|
| 1996 | - 'name' => 'text-example', |
|
| 1997 | - 'placeholder' => 'url placeholder', |
|
| 1998 | - 'title' => 'Text input example', |
|
| 1999 | - 'value' => '', |
|
| 2000 | - 'required' => false, |
|
| 2001 | - 'help_text' => 'help text', |
|
| 2002 | - 'label' => 'Text input example label' |
|
| 2003 | - )); |
|
| 2004 | - |
|
| 2005 | - // checkbox example |
|
| 2006 | - $output .= aui()->input(array( |
|
| 2007 | - 'type' => 'checkbox', |
|
| 2008 | - 'id' => 'checkbox-example', |
|
| 2009 | - 'name' => 'checkbox-example', |
|
| 2010 | - 'placeholder' => 'checkbox-example', |
|
| 2011 | - 'title' => 'Checkbox example', |
|
| 2012 | - 'value' => '1', |
|
| 2013 | - 'checked' => true, |
|
| 2014 | - 'required' => false, |
|
| 2015 | - 'help_text' => 'help text', |
|
| 2016 | - 'label' => 'Checkbox checked' |
|
| 2017 | - )); |
|
| 2018 | - |
|
| 2019 | - // checkbox example |
|
| 2020 | - $output .= aui()->input(array( |
|
| 2021 | - 'type' => 'checkbox', |
|
| 2022 | - 'id' => 'checkbox-example2', |
|
| 2023 | - 'name' => 'checkbox-example2', |
|
| 2024 | - 'placeholder' => 'checkbox-example', |
|
| 2025 | - 'title' => 'Checkbox example', |
|
| 2026 | - 'value' => '1', |
|
| 2027 | - 'checked' => false, |
|
| 2028 | - 'required' => false, |
|
| 2029 | - 'help_text' => 'help text', |
|
| 2030 | - 'label' => 'Checkbox un-checked' |
|
| 2031 | - )); |
|
| 2032 | - |
|
| 2033 | - // switch example |
|
| 2034 | - $output .= aui()->input(array( |
|
| 2035 | - 'type' => 'checkbox', |
|
| 2036 | - 'id' => 'switch-example', |
|
| 2037 | - 'name' => 'switch-example', |
|
| 2038 | - 'placeholder' => 'checkbox-example', |
|
| 2039 | - 'title' => 'Switch example', |
|
| 2040 | - 'value' => '1', |
|
| 2041 | - 'checked' => true, |
|
| 2042 | - 'switch' => true, |
|
| 2043 | - 'required' => false, |
|
| 2044 | - 'help_text' => 'help text', |
|
| 2045 | - 'label' => 'Switch on' |
|
| 2046 | - )); |
|
| 2047 | - |
|
| 2048 | - // switch example |
|
| 2049 | - $output .= aui()->input(array( |
|
| 2050 | - 'type' => 'checkbox', |
|
| 2051 | - 'id' => 'switch-example2', |
|
| 2052 | - 'name' => 'switch-example2', |
|
| 2053 | - 'placeholder' => 'checkbox-example', |
|
| 2054 | - 'title' => 'Switch example', |
|
| 2055 | - 'value' => '1', |
|
| 2056 | - 'checked' => false, |
|
| 2057 | - 'switch' => true, |
|
| 2058 | - 'required' => false, |
|
| 2059 | - 'help_text' => 'help text', |
|
| 2060 | - 'label' => 'Switch off' |
|
| 2061 | - )); |
|
| 2062 | - |
|
| 2063 | - // close form |
|
| 2064 | - $output .= "</form>"; |
|
| 2065 | - |
|
| 2066 | - return $output; |
|
| 2067 | - } |
|
| 1782 | + // lighten |
|
| 1783 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
| 2068 | 1784 | |
| 2069 | - /** |
|
| 2070 | - * Calendar params. |
|
| 2071 | - * |
|
| 2072 | - * @since 0.1.44 |
|
| 2073 | - * |
|
| 2074 | - * @return array Calendar params. |
|
| 2075 | - */ |
|
| 2076 | - public static function calendar_params() { |
|
| 2077 | - $params = array( |
|
| 2078 | - 'month_long_1' => __( 'January', 'aui' ), |
|
| 2079 | - 'month_long_2' => __( 'February', 'aui' ), |
|
| 2080 | - 'month_long_3' => __( 'March', 'aui' ), |
|
| 2081 | - 'month_long_4' => __( 'April', 'aui' ), |
|
| 2082 | - 'month_long_5' => __( 'May', 'aui' ), |
|
| 2083 | - 'month_long_6' => __( 'June', 'aui' ), |
|
| 2084 | - 'month_long_7' => __( 'July', 'aui' ), |
|
| 2085 | - 'month_long_8' => __( 'August', 'aui' ), |
|
| 2086 | - 'month_long_9' => __( 'September', 'aui' ), |
|
| 2087 | - 'month_long_10' => __( 'October', 'aui' ), |
|
| 2088 | - 'month_long_11' => __( 'November', 'aui' ), |
|
| 2089 | - 'month_long_12' => __( 'December', 'aui' ), |
|
| 2090 | - 'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ), |
|
| 2091 | - 'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ), |
|
| 2092 | - 'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ), |
|
| 2093 | - 'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ), |
|
| 2094 | - 'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ), |
|
| 2095 | - 'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ), |
|
| 2096 | - 'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ), |
|
| 2097 | - 'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ), |
|
| 2098 | - 'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ), |
|
| 2099 | - 'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ), |
|
| 2100 | - 'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ), |
|
| 2101 | - 'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ), |
|
| 2102 | - 'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ), |
|
| 2103 | - 'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ), |
|
| 2104 | - 'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ), |
|
| 2105 | - 'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ), |
|
| 2106 | - 'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ), |
|
| 2107 | - 'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ), |
|
| 2108 | - 'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ), |
|
| 2109 | - 'day_s2_1' => __( 'Su', 'aui' ), |
|
| 2110 | - 'day_s2_2' => __( 'Mo', 'aui' ), |
|
| 2111 | - 'day_s2_3' => __( 'Tu', 'aui' ), |
|
| 2112 | - 'day_s2_4' => __( 'We', 'aui' ), |
|
| 2113 | - 'day_s2_5' => __( 'Th', 'aui' ), |
|
| 2114 | - 'day_s2_6' => __( 'Fr', 'aui' ), |
|
| 2115 | - 'day_s2_7' => __( 'Sa', 'aui' ), |
|
| 2116 | - 'day_s3_1' => __( 'Sun', 'aui' ), |
|
| 2117 | - 'day_s3_2' => __( 'Mon', 'aui' ), |
|
| 2118 | - 'day_s3_3' => __( 'Tue', 'aui' ), |
|
| 2119 | - 'day_s3_4' => __( 'Wed', 'aui' ), |
|
| 2120 | - 'day_s3_5' => __( 'Thu', 'aui' ), |
|
| 2121 | - 'day_s3_6' => __( 'Fri', 'aui' ), |
|
| 2122 | - 'day_s3_7' => __( 'Sat', 'aui' ), |
|
| 2123 | - 'day_s5_1' => __( 'Sunday', 'aui' ), |
|
| 2124 | - 'day_s5_2' => __( 'Monday', 'aui' ), |
|
| 2125 | - 'day_s5_3' => __( 'Tuesday', 'aui' ), |
|
| 2126 | - 'day_s5_4' => __( 'Wednesday', 'aui' ), |
|
| 2127 | - 'day_s5_5' => __( 'Thursday', 'aui' ), |
|
| 2128 | - 'day_s5_6' => __( 'Friday', 'aui' ), |
|
| 2129 | - 'day_s5_7' => __( 'Saturday', 'aui' ), |
|
| 2130 | - 'am_lower' => __( 'am', 'aui' ), |
|
| 2131 | - 'pm_lower' => __( 'pm', 'aui' ), |
|
| 2132 | - 'am_upper' => __( 'AM', 'aui' ), |
|
| 2133 | - 'pm_upper' => __( 'PM', 'aui' ), |
|
| 2134 | - 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
|
| 2135 | - 'time_24hr' => false, |
|
| 2136 | - 'year' => __( 'Year', 'aui' ), |
|
| 2137 | - 'hour' => __( 'Hour', 'aui' ), |
|
| 2138 | - 'minute' => __( 'Minute', 'aui' ), |
|
| 2139 | - 'weekAbbreviation' => __( 'Wk', 'aui' ), |
|
| 2140 | - 'rangeSeparator' => __( ' to ', 'aui' ), |
|
| 2141 | - 'scrollTitle' => __( 'Scroll to increment', 'aui' ), |
|
| 2142 | - 'toggleTitle' => __( 'Click to toggle', 'aui' ) |
|
| 2143 | - ); |
|
| 2144 | - |
|
| 2145 | - return apply_filters( 'ayecode_ui_calendar_params', $params ); |
|
| 2146 | - } |
|
| 1785 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
| 1786 | + $op_25 = $color_code."40"; // 25% opacity |
|
| 2147 | 1787 | |
| 2148 | - /** |
|
| 2149 | - * Flatpickr calendar localize. |
|
| 2150 | - * |
|
| 2151 | - * @since 0.1.44 |
|
| 2152 | - * |
|
| 2153 | - * @return string Calendar locale. |
|
| 2154 | - */ |
|
| 2155 | - public static function flatpickr_locale() { |
|
| 2156 | - $params = self::calendar_params(); |
|
| 2157 | - |
|
| 2158 | - if ( is_string( $params ) ) { |
|
| 2159 | - $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
|
| 2160 | - } else { |
|
| 2161 | - foreach ( (array) $params as $key => $value ) { |
|
| 2162 | - if ( ! is_scalar( $value ) ) { |
|
| 2163 | - continue; |
|
| 2164 | - } |
|
| 2165 | 1788 | |
| 2166 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
| 2167 | - } |
|
| 2168 | - } |
|
| 1789 | + // button states |
|
| 1790 | + $output .= $prefix ." .btn-primary:hover, $prefix .btn-primary:focus, $prefix .btn-primary.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
| 1791 | + $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1792 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
| 1793 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + // dropdown's |
|
| 1797 | + $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + // input states |
|
| 1801 | + $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1802 | + |
|
| 1803 | + // page link |
|
| 1804 | + $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1805 | + |
|
| 1806 | + return $output; |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + public static function css_secondary($color_code,$compatibility){; |
|
| 1810 | + $color_code = sanitize_hex_color($color_code); |
|
| 1811 | + if(!$color_code){return '';} |
|
| 1812 | + /** |
|
| 1813 | + * c = color, b = background color, o = border-color, f = fill |
|
| 1814 | + */ |
|
| 1815 | + $selectors = array( |
|
| 1816 | + '.btn-secondary' => array('b','o'), |
|
| 1817 | + '.btn-secondary.disabled' => array('b','o'), |
|
| 1818 | + '.btn-secondary:disabled' => array('b','o'), |
|
| 1819 | + '.btn-outline-secondary' => array('c','o'), |
|
| 1820 | + '.btn-outline-secondary:hover' => array('b','o'), |
|
| 1821 | + '.btn-outline-secondary.disabled' => array('c'), |
|
| 1822 | + '.btn-outline-secondary:disabled' => array('c'), |
|
| 1823 | + '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
| 1824 | + '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
| 1825 | + '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
| 1826 | + '.badge-secondary' => array('b'), |
|
| 1827 | + '.alert-secondary' => array('b','o'), |
|
| 1828 | + '.btn-link.btn-secondary' => array('c'), |
|
| 1829 | + ); |
|
| 1830 | + |
|
| 1831 | + $important_selectors = array( |
|
| 1832 | + '.bg-secondary' => array('b','f'), |
|
| 1833 | + '.border-secondary' => array('o'), |
|
| 1834 | + '.text-secondary' => array('c'), |
|
| 1835 | + ); |
|
| 1836 | + |
|
| 1837 | + $color = array(); |
|
| 1838 | + $color_i = array(); |
|
| 1839 | + $background = array(); |
|
| 1840 | + $background_i = array(); |
|
| 1841 | + $border = array(); |
|
| 1842 | + $border_i = array(); |
|
| 1843 | + $fill = array(); |
|
| 1844 | + $fill_i = array(); |
|
| 1845 | + |
|
| 1846 | + $output = ''; |
|
| 1847 | + |
|
| 1848 | + // build rules into each type |
|
| 1849 | + foreach($selectors as $selector => $types){ |
|
| 1850 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1851 | + $types = array_combine($types,$types); |
|
| 1852 | + if(isset($types['c'])){$color[] = $selector;} |
|
| 1853 | + if(isset($types['b'])){$background[] = $selector;} |
|
| 1854 | + if(isset($types['o'])){$border[] = $selector;} |
|
| 1855 | + if(isset($types['f'])){$fill[] = $selector;} |
|
| 1856 | + } |
|
| 1857 | + |
|
| 1858 | + // build rules into each type |
|
| 1859 | + foreach($important_selectors as $selector => $types){ |
|
| 1860 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1861 | + $types = array_combine($types,$types); |
|
| 1862 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
| 1863 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
| 1864 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
| 1865 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
| 1866 | + } |
|
| 1867 | + |
|
| 1868 | + // add any color rules |
|
| 1869 | + if(!empty($color)){ |
|
| 1870 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
| 1871 | + } |
|
| 1872 | + if(!empty($color_i)){ |
|
| 1873 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
| 1874 | + } |
|
| 1875 | + |
|
| 1876 | + // add any background color rules |
|
| 1877 | + if(!empty($background)){ |
|
| 1878 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
| 1879 | + } |
|
| 1880 | + if(!empty($background_i)){ |
|
| 1881 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
| 1882 | + } |
|
| 1883 | + |
|
| 1884 | + // add any border color rules |
|
| 1885 | + if(!empty($border)){ |
|
| 1886 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
| 1887 | + } |
|
| 1888 | + if(!empty($border_i)){ |
|
| 1889 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
| 1890 | + } |
|
| 1891 | + |
|
| 1892 | + // add any fill color rules |
|
| 1893 | + if(!empty($fill)){ |
|
| 1894 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
| 1895 | + } |
|
| 1896 | + if(!empty($fill_i)){ |
|
| 1897 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
| 1898 | + } |
|
| 1899 | + |
|
| 1900 | + |
|
| 1901 | + $prefix = $compatibility ? ".bsui " : ""; |
|
| 1902 | + |
|
| 1903 | + // darken |
|
| 1904 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
| 1905 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
| 1906 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
| 1907 | + |
|
| 1908 | + // lighten |
|
| 1909 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
| 1910 | + |
|
| 1911 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
| 1912 | + $op_25 = $color_code."40"; // 25% opacity |
|
| 2169 | 1913 | |
| 2170 | - $day_s3 = array(); |
|
| 2171 | - $day_s5 = array(); |
|
| 2172 | 1914 | |
| 2173 | - for ( $i = 1; $i <= 7; $i ++ ) { |
|
| 2174 | - $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
| 2175 | - $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
| 2176 | - } |
|
| 1915 | + // button states |
|
| 1916 | + $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
| 1917 | + $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1918 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
| 1919 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 2177 | 1920 | |
| 2178 | - $month_s = array(); |
|
| 2179 | - $month_long = array(); |
|
| 2180 | 1921 | |
| 2181 | - for ( $i = 1; $i <= 12; $i ++ ) { |
|
| 2182 | - $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); |
|
| 2183 | - $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); |
|
| 2184 | - } |
|
| 1922 | + return $output; |
|
| 1923 | + } |
|
| 1924 | + |
|
| 1925 | + /** |
|
| 1926 | + * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
| 1927 | + * |
|
| 1928 | + * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
| 1929 | + * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
| 1930 | + * |
|
| 1931 | + * @return string |
|
| 1932 | + */ |
|
| 1933 | + public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
| 1934 | + $hexCode = ltrim($hexCode, '#'); |
|
| 1935 | + |
|
| 1936 | + if (strlen($hexCode) == 3) { |
|
| 1937 | + $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
| 1938 | + } |
|
| 1939 | + |
|
| 1940 | + $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
| 1941 | + |
|
| 1942 | + foreach ($hexCode as & $color) { |
|
| 1943 | + $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
| 1944 | + $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
| 1945 | + |
|
| 1946 | + $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
| 1947 | + } |
|
| 1948 | + |
|
| 1949 | + return '#' . implode($hexCode); |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + /** |
|
| 1953 | + * Check if we should display examples. |
|
| 1954 | + */ |
|
| 1955 | + public function maybe_show_examples(){ |
|
| 1956 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
| 1957 | + echo "<head>"; |
|
| 1958 | + wp_head(); |
|
| 1959 | + echo "</head>"; |
|
| 1960 | + echo "<body>"; |
|
| 1961 | + echo $this->get_examples(); |
|
| 1962 | + echo "</body>"; |
|
| 1963 | + exit; |
|
| 1964 | + } |
|
| 1965 | + } |
|
| 1966 | + |
|
| 1967 | + /** |
|
| 1968 | + * Get developer examples. |
|
| 1969 | + * |
|
| 1970 | + * @return string |
|
| 1971 | + */ |
|
| 1972 | + public function get_examples(){ |
|
| 1973 | + $output = ''; |
|
| 1974 | + |
|
| 1975 | + |
|
| 1976 | + // open form |
|
| 1977 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
| 1978 | + |
|
| 1979 | + // input example |
|
| 1980 | + $output .= aui()->input(array( |
|
| 1981 | + 'type' => 'text', |
|
| 1982 | + 'id' => 'text-example', |
|
| 1983 | + 'name' => 'text-example', |
|
| 1984 | + 'placeholder' => 'text placeholder', |
|
| 1985 | + 'title' => 'Text input example', |
|
| 1986 | + 'value' => '', |
|
| 1987 | + 'required' => false, |
|
| 1988 | + 'help_text' => 'help text', |
|
| 1989 | + 'label' => 'Text input example label' |
|
| 1990 | + )); |
|
| 1991 | + |
|
| 1992 | + // input example |
|
| 1993 | + $output .= aui()->input(array( |
|
| 1994 | + 'type' => 'url', |
|
| 1995 | + 'id' => 'text-example2', |
|
| 1996 | + 'name' => 'text-example', |
|
| 1997 | + 'placeholder' => 'url placeholder', |
|
| 1998 | + 'title' => 'Text input example', |
|
| 1999 | + 'value' => '', |
|
| 2000 | + 'required' => false, |
|
| 2001 | + 'help_text' => 'help text', |
|
| 2002 | + 'label' => 'Text input example label' |
|
| 2003 | + )); |
|
| 2004 | + |
|
| 2005 | + // checkbox example |
|
| 2006 | + $output .= aui()->input(array( |
|
| 2007 | + 'type' => 'checkbox', |
|
| 2008 | + 'id' => 'checkbox-example', |
|
| 2009 | + 'name' => 'checkbox-example', |
|
| 2010 | + 'placeholder' => 'checkbox-example', |
|
| 2011 | + 'title' => 'Checkbox example', |
|
| 2012 | + 'value' => '1', |
|
| 2013 | + 'checked' => true, |
|
| 2014 | + 'required' => false, |
|
| 2015 | + 'help_text' => 'help text', |
|
| 2016 | + 'label' => 'Checkbox checked' |
|
| 2017 | + )); |
|
| 2018 | + |
|
| 2019 | + // checkbox example |
|
| 2020 | + $output .= aui()->input(array( |
|
| 2021 | + 'type' => 'checkbox', |
|
| 2022 | + 'id' => 'checkbox-example2', |
|
| 2023 | + 'name' => 'checkbox-example2', |
|
| 2024 | + 'placeholder' => 'checkbox-example', |
|
| 2025 | + 'title' => 'Checkbox example', |
|
| 2026 | + 'value' => '1', |
|
| 2027 | + 'checked' => false, |
|
| 2028 | + 'required' => false, |
|
| 2029 | + 'help_text' => 'help text', |
|
| 2030 | + 'label' => 'Checkbox un-checked' |
|
| 2031 | + )); |
|
| 2032 | + |
|
| 2033 | + // switch example |
|
| 2034 | + $output .= aui()->input(array( |
|
| 2035 | + 'type' => 'checkbox', |
|
| 2036 | + 'id' => 'switch-example', |
|
| 2037 | + 'name' => 'switch-example', |
|
| 2038 | + 'placeholder' => 'checkbox-example', |
|
| 2039 | + 'title' => 'Switch example', |
|
| 2040 | + 'value' => '1', |
|
| 2041 | + 'checked' => true, |
|
| 2042 | + 'switch' => true, |
|
| 2043 | + 'required' => false, |
|
| 2044 | + 'help_text' => 'help text', |
|
| 2045 | + 'label' => 'Switch on' |
|
| 2046 | + )); |
|
| 2047 | + |
|
| 2048 | + // switch example |
|
| 2049 | + $output .= aui()->input(array( |
|
| 2050 | + 'type' => 'checkbox', |
|
| 2051 | + 'id' => 'switch-example2', |
|
| 2052 | + 'name' => 'switch-example2', |
|
| 2053 | + 'placeholder' => 'checkbox-example', |
|
| 2054 | + 'title' => 'Switch example', |
|
| 2055 | + 'value' => '1', |
|
| 2056 | + 'checked' => false, |
|
| 2057 | + 'switch' => true, |
|
| 2058 | + 'required' => false, |
|
| 2059 | + 'help_text' => 'help text', |
|
| 2060 | + 'label' => 'Switch off' |
|
| 2061 | + )); |
|
| 2062 | + |
|
| 2063 | + // close form |
|
| 2064 | + $output .= "</form>"; |
|
| 2065 | + |
|
| 2066 | + return $output; |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + /** |
|
| 2070 | + * Calendar params. |
|
| 2071 | + * |
|
| 2072 | + * @since 0.1.44 |
|
| 2073 | + * |
|
| 2074 | + * @return array Calendar params. |
|
| 2075 | + */ |
|
| 2076 | + public static function calendar_params() { |
|
| 2077 | + $params = array( |
|
| 2078 | + 'month_long_1' => __( 'January', 'aui' ), |
|
| 2079 | + 'month_long_2' => __( 'February', 'aui' ), |
|
| 2080 | + 'month_long_3' => __( 'March', 'aui' ), |
|
| 2081 | + 'month_long_4' => __( 'April', 'aui' ), |
|
| 2082 | + 'month_long_5' => __( 'May', 'aui' ), |
|
| 2083 | + 'month_long_6' => __( 'June', 'aui' ), |
|
| 2084 | + 'month_long_7' => __( 'July', 'aui' ), |
|
| 2085 | + 'month_long_8' => __( 'August', 'aui' ), |
|
| 2086 | + 'month_long_9' => __( 'September', 'aui' ), |
|
| 2087 | + 'month_long_10' => __( 'October', 'aui' ), |
|
| 2088 | + 'month_long_11' => __( 'November', 'aui' ), |
|
| 2089 | + 'month_long_12' => __( 'December', 'aui' ), |
|
| 2090 | + 'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ), |
|
| 2091 | + 'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ), |
|
| 2092 | + 'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ), |
|
| 2093 | + 'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ), |
|
| 2094 | + 'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ), |
|
| 2095 | + 'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ), |
|
| 2096 | + 'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ), |
|
| 2097 | + 'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ), |
|
| 2098 | + 'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ), |
|
| 2099 | + 'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ), |
|
| 2100 | + 'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ), |
|
| 2101 | + 'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ), |
|
| 2102 | + 'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ), |
|
| 2103 | + 'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ), |
|
| 2104 | + 'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ), |
|
| 2105 | + 'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ), |
|
| 2106 | + 'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ), |
|
| 2107 | + 'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ), |
|
| 2108 | + 'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ), |
|
| 2109 | + 'day_s2_1' => __( 'Su', 'aui' ), |
|
| 2110 | + 'day_s2_2' => __( 'Mo', 'aui' ), |
|
| 2111 | + 'day_s2_3' => __( 'Tu', 'aui' ), |
|
| 2112 | + 'day_s2_4' => __( 'We', 'aui' ), |
|
| 2113 | + 'day_s2_5' => __( 'Th', 'aui' ), |
|
| 2114 | + 'day_s2_6' => __( 'Fr', 'aui' ), |
|
| 2115 | + 'day_s2_7' => __( 'Sa', 'aui' ), |
|
| 2116 | + 'day_s3_1' => __( 'Sun', 'aui' ), |
|
| 2117 | + 'day_s3_2' => __( 'Mon', 'aui' ), |
|
| 2118 | + 'day_s3_3' => __( 'Tue', 'aui' ), |
|
| 2119 | + 'day_s3_4' => __( 'Wed', 'aui' ), |
|
| 2120 | + 'day_s3_5' => __( 'Thu', 'aui' ), |
|
| 2121 | + 'day_s3_6' => __( 'Fri', 'aui' ), |
|
| 2122 | + 'day_s3_7' => __( 'Sat', 'aui' ), |
|
| 2123 | + 'day_s5_1' => __( 'Sunday', 'aui' ), |
|
| 2124 | + 'day_s5_2' => __( 'Monday', 'aui' ), |
|
| 2125 | + 'day_s5_3' => __( 'Tuesday', 'aui' ), |
|
| 2126 | + 'day_s5_4' => __( 'Wednesday', 'aui' ), |
|
| 2127 | + 'day_s5_5' => __( 'Thursday', 'aui' ), |
|
| 2128 | + 'day_s5_6' => __( 'Friday', 'aui' ), |
|
| 2129 | + 'day_s5_7' => __( 'Saturday', 'aui' ), |
|
| 2130 | + 'am_lower' => __( 'am', 'aui' ), |
|
| 2131 | + 'pm_lower' => __( 'pm', 'aui' ), |
|
| 2132 | + 'am_upper' => __( 'AM', 'aui' ), |
|
| 2133 | + 'pm_upper' => __( 'PM', 'aui' ), |
|
| 2134 | + 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
|
| 2135 | + 'time_24hr' => false, |
|
| 2136 | + 'year' => __( 'Year', 'aui' ), |
|
| 2137 | + 'hour' => __( 'Hour', 'aui' ), |
|
| 2138 | + 'minute' => __( 'Minute', 'aui' ), |
|
| 2139 | + 'weekAbbreviation' => __( 'Wk', 'aui' ), |
|
| 2140 | + 'rangeSeparator' => __( ' to ', 'aui' ), |
|
| 2141 | + 'scrollTitle' => __( 'Scroll to increment', 'aui' ), |
|
| 2142 | + 'toggleTitle' => __( 'Click to toggle', 'aui' ) |
|
| 2143 | + ); |
|
| 2144 | + |
|
| 2145 | + return apply_filters( 'ayecode_ui_calendar_params', $params ); |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + /** |
|
| 2149 | + * Flatpickr calendar localize. |
|
| 2150 | + * |
|
| 2151 | + * @since 0.1.44 |
|
| 2152 | + * |
|
| 2153 | + * @return string Calendar locale. |
|
| 2154 | + */ |
|
| 2155 | + public static function flatpickr_locale() { |
|
| 2156 | + $params = self::calendar_params(); |
|
| 2157 | + |
|
| 2158 | + if ( is_string( $params ) ) { |
|
| 2159 | + $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
|
| 2160 | + } else { |
|
| 2161 | + foreach ( (array) $params as $key => $value ) { |
|
| 2162 | + if ( ! is_scalar( $value ) ) { |
|
| 2163 | + continue; |
|
| 2164 | + } |
|
| 2165 | + |
|
| 2166 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
| 2167 | + } |
|
| 2168 | + } |
|
| 2169 | + |
|
| 2170 | + $day_s3 = array(); |
|
| 2171 | + $day_s5 = array(); |
|
| 2172 | + |
|
| 2173 | + for ( $i = 1; $i <= 7; $i ++ ) { |
|
| 2174 | + $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
| 2175 | + $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
| 2176 | + } |
|
| 2177 | + |
|
| 2178 | + $month_s = array(); |
|
| 2179 | + $month_long = array(); |
|
| 2180 | + |
|
| 2181 | + for ( $i = 1; $i <= 12; $i ++ ) { |
|
| 2182 | + $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); |
|
| 2183 | + $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); |
|
| 2184 | + } |
|
| 2185 | 2185 | |
| 2186 | 2186 | ob_start(); |
| 2187 | 2187 | if ( 0 ) { ?><script><?php } ?> |
@@ -2223,189 +2223,189 @@ discard block |
||
| 2223 | 2223 | } |
| 2224 | 2224 | <?php if ( 0 ) { ?></script><?php } ?> |
| 2225 | 2225 | <?php |
| 2226 | - $locale = ob_get_clean(); |
|
| 2226 | + $locale = ob_get_clean(); |
|
| 2227 | 2227 | |
| 2228 | - return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
|
| 2229 | - } |
|
| 2228 | + return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
|
| 2229 | + } |
|
| 2230 | 2230 | |
| 2231 | - /** |
|
| 2232 | - * Select2 JS params. |
|
| 2233 | - * |
|
| 2234 | - * @since 0.1.44 |
|
| 2235 | - * |
|
| 2236 | - * @return array Select2 JS params. |
|
| 2237 | - */ |
|
| 2238 | - public static function select2_params() { |
|
| 2239 | - $params = array( |
|
| 2240 | - 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'aui' ), |
|
| 2241 | - 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'aui' ), |
|
| 2242 | - 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'aui' ), |
|
| 2243 | - 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ), |
|
| 2244 | - 'i18n_input_too_short_n' => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ), |
|
| 2245 | - 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'aui' ), |
|
| 2246 | - 'i18n_input_too_long_n' => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ), |
|
| 2247 | - 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ), |
|
| 2248 | - 'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ), |
|
| 2249 | - 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'aui' ), |
|
| 2250 | - 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'aui' ) |
|
| 2251 | - ); |
|
| 2252 | - |
|
| 2253 | - return apply_filters( 'ayecode_ui_select2_params', $params ); |
|
| 2254 | - } |
|
| 2231 | + /** |
|
| 2232 | + * Select2 JS params. |
|
| 2233 | + * |
|
| 2234 | + * @since 0.1.44 |
|
| 2235 | + * |
|
| 2236 | + * @return array Select2 JS params. |
|
| 2237 | + */ |
|
| 2238 | + public static function select2_params() { |
|
| 2239 | + $params = array( |
|
| 2240 | + 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'aui' ), |
|
| 2241 | + 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'aui' ), |
|
| 2242 | + 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'aui' ), |
|
| 2243 | + 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ), |
|
| 2244 | + 'i18n_input_too_short_n' => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ), |
|
| 2245 | + 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'aui' ), |
|
| 2246 | + 'i18n_input_too_long_n' => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ), |
|
| 2247 | + 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ), |
|
| 2248 | + 'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ), |
|
| 2249 | + 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'aui' ), |
|
| 2250 | + 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'aui' ) |
|
| 2251 | + ); |
|
| 2252 | + |
|
| 2253 | + return apply_filters( 'ayecode_ui_select2_params', $params ); |
|
| 2254 | + } |
|
| 2255 | 2255 | |
| 2256 | - /** |
|
| 2257 | - * Select2 JS localize. |
|
| 2258 | - * |
|
| 2259 | - * @since 0.1.44 |
|
| 2260 | - * |
|
| 2261 | - * @return string Select2 JS locale. |
|
| 2262 | - */ |
|
| 2263 | - public static function select2_locale() { |
|
| 2264 | - $params = self::select2_params(); |
|
| 2265 | - |
|
| 2266 | - foreach ( (array) $params as $key => $value ) { |
|
| 2267 | - if ( ! is_scalar( $value ) ) { |
|
| 2268 | - continue; |
|
| 2269 | - } |
|
| 2256 | + /** |
|
| 2257 | + * Select2 JS localize. |
|
| 2258 | + * |
|
| 2259 | + * @since 0.1.44 |
|
| 2260 | + * |
|
| 2261 | + * @return string Select2 JS locale. |
|
| 2262 | + */ |
|
| 2263 | + public static function select2_locale() { |
|
| 2264 | + $params = self::select2_params(); |
|
| 2265 | + |
|
| 2266 | + foreach ( (array) $params as $key => $value ) { |
|
| 2267 | + if ( ! is_scalar( $value ) ) { |
|
| 2268 | + continue; |
|
| 2269 | + } |
|
| 2270 | 2270 | |
| 2271 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
| 2272 | - } |
|
| 2271 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
| 2272 | + } |
|
| 2273 | 2273 | |
| 2274 | - $locale = json_encode( $params ); |
|
| 2274 | + $locale = json_encode( $params ); |
|
| 2275 | 2275 | |
| 2276 | - return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
|
| 2277 | - } |
|
| 2276 | + return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
|
| 2277 | + } |
|
| 2278 | 2278 | |
| 2279 | - /** |
|
| 2280 | - * Time ago JS localize. |
|
| 2281 | - * |
|
| 2282 | - * @since 0.1.47 |
|
| 2283 | - * |
|
| 2284 | - * @return string Time ago JS locale. |
|
| 2285 | - */ |
|
| 2286 | - public static function timeago_locale() { |
|
| 2287 | - $params = array( |
|
| 2288 | - 'prefix_ago' => '', |
|
| 2289 | - 'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ), |
|
| 2290 | - 'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ', |
|
| 2291 | - 'suffix_after' => '', |
|
| 2292 | - 'seconds' => _x( 'less than a minute', 'time ago', 'aui' ), |
|
| 2293 | - 'minute' => _x( 'about a minute', 'time ago', 'aui' ), |
|
| 2294 | - 'minutes' => _x( '%d minutes', 'time ago', 'aui' ), |
|
| 2295 | - 'hour' => _x( 'about an hour', 'time ago', 'aui' ), |
|
| 2296 | - 'hours' => _x( 'about %d hours', 'time ago', 'aui' ), |
|
| 2297 | - 'day' => _x( 'a day', 'time ago', 'aui' ), |
|
| 2298 | - 'days' => _x( '%d days', 'time ago', 'aui' ), |
|
| 2299 | - 'month' => _x( 'about a month', 'time ago', 'aui' ), |
|
| 2300 | - 'months' => _x( '%d months', 'time ago', 'aui' ), |
|
| 2301 | - 'year' => _x( 'about a year', 'time ago', 'aui' ), |
|
| 2302 | - 'years' => _x( '%d years', 'time ago', 'aui' ), |
|
| 2303 | - ); |
|
| 2304 | - |
|
| 2305 | - $params = apply_filters( 'ayecode_ui_timeago_params', $params ); |
|
| 2306 | - |
|
| 2307 | - foreach ( (array) $params as $key => $value ) { |
|
| 2308 | - if ( ! is_scalar( $value ) ) { |
|
| 2309 | - continue; |
|
| 2310 | - } |
|
| 2279 | + /** |
|
| 2280 | + * Time ago JS localize. |
|
| 2281 | + * |
|
| 2282 | + * @since 0.1.47 |
|
| 2283 | + * |
|
| 2284 | + * @return string Time ago JS locale. |
|
| 2285 | + */ |
|
| 2286 | + public static function timeago_locale() { |
|
| 2287 | + $params = array( |
|
| 2288 | + 'prefix_ago' => '', |
|
| 2289 | + 'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ), |
|
| 2290 | + 'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ', |
|
| 2291 | + 'suffix_after' => '', |
|
| 2292 | + 'seconds' => _x( 'less than a minute', 'time ago', 'aui' ), |
|
| 2293 | + 'minute' => _x( 'about a minute', 'time ago', 'aui' ), |
|
| 2294 | + 'minutes' => _x( '%d minutes', 'time ago', 'aui' ), |
|
| 2295 | + 'hour' => _x( 'about an hour', 'time ago', 'aui' ), |
|
| 2296 | + 'hours' => _x( 'about %d hours', 'time ago', 'aui' ), |
|
| 2297 | + 'day' => _x( 'a day', 'time ago', 'aui' ), |
|
| 2298 | + 'days' => _x( '%d days', 'time ago', 'aui' ), |
|
| 2299 | + 'month' => _x( 'about a month', 'time ago', 'aui' ), |
|
| 2300 | + 'months' => _x( '%d months', 'time ago', 'aui' ), |
|
| 2301 | + 'year' => _x( 'about a year', 'time ago', 'aui' ), |
|
| 2302 | + 'years' => _x( '%d years', 'time ago', 'aui' ), |
|
| 2303 | + ); |
|
| 2304 | + |
|
| 2305 | + $params = apply_filters( 'ayecode_ui_timeago_params', $params ); |
|
| 2306 | + |
|
| 2307 | + foreach ( (array) $params as $key => $value ) { |
|
| 2308 | + if ( ! is_scalar( $value ) ) { |
|
| 2309 | + continue; |
|
| 2310 | + } |
|
| 2311 | 2311 | |
| 2312 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
| 2313 | - } |
|
| 2312 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
| 2313 | + } |
|
| 2314 | 2314 | |
| 2315 | - $locale = json_encode( $params ); |
|
| 2315 | + $locale = json_encode( $params ); |
|
| 2316 | 2316 | |
| 2317 | - return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) ); |
|
| 2318 | - } |
|
| 2317 | + return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) ); |
|
| 2318 | + } |
|
| 2319 | 2319 | |
| 2320 | - /** |
|
| 2321 | - * JavaScript Minifier |
|
| 2322 | - * |
|
| 2323 | - * @param $input |
|
| 2324 | - * |
|
| 2325 | - * @return mixed |
|
| 2326 | - */ |
|
| 2327 | - public static function minify_js($input) { |
|
| 2328 | - if(trim($input) === "") return $input; |
|
| 2329 | - return preg_replace( |
|
| 2330 | - array( |
|
| 2331 | - // Remove comment(s) |
|
| 2332 | - '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
|
| 2333 | - // Remove white-space(s) outside the string and regex |
|
| 2334 | - '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
|
| 2335 | - // Remove the last semicolon |
|
| 2336 | - '#;+\}#', |
|
| 2337 | - // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
|
| 2338 | - '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
|
| 2339 | - // --ibid. From `foo['bar']` to `foo.bar` |
|
| 2340 | - '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
|
| 2341 | - ), |
|
| 2342 | - array( |
|
| 2343 | - '$1', |
|
| 2344 | - '$1$2', |
|
| 2345 | - '}', |
|
| 2346 | - '$1$3', |
|
| 2347 | - '$1.$3' |
|
| 2348 | - ), |
|
| 2349 | - $input); |
|
| 2350 | - } |
|
| 2320 | + /** |
|
| 2321 | + * JavaScript Minifier |
|
| 2322 | + * |
|
| 2323 | + * @param $input |
|
| 2324 | + * |
|
| 2325 | + * @return mixed |
|
| 2326 | + */ |
|
| 2327 | + public static function minify_js($input) { |
|
| 2328 | + if(trim($input) === "") return $input; |
|
| 2329 | + return preg_replace( |
|
| 2330 | + array( |
|
| 2331 | + // Remove comment(s) |
|
| 2332 | + '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
|
| 2333 | + // Remove white-space(s) outside the string and regex |
|
| 2334 | + '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
|
| 2335 | + // Remove the last semicolon |
|
| 2336 | + '#;+\}#', |
|
| 2337 | + // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
|
| 2338 | + '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
|
| 2339 | + // --ibid. From `foo['bar']` to `foo.bar` |
|
| 2340 | + '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
|
| 2341 | + ), |
|
| 2342 | + array( |
|
| 2343 | + '$1', |
|
| 2344 | + '$1$2', |
|
| 2345 | + '}', |
|
| 2346 | + '$1$3', |
|
| 2347 | + '$1.$3' |
|
| 2348 | + ), |
|
| 2349 | + $input); |
|
| 2350 | + } |
|
| 2351 | 2351 | |
| 2352 | - /** |
|
| 2353 | - * Minify CSS |
|
| 2354 | - * |
|
| 2355 | - * @param $input |
|
| 2356 | - * |
|
| 2357 | - * @return mixed |
|
| 2358 | - */ |
|
| 2359 | - public static function minify_css($input) { |
|
| 2360 | - if(trim($input) === "") return $input; |
|
| 2361 | - return preg_replace( |
|
| 2362 | - array( |
|
| 2363 | - // Remove comment(s) |
|
| 2364 | - '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s', |
|
| 2365 | - // Remove unused white-space(s) |
|
| 2366 | - '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', |
|
| 2367 | - // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` |
|
| 2368 | - '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si', |
|
| 2369 | - // Replace `:0 0 0 0` with `:0` |
|
| 2370 | - '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i', |
|
| 2371 | - // Replace `background-position:0` with `background-position:0 0` |
|
| 2372 | - '#(background-position):0(?=[;\}])#si', |
|
| 2373 | - // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space |
|
| 2374 | - '#(?<=[\s:,\-])0+\.(\d+)#s', |
|
| 2375 | - // Minify string value |
|
| 2376 | - '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', |
|
| 2377 | - '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', |
|
| 2378 | - // Minify HEX color code |
|
| 2379 | - '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i', |
|
| 2380 | - // Replace `(border|outline):none` with `(border|outline):0` |
|
| 2381 | - '#(?<=[\{;])(border|outline):none(?=[;\}\!])#', |
|
| 2382 | - // Remove empty selector(s) |
|
| 2383 | - '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s' |
|
| 2384 | - ), |
|
| 2385 | - array( |
|
| 2386 | - '$1', |
|
| 2387 | - '$1$2$3$4$5$6$7', |
|
| 2388 | - '$1', |
|
| 2389 | - ':0', |
|
| 2390 | - '$1:0 0', |
|
| 2391 | - '.$1', |
|
| 2392 | - '$1$3', |
|
| 2393 | - '$1$2$4$5', |
|
| 2394 | - '$1$2$3', |
|
| 2395 | - '$1:0', |
|
| 2396 | - '$1$2' |
|
| 2397 | - ), |
|
| 2398 | - $input); |
|
| 2399 | - } |
|
| 2352 | + /** |
|
| 2353 | + * Minify CSS |
|
| 2354 | + * |
|
| 2355 | + * @param $input |
|
| 2356 | + * |
|
| 2357 | + * @return mixed |
|
| 2358 | + */ |
|
| 2359 | + public static function minify_css($input) { |
|
| 2360 | + if(trim($input) === "") return $input; |
|
| 2361 | + return preg_replace( |
|
| 2362 | + array( |
|
| 2363 | + // Remove comment(s) |
|
| 2364 | + '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s', |
|
| 2365 | + // Remove unused white-space(s) |
|
| 2366 | + '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', |
|
| 2367 | + // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` |
|
| 2368 | + '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si', |
|
| 2369 | + // Replace `:0 0 0 0` with `:0` |
|
| 2370 | + '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i', |
|
| 2371 | + // Replace `background-position:0` with `background-position:0 0` |
|
| 2372 | + '#(background-position):0(?=[;\}])#si', |
|
| 2373 | + // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space |
|
| 2374 | + '#(?<=[\s:,\-])0+\.(\d+)#s', |
|
| 2375 | + // Minify string value |
|
| 2376 | + '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', |
|
| 2377 | + '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', |
|
| 2378 | + // Minify HEX color code |
|
| 2379 | + '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i', |
|
| 2380 | + // Replace `(border|outline):none` with `(border|outline):0` |
|
| 2381 | + '#(?<=[\{;])(border|outline):none(?=[;\}\!])#', |
|
| 2382 | + // Remove empty selector(s) |
|
| 2383 | + '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s' |
|
| 2384 | + ), |
|
| 2385 | + array( |
|
| 2386 | + '$1', |
|
| 2387 | + '$1$2$3$4$5$6$7', |
|
| 2388 | + '$1', |
|
| 2389 | + ':0', |
|
| 2390 | + '$1:0 0', |
|
| 2391 | + '.$1', |
|
| 2392 | + '$1$3', |
|
| 2393 | + '$1$2$4$5', |
|
| 2394 | + '$1$2$3', |
|
| 2395 | + '$1:0', |
|
| 2396 | + '$1$2' |
|
| 2397 | + ), |
|
| 2398 | + $input); |
|
| 2399 | + } |
|
| 2400 | 2400 | |
| 2401 | - /** |
|
| 2402 | - * Get the conditional fields JavaScript. |
|
| 2403 | - * |
|
| 2404 | - * @return mixed |
|
| 2405 | - */ |
|
| 2406 | - public function conditional_fields_js() { |
|
| 2407 | - ob_start(); |
|
| 2408 | - ?> |
|
| 2401 | + /** |
|
| 2402 | + * Get the conditional fields JavaScript. |
|
| 2403 | + * |
|
| 2404 | + * @return mixed |
|
| 2405 | + */ |
|
| 2406 | + public function conditional_fields_js() { |
|
| 2407 | + ob_start(); |
|
| 2408 | + ?> |
|
| 2409 | 2409 | <script> |
| 2410 | 2410 | /** |
| 2411 | 2411 | * Conditional Fields |
@@ -2909,14 +2909,14 @@ discard block |
||
| 2909 | 2909 | <?php do_action( 'aui_conditional_fields_js', $this ); ?> |
| 2910 | 2910 | </script> |
| 2911 | 2911 | <?php |
| 2912 | - $output = ob_get_clean(); |
|
| 2912 | + $output = ob_get_clean(); |
|
| 2913 | 2913 | |
| 2914 | - return str_replace( array( '<script>', '</script>' ), '', self::minify_js( $output ) ); |
|
| 2915 | - } |
|
| 2916 | - } |
|
| 2914 | + return str_replace( array( '<script>', '</script>' ), '', self::minify_js( $output ) ); |
|
| 2915 | + } |
|
| 2916 | + } |
|
| 2917 | 2917 | |
| 2918 | - /** |
|
| 2919 | - * Run the class if found. |
|
| 2920 | - */ |
|
| 2921 | - AyeCode_UI_Settings::instance(); |
|
| 2918 | + /** |
|
| 2919 | + * Run the class if found. |
|
| 2920 | + */ |
|
| 2921 | + AyeCode_UI_Settings::instance(); |
|
| 2922 | 2922 | } |
| 2923 | 2923 | \ No newline at end of file |