Passed
Pull Request — master (#409)
by Brian
15:26 queued 10:36
created
includes/class-wpinv.php 1 patch
Indentation   +490 added lines, -490 removed lines patch added patch discarded remove patch
@@ -14,508 +14,508 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * Tax instance.
40
-	 *
41
-	 * @var WPInv_EUVat
42
-	 */
43
-	public $tax;
44
-
45
-	/**
46
-	 * @param array An array of payment gateways.
47
-	 */
48
-	public $gateways;
49
-
50
-	/**
51
-	 * Class constructor.
52
-	 */
53
-	public function __construct() {
54
-		$this->define_constants();
55
-		$this->includes();
56
-		$this->init_hooks();
57
-		$this->set_properties();
58
-	}
59
-
60
-	/**
61
-	 * Sets a custom data property.
62
-	 * 
63
-	 * @param string $prop The prop to set.
64
-	 * @param mixed $value The value to retrieve.
65
-	 */
66
-	public function set( $prop, $value ) {
67
-		$this->data[ $prop ] = $value;
68
-	}
69
-
70
-	/**
71
-	 * Gets a custom data property.
72
-	 * 
73
-	 * @param string $prop The prop to set.
74
-	 * @return mixed The value.
75
-	 */
76
-	public function get( $prop ) {
77
-
78
-		if ( isset( $this->data[ $prop ] ) ) {
79
-			return $this->data[ $prop ];
80
-		}
81
-
82
-		return null;
83
-	}
84
-
85
-	/**
86
-	 * Define class properties.
87
-	 */
88
-	public function set_properties() {
89
-
90
-		// Sessions.
91
-		$this->set( 'session', new WPInv_Session_Handler() );
92
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
93
-		$this->form_elements = new WPInv_Payment_Form_Elements();
94
-		$this->tax           = new WPInv_EUVat();
95
-		$this->tax->init();
96
-		$GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
97
-
98
-		// Init other objects.
99
-		$this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
100
-		$this->set( 'session', new WPInv_Session_Handler() );
101
-		$this->set( 'notes', new WPInv_Notes() );
102
-		$this->set( 'api', new WPInv_API() );
103
-		$this->set( 'post_types', new GetPaid_Post_Types() );
104
-		$this->set( 'template', new GetPaid_Template() );
105
-		$this->set( 'admin', new GetPaid_Admin() );
106
-	}
107
-
108
-	 /**
109
-	 * Define plugin constants.
110
-	 */
111
-	public function define_constants() {
112
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
113
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
114
-		$this->version = WPINV_VERSION;
115
-	}
116
-
117
-	/**
118
-	 * Hook into actions and filters.
119
-	 *
120
-	 * @since 1.0.19
121
-	 */
122
-	protected function init_hooks() {
123
-		/* Internationalize the text strings used. */
124
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
125
-
126
-		// Init the plugin after WordPress inits.
127
-		add_action( 'init', array( $this, 'init' ), 1 );
128
-		add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
129
-		add_action( 'init', array( &$this, 'wpinv_actions' ) );
130
-
131
-		if ( class_exists( 'BuddyPress' ) ) {
132
-			add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
133
-		}
134
-
135
-		add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
136
-		add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
137
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
138
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
139
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
140
-
141
-		// Fires after registering actions.
142
-		do_action( 'wpinv_actions', $this );
143
-		do_action( 'getpaid_actions', $this );
144
-
145
-	}
146
-
147
-	public function plugins_loaded() {
148
-		/* Internationalize the text strings used. */
149
-		$this->load_textdomain();
150
-
151
-		do_action( 'wpinv_loaded' );
152
-
153
-		// Fix oxygen page builder conflict
154
-		if ( function_exists( 'ct_css_output' ) ) {
155
-			wpinv_oxygen_fix_conflict();
156
-		}
157
-	}
158
-
159
-	/**
160
-	 * Load the translation of the plugin.
161
-	 *
162
-	 * @since 1.0
163
-	 */
164
-	public function load_textdomain( $locale = NULL ) {
165
-		if ( empty( $locale ) ) {
166
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
167
-		}
168
-
169
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
170
-
171
-		unload_textdomain( 'invoicing' );
172
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
173
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
174
-
175
-		/**
176
-		 * Define language constants.
177
-		 */
178
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
179
-	}
180
-
181
-	/**
182
-	 * Include required core files used in admin and on the frontend.
183
-	 */
184
-	public function includes() {
185
-
186
-		// Start with the settings.
187
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
188
-
189
-		// Packages/libraries.
190
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
191
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
193
-
194
-		// Load functions.
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
206
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
207
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
208
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
209
-
210
-		// Register autoloader.
211
-		try {
212
-			spl_autoload_register( array( $this, 'autoload' ), true );
213
-		} catch ( Exception $e ) {
214
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
215
-		}
216
-
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
235
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
236
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
237
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
238
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
239
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
240
-
241
-		/**
242
-		 * Load the tax class.
243
-		 */
244
-		if ( ! class_exists( 'WPInv_EUVat' ) ) {
245
-			require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
246
-		}
247
-
248
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
249
-		if ( !empty( $gateways ) ) {
250
-			foreach ( $gateways as $gateway ) {
251
-				if ( $gateway == 'manual' ) {
252
-					continue;
253
-				}
254
-
255
-				$gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
256
-
257
-				if ( file_exists( $gateway_file ) ) {
258
-					require_once( $gateway_file );
259
-				}
260
-			}
261
-		}
262
-
263
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
264
-			GetPaid_Post_Types_Admin::init();
265
-
266
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
267
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
268
-			//require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
269
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
270
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
271
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
272
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
273
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
274
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
275
-			//require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
276
-			// load the user class only on the users.php page
277
-			global $pagenow;
278
-			if($pagenow=='users.php'){
279
-				new WPInv_Admin_Users();
280
-			}
281
-		}
282
-
283
-		// Register cli commands
284
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
285
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
286
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
287
-		}
288
-
289
-		// include css inliner
290
-		if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
291
-			include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
292
-		}
293
-
294
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
295
-	}
296
-
297
-	/**
298
-	 * Class autoloader
299
-	 *
300
-	 * @param       string $class_name The name of the class to load.
301
-	 * @access      public
302
-	 * @since       1.0.19
303
-	 * @return      void
304
-	 */
305
-	public function autoload( $class_name ) {
306
-
307
-		// Normalize the class name...
308
-		$class_name  = strtolower( $class_name );
309
-
310
-		// ... and make sure it is our class.
311
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
312
-			return;
313
-		}
314
-
315
-		// Next, prepare the file name from the class.
316
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
317
-
318
-		// Base path of the classes.
319
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
320
-
321
-		// And an array of possible locations in order of importance.
322
-		$locations = array(
323
-			"$plugin_path/includes",
324
-			"$plugin_path/includes/data-stores",
325
-			"$plugin_path/includes/gateways",
326
-			"$plugin_path/includes/api",
327
-			"$plugin_path/includes/admin",
328
-			"$plugin_path/includes/admin/meta-boxes",
329
-		);
330
-
331
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
332
-
333
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
334
-				include trailingslashit( $location ) . $file_name;
335
-				break;
336
-			}
337
-
338
-		}
339
-
340
-	}
341
-
342
-	/**
343
-	 * Inits hooks etc.
344
-	 */
345
-	public function init() {
346
-
347
-		// Fires before getpaid inits.
348
-		do_action( 'before_getpaid_init', $this );
349
-
350
-		// Load default gateways.
351
-		$gateways = apply_filters(
352
-			'getpaid_default_gateways',
353
-			array(
354
-				'manual'        => 'GetPaid_Manual_Gateway',
355
-				'paypal'        => 'GetPaid_Paypal_Gateway',
356
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
357
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
358
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
359
-			)
360
-		);
361
-
362
-		foreach ( $gateways as $id => $class ) {
363
-			$this->gateways[ $id ] = new $class();
364
-		}
365
-
366
-		// Fires after getpaid inits.
367
-		do_action( 'getpaid_init', $this );
368
-
369
-	}
370
-
371
-	/**
372
-	 * Checks if this is an IPN request and processes it.
373
-	 */
374
-	public function maybe_process_ipn() {
375
-
376
-		// Ensure that this is an IPN request.
377
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
378
-			return;
379
-		}
380
-
381
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
382
-
383
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
384
-		do_action( "wpinv_verify_{$gateway}_ipn" );
385
-		exit;
386
-
387
-	}
388
-
389
-	public function enqueue_scripts() {
390
-		$suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
391
-
392
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
393
-		wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
394
-		wp_enqueue_style( 'wpinv_front_style' );
395
-
396
-		// Register scripts
397
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
398
-		wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
399
-
400
-		$localize                         = array();
401
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
402
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
403
-		$localize['currency_symbol']      = wpinv_currency_symbol();
404
-		$localize['currency_pos']         = wpinv_currency_position();
405
-		$localize['thousand_sep']         = wpinv_thousands_separator();
406
-		$localize['decimal_sep']          = wpinv_decimal_separator();
407
-		$localize['decimals']             = wpinv_decimals();
408
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
409
-		$localize['UseTaxes']             = wpinv_use_taxes();
410
-		$localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
411
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
412
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
413
-
414
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
415
-
416
-		wp_enqueue_script( 'jquery-blockui' );
417
-		$autofill_api = wpinv_get_option('address_autofill_api');
418
-		$autofill_active = wpinv_get_option('address_autofill_active');
419
-		if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
420
-			if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
421
-				wp_dequeue_script( 'google-maps-api' );
422
-			}
423
-			wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
424
-			wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
425
-		}
426
-
427
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
428
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
429
-
430
-		wp_enqueue_script( 'wpinv-front-script' );
431
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
432
-
433
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
434
-		wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
435
-	}
436
-
437
-	public function wpinv_actions() {
438
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
439
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
440
-		}
441
-	}
442
-
443
-	public function pre_get_posts( $wp_query ) {
444
-		if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
445
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
446
-		}
447
-
448
-		return $wp_query;
449
-	}
450
-
451
-	public function bp_invoicing_init() {
452
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
453
-	}
454
-
455
-	/**
456
-	 * Register widgets
457
-	 *
458
-	 */
459
-	public function register_widgets() {
460
-		$widgets = apply_filters(
461
-			'getpaid_widget_classes',
462
-			array(
463
-				'WPInv_Checkout_Widget',
464
-				'WPInv_History_Widget',
465
-				'WPInv_Receipt_Widget',
466
-				'WPInv_Subscriptions_Widget',
467
-				'WPInv_Buy_Item_Widget',
468
-				'WPInv_Messages_Widget',
469
-				'WPInv_GetPaid_Widget'
470
-			)
471
-		);
472
-
473
-		foreach ( $widgets as $widget ) {
474
-			register_widget( $widget );
475
-		}
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * Tax instance.
40
+     *
41
+     * @var WPInv_EUVat
42
+     */
43
+    public $tax;
44
+
45
+    /**
46
+     * @param array An array of payment gateways.
47
+     */
48
+    public $gateways;
49
+
50
+    /**
51
+     * Class constructor.
52
+     */
53
+    public function __construct() {
54
+        $this->define_constants();
55
+        $this->includes();
56
+        $this->init_hooks();
57
+        $this->set_properties();
58
+    }
59
+
60
+    /**
61
+     * Sets a custom data property.
62
+     * 
63
+     * @param string $prop The prop to set.
64
+     * @param mixed $value The value to retrieve.
65
+     */
66
+    public function set( $prop, $value ) {
67
+        $this->data[ $prop ] = $value;
68
+    }
69
+
70
+    /**
71
+     * Gets a custom data property.
72
+     * 
73
+     * @param string $prop The prop to set.
74
+     * @return mixed The value.
75
+     */
76
+    public function get( $prop ) {
77
+
78
+        if ( isset( $this->data[ $prop ] ) ) {
79
+            return $this->data[ $prop ];
80
+        }
81
+
82
+        return null;
83
+    }
84
+
85
+    /**
86
+     * Define class properties.
87
+     */
88
+    public function set_properties() {
89
+
90
+        // Sessions.
91
+        $this->set( 'session', new WPInv_Session_Handler() );
92
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
93
+        $this->form_elements = new WPInv_Payment_Form_Elements();
94
+        $this->tax           = new WPInv_EUVat();
95
+        $this->tax->init();
96
+        $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
97
+
98
+        // Init other objects.
99
+        $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
100
+        $this->set( 'session', new WPInv_Session_Handler() );
101
+        $this->set( 'notes', new WPInv_Notes() );
102
+        $this->set( 'api', new WPInv_API() );
103
+        $this->set( 'post_types', new GetPaid_Post_Types() );
104
+        $this->set( 'template', new GetPaid_Template() );
105
+        $this->set( 'admin', new GetPaid_Admin() );
106
+    }
107
+
108
+        /**
109
+         * Define plugin constants.
110
+         */
111
+    public function define_constants() {
112
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
113
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
114
+        $this->version = WPINV_VERSION;
115
+    }
116
+
117
+    /**
118
+     * Hook into actions and filters.
119
+     *
120
+     * @since 1.0.19
121
+     */
122
+    protected function init_hooks() {
123
+        /* Internationalize the text strings used. */
124
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
125
+
126
+        // Init the plugin after WordPress inits.
127
+        add_action( 'init', array( $this, 'init' ), 1 );
128
+        add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
129
+        add_action( 'init', array( &$this, 'wpinv_actions' ) );
130
+
131
+        if ( class_exists( 'BuddyPress' ) ) {
132
+            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
133
+        }
134
+
135
+        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
136
+        add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
137
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
138
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
139
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
140
+
141
+        // Fires after registering actions.
142
+        do_action( 'wpinv_actions', $this );
143
+        do_action( 'getpaid_actions', $this );
144
+
145
+    }
146
+
147
+    public function plugins_loaded() {
148
+        /* Internationalize the text strings used. */
149
+        $this->load_textdomain();
150
+
151
+        do_action( 'wpinv_loaded' );
152
+
153
+        // Fix oxygen page builder conflict
154
+        if ( function_exists( 'ct_css_output' ) ) {
155
+            wpinv_oxygen_fix_conflict();
156
+        }
157
+    }
158
+
159
+    /**
160
+     * Load the translation of the plugin.
161
+     *
162
+     * @since 1.0
163
+     */
164
+    public function load_textdomain( $locale = NULL ) {
165
+        if ( empty( $locale ) ) {
166
+            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
167
+        }
168
+
169
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
170
+
171
+        unload_textdomain( 'invoicing' );
172
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
173
+        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
174
+
175
+        /**
176
+         * Define language constants.
177
+         */
178
+        require_once( WPINV_PLUGIN_DIR . 'language.php' );
179
+    }
180
+
181
+    /**
182
+     * Include required core files used in admin and on the frontend.
183
+     */
184
+    public function includes() {
185
+
186
+        // Start with the settings.
187
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
188
+
189
+        // Packages/libraries.
190
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
191
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
192
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
193
+
194
+        // Load functions.
195
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
196
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
198
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
199
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
205
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
206
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
207
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
208
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
209
+
210
+        // Register autoloader.
211
+        try {
212
+            spl_autoload_register( array( $this, 'autoload' ), true );
213
+        } catch ( Exception $e ) {
214
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
215
+        }
216
+
217
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
218
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
219
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
220
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
221
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
222
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
234
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
235
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
236
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
237
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
238
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
239
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
240
+
241
+        /**
242
+         * Load the tax class.
243
+         */
244
+        if ( ! class_exists( 'WPInv_EUVat' ) ) {
245
+            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
246
+        }
247
+
248
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
249
+        if ( !empty( $gateways ) ) {
250
+            foreach ( $gateways as $gateway ) {
251
+                if ( $gateway == 'manual' ) {
252
+                    continue;
253
+                }
254
+
255
+                $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
256
+
257
+                if ( file_exists( $gateway_file ) ) {
258
+                    require_once( $gateway_file );
259
+                }
260
+            }
261
+        }
262
+
263
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
264
+            GetPaid_Post_Types_Admin::init();
265
+
266
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
267
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
268
+            //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
269
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
270
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
271
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
272
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
273
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
274
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
275
+            //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
276
+            // load the user class only on the users.php page
277
+            global $pagenow;
278
+            if($pagenow=='users.php'){
279
+                new WPInv_Admin_Users();
280
+            }
281
+        }
282
+
283
+        // Register cli commands
284
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
285
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
286
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
287
+        }
288
+
289
+        // include css inliner
290
+        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
291
+            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
292
+        }
293
+
294
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
295
+    }
296
+
297
+    /**
298
+     * Class autoloader
299
+     *
300
+     * @param       string $class_name The name of the class to load.
301
+     * @access      public
302
+     * @since       1.0.19
303
+     * @return      void
304
+     */
305
+    public function autoload( $class_name ) {
306
+
307
+        // Normalize the class name...
308
+        $class_name  = strtolower( $class_name );
309
+
310
+        // ... and make sure it is our class.
311
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
312
+            return;
313
+        }
314
+
315
+        // Next, prepare the file name from the class.
316
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
317
+
318
+        // Base path of the classes.
319
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
320
+
321
+        // And an array of possible locations in order of importance.
322
+        $locations = array(
323
+            "$plugin_path/includes",
324
+            "$plugin_path/includes/data-stores",
325
+            "$plugin_path/includes/gateways",
326
+            "$plugin_path/includes/api",
327
+            "$plugin_path/includes/admin",
328
+            "$plugin_path/includes/admin/meta-boxes",
329
+        );
330
+
331
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
332
+
333
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
334
+                include trailingslashit( $location ) . $file_name;
335
+                break;
336
+            }
337
+
338
+        }
339
+
340
+    }
341
+
342
+    /**
343
+     * Inits hooks etc.
344
+     */
345
+    public function init() {
346
+
347
+        // Fires before getpaid inits.
348
+        do_action( 'before_getpaid_init', $this );
349
+
350
+        // Load default gateways.
351
+        $gateways = apply_filters(
352
+            'getpaid_default_gateways',
353
+            array(
354
+                'manual'        => 'GetPaid_Manual_Gateway',
355
+                'paypal'        => 'GetPaid_Paypal_Gateway',
356
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
357
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
358
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
359
+            )
360
+        );
361
+
362
+        foreach ( $gateways as $id => $class ) {
363
+            $this->gateways[ $id ] = new $class();
364
+        }
365
+
366
+        // Fires after getpaid inits.
367
+        do_action( 'getpaid_init', $this );
368
+
369
+    }
370
+
371
+    /**
372
+     * Checks if this is an IPN request and processes it.
373
+     */
374
+    public function maybe_process_ipn() {
375
+
376
+        // Ensure that this is an IPN request.
377
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
378
+            return;
379
+        }
380
+
381
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
382
+
383
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
384
+        do_action( "wpinv_verify_{$gateway}_ipn" );
385
+        exit;
386
+
387
+    }
388
+
389
+    public function enqueue_scripts() {
390
+        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
391
+
392
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
393
+        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
394
+        wp_enqueue_style( 'wpinv_front_style' );
395
+
396
+        // Register scripts
397
+        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
398
+        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
399
+
400
+        $localize                         = array();
401
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
402
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
403
+        $localize['currency_symbol']      = wpinv_currency_symbol();
404
+        $localize['currency_pos']         = wpinv_currency_position();
405
+        $localize['thousand_sep']         = wpinv_thousands_separator();
406
+        $localize['decimal_sep']          = wpinv_decimal_separator();
407
+        $localize['decimals']             = wpinv_decimals();
408
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
409
+        $localize['UseTaxes']             = wpinv_use_taxes();
410
+        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
411
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
412
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
413
+
414
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
415
+
416
+        wp_enqueue_script( 'jquery-blockui' );
417
+        $autofill_api = wpinv_get_option('address_autofill_api');
418
+        $autofill_active = wpinv_get_option('address_autofill_active');
419
+        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
420
+            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
421
+                wp_dequeue_script( 'google-maps-api' );
422
+            }
423
+            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
424
+            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
425
+        }
426
+
427
+        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
428
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
429
+
430
+        wp_enqueue_script( 'wpinv-front-script' );
431
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
432
+
433
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
434
+        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
435
+    }
436
+
437
+    public function wpinv_actions() {
438
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
439
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
440
+        }
441
+    }
442
+
443
+    public function pre_get_posts( $wp_query ) {
444
+        if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
445
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
446
+        }
447
+
448
+        return $wp_query;
449
+    }
450
+
451
+    public function bp_invoicing_init() {
452
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
453
+    }
454
+
455
+    /**
456
+     * Register widgets
457
+     *
458
+     */
459
+    public function register_widgets() {
460
+        $widgets = apply_filters(
461
+            'getpaid_widget_classes',
462
+            array(
463
+                'WPInv_Checkout_Widget',
464
+                'WPInv_History_Widget',
465
+                'WPInv_Receipt_Widget',
466
+                'WPInv_Subscriptions_Widget',
467
+                'WPInv_Buy_Item_Widget',
468
+                'WPInv_Messages_Widget',
469
+                'WPInv_GetPaid_Widget'
470
+            )
471
+        );
472
+
473
+        foreach ( $widgets as $widget ) {
474
+            register_widget( $widget );
475
+        }
476 476
 		
477
-	}
477
+    }
478 478
 
