Passed
Push — master ( 5faead...57234e )
by Brian
04:33
created
includes/reports/class-getpaid-reports-report.php 1 patch
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -12,88 +12,88 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Report {
14 14
 
15
-	/**
16
-	 * @var array
17
-	 */
18
-	public $views;
15
+    /**
16
+     * @var array
17
+     */
18
+    public $views;
19 19
 
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 */
24
-	public function __construct() {
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     */
24
+    public function __construct() {
25 25
 
26
-		$this->views        = array(
26
+        $this->views        = array(
27 27
 
28 28
             'items'     => array(
29
-				'label' => __( 'Items', 'invoicing' ),
30
-				'class' => 'GetPaid_Reports_Report_Items',
31
-			),
29
+                'label' => __( 'Items', 'invoicing' ),
30
+                'class' => 'GetPaid_Reports_Report_Items',
31
+            ),
32 32
 
33
-			'gateways'  => array(
34
-				'label' => __( 'Payment Methods', 'invoicing' ),
35
-				'class' => 'GetPaid_Reports_Report_Gateways',
36
-			),
33
+            'gateways'  => array(
34
+                'label' => __( 'Payment Methods', 'invoicing' ),
35
+                'class' => 'GetPaid_Reports_Report_Gateways',
36
+            ),
37 37
 
38
-			'discounts'  => array(
39
-				'label' => __( 'Discount Codes', 'invoicing' ),
40
-				'class' => 'GetPaid_Reports_Report_Discounts',
41
-			),
38
+            'discounts'  => array(
39
+                'label' => __( 'Discount Codes', 'invoicing' ),
40
+                'class' => 'GetPaid_Reports_Report_Discounts',
41
+            ),
42 42
 
43 43
         );
44 44
 
45
-		$this->views        = apply_filters( 'wpinv_report_views', $this->views );
46
-
47
-	}
48
-
49
-	/**
50
-	 * Retrieves the current range.
51
-	 *
52
-	 */
53
-	public function get_range() {
54
-		$valid_ranges = $this->get_periods();
55
-
56
-		if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) {
57
-			return sanitize_key( $_GET['date_range'] );
58
-		}
59
-
60
-		return '7_days';
61
-	}
62
-
63
-	/**
64
-	 * Returns an array of date ranges.
65
-	 *
66
-	 * @return array
67
-	 */
68
-	public function get_periods() {
69
-
70
-		$periods = array(
71
-			'today'        => __( 'Today', 'invoicing' ),
72
-			'yesterday'    => __( 'Yesterday', 'invoicing' ),
73
-			'week'         => __( 'This week', 'invoicing' ),
74
-			'last_week'    => __( 'Last week', 'invoicing' ),
75
-			'7_days'       => __( 'Last 7 days', 'invoicing' ),
76
-			'month'        => __( 'This month', 'invoicing' ),
77
-			'last_month'   => __( 'Last month', 'invoicing' ),
78
-			'30_days'      => __( 'Last 30 days', 'invoicing' ),
79
-			'quarter'      => __( 'This Quarter', 'invoicing' ),
80
-			'last_quarter' => __( 'Last Quarter', 'invoicing' ),
81
-			'year'         => __( 'This year', 'invoicing' ),
82
-			'last_year'    => __( 'Last Year', 'invoicing' ),
83
-			'custom'       => __( 'Custom Date Range', 'invoicing' ),
84
-		);
85
-
86
-		return apply_filters( 'getpaid_earning_periods', $periods );
87
-	}
88
-
89
-	/**
90
-	 * Displays the range selector.
91
-	 *
92
-	 */
93
-	public function display_range_selector() {
94
-
95
-		$range = $this->get_range();
96
-		?>
45
+        $this->views        = apply_filters( 'wpinv_report_views', $this->views );
46
+
47
+    }
48
+
49
+    /**
50
+     * Retrieves the current range.
51
+     *
52
+     */
53
+    public function get_range() {
54
+        $valid_ranges = $this->get_periods();
55
+
56
+        if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) {
57
+            return sanitize_key( $_GET['date_range'] );
58
+        }
59
+
60
+        return '7_days';
61
+    }
62
+
63
+    /**
64
+     * Returns an array of date ranges.
65
+     *
66
+     * @return array
67
+     */
68
+    public function get_periods() {
69
+
70
+        $periods = array(
71
+            'today'        => __( 'Today', 'invoicing' ),
72
+            'yesterday'    => __( 'Yesterday', 'invoicing' ),
73
+            'week'         => __( 'This week', 'invoicing' ),
74
+            'last_week'    => __( 'Last week', 'invoicing' ),
75
+            '7_days'       => __( 'Last 7 days', 'invoicing' ),
76
+            'month'        => __( 'This month', 'invoicing' ),
77
+            'last_month'   => __( 'Last month', 'invoicing' ),
78
+            '30_days'      => __( 'Last 30 days', 'invoicing' ),
79
+            'quarter'      => __( 'This Quarter', 'invoicing' ),
80
+            'last_quarter' => __( 'Last Quarter', 'invoicing' ),
81
+            'year'         => __( 'This year', 'invoicing' ),
82
+            'last_year'    => __( 'Last Year', 'invoicing' ),
83
+            'custom'       => __( 'Custom Date Range', 'invoicing' ),
84
+        );
85
+
86
+        return apply_filters( 'getpaid_earning_periods', $periods );
87
+    }
88
+
89
+    /**
90
+     * Displays the range selector.
91
+     *
92
+     */
93
+    public function display_range_selector() {
94
+
95
+        $range = $this->get_range();
96
+        ?>
97 97
 
98 98
 			<form method="get" class="getpaid-filter-earnings float-right">
99 99
 				<?php getpaid_hidden_field( 'page', 'wpinv-reports' );  ?>
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
 			</form>
116 116
 
117 117
 		<?php
118
-	}
118
+    }
119 119
 
120
-	/**
121
-	 * Displays the reports tab.
122
-	 *
123
-	 */
124
-	public function display() {
125
-		?>
120
+    /**
121
+     * Displays the reports tab.
122
+     *
123
+     */
124
+    public function display() {
125
+        ?>
126 126
 
127 127
 		<div class="mt-4" style="max-width: 1200px;">
128 128
 
@@ -202,24 +202,24 @@  discard block
 block discarded – undo
202 202
 
203 203
 		<?php
204 204
 
205
-	}
206
-
207
-	/**
208
-	 * Displays the left side.
209
-	 *
210
-	 */
211
-	public function display_left() {
212
-		$graphs = array(
213
-			'sales'    => __( 'Earnings', 'invoicing' ),
214
-			'refunds'  => __( 'Refunds', 'invoicing' ),
215
-			'tax'      => __( 'Taxes', 'invoicing' ),
216
-			'fees'     => __( 'Fees', 'invoicing' ),
217
-			'discount' => __( 'Discounts', 'invoicing' ),
218
-			'invoices' => __( 'Invoices', 'invoicing' ),
219
-			'items'    => __( 'Purchased Items', 'invoicing' ),
220
-		);
221
-
222
-		?>
205
+    }
206
+
207
+    /**
208
+     * Displays the left side.
209
+     *
210
+     */
211
+    public function display_left() {
212
+        $graphs = array(
213
+            'sales'    => __( 'Earnings', 'invoicing' ),
214
+            'refunds'  => __( 'Refunds', 'invoicing' ),
215
+            'tax'      => __( 'Taxes', 'invoicing' ),
216
+            'fees'     => __( 'Fees', 'invoicing' ),
217
+            'discount' => __( 'Discounts', 'invoicing' ),
218
+            'invoices' => __( 'Invoices', 'invoicing' ),
219
+            'items'    => __( 'Purchased Items', 'invoicing' ),
220
+        );
221
+
222
+        ?>
223 223
 
224 224
 			<?php foreach ( $graphs as $key => $graph ) : ?>
225 225
 				<div class="row mb-4">
@@ -238,35 +238,35 @@  discard block
 block discarded – undo
238 238
 
239 239
 		<?php
240 240
 
241
-	}
242
-
243
-	/**
244
-	 * Retrieves the download url.
245
-	 *
246
-	 */
247
-	public function get_download_url( $graph, $file_type ) {
248
-
249
-		return wp_nonce_url(
250
-			add_query_arg(
251
-				array(
252
-					'getpaid-admin-action' => 'download_graph',
253
-					'file_type'            => urlencode( $file_type ),
254
-					'graph'                => urlencode( $graph ),
255
-				)
256
-			),
257
-			'getpaid-nonce',
258
-			'getpaid-nonce'
259
-		);
241
+    }
242
+
243
+    /**
244
+     * Retrieves the download url.
245
+     *
246
+     */
247
+    public function get_download_url( $graph, $file_type ) {
248
+
249
+        return wp_nonce_url(
250
+            add_query_arg(
251
+                array(
252
+                    'getpaid-admin-action' => 'download_graph',
253
+                    'file_type'            => urlencode( $file_type ),
254
+                    'graph'                => urlencode( $graph ),
255
+                )
256
+            ),
257
+            'getpaid-nonce',
258
+            'getpaid-nonce'
259
+        );
260 260
 
261
-	}
261
+    }
262 262
 
263
-	/**
264
-	 * Displays the right side.
265
-	 *
266
-	 */
267
-	public function display_right() {
263
+    /**
264
+     * Displays the right side.
265
+     *
266
+     */
267
+    public function display_right() {
268 268
 
269
-		?>
269
+        ?>
270 270
 
271 271
 			<?php foreach ( $this->views as $key => $view ) : ?>
272 272
 				<div class="row mb-4">
@@ -295,10 +295,10 @@  discard block
 block discarded – undo
295 295
 							</div>
296 296
 							<div class="card-body">
297 297
 								<?php
298
-									$class = $view['class'];
299
-									$class = new $class();
300
-									$class->display_stats();
301
-								?>
298
+                                    $class = $view['class'];
299
+                                    $class = new $class();
300
+                                    $class->display_stats();
301
+                                ?>
302 302
 							</div>
303 303
 						</div>
304 304
 					</div>
@@ -307,67 +307,67 @@  discard block
 block discarded – undo
307 307
 
308 308
 		<?php
309 309
 
310
-	}
311
-
312
-	/**
313
-	 * Returns a list of report cards.
314
-	 *
315
-	 */
316
-	public function get_cards() {
317
-
318
-		$cards = array(
319
-			'total_sales' => array(
320
-				'description' => __( 'Gross sales in the period.', 'invoicing' ),
321
-				'label'       => __( 'Gross Revenue', 'invoicing' ),
322
-			),
323
-			'net_sales' => array(
324
-				'description' => __( 'Net sales in the period.', 'invoicing' ),
325
-				'label'       => __( 'Net Revenue', 'invoicing' ),
326
-			),
327
-			'average_sales' => array(
328
-				'description' => __( 'Average net daily/monthly sales.', 'invoicing' ),
329
-				'label'       => __( 'Avg. Net Sales', 'invoicing' ),
330
-			),
331
-			'average_total_sales' => array(
332
-				'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ),
333
-				'label'       => __( 'Avg. Gross Sales', 'invoicing' ),
334
-			),
335
-			'total_invoices'  => array(
336
-				'description' => __( 'Number of paid invoices.', 'invoicing' ),
337
-				'label'       => __( 'Paid Invoices', 'invoicing' ),
338
-			),
339
-			'total_items' => array(
340
-				'description' => __( 'Number of items purchased.', 'invoicing' ),
341
-				'label'       => __( 'Purchased Items', 'invoicing' ),
342
-			),
343
-			'refunded_items' => array(
344
-				'description' => __( 'Number of items refunded.', 'invoicing' ),
345
-				'label'       => __( 'Refunded Items', 'invoicing' ),
346
-			),
347
-			'total_tax' => array(
348
-				'description' => __( 'Total charged for taxes.', 'invoicing' ),
349
-				'label'       => __( 'Tax', 'invoicing' ),
350
-			),
351
-			'total_refunded_tax' => array(
352
-				'description' => __( 'Total refunded for taxes.', 'invoicing' ),
353
-				'label'       => __( 'Refunded Tax', 'invoicing' ),
354
-			),
355
-			'total_fees' => array(
356
-				'description' => __( 'Total fees charged.', 'invoicing' ),
357
-				'label'       => __( 'Fees', 'invoicing' ),
358
-			),
359
-			'total_refunds' => array(
360
-				'description' => __( 'Total of refunded invoices.', 'invoicing' ),
361
-				'label'       => __( 'Refunded', 'invoicing' ),
362
-			),
363
-			'total_discount'  => array(
364
-				'description' => __( 'Total of discounts used.', 'invoicing' ),
365
-				'label'       => __( 'Discounted', 'invoicing' ),
366
-			),
367
-		);
368
-
369
-		return apply_filters( 'wpinv_report_cards', $cards );
370
-	}
310
+    }
311
+
312
+    /**
313
+     * Returns a list of report cards.
314
+     *
315
+     */
316
+    public function get_cards() {
317
+
318
+        $cards = array(
319
+            'total_sales' => array(
320
+                'description' => __( 'Gross sales in the period.', 'invoicing' ),
321
+                'label'       => __( 'Gross Revenue', 'invoicing' ),
322
+            ),
323
+            'net_sales' => array(
324
+                'description' => __( 'Net sales in the period.', 'invoicing' ),
325
+                'label'       => __( 'Net Revenue', 'invoicing' ),
326
+            ),
327
+            'average_sales' => array(
328
+                'description' => __( 'Average net daily/monthly sales.', 'invoicing' ),
329
+                'label'       => __( 'Avg. Net Sales', 'invoicing' ),
330
+            ),
331
+            'average_total_sales' => array(
332
+                'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ),
333
+                'label'       => __( 'Avg. Gross Sales', 'invoicing' ),
334
+            ),
335
+            'total_invoices'  => array(
336
+                'description' => __( 'Number of paid invoices.', 'invoicing' ),
337
+                'label'       => __( 'Paid Invoices', 'invoicing' ),
338
+            ),
339
+            'total_items' => array(
340
+                'description' => __( 'Number of items purchased.', 'invoicing' ),
341
+                'label'       => __( 'Purchased Items', 'invoicing' ),
342
+            ),
343
+            'refunded_items' => array(
344
+                'description' => __( 'Number of items refunded.', 'invoicing' ),
345
+                'label'       => __( 'Refunded Items', 'invoicing' ),
346
+            ),
347
+            'total_tax' => array(
348
+                'description' => __( 'Total charged for taxes.', 'invoicing' ),
349
+                'label'       => __( 'Tax', 'invoicing' ),
350
+            ),
351
+            'total_refunded_tax' => array(
352
+                'description' => __( 'Total refunded for taxes.', 'invoicing' ),
353
+                'label'       => __( 'Refunded Tax', 'invoicing' ),
354
+            ),
355
+            'total_fees' => array(
356
+                'description' => __( 'Total fees charged.', 'invoicing' ),
357
+                'label'       => __( 'Fees', 'invoicing' ),
358
+            ),
359
+            'total_refunds' => array(
360
+                'description' => __( 'Total of refunded invoices.', 'invoicing' ),
361
+                'label'       => __( 'Refunded', 'invoicing' ),
362
+            ),
363
+            'total_discount'  => array(
364
+                'description' => __( 'Total of discounts used.', 'invoicing' ),
365
+                'label'       => __( 'Discounted', 'invoicing' ),
366
+            ),
367
+        );
368
+
369
+        return apply_filters( 'wpinv_report_cards', $cards );
370
+    }
371 371
 
