Passed
Push — master ( 72aaeb...55577f )
by Brian
04:34
created
includes/admin/subscriptions.php 1 patch
Indentation   +323 added lines, -323 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,37 +80,37 @@  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->exists() ) {
83
+    // Fetch the subscription.
84
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
85
+    if ( ! $sub->exists() ) {
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' );
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 100
 
101
-	$subscription_id     = $sub->get_id();
102
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
103
-	$subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
101
+    $subscription_id     = $sub->get_id();
102
+    $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
103
+    $subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
104 104
 
105
-	if ( ! empty( $subscription_group ) ) {
106
-		add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'advanced' );
107
-	}
105
+    if ( ! empty( $subscription_group ) ) {
106
+        add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'advanced' );
107
+    }
108 108
 
109
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced', 'low' );
109
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced', 'low' );
110 110
 
111
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
111
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
112 112
 
113
-	?>
113
+    ?>
114 114
 
115 115
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
116 116
 
@@ -150,45 +150,45 @@  discard block
 block discarded – undo
150 150
  */
151 151
 function getpaid_admin_subscription_details_metabox( $sub ) {
152 152
 
153
-	// Subscription items.
154
-	$subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
155
-	$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
156
-
157
-	// Prepare subscription detail columns.
158
-	$fields = apply_filters(
159
-		'getpaid_subscription_admin_page_fields',
160
-		array(
161
-			'subscription'   => __( 'Subscription', 'invoicing' ),
162
-			'customer'       => __( 'Customer', 'invoicing' ),
163
-			'amount'         => __( 'Amount', 'invoicing' ),
164
-			'start_date'     => __( 'Start Date', 'invoicing' ),
165
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
166
-			'renewals'       => __( 'Payments', 'invoicing' ),
167
-			'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
168
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
169
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
170
-			'status'         => __( 'Status', 'invoicing' ),
171
-		)
172
-	);
173
-
174
-	if ( ! $sub->is_active() ) {
175
-
176
-		if ( isset( $fields['renews_on'] ) ) {
177
-			unset( $fields['renews_on'] );
178
-		}
179
-
180
-		if ( isset( $fields['gateway'] ) ) {
181
-			unset( $fields['gateway'] );
182
-		}
183
-
184
-	}
185
-
186
-	$profile_id = $sub->get_profile_id();
187
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
188
-		unset( $fields['profile_id'] );
189
-	}
190
-
191
-	?>
153
+    // Subscription items.
154
+    $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
155
+    $items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
156
+
157
+    // Prepare subscription detail columns.
158
+    $fields = apply_filters(
159
+        'getpaid_subscription_admin_page_fields',
160
+        array(
161
+            'subscription'   => __( 'Subscription', 'invoicing' ),
162
+            'customer'       => __( 'Customer', 'invoicing' ),
163
+            'amount'         => __( 'Amount', 'invoicing' ),
164
+            'start_date'     => __( 'Start Date', 'invoicing' ),
165
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
166
+            'renewals'       => __( 'Payments', 'invoicing' ),
167
+            'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
168
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
169
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
170
+            'status'         => __( 'Status', 'invoicing' ),
171
+        )
172
+    );
173
+
174
+    if ( ! $sub->is_active() ) {
175
+
176
+        if ( isset( $fields['renews_on'] ) ) {
177
+            unset( $fields['renews_on'] );
178
+        }
179
+
180
+        if ( isset( $fields['gateway'] ) ) {
181
+            unset( $fields['gateway'] );
182
+        }
183
+
184
+    }
185
+
186
+    $profile_id = $sub->get_profile_id();
187
+    if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
188
+        unset( $fields['profile_id'] );
189
+    }
190
+
191
+    ?>
192 192
 
193 193
 		<table class="table table-borderless" style="font-size: 14px;">
194 194
 			<tbody>
@@ -222,20 +222,20 @@  discard block
 block discarded – undo
222 222
  */
223 223
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
224 224
 
225
-	$username = __( '(Missing User)', 'invoicing' );
225
+    $username = __( '(Missing User)', 'invoicing' );
226 226
 
227
-	$user = get_userdata( $subscription->get_customer_id() );
228
-	if ( $user ) {
227
+    $user = get_userdata( $subscription->get_customer_id() );
228
+    if ( $user ) {
229 229
 
230
-		$username = sprintf(
231
-			'<a href="user-edit.php?user_id=%s">%s</a>',
232
-			absint( $user->ID ),
233
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
234
-		);
230
+        $username = sprintf(
231
+            '<a href="user-edit.php?user_id=%s">%s</a>',
232
+            absint( $user->ID ),
233
+            ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
234
+        );
235 235
 
236
-	}
236
+    }
237 237
 
238
-	echo  $username;
238
+    echo  $username;
239 239
 }
240 240
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
241 241
 
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
  * @param WPInv_Subscription $subscription
246 246
  */
247 247
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
248
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
249
-	echo "<span>$amount</span>";
248
+    $amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
249
+    echo "<span>$amount</span>";
250 250
 }
251 251
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
252 252
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
  * @param WPInv_Subscription $subscription
257 257
  */
258 258
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
259
-	echo  '#' . absint( $subscription->get_id() );
259
+    echo  '#' . absint( $subscription->get_id() );
260 260
 }
261 261
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
262 262
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
  * @param WPInv_Subscription $subscription
267 267
  */
268 268
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
269
-	echo getpaid_format_date_value( $subscription->get_date_created() );
269
+    echo getpaid_format_date_value( $subscription->get_date_created() );
270 270
 }
271 271
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
272 272
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
  * @param WPInv_Subscription $subscription
277 277
  */
278 278
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
279
-	echo getpaid_format_date_value( $subscription->get_expiration() );
279
+    echo getpaid_format_date_value( $subscription->get_expiration() );
280 280
 }
281 281
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
282 282
 
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
  * @param WPInv_Subscription $subscription
287 287
  */
288 288
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
289
-	$max_bills = $subscription->get_bill_times();
290
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
289
+    $max_bills = $subscription->get_bill_times();
290
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
291 291
 }
292 292
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
293 293
 /**
@@ -298,13 +298,13 @@  discard block
 block discarded – undo
298 298
  */
299 299
 function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) {
300 300
 
301
-	if ( empty( $subscription_group ) ) {
302
-		echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
303
-		return;
304
-	}
301
+    if ( empty( $subscription_group ) ) {
302
+        echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
303
+        return;
304
+    }
305 305
 
306
-	$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
307
-	echo implode( ' | ', $markup );
306
+    $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
307
+    echo implode( ' | ', $markup );
308 308
 
309 309
 }
310 310
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 );
@@ -316,13 +316,13 @@  discard block
 block discarded – undo
316 316
  */
317 317
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
318 318
 
319
-	$gateway = $subscription->get_gateway();
319
+    $gateway = $subscription->get_gateway();
320 320
 
321
-	if ( ! empty( $gateway ) ) {
322
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
323
-	} else {
324
-		echo "&mdash;";
325
-	}
321
+    if ( ! empty( $gateway ) ) {
322
+        echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
323
+    } else {
324
+        echo "&mdash;";
325
+    }
326 326
 
327 327
 }
328 328
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
  * @param WPInv_Subscription $subscription
334 334
  */
335 335
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
336
-	echo $subscription->get_status_label_html();
336
+    echo $subscription->get_status_label_html();
337 337
 }
338 338
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
339 339
 
@@ -344,29 +344,29 @@  discard block
 block discarded – undo
344 344
  */
345 345
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
346 346
 
347
-	$profile_id = $subscription->get_profile_id();
348
-
349
-	$input = aui()->input(
350
-		array(
351
-			'type'        => 'text',
352
-			'id'          => 'wpinv_subscription_profile_id',
353
-			'name'        => 'wpinv_subscription_profile_id',
354
-			'label'       => __( 'Profile Id', 'invoicing' ),
355
-			'label_type'  => 'hidden',
356
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
357
-			'value'       => sanitize_text_field( $profile_id ),
358
-			'input_group_right' => '',
359
-			'no_wrap'     => true,
360
-		)
361
-	);
362
-
363
-	echo str_ireplace( 'form-control', 'regular-text', $input );
364
-
365
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
366
-	if ( ! empty( $url ) ) {
367
-		$url = esc_url_raw( $url );
368
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
369
-	}
347
+    $profile_id = $subscription->get_profile_id();
348
+
349
+    $input = aui()->input(
350
+        array(
351
+            'type'        => 'text',
352
+            'id'          => 'wpinv_subscription_profile_id',
353
+            'name'        => 'wpinv_subscription_profile_id',
354
+            'label'       => __( 'Profile Id', 'invoicing' ),
355
+            'label_type'  => 'hidden',
356
+            'placeholder' => __( 'Profile Id', 'invoicing' ),
357
+            'value'       => sanitize_text_field( $profile_id ),
358
+            'input_group_right' => '',
359
+            'no_wrap'     => true,
360
+        )
361
+    );
362
+
363
+    echo str_ireplace( 'form-control', 'regular-text', $input );
364
+
365
+    $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
366
+    if ( ! empty( $url ) ) {
367
+        $url = esc_url_raw( $url );
368
+        echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
369
+    }
370 370
 