479
-	/**
480
-	 * Remove our pages from yoast sitemaps.
481
-	 *
482
-	 * @since 1.0.19
483
-	 * @param int[] $excluded_posts_ids
484
-	 */
485
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
479
+    /**
480
+     * Remove our pages from yoast sitemaps.
481
+     *
482
+     * @since 1.0.19
483
+     * @param int[] $excluded_posts_ids
484
+     */
485
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
486 486
 
487
-		// Ensure that we have an array.
488
-		if ( ! is_array( $excluded_posts_ids ) ) {
489
-			$excluded_posts_ids = array();
490
-		}
487
+        // Ensure that we have an array.
488
+        if ( ! is_array( $excluded_posts_ids ) ) {
489
+            $excluded_posts_ids = array();
490
+        }
491 491
 
492
-		// Prepare our pages.
493
-		$our_pages = array();
492
+        // Prepare our pages.
493
+        $our_pages = array();
494 494
 
495
-		// Checkout page.
496
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
495
+        // Checkout page.
496
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
497 497
 
498
-		// Success page.
499
-		$our_pages[] = wpinv_get_option( 'success_page', false );
498
+        // Success page.
499
+        $our_pages[] = wpinv_get_option( 'success_page', false );
500 500
 
501
-		// Failure page.
502
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
501
+        // Failure page.
502
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
503 503
 
504
-		// History page.
505
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
504
+        // History page.
505
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
506 506
 
507
-		// Subscriptions page.
508
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
507
+        // Subscriptions page.
508
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
509 509
 
510
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
510
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
511 511
 
512
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
513
-		return array_unique( $excluded_posts_ids );
512
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
513
+        return array_unique( $excluded_posts_ids );
514 514
 
515
-	}
515
+    }
516 516
 
517
-	public function wp_footer() {
518
-		echo '
517
+    public function wp_footer() {
518
+        echo '
519 519
 			<div class="bsui">
520 520
 				<div  id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog">
521 521
 					<div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;">
@@ -526,6 +526,6 @@  discard block
 block discarded – undo
526 526
 				</div>
527 527
 			</div>
528 528
 		';
529
-	}
529
+    }
530 530
 
531 531
 }
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 1 patch
Indentation   +949 added lines, -949 removed lines patch added patch discarded remove patch
@@ -15,127 +15,127 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => null,
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	private $subs_db;
66
-
67
-	/**
68
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
69
-	 *
70
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
71
-	 * @param  bool $deprecated
72
-	 */
73
-	function __construct( $subscription = 0, $deprecated = false ) {
74
-
75
-		parent::__construct( $subscription );
76
-
77
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
78
-			$this->set_id( $subscription );
79
-		} elseif ( $subscription instanceof self ) {
80
-			$this->set_id( $subscription->get_id() );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
84
-			$this->set_id( $subscription_id );
85
-		} else {
86
-			$this->set_object_read( true );
87
-		}
88
-
89
-		// Load the datastore.
90
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
91
-
92
-		if ( $this->get_id() > 0 ) {
93
-			$this->data_store->read( $this );
94
-		}
95
-
96
-	}
97
-
98
-	/**
99
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
100
-	 *
101
-	 *
102
-	 * @static
103
-	 * @param string $value
104
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
105
-	 * @since 1.0.19
106
-	 * @return int
107
-	 */
108
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => null,
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    private $subs_db;
66
+
67
+    /**
68
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
69
+     *
70
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
71
+     * @param  bool $deprecated
72
+     */
73
+    function __construct( $subscription = 0, $deprecated = false ) {
74
+
75
+        parent::__construct( $subscription );
76
+
77
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
78
+            $this->set_id( $subscription );
79
+        } elseif ( $subscription instanceof self ) {
80
+            $this->set_id( $subscription->get_id() );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
84
+            $this->set_id( $subscription_id );
85
+        } else {
86
+            $this->set_object_read( true );
87
+        }
88
+
89
+        // Load the datastore.
90
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
91
+
92
+        if ( $this->get_id() > 0 ) {
93
+            $this->data_store->read( $this );
94
+        }
95
+
96
+    }
97
+
98
+    /**
99
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
100
+     *
101
+     *
102
+     * @static
103
+     * @param string $value
104
+     * @param string $field Either invoice_id, transaction_id or profile_id.
105
+     * @since 1.0.19
106
+     * @return int
107
+     */
108
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
109 109
         global $wpdb;
