@@ -20,406 +20,406 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class GetPaid_Installer { |
| 22 | 22 | |
| 23 | - private static $schema = null; |
|
| 24 | - private static $schema_version = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Upgrades the install. |
|
| 28 | - * |
|
| 29 | - * @param string $upgrade_from The current invoicing version. |
|
| 30 | - */ |
|
| 31 | - public function upgrade_db( $upgrade_from ) { |
|
| 32 | - |
|
| 33 | - // Save the current invoicing version. |
|
| 34 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
| 35 | - |
|
| 36 | - // Setup the invoice Custom Post Type. |
|
| 37 | - GetPaid_Post_Types::register_post_types(); |
|
| 38 | - |
|
| 39 | - // Clear the permalinks |
|
| 40 | - flush_rewrite_rules(); |
|
| 41 | - |
|
| 42 | - // Maybe create new/missing pages. |
|
| 43 | - $this->create_pages(); |
|
| 44 | - |
|
| 45 | - // Maybe re(add) admin capabilities. |
|
| 46 | - $this->add_capabilities(); |
|
| 47 | - |
|
| 48 | - // Maybe create the default payment form. |
|
| 49 | - wpinv_get_default_payment_form(); |
|
| 50 | - |
|
| 51 | - // Create any missing database tables. |
|
| 52 | - $method = "upgrade_from_$upgrade_from"; |
|
| 53 | - |
|
| 54 | - $installed = get_option( 'gepaid_installed_on' ); |
|
| 55 | - |
|
| 56 | - if ( empty( $installed ) ) { |
|
| 57 | - update_option( 'gepaid_installed_on', time() ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if ( method_exists( $this, $method ) ) { |
|
| 61 | - $this->$method(); |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Do a fresh install. |
|
| 67 | - * |
|
| 68 | - */ |
|
| 69 | - public function upgrade_from_0() { |
|
| 70 | - |
|
| 71 | - // Save default tax rates. |
|
| 72 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Upgrade to 0.0.5 |
|
| 77 | - * |
|
| 78 | - */ |
|
| 79 | - public function upgrade_from_004() { |
|
| 80 | - global $wpdb; |
|
| 81 | - |
|
| 82 | - // Invoices. |
|
| 83 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 84 | - if ( ! empty( $results ) ) { |
|
| 85 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 86 | - |
|
| 87 | - // Clean post cache |
|
| 88 | - foreach ( $results as $row ) { |
|
| 89 | - clean_post_cache( $row->ID ); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Item meta key changes |
|
| 94 | - $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
| 95 | - $results = $wpdb->get_results( $query ); |
|
| 96 | - |
|
| 97 | - if ( ! empty( $results ) ) { |
|
| 98 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
| 99 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
| 100 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
| 101 | - |
|
| 102 | - foreach ( $results as $row ) { |
|
| 103 | - clean_post_cache( $row->post_id ); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $this->upgrade_from_118(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Upgrade to version 2.0.0. |
|
| 112 | - * |
|
| 113 | - */ |
|
| 114 | - public function upgrade_from_118() { |
|
| 115 | - $this->migrate_old_invoices(); |
|
| 116 | - $this->upgrade_from_279(); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Upgrade to version 2.0.0. |
|
| 121 | - * |
|
| 122 | - */ |
|
| 123 | - public function upgrade_from_279() { |
|
| 124 | - self::migrate_old_customers(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Give administrators the capability to manage GetPaid. |
|
| 129 | - * |
|
| 130 | - */ |
|
| 131 | - public function add_capabilities() { |
|
| 132 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Retreives GetPaid pages. |
|
| 137 | - * |
|
| 138 | - */ |
|
| 139 | - public static function get_pages() { |
|
| 140 | - |
|
| 141 | - return apply_filters( |
|
| 142 | - 'wpinv_create_pages', |
|
| 143 | - array( |
|
| 144 | - |
|
| 145 | - // Checkout page. |
|
| 146 | - 'checkout_page' => array( |
|
| 147 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
| 148 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
| 149 | - 'content' => ' |
|
| 23 | + private static $schema = null; |
|
| 24 | + private static $schema_version = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Upgrades the install. |
|
| 28 | + * |
|
| 29 | + * @param string $upgrade_from The current invoicing version. |
|
| 30 | + */ |
|
| 31 | + public function upgrade_db( $upgrade_from ) { |
|
| 32 | + |
|
| 33 | + // Save the current invoicing version. |
|
| 34 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
| 35 | + |
|
| 36 | + // Setup the invoice Custom Post Type. |
|
| 37 | + GetPaid_Post_Types::register_post_types(); |
|
| 38 | + |
|
| 39 | + // Clear the permalinks |
|
| 40 | + flush_rewrite_rules(); |
|
| 41 | + |
|
| 42 | + // Maybe create new/missing pages. |
|
| 43 | + $this->create_pages(); |
|
| 44 | + |
|
| 45 | + // Maybe re(add) admin capabilities. |
|
| 46 | + $this->add_capabilities(); |
|
| 47 | + |
|
| 48 | + // Maybe create the default payment form. |
|
| 49 | + wpinv_get_default_payment_form(); |
|
| 50 | + |
|
| 51 | + // Create any missing database tables. |
|
| 52 | + $method = "upgrade_from_$upgrade_from"; |
|
| 53 | + |
|
| 54 | + $installed = get_option( 'gepaid_installed_on' ); |
|
| 55 | + |
|
| 56 | + if ( empty( $installed ) ) { |
|
| 57 | + update_option( 'gepaid_installed_on', time() ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if ( method_exists( $this, $method ) ) { |
|
| 61 | + $this->$method(); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Do a fresh install. |
|
| 67 | + * |
|
| 68 | + */ |
|
| 69 | + public function upgrade_from_0() { |
|
| 70 | + |
|
| 71 | + // Save default tax rates. |
|
| 72 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Upgrade to 0.0.5 |
|
| 77 | + * |
|
| 78 | + */ |
|
| 79 | + public function upgrade_from_004() { |
|
| 80 | + global $wpdb; |
|
| 81 | + |
|
| 82 | + // Invoices. |
|
| 83 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 84 | + if ( ! empty( $results ) ) { |
|
| 85 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 86 | + |
|
| 87 | + // Clean post cache |
|
| 88 | + foreach ( $results as $row ) { |
|
| 89 | + clean_post_cache( $row->ID ); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Item meta key changes |
|
| 94 | + $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
| 95 | + $results = $wpdb->get_results( $query ); |
|
| 96 | + |
|
| 97 | + if ( ! empty( $results ) ) { |
|
| 98 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
| 99 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
| 100 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
| 101 | + |
|
| 102 | + foreach ( $results as $row ) { |
|
| 103 | + clean_post_cache( $row->post_id ); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $this->upgrade_from_118(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Upgrade to version 2.0.0. |
|
| 112 | + * |
|
| 113 | + */ |
|
| 114 | + public function upgrade_from_118() { |
|
| 115 | + $this->migrate_old_invoices(); |
|
| 116 | + $this->upgrade_from_279(); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Upgrade to version 2.0.0. |
|
| 121 | + * |
|
| 122 | + */ |
|
| 123 | + public function upgrade_from_279() { |
|
| 124 | + self::migrate_old_customers(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Give administrators the capability to manage GetPaid. |
|
| 129 | + * |
|
| 130 | + */ |
|
| 131 | + public function add_capabilities() { |
|
| 132 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Retreives GetPaid pages. |
|
| 137 | + * |
|
| 138 | + */ |
|
| 139 | + public static function get_pages() { |
|
| 140 | + |
|
| 141 | + return apply_filters( |
|
| 142 | + 'wpinv_create_pages', |
|
| 143 | + array( |
|
| 144 | + |
|
| 145 | + // Checkout page. |
|
| 146 | + 'checkout_page' => array( |
|
| 147 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
| 148 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
| 149 | + 'content' => ' |
|
| 150 | 150 | <!-- wp:shortcode --> |
| 151 | 151 | [wpinv_checkout] |
| 152 | 152 | <!-- /wp:shortcode --> |
| 153 | 153 | ', |
| 154 | - 'parent' => '', |
|
| 155 | - ), |
|
| 156 | - |
|
| 157 | - // Invoice history page. |
|
| 158 | - 'invoice_history_page' => array( |
|
| 159 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
| 160 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
| 161 | - 'content' => ' |
|
| 154 | + 'parent' => '', |
|
| 155 | + ), |
|
| 156 | + |
|
| 157 | + // Invoice history page. |
|
| 158 | + 'invoice_history_page' => array( |
|
| 159 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
| 160 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
| 161 | + 'content' => ' |
|
| 162 | 162 | <!-- wp:shortcode --> |
| 163 | 163 | [wpinv_history] |
| 164 | 164 | <!-- /wp:shortcode --> |
| 165 | 165 | ', |
| 166 | - 'parent' => '', |
|
| 167 | - ), |
|
| 168 | - |
|
| 169 | - // Success page content. |
|
| 170 | - 'success_page' => array( |
|
| 171 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
| 172 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
| 173 | - 'content' => ' |
|
| 166 | + 'parent' => '', |
|
| 167 | + ), |
|
| 168 | + |
|
| 169 | + // Success page content. |
|
| 170 | + 'success_page' => array( |
|
| 171 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
| 172 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
| 173 | + 'content' => ' |
|
| 174 | 174 | <!-- wp:shortcode --> |
| 175 | 175 | [wpinv_receipt] |
| 176 | 176 | <!-- /wp:shortcode --> |
| 177 | 177 | ', |
| 178 | - 'parent' => 'gp-checkout', |
|
| 179 | - ), |
|
| 180 | - |
|
| 181 | - // Failure page content. |
|
| 182 | - 'failure_page' => array( |
|
| 183 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
| 184 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
| 185 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
| 186 | - 'parent' => 'gp-checkout', |
|
| 187 | - ), |
|
| 188 | - |
|
| 189 | - // Subscriptions history page. |
|
| 190 | - 'invoice_subscription_page' => array( |
|
| 191 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
| 192 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
| 193 | - 'content' => ' |
|
| 178 | + 'parent' => 'gp-checkout', |
|
| 179 | + ), |
|
| 180 | + |
|
| 181 | + // Failure page content. |
|
| 182 | + 'failure_page' => array( |
|
| 183 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
| 184 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
| 185 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
| 186 | + 'parent' => 'gp-checkout', |
|
| 187 | + ), |
|
| 188 | + |
|
| 189 | + // Subscriptions history page. |
|
| 190 | + 'invoice_subscription_page' => array( |
|
| 191 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
| 192 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
| 193 | + 'content' => ' |
|
| 194 | 194 | <!-- wp:shortcode --> |
| 195 | 195 | [wpinv_subscriptions] |
| 196 | 196 | <!-- /wp:shortcode --> |
| 197 | 197 | ', |
| 198 | - 'parent' => '', |
|
| 199 | - ), |
|
| 200 | - |
|
| 201 | - ) |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Re-create GetPaid pages. |
|
| 207 | - * |
|
| 208 | - */ |
|
| 209 | - public function create_pages() { |
|
| 210 | - |
|
| 211 | - foreach ( self::get_pages() as $key => $page ) { |
|
| 212 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Migrates old invoices to new invoices. |
|
| 218 | - * |
|
| 219 | - */ |
|
| 220 | - public function migrate_old_invoices() { |
|
| 221 | - global $wpdb; |
|
| 222 | - |
|
| 223 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 224 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 225 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
| 226 | - $invoices = array_unique( |
|
| 227 | - get_posts( |
|
| 228 | - array( |
|
| 229 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
| 230 | - 'posts_per_page' => -1, |
|
| 231 | - 'fields' => 'ids', |
|
| 232 | - 'post_status' => array_keys( get_post_stati() ), |
|
| 233 | - 'exclude' => (array) $migrated, |
|
| 234 | - ) |
|
| 235 | - ) |
|
| 236 | - ); |
|
| 237 | - |
|
| 238 | - // Abort if we do not have any invoices. |
|
| 239 | - if ( empty( $invoices ) ) { |
|
| 240 | - return; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
| 244 | - |
|
| 245 | - $invoice_rows = array(); |
|
| 246 | - foreach ( $invoices as $invoice ) { |
|
| 247 | - |
|
| 248 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
| 249 | - |
|
| 250 | - if ( empty( $invoice->ID ) ) { |
|
| 251 | - return; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $fields = array( |
|
| 255 | - 'post_id' => $invoice->ID, |
|
| 256 | - 'number' => $invoice->get_number(), |
|
| 257 | - 'key' => $invoice->get_key(), |
|
| 258 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
| 259 | - 'mode' => $invoice->mode, |
|
| 260 | - 'user_ip' => $invoice->get_ip(), |
|
| 261 | - 'first_name' => $invoice->get_first_name(), |
|
| 262 | - 'last_name' => $invoice->get_last_name(), |
|
| 263 | - 'address' => $invoice->get_address(), |
|
| 264 | - 'city' => $invoice->city, |
|
| 265 | - 'state' => $invoice->state, |
|
| 266 | - 'country' => $invoice->country, |
|
| 267 | - 'zip' => $invoice->zip, |
|
| 268 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
| 269 | - 'gateway' => $invoice->get_gateway(), |
|
| 270 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
| 271 | - 'currency' => $invoice->get_currency(), |
|
| 272 | - 'subtotal' => $invoice->get_subtotal(), |
|
| 273 | - 'tax' => $invoice->get_tax(), |
|
| 274 | - 'fees_total' => $invoice->get_fees_total(), |
|
| 275 | - 'total' => $invoice->get_total(), |
|
| 276 | - 'discount' => $invoice->get_discount(), |
|
| 277 | - 'discount_code' => $invoice->get_discount_code(), |
|
| 278 | - 'disable_taxes' => $invoice->disable_taxes, |
|
| 279 | - 'due_date' => $invoice->get_due_date(), |
|
| 280 | - 'completed_date' => $invoice->get_completed_date(), |
|
| 281 | - 'company' => $invoice->company, |
|
| 282 | - 'vat_number' => $invoice->vat_number, |
|
| 283 | - 'vat_rate' => $invoice->vat_rate, |
|
| 284 | - 'custom_meta' => $invoice->payment_meta, |
|
| 285 | - ); |
|
| 286 | - |
|
| 287 | - foreach ( $fields as $key => $val ) { |
|
| 288 | - if ( is_null( $val ) ) { |
|
| 289 | - $val = ''; |
|
| 290 | - } |
|
| 291 | - $val = maybe_serialize( $val ); |
|
| 292 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $fields = implode( ', ', $fields ); |
|
| 296 | - $invoice_rows[] = "($fields)"; |
|
| 297 | - |
|
| 298 | - $item_rows = array(); |
|
| 299 | - $item_columns = array(); |
|
| 300 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
| 301 | - $fields = array( |
|
| 302 | - 'post_id' => $invoice->ID, |
|
| 303 | - 'item_id' => $details['id'], |
|
| 304 | - 'item_name' => $details['name'], |
|
| 305 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
| 306 | - 'vat_rate' => $details['vat_rate'], |
|
| 307 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
| 308 | - 'tax' => $details['tax'], |
|
| 309 | - 'item_price' => $details['item_price'], |
|
| 310 | - 'custom_price' => $details['custom_price'], |
|
| 311 | - 'quantity' => $details['quantity'], |
|
| 312 | - 'discount' => $details['discount'], |
|
| 313 | - 'subtotal' => $details['subtotal'], |
|
| 314 | - 'price' => $details['price'], |
|
| 315 | - 'meta' => $details['meta'], |
|
| 316 | - 'fees' => $details['fees'], |
|
| 317 | - ); |
|
| 318 | - |
|
| 319 | - $item_columns = array_keys( $fields ); |
|
| 320 | - |
|
| 321 | - foreach ( $fields as $key => $val ) { |
|
| 322 | - if ( is_null( $val ) ) { |
|
| 323 | - $val = ''; |
|
| 324 | - } |
|
| 325 | - $val = maybe_serialize( $val ); |
|
| 326 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - $fields = implode( ', ', $fields ); |
|
| 330 | - $item_rows[] = "($fields)"; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - $item_rows = implode( ', ', $item_rows ); |
|
| 334 | - $item_columns = implode( ', ', $item_columns ); |
|
| 335 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if ( empty( $invoice_rows ) ) { |
|
| 339 | - return; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
| 343 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Migrates old customers to new table. |
|
| 348 | - * |
|
| 349 | - */ |
|
| 350 | - public static function migrate_old_customers() { |
|
| 351 | - global $wpdb; |
|
| 352 | - |
|
| 353 | - // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
|
| 354 | - $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
| 355 | - |
|
| 356 | - foreach ( $invoice_ids as $invoice_id ) { |
|
| 357 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 358 | - |
|
| 359 | - if ( empty( $invoice ) ) { |
|
| 360 | - continue; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // Fetch customer from the user ID. |
|
| 364 | - $user_id = $invoice->get_user_id(); |
|
| 365 | - |
|
| 366 | - if ( empty( $user_id ) ) { |
|
| 367 | - continue; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
| 371 | - |
|
| 372 | - // Create if not exists. |
|
| 373 | - if ( empty( $customer ) ) { |
|
| 374 | - $customer = new GetPaid_Customer( 0 ); |
|
| 375 | - $customer->clone_user( $user_id ); |
|
| 376 | - $customer->save(); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - $invoice->set_customer_id( $customer->get_id() ); |
|
| 380 | - $invoice->save(); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Migrates old invoices to new invoices. |
|
| 386 | - * |
|
| 387 | - */ |
|
| 388 | - public static function rename_gateways_label() { |
|
| 389 | - global $wpdb; |
|
| 390 | - |
|
| 391 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
| 392 | - |
|
| 393 | - $wpdb->update( |
|
| 394 | - $wpdb->prefix . 'getpaid_invoices', |
|
| 395 | - array( 'gateway' => $gateway ), |
|
| 396 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
| 397 | - '%s', |
|
| 398 | - '%s' |
|
| 399 | - ); |
|
| 400 | - |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Returns the DB schema. |
|
| 406 | - * |
|
| 407 | - */ |
|
| 408 | - public static function get_db_schema() { |
|
| 409 | - global $wpdb; |
|
| 410 | - |
|
| 411 | - if ( ! empty( self::$schema ) ) { |
|
| 412 | - return self::$schema; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 416 | - |
|
| 417 | - $charset_collate = $wpdb->get_charset_collate(); |
|
| 418 | - |
|
| 419 | - $schema = array(); |
|
| 420 | - |
|
| 421 | - // Subscriptions. |
|
| 422 | - $schema['subscriptions'] = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
| 198 | + 'parent' => '', |
|
| 199 | + ), |
|
| 200 | + |
|
| 201 | + ) |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Re-create GetPaid pages. |
|
| 207 | + * |
|
| 208 | + */ |
|
| 209 | + public function create_pages() { |
|
| 210 | + |
|
| 211 | + foreach ( self::get_pages() as $key => $page ) { |
|
| 212 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Migrates old invoices to new invoices. |
|
| 218 | + * |
|
| 219 | + */ |
|
| 220 | + public function migrate_old_invoices() { |
|
| 221 | + global $wpdb; |
|
| 222 | + |
|
| 223 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 224 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 225 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
| 226 | + $invoices = array_unique( |
|
| 227 | + get_posts( |
|
| 228 | + array( |
|
| 229 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
| 230 | + 'posts_per_page' => -1, |
|
| 231 | + 'fields' => 'ids', |
|
| 232 | + 'post_status' => array_keys( get_post_stati() ), |
|
| 233 | + 'exclude' => (array) $migrated, |
|
| 234 | + ) |
|
| 235 | + ) |
|
| 236 | + ); |
|
| 237 | + |
|
| 238 | + // Abort if we do not have any invoices. |
|
| 239 | + if ( empty( $invoices ) ) { |
|
| 240 | + return; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
| 244 | + |
|
| 245 | + $invoice_rows = array(); |
|
| 246 | + foreach ( $invoices as $invoice ) { |
|
| 247 | + |
|
| 248 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
| 249 | + |
|
| 250 | + if ( empty( $invoice->ID ) ) { |
|
| 251 | + return; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $fields = array( |
|
| 255 | + 'post_id' => $invoice->ID, |
|
| 256 | + 'number' => $invoice->get_number(), |
|
| 257 | + 'key' => $invoice->get_key(), |
|
| 258 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
| 259 | + 'mode' => $invoice->mode, |
|
| 260 | + 'user_ip' => $invoice->get_ip(), |
|
| 261 | + 'first_name' => $invoice->get_first_name(), |
|
| 262 | + 'last_name' => $invoice->get_last_name(), |
|
| 263 | + 'address' => $invoice->get_address(), |
|
| 264 | + 'city' => $invoice->city, |
|
| 265 | + 'state' => $invoice->state, |
|
| 266 | + 'country' => $invoice->country, |
|
| 267 | + 'zip' => $invoice->zip, |
|
| 268 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
| 269 | + 'gateway' => $invoice->get_gateway(), |
|
| 270 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
| 271 | + 'currency' => $invoice->get_currency(), |
|
| 272 | + 'subtotal' => $invoice->get_subtotal(), |
|
| 273 | + 'tax' => $invoice->get_tax(), |
|
| 274 | + 'fees_total' => $invoice->get_fees_total(), |
|
| 275 | + 'total' => $invoice->get_total(), |
|
| 276 | + 'discount' => $invoice->get_discount(), |
|
| 277 | + 'discount_code' => $invoice->get_discount_code(), |
|
| 278 | + 'disable_taxes' => $invoice->disable_taxes, |
|
| 279 | + 'due_date' => $invoice->get_due_date(), |
|
| 280 | + 'completed_date' => $invoice->get_completed_date(), |
|
| 281 | + 'company' => $invoice->company, |
|
| 282 | + 'vat_number' => $invoice->vat_number, |
|
| 283 | + 'vat_rate' => $invoice->vat_rate, |
|
| 284 | + 'custom_meta' => $invoice->payment_meta, |
|
| 285 | + ); |
|
| 286 | + |
|
| 287 | + foreach ( $fields as $key => $val ) { |
|
| 288 | + if ( is_null( $val ) ) { |
|
| 289 | + $val = ''; |
|
| 290 | + } |
|
| 291 | + $val = maybe_serialize( $val ); |
|
| 292 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $fields = implode( ', ', $fields ); |
|
| 296 | + $invoice_rows[] = "($fields)"; |
|
| 297 | + |
|
| 298 | + $item_rows = array(); |
|
| 299 | + $item_columns = array(); |
|
| 300 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
| 301 | + $fields = array( |
|
| 302 | + 'post_id' => $invoice->ID, |
|
| 303 | + 'item_id' => $details['id'], |
|
| 304 | + 'item_name' => $details['name'], |
|
| 305 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
| 306 | + 'vat_rate' => $details['vat_rate'], |
|
| 307 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
| 308 | + 'tax' => $details['tax'], |
|
| 309 | + 'item_price' => $details['item_price'], |
|
| 310 | + 'custom_price' => $details['custom_price'], |
|
| 311 | + 'quantity' => $details['quantity'], |
|
| 312 | + 'discount' => $details['discount'], |
|
| 313 | + 'subtotal' => $details['subtotal'], |
|
| 314 | + 'price' => $details['price'], |
|
| 315 | + 'meta' => $details['meta'], |
|
| 316 | + 'fees' => $details['fees'], |
|
| 317 | + ); |
|
| 318 | + |
|
| 319 | + $item_columns = array_keys( $fields ); |
|
| 320 | + |
|
| 321 | + foreach ( $fields as $key => $val ) { |
|
| 322 | + if ( is_null( $val ) ) { |
|
| 323 | + $val = ''; |
|
| 324 | + } |
|
| 325 | + $val = maybe_serialize( $val ); |
|
| 326 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + $fields = implode( ', ', $fields ); |
|
| 330 | + $item_rows[] = "($fields)"; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + $item_rows = implode( ', ', $item_rows ); |
|
| 334 | + $item_columns = implode( ', ', $item_columns ); |
|
| 335 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if ( empty( $invoice_rows ) ) { |
|
| 339 | + return; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
| 343 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Migrates old customers to new table. |
|
| 348 | + * |
|
| 349 | + */ |
|
| 350 | + public static function migrate_old_customers() { |
|
| 351 | + global $wpdb; |
|
| 352 | + |
|
| 353 | + // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
|
| 354 | + $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
| 355 | + |
|
| 356 | + foreach ( $invoice_ids as $invoice_id ) { |
|
| 357 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 358 | + |
|
| 359 | + if ( empty( $invoice ) ) { |
|
| 360 | + continue; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // Fetch customer from the user ID. |
|
| 364 | + $user_id = $invoice->get_user_id(); |
|
| 365 | + |
|
| 366 | + if ( empty( $user_id ) ) { |
|
| 367 | + continue; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
| 371 | + |
|
| 372 | + // Create if not exists. |
|
| 373 | + if ( empty( $customer ) ) { |
|
| 374 | + $customer = new GetPaid_Customer( 0 ); |
|
| 375 | + $customer->clone_user( $user_id ); |
|
| 376 | + $customer->save(); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + $invoice->set_customer_id( $customer->get_id() ); |
|
| 380 | + $invoice->save(); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Migrates old invoices to new invoices. |
|
| 386 | + * |
|
| 387 | + */ |
|
| 388 | + public static function rename_gateways_label() { |
|
| 389 | + global $wpdb; |
|
| 390 | + |
|
| 391 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
| 392 | + |
|
| 393 | + $wpdb->update( |
|
| 394 | + $wpdb->prefix . 'getpaid_invoices', |
|
| 395 | + array( 'gateway' => $gateway ), |
|
| 396 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
| 397 | + '%s', |
|
| 398 | + '%s' |
|
| 399 | + ); |
|
| 400 | + |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Returns the DB schema. |
|
| 406 | + * |
|
| 407 | + */ |
|
| 408 | + public static function get_db_schema() { |
|
| 409 | + global $wpdb; |
|
| 410 | + |
|
| 411 | + if ( ! empty( self::$schema ) ) { |
|
| 412 | + return self::$schema; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 416 | + |
|
| 417 | + $charset_collate = $wpdb->get_charset_collate(); |
|
| 418 | + |
|
| 419 | + $schema = array(); |
|
| 420 | + |
|
| 421 | + // Subscriptions. |
|
| 422 | + $schema['subscriptions'] = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
| 423 | 423 | id bigint(20) unsigned NOT NULL auto_increment, |
| 424 | 424 | customer_id bigint(20) NOT NULL, |
| 425 | 425 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -442,8 +442,8 @@ discard block |
||
| 442 | 442 | KEY customer_and_status (customer_id, status) |
| 443 | 443 | ) $charset_collate;"; |
| 444 | 444 | |
| 445 | - // Invoices. |
|
| 446 | - $schema['invoices'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
| 445 | + // Invoices. |
|
| 446 | + $schema['invoices'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
| 447 | 447 | post_id BIGINT(20) NOT NULL, |
| 448 | 448 | customer_id BIGINT(20) NOT NULL DEFAULT 0, |
| 449 | 449 | `number` VARCHAR(100), |
@@ -481,8 +481,8 @@ discard block |
||
| 481 | 481 | KEY invoice_key (invoice_key) |
| 482 | 482 | ) $charset_collate;"; |
| 483 | 483 | |
| 484 | - // Invoice items. |
|
| 485 | - $schema['items'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
| 484 | + // Invoice items. |
|
| 485 | + $schema['items'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
| 486 | 486 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
| 487 | 487 | post_id BIGINT(20) NOT NULL, |
| 488 | 488 | item_id BIGINT(20) NOT NULL, |
@@ -504,8 +504,8 @@ discard block |
||
| 504 | 504 | KEY post_id (post_id) |
| 505 | 505 | ) $charset_collate;"; |
| 506 | 506 | |
| 507 | - // Customers. |
|
| 508 | - $schema['customers'] = "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
| 507 | + // Customers. |
|
| 508 | + $schema['customers'] = "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
| 509 | 509 | id BIGINT(20) NOT NULL AUTO_INCREMENT, |
| 510 | 510 | user_id BIGINT(20) NOT NULL, |
| 511 | 511 | email VARCHAR(100) NOT NULL, |
@@ -515,38 +515,38 @@ discard block |
||
| 515 | 515 | purchase_count BIGINT(20) NOT NULL DEFAULT 0, |
| 516 | 516 | "; |
| 517 | 517 | |
| 518 | - // Add address fields. |
|
| 519 | - foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) { |
|
| 520 | - // Skip id, user_id and email. |
|
| 521 | - if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
| 522 | - continue; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $field = sanitize_key( $field ); |
|
| 526 | - $length = 100; |
|
| 527 | - $default = ''; |
|
| 528 | - |
|
| 529 | - // Country. |
|
| 530 | - if ( 'country' === $field ) { |
|
| 531 | - $length = 2; |
|
| 532 | - $default = wpinv_get_default_country(); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - // State. |
|
| 536 | - if ( 'state' === $field ) { |
|
| 537 | - $default = wpinv_get_default_state(); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // Phone, zip. |
|
| 541 | - if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
| 542 | - $length = 20; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - $schema['customers'] .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default', |
|
| 518 | + // Add address fields. |
|
| 519 | + foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) { |
|
| 520 | + // Skip id, user_id and email. |
|
| 521 | + if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
| 522 | + continue; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $field = sanitize_key( $field ); |
|
| 526 | + $length = 100; |
|
| 527 | + $default = ''; |
|
| 528 | + |
|
| 529 | + // Country. |
|
| 530 | + if ( 'country' === $field ) { |
|
| 531 | + $length = 2; |
|
| 532 | + $default = wpinv_get_default_country(); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + // State. |
|
| 536 | + if ( 'state' === $field ) { |
|
| 537 | + $default = wpinv_get_default_state(); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // Phone, zip. |
|
| 541 | + if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
| 542 | + $length = 20; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + $schema['customers'] .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default', |
|
| 546 | 546 | "; |
| 547 | - } |
|
| 547 | + } |
|
| 548 | 548 | |
| 549 | - $schema['customers'] .= "date_created DATETIME NOT NULL, |
|
| 549 | + $schema['customers'] .= "date_created DATETIME NOT NULL, |
|
| 550 | 550 | date_modified DATETIME NOT NULL, |
| 551 | 551 | uuid VARCHAR(100) NOT NULL, |
| 552 | 552 | is_anonymized INT(2) NOT NULL DEFAULT 0, |
@@ -556,8 +556,8 @@ discard block |
||
| 556 | 556 | KEY email (email) |
| 557 | 557 | ) $charset_collate;"; |
| 558 | 558 | |
| 559 | - // Customer meta. |
|
| 560 | - $schema['customer_meta'] = "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
| 559 | + // Customer meta. |
|
| 560 | + $schema['customer_meta'] = "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
| 561 | 561 | meta_id BIGINT(20) NOT NULL AUTO_INCREMENT, |
| 562 | 562 | customer_id BIGINT(20) NOT NULL, |
| 563 | 563 | meta_key VARCHAR(255) NOT NULL, |
@@ -582,75 +582,75 @@ discard block |
||
| 582 | 582 | KEY timestamp (timestamp) |
| 583 | 583 | ) $charset_collate;"; |
| 584 | 584 | |
| 585 | - // Filter. |
|
| 586 | - $schema = apply_filters( 'getpaid_db_schema', $schema ); |
|
| 587 | - |
|
| 588 | - self::$schema = implode( "\n", array_values( $schema ) ); |
|
| 589 | - self::$schema_version = md5( sanitize_key( self::$schema ) ); |
|
| 590 | - |
|
| 591 | - return self::$schema; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Returns the DB schema version. |
|
| 596 | - * |
|
| 597 | - */ |
|
| 598 | - public static function get_db_schema_version() { |
|
| 599 | - if ( ! empty( self::$schema_version ) ) { |
|
| 600 | - return self::$schema_version; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - self::get_db_schema(); |
|
| 604 | - |
|
| 605 | - return self::$schema_version; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Checks if the db schema is up to date. |
|
| 610 | - * |
|
| 611 | - * @return bool |
|
| 612 | - */ |
|
| 613 | - public static function is_db_schema_up_to_date() { |
|
| 614 | - return self::get_db_schema_version() === get_option( 'getpaid_db_schema' ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Set up the database tables which the plugin needs to function. |
|
| 619 | - */ |
|
| 620 | - public static function create_db_tables() { |
|
| 621 | - global $wpdb; |
|
| 622 | - |
|
| 623 | - $wpdb->hide_errors(); |
|
| 624 | - |
|
| 625 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 626 | - |
|
| 627 | - $schema = self::get_db_schema(); |
|
| 628 | - |
|
| 629 | - // If invoices table exists, rename key to invoice_key. |
|
| 630 | - $invoices_table = "{$wpdb->prefix}getpaid_invoices"; |
|
| 631 | - |
|
| 632 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) { |
|
| 633 | - $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" ); |
|
| 634 | - |
|
| 635 | - foreach ( $fields as $field ) { |
|
| 636 | - if ( 'key' === $field->Field ) { |
|
| 637 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" ); |
|
| 638 | - break; |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - dbDelta( $schema ); |
|
| 644 | - wp_cache_flush(); |
|
| 645 | - update_option( 'getpaid_db_schema', self::get_db_schema_version() ); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * Creates tables if schema is not up to date. |
|
| 650 | - */ |
|
| 651 | - public static function maybe_create_db_tables() { |
|
| 652 | - if ( ! self::is_db_schema_up_to_date() ) { |
|
| 653 | - self::create_db_tables(); |
|
| 654 | - } |
|
| 655 | - } |
|
| 585 | + // Filter. |
|
| 586 | + $schema = apply_filters( 'getpaid_db_schema', $schema ); |
|
| 587 | + |
|
| 588 | + self::$schema = implode( "\n", array_values( $schema ) ); |
|
| 589 | + self::$schema_version = md5( sanitize_key( self::$schema ) ); |
|
| 590 | + |
|
| 591 | + return self::$schema; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Returns the DB schema version. |
|
| 596 | + * |
|
| 597 | + */ |
|
| 598 | + public static function get_db_schema_version() { |
|
| 599 | + if ( ! empty( self::$schema_version ) ) { |
|
| 600 | + return self::$schema_version; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + self::get_db_schema(); |
|
| 604 | + |
|
| 605 | + return self::$schema_version; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Checks if the db schema is up to date. |
|
| 610 | + * |
|
| 611 | + * @return bool |
|
| 612 | + */ |
|
| 613 | + public static function is_db_schema_up_to_date() { |
|
| 614 | + return self::get_db_schema_version() === get_option( 'getpaid_db_schema' ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Set up the database tables which the plugin needs to function. |
|
| 619 | + */ |
|
| 620 | + public static function create_db_tables() { |
|
| 621 | + global $wpdb; |
|
| 622 | + |
|
| 623 | + $wpdb->hide_errors(); |
|
| 624 | + |
|
| 625 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 626 | + |
|
| 627 | + $schema = self::get_db_schema(); |
|
| 628 | + |
|
| 629 | + // If invoices table exists, rename key to invoice_key. |
|
| 630 | + $invoices_table = "{$wpdb->prefix}getpaid_invoices"; |
|
| 631 | + |
|
| 632 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) { |
|
| 633 | + $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" ); |
|
| 634 | + |
|
| 635 | + foreach ( $fields as $field ) { |
|
| 636 | + if ( 'key' === $field->Field ) { |
|
| 637 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" ); |
|
| 638 | + break; |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + dbDelta( $schema ); |
|
| 644 | + wp_cache_flush(); |
|
| 645 | + update_option( 'getpaid_db_schema', self::get_db_schema_version() ); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * Creates tables if schema is not up to date. |
|
| 650 | + */ |
|
| 651 | + public static function maybe_create_db_tables() { |
|
| 652 | + if ( ! self::is_db_schema_up_to_date() ) { |
|
| 653 | + self::create_db_tables(); |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | 656 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @since 2.0.2 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * The main installer/updater class. |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @param string $upgrade_from The current invoicing version. |
| 30 | 30 | */ |
| 31 | - public function upgrade_db( $upgrade_from ) { |
|
| 31 | + public function upgrade_db($upgrade_from) { |
|
| 32 | 32 | |
| 33 | 33 | // Save the current invoicing version. |
| 34 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
| 34 | + update_option('wpinv_version', WPINV_VERSION); |
|
| 35 | 35 | |
| 36 | 36 | // Setup the invoice Custom Post Type. |
| 37 | 37 | GetPaid_Post_Types::register_post_types(); |
@@ -51,13 +51,13 @@ discard block |
||
| 51 | 51 | // Create any missing database tables. |
| 52 | 52 | $method = "upgrade_from_$upgrade_from"; |
| 53 | 53 | |
| 54 | - $installed = get_option( 'gepaid_installed_on' ); |
|
| 54 | + $installed = get_option('gepaid_installed_on'); |
|
| 55 | 55 | |
| 56 | - if ( empty( $installed ) ) { |
|
| 57 | - update_option( 'gepaid_installed_on', time() ); |
|
| 56 | + if (empty($installed)) { |
|
| 57 | + update_option('gepaid_installed_on', time()); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if ( method_exists( $this, $method ) ) { |
|
| 60 | + if (method_exists($this, $method)) { |
|
| 61 | 61 | $this->$method(); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | public function upgrade_from_0() { |
| 70 | 70 | |
| 71 | 71 | // Save default tax rates. |
| 72 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 72 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -80,27 +80,27 @@ discard block |
||
| 80 | 80 | global $wpdb; |
| 81 | 81 | |
| 82 | 82 | // Invoices. |
| 83 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 84 | - if ( ! empty( $results ) ) { |
|
| 85 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
| 83 | + $results = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
| 84 | + if (!empty($results)) { |
|
| 85 | + $wpdb->query("UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
| 86 | 86 | |
| 87 | 87 | // Clean post cache |
| 88 | - foreach ( $results as $row ) { |
|
| 89 | - clean_post_cache( $row->ID ); |
|
| 88 | + foreach ($results as $row) { |
|
| 89 | + clean_post_cache($row->ID); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Item meta key changes |
| 94 | 94 | $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
| 95 | - $results = $wpdb->get_results( $query ); |
|
| 95 | + $results = $wpdb->get_results($query); |
|
| 96 | 96 | |
| 97 | - if ( ! empty( $results ) ) { |
|
| 98 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
| 99 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
| 100 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
| 97 | + if (!empty($results)) { |
|
| 98 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
| 99 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
| 100 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
| 101 | 101 | |
| 102 | - foreach ( $results as $row ) { |
|
| 103 | - clean_post_cache( $row->post_id ); |
|
| 102 | + foreach ($results as $row) { |
|
| 103 | + clean_post_cache($row->post_id); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | */ |
| 131 | 131 | public function add_capabilities() { |
| 132 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
| 132 | + $GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing'); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | // Checkout page. |
| 146 | 146 | 'checkout_page' => array( |
| 147 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
| 148 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
| 147 | + 'name' => _x('gp-checkout', 'Page slug', 'invoicing'), |
|
| 148 | + 'title' => _x('Checkout', 'Page title', 'invoicing'), |
|
| 149 | 149 | 'content' => ' |
| 150 | 150 | <!-- wp:shortcode --> |
| 151 | 151 | [wpinv_checkout] |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | // Invoice history page. |
| 158 | 158 | 'invoice_history_page' => array( |
| 159 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
| 160 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
| 159 | + 'name' => _x('gp-invoices', 'Page slug', 'invoicing'), |
|
| 160 | + 'title' => _x('My Invoices', 'Page title', 'invoicing'), |
|
| 161 | 161 | 'content' => ' |
| 162 | 162 | <!-- wp:shortcode --> |
| 163 | 163 | [wpinv_history] |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // Success page content. |
| 170 | 170 | 'success_page' => array( |
| 171 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
| 172 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
| 171 | + 'name' => _x('gp-receipt', 'Page slug', 'invoicing'), |
|
| 172 | + 'title' => _x('Payment Confirmation', 'Page title', 'invoicing'), |
|
| 173 | 173 | 'content' => ' |
| 174 | 174 | <!-- wp:shortcode --> |
| 175 | 175 | [wpinv_receipt] |
@@ -180,16 +180,16 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | // Failure page content. |
| 182 | 182 | 'failure_page' => array( |
| 183 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
| 184 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
| 185 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
| 183 | + 'name' => _x('gp-transaction-failed', 'Page slug', 'invoicing'), |
|
| 184 | + 'title' => _x('Transaction Failed', 'Page title', 'invoicing'), |
|
| 185 | + 'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'), |
|
| 186 | 186 | 'parent' => 'gp-checkout', |
| 187 | 187 | ), |
| 188 | 188 | |
| 189 | 189 | // Subscriptions history page. |
| 190 | 190 | 'invoice_subscription_page' => array( |
| 191 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
| 192 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
| 191 | + 'name' => _x('gp-subscriptions', 'Page slug', 'invoicing'), |
|
| 192 | + 'title' => _x('My Subscriptions', 'Page title', 'invoicing'), |
|
| 193 | 193 | 'content' => ' |
| 194 | 194 | <!-- wp:shortcode --> |
| 195 | 195 | [wpinv_subscriptions] |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | public function create_pages() { |
| 210 | 210 | |
| 211 | - foreach ( self::get_pages() as $key => $page ) { |
|
| 212 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
| 211 | + foreach (self::get_pages() as $key => $page) { |
|
| 212 | + wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
@@ -222,32 +222,32 @@ discard block |
||
| 222 | 222 | |
| 223 | 223 | $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
| 224 | 224 | $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
| 225 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
| 225 | + $migrated = $wpdb->get_col("SELECT post_id FROM $invoices_table"); |
|
| 226 | 226 | $invoices = array_unique( |
| 227 | 227 | get_posts( |
| 228 | 228 | array( |
| 229 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
| 229 | + 'post_type' => array('wpi_invoice', 'wpi_quote'), |
|
| 230 | 230 | 'posts_per_page' => -1, |
| 231 | 231 | 'fields' => 'ids', |
| 232 | - 'post_status' => array_keys( get_post_stati() ), |
|
| 232 | + 'post_status' => array_keys(get_post_stati()), |
|
| 233 | 233 | 'exclude' => (array) $migrated, |
| 234 | 234 | ) |
| 235 | 235 | ) |
| 236 | 236 | ); |
| 237 | 237 | |
| 238 | 238 | // Abort if we do not have any invoices. |
| 239 | - if ( empty( $invoices ) ) { |
|
| 239 | + if (empty($invoices)) { |
|
| 240 | 240 | return; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
| 244 | 244 | |
| 245 | 245 | $invoice_rows = array(); |
| 246 | - foreach ( $invoices as $invoice ) { |
|
| 246 | + foreach ($invoices as $invoice) { |
|
| 247 | 247 | |
| 248 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
| 248 | + $invoice = new WPInv_Legacy_Invoice($invoice); |
|
| 249 | 249 | |
| 250 | - if ( empty( $invoice->ID ) ) { |
|
| 250 | + if (empty($invoice->ID)) { |
|
| 251 | 251 | return; |
| 252 | 252 | } |
| 253 | 253 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | 'post_id' => $invoice->ID, |
| 256 | 256 | 'number' => $invoice->get_number(), |
| 257 | 257 | 'key' => $invoice->get_key(), |
| 258 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
| 258 | + 'type' => str_replace('wpi_', '', $invoice->post_type), |
|
| 259 | 259 | 'mode' => $invoice->mode, |
| 260 | 260 | 'user_ip' => $invoice->get_ip(), |
| 261 | 261 | 'first_name' => $invoice->get_first_name(), |
@@ -284,27 +284,27 @@ discard block |
||
| 284 | 284 | 'custom_meta' => $invoice->payment_meta, |
| 285 | 285 | ); |
| 286 | 286 | |
| 287 | - foreach ( $fields as $key => $val ) { |
|
| 288 | - if ( is_null( $val ) ) { |
|
| 287 | + foreach ($fields as $key => $val) { |
|
| 288 | + if (is_null($val)) { |
|
| 289 | 289 | $val = ''; |
| 290 | 290 | } |
| 291 | - $val = maybe_serialize( $val ); |
|
| 292 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 291 | + $val = maybe_serialize($val); |
|
| 292 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - $fields = implode( ', ', $fields ); |
|
| 295 | + $fields = implode(', ', $fields); |
|
| 296 | 296 | $invoice_rows[] = "($fields)"; |
| 297 | 297 | |
| 298 | 298 | $item_rows = array(); |
| 299 | 299 | $item_columns = array(); |
| 300 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
| 300 | + foreach ($invoice->get_cart_details() as $details) { |
|
| 301 | 301 | $fields = array( |
| 302 | 302 | 'post_id' => $invoice->ID, |
| 303 | 303 | 'item_id' => $details['id'], |
| 304 | 304 | 'item_name' => $details['name'], |
| 305 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
| 305 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
| 306 | 306 | 'vat_rate' => $details['vat_rate'], |
| 307 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
| 307 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
| 308 | 308 | 'tax' => $details['tax'], |
| 309 | 309 | 'item_price' => $details['item_price'], |
| 310 | 310 | 'custom_price' => $details['custom_price'], |
@@ -316,31 +316,31 @@ discard block |
||
| 316 | 316 | 'fees' => $details['fees'], |
| 317 | 317 | ); |
| 318 | 318 | |
| 319 | - $item_columns = array_keys( $fields ); |
|
| 319 | + $item_columns = array_keys($fields); |
|
| 320 | 320 | |
| 321 | - foreach ( $fields as $key => $val ) { |
|
| 322 | - if ( is_null( $val ) ) { |
|
| 321 | + foreach ($fields as $key => $val) { |
|
| 322 | + if (is_null($val)) { |
|
| 323 | 323 | $val = ''; |
| 324 | 324 | } |
| 325 | - $val = maybe_serialize( $val ); |
|
| 326 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 325 | + $val = maybe_serialize($val); |
|
| 326 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - $fields = implode( ', ', $fields ); |
|
| 329 | + $fields = implode(', ', $fields); |
|
| 330 | 330 | $item_rows[] = "($fields)"; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - $item_rows = implode( ', ', $item_rows ); |
|
| 334 | - $item_columns = implode( ', ', $item_columns ); |
|
| 335 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
| 333 | + $item_rows = implode(', ', $item_rows); |
|
| 334 | + $item_columns = implode(', ', $item_columns); |
|
| 335 | + $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows"); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if ( empty( $invoice_rows ) ) { |
|
| 338 | + if (empty($invoice_rows)) { |
|
| 339 | 339 | return; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
| 343 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
| 342 | + $invoice_rows = implode(', ', $invoice_rows); |
|
| 343 | + $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows"); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | /** |
@@ -351,32 +351,32 @@ discard block |
||
| 351 | 351 | global $wpdb; |
| 352 | 352 | |
| 353 | 353 | // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
| 354 | - $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
| 354 | + $invoice_ids = $wpdb->get_col("SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL"); |
|
| 355 | 355 | |
| 356 | - foreach ( $invoice_ids as $invoice_id ) { |
|
| 357 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 356 | + foreach ($invoice_ids as $invoice_id) { |
|
| 357 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 358 | 358 | |
| 359 | - if ( empty( $invoice ) ) { |
|
| 359 | + if (empty($invoice)) { |
|
| 360 | 360 | continue; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // Fetch customer from the user ID. |
| 364 | 364 | $user_id = $invoice->get_user_id(); |
| 365 | 365 | |
| 366 | - if ( empty( $user_id ) ) { |
|
| 366 | + if (empty($user_id)) { |
|
| 367 | 367 | continue; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
| 370 | + $customer = getpaid_get_customer_by_user_id($user_id); |
|
| 371 | 371 | |
| 372 | 372 | // Create if not exists. |
| 373 | - if ( empty( $customer ) ) { |
|
| 374 | - $customer = new GetPaid_Customer( 0 ); |
|
| 375 | - $customer->clone_user( $user_id ); |
|
| 373 | + if (empty($customer)) { |
|
| 374 | + $customer = new GetPaid_Customer(0); |
|
| 375 | + $customer->clone_user($user_id); |
|
| 376 | 376 | $customer->save(); |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - $invoice->set_customer_id( $customer->get_id() ); |
|
| 379 | + $invoice->set_customer_id($customer->get_id()); |
|
| 380 | 380 | $invoice->save(); |
| 381 | 381 | } |
| 382 | 382 | } |
@@ -388,12 +388,12 @@ discard block |
||
| 388 | 388 | public static function rename_gateways_label() { |
| 389 | 389 | global $wpdb; |
| 390 | 390 | |
| 391 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
| 391 | + foreach (array_keys(wpinv_get_payment_gateways()) as $gateway) { |
|
| 392 | 392 | |
| 393 | 393 | $wpdb->update( |
| 394 | 394 | $wpdb->prefix . 'getpaid_invoices', |
| 395 | - array( 'gateway' => $gateway ), |
|
| 396 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
| 395 | + array('gateway' => $gateway), |
|
| 396 | + array('gateway' => wpinv_get_gateway_admin_label($gateway)), |
|
| 397 | 397 | '%s', |
| 398 | 398 | '%s' |
| 399 | 399 | ); |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | public static function get_db_schema() { |
| 409 | 409 | global $wpdb; |
| 410 | 410 | |
| 411 | - if ( ! empty( self::$schema ) ) { |
|
| 411 | + if (!empty(self::$schema)) { |
|
| 412 | 412 | return self::$schema; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -516,29 +516,29 @@ discard block |
||
| 516 | 516 | "; |
| 517 | 517 | |
| 518 | 518 | // Add address fields. |
| 519 | - foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) { |
|
| 519 | + foreach (array_keys(getpaid_user_address_fields(true)) as $field) { |
|
| 520 | 520 | // Skip id, user_id and email. |
| 521 | - if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
| 521 | + if (in_array($field, array('id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid'), true)) { |
|
| 522 | 522 | continue; |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - $field = sanitize_key( $field ); |
|
| 525 | + $field = sanitize_key($field); |
|
| 526 | 526 | $length = 100; |
| 527 | 527 | $default = ''; |
| 528 | 528 | |
| 529 | 529 | // Country. |
| 530 | - if ( 'country' === $field ) { |
|
| 530 | + if ('country' === $field) { |
|
| 531 | 531 | $length = 2; |
| 532 | 532 | $default = wpinv_get_default_country(); |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | // State. |
| 536 | - if ( 'state' === $field ) { |
|
| 536 | + if ('state' === $field) { |
|
| 537 | 537 | $default = wpinv_get_default_state(); |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | // Phone, zip. |
| 541 | - if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
| 541 | + if (in_array($field, array('phone', 'zip'), true)) { |
|
| 542 | 542 | $length = 20; |
| 543 | 543 | } |
| 544 | 544 | |
@@ -583,10 +583,10 @@ discard block |
||
| 583 | 583 | ) $charset_collate;"; |
| 584 | 584 | |
| 585 | 585 | // Filter. |
| 586 | - $schema = apply_filters( 'getpaid_db_schema', $schema ); |
|
| 586 | + $schema = apply_filters('getpaid_db_schema', $schema); |
|
| 587 | 587 | |
| 588 | - self::$schema = implode( "\n", array_values( $schema ) ); |
|
| 589 | - self::$schema_version = md5( sanitize_key( self::$schema ) ); |
|
| 588 | + self::$schema = implode("\n", array_values($schema)); |
|
| 589 | + self::$schema_version = md5(sanitize_key(self::$schema)); |
|
| 590 | 590 | |
| 591 | 591 | return self::$schema; |
| 592 | 592 | } |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | * |
| 597 | 597 | */ |
| 598 | 598 | public static function get_db_schema_version() { |
| 599 | - if ( ! empty( self::$schema_version ) ) { |
|
| 599 | + if (!empty(self::$schema_version)) { |
|
| 600 | 600 | return self::$schema_version; |
| 601 | 601 | } |
| 602 | 602 | |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * @return bool |
| 612 | 612 | */ |
| 613 | 613 | public static function is_db_schema_up_to_date() { |
| 614 | - return self::get_db_schema_version() === get_option( 'getpaid_db_schema' ); |
|
| 614 | + return self::get_db_schema_version() === get_option('getpaid_db_schema'); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -629,27 +629,27 @@ discard block |
||
| 629 | 629 | // If invoices table exists, rename key to invoice_key. |
| 630 | 630 | $invoices_table = "{$wpdb->prefix}getpaid_invoices"; |
| 631 | 631 | |
| 632 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) { |
|
| 633 | - $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" ); |
|
| 632 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") === $invoices_table) { |
|
| 633 | + $fields = $wpdb->get_results("SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices"); |
|
| 634 | 634 | |
| 635 | - foreach ( $fields as $field ) { |
|
| 636 | - if ( 'key' === $field->Field ) { |
|
| 637 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" ); |
|
| 635 | + foreach ($fields as $field) { |
|
| 636 | + if ('key' === $field->Field) { |
|
| 637 | + $wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)"); |
|
| 638 | 638 | break; |
| 639 | 639 | } |
| 640 | 640 | } |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - dbDelta( $schema ); |
|
| 643 | + dbDelta($schema); |
|
| 644 | 644 | wp_cache_flush(); |
| 645 | - update_option( 'getpaid_db_schema', self::get_db_schema_version() ); |
|
| 645 | + update_option('getpaid_db_schema', self::get_db_schema_version()); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | /** |
| 649 | 649 | * Creates tables if schema is not up to date. |
| 650 | 650 | */ |
| 651 | 651 | public static function maybe_create_db_tables() { |
| 652 | - if ( ! self::is_db_schema_up_to_date() ) { |
|
| 652 | + if (!self::is_db_schema_up_to_date()) { |
|
| 653 | 653 | self::create_db_tables(); |
| 654 | 654 | } |
| 655 | 655 | } |
@@ -34,12 +34,12 @@ |
||
| 34 | 34 | // Prepare pagination |
| 35 | 35 | $pagination = paginate_links( |
| 36 | 36 | array( |
| 37 | - 'base' => add_query_arg( 'paged', '%#%' ), |
|
| 38 | - 'format' => '', |
|
| 39 | - 'prev_text' => __( '«', 'invoicing' ), |
|
| 40 | - 'next_text' => __( '»', 'invoicing' ), |
|
| 41 | - 'total' => ceil( $total_logs / $per_page ), |
|
| 42 | - 'current' => $page, |
|
| 37 | + 'base' => add_query_arg( 'paged', '%#%' ), |
|
| 38 | + 'format' => '', |
|
| 39 | + 'prev_text' => __( '«', 'invoicing' ), |
|
| 40 | + 'next_text' => __( '»', 'invoicing' ), |
|
| 41 | + 'total' => ceil( $total_logs / $per_page ), |
|
| 42 | + 'current' => $page, |
|
| 43 | 43 | ) |
| 44 | 44 | ); |
| 45 | 45 | |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @since 2.8.22 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * GetPaid_Anonymization_Logs Class |
@@ -19,89 +19,89 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | public function display_logs() { |
| 21 | 21 | // Check user capabilities |
| 22 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 22 | + if (!current_user_can('manage_options')) { |
|
| 23 | 23 | return; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Get current page number |
| 27 | - $page = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 27 | + $page = isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 28 | 28 | $per_page = 20; |
| 29 | 29 | |
| 30 | 30 | // Fetch logs |
| 31 | - $logs = $this->get_logs( $page, $per_page ); |
|
| 31 | + $logs = $this->get_logs($page, $per_page); |
|
| 32 | 32 | $total_logs = $this->get_total_logs(); |
| 33 | 33 | |
| 34 | 34 | // Prepare pagination |
| 35 | 35 | $pagination = paginate_links( |
| 36 | 36 | array( |
| 37 | - 'base' => add_query_arg( 'paged', '%#%' ), |
|
| 37 | + 'base' => add_query_arg('paged', '%#%'), |
|
| 38 | 38 | 'format' => '', |
| 39 | - 'prev_text' => __( '«', 'invoicing' ), |
|
| 40 | - 'next_text' => __( '»', 'invoicing' ), |
|
| 41 | - 'total' => ceil( $total_logs / $per_page ), |
|
| 39 | + 'prev_text' => __('«', 'invoicing'), |
|
| 40 | + 'next_text' => __('»', 'invoicing'), |
|
| 41 | + 'total' => ceil($total_logs / $per_page), |
|
| 42 | 42 | 'current' => $page, |
| 43 | 43 | ) |
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | 46 | ?> |
| 47 | 47 | <div class="wrap getpaid-anonymization-logs"> |
| 48 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
| 48 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
| 49 | 49 | <div class="tablenav top"> |
| 50 | 50 | <div class="alignleft actions"> |
| 51 | 51 | <form method="get"> |
| 52 | 52 | <input type="hidden" name="page" value="wpinv-anonymization-logs"> |
| 53 | - <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date', 'invoicing' ); ?></label> |
|
| 53 | + <label for="filter-by-date" class="screen-reader-text"><?php _e('Filter by date', 'invoicing'); ?></label> |
|
| 54 | 54 | <select name="m" id="filter-by-date"> |
| 55 | - <option value="0"><?php _e( 'All dates', 'invoicing' ); ?></option> |
|
| 55 | + <option value="0"><?php _e('All dates', 'invoicing'); ?></option> |
|
| 56 | 56 | <?php |
| 57 | 57 | $months = $this->get_log_months(); |
| 58 | - foreach ( $months as $month ) { |
|
| 59 | - $selected = ( isset( $_GET['m'] ) && $_GET['m'] == $month->month ) ? ' selected="selected"' : ''; |
|
| 60 | - echo '<option value="' . esc_attr( $month->month ) . '"' . $selected . '>' . esc_html( $month->month_name . ' ' . $month->year ) . '</option>'; |
|
| 58 | + foreach ($months as $month) { |
|
| 59 | + $selected = (isset($_GET['m']) && $_GET['m'] == $month->month) ? ' selected="selected"' : ''; |
|
| 60 | + echo '<option value="' . esc_attr($month->month) . '"' . $selected . '>' . esc_html($month->month_name . ' ' . $month->year) . '</option>'; |
|
| 61 | 61 | } |
| 62 | 62 | ?> |
| 63 | 63 | </select> |
| 64 | - <?php submit_button( __( 'Filter', 'invoicing' ), '', 'filter_action', false ); ?> |
|
| 64 | + <?php submit_button(__('Filter', 'invoicing'), '', 'filter_action', false); ?> |
|
| 65 | 65 | </form> |
| 66 | 66 | </div> |
| 67 | 67 | </div> |
| 68 | 68 | <table class="wp-list-table widefat fixed striped"> |
| 69 | 69 | <thead> |
| 70 | 70 | <tr> |
| 71 | - <th><?php _e( 'Log ID', 'invoicing' ); ?></th> |
|
| 72 | - <th><?php _e( 'User', 'invoicing' ); ?></th> |
|
| 73 | - <th><?php _e( 'Action', 'invoicing' ); ?></th> |
|
| 74 | - <th><?php _e( 'Date', 'invoicing' ); ?></th> |
|
| 75 | - <th><?php _e( 'Details', 'invoicing' ); ?></th> |
|
| 71 | + <th><?php _e('Log ID', 'invoicing'); ?></th> |
|
| 72 | + <th><?php _e('User', 'invoicing'); ?></th> |
|
| 73 | + <th><?php _e('Action', 'invoicing'); ?></th> |
|
| 74 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
| 75 | + <th><?php _e('Details', 'invoicing'); ?></th> |
|
| 76 | 76 | </tr> |
| 77 | 77 | </thead> |
| 78 | 78 | <tbody> |
| 79 | - <?php if ( empty( $logs ) ) : ?> |
|
| 79 | + <?php if (empty($logs)) : ?> |
|
| 80 | 80 | <tr> |
| 81 | - <td colspan="5"><?php _e( 'No anonymization logs found.', 'invoicing' ); ?></td> |
|
| 81 | + <td colspan="5"><?php _e('No anonymization logs found.', 'invoicing'); ?></td> |
|
| 82 | 82 | </tr> |
| 83 | 83 | <?php else : ?> |
| 84 | 84 | <?php |
| 85 | - foreach ( $logs as $log ) : |
|
| 86 | - $additional_info = json_decode( $log->additional_info, true ); |
|
| 85 | + foreach ($logs as $log) : |
|
| 86 | + $additional_info = json_decode($log->additional_info, true); |
|
| 87 | 87 | ?> |
| 88 | 88 | <tr> |
| 89 | - <td><?php echo esc_html( $log->log_id ); ?></td> |
|
| 89 | + <td><?php echo esc_html($log->log_id); ?></td> |
|
| 90 | 90 | <td> |
| 91 | 91 | <?php |
| 92 | - $user_edit_link = get_edit_user_link( $log->user_id ); |
|
| 93 | - if ( $user_edit_link ) { |
|
| 94 | - echo '<a href="' . esc_url( $user_edit_link ) . '">' . esc_html( $log->user_id ) . '</a>'; |
|
| 92 | + $user_edit_link = get_edit_user_link($log->user_id); |
|
| 93 | + if ($user_edit_link) { |
|
| 94 | + echo '<a href="' . esc_url($user_edit_link) . '">' . esc_html($log->user_id) . '</a>'; |
|
| 95 | 95 | } else { |
| 96 | - echo esc_html( $log->user_id ); |
|
| 96 | + echo esc_html($log->user_id); |
|
| 97 | 97 | } |
| 98 | 98 | ?> |
| 99 | 99 | </td> |
| 100 | - <td><?php echo esc_html( ucfirst( $log->action ) ); ?></td> |
|
| 101 | - <td><?php echo esc_html( get_date_from_gmt( $log->timestamp, 'F j, Y g:i a' ) ); ?></td> |
|
| 100 | + <td><?php echo esc_html(ucfirst($log->action)); ?></td> |
|
| 101 | + <td><?php echo esc_html(get_date_from_gmt($log->timestamp, 'F j, Y g:i a')); ?></td> |
|
| 102 | 102 | <td> |
| 103 | 103 | <button class="button-link toggle-details" type="button" aria-expanded="false"> |
| 104 | - <span class="screen-reader-text"><?php _e( 'Show more details', 'invoicing' ); ?></span> |
|
| 104 | + <span class="screen-reader-text"><?php _e('Show more details', 'invoicing'); ?></span> |
|
| 105 | 105 | <span class="dashicons dashicons-arrow-down-alt2"></span> |
| 106 | 106 | </button> |
| 107 | 107 | </td> |
@@ -112,19 +112,19 @@ discard block |
||
| 112 | 112 | <table class="widefat fixed"> |
| 113 | 113 | <tbody> |
| 114 | 114 | <tr> |
| 115 | - <th><?php _e( 'Data Type', 'invoicing' ); ?></th> |
|
| 116 | - <td><?php echo esc_html( $log->data_type ); ?></td> |
|
| 115 | + <th><?php _e('Data Type', 'invoicing'); ?></th> |
|
| 116 | + <td><?php echo esc_html($log->data_type); ?></td> |
|
| 117 | 117 | </tr> |
| 118 | - <?php if ( is_array( $additional_info ) ) : ?> |
|
| 118 | + <?php if (is_array($additional_info)) : ?> |
|
| 119 | 119 | <tr> |
| 120 | - <th><?php _e( 'Additional Information', 'invoicing' ); ?></th> |
|
| 120 | + <th><?php _e('Additional Information', 'invoicing'); ?></th> |
|
| 121 | 121 | <td> |
| 122 | 122 | <table class="widefat fixed"> |
| 123 | 123 | <tbody> |
| 124 | - <?php foreach ( $additional_info as $key => $value ) : ?> |
|
| 124 | + <?php foreach ($additional_info as $key => $value) : ?> |
|
| 125 | 125 | <tr> |
| 126 | - <th><?php echo esc_html( $key ); ?></th> |
|
| 127 | - <td><?php echo esc_html( $value ); ?></td> |
|
| 126 | + <th><?php echo esc_html($key); ?></th> |
|
| 127 | + <td><?php echo esc_html($value); ?></td> |
|
| 128 | 128 | </tr> |
| 129 | 129 | <?php endforeach; ?> |
| 130 | 130 | </tbody> |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | <?php endif; ?> |
| 142 | 142 | </tbody> |
| 143 | 143 | </table> |
| 144 | - <?php if ( $pagination ) : ?> |
|
| 144 | + <?php if ($pagination) : ?> |
|
| 145 | 145 | <div class="tablenav bottom"> |
| 146 | 146 | <div class="tablenav-pages"> |
| 147 | 147 | <?php echo $pagination; ?> |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | * @param int $per_page Number of logs per page |
| 160 | 160 | * @return array |
| 161 | 161 | */ |
| 162 | - private function get_logs( $page, $per_page ) { |
|
| 162 | + private function get_logs($page, $per_page) { |
|
| 163 | 163 | global $wpdb; |
| 164 | 164 | $table_name = $wpdb->prefix . 'getpaid_anonymization_logs'; |
| 165 | - $offset = ( $page - 1 ) * $per_page; |
|
| 165 | + $offset = ($page - 1) * $per_page; |
|
| 166 | 166 | |
| 167 | 167 | $query = $wpdb->prepare( |
| 168 | 168 | "SELECT * FROM $table_name ORDER BY timestamp DESC LIMIT %d OFFSET %d", |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | $offset |
| 171 | 171 | ); |
| 172 | 172 | |
| 173 | - return $wpdb->get_results( $query ); |
|
| 173 | + return $wpdb->get_results($query); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | private function get_total_logs() { |
| 182 | 182 | global $wpdb; |
| 183 | 183 | $table_name = $wpdb->prefix . 'getpaid_anonymization_logs'; |
| 184 | - return $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" ); |
|
| 184 | + return $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -80,10 +80,12 @@ |
||
| 80 | 80 | <tr> |
| 81 | 81 | <td colspan="5"><?php _e( 'No anonymization logs found.', 'invoicing' ); ?></td> |
| 82 | 82 | </tr> |
| 83 | - <?php else : ?> |
|
| 83 | + <?php else { |
|
| 84 | + : ?> |
|
| 84 | 85 | <?php |
| 85 | 86 | foreach ( $logs as $log ) : |
| 86 | 87 | $additional_info = json_decode( $log->additional_info, true ); |
| 88 | +} |
|
| 87 | 89 | ?> |
| 88 | 90 | <tr> |
| 89 | 91 | <td><?php echo esc_html( $log->log_id ); ?></td> |
@@ -25,14 +25,14 @@ discard block |
||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * Highlights sub menus. |
|
| 29 | - */ |
|
| 30 | - public function set_admin_menu_class() { |
|
| 31 | - global $current_screen, $parent_file, $submenu_file; |
|
| 28 | + * Highlights sub menus. |
|
| 29 | + */ |
|
| 30 | + public function set_admin_menu_class() { |
|
| 31 | + global $current_screen, $parent_file, $submenu_file; |
|
| 32 | 32 | |
| 33 | 33 | if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) { |
| 34 | - $parent_file = 'wpinv'; |
|
| 35 | - $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
| 34 | + $parent_file = 'wpinv'; |
|
| 35 | + $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -184,8 +184,8 @@ discard block |
||
| 184 | 184 | foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
| 185 | 185 | $tab_url = add_query_arg( |
| 186 | 186 | array( |
| 187 | - 'settings-updated' => false, |
|
| 188 | - 'tab' => $tab_id, |
|
| 187 | + 'settings-updated' => false, |
|
| 188 | + 'tab' => $tab_id, |
|
| 189 | 189 | ), |
| 190 | 190 | 'admin.php?page=wpinv-settings' |
| 191 | 191 | ); |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | ++$number; |
| 213 | 213 | $tab_url = add_query_arg( |
| 214 | 214 | array( |
| 215 | - 'settings-updated' => false, |
|
| 216 | - 'tab' => $active_tab, |
|
| 217 | - 'section' => $section_id, |
|
| 215 | + 'settings-updated' => false, |
|
| 216 | + 'tab' => $active_tab, |
|
| 217 | + 'section' => $section_id, |
|
| 218 | 218 | ), |
| 219 | 219 | admin_url( 'admin.php?page=wpinv-settings' ) |
| 220 | 220 | ); |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Setup menus in WP admin. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -defined( 'ABSPATH' ) || exit; |
|
| 6 | +defined('ABSPATH') || exit; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * WC_Admin_Menus Class. |
@@ -13,15 +13,15 @@ discard block |
||
| 13 | 13 | * Hook in tabs. |
| 14 | 14 | */ |
| 15 | 15 | public function __construct() { |
| 16 | - add_action( 'admin_head', array( $this, 'set_admin_menu_class' ) ); |
|
| 17 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
| 18 | - add_action( 'admin_menu', array( $this, 'add_customers_menu' ), 18 ); |
|
| 19 | - add_action( 'admin_menu', array( $this, 'add_subscriptions_menu' ), 40 ); |
|
| 20 | - add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 ); |
|
| 21 | - add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 ); |
|
| 22 | - add_action( 'admin_menu', array( $this, 'add_anonymization_logs_menu' ), 40 ); |
|
| 23 | - add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 ); |
|
| 24 | - add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) ); |
|
| 16 | + add_action('admin_head', array($this, 'set_admin_menu_class')); |
|
| 17 | + add_action('admin_menu', array($this, 'admin_menu'), 10); |
|
| 18 | + add_action('admin_menu', array($this, 'add_customers_menu'), 18); |
|
| 19 | + add_action('admin_menu', array($this, 'add_subscriptions_menu'), 40); |
|
| 20 | + add_action('admin_menu', array($this, 'add_addons_menu'), 100); |
|
| 21 | + add_action('admin_menu', array($this, 'add_settings_menu'), 60); |
|
| 22 | + add_action('admin_menu', array($this, 'add_anonymization_logs_menu'), 40); |
|
| 23 | + add_action('admin_menu', array($this, 'remove_admin_submenus'), 10); |
|
| 24 | + add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes')); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | public function set_admin_menu_class() { |
| 31 | 31 | global $current_screen, $parent_file, $submenu_file; |
| 32 | 32 | |
| 33 | - if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) { |
|
| 33 | + if (!empty($current_screen->id) && in_array($current_screen->id, array('wpi_discount', 'wpi_payment_form', 'wpi_invoice'))) { |
|
| 34 | 34 | $parent_file = 'wpinv'; |
| 35 | 35 | $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
| 36 | 36 | } |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function admin_menu() { |
| 40 | 40 | |
| 41 | - $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() ); |
|
| 41 | + $capability = apply_filters('invoicing_capability', wpinv_get_capability()); |
|
| 42 | 42 | add_menu_page( |
| 43 | - __( 'GetPaid', 'invoicing' ), |
|
| 44 | - __( 'GetPaid', 'invoicing' ), |
|
| 43 | + __('GetPaid', 'invoicing'), |
|
| 44 | + __('GetPaid', 'invoicing'), |
|
| 45 | 45 | $capability, |
| 46 | 46 | 'wpinv', |
| 47 | 47 | null, |
| 48 | - 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg' ) ), |
|
| 48 | + 'data:image/svg+xml;base64,' . base64_encode(file_get_contents(WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg')), |
|
| 49 | 49 | '54.123460' |
| 50 | 50 | ); |
| 51 | 51 | } |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | public function add_customers_menu() { |
| 57 | 57 | add_submenu_page( |
| 58 | 58 | 'wpinv', |
| 59 | - __( 'Customers', 'invoicing' ), |
|
| 60 | - __( 'Customers', 'invoicing' ), |
|
| 59 | + __('Customers', 'invoicing'), |
|
| 60 | + __('Customers', 'invoicing'), |
|
| 61 | 61 | wpinv_get_capability(), |
| 62 | 62 | 'wpinv-customers', |
| 63 | - array( $this, 'customers_page' ) |
|
| 63 | + array($this, 'customers_page') |
|
| 64 | 64 | ); |
| 65 | 65 | } |
| 66 | 66 | |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | public function add_subscriptions_menu() { |
| 71 | 71 | add_submenu_page( |
| 72 | 72 | 'wpinv', |
| 73 | - __( 'Subscriptions', 'invoicing' ), |
|
| 74 | - __( 'Subscriptions', 'invoicing' ), |
|
| 73 | + __('Subscriptions', 'invoicing'), |
|
| 74 | + __('Subscriptions', 'invoicing'), |
|
| 75 | 75 | wpinv_get_capability(), |
| 76 | 76 | 'wpinv-subscriptions', |
| 77 | 77 | 'wpinv_subscriptions_page' |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | width: 120px; |
| 94 | 94 | } |
| 95 | 95 | </style> |
| 96 | - <h1><?php echo esc_html( __( 'Customers', 'invoicing' ) ); ?> <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'download_customers' ), 'getpaid-nonce', 'getpaid-nonce' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Export', 'invoicing' ); ?></a></h1> |
|
| 97 | - <form method="get" style="overflow: auto; width: 100%" action=<?php echo esc_url( add_query_arg( array() ) ); ?>> |
|
| 96 | + <h1><?php echo esc_html(__('Customers', 'invoicing')); ?> <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'download_customers'), 'getpaid-nonce', 'getpaid-nonce')); ?>" class="page-title-action"><?php esc_html_e('Export', 'invoicing'); ?></a></h1> |
|
| 97 | + <form method="get" style="overflow: auto; width: 100%" action=<?php echo esc_url(add_query_arg(array())); ?>> |
|
| 98 | 98 | <input type="hidden" name="page" value="wpinv-customers" /> |
| 99 | 99 | <?php |
| 100 | 100 | $table = new WPInv_Customers_Table(); |
| 101 | 101 | $table->prepare_items(); |
| 102 | - $table->search_box( __( 'Search Customers', 'invoicing' ), 'search-customers' ); |
|
| 102 | + $table->search_box(__('Search Customers', 'invoicing'), 'search-customers'); |
|
| 103 | 103 | $table->display(); |
| 104 | 104 | ?> |
| 105 | 105 | </form> |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | public function add_settings_menu() { |
| 114 | 114 | add_submenu_page( |
| 115 | 115 | 'wpinv', |
| 116 | - __( 'Invoice Settings', 'invoicing' ), |
|
| 117 | - __( 'Settings', 'invoicing' ), |
|
| 118 | - apply_filters( 'invoicing_capability', wpinv_get_capability() ), |
|
| 116 | + __('Invoice Settings', 'invoicing'), |
|
| 117 | + __('Settings', 'invoicing'), |
|
| 118 | + apply_filters('invoicing_capability', wpinv_get_capability()), |
|
| 119 | 119 | 'wpinv-settings', |
| 120 | - array( $this, 'options_page' ) |
|
| 120 | + array($this, 'options_page') |
|
| 121 | 121 | ); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -129,26 +129,26 @@ discard block |
||
| 129 | 129 | public function add_anonymization_logs_menu() { |
| 130 | 130 | $anonymization_logs_page = new GetPaid_Anonymization_Logs(); |
| 131 | 131 | add_management_page( |
| 132 | - __( 'Anonymization Logs', 'invoicing' ), |
|
| 133 | - __( 'Anonymization Logs', 'invoicing' ), |
|
| 132 | + __('Anonymization Logs', 'invoicing'), |
|
| 133 | + __('Anonymization Logs', 'invoicing'), |
|
| 134 | 134 | 'manage_options', |
| 135 | 135 | 'wpinv-anonymization-logs', |
| 136 | - array( $anonymization_logs_page, 'display_logs' ) |
|
| 136 | + array($anonymization_logs_page, 'display_logs') |
|
| 137 | 137 | ); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | public function add_addons_menu() { |
| 141 | - if ( ! apply_filters( 'wpi_show_addons_page', true ) ) { |
|
| 141 | + if (!apply_filters('wpi_show_addons_page', true)) { |
|
| 142 | 142 | return; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | add_submenu_page( |
| 146 | 146 | 'wpinv', |
| 147 | - __( 'Invoicing extensions', 'invoicing' ), |
|
| 148 | - __( 'Extensions', 'invoicing' ), |
|
| 147 | + __('Invoicing extensions', 'invoicing'), |
|
| 148 | + __('Extensions', 'invoicing'), |
|
| 149 | 149 | 'manage_options', |
| 150 | 150 | 'wpi-addons', |
| 151 | - array( $this, 'addons_page' ) |
|
| 151 | + array($this, 'addons_page') |
|
| 152 | 152 | ); |
| 153 | 153 | } |
| 154 | 154 | |
@@ -159,29 +159,29 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | function options_page() { |
| 161 | 161 | |
| 162 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 162 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 163 | 163 | return; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $settings_tabs = wpinv_get_settings_tabs(); |
| 167 | - $settings_tabs = empty( $settings_tabs ) ? array() : $settings_tabs; |
|
| 168 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
| 169 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
| 167 | + $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
|
| 168 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
| 169 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
| 170 | 170 | $key = 'main'; |
| 171 | 171 | |
| 172 | - if ( is_array( $sections ) ) { |
|
| 173 | - $key = key( $sections ); |
|
| 172 | + if (is_array($sections)) { |
|
| 173 | + $key = key($sections); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | add_thickbox(); |
| 177 | 177 | |
| 178 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
| 179 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? sanitize_text_field( $_GET['section'] ) : $key; |
|
| 178 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
| 179 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? sanitize_text_field($_GET['section']) : $key; |
|
| 180 | 180 | ?> |
| 181 | 181 | <div class="wrap"> |
| 182 | 182 | <h1 class="nav-tab-wrapper"> |
| 183 | 183 | <?php |
| 184 | - foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
| 184 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
| 185 | 185 | $tab_url = add_query_arg( |
| 186 | 186 | array( |
| 187 | 187 | 'settings-updated' => false, |
@@ -191,23 +191,23 @@ discard block |
||
| 191 | 191 | ); |
| 192 | 192 | |
| 193 | 193 | // Remove the section from the tabs so we always end up at the main section |
| 194 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
| 195 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
| 194 | + $tab_url = remove_query_arg('section', $tab_url); |
|
| 195 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
| 196 | 196 | |
| 197 | 197 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
| 198 | 198 | |
| 199 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab ' . esc_attr( $active ) . '">'; |
|
| 200 | - echo esc_html( $tab_name ); |
|
| 199 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab ' . esc_attr($active) . '">'; |
|
| 200 | + echo esc_html($tab_name); |
|
| 201 | 201 | echo '</a>'; |
| 202 | 202 | } |
| 203 | 203 | ?> |
| 204 | 204 | </h1> |
| 205 | 205 | <?php |
| 206 | - $number_of_sections = count( $sections ); |
|
| 206 | + $number_of_sections = count($sections); |
|
| 207 | 207 | $number = 0; |
| 208 | - if ( $number_of_sections > 1 ) { |
|
| 208 | + if ($number_of_sections > 1) { |
|
| 209 | 209 | echo '<div><ul class="subsubsub">'; |
| 210 | - foreach ( $sections as $section_id => $section_name ) { |
|
| 210 | + foreach ($sections as $section_id => $section_name) { |
|
| 211 | 211 | echo '<li>'; |
| 212 | 212 | ++$number; |
| 213 | 213 | $tab_url = add_query_arg( |
@@ -216,16 +216,16 @@ discard block |
||
| 216 | 216 | 'tab' => $active_tab, |
| 217 | 217 | 'section' => $section_id, |
| 218 | 218 | ), |
| 219 | - admin_url( 'admin.php?page=wpinv-settings' ) |
|
| 219 | + admin_url('admin.php?page=wpinv-settings') |
|
| 220 | 220 | ); |
| 221 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
| 221 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
| 222 | 222 | $class = ''; |
| 223 | - if ( $section == $section_id ) { |
|
| 223 | + if ($section == $section_id) { |
|
| 224 | 224 | $class = 'current'; |
| 225 | 225 | } |
| 226 | - echo '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $tab_url ) . '">' . esc_html( $section_name ) . '</a>'; |
|
| 226 | + echo '<a class="' . esc_attr($class) . '" href="' . esc_url($tab_url) . '">' . esc_html($section_name) . '</a>'; |
|
| 227 | 227 | |
| 228 | - if ( $number != $number_of_sections ) { |
|
| 228 | + if ($number != $number_of_sections) { |
|
| 229 | 229 | echo ' | '; |
| 230 | 230 | } |
| 231 | 231 | echo '</li>'; |
@@ -237,20 +237,20 @@ discard block |
||
| 237 | 237 | <form method="post" action="options.php"> |
| 238 | 238 | <table class="form-tablex"> |
| 239 | 239 | <?php |
| 240 | - settings_fields( 'wpinv_settings' ); |
|
| 240 | + settings_fields('wpinv_settings'); |
|
| 241 | 241 | |
| 242 | - if ( 'main' === $section ) { |
|
| 243 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
| 242 | + if ('main' === $section) { |
|
| 243 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
| 247 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
| 248 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
| 249 | - do_action( 'getpaid_settings_tab_bottom', $active_tab, $section ); |
|
| 246 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section); |
|
| 247 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section); |
|
| 248 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section); |
|
| 249 | + do_action('getpaid_settings_tab_bottom', $active_tab, $section); |
|
| 250 | 250 | |
| 251 | 251 | // For backwards compatibility |
| 252 | - if ( 'main' === $section ) { |
|
| 253 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
| 252 | + if ('main' === $section) { |
|
| 253 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
| 254 | 254 | } |
| 255 | 255 | ?> |
| 256 | 256 | </table> |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | public function remove_admin_submenus() { |
| 265 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
| 265 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -272,8 +272,8 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | add_meta_box( |
| 274 | 274 | 'wpinv_endpoints_nav_link', |
| 275 | - __( 'GetPaid endpoints', 'invoicing' ), |
|
| 276 | - array( $this, 'nav_menu_links' ), |
|
| 275 | + __('GetPaid endpoints', 'invoicing'), |
|
| 276 | + array($this, 'nav_menu_links'), |
|
| 277 | 277 | 'nav-menus', |
| 278 | 278 | 'side', |
| 279 | 279 | 'low' |
@@ -287,12 +287,12 @@ discard block |
||
| 287 | 287 | $endpoints = $this->get_menu_items(); |
| 288 | 288 | ?> |
| 289 | 289 | <div id="invoicing-endpoints" class="posttypediv"> |
| 290 | - <?php if ( ! empty( $endpoints['pages'] ) ) : ?> |
|
| 290 | + <?php if (!empty($endpoints['pages'])) : ?> |
|
| 291 | 291 | <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active"> |
| 292 | 292 | <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear"> |
| 293 | 293 | <?php |
| 294 | - $walker = new Walker_Nav_Menu_Checklist( array() ); |
|
| 295 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $endpoints['pages'] ), 0, (object) array( 'walker' => $walker ) ); |
|
| 294 | + $walker = new Walker_Nav_Menu_Checklist(array()); |
|
| 295 | + echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $endpoints['pages']), 0, (object) array('walker' => $walker)); |
|
| 296 | 296 | ?> |
| 297 | 297 | </ul> |
| 298 | 298 | </div> |
@@ -301,11 +301,11 @@ discard block |
||
| 301 | 301 | <p class="button-controls wp-clearfix" data-items-type="invoicing-endpoints"> |
| 302 | 302 | <span class="list-controls hide-if-no-js"> |
| 303 | 303 | <input type="checkbox" id="invoicing-endpoints-tab" class="select-all"> |
| 304 | - <label for="invoicing-endpoints-tab"><?php esc_html_e( 'Select all', 'invoicing' ); ?></label> |
|
| 304 | + <label for="invoicing-endpoints-tab"><?php esc_html_e('Select all', 'invoicing'); ?></label> |
|
| 305 | 305 | </span> |
| 306 | 306 | |
| 307 | 307 | <span class="add-to-menu"> |
| 308 | - <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints"> |
|
| 308 | + <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints"> |
|
| 309 | 309 | <span class="spinner"></span> |
| 310 | 310 | </span> |
| 311 | 311 | </p> |
@@ -323,18 +323,18 @@ discard block |
||
| 323 | 323 | |
| 324 | 324 | $pages = array( |
| 325 | 325 | array( |
| 326 | - 'id' => wpinv_get_option( 'invoice_history_page' ), |
|
| 327 | - 'label' => __( 'My Invoices', 'invoicing' ), |
|
| 326 | + 'id' => wpinv_get_option('invoice_history_page'), |
|
| 327 | + 'label' => __('My Invoices', 'invoicing'), |
|
| 328 | 328 | ), |
| 329 | 329 | array( |
| 330 | - 'id' => wpinv_get_option( 'invoice_subscription_page' ), |
|
| 331 | - 'label' => __( 'My Subscriptions', 'invoicing' ), |
|
| 330 | + 'id' => wpinv_get_option('invoice_subscription_page'), |
|
| 331 | + 'label' => __('My Subscriptions', 'invoicing'), |
|
| 332 | 332 | ), |
| 333 | 333 | ); |
| 334 | 334 | |
| 335 | - foreach ( apply_filters( 'getpaid_menu_pages', $pages ) as $page ) { |
|
| 335 | + foreach (apply_filters('getpaid_menu_pages', $pages) as $page) { |
|
| 336 | 336 | |
| 337 | - if ( (int) $page['id'] > 0 ) { |
|
| 337 | + if ((int) $page['id'] > 0) { |
|
| 338 | 338 | |
| 339 | 339 | $item = new stdClass(); |
| 340 | 340 | $item->object_id = (int) $page['id']; |
@@ -342,11 +342,11 @@ discard block |
||
| 342 | 342 | $item->object = 'page'; |
| 343 | 343 | $item->menu_item_parent = 0; |
| 344 | 344 | $item->type = 'post_type'; |
| 345 | - $item->title = esc_html( $page['label'] ); |
|
| 346 | - $item->url = get_permalink( (int) $page['id'] ); |
|
| 345 | + $item->title = esc_html($page['label']); |
|
| 346 | + $item->url = get_permalink((int) $page['id']); |
|
| 347 | 347 | $item->target = ''; |
| 348 | 348 | $item->attr_title = ''; |
| 349 | - $item->classes = array( 'wpinv-menu-item' ); |
|
| 349 | + $item->classes = array('wpinv-menu-item'); |
|
| 350 | 350 | $item->xfn = ''; |
| 351 | 351 | |
| 352 | 352 | $items['pages'][] = $item; |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - return apply_filters( 'wpinv_menu_items', $items ); |
|
| 357 | + return apply_filters('wpinv_menu_items', $items); |
|
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | |
@@ -12,136 +12,136 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Daily_Maintenance { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class constructor. |
|
| 17 | - */ |
|
| 18 | - public function __construct() { |
|
| 19 | - |
|
| 20 | - // Clear deprecated events. |
|
| 21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
| 22 | - |
|
| 23 | - // (Maybe) schedule a cron that runs daily. |
|
| 24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
| 25 | - |
|
| 26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
| 27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
| 28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
| 29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
| 30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
| 31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Schedules a cron to run every day at 7 a.m |
|
| 36 | - * |
|
| 37 | - */ |
|
| 38 | - public function maybe_create_scheduled_event() { |
|
| 39 | - |
|
| 40 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
| 41 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
| 42 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Clears deprecated events. |
|
| 48 | - * |
|
| 49 | - */ |
|
| 50 | - public function maybe_clear_deprecated_events() { |
|
| 51 | - |
|
| 52 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
| 53 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
| 54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
| 55 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Fires the old hook for backwards compatibility. |
|
| 61 | - * |
|
| 62 | - */ |
|
| 63 | - public function backwards_compat() { |
|
| 64 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Checks for subscriptions that are scheduled to renew. |
|
| 69 | - * |
|
| 70 | - */ |
|
| 71 | - public function check_renewing_subscriptions() { |
|
| 72 | - |
|
| 73 | - // Fetch subscriptions that expire today. |
|
| 74 | - $args = array( |
|
| 75 | - 'number' => -1, |
|
| 76 | - 'count_total' => false, |
|
| 77 | - 'status' => 'trialling active', |
|
| 78 | - 'date_expires_query' => array( |
|
| 79 | - array( |
|
| 80 | - 'year' => gmdate( 'Y' ), |
|
| 81 | - 'month' => gmdate( 'n' ), |
|
| 82 | - 'day' => gmdate( 'j' ), |
|
| 83 | - 'compare' => '=', |
|
| 84 | - ), |
|
| 85 | - ), |
|
| 86 | - ); |
|
| 87 | - |
|
| 88 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 89 | - |
|
| 90 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 91 | - /** @var WPInv_Subscription $subscription */ |
|
| 92 | - if ( $subscription->is_last_renewal() ) { |
|
| 93 | - $subscription->complete(); |
|
| 94 | - } else { |
|
| 95 | - do_action( 'getpaid_should_renew_subscription', $subscription, $subscription->get_parent_invoice() ); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Expires expired subscriptions. |
|
| 102 | - * |
|
| 103 | - */ |
|
| 104 | - public function maybe_expire_subscriptions() { |
|
| 105 | - |
|
| 106 | - // Fetch expired subscriptions (skips those that expire today). |
|
| 107 | - $args = array( |
|
| 108 | - 'number' => -1, |
|
| 109 | - 'count_total' => false, |
|
| 110 | - 'status' => 'trialling active failing cancelled', |
|
| 111 | - 'date_expires_query' => array( |
|
| 112 | - 'before' => 'yesterday', |
|
| 113 | - 'inclusive' => false, |
|
| 114 | - ), |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 118 | - |
|
| 119 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 120 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
| 121 | - $subscription->set_status( 'expired' ); |
|
| 122 | - $subscription->save(); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Logs cron runs. |
|
| 129 | - * |
|
| 130 | - */ |
|
| 131 | - public function log_cron_run() { |
|
| 132 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Updates GeoIP databases. |
|
| 137 | - * |
|
| 138 | - */ |
|
| 139 | - public function maybe_update_geoip_databases() { |
|
| 140 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
| 141 | - |
|
| 142 | - if ( false === $updated ) { |
|
| 143 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
| 144 | - do_action( 'getpaid_update_geoip_databases' ); |
|
| 145 | - } |
|
| 146 | - } |
|
| 15 | + /** |
|
| 16 | + * Class constructor. |
|
| 17 | + */ |
|
| 18 | + public function __construct() { |
|
| 19 | + |
|
| 20 | + // Clear deprecated events. |
|
| 21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
| 22 | + |
|
| 23 | + // (Maybe) schedule a cron that runs daily. |
|
| 24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
| 25 | + |
|
| 26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
| 27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
| 28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
| 29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
| 30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
| 31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Schedules a cron to run every day at 7 a.m |
|
| 36 | + * |
|
| 37 | + */ |
|
| 38 | + public function maybe_create_scheduled_event() { |
|
| 39 | + |
|
| 40 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
| 41 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
| 42 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Clears deprecated events. |
|
| 48 | + * |
|
| 49 | + */ |
|
| 50 | + public function maybe_clear_deprecated_events() { |
|
| 51 | + |
|
| 52 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
| 53 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
| 54 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
| 55 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Fires the old hook for backwards compatibility. |
|
| 61 | + * |
|
| 62 | + */ |
|
| 63 | + public function backwards_compat() { |
|
| 64 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Checks for subscriptions that are scheduled to renew. |
|
| 69 | + * |
|
| 70 | + */ |
|
| 71 | + public function check_renewing_subscriptions() { |
|
| 72 | + |
|
| 73 | + // Fetch subscriptions that expire today. |
|
| 74 | + $args = array( |
|
| 75 | + 'number' => -1, |
|
| 76 | + 'count_total' => false, |
|
| 77 | + 'status' => 'trialling active', |
|
| 78 | + 'date_expires_query' => array( |
|
| 79 | + array( |
|
| 80 | + 'year' => gmdate( 'Y' ), |
|
| 81 | + 'month' => gmdate( 'n' ), |
|
| 82 | + 'day' => gmdate( 'j' ), |
|
| 83 | + 'compare' => '=', |
|
| 84 | + ), |
|
| 85 | + ), |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 89 | + |
|
| 90 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 91 | + /** @var WPInv_Subscription $subscription */ |
|
| 92 | + if ( $subscription->is_last_renewal() ) { |
|
| 93 | + $subscription->complete(); |
|
| 94 | + } else { |
|
| 95 | + do_action( 'getpaid_should_renew_subscription', $subscription, $subscription->get_parent_invoice() ); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Expires expired subscriptions. |
|
| 102 | + * |
|
| 103 | + */ |
|
| 104 | + public function maybe_expire_subscriptions() { |
|
| 105 | + |
|
| 106 | + // Fetch expired subscriptions (skips those that expire today). |
|
| 107 | + $args = array( |
|
| 108 | + 'number' => -1, |
|
| 109 | + 'count_total' => false, |
|
| 110 | + 'status' => 'trialling active failing cancelled', |
|
| 111 | + 'date_expires_query' => array( |
|
| 112 | + 'before' => 'yesterday', |
|
| 113 | + 'inclusive' => false, |
|
| 114 | + ), |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 118 | + |
|
| 119 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 120 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
| 121 | + $subscription->set_status( 'expired' ); |
|
| 122 | + $subscription->save(); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Logs cron runs. |
|
| 129 | + * |
|
| 130 | + */ |
|
| 131 | + public function log_cron_run() { |
|
| 132 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Updates GeoIP databases. |
|
| 137 | + * |
|
| 138 | + */ |
|
| 139 | + public function maybe_update_geoip_databases() { |
|
| 140 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
| 141 | + |
|
| 142 | + if ( false === $updated ) { |
|
| 143 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
| 144 | + do_action( 'getpaid_update_geoip_databases' ); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Daily maintenance class. |
@@ -18,17 +18,17 @@ discard block |
||
| 18 | 18 | public function __construct() { |
| 19 | 19 | |
| 20 | 20 | // Clear deprecated events. |
| 21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
| 21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
| 22 | 22 | |
| 23 | 23 | // (Maybe) schedule a cron that runs daily. |
| 24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
| 24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
| 25 | 25 | |
| 26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
| 27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
| 28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
| 29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
| 30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
| 31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
| 27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
| 28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
| 29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
| 30 | + add_action('getpaid_daily_maintenance', array($this, 'check_renewing_subscriptions')); |
|
| 31 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases')); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function maybe_create_scheduled_event() { |
| 39 | 39 | |
| 40 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
| 41 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
| 42 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
| 40 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
| 41 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
| 42 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
@@ -49,10 +49,10 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function maybe_clear_deprecated_events() { |
| 51 | 51 | |
| 52 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
| 53 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
| 54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
| 55 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
| 52 | + if (!get_option('wpinv_cleared_old_events')) { |
|
| 53 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
| 54 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
| 55 | + update_option('wpinv_cleared_old_events', 1); |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | */ |
| 63 | 63 | public function backwards_compat() { |
| 64 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
| 64 | + do_action('wpinv_register_schedule_event_daily'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -71,28 +71,28 @@ discard block |
||
| 71 | 71 | public function check_renewing_subscriptions() { |
| 72 | 72 | |
| 73 | 73 | // Fetch subscriptions that expire today. |
| 74 | - $args = array( |
|
| 74 | + $args = array( |
|
| 75 | 75 | 'number' => -1, |
| 76 | 76 | 'count_total' => false, |
| 77 | 77 | 'status' => 'trialling active', |
| 78 | 78 | 'date_expires_query' => array( |
| 79 | 79 | array( |
| 80 | - 'year' => gmdate( 'Y' ), |
|
| 81 | - 'month' => gmdate( 'n' ), |
|
| 82 | - 'day' => gmdate( 'j' ), |
|
| 80 | + 'year' => gmdate('Y'), |
|
| 81 | + 'month' => gmdate('n'), |
|
| 82 | + 'day' => gmdate('j'), |
|
| 83 | 83 | 'compare' => '=', |
| 84 | 84 | ), |
| 85 | 85 | ), |
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 88 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
| 89 | 89 | |
| 90 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 90 | + foreach ($subscriptions->get_results() as $subscription) { |
|
| 91 | 91 | /** @var WPInv_Subscription $subscription */ |
| 92 | - if ( $subscription->is_last_renewal() ) { |
|
| 92 | + if ($subscription->is_last_renewal()) { |
|
| 93 | 93 | $subscription->complete(); |
| 94 | 94 | } else { |
| 95 | - do_action( 'getpaid_should_renew_subscription', $subscription, $subscription->get_parent_invoice() ); |
|
| 95 | + do_action('getpaid_should_renew_subscription', $subscription, $subscription->get_parent_invoice()); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | public function maybe_expire_subscriptions() { |
| 105 | 105 | |
| 106 | 106 | // Fetch expired subscriptions (skips those that expire today). |
| 107 | - $args = array( |
|
| 107 | + $args = array( |
|
| 108 | 108 | 'number' => -1, |
| 109 | 109 | 'count_total' => false, |
| 110 | 110 | 'status' => 'trialling active failing cancelled', |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | ), |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 117 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
| 118 | 118 | |
| 119 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 120 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
| 121 | - $subscription->set_status( 'expired' ); |
|
| 119 | + foreach ($subscriptions->get_results() as $subscription) { |
|
| 120 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', false, $subscription)) { |
|
| 121 | + $subscription->set_status('expired'); |
|
| 122 | 122 | $subscription->save(); |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | */ |
| 131 | 131 | public function log_cron_run() { |
| 132 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
| 132 | + wpinv_error_log('GetPaid Daily Cron', false); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | */ |
| 139 | 139 | public function maybe_update_geoip_databases() { |
| 140 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
| 140 | + $updated = get_transient('getpaid_updated_geoip_databases'); |
|
| 141 | 141 | |
| 142 | - if ( false === $updated ) { |
|
| 143 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
| 144 | - do_action( 'getpaid_update_geoip_databases' ); |
|
| 142 | + if (false === $updated) { |
|
| 143 | + set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS); |
|
| 144 | + do_action('getpaid_update_geoip_databases'); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -291,18 +291,18 @@ |
||
| 291 | 291 | |
| 292 | 292 | $user_meta_data = array( |
| 293 | 293 | 'nickname', |
| 294 | - 'description', |
|
| 295 | - 'rich_editing', |
|
| 296 | - 'syntax_highlighting', |
|
| 297 | - 'comment_shortcuts', |
|
| 294 | + 'description', |
|
| 295 | + 'rich_editing', |
|
| 296 | + 'syntax_highlighting', |
|
| 297 | + 'comment_shortcuts', |
|
| 298 | 298 | 'admin_color', |
| 299 | - 'use_ssl', |
|
| 300 | - 'show_admin_bar_front', |
|
| 301 | - 'locale', |
|
| 302 | - 'wp_capabilities', |
|
| 299 | + 'use_ssl', |
|
| 300 | + 'show_admin_bar_front', |
|
| 301 | + 'locale', |
|
| 302 | + 'wp_capabilities', |
|
| 303 | 303 | 'wp_user_level', |
| 304 | - 'dismissed_wp_pointers', |
|
| 305 | - 'show_welcome_panel', |
|
| 304 | + 'dismissed_wp_pointers', |
|
| 305 | + 'show_welcome_panel', |
|
| 306 | 306 | ); |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 2.8.22 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * WPInv_Data_Retention Class. |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | * Class constructor. |
| 36 | 36 | */ |
| 37 | 37 | public function __construct() { |
| 38 | - add_filter( 'wpinv_settings_misc', array( $this, 'add_data_retention_settings' ) ); |
|
| 38 | + add_filter('wpinv_settings_misc', array($this, 'add_data_retention_settings')); |
|
| 39 | 39 | |
| 40 | - add_action( 'wpmu_delete_user', array( $this, 'maybe_handle_user_deletion' ), 1 ); |
|
| 41 | - add_action( 'delete_user', array( $this, 'maybe_handle_user_deletion' ), 1 ); |
|
| 42 | - add_filter( 'wp_privacy_personal_data_erasure_request', array( $this, 'handle_erasure_request' ), 10, 2 ); |
|
| 40 | + add_action('wpmu_delete_user', array($this, 'maybe_handle_user_deletion'), 1); |
|
| 41 | + add_action('delete_user', array($this, 'maybe_handle_user_deletion'), 1); |
|
| 42 | + add_filter('wp_privacy_personal_data_erasure_request', array($this, 'handle_erasure_request'), 10, 2); |
|
| 43 | 43 | |
| 44 | - add_action( 'getpaid_daily_maintenance', array( $this, 'perform_data_retention_cleanup' ) ); |
|
| 44 | + add_action('getpaid_daily_maintenance', array($this, 'perform_data_retention_cleanup')); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -50,43 +50,43 @@ discard block |
||
| 50 | 50 | * @param array $misc_settings Existing misc settings. |
| 51 | 51 | * @return array Updated misc settings. |
| 52 | 52 | */ |
| 53 | - public function add_data_retention_settings( $misc_settings ) { |
|
| 53 | + public function add_data_retention_settings($misc_settings) { |
|
| 54 | 54 | $misc_settings['data_retention'] = array( |
| 55 | 55 | 'id' => 'data_retention', |
| 56 | - 'name' => '<h3>' . __( 'Data Retention', 'invoicing' ) . '</h3>', |
|
| 56 | + 'name' => '<h3>' . __('Data Retention', 'invoicing') . '</h3>', |
|
| 57 | 57 | 'type' => 'header', |
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | $misc_settings['data_retention_method'] = array( |
| 61 | 61 | 'id' => 'data_retention_method', |
| 62 | - 'name' => __( 'Data Handling', 'invoicing' ), |
|
| 63 | - 'desc' => __( 'Choose how to handle user data when deletion is required.', 'invoicing' ), |
|
| 62 | + 'name' => __('Data Handling', 'invoicing'), |
|
| 63 | + 'desc' => __('Choose how to handle user data when deletion is required.', 'invoicing'), |
|
| 64 | 64 | 'type' => 'select', |
| 65 | 65 | 'options' => array( |
| 66 | - 'anonymize' => __( 'Anonymize data', 'invoicing' ), |
|
| 67 | - 'delete' => __( 'Delete data without anonymization', 'invoicing' ), |
|
| 66 | + 'anonymize' => __('Anonymize data', 'invoicing'), |
|
| 67 | + 'delete' => __('Delete data without anonymization', 'invoicing'), |
|
| 68 | 68 | ), |
| 69 | 69 | 'std' => 'anonymize', |
| 70 | - 'tooltip' => __( 'Anonymization replaces personal data with non-identifiable information. Direct deletion removes all data permanently.', 'invoicing' ), |
|
| 70 | + 'tooltip' => __('Anonymization replaces personal data with non-identifiable information. Direct deletion removes all data permanently.', 'invoicing'), |
|
| 71 | 71 | ); |
| 72 | 72 | |
| 73 | 73 | $misc_settings['data_retention_period'] = array( |
| 74 | 74 | 'id' => 'data_retention_period', |
| 75 | - 'name' => __( 'Retention Period', 'invoicing' ), |
|
| 76 | - 'desc' => __( 'Specify how long to retain customer data after processing.', 'invoicing' ), |
|
| 75 | + 'name' => __('Retention Period', 'invoicing'), |
|
| 76 | + 'desc' => __('Specify how long to retain customer data after processing.', 'invoicing'), |
|
| 77 | 77 | 'type' => 'select', |
| 78 | 78 | 'options' => array( |
| 79 | - 'never' => __( 'Never delete (retain indefinitely)', 'invoicing' ), |
|
| 80 | - '30' => __( '30 days', 'invoicing' ), |
|
| 81 | - '90' => __( '90 days', 'invoicing' ), |
|
| 82 | - '180' => __( '6 months', 'invoicing' ), |
|
| 83 | - '365' => __( '1 year', 'invoicing' ), |
|
| 84 | - '730' => __( '2 years', 'invoicing' ), |
|
| 85 | - '1825' => __( '5 years', 'invoicing' ), |
|
| 86 | - '3650' => __( '10 years', 'invoicing' ), |
|
| 79 | + 'never' => __('Never delete (retain indefinitely)', 'invoicing'), |
|
| 80 | + '30' => __('30 days', 'invoicing'), |
|
| 81 | + '90' => __('90 days', 'invoicing'), |
|
| 82 | + '180' => __('6 months', 'invoicing'), |
|
| 83 | + '365' => __('1 year', 'invoicing'), |
|
| 84 | + '730' => __('2 years', 'invoicing'), |
|
| 85 | + '1825' => __('5 years', 'invoicing'), |
|
| 86 | + '3650' => __('10 years', 'invoicing'), |
|
| 87 | 87 | ), |
| 88 | 88 | 'std' => '3650', |
| 89 | - 'tooltip' => __( 'Choose how long to keep processed customer data before final action. This helps balance data minimization with business needs.', 'invoicing' ), |
|
| 89 | + 'tooltip' => __('Choose how long to keep processed customer data before final action. This helps balance data minimization with business needs.', 'invoicing'), |
|
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | 92 | return $misc_settings; |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @param int $user_id The ID of the user being deleted. |
| 99 | 99 | */ |
| 100 | - public function maybe_handle_user_deletion( $user_id ) { |
|
| 101 | - if ( ! $this->handle_user_deletion ) { |
|
| 100 | + public function maybe_handle_user_deletion($user_id) { |
|
| 101 | + if (!$this->handle_user_deletion) { |
|
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 106 | - $this->handle_admin_user_deletion( $user_id ); |
|
| 105 | + if (current_user_can('manage_options')) { |
|
| 106 | + $this->handle_admin_user_deletion($user_id); |
|
| 107 | 107 | } else { |
| 108 | - $this->handle_self_account_deletion( $user_id ); |
|
| 108 | + $this->handle_self_account_deletion($user_id); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
@@ -115,17 +115,17 @@ discard block |
||
| 115 | 115 | * @since 2.8.22 |
| 116 | 116 | * @param int $user_id The ID of the user being deleted. |
| 117 | 117 | */ |
| 118 | - public function handle_admin_user_deletion( $user_id ) { |
|
| 119 | - if ( $this->has_active_subscriptions( $user_id ) ) { |
|
| 120 | - $this->prevent_user_deletion( $user_id, 'active_subscriptions' ); |
|
| 118 | + public function handle_admin_user_deletion($user_id) { |
|
| 119 | + if ($this->has_active_subscriptions($user_id)) { |
|
| 120 | + $this->prevent_user_deletion($user_id, 'active_subscriptions'); |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if ( $this->has_paid_invoices( $user_id ) ) { |
|
| 125 | - $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' ); |
|
| 126 | - if ( 'anonymize' === $retention_method ) { |
|
| 127 | - $this->anonymize_user_data( $user_id ); |
|
| 128 | - $this->prevent_user_deletion( $user_id, 'paid_invoices' ); |
|
| 124 | + if ($this->has_paid_invoices($user_id)) { |
|
| 125 | + $retention_method = wpinv_get_option('data_retention_method', 'anonymize'); |
|
| 126 | + if ('anonymize' === $retention_method) { |
|
| 127 | + $this->anonymize_user_data($user_id); |
|
| 128 | + $this->prevent_user_deletion($user_id, 'paid_invoices'); |
|
| 129 | 129 | } else { |
| 130 | 130 | // $this->delete_user_data( $user_id ); |
| 131 | 131 | } |
@@ -138,19 +138,19 @@ discard block |
||
| 138 | 138 | * @since 2.8.22 |
| 139 | 139 | * @param int $user_id The ID of the user being deleted. |
| 140 | 140 | */ |
| 141 | - public function handle_self_account_deletion( $user_id ) { |
|
| 142 | - $this->cancel_active_subscriptions( $user_id ); |
|
| 141 | + public function handle_self_account_deletion($user_id) { |
|
| 142 | + $this->cancel_active_subscriptions($user_id); |
|
| 143 | 143 | |
| 144 | - if ( $this->has_paid_invoices( $user_id ) ) { |
|
| 145 | - $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' ); |
|
| 144 | + if ($this->has_paid_invoices($user_id)) { |
|
| 145 | + $retention_method = wpinv_get_option('data_retention_method', 'anonymize'); |
|
| 146 | 146 | |
| 147 | - if ( 'anonymize' === $retention_method ) { |
|
| 148 | - $user = get_userdata( $user_id ); |
|
| 147 | + if ('anonymize' === $retention_method) { |
|
| 148 | + $user = get_userdata($user_id); |
|
| 149 | 149 | |
| 150 | - $this->anonymize_user_data( $user_id ); |
|
| 150 | + $this->anonymize_user_data($user_id); |
|
| 151 | 151 | |
| 152 | - $message = apply_filters( 'uwp_get_account_deletion_message', '', $user ); |
|
| 153 | - do_action( 'uwp_send_account_deletion_emails', $user, $message ); |
|
| 152 | + $message = apply_filters('uwp_get_account_deletion_message', '', $user); |
|
| 153 | + do_action('uwp_send_account_deletion_emails', $user, $message); |
|
| 154 | 154 | |
| 155 | 155 | $this->end_user_session(); |
| 156 | 156 | } |
@@ -164,15 +164,15 @@ discard block |
||
| 164 | 164 | * @param int $user_id The ID of the user being checked. |
| 165 | 165 | * @return bool True if user has active subscriptions, false otherwise. |
| 166 | 166 | */ |
| 167 | - private function has_active_subscriptions( $user_id ) { |
|
| 167 | + private function has_active_subscriptions($user_id) { |
|
| 168 | 168 | $subscriptions = getpaid_get_subscriptions( |
| 169 | 169 | array( |
| 170 | - 'customer_in' => array( (int) $user_id ), |
|
| 170 | + 'customer_in' => array((int) $user_id), |
|
| 171 | 171 | 'status' => 'active', |
| 172 | 172 | ) |
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | - return ! empty( $subscriptions ); |
|
| 175 | + return !empty($subscriptions); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -181,15 +181,15 @@ discard block |
||
| 181 | 181 | * @since 2.8.22 |
| 182 | 182 | * @param int $user_id The ID of the user. |
| 183 | 183 | */ |
| 184 | - private function cancel_active_subscriptions( $user_id ) { |
|
| 184 | + private function cancel_active_subscriptions($user_id) { |
|
| 185 | 185 | $subscriptions = getpaid_get_subscriptions( |
| 186 | 186 | array( |
| 187 | - 'customer_in' => array( (int) $user_id ), |
|
| 187 | + 'customer_in' => array((int) $user_id), |
|
| 188 | 188 | 'status' => 'active', |
| 189 | 189 | ) |
| 190 | 190 | ); |
| 191 | 191 | |
| 192 | - foreach ( $subscriptions as $subscription ) { |
|
| 192 | + foreach ($subscriptions as $subscription) { |
|
| 193 | 193 | $subscription->cancel(); |
| 194 | 194 | } |
| 195 | 195 | } |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param int $user_id The ID of the user being checked. |
| 202 | 202 | * @return bool True if user has paid invoices, false otherwise. |
| 203 | 203 | */ |
| 204 | - private function has_paid_invoices( $user_id ) { |
|
| 204 | + private function has_paid_invoices($user_id) { |
|
| 205 | 205 | $invoices = wpinv_get_invoices( |
| 206 | 206 | array( |
| 207 | 207 | 'user' => (int) $user_id, |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | ) |
| 210 | 210 | ); |
| 211 | 211 | |
| 212 | - return ! empty( $invoices->total ); |
|
| 212 | + return !empty($invoices->total); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -219,24 +219,24 @@ discard block |
||
| 219 | 219 | * @param int $user_id The ID of the user being deleted. |
| 220 | 220 | * @param string $reason The reason for preventing deletion. |
| 221 | 221 | */ |
| 222 | - private function prevent_user_deletion( $user_id, $reason ) { |
|
| 223 | - $user = get_userdata( $user_id ); |
|
| 222 | + private function prevent_user_deletion($user_id, $reason) { |
|
| 223 | + $user = get_userdata($user_id); |
|
| 224 | 224 | |
| 225 | - if ( 'active_subscriptions' === $reason ) { |
|
| 225 | + if ('active_subscriptions' === $reason) { |
|
| 226 | 226 | $this->error_message = sprintf( |
| 227 | 227 | /* translators: %s: user login */ |
| 228 | - esc_html__( 'User deletion for %s has been halted. All active subscriptions should be cancelled first.', 'invoicing' ), |
|
| 228 | + esc_html__('User deletion for %s has been halted. All active subscriptions should be cancelled first.', 'invoicing'), |
|
| 229 | 229 | $user->user_login |
| 230 | 230 | ); |
| 231 | 231 | } else { |
| 232 | 232 | $this->error_message = sprintf( |
| 233 | 233 | /* translators: %s: user login */ |
| 234 | - esc_html__( 'User deletion for %s has been halted due to paid invoices. Data will be anonymized instead.', 'invoicing' ), |
|
| 234 | + esc_html__('User deletion for %s has been halted due to paid invoices. Data will be anonymized instead.', 'invoicing'), |
|
| 235 | 235 | $user->user_login |
| 236 | 236 | ); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - wp_die( $this->error_message, esc_html__( 'User Deletion Halted', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 239 | + wp_die($this->error_message, esc_html__('User Deletion Halted', 'invoicing'), array('response' => 403)); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -246,17 +246,17 @@ discard block |
||
| 246 | 246 | * @param int $user_id The ID of the user to anonymize. |
| 247 | 247 | * @return bool True on success, false on failure. |
| 248 | 248 | */ |
| 249 | - private function anonymize_user_data( $user_id ) { |
|
| 249 | + private function anonymize_user_data($user_id) { |
|
| 250 | 250 | global $wpdb; |
| 251 | 251 | |
| 252 | - $user = get_userdata( $user_id ); |
|
| 253 | - if ( ! $user ) { |
|
| 252 | + $user = get_userdata($user_id); |
|
| 253 | + if (!$user) { |
|
| 254 | 254 | return false; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | $table_name = $wpdb->prefix . 'getpaid_customers'; |
| 258 | - $deletion_date = gmdate( 'Y-m-d', strtotime( '+10 years' ) ); |
|
| 259 | - $hashed_email = $this->hash_email( $user->user_email ); |
|
| 258 | + $deletion_date = gmdate('Y-m-d', strtotime('+10 years')); |
|
| 259 | + $hashed_email = $this->hash_email($user->user_email); |
|
| 260 | 260 | |
| 261 | 261 | $updated = $wpdb->update( |
| 262 | 262 | $table_name, |
@@ -267,10 +267,10 @@ discard block |
||
| 267 | 267 | 'email_cc' => $hashed_email, |
| 268 | 268 | 'phone' => '', |
| 269 | 269 | ), |
| 270 | - array( 'user_id' => (int) $user->ID ) |
|
| 270 | + array('user_id' => (int) $user->ID) |
|
| 271 | 271 | ); |
| 272 | 272 | |
| 273 | - if ( false === $updated ) { |
|
| 273 | + if (false === $updated) { |
|
| 274 | 274 | return false; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | * @since 2.8.22 |
| 288 | 288 | * @param int $user_id The ID of the user being anonymized. |
| 289 | 289 | */ |
| 290 | - do_action( 'wpinv_anonymize_user_meta_data', $user->ID ); |
|
| 290 | + do_action('wpinv_anonymize_user_meta_data', $user->ID); |
|
| 291 | 291 | |
| 292 | 292 | $user_meta_data = array( |
| 293 | 293 | 'nickname', |
@@ -312,13 +312,13 @@ discard block |
||
| 312 | 312 | * @param array $user_meta_data The meta fields to be anonymized. |
| 313 | 313 | * @param int $user_id The ID of the user being anonymized. |
| 314 | 314 | */ |
| 315 | - $user_meta_data = apply_filters( 'wpinv_user_meta_data_to_anonymize', $user_meta_data, $user->ID ); |
|
| 315 | + $user_meta_data = apply_filters('wpinv_user_meta_data_to_anonymize', $user_meta_data, $user->ID); |
|
| 316 | 316 | |
| 317 | - foreach ( $user_meta_data as $meta_key ) { |
|
| 318 | - delete_user_meta( $user->ID, $meta_key ); |
|
| 317 | + foreach ($user_meta_data as $meta_key) { |
|
| 318 | + delete_user_meta($user->ID, $meta_key); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - return $this->ensure_invoice_anonymization( $user->ID, 'anonymize' ); |
|
| 321 | + return $this->ensure_invoice_anonymization($user->ID, 'anonymize'); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -327,15 +327,15 @@ discard block |
||
| 327 | 327 | * @param int $user_id The ID of the user to delete. |
| 328 | 328 | * @return bool True on success, false on failure. |
| 329 | 329 | */ |
| 330 | - private function delete_user_data( $user_id ) { |
|
| 330 | + private function delete_user_data($user_id) { |
|
| 331 | 331 | // Delete associated invoices. |
| 332 | - $this->ensure_invoice_anonymization( $user_id, 'delete' ); |
|
| 332 | + $this->ensure_invoice_anonymization($user_id, 'delete'); |
|
| 333 | 333 | |
| 334 | 334 | // Delete the user. |
| 335 | - if ( is_multisite() ) { |
|
| 336 | - wpmu_delete_user( $user_id ); |
|
| 335 | + if (is_multisite()) { |
|
| 336 | + wpmu_delete_user($user_id); |
|
| 337 | 337 | } else { |
| 338 | - wp_delete_user( $user_id ); |
|
| 338 | + wp_delete_user($user_id); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | * @since 2.8.22 |
| 345 | 345 | * @param int $user_id The ID of the user being deleted. |
| 346 | 346 | */ |
| 347 | - do_action( 'wpinv_delete_user_data', $user_id ); |
|
| 347 | + do_action('wpinv_delete_user_data', $user_id); |
|
| 348 | 348 | |
| 349 | 349 | return true; |
| 350 | 350 | } |
@@ -357,8 +357,8 @@ discard block |
||
| 357 | 357 | * @param string $action The action to perform (anonymize or delete). |
| 358 | 358 | * @return bool True on success, false on failure. |
| 359 | 359 | */ |
| 360 | - public function ensure_invoice_anonymization( $user_id, $action = 'anonymize' ) { |
|
| 361 | - $invoices = wpinv_get_invoices( array( 'user' => $user_id ) ); |
|
| 360 | + public function ensure_invoice_anonymization($user_id, $action = 'anonymize') { |
|
| 361 | + $invoices = wpinv_get_invoices(array('user' => $user_id)); |
|
| 362 | 362 | |
| 363 | 363 | /** |
| 364 | 364 | * Filters the invoice meta fields to be anonymized. |
@@ -367,22 +367,22 @@ discard block |
||
| 367 | 367 | * @param array $inv_meta_data The meta fields to be anonymized. |
| 368 | 368 | * @param int $user_id The ID of the user being processed. |
| 369 | 369 | */ |
| 370 | - $inv_meta_data = apply_filters( 'wpinv_invoice_meta_data_to_anonymize', array(), $user_id ); |
|
| 370 | + $inv_meta_data = apply_filters('wpinv_invoice_meta_data_to_anonymize', array(), $user_id); |
|
| 371 | 371 | |
| 372 | - foreach ( $invoices->invoices as $invoice ) { |
|
| 373 | - foreach ( $inv_meta_data as $meta_key ) { |
|
| 374 | - delete_post_meta( $invoice->get_id(), $meta_key ); |
|
| 372 | + foreach ($invoices->invoices as $invoice) { |
|
| 373 | + foreach ($inv_meta_data as $meta_key) { |
|
| 374 | + delete_post_meta($invoice->get_id(), $meta_key); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if ( 'anonymize' === $action ) { |
|
| 378 | - $hashed_inv_email = $this->hash_email( $invoice->get_email() ); |
|
| 379 | - $hashed_inv_email_cc = $this->hash_email( $invoice->get_email_cc() ); |
|
| 377 | + if ('anonymize' === $action) { |
|
| 378 | + $hashed_inv_email = $this->hash_email($invoice->get_email()); |
|
| 379 | + $hashed_inv_email_cc = $this->hash_email($invoice->get_email_cc()); |
|
| 380 | 380 | |
| 381 | - $invoice->set_email( $hashed_inv_email ); |
|
| 382 | - $invoice->set_email_cc( $hashed_inv_email_cc ); |
|
| 383 | - $invoice->set_phone( '' ); |
|
| 384 | - $invoice->set_ip( $this->anonymize_data( $invoice->get_ip() ) ); |
|
| 385 | - $invoice->set_is_anonymized( 1 ); |
|
| 381 | + $invoice->set_email($hashed_inv_email); |
|
| 382 | + $invoice->set_email_cc($hashed_inv_email_cc); |
|
| 383 | + $invoice->set_phone(''); |
|
| 384 | + $invoice->set_ip($this->anonymize_data($invoice->get_ip())); |
|
| 385 | + $invoice->set_is_anonymized(1); |
|
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | 388 | * Fires when anonymizing additional invoice data. |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | * @param WPInv_Invoice $invoice The invoice being anonymized. |
| 392 | 392 | * @param string $action The action being performed (anonymize or delete). |
| 393 | 393 | */ |
| 394 | - do_action( 'wpinv_anonymize_invoice_data', $invoice, $action ); |
|
| 394 | + do_action('wpinv_anonymize_invoice_data', $invoice, $action); |
|
| 395 | 395 | |
| 396 | 396 | $invoice->save(); |
| 397 | 397 | } else { |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - return $this->log_deletion_action( $user_id, $invoices->invoices, $action ); |
|
| 402 | + return $this->log_deletion_action($user_id, $invoices->invoices, $action); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -411,16 +411,16 @@ discard block |
||
| 411 | 411 | * @param string $action The action being performed (anonymize or delete). |
| 412 | 412 | * @return bool True on success, false on failure. |
| 413 | 413 | */ |
| 414 | - private function log_deletion_action( $user_id, $invoices, $action ) { |
|
| 414 | + private function log_deletion_action($user_id, $invoices, $action) { |
|
| 415 | 415 | global $wpdb; |
| 416 | 416 | |
| 417 | 417 | $table_name = $wpdb->prefix . 'getpaid_anonymization_logs'; |
| 418 | - $user_data = get_userdata( $user_id ); |
|
| 418 | + $user_data = get_userdata($user_id); |
|
| 419 | 419 | |
| 420 | 420 | $additional_info = array( |
| 421 | 421 | 'user_email' => $user_data ? $user_data->user_email : 'N/A', |
| 422 | 422 | 'user_registered' => $user_data ? $user_data->user_registered : 'N/A', |
| 423 | - 'invoice_count' => count( $invoices ), |
|
| 423 | + 'invoice_count' => count($invoices), |
|
| 424 | 424 | ); |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -432,28 +432,28 @@ discard block |
||
| 432 | 432 | * @param array $invoices The invoices being processed. |
| 433 | 433 | * @param string $action The action being performed (anonymize or delete). |
| 434 | 434 | */ |
| 435 | - $additional_info = apply_filters( 'wpinv_anonymization_log_additional_info', $additional_info, $user_id, $invoices, $action ); |
|
| 435 | + $additional_info = apply_filters('wpinv_anonymization_log_additional_info', $additional_info, $user_id, $invoices, $action); |
|
| 436 | 436 | |
| 437 | 437 | $data = array( |
| 438 | 438 | 'user_id' => $user_id, |
| 439 | - 'action' => sanitize_text_field( $action ), |
|
| 439 | + 'action' => sanitize_text_field($action), |
|
| 440 | 440 | 'data_type' => 'invoices', |
| 441 | - 'timestamp' => current_time( 'mysql' ), |
|
| 442 | - 'additional_info' => wp_json_encode( $additional_info ), |
|
| 441 | + 'timestamp' => current_time('mysql'), |
|
| 442 | + 'additional_info' => wp_json_encode($additional_info), |
|
| 443 | 443 | ); |
| 444 | 444 | |
| 445 | 445 | $format = array( |
| 446 | - '%d', // user_id |
|
| 447 | - '%s', // action |
|
| 448 | - '%s', // data_type |
|
| 449 | - '%s', // timestamp |
|
| 450 | - '%s', // additional_info |
|
| 446 | + '%d', // user_id |
|
| 447 | + '%s', // action |
|
| 448 | + '%s', // data_type |
|
| 449 | + '%s', // timestamp |
|
| 450 | + '%s', // additional_info |
|
| 451 | 451 | ); |
| 452 | 452 | |
| 453 | - $result = $wpdb->insert( $table_name, $data, $format ); |
|
| 453 | + $result = $wpdb->insert($table_name, $data, $format); |
|
| 454 | 454 | |
| 455 | - if ( false === $result ) { |
|
| 456 | - wpinv_error_log( sprintf( 'Failed to log anonymization action for user ID: %d. Error: %s', $user_id, $wpdb->last_error ) ); |
|
| 455 | + if (false === $result) { |
|
| 456 | + wpinv_error_log(sprintf('Failed to log anonymization action for user ID: %d. Error: %s', $user_id, $wpdb->last_error)); |
|
| 457 | 457 | return false; |
| 458 | 458 | } |
| 459 | 459 | |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | * @param string $action The action being performed (anonymize or delete). |
| 467 | 467 | * @param array $data The data that was inserted into the log. |
| 468 | 468 | */ |
| 469 | - do_action( 'wpinv_after_log_deletion_action', $user_id, $invoices, $action, $data ); |
|
| 469 | + do_action('wpinv_after_log_deletion_action', $user_id, $invoices, $action, $data); |
|
| 470 | 470 | |
| 471 | 471 | return true; |
| 472 | 472 | } |
@@ -479,20 +479,20 @@ discard block |
||
| 479 | 479 | * @param int $user_id The ID of the user being erased. |
| 480 | 480 | * @return array The modified response. |
| 481 | 481 | */ |
| 482 | - public function handle_erasure_request( $response, $user_id ) { |
|
| 483 | - if ( $this->has_active_subscriptions( $user_id ) ) { |
|
| 484 | - $response['messages'][] = esc_html__( 'User has active subscriptions. Data cannot be erased at this time.', 'invoicing' ); |
|
| 482 | + public function handle_erasure_request($response, $user_id) { |
|
| 483 | + if ($this->has_active_subscriptions($user_id)) { |
|
| 484 | + $response['messages'][] = esc_html__('User has active subscriptions. Data cannot be erased at this time.', 'invoicing'); |
|
| 485 | 485 | $response['items_removed'] = false; |
| 486 | - } elseif ( $this->has_paid_invoices( $user_id ) ) { |
|
| 487 | - $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' ); |
|
| 488 | - if ( 'anonymize' === $retention_method ) { |
|
| 489 | - $this->anonymize_user_data( $user_id ); |
|
| 490 | - $response['messages'][] = esc_html__( 'User data has been anonymized due to existing paid invoices.', 'invoicing' ); |
|
| 486 | + } elseif ($this->has_paid_invoices($user_id)) { |
|
| 487 | + $retention_method = wpinv_get_option('data_retention_method', 'anonymize'); |
|
| 488 | + if ('anonymize' === $retention_method) { |
|
| 489 | + $this->anonymize_user_data($user_id); |
|
| 490 | + $response['messages'][] = esc_html__('User data has been anonymized due to existing paid invoices.', 'invoicing'); |
|
| 491 | 491 | $response['items_removed'] = false; |
| 492 | 492 | $response['items_retained'] = true; |
| 493 | 493 | } else { |
| 494 | - $this->delete_user_data( $user_id ); |
|
| 495 | - $response['messages'][] = esc_html__( 'User data has been deleted.', 'invoicing' ); |
|
| 494 | + $this->delete_user_data($user_id); |
|
| 495 | + $response['messages'][] = esc_html__('User data has been deleted.', 'invoicing'); |
|
| 496 | 496 | $response['items_removed'] = true; |
| 497 | 497 | $response['items_retained'] = false; |
| 498 | 498 | } |
@@ -508,18 +508,18 @@ discard block |
||
| 508 | 508 | * @param string $email The email to hash. |
| 509 | 509 | * @return string The hashed email. |
| 510 | 510 | */ |
| 511 | - private function hash_email( $email ) { |
|
| 511 | + private function hash_email($email) { |
|
| 512 | 512 | $site_url = get_site_url(); |
| 513 | - $domain = wp_parse_url( $site_url, PHP_URL_HOST ); |
|
| 513 | + $domain = wp_parse_url($site_url, PHP_URL_HOST); |
|
| 514 | 514 | |
| 515 | - if ( empty( $domain ) ) { |
|
| 515 | + if (empty($domain)) { |
|
| 516 | 516 | return $email; |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | - $clean_email = sanitize_email( strtolower( trim( $email ) ) ); |
|
| 520 | - $hash = wp_hash( $clean_email ); |
|
| 521 | - $hash = substr( $hash, 0, 20 ); |
|
| 522 | - $anonymized_email = sprintf( '%s@%s', $hash, $domain ); |
|
| 519 | + $clean_email = sanitize_email(strtolower(trim($email))); |
|
| 520 | + $hash = wp_hash($clean_email); |
|
| 521 | + $hash = substr($hash, 0, 20); |
|
| 522 | + $anonymized_email = sprintf('%s@%s', $hash, $domain); |
|
| 523 | 523 | |
| 524 | 524 | /** |
| 525 | 525 | * Filters the anonymized email before returning. |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | * @param string $anonymized_email The anonymized email address. |
| 529 | 529 | * @param string $email The original email address. |
| 530 | 530 | */ |
| 531 | - return apply_filters( 'wpinv_anonymized_email', $anonymized_email, $email ); |
|
| 531 | + return apply_filters('wpinv_anonymized_email', $anonymized_email, $email); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -538,12 +538,12 @@ discard block |
||
| 538 | 538 | * @param string $data The data to anonymize. |
| 539 | 539 | * @return string The anonymized data. |
| 540 | 540 | */ |
| 541 | - private function anonymize_data( $data ) { |
|
| 542 | - if ( empty( $data ) ) { |
|
| 541 | + private function anonymize_data($data) { |
|
| 542 | + if (empty($data)) { |
|
| 543 | 543 | return ''; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - return wp_privacy_anonymize_data( 'text', $data ); |
|
| 546 | + return wp_privacy_anonymize_data('text', $data); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -557,17 +557,17 @@ discard block |
||
| 557 | 557 | public function perform_data_retention_cleanup() { |
| 558 | 558 | global $wpdb; |
| 559 | 559 | |
| 560 | - $retention_period = wpinv_get_option( 'data_retention_period', '3650' ); |
|
| 560 | + $retention_period = wpinv_get_option('data_retention_period', '3650'); |
|
| 561 | 561 | |
| 562 | 562 | // If retention period is set to 'never', exit the function. |
| 563 | - if ( 'never' === $retention_period ) { |
|
| 563 | + if ('never' === $retention_period) { |
|
| 564 | 564 | return; |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | $customers_table = $wpdb->prefix . 'getpaid_customers'; |
| 568 | 568 | |
| 569 | 569 | // Calculate the cutoff date for data retention. |
| 570 | - $cutoff_date = gmdate( 'Y-m-d', strtotime( "-$retention_period days" ) ); |
|
| 570 | + $cutoff_date = gmdate('Y-m-d', strtotime("-$retention_period days")); |
|
| 571 | 571 | |
| 572 | 572 | $expired_records = $wpdb->get_results( |
| 573 | 573 | $wpdb->prepare( |
@@ -582,18 +582,18 @@ discard block |
||
| 582 | 582 | * @since 2.8.22 |
| 583 | 583 | * @param array $expired_records Array of customer records to be processed. |
| 584 | 584 | */ |
| 585 | - do_action( 'getpaid_data_retention_before_cleanup', $expired_records ); |
|
| 585 | + do_action('getpaid_data_retention_before_cleanup', $expired_records); |
|
| 586 | 586 | |
| 587 | - if ( ! empty( $expired_records ) ) { |
|
| 587 | + if (!empty($expired_records)) { |
|
| 588 | 588 | // Disable our custom user deletion handling. |
| 589 | 589 | $this->handle_user_deletion = false; |
| 590 | 590 | |
| 591 | - foreach ( $expired_records as $record ) { |
|
| 591 | + foreach ($expired_records as $record) { |
|
| 592 | 592 | // Delete associated invoices. |
| 593 | - $this->ensure_invoice_anonymization( (int) $record->user_id, 'delete' ); |
|
| 593 | + $this->ensure_invoice_anonymization((int) $record->user_id, 'delete'); |
|
| 594 | 594 | |
| 595 | 595 | // Delete the user. |
| 596 | - wp_delete_user( (int) $record->user_id ); |
|
| 596 | + wp_delete_user((int) $record->user_id); |
|
| 597 | 597 | |
| 598 | 598 | /** |
| 599 | 599 | * Fires after processing each expired record during cleanup. |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | * @since 2.8.22 |
| 602 | 602 | * @param object $record The customer record being processed. |
| 603 | 603 | */ |
| 604 | - do_action( 'getpaid_data_retention_process_record', $record ); |
|
| 604 | + do_action('getpaid_data_retention_process_record', $record); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | // Re-enable our custom user deletion handling. |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | * @since 2.8.22 |
| 614 | 614 | * @param array $expired_records Array of customer records that were processed. |
| 615 | 615 | */ |
| 616 | - do_action( 'getpaid_data_retention_after_cleanup', $expired_records ); |
|
| 616 | + do_action('getpaid_data_retention_after_cleanup', $expired_records); |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | * @param int $retention_period The current retention period in years. |
| 624 | 624 | * @param string $cutoff_date The cutoff date used for identifying expired records. |
| 625 | 625 | */ |
| 626 | - do_action( 'getpaid_data_retention_cleanup_complete', $retention_period, $cutoff_date ); |
|
| 626 | + do_action('getpaid_data_retention_cleanup_complete', $retention_period, $cutoff_date); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | /** |
@@ -636,7 +636,7 @@ discard block |
||
| 636 | 636 | |
| 637 | 637 | // Redirect after deletion. |
| 638 | 638 | $redirect_page = home_url(); |
| 639 | - wp_safe_redirect( $redirect_page ); |
|
| 639 | + wp_safe_redirect($redirect_page); |
|
| 640 | 640 | exit(); |
| 641 | 641 | } |
| 642 | 642 | } |
@@ -14,31 +14,31 @@ 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 | - 'customer_id' => 0, |
|
| 39 | - 'status' => 'wpi-pending', |
|
| 40 | - 'version' => '', |
|
| 41 | - '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 | + 'customer_id' => 0, |
|
| 39 | + 'status' => 'wpi-pending', |
|
| 40 | + 'version' => '', |
|
| 41 | + 'date_created' => null, |
|
| 42 | 42 | 'date_modified' => null, |
| 43 | 43 | 'due_date' => null, |
| 44 | 44 | 'completed_date' => null, |
@@ -61,17 +61,17 @@ discard block |
||
| 61 | 61 | 'state' => null, |
| 62 | 62 | 'zip' => null, |
| 63 | 63 | 'company' => null, |
| 64 | - 'company_id' => null, |
|
| 64 | + 'company_id' => null, |
|
| 65 | 65 | 'vat_number' => null, |
| 66 | 66 | 'vat_rate' => null, |
| 67 | 67 | 'address' => null, |
| 68 | 68 | 'address_confirmed' => false, |
| 69 | 69 | 'shipping' => null, |
| 70 | - 'subtotal' => 0, |
|
| 70 | + 'subtotal' => 0, |
|
| 71 | 71 | 'total_discount' => 0, |
| 72 | 72 | 'total_tax' => 0, |
| 73 | - 'total_fees' => 0, |
|
| 74 | - 'total' => 0, |
|
| 73 | + 'total_fees' => 0, |
|
| 74 | + 'total' => 0, |
|
| 75 | 75 | 'fees' => array(), |
| 76 | 76 | 'discounts' => array(), |
| 77 | 77 | 'taxes' => array(), |
@@ -83,23 +83,23 @@ discard block |
||
| 83 | 83 | 'transaction_id' => '', |
| 84 | 84 | 'currency' => '', |
| 85 | 85 | 'disable_taxes' => false, |
| 86 | - 'subscription_id' => null, |
|
| 87 | - 'remote_subscription_id' => null, |
|
| 86 | + 'subscription_id' => null, |
|
| 87 | + 'remote_subscription_id' => null, |
|
| 88 | 88 | 'is_anonymized' => false, |
| 89 | - 'is_viewed' => false, |
|
| 90 | - 'email_cc' => '', |
|
| 91 | - 'template' => 'quantity', // hours, amount only |
|
| 92 | - 'created_via' => null, |
|
| 89 | + 'is_viewed' => false, |
|
| 90 | + 'email_cc' => '', |
|
| 91 | + 'template' => 'quantity', // hours, amount only |
|
| 92 | + 'created_via' => null, |
|
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | - * Stores meta in cache for future reads. |
|
| 97 | - * |
|
| 98 | - * A group must be set to to enable caching. |
|
| 99 | - * |
|
| 100 | - * @var string |
|
| 101 | - */ |
|
| 102 | - protected $cache_group = 'getpaid_invoices'; |
|
| 96 | + * Stores meta in cache for future reads. |
|
| 97 | + * |
|
| 98 | + * A group must be set to to enable caching. |
|
| 99 | + * |
|
| 100 | + * @var string |
|
| 101 | + */ |
|
| 102 | + protected $cache_group = 'getpaid_invoices'; |
|
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | 105 | * Stores a reference to the original WP_Post object |
@@ -113,121 +113,121 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @var int |
| 115 | 115 | */ |
| 116 | - protected $recurring_item = null; |
|
| 116 | + protected $recurring_item = null; |
|
| 117 | 117 | |
| 118 | - /** |
|
| 118 | + /** |
|
| 119 | 119 | * Stores an array of item totals. |
| 120 | - * |
|
| 121 | - * e.g $totals['discount'] = array( |
|
| 122 | - * 'initial' => 10, |
|
| 123 | - * 'recurring' => 10, |
|
| 124 | - * ) |
|
| 120 | + * |
|
| 121 | + * e.g $totals['discount'] = array( |
|
| 122 | + * 'initial' => 10, |
|
| 123 | + * 'recurring' => 10, |
|
| 124 | + * ) |
|
| 125 | 125 | * |
| 126 | 126 | * @var array |
| 127 | 127 | */ |
| 128 | - protected $totals = array(); |
|
| 128 | + protected $totals = array(); |
|
| 129 | 129 | |
| 130 | - /** |
|
| 130 | + /** |
|
| 131 | 131 | * Tax rate. |
| 132 | - * |
|
| 132 | + * |
|
| 133 | 133 | * @var float |
| 134 | 134 | */ |
| 135 | - protected $tax_rate = 0; |
|
| 135 | + protected $tax_rate = 0; |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Stores the status transition information. |
|
| 139 | - * |
|
| 140 | - * @since 1.0.19 |
|
| 141 | - * @var bool|array |
|
| 142 | - */ |
|
| 143 | - protected $status_transition = false; |
|
| 137 | + /** |
|
| 138 | + * Stores the status transition information. |
|
| 139 | + * |
|
| 140 | + * @since 1.0.19 |
|
| 141 | + * @var bool|array |
|
| 142 | + */ |
|
| 143 | + protected $status_transition = false; |
|
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 147 | - * |
|
| 148 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 149 | - */ |
|
| 146 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 147 | + * |
|
| 148 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 149 | + */ |
|
| 150 | 150 | public function __construct( $invoice = 0 ) { |
| 151 | 151 | |
| 152 | 152 | parent::__construct( $invoice ); |
| 153 | 153 | |
| 154 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 155 | - $this->set_id( (int) $invoice ); |
|
| 156 | - } elseif ( $invoice instanceof self ) { |
|
| 157 | - $this->set_id( $invoice->get_id() ); |
|
| 158 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
| 159 | - $this->set_id( $invoice->ID ); |
|
| 160 | - } elseif ( is_array( $invoice ) ) { |
|
| 161 | - $this->set_props( $invoice ); |
|
| 162 | - |
|
| 163 | - if ( isset( $invoice['ID'] ) ) { |
|
| 164 | - $this->set_id( $invoice['ID'] ); |
|
| 165 | - } |
|
| 154 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 155 | + $this->set_id( (int) $invoice ); |
|
| 156 | + } elseif ( $invoice instanceof self ) { |
|
| 157 | + $this->set_id( $invoice->get_id() ); |
|
| 158 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
| 159 | + $this->set_id( $invoice->ID ); |
|
| 160 | + } elseif ( is_array( $invoice ) ) { |
|
| 161 | + $this->set_props( $invoice ); |
|
| 162 | + |
|
| 163 | + if ( isset( $invoice['ID'] ) ) { |
|
| 164 | + $this->set_id( $invoice['ID'] ); |
|
| 165 | + } |
|
| 166 | 166 | } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
| 167 | - $this->set_id( $invoice_id ); |
|
| 168 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 169 | - $this->set_id( $invoice_id ); |
|
| 170 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 171 | - $this->set_id( $invoice_id ); |
|
| 172 | - } else { |
|
| 173 | - $this->set_object_read( true ); |
|
| 174 | - } |
|
| 167 | + $this->set_id( $invoice_id ); |
|
| 168 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 169 | + $this->set_id( $invoice_id ); |
|
| 170 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 171 | + $this->set_id( $invoice_id ); |
|
| 172 | + } else { |
|
| 173 | + $this->set_object_read( true ); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | // Load the datastore. |
| 177 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 177 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 178 | 178 | |
| 179 | - if ( $this->get_id() > 0 ) { |
|
| 179 | + if ( $this->get_id() > 0 ) { |
|
| 180 | 180 | $this->post = get_post( $this->get_id() ); |
| 181 | 181 | $this->ID = $this->get_id(); |
| 182 | - $this->data_store->read( $this ); |
|
| 182 | + $this->data_store->read( $this ); |
|
| 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'; |
| 222 | - $db_field = 'key' === $field ? 'invoice_key' : $field; |
|
| 222 | + $db_field = 'key' === $field ? 'invoice_key' : $field; |
|
| 223 | 223 | $invoice_id = (int) $wpdb->get_var( |
| 224 | 224 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$db_field`=%s LIMIT 1", $value ) |
| 225 | 225 | ); |
| 226 | 226 | |
| 227 | - // Update the cache with our data |
|
| 228 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 227 | + // Update the cache with our data |
|
| 228 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 229 | 229 | |
| 230 | - return $invoice_id; |
|
| 230 | + return $invoice_id; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -253,83 +253,83 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | - * Get parent invoice ID. |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - * @param string $context View or edit context. |
|
| 260 | - * @return int |
|
| 261 | - */ |
|
| 262 | - public function get_parent_id( $context = 'view' ) { |
|
| 263 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 256 | + * Get parent invoice ID. |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + * @param string $context View or edit context. |
|
| 260 | + * @return int |
|
| 261 | + */ |
|
| 262 | + public function get_parent_id( $context = 'view' ) { |
|
| 263 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | - * Get parent invoice. |
|
| 268 | - * |
|
| 269 | - * @since 1.0.19 |
|
| 270 | - * @return WPInv_Invoice |
|
| 271 | - */ |
|
| 267 | + * Get parent invoice. |
|
| 268 | + * |
|
| 269 | + * @since 1.0.19 |
|
| 270 | + * @return WPInv_Invoice |
|
| 271 | + */ |
|
| 272 | 272 | public function get_parent_payment() { |
| 273 | 273 | return new WPInv_Invoice( $this->get_parent_id() ); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
| 277 | - * Alias for self::get_parent_payment(). |
|
| 278 | - * |
|
| 279 | - * @since 1.0.19 |
|
| 280 | - * @return WPInv_Invoice |
|
| 281 | - */ |
|
| 277 | + * Alias for self::get_parent_payment(). |
|
| 278 | + * |
|
| 279 | + * @since 1.0.19 |
|
| 280 | + * @return WPInv_Invoice |
|
| 281 | + */ |
|
| 282 | 282 | public function get_parent() { |
| 283 | 283 | return $this->get_parent_payment(); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
| 287 | - * Get invoice status. |
|
| 288 | - * |
|
| 289 | - * @since 1.0.19 |
|
| 290 | - * @param string $context View or edit context. |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - public function get_status( $context = 'view' ) { |
|
| 294 | - return $this->get_prop( 'status', $context ); |
|
| 295 | - } |
|
| 287 | + * Get invoice status. |
|
| 288 | + * |
|
| 289 | + * @since 1.0.19 |
|
| 290 | + * @param string $context View or edit context. |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + public function get_status( $context = 'view' ) { |
|
| 294 | + return $this->get_prop( 'status', $context ); |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - /** |
|
| 298 | - * Retrieves an array of possible invoice statuses. |
|
| 299 | - * |
|
| 300 | - * @since 1.0.19 |
|
| 301 | - * @return array |
|
| 302 | - */ |
|
| 303 | - public function get_all_statuses() { |
|
| 304 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 297 | + /** |
|
| 298 | + * Retrieves an array of possible invoice statuses. |
|
| 299 | + * |
|
| 300 | + * @since 1.0.19 |
|
| 301 | + * @return array |
|
| 302 | + */ |
|
| 303 | + public function get_all_statuses() { |
|
| 304 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | - * Get invoice status nice name. |
|
| 309 | - * |
|
| 310 | - * @since 1.0.19 |
|
| 311 | - * @return string |
|
| 312 | - */ |
|
| 308 | + * Get invoice status nice name. |
|
| 309 | + * |
|
| 310 | + * @since 1.0.19 |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 313 | 313 | public function get_status_nicename() { |
| 314 | - $statuses = $this->get_all_statuses(); |
|
| 314 | + $statuses = $this->get_all_statuses(); |
|
| 315 | 315 | |
| 316 | 316 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
| 317 | 317 | |
| 318 | 318 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - /** |
|
| 322 | - * Retrieves the invoice status class |
|
| 323 | - * |
|
| 324 | - * @since 1.0.19 |
|
| 325 | - * @return string |
|
| 326 | - */ |
|
| 327 | - public function get_status_class() { |
|
| 328 | - $statuses = getpaid_get_invoice_status_classes(); |
|
| 329 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark text-white'; |
|
| 330 | - } |
|
| 321 | + /** |
|
| 322 | + * Retrieves the invoice status class |
|
| 323 | + * |
|
| 324 | + * @since 1.0.19 |
|
| 325 | + * @return string |
|
| 326 | + */ |
|
| 327 | + public function get_status_class() { |
|
| 328 | + $statuses = getpaid_get_invoice_status_classes(); |
|
| 329 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark text-white'; |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - /** |
|
| 332 | + /** |
|
| 333 | 333 | * Retrieves the invoice status label html |
| 334 | 334 | * |
| 335 | 335 | * @since 1.0.0 |
@@ -337,261 +337,261 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | public function get_status_label_html() { |
| 339 | 339 | |
| 340 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 341 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 342 | - $class = esc_attr( $this->get_status_class() ); |
|
| 343 | - |
|
| 344 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Get plugin version when the invoice was created. |
|
| 349 | - * |
|
| 350 | - * @since 1.0.19 |
|
| 351 | - * @param string $context View or edit context. |
|
| 352 | - * @return string |
|
| 353 | - */ |
|
| 354 | - public function get_version( $context = 'view' ) { |
|
| 355 | - return $this->get_prop( 'version', $context ); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @deprecated |
|
| 360 | - */ |
|
| 361 | - public function get_invoice_date( $format = true ) { |
|
| 362 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 363 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 364 | - $formatted = getpaid_format_date( $date ); |
|
| 365 | - |
|
| 366 | - if ( $format ) { |
|
| 367 | - return $formatted; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - return empty( $formatted ) ? '' : $date; |
|
| 371 | - } |
|
| 372 | - |
|
| 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 | - } |
|
| 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' ) { |
|
| 340 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 341 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 342 | + $class = esc_attr( $this->get_status_class() ); |
|
| 343 | + |
|
| 344 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Get plugin version when the invoice was created. |
|
| 349 | + * |
|
| 350 | + * @since 1.0.19 |
|
| 351 | + * @param string $context View or edit context. |
|
| 352 | + * @return string |
|
| 353 | + */ |
|
| 354 | + public function get_version( $context = 'view' ) { |
|
| 355 | + return $this->get_prop( 'version', $context ); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @deprecated |
|
| 360 | + */ |
|
| 361 | + public function get_invoice_date( $format = true ) { |
|
| 362 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 363 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 364 | + $formatted = getpaid_format_date( $date ); |
|
| 365 | + |
|
| 366 | + if ( $format ) { |
|
| 367 | + return $formatted; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + return empty( $formatted ) ? '' : $date; |
|
| 371 | + } |
|
| 372 | + |
|
| 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 | + } |
|
| 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' ) { |
|
| 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; |
|
| 409 | - } |
|
| 410 | - |
|
| 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 | - } |
|
| 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 ); |
|
| 431 | - } |
|
| 432 | - |
|
| 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' ) { |
|
| 408 | + return $date; |
|
| 409 | + } |
|
| 410 | + |
|
| 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 | + } |
|
| 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 ); |
|
| 431 | + } |
|
| 432 | + |
|
| 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' ) { |
|
| 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 | - * Get the invoice key. |
|
| 580 | - * |
|
| 581 | - * @since 1.0.19 |
|
| 582 | - * @param string $context View or edit context. |
|
| 583 | - * @return string |
|
| 584 | - */ |
|
| 585 | - public function get_key( $context = 'view' ) { |
|
| 579 | + * Get the invoice key. |
|
| 580 | + * |
|
| 581 | + * @since 1.0.19 |
|
| 582 | + * @param string $context View or edit context. |
|
| 583 | + * @return string |
|
| 584 | + */ |
|
| 585 | + public function get_key( $context = 'view' ) { |
|
| 586 | 586 | return $this->get_prop( 'key', $context ); |
| 587 | - } |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Set the invoice key. |
|
| 591 | - * |
|
| 592 | - * @since 1.0.19 |
|
| 593 | - */ |
|
| 594 | - public function maybe_set_key() { |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Set the invoice key. |
|
| 591 | + * |
|
| 592 | + * @since 1.0.19 |
|
| 593 | + */ |
|
| 594 | + public function maybe_set_key() { |
|
| 595 | 595 | $key = $this->get_key(); |
| 596 | 596 | |
| 597 | 597 | if ( empty( $key ) ) { |
@@ -601,140 +601,140 @@ discard block |
||
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | /** |
| 604 | - * Get the invoice type. |
|
| 605 | - * |
|
| 606 | - * @since 1.0.19 |
|
| 607 | - * @param string $context View or edit context. |
|
| 608 | - * @return string |
|
| 609 | - */ |
|
| 610 | - public function get_type( $context = 'view' ) { |
|
| 604 | + * Get the invoice type. |
|
| 605 | + * |
|
| 606 | + * @since 1.0.19 |
|
| 607 | + * @param string $context View or edit context. |
|
| 608 | + * @return string |
|
| 609 | + */ |
|
| 610 | + public function get_type( $context = 'view' ) { |
|
| 611 | 611 | return $this->get_prop( 'type', $context ); |
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Returns the post type name. |
|
| 616 | - * |
|
| 617 | - * @since 1.0.19 |
|
| 618 | - * @return string |
|
| 619 | - */ |
|
| 620 | - public function get_invoice_quote_type() { |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Returns the post type name. |
|
| 616 | + * |
|
| 617 | + * @since 1.0.19 |
|
| 618 | + * @return string |
|
| 619 | + */ |
|
| 620 | + public function get_invoice_quote_type() { |
|
| 621 | 621 | return getpaid_get_post_type_label( $this->get_post_type(), false ); |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | /** |
| 625 | - * Get the invoice post type label. |
|
| 626 | - * |
|
| 627 | - * @since 1.0.19 |
|
| 628 | - * @param string $context View or edit context. |
|
| 629 | - * @return string |
|
| 630 | - */ |
|
| 631 | - public function get_label( $context = 'view' ) { |
|
| 625 | + * Get the invoice post type label. |
|
| 626 | + * |
|
| 627 | + * @since 1.0.19 |
|
| 628 | + * @param string $context View or edit context. |
|
| 629 | + * @return string |
|
| 630 | + */ |
|
| 631 | + public function get_label( $context = 'view' ) { |
|
| 632 | 632 | return getpaid_get_post_type_label( $this->get_post_type( $context ), false ); |
| 633 | - } |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * Get the invoice post type. |
|
| 637 | - * |
|
| 638 | - * @since 1.0.19 |
|
| 639 | - * @param string $context View or edit context. |
|
| 640 | - * @return string |
|
| 641 | - */ |
|
| 642 | - public function get_post_type( $context = 'view' ) { |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Get the invoice post type. |
|
| 637 | + * |
|
| 638 | + * @since 1.0.19 |
|
| 639 | + * @param string $context View or edit context. |
|
| 640 | + * @return string |
|
| 641 | + */ |
|
| 642 | + public function get_post_type( $context = 'view' ) { |
|
| 643 | 643 | return $this->get_prop( 'post_type', $context ); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** |
| 647 | - * Get the invoice mode. |
|
| 648 | - * |
|
| 649 | - * @since 1.0.19 |
|
| 650 | - * @param string $context View or edit context. |
|
| 651 | - * @return string |
|
| 652 | - */ |
|
| 653 | - public function get_mode( $context = 'view' ) { |
|
| 647 | + * Get the invoice mode. |
|
| 648 | + * |
|
| 649 | + * @since 1.0.19 |
|
| 650 | + * @param string $context View or edit context. |
|
| 651 | + * @return string |
|
| 652 | + */ |
|
| 653 | + public function get_mode( $context = 'view' ) { |
|
| 654 | 654 | return $this->get_prop( 'mode', $context ); |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
| 658 | - * Get the invoice path. |
|
| 659 | - * |
|
| 660 | - * @since 1.0.19 |
|
| 661 | - * @param string $context View or edit context. |
|
| 662 | - * @return string |
|
| 663 | - */ |
|
| 664 | - public function get_path( $context = 'view' ) { |
|
| 658 | + * Get the invoice path. |
|
| 659 | + * |
|
| 660 | + * @since 1.0.19 |
|
| 661 | + * @param string $context View or edit context. |
|
| 662 | + * @return string |
|
| 663 | + */ |
|
| 664 | + public function get_path( $context = 'view' ) { |
|
| 665 | 665 | $path = $this->get_prop( 'path', $context ); |
| 666 | - $prefix = $this->get_type(); |
|
| 666 | + $prefix = $this->get_type(); |
|
| 667 | 667 | |
| 668 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 669 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 670 | - $this->set_path( $path ); |
|
| 671 | - } |
|
| 668 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 669 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 670 | + $this->set_path( $path ); |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | - return $path; |
|
| 673 | + return $path; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | /** |
| 677 | - * Get the invoice name/title. |
|
| 678 | - * |
|
| 679 | - * @since 1.0.19 |
|
| 680 | - * @param string $context View or edit context. |
|
| 681 | - * @return string |
|
| 682 | - */ |
|
| 683 | - public function get_name( $context = 'view' ) { |
|
| 677 | + * Get the invoice name/title. |
|
| 678 | + * |
|
| 679 | + * @since 1.0.19 |
|
| 680 | + * @param string $context View or edit context. |
|
| 681 | + * @return string |
|
| 682 | + */ |
|
| 683 | + public function get_name( $context = 'view' ) { |
|
| 684 | 684 | return $this->get_prop( 'title', $context ); |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
| 688 | - * Alias of self::get_name(). |
|
| 689 | - * |
|
| 690 | - * @since 1.0.19 |
|
| 691 | - * @param string $context View or edit context. |
|
| 692 | - * @return string |
|
| 693 | - */ |
|
| 694 | - public function get_title( $context = 'view' ) { |
|
| 695 | - return $this->get_name( $context ); |
|
| 688 | + * Alias of self::get_name(). |
|
| 689 | + * |
|
| 690 | + * @since 1.0.19 |
|
| 691 | + * @param string $context View or edit context. |
|
| 692 | + * @return string |
|
| 693 | + */ |
|
| 694 | + public function get_title( $context = 'view' ) { |
|
| 695 | + return $this->get_name( $context ); |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
| 699 | - * Get the invoice description. |
|
| 700 | - * |
|
| 701 | - * @since 1.0.19 |
|
| 702 | - * @param string $context View or edit context. |
|
| 703 | - * @return string |
|
| 704 | - */ |
|
| 705 | - public function get_description( $context = 'view' ) { |
|
| 706 | - return $this->get_prop( 'description', $context ); |
|
| 699 | + * Get the invoice description. |
|
| 700 | + * |
|
| 701 | + * @since 1.0.19 |
|
| 702 | + * @param string $context View or edit context. |
|
| 703 | + * @return string |
|
| 704 | + */ |
|
| 705 | + public function get_description( $context = 'view' ) { |
|
| 706 | + return $this->get_prop( 'description', $context ); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
| 710 | - * Alias of self::get_description(). |
|
| 711 | - * |
|
| 712 | - * @since 1.0.19 |
|
| 713 | - * @param string $context View or edit context. |
|
| 714 | - * @return string |
|
| 715 | - */ |
|
| 716 | - public function get_excerpt( $context = 'view' ) { |
|
| 717 | - return $this->get_description( $context ); |
|
| 710 | + * Alias of self::get_description(). |
|
| 711 | + * |
|
| 712 | + * @since 1.0.19 |
|
| 713 | + * @param string $context View or edit context. |
|
| 714 | + * @return string |
|
| 715 | + */ |
|
| 716 | + public function get_excerpt( $context = 'view' ) { |
|
| 717 | + return $this->get_description( $context ); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
| 721 | - * Alias of self::get_description(). |
|
| 722 | - * |
|
| 723 | - * @since 1.0.19 |
|
| 724 | - * @param string $context View or edit context. |
|
| 725 | - * @return string |
|
| 726 | - */ |
|
| 727 | - public function get_summary( $context = 'view' ) { |
|
| 728 | - return $this->get_description( $context ); |
|
| 721 | + * Alias of self::get_description(). |
|
| 722 | + * |
|
| 723 | + * @since 1.0.19 |
|
| 724 | + * @param string $context View or edit context. |
|
| 725 | + * @return string |
|
| 726 | + */ |
|
| 727 | + public function get_summary( $context = 'view' ) { |
|
| 728 | + return $this->get_description( $context ); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
| 732 | - * Returns the user info. |
|
| 733 | - * |
|
| 734 | - * @since 1.0.19 |
|
| 732 | + * Returns the user info. |
|
| 733 | + * |
|
| 734 | + * @since 1.0.19 |
|
| 735 | 735 | * @param string $context View or edit context. |
| 736 | - * @return array |
|
| 737 | - */ |
|
| 736 | + * @return array |
|
| 737 | + */ |
|
| 738 | 738 | public function get_user_info( $context = 'view' ) { |
| 739 | 739 | |
| 740 | 740 | $user_info = array( |
@@ -749,682 +749,682 @@ discard block |
||
| 749 | 749 | 'state' => $this->get_state( $context ), |
| 750 | 750 | 'zip' => $this->get_zip( $context ), |
| 751 | 751 | 'company' => $this->get_company( $context ), |
| 752 | - 'company_id' => $this->get_company_id( $context ), |
|
| 752 | + 'company_id' => $this->get_company_id( $context ), |
|
| 753 | 753 | 'vat_number' => $this->get_vat_number( $context ), |
| 754 | 754 | 'discount' => $this->get_discount_code( $context ), |
| 755 | - ); |
|
| 755 | + ); |
|
| 756 | 756 | |
| 757 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 757 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | /** |
| 761 | - * Get the user id. |
|
| 762 | - * |
|
| 763 | - * @since 1.0.19 |
|
| 764 | - * @param string $context View or edit context. |
|
| 765 | - * @return int |
|
| 766 | - */ |
|
| 767 | - public function get_author( $context = 'view' ) { |
|
| 768 | - return (int) $this->get_prop( 'author', $context ); |
|
| 761 | + * Get the user id. |
|
| 762 | + * |
|
| 763 | + * @since 1.0.19 |
|
| 764 | + * @param string $context View or edit context. |
|
| 765 | + * @return int |
|
| 766 | + */ |
|
| 767 | + public function get_author( $context = 'view' ) { |
|
| 768 | + return (int) $this->get_prop( 'author', $context ); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | /** |
| 772 | - * Alias of self::get_author(). |
|
| 773 | - * |
|
| 774 | - * @since 1.0.19 |
|
| 775 | - * @param string $context View or edit context. |
|
| 776 | - * @return int |
|
| 777 | - */ |
|
| 778 | - public function get_user_id( $context = 'view' ) { |
|
| 779 | - return $this->get_author( $context ); |
|
| 772 | + * Alias of self::get_author(). |
|
| 773 | + * |
|
| 774 | + * @since 1.0.19 |
|
| 775 | + * @param string $context View or edit context. |
|
| 776 | + * @return int |
|
| 777 | + */ |
|
| 778 | + public function get_user_id( $context = 'view' ) { |
|
| 779 | + return $this->get_author( $context ); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
| 783 | - * Get customer ID. |
|
| 784 | - * |
|
| 785 | - * @since 1.0.19 |
|
| 786 | - * @param string $context View or edit context. |
|
| 787 | - * @return int |
|
| 788 | - */ |
|
| 789 | - public function get_customer_id( $context = 'view' ) { |
|
| 790 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 783 | + * Get customer ID. |
|
| 784 | + * |
|
| 785 | + * @since 1.0.19 |
|
| 786 | + * @param string $context View or edit context. |
|
| 787 | + * @return int |
|
| 788 | + */ |
|
| 789 | + public function get_customer_id( $context = 'view' ) { |
|
| 790 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | /** |
| 794 | - * Get the customer's ip. |
|
| 795 | - * |
|
| 796 | - * @since 1.0.19 |
|
| 797 | - * @param string $context View or edit context. |
|
| 798 | - * @return string |
|
| 799 | - */ |
|
| 800 | - public function get_ip( $context = 'view' ) { |
|
| 801 | - return $this->get_prop( 'user_ip', $context ); |
|
| 794 | + * Get the customer's ip. |
|
| 795 | + * |
|
| 796 | + * @since 1.0.19 |
|
| 797 | + * @param string $context View or edit context. |
|
| 798 | + * @return string |
|
| 799 | + */ |
|
| 800 | + public function get_ip( $context = 'view' ) { |
|
| 801 | + return $this->get_prop( 'user_ip', $context ); |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
| 805 | - * Alias of self::get_ip(). |
|
| 806 | - * |
|
| 807 | - * @since 1.0.19 |
|
| 808 | - * @param string $context View or edit context. |
|
| 809 | - * @return string |
|
| 810 | - */ |
|
| 811 | - public function get_user_ip( $context = 'view' ) { |
|
| 812 | - return $this->get_ip( $context ); |
|
| 805 | + * Alias of self::get_ip(). |
|
| 806 | + * |
|
| 807 | + * @since 1.0.19 |
|
| 808 | + * @param string $context View or edit context. |
|
| 809 | + * @return string |
|
| 810 | + */ |
|
| 811 | + public function get_user_ip( $context = 'view' ) { |
|
| 812 | + return $this->get_ip( $context ); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | /** |
| 816 | - * Alias of self::get_ip(). |
|
| 817 | - * |
|
| 818 | - * @since 1.0.19 |
|
| 819 | - * @param string $context View or edit context. |
|
| 820 | - * @return string |
|
| 821 | - */ |
|
| 822 | - public function get_customer_ip( $context = 'view' ) { |
|
| 823 | - return $this->get_ip( $context ); |
|
| 816 | + * Alias of self::get_ip(). |
|
| 817 | + * |
|
| 818 | + * @since 1.0.19 |
|
| 819 | + * @param string $context View or edit context. |
|
| 820 | + * @return string |
|
| 821 | + */ |
|
| 822 | + public function get_customer_ip( $context = 'view' ) { |
|
| 823 | + return $this->get_ip( $context ); |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | /** |
| 827 | - * Get the customer's first name. |
|
| 828 | - * |
|
| 829 | - * @since 1.0.19 |
|
| 830 | - * @param string $context View or edit context. |
|
| 831 | - * @return string |
|
| 832 | - */ |
|
| 833 | - public function get_first_name( $context = 'view' ) { |
|
| 834 | - return $this->get_prop( 'first_name', $context ); |
|
| 827 | + * Get the customer's first name. |
|
| 828 | + * |
|
| 829 | + * @since 1.0.19 |
|
| 830 | + * @param string $context View or edit context. |
|
| 831 | + * @return string |
|
| 832 | + */ |
|
| 833 | + public function get_first_name( $context = 'view' ) { |
|
| 834 | + return $this->get_prop( 'first_name', $context ); |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
| 838 | - * Alias of self::get_first_name(). |
|
| 839 | - * |
|
| 840 | - * @since 1.0.19 |
|
| 841 | - * @param string $context View or edit context. |
|
| 842 | - * @return string |
|
| 843 | - */ |
|
| 844 | - public function get_user_first_name( $context = 'view' ) { |
|
| 845 | - return $this->get_first_name( $context ); |
|
| 838 | + * Alias of self::get_first_name(). |
|
| 839 | + * |
|
| 840 | + * @since 1.0.19 |
|
| 841 | + * @param string $context View or edit context. |
|
| 842 | + * @return string |
|
| 843 | + */ |
|
| 844 | + public function get_user_first_name( $context = 'view' ) { |
|
| 845 | + return $this->get_first_name( $context ); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | /** |
| 849 | - * Alias of self::get_first_name(). |
|
| 850 | - * |
|
| 851 | - * @since 1.0.19 |
|
| 852 | - * @param string $context View or edit context. |
|
| 853 | - * @return string |
|
| 854 | - */ |
|
| 855 | - public function get_customer_first_name( $context = 'view' ) { |
|
| 856 | - return $this->get_first_name( $context ); |
|
| 849 | + * Alias of self::get_first_name(). |
|
| 850 | + * |
|
| 851 | + * @since 1.0.19 |
|
| 852 | + * @param string $context View or edit context. |
|
| 853 | + * @return string |
|
| 854 | + */ |
|
| 855 | + public function get_customer_first_name( $context = 'view' ) { |
|
| 856 | + return $this->get_first_name( $context ); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
| 860 | - * Get the customer's last name. |
|
| 861 | - * |
|
| 862 | - * @since 1.0.19 |
|
| 863 | - * @param string $context View or edit context. |
|
| 864 | - * @return string |
|
| 865 | - */ |
|
| 866 | - public function get_last_name( $context = 'view' ) { |
|
| 867 | - return $this->get_prop( 'last_name', $context ); |
|
| 860 | + * Get the customer's last name. |
|
| 861 | + * |
|
| 862 | + * @since 1.0.19 |
|
| 863 | + * @param string $context View or edit context. |
|
| 864 | + * @return string |
|
| 865 | + */ |
|
| 866 | + public function get_last_name( $context = 'view' ) { |
|
| 867 | + return $this->get_prop( 'last_name', $context ); |
|
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | /** |
| 871 | - * Alias of self::get_last_name(). |
|
| 872 | - * |
|
| 873 | - * @since 1.0.19 |
|
| 874 | - * @param string $context View or edit context. |
|
| 875 | - * @return string |
|
| 876 | - */ |
|
| 877 | - public function get_user_last_name( $context = 'view' ) { |
|
| 878 | - return $this->get_last_name( $context ); |
|
| 871 | + * Alias of self::get_last_name(). |
|
| 872 | + * |
|
| 873 | + * @since 1.0.19 |
|
| 874 | + * @param string $context View or edit context. |
|
| 875 | + * @return string |
|
| 876 | + */ |
|
| 877 | + public function get_user_last_name( $context = 'view' ) { |
|
| 878 | + return $this->get_last_name( $context ); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | /** |
| 882 | - * Alias of self::get_last_name(). |
|
| 883 | - * |
|
| 884 | - * @since 1.0.19 |
|
| 885 | - * @param string $context View or edit context. |
|
| 886 | - * @return string |
|
| 887 | - */ |
|
| 888 | - public function get_customer_last_name( $context = 'view' ) { |
|
| 889 | - return $this->get_last_name( $context ); |
|
| 890 | - } |
|
| 882 | + * Alias of self::get_last_name(). |
|
| 883 | + * |
|
| 884 | + * @since 1.0.19 |
|
| 885 | + * @param string $context View or edit context. |
|
| 886 | + * @return string |
|
| 887 | + */ |
|
| 888 | + public function get_customer_last_name( $context = 'view' ) { |
|
| 889 | + return $this->get_last_name( $context ); |
|
| 890 | + } |
|
| 891 | 891 | |
| 892 | 892 | /** |
| 893 | - * Get the customer's full name. |
|
| 894 | - * |
|
| 895 | - * @since 1.0.19 |
|
| 896 | - * @param string $context View or edit context. |
|
| 897 | - * @return string |
|
| 898 | - */ |
|
| 899 | - public function get_full_name( $context = 'view' ) { |
|
| 900 | - $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 893 | + * Get the customer's full name. |
|
| 894 | + * |
|
| 895 | + * @since 1.0.19 |
|
| 896 | + * @param string $context View or edit context. |
|
| 897 | + * @return string |
|
| 898 | + */ |
|
| 899 | + public function get_full_name( $context = 'view' ) { |
|
| 900 | + $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 901 | 901 | |
| 902 | - if ( ! $name ) { |
|
| 903 | - $user = get_userdata( $this->get_author( $context ) ); |
|
| 902 | + if ( ! $name ) { |
|
| 903 | + $user = get_userdata( $this->get_author( $context ) ); |
|
| 904 | 904 | |
| 905 | - if ( $user ) { |
|
| 906 | - $name = $user->display_name; |
|
| 907 | - } |
|
| 908 | - } |
|
| 905 | + if ( $user ) { |
|
| 906 | + $name = $user->display_name; |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | 909 | |
| 910 | - if ( ! $name ) { |
|
| 911 | - $name = $this->get_email( $context ); |
|
| 912 | - } |
|
| 910 | + if ( ! $name ) { |
|
| 911 | + $name = $this->get_email( $context ); |
|
| 912 | + } |
|
| 913 | 913 | |
| 914 | - return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
| 914 | + return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | /** |
| 918 | - * Alias of self::get_full_name(). |
|
| 919 | - * |
|
| 920 | - * @since 1.0.19 |
|
| 921 | - * @param string $context View or edit context. |
|
| 922 | - * @return string |
|
| 923 | - */ |
|
| 924 | - public function get_user_full_name( $context = 'view' ) { |
|
| 925 | - return $this->get_full_name( $context ); |
|
| 918 | + * Alias of self::get_full_name(). |
|
| 919 | + * |
|
| 920 | + * @since 1.0.19 |
|
| 921 | + * @param string $context View or edit context. |
|
| 922 | + * @return string |
|
| 923 | + */ |
|
| 924 | + public function get_user_full_name( $context = 'view' ) { |
|
| 925 | + return $this->get_full_name( $context ); |
|
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | /** |
| 929 | - * Alias of self::get_full_name(). |
|
| 930 | - * |
|
| 931 | - * @since 1.0.19 |
|
| 932 | - * @param string $context View or edit context. |
|
| 933 | - * @return string |
|
| 934 | - */ |
|
| 935 | - public function get_customer_full_name( $context = 'view' ) { |
|
| 936 | - return $this->get_full_name( $context ); |
|
| 929 | + * Alias of self::get_full_name(). |
|
| 930 | + * |
|
| 931 | + * @since 1.0.19 |
|
| 932 | + * @param string $context View or edit context. |
|
| 933 | + * @return string |
|
| 934 | + */ |
|
| 935 | + public function get_customer_full_name( $context = 'view' ) { |
|
| 936 | + return $this->get_full_name( $context ); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | /** |
| 940 | - * Get the customer's phone number. |
|
| 941 | - * |
|
| 942 | - * @since 1.0.19 |
|
| 943 | - * @param string $context View or edit context. |
|
| 944 | - * @return string |
|
| 945 | - */ |
|
| 946 | - public function get_phone( $context = 'view' ) { |
|
| 947 | - return $this->get_prop( 'phone', $context ); |
|
| 940 | + * Get the customer's phone number. |
|
| 941 | + * |
|
| 942 | + * @since 1.0.19 |
|
| 943 | + * @param string $context View or edit context. |
|
| 944 | + * @return string |
|
| 945 | + */ |
|
| 946 | + public function get_phone( $context = 'view' ) { |
|
| 947 | + return $this->get_prop( 'phone', $context ); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | /** |
| 951 | - * Alias of self::get_phone(). |
|
| 952 | - * |
|
| 953 | - * @since 1.0.19 |
|
| 954 | - * @param string $context View or edit context. |
|
| 955 | - * @return string |
|
| 956 | - */ |
|
| 957 | - public function get_phone_number( $context = 'view' ) { |
|
| 958 | - return $this->get_phone( $context ); |
|
| 951 | + * Alias of self::get_phone(). |
|
| 952 | + * |
|
| 953 | + * @since 1.0.19 |
|
| 954 | + * @param string $context View or edit context. |
|
| 955 | + * @return string |
|
| 956 | + */ |
|
| 957 | + public function get_phone_number( $context = 'view' ) { |
|
| 958 | + return $this->get_phone( $context ); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
| 962 | - * Alias of self::get_phone(). |
|
| 963 | - * |
|
| 964 | - * @since 1.0.19 |
|
| 965 | - * @param string $context View or edit context. |
|
| 966 | - * @return string |
|
| 967 | - */ |
|
| 968 | - public function get_user_phone( $context = 'view' ) { |
|
| 969 | - return $this->get_phone( $context ); |
|
| 962 | + * Alias of self::get_phone(). |
|
| 963 | + * |
|
| 964 | + * @since 1.0.19 |
|
| 965 | + * @param string $context View or edit context. |
|
| 966 | + * @return string |
|
| 967 | + */ |
|
| 968 | + public function get_user_phone( $context = 'view' ) { |
|
| 969 | + return $this->get_phone( $context ); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
| 973 | - * Alias of self::get_phone(). |
|
| 974 | - * |
|
| 975 | - * @since 1.0.19 |
|
| 976 | - * @param string $context View or edit context. |
|
| 977 | - * @return string |
|
| 978 | - */ |
|
| 979 | - public function get_customer_phone( $context = 'view' ) { |
|
| 980 | - return $this->get_phone( $context ); |
|
| 973 | + * Alias of self::get_phone(). |
|
| 974 | + * |
|
| 975 | + * @since 1.0.19 |
|
| 976 | + * @param string $context View or edit context. |
|
| 977 | + * @return string |
|
| 978 | + */ |
|
| 979 | + public function get_customer_phone( $context = 'view' ) { |
|
| 980 | + return $this->get_phone( $context ); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | /** |
| 984 | - * Get the customer's email address. |
|
| 985 | - * |
|
| 986 | - * @since 1.0.19 |
|
| 987 | - * @param string $context View or edit context. |
|
| 988 | - * @return string |
|
| 989 | - */ |
|
| 990 | - public function get_email( $context = 'view' ) { |
|
| 991 | - return $this->get_prop( 'email', $context ); |
|
| 984 | + * Get the customer's email address. |
|
| 985 | + * |
|
| 986 | + * @since 1.0.19 |
|
| 987 | + * @param string $context View or edit context. |
|
| 988 | + * @return string |
|
| 989 | + */ |
|
| 990 | + public function get_email( $context = 'view' ) { |
|
| 991 | + return $this->get_prop( 'email', $context ); |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | /** |
| 995 | - * Alias of self::get_email(). |
|
| 996 | - * |
|
| 997 | - * @since 1.0.19 |
|
| 998 | - * @param string $context View or edit context. |
|
| 999 | - * @return string |
|
| 1000 | - */ |
|
| 1001 | - public function get_email_address( $context = 'view' ) { |
|
| 1002 | - return $this->get_email( $context ); |
|
| 995 | + * Alias of self::get_email(). |
|
| 996 | + * |
|
| 997 | + * @since 1.0.19 |
|
| 998 | + * @param string $context View or edit context. |
|
| 999 | + * @return string |
|
| 1000 | + */ |
|
| 1001 | + public function get_email_address( $context = 'view' ) { |
|
| 1002 | + return $this->get_email( $context ); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
| 1006 | - * Alias of self::get_email(). |
|
| 1007 | - * |
|
| 1008 | - * @since 1.0.19 |
|
| 1009 | - * @param string $context View or edit context. |
|
| 1010 | - * @return string |
|
| 1011 | - */ |
|
| 1012 | - public function get_user_email( $context = 'view' ) { |
|
| 1013 | - return $this->get_email( $context ); |
|
| 1006 | + * Alias of self::get_email(). |
|
| 1007 | + * |
|
| 1008 | + * @since 1.0.19 |
|
| 1009 | + * @param string $context View or edit context. |
|
| 1010 | + * @return string |
|
| 1011 | + */ |
|
| 1012 | + public function get_user_email( $context = 'view' ) { |
|
| 1013 | + return $this->get_email( $context ); |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | /** |
| 1017 | - * Alias of self::get_email(). |
|
| 1018 | - * |
|
| 1019 | - * @since 1.0.19 |
|
| 1020 | - * @param string $context View or edit context. |
|
| 1021 | - * @return string |
|
| 1022 | - */ |
|
| 1023 | - public function get_customer_email( $context = 'view' ) { |
|
| 1024 | - return $this->get_email( $context ); |
|
| 1017 | + * Alias of self::get_email(). |
|
| 1018 | + * |
|
| 1019 | + * @since 1.0.19 |
|
| 1020 | + * @param string $context View or edit context. |
|
| 1021 | + * @return string |
|
| 1022 | + */ |
|
| 1023 | + public function get_customer_email( $context = 'view' ) { |
|
| 1024 | + return $this->get_email( $context ); |
|
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | /** |
| 1028 | - * Get the customer's country. |
|
| 1029 | - * |
|
| 1030 | - * @since 1.0.19 |
|
| 1031 | - * @param string $context View or edit context. |
|
| 1032 | - * @return string |
|
| 1033 | - */ |
|
| 1034 | - public function get_country( $context = 'view' ) { |
|
| 1035 | - $country = $this->get_prop( 'country', $context ); |
|
| 1036 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 1028 | + * Get the customer's country. |
|
| 1029 | + * |
|
| 1030 | + * @since 1.0.19 |
|
| 1031 | + * @param string $context View or edit context. |
|
| 1032 | + * @return string |
|
| 1033 | + */ |
|
| 1034 | + public function get_country( $context = 'view' ) { |
|
| 1035 | + $country = $this->get_prop( 'country', $context ); |
|
| 1036 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | /** |
| 1040 | - * Alias of self::get_country(). |
|
| 1041 | - * |
|
| 1042 | - * @since 1.0.19 |
|
| 1043 | - * @param string $context View or edit context. |
|
| 1044 | - * @return string |
|
| 1045 | - */ |
|
| 1046 | - public function get_user_country( $context = 'view' ) { |
|
| 1047 | - return $this->get_country( $context ); |
|
| 1040 | + * Alias of self::get_country(). |
|
| 1041 | + * |
|
| 1042 | + * @since 1.0.19 |
|
| 1043 | + * @param string $context View or edit context. |
|
| 1044 | + * @return string |
|
| 1045 | + */ |
|
| 1046 | + public function get_user_country( $context = 'view' ) { |
|
| 1047 | + return $this->get_country( $context ); |
|
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | 1050 | /** |
| 1051 | - * Alias of self::get_country(). |
|
| 1052 | - * |
|
| 1053 | - * @since 1.0.19 |
|
| 1054 | - * @param string $context View or edit context. |
|
| 1055 | - * @return string |
|
| 1056 | - */ |
|
| 1057 | - public function get_customer_country( $context = 'view' ) { |
|
| 1058 | - return $this->get_country( $context ); |
|
| 1051 | + * Alias of self::get_country(). |
|
| 1052 | + * |
|
| 1053 | + * @since 1.0.19 |
|
| 1054 | + * @param string $context View or edit context. |
|
| 1055 | + * @return string |
|
| 1056 | + */ |
|
| 1057 | + public function get_customer_country( $context = 'view' ) { |
|
| 1058 | + return $this->get_country( $context ); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | /** |
| 1062 | - * Get the customer's state. |
|
| 1063 | - * |
|
| 1064 | - * @since 1.0.19 |
|
| 1065 | - * @param string $context View or edit context. |
|
| 1066 | - * @return string |
|
| 1067 | - */ |
|
| 1068 | - public function get_state( $context = 'view' ) { |
|
| 1069 | - $state = $this->get_prop( 'state', $context ); |
|
| 1070 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1062 | + * Get the customer's state. |
|
| 1063 | + * |
|
| 1064 | + * @since 1.0.19 |
|
| 1065 | + * @param string $context View or edit context. |
|
| 1066 | + * @return string |
|
| 1067 | + */ |
|
| 1068 | + public function get_state( $context = 'view' ) { |
|
| 1069 | + $state = $this->get_prop( 'state', $context ); |
|
| 1070 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | /** |
| 1074 | - * Alias of self::get_state(). |
|
| 1075 | - * |
|
| 1076 | - * @since 1.0.19 |
|
| 1077 | - * @param string $context View or edit context. |
|
| 1078 | - * @return string |
|
| 1079 | - */ |
|
| 1080 | - public function get_user_state( $context = 'view' ) { |
|
| 1081 | - return $this->get_state( $context ); |
|
| 1074 | + * Alias of self::get_state(). |
|
| 1075 | + * |
|
| 1076 | + * @since 1.0.19 |
|
| 1077 | + * @param string $context View or edit context. |
|
| 1078 | + * @return string |
|
| 1079 | + */ |
|
| 1080 | + public function get_user_state( $context = 'view' ) { |
|
| 1081 | + return $this->get_state( $context ); |
|
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | /** |
| 1085 | - * Alias of self::get_state(). |
|
| 1086 | - * |
|
| 1087 | - * @since 1.0.19 |
|
| 1088 | - * @param string $context View or edit context. |
|
| 1089 | - * @return string |
|
| 1090 | - */ |
|
| 1091 | - public function get_customer_state( $context = 'view' ) { |
|
| 1092 | - return $this->get_state( $context ); |
|
| 1085 | + * Alias of self::get_state(). |
|
| 1086 | + * |
|
| 1087 | + * @since 1.0.19 |
|
| 1088 | + * @param string $context View or edit context. |
|
| 1089 | + * @return string |
|
| 1090 | + */ |
|
| 1091 | + public function get_customer_state( $context = 'view' ) { |
|
| 1092 | + return $this->get_state( $context ); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
| 1096 | - * Get the customer's city. |
|
| 1097 | - * |
|
| 1098 | - * @since 1.0.19 |
|
| 1099 | - * @param string $context View or edit context. |
|
| 1100 | - * @return string |
|
| 1101 | - */ |
|
| 1102 | - public function get_city( $context = 'view' ) { |
|
| 1103 | - return $this->get_prop( 'city', $context ); |
|
| 1096 | + * Get the customer's city. |
|
| 1097 | + * |
|
| 1098 | + * @since 1.0.19 |
|
| 1099 | + * @param string $context View or edit context. |
|
| 1100 | + * @return string |
|
| 1101 | + */ |
|
| 1102 | + public function get_city( $context = 'view' ) { |
|
| 1103 | + return $this->get_prop( 'city', $context ); |
|
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | /** |
| 1107 | - * Alias of self::get_city(). |
|
| 1108 | - * |
|
| 1109 | - * @since 1.0.19 |
|
| 1110 | - * @param string $context View or edit context. |
|
| 1111 | - * @return string |
|
| 1112 | - */ |
|
| 1113 | - public function get_user_city( $context = 'view' ) { |
|
| 1114 | - return $this->get_city( $context ); |
|
| 1107 | + * Alias of self::get_city(). |
|
| 1108 | + * |
|
| 1109 | + * @since 1.0.19 |
|
| 1110 | + * @param string $context View or edit context. |
|
| 1111 | + * @return string |
|
| 1112 | + */ |
|
| 1113 | + public function get_user_city( $context = 'view' ) { |
|
| 1114 | + return $this->get_city( $context ); |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | /** |
| 1118 | - * Alias of self::get_city(). |
|
| 1119 | - * |
|
| 1120 | - * @since 1.0.19 |
|
| 1121 | - * @param string $context View or edit context. |
|
| 1122 | - * @return string |
|
| 1123 | - */ |
|
| 1124 | - public function get_customer_city( $context = 'view' ) { |
|
| 1125 | - return $this->get_city( $context ); |
|
| 1118 | + * Alias of self::get_city(). |
|
| 1119 | + * |
|
| 1120 | + * @since 1.0.19 |
|
| 1121 | + * @param string $context View or edit context. |
|
| 1122 | + * @return string |
|
| 1123 | + */ |
|
| 1124 | + public function get_customer_city( $context = 'view' ) { |
|
| 1125 | + return $this->get_city( $context ); |
|
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | /** |
| 1129 | - * Get the customer's zip. |
|
| 1130 | - * |
|
| 1131 | - * @since 1.0.19 |
|
| 1132 | - * @param string $context View or edit context. |
|
| 1133 | - * @return string |
|
| 1134 | - */ |
|
| 1135 | - public function get_zip( $context = 'view' ) { |
|
| 1136 | - return $this->get_prop( 'zip', $context ); |
|
| 1129 | + * Get the customer's zip. |
|
| 1130 | + * |
|
| 1131 | + * @since 1.0.19 |
|
| 1132 | + * @param string $context View or edit context. |
|
| 1133 | + * @return string |
|
| 1134 | + */ |
|
| 1135 | + public function get_zip( $context = 'view' ) { |
|
| 1136 | + return $this->get_prop( 'zip', $context ); |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | /** |
| 1140 | - * Alias of self::get_zip(). |
|
| 1141 | - * |
|
| 1142 | - * @since 1.0.19 |
|
| 1143 | - * @param string $context View or edit context. |
|
| 1144 | - * @return string |
|
| 1145 | - */ |
|
| 1146 | - public function get_user_zip( $context = 'view' ) { |
|
| 1147 | - return $this->get_zip( $context ); |
|
| 1140 | + * Alias of self::get_zip(). |
|
| 1141 | + * |
|
| 1142 | + * @since 1.0.19 |
|
| 1143 | + * @param string $context View or edit context. |
|
| 1144 | + * @return string |
|
| 1145 | + */ |
|
| 1146 | + public function get_user_zip( $context = 'view' ) { |
|
| 1147 | + return $this->get_zip( $context ); |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Alias of self::get_zip(). |
|
| 1152 | + * |
|
| 1153 | + * @since 1.0.19 |
|
| 1154 | + * @param string $context View or edit context. |
|
| 1155 | + * @return string |
|
| 1156 | + */ |
|
| 1157 | + public function get_customer_zip( $context = 'view' ) { |
|
| 1158 | + return $this->get_zip( $context ); |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + /** |
|
| 1162 | + * Get the customer's company. |
|
| 1163 | + * |
|
| 1164 | + * @since 1.0.19 |
|
| 1165 | + * @param string $context View or edit context. |
|
| 1166 | + * @return string |
|
| 1167 | + */ |
|
| 1168 | + public function get_company( $context = 'view' ) { |
|
| 1169 | + return $this->get_prop( 'company', $context ); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + /** |
|
| 1173 | + * Alias of self::get_company(). |
|
| 1174 | + * |
|
| 1175 | + * @since 1.0.19 |
|
| 1176 | + * @param string $context View or edit context. |
|
| 1177 | + * @return string |
|
| 1178 | + */ |
|
| 1179 | + public function get_user_company( $context = 'view' ) { |
|
| 1180 | + return $this->get_company( $context ); |
|
| 1181 | + } |
|
| 1182 | + |
|
| 1183 | + /** |
|
| 1184 | + * Alias of self::get_company(). |
|
| 1185 | + * |
|
| 1186 | + * @since 1.0.19 |
|
| 1187 | + * @param string $context View or edit context. |
|
| 1188 | + * @return string |
|
| 1189 | + */ |
|
| 1190 | + public function get_customer_company( $context = 'view' ) { |
|
| 1191 | + return $this->get_company( $context ); |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + /** |
|
| 1195 | + * Get the customer's company id. |
|
| 1196 | + * |
|
| 1197 | + * @since 1.0.19 |
|
| 1198 | + * @param string $context View or edit context. |
|
| 1199 | + * @return string |
|
| 1200 | + */ |
|
| 1201 | + public function get_company_id( $context = 'view' ) { |
|
| 1202 | + return $this->get_prop( 'company_id', $context ); |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + /** |
|
| 1206 | + * Get the customer's vat number. |
|
| 1207 | + * |
|
| 1208 | + * @since 1.0.19 |
|
| 1209 | + * @param string $context View or edit context. |
|
| 1210 | + * @return string |
|
| 1211 | + */ |
|
| 1212 | + public function get_vat_number( $context = 'view' ) { |
|
| 1213 | + return $this->get_prop( 'vat_number', $context ); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * Alias of self::get_vat_number(). |
|
| 1218 | + * |
|
| 1219 | + * @since 1.0.19 |
|
| 1220 | + * @param string $context View or edit context. |
|
| 1221 | + * @return string |
|
| 1222 | + */ |
|
| 1223 | + public function get_user_vat_number( $context = 'view' ) { |
|
| 1224 | + return $this->get_vat_number( $context ); |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * Alias of self::get_vat_number(). |
|
| 1229 | + * |
|
| 1230 | + * @since 1.0.19 |
|
| 1231 | + * @param string $context View or edit context. |
|
| 1232 | + * @return string |
|
| 1233 | + */ |
|
| 1234 | + public function get_customer_vat_number( $context = 'view' ) { |
|
| 1235 | + return $this->get_vat_number( $context ); |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + /** |
|
| 1239 | + * Get the customer's vat rate. |
|
| 1240 | + * |
|
| 1241 | + * @since 1.0.19 |
|
| 1242 | + * @param string $context View or edit context. |
|
| 1243 | + * @return string |
|
| 1244 | + */ |
|
| 1245 | + public function get_vat_rate( $context = 'view' ) { |
|
| 1246 | + return $this->get_prop( 'vat_rate', $context ); |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + /** |
|
| 1250 | + * Alias of self::get_vat_rate(). |
|
| 1251 | + * |
|
| 1252 | + * @since 1.0.19 |
|
| 1253 | + * @param string $context View or edit context. |
|
| 1254 | + * @return string |
|
| 1255 | + */ |
|
| 1256 | + public function get_user_vat_rate( $context = 'view' ) { |
|
| 1257 | + return $this->get_vat_rate( $context ); |
|
| 1258 | + } |
|
| 1259 | + |
|
| 1260 | + /** |
|
| 1261 | + * Alias of self::get_vat_rate(). |
|
| 1262 | + * |
|
| 1263 | + * @since 1.0.19 |
|
| 1264 | + * @param string $context View or edit context. |
|
| 1265 | + * @return string |
|
| 1266 | + */ |
|
| 1267 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1268 | + return $this->get_vat_rate( $context ); |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + /** |
|
| 1272 | + * Get the customer's address. |
|
| 1273 | + * |
|
| 1274 | + * @since 1.0.19 |
|
| 1275 | + * @param string $context View or edit context. |
|
| 1276 | + * @return string |
|
| 1277 | + */ |
|
| 1278 | + public function get_address( $context = 'view' ) { |
|
| 1279 | + return $this->get_prop( 'address', $context ); |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * Alias of self::get_address(). |
|
| 1284 | + * |
|
| 1285 | + * @since 1.0.19 |
|
| 1286 | + * @param string $context View or edit context. |
|
| 1287 | + * @return string |
|
| 1288 | + */ |
|
| 1289 | + public function get_user_address( $context = 'view' ) { |
|
| 1290 | + return $this->get_address( $context ); |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + /** |
|
| 1294 | + * Alias of self::get_address(). |
|
| 1295 | + * |
|
| 1296 | + * @since 1.0.19 |
|
| 1297 | + * @param string $context View or edit context. |
|
| 1298 | + * @return string |
|
| 1299 | + */ |
|
| 1300 | + public function get_customer_address( $context = 'view' ) { |
|
| 1301 | + return $this->get_address( $context ); |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + /** |
|
| 1305 | + * Get whether the customer has viewed the invoice or not. |
|
| 1306 | + * |
|
| 1307 | + * @since 1.0.19 |
|
| 1308 | + * @param string $context View or edit context. |
|
| 1309 | + * @return bool |
|
| 1310 | + */ |
|
| 1311 | + public function get_is_viewed( $context = 'view' ) { |
|
| 1312 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + /** |
|
| 1316 | + * Get other recipients for invoice communications. |
|
| 1317 | + * |
|
| 1318 | + * @since 1.0.19 |
|
| 1319 | + * @param string $context View or edit context. |
|
| 1320 | + * @return bool |
|
| 1321 | + */ |
|
| 1322 | + public function get_email_cc( $context = 'view' ) { |
|
| 1323 | + return $this->get_prop( 'email_cc', $context ); |
|
| 1148 | 1324 | } |
| 1149 | 1325 | |
| 1150 | 1326 | /** |
| 1151 | - * Alias of self::get_zip(). |
|
| 1152 | - * |
|
| 1153 | - * @since 1.0.19 |
|
| 1154 | - * @param string $context View or edit context. |
|
| 1155 | - * @return string |
|
| 1156 | - */ |
|
| 1157 | - public function get_customer_zip( $context = 'view' ) { |
|
| 1158 | - return $this->get_zip( $context ); |
|
| 1327 | + * Get invoice template. |
|
| 1328 | + * |
|
| 1329 | + * @since 1.0.19 |
|
| 1330 | + * @param string $context View or edit context. |
|
| 1331 | + * @return bool |
|
| 1332 | + */ |
|
| 1333 | + public function get_template( $context = 'view' ) { |
|
| 1334 | + return $this->get_prop( 'template', $context ); |
|
| 1159 | 1335 | } |
| 1160 | 1336 | |
| 1161 | 1337 | /** |
| 1162 | - * Get the customer's company. |
|
| 1163 | - * |
|
| 1164 | - * @since 1.0.19 |
|
| 1165 | - * @param string $context View or edit context. |
|
| 1166 | - * @return string |
|
| 1167 | - */ |
|
| 1168 | - public function get_company( $context = 'view' ) { |
|
| 1169 | - return $this->get_prop( 'company', $context ); |
|
| 1338 | + * Get invoice source. |
|
| 1339 | + * |
|
| 1340 | + * @since 1.0.19 |
|
| 1341 | + * @param string $context View or edit context. |
|
| 1342 | + * @return bool |
|
| 1343 | + */ |
|
| 1344 | + public function get_created_via( $context = 'view' ) { |
|
| 1345 | + return $this->get_prop( 'created_via', $context ); |
|
| 1170 | 1346 | } |
| 1171 | 1347 | |
| 1172 | 1348 | /** |
| 1173 | - * Alias of self::get_company(). |
|
| 1174 | - * |
|
| 1175 | - * @since 1.0.19 |
|
| 1176 | - * @param string $context View or edit context. |
|
| 1177 | - * @return string |
|
| 1178 | - */ |
|
| 1179 | - public function get_user_company( $context = 'view' ) { |
|
| 1180 | - return $this->get_company( $context ); |
|
| 1349 | + * Get whether the customer has confirmed their address. |
|
| 1350 | + * |
|
| 1351 | + * @since 1.0.19 |
|
| 1352 | + * @param string $context View or edit context. |
|
| 1353 | + * @return bool |
|
| 1354 | + */ |
|
| 1355 | + public function get_address_confirmed( $context = 'view' ) { |
|
| 1356 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1181 | 1357 | } |
| 1182 | 1358 | |
| 1183 | 1359 | /** |
| 1184 | - * Alias of self::get_company(). |
|
| 1185 | - * |
|
| 1186 | - * @since 1.0.19 |
|
| 1187 | - * @param string $context View or edit context. |
|
| 1188 | - * @return string |
|
| 1189 | - */ |
|
| 1190 | - public function get_customer_company( $context = 'view' ) { |
|
| 1191 | - return $this->get_company( $context ); |
|
| 1360 | + * Alias of self::get_address_confirmed(). |
|
| 1361 | + * |
|
| 1362 | + * @since 1.0.19 |
|
| 1363 | + * @param string $context View or edit context. |
|
| 1364 | + * @return bool |
|
| 1365 | + */ |
|
| 1366 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1367 | + return $this->get_address_confirmed( $context ); |
|
| 1192 | 1368 | } |
| 1193 | 1369 | |
| 1194 | - /** |
|
| 1195 | - * Get the customer's company id. |
|
| 1196 | - * |
|
| 1197 | - * @since 1.0.19 |
|
| 1198 | - * @param string $context View or edit context. |
|
| 1199 | - * @return string |
|
| 1200 | - */ |
|
| 1201 | - public function get_company_id( $context = 'view' ) { |
|
| 1202 | - return $this->get_prop( 'company_id', $context ); |
|
| 1370 | + /** |
|
| 1371 | + * Alias of self::get_address(). |
|
| 1372 | + * |
|
| 1373 | + * @since 1.0.19 |
|
| 1374 | + * @param string $context View or edit context. |
|
| 1375 | + * @return bool |
|
| 1376 | + */ |
|
| 1377 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1378 | + return $this->get_address_confirmed( $context ); |
|
| 1203 | 1379 | } |
| 1204 | 1380 | |
| 1205 | 1381 | /** |
| 1206 | - * Get the customer's vat number. |
|
| 1207 | - * |
|
| 1208 | - * @since 1.0.19 |
|
| 1209 | - * @param string $context View or edit context. |
|
| 1210 | - * @return string |
|
| 1211 | - */ |
|
| 1212 | - public function get_vat_number( $context = 'view' ) { |
|
| 1213 | - return $this->get_prop( 'vat_number', $context ); |
|
| 1382 | + * Get the shipping address. |
|
| 1383 | + * |
|
| 1384 | + * @since 1.0.19 |
|
| 1385 | + * @return array|false |
|
| 1386 | + */ |
|
| 1387 | + public function get_shipping_address() { |
|
| 1388 | + |
|
| 1389 | + $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
| 1390 | + return is_array( $shipping_address ) ? $shipping_address : false; |
|
| 1214 | 1391 | } |
| 1215 | 1392 | |
| 1216 | 1393 | /** |
| 1217 | - * Alias of self::get_vat_number(). |
|
| 1218 | - * |
|
| 1219 | - * @since 1.0.19 |
|
| 1220 | - * @param string $context View or edit context. |
|
| 1221 | - * @return string |
|
| 1222 | - */ |
|
| 1223 | - public function get_user_vat_number( $context = 'view' ) { |
|
| 1224 | - return $this->get_vat_number( $context ); |
|
| 1394 | + * Check if the invoice has a shipping address. |
|
| 1395 | + */ |
|
| 1396 | + public function has_shipping_address() { |
|
| 1397 | + return false !== $this->get_shipping_address(); |
|
| 1225 | 1398 | } |
| 1226 | 1399 | |
| 1227 | 1400 | /** |
| 1228 | - * Alias of self::get_vat_number(). |
|
| 1229 | - * |
|
| 1230 | - * @since 1.0.19 |
|
| 1231 | - * @param string $context View or edit context. |
|
| 1232 | - * @return string |
|
| 1233 | - */ |
|
| 1234 | - public function get_customer_vat_number( $context = 'view' ) { |
|
| 1235 | - return $this->get_vat_number( $context ); |
|
| 1401 | + * Get the shipping amount. |
|
| 1402 | + * |
|
| 1403 | + * @since 1.0.19 |
|
| 1404 | + * @param string $context View or edit context. |
|
| 1405 | + * @return float |
|
| 1406 | + */ |
|
| 1407 | + public function get_shipping( $context = 'view' ) { |
|
| 1408 | + |
|
| 1409 | + if ( $context = 'view' ) { |
|
| 1410 | + return floatval( $this->get_prop( 'shipping', $context ) ); |
|
| 1411 | + } |
|
| 1412 | + |
|
| 1413 | + return $this->get_prop( 'shipping', $context ); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + public function has_shipping() { |
|
| 1417 | + return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && $this->get_prop( 'shipping', 'edit' ); |
|
| 1236 | 1418 | } |
| 1237 | 1419 | |
| 1238 | - /** |
|
| 1239 | - * Get the customer's vat rate. |
|
| 1240 | - * |
|
| 1241 | - * @since 1.0.19 |
|
| 1242 | - * @param string $context View or edit context. |
|
| 1243 | - * @return string |
|
| 1244 | - */ |
|
| 1245 | - public function get_vat_rate( $context = 'view' ) { |
|
| 1246 | - return $this->get_prop( 'vat_rate', $context ); |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - /** |
|
| 1250 | - * Alias of self::get_vat_rate(). |
|
| 1251 | - * |
|
| 1252 | - * @since 1.0.19 |
|
| 1253 | - * @param string $context View or edit context. |
|
| 1254 | - * @return string |
|
| 1255 | - */ |
|
| 1256 | - public function get_user_vat_rate( $context = 'view' ) { |
|
| 1257 | - return $this->get_vat_rate( $context ); |
|
| 1258 | - } |
|
| 1259 | - |
|
| 1260 | - /** |
|
| 1261 | - * Alias of self::get_vat_rate(). |
|
| 1262 | - * |
|
| 1263 | - * @since 1.0.19 |
|
| 1264 | - * @param string $context View or edit context. |
|
| 1265 | - * @return string |
|
| 1266 | - */ |
|
| 1267 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1268 | - return $this->get_vat_rate( $context ); |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - /** |
|
| 1272 | - * Get the customer's address. |
|
| 1273 | - * |
|
| 1274 | - * @since 1.0.19 |
|
| 1275 | - * @param string $context View or edit context. |
|
| 1276 | - * @return string |
|
| 1277 | - */ |
|
| 1278 | - public function get_address( $context = 'view' ) { |
|
| 1279 | - return $this->get_prop( 'address', $context ); |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * Alias of self::get_address(). |
|
| 1284 | - * |
|
| 1285 | - * @since 1.0.19 |
|
| 1286 | - * @param string $context View or edit context. |
|
| 1287 | - * @return string |
|
| 1288 | - */ |
|
| 1289 | - public function get_user_address( $context = 'view' ) { |
|
| 1290 | - return $this->get_address( $context ); |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - /** |
|
| 1294 | - * Alias of self::get_address(). |
|
| 1295 | - * |
|
| 1296 | - * @since 1.0.19 |
|
| 1297 | - * @param string $context View or edit context. |
|
| 1298 | - * @return string |
|
| 1299 | - */ |
|
| 1300 | - public function get_customer_address( $context = 'view' ) { |
|
| 1301 | - return $this->get_address( $context ); |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - /** |
|
| 1305 | - * Get whether the customer has viewed the invoice or not. |
|
| 1306 | - * |
|
| 1307 | - * @since 1.0.19 |
|
| 1308 | - * @param string $context View or edit context. |
|
| 1309 | - * @return bool |
|
| 1310 | - */ |
|
| 1311 | - public function get_is_viewed( $context = 'view' ) { |
|
| 1312 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - /** |
|
| 1316 | - * Get other recipients for invoice communications. |
|
| 1317 | - * |
|
| 1318 | - * @since 1.0.19 |
|
| 1319 | - * @param string $context View or edit context. |
|
| 1320 | - * @return bool |
|
| 1321 | - */ |
|
| 1322 | - public function get_email_cc( $context = 'view' ) { |
|
| 1323 | - return $this->get_prop( 'email_cc', $context ); |
|
| 1324 | - } |
|
| 1325 | - |
|
| 1326 | - /** |
|
| 1327 | - * Get invoice template. |
|
| 1328 | - * |
|
| 1329 | - * @since 1.0.19 |
|
| 1330 | - * @param string $context View or edit context. |
|
| 1331 | - * @return bool |
|
| 1332 | - */ |
|
| 1333 | - public function get_template( $context = 'view' ) { |
|
| 1334 | - return $this->get_prop( 'template', $context ); |
|
| 1335 | - } |
|
| 1336 | - |
|
| 1337 | - /** |
|
| 1338 | - * Get invoice source. |
|
| 1339 | - * |
|
| 1340 | - * @since 1.0.19 |
|
| 1341 | - * @param string $context View or edit context. |
|
| 1342 | - * @return bool |
|
| 1343 | - */ |
|
| 1344 | - public function get_created_via( $context = 'view' ) { |
|
| 1345 | - return $this->get_prop( 'created_via', $context ); |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - /** |
|
| 1349 | - * Get whether the customer has confirmed their address. |
|
| 1350 | - * |
|
| 1351 | - * @since 1.0.19 |
|
| 1352 | - * @param string $context View or edit context. |
|
| 1353 | - * @return bool |
|
| 1354 | - */ |
|
| 1355 | - public function get_address_confirmed( $context = 'view' ) { |
|
| 1356 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1357 | - } |
|
| 1358 | - |
|
| 1359 | - /** |
|
| 1360 | - * Alias of self::get_address_confirmed(). |
|
| 1361 | - * |
|
| 1362 | - * @since 1.0.19 |
|
| 1363 | - * @param string $context View or edit context. |
|
| 1364 | - * @return bool |
|
| 1365 | - */ |
|
| 1366 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1367 | - return $this->get_address_confirmed( $context ); |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - /** |
|
| 1371 | - * Alias of self::get_address(). |
|
| 1372 | - * |
|
| 1373 | - * @since 1.0.19 |
|
| 1374 | - * @param string $context View or edit context. |
|
| 1375 | - * @return bool |
|
| 1376 | - */ |
|
| 1377 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1378 | - return $this->get_address_confirmed( $context ); |
|
| 1379 | - } |
|
| 1380 | - |
|
| 1381 | - /** |
|
| 1382 | - * Get the shipping address. |
|
| 1383 | - * |
|
| 1384 | - * @since 1.0.19 |
|
| 1385 | - * @return array|false |
|
| 1386 | - */ |
|
| 1387 | - public function get_shipping_address() { |
|
| 1388 | - |
|
| 1389 | - $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
| 1390 | - return is_array( $shipping_address ) ? $shipping_address : false; |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - /** |
|
| 1394 | - * Check if the invoice has a shipping address. |
|
| 1395 | - */ |
|
| 1396 | - public function has_shipping_address() { |
|
| 1397 | - return false !== $this->get_shipping_address(); |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - /** |
|
| 1401 | - * Get the shipping amount. |
|
| 1402 | - * |
|
| 1403 | - * @since 1.0.19 |
|
| 1404 | - * @param string $context View or edit context. |
|
| 1405 | - * @return float |
|
| 1406 | - */ |
|
| 1407 | - public function get_shipping( $context = 'view' ) { |
|
| 1408 | - |
|
| 1409 | - if ( $context = 'view' ) { |
|
| 1410 | - return floatval( $this->get_prop( 'shipping', $context ) ); |
|
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - return $this->get_prop( 'shipping', $context ); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - public function has_shipping() { |
|
| 1417 | - return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && $this->get_prop( 'shipping', 'edit' ); |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - /** |
|
| 1421 | - * Get the invoice subtotal. |
|
| 1422 | - * |
|
| 1423 | - * @since 1.0.19 |
|
| 1424 | - * @param string $context View or edit context. |
|
| 1425 | - * @return float |
|
| 1426 | - */ |
|
| 1427 | - public function get_subtotal( $context = 'view' ) { |
|
| 1420 | + /** |
|
| 1421 | + * Get the invoice subtotal. |
|
| 1422 | + * |
|
| 1423 | + * @since 1.0.19 |
|
| 1424 | + * @param string $context View or edit context. |
|
| 1425 | + * @return float |
|
| 1426 | + */ |
|
| 1427 | + public function get_subtotal( $context = 'view' ) { |
|
| 1428 | 1428 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
| 1429 | 1429 | |
| 1430 | 1430 | // Backwards compatibility. |
@@ -1436,197 +1436,197 @@ discard block |
||
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | /** |
| 1439 | - * Get the invoice discount total. |
|
| 1440 | - * |
|
| 1441 | - * @since 1.0.19 |
|
| 1442 | - * @param string $context View or edit context. |
|
| 1443 | - * @return float |
|
| 1444 | - */ |
|
| 1445 | - public function get_total_discount( $context = 'view' ) { |
|
| 1446 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
| 1439 | + * Get the invoice discount total. |
|
| 1440 | + * |
|
| 1441 | + * @since 1.0.19 |
|
| 1442 | + * @param string $context View or edit context. |
|
| 1443 | + * @return float |
|
| 1444 | + */ |
|
| 1445 | + public function get_total_discount( $context = 'view' ) { |
|
| 1446 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | /** |
| 1450 | - * Get the invoice tax total. |
|
| 1451 | - * |
|
| 1452 | - * @since 1.0.19 |
|
| 1453 | - * @param string $context View or edit context. |
|
| 1454 | - * @return float |
|
| 1455 | - */ |
|
| 1456 | - public function get_total_tax( $context = 'view' ) { |
|
| 1457 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
| 1458 | - } |
|
| 1450 | + * Get the invoice tax total. |
|
| 1451 | + * |
|
| 1452 | + * @since 1.0.19 |
|
| 1453 | + * @param string $context View or edit context. |
|
| 1454 | + * @return float |
|
| 1455 | + */ |
|
| 1456 | + public function get_total_tax( $context = 'view' ) { |
|
| 1457 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
| 1458 | + } |
|
| 1459 | 1459 | |
| 1460 | - /** |
|
| 1461 | - * @deprecated |
|
| 1462 | - */ |
|
| 1463 | - public function get_final_tax( $currency = false ) { |
|
| 1464 | - $tax = $this->get_total_tax(); |
|
| 1460 | + /** |
|
| 1461 | + * @deprecated |
|
| 1462 | + */ |
|
| 1463 | + public function get_final_tax( $currency = false ) { |
|
| 1464 | + $tax = $this->get_total_tax(); |
|
| 1465 | 1465 | |
| 1466 | 1466 | if ( $currency ) { |
| 1467 | - return wpinv_price( $tax, $this->get_currency() ); |
|
| 1467 | + return wpinv_price( $tax, $this->get_currency() ); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | 1470 | return $tax; |
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | 1473 | /** |
| 1474 | - * Get the invoice fees total. |
|
| 1475 | - * |
|
| 1476 | - * @since 1.0.19 |
|
| 1477 | - * @param string $context View or edit context. |
|
| 1478 | - * @return float |
|
| 1479 | - */ |
|
| 1480 | - public function get_total_fees( $context = 'view' ) { |
|
| 1481 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
| 1474 | + * Get the invoice fees total. |
|
| 1475 | + * |
|
| 1476 | + * @since 1.0.19 |
|
| 1477 | + * @param string $context View or edit context. |
|
| 1478 | + * @return float |
|
| 1479 | + */ |
|
| 1480 | + public function get_total_fees( $context = 'view' ) { |
|
| 1481 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
| 1482 | 1482 | } |
| 1483 | 1483 | |
| 1484 | 1484 | /** |
| 1485 | - * Alias for self::get_total_fees(). |
|
| 1486 | - * |
|
| 1487 | - * @since 1.0.19 |
|
| 1488 | - * @param string $context View or edit context. |
|
| 1489 | - * @return float |
|
| 1490 | - */ |
|
| 1491 | - public function get_fees_total( $context = 'view' ) { |
|
| 1492 | - return $this->get_total_fees( $context ); |
|
| 1485 | + * Alias for self::get_total_fees(). |
|
| 1486 | + * |
|
| 1487 | + * @since 1.0.19 |
|
| 1488 | + * @param string $context View or edit context. |
|
| 1489 | + * @return float |
|
| 1490 | + */ |
|
| 1491 | + public function get_fees_total( $context = 'view' ) { |
|
| 1492 | + return $this->get_total_fees( $context ); |
|
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | 1495 | /** |
| 1496 | - * Get the invoice total. |
|
| 1497 | - * |
|
| 1498 | - * @since 1.0.19 |
|
| 1496 | + * Get the invoice total. |
|
| 1497 | + * |
|
| 1498 | + * @since 1.0.19 |
|
| 1499 | 1499 | * @return float |
| 1500 | - */ |
|
| 1501 | - public function get_total( $context = 'view' ) { |
|
| 1502 | - $total = $this->get_prop( 'total', $context ); |
|
| 1503 | - |
|
| 1504 | - if ( $this->has_shipping() && $context == 'view' ) { |
|
| 1505 | - $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
| 1506 | - } |
|
| 1507 | - |
|
| 1508 | - return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - /** |
|
| 1512 | - * Retrieves the non-recurring total of items. |
|
| 1513 | - * |
|
| 1514 | - * @since 2.3.0 |
|
| 1515 | - * @return float |
|
| 1516 | - */ |
|
| 1517 | - public function get_non_recurring_total() { |
|
| 1518 | - |
|
| 1519 | - $subtotal = 0; |
|
| 1520 | - foreach ( $this->get_items() as $item ) { |
|
| 1521 | - if ( ! $item->is_recurring() ) { |
|
| 1522 | - $subtotal += $item->get_sub_total(); |
|
| 1523 | - } |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - foreach ( $this->get_fees() as $fee ) { |
|
| 1527 | - if ( empty( $fee['recurring_fee'] ) ) { |
|
| 1528 | - $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 1529 | - } |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
| 1500 | + */ |
|
| 1501 | + public function get_total( $context = 'view' ) { |
|
| 1502 | + $total = $this->get_prop( 'total', $context ); |
|
| 1503 | + |
|
| 1504 | + if ( $this->has_shipping() && $context == 'view' ) { |
|
| 1505 | + $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
| 1506 | + } |
|
| 1507 | + |
|
| 1508 | + return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + /** |
|
| 1512 | + * Retrieves the non-recurring total of items. |
|
| 1513 | + * |
|
| 1514 | + * @since 2.3.0 |
|
| 1515 | + * @return float |
|
| 1516 | + */ |
|
| 1517 | + public function get_non_recurring_total() { |
|
| 1518 | + |
|
| 1519 | + $subtotal = 0; |
|
| 1520 | + foreach ( $this->get_items() as $item ) { |
|
| 1521 | + if ( ! $item->is_recurring() ) { |
|
| 1522 | + $subtotal += $item->get_sub_total(); |
|
| 1523 | + } |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + foreach ( $this->get_fees() as $fee ) { |
|
| 1527 | + if ( empty( $fee['recurring_fee'] ) ) { |
|
| 1528 | + $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 1529 | + } |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
| 1533 | 1533 | return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this ); |
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | - /** |
|
| 1537 | - * Get the invoice totals. |
|
| 1538 | - * |
|
| 1539 | - * @since 1.0.19 |
|
| 1536 | + /** |
|
| 1537 | + * Get the invoice totals. |
|
| 1538 | + * |
|
| 1539 | + * @since 1.0.19 |
|
| 1540 | 1540 | * @return array |
| 1541 | - */ |
|
| 1542 | - public function get_totals() { |
|
| 1543 | - return $this->totals; |
|
| 1541 | + */ |
|
| 1542 | + public function get_totals() { |
|
| 1543 | + return $this->totals; |
|
| 1544 | 1544 | } |
| 1545 | 1545 | |
| 1546 | 1546 | /** |
| 1547 | - * Get the initial invoice total. |
|
| 1548 | - * |
|
| 1549 | - * @since 1.0.19 |
|
| 1547 | + * Get the initial invoice total. |
|
| 1548 | + * |
|
| 1549 | + * @since 1.0.19 |
|
| 1550 | 1550 | * @param string $context View or edit context. |
| 1551 | 1551 | * @return float |
| 1552 | - */ |
|
| 1552 | + */ |
|
| 1553 | 1553 | public function get_initial_total() { |
| 1554 | 1554 | |
| 1555 | - if ( empty( $this->totals ) ) { |
|
| 1556 | - $this->recalculate_total(); |
|
| 1557 | - } |
|
| 1555 | + if ( empty( $this->totals ) ) { |
|
| 1556 | + $this->recalculate_total(); |
|
| 1557 | + } |
|
| 1558 | 1558 | |
| 1559 | - $tax = $this->totals['tax']['initial']; |
|
| 1560 | - $fee = $this->totals['fee']['initial']; |
|
| 1561 | - $discount = $this->totals['discount']['initial']; |
|
| 1562 | - $subtotal = $this->totals['subtotal']['initial']; |
|
| 1563 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1559 | + $tax = $this->totals['tax']['initial']; |
|
| 1560 | + $fee = $this->totals['fee']['initial']; |
|
| 1561 | + $discount = $this->totals['discount']['initial']; |
|
| 1562 | + $subtotal = $this->totals['subtotal']['initial']; |
|
| 1563 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1564 | 1564 | |
| 1565 | - if ( 0 > $total ) { |
|
| 1566 | - $total = 0; |
|
| 1567 | - } |
|
| 1565 | + if ( 0 > $total ) { |
|
| 1566 | + $total = 0; |
|
| 1567 | + } |
|
| 1568 | 1568 | |
| 1569 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1569 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1570 | 1570 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
| 1571 | - } |
|
| 1571 | + } |
|
| 1572 | 1572 | |
| 1573 | - /** |
|
| 1574 | - * Get the recurring invoice total. |
|
| 1575 | - * |
|
| 1576 | - * @since 1.0.19 |
|
| 1573 | + /** |
|
| 1574 | + * Get the recurring invoice total. |
|
| 1575 | + * |
|
| 1576 | + * @since 1.0.19 |
|
| 1577 | 1577 | * @param string $context View or edit context. |
| 1578 | 1578 | * @return float |
| 1579 | - */ |
|
| 1579 | + */ |
|
| 1580 | 1580 | public function get_recurring_total() { |
| 1581 | 1581 | |
| 1582 | - if ( empty( $this->totals ) ) { |
|
| 1583 | - $this->recalculate_total(); |
|
| 1584 | - } |
|
| 1582 | + if ( empty( $this->totals ) ) { |
|
| 1583 | + $this->recalculate_total(); |
|
| 1584 | + } |
|
| 1585 | 1585 | |
| 1586 | - $tax = $this->totals['tax']['recurring']; |
|
| 1587 | - $fee = $this->totals['fee']['recurring']; |
|
| 1588 | - $discount = $this->totals['discount']['recurring']; |
|
| 1589 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1590 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1586 | + $tax = $this->totals['tax']['recurring']; |
|
| 1587 | + $fee = $this->totals['fee']['recurring']; |
|
| 1588 | + $discount = $this->totals['discount']['recurring']; |
|
| 1589 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1590 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1591 | 1591 | |
| 1592 | - if ( 0 > $total ) { |
|
| 1593 | - $total = 0; |
|
| 1594 | - } |
|
| 1592 | + if ( 0 > $total ) { |
|
| 1593 | + $total = 0; |
|
| 1594 | + } |
|
| 1595 | 1595 | |
| 1596 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1596 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1597 | 1597 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
| 1598 | - } |
|
| 1598 | + } |
|
| 1599 | 1599 | |
| 1600 | - /** |
|
| 1601 | - * Returns recurring payment details. |
|
| 1602 | - * |
|
| 1603 | - * @since 1.0.19 |
|
| 1600 | + /** |
|
| 1601 | + * Returns recurring payment details. |
|
| 1602 | + * |
|
| 1603 | + * @since 1.0.19 |
|
| 1604 | 1604 | * @param string $field Optionally provide a field to return. |
| 1605 | - * @param string $currency Whether to include the currency. |
|
| 1605 | + * @param string $currency Whether to include the currency. |
|
| 1606 | 1606 | * @return float|string |
| 1607 | - */ |
|
| 1607 | + */ |
|
| 1608 | 1608 | public function get_recurring_details( $field = '', $currency = false ) { |
| 1609 | 1609 | |
| 1610 | - // Maybe recalculate totals. |
|
| 1611 | - if ( empty( $this->totals ) ) { |
|
| 1612 | - $this->recalculate_total(); |
|
| 1613 | - } |
|
| 1610 | + // Maybe recalculate totals. |
|
| 1611 | + if ( empty( $this->totals ) ) { |
|
| 1612 | + $this->recalculate_total(); |
|
| 1613 | + } |
|
| 1614 | 1614 | |
| 1615 | - // Prepare recurring totals. |
|
| 1615 | + // Prepare recurring totals. |
|
| 1616 | 1616 | $data = apply_filters( |
| 1617 | - 'wpinv_get_invoice_recurring_details', |
|
| 1618 | - array( |
|
| 1619 | - 'cart_details' => $this->get_cart_details(), |
|
| 1620 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1621 | - 'discount' => $this->totals['discount']['recurring'], |
|
| 1622 | - 'tax' => $this->totals['tax']['recurring'], |
|
| 1623 | - 'fee' => $this->totals['fee']['recurring'], |
|
| 1624 | - 'total' => $this->get_recurring_total(), |
|
| 1625 | - ), |
|
| 1626 | - $this, |
|
| 1627 | - $field, |
|
| 1628 | - $currency |
|
| 1629 | - ); |
|
| 1617 | + 'wpinv_get_invoice_recurring_details', |
|
| 1618 | + array( |
|
| 1619 | + 'cart_details' => $this->get_cart_details(), |
|
| 1620 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1621 | + 'discount' => $this->totals['discount']['recurring'], |
|
| 1622 | + 'tax' => $this->totals['tax']['recurring'], |
|
| 1623 | + 'fee' => $this->totals['fee']['recurring'], |
|
| 1624 | + 'total' => $this->get_recurring_total(), |
|
| 1625 | + ), |
|
| 1626 | + $this, |
|
| 1627 | + $field, |
|
| 1628 | + $currency |
|
| 1629 | + ); |
|
| 1630 | 1630 | |
| 1631 | 1631 | if ( isset( $data[ $field ] ) ) { |
| 1632 | 1632 | return ( $currency ? wpinv_price( $data[ $field ], $this->get_currency() ) : $data[ $field ] ); |
@@ -1636,166 +1636,166 @@ discard block |
||
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | 1638 | /** |
| 1639 | - * Get the invoice fees. |
|
| 1640 | - * |
|
| 1641 | - * @since 1.0.19 |
|
| 1642 | - * @param string $context View or edit context. |
|
| 1643 | - * @return array |
|
| 1644 | - */ |
|
| 1645 | - public function get_fees( $context = 'view' ) { |
|
| 1646 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1639 | + * Get the invoice fees. |
|
| 1640 | + * |
|
| 1641 | + * @since 1.0.19 |
|
| 1642 | + * @param string $context View or edit context. |
|
| 1643 | + * @return array |
|
| 1644 | + */ |
|
| 1645 | + public function get_fees( $context = 'view' ) { |
|
| 1646 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | 1649 | /** |
| 1650 | - * Get the invoice discounts. |
|
| 1651 | - * |
|
| 1652 | - * @since 1.0.19 |
|
| 1653 | - * @param string $context View or edit context. |
|
| 1654 | - * @return array |
|
| 1655 | - */ |
|
| 1656 | - public function get_discounts( $context = 'view' ) { |
|
| 1657 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1650 | + * Get the invoice discounts. |
|
| 1651 | + * |
|
| 1652 | + * @since 1.0.19 |
|
| 1653 | + * @param string $context View or edit context. |
|
| 1654 | + * @return array |
|
| 1655 | + */ |
|
| 1656 | + public function get_discounts( $context = 'view' ) { |
|
| 1657 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | 1660 | /** |
| 1661 | - * Get the invoice taxes. |
|
| 1662 | - * |
|
| 1663 | - * @since 1.0.19 |
|
| 1664 | - * @param string $context View or edit context. |
|
| 1665 | - * @return array |
|
| 1666 | - */ |
|
| 1667 | - public function get_taxes( $context = 'view' ) { |
|
| 1668 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1661 | + * Get the invoice taxes. |
|
| 1662 | + * |
|
| 1663 | + * @since 1.0.19 |
|
| 1664 | + * @param string $context View or edit context. |
|
| 1665 | + * @return array |
|
| 1666 | + */ |
|
| 1667 | + public function get_taxes( $context = 'view' ) { |
|
| 1668 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | /** |
| 1672 | - * Get the invoice items. |
|
| 1673 | - * |
|
| 1674 | - * @since 1.0.19 |
|
| 1675 | - * @param string $context View or edit context. |
|
| 1676 | - * @return GetPaid_Form_Item[] |
|
| 1677 | - */ |
|
| 1678 | - public function get_items( $context = 'view' ) { |
|
| 1672 | + * Get the invoice items. |
|
| 1673 | + * |
|
| 1674 | + * @since 1.0.19 |
|
| 1675 | + * @param string $context View or edit context. |
|
| 1676 | + * @return GetPaid_Form_Item[] |
|
| 1677 | + */ |
|
| 1678 | + public function get_items( $context = 'view' ) { |
|
| 1679 | 1679 | return $this->get_prop( 'items', $context ); |
| 1680 | - } |
|
| 1680 | + } |
|
| 1681 | 1681 | |
| 1682 | - /** |
|
| 1683 | - * Get the invoice item ids. |
|
| 1684 | - * |
|
| 1685 | - * @since 1.0.19 |
|
| 1686 | - * @return string |
|
| 1687 | - */ |
|
| 1688 | - public function get_item_ids() { |
|
| 1689 | - return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
| 1682 | + /** |
|
| 1683 | + * Get the invoice item ids. |
|
| 1684 | + * |
|
| 1685 | + * @since 1.0.19 |
|
| 1686 | + * @return string |
|
| 1687 | + */ |
|
| 1688 | + public function get_item_ids() { |
|
| 1689 | + return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | 1692 | /** |
| 1693 | - * Get the invoice's payment form. |
|
| 1694 | - * |
|
| 1695 | - * @since 1.0.19 |
|
| 1696 | - * @param string $context View or edit context. |
|
| 1697 | - * @return int |
|
| 1698 | - */ |
|
| 1699 | - public function get_payment_form( $context = 'view' ) { |
|
| 1700 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1693 | + * Get the invoice's payment form. |
|
| 1694 | + * |
|
| 1695 | + * @since 1.0.19 |
|
| 1696 | + * @param string $context View or edit context. |
|
| 1697 | + * @return int |
|
| 1698 | + */ |
|
| 1699 | + public function get_payment_form( $context = 'view' ) { |
|
| 1700 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | 1703 | /** |
| 1704 | - * Get the invoice's submission id. |
|
| 1705 | - * |
|
| 1706 | - * @since 1.0.19 |
|
| 1707 | - * @param string $context View or edit context. |
|
| 1708 | - * @return string |
|
| 1709 | - */ |
|
| 1710 | - public function get_submission_id( $context = 'view' ) { |
|
| 1711 | - return $this->get_prop( 'submission_id', $context ); |
|
| 1704 | + * Get the invoice's submission id. |
|
| 1705 | + * |
|
| 1706 | + * @since 1.0.19 |
|
| 1707 | + * @param string $context View or edit context. |
|
| 1708 | + * @return string |
|
| 1709 | + */ |
|
| 1710 | + public function get_submission_id( $context = 'view' ) { |
|
| 1711 | + return $this->get_prop( 'submission_id', $context ); |
|
| 1712 | 1712 | } |
| 1713 | 1713 | |
| 1714 | 1714 | /** |
| 1715 | - * Get the invoice's discount code. |
|
| 1716 | - * |
|
| 1717 | - * @since 1.0.19 |
|
| 1718 | - * @param string $context View or edit context. |
|
| 1719 | - * @return string |
|
| 1720 | - */ |
|
| 1721 | - public function get_discount_code( $context = 'view' ) { |
|
| 1722 | - return $this->get_prop( 'discount_code', $context ); |
|
| 1715 | + * Get the invoice's discount code. |
|
| 1716 | + * |
|
| 1717 | + * @since 1.0.19 |
|
| 1718 | + * @param string $context View or edit context. |
|
| 1719 | + * @return string |
|
| 1720 | + */ |
|
| 1721 | + public function get_discount_code( $context = 'view' ) { |
|
| 1722 | + return $this->get_prop( 'discount_code', $context ); |
|
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | 1725 | /** |
| 1726 | - * Get the invoice's gateway. |
|
| 1727 | - * |
|
| 1728 | - * @since 1.0.19 |
|
| 1729 | - * @param string $context View or edit context. |
|
| 1730 | - * @return string |
|
| 1731 | - */ |
|
| 1732 | - public function get_gateway( $context = 'view' ) { |
|
| 1733 | - return $this->get_prop( 'gateway', $context ); |
|
| 1726 | + * Get the invoice's gateway. |
|
| 1727 | + * |
|
| 1728 | + * @since 1.0.19 |
|
| 1729 | + * @param string $context View or edit context. |
|
| 1730 | + * @return string |
|
| 1731 | + */ |
|
| 1732 | + public function get_gateway( $context = 'view' ) { |
|
| 1733 | + return $this->get_prop( 'gateway', $context ); |
|
| 1734 | 1734 | } |
| 1735 | 1735 | |
| 1736 | 1736 | /** |
| 1737 | - * Get the invoice's gateway display title. |
|
| 1738 | - * |
|
| 1739 | - * @since 1.0.19 |
|
| 1740 | - * @return string |
|
| 1741 | - */ |
|
| 1737 | + * Get the invoice's gateway display title. |
|
| 1738 | + * |
|
| 1739 | + * @since 1.0.19 |
|
| 1740 | + * @return string |
|
| 1741 | + */ |
|
| 1742 | 1742 | public function get_gateway_title() { |
| 1743 | 1743 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
| 1744 | 1744 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | 1747 | /** |
| 1748 | - * Get the invoice's transaction id. |
|
| 1749 | - * |
|
| 1750 | - * @since 1.0.19 |
|
| 1751 | - * @param string $context View or edit context. |
|
| 1752 | - * @return string |
|
| 1753 | - */ |
|
| 1754 | - public function get_transaction_id( $context = 'view' ) { |
|
| 1755 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 1748 | + * Get the invoice's transaction id. |
|
| 1749 | + * |
|
| 1750 | + * @since 1.0.19 |
|
| 1751 | + * @param string $context View or edit context. |
|
| 1752 | + * @return string |
|
| 1753 | + */ |
|
| 1754 | + public function get_transaction_id( $context = 'view' ) { |
|
| 1755 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 1756 | 1756 | } |
| 1757 | 1757 | |
| 1758 | 1758 | /** |
| 1759 | - * Get the invoice's currency. |
|
| 1760 | - * |
|
| 1761 | - * @since 1.0.19 |
|
| 1762 | - * @param string $context View or edit context. |
|
| 1763 | - * @return string |
|
| 1764 | - */ |
|
| 1765 | - public function get_currency( $context = 'view' ) { |
|
| 1759 | + * Get the invoice's currency. |
|
| 1760 | + * |
|
| 1761 | + * @since 1.0.19 |
|
| 1762 | + * @param string $context View or edit context. |
|
| 1763 | + * @return string |
|
| 1764 | + */ |
|
| 1765 | + public function get_currency( $context = 'view' ) { |
|
| 1766 | 1766 | $currency = $this->get_prop( 'currency', $context ); |
| 1767 | 1767 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | /** |
| 1771 | - * Checks if we are charging taxes for this invoice. |
|
| 1772 | - * |
|
| 1773 | - * @since 1.0.19 |
|
| 1774 | - * @param string $context View or edit context. |
|
| 1775 | - * @return bool |
|
| 1776 | - */ |
|
| 1777 | - public function get_disable_taxes( $context = 'view' ) { |
|
| 1771 | + * Checks if we are charging taxes for this invoice. |
|
| 1772 | + * |
|
| 1773 | + * @since 1.0.19 |
|
| 1774 | + * @param string $context View or edit context. |
|
| 1775 | + * @return bool |
|
| 1776 | + */ |
|
| 1777 | + public function get_disable_taxes( $context = 'view' ) { |
|
| 1778 | 1778 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
| 1779 | 1779 | } |
| 1780 | 1780 | |
| 1781 | 1781 | /** |
| 1782 | - * Retrieves the subscription id for an invoice. |
|
| 1783 | - * |
|
| 1784 | - * @since 1.0.19 |
|
| 1785 | - * @param string $context View or edit context. |
|
| 1786 | - * @return int |
|
| 1787 | - */ |
|
| 1782 | + * Retrieves the subscription id for an invoice. |
|
| 1783 | + * |
|
| 1784 | + * @since 1.0.19 |
|
| 1785 | + * @param string $context View or edit context. |
|
| 1786 | + * @return int |
|
| 1787 | + */ |
|
| 1788 | 1788 | public function get_subscription_id( $context = 'view' ) { |
| 1789 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1790 | - } |
|
| 1791 | - |
|
| 1792 | - /** |
|
| 1793 | - * Retrieves the remote subscription id for an invoice. |
|
| 1794 | - * |
|
| 1795 | - * @since 1.0.19 |
|
| 1796 | - * @param string $context View or edit context. |
|
| 1797 | - * @return int |
|
| 1798 | - */ |
|
| 1789 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1790 | + } |
|
| 1791 | + |
|
| 1792 | + /** |
|
| 1793 | + * Retrieves the remote subscription id for an invoice. |
|
| 1794 | + * |
|
| 1795 | + * @since 1.0.19 |
|
| 1796 | + * @param string $context View or edit context. |
|
| 1797 | + * @return int |
|
| 1798 | + */ |
|
| 1799 | 1799 | public function get_remote_subscription_id( $context = 'view' ) { |
| 1800 | 1800 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
| 1801 | 1801 | |
@@ -1808,23 +1808,23 @@ discard block |
||
| 1808 | 1808 | } |
| 1809 | 1809 | |
| 1810 | 1810 | /** |
| 1811 | - * Get the invoice's _anonymize status. |
|
| 1812 | - * |
|
| 1813 | - * @since 2.8.22 |
|
| 1814 | - * @param string $context View or edit context. |
|
| 1815 | - * @return string |
|
| 1816 | - */ |
|
| 1817 | - public function get_is_anonymized( $context = 'view' ) { |
|
| 1818 | - return (bool) $this->get_prop( 'is_anonymized', $context ); |
|
| 1811 | + * Get the invoice's _anonymize status. |
|
| 1812 | + * |
|
| 1813 | + * @since 2.8.22 |
|
| 1814 | + * @param string $context View or edit context. |
|
| 1815 | + * @return string |
|
| 1816 | + */ |
|
| 1817 | + public function get_is_anonymized( $context = 'view' ) { |
|
| 1818 | + return (bool) $this->get_prop( 'is_anonymized', $context ); |
|
| 1819 | 1819 | } |
| 1820 | 1820 | |
| 1821 | 1821 | /** |
| 1822 | - * Retrieves the payment meta for an invoice. |
|
| 1823 | - * |
|
| 1824 | - * @since 1.0.19 |
|
| 1825 | - * @param string $context View or edit context. |
|
| 1826 | - * @return array |
|
| 1827 | - */ |
|
| 1822 | + * Retrieves the payment meta for an invoice. |
|
| 1823 | + * |
|
| 1824 | + * @since 1.0.19 |
|
| 1825 | + * @param string $context View or edit context. |
|
| 1826 | + * @return array |
|
| 1827 | + */ |
|
| 1828 | 1828 | public function get_payment_meta( $context = 'view' ) { |
| 1829 | 1829 | |
| 1830 | 1830 | return array( |
@@ -1843,31 +1843,31 @@ discard block |
||
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | 1845 | /** |
| 1846 | - * Retrieves the cart details for an invoice. |
|
| 1847 | - * |
|
| 1848 | - * @since 1.0.19 |
|
| 1849 | - * @return array |
|
| 1850 | - */ |
|
| 1846 | + * Retrieves the cart details for an invoice. |
|
| 1847 | + * |
|
| 1848 | + * @since 1.0.19 |
|
| 1849 | + * @return array |
|
| 1850 | + */ |
|
| 1851 | 1851 | public function get_cart_details() { |
| 1852 | 1852 | $items = $this->get_items(); |
| 1853 | 1853 | $cart_details = array(); |
| 1854 | 1854 | |
| 1855 | 1855 | foreach ( $items as $item ) { |
| 1856 | - $item->invoice_id = $this->get_id(); |
|
| 1856 | + $item->invoice_id = $this->get_id(); |
|
| 1857 | 1857 | $cart_details[] = $item->prepare_data_for_saving(); |
| 1858 | 1858 | } |
| 1859 | 1859 | |
| 1860 | 1860 | return $cart_details; |
| 1861 | - } |
|
| 1861 | + } |
|
| 1862 | 1862 | |
| 1863 | - /** |
|
| 1864 | - * Retrieves the recurring item. |
|
| 1865 | - * |
|
| 1866 | - * @return null|GetPaid_Form_Item|int |
|
| 1867 | - */ |
|
| 1868 | - public function get_recurring( $object = false ) { |
|
| 1863 | + /** |
|
| 1864 | + * Retrieves the recurring item. |
|
| 1865 | + * |
|
| 1866 | + * @return null|GetPaid_Form_Item|int |
|
| 1867 | + */ |
|
| 1868 | + public function get_recurring( $object = false ) { |
|
| 1869 | 1869 | |
| 1870 | - // Are we returning an object? |
|
| 1870 | + // Are we returning an object? |
|
| 1871 | 1871 | if ( $object ) { |
| 1872 | 1872 | return $this->get_item( $this->recurring_item ); |
| 1873 | 1873 | } |
@@ -1875,129 +1875,129 @@ discard block |
||
| 1875 | 1875 | return $this->recurring_item; |
| 1876 | 1876 | } |
| 1877 | 1877 | |
| 1878 | - /** |
|
| 1879 | - * Retrieves the subscription name. |
|
| 1880 | - * |
|
| 1881 | - * @since 1.0.19 |
|
| 1882 | - * @return string |
|
| 1883 | - */ |
|
| 1884 | - public function get_subscription_name() { |
|
| 1878 | + /** |
|
| 1879 | + * Retrieves the subscription name. |
|
| 1880 | + * |
|
| 1881 | + * @since 1.0.19 |
|
| 1882 | + * @return string |
|
| 1883 | + */ |
|
| 1884 | + public function get_subscription_name() { |
|
| 1885 | 1885 | |
| 1886 | - // Retrieve the recurring name |
|
| 1886 | + // Retrieve the recurring name |
|
| 1887 | 1887 | $item = $this->get_recurring( true ); |
| 1888 | 1888 | |
| 1889 | - // Abort if it does not exist. |
|
| 1889 | + // Abort if it does not exist. |
|
| 1890 | 1890 | if ( empty( $item ) ) { |
| 1891 | 1891 | return ''; |
| 1892 | 1892 | } |
| 1893 | 1893 | |
| 1894 | - // Return the item name. |
|
| 1894 | + // Return the item name. |
|
| 1895 | 1895 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - /** |
|
| 1899 | - * Retrieves the view url. |
|
| 1900 | - * |
|
| 1901 | - * @since 1.0.19 |
|
| 1902 | - * @return string |
|
| 1903 | - */ |
|
| 1904 | - public function get_view_url() { |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + /** |
|
| 1899 | + * Retrieves the view url. |
|
| 1900 | + * |
|
| 1901 | + * @since 1.0.19 |
|
| 1902 | + * @return string |
|
| 1903 | + */ |
|
| 1904 | + public function get_view_url() { |
|
| 1905 | 1905 | $invoice_url = get_permalink( $this->get_id() ); |
| 1906 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1906 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1907 | 1907 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
| 1908 | - } |
|
| 1908 | + } |
|
| 1909 | 1909 | |
| 1910 | - /** |
|
| 1911 | - * Retrieves the payment url. |
|
| 1912 | - * |
|
| 1913 | - * @since 1.0.19 |
|
| 1914 | - * @return string |
|
| 1915 | - */ |
|
| 1916 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1910 | + /** |
|
| 1911 | + * Retrieves the payment url. |
|
| 1912 | + * |
|
| 1913 | + * @since 1.0.19 |
|
| 1914 | + * @return string |
|
| 1915 | + */ |
|
| 1916 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1917 | 1917 | |
| 1918 | - // Retrieve the checkout url. |
|
| 1918 | + // Retrieve the checkout url. |
|
| 1919 | 1919 | $pay_url = wpinv_get_checkout_uri(); |
| 1920 | 1920 | |
| 1921 | - // Maybe force ssl. |
|
| 1921 | + // Maybe force ssl. |
|
| 1922 | 1922 | if ( is_ssl() ) { |
| 1923 | 1923 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
| 1924 | 1924 | } |
| 1925 | 1925 | |
| 1926 | - // Add the invoice key. |
|
| 1927 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1926 | + // Add the invoice key. |
|
| 1927 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1928 | 1928 | |
| 1929 | - // (Maybe?) add a secret |
|
| 1929 | + // (Maybe?) add a secret |
|
| 1930 | 1930 | if ( $secret ) { |
| 1931 | 1931 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | 1934 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
| 1935 | - } |
|
| 1935 | + } |
|
| 1936 | + |
|
| 1937 | + /** |
|
| 1938 | + * Retrieves the receipt url. |
|
| 1939 | + * |
|
| 1940 | + * @since 1.0.19 |
|
| 1941 | + * @return string |
|
| 1942 | + */ |
|
| 1943 | + public function get_receipt_url() { |
|
| 1944 | + |
|
| 1945 | + // Retrieve the checkout url. |
|
| 1946 | + $receipt_url = wpinv_get_success_page_uri(); |
|
| 1947 | + |
|
| 1948 | + // Maybe force ssl. |
|
| 1949 | + if ( is_ssl() ) { |
|
| 1950 | + $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + // Add the invoice key. |
|
| 1954 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1955 | + |
|
| 1956 | + return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
|
| 1957 | + } |
|
| 1958 | + |
|
| 1959 | + /** |
|
| 1960 | + * Retrieves the remote transaction url. |
|
| 1961 | + * |
|
| 1962 | + * @since 1.6.0 |
|
| 1963 | + * @return string |
|
| 1964 | + */ |
|
| 1965 | + public function get_transaction_url() { |
|
| 1966 | + return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
| 1967 | + } |
|
| 1968 | + |
|
| 1969 | + /** |
|
| 1970 | + * Retrieves the default status. |
|
| 1971 | + * |
|
| 1972 | + * @since 1.0.19 |
|
| 1973 | + * @return string |
|
| 1974 | + */ |
|
| 1975 | + public function get_default_status() { |
|
| 1936 | 1976 | |
| 1937 | - /** |
|
| 1938 | - * Retrieves the receipt url. |
|
| 1939 | - * |
|
| 1940 | - * @since 1.0.19 |
|
| 1941 | - * @return string |
|
| 1942 | - */ |
|
| 1943 | - public function get_receipt_url() { |
|
| 1977 | + $type = $this->get_type(); |
|
| 1978 | + $status = "wpi-$type-pending"; |
|
| 1979 | + return str_replace( '-invoice', '', $status ); |
|
| 1980 | + } |
|
| 1944 | 1981 | |
| 1945 | - // Retrieve the checkout url. |
|
| 1946 | - $receipt_url = wpinv_get_success_page_uri(); |
|
| 1982 | + /** |
|
| 1983 | + * Magic method for accessing invoice properties. |
|
| 1984 | + * |
|
| 1985 | + * @since 1.0.15 |
|
| 1986 | + * @access public |
|
| 1987 | + * |
|
| 1988 | + * @param string $key Discount data to retrieve |
|
| 1989 | + * @param string $context View or edit context. |
|
| 1990 | + * @return mixed Value of the given invoice property (if set). |
|
| 1991 | + */ |
|
| 1992 | + public function get( $key, $context = 'view' ) { |
|
| 1993 | + $method = "get_$key"; |
|
| 1947 | 1994 | |
| 1948 | - // Maybe force ssl. |
|
| 1949 | - if ( is_ssl() ) { |
|
| 1950 | - $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
|
| 1995 | + if ( is_callable( array( $this, $method ) ) ) { |
|
| 1996 | + return $this->$method( $context ); |
|
| 1951 | 1997 | } |
| 1952 | 1998 | |
| 1953 | - // Add the invoice key. |
|
| 1954 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1955 | - |
|
| 1956 | - return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
|
| 1957 | - } |
|
| 1958 | - |
|
| 1959 | - /** |
|
| 1960 | - * Retrieves the remote transaction url. |
|
| 1961 | - * |
|
| 1962 | - * @since 1.6.0 |
|
| 1963 | - * @return string |
|
| 1964 | - */ |
|
| 1965 | - public function get_transaction_url() { |
|
| 1966 | - return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - /** |
|
| 1970 | - * Retrieves the default status. |
|
| 1971 | - * |
|
| 1972 | - * @since 1.0.19 |
|
| 1973 | - * @return string |
|
| 1974 | - */ |
|
| 1975 | - public function get_default_status() { |
|
| 1976 | - |
|
| 1977 | - $type = $this->get_type(); |
|
| 1978 | - $status = "wpi-$type-pending"; |
|
| 1979 | - return str_replace( '-invoice', '', $status ); |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * Magic method for accessing invoice properties. |
|
| 1984 | - * |
|
| 1985 | - * @since 1.0.15 |
|
| 1986 | - * @access public |
|
| 1987 | - * |
|
| 1988 | - * @param string $key Discount data to retrieve |
|
| 1989 | - * @param string $context View or edit context. |
|
| 1990 | - * @return mixed Value of the given invoice property (if set). |
|
| 1991 | - */ |
|
| 1992 | - public function get( $key, $context = 'view' ) { |
|
| 1993 | - $method = "get_$key"; |
|
| 1994 | - |
|
| 1995 | - if ( is_callable( array( $this, $method ) ) ) { |
|
| 1996 | - return $this->$method( $context ); |
|
| 1997 | - } |
|
| 1998 | - |
|
| 1999 | 1999 | return $this->get_prop( $key, $context ); |
| 2000 | - } |
|
| 2000 | + } |
|
| 2001 | 2001 | |
| 2002 | 2002 | /* |
| 2003 | 2003 | |-------------------------------------------------------------------------- |
@@ -2010,128 +2010,128 @@ discard block |
||
| 2010 | 2010 | */ |
| 2011 | 2011 | |
| 2012 | 2012 | /** |
| 2013 | - * Magic method for setting invoice properties. |
|
| 2014 | - * |
|
| 2015 | - * @since 1.0.19 |
|
| 2016 | - * @access public |
|
| 2017 | - * |
|
| 2018 | - * @param string $key Discount data to retrieve |
|
| 2019 | - * @param mixed $value new value. |
|
| 2020 | - * @return mixed Value of the given invoice property (if set). |
|
| 2021 | - */ |
|
| 2022 | - public function set( $key, $value ) { |
|
| 2013 | + * Magic method for setting invoice properties. |
|
| 2014 | + * |
|
| 2015 | + * @since 1.0.19 |
|
| 2016 | + * @access public |
|
| 2017 | + * |
|
| 2018 | + * @param string $key Discount data to retrieve |
|
| 2019 | + * @param mixed $value new value. |
|
| 2020 | + * @return mixed Value of the given invoice property (if set). |
|
| 2021 | + */ |
|
| 2022 | + public function set( $key, $value ) { |
|
| 2023 | 2023 | |
| 2024 | 2024 | $setter = "set_$key"; |
| 2025 | 2025 | if ( is_callable( array( $this, $setter ) ) ) { |
| 2026 | 2026 | $this->{$setter}( $value ); |
| 2027 | 2027 | } |
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * Sets item status. |
|
| 2032 | - * |
|
| 2033 | - * @since 1.0.19 |
|
| 2034 | - * @param string $new_status New status. |
|
| 2035 | - * @param string $note Optional note to add. |
|
| 2036 | - * @param bool $manual_update Is this a manual status change?. |
|
| 2037 | - * @return array details of change. |
|
| 2038 | - */ |
|
| 2039 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 2040 | - $old_status = $this->get_status(); |
|
| 2041 | - |
|
| 2042 | - $statuses = $this->get_all_statuses(); |
|
| 2043 | - |
|
| 2044 | - if ( isset( $statuses['draft'] ) ) { |
|
| 2045 | - unset( $statuses['draft'] ); |
|
| 2046 | - } |
|
| 2047 | - |
|
| 2048 | - $this->set_prop( 'status', $new_status ); |
|
| 2049 | - |
|
| 2050 | - // If setting the status, ensure it's set to a valid status. |
|
| 2051 | - if ( true === $this->object_read ) { |
|
| 2052 | - |
|
| 2053 | - // Only allow valid new status. |
|
| 2054 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2055 | - $new_status = $this->get_default_status(); |
|
| 2056 | - } |
|
| 2057 | - |
|
| 2058 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 2059 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2060 | - $old_status = $this->get_default_status(); |
|
| 2061 | - } |
|
| 2062 | - |
|
| 2063 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 2064 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 2065 | - $old_status = 'wpi-pending'; |
|
| 2066 | - } |
|
| 2067 | - |
|
| 2068 | - if ( $old_status !== $new_status ) { |
|
| 2069 | - $this->status_transition = array( |
|
| 2070 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 2071 | - 'to' => $new_status, |
|
| 2072 | - 'note' => $note, |
|
| 2073 | - 'manual' => (bool) $manual_update, |
|
| 2074 | - ); |
|
| 2075 | - |
|
| 2076 | - if ( $manual_update ) { |
|
| 2077 | - do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
| 2078 | - } |
|
| 2079 | - |
|
| 2080 | - $this->maybe_set_date_paid(); |
|
| 2081 | - |
|
| 2082 | - } |
|
| 2083 | - } |
|
| 2084 | - |
|
| 2085 | - return array( |
|
| 2086 | - 'from' => $old_status, |
|
| 2087 | - 'to' => $new_status, |
|
| 2088 | - ); |
|
| 2089 | - } |
|
| 2090 | - |
|
| 2091 | - /** |
|
| 2092 | - * Maybe set date paid. |
|
| 2093 | - * |
|
| 2094 | - * Sets the date paid variable when transitioning to the payment complete |
|
| 2095 | - * order status. |
|
| 2096 | - * |
|
| 2097 | - * @since 1.0.19 |
|
| 2098 | - */ |
|
| 2099 | - public function maybe_set_date_paid() { |
|
| 2100 | - |
|
| 2101 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 2102 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 2103 | - } |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - /** |
|
| 2107 | - * Set parent invoice ID. |
|
| 2108 | - * |
|
| 2109 | - * @since 1.0.19 |
|
| 2110 | - */ |
|
| 2111 | - public function set_parent_id( $value ) { |
|
| 2112 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
| 2113 | - return; |
|
| 2114 | - } |
|
| 2115 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 2116 | - } |
|
| 2117 | - |
|
| 2118 | - /** |
|
| 2119 | - * Set plugin version when the invoice was created. |
|
| 2120 | - * |
|
| 2121 | - * @since 1.0.19 |
|
| 2122 | - */ |
|
| 2123 | - public function set_version( $value ) { |
|
| 2124 | - $this->set_prop( 'version', $value ); |
|
| 2125 | - } |
|
| 2126 | - |
|
| 2127 | - /** |
|
| 2128 | - * Set date when the invoice was created. |
|
| 2129 | - * |
|
| 2130 | - * @since 1.0.19 |
|
| 2131 | - * @param string $value Value to set. |
|
| 2028 | + } |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * Sets item status. |
|
| 2032 | + * |
|
| 2033 | + * @since 1.0.19 |
|
| 2034 | + * @param string $new_status New status. |
|
| 2035 | + * @param string $note Optional note to add. |
|
| 2036 | + * @param bool $manual_update Is this a manual status change?. |
|
| 2037 | + * @return array details of change. |
|
| 2038 | + */ |
|
| 2039 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 2040 | + $old_status = $this->get_status(); |
|
| 2041 | + |
|
| 2042 | + $statuses = $this->get_all_statuses(); |
|
| 2043 | + |
|
| 2044 | + if ( isset( $statuses['draft'] ) ) { |
|
| 2045 | + unset( $statuses['draft'] ); |
|
| 2046 | + } |
|
| 2047 | + |
|
| 2048 | + $this->set_prop( 'status', $new_status ); |
|
| 2049 | + |
|
| 2050 | + // If setting the status, ensure it's set to a valid status. |
|
| 2051 | + if ( true === $this->object_read ) { |
|
| 2052 | + |
|
| 2053 | + // Only allow valid new status. |
|
| 2054 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2055 | + $new_status = $this->get_default_status(); |
|
| 2056 | + } |
|
| 2057 | + |
|
| 2058 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 2059 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2060 | + $old_status = $this->get_default_status(); |
|
| 2061 | + } |
|
| 2062 | + |
|
| 2063 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 2064 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 2065 | + $old_status = 'wpi-pending'; |
|
| 2066 | + } |
|
| 2067 | + |
|
| 2068 | + if ( $old_status !== $new_status ) { |
|
| 2069 | + $this->status_transition = array( |
|
| 2070 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 2071 | + 'to' => $new_status, |
|
| 2072 | + 'note' => $note, |
|
| 2073 | + 'manual' => (bool) $manual_update, |
|
| 2074 | + ); |
|
| 2075 | + |
|
| 2076 | + if ( $manual_update ) { |
|
| 2077 | + do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
| 2078 | + } |
|
| 2079 | + |
|
| 2080 | + $this->maybe_set_date_paid(); |
|
| 2081 | + |
|
| 2082 | + } |
|
| 2083 | + } |
|
| 2084 | + |
|
| 2085 | + return array( |
|
| 2086 | + 'from' => $old_status, |
|
| 2087 | + 'to' => $new_status, |
|
| 2088 | + ); |
|
| 2089 | + } |
|
| 2090 | + |
|
| 2091 | + /** |
|
| 2092 | + * Maybe set date paid. |
|
| 2093 | + * |
|
| 2094 | + * Sets the date paid variable when transitioning to the payment complete |
|
| 2095 | + * order status. |
|
| 2096 | + * |
|
| 2097 | + * @since 1.0.19 |
|
| 2098 | + */ |
|
| 2099 | + public function maybe_set_date_paid() { |
|
| 2100 | + |
|
| 2101 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 2102 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 2103 | + } |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + /** |
|
| 2107 | + * Set parent invoice ID. |
|
| 2108 | + * |
|
| 2109 | + * @since 1.0.19 |
|
| 2110 | + */ |
|
| 2111 | + public function set_parent_id( $value ) { |
|
| 2112 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
| 2113 | + return; |
|
| 2114 | + } |
|
| 2115 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 2116 | + } |
|
| 2117 | + |
|
| 2118 | + /** |
|
| 2119 | + * Set plugin version when the invoice was created. |
|
| 2120 | + * |
|
| 2121 | + * @since 1.0.19 |
|
| 2122 | + */ |
|
| 2123 | + public function set_version( $value ) { |
|
| 2124 | + $this->set_prop( 'version', $value ); |
|
| 2125 | + } |
|
| 2126 | + |
|
| 2127 | + /** |
|
| 2128 | + * Set date when the invoice was created. |
|
| 2129 | + * |
|
| 2130 | + * @since 1.0.19 |
|
| 2131 | + * @param string $value Value to set. |
|
| 2132 | 2132 | * @return bool Whether or not the date was set. |
| 2133 | - */ |
|
| 2134 | - public function set_date_created( $value ) { |
|
| 2133 | + */ |
|
| 2134 | + public function set_date_created( $value ) { |
|
| 2135 | 2135 | $date = strtotime( $value ); |
| 2136 | 2136 | |
| 2137 | 2137 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2139,18 +2139,18 @@ discard block |
||
| 2139 | 2139 | return true; |
| 2140 | 2140 | } |
| 2141 | 2141 | |
| 2142 | - $this->set_prop( 'date_created', '' ); |
|
| 2143 | - return false; |
|
| 2142 | + $this->set_prop( 'date_created', '' ); |
|
| 2143 | + return false; |
|
| 2144 | 2144 | } |
| 2145 | 2145 | |
| 2146 | 2146 | /** |
| 2147 | - * Set date invoice due date. |
|
| 2148 | - * |
|
| 2149 | - * @since 1.0.19 |
|
| 2150 | - * @param string $value Value to set. |
|
| 2147 | + * Set date invoice due date. |
|
| 2148 | + * |
|
| 2149 | + * @since 1.0.19 |
|
| 2150 | + * @param string $value Value to set. |
|
| 2151 | 2151 | * @return bool Whether or not the date was set. |
| 2152 | - */ |
|
| 2153 | - public function set_due_date( $value ) { |
|
| 2152 | + */ |
|
| 2153 | + public function set_due_date( $value ) { |
|
| 2154 | 2154 | $date = strtotime( $value ); |
| 2155 | 2155 | |
| 2156 | 2156 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2158,28 +2158,28 @@ discard block |
||
| 2158 | 2158 | return true; |
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | - $this->set_prop( 'due_date', '' ); |
|
| 2161 | + $this->set_prop( 'due_date', '' ); |
|
| 2162 | 2162 | return false; |
| 2163 | 2163 | } |
| 2164 | 2164 | |
| 2165 | 2165 | /** |
| 2166 | - * Alias of self::set_due_date(). |
|
| 2167 | - * |
|
| 2168 | - * @since 1.0.19 |
|
| 2169 | - * @param string $value New name. |
|
| 2170 | - */ |
|
| 2171 | - public function set_date_due( $value ) { |
|
| 2172 | - $this->set_due_date( $value ); |
|
| 2166 | + * Alias of self::set_due_date(). |
|
| 2167 | + * |
|
| 2168 | + * @since 1.0.19 |
|
| 2169 | + * @param string $value New name. |
|
| 2170 | + */ |
|
| 2171 | + public function set_date_due( $value ) { |
|
| 2172 | + $this->set_due_date( $value ); |
|
| 2173 | 2173 | } |
| 2174 | 2174 | |
| 2175 | 2175 | /** |
| 2176 | - * Set date invoice was completed. |
|
| 2177 | - * |
|
| 2178 | - * @since 1.0.19 |
|
| 2179 | - * @param string $value Value to set. |
|
| 2176 | + * Set date invoice was completed. |
|
| 2177 | + * |
|
| 2178 | + * @since 1.0.19 |
|
| 2179 | + * @param string $value Value to set. |
|
| 2180 | 2180 | * @return bool Whether or not the date was set. |
| 2181 | - */ |
|
| 2182 | - public function set_completed_date( $value ) { |
|
| 2181 | + */ |
|
| 2182 | + public function set_completed_date( $value ) { |
|
| 2183 | 2183 | $date = strtotime( $value ); |
| 2184 | 2184 | |
| 2185 | 2185 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2187,28 +2187,28 @@ discard block |
||
| 2187 | 2187 | return true; |
| 2188 | 2188 | } |
| 2189 | 2189 | |
| 2190 | - $this->set_prop( 'completed_date', '' ); |
|
| 2190 | + $this->set_prop( 'completed_date', '' ); |
|
| 2191 | 2191 | return false; |
| 2192 | 2192 | } |
| 2193 | 2193 | |
| 2194 | 2194 | /** |
| 2195 | - * Alias of self::set_completed_date(). |
|
| 2196 | - * |
|
| 2197 | - * @since 1.0.19 |
|
| 2198 | - * @param string $value New name. |
|
| 2199 | - */ |
|
| 2200 | - public function set_date_completed( $value ) { |
|
| 2201 | - $this->set_completed_date( $value ); |
|
| 2195 | + * Alias of self::set_completed_date(). |
|
| 2196 | + * |
|
| 2197 | + * @since 1.0.19 |
|
| 2198 | + * @param string $value New name. |
|
| 2199 | + */ |
|
| 2200 | + public function set_date_completed( $value ) { |
|
| 2201 | + $this->set_completed_date( $value ); |
|
| 2202 | 2202 | } |
| 2203 | 2203 | |
| 2204 | 2204 | /** |
| 2205 | - * Set date when the invoice was last modified. |
|
| 2206 | - * |
|
| 2207 | - * @since 1.0.19 |
|
| 2208 | - * @param string $value Value to set. |
|
| 2205 | + * Set date when the invoice was last modified. |
|
| 2206 | + * |
|
| 2207 | + * @since 1.0.19 |
|
| 2208 | + * @param string $value Value to set. |
|
| 2209 | 2209 | * @return bool Whether or not the date was set. |
| 2210 | - */ |
|
| 2211 | - public function set_date_modified( $value ) { |
|
| 2210 | + */ |
|
| 2211 | + public function set_date_modified( $value ) { |
|
| 2212 | 2212 | $date = strtotime( $value ); |
| 2213 | 2213 | |
| 2214 | 2214 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2216,809 +2216,809 @@ discard block |
||
| 2216 | 2216 | return true; |
| 2217 | 2217 | } |
| 2218 | 2218 | |
| 2219 | - $this->set_prop( 'date_modified', '' ); |
|
| 2219 | + $this->set_prop( 'date_modified', '' ); |
|
| 2220 | 2220 | return false; |
| 2221 | 2221 | } |
| 2222 | 2222 | |
| 2223 | 2223 | /** |
| 2224 | - * Set the invoice number. |
|
| 2225 | - * |
|
| 2226 | - * @since 1.0.19 |
|
| 2227 | - * @param string $value New number. |
|
| 2228 | - */ |
|
| 2229 | - public function set_number( $value ) { |
|
| 2224 | + * Set the invoice number. |
|
| 2225 | + * |
|
| 2226 | + * @since 1.0.19 |
|
| 2227 | + * @param string $value New number. |
|
| 2228 | + */ |
|
| 2229 | + public function set_number( $value ) { |
|
| 2230 | 2230 | $number = sanitize_text_field( $value ); |
| 2231 | - $this->set_prop( 'number', $number ); |
|
| 2231 | + $this->set_prop( 'number', $number ); |
|
| 2232 | 2232 | } |
| 2233 | 2233 | |
| 2234 | 2234 | /** |
| 2235 | - * Set the invoice type. |
|
| 2236 | - * |
|
| 2237 | - * @since 1.0.19 |
|
| 2238 | - * @param string $value Type. |
|
| 2239 | - */ |
|
| 2240 | - public function set_type( $value ) { |
|
| 2235 | + * Set the invoice type. |
|
| 2236 | + * |
|
| 2237 | + * @since 1.0.19 |
|
| 2238 | + * @param string $value Type. |
|
| 2239 | + */ |
|
| 2240 | + public function set_type( $value ) { |
|
| 2241 | 2241 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
| 2242 | - $this->set_prop( 'type', $type ); |
|
| 2243 | - } |
|
| 2242 | + $this->set_prop( 'type', $type ); |
|
| 2243 | + } |
|
| 2244 | 2244 | |
| 2245 | 2245 | /** |
| 2246 | - * Set the invoice post type. |
|
| 2247 | - * |
|
| 2248 | - * @since 1.0.19 |
|
| 2249 | - * @param string $value Post type. |
|
| 2250 | - */ |
|
| 2251 | - public function set_post_type( $value ) { |
|
| 2246 | + * Set the invoice post type. |
|
| 2247 | + * |
|
| 2248 | + * @since 1.0.19 |
|
| 2249 | + * @param string $value Post type. |
|
| 2250 | + */ |
|
| 2251 | + public function set_post_type( $value ) { |
|
| 2252 | 2252 | if ( getpaid_is_invoice_post_type( $value ) ) { |
| 2253 | - $this->set_type( $value ); |
|
| 2253 | + $this->set_type( $value ); |
|
| 2254 | 2254 | $this->set_prop( 'post_type', $value ); |
| 2255 | 2255 | } |
| 2256 | 2256 | } |
| 2257 | 2257 | |
| 2258 | 2258 | /** |
| 2259 | - * Set the invoice key. |
|
| 2260 | - * |
|
| 2261 | - * @since 1.0.19 |
|
| 2262 | - * @param string $value New key. |
|
| 2263 | - */ |
|
| 2264 | - public function set_key( $value ) { |
|
| 2259 | + * Set the invoice key. |
|
| 2260 | + * |
|
| 2261 | + * @since 1.0.19 |
|
| 2262 | + * @param string $value New key. |
|
| 2263 | + */ |
|
| 2264 | + public function set_key( $value ) { |
|
| 2265 | 2265 | $key = sanitize_text_field( $value ); |
| 2266 | - $this->set_prop( 'key', $key ); |
|
| 2266 | + $this->set_prop( 'key', $key ); |
|
| 2267 | 2267 | } |
| 2268 | 2268 | |
| 2269 | 2269 | /** |
| 2270 | - * Set the invoice mode. |
|
| 2271 | - * |
|
| 2272 | - * @since 1.0.19 |
|
| 2273 | - * @param string $value mode. |
|
| 2274 | - */ |
|
| 2275 | - public function set_mode( $value ) { |
|
| 2270 | + * Set the invoice mode. |
|
| 2271 | + * |
|
| 2272 | + * @since 1.0.19 |
|
| 2273 | + * @param string $value mode. |
|
| 2274 | + */ |
|
| 2275 | + public function set_mode( $value ) { |
|
| 2276 | 2276 | if ( in_array( $value, array( 'live', 'test' ) ) ) { |
| 2277 | 2277 | $this->set_prop( 'mode', $value ); |
| 2278 | 2278 | } |
| 2279 | 2279 | } |
| 2280 | 2280 | |
| 2281 | 2281 | /** |
| 2282 | - * Set the invoice path. |
|
| 2283 | - * |
|
| 2284 | - * @since 1.0.19 |
|
| 2285 | - * @param string $value path. |
|
| 2286 | - */ |
|
| 2287 | - public function set_path( $value ) { |
|
| 2282 | + * Set the invoice path. |
|
| 2283 | + * |
|
| 2284 | + * @since 1.0.19 |
|
| 2285 | + * @param string $value path. |
|
| 2286 | + */ |
|
| 2287 | + public function set_path( $value ) { |
|
| 2288 | 2288 | $this->set_prop( 'path', $value ); |
| 2289 | 2289 | } |
| 2290 | 2290 | |
| 2291 | 2291 | /** |
| 2292 | - * Set the invoice name. |
|
| 2293 | - * |
|
| 2294 | - * @since 1.0.19 |
|
| 2295 | - * @param string $value New name. |
|
| 2296 | - */ |
|
| 2297 | - public function set_name( $value ) { |
|
| 2292 | + * Set the invoice name. |
|
| 2293 | + * |
|
| 2294 | + * @since 1.0.19 |
|
| 2295 | + * @param string $value New name. |
|
| 2296 | + */ |
|
| 2297 | + public function set_name( $value ) { |
|
| 2298 | 2298 | $name = sanitize_text_field( $value ); |
| 2299 | - $this->set_prop( 'name', $name ); |
|
| 2299 | + $this->set_prop( 'name', $name ); |
|
| 2300 | 2300 | } |
| 2301 | 2301 | |
| 2302 | 2302 | /** |
| 2303 | - * Alias of self::set_name(). |
|
| 2304 | - * |
|
| 2305 | - * @since 1.0.19 |
|
| 2306 | - * @param string $value New name. |
|
| 2307 | - */ |
|
| 2308 | - public function set_title( $value ) { |
|
| 2309 | - $this->set_name( $value ); |
|
| 2303 | + * Alias of self::set_name(). |
|
| 2304 | + * |
|
| 2305 | + * @since 1.0.19 |
|
| 2306 | + * @param string $value New name. |
|
| 2307 | + */ |
|
| 2308 | + public function set_title( $value ) { |
|
| 2309 | + $this->set_name( $value ); |
|
| 2310 | 2310 | } |
| 2311 | 2311 | |
| 2312 | 2312 | /** |
| 2313 | - * Set the invoice description. |
|
| 2314 | - * |
|
| 2315 | - * @since 1.0.19 |
|
| 2316 | - * @param string $value New description. |
|
| 2317 | - */ |
|
| 2318 | - public function set_description( $value ) { |
|
| 2313 | + * Set the invoice description. |
|
| 2314 | + * |
|
| 2315 | + * @since 1.0.19 |
|
| 2316 | + * @param string $value New description. |
|
| 2317 | + */ |
|
| 2318 | + public function set_description( $value ) { |
|
| 2319 | 2319 | $description = wp_kses_post( $value ); |
| 2320 | - $this->set_prop( 'description', $description ); |
|
| 2320 | + $this->set_prop( 'description', $description ); |
|
| 2321 | + } |
|
| 2322 | + |
|
| 2323 | + /** |
|
| 2324 | + * Alias of self::set_description(). |
|
| 2325 | + * |
|
| 2326 | + * @since 1.0.19 |
|
| 2327 | + * @param string $value New description. |
|
| 2328 | + */ |
|
| 2329 | + public function set_excerpt( $value ) { |
|
| 2330 | + $this->set_description( $value ); |
|
| 2331 | + } |
|
| 2332 | + |
|
| 2333 | + /** |
|
| 2334 | + * Alias of self::set_description(). |
|
| 2335 | + * |
|
| 2336 | + * @since 1.0.19 |
|
| 2337 | + * @param string $value New description. |
|
| 2338 | + */ |
|
| 2339 | + public function set_summary( $value ) { |
|
| 2340 | + $this->set_description( $value ); |
|
| 2341 | + } |
|
| 2342 | + |
|
| 2343 | + /** |
|
| 2344 | + * Set the receiver of the invoice. |
|
| 2345 | + * |
|
| 2346 | + * @since 1.0.19 |
|
| 2347 | + * @param int $value New author. |
|
| 2348 | + */ |
|
| 2349 | + public function set_author( $value ) { |
|
| 2350 | + $user = get_user_by( 'id', (int) $value ); |
|
| 2351 | + |
|
| 2352 | + if ( $user && $user->ID ) { |
|
| 2353 | + $this->set_prop( 'author', $user->ID ); |
|
| 2354 | + $this->set_prop( 'email', $user->user_email ); |
|
| 2355 | + } |
|
| 2356 | + } |
|
| 2357 | + |
|
| 2358 | + /** |
|
| 2359 | + * Alias of self::set_author(). |
|
| 2360 | + * |
|
| 2361 | + * @since 1.0.19 |
|
| 2362 | + * @param int $value New user id. |
|
| 2363 | + */ |
|
| 2364 | + public function set_user_id( $value ) { |
|
| 2365 | + $this->set_author( $value ); |
|
| 2366 | + } |
|
| 2367 | + |
|
| 2368 | + /** |
|
| 2369 | + * Sets the customer ID. |
|
| 2370 | + * |
|
| 2371 | + * @since 1.0.19 |
|
| 2372 | + * @param int $value New user id. |
|
| 2373 | + */ |
|
| 2374 | + public function set_customer_id( $value ) { |
|
| 2375 | + $this->set_prop( 'customer_id', (int) $value ); |
|
| 2376 | + } |
|
| 2377 | + |
|
| 2378 | + /** |
|
| 2379 | + * Set the customer's ip. |
|
| 2380 | + * |
|
| 2381 | + * @since 1.0.19 |
|
| 2382 | + * @param string $value ip address. |
|
| 2383 | + */ |
|
| 2384 | + public function set_ip( $value ) { |
|
| 2385 | + $this->set_prop( 'ip', $value ); |
|
| 2386 | + } |
|
| 2387 | + |
|
| 2388 | + /** |
|
| 2389 | + * Alias of self::set_ip(). |
|
| 2390 | + * |
|
| 2391 | + * @since 1.0.19 |
|
| 2392 | + * @param string $value ip address. |
|
| 2393 | + */ |
|
| 2394 | + public function set_user_ip( $value ) { |
|
| 2395 | + $this->set_ip( $value ); |
|
| 2396 | + } |
|
| 2397 | + |
|
| 2398 | + /** |
|
| 2399 | + * Set the customer's first name. |
|
| 2400 | + * |
|
| 2401 | + * @since 1.0.19 |
|
| 2402 | + * @param string $value first name. |
|
| 2403 | + */ |
|
| 2404 | + public function set_first_name( $value ) { |
|
| 2405 | + $this->set_prop( 'first_name', $value ); |
|
| 2406 | + } |
|
| 2407 | + |
|
| 2408 | + /** |
|
| 2409 | + * Alias of self::set_first_name(). |
|
| 2410 | + * |
|
| 2411 | + * @since 1.0.19 |
|
| 2412 | + * @param string $value first name. |
|
| 2413 | + */ |
|
| 2414 | + public function set_user_first_name( $value ) { |
|
| 2415 | + $this->set_first_name( $value ); |
|
| 2416 | + } |
|
| 2417 | + |
|
| 2418 | + /** |
|
| 2419 | + * Alias of self::set_first_name(). |
|
| 2420 | + * |
|
| 2421 | + * @since 1.0.19 |
|
| 2422 | + * @param string $value first name. |
|
| 2423 | + */ |
|
| 2424 | + public function set_customer_first_name( $value ) { |
|
| 2425 | + $this->set_first_name( $value ); |
|
| 2426 | + } |
|
| 2427 | + |
|
| 2428 | + /** |
|
| 2429 | + * Set the customer's last name. |
|
| 2430 | + * |
|
| 2431 | + * @since 1.0.19 |
|
| 2432 | + * @param string $value last name. |
|
| 2433 | + */ |
|
| 2434 | + public function set_last_name( $value ) { |
|
| 2435 | + $this->set_prop( 'last_name', $value ); |
|
| 2436 | + } |
|
| 2437 | + |
|
| 2438 | + /** |
|
| 2439 | + * Alias of self::set_last_name(). |
|
| 2440 | + * |
|
| 2441 | + * @since 1.0.19 |
|
| 2442 | + * @param string $value last name. |
|
| 2443 | + */ |
|
| 2444 | + public function set_user_last_name( $value ) { |
|
| 2445 | + $this->set_last_name( $value ); |
|
| 2446 | + } |
|
| 2447 | + |
|
| 2448 | + /** |
|
| 2449 | + * Alias of self::set_last_name(). |
|
| 2450 | + * |
|
| 2451 | + * @since 1.0.19 |
|
| 2452 | + * @param string $value last name. |
|
| 2453 | + */ |
|
| 2454 | + public function set_customer_last_name( $value ) { |
|
| 2455 | + $this->set_last_name( $value ); |
|
| 2321 | 2456 | } |
| 2322 | 2457 | |
| 2323 | 2458 | /** |
| 2324 | - * Alias of self::set_description(). |
|
| 2325 | - * |
|
| 2326 | - * @since 1.0.19 |
|
| 2327 | - * @param string $value New description. |
|
| 2328 | - */ |
|
| 2329 | - public function set_excerpt( $value ) { |
|
| 2330 | - $this->set_description( $value ); |
|
| 2459 | + * Set the customer's phone number. |
|
| 2460 | + * |
|
| 2461 | + * @since 1.0.19 |
|
| 2462 | + * @param string $value phone. |
|
| 2463 | + */ |
|
| 2464 | + public function set_phone( $value ) { |
|
| 2465 | + $this->set_prop( 'phone', $value ); |
|
| 2466 | + } |
|
| 2467 | + |
|
| 2468 | + /** |
|
| 2469 | + * Alias of self::set_phone(). |
|
| 2470 | + * |
|
| 2471 | + * @since 1.0.19 |
|
| 2472 | + * @param string $value phone. |
|
| 2473 | + */ |
|
| 2474 | + public function set_user_phone( $value ) { |
|
| 2475 | + $this->set_phone( $value ); |
|
| 2476 | + } |
|
| 2477 | + |
|
| 2478 | + /** |
|
| 2479 | + * Alias of self::set_phone(). |
|
| 2480 | + * |
|
| 2481 | + * @since 1.0.19 |
|
| 2482 | + * @param string $value phone. |
|
| 2483 | + */ |
|
| 2484 | + public function set_customer_phone( $value ) { |
|
| 2485 | + $this->set_phone( $value ); |
|
| 2486 | + } |
|
| 2487 | + |
|
| 2488 | + /** |
|
| 2489 | + * Alias of self::set_phone(). |
|
| 2490 | + * |
|
| 2491 | + * @since 1.0.19 |
|
| 2492 | + * @param string $value phone. |
|
| 2493 | + */ |
|
| 2494 | + public function set_phone_number( $value ) { |
|
| 2495 | + $this->set_phone( $value ); |
|
| 2496 | + } |
|
| 2497 | + |
|
| 2498 | + /** |
|
| 2499 | + * Set the customer's email address. |
|
| 2500 | + * |
|
| 2501 | + * @since 1.0.19 |
|
| 2502 | + * @param string $value email address. |
|
| 2503 | + */ |
|
| 2504 | + public function set_email( $value ) { |
|
| 2505 | + $this->set_prop( 'email', $value ); |
|
| 2506 | + } |
|
| 2507 | + |
|
| 2508 | + /** |
|
| 2509 | + * Alias of self::set_email(). |
|
| 2510 | + * |
|
| 2511 | + * @since 1.0.19 |
|
| 2512 | + * @param string $value email address. |
|
| 2513 | + */ |
|
| 2514 | + public function set_user_email( $value ) { |
|
| 2515 | + $this->set_email( $value ); |
|
| 2331 | 2516 | } |
| 2332 | 2517 | |
| 2333 | 2518 | /** |
| 2334 | - * Alias of self::set_description(). |
|
| 2335 | - * |
|
| 2336 | - * @since 1.0.19 |
|
| 2337 | - * @param string $value New description. |
|
| 2338 | - */ |
|
| 2339 | - public function set_summary( $value ) { |
|
| 2340 | - $this->set_description( $value ); |
|
| 2519 | + * Alias of self::set_email(). |
|
| 2520 | + * |
|
| 2521 | + * @since 1.0.19 |
|
| 2522 | + * @param string $value email address. |
|
| 2523 | + */ |
|
| 2524 | + public function set_email_address( $value ) { |
|
| 2525 | + $this->set_email( $value ); |
|
| 2341 | 2526 | } |
| 2342 | 2527 | |
| 2343 | 2528 | /** |
| 2344 | - * Set the receiver of the invoice. |
|
| 2345 | - * |
|
| 2346 | - * @since 1.0.19 |
|
| 2347 | - * @param int $value New author. |
|
| 2348 | - */ |
|
| 2349 | - public function set_author( $value ) { |
|
| 2350 | - $user = get_user_by( 'id', (int) $value ); |
|
| 2529 | + * Alias of self::set_email(). |
|
| 2530 | + * |
|
| 2531 | + * @since 1.0.19 |
|
| 2532 | + * @param string $value email address. |
|
| 2533 | + */ |
|
| 2534 | + public function set_customer_email( $value ) { |
|
| 2535 | + $this->set_email( $value ); |
|
| 2536 | + } |
|
| 2351 | 2537 | |
| 2352 | - if ( $user && $user->ID ) { |
|
| 2353 | - $this->set_prop( 'author', $user->ID ); |
|
| 2354 | - $this->set_prop( 'email', $user->user_email ); |
|
| 2355 | - } |
|
| 2538 | + /** |
|
| 2539 | + * Set the customer's country. |
|
| 2540 | + * |
|
| 2541 | + * @since 1.0.19 |
|
| 2542 | + * @param string $value country. |
|
| 2543 | + */ |
|
| 2544 | + public function set_country( $value ) { |
|
| 2545 | + $this->set_prop( 'country', $value ); |
|
| 2356 | 2546 | } |
| 2357 | 2547 | |
| 2358 | 2548 | /** |
| 2359 | - * Alias of self::set_author(). |
|
| 2360 | - * |
|
| 2361 | - * @since 1.0.19 |
|
| 2362 | - * @param int $value New user id. |
|
| 2363 | - */ |
|
| 2364 | - public function set_user_id( $value ) { |
|
| 2365 | - $this->set_author( $value ); |
|
| 2549 | + * Alias of self::set_country(). |
|
| 2550 | + * |
|
| 2551 | + * @since 1.0.19 |
|
| 2552 | + * @param string $value country. |
|
| 2553 | + */ |
|
| 2554 | + public function set_user_country( $value ) { |
|
| 2555 | + $this->set_country( $value ); |
|
| 2366 | 2556 | } |
| 2367 | 2557 | |
| 2368 | 2558 | /** |
| 2369 | - * Sets the customer ID. |
|
| 2370 | - * |
|
| 2371 | - * @since 1.0.19 |
|
| 2372 | - * @param int $value New user id. |
|
| 2373 | - */ |
|
| 2374 | - public function set_customer_id( $value ) { |
|
| 2375 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 2559 | + * Alias of self::set_country(). |
|
| 2560 | + * |
|
| 2561 | + * @since 1.0.19 |
|
| 2562 | + * @param string $value country. |
|
| 2563 | + */ |
|
| 2564 | + public function set_customer_country( $value ) { |
|
| 2565 | + $this->set_country( $value ); |
|
| 2376 | 2566 | } |
| 2377 | 2567 | |
| 2378 | 2568 | /** |
| 2379 | - * Set the customer's ip. |
|
| 2380 | - * |
|
| 2381 | - * @since 1.0.19 |
|
| 2382 | - * @param string $value ip address. |
|
| 2383 | - */ |
|
| 2384 | - public function set_ip( $value ) { |
|
| 2385 | - $this->set_prop( 'ip', $value ); |
|
| 2569 | + * Set the customer's state. |
|
| 2570 | + * |
|
| 2571 | + * @since 1.0.19 |
|
| 2572 | + * @param string $value state. |
|
| 2573 | + */ |
|
| 2574 | + public function set_state( $value ) { |
|
| 2575 | + $this->set_prop( 'state', $value ); |
|
| 2386 | 2576 | } |
| 2387 | 2577 | |
| 2388 | 2578 | /** |
| 2389 | - * Alias of self::set_ip(). |
|
| 2390 | - * |
|
| 2391 | - * @since 1.0.19 |
|
| 2392 | - * @param string $value ip address. |
|
| 2393 | - */ |
|
| 2394 | - public function set_user_ip( $value ) { |
|
| 2395 | - $this->set_ip( $value ); |
|
| 2579 | + * Alias of self::set_state(). |
|
| 2580 | + * |
|
| 2581 | + * @since 1.0.19 |
|
| 2582 | + * @param string $value state. |
|
| 2583 | + */ |
|
| 2584 | + public function set_user_state( $value ) { |
|
| 2585 | + $this->set_state( $value ); |
|
| 2396 | 2586 | } |
| 2397 | 2587 | |
| 2398 | 2588 | /** |
| 2399 | - * Set the customer's first name. |
|
| 2400 | - * |
|
| 2401 | - * @since 1.0.19 |
|
| 2402 | - * @param string $value first name. |
|
| 2403 | - */ |
|
| 2404 | - public function set_first_name( $value ) { |
|
| 2405 | - $this->set_prop( 'first_name', $value ); |
|
| 2589 | + * Alias of self::set_state(). |
|
| 2590 | + * |
|
| 2591 | + * @since 1.0.19 |
|
| 2592 | + * @param string $value state. |
|
| 2593 | + */ |
|
| 2594 | + public function set_customer_state( $value ) { |
|
| 2595 | + $this->set_state( $value ); |
|
| 2406 | 2596 | } |
| 2407 | 2597 | |
| 2408 | 2598 | /** |
| 2409 | - * Alias of self::set_first_name(). |
|
| 2410 | - * |
|
| 2411 | - * @since 1.0.19 |
|
| 2412 | - * @param string $value first name. |
|
| 2413 | - */ |
|
| 2414 | - public function set_user_first_name( $value ) { |
|
| 2415 | - $this->set_first_name( $value ); |
|
| 2599 | + * Set the customer's city. |
|
| 2600 | + * |
|
| 2601 | + * @since 1.0.19 |
|
| 2602 | + * @param string $value city. |
|
| 2603 | + */ |
|
| 2604 | + public function set_city( $value ) { |
|
| 2605 | + $this->set_prop( 'city', $value ); |
|
| 2416 | 2606 | } |
| 2417 | 2607 | |
| 2418 | 2608 | /** |
| 2419 | - * Alias of self::set_first_name(). |
|
| 2420 | - * |
|
| 2421 | - * @since 1.0.19 |
|
| 2422 | - * @param string $value first name. |
|
| 2423 | - */ |
|
| 2424 | - public function set_customer_first_name( $value ) { |
|
| 2425 | - $this->set_first_name( $value ); |
|
| 2609 | + * Alias of self::set_city(). |
|
| 2610 | + * |
|
| 2611 | + * @since 1.0.19 |
|
| 2612 | + * @param string $value city. |
|
| 2613 | + */ |
|
| 2614 | + public function set_user_city( $value ) { |
|
| 2615 | + $this->set_city( $value ); |
|
| 2426 | 2616 | } |
| 2427 | 2617 | |
| 2428 | 2618 | /** |
| 2429 | - * Set the customer's last name. |
|
| 2430 | - * |
|
| 2431 | - * @since 1.0.19 |
|
| 2432 | - * @param string $value last name. |
|
| 2433 | - */ |
|
| 2434 | - public function set_last_name( $value ) { |
|
| 2435 | - $this->set_prop( 'last_name', $value ); |
|
| 2619 | + * Alias of self::set_city(). |
|
| 2620 | + * |
|
| 2621 | + * @since 1.0.19 |
|
| 2622 | + * @param string $value city. |
|
| 2623 | + */ |
|
| 2624 | + public function set_customer_city( $value ) { |
|
| 2625 | + $this->set_city( $value ); |
|
| 2436 | 2626 | } |
| 2437 | 2627 | |
| 2438 | 2628 | /** |
| 2439 | - * Alias of self::set_last_name(). |
|
| 2440 | - * |
|
| 2441 | - * @since 1.0.19 |
|
| 2442 | - * @param string $value last name. |
|
| 2443 | - */ |
|
| 2444 | - public function set_user_last_name( $value ) { |
|
| 2445 | - $this->set_last_name( $value ); |
|
| 2629 | + * Set the customer's zip code. |
|
| 2630 | + * |
|
| 2631 | + * @since 1.0.19 |
|
| 2632 | + * @param string $value zip. |
|
| 2633 | + */ |
|
| 2634 | + public function set_zip( $value ) { |
|
| 2635 | + $this->set_prop( 'zip', $value ); |
|
| 2446 | 2636 | } |
| 2447 | 2637 | |
| 2448 | 2638 | /** |
| 2449 | - * Alias of self::set_last_name(). |
|
| 2450 | - * |
|
| 2451 | - * @since 1.0.19 |
|
| 2452 | - * @param string $value last name. |
|
| 2453 | - */ |
|
| 2454 | - public function set_customer_last_name( $value ) { |
|
| 2455 | - $this->set_last_name( $value ); |
|
| 2639 | + * Alias of self::set_zip(). |
|
| 2640 | + * |
|
| 2641 | + * @since 1.0.19 |
|
| 2642 | + * @param string $value zip. |
|
| 2643 | + */ |
|
| 2644 | + public function set_user_zip( $value ) { |
|
| 2645 | + $this->set_zip( $value ); |
|
| 2456 | 2646 | } |
| 2457 | 2647 | |
| 2458 | 2648 | /** |
| 2459 | - * Set the customer's phone number. |
|
| 2460 | - * |
|
| 2461 | - * @since 1.0.19 |
|
| 2462 | - * @param string $value phone. |
|
| 2463 | - */ |
|
| 2464 | - public function set_phone( $value ) { |
|
| 2465 | - $this->set_prop( 'phone', $value ); |
|
| 2649 | + * Alias of self::set_zip(). |
|
| 2650 | + * |
|
| 2651 | + * @since 1.0.19 |
|
| 2652 | + * @param string $value zip. |
|
| 2653 | + */ |
|
| 2654 | + public function set_customer_zip( $value ) { |
|
| 2655 | + $this->set_zip( $value ); |
|
| 2466 | 2656 | } |
| 2467 | 2657 | |
| 2468 | 2658 | /** |
| 2469 | - * Alias of self::set_phone(). |
|
| 2470 | - * |
|
| 2471 | - * @since 1.0.19 |
|
| 2472 | - * @param string $value phone. |
|
| 2473 | - */ |
|
| 2474 | - public function set_user_phone( $value ) { |
|
| 2475 | - $this->set_phone( $value ); |
|
| 2659 | + * Set the customer's company. |
|
| 2660 | + * |
|
| 2661 | + * @since 1.0.19 |
|
| 2662 | + * @param string $value company. |
|
| 2663 | + */ |
|
| 2664 | + public function set_company( $value ) { |
|
| 2665 | + $this->set_prop( 'company', $value ); |
|
| 2476 | 2666 | } |
| 2477 | 2667 | |
| 2478 | 2668 | /** |
| 2479 | - * Alias of self::set_phone(). |
|
| 2480 | - * |
|
| 2481 | - * @since 1.0.19 |
|
| 2482 | - * @param string $value phone. |
|
| 2483 | - */ |
|
| 2484 | - public function set_customer_phone( $value ) { |
|
| 2485 | - $this->set_phone( $value ); |
|
| 2669 | + * Alias of self::set_company(). |
|
| 2670 | + * |
|
| 2671 | + * @since 1.0.19 |
|
| 2672 | + * @param string $value company. |
|
| 2673 | + */ |
|
| 2674 | + public function set_user_company( $value ) { |
|
| 2675 | + $this->set_company( $value ); |
|
| 2486 | 2676 | } |
| 2487 | 2677 | |
| 2488 | 2678 | /** |
| 2489 | - * Alias of self::set_phone(). |
|
| 2490 | - * |
|
| 2491 | - * @since 1.0.19 |
|
| 2492 | - * @param string $value phone. |
|
| 2493 | - */ |
|
| 2494 | - public function set_phone_number( $value ) { |
|
| 2495 | - $this->set_phone( $value ); |
|
| 2679 | + * Alias of self::set_company(). |
|
| 2680 | + * |
|
| 2681 | + * @since 1.0.19 |
|
| 2682 | + * @param string $value company. |
|
| 2683 | + */ |
|
| 2684 | + public function set_customer_company( $value ) { |
|
| 2685 | + $this->set_company( $value ); |
|
| 2496 | 2686 | } |
| 2497 | 2687 | |
| 2498 | 2688 | /** |
| 2499 | - * Set the customer's email address. |
|
| 2500 | - * |
|
| 2501 | - * @since 1.0.19 |
|
| 2502 | - * @param string $value email address. |
|
| 2503 | - */ |
|
| 2504 | - public function set_email( $value ) { |
|
| 2505 | - $this->set_prop( 'email', $value ); |
|
| 2689 | + * Set the customer's company id. |
|
| 2690 | + * |
|
| 2691 | + * @since 1.0.19 |
|
| 2692 | + * @param string $value company id. |
|
| 2693 | + */ |
|
| 2694 | + public function set_company_id( $value ) { |
|
| 2695 | + $this->set_prop( 'company_id', $value ); |
|
| 2506 | 2696 | } |
| 2507 | 2697 | |
| 2508 | 2698 | /** |
| 2509 | - * Alias of self::set_email(). |
|
| 2510 | - * |
|
| 2511 | - * @since 1.0.19 |
|
| 2512 | - * @param string $value email address. |
|
| 2513 | - */ |
|
| 2514 | - public function set_user_email( $value ) { |
|
| 2515 | - $this->set_email( $value ); |
|
| 2699 | + * Set the customer's var number. |
|
| 2700 | + * |
|
| 2701 | + * @since 1.0.19 |
|
| 2702 | + * @param string $value var number. |
|
| 2703 | + */ |
|
| 2704 | + public function set_vat_number( $value ) { |
|
| 2705 | + $this->set_prop( 'vat_number', $value ); |
|
| 2516 | 2706 | } |
| 2517 | 2707 | |
| 2518 | 2708 | /** |
| 2519 | - * Alias of self::set_email(). |
|
| 2520 | - * |
|
| 2521 | - * @since 1.0.19 |
|
| 2522 | - * @param string $value email address. |
|
| 2523 | - */ |
|
| 2524 | - public function set_email_address( $value ) { |
|
| 2525 | - $this->set_email( $value ); |
|
| 2709 | + * Alias of self::set_vat_number(). |
|
| 2710 | + * |
|
| 2711 | + * @since 1.0.19 |
|
| 2712 | + * @param string $value var number. |
|
| 2713 | + */ |
|
| 2714 | + public function set_user_vat_number( $value ) { |
|
| 2715 | + $this->set_vat_number( $value ); |
|
| 2526 | 2716 | } |
| 2527 | 2717 | |
| 2528 | 2718 | /** |
| 2529 | - * Alias of self::set_email(). |
|
| 2530 | - * |
|
| 2531 | - * @since 1.0.19 |
|
| 2532 | - * @param string $value email address. |
|
| 2533 | - */ |
|
| 2534 | - public function set_customer_email( $value ) { |
|
| 2535 | - $this->set_email( $value ); |
|
| 2719 | + * Alias of self::set_vat_number(). |
|
| 2720 | + * |
|
| 2721 | + * @since 1.0.19 |
|
| 2722 | + * @param string $value var number. |
|
| 2723 | + */ |
|
| 2724 | + public function set_customer_vat_number( $value ) { |
|
| 2725 | + $this->set_vat_number( $value ); |
|
| 2536 | 2726 | } |
| 2537 | 2727 | |
| 2538 | 2728 | /** |
| 2539 | - * Set the customer's country. |
|
| 2540 | - * |
|
| 2541 | - * @since 1.0.19 |
|
| 2542 | - * @param string $value country. |
|
| 2543 | - */ |
|
| 2544 | - public function set_country( $value ) { |
|
| 2545 | - $this->set_prop( 'country', $value ); |
|
| 2729 | + * Set the customer's vat rate. |
|
| 2730 | + * |
|
| 2731 | + * @since 1.0.19 |
|
| 2732 | + * @param string $value var rate. |
|
| 2733 | + */ |
|
| 2734 | + public function set_vat_rate( $value ) { |
|
| 2735 | + $this->set_prop( 'vat_rate', $value ); |
|
| 2546 | 2736 | } |
| 2547 | 2737 | |
| 2548 | 2738 | /** |
| 2549 | - * Alias of self::set_country(). |
|
| 2550 | - * |
|
| 2551 | - * @since 1.0.19 |
|
| 2552 | - * @param string $value country. |
|
| 2553 | - */ |
|
| 2554 | - public function set_user_country( $value ) { |
|
| 2555 | - $this->set_country( $value ); |
|
| 2739 | + * Alias of self::set_vat_rate(). |
|
| 2740 | + * |
|
| 2741 | + * @since 1.0.19 |
|
| 2742 | + * @param string $value var number. |
|
| 2743 | + */ |
|
| 2744 | + public function set_user_vat_rate( $value ) { |
|
| 2745 | + $this->set_vat_rate( $value ); |
|
| 2556 | 2746 | } |
| 2557 | 2747 | |
| 2558 | 2748 | /** |
| 2559 | - * Alias of self::set_country(). |
|
| 2560 | - * |
|
| 2561 | - * @since 1.0.19 |
|
| 2562 | - * @param string $value country. |
|
| 2563 | - */ |
|
| 2564 | - public function set_customer_country( $value ) { |
|
| 2565 | - $this->set_country( $value ); |
|
| 2749 | + * Alias of self::set_vat_rate(). |
|
| 2750 | + * |
|
| 2751 | + * @since 1.0.19 |
|
| 2752 | + * @param string $value var number. |
|
| 2753 | + */ |
|
| 2754 | + public function set_customer_vat_rate( $value ) { |
|
| 2755 | + $this->set_vat_rate( $value ); |
|
| 2566 | 2756 | } |
| 2567 | 2757 | |
| 2568 | 2758 | /** |
| 2569 | - * Set the customer's state. |
|
| 2570 | - * |
|
| 2571 | - * @since 1.0.19 |
|
| 2572 | - * @param string $value state. |
|
| 2573 | - */ |
|
| 2574 | - public function set_state( $value ) { |
|
| 2575 | - $this->set_prop( 'state', $value ); |
|
| 2759 | + * Set the customer's address. |
|
| 2760 | + * |
|
| 2761 | + * @since 1.0.19 |
|
| 2762 | + * @param string $value address. |
|
| 2763 | + */ |
|
| 2764 | + public function set_address( $value ) { |
|
| 2765 | + $this->set_prop( 'address', $value ); |
|
| 2576 | 2766 | } |
| 2577 | 2767 | |
| 2578 | 2768 | /** |
| 2579 | - * Alias of self::set_state(). |
|
| 2580 | - * |
|
| 2581 | - * @since 1.0.19 |
|
| 2582 | - * @param string $value state. |
|
| 2583 | - */ |
|
| 2584 | - public function set_user_state( $value ) { |
|
| 2585 | - $this->set_state( $value ); |
|
| 2769 | + * Alias of self::set_address(). |
|
| 2770 | + * |
|
| 2771 | + * @since 1.0.19 |
|
| 2772 | + * @param string $value address. |
|
| 2773 | + */ |
|
| 2774 | + public function set_user_address( $value ) { |
|
| 2775 | + $this->set_address( $value ); |
|
| 2586 | 2776 | } |
| 2587 | 2777 | |
| 2588 | 2778 | /** |
| 2589 | - * Alias of self::set_state(). |
|
| 2590 | - * |
|
| 2591 | - * @since 1.0.19 |
|
| 2592 | - * @param string $value state. |
|
| 2593 | - */ |
|
| 2594 | - public function set_customer_state( $value ) { |
|
| 2595 | - $this->set_state( $value ); |
|
| 2779 | + * Alias of self::set_address(). |
|
| 2780 | + * |
|
| 2781 | + * @since 1.0.19 |
|
| 2782 | + * @param string $value address. |
|
| 2783 | + */ |
|
| 2784 | + public function set_customer_address( $value ) { |
|
| 2785 | + $this->set_address( $value ); |
|
| 2596 | 2786 | } |
| 2597 | 2787 | |
| 2598 | 2788 | /** |
| 2599 | - * Set the customer's city. |
|
| 2600 | - * |
|
| 2601 | - * @since 1.0.19 |
|
| 2602 | - * @param string $value city. |
|
| 2603 | - */ |
|
| 2604 | - public function set_city( $value ) { |
|
| 2605 | - $this->set_prop( 'city', $value ); |
|
| 2789 | + * Set whether the customer has viewed the invoice or not. |
|
| 2790 | + * |
|
| 2791 | + * @since 1.0.19 |
|
| 2792 | + * @param int|bool $value confirmed. |
|
| 2793 | + */ |
|
| 2794 | + public function set_is_viewed( $value ) { |
|
| 2795 | + $this->set_prop( 'is_viewed', $value ); |
|
| 2606 | 2796 | } |
| 2607 | 2797 | |
| 2608 | 2798 | /** |
| 2609 | - * Alias of self::set_city(). |
|
| 2610 | - * |
|
| 2611 | - * @since 1.0.19 |
|
| 2612 | - * @param string $value city. |
|
| 2613 | - */ |
|
| 2614 | - public function set_user_city( $value ) { |
|
| 2615 | - $this->set_city( $value ); |
|
| 2799 | + * Set extra email recipients. |
|
| 2800 | + * |
|
| 2801 | + * @since 1.0.19 |
|
| 2802 | + * @param string $value email recipients. |
|
| 2803 | + */ |
|
| 2804 | + public function set_email_cc( $value ) { |
|
| 2805 | + $this->set_prop( 'email_cc', $value ); |
|
| 2616 | 2806 | } |
| 2617 | 2807 | |
| 2618 | 2808 | /** |
| 2619 | - * Alias of self::set_city(). |
|
| 2620 | - * |
|
| 2621 | - * @since 1.0.19 |
|
| 2622 | - * @param string $value city. |
|
| 2623 | - */ |
|
| 2624 | - public function set_customer_city( $value ) { |
|
| 2625 | - $this->set_city( $value ); |
|
| 2809 | + * Set the invoice template. |
|
| 2810 | + * |
|
| 2811 | + * @since 1.0.19 |
|
| 2812 | + * @param string $value template. |
|
| 2813 | + */ |
|
| 2814 | + public function set_template( $value ) { |
|
| 2815 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2816 | + $this->set_prop( 'template', $value ); |
|
| 2817 | + } |
|
| 2626 | 2818 | } |
| 2627 | 2819 | |
| 2628 | 2820 | /** |
| 2629 | - * Set the customer's zip code. |
|
| 2630 | - * |
|
| 2631 | - * @since 1.0.19 |
|
| 2632 | - * @param string $value zip. |
|
| 2633 | - */ |
|
| 2634 | - public function set_zip( $value ) { |
|
| 2635 | - $this->set_prop( 'zip', $value ); |
|
| 2821 | + * Set the invoice source. |
|
| 2822 | + * |
|
| 2823 | + * @since 1.0.19 |
|
| 2824 | + * @param string $value source. |
|
| 2825 | + * @deprecated |
|
| 2826 | + */ |
|
| 2827 | + public function created_via( $value ) { |
|
| 2828 | + $this->set_created_via( sanitize_text_field( $value ) ); |
|
| 2636 | 2829 | } |
| 2637 | 2830 | |
| 2638 | 2831 | /** |
| 2639 | - * Alias of self::set_zip(). |
|
| 2640 | - * |
|
| 2641 | - * @since 1.0.19 |
|
| 2642 | - * @param string $value zip. |
|
| 2643 | - */ |
|
| 2644 | - public function set_user_zip( $value ) { |
|
| 2645 | - $this->set_zip( $value ); |
|
| 2832 | + * Set the invoice source. |
|
| 2833 | + * |
|
| 2834 | + * @since 1.0.19 |
|
| 2835 | + * @param string $value source. |
|
| 2836 | + */ |
|
| 2837 | + public function set_created_via( $value ) { |
|
| 2838 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2646 | 2839 | } |
| 2647 | 2840 | |
| 2648 | 2841 | /** |
| 2649 | - * Alias of self::set_zip(). |
|
| 2650 | - * |
|
| 2651 | - * @since 1.0.19 |
|
| 2652 | - * @param string $value zip. |
|
| 2653 | - */ |
|
| 2654 | - public function set_customer_zip( $value ) { |
|
| 2655 | - $this->set_zip( $value ); |
|
| 2842 | + * Set the customer's address confirmed status. |
|
| 2843 | + * |
|
| 2844 | + * @since 1.0.19 |
|
| 2845 | + * @param int|bool $value confirmed. |
|
| 2846 | + */ |
|
| 2847 | + public function set_address_confirmed( $value ) { |
|
| 2848 | + $this->set_prop( 'address_confirmed', $value ); |
|
| 2656 | 2849 | } |
| 2657 | 2850 | |
| 2658 | 2851 | /** |
| 2659 | - * Set the customer's company. |
|
| 2660 | - * |
|
| 2661 | - * @since 1.0.19 |
|
| 2662 | - * @param string $value company. |
|
| 2663 | - */ |
|
| 2664 | - public function set_company( $value ) { |
|
| 2665 | - $this->set_prop( 'company', $value ); |
|
| 2852 | + * Alias of self::set_address_confirmed(). |
|
| 2853 | + * |
|
| 2854 | + * @since 1.0.19 |
|
| 2855 | + * @param int|bool $value confirmed. |
|
| 2856 | + */ |
|
| 2857 | + public function set_user_address_confirmed( $value ) { |
|
| 2858 | + $this->set_address_confirmed( $value ); |
|
| 2666 | 2859 | } |
| 2667 | 2860 | |
| 2668 | 2861 | /** |
| 2669 | - * Alias of self::set_company(). |
|
| 2670 | - * |
|
| 2671 | - * @since 1.0.19 |
|
| 2672 | - * @param string $value company. |
|
| 2673 | - */ |
|
| 2674 | - public function set_user_company( $value ) { |
|
| 2675 | - $this->set_company( $value ); |
|
| 2862 | + * Alias of self::set_address_confirmed(). |
|
| 2863 | + * |
|
| 2864 | + * @since 1.0.19 |
|
| 2865 | + * @param int|bool $value confirmed. |
|
| 2866 | + */ |
|
| 2867 | + public function set_customer_address_confirmed( $value ) { |
|
| 2868 | + $this->set_address_confirmed( $value ); |
|
| 2676 | 2869 | } |
| 2677 | 2870 | |
| 2678 | 2871 | /** |
| 2679 | - * Alias of self::set_company(). |
|
| 2680 | - * |
|
| 2681 | - * @since 1.0.19 |
|
| 2682 | - * @param string $value company. |
|
| 2683 | - */ |
|
| 2684 | - public function set_customer_company( $value ) { |
|
| 2685 | - $this->set_company( $value ); |
|
| 2686 | - } |
|
| 2872 | + * Set the shipping fee |
|
| 2873 | + * |
|
| 2874 | + * @since 1.0.19 |
|
| 2875 | + * @param float $value shipping amount. |
|
| 2876 | + */ |
|
| 2877 | + public function set_shipping( $value ) { |
|
| 2687 | 2878 | |
| 2688 | - /** |
|
| 2689 | - * Set the customer's company id. |
|
| 2690 | - * |
|
| 2691 | - * @since 1.0.19 |
|
| 2692 | - * @param string $value company id. |
|
| 2693 | - */ |
|
| 2694 | - public function set_company_id( $value ) { |
|
| 2695 | - $this->set_prop( 'company_id', $value ); |
|
| 2696 | - } |
|
| 2879 | + if ( ! is_numeric( $value ) ) { |
|
| 2880 | + return $this->set_prop( 'shipping', null ); |
|
| 2881 | + } |
|
| 2697 | 2882 | |
| 2698 | - /** |
|
| 2699 | - * Set the customer's var number. |
|
| 2700 | - * |
|
| 2701 | - * @since 1.0.19 |
|
| 2702 | - * @param string $value var number. |
|
| 2703 | - */ |
|
| 2704 | - public function set_vat_number( $value ) { |
|
| 2705 | - $this->set_prop( 'vat_number', $value ); |
|
| 2883 | + $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
| 2706 | 2884 | } |
| 2707 | 2885 | |
| 2708 | 2886 | /** |
| 2709 | - * Alias of self::set_vat_number(). |
|
| 2710 | - * |
|
| 2711 | - * @since 1.0.19 |
|
| 2712 | - * @param string $value var number. |
|
| 2713 | - */ |
|
| 2714 | - public function set_user_vat_number( $value ) { |
|
| 2715 | - $this->set_vat_number( $value ); |
|
| 2887 | + * Set the invoice sub total. |
|
| 2888 | + * |
|
| 2889 | + * @since 1.0.19 |
|
| 2890 | + * @param float $value sub total. |
|
| 2891 | + */ |
|
| 2892 | + public function set_subtotal( $value ) { |
|
| 2893 | + $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
| 2716 | 2894 | } |
| 2717 | 2895 | |
| 2718 | 2896 | /** |
| 2719 | - * Alias of self::set_vat_number(). |
|
| 2720 | - * |
|
| 2721 | - * @since 1.0.19 |
|
| 2722 | - * @param string $value var number. |
|
| 2723 | - */ |
|
| 2724 | - public function set_customer_vat_number( $value ) { |
|
| 2725 | - $this->set_vat_number( $value ); |
|
| 2897 | + * Set the invoice total. |
|
| 2898 | + * |
|
| 2899 | + * @since 1.0.19 |
|
| 2900 | + * @param float $value sub total. |
|
| 2901 | + */ |
|
| 2902 | + public function set_total( $value ) { |
|
| 2903 | + $this->set_prop( 'total', max( 0, $value ) ); |
|
| 2726 | 2904 | } |
| 2727 | 2905 | |
| 2728 | 2906 | /** |
| 2729 | - * Set the customer's vat rate. |
|
| 2730 | - * |
|
| 2731 | - * @since 1.0.19 |
|
| 2732 | - * @param string $value var rate. |
|
| 2733 | - */ |
|
| 2734 | - public function set_vat_rate( $value ) { |
|
| 2735 | - $this->set_prop( 'vat_rate', $value ); |
|
| 2736 | - } |
|
| 2737 | - |
|
| 2738 | - /** |
|
| 2739 | - * Alias of self::set_vat_rate(). |
|
| 2740 | - * |
|
| 2741 | - * @since 1.0.19 |
|
| 2742 | - * @param string $value var number. |
|
| 2743 | - */ |
|
| 2744 | - public function set_user_vat_rate( $value ) { |
|
| 2745 | - $this->set_vat_rate( $value ); |
|
| 2746 | - } |
|
| 2747 | - |
|
| 2748 | - /** |
|
| 2749 | - * Alias of self::set_vat_rate(). |
|
| 2750 | - * |
|
| 2751 | - * @since 1.0.19 |
|
| 2752 | - * @param string $value var number. |
|
| 2753 | - */ |
|
| 2754 | - public function set_customer_vat_rate( $value ) { |
|
| 2755 | - $this->set_vat_rate( $value ); |
|
| 2756 | - } |
|
| 2757 | - |
|
| 2758 | - /** |
|
| 2759 | - * Set the customer's address. |
|
| 2760 | - * |
|
| 2761 | - * @since 1.0.19 |
|
| 2762 | - * @param string $value address. |
|
| 2763 | - */ |
|
| 2764 | - public function set_address( $value ) { |
|
| 2765 | - $this->set_prop( 'address', $value ); |
|
| 2766 | - } |
|
| 2767 | - |
|
| 2768 | - /** |
|
| 2769 | - * Alias of self::set_address(). |
|
| 2770 | - * |
|
| 2771 | - * @since 1.0.19 |
|
| 2772 | - * @param string $value address. |
|
| 2773 | - */ |
|
| 2774 | - public function set_user_address( $value ) { |
|
| 2775 | - $this->set_address( $value ); |
|
| 2776 | - } |
|
| 2777 | - |
|
| 2778 | - /** |
|
| 2779 | - * Alias of self::set_address(). |
|
| 2780 | - * |
|
| 2781 | - * @since 1.0.19 |
|
| 2782 | - * @param string $value address. |
|
| 2783 | - */ |
|
| 2784 | - public function set_customer_address( $value ) { |
|
| 2785 | - $this->set_address( $value ); |
|
| 2786 | - } |
|
| 2787 | - |
|
| 2788 | - /** |
|
| 2789 | - * Set whether the customer has viewed the invoice or not. |
|
| 2790 | - * |
|
| 2791 | - * @since 1.0.19 |
|
| 2792 | - * @param int|bool $value confirmed. |
|
| 2793 | - */ |
|
| 2794 | - public function set_is_viewed( $value ) { |
|
| 2795 | - $this->set_prop( 'is_viewed', $value ); |
|
| 2796 | - } |
|
| 2797 | - |
|
| 2798 | - /** |
|
| 2799 | - * Set extra email recipients. |
|
| 2800 | - * |
|
| 2801 | - * @since 1.0.19 |
|
| 2802 | - * @param string $value email recipients. |
|
| 2803 | - */ |
|
| 2804 | - public function set_email_cc( $value ) { |
|
| 2805 | - $this->set_prop( 'email_cc', $value ); |
|
| 2806 | - } |
|
| 2807 | - |
|
| 2808 | - /** |
|
| 2809 | - * Set the invoice template. |
|
| 2810 | - * |
|
| 2811 | - * @since 1.0.19 |
|
| 2812 | - * @param string $value template. |
|
| 2813 | - */ |
|
| 2814 | - public function set_template( $value ) { |
|
| 2815 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2816 | - $this->set_prop( 'template', $value ); |
|
| 2817 | - } |
|
| 2818 | - } |
|
| 2819 | - |
|
| 2820 | - /** |
|
| 2821 | - * Set the invoice source. |
|
| 2822 | - * |
|
| 2823 | - * @since 1.0.19 |
|
| 2824 | - * @param string $value source. |
|
| 2825 | - * @deprecated |
|
| 2826 | - */ |
|
| 2827 | - public function created_via( $value ) { |
|
| 2828 | - $this->set_created_via( sanitize_text_field( $value ) ); |
|
| 2829 | - } |
|
| 2830 | - |
|
| 2831 | - /** |
|
| 2832 | - * Set the invoice source. |
|
| 2833 | - * |
|
| 2834 | - * @since 1.0.19 |
|
| 2835 | - * @param string $value source. |
|
| 2836 | - */ |
|
| 2837 | - public function set_created_via( $value ) { |
|
| 2838 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2839 | - } |
|
| 2840 | - |
|
| 2841 | - /** |
|
| 2842 | - * Set the customer's address confirmed status. |
|
| 2843 | - * |
|
| 2844 | - * @since 1.0.19 |
|
| 2845 | - * @param int|bool $value confirmed. |
|
| 2846 | - */ |
|
| 2847 | - public function set_address_confirmed( $value ) { |
|
| 2848 | - $this->set_prop( 'address_confirmed', $value ); |
|
| 2849 | - } |
|
| 2850 | - |
|
| 2851 | - /** |
|
| 2852 | - * Alias of self::set_address_confirmed(). |
|
| 2853 | - * |
|
| 2854 | - * @since 1.0.19 |
|
| 2855 | - * @param int|bool $value confirmed. |
|
| 2856 | - */ |
|
| 2857 | - public function set_user_address_confirmed( $value ) { |
|
| 2858 | - $this->set_address_confirmed( $value ); |
|
| 2859 | - } |
|
| 2860 | - |
|
| 2861 | - /** |
|
| 2862 | - * Alias of self::set_address_confirmed(). |
|
| 2863 | - * |
|
| 2864 | - * @since 1.0.19 |
|
| 2865 | - * @param int|bool $value confirmed. |
|
| 2866 | - */ |
|
| 2867 | - public function set_customer_address_confirmed( $value ) { |
|
| 2868 | - $this->set_address_confirmed( $value ); |
|
| 2869 | - } |
|
| 2870 | - |
|
| 2871 | - /** |
|
| 2872 | - * Set the shipping fee |
|
| 2873 | - * |
|
| 2874 | - * @since 1.0.19 |
|
| 2875 | - * @param float $value shipping amount. |
|
| 2876 | - */ |
|
| 2877 | - public function set_shipping( $value ) { |
|
| 2878 | - |
|
| 2879 | - if ( ! is_numeric( $value ) ) { |
|
| 2880 | - return $this->set_prop( 'shipping', null ); |
|
| 2881 | - } |
|
| 2882 | - |
|
| 2883 | - $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
| 2884 | - } |
|
| 2885 | - |
|
| 2886 | - /** |
|
| 2887 | - * Set the invoice sub total. |
|
| 2888 | - * |
|
| 2889 | - * @since 1.0.19 |
|
| 2890 | - * @param float $value sub total. |
|
| 2891 | - */ |
|
| 2892 | - public function set_subtotal( $value ) { |
|
| 2893 | - $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
| 2894 | - } |
|
| 2895 | - |
|
| 2896 | - /** |
|
| 2897 | - * Set the invoice total. |
|
| 2898 | - * |
|
| 2899 | - * @since 1.0.19 |
|
| 2900 | - * @param float $value sub total. |
|
| 2901 | - */ |
|
| 2902 | - public function set_total( $value ) { |
|
| 2903 | - $this->set_prop( 'total', max( 0, $value ) ); |
|
| 2904 | - } |
|
| 2905 | - |
|
| 2906 | - /** |
|
| 2907 | - * Set the invoice discount amount. |
|
| 2908 | - * |
|
| 2909 | - * @since 1.0.19 |
|
| 2910 | - * @param float $value discount total. |
|
| 2911 | - */ |
|
| 2912 | - public function set_total_discount( $value ) { |
|
| 2913 | - $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
| 2907 | + * Set the invoice discount amount. |
|
| 2908 | + * |
|
| 2909 | + * @since 1.0.19 |
|
| 2910 | + * @param float $value discount total. |
|
| 2911 | + */ |
|
| 2912 | + public function set_total_discount( $value ) { |
|
| 2913 | + $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
| 2914 | 2914 | } |
| 2915 | 2915 | |
| 2916 | 2916 | /** |
| 2917 | - * Alias of self::set_total_discount(). |
|
| 2918 | - * |
|
| 2919 | - * @since 1.0.19 |
|
| 2920 | - * @param float $value discount total. |
|
| 2921 | - */ |
|
| 2922 | - public function set_discount( $value ) { |
|
| 2923 | - $this->set_total_discount( $value ); |
|
| 2917 | + * Alias of self::set_total_discount(). |
|
| 2918 | + * |
|
| 2919 | + * @since 1.0.19 |
|
| 2920 | + * @param float $value discount total. |
|
| 2921 | + */ |
|
| 2922 | + public function set_discount( $value ) { |
|
| 2923 | + $this->set_total_discount( $value ); |
|
| 2924 | 2924 | } |
| 2925 | 2925 | |
| 2926 | 2926 | /** |
| 2927 | - * Set the invoice tax amount. |
|
| 2928 | - * |
|
| 2929 | - * @since 1.0.19 |
|
| 2930 | - * @param float $value tax total. |
|
| 2931 | - */ |
|
| 2932 | - public function set_total_tax( $value ) { |
|
| 2933 | - $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
| 2927 | + * Set the invoice tax amount. |
|
| 2928 | + * |
|
| 2929 | + * @since 1.0.19 |
|
| 2930 | + * @param float $value tax total. |
|
| 2931 | + */ |
|
| 2932 | + public function set_total_tax( $value ) { |
|
| 2933 | + $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
| 2934 | 2934 | } |
| 2935 | 2935 | |
| 2936 | 2936 | /** |
| 2937 | - * Alias of self::set_total_tax(). |
|
| 2938 | - * |
|
| 2939 | - * @since 1.0.19 |
|
| 2940 | - * @param float $value tax total. |
|
| 2941 | - */ |
|
| 2942 | - public function set_tax_total( $value ) { |
|
| 2943 | - $this->set_total_tax( $value ); |
|
| 2937 | + * Alias of self::set_total_tax(). |
|
| 2938 | + * |
|
| 2939 | + * @since 1.0.19 |
|
| 2940 | + * @param float $value tax total. |
|
| 2941 | + */ |
|
| 2942 | + public function set_tax_total( $value ) { |
|
| 2943 | + $this->set_total_tax( $value ); |
|
| 2944 | 2944 | } |
| 2945 | 2945 | |
| 2946 | 2946 | /** |
| 2947 | - * Set the invoice fees amount. |
|
| 2948 | - * |
|
| 2949 | - * @since 1.0.19 |
|
| 2950 | - * @param float $value fees total. |
|
| 2951 | - */ |
|
| 2952 | - public function set_total_fees( $value ) { |
|
| 2953 | - $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
| 2947 | + * Set the invoice fees amount. |
|
| 2948 | + * |
|
| 2949 | + * @since 1.0.19 |
|
| 2950 | + * @param float $value fees total. |
|
| 2951 | + */ |
|
| 2952 | + public function set_total_fees( $value ) { |
|
| 2953 | + $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
| 2954 | 2954 | } |
| 2955 | 2955 | |
| 2956 | 2956 | /** |
| 2957 | - * Alias of self::set_total_fees(). |
|
| 2958 | - * |
|
| 2959 | - * @since 1.0.19 |
|
| 2960 | - * @param float $value fees total. |
|
| 2961 | - */ |
|
| 2962 | - public function set_fees_total( $value ) { |
|
| 2963 | - $this->set_total_fees( $value ); |
|
| 2957 | + * Alias of self::set_total_fees(). |
|
| 2958 | + * |
|
| 2959 | + * @since 1.0.19 |
|
| 2960 | + * @param float $value fees total. |
|
| 2961 | + */ |
|
| 2962 | + public function set_fees_total( $value ) { |
|
| 2963 | + $this->set_total_fees( $value ); |
|
| 2964 | 2964 | } |
| 2965 | 2965 | |
| 2966 | 2966 | /** |
| 2967 | - * Set the invoice fees. |
|
| 2968 | - * |
|
| 2969 | - * @since 1.0.19 |
|
| 2970 | - * @param array $value fees. |
|
| 2971 | - */ |
|
| 2972 | - public function set_fees( $value ) { |
|
| 2967 | + * Set the invoice fees. |
|
| 2968 | + * |
|
| 2969 | + * @since 1.0.19 |
|
| 2970 | + * @param array $value fees. |
|
| 2971 | + */ |
|
| 2972 | + public function set_fees( $value ) { |
|
| 2973 | 2973 | |
| 2974 | - if ( ! is_array( $value ) ) { |
|
| 2975 | - $value = array(); |
|
| 2976 | - } |
|
| 2974 | + if ( ! is_array( $value ) ) { |
|
| 2975 | + $value = array(); |
|
| 2976 | + } |
|
| 2977 | 2977 | |
| 2978 | - $this->set_prop( 'fees', $value ); |
|
| 2978 | + $this->set_prop( 'fees', $value ); |
|
| 2979 | 2979 | } |
| 2980 | 2980 | |
| 2981 | 2981 | /** |
| 2982 | - * Set the invoice taxes. |
|
| 2983 | - * |
|
| 2984 | - * @since 1.0.19 |
|
| 2985 | - * @param array $value taxes. |
|
| 2986 | - */ |
|
| 2987 | - public function set_taxes( $value ) { |
|
| 2982 | + * Set the invoice taxes. |
|
| 2983 | + * |
|
| 2984 | + * @since 1.0.19 |
|
| 2985 | + * @param array $value taxes. |
|
| 2986 | + */ |
|
| 2987 | + public function set_taxes( $value ) { |
|
| 2988 | 2988 | |
| 2989 | - if ( ! is_array( $value ) ) { |
|
| 2990 | - $value = array(); |
|
| 2991 | - } |
|
| 2989 | + if ( ! is_array( $value ) ) { |
|
| 2990 | + $value = array(); |
|
| 2991 | + } |
|
| 2992 | 2992 | |
| 2993 | - $this->set_prop( 'taxes', $value ); |
|
| 2993 | + $this->set_prop( 'taxes', $value ); |
|
| 2994 | 2994 | } |
| 2995 | 2995 | |
| 2996 | 2996 | /** |
| 2997 | - * Set the invoice discounts. |
|
| 2998 | - * |
|
| 2999 | - * @since 1.0.19 |
|
| 3000 | - * @param array $value discounts. |
|
| 3001 | - */ |
|
| 3002 | - public function set_discounts( $value ) { |
|
| 2997 | + * Set the invoice discounts. |
|
| 2998 | + * |
|
| 2999 | + * @since 1.0.19 |
|
| 3000 | + * @param array $value discounts. |
|
| 3001 | + */ |
|
| 3002 | + public function set_discounts( $value ) { |
|
| 3003 | 3003 | |
| 3004 | - if ( ! is_array( $value ) ) { |
|
| 3005 | - $value = array(); |
|
| 3006 | - } |
|
| 3004 | + if ( ! is_array( $value ) ) { |
|
| 3005 | + $value = array(); |
|
| 3006 | + } |
|
| 3007 | 3007 | |
| 3008 | - $this->set_prop( 'discounts', $value ); |
|
| 3008 | + $this->set_prop( 'discounts', $value ); |
|
| 3009 | 3009 | } |
| 3010 | 3010 | |
| 3011 | 3011 | /** |
| 3012 | - * Set the invoice items. |
|
| 3013 | - * |
|
| 3014 | - * @since 1.0.19 |
|
| 3015 | - * @param GetPaid_Form_Item[] $value items. |
|
| 3016 | - */ |
|
| 3017 | - public function set_items( $value ) { |
|
| 3012 | + * Set the invoice items. |
|
| 3013 | + * |
|
| 3014 | + * @since 1.0.19 |
|
| 3015 | + * @param GetPaid_Form_Item[] $value items. |
|
| 3016 | + */ |
|
| 3017 | + public function set_items( $value ) { |
|
| 3018 | 3018 | |
| 3019 | 3019 | // Remove existing items. |
| 3020 | 3020 | $this->set_prop( 'items', array() ); |
| 3021 | - $this->recurring_item = null; |
|
| 3021 | + $this->recurring_item = null; |
|
| 3022 | 3022 | |
| 3023 | 3023 | // Ensure that we have an array. |
| 3024 | 3024 | if ( ! is_array( $value ) ) { |
@@ -3031,105 +3031,105 @@ discard block |
||
| 3031 | 3031 | } |
| 3032 | 3032 | |
| 3033 | 3033 | /** |
| 3034 | - * Set the payment form. |
|
| 3035 | - * |
|
| 3036 | - * @since 1.0.19 |
|
| 3037 | - * @param int $value payment form. |
|
| 3038 | - */ |
|
| 3039 | - public function set_payment_form( $value ) { |
|
| 3040 | - $this->set_prop( 'payment_form', $value ); |
|
| 3034 | + * Set the payment form. |
|
| 3035 | + * |
|
| 3036 | + * @since 1.0.19 |
|
| 3037 | + * @param int $value payment form. |
|
| 3038 | + */ |
|
| 3039 | + public function set_payment_form( $value ) { |
|
| 3040 | + $this->set_prop( 'payment_form', $value ); |
|
| 3041 | 3041 | } |
| 3042 | 3042 | |
| 3043 | 3043 | /** |
| 3044 | - * Set the submission id. |
|
| 3045 | - * |
|
| 3046 | - * @since 1.0.19 |
|
| 3047 | - * @param string $value submission id. |
|
| 3048 | - */ |
|
| 3049 | - public function set_submission_id( $value ) { |
|
| 3050 | - $this->set_prop( 'submission_id', $value ); |
|
| 3044 | + * Set the submission id. |
|
| 3045 | + * |
|
| 3046 | + * @since 1.0.19 |
|
| 3047 | + * @param string $value submission id. |
|
| 3048 | + */ |
|
| 3049 | + public function set_submission_id( $value ) { |
|
| 3050 | + $this->set_prop( 'submission_id', $value ); |
|
| 3051 | 3051 | } |
| 3052 | 3052 | |
| 3053 | 3053 | /** |
| 3054 | - * Set the discount code. |
|
| 3055 | - * |
|
| 3056 | - * @since 1.0.19 |
|
| 3057 | - * @param string $value discount code. |
|
| 3058 | - */ |
|
| 3059 | - public function set_discount_code( $value ) { |
|
| 3060 | - $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
| 3054 | + * Set the discount code. |
|
| 3055 | + * |
|
| 3056 | + * @since 1.0.19 |
|
| 3057 | + * @param string $value discount code. |
|
| 3058 | + */ |
|
| 3059 | + public function set_discount_code( $value ) { |
|
| 3060 | + $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
| 3061 | 3061 | } |
| 3062 | 3062 | |
| 3063 | 3063 | /** |
| 3064 | - * Set the gateway. |
|
| 3065 | - * |
|
| 3066 | - * @since 1.0.19 |
|
| 3067 | - * @param string $value gateway. |
|
| 3068 | - */ |
|
| 3069 | - public function set_gateway( $value ) { |
|
| 3070 | - $this->set_prop( 'gateway', $value ); |
|
| 3064 | + * Set the gateway. |
|
| 3065 | + * |
|
| 3066 | + * @since 1.0.19 |
|
| 3067 | + * @param string $value gateway. |
|
| 3068 | + */ |
|
| 3069 | + public function set_gateway( $value ) { |
|
| 3070 | + $this->set_prop( 'gateway', $value ); |
|
| 3071 | 3071 | } |
| 3072 | 3072 | |
| 3073 | 3073 | /** |
| 3074 | - * Set the transaction id. |
|
| 3075 | - * |
|
| 3076 | - * @since 1.0.19 |
|
| 3077 | - * @param string $value transaction id. |
|
| 3078 | - */ |
|
| 3079 | - public function set_transaction_id( $value ) { |
|
| 3080 | - if ( ! empty( $value ) ) { |
|
| 3081 | - $this->set_prop( 'transaction_id', $value ); |
|
| 3082 | - } |
|
| 3074 | + * Set the transaction id. |
|
| 3075 | + * |
|
| 3076 | + * @since 1.0.19 |
|
| 3077 | + * @param string $value transaction id. |
|
| 3078 | + */ |
|
| 3079 | + public function set_transaction_id( $value ) { |
|
| 3080 | + if ( ! empty( $value ) ) { |
|
| 3081 | + $this->set_prop( 'transaction_id', $value ); |
|
| 3082 | + } |
|
| 3083 | 3083 | } |
| 3084 | 3084 | |
| 3085 | 3085 | /** |
| 3086 | - * Set the currency id. |
|
| 3087 | - * |
|
| 3088 | - * @since 1.0.19 |
|
| 3089 | - * @param string $value currency id. |
|
| 3090 | - */ |
|
| 3091 | - public function set_currency( $value ) { |
|
| 3092 | - $this->set_prop( 'currency', $value ); |
|
| 3086 | + * Set the currency id. |
|
| 3087 | + * |
|
| 3088 | + * @since 1.0.19 |
|
| 3089 | + * @param string $value currency id. |
|
| 3090 | + */ |
|
| 3091 | + public function set_currency( $value ) { |
|
| 3092 | + $this->set_prop( 'currency', $value ); |
|
| 3093 | 3093 | } |
| 3094 | 3094 | |
| 3095 | - /** |
|
| 3096 | - * Set whether to disable taxes. |
|
| 3097 | - * |
|
| 3098 | - * @since 1.0.19 |
|
| 3099 | - * @param bool $value value. |
|
| 3100 | - */ |
|
| 3101 | - public function set_disable_taxes( $value ) { |
|
| 3102 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 3103 | - } |
|
| 3095 | + /** |
|
| 3096 | + * Set whether to disable taxes. |
|
| 3097 | + * |
|
| 3098 | + * @since 1.0.19 |
|
| 3099 | + * @param bool $value value. |
|
| 3100 | + */ |
|
| 3101 | + public function set_disable_taxes( $value ) { |
|
| 3102 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 3103 | + } |
|
| 3104 | 3104 | |
| 3105 | 3105 | /** |
| 3106 | - * Set the subscription id. |
|
| 3107 | - * |
|
| 3108 | - * @since 1.0.19 |
|
| 3109 | - * @param string $value subscription id. |
|
| 3110 | - */ |
|
| 3111 | - public function set_subscription_id( $value ) { |
|
| 3112 | - $this->set_prop( 'subscription_id', $value ); |
|
| 3113 | - } |
|
| 3106 | + * Set the subscription id. |
|
| 3107 | + * |
|
| 3108 | + * @since 1.0.19 |
|
| 3109 | + * @param string $value subscription id. |
|
| 3110 | + */ |
|
| 3111 | + public function set_subscription_id( $value ) { |
|
| 3112 | + $this->set_prop( 'subscription_id', $value ); |
|
| 3113 | + } |
|
| 3114 | 3114 | |
| 3115 | - /** |
|
| 3116 | - * Set the remote subscription id. |
|
| 3117 | - * |
|
| 3118 | - * @since 1.0.19 |
|
| 3119 | - * @param string $value subscription id. |
|
| 3120 | - */ |
|
| 3121 | - public function set_remote_subscription_id( $value ) { |
|
| 3122 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
| 3115 | + /** |
|
| 3116 | + * Set the remote subscription id. |
|
| 3117 | + * |
|
| 3118 | + * @since 1.0.19 |
|
| 3119 | + * @param string $value subscription id. |
|
| 3120 | + */ |
|
| 3121 | + public function set_remote_subscription_id( $value ) { |
|
| 3122 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
| 3123 | 3123 | } |
| 3124 | 3124 | |
| 3125 | 3125 | /** |
| 3126 | - * Set the invoice anonymize status. |
|
| 3127 | - * |
|
| 3128 | - * @since 2.8.22 |
|
| 3129 | - * @param bool $is_anonymized is anonymized. |
|
| 3130 | - */ |
|
| 3131 | - public function set_is_anonymized( $is_anonymized ) { |
|
| 3132 | - $this->set_prop( 'is_anonymized', (bool) $is_anonymized ); |
|
| 3126 | + * Set the invoice anonymize status. |
|
| 3127 | + * |
|
| 3128 | + * @since 2.8.22 |
|
| 3129 | + * @param bool $is_anonymized is anonymized. |
|
| 3130 | + */ |
|
| 3131 | + public function set_is_anonymized( $is_anonymized ) { |
|
| 3132 | + $this->set_prop( 'is_anonymized', (bool) $is_anonymized ); |
|
| 3133 | 3133 | } |
| 3134 | 3134 | |
| 3135 | 3135 | /* |
@@ -3168,24 +3168,24 @@ discard block |
||
| 3168 | 3168 | */ |
| 3169 | 3169 | public function is_taxable() { |
| 3170 | 3170 | return ! $this->get_disable_taxes(); |
| 3171 | - } |
|
| 3171 | + } |
|
| 3172 | 3172 | |
| 3173 | - /** |
|
| 3174 | - * @deprecated |
|
| 3175 | - */ |
|
| 3176 | - public function has_vat() { |
|
| 3173 | + /** |
|
| 3174 | + * @deprecated |
|
| 3175 | + */ |
|
| 3176 | + public function has_vat() { |
|
| 3177 | 3177 | return $this->is_taxable(); |
| 3178 | - } |
|
| 3178 | + } |
|
| 3179 | 3179 | |
| 3180 | - /** |
|
| 3181 | - * Checks to see if the invoice requires payment. |
|
| 3182 | - */ |
|
| 3183 | - public function is_free() { |
|
| 3180 | + /** |
|
| 3181 | + * Checks to see if the invoice requires payment. |
|
| 3182 | + */ |
|
| 3183 | + public function is_free() { |
|
| 3184 | 3184 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
| 3185 | 3185 | |
| 3186 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 3187 | - $is_free = false; |
|
| 3188 | - } |
|
| 3186 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 3187 | + $is_free = false; |
|
| 3188 | + } |
|
| 3189 | 3189 | |
| 3190 | 3190 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
| 3191 | 3191 | } |
@@ -3196,46 +3196,46 @@ discard block |
||
| 3196 | 3196 | public function is_paid() { |
| 3197 | 3197 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
| 3198 | 3198 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
| 3199 | - } |
|
| 3199 | + } |
|
| 3200 | 3200 | |
| 3201 | - /** |
|
| 3201 | + /** |
|
| 3202 | 3202 | * Checks if the invoice needs payment. |
| 3203 | 3203 | */ |
| 3204 | - public function needs_payment() { |
|
| 3205 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 3204 | + public function needs_payment() { |
|
| 3205 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 3206 | 3206 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
| 3207 | 3207 | } |
| 3208 | 3208 | |
| 3209 | - /** |
|
| 3209 | + /** |
|
| 3210 | 3210 | * Checks if the invoice is refunded. |
| 3211 | 3211 | */ |
| 3212 | - public function is_refunded() { |
|
| 3212 | + public function is_refunded() { |
|
| 3213 | 3213 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
| 3214 | 3214 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
| 3215 | - } |
|
| 3215 | + } |
|
| 3216 | 3216 | |
| 3217 | - /** |
|
| 3217 | + /** |
|
| 3218 | 3218 | * Checks if the invoice is held. |
| 3219 | 3219 | */ |
| 3220 | - public function is_held() { |
|
| 3220 | + public function is_held() { |
|
| 3221 | 3221 | $is_held = $this->has_status( 'wpi-onhold' ); |
| 3222 | 3222 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
| 3223 | - } |
|
| 3223 | + } |
|
| 3224 | 3224 | |
| 3225 | - /** |
|
| 3225 | + /** |
|
| 3226 | 3226 | * Checks if the invoice is due. |
| 3227 | 3227 | */ |
| 3228 | - public function is_due() { |
|
| 3229 | - $due_date = $this->get_due_date(); |
|
| 3230 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3231 | - } |
|
| 3228 | + public function is_due() { |
|
| 3229 | + $due_date = $this->get_due_date(); |
|
| 3230 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3231 | + } |
|
| 3232 | 3232 | |
| 3233 | - /** |
|
| 3233 | + /** |
|
| 3234 | 3234 | * Checks if the invoice is draft. |
| 3235 | 3235 | */ |
| 3236 | - public function is_draft() { |
|
| 3236 | + public function is_draft() { |
|
| 3237 | 3237 | return $this->has_status( 'draft, auto-draft' ); |
| 3238 | - } |
|
| 3238 | + } |
|
| 3239 | 3239 | |
| 3240 | 3240 | /** |
| 3241 | 3241 | * Checks if the invoice has a given status. |
@@ -3243,9 +3243,9 @@ discard block |
||
| 3243 | 3243 | public function has_status( $status ) { |
| 3244 | 3244 | $status = wpinv_parse_list( $status ); |
| 3245 | 3245 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
| 3246 | - } |
|
| 3246 | + } |
|
| 3247 | 3247 | |
| 3248 | - /** |
|
| 3248 | + /** |
|
| 3249 | 3249 | * Checks if the invoice is of a given type. |
| 3250 | 3250 | */ |
| 3251 | 3251 | public function is_type( $type ) { |
@@ -3268,25 +3268,25 @@ discard block |
||
| 3268 | 3268 | */ |
| 3269 | 3269 | public function has_free_trial() { |
| 3270 | 3270 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
| 3271 | - } |
|
| 3271 | + } |
|
| 3272 | 3272 | |
| 3273 | - /** |
|
| 3273 | + /** |
|
| 3274 | 3274 | * @deprecated |
| 3275 | 3275 | */ |
| 3276 | 3276 | public function is_free_trial() { |
| 3277 | 3277 | return $this->has_free_trial(); |
| 3278 | 3278 | } |
| 3279 | 3279 | |
| 3280 | - /** |
|
| 3280 | + /** |
|
| 3281 | 3281 | * Check if the initial payment if 0. |
| 3282 | 3282 | * |
| 3283 | 3283 | */ |
| 3284 | - public function is_initial_free() { |
|
| 3284 | + public function is_initial_free() { |
|
| 3285 | 3285 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
| 3286 | 3286 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
| 3287 | 3287 | } |
| 3288 | 3288 | |
| 3289 | - /** |
|
| 3289 | + /** |
|
| 3290 | 3290 | * Check if the recurring item has a free trial. |
| 3291 | 3291 | * |
| 3292 | 3292 | */ |
@@ -3299,14 +3299,14 @@ discard block |
||
| 3299 | 3299 | |
| 3300 | 3300 | $item = $this->get_recurring( true ); |
| 3301 | 3301 | return $item->has_free_trial(); |
| 3302 | - } |
|
| 3302 | + } |
|
| 3303 | 3303 | |
| 3304 | - /** |
|
| 3304 | + /** |
|
| 3305 | 3305 | * Check if the free trial is a result of a discount. |
| 3306 | 3306 | */ |
| 3307 | 3307 | public function is_free_trial_from_discount() { |
| 3308 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3309 | - } |
|
| 3308 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3309 | + } |
|
| 3310 | 3310 | |
| 3311 | 3311 | /** |
| 3312 | 3312 | * Checks if this is an anonymized invoice. |
@@ -3317,12 +3317,12 @@ discard block |
||
| 3317 | 3317 | return true === (bool) $this->get_is_anonymized(); |
| 3318 | 3318 | } |
| 3319 | 3319 | |
| 3320 | - /** |
|
| 3320 | + /** |
|
| 3321 | 3321 | * @deprecated |
| 3322 | 3322 | */ |
| 3323 | 3323 | public function discount_first_payment_only() { |
| 3324 | 3324 | |
| 3325 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3325 | + $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3326 | 3326 | if ( ! $discount->exists() || ! $this->is_recurring() ) { |
| 3327 | 3327 | return true; |
| 3328 | 3328 | } |
@@ -3347,143 +3347,143 @@ discard block |
||
| 3347 | 3347 | */ |
| 3348 | 3348 | public function add_item( $item ) { |
| 3349 | 3349 | |
| 3350 | - if ( is_array( $item ) ) { |
|
| 3351 | - $item = $this->process_array_item( $item ); |
|
| 3352 | - } |
|
| 3350 | + if ( is_array( $item ) ) { |
|
| 3351 | + $item = $this->process_array_item( $item ); |
|
| 3352 | + } |
|
| 3353 | 3353 | |
| 3354 | - if ( is_numeric( $item ) ) { |
|
| 3355 | - $item = new GetPaid_Form_Item( $item ); |
|
| 3356 | - } |
|
| 3354 | + if ( is_numeric( $item ) ) { |
|
| 3355 | + $item = new GetPaid_Form_Item( $item ); |
|
| 3356 | + } |
|
| 3357 | 3357 | |
| 3358 | 3358 | // Make sure that it is available for purchase. |
| 3359 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3360 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3359 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3360 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3361 | 3361 | } |
| 3362 | 3362 | |
| 3363 | 3363 | // Do we have a recurring item? |
| 3364 | - if ( $item->is_recurring() ) { |
|
| 3365 | - $this->recurring_item = $item->get_id(); |
|
| 3364 | + if ( $item->is_recurring() ) { |
|
| 3365 | + $this->recurring_item = $item->get_id(); |
|
| 3366 | 3366 | } |
| 3367 | 3367 | |
| 3368 | 3368 | // Invoice id. |
| 3369 | 3369 | $item->invoice_id = (int) $this->get_id(); |
| 3370 | 3370 | |
| 3371 | - // Remove duplicates. |
|
| 3372 | - $this->remove_item( $item->get_id() ); |
|
| 3371 | + // Remove duplicates. |
|
| 3372 | + $this->remove_item( $item->get_id() ); |
|
| 3373 | 3373 | |
| 3374 | - if ( 0 == $item->get_quantity() ) { |
|
| 3375 | - return; |
|
| 3376 | - } |
|
| 3374 | + if ( 0 == $item->get_quantity() ) { |
|
| 3375 | + return; |
|
| 3376 | + } |
|
| 3377 | 3377 | |
| 3378 | - // Retrieve all items. |
|
| 3378 | + // Retrieve all items. |
|
| 3379 | 3379 | $items = $this->get_items(); |
| 3380 | 3380 | |
| 3381 | - // Add new item. |
|
| 3381 | + // Add new item. |
|
| 3382 | 3382 | $items[] = $item; |
| 3383 | 3383 | |
| 3384 | 3384 | $this->set_prop( 'items', $items ); |
| 3385 | 3385 | |
| 3386 | - return true; |
|
| 3387 | - } |
|
| 3388 | - |
|
| 3389 | - /** |
|
| 3390 | - * Converts an array to an item. |
|
| 3391 | - * |
|
| 3392 | - * @since 1.0.19 |
|
| 3393 | - * @return GetPaid_Form_Item |
|
| 3394 | - */ |
|
| 3395 | - protected function process_array_item( $array ) { |
|
| 3396 | - |
|
| 3397 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3398 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 3399 | - |
|
| 3400 | - // Set item data. |
|
| 3401 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3402 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3403 | - $method = "set_$key"; |
|
| 3404 | - $item->$method( $array[ "item_$key" ] ); |
|
| 3405 | - } |
|
| 3406 | - } |
|
| 3407 | - |
|
| 3408 | - if ( isset( $array['quantity'] ) ) { |
|
| 3409 | - $item->set_quantity( $array['quantity'] ); |
|
| 3410 | - } |
|
| 3411 | - |
|
| 3412 | - // Set item meta. |
|
| 3413 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3414 | - $item->set_item_meta( $array['meta'] ); |
|
| 3415 | - } |
|
| 3416 | - |
|
| 3417 | - return $item; |
|
| 3418 | - } |
|
| 3419 | - |
|
| 3420 | - /** |
|
| 3421 | - * Retrieves a specific item. |
|
| 3422 | - * |
|
| 3423 | - * @since 1.0.19 |
|
| 3424 | - * @return GetPaid_Form_Item|null |
|
| 3425 | - */ |
|
| 3426 | - public function get_item( $item_id ) { |
|
| 3427 | - |
|
| 3428 | - foreach ( $this->get_items() as $item ) { |
|
| 3429 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3430 | - return $item; |
|
| 3431 | - } |
|
| 3432 | - } |
|
| 3433 | - |
|
| 3434 | - return null; |
|
| 3435 | - } |
|
| 3436 | - |
|
| 3437 | - /** |
|
| 3438 | - * Removes a specific item. |
|
| 3439 | - * |
|
| 3440 | - * @since 1.0.19 |
|
| 3441 | - */ |
|
| 3442 | - public function remove_item( $item_id ) { |
|
| 3443 | - $items = $this->get_items(); |
|
| 3444 | - $item_id = (int) $item_id; |
|
| 3445 | - |
|
| 3446 | - foreach ( $items as $index => $item ) { |
|
| 3447 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3448 | - unset( $items[ $index ] ); |
|
| 3449 | - $this->set_prop( 'items', $items ); |
|
| 3450 | - |
|
| 3451 | - if ( $item_id == $this->recurring_item ) { |
|
| 3452 | - $this->recurring_item = null; |
|
| 3453 | - } |
|
| 3386 | + return true; |
|
| 3387 | + } |
|
| 3388 | + |
|
| 3389 | + /** |
|
| 3390 | + * Converts an array to an item. |
|
| 3391 | + * |
|
| 3392 | + * @since 1.0.19 |
|
| 3393 | + * @return GetPaid_Form_Item |
|
| 3394 | + */ |
|
| 3395 | + protected function process_array_item( $array ) { |
|
| 3396 | + |
|
| 3397 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3398 | + $item = new GetPaid_Form_Item( $item_id ); |
|
| 3399 | + |
|
| 3400 | + // Set item data. |
|
| 3401 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3402 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3403 | + $method = "set_$key"; |
|
| 3404 | + $item->$method( $array[ "item_$key" ] ); |
|
| 3405 | + } |
|
| 3406 | + } |
|
| 3407 | + |
|
| 3408 | + if ( isset( $array['quantity'] ) ) { |
|
| 3409 | + $item->set_quantity( $array['quantity'] ); |
|
| 3410 | + } |
|
| 3411 | + |
|
| 3412 | + // Set item meta. |
|
| 3413 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3414 | + $item->set_item_meta( $array['meta'] ); |
|
| 3415 | + } |
|
| 3416 | + |
|
| 3417 | + return $item; |
|
| 3418 | + } |
|
| 3419 | + |
|
| 3420 | + /** |
|
| 3421 | + * Retrieves a specific item. |
|
| 3422 | + * |
|
| 3423 | + * @since 1.0.19 |
|
| 3424 | + * @return GetPaid_Form_Item|null |
|
| 3425 | + */ |
|
| 3426 | + public function get_item( $item_id ) { |
|
| 3427 | + |
|
| 3428 | + foreach ( $this->get_items() as $item ) { |
|
| 3429 | + if ( (int) $item_id == $item->get_id() ) { |
|
| 3430 | + return $item; |
|
| 3431 | + } |
|
| 3432 | + } |
|
| 3433 | + |
|
| 3434 | + return null; |
|
| 3435 | + } |
|
| 3436 | + |
|
| 3437 | + /** |
|
| 3438 | + * Removes a specific item. |
|
| 3439 | + * |
|
| 3440 | + * @since 1.0.19 |
|
| 3441 | + */ |
|
| 3442 | + public function remove_item( $item_id ) { |
|
| 3443 | + $items = $this->get_items(); |
|
| 3444 | + $item_id = (int) $item_id; |
|
| 3445 | + |
|
| 3446 | + foreach ( $items as $index => $item ) { |
|
| 3447 | + if ( (int) $item_id == $item->get_id() ) { |
|
| 3448 | + unset( $items[ $index ] ); |
|
| 3449 | + $this->set_prop( 'items', $items ); |
|
| 3450 | + |
|
| 3451 | + if ( $item_id == $this->recurring_item ) { |
|
| 3452 | + $this->recurring_item = null; |
|
| 3453 | + } |
|
| 3454 | 3454 | } |
| 3455 | - } |
|
| 3455 | + } |
|
| 3456 | 3456 | } |
| 3457 | 3457 | |
| 3458 | 3458 | /** |
| 3459 | - * Adds a fee to the invoice. |
|
| 3460 | - * |
|
| 3461 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3462 | - * @since 1.0.19 |
|
| 3463 | - */ |
|
| 3459 | + * Adds a fee to the invoice. |
|
| 3460 | + * |
|
| 3461 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3462 | + * @since 1.0.19 |
|
| 3463 | + */ |
|
| 3464 | 3464 | public function add_fee( $fee ) { |
| 3465 | 3465 | |
| 3466 | - $fees = $this->get_fees(); |
|
| 3467 | - $fees[ $fee['name'] ] = $fee; |
|
| 3468 | - $this->set_prop( 'fees', $fees ); |
|
| 3466 | + $fees = $this->get_fees(); |
|
| 3467 | + $fees[ $fee['name'] ] = $fee; |
|
| 3468 | + $this->set_prop( 'fees', $fees ); |
|
| 3469 | 3469 | } |
| 3470 | 3470 | |
| 3471 | 3471 | /** |
| 3472 | - * Retrieves a specific fee. |
|
| 3473 | - * |
|
| 3474 | - * @since 1.0.19 |
|
| 3475 | - */ |
|
| 3476 | - public function get_fee( $fee ) { |
|
| 3472 | + * Retrieves a specific fee. |
|
| 3473 | + * |
|
| 3474 | + * @since 1.0.19 |
|
| 3475 | + */ |
|
| 3476 | + public function get_fee( $fee ) { |
|
| 3477 | 3477 | $fees = $this->get_fees(); |
| 3478 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3478 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3479 | 3479 | } |
| 3480 | 3480 | |
| 3481 | 3481 | /** |
| 3482 | - * Removes a specific fee. |
|
| 3483 | - * |
|
| 3484 | - * @since 1.0.19 |
|
| 3485 | - */ |
|
| 3486 | - public function remove_fee( $fee ) { |
|
| 3482 | + * Removes a specific fee. |
|
| 3483 | + * |
|
| 3484 | + * @since 1.0.19 |
|
| 3485 | + */ |
|
| 3486 | + public function remove_fee( $fee ) { |
|
| 3487 | 3487 | $fees = $this->get_fees(); |
| 3488 | 3488 | if ( isset( $fees[ $fee ] ) ) { |
| 3489 | 3489 | unset( $fees[ $fee ] ); |
@@ -3491,54 +3491,54 @@ discard block |
||
| 3491 | 3491 | } |
| 3492 | 3492 | } |
| 3493 | 3493 | |
| 3494 | - /** |
|
| 3495 | - * Adds a discount to the invoice. |
|
| 3496 | - * |
|
| 3497 | - * @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. |
|
| 3498 | - * @since 1.0.19 |
|
| 3499 | - */ |
|
| 3500 | - public function add_discount( $discount ) { |
|
| 3494 | + /** |
|
| 3495 | + * Adds a discount to the invoice. |
|
| 3496 | + * |
|
| 3497 | + * @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. |
|
| 3498 | + * @since 1.0.19 |
|
| 3499 | + */ |
|
| 3500 | + public function add_discount( $discount ) { |
|
| 3501 | 3501 | |
| 3502 | - $discounts = $this->get_discounts(); |
|
| 3503 | - $discounts[ $discount['name'] ] = $discount; |
|
| 3504 | - $this->set_prop( 'discounts', $discounts ); |
|
| 3505 | - } |
|
| 3502 | + $discounts = $this->get_discounts(); |
|
| 3503 | + $discounts[ $discount['name'] ] = $discount; |
|
| 3504 | + $this->set_prop( 'discounts', $discounts ); |
|
| 3505 | + } |
|
| 3506 | 3506 | |
| 3507 | 3507 | /** |
| 3508 | - * Retrieves a specific discount. |
|
| 3509 | - * |
|
| 3510 | - * @since 1.0.19 |
|
| 3511 | - * @return float |
|
| 3512 | - */ |
|
| 3513 | - public function get_discount( $discount = false ) { |
|
| 3508 | + * Retrieves a specific discount. |
|
| 3509 | + * |
|
| 3510 | + * @since 1.0.19 |
|
| 3511 | + * @return float |
|
| 3512 | + */ |
|
| 3513 | + public function get_discount( $discount = false ) { |
|
| 3514 | 3514 | |
| 3515 | - // Backwards compatibility. |
|
| 3516 | - if ( empty( $discount ) ) { |
|
| 3517 | - return $this->get_total_discount(); |
|
| 3518 | - } |
|
| 3515 | + // Backwards compatibility. |
|
| 3516 | + if ( empty( $discount ) ) { |
|
| 3517 | + return $this->get_total_discount(); |
|
| 3518 | + } |
|
| 3519 | 3519 | |
| 3520 | 3520 | $discounts = $this->get_discounts(); |
| 3521 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3521 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3522 | 3522 | } |
| 3523 | 3523 | |
| 3524 | 3524 | /** |
| 3525 | - * Removes a specific discount. |
|
| 3526 | - * |
|
| 3527 | - * @since 1.0.19 |
|
| 3528 | - */ |
|
| 3529 | - public function remove_discount( $discount ) { |
|
| 3525 | + * Removes a specific discount. |
|
| 3526 | + * |
|
| 3527 | + * @since 1.0.19 |
|
| 3528 | + */ |
|
| 3529 | + public function remove_discount( $discount ) { |
|
| 3530 | 3530 | $discounts = $this->get_discounts(); |
| 3531 | 3531 | if ( isset( $discounts[ $discount ] ) ) { |
| 3532 | 3532 | unset( $discounts[ $discount ] ); |
| 3533 | 3533 | $this->set_prop( 'discounts', $discounts ); |
| 3534 | 3534 | } |
| 3535 | 3535 | |
| 3536 | - if ( 'discount_code' == $discount ) { |
|
| 3537 | - foreach ( $this->get_items() as $item ) { |
|
| 3538 | - $item->item_discount = 0; |
|
| 3539 | - $item->recurring_item_discount = 0; |
|
| 3540 | - } |
|
| 3541 | - } |
|
| 3536 | + if ( 'discount_code' == $discount ) { |
|
| 3537 | + foreach ( $this->get_items() as $item ) { |
|
| 3538 | + $item->item_discount = 0; |
|
| 3539 | + $item->recurring_item_discount = 0; |
|
| 3540 | + } |
|
| 3541 | + } |
|
| 3542 | 3542 | } |
| 3543 | 3543 | |
| 3544 | 3544 | /** |
@@ -3550,116 +3550,116 @@ discard block |
||
| 3550 | 3550 | if ( $this->is_taxable() ) { |
| 3551 | 3551 | |
| 3552 | 3552 | $taxes = $this->get_taxes(); |
| 3553 | - $taxes[ $tax['name'] ] = $tax; |
|
| 3554 | - $this->set_prop( 'taxes', $tax ); |
|
| 3553 | + $taxes[ $tax['name'] ] = $tax; |
|
| 3554 | + $this->set_prop( 'taxes', $tax ); |
|
| 3555 | 3555 | |
| 3556 | 3556 | } |
| 3557 | 3557 | } |
| 3558 | 3558 | |
| 3559 | 3559 | /** |
| 3560 | - * Retrieves a specific tax. |
|
| 3561 | - * |
|
| 3562 | - * @since 1.0.19 |
|
| 3563 | - */ |
|
| 3564 | - public function get_tax( $tax = null ) { |
|
| 3560 | + * Retrieves a specific tax. |
|
| 3561 | + * |
|
| 3562 | + * @since 1.0.19 |
|
| 3563 | + */ |
|
| 3564 | + public function get_tax( $tax = null ) { |
|
| 3565 | 3565 | |
| 3566 | - // Backwards compatibility. |
|
| 3567 | - if ( empty( $tax ) ) { |
|
| 3568 | - return $this->get_total_tax(); |
|
| 3569 | - } |
|
| 3566 | + // Backwards compatibility. |
|
| 3567 | + if ( empty( $tax ) ) { |
|
| 3568 | + return $this->get_total_tax(); |
|
| 3569 | + } |
|
| 3570 | 3570 | |
| 3571 | 3571 | $taxes = $this->get_taxes(); |
| 3572 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3572 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3573 | 3573 | } |
| 3574 | 3574 | |
| 3575 | - public function get_tax_total_by_name( $name ) { |
|
| 3576 | - if ( $name && 0 === strpos( $name, 'tax__' ) ) { |
|
| 3577 | - $name = str_replace( 'tax__', '', $name ); |
|
| 3578 | - } |
|
| 3575 | + public function get_tax_total_by_name( $name ) { |
|
| 3576 | + if ( $name && 0 === strpos( $name, 'tax__' ) ) { |
|
| 3577 | + $name = str_replace( 'tax__', '', $name ); |
|
| 3578 | + } |
|
| 3579 | 3579 | |
| 3580 | - if ( empty( $name ) ) { |
|
| 3581 | - return 0; |
|
| 3582 | - } |
|
| 3580 | + if ( empty( $name ) ) { |
|
| 3581 | + return 0; |
|
| 3582 | + } |
|
| 3583 | 3583 | |
| 3584 | - $tax = $this->get_tax( $name ); |
|
| 3584 | + $tax = $this->get_tax( $name ); |
|
| 3585 | 3585 | |
| 3586 | - if ( empty( $tax ) ) { |
|
| 3587 | - return 0; |
|
| 3588 | - } |
|
| 3586 | + if ( empty( $tax ) ) { |
|
| 3587 | + return 0; |
|
| 3588 | + } |
|
| 3589 | 3589 | |
| 3590 | 3590 | return $this->is_renewal() ? $tax['recurring_tax'] : $tax['initial_tax']; |
| 3591 | 3591 | } |
| 3592 | 3592 | |
| 3593 | - /** |
|
| 3594 | - * Get tax item name. |
|
| 3595 | - * |
|
| 3596 | - * @since 2.8.8 |
|
| 3597 | - */ |
|
| 3598 | - public function get_tax_item_name( $tax_key, $tax_item, $suffix = '' ) { |
|
| 3599 | - $tax_name = _x( 'Tax', 'Tax name', 'invoicing' ); |
|
| 3593 | + /** |
|
| 3594 | + * Get tax item name. |
|
| 3595 | + * |
|
| 3596 | + * @since 2.8.8 |
|
| 3597 | + */ |
|
| 3598 | + public function get_tax_item_name( $tax_key, $tax_item, $suffix = '' ) { |
|
| 3599 | + $tax_name = _x( 'Tax', 'Tax name', 'invoicing' ); |
|
| 3600 | 3600 | |
| 3601 | - if ( ! empty( $tax_item ) && is_array( $tax_item ) && ! empty( $tax_item['name'] ) ) { |
|
| 3602 | - $tax_name = __( $tax_item['name'], 'invoicing' ); |
|
| 3603 | - } |
|
| 3601 | + if ( ! empty( $tax_item ) && is_array( $tax_item ) && ! empty( $tax_item['name'] ) ) { |
|
| 3602 | + $tax_name = __( $tax_item['name'], 'invoicing' ); |
|
| 3603 | + } |
|
| 3604 | 3604 | |
| 3605 | - if ( $suffix ) { |
|
| 3606 | - $tax_name .= $suffix; |
|
| 3607 | - } |
|
| 3605 | + if ( $suffix ) { |
|
| 3606 | + $tax_name .= $suffix; |
|
| 3607 | + } |
|
| 3608 | 3608 | |
| 3609 | - return apply_filters( 'wpinv_invoice_get_tax_name', $tax_name, $this, $tax_key, $tax_item, $suffix ); |
|
| 3610 | - } |
|
| 3609 | + return apply_filters( 'wpinv_invoice_get_tax_name', $tax_name, $this, $tax_key, $tax_item, $suffix ); |
|
| 3610 | + } |
|
| 3611 | 3611 | |
| 3612 | - /** |
|
| 3613 | - * Get tax item amount. |
|
| 3614 | - * |
|
| 3615 | - * @since 2.8.8 |
|
| 3616 | - */ |
|
| 3617 | - public function get_tax_item_amount( $tax_key, $tax_item, $with_currency = false ) { |
|
| 3618 | - $tax_amount = $this->get_tax_total_by_name( $tax_key ); |
|
| 3612 | + /** |
|
| 3613 | + * Get tax item amount. |
|
| 3614 | + * |
|
| 3615 | + * @since 2.8.8 |
|
| 3616 | + */ |
|
| 3617 | + public function get_tax_item_amount( $tax_key, $tax_item, $with_currency = false ) { |
|
| 3618 | + $tax_amount = $this->get_tax_total_by_name( $tax_key ); |
|
| 3619 | 3619 | |
| 3620 | - if ( $with_currency ) { |
|
| 3621 | - $tax_amount = wpinv_price( $tax_amount, $this->get_currency() ); |
|
| 3622 | - } |
|
| 3620 | + if ( $with_currency ) { |
|
| 3621 | + $tax_amount = wpinv_price( $tax_amount, $this->get_currency() ); |
|
| 3622 | + } |
|
| 3623 | 3623 | |
| 3624 | - return apply_filters( 'wpinv_invoice_get_tax_amount', $tax_amount, $this, $tax_item, $with_currency ); |
|
| 3625 | - } |
|
| 3624 | + return apply_filters( 'wpinv_invoice_get_tax_amount', $tax_amount, $this, $tax_item, $with_currency ); |
|
| 3625 | + } |
|
| 3626 | 3626 | |
| 3627 | - public function get_item_tax_name( $percentage = true, $sep = ' + ' ) { |
|
| 3628 | - $taxes = $this->get_taxes(); |
|
| 3627 | + public function get_item_tax_name( $percentage = true, $sep = ' + ' ) { |
|
| 3628 | + $taxes = $this->get_taxes(); |
|
| 3629 | 3629 | |
| 3630 | - if ( ! empty( $taxes ) && is_array( $taxes ) && count( $taxes ) == 1 && wpinv_display_individual_tax_rates() ) { |
|
| 3631 | - $names = array(); |
|
| 3630 | + if ( ! empty( $taxes ) && is_array( $taxes ) && count( $taxes ) == 1 && wpinv_display_individual_tax_rates() ) { |
|
| 3631 | + $names = array(); |
|
| 3632 | 3632 | |
| 3633 | - foreach ( $taxes as $key => $tax ) { |
|
| 3634 | - if ( ! empty( $tax ) && ! empty( $tax['name'] ) ) { |
|
| 3635 | - $name = __( $tax['name'], 'invoicing' ); |
|
| 3633 | + foreach ( $taxes as $key => $tax ) { |
|
| 3634 | + if ( ! empty( $tax ) && ! empty( $tax['name'] ) ) { |
|
| 3635 | + $name = __( $tax['name'], 'invoicing' ); |
|
| 3636 | 3636 | |
| 3637 | - $names[] = $name; |
|
| 3638 | - } |
|
| 3639 | - } |
|
| 3637 | + $names[] = $name; |
|
| 3638 | + } |
|
| 3639 | + } |
|
| 3640 | 3640 | |
| 3641 | - if ( ! empty( $names ) ) { |
|
| 3642 | - $names = array_unique( $names ); |
|
| 3641 | + if ( ! empty( $names ) ) { |
|
| 3642 | + $names = array_unique( $names ); |
|
| 3643 | 3643 | |
| 3644 | - $tax_name = implode( $sep, $names ); |
|
| 3645 | - } |
|
| 3644 | + $tax_name = implode( $sep, $names ); |
|
| 3645 | + } |
|
| 3646 | 3646 | |
| 3647 | - if ( $percentage ) { |
|
| 3648 | - $tax_name = wp_sprintf( _x( '%s (%%)', 'Tax name with %. Ex: Tax (%)', 'invoicing' ), $tax_name ); |
|
| 3649 | - } |
|
| 3650 | - } else { |
|
| 3651 | - $tax_name = $percentage ? __( 'Tax (%)', 'invoicing' ) : _x( 'Tax', 'Tax name', 'invoicing' ); |
|
| 3652 | - } |
|
| 3647 | + if ( $percentage ) { |
|
| 3648 | + $tax_name = wp_sprintf( _x( '%s (%%)', 'Tax name with %. Ex: Tax (%)', 'invoicing' ), $tax_name ); |
|
| 3649 | + } |
|
| 3650 | + } else { |
|
| 3651 | + $tax_name = $percentage ? __( 'Tax (%)', 'invoicing' ) : _x( 'Tax', 'Tax name', 'invoicing' ); |
|
| 3652 | + } |
|
| 3653 | 3653 | |
| 3654 | - return apply_filters( 'wpinv_invoice_get_item_tax_name', $tax_name, $this, $percentage, $sep ); |
|
| 3655 | - } |
|
| 3654 | + return apply_filters( 'wpinv_invoice_get_item_tax_name', $tax_name, $this, $percentage, $sep ); |
|
| 3655 | + } |
|
| 3656 | 3656 | |
| 3657 | 3657 | /** |
| 3658 | - * Removes a specific tax. |
|
| 3659 | - * |
|
| 3660 | - * @since 1.0.19 |
|
| 3661 | - */ |
|
| 3662 | - public function remove_tax( $tax ) { |
|
| 3658 | + * Removes a specific tax. |
|
| 3659 | + * |
|
| 3660 | + * @since 1.0.19 |
|
| 3661 | + */ |
|
| 3662 | + public function remove_tax( $tax ) { |
|
| 3663 | 3663 | $taxes = $this->get_taxes(); |
| 3664 | 3664 | if ( isset( $taxes[ $tax ] ) ) { |
| 3665 | 3665 | unset( $taxes[ $tax ] ); |
@@ -3668,191 +3668,191 @@ discard block |
||
| 3668 | 3668 | } |
| 3669 | 3669 | |
| 3670 | 3670 | /** |
| 3671 | - * Recalculates the invoice subtotal. |
|
| 3672 | - * |
|
| 3673 | - * @since 1.0.19 |
|
| 3674 | - * @return float The recalculated subtotal |
|
| 3675 | - */ |
|
| 3676 | - public function recalculate_subtotal() { |
|
| 3671 | + * Recalculates the invoice subtotal. |
|
| 3672 | + * |
|
| 3673 | + * @since 1.0.19 |
|
| 3674 | + * @return float The recalculated subtotal |
|
| 3675 | + */ |
|
| 3676 | + public function recalculate_subtotal() { |
|
| 3677 | 3677 | $items = $this->get_items(); |
| 3678 | - $subtotal = 0; |
|
| 3679 | - $recurring = 0; |
|
| 3678 | + $subtotal = 0; |
|
| 3679 | + $recurring = 0; |
|
| 3680 | 3680 | |
| 3681 | 3681 | foreach ( $items as $item ) { |
| 3682 | - $subtotal += $item->get_sub_total( 'edit' ); |
|
| 3683 | - $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
| 3682 | + $subtotal += $item->get_sub_total( 'edit' ); |
|
| 3683 | + $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
| 3684 | 3684 | } |
| 3685 | 3685 | |
| 3686 | - if ( wpinv_prices_include_tax() ) { |
|
| 3687 | - $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
| 3688 | - $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
| 3689 | - } |
|
| 3686 | + if ( wpinv_prices_include_tax() ) { |
|
| 3687 | + $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
| 3688 | + $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
| 3689 | + } |
|
| 3690 | 3690 | |
| 3691 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3692 | - $this->set_subtotal( $current ); |
|
| 3691 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3692 | + $this->set_subtotal( $current ); |
|
| 3693 | 3693 | |
| 3694 | - $this->totals['subtotal'] = array( |
|
| 3695 | - 'initial' => $subtotal, |
|
| 3696 | - 'recurring' => $recurring, |
|
| 3697 | - ); |
|
| 3694 | + $this->totals['subtotal'] = array( |
|
| 3695 | + 'initial' => $subtotal, |
|
| 3696 | + 'recurring' => $recurring, |
|
| 3697 | + ); |
|
| 3698 | 3698 | |
| 3699 | 3699 | return $current; |
| 3700 | 3700 | } |
| 3701 | 3701 | |
| 3702 | 3702 | /** |
| 3703 | - * Recalculates the invoice discount total. |
|
| 3704 | - * |
|
| 3705 | - * @since 1.0.19 |
|
| 3706 | - * @return float The recalculated discount |
|
| 3707 | - */ |
|
| 3708 | - public function recalculate_total_discount() { |
|
| 3709 | - // Fix renewal invoice amount when tax + recurring discount applied. |
|
| 3710 | - if ( $this->is_renewal() && $this->get_discount_code() ) { |
|
| 3711 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 3712 | - $discount = new WPInv_Discount( $this->get_discount_code() ); |
|
| 3713 | - |
|
| 3714 | - if ( $discount->exists() && $discount->is_recurring() ) { |
|
| 3715 | - getpaid_calculate_invoice_discount( $this, $discount ); |
|
| 3716 | - } |
|
| 3717 | - } |
|
| 3703 | + * Recalculates the invoice discount total. |
|
| 3704 | + * |
|
| 3705 | + * @since 1.0.19 |
|
| 3706 | + * @return float The recalculated discount |
|
| 3707 | + */ |
|
| 3708 | + public function recalculate_total_discount() { |
|
| 3709 | + // Fix renewal invoice amount when tax + recurring discount applied. |
|
| 3710 | + if ( $this->is_renewal() && $this->get_discount_code() ) { |
|
| 3711 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 3712 | + $discount = new WPInv_Discount( $this->get_discount_code() ); |
|
| 3713 | + |
|
| 3714 | + if ( $discount->exists() && $discount->is_recurring() ) { |
|
| 3715 | + getpaid_calculate_invoice_discount( $this, $discount ); |
|
| 3716 | + } |
|
| 3717 | + } |
|
| 3718 | 3718 | |
| 3719 | - $discounts = $this->get_discounts(); |
|
| 3720 | - $discount = 0; |
|
| 3721 | - $recurring = 0; |
|
| 3719 | + $discounts = $this->get_discounts(); |
|
| 3720 | + $discount = 0; |
|
| 3721 | + $recurring = 0; |
|
| 3722 | 3722 | |
| 3723 | 3723 | foreach ( $discounts as $data ) { |
| 3724 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3725 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3726 | - } |
|
| 3724 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3725 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3726 | + } |
|
| 3727 | 3727 | |
| 3728 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3728 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3729 | 3729 | |
| 3730 | - $this->set_total_discount( $current ); |
|
| 3730 | + $this->set_total_discount( $current ); |
|
| 3731 | 3731 | |
| 3732 | - $this->totals['discount'] = array( |
|
| 3733 | - 'initial' => $discount, |
|
| 3734 | - 'recurring' => $recurring, |
|
| 3735 | - ); |
|
| 3732 | + $this->totals['discount'] = array( |
|
| 3733 | + 'initial' => $discount, |
|
| 3734 | + 'recurring' => $recurring, |
|
| 3735 | + ); |
|
| 3736 | 3736 | |
| 3737 | - return $current; |
|
| 3737 | + return $current; |
|
| 3738 | 3738 | } |
| 3739 | 3739 | |
| 3740 | 3740 | /** |
| 3741 | - * Recalculates the invoice tax total. |
|
| 3742 | - * |
|
| 3743 | - * @since 1.0.19 |
|
| 3744 | - * @return float The recalculated tax |
|
| 3745 | - */ |
|
| 3746 | - public function recalculate_total_tax() { |
|
| 3741 | + * Recalculates the invoice tax total. |
|
| 3742 | + * |
|
| 3743 | + * @since 1.0.19 |
|
| 3744 | + * @return float The recalculated tax |
|
| 3745 | + */ |
|
| 3746 | + public function recalculate_total_tax() { |
|
| 3747 | 3747 | |
| 3748 | - // Maybe disable taxes. |
|
| 3749 | - $vat_number = $this->get_vat_number(); |
|
| 3750 | - $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
| 3748 | + // Maybe disable taxes. |
|
| 3749 | + $vat_number = $this->get_vat_number(); |
|
| 3750 | + $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
| 3751 | 3751 | |
| 3752 | - if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 3753 | - $skip_tax = false; |
|
| 3754 | - } |
|
| 3752 | + if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 3753 | + $skip_tax = false; |
|
| 3754 | + } |
|
| 3755 | 3755 | |
| 3756 | - if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
| 3756 | + if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
| 3757 | 3757 | |
| 3758 | - $this->totals['tax'] = array( |
|
| 3759 | - 'initial' => 0, |
|
| 3760 | - 'recurring' => 0, |
|
| 3761 | - ); |
|
| 3758 | + $this->totals['tax'] = array( |
|
| 3759 | + 'initial' => 0, |
|
| 3760 | + 'recurring' => 0, |
|
| 3761 | + ); |
|
| 3762 | 3762 | |
| 3763 | - $this->tax_rate = 0; |
|
| 3763 | + $this->tax_rate = 0; |
|
| 3764 | 3764 | |
| 3765 | - $this->set_taxes( array() ); |
|
| 3766 | - $current = 0; |
|
| 3767 | - } else { |
|
| 3765 | + $this->set_taxes( array() ); |
|
| 3766 | + $current = 0; |
|
| 3767 | + } else { |
|
| 3768 | 3768 | |
| 3769 | - $item_taxes = array(); |
|
| 3769 | + $item_taxes = array(); |
|
| 3770 | 3770 | |
| 3771 | - foreach ( $this->get_items() as $item ) { |
|
| 3772 | - $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
| 3773 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 3774 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 3775 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 3776 | - foreach ( $taxes as $name => $amount ) { |
|
| 3777 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 3778 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 3771 | + foreach ( $this->get_items() as $item ) { |
|
| 3772 | + $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
| 3773 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 3774 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 3775 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 3776 | + foreach ( $taxes as $name => $amount ) { |
|
| 3777 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 3778 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 3779 | 3779 | |
| 3780 | - if ( ! isset( $item_taxes[ $name ] ) ) { |
|
| 3781 | - $item_taxes[ $name ] = $tax; |
|
| 3782 | - continue; |
|
| 3783 | - } |
|
| 3780 | + if ( ! isset( $item_taxes[ $name ] ) ) { |
|
| 3781 | + $item_taxes[ $name ] = $tax; |
|
| 3782 | + continue; |
|
| 3783 | + } |
|
| 3784 | 3784 | |
| 3785 | - $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 3786 | - $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3785 | + $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 3786 | + $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3787 | 3787 | |
| 3788 | - } |
|
| 3789 | - } |
|
| 3788 | + } |
|
| 3789 | + } |
|
| 3790 | 3790 | |
| 3791 | - $this->set_taxes( $item_taxes ); |
|
| 3791 | + $this->set_taxes( $item_taxes ); |
|
| 3792 | 3792 | |
| 3793 | - $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
| 3794 | - $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
| 3793 | + $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
| 3794 | + $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
| 3795 | 3795 | |
| 3796 | - $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
| 3796 | + $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
| 3797 | 3797 | |
| 3798 | - $this->totals['tax'] = array( |
|
| 3799 | - 'initial' => $initial_tax, |
|
| 3800 | - 'recurring' => $recurring_tax, |
|
| 3801 | - ); |
|
| 3798 | + $this->totals['tax'] = array( |
|
| 3799 | + 'initial' => $initial_tax, |
|
| 3800 | + 'recurring' => $recurring_tax, |
|
| 3801 | + ); |
|
| 3802 | 3802 | |
| 3803 | - } |
|
| 3803 | + } |
|
| 3804 | 3804 | |
| 3805 | - $this->set_total_tax( $current ); |
|
| 3805 | + $this->set_total_tax( $current ); |
|
| 3806 | 3806 | |
| 3807 | - return $current; |
|
| 3807 | + return $current; |
|
| 3808 | 3808 | } |
| 3809 | 3809 | |
| 3810 | 3810 | /** |
| 3811 | - * Recalculates the invoice fees total. |
|
| 3812 | - * |
|
| 3813 | - * @since 1.0.19 |
|
| 3814 | - * @return float The recalculated fee |
|
| 3815 | - */ |
|
| 3816 | - public function recalculate_total_fees() { |
|
| 3817 | - $fees = $this->get_fees(); |
|
| 3818 | - $fee = 0; |
|
| 3819 | - $recurring = 0; |
|
| 3811 | + * Recalculates the invoice fees total. |
|
| 3812 | + * |
|
| 3813 | + * @since 1.0.19 |
|
| 3814 | + * @return float The recalculated fee |
|
| 3815 | + */ |
|
| 3816 | + public function recalculate_total_fees() { |
|
| 3817 | + $fees = $this->get_fees(); |
|
| 3818 | + $fee = 0; |
|
| 3819 | + $recurring = 0; |
|
| 3820 | 3820 | |
| 3821 | 3821 | foreach ( $fees as $data ) { |
| 3822 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3823 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3824 | - } |
|
| 3822 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3823 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3824 | + } |
|
| 3825 | 3825 | |
| 3826 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3827 | - $this->set_total_fees( $current ); |
|
| 3826 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3827 | + $this->set_total_fees( $current ); |
|
| 3828 | 3828 | |
| 3829 | - $this->totals['fee'] = array( |
|
| 3830 | - 'initial' => $fee, |
|
| 3831 | - 'recurring' => $recurring, |
|
| 3832 | - ); |
|
| 3829 | + $this->totals['fee'] = array( |
|
| 3830 | + 'initial' => $fee, |
|
| 3831 | + 'recurring' => $recurring, |
|
| 3832 | + ); |
|
| 3833 | 3833 | |
| 3834 | 3834 | $this->set_total_fees( $fee ); |
| 3835 | 3835 | return $current; |
| 3836 | 3836 | } |
| 3837 | 3837 | |
| 3838 | 3838 | /** |
| 3839 | - * Recalculates the invoice total. |
|
| 3840 | - * |
|
| 3841 | - * @since 1.0.19 |
|
| 3839 | + * Recalculates the invoice total. |
|
| 3840 | + * |
|
| 3841 | + * @since 1.0.19 |
|
| 3842 | 3842 | * @return float The invoice total |
| 3843 | - */ |
|
| 3844 | - public function recalculate_total() { |
|
| 3843 | + */ |
|
| 3844 | + public function recalculate_total() { |
|
| 3845 | 3845 | $this->recalculate_total_fees(); |
| 3846 | 3846 | $this->recalculate_total_discount(); |
| 3847 | - $this->recalculate_total_tax(); |
|
| 3848 | - $this->recalculate_subtotal(); |
|
| 3849 | - $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
| 3850 | - return $this->get_total(); |
|
| 3851 | - } |
|
| 3852 | - |
|
| 3853 | - /** |
|
| 3854 | - * @deprecated |
|
| 3855 | - */ |
|
| 3847 | + $this->recalculate_total_tax(); |
|
| 3848 | + $this->recalculate_subtotal(); |
|
| 3849 | + $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
| 3850 | + return $this->get_total(); |
|
| 3851 | + } |
|
| 3852 | + |
|
| 3853 | + /** |
|
| 3854 | + * @deprecated |
|
| 3855 | + */ |
|
| 3856 | 3856 | public function recalculate_totals() { |
| 3857 | 3857 | $this->recalculate_total(); |
| 3858 | 3858 | $this->save( true ); |
@@ -3866,22 +3866,22 @@ discard block |
||
| 3866 | 3866 | return $this->get_data(); |
| 3867 | 3867 | } |
| 3868 | 3868 | |
| 3869 | - /** |
|
| 3869 | + /** |
|
| 3870 | 3870 | * Adds a system note to an invoice. |
| 3871 | 3871 | * |
| 3872 | 3872 | * @param string $note The note being added. |
| 3873 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3873 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3874 | 3874 | * |
| 3875 | 3875 | */ |
| 3876 | 3876 | public function add_system_note( $note ) { |
| 3877 | - return $this->add_note( $note, false, false, true ); |
|
| 3878 | - } |
|
| 3877 | + return $this->add_note( $note, false, false, true ); |
|
| 3878 | + } |
|
| 3879 | 3879 | |
| 3880 | 3880 | /** |
| 3881 | 3881 | * Adds a note to an invoice. |
| 3882 | 3882 | * |
| 3883 | 3883 | * @param string $note The note being added. |
| 3884 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3884 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3885 | 3885 | * |
| 3886 | 3886 | */ |
| 3887 | 3887 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3891,20 +3891,20 @@ discard block |
||
| 3891 | 3891 | return false; |
| 3892 | 3892 | } |
| 3893 | 3893 | |
| 3894 | - $author = 'System'; |
|
| 3895 | - $author_email = '[email protected]'; |
|
| 3894 | + $author = 'System'; |
|
| 3895 | + $author_email = '[email protected]'; |
|
| 3896 | 3896 | |
| 3897 | - // If this is an admin comment or it has been added by the user. |
|
| 3898 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3899 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3897 | + // If this is an admin comment or it has been added by the user. |
|
| 3898 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3899 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3900 | 3900 | $author = $user->display_name; |
| 3901 | 3901 | $author_email = $user->user_email; |
| 3902 | - } |
|
| 3902 | + } |
|
| 3903 | 3903 | |
| 3904 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3905 | - } |
|
| 3904 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3905 | + } |
|
| 3906 | 3906 | |
| 3907 | - /** |
|
| 3907 | + /** |
|
| 3908 | 3908 | * Generates a unique key for the invoice. |
| 3909 | 3909 | */ |
| 3910 | 3910 | public function generate_key( $string = '' ) { |
@@ -3924,111 +3924,111 @@ discard block |
||
| 3924 | 3924 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
| 3925 | 3925 | } |
| 3926 | 3926 | |
| 3927 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3928 | - } |
|
| 3929 | - |
|
| 3930 | - /** |
|
| 3931 | - * Handle the status transition. |
|
| 3932 | - */ |
|
| 3933 | - protected function status_transition() { |
|
| 3934 | - $status_transition = $this->status_transition; |
|
| 3935 | - |
|
| 3936 | - // Reset status transition variable. |
|
| 3937 | - $this->status_transition = false; |
|
| 3938 | - |
|
| 3939 | - if ( $status_transition ) { |
|
| 3940 | - try { |
|
| 3941 | - |
|
| 3942 | - // Fire a hook for the status change. |
|
| 3943 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3944 | - |
|
| 3945 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3946 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3947 | - |
|
| 3948 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 3949 | - |
|
| 3950 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3951 | - $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 ) ); |
|
| 3952 | - |
|
| 3953 | - // Fire another hook. |
|
| 3954 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3955 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3956 | - |
|
| 3957 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3958 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3959 | - |
|
| 3960 | - // Note the transition occurred. |
|
| 3961 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3962 | - |
|
| 3963 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3964 | - if ( |
|
| 3965 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3966 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3967 | - ) { |
|
| 3968 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3969 | - } |
|
| 3970 | - |
|
| 3971 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3972 | - if ( |
|
| 3973 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3974 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3975 | - ) { |
|
| 3976 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3977 | - } |
|
| 3978 | - } else { |
|
| 3979 | - /* translators: %s: new invoice status */ |
|
| 3980 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3981 | - |
|
| 3982 | - // Note the transition occurred. |
|
| 3983 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3984 | - |
|
| 3985 | - } |
|
| 3986 | - } catch ( Exception $e ) { |
|
| 3987 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3988 | - } |
|
| 3989 | - } |
|
| 3990 | - } |
|
| 3991 | - |
|
| 3992 | - /** |
|
| 3993 | - * Updates an invoice status. |
|
| 3994 | - */ |
|
| 3995 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3996 | - |
|
| 3997 | - // Fires before updating a status. |
|
| 3998 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3999 | - |
|
| 4000 | - // Update the status. |
|
| 4001 | - $this->set_status( $new_status, $note, $manual ); |
|
| 4002 | - |
|
| 4003 | - // Save the order. |
|
| 4004 | - return $this->save(); |
|
| 4005 | - } |
|
| 4006 | - |
|
| 4007 | - /** |
|
| 4008 | - * @deprecated |
|
| 4009 | - */ |
|
| 4010 | - public function refresh_item_ids() { |
|
| 3927 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3928 | + } |
|
| 3929 | + |
|
| 3930 | + /** |
|
| 3931 | + * Handle the status transition. |
|
| 3932 | + */ |
|
| 3933 | + protected function status_transition() { |
|
| 3934 | + $status_transition = $this->status_transition; |
|
| 3935 | + |
|
| 3936 | + // Reset status transition variable. |
|
| 3937 | + $this->status_transition = false; |
|
| 3938 | + |
|
| 3939 | + if ( $status_transition ) { |
|
| 3940 | + try { |
|
| 3941 | + |
|
| 3942 | + // Fire a hook for the status change. |
|
| 3943 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3944 | + |
|
| 3945 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3946 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3947 | + |
|
| 3948 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 3949 | + |
|
| 3950 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3951 | + $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 ) ); |
|
| 3952 | + |
|
| 3953 | + // Fire another hook. |
|
| 3954 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3955 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3956 | + |
|
| 3957 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3958 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3959 | + |
|
| 3960 | + // Note the transition occurred. |
|
| 3961 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3962 | + |
|
| 3963 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3964 | + if ( |
|
| 3965 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3966 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3967 | + ) { |
|
| 3968 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3969 | + } |
|
| 3970 | + |
|
| 3971 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3972 | + if ( |
|
| 3973 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3974 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3975 | + ) { |
|
| 3976 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3977 | + } |
|
| 3978 | + } else { |
|
| 3979 | + /* translators: %s: new invoice status */ |
|
| 3980 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3981 | + |
|
| 3982 | + // Note the transition occurred. |
|
| 3983 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3984 | + |
|
| 3985 | + } |
|
| 3986 | + } catch ( Exception $e ) { |
|
| 3987 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3988 | + } |
|
| 3989 | + } |
|
| 3990 | + } |
|
| 3991 | + |
|
| 3992 | + /** |
|
| 3993 | + * Updates an invoice status. |
|
| 3994 | + */ |
|
| 3995 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3996 | + |
|
| 3997 | + // Fires before updating a status. |
|
| 3998 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3999 | + |
|
| 4000 | + // Update the status. |
|
| 4001 | + $this->set_status( $new_status, $note, $manual ); |
|
| 4002 | + |
|
| 4003 | + // Save the order. |
|
| 4004 | + return $this->save(); |
|
| 4005 | + } |
|
| 4006 | + |
|
| 4007 | + /** |
|
| 4008 | + * @deprecated |
|
| 4009 | + */ |
|
| 4010 | + public function refresh_item_ids() { |
|
| 4011 | 4011 | $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) ); |
| 4012 | 4012 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
| 4013 | - } |
|
| 4013 | + } |
|
| 4014 | 4014 | |
| 4015 | - /** |
|
| 4016 | - * @deprecated |
|
| 4017 | - */ |
|
| 4018 | - public function update_items( $temp = false ) { |
|
| 4015 | + /** |
|
| 4016 | + * @deprecated |
|
| 4017 | + */ |
|
| 4018 | + public function update_items( $temp = false ) { |
|
| 4019 | 4019 | |
| 4020 | - $this->set_items( $this->get_items() ); |
|
| 4020 | + $this->set_items( $this->get_items() ); |
|
| 4021 | 4021 | |
| 4022 | - if ( ! $temp ) { |
|
| 4023 | - $this->save(); |
|
| 4024 | - } |
|
| 4022 | + if ( ! $temp ) { |
|
| 4023 | + $this->save(); |
|
| 4024 | + } |
|
| 4025 | 4025 | |
| 4026 | 4026 | return $this; |
| 4027 | - } |
|
| 4027 | + } |
|
| 4028 | 4028 | |
| 4029 | - /** |
|
| 4030 | - * @deprecated |
|
| 4031 | - */ |
|
| 4029 | + /** |
|
| 4030 | + * @deprecated |
|
| 4031 | + */ |
|
| 4032 | 4032 | public function validate_discount() { |
| 4033 | 4033 | |
| 4034 | 4034 | $discount_code = $this->get_discount_code(); |
@@ -4043,100 +4043,100 @@ discard block |
||
| 4043 | 4043 | return $discount->exists(); |
| 4044 | 4044 | } |
| 4045 | 4045 | |
| 4046 | - /** |
|
| 4047 | - * Refunds an invoice. |
|
| 4048 | - */ |
|
| 4046 | + /** |
|
| 4047 | + * Refunds an invoice. |
|
| 4048 | + */ |
|
| 4049 | 4049 | public function refund() { |
| 4050 | - $this->set_status( 'wpi-refunded' ); |
|
| 4050 | + $this->set_status( 'wpi-refunded' ); |
|
| 4051 | 4051 | $this->save(); |
| 4052 | - } |
|
| 4052 | + } |
|
| 4053 | 4053 | |
| 4054 | - /** |
|
| 4055 | - * Marks an invoice as paid. |
|
| 4056 | - * |
|
| 4057 | - * @param string $transaction_id |
|
| 4058 | - */ |
|
| 4054 | + /** |
|
| 4055 | + * Marks an invoice as paid. |
|
| 4056 | + * |
|
| 4057 | + * @param string $transaction_id |
|
| 4058 | + */ |
|
| 4059 | 4059 | public function mark_paid( $transaction_id = null, $note = '' ) { |
| 4060 | 4060 | |
| 4061 | - // Set the transaction id. |
|
| 4062 | - if ( empty( $transaction_id ) ) { |
|
| 4063 | - $transaction_id = $this->generate_key( 'trans_' ); |
|
| 4064 | - } |
|
| 4061 | + // Set the transaction id. |
|
| 4062 | + if ( empty( $transaction_id ) ) { |
|
| 4063 | + $transaction_id = $this->generate_key( 'trans_' ); |
|
| 4064 | + } |
|
| 4065 | 4065 | |
| 4066 | - if ( ! $this->get_transaction_id() ) { |
|
| 4067 | - $this->set_transaction_id( $transaction_id ); |
|
| 4068 | - } |
|
| 4066 | + if ( ! $this->get_transaction_id() ) { |
|
| 4067 | + $this->set_transaction_id( $transaction_id ); |
|
| 4068 | + } |
|
| 4069 | 4069 | |
| 4070 | - if ( $this->is_paid() && 'wpi-processing' !== $this->get_status() ) { |
|
| 4071 | - return $this->save(); |
|
| 4072 | - } |
|
| 4070 | + if ( $this->is_paid() && 'wpi-processing' !== $this->get_status() ) { |
|
| 4071 | + return $this->save(); |
|
| 4072 | + } |
|
| 4073 | 4073 | |
| 4074 | - // Set the completed date. |
|
| 4075 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 4074 | + // Set the completed date. |
|
| 4075 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 4076 | 4076 | |
| 4077 | - // Set the new status. |
|
| 4078 | - $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
| 4079 | - if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
| 4077 | + // Set the new status. |
|
| 4078 | + $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
| 4079 | + if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
| 4080 | 4080 | |
| 4081 | - $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
| 4082 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 4081 | + $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
| 4082 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 4083 | 4083 | |
| 4084 | - if ( 'none' == $this->get_gateway() ) { |
|
| 4085 | - $_note = $note; |
|
| 4086 | - } |
|
| 4084 | + if ( 'none' == $this->get_gateway() ) { |
|
| 4085 | + $_note = $note; |
|
| 4086 | + } |
|
| 4087 | 4087 | |
| 4088 | - $this->set_status( 'wpi-renewal', $_note ); |
|
| 4088 | + $this->set_status( 'wpi-renewal', $_note ); |
|
| 4089 | 4089 | |
| 4090 | - } else { |
|
| 4090 | + } else { |
|
| 4091 | 4091 | |
| 4092 | - $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 4093 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 4092 | + $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 4093 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 4094 | 4094 | |
| 4095 | - if ( 'none' == $this->get_gateway() ) { |
|
| 4096 | - $_note = $note; |
|
| 4097 | - } |
|
| 4095 | + if ( 'none' == $this->get_gateway() ) { |
|
| 4096 | + $_note = $note; |
|
| 4097 | + } |
|
| 4098 | 4098 | |
| 4099 | - $this->set_status( 'publish', $_note ); |
|
| 4099 | + $this->set_status( 'publish', $_note ); |
|
| 4100 | 4100 | |
| 4101 | - } |
|
| 4101 | + } |
|
| 4102 | 4102 | |
| 4103 | - // Set checkout mode. |
|
| 4104 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 4105 | - $this->set_mode( $mode ); |
|
| 4103 | + // Set checkout mode. |
|
| 4104 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 4105 | + $this->set_mode( $mode ); |
|
| 4106 | 4106 | |
| 4107 | - // Save the invoice. |
|
| 4107 | + // Save the invoice. |
|
| 4108 | 4108 | $this->save(); |
| 4109 | - } |
|
| 4110 | - |
|
| 4111 | - /** |
|
| 4112 | - * Save data to the database. |
|
| 4113 | - * |
|
| 4114 | - * @since 1.0.19 |
|
| 4115 | - * @return int invoice ID |
|
| 4116 | - */ |
|
| 4117 | - public function save() { |
|
| 4118 | - $this->maybe_set_date_paid(); |
|
| 4119 | - $this->maybe_set_key(); |
|
| 4120 | - parent::save(); |
|
| 4121 | - $this->clear_cache(); |
|
| 4122 | - $this->status_transition(); |
|
| 4123 | - return $this->get_id(); |
|
| 4124 | - } |
|
| 4125 | - |
|
| 4126 | - /** |
|
| 4109 | + } |
|
| 4110 | + |
|
| 4111 | + /** |
|
| 4112 | + * Save data to the database. |
|
| 4113 | + * |
|
| 4114 | + * @since 1.0.19 |
|
| 4115 | + * @return int invoice ID |
|
| 4116 | + */ |
|
| 4117 | + public function save() { |
|
| 4118 | + $this->maybe_set_date_paid(); |
|
| 4119 | + $this->maybe_set_key(); |
|
| 4120 | + parent::save(); |
|
| 4121 | + $this->clear_cache(); |
|
| 4122 | + $this->status_transition(); |
|
| 4123 | + return $this->get_id(); |
|
| 4124 | + } |
|
| 4125 | + |
|
| 4126 | + /** |
|
| 4127 | 4127 | * Clears the subscription's cache. |
| 4128 | 4128 | */ |
| 4129 | 4129 | public function clear_cache() { |
| 4130 | - if ( $this->get_key() ) { |
|
| 4131 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 4132 | - } |
|
| 4133 | - |
|
| 4134 | - if ( $this->get_number() ) { |
|
| 4135 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 4136 | - } |
|
| 4137 | - |
|
| 4138 | - if ( $this->get_transaction_id() ) { |
|
| 4139 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 4140 | - } |
|
| 4141 | - } |
|
| 4130 | + if ( $this->get_key() ) { |
|
| 4131 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 4132 | + } |
|
| 4133 | + |
|
| 4134 | + if ( $this->get_number() ) { |
|
| 4135 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 4136 | + } |
|
| 4137 | + |
|
| 4138 | + if ( $this->get_transaction_id() ) { |
|
| 4139 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 4140 | + } |
|
| 4141 | + } |
|
| 4142 | 4142 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Invoice class. |
@@ -147,39 +147,39 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
| 149 | 149 | */ |
| 150 | - public function __construct( $invoice = 0 ) { |
|
| 150 | + public function __construct($invoice = 0) { |
|
| 151 | 151 | |
| 152 | - parent::__construct( $invoice ); |
|
| 152 | + parent::__construct($invoice); |
|
| 153 | 153 | |
| 154 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 155 | - $this->set_id( (int) $invoice ); |
|
| 156 | - } elseif ( $invoice instanceof self ) { |
|
| 157 | - $this->set_id( $invoice->get_id() ); |
|
| 158 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
| 159 | - $this->set_id( $invoice->ID ); |
|
| 160 | - } elseif ( is_array( $invoice ) ) { |
|
| 161 | - $this->set_props( $invoice ); |
|
| 154 | + if (!empty($invoice) && is_numeric($invoice) && getpaid_is_invoice_post_type(get_post_type((int) $invoice))) { |
|
| 155 | + $this->set_id((int) $invoice); |
|
| 156 | + } elseif ($invoice instanceof self) { |
|
| 157 | + $this->set_id($invoice->get_id()); |
|
| 158 | + } elseif (!empty($invoice->ID)) { |
|
| 159 | + $this->set_id($invoice->ID); |
|
| 160 | + } elseif (is_array($invoice)) { |
|
| 161 | + $this->set_props($invoice); |
|
| 162 | 162 | |
| 163 | - if ( isset( $invoice['ID'] ) ) { |
|
| 164 | - $this->set_id( $invoice['ID'] ); |
|
| 163 | + if (isset($invoice['ID'])) { |
|
| 164 | + $this->set_id($invoice['ID']); |
|
| 165 | 165 | } |
| 166 | -} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 167 | - $this->set_id( $invoice_id ); |
|
| 168 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 169 | - $this->set_id( $invoice_id ); |
|
| 170 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 171 | - $this->set_id( $invoice_id ); |
|
| 166 | +} elseif (is_string($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'key')) { |
|
| 167 | + $this->set_id($invoice_id); |
|
| 168 | + } elseif (is_string($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'number')) { |
|
| 169 | + $this->set_id($invoice_id); |
|
| 170 | + } elseif (is_string($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'transaction_id')) { |
|
| 171 | + $this->set_id($invoice_id); |
|
| 172 | 172 | } else { |
| 173 | - $this->set_object_read( true ); |
|
| 173 | + $this->set_object_read(true); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | // Load the datastore. |
| 177 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 177 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 178 | 178 | |
| 179 | - if ( $this->get_id() > 0 ) { |
|
| 180 | - $this->post = get_post( $this->get_id() ); |
|
| 179 | + if ($this->get_id() > 0) { |
|
| 180 | + $this->post = get_post($this->get_id()); |
|
| 181 | 181 | $this->ID = $this->get_id(); |
| 182 | - $this->data_store->read( $this ); |
|
| 182 | + $this->data_store->read($this); |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
@@ -193,39 +193,39 @@ discard block |
||
| 193 | 193 | * @since 1.0.15 |
| 194 | 194 | * @return int |
| 195 | 195 | */ |
| 196 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 196 | + public static function get_invoice_id_by_field($value, $field = 'key') { |
|
| 197 | 197 | global $wpdb; |
| 198 | 198 | |
| 199 | 199 | // Trim the value. |
| 200 | - $value = trim( $value ); |
|
| 200 | + $value = trim($value); |
|
| 201 | 201 | |
| 202 | - if ( empty( $value ) ) { |
|
| 202 | + if (empty($value)) { |
|
| 203 | 203 | return 0; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | // Valid fields. |
| 207 | - $fields = array( 'key', 'number', 'transaction_id' ); |
|
| 207 | + $fields = array('key', 'number', 'transaction_id'); |
|
| 208 | 208 | |
| 209 | 209 | // Ensure a field has been passed. |
| 210 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 210 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 211 | 211 | return 0; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 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 ) { |
|
| 215 | + $invoice_id = wp_cache_get($value, "getpaid_invoice_{$field}s_to_invoice_ids"); |
|
| 216 | + if (false !== $invoice_id) { |
|
| 217 | 217 | return $invoice_id; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // Fetch from the db. |
| 221 | 221 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 222 | - $db_field = 'key' === $field ? 'invoice_key' : $field; |
|
| 222 | + $db_field = 'key' === $field ? 'invoice_key' : $field; |
|
| 223 | 223 | $invoice_id = (int) $wpdb->get_var( |
| 224 | - $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$db_field`=%s LIMIT 1", $value ) |
|
| 224 | + $wpdb->prepare("SELECT `post_id` FROM $table WHERE `$db_field`=%s LIMIT 1", $value) |
|
| 225 | 225 | ); |
| 226 | 226 | |
| 227 | 227 | // Update the cache with our data |
| 228 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 228 | + wp_cache_set($value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids"); |
|
| 229 | 229 | |
| 230 | 230 | return $invoice_id; |
| 231 | 231 | } |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | /** |
| 234 | 234 | * Checks if an invoice key is set. |
| 235 | 235 | */ |
| 236 | - public function _isset( $key ) { |
|
| 237 | - return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
|
| 236 | + public function _isset($key) { |
|
| 237 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /* |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | * @param string $context View or edit context. |
| 260 | 260 | * @return int |
| 261 | 261 | */ |
| 262 | - public function get_parent_id( $context = 'view' ) { |
|
| 263 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 262 | + public function get_parent_id($context = 'view') { |
|
| 263 | + return (int) $this->get_prop('parent_id', $context); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @return WPInv_Invoice |
| 271 | 271 | */ |
| 272 | 272 | public function get_parent_payment() { |
| 273 | - return new WPInv_Invoice( $this->get_parent_id() ); |
|
| 273 | + return new WPInv_Invoice($this->get_parent_id()); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * @param string $context View or edit context. |
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | - public function get_status( $context = 'view' ) { |
|
| 294 | - return $this->get_prop( 'status', $context ); |
|
| 293 | + public function get_status($context = 'view') { |
|
| 294 | + return $this->get_prop('status', $context); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * @return array |
| 302 | 302 | */ |
| 303 | 303 | public function get_all_statuses() { |
| 304 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 304 | + return wpinv_get_invoice_statuses(true, true, $this); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | public function get_status_nicename() { |
| 314 | 314 | $statuses = $this->get_all_statuses(); |
| 315 | 315 | |
| 316 | - $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
|
| 316 | + $status = isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : $this->get_status(); |
|
| 317 | 317 | |
| 318 | - return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
|
| 318 | + return apply_filters('wpinv_get_invoice_status_nicename', $status, $this); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | */ |
| 327 | 327 | public function get_status_class() { |
| 328 | 328 | $statuses = getpaid_get_invoice_status_classes(); |
| 329 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark text-white'; |
|
| 329 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'bg-dark text-white'; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -337,9 +337,9 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | public function get_status_label_html() { |
| 339 | 339 | |
| 340 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 341 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 342 | - $class = esc_attr( $this->get_status_class() ); |
|
| 340 | + $status_label = sanitize_text_field($this->get_status_nicename()); |
|
| 341 | + $status = sanitize_html_class($this->get_status()); |
|
| 342 | + $class = esc_attr($this->get_status_class()); |
|
| 343 | 343 | |
| 344 | 344 | return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
| 345 | 345 | } |
@@ -351,23 +351,23 @@ discard block |
||
| 351 | 351 | * @param string $context View or edit context. |
| 352 | 352 | * @return string |
| 353 | 353 | */ |
| 354 | - public function get_version( $context = 'view' ) { |
|
| 355 | - return $this->get_prop( 'version', $context ); |
|
| 354 | + public function get_version($context = 'view') { |
|
| 355 | + return $this->get_prop('version', $context); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
| 359 | 359 | * @deprecated |
| 360 | 360 | */ |
| 361 | - public function get_invoice_date( $format = true ) { |
|
| 362 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 363 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 364 | - $formatted = getpaid_format_date( $date ); |
|
| 361 | + public function get_invoice_date($format = true) { |
|
| 362 | + $date = getpaid_format_date($this->get_date_completed()); |
|
| 363 | + $date = empty($date) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 364 | + $formatted = getpaid_format_date($date); |
|
| 365 | 365 | |
| 366 | - if ( $format ) { |
|
| 366 | + if ($format) { |
|
| 367 | 367 | return $formatted; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - return empty( $formatted ) ? '' : $date; |
|
| 370 | + return empty($formatted) ? '' : $date; |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -377,8 +377,8 @@ discard block |
||
| 377 | 377 | * @param string $context View or edit context. |
| 378 | 378 | * @return string |
| 379 | 379 | */ |
| 380 | - public function get_date_created( $context = 'view' ) { |
|
| 381 | - return $this->get_prop( 'date_created', $context ); |
|
| 380 | + public function get_date_created($context = 'view') { |
|
| 381 | + return $this->get_prop('date_created', $context); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -388,8 +388,8 @@ discard block |
||
| 388 | 388 | * @param string $context View or edit context. |
| 389 | 389 | * @return string |
| 390 | 390 | */ |
| 391 | - public function get_created_date( $context = 'view' ) { |
|
| 392 | - return $this->get_date_created( $context ); |
|
| 391 | + public function get_created_date($context = 'view') { |
|
| 392 | + return $this->get_date_created($context); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -399,11 +399,11 @@ discard block |
||
| 399 | 399 | * @param string $context View or edit context. |
| 400 | 400 | * @return string |
| 401 | 401 | */ |
| 402 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 403 | - $date = $this->get_date_created( $context ); |
|
| 402 | + public function get_date_created_gmt($context = 'view') { |
|
| 403 | + $date = $this->get_date_created($context); |
|
| 404 | 404 | |
| 405 | - if ( $date ) { |
|
| 406 | - $date = get_gmt_from_date( $date ); |
|
| 405 | + if ($date) { |
|
| 406 | + $date = get_gmt_from_date($date); |
|
| 407 | 407 | } |
| 408 | 408 | return $date; |
| 409 | 409 | } |
@@ -415,8 +415,8 @@ discard block |
||
| 415 | 415 | * @param string $context View or edit context. |
| 416 | 416 | * @return string |
| 417 | 417 | */ |
| 418 | - public function get_date_modified( $context = 'view' ) { |
|
| 419 | - return $this->get_prop( 'date_modified', $context ); |
|
| 418 | + public function get_date_modified($context = 'view') { |
|
| 419 | + return $this->get_prop('date_modified', $context); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -426,8 +426,8 @@ discard block |
||
| 426 | 426 | * @param string $context View or edit context. |
| 427 | 427 | * @return string |
| 428 | 428 | */ |
| 429 | - public function get_modified_date( $context = 'view' ) { |
|
| 430 | - return $this->get_date_modified( $context ); |
|
| 429 | + public function get_modified_date($context = 'view') { |
|
| 430 | + return $this->get_date_modified($context); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -437,11 +437,11 @@ discard block |
||
| 437 | 437 | * @param string $context View or edit context. |
| 438 | 438 | * @return string |
| 439 | 439 | */ |
| 440 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 441 | - $date = $this->get_date_modified( $context ); |
|
| 440 | + public function get_date_modified_gmt($context = 'view') { |
|
| 441 | + $date = $this->get_date_modified($context); |
|
| 442 | 442 | |
| 443 | - if ( $date ) { |
|
| 444 | - $date = get_gmt_from_date( $date ); |
|
| 443 | + if ($date) { |
|
| 444 | + $date = get_gmt_from_date($date); |
|
| 445 | 445 | } |
| 446 | 446 | return $date; |
| 447 | 447 | } |
@@ -453,8 +453,8 @@ discard block |
||
| 453 | 453 | * @param string $context View or edit context. |
| 454 | 454 | * @return string |
| 455 | 455 | */ |
| 456 | - public function get_due_date( $context = 'view' ) { |
|
| 457 | - return $this->get_prop( 'due_date', $context ); |
|
| 456 | + public function get_due_date($context = 'view') { |
|
| 457 | + return $this->get_prop('due_date', $context); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -464,8 +464,8 @@ discard block |
||
| 464 | 464 | * @param string $context View or edit context. |
| 465 | 465 | * @return string |
| 466 | 466 | */ |
| 467 | - public function get_date_due( $context = 'view' ) { |
|
| 468 | - return $this->get_due_date( $context ); |
|
| 467 | + public function get_date_due($context = 'view') { |
|
| 468 | + return $this->get_due_date($context); |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | /** |
@@ -475,11 +475,11 @@ discard block |
||
| 475 | 475 | * @param string $context View or edit context. |
| 476 | 476 | * @return string |
| 477 | 477 | */ |
| 478 | - public function get_due_date_gmt( $context = 'view' ) { |
|
| 479 | - $date = $this->get_due_date( $context ); |
|
| 478 | + public function get_due_date_gmt($context = 'view') { |
|
| 479 | + $date = $this->get_due_date($context); |
|
| 480 | 480 | |
| 481 | - if ( $date ) { |
|
| 482 | - $date = get_gmt_from_date( $date ); |
|
| 481 | + if ($date) { |
|
| 482 | + $date = get_gmt_from_date($date); |
|
| 483 | 483 | } |
| 484 | 484 | return $date; |
| 485 | 485 | } |
@@ -491,8 +491,8 @@ discard block |
||
| 491 | 491 | * @param string $context View or edit context. |
| 492 | 492 | * @return string |
| 493 | 493 | */ |
| 494 | - public function get_gmt_date_due( $context = 'view' ) { |
|
| 495 | - return $this->get_due_date_gmt( $context ); |
|
| 494 | + public function get_gmt_date_due($context = 'view') { |
|
| 495 | + return $this->get_due_date_gmt($context); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | /** |
@@ -502,8 +502,8 @@ discard block |
||
| 502 | 502 | * @param string $context View or edit context. |
| 503 | 503 | * @return string |
| 504 | 504 | */ |
| 505 | - public function get_completed_date( $context = 'view' ) { |
|
| 506 | - return $this->get_prop( 'completed_date', $context ); |
|
| 505 | + public function get_completed_date($context = 'view') { |
|
| 506 | + return $this->get_prop('completed_date', $context); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | /** |
@@ -513,8 +513,8 @@ discard block |
||
| 513 | 513 | * @param string $context View or edit context. |
| 514 | 514 | * @return string |
| 515 | 515 | */ |
| 516 | - public function get_date_completed( $context = 'view' ) { |
|
| 517 | - return $this->get_completed_date( $context ); |
|
| 516 | + public function get_date_completed($context = 'view') { |
|
| 517 | + return $this->get_completed_date($context); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -524,11 +524,11 @@ discard block |
||
| 524 | 524 | * @param string $context View or edit context. |
| 525 | 525 | * @return string |
| 526 | 526 | */ |
| 527 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
| 528 | - $date = $this->get_completed_date( $context ); |
|
| 527 | + public function get_completed_date_gmt($context = 'view') { |
|
| 528 | + $date = $this->get_completed_date($context); |
|
| 529 | 529 | |
| 530 | - if ( $date ) { |
|
| 531 | - $date = get_gmt_from_date( $date ); |
|
| 530 | + if ($date) { |
|
| 531 | + $date = get_gmt_from_date($date); |
|
| 532 | 532 | } |
| 533 | 533 | return $date; |
| 534 | 534 | } |
@@ -540,8 +540,8 @@ discard block |
||
| 540 | 540 | * @param string $context View or edit context. |
| 541 | 541 | * @return string |
| 542 | 542 | */ |
| 543 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
| 544 | - return $this->get_completed_date_gmt( $context ); |
|
| 543 | + public function get_gmt_completed_date($context = 'view') { |
|
| 544 | + return $this->get_completed_date_gmt($context); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -551,12 +551,12 @@ discard block |
||
| 551 | 551 | * @param string $context View or edit context. |
| 552 | 552 | * @return string |
| 553 | 553 | */ |
| 554 | - public function get_number( $context = 'view' ) { |
|
| 555 | - $number = $this->get_prop( 'number', $context ); |
|
| 554 | + public function get_number($context = 'view') { |
|
| 555 | + $number = $this->get_prop('number', $context); |
|
| 556 | 556 | |
| 557 | - if ( empty( $number ) ) { |
|
| 557 | + if (empty($number)) { |
|
| 558 | 558 | $number = $this->generate_number(); |
| 559 | - $this->set_number( $this->generate_number() ); |
|
| 559 | + $this->set_number($this->generate_number()); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | return $number; |
@@ -570,8 +570,8 @@ discard block |
||
| 570 | 570 | public function maybe_set_number() { |
| 571 | 571 | $number = $this->get_number(); |
| 572 | 572 | |
| 573 | - if ( empty( $number ) || $this->get_id() == $number ) { |
|
| 574 | - $this->set_number( $this->generate_number() ); |
|
| 573 | + if (empty($number) || $this->get_id() == $number) { |
|
| 574 | + $this->set_number($this->generate_number()); |
|
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | |
@@ -582,8 +582,8 @@ discard block |
||
| 582 | 582 | * @param string $context View or edit context. |
| 583 | 583 | * @return string |
| 584 | 584 | */ |
| 585 | - public function get_key( $context = 'view' ) { |
|
| 586 | - return $this->get_prop( 'key', $context ); |
|
| 585 | + public function get_key($context = 'view') { |
|
| 586 | + return $this->get_prop('key', $context); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
@@ -594,9 +594,9 @@ discard block |
||
| 594 | 594 | public function maybe_set_key() { |
| 595 | 595 | $key = $this->get_key(); |
| 596 | 596 | |
| 597 | - if ( empty( $key ) ) { |
|
| 598 | - $key = $this->generate_key( $this->get_type() . '_' ); |
|
| 599 | - $this->set_key( $key ); |
|
| 597 | + if (empty($key)) { |
|
| 598 | + $key = $this->generate_key($this->get_type() . '_'); |
|
| 599 | + $this->set_key($key); |
|
| 600 | 600 | } |
| 601 | 601 | } |
| 602 | 602 | |
@@ -607,8 +607,8 @@ discard block |
||
| 607 | 607 | * @param string $context View or edit context. |
| 608 | 608 | * @return string |
| 609 | 609 | */ |
| 610 | - public function get_type( $context = 'view' ) { |
|
| 611 | - return $this->get_prop( 'type', $context ); |
|
| 610 | + public function get_type($context = 'view') { |
|
| 611 | + return $this->get_prop('type', $context); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | /** |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | * @return string |
| 619 | 619 | */ |
| 620 | 620 | public function get_invoice_quote_type() { |
| 621 | - return getpaid_get_post_type_label( $this->get_post_type(), false ); |
|
| 621 | + return getpaid_get_post_type_label($this->get_post_type(), false); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | /** |
@@ -628,8 +628,8 @@ discard block |
||
| 628 | 628 | * @param string $context View or edit context. |
| 629 | 629 | * @return string |
| 630 | 630 | */ |
| 631 | - public function get_label( $context = 'view' ) { |
|
| 632 | - return getpaid_get_post_type_label( $this->get_post_type( $context ), false ); |
|
| 631 | + public function get_label($context = 'view') { |
|
| 632 | + return getpaid_get_post_type_label($this->get_post_type($context), false); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
@@ -639,8 +639,8 @@ discard block |
||
| 639 | 639 | * @param string $context View or edit context. |
| 640 | 640 | * @return string |
| 641 | 641 | */ |
| 642 | - public function get_post_type( $context = 'view' ) { |
|
| 643 | - return $this->get_prop( 'post_type', $context ); |
|
| 642 | + public function get_post_type($context = 'view') { |
|
| 643 | + return $this->get_prop('post_type', $context); |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** |
@@ -650,8 +650,8 @@ discard block |
||
| 650 | 650 | * @param string $context View or edit context. |
| 651 | 651 | * @return string |
| 652 | 652 | */ |
| 653 | - public function get_mode( $context = 'view' ) { |
|
| 654 | - return $this->get_prop( 'mode', $context ); |
|
| 653 | + public function get_mode($context = 'view') { |
|
| 654 | + return $this->get_prop('mode', $context); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -661,13 +661,13 @@ discard block |
||
| 661 | 661 | * @param string $context View or edit context. |
| 662 | 662 | * @return string |
| 663 | 663 | */ |
| 664 | - public function get_path( $context = 'view' ) { |
|
| 665 | - $path = $this->get_prop( 'path', $context ); |
|
| 664 | + public function get_path($context = 'view') { |
|
| 665 | + $path = $this->get_prop('path', $context); |
|
| 666 | 666 | $prefix = $this->get_type(); |
| 667 | 667 | |
| 668 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 669 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 670 | - $this->set_path( $path ); |
|
| 668 | + if (0 !== strpos($path, $prefix)) { |
|
| 669 | + $path = sanitize_title($prefix . '-' . $this->get_id()); |
|
| 670 | + $this->set_path($path); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | return $path; |
@@ -680,8 +680,8 @@ discard block |
||
| 680 | 680 | * @param string $context View or edit context. |
| 681 | 681 | * @return string |
| 682 | 682 | */ |
| 683 | - public function get_name( $context = 'view' ) { |
|
| 684 | - return $this->get_prop( 'title', $context ); |
|
| 683 | + public function get_name($context = 'view') { |
|
| 684 | + return $this->get_prop('title', $context); |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -691,8 +691,8 @@ discard block |
||
| 691 | 691 | * @param string $context View or edit context. |
| 692 | 692 | * @return string |
| 693 | 693 | */ |
| 694 | - public function get_title( $context = 'view' ) { |
|
| 695 | - return $this->get_name( $context ); |
|
| 694 | + public function get_title($context = 'view') { |
|
| 695 | + return $this->get_name($context); |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
@@ -702,8 +702,8 @@ discard block |
||
| 702 | 702 | * @param string $context View or edit context. |
| 703 | 703 | * @return string |
| 704 | 704 | */ |
| 705 | - public function get_description( $context = 'view' ) { |
|
| 706 | - return $this->get_prop( 'description', $context ); |
|
| 705 | + public function get_description($context = 'view') { |
|
| 706 | + return $this->get_prop('description', $context); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -713,8 +713,8 @@ discard block |
||
| 713 | 713 | * @param string $context View or edit context. |
| 714 | 714 | * @return string |
| 715 | 715 | */ |
| 716 | - public function get_excerpt( $context = 'view' ) { |
|
| 717 | - return $this->get_description( $context ); |
|
| 716 | + public function get_excerpt($context = 'view') { |
|
| 717 | + return $this->get_description($context); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -724,8 +724,8 @@ discard block |
||
| 724 | 724 | * @param string $context View or edit context. |
| 725 | 725 | * @return string |
| 726 | 726 | */ |
| 727 | - public function get_summary( $context = 'view' ) { |
|
| 728 | - return $this->get_description( $context ); |
|
| 727 | + public function get_summary($context = 'view') { |
|
| 728 | + return $this->get_description($context); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
@@ -735,26 +735,26 @@ discard block |
||
| 735 | 735 | * @param string $context View or edit context. |
| 736 | 736 | * @return array |
| 737 | 737 | */ |
| 738 | - public function get_user_info( $context = 'view' ) { |
|
| 738 | + public function get_user_info($context = 'view') { |
|
| 739 | 739 | |
| 740 | 740 | $user_info = array( |
| 741 | - 'user_id' => $this->get_user_id( $context ), |
|
| 742 | - 'email' => $this->get_email( $context ), |
|
| 743 | - 'first_name' => $this->get_first_name( $context ), |
|
| 744 | - 'last_name' => $this->get_last_name( $context ), |
|
| 745 | - 'address' => $this->get_address( $context ), |
|
| 746 | - 'phone' => $this->get_phone( $context ), |
|
| 747 | - 'city' => $this->get_city( $context ), |
|
| 748 | - 'country' => $this->get_country( $context ), |
|
| 749 | - 'state' => $this->get_state( $context ), |
|
| 750 | - 'zip' => $this->get_zip( $context ), |
|
| 751 | - 'company' => $this->get_company( $context ), |
|
| 752 | - 'company_id' => $this->get_company_id( $context ), |
|
| 753 | - 'vat_number' => $this->get_vat_number( $context ), |
|
| 754 | - 'discount' => $this->get_discount_code( $context ), |
|
| 741 | + 'user_id' => $this->get_user_id($context), |
|
| 742 | + 'email' => $this->get_email($context), |
|
| 743 | + 'first_name' => $this->get_first_name($context), |
|
| 744 | + 'last_name' => $this->get_last_name($context), |
|
| 745 | + 'address' => $this->get_address($context), |
|
| 746 | + 'phone' => $this->get_phone($context), |
|
| 747 | + 'city' => $this->get_city($context), |
|
| 748 | + 'country' => $this->get_country($context), |
|
| 749 | + 'state' => $this->get_state($context), |
|
| 750 | + 'zip' => $this->get_zip($context), |
|
| 751 | + 'company' => $this->get_company($context), |
|
| 752 | + 'company_id' => $this->get_company_id($context), |
|
| 753 | + 'vat_number' => $this->get_vat_number($context), |
|
| 754 | + 'discount' => $this->get_discount_code($context), |
|
| 755 | 755 | ); |
| 756 | 756 | |
| 757 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 757 | + return apply_filters('wpinv_user_info', $user_info, $this->get_id(), $this); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | /** |
@@ -764,8 +764,8 @@ discard block |
||
| 764 | 764 | * @param string $context View or edit context. |
| 765 | 765 | * @return int |
| 766 | 766 | */ |
| 767 | - public function get_author( $context = 'view' ) { |
|
| 768 | - return (int) $this->get_prop( 'author', $context ); |
|
| 767 | + public function get_author($context = 'view') { |
|
| 768 | + return (int) $this->get_prop('author', $context); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | /** |
@@ -775,8 +775,8 @@ discard block |
||
| 775 | 775 | * @param string $context View or edit context. |
| 776 | 776 | * @return int |
| 777 | 777 | */ |
| 778 | - public function get_user_id( $context = 'view' ) { |
|
| 779 | - return $this->get_author( $context ); |
|
| 778 | + public function get_user_id($context = 'view') { |
|
| 779 | + return $this->get_author($context); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -786,8 +786,8 @@ discard block |
||
| 786 | 786 | * @param string $context View or edit context. |
| 787 | 787 | * @return int |
| 788 | 788 | */ |
| 789 | - public function get_customer_id( $context = 'view' ) { |
|
| 790 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 789 | + public function get_customer_id($context = 'view') { |
|
| 790 | + return (int) $this->get_prop('customer_id', $context); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | /** |
@@ -797,8 +797,8 @@ discard block |
||
| 797 | 797 | * @param string $context View or edit context. |
| 798 | 798 | * @return string |
| 799 | 799 | */ |
| 800 | - public function get_ip( $context = 'view' ) { |
|
| 801 | - return $this->get_prop( 'user_ip', $context ); |
|
| 800 | + public function get_ip($context = 'view') { |
|
| 801 | + return $this->get_prop('user_ip', $context); |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
@@ -808,8 +808,8 @@ discard block |
||
| 808 | 808 | * @param string $context View or edit context. |
| 809 | 809 | * @return string |
| 810 | 810 | */ |
| 811 | - public function get_user_ip( $context = 'view' ) { |
|
| 812 | - return $this->get_ip( $context ); |
|
| 811 | + public function get_user_ip($context = 'view') { |
|
| 812 | + return $this->get_ip($context); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | /** |
@@ -819,8 +819,8 @@ discard block |
||
| 819 | 819 | * @param string $context View or edit context. |
| 820 | 820 | * @return string |
| 821 | 821 | */ |
| 822 | - public function get_customer_ip( $context = 'view' ) { |
|
| 823 | - return $this->get_ip( $context ); |
|
| 822 | + public function get_customer_ip($context = 'view') { |
|
| 823 | + return $this->get_ip($context); |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | /** |
@@ -830,8 +830,8 @@ discard block |
||
| 830 | 830 | * @param string $context View or edit context. |
| 831 | 831 | * @return string |
| 832 | 832 | */ |
| 833 | - public function get_first_name( $context = 'view' ) { |
|
| 834 | - return $this->get_prop( 'first_name', $context ); |
|
| 833 | + public function get_first_name($context = 'view') { |
|
| 834 | + return $this->get_prop('first_name', $context); |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
@@ -841,8 +841,8 @@ discard block |
||
| 841 | 841 | * @param string $context View or edit context. |
| 842 | 842 | * @return string |
| 843 | 843 | */ |
| 844 | - public function get_user_first_name( $context = 'view' ) { |
|
| 845 | - return $this->get_first_name( $context ); |
|
| 844 | + public function get_user_first_name($context = 'view') { |
|
| 845 | + return $this->get_first_name($context); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | /** |
@@ -852,8 +852,8 @@ discard block |
||
| 852 | 852 | * @param string $context View or edit context. |
| 853 | 853 | * @return string |
| 854 | 854 | */ |
| 855 | - public function get_customer_first_name( $context = 'view' ) { |
|
| 856 | - return $this->get_first_name( $context ); |
|
| 855 | + public function get_customer_first_name($context = 'view') { |
|
| 856 | + return $this->get_first_name($context); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
@@ -863,8 +863,8 @@ discard block |
||
| 863 | 863 | * @param string $context View or edit context. |
| 864 | 864 | * @return string |
| 865 | 865 | */ |
| 866 | - public function get_last_name( $context = 'view' ) { |
|
| 867 | - return $this->get_prop( 'last_name', $context ); |
|
| 866 | + public function get_last_name($context = 'view') { |
|
| 867 | + return $this->get_prop('last_name', $context); |
|
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | /** |
@@ -874,8 +874,8 @@ discard block |
||
| 874 | 874 | * @param string $context View or edit context. |
| 875 | 875 | * @return string |
| 876 | 876 | */ |
| 877 | - public function get_user_last_name( $context = 'view' ) { |
|
| 878 | - return $this->get_last_name( $context ); |
|
| 877 | + public function get_user_last_name($context = 'view') { |
|
| 878 | + return $this->get_last_name($context); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | /** |
@@ -885,8 +885,8 @@ discard block |
||
| 885 | 885 | * @param string $context View or edit context. |
| 886 | 886 | * @return string |
| 887 | 887 | */ |
| 888 | - public function get_customer_last_name( $context = 'view' ) { |
|
| 889 | - return $this->get_last_name( $context ); |
|
| 888 | + public function get_customer_last_name($context = 'view') { |
|
| 889 | + return $this->get_last_name($context); |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | /** |
@@ -896,22 +896,22 @@ discard block |
||
| 896 | 896 | * @param string $context View or edit context. |
| 897 | 897 | * @return string |
| 898 | 898 | */ |
| 899 | - public function get_full_name( $context = 'view' ) { |
|
| 900 | - $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 899 | + public function get_full_name($context = 'view') { |
|
| 900 | + $name = trim($this->get_first_name($context) . ' ' . $this->get_last_name($context)); |
|
| 901 | 901 | |
| 902 | - if ( ! $name ) { |
|
| 903 | - $user = get_userdata( $this->get_author( $context ) ); |
|
| 902 | + if (!$name) { |
|
| 903 | + $user = get_userdata($this->get_author($context)); |
|
| 904 | 904 | |
| 905 | - if ( $user ) { |
|
| 905 | + if ($user) { |
|
| 906 | 906 | $name = $user->display_name; |
| 907 | 907 | } |
| 908 | 908 | } |
| 909 | 909 | |
| 910 | - if ( ! $name ) { |
|
| 911 | - $name = $this->get_email( $context ); |
|
| 910 | + if (!$name) { |
|
| 911 | + $name = $this->get_email($context); |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | - return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
| 914 | + return apply_filters('wpinv_invoice_user_full_name', $name, $this); |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | /** |
@@ -921,8 +921,8 @@ discard block |
||
| 921 | 921 | * @param string $context View or edit context. |
| 922 | 922 | * @return string |
| 923 | 923 | */ |
| 924 | - public function get_user_full_name( $context = 'view' ) { |
|
| 925 | - return $this->get_full_name( $context ); |
|
| 924 | + public function get_user_full_name($context = 'view') { |
|
| 925 | + return $this->get_full_name($context); |
|
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | /** |
@@ -932,8 +932,8 @@ discard block |
||
| 932 | 932 | * @param string $context View or edit context. |
| 933 | 933 | * @return string |
| 934 | 934 | */ |
| 935 | - public function get_customer_full_name( $context = 'view' ) { |
|
| 936 | - return $this->get_full_name( $context ); |
|
| 935 | + public function get_customer_full_name($context = 'view') { |
|
| 936 | + return $this->get_full_name($context); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | /** |
@@ -943,8 +943,8 @@ discard block |
||
| 943 | 943 | * @param string $context View or edit context. |
| 944 | 944 | * @return string |
| 945 | 945 | */ |
| 946 | - public function get_phone( $context = 'view' ) { |
|
| 947 | - return $this->get_prop( 'phone', $context ); |
|
| 946 | + public function get_phone($context = 'view') { |
|
| 947 | + return $this->get_prop('phone', $context); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | /** |
@@ -954,8 +954,8 @@ discard block |
||
| 954 | 954 | * @param string $context View or edit context. |
| 955 | 955 | * @return string |
| 956 | 956 | */ |
| 957 | - public function get_phone_number( $context = 'view' ) { |
|
| 958 | - return $this->get_phone( $context ); |
|
| 957 | + public function get_phone_number($context = 'view') { |
|
| 958 | + return $this->get_phone($context); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -965,8 +965,8 @@ discard block |
||
| 965 | 965 | * @param string $context View or edit context. |
| 966 | 966 | * @return string |
| 967 | 967 | */ |
| 968 | - public function get_user_phone( $context = 'view' ) { |
|
| 969 | - return $this->get_phone( $context ); |
|
| 968 | + public function get_user_phone($context = 'view') { |
|
| 969 | + return $this->get_phone($context); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
@@ -976,8 +976,8 @@ discard block |
||
| 976 | 976 | * @param string $context View or edit context. |
| 977 | 977 | * @return string |
| 978 | 978 | */ |
| 979 | - public function get_customer_phone( $context = 'view' ) { |
|
| 980 | - return $this->get_phone( $context ); |
|
| 979 | + public function get_customer_phone($context = 'view') { |
|
| 980 | + return $this->get_phone($context); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | /** |
@@ -987,8 +987,8 @@ discard block |
||
| 987 | 987 | * @param string $context View or edit context. |
| 988 | 988 | * @return string |
| 989 | 989 | */ |
| 990 | - public function get_email( $context = 'view' ) { |
|
| 991 | - return $this->get_prop( 'email', $context ); |
|
| 990 | + public function get_email($context = 'view') { |
|
| 991 | + return $this->get_prop('email', $context); |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | /** |
@@ -998,8 +998,8 @@ discard block |
||
| 998 | 998 | * @param string $context View or edit context. |
| 999 | 999 | * @return string |
| 1000 | 1000 | */ |
| 1001 | - public function get_email_address( $context = 'view' ) { |
|
| 1002 | - return $this->get_email( $context ); |
|
| 1001 | + public function get_email_address($context = 'view') { |
|
| 1002 | + return $this->get_email($context); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1009,8 +1009,8 @@ discard block |
||
| 1009 | 1009 | * @param string $context View or edit context. |
| 1010 | 1010 | * @return string |
| 1011 | 1011 | */ |
| 1012 | - public function get_user_email( $context = 'view' ) { |
|
| 1013 | - return $this->get_email( $context ); |
|
| 1012 | + public function get_user_email($context = 'view') { |
|
| 1013 | + return $this->get_email($context); |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | /** |
@@ -1020,8 +1020,8 @@ discard block |
||
| 1020 | 1020 | * @param string $context View or edit context. |
| 1021 | 1021 | * @return string |
| 1022 | 1022 | */ |
| 1023 | - public function get_customer_email( $context = 'view' ) { |
|
| 1024 | - return $this->get_email( $context ); |
|
| 1023 | + public function get_customer_email($context = 'view') { |
|
| 1024 | + return $this->get_email($context); |
|
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | /** |
@@ -1031,9 +1031,9 @@ discard block |
||
| 1031 | 1031 | * @param string $context View or edit context. |
| 1032 | 1032 | * @return string |
| 1033 | 1033 | */ |
| 1034 | - public function get_country( $context = 'view' ) { |
|
| 1035 | - $country = $this->get_prop( 'country', $context ); |
|
| 1036 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 1034 | + public function get_country($context = 'view') { |
|
| 1035 | + $country = $this->get_prop('country', $context); |
|
| 1036 | + return empty($country) ? wpinv_get_default_country() : $country; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | /** |
@@ -1043,8 +1043,8 @@ discard block |
||
| 1043 | 1043 | * @param string $context View or edit context. |
| 1044 | 1044 | * @return string |
| 1045 | 1045 | */ |
| 1046 | - public function get_user_country( $context = 'view' ) { |
|
| 1047 | - return $this->get_country( $context ); |
|
| 1046 | + public function get_user_country($context = 'view') { |
|
| 1047 | + return $this->get_country($context); |
|
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | 1050 | /** |
@@ -1054,8 +1054,8 @@ discard block |
||
| 1054 | 1054 | * @param string $context View or edit context. |
| 1055 | 1055 | * @return string |
| 1056 | 1056 | */ |
| 1057 | - public function get_customer_country( $context = 'view' ) { |
|
| 1058 | - return $this->get_country( $context ); |
|
| 1057 | + public function get_customer_country($context = 'view') { |
|
| 1058 | + return $this->get_country($context); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | /** |
@@ -1065,9 +1065,9 @@ discard block |
||
| 1065 | 1065 | * @param string $context View or edit context. |
| 1066 | 1066 | * @return string |
| 1067 | 1067 | */ |
| 1068 | - public function get_state( $context = 'view' ) { |
|
| 1069 | - $state = $this->get_prop( 'state', $context ); |
|
| 1070 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1068 | + public function get_state($context = 'view') { |
|
| 1069 | + $state = $this->get_prop('state', $context); |
|
| 1070 | + return empty($state) ? wpinv_get_default_state() : $state; |
|
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | /** |
@@ -1077,8 +1077,8 @@ discard block |
||
| 1077 | 1077 | * @param string $context View or edit context. |
| 1078 | 1078 | * @return string |
| 1079 | 1079 | */ |
| 1080 | - public function get_user_state( $context = 'view' ) { |
|
| 1081 | - return $this->get_state( $context ); |
|
| 1080 | + public function get_user_state($context = 'view') { |
|
| 1081 | + return $this->get_state($context); |
|
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | /** |
@@ -1088,8 +1088,8 @@ discard block |
||
| 1088 | 1088 | * @param string $context View or edit context. |
| 1089 | 1089 | * @return string |
| 1090 | 1090 | */ |
| 1091 | - public function get_customer_state( $context = 'view' ) { |
|
| 1092 | - return $this->get_state( $context ); |
|
| 1091 | + public function get_customer_state($context = 'view') { |
|
| 1092 | + return $this->get_state($context); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
@@ -1099,8 +1099,8 @@ discard block |
||
| 1099 | 1099 | * @param string $context View or edit context. |
| 1100 | 1100 | * @return string |
| 1101 | 1101 | */ |
| 1102 | - public function get_city( $context = 'view' ) { |
|
| 1103 | - return $this->get_prop( 'city', $context ); |
|
| 1102 | + public function get_city($context = 'view') { |
|
| 1103 | + return $this->get_prop('city', $context); |
|
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | /** |
@@ -1110,8 +1110,8 @@ discard block |
||
| 1110 | 1110 | * @param string $context View or edit context. |
| 1111 | 1111 | * @return string |
| 1112 | 1112 | */ |
| 1113 | - public function get_user_city( $context = 'view' ) { |
|
| 1114 | - return $this->get_city( $context ); |
|
| 1113 | + public function get_user_city($context = 'view') { |
|
| 1114 | + return $this->get_city($context); |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | /** |
@@ -1121,8 +1121,8 @@ discard block |
||
| 1121 | 1121 | * @param string $context View or edit context. |
| 1122 | 1122 | * @return string |
| 1123 | 1123 | */ |
| 1124 | - public function get_customer_city( $context = 'view' ) { |
|
| 1125 | - return $this->get_city( $context ); |
|
| 1124 | + public function get_customer_city($context = 'view') { |
|
| 1125 | + return $this->get_city($context); |
|
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | /** |
@@ -1132,8 +1132,8 @@ discard block |
||
| 1132 | 1132 | * @param string $context View or edit context. |
| 1133 | 1133 | * @return string |
| 1134 | 1134 | */ |
| 1135 | - public function get_zip( $context = 'view' ) { |
|
| 1136 | - return $this->get_prop( 'zip', $context ); |
|
| 1135 | + public function get_zip($context = 'view') { |
|
| 1136 | + return $this->get_prop('zip', $context); |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | /** |
@@ -1143,8 +1143,8 @@ discard block |
||
| 1143 | 1143 | * @param string $context View or edit context. |
| 1144 | 1144 | * @return string |
| 1145 | 1145 | */ |
| 1146 | - public function get_user_zip( $context = 'view' ) { |
|
| 1147 | - return $this->get_zip( $context ); |
|
| 1146 | + public function get_user_zip($context = 'view') { |
|
| 1147 | + return $this->get_zip($context); |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | /** |
@@ -1154,8 +1154,8 @@ discard block |
||
| 1154 | 1154 | * @param string $context View or edit context. |
| 1155 | 1155 | * @return string |
| 1156 | 1156 | */ |
| 1157 | - public function get_customer_zip( $context = 'view' ) { |
|
| 1158 | - return $this->get_zip( $context ); |
|
| 1157 | + public function get_customer_zip($context = 'view') { |
|
| 1158 | + return $this->get_zip($context); |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | /** |
@@ -1165,8 +1165,8 @@ discard block |
||
| 1165 | 1165 | * @param string $context View or edit context. |
| 1166 | 1166 | * @return string |
| 1167 | 1167 | */ |
| 1168 | - public function get_company( $context = 'view' ) { |
|
| 1169 | - return $this->get_prop( 'company', $context ); |
|
| 1168 | + public function get_company($context = 'view') { |
|
| 1169 | + return $this->get_prop('company', $context); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | /** |
@@ -1176,8 +1176,8 @@ discard block |
||
| 1176 | 1176 | * @param string $context View or edit context. |
| 1177 | 1177 | * @return string |
| 1178 | 1178 | */ |
| 1179 | - public function get_user_company( $context = 'view' ) { |
|
| 1180 | - return $this->get_company( $context ); |
|
| 1179 | + public function get_user_company($context = 'view') { |
|
| 1180 | + return $this->get_company($context); |
|
| 1181 | 1181 | } |
| 1182 | 1182 | |
| 1183 | 1183 | /** |
@@ -1187,8 +1187,8 @@ discard block |
||
| 1187 | 1187 | * @param string $context View or edit context. |
| 1188 | 1188 | * @return string |
| 1189 | 1189 | */ |
| 1190 | - public function get_customer_company( $context = 'view' ) { |
|
| 1191 | - return $this->get_company( $context ); |
|
| 1190 | + public function get_customer_company($context = 'view') { |
|
| 1191 | + return $this->get_company($context); |
|
| 1192 | 1192 | } |
| 1193 | 1193 | |
| 1194 | 1194 | /** |
@@ -1198,8 +1198,8 @@ discard block |
||
| 1198 | 1198 | * @param string $context View or edit context. |
| 1199 | 1199 | * @return string |
| 1200 | 1200 | */ |
| 1201 | - public function get_company_id( $context = 'view' ) { |
|
| 1202 | - return $this->get_prop( 'company_id', $context ); |
|
| 1201 | + public function get_company_id($context = 'view') { |
|
| 1202 | + return $this->get_prop('company_id', $context); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | 1205 | /** |
@@ -1209,8 +1209,8 @@ discard block |
||
| 1209 | 1209 | * @param string $context View or edit context. |
| 1210 | 1210 | * @return string |
| 1211 | 1211 | */ |
| 1212 | - public function get_vat_number( $context = 'view' ) { |
|
| 1213 | - return $this->get_prop( 'vat_number', $context ); |
|
| 1212 | + public function get_vat_number($context = 'view') { |
|
| 1213 | + return $this->get_prop('vat_number', $context); |
|
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | /** |
@@ -1220,8 +1220,8 @@ discard block |
||
| 1220 | 1220 | * @param string $context View or edit context. |
| 1221 | 1221 | * @return string |
| 1222 | 1222 | */ |
| 1223 | - public function get_user_vat_number( $context = 'view' ) { |
|
| 1224 | - return $this->get_vat_number( $context ); |
|
| 1223 | + public function get_user_vat_number($context = 'view') { |
|
| 1224 | + return $this->get_vat_number($context); |
|
| 1225 | 1225 | } |
| 1226 | 1226 | |
| 1227 | 1227 | /** |
@@ -1231,8 +1231,8 @@ discard block |
||
| 1231 | 1231 | * @param string $context View or edit context. |
| 1232 | 1232 | * @return string |
| 1233 | 1233 | */ |
| 1234 | - public function get_customer_vat_number( $context = 'view' ) { |
|
| 1235 | - return $this->get_vat_number( $context ); |
|
| 1234 | + public function get_customer_vat_number($context = 'view') { |
|
| 1235 | + return $this->get_vat_number($context); |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | /** |
@@ -1242,8 +1242,8 @@ discard block |
||
| 1242 | 1242 | * @param string $context View or edit context. |
| 1243 | 1243 | * @return string |
| 1244 | 1244 | */ |
| 1245 | - public function get_vat_rate( $context = 'view' ) { |
|
| 1246 | - return $this->get_prop( 'vat_rate', $context ); |
|
| 1245 | + public function get_vat_rate($context = 'view') { |
|
| 1246 | + return $this->get_prop('vat_rate', $context); |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | /** |
@@ -1253,8 +1253,8 @@ discard block |
||
| 1253 | 1253 | * @param string $context View or edit context. |
| 1254 | 1254 | * @return string |
| 1255 | 1255 | */ |
| 1256 | - public function get_user_vat_rate( $context = 'view' ) { |
|
| 1257 | - return $this->get_vat_rate( $context ); |
|
| 1256 | + public function get_user_vat_rate($context = 'view') { |
|
| 1257 | + return $this->get_vat_rate($context); |
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | /** |
@@ -1264,8 +1264,8 @@ discard block |
||
| 1264 | 1264 | * @param string $context View or edit context. |
| 1265 | 1265 | * @return string |
| 1266 | 1266 | */ |
| 1267 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1268 | - return $this->get_vat_rate( $context ); |
|
| 1267 | + public function get_customer_vat_rate($context = 'view') { |
|
| 1268 | + return $this->get_vat_rate($context); |
|
| 1269 | 1269 | } |
| 1270 | 1270 | |
| 1271 | 1271 | /** |
@@ -1275,8 +1275,8 @@ discard block |
||
| 1275 | 1275 | * @param string $context View or edit context. |
| 1276 | 1276 | * @return string |
| 1277 | 1277 | */ |
| 1278 | - public function get_address( $context = 'view' ) { |
|
| 1279 | - return $this->get_prop( 'address', $context ); |
|
| 1278 | + public function get_address($context = 'view') { |
|
| 1279 | + return $this->get_prop('address', $context); |
|
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | /** |
@@ -1286,8 +1286,8 @@ discard block |
||
| 1286 | 1286 | * @param string $context View or edit context. |
| 1287 | 1287 | * @return string |
| 1288 | 1288 | */ |
| 1289 | - public function get_user_address( $context = 'view' ) { |
|
| 1290 | - return $this->get_address( $context ); |
|
| 1289 | + public function get_user_address($context = 'view') { |
|
| 1290 | + return $this->get_address($context); |
|
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | 1293 | /** |
@@ -1297,8 +1297,8 @@ discard block |
||
| 1297 | 1297 | * @param string $context View or edit context. |
| 1298 | 1298 | * @return string |
| 1299 | 1299 | */ |
| 1300 | - public function get_customer_address( $context = 'view' ) { |
|
| 1301 | - return $this->get_address( $context ); |
|
| 1300 | + public function get_customer_address($context = 'view') { |
|
| 1301 | + return $this->get_address($context); |
|
| 1302 | 1302 | } |
| 1303 | 1303 | |
| 1304 | 1304 | /** |
@@ -1308,8 +1308,8 @@ discard block |
||
| 1308 | 1308 | * @param string $context View or edit context. |
| 1309 | 1309 | * @return bool |
| 1310 | 1310 | */ |
| 1311 | - public function get_is_viewed( $context = 'view' ) { |
|
| 1312 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1311 | + public function get_is_viewed($context = 'view') { |
|
| 1312 | + return (bool) $this->get_prop('is_viewed', $context); |
|
| 1313 | 1313 | } |
| 1314 | 1314 | |
| 1315 | 1315 | /** |
@@ -1319,8 +1319,8 @@ discard block |
||
| 1319 | 1319 | * @param string $context View or edit context. |
| 1320 | 1320 | * @return bool |
| 1321 | 1321 | */ |
| 1322 | - public function get_email_cc( $context = 'view' ) { |
|
| 1323 | - return $this->get_prop( 'email_cc', $context ); |
|
| 1322 | + public function get_email_cc($context = 'view') { |
|
| 1323 | + return $this->get_prop('email_cc', $context); |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | /** |
@@ -1330,8 +1330,8 @@ discard block |
||
| 1330 | 1330 | * @param string $context View or edit context. |
| 1331 | 1331 | * @return bool |
| 1332 | 1332 | */ |
| 1333 | - public function get_template( $context = 'view' ) { |
|
| 1334 | - return $this->get_prop( 'template', $context ); |
|
| 1333 | + public function get_template($context = 'view') { |
|
| 1334 | + return $this->get_prop('template', $context); |
|
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | /** |
@@ -1341,8 +1341,8 @@ discard block |
||
| 1341 | 1341 | * @param string $context View or edit context. |
| 1342 | 1342 | * @return bool |
| 1343 | 1343 | */ |
| 1344 | - public function get_created_via( $context = 'view' ) { |
|
| 1345 | - return $this->get_prop( 'created_via', $context ); |
|
| 1344 | + public function get_created_via($context = 'view') { |
|
| 1345 | + return $this->get_prop('created_via', $context); |
|
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | 1348 | /** |
@@ -1352,8 +1352,8 @@ discard block |
||
| 1352 | 1352 | * @param string $context View or edit context. |
| 1353 | 1353 | * @return bool |
| 1354 | 1354 | */ |
| 1355 | - public function get_address_confirmed( $context = 'view' ) { |
|
| 1356 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1355 | + public function get_address_confirmed($context = 'view') { |
|
| 1356 | + return (bool) $this->get_prop('address_confirmed', $context); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | 1359 | /** |
@@ -1363,8 +1363,8 @@ discard block |
||
| 1363 | 1363 | * @param string $context View or edit context. |
| 1364 | 1364 | * @return bool |
| 1365 | 1365 | */ |
| 1366 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1367 | - return $this->get_address_confirmed( $context ); |
|
| 1366 | + public function get_user_address_confirmed($context = 'view') { |
|
| 1367 | + return $this->get_address_confirmed($context); |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | /** |
@@ -1374,8 +1374,8 @@ discard block |
||
| 1374 | 1374 | * @param string $context View or edit context. |
| 1375 | 1375 | * @return bool |
| 1376 | 1376 | */ |
| 1377 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1378 | - return $this->get_address_confirmed( $context ); |
|
| 1377 | + public function get_customer_address_confirmed($context = 'view') { |
|
| 1378 | + return $this->get_address_confirmed($context); |
|
| 1379 | 1379 | } |
| 1380 | 1380 | |
| 1381 | 1381 | /** |
@@ -1386,8 +1386,8 @@ discard block |
||
| 1386 | 1386 | */ |
| 1387 | 1387 | public function get_shipping_address() { |
| 1388 | 1388 | |
| 1389 | - $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
| 1390 | - return is_array( $shipping_address ) ? $shipping_address : false; |
|
| 1389 | + $shipping_address = get_post_meta($this->get_id(), 'shipping_address', true); |
|
| 1390 | + return is_array($shipping_address) ? $shipping_address : false; |
|
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | 1393 | /** |
@@ -1404,17 +1404,17 @@ discard block |
||
| 1404 | 1404 | * @param string $context View or edit context. |
| 1405 | 1405 | * @return float |
| 1406 | 1406 | */ |
| 1407 | - public function get_shipping( $context = 'view' ) { |
|
| 1407 | + public function get_shipping($context = 'view') { |
|
| 1408 | 1408 | |
| 1409 | - if ( $context = 'view' ) { |
|
| 1410 | - return floatval( $this->get_prop( 'shipping', $context ) ); |
|
| 1409 | + if ($context = 'view') { |
|
| 1410 | + return floatval($this->get_prop('shipping', $context)); |
|
| 1411 | 1411 | } |
| 1412 | 1412 | |
| 1413 | - return $this->get_prop( 'shipping', $context ); |
|
| 1413 | + return $this->get_prop('shipping', $context); |
|
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | 1416 | public function has_shipping() { |
| 1417 | - return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && $this->get_prop( 'shipping', 'edit' ); |
|
| 1417 | + return defined('GETPAID_SHIPPING_CALCULATOR_VERSION') && $this->get_prop('shipping', 'edit'); |
|
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | /** |
@@ -1424,12 +1424,12 @@ discard block |
||
| 1424 | 1424 | * @param string $context View or edit context. |
| 1425 | 1425 | * @return float |
| 1426 | 1426 | */ |
| 1427 | - public function get_subtotal( $context = 'view' ) { |
|
| 1428 | - $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
|
| 1427 | + public function get_subtotal($context = 'view') { |
|
| 1428 | + $subtotal = (float) $this->get_prop('subtotal', $context); |
|
| 1429 | 1429 | |
| 1430 | 1430 | // Backwards compatibility. |
| 1431 | - if ( is_bool( $context ) && $context ) { |
|
| 1432 | - return wpinv_price( $subtotal, $this->get_currency() ); |
|
| 1431 | + if (is_bool($context) && $context) { |
|
| 1432 | + return wpinv_price($subtotal, $this->get_currency()); |
|
| 1433 | 1433 | } |
| 1434 | 1434 | |
| 1435 | 1435 | return $subtotal; |
@@ -1442,8 +1442,8 @@ discard block |
||
| 1442 | 1442 | * @param string $context View or edit context. |
| 1443 | 1443 | * @return float |
| 1444 | 1444 | */ |
| 1445 | - public function get_total_discount( $context = 'view' ) { |
|
| 1446 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
| 1445 | + public function get_total_discount($context = 'view') { |
|
| 1446 | + return wpinv_round_amount(wpinv_sanitize_amount($this->get_prop('total_discount', $context))); |
|
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | /** |
@@ -1453,18 +1453,18 @@ discard block |
||
| 1453 | 1453 | * @param string $context View or edit context. |
| 1454 | 1454 | * @return float |
| 1455 | 1455 | */ |
| 1456 | - public function get_total_tax( $context = 'view' ) { |
|
| 1457 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
| 1456 | + public function get_total_tax($context = 'view') { |
|
| 1457 | + return wpinv_round_amount(wpinv_sanitize_amount($this->get_prop('total_tax', $context))); |
|
| 1458 | 1458 | } |
| 1459 | 1459 | |
| 1460 | 1460 | /** |
| 1461 | 1461 | * @deprecated |
| 1462 | 1462 | */ |
| 1463 | - public function get_final_tax( $currency = false ) { |
|
| 1463 | + public function get_final_tax($currency = false) { |
|
| 1464 | 1464 | $tax = $this->get_total_tax(); |
| 1465 | 1465 | |
| 1466 | - if ( $currency ) { |
|
| 1467 | - return wpinv_price( $tax, $this->get_currency() ); |
|
| 1466 | + if ($currency) { |
|
| 1467 | + return wpinv_price($tax, $this->get_currency()); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | 1470 | return $tax; |
@@ -1477,8 +1477,8 @@ discard block |
||
| 1477 | 1477 | * @param string $context View or edit context. |
| 1478 | 1478 | * @return float |
| 1479 | 1479 | */ |
| 1480 | - public function get_total_fees( $context = 'view' ) { |
|
| 1481 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
| 1480 | + public function get_total_fees($context = 'view') { |
|
| 1481 | + return wpinv_round_amount(wpinv_sanitize_amount($this->get_prop('total_fees', $context))); |
|
| 1482 | 1482 | } |
| 1483 | 1483 | |
| 1484 | 1484 | /** |
@@ -1488,8 +1488,8 @@ discard block |
||
| 1488 | 1488 | * @param string $context View or edit context. |
| 1489 | 1489 | * @return float |
| 1490 | 1490 | */ |
| 1491 | - public function get_fees_total( $context = 'view' ) { |
|
| 1492 | - return $this->get_total_fees( $context ); |
|
| 1491 | + public function get_fees_total($context = 'view') { |
|
| 1492 | + return $this->get_total_fees($context); |
|
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | 1495 | /** |
@@ -1498,14 +1498,14 @@ discard block |
||
| 1498 | 1498 | * @since 1.0.19 |
| 1499 | 1499 | * @return float |
| 1500 | 1500 | */ |
| 1501 | - public function get_total( $context = 'view' ) { |
|
| 1502 | - $total = $this->get_prop( 'total', $context ); |
|
| 1501 | + public function get_total($context = 'view') { |
|
| 1502 | + $total = $this->get_prop('total', $context); |
|
| 1503 | 1503 | |
| 1504 | - if ( $this->has_shipping() && $context == 'view' ) { |
|
| 1505 | - $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
| 1504 | + if ($this->has_shipping() && $context == 'view') { |
|
| 1505 | + $total = $this->get_prop('total', $context) + $this->get_shipping($context); |
|
| 1506 | 1506 | } |
| 1507 | 1507 | |
| 1508 | - return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1508 | + return wpinv_round_amount(wpinv_sanitize_amount($total)); |
|
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | /** |
@@ -1517,20 +1517,20 @@ discard block |
||
| 1517 | 1517 | public function get_non_recurring_total() { |
| 1518 | 1518 | |
| 1519 | 1519 | $subtotal = 0; |
| 1520 | - foreach ( $this->get_items() as $item ) { |
|
| 1521 | - if ( ! $item->is_recurring() ) { |
|
| 1520 | + foreach ($this->get_items() as $item) { |
|
| 1521 | + if (!$item->is_recurring()) { |
|
| 1522 | 1522 | $subtotal += $item->get_sub_total(); |
| 1523 | 1523 | } |
| 1524 | 1524 | } |
| 1525 | 1525 | |
| 1526 | - foreach ( $this->get_fees() as $fee ) { |
|
| 1527 | - if ( empty( $fee['recurring_fee'] ) ) { |
|
| 1528 | - $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 1526 | + foreach ($this->get_fees() as $fee) { |
|
| 1527 | + if (empty($fee['recurring_fee'])) { |
|
| 1528 | + $subtotal += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 1529 | 1529 | } |
| 1530 | 1530 | } |
| 1531 | 1531 | |
| 1532 | - $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
| 1533 | - return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this ); |
|
| 1532 | + $subtotal = wpinv_round_amount(wpinv_sanitize_amount($subtotal)); |
|
| 1533 | + return apply_filters('wpinv_get_non_recurring_invoice_total', $subtotal, $this); |
|
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | 1536 | /** |
@@ -1552,7 +1552,7 @@ discard block |
||
| 1552 | 1552 | */ |
| 1553 | 1553 | public function get_initial_total() { |
| 1554 | 1554 | |
| 1555 | - if ( empty( $this->totals ) ) { |
|
| 1555 | + if (empty($this->totals)) { |
|
| 1556 | 1556 | $this->recalculate_total(); |
| 1557 | 1557 | } |
| 1558 | 1558 | |
@@ -1562,12 +1562,12 @@ discard block |
||
| 1562 | 1562 | $subtotal = $this->totals['subtotal']['initial']; |
| 1563 | 1563 | $total = $tax + $fee - $discount + $subtotal; |
| 1564 | 1564 | |
| 1565 | - if ( 0 > $total ) { |
|
| 1565 | + if (0 > $total) { |
|
| 1566 | 1566 | $total = 0; |
| 1567 | 1567 | } |
| 1568 | 1568 | |
| 1569 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1570 | - return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
|
| 1569 | + $total = wpinv_round_amount(wpinv_sanitize_amount($total)); |
|
| 1570 | + return apply_filters('wpinv_get_initial_invoice_total', $total, $this); |
|
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | 1573 | /** |
@@ -1579,7 +1579,7 @@ discard block |
||
| 1579 | 1579 | */ |
| 1580 | 1580 | public function get_recurring_total() { |
| 1581 | 1581 | |
| 1582 | - if ( empty( $this->totals ) ) { |
|
| 1582 | + if (empty($this->totals)) { |
|
| 1583 | 1583 | $this->recalculate_total(); |
| 1584 | 1584 | } |
| 1585 | 1585 | |
@@ -1589,12 +1589,12 @@ discard block |
||
| 1589 | 1589 | $subtotal = $this->totals['subtotal']['recurring']; |
| 1590 | 1590 | $total = $tax + $fee - $discount + $subtotal; |
| 1591 | 1591 | |
| 1592 | - if ( 0 > $total ) { |
|
| 1592 | + if (0 > $total) { |
|
| 1593 | 1593 | $total = 0; |
| 1594 | 1594 | } |
| 1595 | 1595 | |
| 1596 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1597 | - return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
|
| 1596 | + $total = wpinv_round_amount(wpinv_sanitize_amount($total)); |
|
| 1597 | + return apply_filters('wpinv_get_recurring_invoice_total', $total, $this); |
|
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | 1600 | /** |
@@ -1605,10 +1605,10 @@ discard block |
||
| 1605 | 1605 | * @param string $currency Whether to include the currency. |
| 1606 | 1606 | * @return float|string |
| 1607 | 1607 | */ |
| 1608 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
| 1608 | + public function get_recurring_details($field = '', $currency = false) { |
|
| 1609 | 1609 | |
| 1610 | 1610 | // Maybe recalculate totals. |
| 1611 | - if ( empty( $this->totals ) ) { |
|
| 1611 | + if (empty($this->totals)) { |
|
| 1612 | 1612 | $this->recalculate_total(); |
| 1613 | 1613 | } |
| 1614 | 1614 | |
@@ -1628,8 +1628,8 @@ discard block |
||
| 1628 | 1628 | $currency |
| 1629 | 1629 | ); |
| 1630 | 1630 | |
| 1631 | - if ( isset( $data[ $field ] ) ) { |
|
| 1632 | - return ( $currency ? wpinv_price( $data[ $field ], $this->get_currency() ) : $data[ $field ] ); |
|
| 1631 | + if (isset($data[$field])) { |
|
| 1632 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
| 1633 | 1633 | } |
| 1634 | 1634 | |
| 1635 | 1635 | return $data; |
@@ -1642,8 +1642,8 @@ discard block |
||
| 1642 | 1642 | * @param string $context View or edit context. |
| 1643 | 1643 | * @return array |
| 1644 | 1644 | */ |
| 1645 | - public function get_fees( $context = 'view' ) { |
|
| 1646 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1645 | + public function get_fees($context = 'view') { |
|
| 1646 | + return wpinv_parse_list($this->get_prop('fees', $context)); |
|
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | 1649 | /** |
@@ -1653,8 +1653,8 @@ discard block |
||
| 1653 | 1653 | * @param string $context View or edit context. |
| 1654 | 1654 | * @return array |
| 1655 | 1655 | */ |
| 1656 | - public function get_discounts( $context = 'view' ) { |
|
| 1657 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1656 | + public function get_discounts($context = 'view') { |
|
| 1657 | + return wpinv_parse_list($this->get_prop('discounts', $context)); |
|
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | 1660 | /** |
@@ -1664,8 +1664,8 @@ discard block |
||
| 1664 | 1664 | * @param string $context View or edit context. |
| 1665 | 1665 | * @return array |
| 1666 | 1666 | */ |
| 1667 | - public function get_taxes( $context = 'view' ) { |
|
| 1668 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1667 | + public function get_taxes($context = 'view') { |
|
| 1668 | + return wpinv_parse_list($this->get_prop('taxes', $context)); |
|
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | /** |
@@ -1675,8 +1675,8 @@ discard block |
||
| 1675 | 1675 | * @param string $context View or edit context. |
| 1676 | 1676 | * @return GetPaid_Form_Item[] |
| 1677 | 1677 | */ |
| 1678 | - public function get_items( $context = 'view' ) { |
|
| 1679 | - return $this->get_prop( 'items', $context ); |
|
| 1678 | + public function get_items($context = 'view') { |
|
| 1679 | + return $this->get_prop('items', $context); |
|
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | 1682 | /** |
@@ -1686,7 +1686,7 @@ discard block |
||
| 1686 | 1686 | * @return string |
| 1687 | 1687 | */ |
| 1688 | 1688 | public function get_item_ids() { |
| 1689 | - return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
| 1689 | + return implode(', ', wp_list_pluck($this->get_cart_details(), 'item_id')); |
|
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | 1692 | /** |
@@ -1696,8 +1696,8 @@ discard block |
||
| 1696 | 1696 | * @param string $context View or edit context. |
| 1697 | 1697 | * @return int |
| 1698 | 1698 | */ |
| 1699 | - public function get_payment_form( $context = 'view' ) { |
|
| 1700 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1699 | + public function get_payment_form($context = 'view') { |
|
| 1700 | + return intval($this->get_prop('payment_form', $context)); |
|
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | 1703 | /** |
@@ -1707,8 +1707,8 @@ discard block |
||
| 1707 | 1707 | * @param string $context View or edit context. |
| 1708 | 1708 | * @return string |
| 1709 | 1709 | */ |
| 1710 | - public function get_submission_id( $context = 'view' ) { |
|
| 1711 | - return $this->get_prop( 'submission_id', $context ); |
|
| 1710 | + public function get_submission_id($context = 'view') { |
|
| 1711 | + return $this->get_prop('submission_id', $context); |
|
| 1712 | 1712 | } |
| 1713 | 1713 | |
| 1714 | 1714 | /** |
@@ -1718,8 +1718,8 @@ discard block |
||
| 1718 | 1718 | * @param string $context View or edit context. |
| 1719 | 1719 | * @return string |
| 1720 | 1720 | */ |
| 1721 | - public function get_discount_code( $context = 'view' ) { |
|
| 1722 | - return $this->get_prop( 'discount_code', $context ); |
|
| 1721 | + public function get_discount_code($context = 'view') { |
|
| 1722 | + return $this->get_prop('discount_code', $context); |
|
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | 1725 | /** |
@@ -1729,8 +1729,8 @@ discard block |
||
| 1729 | 1729 | * @param string $context View or edit context. |
| 1730 | 1730 | * @return string |
| 1731 | 1731 | */ |
| 1732 | - public function get_gateway( $context = 'view' ) { |
|
| 1733 | - return $this->get_prop( 'gateway', $context ); |
|
| 1732 | + public function get_gateway($context = 'view') { |
|
| 1733 | + return $this->get_prop('gateway', $context); |
|
| 1734 | 1734 | } |
| 1735 | 1735 | |
| 1736 | 1736 | /** |
@@ -1740,8 +1740,8 @@ discard block |
||
| 1740 | 1740 | * @return string |
| 1741 | 1741 | */ |
| 1742 | 1742 | public function get_gateway_title() { |
| 1743 | - $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
|
| 1744 | - return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
|
| 1743 | + $title = wpinv_get_gateway_checkout_label($this->get_gateway()); |
|
| 1744 | + return apply_filters('wpinv_gateway_title', $title, $this->get_id(), $this); |
|
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | 1747 | /** |
@@ -1751,8 +1751,8 @@ discard block |
||
| 1751 | 1751 | * @param string $context View or edit context. |
| 1752 | 1752 | * @return string |
| 1753 | 1753 | */ |
| 1754 | - public function get_transaction_id( $context = 'view' ) { |
|
| 1755 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 1754 | + public function get_transaction_id($context = 'view') { |
|
| 1755 | + return $this->get_prop('transaction_id', $context); |
|
| 1756 | 1756 | } |
| 1757 | 1757 | |
| 1758 | 1758 | /** |
@@ -1762,9 +1762,9 @@ discard block |
||
| 1762 | 1762 | * @param string $context View or edit context. |
| 1763 | 1763 | * @return string |
| 1764 | 1764 | */ |
| 1765 | - public function get_currency( $context = 'view' ) { |
|
| 1766 | - $currency = $this->get_prop( 'currency', $context ); |
|
| 1767 | - return empty( $currency ) ? wpinv_get_currency() : $currency; |
|
| 1765 | + public function get_currency($context = 'view') { |
|
| 1766 | + $currency = $this->get_prop('currency', $context); |
|
| 1767 | + return empty($currency) ? wpinv_get_currency() : $currency; |
|
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | /** |
@@ -1774,8 +1774,8 @@ discard block |
||
| 1774 | 1774 | * @param string $context View or edit context. |
| 1775 | 1775 | * @return bool |
| 1776 | 1776 | */ |
| 1777 | - public function get_disable_taxes( $context = 'view' ) { |
|
| 1778 | - return (bool) $this->get_prop( 'disable_taxes', $context ); |
|
| 1777 | + public function get_disable_taxes($context = 'view') { |
|
| 1778 | + return (bool) $this->get_prop('disable_taxes', $context); |
|
| 1779 | 1779 | } |
| 1780 | 1780 | |
| 1781 | 1781 | /** |
@@ -1785,8 +1785,8 @@ discard block |
||
| 1785 | 1785 | * @param string $context View or edit context. |
| 1786 | 1786 | * @return int |
| 1787 | 1787 | */ |
| 1788 | - public function get_subscription_id( $context = 'view' ) { |
|
| 1789 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1788 | + public function get_subscription_id($context = 'view') { |
|
| 1789 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id($context) : $this->get_prop('subscription_id', $context); |
|
| 1790 | 1790 | } |
| 1791 | 1791 | |
| 1792 | 1792 | /** |
@@ -1796,12 +1796,12 @@ discard block |
||
| 1796 | 1796 | * @param string $context View or edit context. |
| 1797 | 1797 | * @return int |
| 1798 | 1798 | */ |
| 1799 | - public function get_remote_subscription_id( $context = 'view' ) { |
|
| 1800 | - $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
|
| 1799 | + public function get_remote_subscription_id($context = 'view') { |
|
| 1800 | + $subscription_id = $this->get_prop('remote_subscription_id', $context); |
|
| 1801 | 1801 | |
| 1802 | - if ( empty( $subscription_id ) && $this->is_renewal() ) { |
|
| 1802 | + if (empty($subscription_id) && $this->is_renewal()) { |
|
| 1803 | 1803 | $parent = $this->get_parent(); |
| 1804 | - return $parent->get_remote_subscription_id( $context ); |
|
| 1804 | + return $parent->get_remote_subscription_id($context); |
|
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | 1807 | return $subscription_id; |
@@ -1814,8 +1814,8 @@ discard block |
||
| 1814 | 1814 | * @param string $context View or edit context. |
| 1815 | 1815 | * @return string |
| 1816 | 1816 | */ |
| 1817 | - public function get_is_anonymized( $context = 'view' ) { |
|
| 1818 | - return (bool) $this->get_prop( 'is_anonymized', $context ); |
|
| 1817 | + public function get_is_anonymized($context = 'view') { |
|
| 1818 | + return (bool) $this->get_prop('is_anonymized', $context); |
|
| 1819 | 1819 | } |
| 1820 | 1820 | |
| 1821 | 1821 | /** |
@@ -1825,20 +1825,20 @@ discard block |
||
| 1825 | 1825 | * @param string $context View or edit context. |
| 1826 | 1826 | * @return array |
| 1827 | 1827 | */ |
| 1828 | - public function get_payment_meta( $context = 'view' ) { |
|
| 1828 | + public function get_payment_meta($context = 'view') { |
|
| 1829 | 1829 | |
| 1830 | 1830 | return array( |
| 1831 | - 'price' => $this->get_total( $context ), |
|
| 1832 | - 'date' => $this->get_date_created( $context ), |
|
| 1833 | - 'user_email' => $this->get_email( $context ), |
|
| 1834 | - 'invoice_key' => $this->get_key( $context ), |
|
| 1835 | - 'currency' => $this->get_currency( $context ), |
|
| 1836 | - 'items' => $this->get_items( $context ), |
|
| 1837 | - 'user_info' => $this->get_user_info( $context ), |
|
| 1831 | + 'price' => $this->get_total($context), |
|
| 1832 | + 'date' => $this->get_date_created($context), |
|
| 1833 | + 'user_email' => $this->get_email($context), |
|
| 1834 | + 'invoice_key' => $this->get_key($context), |
|
| 1835 | + 'currency' => $this->get_currency($context), |
|
| 1836 | + 'items' => $this->get_items($context), |
|
| 1837 | + 'user_info' => $this->get_user_info($context), |
|
| 1838 | 1838 | 'cart_details' => $this->get_cart_details(), |
| 1839 | - 'status' => $this->get_status( $context ), |
|
| 1840 | - 'fees' => $this->get_fees( $context ), |
|
| 1841 | - 'taxes' => $this->get_taxes( $context ), |
|
| 1839 | + 'status' => $this->get_status($context), |
|
| 1840 | + 'fees' => $this->get_fees($context), |
|
| 1841 | + 'taxes' => $this->get_taxes($context), |
|
| 1842 | 1842 | ); |
| 1843 | 1843 | } |
| 1844 | 1844 | |
@@ -1852,9 +1852,9 @@ discard block |
||
| 1852 | 1852 | $items = $this->get_items(); |
| 1853 | 1853 | $cart_details = array(); |
| 1854 | 1854 | |
| 1855 | - foreach ( $items as $item ) { |
|
| 1855 | + foreach ($items as $item) { |
|
| 1856 | 1856 | $item->invoice_id = $this->get_id(); |
| 1857 | - $cart_details[] = $item->prepare_data_for_saving(); |
|
| 1857 | + $cart_details[] = $item->prepare_data_for_saving(); |
|
| 1858 | 1858 | } |
| 1859 | 1859 | |
| 1860 | 1860 | return $cart_details; |
@@ -1865,11 +1865,11 @@ discard block |
||
| 1865 | 1865 | * |
| 1866 | 1866 | * @return null|GetPaid_Form_Item|int |
| 1867 | 1867 | */ |
| 1868 | - public function get_recurring( $object = false ) { |
|
| 1868 | + public function get_recurring($object = false) { |
|
| 1869 | 1869 | |
| 1870 | 1870 | // Are we returning an object? |
| 1871 | - if ( $object ) { |
|
| 1872 | - return $this->get_item( $this->recurring_item ); |
|
| 1871 | + if ($object) { |
|
| 1872 | + return $this->get_item($this->recurring_item); |
|
| 1873 | 1873 | } |
| 1874 | 1874 | |
| 1875 | 1875 | return $this->recurring_item; |
@@ -1884,15 +1884,15 @@ discard block |
||
| 1884 | 1884 | public function get_subscription_name() { |
| 1885 | 1885 | |
| 1886 | 1886 | // Retrieve the recurring name |
| 1887 | - $item = $this->get_recurring( true ); |
|
| 1887 | + $item = $this->get_recurring(true); |
|
| 1888 | 1888 | |
| 1889 | 1889 | // Abort if it does not exist. |
| 1890 | - if ( empty( $item ) ) { |
|
| 1890 | + if (empty($item)) { |
|
| 1891 | 1891 | return ''; |
| 1892 | 1892 | } |
| 1893 | 1893 | |
| 1894 | 1894 | // Return the item name. |
| 1895 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
|
| 1895 | + return apply_filters('wpinv_invoice_get_subscription_name', $item->get_name(), $this); |
|
| 1896 | 1896 | } |
| 1897 | 1897 | |
| 1898 | 1898 | /** |
@@ -1902,9 +1902,9 @@ discard block |
||
| 1902 | 1902 | * @return string |
| 1903 | 1903 | */ |
| 1904 | 1904 | public function get_view_url() { |
| 1905 | - $invoice_url = get_permalink( $this->get_id() ); |
|
| 1906 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1907 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
|
| 1905 | + $invoice_url = get_permalink($this->get_id()); |
|
| 1906 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
| 1907 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this); |
|
| 1908 | 1908 | } |
| 1909 | 1909 | |
| 1910 | 1910 | /** |
@@ -1913,25 +1913,25 @@ discard block |
||
| 1913 | 1913 | * @since 1.0.19 |
| 1914 | 1914 | * @return string |
| 1915 | 1915 | */ |
| 1916 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1916 | + public function get_checkout_payment_url($deprecated = false, $secret = false) { |
|
| 1917 | 1917 | |
| 1918 | 1918 | // Retrieve the checkout url. |
| 1919 | 1919 | $pay_url = wpinv_get_checkout_uri(); |
| 1920 | 1920 | |
| 1921 | 1921 | // Maybe force ssl. |
| 1922 | - if ( is_ssl() ) { |
|
| 1923 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
| 1922 | + if (is_ssl()) { |
|
| 1923 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
| 1924 | 1924 | } |
| 1925 | 1925 | |
| 1926 | 1926 | // Add the invoice key. |
| 1927 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1927 | + $pay_url = add_query_arg('invoice_key', $this->get_key(), $pay_url); |
|
| 1928 | 1928 | |
| 1929 | 1929 | // (Maybe?) add a secret |
| 1930 | - if ( $secret ) { |
|
| 1931 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
|
| 1930 | + if ($secret) { |
|
| 1931 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $pay_url); |
|
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
|
| 1934 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret); |
|
| 1935 | 1935 | } |
| 1936 | 1936 | |
| 1937 | 1937 | /** |
@@ -1946,14 +1946,14 @@ discard block |
||
| 1946 | 1946 | $receipt_url = wpinv_get_success_page_uri(); |
| 1947 | 1947 | |
| 1948 | 1948 | // Maybe force ssl. |
| 1949 | - if ( is_ssl() ) { |
|
| 1950 | - $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
|
| 1949 | + if (is_ssl()) { |
|
| 1950 | + $receipt_url = str_replace('http:', 'https:', $receipt_url); |
|
| 1951 | 1951 | } |
| 1952 | 1952 | |
| 1953 | 1953 | // Add the invoice key. |
| 1954 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1954 | + $receipt_url = add_query_arg('invoice_key', $this->get_key(), $receipt_url); |
|
| 1955 | 1955 | |
| 1956 | - return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
|
| 1956 | + return apply_filters('getpaid_get_invoice_receipt_url', $receipt_url, $this); |
|
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | 1959 | /** |
@@ -1963,7 +1963,7 @@ discard block |
||
| 1963 | 1963 | * @return string |
| 1964 | 1964 | */ |
| 1965 | 1965 | public function get_transaction_url() { |
| 1966 | - return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
| 1966 | + return apply_filters('getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this); |
|
| 1967 | 1967 | } |
| 1968 | 1968 | |
| 1969 | 1969 | /** |
@@ -1976,7 +1976,7 @@ discard block |
||
| 1976 | 1976 | |
| 1977 | 1977 | $type = $this->get_type(); |
| 1978 | 1978 | $status = "wpi-$type-pending"; |
| 1979 | - return str_replace( '-invoice', '', $status ); |
|
| 1979 | + return str_replace('-invoice', '', $status); |
|
| 1980 | 1980 | } |
| 1981 | 1981 | |
| 1982 | 1982 | /** |
@@ -1989,14 +1989,14 @@ discard block |
||
| 1989 | 1989 | * @param string $context View or edit context. |
| 1990 | 1990 | * @return mixed Value of the given invoice property (if set). |
| 1991 | 1991 | */ |
| 1992 | - public function get( $key, $context = 'view' ) { |
|
| 1992 | + public function get($key, $context = 'view') { |
|
| 1993 | 1993 | $method = "get_$key"; |
| 1994 | 1994 | |
| 1995 | - if ( is_callable( array( $this, $method ) ) ) { |
|
| 1996 | - return $this->$method( $context ); |
|
| 1995 | + if (is_callable(array($this, $method))) { |
|
| 1996 | + return $this->$method($context); |
|
| 1997 | 1997 | } |
| 1998 | 1998 | |
| 1999 | - return $this->get_prop( $key, $context ); |
|
| 1999 | + return $this->get_prop($key, $context); |
|
| 2000 | 2000 | } |
| 2001 | 2001 | |
| 2002 | 2002 | /* |
@@ -2019,11 +2019,11 @@ discard block |
||
| 2019 | 2019 | * @param mixed $value new value. |
| 2020 | 2020 | * @return mixed Value of the given invoice property (if set). |
| 2021 | 2021 | */ |
| 2022 | - public function set( $key, $value ) { |
|
| 2022 | + public function set($key, $value) { |
|
| 2023 | 2023 | |
| 2024 | 2024 | $setter = "set_$key"; |
| 2025 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
| 2026 | - $this->{$setter}( $value ); |
|
| 2025 | + if (is_callable(array($this, $setter))) { |
|
| 2026 | + $this->{$setter}($value); |
|
| 2027 | 2027 | } |
| 2028 | 2028 | } |
| 2029 | 2029 | |
@@ -2036,45 +2036,45 @@ discard block |
||
| 2036 | 2036 | * @param bool $manual_update Is this a manual status change?. |
| 2037 | 2037 | * @return array details of change. |
| 2038 | 2038 | */ |
| 2039 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 2039 | + public function set_status($new_status, $note = '', $manual_update = false) { |
|
| 2040 | 2040 | $old_status = $this->get_status(); |
| 2041 | 2041 | |
| 2042 | 2042 | $statuses = $this->get_all_statuses(); |
| 2043 | 2043 | |
| 2044 | - if ( isset( $statuses['draft'] ) ) { |
|
| 2045 | - unset( $statuses['draft'] ); |
|
| 2044 | + if (isset($statuses['draft'])) { |
|
| 2045 | + unset($statuses['draft']); |
|
| 2046 | 2046 | } |
| 2047 | 2047 | |
| 2048 | - $this->set_prop( 'status', $new_status ); |
|
| 2048 | + $this->set_prop('status', $new_status); |
|
| 2049 | 2049 | |
| 2050 | 2050 | // If setting the status, ensure it's set to a valid status. |
| 2051 | - if ( true === $this->object_read ) { |
|
| 2051 | + if (true === $this->object_read) { |
|
| 2052 | 2052 | |
| 2053 | 2053 | // Only allow valid new status. |
| 2054 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2054 | + if (!array_key_exists($new_status, $statuses)) { |
|
| 2055 | 2055 | $new_status = $this->get_default_status(); |
| 2056 | 2056 | } |
| 2057 | 2057 | |
| 2058 | 2058 | // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
| 2059 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2059 | + if ($old_status && !array_key_exists($new_status, $statuses)) { |
|
| 2060 | 2060 | $old_status = $this->get_default_status(); |
| 2061 | 2061 | } |
| 2062 | 2062 | |
| 2063 | 2063 | // Paid - Renewal (i.e when duplicating a parent invoice ) |
| 2064 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 2064 | + if ($new_status == 'wpi-pending' && $old_status == 'publish' && !$this->get_id()) { |
|
| 2065 | 2065 | $old_status = 'wpi-pending'; |
| 2066 | 2066 | } |
| 2067 | 2067 | |
| 2068 | - if ( $old_status !== $new_status ) { |
|
| 2068 | + if ($old_status !== $new_status) { |
|
| 2069 | 2069 | $this->status_transition = array( |
| 2070 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 2070 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
| 2071 | 2071 | 'to' => $new_status, |
| 2072 | 2072 | 'note' => $note, |
| 2073 | 2073 | 'manual' => (bool) $manual_update, |
| 2074 | 2074 | ); |
| 2075 | 2075 | |
| 2076 | - if ( $manual_update ) { |
|
| 2077 | - do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
| 2076 | + if ($manual_update) { |
|
| 2077 | + do_action('getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status); |
|
| 2078 | 2078 | } |
| 2079 | 2079 | |
| 2080 | 2080 | $this->maybe_set_date_paid(); |
@@ -2098,8 +2098,8 @@ discard block |
||
| 2098 | 2098 | */ |
| 2099 | 2099 | public function maybe_set_date_paid() { |
| 2100 | 2100 | |
| 2101 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 2102 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 2101 | + if (!$this->get_date_completed('edit') && $this->is_paid()) { |
|
| 2102 | + $this->set_date_completed(current_time('mysql')); |
|
| 2103 | 2103 | } |
| 2104 | 2104 | } |
| 2105 | 2105 | |
@@ -2108,11 +2108,11 @@ discard block |
||
| 2108 | 2108 | * |
| 2109 | 2109 | * @since 1.0.19 |
| 2110 | 2110 | */ |
| 2111 | - public function set_parent_id( $value ) { |
|
| 2112 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
| 2111 | + public function set_parent_id($value) { |
|
| 2112 | + if ($value && ($value === $this->get_id())) { |
|
| 2113 | 2113 | return; |
| 2114 | 2114 | } |
| 2115 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 2115 | + $this->set_prop('parent_id', absint($value)); |
|
| 2116 | 2116 | } |
| 2117 | 2117 | |
| 2118 | 2118 | /** |
@@ -2120,8 +2120,8 @@ discard block |
||
| 2120 | 2120 | * |
| 2121 | 2121 | * @since 1.0.19 |
| 2122 | 2122 | */ |
| 2123 | - public function set_version( $value ) { |
|
| 2124 | - $this->set_prop( 'version', $value ); |
|
| 2123 | + public function set_version($value) { |
|
| 2124 | + $this->set_prop('version', $value); |
|
| 2125 | 2125 | } |
| 2126 | 2126 | |
| 2127 | 2127 | /** |
@@ -2131,15 +2131,15 @@ discard block |
||
| 2131 | 2131 | * @param string $value Value to set. |
| 2132 | 2132 | * @return bool Whether or not the date was set. |
| 2133 | 2133 | */ |
| 2134 | - public function set_date_created( $value ) { |
|
| 2135 | - $date = strtotime( $value ); |
|
| 2134 | + public function set_date_created($value) { |
|
| 2135 | + $date = strtotime($value); |
|
| 2136 | 2136 | |
| 2137 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 2138 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 2137 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 2138 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
| 2139 | 2139 | return true; |
| 2140 | 2140 | } |
| 2141 | 2141 | |
| 2142 | - $this->set_prop( 'date_created', '' ); |
|
| 2142 | + $this->set_prop('date_created', ''); |
|
| 2143 | 2143 | return false; |
| 2144 | 2144 | } |
| 2145 | 2145 | |
@@ -2150,15 +2150,15 @@ discard block |
||
| 2150 | 2150 | * @param string $value Value to set. |
| 2151 | 2151 | * @return bool Whether or not the date was set. |
| 2152 | 2152 | */ |
| 2153 | - public function set_due_date( $value ) { |
|
| 2154 | - $date = strtotime( $value ); |
|
| 2153 | + public function set_due_date($value) { |
|
| 2154 | + $date = strtotime($value); |
|
| 2155 | 2155 | |
| 2156 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 2157 | - $this->set_prop( 'due_date', date( 'Y-m-d H:i:s', $date ) ); |
|
| 2156 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 2157 | + $this->set_prop('due_date', date('Y-m-d H:i:s', $date)); |
|
| 2158 | 2158 | return true; |
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | - $this->set_prop( 'due_date', '' ); |
|
| 2161 | + $this->set_prop('due_date', ''); |
|
| 2162 | 2162 | return false; |
| 2163 | 2163 | } |
| 2164 | 2164 | |
@@ -2168,8 +2168,8 @@ discard block |
||
| 2168 | 2168 | * @since 1.0.19 |
| 2169 | 2169 | * @param string $value New name. |
| 2170 | 2170 | */ |
| 2171 | - public function set_date_due( $value ) { |
|
| 2172 | - $this->set_due_date( $value ); |
|
| 2171 | + public function set_date_due($value) { |
|
| 2172 | + $this->set_due_date($value); |
|
| 2173 | 2173 | } |
| 2174 | 2174 | |
| 2175 | 2175 | /** |
@@ -2179,15 +2179,15 @@ discard block |
||
| 2179 | 2179 | * @param string $value Value to set. |
| 2180 | 2180 | * @return bool Whether or not the date was set. |
| 2181 | 2181 | */ |
| 2182 | - public function set_completed_date( $value ) { |
|
| 2183 | - $date = strtotime( $value ); |
|
| 2182 | + public function set_completed_date($value) { |
|
| 2183 | + $date = strtotime($value); |
|
| 2184 | 2184 | |
| 2185 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 2186 | - $this->set_prop( 'completed_date', date( 'Y-m-d H:i:s', $date ) ); |
|
| 2185 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 2186 | + $this->set_prop('completed_date', date('Y-m-d H:i:s', $date)); |
|
| 2187 | 2187 | return true; |
| 2188 | 2188 | } |
| 2189 | 2189 | |
| 2190 | - $this->set_prop( 'completed_date', '' ); |
|
| 2190 | + $this->set_prop('completed_date', ''); |
|
| 2191 | 2191 | return false; |
| 2192 | 2192 | } |
| 2193 | 2193 | |
@@ -2197,8 +2197,8 @@ discard block |
||
| 2197 | 2197 | * @since 1.0.19 |
| 2198 | 2198 | * @param string $value New name. |
| 2199 | 2199 | */ |
| 2200 | - public function set_date_completed( $value ) { |
|
| 2201 | - $this->set_completed_date( $value ); |
|
| 2200 | + public function set_date_completed($value) { |
|
| 2201 | + $this->set_completed_date($value); |
|
| 2202 | 2202 | } |
| 2203 | 2203 | |
| 2204 | 2204 | /** |
@@ -2208,15 +2208,15 @@ discard block |
||
| 2208 | 2208 | * @param string $value Value to set. |
| 2209 | 2209 | * @return bool Whether or not the date was set. |
| 2210 | 2210 | */ |
| 2211 | - public function set_date_modified( $value ) { |
|
| 2212 | - $date = strtotime( $value ); |
|
| 2211 | + public function set_date_modified($value) { |
|
| 2212 | + $date = strtotime($value); |
|
| 2213 | 2213 | |
| 2214 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 2215 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
| 2214 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 2215 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
| 2216 | 2216 | return true; |
| 2217 | 2217 | } |
| 2218 | 2218 | |
| 2219 | - $this->set_prop( 'date_modified', '' ); |
|
| 2219 | + $this->set_prop('date_modified', ''); |
|
| 2220 | 2220 | return false; |
| 2221 | 2221 | } |
| 2222 | 2222 | |
@@ -2226,9 +2226,9 @@ discard block |
||
| 2226 | 2226 | * @since 1.0.19 |
| 2227 | 2227 | * @param string $value New number. |
| 2228 | 2228 | */ |
| 2229 | - public function set_number( $value ) { |
|
| 2230 | - $number = sanitize_text_field( $value ); |
|
| 2231 | - $this->set_prop( 'number', $number ); |
|
| 2229 | + public function set_number($value) { |
|
| 2230 | + $number = sanitize_text_field($value); |
|
| 2231 | + $this->set_prop('number', $number); |
|
| 2232 | 2232 | } |
| 2233 | 2233 | |
| 2234 | 2234 | /** |
@@ -2237,9 +2237,9 @@ discard block |
||
| 2237 | 2237 | * @since 1.0.19 |
| 2238 | 2238 | * @param string $value Type. |
| 2239 | 2239 | */ |
| 2240 | - public function set_type( $value ) { |
|
| 2241 | - $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
|
| 2242 | - $this->set_prop( 'type', $type ); |
|
| 2240 | + public function set_type($value) { |
|
| 2241 | + $type = sanitize_text_field(str_replace('wpi_', '', $value)); |
|
| 2242 | + $this->set_prop('type', $type); |
|
| 2243 | 2243 | } |
| 2244 | 2244 | |
| 2245 | 2245 | /** |
@@ -2248,10 +2248,10 @@ discard block |
||
| 2248 | 2248 | * @since 1.0.19 |
| 2249 | 2249 | * @param string $value Post type. |
| 2250 | 2250 | */ |
| 2251 | - public function set_post_type( $value ) { |
|
| 2252 | - if ( getpaid_is_invoice_post_type( $value ) ) { |
|
| 2253 | - $this->set_type( $value ); |
|
| 2254 | - $this->set_prop( 'post_type', $value ); |
|
| 2251 | + public function set_post_type($value) { |
|
| 2252 | + if (getpaid_is_invoice_post_type($value)) { |
|
| 2253 | + $this->set_type($value); |
|
| 2254 | + $this->set_prop('post_type', $value); |
|
| 2255 | 2255 | } |
| 2256 | 2256 | } |
| 2257 | 2257 | |
@@ -2261,9 +2261,9 @@ discard block |
||
| 2261 | 2261 | * @since 1.0.19 |
| 2262 | 2262 | * @param string $value New key. |
| 2263 | 2263 | */ |
| 2264 | - public function set_key( $value ) { |
|
| 2265 | - $key = sanitize_text_field( $value ); |
|
| 2266 | - $this->set_prop( 'key', $key ); |
|
| 2264 | + public function set_key($value) { |
|
| 2265 | + $key = sanitize_text_field($value); |
|
| 2266 | + $this->set_prop('key', $key); |
|
| 2267 | 2267 | } |
| 2268 | 2268 | |
| 2269 | 2269 | /** |
@@ -2272,9 +2272,9 @@ discard block |
||
| 2272 | 2272 | * @since 1.0.19 |
| 2273 | 2273 | * @param string $value mode. |
| 2274 | 2274 | */ |
| 2275 | - public function set_mode( $value ) { |
|
| 2276 | - if ( in_array( $value, array( 'live', 'test' ) ) ) { |
|
| 2277 | - $this->set_prop( 'mode', $value ); |
|
| 2275 | + public function set_mode($value) { |
|
| 2276 | + if (in_array($value, array('live', 'test'))) { |
|
| 2277 | + $this->set_prop('mode', $value); |
|
| 2278 | 2278 | } |
| 2279 | 2279 | } |
| 2280 | 2280 | |
@@ -2284,8 +2284,8 @@ discard block |
||
| 2284 | 2284 | * @since 1.0.19 |
| 2285 | 2285 | * @param string $value path. |
| 2286 | 2286 | */ |
| 2287 | - public function set_path( $value ) { |
|
| 2288 | - $this->set_prop( 'path', $value ); |
|
| 2287 | + public function set_path($value) { |
|
| 2288 | + $this->set_prop('path', $value); |
|
| 2289 | 2289 | } |
| 2290 | 2290 | |
| 2291 | 2291 | /** |
@@ -2294,9 +2294,9 @@ discard block |
||
| 2294 | 2294 | * @since 1.0.19 |
| 2295 | 2295 | * @param string $value New name. |
| 2296 | 2296 | */ |
| 2297 | - public function set_name( $value ) { |
|
| 2298 | - $name = sanitize_text_field( $value ); |
|
| 2299 | - $this->set_prop( 'name', $name ); |
|
| 2297 | + public function set_name($value) { |
|
| 2298 | + $name = sanitize_text_field($value); |
|
| 2299 | + $this->set_prop('name', $name); |
|
| 2300 | 2300 | } |
| 2301 | 2301 | |
| 2302 | 2302 | /** |
@@ -2305,8 +2305,8 @@ discard block |
||
| 2305 | 2305 | * @since 1.0.19 |
| 2306 | 2306 | * @param string $value New name. |
| 2307 | 2307 | */ |
| 2308 | - public function set_title( $value ) { |
|
| 2309 | - $this->set_name( $value ); |
|
| 2308 | + public function set_title($value) { |
|
| 2309 | + $this->set_name($value); |
|
| 2310 | 2310 | } |
| 2311 | 2311 | |
| 2312 | 2312 | /** |
@@ -2315,9 +2315,9 @@ discard block |
||
| 2315 | 2315 | * @since 1.0.19 |
| 2316 | 2316 | * @param string $value New description. |
| 2317 | 2317 | */ |
| 2318 | - public function set_description( $value ) { |
|
| 2319 | - $description = wp_kses_post( $value ); |
|
| 2320 | - $this->set_prop( 'description', $description ); |
|
| 2318 | + public function set_description($value) { |
|
| 2319 | + $description = wp_kses_post($value); |
|
| 2320 | + $this->set_prop('description', $description); |
|
| 2321 | 2321 | } |
| 2322 | 2322 | |
| 2323 | 2323 | /** |
@@ -2326,8 +2326,8 @@ discard block |
||
| 2326 | 2326 | * @since 1.0.19 |
| 2327 | 2327 | * @param string $value New description. |
| 2328 | 2328 | */ |
| 2329 | - public function set_excerpt( $value ) { |
|
| 2330 | - $this->set_description( $value ); |
|
| 2329 | + public function set_excerpt($value) { |
|
| 2330 | + $this->set_description($value); |
|
| 2331 | 2331 | } |
| 2332 | 2332 | |
| 2333 | 2333 | /** |
@@ -2336,8 +2336,8 @@ discard block |
||
| 2336 | 2336 | * @since 1.0.19 |
| 2337 | 2337 | * @param string $value New description. |
| 2338 | 2338 | */ |
| 2339 | - public function set_summary( $value ) { |
|
| 2340 | - $this->set_description( $value ); |
|
| 2339 | + public function set_summary($value) { |
|
| 2340 | + $this->set_description($value); |
|
| 2341 | 2341 | } |
| 2342 | 2342 | |
| 2343 | 2343 | /** |
@@ -2346,12 +2346,12 @@ discard block |
||
| 2346 | 2346 | * @since 1.0.19 |
| 2347 | 2347 | * @param int $value New author. |
| 2348 | 2348 | */ |
| 2349 | - public function set_author( $value ) { |
|
| 2350 | - $user = get_user_by( 'id', (int) $value ); |
|
| 2349 | + public function set_author($value) { |
|
| 2350 | + $user = get_user_by('id', (int) $value); |
|
| 2351 | 2351 | |
| 2352 | - if ( $user && $user->ID ) { |
|
| 2353 | - $this->set_prop( 'author', $user->ID ); |
|
| 2354 | - $this->set_prop( 'email', $user->user_email ); |
|
| 2352 | + if ($user && $user->ID) { |
|
| 2353 | + $this->set_prop('author', $user->ID); |
|
| 2354 | + $this->set_prop('email', $user->user_email); |
|
| 2355 | 2355 | } |
| 2356 | 2356 | } |
| 2357 | 2357 | |
@@ -2361,8 +2361,8 @@ discard block |
||
| 2361 | 2361 | * @since 1.0.19 |
| 2362 | 2362 | * @param int $value New user id. |
| 2363 | 2363 | */ |
| 2364 | - public function set_user_id( $value ) { |
|
| 2365 | - $this->set_author( $value ); |
|
| 2364 | + public function set_user_id($value) { |
|
| 2365 | + $this->set_author($value); |
|
| 2366 | 2366 | } |
| 2367 | 2367 | |
| 2368 | 2368 | /** |
@@ -2371,8 +2371,8 @@ discard block |
||
| 2371 | 2371 | * @since 1.0.19 |
| 2372 | 2372 | * @param int $value New user id. |
| 2373 | 2373 | */ |
| 2374 | - public function set_customer_id( $value ) { |
|
| 2375 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 2374 | + public function set_customer_id($value) { |
|
| 2375 | + $this->set_prop('customer_id', (int) $value); |
|
| 2376 | 2376 | } |
| 2377 | 2377 | |
| 2378 | 2378 | /** |
@@ -2381,8 +2381,8 @@ discard block |
||
| 2381 | 2381 | * @since 1.0.19 |
| 2382 | 2382 | * @param string $value ip address. |
| 2383 | 2383 | */ |
| 2384 | - public function set_ip( $value ) { |
|
| 2385 | - $this->set_prop( 'ip', $value ); |
|
| 2384 | + public function set_ip($value) { |
|
| 2385 | + $this->set_prop('ip', $value); |
|
| 2386 | 2386 | } |
| 2387 | 2387 | |
| 2388 | 2388 | /** |
@@ -2391,8 +2391,8 @@ discard block |
||
| 2391 | 2391 | * @since 1.0.19 |
| 2392 | 2392 | * @param string $value ip address. |
| 2393 | 2393 | */ |
| 2394 | - public function set_user_ip( $value ) { |
|
| 2395 | - $this->set_ip( $value ); |
|
| 2394 | + public function set_user_ip($value) { |
|
| 2395 | + $this->set_ip($value); |
|
| 2396 | 2396 | } |
| 2397 | 2397 | |
| 2398 | 2398 | /** |
@@ -2401,8 +2401,8 @@ discard block |
||
| 2401 | 2401 | * @since 1.0.19 |
| 2402 | 2402 | * @param string $value first name. |
| 2403 | 2403 | */ |
| 2404 | - public function set_first_name( $value ) { |
|
| 2405 | - $this->set_prop( 'first_name', $value ); |
|
| 2404 | + public function set_first_name($value) { |
|
| 2405 | + $this->set_prop('first_name', $value); |
|
| 2406 | 2406 | } |
| 2407 | 2407 | |
| 2408 | 2408 | /** |
@@ -2411,8 +2411,8 @@ discard block |
||
| 2411 | 2411 | * @since 1.0.19 |
| 2412 | 2412 | * @param string $value first name. |
| 2413 | 2413 | */ |
| 2414 | - public function set_user_first_name( $value ) { |
|
| 2415 | - $this->set_first_name( $value ); |
|
| 2414 | + public function set_user_first_name($value) { |
|
| 2415 | + $this->set_first_name($value); |
|
| 2416 | 2416 | } |
| 2417 | 2417 | |
| 2418 | 2418 | /** |
@@ -2421,8 +2421,8 @@ discard block |
||
| 2421 | 2421 | * @since 1.0.19 |
| 2422 | 2422 | * @param string $value first name. |
| 2423 | 2423 | */ |
| 2424 | - public function set_customer_first_name( $value ) { |
|
| 2425 | - $this->set_first_name( $value ); |
|
| 2424 | + public function set_customer_first_name($value) { |
|
| 2425 | + $this->set_first_name($value); |
|
| 2426 | 2426 | } |
| 2427 | 2427 | |
| 2428 | 2428 | /** |
@@ -2431,8 +2431,8 @@ discard block |
||
| 2431 | 2431 | * @since 1.0.19 |
| 2432 | 2432 | * @param string $value last name. |
| 2433 | 2433 | */ |
| 2434 | - public function set_last_name( $value ) { |
|
| 2435 | - $this->set_prop( 'last_name', $value ); |
|
| 2434 | + public function set_last_name($value) { |
|
| 2435 | + $this->set_prop('last_name', $value); |
|
| 2436 | 2436 | } |
| 2437 | 2437 | |
| 2438 | 2438 | /** |
@@ -2441,8 +2441,8 @@ discard block |
||
| 2441 | 2441 | * @since 1.0.19 |
| 2442 | 2442 | * @param string $value last name. |
| 2443 | 2443 | */ |
| 2444 | - public function set_user_last_name( $value ) { |
|
| 2445 | - $this->set_last_name( $value ); |
|
| 2444 | + public function set_user_last_name($value) { |
|
| 2445 | + $this->set_last_name($value); |
|
| 2446 | 2446 | } |
| 2447 | 2447 | |
| 2448 | 2448 | /** |
@@ -2451,8 +2451,8 @@ discard block |
||
| 2451 | 2451 | * @since 1.0.19 |
| 2452 | 2452 | * @param string $value last name. |
| 2453 | 2453 | */ |
| 2454 | - public function set_customer_last_name( $value ) { |
|
| 2455 | - $this->set_last_name( $value ); |
|
| 2454 | + public function set_customer_last_name($value) { |
|
| 2455 | + $this->set_last_name($value); |
|
| 2456 | 2456 | } |
| 2457 | 2457 | |
| 2458 | 2458 | /** |
@@ -2461,8 +2461,8 @@ discard block |
||
| 2461 | 2461 | * @since 1.0.19 |
| 2462 | 2462 | * @param string $value phone. |
| 2463 | 2463 | */ |
| 2464 | - public function set_phone( $value ) { |
|
| 2465 | - $this->set_prop( 'phone', $value ); |
|
| 2464 | + public function set_phone($value) { |
|
| 2465 | + $this->set_prop('phone', $value); |
|
| 2466 | 2466 | } |
| 2467 | 2467 | |
| 2468 | 2468 | /** |
@@ -2471,8 +2471,8 @@ discard block |
||
| 2471 | 2471 | * @since 1.0.19 |
| 2472 | 2472 | * @param string $value phone. |
| 2473 | 2473 | */ |
| 2474 | - public function set_user_phone( $value ) { |
|
| 2475 | - $this->set_phone( $value ); |
|
| 2474 | + public function set_user_phone($value) { |
|
| 2475 | + $this->set_phone($value); |
|
| 2476 | 2476 | } |
| 2477 | 2477 | |
| 2478 | 2478 | /** |
@@ -2481,8 +2481,8 @@ discard block |
||
| 2481 | 2481 | * @since 1.0.19 |
| 2482 | 2482 | * @param string $value phone. |
| 2483 | 2483 | */ |
| 2484 | - public function set_customer_phone( $value ) { |
|
| 2485 | - $this->set_phone( $value ); |
|
| 2484 | + public function set_customer_phone($value) { |
|
| 2485 | + $this->set_phone($value); |
|
| 2486 | 2486 | } |
| 2487 | 2487 | |
| 2488 | 2488 | /** |
@@ -2491,8 +2491,8 @@ discard block |
||
| 2491 | 2491 | * @since 1.0.19 |
| 2492 | 2492 | * @param string $value phone. |
| 2493 | 2493 | */ |
| 2494 | - public function set_phone_number( $value ) { |
|
| 2495 | - $this->set_phone( $value ); |
|
| 2494 | + public function set_phone_number($value) { |
|
| 2495 | + $this->set_phone($value); |
|
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | /** |
@@ -2501,8 +2501,8 @@ discard block |
||
| 2501 | 2501 | * @since 1.0.19 |
| 2502 | 2502 | * @param string $value email address. |
| 2503 | 2503 | */ |
| 2504 | - public function set_email( $value ) { |
|
| 2505 | - $this->set_prop( 'email', $value ); |
|
| 2504 | + public function set_email($value) { |
|
| 2505 | + $this->set_prop('email', $value); |
|
| 2506 | 2506 | } |
| 2507 | 2507 | |
| 2508 | 2508 | /** |
@@ -2511,8 +2511,8 @@ discard block |
||
| 2511 | 2511 | * @since 1.0.19 |
| 2512 | 2512 | * @param string $value email address. |
| 2513 | 2513 | */ |
| 2514 | - public function set_user_email( $value ) { |
|
| 2515 | - $this->set_email( $value ); |
|
| 2514 | + public function set_user_email($value) { |
|
| 2515 | + $this->set_email($value); |
|
| 2516 | 2516 | } |
| 2517 | 2517 | |
| 2518 | 2518 | /** |
@@ -2521,8 +2521,8 @@ discard block |
||
| 2521 | 2521 | * @since 1.0.19 |
| 2522 | 2522 | * @param string $value email address. |
| 2523 | 2523 | */ |
| 2524 | - public function set_email_address( $value ) { |
|
| 2525 | - $this->set_email( $value ); |
|
| 2524 | + public function set_email_address($value) { |
|
| 2525 | + $this->set_email($value); |
|
| 2526 | 2526 | } |
| 2527 | 2527 | |
| 2528 | 2528 | /** |
@@ -2531,8 +2531,8 @@ discard block |
||
| 2531 | 2531 | * @since 1.0.19 |
| 2532 | 2532 | * @param string $value email address. |
| 2533 | 2533 | */ |
| 2534 | - public function set_customer_email( $value ) { |
|
| 2535 | - $this->set_email( $value ); |
|
| 2534 | + public function set_customer_email($value) { |
|
| 2535 | + $this->set_email($value); |
|
| 2536 | 2536 | } |
| 2537 | 2537 | |
| 2538 | 2538 | /** |
@@ -2541,8 +2541,8 @@ discard block |
||
| 2541 | 2541 | * @since 1.0.19 |
| 2542 | 2542 | * @param string $value country. |
| 2543 | 2543 | */ |
| 2544 | - public function set_country( $value ) { |
|
| 2545 | - $this->set_prop( 'country', $value ); |
|
| 2544 | + public function set_country($value) { |
|
| 2545 | + $this->set_prop('country', $value); |
|
| 2546 | 2546 | } |
| 2547 | 2547 | |
| 2548 | 2548 | /** |
@@ -2551,8 +2551,8 @@ discard block |
||
| 2551 | 2551 | * @since 1.0.19 |
| 2552 | 2552 | * @param string $value country. |
| 2553 | 2553 | */ |
| 2554 | - public function set_user_country( $value ) { |
|
| 2555 | - $this->set_country( $value ); |
|
| 2554 | + public function set_user_country($value) { |
|
| 2555 | + $this->set_country($value); |
|
| 2556 | 2556 | } |
| 2557 | 2557 | |
| 2558 | 2558 | /** |
@@ -2561,8 +2561,8 @@ discard block |
||
| 2561 | 2561 | * @since 1.0.19 |
| 2562 | 2562 | * @param string $value country. |
| 2563 | 2563 | */ |
| 2564 | - public function set_customer_country( $value ) { |
|
| 2565 | - $this->set_country( $value ); |
|
| 2564 | + public function set_customer_country($value) { |
|
| 2565 | + $this->set_country($value); |
|
| 2566 | 2566 | } |
| 2567 | 2567 | |
| 2568 | 2568 | /** |
@@ -2571,8 +2571,8 @@ discard block |
||
| 2571 | 2571 | * @since 1.0.19 |
| 2572 | 2572 | * @param string $value state. |
| 2573 | 2573 | */ |
| 2574 | - public function set_state( $value ) { |
|
| 2575 | - $this->set_prop( 'state', $value ); |
|
| 2574 | + public function set_state($value) { |
|
| 2575 | + $this->set_prop('state', $value); |
|
| 2576 | 2576 | } |
| 2577 | 2577 | |
| 2578 | 2578 | /** |
@@ -2581,8 +2581,8 @@ discard block |
||
| 2581 | 2581 | * @since 1.0.19 |
| 2582 | 2582 | * @param string $value state. |
| 2583 | 2583 | */ |
| 2584 | - public function set_user_state( $value ) { |
|
| 2585 | - $this->set_state( $value ); |
|
| 2584 | + public function set_user_state($value) { |
|
| 2585 | + $this->set_state($value); |
|
| 2586 | 2586 | } |
| 2587 | 2587 | |
| 2588 | 2588 | /** |
@@ -2591,8 +2591,8 @@ discard block |
||
| 2591 | 2591 | * @since 1.0.19 |
| 2592 | 2592 | * @param string $value state. |
| 2593 | 2593 | */ |
| 2594 | - public function set_customer_state( $value ) { |
|
| 2595 | - $this->set_state( $value ); |
|
| 2594 | + public function set_customer_state($value) { |
|
| 2595 | + $this->set_state($value); |
|
| 2596 | 2596 | } |
| 2597 | 2597 | |
| 2598 | 2598 | /** |
@@ -2601,8 +2601,8 @@ discard block |
||
| 2601 | 2601 | * @since 1.0.19 |
| 2602 | 2602 | * @param string $value city. |
| 2603 | 2603 | */ |
| 2604 | - public function set_city( $value ) { |
|
| 2605 | - $this->set_prop( 'city', $value ); |
|
| 2604 | + public function set_city($value) { |
|
| 2605 | + $this->set_prop('city', $value); |
|
| 2606 | 2606 | } |
| 2607 | 2607 | |
| 2608 | 2608 | /** |
@@ -2611,8 +2611,8 @@ discard block |
||
| 2611 | 2611 | * @since 1.0.19 |
| 2612 | 2612 | * @param string $value city. |
| 2613 | 2613 | */ |
| 2614 | - public function set_user_city( $value ) { |
|
| 2615 | - $this->set_city( $value ); |
|
| 2614 | + public function set_user_city($value) { |
|
| 2615 | + $this->set_city($value); |
|
| 2616 | 2616 | } |
| 2617 | 2617 | |
| 2618 | 2618 | /** |
@@ -2621,8 +2621,8 @@ discard block |
||
| 2621 | 2621 | * @since 1.0.19 |
| 2622 | 2622 | * @param string $value city. |
| 2623 | 2623 | */ |
| 2624 | - public function set_customer_city( $value ) { |
|
| 2625 | - $this->set_city( $value ); |
|
| 2624 | + public function set_customer_city($value) { |
|
| 2625 | + $this->set_city($value); |
|
| 2626 | 2626 | } |
| 2627 | 2627 | |
| 2628 | 2628 | /** |
@@ -2631,8 +2631,8 @@ discard block |
||
| 2631 | 2631 | * @since 1.0.19 |
| 2632 | 2632 | * @param string $value zip. |
| 2633 | 2633 | */ |
| 2634 | - public function set_zip( $value ) { |
|
| 2635 | - $this->set_prop( 'zip', $value ); |
|
| 2634 | + public function set_zip($value) { |
|
| 2635 | + $this->set_prop('zip', $value); |
|
| 2636 | 2636 | } |
| 2637 | 2637 | |
| 2638 | 2638 | /** |
@@ -2641,8 +2641,8 @@ discard block |
||
| 2641 | 2641 | * @since 1.0.19 |
| 2642 | 2642 | * @param string $value zip. |
| 2643 | 2643 | */ |
| 2644 | - public function set_user_zip( $value ) { |
|
| 2645 | - $this->set_zip( $value ); |
|
| 2644 | + public function set_user_zip($value) { |
|
| 2645 | + $this->set_zip($value); |
|
| 2646 | 2646 | } |
| 2647 | 2647 | |
| 2648 | 2648 | /** |
@@ -2651,8 +2651,8 @@ discard block |
||
| 2651 | 2651 | * @since 1.0.19 |
| 2652 | 2652 | * @param string $value zip. |
| 2653 | 2653 | */ |
| 2654 | - public function set_customer_zip( $value ) { |
|
| 2655 | - $this->set_zip( $value ); |
|
| 2654 | + public function set_customer_zip($value) { |
|
| 2655 | + $this->set_zip($value); |
|
| 2656 | 2656 | } |
| 2657 | 2657 | |
| 2658 | 2658 | /** |
@@ -2661,8 +2661,8 @@ discard block |
||
| 2661 | 2661 | * @since 1.0.19 |
| 2662 | 2662 | * @param string $value company. |
| 2663 | 2663 | */ |
| 2664 | - public function set_company( $value ) { |
|
| 2665 | - $this->set_prop( 'company', $value ); |
|
| 2664 | + public function set_company($value) { |
|
| 2665 | + $this->set_prop('company', $value); |
|
| 2666 | 2666 | } |
| 2667 | 2667 | |
| 2668 | 2668 | /** |
@@ -2671,8 +2671,8 @@ discard block |
||
| 2671 | 2671 | * @since 1.0.19 |
| 2672 | 2672 | * @param string $value company. |
| 2673 | 2673 | */ |
| 2674 | - public function set_user_company( $value ) { |
|
| 2675 | - $this->set_company( $value ); |
|
| 2674 | + public function set_user_company($value) { |
|
| 2675 | + $this->set_company($value); |
|
| 2676 | 2676 | } |
| 2677 | 2677 | |
| 2678 | 2678 | /** |
@@ -2681,8 +2681,8 @@ discard block |
||
| 2681 | 2681 | * @since 1.0.19 |
| 2682 | 2682 | * @param string $value company. |
| 2683 | 2683 | */ |
| 2684 | - public function set_customer_company( $value ) { |
|
| 2685 | - $this->set_company( $value ); |
|
| 2684 | + public function set_customer_company($value) { |
|
| 2685 | + $this->set_company($value); |
|
| 2686 | 2686 | } |
| 2687 | 2687 | |
| 2688 | 2688 | /** |
@@ -2691,8 +2691,8 @@ discard block |
||
| 2691 | 2691 | * @since 1.0.19 |
| 2692 | 2692 | * @param string $value company id. |
| 2693 | 2693 | */ |
| 2694 | - public function set_company_id( $value ) { |
|
| 2695 | - $this->set_prop( 'company_id', $value ); |
|
| 2694 | + public function set_company_id($value) { |
|
| 2695 | + $this->set_prop('company_id', $value); |
|
| 2696 | 2696 | } |
| 2697 | 2697 | |
| 2698 | 2698 | /** |
@@ -2701,8 +2701,8 @@ discard block |
||
| 2701 | 2701 | * @since 1.0.19 |
| 2702 | 2702 | * @param string $value var number. |
| 2703 | 2703 | */ |
| 2704 | - public function set_vat_number( $value ) { |
|
| 2705 | - $this->set_prop( 'vat_number', $value ); |
|
| 2704 | + public function set_vat_number($value) { |
|
| 2705 | + $this->set_prop('vat_number', $value); |
|
| 2706 | 2706 | } |
| 2707 | 2707 | |
| 2708 | 2708 | /** |
@@ -2711,8 +2711,8 @@ discard block |
||
| 2711 | 2711 | * @since 1.0.19 |
| 2712 | 2712 | * @param string $value var number. |
| 2713 | 2713 | */ |
| 2714 | - public function set_user_vat_number( $value ) { |
|
| 2715 | - $this->set_vat_number( $value ); |
|
| 2714 | + public function set_user_vat_number($value) { |
|
| 2715 | + $this->set_vat_number($value); |
|
| 2716 | 2716 | } |
| 2717 | 2717 | |
| 2718 | 2718 | /** |
@@ -2721,8 +2721,8 @@ discard block |
||
| 2721 | 2721 | * @since 1.0.19 |
| 2722 | 2722 | * @param string $value var number. |
| 2723 | 2723 | */ |
| 2724 | - public function set_customer_vat_number( $value ) { |
|
| 2725 | - $this->set_vat_number( $value ); |
|
| 2724 | + public function set_customer_vat_number($value) { |
|
| 2725 | + $this->set_vat_number($value); |
|
| 2726 | 2726 | } |
| 2727 | 2727 | |
| 2728 | 2728 | /** |
@@ -2731,8 +2731,8 @@ discard block |
||
| 2731 | 2731 | * @since 1.0.19 |
| 2732 | 2732 | * @param string $value var rate. |
| 2733 | 2733 | */ |
| 2734 | - public function set_vat_rate( $value ) { |
|
| 2735 | - $this->set_prop( 'vat_rate', $value ); |
|
| 2734 | + public function set_vat_rate($value) { |
|
| 2735 | + $this->set_prop('vat_rate', $value); |
|
| 2736 | 2736 | } |
| 2737 | 2737 | |
| 2738 | 2738 | /** |
@@ -2741,8 +2741,8 @@ discard block |
||
| 2741 | 2741 | * @since 1.0.19 |
| 2742 | 2742 | * @param string $value var number. |
| 2743 | 2743 | */ |
| 2744 | - public function set_user_vat_rate( $value ) { |
|
| 2745 | - $this->set_vat_rate( $value ); |
|
| 2744 | + public function set_user_vat_rate($value) { |
|
| 2745 | + $this->set_vat_rate($value); |
|
| 2746 | 2746 | } |
| 2747 | 2747 | |
| 2748 | 2748 | /** |
@@ -2751,8 +2751,8 @@ discard block |
||
| 2751 | 2751 | * @since 1.0.19 |
| 2752 | 2752 | * @param string $value var number. |
| 2753 | 2753 | */ |
| 2754 | - public function set_customer_vat_rate( $value ) { |
|
| 2755 | - $this->set_vat_rate( $value ); |
|
| 2754 | + public function set_customer_vat_rate($value) { |
|
| 2755 | + $this->set_vat_rate($value); |
|
| 2756 | 2756 | } |
| 2757 | 2757 | |
| 2758 | 2758 | /** |
@@ -2761,8 +2761,8 @@ discard block |
||
| 2761 | 2761 | * @since 1.0.19 |
| 2762 | 2762 | * @param string $value address. |
| 2763 | 2763 | */ |
| 2764 | - public function set_address( $value ) { |
|
| 2765 | - $this->set_prop( 'address', $value ); |
|
| 2764 | + public function set_address($value) { |
|
| 2765 | + $this->set_prop('address', $value); |
|
| 2766 | 2766 | } |
| 2767 | 2767 | |
| 2768 | 2768 | /** |
@@ -2771,8 +2771,8 @@ discard block |
||
| 2771 | 2771 | * @since 1.0.19 |
| 2772 | 2772 | * @param string $value address. |
| 2773 | 2773 | */ |
| 2774 | - public function set_user_address( $value ) { |
|
| 2775 | - $this->set_address( $value ); |
|
| 2774 | + public function set_user_address($value) { |
|
| 2775 | + $this->set_address($value); |
|
| 2776 | 2776 | } |
| 2777 | 2777 | |
| 2778 | 2778 | /** |
@@ -2781,8 +2781,8 @@ discard block |
||
| 2781 | 2781 | * @since 1.0.19 |
| 2782 | 2782 | * @param string $value address. |
| 2783 | 2783 | */ |
| 2784 | - public function set_customer_address( $value ) { |
|
| 2785 | - $this->set_address( $value ); |
|
| 2784 | + public function set_customer_address($value) { |
|
| 2785 | + $this->set_address($value); |
|
| 2786 | 2786 | } |
| 2787 | 2787 | |
| 2788 | 2788 | /** |
@@ -2791,8 +2791,8 @@ discard block |
||
| 2791 | 2791 | * @since 1.0.19 |
| 2792 | 2792 | * @param int|bool $value confirmed. |
| 2793 | 2793 | */ |
| 2794 | - public function set_is_viewed( $value ) { |
|
| 2795 | - $this->set_prop( 'is_viewed', $value ); |
|
| 2794 | + public function set_is_viewed($value) { |
|
| 2795 | + $this->set_prop('is_viewed', $value); |
|
| 2796 | 2796 | } |
| 2797 | 2797 | |
| 2798 | 2798 | /** |
@@ -2801,8 +2801,8 @@ discard block |
||
| 2801 | 2801 | * @since 1.0.19 |
| 2802 | 2802 | * @param string $value email recipients. |
| 2803 | 2803 | */ |
| 2804 | - public function set_email_cc( $value ) { |
|
| 2805 | - $this->set_prop( 'email_cc', $value ); |
|
| 2804 | + public function set_email_cc($value) { |
|
| 2805 | + $this->set_prop('email_cc', $value); |
|
| 2806 | 2806 | } |
| 2807 | 2807 | |
| 2808 | 2808 | /** |
@@ -2811,9 +2811,9 @@ discard block |
||
| 2811 | 2811 | * @since 1.0.19 |
| 2812 | 2812 | * @param string $value template. |
| 2813 | 2813 | */ |
| 2814 | - public function set_template( $value ) { |
|
| 2815 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2816 | - $this->set_prop( 'template', $value ); |
|
| 2814 | + public function set_template($value) { |
|
| 2815 | + if (in_array($value, array('quantity', 'hours', 'amount'))) { |
|
| 2816 | + $this->set_prop('template', $value); |
|
| 2817 | 2817 | } |
| 2818 | 2818 | } |
| 2819 | 2819 | |
@@ -2824,8 +2824,8 @@ discard block |
||
| 2824 | 2824 | * @param string $value source. |
| 2825 | 2825 | * @deprecated |
| 2826 | 2826 | */ |
| 2827 | - public function created_via( $value ) { |
|
| 2828 | - $this->set_created_via( sanitize_text_field( $value ) ); |
|
| 2827 | + public function created_via($value) { |
|
| 2828 | + $this->set_created_via(sanitize_text_field($value)); |
|
| 2829 | 2829 | } |
| 2830 | 2830 | |
| 2831 | 2831 | /** |
@@ -2834,8 +2834,8 @@ discard block |
||
| 2834 | 2834 | * @since 1.0.19 |
| 2835 | 2835 | * @param string $value source. |
| 2836 | 2836 | */ |
| 2837 | - public function set_created_via( $value ) { |
|
| 2838 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2837 | + public function set_created_via($value) { |
|
| 2838 | + $this->set_prop('created_via', sanitize_text_field($value)); |
|
| 2839 | 2839 | } |
| 2840 | 2840 | |
| 2841 | 2841 | /** |
@@ -2844,8 +2844,8 @@ discard block |
||
| 2844 | 2844 | * @since 1.0.19 |
| 2845 | 2845 | * @param int|bool $value confirmed. |
| 2846 | 2846 | */ |
| 2847 | - public function set_address_confirmed( $value ) { |
|
| 2848 | - $this->set_prop( 'address_confirmed', $value ); |
|
| 2847 | + public function set_address_confirmed($value) { |
|
| 2848 | + $this->set_prop('address_confirmed', $value); |
|
| 2849 | 2849 | } |
| 2850 | 2850 | |
| 2851 | 2851 | /** |
@@ -2854,8 +2854,8 @@ discard block |
||
| 2854 | 2854 | * @since 1.0.19 |
| 2855 | 2855 | * @param int|bool $value confirmed. |
| 2856 | 2856 | */ |
| 2857 | - public function set_user_address_confirmed( $value ) { |
|
| 2858 | - $this->set_address_confirmed( $value ); |
|
| 2857 | + public function set_user_address_confirmed($value) { |
|
| 2858 | + $this->set_address_confirmed($value); |
|
| 2859 | 2859 | } |
| 2860 | 2860 | |
| 2861 | 2861 | /** |
@@ -2864,8 +2864,8 @@ discard block |
||
| 2864 | 2864 | * @since 1.0.19 |
| 2865 | 2865 | * @param int|bool $value confirmed. |
| 2866 | 2866 | */ |
| 2867 | - public function set_customer_address_confirmed( $value ) { |
|
| 2868 | - $this->set_address_confirmed( $value ); |
|
| 2867 | + public function set_customer_address_confirmed($value) { |
|
| 2868 | + $this->set_address_confirmed($value); |
|
| 2869 | 2869 | } |
| 2870 | 2870 | |
| 2871 | 2871 | /** |
@@ -2874,13 +2874,13 @@ discard block |
||
| 2874 | 2874 | * @since 1.0.19 |
| 2875 | 2875 | * @param float $value shipping amount. |
| 2876 | 2876 | */ |
| 2877 | - public function set_shipping( $value ) { |
|
| 2877 | + public function set_shipping($value) { |
|
| 2878 | 2878 | |
| 2879 | - if ( ! is_numeric( $value ) ) { |
|
| 2880 | - return $this->set_prop( 'shipping', null ); |
|
| 2879 | + if (!is_numeric($value)) { |
|
| 2880 | + return $this->set_prop('shipping', null); |
|
| 2881 | 2881 | } |
| 2882 | 2882 | |
| 2883 | - $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
| 2883 | + $this->set_prop('shipping', max(0, floatval($value))); |
|
| 2884 | 2884 | } |
| 2885 | 2885 | |
| 2886 | 2886 | /** |
@@ -2889,8 +2889,8 @@ discard block |
||
| 2889 | 2889 | * @since 1.0.19 |
| 2890 | 2890 | * @param float $value sub total. |
| 2891 | 2891 | */ |
| 2892 | - public function set_subtotal( $value ) { |
|
| 2893 | - $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
| 2892 | + public function set_subtotal($value) { |
|
| 2893 | + $this->set_prop('subtotal', max(0, $value)); |
|
| 2894 | 2894 | } |
| 2895 | 2895 | |
| 2896 | 2896 | /** |
@@ -2899,8 +2899,8 @@ discard block |
||
| 2899 | 2899 | * @since 1.0.19 |
| 2900 | 2900 | * @param float $value sub total. |
| 2901 | 2901 | */ |
| 2902 | - public function set_total( $value ) { |
|
| 2903 | - $this->set_prop( 'total', max( 0, $value ) ); |
|
| 2902 | + public function set_total($value) { |
|
| 2903 | + $this->set_prop('total', max(0, $value)); |
|
| 2904 | 2904 | } |
| 2905 | 2905 | |
| 2906 | 2906 | /** |
@@ -2909,8 +2909,8 @@ discard block |
||
| 2909 | 2909 | * @since 1.0.19 |
| 2910 | 2910 | * @param float $value discount total. |
| 2911 | 2911 | */ |
| 2912 | - public function set_total_discount( $value ) { |
|
| 2913 | - $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
| 2912 | + public function set_total_discount($value) { |
|
| 2913 | + $this->set_prop('total_discount', max(0, $value)); |
|
| 2914 | 2914 | } |
| 2915 | 2915 | |
| 2916 | 2916 | /** |
@@ -2919,8 +2919,8 @@ discard block |
||
| 2919 | 2919 | * @since 1.0.19 |
| 2920 | 2920 | * @param float $value discount total. |
| 2921 | 2921 | */ |
| 2922 | - public function set_discount( $value ) { |
|
| 2923 | - $this->set_total_discount( $value ); |
|
| 2922 | + public function set_discount($value) { |
|
| 2923 | + $this->set_total_discount($value); |
|
| 2924 | 2924 | } |
| 2925 | 2925 | |
| 2926 | 2926 | /** |
@@ -2929,8 +2929,8 @@ discard block |
||
| 2929 | 2929 | * @since 1.0.19 |
| 2930 | 2930 | * @param float $value tax total. |
| 2931 | 2931 | */ |
| 2932 | - public function set_total_tax( $value ) { |
|
| 2933 | - $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
| 2932 | + public function set_total_tax($value) { |
|
| 2933 | + $this->set_prop('total_tax', max(0, $value)); |
|
| 2934 | 2934 | } |
| 2935 | 2935 | |
| 2936 | 2936 | /** |
@@ -2939,8 +2939,8 @@ discard block |
||
| 2939 | 2939 | * @since 1.0.19 |
| 2940 | 2940 | * @param float $value tax total. |
| 2941 | 2941 | */ |
| 2942 | - public function set_tax_total( $value ) { |
|
| 2943 | - $this->set_total_tax( $value ); |
|
| 2942 | + public function set_tax_total($value) { |
|
| 2943 | + $this->set_total_tax($value); |
|
| 2944 | 2944 | } |
| 2945 | 2945 | |
| 2946 | 2946 | /** |
@@ -2949,8 +2949,8 @@ discard block |
||
| 2949 | 2949 | * @since 1.0.19 |
| 2950 | 2950 | * @param float $value fees total. |
| 2951 | 2951 | */ |
| 2952 | - public function set_total_fees( $value ) { |
|
| 2953 | - $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
| 2952 | + public function set_total_fees($value) { |
|
| 2953 | + $this->set_prop('total_fees', max(0, $value)); |
|
| 2954 | 2954 | } |
| 2955 | 2955 | |
| 2956 | 2956 | /** |
@@ -2959,8 +2959,8 @@ discard block |
||
| 2959 | 2959 | * @since 1.0.19 |
| 2960 | 2960 | * @param float $value fees total. |
| 2961 | 2961 | */ |
| 2962 | - public function set_fees_total( $value ) { |
|
| 2963 | - $this->set_total_fees( $value ); |
|
| 2962 | + public function set_fees_total($value) { |
|
| 2963 | + $this->set_total_fees($value); |
|
| 2964 | 2964 | } |
| 2965 | 2965 | |
| 2966 | 2966 | /** |
@@ -2969,13 +2969,13 @@ discard block |
||
| 2969 | 2969 | * @since 1.0.19 |
| 2970 | 2970 | * @param array $value fees. |
| 2971 | 2971 | */ |
| 2972 | - public function set_fees( $value ) { |
|
| 2972 | + public function set_fees($value) { |
|
| 2973 | 2973 | |
| 2974 | - if ( ! is_array( $value ) ) { |
|
| 2974 | + if (!is_array($value)) { |
|
| 2975 | 2975 | $value = array(); |
| 2976 | 2976 | } |
| 2977 | 2977 | |
| 2978 | - $this->set_prop( 'fees', $value ); |
|
| 2978 | + $this->set_prop('fees', $value); |
|
| 2979 | 2979 | } |
| 2980 | 2980 | |
| 2981 | 2981 | /** |
@@ -2984,13 +2984,13 @@ discard block |
||
| 2984 | 2984 | * @since 1.0.19 |
| 2985 | 2985 | * @param array $value taxes. |
| 2986 | 2986 | */ |
| 2987 | - public function set_taxes( $value ) { |
|
| 2987 | + public function set_taxes($value) { |
|
| 2988 | 2988 | |
| 2989 | - if ( ! is_array( $value ) ) { |
|
| 2989 | + if (!is_array($value)) { |
|
| 2990 | 2990 | $value = array(); |
| 2991 | 2991 | } |
| 2992 | 2992 | |
| 2993 | - $this->set_prop( 'taxes', $value ); |
|
| 2993 | + $this->set_prop('taxes', $value); |
|
| 2994 | 2994 | } |
| 2995 | 2995 | |
| 2996 | 2996 | /** |
@@ -2999,13 +2999,13 @@ discard block |
||
| 2999 | 2999 | * @since 1.0.19 |
| 3000 | 3000 | * @param array $value discounts. |
| 3001 | 3001 | */ |
| 3002 | - public function set_discounts( $value ) { |
|
| 3002 | + public function set_discounts($value) { |
|
| 3003 | 3003 | |
| 3004 | - if ( ! is_array( $value ) ) { |
|
| 3004 | + if (!is_array($value)) { |
|
| 3005 | 3005 | $value = array(); |
| 3006 | 3006 | } |
| 3007 | 3007 | |
| 3008 | - $this->set_prop( 'discounts', $value ); |
|
| 3008 | + $this->set_prop('discounts', $value); |
|
| 3009 | 3009 | } |
| 3010 | 3010 | |
| 3011 | 3011 | /** |
@@ -3014,19 +3014,19 @@ discard block |
||
| 3014 | 3014 | * @since 1.0.19 |
| 3015 | 3015 | * @param GetPaid_Form_Item[] $value items. |
| 3016 | 3016 | */ |
| 3017 | - public function set_items( $value ) { |
|
| 3017 | + public function set_items($value) { |
|
| 3018 | 3018 | |
| 3019 | 3019 | // Remove existing items. |
| 3020 | - $this->set_prop( 'items', array() ); |
|
| 3020 | + $this->set_prop('items', array()); |
|
| 3021 | 3021 | $this->recurring_item = null; |
| 3022 | 3022 | |
| 3023 | 3023 | // Ensure that we have an array. |
| 3024 | - if ( ! is_array( $value ) ) { |
|
| 3024 | + if (!is_array($value)) { |
|
| 3025 | 3025 | return; |
| 3026 | 3026 | } |
| 3027 | 3027 | |
| 3028 | - foreach ( $value as $item ) { |
|
| 3029 | - $this->add_item( $item ); |
|
| 3028 | + foreach ($value as $item) { |
|
| 3029 | + $this->add_item($item); |
|
| 3030 | 3030 | } |
| 3031 | 3031 | } |
| 3032 | 3032 | |
@@ -3036,8 +3036,8 @@ discard block |
||
| 3036 | 3036 | * @since 1.0.19 |
| 3037 | 3037 | * @param int $value payment form. |
| 3038 | 3038 | */ |
| 3039 | - public function set_payment_form( $value ) { |
|
| 3040 | - $this->set_prop( 'payment_form', $value ); |
|
| 3039 | + public function set_payment_form($value) { |
|
| 3040 | + $this->set_prop('payment_form', $value); |
|
| 3041 | 3041 | } |
| 3042 | 3042 | |
| 3043 | 3043 | /** |
@@ -3046,8 +3046,8 @@ discard block |
||
| 3046 | 3046 | * @since 1.0.19 |
| 3047 | 3047 | * @param string $value submission id. |
| 3048 | 3048 | */ |
| 3049 | - public function set_submission_id( $value ) { |
|
| 3050 | - $this->set_prop( 'submission_id', $value ); |
|
| 3049 | + public function set_submission_id($value) { |
|
| 3050 | + $this->set_prop('submission_id', $value); |
|
| 3051 | 3051 | } |
| 3052 | 3052 | |
| 3053 | 3053 | /** |
@@ -3056,8 +3056,8 @@ discard block |
||
| 3056 | 3056 | * @since 1.0.19 |
| 3057 | 3057 | * @param string $value discount code. |
| 3058 | 3058 | */ |
| 3059 | - public function set_discount_code( $value ) { |
|
| 3060 | - $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
| 3059 | + public function set_discount_code($value) { |
|
| 3060 | + $this->set_prop('discount_code', sanitize_text_field($value)); |
|
| 3061 | 3061 | } |
| 3062 | 3062 | |
| 3063 | 3063 | /** |
@@ -3066,8 +3066,8 @@ discard block |
||
| 3066 | 3066 | * @since 1.0.19 |
| 3067 | 3067 | * @param string $value gateway. |
| 3068 | 3068 | */ |
| 3069 | - public function set_gateway( $value ) { |
|
| 3070 | - $this->set_prop( 'gateway', $value ); |
|
| 3069 | + public function set_gateway($value) { |
|
| 3070 | + $this->set_prop('gateway', $value); |
|
| 3071 | 3071 | } |
| 3072 | 3072 | |
| 3073 | 3073 | /** |
@@ -3076,9 +3076,9 @@ discard block |
||
| 3076 | 3076 | * @since 1.0.19 |
| 3077 | 3077 | * @param string $value transaction id. |
| 3078 | 3078 | */ |
| 3079 | - public function set_transaction_id( $value ) { |
|
| 3080 | - if ( ! empty( $value ) ) { |
|
| 3081 | - $this->set_prop( 'transaction_id', $value ); |
|
| 3079 | + public function set_transaction_id($value) { |
|
| 3080 | + if (!empty($value)) { |
|
| 3081 | + $this->set_prop('transaction_id', $value); |
|
| 3082 | 3082 | } |
| 3083 | 3083 | } |
| 3084 | 3084 | |
@@ -3088,8 +3088,8 @@ discard block |
||
| 3088 | 3088 | * @since 1.0.19 |
| 3089 | 3089 | * @param string $value currency id. |
| 3090 | 3090 | */ |
| 3091 | - public function set_currency( $value ) { |
|
| 3092 | - $this->set_prop( 'currency', $value ); |
|
| 3091 | + public function set_currency($value) { |
|
| 3092 | + $this->set_prop('currency', $value); |
|
| 3093 | 3093 | } |
| 3094 | 3094 | |
| 3095 | 3095 | /** |
@@ -3098,8 +3098,8 @@ discard block |
||
| 3098 | 3098 | * @since 1.0.19 |
| 3099 | 3099 | * @param bool $value value. |
| 3100 | 3100 | */ |
| 3101 | - public function set_disable_taxes( $value ) { |
|
| 3102 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 3101 | + public function set_disable_taxes($value) { |
|
| 3102 | + $this->set_prop('disable_taxes', (bool) $value); |
|
| 3103 | 3103 | } |
| 3104 | 3104 | |
| 3105 | 3105 | /** |
@@ -3108,8 +3108,8 @@ discard block |
||
| 3108 | 3108 | * @since 1.0.19 |
| 3109 | 3109 | * @param string $value subscription id. |
| 3110 | 3110 | */ |
| 3111 | - public function set_subscription_id( $value ) { |
|
| 3112 | - $this->set_prop( 'subscription_id', $value ); |
|
| 3111 | + public function set_subscription_id($value) { |
|
| 3112 | + $this->set_prop('subscription_id', $value); |
|
| 3113 | 3113 | } |
| 3114 | 3114 | |
| 3115 | 3115 | /** |
@@ -3118,8 +3118,8 @@ discard block |
||
| 3118 | 3118 | * @since 1.0.19 |
| 3119 | 3119 | * @param string $value subscription id. |
| 3120 | 3120 | */ |
| 3121 | - public function set_remote_subscription_id( $value ) { |
|
| 3122 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
| 3121 | + public function set_remote_subscription_id($value) { |
|
| 3122 | + $this->set_prop('remote_subscription_id', $value); |
|
| 3123 | 3123 | } |
| 3124 | 3124 | |
| 3125 | 3125 | /** |
@@ -3128,8 +3128,8 @@ discard block |
||
| 3128 | 3128 | * @since 2.8.22 |
| 3129 | 3129 | * @param bool $is_anonymized is anonymized. |
| 3130 | 3130 | */ |
| 3131 | - public function set_is_anonymized( $is_anonymized ) { |
|
| 3132 | - $this->set_prop( 'is_anonymized', (bool) $is_anonymized ); |
|
| 3131 | + public function set_is_anonymized($is_anonymized) { |
|
| 3132 | + $this->set_prop('is_anonymized', (bool) $is_anonymized); |
|
| 3133 | 3133 | } |
| 3134 | 3134 | |
| 3135 | 3135 | /* |
@@ -3146,28 +3146,28 @@ discard block |
||
| 3146 | 3146 | */ |
| 3147 | 3147 | public function is_parent() { |
| 3148 | 3148 | $parent = $this->get_parent_id(); |
| 3149 | - return apply_filters( 'wpinv_invoice_is_parent', empty( $parent ), $this ); |
|
| 3149 | + return apply_filters('wpinv_invoice_is_parent', empty($parent), $this); |
|
| 3150 | 3150 | } |
| 3151 | 3151 | |
| 3152 | 3152 | /** |
| 3153 | 3153 | * Checks if this is a renewal invoice. |
| 3154 | 3154 | */ |
| 3155 | 3155 | public function is_renewal() { |
| 3156 | - return $this->is_recurring() && ! $this->is_parent(); |
|
| 3156 | + return $this->is_recurring() && !$this->is_parent(); |
|
| 3157 | 3157 | } |
| 3158 | 3158 | |
| 3159 | 3159 | /** |
| 3160 | 3160 | * Checks if this is a recurring invoice. |
| 3161 | 3161 | */ |
| 3162 | 3162 | public function is_recurring() { |
| 3163 | - return ! empty( $this->recurring_item ); |
|
| 3163 | + return !empty($this->recurring_item); |
|
| 3164 | 3164 | } |
| 3165 | 3165 | |
| 3166 | 3166 | /** |
| 3167 | 3167 | * Checks if this is a taxable invoice. |
| 3168 | 3168 | */ |
| 3169 | 3169 | public function is_taxable() { |
| 3170 | - return ! $this->get_disable_taxes(); |
|
| 3170 | + return !$this->get_disable_taxes(); |
|
| 3171 | 3171 | } |
| 3172 | 3172 | |
| 3173 | 3173 | /** |
@@ -3181,45 +3181,45 @@ discard block |
||
| 3181 | 3181 | * Checks to see if the invoice requires payment. |
| 3182 | 3182 | */ |
| 3183 | 3183 | public function is_free() { |
| 3184 | - $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
|
| 3184 | + $is_free = ((float) wpinv_round_amount($this->get_initial_total()) == 0); |
|
| 3185 | 3185 | |
| 3186 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 3186 | + if ($this->is_recurring() && $this->get_recurring_total() > 0) { |
|
| 3187 | 3187 | $is_free = false; |
| 3188 | 3188 | } |
| 3189 | 3189 | |
| 3190 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
| 3190 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
| 3191 | 3191 | } |
| 3192 | 3192 | |
| 3193 | 3193 | /** |
| 3194 | 3194 | * Checks if the invoice is paid. |
| 3195 | 3195 | */ |
| 3196 | 3196 | public function is_paid() { |
| 3197 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
| 3198 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
| 3197 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
| 3198 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
| 3199 | 3199 | } |
| 3200 | 3200 | |
| 3201 | 3201 | /** |
| 3202 | 3202 | * Checks if the invoice needs payment. |
| 3203 | 3203 | */ |
| 3204 | 3204 | public function needs_payment() { |
| 3205 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 3206 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
|
| 3205 | + $needs_payment = !$this->is_paid() && !$this->is_refunded() && !$this->is_free(); |
|
| 3206 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this); |
|
| 3207 | 3207 | } |
| 3208 | 3208 | |
| 3209 | 3209 | /** |
| 3210 | 3210 | * Checks if the invoice is refunded. |
| 3211 | 3211 | */ |
| 3212 | 3212 | public function is_refunded() { |
| 3213 | - $is_refunded = $this->has_status( 'wpi-refunded' ); |
|
| 3214 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
| 3213 | + $is_refunded = $this->has_status('wpi-refunded'); |
|
| 3214 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
| 3215 | 3215 | } |
| 3216 | 3216 | |
| 3217 | 3217 | /** |
| 3218 | 3218 | * Checks if the invoice is held. |
| 3219 | 3219 | */ |
| 3220 | 3220 | public function is_held() { |
| 3221 | - $is_held = $this->has_status( 'wpi-onhold' ); |
|
| 3222 | - return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
|
| 3221 | + $is_held = $this->has_status('wpi-onhold'); |
|
| 3222 | + return apply_filters('wpinv_invoice_is_held', $is_held, $this); |
|
| 3223 | 3223 | } |
| 3224 | 3224 | |
| 3225 | 3225 | /** |
@@ -3227,30 +3227,30 @@ discard block |
||
| 3227 | 3227 | */ |
| 3228 | 3228 | public function is_due() { |
| 3229 | 3229 | $due_date = $this->get_due_date(); |
| 3230 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3230 | + return empty($due_date) ? false : current_time('timestamp') > strtotime($due_date); |
|
| 3231 | 3231 | } |
| 3232 | 3232 | |
| 3233 | 3233 | /** |
| 3234 | 3234 | * Checks if the invoice is draft. |
| 3235 | 3235 | */ |
| 3236 | 3236 | public function is_draft() { |
| 3237 | - return $this->has_status( 'draft, auto-draft' ); |
|
| 3237 | + return $this->has_status('draft, auto-draft'); |
|
| 3238 | 3238 | } |
| 3239 | 3239 | |
| 3240 | 3240 | /** |
| 3241 | 3241 | * Checks if the invoice has a given status. |
| 3242 | 3242 | */ |
| 3243 | - public function has_status( $status ) { |
|
| 3244 | - $status = wpinv_parse_list( $status ); |
|
| 3245 | - return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
|
| 3243 | + public function has_status($status) { |
|
| 3244 | + $status = wpinv_parse_list($status); |
|
| 3245 | + return apply_filters('wpinv_has_status', in_array($this->get_status(), $status), $status); |
|
| 3246 | 3246 | } |
| 3247 | 3247 | |
| 3248 | 3248 | /** |
| 3249 | 3249 | * Checks if the invoice is of a given type. |
| 3250 | 3250 | */ |
| 3251 | - public function is_type( $type ) { |
|
| 3252 | - $type = wpinv_parse_list( $type ); |
|
| 3253 | - return in_array( $this->get_type(), $type ); |
|
| 3251 | + public function is_type($type) { |
|
| 3252 | + $type = wpinv_parse_list($type); |
|
| 3253 | + return in_array($this->get_type(), $type); |
|
| 3254 | 3254 | } |
| 3255 | 3255 | |
| 3256 | 3256 | /** |
@@ -3282,8 +3282,8 @@ discard block |
||
| 3282 | 3282 | * |
| 3283 | 3283 | */ |
| 3284 | 3284 | public function is_initial_free() { |
| 3285 | - $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
|
| 3286 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
|
| 3285 | + $is_initial_free = !((float) wpinv_round_amount($this->get_initial_total()) > 0); |
|
| 3286 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this); |
|
| 3287 | 3287 | } |
| 3288 | 3288 | |
| 3289 | 3289 | /** |
@@ -3293,11 +3293,11 @@ discard block |
||
| 3293 | 3293 | public function item_has_free_trial() { |
| 3294 | 3294 | |
| 3295 | 3295 | // Ensure we have a recurring item. |
| 3296 | - if ( ! $this->is_recurring() ) { |
|
| 3296 | + if (!$this->is_recurring()) { |
|
| 3297 | 3297 | return false; |
| 3298 | 3298 | } |
| 3299 | 3299 | |
| 3300 | - $item = $this->get_recurring( true ); |
|
| 3300 | + $item = $this->get_recurring(true); |
|
| 3301 | 3301 | return $item->has_free_trial(); |
| 3302 | 3302 | } |
| 3303 | 3303 | |
@@ -3305,7 +3305,7 @@ discard block |
||
| 3305 | 3305 | * Check if the free trial is a result of a discount. |
| 3306 | 3306 | */ |
| 3307 | 3307 | public function is_free_trial_from_discount() { |
| 3308 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3308 | + return $this->has_free_trial() && !$this->item_has_free_trial(); |
|
| 3309 | 3309 | } |
| 3310 | 3310 | |
| 3311 | 3311 | /** |
@@ -3322,12 +3322,12 @@ discard block |
||
| 3322 | 3322 | */ |
| 3323 | 3323 | public function discount_first_payment_only() { |
| 3324 | 3324 | |
| 3325 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3326 | - if ( ! $discount->exists() || ! $this->is_recurring() ) { |
|
| 3325 | + $discount = wpinv_get_discount_obj($this->get_discount_code()); |
|
| 3326 | + if (!$discount->exists() || !$this->is_recurring()) { |
|
| 3327 | 3327 | return true; |
| 3328 | 3328 | } |
| 3329 | 3329 | |
| 3330 | - return ! $discount->get_is_recurring(); |
|
| 3330 | + return !$discount->get_is_recurring(); |
|
| 3331 | 3331 | } |
| 3332 | 3332 | |
| 3333 | 3333 | /* |
@@ -3345,23 +3345,23 @@ discard block |
||
| 3345 | 3345 | * @param GetPaid_Form_Item|array $item |
| 3346 | 3346 | * @return WP_Error|Bool |
| 3347 | 3347 | */ |
| 3348 | - public function add_item( $item ) { |
|
| 3348 | + public function add_item($item) { |
|
| 3349 | 3349 | |
| 3350 | - if ( is_array( $item ) ) { |
|
| 3351 | - $item = $this->process_array_item( $item ); |
|
| 3350 | + if (is_array($item)) { |
|
| 3351 | + $item = $this->process_array_item($item); |
|
| 3352 | 3352 | } |
| 3353 | 3353 | |
| 3354 | - if ( is_numeric( $item ) ) { |
|
| 3355 | - $item = new GetPaid_Form_Item( $item ); |
|
| 3354 | + if (is_numeric($item)) { |
|
| 3355 | + $item = new GetPaid_Form_Item($item); |
|
| 3356 | 3356 | } |
| 3357 | 3357 | |
| 3358 | 3358 | // Make sure that it is available for purchase. |
| 3359 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3360 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3359 | + if ($item->get_id() > 0 && !$item->can_purchase()) { |
|
| 3360 | + return new WP_Error('invalid_item', __('This item is not available for purchase', 'invoicing')); |
|
| 3361 | 3361 | } |
| 3362 | 3362 | |
| 3363 | 3363 | // Do we have a recurring item? |
| 3364 | - if ( $item->is_recurring() ) { |
|
| 3364 | + if ($item->is_recurring()) { |
|
| 3365 | 3365 | $this->recurring_item = $item->get_id(); |
| 3366 | 3366 | } |
| 3367 | 3367 | |
@@ -3369,9 +3369,9 @@ discard block |
||
| 3369 | 3369 | $item->invoice_id = (int) $this->get_id(); |
| 3370 | 3370 | |
| 3371 | 3371 | // Remove duplicates. |
| 3372 | - $this->remove_item( $item->get_id() ); |
|
| 3372 | + $this->remove_item($item->get_id()); |
|
| 3373 | 3373 | |
| 3374 | - if ( 0 == $item->get_quantity() ) { |
|
| 3374 | + if (0 == $item->get_quantity()) { |
|
| 3375 | 3375 | return; |
| 3376 | 3376 | } |
| 3377 | 3377 | |
@@ -3381,7 +3381,7 @@ discard block |
||
| 3381 | 3381 | // Add new item. |
| 3382 | 3382 | $items[] = $item; |
| 3383 | 3383 | |
| 3384 | - $this->set_prop( 'items', $items ); |
|
| 3384 | + $this->set_prop('items', $items); |
|
| 3385 | 3385 | |
| 3386 | 3386 | return true; |
| 3387 | 3387 | } |
@@ -3392,26 +3392,26 @@ discard block |
||
| 3392 | 3392 | * @since 1.0.19 |
| 3393 | 3393 | * @return GetPaid_Form_Item |
| 3394 | 3394 | */ |
| 3395 | - protected function process_array_item( $array ) { |
|
| 3395 | + protected function process_array_item($array) { |
|
| 3396 | 3396 | |
| 3397 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3398 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 3397 | + $item_id = isset($array['item_id']) ? $array['item_id'] : 0; |
|
| 3398 | + $item = new GetPaid_Form_Item($item_id); |
|
| 3399 | 3399 | |
| 3400 | 3400 | // Set item data. |
| 3401 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3402 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3401 | + foreach (array('name', 'price', 'description') as $key) { |
|
| 3402 | + if (isset($array["item_$key"])) { |
|
| 3403 | 3403 | $method = "set_$key"; |
| 3404 | - $item->$method( $array[ "item_$key" ] ); |
|
| 3404 | + $item->$method($array["item_$key"]); |
|
| 3405 | 3405 | } |
| 3406 | 3406 | } |
| 3407 | 3407 | |
| 3408 | - if ( isset( $array['quantity'] ) ) { |
|
| 3409 | - $item->set_quantity( $array['quantity'] ); |
|
| 3408 | + if (isset($array['quantity'])) { |
|
| 3409 | + $item->set_quantity($array['quantity']); |
|
| 3410 | 3410 | } |
| 3411 | 3411 | |
| 3412 | 3412 | // Set item meta. |
| 3413 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3414 | - $item->set_item_meta( $array['meta'] ); |
|
| 3413 | + if (isset($array['meta']) && is_array($array['meta'])) { |
|
| 3414 | + $item->set_item_meta($array['meta']); |
|
| 3415 | 3415 | } |
| 3416 | 3416 | |
| 3417 | 3417 | return $item; |
@@ -3423,10 +3423,10 @@ discard block |
||
| 3423 | 3423 | * @since 1.0.19 |
| 3424 | 3424 | * @return GetPaid_Form_Item|null |
| 3425 | 3425 | */ |
| 3426 | - public function get_item( $item_id ) { |
|
| 3426 | + public function get_item($item_id) { |
|
| 3427 | 3427 | |
| 3428 | - foreach ( $this->get_items() as $item ) { |
|
| 3429 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3428 | + foreach ($this->get_items() as $item) { |
|
| 3429 | + if ((int) $item_id == $item->get_id()) { |
|
| 3430 | 3430 | return $item; |
| 3431 | 3431 | } |
| 3432 | 3432 | } |
@@ -3439,16 +3439,16 @@ discard block |
||
| 3439 | 3439 | * |
| 3440 | 3440 | * @since 1.0.19 |
| 3441 | 3441 | */ |
| 3442 | - public function remove_item( $item_id ) { |
|
| 3442 | + public function remove_item($item_id) { |
|
| 3443 | 3443 | $items = $this->get_items(); |
| 3444 | 3444 | $item_id = (int) $item_id; |
| 3445 | 3445 | |
| 3446 | - foreach ( $items as $index => $item ) { |
|
| 3447 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3448 | - unset( $items[ $index ] ); |
|
| 3449 | - $this->set_prop( 'items', $items ); |
|
| 3446 | + foreach ($items as $index => $item) { |
|
| 3447 | + if ((int) $item_id == $item->get_id()) { |
|
| 3448 | + unset($items[$index]); |
|
| 3449 | + $this->set_prop('items', $items); |
|
| 3450 | 3450 | |
| 3451 | - if ( $item_id == $this->recurring_item ) { |
|
| 3451 | + if ($item_id == $this->recurring_item) { |
|
| 3452 | 3452 | $this->recurring_item = null; |
| 3453 | 3453 | } |
| 3454 | 3454 | } |
@@ -3461,11 +3461,11 @@ discard block |
||
| 3461 | 3461 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
| 3462 | 3462 | * @since 1.0.19 |
| 3463 | 3463 | */ |
| 3464 | - public function add_fee( $fee ) { |
|
| 3464 | + public function add_fee($fee) { |
|
| 3465 | 3465 | |
| 3466 | 3466 | $fees = $this->get_fees(); |
| 3467 | - $fees[ $fee['name'] ] = $fee; |
|
| 3468 | - $this->set_prop( 'fees', $fees ); |
|
| 3467 | + $fees[$fee['name']] = $fee; |
|
| 3468 | + $this->set_prop('fees', $fees); |
|
| 3469 | 3469 | } |
| 3470 | 3470 | |
| 3471 | 3471 | /** |
@@ -3473,9 +3473,9 @@ discard block |
||
| 3473 | 3473 | * |
| 3474 | 3474 | * @since 1.0.19 |
| 3475 | 3475 | */ |
| 3476 | - public function get_fee( $fee ) { |
|
| 3476 | + public function get_fee($fee) { |
|
| 3477 | 3477 | $fees = $this->get_fees(); |
| 3478 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3478 | + return isset($fees[$fee]) ? $fees[$fee] : null; |
|
| 3479 | 3479 | } |
| 3480 | 3480 | |
| 3481 | 3481 | /** |
@@ -3483,11 +3483,11 @@ discard block |
||
| 3483 | 3483 | * |
| 3484 | 3484 | * @since 1.0.19 |
| 3485 | 3485 | */ |
| 3486 | - public function remove_fee( $fee ) { |
|
| 3486 | + public function remove_fee($fee) { |
|
| 3487 | 3487 | $fees = $this->get_fees(); |
| 3488 | - if ( isset( $fees[ $fee ] ) ) { |
|
| 3489 | - unset( $fees[ $fee ] ); |
|
| 3490 | - $this->set_prop( 'fees', $fees ); |
|
| 3488 | + if (isset($fees[$fee])) { |
|
| 3489 | + unset($fees[$fee]); |
|
| 3490 | + $this->set_prop('fees', $fees); |
|
| 3491 | 3491 | } |
| 3492 | 3492 | } |
| 3493 | 3493 | |
@@ -3497,11 +3497,11 @@ discard block |
||
| 3497 | 3497 | * @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. |
| 3498 | 3498 | * @since 1.0.19 |
| 3499 | 3499 | */ |
| 3500 | - public function add_discount( $discount ) { |
|
| 3500 | + public function add_discount($discount) { |
|
| 3501 | 3501 | |
| 3502 | 3502 | $discounts = $this->get_discounts(); |
| 3503 | - $discounts[ $discount['name'] ] = $discount; |
|
| 3504 | - $this->set_prop( 'discounts', $discounts ); |
|
| 3503 | + $discounts[$discount['name']] = $discount; |
|
| 3504 | + $this->set_prop('discounts', $discounts); |
|
| 3505 | 3505 | } |
| 3506 | 3506 | |
| 3507 | 3507 | /** |
@@ -3510,15 +3510,15 @@ discard block |
||
| 3510 | 3510 | * @since 1.0.19 |
| 3511 | 3511 | * @return float |
| 3512 | 3512 | */ |
| 3513 | - public function get_discount( $discount = false ) { |
|
| 3513 | + public function get_discount($discount = false) { |
|
| 3514 | 3514 | |
| 3515 | 3515 | // Backwards compatibility. |
| 3516 | - if ( empty( $discount ) ) { |
|
| 3516 | + if (empty($discount)) { |
|
| 3517 | 3517 | return $this->get_total_discount(); |
| 3518 | 3518 | } |
| 3519 | 3519 | |
| 3520 | 3520 | $discounts = $this->get_discounts(); |
| 3521 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3521 | + return isset($discounts[$discount]) ? $discounts[$discount] : null; |
|
| 3522 | 3522 | } |
| 3523 | 3523 | |
| 3524 | 3524 | /** |
@@ -3526,15 +3526,15 @@ discard block |
||
| 3526 | 3526 | * |
| 3527 | 3527 | * @since 1.0.19 |
| 3528 | 3528 | */ |
| 3529 | - public function remove_discount( $discount ) { |
|
| 3529 | + public function remove_discount($discount) { |
|
| 3530 | 3530 | $discounts = $this->get_discounts(); |
| 3531 | - if ( isset( $discounts[ $discount ] ) ) { |
|
| 3532 | - unset( $discounts[ $discount ] ); |
|
| 3533 | - $this->set_prop( 'discounts', $discounts ); |
|
| 3531 | + if (isset($discounts[$discount])) { |
|
| 3532 | + unset($discounts[$discount]); |
|
| 3533 | + $this->set_prop('discounts', $discounts); |
|
| 3534 | 3534 | } |
| 3535 | 3535 | |
| 3536 | - if ( 'discount_code' == $discount ) { |
|
| 3537 | - foreach ( $this->get_items() as $item ) { |
|
| 3536 | + if ('discount_code' == $discount) { |
|
| 3537 | + foreach ($this->get_items() as $item) { |
|
| 3538 | 3538 | $item->item_discount = 0; |
| 3539 | 3539 | $item->recurring_item_discount = 0; |
| 3540 | 3540 | } |
@@ -3546,12 +3546,12 @@ discard block |
||
| 3546 | 3546 | * |
| 3547 | 3547 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
| 3548 | 3548 | */ |
| 3549 | - public function add_tax( $tax ) { |
|
| 3550 | - if ( $this->is_taxable() ) { |
|
| 3549 | + public function add_tax($tax) { |
|
| 3550 | + if ($this->is_taxable()) { |
|
| 3551 | 3551 | |
| 3552 | - $taxes = $this->get_taxes(); |
|
| 3553 | - $taxes[ $tax['name'] ] = $tax; |
|
| 3554 | - $this->set_prop( 'taxes', $tax ); |
|
| 3552 | + $taxes = $this->get_taxes(); |
|
| 3553 | + $taxes[$tax['name']] = $tax; |
|
| 3554 | + $this->set_prop('taxes', $tax); |
|
| 3555 | 3555 | |
| 3556 | 3556 | } |
| 3557 | 3557 | } |
@@ -3561,29 +3561,29 @@ discard block |
||
| 3561 | 3561 | * |
| 3562 | 3562 | * @since 1.0.19 |
| 3563 | 3563 | */ |
| 3564 | - public function get_tax( $tax = null ) { |
|
| 3564 | + public function get_tax($tax = null) { |
|
| 3565 | 3565 | |
| 3566 | 3566 | // Backwards compatibility. |
| 3567 | - if ( empty( $tax ) ) { |
|
| 3567 | + if (empty($tax)) { |
|
| 3568 | 3568 | return $this->get_total_tax(); |
| 3569 | 3569 | } |
| 3570 | 3570 | |
| 3571 | 3571 | $taxes = $this->get_taxes(); |
| 3572 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3572 | + return isset($taxes[$tax]) ? $taxes[$tax] : null; |
|
| 3573 | 3573 | } |
| 3574 | 3574 | |
| 3575 | - public function get_tax_total_by_name( $name ) { |
|
| 3576 | - if ( $name && 0 === strpos( $name, 'tax__' ) ) { |
|
| 3577 | - $name = str_replace( 'tax__', '', $name ); |
|
| 3575 | + public function get_tax_total_by_name($name) { |
|
| 3576 | + if ($name && 0 === strpos($name, 'tax__')) { |
|
| 3577 | + $name = str_replace('tax__', '', $name); |
|
| 3578 | 3578 | } |
| 3579 | 3579 | |
| 3580 | - if ( empty( $name ) ) { |
|
| 3580 | + if (empty($name)) { |
|
| 3581 | 3581 | return 0; |
| 3582 | 3582 | } |
| 3583 | 3583 | |
| 3584 | - $tax = $this->get_tax( $name ); |
|
| 3584 | + $tax = $this->get_tax($name); |
|
| 3585 | 3585 | |
| 3586 | - if ( empty( $tax ) ) { |
|
| 3586 | + if (empty($tax)) { |
|
| 3587 | 3587 | return 0; |
| 3588 | 3588 | } |
| 3589 | 3589 | |
@@ -3595,18 +3595,18 @@ discard block |
||
| 3595 | 3595 | * |
| 3596 | 3596 | * @since 2.8.8 |
| 3597 | 3597 | */ |
| 3598 | - public function get_tax_item_name( $tax_key, $tax_item, $suffix = '' ) { |
|
| 3599 | - $tax_name = _x( 'Tax', 'Tax name', 'invoicing' ); |
|
| 3598 | + public function get_tax_item_name($tax_key, $tax_item, $suffix = '') { |
|
| 3599 | + $tax_name = _x('Tax', 'Tax name', 'invoicing'); |
|
| 3600 | 3600 | |
| 3601 | - if ( ! empty( $tax_item ) && is_array( $tax_item ) && ! empty( $tax_item['name'] ) ) { |
|
| 3602 | - $tax_name = __( $tax_item['name'], 'invoicing' ); |
|
| 3601 | + if (!empty($tax_item) && is_array($tax_item) && !empty($tax_item['name'])) { |
|
| 3602 | + $tax_name = __($tax_item['name'], 'invoicing'); |
|
| 3603 | 3603 | } |
| 3604 | 3604 | |
| 3605 | - if ( $suffix ) { |
|
| 3605 | + if ($suffix) { |
|
| 3606 | 3606 | $tax_name .= $suffix; |
| 3607 | 3607 | } |
| 3608 | 3608 | |
| 3609 | - return apply_filters( 'wpinv_invoice_get_tax_name', $tax_name, $this, $tax_key, $tax_item, $suffix ); |
|
| 3609 | + return apply_filters('wpinv_invoice_get_tax_name', $tax_name, $this, $tax_key, $tax_item, $suffix); |
|
| 3610 | 3610 | } |
| 3611 | 3611 | |
| 3612 | 3612 | /** |
@@ -3614,44 +3614,44 @@ discard block |
||
| 3614 | 3614 | * |
| 3615 | 3615 | * @since 2.8.8 |
| 3616 | 3616 | */ |
| 3617 | - public function get_tax_item_amount( $tax_key, $tax_item, $with_currency = false ) { |
|
| 3618 | - $tax_amount = $this->get_tax_total_by_name( $tax_key ); |
|
| 3617 | + public function get_tax_item_amount($tax_key, $tax_item, $with_currency = false) { |
|
| 3618 | + $tax_amount = $this->get_tax_total_by_name($tax_key); |
|
| 3619 | 3619 | |
| 3620 | - if ( $with_currency ) { |
|
| 3621 | - $tax_amount = wpinv_price( $tax_amount, $this->get_currency() ); |
|
| 3620 | + if ($with_currency) { |
|
| 3621 | + $tax_amount = wpinv_price($tax_amount, $this->get_currency()); |
|
| 3622 | 3622 | } |
| 3623 | 3623 | |
| 3624 | - return apply_filters( 'wpinv_invoice_get_tax_amount', $tax_amount, $this, $tax_item, $with_currency ); |
|
| 3624 | + return apply_filters('wpinv_invoice_get_tax_amount', $tax_amount, $this, $tax_item, $with_currency); |
|
| 3625 | 3625 | } |
| 3626 | 3626 | |
| 3627 | - public function get_item_tax_name( $percentage = true, $sep = ' + ' ) { |
|
| 3627 | + public function get_item_tax_name($percentage = true, $sep = ' + ') { |
|
| 3628 | 3628 | $taxes = $this->get_taxes(); |
| 3629 | 3629 | |
| 3630 | - if ( ! empty( $taxes ) && is_array( $taxes ) && count( $taxes ) == 1 && wpinv_display_individual_tax_rates() ) { |
|
| 3630 | + if (!empty($taxes) && is_array($taxes) && count($taxes) == 1 && wpinv_display_individual_tax_rates()) { |
|
| 3631 | 3631 | $names = array(); |
| 3632 | 3632 | |
| 3633 | - foreach ( $taxes as $key => $tax ) { |
|
| 3634 | - if ( ! empty( $tax ) && ! empty( $tax['name'] ) ) { |
|
| 3635 | - $name = __( $tax['name'], 'invoicing' ); |
|
| 3633 | + foreach ($taxes as $key => $tax) { |
|
| 3634 | + if (!empty($tax) && !empty($tax['name'])) { |
|
| 3635 | + $name = __($tax['name'], 'invoicing'); |
|
| 3636 | 3636 | |
| 3637 | 3637 | $names[] = $name; |
| 3638 | 3638 | } |
| 3639 | 3639 | } |
| 3640 | 3640 | |
| 3641 | - if ( ! empty( $names ) ) { |
|
| 3642 | - $names = array_unique( $names ); |
|
| 3641 | + if (!empty($names)) { |
|
| 3642 | + $names = array_unique($names); |
|
| 3643 | 3643 | |
| 3644 | - $tax_name = implode( $sep, $names ); |
|
| 3644 | + $tax_name = implode($sep, $names); |
|
| 3645 | 3645 | } |
| 3646 | 3646 | |
| 3647 | - if ( $percentage ) { |
|
| 3648 | - $tax_name = wp_sprintf( _x( '%s (%%)', 'Tax name with %. Ex: Tax (%)', 'invoicing' ), $tax_name ); |
|
| 3647 | + if ($percentage) { |
|
| 3648 | + $tax_name = wp_sprintf(_x('%s (%%)', 'Tax name with %. Ex: Tax (%)', 'invoicing'), $tax_name); |
|
| 3649 | 3649 | } |
| 3650 | 3650 | } else { |
| 3651 | - $tax_name = $percentage ? __( 'Tax (%)', 'invoicing' ) : _x( 'Tax', 'Tax name', 'invoicing' ); |
|
| 3651 | + $tax_name = $percentage ? __('Tax (%)', 'invoicing') : _x('Tax', 'Tax name', 'invoicing'); |
|
| 3652 | 3652 | } |
| 3653 | 3653 | |
| 3654 | - return apply_filters( 'wpinv_invoice_get_item_tax_name', $tax_name, $this, $percentage, $sep ); |
|
| 3654 | + return apply_filters('wpinv_invoice_get_item_tax_name', $tax_name, $this, $percentage, $sep); |
|
| 3655 | 3655 | } |
| 3656 | 3656 | |
| 3657 | 3657 | /** |
@@ -3659,11 +3659,11 @@ discard block |
||
| 3659 | 3659 | * |
| 3660 | 3660 | * @since 1.0.19 |
| 3661 | 3661 | */ |
| 3662 | - public function remove_tax( $tax ) { |
|
| 3662 | + public function remove_tax($tax) { |
|
| 3663 | 3663 | $taxes = $this->get_taxes(); |
| 3664 | - if ( isset( $taxes[ $tax ] ) ) { |
|
| 3665 | - unset( $taxes[ $tax ] ); |
|
| 3666 | - $this->set_prop( 'taxes', $taxes ); |
|
| 3664 | + if (isset($taxes[$tax])) { |
|
| 3665 | + unset($taxes[$tax]); |
|
| 3666 | + $this->set_prop('taxes', $taxes); |
|
| 3667 | 3667 | } |
| 3668 | 3668 | } |
| 3669 | 3669 | |
@@ -3674,22 +3674,22 @@ discard block |
||
| 3674 | 3674 | * @return float The recalculated subtotal |
| 3675 | 3675 | */ |
| 3676 | 3676 | public function recalculate_subtotal() { |
| 3677 | - $items = $this->get_items(); |
|
| 3677 | + $items = $this->get_items(); |
|
| 3678 | 3678 | $subtotal = 0; |
| 3679 | 3679 | $recurring = 0; |
| 3680 | 3680 | |
| 3681 | - foreach ( $items as $item ) { |
|
| 3682 | - $subtotal += $item->get_sub_total( 'edit' ); |
|
| 3683 | - $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
| 3681 | + foreach ($items as $item) { |
|
| 3682 | + $subtotal += $item->get_sub_total('edit'); |
|
| 3683 | + $recurring += $item->get_recurring_sub_total('edit'); |
|
| 3684 | 3684 | } |
| 3685 | 3685 | |
| 3686 | - if ( wpinv_prices_include_tax() ) { |
|
| 3687 | - $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
| 3688 | - $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
| 3686 | + if (wpinv_prices_include_tax()) { |
|
| 3687 | + $subtotal = max(0, $subtotal - $this->totals['tax']['initial']); |
|
| 3688 | + $recurring = max(0, $recurring - $this->totals['tax']['recurring']); |
|
| 3689 | 3689 | } |
| 3690 | 3690 | |
| 3691 | 3691 | $current = $this->is_renewal() ? $recurring : $subtotal; |
| 3692 | - $this->set_subtotal( $current ); |
|
| 3692 | + $this->set_subtotal($current); |
|
| 3693 | 3693 | |
| 3694 | 3694 | $this->totals['subtotal'] = array( |
| 3695 | 3695 | 'initial' => $subtotal, |
@@ -3707,12 +3707,12 @@ discard block |
||
| 3707 | 3707 | */ |
| 3708 | 3708 | public function recalculate_total_discount() { |
| 3709 | 3709 | // Fix renewal invoice amount when tax + recurring discount applied. |
| 3710 | - if ( $this->is_renewal() && $this->get_discount_code() ) { |
|
| 3710 | + if ($this->is_renewal() && $this->get_discount_code()) { |
|
| 3711 | 3711 | // Maybe recalculate discount (Pre-GetPaid Fix). |
| 3712 | - $discount = new WPInv_Discount( $this->get_discount_code() ); |
|
| 3712 | + $discount = new WPInv_Discount($this->get_discount_code()); |
|
| 3713 | 3713 | |
| 3714 | - if ( $discount->exists() && $discount->is_recurring() ) { |
|
| 3715 | - getpaid_calculate_invoice_discount( $this, $discount ); |
|
| 3714 | + if ($discount->exists() && $discount->is_recurring()) { |
|
| 3715 | + getpaid_calculate_invoice_discount($this, $discount); |
|
| 3716 | 3716 | } |
| 3717 | 3717 | } |
| 3718 | 3718 | |
@@ -3720,14 +3720,14 @@ discard block |
||
| 3720 | 3720 | $discount = 0; |
| 3721 | 3721 | $recurring = 0; |
| 3722 | 3722 | |
| 3723 | - foreach ( $discounts as $data ) { |
|
| 3724 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3725 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3723 | + foreach ($discounts as $data) { |
|
| 3724 | + $discount += wpinv_sanitize_amount($data['initial_discount']); |
|
| 3725 | + $recurring += wpinv_sanitize_amount($data['recurring_discount']); |
|
| 3726 | 3726 | } |
| 3727 | 3727 | |
| 3728 | 3728 | $current = $this->is_renewal() ? $recurring : $discount; |
| 3729 | 3729 | |
| 3730 | - $this->set_total_discount( $current ); |
|
| 3730 | + $this->set_total_discount($current); |
|
| 3731 | 3731 | |
| 3732 | 3732 | $this->totals['discount'] = array( |
| 3733 | 3733 | 'initial' => $discount, |
@@ -3747,13 +3747,13 @@ discard block |
||
| 3747 | 3747 | |
| 3748 | 3748 | // Maybe disable taxes. |
| 3749 | 3749 | $vat_number = $this->get_vat_number(); |
| 3750 | - $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
| 3750 | + $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($this->get_country()) && !empty($vat_number); |
|
| 3751 | 3751 | |
| 3752 | - if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 3752 | + if (wpinv_is_base_country($this->get_country()) && 'vat_too' === wpinv_get_option('vat_same_country_rule', 'vat_too')) { |
|
| 3753 | 3753 | $skip_tax = false; |
| 3754 | 3754 | } |
| 3755 | 3755 | |
| 3756 | - if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
| 3756 | + if (!wpinv_use_taxes() || $this->get_disable_taxes() || !wpinv_is_country_taxable($this->get_country()) || $skip_tax) { |
|
| 3757 | 3757 | |
| 3758 | 3758 | $this->totals['tax'] = array( |
| 3759 | 3759 | 'initial' => 0, |
@@ -3762,36 +3762,36 @@ discard block |
||
| 3762 | 3762 | |
| 3763 | 3763 | $this->tax_rate = 0; |
| 3764 | 3764 | |
| 3765 | - $this->set_taxes( array() ); |
|
| 3765 | + $this->set_taxes(array()); |
|
| 3766 | 3766 | $current = 0; |
| 3767 | 3767 | } else { |
| 3768 | 3768 | |
| 3769 | 3769 | $item_taxes = array(); |
| 3770 | 3770 | |
| 3771 | - foreach ( $this->get_items() as $item ) { |
|
| 3772 | - $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
| 3773 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 3774 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 3775 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 3776 | - foreach ( $taxes as $name => $amount ) { |
|
| 3777 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 3778 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 3779 | - |
|
| 3780 | - if ( ! isset( $item_taxes[ $name ] ) ) { |
|
| 3781 | - $item_taxes[ $name ] = $tax; |
|
| 3771 | + foreach ($this->get_items() as $item) { |
|
| 3772 | + $rates = getpaid_get_item_tax_rates($item, $this->get_country(), $this->get_state()); |
|
| 3773 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
| 3774 | + $taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates); |
|
| 3775 | + $r_taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates); |
|
| 3776 | + foreach ($taxes as $name => $amount) { |
|
| 3777 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
| 3778 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
| 3779 | + |
|
| 3780 | + if (!isset($item_taxes[$name])) { |
|
| 3781 | + $item_taxes[$name] = $tax; |
|
| 3782 | 3782 | continue; |
| 3783 | 3783 | } |
| 3784 | 3784 | |
| 3785 | - $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 3786 | - $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3785 | + $item_taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
| 3786 | + $item_taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3787 | 3787 | |
| 3788 | 3788 | } |
| 3789 | 3789 | } |
| 3790 | 3790 | |
| 3791 | - $this->set_taxes( $item_taxes ); |
|
| 3791 | + $this->set_taxes($item_taxes); |
|
| 3792 | 3792 | |
| 3793 | - $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
| 3794 | - $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
| 3793 | + $initial_tax = array_sum(wp_list_pluck($item_taxes, 'initial_tax')); |
|
| 3794 | + $recurring_tax = array_sum(wp_list_pluck($item_taxes, 'recurring_tax')); |
|
| 3795 | 3795 | |
| 3796 | 3796 | $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
| 3797 | 3797 | |
@@ -3802,7 +3802,7 @@ discard block |
||
| 3802 | 3802 | |
| 3803 | 3803 | } |
| 3804 | 3804 | |
| 3805 | - $this->set_total_tax( $current ); |
|
| 3805 | + $this->set_total_tax($current); |
|
| 3806 | 3806 | |
| 3807 | 3807 | return $current; |
| 3808 | 3808 | } |
@@ -3818,20 +3818,20 @@ discard block |
||
| 3818 | 3818 | $fee = 0; |
| 3819 | 3819 | $recurring = 0; |
| 3820 | 3820 | |
| 3821 | - foreach ( $fees as $data ) { |
|
| 3822 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3823 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3821 | + foreach ($fees as $data) { |
|
| 3822 | + $fee += wpinv_sanitize_amount($data['initial_fee']); |
|
| 3823 | + $recurring += wpinv_sanitize_amount($data['recurring_fee']); |
|
| 3824 | 3824 | } |
| 3825 | 3825 | |
| 3826 | 3826 | $current = $this->is_renewal() ? $recurring : $fee; |
| 3827 | - $this->set_total_fees( $current ); |
|
| 3827 | + $this->set_total_fees($current); |
|
| 3828 | 3828 | |
| 3829 | 3829 | $this->totals['fee'] = array( |
| 3830 | 3830 | 'initial' => $fee, |
| 3831 | 3831 | 'recurring' => $recurring, |
| 3832 | 3832 | ); |
| 3833 | 3833 | |
| 3834 | - $this->set_total_fees( $fee ); |
|
| 3834 | + $this->set_total_fees($fee); |
|
| 3835 | 3835 | return $current; |
| 3836 | 3836 | } |
| 3837 | 3837 | |
@@ -3846,7 +3846,7 @@ discard block |
||
| 3846 | 3846 | $this->recalculate_total_discount(); |
| 3847 | 3847 | $this->recalculate_total_tax(); |
| 3848 | 3848 | $this->recalculate_subtotal(); |
| 3849 | - $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
| 3849 | + $this->set_total($this->get_total_tax('edit') + $this->get_total_fees('edit') + $this->get_subtotal('edit') - $this->get_total_discount('edit')); |
|
| 3850 | 3850 | return $this->get_total(); |
| 3851 | 3851 | } |
| 3852 | 3852 | |
@@ -3855,7 +3855,7 @@ discard block |
||
| 3855 | 3855 | */ |
| 3856 | 3856 | public function recalculate_totals() { |
| 3857 | 3857 | $this->recalculate_total(); |
| 3858 | - $this->save( true ); |
|
| 3858 | + $this->save(true); |
|
| 3859 | 3859 | return $this; |
| 3860 | 3860 | } |
| 3861 | 3861 | |
@@ -3873,8 +3873,8 @@ discard block |
||
| 3873 | 3873 | * @return int|false The new note's ID on success, false on failure. |
| 3874 | 3874 | * |
| 3875 | 3875 | */ |
| 3876 | - public function add_system_note( $note ) { |
|
| 3877 | - return $this->add_note( $note, false, false, true ); |
|
| 3876 | + public function add_system_note($note) { |
|
| 3877 | + return $this->add_note($note, false, false, true); |
|
| 3878 | 3878 | } |
| 3879 | 3879 | |
| 3880 | 3880 | /** |
@@ -3884,10 +3884,10 @@ discard block |
||
| 3884 | 3884 | * @return int|false The new note's ID on success, false on failure. |
| 3885 | 3885 | * |
| 3886 | 3886 | */ |
| 3887 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
| 3887 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
| 3888 | 3888 | |
| 3889 | 3889 | // Bail if no note specified or this invoice is not yet saved. |
| 3890 | - if ( ! $note || $this->get_id() == 0 || ( ! is_user_logged_in() && ! $system ) ) { |
|
| 3890 | + if (!$note || $this->get_id() == 0 || (!is_user_logged_in() && !$system)) { |
|
| 3891 | 3891 | return false; |
| 3892 | 3892 | } |
| 3893 | 3893 | |
@@ -3895,22 +3895,22 @@ discard block |
||
| 3895 | 3895 | $author_email = '[email protected]'; |
| 3896 | 3896 | |
| 3897 | 3897 | // If this is an admin comment or it has been added by the user. |
| 3898 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3899 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3898 | + if (is_user_logged_in() && (!$system || $added_by_user)) { |
|
| 3899 | + $user = get_user_by('id', get_current_user_id()); |
|
| 3900 | 3900 | $author = $user->display_name; |
| 3901 | 3901 | $author_email = $user->user_email; |
| 3902 | 3902 | } |
| 3903 | 3903 | |
| 3904 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3904 | + return getpaid_notes()->add_invoice_note($this, $note, $author, $author_email, $customer_type); |
|
| 3905 | 3905 | } |
| 3906 | 3906 | |
| 3907 | 3907 | /** |
| 3908 | 3908 | * Generates a unique key for the invoice. |
| 3909 | 3909 | */ |
| 3910 | - public function generate_key( $string = '' ) { |
|
| 3911 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 3910 | + public function generate_key($string = '') { |
|
| 3911 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 3912 | 3912 | return strtolower( |
| 3913 | - $string . md5( $this->get_id() . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) |
|
| 3913 | + $string . md5($this->get_id() . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true)) |
|
| 3914 | 3914 | ); |
| 3915 | 3915 | } |
| 3916 | 3916 | |
@@ -3920,11 +3920,11 @@ discard block |
||
| 3920 | 3920 | public function generate_number() { |
| 3921 | 3921 | $number = $this->get_id(); |
| 3922 | 3922 | |
| 3923 | - if ( wpinv_sequential_number_active( $this->get_post_type() ) ) { |
|
| 3924 | - $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
|
| 3923 | + if (wpinv_sequential_number_active($this->get_post_type())) { |
|
| 3924 | + $number = wpinv_get_next_invoice_number($this->get_post_type()); |
|
| 3925 | 3925 | } |
| 3926 | 3926 | |
| 3927 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3927 | + return wpinv_format_invoice_number($number, $this->get_post_type()); |
|
| 3928 | 3928 | } |
| 3929 | 3929 | |
| 3930 | 3930 | /** |
@@ -3936,55 +3936,55 @@ discard block |
||
| 3936 | 3936 | // Reset status transition variable. |
| 3937 | 3937 | $this->status_transition = false; |
| 3938 | 3938 | |
| 3939 | - if ( $status_transition ) { |
|
| 3939 | + if ($status_transition) { |
|
| 3940 | 3940 | try { |
| 3941 | 3941 | |
| 3942 | 3942 | // Fire a hook for the status change. |
| 3943 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3943 | + do_action('getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition); |
|
| 3944 | 3944 | |
| 3945 | 3945 | // @deprecated this is deprecated and will be removed in the future. |
| 3946 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3946 | + do_action('wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from']); |
|
| 3947 | 3947 | |
| 3948 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 3948 | + if (!empty($status_transition['from'])) { |
|
| 3949 | 3949 | |
| 3950 | 3950 | /* translators: 1: old invoice status 2: new invoice status */ |
| 3951 | - $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 ) ); |
|
| 3951 | + $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)); |
|
| 3952 | 3952 | |
| 3953 | 3953 | // Fire another hook. |
| 3954 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3955 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3954 | + do_action('getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this); |
|
| 3955 | + do_action('getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to']); |
|
| 3956 | 3956 | |
| 3957 | 3957 | // @deprecated this is deprecated and will be removed in the future. |
| 3958 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3958 | + do_action('wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from']); |
|
| 3959 | 3959 | |
| 3960 | 3960 | // Note the transition occurred. |
| 3961 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3961 | + $this->add_note(trim($status_transition['note'] . ' ' . $transition_note), false, $status_transition['manual']); |
|
| 3962 | 3962 | |
| 3963 | 3963 | // Work out if this was for a payment, and trigger a payment_status hook instead. |
| 3964 | 3964 | if ( |
| 3965 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3966 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3965 | + in_array($status_transition['from'], array('wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold'), true) |
|
| 3966 | + && in_array($status_transition['to'], array('publish', 'wpi-processing', 'wpi-renewal'), true) |
|
| 3967 | 3967 | ) { |
| 3968 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3968 | + do_action('getpaid_invoice_payment_status_changed', $this, $status_transition); |
|
| 3969 | 3969 | } |
| 3970 | 3970 | |
| 3971 | 3971 | // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
| 3972 | 3972 | if ( |
| 3973 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3974 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3973 | + in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'), true) |
|
| 3974 | + && in_array($status_transition['to'], array('wpi-cancelled', 'pending', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold'), true) |
|
| 3975 | 3975 | ) { |
| 3976 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3976 | + do_action('getpaid_invoice_payment_status_reversed', $this, $status_transition); |
|
| 3977 | 3977 | } |
| 3978 | 3978 | } else { |
| 3979 | 3979 | /* translators: %s: new invoice status */ |
| 3980 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3980 | + $transition_note = sprintf(__('Status set to %s.', 'invoicing'), wpinv_status_nicename($status_transition['to'], $this)); |
|
| 3981 | 3981 | |
| 3982 | 3982 | // Note the transition occurred. |
| 3983 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3983 | + $this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']); |
|
| 3984 | 3984 | |
| 3985 | 3985 | } |
| 3986 | - } catch ( Exception $e ) { |
|
| 3987 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3986 | + } catch (Exception $e) { |
|
| 3987 | + $this->add_note(__('Error during status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
| 3988 | 3988 | } |
| 3989 | 3989 | } |
| 3990 | 3990 | } |
@@ -3992,13 +3992,13 @@ discard block |
||
| 3992 | 3992 | /** |
| 3993 | 3993 | * Updates an invoice status. |
| 3994 | 3994 | */ |
| 3995 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3995 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
| 3996 | 3996 | |
| 3997 | 3997 | // Fires before updating a status. |
| 3998 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3998 | + do_action('wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status('edit')); |
|
| 3999 | 3999 | |
| 4000 | 4000 | // Update the status. |
| 4001 | - $this->set_status( $new_status, $note, $manual ); |
|
| 4001 | + $this->set_status($new_status, $note, $manual); |
|
| 4002 | 4002 | |
| 4003 | 4003 | // Save the order. |
| 4004 | 4004 | return $this->save(); |
@@ -4008,18 +4008,18 @@ discard block |
||
| 4008 | 4008 | * @deprecated |
| 4009 | 4009 | */ |
| 4010 | 4010 | public function refresh_item_ids() { |
| 4011 | - $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) ); |
|
| 4012 | - update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
|
| 4011 | + $item_ids = implode(',', array_unique(wp_list_pluck($this->get_cart_details(), 'item_id'))); |
|
| 4012 | + update_post_meta($this->get_id(), '_wpinv_item_ids', $item_ids); |
|
| 4013 | 4013 | } |
| 4014 | 4014 | |
| 4015 | 4015 | /** |
| 4016 | 4016 | * @deprecated |
| 4017 | 4017 | */ |
| 4018 | - public function update_items( $temp = false ) { |
|
| 4018 | + public function update_items($temp = false) { |
|
| 4019 | 4019 | |
| 4020 | - $this->set_items( $this->get_items() ); |
|
| 4020 | + $this->set_items($this->get_items()); |
|
| 4021 | 4021 | |
| 4022 | - if ( ! $temp ) { |
|
| 4022 | + if (!$temp) { |
|
| 4023 | 4023 | $this->save(); |
| 4024 | 4024 | } |
| 4025 | 4025 | |
@@ -4033,11 +4033,11 @@ discard block |
||
| 4033 | 4033 | |
| 4034 | 4034 | $discount_code = $this->get_discount_code(); |
| 4035 | 4035 | |
| 4036 | - if ( empty( $discount_code ) ) { |
|
| 4036 | + if (empty($discount_code)) { |
|
| 4037 | 4037 | return false; |
| 4038 | 4038 | } |
| 4039 | 4039 | |
| 4040 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
| 4040 | + $discount = wpinv_get_discount_obj($discount_code); |
|
| 4041 | 4041 | |
| 4042 | 4042 | // Ensure it is active. |
| 4043 | 4043 | return $discount->exists(); |
@@ -4047,7 +4047,7 @@ discard block |
||
| 4047 | 4047 | * Refunds an invoice. |
| 4048 | 4048 | */ |
| 4049 | 4049 | public function refund() { |
| 4050 | - $this->set_status( 'wpi-refunded' ); |
|
| 4050 | + $this->set_status('wpi-refunded'); |
|
| 4051 | 4051 | $this->save(); |
| 4052 | 4052 | } |
| 4053 | 4053 | |
@@ -4056,53 +4056,53 @@ discard block |
||
| 4056 | 4056 | * |
| 4057 | 4057 | * @param string $transaction_id |
| 4058 | 4058 | */ |
| 4059 | - public function mark_paid( $transaction_id = null, $note = '' ) { |
|
| 4059 | + public function mark_paid($transaction_id = null, $note = '') { |
|
| 4060 | 4060 | |
| 4061 | 4061 | // Set the transaction id. |
| 4062 | - if ( empty( $transaction_id ) ) { |
|
| 4063 | - $transaction_id = $this->generate_key( 'trans_' ); |
|
| 4062 | + if (empty($transaction_id)) { |
|
| 4063 | + $transaction_id = $this->generate_key('trans_'); |
|
| 4064 | 4064 | } |
| 4065 | 4065 | |
| 4066 | - if ( ! $this->get_transaction_id() ) { |
|
| 4067 | - $this->set_transaction_id( $transaction_id ); |
|
| 4066 | + if (!$this->get_transaction_id()) { |
|
| 4067 | + $this->set_transaction_id($transaction_id); |
|
| 4068 | 4068 | } |
| 4069 | 4069 | |
| 4070 | - if ( $this->is_paid() && 'wpi-processing' !== $this->get_status() ) { |
|
| 4070 | + if ($this->is_paid() && 'wpi-processing' !== $this->get_status()) { |
|
| 4071 | 4071 | return $this->save(); |
| 4072 | 4072 | } |
| 4073 | 4073 | |
| 4074 | 4074 | // Set the completed date. |
| 4075 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 4075 | + $this->set_date_completed(current_time('mysql')); |
|
| 4076 | 4076 | |
| 4077 | 4077 | // Set the new status. |
| 4078 | - $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
| 4079 | - if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
| 4078 | + $gateway = sanitize_text_field($this->get_gateway_title()); |
|
| 4079 | + if ($this->is_renewal() || !$this->is_parent()) { |
|
| 4080 | 4080 | |
| 4081 | - $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
| 4082 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 4081 | + $_note = wp_sprintf(__('Renewed via %s', 'invoicing'), $gateway); |
|
| 4082 | + $_note = $_note . empty($note) ? '' : " ($note)"; |
|
| 4083 | 4083 | |
| 4084 | - if ( 'none' == $this->get_gateway() ) { |
|
| 4084 | + if ('none' == $this->get_gateway()) { |
|
| 4085 | 4085 | $_note = $note; |
| 4086 | 4086 | } |
| 4087 | 4087 | |
| 4088 | - $this->set_status( 'wpi-renewal', $_note ); |
|
| 4088 | + $this->set_status('wpi-renewal', $_note); |
|
| 4089 | 4089 | |
| 4090 | 4090 | } else { |
| 4091 | 4091 | |
| 4092 | - $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 4093 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 4092 | + $_note = wp_sprintf(__('Paid via %s', 'invoicing'), $gateway); |
|
| 4093 | + $_note = $_note . empty($note) ? '' : " ($note)"; |
|
| 4094 | 4094 | |
| 4095 | - if ( 'none' == $this->get_gateway() ) { |
|
| 4095 | + if ('none' == $this->get_gateway()) { |
|
| 4096 | 4096 | $_note = $note; |
| 4097 | 4097 | } |
| 4098 | 4098 | |
| 4099 | - $this->set_status( 'publish', $_note ); |
|
| 4099 | + $this->set_status('publish', $_note); |
|
| 4100 | 4100 | |
| 4101 | 4101 | } |
| 4102 | 4102 | |
| 4103 | 4103 | // Set checkout mode. |
| 4104 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 4105 | - $this->set_mode( $mode ); |
|
| 4104 | + $mode = wpinv_is_test_mode($this->get_gateway()) ? 'test' : 'live'; |
|
| 4105 | + $this->set_mode($mode); |
|
| 4106 | 4106 | |
| 4107 | 4107 | // Save the invoice. |
| 4108 | 4108 | $this->save(); |
@@ -4127,16 +4127,16 @@ discard block |
||
| 4127 | 4127 | * Clears the subscription's cache. |
| 4128 | 4128 | */ |
| 4129 | 4129 | public function clear_cache() { |
| 4130 | - if ( $this->get_key() ) { |
|
| 4131 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 4130 | + if ($this->get_key()) { |
|
| 4131 | + wp_cache_delete($this->get_key(), 'getpaid_invoice_keys_to_invoice_ids'); |
|
| 4132 | 4132 | } |
| 4133 | 4133 | |
| 4134 | - if ( $this->get_number() ) { |
|
| 4135 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 4134 | + if ($this->get_number()) { |
|
| 4135 | + wp_cache_delete($this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids'); |
|
| 4136 | 4136 | } |
| 4137 | 4137 | |
| 4138 | - if ( $this->get_transaction_id() ) { |
|
| 4139 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 4138 | + if ($this->get_transaction_id()) { |
|
| 4139 | + wp_cache_delete($this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids'); |
|
| 4140 | 4140 | } |
| 4141 | 4141 | } |
| 4142 | 4142 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Retrieves the current invoice. |
@@ -14,15 +14,15 @@ discard block |
||
| 14 | 14 | function getpaid_get_current_invoice_id() { |
| 15 | 15 | |
| 16 | 16 | // Ensure that we have an invoice key. |
| 17 | - if ( empty( $_GET['invoice_key'] ) ) { |
|
| 17 | + if (empty($_GET['invoice_key'])) { |
|
| 18 | 18 | return 0; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | // Retrieve an invoice using the key. |
| 22 | - $invoice = new WPInv_Invoice( sanitize_text_field( $_GET['invoice_key'] ) ); |
|
| 22 | + $invoice = new WPInv_Invoice(sanitize_text_field($_GET['invoice_key'])); |
|
| 23 | 23 | |
| 24 | 24 | // Compare the invoice key and the parsed key. |
| 25 | - if ( $invoice->get_id() != 0 && $invoice->get_key() == sanitize_text_field( $_GET['invoice_key'] ) ) { |
|
| 25 | + if ($invoice->get_id() != 0 && $invoice->get_key() == sanitize_text_field($_GET['invoice_key'])) { |
|
| 26 | 26 | return $invoice->get_id(); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -32,42 +32,42 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * Checks if the current user cna view an invoice. |
| 34 | 34 | */ |
| 35 | -function wpinv_user_can_view_invoice( $invoice ) { |
|
| 36 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 35 | +function wpinv_user_can_view_invoice($invoice) { |
|
| 36 | + $invoice = new WPInv_Invoice($invoice); |
|
| 37 | 37 | |
| 38 | 38 | // Abort if the invoice does not exist. |
| 39 | - if ( 0 == $invoice->get_id() ) { |
|
| 39 | + if (0 == $invoice->get_id()) { |
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // Don't allow trash, draft status |
| 44 | - if ( $invoice->is_draft() ) { |
|
| 44 | + if ($invoice->is_draft()) { |
|
| 45 | 45 | return false; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // If users are not required to login to check out, compare the invoice keys. |
| 49 | - if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && sanitize_text_field( $_GET['invoice_key'] ) == $invoice->get_key() ) { |
|
| 49 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && sanitize_text_field($_GET['invoice_key']) == $invoice->get_key()) { |
|
| 50 | 50 | return true; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Always enable for admins.. |
| 54 | - if ( wpinv_current_user_can( 'view_invoice', array( 'invoice' => $invoice ) ) || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user |
|
| 54 | + if (wpinv_current_user_can('view_invoice', array('invoice' => $invoice)) || current_user_can('view_invoices', $invoice->get_id())) { // Admin user |
|
| 55 | 55 | return true; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Else, ensure that this is their invoice. |
| 59 | - if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) { |
|
| 59 | + if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) { |
|
| 60 | 60 | return true; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice ); |
|
| 63 | + return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Checks if the current user cna view an invoice receipt. |
| 68 | 68 | */ |
| 69 | -function wpinv_can_view_receipt( $invoice ) { |
|
| 70 | - return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice ); |
|
| 69 | +function wpinv_can_view_receipt($invoice) { |
|
| 70 | + return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function getpaid_get_invoice_post_types() { |
| 79 | 79 | $post_types = array( |
| 80 | - 'wpi_quote' => __( 'Quote', 'invoicing' ), |
|
| 81 | - 'wpi_invoice' => __( 'Invoice', 'invoicing' ), |
|
| 80 | + 'wpi_quote' => __('Quote', 'invoicing'), |
|
| 81 | + 'wpi_invoice' => __('Invoice', 'invoicing'), |
|
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | 84 | // Ensure the quotes addon is installed. |
| 85 | - if ( ! defined( 'WPINV_QUOTES_VERSION' ) ) { |
|
| 86 | - unset( $post_types['wpi_quote'] ); |
|
| 85 | + if (!defined('WPINV_QUOTES_VERSION')) { |
|
| 86 | + unset($post_types['wpi_quote']); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - return apply_filters( 'getpaid_invoice_post_types', $post_types ); |
|
| 89 | + return apply_filters('getpaid_invoice_post_types', $post_types); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @param string $post_type The post type to check for. |
| 97 | 97 | */ |
| 98 | -function getpaid_is_invoice_post_type( $post_type ) { |
|
| 99 | - return is_scalar( $post_type ) && ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() ); |
|
| 98 | +function getpaid_is_invoice_post_type($post_type) { |
|
| 99 | + return is_scalar($post_type) && !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types()); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
| 107 | 107 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
| 108 | 108 | */ |
| 109 | -function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) { |
|
| 109 | +function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) { |
|
| 110 | 110 | $data['invoice_id'] = 0; |
| 111 | - return wpinv_insert_invoice( $data, $wp_error ); |
|
| 111 | + return wpinv_insert_invoice($data, $wp_error); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -118,35 +118,35 @@ discard block |
||
| 118 | 118 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
| 119 | 119 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
| 120 | 120 | */ |
| 121 | -function wpinv_update_invoice( $data = array(), $wp_error = false ) { |
|
| 121 | +function wpinv_update_invoice($data = array(), $wp_error = false) { |
|
| 122 | 122 | |
| 123 | 123 | // Backwards compatibility. |
| 124 | - if ( ! empty( $data['ID'] ) ) { |
|
| 124 | + if (!empty($data['ID'])) { |
|
| 125 | 125 | $data['invoice_id'] = $data['ID']; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Do we have an invoice id? |
| 129 | - if ( empty( $data['invoice_id'] ) ) { |
|
| 130 | - return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0; |
|
| 129 | + if (empty($data['invoice_id'])) { |
|
| 130 | + return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // Retrieve the invoice. |
| 134 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
| 134 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
| 135 | 135 | |
| 136 | 136 | // And abort if it does not exist. |
| 137 | - if ( empty( $invoice ) ) { |
|
| 138 | - return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0; |
|
| 137 | + if (empty($invoice)) { |
|
| 138 | + return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // Do not update totals for paid / refunded invoices. |
| 142 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 142 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 143 | 143 | |
| 144 | - if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) { |
|
| 145 | - return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0; |
|
| 144 | + if (!empty($data['items']) || !empty($data['cart_details'])) { |
|
| 145 | + return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - return wpinv_insert_invoice( $data, $wp_error ); |
|
| 149 | + return wpinv_insert_invoice($data, $wp_error); |
|
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | |
@@ -157,62 +157,62 @@ discard block |
||
| 157 | 157 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
| 158 | 158 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
| 159 | 159 | */ |
| 160 | -function wpinv_insert_invoice( $data = array(), $wp_error = false ) { |
|
| 160 | +function wpinv_insert_invoice($data = array(), $wp_error = false) { |
|
| 161 | 161 | |
| 162 | 162 | // Ensure that we have invoice data. |
| 163 | - if ( empty( $data ) ) { |
|
| 163 | + if (empty($data)) { |
|
| 164 | 164 | return false; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // The invoice id will be provided when updating an invoice. |
| 168 | - $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false; |
|
| 168 | + $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false; |
|
| 169 | 169 | |
| 170 | 170 | // Retrieve the invoice. |
| 171 | - $invoice = new WPInv_Invoice( $data['invoice_id'] ); |
|
| 171 | + $invoice = new WPInv_Invoice($data['invoice_id']); |
|
| 172 | 172 | |
| 173 | 173 | // Do we have an error? |
| 174 | - if ( ! empty( $invoice->last_error ) ) { |
|
| 175 | - return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0; |
|
| 174 | + if (!empty($invoice->last_error)) { |
|
| 175 | + return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // Backwards compatibility (billing address). |
| 179 | - if ( ! empty( $data['user_info'] ) ) { |
|
| 179 | + if (!empty($data['user_info'])) { |
|
| 180 | 180 | |
| 181 | - foreach ( $data['user_info'] as $key => $value ) { |
|
| 181 | + foreach ($data['user_info'] as $key => $value) { |
|
| 182 | 182 | |
| 183 | - if ( $key == 'discounts' ) { |
|
| 183 | + if ($key == 'discounts') { |
|
| 184 | 184 | $value = (array) $value; |
| 185 | - $data['discount_code'] = empty( $value ) ? null : $value[0]; |
|
| 185 | + $data['discount_code'] = empty($value) ? null : $value[0]; |
|
| 186 | 186 | } else { |
| 187 | - $data[ $key ] = $value; |
|
| 187 | + $data[$key] = $value; |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // Backwards compatibility. |
| 193 | - if ( ! empty( $data['payment_details'] ) ) { |
|
| 193 | + if (!empty($data['payment_details'])) { |
|
| 194 | 194 | |
| 195 | - foreach ( $data['payment_details'] as $key => $value ) { |
|
| 196 | - $data[ $key ] = $value; |
|
| 195 | + foreach ($data['payment_details'] as $key => $value) { |
|
| 196 | + $data[$key] = $value; |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Set up the owner of the invoice. |
| 201 | - $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id(); |
|
| 201 | + $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id(); |
|
| 202 | 202 | |
| 203 | 203 | // Make sure the user exists. |
| 204 | - if ( ! get_userdata( $user_id ) ) { |
|
| 205 | - return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0; |
|
| 204 | + if (!get_userdata($user_id)) { |
|
| 205 | + return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $address = wpinv_get_user_address( $user_id ); |
|
| 208 | + $address = wpinv_get_user_address($user_id); |
|
| 209 | 209 | |
| 210 | - foreach ( $address as $key => $value ) { |
|
| 210 | + foreach ($address as $key => $value) { |
|
| 211 | 211 | |
| 212 | - if ( $value == '' ) { |
|
| 213 | - $address[ $key ] = null; |
|
| 212 | + if ($value == '') { |
|
| 213 | + $address[$key] = null; |
|
| 214 | 214 | } else { |
| 215 | - $address[ $key ] = wpinv_clean( $value ); |
|
| 215 | + $address[$key] = wpinv_clean($value); |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
@@ -221,101 +221,101 @@ discard block |
||
| 221 | 221 | array( |
| 222 | 222 | |
| 223 | 223 | // Basic info. |
| 224 | - 'template' => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null, |
|
| 225 | - 'email_cc' => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null, |
|
| 226 | - 'date_created' => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null, |
|
| 227 | - 'due_date' => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null, |
|
| 228 | - 'date_completed' => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null, |
|
| 229 | - 'number' => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null, |
|
| 230 | - 'key' => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null, |
|
| 231 | - 'status' => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null, |
|
| 232 | - 'post_type' => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null, |
|
| 233 | - 'user_ip' => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(), |
|
| 234 | - 'parent_id' => isset( $data['parent'] ) ? intval( $data['parent'] ) : null, |
|
| 235 | - 'mode' => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null, |
|
| 236 | - 'description' => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null, |
|
| 224 | + 'template' => isset($data['template']) ? wpinv_clean($data['template']) : null, |
|
| 225 | + 'email_cc' => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null, |
|
| 226 | + 'date_created' => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null, |
|
| 227 | + 'due_date' => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null, |
|
| 228 | + 'date_completed' => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null, |
|
| 229 | + 'number' => isset($data['number']) ? wpinv_clean($data['number']) : null, |
|
| 230 | + 'key' => isset($data['key']) ? wpinv_clean($data['key']) : null, |
|
| 231 | + 'status' => isset($data['status']) ? wpinv_clean($data['status']) : null, |
|
| 232 | + 'post_type' => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null, |
|
| 233 | + 'user_ip' => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(), |
|
| 234 | + 'parent_id' => isset($data['parent']) ? intval($data['parent']) : null, |
|
| 235 | + 'mode' => isset($data['mode']) ? wpinv_clean($data['mode']) : null, |
|
| 236 | + 'description' => isset($data['description']) ? wp_kses_post($data['description']) : null, |
|
| 237 | 237 | |
| 238 | 238 | // Payment info. |
| 239 | - 'disable_taxes' => ! empty( $data['disable_taxes'] ), |
|
| 240 | - 'currency' => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(), |
|
| 241 | - 'gateway' => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null, |
|
| 242 | - 'transaction_id' => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null, |
|
| 243 | - 'discount_code' => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null, |
|
| 244 | - 'payment_form' => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null, |
|
| 245 | - 'submission_id' => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null, |
|
| 246 | - 'subscription_id' => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null, |
|
| 247 | - 'is_viewed' => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null, |
|
| 248 | - 'fees' => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null, |
|
| 249 | - 'discounts' => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null, |
|
| 250 | - 'taxes' => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null, |
|
| 239 | + 'disable_taxes' => !empty($data['disable_taxes']), |
|
| 240 | + 'currency' => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(), |
|
| 241 | + 'gateway' => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null, |
|
| 242 | + 'transaction_id' => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null, |
|
| 243 | + 'discount_code' => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null, |
|
| 244 | + 'payment_form' => isset($data['payment_form']) ? intval($data['payment_form']) : null, |
|
| 245 | + 'submission_id' => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null, |
|
| 246 | + 'subscription_id' => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null, |
|
| 247 | + 'is_viewed' => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null, |
|
| 248 | + 'fees' => isset($data['fees']) ? wpinv_clean($data['fees']) : null, |
|
| 249 | + 'discounts' => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null, |
|
| 250 | + 'taxes' => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null, |
|
| 251 | 251 | |
| 252 | 252 | // Billing details. |
| 253 | 253 | 'user_id' => $data['user_id'], |
| 254 | - 'first_name' => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'], |
|
| 255 | - 'last_name' => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'], |
|
| 256 | - 'address' => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'], |
|
| 257 | - 'vat_number' => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'], |
|
| 258 | - 'company' => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'], |
|
| 259 | - 'zip' => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'], |
|
| 260 | - 'state' => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'], |
|
| 261 | - 'city' => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'], |
|
| 262 | - 'country' => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'], |
|
| 263 | - 'phone' => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'], |
|
| 264 | - 'address_confirmed' => ! empty( $data['address_confirmed'] ), |
|
| 254 | + 'first_name' => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'], |
|
| 255 | + 'last_name' => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'], |
|
| 256 | + 'address' => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'], |
|
| 257 | + 'vat_number' => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'], |
|
| 258 | + 'company' => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'], |
|
| 259 | + 'zip' => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'], |
|
| 260 | + 'state' => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'], |
|
| 261 | + 'city' => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'], |
|
| 262 | + 'country' => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'], |
|
| 263 | + 'phone' => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'], |
|
| 264 | + 'address_confirmed' => !empty($data['address_confirmed']), |
|
| 265 | 265 | |
| 266 | 266 | ) |
| 267 | 267 | ); |
| 268 | 268 | |
| 269 | 269 | // Backwards compatibililty. |
| 270 | - if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) { |
|
| 270 | + if (!empty($data['cart_details']) && is_array($data['cart_details'])) { |
|
| 271 | 271 | $data['items'] = array(); |
| 272 | 272 | |
| 273 | - foreach ( $data['cart_details'] as $_item ) { |
|
| 273 | + foreach ($data['cart_details'] as $_item) { |
|
| 274 | 274 | |
| 275 | 275 | // Ensure that we have an item id. |
| 276 | - if ( empty( $_item['id'] ) ) { |
|
| 276 | + if (empty($_item['id'])) { |
|
| 277 | 277 | continue; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | // Retrieve the item. |
| 281 | - $item = new GetPaid_Form_Item( $_item['id'] ); |
|
| 281 | + $item = new GetPaid_Form_Item($_item['id']); |
|
| 282 | 282 | |
| 283 | 283 | // Ensure that it is purchasable. |
| 284 | - if ( ! $item->can_purchase() ) { |
|
| 284 | + if (!$item->can_purchase()) { |
|
| 285 | 285 | continue; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Set quantity. |
| 289 | - if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) { |
|
| 290 | - $item->set_quantity( $_item['quantity'] ); |
|
| 289 | + if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) { |
|
| 290 | + $item->set_quantity($_item['quantity']); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | // Set price. |
| 294 | - if ( isset( $_item['item_price'] ) ) { |
|
| 295 | - $item->set_price( $_item['item_price'] ); |
|
| 294 | + if (isset($_item['item_price'])) { |
|
| 295 | + $item->set_price($_item['item_price']); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( isset( $_item['custom_price'] ) ) { |
|
| 299 | - $item->set_price( $_item['custom_price'] ); |
|
| 298 | + if (isset($_item['custom_price'])) { |
|
| 299 | + $item->set_price($_item['custom_price']); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // Set name. |
| 303 | - if ( ! empty( $_item['name'] ) ) { |
|
| 304 | - $item->set_name( $_item['name'] ); |
|
| 303 | + if (!empty($_item['name'])) { |
|
| 304 | + $item->set_name($_item['name']); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Set description. |
| 308 | - if ( isset( $_item['description'] ) ) { |
|
| 309 | - $item->set_custom_description( $_item['description'] ); |
|
| 308 | + if (isset($_item['description'])) { |
|
| 309 | + $item->set_custom_description($_item['description']); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // Set meta. |
| 313 | - if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) { |
|
| 313 | + if (isset($_item['meta']) && is_array($_item['meta'])) { |
|
| 314 | 314 | |
| 315 | - $item->set_item_meta( $_item['meta'] ); |
|
| 315 | + $item->set_item_meta($_item['meta']); |
|
| 316 | 316 | |
| 317 | - if ( isset( $_item['meta']['description'] ) ) { |
|
| 318 | - $item->set_custom_description( $_item['meta']['description'] ); |
|
| 317 | + if (isset($_item['meta']['description'])) { |
|
| 318 | + $item->set_custom_description($_item['meta']['description']); |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |
@@ -325,14 +325,14 @@ discard block |
||
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | // Add invoice items. |
| 328 | - if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
| 328 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
| 329 | 329 | |
| 330 | - $invoice->set_items( array() ); |
|
| 330 | + $invoice->set_items(array()); |
|
| 331 | 331 | |
| 332 | - foreach ( $data['items'] as $item ) { |
|
| 332 | + foreach ($data['items'] as $item) { |
|
| 333 | 333 | |
| 334 | - if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) { |
|
| 335 | - $invoice->add_item( $item ); |
|
| 334 | + if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) { |
|
| 335 | + $invoice->add_item($item); |
|
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | } |
@@ -341,30 +341,30 @@ discard block |
||
| 341 | 341 | $invoice->recalculate_total(); |
| 342 | 342 | $invoice->save(); |
| 343 | 343 | |
| 344 | - if ( ! $invoice->get_id() ) { |
|
| 345 | - return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0; |
|
| 344 | + if (!$invoice->get_id()) { |
|
| 345 | + return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0; |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | // Add private note. |
| 349 | - if ( ! empty( $data['private_note'] ) ) { |
|
| 350 | - $invoice->add_note( $data['private_note'] ); |
|
| 349 | + if (!empty($data['private_note'])) { |
|
| 350 | + $invoice->add_note($data['private_note']); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | // User notes. |
| 354 | - if ( ! empty( $data['user_note'] ) ) { |
|
| 355 | - $invoice->add_note( $data['user_note'], true ); |
|
| 354 | + if (!empty($data['user_note'])) { |
|
| 355 | + $invoice->add_note($data['user_note'], true); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | // Created via. |
| 359 | - if ( isset( $data['created_via'] ) ) { |
|
| 360 | - update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] ); |
|
| 359 | + if (isset($data['created_via'])) { |
|
| 360 | + update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // Backwards compatiblity. |
| 364 | - if ( $invoice->is_quote() ) { |
|
| 364 | + if ($invoice->is_quote()) { |
|
| 365 | 365 | |
| 366 | - if ( isset( $data['valid_until'] ) ) { |
|
| 367 | - update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] ); |
|
| 366 | + if (isset($data['valid_until'])) { |
|
| 367 | + update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']); |
|
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | |
@@ -378,20 +378,20 @@ discard block |
||
| 378 | 378 | * @param $bool $deprecated |
| 379 | 379 | * @return WPInv_Invoice|null |
| 380 | 380 | */ |
| 381 | -function wpinv_get_invoice( $invoice = 0, $deprecated = false ) { |
|
| 381 | +function wpinv_get_invoice($invoice = 0, $deprecated = false) { |
|
| 382 | 382 | |
| 383 | 383 | // If we are retrieving the invoice from the cart... |
| 384 | - if ( $deprecated && empty( $invoice ) ) { |
|
| 384 | + if ($deprecated && empty($invoice)) { |
|
| 385 | 385 | $invoice = (int) getpaid_get_current_invoice_id(); |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | // Retrieve the invoice. |
| 389 | - if ( ! is_a( $invoice, 'WPInv_Invoice' ) ) { |
|
| 390 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 389 | + if (!is_a($invoice, 'WPInv_Invoice')) { |
|
| 390 | + $invoice = new WPInv_Invoice($invoice); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | // Check if it exists. |
| 394 | - if ( $invoice->exists() ) { |
|
| 394 | + if ($invoice->exists()) { |
|
| 395 | 395 | return $invoice; |
| 396 | 396 | } |
| 397 | 397 | |
@@ -404,15 +404,15 @@ discard block |
||
| 404 | 404 | * @param array $args Args to search for. |
| 405 | 405 | * @return WPInv_Invoice[]|int[]|object |
| 406 | 406 | */ |
| 407 | -function wpinv_get_invoices( $args ) { |
|
| 407 | +function wpinv_get_invoices($args) { |
|
| 408 | 408 | |
| 409 | 409 | // Prepare args. |
| 410 | 410 | $args = wp_parse_args( |
| 411 | 411 | $args, |
| 412 | 412 | array( |
| 413 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 413 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
| 414 | 414 | 'type' => 'wpi_invoice', |
| 415 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 415 | + 'limit' => get_option('posts_per_page'), |
|
| 416 | 416 | 'return' => 'objects', |
| 417 | 417 | ) |
| 418 | 418 | ); |
@@ -430,24 +430,24 @@ discard block |
||
| 430 | 430 | 'post__in' => 'include', |
| 431 | 431 | ); |
| 432 | 432 | |
| 433 | - foreach ( $map_legacy as $to => $from ) { |
|
| 434 | - if ( isset( $args[ $from ] ) ) { |
|
| 435 | - $args[ $to ] = $args[ $from ]; |
|
| 436 | - unset( $args[ $from ] ); |
|
| 433 | + foreach ($map_legacy as $to => $from) { |
|
| 434 | + if (isset($args[$from])) { |
|
| 435 | + $args[$to] = $args[$from]; |
|
| 436 | + unset($args[$from]); |
|
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | // Backwards compatibility. |
| 441 | - if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) { |
|
| 441 | + if (!empty($args['email']) && empty($args['user'])) { |
|
| 442 | 442 | $args['user'] = $args['email']; |
| 443 | - unset( $args['email'] ); |
|
| 443 | + unset($args['email']); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | // Handle cases where the user is set as an email. |
| 447 | - if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) { |
|
| 448 | - $user = get_user_by( 'email', $args['user'] ); |
|
| 447 | + if (!empty($args['author']) && is_email($args['author'])) { |
|
| 448 | + $user = get_user_by('email', $args['user']); |
|
| 449 | 449 | |
| 450 | - if ( $user ) { |
|
| 450 | + if ($user) { |
|
| 451 | 451 | $args['author'] = $user->user_email; |
| 452 | 452 | } |
| 453 | 453 | } |
@@ -457,31 +457,31 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | // Show all posts. |
| 459 | 459 | $paginate = true; |
| 460 | - if ( isset( $args['paginate'] ) ) { |
|
| 460 | + if (isset($args['paginate'])) { |
|
| 461 | 461 | |
| 462 | 462 | $paginate = $args['paginate']; |
| 463 | - $args['no_found_rows'] = empty( $args['paginate'] ); |
|
| 464 | - unset( $args['paginate'] ); |
|
| 463 | + $args['no_found_rows'] = empty($args['paginate']); |
|
| 464 | + unset($args['paginate']); |
|
| 465 | 465 | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | // Whether to return objects or fields. |
| 469 | 469 | $return = $args['return']; |
| 470 | - unset( $args['return'] ); |
|
| 470 | + unset($args['return']); |
|
| 471 | 471 | |
| 472 | 472 | // Get invoices. |
| 473 | - $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) ); |
|
| 473 | + $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args)); |
|
| 474 | 474 | |
| 475 | 475 | // Prepare the results. |
| 476 | - if ( 'objects' === $return ) { |
|
| 477 | - $results = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
| 478 | - } elseif ( 'self' === $return ) { |
|
| 476 | + if ('objects' === $return) { |
|
| 477 | + $results = array_map('wpinv_get_invoice', $invoices->posts); |
|
| 478 | + } elseif ('self' === $return) { |
|
| 479 | 479 | return $invoices; |
| 480 | 480 | } else { |
| 481 | 481 | $results = $invoices->posts; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - if ( $paginate ) { |
|
| 484 | + if ($paginate) { |
|
| 485 | 485 | return (object) array( |
| 486 | 486 | 'invoices' => $results, |
| 487 | 487 | 'total' => $invoices->found_posts, |
@@ -499,8 +499,8 @@ discard block |
||
| 499 | 499 | * @param string $transaction_id The transaction id to check. |
| 500 | 500 | * @return int Invoice id on success or 0 on failure |
| 501 | 501 | */ |
| 502 | -function wpinv_get_id_by_transaction_id( $transaction_id ) { |
|
| 503 | - return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' ); |
|
| 502 | +function wpinv_get_id_by_transaction_id($transaction_id) { |
|
| 503 | + return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id'); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
@@ -509,8 +509,8 @@ discard block |
||
| 509 | 509 | * @param string $invoice_number The invoice number to check. |
| 510 | 510 | * @return int Invoice id on success or 0 on failure |
| 511 | 511 | */ |
| 512 | -function wpinv_get_id_by_invoice_number( $invoice_number ) { |
|
| 513 | - return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' ); |
|
| 512 | +function wpinv_get_id_by_invoice_number($invoice_number) { |
|
| 513 | + return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number'); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -519,8 +519,8 @@ discard block |
||
| 519 | 519 | * @param string $invoice_key The invoice key to check. |
| 520 | 520 | * @return int Invoice id on success or 0 on failure |
| 521 | 521 | */ |
| 522 | -function wpinv_get_invoice_id_by_key( $invoice_key ) { |
|
| 523 | - return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' ); |
|
| 522 | +function wpinv_get_invoice_id_by_key($invoice_key) { |
|
| 523 | + return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key'); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -530,19 +530,19 @@ discard block |
||
| 530 | 530 | * @param string $type Optionally filter by type i.e customer|system |
| 531 | 531 | * @return array|null |
| 532 | 532 | */ |
| 533 | -function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) { |
|
| 533 | +function wpinv_get_invoice_notes($invoice = 0, $type = '') { |
|
| 534 | 534 | |
| 535 | 535 | // Prepare the invoice. |
| 536 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 537 | - if ( empty( $invoice ) ) { |
|
| 536 | + $invoice = wpinv_get_invoice($invoice); |
|
| 537 | + if (empty($invoice)) { |
|
| 538 | 538 | return null; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | // Fetch notes. |
| 542 | - $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type ); |
|
| 542 | + $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type); |
|
| 543 | 543 | |
| 544 | 544 | // Filter the notes. |
| 545 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type ); |
|
| 545 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -550,10 +550,10 @@ discard block |
||
| 550 | 550 | * |
| 551 | 551 | * @param string $post_type |
| 552 | 552 | */ |
| 553 | -function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) { |
|
| 553 | +function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') { |
|
| 554 | 554 | |
| 555 | - $label = getpaid_get_post_type_label( $post_type, false ); |
|
| 556 | - $label = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label ); |
|
| 555 | + $label = getpaid_get_post_type_label($post_type, false); |
|
| 556 | + $label = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label); |
|
| 557 | 557 | $columns = array( |
| 558 | 558 | |
| 559 | 559 | 'invoice-number' => array( |
@@ -562,22 +562,22 @@ discard block |
||
| 562 | 562 | ), |
| 563 | 563 | |
| 564 | 564 | 'created-date' => array( |
| 565 | - 'title' => __( 'Created Date', 'invoicing' ), |
|
| 565 | + 'title' => __('Created Date', 'invoicing'), |
|
| 566 | 566 | 'class' => 'text-left', |
| 567 | 567 | ), |
| 568 | 568 | |
| 569 | 569 | 'payment-date' => array( |
| 570 | - 'title' => __( 'Payment Date', 'invoicing' ), |
|
| 570 | + 'title' => __('Payment Date', 'invoicing'), |
|
| 571 | 571 | 'class' => 'text-left', |
| 572 | 572 | ), |
| 573 | 573 | |
| 574 | 574 | 'invoice-status' => array( |
| 575 | - 'title' => __( 'Status', 'invoicing' ), |
|
| 575 | + 'title' => __('Status', 'invoicing'), |
|
| 576 | 576 | 'class' => 'text-center', |
| 577 | 577 | ), |
| 578 | 578 | |
| 579 | 579 | 'invoice-total' => array( |
| 580 | - 'title' => __( 'Total', 'invoicing' ), |
|
| 580 | + 'title' => __('Total', 'invoicing'), |
|
| 581 | 581 | 'class' => 'text-right', |
| 582 | 582 | ), |
| 583 | 583 | |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | |
| 589 | 589 | ); |
| 590 | 590 | |
| 591 | - return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type ); |
|
| 591 | + return apply_filters('wpinv_user_invoices_columns', $columns, $post_type); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -598,59 +598,59 @@ discard block |
||
| 598 | 598 | |
| 599 | 599 | // Find the invoice. |
| 600 | 600 | $invoice_id = getpaid_get_current_invoice_id(); |
| 601 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 601 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 602 | 602 | |
| 603 | 603 | // Abort if non was found. |
| 604 | - if ( empty( $invoice_id ) || $invoice->is_draft() ) { |
|
| 604 | + if (empty($invoice_id) || $invoice->is_draft()) { |
|
| 605 | 605 | |
| 606 | 606 | return aui()->alert( |
| 607 | 607 | array( |
| 608 | 608 | 'type' => 'warning', |
| 609 | - 'content' => __( 'We could not find your invoice', 'invoicing' ), |
|
| 609 | + 'content' => __('We could not find your invoice', 'invoicing'), |
|
| 610 | 610 | ) |
| 611 | 611 | ); |
| 612 | 612 | |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | // Can the user view this invoice? |
| 616 | - if ( ! wpinv_can_view_receipt( $invoice_id ) ) { |
|
| 616 | + if (!wpinv_can_view_receipt($invoice_id)) { |
|
| 617 | 617 | |
| 618 | 618 | return aui()->alert( |
| 619 | 619 | array( |
| 620 | 620 | 'type' => 'warning', |
| 621 | - 'content' => __( 'You are not allowed to view this receipt', 'invoicing' ), |
|
| 621 | + 'content' => __('You are not allowed to view this receipt', 'invoicing'), |
|
| 622 | 622 | ) |
| 623 | 623 | ); |
| 624 | 624 | |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | // Load the template. |
| 628 | - return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) ); |
|
| 628 | + return wpinv_get_template_html('invoice-receipt.php', compact('invoice')); |
|
| 629 | 629 | |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
| 633 | 633 | * Displays the invoice history. |
| 634 | 634 | */ |
| 635 | -function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) { |
|
| 635 | +function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') { |
|
| 636 | 636 | |
| 637 | 637 | // Ensure that we have a user id. |
| 638 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
| 638 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
| 639 | 639 | $user_id = get_current_user_id(); |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - $label = getpaid_get_post_type_label( $post_type ); |
|
| 643 | - $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label ); |
|
| 642 | + $label = getpaid_get_post_type_label($post_type); |
|
| 643 | + $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label); |
|
| 644 | 644 | |
| 645 | 645 | // View user id. |
| 646 | - if ( empty( $user_id ) ) { |
|
| 646 | + if (empty($user_id)) { |
|
| 647 | 647 | |
| 648 | 648 | return aui()->alert( |
| 649 | 649 | array( |
| 650 | 650 | 'type' => 'warning', |
| 651 | 651 | 'content' => sprintf( |
| 652 | - __( 'You must be logged in to view your %s.', 'invoicing' ), |
|
| 653 | - strtolower( $label ) |
|
| 652 | + __('You must be logged in to view your %s.', 'invoicing'), |
|
| 653 | + strtolower($label) |
|
| 654 | 654 | ), |
| 655 | 655 | ) |
| 656 | 656 | ); |
@@ -660,22 +660,22 @@ discard block |
||
| 660 | 660 | // Fetch invoices. |
| 661 | 661 | $invoices = wpinv_get_invoices( |
| 662 | 662 | array( |
| 663 | - 'page' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 663 | + 'page' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
| 664 | 664 | 'user' => $user_id, |
| 665 | 665 | 'paginate' => true, |
| 666 | 666 | 'type' => $post_type, |
| 667 | - 'status' => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ), |
|
| 667 | + 'status' => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)), |
|
| 668 | 668 | ) |
| 669 | 669 | ); |
| 670 | 670 | |
| 671 | - if ( empty( $invoices->total ) ) { |
|
| 671 | + if (empty($invoices->total)) { |
|
| 672 | 672 | |
| 673 | 673 | return aui()->alert( |
| 674 | 674 | array( |
| 675 | 675 | 'type' => 'info', |
| 676 | 676 | 'content' => sprintf( |
| 677 | - __( 'No %s found.', 'invoicing' ), |
|
| 678 | - strtolower( $label ) |
|
| 677 | + __('No %s found.', 'invoicing'), |
|
| 678 | + strtolower($label) |
|
| 679 | 679 | ), |
| 680 | 680 | ) |
| 681 | 681 | ); |
@@ -683,38 +683,38 @@ discard block |
||
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | // Load the template. |
| 686 | - return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) ); |
|
| 686 | + return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type')); |
|
| 687 | 687 | |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | /** |
| 691 | 691 | * Formats an invoice number given an invoice type. |
| 692 | 692 | */ |
| 693 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
| 693 | +function wpinv_format_invoice_number($number, $type = '') { |
|
| 694 | 694 | |
| 695 | 695 | // Allow other plugins to overide this. |
| 696 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
| 697 | - if ( null !== $check ) { |
|
| 696 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
| 697 | + if (null !== $check) { |
|
| 698 | 698 | return $check; |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | // Ensure that we have a numeric number. |
| 702 | - if ( ! is_numeric( $number ) ) { |
|
| 702 | + if (!is_numeric($number)) { |
|
| 703 | 703 | return $number; |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | // Format the number. |
| 707 | - $padd = absint( (int) wpinv_get_option( 'invoice_number_padd', 5 ) ); |
|
| 708 | - $prefix = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) ); |
|
| 709 | - $prefix = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) ); |
|
| 710 | - $postfix = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) ); |
|
| 711 | - $postfix = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) ); |
|
| 712 | - $formatted_number = zeroise( absint( $number ), $padd ); |
|
| 707 | + $padd = absint((int) wpinv_get_option('invoice_number_padd', 5)); |
|
| 708 | + $prefix = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-')); |
|
| 709 | + $prefix = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type)); |
|
| 710 | + $postfix = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix')); |
|
| 711 | + $postfix = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type)); |
|
| 712 | + $formatted_number = zeroise(absint($number), $padd); |
|
| 713 | 713 | |
| 714 | 714 | // Add the prefix and post fix. |
| 715 | 715 | $formatted_number = $prefix . $formatted_number . $postfix; |
| 716 | 716 | |
| 717 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
| 717 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -723,58 +723,58 @@ discard block |
||
| 723 | 723 | * @param string $type. |
| 724 | 724 | * @return int|null|bool |
| 725 | 725 | */ |
| 726 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
| 726 | +function wpinv_get_next_invoice_number($type = '') { |
|
| 727 | 727 | |
| 728 | 728 | // Allow plugins to overide this. |
| 729 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
| 730 | - if ( null !== $check ) { |
|
| 729 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
| 730 | + if (null !== $check) { |
|
| 731 | 731 | return $check; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | // Ensure sequential invoice numbers is active. |
| 735 | - if ( ! wpinv_sequential_number_active() ) { |
|
| 735 | + if (!wpinv_sequential_number_active()) { |
|
| 736 | 736 | return false; |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | // Retrieve the current number and the start number. |
| 740 | - $number = (int) get_option( 'wpinv_last_invoice_number', 0 ); |
|
| 741 | - $start = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) ); |
|
| 740 | + $number = (int) get_option('wpinv_last_invoice_number', 0); |
|
| 741 | + $start = absint((int) wpinv_get_option('invoice_sequence_start', 1)); |
|
| 742 | 742 | |
| 743 | 743 | // Ensure that we are starting at a positive integer. |
| 744 | - $start = max( $start, 1 ); |
|
| 744 | + $start = max($start, 1); |
|
| 745 | 745 | |
| 746 | 746 | // If this is the first invoice, use the start number. |
| 747 | - $number = max( $start, $number ); |
|
| 747 | + $number = max($start, $number); |
|
| 748 | 748 | |
| 749 | 749 | // Format the invoice number. |
| 750 | - $formatted_number = wpinv_format_invoice_number( $number, $type ); |
|
| 750 | + $formatted_number = wpinv_format_invoice_number($number, $type); |
|
| 751 | 751 | |
| 752 | 752 | // Ensure that this number is unique. |
| 753 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' ); |
|
| 753 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number'); |
|
| 754 | 754 | |
| 755 | 755 | // We found a match. Nice. |
| 756 | - if ( empty( $invoice_id ) ) { |
|
| 757 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
| 758 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
| 756 | + if (empty($invoice_id)) { |
|
| 757 | + update_option('wpinv_last_invoice_number', $number); |
|
| 758 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | - update_option( 'wpinv_last_invoice_number', $number + 1 ); |
|
| 762 | - return wpinv_get_next_invoice_number( $type ); |
|
| 761 | + update_option('wpinv_last_invoice_number', $number + 1); |
|
| 762 | + return wpinv_get_next_invoice_number($type); |
|
| 763 | 763 | |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | /** |
| 767 | 767 | * The prefix used for invoice paths. |
| 768 | 768 | */ |
| 769 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
| 770 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
| 769 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
| 770 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | -function wpinv_generate_post_name( $post_ID ) { |
|
| 774 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
| 775 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
| 773 | +function wpinv_generate_post_name($post_ID) { |
|
| 774 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
| 775 | + $post_name = sanitize_title($prefix . $post_ID); |
|
| 776 | 776 | |
| 777 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
| 777 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | /** |
@@ -782,8 +782,8 @@ discard block |
||
| 782 | 782 | * |
| 783 | 783 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object. |
| 784 | 784 | */ |
| 785 | -function wpinv_is_invoice_viewed( $invoice ) { |
|
| 786 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 785 | +function wpinv_is_invoice_viewed($invoice) { |
|
| 786 | + $invoice = new WPInv_Invoice($invoice); |
|
| 787 | 787 | return (bool) $invoice->get_is_viewed(); |
| 788 | 788 | } |
| 789 | 789 | |
@@ -792,17 +792,17 @@ discard block |
||
| 792 | 792 | * |
| 793 | 793 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object. |
| 794 | 794 | */ |
| 795 | -function getpaid_maybe_mark_invoice_as_viewed( $invoice ) { |
|
| 796 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 795 | +function getpaid_maybe_mark_invoice_as_viewed($invoice) { |
|
| 796 | + $invoice = new WPInv_Invoice($invoice); |
|
| 797 | 797 | |
| 798 | - if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) { |
|
| 799 | - $invoice->set_is_viewed( true ); |
|
| 798 | + if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) { |
|
| 799 | + $invoice->set_is_viewed(true); |
|
| 800 | 800 | $invoice->save(); |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | } |
| 804 | -add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' ); |
|
| 805 | -add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' ); |
|
| 804 | +add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed'); |
|
| 805 | +add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed'); |
|
| 806 | 806 | |
| 807 | 807 | /** |
| 808 | 808 | * Processes an invoice refund. |
@@ -811,26 +811,26 @@ discard block |
||
| 811 | 811 | * @param array $status_transition |
| 812 | 812 | * @todo: descrease customer/store earnings |
| 813 | 813 | */ |
| 814 | -function getpaid_maybe_process_refund( $invoice, $status_transition ) { |
|
| 814 | +function getpaid_maybe_process_refund($invoice, $status_transition) { |
|
| 815 | 815 | |
| 816 | - if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
| 816 | + if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
| 817 | 817 | return; |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | $discount_code = $invoice->get_discount_code(); |
| 821 | - if ( ! empty( $discount_code ) ) { |
|
| 822 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
| 821 | + if (!empty($discount_code)) { |
|
| 822 | + $discount = wpinv_get_discount_obj($discount_code); |
|
| 823 | 823 | |
| 824 | - if ( $discount->exists() ) { |
|
| 824 | + if ($discount->exists()) { |
|
| 825 | 825 | $discount->increase_usage( -1 ); |
| 826 | 826 | } |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | - do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() ); |
|
| 830 | - do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() ); |
|
| 831 | - do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() ); |
|
| 829 | + do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id()); |
|
| 830 | + do_action('wpinv_refund_invoice', $invoice, $invoice->get_id()); |
|
| 831 | + do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id()); |
|
| 832 | 832 | } |
| 833 | -add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 ); |
|
| 833 | +add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2); |
|
| 834 | 834 | |
| 835 | 835 | |
| 836 | 836 | /** |
@@ -838,47 +838,47 @@ discard block |
||
| 838 | 838 | * |
| 839 | 839 | * @param int $invoice_id |
| 840 | 840 | */ |
| 841 | -function getpaid_process_invoice_payment( $invoice_id ) { |
|
| 841 | +function getpaid_process_invoice_payment($invoice_id) { |
|
| 842 | 842 | |
| 843 | 843 | // Fetch the invoice. |
| 844 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 844 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 845 | 845 | |
| 846 | 846 | // We only want to do this once. |
| 847 | - if ( 1 == get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) { |
|
| 847 | + if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) { |
|
| 848 | 848 | return; |
| 849 | 849 | } |
| 850 | 850 | |
| 851 | - update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 ); |
|
| 851 | + update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1); |
|
| 852 | 852 | |
| 853 | 853 | // Fires when processing a payment. |
| 854 | - do_action( 'getpaid_process_payment', $invoice ); |
|
| 854 | + do_action('getpaid_process_payment', $invoice); |
|
| 855 | 855 | |
| 856 | 856 | // Fire an action for each invoice item. |
| 857 | - foreach ( $invoice->get_items() as $item ) { |
|
| 858 | - do_action( 'getpaid_process_item_payment', $item, $invoice ); |
|
| 857 | + foreach ($invoice->get_items() as $item) { |
|
| 858 | + do_action('getpaid_process_item_payment', $item, $invoice); |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | // Increase discount usage. |
| 862 | 862 | $discount_code = $invoice->get_discount_code(); |
| 863 | - if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) { |
|
| 864 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
| 863 | + if (!empty($discount_code) && !$invoice->is_renewal()) { |
|
| 864 | + $discount = wpinv_get_discount_obj($discount_code); |
|
| 865 | 865 | |
| 866 | - if ( $discount->exists() ) { |
|
| 866 | + if ($discount->exists()) { |
|
| 867 | 867 | $discount->increase_usage(); |
| 868 | 868 | } |
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | // Record reverse vat. |
| 872 | - if ( 'invoice' === $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
| 872 | + if ('invoice' === $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
| 873 | 873 | |
| 874 | 874 | $taxes = $invoice->get_total_tax(); |
| 875 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
| 876 | - $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true ); |
|
| 875 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
| 876 | + $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true); |
|
| 877 | 877 | } |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | } |
| 881 | -add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' ); |
|
| 881 | +add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment'); |
|
| 882 | 882 | |
| 883 | 883 | /** |
| 884 | 884 | * Returns an array of invoice item columns |
@@ -886,13 +886,13 @@ discard block |
||
| 886 | 886 | * @param int|WPInv_Invoice $invoice |
| 887 | 887 | * @return array |
| 888 | 888 | */ |
| 889 | -function getpaid_invoice_item_columns( $invoice ) { |
|
| 889 | +function getpaid_invoice_item_columns($invoice) { |
|
| 890 | 890 | |
| 891 | 891 | // Prepare the invoice. |
| 892 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 892 | + $invoice = new WPInv_Invoice($invoice); |
|
| 893 | 893 | |
| 894 | 894 | // Abort if there is no invoice. |
| 895 | - if ( 0 == $invoice->get_id() ) { |
|
| 895 | + if (0 == $invoice->get_id()) { |
|
| 896 | 896 | return array(); |
| 897 | 897 | } |
| 898 | 898 | |
@@ -900,52 +900,52 @@ discard block |
||
| 900 | 900 | $columns = apply_filters( |
| 901 | 901 | 'getpaid_invoice_item_columns', |
| 902 | 902 | array( |
| 903 | - 'name' => __( 'Item', 'invoicing' ), |
|
| 904 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 905 | - 'tax_rate' => __( 'Tax Rate', 'invoicing' ), |
|
| 906 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
| 907 | - 'subtotal' => __( 'Item Subtotal', 'invoicing' ), |
|
| 903 | + 'name' => __('Item', 'invoicing'), |
|
| 904 | + 'price' => __('Price', 'invoicing'), |
|
| 905 | + 'tax_rate' => __('Tax Rate', 'invoicing'), |
|
| 906 | + 'quantity' => __('Quantity', 'invoicing'), |
|
| 907 | + 'subtotal' => __('Item Subtotal', 'invoicing'), |
|
| 908 | 908 | ), |
| 909 | 909 | $invoice |
| 910 | 910 | ); |
| 911 | 911 | |
| 912 | 912 | // Quantities. |
| 913 | - if ( isset( $columns['quantity'] ) ) { |
|
| 913 | + if (isset($columns['quantity'])) { |
|
| 914 | 914 | |
| 915 | - if ( 'hours' == $invoice->get_template() ) { |
|
| 916 | - $columns['quantity'] = __( 'Hours', 'invoicing' ); |
|
| 915 | + if ('hours' == $invoice->get_template()) { |
|
| 916 | + $columns['quantity'] = __('Hours', 'invoicing'); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | - if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) { |
|
| 920 | - unset( $columns['quantity'] ); |
|
| 919 | + if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) { |
|
| 920 | + unset($columns['quantity']); |
|
| 921 | 921 | } |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | // Price. |
| 925 | - if ( isset( $columns['price'] ) ) { |
|
| 925 | + if (isset($columns['price'])) { |
|
| 926 | 926 | |
| 927 | - if ( 'amount' == $invoice->get_template() ) { |
|
| 928 | - $columns['price'] = __( 'Amount', 'invoicing' ); |
|
| 927 | + if ('amount' == $invoice->get_template()) { |
|
| 928 | + $columns['price'] = __('Amount', 'invoicing'); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | - if ( 'hours' == $invoice->get_template() ) { |
|
| 932 | - $columns['price'] = __( 'Rate', 'invoicing' ); |
|
| 931 | + if ('hours' == $invoice->get_template()) { |
|
| 932 | + $columns['price'] = __('Rate', 'invoicing'); |
|
| 933 | 933 | } |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | // Sub total. |
| 937 | - if ( isset( $columns['subtotal'] ) ) { |
|
| 937 | + if (isset($columns['subtotal'])) { |
|
| 938 | 938 | |
| 939 | - if ( 'amount' == $invoice->get_template() ) { |
|
| 940 | - unset( $columns['subtotal'] ); |
|
| 939 | + if ('amount' == $invoice->get_template()) { |
|
| 940 | + unset($columns['subtotal']); |
|
| 941 | 941 | } |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | // Tax rates. |
| 945 | - if ( isset( $columns['tax_rate'] ) ) { |
|
| 945 | + if (isset($columns['tax_rate'])) { |
|
| 946 | 946 | |
| 947 | - if ( 0 == $invoice->get_total_tax() ) { |
|
| 948 | - unset( $columns['tax_rate'] ); |
|
| 947 | + if (0 == $invoice->get_total_tax()) { |
|
| 948 | + unset($columns['tax_rate']); |
|
| 949 | 949 | } |
| 950 | 950 | } |
| 951 | 951 | |
@@ -958,53 +958,53 @@ discard block |
||
| 958 | 958 | * @param int|WPInv_Invoice $invoice |
| 959 | 959 | * @return array |
| 960 | 960 | */ |
| 961 | -function getpaid_invoice_totals_rows( $invoice ) { |
|
| 961 | +function getpaid_invoice_totals_rows($invoice) { |
|
| 962 | 962 | |
| 963 | 963 | // Prepare the invoice. |
| 964 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 964 | + $invoice = new WPInv_Invoice($invoice); |
|
| 965 | 965 | |
| 966 | 966 | // Abort if there is no invoice. |
| 967 | - if ( 0 == $invoice->get_id() ) { |
|
| 967 | + if (0 == $invoice->get_id()) { |
|
| 968 | 968 | return array(); |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | $totals = apply_filters( |
| 972 | 972 | 'getpaid_invoice_totals_rows', |
| 973 | 973 | array( |
| 974 | - 'subtotal' => __( 'Subtotal', 'invoicing' ), |
|
| 975 | - 'shipping' => __( 'Shipping', 'invoicing' ), |
|
| 976 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 977 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 978 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
| 979 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 974 | + 'subtotal' => __('Subtotal', 'invoicing'), |
|
| 975 | + 'shipping' => __('Shipping', 'invoicing'), |
|
| 976 | + 'tax' => __('Tax', 'invoicing'), |
|
| 977 | + 'fee' => __('Fee', 'invoicing'), |
|
| 978 | + 'discount' => __('Discount', 'invoicing'), |
|
| 979 | + 'total' => __('Total', 'invoicing'), |
|
| 980 | 980 | ), |
| 981 | 981 | $invoice |
| 982 | 982 | ); |
| 983 | 983 | |
| 984 | - if ( ! $invoice->has_shipping() ) { |
|
| 985 | - unset( $totals['shipping'] ); |
|
| 984 | + if (!$invoice->has_shipping()) { |
|
| 985 | + unset($totals['shipping']); |
|
| 986 | 986 | } |
| 987 | 987 | |
| 988 | - if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) { |
|
| 989 | - unset( $totals['tax'] ); |
|
| 988 | + if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) { |
|
| 989 | + unset($totals['tax']); |
|
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | // If we have taxes, display individual taxes. |
| 993 | - if ( isset( $totals['tax'] ) && wpinv_display_individual_tax_rates() ) { |
|
| 993 | + if (isset($totals['tax']) && wpinv_display_individual_tax_rates()) { |
|
| 994 | 994 | |
| 995 | 995 | $new_totals = array(); |
| 996 | - foreach ( $totals as $key => $label ) { |
|
| 996 | + foreach ($totals as $key => $label) { |
|
| 997 | 997 | |
| 998 | - if ( 'tax' !== $key ) { |
|
| 999 | - $new_totals[ $key ] = $label; |
|
| 998 | + if ('tax' !== $key) { |
|
| 999 | + $new_totals[$key] = $label; |
|
| 1000 | 1000 | continue; |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - $taxes = array_keys( $invoice->get_taxes() ); |
|
| 1004 | - if ( ! empty( $taxes ) ) { |
|
| 1003 | + $taxes = array_keys($invoice->get_taxes()); |
|
| 1004 | + if (!empty($taxes)) { |
|
| 1005 | 1005 | |
| 1006 | - foreach ( $taxes as $tax ) { |
|
| 1007 | - $new_totals[ 'tax__' . $tax ] = $tax; |
|
| 1006 | + foreach ($taxes as $tax) { |
|
| 1007 | + $new_totals['tax__' . $tax] = $tax; |
|
| 1008 | 1008 | } |
| 1009 | 1009 | } |
| 1010 | 1010 | } |
@@ -1012,12 +1012,12 @@ discard block |
||
| 1012 | 1012 | $totals = $new_totals; |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | - if ( 0 == $invoice->get_total_fees() && isset( $totals['fee'] ) ) { |
|
| 1016 | - unset( $totals['fee'] ); |
|
| 1015 | + if (0 == $invoice->get_total_fees() && isset($totals['fee'])) { |
|
| 1016 | + unset($totals['fee']); |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | - if ( 0 == $invoice->get_total_discount() && isset( $totals['discount'] ) ) { |
|
| 1020 | - unset( $totals['discount'] ); |
|
| 1019 | + if (0 == $invoice->get_total_discount() && isset($totals['discount'])) { |
|
| 1020 | + unset($totals['discount']); |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | return $totals; |
@@ -1028,47 +1028,47 @@ discard block |
||
| 1028 | 1028 | * |
| 1029 | 1029 | * @param WPInv_Invoice $invoice |
| 1030 | 1030 | */ |
| 1031 | -function getpaid_new_invoice( $invoice ) { |
|
| 1031 | +function getpaid_new_invoice($invoice) { |
|
| 1032 | 1032 | |
| 1033 | - if ( ! $invoice->get_status() ) { |
|
| 1033 | + if (!$invoice->get_status()) { |
|
| 1034 | 1034 | return; |
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | 1037 | // Add an invoice created note. |
| 1038 | 1038 | $invoice->add_note( |
| 1039 | 1039 | sprintf( |
| 1040 | - __( '%1$s created with the status "%2$s".', 'invoicing' ), |
|
| 1041 | - ucfirst( $invoice->get_invoice_quote_type() ), |
|
| 1042 | - wpinv_status_nicename( $invoice->get_status(), $invoice ) |
|
| 1040 | + __('%1$s created with the status "%2$s".', 'invoicing'), |
|
| 1041 | + ucfirst($invoice->get_invoice_quote_type()), |
|
| 1042 | + wpinv_status_nicename($invoice->get_status(), $invoice) |
|
| 1043 | 1043 | ) |
| 1044 | 1044 | ); |
| 1045 | 1045 | |
| 1046 | 1046 | } |
| 1047 | -add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' ); |
|
| 1047 | +add_action('getpaid_new_invoice', 'getpaid_new_invoice'); |
|
| 1048 | 1048 | |
| 1049 | 1049 | /** |
| 1050 | 1050 | * This function updates invoice caches. |
| 1051 | 1051 | * |
| 1052 | 1052 | * @param WPInv_Invoice $invoice |
| 1053 | 1053 | */ |
| 1054 | -function getpaid_update_invoice_caches( $invoice ) { |
|
| 1054 | +function getpaid_update_invoice_caches($invoice) { |
|
| 1055 | 1055 | |
| 1056 | 1056 | // Cache invoice number. |
| 1057 | - wp_cache_set( $invoice->get_number(), $invoice->get_id(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 1057 | + wp_cache_set($invoice->get_number(), $invoice->get_id(), 'getpaid_invoice_numbers_to_invoice_ids'); |
|
| 1058 | 1058 | |
| 1059 | 1059 | // Cache invoice key. |
| 1060 | - wp_cache_set( $invoice->get_key(), $invoice->get_id(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 1060 | + wp_cache_set($invoice->get_key(), $invoice->get_id(), 'getpaid_invoice_keys_to_invoice_ids'); |
|
| 1061 | 1061 | |
| 1062 | 1062 | // (Maybe) cache transaction id. |
| 1063 | 1063 | $transaction_id = $invoice->get_transaction_id(); |
| 1064 | 1064 | |
| 1065 | - if ( ! empty( $transaction_id ) ) { |
|
| 1066 | - wp_cache_set( $transaction_id, $invoice->get_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 1065 | + if (!empty($transaction_id)) { |
|
| 1066 | + wp_cache_set($transaction_id, $invoice->get_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids'); |
|
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | 1069 | } |
| 1070 | -add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 ); |
|
| 1071 | -add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 ); |
|
| 1070 | +add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5); |
|
| 1071 | +add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5); |
|
| 1072 | 1072 | |
| 1073 | 1073 | /** |
| 1074 | 1074 | * Duplicates an invoice. |
@@ -1078,7 +1078,7 @@ discard block |
||
| 1078 | 1078 | * @param WPInv_Invoice $old_invoice The invoice to duplicate |
| 1079 | 1079 | * @return WPInv_Invoice The new invoice. |
| 1080 | 1080 | */ |
| 1081 | -function getpaid_duplicate_invoice( $old_invoice ) { |
|
| 1081 | +function getpaid_duplicate_invoice($old_invoice) { |
|
| 1082 | 1082 | |
| 1083 | 1083 | // Create the new invoice. |
| 1084 | 1084 | $invoice = new WPInv_Invoice(); |
@@ -1138,138 +1138,138 @@ discard block |
||
| 1138 | 1138 | * @param WPInv_Invoice $invoice |
| 1139 | 1139 | * @return array |
| 1140 | 1140 | */ |
| 1141 | -function getpaid_get_invoice_meta( $invoice ) { |
|
| 1141 | +function getpaid_get_invoice_meta($invoice) { |
|
| 1142 | 1142 | |
| 1143 | 1143 | // Load the invoice meta. |
| 1144 | 1144 | $meta = array( |
| 1145 | 1145 | |
| 1146 | 1146 | 'number' => array( |
| 1147 | 1147 | 'label' => sprintf( |
| 1148 | - __( '%s Number', 'invoicing' ), |
|
| 1149 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 1148 | + __('%s Number', 'invoicing'), |
|
| 1149 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 1150 | 1150 | ), |
| 1151 | - 'value' => sanitize_text_field( $invoice->get_number() ), |
|
| 1151 | + 'value' => sanitize_text_field($invoice->get_number()), |
|
| 1152 | 1152 | ), |
| 1153 | 1153 | |
| 1154 | 1154 | 'status' => array( |
| 1155 | 1155 | 'label' => sprintf( |
| 1156 | - __( '%s Status', 'invoicing' ), |
|
| 1157 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 1156 | + __('%s Status', 'invoicing'), |
|
| 1157 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 1158 | 1158 | ), |
| 1159 | 1159 | 'value' => $invoice->get_status_label_html(), |
| 1160 | 1160 | ), |
| 1161 | 1161 | |
| 1162 | 1162 | 'date' => array( |
| 1163 | 1163 | 'label' => sprintf( |
| 1164 | - __( '%s Date', 'invoicing' ), |
|
| 1165 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 1164 | + __('%s Date', 'invoicing'), |
|
| 1165 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 1166 | 1166 | ), |
| 1167 | - 'value' => getpaid_format_date( $invoice->get_created_date() ), |
|
| 1167 | + 'value' => getpaid_format_date($invoice->get_created_date()), |
|
| 1168 | 1168 | ), |
| 1169 | 1169 | |
| 1170 | 1170 | 'date_paid' => array( |
| 1171 | - 'label' => __( 'Paid On', 'invoicing' ), |
|
| 1172 | - 'value' => getpaid_format_date( $invoice->get_completed_date() ), |
|
| 1171 | + 'label' => __('Paid On', 'invoicing'), |
|
| 1172 | + 'value' => getpaid_format_date($invoice->get_completed_date()), |
|
| 1173 | 1173 | ), |
| 1174 | 1174 | |
| 1175 | 1175 | 'gateway' => array( |
| 1176 | - 'label' => __( 'Payment Method', 'invoicing' ), |
|
| 1177 | - 'value' => sanitize_text_field( $invoice->get_gateway_title() ), |
|
| 1176 | + 'label' => __('Payment Method', 'invoicing'), |
|
| 1177 | + 'value' => sanitize_text_field($invoice->get_gateway_title()), |
|
| 1178 | 1178 | ), |
| 1179 | 1179 | |
| 1180 | 1180 | 'transaction_id' => array( |
| 1181 | - 'label' => __( 'Transaction ID', 'invoicing' ), |
|
| 1182 | - 'value' => sanitize_text_field( $invoice->get_transaction_id() ), |
|
| 1181 | + 'label' => __('Transaction ID', 'invoicing'), |
|
| 1182 | + 'value' => sanitize_text_field($invoice->get_transaction_id()), |
|
| 1183 | 1183 | ), |
| 1184 | 1184 | |
| 1185 | 1185 | 'due_date' => array( |
| 1186 | - 'label' => __( 'Due Date', 'invoicing' ), |
|
| 1187 | - 'value' => getpaid_format_date( $invoice->get_due_date() ), |
|
| 1186 | + 'label' => __('Due Date', 'invoicing'), |
|
| 1187 | + 'value' => getpaid_format_date($invoice->get_due_date()), |
|
| 1188 | 1188 | ), |
| 1189 | 1189 | |
| 1190 | 1190 | 'vat_number' => array( |
| 1191 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 1192 | - 'value' => sanitize_text_field( $invoice->get_vat_number() ), |
|
| 1191 | + 'label' => __('VAT Number', 'invoicing'), |
|
| 1192 | + 'value' => sanitize_text_field($invoice->get_vat_number()), |
|
| 1193 | 1193 | ), |
| 1194 | 1194 | |
| 1195 | 1195 | ); |
| 1196 | 1196 | |
| 1197 | - $additional_meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true ); |
|
| 1197 | + $additional_meta = get_post_meta($invoice->get_id(), 'additional_meta_data', true); |
|
| 1198 | 1198 | |
| 1199 | - if ( ! empty( $additional_meta ) ) { |
|
| 1199 | + if (!empty($additional_meta)) { |
|
| 1200 | 1200 | |
| 1201 | - foreach ( $additional_meta as $label => $value ) { |
|
| 1202 | - $meta[ sanitize_key( $label ) ] = array( |
|
| 1203 | - 'label' => esc_html( $label ), |
|
| 1204 | - 'value' => esc_html( $value ), |
|
| 1201 | + foreach ($additional_meta as $label => $value) { |
|
| 1202 | + $meta[sanitize_key($label)] = array( |
|
| 1203 | + 'label' => esc_html($label), |
|
| 1204 | + 'value' => esc_html($value), |
|
| 1205 | 1205 | ); |
| 1206 | 1206 | } |
| 1207 | 1207 | } |
| 1208 | 1208 | // If it is not paid, remove the date of payment. |
| 1209 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 1210 | - unset( $meta['date_paid'] ); |
|
| 1211 | - unset( $meta['transaction_id'] ); |
|
| 1209 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
| 1210 | + unset($meta['date_paid']); |
|
| 1211 | + unset($meta['transaction_id']); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | - if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) { |
|
| 1215 | - unset( $meta['gateway'] ); |
|
| 1214 | + if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) { |
|
| 1215 | + unset($meta['gateway']); |
|
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | 1218 | // Only display the due date if due dates are enabled. |
| 1219 | - if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) { |
|
| 1220 | - unset( $meta['due_date'] ); |
|
| 1219 | + if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) { |
|
| 1220 | + unset($meta['due_date']); |
|
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | 1223 | // Only display the vat number if taxes are enabled. |
| 1224 | - if ( ! wpinv_use_taxes() ) { |
|
| 1225 | - unset( $meta['vat_number'] ); |
|
| 1224 | + if (!wpinv_use_taxes()) { |
|
| 1225 | + unset($meta['vat_number']); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | // Link to the parent invoice. |
| 1229 | - if ( $invoice->get_parent_id() > 0 ) { |
|
| 1229 | + if ($invoice->get_parent_id() > 0) { |
|
| 1230 | 1230 | |
| 1231 | 1231 | $meta['parent'] = array( |
| 1232 | 1232 | |
| 1233 | 1233 | 'label' => sprintf( |
| 1234 | - __( 'Parent %s', 'invoicing' ), |
|
| 1235 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 1234 | + __('Parent %s', 'invoicing'), |
|
| 1235 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 1236 | 1236 | ), |
| 1237 | 1237 | |
| 1238 | - 'value' => wpinv_invoice_link( $invoice->get_parent_id() ), |
|
| 1238 | + 'value' => wpinv_invoice_link($invoice->get_parent_id()), |
|
| 1239 | 1239 | |
| 1240 | 1240 | ); |
| 1241 | 1241 | |
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | - if ( $invoice->is_recurring() ) { |
|
| 1244 | + if ($invoice->is_recurring()) { |
|
| 1245 | 1245 | |
| 1246 | - $subscription = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 1247 | - if ( ! empty( $subscription ) && ! is_array( $subscription ) && $subscription->exists() ) { |
|
| 1246 | + $subscription = getpaid_get_invoice_subscriptions($invoice); |
|
| 1247 | + if (!empty($subscription) && !is_array($subscription) && $subscription->exists()) { |
|
| 1248 | 1248 | |
| 1249 | 1249 | // Display the renewal date. |
| 1250 | - if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) { |
|
| 1250 | + if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) { |
|
| 1251 | 1251 | |
| 1252 | 1252 | $meta['renewal_date'] = array( |
| 1253 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
| 1254 | - 'value' => getpaid_format_date( $subscription->get_expiration() ) . |
|
| 1253 | + 'label' => __('Renews On', 'invoicing'), |
|
| 1254 | + 'value' => getpaid_format_date($subscription->get_expiration()) . |
|
| 1255 | 1255 | sprintf( |
| 1256 | 1256 | ' <a class="small" href="%s">%s<a>', |
| 1257 | 1257 | $subscription->get_view_url(), |
| 1258 | - __( '(View Subscription)', 'invoicing' ) |
|
| 1258 | + __('(View Subscription)', 'invoicing') |
|
| 1259 | 1259 | ), |
| 1260 | 1260 | ); |
| 1261 | 1261 | |
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | - if ( $invoice->is_parent() ) { |
|
| 1264 | + if ($invoice->is_parent()) { |
|
| 1265 | 1265 | |
| 1266 | - $recurring_item = $invoice->get_recurring( true ); |
|
| 1266 | + $recurring_item = $invoice->get_recurring(true); |
|
| 1267 | 1267 | |
| 1268 | 1268 | // Display the recurring amount. |
| 1269 | 1269 | $meta['recurring_total'] = array( |
| 1270 | 1270 | |
| 1271 | - 'label' => __( 'Recurring Amount', 'invoicing' ), |
|
| 1272 | - 'value' => getpaid_item_recurring_price_help_text( $recurring_item ), |
|
| 1271 | + 'label' => __('Recurring Amount', 'invoicing'), |
|
| 1272 | + 'value' => getpaid_item_recurring_price_help_text($recurring_item), |
|
| 1273 | 1273 | |
| 1274 | 1274 | ); |
| 1275 | 1275 | |
@@ -1280,13 +1280,13 @@ discard block |
||
| 1280 | 1280 | // Add the invoice total to the meta. |
| 1281 | 1281 | $meta['invoice_total'] = array( |
| 1282 | 1282 | |
| 1283 | - 'label' => __( 'Total Amount', 'invoicing' ), |
|
| 1284 | - 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
| 1283 | + 'label' => __('Total Amount', 'invoicing'), |
|
| 1284 | + 'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
| 1285 | 1285 | |
| 1286 | 1286 | ); |
| 1287 | 1287 | |
| 1288 | 1288 | // Provide a way for third party plugins to filter the meta. |
| 1289 | - $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice ); |
|
| 1289 | + $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice); |
|
| 1290 | 1290 | |
| 1291 | 1291 | return $meta; |
| 1292 | 1292 | |
@@ -1325,12 +1325,12 @@ discard block |
||
| 1325 | 1325 | * @param GetPaid_Form_Item $item |
| 1326 | 1326 | * @return float |
| 1327 | 1327 | */ |
| 1328 | -function getpaid_get_invoice_tax_rate( $invoice, $item ) { |
|
| 1328 | +function getpaid_get_invoice_tax_rate($invoice, $item) { |
|
| 1329 | 1329 | |
| 1330 | - $rates = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() ); |
|
| 1331 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 1332 | - $rates = wp_list_pluck( $rates, 'rate' ); |
|
| 1330 | + $rates = getpaid_get_item_tax_rates($item, $invoice->get_country(), $invoice->get_state()); |
|
| 1331 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
| 1332 | + $rates = wp_list_pluck($rates, 'rate'); |
|
| 1333 | 1333 | |
| 1334 | - return array_sum( $rates ); |
|
| 1334 | + return array_sum($rates); |
|
| 1335 | 1335 | |
| 1336 | 1336 | } |
@@ -14,620 +14,620 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array An array of payment gateways. |
|
| 40 | - */ |
|
| 41 | - public $gateways; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Class constructor. |
|
| 45 | - */ |
|
| 46 | - public function __construct() { |
|
| 47 | - $this->define_constants(); |
|
| 48 | - $this->includes(); |
|
| 49 | - $this->init_hooks(); |
|
| 50 | - $this->set_properties(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Sets a custom data property. |
|
| 55 | - * |
|
| 56 | - * @param string $prop The prop to set. |
|
| 57 | - * @param mixed $value The value to retrieve. |
|
| 58 | - */ |
|
| 59 | - public function set( $prop, $value ) { |
|
| 60 | - $this->data[ $prop ] = $value; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets a custom data property. |
|
| 65 | - * |
|
| 66 | - * @param string $prop The prop to set. |
|
| 67 | - * @return mixed The value. |
|
| 68 | - */ |
|
| 69 | - public function get( $prop ) { |
|
| 70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | - return $this->data[ $prop ]; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Define class properties. |
|
| 79 | - */ |
|
| 80 | - public function set_properties() { |
|
| 81 | - // Sessions. |
|
| 82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 84 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 85 | - |
|
| 86 | - // Init other objects. |
|
| 87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | - $this->set( 'api', new WPInv_API() ); |
|
| 89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 98 | - $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Define plugin constants. |
|
| 103 | - */ |
|
| 104 | - public function define_constants() { |
|
| 105 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 106 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 107 | - $this->version = WPINV_VERSION; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Hook into actions and filters. |
|
| 112 | - * |
|
| 113 | - * @since 1.0.19 |
|
| 114 | - */ |
|
| 115 | - protected function init_hooks() { |
|
| 116 | - /* Internationalize the text strings used. */ |
|
| 117 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 118 | - |
|
| 119 | - // Init the plugin after WordPress inits. |
|
| 120 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 121 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 122 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 123 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 125 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 126 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 127 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 128 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 129 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 130 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 131 | - |
|
| 132 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 133 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 134 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 135 | - |
|
| 136 | - // Fires after registering actions. |
|
| 137 | - do_action( 'wpinv_actions', $this ); |
|
| 138 | - do_action( 'getpaid_actions', $this ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public function plugins_loaded() { |
|
| 142 | - /* Internationalize the text strings used. */ |
|
| 143 | - $this->load_textdomain(); |
|
| 144 | - |
|
| 145 | - do_action( 'wpinv_loaded' ); |
|
| 146 | - |
|
| 147 | - // Fix oxygen page builder conflict |
|
| 148 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 149 | - wpinv_oxygen_fix_conflict(); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Load Localisation files. |
|
| 155 | - * |
|
| 156 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 157 | - * |
|
| 158 | - * Locales found in: |
|
| 159 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 160 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 161 | - * |
|
| 162 | - * @since 1.0.0 |
|
| 163 | - */ |
|
| 164 | - public function load_textdomain() { |
|
| 165 | - // Determines the current locale. |
|
| 166 | - if ( function_exists( 'determine_locale' ) ) { |
|
| 167 | - $locale = determine_locale(); |
|
| 168 | - } elseif ( function_exists( 'get_user_locale' ) ) { |
|
| 169 | - $locale = get_user_locale(); |
|
| 170 | - } else { |
|
| 171 | - $locale = get_locale(); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Filter the locale to use for translations. |
|
| 176 | - */ |
|
| 177 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 178 | - |
|
| 179 | - unload_textdomain( 'invoicing', true ); |
|
| 180 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 181 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Include required core files used in admin and on the frontend. |
|
| 186 | - */ |
|
| 187 | - public function includes() { |
|
| 188 | - // Start with the settings. |
|
| 189 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 190 | - |
|
| 191 | - // Packages/libraries. |
|
| 192 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 193 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 194 | - |
|
| 195 | - // Load functions. |
|
| 196 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 197 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 198 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 203 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 204 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 205 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 206 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 207 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 208 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 209 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 210 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 211 | - |
|
| 212 | - // Register autoloader. |
|
| 213 | - try { |
|
| 214 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 215 | - } catch ( Exception $e ) { |
|
| 216 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 221 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 222 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 224 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 225 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 226 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 227 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 228 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 229 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 230 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 231 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 232 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 234 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 235 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 236 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 237 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 238 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 239 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 241 | - |
|
| 242 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 243 | - GetPaid_Post_Types_Admin::init(); |
|
| 244 | - |
|
| 245 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 246 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 247 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 248 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 249 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 250 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 251 | - // load the user class only on the users.php page |
|
| 252 | - global $pagenow; |
|
| 253 | - if ( $pagenow == 'users.php' ) { |
|
| 254 | - new WPInv_Admin_Users(); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // Register cli commands |
|
| 259 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 260 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 261 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Class autoloader |
|
| 267 | - * |
|
| 268 | - * @param string $class_name The name of the class to load. |
|
| 269 | - * @access public |
|
| 270 | - * @since 1.0.19 |
|
| 271 | - * @return void |
|
| 272 | - */ |
|
| 273 | - public function autoload( $class_name ) { |
|
| 274 | - // Normalize the class name... |
|
| 275 | - $class_name = strtolower( $class_name ); |
|
| 276 | - |
|
| 277 | - // ... and make sure it is our class. |
|
| 278 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 279 | - return; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // Next, prepare the file name from the class. |
|
| 283 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 284 | - |
|
| 285 | - // Base path of the classes. |
|
| 286 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 287 | - |
|
| 288 | - // And an array of possible locations in order of importance. |
|
| 289 | - $locations = array( |
|
| 290 | - "$plugin_path/includes", |
|
| 291 | - "$plugin_path/includes/data-stores", |
|
| 292 | - "$plugin_path/includes/gateways", |
|
| 293 | - "$plugin_path/includes/payments", |
|
| 294 | - "$plugin_path/includes/geolocation", |
|
| 295 | - "$plugin_path/includes/reports", |
|
| 296 | - "$plugin_path/includes/api", |
|
| 297 | - "$plugin_path/includes/admin", |
|
| 298 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 299 | - ); |
|
| 300 | - |
|
| 301 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 302 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 303 | - include trailingslashit( $location ) . $file_name; |
|
| 304 | - break; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Inits hooks etc. |
|
| 311 | - */ |
|
| 312 | - public function init() { |
|
| 313 | - // Fires before getpaid inits. |
|
| 314 | - do_action( 'before_getpaid_init', $this ); |
|
| 315 | - |
|
| 316 | - // Maybe upgrade. |
|
| 317 | - $this->maybe_upgrade_database(); |
|
| 318 | - |
|
| 319 | - // Load default gateways. |
|
| 320 | - $gateways = apply_filters( |
|
| 321 | - 'getpaid_default_gateways', |
|
| 322 | - array( |
|
| 323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 328 | - ) |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - foreach ( $gateways as $id => $class ) { |
|
| 332 | - $this->gateways[ $id ] = new $class(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 336 | - GetPaid_Installer::rename_gateways_label(); |
|
| 337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - // Fires after getpaid inits. |
|
| 341 | - do_action( 'getpaid_init', $this ); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Checks if this is an IPN request and processes it. |
|
| 346 | - */ |
|
| 347 | - public function maybe_process_ipn() { |
|
| 348 | - // Ensure that this is an IPN request. |
|
| 349 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 354 | - |
|
| 355 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 356 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 357 | - exit; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - public function enqueue_scripts() { |
|
| 361 | - // Fires before adding scripts. |
|
| 362 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 363 | - |
|
| 364 | - $localize = array(); |
|
| 365 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 366 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
| 367 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
| 368 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 369 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 370 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 371 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 372 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 373 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 374 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 375 | - |
|
| 376 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 377 | - |
|
| 378 | - // reCaptcha. |
|
| 379 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 380 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
| 384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - public function wpinv_actions() { |
|
| 388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Fires an action after verifying that a user can fire them. |
|
| 399 | - * |
|
| 400 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 401 | - * current user owns the invoice/subscription. |
|
| 402 | - */ |
|
| 403 | - public function maybe_do_authenticated_action() { |
|
| 404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | - $data = wp_unslash( $_REQUEST ); |
|
| 407 | - |
|
| 408 | - if ( is_user_logged_in() ) { |
|
| 409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - public function pre_get_posts( $wp_query ) { |
|
| 417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - return $wp_query; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Register widgets |
|
| 426 | - * |
|
| 427 | - */ |
|
| 428 | - public function register_widgets() { |
|
| 429 | - global $pagenow; |
|
| 430 | - |
|
| 431 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 432 | - // So we disable our widgets when editing a page with UX Builder. |
|
| 433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 434 | - return; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 438 | - |
|
| 439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 440 | - // don't initiate in these conditions. |
|
| 441 | - } else { |
|
| 442 | - // Only load allowed widgets. |
|
| 443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 444 | - $widgets = apply_filters( |
|
| 445 | - 'getpaid_widget_classes', |
|
| 446 | - array( |
|
| 447 | - 'WPInv_Checkout_Widget', |
|
| 448 | - 'WPInv_History_Widget', |
|
| 449 | - 'WPInv_Receipt_Widget', |
|
| 450 | - 'WPInv_Subscriptions_Widget', |
|
| 451 | - 'WPInv_Buy_Item_Widget', |
|
| 452 | - 'WPInv_Messages_Widget', |
|
| 453 | - 'WPInv_GetPaid_Widget', |
|
| 454 | - 'WPInv_Invoice_Widget', |
|
| 455 | - ) |
|
| 456 | - ); |
|
| 457 | - |
|
| 458 | - // For each widget... |
|
| 459 | - foreach ( $widgets as $widget ) { |
|
| 460 | - // Abort early if it is excluded for this page. |
|
| 461 | - if ( in_array( $widget, $exclude ) ) { |
|
| 462 | - continue; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | - register_widget( $widget ); |
|
| 468 | - } else { |
|
| 469 | - new $widget(); |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Upgrades the database. |
|
| 477 | - * |
|
| 478 | - * @since 2.0.2 |
|
| 479 | - */ |
|
| 480 | - public function maybe_upgrade_database() { |
|
| 481 | - // Ensure the database tables are up to date. |
|
| 482 | - GetPaid_Installer::maybe_create_db_tables(); |
|
| 483 | - |
|
| 484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 485 | - |
|
| 486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 487 | - return; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $installer = new GetPaid_Installer(); |
|
| 491 | - |
|
| 492 | - if ( empty( $wpi_version ) ) { |
|
| 493 | - return $installer->upgrade_db( 0 ); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - $upgrades = array( |
|
| 497 | - '0.0.5' => '004', |
|
| 498 | - '1.0.3' => '102', |
|
| 499 | - '2.0.0' => '118', |
|
| 500 | - '2.8.0' => '279', |
|
| 501 | - ); |
|
| 502 | - |
|
| 503 | - foreach ( $upgrades as $key => $method ) { |
|
| 504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | - return $installer->upgrade_db( $method ); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Flushes the permalinks if needed. |
|
| 512 | - * |
|
| 513 | - * @since 2.0.8 |
|
| 514 | - */ |
|
| 515 | - public function maybe_flush_permalinks() { |
|
| 516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 517 | - |
|
| 518 | - if ( ! empty( $flush ) ) { |
|
| 519 | - flush_rewrite_rules(); |
|
| 520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Remove our pages from yoast sitemaps. |
|
| 526 | - * |
|
| 527 | - * @since 1.0.19 |
|
| 528 | - * @param int[] $excluded_posts_ids |
|
| 529 | - */ |
|
| 530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 531 | - // Ensure that we have an array. |
|
| 532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 533 | - $excluded_posts_ids = array(); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - // Prepare our pages. |
|
| 537 | - $our_pages = array(); |
|
| 538 | - |
|
| 539 | - // Checkout page. |
|
| 540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 541 | - |
|
| 542 | - // Success page. |
|
| 543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 544 | - |
|
| 545 | - // Failure page. |
|
| 546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 547 | - |
|
| 548 | - // History page. |
|
| 549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 550 | - |
|
| 551 | - // Subscriptions page. |
|
| 552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 553 | - |
|
| 554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 555 | - |
|
| 556 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 557 | - |
|
| 558 | - return array_unique( $excluded_posts_ids ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Remove our pages from yoast sitemaps. |
|
| 563 | - * |
|
| 564 | - * @since 1.0.19 |
|
| 565 | - * @param string[] $post_types |
|
| 566 | - */ |
|
| 567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
| 568 | - // Ensure that we have an array. |
|
| 569 | - if ( ! is_array( $post_types ) ) { |
|
| 570 | - $post_types = array(); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // Remove our post types. |
|
| 574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Displays additional footer code. |
|
| 579 | - * |
|
| 580 | - * @since 2.0.0 |
|
| 581 | - */ |
|
| 582 | - public function wp_footer() { |
|
| 583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Displays additional header code. |
|
| 588 | - * |
|
| 589 | - * @since 2.0.0 |
|
| 590 | - */ |
|
| 591 | - public function wp_head() { |
|
| 592 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Custom query vars. |
|
| 597 | - * |
|
| 598 | - */ |
|
| 599 | - public function custom_query_vars( $vars ) { |
|
| 600 | - $vars[] = 'getpaid-ipn'; |
|
| 601 | - return $vars; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Add rewrite tags and rules. |
|
| 606 | - * |
|
| 607 | - */ |
|
| 608 | - public function add_rewrite_rule() { |
|
| 609 | - $tag = 'getpaid-ipn'; |
|
| 610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Processes non-query string ipns. |
|
| 616 | - * |
|
| 617 | - */ |
|
| 618 | - public function maybe_process_new_ipn( $query ) { |
|
| 619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
| 620 | - return; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 624 | - |
|
| 625 | - if ( ! empty( $gateway ) ) { |
|
| 626 | - $gateway = sanitize_text_field( $gateway ); |
|
| 627 | - nocache_headers(); |
|
| 628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 630 | - exit; |
|
| 631 | - } |
|
| 632 | - } |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Data container. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Form elements instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Payment_Form_Elements |
|
| 35 | + */ |
|
| 36 | + public $form_elements; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array An array of payment gateways. |
|
| 40 | + */ |
|
| 41 | + public $gateways; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Class constructor. |
|
| 45 | + */ |
|
| 46 | + public function __construct() { |
|
| 47 | + $this->define_constants(); |
|
| 48 | + $this->includes(); |
|
| 49 | + $this->init_hooks(); |
|
| 50 | + $this->set_properties(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Sets a custom data property. |
|
| 55 | + * |
|
| 56 | + * @param string $prop The prop to set. |
|
| 57 | + * @param mixed $value The value to retrieve. |
|
| 58 | + */ |
|
| 59 | + public function set( $prop, $value ) { |
|
| 60 | + $this->data[ $prop ] = $value; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets a custom data property. |
|
| 65 | + * |
|
| 66 | + * @param string $prop The prop to set. |
|
| 67 | + * @return mixed The value. |
|
| 68 | + */ |
|
| 69 | + public function get( $prop ) { |
|
| 70 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | + return $this->data[ $prop ]; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Define class properties. |
|
| 79 | + */ |
|
| 80 | + public function set_properties() { |
|
| 81 | + // Sessions. |
|
| 82 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 84 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 85 | + |
|
| 86 | + // Init other objects. |
|
| 87 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | + $this->set( 'api', new WPInv_API() ); |
|
| 89 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 98 | + $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Define plugin constants. |
|
| 103 | + */ |
|
| 104 | + public function define_constants() { |
|
| 105 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 106 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 107 | + $this->version = WPINV_VERSION; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Hook into actions and filters. |
|
| 112 | + * |
|
| 113 | + * @since 1.0.19 |
|
| 114 | + */ |
|
| 115 | + protected function init_hooks() { |
|
| 116 | + /* Internationalize the text strings used. */ |
|
| 117 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 118 | + |
|
| 119 | + // Init the plugin after WordPress inits. |
|
| 120 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 121 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 122 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 123 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 124 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 125 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 126 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 127 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 128 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 129 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 130 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 131 | + |
|
| 132 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 133 | + add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 134 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 135 | + |
|
| 136 | + // Fires after registering actions. |
|
| 137 | + do_action( 'wpinv_actions', $this ); |
|
| 138 | + do_action( 'getpaid_actions', $this ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public function plugins_loaded() { |
|
| 142 | + /* Internationalize the text strings used. */ |
|
| 143 | + $this->load_textdomain(); |
|
| 144 | + |
|
| 145 | + do_action( 'wpinv_loaded' ); |
|
| 146 | + |
|
| 147 | + // Fix oxygen page builder conflict |
|
| 148 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 149 | + wpinv_oxygen_fix_conflict(); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Load Localisation files. |
|
| 155 | + * |
|
| 156 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 157 | + * |
|
| 158 | + * Locales found in: |
|
| 159 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 160 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 161 | + * |
|
| 162 | + * @since 1.0.0 |
|
| 163 | + */ |
|
| 164 | + public function load_textdomain() { |
|
| 165 | + // Determines the current locale. |
|
| 166 | + if ( function_exists( 'determine_locale' ) ) { |
|
| 167 | + $locale = determine_locale(); |
|
| 168 | + } elseif ( function_exists( 'get_user_locale' ) ) { |
|
| 169 | + $locale = get_user_locale(); |
|
| 170 | + } else { |
|
| 171 | + $locale = get_locale(); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Filter the locale to use for translations. |
|
| 176 | + */ |
|
| 177 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 178 | + |
|
| 179 | + unload_textdomain( 'invoicing', true ); |
|
| 180 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 181 | + load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Include required core files used in admin and on the frontend. |
|
| 186 | + */ |
|
| 187 | + public function includes() { |
|
| 188 | + // Start with the settings. |
|
| 189 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 190 | + |
|
| 191 | + // Packages/libraries. |
|
| 192 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 193 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 194 | + |
|
| 195 | + // Load functions. |
|
| 196 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 197 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 198 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 203 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 204 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 205 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 206 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 207 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 208 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 209 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 210 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 211 | + |
|
| 212 | + // Register autoloader. |
|
| 213 | + try { |
|
| 214 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 215 | + } catch ( Exception $e ) { |
|
| 216 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 221 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 222 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 224 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 225 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 226 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 227 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 228 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 229 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 230 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 231 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 232 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 234 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 235 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 236 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 237 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 238 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 239 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 241 | + |
|
| 242 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 243 | + GetPaid_Post_Types_Admin::init(); |
|
| 244 | + |
|
| 245 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 246 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 247 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 248 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 249 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 250 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 251 | + // load the user class only on the users.php page |
|
| 252 | + global $pagenow; |
|
| 253 | + if ( $pagenow == 'users.php' ) { |
|
| 254 | + new WPInv_Admin_Users(); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // Register cli commands |
|
| 259 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 260 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 261 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Class autoloader |
|
| 267 | + * |
|
| 268 | + * @param string $class_name The name of the class to load. |
|
| 269 | + * @access public |
|
| 270 | + * @since 1.0.19 |
|
| 271 | + * @return void |
|
| 272 | + */ |
|
| 273 | + public function autoload( $class_name ) { |
|
| 274 | + // Normalize the class name... |
|
| 275 | + $class_name = strtolower( $class_name ); |
|
| 276 | + |
|
| 277 | + // ... and make sure it is our class. |
|
| 278 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 279 | + return; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // Next, prepare the file name from the class. |
|
| 283 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 284 | + |
|
| 285 | + // Base path of the classes. |
|
| 286 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 287 | + |
|
| 288 | + // And an array of possible locations in order of importance. |
|
| 289 | + $locations = array( |
|
| 290 | + "$plugin_path/includes", |
|
| 291 | + "$plugin_path/includes/data-stores", |
|
| 292 | + "$plugin_path/includes/gateways", |
|
| 293 | + "$plugin_path/includes/payments", |
|
| 294 | + "$plugin_path/includes/geolocation", |
|
| 295 | + "$plugin_path/includes/reports", |
|
| 296 | + "$plugin_path/includes/api", |
|
| 297 | + "$plugin_path/includes/admin", |
|
| 298 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 299 | + ); |
|
| 300 | + |
|
| 301 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 302 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 303 | + include trailingslashit( $location ) . $file_name; |
|
| 304 | + break; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Inits hooks etc. |
|
| 311 | + */ |
|
| 312 | + public function init() { |
|
| 313 | + // Fires before getpaid inits. |
|
| 314 | + do_action( 'before_getpaid_init', $this ); |
|
| 315 | + |
|
| 316 | + // Maybe upgrade. |
|
| 317 | + $this->maybe_upgrade_database(); |
|
| 318 | + |
|
| 319 | + // Load default gateways. |
|
| 320 | + $gateways = apply_filters( |
|
| 321 | + 'getpaid_default_gateways', |
|
| 322 | + array( |
|
| 323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 328 | + ) |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + foreach ( $gateways as $id => $class ) { |
|
| 332 | + $this->gateways[ $id ] = new $class(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 336 | + GetPaid_Installer::rename_gateways_label(); |
|
| 337 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + // Fires after getpaid inits. |
|
| 341 | + do_action( 'getpaid_init', $this ); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Checks if this is an IPN request and processes it. |
|
| 346 | + */ |
|
| 347 | + public function maybe_process_ipn() { |
|
| 348 | + // Ensure that this is an IPN request. |
|
| 349 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 354 | + |
|
| 355 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 356 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 357 | + exit; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + public function enqueue_scripts() { |
|
| 361 | + // Fires before adding scripts. |
|
| 362 | + do_action( 'getpaid_enqueue_scripts' ); |
|
| 363 | + |
|
| 364 | + $localize = array(); |
|
| 365 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 366 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
| 367 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
| 368 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 369 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 370 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 371 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 372 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 373 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 374 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 375 | + |
|
| 376 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 377 | + |
|
| 378 | + // reCaptcha. |
|
| 379 | + if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 380 | + wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
| 384 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + public function wpinv_actions() { |
|
| 388 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Fires an action after verifying that a user can fire them. |
|
| 399 | + * |
|
| 400 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 401 | + * current user owns the invoice/subscription. |
|
| 402 | + */ |
|
| 403 | + public function maybe_do_authenticated_action() { |
|
| 404 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | + $data = wp_unslash( $_REQUEST ); |
|
| 407 | + |
|
| 408 | + if ( is_user_logged_in() ) { |
|
| 409 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + public function pre_get_posts( $wp_query ) { |
|
| 417 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + return $wp_query; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Register widgets |
|
| 426 | + * |
|
| 427 | + */ |
|
| 428 | + public function register_widgets() { |
|
| 429 | + global $pagenow; |
|
| 430 | + |
|
| 431 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 432 | + // So we disable our widgets when editing a page with UX Builder. |
|
| 433 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 434 | + return; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 438 | + |
|
| 439 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 440 | + // don't initiate in these conditions. |
|
| 441 | + } else { |
|
| 442 | + // Only load allowed widgets. |
|
| 443 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 444 | + $widgets = apply_filters( |
|
| 445 | + 'getpaid_widget_classes', |
|
| 446 | + array( |
|
| 447 | + 'WPInv_Checkout_Widget', |
|
| 448 | + 'WPInv_History_Widget', |
|
| 449 | + 'WPInv_Receipt_Widget', |
|
| 450 | + 'WPInv_Subscriptions_Widget', |
|
| 451 | + 'WPInv_Buy_Item_Widget', |
|
| 452 | + 'WPInv_Messages_Widget', |
|
| 453 | + 'WPInv_GetPaid_Widget', |
|
| 454 | + 'WPInv_Invoice_Widget', |
|
| 455 | + ) |
|
| 456 | + ); |
|
| 457 | + |
|
| 458 | + // For each widget... |
|
| 459 | + foreach ( $widgets as $widget ) { |
|
| 460 | + // Abort early if it is excluded for this page. |
|
| 461 | + if ( in_array( $widget, $exclude ) ) { |
|
| 462 | + continue; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 466 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | + register_widget( $widget ); |
|
| 468 | + } else { |
|
| 469 | + new $widget(); |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Upgrades the database. |
|
| 477 | + * |
|
| 478 | + * @since 2.0.2 |
|
| 479 | + */ |
|
| 480 | + public function maybe_upgrade_database() { |
|
| 481 | + // Ensure the database tables are up to date. |
|
| 482 | + GetPaid_Installer::maybe_create_db_tables(); |
|
| 483 | + |
|
| 484 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 485 | + |
|
| 486 | + if ( $wpi_version == WPINV_VERSION ) { |
|
| 487 | + return; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $installer = new GetPaid_Installer(); |
|
| 491 | + |
|
| 492 | + if ( empty( $wpi_version ) ) { |
|
| 493 | + return $installer->upgrade_db( 0 ); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + $upgrades = array( |
|
| 497 | + '0.0.5' => '004', |
|
| 498 | + '1.0.3' => '102', |
|
| 499 | + '2.0.0' => '118', |
|
| 500 | + '2.8.0' => '279', |
|
| 501 | + ); |
|
| 502 | + |
|
| 503 | + foreach ( $upgrades as $key => $method ) { |
|
| 504 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | + return $installer->upgrade_db( $method ); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * Flushes the permalinks if needed. |
|
| 512 | + * |
|
| 513 | + * @since 2.0.8 |
|
| 514 | + */ |
|
| 515 | + public function maybe_flush_permalinks() { |
|
| 516 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 517 | + |
|
| 518 | + if ( ! empty( $flush ) ) { |
|
| 519 | + flush_rewrite_rules(); |
|
| 520 | + delete_option( 'wpinv_flush_permalinks' ); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Remove our pages from yoast sitemaps. |
|
| 526 | + * |
|
| 527 | + * @since 1.0.19 |
|
| 528 | + * @param int[] $excluded_posts_ids |
|
| 529 | + */ |
|
| 530 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 531 | + // Ensure that we have an array. |
|
| 532 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 533 | + $excluded_posts_ids = array(); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + // Prepare our pages. |
|
| 537 | + $our_pages = array(); |
|
| 538 | + |
|
| 539 | + // Checkout page. |
|
| 540 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 541 | + |
|
| 542 | + // Success page. |
|
| 543 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 544 | + |
|
| 545 | + // Failure page. |
|
| 546 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 547 | + |
|
| 548 | + // History page. |
|
| 549 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 550 | + |
|
| 551 | + // Subscriptions page. |
|
| 552 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 553 | + |
|
| 554 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 555 | + |
|
| 556 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 557 | + |
|
| 558 | + return array_unique( $excluded_posts_ids ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Remove our pages from yoast sitemaps. |
|
| 563 | + * |
|
| 564 | + * @since 1.0.19 |
|
| 565 | + * @param string[] $post_types |
|
| 566 | + */ |
|
| 567 | + public function exclude_invoicing_post_types( $post_types ) { |
|
| 568 | + // Ensure that we have an array. |
|
| 569 | + if ( ! is_array( $post_types ) ) { |
|
| 570 | + $post_types = array(); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // Remove our post types. |
|
| 574 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Displays additional footer code. |
|
| 579 | + * |
|
| 580 | + * @since 2.0.0 |
|
| 581 | + */ |
|
| 582 | + public function wp_footer() { |
|
| 583 | + wpinv_get_template( 'frontend-footer.php' ); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Displays additional header code. |
|
| 588 | + * |
|
| 589 | + * @since 2.0.0 |
|
| 590 | + */ |
|
| 591 | + public function wp_head() { |
|
| 592 | + wpinv_get_template( 'frontend-head.php' ); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Custom query vars. |
|
| 597 | + * |
|
| 598 | + */ |
|
| 599 | + public function custom_query_vars( $vars ) { |
|
| 600 | + $vars[] = 'getpaid-ipn'; |
|
| 601 | + return $vars; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Add rewrite tags and rules. |
|
| 606 | + * |
|
| 607 | + */ |
|
| 608 | + public function add_rewrite_rule() { |
|
| 609 | + $tag = 'getpaid-ipn'; |
|
| 610 | + add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | + add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Processes non-query string ipns. |
|
| 616 | + * |
|
| 617 | + */ |
|
| 618 | + public function maybe_process_new_ipn( $query ) { |
|
| 619 | + if ( is_admin() || ! $query->is_main_query() ) { |
|
| 620 | + return; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 624 | + |
|
| 625 | + if ( ! empty( $gateway ) ) { |
|
| 626 | + $gateway = sanitize_text_field( $gateway ); |
|
| 627 | + nocache_headers(); |
|
| 628 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 630 | + exit; |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | 633 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 1.0.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param string $prop The prop to set. |
| 57 | 57 | * @param mixed $value The value to retrieve. |
| 58 | 58 | */ |
| 59 | - public function set( $prop, $value ) { |
|
| 60 | - $this->data[ $prop ] = $value; |
|
| 59 | + public function set($prop, $value) { |
|
| 60 | + $this->data[$prop] = $value; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | * @param string $prop The prop to set. |
| 67 | 67 | * @return mixed The value. |
| 68 | 68 | */ |
| 69 | - public function get( $prop ) { |
|
| 70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | - return $this->data[ $prop ]; |
|
| 69 | + public function get($prop) { |
|
| 70 | + if (isset($this->data[$prop])) { |
|
| 71 | + return $this->data[$prop]; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | return null; |
@@ -79,31 +79,31 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function set_properties() { |
| 81 | 81 | // Sessions. |
| 82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 82 | + $this->set('session', new WPInv_Session_Handler()); |
|
| 83 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
| 84 | 84 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
| 85 | 85 | |
| 86 | 86 | // Init other objects. |
| 87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | - $this->set( 'api', new WPInv_API() ); |
|
| 89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 98 | - $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
| 87 | + $this->set('notes', new WPInv_Notes()); |
|
| 88 | + $this->set('api', new WPInv_API()); |
|
| 89 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
| 90 | + $this->set('template', new GetPaid_Template()); |
|
| 91 | + $this->set('admin', new GetPaid_Admin()); |
|
| 92 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
| 93 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
| 94 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
| 95 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
| 96 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
| 97 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
| 98 | + $this->set('data_retention', new WPInv_Data_Retention()); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * Define plugin constants. |
| 103 | 103 | */ |
| 104 | 104 | public function define_constants() { |
| 105 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 106 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 105 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 106 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 107 | 107 | $this->version = WPINV_VERSION; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -114,38 +114,38 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | protected function init_hooks() { |
| 116 | 116 | /* Internationalize the text strings used. */ |
| 117 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 117 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 118 | 118 | |
| 119 | 119 | // Init the plugin after WordPress inits. |
| 120 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 121 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 122 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 123 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 125 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 126 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 127 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 128 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 129 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 130 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 131 | - |
|
| 132 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 133 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 134 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 120 | + add_action('init', array($this, 'init'), 1); |
|
| 121 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
| 122 | + add_action('init', array($this, 'wpinv_actions')); |
|
| 123 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
| 124 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
| 125 | + add_action('wp_footer', array($this, 'wp_footer')); |
|
| 126 | + add_action('wp_head', array($this, 'wp_head')); |
|
| 127 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
| 128 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
| 129 | + add_filter('the_seo_framework_sitemap_supported_post_types', array($this, 'exclude_invoicing_post_types')); |
|
| 130 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 131 | + |
|
| 132 | + add_filter('query_vars', array($this, 'custom_query_vars')); |
|
| 133 | + add_action('init', array($this, 'add_rewrite_rule'), 10, 0); |
|
| 134 | + add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1); |
|
| 135 | 135 | |
| 136 | 136 | // Fires after registering actions. |
| 137 | - do_action( 'wpinv_actions', $this ); |
|
| 138 | - do_action( 'getpaid_actions', $this ); |
|
| 137 | + do_action('wpinv_actions', $this); |
|
| 138 | + do_action('getpaid_actions', $this); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | public function plugins_loaded() { |
| 142 | 142 | /* Internationalize the text strings used. */ |
| 143 | 143 | $this->load_textdomain(); |
| 144 | 144 | |
| 145 | - do_action( 'wpinv_loaded' ); |
|
| 145 | + do_action('wpinv_loaded'); |
|
| 146 | 146 | |
| 147 | 147 | // Fix oxygen page builder conflict |
| 148 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 148 | + if (function_exists('ct_css_output')) { |
|
| 149 | 149 | wpinv_oxygen_fix_conflict(); |
| 150 | 150 | } |
| 151 | 151 | } |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function load_textdomain() { |
| 165 | 165 | // Determines the current locale. |
| 166 | - if ( function_exists( 'determine_locale' ) ) { |
|
| 166 | + if (function_exists('determine_locale')) { |
|
| 167 | 167 | $locale = determine_locale(); |
| 168 | - } elseif ( function_exists( 'get_user_locale' ) ) { |
|
| 168 | + } elseif (function_exists('get_user_locale')) { |
|
| 169 | 169 | $locale = get_user_locale(); |
| 170 | 170 | } else { |
| 171 | 171 | $locale = get_locale(); |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | /** |
| 175 | 175 | * Filter the locale to use for translations. |
| 176 | 176 | */ |
| 177 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 177 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
| 178 | 178 | |
| 179 | - unload_textdomain( 'invoicing', true ); |
|
| 180 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 181 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 179 | + unload_textdomain('invoicing', true); |
|
| 180 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 181 | + load_plugin_textdomain('invoicing', false, plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/'); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | // Register autoloader. |
| 213 | 213 | try { |
| 214 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 215 | - } catch ( Exception $e ) { |
|
| 216 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 214 | + spl_autoload_register(array($this, 'autoload'), true); |
|
| 215 | + } catch (Exception $e) { |
|
| 216 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
| 240 | 240 | require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
| 241 | 241 | |
| 242 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 242 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 243 | 243 | GetPaid_Post_Types_Admin::init(); |
| 244 | 244 | |
| 245 | 245 | require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
@@ -250,15 +250,15 @@ discard block |
||
| 250 | 250 | require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
| 251 | 251 | // load the user class only on the users.php page |
| 252 | 252 | global $pagenow; |
| 253 | - if ( $pagenow == 'users.php' ) { |
|
| 253 | + if ($pagenow == 'users.php') { |
|
| 254 | 254 | new WPInv_Admin_Users(); |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | // Register cli commands |
| 259 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 259 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 260 | 260 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
| 261 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 261 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | |
@@ -270,20 +270,20 @@ discard block |
||
| 270 | 270 | * @since 1.0.19 |
| 271 | 271 | * @return void |
| 272 | 272 | */ |
| 273 | - public function autoload( $class_name ) { |
|
| 273 | + public function autoload($class_name) { |
|
| 274 | 274 | // Normalize the class name... |
| 275 | - $class_name = strtolower( $class_name ); |
|
| 275 | + $class_name = strtolower($class_name); |
|
| 276 | 276 | |
| 277 | 277 | // ... and make sure it is our class. |
| 278 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 278 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
| 279 | 279 | return; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // Next, prepare the file name from the class. |
| 283 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 283 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
| 284 | 284 | |
| 285 | 285 | // Base path of the classes. |
| 286 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 286 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
| 287 | 287 | |
| 288 | 288 | // And an array of possible locations in order of importance. |
| 289 | 289 | $locations = array( |
@@ -298,9 +298,9 @@ discard block |
||
| 298 | 298 | "$plugin_path/includes/admin/meta-boxes", |
| 299 | 299 | ); |
| 300 | 300 | |
| 301 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 302 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 303 | - include trailingslashit( $location ) . $file_name; |
|
| 301 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
| 302 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
| 303 | + include trailingslashit($location) . $file_name; |
|
| 304 | 304 | break; |
| 305 | 305 | } |
| 306 | 306 | } |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | */ |
| 312 | 312 | public function init() { |
| 313 | 313 | // Fires before getpaid inits. |
| 314 | - do_action( 'before_getpaid_init', $this ); |
|
| 314 | + do_action('before_getpaid_init', $this); |
|
| 315 | 315 | |
| 316 | 316 | // Maybe upgrade. |
| 317 | 317 | $this->maybe_upgrade_database(); |
@@ -328,17 +328,17 @@ discard block |
||
| 328 | 328 | ) |
| 329 | 329 | ); |
| 330 | 330 | |
| 331 | - foreach ( $gateways as $id => $class ) { |
|
| 332 | - $this->gateways[ $id ] = new $class(); |
|
| 331 | + foreach ($gateways as $id => $class) { |
|
| 332 | + $this->gateways[$id] = new $class(); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | + if ('yes' != get_option('wpinv_renamed_gateways')) { |
|
| 336 | 336 | GetPaid_Installer::rename_gateways_label(); |
| 337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | + update_option('wpinv_renamed_gateways', 'yes'); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | // Fires after getpaid inits. |
| 341 | - do_action( 'getpaid_init', $this ); |
|
| 341 | + do_action('getpaid_init', $this); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -346,51 +346,51 @@ discard block |
||
| 346 | 346 | */ |
| 347 | 347 | public function maybe_process_ipn() { |
| 348 | 348 | // Ensure that this is an IPN request. |
| 349 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 349 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
| 350 | 350 | return; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 353 | + $gateway = sanitize_text_field($_GET['wpi-gateway']); |
|
| 354 | 354 | |
| 355 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 356 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 355 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
| 356 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
| 357 | 357 | exit; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | public function enqueue_scripts() { |
| 361 | 361 | // Fires before adding scripts. |
| 362 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 362 | + do_action('getpaid_enqueue_scripts'); |
|
| 363 | 363 | |
| 364 | 364 | $localize = array(); |
| 365 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 365 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 366 | 366 | $localize['thousands'] = wpinv_thousands_separator(); |
| 367 | 367 | $localize['decimals'] = wpinv_decimal_separator(); |
| 368 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 369 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 368 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 369 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
| 370 | 370 | $localize['UseTaxes'] = wpinv_use_taxes(); |
| 371 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 372 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 373 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 371 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
| 372 | + $localize['loading'] = __('Loading...', 'invoicing'); |
|
| 373 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
| 374 | 374 | $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
| 375 | 375 | |
| 376 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 376 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 377 | 377 | |
| 378 | 378 | // reCaptcha. |
| 379 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 380 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 379 | + if (getpaid_is_recaptcha_enabled() && ($recaptcha_js = getpaid_recaptcha_api_url())) { |
|
| 380 | + wp_enqueue_script('recaptcha', $recaptcha_js, array(), null, true); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
| 384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 383 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array('jquery'), WPINV_VERSION, true); |
|
| 384 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | public function wpinv_actions() { |
| 388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 388 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 389 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 392 | + if (defined('WP_ALL_IMPORT_ROOT_DIR')) { |
|
| 393 | + include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
@@ -401,21 +401,21 @@ discard block |
||
| 401 | 401 | * current user owns the invoice/subscription. |
| 402 | 402 | */ |
| 403 | 403 | public function maybe_do_authenticated_action() { |
| 404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | - $data = wp_unslash( $_REQUEST ); |
|
| 404 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
| 405 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
| 406 | + $data = wp_unslash($_REQUEST); |
|
| 407 | 407 | |
| 408 | - if ( is_user_logged_in() ) { |
|
| 409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 408 | + if (is_user_logged_in()) { |
|
| 409 | + do_action("getpaid_authenticated_action_$key", $data); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 412 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - public function pre_get_posts( $wp_query ) { |
|
| 417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 416 | + public function pre_get_posts($wp_query) { |
|
| 417 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 418 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | return $wp_query; |
@@ -430,17 +430,17 @@ discard block |
||
| 430 | 430 | |
| 431 | 431 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
| 432 | 432 | // So we disable our widgets when editing a page with UX Builder. |
| 433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 433 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
| 434 | 434 | return; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 437 | + $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
| 438 | 438 | |
| 439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 439 | + if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
| 440 | 440 | // don't initiate in these conditions. |
| 441 | 441 | } else { |
| 442 | 442 | // Only load allowed widgets. |
| 443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 443 | + $exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array(); |
|
| 444 | 444 | $widgets = apply_filters( |
| 445 | 445 | 'getpaid_widget_classes', |
| 446 | 446 | array( |
@@ -456,15 +456,15 @@ discard block |
||
| 456 | 456 | ); |
| 457 | 457 | |
| 458 | 458 | // For each widget... |
| 459 | - foreach ( $widgets as $widget ) { |
|
| 459 | + foreach ($widgets as $widget) { |
|
| 460 | 460 | // Abort early if it is excluded for this page. |
| 461 | - if ( in_array( $widget, $exclude ) ) { |
|
| 461 | + if (in_array($widget, $exclude)) { |
|
| 462 | 462 | continue; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
| 466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | - register_widget( $widget ); |
|
| 466 | + if (is_subclass_of($widget, 'WP_Widget')) { |
|
| 467 | + register_widget($widget); |
|
| 468 | 468 | } else { |
| 469 | 469 | new $widget(); |
| 470 | 470 | } |
@@ -481,28 +481,28 @@ discard block |
||
| 481 | 481 | // Ensure the database tables are up to date. |
| 482 | 482 | GetPaid_Installer::maybe_create_db_tables(); |
| 483 | 483 | |
| 484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 484 | + $wpi_version = get_option('wpinv_version', 0); |
|
| 485 | 485 | |
| 486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 486 | + if ($wpi_version == WPINV_VERSION) { |
|
| 487 | 487 | return; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | $installer = new GetPaid_Installer(); |
| 491 | 491 | |
| 492 | - if ( empty( $wpi_version ) ) { |
|
| 493 | - return $installer->upgrade_db( 0 ); |
|
| 492 | + if (empty($wpi_version)) { |
|
| 493 | + return $installer->upgrade_db(0); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - $upgrades = array( |
|
| 496 | + $upgrades = array( |
|
| 497 | 497 | '0.0.5' => '004', |
| 498 | 498 | '1.0.3' => '102', |
| 499 | 499 | '2.0.0' => '118', |
| 500 | 500 | '2.8.0' => '279', |
| 501 | 501 | ); |
| 502 | 502 | |
| 503 | - foreach ( $upgrades as $key => $method ) { |
|
| 504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | - return $installer->upgrade_db( $method ); |
|
| 503 | + foreach ($upgrades as $key => $method) { |
|
| 504 | + if (version_compare($wpi_version, $key, '<')) { |
|
| 505 | + return $installer->upgrade_db($method); |
|
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | } |
@@ -513,11 +513,11 @@ discard block |
||
| 513 | 513 | * @since 2.0.8 |
| 514 | 514 | */ |
| 515 | 515 | public function maybe_flush_permalinks() { |
| 516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 516 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
| 517 | 517 | |
| 518 | - if ( ! empty( $flush ) ) { |
|
| 518 | + if (!empty($flush)) { |
|
| 519 | 519 | flush_rewrite_rules(); |
| 520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 520 | + delete_option('wpinv_flush_permalinks'); |
|
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | |
@@ -527,9 +527,9 @@ discard block |
||
| 527 | 527 | * @since 1.0.19 |
| 528 | 528 | * @param int[] $excluded_posts_ids |
| 529 | 529 | */ |
| 530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 530 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
| 531 | 531 | // Ensure that we have an array. |
| 532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 532 | + if (!is_array($excluded_posts_ids)) { |
|
| 533 | 533 | $excluded_posts_ids = array(); |
| 534 | 534 | } |
| 535 | 535 | |
@@ -537,25 +537,25 @@ discard block |
||
| 537 | 537 | $our_pages = array(); |
| 538 | 538 | |
| 539 | 539 | // Checkout page. |
| 540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 540 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
| 541 | 541 | |
| 542 | 542 | // Success page. |
| 543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 543 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
| 544 | 544 | |
| 545 | 545 | // Failure page. |
| 546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 546 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
| 547 | 547 | |
| 548 | 548 | // History page. |
| 549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 549 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
| 550 | 550 | |
| 551 | 551 | // Subscriptions page. |
| 552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 552 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
| 553 | 553 | |
| 554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 554 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
| 555 | 555 | |
| 556 | 556 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
| 557 | 557 | |
| 558 | - return array_unique( $excluded_posts_ids ); |
|
| 558 | + return array_unique($excluded_posts_ids); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
@@ -564,14 +564,14 @@ discard block |
||
| 564 | 564 | * @since 1.0.19 |
| 565 | 565 | * @param string[] $post_types |
| 566 | 566 | */ |
| 567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
| 567 | + public function exclude_invoicing_post_types($post_types) { |
|
| 568 | 568 | // Ensure that we have an array. |
| 569 | - if ( ! is_array( $post_types ) ) { |
|
| 569 | + if (!is_array($post_types)) { |
|
| 570 | 570 | $post_types = array(); |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | // Remove our post types. |
| 574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 574 | + return array_diff($post_types, array_keys(getpaid_get_invoice_post_types())); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | * @since 2.0.0 |
| 581 | 581 | */ |
| 582 | 582 | public function wp_footer() { |
| 583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 583 | + wpinv_get_template('frontend-footer.php'); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -589,14 +589,14 @@ discard block |
||
| 589 | 589 | * @since 2.0.0 |
| 590 | 590 | */ |
| 591 | 591 | public function wp_head() { |
| 592 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 592 | + wpinv_get_template('frontend-head.php'); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
| 596 | 596 | * Custom query vars. |
| 597 | 597 | * |
| 598 | 598 | */ |
| 599 | - public function custom_query_vars( $vars ) { |
|
| 599 | + public function custom_query_vars($vars) { |
|
| 600 | 600 | $vars[] = 'getpaid-ipn'; |
| 601 | 601 | return $vars; |
| 602 | 602 | } |
@@ -607,26 +607,26 @@ discard block |
||
| 607 | 607 | */ |
| 608 | 608 | public function add_rewrite_rule() { |
| 609 | 609 | $tag = 'getpaid-ipn'; |
| 610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 610 | + add_rewrite_tag("%$tag%", '([^&]+)'); |
|
| 611 | + add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top'); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | /** |
| 615 | 615 | * Processes non-query string ipns. |
| 616 | 616 | * |
| 617 | 617 | */ |
| 618 | - public function maybe_process_new_ipn( $query ) { |
|
| 619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
| 618 | + public function maybe_process_new_ipn($query) { |
|
| 619 | + if (is_admin() || !$query->is_main_query()) { |
|
| 620 | 620 | return; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 623 | + $gateway = get_query_var('getpaid-ipn'); |
|
| 624 | 624 | |
| 625 | - if ( ! empty( $gateway ) ) { |
|
| 626 | - $gateway = sanitize_text_field( $gateway ); |
|
| 625 | + if (!empty($gateway)) { |
|
| 626 | + $gateway = sanitize_text_field($gateway); |
|
| 627 | 627 | nocache_headers(); |
| 628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 628 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
| 629 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
| 630 | 630 | exit; |
| 631 | 631 | } |
| 632 | 632 | } |