371 371
 }
372 372
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -378,39 +378,39 @@  discard block
 block discarded – undo
378 378
  */
379 379
 function getpaid_admin_subscription_update_metabox( $subscription ) {
380 380
 
381
-	?>
381
+    ?>
382 382
 	<div class="mt-3">
383 383
 
384 384
 		<?php
385
-			echo aui()->select(
386
-				array(
387
-					'options'          => getpaid_get_subscription_statuses(),
388
-					'name'             => 'subscription_status',
389
-					'id'               => 'subscription_status_update_select',
390
-					'required'         => true,
391
-					'no_wrap'          => false,
392
-					'label'            => __( 'Subscription Status', 'invoicing' ),
393
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
394
-					'select2'          => true,
395
-					'value'            => $subscription->get_status( 'edit' ),
396
-				)
397
-			);
398
-		?>
385
+            echo aui()->select(
386
+                array(
387
+                    'options'          => getpaid_get_subscription_statuses(),
388
+                    'name'             => 'subscription_status',
389
+                    'id'               => 'subscription_status_update_select',
390
+                    'required'         => true,
391
+                    'no_wrap'          => false,
392
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
393
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
394
+                    'select2'          => true,
395
+                    'value'            => $subscription->get_status( 'edit' ),
396
+                )
397
+            );
398
+        ?>
399 399
 
400 400
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
401 401
 
402 402
 		<?php
403
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
403
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
404 404
 
405
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
406
-			$anchor = __( 'Renew Subscription', 'invoicing' );
407
-			$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' );
405
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
406
+            $anchor = __( 'Renew Subscription', 'invoicing' );
407
+            $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' );
408 408
 
409
-			if ( $subscription->is_active() ) {
410
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
411
-			}
409
+            if ( $subscription->is_active() ) {
410
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
411
+            }
412 412
 
413
-	echo '</div></div>';
413
+    echo '</div></div>';
414 414
 }
415 415
 
416 416
 /**
@@ -420,33 +420,33 @@  discard block
 block discarded – undo
420 420
  */
421 421
 function getpaid_admin_subscription_invoice_details_metabox( $subscription ) {
422 422
 
423
-	$columns = apply_filters(
424
-		'getpaid_subscription_related_invoices_columns',
425
-		array(
426
-			'invoice'      => __( 'Invoice', 'invoicing' ),
427
-			'relationship' => __( 'Relationship', 'invoicing' ),
428
-			'date'         => __( 'Date', 'invoicing' ),
429
-			'status'       => __( 'Status', 'invoicing' ),
430
-			'total'        => __( 'Total', 'invoicing' ),
431
-		),
432
-		$subscription
433
-	);
434
-
435
-	// Prepare the invoices.
436
-	$payments = $subscription->get_child_payments( ! is_admin() );
437
-	$parent   = $subscription->get_parent_invoice();
438
-
439
-	if ( $parent->get_id() ) {
440
-		$payments = array_merge( array( $parent ), $payments );
441
-	}
442
-
443
-	$table_class = 'w-100 bg-white';
444
-
445
-	if ( ! is_admin() ) {
446
-		$table_class = 'table table-bordered table-striped';
447
-	}
448
-
449
-	?>
423
+    $columns = apply_filters(
424
+        'getpaid_subscription_related_invoices_columns',
425
+        array(
426
+            'invoice'      => __( 'Invoice', 'invoicing' ),
427
+            'relationship' => __( 'Relationship', 'invoicing' ),
428
+            'date'         => __( 'Date', 'invoicing' ),
429
+            'status'       => __( 'Status', 'invoicing' ),
430
+            'total'        => __( 'Total', 'invoicing' ),
431
+        ),
432
+        $subscription
433
+    );
434
+
435
+    // Prepare the invoices.
436
+    $payments = $subscription->get_child_payments( ! is_admin() );
437
+    $parent   = $subscription->get_parent_invoice();
438
+
439
+    if ( $parent->get_id() ) {
440
+        $payments = array_merge( array( $parent ), $payments );
441
+    }
442
+
443
+    $table_class = 'w-100 bg-white';
444
+
445
+    if ( ! is_admin() ) {
446
+        $table_class = 'table table-bordered table-striped';
447
+    }
448
+
449
+    ?>
450 450
 		<div class="m-0" style="overflow: auto;">
451 451
 
452 452
 			<table class="<?php echo $table_class; ?>">
@@ -454,18 +454,18 @@  discard block
 block discarded – undo
454 454
 				<thead>
455 455
 					<tr>
456 456
 						<?php
457
-							$processed_columns = 0;
458
-							foreach ( $columns as $key => $label ) {
459
-								$key   = esc_attr( $key );
460
-								$label = sanitize_text_field( $label );
461
-								$class = 'text-center';
462
-								$class = empty( $processed_columns ) ? 'text-left' : $class;
463
-								$class = count( $columns ) - 1 == $processed_columns ? 'text-right' : $class;
464
-								$processed_columns ++;
465
-
466
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
467
-							}
468
-						?>
457
+                            $processed_columns = 0;
458
+                            foreach ( $columns as $key => $label ) {
459
+                                $key   = esc_attr( $key );
460
+                                $label = sanitize_text_field( $label );
461
+                                $class = 'text-center';
462
+                                $class = empty( $processed_columns ) ? 'text-left' : $class;
463
+                                $class = count( $columns ) - 1 == $processed_columns ? 'text-right' : $class;
464
+                                $processed_columns ++;
465
+
466
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
467
+                            }
468
+                        ?>
469 469
 					</tr>
470 470
 				</thead>
471 471
 
@@ -481,72 +481,72 @@  discard block
 block discarded – undo
481 481
 
482 482
 					<?php
483 483
 
484
-						foreach( $payments as $payment ) :
484
+                        foreach( $payments as $payment ) :
485 485
 
486
-							// Ensure that we have an invoice.
487
-							$payment = new WPInv_Invoice( $payment );
486
+                            // Ensure that we have an invoice.
487
+                            $payment = new WPInv_Invoice( $payment );
488 488
 
489
-							// Abort if the invoice is invalid.
490
-							if ( ! $payment->get_id() ) {
491
-								continue;
492
-							}
489
+                            // Abort if the invoice is invalid.
490
+                            if ( ! $payment->get_id() ) {
491
+                                continue;
492
+                            }
493 493
 
494
-							echo '<tr>';
494
+                            echo '<tr>';
495 495
 
496
-								$processed_columns = 0;
497
-								foreach ( array_keys( $columns ) as $key ) {
496
+                                $processed_columns = 0;
497
+                                foreach ( array_keys( $columns ) as $key ) {
498 498
 
499
-									$class = 'text-center';
500
-									$class = empty( $processed_columns ) ? 'text-left' : $class;
501
-									$class = count( $columns ) - 1 == $processed_columns ? 'text-right' : $class;
502
-									$processed_columns ++;
499
+                                    $class = 'text-center';
500
+                                    $class = empty( $processed_columns ) ? 'text-left' : $class;
501
+                                    $class = count( $columns ) - 1 == $processed_columns ? 'text-right' : $class;
502
+                                    $processed_columns ++;
503 503
 
504
-									echo "<td class='p-2 $class'>";
504
+                                    echo "<td class='p-2 $class'>";
505 505
 
506
-										switch( $key ) {
506
+                                        switch( $key ) {
507 507
 
508
-											case 'total':
509
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
510
-												break;
508
+                                            case 'total':
509
+                                                echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
510
+                                                break;
511 511
 
512
-											case 'relationship':
513
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
514
-												break;
512
+                                            case 'relationship':
513
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
514
+                                                break;
515 515
 
516
-											case 'date':
517
-												echo getpaid_format_date_value( $payment->get_date_created() );
518
-												break;
516
+                                            case 'date':
517
+                                                echo getpaid_format_date_value( $payment->get_date_created() );
518
+                                                break;
519 519
 
520
-											case 'status':
520
+                                            case 'status':
521 521
 
522
-												$status = $payment->get_status_nicename();
523
-												if ( is_admin() ) {
524
-													$status = $payment->get_status_label_html();
525
-												}
522
+                                                $status = $payment->get_status_nicename();
523
+                                                if ( is_admin() ) {
524
+                                                    $status = $payment->get_status_label_html();
525
+                                                }
526 526
 
527
-												echo $status;
528
-												break;
527
+                                                echo $status;
528
+                                                break;
529 529
 
530
-											case 'invoice':
531
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
530
+                                            case 'invoice':
531
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
532 532
 
533
-												if ( ! is_admin() ) {
534
-													$link = esc_url( $payment->get_view_url() );
535
-												}
533
+                                                if ( ! is_admin() ) {
534
+                                                    $link = esc_url( $payment->get_view_url() );
535
+                                                }
536 536
 
537
-												$invoice = sanitize_text_field( $payment->get_number() );
538
-												echo "<a href='$link'>$invoice</a>";
539
-												break;
540
-										}
537
+                                                $invoice = sanitize_text_field( $payment->get_number() );
538
+                                                echo "<a href='$link'>$invoice</a>";
539
+                                                break;
540
+                                        }
541 541
 
542
-									echo '</td>';
542
+                                    echo '</td>';
543 543
 
544
-								}
544
+                                }
545 545
 
546
-							echo '</tr>';
546
+                            echo '</tr>';
547 547
 
548
-						endforeach;
549
-					?>
548
+                        endforeach;
549
+                    ?>
550 550
 
551 551
 				</tbody>
552 552
 
@@ -564,42 +564,42 @@  discard block
 block discarded – undo
564 564
  */
565 565
 function getpaid_admin_subscription_item_details_metabox( $subscription ) {
566 566
 
567
-	// Fetch the subscription group.
568
-	$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
567
+    // Fetch the subscription group.
568
+    $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
569 569
 
570
-	if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
571
-		return;
572
-	}
570
+    if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
571
+        return;
572
+    }
573 573
 