110 110
 
111
-		// Trim the value.
112
-		$value = trim( $value );
111
+        // Trim the value.
112
+        $value = trim( $value );
113 113
 
114
-		if ( empty( $value ) ) {
115
-			return 0;
116
-		}
114
+        if ( empty( $value ) ) {
115
+            return 0;
116
+        }
117 117
 
118
-		if ( 'invoice_id' == $field ) {
119
-			$field = 'parent_payment_id';
120
-		}
118
+        if ( 'invoice_id' == $field ) {
119
+            $field = 'parent_payment_id';
120
+        }
121 121
 
122 122
         // Valid fields.
123 123
         $fields = array(
124
-			'parent_payment_id',
125
-			'transaction_id',
126
-			'profile_id'
127
-		);
128
-
129
-		// Ensure a field has been passed.
130
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
131
-			return 0;
132
-		}
133
-
134
-		// Maybe retrieve from the cache.
135
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
136
-		if ( ! empty( $subscription_id ) ) {
137
-			return $subscription_id;
138
-		}
124
+            'parent_payment_id',
125
+            'transaction_id',
126
+            'profile_id'
127
+        );
128
+
129
+        // Ensure a field has been passed.
130
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
131
+            return 0;
132
+        }
133
+
134
+        // Maybe retrieve from the cache.
135
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
136
+        if ( ! empty( $subscription_id ) ) {
137
+            return $subscription_id;
138
+        }
139 139
 
140 140
         // Fetch from the db.
141 141
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -143,34 +143,34 @@  discard block
 block discarded – undo
143 143
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
144 144
         );
145 145
 
146
-		if ( empty( $subscription_id ) ) {
147
-			return 0;
148
-		}
146
+        if ( empty( $subscription_id ) ) {
147
+            return 0;
148
+        }
149 149
 
150
-		// Update the cache with our data.
151
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150
+        // Update the cache with our data.
151
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
152 152
 
153
-		return $subscription_id;
154
-	}
153
+        return $subscription_id;
154
+    }
155 155
 
156
-	/**
156
+    /**
157 157
      * Clears the subscription's cache.
158 158
      */
159 159
     public function clear_cache() {
160
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
162
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
163
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
164
-	}
160
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
162
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
163
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
164
+    }
165 165
 
166
-	/**
166
+    /**
167 167
      * Checks if a subscription key is set.
168 168
      */
169 169
     public function _isset( $key ) {
170 170
         return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
171
-	}
171
+    }
172 172
 
173
-	/*
173
+    /*
174 174
 	|--------------------------------------------------------------------------
175 175
 	| CRUD methods
176 176
 	|--------------------------------------------------------------------------
@@ -179,57 +179,57 @@  discard block
 block discarded – undo
179 179
 	|
180 180
     */
181 181
 
182
-	/*
182
+    /*
183 183
 	|--------------------------------------------------------------------------
184 184
 	| Getters
185 185
 	|--------------------------------------------------------------------------
186 186
 	*/
187 187
 
188
-	/**
189
-	 * Get customer id.
190
-	 *
191
-	 * @since 1.0.19
192
-	 * @param  string $context View or edit context.
193
-	 * @return int
194
-	 */
195
-	public function get_customer_id( $context = 'view' ) {
196
-		return (int) $this->get_prop( 'customer_id', $context );
197
-	}
198
-
199
-	/**
200
-	 * Get customer information.
201
-	 *
202
-	 * @since 1.0.19
203
-	 * @param  string $context View or edit context.
204
-	 * @return WP_User|false WP_User object on success, false on failure.
205
-	 */
206
-	public function get_customer( $context = 'view' ) {
207
-		return get_userdata( $this->get_customer_id( $context ) );
208
-	}
209
-
210
-	/**
211
-	 * Get parent invoice id.
212
-	 *
213
-	 * @since 1.0.19
214
-	 * @param  string $context View or edit context.
215
-	 * @return int
216
-	 */
217
-	public function get_parent_invoice_id( $context = 'view' ) {
218
-		return (int) $this->get_prop( 'parent_payment_id', $context );
219
-	}
220
-
221
-	/**
222
-	 * Alias for self::get_parent_invoice_id().
223
-	 *
224
-	 * @since 1.0.19
225
-	 * @param  string $context View or edit context.
226
-	 * @return int
227
-	 */
188
+    /**
189
+     * Get customer id.
190
+     *
191
+     * @since 1.0.19
192
+     * @param  string $context View or edit context.
193
+     * @return int
194
+     */
195
+    public function get_customer_id( $context = 'view' ) {
196
+        return (int) $this->get_prop( 'customer_id', $context );
197
+    }
198
+
199
+    /**
200
+     * Get customer information.
201
+     *
202
+     * @since 1.0.19
203
+     * @param  string $context View or edit context.
204
+     * @return WP_User|false WP_User object on success, false on failure.
205
+     */
206
+    public function get_customer( $context = 'view' ) {
207
+        return get_userdata( $this->get_customer_id( $context ) );
208
+    }
209
+
210
+    /**
211
+     * Get parent invoice id.
212
+     *
213
+     * @since 1.0.19
214
+     * @param  string $context View or edit context.
215
+     * @return int
216
+     */
217
+    public function get_parent_invoice_id( $context = 'view' ) {
218
+        return (int) $this->get_prop( 'parent_payment_id', $context );
219
+    }
220
+
221
+    /**
222
+     * Alias for self::get_parent_invoice_id().
223
+     *
224
+     * @since 1.0.19
225
+     * @param  string $context View or edit context.
226
+     * @return int
227
+     */
228 228
     public function get_parent_payment_id( $context = 'view' ) {
229 229
         return $this->get_parent_invoice_id( $context );
230
-	}
230
+    }
231 231
 
232
-	/**
232
+    /**
233 233
      * Alias for self::get_parent_invoice_id().
234 234
      *
235 235
      * @since  1.0.0
@@ -239,390 +239,390 @@  discard block
 block discarded – undo
239 239
         return $this->get_parent_invoice_id( $context );
240 240
     }
241 241
 
242
-	/**
243
-	 * Get parent invoice.
244
-	 *
245
-	 * @since 1.0.19
246
-	 * @param  string $context View or edit context.
247
-	 * @return WPInv_Invoice
248
-	 */
249
-	public function get_parent_invoice( $context = 'view' ) {
250
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
251
-	}
252
-
253
-	/**
254
-	 * Alias for self::get_parent_invoice().
255
-	 *
256
-	 * @since 1.0.19
257
-	 * @param  string $context View or edit context.
258
-	 * @return WPInv_Invoice
259
-	 */
242
+    /**
243
+     * Get parent invoice.
244
+     *
245
+     * @since 1.0.19
246
+     * @param  string $context View or edit context.
247
+     * @return WPInv_Invoice
248
+     */
249
+    public function get_parent_invoice( $context = 'view' ) {
250
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
251
+    }
252
+
253
+    /**
254
+     * Alias for self::get_parent_invoice().
255
+     *
256
+     * @since 1.0.19
257
+     * @param  string $context View or edit context.
258
+     * @return WPInv_Invoice
259
+     */
260 260
     public function get_parent_payment( $context = 'view' ) {
261 261
         return $this->get_parent_invoice( $context );
262
-	}
263
-
264
-	/**
265
-	 * Get subscription's product id.
266
-	 *
267
-	 * @since 1.0.19
268
-	 * @param  string $context View or edit context.
269
-	 * @return int
270
-	 */
271
-	public function get_product_id( $context = 'view' ) {
272
-		return (int) $this->get_prop( 'product_id', $context );
273
-	}
274
-
275
-	/**
276
-	 * Get the subscription product.
277
-	 *
278
-	 * @since 1.0.19
279
-	 * @param  string $context View or edit context.
280
-	 * @return WPInv_Item
281
-	 */
282
-	public function get_product( $context = 'view' ) {
283
-		return new WPInv_Item( $this->get_product_id( $context ) );
284
-	}
285
-
286
-	/**
287
-	 * Get parent invoice's gateway.
288
-	 *
289
-	 * Here for backwards compatibility.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return string
294
-	 */
295
-	public function get_gateway( $context = 'view' ) {
296
-		return $this->get_parent_invoice( $context )->get_gateway();
297
-	}
298
-
299
-	/**
300
-	 * Get the period of a renewal.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return string
305
-	 */
306
-	public function get_period( $context = 'view' ) {
307
-		return $this->get_prop( 'period', $context );
308
-	}
309
-
310
-	/**
311
-	 * Get number of periods each renewal is valid for.
312
-	 *
313
-	 * @since 1.0.19
314
-	 * @param  string $context View or edit context.
315
-	 * @return int
316
-	 */
317
-	public function get_frequency( $context = 'view' ) {
318
-		return (int) $this->get_prop( 'frequency', $context );
319
-	}
320
-
321
-	/**
322
-	 * Get the initial amount for the subscription.
323
-	 *
324
-	 * @since 1.0.19
325
-	 * @param  string $context View or edit context.
326
-	 * @return float
327
-	 */
328
-	public function get_initial_amount( $context = 'view' ) {
329
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
330
-	}
331
-
332
-	/**
333
-	 * Get the recurring amount for the subscription.
334
-	 *
335
-	 * @since 1.0.19
336
-	 * @param  string $context View or edit context.
337
-	 * @return float
338
-	 */
339
-	public function get_recurring_amount( $context = 'view' ) {
340
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
341
-	}
342
-
343
-	/**
344
-	 * Get number of times that this subscription can be renewed.
345
-	 *
346
-	 * @since 1.0.19
347
-	 * @param  string $context View or edit context.
348
-	 * @return int
349
-	 */
350
-	public function get_bill_times( $context = 'view' ) {
351
-		return (int) $this->get_prop( 'bill_times', $context );
352
-	}
353
-
354
-	/**
355
-	 * Get transaction id of this subscription's parent invoice.
356
-	 *
357
-	 * @since 1.0.19
358
-	 * @param  string $context View or edit context.
359
-	 * @return string
360
-	 */
361
-	public function get_transaction_id( $context = 'view' ) {
362
-		return $this->get_prop( 'transaction_id', $context );
363
-	}
364
-
365
-	/**
366
-	 * Get the date that the subscription was created.
367
-	 *
368
-	 * @since 1.0.19
369
-	 * @param  string $context View or edit context.
370
-	 * @return string
371
-	 */
372
-	public function get_created( $context = 'view' ) {
373
-		return $this->get_prop( 'created', $context );
374
-	}
375
-
376
-	/**
377
-	 * Alias for self::get_created().
378
-	 *
379
-	 * @since 1.0.19
380
-	 * @param  string $context View or edit context.
381
-	 * @return string
382
-	 */
383
-	public function get_date_created( $context = 'view' ) {
384
-		return $this->get_created( $context );
385
-	}
386
-
387
-	/**
388
-	 * Retrieves the creation date in a timestamp
389
-	 *
390
-	 * @since  1.0.0
391
-	 * @return int
392
-	 */
393
-	public function get_time_created() {
394
-		$created = $this->get_date_created();
395
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
396
-	}
397
-
398
-	/**
399
-	 * Get GMT date when the subscription was created.
400
-	 *
401
-	 * @since 1.0.19
402
-	 * @param  string $context View or edit context.
403
-	 * @return string
404
-	 */
405
-	public function get_date_created_gmt( $context = 'view' ) {
262
+    }
263
+
264
+    /**
265
+     * Get subscription's product id.
266
+     *
267
+     * @since 1.0.19
268
+     * @param  string $context View or edit context.
269
+     * @return int
270
+     */
271
+    public function get_product_id( $context = 'view' ) {
272
+        return (int) $this->get_prop( 'product_id', $context );
273
+    }
274
+
275
+    /**
276
+     * Get the subscription product.
277
+     *
278
+     * @since 1.0.19
279
+     * @param  string $context View or edit context.
280
+     * @return WPInv_Item
281
+     */
282
+    public function get_product( $context = 'view' ) {
283
+        return new WPInv_Item( $this->get_product_id( $context ) );
284
+    }
285
+
286
+    /**
287
+     * Get parent invoice's gateway.
288
+     *
289
+     * Here for backwards compatibility.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return string
294
+     */
295
+    public function get_gateway( $context = 'view' ) {
296
+        return $this->get_parent_invoice( $context )->get_gateway();
297
+    }
298
+
299
+    /**
300
+     * Get the period of a renewal.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return string
305
+     */
306
+    public function get_period( $context = 'view' ) {
307
+        return $this->get_prop( 'period', $context );
308
+    }
309
+
310
+    /**
311
+     * Get number of periods each renewal is valid for.
312
+     *
313
+     * @since 1.0.19
314
+     * @param  string $context View or edit context.
315
+     * @return int
316
+     */
317
+    public function get_frequency( $context = 'view' ) {
318
+        return (int) $this->get_prop( 'frequency', $context );
319
+    }
320
+
321
+    /**
322
+     * Get the initial amount for the subscription.
323
+     *
324
+     * @since 1.0.19
325
+     * @param  string $context View or edit context.
326
+     * @return float
327
+     */
328
+    public function get_initial_amount( $context = 'view' ) {
329
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
330
+    }
331
+
332
+    /**
333
+     * Get the recurring amount for the subscription.
334
+     *
335
+     * @since 1.0.19
336
+     * @param  string $context View or edit context.
337
+     * @return float
338
+     */
339
+    public function get_recurring_amount( $context = 'view' ) {
340
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
341
+    }
342
+
343
+    /**
344
+     * Get number of times that this subscription can be renewed.
345
+     *
346
+     * @since 1.0.19
347
+     * @param  string $context View or edit context.
348
+     * @return int
349
+     */
350
+    public function get_bill_times( $context = 'view' ) {
351
+        return (int) $this->get_prop( 'bill_times', $context );
352
+    }
353
+
354
+    /**
355
+     * Get transaction id of this subscription's parent invoice.
356
+     *
357
+     * @since 1.0.19
358
+     * @param  string $context View or edit context.
359
+     * @return string
360
+     */
361
+    public function get_transaction_id( $context = 'view' ) {
362
+        return $this->get_prop( 'transaction_id', $context );
363
+    }
364
+
365
+    /**
366
+     * Get the date that the subscription was created.
367
+     *
368
+     * @since 1.0.19
369
+     * @param  string $context View or edit context.
370
+     * @return string
371
+     */
372
+    public function get_created( $context = 'view' ) {
373
+        return $this->get_prop( 'created', $context );
374
+    }
375
+
376
+    /**
377
+     * Alias for self::get_created().
378
+     *
379
+     * @since 1.0.19
380
+     * @param  string $context View or edit context.
381
+     * @return string
382
+     */
383
+    public function get_date_created( $context = 'view' ) {
384
+        return $this->get_created( $context );
385
+    }
386
+
387
+    /**
388
+     * Retrieves the creation date in a timestamp
389
+     *
390
+     * @since  1.0.0
391
+     * @return int
392
+     */
393
+    public function get_time_created() {
394
+        $created = $this->get_date_created();
395
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
396
+    }
397
+
398
+    /**
399
+     * Get GMT date when the subscription was created.
400
+     *
401
+     * @since 1.0.19
402
+     * @param  string $context View or edit context.
403
+     * @return string
404
+     */
405
+    public function get_date_created_gmt( $context = 'view' ) {
406 406
         $date = $this->get_date_created( $context );
407 407
 
408 408
         if ( $date ) {
409 409
             $date = get_gmt_from_date( $date );
410 410
         }
411
-		return $date;
412
-	}
413
-
414
-	/**
415
-	 * Get the date that the subscription will renew.
416
-	 *
417
-	 * @since 1.0.19
418
-	 * @param  string $context View or edit context.
419
-	 * @return string
420
-	 */
421
-	public function get_next_renewal_date( $context = 'view' ) {
422
-		return $this->get_prop( 'expiration', $context );
423
-	}
424
-
425
-	/**
426
-	 * Alias for self::get_next_renewal_date().
427
-	 *
428
-	 * @since 1.0.19
429
-	 * @param  string $context View or edit context.
430
-	 * @return string
431
-	 */
432
-	public function get_expiration( $context = 'view' ) {
433
-		return $this->get_next_renewal_date( $context );
434
-	}
435
-
436
-	/**
437
-	 * Retrieves the expiration date in a timestamp
438
-	 *
439
-	 * @since  1.0.0
440
-	 * @return int
441
-	 */
442
-	public function get_expiration_time() {
443
-		$expiration = $this->get_expiration();
444
-
445
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
446
-			return current_time( 'timestamp' );
447
-		}
448
-
449
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
450
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
451
-	}
452
-
453
-	/**
454
-	 * Get GMT date when the subscription will renew.
455
-	 *
456
-	 * @since 1.0.19
457
-	 * @param  string $context View or edit context.
458
-	 * @return string
459
-	 */
460
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
411
+        return $date;
412
+    }
413
+
414
+    /**
415
+     * Get the date that the subscription will renew.
416
+     *
417
+     * @since 1.0.19
418
+     * @param  string $context View or edit context.
419
+     * @return string
420
+     */
421
+    public function get_next_renewal_date( $context = 'view' ) {
422
+        return $this->get_prop( 'expiration', $context );
423
+    }
424
+
425
+    /**
426
+     * Alias for self::get_next_renewal_date().
427
+     *
428
+     * @since 1.0.19
429
+     * @param  string $context View or edit context.
430
+     * @return string
431
+     */
432
+    public function get_expiration( $context = 'view' ) {
433
+        return $this->get_next_renewal_date( $context );
434
+    }
435
+
436
+    /**
437
+     * Retrieves the expiration date in a timestamp
438
+     *
439
+     * @since  1.0.0
440
+     * @return int
441
+     */
442
+    public function get_expiration_time() {
443
+        $expiration = $this->get_expiration();
444
+
445
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
446
+            return current_time( 'timestamp' );
447
+        }
448
+
449
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
450
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
451
+    }
452
+
453
+    /**
454
+     * Get GMT date when the subscription will renew.
455
+     *
456
+     * @since 1.0.19
457
+     * @param  string $context View or edit context.
458
+     * @return string
459
+     */
460
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
461 461
         $date = $this->get_next_renewal_date( $context );