372 372
 	
373 373
 
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 1 patch
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wpinv_subscriptions_page() {
16 16
 
17
-	?>
17
+    ?>
18 18
 
19 19
 	<div class="wrap">
20 20
 		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
@@ -22,27 +22,27 @@  discard block
 block discarded – undo
22 22
 
23 23
 			<?php
24 24
 
25
-				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
25
+                // Verify user permissions.
26
+                if ( ! wpinv_current_user_can_manage_invoicing() ) {
27 27
 
28
-					echo aui()->alert(
29
-						array(
30
-							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
-						)
33
-					);
28
+                    echo aui()->alert(
29
+                        array(
30
+                            'type'    => 'danger',
31
+                            'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
+                        )
33
+                    );
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+                } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
36 36
 
37
-					// Display a single subscription.
38
-					wpinv_recurring_subscription_details();
39
-				} else {
37
+                    // Display a single subscription.
38
+                    wpinv_recurring_subscription_details();
39
+                } else {
40 40
 
41
-					// Display a list of available subscriptions.
42
-					getpaid_print_subscriptions_list();
43
-				}
41
+                    // Display a list of available subscriptions.
42
+                    getpaid_print_subscriptions_list();
43
+                }
44 44
 
45
-			?>
45
+            ?>
46 46
 
47 47
 		</div>
48 48
 	</div>
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function getpaid_print_subscriptions_list() {
61 61
 
62
-	$subscribers_table = new WPInv_Subscriptions_List_Table();
63
-	$subscribers_table->prepare_items();
62
+    $subscribers_table = new WPInv_Subscriptions_List_Table();
63
+    $subscribers_table->prepare_items();
64 64
 
65
-	?>
65
+    ?>
66 66
 	<form id="subscribers-filter" class="bsui" method="get">
67 67
 		<input type="hidden" name="page" value="wpinv-subscriptions" />
68 68
 		<?php $subscribers_table->views(); ?>
@@ -80,27 +80,27 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function wpinv_recurring_subscription_details() {
82 82
 
83
-	// Fetch the subscription.
84
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
85
-	if ( ! $sub->get_id() ) {
83
+    // Fetch the subscription.
84
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
85
+    if ( ! $sub->get_id() ) {
86 86
 
87
-		echo aui()->alert(
88
-			array(
89
-				'type'    => 'danger',
90
-				'content' => __( 'Subscription not found.', 'invoicing' ),
91
-			)
92
-		);
87
+        echo aui()->alert(
88
+            array(
89
+                'type'    => 'danger',
90
+                'content' => __( 'Subscription not found.', 'invoicing' ),
91
+            )
92
+        );
93 93
 
94
-		return;
95
-	}
94
+        return;
95
+    }
96 96
 
97
-	// Use metaboxes to display the subscription details.
98
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
97
+    // Use metaboxes to display the subscription details.
98
+    add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' );
99
+    add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
102 102
 
103
-	?>
103
+    ?>
104 104
 
105 105
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
106 106
 
@@ -140,41 +140,41 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function getpaid_admin_subscription_details_metabox( $sub ) {
142 142
 
143
-	// Prepare subscription detail columns.
144
-	$fields = apply_filters(
145
-		'getpaid_subscription_admin_page_fields',
146
-		array(
147
-			'subscription'   => __( 'Subscription', 'invoicing' ),
148
-			'customer'       => __( 'Customer', 'invoicing' ),
149
-			'amount'         => __( 'Amount', 'invoicing' ),
150
-			'start_date'     => __( 'Start Date', 'invoicing' ),
151
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
-			'renewals'       => __( 'Payments', 'invoicing' ),
153
-			'item'           => __( 'Item', 'invoicing' ),
154
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
155
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
-			'status'         => __( 'Status', 'invoicing' ),
157
-		)
158
-	);
159
-
160
-	if ( ! $sub->is_active() ) {
161
-
162
-		if ( isset( $fields['renews_on'] ) ) {
163
-			unset( $fields['renews_on'] );
164
-		}
165
-
166
-		if ( isset( $fields['gateway'] ) ) {
167
-			unset( $fields['gateway'] );
168
-		}
143
+    // Prepare subscription detail columns.
144
+    $fields = apply_filters(
145
+        'getpaid_subscription_admin_page_fields',
146
+        array(
147
+            'subscription'   => __( 'Subscription', 'invoicing' ),
148
+            'customer'       => __( 'Customer', 'invoicing' ),
149
+            'amount'         => __( 'Amount', 'invoicing' ),
150
+            'start_date'     => __( 'Start Date', 'invoicing' ),
151
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
+            'renewals'       => __( 'Payments', 'invoicing' ),
153
+            'item'           => __( 'Item', 'invoicing' ),
154
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
155
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
+            'status'         => __( 'Status', 'invoicing' ),
157
+        )
158
+    );
159
+
160
+    if ( ! $sub->is_active() ) {
161
+
162
+        if ( isset( $fields['renews_on'] ) ) {
163
+            unset( $fields['renews_on'] );
164
+        }
165
+
166
+        if ( isset( $fields['gateway'] ) ) {
167
+            unset( $fields['gateway'] );
168
+        }
169 169
 		
170
-	}
170
+    }
171 171
 
172
-	$profile_id = $sub->get_profile_id();
173
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
-		unset( $fields['profile_id'] );
175
-	}
172
+    $profile_id = $sub->get_profile_id();
173
+    if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
+        unset( $fields['profile_id'] );
175
+    }
176 176
 
177
-	?>
177
+    ?>
178 178
 
179 179
 		<table class="table table-borderless" style="font-size: 14px;">
180 180
 			<tbody>
@@ -208,20 +208,20 @@  discard block
 block discarded – undo
208 208
  */
209 209
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
210 210
 
211
-	$username = __( '(Missing User)', 'invoicing' );
211
+    $username = __( '(Missing User)', 'invoicing' );
212 212
 
213
-	$user = get_userdata( $subscription->get_customer_id() );
214
-	if ( $user ) {
213
+    $user = get_userdata( $subscription->get_customer_id() );
214
+    if ( $user ) {
215 215
 
216
-		$username = sprintf(
217
-			'<a href="user-edit.php?user_id=%s">%s</a>',
218
-			absint( $user->ID ),
219
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
220
-		);
216
+        $username = sprintf(
217
+            '<a href="user-edit.php?user_id=%s">%s</a>',
218
+            absint( $user->ID ),
219
+            ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
220
+        );
221 221
 
222
-	}
222
+    }
223 223
 
224
-	echo  $username;
224
+    echo  $username;
225 225
 }
226 226
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
227 227
 
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
  * @param WPInv_Subscription $subscription
232 232
  */
233 233
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
234
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
235
-	echo "<span>$amount</span>";
234
+    $amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
235
+    echo "<span>$amount</span>";
236 236
 }
237 237
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
238 238
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
  * @param WPInv_Subscription $subscription
243 243
  */
244 244
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
245
-	echo  '#' . absint( $subscription->get_id() );
245
+    echo  '#' . absint( $subscription->get_id() );
246 246
 }
247 247
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
248 248
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
  * @param WPInv_Subscription $subscription
253 253
  */
254 254
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
255
-	echo getpaid_format_date_value( $subscription->get_date_created() );
255
+    echo getpaid_format_date_value( $subscription->get_date_created() );
256 256
 }
257 257
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
258 258
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
  * @param WPInv_Subscription $subscription
263 263
  */
264 264
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
265
-	echo getpaid_format_date_value( $subscription->get_expiration() );
265
+    echo getpaid_format_date_value( $subscription->get_expiration() );
266 266
 }
267 267
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
268 268
 
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
  * @param WPInv_Subscription $subscription
273 273
  */
274 274
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
275
-	$max_bills = $subscription->get_bill_times();
276
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
275
+    $max_bills = $subscription->get_bill_times();
276
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
277 277
 }
278 278
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
279 279
 /**
@@ -283,16 +283,16 @@  discard block
 block discarded – undo
283 283
  */
284 284
 function getpaid_admin_subscription_metabox_display_item( $subscription ) {
285 285
 
286
-	$item = get_post( $subscription->get_product_id() );
286
+    $item = get_post( $subscription->get_product_id() );
287 287
 
288
-	if ( ! empty( $item ) ) {
289
-		$link = get_edit_post_link( $item );
290
-		$link = esc_url( $link );
291
-		$name = esc_html( get_the_title( $item ) );
292
-		echo "<a href='$link'>$name</a>";
293
-	} else {
294
-		echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
295
-	}
288
+    if ( ! empty( $item ) ) {
289
+        $link = get_edit_post_link( $item );
290
+        $link = esc_url( $link );
291
+        $name = esc_html( get_the_title( $item ) );
292
+        echo "<a href='$link'>$name</a>";
293
+    } else {
294
+        echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
295
+    }
296 296
 
297 297
 }
298 298
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' );
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
  */
305 305
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
306 306
 
307
-	$gateway = $subscription->get_gateway();
307
+    $gateway = $subscription->get_gateway();
308 308
 
309
-	if ( ! empty( $gateway ) ) {
310
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
311
-	} else {
312
-		echo "&mdash;";
313
-	}
309
+    if ( ! empty( $gateway ) ) {
310
+        echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
311
+    } else {
312
+        echo "&mdash;";
313
+    }
314 314
 
315 315
 }
316 316
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
  * @param WPInv_Subscription $subscription
322 322
  */
323 323
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
324
-	echo $subscription->get_status_label_html();
324
+    echo $subscription->get_status_label_html();
325 325
 }
326 326
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
327 327
 
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
  */
333 333
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
334 334
 
335
-	$profile_id = $subscription->get_profile_id();
335
+    $profile_id = $subscription->get_profile_id();
336 336
 
337
-	if ( ! empty( $profile_id ) ) {
338
-		$profile_id = sanitize_text_field( $profile_id );
339
-		echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription );
340
-	} else {
341
-		echo "&mdash;";
342
-	}
337
+    if ( ! empty( $profile_id ) ) {
338
+        $profile_id = sanitize_text_field( $profile_id );
339
+        echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription );
340
+    } else {
341
+        echo "&mdash;";
342
+    }
343 343
 
344 344
 }
345 345
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -351,39 +351,39 @@  discard block
 block discarded – undo
351 351
  */
352 352
 function getpaid_admin_subscription_update_metabox( $subscription ) {
353 353
 
354
-	?>
354
+    ?>
355 355
 	<div class="mt-3">
356 356
 
357 357
 		<?php
358
-			echo aui()->select(
359
-				array(
360
-					'options'          => getpaid_get_subscription_statuses(),
361
-					'name'             => 'subscription_status',
362
-					'id'               => 'subscription_status_update_select',
363
-					'required'         => true,
364
-					'no_wrap'          => false,
365
-					'label'            => __( 'Subscription Status', 'invoicing' ),
366
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
367
-					'select2'          => true,
368
-					'value'            => $subscription->get_status( 'edit' ),
369
-				)
370
-			);
371
-		?>
358
+            echo aui()->select(
359
+                array(
360
+                    'options'          => getpaid_get_subscription_statuses(),
361
+                    'name'             => 'subscription_status',
362
+                    'id'               => 'subscription_status_update_select',
363
+                    'required'         => true,
364
+                    'no_wrap'          => false,
365
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
366
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
367
+                    'select2'          => true,
368
+                    'value'            => $subscription->get_status( 'edit' ),
369
+                )
370
+            );
371
+        ?>
372 372
 
373 373
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
374 374
 	
375 375
 		<?php
376
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
376
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
377 377
 
378
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
379
-			$anchor = __( 'Renew Subscription', 'invoicing' );
380
-			$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' );
378
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
379
+            $anchor = __( 'Renew Subscription', 'invoicing' );
380
+            $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' );
381 381
 
382
-			if ( $subscription->is_active() ) {
383
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
384
-			}
382
+            if ( $subscription->is_active() ) {
383
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
384
+            }
385 385
 
386
-	echo '</div></div>';
386
+    echo '</div></div>';
387 387
 }
388 388
 
389 389
 /**
@@ -393,33 +393,33 @@  discard block
 block discarded – undo
393 393
  */