574
-	// Prepare table columns.
575
-	$columns = apply_filters(
576
-		'getpaid_subscription_item_details_columns',
577
-		array(
578
-			'item_name'    => __( 'Item', 'invoicing' ),
579
-			'price'        => __( 'Price', 'invoicing' ),
580
-			'tax'          => __( 'Tax', 'invoicing' ),
581
-			'discount'     => __( 'Discount', 'invoicing' ),
582
-			'initial'      => __( 'Initial Amount', 'invoicing' ),
583
-			'recurring'    => __( 'Recurring Amount', 'invoicing' ),
584
-		),
585
-		$subscription
586
-	);
574
+    // Prepare table columns.
575
+    $columns = apply_filters(
576
+        'getpaid_subscription_item_details_columns',
577
+        array(
578
+            'item_name'    => __( 'Item', 'invoicing' ),
579
+            'price'        => __( 'Price', 'invoicing' ),
580
+            'tax'          => __( 'Tax', 'invoicing' ),
581
+            'discount'     => __( 'Discount', 'invoicing' ),
582
+            'initial'      => __( 'Initial Amount', 'invoicing' ),
583
+            'recurring'    => __( 'Recurring Amount', 'invoicing' ),
584
+        ),
585
+        $subscription
586
+    );
587 587
 
588
-	// Prepare the invoices.
588
+    // Prepare the invoices.
589 589
 
590
-	$invoice = $subscription->get_parent_invoice();
590
+    $invoice = $subscription->get_parent_invoice();
591 591
 
592
-	if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
593
-		unset( $columns['tax'] );
594
-	}
592
+    if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
593
+        unset( $columns['tax'] );
594
+    }
595 595
 
596
-	$table_class = 'w-100 bg-white';
596
+    $table_class = 'w-100 bg-white';
597 597
 
598
-	if ( ! is_admin() ) {
599
-		$table_class = 'table table-bordered table-striped';
600
-	}
598
+    if ( ! is_admin() ) {
599
+        $table_class = 'table table-bordered table-striped';
600
+    }
601 601
 
602
-	?>
602
+    ?>
603 603
 		<div class="m-0" style="overflow: auto;">
604 604
 
605 605
 			<table class="<?php echo $table_class; ?>">
@@ -607,18 +607,18 @@  discard block
 block discarded – undo
607 607
 				<thead>
608 608
 					<tr>
609 609
 						<?php
610
-							$processed_columns = 0;
611
-							foreach ( $columns as $key => $label ) {
612
-								$key   = esc_attr( $key );
613
-								$label = sanitize_text_field( $label );
614
-								$class = 'text-center';
615
-								$class = empty( $processed_columns ) ? 'text-left' : $class;
616
-								$class = count( $columns ) - 1 == $processed_columns ? 'text-right' : $class;
617
-								$processed_columns ++;
618
-
619
-								echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
620
-							}
621
-						?>
610
+                            $processed_columns = 0;
611
+                            foreach ( $columns as $key => $label ) {
612
+                                $key   = esc_attr( $key );
613
+                                $label = sanitize_text_field( $label );
614
+                                $class = 'text-center';
615
+                                $class = empty( $processed_columns ) ? 'text-left' : $class;
616
+                                $class = count( $columns ) - 1 == $processed_columns ? 'text-right' : $class;
617
+                                $processed_columns ++;
618
+
619
+                                echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
620
+                            }
621
+                        ?>
622 622
 					</tr>
623 623
 				</thead>
624 624
 
@@ -626,64 +626,64 @@  discard block
 block discarded – undo
626 626
 
627 627
 					<?php
628 628
 
629
-						foreach( $subscription_group['items'] as $subscription_group_item ) :
629
+                        foreach( $subscription_group['items'] as $subscription_group_item ) :
630 630
 
631
-							echo '<tr>';
631
+                            echo '<tr>';
632 632
 
633
-								$processed_columns = 0;
634
-								foreach ( array_keys( $columns ) as $key ) {
633
+                                $processed_columns = 0;
634
+                                foreach ( array_keys( $columns ) as $key ) {
635 635
 
636
-									$class = 'text-center';
637
-									$class = empty( $processed_columns ) ? 'text-left' : $class;
638
-									$class = count( $columns ) - 1 == $processed_columns ? 'text-right' : $class;
639
-									$processed_columns ++;
636
+                                    $class = 'text-center';
637
+                                    $class = empty( $processed_columns ) ? 'text-left' : $class;
638
+                                    $class = count( $columns ) - 1 == $processed_columns ? 'text-right' : $class;
639
+                                    $processed_columns ++;
640 640
 
641
-									echo "<td class='p-2 $class'>";
641
+                                    echo "<td class='p-2 $class'>";
642 642
 
643
-										switch( $key ) {
643
+                                        switch( $key ) {
644 644
 
645
-											case 'item_name':
646
-												$item_name = get_the_title( $subscription_group_item['item_id'] );
647
-												$item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
645
+                                            case 'item_name':
646
+                                                $item_name = get_the_title( $subscription_group_item['item_id'] );
647
+                                                $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
648 648
 
649
-												if ( $invoice->get_template() == 'amount' || 1 === (int) $subscription_group_item['quantity'] ) {
650
-													echo sanitize_text_field( $item_name );
651
-												} else {
652
-													printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (int) $subscription_group_item['quantity'] );
653
-												}
649
+                                                if ( $invoice->get_template() == 'amount' || 1 === (int) $subscription_group_item['quantity'] ) {
650
+                                                    echo sanitize_text_field( $item_name );
651
+                                                } else {
652
+                                                    printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (int) $subscription_group_item['quantity'] );
653
+                                                }
654 654
 
655
-												break;
655
+                                                break;
656 656
 
657
-											case 'price':
658
-												echo wpinv_price( $subscription_group_item['price'], $invoice->get_currency() );
659
-												break;
657
+                                            case 'price':
658
+                                                echo wpinv_price( $subscription_group_item['price'], $invoice->get_currency() );
659
+                                                break;
660 660
 
661
-											case 'tax':
662
-												echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
663
-												break;
661
+                                            case 'tax':
662
+                                                echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
663
+                                                break;
664 664
 
665
-											case 'discount':
666
-												echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
667
-												break;
665
+                                            case 'discount':
666
+                                                echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
667
+                                                break;
668 668
 
669
-											case 'initial':
670
-												echo wpinv_price( $subscription_group_item['subtotal'], $invoice->get_currency() );
671
-												break;
669
+                                            case 'initial':
670
+                                                echo wpinv_price( $subscription_group_item['subtotal'], $invoice->get_currency() );
671
+                                                break;
672 672
 
673
-											case 'recurring':
674
-												echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
675
-												break;
673
+                                            case 'recurring':
674
+                                                echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
675
+                                                break;
676 676
 
677
-										}
677
+                                        }
678 678
 
679
-									echo '</td>';
679
+                                    echo '</td>';
680 680
 
681
-								}
681
+                                }
682 682
 
683
-							echo '</tr>';
683
+                            echo '</tr>';
684 684
 
685
-						endforeach;
686
-					?>
685
+                        endforeach;
686
+                    ?>
687 687
 
688 688
 				</tbody>
689 689
 
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 1 patch
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 if ( ! defined( 'ABSPATH' ) ) exit;
7 7
 