462 462
 
463 463
         if ( $date ) {
464 464
             $date = get_gmt_from_date( $date );
465 465
         }
466
-		return $date;
467
-	}
468
-
469
-	/**
470
-	 * Get the subscription's trial period.
471
-	 *
472
-	 * @since 1.0.19
473
-	 * @param  string $context View or edit context.
474
-	 * @return string
475
-	 */
476
-	public function get_trial_period( $context = 'view' ) {
477
-		return $this->get_prop( 'trial_period', $context );
478
-	}
479
-
480
-	/**
481
-	 * Get the subscription's status.
482
-	 *
483
-	 * @since 1.0.19
484
-	 * @param  string $context View or edit context.
485
-	 * @return string
486
-	 */
487
-	public function get_status( $context = 'view' ) {
488
-		return $this->get_prop( 'status', $context );
489
-	}
490
-
491
-	/**
492
-	 * Get the subscription's profile id.
493
-	 *
494
-	 * @since 1.0.19
495
-	 * @param  string $context View or edit context.
496
-	 * @return string
497
-	 */
498
-	public function get_profile_id( $context = 'view' ) {
499
-		return $this->get_prop( 'profile_id', $context );
500
-	}
501
-
502
-	/*
466
+        return $date;
467
+    }
468
+
469
+    /**
470
+     * Get the subscription's trial period.
471
+     *
472
+     * @since 1.0.19
473
+     * @param  string $context View or edit context.
474
+     * @return string
475
+     */
476
+    public function get_trial_period( $context = 'view' ) {
477
+        return $this->get_prop( 'trial_period', $context );
478
+    }
479
+
480
+    /**
481
+     * Get the subscription's status.
482
+     *
483
+     * @since 1.0.19
484
+     * @param  string $context View or edit context.
485
+     * @return string
486
+     */
487
+    public function get_status( $context = 'view' ) {
488
+        return $this->get_prop( 'status', $context );
489
+    }
490
+
491
+    /**
492
+     * Get the subscription's profile id.
493
+     *
494
+     * @since 1.0.19
495
+     * @param  string $context View or edit context.
496
+     * @return string
497
+     */
498
+    public function get_profile_id( $context = 'view' ) {
499
+        return $this->get_prop( 'profile_id', $context );
500
+    }
501
+
502
+    /*
503 503
 	|--------------------------------------------------------------------------
504 504
 	| Setters
505 505
 	|--------------------------------------------------------------------------
506 506
 	*/
507 507
 
508
-	/**
509
-	 * Set customer id.
510
-	 *
511
-	 * @since 1.0.19
512
-	 * @param  int $value The customer's id.
513
-	 */
514
-	public function set_customer_id( $value ) {
515
-		$this->set_prop( 'customer_id', (int) $value );
516
-	}
517
-
518
-	/**
519
-	 * Set parent invoice id.
520
-	 *
521
-	 * @since 1.0.19
522
-	 * @param  int $value The parent invoice id.
523
-	 */
524
-	public function set_parent_invoice_id( $value ) {
525
-		$this->set_prop( 'parent_payment_id', (int) $value );
526
-	}
527
-
528
-	/**
529
-	 * Alias for self::set_parent_invoice_id().
530
-	 *
531
-	 * @since 1.0.19
532
-	 * @param  int $value The parent invoice id.
533
-	 */
508
+    /**
509
+     * Set customer id.
510
+     *
511
+     * @since 1.0.19
512
+     * @param  int $value The customer's id.
513
+     */
514
+    public function set_customer_id( $value ) {
515
+        $this->set_prop( 'customer_id', (int) $value );
516
+    }
517
+
518
+    /**
519
+     * Set parent invoice id.
520
+     *
521
+     * @since 1.0.19
522
+     * @param  int $value The parent invoice id.
523
+     */
524
+    public function set_parent_invoice_id( $value ) {
525
+        $this->set_prop( 'parent_payment_id', (int) $value );
526
+    }
527
+
528
+    /**
529
+     * Alias for self::set_parent_invoice_id().
530
+     *
531
+     * @since 1.0.19
532
+     * @param  int $value The parent invoice id.
533
+     */
534 534
     public function set_parent_payment_id( $value ) {
535 535
         $this->set_parent_invoice_id( $value );
536
-	}
536
+    }
537 537
 
538
-	/**
538
+    /**
539 539
      * Alias for self::set_parent_invoice_id().
540 540
      *
541 541
      * @since 1.0.19
542
-	 * @param  int $value The parent invoice id.
542
+     * @param  int $value The parent invoice id.
543 543
      */