394 394
 function getpaid_admin_subscription_invoice_details_metabox( $subscription ) {
395 395
 
396
-	$columns = apply_filters(
397
-		'getpaid_subscription_related_invoices_columns',
398
-		array(
399
-			'invoice'      => __( 'Invoice', 'invoicing' ),
400
-			'relationship' => __( 'Relationship', 'invoicing' ),
401
-			'date'         => __( 'Date', 'invoicing' ),
402
-			'status'       => __( 'Status', 'invoicing' ),
403
-			'total'        => __( 'Total', 'invoicing' ),
404
-		),
405
-		$subscription
406
-	);
407
-
408
-	// Prepare the invoices.
409
-	$payments = $subscription->get_child_payments( ! is_admin() );
410
-	$parent   = $subscription->get_parent_invoice();
411
-
412
-	if ( $parent->get_id() ) {
413
-		$payments = array_merge( array( $parent ), $payments );
414
-	}
396
+    $columns = apply_filters(
397
+        'getpaid_subscription_related_invoices_columns',
398
+        array(
399
+            'invoice'      => __( 'Invoice', 'invoicing' ),
400
+            'relationship' => __( 'Relationship', 'invoicing' ),
401
+            'date'         => __( 'Date', 'invoicing' ),
402
+            'status'       => __( 'Status', 'invoicing' ),
403
+            'total'        => __( 'Total', 'invoicing' ),
404
+        ),
405
+        $subscription
406
+    );
407
+
408
+    // Prepare the invoices.
409
+    $payments = $subscription->get_child_payments( ! is_admin() );
410
+    $parent   = $subscription->get_parent_invoice();
411
+
412
+    if ( $parent->get_id() ) {
413
+        $payments = array_merge( array( $parent ), $payments );
414
+    }
415 415
 	
416
-	$table_class = 'w-100 bg-white';
416
+    $table_class = 'w-100 bg-white';
417 417
 
418
-	if ( ! is_admin() ) {
419
-		$table_class = 'table table-bordered table-striped';
420
-	}
418
+    if ( ! is_admin() ) {
419
+        $table_class = 'table table-bordered table-striped';
420
+    }
421 421
 
422
-	?>
422
+    ?>
423 423
 		<div class="m-0" style="overflow: auto;">
424 424
 
425 425
 			<table class="<?php echo $table_class; ?>">
@@ -427,13 +427,13 @@  discard block
 block discarded – undo
427 427
 				<thead>
428 428
 					<tr>
429 429
 						<?php
430
-							foreach ( $columns as $key => $label ) {
431
-								$key   = esc_attr( $key );
432
-								$label = sanitize_text_field( $label );
430
+                            foreach ( $columns as $key => $label ) {
431
+                                $key   = esc_attr( $key );
432
+                                $label = sanitize_text_field( $label );
433 433
 
434
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark font-weight-bold'>$label</th>";
435
-							}
436
-						?>
434
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark font-weight-bold'>$label</th>";
435
+                            }
436
+                        ?>
437 437
 					</tr>
438 438
 				</thead>
439 439
 
@@ -449,66 +449,66 @@  discard block
 block discarded – undo
449 449
 
450 450
 					<?php
451 451
 
452
-						foreach( $payments as $payment ) :
452
+                        foreach( $payments as $payment ) :
453 453
 
454
-							// Ensure that we have an invoice.
455
-							$payment = new WPInv_Invoice( $payment );
454
+                            // Ensure that we have an invoice.
455
+                            $payment = new WPInv_Invoice( $payment );
456 456
 
457
-							// Abort if the invoice is invalid.
458
-							if ( ! $payment->get_id() ) {
459
-								continue;
460
-							}
457
+                            // Abort if the invoice is invalid.
458
+                            if ( ! $payment->get_id() ) {
459
+                                continue;
460
+                            }
461 461
 
462
-							echo '<tr>';
462
+                            echo '<tr>';
463 463
 
464
-								foreach ( array_keys( $columns ) as $key ) {
464
+                                foreach ( array_keys( $columns ) as $key ) {
465 465
 
466
-									echo '<td class="p-2 text-left">';
466
+                                    echo '<td class="p-2 text-left">';
467 467
 
468
-										switch( $key ) {
468
+                                        switch( $key ) {
469 469
 
470
-											case 'total':
471
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
472
-												break;
470
+                                            case 'total':
471
+                                                echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
472
+                                                break;
473 473
 
474
-											case 'relationship':
475
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
476
-												break;
474
+                                            case 'relationship':
475
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
476
+                                                break;
477 477
 
478
-											case 'date':
479
-												echo getpaid_format_date_value( $payment->get_date_created() );
480
-												break;
478
+                                            case 'date':
479
+                                                echo getpaid_format_date_value( $payment->get_date_created() );
480
+                                                break;
481 481
 
482
-											case 'status':
482
+                                            case 'status':
483 483
 
484
-												$status = $payment->get_status_nicename();
485
-												if ( is_admin() ) {
486
-													$status = $payment->get_status_label_html();
487
-												}
484
+                                                $status = $payment->get_status_nicename();
485
+                                                if ( is_admin() ) {
486
+                                                    $status = $payment->get_status_label_html();
487
+                                                }
488 488
 
489
-												echo $status;
490
-												break;
489
+                                                echo $status;
490
+                                                break;
491 491
 
492
-											case 'invoice':
493
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
492
+                                            case 'invoice':
493
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
494 494
 
495
-												if ( ! is_admin() ) {
496
-													$link = esc_url( $payment->get_view_url() );
497
-												}
495
+                                                if ( ! is_admin() ) {
496
+                                                    $link = esc_url( $payment->get_view_url() );
497
+                                                }
498 498
 
499
-												$invoice = sanitize_text_field( $payment->get_number() );
500
-												echo "<a href='$link'>$invoice</a>";
501
-												break;
502
-										}
499
+                                                $invoice = sanitize_text_field( $payment->get_number() );
500
+                                                echo "<a href='$link'>$invoice</a>";
501
+                                                break;
502
+                                        }
503 503
 
504
-									echo '</td>';
504
+                                    echo '</td>';
505 505
 
506
-								}
506
+                                }
507 507
 
508
-							echo '</tr>';
508
+                            echo '</tr>';
509 509
 
510
-						endforeach;
511
-					?>
510
+                        endforeach;
511
+                    ?>
512 512
 
513 513
 				</tbody>
514 514
 
Please login to merge, or discard this patch.
includes/subscription-functions.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -17,28 +17,28 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
19 19
 
20
-	// Do not retrieve all fields if we just want the count.
21
-	if ( 'count' == $return ) {
22
-		$args['fields'] = 'id';
23
-		$args['number'] = 1;
24
-	}
20
+    // Do not retrieve all fields if we just want the count.
21
+    if ( 'count' == $return ) {
22
+        $args['fields'] = 'id';
23
+        $args['number'] = 1;
24
+    }
25 25
 
26
-	// Do not count all matches if we just want the results.
27
-	if ( 'results' == $return ) {
28
-		$args['count_total'] = false;
29
-	}
26
+    // Do not count all matches if we just want the results.
27
+    if ( 'results' == $return ) {
28
+        $args['count_total'] = false;
29
+    }
30 30
 
31
-	$query = new GetPaid_Subscriptions_Query( $args );
31
+    $query = new GetPaid_Subscriptions_Query( $args );
32 32
 
33
-	if ( 'results' == $return ) {
34
-		return $query->get_results();
35
-	}
33
+    if ( 'results' == $return ) {
34
+        return $query->get_results();
35
+    }
36 36
 
37
-	if ( 'count' == $return ) {
38
-		return $query->get_total();
39
-	}
37
+    if ( 'count' == $return ) {
38
+        return $query->get_total();
39
+    }
40 40
 
41
-	return $query;
41
+    return $query;
42 42
 }
43 43
 
44 44
 /**
@@ -48,18 +48,18 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function getpaid_get_subscription_statuses() {
50 50
 
51
-	return apply_filters(
52
-		'getpaid_get_subscription_statuses',
53
-		array(
54
-			'pending'    => __( 'Pending', 'invoicing' ),
55
-			'trialling'  => __( 'Trialing', 'invoicing' ),
56
-			'active'     => __( 'Active', 'invoicing' ),
57
-			'failing'    => __( 'Failing', 'invoicing' ),
58
-			'expired'    => __( 'Expired', 'invoicing' ),
59
-			'completed'  => __( 'Complete', 'invoicing' ),
60
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
61
-		)
62
-	);
51
+    return apply_filters(
52
+        'getpaid_get_subscription_statuses',
53
+        array(
54
+            'pending'    => __( 'Pending', 'invoicing' ),
55
+            'trialling'  => __( 'Trialing', 'invoicing' ),
56
+            'active'     => __( 'Active', 'invoicing' ),
57
+            'failing'    => __( 'Failing', 'invoicing' ),
58
+            'expired'    => __( 'Expired', 'invoicing' ),
59
+            'completed'  => __( 'Complete', 'invoicing' ),
60
+            'cancelled'  => __( 'Cancelled', 'invoicing' ),
61
+        )
62
+    );
63 63
 
64 64
 }
65 65
 
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
  * @return string
70 70
  */
71 71
 function getpaid_get_subscription_status_label( $status ) {
72
-	$statuses = getpaid_get_subscription_statuses();
73
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
72
+    $statuses = getpaid_get_subscription_statuses();
73
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
74 74
 }
75 75
 
76 76
 /**
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function getpaid_get_subscription_status_classes() {
82 82
 
83
-	return apply_filters(
84
-		'getpaid_get_subscription_status_classes',
85
-		array(
86
-			'pending'    => 'badge-dark',
87
-			'trialling'  => 'badge-info',
88
-			'active'     => 'badge-success',
89
-			'failing'    => 'badge-warning',
90
-			'expired'    => 'badge-danger',
91
-			'completed'  => 'badge-primary',
92
-			'cancelled'  => 'badge-secondary',
93
-		)
94
-	);
83
+    return apply_filters(
84
+        'getpaid_get_subscription_status_classes',
85
+        array(
86
+            'pending'    => 'badge-dark',
87
+            'trialling'  => 'badge-info',
88
+            'active'     => 'badge-success',
89
+            'failing'    => 'badge-warning',
90
+            'expired'    => 'badge-danger',
91
+            'completed'  => 'badge-primary',
92
+            'cancelled'  => 'badge-secondary',
93
+        )
94
+    );
95 95
 
96 96
 }
97 97
 
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
  */
103 103
 function getpaid_get_subscription_status_counts( $args = array() ) {
104 104
 
105
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
106
-	$counts   = array();
105
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
106
+    $counts   = array();
107 107
 
108
-	foreach ( $statuses as $status ) {
109
-		$_args             = wp_parse_args( "status=$status", $args );
110
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
111
-	}
108
+    foreach ( $statuses as $status ) {
109
+        $_args             = wp_parse_args( "status=$status", $args );
110
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
111
+    }
112 112
 
113
-	return $counts;
113
+    return $counts;
114 114
 
115 115
 }
116 116
 
@@ -121,32 +121,32 @@  discard block
 block discarded – undo
121 121
  */
122 122
 function getpaid_get_subscription_periods() {
123 123
 
124
-	return apply_filters(
125
-		'getpaid_get_subscription_periods',
126
-		array(
124
+    return apply_filters(
125
+        'getpaid_get_subscription_periods',
126
+        array(
127 127
 
128
-			'day'   => array(
129
-				'singular' => __( '%s day', 'invoicing' ),
130
-				'plural'   => __( '%d days', 'invoicing' ),
131
-			),
128
+            'day'   => array(
129
+                'singular' => __( '%s day', 'invoicing' ),
130
+                'plural'   => __( '%d days', 'invoicing' ),
131
+            ),
132 132
 
133
-			'week'   => array(
134
-				'singular' => __( '%s week', 'invoicing' ),
135
-				'plural'   => __( '%d weeks', 'invoicing' ),
136
-			),
133
+            'week'   => array(
134
+                'singular' => __( '%s week', 'invoicing' ),
135
+                'plural'   => __( '%d weeks', 'invoicing' ),
136
+            ),
137 137
 
138
-			'month'   => array(
139
-				'singular' => __( '%s month', 'invoicing' ),
140
-				'plural'   => __( '%d months', 'invoicing' ),
141
-			),
138
+            'month'   => array(
139
+                'singular' => __( '%s month', 'invoicing' ),
140
+                'plural'   => __( '%d months', 'invoicing' ),
141
+            ),
142 142
 
143
-			'year'   => array(
144
-				'singular' => __( '%s year', 'invoicing' ),
145
-				'plural'   => __( '%d years', 'invoicing' ),
146
-			),
143
+            'year'   => array(
144
+                'singular' => __( '%s year', 'invoicing' ),
145
+                'plural'   => __( '%d years', 'invoicing' ),
146
+            ),
147 147
 
148
-		)
149
-	);
148
+        )
149
+    );
150 150
 
151 151
 }
152 152
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
  * @return int
158 158
  */
159 159
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
160
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
160
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
161 161
 }
162 162
 
163 163
 /**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
  * @return string
168 168
  */
169 169
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
170
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
170
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
171 171
 }
172 172
 
173 173
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  * @return string
179 179
  */
180 180
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
181
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
-	return strtolower( sanitize_text_field( $label ) );
181
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
+    return strtolower( sanitize_text_field( $label ) );
183 183
 }
184 184
 
185 185
 /**
@@ -190,22 +190,22 @@  discard block
 block discarded – undo
190 190
  */
191 191
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
192 192
 
193
-	$periods = getpaid_get_subscription_periods();
194
-	$period  = strtolower( $period );
193
+    $periods = getpaid_get_subscription_periods();
194
+    $period  = strtolower( $period );
195 195
 
196
-	if ( isset( $periods[ $period ] ) ) {
197
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
198
-	}
196
+    if ( isset( $periods[ $period ] ) ) {
197
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
198
+    }
199 199
 
200
-	// Backwards compatibility.
201
-	foreach ( $periods as $key => $data ) {
202
-		if ( strpos( $key, $period ) === 0 ) {
203
-			return sprintf( $data['singular'], $singular_prefix );
204
-		}
205
-	}
200
+    // Backwards compatibility.
201
+    foreach ( $periods as $key => $data ) {
202
+        if ( strpos( $key, $period ) === 0 ) {
203
+            return sprintf( $data['singular'], $singular_prefix );
204
+        }
205
+    }
206 206
 
207
-	// Invalid string.
208
-	return '';
207
+    // Invalid string.
208
+    return '';
209 209
 }
210 210
 
211 211
 /**
@@ -217,22 +217,22 @@  discard block
 block discarded – undo
217 217
  */
218 218
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
219 219
 
220
-	$periods = getpaid_get_subscription_periods();
221
-	$period  = strtolower( $period );
220
+    $periods = getpaid_get_subscription_periods();
221
+    $period  = strtolower( $period );
222 222
 
223
-	if ( isset( $periods[ $period ] ) ) {
224
-		return sprintf( $periods[ $period ]['plural'], $interval );
225
-	}
223
+    if ( isset( $periods[ $period ] ) ) {
224
+        return sprintf( $periods[ $period ]['plural'], $interval );
225
+    }
226 226
 
227
-	// Backwards compatibility.
228
-	foreach ( $periods as $key => $data ) {
229
-		if ( strpos( $key, $period ) === 0 ) {
230
-			return sprintf( $data['plural'], $interval );
231
-		}
232
-	}
227
+    // Backwards compatibility.
228
+    foreach ( $periods as $key => $data ) {
229
+        if ( strpos( $key, $period ) === 0 ) {
230
+            return sprintf( $data['plural'], $interval );
231
+        }
232
+    }
233 233
 
234
-	// Invalid string.
235
-	return '';
234
+    // Invalid string.
235
+    return '';
236 236
 }
237 237
 
238 238
 /**
@@ -243,50 +243,50 @@  discard block
 block discarded – undo
243 243
  */
244 244
 function getpaid_get_formatted_subscription_amount( $subscription ) {
245 245
 
246
-	$initial   = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
-	$recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
-	$period    = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
246
+    $initial   = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
+    $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
+    $period    = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
249 249
 
250
-	// Trial periods.
251
-	if ( $subscription->has_trial_period() ) {
250
+    // Trial periods.
251
+    if ( $subscription->has_trial_period() ) {
252 252
 
253
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
254
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
255
-		return sprintf(
253
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
254
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
255
+        return sprintf(
256 256
 
257
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
258
-			_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
259
-			$initial,
260
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
261
-			$recurring,
262
-			$period
257
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
258
+            _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
259
+            $initial,
260
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
261
+            $recurring,
262
+            $period
263 263
 
264
-		);
264
+        );
265 265
 
266
-	}
266
+    }
267 267
 
268
-	if ( $initial != $recurring ) {
268
+    if ( $initial != $recurring ) {
269 269
 
270
-		return sprintf(
270
+        return sprintf(
271 271
 
272
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
273
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
274
-			$initial,
275
-			$recurring,
276
-			$period
272
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
273
+            _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
274
+            $initial,
275
+            $recurring,
276
+            $period
277 277
 
278
-		);
278
+        );
279 279
 
280
-	}
280
+    }
281 281
 
282
-	return sprintf(
282
+    return sprintf(
283 283
 
284
-		// translators: $1: is the recurring amount, $2: is the recurring period
285
-		_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
286
-		$initial,
287
-		$period
284
+        // translators: $1: is the recurring amount, $2: is the recurring period
285
+        _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
286
+        $initial,
287
+        $period
288 288
 
289
-	);
289
+    );
290 290
 
291 291
 }