8 8
 if ( ! class_exists( 'WP_List_Table' ) ) {
9
-	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9
+    include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
12 12
 /**
@@ -14,406 +14,406 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_List_Table extends WP_List_Table {
16 16
 
17
-	/**
18
-	 * URL of this page
19
-	 *
20
-	 * @var   string
21
-	 * @since 1.0.19
22
-	 */
23
-	public $base_url;
24
-
25
-	/**
26
-	 * Query
27
-	 *
28
-	 * @var   GetPaid_Subscriptions_Query
29
-	 * @since 1.0.19
30
-	 */
31
-	public $query;
32
-
33
-	/**
34
-	 * Total subscriptions
35
-	 *
36
-	 * @var   string
37
-	 * @since 1.0.0
38
-	 */
39
-	public $total_count;
40
-
41
-	/**
42
-	 * Current status subscriptions
43
-	 *
44
-	 * @var   string
45
-	 * @since 1.0.0
46
-	 */
47
-	public $current_total_count;
48
-
49
-	/**
50
-	 * Status counts
51
-	 *
52
-	 * @var   array
53
-	 * @since 1.0.19
54
-	 */
55
-	public $status_counts;
56
-
57
-	/**
58
-	 * Number of results to show per page
59
-	 *
60
-	 * @var   int
61
-	 * @since 1.0.0
62
-	 */
63
-	public $per_page = 10;
64
-
65
-	/**
66
-	 *  Constructor function.
67
-	 */
68
-	public function __construct() {
69
-
70
-		parent::__construct(
71
-			array(
72
-				'singular' => 'subscription',
73
-				'plural'   => 'subscriptions',
74
-			)
75
-		);
76
-
77
-		$this->process_bulk_action();
78
-
79
-		$this->prepare_query();
80
-
81
-		$this->base_url = remove_query_arg( 'status' );
82
-
83
-	}
84
-
85
-	/**
86
-	 *  Prepares the display query
87
-	 */
88
-	public function prepare_query() {
89
-
90
-		// Prepare query args.
91
-		$query = array(
92
-			'number'  => $this->per_page,
93
-			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
-		);
98
-
99
-		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
101
-		$this->total_count         = $this->query->get_total();
102
-		$this->current_total_count = $this->query->get_total();
103
-		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
-
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
-		}
110
-
111
-	}
112
-
113
-	/**
114
-	 * Gets the list of views available on this table.
115
-	 *
116
-	 * The format is an associative array:
117
-	 * - `'id' => 'link'`
118
-	 *
119
-	 * @since 1.0.0
120
-	 *
121
-	 * @return array
122
-	 */
123
-	public function get_views() {
124
-
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
-		$views    = array(
127
-
128
-			'all' => sprintf(
129
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
-				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
133
-				$this->total_count
134
-			)
135
-
136
-		);
137
-
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
-
140
-			$views[ $status ] = sprintf(
141
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
-				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
-				$count
146
-			);
147
-
148
-		}
149
-
150
-		return $views;
151
-
152
-	}
153
-
154
-	/**
155
-	 * Render most columns
156
-	 *
157
-	 * @access      private
158
-	 * @since       1.0.0
159
-	 * @return      string
160
-	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
-	}
164
-
165
-	/**
166
-	 * This is how checkbox column renders.
167
-	 *
168
-	 * @param WPInv_Subscription $item
169
-	 * @return string
170
-	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
-	}
174
-
175
-	/**
176
-	 * Status column
177
-	 *
178
-	 * @param WPInv_Subscription $item
179
-	 * @since       1.0.0
180
-	 * @return      string
181
-	 */
182
-	public function column_status( $item ) {
183
-		return $item->get_status_label_html();
184
-	}
185
-
186
-	/**
187
-	 * Subscription column
188
-	 *
189
-	 * @param WPInv_Subscription $item
190
-	 * @since       1.0.0
191
-	 * @return      string
192
-	 */
193
-	public function column_subscription( $item ) {
194
-
195
-		$username = __( '(Missing User)', 'invoicing' );
196
-
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
199
-
200
-			$username = sprintf(
201
-				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
-			);
205
-
206
-		}
207
-
208
-		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
-		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
-			$username
214
-		);
215
-
216
-		$row_actions = array();
217
-
218
-		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
-
222
-		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
224
-
225
-		if ( ! empty( $invoice ) ) {
226
-			$invoice_url            = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
-		}
229
-
230
-		$delete_url            = esc_url(
231
-			wp_nonce_url(
232
-				add_query_arg(
233
-					array(
234
-						'getpaid-admin-action' => 'subscription_manual_delete',
235
-						'id'                   => $item->get_id(),
236
-					)
237
-				),
238
-				'getpaid-nonce',
239
-				'getpaid-nonce'
240
-			)
241
-		);
242
-		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
243
-
244
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
245
-
246
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
247
-	}
248
-
249
-	/**
250
-	 * Renewal date column
251
-	 *
252
-	 * @param WPInv_Subscription $item
253
-	 * @since       1.0.0
254
-	 * @return      string
255
-	 */
256
-	public function column_renewal_date( $item ) {
257
-		return getpaid_format_date_value( $item->get_expiration() );
258
-	}
259
-
260
-	/**
261
-	 * Start date column
262
-	 *
263
-	 * @param WPInv_Subscription $item
264
-	 * @since       1.0.0
265
-	 * @return      string
266
-	 */
267
-	public function column_start_date( $item ) {
268
-		return getpaid_format_date_value( $item->get_date_created() );
269
-	}
270
-
271
-	/**
272
-	 * Amount column
273
-	 *
274
-	 * @param WPInv_Subscription $item
275
-	 * @since       1.0.19
276
-	 * @return      string
277
-	 */
278
-	public function column_amount( $item ) {
279
-		$amount = getpaid_get_formatted_subscription_amount( $item );
280
-		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
281
-	}
282
-
283
-	/**
284
-	 * Billing Times column
285
-	 *
286
-	 * @param WPInv_Subscription $item
287
-	 * @since       1.0.0
288
-	 * @return      string
289
-	 */
290
-	public function column_renewals( $item ) {
291
-		$max_bills = $item->get_bill_times();
292
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
293
-	}
294
-
295
-	/**
296
-	 * Product ID column
297
-	 *
298
-	 * @param WPInv_Subscription $item
299
-	 * @since       1.0.0
300
-	 * @return      string
301
-	 */
302
-	public function column_item( $item ) {
303
-		$subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
304
-
305
-		if ( empty( $subscription_group ) ) {
306
-			return $this->generate_item_markup( $item->get_product_id() );
307
-		}
308
-
309
-		$markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
310
-		return implode( ' | ', $markup );
311
-
312
-	}
313
-
314
-	/**
315
-	 * Generates the items markup.
316
-	 *
317
-	 * @param int $item_id
318
-	 * @since       1.0.0
319
-	 * @return      string
320
-	 */
321
-	public static function generate_item_markup( $item_id ) {
322
-		$item = get_post( $item_id );
323
-
324
-		if ( ! empty( $item ) ) {
325
-			$link = get_edit_post_link( $item );
326
-			$link = esc_url( $link );
327
-			$name = esc_html( get_the_title( $item ) );
328
-			return "<a href='$link'>$name</a>";
329
-		} else {
330
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
331
-		}
332
-
333
-	}
334
-
335
-	/**
336
-	 * Retrieve the current page number
337
-	 *
338
-	 * @return      int
339
-	 */
340
-	public function get_paged() {
341
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
342
-	}
343
-
344
-	/**
345
-	 * Setup the final data for the table
346
-	 *
347
-	 */
348
-	public function prepare_items() {
349
-
350
-		$columns  = $this->get_columns();
351
-		$hidden   = array();
352
-		$sortable = $this->get_sortable_columns();
353
-
354
-		$this->_column_headers = array( $columns, $hidden, $sortable );
355
-
356
-		$this->set_pagination_args(
357
-			array(
358
-			'total_items' => $this->current_total_count,
359
-			'per_page'    => $this->per_page,
360
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
361
-			)
362
-		);
363
-	}
364
-
365
-	/**
366
-	 * Table columns
367
-	 *
368
-	 * @return array
369
-	 */
370
-	public function get_columns(){
371
-		$columns = array(
372
-			'cb'                => '<input type="checkbox" />',
373
-			'subscription'      => __( 'Subscription', 'invoicing' ),
374
-			'start_date'        => __( 'Start Date', 'invoicing' ),
375
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
376
-			'renewals'          => __( 'Payments', 'invoicing' ),
377
-			'item'              => __( 'Items', 'invoicing' ),
378
-			'status'            => __( 'Status', 'invoicing' ),
379
-		);
380
-
381
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
382
-	}
383
-
384
-	/**
385
-	 * Sortable table columns.
386
-	 *
387
-	 * @return array
388
-	 */
389
-	public function get_sortable_columns() {
390
-		$sortable = array(
391
-			'subscription' => array( 'id', true ),
392
-			'start_date'   => array( 'created', true ),
393
-			'renewal_date' => array( 'expiration', true ),
394
-			'renewals'     => array( 'bill_times', true ),
395
-			'item'         => array( 'product_id', true ),
396
-			'status'       => array( 'status', true ),
397
-		);
398
-
399
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
400
-	}
401
-
402
-	/**
403
-	 * Whether the table has items to display or not
404
-	 *
405
-	 * @return bool
406
-	 */
407
-	public function has_items() {
408
-		return ! empty( $this->current_total_count );
409
-	}
410
-
411
-	/**
412
-	 * Processes bulk actions.
413
-	 *
414
-	 */
415
-	public function process_bulk_action() {
416
-
417
-	}
17
+    /**
18
+     * URL of this page
19
+     *
20
+     * @var   string
21
+     * @since 1.0.19
22
+     */
23
+    public $base_url;
24
+
25
+    /**
26
+     * Query
27
+     *
28
+     * @var   GetPaid_Subscriptions_Query
29
+     * @since 1.0.19
30
+     */
31
+    public $query;
32
+
33
+    /**
34
+     * Total subscriptions
35
+     *
36
+     * @var   string
37
+     * @since 1.0.0
38
+     */
39
+    public $total_count;
40
+
41
+    /**
42
+     * Current status subscriptions
43
+     *
44
+     * @var   string
45
+     * @since 1.0.0
46
+     */
47
+    public $current_total_count;
48
+
49
+    /**
50
+     * Status counts
51
+     *
52
+     * @var   array
53
+     * @since 1.0.19
54
+     */
55
+    public $status_counts;
56
+
57
+    /**
58
+     * Number of results to show per page
59
+     *
60
+     * @var   int
61
+     * @since 1.0.0
62
+     */
63
+    public $per_page = 10;
64
+
65
+    /**
66
+     *  Constructor function.
67
+     */
68
+    public function __construct() {
69
+
70
+        parent::__construct(
71
+            array(
72
+                'singular' => 'subscription',
73
+                'plural'   => 'subscriptions',
74
+            )
75
+        );
76
+
77
+        $this->process_bulk_action();
78
+
79
+        $this->prepare_query();
80
+
81
+        $this->base_url = remove_query_arg( 'status' );
82
+
83
+    }
84
+
85
+    /**
86
+     *  Prepares the display query
87
+     */
88
+    public function prepare_query() {
89
+
90
+        // Prepare query args.
91
+        $query = array(
92
+            'number'  => $this->per_page,
93
+            'paged'   => $this->get_paged(),
94
+            'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
+            'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
+            'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
+        );
98
+
99
+        // Prepare class properties.
100
+        $this->query               = new GetPaid_Subscriptions_Query( $query );
101
+        $this->total_count         = $this->query->get_total();
102
+        $this->current_total_count = $this->query->get_total();
103
+        $this->items               = $this->query->get_results();
104
+        $this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
+
106
+        if ( 'all' != $query['status'] ) {
107
+            unset( $query['status'] );
108
+            $this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
+        }
110
+
111
+    }
112
+
113
+    /**
114
+     * Gets the list of views available on this table.
115
+     *
116
+     * The format is an associative array:
117
+     * - `'id' => 'link'`
118
+     *
119
+     * @since 1.0.0
120
+     *
121
+     * @return array
122
+     */
123
+    public function get_views() {
124
+
125
+        $current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
+        $views    = array(
127
+
128
+            'all' => sprintf(
129
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
+                esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
+                $current === 'all' ? ' class="current"' : '',
132
+                __('All','invoicing' ),
133
+                $this->total_count
134
+            )
135
+
136
+        );
137
+
138
+        foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
+
140
+            $views[ $status ] = sprintf(
141
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
+                esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
+                $current === $status ? ' class="current"' : '',
144
+                sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
+                $count
146
+            );
147
+
148
+        }
149
+
150
+        return $views;
151
+
152
+    }
153
+
154
+    /**
155
+     * Render most columns
156
+     *
157
+     * @access      private
158
+     * @since       1.0.0
159
+     * @return      string
160
+     */
161
+    public function column_default( $item, $column_name ) {
162
+        return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
+    }
164
+
165
+    /**
166
+     * This is how checkbox column renders.
167
+     *
168
+     * @param WPInv_Subscription $item
169
+     * @return string
170
+     */
171
+    public function column_cb( $item ) {
172
+        return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
+    }
174
+
175
+    /**
176
+     * Status column
177
+     *
178
+     * @param WPInv_Subscription $item
179
+     * @since       1.0.0
180
+     * @return      string
181
+     */
182
+    public function column_status( $item ) {
183
+        return $item->get_status_label_html();
184
+    }
185
+
186
+    /**
187
+     * Subscription column
188
+     *
189
+     * @param WPInv_Subscription $item
190
+     * @since       1.0.0
191
+     * @return      string
192
+     */
193
+    public function column_subscription( $item ) {
194
+
195
+        $username = __( '(Missing User)', 'invoicing' );
196
+
197
+        $user = get_userdata( $item->get_customer_id() );
198
+        if ( $user ) {
199
+
200
+            $username = sprintf(
201
+                '<a href="user-edit.php?user_id=%s">%s</a>',
202
+                absint( $user->ID ),
203
+                ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
+            );
205
+
206
+        }
207
+
208
+        // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
+        $column_content = sprintf(
210
+            _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
+            '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
+            '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
+            $username
214
+        );
215
+
216
+        $row_actions = array();
217
+
218
+        // View subscription.
219
+        $view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
+        $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
+
222
+        // View invoice.
223
+        $invoice = get_post( $item->get_parent_invoice_id() );
224
+
225
+        if ( ! empty( $invoice ) ) {
226
+            $invoice_url            = get_edit_post_link( $invoice );
227
+            $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
+        }
229
+
230
+        $delete_url            = esc_url(
231
+            wp_nonce_url(
232
+                add_query_arg(
233
+                    array(
234
+                        'getpaid-admin-action' => 'subscription_manual_delete',
235
+                        'id'                   => $item->get_id(),
236
+                    )
237
+                ),
238
+                'getpaid-nonce',
239
+                'getpaid-nonce'
240
+            )
241
+        );
242
+        $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
243
+
244
+        $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
245
+
246
+        return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
247
+    }
248
+
249
+    /**
250
+     * Renewal date column
251
+     *
252
+     * @param WPInv_Subscription $item
253
+     * @since       1.0.0
254
+     * @return      string
255
+     */
256
+    public function column_renewal_date( $item ) {
257
+        return getpaid_format_date_value( $item->get_expiration() );
258
+    }
259
+
260
+    /**
261
+     * Start date column
262
+     *
263
+     * @param WPInv_Subscription $item
264
+     * @since       1.0.0
265
+     * @return      string
266
+     */
267
+    public function column_start_date( $item ) {
268
+        return getpaid_format_date_value( $item->get_date_created() );
269
+    }
270
+
271
+    /**
272
+     * Amount column
273
+     *
274
+     * @param WPInv_Subscription $item
275
+     * @since       1.0.19
276
+     * @return      string
277
+     */
278
+    public function column_amount( $item ) {
279
+        $amount = getpaid_get_formatted_subscription_amount( $item );
280
+        return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
281
+    }
282
+
283
+    /**
284
+     * Billing Times column
285
+     *
286
+     * @param WPInv_Subscription $item
287
+     * @since       1.0.0
288
+     * @return      string
289
+     */
290
+    public function column_renewals( $item ) {
291
+        $max_bills = $item->get_bill_times();
292
+        return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
293
+    }
294
+
295
+    /**
296
+     * Product ID column
297
+     *
298
+     * @param WPInv_Subscription $item
299
+     * @since       1.0.0
300
+     * @return      string
301
+     */
302
+    public function column_item( $item ) {
303
+        $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
304
+
305
+        if ( empty( $subscription_group ) ) {
306
+            return $this->generate_item_markup( $item->get_product_id() );
307
+        }
308
+
309
+        $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
310
+        return implode( ' | ', $markup );
311
+
312
+    }
313
+
314
+    /**
315
+     * Generates the items markup.
316
+     *
317
+     * @param int $item_id
318
+     * @since       1.0.0
319
+     * @return      string
320
+     */
321
+    public static function generate_item_markup( $item_id ) {
322
+        $item = get_post( $item_id );
323
+
324
+        if ( ! empty( $item ) ) {
325
+            $link = get_edit_post_link( $item );
326
+            $link = esc_url( $link );
327
+            $name = esc_html( get_the_title( $item ) );
328
+            return "<a href='$link'>$name</a>";
329
+        } else {
330
+            return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
331
+        }
332
+
333
+    }
334
+
335
+    /**
336
+     * Retrieve the current page number
337
+     *
338
+     * @return      int
339
+     */
340
+    public function get_paged() {
341
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
342
+    }
343
+
344
+    /**
345
+     * Setup the final data for the table
346
+     *
347
+     */
348
+    public function prepare_items() {
349
+
350
+        $columns  = $this->get_columns();
351
+        $hidden   = array();
352
+        $sortable = $this->get_sortable_columns();
353
+
354
+        $this->_column_headers = array( $columns, $hidden, $sortable );
355
+
356
+        $this->set_pagination_args(
357
+            array(
358
+            'total_items' => $this->current_total_count,
359
+            'per_page'    => $this->per_page,
360
+            'total_pages' => ceil( $this->current_total_count / $this->per_page )
361
+            )
362
+        );
363
+    }
364
+
365
+    /**
366
+     * Table columns
367
+     *
368
+     * @return array
369
+     */
370
+    public function get_columns(){
371
+        $columns = array(
372
+            'cb'                => '<input type="checkbox" />',
373
+            'subscription'      => __( 'Subscription', 'invoicing' ),
374
+            'start_date'        => __( 'Start Date', 'invoicing' ),
375
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
376
+            'renewals'          => __( 'Payments', 'invoicing' ),
377
+            'item'              => __( 'Items', 'invoicing' ),
378
+            'status'            => __( 'Status', 'invoicing' ),
379
+        );
380
+
381
+        return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
382
+    }
383
+
384
+    /**
385
+     * Sortable table columns.
386
+     *
387
+     * @return array
388
+     */
389
+    public function get_sortable_columns() {
390
+        $sortable = array(
391
+            'subscription' => array( 'id', true ),
392
+            'start_date'   => array( 'created', true ),
393
+            'renewal_date' => array( 'expiration', true ),
394
+            'renewals'     => array( 'bill_times', true ),
395
+            'item'         => array( 'product_id', true ),
396
+            'status'       => array( 'status', true ),
397
+        );
398
+
399
+        return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
400
+    }
401
+
402
+    /**
403
+     * Whether the table has items to display or not
404
+     *
405
+     * @return bool
406
+     */
407
+    public function has_items() {
408
+        return ! empty( $this->current_total_count );
409
+    }
410
+
411
+    /**
412
+     * Processes bulk actions.
413
+     *
414
+     */
415
+    public function process_bulk_action() {
416
+
417
+    }
418 418
 