544 544
     public function set_original_payment_id( $value ) {
545 545
         $this->set_parent_invoice_id( $value );
546
-	}
547
-
548
-	/**
549
-	 * Set subscription's product id.
550
-	 *
551
-	 * @since 1.0.19
552
-	 * @param  int $value The subscription product id.
553
-	 */
554
-	public function set_product_id( $value ) {
555
-		$this->set_prop( 'product_id', (int) $value );
556
-	}
557
-
558
-	/**
559
-	 * Set the period of a renewal.
560
-	 *
561
-	 * @since 1.0.19
562
-	 * @param  string $value The renewal period.
563
-	 */
564
-	public function set_period( $value ) {
565
-		$this->set_prop( 'period', $value );
566
-	}
567
-
568
-	/**
569
-	 * Set number of periods each renewal is valid for.
570
-	 *
571
-	 * @since 1.0.19
572
-	 * @param  int $value The subscription frequency.
573
-	 */
574
-	public function set_frequency( $value ) {
575
-		$value = empty( $value ) ? 1 : (int) $value;
576
-		$this->set_prop( 'frequency', absint( $value ) );
577
-	}
578
-
579
-	/**
580
-	 * Set the initial amount for the subscription.
581
-	 *
582
-	 * @since 1.0.19
583
-	 * @param  float $value The initial subcription amount.
584
-	 */
585
-	public function set_initial_amount( $value ) {
586
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
587
-	}
588
-
589
-	/**
590
-	 * Set the recurring amount for the subscription.
591
-	 *
592
-	 * @since 1.0.19
593
-	 * @param  float $value The recurring subcription amount.
594
-	 */
595
-	public function set_recurring_amount( $value ) {
596
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
597
-	}
598
-
599
-	/**
600
-	 * Set number of times that this subscription can be renewed.
601
-	 *
602
-	 * @since 1.0.19
603
-	 * @param  int $value Bill times.
604
-	 */
605
-	public function set_bill_times( $value ) {
606
-		$this->set_prop( 'bill_times', (int) $value );
607
-	}
608
-
609
-	/**
610
-	 * Get transaction id of this subscription's parent invoice.
611
-	 *
612
-	 * @since 1.0.19
613
-	 * @param string $value Bill times.
614
-	 */
615
-	public function set_transaction_id( $value ) {
616
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
617
-	}
618
-
619
-	/**
620
-	 * Set date when this subscription started.
621
-	 *
622
-	 * @since 1.0.19
623
-	 * @param string $value strtotime compliant date.
624
-	 */
625
-	public function set_created( $value ) {
546
+    }
547
+
548
+    /**
549
+     * Set subscription's product id.
550
+     *
551
+     * @since 1.0.19
552
+     * @param  int $value The subscription product id.
553
+     */
554
+    public function set_product_id( $value ) {
555
+        $this->set_prop( 'product_id', (int) $value );
556
+    }
557
+
558
+    /**
559
+     * Set the period of a renewal.
560
+     *
561
+     * @since 1.0.19
562
+     * @param  string $value The renewal period.
563
+     */
564
+    public function set_period( $value ) {
565
+        $this->set_prop( 'period', $value );
566
+    }
567
+
568
+    /**
569
+     * Set number of periods each renewal is valid for.
570
+     *
571
+     * @since 1.0.19
572
+     * @param  int $value The subscription frequency.
573
+     */
574
+    public function set_frequency( $value ) {
575
+        $value = empty( $value ) ? 1 : (int) $value;
576
+        $this->set_prop( 'frequency', absint( $value ) );
577
+    }
578
+
579
+    /**
580
+     * Set the initial amount for the subscription.
581
+     *
582
+     * @since 1.0.19
583
+     * @param  float $value The initial subcription amount.
584
+     */
585
+    public function set_initial_amount( $value ) {
586
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
587
+    }
588
+
589
+    /**
590
+     * Set the recurring amount for the subscription.
591
+     *
592
+     * @since 1.0.19
593
+     * @param  float $value The recurring subcription amount.
594
+     */
595
+    public function set_recurring_amount( $value ) {
596
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
597
+    }
598
+
599
+    /**
600
+     * Set number of times that this subscription can be renewed.
601
+     *
602
+     * @since 1.0.19
603
+     * @param  int $value Bill times.
604
+     */
605
+    public function set_bill_times( $value ) {
606
+        $this->set_prop( 'bill_times', (int) $value );
607
+    }
608
+
609
+    /**
610
+     * Get transaction id of this subscription's parent invoice.
611
+     *
612
+     * @since 1.0.19
613
+     * @param string $value Bill times.
614
+     */
615
+    public function set_transaction_id( $value ) {
616
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
617
+    }
618
+
619
+    /**
620
+     * Set date when this subscription started.
621
+     *
622
+     * @since 1.0.19
623
+     * @param string $value strtotime compliant date.
624
+     */
625
+    public function set_created( $value ) {
626 626
         $date = strtotime( $value );
627 627
 
628 628
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -630,94 +630,94 @@  discard block
 block discarded – undo
630 630
             return;
631 631
         }
632 632
 
633
-		$this->set_prop( 'created', '' );
633
+        $this->set_prop( 'created', '' );
634 634
 
635
-	}
635
+    }
636 636
 
637
-	/**
638
-	 * Alias for self::set_created().
639
-	 *
640
-	 * @since 1.0.19
641
-	 * @param string $value strtotime compliant date.
642
-	 */
643
-	public function set_date_created( $value ) {
644
-		$this->set_created( $value );
637
+    /**
638
+     * Alias for self::set_created().
639
+     *
640
+     * @since 1.0.19
641
+     * @param string $value strtotime compliant date.
642
+     */
643
+    public function set_date_created( $value ) {
644
+        $this->set_created( $value );
645 645
     }
646 646
 
647
-	/**
648
-	 * Set the date that the subscription will renew.
649
-	 *
650
-	 * @since 1.0.19
651
-	 * @param string $value strtotime compliant date.
652
-	 */
653
-	public function set_next_renewal_date( $value ) {
654
-		$date = strtotime( $value );
647
+    /**
648
+     * Set the date that the subscription will renew.
649
+     *
650
+     * @since 1.0.19
651
+     * @param string $value strtotime compliant date.
652
+     */
653
+    public function set_next_renewal_date( $value ) {
654
+        $date = strtotime( $value );
655 655
 
656 656
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
657 657
             $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
658 658
             return;
659
-		}
660
-
661
-		$this->set_prop( 'expiration', '' );
662
-
663
-	}
664
-
665
-	/**
666
-	 * Alias for self::set_next_renewal_date().
667
-	 *
668
-	 * @since 1.0.19
669
-	 * @param string $value strtotime compliant date.
670
-	 */
671
-	public function set_expiration( $value ) {
672
-		$this->set_next_renewal_date( $value );
673
-    }
674
-
675
-	/**
676
-	 * Set the subscription's trial period.
677
-	 *
678
-	 * @since 1.0.19
679
-	 * @param string $value trial period e.g 1 year.
680
-	 */
681
-	public function set_trial_period( $value ) {
682
-		$this->set_prop( 'trial_period', $value );
683
-	}
684
-
685
-	/**
686
-	 * Set the subscription's status.
687
-	 *
688
-	 * @since 1.0.19
689
-	 * @param string $new_status    New subscription status.
690
-	 */
691
-	public function set_status( $new_status ) {
692
-
693
-		// Abort if this is not a valid status;
694
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
695
-			return;
696
-		}
697
-
698
-		$old_status = $this->get_status();
699
-		$this->set_prop( 'status', $new_status );
700
-
701
-		if ( true === $this->object_read && $old_status !== $new_status ) {
702
-			$this->status_transition = array(
703
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
704
-				'to'     => $new_status,
705
-			);
706
-		}
707
-
708
-	}
709
-
710
-	/**
711
-	 * Set the subscription's (remote) profile id.
712
-	 *
713
-	 * @since 1.0.19
714
-	 * @param  string $value the remote profile id.
715
-	 */
716
-	public function set_profile_id( $value ) {
717
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
718
-	}
719
-
720
-	/*
659
+        }
660
+
661
+        $this->set_prop( 'expiration', '' );
662
+
663
+    }
664
+
665
+    /**
666
+     * Alias for self::set_next_renewal_date().
667
+     *
668
+     * @since 1.0.19
669
+     * @param string $value strtotime compliant date.
670
+     */
671
+    public function set_expiration( $value ) {
672
+        $this->set_next_renewal_date( $value );
673
+    }
674
+
675
+    /**
676
+     * Set the subscription's trial period.
677
+     *
678
+     * @since 1.0.19
679
+     * @param string $value trial period e.g 1 year.
680
+     */
681
+    public function set_trial_period( $value ) {
682
+        $this->set_prop( 'trial_period', $value );
683
+    }
684
+
685
+    /**
686
+     * Set the subscription's status.
687
+     *
688
+     * @since 1.0.19
689
+     * @param string $new_status    New subscription status.
690
+     */
691
+    public function set_status( $new_status ) {
692
+
693
+        // Abort if this is not a valid status;
694
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
695
+            return;
696
+        }
697
+
698
+        $old_status = $this->get_status();
699
+        $this->set_prop( 'status', $new_status );
700
+
701
+        if ( true === $this->object_read && $old_status !== $new_status ) {
702
+            $this->status_transition = array(
703
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
704
+                'to'     => $new_status,
705
+            );
706
+        }
707
+
708
+    }
709
+
710
+    /**
711
+     * Set the subscription's (remote) profile id.
712
+     *
713
+     * @since 1.0.19
714
+     * @param  string $value the remote profile id.
715
+     */
716
+    public function set_profile_id( $value ) {
717
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
718
+    }
719
+
720
+    /*
721 721
 	|--------------------------------------------------------------------------
722 722
 	| Boolean methods
723 723
 	|--------------------------------------------------------------------------
@@ -726,45 +726,45 @@  discard block
 block discarded – undo
726 726
 	|
727 727
 	*/
728 728
 
729
-	/**
729
+    /**
730 730
      * Checks if the subscription has a given status.
731
-	 *
732
-	 * @param string|array String or array of strings to check for.
733
-	 * @return bool
731
+     *
732
+     * @param string|array String or array of strings to check for.
733
+     * @return bool
734 734
      */
735 735
     public function has_status( $status ) {
736 736
         return in_array( $this->get_status(), wpinv_parse_list( $status ) );
737
-	}
737
+    }
738 738
 
739
-	/**
739
+    /**
740 740
      * Checks if the subscription has a trial period.
741
-	 *
742
-	 * @return bool
741
+     *
742
+     * @return bool
743 743
      */
744 744
     public function has_trial_period() {
745
-		$period = $this->get_trial_period();
745
+        $period = $this->get_trial_period();
746 746
         return ! empty( $period );
747
-	}
748
-
749
-	/**
750
-	 * Is the subscription active?
751
-	 *
752
-	 * @return bool
753
-	 */
754
-	public function is_active() {
755
-		return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' );
756
-	}
757
-
758
-	/**
759
-	 * Is the subscription expired?
760
-	 *
761
-	 * @return bool
762
-	 */
763
-	public function is_expired() {
764
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
765
-	}
766
-
767
-	/*
747
+    }
748
+
749
+    /**
750
+     * Is the subscription active?
751
+     *
752
+     * @return bool
753
+     */
754
+    public function is_active() {
755
+        return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' );
756
+    }
757
+
758
+    /**
759
+     * Is the subscription expired?
760
+     *
761
+     * @return bool
762
+     */
763
+    public function is_expired() {
764
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
765
+    }
766
+
767
+    /*
768 768
 	|--------------------------------------------------------------------------
769 769
 	| Additional methods
770 770
 	|--------------------------------------------------------------------------
@@ -773,27 +773,27 @@  discard block
 block discarded – undo
773 773
 	|
774 774
 	*/
775 775
 
776
-	/**
777
-	 * Backwards compatibilty.
778
-	 */
779
-	public function create( $data = array() ) {
776
+    /**
777
+     * Backwards compatibilty.
778
+     */
779
+    public function create( $data = array() ) {
780 780
 
781
-		// Set the properties.
782
-		if ( is_array( $data ) ) {
783
-			$this->set_props( $data );
784
-		}
781
+        // Set the properties.
782
+        if ( is_array( $data ) ) {
783
+            $this->set_props( $data );
784
+        }
785 785
 
786
-		// Save the item.
787
-		return $this->save();
786
+        // Save the item.
787
+        return $this->save();
788 788
 
789
-	}
789
+    }
790 790
 
791
-	/**
792
-	 * Backwards compatibilty.
793
-	 */
794
-	public function update( $args = array() ) {
795
-		return $this->create( $args );
796
-	}
791
+    /**
792
+     * Backwards compatibilty.
793
+     */
794
+    public function update( $args = array() ) {
795
+        return $this->create( $args );
796
+    }
797 797
 
798 798
     /**
799 799
      * Retrieve renewal payments for a subscription
@@ -803,15 +803,15 @@  discard block
 block discarded – undo
803 803
      */
804 804
     public function get_child_payments() {
805 805
         return get_posts(
806
-			array(
807
-            	'post_parent'    => $this->get_parent_payment_id(),
808
-            	'numberposts'    => -1,
809
-            	'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
810
-            	'orderby'        => 'ID',
811
-            	'order'          => 'DESC',
812
-            	'post_type'      => 'wpi_invoice'
813
-			)
814
-		);
806
+            array(
807
+                'post_parent'    => $this->get_parent_payment_id(),
808
+                'numberposts'    => -1,
809
+                'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
810
+                'orderby'        => 'ID',
811
+                'order'          => 'DESC',
812
+                'post_type'      => 'wpi_invoice'
813
+            )
814
+        );
815 815
     }
816 816
 
817 817
     /**
@@ -821,16 +821,16 @@  discard block
 block discarded – undo
821 821
      * @return int
822 822
      */