292 292
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
  * @return WPInv_Subscription|bool
298 298
  */
299 299
 function getpaid_get_invoice_subscription( $invoice ) {
300
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
300
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
301 301
 }
302 302
 
303 303
 /**
@@ -306,10 +306,10 @@  discard block
 block discarded – undo
306 306
  * @param WPInv_Invoice $invoice
307 307
  */
308 308
 function getpaid_activate_invoice_subscription( $invoice ) {
309
-	$subscription = getpaid_get_invoice_subscription( $invoice );
310
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
311
-		$subscription->activate();
312
-	}
309
+    $subscription = getpaid_get_invoice_subscription( $invoice );
310
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
311
+        $subscription->activate();
312
+    }
313 313
 }
314 314
 
315 315
 /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  * @return WPInv_Subscriptions
319 319
  */
320 320
 function getpaid_subscriptions() {
321
-	return getpaid()->get( 'subscriptions' );
321
+    return getpaid()->get( 'subscriptions' );
322 322
 }
323 323
 
324 324
 /**
@@ -336,14 +336,14 @@  discard block
 block discarded – undo
336 336
         return false;
337 337
     }
338 338
 
339
-	// Fetch the invoiec subscription.
340
-	$subscription = getpaid_get_subscriptions(
341
-		array(
342
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
343
-			'number'     => 1,
344
-		)
345
-	);
339
+    // Fetch the invoiec subscription.
340
+    $subscription = getpaid_get_subscriptions(
341
+        array(
342
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
343
+            'number'     => 1,
344
+        )
345
+    );
346 346
 
347
-	return empty( $subscription ) ? false : $subscription[0];
347
+    return empty( $subscription ) ? false : $subscription[0];
348 348
 
349 349
 }
Please login to merge, or discard this patch.
includes/class-getpaid-subscription-notification-emails.php 1 patch
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -13,282 +13,282 @@
 block discarded – undo
13 13
 class GetPaid_Subscription_Notification_Emails {
14 14
 
15 15
     /**
16
-	 * The array of subscription email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $subscription_actions;
16
+     * The array of subscription email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $subscription_actions;
21 21
 
22 22
     /**
23
-	 * Class constructor
23
+     * Class constructor
24 24
      *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->subscription_actions = apply_filters(
29
-			'getpaid_notification_email_subscription_triggers',
30
-			array(
31
-				'getpaid_subscription_trialling' => 'subscription_trial',
32
-				'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
-				'getpaid_subscription_expired'   => 'subscription_expired',
34
-				'getpaid_subscription_completed' => 'subscription_complete',
35
-				'getpaid_daily_maintenance'      => 'renewal_reminder',
36
-			)
37
-		);
38
-
39
-		$this->init_hooks();
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->subscription_actions = apply_filters(
29
+            'getpaid_notification_email_subscription_triggers',
30
+            array(
31
+                'getpaid_subscription_trialling' => 'subscription_trial',
32
+                'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
+                'getpaid_subscription_expired'   => 'subscription_expired',
34
+                'getpaid_subscription_completed' => 'subscription_complete',
35
+                'getpaid_daily_maintenance'      => 'renewal_reminder',
36
+            )
37
+        );
38
+
39
+        $this->init_hooks();
40 40
 
41 41
     }
42 42
 
43 43
     /**
44
-	 * Registers email hooks.
45
-	 */
46
-	public function init_hooks() {
47
-
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
50
-
51
-			$email = new GetPaid_Notification_Email( $email_type );
52
-
53
-			if ( ! $email->is_active() ) {
54
-				continue;
55
-			}
56
-
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
59
-				continue;
60
-			}
61
-
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
-
64
-		}
65
-
66
-	}
67
-
68
-	/**
69
-	 * Filters subscription merge tags.
70
-	 *
71
-	 * @param array $merge_tags
72
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
-	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
75
-
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
-			$merge_tags = array_merge(
78
-				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
80
-			);
81
-		}
82
-
83
-		return $merge_tags;
84
-
85
-	}
86
-
87
-	/**
88
-	 * Generates subscription merge tags.
89
-	 *
90
-	 * @param WPInv_Subscription $subscription
91
-	 * @return array
92
-	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
94
-
95
-		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
97
-			return array();
98
-		}
99
-
100
-		$invoice    = $subscription->get_parent_invoice();
101
-		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
-			'{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
-			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
-		);
113
-
114
-	}
115
-
116
-	/**
117
-	 * Checks if we should send a notification for a subscription.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return bool
121
-	 */
122
-	public function should_send_notification( $invoice ) {
123
-		return 0 != $invoice->get_id();
124
-	}
125
-
126
-	/**
127
-	 * Returns notification recipients.
128
-	 *
129
-	 * @param WPInv_Invoice $invoice
130
-	 * @return array
131
-	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
134
-
135
-		$cc = $invoice->get_email_cc();
136
-
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
-		}
141
-
142
-		return $recipients;
143
-	}
144
-
145
-	/**
146
-	 * Helper function to send an email.
147
-	 *
148
-	 * @param WPInv_Subscription $subscription
149
-	 * @param GetPaid_Notification_Email $email
150
-	 * @param string $type
151
-	 * @param array $extra_args Extra template args.
152
-	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
-
155
-		// Abort in case the parent invoice does not exist.
156
-		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
158
-			return;
159
-		}
160
-
161
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
162
-
163
-		$recipients  = $this->get_recipients( $invoice );
164
-		$mailer      = new GetPaid_Notification_Email_Sender();
165
-		$merge_tags  = $email->get_merge_tags();
166
-		$content     = $email->get_content( $merge_tags, $extra_args );
167
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
168
-		$attachments = $email->get_attachments();
169
-
170
-		$result = $mailer->send(
171
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
172
-			$subject,
173
-			$content,
174
-			$attachments
175
-		);
176
-
177
-		// Maybe send a copy to the admin.
178
-		if ( $email->include_admin_bcc() ) {
179
-			$mailer->send(
180
-				wpinv_get_admin_email(),
181
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
182
-				$content,
183
-				$attachments
184
-			);
185
-		}
186
-
187
-		if ( ! $result ) {
188
-			$subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
189
-		}
190
-
191
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
192
-
193
-	}
44
+     * Registers email hooks.
45
+     */
46
+    public function init_hooks() {
47
+
48
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
+        foreach ( $this->subscription_actions as $hook => $email_type ) {
50
+
51
+            $email = new GetPaid_Notification_Email( $email_type );
52
+
53
+            if ( ! $email->is_active() ) {
54
+                continue;
55
+            }
56
+
57
+            if ( method_exists( $this, $email_type ) ) {
58
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
59
+                continue;
60
+            }
61
+
62
+            do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
+
64
+        }
65
+
66
+    }
194 67
 
195 68
     /**
196
-	 * Sends a new trial notification.
197
-	 *
198
-	 * @param WPInv_Subscription $subscription
199
-	 */
200
-	public function subscription_trial( $subscription ) {
69
+     * Filters subscription merge tags.
70
+     *
71
+     * @param array $merge_tags
72
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
+     */
74
+    public function subscription_merge_tags( $merge_tags, $object ) {
201 75
 
202
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
-		$this->send_email( $subscription, $email, __FUNCTION__ );
76
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
+            $merge_tags = array_merge(
78
+                $merge_tags,
79
+                $this->get_subscription_merge_tags( $object )
80
+            );
81
+        }
204 82
 
205
-	}
83
+        return $merge_tags;
206 84
 
207
-	/**
208
-	 * Sends a cancelled subscription notification.
209
-	 *
210
-	 * @param WPInv_Subscription $subscription
211
-	 */
212
-	public function subscription_cancelled( $subscription ) {
85
+    }
213 86
 
214
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
-		$this->send_email( $subscription, $email, __FUNCTION__ );
87
+    /**
88
+     * Generates subscription merge tags.
89
+     *
90
+     * @param WPInv_Subscription $subscription
91
+     * @return array
92
+     */
93
+    public function get_subscription_merge_tags( $subscription ) {
94
+
95
+        // Abort if it does not exist.
96
+        if ( ! $subscription->get_id() ) {
97
+            return array();
98
+        }
99
+
100
+        $invoice    = $subscription->get_parent_invoice();
101
+        return array(
102
+            '{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
+            '{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
+            '{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
+            '{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
+            '{subscription_id}'               => absint( $subscription->get_id() ),
107
+            '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
+            '{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
+            '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
+            '{subscription_bill_times}'       => $subscription->get_bill_times(),
111
+            '{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
+        );
216 113
 
217
-	}
114
+    }
218 115
 
219
-	/**
220
-	 * Sends a subscription expired notification.
221
-	 *
222
-	 * @param WPInv_Subscription $subscription
223
-	 */
224
-	public function subscription_expired( $subscription ) {
116
+    /**
117
+     * Checks if we should send a notification for a subscription.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return bool
121
+     */
122
+    public function should_send_notification( $invoice ) {
123
+        return 0 != $invoice->get_id();
124
+    }
225 125
 
226
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
-		$this->send_email( $subscription, $email, __FUNCTION__ );
126
+    /**
127
+     * Returns notification recipients.
128
+     *
129
+     * @param WPInv_Invoice $invoice
130
+     * @return array
131
+     */
132
+    public function get_recipients( $invoice ) {
133
+        $recipients = array( $invoice->get_email() );
228 134
 
229
-	}
135
+        $cc = $invoice->get_email_cc();
230 136
 
231
-	/**
232
-	 * Sends a completed subscription notification.
233
-	 *
234
-	 * @param WPInv_Subscription $subscription
235
-	 */
236
-	public function subscription_complete( $subscription ) {
137
+        if ( ! empty( $cc ) ) {
138
+            $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
+            $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
+        }
237 141
 
238
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
-		$this->send_email( $subscription, $email, __FUNCTION__ );
142
+        return $recipients;
143
+    }
240 144
 
241
-	}
145
+    /**
146
+     * Helper function to send an email.
147
+     *
148
+     * @param WPInv_Subscription $subscription
149
+     * @param GetPaid_Notification_Email $email
150
+     * @param string $type
151
+     * @param array $extra_args Extra template args.
152
+     */
153
+    public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
+
155
+        // Abort in case the parent invoice does not exist.
156
+        $invoice = $subscription->get_parent_invoice();
157
+        if ( ! $this->should_send_notification( $invoice ) ) {
158
+            return;
159
+        }
160
+
161
+        do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
162
+
163
+        $recipients  = $this->get_recipients( $invoice );
164
+        $mailer      = new GetPaid_Notification_Email_Sender();
165
+        $merge_tags  = $email->get_merge_tags();
166
+        $content     = $email->get_content( $merge_tags, $extra_args );
167
+        $subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
168
+        $attachments = $email->get_attachments();
169
+
170
+        $result = $mailer->send(
171
+            apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
172
+            $subject,
173
+            $content,
174
+            $attachments
175
+        );
176
+
177
+        // Maybe send a copy to the admin.
178
+        if ( $email->include_admin_bcc() ) {
179
+            $mailer->send(
180
+                wpinv_get_admin_email(),
181
+                $subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
182
+                $content,
183
+                $attachments
184
+            );
185
+        }
186
+
187
+        if ( ! $result ) {
188
+            $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
189
+        }
190
+
191
+        do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
242 192
 
243
-	/**
244
-	 * Sends a subscription renewal reminder notification.
245
-	 *
246
-	 */
247
-	public function renewal_reminder() {
193
+    }
248 194
 
249
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
195
+    /**
196
+     * Sends a new trial notification.
197
+     *
198
+     * @param WPInv_Subscription $subscription
199
+     */
200
+    public function subscription_trial( $subscription ) {
250 201
 
251
-		// Fetch reminder days.
252
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
202
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
+        $this->send_email( $subscription, $email, __FUNCTION__ );
253 204
 
254
-		// Abort if non is set.
255
-		if ( empty( $reminder_days ) ) {
256
-			return;
257
-		}
205
+    }
258 206
 
259
-		// Fetch matching subscriptions.
207
+    /**
208
+     * Sends a cancelled subscription notification.
209
+     *
210
+     * @param WPInv_Subscription $subscription
211
+     */
212
+    public function subscription_cancelled( $subscription ) {
213
+
214
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
+        $this->send_email( $subscription, $email, __FUNCTION__ );
216
+
217
+    }
218
+
219
+    /**
220
+     * Sends a subscription expired notification.
221
+     *
222
+     * @param WPInv_Subscription $subscription
223
+     */
224
+    public function subscription_expired( $subscription ) {
225
+
226
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
+        $this->send_email( $subscription, $email, __FUNCTION__ );
228
+
229
+    }
230
+
231
+    /**
232
+     * Sends a completed subscription notification.
233
+     *
234
+     * @param WPInv_Subscription $subscription
235
+     */
236
+    public function subscription_complete( $subscription ) {
237
+
238
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
+        $this->send_email( $subscription, $email, __FUNCTION__ );
240
+
241
+    }
242
+
243
+    /**
244
+     * Sends a subscription renewal reminder notification.
245
+     *
246
+     */
247
+    public function renewal_reminder() {
248
+
249
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
250
+
251
+        // Fetch reminder days.
252
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
253
+
254
+        // Abort if non is set.
255
+        if ( empty( $reminder_days ) ) {
256
+            return;
257
+        }
258
+
259
+        // Fetch matching subscriptions.
260 260
         $args  = array(
261 261
             'number'             => -1,
262
-			'count_total'        => false,
263
-			'status'             => 'trialling active',
262
+            'count_total'        => false,
263
+            'status'             => 'trialling active',
264 264
             'date_expires_query' => array(
265
-				'relation'  => 'OR'
265
+                'relation'  => 'OR'
266 266
             ),
267
-		);
267
+        );
268 268
 
269
-		foreach ( $reminder_days as $days ) {
270
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
269
+        foreach ( $reminder_days as $days ) {
270
+            $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
271 271
 
272
-			$args['date_expires_query'][] = array(
273
-				'year'  => $date['year'],
274
-				'month' => $date['month'],
275
-				'day'   => $date['day'],
276
-			);
272
+            $args['date_expires_query'][] = array(
273
+                'year'  => $date['year'],
274
+                'month' => $date['month'],
275
+                'day'   => $date['day'],
276
+            );
277 277
 
278
-		}
278
+        }
279 279
 