419 419
 }
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +527 added lines, -527 removed lines patch added patch discarded remove patch
@@ -14,590 +14,590 @@
 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
-	 * @var array An array of payment gateways.
40
-	 */
41
-	public $gateways;
42
-
43
-	/**
44
-	 * Class constructor.
45
-	 */
46
-	public function __construct() {
47
-		$this->define_constants();
48
-		$this->includes();
49
-		$this->init_hooks();
50
-		$this->set_properties();
51
-	}
52
-
53
-	/**
54
-	 * Sets a custom data property.
55
-	 * 
56
-	 * @param string $prop The prop to set.
57
-	 * @param mixed $value The value to retrieve.
58
-	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
61
-	}
62
-
63
-	/**
64
-	 * Gets a custom data property.
65
-	 *
66
-	 * @param string $prop The prop to set.
67
-	 * @return mixed The value.
68
-	 */
69
-	public function get( $prop ) {
70
-
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
73
-		}
74
-
75
-		return null;
76
-	}
77
-
78
-	/**
79
-	 * Define class properties.
80
-	 */
81
-	public function set_properties() {
82
-
83
-		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
-
88
-		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
-
102
-	}
103
-
104
-	 /**
105
-	 * Define plugin constants.
106
-	 */
107
-	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
-		$this->version = WPINV_VERSION;
111
-	}
112
-
113
-	/**
114
-	 * Hook into actions and filters.
115
-	 *
116
-	 * @since 1.0.19
117
-	 */
118
-	protected function init_hooks() {
119
-		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
-
122
-		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @var array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     * 
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+
71
+        if ( isset( $this->data[ $prop ] ) ) {
72
+            return $this->data[ $prop ];
73
+        }
74
+
75
+        return null;
76
+    }
77
+
78
+    /**
79
+     * Define class properties.
80
+     */
81
+    public function set_properties() {
82
+
83
+        // Sessions.
84
+        $this->set( 'session', new WPInv_Session_Handler() );
85
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
+
88
+        // Init other objects.
89
+        $this->set( 'session', new WPInv_Session_Handler() );
90
+        $this->set( 'notes', new WPInv_Notes() );
91
+        $this->set( 'api', new WPInv_API() );
92
+        $this->set( 'post_types', new GetPaid_Post_Types() );
93
+        $this->set( 'template', new GetPaid_Template() );
94
+        $this->set( 'admin', new GetPaid_Admin() );
95
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
96
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
+
102
+    }
103
+
104
+        /**
105
+         * Define plugin constants.
106
+         */
107
+    public function define_constants() {
108
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
+        $this->version = WPINV_VERSION;
111
+    }
112
+
113
+    /**
114
+     * Hook into actions and filters.
115
+     *
116
+     * @since 1.0.19
117
+     */
118
+    protected function init_hooks() {
119
+        /* Internationalize the text strings used. */
120
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
+
122
+        // Init the plugin after WordPress inits.
123
+        add_action( 'init', array( $this, 'init' ), 1 );
124
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
126
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
130
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
+
134
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135 135
         add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
-
138
-		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
141
-
142
-	}
143
-
144
-	public function plugins_loaded() {
145
-		/* Internationalize the text strings used. */
146
-		$this->load_textdomain();
147
-
148
-		do_action( 'wpinv_loaded' );
149
-
150
-		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
152
-			wpinv_oxygen_fix_conflict();
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Load the translation of the plugin.
158
-	 *
159
-	 * @since 1.0
160
-	 */
161
-	public function load_textdomain( $locale = NULL ) {
162
-		if ( empty( $locale ) ) {
163
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
164
-		}
165
-
166
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
167
-
168
-		unload_textdomain( 'invoicing' );
169
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
170
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
171
-
172
-		/**
173
-		 * Define language constants.
174
-		 */
175
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
176
-	}
177
-
178
-	/**
179
-	 * Include required core files used in admin and on the frontend.
180
-	 */
181
-	public function includes() {
182
-
183
-		// Start with the settings.
184
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
185
-
186
-		// Packages/libraries.
187
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
188
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
189
-
190
-		// Load functions.
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
206
-
207
-		// Register autoloader.
208
-		try {
209
-			spl_autoload_register( array( $this, 'autoload' ), true );
210
-		} catch ( Exception $e ) {
211
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
-		}
213
-
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
235
-
236
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
-			GetPaid_Post_Types_Admin::init();
238
-
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
241
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
242
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
243
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
244
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
245
-			// load the user class only on the users.php page
246
-			global $pagenow;
247
-			if($pagenow=='users.php'){
248
-				new WPInv_Admin_Users();
249
-			}
250
-		}
251
-
252
-		// Register cli commands
253
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
255
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
-		}
257
-
258
-	}
259
-
260
-	/**
261
-	 * Class autoloader
262
-	 *
263
-	 * @param       string $class_name The name of the class to load.
264
-	 * @access      public
265
-	 * @since       1.0.19
266
-	 * @return      void
267
-	 */
268
-	public function autoload( $class_name ) {
269
-
270
-		// Normalize the class name...
271
-		$class_name  = strtolower( $class_name );
272
-
273
-		// ... and make sure it is our class.
274
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
-			return;
276
-		}
277
-
278
-		// Next, prepare the file name from the class.
279
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
-
281
-		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
-
284
-		// And an array of possible locations in order of importance.
285
-		$locations = array(
286
-			"$plugin_path/includes",
287
-			"$plugin_path/includes/data-stores",
288
-			"$plugin_path/includes/gateways",
289
-			"$plugin_path/includes/payments",
290
-			"$plugin_path/includes/geolocation",
291
-			"$plugin_path/includes/reports",
292
-			"$plugin_path/includes/api",
293
-			"$plugin_path/includes/admin",
294
-			"$plugin_path/includes/admin/meta-boxes",
295
-		);
296
-
297
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
-
299
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
-				include trailingslashit( $location ) . $file_name;
301
-				break;
302
-			}
303
-
304
-		}
305
-
306
-	}
307
-
308
-	/**
309
-	 * Inits hooks etc.
310
-	 */
311
-	public function init() {
312
-
313
-		// Fires before getpaid inits.
314
-		do_action( 'before_getpaid_init', $this );
315
-
316
-		// Maybe upgrade.
317
-		$this->maybe_upgrade_database();
318
-
319
-		// Load default gateways.
320
-		$gateways = apply_filters(
321
-			'getpaid_default_gateways',
322
-			array(
323
-				'manual'        => 'GetPaid_Manual_Gateway',
324
-				'paypal'        => 'GetPaid_Paypal_Gateway',
325
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
-			)
329
-		);
330
-
331
-		foreach ( $gateways as $id => $class ) {
332
-			$this->gateways[ $id ] = new $class();
333
-		}
334
-
335
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
336
-			GetPaid_Installer::rename_gateways_label();
337
-			update_option( 'wpinv_renamed_gateways', 'yes' );
338
-		}
339
-
340
-		// Fires after getpaid inits.
341
-		do_action( 'getpaid_init', $this );
342
-
343
-	}
344
-
345
-	/**
346
-	 * Checks if this is an IPN request and processes it.
347
-	 */
348
-	public function maybe_process_ipn() {
349
-
350
-		// Ensure that this is an IPN request.
351
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
352
-			return;
353
-		}
354
-
355
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
356
-
357
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
358
-		do_action( "wpinv_verify_{$gateway}_ipn" );
359
-		exit;
360
-
361
-	}
362
-
363
-	public function enqueue_scripts() {
364
-
365
-		// Fires before adding scripts.
366
-		do_action( 'getpaid_enqueue_scripts' );
367
-
368
-		$localize                         = array();
369
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
370
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
371
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
372
-		$localize['UseTaxes']             = wpinv_use_taxes();
373
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
374
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
375
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
376
-
377
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
378
-
379
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
380
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
381
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
382
-	}
383
-
384
-	public function wpinv_actions() {
385
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
386
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
387
-		}
388
-	}
389
-
390
-	/**
136
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
+
138
+        // Fires after registering actions.
139
+        do_action( 'wpinv_actions', $this );
140
+        do_action( 'getpaid_actions', $this );
141
+
142
+    }
143
+
144
+    public function plugins_loaded() {
145
+        /* Internationalize the text strings used. */
146
+        $this->load_textdomain();
147
+
148
+        do_action( 'wpinv_loaded' );
149
+
150
+        // Fix oxygen page builder conflict
151
+        if ( function_exists( 'ct_css_output' ) ) {
152
+            wpinv_oxygen_fix_conflict();
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Load the translation of the plugin.
158
+     *
159
+     * @since 1.0
160
+     */
161
+    public function load_textdomain( $locale = NULL ) {
162
+        if ( empty( $locale ) ) {
163
+            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
164
+        }
165
+
166
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
167
+
168
+        unload_textdomain( 'invoicing' );
169
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
170
+        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
171
+
172
+        /**
173
+         * Define language constants.
174
+         */
175
+        require_once( WPINV_PLUGIN_DIR . 'language.php' );
176
+    }
177
+
178
+    /**
179
+     * Include required core files used in admin and on the frontend.
180
+     */
181
+    public function includes() {
182
+
183
+        // Start with the settings.
184
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
185
+
186
+        // Packages/libraries.
187
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
188
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
189
+
190
+        // Load functions.
191
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
192
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
193
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
194
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
195
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
196
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
198
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
199
+        require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
205
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
206
+
207
+        // Register autoloader.
208
+        try {
209
+            spl_autoload_register( array( $this, 'autoload' ), true );
210
+        } catch ( Exception $e ) {
211
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
+        }
213
+
214
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
215
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
216
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
217
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
218
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
219
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
220
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
221
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
222
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
234
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
235
+
236
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
+            GetPaid_Post_Types_Admin::init();
238
+
239
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
240
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
241
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
242
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
243
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
244
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
245
+            // load the user class only on the users.php page
246
+            global $pagenow;
247
+            if($pagenow=='users.php'){
248
+                new WPInv_Admin_Users();
249
+            }
250
+        }
251
+
252
+        // Register cli commands
253
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
255
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
+        }
257
+
258
+    }
259
+
260
+    /**
261
+     * Class autoloader
262
+     *
263
+     * @param       string $class_name The name of the class to load.
264
+     * @access      public
265
+     * @since       1.0.19
266
+     * @return      void
267
+     */
268
+    public function autoload( $class_name ) {
269
+
270
+        // Normalize the class name...
271
+        $class_name  = strtolower( $class_name );
272
+
273
+        // ... and make sure it is our class.
274
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
+            return;
276
+        }
277
+
278
+        // Next, prepare the file name from the class.
279
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
+
281
+        // Base path of the classes.
282
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
+
284
+        // And an array of possible locations in order of importance.
285
+        $locations = array(
286
+            "$plugin_path/includes",
287
+            "$plugin_path/includes/data-stores",
288
+            "$plugin_path/includes/gateways",
289
+            "$plugin_path/includes/payments",
290
+            "$plugin_path/includes/geolocation",
291
+            "$plugin_path/includes/reports",
292
+            "$plugin_path/includes/api",
293
+            "$plugin_path/includes/admin",
294
+            "$plugin_path/includes/admin/meta-boxes",
295
+        );
296
+
297
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
+
299
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
+                include trailingslashit( $location ) . $file_name;
301
+                break;
302
+            }
303
+
304
+        }
305
+
306
+    }
307
+
308
+    /**
309
+     * Inits hooks etc.
310
+     */
311
+    public function init() {
312
+
313
+        // Fires before getpaid inits.
314
+        do_action( 'before_getpaid_init', $this );
315
+
316
+        // Maybe upgrade.
317
+        $this->maybe_upgrade_database();
318
+
319
+        // Load default gateways.
320
+        $gateways = apply_filters(
321
+            'getpaid_default_gateways',
322
+            array(
323
+                'manual'        => 'GetPaid_Manual_Gateway',
324
+                'paypal'        => 'GetPaid_Paypal_Gateway',
325
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
+            )
329
+        );
330
+
331
+        foreach ( $gateways as $id => $class ) {
332
+            $this->gateways[ $id ] = new $class();
333
+        }
334
+
335
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
336
+            GetPaid_Installer::rename_gateways_label();
337
+            update_option( 'wpinv_renamed_gateways', 'yes' );
338
+        }
339
+
340
+        // Fires after getpaid inits.
341
+        do_action( 'getpaid_init', $this );
342
+
343
+    }
344
+
345
+    /**
346
+     * Checks if this is an IPN request and processes it.
347
+     */
348
+    public function maybe_process_ipn() {
349
+
350
+        // Ensure that this is an IPN request.
351
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
352
+            return;
353
+        }
354
+
355
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
356
+
357
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
358
+        do_action( "wpinv_verify_{$gateway}_ipn" );
359
+        exit;
360
+
361
+    }
362
+
363
+    public function enqueue_scripts() {
364
+
365
+        // Fires before adding scripts.
366
+        do_action( 'getpaid_enqueue_scripts' );
367
+
368
+        $localize                         = array();
369
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
370
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
371
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
372
+        $localize['UseTaxes']             = wpinv_use_taxes();
373
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
374
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
375
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
376
+
377
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
378
+
379
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
380
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
381
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
382
+    }
383
+
384
+    public function wpinv_actions() {
385
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
386
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
387
+        }
388
+    }
389
+
390
+    /**
391 391
      * Fires an action after verifying that a user can fire them.
392
-	 *
393
-	 * Note: If the action is on an invoice, subscription etc, esure that the
394
-	 * current user owns the invoice/subscription.
392
+     *
393
+     * Note: If the action is on an invoice, subscription etc, esure that the
394
+     * current user owns the invoice/subscription.
395 395
      */