823 823
     public function get_total_payments() {
824
-		global $wpdb;
824
+        global $wpdb;
825 825
 
826
-		$count = (int) $wpdb->get_var(
827
-			$wpdb->prepare(
828
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
829
-				$this->get_parent_invoice_id()
830
-			)
831
-		);
826
+        $count = (int) $wpdb->get_var(
827
+            $wpdb->prepare(
828
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
829
+                $this->get_parent_invoice_id()
830
+            )
831
+        );
832 832
 
833
-		// Maybe include parent invoice.
833
+        // Maybe include parent invoice.
834 834
         if ( ! $this->has_status( 'pending' ) ) {
835 835
             $count++;
836 836
         }
@@ -859,57 +859,57 @@  discard block
 block discarded – undo
859 859
      *
860 860
      * @since  2.4
861 861
      * @param  array $args Array of values for the payment, including amount and transaction ID
862
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
862
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
863 863
      * @return bool
864 864
      */
865 865
     public function add_payment( $args = array(), $invoice = false ) {
866 866
 
867
-		// Process each payment once.
867
+        // Process each payment once.
868 868
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
869 869
             return false;
870 870
         }
871 871
 
872
-		// Are we creating a new invoice?
873
-		if ( empty( $invoice ) ) {
874
-			$invoice = $this->create_payment();
872
+        // Are we creating a new invoice?
873
+        if ( empty( $invoice ) ) {
874
+            $invoice = $this->create_payment();
875 875
 
876
-			if ( empty( $invoice ) ) {
877
-				return false;
878
-			}
876
+            if ( empty( $invoice ) ) {
877
+                return false;
878
+            }
879 879
 
880
-			$invoice->set_status( 'wpi-renewal' );
880
+            $invoice->set_status( 'wpi-renewal' );
881 881
 
882
-		}
882
+        }
883 883
 
884
-		// Maybe set a transaction id.
885
-		if ( ! empty( $args['transaction_id'] ) ) {
886
-			$invoice->set_transaction_id( $args['transaction_id'] );
887
-		}
884
+        // Maybe set a transaction id.
885
+        if ( ! empty( $args['transaction_id'] ) ) {
886
+            $invoice->set_transaction_id( $args['transaction_id'] );
887
+        }
888 888
 
889
-		// Set the completed date.
890
-		$invoice->set_completed_date( current_time( 'mysql' ) );
889
+        // Set the completed date.
890
+        $invoice->set_completed_date( current_time( 'mysql' ) );
891 891
 
892
-		// And the gateway.
893
-		if ( ! empty( $args['gateway'] ) ) {
894
-			$invoice->set_gateway( $args['gateway'] );
895
-		}
892
+        // And the gateway.
893
+        if ( ! empty( $args['gateway'] ) ) {
894
+            $invoice->set_gateway( $args['gateway'] );
895
+        }
896 896
 
897
-		$invoice->save();
897
+        $invoice->save();
898 898
 
899
-		if ( ! $invoice->get_id() ) {
900
-			return 0;
901
-		}
899
+        if ( ! $invoice->get_id() ) {
900
+            return 0;
901
+        }
902 902
 
903
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
904
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
903
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
904
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
905 905
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
906 906
 
907 907
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
908 908
 
909 909
         return $invoice->get_id();
910
-	}
910
+    }
911 911
 
912
-	/**
912
+    /**
913 913
      * Creates a new invoice and returns it.
914 914
      *
915 915
      * @since  1.0.19
@@ -917,104 +917,104 @@  discard block
 block discarded – undo
917 917
      */
918 918
     public function create_payment() {
919 919
 
920
-		$parent_invoice = $this->get_parent_payment();
921
-
922
-		if ( ! $parent_invoice->get_id() ) {
923
-			return false;
924
-		}
925
-
926
-		// Duplicate the parent invoice.
927
-		$invoice = new WPInv_Invoice();
928
-		$invoice->set_props( $parent_invoice->get_data() );
929
-		$invoice->set_id( 0 );
930
-		$invoice->set_items( $parent_invoice->get_items() );
931
-		$invoice->set_parent_id( $parent_invoice->get_id() );
932
-		$invoice->set_transaction_id( '' );
933
-		$invoice->set_key( $invoice->generate_key( 'renewal_' ) );
934
-		$invoice->set_number( '' );
935
-		$invoice->set_completed_date( '' );
936
-		$invoice->set_status( 'wpi-pending' );
937
-		$invoice->recalculate_total();
938
-		$invoice->save();
939
-
940
-		return $invoice->get_id() ? $invoice : false;
941
-    }
942
-
943
-	/**
944
-	 * Renews or completes a subscription
945
-	 *
946
-	 * @since  1.0.0
947
-	 * @return int The subscription's id
948
-	 */
949
-	public function renew() {
950
-
951
-		// Complete subscription if applicable
952
-		if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) {
953
-			return $this->complete();
954
-		}
955
-
956
-		// Calculate new expiration
957
-		$frequency      = $this->get_frequency();
958
-		$period         = $this->get_period();
959
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
960
-
961
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
962
-		$this->set_status( 'active' );
963
-		return $this->save();
964
-
965
-		do_action( 'getpaid_subscription_renewed', $this );
966
-
967
-	}
968
-
969
-	/**
970
-	 * Marks a subscription as completed
971
-	 *
972
-	 * Subscription is completed when the number of payments matches the billing_times field
973
-	 *
974
-	 * @since  1.0.0
975
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
976
-	 */
977
-	public function complete() {
978
-
979
-		// Only mark a subscription as complete if it's not already cancelled.
980
-		if ( $this->has_status( 'cancelled' ) ) {
981
-			return false;
982
-		}
983
-
984
-		$this->set_status( 'completed' );
985
-		return $this->save();
986
-
987
-	}
988
-
989
-	/**
990
-	 * Marks a subscription as expired
991
-	 *
992
-	 * @since  1.0.0
993
-	 * @param  bool $check_expiration
994
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
995
-	 */
996
-	public function expire( $check_expiration = false ) {
997
-
998
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
999
-			// Do not mark as expired since real expiration date is in the future
1000
-			return false;
1001
-		}
1002
-
1003
-		$this->set_status( 'expired' );
1004
-		return $this->save();
1005
-
1006
-	}
1007
-
1008
-	/**
1009
-	 * Marks a subscription as failing
1010
-	 *
1011
-	 * @since  2.4.2
1012
-	 * @return int Subscription id.
1013
-	 */
1014
-	public function failing() {
1015
-		$this->set_status( 'failing' );
1016
-		return $this->save();
1017
-	}
920
+        $parent_invoice = $this->get_parent_payment();
921
+
922
+        if ( ! $parent_invoice->get_id() ) {
923
+            return false;
924
+        }
925
+
926
+        // Duplicate the parent invoice.
927
+        $invoice = new WPInv_Invoice();
928
+        $invoice->set_props( $parent_invoice->get_data() );
929
+        $invoice->set_id( 0 );
930
+        $invoice->set_items( $parent_invoice->get_items() );
931
+        $invoice->set_parent_id( $parent_invoice->get_id() );
932
+        $invoice->set_transaction_id( '' );
933
+        $invoice->set_key( $invoice->generate_key( 'renewal_' ) );
934
+        $invoice->set_number( '' );
935
+        $invoice->set_completed_date( '' );
936
+        $invoice->set_status( 'wpi-pending' );
937
+        $invoice->recalculate_total();
938
+        $invoice->save();
939
+
940
+        return $invoice->get_id() ? $invoice : false;
941
+    }
942
+
943
+    /**
944
+     * Renews or completes a subscription
945
+     *
946
+     * @since  1.0.0
947
+     * @return int The subscription's id
948
+     */
949
+    public function renew() {
950
+
951
+        // Complete subscription if applicable
952
+        if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) {
953
+            return $this->complete();
954
+        }
955
+
956
+        // Calculate new expiration
957
+        $frequency      = $this->get_frequency();
958
+        $period         = $this->get_period();
959
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
960
+
961
+        $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
962
+        $this->set_status( 'active' );
963
+        return $this->save();
964
+
965
+        do_action( 'getpaid_subscription_renewed', $this );
966
+
967
+    }
968
+
969
+    /**
970
+     * Marks a subscription as completed
971
+     *
972
+     * Subscription is completed when the number of payments matches the billing_times field
973
+     *
974
+     * @since  1.0.0
975
+     * @return int|bool Subscription id or false if the subscription is cancelled.
976
+     */
977
+    public function complete() {
978
+
979
+        // Only mark a subscription as complete if it's not already cancelled.
980
+        if ( $this->has_status( 'cancelled' ) ) {
981
+            return false;
982
+        }
983
+
984
+        $this->set_status( 'completed' );
985
+        return $this->save();
986
+
987
+    }
988
+
989
+    /**
990
+     * Marks a subscription as expired
991
+     *
992
+     * @since  1.0.0
993
+     * @param  bool $check_expiration
994
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
995
+     */
996
+    public function expire( $check_expiration = false ) {
997
+
998
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
999
+            // Do not mark as expired since real expiration date is in the future
1000
+            return false;
1001
+        }
1002
+
1003
+        $this->set_status( 'expired' );
1004
+        return $this->save();
1005
+
1006
+    }
1007
+
1008
+    /**
1009
+     * Marks a subscription as failing
1010
+     *
1011
+     * @since  2.4.2
1012
+     * @return int Subscription id.
1013
+     */
1014
+    public function failing() {
1015
+        $this->set_status( 'failing' );
1016
+        return $this->save();
1017
+    }
1018 1018
 
1019 1019
     /**
1020 1020
      * Marks a subscription as cancelled
@@ -1023,19 +1023,19 @@  discard block
 block discarded – undo
1023 1023
      * @return int Subscription id.
1024 1024
      */
1025 1025
     public function cancel() {
1026
-		$this->set_status( 'cancelled' );
1027
-		return $this->save();
1026
+        $this->set_status( 'cancelled' );
1027
+        return $this->save();
1028 1028
     }
1029 1029
 
1030
-	/**
1031
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1032
-	 *
1033
-	 * @since  1.0.0
1034
-	 * @return bool
1035
-	 */
1036
-	public function can_cancel() {
1037
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1038
-	}
1030
+    /**
1031
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1032
+     *
1033
+     * @since  1.0.0
1034
+     * @return bool
1035
+     */
1036
+    public function can_cancel() {
1037
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1038
+    }
1039 1039
 
1040 1040
     /**
1041 1041
      * Returns an array of subscription statuses that can be cancelled
@@ -1048,82 +1048,82 @@  discard block
 block discarded – undo
1048 1048
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1049 1049
     }
1050 1050
 
1051
-	/**
1052
-	 * Retrieves the URL to cancel subscription
1053
-	 *
1054
-	 * @since  1.0.0
1055
-	 * @return string
1056
-	 */
1057
-	public function get_cancel_url() {
1058
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' );
1059
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1060
-	}
1061
-
1062
-	/**
1063
-	 * Determines if subscription can be manually renewed
1064
-	 *
1065
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1066
-	 * that can be renewed manually
1067
-	 *
1068
-	 * @since  2.5
1069
-	 * @return bool
1070
-	 */
1071
-	public function can_renew() {
1072
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1073
-	}
1074
-
1075
-	/**
1076
-	 * Retrieves the URL to renew a subscription
1077
-	 *
1078
-	 * @since  2.5
1079
-	 * @return string
1080
-	 */
1081
-	public function get_renew_url() {
1082
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' );
1083
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1084
-	}
1085
-
1086
-	/**
1087
-	 * Determines if subscription can have their payment method updated
1088
-	 *
1089
-	 * @since  1.0.0
1090
-	 * @return bool
1091
-	 */
1092
-	public function can_update() {
1093
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1094
-	}
1095
-
1096
-	/**
1097
-	 * Retrieves the URL to update subscription
1098
-	 *
1099
-	 * @since  1.0.0
1100
-	 * @return string
1101
-	 */
1102
-	public function get_update_url() {
1103
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1104
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1105
-	}
1106
-
1107
-	/**
1108
-	 * Retrieves the subscription status label
1109
-	 *
1110
-	 * @since  1.0.0
1111
-	 * @return string
1112
-	 */
1113
-	public function get_status_label() {
1114
-		return getpaid_get_subscription_status_label( $this->get_status() );
1115
-	}
1116
-
1117
-	/**
1118
-	 * Retrieves the subscription status class
1119
-	 *
1120
-	 * @since  1.0.19
1121
-	 * @return string
1122
-	 */
1123
-	public function get_status_class() {
1124
-		$statuses = getpaid_get_subscription_status_classes();
1125
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1126
-	}
1051
+    /**
1052
+     * Retrieves the URL to cancel subscription
1053
+     *
1054
+     * @since  1.0.0
1055
+     * @return string
1056
+     */
1057
+    public function get_cancel_url() {
1058
+        $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' );
1059
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1060
+    }
1061
+
1062
+    /**
1063
+     * Determines if subscription can be manually renewed
1064
+     *
1065
+     * This method is filtered by payment gateways in order to return true on subscriptions
1066
+     * that can be renewed manually
1067
+     *
1068
+     * @since  2.5
1069
+     * @return bool
1070
+     */
1071
+    public function can_renew() {
1072
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1073
+    }
1074
+
1075
+    /**
1076
+     * Retrieves the URL to renew a subscription
1077
+     *
1078
+     * @since  2.5
1079
+     * @return string
1080
+     */
1081
+    public function get_renew_url() {
1082
+        $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' );
1083
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1084
+    }
1085
+
1086
+    /**
1087
+     * Determines if subscription can have their payment method updated
1088
+     *
1089
+     * @since  1.0.0
1090
+     * @return bool
1091
+     */
1092
+    public function can_update() {
1093
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1094
+    }
1095
+
1096
+    /**
1097
+     * Retrieves the URL to update subscription
1098
+     *
1099
+     * @since  1.0.0
1100
+     * @return string
1101
+     */
1102
+    public function get_update_url() {
1103
+        $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1104
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1105
+    }
1106
+
1107
+    /**
1108
+     * Retrieves the subscription status label
1109
+     *
1110
+     * @since  1.0.0
1111
+     * @return string
1112
+     */
1113
+    public function get_status_label() {
1114
+        return getpaid_get_subscription_status_label( $this->get_status() );
1115
+    }
1116
+
1117
+    /**
1118
+     * Retrieves the subscription status class
1119
+     *
1120
+     * @since  1.0.19
1121
+     * @return string
1122
+     */
1123
+    public function get_status_class() {
1124
+        $statuses = getpaid_get_subscription_status_classes();
1125
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1126
+    }
1127 1127
 