280
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
280
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
281 281
 
282 282
         foreach ( $subscriptions as $subscription ) {
283 283
 
284
-			// Skip packages.
285
-			if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
286
-				$email->object = $subscription;
287
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
288
-			}
284
+            // Skip packages.
285
+            if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
286
+                $email->object = $subscription;
287
+                $this->send_email( $subscription, $email, __FUNCTION__ );
288
+            }
289 289
 
290
-		}
290
+        }
291 291
 
292
-	}
292
+    }
293 293
 
294 294
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-subscription-data-store.php 1 patch
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,197 +15,197 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Subscription_Data_Store {
17 17
 
18
-	/**
19
-	 * A map of database fields to data types.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $database_fields_to_data_type = array(
25
-		'id'                => '%d',
26
-		'customer_id'       => '%d',
27
-		'frequency'         => '%d',
28
-		'period'            => '%s',
29
-		'initial_amount'    => '%s',
30
-		'recurring_amount'  => '%s',
31
-		'bill_times'        => '%d',
32
-		'transaction_id'    => '%s',
33
-		'parent_payment_id' => '%d',
34
-		'product_id'        => '%d',
35
-		'created'           => '%s',
36
-		'expiration'        => '%s',
37
-		'trial_period'      => '%s',
38
-		'status'            => '%s',
39
-		'profile_id'        => '%s',
40
-	);
41
-
42
-	/*
18
+    /**
19
+     * A map of database fields to data types.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $database_fields_to_data_type = array(
25
+        'id'                => '%d',
26
+        'customer_id'       => '%d',
27
+        'frequency'         => '%d',
28
+        'period'            => '%s',
29
+        'initial_amount'    => '%s',
30
+        'recurring_amount'  => '%s',
31
+        'bill_times'        => '%d',
32
+        'transaction_id'    => '%s',
33
+        'parent_payment_id' => '%d',
34
+        'product_id'        => '%d',
35
+        'created'           => '%s',
36
+        'expiration'        => '%s',
37
+        'trial_period'      => '%s',
38
+        'status'            => '%s',
39
+        'profile_id'        => '%s',
40
+    );
41
+
42
+    /*
43 43
 	|--------------------------------------------------------------------------
44 44
 	| CRUD Methods
45 45
 	|--------------------------------------------------------------------------
46 46
 	*/
47 47
 
48
-	/**
49
-	 * Method to create a new subscription in the database.
50
-	 *
51
-	 * @param WPInv_Subscription $subscription Subscription object.
52
-	 */
53
-	public function create( &$subscription ) {
54
-		global $wpdb;
55
-
56
-		$values  = array();
57
-		$formats = array();
58
-
59
-		$fields = $this->database_fields_to_data_type;
60
-		unset( $fields['id'] );
61
-
62
-		foreach ( $fields as $key => $format ) {
63
-			$method       = "get_$key";
64
-			$values[$key] = $subscription->$method( 'edit' );
65
-			$formats[]    = $format;
66
-		}
67
-
68
-		$result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats );
69
-
70
-		if ( $result ) {
71
-			$subscription->set_id( $wpdb->insert_id );
72
-			$subscription->apply_changes();
73
-			$subscription->clear_cache();
74
-			update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
-			do_action( 'getpaid_new_subscription', $subscription );
76
-			return true;
77
-		}
78
-
79
-		return false;
80
-	}
81
-
82
-	/**
83
-	 * Method to read a subscription from the database.
84
-	 *
85
-	 * @param WPInv_Subscription $subscription Subscription object.
86
-	 *
87
-	 */
88
-	public function read( &$subscription ) {
89
-		global $wpdb;
90
-
91
-		$subscription->set_defaults();
92
-
93
-		if ( ! $subscription->get_id() ) {
94
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
-			$subscription->set_id( 0 );
96
-			return false;
97
-		}
98
-
99
-		// Maybe retrieve from the cache.
100
-		$raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
101
-
102
-		// If not found, retrieve from the db.
103
-		if ( false === $raw_subscription ) {
104
-
105
-			$raw_subscription = $wpdb->get_row(
106
-				$wpdb->prepare(
107
-					"SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d",
108
-					$subscription->get_id()
109
-				)
110
-			);
111
-
112
-			// Update the cache with our data
113
-			wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
114
-
115
-		}
116
-
117
-		if ( ! $raw_subscription ) {
118
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
119
-			return false;
120
-		}
121
-
122
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
123
-			$method     = "set_$key";
124
-			$subscription->$method( $raw_subscription->$key );
125
-		}
126
-
127
-		$subscription->set_object_read( true );
128
-		do_action( 'getpaid_read_subscription', $subscription );
129
-
130
-	}
131
-
132
-	/**
133
-	 * Method to update a subscription in the database.
134
-	 *
135
-	 * @param WPInv_Subscription $subscription Subscription object.
136
-	 */
137
-	public function update( &$subscription ) {
138
-		global $wpdb;
139
-
140
-		$changes = $subscription->get_changes();
141
-		$values  = array();
142
-		$formats = array();
143
-
144
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
145
-			if ( array_key_exists( $key, $changes ) ) {
146
-				$method       = "get_$key";
147
-				$values[$key] = $subscription->$method( 'edit' );
148
-				$formats[]    = $format;
149
-			}
150
-		}
151
-
152
-		if ( empty( $values ) ) {
153
-			return;
154
-		}
155
-
156
-		$wpdb->update(
157
-			$wpdb->prefix . 'wpinv_subscriptions',
158
-			$values,
159
-			array(
160
-				'id' => $subscription->get_id(),
161
-			),
162
-			$formats,
163
-			'%d'
164
-		);
165
-
166
-		// Apply the changes.
167
-		$subscription->apply_changes();
168
-
169
-		// Delete cache.
170
-		$subscription->clear_cache();
171
-
172
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
173
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
174
-
175
-		// Fire a hook.
176
-		do_action( 'getpaid_update_subscription', $subscription );
177
-
178
-	}
179
-
180
-	/**
181
-	 * Method to delete a subscription from the database.
182
-	 *
183
-	 * @param WPInv_Subscription $subscription
184
-	 */
185
-	public function delete( &$subscription ) {
186
-		global $wpdb;
187
-
188
-		$wpdb->query(
189
-			$wpdb->prepare(
190
-				"DELETE FROM {$wpdb->prefix}wpinv_subscriptions
48
+    /**
49
+     * Method to create a new subscription in the database.
50
+     *
51
+     * @param WPInv_Subscription $subscription Subscription object.
52
+     */
53
+    public function create( &$subscription ) {
54
+        global $wpdb;
55
+
56
+        $values  = array();
57
+        $formats = array();
58
+
59
+        $fields = $this->database_fields_to_data_type;
60
+        unset( $fields['id'] );
61
+
62
+        foreach ( $fields as $key => $format ) {
63
+            $method       = "get_$key";
64
+            $values[$key] = $subscription->$method( 'edit' );
65
+            $formats[]    = $format;
66
+        }
67
+
68
+        $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats );
69
+
70
+        if ( $result ) {
71
+            $subscription->set_id( $wpdb->insert_id );
72
+            $subscription->apply_changes();
73
+            $subscription->clear_cache();
74
+            update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
+            do_action( 'getpaid_new_subscription', $subscription );
76
+            return true;
77
+        }
78
+
79
+        return false;
80
+    }
81
+
82
+    /**
83
+     * Method to read a subscription from the database.
84
+     *
85
+     * @param WPInv_Subscription $subscription Subscription object.
86
+     *
87
+     */
88
+    public function read( &$subscription ) {
89
+        global $wpdb;
90
+
91
+        $subscription->set_defaults();
92
+
93
+        if ( ! $subscription->get_id() ) {
94
+            $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
+            $subscription->set_id( 0 );
96
+            return false;
97
+        }
98
+
99
+        // Maybe retrieve from the cache.
100
+        $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
101
+
102
+        // If not found, retrieve from the db.
103
+        if ( false === $raw_subscription ) {
104
+
105
+            $raw_subscription = $wpdb->get_row(
106
+                $wpdb->prepare(
107
+                    "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d",
108
+                    $subscription->get_id()
109
+                )
110
+            );
111
+
112
+            // Update the cache with our data
113
+            wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
114
+
115
+        }
116
+
117
+        if ( ! $raw_subscription ) {
118
+            $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
119
+            return false;
120
+        }
121
+
122
+        foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
123
+            $method     = "set_$key";
124
+            $subscription->$method( $raw_subscription->$key );
125
+        }
126
+
127
+        $subscription->set_object_read( true );
128
+        do_action( 'getpaid_read_subscription', $subscription );
129
+
130
+    }
131
+
132
+    /**
133
+     * Method to update a subscription in the database.
134
+     *
135
+     * @param WPInv_Subscription $subscription Subscription object.
136
+     */
137
+    public function update( &$subscription ) {
138
+        global $wpdb;
139
+
140
+        $changes = $subscription->get_changes();
141
+        $values  = array();
142
+        $formats = array();
143
+
144
+        foreach ( $this->database_fields_to_data_type as $key => $format ) {
145
+            if ( array_key_exists( $key, $changes ) ) {
146
+                $method       = "get_$key";
147
+                $values[$key] = $subscription->$method( 'edit' );
148
+                $formats[]    = $format;
149
+            }
150
+        }
151
+
152
+        if ( empty( $values ) ) {
153
+            return;
154
+        }
155
+
156
+        $wpdb->update(
157
+            $wpdb->prefix . 'wpinv_subscriptions',
158
+            $values,
159
+            array(
160
+                'id' => $subscription->get_id(),
161
+            ),
162
+            $formats,
163
+            '%d'
164
+        );
165
+
166
+        // Apply the changes.
167
+        $subscription->apply_changes();
168
+
169
+        // Delete cache.
170
+        $subscription->clear_cache();
171
+
172
+        update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
173
+        update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
174
+
175
+        // Fire a hook.
176
+        do_action( 'getpaid_update_subscription', $subscription );
177
+
178
+    }
179
+
180
+    /**
181
+     * Method to delete a subscription from the database.
182
+     *
183
+     * @param WPInv_Subscription $subscription
184
+     */
185
+    public function delete( &$subscription ) {
186
+        global $wpdb;
187
+
188
+        $wpdb->query(
189
+            $wpdb->prepare(
190
+                "DELETE FROM {$wpdb->prefix}wpinv_subscriptions
191 191
 				WHERE id = %d",
192
-				$subscription->get_id()
193
-			)
194
-		);
192
+                $subscription->get_id()
193
+            )
194
+        );
195 195
 
196
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
197
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
196
+        delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
197
+        delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
198 198
 
199
-		// Delete cache.
200
-		$subscription->clear_cache();
199
+        // Delete cache.
200
+        $subscription->clear_cache();
201 201
 
202
-		// Fire a hook.
203
-		do_action( 'getpaid_delete_subscription', $subscription );
202
+        // Fire a hook.
203
+        do_action( 'getpaid_delete_subscription', $subscription );
204 204
 
205
-		$subscription->set_id( 0 );
206
-	}
205
+        $subscription->set_id( 0 );
206
+    }
207 207
 
208
-	/*
208
+    /*
209 209
 	|--------------------------------------------------------------------------
210 210
 	| Additional Methods
211 211
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -12,49 +12,49 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 *
18
-	 */
19
-	public function __construct() {
20
-		add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 );
21
-		add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) );
22
-		add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) );
23
-		add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) );
24
-		add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) );
25
-
26
-	}
27
-
28
-	/**
29
-	 * Registers the reports page.
30
-	 *
31
-	 */
32
-	public function register_reports_page() {
33
-
34
-		add_submenu_page(
15
+    /**
16
+     * Class constructor.
17
+     *
18
+     */
19
+    public function __construct() {
20
+        add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 );
21
+        add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) );
22
+        add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) );
23
+        add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) );
24
+        add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) );
25
+
26
+    }
27
+
28
+    /**
29
+     * Registers the reports page.
30
+     *
31
+     */
32
+    public function register_reports_page() {
33
+
34
+        add_submenu_page(
35 35
             'wpinv',
36 36
             __( 'Reports', 'invoicing' ),
37 37
             __( 'Reports', 'invoicing' ),
38 38
             wpinv_get_capability(),
39 39
             'wpinv-reports',
40 40
             array( $this, 'display_reports_page' )
41
-		);
41
+        );
42 42
 
43
-	}
43
+    }
44 44
 
45
-	/**
46
-	 * Displays the reports page.
47
-	 *
48
-	 */
49
-	public function display_reports_page() {
45
+    /**
46
+     * Displays the reports page.
47
+     *
48
+     */
49
+    public function display_reports_page() {
50 50
 
51
-		// Prepare variables.
52
-		$tabs        = $this->get_tabs();
53
-		$current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
54
-		$current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports';
51
+        // Prepare variables.
52
+        $tabs        = $this->get_tabs();
53
+        $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
54
+        $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports';
55 55
 
56
-		// Display the current tab.
57
-		?>
56
+        // Display the current tab.
57
+        ?>
58 58
 
59 59
         <div class="wrap">
60 60
 
@@ -63,19 +63,19 @@  discard block
 block discarded – undo
63 63
 			<nav class="nav-tab-wrapper">
64 64
 
65 65
 				<?php
66
-					foreach( $tabs as $key => $label ) {
66
+                    foreach( $tabs as $key => $label ) {
67 67
 
68
-						$key   = sanitize_text_field( $key );
69
-						$label = sanitize_text_field( $label );
70
-						$class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab';
71
-						$url   = esc_url(
72
-							add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) )
73
-						);
68
+                        $key   = sanitize_text_field( $key );
69
+                        $label = sanitize_text_field( $label );
70
+                        $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab';
71
+                        $url   = esc_url(
72
+                            add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) )
73
+                        );
74 74
 
75
-						echo "\n\t\t\t<a href='$url' class='$class'>$label</a>";
75
+                        echo "\n\t\t\t<a href='$url' class='$class'>$label</a>";
76 76
 
77
-					}
78
-				?>
77
+                    }
78
+                ?>
79 79
 
80 80
 			</nav>
81 81
 
@@ -86,77 +86,77 @@  discard block
 block discarded – undo
86 86
         </div>
87 87
 		<?php
88 88
 
