@@ -20,353 +20,353 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class GetPaid_Installer { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Upgrades the install. |
|
| 25 | - * |
|
| 26 | - * @param string $upgrade_from The current invoicing version. |
|
| 27 | - */ |
|
| 28 | - public function upgrade_db( $upgrade_from ) { |
|
| 29 | - |
|
| 30 | - // Save the current invoicing version. |
|
| 31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
| 32 | - |
|
| 33 | - // Setup the invoice Custom Post Type. |
|
| 34 | - GetPaid_Post_Types::register_post_types(); |
|
| 35 | - |
|
| 36 | - // Clear the permalinks |
|
| 37 | - flush_rewrite_rules(); |
|
| 38 | - |
|
| 39 | - // Maybe create new/missing pages. |
|
| 40 | - $this->create_pages(); |
|
| 41 | - |
|
| 42 | - // Maybe re(add) admin capabilities. |
|
| 43 | - $this->add_capabilities(); |
|
| 44 | - |
|
| 45 | - // Maybe create the default payment form. |
|
| 46 | - wpinv_get_default_payment_form(); |
|
| 47 | - |
|
| 48 | - // Create any missing database tables. |
|
| 49 | - $method = "upgrade_from_$upgrade_from"; |
|
| 50 | - |
|
| 51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
| 52 | - |
|
| 53 | - if ( empty( $installed ) ) { |
|
| 54 | - update_option( 'gepaid_installed_on', time() ); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ( method_exists( $this, $method ) ) { |
|
| 58 | - $this->$method(); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Do a fresh install. |
|
| 65 | - * |
|
| 66 | - */ |
|
| 67 | - public function upgrade_from_0() { |
|
| 68 | - |
|
| 69 | - // Save default tax rates. |
|
| 70 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Upgrade to 0.0.5 |
|
| 75 | - * |
|
| 76 | - */ |
|
| 77 | - public function upgrade_from_004() { |
|
| 78 | - global $wpdb; |
|
| 79 | - |
|
| 80 | - // Invoices. |
|
| 81 | - $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' )" ); |
|
| 82 | - if ( ! empty( $results ) ) { |
|
| 83 | - $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' )" ); |
|
| 84 | - |
|
| 85 | - // Clean post cache |
|
| 86 | - foreach ( $results as $row ) { |
|
| 87 | - clean_post_cache( $row->ID ); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Item meta key changes |
|
| 92 | - $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' )"; |
|
| 93 | - $results = $wpdb->get_results( $query ); |
|
| 94 | - |
|
| 95 | - if ( ! empty( $results ) ) { |
|
| 96 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
| 97 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
| 98 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
| 99 | - |
|
| 100 | - foreach ( $results as $row ) { |
|
| 101 | - clean_post_cache( $row->post_id ); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Upgrade to version 2.0.0. |
|
| 109 | - * |
|
| 110 | - */ |
|
| 111 | - public function upgrade_from_118() { |
|
| 112 | - $this->migrate_old_invoices(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Give administrators the capability to manage GetPaid. |
|
| 117 | - * |
|
| 118 | - */ |
|
| 119 | - public function add_capabilities() { |
|
| 120 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Retreives GetPaid pages. |
|
| 125 | - * |
|
| 126 | - */ |
|
| 127 | - public static function get_pages() { |
|
| 128 | - |
|
| 129 | - return apply_filters( |
|
| 130 | - 'wpinv_create_pages', |
|
| 131 | - array( |
|
| 132 | - |
|
| 133 | - // Checkout page. |
|
| 134 | - 'checkout_page' => array( |
|
| 135 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
| 136 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
| 137 | - 'content' => ' |
|
| 23 | + /** |
|
| 24 | + * Upgrades the install. |
|
| 25 | + * |
|
| 26 | + * @param string $upgrade_from The current invoicing version. |
|
| 27 | + */ |
|
| 28 | + public function upgrade_db( $upgrade_from ) { |
|
| 29 | + |
|
| 30 | + // Save the current invoicing version. |
|
| 31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
| 32 | + |
|
| 33 | + // Setup the invoice Custom Post Type. |
|
| 34 | + GetPaid_Post_Types::register_post_types(); |
|
| 35 | + |
|
| 36 | + // Clear the permalinks |
|
| 37 | + flush_rewrite_rules(); |
|
| 38 | + |
|
| 39 | + // Maybe create new/missing pages. |
|
| 40 | + $this->create_pages(); |
|
| 41 | + |
|
| 42 | + // Maybe re(add) admin capabilities. |
|
| 43 | + $this->add_capabilities(); |
|
| 44 | + |
|
| 45 | + // Maybe create the default payment form. |
|
| 46 | + wpinv_get_default_payment_form(); |
|
| 47 | + |
|
| 48 | + // Create any missing database tables. |
|
| 49 | + $method = "upgrade_from_$upgrade_from"; |
|
| 50 | + |
|
| 51 | + $installed = get_option( 'gepaid_installed_on' ); |
|
| 52 | + |
|
| 53 | + if ( empty( $installed ) ) { |
|
| 54 | + update_option( 'gepaid_installed_on', time() ); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ( method_exists( $this, $method ) ) { |
|
| 58 | + $this->$method(); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Do a fresh install. |
|
| 65 | + * |
|
| 66 | + */ |
|
| 67 | + public function upgrade_from_0() { |
|
| 68 | + |
|
| 69 | + // Save default tax rates. |
|
| 70 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Upgrade to 0.0.5 |
|
| 75 | + * |
|
| 76 | + */ |
|
| 77 | + public function upgrade_from_004() { |
|
| 78 | + global $wpdb; |
|
| 79 | + |
|
| 80 | + // Invoices. |
|
| 81 | + $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' )" ); |
|
| 82 | + if ( ! empty( $results ) ) { |
|
| 83 | + $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' )" ); |
|
| 84 | + |
|
| 85 | + // Clean post cache |
|
| 86 | + foreach ( $results as $row ) { |
|
| 87 | + clean_post_cache( $row->ID ); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Item meta key changes |
|
| 92 | + $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' )"; |
|
| 93 | + $results = $wpdb->get_results( $query ); |
|
| 94 | + |
|
| 95 | + if ( ! empty( $results ) ) { |
|
| 96 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
| 97 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
| 98 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
| 99 | + |
|
| 100 | + foreach ( $results as $row ) { |
|
| 101 | + clean_post_cache( $row->post_id ); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Upgrade to version 2.0.0. |
|
| 109 | + * |
|
| 110 | + */ |
|
| 111 | + public function upgrade_from_118() { |
|
| 112 | + $this->migrate_old_invoices(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Give administrators the capability to manage GetPaid. |
|
| 117 | + * |
|
| 118 | + */ |
|
| 119 | + public function add_capabilities() { |
|
| 120 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Retreives GetPaid pages. |
|
| 125 | + * |
|
| 126 | + */ |
|
| 127 | + public static function get_pages() { |
|
| 128 | + |
|
| 129 | + return apply_filters( |
|
| 130 | + 'wpinv_create_pages', |
|
| 131 | + array( |
|
| 132 | + |
|
| 133 | + // Checkout page. |
|
| 134 | + 'checkout_page' => array( |
|
| 135 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
| 136 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
| 137 | + 'content' => ' |
|
| 138 | 138 | <!-- wp:shortcode --> |
| 139 | 139 | [wpinv_checkout] |
| 140 | 140 | <!-- /wp:shortcode --> |
| 141 | 141 | ', |
| 142 | - 'parent' => '', |
|
| 143 | - ), |
|
| 144 | - |
|
| 145 | - // Invoice history page. |
|
| 146 | - 'invoice_history_page' => array( |
|
| 147 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
| 148 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
| 149 | - 'content' => ' |
|
| 142 | + 'parent' => '', |
|
| 143 | + ), |
|
| 144 | + |
|
| 145 | + // Invoice history page. |
|
| 146 | + 'invoice_history_page' => array( |
|
| 147 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
| 148 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
| 149 | + 'content' => ' |
|
| 150 | 150 | <!-- wp:shortcode --> |
| 151 | 151 | [wpinv_history] |
| 152 | 152 | <!-- /wp:shortcode --> |
| 153 | 153 | ', |
| 154 | - 'parent' => '', |
|
| 155 | - ), |
|
| 156 | - |
|
| 157 | - // Success page content. |
|
| 158 | - 'success_page' => array( |
|
| 159 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
| 160 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
| 161 | - 'content' => ' |
|
| 154 | + 'parent' => '', |
|
| 155 | + ), |
|
| 156 | + |
|
| 157 | + // Success page content. |
|
| 158 | + 'success_page' => array( |
|
| 159 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
| 160 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
| 161 | + 'content' => ' |
|
| 162 | 162 | <!-- wp:shortcode --> |
| 163 | 163 | [wpinv_receipt] |
| 164 | 164 | <!-- /wp:shortcode --> |
| 165 | 165 | ', |
| 166 | - 'parent' => 'gp-checkout', |
|
| 167 | - ), |
|
| 168 | - |
|
| 169 | - // Failure page content. |
|
| 170 | - 'failure_page' => array( |
|
| 171 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
| 172 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
| 173 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
| 174 | - 'parent' => 'gp-checkout', |
|
| 175 | - ), |
|
| 176 | - |
|
| 177 | - // Subscriptions history page. |
|
| 178 | - 'invoice_subscription_page' => array( |
|
| 179 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
| 180 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
| 181 | - 'content' => ' |
|
| 166 | + 'parent' => 'gp-checkout', |
|
| 167 | + ), |
|
| 168 | + |
|
| 169 | + // Failure page content. |
|
| 170 | + 'failure_page' => array( |
|
| 171 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
| 172 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
| 173 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
| 174 | + 'parent' => 'gp-checkout', |
|
| 175 | + ), |
|
| 176 | + |
|
| 177 | + // Subscriptions history page. |
|
| 178 | + 'invoice_subscription_page' => array( |
|
| 179 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
| 180 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
| 181 | + 'content' => ' |
|
| 182 | 182 | <!-- wp:shortcode --> |
| 183 | 183 | [wpinv_subscriptions] |
| 184 | 184 | <!-- /wp:shortcode --> |
| 185 | 185 | ', |
| 186 | - 'parent' => '', |
|
| 187 | - ), |
|
| 188 | - |
|
| 189 | - ) |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Re-create GetPaid pages. |
|
| 196 | - * |
|
| 197 | - */ |
|
| 198 | - public function create_pages() { |
|
| 199 | - |
|
| 200 | - foreach ( self::get_pages() as $key => $page ) { |
|
| 201 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Migrates old invoices to new invoices. |
|
| 208 | - * |
|
| 209 | - */ |
|
| 210 | - public function migrate_old_invoices() { |
|
| 211 | - global $wpdb; |
|
| 212 | - |
|
| 213 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 214 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 215 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
| 216 | - $invoices = array_unique( |
|
| 217 | - get_posts( |
|
| 218 | - array( |
|
| 219 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
| 220 | - 'posts_per_page' => -1, |
|
| 221 | - 'fields' => 'ids', |
|
| 222 | - 'post_status' => array_keys( get_post_stati() ), |
|
| 223 | - 'exclude' => (array) $migrated, |
|
| 224 | - ) |
|
| 225 | - ) |
|
| 226 | - ); |
|
| 227 | - |
|
| 228 | - // Abort if we do not have any invoices. |
|
| 229 | - if ( empty( $invoices ) ) { |
|
| 230 | - return; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
| 234 | - |
|
| 235 | - $invoice_rows = array(); |
|
| 236 | - foreach ( $invoices as $invoice ) { |
|
| 237 | - |
|
| 238 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
| 239 | - |
|
| 240 | - if ( empty( $invoice->ID ) ) { |
|
| 241 | - return; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - $fields = array( |
|
| 245 | - 'post_id' => $invoice->ID, |
|
| 246 | - 'number' => $invoice->get_number(), |
|
| 247 | - 'key' => $invoice->get_key(), |
|
| 248 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
| 249 | - 'mode' => $invoice->mode, |
|
| 250 | - 'user_ip' => $invoice->get_ip(), |
|
| 251 | - 'first_name' => $invoice->get_first_name(), |
|
| 252 | - 'last_name' => $invoice->get_last_name(), |
|
| 253 | - 'address' => $invoice->get_address(), |
|
| 254 | - 'city' => $invoice->city, |
|
| 255 | - 'state' => $invoice->state, |
|
| 256 | - 'country' => $invoice->country, |
|
| 257 | - 'zip' => $invoice->zip, |
|
| 258 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
| 259 | - 'gateway' => $invoice->get_gateway(), |
|
| 260 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
| 261 | - 'currency' => $invoice->get_currency(), |
|
| 262 | - 'subtotal' => $invoice->get_subtotal(), |
|
| 263 | - 'tax' => $invoice->get_tax(), |
|
| 264 | - 'fees_total' => $invoice->get_fees_total(), |
|
| 265 | - 'total' => $invoice->get_total(), |
|
| 266 | - 'discount' => $invoice->get_discount(), |
|
| 267 | - 'discount_code' => $invoice->get_discount_code(), |
|
| 268 | - 'disable_taxes' => $invoice->disable_taxes, |
|
| 269 | - 'due_date' => $invoice->get_due_date(), |
|
| 270 | - 'completed_date' => $invoice->get_completed_date(), |
|
| 271 | - 'company' => $invoice->company, |
|
| 272 | - 'vat_number' => $invoice->vat_number, |
|
| 273 | - 'vat_rate' => $invoice->vat_rate, |
|
| 274 | - 'custom_meta' => $invoice->payment_meta, |
|
| 275 | - ); |
|
| 276 | - |
|
| 277 | - foreach ( $fields as $key => $val ) { |
|
| 278 | - if ( is_null( $val ) ) { |
|
| 279 | - $val = ''; |
|
| 280 | - } |
|
| 281 | - $val = maybe_serialize( $val ); |
|
| 282 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $fields = implode( ', ', $fields ); |
|
| 286 | - $invoice_rows[] = "($fields)"; |
|
| 287 | - |
|
| 288 | - $item_rows = array(); |
|
| 289 | - $item_columns = array(); |
|
| 290 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
| 291 | - $fields = array( |
|
| 292 | - 'post_id' => $invoice->ID, |
|
| 293 | - 'item_id' => $details['id'], |
|
| 294 | - 'item_name' => $details['name'], |
|
| 295 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
| 296 | - 'vat_rate' => $details['vat_rate'], |
|
| 297 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
| 298 | - 'tax' => $details['tax'], |
|
| 299 | - 'item_price' => $details['item_price'], |
|
| 300 | - 'custom_price' => $details['custom_price'], |
|
| 301 | - 'quantity' => $details['quantity'], |
|
| 302 | - 'discount' => $details['discount'], |
|
| 303 | - 'subtotal' => $details['subtotal'], |
|
| 304 | - 'price' => $details['price'], |
|
| 305 | - 'meta' => $details['meta'], |
|
| 306 | - 'fees' => $details['fees'], |
|
| 307 | - ); |
|
| 308 | - |
|
| 309 | - $item_columns = array_keys( $fields ); |
|
| 310 | - |
|
| 311 | - foreach ( $fields as $key => $val ) { |
|
| 312 | - if ( is_null( $val ) ) { |
|
| 313 | - $val = ''; |
|
| 314 | - } |
|
| 315 | - $val = maybe_serialize( $val ); |
|
| 316 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $fields = implode( ', ', $fields ); |
|
| 320 | - $item_rows[] = "($fields)"; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - $item_rows = implode( ', ', $item_rows ); |
|
| 324 | - $item_columns = implode( ', ', $item_columns ); |
|
| 325 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - if ( empty( $invoice_rows ) ) { |
|
| 329 | - return; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
| 333 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
| 334 | - |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Migrates old invoices to new invoices. |
|
| 339 | - * |
|
| 340 | - */ |
|
| 341 | - public static function rename_gateways_label() { |
|
| 342 | - global $wpdb; |
|
| 343 | - |
|
| 344 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
| 345 | - |
|
| 346 | - $wpdb->update( |
|
| 347 | - $wpdb->prefix . 'getpaid_invoices', |
|
| 348 | - array( 'gateway' => $gateway ), |
|
| 349 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
| 350 | - '%s', |
|
| 351 | - '%s' |
|
| 352 | - ); |
|
| 353 | - |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Returns the DB schema. |
|
| 359 | - * |
|
| 360 | - */ |
|
| 361 | - public static function get_db_schema() { |
|
| 362 | - global $wpdb; |
|
| 363 | - |
|
| 364 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 365 | - |
|
| 366 | - $charset_collate = $wpdb->get_charset_collate(); |
|
| 367 | - |
|
| 368 | - // Subscriptions. |
|
| 369 | - $schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
| 186 | + 'parent' => '', |
|
| 187 | + ), |
|
| 188 | + |
|
| 189 | + ) |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Re-create GetPaid pages. |
|
| 196 | + * |
|
| 197 | + */ |
|
| 198 | + public function create_pages() { |
|
| 199 | + |
|
| 200 | + foreach ( self::get_pages() as $key => $page ) { |
|
| 201 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Migrates old invoices to new invoices. |
|
| 208 | + * |
|
| 209 | + */ |
|
| 210 | + public function migrate_old_invoices() { |
|
| 211 | + global $wpdb; |
|
| 212 | + |
|
| 213 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 214 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 215 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
| 216 | + $invoices = array_unique( |
|
| 217 | + get_posts( |
|
| 218 | + array( |
|
| 219 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
| 220 | + 'posts_per_page' => -1, |
|
| 221 | + 'fields' => 'ids', |
|
| 222 | + 'post_status' => array_keys( get_post_stati() ), |
|
| 223 | + 'exclude' => (array) $migrated, |
|
| 224 | + ) |
|
| 225 | + ) |
|
| 226 | + ); |
|
| 227 | + |
|
| 228 | + // Abort if we do not have any invoices. |
|
| 229 | + if ( empty( $invoices ) ) { |
|
| 230 | + return; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
| 234 | + |
|
| 235 | + $invoice_rows = array(); |
|
| 236 | + foreach ( $invoices as $invoice ) { |
|
| 237 | + |
|
| 238 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
| 239 | + |
|
| 240 | + if ( empty( $invoice->ID ) ) { |
|
| 241 | + return; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + $fields = array( |
|
| 245 | + 'post_id' => $invoice->ID, |
|
| 246 | + 'number' => $invoice->get_number(), |
|
| 247 | + 'key' => $invoice->get_key(), |
|
| 248 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
| 249 | + 'mode' => $invoice->mode, |
|
| 250 | + 'user_ip' => $invoice->get_ip(), |
|
| 251 | + 'first_name' => $invoice->get_first_name(), |
|
| 252 | + 'last_name' => $invoice->get_last_name(), |
|
| 253 | + 'address' => $invoice->get_address(), |
|
| 254 | + 'city' => $invoice->city, |
|
| 255 | + 'state' => $invoice->state, |
|
| 256 | + 'country' => $invoice->country, |
|
| 257 | + 'zip' => $invoice->zip, |
|
| 258 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
| 259 | + 'gateway' => $invoice->get_gateway(), |
|
| 260 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
| 261 | + 'currency' => $invoice->get_currency(), |
|
| 262 | + 'subtotal' => $invoice->get_subtotal(), |
|
| 263 | + 'tax' => $invoice->get_tax(), |
|
| 264 | + 'fees_total' => $invoice->get_fees_total(), |
|
| 265 | + 'total' => $invoice->get_total(), |
|
| 266 | + 'discount' => $invoice->get_discount(), |
|
| 267 | + 'discount_code' => $invoice->get_discount_code(), |
|
| 268 | + 'disable_taxes' => $invoice->disable_taxes, |
|
| 269 | + 'due_date' => $invoice->get_due_date(), |
|
| 270 | + 'completed_date' => $invoice->get_completed_date(), |
|
| 271 | + 'company' => $invoice->company, |
|
| 272 | + 'vat_number' => $invoice->vat_number, |
|
| 273 | + 'vat_rate' => $invoice->vat_rate, |
|
| 274 | + 'custom_meta' => $invoice->payment_meta, |
|
| 275 | + ); |
|
| 276 | + |
|
| 277 | + foreach ( $fields as $key => $val ) { |
|
| 278 | + if ( is_null( $val ) ) { |
|
| 279 | + $val = ''; |
|
| 280 | + } |
|
| 281 | + $val = maybe_serialize( $val ); |
|
| 282 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $fields = implode( ', ', $fields ); |
|
| 286 | + $invoice_rows[] = "($fields)"; |
|
| 287 | + |
|
| 288 | + $item_rows = array(); |
|
| 289 | + $item_columns = array(); |
|
| 290 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
| 291 | + $fields = array( |
|
| 292 | + 'post_id' => $invoice->ID, |
|
| 293 | + 'item_id' => $details['id'], |
|
| 294 | + 'item_name' => $details['name'], |
|
| 295 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
| 296 | + 'vat_rate' => $details['vat_rate'], |
|
| 297 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
| 298 | + 'tax' => $details['tax'], |
|
| 299 | + 'item_price' => $details['item_price'], |
|
| 300 | + 'custom_price' => $details['custom_price'], |
|
| 301 | + 'quantity' => $details['quantity'], |
|
| 302 | + 'discount' => $details['discount'], |
|
| 303 | + 'subtotal' => $details['subtotal'], |
|
| 304 | + 'price' => $details['price'], |
|
| 305 | + 'meta' => $details['meta'], |
|
| 306 | + 'fees' => $details['fees'], |
|
| 307 | + ); |
|
| 308 | + |
|
| 309 | + $item_columns = array_keys( $fields ); |
|
| 310 | + |
|
| 311 | + foreach ( $fields as $key => $val ) { |
|
| 312 | + if ( is_null( $val ) ) { |
|
| 313 | + $val = ''; |
|
| 314 | + } |
|
| 315 | + $val = maybe_serialize( $val ); |
|
| 316 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $fields = implode( ', ', $fields ); |
|
| 320 | + $item_rows[] = "($fields)"; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + $item_rows = implode( ', ', $item_rows ); |
|
| 324 | + $item_columns = implode( ', ', $item_columns ); |
|
| 325 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + if ( empty( $invoice_rows ) ) { |
|
| 329 | + return; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
| 333 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
| 334 | + |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Migrates old invoices to new invoices. |
|
| 339 | + * |
|
| 340 | + */ |
|
| 341 | + public static function rename_gateways_label() { |
|
| 342 | + global $wpdb; |
|
| 343 | + |
|
| 344 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
| 345 | + |
|
| 346 | + $wpdb->update( |
|
| 347 | + $wpdb->prefix . 'getpaid_invoices', |
|
| 348 | + array( 'gateway' => $gateway ), |
|
| 349 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
| 350 | + '%s', |
|
| 351 | + '%s' |
|
| 352 | + ); |
|
| 353 | + |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Returns the DB schema. |
|
| 359 | + * |
|
| 360 | + */ |
|
| 361 | + public static function get_db_schema() { |
|
| 362 | + global $wpdb; |
|
| 363 | + |
|
| 364 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 365 | + |
|
| 366 | + $charset_collate = $wpdb->get_charset_collate(); |
|
| 367 | + |
|
| 368 | + // Subscriptions. |
|
| 369 | + $schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
| 370 | 370 | id bigint(20) unsigned NOT NULL auto_increment, |
| 371 | 371 | customer_id bigint(20) NOT NULL, |
| 372 | 372 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -389,8 +389,8 @@ discard block |
||
| 389 | 389 | KEY customer_and_status (customer_id, status) |
| 390 | 390 | ) $charset_collate;"; |
| 391 | 391 | |
| 392 | - // Invoices. |
|
| 393 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
| 392 | + // Invoices. |
|
| 393 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
| 394 | 394 | post_id BIGINT(20) NOT NULL, |
| 395 | 395 | `number` VARCHAR(100), |
| 396 | 396 | `key` VARCHAR(100), |
@@ -426,8 +426,8 @@ discard block |
||
| 426 | 426 | KEY `key` (`key`) |
| 427 | 427 | ) $charset_collate;"; |
| 428 | 428 | |
| 429 | - // Invoice items. |
|
| 430 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
| 429 | + // Invoice items. |
|
| 430 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
| 431 | 431 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
| 432 | 432 | post_id BIGINT(20) NOT NULL, |
| 433 | 433 | item_id BIGINT(20) NOT NULL, |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | KEY post_id (post_id) |
| 450 | 450 | ) $charset_collate;"; |
| 451 | 451 | |
| 452 | - // Customers. |
|
| 453 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
| 452 | + // Customers. |
|
| 453 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
| 454 | 454 | id BIGINT(20) NOT NULL AUTO_INCREMENT, |
| 455 | 455 | user_id BIGINT(20) NOT NULL, |
| 456 | 456 | email VARCHAR(100) NOT NULL, |
@@ -460,38 +460,38 @@ discard block |
||
| 460 | 460 | purchase_count BIGINT(20) NOT NULL DEFAULT 0, |
| 461 | 461 | "; |
| 462 | 462 | |
| 463 | - // Add address fields. |
|
| 464 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
| 463 | + // Add address fields. |
|
| 464 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
| 465 | 465 | |
| 466 | - // Skip id, user_id and email. |
|
| 467 | - if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
| 468 | - continue; |
|
| 469 | - } |
|
| 466 | + // Skip id, user_id and email. |
|
| 467 | + if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
| 468 | + continue; |
|
| 469 | + } |
|
| 470 | 470 | |
| 471 | - $field = sanitize_key( $field ); |
|
| 472 | - $length = 100; |
|
| 473 | - $default = ''; |
|
| 471 | + $field = sanitize_key( $field ); |
|
| 472 | + $length = 100; |
|
| 473 | + $default = ''; |
|
| 474 | 474 | |
| 475 | - // Country. |
|
| 476 | - if ( 'country' === $field ) { |
|
| 477 | - $length = 2; |
|
| 478 | - $default = wpinv_get_default_country(); |
|
| 479 | - } |
|
| 475 | + // Country. |
|
| 476 | + if ( 'country' === $field ) { |
|
| 477 | + $length = 2; |
|
| 478 | + $default = wpinv_get_default_country(); |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - // State. |
|
| 482 | - if ( 'state' === $field ) { |
|
| 483 | - $default = wpinv_get_default_state(); |
|
| 484 | - } |
|
| 481 | + // State. |
|
| 482 | + if ( 'state' === $field ) { |
|
| 483 | + $default = wpinv_get_default_state(); |
|
| 484 | + } |
|
| 485 | 485 | |
| 486 | - // Phone, zip. |
|
| 487 | - if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
| 488 | - $length = 20; |
|
| 489 | - } |
|
| 486 | + // Phone, zip. |
|
| 487 | + if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
| 488 | + $length = 20; |
|
| 489 | + } |
|
| 490 | 490 | |
| 491 | - $schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',"; |
|
| 492 | - } |
|
| 491 | + $schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',"; |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | - $schema .= " |
|
| 494 | + $schema .= " |
|
| 495 | 495 | date_created DATETIME NOT NULL, |
| 496 | 496 | date_modified DATETIME NOT NULL, |
| 497 | 497 | uuid VARCHAR(100) NOT NULL, |
@@ -500,8 +500,8 @@ discard block |
||
| 500 | 500 | KEY email (email) |
| 501 | 501 | ) $charset_collate"; |
| 502 | 502 | |
| 503 | - // Customer meta. |
|
| 504 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
| 503 | + // Customer meta. |
|
| 504 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
| 505 | 505 | meta_id BIGINT(20) NOT NULL AUTO_INCREMENT, |
| 506 | 506 | customer_id BIGINT(20) NOT NULL, |
| 507 | 507 | meta_key VARCHAR(255) NOT NULL, |
@@ -511,41 +511,41 @@ discard block |
||
| 511 | 511 | KEY meta_key (meta_key(191)) |
| 512 | 512 | ) $charset_collate"; |
| 513 | 513 | |
| 514 | - return $schema; |
|
| 515 | - } |
|
| 514 | + return $schema; |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | - /** |
|
| 518 | - * Checks if the db schema is up to date. |
|
| 519 | - * |
|
| 520 | - * @return bool |
|
| 521 | - */ |
|
| 522 | - public static function is_db_schema_up_to_date() { |
|
| 523 | - return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' ); |
|
| 524 | - } |
|
| 517 | + /** |
|
| 518 | + * Checks if the db schema is up to date. |
|
| 519 | + * |
|
| 520 | + * @return bool |
|
| 521 | + */ |
|
| 522 | + public static function is_db_schema_up_to_date() { |
|
| 523 | + return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' ); |
|
| 524 | + } |
|
| 525 | 525 | |
| 526 | - /** |
|
| 527 | - * Set up the database tables which the plugin needs to function. |
|
| 528 | - */ |
|
| 529 | - public static function create_db_tables() { |
|
| 530 | - global $wpdb; |
|
| 526 | + /** |
|
| 527 | + * Set up the database tables which the plugin needs to function. |
|
| 528 | + */ |
|
| 529 | + public static function create_db_tables() { |
|
| 530 | + global $wpdb; |
|
| 531 | 531 | |
| 532 | - $wpdb->hide_errors(); |
|
| 532 | + $wpdb->hide_errors(); |
|
| 533 | 533 | |
| 534 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 534 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 535 | 535 | |
| 536 | - $schema = self::get_db_schema(); |
|
| 536 | + $schema = self::get_db_schema(); |
|
| 537 | 537 | |
| 538 | - dbDelta( $schema ); |
|
| 538 | + dbDelta( $schema ); |
|
| 539 | 539 | |
| 540 | - update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) ); |
|
| 541 | - } |
|
| 540 | + update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) ); |
|
| 541 | + } |
|
| 542 | 542 | |
| 543 | - /** |
|
| 544 | - * Creates tables if schema is not up to date. |
|
| 545 | - */ |
|
| 546 | - public static function maybe_create_db_tables() { |
|
| 547 | - if ( ! self::is_db_schema_up_to_date() ) { |
|
| 548 | - self::create_db_tables(); |
|
| 549 | - } |
|
| 550 | - } |
|
| 543 | + /** |
|
| 544 | + * Creates tables if schema is not up to date. |
|
| 545 | + */ |
|
| 546 | + public static function maybe_create_db_tables() { |
|
| 547 | + if ( ! self::is_db_schema_up_to_date() ) { |
|
| 548 | + self::create_db_tables(); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | 551 | } |
@@ -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. |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @param string $upgrade_from The current invoicing version. |
| 27 | 27 | */ |
| 28 | - public function upgrade_db( $upgrade_from ) { |
|
| 28 | + public function upgrade_db($upgrade_from) { |
|
| 29 | 29 | |
| 30 | 30 | // Save the current invoicing version. |
| 31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
| 31 | + update_option('wpinv_version', WPINV_VERSION); |
|
| 32 | 32 | |
| 33 | 33 | // Setup the invoice Custom Post Type. |
| 34 | 34 | GetPaid_Post_Types::register_post_types(); |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | // Create any missing database tables. |
| 49 | 49 | $method = "upgrade_from_$upgrade_from"; |
| 50 | 50 | |
| 51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
| 51 | + $installed = get_option('gepaid_installed_on'); |
|
| 52 | 52 | |
| 53 | - if ( empty( $installed ) ) { |
|
| 54 | - update_option( 'gepaid_installed_on', time() ); |
|
| 53 | + if (empty($installed)) { |
|
| 54 | + update_option('gepaid_installed_on', time()); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ( method_exists( $this, $method ) ) { |
|
| 57 | + if (method_exists($this, $method)) { |
|
| 58 | 58 | $this->$method(); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | public function upgrade_from_0() { |
| 68 | 68 | |
| 69 | 69 | // Save default tax rates. |
| 70 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 70 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -78,27 +78,27 @@ discard block |
||
| 78 | 78 | global $wpdb; |
| 79 | 79 | |
| 80 | 80 | // Invoices. |
| 81 | - $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' )" ); |
|
| 82 | - if ( ! empty( $results ) ) { |
|
| 83 | - $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' )" ); |
|
| 81 | + $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' )"); |
|
| 82 | + if (!empty($results)) { |
|
| 83 | + $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' )"); |
|
| 84 | 84 | |
| 85 | 85 | // Clean post cache |
| 86 | - foreach ( $results as $row ) { |
|
| 87 | - clean_post_cache( $row->ID ); |
|
| 86 | + foreach ($results as $row) { |
|
| 87 | + clean_post_cache($row->ID); |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // Item meta key changes |
| 92 | 92 | $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' )"; |
| 93 | - $results = $wpdb->get_results( $query ); |
|
| 93 | + $results = $wpdb->get_results($query); |
|
| 94 | 94 | |
| 95 | - if ( ! empty( $results ) ) { |
|
| 96 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
| 97 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
| 98 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
| 95 | + if (!empty($results)) { |
|
| 96 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
| 97 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
| 98 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
| 99 | 99 | |
| 100 | - foreach ( $results as $row ) { |
|
| 101 | - clean_post_cache( $row->post_id ); |
|
| 100 | + foreach ($results as $row) { |
|
| 101 | + clean_post_cache($row->post_id); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | */ |
| 119 | 119 | public function add_capabilities() { |
| 120 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
| 120 | + $GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing'); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | // Checkout page. |
| 134 | 134 | 'checkout_page' => array( |
| 135 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
| 136 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
| 135 | + 'name' => _x('gp-checkout', 'Page slug', 'invoicing'), |
|
| 136 | + 'title' => _x('Checkout', 'Page title', 'invoicing'), |
|
| 137 | 137 | 'content' => ' |
| 138 | 138 | <!-- wp:shortcode --> |
| 139 | 139 | [wpinv_checkout] |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | // Invoice history page. |
| 146 | 146 | 'invoice_history_page' => array( |
| 147 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
| 148 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
| 147 | + 'name' => _x('gp-invoices', 'Page slug', 'invoicing'), |
|
| 148 | + 'title' => _x('My Invoices', 'Page title', 'invoicing'), |
|
| 149 | 149 | 'content' => ' |
| 150 | 150 | <!-- wp:shortcode --> |
| 151 | 151 | [wpinv_history] |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | // Success page content. |
| 158 | 158 | 'success_page' => array( |
| 159 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
| 160 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
| 159 | + 'name' => _x('gp-receipt', 'Page slug', 'invoicing'), |
|
| 160 | + 'title' => _x('Payment Confirmation', 'Page title', 'invoicing'), |
|
| 161 | 161 | 'content' => ' |
| 162 | 162 | <!-- wp:shortcode --> |
| 163 | 163 | [wpinv_receipt] |
@@ -168,16 +168,16 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // Failure page content. |
| 170 | 170 | 'failure_page' => array( |
| 171 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
| 172 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
| 173 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
| 171 | + 'name' => _x('gp-transaction-failed', 'Page slug', 'invoicing'), |
|
| 172 | + 'title' => _x('Transaction Failed', 'Page title', 'invoicing'), |
|
| 173 | + 'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'), |
|
| 174 | 174 | 'parent' => 'gp-checkout', |
| 175 | 175 | ), |
| 176 | 176 | |
| 177 | 177 | // Subscriptions history page. |
| 178 | 178 | 'invoice_subscription_page' => array( |
| 179 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
| 180 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
| 179 | + 'name' => _x('gp-subscriptions', 'Page slug', 'invoicing'), |
|
| 180 | + 'title' => _x('My Subscriptions', 'Page title', 'invoicing'), |
|
| 181 | 181 | 'content' => ' |
| 182 | 182 | <!-- wp:shortcode --> |
| 183 | 183 | [wpinv_subscriptions] |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public function create_pages() { |
| 199 | 199 | |
| 200 | - foreach ( self::get_pages() as $key => $page ) { |
|
| 201 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
| 200 | + foreach (self::get_pages() as $key => $page) { |
|
| 201 | + wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | } |
@@ -212,32 +212,32 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
| 214 | 214 | $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
| 215 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
| 215 | + $migrated = $wpdb->get_col("SELECT post_id FROM $invoices_table"); |
|
| 216 | 216 | $invoices = array_unique( |
| 217 | 217 | get_posts( |
| 218 | 218 | array( |
| 219 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
| 219 | + 'post_type' => array('wpi_invoice', 'wpi_quote'), |
|
| 220 | 220 | 'posts_per_page' => -1, |
| 221 | 221 | 'fields' => 'ids', |
| 222 | - 'post_status' => array_keys( get_post_stati() ), |
|
| 222 | + 'post_status' => array_keys(get_post_stati()), |
|
| 223 | 223 | 'exclude' => (array) $migrated, |
| 224 | 224 | ) |
| 225 | 225 | ) |
| 226 | 226 | ); |
| 227 | 227 | |
| 228 | 228 | // Abort if we do not have any invoices. |
| 229 | - if ( empty( $invoices ) ) { |
|
| 229 | + if (empty($invoices)) { |
|
| 230 | 230 | return; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
| 234 | 234 | |
| 235 | 235 | $invoice_rows = array(); |
| 236 | - foreach ( $invoices as $invoice ) { |
|
| 236 | + foreach ($invoices as $invoice) { |
|
| 237 | 237 | |
| 238 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
| 238 | + $invoice = new WPInv_Legacy_Invoice($invoice); |
|
| 239 | 239 | |
| 240 | - if ( empty( $invoice->ID ) ) { |
|
| 240 | + if (empty($invoice->ID)) { |
|
| 241 | 241 | return; |
| 242 | 242 | } |
| 243 | 243 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | 'post_id' => $invoice->ID, |
| 246 | 246 | 'number' => $invoice->get_number(), |
| 247 | 247 | 'key' => $invoice->get_key(), |
| 248 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
| 248 | + 'type' => str_replace('wpi_', '', $invoice->post_type), |
|
| 249 | 249 | 'mode' => $invoice->mode, |
| 250 | 250 | 'user_ip' => $invoice->get_ip(), |
| 251 | 251 | 'first_name' => $invoice->get_first_name(), |
@@ -274,27 +274,27 @@ discard block |
||
| 274 | 274 | 'custom_meta' => $invoice->payment_meta, |
| 275 | 275 | ); |
| 276 | 276 | |
| 277 | - foreach ( $fields as $key => $val ) { |
|
| 278 | - if ( is_null( $val ) ) { |
|
| 277 | + foreach ($fields as $key => $val) { |
|
| 278 | + if (is_null($val)) { |
|
| 279 | 279 | $val = ''; |
| 280 | 280 | } |
| 281 | - $val = maybe_serialize( $val ); |
|
| 282 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 281 | + $val = maybe_serialize($val); |
|
| 282 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - $fields = implode( ', ', $fields ); |
|
| 285 | + $fields = implode(', ', $fields); |
|
| 286 | 286 | $invoice_rows[] = "($fields)"; |
| 287 | 287 | |
| 288 | 288 | $item_rows = array(); |
| 289 | 289 | $item_columns = array(); |
| 290 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
| 290 | + foreach ($invoice->get_cart_details() as $details) { |
|
| 291 | 291 | $fields = array( |
| 292 | 292 | 'post_id' => $invoice->ID, |
| 293 | 293 | 'item_id' => $details['id'], |
| 294 | 294 | 'item_name' => $details['name'], |
| 295 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
| 295 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
| 296 | 296 | 'vat_rate' => $details['vat_rate'], |
| 297 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
| 297 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
| 298 | 298 | 'tax' => $details['tax'], |
| 299 | 299 | 'item_price' => $details['item_price'], |
| 300 | 300 | 'custom_price' => $details['custom_price'], |
@@ -306,31 +306,31 @@ discard block |
||
| 306 | 306 | 'fees' => $details['fees'], |
| 307 | 307 | ); |
| 308 | 308 | |
| 309 | - $item_columns = array_keys( $fields ); |
|
| 309 | + $item_columns = array_keys($fields); |
|
| 310 | 310 | |
| 311 | - foreach ( $fields as $key => $val ) { |
|
| 312 | - if ( is_null( $val ) ) { |
|
| 311 | + foreach ($fields as $key => $val) { |
|
| 312 | + if (is_null($val)) { |
|
| 313 | 313 | $val = ''; |
| 314 | 314 | } |
| 315 | - $val = maybe_serialize( $val ); |
|
| 316 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 315 | + $val = maybe_serialize($val); |
|
| 316 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - $fields = implode( ', ', $fields ); |
|
| 319 | + $fields = implode(', ', $fields); |
|
| 320 | 320 | $item_rows[] = "($fields)"; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - $item_rows = implode( ', ', $item_rows ); |
|
| 324 | - $item_columns = implode( ', ', $item_columns ); |
|
| 325 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
| 323 | + $item_rows = implode(', ', $item_rows); |
|
| 324 | + $item_columns = implode(', ', $item_columns); |
|
| 325 | + $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows"); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - if ( empty( $invoice_rows ) ) { |
|
| 328 | + if (empty($invoice_rows)) { |
|
| 329 | 329 | return; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
| 333 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
| 332 | + $invoice_rows = implode(', ', $invoice_rows); |
|
| 333 | + $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows"); |
|
| 334 | 334 | |
| 335 | 335 | } |
| 336 | 336 | |
@@ -341,12 +341,12 @@ discard block |
||
| 341 | 341 | public static function rename_gateways_label() { |
| 342 | 342 | global $wpdb; |
| 343 | 343 | |
| 344 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
| 344 | + foreach (array_keys(wpinv_get_payment_gateways()) as $gateway) { |
|
| 345 | 345 | |
| 346 | 346 | $wpdb->update( |
| 347 | 347 | $wpdb->prefix . 'getpaid_invoices', |
| 348 | - array( 'gateway' => $gateway ), |
|
| 349 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
| 348 | + array('gateway' => $gateway), |
|
| 349 | + array('gateway' => wpinv_get_gateway_admin_label($gateway)), |
|
| 350 | 350 | '%s', |
| 351 | 351 | '%s' |
| 352 | 352 | ); |
@@ -461,30 +461,30 @@ discard block |
||
| 461 | 461 | "; |
| 462 | 462 | |
| 463 | 463 | // Add address fields. |
| 464 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
| 464 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
| 465 | 465 | |
| 466 | 466 | // Skip id, user_id and email. |
| 467 | - if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
| 467 | + if (in_array($field, array('id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid'), true)) { |
|
| 468 | 468 | continue; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - $field = sanitize_key( $field ); |
|
| 471 | + $field = sanitize_key($field); |
|
| 472 | 472 | $length = 100; |
| 473 | 473 | $default = ''; |
| 474 | 474 | |
| 475 | 475 | // Country. |
| 476 | - if ( 'country' === $field ) { |
|
| 476 | + if ('country' === $field) { |
|
| 477 | 477 | $length = 2; |
| 478 | 478 | $default = wpinv_get_default_country(); |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | // State. |
| 482 | - if ( 'state' === $field ) { |
|
| 482 | + if ('state' === $field) { |
|
| 483 | 483 | $default = wpinv_get_default_state(); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | // Phone, zip. |
| 487 | - if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
| 487 | + if (in_array($field, array('phone', 'zip'), true)) { |
|
| 488 | 488 | $length = 20; |
| 489 | 489 | } |
| 490 | 490 | |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | * @return bool |
| 521 | 521 | */ |
| 522 | 522 | public static function is_db_schema_up_to_date() { |
| 523 | - return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' ); |
|
| 523 | + return md5(self::get_db_schema()) === get_option('getpaid_db_schema'); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -535,16 +535,16 @@ discard block |
||
| 535 | 535 | |
| 536 | 536 | $schema = self::get_db_schema(); |
| 537 | 537 | |
| 538 | - dbDelta( $schema ); |
|
| 538 | + dbDelta($schema); |
|
| 539 | 539 | |
| 540 | - update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) ); |
|
| 540 | + update_option('getpaid_db_schema', md5(self::get_db_schema())); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
| 544 | 544 | * Creates tables if schema is not up to date. |
| 545 | 545 | */ |
| 546 | 546 | public static function maybe_create_db_tables() { |
| 547 | - if ( ! self::is_db_schema_up_to_date() ) { |
|
| 547 | + if (!self::is_db_schema_up_to_date()) { |
|
| 548 | 548 | self::create_db_tables(); |
| 549 | 549 | } |
| 550 | 550 | } |
@@ -14,93 +14,93 @@ discard block |
||
| 14 | 14 | class GetPaid_Admin { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Local path to this plugins admin directory |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $admin_path; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Web path to this plugins admin directory |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - public $admin_url; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Reports components. |
|
| 32 | - * |
|
| 33 | - * @var GetPaid_Reports |
|
| 34 | - */ |
|
| 17 | + * Local path to this plugins admin directory |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $admin_path; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Web path to this plugins admin directory |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + public $admin_url; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Reports components. |
|
| 32 | + * |
|
| 33 | + * @var GetPaid_Reports |
|
| 34 | + */ |
|
| 35 | 35 | public $reports; |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * Class constructor. |
|
| 39 | - */ |
|
| 40 | - public function __construct() { |
|
| 38 | + * Class constructor. |
|
| 39 | + */ |
|
| 40 | + public function __construct() { |
|
| 41 | 41 | |
| 42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
| 43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | - $this->reports = new GetPaid_Reports(); |
|
| 43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | + $this->reports = new GetPaid_Reports(); |
|
| 45 | 45 | |
| 46 | 46 | if ( is_admin() ) { |
| 47 | - $this->init_admin_hooks(); |
|
| 47 | + $this->init_admin_hooks(); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * Init action and filter hooks |
|
| 54 | - * |
|
| 55 | - */ |
|
| 56 | - private function init_admin_hooks() { |
|
| 53 | + * Init action and filter hooks |
|
| 54 | + * |
|
| 55 | + */ |
|
| 56 | + private function init_admin_hooks() { |
|
| 57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
| 58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
| 60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
| 61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
| 62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
| 65 | - add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
| 66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
| 67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
| 65 | + add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
| 66 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
| 67 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 68 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 69 | 69 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
| 70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 71 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
| 72 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 73 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 74 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
| 75 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 76 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
| 77 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
| 78 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 79 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 80 | - |
|
| 81 | - // Setup/welcome |
|
| 82 | - if ( ! empty( $_GET['page'] ) ) { |
|
| 83 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
| 84 | - case 'gp-setup': |
|
| 85 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
| 86 | - break; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Register admin scripts |
|
| 94 | - * |
|
| 95 | - */ |
|
| 96 | - public function enqeue_scripts() { |
|
| 70 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 71 | + add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
| 72 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 73 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 74 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
| 75 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 76 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
| 77 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
| 78 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 79 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 80 | + |
|
| 81 | + // Setup/welcome |
|
| 82 | + if ( ! empty( $_GET['page'] ) ) { |
|
| 83 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
| 84 | + case 'gp-setup': |
|
| 85 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
| 86 | + break; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Register admin scripts |
|
| 94 | + * |
|
| 95 | + */ |
|
| 96 | + public function enqeue_scripts() { |
|
| 97 | 97 | global $current_screen, $pagenow; |
| 98 | 98 | |
| 99 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 100 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 99 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 100 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 101 | 101 | |
| 102 | 102 | if ( ! empty( $current_screen->post_type ) ) { |
| 103 | - $page = $current_screen->post_type; |
|
| 103 | + $page = $current_screen->post_type; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // General styles. |
@@ -121,53 +121,53 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // Payment form scripts. |
| 124 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 124 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 125 | 125 | $this->load_payment_form_scripts(); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 129 | - wp_enqueue_script( 'postbox' ); |
|
| 130 | - } |
|
| 128 | + if ( $page == 'wpinv-subscriptions' ) { |
|
| 129 | + wp_enqueue_script( 'postbox' ); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | - * Returns admin js translations. |
|
| 136 | - * |
|
| 137 | - */ |
|
| 138 | - protected function get_admin_i18() { |
|
| 135 | + * Returns admin js translations. |
|
| 136 | + * |
|
| 137 | + */ |
|
| 138 | + protected function get_admin_i18() { |
|
| 139 | 139 | global $post; |
| 140 | 140 | |
| 141 | - $date_range = array( |
|
| 142 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
| 143 | - ); |
|
| 141 | + $date_range = array( |
|
| 142 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
| 143 | + ); |
|
| 144 | 144 | |
| 145 | - if ( $date_range['period'] == 'custom' ) { |
|
| 145 | + if ( $date_range['period'] == 'custom' ) { |
|
| 146 | 146 | |
| 147 | - if ( isset( $_GET['from'] ) ) { |
|
| 148 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 149 | - } |
|
| 147 | + if ( isset( $_GET['from'] ) ) { |
|
| 148 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - if ( isset( $_GET['to'] ) ) { |
|
| 152 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 153 | - } |
|
| 151 | + if ( isset( $_GET['to'] ) ) { |
|
| 152 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $i18n = array( |
| 157 | 157 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 158 | 158 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
| 159 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 160 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 161 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
| 162 | - 'date_range' => $date_range, |
|
| 159 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 160 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 161 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
| 162 | + 'date_range' => $date_range, |
|
| 163 | 163 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
| 164 | 164 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
| 165 | 165 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
| 166 | 166 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
| 167 | 167 | 'tax' => wpinv_tax_amount(), |
| 168 | 168 | 'discount' => 0, |
| 169 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
| 170 | - 'currency' => wpinv_get_currency(), |
|
| 169 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
| 170 | + 'currency' => wpinv_get_currency(), |
|
| 171 | 171 | 'currency_pos' => wpinv_currency_position(), |
| 172 | 172 | 'thousand_sep' => wpinv_thousands_separator(), |
| 173 | 173 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -187,118 +187,118 @@ discard block |
||
| 187 | 187 | 'item_description' => __( 'Item Description', 'invoicing' ), |
| 188 | 188 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
| 189 | 189 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
| 190 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
| 191 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 192 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 193 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
| 194 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
| 190 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
| 191 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 192 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 193 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
| 194 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
| 195 | 195 | ); |
| 196 | 196 | |
| 197 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 197 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 198 | 198 | |
| 199 | - $invoice = new WPInv_Invoice( $post ); |
|
| 200 | - $i18n['save_invoice'] = sprintf( |
|
| 201 | - __( 'Save %s', 'invoicing' ), |
|
| 202 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 203 | - ); |
|
| 199 | + $invoice = new WPInv_Invoice( $post ); |
|
| 200 | + $i18n['save_invoice'] = sprintf( |
|
| 201 | + __( 'Save %s', 'invoicing' ), |
|
| 202 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 203 | + ); |
|
| 204 | 204 | |
| 205 | - $i18n['invoice_description'] = sprintf( |
|
| 206 | - __( '%s Description', 'invoicing' ), |
|
| 207 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 208 | - ); |
|
| 205 | + $i18n['invoice_description'] = sprintf( |
|
| 206 | + __( '%s Description', 'invoicing' ), |
|
| 207 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 208 | + ); |
|
| 209 | 209 | |
| 210 | - } |
|
| 211 | - return $i18n; |
|
| 212 | - } |
|
| 210 | + } |
|
| 211 | + return $i18n; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Change the admin footer text on GetPaid admin pages. |
|
| 216 | - * |
|
| 217 | - * @since 2.0.0 |
|
| 218 | - * @param string $footer_text |
|
| 219 | - * @return string |
|
| 220 | - */ |
|
| 221 | - public function admin_footer_text( $footer_text ) { |
|
| 222 | - global $current_screen; |
|
| 214 | + /** |
|
| 215 | + * Change the admin footer text on GetPaid admin pages. |
|
| 216 | + * |
|
| 217 | + * @since 2.0.0 |
|
| 218 | + * @param string $footer_text |
|
| 219 | + * @return string |
|
| 220 | + */ |
|
| 221 | + public function admin_footer_text( $footer_text ) { |
|
| 222 | + global $current_screen; |
|
| 223 | 223 | |
| 224 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 224 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 225 | 225 | |
| 226 | 226 | if ( ! empty( $current_screen->post_type ) ) { |
| 227 | - $page = $current_screen->post_type; |
|
| 227 | + $page = $current_screen->post_type; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // General styles. |
| 231 | 231 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
| 232 | 232 | |
| 233 | - // Change the footer text |
|
| 234 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 233 | + // Change the footer text |
|
| 234 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 235 | 235 | |
| 236 | - $rating_url = esc_url( |
|
| 237 | - wp_nonce_url( |
|
| 238 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 239 | - 'getpaid-nonce', |
|
| 240 | - 'getpaid-nonce' |
|
| 236 | + $rating_url = esc_url( |
|
| 237 | + wp_nonce_url( |
|
| 238 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 239 | + 'getpaid-nonce', |
|
| 240 | + 'getpaid-nonce' |
|
| 241 | 241 | ) |
| 242 | - ); |
|
| 242 | + ); |
|
| 243 | 243 | |
| 244 | - $footer_text = sprintf( |
|
| 245 | - /* translators: %s: five stars */ |
|
| 246 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 247 | - "<a href='$rating_url'>★★★★★</a>" |
|
| 248 | - ); |
|
| 244 | + $footer_text = sprintf( |
|
| 245 | + /* translators: %s: five stars */ |
|
| 246 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 247 | + "<a href='$rating_url'>★★★★★</a>" |
|
| 248 | + ); |
|
| 249 | 249 | |
| 250 | - } else { |
|
| 250 | + } else { |
|
| 251 | 251 | |
| 252 | - $footer_text = sprintf( |
|
| 253 | - /* translators: %s: GetPaid */ |
|
| 254 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
| 255 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 256 | - ); |
|
| 252 | + $footer_text = sprintf( |
|
| 253 | + /* translators: %s: GetPaid */ |
|
| 254 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
| 255 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 256 | + ); |
|
| 257 | 257 | |
| 258 | - } |
|
| 258 | + } |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - return $footer_text; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Redirects to wp.org to rate the plugin. |
|
| 266 | - * |
|
| 267 | - * @since 2.0.0 |
|
| 268 | - */ |
|
| 269 | - public function redirect_to_wordpress_rating_page() { |
|
| 270 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 271 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 272 | - exit; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Loads payment form js. |
|
| 277 | - * |
|
| 278 | - */ |
|
| 279 | - protected function load_payment_form_scripts() { |
|
| 261 | + return $footer_text; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Redirects to wp.org to rate the plugin. |
|
| 266 | + * |
|
| 267 | + * @since 2.0.0 |
|
| 268 | + */ |
|
| 269 | + public function redirect_to_wordpress_rating_page() { |
|
| 270 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 271 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 272 | + exit; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Loads payment form js. |
|
| 277 | + * |
|
| 278 | + */ |
|
| 279 | + protected function load_payment_form_scripts() { |
|
| 280 | 280 | global $post; |
| 281 | 281 | |
| 282 | 282 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
| 283 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 284 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 283 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 284 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 285 | 285 | |
| 286 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
| 286 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 287 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
| 288 | 288 | |
| 289 | - wp_localize_script( |
|
| 289 | + wp_localize_script( |
|
| 290 | 290 | 'wpinv-admin-payment-form-script', |
| 291 | 291 | 'wpinvPaymentFormAdmin', |
| 292 | 292 | array( |
| 293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 295 | - 'currency' => wpinv_currency_symbol(), |
|
| 296 | - 'position' => wpinv_currency_position(), |
|
| 297 | - 'decimals' => (int) wpinv_decimals(), |
|
| 298 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
| 299 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
| 300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 301 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 293 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 294 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 295 | + 'currency' => wpinv_currency_symbol(), |
|
| 296 | + 'position' => wpinv_currency_position(), |
|
| 297 | + 'decimals' => (int) wpinv_decimals(), |
|
| 298 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
| 299 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
| 300 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 301 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 302 | 302 | ) |
| 303 | 303 | ); |
| 304 | 304 | |
@@ -307,19 +307,19 @@ discard block |
||
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
| 310 | - * Add our classes to admin pages. |
|
| 310 | + * Add our classes to admin pages. |
|
| 311 | 311 | * |
| 312 | 312 | * @param string $classes |
| 313 | 313 | * @return string |
| 314 | - * |
|
| 315 | - */ |
|
| 314 | + * |
|
| 315 | + */ |
|
| 316 | 316 | public function admin_body_class( $classes ) { |
| 317 | - global $pagenow, $post, $current_screen; |
|
| 317 | + global $pagenow, $post, $current_screen; |
|
| 318 | 318 | |
| 319 | 319 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
| 320 | 320 | |
| 321 | 321 | if ( ! empty( $current_screen->post_type ) ) { |
| 322 | - $page = $current_screen->post_type; |
|
| 322 | + $page = $current_screen->post_type; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -328,70 +328,70 @@ discard block |
||
| 328 | 328 | |
| 329 | 329 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
| 330 | 330 | $classes .= ' wpinv-cpt wpinv'; |
| 331 | - } |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 333 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 334 | 334 | $classes .= ' getpaid-is-invoice-cpt'; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - return $classes; |
|
| 337 | + return $classes; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
| 341 | - * Maybe show the AyeCode Connect Notice. |
|
| 342 | - */ |
|
| 343 | - public function init_ayecode_connect_helper() { |
|
| 341 | + * Maybe show the AyeCode Connect Notice. |
|
| 342 | + */ |
|
| 343 | + public function init_ayecode_connect_helper() { |
|
| 344 | 344 | |
| 345 | - // Register with the deactivation survey class. |
|
| 346 | - AyeCode_Deactivation_Survey::instance( |
|
| 345 | + // Register with the deactivation survey class. |
|
| 346 | + AyeCode_Deactivation_Survey::instance( |
|
| 347 | 347 | array( |
| 348 | - 'slug' => 'invoicing', |
|
| 349 | - 'version' => WPINV_VERSION, |
|
| 350 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
| 351 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
| 352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
| 348 | + 'slug' => 'invoicing', |
|
| 349 | + 'version' => WPINV_VERSION, |
|
| 350 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
| 351 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
| 352 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
| 353 | 353 | ) |
| 354 | 354 | ); |
| 355 | 355 | |
| 356 | 356 | new AyeCode_Connect_Helper( |
| 357 | 357 | array( |
| 358 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
| 359 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
| 360 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
| 361 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
| 362 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
| 363 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
| 364 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
| 358 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
| 359 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
| 360 | + 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
| 361 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
| 362 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
| 363 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
| 364 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
| 365 | 365 | ), |
| 366 | 366 | array( 'wpi-addons' ) |
| 367 | 367 | ); |
| 368 | 368 | |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - /** |
|
| 372 | - * Redirect users to settings on activation. |
|
| 373 | - * |
|
| 374 | - * @return void |
|
| 375 | - */ |
|
| 376 | - public function activation_redirect() { |
|
| 371 | + /** |
|
| 372 | + * Redirect users to settings on activation. |
|
| 373 | + * |
|
| 374 | + * @return void |
|
| 375 | + */ |
|
| 376 | + public function activation_redirect() { |
|
| 377 | 377 | |
| 378 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 378 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 379 | 379 | |
| 380 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 381 | - return; |
|
| 382 | - } |
|
| 380 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 381 | + return; |
|
| 382 | + } |
|
| 383 | 383 | |
| 384 | - // Bail if activating from network, or bulk |
|
| 385 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 386 | - return; |
|
| 387 | - } |
|
| 384 | + // Bail if activating from network, or bulk |
|
| 385 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 386 | + return; |
|
| 387 | + } |
|
| 388 | 388 | |
| 389 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 389 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 390 | 390 | |
| 391 | 391 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
| 392 | 392 | exit; |
| 393 | 393 | |
| 394 | - } |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | 396 | /** |
| 397 | 397 | * Fires an admin action after verifying that a user can fire them. |
@@ -404,543 +404,543 @@ discard block |
||
| 404 | 404 | } |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - /** |
|
| 407 | + /** |
|
| 408 | 408 | * Duplicate invoice. |
| 409 | - * |
|
| 410 | - * @param array $args |
|
| 409 | + * |
|
| 410 | + * @param array $args |
|
| 411 | 411 | */ |
| 412 | 412 | public function duplicate_invoice( $args ) { |
| 413 | 413 | |
| 414 | - if ( empty( $args['invoice_id'] ) ) { |
|
| 415 | - return; |
|
| 416 | - } |
|
| 414 | + if ( empty( $args['invoice_id'] ) ) { |
|
| 415 | + return; |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
| 418 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
| 419 | 419 | |
| 420 | - if ( ! $invoice->exists() ) { |
|
| 421 | - return; |
|
| 422 | - } |
|
| 420 | + if ( ! $invoice->exists() ) { |
|
| 421 | + return; |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
| 425 | - $new_invoice->save(); |
|
| 424 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
| 425 | + $new_invoice->save(); |
|
| 426 | 426 | |
| 427 | - if ( $new_invoice->exists() ) { |
|
| 427 | + if ( $new_invoice->exists() ) { |
|
| 428 | 428 | |
| 429 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
| 429 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
| 430 | 430 | |
| 431 | - wp_safe_redirect( |
|
| 432 | - add_query_arg( |
|
| 433 | - array( |
|
| 434 | - 'action' => 'edit', |
|
| 435 | - 'post' => $new_invoice->get_id(), |
|
| 436 | - ), |
|
| 437 | - admin_url( 'post.php' ) |
|
| 438 | - ) |
|
| 439 | - ); |
|
| 440 | - exit; |
|
| 431 | + wp_safe_redirect( |
|
| 432 | + add_query_arg( |
|
| 433 | + array( |
|
| 434 | + 'action' => 'edit', |
|
| 435 | + 'post' => $new_invoice->get_id(), |
|
| 436 | + ), |
|
| 437 | + admin_url( 'post.php' ) |
|
| 438 | + ) |
|
| 439 | + ); |
|
| 440 | + exit; |
|
| 441 | 441 | |
| 442 | - } |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
| 444 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
| 445 | 445 | |
| 446 | - } |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - /** |
|
| 448 | + /** |
|
| 449 | 449 | * Sends a payment reminder to a customer. |
| 450 | - * |
|
| 451 | - * @param array $args |
|
| 450 | + * |
|
| 451 | + * @param array $args |
|
| 452 | 452 | */ |
| 453 | 453 | public function duplicate_payment_form( $args ) { |
| 454 | 454 | |
| 455 | - if ( empty( $args['form_id'] ) ) { |
|
| 456 | - return; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 455 | + if ( empty( $args['form_id'] ) ) { |
|
| 456 | + return; |
|
| 457 | + } |
|
| 460 | 458 | |
| 461 | - if ( ! $form->exists() ) { |
|
| 462 | - return; |
|
| 463 | - } |
|
| 459 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 464 | 460 | |
| 465 | - $new_form = new GetPaid_Payment_Form(); |
|
| 466 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
| 467 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
| 468 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
| 469 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
| 470 | - $new_form->save(); |
|
| 461 | + if ( ! $form->exists() ) { |
|
| 462 | + return; |
|
| 463 | + } |
|
| 471 | 464 | |
| 472 | - if ( $new_form->exists() ) { |
|
| 473 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
| 474 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
| 475 | - } else { |
|
| 476 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
| 477 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
| 478 | - } |
|
| 465 | + $new_form = new GetPaid_Payment_Form(); |
|
| 466 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
| 467 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
| 468 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
| 469 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
| 470 | + $new_form->save(); |
|
| 471 | + |
|
| 472 | + if ( $new_form->exists() ) { |
|
| 473 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
| 474 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
| 475 | + } else { |
|
| 476 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
| 477 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - wp_redirect( $url ); |
|
| 481 | - exit; |
|
| 482 | - } |
|
| 480 | + wp_redirect( $url ); |
|
| 481 | + exit; |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | - /** |
|
| 484 | + /** |
|
| 485 | 485 | * Resets form stats. |
| 486 | - * |
|
| 487 | - * @param array $args |
|
| 486 | + * |
|
| 487 | + * @param array $args |
|
| 488 | 488 | */ |
| 489 | 489 | public function reset_form_stats( $args ) { |
| 490 | 490 | |
| 491 | - if ( empty( $args['form_id'] ) ) { |
|
| 492 | - return; |
|
| 493 | - } |
|
| 491 | + if ( empty( $args['form_id'] ) ) { |
|
| 492 | + return; |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 495 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 496 | 496 | |
| 497 | - if ( ! $form->exists() ) { |
|
| 498 | - return; |
|
| 499 | - } |
|
| 497 | + if ( ! $form->exists() ) { |
|
| 498 | + return; |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | - $form->set_earned( 0 ); |
|
| 502 | - $form->set_refunded( 0 ); |
|
| 503 | - $form->set_cancelled( 0 ); |
|
| 504 | - $form->set_failed( 0 ); |
|
| 505 | - $form->save(); |
|
| 501 | + $form->set_earned( 0 ); |
|
| 502 | + $form->set_refunded( 0 ); |
|
| 503 | + $form->set_cancelled( 0 ); |
|
| 504 | + $form->set_failed( 0 ); |
|
| 505 | + $form->save(); |
|
| 506 | 506 | |
| 507 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
| 507 | + $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
| 508 | 508 | |
| 509 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
| 510 | - exit; |
|
| 511 | - } |
|
| 509 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
| 510 | + exit; |
|
| 511 | + } |
|
| 512 | 512 | |
| 513 | - /** |
|
| 513 | + /** |
|
| 514 | 514 | * Sends a payment reminder to a customer. |
| 515 | - * |
|
| 516 | - * @param array $args |
|
| 515 | + * |
|
| 516 | + * @param array $args |
|
| 517 | 517 | */ |
| 518 | 518 | public function send_customer_invoice( $args ) { |
| 519 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
| 520 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 521 | - exit; |
|
| 522 | - } |
|
| 519 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
| 520 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 521 | + exit; |
|
| 522 | + } |
|
| 523 | 523 | |
| 524 | - /** |
|
| 524 | + /** |
|
| 525 | 525 | * Sends a payment reminder to a customer. |
| 526 | - * |
|
| 527 | - * @param array $args |
|
| 526 | + * |
|
| 527 | + * @param array $args |
|
| 528 | 528 | */ |
| 529 | 529 | public function send_customer_payment_reminder( $args ) { |
| 530 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 530 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 531 | 531 | |
| 532 | - if ( $sent ) { |
|
| 533 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 534 | - } else { |
|
| 535 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 536 | - } |
|
| 532 | + if ( $sent ) { |
|
| 533 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 534 | + } else { |
|
| 535 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 536 | + } |
|
| 537 | 537 | |
| 538 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 539 | - exit; |
|
| 540 | - } |
|
| 538 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 539 | + exit; |
|
| 540 | + } |
|
| 541 | 541 | |
| 542 | - /** |
|
| 542 | + /** |
|
| 543 | 543 | * Resets tax rates. |
| 544 | - * |
|
| 544 | + * |
|
| 545 | 545 | */ |
| 546 | 546 | public function admin_reset_tax_rates() { |
| 547 | 547 | |
| 548 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 549 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 550 | - exit; |
|
| 548 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 549 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 550 | + exit; |
|
| 551 | 551 | |
| 552 | - } |
|
| 552 | + } |
|
| 553 | 553 | |
| 554 | - /** |
|
| 554 | + /** |
|
| 555 | 555 | * Resets admin pages. |
| 556 | - * |
|
| 556 | + * |
|
| 557 | 557 | */ |
| 558 | 558 | public function admin_create_missing_pages() { |
| 559 | - $installer = new GetPaid_Installer(); |
|
| 560 | - $installer->create_pages(); |
|
| 561 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 562 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 563 | - exit; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Refreshes the permalinks. |
|
| 568 | - */ |
|
| 569 | - public function admin_refresh_permalinks() { |
|
| 570 | - flush_rewrite_rules(); |
|
| 571 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
| 572 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 573 | - exit; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - /** |
|
| 559 | + $installer = new GetPaid_Installer(); |
|
| 560 | + $installer->create_pages(); |
|
| 561 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 562 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 563 | + exit; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Refreshes the permalinks. |
|
| 568 | + */ |
|
| 569 | + public function admin_refresh_permalinks() { |
|
| 570 | + flush_rewrite_rules(); |
|
| 571 | + $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
| 572 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 573 | + exit; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | 577 | * Creates missing admin tables. |
| 578 | - * |
|
| 578 | + * |
|
| 579 | 579 | */ |
| 580 | 580 | public function admin_create_missing_tables() { |
| 581 | - global $wpdb; |
|
| 581 | + global $wpdb; |
|
| 582 | 582 | |
| 583 | - GetPaid_Installer::create_db_tables(); |
|
| 583 | + GetPaid_Installer::create_db_tables(); |
|
| 584 | 584 | |
| 585 | - if ( '' !== $wpdb->last_error ) { |
|
| 586 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 587 | - } else { |
|
| 588 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 589 | - } |
|
| 585 | + if ( '' !== $wpdb->last_error ) { |
|
| 586 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 587 | + } else { |
|
| 588 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 589 | + } |
|
| 590 | 590 | |
| 591 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 592 | - exit; |
|
| 593 | - } |
|
| 591 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 592 | + exit; |
|
| 593 | + } |
|
| 594 | 594 | |
| 595 | - /** |
|
| 595 | + /** |
|
| 596 | 596 | * Migrates old invoices to the new database tables. |
| 597 | - * |
|
| 597 | + * |
|
| 598 | 598 | */ |
| 599 | 599 | public function admin_migrate_old_invoices() { |
| 600 | 600 | |
| 601 | - // Migrate the invoices. |
|
| 602 | - $installer = new GetPaid_Installer(); |
|
| 603 | - $installer->migrate_old_invoices(); |
|
| 601 | + // Migrate the invoices. |
|
| 602 | + $installer = new GetPaid_Installer(); |
|
| 603 | + $installer->migrate_old_invoices(); |
|
| 604 | 604 | |
| 605 | - // Show an admin message. |
|
| 606 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 605 | + // Show an admin message. |
|
| 606 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 607 | 607 | |
| 608 | - // Redirect the admin. |
|
| 609 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 610 | - exit; |
|
| 608 | + // Redirect the admin. |
|
| 609 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 610 | + exit; |
|
| 611 | 611 | |
| 612 | - } |
|
| 612 | + } |
|
| 613 | 613 | |
| 614 | - /** |
|
| 614 | + /** |
|
| 615 | 615 | * Download customers. |
| 616 | - * |
|
| 616 | + * |
|
| 617 | 617 | */ |
| 618 | 618 | public function admin_download_customers() { |
| 619 | - global $wpdb; |
|
| 620 | - |
|
| 621 | - $output = fopen( 'php://output', 'w' ); |
|
| 622 | - |
|
| 623 | - if ( false === $output ) { |
|
| 624 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 625 | - } |
|
| 619 | + global $wpdb; |
|
| 626 | 620 | |
| 627 | - header( 'Content-Type:text/csv' ); |
|
| 628 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
| 621 | + $output = fopen( 'php://output', 'w' ); |
|
| 629 | 622 | |
| 630 | - $post_types = ''; |
|
| 623 | + if ( false === $output ) { |
|
| 624 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 625 | + } |
|
| 631 | 626 | |
| 632 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 633 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
| 634 | - } |
|
| 627 | + header( 'Content-Type:text/csv' ); |
|
| 628 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
| 635 | 629 | |
| 636 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 630 | + $post_types = ''; |
|
| 637 | 631 | |
| 638 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 632 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 633 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
| 634 | + } |
|
| 639 | 635 | |
| 640 | - $columns = array( |
|
| 641 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 642 | - 'email' => __( 'Email', 'invoicing' ), |
|
| 643 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 644 | - 'state' => __( 'State', 'invoicing' ), |
|
| 645 | - 'city' => __( 'City', 'invoicing' ), |
|
| 646 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 647 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 648 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 649 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 650 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
| 651 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 652 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
| 653 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 654 | - ); |
|
| 636 | + $post_types = rtrim( $post_types, ' OR' ); |
|
| 637 | + |
|
| 638 | + $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 639 | + |
|
| 640 | + $columns = array( |
|
| 641 | + 'name' => __( 'Name', 'invoicing' ), |
|
| 642 | + 'email' => __( 'Email', 'invoicing' ), |
|
| 643 | + 'country' => __( 'Country', 'invoicing' ), |
|
| 644 | + 'state' => __( 'State', 'invoicing' ), |
|
| 645 | + 'city' => __( 'City', 'invoicing' ), |
|
| 646 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 647 | + 'address' => __( 'Address', 'invoicing' ), |
|
| 648 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
| 649 | + 'company' => __( 'Company', 'invoicing' ), |
|
| 650 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
| 651 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 652 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
| 653 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
| 654 | + ); |
|
| 655 | 655 | |
| 656 | - // Output the csv column headers. |
|
| 657 | - fputcsv( $output, array_values( $columns ) ); |
|
| 656 | + // Output the csv column headers. |
|
| 657 | + fputcsv( $output, array_values( $columns ) ); |
|
| 658 | 658 | |
| 659 | - // Loop through |
|
| 660 | - $table = new WPInv_Customers_Table(); |
|
| 661 | - foreach ( $customers as $customer_id ) { |
|
| 659 | + // Loop through |
|
| 660 | + $table = new WPInv_Customers_Table(); |
|
| 661 | + foreach ( $customers as $customer_id ) { |
|
| 662 | 662 | |
| 663 | - $user = get_user_by( 'id', $customer_id ); |
|
| 664 | - $row = array(); |
|
| 665 | - if ( empty( $user ) ) { |
|
| 666 | - continue; |
|
| 667 | - } |
|
| 663 | + $user = get_user_by( 'id', $customer_id ); |
|
| 664 | + $row = array(); |
|
| 665 | + if ( empty( $user ) ) { |
|
| 666 | + continue; |
|
| 667 | + } |
|
| 668 | 668 | |
| 669 | - foreach ( array_keys( $columns ) as $column ) { |
|
| 669 | + foreach ( array_keys( $columns ) as $column ) { |
|
| 670 | 670 | |
| 671 | - $method = 'column_' . $column; |
|
| 671 | + $method = 'column_' . $column; |
|
| 672 | 672 | |
| 673 | - if ( 'name' == $column ) { |
|
| 674 | - $value = esc_html( $user->display_name ); |
|
| 675 | - } elseif ( 'email' == $column ) { |
|
| 676 | - $value = sanitize_email( $user->user_email ); |
|
| 677 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
| 678 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
| 679 | - } |
|
| 673 | + if ( 'name' == $column ) { |
|
| 674 | + $value = esc_html( $user->display_name ); |
|
| 675 | + } elseif ( 'email' == $column ) { |
|
| 676 | + $value = sanitize_email( $user->user_email ); |
|
| 677 | + } elseif ( is_callable( array( $table, $method ) ) ) { |
|
| 678 | + $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
| 679 | + } |
|
| 680 | 680 | |
| 681 | - if ( empty( $value ) ) { |
|
| 682 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
| 683 | - } |
|
| 681 | + if ( empty( $value ) ) { |
|
| 682 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
| 683 | + } |
|
| 684 | 684 | |
| 685 | - $row[] = $value; |
|
| 685 | + $row[] = $value; |
|
| 686 | 686 | |
| 687 | - } |
|
| 687 | + } |
|
| 688 | 688 | |
| 689 | - fputcsv( $output, $row ); |
|
| 690 | - } |
|
| 689 | + fputcsv( $output, $row ); |
|
| 690 | + } |
|
| 691 | 691 | |
| 692 | - fclose( $output ); |
|
| 693 | - exit; |
|
| 692 | + fclose( $output ); |
|
| 693 | + exit; |
|
| 694 | 694 | |
| 695 | - } |
|
| 695 | + } |
|
| 696 | 696 | |
| 697 | - /** |
|
| 697 | + /** |
|
| 698 | 698 | * Installs a plugin. |
| 699 | - * |
|
| 700 | - * @param array $data |
|
| 699 | + * |
|
| 700 | + * @param array $data |
|
| 701 | 701 | */ |
| 702 | 702 | public function admin_install_plugin( $data ) { |
| 703 | 703 | |
| 704 | - if ( ! empty( $data['plugins'] ) ) { |
|
| 705 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 706 | - wp_cache_flush(); |
|
| 704 | + if ( ! empty( $data['plugins'] ) ) { |
|
| 705 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 706 | + wp_cache_flush(); |
|
| 707 | 707 | |
| 708 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
| 709 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
| 710 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 711 | - $installed = $upgrader->install( $plugin_zip ); |
|
| 708 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
| 709 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
| 710 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 711 | + $installed = $upgrader->install( $plugin_zip ); |
|
| 712 | 712 | |
| 713 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
| 714 | - activate_plugin( $file, '', false, true ); |
|
| 715 | - } else { |
|
| 716 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
| 717 | - } |
|
| 713 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
| 714 | + activate_plugin( $file, '', false, true ); |
|
| 715 | + } else { |
|
| 716 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
| 717 | + } |
|
| 718 | 718 | } |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
| 722 | - wp_safe_redirect( $redirect ); |
|
| 723 | - exit; |
|
| 721 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
| 722 | + wp_safe_redirect( $redirect ); |
|
| 723 | + exit; |
|
| 724 | 724 | |
| 725 | - } |
|
| 725 | + } |
|
| 726 | 726 | |
| 727 | - /** |
|
| 727 | + /** |
|
| 728 | 728 | * Connects a gateway. |
| 729 | - * |
|
| 730 | - * @param array $data |
|
| 729 | + * |
|
| 730 | + * @param array $data |
|
| 731 | 731 | */ |
| 732 | 732 | public function admin_connect_gateway( $data ) { |
| 733 | 733 | |
| 734 | - if ( ! empty( $data['plugin'] ) ) { |
|
| 734 | + if ( ! empty( $data['plugin'] ) ) { |
|
| 735 | 735 | |
| 736 | - $gateway = sanitize_key( $data['plugin'] ); |
|
| 737 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 736 | + $gateway = sanitize_key( $data['plugin'] ); |
|
| 737 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 738 | 738 | |
| 739 | - if ( ! empty( $connect_url ) ) { |
|
| 740 | - wp_redirect( $connect_url ); |
|
| 741 | - exit; |
|
| 742 | - } |
|
| 739 | + if ( ! empty( $connect_url ) ) { |
|
| 740 | + wp_redirect( $connect_url ); |
|
| 741 | + exit; |
|
| 742 | + } |
|
| 743 | 743 | |
| 744 | - if ( 'stripe' == $data['plugin'] ) { |
|
| 745 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 746 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 747 | - wp_cache_flush(); |
|
| 744 | + if ( 'stripe' == $data['plugin'] ) { |
|
| 745 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 746 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 747 | + wp_cache_flush(); |
|
| 748 | 748 | |
| 749 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
| 750 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
| 751 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 752 | - $upgrader->install( $plugin_zip ); |
|
| 753 | - } |
|
| 749 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
| 750 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
| 751 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 752 | + $upgrader->install( $plugin_zip ); |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
| 756 | - } |
|
| 755 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
| 756 | + } |
|
| 757 | 757 | |
| 758 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 759 | - if ( ! empty( $connect_url ) ) { |
|
| 760 | - wp_redirect( $connect_url ); |
|
| 761 | - exit; |
|
| 762 | - } |
|
| 758 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 759 | + if ( ! empty( $connect_url ) ) { |
|
| 760 | + wp_redirect( $connect_url ); |
|
| 761 | + exit; |
|
| 762 | + } |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
| 766 | - wp_safe_redirect( $redirect ); |
|
| 767 | - exit; |
|
| 765 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
| 766 | + wp_safe_redirect( $redirect ); |
|
| 767 | + exit; |
|
| 768 | 768 | |
| 769 | - } |
|
| 769 | + } |
|
| 770 | 770 | |
| 771 | - /** |
|
| 771 | + /** |
|
| 772 | 772 | * Recalculates discounts. |
| 773 | - * |
|
| 773 | + * |
|
| 774 | 774 | */ |
| 775 | 775 | public function admin_recalculate_discounts() { |
| 776 | - global $wpdb; |
|
| 776 | + global $wpdb; |
|
| 777 | 777 | |
| 778 | - // Fetch all invoices that have discount codes. |
|
| 779 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 780 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 778 | + // Fetch all invoices that have discount codes. |
|
| 779 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 780 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 781 | 781 | |
| 782 | - foreach ( $invoices as $invoice ) { |
|
| 782 | + foreach ( $invoices as $invoice ) { |
|
| 783 | 783 | |
| 784 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 784 | + $invoice = new WPInv_Invoice( $invoice ); |
|
| 785 | 785 | |
| 786 | - if ( ! $invoice->exists() ) { |
|
| 787 | - continue; |
|
| 788 | - } |
|
| 786 | + if ( ! $invoice->exists() ) { |
|
| 787 | + continue; |
|
| 788 | + } |
|
| 789 | 789 | |
| 790 | - // Abort if the discount does not exist or does not apply here. |
|
| 791 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 792 | - if ( ! $discount->exists() ) { |
|
| 793 | - continue; |
|
| 794 | - } |
|
| 790 | + // Abort if the discount does not exist or does not apply here. |
|
| 791 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 792 | + if ( ! $discount->exists() ) { |
|
| 793 | + continue; |
|
| 794 | + } |
|
| 795 | 795 | |
| 796 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 797 | - $invoice->recalculate_total(); |
|
| 796 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 797 | + $invoice->recalculate_total(); |
|
| 798 | 798 | |
| 799 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 800 | - $invoice->save(); |
|
| 801 | - } |
|
| 799 | + if ( $invoice->get_total_discount() > 0 ) { |
|
| 800 | + $invoice->save(); |
|
| 801 | + } |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - // Show an admin message. |
|
| 805 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 804 | + // Show an admin message. |
|
| 805 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 806 | 806 | |
| 807 | - // Redirect the admin. |
|
| 808 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 809 | - exit; |
|
| 807 | + // Redirect the admin. |
|
| 808 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 809 | + exit; |
|
| 810 | 810 | |
| 811 | - } |
|
| 811 | + } |
|
| 812 | 812 | |
| 813 | 813 | /** |
| 814 | - * Returns an array of admin notices. |
|
| 815 | - * |
|
| 816 | - * @since 1.0.19 |
|
| 814 | + * Returns an array of admin notices. |
|
| 815 | + * |
|
| 816 | + * @since 1.0.19 |
|
| 817 | 817 | * @return array |
| 818 | - */ |
|
| 819 | - public function get_notices() { |
|
| 820 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
| 818 | + */ |
|
| 819 | + public function get_notices() { |
|
| 820 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
| 821 | 821 | return is_array( $notices ) ? $notices : array(); |
| 822 | - } |
|
| 822 | + } |
|
| 823 | 823 | |
| 824 | - /** |
|
| 825 | - * Checks if we have any admin notices. |
|
| 826 | - * |
|
| 827 | - * @since 2.0.4 |
|
| 824 | + /** |
|
| 825 | + * Checks if we have any admin notices. |
|
| 826 | + * |
|
| 827 | + * @since 2.0.4 |
|
| 828 | 828 | * @return array |
| 829 | - */ |
|
| 830 | - public function has_notices() { |
|
| 831 | - return count( $this->get_notices() ) > 0; |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - /** |
|
| 835 | - * Clears all admin notices |
|
| 836 | - * |
|
| 837 | - * @access public |
|
| 838 | - * @since 1.0.19 |
|
| 839 | - */ |
|
| 840 | - public function clear_notices() { |
|
| 841 | - delete_option( 'wpinv_admin_notices' ); |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - /** |
|
| 845 | - * Saves a new admin notice |
|
| 846 | - * |
|
| 847 | - * @access public |
|
| 848 | - * @since 1.0.19 |
|
| 849 | - */ |
|
| 850 | - public function save_notice( $type, $message ) { |
|
| 851 | - $notices = $this->get_notices(); |
|
| 852 | - |
|
| 853 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
| 854 | - $notices[ $type ] = array(); |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - $notices[ $type ][] = $message; |
|
| 858 | - |
|
| 859 | - update_option( 'wpinv_admin_notices', $notices ); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * Displays a success notice |
|
| 864 | - * |
|
| 865 | - * @param string $msg The message to qeue. |
|
| 866 | - * @access public |
|
| 867 | - * @since 1.0.19 |
|
| 868 | - */ |
|
| 869 | - public function show_success( $msg ) { |
|
| 870 | - $this->save_notice( 'success', $msg ); |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * Displays a error notice |
|
| 875 | - * |
|
| 876 | - * @access public |
|
| 877 | - * @param string $msg The message to qeue. |
|
| 878 | - * @since 1.0.19 |
|
| 879 | - */ |
|
| 880 | - public function show_error( $msg ) { |
|
| 881 | - $this->save_notice( 'error', $msg ); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * Displays a warning notice |
|
| 886 | - * |
|
| 887 | - * @access public |
|
| 888 | - * @param string $msg The message to qeue. |
|
| 889 | - * @since 1.0.19 |
|
| 890 | - */ |
|
| 891 | - public function show_warning( $msg ) { |
|
| 892 | - $this->save_notice( 'warning', $msg ); |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * Displays a info notice |
|
| 897 | - * |
|
| 898 | - * @access public |
|
| 899 | - * @param string $msg The message to qeue. |
|
| 900 | - * @since 1.0.19 |
|
| 901 | - */ |
|
| 902 | - public function show_info( $msg ) { |
|
| 903 | - $this->save_notice( 'info', $msg ); |
|
| 904 | - } |
|
| 905 | - |
|
| 906 | - /** |
|
| 907 | - * Show notices |
|
| 908 | - * |
|
| 909 | - * @access public |
|
| 910 | - * @since 1.0.19 |
|
| 911 | - */ |
|
| 912 | - public function show_notices() { |
|
| 829 | + */ |
|
| 830 | + public function has_notices() { |
|
| 831 | + return count( $this->get_notices() ) > 0; |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + /** |
|
| 835 | + * Clears all admin notices |
|
| 836 | + * |
|
| 837 | + * @access public |
|
| 838 | + * @since 1.0.19 |
|
| 839 | + */ |
|
| 840 | + public function clear_notices() { |
|
| 841 | + delete_option( 'wpinv_admin_notices' ); |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + /** |
|
| 845 | + * Saves a new admin notice |
|
| 846 | + * |
|
| 847 | + * @access public |
|
| 848 | + * @since 1.0.19 |
|
| 849 | + */ |
|
| 850 | + public function save_notice( $type, $message ) { |
|
| 851 | + $notices = $this->get_notices(); |
|
| 852 | + |
|
| 853 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
| 854 | + $notices[ $type ] = array(); |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + $notices[ $type ][] = $message; |
|
| 858 | + |
|
| 859 | + update_option( 'wpinv_admin_notices', $notices ); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * Displays a success notice |
|
| 864 | + * |
|
| 865 | + * @param string $msg The message to qeue. |
|
| 866 | + * @access public |
|
| 867 | + * @since 1.0.19 |
|
| 868 | + */ |
|
| 869 | + public function show_success( $msg ) { |
|
| 870 | + $this->save_notice( 'success', $msg ); |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * Displays a error notice |
|
| 875 | + * |
|
| 876 | + * @access public |
|
| 877 | + * @param string $msg The message to qeue. |
|
| 878 | + * @since 1.0.19 |
|
| 879 | + */ |
|
| 880 | + public function show_error( $msg ) { |
|
| 881 | + $this->save_notice( 'error', $msg ); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * Displays a warning notice |
|
| 886 | + * |
|
| 887 | + * @access public |
|
| 888 | + * @param string $msg The message to qeue. |
|
| 889 | + * @since 1.0.19 |
|
| 890 | + */ |
|
| 891 | + public function show_warning( $msg ) { |
|
| 892 | + $this->save_notice( 'warning', $msg ); |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * Displays a info notice |
|
| 897 | + * |
|
| 898 | + * @access public |
|
| 899 | + * @param string $msg The message to qeue. |
|
| 900 | + * @since 1.0.19 |
|
| 901 | + */ |
|
| 902 | + public function show_info( $msg ) { |
|
| 903 | + $this->save_notice( 'info', $msg ); |
|
| 904 | + } |
|
| 905 | + |
|
| 906 | + /** |
|
| 907 | + * Show notices |
|
| 908 | + * |
|
| 909 | + * @access public |
|
| 910 | + * @since 1.0.19 |
|
| 911 | + */ |
|
| 912 | + public function show_notices() { |
|
| 913 | 913 | |
| 914 | 914 | $notices = $this->get_notices(); |
| 915 | 915 | $this->clear_notices(); |
| 916 | 916 | |
| 917 | - foreach ( $notices as $type => $messages ) { |
|
| 917 | + foreach ( $notices as $type => $messages ) { |
|
| 918 | 918 | |
| 919 | - if ( ! is_array( $messages ) ) { |
|
| 920 | - continue; |
|
| 921 | - } |
|
| 919 | + if ( ! is_array( $messages ) ) { |
|
| 920 | + continue; |
|
| 921 | + } |
|
| 922 | 922 | |
| 923 | 923 | $type = esc_attr( $type ); |
| 924 | - foreach ( $messages as $message ) { |
|
| 925 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
| 924 | + foreach ( $messages as $message ) { |
|
| 925 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
| 926 | 926 | } |
| 927 | 927 | } |
| 928 | 928 | |
| 929 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 930 | - |
|
| 931 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 932 | - $url = wp_nonce_url( |
|
| 933 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 934 | - 'getpaid-nonce', |
|
| 935 | - 'getpaid-nonce' |
|
| 936 | - ); |
|
| 937 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 938 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 939 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
| 940 | - break; |
|
| 941 | - } |
|
| 929 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 930 | + |
|
| 931 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 932 | + $url = wp_nonce_url( |
|
| 933 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 934 | + 'getpaid-nonce', |
|
| 935 | + 'getpaid-nonce' |
|
| 936 | + ); |
|
| 937 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 938 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 939 | + echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
| 940 | + break; |
|
| 941 | + } |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | - } |
|
| 944 | + } |
|
| 945 | 945 | |
| 946 | 946 | } |
@@ -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 | * The main admin class. |
@@ -39,11 +39,11 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function __construct() { |
| 41 | 41 | |
| 42 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
| 43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 42 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
| 43 | + $this->admin_url = plugins_url('/', __FILE__); |
|
| 44 | 44 | $this->reports = new GetPaid_Reports(); |
| 45 | 45 | |
| 46 | - if ( is_admin() ) { |
|
| 46 | + if (is_admin()) { |
|
| 47 | 47 | $this->init_admin_hooks(); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,35 +54,35 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | */ |
| 56 | 56 | private function init_admin_hooks() { |
| 57 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
|
| 58 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
| 59 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
| 60 | - add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
|
| 61 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
|
| 62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
| 65 | - add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
| 66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
| 67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 69 | - add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
|
| 70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 71 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
| 72 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 73 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 74 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
| 75 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 76 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
| 77 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
| 78 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 79 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 57 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'), 9); |
|
| 58 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
| 59 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
| 60 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
| 61 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
| 62 | + add_action('admin_notices', array($this, 'show_notices')); |
|
| 63 | + add_action('getpaid_authenticated_admin_action_rate_plugin', array($this, 'redirect_to_wordpress_rating_page')); |
|
| 64 | + add_action('getpaid_authenticated_admin_action_duplicate_form', array($this, 'duplicate_payment_form')); |
|
| 65 | + add_action('getpaid_authenticated_admin_action_reset_form_stats', array($this, 'reset_form_stats')); |
|
| 66 | + add_action('getpaid_authenticated_admin_action_duplicate_invoice', array($this, 'duplicate_invoice')); |
|
| 67 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
| 68 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
| 69 | + add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates')); |
|
| 70 | + add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages')); |
|
| 71 | + add_action('getpaid_authenticated_admin_action_refresh_permalinks', array($this, 'admin_refresh_permalinks')); |
|
| 72 | + add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables')); |
|
| 73 | + add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices')); |
|
| 74 | + add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers')); |
|
| 75 | + add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts')); |
|
| 76 | + add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin')); |
|
| 77 | + add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway')); |
|
| 78 | + add_filter('admin_footer_text', array($this, 'admin_footer_text')); |
|
| 79 | + do_action('getpaid_init_admin_hooks', $this); |
|
| 80 | 80 | |
| 81 | 81 | // Setup/welcome |
| 82 | - if ( ! empty( $_GET['page'] ) ) { |
|
| 83 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
| 82 | + if (!empty($_GET['page'])) { |
|
| 83 | + switch (sanitize_text_field($_GET['page'])) { |
|
| 84 | 84 | case 'gp-setup': |
| 85 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
| 85 | + include_once dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php'; |
|
| 86 | 86 | break; |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -96,37 +96,37 @@ discard block |
||
| 96 | 96 | public function enqeue_scripts() { |
| 97 | 97 | global $current_screen, $pagenow; |
| 98 | 98 | |
| 99 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 99 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
| 100 | 100 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
| 101 | 101 | |
| 102 | - if ( ! empty( $current_screen->post_type ) ) { |
|
| 102 | + if (!empty($current_screen->post_type)) { |
|
| 103 | 103 | $page = $current_screen->post_type; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // General styles. |
| 107 | - if ( false !== stripos( $page, 'wpi' ) || false !== stripos( $page, 'getpaid' ) || 'gp-setup' == $page || false !== stripos( $page, 'geodir-tickets' ) ) { |
|
| 107 | + if (false !== stripos($page, 'wpi') || false !== stripos($page, 'getpaid') || 'gp-setup' == $page || false !== stripos($page, 'geodir-tickets')) { |
|
| 108 | 108 | |
| 109 | 109 | // Styles. |
| 110 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
| 111 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
| 112 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
| 110 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
| 111 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
| 112 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
| 113 | 113 | |
| 114 | 114 | // Scripts. |
| 115 | - wp_enqueue_script( 'select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 115 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
| 116 | 116 | |
| 117 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
| 118 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ), $version ); |
|
| 119 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
| 117 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
| 118 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version); |
|
| 119 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
| 120 | 120 | |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // Payment form scripts. |
| 124 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 124 | + if ('wpi_payment_form' == $page && $editing) { |
|
| 125 | 125 | $this->load_payment_form_scripts(); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 129 | - wp_enqueue_script( 'postbox' ); |
|
| 128 | + if ($page == 'wpinv-subscriptions') { |
|
| 129 | + wp_enqueue_script('postbox'); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | } |
@@ -139,31 +139,31 @@ discard block |
||
| 139 | 139 | global $post; |
| 140 | 140 | |
| 141 | 141 | $date_range = array( |
| 142 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
| 142 | + 'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days', |
|
| 143 | 143 | ); |
| 144 | 144 | |
| 145 | - if ( $date_range['period'] == 'custom' ) { |
|
| 145 | + if ($date_range['period'] == 'custom') { |
|
| 146 | 146 | |
| 147 | - if ( isset( $_GET['from'] ) ) { |
|
| 148 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 147 | + if (isset($_GET['from'])) { |
|
| 148 | + $date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if ( isset( $_GET['to'] ) ) { |
|
| 152 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 151 | + if (isset($_GET['to'])) { |
|
| 152 | + $date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $i18n = array( |
| 157 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 158 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
| 159 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 160 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 161 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
| 157 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 158 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
| 159 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
| 160 | + 'rest_nonce' => wp_create_nonce('wp_rest'), |
|
| 161 | + 'rest_root' => esc_url_raw(rest_url()), |
|
| 162 | 162 | 'date_range' => $date_range, |
| 163 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
| 164 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
| 165 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
| 166 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
| 163 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
| 164 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
| 165 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
| 166 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
| 167 | 167 | 'tax' => wpinv_tax_amount(), |
| 168 | 168 | 'discount' => 0, |
| 169 | 169 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -172,39 +172,39 @@ discard block |
||
| 172 | 172 | 'thousand_sep' => wpinv_thousands_separator(), |
| 173 | 173 | 'decimal_sep' => wpinv_decimal_separator(), |
| 174 | 174 | 'decimals' => wpinv_decimals(), |
| 175 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
| 176 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
| 177 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
| 178 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
| 179 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
| 180 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
| 181 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
| 182 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
| 183 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
| 184 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
| 185 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
| 186 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
| 187 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
| 188 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
| 189 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
| 190 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
| 191 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 192 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 193 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
| 194 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
| 175 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
| 176 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
| 177 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
| 178 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
| 179 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
| 180 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
| 181 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
| 182 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
| 183 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
| 184 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
| 185 | + 'action_edit' => __('Edit', 'invoicing'), |
|
| 186 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
| 187 | + 'item_description' => __('Item Description', 'invoicing'), |
|
| 188 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
| 189 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
| 190 | + 'searching' => __('Searching', 'invoicing'), |
|
| 191 | + 'loading' => __('Loading...', 'invoicing'), |
|
| 192 | + 'search_customers' => __('Enter customer name or email', 'invoicing'), |
|
| 193 | + 'search_items' => __('Enter item name', 'invoicing'), |
|
| 194 | + 'graphs' => array_merge(array('refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'), array_keys(wpinv_get_report_graphs())), |
|
| 195 | 195 | ); |
| 196 | 196 | |
| 197 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 197 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
| 198 | 198 | |
| 199 | - $invoice = new WPInv_Invoice( $post ); |
|
| 199 | + $invoice = new WPInv_Invoice($post); |
|
| 200 | 200 | $i18n['save_invoice'] = sprintf( |
| 201 | - __( 'Save %s', 'invoicing' ), |
|
| 202 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 201 | + __('Save %s', 'invoicing'), |
|
| 202 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 203 | 203 | ); |
| 204 | 204 | |
| 205 | 205 | $i18n['invoice_description'] = sprintf( |
| 206 | - __( '%s Description', 'invoicing' ), |
|
| 207 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 206 | + __('%s Description', 'invoicing'), |
|
| 207 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 208 | 208 | ); |
| 209 | 209 | |
| 210 | 210 | } |
@@ -218,24 +218,24 @@ discard block |
||
| 218 | 218 | * @param string $footer_text |
| 219 | 219 | * @return string |
| 220 | 220 | */ |
| 221 | - public function admin_footer_text( $footer_text ) { |
|
| 221 | + public function admin_footer_text($footer_text) { |
|
| 222 | 222 | global $current_screen; |
| 223 | 223 | |
| 224 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 224 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
| 225 | 225 | |
| 226 | - if ( ! empty( $current_screen->post_type ) ) { |
|
| 226 | + if (!empty($current_screen->post_type)) { |
|
| 227 | 227 | $page = $current_screen->post_type; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // General styles. |
| 231 | - if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
|
| 231 | + if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) { |
|
| 232 | 232 | |
| 233 | 233 | // Change the footer text |
| 234 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 234 | + if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) { |
|
| 235 | 235 | |
| 236 | - $rating_url = esc_url( |
|
| 236 | + $rating_url = esc_url( |
|
| 237 | 237 | wp_nonce_url( |
| 238 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 238 | + admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'), |
|
| 239 | 239 | 'getpaid-nonce', |
| 240 | 240 | 'getpaid-nonce' |
| 241 | 241 | ) |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | $footer_text = sprintf( |
| 245 | 245 | /* translators: %s: five stars */ |
| 246 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 246 | + __('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'), |
|
| 247 | 247 | "<a href='$rating_url'>★★★★★</a>" |
| 248 | 248 | ); |
| 249 | 249 | |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | $footer_text = sprintf( |
| 253 | 253 | /* translators: %s: GetPaid */ |
| 254 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
| 254 | + __('Thank you for using %s!', 'invoicing'), |
|
| 255 | 255 | "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
| 256 | 256 | ); |
| 257 | 257 | |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | * @since 2.0.0 |
| 268 | 268 | */ |
| 269 | 269 | public function redirect_to_wordpress_rating_page() { |
| 270 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 271 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 270 | + update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1); |
|
| 271 | + wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post'); |
|
| 272 | 272 | exit; |
| 273 | 273 | } |
| 274 | 274 | |
@@ -279,30 +279,30 @@ discard block |
||
| 279 | 279 | protected function load_payment_form_scripts() { |
| 280 | 280 | global $post; |
| 281 | 281 | |
| 282 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
|
| 283 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 284 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 282 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION); |
|
| 283 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
| 284 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
| 285 | 285 | |
| 286 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
| 286 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
| 287 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable', 'wp-hooks'), $version); |
|
| 288 | 288 | |
| 289 | 289 | wp_localize_script( |
| 290 | 290 | 'wpinv-admin-payment-form-script', |
| 291 | 291 | 'wpinvPaymentFormAdmin', |
| 292 | 292 | array( |
| 293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 293 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
| 294 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
| 295 | 295 | 'currency' => wpinv_currency_symbol(), |
| 296 | 296 | 'position' => wpinv_currency_position(), |
| 297 | 297 | 'decimals' => (int) wpinv_decimals(), |
| 298 | 298 | 'thousands_sep' => wpinv_thousands_separator(), |
| 299 | 299 | 'decimals_sep' => wpinv_decimal_separator(), |
| 300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 300 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
| 301 | 301 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
| 302 | 302 | ) |
| 303 | 303 | ); |
| 304 | 304 | |
| 305 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
| 305 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
| 306 | 306 | |
| 307 | 307 | } |
| 308 | 308 | |
@@ -313,24 +313,24 @@ discard block |
||
| 313 | 313 | * @return string |
| 314 | 314 | * |
| 315 | 315 | */ |
| 316 | - public function admin_body_class( $classes ) { |
|
| 316 | + public function admin_body_class($classes) { |
|
| 317 | 317 | global $pagenow, $post, $current_screen; |
| 318 | 318 | |
| 319 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 319 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
| 320 | 320 | |
| 321 | - if ( ! empty( $current_screen->post_type ) ) { |
|
| 321 | + if (!empty($current_screen->post_type)) { |
|
| 322 | 322 | $page = $current_screen->post_type; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
| 326 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
| 325 | + if (false !== stripos($page, 'wpi')) { |
|
| 326 | + $classes .= ' wpi-' . sanitize_key($page); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
| 329 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
| 330 | 330 | $classes .= ' wpinv-cpt wpinv'; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 333 | + if (getpaid_is_invoice_post_type($page)) { |
|
| 334 | 334 | $classes .= ' getpaid-is-invoice-cpt'; |
| 335 | 335 | } |
| 336 | 336 | |
@@ -349,21 +349,21 @@ discard block |
||
| 349 | 349 | 'version' => WPINV_VERSION, |
| 350 | 350 | 'support_url' => 'https://wpgetpaid.com/support/', |
| 351 | 351 | 'documentation_url' => 'https://docs.wpgetpaid.com/', |
| 352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
| 352 | + 'activated' => (int) get_option('gepaid_installed_on'), |
|
| 353 | 353 | ) |
| 354 | 354 | ); |
| 355 | 355 | |
| 356 | 356 | new AyeCode_Connect_Helper( |
| 357 | 357 | array( |
| 358 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
| 359 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
| 360 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
| 361 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
| 362 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
| 363 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
| 364 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
| 358 | + 'connect_title' => __('WP Invoicing - an AyeCode product!', 'invoicing'), |
|
| 359 | + 'connect_external' => __('Please confirm you wish to connect your site?', 'invoicing'), |
|
| 360 | + 'connect' => sprintf(__('<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing'), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>'), |
|
| 361 | + 'connect_button' => __('Connect Site', 'invoicing'), |
|
| 362 | + 'connecting_button' => __('Connecting...', 'invoicing'), |
|
| 363 | + 'error_localhost' => __('This service will only work with a live domain, not a localhost.', 'invoicing'), |
|
| 364 | + 'error' => __('Something went wrong, please refresh and try again.', 'invoicing'), |
|
| 365 | 365 | ), |
| 366 | - array( 'wpi-addons' ) |
|
| 366 | + array('wpi-addons') |
|
| 367 | 367 | ); |
| 368 | 368 | |
| 369 | 369 | } |
@@ -375,20 +375,20 @@ discard block |
||
| 375 | 375 | */ |
| 376 | 376 | public function activation_redirect() { |
| 377 | 377 | |
| 378 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 378 | + $redirected = get_option('wpinv_redirected_to_settings'); |
|
| 379 | 379 | |
| 380 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 380 | + if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) { |
|
| 381 | 381 | return; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // Bail if activating from network, or bulk |
| 385 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 385 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 386 | 386 | return; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 389 | + update_option('wpinv_redirected_to_settings', 1); |
|
| 390 | 390 | |
| 391 | - wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
|
| 391 | + wp_safe_redirect(admin_url('index.php?page=gp-setup')); |
|
| 392 | 392 | exit; |
| 393 | 393 | |
| 394 | 394 | } |
@@ -397,10 +397,10 @@ discard block |
||
| 397 | 397 | * Fires an admin action after verifying that a user can fire them. |
| 398 | 398 | */ |
| 399 | 399 | public function maybe_do_admin_action() { |
| 400 | - if ( isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) && wpinv_current_user_can( sanitize_text_field( $_REQUEST['getpaid-admin-action'] ), $_REQUEST ) ) { |
|
| 401 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
| 400 | + if (isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce') && wpinv_current_user_can(sanitize_text_field($_REQUEST['getpaid-admin-action']), $_REQUEST)) { |
|
| 401 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
| 402 | 402 | |
| 403 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
| 403 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
| 404 | 404 | } |
| 405 | 405 | } |
| 406 | 406 | |
@@ -409,24 +409,24 @@ discard block |
||
| 409 | 409 | * |
| 410 | 410 | * @param array $args |
| 411 | 411 | */ |
| 412 | - public function duplicate_invoice( $args ) { |
|
| 412 | + public function duplicate_invoice($args) { |
|
| 413 | 413 | |
| 414 | - if ( empty( $args['invoice_id'] ) ) { |
|
| 414 | + if (empty($args['invoice_id'])) { |
|
| 415 | 415 | return; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
| 418 | + $invoice = new WPInv_Invoice((int) $args['invoice_id']); |
|
| 419 | 419 | |
| 420 | - if ( ! $invoice->exists() ) { |
|
| 420 | + if (!$invoice->exists()) { |
|
| 421 | 421 | return; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
| 424 | + $new_invoice = getpaid_duplicate_invoice($invoice); |
|
| 425 | 425 | $new_invoice->save(); |
| 426 | 426 | |
| 427 | - if ( $new_invoice->exists() ) { |
|
| 427 | + if ($new_invoice->exists()) { |
|
| 428 | 428 | |
| 429 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
| 429 | + getpaid_admin()->show_success(__('Invoice duplicated successfully.', 'invoicing')); |
|
| 430 | 430 | |
| 431 | 431 | wp_safe_redirect( |
| 432 | 432 | add_query_arg( |
@@ -434,14 +434,14 @@ discard block |
||
| 434 | 434 | 'action' => 'edit', |
| 435 | 435 | 'post' => $new_invoice->get_id(), |
| 436 | 436 | ), |
| 437 | - admin_url( 'post.php' ) |
|
| 437 | + admin_url('post.php') |
|
| 438 | 438 | ) |
| 439 | 439 | ); |
| 440 | 440 | exit; |
| 441 | 441 | |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
| 444 | + getpaid_admin()->show_error(__('There was an error duplicating this invoice. Please try again.', 'invoicing')); |
|
| 445 | 445 | |
| 446 | 446 | } |
| 447 | 447 | |
@@ -450,34 +450,34 @@ discard block |
||
| 450 | 450 | * |
| 451 | 451 | * @param array $args |
| 452 | 452 | */ |
| 453 | - public function duplicate_payment_form( $args ) { |
|
| 453 | + public function duplicate_payment_form($args) { |
|
| 454 | 454 | |
| 455 | - if ( empty( $args['form_id'] ) ) { |
|
| 455 | + if (empty($args['form_id'])) { |
|
| 456 | 456 | return; |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 459 | + $form = new GetPaid_Payment_Form((int) $args['form_id']); |
|
| 460 | 460 | |
| 461 | - if ( ! $form->exists() ) { |
|
| 461 | + if (!$form->exists()) { |
|
| 462 | 462 | return; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | $new_form = new GetPaid_Payment_Form(); |
| 466 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
| 467 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
| 468 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
| 469 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
| 466 | + $new_form->set_author($form->get_author('edit')); |
|
| 467 | + $new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing')); |
|
| 468 | + $new_form->set_elements($form->get_elements('edit')); |
|
| 469 | + $new_form->set_items($form->get_items('edit')); |
|
| 470 | 470 | $new_form->save(); |
| 471 | 471 | |
| 472 | - if ( $new_form->exists() ) { |
|
| 473 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
| 474 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
| 472 | + if ($new_form->exists()) { |
|
| 473 | + $this->show_success(__('Form duplicated successfully', 'invoicing')); |
|
| 474 | + $url = get_edit_post_link($new_form->get_id(), 'edit'); |
|
| 475 | 475 | } else { |
| 476 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
| 477 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
| 476 | + $this->show_error(__('Unable to duplicate form', 'invoicing')); |
|
| 477 | + $url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce')); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - wp_redirect( $url ); |
|
| 480 | + wp_redirect($url); |
|
| 481 | 481 | exit; |
| 482 | 482 | } |
| 483 | 483 | |
@@ -486,27 +486,27 @@ discard block |
||
| 486 | 486 | * |
| 487 | 487 | * @param array $args |
| 488 | 488 | */ |
| 489 | - public function reset_form_stats( $args ) { |
|
| 489 | + public function reset_form_stats($args) { |
|
| 490 | 490 | |
| 491 | - if ( empty( $args['form_id'] ) ) { |
|
| 491 | + if (empty($args['form_id'])) { |
|
| 492 | 492 | return; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 495 | + $form = new GetPaid_Payment_Form((int) $args['form_id']); |
|
| 496 | 496 | |
| 497 | - if ( ! $form->exists() ) { |
|
| 497 | + if (!$form->exists()) { |
|
| 498 | 498 | return; |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - $form->set_earned( 0 ); |
|
| 502 | - $form->set_refunded( 0 ); |
|
| 503 | - $form->set_cancelled( 0 ); |
|
| 504 | - $form->set_failed( 0 ); |
|
| 501 | + $form->set_earned(0); |
|
| 502 | + $form->set_refunded(0); |
|
| 503 | + $form->set_cancelled(0); |
|
| 504 | + $form->set_failed(0); |
|
| 505 | 505 | $form->save(); |
| 506 | 506 | |
| 507 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
| 507 | + $this->show_success(__('Form stats reset successfully', 'invoicing')); |
|
| 508 | 508 | |
| 509 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
| 509 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce'))); |
|
| 510 | 510 | exit; |
| 511 | 511 | } |
| 512 | 512 | |
@@ -515,9 +515,9 @@ discard block |
||
| 515 | 515 | * |
| 516 | 516 | * @param array $args |
| 517 | 517 | */ |
| 518 | - public function send_customer_invoice( $args ) { |
|
| 519 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
| 520 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 518 | + public function send_customer_invoice($args) { |
|
| 519 | + getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true); |
|
| 520 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
| 521 | 521 | exit; |
| 522 | 522 | } |
| 523 | 523 | |
@@ -526,16 +526,16 @@ discard block |
||
| 526 | 526 | * |
| 527 | 527 | * @param array $args |
| 528 | 528 | */ |
| 529 | - public function send_customer_payment_reminder( $args ) { |
|
| 530 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 529 | + public function send_customer_payment_reminder($args) { |
|
| 530 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
| 531 | 531 | |
| 532 | - if ( $sent ) { |
|
| 533 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 532 | + if ($sent) { |
|
| 533 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
| 534 | 534 | } else { |
| 535 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 535 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 538 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
| 539 | 539 | exit; |
| 540 | 540 | } |
| 541 | 541 | |
@@ -545,8 +545,8 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | public function admin_reset_tax_rates() { |
| 547 | 547 | |
| 548 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 549 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 548 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
| 549 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 550 | 550 | exit; |
| 551 | 551 | |
| 552 | 552 | } |
@@ -558,8 +558,8 @@ discard block |
||
| 558 | 558 | public function admin_create_missing_pages() { |
| 559 | 559 | $installer = new GetPaid_Installer(); |
| 560 | 560 | $installer->create_pages(); |
| 561 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 562 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 561 | + $this->show_success(__('GetPaid pages updated.', 'invoicing')); |
|
| 562 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 563 | 563 | exit; |
| 564 | 564 | } |
| 565 | 565 | |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | */ |
| 569 | 569 | public function admin_refresh_permalinks() { |
| 570 | 570 | flush_rewrite_rules(); |
| 571 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
| 572 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 571 | + $this->show_success(__('Permalinks refreshed.', 'invoicing')); |
|
| 572 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 573 | 573 | exit; |
| 574 | 574 | } |
| 575 | 575 | |
@@ -582,13 +582,13 @@ discard block |
||
| 582 | 582 | |
| 583 | 583 | GetPaid_Installer::create_db_tables(); |
| 584 | 584 | |
| 585 | - if ( '' !== $wpdb->last_error ) { |
|
| 586 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 585 | + if ('' !== $wpdb->last_error) { |
|
| 586 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
| 587 | 587 | } else { |
| 588 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 588 | + $this->show_success(__('Your GetPaid tables have been updated.', 'invoicing')); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 591 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 592 | 592 | exit; |
| 593 | 593 | } |
| 594 | 594 | |
@@ -603,10 +603,10 @@ discard block |
||
| 603 | 603 | $installer->migrate_old_invoices(); |
| 604 | 604 | |
| 605 | 605 | // Show an admin message. |
| 606 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 606 | + $this->show_success(__('Your invoices have been migrated.', 'invoicing')); |
|
| 607 | 607 | |
| 608 | 608 | // Redirect the admin. |
| 609 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 609 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 610 | 610 | exit; |
| 611 | 611 | |
| 612 | 612 | } |
@@ -618,78 +618,78 @@ discard block |
||
| 618 | 618 | public function admin_download_customers() { |
| 619 | 619 | global $wpdb; |
| 620 | 620 | |
| 621 | - $output = fopen( 'php://output', 'w' ); |
|
| 621 | + $output = fopen('php://output', 'w'); |
|
| 622 | 622 | |
| 623 | - if ( false === $output ) { |
|
| 624 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 623 | + if (false === $output) { |
|
| 624 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | - header( 'Content-Type:text/csv' ); |
|
| 628 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
| 627 | + header('Content-Type:text/csv'); |
|
| 628 | + header('Content-Disposition:attachment;filename=customers.csv'); |
|
| 629 | 629 | |
| 630 | 630 | $post_types = ''; |
| 631 | 631 | |
| 632 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 633 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
| 632 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
| 633 | + $post_types .= $wpdb->prepare('post_type=%s OR ', $post_type); |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 636 | + $post_types = rtrim($post_types, ' OR'); |
|
| 637 | 637 | |
| 638 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 638 | + $customers = $wpdb->get_col("SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"); |
|
| 639 | 639 | |
| 640 | 640 | $columns = array( |
| 641 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 642 | - 'email' => __( 'Email', 'invoicing' ), |
|
| 643 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 644 | - 'state' => __( 'State', 'invoicing' ), |
|
| 645 | - 'city' => __( 'City', 'invoicing' ), |
|
| 646 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 647 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 648 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 649 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 650 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
| 651 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 652 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
| 653 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 641 | + 'name' => __('Name', 'invoicing'), |
|
| 642 | + 'email' => __('Email', 'invoicing'), |
|
| 643 | + 'country' => __('Country', 'invoicing'), |
|
| 644 | + 'state' => __('State', 'invoicing'), |
|
| 645 | + 'city' => __('City', 'invoicing'), |
|
| 646 | + 'zip' => __('ZIP', 'invoicing'), |
|
| 647 | + 'address' => __('Address', 'invoicing'), |
|
| 648 | + 'phone' => __('Phone', 'invoicing'), |
|
| 649 | + 'company' => __('Company', 'invoicing'), |
|
| 650 | + 'company_id' => __('Company ID', 'invoicing'), |
|
| 651 | + 'invoices' => __('Invoices', 'invoicing'), |
|
| 652 | + 'total_raw' => __('Total Spend', 'invoicing'), |
|
| 653 | + 'signup' => __('Date created', 'invoicing'), |
|
| 654 | 654 | ); |
| 655 | 655 | |
| 656 | 656 | // Output the csv column headers. |
| 657 | - fputcsv( $output, array_values( $columns ) ); |
|
| 657 | + fputcsv($output, array_values($columns)); |
|
| 658 | 658 | |
| 659 | 659 | // Loop through |
| 660 | 660 | $table = new WPInv_Customers_Table(); |
| 661 | - foreach ( $customers as $customer_id ) { |
|
| 661 | + foreach ($customers as $customer_id) { |
|
| 662 | 662 | |
| 663 | - $user = get_user_by( 'id', $customer_id ); |
|
| 663 | + $user = get_user_by('id', $customer_id); |
|
| 664 | 664 | $row = array(); |
| 665 | - if ( empty( $user ) ) { |
|
| 665 | + if (empty($user)) { |
|
| 666 | 666 | continue; |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - foreach ( array_keys( $columns ) as $column ) { |
|
| 669 | + foreach (array_keys($columns) as $column) { |
|
| 670 | 670 | |
| 671 | 671 | $method = 'column_' . $column; |
| 672 | 672 | |
| 673 | - if ( 'name' == $column ) { |
|
| 674 | - $value = esc_html( $user->display_name ); |
|
| 675 | - } elseif ( 'email' == $column ) { |
|
| 676 | - $value = sanitize_email( $user->user_email ); |
|
| 677 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
| 678 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
| 673 | + if ('name' == $column) { |
|
| 674 | + $value = esc_html($user->display_name); |
|
| 675 | + } elseif ('email' == $column) { |
|
| 676 | + $value = sanitize_email($user->user_email); |
|
| 677 | + } elseif (is_callable(array($table, $method))) { |
|
| 678 | + $value = wp_strip_all_tags($table->$method($user)); |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - if ( empty( $value ) ) { |
|
| 682 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
| 681 | + if (empty($value)) { |
|
| 682 | + $value = esc_html(get_user_meta($user->ID, '_wpinv_' . $column, true)); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | $row[] = $value; |
| 686 | 686 | |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | - fputcsv( $output, $row ); |
|
| 689 | + fputcsv($output, $row); |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - fclose( $output ); |
|
| 692 | + fclose($output); |
|
| 693 | 693 | exit; |
| 694 | 694 | |
| 695 | 695 | } |
@@ -699,27 +699,27 @@ discard block |
||
| 699 | 699 | * |
| 700 | 700 | * @param array $data |
| 701 | 701 | */ |
| 702 | - public function admin_install_plugin( $data ) { |
|
| 702 | + public function admin_install_plugin($data) { |
|
| 703 | 703 | |
| 704 | - if ( ! empty( $data['plugins'] ) ) { |
|
| 704 | + if (!empty($data['plugins'])) { |
|
| 705 | 705 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 706 | 706 | wp_cache_flush(); |
| 707 | 707 | |
| 708 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
| 709 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
| 710 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 711 | - $installed = $upgrader->install( $plugin_zip ); |
|
| 708 | + foreach ($data['plugins'] as $slug => $file) { |
|
| 709 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip'); |
|
| 710 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
| 711 | + $installed = $upgrader->install($plugin_zip); |
|
| 712 | 712 | |
| 713 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
| 714 | - activate_plugin( $file, '', false, true ); |
|
| 713 | + if (!is_wp_error($installed) && $installed) { |
|
| 714 | + activate_plugin($file, '', false, true); |
|
| 715 | 715 | } else { |
| 716 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
| 716 | + wpinv_error_log($upgrader->skin->get_upgrade_messages(), false); |
|
| 717 | 717 | } |
| 718 | 718 | } |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
| 722 | - wp_safe_redirect( $redirect ); |
|
| 721 | + $redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php'); |
|
| 722 | + wp_safe_redirect($redirect); |
|
| 723 | 723 | exit; |
| 724 | 724 | |
| 725 | 725 | } |
@@ -729,41 +729,41 @@ discard block |
||
| 729 | 729 | * |
| 730 | 730 | * @param array $data |
| 731 | 731 | */ |
| 732 | - public function admin_connect_gateway( $data ) { |
|
| 732 | + public function admin_connect_gateway($data) { |
|
| 733 | 733 | |
| 734 | - if ( ! empty( $data['plugin'] ) ) { |
|
| 734 | + if (!empty($data['plugin'])) { |
|
| 735 | 735 | |
| 736 | - $gateway = sanitize_key( $data['plugin'] ); |
|
| 737 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 736 | + $gateway = sanitize_key($data['plugin']); |
|
| 737 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
| 738 | 738 | |
| 739 | - if ( ! empty( $connect_url ) ) { |
|
| 740 | - wp_redirect( $connect_url ); |
|
| 739 | + if (!empty($connect_url)) { |
|
| 740 | + wp_redirect($connect_url); |
|
| 741 | 741 | exit; |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | - if ( 'stripe' == $data['plugin'] ) { |
|
| 744 | + if ('stripe' == $data['plugin']) { |
|
| 745 | 745 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 746 | 746 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 747 | 747 | wp_cache_flush(); |
| 748 | 748 | |
| 749 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
| 750 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
| 751 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 752 | - $upgrader->install( $plugin_zip ); |
|
| 749 | + if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) { |
|
| 750 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip'); |
|
| 751 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
| 752 | + $upgrader->install($plugin_zip); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
| 755 | + activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 759 | - if ( ! empty( $connect_url ) ) { |
|
| 760 | - wp_redirect( $connect_url ); |
|
| 758 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
| 759 | + if (!empty($connect_url)) { |
|
| 760 | + wp_redirect($connect_url); |
|
| 761 | 761 | exit; |
| 762 | 762 | } |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
| 766 | - wp_safe_redirect( $redirect ); |
|
| 765 | + $redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
|
| 766 | + wp_safe_redirect($redirect); |
|
| 767 | 767 | exit; |
| 768 | 768 | |
| 769 | 769 | } |
@@ -777,35 +777,35 @@ discard block |
||
| 777 | 777 | |
| 778 | 778 | // Fetch all invoices that have discount codes. |
| 779 | 779 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 780 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 780 | + $invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''"); |
|
| 781 | 781 | |
| 782 | - foreach ( $invoices as $invoice ) { |
|
| 782 | + foreach ($invoices as $invoice) { |
|
| 783 | 783 | |
| 784 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 784 | + $invoice = new WPInv_Invoice($invoice); |
|
| 785 | 785 | |
| 786 | - if ( ! $invoice->exists() ) { |
|
| 786 | + if (!$invoice->exists()) { |
|
| 787 | 787 | continue; |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | // Abort if the discount does not exist or does not apply here. |
| 791 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 792 | - if ( ! $discount->exists() ) { |
|
| 791 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 792 | + if (!$discount->exists()) { |
|
| 793 | 793 | continue; |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 796 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 797 | 797 | $invoice->recalculate_total(); |
| 798 | 798 | |
| 799 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 799 | + if ($invoice->get_total_discount() > 0) { |
|
| 800 | 800 | $invoice->save(); |
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | // Show an admin message. |
| 805 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 805 | + $this->show_success(__('Discounts have been recalculated.', 'invoicing')); |
|
| 806 | 806 | |
| 807 | 807 | // Redirect the admin. |
| 808 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 808 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 809 | 809 | exit; |
| 810 | 810 | |
| 811 | 811 | } |
@@ -817,8 +817,8 @@ discard block |
||
| 817 | 817 | * @return array |
| 818 | 818 | */ |
| 819 | 819 | public function get_notices() { |
| 820 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
| 821 | - return is_array( $notices ) ? $notices : array(); |
|
| 820 | + $notices = get_option('wpinv_admin_notices'); |
|
| 821 | + return is_array($notices) ? $notices : array(); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | * @return array |
| 829 | 829 | */ |
| 830 | 830 | public function has_notices() { |
| 831 | - return count( $this->get_notices() ) > 0; |
|
| 831 | + return count($this->get_notices()) > 0; |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | * @since 1.0.19 |
| 839 | 839 | */ |
| 840 | 840 | public function clear_notices() { |
| 841 | - delete_option( 'wpinv_admin_notices' ); |
|
| 841 | + delete_option('wpinv_admin_notices'); |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | /** |
@@ -847,16 +847,16 @@ discard block |
||
| 847 | 847 | * @access public |
| 848 | 848 | * @since 1.0.19 |
| 849 | 849 | */ |
| 850 | - public function save_notice( $type, $message ) { |
|
| 850 | + public function save_notice($type, $message) { |
|
| 851 | 851 | $notices = $this->get_notices(); |
| 852 | 852 | |
| 853 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
| 854 | - $notices[ $type ] = array(); |
|
| 853 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
| 854 | + $notices[$type] = array(); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | - $notices[ $type ][] = $message; |
|
| 857 | + $notices[$type][] = $message; |
|
| 858 | 858 | |
| 859 | - update_option( 'wpinv_admin_notices', $notices ); |
|
| 859 | + update_option('wpinv_admin_notices', $notices); |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | /** |
@@ -866,8 +866,8 @@ discard block |
||
| 866 | 866 | * @access public |
| 867 | 867 | * @since 1.0.19 |
| 868 | 868 | */ |
| 869 | - public function show_success( $msg ) { |
|
| 870 | - $this->save_notice( 'success', $msg ); |
|
| 869 | + public function show_success($msg) { |
|
| 870 | + $this->save_notice('success', $msg); |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | /** |
@@ -877,8 +877,8 @@ discard block |
||
| 877 | 877 | * @param string $msg The message to qeue. |
| 878 | 878 | * @since 1.0.19 |
| 879 | 879 | */ |
| 880 | - public function show_error( $msg ) { |
|
| 881 | - $this->save_notice( 'error', $msg ); |
|
| 880 | + public function show_error($msg) { |
|
| 881 | + $this->save_notice('error', $msg); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | /** |
@@ -888,8 +888,8 @@ discard block |
||
| 888 | 888 | * @param string $msg The message to qeue. |
| 889 | 889 | * @since 1.0.19 |
| 890 | 890 | */ |
| 891 | - public function show_warning( $msg ) { |
|
| 892 | - $this->save_notice( 'warning', $msg ); |
|
| 891 | + public function show_warning($msg) { |
|
| 892 | + $this->save_notice('warning', $msg); |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -899,8 +899,8 @@ discard block |
||
| 899 | 899 | * @param string $msg The message to qeue. |
| 900 | 900 | * @since 1.0.19 |
| 901 | 901 | */ |
| 902 | - public function show_info( $msg ) { |
|
| 903 | - $this->save_notice( 'info', $msg ); |
|
| 902 | + public function show_info($msg) { |
|
| 903 | + $this->save_notice('info', $msg); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -914,29 +914,29 @@ discard block |
||
| 914 | 914 | $notices = $this->get_notices(); |
| 915 | 915 | $this->clear_notices(); |
| 916 | 916 | |
| 917 | - foreach ( $notices as $type => $messages ) { |
|
| 917 | + foreach ($notices as $type => $messages) { |
|
| 918 | 918 | |
| 919 | - if ( ! is_array( $messages ) ) { |
|
| 919 | + if (!is_array($messages)) { |
|
| 920 | 920 | continue; |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | - $type = esc_attr( $type ); |
|
| 924 | - foreach ( $messages as $message ) { |
|
| 925 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
| 923 | + $type = esc_attr($type); |
|
| 924 | + foreach ($messages as $message) { |
|
| 925 | + echo wp_kses_post("<div class='notice notice-$type is-dismissible'><p>$message</p></div>"); |
|
| 926 | 926 | } |
| 927 | 927 | } |
| 928 | 928 | |
| 929 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 929 | + foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) { |
|
| 930 | 930 | |
| 931 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 932 | - $url = wp_nonce_url( |
|
| 933 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 931 | + if (!is_numeric(wpinv_get_option($page, false))) { |
|
| 932 | + $url = wp_nonce_url( |
|
| 933 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
| 934 | 934 | 'getpaid-nonce', |
| 935 | 935 | 'getpaid-nonce' |
| 936 | 936 | ); |
| 937 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 938 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 939 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
| 937 | + $message = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing'); |
|
| 938 | + $message2 = __('Generate Pages', 'invoicing'); |
|
| 939 | + echo wp_kses_post("<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"); |
|
| 940 | 940 | break; |
| 941 | 941 | } |
| 942 | 942 | } |
@@ -14,651 +14,651 @@ |
||
| 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 | - |
|
| 71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 72 | - return $this->data[ $prop ]; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return null; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Define class properties. |
|
| 80 | - */ |
|
| 81 | - public function set_properties() { |
|
| 82 | - |
|
| 83 | - // Sessions. |
|
| 84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 87 | - |
|
| 88 | - // Init other objects. |
|
| 89 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 90 | - $this->set( 'api', new WPInv_API() ); |
|
| 91 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 92 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 93 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 94 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 95 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 96 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 97 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 98 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 99 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Define plugin constants. |
|
| 105 | - */ |
|
| 106 | - public function define_constants() { |
|
| 107 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 108 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 109 | - $this->version = WPINV_VERSION; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Hook into actions and filters. |
|
| 114 | - * |
|
| 115 | - * @since 1.0.19 |
|
| 116 | - */ |
|
| 117 | - protected function init_hooks() { |
|
| 118 | - /* Internationalize the text strings used. */ |
|
| 119 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 120 | - |
|
| 121 | - // Init the plugin after WordPress inits. |
|
| 122 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 123 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 124 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 125 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 126 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 127 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 128 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 129 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 130 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 131 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 133 | - |
|
| 134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 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 | + |
|
| 71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 72 | + return $this->data[ $prop ]; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return null; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Define class properties. |
|
| 80 | + */ |
|
| 81 | + public function set_properties() { |
|
| 82 | + |
|
| 83 | + // Sessions. |
|
| 84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 87 | + |
|
| 88 | + // Init other objects. |
|
| 89 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 90 | + $this->set( 'api', new WPInv_API() ); |
|
| 91 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 92 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 93 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 94 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 95 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 96 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 97 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 98 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 99 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Define plugin constants. |
|
| 105 | + */ |
|
| 106 | + public function define_constants() { |
|
| 107 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 108 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 109 | + $this->version = WPINV_VERSION; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Hook into actions and filters. |
|
| 114 | + * |
|
| 115 | + * @since 1.0.19 |
|
| 116 | + */ |
|
| 117 | + protected function init_hooks() { |
|
| 118 | + /* Internationalize the text strings used. */ |
|
| 119 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 120 | + |
|
| 121 | + // Init the plugin after WordPress inits. |
|
| 122 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 123 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 124 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 125 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 126 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 127 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 128 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 129 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 130 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 131 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 133 | + |
|
| 134 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 135 | 135 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
| 136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 137 | - |
|
| 138 | - // Fires after registering actions. |
|
| 139 | - do_action( 'wpinv_actions', $this ); |
|
| 140 | - do_action( 'getpaid_actions', $this ); |
|
| 141 | - |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function plugins_loaded() { |
|
| 145 | - /* Internationalize the text strings used. */ |
|
| 146 | - $this->load_textdomain(); |
|
| 147 | - |
|
| 148 | - do_action( 'wpinv_loaded' ); |
|
| 149 | - |
|
| 150 | - // Fix oxygen page builder conflict |
|
| 151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 152 | - wpinv_oxygen_fix_conflict(); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Load Localisation files. |
|
| 158 | - * |
|
| 159 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 160 | - * |
|
| 161 | - * Locales found in: |
|
| 162 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 163 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 164 | - * |
|
| 165 | - * @since 1.0.0 |
|
| 166 | - */ |
|
| 167 | - public function load_textdomain() { |
|
| 168 | - |
|
| 169 | - load_plugin_textdomain( |
|
| 170 | - 'invoicing', |
|
| 171 | - false, |
|
| 172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Include required core files used in admin and on the frontend. |
|
| 179 | - */ |
|
| 180 | - public function includes() { |
|
| 181 | - |
|
| 182 | - // Start with the settings. |
|
| 183 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 184 | - |
|
| 185 | - // Packages/libraries. |
|
| 186 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 187 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 188 | - |
|
| 189 | - // Load functions. |
|
| 190 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 191 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 192 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 193 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 194 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 195 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 197 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 198 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 203 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 204 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 205 | - |
|
| 206 | - // Register autoloader. |
|
| 207 | - try { |
|
| 208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 209 | - } catch ( Exception $e ) { |
|
| 210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 214 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 215 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 216 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 217 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 218 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 219 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 221 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 222 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 224 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 226 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 227 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 228 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 229 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 230 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 231 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 232 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 234 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 235 | - |
|
| 236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 237 | - GetPaid_Post_Types_Admin::init(); |
|
| 238 | - |
|
| 239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 241 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 242 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 243 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 245 | - // load the user class only on the users.php page |
|
| 246 | - global $pagenow; |
|
| 247 | - if ( $pagenow == 'users.php' ) { |
|
| 248 | - new WPInv_Admin_Users(); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // Register cli commands |
|
| 253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 254 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Class autoloader |
|
| 262 | - * |
|
| 263 | - * @param string $class_name The name of the class to load. |
|
| 264 | - * @access public |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @return void |
|
| 267 | - */ |
|
| 268 | - public function autoload( $class_name ) { |
|
| 269 | - |
|
| 270 | - // Normalize the class name... |
|
| 271 | - $class_name = strtolower( $class_name ); |
|
| 272 | - |
|
| 273 | - // ... and make sure it is our class. |
|
| 274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // Next, prepare the file name from the class. |
|
| 279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 280 | - |
|
| 281 | - // Base path of the classes. |
|
| 282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 283 | - |
|
| 284 | - // And an array of possible locations in order of importance. |
|
| 285 | - $locations = array( |
|
| 286 | - "$plugin_path/includes", |
|
| 287 | - "$plugin_path/includes/data-stores", |
|
| 288 | - "$plugin_path/includes/gateways", |
|
| 289 | - "$plugin_path/includes/payments", |
|
| 290 | - "$plugin_path/includes/geolocation", |
|
| 291 | - "$plugin_path/includes/reports", |
|
| 292 | - "$plugin_path/includes/api", |
|
| 293 | - "$plugin_path/includes/admin", |
|
| 294 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 295 | - ); |
|
| 296 | - |
|
| 297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 298 | - |
|
| 299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 300 | - include trailingslashit( $location ) . $file_name; |
|
| 301 | - break; |
|
| 302 | - } |
|
| 136 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 137 | + |
|
| 138 | + // Fires after registering actions. |
|
| 139 | + do_action( 'wpinv_actions', $this ); |
|
| 140 | + do_action( 'getpaid_actions', $this ); |
|
| 141 | + |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function plugins_loaded() { |
|
| 145 | + /* Internationalize the text strings used. */ |
|
| 146 | + $this->load_textdomain(); |
|
| 147 | + |
|
| 148 | + do_action( 'wpinv_loaded' ); |
|
| 149 | + |
|
| 150 | + // Fix oxygen page builder conflict |
|
| 151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 152 | + wpinv_oxygen_fix_conflict(); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Load Localisation files. |
|
| 158 | + * |
|
| 159 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 160 | + * |
|
| 161 | + * Locales found in: |
|
| 162 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 163 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 164 | + * |
|
| 165 | + * @since 1.0.0 |
|
| 166 | + */ |
|
| 167 | + public function load_textdomain() { |
|
| 168 | + |
|
| 169 | + load_plugin_textdomain( |
|
| 170 | + 'invoicing', |
|
| 171 | + false, |
|
| 172 | + plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Include required core files used in admin and on the frontend. |
|
| 179 | + */ |
|
| 180 | + public function includes() { |
|
| 181 | + |
|
| 182 | + // Start with the settings. |
|
| 183 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 184 | + |
|
| 185 | + // Packages/libraries. |
|
| 186 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 187 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 188 | + |
|
| 189 | + // Load functions. |
|
| 190 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 191 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 192 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 193 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 194 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 195 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 197 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 198 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 203 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 204 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 205 | + |
|
| 206 | + // Register autoloader. |
|
| 207 | + try { |
|
| 208 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 209 | + } catch ( Exception $e ) { |
|
| 210 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 214 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 215 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 216 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 217 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 218 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 219 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 221 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 222 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 224 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 226 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 227 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 228 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 229 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 230 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 231 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 232 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 234 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 235 | + |
|
| 236 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 237 | + GetPaid_Post_Types_Admin::init(); |
|
| 238 | + |
|
| 239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 241 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 242 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 243 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 245 | + // load the user class only on the users.php page |
|
| 246 | + global $pagenow; |
|
| 247 | + if ( $pagenow == 'users.php' ) { |
|
| 248 | + new WPInv_Admin_Users(); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // Register cli commands |
|
| 253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 254 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Class autoloader |
|
| 262 | + * |
|
| 263 | + * @param string $class_name The name of the class to load. |
|
| 264 | + * @access public |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @return void |
|
| 267 | + */ |
|
| 268 | + public function autoload( $class_name ) { |
|
| 269 | + |
|
| 270 | + // Normalize the class name... |
|
| 271 | + $class_name = strtolower( $class_name ); |
|
| 272 | + |
|
| 273 | + // ... and make sure it is our class. |
|
| 274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // Next, prepare the file name from the class. |
|
| 279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 280 | + |
|
| 281 | + // Base path of the classes. |
|
| 282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 283 | + |
|
| 284 | + // And an array of possible locations in order of importance. |
|
| 285 | + $locations = array( |
|
| 286 | + "$plugin_path/includes", |
|
| 287 | + "$plugin_path/includes/data-stores", |
|
| 288 | + "$plugin_path/includes/gateways", |
|
| 289 | + "$plugin_path/includes/payments", |
|
| 290 | + "$plugin_path/includes/geolocation", |
|
| 291 | + "$plugin_path/includes/reports", |
|
| 292 | + "$plugin_path/includes/api", |
|
| 293 | + "$plugin_path/includes/admin", |
|
| 294 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 295 | + ); |
|
| 296 | + |
|
| 297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 298 | + |
|
| 299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 300 | + include trailingslashit( $location ) . $file_name; |
|
| 301 | + break; |
|
| 302 | + } |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Inits hooks etc. |
|
| 309 | - */ |
|
| 310 | - public function init() { |
|
| 311 | - |
|
| 312 | - // Fires before getpaid inits. |
|
| 313 | - do_action( 'before_getpaid_init', $this ); |
|
| 314 | - |
|
| 315 | - // Maybe upgrade. |
|
| 316 | - $this->maybe_upgrade_database(); |
|
| 317 | - |
|
| 318 | - // Load default gateways. |
|
| 319 | - $gateways = apply_filters( |
|
| 320 | - 'getpaid_default_gateways', |
|
| 321 | - array( |
|
| 322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | - ) |
|
| 328 | - ); |
|
| 329 | - |
|
| 330 | - foreach ( $gateways as $id => $class ) { |
|
| 331 | - $this->gateways[ $id ] = new $class(); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | - GetPaid_Installer::rename_gateways_label(); |
|
| 336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // Fires after getpaid inits. |
|
| 340 | - do_action( 'getpaid_init', $this ); |
|
| 341 | - |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Checks if this is an IPN request and processes it. |
|
| 346 | - */ |
|
| 347 | - public function maybe_process_ipn() { |
|
| 348 | - |
|
| 349 | - // Ensure that this is an IPN request. |
|
| 350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 351 | - return; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 355 | - |
|
| 356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 358 | - exit; |
|
| 359 | - |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - public function enqueue_scripts() { |
|
| 363 | - |
|
| 364 | - // Fires before adding scripts. |
|
| 365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 366 | - |
|
| 367 | - $localize = array(); |
|
| 368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 369 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
| 370 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
| 371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 377 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 378 | - |
|
| 379 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 380 | - |
|
| 381 | - // reCaptcha. |
|
| 382 | - if ( getpaid_is_recaptcha_enabled() ) { |
|
| 383 | - $url = apply_filters( |
|
| 384 | - 'getpaid_recaptcha_api_url', |
|
| 385 | - add_query_arg( |
|
| 386 | - array( |
|
| 387 | - 'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(), |
|
| 388 | - ), |
|
| 389 | - 'https://www.google.com/recaptcha/api.js' |
|
| 390 | - ) |
|
| 391 | - ); |
|
| 392 | - wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 396 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 397 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - public function wpinv_actions() { |
|
| 401 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 402 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 406 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Inits hooks etc. |
|
| 309 | + */ |
|
| 310 | + public function init() { |
|
| 311 | + |
|
| 312 | + // Fires before getpaid inits. |
|
| 313 | + do_action( 'before_getpaid_init', $this ); |
|
| 314 | + |
|
| 315 | + // Maybe upgrade. |
|
| 316 | + $this->maybe_upgrade_database(); |
|
| 317 | + |
|
| 318 | + // Load default gateways. |
|
| 319 | + $gateways = apply_filters( |
|
| 320 | + 'getpaid_default_gateways', |
|
| 321 | + array( |
|
| 322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | + ) |
|
| 328 | + ); |
|
| 329 | + |
|
| 330 | + foreach ( $gateways as $id => $class ) { |
|
| 331 | + $this->gateways[ $id ] = new $class(); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | + GetPaid_Installer::rename_gateways_label(); |
|
| 336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // Fires after getpaid inits. |
|
| 340 | + do_action( 'getpaid_init', $this ); |
|
| 341 | + |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Checks if this is an IPN request and processes it. |
|
| 346 | + */ |
|
| 347 | + public function maybe_process_ipn() { |
|
| 348 | + |
|
| 349 | + // Ensure that this is an IPN request. |
|
| 350 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 351 | + return; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 355 | + |
|
| 356 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 357 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 358 | + exit; |
|
| 359 | + |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + public function enqueue_scripts() { |
|
| 363 | + |
|
| 364 | + // Fires before adding scripts. |
|
| 365 | + do_action( 'getpaid_enqueue_scripts' ); |
|
| 366 | + |
|
| 367 | + $localize = array(); |
|
| 368 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 369 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
| 370 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
| 371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 374 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 375 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 377 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 378 | + |
|
| 379 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 380 | + |
|
| 381 | + // reCaptcha. |
|
| 382 | + if ( getpaid_is_recaptcha_enabled() ) { |
|
| 383 | + $url = apply_filters( |
|
| 384 | + 'getpaid_recaptcha_api_url', |
|
| 385 | + add_query_arg( |
|
| 386 | + array( |
|
| 387 | + 'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(), |
|
| 388 | + ), |
|
| 389 | + 'https://www.google.com/recaptcha/api.js' |
|
| 390 | + ) |
|
| 391 | + ); |
|
| 392 | + wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 396 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 397 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + public function wpinv_actions() { |
|
| 401 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 402 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 406 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | 411 | * Fires an action after verifying that a user can fire them. |
| 412 | - * |
|
| 413 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 414 | - * current user owns the invoice/subscription. |
|
| 412 | + * |
|
| 413 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 414 | + * current user owns the invoice/subscription. |
|
| 415 | 415 | */ |
| 416 | 416 | public function maybe_do_authenticated_action() { |
| 417 | 417 | |
| 418 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 418 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 419 | 419 | |
| 420 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 421 | - $data = wp_unslash( $_REQUEST ); |
|
| 422 | - if ( is_user_logged_in() ) { |
|
| 423 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 424 | - } |
|
| 420 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 421 | + $data = wp_unslash( $_REQUEST ); |
|
| 422 | + if ( is_user_logged_in() ) { |
|
| 423 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 426 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 427 | + |
|
| 428 | + } |
|
| 427 | 429 | |
| 428 | - } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + public function pre_get_posts( $wp_query ) { |
|
| 433 | + |
|
| 434 | + 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() ) { |
|
| 435 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 436 | + } |
|
| 429 | 437 | |
| 438 | + return $wp_query; |
|
| 430 | 439 | } |
| 431 | 440 | |
| 432 | - public function pre_get_posts( $wp_query ) { |
|
| 433 | - |
|
| 434 | - 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() ) { |
|
| 435 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $wp_query; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Register widgets |
|
| 443 | - * |
|
| 444 | - */ |
|
| 445 | - public function register_widgets() { |
|
| 446 | - global $pagenow; |
|
| 447 | - |
|
| 448 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 449 | - // So we disable our widgets when editing a page with UX Builder. |
|
| 450 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 451 | - return; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 455 | - |
|
| 456 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 457 | - // don't initiate in these conditions. |
|
| 458 | - } else { |
|
| 459 | - |
|
| 460 | - // Only load allowed widgets. |
|
| 461 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 462 | - $widgets = apply_filters( |
|
| 463 | - 'getpaid_widget_classes', |
|
| 464 | - array( |
|
| 465 | - 'WPInv_Checkout_Widget', |
|
| 466 | - 'WPInv_History_Widget', |
|
| 467 | - 'WPInv_Receipt_Widget', |
|
| 468 | - 'WPInv_Subscriptions_Widget', |
|
| 469 | - 'WPInv_Buy_Item_Widget', |
|
| 470 | - 'WPInv_Messages_Widget', |
|
| 471 | - 'WPInv_GetPaid_Widget', |
|
| 472 | - 'WPInv_Invoice_Widget', |
|
| 473 | - ) |
|
| 474 | - ); |
|
| 475 | - |
|
| 476 | - // For each widget... |
|
| 477 | - foreach ( $widgets as $widget ) { |
|
| 478 | - |
|
| 479 | - // Abort early if it is excluded for this page. |
|
| 480 | - if ( in_array( $widget, $exclude ) ) { |
|
| 481 | - continue; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 485 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 486 | - register_widget( $widget ); |
|
| 487 | - } else { |
|
| 488 | - new $widget(); |
|
| 489 | - } |
|
| 441 | + /** |
|
| 442 | + * Register widgets |
|
| 443 | + * |
|
| 444 | + */ |
|
| 445 | + public function register_widgets() { |
|
| 446 | + global $pagenow; |
|
| 447 | + |
|
| 448 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 449 | + // So we disable our widgets when editing a page with UX Builder. |
|
| 450 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 451 | + return; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 455 | + |
|
| 456 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 457 | + // don't initiate in these conditions. |
|
| 458 | + } else { |
|
| 459 | + |
|
| 460 | + // Only load allowed widgets. |
|
| 461 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 462 | + $widgets = apply_filters( |
|
| 463 | + 'getpaid_widget_classes', |
|
| 464 | + array( |
|
| 465 | + 'WPInv_Checkout_Widget', |
|
| 466 | + 'WPInv_History_Widget', |
|
| 467 | + 'WPInv_Receipt_Widget', |
|
| 468 | + 'WPInv_Subscriptions_Widget', |
|
| 469 | + 'WPInv_Buy_Item_Widget', |
|
| 470 | + 'WPInv_Messages_Widget', |
|
| 471 | + 'WPInv_GetPaid_Widget', |
|
| 472 | + 'WPInv_Invoice_Widget', |
|
| 473 | + ) |
|
| 474 | + ); |
|
| 475 | + |
|
| 476 | + // For each widget... |
|
| 477 | + foreach ( $widgets as $widget ) { |
|
| 478 | + |
|
| 479 | + // Abort early if it is excluded for this page. |
|
| 480 | + if ( in_array( $widget, $exclude ) ) { |
|
| 481 | + continue; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 485 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 486 | + register_widget( $widget ); |
|
| 487 | + } else { |
|
| 488 | + new $widget(); |
|
| 489 | + } |
|
| 490 | 490 | } |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Upgrades the database. |
|
| 497 | + * |
|
| 498 | + * @since 2.0.2 |
|
| 499 | + */ |
|
| 500 | + public function maybe_upgrade_database() { |
|
| 501 | + |
|
| 502 | + // Ensure the database tables are up to date. |
|
| 503 | + GetPaid_Installer::maybe_create_db_tables(); |
|
| 504 | + |
|
| 505 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 506 | + |
|
| 507 | + if ( $wpi_version == WPINV_VERSION ) { |
|
| 508 | + return; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + $installer = new GetPaid_Installer(); |
|
| 512 | + |
|
| 513 | + if ( empty( $wpi_version ) ) { |
|
| 514 | + return $installer->upgrade_db( 0 ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $upgrades = array( |
|
| 518 | + '0.0.5' => '004', |
|
| 519 | + '1.0.3' => '102', |
|
| 520 | + '2.0.0' => '118', |
|
| 521 | + ); |
|
| 522 | + |
|
| 523 | + foreach ( $upgrades as $key => $method ) { |
|
| 494 | 524 | |
| 495 | - /** |
|
| 496 | - * Upgrades the database. |
|
| 497 | - * |
|
| 498 | - * @since 2.0.2 |
|
| 499 | - */ |
|
| 500 | - public function maybe_upgrade_database() { |
|
| 525 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 526 | + return $installer->upgrade_db( $method ); |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Flushes the permalinks if needed. |
|
| 534 | + * |
|
| 535 | + * @since 2.0.8 |
|
| 536 | + */ |
|
| 537 | + public function maybe_flush_permalinks() { |
|
| 538 | + |
|
| 539 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 540 | + |
|
| 541 | + if ( ! empty( $flush ) ) { |
|
| 542 | + flush_rewrite_rules(); |
|
| 543 | + delete_option( 'wpinv_flush_permalinks' ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Remove our pages from yoast sitemaps. |
|
| 550 | + * |
|
| 551 | + * @since 1.0.19 |
|
| 552 | + * @param int[] $excluded_posts_ids |
|
| 553 | + */ |
|
| 554 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 555 | + |
|
| 556 | + // Ensure that we have an array. |
|
| 557 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 558 | + $excluded_posts_ids = array(); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + // Prepare our pages. |
|
| 562 | + $our_pages = array(); |
|
| 563 | + |
|
| 564 | + // Checkout page. |
|
| 565 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 566 | + |
|
| 567 | + // Success page. |
|
| 568 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 569 | + |
|
| 570 | + // Failure page. |
|
| 571 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 501 | 572 | |
| 502 | - // Ensure the database tables are up to date. |
|
| 503 | - GetPaid_Installer::maybe_create_db_tables(); |
|
| 573 | + // History page. |
|
| 574 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 504 | 575 | |
| 505 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 576 | + // Subscriptions page. |
|
| 577 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 506 | 578 | |
| 507 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 508 | - return; |
|
| 509 | - } |
|
| 579 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 510 | 580 | |
| 511 | - $installer = new GetPaid_Installer(); |
|
| 581 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 582 | + return array_unique( $excluded_posts_ids ); |
|
| 512 | 583 | |
| 513 | - if ( empty( $wpi_version ) ) { |
|
| 514 | - return $installer->upgrade_db( 0 ); |
|
| 515 | - } |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Remove our pages from yoast sitemaps. |
|
| 588 | + * |
|
| 589 | + * @since 1.0.19 |
|
| 590 | + * @param string[] $post_types |
|
| 591 | + */ |
|
| 592 | + public function exclude_invoicing_post_types( $post_types ) { |
|
| 593 | + |
|
| 594 | + // Ensure that we have an array. |
|
| 595 | + if ( ! is_array( $post_types ) ) { |
|
| 596 | + $post_types = array(); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + // Remove our post types. |
|
| 600 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * Displays additional footer code. |
|
| 605 | + * |
|
| 606 | + * @since 2.0.0 |
|
| 607 | + */ |
|
| 608 | + public function wp_footer() { |
|
| 609 | + wpinv_get_template( 'frontend-footer.php' ); |
|
| 610 | + } |
|
| 516 | 611 | |
| 517 | - $upgrades = array( |
|
| 518 | - '0.0.5' => '004', |
|
| 519 | - '1.0.3' => '102', |
|
| 520 | - '2.0.0' => '118', |
|
| 521 | - ); |
|
| 612 | + /** |
|
| 613 | + * Displays additional header code. |
|
| 614 | + * |
|
| 615 | + * @since 2.0.0 |
|
| 616 | + */ |
|
| 617 | + public function wp_head() { |
|
| 618 | + wpinv_get_template( 'frontend-head.php' ); |
|
| 619 | + } |
|
| 522 | 620 | |
| 523 | - foreach ( $upgrades as $key => $method ) { |
|
| 524 | - |
|
| 525 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 526 | - return $installer->upgrade_db( $method ); |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Flushes the permalinks if needed. |
|
| 534 | - * |
|
| 535 | - * @since 2.0.8 |
|
| 536 | - */ |
|
| 537 | - public function maybe_flush_permalinks() { |
|
| 538 | - |
|
| 539 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 540 | - |
|
| 541 | - if ( ! empty( $flush ) ) { |
|
| 542 | - flush_rewrite_rules(); |
|
| 543 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Remove our pages from yoast sitemaps. |
|
| 550 | - * |
|
| 551 | - * @since 1.0.19 |
|
| 552 | - * @param int[] $excluded_posts_ids |
|
| 553 | - */ |
|
| 554 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 555 | - |
|
| 556 | - // Ensure that we have an array. |
|
| 557 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 558 | - $excluded_posts_ids = array(); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - // Prepare our pages. |
|
| 562 | - $our_pages = array(); |
|
| 563 | - |
|
| 564 | - // Checkout page. |
|
| 565 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 566 | - |
|
| 567 | - // Success page. |
|
| 568 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 569 | - |
|
| 570 | - // Failure page. |
|
| 571 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 572 | - |
|
| 573 | - // History page. |
|
| 574 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 575 | - |
|
| 576 | - // Subscriptions page. |
|
| 577 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 578 | - |
|
| 579 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 580 | - |
|
| 581 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 582 | - return array_unique( $excluded_posts_ids ); |
|
| 583 | - |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Remove our pages from yoast sitemaps. |
|
| 588 | - * |
|
| 589 | - * @since 1.0.19 |
|
| 590 | - * @param string[] $post_types |
|
| 591 | - */ |
|
| 592 | - public function exclude_invoicing_post_types( $post_types ) { |
|
| 593 | - |
|
| 594 | - // Ensure that we have an array. |
|
| 595 | - if ( ! is_array( $post_types ) ) { |
|
| 596 | - $post_types = array(); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - // Remove our post types. |
|
| 600 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * Displays additional footer code. |
|
| 605 | - * |
|
| 606 | - * @since 2.0.0 |
|
| 607 | - */ |
|
| 608 | - public function wp_footer() { |
|
| 609 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * Displays additional header code. |
|
| 614 | - * |
|
| 615 | - * @since 2.0.0 |
|
| 616 | - */ |
|
| 617 | - public function wp_head() { |
|
| 618 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Custom query vars. |
|
| 623 | - * |
|
| 624 | - */ |
|
| 625 | - public function custom_query_vars( $vars ) { |
|
| 621 | + /** |
|
| 622 | + * Custom query vars. |
|
| 623 | + * |
|
| 624 | + */ |
|
| 625 | + public function custom_query_vars( $vars ) { |
|
| 626 | 626 | $vars[] = 'getpaid-ipn'; |
| 627 | 627 | return $vars; |
| 628 | - } |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | - /** |
|
| 631 | - * Add rewrite tags and rules. |
|
| 632 | - * |
|
| 633 | - */ |
|
| 634 | - public function add_rewrite_rule() { |
|
| 630 | + /** |
|
| 631 | + * Add rewrite tags and rules. |
|
| 632 | + * |
|
| 633 | + */ |
|
| 634 | + public function add_rewrite_rule() { |
|
| 635 | 635 | $tag = 'getpaid-ipn'; |
| 636 | 636 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
| 637 | 637 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
| 638 | - } |
|
| 638 | + } |
|
| 639 | 639 | |
| 640 | - /** |
|
| 641 | - * Processes non-query string ipns. |
|
| 642 | - * |
|
| 643 | - */ |
|
| 644 | - public function maybe_process_new_ipn( $query ) { |
|
| 640 | + /** |
|
| 641 | + * Processes non-query string ipns. |
|
| 642 | + * |
|
| 643 | + */ |
|
| 644 | + public function maybe_process_new_ipn( $query ) { |
|
| 645 | 645 | |
| 646 | 646 | if ( is_admin() || ! $query->is_main_query() ) { |
| 647 | 647 | return; |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 650 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 651 | 651 | |
| 652 | 652 | if ( ! empty( $gateway ) ) { |
| 653 | 653 | |
| 654 | - $gateway = sanitize_text_field( $gateway ); |
|
| 655 | - nocache_headers(); |
|
| 656 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 657 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 658 | - exit; |
|
| 654 | + $gateway = sanitize_text_field( $gateway ); |
|
| 655 | + nocache_headers(); |
|
| 656 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 657 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 658 | + exit; |
|
| 659 | 659 | |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - } |
|
| 662 | + } |
|
| 663 | 663 | |
| 664 | 664 | } |
@@ -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,10 +66,10 @@ discard block |
||
| 66 | 66 | * @param string $prop The prop to set. |
| 67 | 67 | * @return mixed The value. |
| 68 | 68 | */ |
| 69 | - public function get( $prop ) { |
|
| 69 | + public function get($prop) { |
|
| 70 | 70 | |
| 71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 72 | - return $this->data[ $prop ]; |
|
| 71 | + if (isset($this->data[$prop])) { |
|
| 72 | + return $this->data[$prop]; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | return null; |
@@ -81,22 +81,22 @@ discard block |
||
| 81 | 81 | public function set_properties() { |
| 82 | 82 | |
| 83 | 83 | // Sessions. |
| 84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 84 | + $this->set('session', new WPInv_Session_Handler()); |
|
| 85 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
| 86 | 86 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
| 87 | 87 | |
| 88 | 88 | // Init other objects. |
| 89 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 90 | - $this->set( 'api', new WPInv_API() ); |
|
| 91 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 92 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 93 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 94 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 95 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 96 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 97 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 98 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 99 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 89 | + $this->set('notes', new WPInv_Notes()); |
|
| 90 | + $this->set('api', new WPInv_API()); |
|
| 91 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
| 92 | + $this->set('template', new GetPaid_Template()); |
|
| 93 | + $this->set('admin', new GetPaid_Admin()); |
|
| 94 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
| 95 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
| 96 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
| 97 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
| 98 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
| 99 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
| 100 | 100 | |
| 101 | 101 | } |
| 102 | 102 | |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * Define plugin constants. |
| 105 | 105 | */ |
| 106 | 106 | public function define_constants() { |
| 107 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 108 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 107 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 108 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 109 | 109 | $this->version = WPINV_VERSION; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -116,28 +116,28 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | protected function init_hooks() { |
| 118 | 118 | /* Internationalize the text strings used. */ |
| 119 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 119 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 120 | 120 | |
| 121 | 121 | // Init the plugin after WordPress inits. |
| 122 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 123 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 124 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 125 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 126 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 127 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 128 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 129 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 130 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 131 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 133 | - |
|
| 134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 135 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 122 | + add_action('init', array($this, 'init'), 1); |
|
| 123 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
| 124 | + add_action('init', array($this, 'wpinv_actions')); |
|
| 125 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
| 126 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
| 127 | + add_action('wp_footer', array($this, 'wp_footer')); |
|
| 128 | + add_action('wp_head', array($this, 'wp_head')); |
|
| 129 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
| 130 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
| 131 | + add_filter('the_seo_framework_sitemap_supported_post_types', array($this, 'exclude_invoicing_post_types')); |
|
| 132 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 133 | + |
|
| 134 | + add_filter('query_vars', array($this, 'custom_query_vars')); |
|
| 135 | + add_action('init', array($this, 'add_rewrite_rule'), 10, 0); |
|
| 136 | + add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1); |
|
| 137 | 137 | |
| 138 | 138 | // Fires after registering actions. |
| 139 | - do_action( 'wpinv_actions', $this ); |
|
| 140 | - do_action( 'getpaid_actions', $this ); |
|
| 139 | + do_action('wpinv_actions', $this); |
|
| 140 | + do_action('getpaid_actions', $this); |
|
| 141 | 141 | |
| 142 | 142 | } |
| 143 | 143 | |
@@ -145,10 +145,10 @@ discard block |
||
| 145 | 145 | /* Internationalize the text strings used. */ |
| 146 | 146 | $this->load_textdomain(); |
| 147 | 147 | |
| 148 | - do_action( 'wpinv_loaded' ); |
|
| 148 | + do_action('wpinv_loaded'); |
|
| 149 | 149 | |
| 150 | 150 | // Fix oxygen page builder conflict |
| 151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 151 | + if (function_exists('ct_css_output')) { |
|
| 152 | 152 | wpinv_oxygen_fix_conflict(); |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | load_plugin_textdomain( |
| 170 | 170 | 'invoicing', |
| 171 | 171 | false, |
| 172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
| 172 | + plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/' |
|
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | 175 | } |
@@ -205,9 +205,9 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | // Register autoloader. |
| 207 | 207 | try { |
| 208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 209 | - } catch ( Exception $e ) { |
|
| 210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 208 | + spl_autoload_register(array($this, 'autoload'), true); |
|
| 209 | + } catch (Exception $e) { |
|
| 210 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
| 234 | 234 | require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
| 235 | 235 | |
| 236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 236 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 237 | 237 | GetPaid_Post_Types_Admin::init(); |
| 238 | 238 | |
| 239 | 239 | require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
@@ -244,15 +244,15 @@ discard block |
||
| 244 | 244 | require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
| 245 | 245 | // load the user class only on the users.php page |
| 246 | 246 | global $pagenow; |
| 247 | - if ( $pagenow == 'users.php' ) { |
|
| 247 | + if ($pagenow == 'users.php') { |
|
| 248 | 248 | new WPInv_Admin_Users(); |
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // Register cli commands |
| 253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 253 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 254 | 254 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
| 255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 255 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | } |
@@ -265,21 +265,21 @@ discard block |
||
| 265 | 265 | * @since 1.0.19 |
| 266 | 266 | * @return void |
| 267 | 267 | */ |
| 268 | - public function autoload( $class_name ) { |
|
| 268 | + public function autoload($class_name) { |
|
| 269 | 269 | |
| 270 | 270 | // Normalize the class name... |
| 271 | - $class_name = strtolower( $class_name ); |
|
| 271 | + $class_name = strtolower($class_name); |
|
| 272 | 272 | |
| 273 | 273 | // ... and make sure it is our class. |
| 274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 274 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // Next, prepare the file name from the class. |
| 279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 279 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
| 280 | 280 | |
| 281 | 281 | // Base path of the classes. |
| 282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 282 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
| 283 | 283 | |
| 284 | 284 | // And an array of possible locations in order of importance. |
| 285 | 285 | $locations = array( |
@@ -294,10 +294,10 @@ discard block |
||
| 294 | 294 | "$plugin_path/includes/admin/meta-boxes", |
| 295 | 295 | ); |
| 296 | 296 | |
| 297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 297 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
| 298 | 298 | |
| 299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 300 | - include trailingslashit( $location ) . $file_name; |
|
| 299 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
| 300 | + include trailingslashit($location) . $file_name; |
|
| 301 | 301 | break; |
| 302 | 302 | } |
| 303 | 303 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | public function init() { |
| 311 | 311 | |
| 312 | 312 | // Fires before getpaid inits. |
| 313 | - do_action( 'before_getpaid_init', $this ); |
|
| 313 | + do_action('before_getpaid_init', $this); |
|
| 314 | 314 | |
| 315 | 315 | // Maybe upgrade. |
| 316 | 316 | $this->maybe_upgrade_database(); |
@@ -327,17 +327,17 @@ discard block |
||
| 327 | 327 | ) |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | - foreach ( $gateways as $id => $class ) { |
|
| 331 | - $this->gateways[ $id ] = new $class(); |
|
| 330 | + foreach ($gateways as $id => $class) { |
|
| 331 | + $this->gateways[$id] = new $class(); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 334 | + if ('yes' != get_option('wpinv_renamed_gateways')) { |
|
| 335 | 335 | GetPaid_Installer::rename_gateways_label(); |
| 336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 336 | + update_option('wpinv_renamed_gateways', 'yes'); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // Fires after getpaid inits. |
| 340 | - do_action( 'getpaid_init', $this ); |
|
| 340 | + do_action('getpaid_init', $this); |
|
| 341 | 341 | |
| 342 | 342 | } |
| 343 | 343 | |
@@ -347,14 +347,14 @@ discard block |
||
| 347 | 347 | public function maybe_process_ipn() { |
| 348 | 348 | |
| 349 | 349 | // Ensure that this is an IPN request. |
| 350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 350 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
| 351 | 351 | return; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 354 | + $gateway = sanitize_text_field($_GET['wpi-gateway']); |
|
| 355 | 355 | |
| 356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 356 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
| 357 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
| 358 | 358 | exit; |
| 359 | 359 | |
| 360 | 360 | } |
@@ -362,24 +362,24 @@ discard block |
||
| 362 | 362 | public function enqueue_scripts() { |
| 363 | 363 | |
| 364 | 364 | // Fires before adding scripts. |
| 365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 365 | + do_action('getpaid_enqueue_scripts'); |
|
| 366 | 366 | |
| 367 | 367 | $localize = array(); |
| 368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 368 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 369 | 369 | $localize['thousands'] = wpinv_thousands_separator(); |
| 370 | 370 | $localize['decimals'] = wpinv_decimal_separator(); |
| 371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 371 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 372 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
| 373 | 373 | $localize['UseTaxes'] = wpinv_use_taxes(); |
| 374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 374 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
| 375 | + $localize['loading'] = __('Loading...', 'invoicing'); |
|
| 376 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
| 377 | 377 | $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
| 378 | 378 | |
| 379 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 379 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 380 | 380 | |
| 381 | 381 | // reCaptcha. |
| 382 | - if ( getpaid_is_recaptcha_enabled() ) { |
|
| 382 | + if (getpaid_is_recaptcha_enabled()) { |
|
| 383 | 383 | $url = apply_filters( |
| 384 | 384 | 'getpaid_recaptcha_api_url', |
| 385 | 385 | add_query_arg( |
@@ -389,21 +389,21 @@ discard block |
||
| 389 | 389 | 'https://www.google.com/recaptcha/api.js' |
| 390 | 390 | ) |
| 391 | 391 | ); |
| 392 | - wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 392 | + wp_enqueue_script('recaptcha', $url, array(), null, true); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 396 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 397 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 395 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
| 396 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true); |
|
| 397 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | public function wpinv_actions() { |
| 401 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 402 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 401 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 402 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 406 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 405 | + if (defined('WP_ALL_IMPORT_ROOT_DIR')) { |
|
| 406 | + include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | |
@@ -415,24 +415,24 @@ discard block |
||
| 415 | 415 | */ |
| 416 | 416 | public function maybe_do_authenticated_action() { |
| 417 | 417 | |
| 418 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 418 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
| 419 | 419 | |
| 420 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 421 | - $data = wp_unslash( $_REQUEST ); |
|
| 422 | - if ( is_user_logged_in() ) { |
|
| 423 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 420 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
| 421 | + $data = wp_unslash($_REQUEST); |
|
| 422 | + if (is_user_logged_in()) { |
|
| 423 | + do_action("getpaid_authenticated_action_$key", $data); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 426 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
| 427 | 427 | |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - public function pre_get_posts( $wp_query ) { |
|
| 432 | + public function pre_get_posts($wp_query) { |
|
| 433 | 433 | |
| 434 | - 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() ) { |
|
| 435 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 434 | + 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()) { |
|
| 435 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | return $wp_query; |
@@ -447,18 +447,18 @@ discard block |
||
| 447 | 447 | |
| 448 | 448 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
| 449 | 449 | // So we disable our widgets when editing a page with UX Builder. |
| 450 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 450 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
| 451 | 451 | return; |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 454 | + $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
| 455 | 455 | |
| 456 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 456 | + if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
| 457 | 457 | // don't initiate in these conditions. |
| 458 | 458 | } else { |
| 459 | 459 | |
| 460 | 460 | // Only load allowed widgets. |
| 461 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 461 | + $exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array(); |
|
| 462 | 462 | $widgets = apply_filters( |
| 463 | 463 | 'getpaid_widget_classes', |
| 464 | 464 | array( |
@@ -474,16 +474,16 @@ discard block |
||
| 474 | 474 | ); |
| 475 | 475 | |
| 476 | 476 | // For each widget... |
| 477 | - foreach ( $widgets as $widget ) { |
|
| 477 | + foreach ($widgets as $widget) { |
|
| 478 | 478 | |
| 479 | 479 | // Abort early if it is excluded for this page. |
| 480 | - if ( in_array( $widget, $exclude ) ) { |
|
| 480 | + if (in_array($widget, $exclude)) { |
|
| 481 | 481 | continue; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
| 485 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 486 | - register_widget( $widget ); |
|
| 485 | + if (is_subclass_of($widget, 'WP_Widget')) { |
|
| 486 | + register_widget($widget); |
|
| 487 | 487 | } else { |
| 488 | 488 | new $widget(); |
| 489 | 489 | } |
@@ -502,28 +502,28 @@ discard block |
||
| 502 | 502 | // Ensure the database tables are up to date. |
| 503 | 503 | GetPaid_Installer::maybe_create_db_tables(); |
| 504 | 504 | |
| 505 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 505 | + $wpi_version = get_option('wpinv_version', 0); |
|
| 506 | 506 | |
| 507 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 507 | + if ($wpi_version == WPINV_VERSION) { |
|
| 508 | 508 | return; |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | $installer = new GetPaid_Installer(); |
| 512 | 512 | |
| 513 | - if ( empty( $wpi_version ) ) { |
|
| 514 | - return $installer->upgrade_db( 0 ); |
|
| 513 | + if (empty($wpi_version)) { |
|
| 514 | + return $installer->upgrade_db(0); |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - $upgrades = array( |
|
| 517 | + $upgrades = array( |
|
| 518 | 518 | '0.0.5' => '004', |
| 519 | 519 | '1.0.3' => '102', |
| 520 | 520 | '2.0.0' => '118', |
| 521 | 521 | ); |
| 522 | 522 | |
| 523 | - foreach ( $upgrades as $key => $method ) { |
|
| 523 | + foreach ($upgrades as $key => $method) { |
|
| 524 | 524 | |
| 525 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 526 | - return $installer->upgrade_db( $method ); |
|
| 525 | + if (version_compare($wpi_version, $key, '<')) { |
|
| 526 | + return $installer->upgrade_db($method); |
|
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | |
@@ -536,11 +536,11 @@ discard block |
||
| 536 | 536 | */ |
| 537 | 537 | public function maybe_flush_permalinks() { |
| 538 | 538 | |
| 539 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 539 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
| 540 | 540 | |
| 541 | - if ( ! empty( $flush ) ) { |
|
| 541 | + if (!empty($flush)) { |
|
| 542 | 542 | flush_rewrite_rules(); |
| 543 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 543 | + delete_option('wpinv_flush_permalinks'); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | } |
@@ -551,10 +551,10 @@ discard block |
||
| 551 | 551 | * @since 1.0.19 |
| 552 | 552 | * @param int[] $excluded_posts_ids |
| 553 | 553 | */ |
| 554 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 554 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
| 555 | 555 | |
| 556 | 556 | // Ensure that we have an array. |
| 557 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 557 | + if (!is_array($excluded_posts_ids)) { |
|
| 558 | 558 | $excluded_posts_ids = array(); |
| 559 | 559 | } |
| 560 | 560 | |
@@ -562,24 +562,24 @@ discard block |
||
| 562 | 562 | $our_pages = array(); |
| 563 | 563 | |
| 564 | 564 | // Checkout page. |
| 565 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 565 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
| 566 | 566 | |
| 567 | 567 | // Success page. |
| 568 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 568 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
| 569 | 569 | |
| 570 | 570 | // Failure page. |
| 571 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 571 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
| 572 | 572 | |
| 573 | 573 | // History page. |
| 574 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 574 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
| 575 | 575 | |
| 576 | 576 | // Subscriptions page. |
| 577 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 577 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
| 578 | 578 | |
| 579 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 579 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
| 580 | 580 | |
| 581 | 581 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
| 582 | - return array_unique( $excluded_posts_ids ); |
|
| 582 | + return array_unique($excluded_posts_ids); |
|
| 583 | 583 | |
| 584 | 584 | } |
| 585 | 585 | |
@@ -589,15 +589,15 @@ discard block |
||
| 589 | 589 | * @since 1.0.19 |
| 590 | 590 | * @param string[] $post_types |
| 591 | 591 | */ |
| 592 | - public function exclude_invoicing_post_types( $post_types ) { |
|
| 592 | + public function exclude_invoicing_post_types($post_types) { |
|
| 593 | 593 | |
| 594 | 594 | // Ensure that we have an array. |
| 595 | - if ( ! is_array( $post_types ) ) { |
|
| 595 | + if (!is_array($post_types)) { |
|
| 596 | 596 | $post_types = array(); |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | // Remove our post types. |
| 600 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 600 | + return array_diff($post_types, array_keys(getpaid_get_invoice_post_types())); |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | /** |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | * @since 2.0.0 |
| 607 | 607 | */ |
| 608 | 608 | public function wp_footer() { |
| 609 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 609 | + wpinv_get_template('frontend-footer.php'); |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | /** |
@@ -615,14 +615,14 @@ discard block |
||
| 615 | 615 | * @since 2.0.0 |
| 616 | 616 | */ |
| 617 | 617 | public function wp_head() { |
| 618 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 618 | + wpinv_get_template('frontend-head.php'); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
| 622 | 622 | * Custom query vars. |
| 623 | 623 | * |
| 624 | 624 | */ |
| 625 | - public function custom_query_vars( $vars ) { |
|
| 625 | + public function custom_query_vars($vars) { |
|
| 626 | 626 | $vars[] = 'getpaid-ipn'; |
| 627 | 627 | return $vars; |
| 628 | 628 | } |
@@ -633,28 +633,28 @@ discard block |
||
| 633 | 633 | */ |
| 634 | 634 | public function add_rewrite_rule() { |
| 635 | 635 | $tag = 'getpaid-ipn'; |
| 636 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 637 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 636 | + add_rewrite_tag("%$tag%", '([^&]+)'); |
|
| 637 | + add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top'); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
| 641 | 641 | * Processes non-query string ipns. |
| 642 | 642 | * |
| 643 | 643 | */ |
| 644 | - public function maybe_process_new_ipn( $query ) { |
|
| 644 | + public function maybe_process_new_ipn($query) { |
|
| 645 | 645 | |
| 646 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
| 646 | + if (is_admin() || !$query->is_main_query()) { |
|
| 647 | 647 | return; |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 650 | + $gateway = get_query_var('getpaid-ipn'); |
|
| 651 | 651 | |
| 652 | - if ( ! empty( $gateway ) ) { |
|
| 652 | + if (!empty($gateway)) { |
|
| 653 | 653 | |
| 654 | - $gateway = sanitize_text_field( $gateway ); |
|
| 654 | + $gateway = sanitize_text_field($gateway); |
|
| 655 | 655 | nocache_headers(); |
| 656 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 657 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 656 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
| 657 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
| 658 | 658 | exit; |
| 659 | 659 | |
| 660 | 660 | } |