Passed
Push — master ( c5d98b...02cd26 )
by Stiofan
04:53
created
includes/data/default-payment-form.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @version 1.0.19
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 return array(
14 14
 
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
         'placeholder' => '[email protected]',
18 18
         'value'       => '',
19
-        'label'       => __( 'Billing Email', 'invoicing' ),
19
+        'label'       => __('Billing Email', 'invoicing'),
20 20
         'description' => '',
21 21
         'required'    => true,
22 22
         'id'          => 'mmdwqzpox',
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
             array(
35 35
                 'placeholder'  => 'Jon',
36 36
                 'value'        => '',
37
-                'label'        => __( 'First Name', 'invoicing' ),
37
+                'label'        => __('First Name', 'invoicing'),
38 38
                 'description'  => '',
39 39
                 'required'     => false,
40 40
                 'visible'      => true,
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             array(
45 45
                 'placeholder'  => 'Snow',
46 46
                 'value'        => '',
47
-                'label'        => __( 'Last Name', 'invoicing' ),
47
+                'label'        => __('Last Name', 'invoicing'),
48 48
                 'description'  => '',
49 49
                 'required'     => false,
50 50
                 'visible'      => true,
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             array(
55 55
                 'placeholder'  => '',
56 56
                 'value'        => '',
57
-                'label'        => __( 'Address', 'invoicing' ),
57
+                'label'        => __('Address', 'invoicing'),
58 58
                 'description'  => '',
59 59
                 'required'     => false,
60 60
                 'visible'      => true,
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
             array(
65 65
                 'placeholder'  => '',
66 66
                 'value'        => '',
67
-                'label'        => __( 'City', 'invoicing' ),
67
+                'label'        => __('City', 'invoicing'),
68 68
                 'description'  => '',
69 69
                 'required'     => false,
70 70
                 'visible'      => true,
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
             ),
73 73
 
74 74
             array(
75
-                'placeholder'  => __( 'Select your country' ),
75
+                'placeholder'  => __('Select your country'),
76 76
                 'value'        => '',
77
-                'label'        => __( 'Country', 'invoicing' ),
77
+                'label'        => __('Country', 'invoicing'),
78 78
                 'description'  => '',
79 79
                 'required'     => false,
80 80
                 'visible'      => true,
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
             ),
83 83
 
84 84
             array(
85
-                'placeholder'  => __( 'Choose a state', 'invoicing' ),
85
+                'placeholder'  => __('Choose a state', 'invoicing'),
86 86
                 'value'        => '',
87
-                'label'        => __( 'State / Province', 'invoicing' ),
87
+                'label'        => __('State / Province', 'invoicing'),
88 88
                 'description'  => '',
89 89
                 'required'     => false,
90 90
                 'visible'      => true,
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
             array(
95 95
                 'placeholder'  => '',
96 96
                 'value'        => '',
97
-                'label'        => __( 'ZIP / Postcode', 'invoicing' ),
97
+                'label'        => __('ZIP / Postcode', 'invoicing'),
98 98
                 'description'  => '',
99 99
                 'required'     => false,
100 100
                 'visible'      => true,
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
             array(
105 105
                 'placeholder'  => '',
106 106
                 'value'        => '',
107
-                'label'        => __( 'Phone', 'invoicing' ),
107
+                'label'        => __('Phone', 'invoicing'),
108 108
                 'description'  => '',
109 109
                 'required'     => false,
110 110
                 'visible'      => true,
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             array(
115 115
                 'placeholder'  => '',
116 116
                 'value'        => '',
117
-                'label'        => __( 'Company', 'invoicing' ),
117
+                'label'        => __('Company', 'invoicing'),
118 118
                 'description'  => '',
119 119
                 'required'     => false,
120 120
                 'visible'      => true,
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
             array(
125 125
                 'placeholder'  => '',
126 126
                 'value'        => '',
127
-                'label'        => __( 'VAT Number', 'invoicing' ),
127
+                'label'        => __('VAT Number', 'invoicing'),
128 128
                 'description'  => '',
129 129
                 'required'     => false,
130 130
                 'visible'      => true,
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
     array(
137 137
 
138 138
         'value'        => '',
139
-        'input_label'  => __( 'Coupon Code', 'invoicing' ),
140
-        'button_label' => __( 'Apply Coupon', 'invoicing' ),
141
-        'description'  => __( 'Have a discount code? Enter it above.', 'invoicing' ),
139
+        'input_label'  => __('Coupon Code', 'invoicing'),
140
+        'button_label' => __('Apply Coupon', 'invoicing'),
141
+        'description'  => __('Have a discount code? Enter it above.', 'invoicing'),
142 142
         'id'           => 'kcicdiscount',
143 143
         'name'         => 'kcicdiscount',
144 144
         'type'         => 'discount',
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
     ),
159 159
 
160 160
     array(
161
-        'text'    => __( 'Select Payment Method', 'invoicing' ),
161
+        'text'    => __('Select Payment Method', 'invoicing'),
162 162
         'id'          => 'gtscicd',
163 163
         'name'        => 'gtscicd',
164 164
         'type'        => 'gateway_select',
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 
171 171
         'value'       =>'',
172 172
         'class'       => 'btn-primary',
173
-        'label'       => __( 'Pay Now »', 'invoicing' ),
174
-        'description' => __( 'By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
173
+        'label'       => __('Pay Now »', 'invoicing'),
174
+        'description' => __('By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'),
175 175
         'id'          => 'rtqljyy',
176 176
         'name'        => 'rtqljyy',
177 177
         'type'        => 'pay_button',
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 2 patches
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Returns an array of discount type.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
     return apply_filters(
18 18
         'wpinv_discount_types',
19 19
         array(
20
-            'percent'   => __( 'Percentage', 'invoicing' ),
21
-            'flat'     => __( 'Flat Amount', 'invoicing' ),
20
+            'percent'   => __('Percentage', 'invoicing'),
21
+            'flat'     => __('Flat Amount', 'invoicing'),
22 22
         )
23 23
     );
24 24
 }
@@ -28,46 +28,46 @@  discard block
 block discarded – undo
28 28
  * 
29 29
  * @return string
30 30
  */
31
-function wpinv_get_discount_type_name( $type = '' ) {
31
+function wpinv_get_discount_type_name($type = '') {
32 32
     $types = wpinv_get_discount_types();
33
-    return isset( $types[ $type ] ) ? $types[ $type ] : $type;
33
+    return isset($types[$type]) ? $types[$type] : $type;
34 34
 }
35 35
 
36 36
 /**
37 37
  * Deletes a discount via the admin page.
38 38
  * 
39 39
  */
40
-function wpinv_delete_discount( $data ) {
40
+function wpinv_delete_discount($data) {
41 41
 
42
-    $discount = new WPInv_Discount( absint( $data['discount'] ) );
43
-    $discount->delete( true );
42
+    $discount = new WPInv_Discount(absint($data['discount']));
43
+    $discount->delete(true);
44 44
 
45 45
 }
46
-add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' );
46
+add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount');
47 47
 
48 48
 /**
49 49
  * Deactivates a discount via the admin page.
50 50
  */
51
-function wpinv_activate_discount( $data ) {
51
+function wpinv_activate_discount($data) {
52 52
 
53
-    $discount = new WPInv_Discount( absint( $data['discount'] ) );
54
-    $discount->set_status( 'publish' );
53
+    $discount = new WPInv_Discount(absint($data['discount']));
54
+    $discount->set_status('publish');
55 55
     $discount->save();
56 56
 
57 57
 }
58
-add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' );
58
+add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount');
59 59
 
60 60
 /**
61 61
  * Activates a discount via the admin page.
62 62
  */
63
-function wpinv_deactivate_discount( $data ) {
63
+function wpinv_deactivate_discount($data) {
64 64
 
65
-    $discount = new WPInv_Discount( absint( $data['discount'] ) );
66
-    $discount->set_status( 'pending' );
65
+    $discount = new WPInv_Discount(absint($data['discount']));
66
+    $discount->set_status('pending');
67 67
     $discount->save();
68 68
 
69 69
 }
70
-add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' );
70
+add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount');
71 71
 
72 72
 /**
73 73
  * Fetches a discount object.
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
  * @since 1.0.15
77 77
  * @return WPInv_Discount
78 78
  */
79
-function wpinv_get_discount( $discount ) {
80
-    return new WPInv_Discount( $discount );
79
+function wpinv_get_discount($discount) {
80
+    return new WPInv_Discount($discount);
81 81
 }
82 82
 
83 83
 /**
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
  * @since 1.0.15
88 88
  * @return WPInv_Discount
89 89
  */
90
-function wpinv_get_discount_obj( $discount = 0 ) {
91
-    return new WPInv_Discount( $discount );
90
+function wpinv_get_discount_obj($discount = 0) {
91
+    return new WPInv_Discount($discount);
92 92
 }
93 93
 
94 94
 /**
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
  * @param string|int $value The field value
99 99
  * @return bool|WPInv_Discount
100 100
  */
101
-function wpinv_get_discount_by( $deprecated = null, $value = '' ) {
102
-    $discount = new WPInv_Discount( $value );
101
+function wpinv_get_discount_by($deprecated = null, $value = '') {
102
+    $discount = new WPInv_Discount($value);
103 103
 
104
-    if ( $discount->get_id() != 0 ) {
104
+    if ($discount->get_id() != 0) {
105 105
         return $discount;
106 106
     }
107 107
 
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 function wpinv_get_discount_statuses() {
117 117
 
118 118
     return array(
119
-        'expired'  => __( 'Expired', 'invoicing' ),
120
-        'publish'  => __( 'Active', 'invoicing' ),
121
-        'inactive' => __( 'Inactive', 'invoicing' ),
119
+        'expired'  => __('Expired', 'invoicing'),
120
+        'publish'  => __('Active', 'invoicing'),
121
+        'inactive' => __('Inactive', 'invoicing'),
122 122
     );
123 123
 
124 124
 }
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 /**
127 127
  * Retrieves an invoice status label.
128 128
  */
129
-function wpinv_discount_status( $status ) {
129
+function wpinv_discount_status($status) {
130 130
     $statuses = wpinv_get_discount_statuses();
131
-    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' );
131
+    return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing');
132 132
 }
133 133
 
134 134
 /**
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
  * @param int|array|string|WPInv_Discount $code discount data, object, ID or code.
139 139
  * @return bool
140 140
  */
141
-function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) {
141
+function wpinv_discount_is_recurring($discount = 0, $code = 0) {
142 142
 
143
-    if( ! empty( $discount ) ) {
144
-        $discount    = wpinv_get_discount_obj( $discount );
143
+    if (!empty($discount)) {
144
+        $discount    = wpinv_get_discount_obj($discount);
145 145
     } else {
146
-        $discount    = wpinv_get_discount_obj( $code );
146
+        $discount    = wpinv_get_discount_obj($code);
147 147
     }
148 148
 
149 149
     return $discount->get_is_recurring();
@@ -158,35 +158,35 @@  discard block
 block discarded – undo
158 158
  * @param WPInv_Discount $discount
159 159
  * @return array
160 160
  */
161
-function getpaid_calculate_invoice_discount( $invoice, $discount ) {
161
+function getpaid_calculate_invoice_discount($invoice, $discount) {
162 162
 
163 163
 	$initial_discount   = 0;
164 164
 	$recurring_discount = 0;
165 165
 
166
-	foreach ( $invoice->get_items() as $item ) {
166
+	foreach ($invoice->get_items() as $item) {
167 167
 
168 168
 		// Abort if it is not valid for this item.
169
-		if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
169
+		if (!$discount->is_valid_for_items(array($item->get_id()))) {
170 170
 			continue;
171 171
 		}
172 172
 
173 173
 		// Calculate the initial amount...
174
-		$item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
174
+		$item_discount           = $discount->get_discounted_amount($item->get_sub_total());
175 175
 		$recurring_item_discount = 0;
176 176
 
177 177
 		// ... and maybe the recurring amount.
178
-		if ( $item->is_recurring() && $discount->is_recurring() ) {
179
-			$recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
178
+		if ($item->is_recurring() && $discount->is_recurring()) {
179
+			$recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total());
180 180
 		}
181 181
 
182 182
 		// Discount should not exceed discounted amount.
183
-		if ( ! $discount->is_type( 'percent' ) ) {
183
+		if (!$discount->is_type('percent')) {
184 184
 
185
-			if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
185
+			if (($initial_discount + $item_discount) > $discount->get_amount()) {
186 186
 				$item_discount = $discount->get_amount() - $initial_discount;
187 187
 			}
188 188
 
189
-			if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
189
+			if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) {
190 190
 				$recurring_item_discount = $discount->get_amount() - $recurring_discount;
191 191
 			}
192 192
 
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
         array(
220 220
             'post_type'   => 'wpi_discount',
221 221
             'numberposts' => 1,
222
-            'fields'      => array( 'ids' ),
222
+            'fields'      => array('ids'),
223 223
         )
224 224
     );
225 225
 
226
-    return ! empty( $discounts );
226
+    return !empty($discounts);
227 227
 
228 228
 }
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -160,51 +160,51 @@
 block discarded – undo
160 160
  */
161 161
 function getpaid_calculate_invoice_discount( $invoice, $discount ) {
162 162
 
163
-	$initial_discount   = 0;
164
-	$recurring_discount = 0;
163
+    $initial_discount   = 0;
164
+    $recurring_discount = 0;
165 165
 
166
-	foreach ( $invoice->get_items() as $item ) {
166
+    foreach ( $invoice->get_items() as $item ) {
167 167
 
168
-		// Abort if it is not valid for this item.
169
-		if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
-			continue;
171
-		}
168
+        // Abort if it is not valid for this item.
169
+        if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
+            continue;
171
+        }
172 172
 
173
-		// Calculate the initial amount...
174
-		$item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
-		$recurring_item_discount = 0;
173
+        // Calculate the initial amount...
174
+        $item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
+        $recurring_item_discount = 0;
176 176
 
177
-		// ... and maybe the recurring amount.
178
-		if ( $item->is_recurring() && $discount->is_recurring() ) {
179
-			$recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
-		}
177
+        // ... and maybe the recurring amount.
178
+        if ( $item->is_recurring() && $discount->is_recurring() ) {
179
+            $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
+        }
181 181
 
182
-		// Discount should not exceed discounted amount.
183
-		if ( ! $discount->is_type( 'percent' ) ) {
182
+        // Discount should not exceed discounted amount.
183
+        if ( ! $discount->is_type( 'percent' ) ) {
184 184
 
185
-			if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
-				$item_discount = $discount->get_amount() - $initial_discount;
187
-			}
185
+            if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
+                $item_discount = $discount->get_amount() - $initial_discount;
187
+            }
188 188
 
189
-			if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
-				$recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
-			}
189
+            if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
+                $recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
+            }
192 192
 
193
-		}
193
+        }
194 194
 
195
-		$initial_discount             += $item_discount;
196
-		$recurring_discount           += $recurring_item_discount;
197
-		$item->item_discount           = $item_discount;
198
-		$item->recurring_item_discount = $recurring_item_discount;
195
+        $initial_discount             += $item_discount;
196
+        $recurring_discount           += $recurring_item_discount;
197
+        $item->item_discount           = $item_discount;
198
+        $item->recurring_item_discount = $recurring_item_discount;
199 199
 
200
-	}
200
+    }
201 201
 
202
-	return array(
203
-		'name'               => 'discount_code',
204
-		'discount_code'      => $discount->get_code(),
205
-		'initial_discount'   => $initial_discount,
206
-		'recurring_discount' => $recurring_discount,
207
-	);
202
+    return array(
203
+        'name'               => 'discount_code',
204
+        'discount_code'      => $discount->get_code(),
205
+        'initial_discount'   => $initial_discount,
206
+        'recurring_discount' => $recurring_discount,
207
+    );
208 208
 
209 209
 }
210 210
 
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 2 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -12,202 +12,202 @@
 block discarded – undo
12 12
  */
13 13
 class WPInv_Notes {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct() {
19
-
20
-		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
-
24
-		// Delete comments count cache whenever there is a new comment or a comment status changes.
25
-		add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
-		add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
-
28
-		// Count comments.
29
-		add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
-
31
-		// Fires after notes are loaded.
32
-		do_action( 'wpinv_notes_init', $this );
33
-	}
34
-
35
-	/**
36
-	 * Filters invoice notes query to only include our notes.
37
-	 *
38
-	 * @param WP_Comment_Query $query
39
-	 */
40
-	public function set_invoice_note_type( $query ) {
41
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
-
43
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
-			$query->query_vars['type'] = 'wpinv_note';
45
-		} else {
46
-
47
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
48
-				$query->query_vars['type__not_in'] = array();
49
-			}
50
-
51
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
-		}
54
-
55
-		return $query;
56
-	}
57
-
58
-	/**
59
-	 * Exclude notes from the comments feed.
60
-	 */
61
-	function wpinv_comment_feed_where( $where ){
62
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
-	}
64
-
65
-	/**
66
-	 * Delete comments count cache whenever there is
67
-	 * new comment or the status of a comment changes. Cache
68
-	 * will be regenerated next time WPInv_Notes::wp_count_comments()
69
-	 * is called.
70
-	 */
71
-	public function delete_comments_count_cache() {
72
-		delete_transient( 'getpaid_count_comments' );
73
-	}
74
-
75
-	/**
76
-	 * Remove invoice notes from wp_count_comments().
77
-	 *
78
-	 * @since  2.2
79
-	 * @param  object $stats   Comment stats.
80
-	 * @param  int    $post_id Post ID.
81
-	 * @return object
82
-	 */
83
-	public function wp_count_comments( $stats, $post_id ) {
84
-		global $wpdb;
85
-
86
-		if ( empty( $post_id ) ) {
87
-			$stats = get_transient( 'getpaid_count_comments' );
88
-
89
-			if ( ! $stats ) {
90
-				$stats = array(
91
-					'total_comments' => 0,
92
-					'all'            => 0,
93
-				);
94
-
95
-				$count = $wpdb->get_results(
96
-					"
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct() {
19
+
20
+        // Filter inovice notes.
21
+        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
+        add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
+
24
+        // Delete comments count cache whenever there is a new comment or a comment status changes.
25
+        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
+        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
+
28
+        // Count comments.
29
+        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
+
31
+        // Fires after notes are loaded.
32
+        do_action( 'wpinv_notes_init', $this );
33
+    }
34
+
35
+    /**
36
+     * Filters invoice notes query to only include our notes.
37
+     *
38
+     * @param WP_Comment_Query $query
39
+     */
40
+    public function set_invoice_note_type( $query ) {
41
+        $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
+
43
+        if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
+            $query->query_vars['type'] = 'wpinv_note';
45
+        } else {
46
+
47
+            if ( empty( $query->query_vars['type__not_in'] ) ) {
48
+                $query->query_vars['type__not_in'] = array();
49
+            }
50
+
51
+            $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
+            $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
+        }
54
+
55
+        return $query;
56
+    }
57
+
58
+    /**
59
+     * Exclude notes from the comments feed.
60
+     */
61
+    function wpinv_comment_feed_where( $where ){
62
+        return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
+    }
64
+
65
+    /**
66
+     * Delete comments count cache whenever there is
67
+     * new comment or the status of a comment changes. Cache
68
+     * will be regenerated next time WPInv_Notes::wp_count_comments()
69
+     * is called.
70
+     */
71
+    public function delete_comments_count_cache() {
72
+        delete_transient( 'getpaid_count_comments' );
73
+    }
74
+
75
+    /**
76
+     * Remove invoice notes from wp_count_comments().
77
+     *
78
+     * @since  2.2
79
+     * @param  object $stats   Comment stats.
80
+     * @param  int    $post_id Post ID.
81
+     * @return object
82
+     */
83
+    public function wp_count_comments( $stats, $post_id ) {
84
+        global $wpdb;
85
+
86
+        if ( empty( $post_id ) ) {
87
+            $stats = get_transient( 'getpaid_count_comments' );
88
+
89
+            if ( ! $stats ) {
90
+                $stats = array(
91
+                    'total_comments' => 0,
92
+                    'all'            => 0,
93
+                );
94
+
95
+                $count = $wpdb->get_results(
96
+                    "
97 97
 					SELECT comment_approved, COUNT(*) AS num_comments
98 98
 					FROM {$wpdb->comments}
99 99
 					WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note')
100 100
 					GROUP BY comment_approved
101 101
 					",
102
-					ARRAY_A
103
-				);
104
-
105
-				$approved = array(
106
-					'0'            => 'moderated',
107
-					'1'            => 'approved',
108
-					'spam'         => 'spam',
109
-					'trash'        => 'trash',
110
-					'post-trashed' => 'post-trashed',
111
-				);
112
-
113
-				foreach ( (array) $count as $row ) {
114
-					// Don't count post-trashed toward totals.
115
-					if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
-						$stats['all']            += $row['num_comments'];
117
-						$stats['total_comments'] += $row['num_comments'];
118
-					} elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
-						$stats['total_comments'] += $row['num_comments'];
120
-					}
121
-					if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
-						$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
-					}
124
-				}
125
-
126
-				foreach ( $approved as $key ) {
127
-					if ( empty( $stats[ $key ] ) ) {
128
-						$stats[ $key ] = 0;
129
-					}
130
-				}
131
-
132
-				$stats = (object) $stats;
133
-				set_transient( 'getpaid_count_comments', $stats );
134
-			}
135
-
136
-		}
137
-
138
-		return $stats;
139
-	}
140
-
141
-	/**
142
-	 * Returns an array of invoice notes.
143
-	 *
144
-	 * @param int $invoice_id The invoice ID whose notes to retrieve.
145
-	 * @param string $type Optional. Pass in customer to only return customer notes.
146
-	 * @return WP_Comment[]
147
-	 */
148
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
149
-
150
-		// Default comment args.
151
-		$args = array(
152
-			'post_id'   => $invoice_id,
153
-			'orderby'   => 'comment_ID',
154
-			'order'     => 'ASC',
155
-		);
156
-
157
-		// Maybe only show customer comments.
158
-		if ( $type == 'customer' ) {
159
-			$args['meta_key']   = '_wpi_customer_note';
160
-			$args['meta_value'] = 1;
161
-		}
162
-
163
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
164
-
165
-		return get_comments( $args );
166
-	}
167
-
168
-	/**
169
-	 * Saves an invoice comment.
170
-	 * 
171
-	 * @param WPInv_Invoice $invoice The invoice to add the comment to.
172
-	 * @param string $note The note content.
173
-	 * @param string $note_author The name of the author of the note.
174
-	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
175
-	 * @return int|false The new note's ID on success, false on failure.
176
-	 */
177
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
178
-
179
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
180
-
181
-		/**
182
-		 * Insert the comment.
183
-		 */
184
-		$note_id = wp_insert_comment(
185
-			wp_filter_comment(
186
-				array(
187
-					'comment_post_ID'      => $invoice->get_id(),
188
-					'comment_content'      => $note,
189
-					'comment_agent'        => 'Invoicing',
190
-					'user_id'              => get_current_user_id(),
191
-					'comment_author'       => $note_author,
192
-					'comment_author_IP'    => wpinv_get_ip(),
193
-					'comment_author_email' => $author_email,
194
-					'comment_author_url'   => $invoice->get_view_url(),
195
-					'comment_type'         => 'wpinv_note',
196
-				)
197
-			)
198
-		);
199
-
200
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
201
-
202
-		// Are we notifying the customer?
203
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
204
-			return $note_id;
205
-		}
206
-
207
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
208
-		do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
209
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
210
-		return $note_id;
211
-	}
102
+                    ARRAY_A
103
+                );
104
+
105
+                $approved = array(
106
+                    '0'            => 'moderated',
107
+                    '1'            => 'approved',
108
+                    'spam'         => 'spam',
109
+                    'trash'        => 'trash',
110
+                    'post-trashed' => 'post-trashed',
111
+                );
112
+
113
+                foreach ( (array) $count as $row ) {
114
+                    // Don't count post-trashed toward totals.
115
+                    if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
+                        $stats['all']            += $row['num_comments'];
117
+                        $stats['total_comments'] += $row['num_comments'];
118
+                    } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
+                        $stats['total_comments'] += $row['num_comments'];
120
+                    }
121
+                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
+                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
+                    }
124
+                }
125
+
126
+                foreach ( $approved as $key ) {
127
+                    if ( empty( $stats[ $key ] ) ) {
128
+                        $stats[ $key ] = 0;
129
+                    }
130
+                }
131
+
132
+                $stats = (object) $stats;
133
+                set_transient( 'getpaid_count_comments', $stats );
134
+            }
135
+
136
+        }
137
+
138
+        return $stats;
139
+    }
140
+
141
+    /**
142
+     * Returns an array of invoice notes.
143
+     *
144
+     * @param int $invoice_id The invoice ID whose notes to retrieve.
145
+     * @param string $type Optional. Pass in customer to only return customer notes.
146
+     * @return WP_Comment[]
147
+     */
148
+    public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
149
+
150
+        // Default comment args.
151
+        $args = array(
152
+            'post_id'   => $invoice_id,
153
+            'orderby'   => 'comment_ID',
154
+            'order'     => 'ASC',
155
+        );
156
+
157
+        // Maybe only show customer comments.
158
+        if ( $type == 'customer' ) {
159
+            $args['meta_key']   = '_wpi_customer_note';
160
+            $args['meta_value'] = 1;
161
+        }
162
+
163
+        $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
164
+
165
+        return get_comments( $args );
166
+    }
167
+
168
+    /**
169
+     * Saves an invoice comment.
170
+     * 
171
+     * @param WPInv_Invoice $invoice The invoice to add the comment to.
172
+     * @param string $note The note content.
173
+     * @param string $note_author The name of the author of the note.
174
+     * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
175
+     * @return int|false The new note's ID on success, false on failure.
176
+     */
177
+    function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
178
+
179
+        do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
180
+
181
+        /**
182
+         * Insert the comment.
183
+         */
184
+        $note_id = wp_insert_comment(
185
+            wp_filter_comment(
186
+                array(
187
+                    'comment_post_ID'      => $invoice->get_id(),
188
+                    'comment_content'      => $note,
189
+                    'comment_agent'        => 'Invoicing',
190
+                    'user_id'              => get_current_user_id(),
191
+                    'comment_author'       => $note_author,
192
+                    'comment_author_IP'    => wpinv_get_ip(),
193
+                    'comment_author_email' => $author_email,
194
+                    'comment_author_url'   => $invoice->get_view_url(),
195
+                    'comment_type'         => 'wpinv_note',
196
+                )
197
+            )
198
+        );
199
+
200
+        do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
201
+
202
+        // Are we notifying the customer?
203
+        if ( empty( $note_id ) || empty( $for_customer ) ) {
204
+            return $note_id;
205
+        }
206
+
207
+        add_comment_meta( $note_id, '_wpi_customer_note', 1 );
208
+        do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
209
+        do_action( 'getpaid_new_customer_note', $invoice, $note );
210
+        return $note_id;
211
+    }
212 212
 
213 213
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Handles invoice notes.
@@ -18,18 +18,18 @@  discard block
 block discarded – undo
18 18
 	public function __construct() {
19 19
 
20 20
 		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
21
+		add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
22
+		add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1);
23 23
 
24 24
 		// Delete comments count cache whenever there is a new comment or a comment status changes.
25
-		add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
-		add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
25
+		add_action('wp_insert_comment', array($this, 'delete_comments_count_cache'));
26
+		add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache'));
27 27
 
28 28
 		// Count comments.
29
-		add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
29
+		add_filter('wp_count_comments', array($this, 'wp_count_comments'), 100, 2);
30 30
 
31 31
 		// Fires after notes are loaded.
32
-		do_action( 'wpinv_notes_init', $this );
32
+		do_action('wpinv_notes_init', $this);
33 33
 	}
34 34
 
35 35
 	/**
@@ -37,19 +37,19 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param WP_Comment_Query $query
39 39
 	 */
40
-	public function set_invoice_note_type( $query ) {
41
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
40
+	public function set_invoice_note_type($query) {
41
+		$post_id = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42 42
 
43
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
43
+		if ($post_id && getpaid_is_invoice_post_type(get_post_type($post_id))) {
44 44
 			$query->query_vars['type'] = 'wpinv_note';
45 45
 		} else {
46 46
 
47
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
47
+			if (empty($query->query_vars['type__not_in'])) {
48 48
 				$query->query_vars['type__not_in'] = array();
49 49
 			}
50 50
 
51
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
51
+			$query->query_vars['type__not_in'] = wpinv_parse_list($query->query_vars['type__not_in']);
52
+			$query->query_vars['type__not_in'] = array_merge(array('wpinv_note'), $query->query_vars['type__not_in']);
53 53
 		}
54 54
 
55 55
 		return $query;
@@ -58,8 +58,8 @@  discard block
 block discarded – undo
58 58
 	/**
59 59
 	 * Exclude notes from the comments feed.
60 60
 	 */
61
-	function wpinv_comment_feed_where( $where ){
62
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
61
+	function wpinv_comment_feed_where($where) {
62
+		return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' ";
63 63
 	}
64 64
 
65 65
 	/**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * is called.
70 70
 	 */
71 71
 	public function delete_comments_count_cache() {
72
-		delete_transient( 'getpaid_count_comments' );
72
+		delete_transient('getpaid_count_comments');
73 73
 	}
74 74
 
75 75
 	/**
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
 	 * @param  int    $post_id Post ID.
81 81
 	 * @return object
82 82
 	 */
83
-	public function wp_count_comments( $stats, $post_id ) {
83
+	public function wp_count_comments($stats, $post_id) {
84 84
 		global $wpdb;
85 85
 
86
-		if ( empty( $post_id ) ) {
87
-			$stats = get_transient( 'getpaid_count_comments' );
86
+		if (empty($post_id)) {
87
+			$stats = get_transient('getpaid_count_comments');
88 88
 
89
-			if ( ! $stats ) {
89
+			if (!$stats) {
90 90
 				$stats = array(
91 91
 					'total_comments' => 0,
92 92
 					'all'            => 0,
@@ -110,27 +110,27 @@  discard block
 block discarded – undo
110 110
 					'post-trashed' => 'post-trashed',
111 111
 				);
112 112
 
113
-				foreach ( (array) $count as $row ) {
113
+				foreach ((array) $count as $row) {
114 114
 					// Don't count post-trashed toward totals.
115
-					if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
115
+					if (!in_array($row['comment_approved'], array('post-trashed', 'trash', 'spam'), true)) {
116 116
 						$stats['all']            += $row['num_comments'];
117 117
 						$stats['total_comments'] += $row['num_comments'];
118
-					} elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
118
+					} elseif (!in_array($row['comment_approved'], array('post-trashed', 'trash'), true)) {
119 119
 						$stats['total_comments'] += $row['num_comments'];
120 120
 					}
121
-					if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
-						$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
121
+					if (isset($approved[$row['comment_approved']])) {
122
+						$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
123 123
 					}
124 124
 				}
125 125
 
126
-				foreach ( $approved as $key ) {
127
-					if ( empty( $stats[ $key ] ) ) {
128
-						$stats[ $key ] = 0;
126
+				foreach ($approved as $key) {
127
+					if (empty($stats[$key])) {
128
+						$stats[$key] = 0;
129 129
 					}
130 130
 				}
131 131
 
132 132
 				$stats = (object) $stats;
133
-				set_transient( 'getpaid_count_comments', $stats );
133
+				set_transient('getpaid_count_comments', $stats);
134 134
 			}
135 135
 
136 136
 		}
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @param string $type Optional. Pass in customer to only return customer notes.
146 146
 	 * @return WP_Comment[]
147 147
 	 */
148
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
148
+	public function get_invoice_notes($invoice_id = 0, $type = 'all') {
149 149
 
150 150
 		// Default comment args.
151 151
 		$args = array(
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
 		);
156 156
 
157 157
 		// Maybe only show customer comments.
158
-		if ( $type == 'customer' ) {
158
+		if ($type == 'customer') {
159 159
 			$args['meta_key']   = '_wpi_customer_note';
160 160
 			$args['meta_value'] = 1;
161 161
 		}
162 162
 
163
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
163
+		$args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
164 164
 
165
-		return get_comments( $args );
165
+		return get_comments($args);
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
 	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
175 175
 	 * @return int|false The new note's ID on success, false on failure.
176 176
 	 */
177
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
177
+	function add_invoice_note($invoice, $note, $note_author, $author_email, $for_customer = false) {
178 178
 
179
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
179
+		do_action('wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer);
180 180
 
181 181
 		/**
182 182
 		 * Insert the comment.
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
 			)
198 198
 		);
199 199
 
200
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
200
+		do_action('wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer);
201 201
 
202 202
 		// Are we notifying the customer?
203
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
203
+		if (empty($note_id) || empty($for_customer)) {
204 204
 			return $note_id;
205 205
 		}
206 206
 
207
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
208
-		do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
209
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
207
+		add_comment_meta($note_id, '_wpi_customer_note', 1);
208
+		do_action('wpinv_new_customer_note', array('invoice_id' => $invoice->get_id(), 'user_note' => $note));
209
+		do_action('getpaid_new_customer_note', $invoice, $note);
210 210
 		return $note_id;
211 211
 	}
212 212
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-payment-form.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit; // Exit if accessed directly
10
+    exit; // Exit if accessed directly
11 11
 }
12 12
 
13 13
 /**
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
 class GetPaid_Meta_Box_Payment_Form {
17 17
 
18 18
     /**
19
-	 * Output the metabox.
20
-	 *
21
-	 * @param WP_Post $post
22
-	 */
19
+     * Output the metabox.
20
+     *
21
+     * @param WP_Post $post
22
+     */
23 23
     public static function output( $post ) {
24 24
         ?>
25 25
         <style>
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
     }
103 103
 
104 104
     /**
105
-	 * Save meta box data.
106
-	 *
107
-	 * @param int $post_id
108
-	 */
109
-	public static function save( $post_id ) {
105
+     * Save meta box data.
106
+     *
107
+     * @param int $post_id
108
+     */
109
+    public static function save( $post_id ) {
110 110
 
111 111
         // Prepare the form.
112 112
         $form = new GetPaid_Payment_Form( $post_id );
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
     }
138 138
 
139 139
     /**
140
-	 * Converts an array fo form items to objects.
141
-	 *
142
-	 * @param array $items
143
-	 */
144
-	public static function item_to_objects( $items ) {
140
+     * Converts an array fo form items to objects.
141
+     *
142
+     * @param array $items
143
+     */
144
+    public static function item_to_objects( $items ) {
145 145
 
146 146
         $objects = array();
147 147
 
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit; // Exit if accessed directly
11 11
 }
12 12
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param WP_Post $post
22 22
 	 */
23
-    public static function output( $post ) {
23
+    public static function output($post) {
24 24
         ?>
25 25
         <style>
26 26
             .wpinv-form-builder-edit-field-wrapper label.d-block > span:first-child{
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
                 <div class="col-sm-4">
34 34
 
35 35
                     <!-- Builder tabs -->
36
-                    <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e( 'Go Back', 'invoicing' ); ?></button>
36
+                    <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e('Go Back', 'invoicing'); ?></button>
37 37
 
38 38
                     <!-- Builder tab content -->
39 39
                     <div class="mt-4">
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
                         <!-- Available builder elements -->
42 42
                         <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'">
43 43
                             <div class="wpinv-form-builder-add-field-types">
44
-                                <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small>
44
+                                <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small>
45 45
                                 <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable">
46 46
                                     <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }">
47 47
                                         <button class="button btn text-dark">
@@ -56,18 +56,18 @@  discard block
 block discarded – undo
56 56
                         <!-- Edit an element -->
57 57
                         <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='edit_item'" style="font-size: 14px;">
58 58
                             <div class="wpinv-form-builder-edit-field-wrapper">
59
-                                <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?>
60
-                                <?php do_action( 'getpaid_payment_form_edit_element_template', $post ); ?>
59
+                                <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?>
60
+                                <?php do_action('getpaid_payment_form_edit_element_template', $post); ?>
61 61
                                 <div class='form-group'>
62
-                                    <label :for="active_form_element.id + '_grid_width'"><?php esc_html_e( 'Width', 'invoicing' ) ?></label>
62
+                                    <label :for="active_form_element.id + '_grid_width'"><?php esc_html_e('Width', 'invoicing') ?></label>
63 63
                                     <select class='form-control custom-select' :id="active_form_element.id + '_grid_width'" v-model='gridWidth'>
64
-                                        <option value='full'><?php esc_html_e( 'Full Width', 'invoicing' ); ?></option>
65
-                                        <option value='half'><?php esc_html_e( 'Half Width', 'invoicing' ); ?></option>
66
-                                        <option value='third'><?php esc_html_e( '1/3 Width', 'invoicing' ); ?></option>
64
+                                        <option value='full'><?php esc_html_e('Full Width', 'invoicing'); ?></option>
65
+                                        <option value='half'><?php esc_html_e('Half Width', 'invoicing'); ?></option>
66
+                                        <option value='third'><?php esc_html_e('1/3 Width', 'invoicing'); ?></option>
67 67
                                     </select>
68 68
                                 </div>
69 69
                                 <div>
70
-                                    <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Element', 'invoicing' ); ?></button>
70
+                                    <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Element', 'invoicing'); ?></button>
71 71
                                 </div>
72 72
                             </div>
73 73
                         </div>
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 
77 77
                 </div>
78 78
                 <div class="col-sm-8 border-left">
79
-                    <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small>
80
-                    <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p>
79
+                    <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small>
80
+                    <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p>
81 81
 
82 82
                     <div class="container-fluid">
83 83
                         <draggable class="section row" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 14px;">
84 84
                             <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="[{ active: active_form_element==form_element &&  active_tab=='edit_item' }, form_element.type, grid_class( form_element ) ]" @click="active_tab = 'edit_item'; active_form_element = form_element">
85 85
                                 <div class="wpinv-form-builder-element-preview-inner">
86 86
                                     <div class="wpinv-payment-form-field-preview-overlay"></div>
87
-                                    <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?>
87
+                                    <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?>
88 88
                                 </div>
89 89
                             </div>
90 90
                         </draggable>
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         </script>
104 104
         <?php
105 105
 
106
-        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
106
+        wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
107 107
     }
108 108
 
109 109
     /**
@@ -111,33 +111,33 @@  discard block
 block discarded – undo
111 111
 	 *
112 112
 	 * @param int $post_id
113 113
 	 */
114
-	public static function save( $post_id ) {
114
+	public static function save($post_id) {
115 115
 
116 116
         // Prepare the form.
117
-        $form = new GetPaid_Payment_Form( $post_id );
117
+        $form = new GetPaid_Payment_Form($post_id);
118 118
 
119 119
         // Fetch form items.
120
-        $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true );
120
+        $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true);
121 121
 
122 122
         // Ensure that we have an array...
123
-        if ( empty( $form_items ) ) {
123
+        if (empty($form_items)) {
124 124
             $form_items = array();
125 125
         }
126 126
 
127 127
         // Add it to the form.
128
-        $form->set_items( self::item_to_objects( wp_kses_post_deep( $form_items ) ) );
128
+        $form->set_items(self::item_to_objects(wp_kses_post_deep($form_items)));
129 129
 
130 130
         // Save form elements.
131
-        $form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true );
132
-        if ( empty( $form_elements ) ) {
131
+        $form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true);
132
+        if (empty($form_elements)) {
133 133
             $form_elements = array();
134 134
         }
135 135
 
136
-        $form->set_elements( wp_kses_post_deep( $form_elements ) );
136
+        $form->set_elements(wp_kses_post_deep($form_elements));
137 137
 
138 138
         // Persist data to the datastore.
139 139
         $form->save();
140
-        do_action( 'getpaid_payment_form_metabox_save', $post_id, $form );
140
+        do_action('getpaid_payment_form_metabox_save', $post_id, $form);
141 141
 
142 142
     }
143 143
 
@@ -146,14 +146,14 @@  discard block
 block discarded – undo
146 146
 	 *
147 147
 	 * @param array $items
148 148
 	 */
149
-	public static function item_to_objects( $items ) {
149
+	public static function item_to_objects($items) {
150 150
 
151 151
         $objects = array();
152 152
 
153
-        foreach ( $items as $item ) {
154
-            $_item = new GetPaid_Form_Item( $item['id'] );
155
-            $_item->set_allow_quantities( (bool) $item['allow_quantities'] );
156
-            $_item->set_is_required( (bool) $item['required'] );
153
+        foreach ($items as $item) {
154
+            $_item = new GetPaid_Form_Item($item['id']);
155
+            $_item->set_allow_quantities((bool) $item['allow_quantities']);
156
+            $_item->set_is_required((bool) $item['required']);
157 157
             $objects[] = $_item;
158 158
         }
159 159
 
Please login to merge, or discard this patch.
includes/class-getpaid-tax.php 2 patches
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -13,168 +13,168 @@
 block discarded – undo
13 13
  */
14 14
 class GetPaid_Tax {
15 15
 
16
-	/**
17
-	 * Calculates tax for a line item.
18
-	 *
19
-	 * @param  float   $price              The price to calc tax on.
20
-	 * @param  array   $rates              The rates to apply.
21
-	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
-	 * @return array                       Array of tax name => tax amount.
23
-	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
-
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
28
-		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
30
-		}
31
-
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
-
34
-	}
35
-
36
-	/**
37
-	 * Calc tax from inclusive price.
38
-	 *
39
-	 * @param  float $price Price to calculate tax for.
40
-	 * @param  array $rates Array of tax rates.
41
-	 * @return array
42
-	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
44
-		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
-
47
-		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
-
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
55
-		}
56
-
57
-		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
-
60
-		return $taxes;
61
-	}
62
-
63
-	/**
64
-	 * Calc tax from exclusive price.
65
-	 *
66
-	 * @param  float $price Price to calculate tax for.
67
-	 * @param  array $rates Array of tax rates.
68
-	 * @return array
69
-	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
71
-		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
-
74
-		foreach ( $tax_rates as $name => $rate ) {
75
-
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
-
79
-		}
80
-
81
-		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
-
84
-		return $taxes;
85
-	}
86
-
87
-	/**
88
-	 * Get's an array of all tax rates.
89
-	 *
90
-	 * @return array
91
-	 */
92
-	public static function get_all_tax_rates() {
93
-
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
95
-
96
-		return apply_filters(
97
-			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
99
-		);
100
-
101
-	}
102
-
103
-	/**
104
-	 * Get's an array of default tax rates.
105
-	 *
106
-	 * @return array
107
-	 */
108
-	public static function get_default_tax_rates() {
109
-
110
-		return apply_filters(
111
-			'getpaid_get_default_tax_rates',
112
-			array(
113
-				array(
114
-					'country'   => wpinv_get_default_country(),
115
-					'state'     => wpinv_get_default_state(),
116
-					'global'    => true,
117
-					'rate'      => wpinv_get_default_tax_rate(),
118
-					'name'      => __( 'Base Tax', 'invoicing' ),
119
-				)
120
-			)
121
-		);
122
-
123
-	}
124
-
125
-	/**
126
-	 * Get's an array of tax rates for a given address.
127
-	 *
128
-	 * @param string $country
129
-	 * @param string $state
130
-	 * @return array
131
-	 */
132
-	public static function get_address_tax_rates( $country, $state ) {
133
-
134
-		$all_tax_rates  = self::get_all_tax_rates();
135
-		$matching_rates = array_merge(
136
-			wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
137
-			wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
138
-		);
139
-
140
-		foreach ( $matching_rates as $i => $rate ) {
141
-
142
-			$states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
143
-			if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
144
-				unset( $matching_rates[ $i ] );
145
-			}
146
-
147
-		}
148
-
149
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
150
-
151
-	}
152
-
153
-	/**
154
-	 * Sums a set of taxes to form a single total. Result is rounded to precision.
155
-	 *
156
-	 * @param  array $taxes Array of taxes.
157
-	 * @return float
158
-	 */
159
-	public static function get_tax_total( $taxes ) {
160
-		return self::round( array_sum( $taxes ) );
161
-	}
162
-
163
-	/**
164
-	 * Round to precision.
165
-	 *
166
-	 * Filter example: to return rounding to .5 cents you'd use:
167
-	 *
168
-	 * function euro_5cent_rounding( $in ) {
169
-	 *      return round( $in / 5, 2 ) * 5;
170
-	 * }
171
-	 * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
172
-	 *
173
-	 * @param float|int $in Value to round.
174
-	 * @return float
175
-	 */
176
-	public static function round( $in ) {
177
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
178
-	}
16
+    /**
17
+     * Calculates tax for a line item.
18
+     *
19
+     * @param  float   $price              The price to calc tax on.
20
+     * @param  array   $rates              The rates to apply.
21
+     * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
+     * @return array                       Array of tax name => tax amount.
23
+     */
24
+    public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
+
26
+        if ( $price_includes_tax ) {
27
+            $taxes = self::calc_inclusive_tax( $price, $rates );
28
+        } else {
29
+            $taxes = self::calc_exclusive_tax( $price, $rates );
30
+        }
31
+
32
+        return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
+
34
+    }
35
+
36
+    /**
37
+     * Calc tax from inclusive price.
38
+     *
39
+     * @param  float $price Price to calculate tax for.
40
+     * @param  array $rates Array of tax rates.
41
+     * @return array
42
+     */
43
+    public static function calc_inclusive_tax( $price, $rates ) {
44
+        $taxes     = array();
45
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
+
47
+        // Add tax rates.
48
+        $tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
+
50
+        foreach ( $tax_rates as $name => $rate ) {
51
+            $the_rate       = ( $rate / 100 ) / $tax_rate;
52
+            $net_price      = $price - ( $the_rate * $price );
53
+            $tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
+            $taxes[ $name ] = $tax_amount;
55
+        }
56
+
57
+        // Round all taxes to precision (4DP) before passing them back.
58
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
+
60
+        return $taxes;
61
+    }
62
+
63
+    /**
64
+     * Calc tax from exclusive price.
65
+     *
66
+     * @param  float $price Price to calculate tax for.
67
+     * @param  array $rates Array of tax rates.
68
+     * @return array
69
+     */
70
+    public static function calc_exclusive_tax( $price, $rates ) {
71
+        $taxes     = array();
72
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
+
74
+        foreach ( $tax_rates as $name => $rate ) {
75
+
76
+            $tax_amount     = $price * ( $rate / 100 );
77
+            $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
+
79
+        }
80
+
81
+        // Round all taxes to precision (4DP) before passing them back.
82
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
+
84
+        return $taxes;
85
+    }
86
+
87
+    /**
88
+     * Get's an array of all tax rates.
89
+     *
90
+     * @return array
91
+     */
92
+    public static function get_all_tax_rates() {
93
+
94
+        $rates = get_option( 'wpinv_tax_rates', array() );
95
+
96
+        return apply_filters(
97
+            'getpaid_get_all_tax_rates',
98
+            array_filter( wpinv_parse_list( $rates ) )
99
+        );
100
+
101
+    }
102
+
103
+    /**
104
+     * Get's an array of default tax rates.
105
+     *
106
+     * @return array
107
+     */
108
+    public static function get_default_tax_rates() {
109
+
110
+        return apply_filters(
111
+            'getpaid_get_default_tax_rates',
112
+            array(
113
+                array(
114
+                    'country'   => wpinv_get_default_country(),
115
+                    'state'     => wpinv_get_default_state(),
116
+                    'global'    => true,
117
+                    'rate'      => wpinv_get_default_tax_rate(),
118
+                    'name'      => __( 'Base Tax', 'invoicing' ),
119
+                )
120
+            )
121
+        );
122
+
123
+    }
124
+
125
+    /**
126
+     * Get's an array of tax rates for a given address.
127
+     *
128
+     * @param string $country
129
+     * @param string $state
130
+     * @return array
131
+     */
132
+    public static function get_address_tax_rates( $country, $state ) {
133
+
134
+        $all_tax_rates  = self::get_all_tax_rates();
135
+        $matching_rates = array_merge(
136
+            wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
137
+            wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
138
+        );
139
+
140
+        foreach ( $matching_rates as $i => $rate ) {
141
+
142
+            $states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
143
+            if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
144
+                unset( $matching_rates[ $i ] );
145
+            }
146
+
147
+        }
148
+
149
+        return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
150
+
151
+    }
152
+
153
+    /**
154
+     * Sums a set of taxes to form a single total. Result is rounded to precision.
155
+     *
156
+     * @param  array $taxes Array of taxes.
157
+     * @return float
158
+     */
159
+    public static function get_tax_total( $taxes ) {
160
+        return self::round( array_sum( $taxes ) );
161
+    }
162
+
163
+    /**
164
+     * Round to precision.
165
+     *
166
+     * Filter example: to return rounding to .5 cents you'd use:
167
+     *
168
+     * function euro_5cent_rounding( $in ) {
169
+     *      return round( $in / 5, 2 ) * 5;
170
+     * }
171
+     * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
172
+     *
173
+     * @param float|int $in Value to round.
174
+     * @return float
175
+     */
176
+    public static function round( $in ) {
177
+        return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
178
+    }
179 179
 
180 180
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Class GetPaid_Tax
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
 	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22 22
 	 * @return array                       Array of tax name => tax amount.
23 23
 	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
24
+	public static function calc_tax($price, $rates, $price_includes_tax = false) {
25 25
 
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
26
+		if ($price_includes_tax) {
27
+			$taxes = self::calc_inclusive_tax($price, $rates);
28 28
 		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
29
+			$taxes = self::calc_exclusive_tax($price, $rates);
30 30
 		}
31 31
 
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
32
+		return apply_filters('getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax);
33 33
 
34 34
 	}
35 35
 
@@ -40,22 +40,22 @@  discard block
 block discarded – undo
40 40
 	 * @param  array $rates Array of tax rates.
41 41
 	 * @return array
42 42
 	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
43
+	public static function calc_inclusive_tax($price, $rates) {
44 44
 		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
45
+		$tax_rates = wp_list_pluck($rates, 'rate', 'name');
46 46
 
47 47
 		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
48
+		$tax_rate  = 1 + (array_sum($tax_rates) / 100);
49 49
 
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
50
+		foreach ($tax_rates as $name => $rate) {
51
+			$the_rate       = ($rate / 100) / $tax_rate;
52
+			$net_price      = $price - ($the_rate * $price);
53
+			$tax_amount     = apply_filters('getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price);
54
+			$taxes[$name] = $tax_amount;
55 55
 		}
56 56
 
57 57
 		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
58
+		$taxes = array_map(array(__CLASS__, 'round'), $taxes);
59 59
 
60 60
 		return $taxes;
61 61
 	}
@@ -67,19 +67,19 @@  discard block
 block discarded – undo
67 67
 	 * @param  array $rates Array of tax rates.
68 68
 	 * @return array
69 69
 	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
70
+	public static function calc_exclusive_tax($price, $rates) {
71 71
 		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
72
+		$tax_rates = wp_list_pluck($rates, 'rate', 'name');
73 73
 
74
-		foreach ( $tax_rates as $name => $rate ) {
74
+		foreach ($tax_rates as $name => $rate) {
75 75
 
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
76
+			$tax_amount     = $price * ($rate / 100);
77
+			$taxes[$name] = apply_filters('getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price);
78 78
 
79 79
 		}
80 80
 
81 81
 		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
82
+		$taxes = array_map(array(__CLASS__, 'round'), $taxes);
83 83
 
84 84
 		return $taxes;
85 85
 	}
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public static function get_all_tax_rates() {
93 93
 
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
94
+		$rates = get_option('wpinv_tax_rates', array());
95 95
 
96 96
 		return apply_filters(
97 97
 			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
98
+			array_filter(wpinv_parse_list($rates))
99 99
 		);
100 100
 
101 101
 	}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 					'state'     => wpinv_get_default_state(),
116 116
 					'global'    => true,
117 117
 					'rate'      => wpinv_get_default_tax_rate(),
118
-					'name'      => __( 'Base Tax', 'invoicing' ),
118
+					'name'      => __('Base Tax', 'invoicing'),
119 119
 				)
120 120
 			)
121 121
 		);
@@ -129,24 +129,24 @@  discard block
 block discarded – undo
129 129
 	 * @param string $state
130 130
 	 * @return array
131 131
 	 */
132
-	public static function get_address_tax_rates( $country, $state ) {
132
+	public static function get_address_tax_rates($country, $state) {
133 133
 
134 134
 		$all_tax_rates  = self::get_all_tax_rates();
135 135
 		$matching_rates = array_merge(
136
-			wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
137
-			wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
136
+			wp_list_filter($all_tax_rates, array('country' => $country)),
137
+			wp_list_filter($all_tax_rates, array('country' => ''))
138 138
 		);
139 139
 
140
-		foreach ( $matching_rates as $i => $rate ) {
140
+		foreach ($matching_rates as $i => $rate) {
141 141
 
142
-			$states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
143
-			if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
144
-				unset( $matching_rates[ $i ] );
142
+			$states = array_filter(wpinv_clean(explode(',', strtolower($rate['state']))));
143
+			if (empty($rate['global']) && !in_array(strtolower($state), $states)) {
144
+				unset($matching_rates[$i]);
145 145
 			}
146 146
 
147 147
 		}
148 148
 
149
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
149
+		return apply_filters('getpaid_get_address_tax_rates', $matching_rates, $country, $state);
150 150
 
151 151
 	}
152 152
 
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 	 * @param  array $taxes Array of taxes.
157 157
 	 * @return float
158 158
 	 */
159
-	public static function get_tax_total( $taxes ) {
160
-		return self::round( array_sum( $taxes ) );
159
+	public static function get_tax_total($taxes) {
160
+		return self::round(array_sum($taxes));
161 161
 	}
162 162
 
163 163
 	/**
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 	 * @param float|int $in Value to round.
174 174
 	 * @return float
175 175
 	 */
176
-	public static function round( $in ) {
177
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
176
+	public static function round($in) {
177
+		return apply_filters('getpaid_tax_round', round($in, 4), $in);
178 178
 	}
179 179
 
180 180
 }
Please login to merge, or discard this patch.
includes/deprecated-functions.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * @deprecated
247 247
  */
248 248
 function wpinv_get_payment_key( $invoice = 0 ) {
249
-	$invoice = new WPInv_Invoice( $invoice );
249
+    $invoice = new WPInv_Invoice( $invoice );
250 250
     return $invoice->get_key();
251 251
 }
252 252
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
  * @deprecated
425 425
  */
426 426
 function wpinv_get_checkout_session() {
427
-	return false;
427
+    return false;
428 428
 }
429 429
 
430 430
 /**
@@ -1273,5 +1273,5 @@  discard block
 block discarded – undo
1273 1273
  * @deprecated
1274 1274
  */
1275 1275
 function wpinv_get_subscription( $invoice ) {
1276
-	return wpinv_get_invoice_subscription( $invoice );
1276
+    return wpinv_get_invoice_subscription( $invoice );
1277 1277
 }
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * @deprecated
@@ -19,48 +19,48 @@  discard block
 block discarded – undo
19 19
  * @deprecated
20 20
  */
21 21
 function wpinv_get_invoice_cart() {
22
-    return wpinv_get_invoice( getpaid_get_current_invoice_id() );
22
+    return wpinv_get_invoice(getpaid_get_current_invoice_id());
23 23
 }
24 24
 
25 25
 /**
26 26
  * @deprecated
27 27
  */
28
-function wpinv_get_invoice_description( $invoice ) {
29
-    $invoice = new WPInv_Invoice( $invoice );
28
+function wpinv_get_invoice_description($invoice) {
29
+    $invoice = new WPInv_Invoice($invoice);
30 30
     return $invoice->get_description();
31 31
 }
32 32
 
33 33
 /**
34 34
  * @deprecated
35 35
  */
36
-function wpinv_get_invoice_currency_code( $invoice ) {
37
-    $invoice = new WPInv_Invoice( $invoice );
36
+function wpinv_get_invoice_currency_code($invoice) {
37
+    $invoice = new WPInv_Invoice($invoice);
38 38
     return $invoice->get_currency();
39 39
 }
40 40
 
41 41
 /**
42 42
  * @deprecated
43 43
  */
44
-function wpinv_get_payment_user_email( $invoice ) {
45
-    $invoice = new WPInv_Invoice( $invoice );
44
+function wpinv_get_payment_user_email($invoice) {
45
+    $invoice = new WPInv_Invoice($invoice);
46 46
     return $invoice->get_email();
47 47
 }
48 48
 
49 49
 /**
50 50
  * @deprecated
51 51
  */
52
-function wpinv_get_user_id( $invoice ) {
53
-    $invoice = new WPInv_Invoice( $invoice );
52
+function wpinv_get_user_id($invoice) {
53
+    $invoice = new WPInv_Invoice($invoice);
54 54
     return $invoice->get_user_id();
55 55
 }
56 56
 
57 57
 /**
58 58
  * @deprecated
59 59
  */
60
-function wpinv_get_invoice_status( $invoice, $return_label = false ) {
61
-    $invoice = new WPInv_Invoice( $invoice );
60
+function wpinv_get_invoice_status($invoice, $return_label = false) {
61
+    $invoice = new WPInv_Invoice($invoice);
62 62
     
63
-    if ( $return_label ) {
63
+    if ($return_label) {
64 64
         return $invoice->get_status_nicename();
65 65
     }
66 66
 
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 /**
71 71
  * @deprecated
72 72
  */
73
-function wpinv_get_payment_gateway( $invoice, $return_label = false ) {
74
-    $invoice = new WPInv_Invoice( $invoice );
73
+function wpinv_get_payment_gateway($invoice, $return_label = false) {
74
+    $invoice = new WPInv_Invoice($invoice);
75 75
 
76
-    if ( $return_label ) {
76
+    if ($return_label) {
77 77
         return $invoice->get_gateway_title();
78 78
     }
79 79
 
@@ -83,75 +83,75 @@  discard block
 block discarded – undo
83 83
 /**
84 84
  * @deprecated
85 85
  */
86
-function wpinv_get_payment_gateway_name( $invoice ) {
87
-    return wpinv_get_payment_gateway( $invoice, true );
86
+function wpinv_get_payment_gateway_name($invoice) {
87
+    return wpinv_get_payment_gateway($invoice, true);
88 88
 }
89 89
 
90 90
 /**
91 91
  * @deprecated
92 92
  */
93
-function wpinv_get_payment_transaction_id( $invoice ) {
94
-    $invoice = new WPInv_Invoice( $invoice );
93
+function wpinv_get_payment_transaction_id($invoice) {
94
+    $invoice = new WPInv_Invoice($invoice);
95 95
     return $invoice->get_transaction_id();
96 96
 }
97 97
 
98 98
 /**
99 99
  * @deprecated
100 100
  */
101
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
102
-    $invoice = new WPInv_Invoice( $invoice_id );
103
-    return $invoice->get_meta( $meta_key, $single );
101
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
102
+    $invoice = new WPInv_Invoice($invoice_id);
103
+    return $invoice->get_meta($meta_key, $single);
104 104
 }
105 105
 
106 106
 /**
107 107
  * @deprecated
108 108
  */
109
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) {
110
-    $invoice = new WPInv_Invoice( $invoice_id );
111
-    return $invoice->update_meta_data( $meta_key, $meta_value );
109
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') {
110
+    $invoice = new WPInv_Invoice($invoice_id);
111
+    return $invoice->update_meta_data($meta_key, $meta_value);
112 112
 }
113 113
 
114 114
 /**
115 115
  * @deprecated
116 116
  */
117
-function wpinv_get_items( $invoice = 0 ) {
118
-    $invoice = new WPInv_Invoice( $invoice );
117
+function wpinv_get_items($invoice = 0) {
118
+    $invoice = new WPInv_Invoice($invoice);
119 119
     return $invoice->get_items();
120 120
 }
121 121
 
122 122
 /**
123 123
  * @deprecated
124 124
  */
125
-function wpinv_get_fees( $invoice = 0 ) {
126
-    $invoice = new WPInv_Invoice( $invoice );
125
+function wpinv_get_fees($invoice = 0) {
126
+    $invoice = new WPInv_Invoice($invoice);
127 127
     return $invoice->get_fees();
128 128
 }
129 129
 
130 130
 /**
131 131
  * @deprecated
132 132
  */
133
-function wpinv_get_invoice_ip( $invoice ) {
134
-    $invoice = new WPInv_Invoice( $invoice );
133
+function wpinv_get_invoice_ip($invoice) {
134
+    $invoice = new WPInv_Invoice($invoice);
135 135
     return $invoice->get_ip();
136 136
 }
137 137
 
138 138
 /**
139 139
  * @deprecated
140 140
  */
141
-function wpinv_get_invoice_user_info( $invoice ) {
142
-    $invoice = new WPInv_Invoice( $invoice );
141
+function wpinv_get_invoice_user_info($invoice) {
142
+    $invoice = new WPInv_Invoice($invoice);
143 143
     return $invoice->get_user_info();
144 144
 }
145 145
 
146 146
 /**
147 147
  * @deprecated
148 148
  */
149
-function wpinv_subtotal( $invoice = 0, $currency = false ) {
150
-    $invoice  = new WPInv_Invoice( $invoice );
149
+function wpinv_subtotal($invoice = 0, $currency = false) {
150
+    $invoice  = new WPInv_Invoice($invoice);
151 151
     $subtotal = $invoice->get_subtotal();
152 152
 
153
-    if ( $currency ) {
154
-        return wpinv_price( $subtotal, $invoice->get_currency() );
153
+    if ($currency) {
154
+        return wpinv_price($subtotal, $invoice->get_currency());
155 155
     }
156 156
 
157 157
     return $subtotal;
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 /**
161 161
  * @deprecated
162 162
  */
163
-function wpinv_tax( $invoice = 0, $currency = false ) {
164
-    $invoice  = new WPInv_Invoice( $invoice );
163
+function wpinv_tax($invoice = 0, $currency = false) {
164
+    $invoice  = new WPInv_Invoice($invoice);
165 165
     $tax      = $invoice->get_total_tax();
166 166
 
167
-    if ( $currency ) {
168
-        return wpinv_price( $tax, $invoice->get_currency() );
167
+    if ($currency) {
168
+        return wpinv_price($tax, $invoice->get_currency());
169 169
     }
170 170
 
171 171
     return $tax;
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 /**
175 175
  * @deprecated
176 176
  */
177
-function wpinv_discount( $invoice = 0, $currency = false ) {
178
-    $invoice  = new WPInv_Invoice( $invoice );
177
+function wpinv_discount($invoice = 0, $currency = false) {
178
+    $invoice  = new WPInv_Invoice($invoice);
179 179
     $discount = $invoice->get_total_discount();
180 180
 
181
-    if ( $currency ) {
182
-        return wpinv_price( $discount, $invoice->get_currency() );
181
+    if ($currency) {
182
+        return wpinv_price($discount, $invoice->get_currency());
183 183
     }
184 184
 
185 185
     return $discount;
@@ -188,20 +188,20 @@  discard block
 block discarded – undo
188 188
 /**
189 189
  * @deprecated
190 190
  */
191
-function wpinv_discount_code( $invoice = 0 ) {
192
-    $invoice = new WPInv_Invoice( $invoice );
191
+function wpinv_discount_code($invoice = 0) {
192
+    $invoice = new WPInv_Invoice($invoice);
193 193
     return $invoice->get_discount_code();
194 194
 }
195 195
 
196 196
 /**
197 197
  * @deprecated
198 198
  */
199
-function wpinv_payment_total( $invoice = 0, $currency = false ) {
200
-    $invoice  = new WPInv_Invoice( $invoice );
199
+function wpinv_payment_total($invoice = 0, $currency = false) {
200
+    $invoice = new WPInv_Invoice($invoice);
201 201
     $total = $invoice->get_total();
202 202
 
203
-    if ( $currency ) {
204
-        return wpinv_price( $total, $invoice->get_currency() );
203
+    if ($currency) {
204
+        return wpinv_price($total, $invoice->get_currency());
205 205
     }
206 206
 
207 207
     return $total;
@@ -210,51 +210,51 @@  discard block
 block discarded – undo
210 210
 /**
211 211
  * @deprecated
212 212
  */
213
-function wpinv_get_date_created( $invoice = 0, $format = '' ) {
214
-    $invoice = new WPInv_Invoice( $invoice );
213
+function wpinv_get_date_created($invoice = 0, $format = '') {
214
+    $invoice = new WPInv_Invoice($invoice);
215 215
 
216
-    $format         = ! empty( $format ) ? $format : get_option( 'date_format' );
216
+    $format         = !empty($format) ? $format : get_option('date_format');
217 217
     $date_created   = $invoice->get_created_date();
218 218
 
219
-    return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : '';
219
+    return empty($date_created) ? date_i18n($format, strtotime($date_created)) : '';
220 220
 }
221 221
 
222 222
 /**
223 223
  * @deprecated
224 224
  */
225
-function wpinv_get_invoice_date( $invoice = 0, $format = '' ) {
226
-    wpinv_get_date_created( $invoice, $format );
225
+function wpinv_get_invoice_date($invoice = 0, $format = '') {
226
+    wpinv_get_date_created($invoice, $format);
227 227
 }
228 228
 
229 229
 /**
230 230
  * @deprecated
231 231
  */
232
-function wpinv_get_invoice_vat_number( $invoice = 0 ) {
233
-    $invoice = new WPInv_Invoice( $invoice );
232
+function wpinv_get_invoice_vat_number($invoice = 0) {
233
+    $invoice = new WPInv_Invoice($invoice);
234 234
     return $invoice->get_vat_number();
235 235
 }
236 236
 
237 237
 /**
238 238
  * @deprecated
239 239
  */
240
-function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
241
-    $invoice = new WPInv_Invoice( $invoice );
242
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
240
+function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
241
+    $invoice = new WPInv_Invoice($invoice);
242
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
243 243
 }
244 244
 
245 245
 /**
246 246
  * @deprecated
247 247
  */
248
-function wpinv_get_payment_key( $invoice = 0 ) {
249
-	$invoice = new WPInv_Invoice( $invoice );
248
+function wpinv_get_payment_key($invoice = 0) {
249
+	$invoice = new WPInv_Invoice($invoice);
250 250
     return $invoice->get_key();
251 251
 }
252 252
 
253 253
 /**
254 254
  * @deprecated
255 255
  */
256
-function wpinv_get_invoice_number( $invoice = 0 ) {
257
-    $invoice = new WPInv_Invoice( $invoice );
256
+function wpinv_get_invoice_number($invoice = 0) {
257
+    $invoice = new WPInv_Invoice($invoice);
258 258
     return $invoice->get_number();
259 259
 }
260 260
 
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
 /**
402 402
  * @deprecated
403 403
  */
404
-function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) {    
405
-    $invoice = new WPInv_Invoice( $invoice );
406
-    return $invoice->update_status( $new_status );
404
+function wpinv_update_payment_status($invoice, $new_status = 'publish') {    
405
+    $invoice = new WPInv_Invoice($invoice);
406
+    return $invoice->update_status($new_status);
407 407
 }
408 408
 
409 409
 /**
@@ -456,22 +456,22 @@  discard block
 block discarded – undo
456 456
 /**
457 457
  * @deprecated
458 458
  */
459
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
459
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
460 460
 
461 461
     // Fetch the invoice.
462
-    $invoice = new WPInv_Invoice( $invoice_id );
462
+    $invoice = new WPInv_Invoice($invoice_id);
463 463
 
464
-    if ( 0 ==  $invoice->get_id() ) {
464
+    if (0 == $invoice->get_id()) {
465 465
         return false;
466 466
     }
467 467
 
468 468
     // Prepare the transaction id.
469
-    if ( empty( $transaction_id ) ) {
469
+    if (empty($transaction_id)) {
470 470
         $transaction_id = $invoice_id;
471 471
     }
472 472
 
473 473
     // Set the transaction id;
474
-    $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) );
474
+    $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice));
475 475
 
476 476
     // Save the invoice.
477 477
     return $invoice->save();
@@ -484,12 +484,12 @@  discard block
 block discarded – undo
484 484
  * @param WPInv_Invoice $invoice
485 485
  * @param string $gateway
486 486
  */
487
-function wpinv_send_to_gateway( $gateway, $invoice ) {
487
+function wpinv_send_to_gateway($gateway, $invoice) {
488 488
 
489 489
     $payment_data = array(
490 490
         'invoice_id'        => $invoice->get_id(),
491 491
         'items'             => $invoice->get_cart_details(),
492
-        'cart_discounts'    => array( $invoice->get_discount_code() ),
492
+        'cart_discounts'    => array($invoice->get_discount_code()),
493 493
         'fees'              => $invoice->get_total_fees(),
494 494
         'subtotal'          => $invoice->get_subtotal(),
495 495
         'discount'          => $invoice->get_total_discount(),
@@ -497,16 +497,16 @@  discard block
 block discarded – undo
497 497
         'price'             => $invoice->get_total(),
498 498
         'invoice_key'       => $invoice->get_key(),
499 499
         'user_email'        => $invoice->get_email(),
500
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
500
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
501 501
         'user_info'         => $invoice->get_user_info(),
502
-        'post_data'         => stripslashes_deep( $_POST ),
502
+        'post_data'         => stripslashes_deep($_POST),
503 503
         'cart_details'      => $invoice->get_cart_details(),
504 504
         'gateway'           => $gateway,
505 505
         'card_info'         => array(),
506 506
         'gateway_nonce'     => wp_create_nonce('wpi-gateway'),
507 507
     );
508 508
 
509
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
509
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
510 510
 }
511 511
 
512 512
 /**
@@ -519,10 +519,10 @@  discard block
 block discarded – undo
519 519
 /**
520 520
  * @deprecated
521 521
  */
522
-function wpinv_die( $message = '', $title = '', $status = 400 ) {
523
-    add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 );
524
-    add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 );
525
-    wp_die( $message, $title, array( 'response' => $status ));
522
+function wpinv_die($message = '', $title = '', $status = 400) {
523
+    add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3);
524
+    add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3);
525
+    wp_die($message, $title, array('response' => $status));
526 526
 }
527 527
 
528 528
 /**
@@ -640,14 +640,14 @@  discard block
 block discarded – undo
640 640
 /**
641 641
  * @deprecated
642 642
  */
643
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
644
-    return empty( $status_display ) ? sanitize_text_field( $status ) : sanitize_text_field( $status_display );
643
+function wpinv_invoice_status_label($status, $status_display = '') {
644
+    return empty($status_display) ? sanitize_text_field($status) : sanitize_text_field($status_display);
645 645
 }
646 646
 
647 647
 /**
648 648
  * @deprecated
649 649
  */
650
-function wpinv_clean_invoice_number( $number ) {
650
+function wpinv_clean_invoice_number($number) {
651 651
     return $number;
652 652
 }
653 653
 
@@ -852,12 +852,12 @@  discard block
 block discarded – undo
852 852
 /**
853 853
  * @deprecated
854 854
  */
855
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
855
+function wpinv_item_show_price($item_id = 0, $echo = true) {
856 856
 
857
-    if ( $echo ) {
858
-        echo wpinv_item_price( $item_id );
857
+    if ($echo) {
858
+        echo wpinv_item_price($item_id);
859 859
     } else {
860
-        return wpinv_item_price( $item_id );
860
+        return wpinv_item_price($item_id);
861 861
     }
862 862
 
863 863
 }
@@ -1272,6 +1272,6 @@  discard block
 block discarded – undo
1272 1272
  * @return WPInv_Subscription|bool
1273 1273
  * @deprecated
1274 1274
  */
1275
-function wpinv_get_subscription( $invoice ) {
1276
-	return wpinv_get_invoice_subscription( $invoice );
1275
+function wpinv_get_subscription($invoice) {
1276
+	return wpinv_get_invoice_subscription($invoice);
1277 1277
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-subscription-data-store.php 2 patches
Indentation   +182 added lines, -182 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,198 +15,198 @@  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->set_id( 0 );
119
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
120
-			return false;
121
-		}
122
-
123
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
124
-			$method     = "set_$key";
125
-			$subscription->$method( $raw_subscription->$key );
126
-		}
127
-
128
-		$subscription->set_object_read( true );
129
-		do_action( 'getpaid_read_subscription', $subscription );
130
-
131
-	}
132
-
133
-	/**
134
-	 * Method to update a subscription in the database.
135
-	 *
136
-	 * @param WPInv_Subscription $subscription Subscription object.
137
-	 */
138
-	public function update( &$subscription ) {
139
-		global $wpdb;
140
-
141
-		$changes = $subscription->get_changes();
142
-		$values  = array();
143
-		$formats = array();
144
-
145
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
146
-			if ( array_key_exists( $key, $changes ) ) {
147
-				$method       = "get_$key";
148
-				$values[$key] = $subscription->$method( 'edit' );
149
-				$formats[]    = $format;
150
-			}
151
-		}
152
-
153
-		if ( empty( $values ) ) {
154
-			return;
155
-		}
156
-
157
-		$wpdb->update(
158
-			$wpdb->prefix . 'wpinv_subscriptions',
159
-			$values,
160
-			array(
161
-				'id' => $subscription->get_id(),
162
-			),
163
-			$formats,
164
-			'%d'
165
-		);
166
-
167
-		// Apply the changes.
168
-		$subscription->apply_changes();
169
-
170
-		// Delete cache.
171
-		$subscription->clear_cache();
172
-
173
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
174
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
175
-
176
-		// Fire a hook.
177
-		do_action( 'getpaid_update_subscription', $subscription );
178
-
179
-	}
180
-
181
-	/**
182
-	 * Method to delete a subscription from the database.
183
-	 *
184
-	 * @param WPInv_Subscription $subscription
185
-	 */
186
-	public function delete( &$subscription ) {
187
-		global $wpdb;
188
-
189
-		$wpdb->query(
190
-			$wpdb->prepare(
191
-				"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->set_id( 0 );
119
+            $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
120
+            return false;
121
+        }
122
+
123
+        foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
124
+            $method     = "set_$key";
125
+            $subscription->$method( $raw_subscription->$key );
126
+        }
127
+
128
+        $subscription->set_object_read( true );
129
+        do_action( 'getpaid_read_subscription', $subscription );
130
+
131
+    }
132
+
133
+    /**
134
+     * Method to update a subscription in the database.
135
+     *
136
+     * @param WPInv_Subscription $subscription Subscription object.
137
+     */
138
+    public function update( &$subscription ) {
139
+        global $wpdb;
140
+
141
+        $changes = $subscription->get_changes();
142
+        $values  = array();
143
+        $formats = array();
144
+
145
+        foreach ( $this->database_fields_to_data_type as $key => $format ) {
146
+            if ( array_key_exists( $key, $changes ) ) {
147
+                $method       = "get_$key";
148
+                $values[$key] = $subscription->$method( 'edit' );
149
+                $formats[]    = $format;
150
+            }
151
+        }
152
+
153
+        if ( empty( $values ) ) {
154
+            return;
155
+        }
156
+
157
+        $wpdb->update(
158
+            $wpdb->prefix . 'wpinv_subscriptions',
159
+            $values,
160
+            array(
161
+                'id' => $subscription->get_id(),
162
+            ),
163
+            $formats,
164
+            '%d'
165
+        );
166
+
167
+        // Apply the changes.
168
+        $subscription->apply_changes();
169
+
170
+        // Delete cache.
171
+        $subscription->clear_cache();
172
+
173
+        update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
174
+        update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
175
+
176
+        // Fire a hook.
177
+        do_action( 'getpaid_update_subscription', $subscription );
178
+
179
+    }
180
+
181
+    /**
182
+     * Method to delete a subscription from the database.
183
+     *
184
+     * @param WPInv_Subscription $subscription
185
+     */
186
+    public function delete( &$subscription ) {
187
+        global $wpdb;
188
+
189
+        $wpdb->query(
190
+            $wpdb->prepare(
191
+                "DELETE FROM {$wpdb->prefix}wpinv_subscriptions
192 192
 				WHERE id = %d",
193
-				$subscription->get_id()
194
-			)
195
-		);
193
+                $subscription->get_id()
194
+            )
195
+        );
196 196
 
197
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
198
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
197
+        delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
198
+        delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
199 199
 
200
-		// Delete cache.
201
-		$subscription->clear_cache();
200
+        // Delete cache.
201
+        $subscription->clear_cache();
202 202
 
203
-		// Fire a hook.
204
-		do_action( 'getpaid_delete_subscription', $subscription );
203
+        // Fire a hook.
204
+        do_action( 'getpaid_delete_subscription', $subscription );
205 205
 
206
-		$subscription->set_id( 0 );
207
-	}
206
+        $subscription->set_id( 0 );
207
+    }
208 208
 
209
-	/*
209
+    /*
210 210
 	|--------------------------------------------------------------------------
211 211
 	| Additional Methods
212 212
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Subscription_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -50,29 +50,29 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @param WPInv_Subscription $subscription Subscription object.
52 52
 	 */
53
-	public function create( &$subscription ) {
53
+	public function create(&$subscription) {
54 54
 		global $wpdb;
55 55
 
56 56
 		$values  = array();
57 57
 		$formats = array();
58 58
 
59 59
 		$fields = $this->database_fields_to_data_type;
60
-		unset( $fields['id'] );
60
+		unset($fields['id']);
61 61
 
62
-		foreach ( $fields as $key => $format ) {
62
+		foreach ($fields as $key => $format) {
63 63
 			$method       = "get_$key";
64
-			$values[$key] = $subscription->$method( 'edit' );
64
+			$values[$key] = $subscription->$method('edit');
65 65
 			$formats[]    = $format;
66 66
 		}
67 67
 
68
-		$result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats );
68
+		$result = $wpdb->insert($wpdb->prefix . 'wpinv_subscriptions', $values, $formats);
69 69
 
70
-		if ( $result ) {
71
-			$subscription->set_id( $wpdb->insert_id );
70
+		if ($result) {
71
+			$subscription->set_id($wpdb->insert_id);
72 72
 			$subscription->apply_changes();
73 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 );
74
+			update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id());
75
+			do_action('getpaid_new_subscription', $subscription);
76 76
 			return true;
77 77
 		}
78 78
 
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
 	 * @param WPInv_Subscription $subscription Subscription object.
86 86
 	 *
87 87
 	 */
88
-	public function read( &$subscription ) {
88
+	public function read(&$subscription) {
89 89
 		global $wpdb;
90 90
 
91 91
 		$subscription->set_defaults();
92 92
 
93
-		if ( ! $subscription->get_id() ) {
94
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
-			$subscription->set_id( 0 );
93
+		if (!$subscription->get_id()) {
94
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
95
+			$subscription->set_id(0);
96 96
 			return false;
97 97
 		}
98 98
 
99 99
 		// Maybe retrieve from the cache.
100
-		$raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
100
+		$raw_subscription = wp_cache_get($subscription->get_id(), 'getpaid_subscriptions');
101 101
 
102 102
 		// If not found, retrieve from the db.
103
-		if ( false === $raw_subscription ) {
103
+		if (false === $raw_subscription) {
104 104
 
105 105
 			$raw_subscription = $wpdb->get_row(
106 106
 				$wpdb->prepare(
@@ -110,23 +110,23 @@  discard block
 block discarded – undo
110 110
 			);
111 111
 
112 112
 			// Update the cache with our data
113
-			wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
113
+			wp_cache_set($subscription->get_id(), $raw_subscription, 'getpaid_subscriptions');
114 114
 
115 115
 		}
116 116
 
117
-		if ( ! $raw_subscription ) {
118
-			$subscription->set_id( 0 );
119
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
117
+		if (!$raw_subscription) {
118
+			$subscription->set_id(0);
119
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
120 120
 			return false;
121 121
 		}
122 122
 
123
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
124
-			$method     = "set_$key";
125
-			$subscription->$method( $raw_subscription->$key );
123
+		foreach (array_keys($this->database_fields_to_data_type) as $key) {
124
+			$method = "set_$key";
125
+			$subscription->$method($raw_subscription->$key);
126 126
 		}
127 127
 
128
-		$subscription->set_object_read( true );
129
-		do_action( 'getpaid_read_subscription', $subscription );
128
+		$subscription->set_object_read(true);
129
+		do_action('getpaid_read_subscription', $subscription);
130 130
 
131 131
 	}
132 132
 
@@ -135,22 +135,22 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @param WPInv_Subscription $subscription Subscription object.
137 137
 	 */
138
-	public function update( &$subscription ) {
138
+	public function update(&$subscription) {
139 139
 		global $wpdb;
140 140
 
141 141
 		$changes = $subscription->get_changes();
142 142
 		$values  = array();
143 143
 		$formats = array();
144 144
 
145
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
146
-			if ( array_key_exists( $key, $changes ) ) {
145
+		foreach ($this->database_fields_to_data_type as $key => $format) {
146
+			if (array_key_exists($key, $changes)) {
147 147
 				$method       = "get_$key";
148
-				$values[$key] = $subscription->$method( 'edit' );
148
+				$values[$key] = $subscription->$method('edit');
149 149
 				$formats[]    = $format;
150 150
 			}
151 151
 		}
152 152
 
153
-		if ( empty( $values ) ) {
153
+		if (empty($values)) {
154 154
 			return;
155 155
 		}
156 156
 
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 		// Delete cache.
171 171
 		$subscription->clear_cache();
172 172
 
173
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
174
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
173
+		update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id());
174
+		update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id());
175 175
 
176 176
 		// Fire a hook.
177
-		do_action( 'getpaid_update_subscription', $subscription );
177
+		do_action('getpaid_update_subscription', $subscription);
178 178
 
179 179
 	}
180 180
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @param WPInv_Subscription $subscription
185 185
 	 */
186
-	public function delete( &$subscription ) {
186
+	public function delete(&$subscription) {
187 187
 		global $wpdb;
188 188
 
189 189
 		$wpdb->query(
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
 			)
195 195
 		);
196 196
 
197
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
198
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
197
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id');
198
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id');
199 199
 
200 200
 		// Delete cache.
201 201
 		$subscription->clear_cache();
202 202
 
203 203
 		// Fire a hook.
204
-		do_action( 'getpaid_delete_subscription', $subscription );
204
+		do_action('getpaid_delete_subscription', $subscription);
205 205
 
206
-		$subscription->set_id( 0 );
206
+		$subscription->set_id(0);
207 207
 	}
208 208
 
209 209
 	/*
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-subscription.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  */
7 7
 
8 8
 if ( ! defined( 'ABSPATH' ) ) {
9
-	exit; // Exit if accessed directly
9
+    exit; // Exit if accessed directly
10 10
 }
11 11
 
12 12
 /**
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 class GetPaid_Meta_Box_Invoice_Subscription {
16 16
 
17 17
     /**
18
-	 * Output the subscription metabox.
19
-	 *
20
-	 * @param WP_Post $post
21
-	 */
18
+     * Output the subscription metabox.
19
+     *
20
+     * @param WP_Post $post
21
+     */
22 22
     public static function output( $post ) {
23 23
 
24 24
         // Fetch the invoice.
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
     }
35 35
 
36 36
     /**
37
-	 * Output the subscription invoices.
38
-	 *
39
-	 * @param WP_Post $post
40
-	 */
37
+     * Output the subscription invoices.
38
+     *
39
+     * @param WP_Post $post
40
+     */
41 41
     public static function output_invoices( $post ) {
42 42
 
43 43
         // Fetch the invoice.
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
     }
54 54
 
55 55
     /**
56
-	 * Outputs related subscriptions.
57
-	 *
58
-	 * @param WP_Post $post
59
-	 */
56
+     * Outputs related subscriptions.
57
+     *
58
+     * @param WP_Post $post
59
+     */
60 60
     public static function output_related( $post ) {
61 61
 
62 62
         // Fetch the invoice.
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if (!defined('ABSPATH')) {
9 9
 	exit; // Exit if accessed directly
10 10
 }
11 11
 
@@ -19,16 +19,16 @@  discard block
 block discarded – undo
19 19
 	 *
20 20
 	 * @param WP_Post $post
21 21
 	 */
22
-    public static function output( $post ) {
22
+    public static function output($post) {
23 23
 
24 24
         // Fetch the invoice.
25
-        $invoice = new WPInv_Invoice( $post );
25
+        $invoice = new WPInv_Invoice($post);
26 26
 
27 27
         // Fetch the subscription.
28
-        $subscription = getpaid_get_invoice_subscription( $invoice );
28
+        $subscription = getpaid_get_invoice_subscription($invoice);
29 29
 
30 30
         echo '<div class="bsui">';
31
-        getpaid_admin_subscription_details_metabox( /** @scrutinizer ignore-type */$subscription );
31
+        getpaid_admin_subscription_details_metabox(/** @scrutinizer ignore-type */$subscription);
32 32
         echo '</div>';
33 33
 
34 34
     }
@@ -38,16 +38,16 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @param WP_Post $post
40 40
 	 */
41
-    public static function output_invoices( $post ) {
41
+    public static function output_invoices($post) {
42 42
 
43 43
         // Fetch the invoice.
44
-        $invoice = new WPInv_Invoice( $post );
44
+        $invoice = new WPInv_Invoice($post);
45 45
 
46 46
         // Fetch the subscription.
47
-        $subscription = getpaid_get_invoice_subscription( $invoice );
47
+        $subscription = getpaid_get_invoice_subscription($invoice);
48 48
 
49 49
         echo '<div class="bsui">';
50
-        getpaid_admin_subscription_invoice_details_metabox( /** @scrutinizer ignore-type */$subscription, false );
50
+        getpaid_admin_subscription_invoice_details_metabox(/** @scrutinizer ignore-type */$subscription, false);
51 51
         echo '</div>';
52 52
 
53 53
     }
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
 	 *
58 58
 	 * @param WP_Post $post
59 59
 	 */
60
-    public static function output_related( $post ) {
60
+    public static function output_related($post) {
61 61
 
62 62
         // Fetch the invoice.
63
-        $invoice = new WPInv_Invoice( $post );
63
+        $invoice = new WPInv_Invoice($post);
64 64
 
65 65
         // Fetch the subscription.
66
-        $subscription = getpaid_get_invoice_subscription( $invoice );
66
+        $subscription = getpaid_get_invoice_subscription($invoice);
67 67
 
68 68
         echo '<div class="bsui">';
69
-        getpaid_admin_subscription_related_subscriptions_metabox( /** @scrutinizer ignore-type */$subscription, false );
69
+        getpaid_admin_subscription_related_subscriptions_metabox(/** @scrutinizer ignore-type */$subscription, false);
70 70
         echo '</div>';
71 71
 
72 72
     }
Please login to merge, or discard this patch.
widgets/subscriptions.php 2 patches
Indentation   +346 added lines, -346 removed lines patch added patch discarded remove patch
@@ -14,144 +14,144 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_Widget extends WP_Super_Duper {
16 16
 
17
-	/**
18
-	 * Register the widget with WordPress.
19
-	 *
20
-	 */
21
-	public function __construct() {
22
-
23
-		$options = array(
24
-			'textdomain'    => 'invoicing',
25
-			'block-icon'    => 'controls-repeat',
26
-			'block-category'=> 'widgets',
27
-			'block-keywords'=> "['invoicing','subscriptions', 'getpaid']",
28
-			'class_name'     => __CLASS__,
29
-			'base_id'       => 'wpinv_subscriptions',
30
-			'name'          => __( 'GetPaid > Subscriptions', 'invoicing' ),
31
-			'widget_ops'    => array(
32
-				'classname'   => 'getpaid-subscriptions bsui',
33
-				'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
34
-			),
35
-			'arguments'     => array(
36
-				'title'  => array(
37
-					'title'       => __( 'Widget title', 'invoicing' ),
38
-					'desc'        => __( 'Enter widget title.', 'invoicing' ),
39
-					'type'        => 'text',
40
-					'desc_tip'    => true,
41
-					'default'     => '',
42
-					'advanced'    => false
43
-				),
44
-			)
45
-
46
-		);
47
-
48
-
49
-		parent::__construct( $options );
50
-	}
51
-
52
-	/**
53
-	 * Retrieves current user's subscriptions.
54
-	 *
55
-	 * @return GetPaid_Subscriptions_Query
56
-	 */
57
-	public function get_subscriptions() {
58
-
59
-		// Prepare license args.
60
-		$args  = array(
61
-			'customer_in' => get_current_user_id(),
62
-			'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
63
-		);
64
-
65
-		return new GetPaid_Subscriptions_Query( $args );
66
-
67
-	}
68
-
69
-	/**
70
-	 * The Super block output function.
71
-	 *
72
-	 * @param array $args
73
-	 * @param array $widget_args
74
-	 * @param string $content
75
-	 *
76
-	 * @return mixed|string|bool
77
-	 */
78
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
79
-
80
-		// Ensure that the user is logged in.
81
-		if ( ! is_user_logged_in() ) {
82
-
83
-			return aui()->alert(
84
-				array(
85
-					'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
86
-					'type'    => 'error',
87
-				)
88
-			);
89
-
90
-		}
91
-
92
-		// Are we displaying a single subscription?
93
-		if ( isset( $_GET['subscription'] ) ) {
94
-			return $this->display_single_subscription( trim( $_GET['subscription'] ) );
95
-		}
96
-
97
-		// Retrieve the user's subscriptions.
98
-		$subscriptions = $this->get_subscriptions();
99
-
100
-		// Start the output buffer.
101
-		ob_start();
102
-
103
-		// Backwards compatibility.
104
-		do_action( 'wpinv_before_user_subscriptions' );
105
-
106
-		// Display errors and notices.
107
-		wpinv_print_errors();
108
-
109
-		do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
110
-
111
-		// Print the table header.
112
-		$this->print_table_header();
113
-
114
-		// Print table body.
115
-		$this->print_table_body( $subscriptions->get_results() );
116
-
117
-		// Print table footer.
118
-		$this->print_table_footer();
119
-
120
-		// Print the navigation.
121
-		$this->print_navigation( $subscriptions->get_total() );
122
-
123
-		// Backwards compatibility.
124
-		do_action( 'wpinv_after_user_subscriptions' );
125
-
126
-		// Return the output.
127
-		return ob_get_clean();
128
-
129
-	}
130
-
131
-	/**
132
-	 * Retrieves the subscription columns.
133
-	 *
134
-	 * @return array
135
-	 */
136
-	public function get_subscriptions_table_columns() {
17
+    /**
18
+     * Register the widget with WordPress.
19
+     *
20
+     */
21
+    public function __construct() {
22
+
23
+        $options = array(
24
+            'textdomain'    => 'invoicing',
25
+            'block-icon'    => 'controls-repeat',
26
+            'block-category'=> 'widgets',
27
+            'block-keywords'=> "['invoicing','subscriptions', 'getpaid']",
28
+            'class_name'     => __CLASS__,
29
+            'base_id'       => 'wpinv_subscriptions',
30
+            'name'          => __( 'GetPaid > Subscriptions', 'invoicing' ),
31
+            'widget_ops'    => array(
32
+                'classname'   => 'getpaid-subscriptions bsui',
33
+                'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
34
+            ),
35
+            'arguments'     => array(
36
+                'title'  => array(
37
+                    'title'       => __( 'Widget title', 'invoicing' ),
38
+                    'desc'        => __( 'Enter widget title.', 'invoicing' ),
39
+                    'type'        => 'text',
40
+                    'desc_tip'    => true,
41
+                    'default'     => '',
42
+                    'advanced'    => false
43
+                ),
44
+            )
45
+
46
+        );
47
+
48
+
49
+        parent::__construct( $options );
50
+    }
51
+
52
+    /**
53
+     * Retrieves current user's subscriptions.
54
+     *
55
+     * @return GetPaid_Subscriptions_Query
56
+     */
57
+    public function get_subscriptions() {
58
+
59
+        // Prepare license args.
60
+        $args  = array(
61
+            'customer_in' => get_current_user_id(),
62
+            'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
63
+        );
64
+
65
+        return new GetPaid_Subscriptions_Query( $args );
66
+
67
+    }
68
+
69
+    /**
70
+     * The Super block output function.
71
+     *
72
+     * @param array $args
73
+     * @param array $widget_args
74
+     * @param string $content
75
+     *
76
+     * @return mixed|string|bool
77
+     */
78
+    public function output( $args = array(), $widget_args = array(), $content = '' ) {
79
+
80
+        // Ensure that the user is logged in.
81
+        if ( ! is_user_logged_in() ) {
82
+
83
+            return aui()->alert(
84
+                array(
85
+                    'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
86
+                    'type'    => 'error',
87
+                )
88
+            );
89
+
90
+        }
91
+
92
+        // Are we displaying a single subscription?
93
+        if ( isset( $_GET['subscription'] ) ) {
94
+            return $this->display_single_subscription( trim( $_GET['subscription'] ) );
95
+        }
96
+
97
+        // Retrieve the user's subscriptions.
98
+        $subscriptions = $this->get_subscriptions();
99
+
100
+        // Start the output buffer.
101
+        ob_start();
102
+
103
+        // Backwards compatibility.
104
+        do_action( 'wpinv_before_user_subscriptions' );
105
+
106
+        // Display errors and notices.
107
+        wpinv_print_errors();
108
+
109
+        do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
110
+
111
+        // Print the table header.
112
+        $this->print_table_header();
113
+
114
+        // Print table body.
115
+        $this->print_table_body( $subscriptions->get_results() );
116
+
117
+        // Print table footer.
118
+        $this->print_table_footer();
119
+
120
+        // Print the navigation.
121
+        $this->print_navigation( $subscriptions->get_total() );
122
+
123
+        // Backwards compatibility.
124
+        do_action( 'wpinv_after_user_subscriptions' );
125
+
126
+        // Return the output.
127
+        return ob_get_clean();
128
+
129
+    }
130
+
131
+    /**
132
+     * Retrieves the subscription columns.
133
+     *
134
+     * @return array
135
+     */
136
+    public function get_subscriptions_table_columns() {
137 137
 
138
-		$columns = array(
139
-			'subscription'   => __( 'Subscription', 'invoicing' ),
140
-			'amount'         => __( 'Amount', 'invoicing' ),
141
-			'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
-			'status'         => __( 'Status', 'invoicing' ),
143
-		);
138
+        $columns = array(
139
+            'subscription'   => __( 'Subscription', 'invoicing' ),
140
+            'amount'         => __( 'Amount', 'invoicing' ),
141
+            'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
+            'status'         => __( 'Status', 'invoicing' ),
143
+        );
144 144
 
145
-		return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
146
-	}
145
+        return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
146
+    }
147 147
 
148
-	/**
149
-	 * Displays the table header.
150
-	 *
151
-	 */
152
-	public function print_table_header() {
148
+    /**
149
+     * Displays the table header.
150
+     *
151
+     */
152
+    public function print_table_header() {
153 153
 
154
-		?>
154
+        ?>
155 155
 
156 156
 			<table class="table table-bordered table-striped">
157 157
 
@@ -167,121 +167,121 @@  discard block
 block discarded – undo
167 167
 
168 168
 		<?php
169 169
 
170
-	}
170
+    }
171 171
 
172
-	/**
173
-	 * Displays the table body.
174
-	 *
175
-	 * @param WPInv_Subscription[] $subscriptions
176
-	 */
177
-	public function print_table_body( $subscriptions ) {
172
+    /**
173
+     * Displays the table body.
174
+     *
175
+     * @param WPInv_Subscription[] $subscriptions
176
+     */
177
+    public function print_table_body( $subscriptions ) {
178 178
 
179
-		if ( empty( $subscriptions ) ) {
180
-			$this->print_table_body_no_subscriptions();
181
-		} else {
182
-			$this->print_table_body_subscriptions( $subscriptions );
183
-		}
179
+        if ( empty( $subscriptions ) ) {
180
+            $this->print_table_body_no_subscriptions();
181
+        } else {
182
+            $this->print_table_body_subscriptions( $subscriptions );
183
+        }
184 184
 
185
-	}
185
+    }
186 186
 
187
-	/**
188
-	 * Displays the table body if no subscriptions were found.
189
-	 *
190
-	 */
191
-	public function print_table_body_no_subscriptions() {
187
+    /**
188
+     * Displays the table body if no subscriptions were found.
189
+     *
190
+     */
191
+    public function print_table_body_no_subscriptions() {
192 192
 
193
-		?>
193
+        ?>
194 194
 		<tbody>
195 195
 
196 196
 			<tr>
197 197
 				<td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>">
198 198
 
199 199
 					<?php
200
-						echo aui()->alert(
201
-							array(
202
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
203
-								'type'    => 'warning',
204
-							)
205
-						);
206
-					?>
200
+                        echo aui()->alert(
201
+                            array(
202
+                                'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
203
+                                'type'    => 'warning',
204
+                            )
205
+                        );
206
+                    ?>
207 207
 
208 208
 				</td>
209 209
 			</tr>
210 210
 
211 211
 		</tbody>
212 212
 		<?php
213
-	}
213
+    }
214 214
 
215
-	/**
216
-	 * Displays the table body if subscriptions were found.
217
-	 *
218
-	 * @param WPInv_Subscription[] $subscriptions
219
-	 */
220
-	public function print_table_body_subscriptions( $subscriptions ) {
215
+    /**
216
+     * Displays the table body if subscriptions were found.
217
+     *
218
+     * @param WPInv_Subscription[] $subscriptions
219
+     */
220
+    public function print_table_body_subscriptions( $subscriptions ) {
221 221
 
222
-		?>
222
+        ?>
223 223
 		<tbody>
224 224
 
225 225
 			<?php foreach ( $subscriptions as $subscription ) : ?>
226 226
 				<tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>">
227 227
 					<?php
228
-						wpinv_get_template(
229
-							'subscriptions/subscriptions-table-row.php',
230
-							array(
231
-								'subscription' => $subscription,
232
-								'widget'       => $this
233
-							)
234
-						);
235
-					?>
228
+                        wpinv_get_template(
229
+                            'subscriptions/subscriptions-table-row.php',
230
+                            array(
231
+                                'subscription' => $subscription,
232
+                                'widget'       => $this
233
+                            )
234
+                        );
235
+                    ?>
236 236
 				</tr>
237 237
 			<?php endforeach; ?>
238 238
 
239 239
 		</tbody>
240 240
 		<?php
241
-	}
242
-
243
-	/**
244
-	 * Adds row actions to a column
245
-	 *
246
-	 * @param string $content column content
247
-	 * @param WPInv_Subscription $subscription
248
-	 * @since       1.0.0
249
-	 * @return      string
250
-	 */
251
-	public function add_row_actions( $content, $subscription ) {
252
-
253
-		// Prepare row actions.
254
-		$actions = array();
255
-
256
-		// View subscription action.
257
-		$view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
-		$view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
-		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
-
261
-		// Filter the actions.
262
-		$actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
-
264
-		$sanitized  = array();
265
-		foreach ( $actions as $key => $action ) {
266
-			$key         = sanitize_html_class( $key );
267
-			$action      = wp_kses_post( $action );
268
-			$sanitized[] = "<span class='$key'>$action</span>";
269
-		}
270
-
271
-		$row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
-		$row_actions .= implode( ' | ', $sanitized );
273
-		$row_actions .= '</small>';
274
-
275
-		return $content . $row_actions;
276
-	}
277
-
278
-	/**
279
-	 * Displays the table footer.
280
-	 *
281
-	 */
282
-	public function print_table_footer() {
283
-
284
-		?>
241
+    }
242
+
243
+    /**
244
+     * Adds row actions to a column
245
+     *
246
+     * @param string $content column content
247
+     * @param WPInv_Subscription $subscription
248
+     * @since       1.0.0
249
+     * @return      string
250
+     */
251
+    public function add_row_actions( $content, $subscription ) {
252
+
253
+        // Prepare row actions.
254
+        $actions = array();
255
+
256
+        // View subscription action.
257
+        $view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
+        $view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
+        $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
+
261
+        // Filter the actions.
262
+        $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
+
264
+        $sanitized  = array();
265
+        foreach ( $actions as $key => $action ) {
266
+            $key         = sanitize_html_class( $key );
267
+            $action      = wp_kses_post( $action );
268
+            $sanitized[] = "<span class='$key'>$action</span>";
269
+        }
270
+
271
+        $row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
+        $row_actions .= implode( ' | ', $sanitized );
273
+        $row_actions .= '</small>';
274
+
275
+        return $content . $row_actions;
276
+    }
277
+
278
+    /**
279
+     * Displays the table footer.
280
+     *
281
+     */
282
+    public function print_table_footer() {
283
+
284
+        ?>
285 285
 
286 286
 				<tfoot>
287 287
 					<tr>
@@ -296,143 +296,143 @@  discard block
 block discarded – undo
296 296
 			</table>
297 297
 		<?php
298 298
 
299
-	}
299
+    }
300 300
 
301
-	/**
302
-	 * Displays the navigation.
303
-	 *
304
-	 * @param int $total
305
-	 */
306
-	public function print_navigation( $total ) {
301
+    /**
302
+     * Displays the navigation.
303
+     *
304
+     * @param int $total
305
+     */
306
+    public function print_navigation( $total ) {
307 307
 
308
-		if ( $total < 1 ) {
308
+        if ( $total < 1 ) {
309 309
 
310
-			// Out-of-bounds, run the query again without LIMIT for total count.
311
-			$args  = array(
312
-				'customer_in' => get_current_user_id(),
313
-				'fields'      => 'id',
314
-			);
310
+            // Out-of-bounds, run the query again without LIMIT for total count.
311
+            $args  = array(
312
+                'customer_in' => get_current_user_id(),
313
+                'fields'      => 'id',
314
+            );
315 315
 
316
-			$count_query = new GetPaid_Subscriptions_Query( $args );
317
-			$total       = $count_query->get_total();
318
-		}
316
+            $count_query = new GetPaid_Subscriptions_Query( $args );
317
+            $total       = $count_query->get_total();
318
+        }
319 319
 
320
-		// Abort if we do not have pages.
321
-		if ( 2 > $total ) {
322
-			return;
323
-		}
320
+        // Abort if we do not have pages.
321
+        if ( 2 > $total ) {
322
+            return;
323
+        }
324 324
 
325
-		?>
325
+        ?>
326 326
 
327 327
 		<div class="getpaid-subscriptions-pagination">
328 328
 			<?php
329
-				$big = 999999;
330
-
331
-				echo getpaid_paginate_links(
332
-					array(
333
-						'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
334
-						'format'  => '?paged=%#%',
335
-						'total'   => (int) ceil( $total / 10 ),
336
-					)
337
-				);
338
-			?>
329
+                $big = 999999;
330
+
331
+                echo getpaid_paginate_links(
332
+                    array(
333
+                        'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
334
+                        'format'  => '?paged=%#%',
335
+                        'total'   => (int) ceil( $total / 10 ),
336
+                    )
337
+                );
338
+            ?>
339 339
 		</div>
340 340
 
341 341
 		<?php
342
-	}
343
-
344
-	/**
345
-	 * Returns a single subscription's columns.
346
-	 *
347
-	 * @param WPInv_Subscription $subscription
348
-	 *
349
-	 * @return array
350
-	 */
351
-	public function get_single_subscription_columns( $subscription ) {
352
-
353
-		// Prepare subscription detail columns.
354
-		$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
355
-		$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
356
-		$fields             = apply_filters(
357
-			'getpaid_single_subscription_details_fields',
358
-			array(
359
-				'status'           => __( 'Status', 'invoicing' ),
360
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
361
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
362
-				'start_date'       => __( 'Start date', 'invoicing' ),
363
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
364
-				'payments'         => __( 'Payments', 'invoicing' ),
365
-				'item'             => _n( 'Item', 'Items', $items_count, 'invoicing' ),
366
-			),
367
-			$subscription
368
-		);
369
-
370
-		if ( isset( $fields['expiry_date'] ) ) {
371
-
372
-			if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
373
-				$fields['expiry_date'] = __( 'End date', 'invoicing' );
374
-			}
375
-
376
-			if ( 'pending' == $subscription->get_status() ) {
377
-				unset( $fields['expiry_date'] );
378
-			}
379
-
380
-		}
381
-
382
-		if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) {
383
-			unset( $fields['start_date'] );
384
-		}
385
-
386
-		if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
387
-			unset( $fields['initial_amount'] );
388
-		}
389
-
390
-		return $fields;
391
-	}
392
-
393
-	/**
394
-	 * Displays a single subscription.
395
-	 *
396
-	 * @param string $subscription
397
-	 *
398
-	 * @return string
399
-	 */
400
-	public function display_single_subscription( $subscription ) {
401
-
402
-		// Fetch the subscription.
403
-		$subscription = new WPInv_Subscription( (int) $subscription );
404
-
405
-		if ( ! $subscription->exists() ) {
406
-
407
-			return aui()->alert(
408
-				array(
409
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
410
-					'type'    => 'error',
411
-				)
412
-			);
413
-
414
-		}
415
-
416
-		// Ensure that the user owns this subscription key.
417
-		if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
418
-
419
-			return aui()->alert(
420
-				array(
421
-					'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
422
-					'type'    => 'error',
423
-				)
424
-			);
425
-
426
-		}
427
-
428
-		return wpinv_get_template_html(
429
-			'subscriptions/subscription-details.php',
430
-			array(
431
-				'subscription' => $subscription,
432
-				'widget'       => $this
433
-			)
434
-		);
435
-
436
-	}
342
+    }
343
+
344
+    /**
345
+     * Returns a single subscription's columns.
346
+     *
347
+     * @param WPInv_Subscription $subscription
348
+     *
349
+     * @return array
350
+     */
351
+    public function get_single_subscription_columns( $subscription ) {
352
+
353
+        // Prepare subscription detail columns.
354
+        $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
355
+        $items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
356
+        $fields             = apply_filters(
357
+            'getpaid_single_subscription_details_fields',
358
+            array(
359
+                'status'           => __( 'Status', 'invoicing' ),
360
+                'initial_amount'   => __( 'Initial amount', 'invoicing' ),
361
+                'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
362
+                'start_date'       => __( 'Start date', 'invoicing' ),
363
+                'expiry_date'      => __( 'Next payment', 'invoicing' ),
364
+                'payments'         => __( 'Payments', 'invoicing' ),
365
+                'item'             => _n( 'Item', 'Items', $items_count, 'invoicing' ),
366
+            ),
367
+            $subscription
368
+        );
369
+
370
+        if ( isset( $fields['expiry_date'] ) ) {
371
+
372
+            if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
373
+                $fields['expiry_date'] = __( 'End date', 'invoicing' );
374
+            }
375
+
376
+            if ( 'pending' == $subscription->get_status() ) {
377
+                unset( $fields['expiry_date'] );
378
+            }
379
+
380
+        }
381
+
382
+        if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) {
383
+            unset( $fields['start_date'] );
384
+        }
385
+
386
+        if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
387
+            unset( $fields['initial_amount'] );
388
+        }
389
+
390
+        return $fields;
391
+    }
392
+
393
+    /**
394
+     * Displays a single subscription.
395
+     *
396
+     * @param string $subscription
397
+     *
398
+     * @return string
399
+     */
400
+    public function display_single_subscription( $subscription ) {
401
+
402
+        // Fetch the subscription.
403
+        $subscription = new WPInv_Subscription( (int) $subscription );
404
+
405
+        if ( ! $subscription->exists() ) {
406
+
407
+            return aui()->alert(
408
+                array(
409
+                    'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
410
+                    'type'    => 'error',
411
+                )
412
+            );
413
+
414
+        }
415
+
416
+        // Ensure that the user owns this subscription key.
417
+        if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
418
+
419
+            return aui()->alert(
420
+                array(
421
+                    'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
422
+                    'type'    => 'error',
423
+                )
424
+            );
425
+
426
+        }
427
+
428
+        return wpinv_get_template_html(
429
+            'subscriptions/subscription-details.php',
430
+            array(
431
+                'subscription' => $subscription,
432
+                'widget'       => $this
433
+            )
434
+        );
435
+
436
+    }
437 437
 
438 438
 }
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @version 1.0.0
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Contains the subscriptions widget.
@@ -27,15 +27,15 @@  discard block
 block discarded – undo
27 27
 			'block-keywords'=> "['invoicing','subscriptions', 'getpaid']",
28 28
 			'class_name'     => __CLASS__,
29 29
 			'base_id'       => 'wpinv_subscriptions',
30
-			'name'          => __( 'GetPaid > Subscriptions', 'invoicing' ),
30
+			'name'          => __('GetPaid > Subscriptions', 'invoicing'),
31 31
 			'widget_ops'    => array(
32 32
 				'classname'   => 'getpaid-subscriptions bsui',
33
-				'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
33
+				'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'),
34 34
 			),
35 35
 			'arguments'     => array(
36 36
 				'title'  => array(
37
-					'title'       => __( 'Widget title', 'invoicing' ),
38
-					'desc'        => __( 'Enter widget title.', 'invoicing' ),
37
+					'title'       => __('Widget title', 'invoicing'),
38
+					'desc'        => __('Enter widget title.', 'invoicing'),
39 39
 					'type'        => 'text',
40 40
 					'desc_tip'    => true,
41 41
 					'default'     => '',
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		);
47 47
 
48 48
 
49
-		parent::__construct( $options );
49
+		parent::__construct($options);
50 50
 	}
51 51
 
52 52
 	/**
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 	public function get_subscriptions() {
58 58
 
59 59
 		// Prepare license args.
60
-		$args  = array(
60
+		$args = array(
61 61
 			'customer_in' => get_current_user_id(),
62
-			'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
62
+			'paged'       => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
63 63
 		);
64 64
 
65
-		return new GetPaid_Subscriptions_Query( $args );
65
+		return new GetPaid_Subscriptions_Query($args);
66 66
 
67 67
 	}
68 68
 
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return mixed|string|bool
77 77
 	 */
78
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
78
+	public function output($args = array(), $widget_args = array(), $content = '') {
79 79
 
80 80
 		// Ensure that the user is logged in.
81
-		if ( ! is_user_logged_in() ) {
81
+		if (!is_user_logged_in()) {
82 82
 
83 83
 			return aui()->alert(
84 84
 				array(
85
-					'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
85
+					'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')),
86 86
 					'type'    => 'error',
87 87
 				)
88 88
 			);
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 		}
91 91
 
92 92
 		// Are we displaying a single subscription?
93
-		if ( isset( $_GET['subscription'] ) ) {
94
-			return $this->display_single_subscription( trim( $_GET['subscription'] ) );
93
+		if (isset($_GET['subscription'])) {
94
+			return $this->display_single_subscription(trim($_GET['subscription']));
95 95
 		}
96 96
 
97 97
 		// Retrieve the user's subscriptions.
@@ -101,27 +101,27 @@  discard block
 block discarded – undo
101 101
 		ob_start();
102 102
 
103 103
 		// Backwards compatibility.
104
-		do_action( 'wpinv_before_user_subscriptions' );
104
+		do_action('wpinv_before_user_subscriptions');
105 105
 
106 106
 		// Display errors and notices.
107 107
 		wpinv_print_errors();
108 108
 
109
-		do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
109
+		do_action('getpaid_license_manager_before_subscriptions', $subscriptions);
110 110
 
111 111
 		// Print the table header.
112 112
 		$this->print_table_header();
113 113
 
114 114
 		// Print table body.
115
-		$this->print_table_body( $subscriptions->get_results() );
115
+		$this->print_table_body($subscriptions->get_results());
116 116
 
117 117
 		// Print table footer.
118 118
 		$this->print_table_footer();
119 119
 
120 120
 		// Print the navigation.
121
-		$this->print_navigation( $subscriptions->get_total() );
121
+		$this->print_navigation($subscriptions->get_total());
122 122
 
123 123
 		// Backwards compatibility.
124
-		do_action( 'wpinv_after_user_subscriptions' );
124
+		do_action('wpinv_after_user_subscriptions');
125 125
 
126 126
 		// Return the output.
127 127
 		return ob_get_clean();
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 	public function get_subscriptions_table_columns() {
137 137
 
138 138
 		$columns = array(
139
-			'subscription'   => __( 'Subscription', 'invoicing' ),
140
-			'amount'         => __( 'Amount', 'invoicing' ),
141
-			'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
-			'status'         => __( 'Status', 'invoicing' ),
139
+			'subscription'   => __('Subscription', 'invoicing'),
140
+			'amount'         => __('Amount', 'invoicing'),
141
+			'renewal-date'   => __('Next payment', 'invoicing'),
142
+			'status'         => __('Status', 'invoicing'),
143 143
 		);
144 144
 
145
-		return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
145
+		return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns);
146 146
 	}
147 147
 
148 148
 	/**
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 
158 158
 				<thead>
159 159
 					<tr>
160
-						<?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?>
161
-							<th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class( $key ); ?>">
162
-								<?php echo sanitize_text_field( $label ); ?>
160
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
161
+							<th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class($key); ?>">
162
+								<?php echo sanitize_text_field($label); ?>
163 163
 							</th>
164 164
 						<?php endforeach; ?>
165 165
 					</tr>
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 	 *
175 175
 	 * @param WPInv_Subscription[] $subscriptions
176 176
 	 */
177
-	public function print_table_body( $subscriptions ) {
177
+	public function print_table_body($subscriptions) {
178 178
 
179
-		if ( empty( $subscriptions ) ) {
179
+		if (empty($subscriptions)) {
180 180
 			$this->print_table_body_no_subscriptions();
181 181
 		} else {
182
-			$this->print_table_body_subscriptions( $subscriptions );
182
+			$this->print_table_body_subscriptions($subscriptions);
183 183
 		}
184 184
 
185 185
 	}
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 		<tbody>
195 195
 
196 196
 			<tr>
197
-				<td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>">
197
+				<td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>">
198 198
 
199 199
 					<?php
200 200
 						echo aui()->alert(
201 201
 							array(
202
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
202
+								'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')),
203 203
 								'type'    => 'warning',
204 204
 							)
205 205
 						);
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
 	 *
218 218
 	 * @param WPInv_Subscription[] $subscriptions
219 219
 	 */
220
-	public function print_table_body_subscriptions( $subscriptions ) {
220
+	public function print_table_body_subscriptions($subscriptions) {
221 221
 
222 222
 		?>
223 223
 		<tbody>
224 224
 
225
-			<?php foreach ( $subscriptions as $subscription ) : ?>
225
+			<?php foreach ($subscriptions as $subscription) : ?>
226 226
 				<tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>">
227 227
 					<?php
228 228
 						wpinv_get_template(
@@ -248,28 +248,28 @@  discard block
 block discarded – undo
248 248
 	 * @since       1.0.0
249 249
 	 * @return      string
250 250
 	 */
251
-	public function add_row_actions( $content, $subscription ) {
251
+	public function add_row_actions($content, $subscription) {
252 252
 
253 253
 		// Prepare row actions.
254 254
 		$actions = array();
255 255
 
256 256
 		// View subscription action.
257
-		$view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
-		$view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
-		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
257
+		$view_url        = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')));
258
+		$view_url        = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), $view_url));
259
+		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>';
260 260
 
261 261
 		// Filter the actions.
262
-		$actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
262
+		$actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription);
263 263
 
264
-		$sanitized  = array();
265
-		foreach ( $actions as $key => $action ) {
266
-			$key         = sanitize_html_class( $key );
267
-			$action      = wp_kses_post( $action );
264
+		$sanitized = array();
265
+		foreach ($actions as $key => $action) {
266
+			$key         = sanitize_html_class($key);
267
+			$action      = wp_kses_post($action);
268 268
 			$sanitized[] = "<span class='$key'>$action</span>";
269 269
 		}
270 270
 
271 271
 		$row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
-		$row_actions .= implode( ' | ', $sanitized );
272
+		$row_actions .= implode(' | ', $sanitized);
273 273
 		$row_actions .= '</small>';
274 274
 
275 275
 		return $content . $row_actions;
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 
286 286
 				<tfoot>
287 287
 					<tr>
288
-						<?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?>
289
-							<th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class( $key ); ?>">
290
-								<?php echo sanitize_text_field( $label ); ?>
288
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
289
+							<th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class($key); ?>">
290
+								<?php echo sanitize_text_field($label); ?>
291 291
 							</th>
292 292
 						<?php endforeach; ?>
293 293
 					</tr>
@@ -303,22 +303,22 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param int $total
305 305
 	 */
306
-	public function print_navigation( $total ) {
306
+	public function print_navigation($total) {
307 307
 
308
-		if ( $total < 1 ) {
308
+		if ($total < 1) {
309 309
 
310 310
 			// Out-of-bounds, run the query again without LIMIT for total count.
311
-			$args  = array(
311
+			$args = array(
312 312
 				'customer_in' => get_current_user_id(),
313 313
 				'fields'      => 'id',
314 314
 			);
315 315
 
316
-			$count_query = new GetPaid_Subscriptions_Query( $args );
316
+			$count_query = new GetPaid_Subscriptions_Query($args);
317 317
 			$total       = $count_query->get_total();
318 318
 		}
319 319
 
320 320
 		// Abort if we do not have pages.
321
-		if ( 2 > $total ) {
321
+		if (2 > $total) {
322 322
 			return;
323 323
 		}
324 324
 
@@ -330,9 +330,9 @@  discard block
 block discarded – undo
330 330
 
331 331
 				echo getpaid_paginate_links(
332 332
 					array(
333
-						'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
333
+						'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
334 334
 						'format'  => '?paged=%#%',
335
-						'total'   => (int) ceil( $total / 10 ),
335
+						'total'   => (int) ceil($total / 10),
336 336
 					)
337 337
 				);
338 338
 			?>
@@ -348,43 +348,43 @@  discard block
 block discarded – undo
348 348
 	 *
349 349
 	 * @return array
350 350
 	 */
351
-	public function get_single_subscription_columns( $subscription ) {
351
+	public function get_single_subscription_columns($subscription) {
352 352
 
353 353
 		// Prepare subscription detail columns.
354
-		$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
355
-		$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
354
+		$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id());
355
+		$items_count        = empty($subscription_group) ? 1 : count($subscription_group['items']);
356 356
 		$fields             = apply_filters(
357 357
 			'getpaid_single_subscription_details_fields',
358 358
 			array(
359
-				'status'           => __( 'Status', 'invoicing' ),
360
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
361
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
362
-				'start_date'       => __( 'Start date', 'invoicing' ),
363
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
364
-				'payments'         => __( 'Payments', 'invoicing' ),
365
-				'item'             => _n( 'Item', 'Items', $items_count, 'invoicing' ),
359
+				'status'           => __('Status', 'invoicing'),
360
+				'initial_amount'   => __('Initial amount', 'invoicing'),
361
+				'recurring_amount' => __('Recurring amount', 'invoicing'),
362
+				'start_date'       => __('Start date', 'invoicing'),
363
+				'expiry_date'      => __('Next payment', 'invoicing'),
364
+				'payments'         => __('Payments', 'invoicing'),
365
+				'item'             => _n('Item', 'Items', $items_count, 'invoicing'),
366 366
 			),
367 367
 			$subscription
368 368
 		);
369 369
 
370
-		if ( isset( $fields['expiry_date'] ) ) {
370
+		if (isset($fields['expiry_date'])) {
371 371
 
372
-			if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
373
-				$fields['expiry_date'] = __( 'End date', 'invoicing' );
372
+			if (!$subscription->is_active() || $subscription->is_last_renewal()) {
373
+				$fields['expiry_date'] = __('End date', 'invoicing');
374 374
 			}
375 375
 
376
-			if ( 'pending' == $subscription->get_status() ) {
377
-				unset( $fields['expiry_date'] );
376
+			if ('pending' == $subscription->get_status()) {
377
+				unset($fields['expiry_date']);
378 378
 			}
379 379
 
380 380
 		}
381 381
 
382
-		if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) {
383
-			unset( $fields['start_date'] );
382
+		if (isset($fields['start_date']) && 'pending' == $subscription->get_status()) {
383
+			unset($fields['start_date']);
384 384
 		}
385 385
 
386
-		if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
387
-			unset( $fields['initial_amount'] );
386
+		if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) {
387
+			unset($fields['initial_amount']);
388 388
 		}
389 389
 
390 390
 		return $fields;
@@ -397,16 +397,16 @@  discard block
 block discarded – undo
397 397
 	 *
398 398
 	 * @return string
399 399
 	 */
400
-	public function display_single_subscription( $subscription ) {
400
+	public function display_single_subscription($subscription) {
401 401
 
402 402
 		// Fetch the subscription.
403
-		$subscription = new WPInv_Subscription( (int) $subscription );
403
+		$subscription = new WPInv_Subscription((int) $subscription);
404 404
 
405
-		if ( ! $subscription->exists() ) {
405
+		if (!$subscription->exists()) {
406 406
 
407 407
 			return aui()->alert(
408 408
 				array(
409
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
409
+					'content' => wp_kses_post(__('Subscription not found.', 'invoicing')),
410 410
 					'type'    => 'error',
411 411
 				)
412 412
 			);
@@ -414,11 +414,11 @@  discard block
 block discarded – undo
414 414
 		}
415 415
 
416 416
 		// Ensure that the user owns this subscription key.
417
-		if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
417
+		if (get_current_user_id() != $subscription->get_customer_id() && !wpinv_current_user_can_manage_invoicing()) {
418 418
 
419 419
 			return aui()->alert(
420 420
 				array(
421
-					'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
421
+					'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')),
422 422
 					'type'    => 'error',
423 423
 				)
424 424
 			);
Please login to merge, or discard this patch.