396 396
     public function maybe_do_authenticated_action() {
397 397
 
398
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
398
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
399
+
400
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
401
+            $data = wp_unslash( $_REQUEST );
402
+            if ( is_user_logged_in() ) {
403
+                do_action( "getpaid_authenticated_action_$key", $data );
404
+            }
405
+
406
+            do_action( "getpaid_unauthenticated_action_$key", $data );
407
+
408
+        }
399 409
 
400
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
401
-			$data = wp_unslash( $_REQUEST );
402
-			if ( is_user_logged_in() ) {
403
-				do_action( "getpaid_authenticated_action_$key", $data );
404
-			}
410
+    }
405 411
 
406
-			do_action( "getpaid_unauthenticated_action_$key", $data );
412
+    public function pre_get_posts( $wp_query ) {
407 413
 
408
-		}
414
+        if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
415
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
416
+        }
409 417
 
418
+        return $wp_query;
410 419
     }
411 420
 
412
-	public function pre_get_posts( $wp_query ) {
413
-
414
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
415
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
416
-		}
417
-
418
-		return $wp_query;
419
-	}
420
-
421
-	/**
422
-	 * Register widgets
423
-	 *
424
-	 */
425
-	public function register_widgets() {
426
-
427
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
428
-		// So we disable our widgets when editing a page with UX Builder.
429
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
430
-			return;
431
-		}
432
-
433
-		$widgets = apply_filters(
434
-			'getpaid_widget_classes',
435
-			array(
436
-				'WPInv_Checkout_Widget',
437
-				'WPInv_History_Widget',
438
-				'WPInv_Receipt_Widget',
439
-				'WPInv_Subscriptions_Widget',
440
-				'WPInv_Buy_Item_Widget',
441
-				'WPInv_Messages_Widget',
442
-				'WPInv_GetPaid_Widget'
443
-			)
444
-		);
445
-
446
-		foreach ( $widgets as $widget ) {
447
-			register_widget( $widget );
448
-		}
421
+    /**
422
+     * Register widgets
423
+     *
424
+     */
425
+    public function register_widgets() {
426
+
427
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
428
+        // So we disable our widgets when editing a page with UX Builder.
429
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
430
+            return;
431
+        }
432
+
433
+        $widgets = apply_filters(
434
+            'getpaid_widget_classes',
435
+            array(
436
+                'WPInv_Checkout_Widget',
437
+                'WPInv_History_Widget',
438
+                'WPInv_Receipt_Widget',
439
+                'WPInv_Subscriptions_Widget',
440
+                'WPInv_Buy_Item_Widget',
441
+                'WPInv_Messages_Widget',
442
+                'WPInv_GetPaid_Widget'
443
+            )
444
+        );
445
+
446
+        foreach ( $widgets as $widget ) {
447
+            register_widget( $widget );
448
+        }
449 449
 		
