Passed
Push — master ( 0a2cdb...97ebee )
by Brian
04:41
created
includes/admin/meta-boxes/class-getpaid-meta-box-item-details.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Item_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the item.
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
                                 // Dynamic pricing.
114 114
                                 if ( $item->supports_dynamic_pricing() ) {
115 115
 
116
-								do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item );
116
+                                do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item );
117 117
 
118
-								// NYP toggle.
119
-								echo aui()->input(
120
-								array(
118
+                                // NYP toggle.
119
+                                echo aui()->input(
120
+                                array(
121 121
                                     'id'      => 'wpinv_name_your_price',
122 122
                                     'name'    => 'wpinv_name_your_price',
123 123
                                     'type'    => 'checkbox',
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
                                     'value'   => '1',
126 126
                                     'checked' => $item->user_can_set_their_price(),
127 127
                                     'no_wrap' => true,
128
-								)
129
-							);
128
+                                )
129
+                            );
130 130
 
131
-							do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item );
131
+                            do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item );
132 132
 
133 133
                                 }
134 134
 
@@ -270,35 +270,35 @@  discard block
 block discarded – undo
270 270
     }
271 271
 
272 272
     /**
273
-	 * Save meta box data.
274
-	 *
275
-	 * @param int $post_id
276
-	 */
277
-	public static function save( $post_id ) {
273
+     * Save meta box data.
274
+     *
275
+     * @param int $post_id
276
+     */
277
+    public static function save( $post_id ) {
278 278
 
279 279
         // Prepare the item.
280 280
         $item = new WPInv_Item( $post_id );
281 281
 
282 282
         // Load new data.
283 283
         $item->set_props(
284
-			array(
285
-				'price'              => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null,
286
-				'vat_rule'           => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
287
-				'vat_class'          => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
288
-				'type'               => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
289
-				'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ),
284
+            array(
285
+                'price'              => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null,
286
+                'vat_rule'           => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
287
+                'vat_class'          => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
288
+                'type'               => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
289
+                'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ),
290 290
                 'minimum_price'      => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null,
291
-				'is_recurring'       => ! empty( $_POST['wpinv_is_recurring'] ),
292
-				'recurring_period'   => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
293
-				'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
-				'recurring_limit'    => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
-				'is_free_trial'      => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
296
-				'trial_period'       => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
297
-				'trial_interval'     => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
298
-			)
291
+                'is_recurring'       => ! empty( $_POST['wpinv_is_recurring'] ),
292
+                'recurring_period'   => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
293
+                'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
+                'recurring_limit'    => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
+                'is_free_trial'      => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
296
+                'trial_period'       => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
297
+                'trial_interval'     => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
298
+            )
299 299
         );
300 300
 
301
-		$item->save();
302
-		do_action( 'getpaid_item_metabox_save', $post_id, $item );
303
-	}
301
+        $item->save();
302
+        do_action( 'getpaid_item_metabox_save', $post_id, $item );
303
+    }
304 304
 }
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,27 +21,27 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the item.
27
-        $item = new WPInv_Item( $post );
27
+        $item = new WPInv_Item($post);
28 28
 
29 29
         // Nonce field.
30
-        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
30
+        wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
31 31
 
32 32
         // Set the currency position.
33 33
         $position = wpinv_currency_position();
34 34
 
35
-        if ( $position == 'left_space' ) {
35
+        if ($position == 'left_space') {
36 36
             $position = 'left';
37 37
         }
38 38
 
39
-        if ( $position == 'right_space' ) {
39
+        if ($position == 'right_space') {
40 40
             $position = 'right';
41 41
         }
42 42
 
43 43
         ?>
44
-        <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr( $item->get_type( 'edit' ) ); ?>" />
44
+        <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr($item->get_type('edit')); ?>" />
45 45
         <style>
46 46
             #poststuff .input-group-text,
47 47
             #poststuff .form-control {
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
         </style>
56 56
         <div class='bsui' style='max-width: 600px;padding-top: 10px;'>
57 57
 
58
-            <?php do_action( 'wpinv_item_details_metabox_before_price', $item ); ?>
58
+            <?php do_action('wpinv_item_details_metabox_before_price', $item); ?>
59 59
             <div class="form-group row">
60
-                <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e( 'Item Price', 'invoicing' ); ?></span></label>
60
+                <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e('Item Price', 'invoicing'); ?></span></label>
61 61
                 <div class="col-sm-8">
62 62
                     <div class="row">
63 63
                         <div class="col-sm-4 getpaid-price-input">
64 64
                             <div class="input-group input-group-sm">
65
-                                <?php if ( 'left' == $position ) : ?>
65
+                                <?php if ('left' == $position) : ?>
66 66
                                 <div class="input-group-prepend">
67 67
                                     <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
68 68
                                 </div>
69 69
                                 <?php endif; ?>
70
-                                <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control">
70
+                                <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_price('edit'))); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control">
71 71
 
72
-                                <?php if ( 'left' != $position ) : ?>
72
+                                <?php if ('left' != $position) : ?>
73 73
                                 <div class="input-group-append">
74 74
                                     <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
75 75
                                 </div>
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
                         </div>
80 80
                         <div class="col-sm-4 wpinv_show_if_recurring">
81 81
                             <?php
82
-                                _e( 'every' );
82
+                                _e('every');
83 83
                                 echo '&nbsp;';
84 84
                             ?>
85
-                            <input type="number" style="max-width: 60px;" value="<?php echo esc_attr( $item->get_recurring_interval( 'edit' ) ); ?>" placeholder="1" name="wpinv_recurring_interval" id="wpinv_recurring_interval" />
85
+                            <input type="number" style="max-width: 60px;" value="<?php echo esc_attr($item->get_recurring_interval('edit')); ?>" placeholder="1" name="wpinv_recurring_interval" id="wpinv_recurring_interval" />
86 86
                         </div>
87 87
                         <div class="col-sm-4 wpinv_show_if_recurring">
88 88
                             <?php
@@ -90,16 +90,16 @@  discard block
 block discarded – undo
90 90
                                     array(
91 91
                                         'id'               => 'wpinv_recurring_period',
92 92
                                         'name'             => 'wpinv_recurring_period',
93
-                                        'label'            => __( 'Period', 'invoicing' ),
94
-                                        'placeholder'      => __( 'Select Period', 'invoicing' ),
95
-                                        'value'            => $item->get_recurring_period( 'edit' ),
93
+                                        'label'            => __('Period', 'invoicing'),
94
+                                        'placeholder'      => __('Select Period', 'invoicing'),
95
+                                        'value'            => $item->get_recurring_period('edit'),
96 96
                                         'select2'          => true,
97 97
                                         'data-allow-clear' => 'false',
98 98
                                         'options'          => array(
99
-                                            'D' => __( 'day(s)', 'invoicing' ),
100
-                                            'W' => __( 'week(s)', 'invoicing' ),
101
-                                            'M' => __( 'month(s)', 'invoicing' ),
102
-                                            'Y' => __( 'year(s)', 'invoicing' ),
99
+                                            'D' => __('day(s)', 'invoicing'),
100
+                                            'W' => __('week(s)', 'invoicing'),
101
+                                            'M' => __('month(s)', 'invoicing'),
102
+                                            'Y' => __('year(s)', 'invoicing'),
103 103
                                         ),
104 104
                                     )
105 105
                                 );
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
                             <?php
112 112
 
113 113
                                 // Dynamic pricing.
114
-                                if ( $item->supports_dynamic_pricing() ) {
114
+                                if ($item->supports_dynamic_pricing()) {
115 115
 
116
-								do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item );
116
+								do_action('wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item);
117 117
 
118 118
 								// NYP toggle.
119 119
 								echo aui()->input(
@@ -121,31 +121,31 @@  discard block
 block discarded – undo
121 121
                                     'id'      => 'wpinv_name_your_price',
122 122
                                     'name'    => 'wpinv_name_your_price',
123 123
                                     'type'    => 'checkbox',
124
-                                    'label'   => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ),
124
+                                    'label'   => apply_filters('wpinv_name_your_price_toggle_text', __('Let customers name their price', 'invoicing')),
125 125
                                     'value'   => '1',
126 126
                                     'checked' => $item->user_can_set_their_price(),
127 127
                                     'no_wrap' => true,
128 128
 								)
129 129
 							);
130 130
 
131
-							do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item );
131
+							do_action('wpinv_item_details_metabox_dynamic_pricing_checkbox', $item);
132 132
 
133 133
                                 }
134 134
 
135 135
                                 // Subscriptions.
136
-                                do_action( 'wpinv_item_details_metabox_before_subscription_checkbox', $item );
136
+                                do_action('wpinv_item_details_metabox_before_subscription_checkbox', $item);
137 137
                                 echo aui()->input(
138 138
                                     array(
139 139
                                         'id'      => 'wpinv_is_recurring',
140 140
                                         'name'    => 'wpinv_is_recurring',
141 141
                                         'type'    => 'checkbox',
142
-                                        'label'   => apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Charge customers a recurring amount for this item', 'invoicing' ) ),
142
+                                        'label'   => apply_filters('wpinv_is_recurring_toggle_text', __('Charge customers a recurring amount for this item', 'invoicing')),
143 143
                                         'value'   => '1',
144 144
                                         'checked' => $item->is_recurring(),
145 145
                                         'no_wrap' => true,
146 146
                                     )
147 147
                                 );
148
-                                do_action( 'wpinv_item_details_metabox_subscription_checkbox', $item );
148
+                                do_action('wpinv_item_details_metabox_subscription_checkbox', $item);
149 149
 
150 150
                             ?>
151 151
                             <div class="wpinv_show_if_recurring">
@@ -155,30 +155,30 @@  discard block
 block discarded – undo
155 155
                     </div>
156 156
                 </div>
157 157
                 <div class="col-sm-1 pt-2 pl-0">
158
-                    <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e( 'Set the subscription price, billing interval and period.', 'invoicing' ); ?>"></span>
158
+                    <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e('Set the subscription price, billing interval and period.', 'invoicing'); ?>"></span>
159 159
                 </div>
160 160
             </div>
161
-            <?php do_action( 'wpinv_item_details_metabox_after_price', $item ); ?>
161
+            <?php do_action('wpinv_item_details_metabox_after_price', $item); ?>
162 162
 
163
-            <?php if ( $item->supports_dynamic_pricing() ) : ?>
164
-                <?php do_action( 'wpinv_item_details_metabox_before_minimum_price', $item ); ?>
163
+            <?php if ($item->supports_dynamic_pricing()) : ?>
164
+                <?php do_action('wpinv_item_details_metabox_before_minimum_price', $item); ?>
165 165
                 <div class="wpinv_show_if_dynamic wpinv_minimum_price">
166 166
 
167 167
                     <div class="form-group row">
168 168
                         <label for="wpinv_minimum_price" class="col-sm-3 col-form-label">
169
-                            <?php _e( 'Minimum Price', 'invoicing' ); ?>
169
+                            <?php _e('Minimum Price', 'invoicing'); ?>
170 170
                         </label>
171 171
                         <div class="col-sm-8">
172 172
                             <div class="input-group input-group-sm">
173
-                                <?php if ( 'left' == $position ) : ?>
173
+                                <?php if ('left' == $position) : ?>
174 174
                                     <div class="input-group-prepend">
175 175
                                         <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
176 176
                                     </div>
177 177
                                 <?php endif; ?>
178 178
 
179
-                                <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control">
179
+                                <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_minimum_price('edit'))); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control">
180 180
 
181
-                                <?php if ( 'left' != $position ) : ?>
181
+                                <?php if ('left' != $position) : ?>
182 182
                                     <div class="input-group-append">
183 183
                                         <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
184 184
                                     </div>
@@ -187,45 +187,45 @@  discard block
 block discarded – undo
187 187
                         </div>
188 188
 
189 189
                         <div class="col-sm-1 pt-2 pl-0">
190
-                            <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the minimum amount that users are allowed to set', 'invoicing' ); ?>"></span>
190
+                            <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the minimum amount that users are allowed to set', 'invoicing'); ?>"></span>
191 191
                         </div>
192 192
                     </div>
193 193
 
194 194
                 </div>
195
-                <?php do_action( 'wpinv_item_details_metabox_minimum_price', $item ); ?>
195
+                <?php do_action('wpinv_item_details_metabox_minimum_price', $item); ?>
196 196
             <?php endif; ?>
197 197
 
198
-            <?php do_action( 'wpinv_item_details_metabox_before_maximum_renewals', $item ); ?>
198
+            <?php do_action('wpinv_item_details_metabox_before_maximum_renewals', $item); ?>
199 199
             <div class="wpinv_show_if_recurring wpinv_maximum_renewals">
200 200
 
201 201
                 <div class="form-group row">
202 202
                     <label for="wpinv_recurring_limit" class="col-sm-3 col-form-label">
203
-                        <?php _e( 'Maximum Renewals', 'invoicing' ); ?>
203
+                        <?php _e('Maximum Renewals', 'invoicing'); ?>
204 204
                     </label>
205 205
                     <div class="col-sm-8">
206
-                        <input type="number" value="<?php echo esc_attr( $item->get_recurring_limit( 'edit' ) ); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" />
206
+                        <input type="number" value="<?php echo esc_attr($item->get_recurring_limit('edit')); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" />
207 207
                     </div>
208 208
                     <div class="col-sm-1 pt-2 pl-0">
209
-                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing' ); ?>"></span>
209
+                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing'); ?>"></span>
210 210
                     </div>
211 211
                 </div>
212 212
 
213 213
             </div>
214
-            <?php do_action( 'wpinv_item_details_metabox_maximum_renewals', $item ); ?>
214
+            <?php do_action('wpinv_item_details_metabox_maximum_renewals', $item); ?>
215 215
 
216
-            <?php do_action( 'wpinv_item_details_metabox_before_free_trial', $item ); ?>
216
+            <?php do_action('wpinv_item_details_metabox_before_free_trial', $item); ?>
217 217
             <div class="wpinv_show_if_recurring wpinv_free_trial">
218 218
 
219 219
                 <div class="form-group row">
220
-                    <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php defined( 'GETPAID_PAID_TRIALS_VERSION' ) ? _e( 'Free/Paid Trial', 'invoicing' ) : _e( 'Free Trial', 'invoicing' ); ?></label>
220
+                    <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php defined('GETPAID_PAID_TRIALS_VERSION') ? _e('Free/Paid Trial', 'invoicing') : _e('Free Trial', 'invoicing'); ?></label>
221 221
 
222 222
                     <div class="col-sm-8">
223 223
                         <div class="row">
224 224
                             <div class="col-sm-6">
225
-                                <?php $value = $item->has_free_trial() ? $item->get_trial_interval( 'edit' ) : 0; ?>
225
+                                <?php $value = $item->has_free_trial() ? $item->get_trial_interval('edit') : 0; ?>
226 226
 
227 227
                                 <div>
228
-                                    <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr( $value ); ?>" >
228
+                                    <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr($value); ?>" >
229 229
                                 </div>
230 230
                             </div>
231 231
                             <div class="col-sm-6">
@@ -234,17 +234,17 @@  discard block
 block discarded – undo
234 234
                                         array(
235 235
                                             'id'          => 'wpinv_trial_period',
236 236
                                             'name'        => 'wpinv_trial_period',
237
-                                            'label'       => __( 'Trial Period', 'invoicing' ),
238
-                                            'placeholder' => __( 'Trial Period', 'invoicing' ),
239
-                                            'value'       => $item->get_trial_period( 'edit' ),
237
+                                            'label'       => __('Trial Period', 'invoicing'),
238
+                                            'placeholder' => __('Trial Period', 'invoicing'),
239
+                                            'value'       => $item->get_trial_period('edit'),
240 240
                                             'select2'     => true,
241 241
                                             'data-allow-clear' => 'false',
242 242
                                             'no_wrap'     => true,
243 243
                                             'options'     => array(
244
-                                                'D' => __( 'day(s)', 'invoicing' ),
245
-                                                'W' => __( 'week(s)', 'invoicing' ),
246
-                                                'M' => __( 'month(s)', 'invoicing' ),
247
-                                                'Y' => __( 'year(s)', 'invoicing' ),
244
+                                                'D' => __('day(s)', 'invoicing'),
245
+                                                'W' => __('week(s)', 'invoicing'),
246
+                                                'M' => __('month(s)', 'invoicing'),
247
+                                                'Y' => __('year(s)', 'invoicing'),
248 248
                                             ),
249 249
                                         )
250 250
                                     );
@@ -255,15 +255,15 @@  discard block
 block discarded – undo
255 255
                     </div>
256 256
 
257 257
                     <div class="col-sm-1 pt-2 pl-0">
258
-                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'An optional period of time to wait before charging the first recurring payment.', 'invoicing' ); ?>"></span>
258
+                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('An optional period of time to wait before charging the first recurring payment.', 'invoicing'); ?>"></span>
259 259
                     </div>
260 260
 
261 261
                 </div>
262 262
 
263 263
             </div>
264
-            <?php do_action( 'wpinv_item_details_metabox__free_trial', $item ); ?>
264
+            <?php do_action('wpinv_item_details_metabox__free_trial', $item); ?>
265 265
 
266
-            <?php do_action( 'wpinv_item_details_metabox_item_details', $item ); ?>
266
+            <?php do_action('wpinv_item_details_metabox_item_details', $item); ?>
267 267
         </div>
268 268
         <?php
269 269
 
@@ -274,31 +274,31 @@  discard block
 block discarded – undo
274 274
 	 *
275 275
 	 * @param int $post_id
276 276
 	 */
277
-	public static function save( $post_id ) {
277
+	public static function save($post_id) {
278 278
 
279 279
         // Prepare the item.
280
-        $item = new WPInv_Item( $post_id );
280
+        $item = new WPInv_Item($post_id);
281 281
 
282 282
         // Load new data.
283 283
         $item->set_props(
284 284
 			array(
285
-				'price'              => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null,
286
-				'vat_rule'           => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
287
-				'vat_class'          => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
288
-				'type'               => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
289
-				'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ),
290
-                'minimum_price'      => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null,
291
-				'is_recurring'       => ! empty( $_POST['wpinv_is_recurring'] ),
292
-				'recurring_period'   => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
293
-				'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
-				'recurring_limit'    => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
-				'is_free_trial'      => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
296
-				'trial_period'       => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
297
-				'trial_interval'     => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
285
+				'price'              => isset($_POST['wpinv_item_price']) ? getpaid_standardize_amount($_POST['wpinv_item_price']) : null,
286
+				'vat_rule'           => isset($_POST['wpinv_vat_rules']) ? wpinv_clean($_POST['wpinv_vat_rules']) : null,
287
+				'vat_class'          => isset($_POST['wpinv_vat_class']) ? wpinv_clean($_POST['wpinv_vat_class']) : null,
288
+				'type'               => isset($_POST['wpinv_item_type']) ? wpinv_clean($_POST['wpinv_item_type']) : null,
289
+				'is_dynamic_pricing' => !empty($_POST['wpinv_name_your_price']),
290
+                'minimum_price'      => isset($_POST['wpinv_minimum_price']) ? getpaid_standardize_amount($_POST['wpinv_minimum_price']) : null,
291
+				'is_recurring'       => !empty($_POST['wpinv_is_recurring']),
292
+				'recurring_period'   => isset($_POST['wpinv_recurring_period']) ? wpinv_clean($_POST['wpinv_recurring_period']) : null,
293
+				'recurring_interval' => isset($_POST['wpinv_recurring_interval']) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
+				'recurring_limit'    => isset($_POST['wpinv_recurring_limit']) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
+				'is_free_trial'      => isset($_POST['wpinv_trial_interval']) ? (0 != (int) $_POST['wpinv_trial_interval']) : null,
296
+				'trial_period'       => isset($_POST['wpinv_trial_period']) ? wpinv_clean($_POST['wpinv_trial_period']) : null,
297
+				'trial_interval'     => isset($_POST['wpinv_trial_interval']) ? (int) $_POST['wpinv_trial_interval'] : null,
298 298
 			)
299 299
         );
300 300
 
301 301
 		$item->save();
302
-		do_action( 'getpaid_item_metabox_save', $post_id, $item );
302
+		do_action('getpaid_item_metabox_save', $post_id, $item);
303 303
 	}
304 304
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-notes.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,38 +1,38 @@
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( ! defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Notes {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $post;
10 10
 
11
-        $notes = wpinv_get_invoice_notes( $post->ID );
11
+        $notes = wpinv_get_invoice_notes($post->ID);
12 12
 
13 13
         echo '<ul class="invoice_notes">';
14 14
 
15
-        if ( $notes ) {
16
-            foreach ( $notes as $note ) {
17
-                wpinv_get_invoice_note_line_item( $note );
15
+        if ($notes) {
16
+            foreach ($notes as $note) {
17
+                wpinv_get_invoice_note_line_item($note);
18 18
             }
19 19
 } else {
20
-            echo '<li>' . __( 'There are no notes yet.', 'invoicing' ) . '</li>';
20
+            echo '<li>' . __('There are no notes yet.', 'invoicing') . '</li>';
21 21
         }
22 22
 
23 23
         echo '</ul>';
24 24
         ?>
25 25
         <div class="add_note">
26
-            <h4><?php _e( 'Add note', 'invoicing' ); ?></h4>
26
+            <h4><?php _e('Add note', 'invoicing'); ?></h4>
27 27
             <p>
28 28
                 <textarea type="text" name="invoice_note" id="add_invoice_note" class="input-text" cols="20" rows="5"></textarea>
29 29
             </p>
30 30
             <p>
31 31
                 <select name="invoice_note_type" id="invoice_note_type" class="regular-text">
32
-                    <option value=""><?php _e( 'Private note', 'invoicing' ); ?></option>
33
-                    <option value="customer"><?php _e( 'Note to customer', 'invoicing' ); ?></option>
32
+                    <option value=""><?php _e('Private note', 'invoicing'); ?></option>
33
+                    <option value="customer"><?php _e('Note to customer', 'invoicing'); ?></option>
34 34
                 </select>
35
-                <a href="#" class="add_note button"><?php _e( 'Add', 'invoicing' ); ?></a> <span class="description"><?php _e( 'Add a note for your reference, or add a customer note (the user will be notified).', 'invoicing' ); ?></span>
35
+                <a href="#" class="add_note button"><?php _e('Add', 'invoicing'); ?></a> <span class="description"><?php _e('Add a note for your reference, or add a customer note (the user will be notified).', 'invoicing'); ?></span>
36 36
             </p>
37 37
         </div>
38 38
         <?php
Please login to merge, or discard this patch.
includes/admin/class-wpinv-customers-table.php 2 patches
Indentation   +362 added lines, -362 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 // Load WP_List_Table if not loaded
13 13
 if ( ! class_exists( 'WP_List_Table' ) ) {
14
-	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
14
+    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
15 15
 }
16 16
 
17 17
 /**
@@ -23,369 +23,369 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class WPInv_Customers_Table extends WP_List_Table {
25 25
 
26
-	/**
27
-	 * @var int Number of items per page
28
-	 * @since 1.0.19
29
-	 */
30
-	public $per_page = 10;
31
-
32
-	/**
33
-	 * @var int Number of items
34
-	 * @since 1.0.19
35
-	 */
36
-	public $total = 0;
37
-
38
-	/**
39
-	 * Get things started
40
-	 *
41
-	 * @since 1.0.19
42
-	 * @see WP_List_Table::__construct()
43
-	 */
44
-	public function __construct() {
45
-
46
-		// Set parent defaults
47
-		parent::__construct(
26
+    /**
27
+     * @var int Number of items per page
28
+     * @since 1.0.19
29
+     */
30
+    public $per_page = 10;
31
+
32
+    /**
33
+     * @var int Number of items
34
+     * @since 1.0.19
35
+     */
36
+    public $total = 0;
37
+
38
+    /**
39
+     * Get things started
40
+     *
41
+     * @since 1.0.19
42
+     * @see WP_List_Table::__construct()
43
+     */
44
+    public function __construct() {
45
+
46
+        // Set parent defaults
47
+        parent::__construct(
48 48
             array(
49
-				'singular' => 'id',
50
-				'plural'   => 'ids',
51
-				'ajax'     => false,
49
+                'singular' => 'id',
50
+                'plural'   => 'ids',
51
+                'ajax'     => false,
52 52
             )
53 53
         );
54 54
 
55
-	}
56
-
57
-	/**
58
-	 * Gets the name of the primary column.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @access protected
62
-	 *
63
-	 * @return string Name of the primary column.
64
-	 */
65
-	protected function get_primary_column_name() {
66
-		return 'name';
67
-	}
68
-
69
-	/**
70
-	 * This function renders most of the columns in the list table.
71
-	 *
72
-	 * @since 1.0.19
73
-	 *
74
-	 * @param WP_User $item
75
-	 * @param string $column_name The name of the column
76
-	 *
77
-	 * @return string Column Name
78
-	 */
79
-	public function column_default( $item, $column_name ) {
80
-		$value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) );
81
-		return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item );
82
-	}
83
-
84
-	/**
85
-	 * Displays the country column.
86
-	 *
87
-	 * @since 1.0.19
88
-	 *
89
-	 * @param WP_User $user
90
-	 *
91
-	 * @return string Column Name
92
-	 */
93
-	public function column_country( $user ) {
94
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
95
-		if ( $country ) {
96
-			$country = wpinv_country_name( $country );
97
-		}
98
-		return esc_html( $country );
99
-	}
100
-
101
-	/**
102
-	 * Displays the state column.
103
-	 *
104
-	 * @since 1.0.19
105
-	 *
106
-	 * @param WP_User $user
107
-	 *
108
-	 * @return string Column Name
109
-	 */
110
-	public function column_state( $user ) {
111
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
112
-		$state   = $user->_wpinv_state;
113
-		if ( $state ) {
114
-			$state = wpinv_state_name( $state, $country );
115
-		}
116
-
117
-		return esc_html( $state );
118
-	}
119
-
120
-	/**
121
-	 * Displays the signup column.
122
-	 *
123
-	 * @since 1.0.19
124
-	 *
125
-	 * @param WP_User $user
126
-	 *
127
-	 * @return string Column Name
128
-	 */
129
-	public function column_signup( $user ) {
130
-		return getpaid_format_date_value( $user->user_registered );
131
-	}
132
-
133
-	/**
134
-	 * Displays the total spent column.
135
-	 *
136
-	 * @since 1.0.19
137
-	 *
138
-	 * @param WP_User $user
139
-	 *
140
-	 * @return string Column Name
141
-	 */
142
-	public function column_total( $user ) {
143
-		return wpinv_price( $this->column_total_raw( $user ) );
144
-	}
145
-
146
-	/**
147
-	 * Displays the total spent column.
148
-	 *
149
-	 * @since 1.0.19
150
-	 *
151
-	 * @param WP_User $user
152
-	 *
153
-	 * @return float
154
-	 */
155
-	public function column_total_raw( $user ) {
156
-
157
-		$args = array(
158
-			'data'           => array(
159
-
160
-				'total' => array(
161
-					'type'     => 'invoice_data',
162
-					'function' => 'SUM',
163
-					'name'     => 'total_sales',
164
-				),
165
-
166
-			),
167
-			'where'          => array(
168
-
169
-				'author' => array(
170
-					'type'     => 'post_data',
171
-					'value'    => absint( $user->ID ),
172
-					'key'      => 'posts.post_author',
173
-					'operator' => '=',
174
-				),
175
-
176
-			),
177
-			'query_type'     => 'get_var',
178
-			'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ),
179
-		);
180
-
181
-		return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
182
-
183
-	}
184
-
185
-	/**
186
-	 * Displays the total spent column.
187
-	 *
188
-	 * @since 1.0.19
189
-	 *
190
-	 * @param WP_User $user
191
-	 *
192
-	 * @return string Column Name
193
-	 */
194
-	public function column_invoices( $user ) {
195
-
196
-		$args = array(
197
-			'data'           => array(
198
-
199
-				'ID' => array(
200
-					'type'     => 'post_data',
201
-					'function' => 'COUNT',
202
-					'name'     => 'count',
203
-					'distinct' => true,
204
-				),
205
-
206
-			),
207
-			'where'          => array(
208
-
209
-				'author' => array(
210
-					'type'     => 'post_data',
211
-					'value'    => absint( $user->ID ),
212
-					'key'      => 'posts.post_author',
213
-					'operator' => '=',
214
-				),
215
-
216
-			),
217
-			'query_type'     => 'get_var',
218
-			'invoice_status' => array_keys( wpinv_get_invoice_statuses() ),
219
-		);
220
-
221
-		return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
222
-
223
-	}
224
-
225
-	/**
226
-	 * Generates content for a single row of the table
227
-	 * @since 1.0.19
228
-	 *
229
-	 * @param int $item The user id.
230
-	 */
231
-	public function single_row( $item ) {
232
-		$item = get_user_by( 'id', $item );
233
-
234
-		if ( empty( $item ) ) {
235
-			return;
236
-		}
237
-
238
-		echo '<tr>';
239
-		$this->single_row_columns( $item );
240
-		echo '</tr>';
241
-	}
242
-
243
-	/**
244
-	 * Displays the customers name
245
-	 *
246
-	 * @param  WP_User $customer customer.
247
-	 * @return string
248
-	 */
249
-	public function column_name( $customer ) {
250
-
251
-		// Customer view URL.
252
-		$view_url    = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) );
253
-		$row_actions = $this->row_actions(
254
-			array(
255
-				'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
256
-			)
257
-		);
258
-
259
-		// Get user's address.
260
-		$address = wpinv_get_user_address( $customer->ID );
261
-
262
-		// Customer email address.
263
-		$email       = sanitize_email( $customer->user_email );
264
-
265
-		// Customer's avatar.
266
-		$avatar = esc_url( get_avatar_url( $email ) );
267
-		$avatar = "<img src='$avatar' height='32' width='32'/>";
268
-
269
-		// Customer's name.
270
-		$name   = esc_html( "{$address['first_name']} {$address['last_name']}" );
271
-
272
-		if ( ! empty( $name ) ) {
273
-			$name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
274
-		}
275
-
276
-		$email = "<div class='row-title'><a href='$view_url'>$email</a></div>";
277
-
278
-		return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
279
-
280
-	}
281
-
282
-	/**
283
-	 * Retrieve the table columns
284
-	 *
285
-	 * @since 1.0.19
286
-	 * @return array $columns Array of all the list table columns
287
-	 */
288
-	public function get_columns() {
289
-
290
-		$columns = array(
291
-			'name'     => __( 'Name', 'invoicing' ),
292
-			'country'  => __( 'Country', 'invoicing' ),
293
-			'state'    => __( 'State', 'invoicing' ),
294
-			'city'     => __( 'City', 'invoicing' ),
295
-			'zip'      => __( 'ZIP', 'invoicing' ),
296
-			'address'  => __( 'Address', 'invoicing' ),
297
-			'phone'    => __( 'Phone', 'invoicing' ),
298
-			'company'  => __( 'Company', 'invoicing' ),
299
-			'invoices' => __( 'Invoices', 'invoicing' ),
300
-			'total'    => __( 'Total Spend', 'invoicing' ),
301
-			'signup'   => __( 'Date created', 'invoicing' ),
302
-		);
303
-		return apply_filters( 'wpinv_customers_table_columns', $columns );
304
-
305
-	}
306
-
307
-	/**
308
-	 * Retrieve the current page number
309
-	 *
310
-	 * @since 1.0.19
311
-	 * @return int Current page number
312
-	 */
313
-	public function get_paged() {
314
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
315
-	}
316
-
317
-	/**
318
-	 * Returns bulk actions.
319
-	 *
320
-	 * @since 1.0.19
321
-	 * @return void
322
-	 */
323
-	public function bulk_actions( $which = '' ) {
324
-		return array();
325
-	}
326
-
327
-	/**
328
-	 *  Prepares the display query
329
-	 */
330
-	public function prepare_query() {
331
-		global $wpdb;
332
-
333
-		$post_types = '';
334
-
335
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
336
-			$post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type );
337
-		}
338
-
339
-		$post_types = rtrim( $post_types, ' OR' );
340
-
341
-		// Maybe search.
342
-		if ( ! empty( $_POST['s'] ) ) {
343
-			$users = get_users(
344
-				array(
345
-					'search'         => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*',
346
-					'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
347
-					'fields'         => 'ID',
348
-				)
349
-			);
350
-
351
-			$users      = implode( ', ', $users );
352
-			$post_types = "($post_types) AND ( post_author IN ( $users ) )";
353
-		}
354
-
355
-		// Users with invoices.
356
-    	$customers = $wpdb->get_col(
357
-			$wpdb->prepare(
358
-				"SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d",
359
-				$this->get_paged() * 10 - 10,
360
-				$this->per_page
361
-			)
362
-		);
363
-
364
-		$this->items = $customers;
365
-		$this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" );
366
-
367
-	}
368
-
369
-	/**
370
-	 * Setup the final data for the table
371
-	 *
372
-	 * @since 1.0.19
373
-	 * @return void
374
-	 */
375
-	public function prepare_items() {
376
-		$columns               = $this->get_columns();
377
-		$hidden                = array(); // No hidden columns
378
-		$sortable              = $this->get_sortable_columns();
379
-		$this->_column_headers = array( $columns, $hidden, $sortable );
380
-		$this->prepare_query();
381
-
382
-		$this->set_pagination_args(
383
-			array(
384
-				'total_items' => $this->total,
385
-				'per_page'    => $this->per_page,
386
-				'total_pages' => ceil( $this->total / $this->per_page ),
387
-			)
388
-		);
389
-
390
-	}
55
+    }
56
+
57
+    /**
58
+     * Gets the name of the primary column.
59
+     *
60
+     * @since 1.0.19
61
+     * @access protected
62
+     *
63
+     * @return string Name of the primary column.
64
+     */
65
+    protected function get_primary_column_name() {
66
+        return 'name';
67
+    }
68
+
69
+    /**
70
+     * This function renders most of the columns in the list table.
71
+     *
72
+     * @since 1.0.19
73
+     *
74
+     * @param WP_User $item
75
+     * @param string $column_name The name of the column
76
+     *
77
+     * @return string Column Name
78
+     */
79
+    public function column_default( $item, $column_name ) {
80
+        $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) );
81
+        return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item );
82
+    }
83
+
84
+    /**
85
+     * Displays the country column.
86
+     *
87
+     * @since 1.0.19
88
+     *
89
+     * @param WP_User $user
90
+     *
91
+     * @return string Column Name
92
+     */
93
+    public function column_country( $user ) {
94
+        $country = wpinv_sanitize_country( $user->_wpinv_country );
95
+        if ( $country ) {
96
+            $country = wpinv_country_name( $country );
97
+        }
98
+        return esc_html( $country );
99
+    }
100
+
101
+    /**
102
+     * Displays the state column.
103
+     *
104
+     * @since 1.0.19
105
+     *
106
+     * @param WP_User $user
107
+     *
108
+     * @return string Column Name
109
+     */
110
+    public function column_state( $user ) {
111
+        $country = wpinv_sanitize_country( $user->_wpinv_country );
112
+        $state   = $user->_wpinv_state;
113
+        if ( $state ) {
114
+            $state = wpinv_state_name( $state, $country );
115
+        }
116
+
117
+        return esc_html( $state );
118
+    }
119
+
120
+    /**
121
+     * Displays the signup column.
122
+     *
123
+     * @since 1.0.19
124
+     *
125
+     * @param WP_User $user
126
+     *
127
+     * @return string Column Name
128
+     */
129
+    public function column_signup( $user ) {
130
+        return getpaid_format_date_value( $user->user_registered );
131
+    }
132
+
133
+    /**
134
+     * Displays the total spent column.
135
+     *
136
+     * @since 1.0.19
137
+     *
138
+     * @param WP_User $user
139
+     *
140
+     * @return string Column Name
141
+     */
142
+    public function column_total( $user ) {
143
+        return wpinv_price( $this->column_total_raw( $user ) );
144
+    }
145
+
146
+    /**
147
+     * Displays the total spent column.
148
+     *
149
+     * @since 1.0.19
150
+     *
151
+     * @param WP_User $user
152
+     *
153
+     * @return float
154
+     */
155
+    public function column_total_raw( $user ) {
156
+
157
+        $args = array(
158
+            'data'           => array(
159
+
160
+                'total' => array(
161
+                    'type'     => 'invoice_data',
162
+                    'function' => 'SUM',
163
+                    'name'     => 'total_sales',
164
+                ),
165
+
166
+            ),
167
+            'where'          => array(
168
+
169
+                'author' => array(
170
+                    'type'     => 'post_data',
171
+                    'value'    => absint( $user->ID ),
172
+                    'key'      => 'posts.post_author',
173
+                    'operator' => '=',
174
+                ),
175
+
176
+            ),
177
+            'query_type'     => 'get_var',
178
+            'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ),
179
+        );
180
+
181
+        return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
182
+
183
+    }
184
+
185
+    /**
186
+     * Displays the total spent column.
187
+     *
188
+     * @since 1.0.19
189
+     *
190
+     * @param WP_User $user
191
+     *
192
+     * @return string Column Name
193
+     */
194
+    public function column_invoices( $user ) {
195
+
196
+        $args = array(
197
+            'data'           => array(
198
+
199
+                'ID' => array(
200
+                    'type'     => 'post_data',
201
+                    'function' => 'COUNT',
202
+                    'name'     => 'count',
203
+                    'distinct' => true,
204
+                ),
205
+
206
+            ),
207
+            'where'          => array(
208
+
209
+                'author' => array(
210
+                    'type'     => 'post_data',
211
+                    'value'    => absint( $user->ID ),
212
+                    'key'      => 'posts.post_author',
213
+                    'operator' => '=',
214
+                ),
215
+
216
+            ),
217
+            'query_type'     => 'get_var',
218
+            'invoice_status' => array_keys( wpinv_get_invoice_statuses() ),
219
+        );
220
+
221
+        return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
222
+
223
+    }
224
+
225
+    /**
226
+     * Generates content for a single row of the table
227
+     * @since 1.0.19
228
+     *
229
+     * @param int $item The user id.
230
+     */
231
+    public function single_row( $item ) {
232
+        $item = get_user_by( 'id', $item );
233
+
234
+        if ( empty( $item ) ) {
235
+            return;
236
+        }
237
+
238
+        echo '<tr>';
239
+        $this->single_row_columns( $item );
240
+        echo '</tr>';
241
+    }
242
+
243
+    /**
244
+     * Displays the customers name
245
+     *
246
+     * @param  WP_User $customer customer.
247
+     * @return string
248
+     */
249
+    public function column_name( $customer ) {
250
+
251
+        // Customer view URL.
252
+        $view_url    = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) );
253
+        $row_actions = $this->row_actions(
254
+            array(
255
+                'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
256
+            )
257
+        );
258
+
259
+        // Get user's address.
260
+        $address = wpinv_get_user_address( $customer->ID );
261
+
262
+        // Customer email address.
263
+        $email       = sanitize_email( $customer->user_email );
264
+
265
+        // Customer's avatar.
266
+        $avatar = esc_url( get_avatar_url( $email ) );
267
+        $avatar = "<img src='$avatar' height='32' width='32'/>";
268
+
269
+        // Customer's name.
270
+        $name   = esc_html( "{$address['first_name']} {$address['last_name']}" );
271
+
272
+        if ( ! empty( $name ) ) {
273
+            $name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
274
+        }
275
+
276
+        $email = "<div class='row-title'><a href='$view_url'>$email</a></div>";
277
+
278
+        return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
279
+
280
+    }
281
+
282
+    /**
283
+     * Retrieve the table columns
284
+     *
285
+     * @since 1.0.19
286
+     * @return array $columns Array of all the list table columns
287
+     */
288
+    public function get_columns() {
289
+
290
+        $columns = array(
291
+            'name'     => __( 'Name', 'invoicing' ),
292
+            'country'  => __( 'Country', 'invoicing' ),
293
+            'state'    => __( 'State', 'invoicing' ),
294
+            'city'     => __( 'City', 'invoicing' ),
295
+            'zip'      => __( 'ZIP', 'invoicing' ),
296
+            'address'  => __( 'Address', 'invoicing' ),
297
+            'phone'    => __( 'Phone', 'invoicing' ),
298
+            'company'  => __( 'Company', 'invoicing' ),
299
+            'invoices' => __( 'Invoices', 'invoicing' ),
300
+            'total'    => __( 'Total Spend', 'invoicing' ),
301
+            'signup'   => __( 'Date created', 'invoicing' ),
302
+        );
303
+        return apply_filters( 'wpinv_customers_table_columns', $columns );
304
+
305
+    }
306
+
307
+    /**
308
+     * Retrieve the current page number
309
+     *
310
+     * @since 1.0.19
311
+     * @return int Current page number
312
+     */
313
+    public function get_paged() {
314
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
315
+    }
316
+
317
+    /**
318
+     * Returns bulk actions.
319
+     *
320
+     * @since 1.0.19
321
+     * @return void
322
+     */
323
+    public function bulk_actions( $which = '' ) {
324
+        return array();
325
+    }
326
+
327
+    /**
328
+     *  Prepares the display query
329
+     */
330
+    public function prepare_query() {
331
+        global $wpdb;
332
+
333
+        $post_types = '';
334
+
335
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
336
+            $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type );
337
+        }
338
+
339
+        $post_types = rtrim( $post_types, ' OR' );
340
+
341
+        // Maybe search.
342
+        if ( ! empty( $_POST['s'] ) ) {
343
+            $users = get_users(
344
+                array(
345
+                    'search'         => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*',
346
+                    'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
347
+                    'fields'         => 'ID',
348
+                )
349
+            );
350
+
351
+            $users      = implode( ', ', $users );
352
+            $post_types = "($post_types) AND ( post_author IN ( $users ) )";
353
+        }
354
+
355
+        // Users with invoices.
356
+        $customers = $wpdb->get_col(
357
+            $wpdb->prepare(
358
+                "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d",
359
+                $this->get_paged() * 10 - 10,
360
+                $this->per_page
361
+            )
362
+        );
363
+
364
+        $this->items = $customers;
365
+        $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" );
366
+
367
+    }
368
+
369
+    /**
370
+     * Setup the final data for the table
371
+     *
372
+     * @since 1.0.19
373
+     * @return void
374
+     */
375
+    public function prepare_items() {
376
+        $columns               = $this->get_columns();
377
+        $hidden                = array(); // No hidden columns
378
+        $sortable              = $this->get_sortable_columns();
379
+        $this->_column_headers = array( $columns, $hidden, $sortable );
380
+        $this->prepare_query();
381
+
382
+        $this->set_pagination_args(
383
+            array(
384
+                'total_items' => $this->total,
385
+                'per_page'    => $this->per_page,
386
+                'total_pages' => ceil( $this->total / $this->per_page ),
387
+            )
388
+        );
389
+
390
+    }
391 391
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@  discard block
 block discarded – undo
5 5
  */
6 6
 
7 7
 // Exit if accessed directly
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if (!defined('ABSPATH')) {
9 9
 exit;
10 10
 }
11 11
 
12 12
 // Load WP_List_Table if not loaded
13
-if ( ! class_exists( 'WP_List_Table' ) ) {
13
+if (!class_exists('WP_List_Table')) {
14 14
 	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
15 15
 }
16 16
 
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return string Column Name
78 78
 	 */
79
-	public function column_default( $item, $column_name ) {
80
-		$value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) );
81
-		return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item );
79
+	public function column_default($item, $column_name) {
80
+		$value = esc_html(get_user_meta($item->ID, '_wpinv_' . $column_name, true));
81
+		return apply_filters('wpinv_customers_table_column' . $column_name, $value, $item);
82 82
 	}
83 83
 
84 84
 	/**
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @return string Column Name
92 92
 	 */
93
-	public function column_country( $user ) {
94
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
95
-		if ( $country ) {
96
-			$country = wpinv_country_name( $country );
93
+	public function column_country($user) {
94
+		$country = wpinv_sanitize_country($user->_wpinv_country);
95
+		if ($country) {
96
+			$country = wpinv_country_name($country);
97 97
 		}
98
-		return esc_html( $country );
98
+		return esc_html($country);
99 99
 	}
100 100
 
101 101
 	/**
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 	 *
108 108
 	 * @return string Column Name
109 109
 	 */
110
-	public function column_state( $user ) {
111
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
110
+	public function column_state($user) {
111
+		$country = wpinv_sanitize_country($user->_wpinv_country);
112 112
 		$state   = $user->_wpinv_state;
113
-		if ( $state ) {
114
-			$state = wpinv_state_name( $state, $country );
113
+		if ($state) {
114
+			$state = wpinv_state_name($state, $country);
115 115
 		}
116 116
 
117
-		return esc_html( $state );
117
+		return esc_html($state);
118 118
 	}
119 119
 
120 120
 	/**
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 	 *
127 127
 	 * @return string Column Name
128 128
 	 */
129
-	public function column_signup( $user ) {
130
-		return getpaid_format_date_value( $user->user_registered );
129
+	public function column_signup($user) {
130
+		return getpaid_format_date_value($user->user_registered);
131 131
 	}
132 132
 
133 133
 	/**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @return string Column Name
141 141
 	 */
142
-	public function column_total( $user ) {
143
-		return wpinv_price( $this->column_total_raw( $user ) );
142
+	public function column_total($user) {
143
+		return wpinv_price($this->column_total_raw($user));
144 144
 	}
145 145
 
146 146
 	/**
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @return float
154 154
 	 */
155
-	public function column_total_raw( $user ) {
155
+	public function column_total_raw($user) {
156 156
 
157 157
 		$args = array(
158 158
 			'data'           => array(
@@ -168,17 +168,17 @@  discard block
 block discarded – undo
168 168
 
169 169
 				'author' => array(
170 170
 					'type'     => 'post_data',
171
-					'value'    => absint( $user->ID ),
171
+					'value'    => absint($user->ID),
172 172
 					'key'      => 'posts.post_author',
173 173
 					'operator' => '=',
174 174
 				),
175 175
 
176 176
 			),
177 177
 			'query_type'     => 'get_var',
178
-			'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ),
178
+			'invoice_status' => array('wpi-renewal', 'wpi-processing', 'publish'),
179 179
 		);
180 180
 
181
-		return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
181
+		return wpinv_round_amount(GetPaid_Reports_Helper::get_invoice_report_data($args));
182 182
 
183 183
 	}
184 184
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 *
192 192
 	 * @return string Column Name
193 193
 	 */
194
-	public function column_invoices( $user ) {
194
+	public function column_invoices($user) {
195 195
 
196 196
 		$args = array(
197 197
 			'data'           => array(
@@ -208,17 +208,17 @@  discard block
 block discarded – undo
208 208
 
209 209
 				'author' => array(
210 210
 					'type'     => 'post_data',
211
-					'value'    => absint( $user->ID ),
211
+					'value'    => absint($user->ID),
212 212
 					'key'      => 'posts.post_author',
213 213
 					'operator' => '=',
214 214
 				),
215 215
 
216 216
 			),
217 217
 			'query_type'     => 'get_var',
218
-			'invoice_status' => array_keys( wpinv_get_invoice_statuses() ),
218
+			'invoice_status' => array_keys(wpinv_get_invoice_statuses()),
219 219
 		);
220 220
 
221
-		return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
221
+		return absint(GetPaid_Reports_Helper::get_invoice_report_data($args));
222 222
 
223 223
 	}
224 224
 
@@ -228,15 +228,15 @@  discard block
 block discarded – undo
228 228
 	 *
229 229
 	 * @param int $item The user id.
230 230
 	 */
231
-	public function single_row( $item ) {
232
-		$item = get_user_by( 'id', $item );
231
+	public function single_row($item) {
232
+		$item = get_user_by('id', $item);
233 233
 
234
-		if ( empty( $item ) ) {
234
+		if (empty($item)) {
235 235
 			return;
236 236
 		}
237 237
 
238 238
 		echo '<tr>';
239
-		$this->single_row_columns( $item );
239
+		$this->single_row_columns($item);
240 240
 		echo '</tr>';
241 241
 	}
242 242
 
@@ -246,30 +246,30 @@  discard block
 block discarded – undo
246 246
 	 * @param  WP_User $customer customer.
247 247
 	 * @return string
248 248
 	 */
249
-	public function column_name( $customer ) {
249
+	public function column_name($customer) {
250 250
 
251 251
 		// Customer view URL.
252
-		$view_url    = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) );
252
+		$view_url    = esc_url(add_query_arg('user_id', $customer->ID, admin_url('user-edit.php')));
253 253
 		$row_actions = $this->row_actions(
254 254
 			array(
255
-				'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
255
+				'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __('Edit Details', 'invoicing') . '</a>',
256 256
 			)
257 257
 		);
258 258
 
259 259
 		// Get user's address.
260
-		$address = wpinv_get_user_address( $customer->ID );
260
+		$address = wpinv_get_user_address($customer->ID);
261 261
 
262 262
 		// Customer email address.
263
-		$email       = sanitize_email( $customer->user_email );
263
+		$email = sanitize_email($customer->user_email);
264 264
 
265 265
 		// Customer's avatar.
266
-		$avatar = esc_url( get_avatar_url( $email ) );
266
+		$avatar = esc_url(get_avatar_url($email));
267 267
 		$avatar = "<img src='$avatar' height='32' width='32'/>";
268 268
 
269 269
 		// Customer's name.
270
-		$name   = esc_html( "{$address['first_name']} {$address['last_name']}" );
270
+		$name   = esc_html("{$address['first_name']} {$address['last_name']}");
271 271
 
272
-		if ( ! empty( $name ) ) {
272
+		if (!empty($name)) {
273 273
 			$name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
274 274
 		}
275 275
 
@@ -288,19 +288,19 @@  discard block
 block discarded – undo
288 288
 	public function get_columns() {
289 289
 
290 290
 		$columns = array(
291
-			'name'     => __( 'Name', 'invoicing' ),
292
-			'country'  => __( 'Country', 'invoicing' ),
293
-			'state'    => __( 'State', 'invoicing' ),
294
-			'city'     => __( 'City', 'invoicing' ),
295
-			'zip'      => __( 'ZIP', 'invoicing' ),
296
-			'address'  => __( 'Address', 'invoicing' ),
297
-			'phone'    => __( 'Phone', 'invoicing' ),
298
-			'company'  => __( 'Company', 'invoicing' ),
299
-			'invoices' => __( 'Invoices', 'invoicing' ),
300
-			'total'    => __( 'Total Spend', 'invoicing' ),
301
-			'signup'   => __( 'Date created', 'invoicing' ),
291
+			'name'     => __('Name', 'invoicing'),
292
+			'country'  => __('Country', 'invoicing'),
293
+			'state'    => __('State', 'invoicing'),
294
+			'city'     => __('City', 'invoicing'),
295
+			'zip'      => __('ZIP', 'invoicing'),
296
+			'address'  => __('Address', 'invoicing'),
297
+			'phone'    => __('Phone', 'invoicing'),
298
+			'company'  => __('Company', 'invoicing'),
299
+			'invoices' => __('Invoices', 'invoicing'),
300
+			'total'    => __('Total Spend', 'invoicing'),
301
+			'signup'   => __('Date created', 'invoicing'),
302 302
 		);
303
-		return apply_filters( 'wpinv_customers_table_columns', $columns );
303
+		return apply_filters('wpinv_customers_table_columns', $columns);
304 304
 
305 305
 	}
306 306
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * @return int Current page number
312 312
 	 */
313 313
 	public function get_paged() {
314
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
314
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
315 315
 	}
316 316
 
317 317
 	/**
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	 * @since 1.0.19
321 321
 	 * @return void
322 322
 	 */
323
-	public function bulk_actions( $which = '' ) {
323
+	public function bulk_actions($which = '') {
324 324
 		return array();
325 325
 	}
326 326
 
@@ -332,23 +332,23 @@  discard block
 block discarded – undo
332 332
 
333 333
 		$post_types = '';
334 334
 
335
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
336
-			$post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type );
335
+		foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) {
336
+			$post_types .= $wpdb->prepare('post_type=%s OR ', $post_type);
337 337
 		}
338 338
 
339
-		$post_types = rtrim( $post_types, ' OR' );
339
+		$post_types = rtrim($post_types, ' OR');
340 340
 
341 341
 		// Maybe search.
342
-		if ( ! empty( $_POST['s'] ) ) {
342
+		if (!empty($_POST['s'])) {
343 343
 			$users = get_users(
344 344
 				array(
345
-					'search'         => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*',
346
-					'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
345
+					'search'         => '*' . sanitize_text_field(urldecode($_POST['s'])) . '*',
346
+					'search_columns' => array('user_login', 'user_email', 'display_name'),
347 347
 					'fields'         => 'ID',
348 348
 				)
349 349
 			);
350 350
 
351
-			$users      = implode( ', ', $users );
351
+			$users      = implode(', ', $users);
352 352
 			$post_types = "($post_types) AND ( post_author IN ( $users ) )";
353 353
 		}
354 354
 
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 		);
363 363
 
364 364
 		$this->items = $customers;
365
-		$this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" );
365
+		$this->total = (int) $wpdb->get_var("SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types");
366 366
 
367 367
 	}
368 368
 
@@ -376,14 +376,14 @@  discard block
 block discarded – undo
376 376
 		$columns               = $this->get_columns();
377 377
 		$hidden                = array(); // No hidden columns
378 378
 		$sortable              = $this->get_sortable_columns();
379
-		$this->_column_headers = array( $columns, $hidden, $sortable );
379
+		$this->_column_headers = array($columns, $hidden, $sortable);
380 380
 		$this->prepare_query();
381 381
 
382 382
 		$this->set_pagination_args(
383 383
 			array(
384 384
 				'total_items' => $this->total,
385 385
 				'per_page'    => $this->per_page,
386
-				'total_pages' => ceil( $this->total / $this->per_page ),
386
+				'total_pages' => ceil($this->total / $this->per_page),
387 387
 			)
388 388
 		);
389 389
 
Please login to merge, or discard this patch.
includes/admin/register-settings.php 2 patches
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
     $name       = isset( $option['name'] ) ? $option['name'] : '';
193 193
     $cb         = "wpinv_{$option['type']}_callback";
194 194
     $section    = "wpinv_settings_{$tab}_$section";
195
-	$is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
195
+    $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
196 196
 
197
-	if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
198
-		$tip   = wpinv_clean( $option['desc'] );
199
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
200
-		unset( $option['desc'] );
201
-	}
197
+    if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
198
+        $tip   = wpinv_clean( $option['desc'] );
199
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
200
+        unset( $option['desc'] );
201
+    }
202 202
 
203 203
     // Loop through all tabs.
204 204
     add_settings_field(
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
             'faux'            => isset( $option['faux'] ) ? $option['faux'] : false,
226 226
             'onchange'        => isset( $option['onchange'] ) ? $option['onchange'] : '',
227 227
             'custom'          => isset( $option['custom'] ) ? $option['custom'] : '',
228
-			'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
229
-			'class'           => isset( $option['class'] ) ? $option['class'] : '',
230
-			'style'           => isset( $option['style'] ) ? $option['style'] : '',
228
+            'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
229
+            'class'           => isset( $option['class'] ) ? $option['class'] : '',
230
+            'style'           => isset( $option['style'] ) ? $option['style'] : '',
231 231
             'cols'            => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232 232
             'rows'            => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
233 233
         )
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
  * @return array
242 242
  */
243 243
 function wpinv_get_registered_settings() {
244
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
244
+    return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
245 245
 }
246 246
 
247 247
 /**
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
  */
261 261
 function wpinv_settings_sanitize( $input = array() ) {
262 262
 
263
-	$wpinv_options = wpinv_get_options();
264
-	$raw_referrer  = wp_get_raw_referer();
263
+    $wpinv_options = wpinv_get_options();
264
+    $raw_referrer  = wp_get_raw_referer();
265 265
 
266 266
     if ( empty( $raw_referrer ) ) {
267
-		return array_merge( $wpinv_options, $input );
267
+        return array_merge( $wpinv_options, $input );
268 268
     }
269 269
 
270 270
     wp_parse_str( $raw_referrer, $referrer );
271 271
 
272
-	if ( in_array( 'gp-setup', $referrer ) ) {
273
-		return array_merge( $wpinv_options, $input );
274
-	}
272
+    if ( in_array( 'gp-setup', $referrer ) ) {
273
+        return array_merge( $wpinv_options, $input );
274
+    }
275 275
 
276 276
     $settings = wpinv_get_registered_settings();
277 277
     $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
@@ -293,10 +293,10 @@  discard block
 block discarded – undo
293 293
         }
294 294
 
295 295
         // General filter
296
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
296
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
297 297
 
298
-		// Key specific filter.
299
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
298
+        // Key specific filter.
299
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
300 300
     }
301 301
 
302 302
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
 
340 340
     foreach ( $new_rates as $rate ) {
341 341
 
342
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
-		$rate['name']    = sanitize_text_field( $rate['name'] );
344
-		$rate['state']   = sanitize_text_field( $rate['state'] );
345
-		$rate['country'] = sanitize_text_field( $rate['country'] );
346
-		$rate['global']  = empty( $rate['state'] );
347
-		$tax_rates[]     = $rate;
342
+        $rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
+        $rate['name']    = sanitize_text_field( $rate['name'] );
344
+        $rate['state']   = sanitize_text_field( $rate['state'] );
345
+        $rate['country'] = sanitize_text_field( $rate['country'] );
346
+        $rate['global']  = empty( $rate['state'] );
347
+        $tax_rates[]     = $rate;
348 348
 
349
-	}
349
+    }
350 350
 
351 351
     update_option( 'wpinv_tax_rates', $tax_rates );
352 352
 
@@ -359,11 +359,11 @@  discard block
 block discarded – undo
359 359
     $tabs['general']  = __( 'General', 'invoicing' );
360 360
     $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
361 361
     $tabs['taxes']    = __( 'Taxes', 'invoicing' );
362
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
362
+    $tabs['emails']   = __( 'Emails', 'invoicing' );
363 363
 
364
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
365
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
366
-	}
364
+    if ( count( getpaid_get_integration_settings() ) > 0 ) {
365
+        $tabs['integrations'] = __( 'Integrations', 'invoicing' );
366
+    }
367 367
 
368 368
     $tabs['privacy']  = __( 'Privacy', 'invoicing' );
369 369
     $tabs['misc']     = __( 'Misc', 'invoicing' );
@@ -394,52 +394,52 @@  discard block
 block discarded – undo
394 394
         'general'      => apply_filters(
395 395
             'wpinv_settings_sections_general',
396 396
             array(
397
-				'main'             => __( 'General Settings', 'invoicing' ),
398
-				'page_section'     => __( 'Page Settings', 'invoicing' ),
399
-				'currency_section' => __( 'Currency Settings', 'invoicing' ),
400
-				'labels'           => __( 'Label Texts', 'invoicing' ),
397
+                'main'             => __( 'General Settings', 'invoicing' ),
398
+                'page_section'     => __( 'Page Settings', 'invoicing' ),
399
+                'currency_section' => __( 'Currency Settings', 'invoicing' ),
400
+                'labels'           => __( 'Label Texts', 'invoicing' ),
401 401
             )
402 402
         ),
403 403
         'gateways'     => apply_filters(
404 404
             'wpinv_settings_sections_gateways',
405 405
             array(
406
-				'main' => __( 'Gateway Settings', 'invoicing' ),
406
+                'main' => __( 'Gateway Settings', 'invoicing' ),
407 407
             )
408 408
         ),
409 409
         'taxes'        => apply_filters(
410 410
             'wpinv_settings_sections_taxes',
411 411
             array(
412
-				'main'  => __( 'Tax Settings', 'invoicing' ),
413
-				'rates' => __( 'Tax Rates', 'invoicing' ),
414
-				'vat'   => __( 'EU VAT Settings', 'invoicing' ),
412
+                'main'  => __( 'Tax Settings', 'invoicing' ),
413
+                'rates' => __( 'Tax Rates', 'invoicing' ),
414
+                'vat'   => __( 'EU VAT Settings', 'invoicing' ),
415 415
             )
416 416
         ),
417 417
         'emails'       => apply_filters(
418 418
             'wpinv_settings_sections_emails',
419 419
             array(
420
-				'main' => __( 'Email Settings', 'invoicing' ),
420
+                'main' => __( 'Email Settings', 'invoicing' ),
421 421
             )
422 422
         ),
423 423
 
424
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
424
+        'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
425 425
 
426 426
         'privacy'      => apply_filters(
427 427
             'wpinv_settings_sections_privacy',
428 428
             array(
429
-				'main' => __( 'Privacy policy', 'invoicing' ),
429
+                'main' => __( 'Privacy policy', 'invoicing' ),
430 430
             )
431 431
         ),
432 432
         'misc'         => apply_filters(
433 433
             'wpinv_settings_sections_misc',
434 434
             array(
435
-				'main'       => __( 'Miscellaneous', 'invoicing' ),
436
-				'custom-css' => __( 'Custom CSS', 'invoicing' ),
435
+                'main'       => __( 'Miscellaneous', 'invoicing' ),
436
+                'custom-css' => __( 'Custom CSS', 'invoicing' ),
437 437
             )
438 438
         ),
439 439
         'tools'        => apply_filters(
440 440
             'wpinv_settings_sections_tools',
441 441
             array(
442
-				'main' => __( 'Diagnostic Tools', 'invoicing' ),
442
+                'main' => __( 'Diagnostic Tools', 'invoicing' ),
443 443
             )
444 444
         ),
445 445
     );
@@ -450,46 +450,46 @@  discard block
 block discarded – undo
450 450
 }
451 451
 
452 452
 function wpinv_get_pages( $with_slug = false, $default_label = null ) {
453
-	$pages_options = array();
453
+    $pages_options = array();
454 454
 
455
-	if ( $default_label !== null && $default_label !== false ) {
456
-		$pages_options = array( '' => $default_label ); // Blank option
457
-	}
455
+    if ( $default_label !== null && $default_label !== false ) {
456
+        $pages_options = array( '' => $default_label ); // Blank option
457
+    }
458 458
 
459
-	$pages = get_pages();
460
-	if ( $pages ) {
461
-		foreach ( $pages as $page ) {
462
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
459
+    $pages = get_pages();
460
+    if ( $pages ) {
461
+        foreach ( $pages as $page ) {
462
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
463 463
             $pages_options[ $page->ID ] = $title;
464
-		}
465
-	}
464
+        }
465
+    }
466 466
 
467
-	return $pages_options;
467
+    return $pages_options;
468 468
 }
469 469
 
470 470
 function wpinv_header_callback( $args ) {
471
-	if ( ! empty( $args['desc'] ) ) {
471
+    if ( ! empty( $args['desc'] ) ) {
472 472
         echo wp_kses_post( $args['desc'] );
473 473
     }
474 474
 }
475 475
 
476 476
 function wpinv_hidden_callback( $args ) {
477 477
 
478
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
479
-	$value   = wpinv_get_option( $args['id'], $std );
478
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
479
+    $value   = wpinv_get_option( $args['id'], $std );
480 480
 
481
-	if ( isset( $args['set_value'] ) ) {
482
-		$value = $args['set_value'];
483
-	}
481
+    if ( isset( $args['set_value'] ) ) {
482
+        $value = $args['set_value'];
483
+    }
484 484
 
485
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
486
-		$args['readonly'] = true;
487
-		$name  = '';
488
-	} else {
489
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
490
-	}
485
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
486
+        $args['readonly'] = true;
487
+        $name  = '';
488
+    } else {
489
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
490
+    }
491 491
 
492
-	echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
492
+    echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
493 493
 
494 494
 }
495 495
 
@@ -498,12 +498,12 @@  discard block
 block discarded – undo
498 498
  */
499 499
 function wpinv_checkbox_callback( $args ) {
500 500
 
501
-	$std = isset( $args['std'] ) ? $args['std'] : '';
502
-	$std = wpinv_get_option( $args['id'], $std );
503
-	$id  = esc_attr( $args['id'] );
501
+    $std = isset( $args['std'] ) ? $args['std'] : '';
502
+    $std = wpinv_get_option( $args['id'], $std );
503
+    $id  = esc_attr( $args['id'] );
504 504
 
505
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
506
-	?>
505
+    getpaid_hidden_field( "wpinv_settings[$id]", '0' );
506
+    ?>
507 507
 		<fieldset>
508 508
 			<label>
509 509
 				<input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox">
@@ -515,75 +515,75 @@  discard block
 block discarded – undo
515 515
 
516 516
 function wpinv_multicheck_callback( $args ) {
517 517
 
518
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
519
-	$class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
518
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
519
+    $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
520 520
 
521
-	if ( ! empty( $args['options'] ) ) {
521
+    if ( ! empty( $args['options'] ) ) {
522 522
 
523
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
524
-		$value   = wpinv_get_option( $args['id'], $std );
523
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
524
+        $value   = wpinv_get_option( $args['id'], $std );
525 525
 
526
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
526
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
527 527
         foreach ( $args['options'] as $key => $option ) :
528
-			$sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
529
-			if ( in_array( $sanitize_key, $value ) ) {
530
-				$enabled = $sanitize_key;
531
-			} else {
532
-				$enabled = null;
533
-			}
534
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
535
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
536
-		endforeach;
537
-		echo '</div>';
538
-		echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
539
-	}
528
+            $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
529
+            if ( in_array( $sanitize_key, $value ) ) {
530
+                $enabled = $sanitize_key;
531
+            } else {
532
+                $enabled = null;
533
+            }
534
+            echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
535
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
536
+        endforeach;
537
+        echo '</div>';
538
+        echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
539
+    }
540 540
 }
541 541
 
542 542
 function wpinv_payment_icons_callback( $args ) {
543 543
 
544 544
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
545
-	$value   = wpinv_get_option( $args['id'], false );
545
+    $value   = wpinv_get_option( $args['id'], false );
546 546
 
547
-	if ( ! empty( $args['options'] ) ) {
548
-		foreach ( $args['options'] as $key => $option ) {
547
+    if ( ! empty( $args['options'] ) ) {
548
+        foreach ( $args['options'] as $key => $option ) {
549 549
             $sanitize_key = wpinv_sanitize_key( $key );
550 550
 
551
-			if ( empty( $value ) ) {
552
-				$enabled = $option;
553
-			} else {
554
-				$enabled = null;
555
-			}
556
-
557
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
558
-
559
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
560
-
561
-				if ( wpinv_string_is_image_url( $key ) ) {
562
-				echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
563
-				} else {
564
-				$card = strtolower( str_replace( ' ', '', $option ) );
565
-
566
-				if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
567
-					$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
568
-					} else {
569
-					$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
570
-					$content_dir = WP_CONTENT_DIR;
571
-
572
-					if ( function_exists( 'wp_normalize_path' ) ) {
573
-						// Replaces backslashes with forward slashes for Windows systems
574
-						$image = wp_normalize_path( $image );
575
-						$content_dir = wp_normalize_path( $content_dir );
576
-						}
577
-
578
-					$image = str_replace( $content_dir, content_url(), $image );
579
-					}
580
-
581
-				echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
582
-				}
583
-			echo $option . '</label>';
584
-		}
585
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
586
-	}
551
+            if ( empty( $value ) ) {
552
+                $enabled = $option;
553
+            } else {
554
+                $enabled = null;
555
+            }
556
+
557
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
558
+
559
+                echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
560
+
561
+                if ( wpinv_string_is_image_url( $key ) ) {
562
+                echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
563
+                } else {
564
+                $card = strtolower( str_replace( ' ', '', $option ) );
565
+
566
+                if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
567
+                    $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
568
+                    } else {
569
+                    $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
570
+                    $content_dir = WP_CONTENT_DIR;
571
+
572
+                    if ( function_exists( 'wp_normalize_path' ) ) {
573
+                        // Replaces backslashes with forward slashes for Windows systems
574
+                        $image = wp_normalize_path( $image );
575
+                        $content_dir = wp_normalize_path( $content_dir );
576
+                        }
577
+
578
+                    $image = str_replace( $content_dir, content_url(), $image );
579
+                    }
580
+
581
+                echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
582
+                }
583
+            echo $option . '</label>';
584
+        }
585
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
586
+    }
587 587
 }
588 588
 
589 589
 /**
@@ -591,9 +591,9 @@  discard block
 block discarded – undo
591 591
  */
592 592
 function wpinv_radio_callback( $args ) {
593 593
 
594
-	$std = isset( $args['std'] ) ? $args['std'] : '';
595
-	$std = wpinv_get_option( $args['id'], $std );
596
-	?>
594
+    $std = isset( $args['std'] ) ? $args['std'] : '';
595
+    $std = wpinv_get_option( $args['id'], $std );
596
+    ?>
597 597
 		<fieldset>
598 598
 			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
599 599
 				<?php foreach ( $args['options'] as $key => $option ) : ?>
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 			</ul>
608 608
 		</fieldset>
609 609
 	<?php
610
-	getpaid_settings_description_callback( $args );
610
+    getpaid_settings_description_callback( $args );
611 611
 }
612 612
 
613 613
 /**
@@ -615,10 +615,10 @@  discard block
 block discarded – undo
615 615
  */
616 616
 function getpaid_settings_description_callback( $args ) {
617 617
 
618
-	if ( ! empty( $args['desc'] ) ) {
619
-		$description = wp_kses_post( $args['desc'] );
620
-		echo "<p class='description'>$description</p>";
621
-	}
618
+    if ( ! empty( $args['desc'] ) ) {
619
+        $description = wp_kses_post( $args['desc'] );
620
+        echo "<p class='description'>$description</p>";
621
+    }
622 622
 
623 623
 }
624 624
 
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
  */
628 628
 function wpinv_gateways_callback() {
629 629
 
630
-	?>
630
+    ?>
631 631
 		</td>
632 632
 	</tr>
633 633
 	<tr class="bsui">
@@ -641,22 +641,22 @@  discard block
 block discarded – undo
641 641
 
642 642
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
643 643
     $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
644
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
645
-	$value   = wpinv_get_option( $args['id'], $std );
644
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
645
+    $value   = wpinv_get_option( $args['id'], $std );
646 646
 
647
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >';
647
+    echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >';
648 648
 
649
-	foreach ( $args['options'] as $key => $option ) :
650
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
649
+    foreach ( $args['options'] as $key => $option ) :
650
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
651 651
             $selected = selected( $key, $args['selected'], false );
652 652
         } else {
653 653
             $selected = selected( $key, $value, false );
654 654
         }
655
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
656
-	endforeach;
655
+        echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
656
+    endforeach;
657 657
 
658
-	echo '</select>';
659
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
658
+    echo '</select>';
659
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
660 660
 }
661 661
 
662 662
 /**
@@ -667,29 +667,29 @@  discard block
 block discarded – undo
667 667
  */
668 668
 function wpinv_settings_attrs_helper( $args ) {
669 669
 
670
-	$value        = isset( $args['std'] ) ? $args['std'] : '';
671
-	$id           = esc_attr( $args['id'] );
672
-	$placeholder  = esc_attr( $args['placeholder'] );
670
+    $value        = isset( $args['std'] ) ? $args['std'] : '';
671
+    $id           = esc_attr( $args['id'] );
672
+    $placeholder  = esc_attr( $args['placeholder'] );
673 673
 
674
-	if ( ! empty( $args['faux'] ) ) {
675
-		$args['readonly'] = true;
676
-		$name             = '';
677
-	} else {
678
-		$value  = wpinv_get_option( $args['id'], $value );
679
-		$name   = "wpinv_settings[$id]";
680
-	}
674
+    if ( ! empty( $args['faux'] ) ) {
675
+        $args['readonly'] = true;
676
+        $name             = '';
677
+    } else {
678
+        $value  = wpinv_get_option( $args['id'], $value );
679
+        $name   = "wpinv_settings[$id]";
680
+    }
681 681
 
682
-	$value    = is_scalar( $value ) ? esc_attr( $value ) : '';
683
-	$class    = esc_attr( $args['class'] );
684
-	$style    = esc_attr( $args['style'] );
685
-	$readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
682
+    $value    = is_scalar( $value ) ? esc_attr( $value ) : '';
683
+    $class    = esc_attr( $args['class'] );
684
+    $style    = esc_attr( $args['style'] );
685
+    $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
686 686
 
687
-	$onchange = '';
687
+    $onchange = '';
688 688
     if ( ! empty( $args['onchange'] ) ) {
689 689
         $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
690
-	}
690
+    }
691 691
 
692
-	return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
692
+    return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
693 693
 }
694 694
 
695 695
 /**
@@ -697,9 +697,9 @@  discard block
 block discarded – undo
697 697
  */
698 698
 function wpinv_text_callback( $args ) {
699 699
 
700
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
700
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
701 701
 
702
-	?>
702
+    ?>
703 703
 		<label style="width: 100%;">
704 704
 			<input type="text" <?php echo wpinv_settings_attrs_helper( $args ); ?>>
705 705
 			<?php echo wp_kses_post( $desc ); ?>
@@ -713,10 +713,10 @@  discard block
 block discarded – undo
713 713
  */
714 714
 function wpinv_number_callback( $args ) {
715 715
 
716
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
717
-	$attr = wpinv_settings_attrs_helper( $args );
716
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
717
+    $attr = wpinv_settings_attrs_helper( $args );
718 718
 
719
-	?>
719
+    ?>
720 720
 		<label style="width: 100%;">
721 721
 			<input type="number" step="<?php echo floatval( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php echo $attr; ?>>
722 722
 			<?php echo wp_kses_post( $desc ); ?>
@@ -728,34 +728,34 @@  discard block
 block discarded – undo
728 728
 function wpinv_textarea_callback( $args ) {
729 729
 
730 730
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
731
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
732
-	$value   = wpinv_get_option( $args['id'], $std );
731
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
732
+    $value   = wpinv_get_option( $args['id'], $std );
733 733
 
734 734
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
735 735
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
736 736
 
737
-	echo '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
738
-	echo '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
737
+    echo '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
738
+    echo '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
739 739
 
740 740
 }
741 741
 
742 742
 function wpinv_password_callback( $args ) {
743 743
 
744 744
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
745
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
746
-	$value   = wpinv_get_option( $args['id'], $std );
745
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
746
+    $value   = wpinv_get_option( $args['id'], $std );
747 747
 
748
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
749
-	echo '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
750
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
748
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
749
+    echo '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
750
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
751 751
 
752 752
 }
753 753
 
754 754
 function wpinv_missing_callback( $args ) {
755
-	printf(
756
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
757
-		'<strong>' . $args['id'] . '</strong>'
758
-	);
755
+    printf(
756
+        __( 'The callback function used for the %s setting is missing.', 'invoicing' ),
757
+        '<strong>' . $args['id'] . '</strong>'
758
+    );
759 759
 }
760 760
 
761 761
 /**
@@ -763,14 +763,14 @@  discard block
 block discarded – undo
763 763
  */
764 764
 function wpinv_select_callback( $args ) {
765 765
 
766
-	$desc   = wp_kses_post( $args['desc'] );
767
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
768
-	$attr   = wpinv_settings_attrs_helper( $args );
769
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
770
-	$value  = wpinv_get_option( $args['id'], $value );
771
-	$rand   = uniqid( 'random_id' );
766
+    $desc   = wp_kses_post( $args['desc'] );
767
+    $desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
768
+    $attr   = wpinv_settings_attrs_helper( $args );
769
+    $value  = isset( $args['std'] ) ? $args['std'] : '';
770
+    $value  = wpinv_get_option( $args['id'], $value );
771
+    $rand   = uniqid( 'random_id' );
772 772
 
773
-	?>
773
+    ?>
774 774
 		<label style="width: 100%;">
775 775
 			<select <?php echo $attr; ?> data-allow-clear="true">
776 776
 				<?php foreach ( $args['options'] as $option => $name ) : ?>
@@ -803,50 +803,50 @@  discard block
 block discarded – undo
803 803
 function wpinv_color_select_callback( $args ) {
804 804
 
805 805
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
806
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
807
-	$value   = wpinv_get_option( $args['id'], $std );
806
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
807
+    $value   = wpinv_get_option( $args['id'], $std );
808 808
 
809
-	echo '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
809
+    echo '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
810 810
 
811
-	foreach ( $args['options'] as $option => $color ) {
812
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
813
-	}
811
+    foreach ( $args['options'] as $option => $color ) {
812
+        echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
813
+    }
814 814
 
815
-	echo '</select>';
816
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
815
+    echo '</select>';
816
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
817 817
 
818 818
 }
819 819
 
820 820
 function wpinv_rich_editor_callback( $args ) {
821
-	global $wp_version;
821
+    global $wp_version;
822 822
 
823 823
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
824 824
 
825
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
826
-	$value   = wpinv_get_option( $args['id'], $std );
825
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
826
+    $value   = wpinv_get_option( $args['id'], $std );
827 827
 
828
-	if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
829
-		$value = $std;
830
-	}
828
+    if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
829
+        $value = $std;
830
+    }
831 831
 
832
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
832
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
833 833
 
834
-	echo '<div class="getpaid-settings-editor-input">';
835
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
836
-		wp_editor(
834
+    echo '<div class="getpaid-settings-editor-input">';
835
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
836
+        wp_editor(
837 837
             stripslashes( $value ),
838 838
             'wpinv_settings_' . esc_attr( $args['id'] ),
839 839
             array(
840
-				'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
841
-				'textarea_rows' => absint( $rows ),
842
-				'media_buttons' => false,
840
+                'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
841
+                'textarea_rows' => absint( $rows ),
842
+                'media_buttons' => false,
843 843
             )
844 844
         );
845
-	} else {
846
-		echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
847
-	}
845
+    } else {
846
+        echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
847
+    }
848 848
 
849
-	echo '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
849
+    echo '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
850 850
 
851 851
 }
852 852
 
@@ -854,51 +854,51 @@  discard block
 block discarded – undo
854 854
 
855 855
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
856 856
 
857
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
858
-	$value   = wpinv_get_option( $args['id'], $std );
857
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
858
+    $value   = wpinv_get_option( $args['id'], $std );
859 859
 
860
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
861
-	echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
862
-	echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
863
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
860
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
861
+    echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
862
+    echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
863
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
864 864
 
865 865
 }
866 866
 
867 867
 function wpinv_color_callback( $args ) {
868 868
 
869
-	$std         = isset( $args['std'] ) ? $args['std'] : '';
870
-	$value       = wpinv_get_option( $args['id'], $std );
869
+    $std         = isset( $args['std'] ) ? $args['std'] : '';
870
+    $value       = wpinv_get_option( $args['id'], $std );
871 871
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
872 872
 
873
-	echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
874
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
873
+    echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
874
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
875 875
 
876 876
 }
877 877
 
878 878
 function wpinv_country_states_callback( $args ) {
879 879
 
880
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
881
-	$value   = wpinv_get_option( $args['id'], $std );
880
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
881
+    $value   = wpinv_get_option( $args['id'], $std );
882 882
 
883 883
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
884 884
 
885
-	if ( isset( $args['placeholder'] ) ) {
886
-		$placeholder = $args['placeholder'];
887
-	} else {
888
-		$placeholder = '';
889
-	}
885
+    if ( isset( $args['placeholder'] ) ) {
886
+        $placeholder = $args['placeholder'];
887
+    } else {
888
+        $placeholder = '';
889
+    }
890 890
 
891
-	$states = wpinv_get_country_states();
891
+    $states = wpinv_get_country_states();
892 892
 
893
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
894
-	echo '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
893
+    $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
894
+    echo '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
895 895
 
896
-	foreach ( $states as $option => $name ) {
897
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
898
-	}
896
+    foreach ( $states as $option => $name ) {
897
+        echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
898
+    }
899 899
 
900
-	echo '</select>';
901
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
900
+    echo '</select>';
901
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
902 902
 
903 903
 }
904 904
 
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
  */
908 908
 function wpinv_tax_rates_callback() {
909 909
 
910
-	?>
910
+    ?>
911 911
 		</td>
912 912
 	</tr>
913 913
 	<tr class="bsui">
@@ -922,17 +922,17 @@  discard block
 block discarded – undo
922 922
  * Displays a tax rate' edit row.
923 923
  */
924 924
 function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) {
925
-	ob_start();
925
+    ob_start();
926 926
 
927
-	$key                      = sanitize_key( $key );
928
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
929
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
927
+    $key                      = sanitize_key( $key );
928
+    $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
929
+    include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
930 930
 
931
-	if ( $echo ) {
932
-		echo ob_get_clean();
933
-	} else {
934
-		return ob_get_clean();
935
-	}
931
+    if ( $echo ) {
932
+        echo ob_get_clean();
933
+    } else {
934
+        return ob_get_clean();
935
+    }
936 936
 
937 937
 }
938 938
 
@@ -965,14 +965,14 @@  discard block
 block discarded – undo
965 965
                 <td>
966 966
 					<a href="
967 967
                     <?php
968
-						echo esc_url(
969
-							wp_nonce_url(
970
-								add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
971
-								'getpaid-nonce',
972
-								'getpaid-nonce'
973
-							)
974
-						);
975
-					?>
968
+                        echo esc_url(
969
+                            wp_nonce_url(
970
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
971
+                                'getpaid-nonce',
972
+                                'getpaid-nonce'
973
+                            )
974
+                        );
975
+                    ?>
976 976
                     " class="button button-primary"><?php _e( 'Run', 'invoicing' ); ?></a>
977 977
                 </td>
978 978
             </tr>
@@ -984,14 +984,14 @@  discard block
 block discarded – undo
984 984
                 <td>
985 985
 					<a href="
986 986
                     <?php
987
-						echo esc_url(
988
-							wp_nonce_url(
989
-								add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
990
-								'getpaid-nonce',
991
-								'getpaid-nonce'
992
-							)
993
-						);
994
-					?>
987
+                        echo esc_url(
988
+                            wp_nonce_url(
989
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
990
+                                'getpaid-nonce',
991
+                                'getpaid-nonce'
992
+                            )
993
+                        );
994
+                    ?>
995 995
                     " class="button button-primary"><?php _e( 'Run', 'invoicing' ); ?></a>
996 996
                 </td>
997 997
             </tr>
@@ -1003,14 +1003,14 @@  discard block
 block discarded – undo
1003 1003
                 <td>
1004 1004
 					<a href="
1005 1005
                     <?php
1006
-						echo esc_url(
1007
-							wp_nonce_url(
1008
-								add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1009
-								'getpaid-nonce',
1010
-								'getpaid-nonce'
1011
-							)
1012
-						);
1013
-					?>
1006
+                        echo esc_url(
1007
+                            wp_nonce_url(
1008
+                                add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1009
+                                'getpaid-nonce',
1010
+                                'getpaid-nonce'
1011
+                            )
1012
+                        );
1013
+                    ?>
1014 1014
                     " class="button button-primary"><?php _e( 'Run', 'invoicing' ); ?></a>
1015 1015
                 </td>
1016 1016
             </tr>
@@ -1023,14 +1023,14 @@  discard block
 block discarded – undo
1023 1023
                 <td>
1024 1024
 					<a href="
1025 1025
                     <?php
1026
-						echo esc_url(
1027
-							wp_nonce_url(
1028
-								add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1029
-								'getpaid-nonce',
1030
-								'getpaid-nonce'
1031
-							)
1032
-						);
1033
-					?>
1026
+                        echo esc_url(
1027
+                            wp_nonce_url(
1028
+                                add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1029
+                                'getpaid-nonce',
1030
+                                'getpaid-nonce'
1031
+                            )
1032
+                        );
1033
+                    ?>
1034 1034
                     " class="button button-primary"><?php _e( 'Run', 'invoicing' ); ?></a>
1035 1035
                 </td>
1036 1036
             </tr>
@@ -1043,8 +1043,8 @@  discard block
 block discarded – undo
1043 1043
                 <td>
1044 1044
 					<a href="
1045 1045
                     <?php
1046
-						echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1047
-					?>
1046
+                        echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1047
+                    ?>
1048 1048
                     " class="button button-primary"><?php _e( 'Launch', 'invoicing' ); ?></a>
1049 1049
                 </td>
1050 1050
             </tr>
@@ -1059,19 +1059,19 @@  discard block
 block discarded – undo
1059 1059
 
1060 1060
 
1061 1061
 function wpinv_descriptive_text_callback( $args ) {
1062
-	echo wp_kses_post( $args['desc'] );
1062
+    echo wp_kses_post( $args['desc'] );
1063 1063
 }
1064 1064
 
1065 1065
 function wpinv_raw_html_callback( $args ) {
1066
-	echo $args['desc'];
1066
+    echo $args['desc'];
1067 1067
 }
1068 1068
 
1069 1069
 function wpinv_hook_callback( $args ) {
1070
-	do_action( 'wpinv_' . $args['id'], $args );
1070
+    do_action( 'wpinv_' . $args['id'], $args );
1071 1071
 }
1072 1072
 
1073 1073
 function wpinv_set_settings_cap() {
1074
-	return wpinv_get_capability();
1074
+    return wpinv_get_capability();
1075 1075
 }
1076 1076
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1077 1077
 
@@ -1095,15 +1095,15 @@  discard block
 block discarded – undo
1095 1095
  */
1096 1096
 function wpinv_get_merge_tags_help_text( $subscription = false ) {
1097 1097
 
1098
-	$url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1099
-	$link = sprintf(
1100
-		'<strong><a href="%s" target="_blank">%s</a></strong>',
1101
-		$url,
1102
-		esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1103
-	);
1098
+    $url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1099
+    $link = sprintf(
1100
+        '<strong><a href="%s" target="_blank">%s</a></strong>',
1101
+        $url,
1102
+        esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1103
+    );
1104 1104
 
1105
-	$description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1105
+    $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1106 1106
 
1107
-	return "$description $link";
1107
+    return "$description $link";
1108 1108
 
1109 1109
 }
Please login to merge, or discard this patch.
Spacing   +360 added lines, -360 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves all default settings.
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
 function wpinv_get_settings() {
17 17
     $defaults = array();
18 18
 
19
-    foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) {
19
+    foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) {
20 20
 
21
-        foreach ( array_values( $tab_settings ) as $section_settings ) {
21
+        foreach (array_values($tab_settings) as $section_settings) {
22 22
 
23
-            foreach ( $section_settings as $key => $setting ) {
24
-                if ( isset( $setting['std'] ) ) {
25
-                    $defaults[ $key ] = $setting['std'];
23
+            foreach ($section_settings as $key => $setting) {
24
+                if (isset($setting['std'])) {
25
+                    $defaults[$key] = $setting['std'];
26 26
                 }
27 27
             }
28 28
 }
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
     global $wpinv_options;
42 42
 
43 43
     // Try fetching the saved options.
44
-    if ( empty( $wpinv_options ) ) {
45
-        $wpinv_options = get_option( 'wpinv_settings' );
44
+    if (empty($wpinv_options)) {
45
+        $wpinv_options = get_option('wpinv_settings');
46 46
     }
47 47
 
48 48
     // If that fails, don't fetch the default settings to prevent a loop.
49
-    if ( ! is_array( $wpinv_options ) ) {
49
+    if (!is_array($wpinv_options)) {
50 50
         $wpinv_options = array();
51 51
     }
52 52
 
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
  * @param mixed $default The default value to use if the setting has not been set.
61 61
  * @return mixed
62 62
  */
63
-function wpinv_get_option( $key = '', $default = false ) {
63
+function wpinv_get_option($key = '', $default = false) {
64 64
 
65 65
     $options = wpinv_get_options();
66
-    $value   = isset( $options[ $key ] ) ? $options[ $key ] : $default;
67
-    $value   = apply_filters( 'wpinv_get_option', $value, $key, $default );
66
+    $value   = isset($options[$key]) ? $options[$key] : $default;
67
+    $value   = apply_filters('wpinv_get_option', $value, $key, $default);
68 68
 
69
-    return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default );
69
+    return apply_filters('wpinv_get_option_' . $key, $value, $key, $default);
70 70
 }
71 71
 
72 72
 /**
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
  * @param array $options the new options.
76 76
  * @return bool
77 77
  */
78
-function wpinv_update_options( $options ) {
78
+function wpinv_update_options($options) {
79 79
     global $wpinv_options;
80 80
 
81 81
     // update the option.
82
-    if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) {
82
+    if (is_array($options) && update_option('wpinv_settings', $options)) {
83 83
         $wpinv_options = $options;
84 84
         return true;
85 85
     }
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
  * @param mixed $value The setting value.
95 95
  * @return bool
96 96
  */
97
-function wpinv_update_option( $key = '', $value = false ) {
97
+function wpinv_update_option($key = '', $value = false) {
98 98
 
99 99
     // If no key, exit.
100
-    if ( empty( $key ) ) {
100
+    if (empty($key)) {
101 101
         return false;
102 102
     }
103 103
 
104 104
     // Maybe delete the option instead.
105
-    if ( is_null( $value ) ) {
106
-        return wpinv_delete_option( $key );
105
+    if (is_null($value)) {
106
+        return wpinv_delete_option($key);
107 107
     }
108 108
 
109 109
     // Prepare the new options.
110 110
     $options         = wpinv_get_options();
111
-    $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key );
111
+    $options[$key] = apply_filters('wpinv_update_option', $value, $key);
112 112
 
113 113
     // Save the new options.
114
-    return wpinv_update_options( $options );
114
+    return wpinv_update_options($options);
115 115
 
116 116
 }
117 117
 
@@ -121,18 +121,18 @@  discard block
 block discarded – undo
121 121
  * @param string $key the setting key.
122 122
  * @return bool
123 123
  */
124
-function wpinv_delete_option( $key = '' ) {
124
+function wpinv_delete_option($key = '') {
125 125
 
126 126
     // If no key, exit
127
-    if ( empty( $key ) ) {
127
+    if (empty($key)) {
128 128
         return false;
129 129
     }
130 130
 
131 131
     $options = wpinv_get_options();
132 132
 
133
-    if ( isset( $options[ $key ] ) ) {
134
-        unset( $options[ $key ] );
135
-        return wpinv_update_options( $options );
133
+    if (isset($options[$key])) {
134
+        unset($options[$key]);
135
+        return wpinv_update_options($options);
136 136
     }
137 137
 
138 138
     return true;
@@ -146,14 +146,14 @@  discard block
 block discarded – undo
146 146
 function wpinv_register_settings() {
147 147
 
148 148
     // Loop through all tabs.
149
-    foreach ( wpinv_get_registered_settings() as $tab => $sections ) {
149
+    foreach (wpinv_get_registered_settings() as $tab => $sections) {
150 150
 
151 151
         // In each tab, loop through sections.
152
-        foreach ( $sections as $section => $settings ) {
152
+        foreach ($sections as $section => $settings) {
153 153
 
154 154
             // Check for backwards compatibility
155
-            $section_tabs = wpinv_get_settings_tab_sections( $tab );
156
-            if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) {
155
+            $section_tabs = wpinv_get_settings_tab_sections($tab);
156
+            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
157 157
                 $section = 'main';
158 158
                 $settings = $sections;
159 159
             }
@@ -166,18 +166,18 @@  discard block
 block discarded – undo
166 166
                 'wpinv_settings_' . $tab . '_' . $section
167 167
             );
168 168
 
169
-            foreach ( $settings as $option ) {
170
-                if ( ! empty( $option['id'] ) ) {
171
-                    wpinv_register_settings_option( $tab, $section, $option );
169
+            foreach ($settings as $option) {
170
+                if (!empty($option['id'])) {
171
+                    wpinv_register_settings_option($tab, $section, $option);
172 172
                 }
173 173
             }
174 174
 }
175 175
     }
176 176
 
177 177
     // Creates our settings in the options table.
178
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
178
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
179 179
 }
180
-add_action( 'admin_init', 'wpinv_register_settings' );
180
+add_action('admin_init', 'wpinv_register_settings');
181 181
 
182 182
 /**
183 183
  * Register a single settings option.
@@ -187,49 +187,49 @@  discard block
 block discarded – undo
187 187
  * @param string $option
188 188
  *
189 189
  */
190
-function wpinv_register_settings_option( $tab, $section, $option ) {
190
+function wpinv_register_settings_option($tab, $section, $option) {
191 191
 
192
-    $name       = isset( $option['name'] ) ? $option['name'] : '';
192
+    $name       = isset($option['name']) ? $option['name'] : '';
193 193
     $cb         = "wpinv_{$option['type']}_callback";
194 194
     $section    = "wpinv_settings_{$tab}_$section";
195
-	$is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
195
+	$is_wizzard = is_admin() && isset($_GET['page']) && 'gp-setup' == $_GET['page'];
196 196
 
197
-	if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
198
-		$tip   = wpinv_clean( $option['desc'] );
197
+	if (isset($option['desc']) && (!$is_wizzard && !empty($option['help-tip']))) {
198
+		$tip   = wpinv_clean($option['desc']);
199 199
 		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
200
-		unset( $option['desc'] );
200
+		unset($option['desc']);
201 201
 	}
202 202
 
203 203
     // Loop through all tabs.
204 204
     add_settings_field(
205 205
         'wpinv_settings[' . $option['id'] . ']',
206 206
         $name,
207
-        function_exists( $cb ) ? $cb : 'wpinv_missing_callback',
207
+        function_exists($cb) ? $cb : 'wpinv_missing_callback',
208 208
         $section,
209 209
         $section,
210 210
         array(
211 211
             'section'         => $section,
212
-            'id'              => isset( $option['id'] ) ? $option['id'] : uniqid( 'wpinv-' ),
213
-            'desc'            => isset( $option['desc'] ) ? $option['desc'] : '',
212
+            'id'              => isset($option['id']) ? $option['id'] : uniqid('wpinv-'),
213
+            'desc'            => isset($option['desc']) ? $option['desc'] : '',
214 214
             'name'            => $name,
215
-            'size'            => isset( $option['size'] ) ? $option['size'] : null,
216
-            'options'         => isset( $option['options'] ) ? $option['options'] : '',
217
-            'selected'        => isset( $option['selected'] ) ? $option['selected'] : null,
218
-            'std'             => isset( $option['std'] ) ? $option['std'] : '',
219
-            'min'             => isset( $option['min'] ) ? $option['min'] : 0,
220
-            'max'             => isset( $option['max'] ) ? $option['max'] : 999999,
221
-            'step'            => isset( $option['step'] ) ? $option['step'] : 1,
222
-            'placeholder'     => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
223
-            'allow_blank'     => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
224
-            'readonly'        => isset( $option['readonly'] ) ? $option['readonly'] : false,
225
-            'faux'            => isset( $option['faux'] ) ? $option['faux'] : false,
226
-            'onchange'        => isset( $option['onchange'] ) ? $option['onchange'] : '',
227
-            'custom'          => isset( $option['custom'] ) ? $option['custom'] : '',
228
-			'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
229
-			'class'           => isset( $option['class'] ) ? $option['class'] : '',
230
-			'style'           => isset( $option['style'] ) ? $option['style'] : '',
231
-            'cols'            => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232
-            'rows'            => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
215
+            'size'            => isset($option['size']) ? $option['size'] : null,
216
+            'options'         => isset($option['options']) ? $option['options'] : '',
217
+            'selected'        => isset($option['selected']) ? $option['selected'] : null,
218
+            'std'             => isset($option['std']) ? $option['std'] : '',
219
+            'min'             => isset($option['min']) ? $option['min'] : 0,
220
+            'max'             => isset($option['max']) ? $option['max'] : 999999,
221
+            'step'            => isset($option['step']) ? $option['step'] : 1,
222
+            'placeholder'     => isset($option['placeholder']) ? $option['placeholder'] : null,
223
+            'allow_blank'     => isset($option['allow_blank']) ? $option['allow_blank'] : true,
224
+            'readonly'        => isset($option['readonly']) ? $option['readonly'] : false,
225
+            'faux'            => isset($option['faux']) ? $option['faux'] : false,
226
+            'onchange'        => isset($option['onchange']) ? $option['onchange'] : '',
227
+            'custom'          => isset($option['custom']) ? $option['custom'] : '',
228
+			'default_content' => isset($option['default_content']) ? $option['default_content'] : '',
229
+			'class'           => isset($option['class']) ? $option['class'] : '',
230
+			'style'           => isset($option['style']) ? $option['style'] : '',
231
+            'cols'            => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232
+            'rows'            => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
233 233
         )
234 234
     );
235 235
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
  * @return array
242 242
  */
243 243
 function wpinv_get_registered_settings() {
244
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
244
+	return array_filter(apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings')));
245 245
 }
246 246
 
247 247
 /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
  * @return array
251 251
  */
252 252
 function getpaid_get_integration_settings() {
253
-    return apply_filters( 'getpaid_integration_settings', array() );
253
+    return apply_filters('getpaid_integration_settings', array());
254 254
 }
255 255
 
256 256
 /**
@@ -258,126 +258,126 @@  discard block
 block discarded – undo
258 258
  *
259 259
  * @return array
260 260
  */
261
-function wpinv_settings_sanitize( $input = array() ) {
261
+function wpinv_settings_sanitize($input = array()) {
262 262
 
263 263
 	$wpinv_options = wpinv_get_options();
264 264
 	$raw_referrer  = wp_get_raw_referer();
265 265
 
266
-    if ( empty( $raw_referrer ) ) {
267
-		return array_merge( $wpinv_options, $input );
266
+    if (empty($raw_referrer)) {
267
+		return array_merge($wpinv_options, $input);
268 268
     }
269 269
 
270
-    wp_parse_str( $raw_referrer, $referrer );
270
+    wp_parse_str($raw_referrer, $referrer);
271 271
 
272
-	if ( in_array( 'gp-setup', $referrer ) ) {
273
-		return array_merge( $wpinv_options, $input );
272
+	if (in_array('gp-setup', $referrer)) {
273
+		return array_merge($wpinv_options, $input);
274 274
 	}
275 275
 
276 276
     $settings = wpinv_get_registered_settings();
277
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
278
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
277
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
278
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
279 279
 
280 280
     $input = $input ? $input : array();
281
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
282
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
281
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
282
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
283 283
 
284 284
     // Loop through each setting being saved and pass it through a sanitization filter
285
-    foreach ( $input as $key => $value ) {
285
+    foreach ($input as $key => $value) {
286 286
 
287 287
         // Get the setting type (checkbox, select, etc)
288
-        $type = isset( $settings[ $tab ][ $section ][ $key ]['type'] ) ? $settings[ $tab ][ $section ][ $key ]['type'] : false;
288
+        $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false;
289 289
 
290
-        if ( $type ) {
290
+        if ($type) {
291 291
             // Field type specific filter
292
-            $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$type", $value, $key );
292
+            $input[$key] = apply_filters("wpinv_settings_sanitize_$type", $value, $key);
293 293
         }
294 294
 
295 295
         // General filter
296
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
296
+		$input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
297 297
 
298 298
 		// Key specific filter.
299
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
299
+		$input[$key] = apply_filters("wpinv_settings_sanitize_$key", $input[$key]);
300 300
     }
301 301
 
302 302
     // Loop through the whitelist and unset any that are empty for the tab being saved
303
-    $main_settings    = isset( $settings[ $tab ] ) ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
304
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
303
+    $main_settings    = isset($settings[$tab]) ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
304
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
305 305
 
306
-    $found_settings   = array_merge( $main_settings, $section_settings );
306
+    $found_settings   = array_merge($main_settings, $section_settings);
307 307
 
308
-    if ( ! empty( $found_settings ) ) {
309
-        foreach ( $found_settings as $key => $value ) {
308
+    if (!empty($found_settings)) {
309
+        foreach ($found_settings as $key => $value) {
310 310
 
311 311
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
312
-            if ( is_numeric( $key ) ) {
312
+            if (is_numeric($key)) {
313 313
                 $key = $value['id'];
314 314
             }
315 315
 
316
-            if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) {
317
-                unset( $wpinv_options[ $key ] );
316
+            if (!isset($input[$key]) && isset($wpinv_options[$key])) {
317
+                unset($wpinv_options[$key]);
318 318
             }
319 319
         }
320 320
     }
321 321
 
322 322
     // Merge our new settings with the existing
323
-    $output = array_merge( $wpinv_options, $input );
323
+    $output = array_merge($wpinv_options, $input);
324 324
 
325
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
325
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
326 326
 
327 327
     return $output;
328 328
 }
329
-add_filter( 'wpinv_settings_sanitize_text', 'trim', 10, 1 );
330
-add_filter( 'wpinv_settings_sanitize_tax_rate', 'wpinv_sanitize_amount' );
329
+add_filter('wpinv_settings_sanitize_text', 'trim', 10, 1);
330
+add_filter('wpinv_settings_sanitize_tax_rate', 'wpinv_sanitize_amount');
331 331
 
332
-function wpinv_settings_sanitize_tax_rates( $input ) {
333
-    if ( ! wpinv_current_user_can_manage_invoicing() ) {
332
+function wpinv_settings_sanitize_tax_rates($input) {
333
+    if (!wpinv_current_user_can_manage_invoicing()) {
334 334
         return $input;
335 335
     }
336 336
 
337
-    $new_rates = ! empty( $_POST['tax_rates'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rates'] ) ) : array();
337
+    $new_rates = !empty($_POST['tax_rates']) ? wp_kses_post_deep(array_values($_POST['tax_rates'])) : array();
338 338
     $tax_rates = array();
339 339
 
340
-    foreach ( $new_rates as $rate ) {
340
+    foreach ($new_rates as $rate) {
341 341
 
342
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
-		$rate['name']    = sanitize_text_field( $rate['name'] );
344
-		$rate['state']   = sanitize_text_field( $rate['state'] );
345
-		$rate['country'] = sanitize_text_field( $rate['country'] );
346
-		$rate['global']  = empty( $rate['state'] );
342
+		$rate['rate']    = wpinv_sanitize_amount($rate['rate']);
343
+		$rate['name']    = sanitize_text_field($rate['name']);
344
+		$rate['state']   = sanitize_text_field($rate['state']);
345
+		$rate['country'] = sanitize_text_field($rate['country']);
346
+		$rate['global']  = empty($rate['state']);
347 347
 		$tax_rates[]     = $rate;
348 348
 
349 349
 	}
350 350
 
351
-    update_option( 'wpinv_tax_rates', $tax_rates );
351
+    update_option('wpinv_tax_rates', $tax_rates);
352 352
 
353 353
     return $input;
354 354
 }
355
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
355
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
356 356
 
357 357
 function wpinv_get_settings_tabs() {
358 358
     $tabs             = array();
359
-    $tabs['general']  = __( 'General', 'invoicing' );
360
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
361
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
362
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
359
+    $tabs['general']  = __('General', 'invoicing');
360
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
361
+    $tabs['taxes']    = __('Taxes', 'invoicing');
362
+	$tabs['emails'] = __('Emails', 'invoicing');
363 363
 
364
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
365
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
364
+	if (count(getpaid_get_integration_settings()) > 0) {
365
+		$tabs['integrations'] = __('Integrations', 'invoicing');
366 366
 	}
367 367
 
368
-    $tabs['privacy']  = __( 'Privacy', 'invoicing' );
369
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
370
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
368
+    $tabs['privacy']  = __('Privacy', 'invoicing');
369
+    $tabs['misc']     = __('Misc', 'invoicing');
370
+    $tabs['tools']    = __('Tools', 'invoicing');
371 371
 
372
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
372
+    return apply_filters('wpinv_settings_tabs', $tabs);
373 373
 }
374 374
 
375
-function wpinv_get_settings_tab_sections( $tab = false ) {
375
+function wpinv_get_settings_tab_sections($tab = false) {
376 376
     $tabs     = false;
377 377
     $sections = wpinv_get_registered_settings_sections();
378 378
 
379
-    if ( $tab && ! empty( $sections[ $tab ] ) ) {
380
-        $tabs = $sections[ $tab ];
379
+    if ($tab && !empty($sections[$tab])) {
380
+        $tabs = $sections[$tab];
381 381
     }
382 382
 
383 383
     return $tabs;
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 function wpinv_get_registered_settings_sections() {
387 387
     static $sections = false;
388 388
 
389
-    if ( false !== $sections ) {
389
+    if (false !== $sections) {
390 390
         return $sections;
391 391
     }
392 392
 
@@ -394,161 +394,161 @@  discard block
 block discarded – undo
394 394
         'general'      => apply_filters(
395 395
             'wpinv_settings_sections_general',
396 396
             array(
397
-				'main'             => __( 'General Settings', 'invoicing' ),
398
-				'page_section'     => __( 'Page Settings', 'invoicing' ),
399
-				'currency_section' => __( 'Currency Settings', 'invoicing' ),
400
-				'labels'           => __( 'Label Texts', 'invoicing' ),
397
+				'main'             => __('General Settings', 'invoicing'),
398
+				'page_section'     => __('Page Settings', 'invoicing'),
399
+				'currency_section' => __('Currency Settings', 'invoicing'),
400
+				'labels'           => __('Label Texts', 'invoicing'),
401 401
             )
402 402
         ),
403 403
         'gateways'     => apply_filters(
404 404
             'wpinv_settings_sections_gateways',
405 405
             array(
406
-				'main' => __( 'Gateway Settings', 'invoicing' ),
406
+				'main' => __('Gateway Settings', 'invoicing'),
407 407
             )
408 408
         ),
409 409
         'taxes'        => apply_filters(
410 410
             'wpinv_settings_sections_taxes',
411 411
             array(
412
-				'main'  => __( 'Tax Settings', 'invoicing' ),
413
-				'rates' => __( 'Tax Rates', 'invoicing' ),
414
-				'vat'   => __( 'EU VAT Settings', 'invoicing' ),
412
+				'main'  => __('Tax Settings', 'invoicing'),
413
+				'rates' => __('Tax Rates', 'invoicing'),
414
+				'vat'   => __('EU VAT Settings', 'invoicing'),
415 415
             )
416 416
         ),
417 417
         'emails'       => apply_filters(
418 418
             'wpinv_settings_sections_emails',
419 419
             array(
420
-				'main' => __( 'Email Settings', 'invoicing' ),
420
+				'main' => __('Email Settings', 'invoicing'),
421 421
             )
422 422
         ),
423 423
 
424
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
424
+		'integrations' => wp_list_pluck(getpaid_get_integration_settings(), 'label', 'id'),
425 425
 
426 426
         'privacy'      => apply_filters(
427 427
             'wpinv_settings_sections_privacy',
428 428
             array(
429
-				'main' => __( 'Privacy policy', 'invoicing' ),
429
+				'main' => __('Privacy policy', 'invoicing'),
430 430
             )
431 431
         ),
432 432
         'misc'         => apply_filters(
433 433
             'wpinv_settings_sections_misc',
434 434
             array(
435
-				'main'       => __( 'Miscellaneous', 'invoicing' ),
436
-				'custom-css' => __( 'Custom CSS', 'invoicing' ),
435
+				'main'       => __('Miscellaneous', 'invoicing'),
436
+				'custom-css' => __('Custom CSS', 'invoicing'),
437 437
             )
438 438
         ),
439 439
         'tools'        => apply_filters(
440 440
             'wpinv_settings_sections_tools',
441 441
             array(
442
-				'main' => __( 'Diagnostic Tools', 'invoicing' ),
442
+				'main' => __('Diagnostic Tools', 'invoicing'),
443 443
             )
444 444
         ),
445 445
     );
446 446
 
447
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
447
+    $sections = apply_filters('wpinv_settings_sections', $sections);
448 448
 
449 449
     return $sections;
450 450
 }
451 451
 
452
-function wpinv_get_pages( $with_slug = false, $default_label = null ) {
452
+function wpinv_get_pages($with_slug = false, $default_label = null) {
453 453
 	$pages_options = array();
454 454
 
455
-	if ( $default_label !== null && $default_label !== false ) {
456
-		$pages_options = array( '' => $default_label ); // Blank option
455
+	if ($default_label !== null && $default_label !== false) {
456
+		$pages_options = array('' => $default_label); // Blank option
457 457
 	}
458 458
 
459 459
 	$pages = get_pages();
460
-	if ( $pages ) {
461
-		foreach ( $pages as $page ) {
460
+	if ($pages) {
461
+		foreach ($pages as $page) {
462 462
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
463
-            $pages_options[ $page->ID ] = $title;
463
+            $pages_options[$page->ID] = $title;
464 464
 		}
465 465
 	}
466 466
 
467 467
 	return $pages_options;
468 468
 }
469 469
 
470
-function wpinv_header_callback( $args ) {
471
-	if ( ! empty( $args['desc'] ) ) {
472
-        echo wp_kses_post( $args['desc'] );
470
+function wpinv_header_callback($args) {
471
+	if (!empty($args['desc'])) {
472
+        echo wp_kses_post($args['desc']);
473 473
     }
474 474
 }
475 475
 
476
-function wpinv_hidden_callback( $args ) {
476
+function wpinv_hidden_callback($args) {
477 477
 
478
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
479
-	$value   = wpinv_get_option( $args['id'], $std );
478
+	$std     = isset($args['std']) ? $args['std'] : '';
479
+	$value   = wpinv_get_option($args['id'], $std);
480 480
 
481
-	if ( isset( $args['set_value'] ) ) {
481
+	if (isset($args['set_value'])) {
482 482
 		$value = $args['set_value'];
483 483
 	}
484 484
 
485
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
485
+	if (isset($args['faux']) && true === $args['faux']) {
486 486
 		$args['readonly'] = true;
487
-		$name  = '';
487
+		$name = '';
488 488
 	} else {
489
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
489
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
490 490
 	}
491 491
 
492
-	echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
492
+	echo '<input type="hidden" id="wpinv_settings[' . esc_attr($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />';
493 493
 
494 494
 }
495 495
 
496 496
 /**
497 497
  * Displays a checkbox settings callback.
498 498
  */
499
-function wpinv_checkbox_callback( $args ) {
499
+function wpinv_checkbox_callback($args) {
500 500
 
501
-	$std = isset( $args['std'] ) ? $args['std'] : '';
502
-	$std = wpinv_get_option( $args['id'], $std );
503
-	$id  = esc_attr( $args['id'] );
501
+	$std = isset($args['std']) ? $args['std'] : '';
502
+	$std = wpinv_get_option($args['id'], $std);
503
+	$id  = esc_attr($args['id']);
504 504
 
505
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
505
+	getpaid_hidden_field("wpinv_settings[$id]", '0');
506 506
 	?>
507 507
 		<fieldset>
508 508
 			<label>
509
-				<input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox">
510
-				<?php echo wp_kses_post( $args['desc'] ); ?>
509
+				<input id="wpinv-settings-<?php echo esc_attr($id); ?>" name="wpinv_settings[<?php echo esc_attr($id); ?>]" <?php checked(empty($std), false); ?> value="1" type="checkbox">
510
+				<?php echo wp_kses_post($args['desc']); ?>
511 511
 			</label>
512 512
 		</fieldset>
513 513
 	<?php
514 514
 }
515 515
 
516
-function wpinv_multicheck_callback( $args ) {
516
+function wpinv_multicheck_callback($args) {
517 517
 
518
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
519
-	$class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
518
+	$sanitize_id = wpinv_sanitize_key($args['id']);
519
+	$class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
520 520
 
521
-	if ( ! empty( $args['options'] ) ) {
521
+	if (!empty($args['options'])) {
522 522
 
523
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
524
-		$value   = wpinv_get_option( $args['id'], $std );
523
+		$std     = isset($args['std']) ? $args['std'] : array();
524
+		$value   = wpinv_get_option($args['id'], $std);
525 525
 
526 526
 		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
527
-        foreach ( $args['options'] as $key => $option ) :
528
-			$sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
529
-			if ( in_array( $sanitize_key, $value ) ) {
527
+        foreach ($args['options'] as $key => $option) :
528
+			$sanitize_key = esc_attr(wpinv_sanitize_key($key));
529
+			if (in_array($sanitize_key, $value)) {
530 530
 				$enabled = $sanitize_key;
531 531
 			} else {
532 532
 				$enabled = null;
533 533
 			}
534
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
535
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
534
+			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/>&nbsp;';
535
+			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>';
536 536
 		endforeach;
537 537
 		echo '</div>';
538
-		echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
538
+		echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
539 539
 	}
540 540
 }
541 541
 
542
-function wpinv_payment_icons_callback( $args ) {
542
+function wpinv_payment_icons_callback($args) {
543 543
 
544
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
545
-	$value   = wpinv_get_option( $args['id'], false );
544
+    $sanitize_id = wpinv_sanitize_key($args['id']);
545
+	$value = wpinv_get_option($args['id'], false);
546 546
 
547
-	if ( ! empty( $args['options'] ) ) {
548
-		foreach ( $args['options'] as $key => $option ) {
549
-            $sanitize_key = wpinv_sanitize_key( $key );
547
+	if (!empty($args['options'])) {
548
+		foreach ($args['options'] as $key => $option) {
549
+            $sanitize_key = wpinv_sanitize_key($key);
550 550
 
551
-			if ( empty( $value ) ) {
551
+			if (empty($value)) {
552 552
 				$enabled = $option;
553 553
 			} else {
554 554
 				$enabled = null;
@@ -556,67 +556,67 @@  discard block
 block discarded – undo
556 556
 
557 557
 			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
558 558
 
559
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
559
+				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/>&nbsp;';
560 560
 
561
-				if ( wpinv_string_is_image_url( $key ) ) {
562
-				echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
561
+				if (wpinv_string_is_image_url($key)) {
562
+				echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
563 563
 				} else {
564
-				$card = strtolower( str_replace( ' ', '', $option ) );
564
+				$card = strtolower(str_replace(' ', '', $option));
565 565
 
566
-				if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
567
-					$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
566
+				if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
567
+					$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
568 568
 					} else {
569
-					$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
569
+					$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
570 570
 					$content_dir = WP_CONTENT_DIR;
571 571
 
572
-					if ( function_exists( 'wp_normalize_path' ) ) {
572
+					if (function_exists('wp_normalize_path')) {
573 573
 						// Replaces backslashes with forward slashes for Windows systems
574
-						$image = wp_normalize_path( $image );
575
-						$content_dir = wp_normalize_path( $content_dir );
574
+						$image = wp_normalize_path($image);
575
+						$content_dir = wp_normalize_path($content_dir);
576 576
 						}
577 577
 
578
-					$image = str_replace( $content_dir, content_url(), $image );
578
+					$image = str_replace($content_dir, content_url(), $image);
579 579
 					}
580 580
 
581
-				echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
581
+				echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
582 582
 				}
583 583
 			echo $option . '</label>';
584 584
 		}
585
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
585
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
586 586
 	}
587 587
 }
588 588
 
589 589
 /**
590 590
  * Displays a radio settings field.
591 591
  */
592
-function wpinv_radio_callback( $args ) {
592
+function wpinv_radio_callback($args) {
593 593
 
594
-	$std = isset( $args['std'] ) ? $args['std'] : '';
595
-	$std = wpinv_get_option( $args['id'], $std );
594
+	$std = isset($args['std']) ? $args['std'] : '';
595
+	$std = wpinv_get_option($args['id'], $std);
596 596
 	?>
597 597
 		<fieldset>
598
-			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
599
-				<?php foreach ( $args['options'] as $key => $option ) : ?>
598
+			<ul id="wpinv-settings-<?php echo esc_attr($args['id']); ?>" style="margin-top: 0;">
599
+				<?php foreach ($args['options'] as $key => $option) : ?>
600 600
 					<li>
601 601
 						<label>
602
-							<input name="wpinv_settings[<?php echo esc_attr( $args['id'] ); ?>]" <?php checked( $std, $key ); ?> value="<?php echo esc_attr( $key ); ?>" type="radio">
603
-							<?php echo wp_kses_post( $option ); ?>
602
+							<input name="wpinv_settings[<?php echo esc_attr($args['id']); ?>]" <?php checked($std, $key); ?> value="<?php echo esc_attr($key); ?>" type="radio">
603
+							<?php echo wp_kses_post($option); ?>
604 604
 						</label>
605 605
 					</li>
606 606
 				<?php endforeach; ?>
607 607
 			</ul>
608 608
 		</fieldset>
609 609
 	<?php
610
-	getpaid_settings_description_callback( $args );
610
+	getpaid_settings_description_callback($args);
611 611
 }
612 612
 
613 613
 /**
614 614
  * Displays a description if available.
615 615
  */
616
-function getpaid_settings_description_callback( $args ) {
616
+function getpaid_settings_description_callback($args) {
617 617
 
618
-	if ( ! empty( $args['desc'] ) ) {
619
-		$description = wp_kses_post( $args['desc'] );
618
+	if (!empty($args['desc'])) {
619
+		$description = wp_kses_post($args['desc']);
620 620
 		echo "<p class='description'>$description</p>";
621 621
 	}
622 622
 
@@ -632,31 +632,31 @@  discard block
 block discarded – undo
632 632
 	</tr>
633 633
 	<tr class="bsui">
634 634
     	<td colspan="2" class="p-0">
635
-			<?php include plugin_dir_path( __FILE__ ) . 'views/html-gateways-edit.php'; ?>
635
+			<?php include plugin_dir_path(__FILE__) . 'views/html-gateways-edit.php'; ?>
636 636
 
637 637
 	<?php
638 638
 }
639 639
 
640
-function wpinv_gateway_select_callback( $args ) {
640
+function wpinv_gateway_select_callback($args) {
641 641
 
642
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
643
-    $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
644
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
645
-	$value   = wpinv_get_option( $args['id'], $std );
642
+    $sanitize_id = wpinv_sanitize_key($args['id']);
643
+    $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
644
+	$std     = isset($args['std']) ? $args['std'] : '';
645
+	$value   = wpinv_get_option($args['id'], $std);
646 646
 
647 647
 	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >';
648 648
 
649
-	foreach ( $args['options'] as $key => $option ) :
650
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
651
-            $selected = selected( $key, $args['selected'], false );
649
+	foreach ($args['options'] as $key => $option) :
650
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
651
+            $selected = selected($key, $args['selected'], false);
652 652
         } else {
653
-            $selected = selected( $key, $value, false );
653
+            $selected = selected($key, $value, false);
654 654
         }
655
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
655
+		echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>';
656 656
 	endforeach;
657 657
 
658 658
 	echo '</select>';
659
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
659
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
660 660
 }
661 661
 
662 662
 /**
@@ -665,28 +665,28 @@  discard block
 block discarded – undo
665 665
  * @param array $args
666 666
  * @return string
667 667
  */
668
-function wpinv_settings_attrs_helper( $args ) {
668
+function wpinv_settings_attrs_helper($args) {
669 669
 
670
-	$value        = isset( $args['std'] ) ? $args['std'] : '';
671
-	$id           = esc_attr( $args['id'] );
672
-	$placeholder  = esc_attr( $args['placeholder'] );
670
+	$value        = isset($args['std']) ? $args['std'] : '';
671
+	$id           = esc_attr($args['id']);
672
+	$placeholder  = esc_attr($args['placeholder']);
673 673
 
674
-	if ( ! empty( $args['faux'] ) ) {
674
+	if (!empty($args['faux'])) {
675 675
 		$args['readonly'] = true;
676 676
 		$name             = '';
677 677
 	} else {
678
-		$value  = wpinv_get_option( $args['id'], $value );
678
+		$value  = wpinv_get_option($args['id'], $value);
679 679
 		$name   = "wpinv_settings[$id]";
680 680
 	}
681 681
 
682
-	$value    = is_scalar( $value ) ? esc_attr( $value ) : '';
683
-	$class    = esc_attr( $args['class'] );
684
-	$style    = esc_attr( $args['style'] );
685
-	$readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
682
+	$value    = is_scalar($value) ? esc_attr($value) : '';
683
+	$class    = esc_attr($args['class']);
684
+	$style    = esc_attr($args['style']);
685
+	$readonly = empty($args['readonly']) ? '' : 'readonly onclick="this.select()"';
686 686
 
687 687
 	$onchange = '';
688
-    if ( ! empty( $args['onchange'] ) ) {
689
-        $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
688
+    if (!empty($args['onchange'])) {
689
+        $onchange = ' onchange="' . esc_attr($args['onchange']) . '"';
690 690
 	}
691 691
 
692 692
 	return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
@@ -695,14 +695,14 @@  discard block
 block discarded – undo
695 695
 /**
696 696
  * Displays a text input settings callback.
697 697
  */
698
-function wpinv_text_callback( $args ) {
698
+function wpinv_text_callback($args) {
699 699
 
700
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
700
+	$desc = empty($desc) ? '' : "<p class='description'>$desc</p>";
701 701
 
702 702
 	?>
703 703
 		<label style="width: 100%;">
704
-			<input type="text" <?php echo wpinv_settings_attrs_helper( $args ); ?>>
705
-			<?php echo wp_kses_post( $desc ); ?>
704
+			<input type="text" <?php echo wpinv_settings_attrs_helper($args); ?>>
705
+			<?php echo wp_kses_post($desc); ?>
706 706
 		</label>
707 707
 	<?php
708 708
 
@@ -711,49 +711,49 @@  discard block
 block discarded – undo
711 711
 /**
712 712
  * Displays a number input settings callback.
713 713
  */
714
-function wpinv_number_callback( $args ) {
714
+function wpinv_number_callback($args) {
715 715
 
716
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
717
-	$attr = wpinv_settings_attrs_helper( $args );
716
+	$desc = empty($desc) ? '' : "<p class='description'>$desc</p>";
717
+	$attr = wpinv_settings_attrs_helper($args);
718 718
 
719 719
 	?>
720 720
 		<label style="width: 100%;">
721
-			<input type="number" step="<?php echo floatval( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php echo $attr; ?>>
722
-			<?php echo wp_kses_post( $desc ); ?>
721
+			<input type="number" step="<?php echo floatval($args['step']); ?>" max="<?php echo intval($args['max']); ?>" min="<?php echo intval($args['min']); ?>" <?php echo $attr; ?>>
722
+			<?php echo wp_kses_post($desc); ?>
723 723
 		</label>
724 724
 	<?php
725 725
 
726 726
 }
727 727
 
728
-function wpinv_textarea_callback( $args ) {
728
+function wpinv_textarea_callback($args) {
729 729
 
730
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
731
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
732
-	$value   = wpinv_get_option( $args['id'], $std );
730
+    $sanitize_id = wpinv_sanitize_key($args['id']);
731
+	$std     = isset($args['std']) ? $args['std'] : '';
732
+	$value   = wpinv_get_option($args['id'], $std);
733 733
 
734
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
735
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
734
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
735
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
736 736
 
737
-	echo '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
738
-	echo '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
737
+	echo '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>';
738
+	echo '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
739 739
 
740 740
 }
741 741
 
742
-function wpinv_password_callback( $args ) {
742
+function wpinv_password_callback($args) {
743 743
 
744
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
745
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
746
-	$value   = wpinv_get_option( $args['id'], $std );
744
+    $sanitize_id = wpinv_sanitize_key($args['id']);
745
+	$std     = isset($args['std']) ? $args['std'] : '';
746
+	$value   = wpinv_get_option($args['id'], $std);
747 747
 
748
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
749
-	echo '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
750
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
748
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
749
+	echo '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>';
750
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
751 751
 
752 752
 }
753 753
 
754
-function wpinv_missing_callback( $args ) {
754
+function wpinv_missing_callback($args) {
755 755
 	printf(
756
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
756
+		__('The callback function used for the %s setting is missing.', 'invoicing'),
757 757
 		'<strong>' . $args['id'] . '</strong>'
758 758
 	);
759 759
 }
@@ -761,35 +761,35 @@  discard block
 block discarded – undo
761 761
 /**
762 762
  * Displays a number input settings callback.
763 763
  */
764
-function wpinv_select_callback( $args ) {
764
+function wpinv_select_callback($args) {
765 765
 
766
-	$desc   = wp_kses_post( $args['desc'] );
767
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
768
-	$attr   = wpinv_settings_attrs_helper( $args );
769
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
770
-	$value  = wpinv_get_option( $args['id'], $value );
771
-	$rand   = uniqid( 'random_id' );
766
+	$desc   = wp_kses_post($args['desc']);
767
+	$desc   = empty($desc) ? '' : "<p class='description'>$desc</p>";
768
+	$attr   = wpinv_settings_attrs_helper($args);
769
+	$value  = isset($args['std']) ? $args['std'] : '';
770
+	$value  = wpinv_get_option($args['id'], $value);
771
+	$rand   = uniqid('random_id');
772 772
 
773 773
 	?>
774 774
 		<label style="width: 100%;">
775 775
 			<select <?php echo $attr; ?> data-allow-clear="true">
776
-				<?php foreach ( $args['options'] as $option => $name ) : ?>
777
-					<option value="<?php echo esc_attr( $option ); ?>" <?php echo selected( $option, $value ); ?>><?php echo wpinv_clean( $name ); ?></option>
776
+				<?php foreach ($args['options'] as $option => $name) : ?>
777
+					<option value="<?php echo esc_attr($option); ?>" <?php echo selected($option, $value); ?>><?php echo wpinv_clean($name); ?></option>
778 778
 				<?php endforeach; ?>
779 779
 			</select>
780 780
 
781
-			<?php if ( substr( $args['id'], -5 ) === '_page' && is_numeric( $value ) ) : ?>
782
-				<a href="<?php echo get_edit_post_link( $value ); ?>" target="_blank" class="button getpaid-page-setting-edit"><?php _e( 'Edit Page', 'invoicing' ); ?></a>
781
+			<?php if (substr($args['id'], -5) === '_page' && is_numeric($value)) : ?>
782
+				<a href="<?php echo get_edit_post_link($value); ?>" target="_blank" class="button getpaid-page-setting-edit"><?php _e('Edit Page', 'invoicing'); ?></a>
783 783
 			<?php endif; ?>
784 784
 
785
-			<?php if ( substr( $args['id'], -5 ) === '_page' && ! empty( $args['default_content'] ) ) : ?>
786
-				&nbsp;<a href="#TB_inline?&width=400&height=550&inlineId=<?php echo $rand; ?>" class="button thickbox getpaid-page-setting-view-default"><?php _e( 'View Default Content', 'invoicing' ); ?></a>
785
+			<?php if (substr($args['id'], -5) === '_page' && !empty($args['default_content'])) : ?>
786
+				&nbsp;<a href="#TB_inline?&width=400&height=550&inlineId=<?php echo $rand; ?>" class="button thickbox getpaid-page-setting-view-default"><?php _e('View Default Content', 'invoicing'); ?></a>
787 787
 				<div id='<?php echo $rand; ?>' style='display:none;'>
788 788
 					<div>
789
-						<h3><?php _e( 'Original Content', 'invoicing' ); ?></h3>
790
-						<textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php echo gepaid_trim_lines( wp_kses_post( $args['default_content'] ) ); ?></textarea>
791
-						<h3><?php _e( 'Current Content', 'invoicing' ); ?></h3>
792
-						<textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php $_post = get_post( $value ); echo empty( $_post ) ? '' : gepaid_trim_lines( wp_kses_post( $_post->post_content ) ); ?></textarea>
789
+						<h3><?php _e('Original Content', 'invoicing'); ?></h3>
790
+						<textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php echo gepaid_trim_lines(wp_kses_post($args['default_content'])); ?></textarea>
791
+						<h3><?php _e('Current Content', 'invoicing'); ?></h3>
792
+						<textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php $_post = get_post($value); echo empty($_post) ? '' : gepaid_trim_lines(wp_kses_post($_post->post_content)); ?></textarea>
793 793
 					</div>
794 794
 				</div>
795 795
 			<?php endif; ?>
@@ -800,89 +800,89 @@  discard block
 block discarded – undo
800 800
 
801 801
 }
802 802
 
803
-function wpinv_color_select_callback( $args ) {
803
+function wpinv_color_select_callback($args) {
804 804
 
805
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
806
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
807
-	$value   = wpinv_get_option( $args['id'], $std );
805
+    $sanitize_id = wpinv_sanitize_key($args['id']);
806
+	$std     = isset($args['std']) ? $args['std'] : '';
807
+	$value   = wpinv_get_option($args['id'], $std);
808 808
 
809
-	echo '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
809
+	echo '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
810 810
 
811
-	foreach ( $args['options'] as $option => $color ) {
812
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
811
+	foreach ($args['options'] as $option => $color) {
812
+		echo '<option value="' . esc_attr($option) . '" ' . selected($option, $value) . '>' . esc_html($color['label']) . '</option>';
813 813
 	}
814 814
 
815 815
 	echo '</select>';
816
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
816
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
817 817
 
818 818
 }
819 819
 
820
-function wpinv_rich_editor_callback( $args ) {
820
+function wpinv_rich_editor_callback($args) {
821 821
 	global $wp_version;
822 822
 
823
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
823
+    $sanitize_id = wpinv_sanitize_key($args['id']);
824 824
 
825
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
826
-	$value   = wpinv_get_option( $args['id'], $std );
825
+	$std     = isset($args['std']) ? $args['std'] : '';
826
+	$value   = wpinv_get_option($args['id'], $std);
827 827
 
828
-	if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
828
+	if (!empty($args['allow_blank']) && empty($value)) {
829 829
 		$value = $std;
830 830
 	}
831 831
 
832
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
832
+	$rows = isset($args['size']) ? $args['size'] : 20;
833 833
 
834 834
 	echo '<div class="getpaid-settings-editor-input">';
835
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
835
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
836 836
 		wp_editor(
837
-            stripslashes( $value ),
838
-            'wpinv_settings_' . esc_attr( $args['id'] ),
837
+            stripslashes($value),
838
+            'wpinv_settings_' . esc_attr($args['id']),
839 839
             array(
840
-				'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
841
-				'textarea_rows' => absint( $rows ),
840
+				'textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']',
841
+				'textarea_rows' => absint($rows),
842 842
 				'media_buttons' => false,
843 843
             )
844 844
         );
845 845
 	} else {
846
-		echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
846
+		echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>';
847 847
 	}
848 848
 
849
-	echo '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
849
+	echo '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
850 850
 
851 851
 }
852 852
 
853
-function wpinv_upload_callback( $args ) {
853
+function wpinv_upload_callback($args) {
854 854
 
855
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
855
+    $sanitize_id = wpinv_sanitize_key($args['id']);
856 856
 
857
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
858
-	$value   = wpinv_get_option( $args['id'], $std );
857
+	$std     = isset($args['std']) ? $args['std'] : '';
858
+	$value   = wpinv_get_option($args['id'], $std);
859 859
 
860
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
861
-	echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
862
-	echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
863
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
860
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
861
+	echo '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
862
+	echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>';
863
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
864 864
 
865 865
 }
866 866
 
867
-function wpinv_color_callback( $args ) {
867
+function wpinv_color_callback($args) {
868 868
 
869
-	$std         = isset( $args['std'] ) ? $args['std'] : '';
870
-	$value       = wpinv_get_option( $args['id'], $std );
871
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
869
+	$std         = isset($args['std']) ? $args['std'] : '';
870
+	$value       = wpinv_get_option($args['id'], $std);
871
+    $sanitize_id = wpinv_sanitize_key($args['id']);
872 872
 
873
-	echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
874
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
873
+	echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($std) . '" />';
874
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
875 875
 
876 876
 }
877 877
 
878
-function wpinv_country_states_callback( $args ) {
878
+function wpinv_country_states_callback($args) {
879 879
 
880
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
881
-	$value   = wpinv_get_option( $args['id'], $std );
880
+	$std     = isset($args['std']) ? $args['std'] : '';
881
+	$value   = wpinv_get_option($args['id'], $std);
882 882
 
883
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
883
+    $sanitize_id = wpinv_sanitize_key($args['id']);
884 884
 
885
-	if ( isset( $args['placeholder'] ) ) {
885
+	if (isset($args['placeholder'])) {
886 886
 		$placeholder = $args['placeholder'];
887 887
 	} else {
888 888
 		$placeholder = '';
@@ -890,15 +890,15 @@  discard block
 block discarded – undo
890 890
 
891 891
 	$states = wpinv_get_country_states();
892 892
 
893
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
894
-	echo '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
893
+	$class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
894
+	echo '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>';
895 895
 
896
-	foreach ( $states as $option => $name ) {
897
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
896
+	foreach ($states as $option => $name) {
897
+		echo '<option value="' . esc_attr($option) . '" ' . selected($option, $value) . '>' . esc_html($name) . '</option>';
898 898
 	}
899 899
 
900 900
 	echo '</select>';
901
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
901
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
902 902
 
903 903
 }
904 904
 
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
 	</tr>
913 913
 	<tr class="bsui">
914 914
     	<td colspan="2" class="p-0">
915
-			<?php include plugin_dir_path( __FILE__ ) . 'views/html-tax-rates-edit.php'; ?>
915
+			<?php include plugin_dir_path(__FILE__) . 'views/html-tax-rates-edit.php'; ?>
916 916
 
917 917
 	<?php
918 918
 
@@ -921,14 +921,14 @@  discard block
 block discarded – undo
921 921
 /**
922 922
  * Displays a tax rate' edit row.
923 923
  */
924
-function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) {
924
+function wpinv_tax_rate_callback($tax_rate, $key, $echo = true) {
925 925
 	ob_start();
926 926
 
927
-	$key                      = sanitize_key( $key );
928
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
929
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
927
+	$key                      = sanitize_key($key);
928
+	$tax_rate['reduced_rate'] = empty($tax_rate['reduced_rate']) ? 0 : $tax_rate['reduced_rate'];
929
+	include plugin_dir_path(__FILE__) . 'views/html-tax-rate-edit.php';
930 930
 
931
-	if ( $echo ) {
931
+	if ($echo) {
932 932
 		echo ob_get_clean();
933 933
 	} else {
934 934
 		return ob_get_clean();
@@ -937,154 +937,154 @@  discard block
 block discarded – undo
937 937
 }
938 938
 
939 939
 
940
-function wpinv_tools_callback( $args ) {
940
+function wpinv_tools_callback($args) {
941 941
     ob_start();
942 942
     ?>
943 943
     </td><tr>
944 944
     <td colspan="2" class="wpinv_tools_tdbox">
945 945
     <?php
946
-    if ( $args['desc'] ) {
946
+    if ($args['desc']) {
947 947
 ?>
948 948
 <p><?php echo $args['desc']; ?></p><?php } ?>
949
-    <?php do_action( 'wpinv_tools_before' ); ?>
949
+    <?php do_action('wpinv_tools_before'); ?>
950 950
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
951 951
         <thead>
952 952
             <tr>
953
-                <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th>
954
-                <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th>
955
-                <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th>
953
+                <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th>
954
+                <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th>
955
+                <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th>
956 956
             </tr>
957 957
         </thead>
958 958
 
959 959
         <tbody>
960 960
 			<tr>
961
-                <td><?php _e( 'Check Pages', 'invoicing' ); ?></td>
961
+                <td><?php _e('Check Pages', 'invoicing'); ?></td>
962 962
                 <td>
963
-                    <small><?php _e( 'Creates any missing GetPaid pages.', 'invoicing' ); ?></small>
963
+                    <small><?php _e('Creates any missing GetPaid pages.', 'invoicing'); ?></small>
964 964
                 </td>
965 965
                 <td>
966 966
 					<a href="
967 967
                     <?php
968 968
 						echo esc_url(
969 969
 							wp_nonce_url(
970
-								add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
970
+								add_query_arg('getpaid-admin-action', 'create_missing_pages'),
971 971
 								'getpaid-nonce',
972 972
 								'getpaid-nonce'
973 973
 							)
974 974
 						);
975 975
 					?>
976
-                    " class="button button-primary"><?php _e( 'Run', 'invoicing' ); ?></a>
976
+                    " class="button button-primary"><?php _e('Run', 'invoicing'); ?></a>
977 977
                 </td>
978 978
             </tr>
979 979
 			<tr>
980
-                <td><?php _e( 'Create Database Tables', 'invoicing' ); ?></td>
980
+                <td><?php _e('Create Database Tables', 'invoicing'); ?></td>
981 981
                 <td>
982
-                    <small><?php _e( 'Run this tool to create any missing database tables.', 'invoicing' ); ?></small>
982
+                    <small><?php _e('Run this tool to create any missing database tables.', 'invoicing'); ?></small>
983 983
                 </td>
984 984
                 <td>
985 985
 					<a href="
986 986
                     <?php
987 987
 						echo esc_url(
988 988
 							wp_nonce_url(
989
-								add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
989
+								add_query_arg('getpaid-admin-action', 'create_missing_tables'),
990 990
 								'getpaid-nonce',
991 991
 								'getpaid-nonce'
992 992
 							)
993 993
 						);
994 994
 					?>
995
-                    " class="button button-primary"><?php _e( 'Run', 'invoicing' ); ?></a>
995
+                    " class="button button-primary"><?php _e('Run', 'invoicing'); ?></a>
996 996
                 </td>
997 997
             </tr>
998 998
 			<tr>
999
-                <td><?php _e( 'Migrate old invoices', 'invoicing' ); ?></td>
999
+                <td><?php _e('Migrate old invoices', 'invoicing'); ?></td>
1000 1000
                 <td>
1001
-                    <small><?php _e( 'If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing' ); ?></small>
1001
+                    <small><?php _e('If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing'); ?></small>
1002 1002
                 </td>
1003 1003
                 <td>
1004 1004
 					<a href="
1005 1005
                     <?php
1006 1006
 						echo esc_url(
1007 1007
 							wp_nonce_url(
1008
-								add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1008
+								add_query_arg('getpaid-admin-action', 'migrate_old_invoices'),
1009 1009
 								'getpaid-nonce',
1010 1010
 								'getpaid-nonce'
1011 1011
 							)
1012 1012
 						);
1013 1013
 					?>
1014
-                    " class="button button-primary"><?php _e( 'Run', 'invoicing' ); ?></a>
1014
+                    " class="button button-primary"><?php _e('Run', 'invoicing'); ?></a>
1015 1015
                 </td>
1016 1016
             </tr>
1017 1017
 
1018 1018
 			<tr>
1019
-                <td><?php _e( 'Recalculate Discounts', 'invoicing' ); ?></td>
1019
+                <td><?php _e('Recalculate Discounts', 'invoicing'); ?></td>
1020 1020
                 <td>
1021
-                    <small><?php _e( 'Recalculate discounts for existing invoices that have discount codes but are not discounted.', 'invoicing' ); ?></small>
1021
+                    <small><?php _e('Recalculate discounts for existing invoices that have discount codes but are not discounted.', 'invoicing'); ?></small>
1022 1022
                 </td>
1023 1023
                 <td>
1024 1024
 					<a href="
1025 1025
                     <?php
1026 1026
 						echo esc_url(
1027 1027
 							wp_nonce_url(
1028
-								add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1028
+								add_query_arg('getpaid-admin-action', 'recalculate_discounts'),
1029 1029
 								'getpaid-nonce',
1030 1030
 								'getpaid-nonce'
1031 1031
 							)
1032 1032
 						);
1033 1033
 					?>
1034
-                    " class="button button-primary"><?php _e( 'Run', 'invoicing' ); ?></a>
1034
+                    " class="button button-primary"><?php _e('Run', 'invoicing'); ?></a>
1035 1035
                 </td>
1036 1036
             </tr>
1037 1037
 
1038 1038
 			<tr>
1039
-                <td><?php _e( 'Set-up Wizard', 'invoicing' ); ?></td>
1039
+                <td><?php _e('Set-up Wizard', 'invoicing'); ?></td>
1040 1040
                 <td>
1041
-                    <small><?php _e( 'Launch the quick set-up wizard.', 'invoicing' ); ?></small>
1041
+                    <small><?php _e('Launch the quick set-up wizard.', 'invoicing'); ?></small>
1042 1042
                 </td>
1043 1043
                 <td>
1044 1044
 					<a href="
1045 1045
                     <?php
1046
-						echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1046
+						echo esc_url(admin_url('index.php?page=gp-setup'));
1047 1047
 					?>
1048
-                    " class="button button-primary"><?php _e( 'Launch', 'invoicing' ); ?></a>
1048
+                    " class="button button-primary"><?php _e('Launch', 'invoicing'); ?></a>
1049 1049
                 </td>
1050 1050
             </tr>
1051 1051
 
1052
-			<?php do_action( 'wpinv_tools_row' ); ?>
1052
+			<?php do_action('wpinv_tools_row'); ?>
1053 1053
         </tbody>
1054 1054
     </table>
1055
-    <?php do_action( 'wpinv_tools_after' ); ?>
1055
+    <?php do_action('wpinv_tools_after'); ?>
1056 1056
     <?php
1057 1057
     echo ob_get_clean();
1058 1058
 }
1059 1059
 
1060 1060
 
1061
-function wpinv_descriptive_text_callback( $args ) {
1062
-	echo wp_kses_post( $args['desc'] );
1061
+function wpinv_descriptive_text_callback($args) {
1062
+	echo wp_kses_post($args['desc']);
1063 1063
 }
1064 1064
 
1065
-function wpinv_raw_html_callback( $args ) {
1065
+function wpinv_raw_html_callback($args) {
1066 1066
 	echo $args['desc'];
1067 1067
 }
1068 1068
 
1069
-function wpinv_hook_callback( $args ) {
1070
-	do_action( 'wpinv_' . $args['id'], $args );
1069
+function wpinv_hook_callback($args) {
1070
+	do_action('wpinv_' . $args['id'], $args);
1071 1071
 }
1072 1072
 
1073 1073
 function wpinv_set_settings_cap() {
1074 1074
 	return wpinv_get_capability();
1075 1075
 }
1076
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1076
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1077 1077
 
1078 1078
 
1079
-function wpinv_on_update_settings( $old_value, $value, $option ) {
1080
-    $old = ! empty( $old_value['remove_data_on_unistall'] ) ? 1 : '';
1081
-    $new = ! empty( $value['remove_data_on_unistall'] ) ? 1 : '';
1079
+function wpinv_on_update_settings($old_value, $value, $option) {
1080
+    $old = !empty($old_value['remove_data_on_unistall']) ? 1 : '';
1081
+    $new = !empty($value['remove_data_on_unistall']) ? 1 : '';
1082 1082
 
1083
-    if ( $old != $new ) {
1084
-        update_option( 'wpinv_remove_data_on_invoice_unistall', $new );
1083
+    if ($old != $new) {
1084
+        update_option('wpinv_remove_data_on_invoice_unistall', $new);
1085 1085
     }
1086 1086
 }
1087
-add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 );
1087
+add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3);
1088 1088
 
1089 1089
 /**
1090 1090
  * Returns the merge tags help text.
@@ -1093,16 +1093,16 @@  discard block
 block discarded – undo
1093 1093
  *
1094 1094
  * @return string
1095 1095
  */
1096
-function wpinv_get_merge_tags_help_text( $subscription = false ) {
1096
+function wpinv_get_merge_tags_help_text($subscription = false) {
1097 1097
 
1098 1098
 	$url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1099 1099
 	$link = sprintf(
1100 1100
 		'<strong><a href="%s" target="_blank">%s</a></strong>',
1101 1101
 		$url,
1102
-		esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1102
+		esc_html__('View available merge tags.', 'wpinv-quotes')
1103 1103
 	);
1104 1104
 
1105
-	$description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1105
+	$description = esc_html__('The content of the email (Merge Tags and HTML are allowed).', 'invoicing');
1106 1106
 
1107 1107
 	return "$description $link";
1108 1108
 
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
             'getpaid-nonce',
58 58
             'getpaid-nonce'
59 59
         );
60
-		$anchor = __( 'Deactivate', 'invoicing' );
61
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
60
+        $anchor = __( 'Deactivate', 'invoicing' );
61
+        $title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
62 62
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
63 63
 
64 64
     } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) {
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
             'getpaid-nonce',
74 74
             'getpaid-nonce'
75 75
         );
76
-		$anchor = __( 'Activate', 'invoicing' );
77
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
76
+        $anchor = __( 'Activate', 'invoicing' );
77
+        $title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
78 78
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
79 79
 
80 80
     }
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
             'getpaid-nonce'
92 92
         )
93 93
     );
94
-	$anchor = __( 'Delete', 'invoicing' );
95
-	$title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
94
+    $anchor = __( 'Delete', 'invoicing' );
95
+    $title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
96 96
     $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
97 97
 
98 98
     $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
             $types = wpinv_get_discount_types();
119 119
 
120 120
             foreach ( $types as $name => $type ) {
121
-			echo '<option value="' . esc_attr( $name ) . '"';
121
+            echo '<option value="' . esc_attr( $name ) . '"';
122 122
 
123
-			if ( isset( $_GET['discount_type'] ) ) {
124
-				selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
123
+            if ( isset( $_GET['discount_type'] ) ) {
124
+                selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
125 125
                 }
126 126
 
127
-			echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
127
+            echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
128 128
             }
129 129
         ?>
130 130
     </select>
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
         // Filter vat rule type
152 152
         if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
153 153
             $meta_query[] = array(
154
-				'key'     => '_wpi_discount_type',
155
-				'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
156
-				'compare' => '=',
157
-			);
158
-			}
154
+                'key'     => '_wpi_discount_type',
155
+                'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
156
+                'compare' => '=',
157
+            );
158
+            }
159 159
 
160 160
         if ( ! empty( $meta_query ) ) {
161 161
             $vars['meta_query'] = $meta_query;
162
-			}
162
+            }
163 163
     }
164 164
 
165 165
     return $vars;
Please login to merge, or discard this patch.
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -1,51 +1,51 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( ! defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
8
-function wpinv_discount_custom_column( $column ) {
7
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
8
+function wpinv_discount_custom_column($column) {
9 9
     global $post;
10 10
 
11
-    $discount = new WPInv_Discount( $post );
11
+    $discount = new WPInv_Discount($post);
12 12
 
13
-    switch ( $column ) {
13
+    switch ($column) {
14 14
         case 'code':
15
-            echo esc_html( $discount->get_code() );
15
+            echo esc_html($discount->get_code());
16 16
             break;
17 17
         case 'amount':
18
-            echo wp_kses_post( $discount->get_formatted_amount() );
18
+            echo wp_kses_post($discount->get_formatted_amount());
19 19
             break;
20 20
         case 'usage':
21
-            echo wp_kses_post( $discount->get_usage() );
21
+            echo wp_kses_post($discount->get_usage());
22 22
             break;
23 23
         case 'start_date':
24
-            echo wp_kses_post( getpaid_format_date_value( $discount->get_start_date() ) );
24
+            echo wp_kses_post(getpaid_format_date_value($discount->get_start_date()));
25 25
             break;
26 26
         case 'expiry_date':
27
-            echo wp_kses_post( getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) ) );
27
+            echo wp_kses_post(getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing')));
28 28
             break;
29 29
     }
30 30
 }
31 31
 
32
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 90, 2 );
33
-function wpinv_post_row_actions( $actions, $post ) {
34
-    $post_type = ! empty( $post->post_type ) ? $post->post_type : '';
32
+add_filter('post_row_actions', 'wpinv_post_row_actions', 90, 2);
33
+function wpinv_post_row_actions($actions, $post) {
34
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
35 35
 
36
-    if ( $post_type == 'wpi_discount' ) {
37
-        $actions = wpinv_discount_row_actions( $post, $actions );
36
+    if ($post_type == 'wpi_discount') {
37
+        $actions = wpinv_discount_row_actions($post, $actions);
38 38
     }
39 39
 
40 40
     return $actions;
41 41
 }
42 42
 
43
-function wpinv_discount_row_actions( $discount, $row_actions ) {
44
-    $row_actions  = array();
45
-    $edit_link = get_edit_post_link( $discount->ID );
46
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
43
+function wpinv_discount_row_actions($discount, $row_actions) {
44
+    $row_actions = array();
45
+    $edit_link = get_edit_post_link($discount->ID);
46
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
47 47
 
48
-    if ( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) {
48
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
49 49
 
50 50
         $url = wp_nonce_url(
51 51
             add_query_arg(
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
             'getpaid-nonce',
58 58
             'getpaid-nonce'
59 59
         );
60
-		$anchor = __( 'Deactivate', 'invoicing' );
61
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
60
+		$anchor = __('Deactivate', 'invoicing');
61
+		$title  = esc_attr__('Are you sure you want to deactivate this discount?', 'invoicing');
62 62
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
63 63
 
64
-    } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) {
64
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
65 65
 
66
-        $url    = wp_nonce_url(
66
+        $url = wp_nonce_url(
67 67
             add_query_arg(
68 68
                 array(
69 69
                     'getpaid-admin-action' => 'activate_discount',
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
             'getpaid-nonce',
74 74
             'getpaid-nonce'
75 75
         );
76
-		$anchor = __( 'Activate', 'invoicing' );
77
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
76
+		$anchor = __('Activate', 'invoicing');
77
+		$title  = esc_attr__('Are you sure you want to activate this discount?', 'invoicing');
78 78
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
79 79
 
80 80
     }
81 81
 
82
-    $url    = esc_url(
82
+    $url = esc_url(
83 83
         wp_nonce_url(
84 84
             add_query_arg(
85 85
                 array(
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
             'getpaid-nonce'
92 92
         )
93 93
     );
94
-	$anchor = __( 'Delete', 'invoicing' );
95
-	$title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
94
+	$anchor = __('Delete', 'invoicing');
95
+	$title  = esc_attr__('Are you sure you want to delete this discount?', 'invoicing');
96 96
     $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
97 97
 
98
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
98
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
99 99
 
100 100
     return $row_actions;
101 101
 }
@@ -103,68 +103,68 @@  discard block
 block discarded – undo
103 103
 function wpinv_restrict_manage_posts() {
104 104
     global $typenow;
105 105
 
106
-    if ( 'wpi_discount' == $typenow ) {
106
+    if ('wpi_discount' == $typenow) {
107 107
         wpinv_discount_filters();
108 108
     }
109 109
 }
110
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
110
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
111 111
 
112 112
 function wpinv_discount_filters() {
113 113
 
114 114
     ?>
115 115
     <select name="discount_type" id="dropdown_wpinv_discount_type">
116
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
116
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
117 117
         <?php
118 118
             $types = wpinv_get_discount_types();
119 119
 
120
-            foreach ( $types as $name => $type ) {
121
-			echo '<option value="' . esc_attr( $name ) . '"';
120
+            foreach ($types as $name => $type) {
121
+			echo '<option value="' . esc_attr($name) . '"';
122 122
 
123
-			if ( isset( $_GET['discount_type'] ) ) {
124
-				selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
123
+			if (isset($_GET['discount_type'])) {
124
+				selected($name, sanitize_text_field($_GET['discount_type']));
125 125
                 }
126 126
 
127
-			echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
127
+			echo '>' . esc_html__($type, 'invoicing') . '</option>';
128 128
             }
129 129
         ?>
130 130
     </select>
131 131
     <?php
132 132
 }
133 133
 
134
-function wpinv_request( $vars ) {
134
+function wpinv_request($vars) {
135 135
     global $typenow, $wp_post_statuses;
136 136
 
137
-    if ( getpaid_is_invoice_post_type( $typenow ) ) {
138
-        if ( ! isset( $vars['post_status'] ) ) {
139
-            $post_statuses = wpinv_get_invoice_statuses( false, false, $typenow );
137
+    if (getpaid_is_invoice_post_type($typenow)) {
138
+        if (!isset($vars['post_status'])) {
139
+            $post_statuses = wpinv_get_invoice_statuses(false, false, $typenow);
140 140
 
141
-            foreach ( $post_statuses as $status => $value ) {
142
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
143
-                    unset( $post_statuses[ $status ] );
141
+            foreach ($post_statuses as $status => $value) {
142
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
143
+                    unset($post_statuses[$status]);
144 144
                 }
145 145
             }
146 146
 
147
-            $vars['post_status'] = array_keys( $post_statuses );
147
+            $vars['post_status'] = array_keys($post_statuses);
148 148
         }
149
-} elseif ( 'wpi_discount' == $typenow ) {
150
-        $meta_query = ! empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
149
+} elseif ('wpi_discount' == $typenow) {
150
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
151 151
         // Filter vat rule type
152
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
152
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
153 153
             $meta_query[] = array(
154 154
 				'key'     => '_wpi_discount_type',
155
-				'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
155
+				'value'   => sanitize_key(urldecode($_GET['discount_type'])),
156 156
 				'compare' => '=',
157 157
 			);
158 158
 			}
159 159
 
160
-        if ( ! empty( $meta_query ) ) {
160
+        if (!empty($meta_query)) {
161 161
             $vars['meta_query'] = $meta_query;
162 162
 			}
163 163
     }
164 164
 
165 165
     return $vars;
166 166
 }
167
-add_filter( 'request', 'wpinv_request' );
167
+add_filter('request', 'wpinv_request');
168 168
 
169 169
 /**
170 170
  * Create a page and store the ID in an option.
@@ -176,61 +176,61 @@  discard block
 block discarded – undo
176 176
  * @param int $post_parent (default: 0) Parent for the new page
177 177
  * @return int page ID
178 178
  */
179
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
179
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
180 180
     global $wpdb;
181 181
 
182
-    $option_value = wpinv_get_option( $option );
182
+    $option_value = wpinv_get_option($option);
183 183
 
184
-    if ( ! empty( $option_value ) && ( $page_object = get_post( $option_value ) ) ) {
185
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
184
+    if (!empty($option_value) && ($page_object = get_post($option_value))) {
185
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
186 186
             // Valid page is already in place
187 187
             return $page_object->ID;
188 188
         }
189 189
     }
190 190
 
191
-    if ( ! empty( $post_parent ) ) {
192
-        $page = get_page_by_path( $post_parent );
193
-        if ( $page ) {
191
+    if (!empty($post_parent)) {
192
+        $page = get_page_by_path($post_parent);
193
+        if ($page) {
194 194
             $post_parent = $page->ID;
195 195
         } else {
196 196
             $post_parent = '';
197 197
         }
198 198
     }
199 199
 
200
-    if ( strlen( $page_content ) > 0 ) {
200
+    if (strlen($page_content) > 0) {
201 201
         // Search for an existing page with the specified page content (typically a shortcode)
202
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
202
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
203 203
     } else {
204 204
         // Search for an existing page with the specified page slug
205
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
205
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
206 206
     }
207 207
 
208
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
208
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
209 209
 
210
-    if ( $valid_page_found ) {
211
-        if ( $option ) {
212
-            wpinv_update_option( $option, $valid_page_found );
210
+    if ($valid_page_found) {
211
+        if ($option) {
212
+            wpinv_update_option($option, $valid_page_found);
213 213
         }
214 214
         return $valid_page_found;
215 215
     }
216 216
 
217 217
     // Search for a matching valid trashed page
218
-    if ( strlen( $page_content ) > 0 ) {
218
+    if (strlen($page_content) > 0) {
219 219
         // Search for an existing page with the specified page content (typically a shortcode)
220
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
220
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
221 221
     } else {
222 222
         // Search for an existing page with the specified page slug
223
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
223
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
224 224
     }
225 225
 
226
-    if ( $trashed_page_found ) {
226
+    if ($trashed_page_found) {
227 227
         $page_id   = $trashed_page_found;
228 228
         $page_data = array(
229 229
             'ID'          => $page_id,
230 230
             'post_status' => 'publish',
231 231
             'post_parent' => $post_parent,
232 232
         );
233
-        wp_update_post( $page_data );
233
+        wp_update_post($page_data);
234 234
     } else {
235 235
         $page_data = array(
236 236
             'post_status'    => 'publish',
@@ -242,11 +242,11 @@  discard block
 block discarded – undo
242 242
             'post_parent'    => $post_parent,
243 243
             'comment_status' => 'closed',
244 244
         );
245
-        $page_id = wp_insert_post( $page_data );
245
+        $page_id = wp_insert_post($page_data);
246 246
     }
247 247
 
248
-    if ( $option ) {
249
-        wpinv_update_option( $option, (int) $page_id );
248
+    if ($option) {
249
+        wpinv_update_option($option, (int) $page_id);
250 250
     }
251 251
 
252 252
     return $page_id;
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
  *
260 260
  * @return array
261 261
  */
262
-function wpinv_add_aui_screens( $screen_ids ) {
262
+function wpinv_add_aui_screens($screen_ids) {
263 263
 
264 264
     // load on these pages if set
265
-    $screen_ids = array_merge( $screen_ids, wpinv_get_screen_ids() );
265
+    $screen_ids = array_merge($screen_ids, wpinv_get_screen_ids());
266 266
 
267 267
     return $screen_ids;
268 268
 }
269
-add_filter( 'aui_screen_ids', 'wpinv_add_aui_screens' );
269
+add_filter('aui_screen_ids', 'wpinv_add_aui_screens');
Please login to merge, or discard this patch.
includes/admin/class-wpinv-admin-menus.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
     }
25 25
 
26 26
     /**
27
-	 * Highlights sub menus.
28
-	 */
29
-	public function set_admin_menu_class() {
30
-		global $current_screen, $parent_file, $submenu_file;
27
+     * Highlights sub menus.
28
+     */
29
+    public function set_admin_menu_class() {
30
+        global $current_screen, $parent_file, $submenu_file;
31 31
 
32 32
         if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) {
33
-			$parent_file = 'wpinv';
34
-			$submenu_file = 'edit.php?post_type=' . $current_screen->id;
33
+            $parent_file = 'wpinv';
34
+            $submenu_file = 'edit.php?post_type=' . $current_screen->id;
35 35
         }
36 36
 
37 37
     }
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
                 foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
166 166
                     $tab_url = add_query_arg(
167 167
                         array(
168
-							'settings-updated' => false,
169
-							'tab'              => $tab_id,
168
+                            'settings-updated' => false,
169
+                            'tab'              => $tab_id,
170 170
                         ),
171 171
                         'admin.php?page=wpinv-settings'
172 172
                     );
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
                     $number++;
194 194
                     $tab_url = add_query_arg(
195 195
                         array(
196
-							'settings-updated' => false,
197
-							'tab'              => $active_tab,
198
-							'section'          => $section_id,
196
+                            'settings-updated' => false,
197
+                            'tab'              => $active_tab,
198
+                            'section'          => $section_id,
199 199
                         ),
200 200
                         admin_url( 'admin.php?page=wpinv-settings' )
201 201
                     );
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Setup menus in WP admin.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * WC_Admin_Menus Class.
@@ -13,14 +13,14 @@  discard block
 block discarded – undo
13 13
      * Hook in tabs.
14 14
      */
15 15
     public function __construct() {
16
-        add_action( 'admin_head', array( $this, 'set_admin_menu_class' ) );
17
-        add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 );
18
-        add_action( 'admin_menu', array( $this, 'add_customers_menu' ), 18 );
19
-        add_action( 'admin_menu', array( $this, 'add_subscriptions_menu' ), 40 );
20
-        add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 );
21
-        add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 );
22
-        add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 );
23
-        add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
16
+        add_action('admin_head', array($this, 'set_admin_menu_class'));
17
+        add_action('admin_menu', array($this, 'admin_menu'), 10);
18
+        add_action('admin_menu', array($this, 'add_customers_menu'), 18);
19
+        add_action('admin_menu', array($this, 'add_subscriptions_menu'), 40);
20
+        add_action('admin_menu', array($this, 'add_addons_menu'), 100);
21
+        add_action('admin_menu', array($this, 'add_settings_menu'), 60);
22
+        add_action('admin_menu', array($this, 'remove_admin_submenus'), 10);
23
+        add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes'));
24 24
     }
25 25
 
26 26
     /**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	public function set_admin_menu_class() {
30 30
 		global $current_screen, $parent_file, $submenu_file;
31 31
 
32
-        if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) {
32
+        if (!empty($current_screen->id) && in_array($current_screen->id, array('wpi_discount', 'wpi_payment_form', 'wpi_invoice'))) {
33 33
 			$parent_file = 'wpinv';
34 34
 			$submenu_file = 'edit.php?post_type=' . $current_screen->id;
35 35
         }
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 
39 39
     public function admin_menu() {
40 40
 
41
-        $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() );
41
+        $capability = apply_filters('invoicing_capability', wpinv_get_capability());
42 42
         add_menu_page(
43
-            __( 'GetPaid', 'invoicing' ),
44
-            __( 'GetPaid', 'invoicing' ),
43
+            __('GetPaid', 'invoicing'),
44
+            __('GetPaid', 'invoicing'),
45 45
             $capability,
46 46
             'wpinv',
47 47
             null,
48
-            'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg' ) ),
48
+            'data:image/svg+xml;base64,' . base64_encode(file_get_contents(WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg')),
49 49
             '54.123460'
50 50
         );
51 51
 
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
     public function add_customers_menu() {
58 58
         add_submenu_page(
59 59
             'wpinv',
60
-            __( 'Customers', 'invoicing' ),
61
-            __( 'Customers', 'invoicing' ),
60
+            __('Customers', 'invoicing'),
61
+            __('Customers', 'invoicing'),
62 62
             wpinv_get_capability(),
63 63
             'wpinv-customers',
64
-            array( $this, 'customers_page' )
64
+            array($this, 'customers_page')
65 65
         );
66 66
     }
67 67
 
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
     public function add_subscriptions_menu() {
72 72
         add_submenu_page(
73 73
             'wpinv',
74
-            __( 'Subscriptions', 'invoicing' ),
75
-            __( 'Subscriptions', 'invoicing' ),
74
+            __('Subscriptions', 'invoicing'),
75
+            __('Subscriptions', 'invoicing'),
76 76
             wpinv_get_capability(),
77 77
             'wpinv-subscriptions',
78 78
             'wpinv_subscriptions_page'
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
                     width: 30%;
92 92
                 }
93 93
             </style>
94
-            <h1><?php echo esc_html( __( 'Customers', 'invoicing' ) ); ?>&nbsp;<a href="<?php echo wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'download_customers' ), 'getpaid-nonce', 'getpaid-nonce' ); ?>" class="page-title-action"><?php _e( 'Export', 'invoicing' ); ?></a></h1>
94
+            <h1><?php echo esc_html(__('Customers', 'invoicing')); ?>&nbsp;<a href="<?php echo wp_nonce_url(add_query_arg('getpaid-admin-action', 'download_customers'), 'getpaid-nonce', 'getpaid-nonce'); ?>" class="page-title-action"><?php _e('Export', 'invoicing'); ?></a></h1>
95 95
             <form method="post">
96 96
             <?php
97 97
                 $table = new WPInv_Customers_Table();
98 98
                 $table->prepare_items();
99
-                $table->search_box( __( 'Search Customers', 'invoicing' ), 'search-customers' );
99
+                $table->search_box(__('Search Customers', 'invoicing'), 'search-customers');
100 100
                 $table->display();
101 101
             ?>
102 102
             </form>
@@ -110,26 +110,26 @@  discard block
 block discarded – undo
110 110
     public function add_settings_menu() {
111 111
         add_submenu_page(
112 112
             'wpinv',
113
-            __( 'Invoice Settings', 'invoicing' ),
114
-            __( 'Settings', 'invoicing' ),
115
-            apply_filters( 'invoicing_capability', wpinv_get_capability() ),
113
+            __('Invoice Settings', 'invoicing'),
114
+            __('Settings', 'invoicing'),
115
+            apply_filters('invoicing_capability', wpinv_get_capability()),
116 116
             'wpinv-settings',
117
-            array( $this, 'options_page' )
117
+            array($this, 'options_page')
118 118
         );
119 119
     }
120 120
 
121 121
     public function add_addons_menu() {
122
-        if ( ! apply_filters( 'wpi_show_addons_page', true ) ) {
122
+        if (!apply_filters('wpi_show_addons_page', true)) {
123 123
             return;
124 124
         }
125 125
 
126 126
         add_submenu_page(
127 127
             'wpinv',
128
-            __( 'Invoicing extensions', 'invoicing' ),
129
-            __( 'Extensions', 'invoicing' ),
128
+            __('Invoicing extensions', 'invoicing'),
129
+            __('Extensions', 'invoicing'),
130 130
             'manage_options',
131 131
             'wpi-addons',
132
-            array( $this, 'addons_page' )
132
+            array($this, 'addons_page')
133 133
         );
134 134
     }
135 135
 
@@ -140,29 +140,29 @@  discard block
 block discarded – undo
140 140
 
141 141
     function options_page() {
142 142
 
143
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
143
+        if (!wpinv_current_user_can_manage_invoicing()) {
144 144
             return;
145 145
         }
146 146
 
147 147
         $settings_tabs = wpinv_get_settings_tabs();
148
-        $settings_tabs = empty( $settings_tabs ) ? array() : $settings_tabs;
149
-        $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
150
-        $sections      = wpinv_get_settings_tab_sections( $active_tab );
148
+        $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
149
+        $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
150
+        $sections      = wpinv_get_settings_tab_sections($active_tab);
151 151
         $key           = 'main';
152 152
 
153
-        if ( is_array( $sections ) ) {
154
-            $key = key( $sections );
153
+        if (is_array($sections)) {
154
+            $key = key($sections);
155 155
         }
156 156
 
157 157
         add_thickbox();
158 158
 
159
-        $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
160
-        $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? sanitize_text_field( $_GET['section'] ) : $key;
159
+        $registered_sections = wpinv_get_settings_tab_sections($active_tab);
160
+        $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? sanitize_text_field($_GET['section']) : $key;
161 161
         ?>
162 162
         <div class="wrap">
163 163
             <h1 class="nav-tab-wrapper">
164 164
                 <?php
165
-                foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
165
+                foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
166 166
                     $tab_url = add_query_arg(
167 167
                         array(
168 168
 							'settings-updated' => false,
@@ -172,23 +172,23 @@  discard block
 block discarded – undo
172 172
                     );
173 173
 
174 174
                     // Remove the section from the tabs so we always end up at the main section
175
-                    $tab_url = remove_query_arg( 'section', $tab_url );
176
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
175
+                    $tab_url = remove_query_arg('section', $tab_url);
176
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
177 177
 
178 178
                     $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
179 179
 
180
-                    echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
181
-                    echo esc_html( $tab_name );
180
+                    echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
181
+                    echo esc_html($tab_name);
182 182
                     echo '</a>';
183 183
                 }
184 184
                 ?>
185 185
             </h1>
186 186
             <?php
187
-            $number_of_sections = count( $sections );
187
+            $number_of_sections = count($sections);
188 188
             $number = 0;
189
-            if ( $number_of_sections > 1 ) {
189
+            if ($number_of_sections > 1) {
190 190
                 echo '<div><ul class="subsubsub">';
191
-                foreach ( $sections as $section_id => $section_name ) {
191
+                foreach ($sections as $section_id => $section_name) {
192 192
                     echo '<li>';
193 193
                     $number++;
194 194
                     $tab_url = add_query_arg(
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
 							'tab'              => $active_tab,
198 198
 							'section'          => $section_id,
199 199
                         ),
200
-                        admin_url( 'admin.php?page=wpinv-settings' )
200
+                        admin_url('admin.php?page=wpinv-settings')
201 201
                     );
202
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
202
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
203 203
                     $class = '';
204
-                    if ( $section == $section_id ) {
204
+                    if ($section == $section_id) {
205 205
                         $class = 'current';
206 206
                     }
207
-                    echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
207
+                    echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
208 208
 
209
-                    if ( $number != $number_of_sections ) {
209
+                    if ($number != $number_of_sections) {
210 210
                         echo ' | ';
211 211
                     }
212 212
                     echo '</li>';
@@ -218,20 +218,20 @@  discard block
 block discarded – undo
218 218
                 <form method="post" action="options.php">
219 219
                     <table class="form-table">
220 220
                         <?php
221
-                        settings_fields( 'wpinv_settings' );
221
+                        settings_fields('wpinv_settings');
222 222
 
223
-                        if ( 'main' === $section ) {
224
-                            do_action( 'wpinv_settings_tab_top', $active_tab );
223
+                        if ('main' === $section) {
224
+                            do_action('wpinv_settings_tab_top', $active_tab);
225 225
                         }
226 226
 
227
-                        do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section );
228
-                        do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section );
229
-                        do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section );
230
-                        do_action( 'getpaid_settings_tab_bottom', $active_tab, $section );
227
+                        do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section);
228
+                        do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section);
229
+                        do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section);
230
+                        do_action('getpaid_settings_tab_bottom', $active_tab, $section);
231 231
 
232 232
                         // For backwards compatibility
233
-                        if ( 'main' === $section ) {
234
-                            do_action( 'wpinv_settings_tab_bottom', $active_tab );
233
+                        if ('main' === $section) {
234
+                            do_action('wpinv_settings_tab_bottom', $active_tab);
235 235
                         }
236 236
                         ?>
237 237
                     </table>
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     }
244 244
 
245 245
     public function remove_admin_submenus() {
246
-        remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
246
+        remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
247 247
     }
248 248
 
249 249
     /**
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
 
254 254
         add_meta_box(
255 255
             'wpinv_endpoints_nav_link',
256
-            __( 'GetPaid endpoints', 'invoicing' ),
257
-            array( $this, 'nav_menu_links' ),
256
+            __('GetPaid endpoints', 'invoicing'),
257
+            array($this, 'nav_menu_links'),
258 258
             'nav-menus',
259 259
             'side',
260 260
             'low'
@@ -269,12 +269,12 @@  discard block
 block discarded – undo
269 269
         $endpoints = $this->get_menu_items();
270 270
         ?>
271 271
         <div id="invoicing-endpoints" class="posttypediv">
272
-            <?php if ( ! empty( $endpoints['pages'] ) ) : ?>
272
+            <?php if (!empty($endpoints['pages'])) : ?>
273 273
                 <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active">
274 274
                     <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear">
275 275
                         <?php
276
-                            $walker = new Walker_Nav_Menu_Checklist( array() );
277
-                            echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $endpoints['pages'] ), 0, (object) array( 'walker' => $walker ) );
276
+                            $walker = new Walker_Nav_Menu_Checklist(array());
277
+                            echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $endpoints['pages']), 0, (object) array('walker' => $walker));
278 278
                         ?>
279 279
                     </ul>
280 280
                 </div>
@@ -283,11 +283,11 @@  discard block
 block discarded – undo
283 283
             <p class="button-controls wp-clearfix" data-items-type="invoicing-endpoints">
284 284
                 <span class="list-controls hide-if-no-js">
285 285
                     <input type="checkbox" id="invoicing-endpoints-tab" class="select-all">
286
-                    <label for="invoicing-endpoints-tab"><?php _e( 'Select all', 'invoicing' ); ?></label>
286
+                    <label for="invoicing-endpoints-tab"><?php _e('Select all', 'invoicing'); ?></label>
287 287
                 </span>
288 288
 
289 289
                 <span class="add-to-menu">
290
-                    <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints">
290
+                    <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints">
291 291
                     <span class="spinner"></span>
292 292
                 </span>
293 293
             </p>
@@ -305,18 +305,18 @@  discard block
 block discarded – undo
305 305
 
306 306
         $pages = array(
307 307
             array(
308
-                'id'    => wpinv_get_option( 'invoice_history_page' ),
309
-                'label' => __( 'My Invoices', 'invoicing' ),
308
+                'id'    => wpinv_get_option('invoice_history_page'),
309
+                'label' => __('My Invoices', 'invoicing'),
310 310
             ),
311 311
             array(
312
-                'id'    => wpinv_get_option( 'invoice_subscription_page' ),
313
-                'label' => __( 'My Subscriptions', 'invoicing' ),
312
+                'id'    => wpinv_get_option('invoice_subscription_page'),
313
+                'label' => __('My Subscriptions', 'invoicing'),
314 314
             ),
315 315
         );
316 316
 
317
-        foreach ( apply_filters( 'getpaid_menu_pages', $pages ) as $page ) {
317
+        foreach (apply_filters('getpaid_menu_pages', $pages) as $page) {
318 318
 
319
-            if ( (int) $page['id'] > 0 ) {
319
+            if ((int) $page['id'] > 0) {
320 320
 
321 321
                 $item                   = new stdClass();
322 322
                 $item->object_id        = (int) $page['id'];
@@ -324,11 +324,11 @@  discard block
 block discarded – undo
324 324
                 $item->object           = 'page';
325 325
                 $item->menu_item_parent = 0;
326 326
                 $item->type             = 'post_type';
327
-                $item->title            = esc_html( $page['label'] );
328
-                $item->url              = get_permalink( (int) $page['id'] );
327
+                $item->title            = esc_html($page['label']);
328
+                $item->url              = get_permalink((int) $page['id']);
329 329
                 $item->target           = '';
330 330
                 $item->attr_title       = '';
331
-                $item->classes          = array( 'wpinv-menu-item' );
331
+                $item->classes          = array('wpinv-menu-item');
332 332
                 $item->xfn              = '';
333 333
 
334 334
                 $items['pages'][]       = $item;
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
             }
337 337
 }
338 338
 
339
-        return apply_filters( 'wpinv_menu_items', $items );
339
+        return apply_filters('wpinv_menu_items', $items);
340 340
     }
341 341
 
342 342
 }
Please login to merge, or discard this patch.
includes/class-wpinv-addons.php 2 patches
Indentation   +210 added lines, -210 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;
9
+    exit;
10 10
 }
11 11
 
12 12
 /**
@@ -15,92 +15,92 @@  discard block
 block discarded – undo
15 15
 class WPInv_Admin_Addons extends Ayecode_Addons {
16 16
 
17 17
 
18
-	/**
19
-	 * Get the extensions page tabs.
20
-	 *
21
-	 * @return array of tabs.
22
-	 */
23
-	public function get_tabs() {
24
-		$tabs = array(
25
-			'addons'              => __( 'Addons', 'invoicing' ),
18
+    /**
19
+     * Get the extensions page tabs.
20
+     *
21
+     * @return array of tabs.
22
+     */
23
+    public function get_tabs() {
24
+        $tabs = array(
25
+            'addons'              => __( 'Addons', 'invoicing' ),
26 26
             'gateways'            => __( 'Payment Gateways', 'invoicing' ),
27 27
             'recommended_plugins' => __( 'Recommended plugins', 'invoicing' ),
28 28
             'membership'          => __( 'Membership', 'invoicing' ),
29
-		);
30
-
31
-		return $tabs;
32
-	}
33
-
34
-	/**
35
-	 * Get section content for the addons screen.
36
-	 *
37
-	 * @param  string $section_id
38
-	 *
39
-	 * @return array
40
-	 */
41
-	public function get_section_data( $section_id ) {
42
-		$section      = self::get_tab( $section_id );
43
-		$api_url = 'https://wpinvoicing.com/edd-api/v2/products/';
44
-		$section_data = new stdClass();
45
-
46
-		if ( $section_id == 'recommended_plugins' ) {
47
-			$section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
-		} elseif ( ! empty( $section ) ) {
49
-			if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
50
-			//if ( 1==1) {
51
-
52
-				$query_args = array(
53
-					'category' => $section_id,
54
-					'number'   => 100,
55
-				);
56
-				$query_args = apply_filters( 'wpeu_edd_api_query_args', $query_args, $api_url, $section_id );
57
-
58
-				$raw_section = wp_safe_remote_get(
29
+        );
30
+
31
+        return $tabs;
32
+    }
33
+
34
+    /**
35
+     * Get section content for the addons screen.
36
+     *
37
+     * @param  string $section_id
38
+     *
39
+     * @return array
40
+     */
41
+    public function get_section_data( $section_id ) {
42
+        $section      = self::get_tab( $section_id );
43
+        $api_url = 'https://wpinvoicing.com/edd-api/v2/products/';
44
+        $section_data = new stdClass();
45
+
46
+        if ( $section_id == 'recommended_plugins' ) {
47
+            $section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
+        } elseif ( ! empty( $section ) ) {
49
+            if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
50
+            //if ( 1==1) {
51
+
52
+                $query_args = array(
53
+                    'category' => $section_id,
54
+                    'number'   => 100,
55
+                );
56
+                $query_args = apply_filters( 'wpeu_edd_api_query_args', $query_args, $api_url, $section_id );
57
+
58
+                $raw_section = wp_safe_remote_get(
59 59
                     esc_url_raw( add_query_arg( $query_args, $api_url ) ),
60 60
                     array(
61
-						'user-agent' => 'Invoicing Addons Page',
62
-						'timeout'    => 15,
61
+                        'user-agent' => 'Invoicing Addons Page',
62
+                        'timeout'    => 15,
63 63
                     )
64 64
                 );
65 65
 
66
-				if ( ! is_wp_error( $raw_section ) ) {
67
-					$section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
66
+                if ( ! is_wp_error( $raw_section ) ) {
67
+                    $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
68 68
 
69
-					if ( ! empty( $section_data->products ) ) {
70
-						set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
71
-					}
72
-				}
73
-			}
69
+                    if ( ! empty( $section_data->products ) ) {
70
+                        set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
71
+                    }
72
+                }
73
+            }
74 74
 }
75 75
 
76
-		$products = isset( $section_data->products ) ? $section_data->products : array();
77
-		if ( 'addons' == $section_id ) {
78
-
79
-			$quotes = new stdClass();
80
-			$quotes->info = new stdClass();
81
-			$quotes->info->id = '';
82
-			$quotes->info->slug = 'invoicing-quotes';
83
-			$quotes->info->title = __( 'Quotes', 'invoicing' );
84
-			$quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
85
-			$quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
86
-			$quotes->info->thumbnail = WPINV_PLUGIN_URL . 'assets/images/Quotes-1-768x384.png';
87
-
88
-			$products[] = $quotes;
89
-		}
90
-
91
-		return apply_filters( 'wpi_addons_section_data', $products, $section_id );
92
-	}
93
-
94
-	/**
95
-	 * Outputs a button.
96
-	 *ccc
97
-	 * @param string $url
98
-	 * @param string $text
99
-	 * @param string $theme
100
-	 * @param string $plugin
101
-	 */
102
-	public function output_button( $addon ) {
103
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
76
+        $products = isset( $section_data->products ) ? $section_data->products : array();
77
+        if ( 'addons' == $section_id ) {
78
+
79
+            $quotes = new stdClass();
80
+            $quotes->info = new stdClass();
81
+            $quotes->info->id = '';
82
+            $quotes->info->slug = 'invoicing-quotes';
83
+            $quotes->info->title = __( 'Quotes', 'invoicing' );
84
+            $quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
85
+            $quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
86
+            $quotes->info->thumbnail = WPINV_PLUGIN_URL . 'assets/images/Quotes-1-768x384.png';
87
+
88
+            $products[] = $quotes;
89
+        }
90
+
91
+        return apply_filters( 'wpi_addons_section_data', $products, $section_id );
92
+    }
93
+
94
+    /**
95
+     * Outputs a button.
96
+     *ccc
97
+     * @param string $url
98
+     * @param string $text
99
+     * @param string $theme
100
+     * @param string $plugin
101
+     */
102
+    public function output_button( $addon ) {
103
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
104 104
 //		$button_text = __('Free','invoicing');
105 105
 //		$licensing = false;
106 106
 //		$installed = false;
@@ -112,128 +112,128 @@  discard block
 block discarded – undo
112 112
 //		$install_status = 'get';
113 113
 //		$onclick = '';
114 114
 
115
-		$wp_org_themes = array( 'supreme-directory', 'directory-starter' );
116
-
117
-		$button_args = array(
118
-			'type'           => ($current_tab == 'addons' || $current_tab == 'gateways') ? 'addons' : $current_tab,
119
-			'id'             => isset( $addon->info->id ) ? absint( $addon->info->id ) : '',
120
-			'title'          => isset( $addon->info->title ) ? $addon->info->title : '',
121
-			'button_text'    => __( 'Free', 'invoicing' ),
122
-			'price_text'     => __( 'Free', 'invoicing' ),
123
-			'link'           => isset( $addon->info->link ) ? $addon->info->link : '', // link to product
124
-			'url'            => isset( $addon->info->link ) ? $addon->info->link : '', // button url
125
-			'class'          => 'button-primary',
126
-			'install_status' => 'get',
127
-			'installed'      => false,
128
-			'price'          => '',
129
-			'licensing'      => isset( $addon->licensing->enabled ) && $addon->licensing->enabled ? true : false,
130
-			'license'        => isset( $addon->licensing->license ) && $addon->licensing->license ? $addon->licensing->license : '',
131
-			'onclick'        => '',
132
-			'slug'           => isset( $addon->info->slug ) ? $addon->info->slug : '',
133
-			'active'         => false,
134
-			'file'           => '',
135
-			'update_url'     => '',
136
-		);
137
-
138
-		if ( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset( $addon->info->slug ) && $addon->info->slug ) ) {
139
-			include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
140
-			$status = install_plugin_install_status(
115
+        $wp_org_themes = array( 'supreme-directory', 'directory-starter' );
116
+
117
+        $button_args = array(
118
+            'type'           => ($current_tab == 'addons' || $current_tab == 'gateways') ? 'addons' : $current_tab,
119
+            'id'             => isset( $addon->info->id ) ? absint( $addon->info->id ) : '',
120
+            'title'          => isset( $addon->info->title ) ? $addon->info->title : '',
121
+            'button_text'    => __( 'Free', 'invoicing' ),
122
+            'price_text'     => __( 'Free', 'invoicing' ),
123
+            'link'           => isset( $addon->info->link ) ? $addon->info->link : '', // link to product
124
+            'url'            => isset( $addon->info->link ) ? $addon->info->link : '', // button url
125
+            'class'          => 'button-primary',
126
+            'install_status' => 'get',
127
+            'installed'      => false,
128
+            'price'          => '',
129
+            'licensing'      => isset( $addon->licensing->enabled ) && $addon->licensing->enabled ? true : false,
130
+            'license'        => isset( $addon->licensing->license ) && $addon->licensing->license ? $addon->licensing->license : '',
131
+            'onclick'        => '',
132
+            'slug'           => isset( $addon->info->slug ) ? $addon->info->slug : '',
133
+            'active'         => false,
134
+            'file'           => '',
135
+            'update_url'     => '',
136
+        );
137
+
138
+        if ( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset( $addon->info->slug ) && $addon->info->slug ) ) {
139
+            include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
140
+            $status = install_plugin_install_status(
141 141
                 array(
142
-					'slug'    => $button_args['slug'],
143
-					'version' => '',
142
+                    'slug'    => $button_args['slug'],
143
+                    'version' => '',
144 144
                 )
145 145
             );
146
-			$button_args['install_status'] = isset( $status['status'] ) ? $status['status'] : 'install';
147
-			$button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
148
-		} elseif ( ($current_tab == 'addons' || $current_tab == 'gateways') && isset( $addon->info->id ) && $addon->info->id ) {
149
-			include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
150
-			if ( ! empty( $addon->licensing->edd_slug ) ) {
146
+            $button_args['install_status'] = isset( $status['status'] ) ? $status['status'] : 'install';
147
+            $button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
148
+        } elseif ( ($current_tab == 'addons' || $current_tab == 'gateways') && isset( $addon->info->id ) && $addon->info->id ) {
149
+            include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
150
+            if ( ! empty( $addon->licensing->edd_slug ) ) {
151 151
 $button_args['slug'] = $addon->licensing->edd_slug;}
152
-			$status = self::install_plugin_install_status( $addon );
153
-			$button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
154
-			if ( isset( $status['status'] ) ) {
152
+            $status = self::install_plugin_install_status( $addon );
153
+            $button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
154
+            if ( isset( $status['status'] ) ) {
155 155
 $button_args['install_status'] = $status['status'];}
156
-			$button_args['update_url'] = 'https://wpinvoicing.com';
157
-		} elseif ( $current_tab == 'themes' && isset( $addon->info->id ) && $addon->info->id ) {
158
-			if ( ! empty( $addon->licensing->edd_slug ) ) {
156
+            $button_args['update_url'] = 'https://wpinvoicing.com';
157
+        } elseif ( $current_tab == 'themes' && isset( $addon->info->id ) && $addon->info->id ) {
158
+            if ( ! empty( $addon->licensing->edd_slug ) ) {
159 159
 $button_args['slug'] = $addon->licensing->edd_slug;}
160
-			$button_args['installed'] = self::is_theme_installed( $addon );
161
-			if ( ! in_array( $button_args['slug'], $wp_org_themes ) ) {
162
-				$button_args['update_url'] = 'https://wpinvoicing.com';
163
-			}
164
-		}
165
-
166
-		// set price
167
-		if ( isset( $addon->pricing ) && ! empty( $addon->pricing ) ) {
168
-			if ( is_object( $addon->pricing ) ) {
169
-				$prices = (array)$addon->pricing;
170
-				$button_args['price'] = reset( $prices );
171
-			} elseif ( isset( $addon->pricing ) ) {
172
-				$button_args['price'] = $addon->pricing;
173
-			}
174
-		}
175
-
176
-		// set price text
177
-		if ( $button_args['price'] && $button_args['price'] != '0.00' ) {
178
-			$button_args['price_text'] = sprintf( __( 'From: $%d', 'invoicing' ), $button_args['price'] );
179
-		}
180
-
181
-		// set if installed
182
-		if ( in_array( $button_args['install_status'], array( 'installed', 'latest_installed', 'update_available', 'newer_installed' ) ) ) {
183
-			$button_args['installed'] = true;
184
-		}
160
+            $button_args['installed'] = self::is_theme_installed( $addon );
161
+            if ( ! in_array( $button_args['slug'], $wp_org_themes ) ) {
162
+                $button_args['update_url'] = 'https://wpinvoicing.com';
163
+            }
164
+        }
165
+
166
+        // set price
167
+        if ( isset( $addon->pricing ) && ! empty( $addon->pricing ) ) {
168
+            if ( is_object( $addon->pricing ) ) {
169
+                $prices = (array)$addon->pricing;
170
+                $button_args['price'] = reset( $prices );
171
+            } elseif ( isset( $addon->pricing ) ) {
172
+                $button_args['price'] = $addon->pricing;
173
+            }
174
+        }
175
+
176
+        // set price text
177
+        if ( $button_args['price'] && $button_args['price'] != '0.00' ) {
178
+            $button_args['price_text'] = sprintf( __( 'From: $%d', 'invoicing' ), $button_args['price'] );
179
+        }
180
+
181
+        // set if installed
182
+        if ( in_array( $button_args['install_status'], array( 'installed', 'latest_installed', 'update_available', 'newer_installed' ) ) ) {
183
+            $button_args['installed'] = true;
184
+        }
185 185
 
186 186
 //		print_r($button_args);
187
-		// set if active
188
-		if ( $button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes') ) {
189
-			if ( $button_args['type'] != 'themes' ) {
190
-				$button_args['active'] = is_plugin_active( $button_args['file'] );
191
-			} else {
192
-				$button_args['active'] = self::is_theme_active( $addon );
193
-			}
194
-		}
195
-
196
-		// set button text and class
197
-		if ( $button_args['active'] ) {
198
-			$button_args['button_text'] = __( 'Active', 'invoicing' );
199
-			$button_args['class'] = ' button-secondary disabled ';
200
-		} elseif ( $button_args['installed'] ) {
201
-			$button_args['button_text'] = __( 'Activate', 'invoicing' );
202
-
203
-			if ( $button_args['type'] != 'themes' ) {
204
-				if ( current_user_can( 'manage_options' ) ) {
205
-					$button_args['url'] = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $button_args['file'] ), 'activate-plugin_' . $button_args['file'] );
206
-				} else {
207
-					$button_args['url'] = '#';
208
-				}
209
-			} else {
210
-				if ( current_user_can( 'switch_themes' ) ) {
211
-					$button_args['url'] = self::get_theme_activation_url( $addon );
212
-				} else {
213
-					$button_args['url'] = '#';
214
-				}
215
-			}
187
+        // set if active
188
+        if ( $button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes') ) {
189
+            if ( $button_args['type'] != 'themes' ) {
190
+                $button_args['active'] = is_plugin_active( $button_args['file'] );
191
+            } else {
192
+                $button_args['active'] = self::is_theme_active( $addon );
193
+            }
194
+        }
195
+
196
+        // set button text and class
197
+        if ( $button_args['active'] ) {
198
+            $button_args['button_text'] = __( 'Active', 'invoicing' );
199
+            $button_args['class'] = ' button-secondary disabled ';
200
+        } elseif ( $button_args['installed'] ) {
201
+            $button_args['button_text'] = __( 'Activate', 'invoicing' );
202
+
203
+            if ( $button_args['type'] != 'themes' ) {
204
+                if ( current_user_can( 'manage_options' ) ) {
205
+                    $button_args['url'] = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $button_args['file'] ), 'activate-plugin_' . $button_args['file'] );
206
+                } else {
207
+                    $button_args['url'] = '#';
208
+                }
209
+            } else {
210
+                if ( current_user_can( 'switch_themes' ) ) {
211
+                    $button_args['url'] = self::get_theme_activation_url( $addon );
212
+                } else {
213
+                    $button_args['url'] = '#';
214
+                }
215
+            }
216 216
 } else {
217
-			if ( $button_args['type'] == 'recommended_plugins' ) {
218
-				$button_args['button_text'] = __( 'Install', 'invoicing' );
219
-					} else {
220
-				$button_args['button_text'] = __( 'Get it', 'invoicing' );
217
+            if ( $button_args['type'] == 'recommended_plugins' ) {
218
+                $button_args['button_text'] = __( 'Install', 'invoicing' );
219
+                    } else {
220
+                $button_args['button_text'] = __( 'Get it', 'invoicing' );
221 221
 
222
-				/*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
222
+                /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
223 223
 			$button_args['button_text'] = __('Install','invoicing');
224 224
 			$button_args['url'] = self::get_theme_install_url($button_args['slug']);
225 225
 			$button_args['onclick'] = 'gd_set_button_installing(this);';
226 226
 				}*/
227 227
 
228
-					}
229
-		}
228
+                    }
229
+        }
230 230
 
231
-		// filter the button arguments
232
-		$button_args = apply_filters( 'edd_api_button_args', $button_args );
231
+        // filter the button arguments
232
+        $button_args = apply_filters( 'edd_api_button_args', $button_args );
233 233
 //		print_r($button_args);
234
-		// set price text
235
-		if ( isset( $button_args['price_text'] ) ) {
236
-			?>
234
+        // set price text
235
+        if ( isset( $button_args['price_text'] ) ) {
236
+            ?>
237 237
 			<a
238 238
 				target="_blank"
239 239
 				class="addons-price-text"
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
 				<?php echo esc_html( $button_args['price_text'] ); ?>
242 242
 			</a>
243 243
 			<?php
244
-		}
244
+        }
245 245
 
246
-		?>
246
+        ?>
247 247
 		<a
248 248
 			data-licence="<?php echo esc_attr( $button_args['license'] ); ?>"
249 249
 			data-licensing="<?php echo $button_args['licensing'] ? 1 : 0; ?>"
@@ -267,33 +267,33 @@  discard block
 block discarded – undo
267 267
 		</a>
268 268
 		<?php
269 269
 
270
-	}
271
-
272
-
273
-	/**
274
-	 * Handles output of the addons page in admin.
275
-	 */
276
-	public function output() {
277
-		$tabs            = self::get_tabs();
278
-		$sections        = self::get_sections();
279
-		$theme           = wp_get_theme();
280
-		$section_keys    = array_keys( $sections );
281
-		$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
282
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
283
-		include_once WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php';
284
-	}
285
-
286
-	/**
287
-	 * A list of recommended wp.org plugins.
288
-	 * @return array
289
-	 */
290
-	public function get_recommend_wp_plugins() {
291
-		$plugins = array(
270
+    }
271
+
272
+
273
+    /**
274
+     * Handles output of the addons page in admin.
275
+     */
276
+    public function output() {
277
+        $tabs            = self::get_tabs();
278
+        $sections        = self::get_sections();
279
+        $theme           = wp_get_theme();
280
+        $section_keys    = array_keys( $sections );
281
+        $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
282
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
283
+        include_once WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php';
284
+    }
285
+
286
+    /**
287
+     * A list of recommended wp.org plugins.
288
+     * @return array
289
+     */
290
+    public function get_recommend_wp_plugins() {
291
+        $plugins = array(
292 292
             'invoicing-quotes' => array(
293 293
                 'url'       => 'https://wordpress.org/plugins/invoicing-quotes/',
294 294
                 'slug'      => 'invoicing-quotes',
295
-				'name'      => 'Quotes',
296
-				'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
295
+                'name'      => 'Quotes',
296
+                'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
297 297
                 'desc'      => __( 'Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.', 'invoicing' ),
298 298
             ),
299 299
             'geodirectory'     => array(
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
                 'name' => 'UsersWP',
309 309
                 'desc' => __( 'Allow frontend user login and registration as well as have slick profile pages.', 'invoicing' ),
310 310
             ),
311
-		);
311
+        );
312 312
 
313
-		return $plugins;
314
-	}
313
+        return $plugins;
314
+    }
315 315
 }
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * All Invoicing extensions screen related functions can be found here.
6 6
  *
7 7
  */
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if (!defined('ABSPATH')) {
9 9
 	exit;
10 10
 }
11 11
 
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
 	 */
23 23
 	public function get_tabs() {
24 24
 		$tabs = array(
25
-			'addons'              => __( 'Addons', 'invoicing' ),
26
-            'gateways'            => __( 'Payment Gateways', 'invoicing' ),
27
-            'recommended_plugins' => __( 'Recommended plugins', 'invoicing' ),
28
-            'membership'          => __( 'Membership', 'invoicing' ),
25
+			'addons'              => __('Addons', 'invoicing'),
26
+            'gateways'            => __('Payment Gateways', 'invoicing'),
27
+            'recommended_plugins' => __('Recommended plugins', 'invoicing'),
28
+            'membership'          => __('Membership', 'invoicing'),
29 29
 		);
30 30
 
31 31
 		return $tabs;
@@ -38,57 +38,57 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return array
40 40
 	 */
41
-	public function get_section_data( $section_id ) {
42
-		$section      = self::get_tab( $section_id );
41
+	public function get_section_data($section_id) {
42
+		$section      = self::get_tab($section_id);
43 43
 		$api_url = 'https://wpinvoicing.com/edd-api/v2/products/';
44 44
 		$section_data = new stdClass();
45 45
 
46
-		if ( $section_id == 'recommended_plugins' ) {
46
+		if ($section_id == 'recommended_plugins') {
47 47
 			$section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
-		} elseif ( ! empty( $section ) ) {
49
-			if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
48
+		} elseif (!empty($section)) {
49
+			if (false === ($section_data = get_transient('wpi_addons_section_' . $section_id))) { //@todo restore after testing
50 50
 			//if ( 1==1) {
51 51
 
52 52
 				$query_args = array(
53 53
 					'category' => $section_id,
54 54
 					'number'   => 100,
55 55
 				);
56
-				$query_args = apply_filters( 'wpeu_edd_api_query_args', $query_args, $api_url, $section_id );
56
+				$query_args = apply_filters('wpeu_edd_api_query_args', $query_args, $api_url, $section_id);
57 57
 
58 58
 				$raw_section = wp_safe_remote_get(
59
-                    esc_url_raw( add_query_arg( $query_args, $api_url ) ),
59
+                    esc_url_raw(add_query_arg($query_args, $api_url)),
60 60
                     array(
61 61
 						'user-agent' => 'Invoicing Addons Page',
62 62
 						'timeout'    => 15,
63 63
                     )
64 64
                 );
65 65
 
66
-				if ( ! is_wp_error( $raw_section ) ) {
67
-					$section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
66
+				if (!is_wp_error($raw_section)) {
67
+					$section_data = json_decode(wp_remote_retrieve_body($raw_section));
68 68
 
69
-					if ( ! empty( $section_data->products ) ) {
70
-						set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
69
+					if (!empty($section_data->products)) {
70
+						set_transient('wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS);
71 71
 					}
72 72
 				}
73 73
 			}
74 74
 }
75 75
 
76
-		$products = isset( $section_data->products ) ? $section_data->products : array();
77
-		if ( 'addons' == $section_id ) {
76
+		$products = isset($section_data->products) ? $section_data->products : array();
77
+		if ('addons' == $section_id) {
78 78
 
79 79
 			$quotes = new stdClass();
80 80
 			$quotes->info = new stdClass();
81 81
 			$quotes->info->id = '';
82 82
 			$quotes->info->slug = 'invoicing-quotes';
83
-			$quotes->info->title = __( 'Quotes', 'invoicing' );
84
-			$quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
83
+			$quotes->info->title = __('Quotes', 'invoicing');
84
+			$quotes->info->excerpt = __('Create quotes and estimates', 'invoicing');
85 85
 			$quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
86 86
 			$quotes->info->thumbnail = WPINV_PLUGIN_URL . 'assets/images/Quotes-1-768x384.png';
87 87
 
88 88
 			$products[] = $quotes;
89 89
 		}
90 90
 
91
-		return apply_filters( 'wpi_addons_section_data', $products, $section_id );
91
+		return apply_filters('wpi_addons_section_data', $products, $section_id);
92 92
 	}
93 93
 
94 94
 	/**
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 	 * @param string $theme
100 100
 	 * @param string $plugin
101 101
 	 */
102
-	public function output_button( $addon ) {
103
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
102
+	public function output_button($addon) {
103
+		$current_tab = empty($_GET['tab']) ? 'addons' : sanitize_title($_GET['tab']);
104 104
 //		$button_text = __('Free','invoicing');
105 105
 //		$licensing = false;
106 106
 //		$installed = false;
@@ -112,30 +112,30 @@  discard block
 block discarded – undo
112 112
 //		$install_status = 'get';
113 113
 //		$onclick = '';
114 114
 
115
-		$wp_org_themes = array( 'supreme-directory', 'directory-starter' );
115
+		$wp_org_themes = array('supreme-directory', 'directory-starter');
116 116
 
117 117
 		$button_args = array(
118 118
 			'type'           => ($current_tab == 'addons' || $current_tab == 'gateways') ? 'addons' : $current_tab,
119
-			'id'             => isset( $addon->info->id ) ? absint( $addon->info->id ) : '',
120
-			'title'          => isset( $addon->info->title ) ? $addon->info->title : '',
121
-			'button_text'    => __( 'Free', 'invoicing' ),
122
-			'price_text'     => __( 'Free', 'invoicing' ),
123
-			'link'           => isset( $addon->info->link ) ? $addon->info->link : '', // link to product
124
-			'url'            => isset( $addon->info->link ) ? $addon->info->link : '', // button url
119
+			'id'             => isset($addon->info->id) ? absint($addon->info->id) : '',
120
+			'title'          => isset($addon->info->title) ? $addon->info->title : '',
121
+			'button_text'    => __('Free', 'invoicing'),
122
+			'price_text'     => __('Free', 'invoicing'),
123
+			'link'           => isset($addon->info->link) ? $addon->info->link : '', // link to product
124
+			'url'            => isset($addon->info->link) ? $addon->info->link : '', // button url
125 125
 			'class'          => 'button-primary',
126 126
 			'install_status' => 'get',
127 127
 			'installed'      => false,
128 128
 			'price'          => '',
129
-			'licensing'      => isset( $addon->licensing->enabled ) && $addon->licensing->enabled ? true : false,
130
-			'license'        => isset( $addon->licensing->license ) && $addon->licensing->license ? $addon->licensing->license : '',
129
+			'licensing'      => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false,
130
+			'license'        => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '',
131 131
 			'onclick'        => '',
132
-			'slug'           => isset( $addon->info->slug ) ? $addon->info->slug : '',
132
+			'slug'           => isset($addon->info->slug) ? $addon->info->slug : '',
133 133
 			'active'         => false,
134 134
 			'file'           => '',
135 135
 			'update_url'     => '',
136 136
 		);
137 137
 
138
-		if ( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset( $addon->info->slug ) && $addon->info->slug ) ) {
138
+		if ('invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug)) {
139 139
 			include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
140 140
 			$status = install_plugin_install_status(
141 141
                 array(
@@ -143,81 +143,81 @@  discard block
 block discarded – undo
143 143
 					'version' => '',
144 144
                 )
145 145
             );
146
-			$button_args['install_status'] = isset( $status['status'] ) ? $status['status'] : 'install';
147
-			$button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
148
-		} elseif ( ($current_tab == 'addons' || $current_tab == 'gateways') && isset( $addon->info->id ) && $addon->info->id ) {
146
+			$button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install';
147
+			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
148
+		} elseif (($current_tab == 'addons' || $current_tab == 'gateways') && isset($addon->info->id) && $addon->info->id) {
149 149
 			include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
150
-			if ( ! empty( $addon->licensing->edd_slug ) ) {
151
-$button_args['slug'] = $addon->licensing->edd_slug;}
152
-			$status = self::install_plugin_install_status( $addon );
153
-			$button_args['file'] = isset( $status['file'] ) ? $status['file'] : '';
154
-			if ( isset( $status['status'] ) ) {
155
-$button_args['install_status'] = $status['status'];}
150
+			if (!empty($addon->licensing->edd_slug)) {
151
+$button_args['slug'] = $addon->licensing->edd_slug; }
152
+			$status = self::install_plugin_install_status($addon);
153
+			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
154
+			if (isset($status['status'])) {
155
+$button_args['install_status'] = $status['status']; }
156 156
 			$button_args['update_url'] = 'https://wpinvoicing.com';
157
-		} elseif ( $current_tab == 'themes' && isset( $addon->info->id ) && $addon->info->id ) {
158
-			if ( ! empty( $addon->licensing->edd_slug ) ) {
159
-$button_args['slug'] = $addon->licensing->edd_slug;}
160
-			$button_args['installed'] = self::is_theme_installed( $addon );
161
-			if ( ! in_array( $button_args['slug'], $wp_org_themes ) ) {
157
+		} elseif ($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
158
+			if (!empty($addon->licensing->edd_slug)) {
159
+$button_args['slug'] = $addon->licensing->edd_slug; }
160
+			$button_args['installed'] = self::is_theme_installed($addon);
161
+			if (!in_array($button_args['slug'], $wp_org_themes)) {
162 162
 				$button_args['update_url'] = 'https://wpinvoicing.com';
163 163
 			}
164 164
 		}
165 165
 
166 166
 		// set price
167
-		if ( isset( $addon->pricing ) && ! empty( $addon->pricing ) ) {
168
-			if ( is_object( $addon->pricing ) ) {
169
-				$prices = (array)$addon->pricing;
170
-				$button_args['price'] = reset( $prices );
171
-			} elseif ( isset( $addon->pricing ) ) {
167
+		if (isset($addon->pricing) && !empty($addon->pricing)) {
168
+			if (is_object($addon->pricing)) {
169
+				$prices = (array) $addon->pricing;
170
+				$button_args['price'] = reset($prices);
171
+			} elseif (isset($addon->pricing)) {
172 172
 				$button_args['price'] = $addon->pricing;
173 173
 			}
174 174
 		}
175 175
 
176 176
 		// set price text
177
-		if ( $button_args['price'] && $button_args['price'] != '0.00' ) {
178
-			$button_args['price_text'] = sprintf( __( 'From: $%d', 'invoicing' ), $button_args['price'] );
177
+		if ($button_args['price'] && $button_args['price'] != '0.00') {
178
+			$button_args['price_text'] = sprintf(__('From: $%d', 'invoicing'), $button_args['price']);
179 179
 		}
180 180
 
181 181
 		// set if installed
182
-		if ( in_array( $button_args['install_status'], array( 'installed', 'latest_installed', 'update_available', 'newer_installed' ) ) ) {
182
+		if (in_array($button_args['install_status'], array('installed', 'latest_installed', 'update_available', 'newer_installed'))) {
183 183
 			$button_args['installed'] = true;
184 184
 		}
185 185
 
186 186
 //		print_r($button_args);
187 187
 		// set if active
188
-		if ( $button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes') ) {
189
-			if ( $button_args['type'] != 'themes' ) {
190
-				$button_args['active'] = is_plugin_active( $button_args['file'] );
188
+		if ($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')) {
189
+			if ($button_args['type'] != 'themes') {
190
+				$button_args['active'] = is_plugin_active($button_args['file']);
191 191
 			} else {
192
-				$button_args['active'] = self::is_theme_active( $addon );
192
+				$button_args['active'] = self::is_theme_active($addon);
193 193
 			}
194 194
 		}
195 195
 
196 196
 		// set button text and class
197
-		if ( $button_args['active'] ) {
198
-			$button_args['button_text'] = __( 'Active', 'invoicing' );
197
+		if ($button_args['active']) {
198
+			$button_args['button_text'] = __('Active', 'invoicing');
199 199
 			$button_args['class'] = ' button-secondary disabled ';
200
-		} elseif ( $button_args['installed'] ) {
201
-			$button_args['button_text'] = __( 'Activate', 'invoicing' );
200
+		} elseif ($button_args['installed']) {
201
+			$button_args['button_text'] = __('Activate', 'invoicing');
202 202
 
203
-			if ( $button_args['type'] != 'themes' ) {
204
-				if ( current_user_can( 'manage_options' ) ) {
205
-					$button_args['url'] = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $button_args['file'] ), 'activate-plugin_' . $button_args['file'] );
203
+			if ($button_args['type'] != 'themes') {
204
+				if (current_user_can('manage_options')) {
205
+					$button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin=' . $button_args['file']), 'activate-plugin_' . $button_args['file']);
206 206
 				} else {
207 207
 					$button_args['url'] = '#';
208 208
 				}
209 209
 			} else {
210
-				if ( current_user_can( 'switch_themes' ) ) {
211
-					$button_args['url'] = self::get_theme_activation_url( $addon );
210
+				if (current_user_can('switch_themes')) {
211
+					$button_args['url'] = self::get_theme_activation_url($addon);
212 212
 				} else {
213 213
 					$button_args['url'] = '#';
214 214
 				}
215 215
 			}
216 216
 } else {
217
-			if ( $button_args['type'] == 'recommended_plugins' ) {
218
-				$button_args['button_text'] = __( 'Install', 'invoicing' );
217
+			if ($button_args['type'] == 'recommended_plugins') {
218
+				$button_args['button_text'] = __('Install', 'invoicing');
219 219
 					} else {
220
-				$button_args['button_text'] = __( 'Get it', 'invoicing' );
220
+				$button_args['button_text'] = __('Get it', 'invoicing');
221 221
 
222 222
 				/*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
223 223
 			$button_args['button_text'] = __('Install','invoicing');
@@ -229,41 +229,41 @@  discard block
 block discarded – undo
229 229
 		}
230 230
 
231 231
 		// filter the button arguments
232
-		$button_args = apply_filters( 'edd_api_button_args', $button_args );
232
+		$button_args = apply_filters('edd_api_button_args', $button_args);
233 233
 //		print_r($button_args);
234 234
 		// set price text
235
-		if ( isset( $button_args['price_text'] ) ) {
235
+		if (isset($button_args['price_text'])) {
236 236
 			?>
237 237
 			<a
238 238
 				target="_blank"
239 239
 				class="addons-price-text"
240
-				href="<?php echo esc_url( $button_args['link'] ); ?>">
241
-				<?php echo esc_html( $button_args['price_text'] ); ?>
240
+				href="<?php echo esc_url($button_args['link']); ?>">
241
+				<?php echo esc_html($button_args['price_text']); ?>
242 242
 			</a>
243 243
 			<?php
244 244
 		}
245 245
 
246 246
 		?>
247 247
 		<a
248
-			data-licence="<?php echo esc_attr( $button_args['license'] ); ?>"
248
+			data-licence="<?php echo esc_attr($button_args['license']); ?>"
249 249
 			data-licensing="<?php echo $button_args['licensing'] ? 1 : 0; ?>"
250
-			data-title="<?php echo esc_attr( $button_args['title'] ); ?>"
251
-			data-type="<?php echo esc_attr( $button_args['type'] ); ?>"
252
-			data-text-error-message="<?php _e( 'Something went wrong!', 'invoicing' ); ?>"
253
-			data-text-activate="<?php _e( 'Activate', 'invoicing' ); ?>"
254
-			data-text-activating="<?php _e( 'Activating', 'invoicing' ); ?>"
255
-			data-text-deactivate="<?php _e( 'Deactivate', 'invoicing' ); ?>"
256
-			data-text-installed="<?php _e( 'Installed', 'invoicing' ); ?>"
257
-			data-text-install="<?php _e( 'Install', 'invoicing' ); ?>"
258
-			data-text-installing="<?php _e( 'Installing', 'invoicing' ); ?>"
259
-			data-text-error="<?php _e( 'Error', 'invoicing' ); ?>"
250
+			data-title="<?php echo esc_attr($button_args['title']); ?>"
251
+			data-type="<?php echo esc_attr($button_args['type']); ?>"
252
+			data-text-error-message="<?php _e('Something went wrong!', 'invoicing'); ?>"
253
+			data-text-activate="<?php _e('Activate', 'invoicing'); ?>"
254
+			data-text-activating="<?php _e('Activating', 'invoicing'); ?>"
255
+			data-text-deactivate="<?php _e('Deactivate', 'invoicing'); ?>"
256
+			data-text-installed="<?php _e('Installed', 'invoicing'); ?>"
257
+			data-text-install="<?php _e('Install', 'invoicing'); ?>"
258
+			data-text-installing="<?php _e('Installing', 'invoicing'); ?>"
259
+			data-text-error="<?php _e('Error', 'invoicing'); ?>"
260 260
 			<?php
261
-            if ( ! empty( $button_args['onclick'] ) ) {
262
-echo " onclick='" . esc_attr( $button_args['onclick'] ) . "' ";}
261
+            if (!empty($button_args['onclick'])) {
262
+echo " onclick='" . esc_attr($button_args['onclick']) . "' "; }
263 263
 ?>
264
-			class="addons-button  <?php echo esc_attr( $button_args['class'] ); ?>"
265
-			href="<?php echo esc_url( $button_args['url'] ); ?>">
266
-			<?php echo esc_html( $button_args['button_text'] ); ?>
264
+			class="addons-button  <?php echo esc_attr($button_args['class']); ?>"
265
+			href="<?php echo esc_url($button_args['url']); ?>">
266
+			<?php echo esc_html($button_args['button_text']); ?>
267 267
 		</a>
268 268
 		<?php
269 269
 
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
 		$tabs            = self::get_tabs();
278 278
 		$sections        = self::get_sections();
279 279
 		$theme           = wp_get_theme();
280
-		$section_keys    = array_keys( $sections );
281
-		$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
282
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
280
+		$section_keys    = array_keys($sections);
281
+		$current_section = isset($_GET['section']) ? sanitize_text_field($_GET['section']) : current($section_keys);
282
+		$current_tab     = empty($_GET['tab']) ? 'addons' : sanitize_title($_GET['tab']);
283 283
 		include_once WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php';
284 284
 	}
285 285
 
@@ -294,19 +294,19 @@  discard block
 block discarded – undo
294 294
                 'slug'      => 'invoicing-quotes',
295 295
 				'name'      => 'Quotes',
296 296
 				'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
297
-                'desc'      => __( 'Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.', 'invoicing' ),
297
+                'desc'      => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.', 'invoicing'),
298 298
             ),
299 299
             'geodirectory'     => array(
300 300
                 'url'  => 'https://wordpress.org/plugins/geodirectory/',
301 301
                 'slug' => 'geodirectory',
302 302
                 'name' => 'GeoDirectory',
303
-                'desc' => __( 'Turn any WordPress theme into a global business directory portal.', 'invoicing' ),
303
+                'desc' => __('Turn any WordPress theme into a global business directory portal.', 'invoicing'),
304 304
             ),
305 305
             'userswp'          => array(
306 306
                 'url'  => 'https://wordpress.org/plugins/userswp/',
307 307
                 'slug' => 'userswp',
308 308
                 'name' => 'UsersWP',
309
-                'desc' => __( 'Allow frontend user login and registration as well as have slick profile pages.', 'invoicing' ),
309
+                'desc' => __('Allow frontend user login and registration as well as have slick profile pages.', 'invoicing'),
310 310
             ),
311 311
 		);
312 312
 
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-controller.php 2 patches
Indentation   +539 added lines, -539 removed lines patch added patch discarded remove patch
@@ -21,569 +21,569 @@
 block discarded – undo
21 21
  */
22 22
 class GetPaid_REST_Controller extends WP_REST_Controller {
23 23
 
24
-	/**
24
+    /**
25 25
      * The namespaces of this controller's route.
26 26
      *
27 27
      * @since 1.0.19
28 28
      * @var array
29 29
      */
30
-	protected $namespaces;
30
+    protected $namespaces;
31 31
 
32
-	/**
32
+    /**
33 33
      * The official namespace of this controller's route.
34 34
      *
35 35
      * @since 1.0.19
36 36
      * @var string
37 37
      */
38
-	protected $namespace = 'getpaid/v1';
38
+    protected $namespace = 'getpaid/v1';
39 39
 
40
-	/**
40
+    /**
41 41
      * Cached results of get_item_schema.
42 42
      *
43 43
      * @since 1.0.19
44 44
      * @var array
45 45
      */
46
-	protected $schema;
46
+    protected $schema;
47 47
 
48 48
     /**
49
-	 * Constructor.
50
-	 *
51
-	 * @since 1.0.19
52
-	 *
53
-	 */
54
-	public function __construct() {
55
-
56
-		// Offer several namespaces for backwards compatibility.
57
-		$this->namespaces = apply_filters(
58
-			'getpaid_rest_api_namespaces',
59
-			array(
60
-				'getpaid/v1',
61
-				'invoicing/v1',
62
-				'wpi/v1',
63
-			)
64
-		);
65
-
66
-		// Register REST routes.
49
+     * Constructor.
50
+     *
51
+     * @since 1.0.19
52
+     *
53
+     */
54
+    public function __construct() {
55
+
56
+        // Offer several namespaces for backwards compatibility.
57
+        $this->namespaces = apply_filters(
58
+            'getpaid_rest_api_namespaces',
59
+            array(
60
+                'getpaid/v1',
61
+                'invoicing/v1',
62
+                'wpi/v1',
63
+            )
64
+        );
65
+
66
+        // Register REST routes.
67 67
         add_action( 'rest_api_init', array( $this, 'register_routes' ) );
68 68
 
69
-	}
70
-
71
-	/**
72
-	 * Registers routes for each namespace.
73
-	 *
74
-	 * @since 1.0.19
75
-	 *
76
-	 */
77
-	public function register_routes() {
78
-
79
-		foreach ( $this->namespaces as $namespace ) {
80
-			$this->register_namespace_routes( $namespace );
81
-		}
82
-
83
-	}
84
-
85
-	/**
86
-	 * Registers routes for a namespace.
87
-	 *
88
-	 * @since 1.0.19
89
-	 *
90
-	 * @param string $namespace
91
-	 */
92
-	public function register_namespace_routes( /** @scrutinizer ignore-unused */ $namespace ) {
93
-
94
-		getpaid_doing_it_wrong(
95
-			__CLASS__ . '::' . __METHOD__,
96
-			/* translators: %s: register_namespace_routes() */
97
-			sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ),
98
-			'1.0.19'
99
-		);
100
-
101
-	}
102
-
103
-	/**
104
-	 * Get normalized rest base.
105
-	 *
106
-	 * @return string
107
-	 */
108
-	protected function get_normalized_rest_base() {
109
-		return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
110
-	}
111
-
112
-	/**
113
-	 * Fill batches.
114
-	 *
115
-	 * @param array array of request items.
116
-	 * @return array
117
-	 */
118
-	protected function fill_batch_keys( $items ) {
119
-
120
-		$items['create'] = empty( $items['create'] ) ? array() : $items['create'];
121
-		$items['update'] = empty( $items['update'] ) ? array() : $items['update'];
122
-		$items['delete'] = empty( $items['delete'] ) ? array() : wp_parse_id_list( $items['delete'] );
123
-		return $items;
124
-
125
-	}
126
-
127
-	/**
128
-	 * Check batch limit.
129
-	 *
130
-	 * @param array $items Request items.
131
-	 * @return bool|WP_Error
132
-	 */
133
-	protected function check_batch_limit( $items ) {
134
-		$limit = apply_filters( 'getpaid_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
135
-		$total = count( $items['create'] ) + count( $items['update'] ) + count( $items['delete'] );
136
-
137
-		if ( $total > $limit ) {
138
-			/* translators: %s: items limit */
139
-			return new WP_Error( 'getpaid_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'invoicing' ), $limit ), array( 'status' => 413 ) );
140
-		}
141
-
142
-		return true;
143
-	}
144
-
145
-	/**
146
-	 * Bulk create items.
147
-	 *
148
-	 * @param array $items Array of items to create.
149
-	 * @param WP_REST_Request $request Full details about the request.
150
-	 * @param WP_REST_Server $wp_rest_server
151
-	 * @return array()
152
-	 */
153
-	protected function batch_create_items( $items, $request, $wp_rest_server ) {
154
-
155
-		$query  = $request->get_query_params();
156
-		$create = array();
157
-
158
-		foreach ( $items as $item ) {
159
-			$_item = new WP_REST_Request( 'POST' );
160
-
161
-			// Default parameters.
162
-			$defaults = array();
163
-			$schema   = $this->get_public_item_schema();
164
-			foreach ( $schema['properties'] as $arg => $options ) {
165
-				if ( isset( $options['default'] ) ) {
166
-					$defaults[ $arg ] = $options['default'];
167
-				}
168
-			}
169
-			$_item->set_default_params( $defaults );
170
-
171
-			// Set request parameters.
172
-			$_item->set_body_params( $item );
173
-
174
-			// Set query (GET) parameters.
175
-			$_item->set_query_params( $query );
176
-
177
-			// Create the item.
178
-			$_response = $this->create_item( $_item );
179
-
180
-			// If an error occured...
181
-			if ( is_wp_error( $_response ) ) {
182
-
183
-				$create[]   = array(
184
-					'id'    => 0,
185
-					'error' => array(
186
-						'code'    => $_response->get_error_code(),
187
-						'message' => $_response->get_error_message(),
188
-						'data'    => $_response->get_error_data(),
189
-					),
190
-				);
191
-
192
-				continue;
193
-			}
194
-
195
-			$create[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
196
-
197
-		}
198
-
199
-		return $create;
69
+    }
70
+
71
+    /**
72
+     * Registers routes for each namespace.
73
+     *
74
+     * @since 1.0.19
75
+     *
76
+     */
77
+    public function register_routes() {
78
+
79
+        foreach ( $this->namespaces as $namespace ) {
80
+            $this->register_namespace_routes( $namespace );
81
+        }
82
+
83
+    }
84
+
85
+    /**
86
+     * Registers routes for a namespace.
87
+     *
88
+     * @since 1.0.19
89
+     *
90
+     * @param string $namespace
91
+     */
92
+    public function register_namespace_routes( /** @scrutinizer ignore-unused */ $namespace ) {
93
+
94
+        getpaid_doing_it_wrong(
95
+            __CLASS__ . '::' . __METHOD__,
96
+            /* translators: %s: register_namespace_routes() */
97
+            sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ),
98
+            '1.0.19'
99
+        );
100
+
101
+    }
102
+
103
+    /**
104
+     * Get normalized rest base.
105
+     *
106
+     * @return string
107
+     */
108
+    protected function get_normalized_rest_base() {
109
+        return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
110
+    }
111
+
112
+    /**
113
+     * Fill batches.
114
+     *
115
+     * @param array array of request items.
116
+     * @return array
117
+     */
118
+    protected function fill_batch_keys( $items ) {
119
+
120
+        $items['create'] = empty( $items['create'] ) ? array() : $items['create'];
121
+        $items['update'] = empty( $items['update'] ) ? array() : $items['update'];
122
+        $items['delete'] = empty( $items['delete'] ) ? array() : wp_parse_id_list( $items['delete'] );
123
+        return $items;
124
+
125
+    }
126
+
127
+    /**
128
+     * Check batch limit.
129
+     *
130
+     * @param array $items Request items.
131
+     * @return bool|WP_Error
132
+     */
133
+    protected function check_batch_limit( $items ) {
134
+        $limit = apply_filters( 'getpaid_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
135
+        $total = count( $items['create'] ) + count( $items['update'] ) + count( $items['delete'] );
136
+
137
+        if ( $total > $limit ) {
138
+            /* translators: %s: items limit */
139
+            return new WP_Error( 'getpaid_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'invoicing' ), $limit ), array( 'status' => 413 ) );
140
+        }
141
+
142
+        return true;
143
+    }
144
+
145
+    /**
146
+     * Bulk create items.
147
+     *
148
+     * @param array $items Array of items to create.
149
+     * @param WP_REST_Request $request Full details about the request.
150
+     * @param WP_REST_Server $wp_rest_server
151
+     * @return array()
152
+     */
153
+    protected function batch_create_items( $items, $request, $wp_rest_server ) {
154
+
155
+        $query  = $request->get_query_params();
156
+        $create = array();
157
+
158
+        foreach ( $items as $item ) {
159
+            $_item = new WP_REST_Request( 'POST' );
160
+
161
+            // Default parameters.
162
+            $defaults = array();
163
+            $schema   = $this->get_public_item_schema();
164
+            foreach ( $schema['properties'] as $arg => $options ) {
165
+                if ( isset( $options['default'] ) ) {
166
+                    $defaults[ $arg ] = $options['default'];
167
+                }
168
+            }
169
+            $_item->set_default_params( $defaults );
170
+
171
+            // Set request parameters.
172
+            $_item->set_body_params( $item );
173
+
174
+            // Set query (GET) parameters.
175
+            $_item->set_query_params( $query );
176
+
177
+            // Create the item.
178
+            $_response = $this->create_item( $_item );
179
+
180
+            // If an error occured...
181
+            if ( is_wp_error( $_response ) ) {
182
+
183
+                $create[]   = array(
184
+                    'id'    => 0,
185
+                    'error' => array(
186
+                        'code'    => $_response->get_error_code(),
187
+                        'message' => $_response->get_error_message(),
188
+                        'data'    => $_response->get_error_data(),
189
+                    ),
190
+                );
191
+
192
+                continue;
193
+            }
194
+
195
+            $create[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
196
+
197
+        }
198
+
199
+        return $create;
200
+
201
+    }
202
+
203
+    /**
204
+     * Bulk update items.
205
+     *
206
+     * @param array $items Array of items to update.
207
+     * @param WP_REST_Request $request Full details about the request.
208
+     * @param WP_REST_Server $wp_rest_server
209
+     * @return array()
210
+     */
211
+    protected function batch_update_items( $items, $request, $wp_rest_server ) {
212
+
213
+        $query  = $request->get_query_params();
214
+        $update = array();
215
+
216
+        foreach ( $items as $item ) {
217
+
218
+            // Create a dummy request.
219
+            $_item = new WP_REST_Request( 'PUT' );
220
+
221
+            // Add body params.
222
+            $_item->set_body_params( $item );
223
+
224
+            // Set query (GET) parameters.
225
+            $_item->set_query_params( $query );
226
+
227
+            // Update the item.
228
+            $_response = $this->update_item( $_item );
229
+
230
+            // If an error occured...
231
+            if ( is_wp_error( $_response ) ) {
232
+
233
+                $update[] = array(
234
+                    'id'    => $item['id'],
235
+                    'error' => array(
236
+                        'code'    => $_response->get_error_code(),
237
+                        'message' => $_response->get_error_message(),
238
+                        'data'    => $_response->get_error_data(),
239
+                    ),
240
+                );
241
+
242
+                continue;
243
+
244
+            }
245
+
246
+            $update[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
247
+
248
+        }
249
+
250
+        return $update;
251
+
252
+    }
253
+
254
+    /**
255
+     * Bulk delete items.
256
+     *
257
+     * @param array $items Array of items to delete.
258
+     * @param WP_REST_Server $wp_rest_server
259
+     * @return array()
260
+     */
261
+    protected function batch_delete_items( $items, $wp_rest_server ) {
262
+
263
+        $delete = array();
264
+
265
+        foreach ( array_filter( $items ) as $id ) {
266
+
267
+            // Prepare the request.
268
+            $_item = new WP_REST_Request( 'DELETE' );
269
+            $_item->set_query_params(
270
+                array(
271
+                    'id'    => $id,
272
+                    'force' => true,
273
+                )
274
+            );
275
+
276
+            // Delete the item.
277
+            $_response = $this->delete_item( $_item );
278
+
279
+            if ( is_wp_error( $_response ) ) {
280
+
281
+                $delete[] = array(
282
+                    'id'    => $id,
283
+                    'error' => array(
284
+                        'code'    => $_response->get_error_code(),
285
+                        'message' => $_response->get_error_message(),
286
+                        'data'    => $_response->get_error_data(),
287
+                    ),
288
+                );
289
+
290
+                continue;
291
+            }
200 292
 
201
-	}
202
-
203
-	/**
204
-	 * Bulk update items.
205
-	 *
206
-	 * @param array $items Array of items to update.
207
-	 * @param WP_REST_Request $request Full details about the request.
208
-	 * @param WP_REST_Server $wp_rest_server
209
-	 * @return array()
210
-	 */
211
-	protected function batch_update_items( $items, $request, $wp_rest_server ) {
212
-
213
-		$query  = $request->get_query_params();
214
-		$update = array();
215
-
216
-		foreach ( $items as $item ) {
217
-
218
-			// Create a dummy request.
219
-			$_item = new WP_REST_Request( 'PUT' );
220
-
221
-			// Add body params.
222
-			$_item->set_body_params( $item );
223
-
224
-			// Set query (GET) parameters.
225
-			$_item->set_query_params( $query );
226
-
227
-			// Update the item.
228
-			$_response = $this->update_item( $_item );
229
-
230
-			// If an error occured...
231
-			if ( is_wp_error( $_response ) ) {
232
-
233
-				$update[] = array(
234
-					'id'    => $item['id'],
235
-					'error' => array(
236
-						'code'    => $_response->get_error_code(),
237
-						'message' => $_response->get_error_message(),
238
-						'data'    => $_response->get_error_data(),
239
-					),
240
-				);
241
-
242
-				continue;
243
-
244
-			}
245
-
246
-			$update[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
247
-
248
-		}
249
-
250
-		return $update;
251
-
252
-	}
293
+            $delete[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
253 294
 
254
-	/**
255
-	 * Bulk delete items.
256
-	 *
257
-	 * @param array $items Array of items to delete.
258
-	 * @param WP_REST_Server $wp_rest_server
259
-	 * @return array()
260
-	 */
261
-	protected function batch_delete_items( $items, $wp_rest_server ) {
262
-
263
-		$delete = array();
264
-
265
-		foreach ( array_filter( $items ) as $id ) {
266
-
267
-			// Prepare the request.
268
-			$_item = new WP_REST_Request( 'DELETE' );
269
-			$_item->set_query_params(
270
-				array(
271
-					'id'    => $id,
272
-					'force' => true,
273
-				)
274
-			);
275
-
276
-			// Delete the item.
277
-			$_response = $this->delete_item( $_item );
278
-
279
-			if ( is_wp_error( $_response ) ) {
280
-
281
-				$delete[] = array(
282
-					'id'    => $id,
283
-					'error' => array(
284
-						'code'    => $_response->get_error_code(),
285
-						'message' => $_response->get_error_message(),
286
-						'data'    => $_response->get_error_data(),
287
-					),
288
-				);
289
-
290
-				continue;
291
-			}
292
-
293
-			$delete[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
294
-
295
-		}
296
-
297
-		return $delete;
298
-
299
-	}
300
-
301
-	/**
302
-	 * Bulk create, update and delete items.
303
-	 *
304
-	 * @param WP_REST_Request $request Full details about the request.
305
-	 * @return WP_Error|array.
306
-	 */
307
-	public function batch_items( $request ) {
308
-		global $wp_rest_server;
309
-
310
-		// Prepare the batch items.
311
-		$items = $this->fill_batch_keys( array_filter( $request->get_params() ) );
312
-
313
-		// Ensure that the batch has not exceeded the limit to prevent abuse.
314
-		$limit = $this->check_batch_limit( $items );
315
-		if ( is_wp_error( $limit ) ) {
316
-			return $limit;
317
-		}
318
-
319
-		// Process the items.
320
-		return array(
321
-			'create' => $this->batch_create_items( $items['create'], $request, $wp_rest_server ),
322
-			'update' => $this->batch_update_items( $items['update'], $request, $wp_rest_server ),
323
-			'delete' => $this->batch_delete_items( $items['delete'], $wp_rest_server ),
324
-		);
325
-
326
-	}
327
-
328
-	/**
329
-	 * Add meta query.
330
-	 *
331
-	 * @since 1.0.19
332
-	 * @param array $args       Query args.
333
-	 * @param array $meta_query Meta query.
334
-	 * @return array
335
-	 */
336
-	protected function add_meta_query( $args, $meta_query ) {
337
-		if ( empty( $args['meta_query'] ) ) {
338
-			$args['meta_query'] = array();
339
-		}
340
-
341
-		$args['meta_query'][] = $meta_query;
342
-
343
-		return $args['meta_query'];
344
-	}
345
-
346
-	/**
347
-	 * Get the batch schema, conforming to JSON Schema.
348
-	 *
349
-	 * @return array
350
-	 */
351
-	public function get_public_batch_schema() {
352
-
353
-		return array(
354
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
355
-			'title'      => 'batch',
356
-			'type'       => 'object',
357
-			'properties' => array(
358
-				'create' => array(
359
-					'description' => __( 'List of created resources.', 'invoicing' ),
360
-					'type'        => 'array',
361
-					'context'     => array( 'view', 'edit' ),
362
-					'items'       => array(
363
-						'type' => 'object',
364
-					),
365
-				),
366
-				'update' => array(
367
-					'description' => __( 'List of updated resources.', 'invoicing' ),
368
-					'type'        => 'array',
369
-					'context'     => array( 'view', 'edit' ),
370
-					'items'       => array(
371
-						'type' => 'object',
372
-					),
373
-				),
374
-				'delete' => array(
375
-					'description' => __( 'List of deleted resources.', 'invoicing' ),
376
-					'type'        => 'array',
377
-					'context'     => array( 'view', 'edit' ),
378
-					'items'       => array(
379
-						'type' => 'integer',
380
-					),
381
-				),
382
-			),
383
-		);
384
-
385
-	}
386
-
387
-	/**
388
-	 * Returns the value of schema['properties']
389
-	 *
390
-	 * i.e Schema fields.
391
-	 *
392
-	 * @since 1.0.19
393
-	 * @return array
394
-	 */
395
-	protected function get_schema_properties() {
396
-
397
-		$schema     = $this->get_item_schema();
398
-		$properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
399
-
400
-		// For back-compat, include any field with an empty schema
401
-		// because it won't be present in $this->get_item_schema().
402
-		foreach ( $this->get_additional_fields() as $field_name => $field_options ) {
403
-			if ( is_null( $field_options['schema'] ) ) {
404
-				$properties[ $field_name ] = $field_options;
405
-			}
406
-		}
407
-
408
-		return $properties;
409
-	}
410
-
411
-	/**
412
-	 * Filters fields by context.
413
-	 *
414
-	 * @param array $fields Array of fields
415
-	 * @param string|null context view, edit or embed
416
-	 * @since 1.0.19
417
-	 * @return array
418
-	 */
419
-	protected function filter_response_fields_by_context( $fields, $context ) {
420
-
421
-		if ( empty( $context ) ) {
422
-			return $fields;
423
-		}
424
-
425
-		foreach ( $fields as $name => $options ) {
426
-			if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
427
-				unset( $fields[ $name ] );
428
-			}
429
-		}
430
-
431
-		return $fields;
432
-
433
-	}
434
-
435
-	/**
436
-	 * Filters fields by an array of requested fields.
437
-	 *
438
-	 * @param array $fields Array of available fields
439
-	 * @param array $requested array of requested fields.
440
-	 * @since 1.0.19
441
-	 * @return array
442
-	 */
443
-	protected function filter_response_fields_by_array( $fields, $requested ) {
444
-
445
-		// Trim off any whitespace from the list array.
446
-		$requested = array_map( 'trim', $requested );
447
-
448
-		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
449
-		if ( in_array( 'id', $fields, true ) ) {
450
-			$requested[] = 'id';
451
-		}
452
-
453
-		// Get rid of duplicate fields.
454
-		$requested = array_unique( $requested );
455
-
456
-		// Return the list of all included fields which are available.
457
-		return array_reduce(
458
-			$requested,
459
-			function( $response_fields, $field ) use ( $fields ) {
460
-
461
-				if ( in_array( $field, $fields, true ) ) {
462
-					$response_fields[] = $field;
463
-					return $response_fields;
464
-				}
465
-
466
-				// Check for nested fields if $field is not a direct match.
467
-				$nested_fields = explode( '.', $field );
468
-
469
-				// A nested field is included so long as its top-level property is
470
-				// present in the schema.
471
-				if ( in_array( $nested_fields[0], $fields, true ) ) {
472
-					$response_fields[] = $field;
473
-				}
474
-
475
-				return $response_fields;
476
-			},
477
-			array()
478
-		);
479
-
480
-	}
481
-
482
-	/**
483
-	 * Gets an array of fields to be included on the response.
484
-	 *
485
-	 * Included fields are based on item schema and `_fields=` request argument.
486
-	 * Copied from WordPress 5.3 to support old versions.
487
-	 *
488
-	 * @since 1.0.19
489
-	 * @param WP_REST_Request $request Full details about the request.
490
-	 * @return array Fields to be included in the response.
491
-	 */
492
-	public function get_fields_for_response( $request ) {
493
-
494
-		// Retrieve fields in the schema.
495
-		$properties = $this->get_schema_properties();
496
-
497
-		// Exclude fields that specify a different context than the request context.
498
-		$properties = $this->filter_response_fields_by_context( $properties, $request['context'] );
499
-
500
-		// We only need the field keys.
501
-		$fields = array_keys( $properties );
502
-
503
-		// Is the user filtering the response fields??
504
-		if ( empty( $request['_fields'] ) ) {
505
-			return $fields;
506
-		}
507
-
508
-		return $this->filter_response_fields_by_array( $fields, wpinv_parse_list( $request['_fields'] ) );
509
-
510
-	}
511
-
512
-	/**
513
-	 * Limits an object to the requested fields.
514
-	 *
515
-	 * Included fields are based on the `_fields` request argument.
516
-	 *
517
-	 * @since 1.0.19
518
-	 * @param array $data Fields to include in the response.
519
-	 * @param array $fields Requested fields.
520
-	 * @return array Fields to be included in the response.
521
-	 */
522
-	public function limit_object_to_requested_fields( $data, $fields, $prefix = '' ) {
523
-
524
-		// Is the user filtering the response fields??
525
-		if ( empty( $fields ) ) {
526
-			return $data;
527
-		}
528
-
529
-		foreach ( $data as $key => $value ) {
530
-
531
-			// Numeric arrays.
532
-			if ( is_numeric( $key ) && is_array( $value ) ) {
533
-				$data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $prefix );
534
-				continue;
535
-			}
536
-
537
-			// Generate a new prefix.
538
-			$new_prefix = empty( $prefix ) ? $key : "$prefix.$key";
539
-
540
-			// Check if it was requested.
541
-			if ( ! empty( $key ) && ! $this->is_field_included( $new_prefix, $fields ) ) {
542
-				unset( $data[ $key ] );
543
-				continue;
544
-			}
545
-
546
-			if ( $key != 'meta_data' && is_array( $value ) ) {
547
-				$data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $new_prefix );
548
-			}
295
+        }
296
+
297
+        return $delete;
298
+
299
+    }
300
+
301
+    /**
302
+     * Bulk create, update and delete items.
303
+     *
304
+     * @param WP_REST_Request $request Full details about the request.
305
+     * @return WP_Error|array.
306
+     */
307
+    public function batch_items( $request ) {
308
+        global $wp_rest_server;
309
+
310
+        // Prepare the batch items.
311
+        $items = $this->fill_batch_keys( array_filter( $request->get_params() ) );
312
+
313
+        // Ensure that the batch has not exceeded the limit to prevent abuse.
314
+        $limit = $this->check_batch_limit( $items );
315
+        if ( is_wp_error( $limit ) ) {
316
+            return $limit;
317
+        }
318
+
319
+        // Process the items.
320
+        return array(
321
+            'create' => $this->batch_create_items( $items['create'], $request, $wp_rest_server ),
322
+            'update' => $this->batch_update_items( $items['update'], $request, $wp_rest_server ),
323
+            'delete' => $this->batch_delete_items( $items['delete'], $wp_rest_server ),
324
+        );
325
+
326
+    }
327
+
328
+    /**
329
+     * Add meta query.
330
+     *
331
+     * @since 1.0.19
332
+     * @param array $args       Query args.
333
+     * @param array $meta_query Meta query.
334
+     * @return array
335
+     */
336
+    protected function add_meta_query( $args, $meta_query ) {
337
+        if ( empty( $args['meta_query'] ) ) {
338
+            $args['meta_query'] = array();
339
+        }
340
+
341
+        $args['meta_query'][] = $meta_query;
342
+
343
+        return $args['meta_query'];
344
+    }
345
+
346
+    /**
347
+     * Get the batch schema, conforming to JSON Schema.
348
+     *
349
+     * @return array
350
+     */
351
+    public function get_public_batch_schema() {
352
+
353
+        return array(
354
+            '$schema'    => 'http://json-schema.org/draft-04/schema#',
355
+            'title'      => 'batch',
356
+            'type'       => 'object',
357
+            'properties' => array(
358
+                'create' => array(
359
+                    'description' => __( 'List of created resources.', 'invoicing' ),
360
+                    'type'        => 'array',
361
+                    'context'     => array( 'view', 'edit' ),
362
+                    'items'       => array(
363
+                        'type' => 'object',
364
+                    ),
365
+                ),
366
+                'update' => array(
367
+                    'description' => __( 'List of updated resources.', 'invoicing' ),
368
+                    'type'        => 'array',
369
+                    'context'     => array( 'view', 'edit' ),
370
+                    'items'       => array(
371
+                        'type' => 'object',
372
+                    ),
373
+                ),
374
+                'delete' => array(
375
+                    'description' => __( 'List of deleted resources.', 'invoicing' ),
376
+                    'type'        => 'array',
377
+                    'context'     => array( 'view', 'edit' ),
378
+                    'items'       => array(
379
+                        'type' => 'integer',
380
+                    ),
381
+                ),
382
+            ),
383
+        );
384
+
385
+    }
386
+
387
+    /**
388
+     * Returns the value of schema['properties']
389
+     *
390
+     * i.e Schema fields.
391
+     *
392
+     * @since 1.0.19
393
+     * @return array
394
+     */
395
+    protected function get_schema_properties() {
396
+
397
+        $schema     = $this->get_item_schema();
398
+        $properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
399
+
400
+        // For back-compat, include any field with an empty schema
401
+        // because it won't be present in $this->get_item_schema().
402
+        foreach ( $this->get_additional_fields() as $field_name => $field_options ) {
403
+            if ( is_null( $field_options['schema'] ) ) {
404
+                $properties[ $field_name ] = $field_options;
405
+            }
406
+        }
407
+
408
+        return $properties;
409
+    }
410
+
411
+    /**
412
+     * Filters fields by context.
413
+     *
414
+     * @param array $fields Array of fields
415
+     * @param string|null context view, edit or embed
416
+     * @since 1.0.19
417
+     * @return array
418
+     */
419
+    protected function filter_response_fields_by_context( $fields, $context ) {
420
+
421
+        if ( empty( $context ) ) {
422
+            return $fields;
423
+        }
424
+
425
+        foreach ( $fields as $name => $options ) {
426
+            if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
427
+                unset( $fields[ $name ] );
428
+            }
429
+        }
430
+
431
+        return $fields;
432
+
433
+    }
434
+
435
+    /**
436
+     * Filters fields by an array of requested fields.
437
+     *
438
+     * @param array $fields Array of available fields
439
+     * @param array $requested array of requested fields.
440
+     * @since 1.0.19
441
+     * @return array
442
+     */
443
+    protected function filter_response_fields_by_array( $fields, $requested ) {
444
+
445
+        // Trim off any whitespace from the list array.
446
+        $requested = array_map( 'trim', $requested );
447
+
448
+        // Always persist 'id', because it can be needed for add_additional_fields_to_object().
449
+        if ( in_array( 'id', $fields, true ) ) {
450
+            $requested[] = 'id';
451
+        }
452
+
453
+        // Get rid of duplicate fields.
454
+        $requested = array_unique( $requested );
455
+
456
+        // Return the list of all included fields which are available.
457
+        return array_reduce(
458
+            $requested,
459
+            function( $response_fields, $field ) use ( $fields ) {
460
+
461
+                if ( in_array( $field, $fields, true ) ) {
462
+                    $response_fields[] = $field;
463
+                    return $response_fields;
464
+                }
465
+
466
+                // Check for nested fields if $field is not a direct match.
467
+                $nested_fields = explode( '.', $field );
468
+
469
+                // A nested field is included so long as its top-level property is
470
+                // present in the schema.
471
+                if ( in_array( $nested_fields[0], $fields, true ) ) {
472
+                    $response_fields[] = $field;
473
+                }
474
+
475
+                return $response_fields;
476
+            },
477
+            array()
478
+        );
479
+
480
+    }
481
+
482
+    /**
483
+     * Gets an array of fields to be included on the response.
484
+     *
485
+     * Included fields are based on item schema and `_fields=` request argument.
486
+     * Copied from WordPress 5.3 to support old versions.
487
+     *
488
+     * @since 1.0.19
489
+     * @param WP_REST_Request $request Full details about the request.
490
+     * @return array Fields to be included in the response.
491
+     */
492
+    public function get_fields_for_response( $request ) {
493
+
494
+        // Retrieve fields in the schema.
495
+        $properties = $this->get_schema_properties();
496
+
497
+        // Exclude fields that specify a different context than the request context.
498
+        $properties = $this->filter_response_fields_by_context( $properties, $request['context'] );
499
+
500
+        // We only need the field keys.
501
+        $fields = array_keys( $properties );
502
+
503
+        // Is the user filtering the response fields??
504
+        if ( empty( $request['_fields'] ) ) {
505
+            return $fields;
506
+        }
507
+
508
+        return $this->filter_response_fields_by_array( $fields, wpinv_parse_list( $request['_fields'] ) );
509
+
510
+    }
511
+
512
+    /**
513
+     * Limits an object to the requested fields.
514
+     *
515
+     * Included fields are based on the `_fields` request argument.
516
+     *
517
+     * @since 1.0.19
518
+     * @param array $data Fields to include in the response.
519
+     * @param array $fields Requested fields.
520
+     * @return array Fields to be included in the response.
521
+     */
522
+    public function limit_object_to_requested_fields( $data, $fields, $prefix = '' ) {
523
+
524
+        // Is the user filtering the response fields??
525
+        if ( empty( $fields ) ) {
526
+            return $data;
527
+        }
528
+
529
+        foreach ( $data as $key => $value ) {
530
+
531
+            // Numeric arrays.
532
+            if ( is_numeric( $key ) && is_array( $value ) ) {
533
+                $data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $prefix );
534
+                continue;
535
+            }
536
+
537
+            // Generate a new prefix.
538
+            $new_prefix = empty( $prefix ) ? $key : "$prefix.$key";
539
+
540
+            // Check if it was requested.
541
+            if ( ! empty( $key ) && ! $this->is_field_included( $new_prefix, $fields ) ) {
542
+                unset( $data[ $key ] );
543
+                continue;
544
+            }
545
+
546
+            if ( $key != 'meta_data' && is_array( $value ) ) {
547
+                $data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $new_prefix );
548
+            }
549 549
 }
550 550
 
551
-		return $data;
552
-	}
553
-
554
-	/**
555
-	 * Given an array of fields to include in a response, some of which may be
556
-	 * `nested.fields`, determine whether the provided field should be included
557
-	 * in the response body.
558
-	 *
559
-	 * Copied from WordPress 5.3 to support old versions.
560
-	 *
561
-	 * @since 1.0.19
562
-	 *
563
-	 * @param string $field  A field to test for inclusion in the response body.
564
-	 * @param array  $fields An array of string fields supported by the endpoint.
565
-	 * @return bool Whether to include the field or not.
566
-	 * @see rest_is_field_included()
567
-	 */
568
-	public function is_field_included( $field, $fields ) {
569
-		if ( in_array( $field, $fields, true ) ) {
570
-			return true;
571
-		}
572
-
573
-		foreach ( $fields as $accepted_field ) {
574
-			// Check to see if $field is the parent of any item in $fields.
575
-			// A field "parent" should be accepted if "parent.child" is accepted.
576
-			if ( strpos( $accepted_field, "$field." ) === 0 ) {
577
-				return true;
578
-			}
579
-			// Conversely, if "parent" is accepted, all "parent.child" fields
580
-			// should also be accepted.
581
-			if ( strpos( $field, "$accepted_field." ) === 0 ) {
582
-				return true;
583
-			}
584
-		}
585
-
586
-		return false;
587
-	}
551
+        return $data;
552
+    }
553
+
554
+    /**
555
+     * Given an array of fields to include in a response, some of which may be
556
+     * `nested.fields`, determine whether the provided field should be included
557
+     * in the response body.
558
+     *
559
+     * Copied from WordPress 5.3 to support old versions.
560
+     *
561
+     * @since 1.0.19
562
+     *
563
+     * @param string $field  A field to test for inclusion in the response body.
564
+     * @param array  $fields An array of string fields supported by the endpoint.
565
+     * @return bool Whether to include the field or not.
566
+     * @see rest_is_field_included()
567
+     */
568
+    public function is_field_included( $field, $fields ) {
569
+        if ( in_array( $field, $fields, true ) ) {
570
+            return true;
571
+        }
572
+
573
+        foreach ( $fields as $accepted_field ) {
574
+            // Check to see if $field is the parent of any item in $fields.
575
+            // A field "parent" should be accepted if "parent.child" is accepted.
576
+            if ( strpos( $accepted_field, "$field." ) === 0 ) {
577
+                return true;
578
+            }
579
+            // Conversely, if "parent" is accepted, all "parent.child" fields
580
+            // should also be accepted.
581
+            if ( strpos( $field, "$accepted_field." ) === 0 ) {
582
+                return true;
583
+            }
584
+        }
585
+
586
+        return false;
587
+    }
588 588
 
589 589
 }
Please login to merge, or discard this patch.
Spacing   +95 added lines, -95 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
 /**
14 14
  * Core class to access posts via the REST API.
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		);
65 65
 
66 66
 		// Register REST routes.
67
-        add_action( 'rest_api_init', array( $this, 'register_routes' ) );
67
+        add_action('rest_api_init', array($this, 'register_routes'));
68 68
 
69 69
 	}
70 70
 
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public function register_routes() {
78 78
 
79
-		foreach ( $this->namespaces as $namespace ) {
80
-			$this->register_namespace_routes( $namespace );
79
+		foreach ($this->namespaces as $namespace) {
80
+			$this->register_namespace_routes($namespace);
81 81
 		}
82 82
 
83 83
 	}
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @param string $namespace
91 91
 	 */
92
-	public function register_namespace_routes( /** @scrutinizer ignore-unused */ $namespace ) {
92
+	public function register_namespace_routes(/** @scrutinizer ignore-unused */ $namespace) {
93 93
 
94 94
 		getpaid_doing_it_wrong(
95 95
 			__CLASS__ . '::' . __METHOD__,
96 96
 			/* translators: %s: register_namespace_routes() */
97
-			sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ),
97
+			sprintf(__("Method '%s' must be overridden."), __METHOD__),
98 98
 			'1.0.19'
99 99
 		);
100 100
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return string
107 107
 	 */
108 108
 	protected function get_normalized_rest_base() {
109
-		return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
109
+		return preg_replace('/\(.*\)\//i', '', $this->rest_base);
110 110
 	}
111 111
 
112 112
 	/**
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 	 * @param array array of request items.
116 116
 	 * @return array
117 117
 	 */
118
-	protected function fill_batch_keys( $items ) {
118
+	protected function fill_batch_keys($items) {
119 119
 
120
-		$items['create'] = empty( $items['create'] ) ? array() : $items['create'];
121
-		$items['update'] = empty( $items['update'] ) ? array() : $items['update'];
122
-		$items['delete'] = empty( $items['delete'] ) ? array() : wp_parse_id_list( $items['delete'] );
120
+		$items['create'] = empty($items['create']) ? array() : $items['create'];
121
+		$items['update'] = empty($items['update']) ? array() : $items['update'];
122
+		$items['delete'] = empty($items['delete']) ? array() : wp_parse_id_list($items['delete']);
123 123
 		return $items;
124 124
 
125 125
 	}
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
 	 * @param array $items Request items.
131 131
 	 * @return bool|WP_Error
132 132
 	 */
133
-	protected function check_batch_limit( $items ) {
134
-		$limit = apply_filters( 'getpaid_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
135
-		$total = count( $items['create'] ) + count( $items['update'] ) + count( $items['delete'] );
133
+	protected function check_batch_limit($items) {
134
+		$limit = apply_filters('getpaid_rest_batch_items_limit', 100, $this->get_normalized_rest_base());
135
+		$total = count($items['create']) + count($items['update']) + count($items['delete']);
136 136
 
137
-		if ( $total > $limit ) {
137
+		if ($total > $limit) {
138 138
 			/* translators: %s: items limit */
139
-			return new WP_Error( 'getpaid_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'invoicing' ), $limit ), array( 'status' => 413 ) );
139
+			return new WP_Error('getpaid_rest_request_entity_too_large', sprintf(__('Unable to accept more than %s items for this request.', 'invoicing'), $limit), array('status' => 413));
140 140
 		}
141 141
 
142 142
 		return true;
@@ -150,37 +150,37 @@  discard block
 block discarded – undo
150 150
 	 * @param WP_REST_Server $wp_rest_server
151 151
 	 * @return array()
152 152
 	 */
153
-	protected function batch_create_items( $items, $request, $wp_rest_server ) {
153
+	protected function batch_create_items($items, $request, $wp_rest_server) {
154 154
 
155 155
 		$query  = $request->get_query_params();
156 156
 		$create = array();
157 157
 
158
-		foreach ( $items as $item ) {
159
-			$_item = new WP_REST_Request( 'POST' );
158
+		foreach ($items as $item) {
159
+			$_item = new WP_REST_Request('POST');
160 160
 
161 161
 			// Default parameters.
162 162
 			$defaults = array();
163 163
 			$schema   = $this->get_public_item_schema();
164
-			foreach ( $schema['properties'] as $arg => $options ) {
165
-				if ( isset( $options['default'] ) ) {
166
-					$defaults[ $arg ] = $options['default'];
164
+			foreach ($schema['properties'] as $arg => $options) {
165
+				if (isset($options['default'])) {
166
+					$defaults[$arg] = $options['default'];
167 167
 				}
168 168
 			}
169
-			$_item->set_default_params( $defaults );
169
+			$_item->set_default_params($defaults);
170 170
 
171 171
 			// Set request parameters.
172
-			$_item->set_body_params( $item );
172
+			$_item->set_body_params($item);
173 173
 
174 174
 			// Set query (GET) parameters.
175
-			$_item->set_query_params( $query );
175
+			$_item->set_query_params($query);
176 176
 
177 177
 			// Create the item.
178
-			$_response = $this->create_item( $_item );
178
+			$_response = $this->create_item($_item);
179 179
 
180 180
 			// If an error occured...
181
-			if ( is_wp_error( $_response ) ) {
181
+			if (is_wp_error($_response)) {
182 182
 
183
-				$create[]   = array(
183
+				$create[] = array(
184 184
 					'id'    => 0,
185 185
 					'error' => array(
186 186
 						'code'    => $_response->get_error_code(),
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 				continue;
193 193
 			}
194 194
 
195
-			$create[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
195
+			$create[] = $wp_rest_server->response_to_data(/** @scrutinizer ignore-type */ $_response, false);
196 196
 
197 197
 		}
198 198
 
@@ -208,27 +208,27 @@  discard block
 block discarded – undo
208 208
 	 * @param WP_REST_Server $wp_rest_server
209 209
 	 * @return array()
210 210
 	 */
211
-	protected function batch_update_items( $items, $request, $wp_rest_server ) {
211
+	protected function batch_update_items($items, $request, $wp_rest_server) {
212 212
 
213 213
 		$query  = $request->get_query_params();
214 214
 		$update = array();
215 215
 
216
-		foreach ( $items as $item ) {
216
+		foreach ($items as $item) {
217 217
 
218 218
 			// Create a dummy request.
219
-			$_item = new WP_REST_Request( 'PUT' );
219
+			$_item = new WP_REST_Request('PUT');
220 220
 
221 221
 			// Add body params.
222
-			$_item->set_body_params( $item );
222
+			$_item->set_body_params($item);
223 223
 
224 224
 			// Set query (GET) parameters.
225
-			$_item->set_query_params( $query );
225
+			$_item->set_query_params($query);
226 226
 
227 227
 			// Update the item.
228
-			$_response = $this->update_item( $_item );
228
+			$_response = $this->update_item($_item);
229 229
 
230 230
 			// If an error occured...
231
-			if ( is_wp_error( $_response ) ) {
231
+			if (is_wp_error($_response)) {
232 232
 
233 233
 				$update[] = array(
234 234
 					'id'    => $item['id'],
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 
244 244
 			}
245 245
 
246
-			$update[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
246
+			$update[] = $wp_rest_server->response_to_data(/** @scrutinizer ignore-type */ $_response, false);
247 247
 
248 248
 		}
249 249
 
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
 	 * @param WP_REST_Server $wp_rest_server
259 259
 	 * @return array()
260 260
 	 */
261
-	protected function batch_delete_items( $items, $wp_rest_server ) {
261
+	protected function batch_delete_items($items, $wp_rest_server) {
262 262
 
263 263
 		$delete = array();
264 264
 
265
-		foreach ( array_filter( $items ) as $id ) {
265
+		foreach (array_filter($items) as $id) {
266 266
 
267 267
 			// Prepare the request.
268
-			$_item = new WP_REST_Request( 'DELETE' );
268
+			$_item = new WP_REST_Request('DELETE');
269 269
 			$_item->set_query_params(
270 270
 				array(
271 271
 					'id'    => $id,
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
 			);
275 275
 
276 276
 			// Delete the item.
277
-			$_response = $this->delete_item( $_item );
277
+			$_response = $this->delete_item($_item);
278 278
 
279
-			if ( is_wp_error( $_response ) ) {
279
+			if (is_wp_error($_response)) {
280 280
 
281 281
 				$delete[] = array(
282 282
 					'id'    => $id,
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 				continue;
291 291
 			}
292 292
 
293
-			$delete[] = $wp_rest_server->response_to_data( /** @scrutinizer ignore-type */ $_response, false );
293
+			$delete[] = $wp_rest_server->response_to_data(/** @scrutinizer ignore-type */ $_response, false);
294 294
 
295 295
 		}
296 296
 
@@ -304,23 +304,23 @@  discard block
 block discarded – undo
304 304
 	 * @param WP_REST_Request $request Full details about the request.
305 305
 	 * @return WP_Error|array.
306 306
 	 */
307
-	public function batch_items( $request ) {
307
+	public function batch_items($request) {
308 308
 		global $wp_rest_server;
309 309
 
310 310
 		// Prepare the batch items.
311
-		$items = $this->fill_batch_keys( array_filter( $request->get_params() ) );
311
+		$items = $this->fill_batch_keys(array_filter($request->get_params()));
312 312
 
313 313
 		// Ensure that the batch has not exceeded the limit to prevent abuse.
314
-		$limit = $this->check_batch_limit( $items );
315
-		if ( is_wp_error( $limit ) ) {
314
+		$limit = $this->check_batch_limit($items);
315
+		if (is_wp_error($limit)) {
316 316
 			return $limit;
317 317
 		}
318 318
 
319 319
 		// Process the items.
320 320
 		return array(
321
-			'create' => $this->batch_create_items( $items['create'], $request, $wp_rest_server ),
322
-			'update' => $this->batch_update_items( $items['update'], $request, $wp_rest_server ),
323
-			'delete' => $this->batch_delete_items( $items['delete'], $wp_rest_server ),
321
+			'create' => $this->batch_create_items($items['create'], $request, $wp_rest_server),
322
+			'update' => $this->batch_update_items($items['update'], $request, $wp_rest_server),
323
+			'delete' => $this->batch_delete_items($items['delete'], $wp_rest_server),
324 324
 		);
325 325
 
326 326
 	}
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
 	 * @param array $meta_query Meta query.
334 334
 	 * @return array
335 335
 	 */
336
-	protected function add_meta_query( $args, $meta_query ) {
337
-		if ( empty( $args['meta_query'] ) ) {
336
+	protected function add_meta_query($args, $meta_query) {
337
+		if (empty($args['meta_query'])) {
338 338
 			$args['meta_query'] = array();
339 339
 		}
340 340
 
@@ -356,25 +356,25 @@  discard block
 block discarded – undo
356 356
 			'type'       => 'object',
357 357
 			'properties' => array(
358 358
 				'create' => array(
359
-					'description' => __( 'List of created resources.', 'invoicing' ),
359
+					'description' => __('List of created resources.', 'invoicing'),
360 360
 					'type'        => 'array',
361
-					'context'     => array( 'view', 'edit' ),
361
+					'context'     => array('view', 'edit'),
362 362
 					'items'       => array(
363 363
 						'type' => 'object',
364 364
 					),
365 365
 				),
366 366
 				'update' => array(
367
-					'description' => __( 'List of updated resources.', 'invoicing' ),
367
+					'description' => __('List of updated resources.', 'invoicing'),
368 368
 					'type'        => 'array',
369
-					'context'     => array( 'view', 'edit' ),
369
+					'context'     => array('view', 'edit'),
370 370
 					'items'       => array(
371 371
 						'type' => 'object',
372 372
 					),
373 373
 				),
374 374
 				'delete' => array(
375
-					'description' => __( 'List of deleted resources.', 'invoicing' ),
375
+					'description' => __('List of deleted resources.', 'invoicing'),
376 376
 					'type'        => 'array',
377
-					'context'     => array( 'view', 'edit' ),
377
+					'context'     => array('view', 'edit'),
378 378
 					'items'       => array(
379 379
 						'type' => 'integer',
380 380
 					),
@@ -395,13 +395,13 @@  discard block
 block discarded – undo
395 395
 	protected function get_schema_properties() {
396 396
 
397 397
 		$schema     = $this->get_item_schema();
398
-		$properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
398
+		$properties = isset($schema['properties']) ? $schema['properties'] : array();
399 399
 
400 400
 		// For back-compat, include any field with an empty schema
401 401
 		// because it won't be present in $this->get_item_schema().
402
-		foreach ( $this->get_additional_fields() as $field_name => $field_options ) {
403
-			if ( is_null( $field_options['schema'] ) ) {
404
-				$properties[ $field_name ] = $field_options;
402
+		foreach ($this->get_additional_fields() as $field_name => $field_options) {
403
+			if (is_null($field_options['schema'])) {
404
+				$properties[$field_name] = $field_options;
405 405
 			}
406 406
 		}
407 407
 
@@ -416,15 +416,15 @@  discard block
 block discarded – undo
416 416
 	 * @since 1.0.19
417 417
 	 * @return array
418 418
 	 */
419
-	protected function filter_response_fields_by_context( $fields, $context ) {
419
+	protected function filter_response_fields_by_context($fields, $context) {
420 420
 
421
-		if ( empty( $context ) ) {
421
+		if (empty($context)) {
422 422
 			return $fields;
423 423
 		}
424 424
 
425
-		foreach ( $fields as $name => $options ) {
426
-			if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
427
-				unset( $fields[ $name ] );
425
+		foreach ($fields as $name => $options) {
426
+			if (!empty($options['context']) && !in_array($context, $options['context'], true)) {
427
+				unset($fields[$name]);
428 428
 			}
429 429
 		}
430 430
 
@@ -440,35 +440,35 @@  discard block
 block discarded – undo
440 440
 	 * @since 1.0.19
441 441
 	 * @return array
442 442
 	 */
443
-	protected function filter_response_fields_by_array( $fields, $requested ) {
443
+	protected function filter_response_fields_by_array($fields, $requested) {
444 444
 
445 445
 		// Trim off any whitespace from the list array.
446
-		$requested = array_map( 'trim', $requested );
446
+		$requested = array_map('trim', $requested);
447 447
 
448 448
 		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
449
-		if ( in_array( 'id', $fields, true ) ) {
449
+		if (in_array('id', $fields, true)) {
450 450
 			$requested[] = 'id';
451 451
 		}
452 452
 
453 453
 		// Get rid of duplicate fields.
454
-		$requested = array_unique( $requested );
454
+		$requested = array_unique($requested);
455 455
 
456 456
 		// Return the list of all included fields which are available.
457 457
 		return array_reduce(
458 458
 			$requested,
459
-			function( $response_fields, $field ) use ( $fields ) {
459
+			function($response_fields, $field) use ($fields) {
460 460
 
461
-				if ( in_array( $field, $fields, true ) ) {
461
+				if (in_array($field, $fields, true)) {
462 462
 					$response_fields[] = $field;
463 463
 					return $response_fields;
464 464
 				}
465 465
 
466 466
 				// Check for nested fields if $field is not a direct match.
467
-				$nested_fields = explode( '.', $field );
467
+				$nested_fields = explode('.', $field);
468 468
 
469 469
 				// A nested field is included so long as its top-level property is
470 470
 				// present in the schema.
471
-				if ( in_array( $nested_fields[0], $fields, true ) ) {
471
+				if (in_array($nested_fields[0], $fields, true)) {
472 472
 					$response_fields[] = $field;
473 473
 				}
474 474
 
@@ -489,23 +489,23 @@  discard block
 block discarded – undo
489 489
 	 * @param WP_REST_Request $request Full details about the request.
490 490
 	 * @return array Fields to be included in the response.
491 491
 	 */
492
-	public function get_fields_for_response( $request ) {
492
+	public function get_fields_for_response($request) {
493 493
 
494 494
 		// Retrieve fields in the schema.
495 495
 		$properties = $this->get_schema_properties();
496 496
 
497 497
 		// Exclude fields that specify a different context than the request context.
498
-		$properties = $this->filter_response_fields_by_context( $properties, $request['context'] );
498
+		$properties = $this->filter_response_fields_by_context($properties, $request['context']);
499 499
 
500 500
 		// We only need the field keys.
501
-		$fields = array_keys( $properties );
501
+		$fields = array_keys($properties);
502 502
 
503 503
 		// Is the user filtering the response fields??
504
-		if ( empty( $request['_fields'] ) ) {
504
+		if (empty($request['_fields'])) {
505 505
 			return $fields;
506 506
 		}
507 507
 
508
-		return $this->filter_response_fields_by_array( $fields, wpinv_parse_list( $request['_fields'] ) );
508
+		return $this->filter_response_fields_by_array($fields, wpinv_parse_list($request['_fields']));
509 509
 
510 510
 	}
511 511
 
@@ -519,32 +519,32 @@  discard block
 block discarded – undo
519 519
 	 * @param array $fields Requested fields.
520 520
 	 * @return array Fields to be included in the response.
521 521
 	 */
522
-	public function limit_object_to_requested_fields( $data, $fields, $prefix = '' ) {
522
+	public function limit_object_to_requested_fields($data, $fields, $prefix = '') {
523 523
 
524 524
 		// Is the user filtering the response fields??
525
-		if ( empty( $fields ) ) {
525
+		if (empty($fields)) {
526 526
 			return $data;
527 527
 		}
528 528
 
529
-		foreach ( $data as $key => $value ) {
529
+		foreach ($data as $key => $value) {
530 530
 
531 531
 			// Numeric arrays.
532
-			if ( is_numeric( $key ) && is_array( $value ) ) {
533
-				$data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $prefix );
532
+			if (is_numeric($key) && is_array($value)) {
533
+				$data[$key] = $this->limit_object_to_requested_fields($value, $fields, $prefix);
534 534
 				continue;
535 535
 			}
536 536
 
537 537
 			// Generate a new prefix.
538
-			$new_prefix = empty( $prefix ) ? $key : "$prefix.$key";
538
+			$new_prefix = empty($prefix) ? $key : "$prefix.$key";
539 539
 
540 540
 			// Check if it was requested.
541
-			if ( ! empty( $key ) && ! $this->is_field_included( $new_prefix, $fields ) ) {
542
-				unset( $data[ $key ] );
541
+			if (!empty($key) && !$this->is_field_included($new_prefix, $fields)) {
542
+				unset($data[$key]);
543 543
 				continue;
544 544
 			}
545 545
 
546
-			if ( $key != 'meta_data' && is_array( $value ) ) {
547
-				$data[ $key ] = $this->limit_object_to_requested_fields( $value, $fields, $new_prefix );
546
+			if ($key != 'meta_data' && is_array($value)) {
547
+				$data[$key] = $this->limit_object_to_requested_fields($value, $fields, $new_prefix);
548 548
 			}
549 549
 }
550 550
 
@@ -565,20 +565,20 @@  discard block
 block discarded – undo
565 565
 	 * @return bool Whether to include the field or not.
566 566
 	 * @see rest_is_field_included()
567 567
 	 */
568
-	public function is_field_included( $field, $fields ) {
569
-		if ( in_array( $field, $fields, true ) ) {
568
+	public function is_field_included($field, $fields) {
569
+		if (in_array($field, $fields, true)) {
570 570
 			return true;
571 571
 		}
572 572
 
573
-		foreach ( $fields as $accepted_field ) {
573
+		foreach ($fields as $accepted_field) {
574 574
 			// Check to see if $field is the parent of any item in $fields.
575 575
 			// A field "parent" should be accepted if "parent.child" is accepted.
576
-			if ( strpos( $accepted_field, "$field." ) === 0 ) {
576
+			if (strpos($accepted_field, "$field.") === 0) {
577 577
 				return true;
578 578
 			}
579 579
 			// Conversely, if "parent" is accepted, all "parent.child" fields
580 580
 			// should also be accepted.
581
-			if ( strpos( $field, "$accepted_field." ) === 0 ) {
581
+			if (strpos($field, "$accepted_field.") === 0) {
582 582
 				return true;
583 583
 			}
584 584
 		}
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-settings-controller.php 2 patches
Indentation   +743 added lines, -743 removed lines patch added patch discarded remove patch
@@ -18,756 +18,756 @@
 block discarded – undo
18 18
  */
19 19
 class GetPaid_REST_Settings_Controller extends GetPaid_REST_Controller {
20 20
 
21
-	/**
22
-	 * An array of available settings.
23
-	 *
24
-	 * @var string
25
-	 */
26
-	protected $settings;
27
-
28
-	/**
29
-	 * Route base.
30
-	 *
31
-	 * @var string
32
-	 */
33
-	protected $rest_base = 'settings';
34
-
35
-	/**
36
-	 * Registers the routes for the objects of the controller.
37
-	 *
38
-	 * @since 2.0.0
39
-	 *
40
-	 * @see register_rest_route()
41
-	 */
42
-	public function register_namespace_routes( $namespace ) {
43
-
44
-		// List all registered tabs.
45
-		register_rest_route(
46
-			$namespace,
47
-			$this->rest_base,
48
-			array(
49
-				array(
50
-					'methods'             => WP_REST_Server::READABLE,
51
-					'callback'            => array( $this, 'get_tabs' ),
52
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
53
-				),
54
-				'schema' => '__return_empty_array',
55
-			)
56
-		);
57
-
58
-		// View/Update a single setting.
59
-		register_rest_route(
60
-			$namespace,
61
-			$this->rest_base . '/setting/(?P<id>[\w-]+)',
62
-			array(
63
-				'args'   => array(
64
-					'id' => array(
65
-						'description' => __( 'Unique identifier for the setting.', 'invoicing' ),
66
-						'type'        => 'string',
67
-						'required'    => true,
68
-					),
69
-				),
70
-				array(
71
-					'methods'             => WP_REST_Server::READABLE,
72
-					'callback'            => array( $this, 'get_item' ),
73
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
74
-				),
75
-				array(
76
-					'methods'             => WP_REST_Server::EDITABLE,
77
-					'callback'            => array( $this, 'update_item' ),
78
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
79
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
80
-				),
81
-				'schema' => array( $this, 'get_public_item_schema' ),
82
-			)
83
-		);
84
-
85
-		// List registered sections for a given tab.
86
-		register_rest_route(
87
-			$namespace,
88
-			$this->rest_base . '/(?P<tab>[\w-]+)',
89
-			array(
90
-				'args'   => array(
91
-					'tab' => array(
92
-						'description' => __( 'Unique identifier for the tab whose sections should be retrieved.', 'invoicing' ),
93
-						'type'        => 'string',
94
-						'required'    => true,
95
-						'enum'        => array_keys( wpinv_get_settings_tabs() ),
96
-					),
97
-				),
98
-				array(
99
-					'methods'             => WP_REST_Server::READABLE,
100
-					'callback'            => array( $this, 'get_sections' ),
101
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
102
-				),
103
-				'schema' => '__return_empty_array',
104
-			)
105
-		);
106
-
107
-		// List all registered settings for a given tab.
108
-		register_rest_route(
109
-			$namespace,
110
-			$this->rest_base . '/(?P<tab>[\w-]+)/(?P<section>[\w-]+)',
111
-			array(
112
-				'args'   => array(
113
-					'tab'     => array(
114
-						'description' => __( 'Unique identifier for the tab whose settings should be retrieved.', 'invoicing' ),
115
-						'type'        => 'string',
116
-						'required'    => true,
117
-						'enum'        => array_keys( wpinv_get_settings_tabs() ),
118
-					),
119
-					'section' => array(
120
-						'description' => __( 'The section in the tab whose settings should be retrieved.', 'invoicing' ),
121
-						'type'        => 'string',
122
-						'required'    => true,
123
-					),
124
-				),
125
-				array(
126
-					'methods'             => WP_REST_Server::READABLE,
127
-					'callback'            => array( $this, 'get_items' ),
128
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
129
-				),
130
-				'schema' => array( $this, 'get_public_item_schema' ),
131
-			)
132
-		);
133
-
134
-		register_rest_route(
135
-			$namespace,
136
-			'/' . $this->rest_base . '/batch',
137
-			array(
138
-				'args'   => array(
139
-					'id' => array(
140
-						'description' => __( 'Setting ID.', 'invoicing' ),
141
-						'type'        => 'string',
142
-					),
143
-				),
144
-				array(
145
-					'methods'             => WP_REST_Server::EDITABLE,
146
-					'callback'            => array( $this, 'batch_items' ),
147
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
148
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
149
-				),
150
-				'schema' => array( $this, 'get_public_batch_schema' ),
151
-			)
152
-		);
153
-
154
-	}
155
-
156
-	/**
157
-	 * Return all settings.
158
-	 *
159
-	 * @since  2.0.0
160
-	 * @param  WP_REST_Request $request Request data.
161
-	 * @return WP_Error|WP_REST_Response
162
-	 */
163
-	public function get_items( $request ) {
164
-
165
-		$settings = $this->get_settings();
166
-
167
-		if ( ! isset( $settings[ $request['tab'] ] ) ) {
168
-			return new WP_Error( 'rest_invalid_tab', __( 'Invalid tab.', 'invoicing' ), array( 'status' => 400 ) );
169
-		}
170
-
171
-		if ( ! isset( $settings[ $request['tab'] ][ $request['section'] ] ) ) {
172
-			return new WP_Error( 'rest_invalid_section', __( 'Invalid section.', 'invoicing' ), array( 'status' => 400 ) );
173
-		}
174
-
175
-		$settings = $settings[ $request['tab'] ][ $request['section'] ];
176
-		$prepared = array();
177
-
178
-		foreach ( $settings as $setting ) {
179
-
180
-			$setting      = $this->sanitize_setting( $setting );
181
-			$setting_data = $this->prepare_item_for_response( $setting, $request );
182
-			$setting_data = $this->prepare_response_for_collection( $setting_data );
183
-
184
-			if ( $this->is_setting_type_valid( $setting['type'] ) ) {
185
-				$prepared[]   = $setting_data;
186
-			}
21
+    /**
22
+     * An array of available settings.
23
+     *
24
+     * @var string
25
+     */
26
+    protected $settings;
27
+
28
+    /**
29
+     * Route base.
30
+     *
31
+     * @var string
32
+     */
33
+    protected $rest_base = 'settings';
34
+
35
+    /**
36
+     * Registers the routes for the objects of the controller.
37
+     *
38
+     * @since 2.0.0
39
+     *
40
+     * @see register_rest_route()
41
+     */
42
+    public function register_namespace_routes( $namespace ) {
43
+
44
+        // List all registered tabs.
45
+        register_rest_route(
46
+            $namespace,
47
+            $this->rest_base,
48
+            array(
49
+                array(
50
+                    'methods'             => WP_REST_Server::READABLE,
51
+                    'callback'            => array( $this, 'get_tabs' ),
52
+                    'permission_callback' => array( $this, 'get_items_permissions_check' ),
53
+                ),
54
+                'schema' => '__return_empty_array',
55
+            )
56
+        );
57
+
58
+        // View/Update a single setting.
59
+        register_rest_route(
60
+            $namespace,
61
+            $this->rest_base . '/setting/(?P<id>[\w-]+)',
62
+            array(
63
+                'args'   => array(
64
+                    'id' => array(
65
+                        'description' => __( 'Unique identifier for the setting.', 'invoicing' ),
66
+                        'type'        => 'string',
67
+                        'required'    => true,
68
+                    ),
69
+                ),
70
+                array(
71
+                    'methods'             => WP_REST_Server::READABLE,
72
+                    'callback'            => array( $this, 'get_item' ),
73
+                    'permission_callback' => array( $this, 'get_items_permissions_check' ),
74
+                ),
75
+                array(
76
+                    'methods'             => WP_REST_Server::EDITABLE,
77
+                    'callback'            => array( $this, 'update_item' ),
78
+                    'permission_callback' => array( $this, 'update_items_permissions_check' ),
79
+                    'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
80
+                ),
81
+                'schema' => array( $this, 'get_public_item_schema' ),
82
+            )
83
+        );
84
+
85
+        // List registered sections for a given tab.
86
+        register_rest_route(
87
+            $namespace,
88
+            $this->rest_base . '/(?P<tab>[\w-]+)',
89
+            array(
90
+                'args'   => array(
91
+                    'tab' => array(
92
+                        'description' => __( 'Unique identifier for the tab whose sections should be retrieved.', 'invoicing' ),
93
+                        'type'        => 'string',
94
+                        'required'    => true,
95
+                        'enum'        => array_keys( wpinv_get_settings_tabs() ),
96
+                    ),
97
+                ),
98
+                array(
99
+                    'methods'             => WP_REST_Server::READABLE,
100
+                    'callback'            => array( $this, 'get_sections' ),
101
+                    'permission_callback' => array( $this, 'get_items_permissions_check' ),
102
+                ),
103
+                'schema' => '__return_empty_array',
104
+            )
105
+        );
106
+
107
+        // List all registered settings for a given tab.
108
+        register_rest_route(
109
+            $namespace,
110
+            $this->rest_base . '/(?P<tab>[\w-]+)/(?P<section>[\w-]+)',
111
+            array(
112
+                'args'   => array(
113
+                    'tab'     => array(
114
+                        'description' => __( 'Unique identifier for the tab whose settings should be retrieved.', 'invoicing' ),
115
+                        'type'        => 'string',
116
+                        'required'    => true,
117
+                        'enum'        => array_keys( wpinv_get_settings_tabs() ),
118
+                    ),
119
+                    'section' => array(
120
+                        'description' => __( 'The section in the tab whose settings should be retrieved.', 'invoicing' ),
121
+                        'type'        => 'string',
122
+                        'required'    => true,
123
+                    ),
124
+                ),
125
+                array(
126
+                    'methods'             => WP_REST_Server::READABLE,
127
+                    'callback'            => array( $this, 'get_items' ),
128
+                    'permission_callback' => array( $this, 'get_items_permissions_check' ),
129
+                ),
130
+                'schema' => array( $this, 'get_public_item_schema' ),
131
+            )
132
+        );
133
+
134
+        register_rest_route(
135
+            $namespace,
136
+            '/' . $this->rest_base . '/batch',
137
+            array(
138
+                'args'   => array(
139
+                    'id' => array(
140
+                        'description' => __( 'Setting ID.', 'invoicing' ),
141
+                        'type'        => 'string',
142
+                    ),
143
+                ),
144
+                array(
145
+                    'methods'             => WP_REST_Server::EDITABLE,
146
+                    'callback'            => array( $this, 'batch_items' ),
147
+                    'permission_callback' => array( $this, 'batch_items_permissions_check' ),
148
+                    'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
149
+                ),
150
+                'schema' => array( $this, 'get_public_batch_schema' ),
151
+            )
152
+        );
153
+
154
+    }
155
+
156
+    /**
157
+     * Return all settings.
158
+     *
159
+     * @since  2.0.0
160
+     * @param  WP_REST_Request $request Request data.
161
+     * @return WP_Error|WP_REST_Response
162
+     */
163
+    public function get_items( $request ) {
164
+
165
+        $settings = $this->get_settings();
166
+
167
+        if ( ! isset( $settings[ $request['tab'] ] ) ) {
168
+            return new WP_Error( 'rest_invalid_tab', __( 'Invalid tab.', 'invoicing' ), array( 'status' => 400 ) );
169
+        }
170
+
171
+        if ( ! isset( $settings[ $request['tab'] ][ $request['section'] ] ) ) {
172
+            return new WP_Error( 'rest_invalid_section', __( 'Invalid section.', 'invoicing' ), array( 'status' => 400 ) );
173
+        }
174
+
175
+        $settings = $settings[ $request['tab'] ][ $request['section'] ];
176
+        $prepared = array();
177
+
178
+        foreach ( $settings as $setting ) {
179
+
180
+            $setting      = $this->sanitize_setting( $setting );
181
+            $setting_data = $this->prepare_item_for_response( $setting, $request );
182
+            $setting_data = $this->prepare_response_for_collection( $setting_data );
183
+
184
+            if ( $this->is_setting_type_valid( $setting['type'] ) ) {
185
+                $prepared[]   = $setting_data;
186
+            }
187 187
 }
188 188
 
189
-		return rest_ensure_response( $prepared );
190
-	}
191
-
192
-	/**
193
-	 * Return a single setting.
194
-	 *
195
-	 * @since  2.0.0
196
-	 * @param  WP_REST_Request $request Request data.
197
-	 * @return WP_Error|WP_REST_Response
198
-	 */
199
-	public function get_item( $request ) {
200
-		$setting  = $this->get_setting( $request['id'] );
201
-
202
-		if ( is_wp_error( $setting ) ) {
203
-			return $setting;
204
-		}
205
-
206
-		$setting  = $this->sanitize_setting( $setting );
207
-		$response = $this->prepare_item_for_response( $setting, $request );
208
-		return rest_ensure_response( $response );
209
-	}
210
-
211
-	/**
212
-	 * Update a single setting.
213
-	 *
214
-	 * @since  2.0.0
215
-	 * @param  WP_REST_Request $request Request data.
216
-	 * @return WP_Error|WP_REST_Response
217
-	 */
218
-	public function update_item( $request ) {
219
-		$setting = $this->get_setting( $request['id'] );
220
-
221
-		if ( is_wp_error( $setting ) ) {
222
-			return $setting;
223
-		}
224
-
225
-		if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) {
226
-			$value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting );
227
-		} else {
228
-			$value = $this->validate_setting_text_field( $request['value'], $setting );
229
-		}
230
-
231
-		if ( is_wp_error( $value ) ) {
232
-			return $value;
233
-		}
234
-
235
-		wpinv_update_option( $request['id'], $value );
236
-		$setting['value'] = $value;
237
-		$setting          = $this->sanitize_setting( $setting );
238
-		$response         = $this->prepare_item_for_response( $setting, $request );
239
-
240
-		return rest_ensure_response( $response );
241
-	}
242
-
243
-	/**
244
-	 * Makes sure the current user has access to READ the settings APIs.
245
-	 *
246
-	 * @since  2.0.0
247
-	 * @param WP_REST_Request $request Full data about the request.
248
-	 * @return WP_Error|boolean
249
-	 */
250
-	public function get_items_permissions_check( $request ) {
251
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
252
-			return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
253
-		}
254
-
255
-		return true;
256
-	}
257
-
258
-	/**
259
-	 * Makes sure the current user has access to WRITE the settings APIs.
260
-	 *
261
-	 * @since  2.0.0
262
-	 * @param WP_REST_Request $request Full data about the request.
263
-	 * @return WP_Error|boolean
264
-	 */
265
-	public function update_items_permissions_check( $request ) {
266
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
267
-			return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
268
-		}
269
-
270
-		return true;
271
-	}
272
-
273
-	/**
274
-	 * Check if a given request has access batch create, update and delete items.
275
-	 *
276
-	 * @param  WP_REST_Request $request Full details about the request.
277
-	 *
278
-	 * @return boolean|WP_Error
279
-	 */
280
-	public function batch_items_permissions_check( $request ) {
281
-		return wpinv_current_user_can_manage_invoicing() ? true : new WP_Error( 'rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
282
-	}
283
-
284
-	/**
285
-	 * Prepare links for the request.
286
-	 *
287
-	 * @param string $setting_id Setting ID.
288
-	 * @return array Links for the given setting.
289
-	 */
290
-	protected function prepare_links( $setting_id ) {
291
-
292
-		$links = array(
293
-			'self'       => array(
294
-				'href' => rest_url( sprintf( '/%s/%s/setting/%s', $this->namespace, $this->rest_base, $setting_id ) ),
295
-			),
296
-			'collection' => array(
297
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
298
-			),
299
-		);
300
-
301
-		return $links;
302
-	}
303
-
304
-	/**
305
-	 * Prepare a settings object for serialization.
306
-	 *
307
-	 * @since  2.0.0
308
-	 * @param array           $item Setting object.
309
-	 * @param WP_REST_Request $request Request object.
310
-	 * @return WP_REST_Response $response Response data.
311
-	 */
312
-	public function prepare_item_for_response( $item, $request ) {
313
-		$context = empty( $request['context'] ) ? 'view' : $request['context'];
314
-		$data    = $this->add_additional_fields_to_object( $item, $request );
315
-		$data    = $this->filter_response_by_context( $data, $context );
316
-
317
-		$response = rest_ensure_response( $data );
318
-
319
-		$response->add_links( $this->prepare_links( $item['id'] ) );
320
-
321
-		return $response;
322
-	}
323
-
324
-	/**
325
-	 * Filters out bad values from the settings array/filter so we
326
-	 * only return known values via the API.
327
-	 *
328
-	 * @since 2.0.0
329
-	 * @param  array $setting Setting.
330
-	 * @return array
331
-	 */
332
-	public function filter_setting( $setting ) {
333
-		return array_intersect_key(
334
-			$setting,
335
-			array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) )
336
-		);
337
-	}
338
-
339
-	/**
340
-	 * Callback for allowed keys for each setting response.
341
-	 *
342
-	 * @param  string $key Key to check.
343
-	 * @return boolean
344
-	 */
345
-	public function allowed_setting_keys( $key ) {
346
-		return in_array( $key, array_keys( $this->setting_defaults() ), true );
347
-	}
348
-
349
-	/**
350
-	 * Returns default options for a setting. null means the field is required.
351
-	 *
352
-	 * @since  2.0.0
353
-	 * @return array
354
-	 */
355
-	protected function setting_defaults() {
356
-		return array(
357
-			'id'          => null,
358
-			'name'        => null,
359
-			'desc'        => '',
360
-			'options'     => array(),
361
-			'std'         => false,
362
-			'value'       => false,
363
-			'placeholder' => '',
364
-			'readonly'    => false,
365
-			'faux'        => false,
366
-			'section'     => 'main',
367
-			'tab'         => 'general',
368
-			'type'        => 'text',
369
-		);
370
-	}
371
-
372
-	/**
373
-	 * Sanitizes a setting's field.
374
-	 *
375
-	 * @param  array $setting The setting to sanitize.
376
-	 * @return array
377
-	 */
378
-	public function sanitize_setting( $setting ) {
379
-
380
-		$setting          = wp_parse_args( $setting, $this->setting_defaults() );
381
-		$setting['value'] = wpinv_get_option( $setting['id'], $setting['std'] );
382
-		return $this->filter_setting( $setting );
383
-
384
-	}
385
-
386
-	/**
387
-	 * Get setting data.
388
-	 *
389
-	 * @since  2.0.0
390
-	 * @param string $setting_id Setting ID.
391
-	 * @return array|WP_Error
392
-	 */
393
-	public function get_setting( $setting_id ) {
394
-
395
-		if ( empty( $setting_id ) ) {
396
-			return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'invoicing' ), array( 'status' => 404 ) );
397
-		}
398
-
399
-		$settings  = $this->get_settings();
400
-
401
-		foreach ( $settings as $tabs ) {
402
-
403
-			foreach ( $tabs as $sections ) {
404
-
405
-				if ( isset( $sections[ $setting_id ] ) ) {
406
-					if ( ! $this->is_setting_type_valid( $sections[ $setting_id ]['type'] ) ) {
407
-						return new WP_Error( 'rest_setting_setting_type_invalid', __( 'Invalid setting type.', 'invoicing' ), array( 'status' => 404 ) );
408
-					}
409
-
410
-					return $sections[ $setting_id ];
411
-				}
189
+        return rest_ensure_response( $prepared );
190
+    }
191
+
192
+    /**
193
+     * Return a single setting.
194
+     *
195
+     * @since  2.0.0
196
+     * @param  WP_REST_Request $request Request data.
197
+     * @return WP_Error|WP_REST_Response
198
+     */
199
+    public function get_item( $request ) {
200
+        $setting  = $this->get_setting( $request['id'] );
201
+
202
+        if ( is_wp_error( $setting ) ) {
203
+            return $setting;
204
+        }
205
+
206
+        $setting  = $this->sanitize_setting( $setting );
207
+        $response = $this->prepare_item_for_response( $setting, $request );
208
+        return rest_ensure_response( $response );
209
+    }
210
+
211
+    /**
212
+     * Update a single setting.
213
+     *
214
+     * @since  2.0.0
215
+     * @param  WP_REST_Request $request Request data.
216
+     * @return WP_Error|WP_REST_Response
217
+     */
218
+    public function update_item( $request ) {
219
+        $setting = $this->get_setting( $request['id'] );
220
+
221
+        if ( is_wp_error( $setting ) ) {
222
+            return $setting;
223
+        }
224
+
225
+        if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) {
226
+            $value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting );
227
+        } else {
228
+            $value = $this->validate_setting_text_field( $request['value'], $setting );
229
+        }
230
+
231
+        if ( is_wp_error( $value ) ) {
232
+            return $value;
233
+        }
234
+
235
+        wpinv_update_option( $request['id'], $value );
236
+        $setting['value'] = $value;
237
+        $setting          = $this->sanitize_setting( $setting );
238
+        $response         = $this->prepare_item_for_response( $setting, $request );
239
+
240
+        return rest_ensure_response( $response );
241
+    }
242
+
243
+    /**
244
+     * Makes sure the current user has access to READ the settings APIs.
245
+     *
246
+     * @since  2.0.0
247
+     * @param WP_REST_Request $request Full data about the request.
248
+     * @return WP_Error|boolean
249
+     */
250
+    public function get_items_permissions_check( $request ) {
251
+        if ( ! wpinv_current_user_can_manage_invoicing() ) {
252
+            return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
253
+        }
254
+
255
+        return true;
256
+    }
257
+
258
+    /**
259
+     * Makes sure the current user has access to WRITE the settings APIs.
260
+     *
261
+     * @since  2.0.0
262
+     * @param WP_REST_Request $request Full data about the request.
263
+     * @return WP_Error|boolean
264
+     */
265
+    public function update_items_permissions_check( $request ) {
266
+        if ( ! wpinv_current_user_can_manage_invoicing() ) {
267
+            return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
268
+        }
269
+
270
+        return true;
271
+    }
272
+
273
+    /**
274
+     * Check if a given request has access batch create, update and delete items.
275
+     *
276
+     * @param  WP_REST_Request $request Full details about the request.
277
+     *
278
+     * @return boolean|WP_Error
279
+     */
280
+    public function batch_items_permissions_check( $request ) {
281
+        return wpinv_current_user_can_manage_invoicing() ? true : new WP_Error( 'rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
282
+    }
283
+
284
+    /**
285
+     * Prepare links for the request.
286
+     *
287
+     * @param string $setting_id Setting ID.
288
+     * @return array Links for the given setting.
289
+     */
290
+    protected function prepare_links( $setting_id ) {
291
+
292
+        $links = array(
293
+            'self'       => array(
294
+                'href' => rest_url( sprintf( '/%s/%s/setting/%s', $this->namespace, $this->rest_base, $setting_id ) ),
295
+            ),
296
+            'collection' => array(
297
+                'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
298
+            ),
299
+        );
300
+
301
+        return $links;
302
+    }
303
+
304
+    /**
305
+     * Prepare a settings object for serialization.
306
+     *
307
+     * @since  2.0.0
308
+     * @param array           $item Setting object.
309
+     * @param WP_REST_Request $request Request object.
310
+     * @return WP_REST_Response $response Response data.
311
+     */
312
+    public function prepare_item_for_response( $item, $request ) {
313
+        $context = empty( $request['context'] ) ? 'view' : $request['context'];
314
+        $data    = $this->add_additional_fields_to_object( $item, $request );
315
+        $data    = $this->filter_response_by_context( $data, $context );
316
+
317
+        $response = rest_ensure_response( $data );
318
+
319
+        $response->add_links( $this->prepare_links( $item['id'] ) );
320
+
321
+        return $response;
322
+    }
323
+
324
+    /**
325
+     * Filters out bad values from the settings array/filter so we
326
+     * only return known values via the API.
327
+     *
328
+     * @since 2.0.0
329
+     * @param  array $setting Setting.
330
+     * @return array
331
+     */
332
+    public function filter_setting( $setting ) {
333
+        return array_intersect_key(
334
+            $setting,
335
+            array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) )
336
+        );
337
+    }
338
+
339
+    /**
340
+     * Callback for allowed keys for each setting response.
341
+     *
342
+     * @param  string $key Key to check.
343
+     * @return boolean
344
+     */
345
+    public function allowed_setting_keys( $key ) {
346
+        return in_array( $key, array_keys( $this->setting_defaults() ), true );
347
+    }
348
+
349
+    /**
350
+     * Returns default options for a setting. null means the field is required.
351
+     *
352
+     * @since  2.0.0
353
+     * @return array
354
+     */
355
+    protected function setting_defaults() {
356
+        return array(
357
+            'id'          => null,
358
+            'name'        => null,
359
+            'desc'        => '',
360
+            'options'     => array(),
361
+            'std'         => false,
362
+            'value'       => false,
363
+            'placeholder' => '',
364
+            'readonly'    => false,
365
+            'faux'        => false,
366
+            'section'     => 'main',
367
+            'tab'         => 'general',
368
+            'type'        => 'text',
369
+        );
370
+    }
371
+
372
+    /**
373
+     * Sanitizes a setting's field.
374
+     *
375
+     * @param  array $setting The setting to sanitize.
376
+     * @return array
377
+     */
378
+    public function sanitize_setting( $setting ) {
379
+
380
+        $setting          = wp_parse_args( $setting, $this->setting_defaults() );
381
+        $setting['value'] = wpinv_get_option( $setting['id'], $setting['std'] );
382
+        return $this->filter_setting( $setting );
383
+
384
+    }
385
+
386
+    /**
387
+     * Get setting data.
388
+     *
389
+     * @since  2.0.0
390
+     * @param string $setting_id Setting ID.
391
+     * @return array|WP_Error
392
+     */
393
+    public function get_setting( $setting_id ) {
394
+
395
+        if ( empty( $setting_id ) ) {
396
+            return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'invoicing' ), array( 'status' => 404 ) );
397
+        }
398
+
399
+        $settings  = $this->get_settings();
400
+
401
+        foreach ( $settings as $tabs ) {
402
+
403
+            foreach ( $tabs as $sections ) {
404
+
405
+                if ( isset( $sections[ $setting_id ] ) ) {
406
+                    if ( ! $this->is_setting_type_valid( $sections[ $setting_id ]['type'] ) ) {
407
+                        return new WP_Error( 'rest_setting_setting_type_invalid', __( 'Invalid setting type.', 'invoicing' ), array( 'status' => 404 ) );
408
+                    }
409
+
410
+                    return $sections[ $setting_id ];
411
+                }
412 412
 }
413 413
 }
414 414
 
415
-		return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'invoicing' ), array( 'status' => 404 ) );
416
-	}
417
-
418
-	/**
419
-	 * Get all tabs.
420
-	 *
421
-	 * @param  WP_REST_Request $request Request data.
422
-	 * @return array
423
-	 */
424
-	public function get_tabs( $request ) {
425
-		$tabs     = wpinv_get_settings_tabs();
426
-		$prepared = array();
427
-
428
-		foreach ( $tabs as $id => $tab ) {
429
-
430
-			$_request        = $request;
431
-			$_request['tab'] = sanitize_title( $id );
432
-			$data            = array(
433
-				'id'       => sanitize_title( $id ),
434
-				'label'    => sanitize_text_field( $tab ),
435
-				'sections' => $this->get_sections( $_request ),
436
-			);
437
-
438
-			$data     = $this->add_additional_fields_to_object( $data, $request );
439
-			$response = rest_ensure_response( $data );
440
-
441
-			if ( ! is_wp_error( $response ) ) {
442
-				$links = array(
443
-					'sections'   => array(
444
-						'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $id ) ),
445
-					),
446
-					'collection' => array(
447
-						'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
448
-					),
449
-				);
450
-				$response->add_links( $links );
451
-				$response = $this->prepare_response_for_collection( $response );
452
-			}
453
-
454
-			$prepared[] = $response;
455
-
456
-		}
457
-
458
-		return rest_ensure_response( $prepared );
459
-	}
460
-
461
-	/**
462
-	 * Get all sections.
463
-	 *
464
-	 * @param  WP_REST_Request $request Request data.
465
-	 * @return array
466
-	 */
467
-	public function get_sections( $request ) {
468
-
469
-		$tab      = sanitize_title( $request['tab'] );
470
-		$sections = wpinv_get_settings_tab_sections( $tab );
471
-		$prepared = array();
472
-
473
-		foreach ( $sections as $id => $section ) {
474
-
475
-			$data            = array(
476
-				'id'    => sanitize_title( $id ),
477
-				'label' => sanitize_text_field( $section ),
478
-			);
479
-
480
-			$data     = $this->add_additional_fields_to_object( $data, $request );
481
-			$response = rest_ensure_response( $data );
482
-
483
-			if ( ! is_wp_error( $response ) ) {
484
-				$links = array(
485
-					'settings'   => array(
486
-						'href' => rest_url( sprintf( '/%s/%s/%s/%s', $this->namespace, $this->rest_base, $tab, $id ) ),
487
-					),
488
-					'collection' => array(
489
-						'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tab ) ),
490
-					),
491
-					'tabs'       => array(
492
-						'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
493
-					),
494
-				);
495
-				$response->add_links( $links );
496
-				$response = $this->prepare_response_for_collection( $response );
497
-			}
498
-
499
-			$prepared[] = $response;
500
-
501
-		}
502
-
503
-		return rest_ensure_response( $prepared );
504
-	}
505
-
506
-	/**
507
-	 * Get all settings.
508
-	 *
509
-	 * @return array
510
-	 */
511
-	public function get_settings() {
512
-
513
-		if ( empty( $this->settings ) ) {
514
-			$this->settings = wpinv_get_registered_settings();
515
-		}
516
-
517
-		return $this->settings;
518
-
519
-	}
520
-
521
-	/**
522
-	 * Boolean for if a setting type is a valid supported setting type.
523
-	 *
524
-	 * @since  2.0.0
525
-	 * @param  string $type Type.
526
-	 * @return bool
527
-	 */
528
-	public function is_setting_type_valid( $type ) {
529
-
530
-		return in_array(
531
-			$type,
415
+        return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'invoicing' ), array( 'status' => 404 ) );
416
+    }
417
+
418
+    /**
419
+     * Get all tabs.
420
+     *
421
+     * @param  WP_REST_Request $request Request data.
422
+     * @return array
423
+     */
424
+    public function get_tabs( $request ) {
425
+        $tabs     = wpinv_get_settings_tabs();
426
+        $prepared = array();
427
+
428
+        foreach ( $tabs as $id => $tab ) {
429
+
430
+            $_request        = $request;
431
+            $_request['tab'] = sanitize_title( $id );
432
+            $data            = array(
433
+                'id'       => sanitize_title( $id ),
434
+                'label'    => sanitize_text_field( $tab ),
435
+                'sections' => $this->get_sections( $_request ),
436
+            );
437
+
438
+            $data     = $this->add_additional_fields_to_object( $data, $request );
439
+            $response = rest_ensure_response( $data );
440
+
441
+            if ( ! is_wp_error( $response ) ) {
442
+                $links = array(
443
+                    'sections'   => array(
444
+                        'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $id ) ),
445
+                    ),
446
+                    'collection' => array(
447
+                        'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
448
+                    ),
449
+                );
450
+                $response->add_links( $links );
451
+                $response = $this->prepare_response_for_collection( $response );
452
+            }
453
+
454
+            $prepared[] = $response;
455
+
456
+        }
457
+
458
+        return rest_ensure_response( $prepared );
459
+    }
460
+
461
+    /**
462
+     * Get all sections.
463
+     *
464
+     * @param  WP_REST_Request $request Request data.
465
+     * @return array
466
+     */
467
+    public function get_sections( $request ) {
468
+
469
+        $tab      = sanitize_title( $request['tab'] );
470
+        $sections = wpinv_get_settings_tab_sections( $tab );
471
+        $prepared = array();
472
+
473
+        foreach ( $sections as $id => $section ) {
474
+
475
+            $data            = array(
476
+                'id'    => sanitize_title( $id ),
477
+                'label' => sanitize_text_field( $section ),
478
+            );
479
+
480
+            $data     = $this->add_additional_fields_to_object( $data, $request );
481
+            $response = rest_ensure_response( $data );
482
+
483
+            if ( ! is_wp_error( $response ) ) {
484
+                $links = array(
485
+                    'settings'   => array(
486
+                        'href' => rest_url( sprintf( '/%s/%s/%s/%s', $this->namespace, $this->rest_base, $tab, $id ) ),
487
+                    ),
488
+                    'collection' => array(
489
+                        'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tab ) ),
490
+                    ),
491
+                    'tabs'       => array(
492
+                        'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
493
+                    ),
494
+                );
495
+                $response->add_links( $links );
496
+                $response = $this->prepare_response_for_collection( $response );
497
+            }
498
+
499
+            $prepared[] = $response;
500
+
501
+        }
502
+
503
+        return rest_ensure_response( $prepared );
504
+    }
505
+
506
+    /**
507
+     * Get all settings.
508
+     *
509
+     * @return array
510
+     */
511
+    public function get_settings() {
512
+
513
+        if ( empty( $this->settings ) ) {
514
+            $this->settings = wpinv_get_registered_settings();
515
+        }
516
+
517
+        return $this->settings;
518
+
519
+    }
520
+
521
+    /**
522
+     * Boolean for if a setting type is a valid supported setting type.
523
+     *
524
+     * @since  2.0.0
525
+     * @param  string $type Type.
526
+     * @return bool
527
+     */
528
+    public function is_setting_type_valid( $type ) {
529
+
530
+        return in_array(
531
+            $type,
532 532
             array(
533
-				'text',         // Validates with validate_setting_text_field.
534
-				'email',        // Validates with validate_setting_text_field.
535
-				'number',       // Validates with validate_setting_text_field.
536
-				'color',        // Validates with validate_setting_text_field.
537
-				'password',     // Validates with validate_setting_text_field.
538
-				'textarea',     // Validates with validate_setting_textarea_field.
539
-				'select',       // Validates with validate_setting_select_field.
540
-				'multiselect',  // Validates with validate_setting_multiselect_field.
541
-				'radio',        // Validates with validate_setting_radio_field (-> validate_setting_select_field).
542
-				'checkbox',     // Validates with validate_setting_checkbox_field.
543
-				'header',       // Validates with validate_setting_text_field.
544
-			)
545
-		);
546
-
547
-	}
548
-
549
-	/**
550
-	 * Get the settings schema, conforming to JSON Schema.
551
-	 *
552
-	 * @return array
553
-	 */
554
-	public function get_item_schema() {
555
-
556
-		// Maybe retrieve the schema from cache.
557
-		if ( ! empty( $this->schema ) ) {
558
-			return $this->add_additional_fields_schema( $this->schema );
559
-		}
560
-
561
-		$schema = array(
562
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
563
-			'title'      => 'setting',
564
-			'type'       => 'object',
565
-			'properties' => array(
566
-				'id'          => array(
567
-					'description' => __( 'A unique identifier for the setting.', 'invoicing' ),
568
-					'type'        => 'string',
569
-					'arg_options' => array(
570
-						'sanitize_callback' => 'sanitize_title',
571
-					),
572
-					'context'     => array( 'view', 'edit' ),
573
-					'readonly'    => true,
574
-				),
575
-				'tab'         => array(
576
-					'description' => __( 'An identifier for the tab this setting belongs to.', 'invoicing' ),
577
-					'type'        => 'string',
578
-					'arg_options' => array(
579
-						'sanitize_callback' => 'sanitize_title',
580
-					),
581
-					'context'     => array( 'view', 'edit' ),
582
-					'readonly'    => true,
583
-				),
584
-				'section'     => array(
585
-					'description' => __( 'An identifier for the section this setting belongs to.', 'invoicing' ),
586
-					'type'        => 'string',
587
-					'arg_options' => array(
588
-						'sanitize_callback' => 'sanitize_title',
589
-					),
590
-					'context'     => array( 'view', 'edit' ),
591
-					'readonly'    => true,
592
-				),
593
-				'name'        => array(
594
-					'description' => __( 'A human readable label for the setting used in interfaces.', 'invoicing' ),
595
-					'type'        => 'string',
596
-					'arg_options' => array(
597
-						'sanitize_callback' => 'sanitize_text_field',
598
-					),
599
-					'context'     => array( 'view', 'edit' ),
600
-					'readonly'    => true,
601
-				),
602
-				'desc'        => array(
603
-					'description' => __( 'A human readable description for the setting used in interfaces.', 'invoicing' ),
604
-					'type'        => 'string',
605
-					'context'     => array( 'view', 'edit' ),
606
-					'readonly'    => true,
607
-				),
608
-				'value'       => array(
609
-					'description' => __( 'The current value of this setting.', 'invoicing' ),
610
-					'type'        => 'mixed',
611
-					'context'     => array( 'view', 'edit' ),
612
-				),
613
-				'default'     => array(
614
-					'description' => __( 'Default value for the setting.', 'invoicing' ),
615
-					'type'        => 'mixed',
616
-					'context'     => array( 'view', 'edit' ),
617
-					'readonly'    => true,
618
-				),
619
-				'placeholder' => array(
620
-					'description' => __( 'Placeholder text to be displayed in text inputs.', 'invoicing' ),
621
-					'type'        => 'string',
622
-					'arg_options' => array(
623
-						'sanitize_callback' => 'sanitize_text_field',
624
-					),
625
-					'context'     => array( 'view', 'edit' ),
626
-					'readonly'    => true,
627
-				),
628
-				'type'        => array(
629
-					'description' => __( 'Type of setting.', 'invoicing' ),
630
-					'type'        => 'string',
631
-					'arg_options' => array(
632
-						'sanitize_callback' => 'sanitize_text_field',
633
-					),
634
-					'context'     => array( 'view', 'edit' ),
635
-					'enum'        => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'raw_html' ),
636
-					'readonly'    => true,
637
-				),
638
-				'options'     => array(
639
-					'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'invoicing' ),
640
-					'type'        => 'object',
641
-					'context'     => array( 'view', 'edit' ),
642
-					'readonly'    => true,
643
-				),
644
-				'readonly'    => array(
645
-					'description' => __( 'Whether or not this setting is readonly', 'invoicing' ),
646
-					'type'        => 'string',
647
-					'context'     => array( 'view' ),
648
-					'readonly'    => true,
649
-				),
650
-				'faux'        => array(
651
-					'description' => __( 'Whether or not this setting is readonly/faux', 'invoicing' ),
652
-					'type'        => 'string',
653
-					'context'     => array( 'view' ),
654
-					'readonly'    => true,
655
-				),
656
-			),
657
-		);
658
-
659
-		// Filters the settings schema for the REST API.
533
+                'text',         // Validates with validate_setting_text_field.
534
+                'email',        // Validates with validate_setting_text_field.
535
+                'number',       // Validates with validate_setting_text_field.
536
+                'color',        // Validates with validate_setting_text_field.
537
+                'password',     // Validates with validate_setting_text_field.
538
+                'textarea',     // Validates with validate_setting_textarea_field.
539
+                'select',       // Validates with validate_setting_select_field.
540
+                'multiselect',  // Validates with validate_setting_multiselect_field.
541
+                'radio',        // Validates with validate_setting_radio_field (-> validate_setting_select_field).
542
+                'checkbox',     // Validates with validate_setting_checkbox_field.
543
+                'header',       // Validates with validate_setting_text_field.
544
+            )
545
+        );
546
+
547
+    }
548
+
549
+    /**
550
+     * Get the settings schema, conforming to JSON Schema.
551
+     *
552
+     * @return array
553
+     */
554
+    public function get_item_schema() {
555
+
556
+        // Maybe retrieve the schema from cache.
557
+        if ( ! empty( $this->schema ) ) {
558
+            return $this->add_additional_fields_schema( $this->schema );
559
+        }
560
+
561
+        $schema = array(
562
+            '$schema'    => 'http://json-schema.org/draft-04/schema#',
563
+            'title'      => 'setting',
564
+            'type'       => 'object',
565
+            'properties' => array(
566
+                'id'          => array(
567
+                    'description' => __( 'A unique identifier for the setting.', 'invoicing' ),
568
+                    'type'        => 'string',
569
+                    'arg_options' => array(
570
+                        'sanitize_callback' => 'sanitize_title',
571
+                    ),
572
+                    'context'     => array( 'view', 'edit' ),
573
+                    'readonly'    => true,
574
+                ),
575
+                'tab'         => array(
576
+                    'description' => __( 'An identifier for the tab this setting belongs to.', 'invoicing' ),
577
+                    'type'        => 'string',
578
+                    'arg_options' => array(
579
+                        'sanitize_callback' => 'sanitize_title',
580
+                    ),
581
+                    'context'     => array( 'view', 'edit' ),
582
+                    'readonly'    => true,
583
+                ),
584
+                'section'     => array(
585
+                    'description' => __( 'An identifier for the section this setting belongs to.', 'invoicing' ),
586
+                    'type'        => 'string',
587
+                    'arg_options' => array(
588
+                        'sanitize_callback' => 'sanitize_title',
589
+                    ),
590
+                    'context'     => array( 'view', 'edit' ),
591
+                    'readonly'    => true,
592
+                ),
593
+                'name'        => array(
594
+                    'description' => __( 'A human readable label for the setting used in interfaces.', 'invoicing' ),
595
+                    'type'        => 'string',
596
+                    'arg_options' => array(
597
+                        'sanitize_callback' => 'sanitize_text_field',
598
+                    ),
599
+                    'context'     => array( 'view', 'edit' ),
600
+                    'readonly'    => true,
601
+                ),
602
+                'desc'        => array(
603
+                    'description' => __( 'A human readable description for the setting used in interfaces.', 'invoicing' ),
604
+                    'type'        => 'string',
605
+                    'context'     => array( 'view', 'edit' ),
606
+                    'readonly'    => true,
607
+                ),
608
+                'value'       => array(
609
+                    'description' => __( 'The current value of this setting.', 'invoicing' ),
610
+                    'type'        => 'mixed',
611
+                    'context'     => array( 'view', 'edit' ),
612
+                ),
613
+                'default'     => array(
614
+                    'description' => __( 'Default value for the setting.', 'invoicing' ),
615
+                    'type'        => 'mixed',
616
+                    'context'     => array( 'view', 'edit' ),
617
+                    'readonly'    => true,
618
+                ),
619
+                'placeholder' => array(
620
+                    'description' => __( 'Placeholder text to be displayed in text inputs.', 'invoicing' ),
621
+                    'type'        => 'string',
622
+                    'arg_options' => array(
623
+                        'sanitize_callback' => 'sanitize_text_field',
624
+                    ),
625
+                    'context'     => array( 'view', 'edit' ),
626
+                    'readonly'    => true,
627
+                ),
628
+                'type'        => array(
629
+                    'description' => __( 'Type of setting.', 'invoicing' ),
630
+                    'type'        => 'string',
631
+                    'arg_options' => array(
632
+                        'sanitize_callback' => 'sanitize_text_field',
633
+                    ),
634
+                    'context'     => array( 'view', 'edit' ),
635
+                    'enum'        => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'raw_html' ),
636
+                    'readonly'    => true,
637
+                ),
638
+                'options'     => array(
639
+                    'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'invoicing' ),
640
+                    'type'        => 'object',
641
+                    'context'     => array( 'view', 'edit' ),
642
+                    'readonly'    => true,
643
+                ),
644
+                'readonly'    => array(
645
+                    'description' => __( 'Whether or not this setting is readonly', 'invoicing' ),
646
+                    'type'        => 'string',
647
+                    'context'     => array( 'view' ),
648
+                    'readonly'    => true,
649
+                ),
650
+                'faux'        => array(
651
+                    'description' => __( 'Whether or not this setting is readonly/faux', 'invoicing' ),
652
+                    'type'        => 'string',
653
+                    'context'     => array( 'view' ),
654
+                    'readonly'    => true,
655
+                ),
656
+            ),
657
+        );
658
+
659
+        // Filters the settings schema for the REST API.
660 660
         $schema = apply_filters( 'getpaid_rest_settings_schema', $schema );
661 661
 
662
-		// Cache the settings schema.
663
-		$this->schema = $schema;
664
-
665
-		return $this->add_additional_fields_schema( $this->schema );
666
-
667
-	}
668
-
669
-	/**
670
-	 * Validate a text value for a text based setting.
671
-	 *
672
-	 * @since 2.0.0
673
-	 * @param string $value Value.
674
-	 * @param array  $setting Setting.
675
-	 * @return string
676
-	 */
677
-	public function validate_setting_text_field( $value ) {
678
-		$value = is_null( $value ) ? '' : $value;
679
-		return wp_kses_post( trim( stripslashes( $value ) ) );
680
-	}
681
-
682
-	/**
683
-	 * Validate select based settings.
684
-	 *
685
-	 * @since 2.0.0
686
-	 * @param string $value Value.
687
-	 * @param array  $setting Setting.
688
-	 * @return string|WP_Error
689
-	 */
690
-	public function validate_setting_select_field( $value, $setting ) {
691
-		if ( array_key_exists( $value, $setting['options'] ) ) {
692
-			return $value;
693
-		} else {
694
-			return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'invoicing' ), array( 'status' => 400 ) );
695
-		}
696
-	}
697
-
698
-	/**
699
-	 * Validate multiselect based settings.
700
-	 *
701
-	 * @since 2.0.0
702
-	 * @param array $values Values.
703
-	 * @param array $setting Setting.
704
-	 * @return array|WP_Error
705
-	 */
706
-	public function validate_setting_multiselect_field( $values, $setting ) {
707
-		if ( empty( $values ) ) {
708
-			return array();
709
-		}
710
-
711
-		if ( ! is_array( $values ) ) {
712
-			return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'invoicing' ), array( 'status' => 400 ) );
713
-		}
714
-
715
-		$final_values = array();
716
-		foreach ( $values as $value ) {
717
-			if ( array_key_exists( $value, $setting['options'] ) ) {
718
-				$final_values[] = $value;
719
-			}
720
-		}
721
-
722
-		return $final_values;
723
-	}
724
-
725
-	/**
726
-	 * Validate radio based settings.
727
-	 *
728
-	 * @since 2.0.0
729
-	 * @param string $value Value.
730
-	 * @param array  $setting Setting.
731
-	 * @return string|WP_Error
732
-	 */
733
-	public function validate_setting_radio_field( $value, $setting ) {
734
-		return $this->validate_setting_select_field( $value, $setting );
735
-	}
736
-
737
-	/**
738
-	 * Validate checkbox based settings.
739
-	 *
740
-	 * @since 2.0.0
741
-	 * @param string $value Value.
742
-	 * @return int
743
-	 */
744
-	public function validate_setting_checkbox_field( $value ) {
745
-		return (int) ! empty( $value );
746
-	}
747
-
748
-	/**
749
-	 * Validate textarea based settings.
750
-	 *
751
-	 * @since 2.0.0
752
-	 * @param string $value Value.
753
-	 * @return string
754
-	 */
755
-	public function validate_setting_textarea_field( $value ) {
756
-		$value = is_null( $value ) ? '' : $value;
757
-		return wp_kses(
758
-			trim( stripslashes( $value ) ),
759
-			array_merge(
760
-				array(
761
-					'iframe' => array(
762
-						'src'   => true,
763
-						'style' => true,
764
-						'id'    => true,
765
-						'class' => true,
766
-					),
767
-				),
768
-				wp_kses_allowed_html( 'post' )
769
-			)
770
-		);
771
-	}
662
+        // Cache the settings schema.
663
+        $this->schema = $schema;
664
+
665
+        return $this->add_additional_fields_schema( $this->schema );
666
+
667
+    }
668
+
669
+    /**
670
+     * Validate a text value for a text based setting.
671
+     *
672
+     * @since 2.0.0
673
+     * @param string $value Value.
674
+     * @param array  $setting Setting.
675
+     * @return string
676
+     */
677
+    public function validate_setting_text_field( $value ) {
678
+        $value = is_null( $value ) ? '' : $value;
679
+        return wp_kses_post( trim( stripslashes( $value ) ) );
680
+    }
681
+
682
+    /**
683
+     * Validate select based settings.
684
+     *
685
+     * @since 2.0.0
686
+     * @param string $value Value.
687
+     * @param array  $setting Setting.
688
+     * @return string|WP_Error
689
+     */
690
+    public function validate_setting_select_field( $value, $setting ) {
691
+        if ( array_key_exists( $value, $setting['options'] ) ) {
692
+            return $value;
693
+        } else {
694
+            return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'invoicing' ), array( 'status' => 400 ) );
695
+        }
696
+    }
697
+
698
+    /**
699
+     * Validate multiselect based settings.
700
+     *
701
+     * @since 2.0.0
702
+     * @param array $values Values.
703
+     * @param array $setting Setting.
704
+     * @return array|WP_Error
705
+     */
706
+    public function validate_setting_multiselect_field( $values, $setting ) {
707
+        if ( empty( $values ) ) {
708
+            return array();
709
+        }
710
+
711
+        if ( ! is_array( $values ) ) {
712
+            return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'invoicing' ), array( 'status' => 400 ) );
713
+        }
714
+
715
+        $final_values = array();
716
+        foreach ( $values as $value ) {
717
+            if ( array_key_exists( $value, $setting['options'] ) ) {
718
+                $final_values[] = $value;
719
+            }
720
+        }
721
+
722
+        return $final_values;
723
+    }
724
+
725
+    /**
726
+     * Validate radio based settings.
727
+     *
728
+     * @since 2.0.0
729
+     * @param string $value Value.
730
+     * @param array  $setting Setting.
731
+     * @return string|WP_Error
732
+     */
733
+    public function validate_setting_radio_field( $value, $setting ) {
734
+        return $this->validate_setting_select_field( $value, $setting );
735
+    }
736
+
737
+    /**
738
+     * Validate checkbox based settings.
739
+     *
740
+     * @since 2.0.0
741
+     * @param string $value Value.
742
+     * @return int
743
+     */
744
+    public function validate_setting_checkbox_field( $value ) {
745
+        return (int) ! empty( $value );
746
+    }
747
+
748
+    /**
749
+     * Validate textarea based settings.
750
+     *
751
+     * @since 2.0.0
752
+     * @param string $value Value.
753
+     * @return string
754
+     */
755
+    public function validate_setting_textarea_field( $value ) {
756
+        $value = is_null( $value ) ? '' : $value;
757
+        return wp_kses(
758
+            trim( stripslashes( $value ) ),
759
+            array_merge(
760
+                array(
761
+                    'iframe' => array(
762
+                        'src'   => true,
763
+                        'style' => true,
764
+                        'id'    => true,
765
+                        'class' => true,
766
+                    ),
767
+                ),
768
+                wp_kses_allowed_html( 'post' )
769
+            )
770
+        );
771
+    }
772 772
 
773 773
 }
Please login to merge, or discard this patch.
Spacing   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @since   2.0.0
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * GetPaid REST Setting controller class.
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 *
40 40
 	 * @see register_rest_route()
41 41
 	 */
42
-	public function register_namespace_routes( $namespace ) {
42
+	public function register_namespace_routes($namespace) {
43 43
 
44 44
 		// List all registered tabs.
45 45
 		register_rest_route(
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 			array(
49 49
 				array(
50 50
 					'methods'             => WP_REST_Server::READABLE,
51
-					'callback'            => array( $this, 'get_tabs' ),
52
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
51
+					'callback'            => array($this, 'get_tabs'),
52
+					'permission_callback' => array($this, 'get_items_permissions_check'),
53 53
 				),
54 54
 				'schema' => '__return_empty_array',
55 55
 			)
@@ -62,23 +62,23 @@  discard block
 block discarded – undo
62 62
 			array(
63 63
 				'args'   => array(
64 64
 					'id' => array(
65
-						'description' => __( 'Unique identifier for the setting.', 'invoicing' ),
65
+						'description' => __('Unique identifier for the setting.', 'invoicing'),
66 66
 						'type'        => 'string',
67 67
 						'required'    => true,
68 68
 					),
69 69
 				),
70 70
 				array(
71 71
 					'methods'             => WP_REST_Server::READABLE,
72
-					'callback'            => array( $this, 'get_item' ),
73
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
72
+					'callback'            => array($this, 'get_item'),
73
+					'permission_callback' => array($this, 'get_items_permissions_check'),
74 74
 				),
75 75
 				array(
76 76
 					'methods'             => WP_REST_Server::EDITABLE,
77
-					'callback'            => array( $this, 'update_item' ),
78
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
79
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
77
+					'callback'            => array($this, 'update_item'),
78
+					'permission_callback' => array($this, 'update_items_permissions_check'),
79
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
80 80
 				),
81
-				'schema' => array( $this, 'get_public_item_schema' ),
81
+				'schema' => array($this, 'get_public_item_schema'),
82 82
 			)
83 83
 		);
84 84
 
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
89 89
 			array(
90 90
 				'args'   => array(
91 91
 					'tab' => array(
92
-						'description' => __( 'Unique identifier for the tab whose sections should be retrieved.', 'invoicing' ),
92
+						'description' => __('Unique identifier for the tab whose sections should be retrieved.', 'invoicing'),
93 93
 						'type'        => 'string',
94 94
 						'required'    => true,
95
-						'enum'        => array_keys( wpinv_get_settings_tabs() ),
95
+						'enum'        => array_keys(wpinv_get_settings_tabs()),
96 96
 					),
97 97
 				),
98 98
 				array(
99 99
 					'methods'             => WP_REST_Server::READABLE,
100
-					'callback'            => array( $this, 'get_sections' ),
101
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
100
+					'callback'            => array($this, 'get_sections'),
101
+					'permission_callback' => array($this, 'get_items_permissions_check'),
102 102
 				),
103 103
 				'schema' => '__return_empty_array',
104 104
 			)
@@ -111,23 +111,23 @@  discard block
 block discarded – undo
111 111
 			array(
112 112
 				'args'   => array(
113 113
 					'tab'     => array(
114
-						'description' => __( 'Unique identifier for the tab whose settings should be retrieved.', 'invoicing' ),
114
+						'description' => __('Unique identifier for the tab whose settings should be retrieved.', 'invoicing'),
115 115
 						'type'        => 'string',
116 116
 						'required'    => true,
117
-						'enum'        => array_keys( wpinv_get_settings_tabs() ),
117
+						'enum'        => array_keys(wpinv_get_settings_tabs()),
118 118
 					),
119 119
 					'section' => array(
120
-						'description' => __( 'The section in the tab whose settings should be retrieved.', 'invoicing' ),
120
+						'description' => __('The section in the tab whose settings should be retrieved.', 'invoicing'),
121 121
 						'type'        => 'string',
122 122
 						'required'    => true,
123 123
 					),
124 124
 				),
125 125
 				array(
126 126
 					'methods'             => WP_REST_Server::READABLE,
127
-					'callback'            => array( $this, 'get_items' ),
128
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
127
+					'callback'            => array($this, 'get_items'),
128
+					'permission_callback' => array($this, 'get_items_permissions_check'),
129 129
 				),
130
-				'schema' => array( $this, 'get_public_item_schema' ),
130
+				'schema' => array($this, 'get_public_item_schema'),
131 131
 			)
132 132
 		);
133 133
 
@@ -137,17 +137,17 @@  discard block
 block discarded – undo
137 137
 			array(
138 138
 				'args'   => array(
139 139
 					'id' => array(
140
-						'description' => __( 'Setting ID.', 'invoicing' ),
140
+						'description' => __('Setting ID.', 'invoicing'),
141 141
 						'type'        => 'string',
142 142
 					),
143 143
 				),
144 144
 				array(
145 145
 					'methods'             => WP_REST_Server::EDITABLE,
146
-					'callback'            => array( $this, 'batch_items' ),
147
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
148
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
146
+					'callback'            => array($this, 'batch_items'),
147
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
148
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
149 149
 				),
150
-				'schema' => array( $this, 'get_public_batch_schema' ),
150
+				'schema' => array($this, 'get_public_batch_schema'),
151 151
 			)
152 152
 		);
153 153
 
@@ -160,33 +160,33 @@  discard block
 block discarded – undo
160 160
 	 * @param  WP_REST_Request $request Request data.
161 161
 	 * @return WP_Error|WP_REST_Response
162 162
 	 */
163
-	public function get_items( $request ) {
163
+	public function get_items($request) {
164 164
 
165 165
 		$settings = $this->get_settings();
166 166
 
167
-		if ( ! isset( $settings[ $request['tab'] ] ) ) {
168
-			return new WP_Error( 'rest_invalid_tab', __( 'Invalid tab.', 'invoicing' ), array( 'status' => 400 ) );
167
+		if (!isset($settings[$request['tab']])) {
168
+			return new WP_Error('rest_invalid_tab', __('Invalid tab.', 'invoicing'), array('status' => 400));
169 169
 		}
170 170
 
171
-		if ( ! isset( $settings[ $request['tab'] ][ $request['section'] ] ) ) {
172
-			return new WP_Error( 'rest_invalid_section', __( 'Invalid section.', 'invoicing' ), array( 'status' => 400 ) );
171
+		if (!isset($settings[$request['tab']][$request['section']])) {
172
+			return new WP_Error('rest_invalid_section', __('Invalid section.', 'invoicing'), array('status' => 400));
173 173
 		}
174 174
 
175
-		$settings = $settings[ $request['tab'] ][ $request['section'] ];
175
+		$settings = $settings[$request['tab']][$request['section']];
176 176
 		$prepared = array();
177 177
 
178
-		foreach ( $settings as $setting ) {
178
+		foreach ($settings as $setting) {
179 179
 
180
-			$setting      = $this->sanitize_setting( $setting );
181
-			$setting_data = $this->prepare_item_for_response( $setting, $request );
182
-			$setting_data = $this->prepare_response_for_collection( $setting_data );
180
+			$setting      = $this->sanitize_setting($setting);
181
+			$setting_data = $this->prepare_item_for_response($setting, $request);
182
+			$setting_data = $this->prepare_response_for_collection($setting_data);
183 183
 
184
-			if ( $this->is_setting_type_valid( $setting['type'] ) ) {
185
-				$prepared[]   = $setting_data;
184
+			if ($this->is_setting_type_valid($setting['type'])) {
185
+				$prepared[] = $setting_data;
186 186
 			}
187 187
 }
188 188
 
189
-		return rest_ensure_response( $prepared );
189
+		return rest_ensure_response($prepared);
190 190
 	}
191 191
 
192 192
 	/**
@@ -196,16 +196,16 @@  discard block
 block discarded – undo
196 196
 	 * @param  WP_REST_Request $request Request data.
197 197
 	 * @return WP_Error|WP_REST_Response
198 198
 	 */
199
-	public function get_item( $request ) {
200
-		$setting  = $this->get_setting( $request['id'] );
199
+	public function get_item($request) {
200
+		$setting = $this->get_setting($request['id']);
201 201
 
202
-		if ( is_wp_error( $setting ) ) {
202
+		if (is_wp_error($setting)) {
203 203
 			return $setting;
204 204
 		}
205 205
 
206
-		$setting  = $this->sanitize_setting( $setting );
207
-		$response = $this->prepare_item_for_response( $setting, $request );
208
-		return rest_ensure_response( $response );
206
+		$setting  = $this->sanitize_setting($setting);
207
+		$response = $this->prepare_item_for_response($setting, $request);
208
+		return rest_ensure_response($response);
209 209
 	}
210 210
 
211 211
 	/**
@@ -215,29 +215,29 @@  discard block
 block discarded – undo
215 215
 	 * @param  WP_REST_Request $request Request data.
216 216
 	 * @return WP_Error|WP_REST_Response
217 217
 	 */
218
-	public function update_item( $request ) {
219
-		$setting = $this->get_setting( $request['id'] );
218
+	public function update_item($request) {
219
+		$setting = $this->get_setting($request['id']);
220 220
 
221
-		if ( is_wp_error( $setting ) ) {
221
+		if (is_wp_error($setting)) {
222 222
 			return $setting;
223 223
 		}
224 224
 
225
-		if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) {
226
-			$value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting );
225
+		if (is_callable(array($this, 'validate_setting_' . $setting['type'] . '_field'))) {
226
+			$value = $this->{'validate_setting_' . $setting['type'] . '_field'}($request['value'], $setting);
227 227
 		} else {
228
-			$value = $this->validate_setting_text_field( $request['value'], $setting );
228
+			$value = $this->validate_setting_text_field($request['value'], $setting);
229 229
 		}
230 230
 
231
-		if ( is_wp_error( $value ) ) {
231
+		if (is_wp_error($value)) {
232 232
 			return $value;
233 233
 		}
234 234
 
235
-		wpinv_update_option( $request['id'], $value );
235
+		wpinv_update_option($request['id'], $value);
236 236
 		$setting['value'] = $value;
237
-		$setting          = $this->sanitize_setting( $setting );
238
-		$response         = $this->prepare_item_for_response( $setting, $request );
237
+		$setting          = $this->sanitize_setting($setting);
238
+		$response         = $this->prepare_item_for_response($setting, $request);
239 239
 
240
-		return rest_ensure_response( $response );
240
+		return rest_ensure_response($response);
241 241
 	}
242 242
 
243 243
 	/**
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
 	 * @param WP_REST_Request $request Full data about the request.
248 248
 	 * @return WP_Error|boolean
249 249
 	 */
250
-	public function get_items_permissions_check( $request ) {
251
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
252
-			return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
250
+	public function get_items_permissions_check($request) {
251
+		if (!wpinv_current_user_can_manage_invoicing()) {
252
+			return new WP_Error('rest_cannot_view', __('Sorry, you cannot list resources.', 'invoicing'), array('status' => rest_authorization_required_code()));
253 253
 		}
254 254
 
255 255
 		return true;
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 	 * @param WP_REST_Request $request Full data about the request.
263 263
 	 * @return WP_Error|boolean
264 264
 	 */
265
-	public function update_items_permissions_check( $request ) {
266
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
267
-			return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
265
+	public function update_items_permissions_check($request) {
266
+		if (!wpinv_current_user_can_manage_invoicing()) {
267
+			return new WP_Error('rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'invoicing'), array('status' => rest_authorization_required_code()));
268 268
 		}
269 269
 
270 270
 		return true;
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	 *
278 278
 	 * @return boolean|WP_Error
279 279
 	 */
280
-	public function batch_items_permissions_check( $request ) {
281
-		return wpinv_current_user_can_manage_invoicing() ? true : new WP_Error( 'rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
280
+	public function batch_items_permissions_check($request) {
281
+		return wpinv_current_user_can_manage_invoicing() ? true : new WP_Error('rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'invoicing'), array('status' => rest_authorization_required_code()));
282 282
 	}
283 283
 
284 284
 	/**
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
 	 * @param string $setting_id Setting ID.
288 288
 	 * @return array Links for the given setting.
289 289
 	 */
290
-	protected function prepare_links( $setting_id ) {
290
+	protected function prepare_links($setting_id) {
291 291
 
292 292
 		$links = array(
293 293
 			'self'       => array(
294
-				'href' => rest_url( sprintf( '/%s/%s/setting/%s', $this->namespace, $this->rest_base, $setting_id ) ),
294
+				'href' => rest_url(sprintf('/%s/%s/setting/%s', $this->namespace, $this->rest_base, $setting_id)),
295 295
 			),
296 296
 			'collection' => array(
297
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
297
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
298 298
 			),
299 299
 		);
300 300
 
@@ -309,14 +309,14 @@  discard block
 block discarded – undo
309 309
 	 * @param WP_REST_Request $request Request object.
310 310
 	 * @return WP_REST_Response $response Response data.
311 311
 	 */
312
-	public function prepare_item_for_response( $item, $request ) {
313
-		$context = empty( $request['context'] ) ? 'view' : $request['context'];
314
-		$data    = $this->add_additional_fields_to_object( $item, $request );
315
-		$data    = $this->filter_response_by_context( $data, $context );
312
+	public function prepare_item_for_response($item, $request) {
313
+		$context = empty($request['context']) ? 'view' : $request['context'];
314
+		$data    = $this->add_additional_fields_to_object($item, $request);
315
+		$data    = $this->filter_response_by_context($data, $context);
316 316
 
317
-		$response = rest_ensure_response( $data );
317
+		$response = rest_ensure_response($data);
318 318
 
319
-		$response->add_links( $this->prepare_links( $item['id'] ) );
319
+		$response->add_links($this->prepare_links($item['id']));
320 320
 
321 321
 		return $response;
322 322
 	}
@@ -329,10 +329,10 @@  discard block
 block discarded – undo
329 329
 	 * @param  array $setting Setting.
330 330
 	 * @return array
331 331
 	 */
332
-	public function filter_setting( $setting ) {
332
+	public function filter_setting($setting) {
333 333
 		return array_intersect_key(
334 334
 			$setting,
335
-			array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) )
335
+			array_flip(array_filter(array_keys($setting), array($this, 'allowed_setting_keys')))
336 336
 		);
337 337
 	}
338 338
 
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
 	 * @param  string $key Key to check.
343 343
 	 * @return boolean
344 344
 	 */
345
-	public function allowed_setting_keys( $key ) {
346
-		return in_array( $key, array_keys( $this->setting_defaults() ), true );
345
+	public function allowed_setting_keys($key) {
346
+		return in_array($key, array_keys($this->setting_defaults()), true);
347 347
 	}
348 348
 
349 349
 	/**
@@ -375,11 +375,11 @@  discard block
 block discarded – undo
375 375
 	 * @param  array $setting The setting to sanitize.
376 376
 	 * @return array
377 377
 	 */
378
-	public function sanitize_setting( $setting ) {
378
+	public function sanitize_setting($setting) {
379 379
 
380
-		$setting          = wp_parse_args( $setting, $this->setting_defaults() );
381
-		$setting['value'] = wpinv_get_option( $setting['id'], $setting['std'] );
382
-		return $this->filter_setting( $setting );
380
+		$setting          = wp_parse_args($setting, $this->setting_defaults());
381
+		$setting['value'] = wpinv_get_option($setting['id'], $setting['std']);
382
+		return $this->filter_setting($setting);
383 383
 
384 384
 	}
385 385
 
@@ -390,29 +390,29 @@  discard block
 block discarded – undo
390 390
 	 * @param string $setting_id Setting ID.
391 391
 	 * @return array|WP_Error
392 392
 	 */
393
-	public function get_setting( $setting_id ) {
393
+	public function get_setting($setting_id) {
394 394
 
395
-		if ( empty( $setting_id ) ) {
396
-			return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'invoicing' ), array( 'status' => 404 ) );
395
+		if (empty($setting_id)) {
396
+			return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'invoicing'), array('status' => 404));
397 397
 		}
398 398
 
399
-		$settings  = $this->get_settings();
399
+		$settings = $this->get_settings();
400 400
 
401
-		foreach ( $settings as $tabs ) {
401
+		foreach ($settings as $tabs) {
402 402
 
403
-			foreach ( $tabs as $sections ) {
403
+			foreach ($tabs as $sections) {
404 404
 
405
-				if ( isset( $sections[ $setting_id ] ) ) {
406
-					if ( ! $this->is_setting_type_valid( $sections[ $setting_id ]['type'] ) ) {
407
-						return new WP_Error( 'rest_setting_setting_type_invalid', __( 'Invalid setting type.', 'invoicing' ), array( 'status' => 404 ) );
405
+				if (isset($sections[$setting_id])) {
406
+					if (!$this->is_setting_type_valid($sections[$setting_id]['type'])) {
407
+						return new WP_Error('rest_setting_setting_type_invalid', __('Invalid setting type.', 'invoicing'), array('status' => 404));
408 408
 					}
409 409
 
410
-					return $sections[ $setting_id ];
410
+					return $sections[$setting_id];
411 411
 				}
412 412
 }
413 413
 }
414 414
 
415
-		return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'invoicing' ), array( 'status' => 404 ) );
415
+		return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'invoicing'), array('status' => 404));
416 416
 	}
417 417
 
418 418
 	/**
@@ -421,41 +421,41 @@  discard block
 block discarded – undo
421 421
 	 * @param  WP_REST_Request $request Request data.
422 422
 	 * @return array
423 423
 	 */
424
-	public function get_tabs( $request ) {
424
+	public function get_tabs($request) {
425 425
 		$tabs     = wpinv_get_settings_tabs();
426 426
 		$prepared = array();
427 427
 
428
-		foreach ( $tabs as $id => $tab ) {
428
+		foreach ($tabs as $id => $tab) {
429 429
 
430 430
 			$_request        = $request;
431
-			$_request['tab'] = sanitize_title( $id );
431
+			$_request['tab'] = sanitize_title($id);
432 432
 			$data            = array(
433
-				'id'       => sanitize_title( $id ),
434
-				'label'    => sanitize_text_field( $tab ),
435
-				'sections' => $this->get_sections( $_request ),
433
+				'id'       => sanitize_title($id),
434
+				'label'    => sanitize_text_field($tab),
435
+				'sections' => $this->get_sections($_request),
436 436
 			);
437 437
 
438
-			$data     = $this->add_additional_fields_to_object( $data, $request );
439
-			$response = rest_ensure_response( $data );
438
+			$data     = $this->add_additional_fields_to_object($data, $request);
439
+			$response = rest_ensure_response($data);
440 440
 
441
-			if ( ! is_wp_error( $response ) ) {
441
+			if (!is_wp_error($response)) {
442 442
 				$links = array(
443 443
 					'sections'   => array(
444
-						'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $id ) ),
444
+						'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $id)),
445 445
 					),
446 446
 					'collection' => array(
447
-						'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
447
+						'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
448 448
 					),
449 449
 				);
450
-				$response->add_links( $links );
451
-				$response = $this->prepare_response_for_collection( $response );
450
+				$response->add_links($links);
451
+				$response = $this->prepare_response_for_collection($response);
452 452
 			}
453 453
 
454 454
 			$prepared[] = $response;
455 455
 
456 456
 		}
457 457
 
458
-		return rest_ensure_response( $prepared );
458
+		return rest_ensure_response($prepared);
459 459
 	}
460 460
 
461 461
 	/**
@@ -464,43 +464,43 @@  discard block
 block discarded – undo
464 464
 	 * @param  WP_REST_Request $request Request data.
465 465
 	 * @return array
466 466
 	 */
467
-	public function get_sections( $request ) {
467
+	public function get_sections($request) {
468 468
 
469
-		$tab      = sanitize_title( $request['tab'] );
470
-		$sections = wpinv_get_settings_tab_sections( $tab );
469
+		$tab      = sanitize_title($request['tab']);
470
+		$sections = wpinv_get_settings_tab_sections($tab);
471 471
 		$prepared = array();
472 472
 
473
-		foreach ( $sections as $id => $section ) {
473
+		foreach ($sections as $id => $section) {
474 474
 
475
-			$data            = array(
476
-				'id'    => sanitize_title( $id ),
477
-				'label' => sanitize_text_field( $section ),
475
+			$data = array(
476
+				'id'    => sanitize_title($id),
477
+				'label' => sanitize_text_field($section),
478 478
 			);
479 479
 
480
-			$data     = $this->add_additional_fields_to_object( $data, $request );
481
-			$response = rest_ensure_response( $data );
480
+			$data     = $this->add_additional_fields_to_object($data, $request);
481
+			$response = rest_ensure_response($data);
482 482
 
483
-			if ( ! is_wp_error( $response ) ) {
483
+			if (!is_wp_error($response)) {
484 484
 				$links = array(
485 485
 					'settings'   => array(
486
-						'href' => rest_url( sprintf( '/%s/%s/%s/%s', $this->namespace, $this->rest_base, $tab, $id ) ),
486
+						'href' => rest_url(sprintf('/%s/%s/%s/%s', $this->namespace, $this->rest_base, $tab, $id)),
487 487
 					),
488 488
 					'collection' => array(
489
-						'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tab ) ),
489
+						'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $tab)),
490 490
 					),
491 491
 					'tabs'       => array(
492
-						'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
492
+						'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
493 493
 					),
494 494
 				);
495
-				$response->add_links( $links );
496
-				$response = $this->prepare_response_for_collection( $response );
495
+				$response->add_links($links);
496
+				$response = $this->prepare_response_for_collection($response);
497 497
 			}
498 498
 
499 499
 			$prepared[] = $response;
500 500
 
501 501
 		}
502 502
 
503
-		return rest_ensure_response( $prepared );
503
+		return rest_ensure_response($prepared);
504 504
 	}
505 505
 
506 506
 	/**
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 */
511 511
 	public function get_settings() {
512 512
 
513
-		if ( empty( $this->settings ) ) {
513
+		if (empty($this->settings)) {
514 514
 			$this->settings = wpinv_get_registered_settings();
515 515
 		}
516 516
 
@@ -525,22 +525,22 @@  discard block
 block discarded – undo
525 525
 	 * @param  string $type Type.
526 526
 	 * @return bool
527 527
 	 */
528
-	public function is_setting_type_valid( $type ) {
528
+	public function is_setting_type_valid($type) {
529 529
 
530 530
 		return in_array(
531 531
 			$type,
532 532
             array(
533
-				'text',         // Validates with validate_setting_text_field.
534
-				'email',        // Validates with validate_setting_text_field.
535
-				'number',       // Validates with validate_setting_text_field.
536
-				'color',        // Validates with validate_setting_text_field.
537
-				'password',     // Validates with validate_setting_text_field.
538
-				'textarea',     // Validates with validate_setting_textarea_field.
539
-				'select',       // Validates with validate_setting_select_field.
540
-				'multiselect',  // Validates with validate_setting_multiselect_field.
541
-				'radio',        // Validates with validate_setting_radio_field (-> validate_setting_select_field).
542
-				'checkbox',     // Validates with validate_setting_checkbox_field.
543
-				'header',       // Validates with validate_setting_text_field.
533
+				'text', // Validates with validate_setting_text_field.
534
+				'email', // Validates with validate_setting_text_field.
535
+				'number', // Validates with validate_setting_text_field.
536
+				'color', // Validates with validate_setting_text_field.
537
+				'password', // Validates with validate_setting_text_field.
538
+				'textarea', // Validates with validate_setting_textarea_field.
539
+				'select', // Validates with validate_setting_select_field.
540
+				'multiselect', // Validates with validate_setting_multiselect_field.
541
+				'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field).
542
+				'checkbox', // Validates with validate_setting_checkbox_field.
543
+				'header', // Validates with validate_setting_text_field.
544 544
 			)
545 545
 		);
546 546
 
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 	public function get_item_schema() {
555 555
 
556 556
 		// Maybe retrieve the schema from cache.
557
-		if ( ! empty( $this->schema ) ) {
558
-			return $this->add_additional_fields_schema( $this->schema );
557
+		if (!empty($this->schema)) {
558
+			return $this->add_additional_fields_schema($this->schema);
559 559
 		}
560 560
 
561 561
 		$schema = array(
@@ -564,105 +564,105 @@  discard block
 block discarded – undo
564 564
 			'type'       => 'object',
565 565
 			'properties' => array(
566 566
 				'id'          => array(
567
-					'description' => __( 'A unique identifier for the setting.', 'invoicing' ),
567
+					'description' => __('A unique identifier for the setting.', 'invoicing'),
568 568
 					'type'        => 'string',
569 569
 					'arg_options' => array(
570 570
 						'sanitize_callback' => 'sanitize_title',
571 571
 					),
572
-					'context'     => array( 'view', 'edit' ),
572
+					'context'     => array('view', 'edit'),
573 573
 					'readonly'    => true,
574 574
 				),
575 575
 				'tab'         => array(
576
-					'description' => __( 'An identifier for the tab this setting belongs to.', 'invoicing' ),
576
+					'description' => __('An identifier for the tab this setting belongs to.', 'invoicing'),
577 577
 					'type'        => 'string',
578 578
 					'arg_options' => array(
579 579
 						'sanitize_callback' => 'sanitize_title',
580 580
 					),
581
-					'context'     => array( 'view', 'edit' ),
581
+					'context'     => array('view', 'edit'),
582 582
 					'readonly'    => true,
583 583
 				),
584 584
 				'section'     => array(
585
-					'description' => __( 'An identifier for the section this setting belongs to.', 'invoicing' ),
585
+					'description' => __('An identifier for the section this setting belongs to.', 'invoicing'),
586 586
 					'type'        => 'string',
587 587
 					'arg_options' => array(
588 588
 						'sanitize_callback' => 'sanitize_title',
589 589
 					),
590
-					'context'     => array( 'view', 'edit' ),
590
+					'context'     => array('view', 'edit'),
591 591
 					'readonly'    => true,
592 592
 				),
593 593
 				'name'        => array(
594
-					'description' => __( 'A human readable label for the setting used in interfaces.', 'invoicing' ),
594
+					'description' => __('A human readable label for the setting used in interfaces.', 'invoicing'),
595 595
 					'type'        => 'string',
596 596
 					'arg_options' => array(
597 597
 						'sanitize_callback' => 'sanitize_text_field',
598 598
 					),
599
-					'context'     => array( 'view', 'edit' ),
599
+					'context'     => array('view', 'edit'),
600 600
 					'readonly'    => true,
601 601
 				),
602 602
 				'desc'        => array(
603
-					'description' => __( 'A human readable description for the setting used in interfaces.', 'invoicing' ),
603
+					'description' => __('A human readable description for the setting used in interfaces.', 'invoicing'),
604 604
 					'type'        => 'string',
605
-					'context'     => array( 'view', 'edit' ),
605
+					'context'     => array('view', 'edit'),
606 606
 					'readonly'    => true,
607 607
 				),
608 608
 				'value'       => array(
609
-					'description' => __( 'The current value of this setting.', 'invoicing' ),
609
+					'description' => __('The current value of this setting.', 'invoicing'),
610 610
 					'type'        => 'mixed',
611
-					'context'     => array( 'view', 'edit' ),
611
+					'context'     => array('view', 'edit'),
612 612
 				),
613 613
 				'default'     => array(
614
-					'description' => __( 'Default value for the setting.', 'invoicing' ),
614
+					'description' => __('Default value for the setting.', 'invoicing'),
615 615
 					'type'        => 'mixed',
616
-					'context'     => array( 'view', 'edit' ),
616
+					'context'     => array('view', 'edit'),
617 617
 					'readonly'    => true,
618 618
 				),
619 619
 				'placeholder' => array(
620
-					'description' => __( 'Placeholder text to be displayed in text inputs.', 'invoicing' ),
620
+					'description' => __('Placeholder text to be displayed in text inputs.', 'invoicing'),
621 621
 					'type'        => 'string',
622 622
 					'arg_options' => array(
623 623
 						'sanitize_callback' => 'sanitize_text_field',
624 624
 					),
625
-					'context'     => array( 'view', 'edit' ),
625
+					'context'     => array('view', 'edit'),
626 626
 					'readonly'    => true,
627 627
 				),
628 628
 				'type'        => array(
629
-					'description' => __( 'Type of setting.', 'invoicing' ),
629
+					'description' => __('Type of setting.', 'invoicing'),
630 630
 					'type'        => 'string',
631 631
 					'arg_options' => array(
632 632
 						'sanitize_callback' => 'sanitize_text_field',
633 633
 					),
634
-					'context'     => array( 'view', 'edit' ),
635
-					'enum'        => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'raw_html' ),
634
+					'context'     => array('view', 'edit'),
635
+					'enum'        => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'raw_html'),
636 636
 					'readonly'    => true,
637 637
 				),
638 638
 				'options'     => array(
639
-					'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'invoicing' ),
639
+					'description' => __('Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'invoicing'),
640 640
 					'type'        => 'object',
641
-					'context'     => array( 'view', 'edit' ),
641
+					'context'     => array('view', 'edit'),
642 642
 					'readonly'    => true,
643 643
 				),
644 644
 				'readonly'    => array(
645
-					'description' => __( 'Whether or not this setting is readonly', 'invoicing' ),
645
+					'description' => __('Whether or not this setting is readonly', 'invoicing'),
646 646
 					'type'        => 'string',
647
-					'context'     => array( 'view' ),
647
+					'context'     => array('view'),
648 648
 					'readonly'    => true,
649 649
 				),
650 650
 				'faux'        => array(
651
-					'description' => __( 'Whether or not this setting is readonly/faux', 'invoicing' ),
651
+					'description' => __('Whether or not this setting is readonly/faux', 'invoicing'),
652 652
 					'type'        => 'string',
653
-					'context'     => array( 'view' ),
653
+					'context'     => array('view'),
654 654
 					'readonly'    => true,
655 655
 				),
656 656
 			),
657 657
 		);
658 658
 
659 659
 		// Filters the settings schema for the REST API.
660
-        $schema = apply_filters( 'getpaid_rest_settings_schema', $schema );
660
+        $schema = apply_filters('getpaid_rest_settings_schema', $schema);
661 661
 
662 662
 		// Cache the settings schema.
663 663
 		$this->schema = $schema;
664 664
 
665
-		return $this->add_additional_fields_schema( $this->schema );
665
+		return $this->add_additional_fields_schema($this->schema);
666 666
 
667 667
 	}
668 668
 
@@ -674,9 +674,9 @@  discard block
 block discarded – undo
674 674
 	 * @param array  $setting Setting.
675 675
 	 * @return string
676 676
 	 */
677
-	public function validate_setting_text_field( $value ) {
678
-		$value = is_null( $value ) ? '' : $value;
679
-		return wp_kses_post( trim( stripslashes( $value ) ) );
677
+	public function validate_setting_text_field($value) {
678
+		$value = is_null($value) ? '' : $value;
679
+		return wp_kses_post(trim(stripslashes($value)));
680 680
 	}
681 681
 
682 682
 	/**
@@ -687,11 +687,11 @@  discard block
 block discarded – undo
687 687
 	 * @param array  $setting Setting.
688 688
 	 * @return string|WP_Error
689 689
 	 */
690
-	public function validate_setting_select_field( $value, $setting ) {
691
-		if ( array_key_exists( $value, $setting['options'] ) ) {
690
+	public function validate_setting_select_field($value, $setting) {
691
+		if (array_key_exists($value, $setting['options'])) {
692 692
 			return $value;
693 693
 		} else {
694
-			return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'invoicing' ), array( 'status' => 400 ) );
694
+			return new WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'invoicing'), array('status' => 400));
695 695
 		}
696 696
 	}
697 697
 
@@ -703,18 +703,18 @@  discard block
 block discarded – undo
703 703
 	 * @param array $setting Setting.
704 704
 	 * @return array|WP_Error
705 705
 	 */
706
-	public function validate_setting_multiselect_field( $values, $setting ) {
707
-		if ( empty( $values ) ) {
706
+	public function validate_setting_multiselect_field($values, $setting) {
707
+		if (empty($values)) {
708 708
 			return array();
709 709
 		}
710 710
 
711
-		if ( ! is_array( $values ) ) {
712
-			return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'invoicing' ), array( 'status' => 400 ) );
711
+		if (!is_array($values)) {
712
+			return new WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'invoicing'), array('status' => 400));
713 713
 		}
714 714
 
715 715
 		$final_values = array();
716
-		foreach ( $values as $value ) {
717
-			if ( array_key_exists( $value, $setting['options'] ) ) {
716
+		foreach ($values as $value) {
717
+			if (array_key_exists($value, $setting['options'])) {
718 718
 				$final_values[] = $value;
719 719
 			}
720 720
 		}
@@ -730,8 +730,8 @@  discard block
 block discarded – undo
730 730
 	 * @param array  $setting Setting.
731 731
 	 * @return string|WP_Error
732 732
 	 */
733
-	public function validate_setting_radio_field( $value, $setting ) {
734
-		return $this->validate_setting_select_field( $value, $setting );
733
+	public function validate_setting_radio_field($value, $setting) {
734
+		return $this->validate_setting_select_field($value, $setting);
735 735
 	}
736 736
 
737 737
 	/**
@@ -741,8 +741,8 @@  discard block
 block discarded – undo
741 741
 	 * @param string $value Value.
742 742
 	 * @return int
743 743
 	 */
744
-	public function validate_setting_checkbox_field( $value ) {
745
-		return (int) ! empty( $value );
744
+	public function validate_setting_checkbox_field($value) {
745
+		return (int) !empty($value);
746 746
 	}
747 747
 
748 748
 	/**
@@ -752,10 +752,10 @@  discard block
 block discarded – undo
752 752
 	 * @param string $value Value.
753 753
 	 * @return string
754 754
 	 */
755
-	public function validate_setting_textarea_field( $value ) {
756
-		$value = is_null( $value ) ? '' : $value;
755
+	public function validate_setting_textarea_field($value) {
756
+		$value = is_null($value) ? '' : $value;
757 757
 		return wp_kses(
758
-			trim( stripslashes( $value ) ),
758
+			trim(stripslashes($value)),
759 759
 			array_merge(
760 760
 				array(
761 761
 					'iframe' => array(
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 						'class' => true,
766 766
 					),
767 767
 				),
768
-				wp_kses_allowed_html( 'post' )
768
+				wp_kses_allowed_html('post')
769 769
 			)
770 770
 		);
771 771
 	}
Please login to merge, or discard this patch.