89
-			// Wordfence loads an unsupported version of chart js on our page.
90
-			wp_deregister_style( 'chart-js' );
91
-			wp_deregister_script( 'chart-js' );
92
-			wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
93
-			wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
94
-
95
-	}
96
-
97
-	/**
98
-	 * Retrieves reports page tabs.
99
-	 *
100
-	 * @return array
101
-	 */
102
-	public function get_tabs() {
103
-
104
-		$tabs = array(
105
-			'reports' => __( 'Reports', 'invoicing' ),
106
-			'export'  => __( 'Export', 'invoicing' ),
107
-		);
108
-
109
-		return apply_filters( 'getpaid_report_tabs', $tabs );
110
-	}
111
-
112
-	/**
113
-	 * Displays the reports tab.
114
-	 *
115
-	 */
116
-	public function display_reports_tab() {
117
-
118
-		$reports = new GetPaid_Reports_Report();
119
-		$reports->display();
120
-
121
-	}
122
-
123
-	/**
124
-	 * Displays the exports tab.
125
-	 *
126
-	 */
127
-	public function display_exports_tab() {
128
-
129
-		$exports = new GetPaid_Reports_Export();
130
-		$exports->display();
131
-
132
-	}
133
-
134
-	/**
135
-	 * Donwnloads a graph.
136
-	 *
137
-	 * @param array $args
138
-	 */
139
-	public function download_graph( $args ) {
140
-
141
-		if ( ! empty( $args['graph'] ) ) {
142
-			$downloader = new GetPaid_Graph_Downloader();
143
-			$downloader->download( $args['graph'] );
144
-		}
145
-
146
-	}
147
-
148
-	/**
149
-	 * Exports invoices.
150
-	 *
151
-	 * @param array $args
152
-	 */
153
-	public function export_invoices( $args ) {
154
-
155
-		if ( ! empty( $args['post_type'] ) ) {
156
-			$downloader = new GetPaid_Invoice_Exporter();
157
-			$downloader->export( $args['post_type'], $args );
158
-		}
159
-
160
-	}
89
+            // Wordfence loads an unsupported version of chart js on our page.
90
+            wp_deregister_style( 'chart-js' );
91
+            wp_deregister_script( 'chart-js' );
92
+            wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
93
+            wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
94
+
95
+    }
96
+
97
+    /**
98
+     * Retrieves reports page tabs.
99
+     *
100
+     * @return array
101
+     */
102
+    public function get_tabs() {
103
+
104
+        $tabs = array(
105
+            'reports' => __( 'Reports', 'invoicing' ),
106
+            'export'  => __( 'Export', 'invoicing' ),
107
+        );
108
+
109
+        return apply_filters( 'getpaid_report_tabs', $tabs );
110
+    }
111
+
112
+    /**
113
+     * Displays the reports tab.
114
+     *
115
+     */
116
+    public function display_reports_tab() {
117
+
118
+        $reports = new GetPaid_Reports_Report();
119
+        $reports->display();
120
+
121
+    }
122
+
123
+    /**
124
+     * Displays the exports tab.
125
+     *
126
+     */
127
+    public function display_exports_tab() {
128
+
129
+        $exports = new GetPaid_Reports_Export();
130
+        $exports->display();
131
+
132
+    }
133
+
134
+    /**
135
+     * Donwnloads a graph.
136
+     *
137
+     * @param array $args
138
+     */
139
+    public function download_graph( $args ) {
140
+
141
+        if ( ! empty( $args['graph'] ) ) {
142
+            $downloader = new GetPaid_Graph_Downloader();
143
+            $downloader->download( $args['graph'] );
144
+        }
145
+
146
+    }
147
+
148
+    /**
149
+     * Exports invoices.
150
+     *
151
+     * @param array $args
152
+     */
153
+    public function export_invoices( $args ) {
154
+
155
+        if ( ! empty( $args['post_type'] ) ) {
156
+            $downloader = new GetPaid_Invoice_Exporter();
157
+            $downloader->export( $args['post_type'], $args );
158
+        }
159
+
160
+    }
161 161
 
162 162
 }
Please login to merge, or discard this patch.
includes/class-getpaid-post-types.php 1 patch
Indentation   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -15,319 +15,319 @@
 block discarded – undo
15 15
 class GetPaid_Post_Types {
16 16
 
17 17
     /**
18
-	 * Hook in methods.
19
-	 */
20
-	public function __construct() {
21
-		add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 );
22
-		add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 );
23
-		add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) );
24
-		add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) );
25
-	}
18
+     * Hook in methods.
19
+     */
20
+    public function __construct() {
21
+        add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 );
22
+        add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 );
23
+        add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) );
24
+        add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) );
25
+    }
26 26
 
27
-	/**
28
-	 * Register core post types.
29
-	 */
30
-	public static function register_post_types() {
27
+    /**
28
+     * Register core post types.
29
+     */
30
+    public static function register_post_types() {
31 31
 
32
-		if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) {
33
-			return;
34
-		}
32
+        if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) {
33
+            return;
34
+        }
35 35
 
36
-		// Fires before registering post types.
37
-		do_action( 'getpaid_register_post_types' );
36
+        // Fires before registering post types.
37
+        do_action( 'getpaid_register_post_types' );
38 38
 
39
-		// Register item post type.
40
-		register_post_type(
41
-			'wpi_item',
42
-			apply_filters(
43
-				'wpinv_register_post_type_invoice_item',
44
-				array(
45
-					'labels'             => array(
46
-						'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
47
-						'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
48
-						'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
49
-						'name_admin_bar'     => _x( 'Item', 'add new on admin bar', 'invoicing' ),
50
-						'add_new'            => _x( 'Add New', 'Item', 'invoicing' ),
51
-						'add_new_item'       => __( 'Add New Item', 'invoicing' ),
52
-						'new_item'           => __( 'New Item', 'invoicing' ),
53
-						'edit_item'          => __( 'Edit Item', 'invoicing' ),
54
-						'view_item'          => __( 'View Item', 'invoicing' ),
55
-						'all_items'          => __( 'Items', 'invoicing' ),
56
-						'search_items'       => __( 'Search items', 'invoicing' ),
57
-						'parent_item_colon'  => __( 'Parent item:', 'invoicing' ),
58
-						'not_found'          => __( 'No items found.', 'invoicing' ),
59
-						'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
60
-					),
61
-					'description'           => __( 'This is where you can add new invoice items.', 'invoicing' ),
62
-					'public'                => false,
63
-					'has_archive'           => false,
64
-					'_builtin'              => false,
65
-					'show_ui'               => true,
66
-					'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
67
-					'show_in_nav_menus'     => false,
68
-					'supports'              => array( 'title', 'excerpt', 'thumbnail' ),
69
-					'rewrite'               => false,
70
-					'query_var'             => false,
71
-					'map_meta_cap'          => true,
72
-					'show_in_admin_bar'     => true,
73
-					'can_export'            => true,
74
-				)
75
-			)
76
-		);
39
+        // Register item post type.
40
+        register_post_type(
41
+            'wpi_item',
42
+            apply_filters(
43
+                'wpinv_register_post_type_invoice_item',
44
+                array(
45
+                    'labels'             => array(
46
+                        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
47
+                        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
48
+                        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
49
+                        'name_admin_bar'     => _x( 'Item', 'add new on admin bar', 'invoicing' ),
50
+                        'add_new'            => _x( 'Add New', 'Item', 'invoicing' ),
51
+                        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
52
+                        'new_item'           => __( 'New Item', 'invoicing' ),
53
+                        'edit_item'          => __( 'Edit Item', 'invoicing' ),
54
+                        'view_item'          => __( 'View Item', 'invoicing' ),
55
+                        'all_items'          => __( 'Items', 'invoicing' ),
56
+                        'search_items'       => __( 'Search items', 'invoicing' ),
57
+                        'parent_item_colon'  => __( 'Parent item:', 'invoicing' ),
58
+                        'not_found'          => __( 'No items found.', 'invoicing' ),
59
+                        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
60
+                    ),
61
+                    'description'           => __( 'This is where you can add new invoice items.', 'invoicing' ),
62
+                    'public'                => false,
63
+                    'has_archive'           => false,
64
+                    '_builtin'              => false,
65
+                    'show_ui'               => true,
66
+                    'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
67
+                    'show_in_nav_menus'     => false,
68
+                    'supports'              => array( 'title', 'excerpt', 'thumbnail' ),
69
+                    'rewrite'               => false,
70
+                    'query_var'             => false,
71
+                    'map_meta_cap'          => true,
72
+                    'show_in_admin_bar'     => true,
73
+                    'can_export'            => true,
74
+                )
75
+            )
76
+        );
77 77
 
78
-		// Register payment form post type.
79
-		register_post_type(
80
-			'wpi_payment_form',
81
-			apply_filters(
82
-				'wpinv_register_post_type_payment_form',
83
-				array(
84
-					'labels'             => array(
85
-						'name'               => _x( 'Payment Forms', 'post type general name', 'invoicing' ),
86
-						'singular_name'      => _x( 'Payment Form', 'post type singular name', 'invoicing' ),
87
-						'menu_name'          => _x( 'Payment Forms', 'admin menu', 'invoicing' ),
88
-						'name_admin_bar'     => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ),
89
-						'add_new'            => _x( 'Add New', 'Payment Form', 'invoicing' ),
90
-						'add_new_item'       => __( 'Add New Payment Form', 'invoicing' ),
91
-						'new_item'           => __( 'New Payment Form', 'invoicing' ),
92
-						'edit_item'          => __( 'Edit Payment Form', 'invoicing' ),
93
-						'view_item'          => __( 'View Payment Form', 'invoicing' ),
94
-						'all_items'          => __( 'Payment Forms', 'invoicing' ),
95
-						'search_items'       => __( 'Search Payment Forms', 'invoicing' ),
96
-						'parent_item_colon'  => __( 'Parent Payment Forms:', 'invoicing' ),
97
-						'not_found'          => __( 'No payment forms found.', 'invoicing' ),
98
-						'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' )
99
-					),
100
-					'description'        => __( 'Add new payment forms.', 'invoicing' ),
101
-					'public'             => false,
102
-					'show_ui'            => true,
103
-					'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true,
104
-					'show_in_nav_menus'  => false,
105
-					'query_var'          => false,
106
-					'rewrite'            => true,
107
-					'map_meta_cap'       => true,
108
-					'has_archive'        => false,
109
-					'hierarchical'       => false,
110
-					'menu_position'      => null,
111
-					'supports'           => array( 'title' ),
112
-					'menu_icon'          => 'dashicons-media-form',
113
-				)
114
-			)
115
-		);
78
+        // Register payment form post type.
79
+        register_post_type(
80
+            'wpi_payment_form',
81
+            apply_filters(
82
+                'wpinv_register_post_type_payment_form',
83
+                array(
84
+                    'labels'             => array(
85
+                        'name'               => _x( 'Payment Forms', 'post type general name', 'invoicing' ),
86
+                        'singular_name'      => _x( 'Payment Form', 'post type singular name', 'invoicing' ),
87
+                        'menu_name'          => _x( 'Payment Forms', 'admin menu', 'invoicing' ),
88
+                        'name_admin_bar'     => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ),
89
+                        'add_new'            => _x( 'Add New', 'Payment Form', 'invoicing' ),
90
+                        'add_new_item'       => __( 'Add New Payment Form', 'invoicing' ),
91
+                        'new_item'           => __( 'New Payment Form', 'invoicing' ),
92
+                        'edit_item'          => __( 'Edit Payment Form', 'invoicing' ),
93
+                        'view_item'          => __( 'View Payment Form', 'invoicing' ),
94
+                        'all_items'          => __( 'Payment Forms', 'invoicing' ),
95
+                        'search_items'       => __( 'Search Payment Forms', 'invoicing' ),
96
+                        'parent_item_colon'  => __( 'Parent Payment Forms:', 'invoicing' ),
97
+                        'not_found'          => __( 'No payment forms found.', 'invoicing' ),
98
+                        'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' )
99
+                    ),
100
+                    'description'        => __( 'Add new payment forms.', 'invoicing' ),
101
+                    'public'             => false,
102
+                    'show_ui'            => true,
103
+                    'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true,
104
+                    'show_in_nav_menus'  => false,
105
+                    'query_var'          => false,
106
+                    'rewrite'            => true,
107
+                    'map_meta_cap'       => true,
108
+                    'has_archive'        => false,
109
+                    'hierarchical'       => false,
110
+                    'menu_position'      => null,
111
+                    'supports'           => array( 'title' ),
112
+                    'menu_icon'          => 'dashicons-media-form',
113
+                )
114
+            )
115
+        );
116 116
 