450
-	}
450
+    }
451 451
 
452
-	/**
453
-	 * Upgrades the database.
454
-	 *
455
-	 * @since 2.0.2
456
-	 */
457
-	public function maybe_upgrade_database() {
452
+    /**
453
+     * Upgrades the database.
454
+     *
455
+     * @since 2.0.2
456
+     */
457
+    public function maybe_upgrade_database() {
458 458
 
459
-		$wpi_version = get_option( 'wpinv_version', 0 );
459
+        $wpi_version = get_option( 'wpinv_version', 0 );
460 460
 
461
-		if ( $wpi_version == WPINV_VERSION ) {
462
-			return;
463
-		}
461
+        if ( $wpi_version == WPINV_VERSION ) {
462
+            return;
463
+        }
464 464
 
465
-		$installer = new GetPaid_Installer();
465
+        $installer = new GetPaid_Installer();
466 466
 
467
-		if ( empty( $wpi_version ) ) {
468
-			return $installer->upgrade_db( 0 );
469
-		}
467
+        if ( empty( $wpi_version ) ) {
468
+            return $installer->upgrade_db( 0 );
469
+        }
470 470
 
471
-		$upgrades  = array(
472
-			'0.0.5' => '004',
473
-			'1.0.3' => '102',
474
-			'2.0.0' => '118',
475
-			'2.0.8' => '207',
476
-		);
471
+        $upgrades  = array(
472
+            '0.0.5' => '004',
473
+            '1.0.3' => '102',
474
+            '2.0.0' => '118',
475
+            '2.0.8' => '207',
476
+        );
477 477
 
478
-		foreach ( $upgrades as $key => $method ) {
478
+        foreach ( $upgrades as $key => $method ) {
479 479
 
480
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
481
-				return $installer->upgrade_db( $method );
482
-			}
480
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
481
+                return $installer->upgrade_db( $method );
482
+            }
483 483
 
484
-		}
484
+        }
485 485
 