1128 1128
     /**
1129 1129
      * Retrieves the subscription status label
@@ -1133,11 +1133,11 @@  discard block
 block discarded – undo
1133 1133
      */
1134 1134
     public function get_status_label_html() {
1135 1135
 
1136
-		$status_label = sanitize_text_field( $this->get_status_label() );
1137
-		$class        = esc_attr( $this->get_status_class() );
1138
-		$status       = sanitize_html_class( $this->get_status_label() );
1136
+        $status_label = sanitize_text_field( $this->get_status_label() );
1137
+        $class        = esc_attr( $this->get_status_class() );
1138
+        $status       = sanitize_html_class( $this->get_status_label() );
1139 1139
 
1140
-		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1140
+        return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1141 1141
     }
1142 1142
 
1143 1143
     /**
@@ -1148,63 +1148,63 @@  discard block
 block discarded – undo
1148 1148
      * @return bool
1149 1149
      */
1150 1150
     public function payment_exists( $txn_id = '' ) {
1151
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1151
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1152 1152
         return ! empty( $invoice_id );
1153
-	}
1154
-
1155
-	/**
1156
-	 * Handle the status transition.
1157
-	 */
1158
-	protected function status_transition() {
1159
-		$status_transition = $this->status_transition;
1160
-
1161
-		// Reset status transition variable.
1162
-		$this->status_transition = false;
1163
-
1164
-		if ( $status_transition ) {
1165
-			try {
1166
-
1167
-				// Fire a hook for the status change.
1168
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1169
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1170
-
1171
-				if ( ! empty( $status_transition['from'] ) ) {
1172
-
1173
-					/* translators: 1: old subscription status 2: new subscription status */
1174
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1175
-
1176
-					// Fire another hook.
1177
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1178
-					do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
1179
-
1180
-					// Note the transition occurred.
1181
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1182
-
1183
-				} else {
1184
-					/* translators: %s: new invoice status */
1185
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1186
-
1187
-					// Note the transition occurred.
1188
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1189
-
1190
-				}
1191
-			} catch ( Exception $e ) {
1192
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1193
-			}
1194
-		}
1195
-
1196
-	}
1197
-
1198
-	/**
1199
-	 * Save data to the database.
1200
-	 *
1201
-	 * @since 1.0.19
1202
-	 * @return int subscription ID
1203
-	 */
1204
-	public function save() {
1205
-		parent::save();
1206
-		$this->status_transition();
1207
-		return $this->get_id();
1208
-	}
1153
+    }
1154
+
1155
+    /**
1156
+     * Handle the status transition.
1157
+     */
1158
+    protected function status_transition() {
1159
+        $status_transition = $this->status_transition;
1160
+
1161
+        // Reset status transition variable.
1162
+        $this->status_transition = false;
1163
+
1164
+        if ( $status_transition ) {
1165
+            try {
1166
+
1167
+                // Fire a hook for the status change.
1168
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1169
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1170
+
1171
+                if ( ! empty( $status_transition['from'] ) ) {
1172
+
1173
+                    /* translators: 1: old subscription status 2: new subscription status */
1174
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1175
+
1176
+                    // Fire another hook.
1177
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1178
+                    do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
1179
+
1180
+                    // Note the transition occurred.
1181
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1182
+
1183
+                } else {
1184
+                    /* translators: %s: new invoice status */
1185
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1186
+
1187
+                    // Note the transition occurred.
1188
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1189
+
1190
+                }
1191
+            } catch ( Exception $e ) {
1192
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1193
+            }
1194
+        }
1195
+
1196
+    }
1197
+
1198
+    /**
1199
+     * Save data to the database.
1200
+     *
1201
+     * @since 1.0.19
1202
+     * @return int subscription ID
1203
+     */
1204
+    public function save() {
1205
+        parent::save();
1206
+        $this->status_transition();
1207
+        return $this->get_id();
1208
+    }
1209 1209
 
1210 1210
 }
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 1 patch
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wpinv_subscriptions_page() {
16 16
 
17
-	?>
17
+    ?>
18 18
 
19 19
 	<div class="wrap">
20 20
 		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
@@ -22,27 +22,27 @@  discard block
 block discarded – undo
22 22
 
23 23
 			<?php
24 24
 
25
-				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
25
+                // Verify user permissions.
26
+                if ( ! wpinv_current_user_can_manage_invoicing() ) {
27 27
 
28
-					echo aui()->alert(
29
-						array(
30
-							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
-						)
33
-					);
28
+                    echo aui()->alert(
29
+                        array(
30
+                            'type'    => 'danger',
31
+                            'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
+                        )
33
+                    );
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+                } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
36 36
 
37
-					// Display a single subscription.
38
-					wpinv_recurring_subscription_details();
39
-				} else {
37
+                    // Display a single subscription.
38
+                    wpinv_recurring_subscription_details();
39
+                } else {
40 40
 
41
-					// Display a list of available subscriptions.
42
-					getpaid_print_subscriptions_list();
43
-				}
41
+                    // Display a list of available subscriptions.
42
+                    getpaid_print_subscriptions_list();
43
+                }
44 44
 
45
-			?>
45
+            ?>
46 46
 
47 47
 		</div>
48 48
 	</div>
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function getpaid_print_subscriptions_list() {
61 61
 
62
-	$subscribers_table = new WPInv_Subscriptions_List_Table();
63
-	$subscribers_table->prepare_items();
62
+    $subscribers_table = new WPInv_Subscriptions_List_Table();
63
+    $subscribers_table->prepare_items();
64 64
 
65
-	?>
65
+    ?>
66 66
 	<form id="subscribers-filter" class="bsui" method="get">
67 67
 		<input type="hidden" name="page" value="wpinv-subscriptions" />
68 68
 		<?php $subscribers_table->views(); ?>
@@ -80,27 +80,27 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function wpinv_recurring_subscription_details() {
82 82
 
83
-	// Fetch the subscription.
84
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
85
-	if ( ! $sub->get_id() ) {
83
+    // Fetch the subscription.
84
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
85
+    if ( ! $sub->get_id() ) {
86 86
 
87
-		echo aui()->alert(
88
-			array(
89
-				'type'    => 'danger',
90
-				'content' => __( 'Subscription not found.', 'invoicing' ),
91
-			)
92
-		);
87
+        echo aui()->alert(
88
+            array(
89
+                'type'    => 'danger',
90
+                'content' => __( 'Subscription not found.', 'invoicing' ),
91
+            )
92
+        );
93 93
 
94
-		return;
95
-	}
94
+        return;
95
+    }
96 96
 
97
-	// Use metaboxes to display the subscription details.
98
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
97
+    // Use metaboxes to display the subscription details.
98
+    add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' );
99
+    add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
102 102
 
103
-	?>
103
+    ?>
104 104
 
105 105
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
106 106
 
@@ -140,28 +140,28 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function getpaid_admin_subscription_details_metabox( $sub ) {
142 142
 
143
-	// Prepare subscription detail columns.
144
-	$fields = apply_filters(
145
-		'getpaid_subscription_admin_page_fields',
146
-		array(
147
-			'subscription'   => __( 'Subscription', 'invoicing' ),
148
-			'customer'       => __( 'Customer', 'invoicing' ),
149
-			'amount'         => __( 'Amount', 'invoicing' ),
150
-			'start_date'     => __( 'Start Date', 'invoicing' ),
151
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
-			'renewals'       => __( 'Renewals', 'invoicing' ),
153
-			'item'           => __( 'Item', 'invoicing' ),
154
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
155
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
-			'status'         => __( 'Status', 'invoicing' ),
157
-		)
158
-	);
159
-
160
-	if ( ! $sub->is_active() && isset( $fields['renews_on'] ) ) {
161
-		unset( $fields['renews_on'] );
162
-	}
163
-
164
-	?>
143
+    // Prepare subscription detail columns.
144
+    $fields = apply_filters(
145
+        'getpaid_subscription_admin_page_fields',
146
+        array(
147
+            'subscription'   => __( 'Subscription', 'invoicing' ),
148
+            'customer'       => __( 'Customer', 'invoicing' ),
149
+            'amount'         => __( 'Amount', 'invoicing' ),
150
+            'start_date'     => __( 'Start Date', 'invoicing' ),
151
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
+            'renewals'       => __( 'Renewals', 'invoicing' ),
153
+            'item'           => __( 'Item', 'invoicing' ),
154
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
155
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
+            'status'         => __( 'Status', 'invoicing' ),
157
+        )
158
+    );
159
+
160
+    if ( ! $sub->is_active() && isset( $fields['renews_on'] ) ) {
161
+        unset( $fields['renews_on'] );
162
+    }
163
+
164
+    ?>
165 165
 
166 166
 		<table class="table table-borderless" style="font-size: 14px;">
167 167
 			<tbody>
@@ -195,20 +195,20 @@  discard block
 block discarded – undo
195 195
  */
196 196
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
197 197
 
198
-	$username = __( '(Missing User)', 'invoicing' );
198
+    $username = __( '(Missing User)', 'invoicing' );
199 199
 
200
-	$user = get_userdata( $subscription->get_customer_id() );
201
-	if ( $user ) {
200
+    $user = get_userdata( $subscription->get_customer_id() );
201
+    if ( $user ) {
202 202
 
203
-		$username = sprintf(
204
-			'<a href="user-edit.php?user_id=%s">%s</a>',
205
-			absint( $user->ID ),
206
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
207
-		);
203
+        $username = sprintf(
204
+            '<a href="user-edit.php?user_id=%s">%s</a>',
205
+            absint( $user->ID ),
206
+            ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
207
+        );
208 208
 
209
-	}
209
+    }
210 210
 
211
-	echo  $username;
211
+    echo  $username;
212 212
 }
213 213
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
214 214
 
@@ -219,43 +219,43 @@  discard block
 block discarded – undo
219 219
  */
220 220
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
221 221
 
222
-	$initial   = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() );
223
-	$recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() );
224
-	$period    = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() );
222
+    $initial   = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() );
223
+    $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() );
224
+    $period    = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() );
225 225
 
226
-	if ( $subscription->has_trial_period() ) {
226
+    if ( $subscription->has_trial_period() ) {
227 227
 
228
-		// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
229
-		$amount = sprintf(
230
-			_x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
231
-			$initial,
232
-			sanitize_text_field( $subscription->get_trial_period() ),
233
-			$recurring,
234
-			sanitize_text_field( strtolower( $period ) )
235
-		);
228
+        // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
229
+        $amount = sprintf(
230
+            _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
231
+            $initial,
232
+            sanitize_text_field( $subscription->get_trial_period() ),
233
+            $recurring,
234
+            sanitize_text_field( strtolower( $period ) )
235
+        );
236 236
 
237
-	} else if ( $initial != $recurring ) {
237
+    } else if ( $initial != $recurring ) {
238 238
 
239
-		// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio
240
-		$amount = sprintf(
241
-			_x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ),
242
-			$initial,
243
-			$recurring,
244
-			sanitize_text_field( strtolower( $period ) )
245
-		);
239
+        // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio
240
+        $amount = sprintf(
241
+            _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ),
242
+            $initial,
243
+            $recurring,
244
+            sanitize_text_field( strtolower( $period ) )
245
+        );
246 246
 
247
-	} else {
247
+    } else {
248 248
 
249
-		// translators: $1: is the recurring amount, $2: is the recurring period
250
-		$amount = sprintf(
251
-			_x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ),
252
-			$initial,
253
-			sanitize_text_field( strtolower( $period ) )
254
-		);
249
+        // translators: $1: is the recurring amount, $2: is the recurring period
250
+        $amount = sprintf(
251
+            _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ),
252
+            $initial,
253
+            sanitize_text_field( strtolower( $period ) )
254
+        );
255 255
 
256
-	}
256
+    }
257 257
 
258
-	echo "<span>$amount</span>";
258
+    echo "<span>$amount</span>";
259 259
 }