117
-		// Register invoice post type.
118
-		register_post_type(
119
-			'wpi_invoice',
120
-			apply_filters(
121
-				'wpinv_register_post_type_invoice',
122
-				array(
123
-					'labels'                 => array(
124
-						'name'                  => __( 'Invoices', 'invoicing' ),
125
-						'singular_name'         => __( 'Invoice', 'invoicing' ),
126
-						'all_items'             => __( 'Invoices', 'invoicing' ),
127
-						'menu_name'             => _x( 'Invoices', 'Admin menu name', 'invoicing' ),
128
-						'add_new'               => __( 'Add New', 'invoicing' ),
129
-						'add_new_item'          => __( 'Add new invoice', 'invoicing' ),
130
-						'edit'                  => __( 'Edit', 'invoicing' ),
131
-						'edit_item'             => __( 'Edit invoice', 'invoicing' ),
132
-						'new_item'              => __( 'New invoice', 'invoicing' ),
133
-						'view_item'             => __( 'View invoice', 'invoicing' ),
134
-						'view_items'            => __( 'View Invoices', 'invoicing' ),
135
-						'search_items'          => __( 'Search invoices', 'invoicing' ),
136
-						'not_found'             => __( 'No invoices found', 'invoicing' ),
137
-						'not_found_in_trash'    => __( 'No invoices found in trash', 'invoicing' ),
138
-						'parent'                => __( 'Parent invoice', 'invoicing' ),
139
-						'featured_image'        => __( 'Invoice image', 'invoicing' ),
140
-						'set_featured_image'    => __( 'Set invoice image', 'invoicing' ),
141
-						'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ),
142
-						'use_featured_image'    => __( 'Use as invoice image', 'invoicing' ),
143
-						'insert_into_item'      => __( 'Insert into invoice', 'invoicing' ),
144
-						'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ),
145
-						'filter_items_list'     => __( 'Filter invoices', 'invoicing' ),
146
-						'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ),
147
-						'items_list'            => __( 'Invoices list', 'invoicing' ),
148
-					),
149
-					'description'           => __( 'This is where invoices are stored.', 'invoicing' ),
150
-					'public'                => true,
151
-					'has_archive'           => false,
152
-					'publicly_queryable'    => true,
153
-        			'exclude_from_search'   => true,
154
-        			'show_ui'               => true,
155
-					'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
156
-					'show_in_nav_menus'     => false,
157
-					'supports'              => array( 'title', 'author', 'excerpt'  ),
158
-					'rewrite'               => array(
159
-						'slug'              => 'invoice',
160
-						'with_front'        => false,
161
-					),
162
-					'query_var'             => false,
163
-					'map_meta_cap'          => true,
164
-					'show_in_admin_bar'     => true,
165
-					'can_export'            => true,
166
-					'hierarchical'          => false,
167
-					'menu_position'         => null,
168
-					'menu_icon'             => 'dashicons-media-spreadsheet',
169
-				)
170
-			)
171
-		);
117
+        // Register invoice post type.
118
+        register_post_type(
119
+            'wpi_invoice',
120
+            apply_filters(
121
+                'wpinv_register_post_type_invoice',
122
+                array(
123
+                    'labels'                 => array(
124
+                        'name'                  => __( 'Invoices', 'invoicing' ),
125
+                        'singular_name'         => __( 'Invoice', 'invoicing' ),
126
+                        'all_items'             => __( 'Invoices', 'invoicing' ),
127
+                        'menu_name'             => _x( 'Invoices', 'Admin menu name', 'invoicing' ),
128
+                        'add_new'               => __( 'Add New', 'invoicing' ),
129
+                        'add_new_item'          => __( 'Add new invoice', 'invoicing' ),
130
+                        'edit'                  => __( 'Edit', 'invoicing' ),
131
+                        'edit_item'             => __( 'Edit invoice', 'invoicing' ),
132
+                        'new_item'              => __( 'New invoice', 'invoicing' ),
133
+                        'view_item'             => __( 'View invoice', 'invoicing' ),
134
+                        'view_items'            => __( 'View Invoices', 'invoicing' ),
135
+                        'search_items'          => __( 'Search invoices', 'invoicing' ),
136
+                        'not_found'             => __( 'No invoices found', 'invoicing' ),
137
+                        'not_found_in_trash'    => __( 'No invoices found in trash', 'invoicing' ),
138
+                        'parent'                => __( 'Parent invoice', 'invoicing' ),
139
+                        'featured_image'        => __( 'Invoice image', 'invoicing' ),
140
+                        'set_featured_image'    => __( 'Set invoice image', 'invoicing' ),
141
+                        'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ),
142
+                        'use_featured_image'    => __( 'Use as invoice image', 'invoicing' ),
143
+                        'insert_into_item'      => __( 'Insert into invoice', 'invoicing' ),
144
+                        'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ),
145
+                        'filter_items_list'     => __( 'Filter invoices', 'invoicing' ),
146
+                        'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ),
147
+                        'items_list'            => __( 'Invoices list', 'invoicing' ),
148
+                    ),
149
+                    'description'           => __( 'This is where invoices are stored.', 'invoicing' ),
150
+                    'public'                => true,
151
+                    'has_archive'           => false,
152
+                    'publicly_queryable'    => true,
153
+                    'exclude_from_search'   => true,
154
+                    'show_ui'               => true,
155
+                    'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
156
+                    'show_in_nav_menus'     => false,
157
+                    'supports'              => array( 'title', 'author', 'excerpt'  ),
158
+                    'rewrite'               => array(
159
+                        'slug'              => 'invoice',
160
+                        'with_front'        => false,
161
+                    ),
162
+                    'query_var'             => false,
163
+                    'map_meta_cap'          => true,
164
+                    'show_in_admin_bar'     => true,
165
+                    'can_export'            => true,
166
+                    'hierarchical'          => false,
167
+                    'menu_position'         => null,
168
+                    'menu_icon'             => 'dashicons-media-spreadsheet',
169
+                )
170
+            )
171
+        );
172 172
 
173
-		// Register discount post type.
174
-		register_post_type(
175
-			'wpi_discount',
176
-			apply_filters(
177
-				'wpinv_register_post_type_discount',
178
-				array(
179
-					'labels'                 => array(
180
-						'name'                  => __( 'Discounts', 'invoicing' ),
181
-						'singular_name'         => __( 'Discount', 'invoicing' ),
182
-						'all_items'             => __( 'Discounts', 'invoicing' ),
183
-						'menu_name'             => _x( 'Discounts', 'Admin menu name', 'invoicing' ),
184
-						'add_new'               => __( 'Add New', 'invoicing' ),
185
-						'add_new_item'          => __( 'Add new discount', 'invoicing' ),
186
-						'edit'                  => __( 'Edit', 'invoicing' ),
187
-						'edit_item'             => __( 'Edit discount', 'invoicing' ),
188
-						'new_item'              => __( 'New discount', 'invoicing' ),
189
-						'view_item'             => __( 'View discount', 'invoicing' ),
190
-						'view_items'            => __( 'View Discounts', 'invoicing' ),
191
-						'search_items'          => __( 'Search discounts', 'invoicing' ),
192
-						'not_found'             => __( 'No discounts found', 'invoicing' ),
193
-						'not_found_in_trash'    => __( 'No discounts found in trash', 'invoicing' ),
194
-						'parent'                => __( 'Parent discount', 'invoicing' ),
195
-						'featured_image'        => __( 'Discount image', 'invoicing' ),
196
-						'set_featured_image'    => __( 'Set discount image', 'invoicing' ),
197
-						'remove_featured_image' => __( 'Remove discount image', 'invoicing' ),
198
-						'use_featured_image'    => __( 'Use as discount image', 'invoicing' ),
199
-						'insert_into_item'      => __( 'Insert into discount', 'invoicing' ),
200
-						'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ),
201
-						'filter_items_list'     => __( 'Filter discounts', 'invoicing' ),
202
-						'items_list_navigation' => __( 'Discount navigation', 'invoicing' ),
203
-						'items_list'            => __( 'Discounts list', 'invoicing' ),
204
-					),
205
-					'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
206
-					'public'             => false,
207
-					'can_export'         => true,
208
-					'_builtin'           => false,
209
-					'publicly_queryable' => false,
210
-					'exclude_from_search'=> true,
211
-					'show_ui'            => true,
212
-					'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
213
-					'query_var'          => false,
214
-					'rewrite'            => false,
215
-					'map_meta_cap'       => true,
216
-					'has_archive'        => false,
217
-					'hierarchical'       => false,
218
-					'supports'           => array( 'title', 'excerpt' ),
219
-					'show_in_nav_menus'  => false,
220
-					'show_in_admin_bar'  => true,
221
-					'menu_position'      => null,
222
-				)
223
-			)
224
-		);
173
+        // Register discount post type.
174
+        register_post_type(
175
+            'wpi_discount',
176
+            apply_filters(
177
+                'wpinv_register_post_type_discount',
178
+                array(
179
+                    'labels'                 => array(
180
+                        'name'                  => __( 'Discounts', 'invoicing' ),
181
+                        'singular_name'         => __( 'Discount', 'invoicing' ),
182
+                        'all_items'             => __( 'Discounts', 'invoicing' ),
183
+                        'menu_name'             => _x( 'Discounts', 'Admin menu name', 'invoicing' ),
184
+                        'add_new'               => __( 'Add New', 'invoicing' ),
185
+                        'add_new_item'          => __( 'Add new discount', 'invoicing' ),
186
+                        'edit'                  => __( 'Edit', 'invoicing' ),
187
+                        'edit_item'             => __( 'Edit discount', 'invoicing' ),
188
+                        'new_item'              => __( 'New discount', 'invoicing' ),
189
+                        'view_item'             => __( 'View discount', 'invoicing' ),
190
+                        'view_items'            => __( 'View Discounts', 'invoicing' ),
191
+                        'search_items'          => __( 'Search discounts', 'invoicing' ),
192
+                        'not_found'             => __( 'No discounts found', 'invoicing' ),
193
+                        'not_found_in_trash'    => __( 'No discounts found in trash', 'invoicing' ),
194
+                        'parent'                => __( 'Parent discount', 'invoicing' ),
195
+                        'featured_image'        => __( 'Discount image', 'invoicing' ),
196
+                        'set_featured_image'    => __( 'Set discount image', 'invoicing' ),
197
+                        'remove_featured_image' => __( 'Remove discount image', 'invoicing' ),
198
+                        'use_featured_image'    => __( 'Use as discount image', 'invoicing' ),
199
+                        'insert_into_item'      => __( 'Insert into discount', 'invoicing' ),
200
+                        'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ),
201
+                        'filter_items_list'     => __( 'Filter discounts', 'invoicing' ),
202
+                        'items_list_navigation' => __( 'Discount navigation', 'invoicing' ),
203
+                        'items_list'            => __( 'Discounts list', 'invoicing' ),
204
+                    ),
205
+                    'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
206
+                    'public'             => false,
207
+                    'can_export'         => true,
208
+                    '_builtin'           => false,
209
+                    'publicly_queryable' => false,
210
+                    'exclude_from_search'=> true,
211
+                    'show_ui'            => true,
212
+                    'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
213
+                    'query_var'          => false,
214
+                    'rewrite'            => false,
215
+                    'map_meta_cap'       => true,
216
+                    'has_archive'        => false,
217
+                    'hierarchical'       => false,
218
+                    'supports'           => array( 'title', 'excerpt' ),
219
+                    'show_in_nav_menus'  => false,
220
+                    'show_in_admin_bar'  => true,
221
+                    'menu_position'      => null,
222
+                )
223
+            )
224
+        );
225 225
 
226
-		do_action( 'getpaid_after_register_post_types' );
227
-	}
226
+        do_action( 'getpaid_after_register_post_types' );
227
+    }
228 228
 
229
-	/**
230
-	 * Register our custom post statuses.
231
-	 */
232
-	public static function register_post_status() {
229
+    /**
230
+     * Register our custom post statuses.
231
+     */
232
+    public static function register_post_status() {
233 233
 
234
-		$invoice_statuses = apply_filters(
235
-			'getpaid_register_invoice_post_statuses',
236
-			array(
234
+        $invoice_statuses = apply_filters(
235
+            'getpaid_register_invoice_post_statuses',
236
+            array(
237 237
 
238
-				'wpi-pending' => array(
239
-					'label'                     => _x( 'Pending Payment', 'Invoice status', 'invoicing' ),
240
-        			'public'                    => true,
241
-        			'exclude_from_search'       => true,
242
-        			'show_in_admin_all_list'    => true,
243
-					'show_in_admin_status_list' => true,
244
-					/* translators: %s: number of invoices */
245
-        			'label_count'               => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' )
246
-				),
238
+                'wpi-pending' => array(
239
+                    'label'                     => _x( 'Pending Payment', 'Invoice status', 'invoicing' ),
240
+                    'public'                    => true,
241
+                    'exclude_from_search'       => true,
242
+                    'show_in_admin_all_list'    => true,
243
+                    'show_in_admin_status_list' => true,
244
+                    /* translators: %s: number of invoices */
245
+                    'label_count'               => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' )
246
+                ),
247 247
 
248
-				'wpi-processing' => array(
249
-					'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
250
-        			'public'                    => true,
251
-        			'exclude_from_search'       => true,
252
-        			'show_in_admin_all_list'    => true,
253
-					'show_in_admin_status_list' => true,
254
-					/* translators: %s: number of invoices */
255
-        			'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
256
-				),
248
+                'wpi-processing' => array(
249
+                    'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
250
+                    'public'                    => true,
251
+                    'exclude_from_search'       => true,
252
+                    'show_in_admin_all_list'    => true,
253
+                    'show_in_admin_status_list' => true,
254
+                    /* translators: %s: number of invoices */
255
+                    'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
256
+                ),
257 257
 
258
-				'wpi-onhold' => array(
259
-					'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
260
-        			'public'                    => true,
261
-        			'exclude_from_search'       => true,
262
-        			'show_in_admin_all_list'    => true,
263
-					'show_in_admin_status_list' => true,
264
-					/* translators: %s: number of invoices */
265
-        			'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
266
-				),
258
+                'wpi-onhold' => array(
259
+                    'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
260
+                    'public'                    => true,
261
+                    'exclude_from_search'       => true,
262
+                    'show_in_admin_all_list'    => true,
263
+                    'show_in_admin_status_list' => true,
264
+                    /* translators: %s: number of invoices */
265
+                    'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
266
+                ),
267 267
 
268
-				'wpi-cancelled' => array(
269
-					'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
270
-        			'public'                    => true,
271
-        			'exclude_from_search'       => true,
272
-        			'show_in_admin_all_list'    => true,
273
-					'show_in_admin_status_list' => true,
274
-					/* translators: %s: number of invoices */
275
-        			'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
276
-				),
268
+                'wpi-cancelled' => array(
269
+                    'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
270
+                    'public'                    => true,
271
+                    'exclude_from_search'       => true,
272
+                    'show_in_admin_all_list'    => true,
273
+                    'show_in_admin_status_list' => true,
274
+                    /* translators: %s: number of invoices */
275
+                    'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
276
+                ),
277 277
 
278
-				'wpi-refunded' => array(
279
-					'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
280
-        			'public'                    => true,
281
-        			'exclude_from_search'       => true,
282
-        			'show_in_admin_all_list'    => true,
283
-					'show_in_admin_status_list' => true,
284
-					/* translators: %s: number of invoices */
285
-        			'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
286
-				),
278
+                'wpi-refunded' => array(
279
+                    'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
280
+                    'public'                    => true,
281
+                    'exclude_from_search'       => true,
282
+                    'show_in_admin_all_list'    => true,
283
+                    'show_in_admin_status_list' => true,
284
+                    /* translators: %s: number of invoices */
285
+                    'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
286
+                ),
287 287
 
288
-				'wpi-failed' => array(
289
-					'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
290
-        			'public'                    => true,
291
-        			'exclude_from_search'       => true,
292
-        			'show_in_admin_all_list'    => true,
293
-					'show_in_admin_status_list' => true,
294
-					/* translators: %s: number of invoices */
295
-        			'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
296
-				),
288
+                'wpi-failed' => array(
289
+                    'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
290
+                    'public'                    => true,
291
+                    'exclude_from_search'       => true,
292
+                    'show_in_admin_all_list'    => true,
293
+                    'show_in_admin_status_list' => true,
294
+                    /* translators: %s: number of invoices */
295
+                    'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
296
+                ),
297 297
 
298
-				'wpi-renewal' => array(
299
-					'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
300
-        			'public'                    => true,
301
-        			'exclude_from_search'       => true,
302
-        			'show_in_admin_all_list'    => true,
303
-					'show_in_admin_status_list' => true,
304
-					/* translators: %s: number of invoices */
305
-        			'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
306
-				)
307
-			)
308
-		);
298
+                'wpi-renewal' => array(
299
+                    'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
300
+                    'public'                    => true,
301
+                    'exclude_from_search'       => true,
302
+                    'show_in_admin_all_list'    => true,
303
+                    'show_in_admin_status_list' => true,
304
+                    /* translators: %s: number of invoices */
305
+                    'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
306
+                )
307
+            )
308
+        );
309 309
 
310
-		foreach ( $invoice_statuses as $invoice_statuse => $args ) {
311
-			register_post_status( $invoice_statuse, $args );
312
-		}
313
-	}
310
+        foreach ( $invoice_statuses as $invoice_statuse => $args ) {
311
+            register_post_status( $invoice_statuse, $args );
312
+        }
313
+    }
314 314
 
