@@ -14,76 +14,76 @@ 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; |
|
| 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 | 29 | |
| 30 | - /** |
|
| 31 | - * Reports components. |
|
| 32 | - * |
|
| 33 | - * @var GetPaid_Reports |
|
| 34 | - */ |
|
| 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' ) ); |
| 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_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 65 | - 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_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 65 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 66 | 66 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
| 67 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 68 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 69 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 70 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 71 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 67 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 68 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 69 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 70 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 71 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 72 | 72 | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | - * Register admin scripts |
|
| 77 | - * |
|
| 78 | - */ |
|
| 79 | - public function enqeue_scripts() { |
|
| 76 | + * Register admin scripts |
|
| 77 | + * |
|
| 78 | + */ |
|
| 79 | + public function enqeue_scripts() { |
|
| 80 | 80 | global $current_screen, $pagenow; |
| 81 | 81 | |
| 82 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 83 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 82 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 83 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 84 | 84 | |
| 85 | 85 | if ( ! empty( $current_screen->post_type ) ) { |
| 86 | - $page = $current_screen->post_type; |
|
| 86 | + $page = $current_screen->post_type; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // General styles. |
@@ -105,54 +105,54 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // Payment form scripts. |
| 108 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 108 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 109 | 109 | $this->load_payment_form_scripts(); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 113 | - wp_enqueue_script( 'postbox' ); |
|
| 114 | - } |
|
| 112 | + if ( $page == 'wpinv-subscriptions' ) { |
|
| 113 | + wp_enqueue_script( 'postbox' ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
| 119 | - * Returns admin js translations. |
|
| 120 | - * |
|
| 121 | - */ |
|
| 122 | - protected function get_admin_i18() { |
|
| 119 | + * Returns admin js translations. |
|
| 120 | + * |
|
| 121 | + */ |
|
| 122 | + protected function get_admin_i18() { |
|
| 123 | 123 | global $post; |
| 124 | 124 | |
| 125 | - $date_range = array( |
|
| 126 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
| 127 | - ); |
|
| 125 | + $date_range = array( |
|
| 126 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
| 127 | + ); |
|
| 128 | 128 | |
| 129 | - if ( $date_range['period'] == 'custom' ) { |
|
| 129 | + if ( $date_range['period'] == 'custom' ) { |
|
| 130 | 130 | |
| 131 | - if ( isset( $_GET['from'] ) ) { |
|
| 132 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 133 | - } |
|
| 131 | + if ( isset( $_GET['from'] ) ) { |
|
| 132 | + $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - if ( isset( $_GET['to'] ) ) { |
|
| 136 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 137 | - } |
|
| 135 | + if ( isset( $_GET['to'] ) ) { |
|
| 136 | + $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | $i18n = array( |
| 142 | 142 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 143 | 143 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
| 144 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 145 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 146 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
| 147 | - 'date_range' => $date_range, |
|
| 144 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 145 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 146 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
| 147 | + 'date_range' => $date_range, |
|
| 148 | 148 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
| 149 | 149 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
| 150 | 150 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
| 151 | 151 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
| 152 | 152 | 'tax' => wpinv_tax_amount(), |
| 153 | 153 | 'discount' => 0, |
| 154 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
| 155 | - 'currency' => wpinv_get_currency(), |
|
| 154 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
| 155 | + 'currency' => wpinv_get_currency(), |
|
| 156 | 156 | 'currency_pos' => wpinv_currency_position(), |
| 157 | 157 | 'thousand_sep' => wpinv_thousands_separator(), |
| 158 | 158 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -172,116 +172,116 @@ discard block |
||
| 172 | 172 | 'item_description' => __( 'Item Description', 'invoicing' ), |
| 173 | 173 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
| 174 | 174 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
| 175 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
| 176 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 175 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
| 176 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 177 | 177 | ); |
| 178 | 178 | |
| 179 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 179 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 180 | 180 | |
| 181 | - $invoice = new WPInv_Invoice( $post ); |
|
| 182 | - $i18n['save_invoice'] = sprintf( |
|
| 183 | - __( 'Save %s', 'invoicing' ), |
|
| 184 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 185 | - ); |
|
| 181 | + $invoice = new WPInv_Invoice( $post ); |
|
| 182 | + $i18n['save_invoice'] = sprintf( |
|
| 183 | + __( 'Save %s', 'invoicing' ), |
|
| 184 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 185 | + ); |
|
| 186 | 186 | |
| 187 | - $i18n['invoice_description'] = sprintf( |
|
| 188 | - __( '%s Description', 'invoicing' ), |
|
| 189 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 190 | - ); |
|
| 187 | + $i18n['invoice_description'] = sprintf( |
|
| 188 | + __( '%s Description', 'invoicing' ), |
|
| 189 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 190 | + ); |
|
| 191 | 191 | |
| 192 | - } |
|
| 193 | - return $i18n; |
|
| 194 | - } |
|
| 192 | + } |
|
| 193 | + return $i18n; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Change the admin footer text on GetPaid admin pages. |
|
| 198 | - * |
|
| 199 | - * @since 2.0.0 |
|
| 200 | - * @param string $footer_text |
|
| 201 | - * @return string |
|
| 202 | - */ |
|
| 203 | - public function admin_footer_text( $footer_text ) { |
|
| 204 | - global $current_screen; |
|
| 196 | + /** |
|
| 197 | + * Change the admin footer text on GetPaid admin pages. |
|
| 198 | + * |
|
| 199 | + * @since 2.0.0 |
|
| 200 | + * @param string $footer_text |
|
| 201 | + * @return string |
|
| 202 | + */ |
|
| 203 | + public function admin_footer_text( $footer_text ) { |
|
| 204 | + global $current_screen; |
|
| 205 | 205 | |
| 206 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 206 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 207 | 207 | |
| 208 | 208 | if ( ! empty( $current_screen->post_type ) ) { |
| 209 | - $page = $current_screen->post_type; |
|
| 209 | + $page = $current_screen->post_type; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // General styles. |
| 213 | 213 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
| 214 | 214 | |
| 215 | - // Change the footer text |
|
| 216 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 217 | - |
|
| 218 | - $rating_url = esc_url( |
|
| 219 | - wp_nonce_url( |
|
| 220 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 221 | - 'getpaid-nonce', |
|
| 222 | - 'getpaid-nonce' |
|
| 223 | - ) |
|
| 224 | - ); |
|
| 225 | - |
|
| 226 | - $footer_text = sprintf( |
|
| 227 | - /* translators: %s: five stars */ |
|
| 228 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 229 | - "<a href='$rating_url'>★★★★★</a>" |
|
| 230 | - ); |
|
| 231 | - |
|
| 232 | - } else { |
|
| 233 | - |
|
| 234 | - $footer_text = sprintf( |
|
| 235 | - /* translators: %s: GetPaid */ |
|
| 236 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
| 237 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - return $footer_text; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Redirects to wp.org to rate the plugin. |
|
| 249 | - * |
|
| 250 | - * @since 2.0.0 |
|
| 251 | - */ |
|
| 252 | - public function redirect_to_wordpress_rating_page() { |
|
| 253 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 254 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 255 | - exit; |
|
| 256 | - } |
|
| 215 | + // Change the footer text |
|
| 216 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 217 | + |
|
| 218 | + $rating_url = esc_url( |
|
| 219 | + wp_nonce_url( |
|
| 220 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 221 | + 'getpaid-nonce', |
|
| 222 | + 'getpaid-nonce' |
|
| 223 | + ) |
|
| 224 | + ); |
|
| 225 | + |
|
| 226 | + $footer_text = sprintf( |
|
| 227 | + /* translators: %s: five stars */ |
|
| 228 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 229 | + "<a href='$rating_url'>★★★★★</a>" |
|
| 230 | + ); |
|
| 231 | + |
|
| 232 | + } else { |
|
| 233 | + |
|
| 234 | + $footer_text = sprintf( |
|
| 235 | + /* translators: %s: GetPaid */ |
|
| 236 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
| 237 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + return $footer_text; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Redirects to wp.org to rate the plugin. |
|
| 249 | + * |
|
| 250 | + * @since 2.0.0 |
|
| 251 | + */ |
|
| 252 | + public function redirect_to_wordpress_rating_page() { |
|
| 253 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 254 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 255 | + exit; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | - * Loads payment form js. |
|
| 260 | - * |
|
| 261 | - */ |
|
| 262 | - protected function load_payment_form_scripts() { |
|
| 259 | + * Loads payment form js. |
|
| 260 | + * |
|
| 261 | + */ |
|
| 262 | + protected function load_payment_form_scripts() { |
|
| 263 | 263 | global $post; |
| 264 | 264 | |
| 265 | 265 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
| 266 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 267 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 266 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 267 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 268 | 268 | |
| 269 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 270 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 269 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 270 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 271 | 271 | |
| 272 | - wp_localize_script( |
|
| 272 | + wp_localize_script( |
|
| 273 | 273 | 'wpinv-admin-payment-form-script', |
| 274 | 274 | 'wpinvPaymentFormAdmin', |
| 275 | 275 | array( |
| 276 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 277 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 278 | - 'currency' => wpinv_currency_symbol(), |
|
| 279 | - 'position' => wpinv_currency_position(), |
|
| 280 | - 'decimals' => (int) wpinv_decimals(), |
|
| 281 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
| 282 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
| 283 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 284 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 276 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 277 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 278 | + 'currency' => wpinv_currency_symbol(), |
|
| 279 | + 'position' => wpinv_currency_position(), |
|
| 280 | + 'decimals' => (int) wpinv_decimals(), |
|
| 281 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
| 282 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
| 283 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 284 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 285 | 285 | ) |
| 286 | 286 | ); |
| 287 | 287 | |
@@ -290,20 +290,20 @@ discard block |
||
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
| 293 | - * Add our classes to admin pages. |
|
| 293 | + * Add our classes to admin pages. |
|
| 294 | 294 | * |
| 295 | 295 | * @param string $classes |
| 296 | 296 | * @return string |
| 297 | - * |
|
| 298 | - */ |
|
| 297 | + * |
|
| 298 | + */ |
|
| 299 | 299 | public function admin_body_class( $classes ) { |
| 300 | - global $pagenow, $post, $current_screen; |
|
| 300 | + global $pagenow, $post, $current_screen; |
|
| 301 | 301 | |
| 302 | 302 | |
| 303 | 303 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
| 304 | 304 | |
| 305 | 305 | if ( ! empty( $current_screen->post_type ) ) { |
| 306 | - $page = $current_screen->post_type; |
|
| 306 | + $page = $current_screen->post_type; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -312,59 +312,59 @@ discard block |
||
| 312 | 312 | |
| 313 | 313 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
| 314 | 314 | $classes .= ' wpinv-cpt wpinv'; |
| 315 | - } |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 317 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 318 | 318 | $classes .= ' getpaid-is-invoice-cpt'; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - return $classes; |
|
| 321 | + return $classes; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
| 325 | - * Maybe show the AyeCode Connect Notice. |
|
| 326 | - */ |
|
| 327 | - public function init_ayecode_connect_helper(){ |
|
| 325 | + * Maybe show the AyeCode Connect Notice. |
|
| 326 | + */ |
|
| 327 | + public function init_ayecode_connect_helper(){ |
|
| 328 | 328 | |
| 329 | 329 | new AyeCode_Connect_Helper( |
| 330 | 330 | array( |
| 331 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 332 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 333 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 334 | - 'connect_button' => __("Connect Site","invoicing"), |
|
| 335 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
| 336 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 337 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 331 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 332 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 333 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 334 | + 'connect_button' => __("Connect Site","invoicing"), |
|
| 335 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
| 336 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 337 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 338 | 338 | ), |
| 339 | 339 | array( 'wpi-addons' ) |
| 340 | 340 | ); |
| 341 | 341 | |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - /** |
|
| 345 | - * Redirect users to settings on activation. |
|
| 346 | - * |
|
| 347 | - * @return void |
|
| 348 | - */ |
|
| 349 | - public function activation_redirect() { |
|
| 344 | + /** |
|
| 345 | + * Redirect users to settings on activation. |
|
| 346 | + * |
|
| 347 | + * @return void |
|
| 348 | + */ |
|
| 349 | + public function activation_redirect() { |
|
| 350 | 350 | |
| 351 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 351 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 352 | 352 | |
| 353 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 354 | - return; |
|
| 355 | - } |
|
| 353 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 354 | + return; |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - // Bail if activating from network, or bulk |
|
| 358 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 359 | - return; |
|
| 360 | - } |
|
| 357 | + // Bail if activating from network, or bulk |
|
| 358 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 359 | + return; |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 362 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 363 | 363 | |
| 364 | 364 | wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
| 365 | 365 | exit; |
| 366 | 366 | |
| 367 | - } |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | 369 | /** |
| 370 | 370 | * Fires an admin action after verifying that a user can fire them. |
@@ -378,261 +378,261 @@ discard block |
||
| 378 | 378 | |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - /** |
|
| 381 | + /** |
|
| 382 | 382 | * Sends a payment reminder to a customer. |
| 383 | - * |
|
| 384 | - * @param array $args |
|
| 383 | + * |
|
| 384 | + * @param array $args |
|
| 385 | 385 | */ |
| 386 | 386 | public function send_customer_invoice( $args ) { |
| 387 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 387 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 388 | 388 | |
| 389 | - if ( $sent ) { |
|
| 390 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
| 391 | - } else { |
|
| 392 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
| 393 | - } |
|
| 389 | + if ( $sent ) { |
|
| 390 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
| 391 | + } else { |
|
| 392 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 396 | - exit; |
|
| 397 | - } |
|
| 395 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 396 | + exit; |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - /** |
|
| 399 | + /** |
|
| 400 | 400 | * Sends a payment reminder to a customer. |
| 401 | - * |
|
| 402 | - * @param array $args |
|
| 401 | + * |
|
| 402 | + * @param array $args |
|
| 403 | 403 | */ |
| 404 | 404 | public function send_customer_payment_reminder( $args ) { |
| 405 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 405 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 406 | 406 | |
| 407 | - if ( $sent ) { |
|
| 408 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 409 | - } else { |
|
| 410 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 411 | - } |
|
| 407 | + if ( $sent ) { |
|
| 408 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 409 | + } else { |
|
| 410 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 414 | - exit; |
|
| 415 | - } |
|
| 413 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 414 | + exit; |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | - /** |
|
| 417 | + /** |
|
| 418 | 418 | * Resets tax rates. |
| 419 | - * |
|
| 419 | + * |
|
| 420 | 420 | */ |
| 421 | 421 | public function admin_reset_tax_rates() { |
| 422 | 422 | |
| 423 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 424 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 425 | - exit; |
|
| 423 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 424 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 425 | + exit; |
|
| 426 | 426 | |
| 427 | - } |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - /** |
|
| 429 | + /** |
|
| 430 | 430 | * Resets admin pages. |
| 431 | - * |
|
| 431 | + * |
|
| 432 | 432 | */ |
| 433 | 433 | public function admin_create_missing_pages() { |
| 434 | - $installer = new GetPaid_Installer(); |
|
| 435 | - $installer->create_pages(); |
|
| 436 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 437 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 438 | - exit; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 434 | + $installer = new GetPaid_Installer(); |
|
| 435 | + $installer->create_pages(); |
|
| 436 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 437 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 438 | + exit; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | 442 | * Creates an missing admin tables. |
| 443 | - * |
|
| 443 | + * |
|
| 444 | 444 | */ |
| 445 | 445 | public function admin_create_missing_tables() { |
| 446 | - global $wpdb; |
|
| 447 | - $installer = new GetPaid_Installer(); |
|
| 446 | + global $wpdb; |
|
| 447 | + $installer = new GetPaid_Installer(); |
|
| 448 | 448 | |
| 449 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 450 | - $installer->create_subscriptions_table(); |
|
| 449 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 450 | + $installer->create_subscriptions_table(); |
|
| 451 | 451 | |
| 452 | - if ( $wpdb->last_error !== '' ) { |
|
| 453 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 454 | - } |
|
| 455 | - } |
|
| 452 | + if ( $wpdb->last_error !== '' ) { |
|
| 453 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | 456 | |
| 457 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 458 | - $installer->create_invoices_table(); |
|
| 457 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 458 | + $installer->create_invoices_table(); |
|
| 459 | 459 | |
| 460 | - if ( $wpdb->last_error !== '' ) { |
|
| 461 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 462 | - } |
|
| 463 | - } |
|
| 460 | + if ( $wpdb->last_error !== '' ) { |
|
| 461 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 462 | + } |
|
| 463 | + } |
|
| 464 | 464 | |
| 465 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 466 | - $installer->create_invoice_items_table(); |
|
| 465 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 466 | + $installer->create_invoice_items_table(); |
|
| 467 | 467 | |
| 468 | - if ( $wpdb->last_error !== '' ) { |
|
| 469 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 470 | - } |
|
| 471 | - } |
|
| 468 | + if ( $wpdb->last_error !== '' ) { |
|
| 469 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - if ( ! $this->has_notices() ) { |
|
| 474 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 475 | - } |
|
| 473 | + if ( ! $this->has_notices() ) { |
|
| 474 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 478 | - exit; |
|
| 479 | - } |
|
| 477 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 478 | + exit; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - /** |
|
| 481 | + /** |
|
| 482 | 482 | * Migrates old invoices to the new database tables. |
| 483 | - * |
|
| 483 | + * |
|
| 484 | 484 | */ |
| 485 | 485 | public function admin_migrate_old_invoices() { |
| 486 | 486 | |
| 487 | - // Migrate the invoices. |
|
| 488 | - $installer = new GetPaid_Installer(); |
|
| 489 | - $installer->migrate_old_invoices(); |
|
| 487 | + // Migrate the invoices. |
|
| 488 | + $installer = new GetPaid_Installer(); |
|
| 489 | + $installer->migrate_old_invoices(); |
|
| 490 | 490 | |
| 491 | - // Show an admin message. |
|
| 492 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 491 | + // Show an admin message. |
|
| 492 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 493 | 493 | |
| 494 | - // Redirect the admin. |
|
| 495 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 496 | - exit; |
|
| 494 | + // Redirect the admin. |
|
| 495 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 496 | + exit; |
|
| 497 | 497 | |
| 498 | - } |
|
| 498 | + } |
|
| 499 | 499 | |
| 500 | 500 | /** |
| 501 | - * Returns an array of admin notices. |
|
| 502 | - * |
|
| 503 | - * @since 1.0.19 |
|
| 501 | + * Returns an array of admin notices. |
|
| 502 | + * |
|
| 503 | + * @since 1.0.19 |
|
| 504 | 504 | * @return array |
| 505 | - */ |
|
| 506 | - public function get_notices() { |
|
| 507 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
| 505 | + */ |
|
| 506 | + public function get_notices() { |
|
| 507 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
| 508 | 508 | return is_array( $notices ) ? $notices : array(); |
| 509 | - } |
|
| 509 | + } |
|
| 510 | 510 | |
| 511 | - /** |
|
| 512 | - * Checks if we have any admin notices. |
|
| 513 | - * |
|
| 514 | - * @since 2.0.4 |
|
| 511 | + /** |
|
| 512 | + * Checks if we have any admin notices. |
|
| 513 | + * |
|
| 514 | + * @since 2.0.4 |
|
| 515 | 515 | * @return array |
| 516 | - */ |
|
| 517 | - public function has_notices() { |
|
| 518 | - return count( $this->get_notices() ) > 0; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Clears all admin notices |
|
| 523 | - * |
|
| 524 | - * @access public |
|
| 525 | - * @since 1.0.19 |
|
| 526 | - */ |
|
| 527 | - public function clear_notices() { |
|
| 528 | - delete_option( 'wpinv_admin_notices' ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Saves a new admin notice |
|
| 533 | - * |
|
| 534 | - * @access public |
|
| 535 | - * @since 1.0.19 |
|
| 536 | - */ |
|
| 537 | - public function save_notice( $type, $message ) { |
|
| 538 | - $notices = $this->get_notices(); |
|
| 539 | - |
|
| 540 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 541 | - $notices[ $type ] = array(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - $notices[ $type ][] = $message; |
|
| 545 | - |
|
| 546 | - update_option( 'wpinv_admin_notices', $notices ); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Displays a success notice |
|
| 551 | - * |
|
| 552 | - * @param string $msg The message to qeue. |
|
| 553 | - * @access public |
|
| 554 | - * @since 1.0.19 |
|
| 555 | - */ |
|
| 556 | - public function show_success( $msg ) { |
|
| 557 | - $this->save_notice( 'success', $msg ); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Displays a error notice |
|
| 562 | - * |
|
| 563 | - * @access public |
|
| 564 | - * @param string $msg The message to qeue. |
|
| 565 | - * @since 1.0.19 |
|
| 566 | - */ |
|
| 567 | - public function show_error( $msg ) { |
|
| 568 | - $this->save_notice( 'error', $msg ); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Displays a warning notice |
|
| 573 | - * |
|
| 574 | - * @access public |
|
| 575 | - * @param string $msg The message to qeue. |
|
| 576 | - * @since 1.0.19 |
|
| 577 | - */ |
|
| 578 | - public function show_warning( $msg ) { |
|
| 579 | - $this->save_notice( 'warning', $msg ); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * Displays a info notice |
|
| 584 | - * |
|
| 585 | - * @access public |
|
| 586 | - * @param string $msg The message to qeue. |
|
| 587 | - * @since 1.0.19 |
|
| 588 | - */ |
|
| 589 | - public function show_info( $msg ) { |
|
| 590 | - $this->save_notice( 'info', $msg ); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Show notices |
|
| 595 | - * |
|
| 596 | - * @access public |
|
| 597 | - * @since 1.0.19 |
|
| 598 | - */ |
|
| 599 | - public function show_notices() { |
|
| 516 | + */ |
|
| 517 | + public function has_notices() { |
|
| 518 | + return count( $this->get_notices() ) > 0; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Clears all admin notices |
|
| 523 | + * |
|
| 524 | + * @access public |
|
| 525 | + * @since 1.0.19 |
|
| 526 | + */ |
|
| 527 | + public function clear_notices() { |
|
| 528 | + delete_option( 'wpinv_admin_notices' ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Saves a new admin notice |
|
| 533 | + * |
|
| 534 | + * @access public |
|
| 535 | + * @since 1.0.19 |
|
| 536 | + */ |
|
| 537 | + public function save_notice( $type, $message ) { |
|
| 538 | + $notices = $this->get_notices(); |
|
| 539 | + |
|
| 540 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 541 | + $notices[ $type ] = array(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + $notices[ $type ][] = $message; |
|
| 545 | + |
|
| 546 | + update_option( 'wpinv_admin_notices', $notices ); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Displays a success notice |
|
| 551 | + * |
|
| 552 | + * @param string $msg The message to qeue. |
|
| 553 | + * @access public |
|
| 554 | + * @since 1.0.19 |
|
| 555 | + */ |
|
| 556 | + public function show_success( $msg ) { |
|
| 557 | + $this->save_notice( 'success', $msg ); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Displays a error notice |
|
| 562 | + * |
|
| 563 | + * @access public |
|
| 564 | + * @param string $msg The message to qeue. |
|
| 565 | + * @since 1.0.19 |
|
| 566 | + */ |
|
| 567 | + public function show_error( $msg ) { |
|
| 568 | + $this->save_notice( 'error', $msg ); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Displays a warning notice |
|
| 573 | + * |
|
| 574 | + * @access public |
|
| 575 | + * @param string $msg The message to qeue. |
|
| 576 | + * @since 1.0.19 |
|
| 577 | + */ |
|
| 578 | + public function show_warning( $msg ) { |
|
| 579 | + $this->save_notice( 'warning', $msg ); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Displays a info notice |
|
| 584 | + * |
|
| 585 | + * @access public |
|
| 586 | + * @param string $msg The message to qeue. |
|
| 587 | + * @since 1.0.19 |
|
| 588 | + */ |
|
| 589 | + public function show_info( $msg ) { |
|
| 590 | + $this->save_notice( 'info', $msg ); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Show notices |
|
| 595 | + * |
|
| 596 | + * @access public |
|
| 597 | + * @since 1.0.19 |
|
| 598 | + */ |
|
| 599 | + public function show_notices() { |
|
| 600 | 600 | |
| 601 | 601 | $notices = $this->get_notices(); |
| 602 | 602 | $this->clear_notices(); |
| 603 | 603 | |
| 604 | - foreach ( $notices as $type => $messages ) { |
|
| 604 | + foreach ( $notices as $type => $messages ) { |
|
| 605 | 605 | |
| 606 | - if ( ! is_array( $messages ) ) { |
|
| 607 | - continue; |
|
| 608 | - } |
|
| 606 | + if ( ! is_array( $messages ) ) { |
|
| 607 | + continue; |
|
| 608 | + } |
|
| 609 | 609 | |
| 610 | 610 | $type = sanitize_key( $type ); |
| 611 | - foreach ( $messages as $message ) { |
|
| 611 | + foreach ( $messages as $message ) { |
|
| 612 | 612 | $message = wp_kses_post( $message ); |
| 613 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 613 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 619 | + |
|
| 620 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 621 | + $url = esc_url( |
|
| 622 | + wp_nonce_url( |
|
| 623 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 624 | + 'getpaid-nonce', |
|
| 625 | + 'getpaid-nonce' |
|
| 626 | + ) |
|
| 627 | + ); |
|
| 628 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 629 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 630 | + echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
| 631 | + break; |
|
| 614 | 632 | } |
| 615 | 633 | |
| 616 | 634 | } |
| 617 | 635 | |
| 618 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 619 | - |
|
| 620 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 621 | - $url = esc_url( |
|
| 622 | - wp_nonce_url( |
|
| 623 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 624 | - 'getpaid-nonce', |
|
| 625 | - 'getpaid-nonce' |
|
| 626 | - ) |
|
| 627 | - ); |
|
| 628 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 629 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 630 | - echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
| 631 | - break; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - } |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | 638 | } |
@@ -14,534 +14,534 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @param 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( 'session', new WPInv_Session_Handler() ); |
|
| 90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 91 | - $this->set( 'api', new WPInv_API() ); |
|
| 92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 93 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 101 | - |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Define plugin constants. |
|
| 106 | - */ |
|
| 107 | - public function define_constants() { |
|
| 108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 110 | - $this->version = WPINV_VERSION; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Hook into actions and filters. |
|
| 115 | - * |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - */ |
|
| 118 | - protected function init_hooks() { |
|
| 119 | - /* Internationalize the text strings used. */ |
|
| 120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 121 | - |
|
| 122 | - // Init the plugin after WordPress inits. |
|
| 123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 127 | - |
|
| 128 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 129 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 133 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 134 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 135 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 136 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 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 the translation of the plugin. |
|
| 158 | - * |
|
| 159 | - * @since 1.0 |
|
| 160 | - */ |
|
| 161 | - public function load_textdomain( $locale = NULL ) { |
|
| 162 | - if ( empty( $locale ) ) { |
|
| 163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 167 | - |
|
| 168 | - unload_textdomain( 'invoicing' ); |
|
| 169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Define language constants. |
|
| 174 | - */ |
|
| 175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Include required core files used in admin and on the frontend. |
|
| 180 | - */ |
|
| 181 | - public function includes() { |
|
| 182 | - |
|
| 183 | - // Start with the settings. |
|
| 184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 185 | - |
|
| 186 | - // Packages/libraries. |
|
| 187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 189 | - |
|
| 190 | - // Load functions. |
|
| 191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
| 200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
| 205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 206 | - |
|
| 207 | - // Register autoloader. |
|
| 208 | - try { |
|
| 209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 210 | - } catch ( Exception $e ) { |
|
| 211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.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 | - |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Inits hooks etc. |
|
| 310 | - */ |
|
| 311 | - public function init() { |
|
| 312 | - |
|
| 313 | - // Fires before getpaid inits. |
|
| 314 | - do_action( 'before_getpaid_init', $this ); |
|
| 315 | - |
|
| 316 | - // Maybe upgrade. |
|
| 317 | - $this->maybe_upgrade_database(); |
|
| 318 | - |
|
| 319 | - // Load default gateways. |
|
| 320 | - $gateways = apply_filters( |
|
| 321 | - 'getpaid_default_gateways', |
|
| 322 | - array( |
|
| 323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 328 | - ) |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - foreach ( $gateways as $id => $class ) { |
|
| 332 | - $this->gateways[ $id ] = new $class(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // Fires after getpaid inits. |
|
| 336 | - do_action( 'getpaid_init', $this ); |
|
| 337 | - |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Checks if this is an IPN request and processes it. |
|
| 342 | - */ |
|
| 343 | - public function maybe_process_ipn() { |
|
| 344 | - |
|
| 345 | - // Ensure that this is an IPN request. |
|
| 346 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 347 | - return; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 351 | - |
|
| 352 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 353 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 354 | - exit; |
|
| 355 | - |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - public function enqueue_scripts() { |
|
| 359 | - |
|
| 360 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 361 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 362 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 363 | - |
|
| 364 | - $localize = array(); |
|
| 365 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 366 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 367 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 368 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 369 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 370 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 371 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 372 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 373 | - |
|
| 374 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 375 | - |
|
| 376 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 377 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 378 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - public function wpinv_actions() { |
|
| 382 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 383 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 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 | + * @param 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( 'session', new WPInv_Session_Handler() ); |
|
| 90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 91 | + $this->set( 'api', new WPInv_API() ); |
|
| 92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 93 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Define plugin constants. |
|
| 106 | + */ |
|
| 107 | + public function define_constants() { |
|
| 108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 110 | + $this->version = WPINV_VERSION; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Hook into actions and filters. |
|
| 115 | + * |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + */ |
|
| 118 | + protected function init_hooks() { |
|
| 119 | + /* Internationalize the text strings used. */ |
|
| 120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 121 | + |
|
| 122 | + // Init the plugin after WordPress inits. |
|
| 123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 127 | + |
|
| 128 | + if ( class_exists( 'BuddyPress' ) ) { |
|
| 129 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 133 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 134 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 135 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 136 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 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 the translation of the plugin. |
|
| 158 | + * |
|
| 159 | + * @since 1.0 |
|
| 160 | + */ |
|
| 161 | + public function load_textdomain( $locale = NULL ) { |
|
| 162 | + if ( empty( $locale ) ) { |
|
| 163 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 167 | + |
|
| 168 | + unload_textdomain( 'invoicing' ); |
|
| 169 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 170 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Define language constants. |
|
| 174 | + */ |
|
| 175 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Include required core files used in admin and on the frontend. |
|
| 180 | + */ |
|
| 181 | + public function includes() { |
|
| 182 | + |
|
| 183 | + // Start with the settings. |
|
| 184 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 185 | + |
|
| 186 | + // Packages/libraries. |
|
| 187 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 188 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 189 | + |
|
| 190 | + // Load functions. |
|
| 191 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 194 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 195 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 198 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 199 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
| 200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 204 | + require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
| 205 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 206 | + |
|
| 207 | + // Register autoloader. |
|
| 208 | + try { |
|
| 209 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 210 | + } catch ( Exception $e ) { |
|
| 211 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 216 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 219 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 220 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 222 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 225 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 230 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 231 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 233 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.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 | + |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Inits hooks etc. |
|
| 310 | + */ |
|
| 311 | + public function init() { |
|
| 312 | + |
|
| 313 | + // Fires before getpaid inits. |
|
| 314 | + do_action( 'before_getpaid_init', $this ); |
|
| 315 | + |
|
| 316 | + // Maybe upgrade. |
|
| 317 | + $this->maybe_upgrade_database(); |
|
| 318 | + |
|
| 319 | + // Load default gateways. |
|
| 320 | + $gateways = apply_filters( |
|
| 321 | + 'getpaid_default_gateways', |
|
| 322 | + array( |
|
| 323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 328 | + ) |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + foreach ( $gateways as $id => $class ) { |
|
| 332 | + $this->gateways[ $id ] = new $class(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // Fires after getpaid inits. |
|
| 336 | + do_action( 'getpaid_init', $this ); |
|
| 337 | + |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Checks if this is an IPN request and processes it. |
|
| 342 | + */ |
|
| 343 | + public function maybe_process_ipn() { |
|
| 344 | + |
|
| 345 | + // Ensure that this is an IPN request. |
|
| 346 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 347 | + return; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 351 | + |
|
| 352 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 353 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 354 | + exit; |
|
| 355 | + |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + public function enqueue_scripts() { |
|
| 359 | + |
|
| 360 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 361 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 362 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
| 363 | + |
|
| 364 | + $localize = array(); |
|
| 365 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 366 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 367 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 368 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 369 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 370 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 371 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 372 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 373 | + |
|
| 374 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 375 | + |
|
| 376 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 377 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 378 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + public function wpinv_actions() { |
|
| 382 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 383 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | 388 | * Fires an action after verifying that a user can fire them. |
| 389 | - * |
|
| 390 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 391 | - * current user owns the invoice/subscription. |
|
| 389 | + * |
|
| 390 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 391 | + * current user owns the invoice/subscription. |
|
| 392 | 392 | */ |
| 393 | 393 | public function maybe_do_authenticated_action() { |
| 394 | 394 | |
| 395 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 395 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 396 | + |
|
| 397 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 398 | + $data = wp_unslash( $_REQUEST ); |
|
| 399 | + if ( is_user_logged_in() ) { |
|
| 400 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 401 | + } |
|
| 396 | 402 | |
| 397 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 398 | - $data = wp_unslash( $_REQUEST ); |
|
| 399 | - if ( is_user_logged_in() ) { |
|
| 400 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 401 | - } |
|
| 403 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 404 | + |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + } |
|
| 402 | 408 | |
| 403 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 409 | + public function pre_get_posts( $wp_query ) { |
|
| 404 | 410 | |
| 405 | - } |
|
| 411 | + 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() ) { |
|
| 412 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 413 | + } |
|
| 406 | 414 | |
| 415 | + return $wp_query; |
|
| 407 | 416 | } |
| 408 | 417 | |
| 409 | - public function pre_get_posts( $wp_query ) { |
|
| 410 | - |
|
| 411 | - 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() ) { |
|
| 412 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - return $wp_query; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - public function bp_invoicing_init() { |
|
| 419 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Register widgets |
|
| 424 | - * |
|
| 425 | - */ |
|
| 426 | - public function register_widgets() { |
|
| 427 | - |
|
| 428 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 429 | - // So we disable our widgets when editing a page with UX Builder. |
|
| 430 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 431 | - return; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - $widgets = apply_filters( |
|
| 435 | - 'getpaid_widget_classes', |
|
| 436 | - array( |
|
| 437 | - 'WPInv_Checkout_Widget', |
|
| 438 | - 'WPInv_History_Widget', |
|
| 439 | - 'WPInv_Receipt_Widget', |
|
| 440 | - 'WPInv_Subscriptions_Widget', |
|
| 441 | - 'WPInv_Buy_Item_Widget', |
|
| 442 | - 'WPInv_Messages_Widget', |
|
| 443 | - 'WPInv_GetPaid_Widget' |
|
| 444 | - ) |
|
| 445 | - ); |
|
| 446 | - |
|
| 447 | - foreach ( $widgets as $widget ) { |
|
| 448 | - register_widget( $widget ); |
|
| 449 | - } |
|
| 418 | + public function bp_invoicing_init() { |
|
| 419 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Register widgets |
|
| 424 | + * |
|
| 425 | + */ |
|
| 426 | + public function register_widgets() { |
|
| 427 | + |
|
| 428 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 429 | + // So we disable our widgets when editing a page with UX Builder. |
|
| 430 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 431 | + return; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + $widgets = apply_filters( |
|
| 435 | + 'getpaid_widget_classes', |
|
| 436 | + array( |
|
| 437 | + 'WPInv_Checkout_Widget', |
|
| 438 | + 'WPInv_History_Widget', |
|
| 439 | + 'WPInv_Receipt_Widget', |
|
| 440 | + 'WPInv_Subscriptions_Widget', |
|
| 441 | + 'WPInv_Buy_Item_Widget', |
|
| 442 | + 'WPInv_Messages_Widget', |
|
| 443 | + 'WPInv_GetPaid_Widget' |
|
| 444 | + ) |
|
| 445 | + ); |
|
| 446 | + |
|
| 447 | + foreach ( $widgets as $widget ) { |
|
| 448 | + register_widget( $widget ); |
|
| 449 | + } |
|
| 450 | 450 | |
| 451 | - } |
|
| 451 | + } |
|
| 452 | 452 | |
| 453 | - /** |
|
| 454 | - * Upgrades the database. |
|
| 455 | - * |
|
| 456 | - * @since 2.0.2 |
|
| 457 | - */ |
|
| 458 | - public function maybe_upgrade_database() { |
|
| 453 | + /** |
|
| 454 | + * Upgrades the database. |
|
| 455 | + * |
|
| 456 | + * @since 2.0.2 |
|
| 457 | + */ |
|
| 458 | + public function maybe_upgrade_database() { |
|
| 459 | 459 | |
| 460 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 460 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 461 | 461 | |
| 462 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 463 | - return; |
|
| 464 | - } |
|
| 462 | + if ( $wpi_version == WPINV_VERSION ) { |
|
| 463 | + return; |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - $installer = new GetPaid_Installer(); |
|
| 466 | + $installer = new GetPaid_Installer(); |
|
| 467 | 467 | |
| 468 | - if ( empty( $wpi_version ) ) { |
|
| 469 | - return $installer->upgrade_db( 0 ); |
|
| 470 | - } |
|
| 468 | + if ( empty( $wpi_version ) ) { |
|
| 469 | + return $installer->upgrade_db( 0 ); |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | - $upgrades = array( |
|
| 473 | - '0.0.5' => '004', |
|
| 474 | - '1.0.3' => '102', |
|
| 475 | - '2.0.0' => '118', |
|
| 476 | - '2.0.8' => '207', |
|
| 477 | - ); |
|
| 472 | + $upgrades = array( |
|
| 473 | + '0.0.5' => '004', |
|
| 474 | + '1.0.3' => '102', |
|
| 475 | + '2.0.0' => '118', |
|
| 476 | + '2.0.8' => '207', |
|
| 477 | + ); |
|
| 478 | 478 | |
| 479 | - foreach ( $upgrades as $key => $method ) { |
|
| 479 | + foreach ( $upgrades as $key => $method ) { |
|
| 480 | 480 | |
| 481 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 482 | - return $installer->upgrade_db( $method ); |
|
| 483 | - } |
|
| 481 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 482 | + return $installer->upgrade_db( $method ); |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | - } |
|
| 485 | + } |
|
| 486 | 486 | |
| 487 | - } |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - /** |
|
| 490 | - * Flushes the permalinks if needed. |
|
| 491 | - * |
|
| 492 | - * @since 2.0.8 |
|
| 493 | - */ |
|
| 494 | - public function maybe_flush_permalinks() { |
|
| 489 | + /** |
|
| 490 | + * Flushes the permalinks if needed. |
|
| 491 | + * |
|
| 492 | + * @since 2.0.8 |
|
| 493 | + */ |
|
| 494 | + public function maybe_flush_permalinks() { |
|
| 495 | 495 | |
| 496 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 496 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 497 | 497 | |
| 498 | - if ( ! empty( $flush ) ) { |
|
| 499 | - flush_rewrite_rules(); |
|
| 500 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 501 | - } |
|
| 498 | + if ( ! empty( $flush ) ) { |
|
| 499 | + flush_rewrite_rules(); |
|
| 500 | + delete_option( 'wpinv_flush_permalinks' ); |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | - } |
|
| 503 | + } |
|
| 504 | 504 | |
| 505 | - /** |
|
| 506 | - * Remove our pages from yoast sitemaps. |
|
| 507 | - * |
|
| 508 | - * @since 1.0.19 |
|
| 509 | - * @param int[] $excluded_posts_ids |
|
| 510 | - */ |
|
| 511 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 505 | + /** |
|
| 506 | + * Remove our pages from yoast sitemaps. |
|
| 507 | + * |
|
| 508 | + * @since 1.0.19 |
|
| 509 | + * @param int[] $excluded_posts_ids |
|
| 510 | + */ |
|
| 511 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 512 | 512 | |
| 513 | - // Ensure that we have an array. |
|
| 514 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 515 | - $excluded_posts_ids = array(); |
|
| 516 | - } |
|
| 513 | + // Ensure that we have an array. |
|
| 514 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 515 | + $excluded_posts_ids = array(); |
|
| 516 | + } |
|
| 517 | 517 | |
| 518 | - // Prepare our pages. |
|
| 519 | - $our_pages = array(); |
|
| 518 | + // Prepare our pages. |
|
| 519 | + $our_pages = array(); |
|
| 520 | 520 | |
| 521 | - // Checkout page. |
|
| 522 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 521 | + // Checkout page. |
|
| 522 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 523 | 523 | |
| 524 | - // Success page. |
|
| 525 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 524 | + // Success page. |
|
| 525 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 526 | 526 | |
| 527 | - // Failure page. |
|
| 528 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 527 | + // Failure page. |
|
| 528 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 529 | 529 | |
| 530 | - // History page. |
|
| 531 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 530 | + // History page. |
|
| 531 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 532 | 532 | |
| 533 | - // Subscriptions page. |
|
| 534 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 533 | + // Subscriptions page. |
|
| 534 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 535 | 535 | |
| 536 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 536 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 537 | 537 | |
| 538 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 539 | - return array_unique( $excluded_posts_ids ); |
|
| 538 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 539 | + return array_unique( $excluded_posts_ids ); |
|
| 540 | 540 | |
| 541 | - } |
|
| 541 | + } |
|
| 542 | 542 | |
| 543 | - public function wp_footer() { |
|
| 544 | - echo ' |
|
| 543 | + public function wp_footer() { |
|
| 544 | + echo ' |
|
| 545 | 545 | <div class="bsui"> |
| 546 | 546 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
| 547 | 547 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -557,6 +557,6 @@ discard block |
||
| 557 | 557 | </div> |
| 558 | 558 | </div> |
| 559 | 559 | '; |
| 560 | - } |
|
| 560 | + } |
|
| 561 | 561 | |
| 562 | 562 | } |