260 260
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
261 261
 
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
  * @param WPInv_Subscription $subscription
266 266
  */
267 267
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
268
-	echo  '#' . absint( $subscription->get_id() );
268
+    echo  '#' . absint( $subscription->get_id() );
269 269
 }
270 270
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
271 271
 
@@ -276,12 +276,12 @@  discard block
 block discarded – undo
276 276
  */
277 277
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
278 278
 
279
-	$created = $subscription->get_date_created();
280
-	if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) {
281
-		echo "&mdash;";
282
-	} else {
283
-		echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) );
284
-	}
279
+    $created = $subscription->get_date_created();
280
+    if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) {
281
+        echo "&mdash;";
282
+    } else {
283
+        echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $created ) );
284
+    }
285 285
 
286 286
 }
287 287
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
@@ -293,12 +293,12 @@  discard block
 block discarded – undo
293 293
  */
294 294
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
295 295
 
296
-	$expiration = $subscription->get_expiration();
297
-	if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
298
-		echo "&mdash;";
299
-	} else {
300
-		echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) );
301
-	}
296
+    $expiration = $subscription->get_expiration();
297
+    if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
298
+        echo "&mdash;";
299
+    } else {
300
+        echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $expiration ) );
301
+    }
302 302
 
303 303
 }
304 304
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
  * @param WPInv_Subscription $subscription
310 310
  */
311 311
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
312
-	$max_bills = $subscription->get_bill_times();
313
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
312
+    $max_bills = $subscription->get_bill_times();
313
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
314 314
 }
315 315
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
316 316
 
@@ -321,16 +321,16 @@  discard block
 block discarded – undo
321 321
  */
322 322
 function getpaid_admin_subscription_metabox_display_item( $subscription ) {
323 323
 
324
-	$item = get_post( $subscription->get_product_id() );
324
+    $item = get_post( $subscription->get_product_id() );
325 325
 
326
-	if ( ! empty( $item ) ) {
327
-		$link = get_edit_post_link( $item );
328
-		$link = esc_url( $link );
329
-		$name = esc_html( get_the_title( $item ) );
330
-		echo "<a href='$link'>$name</a>";
331
-	} else {
332
-		echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
333
-	}
326
+    if ( ! empty( $item ) ) {
327
+        $link = get_edit_post_link( $item );
328
+        $link = esc_url( $link );
329
+        $name = esc_html( get_the_title( $item ) );
330
+        echo "<a href='$link'>$name</a>";
331
+    } else {
332
+        echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
333
+    }
334 334
 
335 335
 }
336 336
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' );
@@ -342,13 +342,13 @@  discard block
 block discarded – undo
342 342
  */
343 343
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
344 344
 
345
-	$gateway = $subscription->get_gateway();
345
+    $gateway = $subscription->get_gateway();
346 346
 
347
-	if ( ! empty( $gateway ) ) {
348
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
349
-	} else {
350
-		echo "&mdash;";
351
-	}
347
+    if ( ! empty( $gateway ) ) {
348
+        echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
349
+    } else {
350
+        echo "&mdash;";
351
+    }
352 352
 
353 353
 }
354 354
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
  * @param WPInv_Subscription $subscription
360 360
  */
361 361
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
362
-	echo $subscription->get_status_label_html();
362
+    echo $subscription->get_status_label_html();
363 363
 }
364 364
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
365 365
 
@@ -370,14 +370,14 @@  discard block
 block discarded – undo
370 370
  */
371 371
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
372 372
 
373
-	$profile_id = $subscription->get_profile_id();
373
+    $profile_id = $subscription->get_profile_id();
374 374
 
375
-	if ( ! empty( $profile_id ) ) {
376
-		$profile_id = sanitize_text_field( $profile_id );
377
-		echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription );
378
-	} else {
379
-		echo "&mdash;";
380
-	}
375
+    if ( ! empty( $profile_id ) ) {
376
+        $profile_id = sanitize_text_field( $profile_id );
377
+        echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription );
378
+    } else {
379
+        echo "&mdash;";
380
+    }
381 381
 
382 382
 }
383 383
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -389,39 +389,39 @@  discard block
 block discarded – undo
389 389
  */
390 390
 function getpaid_admin_subscription_update_metabox( $subscription ) {
391 391
 
392
-	?>
392
+    ?>
393 393
 	<div class="mt-3">
394 394
 
395 395
 		<?php
396
-			echo aui()->select(
397
-				array(
398
-					'options'          => getpaid_get_subscription_statuses(),
399
-					'name'             => 'subscription_status',
400
-					'id'               => 'subscription_status_update_select',
401
-					'required'         => true,
402
-					'no_wrap'          => false,
403
-					'label'            => __( 'Subscription Status', 'invoicing' ),
404
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
405
-					'select2'          => true,
406
-					'value'            => $subscription->get_status( 'edit' ),
407
-				)
408
-			);
409
-		?>
396
+            echo aui()->select(
397
+                array(
398
+                    'options'          => getpaid_get_subscription_statuses(),
399
+                    'name'             => 'subscription_status',
400
+                    'id'               => 'subscription_status_update_select',
401
+                    'required'         => true,
402
+                    'no_wrap'          => false,
403
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
404
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
405
+                    'select2'          => true,
406
+                    'value'            => $subscription->get_status( 'edit' ),
407
+                )
408
+            );
409
+        ?>
410 410
 
411 411
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
412 412
 	
413 413
 		<?php
414
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
414
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
415 415
 
416
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
417
-			$anchor = __( 'Renew Subscription', 'invoicing' );
418
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
416
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
417
+            $anchor = __( 'Renew Subscription', 'invoicing' );
418
+            $title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
419 419
 
420
-			if ( $subscription->is_active() ) {
421
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
422
-			}
420
+            if ( $subscription->is_active() ) {
421
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
422
+            }
423 423
 
424
-	echo '</div></div>';
424
+    echo '</div></div>';
425 425
 }
426 426
 
427 427
 /**
@@ -431,27 +431,27 @@  discard block
 block discarded – undo
431 431
  */
432 432
 function getpaid_admin_subscription_invoice_details_metabox( $subscription ) {
433 433
 
434
-	$columns = apply_filters(
435
-		'getpaid_subscription_related_invoices_columns',
436
-		array(
437
-
438
-			'invoice'      => __( 'Invoice', 'invoicing' ),
439
-			'relationship' => __( 'Relationship', 'invoicing' ),
440
-			'date'         => __( 'Date', 'invoicing' ),
441
-			'status'       => __( 'Status', 'invoicing' ),
442
-			'total'        => __( 'Total', 'invoicing' ),
443
-		)
444
-	);
445
-
446
-	// Prepare the invoices.
447
-	$payments = $subscription->get_child_payments();
448
-	$parent   = $subscription->get_parent_invoice();
449
-
450
-	if ( $parent->get_id() ) {
451
-		$payments = array_merge( array( $parent ), $payments );
452
-	}
434
+    $columns = apply_filters(
435
+        'getpaid_subscription_related_invoices_columns',
436
+        array(
437
+
438
+            'invoice'      => __( 'Invoice', 'invoicing' ),
439
+            'relationship' => __( 'Relationship', 'invoicing' ),
440
+            'date'         => __( 'Date', 'invoicing' ),
441
+            'status'       => __( 'Status', 'invoicing' ),
442
+            'total'        => __( 'Total', 'invoicing' ),
443
+        )
444
+    );
445
+
446
+    // Prepare the invoices.
447
+    $payments = $subscription->get_child_payments();
448
+    $parent   = $subscription->get_parent_invoice();
449
+
450
+    if ( $parent->get_id() ) {
451
+        $payments = array_merge( array( $parent ), $payments );
452
+    }
453 453
 	
454
-	?>
454
+    ?>
455 455
 		<div class="m-0" style="overflow: auto;">
456 456
 
457 457
 			<table class="w-100 bg-white">
@@ -459,13 +459,13 @@  discard block
 block discarded – undo
459 459
 				<thead>
460 460
 					<tr>
461 461
 						<?php
462
-							foreach ( $columns as $key => $label ) {
463
-								$key   = esc_attr( $key );
464
-								$label = sanitize_text_field( $label );
462
+                            foreach ( $columns as $key => $label ) {
463
+                                $key   = esc_attr( $key );
464
+                                $label = sanitize_text_field( $label );
465 465
 
466
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>";
467
-							}
468
-						?>
466
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>";
467
+                            }
468
+                        ?>
469 469
 					</tr>
470 470
 				</thead>
471 471
 
@@ -473,57 +473,57 @@  discard block
 block discarded – undo
473 473
 
474 474
 					<?php
475 475
 
476
-						foreach( $payments as $payment ) :
476
+                        foreach( $payments as $payment ) :
477 477
 
478
-							// Ensure that we have an invoice.
479
-							if ( ! is_a( $payment, 'WPInv_Invoice' ) ) {
480
-								$payment = new WPInv_Invoice( $payment );
481
-							}
478
+                            // Ensure that we have an invoice.
479
+                            if ( ! is_a( $payment, 'WPInv_Invoice' ) ) {
480
+                                $payment = new WPInv_Invoice( $payment );
481
+                            }
482 482
 
483
-							// Abort if the invoice is invalid.
484
-							if ( ! $payment->get_id() ) {
485
-								continue;
486
-							}
483
+                            // Abort if the invoice is invalid.
484
+                            if ( ! $payment->get_id() ) {
485
+                                continue;
486
+                            }
487 487
 
488
-							echo '<tr>';
488
+                            echo '<tr>';
489 489
 
490
-								foreach ( array_keys( $columns ) as $key ) {
490
+                                foreach ( array_keys( $columns ) as $key ) {
491 491
 									
492
-									echo '<td class="p-2 text-left">';
492
+                                    echo '<td class="p-2 text-left">';
493 493
 
494
-										switch( $key ) {
494
+                                        switch( $key ) {
495 495
 
496
-											case 'total':
497
-												echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>';
498
-												break;
496
+                                            case 'total':
497
+                                                echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>';
498
+                                                break;
499 499
 
500
-											case 'relationship':
501
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
502
-												break;
500
+                                            case 'relationship':
501
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
502
+                                                break;
503 503
 
504
-											case 'date':
505
-												echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $payment->get_date_created() ) );
506
-												break;
504
+                                            case 'date':
505
+                                                echo date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $payment->get_date_created() ) );
506
+                                                break;
507 507
 
508
-											case 'status':
509
-												echo $payment->get_status_label_html();
510
-												break;
508
+                                            case 'status':
509
+                                                echo $payment->get_status_label_html();
510
+                                                break;
511 511
 
512
-											case 'invoice':
513
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
514
-												$invoice = sanitize_text_field( $payment->get_number() );
515
-												echo "<a href='$link'>$invoice</a>";
516
-												break;
517
-										}
512
+                                            case 'invoice':
513
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
514
+                                                $invoice = sanitize_text_field( $payment->get_number() );
515
+                                                echo "<a href='$link'>$invoice</a>";
516
+                                                break;
517
+                                        }
518 518
 
519
-									echo '</td>';
519
+                                    echo '</td>';
520 520
 								
521
-								}
521
+                                }
522 522
 
523
-							echo '</tr>';
523
+                            echo '</tr>';
524 524
 
525
-						endforeach;
526
-					?>
525
+                        endforeach;
526
+                    ?>
527 527
 
528 528
 				</tbody>
529 529
 
@@ -543,30 +543,30 @@  discard block
 block discarded – undo
543 543
  */
544 544
 function wpinv_recurring_process_subscription_deletion() {
545 545
 
546
-	if( empty( $_POST['sub_id'] ) ) {
547
-		return;
548
-	}
546
+    if( empty( $_POST['sub_id'] ) ) {
547
+        return;
548
+    }
549 549
 
550
-	if( empty( $_POST['wpinv_delete_subscription'] ) ) {
551
-		return;
552
-	}
550
+    if( empty( $_POST['wpinv_delete_subscription'] ) ) {
551
+        return;
552
+    }
553 553
 
554
-	if( ! current_user_can( 'manage_invoicing') ) {
555
-		return;
556
-	}
554
+    if( ! current_user_can( 'manage_invoicing') ) {
555
+        return;
556
+    }
557 557
 
558
-	if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) {
559
-		wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
560
-	}
558
+    if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) {
559
+        wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
560
+    }
561 561
 
562
-	$subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) );
562
+    $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) );
563 563
 
564
-	delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' );
564
+    delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' );
565 565
 
566
-	$subscription->delete();
566
+    $subscription->delete();
567 567
 
568
-	wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) );
569
-	exit;
568
+    wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) );
569
+    exit;
570 570
 
571 571
 }
572 572
 add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 );
Please login to merge, or discard this patch.