315
-	/**
316
-	 * Flush rewrite rules.
317
-	 */
318
-	public static function flush_rewrite_rules() {
319
-		flush_rewrite_rules();
320
-	}
315
+    /**
316
+     * Flush rewrite rules.
317
+     */
318
+    public static function flush_rewrite_rules() {
319
+        flush_rewrite_rules();
320
+    }
321 321
 
322
-	/**
323
-	 * Flush rules to prevent 404.
324
-	 *
325
-	 */
326
-	public static function maybe_flush_rewrite_rules() {
327
-		if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) {
328
-			update_option( 'getpaid_flushed_rewrite_rules', '1' );
329
-			self::flush_rewrite_rules();
330
-		}
331
-	}
322
+    /**
323
+     * Flush rules to prevent 404.
324
+     *
325
+     */
326
+    public static function maybe_flush_rewrite_rules() {
327
+        if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) {
328
+            update_option( 'getpaid_flushed_rewrite_rules', '1' );
329
+            self::flush_rewrite_rules();
330
+        }
331
+    }
332 332
 
333 333
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 1 patch
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -12,267 +12,267 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
21
-
22 15
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
39 21
 
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-
45
-		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
22
+    /**
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
47 26
 
48
-		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type );
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
50 29
 
51
-		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
53 32
 
54
-		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
-		}
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
58 35
 
59
-	}
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
60 39
 
61
-	/**
62
-	 * Register core metaboxes.
63
-	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type ) {
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
65 44
 
66
-		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
45
+        // For invoices...
46
+        self::add_invoice_meta_boxes( $post_type, $post );
68 47
 
69
-			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
48
+        // For payment forms.
49
+        self::add_payment_form_meta_boxes( $post_type );
71 50
 
72
-			// Payment form information.
73
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
51
+        // For invoice items.
52
+        self::add_item_meta_boxes( $post_type );
74 53
 
75
-		}
54
+        // For invoice discounts.
55
+        if ( $post_type == 'wpi_discount' ) {
56
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
+        }
76 58
 
77
-	}
59
+    }
78 60
 
79
-	/**
80
-	 * Register core metaboxes.
81
-	 */
82
-	protected static function add_item_meta_boxes( $post_type ) {
61
+    /**
62
+     * Register core metaboxes.
63
+     */
64
+    protected static function add_payment_form_meta_boxes( $post_type ) {
83 65
 
84
-		if ( $post_type == 'wpi_item' ) {
66
+        // For payment forms.
67
+        if ( $post_type == 'wpi_payment_form' ) {
85 68
 
86
-			// Item details.
87
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
69
+            // Design payment form.
70
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
88 71
 
89
-			// If taxes are enabled, register the tax metabox.
90
-			if ( wpinv_use_taxes() ) {
91
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
-			}
72
+            // Payment form information.
73
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
93 74
 
94
-			// Item info.
95
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
75
+        }
96 76
 
97
-		}
77
+    }
98 78
 
99
-	}
79
+    /**
80
+     * Register core metaboxes.
81
+     */
82
+    protected static function add_item_meta_boxes( $post_type ) {
100 83
 
101
-	/**
102
-	 * Register invoice metaboxes.
103
-	 */
104
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
84
+        if ( $post_type == 'wpi_item' ) {
105 85
 
106
-		// For invoices...
107
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
-			$invoice = new WPInv_Invoice( $post );
86
+            // Item details.
87
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
109 88
 
110
-			// Resend invoice.
111
-			if ( ! $invoice->is_draft() ) {
89
+            // If taxes are enabled, register the tax metabox.
90
+            if ( wpinv_use_taxes() ) {
91
+                add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
+            }
112 93
 
113
-				add_meta_box(
114
-					'wpinv-mb-resend-invoice',
115
-					sprintf(
116
-						__( 'Resend %s', 'invoicing' ),
117
-						ucfirst( $invoice->get_invoice_quote_type() )
118
-					),
119
-					'GetPaid_Meta_Box_Resend_Invoice::output',
120
-					$post_type,
121
-					'side',
122
-					'low'
123
-				);
94
+            // Item info.
95
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
124 96
 
125
-			}
97
+        }
126 98
 
127
-			// Subscriptions.
128
-			$subscription = getpaid_get_invoice_subscription( $invoice );
129
-			if ( ! empty( $subscription ) ) {
130
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
131
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
132
-			}
133
-
134
-			// Invoice details.
135
-			add_meta_box(
136
-				'wpinv-details',
137
-				sprintf(
138
-					__( '%s Details', 'invoicing' ),
139
-					ucfirst( $invoice->get_invoice_quote_type() )
140
-				),
141
-				'GetPaid_Meta_Box_Invoice_Details::output',
142
-				$post_type,
143
-				'side'
144
-			);
145
-
146
-			// Payment details.
147
-			if ( ! $invoice->is_draft() ) {
148
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
149
-			}
99
+    }
150 100
 
151
-			// Billing details.
152
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
101
+    /**
102
+     * Register invoice metaboxes.
103
+     */
104
+    protected static function add_invoice_meta_boxes( $post_type, $post ) {
105
+
106
+        // For invoices...
107
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
+            $invoice = new WPInv_Invoice( $post );
109
+
110
+            // Resend invoice.
111
+            if ( ! $invoice->is_draft() ) {
112
+
113
+                add_meta_box(
114
+                    'wpinv-mb-resend-invoice',
115
+                    sprintf(
116
+                        __( 'Resend %s', 'invoicing' ),
117
+                        ucfirst( $invoice->get_invoice_quote_type() )
118
+                    ),
119
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
120
+                    $post_type,
121
+                    'side',
122
+                    'low'
123
+                );
124
+
125
+            }
126
+
127
+            // Subscriptions.
128
+            $subscription = getpaid_get_invoice_subscription( $invoice );
129
+            if ( ! empty( $subscription ) ) {
130
+                add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
131
+                add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
132
+            }
133
+
134
+            // Invoice details.
135
+            add_meta_box(
136
+                'wpinv-details',
137
+                sprintf(
138
+                    __( '%s Details', 'invoicing' ),
139
+                    ucfirst( $invoice->get_invoice_quote_type() )
140
+                ),
141
+                'GetPaid_Meta_Box_Invoice_Details::output',
142
+                $post_type,
143
+                'side'
144
+            );
145
+
146
+            // Payment details.
147
+            if ( ! $invoice->is_draft() ) {
148
+                add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
149
+            }
150
+
151
+            // Billing details.
152
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
153 153
 			
154
-			// Invoice items.
155
-			add_meta_box(
156
-				'wpinv-items',
157
-				sprintf(
158
-					__( '%s Items', 'invoicing' ),
159
-					ucfirst( $invoice->get_invoice_quote_type() )
160
-				),
161
-				'GetPaid_Meta_Box_Invoice_Items::output',
162
-				$post_type,
163
-				'normal',
164
-				'high'
165
-			);
154
+            // Invoice items.
155
+            add_meta_box(
156
+                'wpinv-items',
157
+                sprintf(
158
+                    __( '%s Items', 'invoicing' ),
159
+                    ucfirst( $invoice->get_invoice_quote_type() )
160
+                ),
161
+                'GetPaid_Meta_Box_Invoice_Items::output',
162
+                $post_type,
163
+                'normal',
164
+                'high'
165
+            );
166 166
 			
167
-			// Invoice notes.
168
-			add_meta_box(
169
-				'wpinv-notes',
170
-				sprintf(
171
-					__( '%s Notes', 'invoicing' ),
172
-					ucfirst( $invoice->get_invoice_quote_type() )
173
-				),
174
-				'WPInv_Meta_Box_Notes::output',
175
-				$post_type,
176
-				'side',
177
-				'low'
178
-			);
179
-
180
-			// Shipping Address.
181
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
182
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
183
-			}
184
-
185
-			// Payment form information.
186
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
187
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
188
-			}
189
-
190
-		}
191
-
192
-	}
193
-
194
-	/**
195
-	 * Remove some metaboxes.
196
-	 */
197
-	public static function remove_meta_boxes() {
198
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
199
-	}
200
-
201
-	/**
202
-	 * Rename other metaboxes.
203
-	 */
204
-	public static function rename_meta_boxes() {
167
+            // Invoice notes.
168
+            add_meta_box(
169
+                'wpinv-notes',
170
+                sprintf(
171
+                    __( '%s Notes', 'invoicing' ),
172
+                    ucfirst( $invoice->get_invoice_quote_type() )
173
+                ),
174
+                'WPInv_Meta_Box_Notes::output',
175
+                $post_type,
176
+                'side',
177
+                'low'
178
+            );
179
+
180
+            // Shipping Address.
181
+            if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
182
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
183
+            }
184
+
185
+            // Payment form information.
186
+            if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
187
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
188
+            }
189
+
190
+        }
191
+
192
+    }
193
+
194
+    /**
195
+     * Remove some metaboxes.
196
+     */
197
+    public static function remove_meta_boxes() {
198
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
199
+    }
200
+
201
+    /**
202
+     * Rename other metaboxes.
203
+     */
204
+    public static function rename_meta_boxes() {
205 205
 		
206
-	}
207
-
208
-	/**
209
-	 * Check if we're saving, then trigger an action based on the post type.
210
-	 *
211
-	 * @param  int    $post_id Post ID.
212
-	 * @param  object $post Post object.
213
-	 */
214
-	public static function save_meta_boxes( $post_id, $post ) {
215
-		$post_id = absint( $post_id );
216
-		$data    = wp_unslash( $_POST );
217
-
218
-		// Do not save for ajax requests.
219
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
220
-			return;
221
-		}
222
-
223
-		// $post_id and $post are required
224
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
225
-			return;
226
-		}
227
-
228
-		// Dont' save meta boxes for revisions or autosaves.
229
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
230
-			return;
231
-		}
232
-
233
-		// Check the nonce.
234
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
235
-			return;
236
-		}
237
-
238
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
239
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
240
-			return;
241
-		}
242
-
243
-		// Check user has permission to edit.
244
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
245
-			return;
246
-		}
247
-
248
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
249
-
250
-			// We need this save event to run once to avoid potential endless loops.
251
-			self::$saved_meta_boxes = true;
252
-
253
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
254
-
255
-		}
256
-
257
-		// Ensure this is our post type.
258
-		$post_types_map = array(
259
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
260
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
261
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
262
-		);
263
-
264
-		// Is this our post type?
265
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
266
-			return;
267
-		}
268
-
269
-		// We need this save event to run once to avoid potential endless loops.
270
-		self::$saved_meta_boxes = true;
206
+    }
207
+
208
+    /**
209
+     * Check if we're saving, then trigger an action based on the post type.
210
+     *
211
+     * @param  int    $post_id Post ID.
212
+     * @param  object $post Post object.
213
+     */
214
+    public static function save_meta_boxes( $post_id, $post ) {
215
+        $post_id = absint( $post_id );
216
+        $data    = wp_unslash( $_POST );
217
+
218
+        // Do not save for ajax requests.
219
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
220
+            return;
221
+        }
222
+
223
+        // $post_id and $post are required
224
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
225
+            return;
226
+        }
227
+
228
+        // Dont' save meta boxes for revisions or autosaves.
229
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
230
+            return;
231
+        }
232
+
233
+        // Check the nonce.
234
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
235
+            return;
236
+        }
237
+
238
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
239
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
240
+            return;
241
+        }
242
+
243
+        // Check user has permission to edit.
244
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
245
+            return;
246
+        }
247
+
248
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
249
+
250
+            // We need this save event to run once to avoid potential endless loops.
251
+            self::$saved_meta_boxes = true;
252
+
253
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
254
+
255
+        }
256
+
257
+        // Ensure this is our post type.
258
+        $post_types_map = array(
259
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
260
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
261
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
262
+        );
263
+
264
+        // Is this our post type?
265
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
266
+            return;
267
+        }
268
+
269
+        // We need this save event to run once to avoid potential endless loops.
270
+        self::$saved_meta_boxes = true;
271 271
 		
272
-		// Save the post.
273
-		$class = $post_types_map[ $post->post_type ];
274
-		$class::save( $post_id, $_POST, $post );
272
+        // Save the post.
273
+        $class = $post_types_map[ $post->post_type ];
274
+        $class::save( $post_id, $_POST, $post );
275 275
 
276
-	}
276
+    }
277 277
 
278 278
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-manual-gateway.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'manual';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'addons' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
34
-	public $order = 11;
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34
+    public $order = 11;
35 35
 
36 36
     /**
37
-	 * Class constructor.
38
-	 */
39
-	public function __construct() {
37
+     * Class constructor.
38
+     */
39
+    public function __construct() {
40 40
         parent::__construct();
41 41
 
42 42
         $this->title        = __( 'Test Gateway', 'invoicing' );
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
     }
47 47
 
48 48
     /**
49
-	 * Process Payment.
50
-	 *
51
-	 *
52
-	 * @param WPInv_Invoice $invoice Invoice.
53
-	 * @param array $submission_data Posted checkout fields.
54
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
-	 * @return array
56
-	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
49
+     * Process Payment.
50
+     *
51
+     *
52
+     * @param WPInv_Invoice $invoice Invoice.
53
+     * @param array $submission_data Posted checkout fields.
54
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
+     * @return array
56
+     */
57
+    public function process_payment( $invoice, $submission_data, $submission ) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
@@ -68,13 +68,13 @@  discard block
 block discarded – undo
68 68
     }
69 69
 
70 70
     /**
71
-	 * (Maybe) renews a manual subscription profile.
72
-	 *
73
-	 *
74
-	 * @param bool $should_expire
71
+     * (Maybe) renews a manual subscription profile.
72
+     *
73
+     *
74
+     * @param bool $should_expire
75 75
      * @param WPInv_Subscription $subscription
76
-	 */
77
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
76
+     */
77
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
78 78
 
79 79
         // Ensure its our subscription && it's active.
80 80
         if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -102,13 +102,13 @@  discard block
 block discarded – undo
102 102
     }
103 103
 
104 104
     /**
105
-	 * Processes invoice addons.
106
-	 *
107
-	 * @param WPInv_Invoice $invoice
108
-	 * @param GetPaid_Form_Item[] $items
109
-	 * @return WPInv_Invoice
110
-	 */
111
-	public function process_addons( $invoice, $items ) {
105
+     * Processes invoice addons.
106
+     *
107
+     * @param WPInv_Invoice $invoice
108
+     * @param GetPaid_Form_Item[] $items
109
+     * @return WPInv_Invoice
110
+     */
111
+    public function process_addons( $invoice, $items ) {
112 112
 
113 113
         foreach ( $items as $item ) {
114 114
             $invoice->add_item( $item );
Please login to merge, or discard this patch.