486
-	}
486
+    }
487 487
 
488
-	/**
489
-	 * Flushes the permalinks if needed.
490
-	 *
491
-	 * @since 2.0.8
492
-	 */
493
-	public function maybe_flush_permalinks() {
488
+    /**
489
+     * Flushes the permalinks if needed.
490
+     *
491
+     * @since 2.0.8
492
+     */
493
+    public function maybe_flush_permalinks() {
494 494
 
495
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
495
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
496 496
 
497
-		if ( ! empty( $flush ) ) {
498
-			flush_rewrite_rules();
499
-			delete_option( 'wpinv_flush_permalinks' );
500
-		}
497
+        if ( ! empty( $flush ) ) {
498
+            flush_rewrite_rules();
499
+            delete_option( 'wpinv_flush_permalinks' );
500
+        }
501 501
 
502
-	}
502
+    }
503 503
 
504
-	/**
505
-	 * Remove our pages from yoast sitemaps.
506
-	 *
507
-	 * @since 1.0.19
508
-	 * @param int[] $excluded_posts_ids
509
-	 */
510
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
504
+    /**
505
+     * Remove our pages from yoast sitemaps.
506
+     *
507
+     * @since 1.0.19
508
+     * @param int[] $excluded_posts_ids
509
+     */
510
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
511 511
 
512
-		// Ensure that we have an array.
513
-		if ( ! is_array( $excluded_posts_ids ) ) {
514
-			$excluded_posts_ids = array();
515
-		}
512
+        // Ensure that we have an array.
513
+        if ( ! is_array( $excluded_posts_ids ) ) {
514
+            $excluded_posts_ids = array();
515
+        }
516 516
 
517
-		// Prepare our pages.
518
-		$our_pages = array();
517
+        // Prepare our pages.
518
+        $our_pages = array();
519 519
 
520
-		// Checkout page.
521
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
520
+        // Checkout page.
521
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
522 522
 
523
-		// Success page.
524
-		$our_pages[] = wpinv_get_option( 'success_page', false );
523
+        // Success page.
524
+        $our_pages[] = wpinv_get_option( 'success_page', false );
525 525
 
526
-		// Failure page.
527
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
526
+        // Failure page.
527
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
528 528
 
529
-		// History page.
530
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
529
+        // History page.
530
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
531 531
 
532
-		// Subscriptions page.
533
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
532
+        // Subscriptions page.
533
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
534 534
 
535
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
535
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
536 536
 
537
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
538
-		return array_unique( $excluded_posts_ids );
537
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
538
+        return array_unique( $excluded_posts_ids );
539 539
 
540
-	}
540
+    }
541 541
 
542
-	/**
543
-	 * Displays additional footer code.
544
-	 * 
545
-	 * @since 2.0.0
546
-	 */
547
-	public function wp_footer() {
548
-		wpinv_get_template( 'frontend-footer.php' );
549
-	}
542
+    /**
543
+     * Displays additional footer code.
544
+     * 
545
+     * @since 2.0.0
546
+     */
547
+    public function wp_footer() {
548
+        wpinv_get_template( 'frontend-footer.php' );
549
+    }
550 550
 
551
-	/**
552
-	 * Displays additional header code.
553
-	 * 
554
-	 * @since 2.0.0
555
-	 */
556
-	public function wp_head() {
557
-		wpinv_get_template( 'frontend-head.php' );
558
-	}
551
+    /**
552
+     * Displays additional header code.
553
+     * 
554
+     * @since 2.0.0
555
+     */
556
+    public function wp_head() {
557
+        wpinv_get_template( 'frontend-head.php' );
558
+    }
559 559
 
560
-	/**
561
-	 * Custom query vars.
562
-	 *
563
-	 */
564
-	public function custom_query_vars( $vars ) {
560
+    /**
561
+     * Custom query vars.
562
+     *
563
+     */
564
+    public function custom_query_vars( $vars ) {
565 565
         $vars[] = 'getpaid-ipn';
566 566
         return $vars;
567
-	}
567
+    }
568 568
 
569
-	/**
570
-	 * Add rewrite tags and rules.
571
-	 *
572
-	 */
573
-	public function add_rewrite_rule() {
569
+    /**
570
+     * Add rewrite tags and rules.
571
+     *
572
+     */
573
+    public function add_rewrite_rule() {
574 574
         $tag = 'getpaid-ipn';
575 575
         add_rewrite_tag( "%$tag%", '([^&]+)' );
576 576
         add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' );
577
-	}
577
+    }
578 578
 
579
-	/**
580
-	 * Processes non-query string ipns.
581
-	 *
582
-	 */
583
-	public function maybe_process_new_ipn( $query ) {
579
+    /**
580
+     * Processes non-query string ipns.
581
+     *
582
+     */
583
+    public function maybe_process_new_ipn( $query ) {
584 584
 
585 585
         if ( is_admin() || ! $query->is_main_query() ) {
586 586
             return;
587 587
         }
588 588
 
589
-		$gateway = get_query_var( 'getpaid-ipn' );
589
+        $gateway = get_query_var( 'getpaid-ipn' );
590 590
 
591 591
         if ( ! empty( $gateway ) ){
592 592
 
593
-			$gateway = sanitize_text_field( $gateway );
594
-			nocache_headers();
595
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
596
-			do_action( "wpinv_verify_{$gateway}_ipn" );
597
-			exit;
593
+            $gateway = sanitize_text_field( $gateway );
594
+            nocache_headers();
595
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
596
+            do_action( "wpinv_verify_{$gateway}_ipn" );
597
+            exit;
598 598
 
599 599
         }
600 600
 
601
-	}
601
+    }
602 602
 
603 603
 }
Please login to merge, or discard this patch.